Skip to content

Latest commit

 

History

History
461 lines (378 loc) · 12.9 KB

StrategyLibV1.md

File metadata and controls

461 lines (378 loc) · 12.9 KB

StrategyLibV1.sol

View Source: contracts/libraries/StrategyLibV1.sol

StrategyLibV1

Events

event StrategyAdded(address indexed strategy);

Functions

_deleteStrategy

function _deleteStrategy(IStore s, address toFind) private nonpayable

Arguments

Name Type Description
s IStore
toFind address
Source Code
function _deleteStrategy(IStore s, address toFind) private {
    bytes32 key = ProtoUtilV1.NS_LENDING_STRATEGY_ACTIVE;

    uint256 pos = s.getAddressArrayItemPosition(key, toFind);
    require(pos > 1, "Invalid strategy");

    s.deleteAddressArrayItem(key, toFind);
    s.setBoolByKey(_getIsActiveStrategyKey(toFind), false);
  }

_getIsActiveStrategyKey

function _getIsActiveStrategyKey(address strategyAddress) private pure
returns(bytes32)

Arguments

Name Type Description
strategyAddress address
Source Code
function _getIsActiveStrategyKey(address strategyAddress) private pure returns (bytes32) {
    return keccak256(abi.encodePacked(ProtoUtilV1.NS_LENDING_STRATEGY_ACTIVE, strategyAddress));
  }

disableStrategyInternal

function disableStrategyInternal(IStore s, address toFind) external nonpayable

Arguments

Name Type Description
s IStore
toFind address
Source Code
function disableStrategyInternal(IStore s, address toFind) external {
    // @suppress-address-trust-issue Check caller.
    _deleteStrategy(s, toFind);

    s.setAddressArrayByKey(ProtoUtilV1.NS_LENDING_STRATEGY_DISABLED, toFind);
  }

addStrategiesInternal

function addStrategiesInternal(IStore s, address[] strategies) external nonpayable

Arguments

Name Type Description
s IStore
strategies address[]
Source Code
function addStrategiesInternal(IStore s, address[] memory strategies) external {
    for (uint256 i = 0; i < strategies.length; i++) {
      address strategy = strategies[i];
      _addStrategy(s, strategy);
    }
  }

getLendingPeriodsInternal

function getLendingPeriodsInternal(IStore s, bytes32 coverKey) external view
returns(lendingPeriod uint256, withdrawalWindow uint256)

Arguments

Name Type Description
s IStore
coverKey bytes32
Source Code
function getLendingPeriodsInternal(IStore s, bytes32 coverKey) external view returns (uint256 lendingPeriod, uint256 withdrawalWindow) {
    lendingPeriod = s.getUintByKey(getLendingPeriodKey(coverKey, true));
    withdrawalWindow = s.getUintByKey(getWithdrawalWindowKey(coverKey, true));

    if (lendingPeriod == 0) {
      lendingPeriod = s.getUintByKey(getLendingPeriodKey(0, true));
      withdrawalWindow = s.getUintByKey(getWithdrawalWindowKey(0, true));
    }
  }

setLendingPeriodsInternal

function setLendingPeriodsInternal(IStore s, bytes32 coverKey, uint256 lendingPeriod, uint256 withdrawalWindow) external nonpayable

Arguments

Name Type Description
s IStore
coverKey bytes32
lendingPeriod uint256
withdrawalWindow uint256
Source Code
function setLendingPeriodsInternal(
    IStore s,
    bytes32 coverKey,
    uint256 lendingPeriod,
    uint256 withdrawalWindow
  ) external {
    s.setUintByKey(getLendingPeriodKey(coverKey, true), lendingPeriod);
    s.setUintByKey(getWithdrawalWindowKey(coverKey, true), withdrawalWindow);
  }

getLendingPeriodKey

function getLendingPeriodKey(bytes32 coverKey, bool ignoreMissingKey) public pure
returns(bytes32)

Arguments

Name Type Description
coverKey bytes32
ignoreMissingKey bool
Source Code
function getLendingPeriodKey(bytes32 coverKey, bool ignoreMissingKey) public pure returns (bytes32) {
    if (ignoreMissingKey == false) {
      require(coverKey > 0, "Invalid Cover Key");
    }

    if (coverKey > 0) {
      return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_LIQUIDITY_LENDING_PERIOD, coverKey));
    }

    return ProtoUtilV1.NS_COVER_LIQUIDITY_LENDING_PERIOD;
  }

getWithdrawalWindowKey

function getWithdrawalWindowKey(bytes32 coverKey, bool ignoreMissingKey) public pure
returns(bytes32)

Arguments

Name Type Description
coverKey bytes32
ignoreMissingKey bool
Source Code
function getWithdrawalWindowKey(bytes32 coverKey, bool ignoreMissingKey) public pure returns (bytes32) {
    if (ignoreMissingKey == false) {
      require(coverKey > 0, "Invalid Cover Key");
    }

    if (coverKey > 0) {
      return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_LIQUIDITY_WITHDRAWAL_WINDOW, coverKey));
    }

    return ProtoUtilV1.NS_COVER_LIQUIDITY_WITHDRAWAL_WINDOW;
  }

_addStrategy

function _addStrategy(IStore s, address deployedOn) private nonpayable

Arguments

Name Type Description
s IStore
deployedOn address
Source Code
function _addStrategy(IStore s, address deployedOn) private {
    ILendingStrategy strategy = ILendingStrategy(deployedOn);
    require(strategy.getWeight() <= ProtoUtilV1.MULTIPLIER, "Weight too much");

    s.setBoolByKey(_getIsActiveStrategyKey(deployedOn), true);
    s.setAddressArrayByKey(ProtoUtilV1.NS_LENDING_STRATEGY_ACTIVE, deployedOn);
    emit StrategyAdded(deployedOn);
  }

getDisabledStrategiesInternal

function getDisabledStrategiesInternal(IStore s) external view
returns(strategies address[])

Arguments

Name Type Description
s IStore
Source Code
function getDisabledStrategiesInternal(IStore s) external view returns (address[] memory strategies) {
    return s.getAddressArrayByKey(ProtoUtilV1.NS_LENDING_STRATEGY_DISABLED);
  }

getActiveStrategiesInternal

function getActiveStrategiesInternal(IStore s) external view
returns(strategies address[])

Arguments

Name Type Description
s IStore
Source Code
function getActiveStrategiesInternal(IStore s) external view returns (address[] memory strategies) {
    return s.getAddressArrayByKey(ProtoUtilV1.NS_LENDING_STRATEGY_ACTIVE);
  }

Contracts