Skip to content

Latest commit

 

History

History
823 lines (674 loc) · 25.6 KB

VaultDelegateBase.md

File metadata and controls

823 lines (674 loc) · 25.6 KB

Vault Delegate Base Contract (VaultDelegateBase.sol)

View Source: contracts/core/delegates/VaultDelegateBase.sol

↗ Extends: IVaultDelegate, Recoverable ↘ Derived Contracts: VaultDelegateWithFlashLoan

VaultDelegateBase

The vault delegate base contract includes pre and post hooks. The hooks are accessible only to vault contracts.

Functions

Constructs this contract

function (IStore store) internal nonpayable Recoverable 

Arguments

Name Type Description
store IStore Provide the store contract instance
Source Code
constructor(IStore store) Recoverable(store) {}

preTransferGovernance

This hook runs before transferGovernance implementation on vault(s).

function preTransferGovernance(address caller, bytes32 coverKey, address , uint256 ) external nonpayable nonReentrant 
returns(stablecoin address)

Arguments

Name Type Description
caller address Enter your msg.sender value.
coverKey bytes32 Provide your vault's cover key.
address caller Enter your msg.sender value.
uint256 caller Enter your msg.sender value.

Returns

stablecoin Returns address of the protocol stablecoin if the hook validation passes.

Source Code
function preTransferGovernance(
    address caller,
    bytes32 coverKey,
    address, /*to*/
    uint256 /*amount*/
  ) external override nonReentrant returns (address stablecoin) {
    // @suppress-zero-value-check This function does not transfer any values
    s.mustNotBePaused();
    s.mustBeProtocolMember(caller);
    s.mustBeProtocolMember(msg.sender);
    s.senderMustBeVaultContract(coverKey);
    s.callerMustBeClaimsProcessorContract(caller);

    stablecoin = s.getStablecoin();
  }

postTransferGovernance

This hook runs after transferGovernance implementation on vault(s) and performs cleanup and/or validation if needed.

function postTransferGovernance(address caller, bytes32 coverKey, address , uint256 ) external view

Arguments

Name Type Description
caller address Enter your msg.sender value.
coverKey bytes32 Provide your vault's cover key.
address caller Enter your msg.sender value.
uint256 caller Enter your msg.sender value.
Source Code
function postTransferGovernance(
    address caller,
    bytes32 coverKey,
    address, /*to*/
    uint256 /*amount*/
  ) external view override {
    s.mustNotBePaused();
    s.mustBeProtocolMember(caller);
    s.mustBeProtocolMember(msg.sender);
    s.senderMustBeVaultContract(coverKey);
    s.callerMustBeClaimsProcessorContract(caller);
  }

preTransferToStrategy

This hook runs before transferToStrategy implementation on vault(s)

function preTransferToStrategy(address caller, IERC20 token, bytes32 coverKey, bytes32 strategyName, uint256 amount) external nonpayable nonReentrant 

Arguments

Name Type Description
caller address Enter your msg.sender value
token IERC20 Provide the ERC20 token you'd like to transfer to the given strategy
coverKey bytes32 Provide your vault's cover key
strategyName bytes32 Enter the strategy name
amount uint256 Enter the amount to transfer
Source Code
function preTransferToStrategy(
    address caller,
    IERC20 token,
    bytes32 coverKey,
    bytes32 strategyName,
    uint256 amount
  ) external override nonReentrant {
    // @suppress-zero-value-check Checked
    s.mustNotBePaused();
    s.mustBeProtocolMember(caller);
    s.mustBeProtocolMember(msg.sender);
    s.senderMustBeVaultContract(coverKey);
    s.callerMustBeSpecificStrategyContract(caller, strategyName);

    s.preTransferToStrategyInternal(token, coverKey, strategyName, amount);
  }

postTransferToStrategy

This hook runs after transferToStrategy implementation on vault(s) and performs cleanup and/or validation if needed.

function postTransferToStrategy(address caller, IERC20 , bytes32 coverKey, bytes32 strategyName, uint256 ) external view

