Skip to content

Commit

Permalink
Merge branch 'feat/sui-operators' of github.com:axelarnetwork/axelar-…
Browse files Browse the repository at this point in the history
…contract-deployments into feat/sui-operators
  • Loading branch information
npty committed Aug 4, 2024
2 parents 17617fb + 4aa1ac0 commit 144d15a
Show file tree
Hide file tree
Showing 6 changed files with 1,207 additions and 257 deletions.
1,319 changes: 1,077 additions & 242 deletions axelar-chains-config/info/stagenet.json

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions sui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ Deploy the Operators package:
node sui/deploy-contract.js deploy Operators
```

Deploy the Abi package:

```bash
node sui/deploy-contract.js deploy Abi
```

Deploy the Governance package (requires `abi` and `axelar_gateway`):

```bash
node sui/deploy-contract.js deploy Governance
```

Deploy the ITS package (requires `abi`, `axelar_gateway` and `goverannce`):

```bash
node sui/deploy-contract.js deploy ITS
```

Deploy the Squid package (requires `abi`, `axelar_gateway`, `goverannce` and `its`):

```bash
node sui/deploy-contract.js deploy Squid
```

Call Contract:

```bash
Expand Down
53 changes: 49 additions & 4 deletions sui/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const {
suiPackageAddress,
suiClockAddress,
readMovePackageName,
getChannelId,
getSingletonChannelId,
getItsChannelId,
getSquidChannelId,
} = require('./utils');

/**
Expand All @@ -35,7 +37,7 @@ const {
* 2. Ensure the corresponding folder exists in the specified path
*
*/
const PACKAGE_DIRS = ['gas_service', 'test', 'axelar_gateway', 'operators'];
const PACKAGE_DIRS = ['gas_service', 'test', 'axelar_gateway', 'operators', 'abi', 'governance', 'its', 'squid'];

