Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slither doc, feecalc fixes, add mock deposit contract and feecalc to … #37

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ deploy_log.json

contracts/governance/SimpleVesting.sol
contracts/util/SingleTokenVestingNonRevocable.sol
contracts/v2/periphery/*.sol
./**/*.js
test/**/*
./**/*.md
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ export ALCHEMY_GOERLI_KEY='xx'
// see deploy_minterv2.js or deploy tasks in package.json for hardhat deploy usage
```

# Slither

Slither run results and howto:

- start venv
- `pip3 install slither-analyzer`
- `slither . --ignore-compile`
./contracts/
--compile-force-framework hardhat
--solc-remaps @openzeppelin/=$(pwd)/node_modules/@openzeppelin/
--solc solc-0.8.10 --solc-args "--optimize --optimize-runs 200"`

# Archival

# Errors
Expand Down
48 changes: 24 additions & 24 deletions contracts/v2/periphery/FeeCalc.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";

pragma solidity ^0.8.20;

import {Ownable2Step} from "@openzeppelin/contracts/access/Ownable2Step.sol";

contract FeeCalc is Ownable2Step {
struct Settings {
uint256 adminFee;
Expand All @@ -25,26 +23,6 @@
costPerValidator = ((32 + (32 * adminFee)) * 1 ether) / BIPS;
}

function processDeposit(uint256 value) external view returns (uint256 amt, uint256 fee) {
if (config.chargeOnDeposit) {
fee = (value * adminFee) / BIPS;
amt = value - fee;
}
}

function processWithdraw(uint256 value) external view returns (uint256 amt, uint256 fee) {
if (config.refundFeesOnWithdraw) {
fee = (value * adminFee) / BIPS;
amt = value + fee;
} else if (config.chargeOnExit) {
fee = (value * config.exitFee) / BIPS;
amt = value - fee;
} else {
fee = 0;
amt = value;
}
}

function set(Settings calldata newSettings) external onlyOwner {
config = newSettings;
adminFee = newSettings.adminFee;
Expand All @@ -62,4 +40,26 @@
adminFee = amount;
config.adminFee = amount;
}

function processDeposit(uint256 value, address sender) external view returns (uint256 amt, uint256 fee) {

Check failure on line 44 in contracts/v2/periphery/FeeCalc.sol

View workflow job for this annotation

GitHub Actions / build (20.x)

Variable "sender" is unused
// TODO: semder is currently unsused but can be used later to calculate a fee reduction based on token holdings
if (config.chargeOnDeposit) {
fee = (value * adminFee) / BIPS;
amt = value - fee;
}
}

function processWithdraw(uint256 value, address sender) external view returns (uint256 amt, uint256 fee) {

Check failure on line 52 in contracts/v2/periphery/FeeCalc.sol

View workflow job for this annotation

GitHub Actions / build (20.x)

Variable "sender" is unused
// TODO: semder is currently unsused but can be used later to calculate a fee reduction based on token holdings
if (config.refundFeesOnWithdraw) {
fee = (value * adminFee) / BIPS;
amt = value + fee;
} else if (config.chargeOnExit) {
fee = (value * config.exitFee) / BIPS;
amt = value - fee;
} else {
fee = 0;
amt = value;
}
}
}
9 changes: 9 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ const config: HardhatUserConfig = {
},
},
},
{
version: "0.6.11",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
],
},
networks: {
Expand Down
26 changes: 26 additions & 0 deletions scripts/v2/1_deploy_minterv2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ let {DeployHelper} = require("./lib/DeployHelper.js");
let {deployMinterV2, setWithdrawalCredential, addMinter} = require("./lib/minter_deploy_utils.js");
let genParams = require("./lib/opts.js");
let OA = require("./lib/onchain_actions.js");
const {network, ethers} = require("hardhat");

require("dotenv").config();

Expand All @@ -16,6 +17,12 @@ async function main() {
let params = genParams(dh);
dh.multisig_address = params.multisigAddr;

// if testnet deploy a mock deposit contract
if (network.name !== "mainnet") {
await dh.deployContract("DepositContract", "DepositContract", []);
params.depositContractAddr = dh.addressOf("DepositContract");
}

/** Deploy core of v2 system
* 1. Deploy sgETH
* 2. Deploy wsgETH
Expand All @@ -32,6 +39,16 @@ async function main() {
let wsgETHAddr = dh.addressOf(wsgETH);
params.wsgETH = wsgETHAddr;


await dh.deployContract("FeeCalc", "FeeCalc", [{
adminFee: 10,
exitFee: 0,
refundFeesOnWithdraw: true,
chargeOnDeposit: true,
chargeOnExit: false
}]);
params.feeCalcAddr = dh.addressOf("FeeCalc");

await deployMinterV2(dh, params);
let minter = dh.addressOf(params.names.minter);
params.minter = minter;
Expand Down Expand Up @@ -109,6 +126,15 @@ async function main() {

// test deposit withdraw flow
await oa.e2e(params);

// starting sgeth bal 0.0
// Deposited Eth, got sgETH: 0.01 0.01
// new sgETH bal post withdraw 0.0
// warmed up deposit/withdraw
// starting wsgeth bal 0.0
// Staked Eth, got wsgETH: 0.01 0.01
// Unstaked wsgETH, new wsgETH bal: 0.005
// warmed up stake/unstake
}

// We recommend this pattern to be able to use async/await everywhere
Expand Down
Loading