Skip to content

Commit

Permalink
feat: its register other chains automatically (#97)
Browse files Browse the repository at this point in the history
* fix type imports

* update more imports

* bumped version

* exporting its contract addresses as well

* v2.1.4

* register other chains for its on create and export
  • Loading branch information
Foivos authored Nov 29, 2023
1 parent 5e0a89f commit 0b8c2f4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
4 changes: 3 additions & 1 deletion packages/axelar-local-dev/src/exportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import { ethers } from 'ethers';
import { setJSON } from './utils';
import { Network, NetworkOptions } from './Network';
import { Network, NetworkOptions, networks } from './Network';
import { RelayData, RelayerMap, relay } from './relay';
import { createNetwork, forkNetwork, listen, stopAll } from './networkUtils';
import { testnetInfo } from './info';
import { EvmRelayer } from './relay/EvmRelayer';
import { getChainArray } from '@axelar-network/axelar-chains-config';
import { registerRemoteITS } from './its';

let interval: any;

Expand Down Expand Up @@ -85,6 +86,7 @@ export async function createAndExport(options: CreateLocalOptions = {}) {

i++;
}
await registerRemoteITS(networks);
listen(_options.port);
interval = setInterval(async () => {
if (relaying) return;
Expand Down
25 changes: 21 additions & 4 deletions packages/axelar-local-dev/src/its.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { BigNumberish, Contract, Wallet } from 'ethers';
import {
IInterchainToken,
ITokenManager,
} from './types/@axelar-network/interchain-token-service/contracts/interfaces';
import { IInterchainToken, ITokenManager } from './types/@axelar-network/interchain-token-service/contracts/interfaces';
import {
IInterchainToken__factory as IInterchainTokenFactory,
ITokenManager__factory as TokenManagerFactory,
} from './types/factories/@axelar-network/interchain-token-service/contracts/interfaces';
import { Network, networks } from './Network';
import { relay } from './relay';
import { logger } from './utils';

export interface ITS {
registerCanonicalToken: (tokenAddress: string, wallet?: Wallet) => Promise<ITokenManager>;
Expand Down Expand Up @@ -102,3 +100,22 @@ export async function setupITS(network: Network) {
return IInterchainTokenFactory.connect(tokenAddress, destinationChain.provider);
};
}

export async function registerRemoteITS(networks: Network[]) {
for (const network of networks) {
logger.log(`Registerring ITS for ${networks.length} other chain for ${network.name}...`);
const data = [] as string[];
for (const otherNetwork of networks) {
data.push(
(
await network.interchainTokenService.populateTransaction.setTrustedAddress(
otherNetwork.name,
otherNetwork.interchainTokenService.address
)
).data as string
);
}
await (await network.interchainTokenService.multicall(data)).wait();
logger.log(`Done`);
}
}
2 changes: 1 addition & 1 deletion packages/axelar-local-dev/src/relay/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class Command {
this.commandId = commandId;
this.name = name;
this.data = data;

this.encodedData =
(chain === 'aptos' || chain === 'sui') && name === 'approve_contract_call' ? '' : defaultAbiCoder.encode(dataSignature, data);
this.post = post;
Expand Down
2 changes: 1 addition & 1 deletion packages/axelar-local-dev/src/relay/Relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export abstract class Relayer {
this.commands['near'] = [];
// Update all events at the source chains
await this.updateEvents();

await this.execute(this.commands);
}

Expand Down

0 comments on commit 0b8c2f4

Please sign in to comment.