View Source: contracts/core/cxToken/cxToken.sol
↗ Extends: ICxToken, Recoverable, ERC20
cxToken
cxTokens are minted when someone purchases a cover.
The cxTokens can be exchanged for a USD stablecoin at a 1:1 exchange rate
after a cover incident is successfully resolved (minus platform fees).
Restrictions:
- cxTokens cannot be transferred from one person to another.
- Only claims can be submitted with cxTokens
- There is a lag period before your cxTokens starts its coverage. cxTokens start coverage the next day (or longer) at the UTC EOD timestamp and remain valid until the expiration date.
- The lag configuration can be found in ProtoUtilV1.NS_COVERAGE_LAG and PolicyAdmin.getCoverageLag function.
Constants & Variables
bytes32 public COVER_KEY;
bytes32 public PRODUCT_KEY;
uint256 public createdOn;
uint256 public expiresOn;
mapping(address => mapping(uint256 => uint256)) public coverageStartsFrom;
- constructor(IStore store, bytes32 coverKey, bytes32 productKey, string tokenName, uint256 expiry)
- getCoverageStartsFrom(address account, uint256 date)
- _getExcludedCoverageOf(address account)
- getClaimablePolicyOf(address account)
- mint(bytes32 coverKey, bytes32 productKey, address to, uint256 amount)
- burn(uint256 amount)
- _beforeTokenTransfer(address from, address to, uint256 )
Constructs this contract.
function (IStore store, bytes32 coverKey, bytes32 productKey, string tokenName, uint256 expiry) public nonpayable ERC20 Recoverable
Arguments
Name | Type | Description |
---|---|---|
store | IStore | Provide the store contract instance |
coverKey | bytes32 | Enter the cover key |
productKey | bytes32 | Enter the product key |
tokenName | string | Enter token name for this ERC-20 contract. The token symbol will be cxUSD . |
expiry | uint256 | Provide the cover expiry timestamp |
Source Code
constructor(
IStore store,
bytes32 coverKey,
bytes32 productKey,
string memory tokenName,
uint256 expiry
) ERC20(tokenName, "cxUSD") Recoverable(store) {
COVER_KEY = coverKey;
PRODUCT_KEY = productKey;
expiresOn = expiry;
}
Returns the value of the coverageStartsFrom
mapping.
Warning: this function does not validate the input arguments.
function getCoverageStartsFrom(address account, uint256 date) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
account | address | Enter an account to get the coverageStartsFrom value. |
date | uint256 | Enter a date. Ensure that you supply a UTC EOD value. |
Source Code
function getCoverageStartsFrom(address account, uint256 date) external view override returns (uint256) {
return coverageStartsFrom[account][date];
}
Gets sum of the lagged and, therefore, excluded policy of a given account.
Only policies purchased within 24-48 hours (or longer depending on this cover's configuration) are valid.
Given the present codebase, the loop that follows may appear pointless and invalid.
Since the protocol is upgradable but not cxTokens,
erroneous code could be introduced in the future,
which is why we go all the way until the resolution deadline.
function _getExcludedCoverageOf(address account) private view
returns(exclusion uint256)
Arguments
Name | Type | Description |
---|---|---|
account | address | Enter an account. |
Source Code
function _getExcludedCoverageOf(address account) private view returns (uint256 exclusion) {
uint256 incidentDate = s.getActiveIncidentDateInternal(COVER_KEY, PRODUCT_KEY);
uint256 resolutionEOD = PolicyHelperV1.getEODInternal(s.getResolutionTimestampInternal(COVER_KEY, PRODUCT_KEY));
uint256 totalDays = (resolutionEOD - incidentDate) / 1 days;
for (uint256 i = 0; i < totalDays; i++) {
uint256 date = PolicyHelperV1.getEODInternal(incidentDate + (i * 1 days));
exclusion += coverageStartsFrom[account][date];
}
}
Gets the claimable policy of an account. Warning: this function does not validate the input arguments.
function getClaimablePolicyOf(address account) external view
returns(uint256)
Arguments
Name | Type | Description |
---|---|---|
account | address | Enter an account. |
Source Code
function getClaimablePolicyOf(address account) external view override returns (uint256) {
uint256 exclusion = _getExcludedCoverageOf(account);
uint256 balance = super.balanceOf(account);
if (exclusion > balance) {
return 0;
}
return balance - exclusion;
}
Mints cxTokens when a policy is purchased. This feature can only be accessed by the latest policy smart contract.
function mint(bytes32 coverKey, bytes32 productKey, address to, uint256 amount) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
coverKey | bytes32 | Enter the cover key for which the cxTokens are being minted |
productKey | bytes32 | |
to | address | Enter the address where the minted token will be sent |
amount | uint256 | Specify the amount of cxTokens to mint |
Source Code
function mint(
bytes32 coverKey,
bytes32 productKey,
address to,
uint256 amount
) external override nonReentrant {
require(amount > 0, "Please specify amount");
require(coverKey == COVER_KEY, "Invalid cover");
require(productKey == PRODUCT_KEY, "Invalid product");
s.mustNotBePaused();
s.senderMustBePolicyContract();
s.mustBeSupportedProductOrEmpty(coverKey, productKey);
uint256 effectiveFrom = PolicyHelperV1.getEODInternal(block.timestamp) + s.getCoverageLagInternal(coverKey); // solhint-disable-line
coverageStartsFrom[to][effectiveFrom] += amount;
super._mint(to, amount);
}
Burns the tokens held by the sender.
function burn(uint256 amount) external nonpayable nonReentrant
Arguments
Name | Type | Description |
---|---|---|
amount | uint256 | Specify the amount of tokens to burn |
Source Code
function burn(uint256 amount) external override nonReentrant {
require(amount > 0, "Please specify amount");
s.mustNotBePaused();
super._burn(msg.sender, amount);
}
Overrides Openzeppelin ERC-20 contract's _beforeTokenTransfer
hook.
This is called during transfer
, transferFrom
, mint
, and burn
function invocation.
cxToken Restrictions:
- An expired cxToken can't be transferred.
- cxTokens can only be transferred to the claims processor contract.
function _beforeTokenTransfer(address from, address to, uint256 ) internal view
Arguments
Name | Type | Description |
---|---|---|
from | address | The account sending the cxTokens |
to | address | The account receiving the cxTokens |
uint256 | from The account sending the cxTokens |
Source Code
function _beforeTokenTransfer(
address from,
address to,
uint256
) internal view override {
// solhint-disable-next-line
if (block.timestamp > expiresOn) {
require(to == address(0), "Expired cxToken");
}
// cxTokens can only be transferred to the claims processor contract
if (from != address(0) && to != address(0)) {
s.mustBeExactContract(ProtoUtilV1.CNS_CLAIM_PROCESSOR, ProtoUtilV1.KEY_INTENTIONALLY_EMPTY, to);
}
}
- AaveStrategy
- AccessControl
- AccessControlLibV1
- Address
- BaseLibV1
- BokkyPooBahsDateTimeLibrary
- BondPool
- BondPoolBase
- BondPoolLibV1
- CompoundStrategy
- Context
- Cover
- CoverBase
- CoverLibV1
- CoverReassurance
- CoverStake
- CoverUtilV1
- cxToken
- cxTokenFactory
- cxTokenFactoryLibV1
- Delayable
- Destroyable
- ERC165
- ERC20
- FakeAaveLendingPool
- FakeCompoundDaiDelegator
- FakePriceOracle
- FakeRecoverable
- FakeStore
- FakeToken
- FakeUniswapPair
- FakeUniswapV2FactoryLike
- FakeUniswapV2PairLike
- FakeUniswapV2RouterLike
- FaultyAaveLendingPool
- FaultyCompoundDaiDelegator
- Finalization
- ForceEther
- Governance
- GovernanceUtilV1
- IAaveV2LendingPoolLike
- IAccessControl
- IBondPool
- IClaimsProcessor
- ICompoundERC20DelegatorLike
- ICover
- ICoverReassurance
- ICoverStake
- ICxToken
- ICxTokenFactory
- IERC165
- IERC20
- IERC20Detailed
- IERC20Metadata
- IERC3156FlashBorrower
- IERC3156FlashLender
- IFinalization
- IGovernance
- ILendingStrategy
- ILiquidityEngine
- IMember
- INeptuneRouterV1
- InvalidStrategy
- IPausable
- IPolicy
- IPolicyAdmin
- IPriceOracle
- IProtocol
- IRecoverable
- IReporter
- IResolution
- IResolvable
- IStakingPools
- IStore
- IStoreLike
- IUniswapV2FactoryLike
- IUniswapV2PairLike
- IUniswapV2RouterLike
- IUnstakable
- IVault
- IVaultDelegate
- IVaultFactory
- IWitness
- LiquidityEngine
- MaliciousToken
- MockAccessControlUser
- MockCoverUtilUser
- MockCxToken
- MockCxTokenPolicy
- MockCxTokenStore
- MockFlashBorrower
- MockLiquidityEngineUser
- MockProcessorStore
- MockProcessorStoreLib
- MockProtocol
- MockRegistryClient
- MockStore
- MockStoreKeyUtilUser
- MockValidationLibUser
- MockVault
- MockVaultLibUser
- NeptuneRouterV1
- NPM
- NpmDistributor
- NTransferUtilV2
- NTransferUtilV2Intermediate
- Ownable
- Pausable
- Policy
- PolicyAdmin
- PolicyHelperV1
- PoorMansERC20
- POT
- PriceLibV1
- Processor
- ProtoBase
- Protocol
- ProtoUtilV1
- Recoverable
- ReentrancyGuard
- RegistryLibV1
- Reporter
- Resolution
- Resolvable
- RoutineInvokerLibV1
- SafeERC20
- StakingPoolBase
- StakingPoolCoreLibV1
- StakingPoolInfo
- StakingPoolLibV1
- StakingPoolReward
- StakingPools
- Store
- StoreBase
- StoreKeyUtil
- StrategyLibV1
- Strings
- TimelockController
- Unstakable
- ValidationLibV1
- Vault
- VaultBase
- VaultDelegate
- VaultDelegateBase
- VaultDelegateWithFlashLoan
- VaultFactory
- VaultFactoryLibV1
- VaultLibV1
- VaultLiquidity
- VaultStrategy
- WithFlashLoan
- WithPausability
- WithRecovery
- Witness