Last active
February 15, 2021 19:31
-
-
Save 0xmikko/c2a7ea4eb1faadad2e975777aeb96fdc to your computer and use it in GitHub Desktop.
Gearbox swap
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
// store balances before swap | |
uint256 balanceInBefore = _vaultService.getBalance(tokenIn); | |
uint256 balanceOutBefore = _vaultService.getBalance(tokenOut); | |
// swapTokens | |
_vaultService.swapTokensForExactTokens( | |
amountOut, | |
amountInMax, | |
path, | |
deadline | |
); | |
// compute changes in balances | |
uint256 amountInSpent = | |
balanceInBefore.sub(_vaultService.getBalance(tokenIn)); | |
uint256 amountOutGot = | |
_vaultService.getBalance(tokenOut).sub(balanceOutBefore); | |
// update stored balances with differences | |
_PositionRepository.swapAssets( | |
msg.sender, | |
tokenIn, | |
amountInSpent, | |
tokenOut, | |
amountOutGot | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment