Claims & Payouts
Supply your cxTokens to the Claims Processor contract to receive the payout in stablecoin tokens.
import { ChainId, governance, claimsProcessor, cxToken, utils } from '@neptunemutual/sdk'
import { info } from '../configs/info.js'
import { getProvider } from '../provider.js'
import { ether } from '../bn.js'
const getCxToken = async (coverKey, productKey, provider) => {
const policyDuration = 2 // 2 months
const expiryDate = utils.date.getExpiryDate(policyDuration, new Date())
const { result } = await cxToken.getCTokenByExpiryDate(ChainId.Mumbai, coverKey, productKey, expiryDate, provider)
return result
}
const claim = async () => {
try {
const { key } = info
const productKey = utils.keyUtil.toBytes32('')
const provider = getProvider()
const amount = ether(20)
const instance = await getCxToken(key, productKey, provider)
// Approve the claims processor to spend your cxTokens
let response = await claimsProcessor.approve(ChainId.Mumbai, instance.address, {}, provider)
await response.result.wait()
// Get the incident date and submit a claim
const incidentDate = (await governance.getIncidentDate(ChainId.Mumbai, key, productKey, provider)).result
response = await claimsProcessor.claim(ChainId.Mumbai, instance.address, key, productKey, incidentDate, amount, provider)
await response.result.wait()
console.info('We\'ve sent you the payout')
} catch (error) {
console.error(error)
}
}
claim()
/*****************************************************************************
[info] We've sent you the payout
*****************************************************************************/
Ensure that you submit a claim only when the resolution occurs or else, you may receive an error message
/*****************************************************************************
[error] Error: execution reverted: Invalid incident date
at getResult (/projects/@neptunemutual/sdk-test/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:132:21)
at processJsonFunc (/projects/@neptunemutual/sdk-test/node_modules/@ethersproject/web/lib/index.js:309:22)
at /projects/@neptunemutual/sdk-test/node_modules/@ethersproject/web/lib/index.js:241:46
at step (/projects/@neptunemutual/sdk-test/node_modules/@ethersproject/web/lib/index.js:33:23)
at Object.next (/projects/@neptunemutual/sdk-test/node_modules/@ethersproject/web/lib/index.js:14:53)
at fulfilled (/projects/@neptunemutual/sdk-test/node_modules/@ethersproject/web/lib/index.js:5:58)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
code: 3,
data: '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000c436c61696d2064656e6965640000000000000000000000000000000000000000'
}
*****************************************************************************/
Copy link