Skip to content

Commit

Permalink
Merge branch 'main' into docs/readme
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth authored Dec 15, 2023
2 parents c35a4ed + fd2bd8e commit adab8dc
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 477 deletions.
16 changes: 14 additions & 2 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,25 @@ async function deployAll(
deploymentKey,
);

const factory = await deployInterchainTokenFactory(
const tokenFactory = await deployInterchainTokenFactory(
wallet,
create3Deployer.address,
interchainTokenServiceAddress,
factoryDeploymentKey,
);
return [service, gateway, gasService, factory, create3Deployer];

return {
service,
gateway,
gasService,
tokenFactory,
create3Deployer,
tokenManagerDeployer,
interchainToken,
interchainTokenDeployer,
tokenManager,
tokenHandler,
};
}

module.exports = {
Expand Down
22 changes: 11 additions & 11 deletions test/AddressDerivation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ const {
} = ethers;
const { deployAll } = require('../scripts/deploy');
const { approveContractCall } = require('../scripts/utils');
const { getRandomBytes32, getSaltFromKey, isHardhat } = require('./utils');
const { getRandomBytes32, getSaltFromKey, isHardhat, getContractJSON } = require('./utils');
const { create3DeployContract } = require('@axelar-network/axelar-gmp-sdk-solidity');
const Token = require('../artifacts/contracts/test/TestInterchainTokenStandard.sol/TestInterchainTokenStandard.json');
const Token = getContractJSON('TestInterchainTokenStandard');
const MINT_BURN = 0;
const MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN = 1;

Expand All @@ -21,7 +21,7 @@ if (isHardhat) {
let service;
let gateway;
let create3Deployer;
let factory;
let tokenFactory;
let token;
let sourceAddress;

Expand All @@ -35,7 +35,7 @@ if (isHardhat) {
const wallets = await ethers.getSigners();
wallet = wallets[0];

[service, gateway, , factory, create3Deployer] = await deployAll(wallet, 'Test', [sourceChain, destinationChain]);
({ service, gateway, tokenFactory, create3Deployer } = await deployAll(wallet, 'Test', [sourceChain, destinationChain]));
token = await create3DeployContract(create3Deployer.address, wallet, Token, 'Test', [
tokenName,
tokenSymbol,
Expand Down Expand Up @@ -116,23 +116,23 @@ if (isHardhat) {

it('Should derive the correct token address for interchain token deployment on source chain', async () => {
const salt = getSaltFromKey('deployInterchainToken');
const tokenId = await factory.interchainTokenId(wallet.address, salt);
const tokenId = await tokenFactory.interchainTokenId(wallet.address, salt);

const expectedTokenAddress = '0xD48F12c4b65135575495C476977B893D8e817B4b';
const expectedTokenManagerAddress = '0xcb7DEA0Aeb34A992451717C0537b5C4eA1635A54';

const params = defaultAbiCoder.encode(['bytes', 'address'], [factory.address, expectedTokenAddress]);
const params = defaultAbiCoder.encode(['bytes', 'address'], [tokenFactory.address, expectedTokenAddress]);

await expect(factory.deployInterchainToken(salt, tokenName, tokenSymbol, tokenDecimals, initialSupply, wallet.address))
await expect(tokenFactory.deployInterchainToken(salt, tokenName, tokenSymbol, tokenDecimals, initialSupply, wallet.address))
.to.emit(service, 'InterchainTokenDeployed')
.withArgs(tokenId, expectedTokenAddress, factory.address, tokenName, tokenSymbol, tokenDecimals)
.withArgs(tokenId, expectedTokenAddress, tokenFactory.address, tokenName, tokenSymbol, tokenDecimals)
.to.emit(service, 'TokenManagerDeployed')
.withArgs(tokenId, expectedTokenManagerAddress, MINT_BURN, params);
});

it('Should derive the correct token address for remote interchain token deployment', async () => {
const salt = getSaltFromKey('deployRemoteInterchainToken');
const tokenId = await factory.interchainTokenId(wallet.address, salt);
const tokenId = await tokenFactory.interchainTokenId(wallet.address, salt);
const minter = wallet.address;
const operator = wallet.address;

Expand All @@ -156,7 +156,7 @@ if (isHardhat) {

it('Should derive the correct token address for remote interchain token deployment with empty minter and operator', async () => {
const salt = getSaltFromKey('deployRemoteInterchainTokenEmpty');
const tokenId = await factory.interchainTokenId(wallet.address, salt);
const tokenId = await tokenFactory.interchainTokenId(wallet.address, salt);
const minter = AddressZero;
const operator = '0x';

Expand All @@ -179,7 +179,7 @@ if (isHardhat) {
});

it('Should derive the correct token address for remote canonical token deployment', async () => {
const tokenId = await factory.canonicalInterchainTokenId(token.address);
const tokenId = await tokenFactory.canonicalInterchainTokenId(token.address);
const minter = wallet.address;
const operator = wallet.address;

Expand Down
2 changes: 0 additions & 2 deletions test/ERC20Permit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ describe('ERC20 Permit', () => {
const wallets = await ethers.getSigners();
owner = wallets[0];
user = wallets[1];
});

beforeEach(async () => {
interchainToken = await deployContract(owner, 'InterchainToken', [owner.address]);
interchainTokenDeployer = await deployContract(owner, 'InterchainTokenDeployer', [interchainToken.address]);

Expand Down
37 changes: 4 additions & 33 deletions test/InterchainTokenFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ const {
constants: { AddressZero },
utils: { defaultAbiCoder, keccak256, toUtf8Bytes },
} = ethers;

const { deployAll, deployContract } = require('../scripts/deploy');
const { getRandomBytes32, expectRevert } = require('./utils');

// const MESSAGE_TYPE_INTERCHAIN_TRANSFER = 0;
const MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN = 1;
// const MESSAGE_TYPE_DEPLOY_TOKEN_MANAGER = 2;

const LOCK_UNLOCK = 2;
const MINT_BURN = 0;
Expand All @@ -35,7 +32,7 @@ describe('InterchainTokenFactory', () => {

before(async () => {
[wallet, otherWallet] = await ethers.getSigners();
[service, gateway, gasService, tokenFactory] = await deployAll(wallet, chainName, [destinationChain]);
({ service, gateway, gasService, tokenFactory } = await deployAll(wallet, chainName, [destinationChain]));
});

describe('Token Factory Deployment', async () => {
Expand Down Expand Up @@ -72,9 +69,11 @@ describe('InterchainTokenFactory', () => {
await (await token.setTokenId(tokenId)).wait();
}

it('Should register a token', async () => {
before(async () => {
await deployToken();
});

it('Should register a token', async () => {
const params = defaultAbiCoder.encode(['bytes', 'address'], ['0x', token.address]);

await expect(tokenFactory.registerCanonicalInterchainToken(token.address))
Expand All @@ -84,19 +83,11 @@ describe('InterchainTokenFactory', () => {

it('Should initiate a remote interchain token deployment with no original chain name provided', async () => {
const gasValue = 1234;

await deployToken();

const params = defaultAbiCoder.encode(['bytes', 'address'], ['0x', token.address]);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes'],
[MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, name, symbol, decimals, '0x'],
);

await expect(tokenFactory.registerCanonicalInterchainToken(token.address))
.to.emit(service, 'TokenManagerDeployed')
.withArgs(tokenId, tokenManagerAddress, LOCK_UNLOCK, params);

await expect(
tokenFactory.deployRemoteCanonicalInterchainToken('', token.address, destinationChain, gasValue, {
value: gasValue,
Expand All @@ -112,19 +103,11 @@ describe('InterchainTokenFactory', () => {

it('Should initiate a remote interchain token deployment', async () => {
const gasValue = 1234;

await deployToken();

const params = defaultAbiCoder.encode(['bytes', 'address'], ['0x', token.address]);
const payload = defaultAbiCoder.encode(
['uint256', 'bytes32', 'string', 'string', 'uint8', 'bytes'],
[MESSAGE_TYPE_DEPLOY_INTERCHAIN_TOKEN, tokenId, name, symbol, decimals, '0x'],
);

await expect(tokenFactory.registerCanonicalInterchainToken(token.address))
.to.emit(service, 'TokenManagerDeployed')
.withArgs(tokenId, tokenManagerAddress, LOCK_UNLOCK, params);

await expect(
tokenFactory.deployRemoteCanonicalInterchainToken(chainName, token.address, destinationChain, gasValue, {
value: gasValue,
Expand All @@ -138,19 +121,7 @@ describe('InterchainTokenFactory', () => {
.withArgs(service.address, destinationChain, service.address, keccak256(payload), payload);
});

it('Should transfer some tokens to the factory', async () => {
await deployToken();

const params = defaultAbiCoder.encode(['bytes', 'address'], ['0x', token.address]);

await expect(tokenFactory.registerCanonicalInterchainToken(token.address))
.to.emit(service, 'TokenManagerDeployed')
.withArgs(tokenId, tokenManagerAddress, LOCK_UNLOCK, params);
});

it('Should revert when trying to register a canonical lock/unlock gateway token', async () => {
await deployToken();

const tokenCap = 0;
const mintLimit = 0;
const tokenAddress = token.address;
Expand Down
Loading

0 comments on commit adab8dc

Please sign in to comment.