Skip to content

Latest commit

 

History

History
747 lines (631 loc) · 21.5 KB

ProtoUtilV1.md

File metadata and controls

747 lines (631 loc) · 21.5 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 MAX_LIQUIDITY;
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

getProtocol

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

Arguments

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

getProtocolAddress

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

Arguments

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

getContract

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

Arguments

Name Type Description
s IStore
name bytes32
key bytes32
Source Code
function getContract(
    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);
  }

isProtocolMember

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

Arguments

Name Type Description
s IStore
contractAddress address
Source Code
function isProtocolMember(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 = isProtocolMember(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 = getContract(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);
  }

npmToken

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

Arguments

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

getNpmTokenAddress

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

Arguments

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

getUniswapV2Router

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

Arguments

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

getUniswapV2Factory

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

Arguments

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

getNpmPriceOracle

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

Arguments

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

getTreasury

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

Arguments

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

getStablecoin

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

Arguments

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

getStablecoinPrecision

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

Arguments

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

getBurnAddress

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

Arguments

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

Contracts