Skip to content

Latest commit

 

History

History
749 lines (633 loc) · 22.3 KB

ProtoUtilV1.md

File metadata and controls

749 lines (633 loc) · 22.3 KB

ProtoUtilV1.sol

View Source: contracts/libraries/ProtoUtilV1.sol

ProtoUtilV1

Contract Members

Constants & Variables

uint256 public constant MAX_POLICY_DURATION;
bytes32 public constant KEY_INTENTIONALLY_EMPTY;
bytes32 public constant PRODUCT_KEY_INTENTIONALLY_EMPTY;
uint256 public constant MULTIPLIER;
uint256 public constant MIN_LIQUIDITY;
uint256 public constant MAX_LIQUIDITY;
uint256 public constant MIN_PROPOSAL_AMOUNT;
uint256 public constant MAX_PROPOSAL_AMOUNT;
uint256 public constant MAX_NPM_STAKE;
uint256 public constant NPM_PRECISION;
uint256 public constant CXTOKEN_PRECISION;
uint256 public constant POD_PRECISION;
bytes32 public constant CNS_CORE;
bytes32 public constant CNS_NPM;
bytes32 public constant CNS_COVER;
bytes32 public constant CNS_UNISWAP_V2_ROUTER;
bytes32 public constant CNS_UNISWAP_V2_FACTORY;
bytes32 public constant CNS_PRICE_DISCOVERY;
bytes32 public constant CNS_TREASURY;
bytes32 public constant CNS_NPM_PRICE_ORACLE;
bytes32 public constant CNS_COVER_REASSURANCE;
bytes32 public constant CNS_POOL_BOND;
bytes32 public constant CNS_COVER_POLICY;
bytes32 public constant CNS_COVER_POLICY_MANAGER;
bytes32 public constant CNS_COVER_POLICY_ADMIN;
bytes32 public constant CNS_COVER_STAKE;
bytes32 public constant CNS_COVER_VAULT;
bytes32 public constant CNS_COVER_VAULT_DELEGATE;
bytes32 public constant CNS_COVER_STABLECOIN;
bytes32 public constant CNS_COVER_CXTOKEN_FACTORY;
bytes32 public constant CNS_COVER_VAULT_FACTORY;
bytes32 public constant CNS_BOND_POOL;
bytes32 public constant CNS_STAKING_POOL;
bytes32 public constant CNS_LIQUIDITY_ENGINE;
bytes32 public constant CNS_STRATEGY_AAVE;
bytes32 public constant CNS_STRATEGY_COMPOUND;
bytes32 public constant CNS_GOVERNANCE;
bytes32 public constant CNS_GOVERNANCE_RESOLUTION;
bytes32 public constant CNS_CLAIM_PROCESSOR;
bytes32 public constant CNS_BURNER;
bytes32 public constant NS_MEMBERS;
bytes32 public constant NS_CONTRACTS;
bytes32 public constant NS_COVER;
bytes32 public constant NS_COVER_PRODUCT;
bytes32 public constant NS_COVER_PRODUCT_EFFICIENCY;
bytes32 public constant NS_COVER_CREATION_DATE;
bytes32 public constant NS_COVER_CREATION_FEE;
bytes32 public constant NS_COVER_CREATION_MIN_STAKE;
bytes32 public constant NS_COVER_REASSURANCE;
bytes32 public constant NS_COVER_REASSURANCE_PAYOUT;
bytes32 public constant NS_COVER_REASSURANCE_WEIGHT;
bytes32 public constant NS_COVER_REASSURANCE_RATE;
bytes32 public constant NS_COVER_LEVERAGE_FACTOR;
bytes32 public constant NS_COVER_CREATION_FEE_EARNING;
bytes32 public constant NS_COVER_INFO;
bytes32 public constant NS_COVER_OWNER;
bytes32 public constant NS_COVER_SUPPORTS_PRODUCTS;
bytes32 public constant NS_VAULT_STRATEGY_OUT;
bytes32 public constant NS_VAULT_LENDING_INCOMES;
bytes32 public constant NS_VAULT_LENDING_LOSSES;
bytes32 public constant NS_VAULT_DEPOSIT_HEIGHTS;
bytes32 public constant NS_COVER_LIQUIDITY_LENDING_PERIOD;
bytes32 public constant NS_COVER_LIQUIDITY_MAX_LENDING_RATIO;
bytes32 public constant NS_COVER_LIQUIDITY_WITHDRAWAL_WINDOW;
bytes32 public constant NS_COVER_LIQUIDITY_MIN_STAKE;
bytes32 public constant NS_COVER_LIQUIDITY_STAKE;
bytes32 public constant NS_COVER_LIQUIDITY_COMMITTED;
bytes32 public constant NS_COVER_STABLECOIN_NAME;
bytes32 public constant NS_COVER_REQUIRES_WHITELIST;
bytes32 public constant NS_COVER_HAS_FLASH_LOAN;
bytes32 public constant NS_COVER_LIQUIDITY_FLASH_LOAN_FEE;
bytes32 public constant NS_COVER_LIQUIDITY_FLASH_LOAN_FEE_PROTOCOL;
bytes32 public constant NS_COVERAGE_LAG;
bytes32 public constant NS_COVER_POLICY_RATE_FLOOR;
bytes32 public constant NS_COVER_POLICY_RATE_CEILING;
bytes32 public constant NS_POLICY_DISABLED;
bytes32 public constant NS_POLICY_LAST_PURCHASE_ID;
bytes32 public constant NS_COVER_STAKE;
bytes32 public constant NS_COVER_STAKE_OWNED;
bytes32 public constant NS_COVER_STATUS;
bytes32 public constant NS_COVER_CXTOKEN;
bytes32 public constant NS_VAULT_TOKEN_NAME;
bytes32 public constant NS_VAULT_TOKEN_SYMBOL;
bytes32 public constant NS_COVER_CREATOR_WHITELIST;
bytes32 public constant NS_COVER_USER_WHITELIST;
bytes32 public constant NS_COVER_CLAIM_BLACKLIST;
bytes32 public constant NS_GOVERNANCE_RESOLUTION_TS;
bytes32 public constant NS_GOVERNANCE_UNSTAKEN;
bytes32 public constant NS_GOVERNANCE_UNSTAKE_TS;
bytes32 public constant NS_GOVERNANCE_UNSTAKE_REWARD;
bytes32 public constant NS_GOVERNANCE_UNSTAKE_BURNED;
bytes32 public constant NS_GOVERNANCE_UNSTAKE_REPORTER_FEE;
bytes32 public constant NS_GOVERNANCE_REPORTING_MIN_FIRST_STAKE;
bytes32 public constant NS_GOVERNANCE_REPORTING_INCIDENT_DATE;
bytes32 public constant NS_GOVERNANCE_REPORTING_PERIOD;
bytes32 public constant NS_GOVERNANCE_REPORTING_WITNESS_YES;
bytes32 public constant NS_GOVERNANCE_REPORTING_HAS_A_DISPUTE;
bytes32 public constant NS_GOVERNANCE_REPORTING_FINALIZATION;
bytes32 public constant NS_GOVERNANCE_REPORTING_WITNESS_NO;
bytes32 public constant NS_GOVERNANCE_REPORTING_STAKE_OWNED_YES;
bytes32 public constant NS_GOVERNANCE_REPORTING_STAKE_OWNED_NO;
bytes32 public constant NS_GOVERNANCE_REPORTING_BURN_RATE;
bytes32 public constant NS_GOVERNANCE_REPORTER_COMMISSION;
bytes32 public constant NS_CLAIM_PERIOD;
bytes32 public constant NS_CLAIM_PAYOUTS;
bytes32 public constant NS_CLAIM_BEGIN_TS;
bytes32 public constant NS_CLAIM_EXPIRY_TS;
bytes32 public constant NS_RESOLUTION_DEADLINE;
bytes32 public constant NS_RESOLUTION_COOL_DOWN_PERIOD;
bytes32 public constant NS_COVER_PLATFORM_FEE;
bytes32 public constant NS_CLAIM_REPORTER_COMMISSION;
bytes32 public constant NS_LAST_LIQUIDITY_STATE_UPDATE;
bytes32 public constant NS_LIQUIDITY_STATE_UPDATE_INTERVAL;
bytes32 public constant NS_LENDING_STRATEGY_ACTIVE;
bytes32 public constant NS_LENDING_STRATEGY_DISABLED;
bytes32 public constant NS_LENDING_STRATEGY_WITHDRAWAL_START;
bytes32 public constant NS_ACCRUAL_INVOCATION;
bytes32 public constant NS_LENDING_STRATEGY_WITHDRAWAL_END;
bytes32 public constant CNAME_PROTOCOL;
bytes32 public constant CNAME_TREASURY;
bytes32 public constant CNAME_POLICY;
bytes32 public constant CNAME_POLICY_ADMIN;
bytes32 public constant CNAME_BOND_POOL;
bytes32 public constant CNAME_STAKING_POOL;
bytes32 public constant CNAME_CLAIMS_PROCESSOR;
bytes32 public constant CNAME_COVER;
bytes32 public constant CNAME_GOVERNANCE;
bytes32 public constant CNAME_RESOLUTION;
bytes32 public constant CNAME_VAULT_FACTORY;
bytes32 public constant CNAME_CXTOKEN_FACTORY;
bytes32 public constant CNAME_COVER_STAKE;
bytes32 public constant CNAME_COVER_REASSURANCE;
bytes32 public constant CNAME_LIQUIDITY_VAULT;
bytes32 public constant CNAME_VAULT_DELEGATE;
bytes32 public constant CNAME_LIQUIDITY_ENGINE;

