Skip to content

Commit

Permalink
Improve deploy command (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhiqiang Zhang authored Mar 11, 2022
1 parent 584f376 commit 3b24d68
Show file tree
Hide file tree
Showing 21 changed files with 422 additions and 3,605 deletions.
3,239 changes: 0 additions & 3,239 deletions .openzeppelin/unknown-31337.json

This file was deleted.

12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ yarn hardhat deployAcessManager --network <ropsten> --wallet <walletAddress>
* Deploy ClientManager

```shell
yarn hardhat deployClientManager --network <ropsten> --chain <native-chain-name> --accm <acessManagerAddress>
yarn hardhat deployClientManager --network <ropsten> --chain <native-chain-name>
```

* Deploy Tendermint Client
Expand All @@ -58,7 +58,7 @@ yarn hardhat deployTendermint --network <ropsten>
* Deploy Routing

```shell
yarn hardhat deployRouting --network <ropsten> --accm <acessManagerAddress>
yarn hardhat deployRouting --network <ropsten>
```

* Deploy Packet
Expand All @@ -79,6 +79,12 @@ yarn hardhat deployERC1155Bank --network <ropsten>
yarn hardhat deployNFTTransfer --network <ropsten>
```

* Deploy MT Transfer

```shell
yarn hardhat deployMtTransfer --network <ropsten>
```

### Transfer proxy contract ownership

For the safe upgrade of the contract, it is necessary to cooperate with the operation of the multi-signature wallet to transfer the ownership of the contract to the multi-signature wallet. Note that after the project is deployed, the proxy contract address of all contracts and the compilation information of the contract are recorded in the .openzeppelin directory. This information is needed when the contract upgrade is executed next time. Modify the following [script](#./script/transfer-ownership.js) to complete the ownership transfer. In the `scripts/transfer-ownership.js` file, you need to replace the `gnosisSafe` variable, which is the address of the multi-signature wallet. After the modification is complete, execute the following command:
Expand Down Expand Up @@ -118,7 +124,7 @@ Grant mint and burn permissions to the `<transfer-contract-address>` EOA
### Create light client

```shell
DEBUG=* yarn hardhat createClient --chain irishub-testnet --client <tendermint client contract address> --clientstate <encode-clientstate> --consensusstate <encode-consensusstate> --network <ropsten>
DEBUG=* yarn hardhat createClient --chain irishub-testnet --clientstate <encode-clientstate> --consensusstate <encode-consensusstate> --network <ropsten>
```

## Upgrade contract
Expand Down
43 changes: 22 additions & 21 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import "@typechain/hardhat"
import "hardhat-gas-reporter"
import "hardhat-contract-sizer"
import "hardhat-abi-exporter"
import "./tasks/deployLibraries"
import "./tasks/deployTendermintClient"
import "./tasks/deployClientManager"
import "./tasks/deployPacket"
import "./tasks/deployRouting"
import "./tasks/deployERC1155Bank"
import "./tasks/deployNFTTransfer"
import "./tasks/deployAccessManager"
import "./tasks/deployUptickGateway"
import "./tasks/tendermintLibraries"
import "./tasks/tendermintClient"
import "./tasks/clientManager"
import "./tasks/packet"
import "./tasks/routing"
import "./tasks/erc1155Bank"
import "./tasks/nftTransfer"
import "./tasks/mtTransfer"
import "./tasks/accessManager"
import "./tasks/uptickGateway"

module.exports = {
defaultNetwork: 'hardhat',
Expand All @@ -33,18 +34,18 @@ module.exports = {
// gas: 4100000,
// accounts: [''],
// },
bsctestnet: {
url: 'https://data-seed-prebsc-1-s1.binance.org:8545',
gasPrice: 20000000000,
chainId: 97,
//accounts: [''],
},
bsc: {
url: 'https://bsc-dataseed.binance.org',
gasPrice: 20000000000,
chainId: 56,
//accounts: [''],
},
// bsctestnet: {
// url: 'https://data-seed-prebsc-1-s1.binance.org:8545',
// gasPrice: 20000000000,
// chainId: 97,
// accounts: [''],
// },
// bsc: {
// url: 'https://bsc-dataseed.binance.org',
// gasPrice: 20000000000,
// chainId: 56,
// //accounts: [''],
// },
},
solidity: {
version: '0.6.8',
Expand Down
17 changes: 17 additions & 0 deletions tasks/accessManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import "@nomiclabs/hardhat-web3";
import { task } from "hardhat/config"
const config = require('./config')

task("deployAcessManager", "Deploy acessManager")
.setAction(async (taskArgs, hre) => {
await config.load(async function (env: any) {
const accessManagerFactory = await hre.ethers.getContractFactory('AccessManager')
const accessManager = await hre.upgrades.deployProxy(accessManagerFactory,
[env.multiSignWalletAddress]);
await accessManager.deployed();
console.log("AccessManager deployed to:", accessManager.address);
env.contract.accessManagerAddress = accessManager.address
},true)
});

module.exports = {};
143 changes: 143 additions & 0 deletions tasks/clientManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import "@nomiclabs/hardhat-web3";
import { task, types } from "hardhat/config"
const config = require('./config')

let client = require("../test/proto/compiled.js");

task("deployClientManager", "Deploy Client Manager")
.setAction(async (taskArgs, hre) => {
await config.load(async function (env: any) {
const clientManagerFactory = await hre.ethers.getContractFactory('ClientManager')
const clientManager = await hre.upgrades.deployProxy(clientManagerFactory, [
env.network.nativeChainName,
env.contract.accessManagerAddress
]);
await clientManager.deployed();
console.log("Client Manager deployed to:", clientManager.address);
env.contract.clientManagerAddress = clientManager.address
}, true)
});

task("upgradeClientManager", "Upgrade Client Manager")
.addParam("chain", "Chain Name")
.setAction(async (taskArgs, hre) => {
await config.load(async function (env: any) {
const clientManagerFactory = await hre.ethers.getContractFactory('ClientManager')
const clientManager = await hre.upgrades.upgradeProxy(
env.contract.clientManagerAddress,
clientManagerFactory
);
await clientManager.deployed();
console.log("Client Manager upgraded to:", clientManager.address);
env.contract.clientManagerAddress = clientManager.address
})
});
task("createClient", "Deploy Client Manager")
.setAction(async (taskArgs, hre) => {
await config.load(async function (env: any) {
const clientManagerFactory = await hre.ethers.getContractFactory('ClientManager')
const clientManager = await clientManagerFactory.attach(env.contract.clientManagerAddress);
const clientStatebytes = Buffer.from(env.network.clientstate, "hex")
const clientStateObj = JSON.parse(clientStatebytes.toString())
const clientStateEncode = {
chainId: clientStateObj.chainId,
trustLevel: {
numerator: clientStateObj.trustLevel.numerator,
denominator: clientStateObj.trustLevel.denominator
},

trustingPeriod: clientStateObj.trustingPeriod,
unbondingPeriod: clientStateObj.unbondingPeriod,
maxClockDrift: clientStateObj.maxClockDrift,
latestHeight: {
revisionNumber: clientStateObj.latestHeight.revisionNumber,
revisionHeight: clientStateObj.latestHeight.revisionHeight
},
merklePrefix: {
keyPrefix: Buffer.from("tibc"),
},
timeDelay: 0,
}


const clientState = client.ClientState.encode(clientStateEncode).finish();
const consensusStateBytes = Buffer.from(env.network.consensusstate, "hex")
const consensusStateObj = JSON.parse(consensusStateBytes.toString())
const consensusStateEncode = {
timestamp: {
secs: consensusStateObj.timestamp.secs,
nanos: consensusStateObj.timestamp.nanos,
},
root: Buffer.from(consensusStateObj.root, "hex"),
nextValidatorsHash: Buffer.from(consensusStateObj.nextValidatorsHash, "hex")
}
const consensusState = client.ConsensusState.encode(consensusStateEncode).finish();
const result = await clientManager.createClient(
env.network.counterpartyChainName,
env.contract.tmLightClientAddress,
clientState,
consensusState);
console.log(result);
}, true)
});

task("registerRelayer", "Deploy Client Manager")
.setAction(async (taskArgs, hre) => {
await config.load(async function (env: any) {
const clientManagerFactory = await hre.ethers.getContractFactory('ClientManager')
const clientManager = await clientManagerFactory.attach(env.contract.clientManagerAddress);
const result = await clientManager.registerRelayer(
env.network.counterpartyChainName,
env.network.relayerAddress
);
console.log(result);
})
});

task("updateClient", "Deploy Client Manager")
.addParam("header", "HEX encoding header")
.setAction(async (taskArgs, hre) => {
await config.load(async function (env: any) {
const clientManagerFactory = await hre.ethers.getContractFactory('ClientManager')
const clientManager = await clientManagerFactory.attach(env.contract.clientManagerAddress);
const result = await clientManager.updateClient(env.network.counterpartyChainName, Buffer.from(taskArgs.header, "hex"))
console.log(await result.wait());
})
});

task("getClient", "Deploy Client Manager")
.setAction(async (taskArgs, hre) => {
await config.load(async function (env: any) {
const clientManagerFactory = await hre.ethers.getContractFactory('ClientManager')
const clientManager = await clientManagerFactory.attach(env.contract.clientManagerAddress);
const result = await clientManager.clients(
env.network.counterpartyChainName,
)
console.log(await result);
})
});

task("getRelayers", "Deploy Client Manager")
.setAction(async (taskArgs, hre) => {
await config.load(async function (env: any) {
const clientManagerFactory = await hre.ethers.getContractFactory('ClientManager')
const clientManager = await clientManagerFactory.attach(env.contract.clientManagerAddress);
const result = await clientManager.relayers(
env.network.counterpartyChainName,
env.network.relayerAddress
)
console.log(result);
})
});

task("lastheight", "Deploy Client Manager")
.setAction(async (taskArgs, hre) => {
await config.load(async function (env: any) {
const clientManagerFactory = await hre.ethers.getContractFactory('ClientManager')
const clientManager = await clientManagerFactory.attach(env.contract.clientManagerAddress);
const result = await clientManager.getLatestHeight(env.network.counterpartyChainName)
console.log(result);
})
});

module.exports = {};
27 changes: 27 additions & 0 deletions tasks/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const fs = require('fs')

function writeConfig(content:Object) {
let data = JSON.stringify(content, null,'\t');
fs.writeFileSync('./tibcconfig.json', data)
}

async function load(callback: Function,override:Boolean = false) {
let env = loadSync();
await callback(env);
if(override) {
writeConfig(env);
}
}

function loadSync() {
try {
let rawdata = fs.readFileSync('./tibcconfig.json');
return JSON.parse(rawdata);
}catch(e) {
console.log("no tibcconfig.json file found");
}
}

export = {
load,
};
15 changes: 0 additions & 15 deletions tasks/deployAccessManager.ts

This file was deleted.

Loading

0 comments on commit 3b24d68

Please sign in to comment.