Create a New Cover

This example creates a new cover contract on Neptune Mutual DAO on the chosen network/chain. When you create a new cover, a couple of smart contract instances are deployed automatically behind the scenes:

  • Cover Vault

  • Cover Token

Step 1: Create a Cover Info Object

Compose a javascript object having the following structure:

interface ICoverInfo {
key: string
coverName: string
projectName: string
about: string
tags: string[]
blockchain: {
chainId: number
name: string
}
smartContracts: string[]
rules: string
links: {
website: string
documentation: string
telegram: string
twitter: string
github: string
facebook: string
blog: string
discord: string
linkedin: string
slack: string
}
reportingPeriod: number
selfCoveragePeriod: number
resolutionSources: string[]
assuranceToken: {
at: string
name: string
symbol: string
initialAmount: string
}
stakeWithFees: string
initialLiquidity: string
}

Example:

const info = {
key: '0x70726f746f3a636f6e7472616374733a636f7665723a6366633a303100000000',
coverName: 'Compound Finance Cover',
projectName: 'Compound Finance',
about: 'Compound is an algorithmic, autonomous interest rate protocol built for developers, to unlock a universe of open financial applications.',
tags: ['Smart Contract', 'DeFi', 'Lending'],
blockchain: {
chainId: 1,
name: 'Main Ethereum Network'
},
smartContracts: ['0xc00e94cb662c3520282e6f5717214004a7f26888'],
rules: `1. You must have maintained at least 1 NEP tokens in your wallet during your coverage period.
2. During your coverage period, the protocol faced an attack, hack, exploitation, or vulnerability which resulted in the user assets being stolen or lost and the protocol was also unable to cover the loss themselves. This does not have to be your own loss.
3. The protocol never communicated anything about their plans to cover the lost fund and de-risk their users within 7 days of the incident.
4. The protocol promised but later were unable to cover, write off, or bear at least 75% of the sufferred loss on behalf of their users within 30 days of the incident`,
links: {
website: 'https://compound.finance/',
documentation: 'https://docs.compound.finance/',
telegram: null,
twitter: 'https://twitter.com/compoundfinance',
github: 'https://github.com/compound',
facebook: 'https://facebook.com/compoundfinance',
blog: 'https://blog.medium.com/compoundfinance',
discord: 'https://discord.com/invite/cU7vmVW',
linkedin: 'https://linkedin.com/in/compoundfinance',
slack: null
},
reportingPeriod: 7,
selfCoveragePeriod: 30,
resolutionSources: ['https://twitter.com/compoundfinance', 'https://medium.com/compound-finance', 'https://twitter.com/neptunemutual'],
assuranceToken: {
at: '0x0e7c8a8545352663ee070f1c9a0174f4a50532dc',
name: 'Compound',
symbol: 'COMP',
initialAmount: '5000000000000000000000'
},
stakeWithFees: '5000000000000000000000',
initialLiquidity: '5000000000000000000000'
}
export { info }

info.js file

Step 2: Submit Approvals

Before you can create a new cover, you must submit at least one approval transaction:

  • NEP Token: Approve Stake and Fees (Required)

  • Assurance Token: Approve Initial Assurance Amount (Optional)

  • Stablecoin (DAI/BUSD/xDAI/USDC): Approve Initial Liquidity (Optional)

const info = {
// ...,
assuranceToken: {
at: '0x0e7c8a8545352663ee070f1c9a0174f4a50532dc',
name: 'Compound',
symbol: 'COMP',
initialAmount: '5000000000000000000000'
},
stakeWithFees: '5000000000000000000000',
initialLiquidity: '5000000000000000000000'
}

If you do not create Assurance Token and Stablecoin approvals, you must set the assuranceToken.initialAmount and initialLiquidity to zero.

Approve Assurance Token (Optional)

If you defined Assurance Token and initial amount in your info.js file, you need to first submit an approval transaction allowing the protocol to transfer the assurance amount to itself.