Functions

getProtocolInternal

function getProtocolInternal(IStore s) external view
returns(contract IProtocol)

Arguments

Name Type Description
s IStore
Source Code
function getProtocolInternal(IStore s) external view returns (IProtocol) {
    return IProtocol(getProtocolAddressInternal(s));
  }

getProtocolAddressInternal

function getProtocolAddressInternal(IStore s) public view
returns(address)

Arguments

Name Type Description
s IStore
Source Code
function getProtocolAddressInternal(IStore s) public view returns (address) {
    return s.getAddressByKey(CNS_CORE);
  }

getContractInternal

function getContractInternal(IStore s, bytes32 name, bytes32 key) public view
returns(address)

Arguments

Name Type Description
s IStore
name bytes32
key bytes32
Source Code
function getContractInternal(
    IStore s,
    bytes32 name,
    bytes32 key
  ) public view returns (address) {
    if (key > 0) {
      return s.getAddressByKeys(NS_CONTRACTS, name, key);
    }

    return s.getAddressByKeys(NS_CONTRACTS, name);
  }

isProtocolMemberInternal

function isProtocolMemberInternal(IStore s, address contractAddress) public view
returns(bool)

Arguments

Name Type Description
s IStore
contractAddress address
Source Code
function isProtocolMemberInternal(IStore s, address contractAddress) public view returns (bool) {
    return s.getBoolByKeys(ProtoUtilV1.NS_MEMBERS, contractAddress);
  }

