Skip to content

Commit

Permalink
feat: remove hardcoded addresses (#81)
Browse files Browse the repository at this point in the history
Co-authored-by: npty <[email protected]>
  • Loading branch information
Foivos and npty authored Jul 19, 2024
1 parent e685221 commit 5c829ce
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-hairs-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@axelar-network/axelar-cgp-sui': patch
---

Remove all hardcoded addresses
4 changes: 2 additions & 2 deletions move/abi/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "134C22A16B63D227C88D4E1F5D02607C8E7C2D0FA5D3BAD6136E0041F441654D"
manifest_digest = "19FE4545AB614FCF65345A44D24FFA04796A02BF83A93E4B0C440B1DC07D8017"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
Expand All @@ -21,6 +21,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.25.1"
compiler-version = "1.26.1"
edition = "2024.beta"
flavor = "sui"
3 changes: 1 addition & 2 deletions move/abi/Move.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[package]
name = "Abi"
version = "0.1.0"
published-at = "0x41fb7e9c9d8851ecbfd4b89c910c0465de0cd0cf757c4bb261a8a6019ea33390"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.25.3" }

[addresses]
abi = "0x0"
abi = "0xa0"
4 changes: 2 additions & 2 deletions move/axelar_gateway/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "10303CE6C59BAA2CE814E3D11BACC8CB24BE0F8D66753B02190E291CA40F0D39"
manifest_digest = "E2AF940D04A66ED5B6A13F4003C5DBD4D76854BB80FA560E428FBD926E6154A8"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
Expand All @@ -21,6 +21,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.25.1"
compiler-version = "1.26.1"
edition = "2024.beta"
flavor = "sui"
3 changes: 1 addition & 2 deletions move/axelar_gateway/Move.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[package]
name = "AxelarGateway"
version = "0.1.0"
published-at = "0x0"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.25.3" }

[addresses]
axelar_gateway = "0x0"
axelar_gateway = "0xa1"
clock = "0x6"
4 changes: 2 additions & 2 deletions move/gas_service/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "087A028093BEA5B33AB826F8CFE6D5B029A93CC7ACFE21C55F92BE7AA4500D07"
manifest_digest = "2BF1B7ACF4C8013E173E1C6DE00772466CF18C53F518ED3802CEF10C4F8BE818"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
Expand All @@ -21,6 +21,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.25.1"
compiler-version = "1.26.1"
edition = "2024.beta"
flavor = "sui"
3 changes: 1 addition & 2 deletions move/gas_service/Move.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[package]
name = "GasService"
version = "0.1.0"
published-at = "0x9249adc3fac09edb21a0848af2ccf4901ffb3689124bc91d67bc613903ca643c"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.25.3" }

[addresses]
gas_service = "0x9249adc3fac09edb21a0848af2ccf4901ffb3689124bc91d67bc613903ca643c"
gas_service = "0xa2"
4 changes: 2 additions & 2 deletions move/governance/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "DDE122A0D708826C620F1612EA66CF667DC100950E4572CE1B5D769914214352"
manifest_digest = "6167F2C716EC29F35ABF270163CC4B2DBEB631D4E9FF3BFB095F50D0E6471877"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"
dependencies = [
{ name = "Abi" },
Expand Down Expand Up @@ -39,6 +39,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.25.1"
compiler-version = "1.26.1"
edition = "2024.beta"
flavor = "sui"
3 changes: 1 addition & 2 deletions move/governance/Move.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "Governance"
version = "0.1.0"
published-at = "0x0cba440261d721bde9c85eafe18aae673ee72702fa95da567675b34224f5ad77"
edition = "2024.beta"

[dependencies]
Expand All @@ -10,4 +9,4 @@ AxelarGateway = { local = "../axelar_gateway" }
Abi = { local = "../abi" }

[addresses]
governance = "0x0cba440261d721bde9c85eafe18aae673ee72702fa95da567675b34224f5ad77"
governance = "0xa3"
4 changes: 2 additions & 2 deletions move/interchain_token/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "DD779F8BB7EFE326F7F6ECEA9DB375E63D53DF5DBD30BF2C6230241EBE1E6B2B"
manifest_digest = "86DAD8A24989FCCBA0BC09AB6FEAC6989936D441B0FCAC6F34FF30F628D99568"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
Expand All @@ -21,6 +21,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.25.1"
compiler-version = "1.26.1"
edition = "2024.beta"
flavor = "sui"
2 changes: 1 addition & 1 deletion move/interchain_token/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2024.beta"
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.25.3" }

[addresses]
interchain_token = "0x106"
interchain_token = "0xa8"
4 changes: 2 additions & 2 deletions move/its/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "1147666C677721F15D3F7BBBFAEBB42A77A1E40BADAC55CF5299A610C616C456"
manifest_digest = "104242E093ACB27B26904E67D50349D053577B8949543643EC53F981A867C8A6"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"
dependencies = [
{ name = "AxelarGateway" },
Expand Down Expand Up @@ -49,6 +49,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.25.1"
compiler-version = "1.26.1"
edition = "2024.beta"
flavor = "sui"
3 changes: 1 addition & 2 deletions move/its/Move.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "ITS"
version = "0.1.0"
published-at = "0x89967fea5cc3bdf2d44cabe901aca920aa2a0485ca9a479f9932814c55d5f9b3"
edition = "2024.beta"

[dependencies]
Expand All @@ -10,4 +9,4 @@ AxelarGateway = { local = "../axelar_gateway" }
Governance = { local = "../governance" }

[addresses]
its = "0x89967fea5cc3bdf2d44cabe901aca920aa2a0485ca9a479f9932814c55d5f9b3"
its = "0xa5"
4 changes: 2 additions & 2 deletions move/operators/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "F3843E711A5044D1CF9708AF5AA3CEC7EDA8C17E39065DE7ACBC14C91B9C3B24"
manifest_digest = "5A75F2D3BB5ACF74D39EB64EC32CEF718BF194284655952239D08141E9B07974"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ name = "Sui" },
Expand All @@ -21,6 +21,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.25.1"
compiler-version = "1.26.1"
edition = "2024.beta"
flavor = "sui"
2 changes: 1 addition & 1 deletion move/operators/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2024.beta"
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.25.3" }

[addresses]
operators = "0x107"
operators = "0xa4"
4 changes: 2 additions & 2 deletions move/squid/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "F04564A9B03EECFDBF7CA6366332C84FE6CD5664BA92120778113C63A95FFC65"
manifest_digest = "33DD4E0212DFE5613CBD68D9AD07266CF4A7DCAD5B99E0E57517C04C6E2A3B00"
deps_digest = "F9B494B64F0615AED0E98FC12A85B85ECD2BC5185C22D30E7F67786BB52E507C"
dependencies = [
{ name = "AxelarGateway" },
Expand Down Expand Up @@ -69,6 +69,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.25.1"
compiler-version = "1.26.1"
edition = "2024.beta"
flavor = "sui"
3 changes: 1 addition & 2 deletions move/squid/Move.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[package]
name = "Squid"
version = "0.1.0"
published-at = "0x742acc52f94b86d3a2a4fdc39b1e0d75812f05253f88443754326c1e31cae873"
edition = "2024.beta"

[dependencies]
Expand All @@ -11,4 +10,4 @@ AxelarGateway = { local = "../axelar_gateway" }
ITS = { local = "../its" }

[addresses]
squid = "0x742acc52f94b86d3a2a4fdc39b1e0d75812f05253f88443754326c1e31cae873"
squid = "0xa6"
4 changes: 2 additions & 2 deletions move/test/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 2
manifest_digest = "E39FD071E9EFD0729A4D15C389E9E5EF831FB1E0DB9B2A6E35AFD0DC302863A1"
manifest_digest = "9B4503E476069F069DBE725F008DC72F1E49917F879CD84B54B8D3C38C2EFB72"
deps_digest = "3C4103934B1E040BB6B23F1D610B4EF9F2F1166A50A104EADCF77467C004C600"
dependencies = [
{ name = "AxelarGateway" },
Expand Down Expand Up @@ -30,6 +30,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.25.1"
compiler-version = "1.26.1"
edition = "2024.beta"
flavor = "sui"
3 changes: 1 addition & 2 deletions move/test/Move.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
[package]
name = "Test"
version = "0.1.0"
published-at = "0x5de4d52cd17c6e0483598bebb3243a886edefeb216e5ecc7c578edfeb8a7b4a9"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "mainnet-v1.25.3" }
AxelarGateway = { local = "../axelar_gateway" }

[addresses]
test = "0x5de4d52cd17c6e0483598bebb3243a886edefeb216e5ecc7c578edfeb8a7b4a9"
test = "0xa9"
9 changes: 6 additions & 3 deletions scripts/tx-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const {
utils: { arrayify, hexlify },
} = require('ethers');

const stdPackage = '0x1';
const suiPackage = '0x2';

function getObject(tx, object) {
if (Array.isArray(object)) {
object = hexlify(object);
Expand Down Expand Up @@ -115,7 +118,7 @@ function isTxContext(parameter) {
if (!parameter) return false;
parameter = parameter.Struct;
if (!parameter) return false;
return parameter.address === '0x2' && parameter.module === 'tx_context' && parameter.name === 'TxContext';
return parameter.address === suiPackage && parameter.module === 'tx_context' && parameter.name === 'TxContext';
}

function isString(parameter) {
Expand All @@ -127,8 +130,8 @@ function isString(parameter) {

if (!parameter) return false;

const isAsciiString = parameter.address === '0x1' && parameter.module === 'ascii' && parameter.name === 'String';
const isStringString = parameter.address === '0x1' && parameter.module === 'string' && parameter.name === 'String';
const isAsciiString = parameter.address === stdPackage && parameter.module === 'ascii' && parameter.name === 'String';
const isStringString = parameter.address === stdPackage && parameter.module === 'string' && parameter.name === 'String';

return isAsciiString || isStringString;
}
Expand Down
12 changes: 8 additions & 4 deletions src/tx-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { Bytes, utils as ethersUtils } from 'ethers';
import tmp from 'tmp';
import { updateMoveToml } from './utils';

const stdPackage = '0x1';
const suiPackage = '0x2';

const { arrayify, hexlify } = ethersUtils;

const objectCache = {} as { [id in string]: SuiObjectChange };
Expand Down Expand Up @@ -179,7 +182,7 @@ function isTxContext(parameter: SuiMoveNormalizedType): boolean {
return false;
}

return inside.address === '0x2' && inside.module === 'tx_context' && inside.name === 'TxContext';
return inside.address === suiPackage && inside.module === 'tx_context' && inside.name === 'TxContext';
}

function isString(parameter: SuiMoveNormalizedType): boolean {
Expand All @@ -189,8 +192,8 @@ function isString(parameter: SuiMoveNormalizedType): boolean {
if (asAny.Reference) asAny = asAny.Reference;
asAny = asAny.Struct;
if (!asAny) return false;
const isAsciiString = asAny.address === '0x1' && asAny.module === 'ascii' && asAny.name === 'String';
const isStringString = asAny.address === '0x1' && asAny.module === 'string' && asAny.name === 'String';
const isAsciiString = asAny.address === stdPackage && asAny.module === 'ascii' && asAny.name === 'String';
const isStringString = asAny.address === stdPackage && asAny.module === 'string' && asAny.name === 'String';
return isAsciiString || isStringString;
}

Expand Down Expand Up @@ -247,7 +250,8 @@ export class TxBuilder {
packageName: string,
moveDir: string = `${__dirname}/../move`,
): Promise<{ modules: string[]; dependencies: string[]; digest: Bytes }> {
updateMoveToml(packageName, '0x0', moveDir);
const emptyPackageId = '0x0';
updateMoveToml(packageName, emptyPackageId, moveDir);

tmp.setGracefulCleanup();

Expand Down
7 changes: 4 additions & 3 deletions test/axelar-gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const { arrayify, hexlify, keccak256 } = require('ethers/lib/utils');
const secp256k1 = require('secp256k1');

const COMMAND_TYPE_ROTATE_SIGNERS = 1;
const clock = '0x6';

describe('Axelar Gateway', () => {
let client;
Expand Down Expand Up @@ -114,7 +115,7 @@ describe('Axelar Gateway', () => {
minimumRotationDelay,
previousSignersRetention,
encodedSigners,
'0x6',
clock,
],
});

Expand Down Expand Up @@ -150,7 +151,7 @@ describe('Axelar Gateway', () => {

await builder.moveCall({
target: `${packageId}::gateway::rotate_signers`,
arguments: [gateway, '0x6', encodedSigners, encodedProof],
arguments: [gateway, clock, encodedSigners, encodedProof],
});

await builder.signAndExecute(keypair);
Expand Down Expand Up @@ -185,7 +186,7 @@ describe('Axelar Gateway', () => {

await builder.moveCall({
target: `${packageId}::gateway::rotate_signers`,
arguments: [gateway, '0x6', encodedSigners, encodedProof],
arguments: [gateway, clock, encodedSigners, encodedProof],
});

await expectRevert(builder, keypair, {
Expand Down

0 comments on commit 5c829ce

Please sign in to comment.