Skip to content

Commit

Permalink
chore: add more structs (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
npty authored Sep 2, 2024
1 parent 26a618f commit ed0e5d0
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-penguins-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axelar-network/axelar-cgp-sui': patch
---

chore: add more structs
125 changes: 118 additions & 7 deletions src/bcs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
import { bcs } from '@mysten/sui/bcs';
import { UID } from './types';

function getAxelarStructs() {
function getCommonStructs() {
const Bytes32 = bcs.Address;

const Channel = bcs.struct('Channel', {
id: UID,
});

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

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

const DiscoveryTable = bcs.struct('DiscoveryTable', {
id: UID,
});

const Discovery = bcs.struct('Discovery', {
id: UID,
fields: DiscoveryTable,
});

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

return {
Bytes32,
Channel,
Bag,
CoinBag,
DiscoveryTable,
Discovery,
Table,
};
}

function getGatewayStructs() {
const { Bytes32, Bag } = getCommonStructs();

const Message = bcs.struct('Message', {
source_chain: bcs.String,
message_id: bcs.String,
Expand Down Expand Up @@ -64,17 +105,25 @@ function getAxelarStructs() {
data: bcs.vector(bcs.U8),
});

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

const Operators = bcs.struct('Operators', {
id: UID,
operators: bcs.vector(bcs.Address),
caps: Bag,
});

const ExecuteData = bcs.struct('ExecuteData', {
payload: bcs.vector(bcs.U8),
proof: bcs.vector(bcs.U8),
});

const ApprovedMessage = bcs.struct('ApprovedMessage', {
source_chain: bcs.String,
message_id: bcs.String,
source_address: bcs.String,
destination_id: Bytes32,
payload: bcs.vector(bcs.U8),
});

return {
Bytes32,
Message,
Expand All @@ -89,10 +138,14 @@ function getAxelarStructs() {
EncodedMessage,
Bag,
Operators,
ExecuteData,
ApprovedMessage,
};
}

function getSquidStructs() {
const { Channel, CoinBag } = getCommonStructs();

const DeepbookV2SwapData = bcs.struct('DeepbookV2SwapData', {
swap_type: bcs.U8,
pool_id: bcs.Address,
Expand All @@ -119,14 +172,72 @@ function getSquidStructs() {
metadata: bcs.vector(bcs.U8),
});

const Squid = bcs.struct('Squid', {
id: UID,
channel: Channel,
coin_bag: CoinBag,
});

return {
DeepbookV2SwapData,
SuiTransferSwapData,
ItsTransferSwapData,
Squid,
};
}

function getITSStructs() {
const { Table, Bag, Channel } = getCommonStructs();

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

const ITS = bcs.struct('ITS', {
id: UID,
channel: Channel,
address_tracker: InterchainAddressTracker,
unregistered_coin_types: Table,
unregistered_coin_info: Bag,
registered_coin_types: Table,
registered_coins: Bag,
});

return {
InterchainAddressTracker,
ITS,
};
}

function getGMPStructs() {
const { Channel } = getCommonStructs();

const Singleton = bcs.struct('Singleton', {
id: UID,
channel: Channel,
});

return {
Singleton,
};
}

function getGasServiceStructs() {
const GasService = bcs.struct('GasService', {
id: UID,
balance: bcs.U64,
});

return {
GasService,
};
}

export const bcsStructs = {
gateway: getAxelarStructs(),
common: getCommonStructs(),
gateway: getGatewayStructs(),
squid: getSquidStructs(),
gmp: getGMPStructs(),
gasService: getGasServiceStructs(),
its: getITSStructs(),
};
9 changes: 9 additions & 0 deletions src/tx-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,15 @@ export class TxBuilder {
},
});

await this.client.waitForTransaction({
digest: result.digest,
options: {
showEffects: true,
showObjectChanges: true,
...options,
},
});

if (!result.confirmedLocalExecution) {
while (true) {
try {
Expand Down

0 comments on commit ed0e5d0

Please sign in to comment.