Skip to content

Commit

Permalink
Deploying Popular DeFi Apps
Browse files Browse the repository at this point in the history
For cover creation, added a deployment script for Popular DeFi Apps
  • Loading branch information
heyaibi committed Jan 17, 2023
1 parent 8c91a84 commit 321f1a5
Show file tree
Hide file tree
Showing 17 changed files with 914 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"cSpell.words": [
"Aave",
"alloc",
"Arbitrum",
"Bahs",
"Bokky",
"BSCSCAN",
Expand All @@ -54,6 +55,9 @@
"cpool",
"crpool",
"CXTOKEN",
"dApp",
"defi",
"dydx",
"finalizer",
"Fractionalization",
"genabi",
Expand Down
8 changes: 4 additions & 4 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const config = {
defaultNetwork: 'hardhat',
networks: {
hardhat: {
blockGasLimit: 20000000, // 20M
blockGasLimit: 9000000, // 9M
forking: {
url: process.env.ETHEREUM_RPC_URL,
blockNumber: 16238599
blockNumber: 16425236
},
gasPrice: 12 * GWEI,
gasPrice: 20 * GWEI,
explorer: 'https://etherscan.io'
},
local: {
Expand Down Expand Up @@ -47,7 +47,7 @@ const config = {
url: process.env.ETHEREUM_RPC_URL,
chainId: 1,
accounts: [process.env.PRIVATE_KEY],
gasPrice: 12 * GWEI,
gasPrice: 70 * GWEI,
explorer: 'https://etherscan.io'
}
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"deploy:ethereum": "hardhat run scripts/deploy.js --network ethereum 2>&1 | tee ./.ignored/ethereum-deployment.md",
"deploy:local": "rm -f ./.deployments/local.json && hardhat run scripts/deploy.js --network local 2>&1 | tee ./.ignored/local-deployment.md",
"deploy:fuji": "hardhat run scripts/deploy.js --network fuji 2>&1 | tee ./.ignored/fuji-deployment.md",
"deploy:mumbai": "hardhat run scripts/deploy.js --network mumbai 2>&1 | tee ./.ignored/mumbai-deployment.md",
"deploy:cover": "npx hardhat run scripts/deploy-covers.js",
"deploy:cover:ethereum": "npx hardhat run scripts/deploy-covers.js --network ethereum",
"verify": "node ./scripts/verify.js",
"solhint": "solhint \"contracts/**/*.sol\"",
"genabi": "rm -rf ./abis && mkdir abis && node ./util/extract/abis",
Expand Down
126 changes: 126 additions & 0 deletions scripts/covers/deployments/popular-defi-apps.js
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 }
34 changes: 34 additions & 0 deletions scripts/covers/diversified/popular-defi-apps/cover.js
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)
}
4 changes: 4 additions & 0 deletions scripts/covers/diversified/popular-defi-apps/index.js
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 scripts/covers/diversified/popular-defi-apps/products/aave.js
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 scripts/covers/diversified/popular-defi-apps/products/bancor.js
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'
}
]
}
Loading

0 comments on commit 321f1a5

Please sign in to comment.