Skip to content

Latest commit

 

History

History
307 lines (264 loc) · 9.18 KB

cxTokenFactory.md

File metadata and controls

307 lines (264 loc) · 9.18 KB

cxToken Factory Contract (cxTokenFactory.sol)

View Source: contracts/core/cxToken/cxTokenFactory.sol

↗ Extends: ICxTokenFactory, Recoverable

cxTokenFactory

Deploys new instances of cxTokens on demand.

Functions

Constructs this contract

function (IStore store) public nonpayable Recoverable 

Arguments

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

deploy

Deploys a new instance of cxTokens

function deploy(bytes32 coverKey, bytes32 productKey, string tokenName, uint256 expiryDate) external nonpayable nonReentrant 
returns(deployed address)

Arguments

Name Type Description
coverKey bytes32 Enter the cover key related to this cxToken instance
productKey bytes32 Enter the product key related to this cxToken instance
tokenName string
expiryDate uint256 Specify the expiry date of this cxToken instance
Source Code
function deploy(
    bytes32 coverKey,
    bytes32 productKey,
    string calldata tokenName,
    uint256 expiryDate
  ) external override nonReentrant returns (address deployed) {
    s.mustNotBePaused();
    s.senderMustBePolicyContract();
    s.mustBeValidCoverKey(coverKey);
    s.mustBeSupportedProductOrEmpty(coverKey, productKey);

    require(expiryDate > 0, "Please specify expiry date");

    (bytes memory bytecode, bytes32 salt) = cxTokenFactoryLibV1.getByteCodeInternal(s, coverKey, productKey, tokenName, expiryDate);

    require(s.getAddress(salt) == address(0), "Already deployed");

    // solhint-disable-next-line
    assembly {
      deployed := create2(
        callvalue(), // wei sent with current call
        // Actual code starts after skipping the first 32 bytes
        add(bytecode, 0x20),
        mload(bytecode), // Load the size of code contained in the first 32 bytes
        salt // Salt from function arguments
      )

      if iszero(extcodesize(deployed)) {
        // @suppress-revert This is correct usage
        revert(0, 0)
      }
    }

    s.setAddress(salt, deployed);
    s.setBoolByKeys(ProtoUtilV1.NS_COVER_CXTOKEN, deployed, true);
    s.setAddressArrayByKeys(ProtoUtilV1.NS_COVER_CXTOKEN, coverKey, productKey, deployed);

    emit CxTokenDeployed(deployed, s, coverKey, productKey, tokenName, expiryDate);
  }

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_CXTOKEN_FACTORY;
  }

Contracts