Skip to content

Latest commit

 

History

History
296 lines (256 loc) · 8.61 KB

VaultFactory.md

File metadata and controls

296 lines (256 loc) · 8.61 KB

Vault Factory Contract (VaultFactory.sol)

View Source: contracts/core/liquidity/VaultFactory.sol

↗ Extends: IVaultFactory, Recoverable

VaultFactory

When a new cover is created, an associated liquidity pool or vault is also created. The cover contract deploys new vaults on demand by utilizing the vault factory contract.

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 Vault

function deploy(bytes32 coverKey, string tokenName, string tokenSymbol) external nonpayable nonReentrant 
returns(addr address)

Arguments

Name Type Description
coverKey bytes32 Enter the cover key related to this Vault instance
tokenName string
tokenSymbol string
Source Code
function deploy(
    bytes32 coverKey,
    string calldata tokenName,
    string calldata tokenSymbol
  ) external override nonReentrant returns (address addr) {
    s.mustNotBePaused();
    s.senderMustBeCoverContract();

    (bytes memory bytecode, bytes32 salt) = VaultFactoryLibV1.getByteCode(s, coverKey, tokenName, tokenSymbol, s.getStablecoin());

    // solhint-disable-next-line
    assembly {
      addr := 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(addr)) {
        // @suppress-revert This is correct usage
        revert(0, 0)
      }
    }

    emit VaultDeployed(coverKey, addr);
  }

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

Contracts