Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(javascripts): general message passing #103

Merged
merged 15 commits into from
May 30, 2022
53 changes: 53 additions & 0 deletions scripts/crosschain-token-execute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

require('dotenv').config();

const {
Contract,
Wallet,
utils,
providers: { JsonRpcProvider },
} = require('ethers');

const {
printLog,
printObj,
} = require('./logging');

const path = require('node:path');

// these environment variables should be defined in an '.env' file
const contractsPath = process.env.CONTRACTS_PATH;
const url = process.env.URL;
const privKey = process.env.PRIVATE_KEY;
const sourceChain = process.env.SOURCE_CHAIN;
const commandIDhex = process.env.COMMAND_ID;
const symbol = process.env.SYMBOL;
const amount = process.env.AMOUNT;
const gatewayAddress = process.env.GATEWAY_ADDRESS;

// the ABIs for the contract below must be manually downloaded/compiled
const IAxelarGateway = require(path.join(contractsPath,'IAxelarGateway.json'));

const provider = new JsonRpcProvider(url);
const wallet = new Wallet(privKey, provider);
const gateway = new Contract(gatewayAddress, IAxelarGateway.abi, wallet);

const hash = utils.keccak256(utils.arrayify(Buffer.from([])));
const commandID = utils.arrayify(commandIDhex.startsWith("0x") ? commandIDhex : "0x" + commandIDhex)

printLog(`validating contract call with token for chain ${sourceChain} and destination address ${wallet.address}`);

(async () => {
return gateway.validateContractCallAndMint(commandID,sourceChain,wallet.address,hash,symbol,amount);
})()
.then((tx) => {
jcs47 marked this conversation as resolved.
Show resolved Hide resolved
tx.wait();
jcs47 marked this conversation as resolved.
Show resolved Hide resolved
printLog(`successfully validated contract call with token for chain ${sourceChain} and destination address ${wallet.address} at tx ${tx.hash}`);
printObj({"validated" : tx.hash});
process.exit(0);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
67 changes: 67 additions & 0 deletions scripts/crosschain-token-transfer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict';

require('dotenv').config();

const {
Contract,
Wallet,
providers: { JsonRpcProvider },
} = require('ethers');

const {
printLog,
printObj,
} = require('./logging');

const path = require('node:path');

// these environment variables should be defined in an '.env' file
const contractsPath = process.env.CONTRACTS_PATH;
jcs47 marked this conversation as resolved.
Show resolved Hide resolved
const url = process.env.URL;
const privKey = process.env.PRIVATE_KEY;
const destinationChain = process.env.DESTINATION_CHAIN;
const symbol = process.env.SYMBOL;
const amount = process.env.AMOUNT;
const gatewayAddress = process.env.GATEWAY_ADDRESS;

// the ABIs for the contracts below must be manually downloaded/compiled
const IAxelarGateway = require(path.join(contractsPath,'IAxelarGateway.json'));
const IERC20 = require(path.join(contractsPath,'IERC20.json'));

const provider = new JsonRpcProvider(url);
const wallet = new Wallet(privKey, provider);
const gateway = new Contract(gatewayAddress, IAxelarGateway.abi, wallet);
const payload = Buffer.from([]);
let transactions = {};

printLog(`approving amount of ${amount}${symbol}`);

(async () => {
const tokenAddress = await gateway.tokenAddresses(symbol);
const token = new Contract(tokenAddress, IERC20.abi, wallet);
return token.approve(gatewayAddress, amount);
})()
.then((tx) => {
jcs47 marked this conversation as resolved.
Show resolved Hide resolved
tx.wait();
jcs47 marked this conversation as resolved.
Show resolved Hide resolved
printLog(`successfully approved amount of ${amount}${symbol} at tx ${tx.hash}`);
printLog(`calling contract with token for chain ${destinationChain} and destination address ${wallet.address}`);
transactions.approve = tx.hash;
})
.then(() => gateway.callContractWithToken(
destinationChain,
wallet.address,
payload,
symbol,
amount,
))
.then((tx) => {
tx.wait();
jcs47 marked this conversation as resolved.
Show resolved Hide resolved
printLog(`successfully called contract with token for chain ${destinationChain} and destination address ${wallet.address} at tx ${tx.hash}`);
transactions.mint = tx.hash;
printObj(transactions);
process.exit(0);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
21 changes: 12 additions & 9 deletions scripts/deploy-gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,31 @@ const {
} = require('ethers');

const { execSync } = require('child_process');
const path = require('node:path');

const {
printLog,
printObj,
} = require('./logging');

// these environment variables should be defined in an '.env' file
const contractsPath = process.env.CONTRACTS_PATH;
jcs47 marked this conversation as resolved.
Show resolved Hide resolved
const prefix = process.env.PREFIX;
const chain = process.env.CHAIN;
const url = process.env.URL;
const privKey = process.env.PRIVATE_KEY;
const adminThreshold = parseInt(process.env.ADMIN_THRESHOLD);

// the ABIs for the contracts below must be manually downloaded/compiled
const TokenDeployer = require(path.join(contractsPath,'TokenDeployer.json'));
const AxelarGatewayMultisig = require(path.join(contractsPath,'AxelarGatewayMultisig.json'));
const AxelarGatewayProxy = require(path.join(contractsPath,'AxelarGatewayProxy.json'));

const provider = new JsonRpcProvider(url);
const wallet = new Wallet(privKey, provider);

const TokenDeployer = require('../build/TokenDeployer.json');
const AxelarGatewayMultisig = require('../build/AxelarGatewayMultisig.json');
const AxelarGatewayProxy = require('../build/AxelarGatewayProxy.json');

const printLog = (log) => { console.log(JSON.stringify({ log })) }
const printObj = (obj) => { console.log(JSON.stringify(obj)) }

printLog("retrieving admin addresses")
const adminKeyIDs = JSON.parse(execSync(`${prefix} "axelard q tss external-key-id ${chain} --output json"`)).key_ids;

const admins = adminKeyIDs.map(adminKeyID => {
const output = execSync(`${prefix} "axelard q tss key ${adminKeyID} --output json"`);
const key = JSON.parse(output).ecdsa_key.key;
Expand All @@ -56,7 +60,6 @@ const getAddresses = (role) => {
}

printObj({admins: {addresses: admins, threshold: adminThreshold}});

printLog("retrieving owner addresses")
const { addresses: owners, threshold: ownerThreshold } = getAddresses("master")
printObj({owners: owners, threshold: ownerThreshold })
Expand Down
4 changes: 4 additions & 0 deletions scripts/logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

exports.printLog = (log) => { console.log(JSON.stringify({ log })) }
exports.printObj = (obj) => { console.log(JSON.stringify(obj)) }
jcs47 marked this conversation as resolved.
Show resolved Hide resolved