Skip to content

Commit

Permalink
feat: interchain token service deployment (#83)
Browse files Browse the repository at this point in the history
* added support for ITS.

* Deploying its succesfully

* added some helper functions.

* removed test file

* added a small check on tests

* fixed dep

* changed package-lock as well

* add test.js so i can delete it

* remove test.js

* added support for deploying the newest its

* updated package-lock

* installing its as well.

* using sui testnet because devnet is broken rn

* update package-lock

* disable concurrent tests for sui

* use leran as a dep because postintall depends on it
  • Loading branch information
Foivos authored Nov 29, 2023
1 parent 9290139 commit 65a0307
Show file tree
Hide file tree
Showing 15 changed files with 13,907 additions and 13,866 deletions.
27,503 changes: 13,654 additions & 13,849 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
"build:aptos": "lerna exec --scope=@axelar-network/axelar-local-dev-aptos npm run build",
"build:sui": "lerna exec --scope=@axelar-network/axelar-local-dev-sui npm run build"
},
"dependencies": {
"lerna": "^6.6.1"
},
"devDependencies": {
"lerna": "^6.6.1",
"lerna-update-wizard": "^1.1.2"
}
}
2 changes: 2 additions & 0 deletions packages/axelar-local-dev-sui/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ module.exports = {
testRegex: '/__tests__/.*\\.(test|spec)?\\.(ts)$',
transformIgnorePatterns: ['<rootDir>/node_modules/'],
testTimeout: 300000,
maxConcurrency: 1,
maxWorkers: 1,
};
6 changes: 3 additions & 3 deletions packages/axelar-local-dev-sui/move/sample/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 0
manifest_digest = "B9756E20D89B038C4DA36DD158F55936F14526859C71CDB9AFEA61AE4AAD0903"
manifest_digest = "0EDEB57066A8F166917A87099F7DEC502108CDA37430B4E948FE20B60EA16A71"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"