import { ChainId, cover } from '@neptunemutual/sdk'
import { info } from './info.js'
import { getProvider } from './provider.js'
const create = async () => {
const provider = getProvider()
const response = await cover.approveAssurance(ChainId.Mumbai, info.assuranceToken.at, { amount: info.assuranceToken.initialAmount }, provider)
console.info(response)
}
create()
/*****************************************************************************
{
status: 'Success',
result: {
nonce: 1,
gasPrice: BigNumber { _hex: '0x06fc23ac00', _isBigNumber: true },
gasLimit: BigNumber { _hex: '0x6aa8', _isBigNumber: true },
to: '0x0e7C8A8545352663EE070f1C9a0174f4A50532DC',
value: BigNumber { _hex: '0x00', _isBigNumber: true },
data: '0x095ea7b30000000000000000000000006fb2eaf0b7770087314df3cb73c34b510c2c2354ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
chainId: 80001,
v: 160038,
r: '0xe24c90cc3b940de7929b634d8672e329ee7c02836ef8cbf65b0db0b6bf2cebc1',
s: '0x3be2aa4932cac043da64a10f35e6bd1fa81ec51a203911d2afc86a800c1d39d4',
from: '0x589C82ee29ab1d609FE2F0856E00c2988e75eE51',
hash: '0x74aeb8be4055afafb7e42fc38a5b0ea46ffa85e2bae0b0314818771de62f12bb',
type: null,
wait: [Function (anonymous)]
}
}
*****************************************************************************/

Approve Initial Liquidity (Optional)

Similarly, if you also defined Initial Liquidity Amount when creating the info.js file, you need to submit an approval transaction in advance, allowing the protocol to transfer the amount to itself.

import { ChainId, cover } from '@neptunemutual/sdk'
import { info } from './info.js'
import { getProvider } from './provider.js'
const create = async () => {
const provider = getProvider()
await cover.approveAssurance(ChainId.Mumbai, info.assuranceToken.at, { amount: info.assuranceToken.initialAmount }, provider)
const response = await cover.approveInitialLiquidity(ChainId.Mumbai, { amount: info.initialLiquidity }, provider)
console.info(response)
}
create()
/*****************************************************************************
{
status: 'Success',
result: {
nonce: 1,
gasPrice: BigNumber { _hex: '0x06fc23ac00', _isBigNumber: true },
gasLimit: BigNumber { _hex: '0x6994', _isBigNumber: true },
to: '0x62E329214173E1C50A7Aee8DC2Ca5e04af6D6B6f',
value: BigNumber { _hex: '0x00', _isBigNumber: true },
data: '0x095ea7b300000000000000000000000071698490a88f937e0ef7ed2cc01a58f98de5fc9c00000000000000000000000000000000000000000000010f0cf064dd59200000',
chainId: 80001,
v: 160037,
r: '0x5e6b3321ac4faa32c1c71ede399eef59de63025efaec9b7a4e2cf9cca11ef1b2',
s: '0x78743438938da20deb63e2bf2e4546fd281284154a7cb862b8596ea0aaf732be',
from: '0x589C82ee29ab1d609FE2F0856E00c2988e75eE51',
hash: '0x27b45289bd5fdd03128e6435a5d9ea9d128ca7af2973348ef7f5177d9712af49',
type: null,
wait: [Function (anonymous)]
}
}
*****************************************************************************/

Approve Stake and Fee (Required)

You need to specify the total amount of NEP tokens to approve which contains both the stake and fees.

import { ChainId, cover } from '@neptunemutual/sdk'
import { info } from './info.js'
import { getProvider } from './provider.js'
const create = async () => {
const provider = getProvider()
await cover.approveAssurance(ChainId.Mumbai, info.assuranceToken.at, { amount: info.assuranceToken.initialAmount }, provider)
await cover.approveInitialLiquidity(ChainId.Mumbai, { amount: info.initialLiquidity }, provider)
const response = await cover.approveStakeAndFees(ChainId.Mumbai, { amount: info.stakeWithFees }, provider)
console.info(response)
}
create()
/*****************************************************************************
{
status: 'Success',
result: {
nonce: 1,
gasPrice: BigNumber { _hex: '0x06fc23ac00', _isBigNumber: true },
gasLimit: BigNumber { _hex: '0x6994', _isBigNumber: true },
to: '0xaa6E152DCF34F54aCa65d5c4a720763e347F42d4',
value: BigNumber { _hex: '0x00', _isBigNumber: true },
data: '0x095ea7b30000000000000000000000009147a5cb1f858a8dc5ca2c26ec929e6ec38bac3200000000000000000000000000000000000000000000010f0cf064dd59200000',
chainId: 80001,
v: 160037,
r: '0x23bb2d67079f17cb2219d83d653579519484e40e7bf97f4928e30644c248a52b',
s: '0x75fa3e04cf1bc0bee5667d4301a39cdba0ca2609afa5b9253816580ac7d5ac17',
from: '0x589C82ee29ab1d609FE2F0856E00c2988e75eE51',
hash: '0x1efb4e593e29999814da5edfb210f3c60a7b3682c063a6bf85265e1d6b498d35',
type: null,
wait: [Function (anonymous)]
}
}
*****************************************************************************/

Step 3: Adding a New Cover

Once you've signed the approval transactions, creating a new cover is very easy. There is only one line to add:

await cover.createCover(ChainId.Mumbai, info, provider)

The whole thing now looks something like this:

import { ChainId, cover } from '@neptunemutual/sdk'
import { info } from './info.js'
import { getProvider } from './provider.js'
const create = async () => {
const provider = getProvider()
await cover.approveAssurance(ChainId.Mumbai, info.assuranceToken.at, { amount: info.assuranceToken.initialAmount }, provider)
await cover.approveInitialLiquidity(ChainId.Mumbai, { amount: info.initialLiquidity }, provider)
await cover.approveStakeAndFees(ChainId.Mumbai, { amount: info.stakeWithFees }, provider)
const response = await cover.createCover(ChainId.Mumbai, info, provider)
console.info(response)
}
/*****************************************************************************
[info] {
status: 'Success',
result: {
storage: {
hashBytes32: '0x9ddc75bafdada33df8b2bc2613815fac5c22cc53119a23e6914936ae1ccdc22d',
hash: 'QmYxshCcu1R6Pp37BEQpyqgUgJBmaBnvgN9dFxtKsZqN36',
permalink: 'https://ipfs.infura.io/ipfs/QmYxshCcu1R6Pp37BEQpyqgUgJBmaBnvgN9dFxtKsZqN36'
},
tx: {
nonce: 1,
gasPrice: [BigNumber],
gasLimit: [BigNumber],
to: '0xDd4F24aEe772170487B3327e10Cd7a956c0A0E62',
value: [BigNumber],
data: '0x56aeb05f70726f746f3a636f6e7472616374733a636f7665723a6366633a3031000000029ddc75bafdada33df8b2bc2613815fac5c22cc53119a23e6914936ae1ccdc22d0000000000000000000000000000000000000000000000000000000000093a80000000000000000000000000000000000000000000000a968163f0a57b4000000000000000000000000000001dc2c4363d7e5965f3b9cb404c0e47e497ae5df7000000000000000000000000000000000000000000000a968163f0a57b400000000000000000000000000000000000000000000000000a968163f0a57b400000',
chainId: 80001,
v: 160037,
r: '0xc6d48b47da21895623853d4530b1a31cf9ac3fe28d53231c75bc200688768773',
s: '0x03f97ea2c9c0d3b26dc37eccc9dbf6269a0bace42caf1391e8902a08bda7d584',
from: '0x076F91C0A411197e6Fce476F37c6385CCeacd26D',
hash: '0x6678475de0dd18074affcdec1439fd35c17503bb4000eab430de43b89eeb709c',
type: null,
wait: [Function (anonymous)]
}
}
}
*****************************************************************************/