Arguments

Name Type Description
caller address Enter your msg.sender value
IERC20 caller Enter your msg.sender value
coverKey bytes32 Enter the coverKey
strategyName bytes32 Enter the strategy name
uint256 caller Enter your msg.sender value
Source Code
function postTransferToStrategy(
    address caller,
    IERC20, /*token*/
    bytes32 coverKey,
    bytes32 strategyName,
    uint256 /*amount*/
  ) external view override {
    s.mustNotBePaused();
    s.mustBeProtocolMember(caller);
    s.mustBeProtocolMember(msg.sender);
    s.senderMustBeVaultContract(coverKey);
    s.callerMustBeSpecificStrategyContract(caller, strategyName);
  }

preReceiveFromStrategy

This hook runs before receiveFromStrategy implementation on vault(s)

function preReceiveFromStrategy(address caller, IERC20 , bytes32 coverKey, bytes32 strategyName, uint256 ) external nonpayable nonReentrant 

Arguments

Name Type Description
caller address Enter your msg.sender value
IERC20 caller Enter your msg.sender value
coverKey bytes32 Provide your vault's cover key
strategyName bytes32 Enter the strategy name
uint256 caller Enter your msg.sender value
Source Code
function preReceiveFromStrategy(
    address caller,
    IERC20, /*token*/
    bytes32 coverKey,
    bytes32 strategyName,
    uint256 /*amount*/
  ) external override nonReentrant {
    // @suppress-zero-value-check This function does not transfer any tokens
    s.mustNotBePaused();
    s.mustBeProtocolMember(caller);
    s.mustBeProtocolMember(msg.sender);
    s.senderMustBeVaultContract(coverKey);
    s.callerMustBeSpecificStrategyContract(caller, strategyName);
  }

postReceiveFromStrategy

This hook runs after receiveFromStrategy implementation on vault(s) and performs cleanup and/or validation if needed.

function postReceiveFromStrategy(address caller, IERC20 token, bytes32 coverKey, bytes32 strategyName, uint256 amount) external nonpayable
returns(income uint256, loss uint256)

Arguments

Name Type Description
caller address Enter your msg.sender value
token IERC20 Enter the token your vault received from strategy
coverKey bytes32 Enter the coverKey
strategyName bytes32 Enter the strategy name
amount uint256 Enter the amount received
Source Code
function postReceiveFromStrategy(
    address caller,
    IERC20 token,
    bytes32 coverKey,
    bytes32 strategyName,
    uint256 amount
  ) external override returns (uint256 income, uint256 loss) {
    // @suppress-zero-value-check This call does not perform any transfers
    s.mustNotBePaused();
    s.mustBeProtocolMember(caller);
    s.mustBeProtocolMember(msg.sender);
    s.senderMustBeVaultContract(coverKey);
    s.callerMustBeSpecificStrategyContract(caller, strategyName);

    (income, loss) = s.postReceiveFromStrategyInternal(token, coverKey, strategyName, amount);
  }

preAddLiquidity

This hook runs before addLiquidity implementation on vault(s)

function preAddLiquidity(address caller, bytes32 coverKey, uint256 amount, uint256 npmStakeToAdd) external nonpayable nonReentrant 
returns(podsToMint uint256, previousNpmStake uint256)

Arguments

Name Type Description
caller address
coverKey bytes32 Enter the cover key
amount uint256 Enter the amount of liquidity token to supply.
npmStakeToAdd uint256 Enter the amount of NPM token to stake.
Source Code
function preAddLiquidity(
    address caller,
    bytes32 coverKey,
    uint256 amount,
    uint256 npmStakeToAdd
  ) external override nonReentrant returns (uint256 podsToMint, uint256 previousNpmStake) {
    // @suppress-zero-value-check This call does not transfer any tokens
    s.mustNotBePaused();
    s.mustBeProtocolMember(msg.sender);
    s.senderMustBeVaultContract(coverKey);
    s.mustEnsureAllProductsAreNormal(coverKey);

    ValidationLibV1.mustNotExceedStablecoinThreshold(s, amount);
    GovernanceUtilV1.mustNotExceedNpmThreshold(npmStakeToAdd);

    address pod = msg.sender;
    (podsToMint, previousNpmStake) = s.preAddLiquidityInternal(coverKey, pod, caller, amount, npmStakeToAdd);
  }