dependencies = [
Expand All @@ -20,11 +20,11 @@ dependencies = [

[[move.package]]
name = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/devnet", subdir = "crates/sui-framework/packages/move-stdlib" }
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" }

[[move.package]]
name = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/devnet", subdir = "crates/sui-framework/packages/sui-framework" }
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" }

dependencies = [
{ name = "MoveStdlib" },
Expand Down
2 changes: 1 addition & 1 deletion packages/axelar-local-dev-sui/move/sample/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "Test"
version = "0.0.1"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/devnet" }
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }
Axelar = { local = "../../../../node_modules/@axelar-network/axelar-cgp-sui/move/axelar" }

[addresses]
Expand Down
1 change: 1 addition & 0 deletions packages/axelar-local-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@axelar-network/axelar-cgp-solidity": "^6.1.0",
"@axelar-network/axelar-chains-config": "^0.1.0",
"@axelar-network/axelar-gmp-sdk-solidity": "^5.3.0",
"@axelar-network/interchain-token-service": "^1.0.0-beta.2",
"ethers": "^5.6.5",
"fs-extra": "^10.1.0",
"ganache": "^7.1.0",
Expand Down
82 changes: 81 additions & 1 deletion packages/axelar-local-dev/src/Network.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import { ethers, Wallet, Contract, providers, ContractFactory } from 'ethers';
import http from 'http';
import { ethers, Wallet, Contract, providers } from 'ethers';
import { logger } from './utils';
import { getSignedExecuteInput, getRandomID, deployContract } from './utils';
import {
Expand All @@ -12,11 +12,28 @@ import {
AxelarGasReceiverProxy,
ConstAddressDeployer,
Create3Deployer,
TokenManagerDeployer,
InterchainTokenDeployer,
InterchainToken,
TokenManagerMintBurn,
TokenManagerMintBurnFrom,
TokenManagerLockUnlock,
TokenManagerLockUnlockFee,
InterchainTokenService as InterchainTokenServiceContract,
InterchainTokenFactory as InterchainTokenFactoryContract,
InterchainTokenServiceProxy,
IntercahinTokenFactoryProxy,
} from './contracts';
import { AxelarGateway__factory as AxelarGatewayFactory } from './types/factories/@axelar-network/axelar-cgp-solidity/contracts/AxelarGateway__factory';
import { AxelarGateway } from './types/@axelar-network/axelar-cgp-solidity/contracts/AxelarGateway';
import { InterchainTokenService, InterchainTokenFactory } from './types';
import { AxelarGasService__factory as AxelarGasServiceFactory } from './types/factories/@axelar-network/axelar-cgp-solidity/contracts/gas-service/AxelarGasService__factory';
import {
InterchainTokenService__factory as InterchainTokenServiceFactory,
InterchainTokenFactory__factory as InterchainTokenFactoryFactory,
} from './types';
import { AxelarGasService } from './types/@axelar-network/axelar-cgp-solidity/contracts/gas-service/AxelarGasService';
import { ITS, setupITS } from './its';

const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
const { defaultAbiCoder, arrayify, keccak256, toUtf8Bytes } = ethers.utils;
Expand Down Expand Up @@ -46,6 +63,8 @@ export interface NetworkInfo {
gasReceiverAddress: string;
constAddressDeployerAddress: string;
create3DeployerAddress: string;
InterchainTokenService: string;
InterchainTokenFactory: string;
tokens: { [key: string]: string };
}
export interface NetworkSetup {
Expand Down Expand Up @@ -80,12 +99,15 @@ export class Network {
gasService: AxelarGasService;
constAddressDeployer: Contract;
create3Deployer: Contract;
interchainTokenService: InterchainTokenService;
interchainTokenFactory: InterchainTokenFactory;
isRemote: boolean | undefined;
url: string | undefined;
ganacheProvider: any;
server: http.Server | undefined;
port: number | undefined;
tokens: { [key: string]: string };
its: ITS;
constructor(networkish: any = {}) {
this.name = networkish.name;
this.chainId = networkish.chainId;
Expand All @@ -102,9 +124,12 @@ export class Network {
this.gasService = networkish.gasService;
this.constAddressDeployer = networkish.constAddressDeployer;
this.create3Deployer = networkish.create3Deployer;
this.interchainTokenService = networkish.interchainTokenService;
this.interchainTokenFactory = networkish.interchainTokenFactory;
this.isRemote = networkish.isRemote;
this.url = networkish.url;
this.tokens = networkish.tokens;
this.its = networkish.its;
}
async deployGateway(): Promise<Contract> {
logger.log(`Deploying the Axelar Gateway for ${this.name}... `);
Expand Down Expand Up @@ -156,6 +181,7 @@ export class Network {
logger.log(`Upgraded ${this.gateway.address}`);
return this.gateway;
}

async deployGasReceiver(): Promise<Contract> {
logger.log(`Deploying the Axelar Gas Receiver for ${this.name}... `);
const gasService = await deployContract(this.ownerWallet, AxelarGasServiceFactory, [this.ownerWallet.address]);
Expand All @@ -166,6 +192,7 @@ export class Network {
logger.log(`Deployed at ${this.gasService.address}`);
return this.gasService;
}

async deployConstAddressDeployer(): Promise<Contract> {
logger.log(`Deploying the ConstAddressDeployer for ${this.name}... `);
const constAddressDeployerDeployerPrivateKey = keccak256(toUtf8Bytes('const-address-deployer-deployer'));
Expand All @@ -182,6 +209,7 @@ export class Network {
logger.log(`Deployed at ${this.constAddressDeployer.address}`);
return this.constAddressDeployer;
}

async deployCreate3Deployer(): Promise<Contract> {
logger.log(`Deploying the ConstAddressDeployer for ${this.name}... `);
const create3DeployerPrivateKey = keccak256(toUtf8Bytes('const-address-deployer-deployer'));
Expand All @@ -199,6 +227,56 @@ export class Network {
return this.create3Deployer;
}

async deployInterchainTokenService() {
logger.log(`Deploying the InterchainTokenService for ${this.name}... `);
const deploymentSalt = keccak256(defaultAbiCoder.encode(['string'], ['interchain-token-service-salt']));
const factorySalt = keccak256(defaultAbiCoder.encode(['string'], ['interchain-token-factory-salt']));
const wallet = this.ownerWallet;
const tokenManagerDeployer = await deployContract(wallet, TokenManagerDeployer);
const intercahinToken = await deployContract(wallet, InterchainToken);
const interchainTokenDeployer = await deployContract(wallet, InterchainTokenDeployer, [intercahinToken.address]);

const interchainTokenServiceAddress = await this.create3Deployer.deployedAddress('0x', wallet.address, deploymentSalt);
const tokenManagerImplementations = [
await deployContract(wallet, TokenManagerMintBurn, [interchainTokenServiceAddress]),
await deployContract(wallet, TokenManagerMintBurnFrom, [interchainTokenServiceAddress]),
await deployContract(wallet, TokenManagerLockUnlock, [interchainTokenServiceAddress]),
await deployContract(wallet, TokenManagerLockUnlockFee, [interchainTokenServiceAddress]),
].map((contract) => contract.address);

const interchainTokenFactoryAddress = await this.create3Deployer.deployedAddress('0x', wallet.address, factorySalt);

let implementation = await deployContract(wallet, InterchainTokenServiceContract, [
tokenManagerDeployer.address,
interchainTokenDeployer.address,
this.gateway.address,
this.gasService.address,
interchainTokenFactoryAddress,
this.name,
tokenManagerImplementations,
]);
let factory = new ContractFactory(InterchainTokenServiceProxy.abi, InterchainTokenServiceProxy.bytecode);
let bytecode = factory.getDeployTransaction(
implementation.address,
wallet.address,
defaultAbiCoder.encode(['address', 'string', 'string[]', 'string[]'], [wallet.address, this.name, [], []])
).data;
await this.create3Deployer.connect(wallet).deploy(bytecode, deploymentSalt);
this.interchainTokenService = InterchainTokenServiceFactory.connect(interchainTokenServiceAddress, wallet);

implementation = await deployContract(wallet, InterchainTokenFactoryContract, [interchainTokenServiceAddress]);

factory = new ContractFactory(IntercahinTokenFactoryProxy.abi, IntercahinTokenFactoryProxy.bytecode);
bytecode = factory.getDeployTransaction(implementation.address, wallet.address).data;

await this.create3Deployer.connect(wallet).deploy(bytecode, factorySalt);
this.interchainTokenFactory = InterchainTokenFactoryFactory.connect(interchainTokenFactoryAddress, wallet);

await setupITS(this);
logger.log(`Deployed at ${this.interchainTokenService.address}.`);
return this.interchainTokenService;
}

async deployToken(name: string, symbol: string, decimals: number, cap: bigint, address: string = ADDRESS_ZERO, alias: string = symbol) {
logger.log(`Deploying ${name} for ${this.name}... `);
const data = arrayify(
Expand Down Expand Up @@ -267,6 +345,8 @@ export class Network {
gasReceiverAddress: this.gasService.address,
constAddressDeployerAddress: this.constAddressDeployer.address,
create3DeployerAddress: this.create3Deployer.address,
InterchainTokenService: this.interchainTokenService.address,
InterchainTokenFactory: this.interchainTokenFactory.address,
tokens: this.tokens,
};
return info;
Expand Down
4 changes: 2 additions & 2 deletions packages/axelar-local-dev/src/__tests__/forking.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import chai from 'chai';
import { Contract, Wallet } from 'ethers';
const { expect } = chai;
import { relay, stopAll, setLogger, forkNetwork, mainnetInfo, networks, getFee } from '../';
import { relay, stopAll, setLogger, forkNetwork, mainnetInfo, networks, getFee, ChainCloneData } from '../';
import { keccak256, toUtf8Bytes } from 'ethers/lib/utils';
import { Network } from '../Network';

Expand All @@ -20,7 +20,7 @@ describe.skip('forking', () => {
});

it.skip('should fork Avalanche mainnet', async () => {
const chainName = 'Avalanche';
const chainName = 'avalanche';
const tokenAlias = 'uusdc';
const testAmount = 1234;
const chains = mainnetInfo as any;
Expand Down
3 changes: 2 additions & 1 deletion packages/axelar-local-dev/src/__tests__/network.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import chai from 'chai';
const { expect } = chai;
setLogger(() => null);


function validateNetwork(network: Network) {
// wallets
expect(network.provider).to.not.be.undefined;
Expand All @@ -25,6 +24,8 @@ function validateNetwork(network: Network) {
expect(network.constAddressDeployer).to.not.be.undefined;
expect(network.create3Deployer).to.not.be.undefined;
expect(network.gateway).to.not.be.undefined;
expect(network.its).to.not.be.undefined;
expect(network.interchainTokenService).to.not.be.undefined;
}

describe('Network', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/axelar-local-dev/src/__tests__/token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { expect } = chai;

setLogger(() => undefined);


describe('token', () => {
let chain: Network;
let usdc: Contract;
Expand Down
16 changes: 16 additions & 0 deletions packages/axelar-local-dev/src/contracts/ITS.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.9;

// Interchain Token Service
import { TokenManagerDeployer } from '@axelar-network/interchain-token-service/contracts/utils/TokenManagerDeployer.sol';
import { InterchainToken } from '@axelar-network/interchain-token-service/contracts/interchain-token/InterchainToken.sol';
import { InterchainTokenDeployer } from '@axelar-network/interchain-token-service/contracts/utils/InterchainTokenDeployer.sol';
import { TokenManagerLockUnlock } from '@axelar-network/interchain-token-service/contracts/token-manager/TokenManagerLockUnlock.sol';
import { TokenManagerLockUnlockFee } from '@axelar-network/interchain-token-service/contracts/token-manager/TokenManagerLockUnlockFee.sol';
import { TokenManagerMintBurn } from '@axelar-network/interchain-token-service/contracts/token-manager/TokenManagerMintBurn.sol';
import { TokenManagerMintBurnFrom } from '@axelar-network/interchain-token-service/contracts/token-manager/TokenManagerMintBurnFrom.sol';
import { InterchainTokenService } from '@axelar-network/interchain-token-service/contracts/InterchainTokenService.sol';
import { InterchainTokenServiceProxy } from '@axelar-network/interchain-token-service/contracts/proxies/InterchainTokenServiceProxy.sol';
import { InterchainTokenFactory } from '@axelar-network/interchain-token-service/contracts/InterchainTokenFactory.sol';
import { InterchainTokenFactoryProxy } from '@axelar-network/interchain-token-service/contracts/proxies/InterchainTokenFactoryProxy.sol';
27 changes: 27 additions & 0 deletions packages/axelar-local-dev/src/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ import ConstAddressDeployer from '@axelar-network/axelar-gmp-sdk-solidity/artifa
import Create3Deployer from '@axelar-network/axelar-gmp-sdk-solidity/artifacts/contracts/deploy/Create3Deployer.sol/Create3Deployer.json';
import IAxelarExecutable from '../artifacts/@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarExecutable.sol/IAxelarExecutable.json';

import TokenManagerDeployer from '../artifacts/@axelar-network/interchain-token-service/contracts/utils/TokenManagerDeployer.sol/TokenManagerDeployer.json';
import InterchainToken from '../artifacts/@axelar-network/interchain-token-service/contracts/interchain-token/InterchainToken.sol/InterchainToken.json';
import InterchainTokenDeployer from '../artifacts/@axelar-network/interchain-token-service/contracts/utils/InterchainTokenDeployer.sol/InterchainTokenDeployer.json';
import TokenManagerLockUnlock from '../artifacts/@axelar-network/interchain-token-service/contracts/token-manager/TokenManagerLockUnlock.sol/TokenManagerLockUnlock.json';
import TokenManagerLockUnlockFee from '../artifacts/@axelar-network/interchain-token-service/contracts/token-manager/TokenManagerLockUnlockFee.sol/TokenManagerLockUnlockFee.json';
import TokenManagerMintBurn from '../artifacts/@axelar-network/interchain-token-service/contracts/token-manager/TokenManagerMintBurn.sol/TokenManagerMintBurn.json';
import TokenManagerMintBurnFrom from '../artifacts/@axelar-network/interchain-token-service/contracts/token-manager/TokenManagerMintBurnFrom.sol/TokenManagerMintBurnFrom.json';
import InterchainTokenService from '../artifacts/@axelar-network/interchain-token-service/contracts/InterchainTokenService.sol/InterchainTokenService.json';
import InterchainTokenFactory from '../artifacts/@axelar-network/interchain-token-service/contracts/InterchainTokenFactory.sol/InterchainTokenFactory.json';
import InterchainTokenServiceProxy from '../artifacts/@axelar-network/interchain-token-service/contracts/proxies/InterchainTokenServiceProxy.sol/InterchainTokenServiceProxy.json';
import IntercahinTokenFactoryProxy from '../artifacts/@axelar-network/interchain-token-service/contracts/proxies/InterchainTokenFactoryProxy.sol/InterchainTokenFactoryProxy.json';
import IInterchainTokenService from '../artifacts/@axelar-network/interchain-token-service/contracts/interfaces/IInterchainTokenService.sol/IInterchainTokenService.json';
import IInterchainTokenFactory from '../artifacts/@axelar-network/interchain-token-service/contracts/interfaces/IInterchainTokenFactory.sol/IInterchainTokenFactory.json';

export {
TokenDeployer,
AxelarGatewayProxy,
Expand All @@ -24,4 +38,17 @@ export {
Create3Deployer,
IAxelarGasService,
IAxelarExecutable,
TokenManagerDeployer,
InterchainToken,
InterchainTokenDeployer,
TokenManagerLockUnlock,
TokenManagerLockUnlockFee,
TokenManagerMintBurn,
TokenManagerMintBurnFrom,
InterchainTokenService,
InterchainTokenServiceProxy,
InterchainTokenFactory,
IntercahinTokenFactoryProxy,
IInterchainTokenService,
IInterchainTokenFactory,
};
6 changes: 1 addition & 5 deletions packages/axelar-local-dev/src/contracts/test/Executable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ contract Executable is AxelarExecutable {

/* Handles calls created by setAndSend. Updates this contract's value
and gives the token received to the destination specified at the source chain. */
function _execute(
string calldata sourceChain_,
string calldata sourceAddress_,
bytes calldata payload_
) internal override {
function _execute(string calldata sourceChain_, string calldata sourceAddress_, bytes calldata payload_) internal override {
(value) = abi.decode(payload_, (string));
sourceChain = sourceChain_;
sourceAddress = sourceAddress_;
Expand Down
Loading

0 comments on commit 65a0307

Please sign in to comment.