Skip to content

Latest commit

 

History

History
378 lines (315 loc) · 11.1 KB

NeptuneRouterV1.md

File metadata and controls

378 lines (315 loc) · 11.1 KB

NeptuneRouterV1.sol

View Source: contracts/examples/.router/NeptuneRouter.sol

↗ Extends: INeptuneRouterV1, Recoverable

NeptuneRouterV1

Functions

function (IStore store) public nonpayable Recoverable 

Arguments

Name Type Description
store IStore
Source Code
constructor(IStore store) Recoverable(store) {}

addCovers

function addCovers(struct ICover.AddCoverArgs[] args) external nonpayable
returns(vaults address[])

Arguments

Name Type Description
args struct ICover.AddCoverArgs[]
Source Code
function addCovers(ICover.AddCoverArgs[] calldata args) external override returns (address[] memory vaults) {
    IERC20 npm = s.npmToken();
    IERC20 stablecoin = IERC20(s.getStablecoin());

    ICover cover = s.getCoverContract();

    uint256 totalStakeWithFee;
    uint256 totalReassurance;

    for (uint256 i = 0; i < args.length; i++) {
      totalStakeWithFee += args[i].stakeWithFee;
      totalReassurance += args[i].initialReassuranceAmount;
    }

    npm.ensureTransferFrom(msg.sender, address(this), totalStakeWithFee);

    npm.ensureApproval(address(cover), totalStakeWithFee);

    if (totalReassurance > 0) {
      stablecoin.ensureTransferFrom(msg.sender, address(this), totalReassurance);
      stablecoin.ensureApproval(address(cover), totalReassurance);
    }

    vaults = new address[](args.length + 1);

    for (uint256 i = 0; i < args.length; i++) {
      vaults[i] = cover.addCover(args[i]);
    }
  }

addProducts

function addProducts(struct ICover.AddProductArgs[] args) external nonpayable

Arguments

Name Type Description
args struct ICover.AddProductArgs[]
Source Code
function addProducts(ICover.AddProductArgs[] calldata args) external override {
    ICover cover = s.getCoverContract();

    for (uint256 i = 0; i < args.length; i++) {
      cover.addProduct(args[i]);
    }
  }

_getFee

function _getFee(struct IPolicy.PurchaseCoverArgs[] args) private view
returns(total uint256)

Arguments

Name Type Description
args struct IPolicy.PurchaseCoverArgs[]
Source Code
function _getFee(IPolicy.PurchaseCoverArgs[] calldata args) private view returns (uint256 total) {
    for (uint256 i = 0; i < args.length; i++) {
      PolicyHelperV1.CalculatePolicyFeeArgs memory policyFeeArgs = PolicyHelperV1.CalculatePolicyFeeArgs({
        coverKey: args[i].coverKey,
        productKey: args[i].productKey,
        coverDuration: args[i].coverDuration,
        amountToCover: args[i].amountToCover
      });

      (uint256 fee, ) = s.getPolicyFeeInternal(policyFeeArgs);
      total += fee;
    }
  }

purchaseCovers

function purchaseCovers(struct IPolicy.PurchaseCoverArgs[] args) external nonpayable

Arguments

Name Type Description
args struct IPolicy.PurchaseCoverArgs[]
Source Code
function purchaseCovers(IPolicy.PurchaseCoverArgs[] calldata args) external override {
    uint256 fee = _getFee(args);

    IERC20 stablecoin = IERC20(s.getStablecoin());
    IPolicy policy = s.getPolicyContract();

    stablecoin.ensureTransferFrom(msg.sender, address(this), fee);
    stablecoin.ensureApproval(address(policy), fee);

    for (uint256 i = 0; i < args.length; i++) {
      policy.purchaseCover(args[i]);
    }
  }

addLiquidities

function addLiquidities(struct IVault.AddLiquidityArgs[] args) external nonpayable

Arguments

Name Type Description
args struct IVault.AddLiquidityArgs[]
Source Code
function addLiquidities(IVault.AddLiquidityArgs[] calldata args) external override {
    IERC20 stablecoin = IERC20(s.getStablecoin());
    IERC20 npm = s.npmToken();

    uint256 totalAmount;
    uint256 totalNpm;

    for (uint256 i = 0; i < args.length; i++) {
      totalAmount += args[i].amount;
      totalNpm += args[i].npmStakeToAdd;
    }

    stablecoin.ensureTransferFrom(msg.sender, address(this), totalAmount);
    npm.ensureTransferFrom(msg.sender, address(this), totalNpm);

    for (uint256 i = 0; i < args.length; i++) {
      IVault vault = s.getVault(args[i].coverKey);

      stablecoin.approve(address(vault), args[i].amount);
      npm.approve(address(vault), args[i].npmStakeToAdd);

      vault.addLiquidity(args[i]);

      IERC20(vault).ensureTransfer(msg.sender, vault.balanceOf(address(this)));
    }
  }

Contracts