Skip to content

Commit

Permalink
arb deployment script
Browse files Browse the repository at this point in the history
  • Loading branch information
aalavandhan committed Oct 25, 2021
1 parent d514a14 commit cdeea53
Showing 1 changed file with 216 additions and 0 deletions.
216 changes: 216 additions & 0 deletions tasks/deploy/arbitrum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
const {
txTask,
loadSignerSync,
etherscanVerify,
} = require('../../helpers/tasks');
const { getEthersProvider } = require('../../helpers/utils');
const {
getDeployedContractInstance,
readDeploymentData,
writeDeploymentData,
writeBulkDeploymentData,
getCompiledContractFactory,
} = require('../../helpers/contracts');

const {
deployArbitrumBaseChainGatewayContracts,
deployArbitrumSatelliteChainGatewayContracts,
} = require('../../helpers/deploy');

txTask(
'deploy:arbitrum_base_chain',
'Deploys the chain gateway on the base chain',
).setAction(async (args, hre) => {
const txParams = { gasPrice: args.gasPrice, gasLimit: args.gasLimit };
if (txParams.gasPrice == 0) {
txParams.gasPrice = await hre.ethers.provider.getGasPrice();
}
const deployer = loadSignerSync(args, hre.ethers.provider);
const deployerAddress = await deployer.getAddress();
const chainAddresses = await readDeploymentData(hre.network.name);

console.log('------------------------------------------------------------');
console.log('Deploying contracts on base-chain');
console.log('Deployer:', deployerAddress);
console.log(txParams);

const ampl = await getDeployedContractInstance(
hre.network.name,
'ampl',
hre.ethers.provider,
);

const policy = await getDeployedContractInstance(
hre.network.name,
'policy',
hre.ethers.provider,
);

const tokenVault = await getDeployedContractInstance(
hre.network.name,
'arbitrum/tokenVault',
hre.ethers.provider,
);

const { gateway } = await deployArbitrumBaseChainGatewayContracts(
{
ampl,
policy,
tokenVault,
},
hre.ethers,
deployer,
txParams,
5,
);

console.log('------------------------------------------------------------');
console.log('Writing data to file');
await writeDeploymentData(
hre.network.name,
'arbitrum/transferGateway',
gateway,
);
await writeDeploymentData(
hre.network.name,
'arbitrum/rebaseGateway',
gateway,
);

console.log('------------------------------------------------------------');
console.log('Verify on etherscan');
await etherscanVerify(hre, gateway.address, [
ampl.address,
policy.address,
tokenVault.address,
]);
});

txTask(
'deploy:arbitrum_satellite_chain',
'Deploys the chain gateway contract and connects it with arbitrum bridge and the cross-chain ample token',
).setAction(async (args, hre) => {
// NOTE: gas estimation is off on arbitrum
// const txParams = { gasPrice: args.gasPrice, gasLimit: args.gasLimit };
// if (txParams.gasPrice == 0) {
// txParams.gasPrice = await hre.ethers.provider.getGasPrice();
// }
const txParams = {};
const deployer = loadSignerSync(args, hre.ethers.provider);
const deployerAddress = await deployer.getAddress();
const chainAddresses = await readDeploymentData(hre.network.name);

console.log('------------------------------------------------------------');
console.log('Deploying contracts on satellite-chain');
console.log('Deployer:', deployerAddress);
console.log(txParams);

const xcAmple = await getDeployedContractInstance(
hre.network.name,
'xcAmple',
hre.ethers.provider,
);

const xcAmpleController = await getDeployedContractInstance(
hre.network.name,
'xcAmpleController',
hre.ethers.provider,
);

const { gateway } = await deployArbitrumSatelliteChainGatewayContracts(
{ xcAmple, xcAmpleController },
hre.ethers,
deployer,
txParams,
5,
);

console.log('------------------------------------------------------------');
console.log('Writing data to file');
await writeDeploymentData(
hre.network.name,
'arbitrum/transferGateway',
gateway,
);
await writeDeploymentData(
hre.network.name,
'arbitrum/rebaseGateway',
gateway,
);

console.log('------------------------------------------------------------');
console.log('Verify on etherscan');
await etherscanVerify(hre, gateway.address, [
xcAmple.address,
xcAmpleController.address,
]);
});

txTask('deploy:arbitrum_connection', 'Connects the two gateway contracts')
.addParam('baseChainNetwork', 'The network name of the base chain network')
.addParam(
'satChainNetwork',
'The network name of the satellite chain network',
)
.addParam('baseInbox', 'The address of the arbitrum inbox on the base chain')
.addParam(
'baseRouter',
'The address of the arbitrum router contract on the base chain',
)
.addParam(
'satRouter',
'The address of the arbitrum router contract on the satellite chain',
)
.setAction(async (args, hre) => {
const txParams = { gasPrice: args.gasPrice, gasLimit: args.gasLimit };
if (txParams.gasPrice == 0) {
txParams.gasPrice = await hre.ethers.provider.getGasPrice();
}

const baseChainProvider = getEthersProvider(args.baseChainNetwork);
const satChainProvider = getEthersProvider(args.satChainNetwork);

const baseChainSigner = loadSignerSync(args, baseChainProvider);
const satChainSigner = loadSignerSync(args, satChainProvider);

const baseGateway = await getDeployedContractInstance(
args.baseChainNetwork,
'arbitrum/rebaseGateway',
baseChainProvider,
);
const ampl = await getDeployedContractInstance(
args.baseChainNetwork,
'ampl',
baseChainProvider,
);

const satGateway = await getDeployedContractInstance(
args.satChainNetwork,
'arbitrum/rebaseGateway',
satChainProvider,
);
const xcAmple = await getDeployedContractInstance(
args.satChainNetwork,
'xcAmple',
satChainProvider,
);

await (
await baseGateway
.connect(baseChainSigner)
.initialize(
args.baseInbox,
args.baseRouter,
xcAmple.address,
satGateway.address,
txParams,
)
).wait(2);

// NOTE: gas estimation is off on arbitrum
await (
await satGateway
.connect(satChainSigner)
.initialize(args.satRouter, ampl.address, baseGateway.address, {})
).wait(2);
});

0 comments on commit cdeea53

Please sign in to comment.