Contracts¶
VaultUpgradeable¶
-
contract
VaultUpgradeableis StorageV1ConsumerUpgradeable, ERC20Upgradeable, ICreditor Vault is a baseAsset lender. Vehicles are borrowers that put money to work.
The design logic of the system: Each vault and vehicle is treated as an independent entity. Vault is willing to lend money, but with limited trust on the vehicles Vehicles is willing to borrow money, but only when it is beneficial to how it is using.
Vehicle can potentially borrow from multiple vaults.
Its sole purpose being making money to repay debt and share profits to all stakeholders.
The vault focuses on:
Deciding where the money should be lended to.
Liquidating the returned baseAsset to longAsset.
-
event
Deposit(address indexed _who, uint256 _amount)
-
event
Withdraw(address indexed _who, uint256 _amount)
-
event
Longed(uint256 totalDeposit, uint256 baseProfit, uint256 longedProfit)
-
event
WithdrawFeeUpdated(uint256 _withdrawFeeRatio, uint256 _withdrawalFeeHalfDecayPeriod, uint256 _withdrawalFeeWaivedPeriod)
-
address public
baseAsset
-
address public
longAsset
-
address public
selfCompoundingLongAsset
-
mapping (address => VehicleInfo) public
vInfo
-
mapping (address => bool) public
flashDepositAndWithdrawAllowed
-
mapping (address => uint256) public
lastActivityBlock
-
mapping (address => bool) public
noWithdrawalFee
-
mapping (address => uint256) public
lastFeeTime
-
uint256 public
depositCap
-
mapping (address => uint256) public
withdrawalFeeOccured
-
uint256 public
withdrawFeeRatio
-
uint256 public
withdrawalFeeHalfDecayPeriod
-
uint256 public
withdrawalFeeWaivedPeriod
-
uint256 constant
BPS_UNIT
-
uint256 constant
WITHDRAWAL_FEE_RATIO_CAP
-
EnumerableSetUpgradeable.AddressSet
investmentVehicles
-
bool public
vaultDepositEnabled True if deposit is enabled.
-
address
rewardPool
-
modifier
ifVaultDepositEnabled()
-
modifier
onlyDebtor()
-
modifier
flashDepositAndWithdrawDefence()
-
modifier
timelockPassed(address iv)
-
function
isDebtor(address _target)
public
view
returns (bool) Checks if the target address is debtor
- Parameters
_target – target address
- Return
true if target address is debtor, false if not
-
function
initialize(address _store, address _baseAsset, address _longAsset, uint256 _depositCap)
public
virtual
initializer Initializes the contract
-
function
setRewardPool(address _rewardPool)
public
adminPriviledged Set the reward pool for distributing the longAsset.
See Also: StakingMultiRewardsUpgradable
- Parameters
_rewardPool – Address of the reward pool.
-
function
deposit(uint256 amount)
public
virtual Deposit baseAsset into the vault
- Parameters
amount – The amount of baseAsset deposited from the user
-
function
depositFor(address targetAccount, uint256 amount)
public
virtual Deposit baseAsset into the vault for targetAccount.
- Parameters
targetAccount – Target account to deposit for
amount – The amount of baseAsset deposited from the user
-
function
_deposit(address assetFrom, address shareTo, uint256 amount)
internal
virtual
ifVaultDepositEnabled
flashDepositAndWithdrawDefence
-
function
_accountWithdrawFeeAtDeposit(address _who, uint256 _amount)
internal
-
function
withdraw(uint256 amount)
public
virtual
flashDepositAndWithdrawDefence Withdraw the baseAsset from the vault. Always withdraws 1:1, then distributes withdrawal fee because the interest has already been paid in other forms. The actual amount of the baseAsset user received is subjet to the pending withdraw fee.
- Parameters
amount – Amount of the baseAsset to be withdrawed from the vault.
-
function
_withdrawSendwithFee(address _who, uint256 _sendAmount)
internal
-
function
withdrawAllFromIV(address _iv)
public
opsPriviledged Withdral all the baseAsset from an IV.
- Parameters
_iv – Address of the IV.
-
function
withdrawFromIV(address _iv, uint256 _amount)
public
opsPriviledged Withdral ceterain amount of the baseAsset from an IV.
- Parameters
_iv – Address of the IV.
_amount – Amount of the baseAsset to be withdrawed.
-
function
withdrawFromIVs(address[] memory _ivs, uint256[] memory _amounts)
public
opsPriviledged Withdral ceterain amount of the baseAsset from multiple IVs. See withdrawFromIV for details.
-
function
withdrawAllFromIVs(address[] memory _ivs)
public
opsPriviledged Withdral all the baseAsset from multiple IVs. See withdrawAllFromIV for details.
-
function
_withdrawFromIV(address iv, uint256 amount)
internal
-
function
_accountingDebtRepayment(address _debtor, uint256 repaymentAmountInBase)
internal
-
function
_accountingFundsLendingOut(address _debtor, uint256 _fundsSentOutInBase)
internal
-
function
investAll()
public
opsPriviledged Invest all the available baseAsset in the vault.
-
function
investTo(address _target, uint256 _amount)
public
opsPriviledged Invest certain amount of the baseAsset in the vault to an IV.
- Parameters
_target – Address of the IV.
_amount – Amount of the baseAsset to be invested.
-
function
investToIVs(address[] memory _targets, uint256[] memory _amounts)
public
opsPriviledged Invest certain amount of the baseAsset in the vault to multiple IVs.
-
function
migrateFunds(address _fromIv, address _toIv, uint256 _pullAmount, uint256 _pushAmount)
public
opsPriviledged Migrate certain amount of the baseAsset from one IV to another.
- Parameters
_fromIv – Address of the source IV.
_toIv – Address of the destination IV.
_pullAmount – Amount of the baseAsset to be pulled out from old IV.
_pushAmount – Amount of the baseAsset to be pushed into the new IV.
-
function
effectiveLendCapacity(address _target)
public
view
returns (uint256) Calculate the lending capacity of an IV. This vault cannot lend baseAsset with amount more than the lending capacity.
- Parameters
_target – Address of the IV.
- Return
Return the lending capacity. (Unit: BPS_UNIT)
-
function
_investTo(address _target, uint256 _maxAmountBase)
internal
virtual
returns (uint256)
-
function
addInvestmentVehicle(address newVehicle, uint256 _lendMaxBps, uint256 _lendCap)
public
adminPriviledged
timelockPassed(newVehicle)
returns (uint256) Add an investment vehicle.
- Parameters
newVehicle – Address of the new IV.
_lendMaxBps – Lending capacity of the IV in ratio.
_lendCap – Lending capacity of the IV.
-
function
moveInvestmentVehicleToLowestPriority(address iv)
external
adminPriviledged This moves an IV to the lowest withdraw priority.
- Parameters
iv – Address of the IV.
-
function
removeInvestmentVehicle(address _target)
public
adminPriviledged Remove an IV from the vault.
- Parameters
_target – Address of the IV.
-
function
investmentVehiclesLength()
public
view
returns (uint256) - Return
Return the number of the IVs added to this vault.
-
function
getInvestmentVehicle(uint256 idx)
public
view
returns (address) - Parameters
idx – Index of the IV.
- Return
Return the address of an IV.
-
function
baseAssetDebtOf(address _iv)
public
view
returns (uint256) - Parameters
_iv – Address of the IV.
- Return
Return the debt (in baseAsset) of an IV
-
function
collectAndLong(address[] memory ivs, uint256 minimumLongProfit)
public
opsPriviledged
virtual Collect the interest from IVs and convert them into longAsset. The converted longAsset would be distribute to user through the reward pool.
See also: StakingMultiRewardsUpgradeable
- Parameters
ivs – List of IVs to collect interest from.
minimumLongProfit – The minimum LongProfit collected.
-
function
_distributeProfit(uint256 longedProfit)
internal
-
function
interestPendingInIV(address iv)
public
view
returns (uint256) Return the intest (profit) of the vault in an IV. The interest is defined as the baseAsset balance of the vault in IV minus the debt that the IV owed the vault.
- Parameters
iv – The address of the IV.
- Return
The interest of the vault in the IV.
-
function
_updateRewards(address targetAddr)
internal
-
function
_transfer(address sender, address recipient, uint256 amount)
internal
virtual
override
-
function
_mint(address account, uint256 amount)
internal
virtual
override
-
function
_burn(address account, uint256 amount)
internal
virtual
override
-
function
setDepositCap(uint256 _depositCap)
public
adminPriviledged Set the deposit cap.
- Parameters
_depositCap – Deposit cap (in baseAsset) of the vault.
-
function
setDepositEnabled(bool _flag)
public
adminPriviledged Set the deposit enabled flag.
- Parameters
_flag – True if the deposit is enabled.
-
function
setFlashDepositAndWithdrawAllowed(address[] memory _targets, bool _flag)
public
adminPriviledged
-
function
setNoWithdrawalFee(address[] memory _targets, bool _flag)
public
adminPriviledged Add accounts to the no-withdrawl fee white list.
-
function
setWihdrawFeeParameter(uint256 _withdrawFeeRatio, uint256 _withdrawalFeeHalfDecayPeriod, uint256 _withdrawalFeeWaivedPeriod)
external
adminPriviledged Set the withdraw fee parametrs. See the withdraw fee documentation for more details
- Parameters
_withdrawFeeRatio – The withdraw fee ratio. Unit: BPS_UNIT
_withdrawalFeeHalfDecayPeriod – The half-decay period of the withdraw fee. [second]
_withdrawalFeeWaivedPeriod – The withdraw fee waived period. [second]
-
function
_setWihdrawFeeParameter(uint256 _withdrawFeeRatio, uint256 _withdrawalFeeHalfDecayPeriod, uint256 _withdrawalFeeWaivedPeriod)
internal
-
function
withdrawalFeePending(address _who)
public
view
returns (uint256 fee) Calculate the current unsettled withdraw fee.
- Parameters
_who – The address to calculate the fee.
- Return
fee Return the amount of the withdraw fee (as baseAsset).
-
function
setLongSelfCompounding(address _selfCompoundingLong)
public
adminPriviledged Set the self-compounding vault for the long asset.
See also: SelfCompoundingYieldUpgradable
- Parameters
_selfCompoundingLong – Address of the self-compounding vault.
StakingMultiRewardsUpgradeable¶
-
contract
StakingMultiRewardsUpgradeableis IStakingMultiRewards, StorageV1ConsumerUpgradeable, ReentrancyGuardUpgradeable Multi-reward staking pool. This reward is used for dsitributing the longAsset from the vault. This is a generalized version of the staking pool from synthetix. Additionally, users of the vault does not need to manually “stake” into this reward pool. They are automatically staked when they hold the vault tokens.
See also: https://docs.synthetix.io/contracts/source/contracts/stakingrewards
-
address public
vaultAddress Address of vault associated with this reward pool.
-
mapping (address => bool)
rewardsDistribution
-
mapping (address => Yield) public
yieldInfo
-
EnumerableSetUpgradeable.AddressSet
yields
-
modifier
onlyRewardsDistribution()
-
function
initialize(address _store, address _rewardsDistribution, address _vaultAddress, address _yieldToken, uint256 _yieldDuration, bool _isSelfCompounding)
public
initializer
-
function
setRewardDistribution(address[] calldata _rewardDistributions, bool _flag)
external
override
adminPriviledged Reward Distribution
-
function
notifyTargetRewardAmount(address targetYield, uint256 reward)
external
override
onlyRewardsDistribution
-
function
totalSupply()
public
view
override
returns (uint256)
-
function
updateAllRewards(address targetAccount)
public
override
-
function
updateReward(address targetYield, address targetAccount)
public
override
-
function
lastTimeRewardApplicable(address targetYield)
public
view
override
returns (uint256)
-
function
rewardPerToken(address targetYield)
public
view
override
returns (uint256)
-
function
earnedUnwrapped(address targetYield, address account)
public
view
returns (uint256) Calculate the amount of reward token earned by a user. If the reward token is the share of a self-compounding vault, calculate the reward as the underlying bassetAsset.
- Parameters
targetYield – Address of the reward token.
account – Address of the user account
- Return
Return the amount of reward token earned (as the baseAsset if the targetYield is a self-compound vault.).
-
function
earned(address targetYield, address account)
public
view
override
returns (uint256) Calculate the amount of reward token earned by a user
- Parameters
targetYield – Address of the reward token.
account – Address of the user account
- Return
Return the amount of reward token earned.
-
function
getAllRewards()
public
override Claim all the rewards. See getRewardFor for details.
-
function
getAllRewardsFor(address user)
public
override Claim all the rewards for a user. See getRewardFor for details.
- Parameters
user – Address of the user.
-
function
getReward(address targetYield)
public
override Claim the reward. See getRewardFor for details.
- Parameters
targetYield – The address of the reward.
-
function
getRewardFor(address user, address targetYield)
public
override Claim the reward for a user. If the reward is the share of self-compound asset, baseAsset of the vault would be withdrawed and sent to the user.
- Parameters
targetYield – The address of the reward.
user – Address of the user.
-
function
_getReward(address user, address targetYield)
internal
-
function
addReward(address targetYield, uint256 duration, bool isSelfCompoundingYield)
external
adminPriviledged
override Add a new reward to the reward pool.
- Parameters
targetYield – Address of the new reward token.
duration – Reward distribution duration.
isSelfCompoundingYield – If the new reward is the share of a self-compounding vault.
-
function
removeReward(address targetYield)
external
adminPriviledged
override
-
event
RewardNotified(address targetYield, uint256 amount)
-
event
RewardAdded(address targetYield)
-
event
RewardRemoved(address targetYield)
-
event
RewardPaid(address indexed user, address targetYield, uint256 reward)
-
event
RewardsDurationUpdated(address targetYield, uint256 newDuration)
-
event
Recovered(address token, uint256 amount)
-
event
RewardPayOut(address targetYield, uint256 gained, address to)
-
address public
InvestmentVehicleSingleAssetBaseV1Upgradeable¶
InvestmentVehicleSingleAssetBaseV1Upgradeable is the base contract for single asset IVs. It will receive only one kind of asset and invest into an investment opportunity. Every once in a while, operators should call the collectProfitAndDistribute to perform accounting for relevant parties.
Apart from the usual governance and operators, there are two roles for an IV:
“creditors” who lend their asset
“beneficiaries” who provide other services. (e.g. insurance, operations, tranches, boosts)
Interest are accrued to their contribution respectively. Creditors gets their interest with respect to their lending amount, whereas the governance will set the ratio that is distributed to beneficiaries.
-
contract
InvestmentVehicleSingleAssetBaseV1Upgradeableis StorageV1ConsumerUpgradeable, IDebtor -
uint256 public constant
RATIO_DENOMINATOR
-
uint256 public constant
ASSET_ID_BASE
-
uint256 public constant
SHARE_UNIT
-
uint256 constant
ROLE_OPERATIONS
-
uint256 constant
ROLE_INSURER
-
address public
baseAsset
-
uint256 public
totalShares
-
uint256 public
sharePrice
-
mapping (address => uint256) public
shareBalance
-
event
DividendClaimed(address _who, uint256 amount)
-
event
BeneficiaryAdded(address _target, uint256 _psRatio, uint256 _psRole)
-
event
BeneficiaryRemoved(address _target)
-
event
VaultRemoved(address _target)
-
event
CreditorWithdrawn(address _creditor, uint256 _baseAssetRequested, uint256 _baseAssetTransferred)
-
event
CreditorInvested(address _creditor, uint256 _baseAssetInvested, uint256 shareMinted)
-
event
OpsInvestmentPulled(uint256 _amount)
-
event
OpsInvestAll()
-
event
OpsCollectProfit(uint256 baseAssetProfit)
-
event
InsuranceClaimFiled(uint256 filedAmount)
-
mapping (address => ProfitShareInfo) public
psInfo
-
EnumerableSetUpgradeable.AddressSet
psList
-
mapping (address => bool) public
activeCreditor Whitelist the vaults/ creditors for depositing funds into the IV.
-
address[] public
profitAssets
-
mapping (address => uint256) public
profitAssetHeld
-
modifier
onlyBeneficiary()
-
modifier
onlyCreditor()
-
function
initialize(address _store, address _baseAsset)
public
virtual
initializer
-
function
isBeneficiary(address _address)
public
view
returns (bool) Check if a target is a beneficiary (profit share).
- Parameters
_address – target address
- Return
Return true if the address is a beneficiary.
-
function
addCreditor(address _target)
public
adminPriviledged Add a creditor (typically a vault) to whitelist.
- Parameters
_target – Address of the creditor.
-
function
claimDividendAsBeneficiary()
external
returns (uint256) Claim the dividend.
-
function
claimDividendForBeneficiary(address _who)
external
opsPriviledged
returns (uint256) Claim the dividend for a beneficiary.
- Parameters
_who – Address of the beneficiary.
-
function
_claimDividendForBeneficiary(address _who)
internal
returns (uint256)
-
function
removeVault(address _target)
public
adminPriviledged Remove the target address from the whitelist for further depositing funds into IV. The target address can still withdraw the deposited funds.
- Parameters
_target – Vault address.
-
function
addBeneficiary(address _target, uint256 _psRatio, uint256 _psRole)
public
adminPriviledged Adds a beneficiary to the Investment Vehicle. A beneficiary is a party that benefits the Investment Vehicle, thus should gain something in return.
- Parameters
_target – Address of the new beneficiary
_psRatio – Profit sharing ratio designated to the beneficiary
_psRole – an identifier for different roles in the protocol
-
function
removeBeneficiary(address _target)
public
adminPriviledged Remove the target address from the beneciary list. The target address will no longer receive dividend. However, the target address can still claim the existing dividend.
- Parameters
_target – Address of the beneficiary that is being removed.
-
function
psListLength()
public
view
returns (uint256) Returns the length of the profit sharing list
-
function
withdrawAsCreditor(uint256 _baseAssetRequested)
external
override
returns (uint256) Interacting with creditors Creditor withdraws funds. If _baseAssetRequested is less than the asset that the vehicle can provide, it will withraw as much as possible.
- Parameters
_baseAssetRequested – the amount of base asset requested by the creditor
- Return
The actual amount that the IV has sent back.
-
function
askToInvestAsCreditor(uint256 _amount)
external
onlyCreditor
override
returns (uint256) Creditor pushing more funds into vehicle returns how much funds was accepted by the vehicle.
- Parameters
_amount – the amount of base asset that the creditor wants to invest.
- Return
The amount that was accepted by the IV.
-
function
pullFundsFromInvestment(uint256 _amount)
external
opsPriviledged Interacting with underlying investment opportunities Operator can use this to pull funds out from investment to ease the operation such as moving the funds to another iv, emergency exit, etc.
- Parameters
_amount – the amount of funds that we are removing from the investment opportunity
-
function
_pullFundsFromInvestment(uint256 _amount)
internal
virtual Pull the funds from the underlying investment opportunities. This function will do best effor to pull the requested amount of funds. However, the exact amount of funds pulled is not guaranteed.
-
function
investAll()
public
opsPriviledged
virtual
-
function
_investAll()
internal
virtual
-
function
fileInsuanceClaim()
public Anyone can call the function when the IV has more debt than funds in the investment opportunity, this means that it has lost money and could file for insurance. The function would calculate the lost amount automatically, and call contracts that have provided insurance. If the loss is negligible, the function will not call the respective contracts.
-
function
_fileInsuranceClaimAmount(uint256 _amount)
internal
-
function
collectProfitAndDistribute(uint256 minBaseProfit)
external
virtual
opsPriviledged Collecting profits Operators can call this to account all the profit that has accumulated to all the creditors and beneficiaries of the IV.
- Parameters
minBaseProfit – the minimum profit that should be accounted.
-
function
_collectProfitAsBaseAsset()
internal
virtual
returns (uint256 baseAssetProfit)
-
function
_accountProfit(uint256 baseAssetProfit)
internal
-
function
invested()
public
view
virtual
returns (uint256) View functions
-
function
profitsPending()
public
view
virtual
returns (uint256) Returns the profit that has not been accounted.
- Return
The pending profit in the investment opportunity yet to be accounted.
-
function
shareBalanceAsBaseAsset(uint256 _shareBalance)
public
view
returns (uint256) Converts IV share to amount in base asset
- Parameters
_shareBalance – the share amount
- Return
the equivalent base asset amount
-
function
baseAssetAsShareBalance(uint256 _baseAssetAmount)
public
view
returns (uint256) Converts base asset amount to share amount
- Parameters
_baseAssetAmount – amount in base asset
- Return
the equivalent share amount
-
function
baseAssetBalanceOf(address _address)
public
view
override
returns (uint256) Returns base asset amount that an address holds
- Parameters
_address – the target address, could be a creditor or beneficiary.
- Return
base asset amount of the target address
-
function
totalDebt()
public
view
returns (uint256) Returns the total debt of the IV.
- Return
the total debt of the IV.
-
uint256 public constant
SwapCenter¶
-
contract
SwapCenteris ISwap, ReentrancyGuard, Ownable SwapCenter is used for:
Converting the baseAsset to longAsset in the Vault
Helping users deposit to the Vault with alterative assets.
The asset swapping is done with pre-defined routes accross multiple external DEXs and contracts.
-
mapping (address => mapping (address => Route))
routes
-
uint256 constant
WETH_ID
-
uint256 constant
VAULT_DEPOSIT_ID
-
uint256 constant
UNISWAPV2_ID
-
uint256 constant
SUSHISWAP_ID
-
uint256 constant
ONEINCHAMM_ID
-
uint256 constant
ONEINCHAGG_ID
-
uint256 constant
FARMVAULT_ID
-
uint256 constant
SUSHIBAR_ID
-
uint256 constant
UNISWAPV3_ID
-
uint256 constant
CURVE_RM_LIQ_ID
-
uint256 constant
CURVE_ADD_LIQ_ID
-
address constant
ETH_ADDRESS
-
mapping (address => mapping (address => address))
oneInchAMM_pools
-
mapping (address => mapping (address => uint24))
uniV3_fees
-
mapping (address => address)
curvePool
-
address public
referralAddress
-
constructor()
-
function
setReferalAddress(address _newReferral)
public
onlyOwner Set the referal addresss.
- Parameters
_newReferral – The referral address.
-
function
isETH(address token)
public
pure
returns (bool) - Parameters
token – address
- Return
Return true if the address is ETH_ADDRESS
-
function
getExchangeOrder(address tokenIn, address tokenOut)
public
view
returns (uint256[] memory) Get the exchangeOrder for swapping a pair of token.
- Return
exchangeOrder. See setRoute function for details.
-
function
getPath(address tokenIn, address tokenOut)
public
view
returns (address[][] memory) Get the path for swapping a pair of token.
- Return
path. See setRoute function for details.
-
function
setRoute(address input, address output, uint256[] memory exchangeOrder, address[][] memory path)
public
onlyOwner Set the pre-defined route for swapping a pair of token. To create a reversed swapping route, a separate route has to be created.
- Parameters
input – Address of the input token.
output – Address of the output token.
exchangeOrder – A list of DEXs or contracts used for swapping.
path – A list of paths used in each DEXs or contracts for swapping. The length of path should be the same as the length of exchangeOrder.
-
function
setRouteBatch(address[] memory input, address[] memory output, uint256[][] memory exchangeOrder, address[][][] memory path)
public
onlyOwner Create pre-defined routes in batch. See setRoute function for details.
-
function
swapExactTokenIn(address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut)
external
override
payable
nonReentrant
returns (uint256) Swap the tokens with pre-defined routes.
- Parameters
tokenIn – Address of the input token.
tokenOut – Address of the output token.
amountIn – Amount of the input token.
minAmountOut – The minimum amount of the output token expected to receive. If the output amount is smaller than this value, the transaction will be reverted.
-
function
_swapExactTokenIn_uniswapType(address router, address[] memory path)
internal
-
function
setOneInchPool(address token1, address token2, address pool)
external
onlyOwner Set the 1inch AMM pool to use. The order of token1 and token2 doesn’t matter.
- Parameters
token1 – One of the token in the AMM pool.
token2 – One of the token in the AMM pool.
pool – The address of the 1inch AMM pool.
-
function
_swapOneInchAMM(address[] memory path)
internal
-
function
_swapOneInchAgg(address[] memory path)
internal
-
function
_swapIFARM(address[] memory path)
internal
-
function
_swapXSUSHI(address[] memory path)
internal
-
function
setUniV3Fee(address token1, address token2, uint24 fee)
external
onlyOwner Set the Uniswap V3 fee for swapping token1 and token2. The order of token1 and token2 doesn’t matter.
- Parameters
token1 – One of the token in the AMM pool.
token2 – One of the token in the AMM pool.
fee – The Uniswap V3 fee.(LOW = 500, MEDIUM = 3000, HIGH = 10000)
-
function
getUniV3Fee(address token1, address token2)
public
view
returns (uint24 fee) Get the Uniswap V3 fee for swapping token1 and token2. The order of token1 and token2 doesn’t matter.
- Parameters
token1 – One of the token in the AMM pool.
token2 – One of the token in the AMM pool.
- Return
fee The Uniswap V3 fee.(LOW = 500, MEDIUM = 3000, HIGH = 10000)
-
function
_swapUniSwapV3(address[] memory path)
internal
-
function
_swapAddCurveLiquidity(address[] memory path)
internal
-
function
_swapRemoveCurveLiquidity(address[] memory path)
internal
-
function
_swapDepositVault(address[] memory path)
internal
-
function
_swapWETH(address[] memory path)
internal
-
function
rescueETH(address)
payable
to Rescue ETH from the SwapCenter.
- Parameters
to – The address that eth will be sent to.
YearnV2VaultV1Base¶
-
contract
YearnV2VaultV1Baseis InvestmentVehicleSingleAssetBaseV1Upgradeable YearnV2VaultV1Base is the IV implementation that targets Yearn V2 vaults. It takes the base asset and deposits into the external Yearn vaults
-
address public
yearnVault
-
uint256
YEARN_SHARE_UNIT
-
function
initialize(address _store, address _baseAsset, address _yVault)
public
initializer initialize the iv with yearn external yearn vault and its respective base asset
- Parameters
_store – the address of system storage
_baseAsset – the address of base asset
_yVault – the address of the external yearn vault
-
function
baseAssetToYVaultShares(uint256 baseAssetAmount)
public
view
returns (uint256) calculates the respective yearn vault shares from base asset
- Parameters
baseAssetAmount – the amount of base asset provided
- Return
the amount of respective yearn vault shares
-
function
yVaultSharesToBaseAsset(uint256 shares)
public
view
returns (uint256) calculates the respective base asset amount from yearn vault shares
- Parameters
shares – the amount of yearn vault shares
- Return
the amount of respective base asset
-
function
_investAll()
internal
override
-
function
_pullFundsFromInvestment(uint256 _baseAmount)
internal
override Interacting with underlying investment opportunities
-
function
_collectProfitAsBaseAsset()
internal
override
returns (uint256)
-
function
totalYearnVaultShares()
public
view
returns (uint256 totalShares) View functions exposes the amount of yearn vault shares owned by this IV
- Return
totalShares the yearn vault shares that is owned by this IV
-
function
invested()
public
view
override
returns (uint256) calculates the amount of base asset that is deposited into yearn vault
- Return
amount of base asset in yearn vault
-
function
profitsPending()
public
view
override
returns (uint256) calculates the amount of profit that has not been accounted in the system this is useful for the operators to determine whether it is time to call collectProfitAndDistribute or not.
- Return
the amount of profit that has not been accounted yet
-
address public
TimelockProxy¶
-
contract
TimelockProxyis Proxy TimelockProxy is a proxy implementation that timelocks the implementation switch. The owner is stored in the contract storage of this proxy.
-
bytes32 private constant
_OWNER_SLOT
-
bytes32 private constant
_TIMELOCK_SLOT
-
bytes32 private constant
_IMPLEMENTATION_SLOT
-
event
UpgradeScheduled(address indexed implementation, uint256 activeTime)
-
event
Upgraded(address indexed implementation)
-
event
OwnershipTransferScheduled(address indexed newOwner, uint256 activeTime)
-
event
OwnershipTransfered(address indexed newOwner)
-
event
TimelockUpdateScheduled(uint256 newTimelock, uint256 activeTime)
-
event
TimelockUpdated(uint256 newTimelock)
-
constructor(address _logic, address _owner, uint256 _timelock, bytes memory _data)
-
modifier
ifProxyOwner()
-
modifier
requireTimelockPassed(bytes32 _slot)
-
function
proxyScheduleAddressUpdate(bytes32 _slot, address targetAddress)
public
ifProxyOwner
-
function
proxyScheduleTimelockUpdate(uint256 newTimelock)
public
ifProxyOwner
-
function
proxyUpgradeTimelock()
public
ifProxyOwner
requireTimelockPassed(_TIMELOCK_SLOT)
-
function
proxyUpgradeImplementation()
public
ifProxyOwner
requireTimelockPassed(_IMPLEMENTATION_SLOT)
-
function
proxyUpgradeOwner()
public
ifProxyOwner
requireTimelockPassed(_OWNER_SLOT)
-
function
_implementation()
internal
view
override
returns (address impl)
-
bytes32 private constant
TimelockProxyStorageCentered¶
-
contract
TimelockProxyStorageCenteredis Proxy TimelockProxyStorageCentered is a proxy implementation that timelocks the implementation switch. The owner is stored in the system storage (StorageV1Upgradeable) and not in the contract storage of the proxy.
-
bytes32 private constant
_SYSTEM_STORAGE_SLOT
-
bytes32 private constant
_TIMELOCK_SLOT
-
bytes32 private constant
_IMPLEMENTATION_SLOT
-
event
UpgradeScheduled(address indexed implementation, uint256 activeTime)
-
event
Upgraded(address indexed implementation)
-
event
TimelockUpdateScheduled(uint256 newTimelock, uint256 activeTime)
-
event
TimelockUpdated(uint256 newTimelock)
-
constructor(address _logic, address _storage, uint256 _timelock, bytes memory _data)
-
modifier
adminPriviledged()
-
modifier
requireTimelockPassed(bytes32 _slot)
-
function
proxyScheduleImplementationUpdate(address targetAddress)
public
adminPriviledged
-
function
proxyScheduleTimelockUpdate(uint256 newTimelock)
public
adminPriviledged
-
function
proxyUpgradeTimelock()
public
adminPriviledged
requireTimelockPassed(_TIMELOCK_SLOT)
-
function
proxyUpgradeImplementation()
public
adminPriviledged
requireTimelockPassed(_IMPLEMENTATION_SLOT)
-
function
_implementation()
internal
view
override
returns (address impl)
-
function
_systemStorage()
internal
view
returns (address systemStorage)
-
bytes32 private constant
TimelockRegistryUpgradeable¶
-
contract
TimelockRegistryUpgradeableis StorageV1ConsumerUpgradeable TimelockRegistryUpgradeable is the place where we store all the timelock information between contracts except for proxy switching implementation.
Once the vault hooks up to this contract and have the timelock setting enabled here, adding iv to the vault would be timelocked. There is also an option to add an IV to the whole system, this way it is only timelocked once in the system and improves efficiency while maintaining the initial runaway time.
-
EnumerableSetUpgradeable.AddressSet
ivForGlobal
-
mapping (address => uint256) public
ivForGlobalActiveTime
-
mapping (address => EnumerableSetUpgradeable.AddressSet)
ivForVault
-
mapping (address => mapping (address => uint256)) public
ivForVaultActiveTime
-
mapping (address => EnumerableSetUpgradeable.AddressSet)
ivToBeInsuredByInsuranceVault
-
mapping (address => mapping (address => uint256)) public
ivToBeInsuredByInsuranceVaultActiveTime
-
mapping (address => bool) public
vaultTimelockEnabled
-
uint256 public constant
timelockChangeDelay
-
uint256 public
timelockDelay
-
uint256 public
newTimelockDelay
-
uint256 public
newTimelockActiveTime
-
event
TimelockDelayChanged(uint256 _newTimelockDelay)
-
event
VaultTimelockEnabled(address indexed _vault)
-
event
VaultIVAnnounced(address indexed _vault, address indexed _iv, uint256 activeTime)
-
event
GlobalIVAnnounced(address indexed _iv, uint256 activeTime)
-
event
InsuranceIVAnnounced(address indexed _insuranceVault, address indexed _iv, uint256 activeTime)
-
event
VaultIVRemoved(address indexed _vault, address indexed _iv)
-
event
GlobalIVRemoved(address indexed _iv)
-
event
InsurnaceIVRemoved(address indexed _insuranceVault, address indexed _iv)
-
function
initialize(address _store)
public
override
virtual
initializer
-
function
effectiveTimelock()
public
view
returns (uint256)
-
function
changeTimelockDelay(uint256 _newTimelockDelay)
public
onlyGovernance
-
function
enableVaultTimelock(address _vault)
public
adminPriviledged
-
function
announceIVForVault(address vault, address iv)
public
adminPriviledged
-
function
announceIVForGlobal(address iv)
public
adminPriviledged
-
function
announceIVToBeInsuredByInsuranceVault(address vault, address iv)
public
adminPriviledged
-
function
isIVActiveGlobal(address iv)
public
view
returns (bool)
-
function
isIVActiveForVault(address vault, address iv)
public
view
returns (bool)
-
function
isIVInsuredByInsuranceVault(address vault, address iv)
public
view
returns (bool)
-
function
removeIVForVault(address vault, address iv)
public
adminPriviledged
-
function
removeIVForGlobal(address iv)
public
adminPriviledged
-
function
stopFutureInsuringIV(address vault, address iv)
public
adminPriviledged
-
EnumerableSetUpgradeable.AddressSet
SelfCompoundingYieldUpgradeable¶
-
contract
SelfCompoundingYieldUpgradeableis StorageV1ConsumerUpgradeable, ERC20Upgradeable, ICreditor SelfCompoundingYieldUpgradeable is a special type of vault where only whitelisted addresses can deposit. It also works with a share price instead of a 1:1 ratio.
-
event
Deposit(address indexed _who, uint256 _amount)
-
event
Withdraw(address indexed _who, uint256 _amount)
-
address public
baseAsset Address of the base asset.
-
mapping (address => VehicleInfo) public
vInfo
-
uint256 public constant
BPS_UNIT Unit of the lending cap.
-
uint256 constant public
SHARE_UNIT Unit of the share price.
-
EnumerableSetUpgradeable.AddressSet
investmentVehicles
-
EnumerableSetUpgradeable.AddressSet
whitelistDeposit
-
modifier
onlyWhitelistDeposit()
-
modifier
onlyDebtor()
-
modifier
timelockPassed(address iv)
-
function
isDebtor(address _target)
public
view
returns (bool) Checks if the target address is debtor
- Parameters
_target – target address
- Return
true if target address is debtor, false if not
-
function
initialize(address _store, address _baseAsset)
public
virtual
initializer Initializes the contract
-
function
deposit(uint256 baseAmount)
public
virtual Deposit baseAsset into the vault
- Parameters
baseAmount – The amount of baseAsset deposited from the user
-
function
depositFor(address targetAccount, uint256 baseAmount)
public
virtual Deposit baseAsset into the vault for targetAccount.
- Parameters
targetAccount – Target account to deposit for
baseAmount – The amount of baseAsset deposited from the user
-
function
_deposit(address assetFrom, address shareTo, uint256 baseAmount)
internal
virtual
onlyWhitelistDeposit
-
function
withdraw(uint256 shareAmount)
public
virtual Burns the share amount and withdraws respective base asset.
- Parameters
shareAmount – Amount of the share of the vault.
-
function
withdrawAllFromIV(address _iv)
public
opsPriviledged Withdral all the baseAsset from an IV.
- Parameters
_iv – Address of the IV.
-
function
withdrawFromIV(address _iv, uint256 _amount)
public
opsPriviledged Withdral ceterain amount of the baseAsset from an IV.
- Parameters
_iv – Address of the IV.
_amount – Amount of the baseAsset to be withdrawed.
-
function
withdrawFromIVs(address[] memory _ivs, uint256[] memory _amounts)
public
opsPriviledged Withdral ceterain amount of the baseAsset from multiple IVs. See withdrawFromIV for details.
-
function
withdrawAllFromIVs(address[] memory _ivs)
public
opsPriviledged Withdral all the baseAsset from multiple IVs. See withdrawAllFromIV for details.
-
function
_withdrawFromIV(address iv, uint256 amount)
internal
-
function
_accountingDebtRepayment(address _debtor, uint256 repaymentAmountInBase)
internal
-
function
_accountingFundsLendingOut(address _debtor, uint256 _fundsSentOutInBase)
internal
-
function
investAll()
public
opsPriviledged Invest all the available baseAsset in the vault.
-
function
investTo(address _target, uint256 _amount)
public
opsPriviledged Invest certain amount of the baseAsset in the vault to an IV.
- Parameters
_target – Address of the IV.
_amount – Amount of the baseAsset to be invested.
-
function
investToIVs(address[] memory _targets, uint256[] memory _amounts)
public
opsPriviledged Invest certain amount of the baseAsset in the vault to multiple IVs.
-
function
migrateFunds(address _fromIv, address _toIv, uint256 _pullAmount, uint256 _pushAmount)
public
opsPriviledged Migrate certain amount of the baseAsset from one IV to another.
- Parameters
_fromIv – Address of the source IV.
_toIv – Address of the destination IV.
_pullAmount – Amount of the baseAsset to be pulled out from old IV.
_pushAmount – Amount of the baseAsset to be pushed into the new IV.
-
function
effectiveLendCapacity(address _target)
public
view
returns (uint256) Calculate the lending capacity of an IV. This vault cannot lend baseAsset with amount more than the lending capacity.
- Parameters
_target – Address of the IV.
- Return
Return the lending capacity. (Unit: BPS_UNIT)
-
function
_investTo(address _target, uint256 _maxAmountBase)
internal
virtual
returns (uint256)
-
function
addWhitelistDeposit(address _newDepositor)
public
adminPriviledged Add an account to the deposit whitelist. Unlike VaultUpgradeable, SelfCompoundingYieldUpgradeable doesn’t allow accunts to deposit by default.
- Parameters
_newDepositor – The account to be added to the white list
-
function
removeWhitelistDeposit(address _newDepositor)
public
adminPriviledged Remove an account to the deposit whitelist.
- Parameters
_newDepositor – The account to be removed to the white list
-
function
isWhitelistDeposit(address _target)
public
view
returns (bool) Check if the target account is in the deposit whitelist
- Parameters
_target – Target account
- Return
Return True
-
function
addInvestmentVehicle(address newVehicle, uint256 _lendMaxBps, uint256 _lendCap)
public
adminPriviledged
timelockPassed(newVehicle)
returns (uint256) Add an investment vehicle.
- Parameters
newVehicle – Address of the new IV.
_lendMaxBps – Lending capacity of the IV in ratio.
_lendCap – Lending capacity of the IV in absolute numbers.
-
function
moveInvestmentVehicleToLowestPriority(address iv)
external
adminPriviledged This moves an IV to the lowest withdraw priority.
- Parameters
iv – Address of the IV.
-
function
removeInvestmentVehicle(address _target)
public
adminPriviledged Remove an IV from the vault.
- Parameters
_target – Address of the IV.
-
function
investmentVehiclesLength()
public
view
returns (uint256) - Return
Return the number of the IVs added to this vault.
-
function
getInvestmentVehicle(uint256 idx)
public
view
returns (address) - Parameters
idx – Index of the IV.
- Return
Return the address of an IV.
-
function
baseAssetDebtOf(address _iv)
public
view
returns (uint256) - Parameters
_iv – Address of the IV.
- Return
Return the debt (in baseAsset) of an IV
-
function
baseAssetInvested()
public
view
returns (uint256) - Return
Return the amount of baseAsset that is invested to IVs
-
function
totalBaseAsset()
public
view
returns (uint256) - Return
Total amount of baseAsset (invested + not invested) belongs to this vault.
-
function
sharePrice()
public
view
returns (uint256) - Return
Return the share price. (Unit: SHARE_UNIT)
-
function
shareToBaseAsset(uint256 share)
public
view
returns (uint256) Calculate the corrsponding amount of baseAsset
- Parameters
share – Amount of the vault share.
- Return
The corrsponding amount of baseAsset.
-
function
baseAssetToShare(uint256 baseAmount)
public
view
returns (uint256) - Parameters
baseAmount – Amount of baseAsset.
- Return
The corrsponding amount of vault share.
-
event