Indexed Finance
Search…
UnboundTokenSeller.sol

UnboundTokenSeller

Contract for swapping undesired tokens to desired tokens for an index pool.
This contract is deployed as a proxy for each index pool. When tokens are unbound from a pool, they are transferred to this contract and sold on UniSwap or to anyone who calls the contract in exchange for any token which is currently bound to its index pool and which has a desired weight about zero.
It uses a short-term uniswap price oracle to price swaps and has a configurable slippage rate which determines the range around the moving average for which it will accept a trade.

constructor

1
function constructor(contract IUniswapV2Router02 uniswapRouter, contract UniSwapV2PriceOracle oracle, address controller)
Copied!

Controls

initialize

1
function initialize(contract IPool pool, uint8 premiumPercent)
Copied!
Initialize the proxy contract with the acceptable premium rate and the address of the pool it is for.

setPremiumRate

1
function setPremiumRate(uint8 premiumPercent)
Copied!
Set the premium rate as a percent.

emergencyExecuteSwapTokensForExactTokens

1
function emergencyExecuteSwapTokensForExactTokens(address tokenIn, address tokenOut, uint256 maxAmountIn, uint256 amountOut, address[] path)
Copied!
Emergency function that allows the controller to force a token sale through UniSwap. This exists in case of an emergency which demands immediate removal of a token.

Pool Interaction

handleUnbindToken

1
function handleUnbindToken(address token, uint256 amount)
Copied!
Receive amount of token from the pool.

UniSwap Trades

executeSwapTokensForExactTokens

1
function executeSwapTokensForExactTokens(address tokenIn, address tokenOut, uint256 maxAmountIn, uint256 amountOut, address[] path) returns (uint256 premiumPaidToCaller)
Copied!
Execute a trade with UniSwap to sell some tokens held by the contract for some tokens desired by the pool and pays the caller any tokens received above the minimum acceptable output.

executeSwapExactTokensForTokens

1
function executeSwapExactTokensForTokens(address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut, address[] path) returns (uint256 premiumPaidToCaller)
Copied!
Executes a trade with UniSwap to sell some tokens held by the contract for some tokens desired by the pool and pays the caller any tokens received above the minimum acceptable output.

Caller Trades

swapExactTokensForTokens

1
function swapExactTokensForTokens(address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut) returns (uint256 amountOut)
Copied!
Swap exactly amountIn of tokenIn for at least minAmountOut of tokenOut.

swapTokensForExactTokens

1
function swapTokensForExactTokens(address tokenIn, address tokenOut, uint256 maxAmountIn, uint256 amountOut) returns (uint256 amountIn)
Copied!
Swap up to maxAmountIn of tokenIn for exactly amountOut of tokenOut.

Price Queries

calcInGivenOut

1
function calcInGivenOut(
2
address tokenIn,
3
address tokenOut,
4
uint256 amountOut
5
) returns (uint256 amountIn)
Copied!
Calculate the amount of tokenIn the pool will accept for amountOut of tokenOut.

calcOutGivenIn

1
function calcOutGivenIn(
2
address tokenIn,
3
address tokenOut,
4
uint256 amountIn
5
) returns (uint256 amountOut)
Copied!
Calculate the amount of tokenOut the pool will give for amountIn of tokenIn.
Last modified 1yr ago