forked from pickle-finance/protocol
-
Notifications
You must be signed in to change notification settings - Fork 15
zapper update #183
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
AbigailTCameron
wants to merge
7
commits into
master
Choose a base branch
from
vector-zapper-correction
base: master
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
zapper update #183
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d08b0bb
zapper update
AbigailTCameron 2ec6bea
zapper
AbigailTCameron 897392b
pause zapper
AbigailTCameron 2b3111c
ready for review
AbigailTCameron 6683112
ready for review
AbigailTCameron 851e4b0
Merge branch 'master' into vector-zapper-correction
AbigailTCameron 4232220
review ready
AbigailTCameron 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.6.7; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "../lib/erc20.sol"; | ||
|
||
interface IKyber { | ||
function addLiquidityETH( | ||
address token, | ||
address pool, | ||
uint256 amountTokenDesired, | ||
uint256 amountTokenMin, | ||
uint256 amountETHMin, | ||
uint256[2] calldata vReserveRatioBounds, | ||
address to, | ||
uint256 deadline | ||
) | ||
external | ||
payable | ||
returns ( | ||
uint256 amountToken, | ||
uint256 amountETH, | ||
uint256 liquidity | ||
); | ||
|
||
function addLiquidity( | ||
address tokenA, | ||
address tokenB, | ||
address pool, | ||
uint256 amountADesired, | ||
uint256 amountBDesired, | ||
uint256 amountAMin, | ||
uint256 amountBMin, | ||
uint256[2] calldata vReserveRatioBounds, | ||
address to, | ||
uint256 deadline | ||
) | ||
external | ||
returns ( | ||
uint256 amountA, | ||
uint256 amountB, | ||
uint256 liquidity | ||
); | ||
|
||
function getTradeInfo() external view returns ( | ||
uint112 _reserve0, | ||
uint112 _reserve1, | ||
uint112 _vReserve0, | ||
uint112 _vReserve1, | ||
uint256 feeInPrecision | ||
); | ||
|
||
function getReserves() external view returns (uint112 _reserve0, uint112 _reserve1); | ||
|
||
/** | ||
* @dev Deposit tokens to accumulate rewards | ||
* @param _pid: id of the pool | ||
* @param _amount: amount of stakeToken to be deposited | ||
* @param _shouldHarvest: whether to harvest the reward or not | ||
*/ | ||
function deposit( | ||
uint256 _pid, | ||
uint256 _amount, | ||
bool _shouldHarvest | ||
) external; | ||
|
||
/** | ||
* @dev Get pending rewards of a user from a pool, mostly for front-end | ||
* @param _pid: id of the pool | ||
* @param _user: user to check for pending rewards | ||
*/ | ||
function pendingRewards(uint256 _pid, address _user) | ||
external view | ||
returns (uint256[] memory rewards); | ||
|
||
/** | ||
* @dev Return user's info including deposited amount and reward data | ||
*/ | ||
function getUserInfo(uint256 _pid, address _account) | ||
external | ||
view | ||
returns ( | ||
uint256 amount, | ||
uint256[] memory unclaimedRewards, | ||
uint256[] memory lastRewardPerShares | ||
); | ||
|
||
/** | ||
* @dev Withdraw token (of the sender) from pool, also harvest rewards | ||
* @param _pid: id of the pool | ||
* @param _amount: amount of stakeToken to withdraw | ||
*/ | ||
function withdraw(uint256 _pid, uint256 _amount) external; | ||
|
||
function harvest(uint256 _pid) external; | ||
|
||
function swapExactTokensForTokens( | ||
uint256 amountIn, | ||
uint256 amountOutMin, | ||
address[] calldata poolsPath, | ||
IERC20[] calldata path, | ||
address to, | ||
uint256 deadline | ||
) external returns (uint256[] memory amounts); | ||
} | ||
|
||
interface IRewardLocker { | ||
/** | ||
* @notice Allow a user to vest with specific schedule | ||
*/ | ||
function vestScheduleAtIndices(address token, uint256[] calldata indexes) external returns (uint256); | ||
|
||
function accountVestedBalance(address, address) external returns(uint256); | ||
} | ||
|
||
interface IKyberFactory { | ||
function getPools(IERC20 token0, IERC20 token1) external view returns (address[] memory _tokenPools); | ||
} | ||
|
||
interface IDMMPool { | ||
function kLast() external view 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
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,125 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.7; | ||
|
||
import "./zapper-base.sol"; | ||
import "../interfaces/gaugeproxy.sol"; | ||
|
||
contract SnowglobeZapAvaxVector is ZapperBase { | ||
address public gaugeProxy = 0x215D5eDEb6A6a3f84AE9d72962FEaCCdF815BF27; | ||
|
||
constructor() | ||
public ZapperBase(0x60aE616a2155Ee3d9A68541Ba4544862310933d4){ | ||
|
||
} | ||
|
||
function zapOutAndSwap(address snowglobe, uint256 withdrawAmount, address desiredToken, uint256 desiredTokenOutMin) public override { | ||
(IGlobe vault, IUniPair pair) = _getVaultPair(snowglobe); | ||
address token0 = pair.token0(); | ||
address token1 = pair.token1(); | ||
require(token0 == desiredToken || token1 == desiredToken, "desired token not present in liquidity pair"); | ||
|
||
vault.safeTransferFrom(msg.sender, address(this), withdrawAmount); | ||
vault.withdraw(withdrawAmount); | ||
_removeLiquidity(address(pair), address(this)); | ||
|
||
address swapToken = token1 == desiredToken ? token0 : token1; | ||
_approveTokenIfNeeded(swapToken, address(router)); | ||
(IERC20[] memory path, ) = _swapToken(swapToken, desiredToken, IERC20(swapToken).balanceOf(address(this))); | ||
|
||
_returnAssets(path); | ||
} | ||
|
||
function _swapAndStake(address snowglobe, uint256 tokenAmountOutMin, address tokenIn) public override { | ||
(IGlobe vault, IUniPair pair) = _getVaultPair(snowglobe); | ||
|
||
(uint256 reserveA, uint256 reserveB, ) = pair.getReserves(); | ||
require(reserveA > minimumAmount && reserveB > minimumAmount, "Liquidity pair reserves too low"); | ||
|
||
address token0 = pair.token0(); // first token in the pool | ||
address token1 = pair.token1(); // second token in the pool | ||
|
||
bool isInputA = token0 == tokenIn; | ||
require(isInputA || token1 == tokenIn, "Input token not present in liquidity pair"); | ||
|
||
address[] memory path = new address[](2); | ||
path[0] = tokenIn; | ||
path[1] = isInputA ? token1 : token0; | ||
|
||
uint256 fullInvestment = IERC20(tokenIn).balanceOf(address(this)); | ||
uint256 swapAmountIn; | ||
if (isInputA) { | ||
swapAmountIn = _getSwapAmount(fullInvestment, reserveA, reserveB); | ||
} else { | ||
swapAmountIn = _getSwapAmount(fullInvestment, reserveB, reserveA); | ||
} | ||
|
||
_approveTokenIfNeeded(path[0], address(router)); | ||
(IERC20[] memory paths, uint256[] memory amounts) = _swapToken(path[0], path[1] , swapAmountIn); | ||
|
||
_approveTokenIfNeeded(path[1], address(router)); | ||
(, , uint256 amountLiquidity) = IJoeRouter(router).addLiquidity( | ||
path[0], | ||
path[1], | ||
fullInvestment.sub(amounts[0]), | ||
amounts[1], | ||
1, | ||
1, | ||
address(this), | ||
block.timestamp | ||
); | ||
|
||
_approveTokenIfNeeded(address(pair), address(vault)); | ||
vault.deposit(amountLiquidity); | ||
|
||
//add to guage if possible instead of returning to user, and so no receipt token | ||
vault.safeTransfer(msg.sender, vault.balanceOf(address(this))); | ||
|
||
//taking receipt token and sending back to user | ||
vault.safeTransfer(msg.sender, vault.balanceOf(address(this))); | ||
|
||
//interact with gauge proxy to get gauge address | ||
address gaugeAddress = IGaugeProxyV2(gaugeProxy).getGauge(snowglobe); | ||
|
||
//deposit for into gauge | ||
IGaugeV2(gaugeAddress).depositFor(vault.balanceOf(msg.sender), msg.sender); | ||
|
||
_returnAssets(paths); | ||
} | ||
|
||
function _getSwapAmount(uint256 investmentA, uint256 reserveA, uint256 reserveB) public view override returns (uint256 swapAmount) { | ||
uint256 halfInvestment = investmentA.div(2); | ||
uint256 nominator = IJoeRouter(router).getAmountOut( | ||
AbigailTCameron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
halfInvestment, | ||
reserveA, | ||
reserveB | ||
); | ||
uint256 denominator = IJoeRouter(router).quote( | ||
halfInvestment, | ||
reserveA.add(halfInvestment), | ||
reserveB.sub(nominator) | ||
); | ||
swapAmount = investmentA.sub( | ||
Babylonian.sqrt( | ||
(halfInvestment * halfInvestment * nominator) / denominator | ||
) | ||
); | ||
} | ||
|
||
function estimateSwap(address snowglobe, address tokenIn, uint256 fullInvestmentIn) public view returns (uint256 swapAmountIn, uint256 swapAmountOut, address swapTokenOut){ | ||
(, IUniPair pair) = _getVaultPair(snowglobe); | ||
AbigailTCameron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
bool isInputA = pair.token0() == tokenIn; | ||
require(isInputA || pair.token1() == tokenIn, "Input token not present in liquidity pair"); | ||
|
||
(uint256 reserveA, uint256 reserveB, ) = pair.getReserves(); | ||
(reserveA, reserveB) = isInputA ? (reserveA, reserveB) : (reserveB, reserveA); | ||
|
||
swapAmountIn = _getSwapAmount(fullInvestmentIn, reserveA, reserveB); | ||
swapAmountOut = IJoeRouter(router).getAmountOut( | ||
swapAmountIn, | ||
reserveA, | ||
reserveB | ||
); | ||
swapTokenOut = isInputA ? pair.token1() : pair.token0(); | ||
} | ||
} |
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.