-
Notifications
You must be signed in to change notification settings - Fork 83
/
deployRevenueRecipient.ts
150 lines (135 loc) · 5.6 KB
/
deployRevenueRecipient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import "ts-node/register"
import "tsconfig-paths/register"
import { task } from "hardhat/config"
import { RevenueRecipient__factory, MockERC20__factory, CRPFactory__factory, ConfigurableRightsPool__factory } from "types/generated"
import { simpleToExactAmount, BN } from "@utils/math"
interface Config {
deployer: string
tokens: string[]
amounts: BN[]
weights: BN[]
swapFee: BN
bFactory: string
factory: string
mAssets: string[]
minOuts: BN[]
dao: string
daoProxy: string
nexus: string
balToken: string
}
task("deployRevenueRecipient", "Deploys an instance of revenue recipient contract").setAction(async (_, hre) => {
const { ethers, network } = hre
const [deployer] = await ethers.getSigners()
if (network.name !== "mainnet") throw Error("Invalid network")
const config: Config = {
deployer: await deployer.getAddress(),
tokens: [
"0xe2f2a5C287993345a840Db3B0845fbC70f5935a5",
"0x945Facb997494CC2570096c74b5F66A3507330a1",
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"0xa3BeD4E1c75D00fa6f4E5E6922DB7261B5E9AcD2",
],
amounts: [
simpleToExactAmount(4993),
simpleToExactAmount("8.50635", 15), // 0.0085,
simpleToExactAmount("6.99", 17), // 0.699,
simpleToExactAmount(1428),
],
weights: [simpleToExactAmount(25), simpleToExactAmount(2), simpleToExactAmount(6), simpleToExactAmount(17)],
swapFee: simpleToExactAmount(5, 16),
bFactory: "0x9424B1412450D0f8Fc2255FAf6046b98213B76Bd",
factory: "0xed52D8E202401645eDAD1c0AA21e872498ce47D0",
mAssets: ["0xe2f2a5C287993345a840Db3B0845fbC70f5935a5", "0x945Facb997494CC2570096c74b5F66A3507330a1"],
minOuts: [simpleToExactAmount(3, 17), simpleToExactAmount(20000, 18)],
dao: "0xF6FF1F7FCEB2cE6d26687EaaB5988b445d0b94a2",
daoProxy: "0x7fFAF4ceD81E7c4E71b3531BD7948d7FA8f20329",
nexus: "0xAFcE80b19A8cE13DEc0739a1aaB7A028d6845Eb3",
balToken: "0xba100000625a3754423978a60c9317c58a424e3D",
}
const poolRights = {
canPauseSwapping: false,
canChangeSwapFee: true,
canChangeWeights: true,
canAddRemoveTokens: true,
canWhitelistLPs: true,
canChangeCap: false,
}
// Check balances
const erc20Factory = await new MockERC20__factory(deployer)
const tokens = config.tokens.map((t) => erc20Factory.attach(t))
const balances = await Promise.all(tokens.map((t) => t.balanceOf(config.deployer)))
console.log("Checking balances...")
balances.map((b, i) => {
if (b.lt(config.amounts[i])) {
throw new Error(`${config.tokens[i]} invalid balance`)
}
return 0
})
// Deploy step 1
const crpFactory = await CRPFactory__factory.connect(config.factory, deployer)
let tx = await crpFactory.newCrp(
config.bFactory,
{
poolTokenSymbol: "mBPT1",
poolTokenName: "mStable BPT 1",
constituentTokens: config.tokens,
tokenBalances: config.amounts,
tokenWeights: config.weights,
swapFee: config.swapFee,
},
poolRights,
)
console.log("Creating CRP... ", tx.hash)
let receipt = await tx.wait()
const chosenLog = receipt.logs.find((log) => log.address === config.factory)
const poolAddress = `0x${chosenLog.topics[2].substring(26)}`
console.log("Pool address: ", poolAddress)
// Deploy step 2 - just calls createPool() to deploy and fund the BPool
console.log(`Approving ${tokens[0].address}...`)
let approveTx = await tokens[0].approve(poolAddress, config.amounts[0])
await approveTx.wait()
console.log(`Approving ${tokens[1].address}...`)
approveTx = await tokens[1].approve(poolAddress, config.amounts[1])
await approveTx.wait()
console.log(`Approving ${tokens[2].address}...`)
approveTx = await tokens[2].approve(poolAddress, config.amounts[2])
await approveTx.wait()
console.log(`Approving ${tokens[3].address}...`)
approveTx = await tokens[3].approve(poolAddress, config.amounts[3])
await approveTx.wait()
const crp = await ConfigurableRightsPool__factory.connect(poolAddress, deployer)
tx = await crp.createPool(simpleToExactAmount(10000))
console.log(`Creating Pool... ${tx.hash}`)
receipt = await tx.wait()
// Transfer mBPT to DAO
const poolToken = await erc20Factory.attach(poolAddress)
const balance = await poolToken.balanceOf(config.deployer)
tx = await poolToken.transfer(config.dao, balance)
console.log(`Transferring tokens to DAO... ${tx.hash}`)
await tx.wait()
// Deploy RevenueRecipient contract
const recipient = await new RevenueRecipient__factory(deployer).deploy(
config.nexus,
poolAddress,
config.balToken,
config.mAssets,
config.minOuts,
)
console.log(`Deploying recipient... ${tx.hash}`)
receipt = await recipient.deployTransaction.wait()
console.log(`Deployed Recipient to ${recipient.address}. gas used ${receipt.gasUsed}`)
// Deploy step 3 - Complete setup
// - Whitelist RevenueRecipient as LP
tx = await crp.whitelistLiquidityProvider(recipient.address)
console.log(`Whitelisting recipient... ${tx.hash}`)
receipt = await tx.wait()
// - Transfer ownership to DSProxy
tx = await crp.setController(config.daoProxy)
console.log(`Transferring ownership... ${tx.hash}`)
receipt = await tx.wait()
// Finalise via governance:
// - Update SavingsRate in SavingsManager
// - Add RevenueRecipient address in SavingsManager
})
module.exports = {}