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

feat: {Bounty Submission} Gearbox PoolServiceERC4626Wrapper and PoolServiceERC4626Factory #43

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tushargargght
Copy link

@tushargargght tushargargght commented Mar 27, 2023

Bounty site: https://erc4626.info/
Bounty Spec: https://superform.notion.site/Gearbox-4626-Spec-0de0a498b171417e805759c896137bec
ERC 4626 spec: https://eips.ethereum.org/EIPS/eip-4626

Contracts Created

ERC4626Safe: ERC4626 implementation derived from solmate's ERC4626 with added prevention against Loss of precision vulnerability
PoolServiceERC4626: ERC4626Safe derived PoolService which is ERC4626 wrapper around PoolService
PoolERC4626Factory: PoolService 4626 Wrapper factory

Design Decisions

  1. ERC4626Safe.constructor() mints 100000 shares to address(0) to protect against 'loss of precision' vulnerability. 100000 is a common acceptable amount notably used by Uniswap
    Another option could be to mint some shares to the wrapper contract itself.
  2. ERC4626Safe's convertToAssets(), convertToShares(), previewMint(), and previewWithdraw() modified to use totalAssets() instead of totalSupply() as totalSupply can never be zero because of DesignDecision-1.
  3. PoolServiceERC4626.totalAssets() and PoolServiceERC4626.beforeWithdraw() rounds Up the amount by 1 to account for fromDiesel() round down and adhere to ERC-4626 spec

Testing

run yarn install to install the latest dependencies

Create .env file in the root directory with

MAINNET_RPC_URL=<Your_MAINET_RPC_URL>

and run forge test --match-path contracts\test\pool\PoolServiceERC4626.t.sol to fork-test the PoolERC4626Factory and PoolServiceERC4626 for WETH, WSTETH, USDC, DAI, and WBTC pools

Deployment-Testing

DeployPoolServiceERC4626.s.sol contains the script to deploy all five Pool Services 4626 Wrapper as requested in spec

For testing in the anvil mainnet fork
run anvil --fork-url $MAINNET_RPC_URL and copy the first private key and paste into the .env file so that the file looks like

MAINNET_RPC_URL=<Your_MAINET_RPC_URL>
PRIVATE_KEY=<Generated_From_Anvil>

run forge script contracts/test/pool/script/DeployPoolServiceERC4626.s.sol:DeployPoolService4626Script --fork-url http://localhost:8545 --broadcast

@tushargargght tushargargght changed the title {Bounty Submission} Gearbox PoolServiceERC4626Wrappers and PoolServiceERC4626Factory {Bounty Submission} Gearbox PoolServiceERC4626Wrapper and PoolServiceERC4626Factory Mar 27, 2023
@tushargargght tushargargght changed the title {Bounty Submission} Gearbox PoolServiceERC4626Wrapper and PoolServiceERC4626Factory {Bounty Submission} feat: Gearbox PoolServiceERC4626Wrapper and PoolServiceERC4626Factory Mar 27, 2023
@tushargargght tushargargght changed the title {Bounty Submission} feat: Gearbox PoolServiceERC4626Wrapper and PoolServiceERC4626Factory feat: {Bounty Submission} Gearbox PoolServiceERC4626Wrapper and PoolServiceERC4626Factory Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant