Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
Merge 3c5d773 into 7bd128e
Browse files Browse the repository at this point in the history
  • Loading branch information
steviezhang committed Apr 24, 2020
2 parents 7bd128e + 3c5d773 commit f888e23
Show file tree
Hide file tree
Showing 43 changed files with 409 additions and 1,001 deletions.
45 changes: 45 additions & 0 deletions cli/cmd/bridge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const ethers = require('ethers');
const constants = require('../constants');

const {Command} = require('commander');
const {setupParentArgs} = require("./utils")

const registerResourceCmd = new Command("register-resource")
.description("register a resource ID with a contract address for a handler")
.option('--bridge <address>', 'Custom bridge address', constants.BRIDGE_ADDRESS)
.option('--handler <address>', 'Custom handler', constants.ERC20_HANDLER_ADDRESS)
.option('--targetContract <address>', `Custom addresses to be whitelisted`, constants.ERC20_ADDRESS)
.option('--resourceID <address>', `Custom resourceID to be whitelisted`, constants.ERC20_RESOURCEID)
.action(async function (args) {
await setupParentArgs(args, args.parent.parent)

// Instances
const bridgeInstance = new ethers.Contract(args.bridge, constants.ContractABIs.Bridge.abi, args.wallet);

await bridgeInstance.adminSetResourceIDAndContractAddress(args.handler, args.resourceID, args.targetContract);
console.log(`[BRIDGE] Successfully registered contract ${args.targetContract} with id ${args.resourceID} on handler ${args.handler}`);

})

const setBurnCmd = new Command("set-burn")
.description("set a a token contract as burnable in a handler")
.option('--bridge <address>', 'Custom bridge address', constants.BRIDGE_ADDRESS)
.option('--handler <address>', 'Custom erc20 handler', constants.ERC20_HANDLER_ADDRESS)
.option('--tokenContract <address>', `Custom addresses to be whitelisted`, constants.ERC20_ADDRESS)
.action(async function (args) {
await setupParentArgs(args, args.parent.parent)

// Instances
const bridgeInstance = new ethers.Contract(args.bridge, constants.ContractABIs.Bridge.abi, args.wallet);

await bridgeInstance.adminSetBurnable(args.handler, args.tokenContract);
console.log(`[BRIDGE] Successfully set contract ${args.tokenContract} as burnable on handler ${args.handler}`);

})

const bridgeCmd = new Command("bridge")

bridgeCmd.addCommand(registerResourceCmd)
bridgeCmd.addCommand(setBurnCmd)

