Skip to content

Commit 3ca8ad4

Browse files
authored
Merge pull request #50 from ampleforth/prod-deployment
Prod Deployment
2 parents 9e06338 + b45a600 commit 3ca8ad4

19 files changed

+1059
-115
lines changed

contracts/_utilities/ChainBridgeBatchRebaseReport.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ interface IBridge {
77
bytes32 resourceID,
88
bytes calldata data
99
) external payable;
10+
11+
function getFee(uint8 destinationChainID) external view returns (uint256);
1012
}
1113

1214
interface IPolicy {
@@ -22,8 +24,7 @@ contract ChainBridgeBatchRebaseReport {
2224
address policy,
2325
address bridge,
2426
uint8[] memory destinationChainIDs,
25-
bytes32 resourceID,
26-
uint128 bridgeFee
27+
bytes32 resourceID
2728
) external payable {
2829
for (uint256 i = 0; i < destinationChainIDs.length; i++) {
2930
uint8 destinationChainID = destinationChainIDs[i];
@@ -33,7 +34,8 @@ contract ChainBridgeBatchRebaseReport {
3334
(epoch, totalSupply) = IPolicy(policy).globalAmpleforthEpochAndAMPLSupply();
3435

3536
uint256 dataLen = 64;
36-
IBridge(bridge).deposit{value:bridgeFee}(
37+
uint256 bridgeFee = IBridge(bridge).getFee(destinationChainID);
38+
IBridge(bridge).deposit{value: bridgeFee}(
3739
destinationChainID,
3840
resourceID,
3941
abi.encode(dataLen, epoch, totalSupply)

hardhat.config.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require('./tasks/ops/xc_transfer');
1616
require('./tasks/info/config');
1717
require('./tasks/info/ampl');
1818
require('./tasks/info/chain_bridge');
19+
require('./tasks/info/cb_ampl_tx');
1920

2021
module.exports = {
2122
solidity: {
@@ -65,35 +66,31 @@ module.exports = {
6566
},
6667

6768
networks: {
68-
gethBaseChain: {
69+
localGethBaseChain: {
6970
url: 'http://localhost:7545'
7071
},
71-
gethSatChain1: {
72+
localGethSatChain1: {
7273
url: 'http://localhost:7550'
7374
},
74-
gethSatChain2: {
75+
localGethSatChain2: {
7576
url: 'http://localhost:7555'
7677
},
7778

78-
ropstenBaseChain: {
79+
devRopstenBaseChain: {
7980
url: 'https://eth-ropsten.alchemyapi.io/v2/' + process.env.ALCHEMY_SECRET
8081
},
81-
bscTestnetSatChain: {
82+
devBscTestnetSatChain: {
8283
url: 'https://data-seed-prebsc-1-s1.binance.org:8545'
8384
},
84-
meterTestnetSatChain: {
85+
devMeterTestnetSatChain: {
8586
url: 'http://s11.meter.io:8545'
8687
},
8788

88-
// rinkebyBaseChain: {
89-
// url: 'https://rinkeby.infura.io/v3/' + process.env.INFURA_SECRET
90-
// },
91-
// goerliSatChain: {
92-
// url: 'https://goerli.infura.io/v3/' + process.env.INFURA_SECRET
93-
// },
94-
95-
// avaTestnetSatChain: {
96-
// url: 'https://api.avax-test.network/ext/bc/C/rpc'
97-
// }
89+
prodEthereumBaseChain: {
90+
url: 'https://eth-mainnet.alchemyapi.io/v2/' + process.env.ALCHEMY_SECRET
91+
},
92+
prodBscSatChain: {
93+
url: 'https://bsc-dataseed.binance.org/'
94+
}
9895
}
9996
};

helpers/contracts.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const { getAdminAddress } = require('@openzeppelin/upgrades-core');
44
const DEPLOYMENT_CONFIG_PATH = __dirname + '/../sdk/deployments';
55
const { getEthersProvider } = require('./utils');
66

7+
const BLOCKS_PER_SEC = 1 / 15;
8+
79
const ContractABIPaths = {
810
// Openzepppelin
911
ProxyAdmin: '@openzeppelin/upgrades/contracts/upgradeability',
@@ -157,6 +159,43 @@ const writeProxyDeploymentData = async (network, contractRef, contract) => {
157159
fs.writeFileSync(addressFile, JSON.stringify(chainAddresses, null, 2));
158160
};
159161

162+
const filterContractEvents = async (
163+
ethers,
164+
provider,
165+
address,
166+
abi,
167+
event,
168+
startBlock,
169+
endBlock,
170+
timeFrameSec = 7 * 24 * 3600,
171+
) => {
172+
endBlock = endBlock || (await provider.getBlockNumber());
173+
const freq = timeFrameSec * BLOCKS_PER_SEC;
174+
175+
let logs = [];
176+
for (let i = startBlock; i <= endBlock; i += freq) {
177+
// console.log(i, startBlock, endBlock)
178+
const _logs = await provider.getLogs({
179+
address: address,
180+
fromBlock: ethers.utils.hexlify(i),
181+
toBlock: ethers.utils.hexlify(i + freq > endBlock ? endBlock : i + freq),
182+
});
183+
logs = logs.concat(_logs);
184+
}
185+
186+
const contractInterface = new ethers.utils.Interface(abi);
187+
const decodedEvents = logs.reduce((m, log) => {
188+
try {
189+
log.parsed = contractInterface.parseLog(log);
190+
log.parsed.name == event ? m.push(log) : m;
191+
return m;
192+
} catch (e) {
193+
return m;
194+
}
195+
}, []);
196+
return decodedEvents;
197+
};
198+
160199
module.exports = {
161200
readDeploymentData,
162201
readContractDeploymentData,
@@ -169,4 +208,6 @@ module.exports = {
169208
deployContract,
170209
deployProxyAdminContract,
171210
deployProxyContract,
211+
212+
filterContractEvents,
172213
};

helpers/deploy.js

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,10 @@ async function deployChainBridgeContracts(
211211
};
212212
}
213213

214-
async function deployChainBridgeBaseChainGatewayContracts(
215-
{ ampl, policy, bridge, genericHandler },
214+
async function deployTokenVault(
216215
ethers,
217216
deployer,
218-
txParams = {},
219-
) {
217+
txParams = {}) {
220218
const tokenVault = await deployContract(
221219
ethers,
222220
'TokenVault',
@@ -225,6 +223,15 @@ async function deployChainBridgeBaseChainGatewayContracts(
225223
txParams,
226224
);
227225

226+
return tokenVault;
227+
}
228+
229+
async function deployChainBridgeBaseChainGatewayContracts(
230+
{ ampl, policy, bridge, genericHandler, tokenVault },
231+
ethers,
232+
deployer,
233+
txParams = {},
234+
) {
228235
const rebaseGateway = await deployContract(
229236
ethers,
230237
'AMPLChainBridgeGateway',
@@ -240,11 +247,15 @@ async function deployChainBridgeBaseChainGatewayContracts(
240247
txParams,
241248
);
242249

250+
const deployerAddress = await deployer.getAddress();
251+
const adminRole = await bridge.DEFAULT_ADMIN_ROLE();
252+
const isAdmin = await bridge.hasRole(adminRole, deployerAddress);
253+
243254
const reportRebaseFnSig = CB_FUNCTION_SIG_baseChainReportRebase(
244255
rebaseGateway,
245256
);
246257

247-
try {
258+
if(isAdmin){
248259
await (
249260
await bridge
250261
.connect(deployer)
@@ -256,7 +267,7 @@ async function deployChainBridgeBaseChainGatewayContracts(
256267
txParams,
257268
)
258269
).wait();
259-
} catch (e) {
270+
} else {
260271
console.log(
261272
'Failed adding generic resource to bridge, deployer key not bridge owner',
262273
);
@@ -270,7 +281,7 @@ async function deployChainBridgeBaseChainGatewayContracts(
270281
}
271282

272283
const transferFnSig = CB_FUNCTION_SIG_baseChainTransfer(transferGateway);
273-
try {
284+
if(isAdmin) {
274285
await (
275286
await bridge
276287
.connect(deployer)
@@ -282,7 +293,7 @@ async function deployChainBridgeBaseChainGatewayContracts(
282293
txParams,
283294
)
284295
).wait();
285-
} catch (e) {
296+
} else {
286297
console.log(
287298
'Failed adding generic resource to bridge, deployer key not bridge owner',
288299
);
@@ -295,9 +306,23 @@ async function deployChainBridgeBaseChainGatewayContracts(
295306
]);
296307
}
297308

298-
await (await tokenVault.addBridgeGateway(transferGateway.address)).wait();
309+
if(await tokenVault.owner() == deployerAddress){
310+
await (
311+
await tokenVault
312+
.connect(deployer)
313+
.addBridgeGateway(transferGateway.address)
314+
).wait();
315+
} else {
316+
console.log(
317+
'Failed to add whitelist transfer gateway to vault as deployer not vault owner',
318+
);
319+
console.log('Execute the following on-chain');
320+
console.log('addBridgeGateway', [
321+
transferGateway.address,
322+
]);
323+
}
299324

300-
return { tokenVault, rebaseGateway, transferGateway };
325+
return { rebaseGateway, transferGateway };
301326
}
302327

303328
async function deployChainBridgeSatelliteChainGatewayContracts(
@@ -333,10 +358,13 @@ async function deployChainBridgeSatelliteChainGatewayContracts(
333358
.addBridgeGateway(transferGateway.address, txParams)
334359
).wait();
335360

361+
const adminRole = await bridge.DEFAULT_ADMIN_ROLE();
362+
const isAdmin = await bridge.hasRole(adminRole, await deployer.getAddress());
363+
336364
const reportRebaseFnSig = CB_FUNCTION_SIG_satelliteChainReportRebase(
337365
rebaseGateway,
338366
);
339-
try {
367+
if(isAdmin) {
340368
await (
341369
await bridge.adminSetGenericResource(
342370
genericHandler.address,
@@ -346,7 +374,7 @@ async function deployChainBridgeSatelliteChainGatewayContracts(
346374
txParams,
347375
)
348376
).wait();
349-
} catch (e) {
377+
} else {
350378
console.log(
351379
'Failed adding generic resource to bridge, deployer key not bridge owner',
352380
);
@@ -360,7 +388,7 @@ async function deployChainBridgeSatelliteChainGatewayContracts(
360388
}
361389

362390
const transferFnSig = CB_FUNCTION_SIG_satelliteChainTransfer(transferGateway);
363-
try {
391+
if(isAdmin) {
364392
await (
365393
await bridge.adminSetGenericResource(
366394
genericHandler.address,
@@ -370,7 +398,7 @@ async function deployChainBridgeSatelliteChainGatewayContracts(
370398
txParams,
371399
)
372400
).wait();
373-
} catch (e) {
401+
} else {
374402
console.log(
375403
'Failed adding generic resource to bridge, deployer key not bridge owner',
376404
);
@@ -391,6 +419,7 @@ module.exports = {
391419
deployXCAmpleContracts,
392420
deployChainBridgeContracts,
393421
deployChainBridgeHelpers,
422+
deployTokenVault,
394423
deployChainBridgeBaseChainGatewayContracts,
395424
deployChainBridgeSatelliteChainGatewayContracts,
396425
};

helpers/tasks.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ const { task } = require('hardhat/config');
44

55
function txTask(name, desc) {
66
return task(name, desc)
7-
.addParam(
8-
'gasPrice',
9-
'Gas price for the transaction',
10-
25000000000,
11-
types.int,
12-
)
7+
.addParam('gasPrice', 'Gas price for the transaction', 0, types.int)
138
.addParam('gasLimit', 'Gas limit for the transaction', 7000000, types.int)
149
.addParam('txSleepSec', 'Time to wait between transactions', 2, types.int)
1510
.addParam('keyfile', 'The path to signer keyfile')

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"@openzeppelin/contracts": "^3.2.0",
2222
"@openzeppelin/contracts-upgradeable": "^3.3.0",
2323
"@openzeppelin/upgrades": "^2.8.0",
24-
"chainbridge-solidity": "https://github.com/ChainSafe/chainbridge-solidity#a15727ad30bb359b4dfd0fb155f338d11ea80753",
24+
"chainbridge-solidity": "https://github.com/meterio/chainbridge-solidity-v1.0.0-eth#6b02b0a52ce7e3967feeffbe6a6440a5b1006aec",
2525
"market-oracle": "https://github.com/ampleforth/market-oracle#v1.0.1",
2626
"uFragments": "https://github.com/ampleforth/uFragments#v1.1.0"
2727
},
@@ -38,6 +38,7 @@
3838
"bignumber.js": "^9.0.1",
3939
"chai": "^4.2.0",
4040
"commander": "^6.2.1",
41+
"csv-writer": "^1.6.0",
4142
"eslint": "^4.19.1",
4243
"eslint-config-google": "^0.9.1",
4344
"eslint-config-mocha": "^0.0.0",
@@ -66,6 +67,7 @@
6667
"stochasm": "^0.5.0",
6768
"ts-node": "^9.0.0",
6869
"typechain": "^4.0.3",
69-
"typescript": "^4.0.2"
70+
"typescript": "^4.0.2",
71+
"underscore": "^1.13.1"
7072
}
7173
}

sdk/ampleforth.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ const BigNumber = require('bignumber.js');
44
const AMPL_DECIMALS = 9;
55

66
const toAmplFloatingPt = (ample) =>
7-
ethers.utils.formatUnits(`${ample.toFixed ? ample.toFixed(AMPL_DECIMALS) : ample}`, AMPL_DECIMALS);
7+
ethers.utils.formatUnits(
8+
`${ample.toFixed ? ample.toFixed(AMPL_DECIMALS) : ample}`,
9+
AMPL_DECIMALS,
10+
);
811

912
const toAmplFixedPt = (ample) =>
10-
ethers.utils.parseUnits(`${ample.toFixed ? ample.toFixed(AMPL_DECIMALS) : ample}`, AMPL_DECIMALS);
13+
ethers.utils.parseUnits(
14+
`${ample.toFixed ? ample.toFixed(AMPL_DECIMALS) : ample}`,
15+
AMPL_DECIMALS,
16+
);
1117

1218
const INITIAL_SUPPLY = ethers.utils.parseUnits('50', 6 + AMPL_DECIMALS);
1319
const AMPL_ORACLE_DECIMALS = 18;

0 commit comments

Comments
 (0)