-
Notifications
You must be signed in to change notification settings - Fork 6
Add USDS-SUSDS token wrappers #13
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
Open
foodaka
wants to merge
29
commits into
main
Choose a base branch
from
feat/susds-wrappers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
3fb0e1b
init
foodaka fb66cf8
fork execution
foodaka 17ed1e5
cleanup
foodaka 50f3eb7
test: Don't assume 0 ETH balance on wrapper contracts
CheyenneAtapour d3784d0
Fix TokenBorrow for SUSDS (#15)
CheyenneAtapour df5dd2b
feat: Move borrow logic to base wrapper
CheyenneAtapour 0f69b1c
test: Add borrow test to SDAI wrapper. Lock blocknumbers
CheyenneAtapour e22cbd3
test: Add borrow token test for steth
CheyenneAtapour 340414f
pr comments
foodaka a2dec9e
updated files
foodaka 00b6ed4
move borrow as virtual on base
foodaka 0163386
fix: Fuzz test, rename test, reorder fns per convention
CheyenneAtapour 2cce3f7
borrow not permitted
foodaka 0db3322
Merge branch 'feat/susds-wrappers' of github.com:aave/token-wrappers …
foodaka 6915b96
borrow with sig
foodaka c24b358
fix: Move borrow logic to internal function
CheyenneAtapour 1ab43a0
fix: Address pr comments
CheyenneAtapour 4f5f382
fix: Move borrow logic to base wrapper
CheyenneAtapour 1886062
fix: Move dependencies to V3 origin (#16)
miguelmtzinf 9d654dd
fix: Remove unlimited allowance (#17)
miguelmtzinf 253000b
feat: Generic ERC4626 <> ERC20 Token Wrapper (#20)
CheyenneAtapour 53c52bd
fix: Remove unneccesary file
miguelmtzinf 37e17c4
fix: Disables supply with permit for DAI because DAI permit is not st…
miguelmtzinf a10494c
fix: Re-order functions based on solidity guideliens
miguelmtzinf 11c19c8
fix: Remove solc warnings
miguelmtzinf 596d521
Refactors tests (#21)
miguelmtzinf 86fb6e2
test: Add fuzz test for borrow
CheyenneAtapour 9118be9
fix: Revert change test name
CheyenneAtapour 13224ae
Add Additional BorrowToken Tests (#22)
CheyenneAtapour 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0 | ||
| pragma solidity ^0.8.10; | ||
| import 'forge-std/console2.sol'; | ||
miguelmtzinf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import {IPool} from 'aave-v3-core/contracts/interfaces/IPool.sol'; | ||
| import {ICreditDelegationToken} from 'aave-v3-core/contracts/interfaces/ICreditDelegationToken.sol'; | ||
| import {IERC20} from 'aave-v3-core/contracts/dependencies/openzeppelin/contracts/IERC20.sol'; | ||
| import {IUSDS} from './dependencies/IUSDS.sol'; | ||
| import {BaseTokenWrapper} from './BaseTokenWrapper.sol'; | ||
|
|
||
| /** | ||
| * @title SavingUsdsTokenWrapper | ||
| * @author Aave | ||
| * @notice Contract to wrap USDS to SuSDS on supply to Aave, or unwrap from SuSDS to USDS on withdrawal | ||
| */ | ||
| contract SavingUsdsTokenWrapper is BaseTokenWrapper { | ||
| /** | ||
| * @dev Constructor | ||
| * @param tokenIn Address for USDS | ||
| * @param tokenOut Address for SUSDS | ||
| * @param pool The address of the Aave Pool | ||
| * @param owner The address to transfer ownership to | ||
| */ | ||
| constructor( | ||
| address tokenIn, | ||
| address tokenOut, | ||
| address pool, | ||
| address owner | ||
| ) BaseTokenWrapper(tokenIn, tokenOut, pool, owner) { | ||
| IERC20(tokenIn).approve(tokenOut, type(uint256).max); | ||
| } | ||
|
|
||
| /// @inheritdoc BaseTokenWrapper | ||
| function borrowToken( | ||
| uint256 amount, | ||
| address to, | ||
| uint16 referralCode | ||
| ) external override { | ||
| _borrowToken(amount, to, referralCode); | ||
| } | ||
|
|
||
| /// @inheritdoc BaseTokenWrapper | ||
| function borrowTokenWithPermit( | ||
| uint256 amount, | ||
| address to, | ||
| uint16 referralCode, | ||
| uint256 deadline, | ||
| uint8 permitV, | ||
| bytes32 permitR, | ||
| bytes32 permitS | ||
| ) external override { | ||
| if (deadline != 0) { | ||
| address debtToken = IPool(0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2) | ||
| .getReserveData(TOKEN_OUT) | ||
| .variableDebtTokenAddress; | ||
|
|
||
| ICreditDelegationToken(debtToken).delegationWithSig( | ||
| msg.sender, | ||
| address(this), | ||
| amount, | ||
| deadline, | ||
| permitV, | ||
| permitR, | ||
| permitS | ||
| ); | ||
| } | ||
| _borrowToken(amount, to, referralCode); | ||
| } | ||
|
|
||
| /// @inheritdoc BaseTokenWrapper | ||
| function getTokenOutForTokenIn( | ||
| uint256 amount | ||
| ) external view override returns (uint256) { | ||
| return IUSDS(TOKEN_OUT).previewDeposit(amount); | ||
| } | ||
|
|
||
| /// @inheritdoc BaseTokenWrapper | ||
| function getTokenInForTokenOut( | ||
| uint256 amount | ||
| ) external view override returns (uint256) { | ||
| return IUSDS(TOKEN_OUT).previewRedeem(amount); | ||
| } | ||
|
|
||
| /// @inheritdoc BaseTokenWrapper | ||
| function _wrapTokenIn(uint256 amount) internal override returns (uint256) { | ||
| return IUSDS(TOKEN_OUT).deposit(amount, address(this)); | ||
| } | ||
|
|
||
| /// @inheritdoc BaseTokenWrapper | ||
| function _unwrapTokenOut(uint256 amount) internal override returns (uint256) { | ||
| return IUSDS(TOKEN_OUT).redeem(amount, address(this), address(this)); | ||
| } | ||
|
|
||
| function _borrowToken( | ||
miguelmtzinf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| uint256 amount, | ||
| address to, | ||
miguelmtzinf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| uint16 referralCode | ||
| ) internal { | ||
| require(amount > 0, 'INSUFFICIENT_AMOUNT_TO_BORROW'); | ||
| uint256 balanceBeforeBorrow = IERC20(TOKEN_OUT).balanceOf(address(this)); | ||
| POOL.borrow(TOKEN_OUT, amount, 2, referralCode, address(to)); | ||
| uint256 balanceAfterBorrow = IERC20(TOKEN_OUT).balanceOf(address(this)); | ||
| uint256 amountIn = _unwrapTokenOut( | ||
| balanceAfterBorrow - balanceBeforeBorrow | ||
| ); | ||
| IERC20(TOKEN_IN).transfer(to, amountIn); | ||
| } | ||
| } | ||
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,145 @@ | ||
| // SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
|
||
| pragma solidity >=0.8.0; | ||
|
|
||
| interface IUSDS { | ||
| function DOMAIN_SEPARATOR() external view returns (bytes32); | ||
|
|
||
| function PERMIT_TYPEHASH() external view returns (bytes32); | ||
|
|
||
| function UPGRADE_INTERFACE_VERSION() external view returns (string memory); | ||
|
|
||
| function allowance( | ||
| address owner, | ||
| address spender | ||
| ) external view returns (uint256); | ||
|
|
||
| function approve(address spender, uint256 value) external returns (bool); | ||
|
|
||
| function asset() external view returns (address); | ||
|
|
||
| function balanceOf(address account) external view returns (uint256); | ||
|
|
||
| function chi() external view returns (uint192); | ||
|
|
||
| function convertToAssets(uint256 shares) external view returns (uint256); | ||
|
|
||
| function convertToShares(uint256 assets) external view returns (uint256); | ||
|
|
||
| function decimals() external view returns (uint8); | ||
|
|
||
| function deny(address usr) external; | ||
|
|
||
| function deposit(uint256 assets, address receiver) external returns (uint256); | ||
|
|
||
| function deposit( | ||
| uint256 assets, | ||
| address receiver, | ||
| uint16 referral | ||
| ) external returns (uint256); | ||
|
|
||
| function drip() external returns (uint256); | ||
|
|
||
| function file(bytes32 what, uint256 data) external; | ||
|
|
||
| function getImplementation() external view returns (address); | ||
|
|
||
| function initialize() external; | ||
|
|
||
| function maxDeposit(address account) external view returns (uint256); | ||
|
|
||
| function maxMint(address account) external view returns (uint256); | ||
|
|
||
| function maxRedeem(address owner) external view returns (uint256); | ||
|
|
||
| function maxWithdraw(address owner) external view returns (uint256); | ||
|
|
||
| function mint( | ||
| uint256 shares, | ||
| address receiver, | ||
| uint16 referral | ||
| ) external returns (uint256); | ||
|
|
||
| function mint(uint256 shares, address receiver) external returns (uint256); | ||
|
|
||
| function name() external view returns (string memory); | ||
|
|
||
| function nonces(address account) external view returns (uint256); | ||
|
|
||
| function permit( | ||
| address owner, | ||
| address spender, | ||
| uint256 value, | ||
| uint256 deadline, | ||
| bytes memory signature | ||
| ) external; | ||
|
|
||
| function permit( | ||
| address owner, | ||
| address spender, | ||
| uint256 value, | ||
| uint256 deadline, | ||
| uint8 v, | ||
| bytes32 r, | ||
| bytes32 s | ||
| ) external; | ||
|
|
||
| function previewDeposit(uint256 assets) external view returns (uint256); | ||
|
|
||
| function previewMint(uint256 shares) external view returns (uint256); | ||
|
|
||
| function previewRedeem(uint256 shares) external view returns (uint256); | ||
|
|
||
| function previewWithdraw(uint256 assets) external view returns (uint256); | ||
|
|
||
| function proxiableUUID() external view returns (bytes32); | ||
|
|
||
| function redeem( | ||
| uint256 shares, | ||
| address receiver, | ||
| address owner | ||
| ) external returns (uint256); | ||
|
|
||
| function rely(address usr) external; | ||
|
|
||
| function rho() external view returns (uint64); | ||
|
|
||
| function ssr() external view returns (uint256); | ||
|
|
||
| function symbol() external view returns (string memory); | ||
|
|
||
| function totalAssets() external view returns (uint256); | ||
|
|
||
| function totalSupply() external view returns (uint256); | ||
|
|
||
| function transfer(address to, uint256 value) external returns (bool); | ||
|
|
||
| function transferFrom( | ||
| address from, | ||
| address to, | ||
| uint256 value | ||
| ) external returns (bool); | ||
|
|
||
| function upgradeToAndCall( | ||
| address newImplementation, | ||
| bytes memory data | ||
| ) external payable; | ||
|
|
||
| function usds() external view returns (address); | ||
|
|
||
| function usdsJoin() external view returns (address); | ||
|
|
||
| function vat() external view returns (address); | ||
|
|
||
| function version() external view returns (string memory); | ||
|
|
||
| function vow() external view returns (address); | ||
|
|
||
| function wards(address account) external view returns (uint256); | ||
|
|
||
| function withdraw( | ||
| uint256 assets, | ||
| address receiver, | ||
| address owner | ||
| ) external returns (uint256); | ||
| } |
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
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.