mustBeProtocolMember

Reverts if the caller is one of the protocol members.

function mustBeProtocolMember(IStore s, address contractAddress) external view

Arguments

Name Type Description
s IStore
contractAddress address
Source Code
function mustBeProtocolMember(IStore s, address contractAddress) external view {
    bool isMember = isProtocolMemberInternal(s, contractAddress);
    require(isMember, "Not a protocol member");
  }

mustBeExactContract

Ensures that the sender matches with the exact contract having the specified name.

function mustBeExactContract(IStore s, bytes32 name, bytes32 key, address sender) public view

Arguments

Name Type Description
s IStore ender Enter the msg.sender value
name bytes32 Enter the name of the contract
key bytes32
sender address Enter the msg.sender value
Source Code
function mustBeExactContract(
    IStore s,
    bytes32 name,
    bytes32 key,
    address sender
  ) public view {
    address contractAddress = getContractInternal(s, name, key);
    require(sender == contractAddress, "Access denied");
  }

senderMustBeExactContract

Ensures that the sender matches with the exact contract having the specified name.

function senderMustBeExactContract(IStore s, bytes32 name) external view

Arguments

Name Type Description
s IStore
name bytes32 Enter the name of the contract
Source Code
function senderMustBeExactContract(IStore s, bytes32 name) external view {
    return callerMustBeExactContract(s, name, msg.sender);
  }