postAddLiquidity

This hook runs after addLiquidity implementation on vault(s) and performs cleanup and/or validation if needed.

function postAddLiquidity(address , bytes32 coverKey, uint256 , uint256 ) external nonpayable

Arguments

Name Type Description
address coverKey Enter the coverKey
coverKey bytes32 Enter the coverKey
uint256 coverKey Enter the coverKey
uint256 coverKey Enter the coverKey
Source Code
function postAddLiquidity(
    address, /*caller*/
    bytes32 coverKey,
    uint256, /*amount*/
    uint256 /*npmStakeToAdd*/
  ) external override {
    // @suppress-zero-value-check This function does not transfer any tokens
    s.mustNotBePaused();
    s.mustBeProtocolMember(msg.sender);
    s.senderMustBeVaultContract(coverKey);
    s.mustEnsureAllProductsAreNormal(coverKey);
    s.updateStateAndLiquidity(coverKey);
  }

accrueInterestImplementation

This implemention enables liquidity manages to accrue interests on a vault before withdrawals are allowed.

function accrueInterestImplementation(address caller, bytes32 coverKey) external nonpayable

Arguments

Name Type Description
caller address Enter your msg.sender value
coverKey bytes32 Provide your vault's cover key
Source Code
function accrueInterestImplementation(address caller, bytes32 coverKey) external override {
    s.mustNotBePaused();
    s.senderMustBeVaultContract(coverKey);
    AccessControlLibV1.callerMustBeLiquidityManager(s, caller);

    s.accrueInterestInternal(coverKey);
  }

preRemoveLiquidity

This hook runs before removeLiquidity implementation on vault(s)

function preRemoveLiquidity(address caller, bytes32 coverKey, uint256 podsToRedeem, uint256 npmStakeToRemove, bool exit) external nonpayable nonReentrant 
returns(stablecoin address, stablecoinToRelease uint256)

Arguments

Name Type Description
caller address Enter your msg.sender value
coverKey bytes32 Enter the cover key
podsToRedeem uint256 Enter the amount of pods to redeem
npmStakeToRemove uint256 Enter the amount of NPM stake to remove.
exit bool If this is set to true, LPs can remove their entire NPM stake during a withdrawal period. No restriction.
Source Code
function preRemoveLiquidity(
    address caller,
    bytes32 coverKey,
    uint256 podsToRedeem,
    uint256 npmStakeToRemove,
    bool exit
  ) external override nonReentrant returns (address stablecoin, uint256 stablecoinToRelease) {
    // @suppress-zero-value-check This call does not transfer any tokens
    s.mustNotBePaused();
    s.mustBeProtocolMember(msg.sender);
    s.senderMustBeVaultContract(coverKey);
    s.mustMaintainBlockHeightOffset(coverKey);
    s.mustEnsureAllProductsAreNormal(coverKey);
    s.mustBeDuringWithdrawalPeriod(coverKey);
    s.mustHaveNoBalanceInStrategies(coverKey, stablecoin);
    s.mustBeAccrued(coverKey);

    address pod = msg.sender; // The sender is vault contract
    return s.preRemoveLiquidityInternal(coverKey, pod, caller, podsToRedeem, npmStakeToRemove, exit);
  }

postRemoveLiquidity

This hook runs after removeLiquidity implementation on vault(s) and performs cleanup and/or validation if needed.

function postRemoveLiquidity(address , bytes32 coverKey, uint256 , uint256 , bool ) external nonpayable

Arguments

