forked from neptune-mutual-blue/protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For cover creation, added a deployment script for Popular DeFi Apps
- Loading branch information
Showing
17 changed files
with
914 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
const hre = require('hardhat') | ||
const prime = require('../diversified/popular-defi-apps') | ||
const ethereum = require('../../config/deployments/ethereum.json') | ||
const ipfs = require('../../../util/ipfs') | ||
const { getNetworkInfo } = require('../../../util/network') | ||
const { weiAsToken } = require('../../../util/helper') | ||
|
||
const { ethers } = hre | ||
|
||
const DEPLOYMENT_ID = 6 | ||
|
||
const attach = async (connectedTo, at, contractName, libraries) => { | ||
const contract = libraries ? await ethers.getContractFactory(contractName, libraries) : await ethers.getContractFactory(contractName) | ||
return contract.connect(connectedTo).attach(at) | ||
} | ||
|
||
const getContractInstance = async (connectedTo, deployments, contractName) => { | ||
for (const prop in deployments) { | ||
const candidate = deployments[prop] | ||
if (candidate.contractName === contractName) { | ||
const { data, contractName, address } = candidate | ||
return attach(connectedTo, address, contractName, data) | ||
} | ||
} | ||
} | ||
|
||
const getContracts = async () => { | ||
const signer = await getSigner(process.env.COVER_CREATOR) | ||
const network = await getNetworkInfo() | ||
const { deployedTokens } = network | ||
const { deployments } = ethereum[DEPLOYMENT_ID] | ||
|
||
const cover = await getContractInstance(signer, deployments, 'Cover') | ||
|
||
const npm = await attach(signer, deployedTokens.NPM, 'POT', {}) | ||
|
||
return { cover, npm } | ||
} | ||
|
||
const getSigner = async (impersonate) => { | ||
const network = await getNetworkInfo() | ||
|
||
if (network.mainnet) { | ||
const [owner] = await ethers.getSigners() | ||
return owner | ||
} | ||
|
||
await hre.network.provider.request({ | ||
method: 'hardhat_impersonateAccount', | ||
params: [impersonate] | ||
}) | ||
|
||
return ethers.provider.getSigner(impersonate) | ||
} | ||
|
||
const approve = async (contracts, cover) => { | ||
try { | ||
const signer = await getSigner(process.env.COVER_CREATOR) | ||
console.info('Approving the cover contract to spend %s tokens', weiAsToken(cover.stakeWithFee, 'NPM')) | ||
const allowance = await contracts.npm.allowance(signer.address || signer._address, contracts.cover.address) | ||
|
||
if (allowance.gte(cover.stakeWithFee)) { | ||
console.log('Approval not required') | ||
return | ||
} | ||
|
||
const tx = await contracts.npm.approve(contracts.cover.address, cover.stakeWithFee) | ||
console.log('Approval: %s/tx/%s', hre.network.config.explorer, tx.hash) | ||
} catch (error) { | ||
console.error('Error approving Signer\'s NPM tokens to the cover address') | ||
throw error | ||
} | ||
} | ||
|
||
const deploy = async () => { | ||
const balances = [] | ||
const { cover, products } = prime | ||
|
||
const contracts = await getContracts() | ||
|
||
const signer = await getSigner(process.env.COVER_CREATOR) | ||
balances.push(await ethers.provider.getBalance(signer.address || signer._address)) | ||
|
||
console.log('\n') | ||
console.log('Signer [%s]: https://etherscan.io/address/%s', weiAsToken(balances[0], 'ETH'), signer.address ?? signer._address) | ||
|
||
console.log('-'.repeat(128)) | ||
|
||
await approve(contracts, cover) | ||
|
||
console.log('-'.repeat(128)) | ||
|
||
const info = await ipfs.write(cover) | ||
|
||
console.info('Adding a new cover %s', cover.coverName) | ||
let tx = await contracts.cover.addCover({ info, ...cover }) | ||
console.log('Created the cover %s: %s/tx/%s', cover.coverName, hre.network.config.explorer, tx.hash) | ||
|
||
console.log('-'.repeat(128)) | ||
|
||
const args = await Promise.all(products.map(async (x) => { | ||
return { | ||
coverKey: x.coverKey, | ||
productKey: x.productKey, | ||
info: await ipfs.write(x), | ||
requiresWhitelist: x.requiresWhitelist, | ||
productStatus: '1', | ||
efficiency: x.efficiency | ||
} | ||
})) | ||
|
||
const productList = products.map(x => x.productName).join(', ') | ||
|
||
console.info('Adding products %s under the cover %s', productList, cover.coverName) | ||
tx = await contracts.cover.addProducts(args) | ||
console.log('Created products for %s: %s/tx/%s', cover.coverName, hre.network.config.explorer, tx.hash) | ||
|
||
console.log('-'.repeat(128)) | ||
|
||
balances.push(await ethers.provider.getBalance(signer.address || signer._address)) | ||
const [previous, current] = balances | ||
|
||
console.info('Balance: %s. Gas cost: %s', weiAsToken(current, 'ETH'), weiAsToken(previous.sub(current), 'ETH')) | ||
} | ||
|
||
module.exports = { deploy } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { key, helper } = require('../../../../util') | ||
const { ether, percentage } = helper | ||
|
||
const DAYS = 86400 | ||
|
||
module.exports = { | ||
coverKey: key.toBytes32('popular-defi-apps'), | ||
coverName: 'Popular DeFi Apps', | ||
projectName: null, | ||
tokenName: 'Yield Bearing USDC', | ||
tokenSymbol: 'iUSDC-POP', | ||
requiresWhitelist: false, | ||
supportsProducts: true, | ||
leverageFactor: '6', | ||
tags: ['nft', 'exchange', 'dex', 'swap', 'fork', 'stablecoin', 'lending', 'flashloan', 'borrowing', 'interest', 'loan', 'staking', 'yield', 'insurance', 'payment'], | ||
about: '', | ||
blockchains: [{ | ||
chainId: 1, | ||
name: 'Main Ethereum Network' | ||
}, | ||
{ | ||
chainId: 42161, | ||
name: 'Arbitrum' | ||
}], | ||
floor: percentage(2), | ||
ceiling: percentage(12), | ||
reportingPeriod: 7 * DAYS, | ||
cooldownPeriod: 1 * DAYS, | ||
claimPeriod: 7 * DAYS, | ||
minStakeToReport: ether(10_000), | ||
stakeWithFee: ether(30_000), | ||
initialReassuranceAmount: '0', | ||
reassuranceRate: percentage(25) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const cover = require('./cover') | ||
const products = require('./products') | ||
|
||
module.exports = { cover, products } |
83 changes: 83 additions & 0 deletions
83
scripts/covers/diversified/popular-defi-apps/products/aave.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
const { helper, key } = require('../../../../../util') | ||
const cover = require('../cover') | ||
|
||
module.exports = { | ||
coverKey: cover.coverKey, | ||
productKey: key.toBytes32('aave-v3'), | ||
productName: 'Aave v3', | ||
requiresWhitelist: false, | ||
efficiency: helper.percentage(90), | ||
tags: ['borrowing', 'loan', 'interest', 'interest-bearing', 'lending', 'yield', 'staking'], | ||
about: 'Aave is a decentralized non-custodial liquidity protocol where users can participate as depositors or borrowers. Depositors provide liquidity to the market to earn a passive income, while borrowers are able to borrow in an overcollateralized (perpetually) or undercollateralized (one-block liquidity) fashion.', | ||
blockchains: [{ | ||
chainId: 1, | ||
name: 'Main Ethereum Network' | ||
}, | ||
{ | ||
chainId: 42161, | ||
name: 'Arbitrum' | ||
}], | ||
parameters: [ | ||
{ | ||
parameter: 'Cover Policy Conditions', | ||
type: 'condition', | ||
text: 'This cover is not a contract of insurance. Cover is provided on a parametric basis and the decision as to whether or not an incident is validated is determined by Neptune Mutual’s incident reporting and resolution process whereby the result is based on the number of NPM tokens or vouchers staked by the community in the resolution process; this incident reporting and validation process is community driven, but in exceptional circumstances can be overridden by the Neptune Mutual Association in order to protect against certain types of on-chain consensus attacks.', | ||
list: { | ||
type: 'unordered', | ||
items: [ | ||
'This policy relates exclusively to the AAVE v3 protocol deployed on the Arbitrum and Ethereum blockchain (if available).', | ||
'To be eligible for a claim, policyholder must hold at least 49 NPM tokens in the wallet used for the policy transaction for the full duration of the cover policy.' | ||
] | ||
} | ||
}, | ||
{ | ||
parameter: 'Cover Parameters', | ||
type: 'parameter', | ||
text: 'All of the following parameters must be applicable for the policy to be validated:', | ||
list: { | ||
type: 'ordered', | ||
items: [ | ||
'Minimum total loss of user funds from the reported incident should exceed $5 million.', | ||
'The designated protocol suffers a hack of user funds in which the user funds are permanently and irrecoverably stolen from the protocol.', | ||
'The loss arises from a smart contract vulnerability.', | ||
'The loss must arise from one of the following blockchains: Arbitrum and Ethereum (if available).' | ||
] | ||
} | ||
}, | ||
{ | ||
parameter: 'Cover Exclusions', | ||
type: 'exclusion', | ||
list: { | ||
type: 'ordered', | ||
items: [ | ||
'Incident on any blockchain that is not supported by this cover.', | ||
'Frontend, hosting, server or network infrastructure, database, DNS server, CI/CD, and/or supply-chain attacks.', | ||
'All exclusions present in the standard terms and conditions.' | ||
] | ||
} | ||
} | ||
], | ||
links: { | ||
website: 'https://aave.com/', | ||
documentation: 'https://docs.aave.com/', | ||
twitter: 'https://twitter.com/aaveaave', | ||
github: 'https://github.com/aave', | ||
discord: 'https://discord.com/invite/CvKUrqM', | ||
telegram: 'https://t.me/Aavesome', | ||
blog: 'https://medium.com/aave' | ||
}, | ||
resolutionSources: [ | ||
{ | ||
text: 'Aave Twitter', | ||
uri: 'https://twitter.com/aaveaave' | ||
}, | ||
{ | ||
text: 'Aave Blog', | ||
uri: 'https://medium.com/aave' | ||
}, | ||
{ | ||
text: 'Neptune Mutual Twitter', | ||
uri: 'https://twitter.com/neptunemutual' | ||
} | ||
] | ||
} |
81 changes: 81 additions & 0 deletions
81
scripts/covers/diversified/popular-defi-apps/products/bancor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const { helper, key } = require('../../../../../util') | ||
const cover = require('../cover') | ||
|
||
module.exports = { | ||
coverKey: cover.coverKey, | ||
productKey: key.toBytes32('bancor-v3'), | ||
productName: 'Bancor v3', | ||
requiresWhitelist: false, | ||
efficiency: helper.percentage(50), | ||
tags: ['exchange', 'dex', 'swap'], | ||
about: 'Bancor was the first dApp that utilized AMM model and also pioneered the efforts in "impermanent loss" protection', | ||
blockchains: [{ | ||
chainId: 1, | ||
name: 'Main Ethereum Network' | ||
}], | ||
parameters: [ | ||
{ | ||
parameter: 'Cover Policy Conditions', | ||
type: 'condition', | ||
text: 'This cover is not a contract of insurance. Cover is provided on a parametric basis and the decision as to whether or not an incident is validated is determined by Neptune Mutual’s incident reporting and resolution process whereby the result is based on the number of NPM tokens or vouchers staked by the community in the resolution process; this incident reporting and validation process is community driven, but in exceptional circumstances can be overridden by the Neptune Mutual Association in order to protect against certain types of on-chain consensus attacks.', | ||
list: { | ||
type: 'unordered', | ||
items: [ | ||
'This policy relates exclusively to the version 3 of the Bancor protocol deployed on the Ethereum blockchain.', | ||
'To be eligible for a claim, policyholder must hold at least 299 NPM tokens in the wallet used for the policy transaction for the full duration of the cover policy.' | ||
] | ||
} | ||
}, | ||
{ | ||
parameter: 'Cover Parameters', | ||
type: 'parameter', | ||
text: 'All of the following parameters must be applicable for the policy to be validated:', | ||
list: { | ||
type: 'ordered', | ||
items: [ | ||
'Minimum total loss of user funds from the reported incident should exceed $5 million.', | ||
'The designated protocol suffers a hack of user funds in which the user funds are permanently and irrecoverably stolen from the protocol.', | ||
'The loss arises from a smart contract vulnerability.', | ||
'The loss must arise from one of the following blockchains: Ethereum.' | ||
] | ||
} | ||
}, | ||
{ | ||
parameter: 'Cover Exclusions', | ||
type: 'exclusion', | ||
list: { | ||
type: 'ordered', | ||
items: [ | ||
'Incident on any blockchain that is not supported by this cover.', | ||
'Frontend, hosting, server or network infrastructure, database, DNS server, CI/CD, and/or supply-chain attacks.', | ||
'All exclusions present in the standard terms and conditions.' | ||
] | ||
} | ||
} | ||
], | ||
links: { | ||
website: 'https://www.bancor.network', | ||
app: 'https://app.bancor.network/swap', | ||
github: 'https://github.com/bancorprotocol', | ||
docs: 'https://docs.bancor.network/', | ||
support: 'https://support.bancor.network/hc/en-us/', | ||
blog: 'https://blog.bancor.network/', | ||
discord: 'https://discord.com/invite/5d3JXqYQGj', | ||
telegram: 'https://t.me/bancor', | ||
twitter: 'https://twitter.com/Bancor' | ||
}, | ||
resolutionSources: [ | ||
{ | ||
text: 'Bancor Blog', | ||
uri: 'https://blog.bancor.network/' | ||
}, | ||
{ | ||
text: 'Bancor Twitter', | ||
uri: 'https://twitter.com/Bancor' | ||
}, | ||
{ | ||
text: 'Neptune Mutual Twitter', | ||
uri: 'https://twitter.com/neptunemutual' | ||
} | ||
] | ||
} |
Oops, something went wrong.