Skip to content

Commit

Permalink
feat: add send_erc20_packet script
Browse files Browse the repository at this point in the history
  • Loading branch information
liyukun committed Oct 16, 2023
1 parent f407f44 commit 557bf18
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 87 deletions.
2 changes: 1 addition & 1 deletion migrations/1_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = async function (deployer, network) {
packetAddress
);
const mockTransferAddress = await deployContract("MockTransfer", ibcAddress);
const transferAddress = await deployContract("ICS20TransferERC20", ibcAddress);
const transferAddress = await deployContract("ICS20TransferERC20Allowlist", ibcAddress);
const mockClient = await deployContract("MockClient");
const ibcHandler = await IBCHandler.at(ibcAddress);

Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"scripts": {
"compile": "truffle compile",
"migrate": "truffle migrate --network axon",
"send": "truffle exec './scripts/send_packet.js' --network axon",
"query": "truffle exec './scripts/query_packet.js' --network axon"
"send": "truffle exec './scripts/send_erc20_packet.js' --network axon"
},
"dependencies": {
"@openzeppelin/contracts": "^4.8.0",
Expand All @@ -17,4 +16,4 @@
"ganache": "^7.9.0",
"truffle": "^5.11.1"
}
}
}
2 changes: 1 addition & 1 deletion scripts/check_balance_and_send_back.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async function main() {
console.log("Receiver should be:", receiver);
const sender = process.env.SENDER;

const ICS20TransferERC20 = await artifacts.require("ICS20TransferERC20");
const ICS20TransferERC20 = await artifacts.require("ICS20TransferERC20Allowlist");
const IERC20 = await artifacts.require("IERC20");

const transfer = await ICS20TransferERC20.at(
Expand Down
28 changes: 0 additions & 28 deletions scripts/common.js

This file was deleted.

19 changes: 0 additions & 19 deletions scripts/query_packet.js

This file was deleted.

48 changes: 48 additions & 0 deletions scripts/send_erc20_packet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// This is for emitting SendPacket event directly from Axon to initial the IBC communication

async function main() {
// First provider account.
const [sender] = await web3.eth.getAccounts();
// Receiver should be CKB address, which is first 20 bytes of hash of sender's lock_script
const receiver = process.env.RECEIVER;
console.log("Sender and receiver:", sender, receiver);

const ICS20TransferERC20 = await artifacts.require("ICS20TransferERC20Allowlist");

const transfer = await ICS20TransferERC20.at(
process.env.TRANSFER_CONTRACT_ADDRESS
);

const port = "transfer";
const channel = process.env.CHANNEL;

const denom = `${port}/${channel}/${process.env.DENOM}`;

// Check token associated with the denom that is created before, if not exist, create one
let tokenAddr = await transfer.denomTokenContract(denom);
if (tokenAddr == "0x0000000000000000000000000000000000000000") {
const ERC20PresetMinterPauser = await artifacts.require("ERC20PresetMinterPauser");
const token_name = process.env.TOKEN_NAME;
const token_symbol = process.env.TOKEN_SIMBOL;
const token = await ERC20PresetMinterPauser.new(token_name, token_symbol);
await token.grantRole(await token.MINTER_ROLE(), transfer.address);
await token.mint(sender, 999);
await transfer.setDenomTokenContract(denom, token.address);
tokenAddr = token.address;
}

// Send packet: ERC20 approve and ICS20 sendTransfer.
await token.approve(transfer.address, 499, {
from: sender,
});
await transfer.sendTransfer(denom, 499, receiver, port, channel, 0, {
from: sender,
});
}

module.exports = (callback) => {
main().then(callback).catch(e => {
console.log("Error:", e.message, e);
callback();
});
};
35 changes: 0 additions & 35 deletions scripts/send_packet.js

This file was deleted.

0 comments on commit 557bf18

Please sign in to comment.