Name Type Description
address coverKey Enter the coverKey
coverKey bytes32 Enter the coverKey
uint256 coverKey Enter the coverKey
uint256 coverKey Enter the coverKey
bool coverKey Enter the coverKey
Source Code
function postRemoveLiquidity(
    address, /*caller*/
    bytes32 coverKey,
    uint256, /*podsToRedeem*/
    uint256, /*npmStakeToRemove*/
    bool /*exit*/
  ) external override {
    // @suppress-zero-value-check The uint values are not used and therefore not checked
    s.mustNotBePaused();
    s.mustBeProtocolMember(msg.sender);
    s.senderMustBeVaultContract(coverKey);
    s.updateStateAndLiquidity(coverKey);
  }

calculatePodsImplementation

Calculates the amount of PODs to mint for the given amount of stablecoin

function calculatePodsImplementation(bytes32 coverKey, uint256 stablecoinIn) external view
returns(uint256)

Arguments

Name Type Description
coverKey bytes32 Enter the cover for which you want to calculate PODs
stablecoinIn uint256 Enter the amount in the stablecoin units

Returns

Returns the units of PODs to be minted if this stablecoin liquidity was supplied. Be warned that this value may change based on the cover vault's usage.

Source Code
function calculatePodsImplementation(bytes32 coverKey, uint256 stablecoinIn) external view override returns (uint256) {
    s.senderMustBeVaultContract(coverKey);

    address pod = msg.sender;

    return s.calculatePodsInternal(coverKey, pod, stablecoinIn);
  }

calculateLiquidityImplementation

Calculates the amount of stablecoin units to receive for the given amount of PODs to redeem

function calculateLiquidityImplementation(bytes32 coverKey, uint256 podsToBurn) external view
returns(uint256)

Arguments

Name Type Description
coverKey bytes32 Enter the cover for which you want to calculate PODs
podsToBurn uint256 Enter the amount in the POD units to redeem

Returns

Returns the units of stablecoins to redeem if the specified PODs were burned. Be warned that this value may change based on the cover's vault usage.

Source Code
function calculateLiquidityImplementation(bytes32 coverKey, uint256 podsToBurn) external view override returns (uint256) {
    s.senderMustBeVaultContract(coverKey);
    address pod = msg.sender;
    return s.calculateLiquidityInternal(coverKey, pod, podsToBurn);
  }

getStablecoinBalanceOfImplementation

Returns the stablecoin balance of this vault This also includes amounts lent out in lending strategies by this vault Warning: this function does not validate the cover key supplied.

function getStablecoinBalanceOfImplementation(bytes32 coverKey) external view
returns(uint256)

Arguments

Name Type Description
coverKey bytes32 Enter the cover for which you want to get the stablecoin balance
Source Code
function getStablecoinBalanceOfImplementation(bytes32 coverKey) external view override returns (uint256) {
    s.senderMustBeVaultContract(coverKey);
    return s.getStablecoinOwnedByVaultInternal(coverKey);
  }

getInfoImplementation

Gets information of a given vault by the cover key Warning: this function does not validate the cover key and account supplied.

function getInfoImplementation(bytes32 coverKey, address you) external view
returns(struct IVault.VaultInfoType)

Arguments

Name Type Description
coverKey bytes32 Specify cover key to obtain the info of
you address The address for which the info will be customized
Source Code
function getInfoImplementation(bytes32 coverKey, address you) external view override returns (IVault.VaultInfoType memory) {
    s.senderMustBeVaultContract(coverKey);
    address pod = msg.sender;
    return s.getInfoInternal(coverKey, pod, you);
  }

version

Version number of this contract

function version() external pure
returns(bytes32)

Arguments

Name Type Description
Source Code
function version() external pure override returns (bytes32) {
    return "v0.1";
  }

getName

Name of this contract

function getName() external pure
returns(bytes32)

Arguments

Name Type Description
Source Code
function getName() external pure override returns (bytes32) {
    return ProtoUtilV1.CNAME_VAULT_DELEGATE;
  }

Contracts