callerMustBeExactContract

Ensures that the sender matches with the exact contract having the specified name.

function callerMustBeExactContract(IStore s, bytes32 name, address caller) public view

Arguments

Name Type Description
s IStore
name bytes32 Enter the name of the contract
caller address
Source Code
function callerMustBeExactContract(
    IStore s,
    bytes32 name,
    address caller
  ) public view {
    return mustBeExactContract(s, name, ProtoUtilV1.KEY_INTENTIONALLY_EMPTY, caller);
  }

getNpmTokenInstanceInternal

function getNpmTokenInstanceInternal(IStore s) external view
returns(contract IERC20)

Arguments

Name Type Description
s IStore
Source Code
function getNpmTokenInstanceInternal(IStore s) external view returns (IERC20) {
    return IERC20(getNpmTokenAddressInternal(s));
  }

getNpmTokenAddressInternal

function getNpmTokenAddressInternal(IStore s) public view
returns(address)

Arguments

Name Type Description
s IStore
Source Code
function getNpmTokenAddressInternal(IStore s) public view returns (address) {
    address npm = s.getAddressByKey(CNS_NPM);
    return npm;
  }

getUniswapV2RouterInternal

function getUniswapV2RouterInternal(IStore s) external view
returns(address)

Arguments

Name Type Description
s IStore
Source Code
function getUniswapV2RouterInternal(IStore s) external view returns (address) {
    return s.getAddressByKey(CNS_UNISWAP_V2_ROUTER);
  }

getUniswapV2FactoryInternal

function getUniswapV2FactoryInternal(IStore s) external view
returns(address)

Arguments

Name Type Description
s IStore
Source Code
function getUniswapV2FactoryInternal(IStore s) external view returns (address) {
    return s.getAddressByKey(CNS_UNISWAP_V2_FACTORY);
  }

getNpmPriceOracleInternal

function getNpmPriceOracleInternal(IStore s) external view
returns(address)

Arguments

Name Type Description
s IStore
Source Code
function getNpmPriceOracleInternal(IStore s) external view returns (address) {
    return s.getAddressByKey(CNS_NPM_PRICE_ORACLE);
  }

getTreasuryAddressInternal

function getTreasuryAddressInternal(IStore s) external view
returns(address)

Arguments

Name Type Description
s IStore
Source Code
function getTreasuryAddressInternal(IStore s) external view returns (address) {
    return s.getAddressByKey(CNS_TREASURY);
  }

getStablecoinAddressInternal

function getStablecoinAddressInternal(IStore s) public view
returns(address)

Arguments

Name Type Description
s IStore
Source Code
function getStablecoinAddressInternal(IStore s) public view returns (address) {
    return s.getAddressByKey(CNS_COVER_STABLECOIN);
  }

getStablecoinPrecisionInternal

function getStablecoinPrecisionInternal(IStore s) external view
returns(uint256)

Arguments

Name Type Description
s IStore
Source Code
function getStablecoinPrecisionInternal(IStore s) external view returns (uint256) {
    return 10**IERC20Detailed(getStablecoinAddressInternal(s)).decimals();
  }

getBurnAddressInternal

function getBurnAddressInternal(IStore s) external view
returns(address)

Arguments

Name Type Description
s IStore
Source Code
function getBurnAddressInternal(IStore s) external view returns (address) {
    return s.getAddressByKey(CNS_BURNER);
  }

Contracts