generated from bgd-labs/bgd-forge-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Migrate to Paraswap V6 #32
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
Draft
CheyenneAtapour
wants to merge
20
commits into
bgd-labs:main
Choose a base branch
from
aave:feat/ps-v6
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.
Draft
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
25641c2
fix: Update buy adapter
CheyenneAtapour befc937
fix: Remove unused imports
CheyenneAtapour 7117247
fix: Use safemath, remove unused interface
CheyenneAtapour 3d2f0ff
feat: Add augustus v6 fn sigs, update fork block
CheyenneAtapour f19523d
fix: Update evm version, fork blocks
CheyenneAtapour b798e76
fix: Update fork block
CheyenneAtapour c92d237
fix: Use usdc instead of lusd because frozen
CheyenneAtapour 2595d71
fix: Change busd to usdc
CheyenneAtapour 063c224
fix: Change assets and amounts as per new conditions
CheyenneAtapour 6b0787f
fix: V2 extra collateral test
CheyenneAtapour 7fa6efc
fix: V2 without extra collateral test
CheyenneAtapour 4f3ec85
fix: V3 extra collateral tests
CheyenneAtapour 764e89b
fix: V3 without extra collateral test
CheyenneAtapour d48b8cb
fix: Gho extra collateral tests
CheyenneAtapour bc51b1b
fix: Extra collateral same as new debt tests
CheyenneAtapour be8ec99
fix: Remove commented code
CheyenneAtapour ff967b2
fix: Add cached api calls
CheyenneAtapour d070886
fix: Remove unused extra dep
CheyenneAtapour 25a9932
fix: Remove unnecessary additions to api call script
CheyenneAtapour 1920afd
fix: Remove safemath
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
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 |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import {PercentageMath} from '@aave/core-v3/contracts/protocol/libraries/math/Pe | |
| import {IPoolAddressesProvider} from '@aave/core-v3/contracts/interfaces/IPoolAddressesProvider.sol'; | ||
| import {IERC20Detailed} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20Detailed.sol'; | ||
| import {SafeERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/SafeERC20.sol'; | ||
| import {IParaSwapAugustus} from '../interfaces/IParaSwapAugustus.sol'; | ||
| import {SafeMath} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/SafeMath.sol'; | ||
| import {IParaSwapAugustusRegistry} from '../interfaces/IParaSwapAugustusRegistry.sol'; | ||
| import {BaseParaSwapAdapter} from './BaseParaSwapAdapter.sol'; | ||
|
|
||
|
|
@@ -14,8 +14,9 @@ import {BaseParaSwapAdapter} from './BaseParaSwapAdapter.sol'; | |
| * @notice Implements the logic for buying tokens on ParaSwap | ||
| */ | ||
| abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter { | ||
| using SafeERC20 for IERC20Detailed; | ||
| using PercentageMath for uint256; | ||
| using SafeMath for uint256; | ||
|
||
| using SafeERC20 for IERC20Detailed; | ||
|
|
||
| IParaSwapAugustusRegistry public immutable AUGUSTUS_REGISTRY; | ||
|
|
||
|
|
@@ -48,12 +49,8 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter { | |
| uint256 maxAmountToSwap, | ||
| uint256 amountToReceive | ||
| ) internal returns (uint256 amountSold, uint256 amountBought) { | ||
| (bytes memory buyCalldata, IParaSwapAugustus augustus) = abi.decode( | ||
| paraswapData, | ||
| (bytes, IParaSwapAugustus) | ||
| ); | ||
|
|
||
| require(AUGUSTUS_REGISTRY.isValidAugustus(address(augustus)), 'INVALID_AUGUSTUS'); | ||
| (bytes memory buyCalldata, address augustus) = abi.decode(paraswapData, (bytes, address)); | ||
| require(AUGUSTUS_REGISTRY.isValidAugustus(augustus), 'INVALID_AUGUSTUS'); | ||
|
|
||
| { | ||
| uint256 fromAssetDecimals = _getDecimals(assetToSwapFrom); | ||
|
|
@@ -62,9 +59,10 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter { | |
| uint256 fromAssetPrice = _getPrice(address(assetToSwapFrom)); | ||
| uint256 toAssetPrice = _getPrice(address(assetToSwapTo)); | ||
|
|
||
| uint256 expectedMaxAmountToSwap = ((amountToReceive * | ||
| (toAssetPrice * (10 ** fromAssetDecimals))) / (fromAssetPrice * (10 ** toAssetDecimals))) | ||
| .percentMul(PercentageMath.PERCENTAGE_FACTOR + MAX_SLIPPAGE_PERCENT); | ||
| uint256 expectedMaxAmountToSwap = amountToReceive | ||
| .mul(toAssetPrice.mul(10 ** fromAssetDecimals)) | ||
| .div(fromAssetPrice.mul(10 ** toAssetDecimals)) | ||
| .percentMul(PercentageMath.PERCENTAGE_FACTOR.add(MAX_SLIPPAGE_PERCENT)); | ||
|
|
||
| require(maxAmountToSwap <= expectedMaxAmountToSwap, 'maxAmountToSwap exceed max slippage'); | ||
| } | ||
|
|
@@ -73,14 +71,13 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter { | |
| require(balanceBeforeAssetFrom >= maxAmountToSwap, 'INSUFFICIENT_BALANCE_BEFORE_SWAP'); | ||
| uint256 balanceBeforeAssetTo = assetToSwapTo.balanceOf(address(this)); | ||
|
|
||
| address tokenTransferProxy = augustus.getTokenTransferProxy(); | ||
| assetToSwapFrom.safeApprove(tokenTransferProxy, maxAmountToSwap); | ||
| assetToSwapFrom.safeApprove(augustus, maxAmountToSwap); | ||
|
|
||
| if (toAmountOffset != 0) { | ||
| // Ensure 256 bit (32 bytes) toAmountOffset value is within bounds of the | ||
| // calldata, not overlapping with the first 4 bytes (function selector). | ||
| require( | ||
| toAmountOffset >= 4 && toAmountOffset <= buyCalldata.length - 32, | ||
| toAmountOffset >= 4 && toAmountOffset <= buyCalldata.length.sub(32), | ||
| 'TO_AMOUNT_OFFSET_OUT_OF_RANGE' | ||
| ); | ||
| // Overwrite the toAmount with the correct amount for the buy. | ||
|
|
@@ -90,7 +87,7 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter { | |
| mstore(add(buyCalldata, add(toAmountOffset, 32)), amountToReceive) | ||
| } | ||
| } | ||
| (bool success, ) = address(augustus).call(buyCalldata); | ||
| (bool success, ) = augustus.call(buyCalldata); | ||
| if (!success) { | ||
| // Copy revert reason from call | ||
| assembly { | ||
|
|
@@ -99,12 +96,12 @@ abstract contract BaseParaSwapBuyAdapter is BaseParaSwapAdapter { | |
| } | ||
| } | ||
| // Reset allowance | ||
| assetToSwapFrom.safeApprove(tokenTransferProxy, 0); | ||
| assetToSwapFrom.safeApprove(augustus, 0); | ||
|
|
||
| uint256 balanceAfterAssetFrom = assetToSwapFrom.balanceOf(address(this)); | ||
| amountSold = balanceBeforeAssetFrom - balanceAfterAssetFrom; | ||
| require(amountSold <= maxAmountToSwap, 'WRONG_BALANCE_AFTER_SWAP'); | ||
| amountBought = assetToSwapTo.balanceOf(address(this)) - balanceBeforeAssetTo; | ||
| amountBought = assetToSwapTo.balanceOf(address(this)).sub(balanceBeforeAssetTo); | ||
| require(amountBought >= amountToReceive, 'INSUFFICIENT_AMOUNT_RECEIVED'); | ||
|
|
||
| emit Bought(address(assetToSwapFrom), address(assetToSwapTo), amountSold, amountBought); | ||
|
|
||
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 was deleted.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this new dependency?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed