Create a New Cover
This example shows how to create a new cover contract on Neptune Mutual protocol on your chosen network/chain. Before anyone can supply liquidity to a cover, you'll also need to deploy its vault.

Step 1: Create a Cover Info Object

Compose a javascript object having the following structure:
1
interface ICoverInfo {
2
key: string
3
coverName: string
4
projectName?: string
5
tags: string[]
6
about: string
7
blockchains: [{
8
chainId?: number
9
name: string
10
}]
11
rules: string
12
links: {
13
website: string
14
documentation?: string
15
telegram?: string
16
twitter?: string
17
github?: string
18
facebook?: string
19
blog?: string
20
discord?: string
21
linkedin?: string
22
slack?: string
23
}
24
pricingFloor: string
25
pricingCeiling: string
26
reportingPeriod: string
27
cooldownPeriod: string
28
claimPeriod: string
29
minReportingStake: string
30
resolutionSources: string[]
31
stakeWithFees: string
32
reassurance: string
33
}
34
35
export { ICoverInfo }
36
Copied!
Example:
1
import BigNumber from 'bignumber.js'
2
const DAYS = 86400
3
const ether = (x) => BigNumber((parseFloat(x.toString()) * 10 ** 18).toString()).toString()
4
5
const info = {
6
key: '0x70726f746f3a636f6e7472616374733a636f7665723a6366633a303100000000',
7
coverName: 'Compound Finance Cover',
8
projectName: 'Compound Finance',
9
tags: ['Smart Contract', 'DeFi', 'Lending'],
10
about: 'Compound is an algorithmic, autonomous interest rate protocol built for developers, to unlock a universe of open financial applications.',
11
blockchains: [{
12
chainId: 1,
13
name: 'Main Ethereum Network'
14
}],
15
rules: 'Enter your cover rules here',
16
links: {
17
website: 'https://compound.finance/',
18
documentation: 'https://docs.compound.finance/',
19
twitter: 'https://twitter.com/compoundfinance',
20
github: 'https://github.com/compound',
21
facebook: 'https://facebook.com/compoundfinance',
22
blog: 'https://blog.medium.com/compoundfinance',
23
discord: 'https://discord.com/invite/cU7vmVW',
24
linkedin: 'https://linkedin.com/in/compoundfinance'
25
},
26
pricingFloor: '60_000',
27
pricingCeiling: '120_000',
28
reportingPeriod: BigNumber(7 * DAYS),
29
cooldownPeriod: BigNumber(1 * DAYS),
30
claimPeriod: BigNumber(7 * DAYS),
31
minReportingStake: ether(5000).toString(),
32
resolutionSources: ['https://twitter.com/compoundfinance', 'https://medium.com/compound-finance', 'https://twitter.com/neptunemutual'],
33
stakeWithFees: ether(50_000),
34
reassurance: ether(50_000)
35
}
36
37
export { info }
Copied!

info.js file

Step 2: Submit Approvals

Before you can create a new cover, you must submit at least one approval transaction:
  • NPM Token: Approve Stake and Fees (Required)
  • Reassurance Token: Approve Initial Reassurance Amount (Optional)
1
const info = {
2
// ...,
3
minReportingStake: ether(5000).toString(),
4
resolutionSources: ['https://twitter.com/compoundfinance', 'https://medium.com/compound-finance', 'https://twitter.com/neptunemutual'],
5
stakeWithFees: ether(50_000),
6
reassurance: ether(50_000)
7
}
Copied!
If you do not create Reassurance Token and Stablecoin approvals, you must set the reassuranceToken.initialAmount and initialLiquidity to zero.

Approve Reassurance Token (Optional)

If you defined Reassurance Token and initial amount in your info.js file, you need to first submit an approval transaction allowing the protocol to transfer the reassurance amount to itself.
1
import { ChainId, cover } from '@neptunemutual/sdk'
2
import { info } from './info.js'
3
import { getProvider } from './provider.js'
4
5
const create = async () => {
6
const provider = getProvider()
7
8
const response = await cover.approveReassurance(ChainId.Mumbai, { amount: info.assuranceToken.initialAmount }, provider)
9
console.info(response)
10
}
11
12
create()
13
14
/*****************************************************************************
15
{
16
status: 'Success',
17
result: {
18
nonce: 1,
19
gasPrice: BigNumber { _hex: '0x06fc23ac00', _isBigNumber: true },
20
gasLimit: BigNumber { _hex: '0x6aa8', _isBigNumber: true },
21
to: '0x0e7C8A8545352663EE070f1C9a0174f4A50532DC',
22
value: BigNumber { _hex: '0x00', _isBigNumber: true },
23
data: '0x095ea7b30000000000000000000000006fb2eaf0b7770087314df3cb73c34b510c2c2354ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
24
chainId: 80001,
25
v: 160038,
26
r: '0xe24c90cc3b940de7929b634d8672e329ee7c02836ef8cbf65b0db0b6bf2cebc1',
27
s: '0x3be2aa4932cac043da64a10f35e6bd1fa81ec51a203911d2afc86a800c1d39d4',
28
from: '0x589C82ee29ab1d609FE2F0856E00c2988e75eE51',
29
hash: '0x74aeb8be4055afafb7e42fc38a5b0ea46ffa85e2bae0b0314818771de62f12bb',
30
type: null,
31
wait: [Function (anonymous)]
32
}
33
}
34
*****************************************************************************/
Copied!

Approve Stake and Fee (Required)

You need to specify the total amount of NPM tokens to approve which contains both the stake and fees.
1
import { ChainId, cover } from '@neptunemutual/sdk'
2
import { info } from './info.js'
3
import { getProvider } from './provider.js'
4
5
const create = async () => {
6
const provider = getProvider()
7
8
await cover.approveReassurance(ChainId.Mumbai, { amount: info.assuranceToken.initialAmount }, provider)
9
const response = await cover.approveStakeAndFees(ChainId.Mumbai, { amount: info.stakeWithFees }, provider)
10
11
console.info(response)
12
}
13
14
create()
15
16
/*****************************************************************************
17
{
18
status: 'Success',
19
result: {
20
nonce: 1,
21
gasPrice: BigNumber { _hex: '0x06fc23ac00', _isBigNumber: true },
22
gasLimit: BigNumber { _hex: '0x6994', _isBigNumber: true },
23
to: '0xaa6E152DCF34F54aCa65d5c4a720763e347F42d4',
24
value: BigNumber { _hex: '0x00', _isBigNumber: true },
25
data: '0x095ea7b30000000000000000000000009147a5cb1f858a8dc5ca2c26ec929e6ec38bac3200000000000000000000000000000000000000000000010f0cf064dd59200000',
26
chainId: 80001,
27
v: 160037,
28
r: '0x23bb2d67079f17cb2219d83d653579519484e40e7bf97f4928e30644c248a52b',
29
s: '0x75fa3e04cf1bc0bee5667d4301a39cdba0ca2609afa5b9253816580ac7d5ac17',
30
from: '0x589C82ee29ab1d609FE2F0856E00c2988e75eE51',
31
hash: '0x1efb4e593e29999814da5edfb210f3c60a7b3682c063a6bf85265e1d6b498d35',
32
type: null,
33
wait: [Function (anonymous)]
34
}
35
}
36
*****************************************************************************/
Copied!

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:
1
await cover.createCover(ChainId.Mumbai, info, provider)
Copied!
The whole thing now looks something like this:
1
import { ChainId, cover } from '@neptunemutual/sdk'
2
import { info } from './info.js'
3
import { getProvider } from './provider.js'
4
5
const create = async () => {
6
const provider = getProvider()
7
8
await cover.approveReassurance(ChainId.Mumbai, { amount: info.assuranceToken.initialAmount }, provider)
9
await cover.approveStakeAndFees(ChainId.Mumbai, { amount: info.stakeWithFees }, provider)
10
11
const response = await cover.createCover(ChainId.Mumbai, info, provider) // cover stopped
12
await cover.deployVault(ChainId.Mumbai, info.coverKey) // cover starts
13
console.info(response)
14
}
15
16
/*****************************************************************************
17
[info] {
18
status: 'Success',
19
result: {
20
storage: {
21
hashBytes32: '0x9ddc75bafdada33df8b2bc2613815fac5c22cc53119a23e6914936ae1ccdc22d',
22
hash: 'QmYxshCcu1R6Pp37BEQpyqgUgJBmaBnvgN9dFxtKsZqN36',
23
permalink: 'https://ipfs.infura.io/ipfs/QmYxshCcu1R6Pp37BEQpyqgUgJBmaBnvgN9dFxtKsZqN36'
24
},
25
tx: {
26
nonce: 1,
27
gasPrice: [BigNumber],
28
gasLimit: [BigNumber],
29
to: '0xDd4F24aEe772170487B3327e10Cd7a956c0A0E62',
30
value: [BigNumber],
31
data: '0x56aeb05f70726f746f3a636f6e7472616374733a636f7665723a6366633a3031000000029ddc75bafdada33df8b2bc2613815fac5c22cc53119a23e6914936ae1ccdc22d0000000000000000000000000000000000000000000000000000000000093a80000000000000000000000000000000000000000000000a968163f0a57b4000000000000000000000000000001dc2c4363d7e5965f3b9cb404c0e47e497ae5df7000000000000000000000000000000000000000000000a968163f0a57b400000000000000000000000000000000000000000000000000a968163f0a57b400000',
32
chainId: 80001,
33
v: 160037,
34
r: '0xc6d48b47da21895623853d4530b1a31cf9ac3fe28d53231c75bc200688768773',
35
s: '0x03f97ea2c9c0d3b26dc37eccc9dbf6269a0bace42caf1391e8902a08bda7d584',
36
from: '0x076F91C0A411197e6Fce476F37c6385CCeacd26D',
37
hash: '0x6678475de0dd18074affcdec1439fd35c17503bb4000eab430de43b89eeb709c',
38
type: null,
39
wait: [Function (anonymous)]
40
}
41
}
42
}
43
*****************************************************************************/
Copied!