/**
* Package Mapping Object for Command Options and Post-Deployment Functions
Expand All @@ -46,12 +48,20 @@ const PACKAGE_CONFIGS = {
GasService: () => [],
Test: () => [],
Operators: () => [],
Abi: () => [],
Governance: () => [],
ITS: () => [],
Squid: () => [],
},
postDeployFunctions: {
AxelarGateway: postDeployAxelarGateway,
GasService: postDeployGasService,
Test: postDeployTest,
Operators: postDeployOperators,
Abi: {},
Governance: {},
ITS: postDeployIts,
Squid: postDeploySquid,
},
};

Expand Down Expand Up @@ -94,7 +104,7 @@ async function postDeployTest(published, keypair, client, config, chain, options
const relayerDiscovery = config.sui.contracts.AxelarGateway?.objects?.RelayerDiscovery;

const [singletonObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [`${published.packageId}::test::Singleton`]);
const channelId = await getChannelId(client, singletonObjectId);
const channelId = await getSingletonChannelId(client, singletonObjectId);
chain.contracts.Test.objects = { Singleton: singletonObjectId, ChannelId: channelId };

const tx = new Transaction();
Expand Down Expand Up @@ -191,6 +201,42 @@ async function postDeployAxelarGateway(published, keypair, client, config, chain
};
}

async function postDeployIts(published, keypair, client, config, chain, options) {
const relayerDiscovery = config.sui.contracts.AxelarGateway?.objects?.RelayerDiscovery;

const [itsObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [`${published.packageId}::its::ITS`]);
const channelId = await getItsChannelId(client, itsObjectId);
chain.contracts.ITS.objects = { ITS: itsObjectId, ChannelId: channelId };

const tx = new Transaction();
tx.moveCall({
target: `${published.packageId}::discovery::register_transaction`,
arguments: [tx.object(itsObjectId), tx.object(relayerDiscovery)],
});

const registerTx = await broadcast(client, keypair, tx);

printInfo('Register transaction', registerTx.digest);
}

async function postDeploySquid(published, keypair, client, config, chain, options) {
const relayerDiscovery = config.sui.contracts.AxelarGateway?.objects?.RelayerDiscovery;

const [squidObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [`${published.packageId}::squid::Squid`]);
const channelId = await getSquidChannelId(client, squidObjectId);
chain.contracts.Squid.objects = { Squid: squidObjectId, ChannelId: channelId };

const tx = new Transaction();
tx.moveCall({
target: `${published.packageId}::discovery::register_transaction`,
arguments: [tx.object(squidObjectId), tx.object(chain.contracts.ITS.objects.ITS), tx.object(relayerDiscovery)],
});

const registerTx = await broadcast(client, keypair, tx);

printInfo('Register transaction', registerTx.digest);
}

async function deploy(keypair, client, supportedContract, config, chain, options) {
const { packageDir, packageName } = supportedContract;

Expand Down Expand Up @@ -282,7 +328,6 @@ const GATEWAY_CMD_OPTIONS = [
const addDeployOptions = (program) => {
// Get the package name from the program name
const packageName = program.name();

// Find the corresponding options for the package
const options = PACKAGE_CONFIGS.cmdOptions[packageName]();

Expand Down
4 changes: 2 additions & 2 deletions sui/deploy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { addBaseOptions } = require('./cli-utils');
const { getWallet, printWalletInfo, broadcast } = require('./sign-utils');

// Parse bcs bytes from singleton object to get channel id
async function getChannelId(client, singletonObjectId) {
async function getSingletonChannelId(client, singletonObjectId) {
const bcsBytes = await getBcsBytesByObjectId(client, singletonObjectId);
const data = singletonStruct.parse(bcsBytes);
return '0x' + data.channel.id;
Expand Down Expand Up @@ -45,7 +45,7 @@ async function processCommand(config, chain, options) {

await broadcast(client, keypair, tx);

const channelId = await getChannelId(client, singleton.objectId);
const channelId = await getSingletonChannelId(client, singleton.objectId);

chain.contracts.test.address = published.packageId;
chain.contracts.test.objects = { singleton: singleton.objectId, channelId };
Expand Down
44 changes: 38 additions & 6 deletions sui/types-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,45 @@ const discoveryStruct = bcs.struct('Discovery', {
fields: discoveryTable,
});

const bagStruct = bcs.struct('Bags', {
id: UID,
size: bcs.u64(),
const bagStruct = bcs.struct('Bag', {
id: UID,
size: bcs.U64,
});

const operatorsStruct = bcs.struct('Operators', {
id: UID,
operators: bcs.vector(addressStruct),
caps: bagStruct,
id: UID,
operators: bcs.vector(addressStruct),
caps: bagStruct,
});

const tableStruct = bcs.struct('Table', {
id: UID,
size: bcs.U64,
});

const interchainAddressTrackerStruct = bcs.struct('InterchainAddressTracker', {
trusted_addresses: tableStruct,
});

const itsStruct = bcs.struct('ITS', {
id: UID,
channel: channelStruct,
address_tracker: interchainAddressTrackerStruct,
unregistered_coin_types: tableStruct,
unregistered_coin_info: bagStruct,
registered_coin_types: tableStruct,
registered_coins: bagStruct,
relayer_discovery_id: UID,
});

const coinBagStrcut = bcs.struct('CoinBag', {
bag: bagStruct,
});

const squidStruct = bcs.struct('Squid', {
id: UID,
channel: channelStruct,
coin_bag: coinBagStrcut,
});

module.exports = {
Expand All @@ -108,4 +138,6 @@ module.exports = {
channelStruct,
singletonStruct,
discoveryStruct,
itsStruct,
squidStruct,
};
20 changes: 17 additions & 3 deletions sui/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const fs = require('fs');
const { fromB64 } = require('@mysten/bcs');
const { CosmWasmClient } = require('@cosmjs/cosmwasm-stargate');
const { updateMoveToml, copyMovePackage, TxBuilder } = require('@axelar-network/axelar-cgp-sui');
const { singletonStruct } = require('./types-utils');
const { singletonStruct, itsStruct, squidStruct } = require('./types-utils');

const suiPackageAddress = '0x2';
const suiClockAddress = '0x6';
Expand Down Expand Up @@ -97,12 +97,24 @@ const getObjectIdsByObjectTypes = (txn, objectTypes) =>
});

// Parse bcs bytes from singleton object which is created when the Test contract is deployed
const getChannelId = async (client, singletonObjectId) => {
const getSingletonChannelId = async (client, singletonObjectId) => {
const bcsBytes = await getBcsBytesByObjectId(client, singletonObjectId);
const data = singletonStruct.parse(bcsBytes);
return '0x' + data.channel.id;
};

const getItsChannelId = async (client, itsObjectId) => {
const bcsBytes = await getBcsBytesByObjectId(client, itsObjectId);
const data = itsStruct.parse(bcsBytes);
return '0x' + data.channel.id;
};

const getSquidChannelId = async (client, squidObjectId) => {
const bcsBytes = await getBcsBytesByObjectId(client, squidObjectId);
const data = squidStruct.parse(bcsBytes);
return '0x' + data.channel.id;
};

const getSigners = async (keypair, config, chain, options) => {
if (options.signers === 'wallet') {
const pubKey = keypair.getPublicKey().toRawBytes();
Expand Down Expand Up @@ -142,6 +154,8 @@ module.exports = {
findPublishedObject,
readMovePackageName,
getObjectIdsByObjectTypes,
getChannelId,
getSingletonChannelId,
getItsChannelId,
getSquidChannelId,
getSigners,
};

0 comments on commit 144d15a

Please sign in to comment.