-
Notifications
You must be signed in to change notification settings - Fork 16
feat: Adds forceApprove logic (SC-978) #110
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a967732
feat: add forceApprove logic
supercontracts 4c9c35d
Merge branch 'dev' into sc-978-forceApprove
supercontracts ea6a1d6
feat: add forceApprove logic in CurveLib.sol
supercontracts dfc0327
chore: linting
supercontracts bd7cf0a
test: add test harness for curve
supercontracts 18f23f9
add new line
supercontracts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
pragma solidity >=0.8.0; | ||
|
||
import "./ForkTestBase.t.sol"; | ||
|
||
import { ForeignController } from "../../src/ForeignController.sol"; | ||
import { MainnetController } from "../../src/MainnetController.sol"; | ||
|
||
import { CurveLib } from "../../src/libraries/CurveLib.sol"; | ||
|
||
import { IALMProxy } from "../../src/interfaces/IALMProxy.sol"; | ||
|
||
interface IHarness { | ||
function approve(address token, address spender, uint256 amount) external; | ||
function approveCurve(address proxy, address token, address spender, uint256 amount) external; | ||
} | ||
|
||
contract MainnetControllerHarness is MainnetController { | ||
|
||
using CurveLib for IALMProxy; | ||
|
||
constructor( | ||
address admin_, | ||
address proxy_, | ||
address rateLimits_, | ||
address vault_, | ||
address psm_, | ||
address daiUsds_, | ||
address cctp_ | ||
) MainnetController(admin_, proxy_, rateLimits_, vault_, psm_, daiUsds_, cctp_) {} | ||
|
||
function approve(address token, address spender, uint256 amount) external { | ||
_approve(token, spender, amount); | ||
lucas-manuel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
function approveCurve(address proxy, address token, address spender, uint256 amount) external { | ||
IALMProxy(proxy)._approve(token, spender, amount); | ||
} | ||
|
||
} | ||
|
||
contract ForeignControllerHarness is ForeignController { | ||
|
||
constructor( | ||
address admin_, | ||
address proxy_, | ||
address rateLimits_, | ||
address psm_, | ||
address usdc_, | ||
address cctp_ | ||
) ForeignController(admin_, proxy_, rateLimits_, psm_, usdc_, cctp_) {} | ||
|
||
function approve(address token, address spender, uint256 amount) external { | ||
_approve(token, spender, amount); | ||
} | ||
|
||
} | ||
|
||
contract ApproveTestBase is ForkTestBase { | ||
|
||
function _approveTest(address token, address harness) internal { | ||
address spender = makeAddr("spender"); | ||
|
||
assertEq(IERC20(token).allowance(harness, spender), 0); | ||
|
||
IHarness(harness).approve(token, spender, 100); | ||
|
||
assertEq(IERC20(token).allowance(address(almProxy), spender), 100); | ||
|
||
IHarness(harness).approve(token, spender, 200); // Would revert without setting to zero | ||
|
||
assertEq(IERC20(token).allowance(address(almProxy), spender), 200); | ||
} | ||
|
||
function _approveCurveTest(address token, address harness) internal { | ||
address spender = makeAddr("spender"); | ||
|
||
assertEq(IERC20(token).allowance(harness, spender), 0); | ||
|
||
IHarness(harness).approveCurve(address(almProxy), token, spender, 100); | ||
|
||
assertEq(IERC20(token).allowance(address(almProxy), spender), 100); | ||
|
||
IHarness(harness).approveCurve(address(almProxy), token, spender, 200); // Would revert without setting to zero | ||
|
||
assertEq(IERC20(token).allowance(address(almProxy), spender), 200); | ||
} | ||
|
||
} | ||
|
||
contract MainnetControllerApproveSuccessTests is ApproveTestBase { | ||
|
||
address harness; | ||
|
||
function setUp() public virtual override { | ||
super.setUp(); | ||
|
||
MainnetControllerHarness harnessCode = new MainnetControllerHarness( | ||
SPARK_PROXY, | ||
address(mainnetController.proxy()), | ||
address(mainnetController.rateLimits()), | ||
address(mainnetController.vault()), | ||
address(mainnetController.psm()), | ||
address(mainnetController.daiUsds()), | ||
address(mainnetController.cctp()) | ||
); | ||
|
||
vm.etch(address(mainnetController), address(harnessCode).code); | ||
|
||
harness = address(MainnetControllerHarness(address(mainnetController))); | ||
} | ||
|
||
function test_approveTokens() public { | ||
_approveTest(Ethereum.CBBTC, harness); | ||
_approveTest(Ethereum.DAI, harness); | ||
_approveTest(Ethereum.GNO, harness); | ||
_approveTest(Ethereum.MKR, harness); | ||
_approveTest(Ethereum.RETH, harness); | ||
_approveTest(Ethereum.SDAI, harness); | ||
_approveTest(Ethereum.SUSDE, harness); | ||
_approveTest(Ethereum.SUSDS, harness); | ||
_approveTest(Ethereum.USDC, harness); | ||
_approveTest(Ethereum.USDE, harness); | ||
_approveTest(Ethereum.USDS, harness); | ||
_approveTest(Ethereum.USCC, harness); | ||
_approveTest(Ethereum.USDT, harness); | ||
_approveTest(Ethereum.USTB, harness); | ||
_approveTest(Ethereum.WBTC, harness); | ||
_approveTest(Ethereum.WEETH, harness); | ||
_approveTest(Ethereum.WETH, harness); | ||
_approveTest(Ethereum.WSTETH, harness); | ||
} | ||
|
||
function test_approveCurveTokens() public { | ||
_approveCurveTest(Ethereum.CBBTC, harness); | ||
_approveCurveTest(Ethereum.DAI, harness); | ||
_approveCurveTest(Ethereum.GNO, harness); | ||
_approveCurveTest(Ethereum.MKR, harness); | ||
_approveCurveTest(Ethereum.RETH, harness); | ||
_approveCurveTest(Ethereum.SDAI, harness); | ||
_approveCurveTest(Ethereum.SUSDE, harness); | ||
_approveCurveTest(Ethereum.SUSDS, harness); | ||
_approveCurveTest(Ethereum.USDC, harness); | ||
_approveCurveTest(Ethereum.USDE, harness); | ||
_approveCurveTest(Ethereum.USDS, harness); | ||
_approveCurveTest(Ethereum.USCC, harness); | ||
_approveCurveTest(Ethereum.USDT, harness); | ||
_approveCurveTest(Ethereum.USTB, harness); | ||
_approveCurveTest(Ethereum.WBTC, harness); | ||
_approveCurveTest(Ethereum.WEETH, harness); | ||
_approveCurveTest(Ethereum.WETH, harness); | ||
_approveCurveTest(Ethereum.WSTETH, harness); | ||
} | ||
|
||
} | ||
|
||
// NOTE: This code is running against mainnet, but is used to demonstrate equivalent approve behaviour | ||
// for USDT-type contracts. Because of this, the foreignController has to be onboarded in the same | ||
// way as the mainnetController. | ||
contract ForeignControllerApproveSuccessTests is ApproveTestBase { | ||
|
||
address harness; | ||
|
||
function setUp() public virtual override { | ||
super.setUp(); | ||
|
||
// NOTE: This etching setup is necessary to get coverage to work | ||
|
||
ForeignController foreignController = new ForeignController( | ||
SPARK_PROXY, | ||
address(almProxy), | ||
makeAddr("rateLimits"), | ||
makeAddr("psm"), | ||
makeAddr("usdc"), | ||
makeAddr("cctp") | ||
); | ||
|
||
ForeignControllerHarness harnessCode = new ForeignControllerHarness( | ||
SPARK_PROXY, | ||
address(almProxy), | ||
makeAddr("rateLimits"), | ||
makeAddr("psm"), | ||
makeAddr("usdc"), | ||
makeAddr("cctp") | ||
); | ||
|
||
// Allow the foreign controller to call the ALMProxy | ||
vm.startPrank(SPARK_PROXY); | ||
almProxy.grantRole(almProxy.CONTROLLER(), address(foreignController)); | ||
vm.stopPrank(); | ||
|
||
vm.etch(address(foreignController), address(harnessCode).code); | ||
|
||
harness = address(ForeignControllerHarness(address(foreignController))); | ||
} | ||
|
||
function test_approveTokens() public { | ||
_approveTest(Ethereum.CBBTC, harness); | ||
_approveTest(Ethereum.DAI, harness); | ||
_approveTest(Ethereum.GNO, harness); | ||
_approveTest(Ethereum.MKR, harness); | ||
_approveTest(Ethereum.RETH, harness); | ||
_approveTest(Ethereum.SDAI, harness); | ||
_approveTest(Ethereum.SUSDE, harness); | ||
_approveTest(Ethereum.SUSDS, harness); | ||
_approveTest(Ethereum.USDC, harness); | ||
_approveTest(Ethereum.USDE, harness); | ||
_approveTest(Ethereum.USDS, harness); | ||
_approveTest(Ethereum.USCC, harness); | ||
_approveTest(Ethereum.USDT, harness); | ||
_approveTest(Ethereum.USTB, harness); | ||
_approveTest(Ethereum.WBTC, harness); | ||
_approveTest(Ethereum.WEETH, harness); | ||
_approveTest(Ethereum.WETH, harness); | ||
_approveTest(Ethereum.WSTETH, harness); | ||
} | ||
lucas-manuel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.