module.exports = bridgeCmd
18 changes: 1 addition & 17 deletions cli/cmd/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const deployCmd = new Command("deploy")
await setupParentArgs(args, args.parent)
let startBal = await args.provider.getBalance(args.wallet.address)
console.log("Deploying contracts...")
await deployRelayerContract(args);
await deployBridgeContract(args);
await deployERC20(args)
await deployERC20Handler(args);
Expand All @@ -38,8 +37,6 @@ Contract Addresses
================================================================
Bridge: ${args.bridgeContract}
----------------------------------------------------------------
Relayer: ${args.relayerContract}
----------------------------------------------------------------
Erc20: ${args.erc20Contract}
----------------------------------------------------------------
Erc20 Handler: ${args.erc20HandlerContract}
Expand All @@ -53,19 +50,6 @@ Centrifuge Handler: ${args.centrifugeHandlerContract}
`)
}

async function deployRelayerContract(cfg) {
// Create an instance of a Contract Factory
let factory = new ethers.ContractFactory(constants.ContractABIs.Relayer.abi, constants.ContractABIs.Relayer.bytecode, cfg.wallet);

// Deploy
let contract = await factory.deploy(
cfg.relayers,
cfg.relayerThreshold
);
await contract.deployed();
cfg.relayerContract = contract.address
console.log("✓ Relayer contract deployed")
}

async function deployBridgeContract(args) {
// Create an instance of a Contract Factory
Expand All @@ -74,7 +58,7 @@ async function deployBridgeContract(args) {
// Deploy
let contract = await factory.deploy(
args.chainId,
args.relayerContract,
args.relayers,
args.relayerThreshold
);
await contract.deployed();
Expand Down
43 changes: 0 additions & 43 deletions cli/cmd/erc20.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,6 @@ const mintCmd = new Command("mint")
console.log(`[ERC20 Mint] Successfully minted ${args.value} tokens to ${args.wallet.address}`);
})

const registerResourceCmd = new Command("register-resource")
.description("register a resource ID with a token addresses for an ERC20 handler")
.option('--bridgeAddress <address>', 'Custom bridge address', constants.BRIDGE_ADDRESS)
.option('--tokenContract <address>', `Custom addresses to be whitelisted`, constants.ERC20_ADDRESS)
.option('--resourceID <address>', `Custom resourceID to be whitelisted`, constants.ERC20_RESOURCEID)
.option('--erc20HandlerAddress <address>', 'Custom erc20 handler', constants.ERC20_HANDLER_ADDRESS)
.action(async function (args) {
await setupParentArgs(args, args.parent.parent)

// Instances
const bridgeInstance = new ethers.Contract(args.bridgeAddress, constants.ContractABIs.Bridge.abi, args.wallet);
const erc20HandlerInstance = new ethers.Contract(args.erc20HandlerAddress, constants.ContractABIs.Erc20Handler.abi, args.wallet);

// Whitelisting Addresses
chainID = await bridgeInstance._chainID()

await erc20HandlerInstance.setResourceIDAndContractAddress(args.resourceID, args.tokenContract);
console.log(`[ERC20 Register Resource] Successfully registered contract ${args.tokenContract} with id ${args.resourceID} on handler ${args.erc20HandlerAddress}`);

})

const setBurnCmd = new Command("set-burn")
.description("set a a token contract as burnable in an ERC20 handler")
.option('--bridgeAddress <address>', 'Custom bridge address', constants.BRIDGE_ADDRESS)
.option('--tokenContract <address>', `Custom addresses to be whitelisted`, constants.ERC20_ADDRESS)
.option('--erc20HandlerAddress <address>', 'Custom erc20 handler', constants.ERC20_HANDLER_ADDRESS)
.action(async function (args) {
setupParentArgs(args, args.parent.parent)

// Instances
const bridgeInstance = new ethers.Contract(args.bridgeAddress, constants.ContractABIs.Bridge.abi, args.wallet);
const erc20HandlerInstance = new ethers.Contract(args.erc20HandlerAddress, constants.ContractABIs.Erc20Handler.abi, args.wallet);

// Whitelisting Addresses
chainID = await bridgeInstance._chainID()

await erc20HandlerInstance.setBurnable(args.tokenContract);
console.log(`[ERC20 Set Burn] Successfully set contract ${args.tokenContract} as burnable on handler ${args.erc20HandlerAddress}`);

})

const transferCmd = new Command("transfer")
.description("Initiates a bridge transfer")
.option('--value <amount>', "Amount to transfer", 1)
Expand Down Expand Up @@ -124,8 +83,6 @@ const balanceCmd = new Command("balance")
const erc20Cmd = new Command("erc20")

erc20Cmd.addCommand(mintCmd)
erc20Cmd.addCommand(registerResourceCmd)
erc20Cmd.addCommand(setBurnCmd)
erc20Cmd.addCommand(transferCmd)
erc20Cmd.addCommand(balanceCmd)

Expand Down
43 changes: 0 additions & 43 deletions cli/cmd/erc721.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,6 @@ const mintCmd = new Command("mint")
console.log(`[ERC721 Mint] Minted token with id ${args.id} to ${args.wallet.address}!`);
})

const setResourceCmd = new Command("register-resource")
.description("set a a token contract as burnable in an ERC721 handler")
.option('--bridgeAddress <address>', 'Custom bridge address', constants.BRIDGE_ADDRESS)
.option(`--tokenContract <address>`, `Custom addresses to be whitelisted`, constants.ERC721_ADDRESS)
.option(`--resourceID <address>`, `Custom resourceID to be whitelisted`, constants.ERC721_RESOURCEID)
.option('--erc721HandlerAddress <address>', 'Custom erc721 handler', constants.ERC721_HANDLER_ADDRESS)
.action(async function (args) {
await setupParentArgs(args, args.parent.parent)

// Instances
const bridgeInstance = new ethers.Contract(args.bridgeAddress, constants.ContractABIs.Bridge.abi, args.wallet);
const erc721HandlerInstance = new ethers.Contract(args.erc721HandlerAddress, constants.ContractABIs.Erc721Handler.abi, args.wallet);

// Whitelisting Addresses
chainID = await bridgeInstance._chainID()

await erc721HandlerInstance.setResourceIDAndContractAddress(args.resourceID, args.tokenContract);
console.log(`[ERC721 Whitelist] Successfully whitelisted ${args.tokenContract} on handler ${args.erc721HandlerAddress}`);

})

const setBurnCmd = new Command("set-burn")
.description("set a a token contract as burnable in an ERC721 handler")
.option('--bridgeAddress <address>', 'Custom bridge address', constants.BRIDGE_ADDRESS)
.option('--tokenContract <address>', `Custom addresses to be whitelisted`, constants.ERC721_ADDRESS)
.option('--erc721HandlerAddress <address>', 'Custom erc721 handler', constants.ERC721_HANDLER_ADDRESS)
.action(async function (args) {
await setupParentArgs(args, args.parent.parent)

// Instances
const bridgeInstance = new ethers.Contract(args.bridgeAddress, constants.ContractABIs.Bridge.abi, args.wallet);
const erc721HandlerInstance = new ethers.Contract(args.erc721HandlerAddress, constants.ContractABIs.Erc721Handler.abi, args.wallet);

// Whitelisting Addresses
chainID = await bridgeInstance._chainID()

await erc721HandlerInstance.setBurnable(args.tokenContract);
console.log(`[ERC721 Set Burn] Successfully set contract ${args.tokenContract} as burnable on handler ${args.erc721HandlerAddress}`);

})

const transferCmd = new Command("transfer")
.description("Initiates a bridge transfer")
.option('--id <id>', "ERC721 token id", 1)
Expand Down Expand Up @@ -99,8 +58,6 @@ const transferCmd = new Command("transfer")
const erc721Cmd = new Command("erc721")

erc721Cmd.addCommand(mintCmd)
erc721Cmd.addCommand(setResourceCmd)
erc721Cmd.addCommand(setBurnCmd)
erc721Cmd.addCommand(transferCmd)

module.exports = erc721Cmd
2 changes: 2 additions & 0 deletions cli/cmd/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const deploy = require("./deploy");
const bridge = require("./bridge")
const erc20 = require("./erc20");
const erc721 = require("./erc721");
// const centrifuge = require("./centrifuge");

module.exports = {
deploy,
bridge,
erc20,
erc721,
// centrifuge,
Expand Down
14 changes: 6 additions & 8 deletions cli/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const ethers = require('ethers');

const CONTRACT_PATH = "../"
const ContractABIs = {
Bridge: require(CONTRACT_PATH + "/build/contracts/Bridge.json"),
Relayer: require(CONTRACT_PATH + "/build/contracts/Relayer.json"),
Bridge: require(CONTRACT_PATH + "build/contracts/Bridge.json"),
Erc20Handler: require(CONTRACT_PATH + "/build/contracts/ERC20Handler.json"),
Erc20Mintable: require(CONTRACT_PATH + "/build/contracts/ERC20PresetMinterPauser.json"),
Erc721Handler: require(CONTRACT_PATH + "/build/contracts/ERC721Handler.json"),
Expand Down Expand Up @@ -38,12 +37,11 @@ module.exports.relayerPrivKeys = [


// These are deterministic
module.exports.BRIDGE_ADDRESS = "0x3167776db165D8eA0f51790CA2bbf44Db5105ADF";
module.exports.RELAYER_ADDRESS = "0x62877dDCd49aD22f5eDfc6ac108e9a4b5D2bD88B";
module.exports.ERC20_ADDRESS = "0x3f709398808af36ADBA86ACC617FeB7F5B7B193E";
module.exports.ERC20_HANDLER_ADDRESS = "0x2B6Ab4b880A45a07d83Cf4d664Df4Ab85705Bc07";
module.exports.ERC721_ADDRESS = "0x21605f71845f372A9ed84253d2D024B7B10999f4";
module.exports.ERC721_HANDLER_ADDRESS = "0xd7E33e1bbf65dC001A0Eb1552613106CD7e40C31";
module.exports.BRIDGE_ADDRESS = "0x62877dDCd49aD22f5eDfc6ac108e9a4b5D2bD88B";
module.exports.ERC20_ADDRESS = "0x3167776db165D8eA0f51790CA2bbf44Db5105ADF";
module.exports.ERC20_HANDLER_ADDRESS = "0x3f709398808af36ADBA86ACC617FeB7F5B7B193E";
module.exports.ERC721_ADDRESS = "0x2B6Ab4b880A45a07d83Cf4d664Df4Ab85705Bc07";
module.exports.ERC721_HANDLER_ADDRESS = "0x21605f71845f372A9ed84253d2D024B7B10999f4";
module.exports.CENTRIFUGE_HANDLER = "0xc279648CE5cAa25B9bA753dAb0Dfef44A069BaF4";

module.exports.DEFAULT_SOURCE_ID = 0;
Expand Down
2 changes: 2 additions & 0 deletions cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const program = new Command();
// Comands
const {
deploy,
bridge,
erc20,
erc721,
// centrifuge,
Expand All @@ -19,6 +20,7 @@ program.option('--json-wallet <path>', '(Optional) Encrypted JSON wallet');
program.option('--json-wallet-password <value>', '(Optional) Password for encrypted JSON wallet');

program.addCommand(deploy)
program.addCommand(bridge)
program.addCommand(erc20)
program.addCommand(erc721)
// program.addCommand(centrifuge)
Expand Down

0 comments on commit f888e23

Please sign in to comment.