Skip to content

Latest commit

 

History

History
353 lines (232 loc) · 8.27 KB

StrategyRouter.md

File metadata and controls

353 lines (232 loc) · 8.27 KB

Solidity API

StrategyRouter

onlyWhitelisted

modifier onlyWhitelisted()

Restrict msg.sender to be externally owned accounts only.

UNIFORM_DECIMALS

uint8 UNIFORM_DECIMALS

We adjust tokens amounts to have uniform number of decimals where needed for calculations.

cycleDuration

uint256 cycleDuration

Minimum time needed before depositing batch balance into strategies.

minUsdPerCycle

uint256 minUsdPerCycle

Minimum batch balance to be deposited into strategies.

minDeposit

uint256 minDeposit

Minimum amount to be deposited into batch by the user.

cycles

mapping(uint256 => struct StrategyRouter.Cycle) cycles

Contains info such as how much were deposited into strategies or price per share in each cycle.

allocateToStrategies

function allocateToStrategies() external

Deposit money collected in the batch into strategies. Can be called when `cycleDuration` seconds has been passed or batch has reached `minUsdPerCycle` amount of coins.

Only callable by user wallets.

compoundAll

function compoundAll() external

Compound all strategies.

Only callable by user wallets.

getSupportedTokens

function getSupportedTokens() public view returns (address[])

Returns list of supported tokens.

getStrategyPercentWeight

function getStrategyPercentWeight(uint256 _strategyId) public view returns (uint256 strategyPercentAllocation)

Returns strategy weight as percent of total weight.

getStrategiesCount

function getStrategiesCount() public view returns (uint256 count)

Returns count of strategies.

getStrategies

function getStrategies() public view returns (struct StrategyRouter.StrategyInfo[])

Returns array of strategies.

getStrategiesBalance

function getStrategiesBalance() public view returns (uint256 totalBalance, uint256[] balances)

Returns amount of tokens in strategies. All returned numbers have `UNIFORM_DECIMALS` decimals.

Name Type Description
totalBalance uint256 Total amount of tokens in strategies.
balances uint256[] Array of token amount in each strategy.

getBatchBalance

function getBatchBalance() public view returns (uint256 totalBalance, uint256[] balances)

Returns token balances and their sum in the batch. Shows total batch balance, possibly not total to be deposited into strategies. because strategies might not take all token supported by router. All returned amounts have `UNIFORM_DECIMALS` decimals.

Name Type Description
totalBalance uint256 Total tokens in the batch.
balances uint256[] Array of token balances in the batch.

receiptToShares

function receiptToShares(uint256 receiptId) public view returns (uint256 shares)

Returns amount of shares retrievable by receipt. Cycle noted in receipt should be closed.

sharesToUsd

function sharesToUsd(uint256 shares) public view returns (uint256 amount)

Calculate how much usd shares representing using current price per share.

Returns amount with uniform decimals

redeemReceiptsToShares

function redeemReceiptsToShares(uint256 receiptId) public returns (uint256 shares)

Convert receipt NFT into share tokens, withdraw functions do it internally. Cycle noted in receipt should be closed.

withdrawFromStrategies

function withdrawFromStrategies(uint256 receiptId, address withdrawToken, uint256 shares, uint256 amount) external

User withdraw usd from strategies via receipt NFT. On partial withdraw leftover shares transfered to user. Receipt is burned. Internally all receipt's shares unlocked from that NFT.

Only callable by user wallets.

Name Type Description
receiptId uint256 Receipt NFT id.
withdrawToken address Supported token that user wish to receive.
shares uint256 Amount of shares to withdraw.
amount uint256 Uniform amount from receipt to withdraw, only for current cycle.

withdrawShares

function withdrawShares(uint256 shares, address withdrawToken) external

User withdraw tokens from strategies via shares. Receipts should be converted to shares prior to call this.

Name Type Description
shares uint256 Amount of shares to withdraw.
withdrawToken address Supported token that user wish to receive.

withdrawFromBatch

function withdrawFromBatch(uint256 receiptId, address withdrawToken, uint256 shares, uint256 amount) external

User withdraw tokens from batch. On partial withdraw amount noted in receipt is updated. Receipt is burned when withdrawing whole amount.

Only callable by user wallets.

Name Type Description
receiptId uint256 Receipt NFT id.
withdrawToken address Supported token that user wish to receive.
shares uint256 Amount of shares to withdraw, specify this if money of receipt were deposited into strategies.
amount uint256 Amount to withdraw, specify this if money of receipt isn't deposited into strategies yet.

depositToBatch

function depositToBatch(address depositToken, uint256 _amount) external

Deposit token into batch. Tokens not deposited into strategies immediately.

_User should approve `amount` of `depositToken` to this contract. Only callable by user wallets.

Name Type Description
depositToken address Supported token to deposit.
_amount uint256 Amount to deposit.

setExchange

function setExchange(contract Exchange newExchange) external

Set address of exchange contract.

Admin function.

setMinUsdPerCycle

function setMinUsdPerCycle(uint256 amount) external

Minimum usd needed to be able to close the cycle.

Admin function.

Name Type Description
amount uint256 Amount of usd, must be `UNIFORM_DECIMALS` decimals.

setMinDepositUsd

function setMinDepositUsd(uint256 amount) external

Minimum to be deposited in the batch.

Admin function.

Name Type Description
amount uint256 Amount of usd, must be `UNIFORM_DECIMALS` decimals.

setCycleDuration

function setCycleDuration(uint256 duration) external

Minimum time needed to be able to close the cycle.

Admin function.

Name Type Description
duration uint256 Duration of cycle in seconds.

addStrategy

function addStrategy(address _strategyAddress, address _depositTokenAddress, uint256 _weight) external

Add strategy.

Admin function. Deposit asset must be supported by the router.

Name Type Description
_strategyAddress address Address of the strategy.
_depositTokenAddress address Asset to be deposited into strategy.
_weight uint256 Weight of the strategy. Used to split user deposit between strategies.

updateStrategy

function updateStrategy(uint256 _strategyId, uint256 _weight) external

Update strategy weight.

Admin function.

Name Type Description
_strategyId uint256 Id of the strategy.
_weight uint256 Weight of the strategy.

removeStrategy

function removeStrategy(uint256 _strategyId) external

Remove strategy, deposit its balance in other strategies.

Admin function.

Name Type Description
_strategyId uint256 Id of the strategy.

rebalanceStrategies

function rebalanceStrategies() external returns (uint256 totalInStrategies, uint256[] balances)

Rebalance strategies, so that their balances will match their weights.

Admin function.

setSupportedToken

function setSupportedToken(address tokenAddress, bool supported) external

Set token as supported for user deposit and withdraw.

Admin function.