Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sui)!: add script option to pause sui contracts #519

Merged
merged 90 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
cc0f516
added a script to migrate tokens and moved custom token manager deplo…
Foivos Jan 17, 2025
7ac4625
made lint happy
Foivos Jan 17, 2025
a858b1b
prettier
Foivos Jan 17, 2025
0410347
addressed some comments
Foivos Jan 17, 2025
76946d0
Merge branch 'main' into feat/update-its-scripts
milapsheth Jan 20, 2025
23af473
remove callContractWithInterchainToken
Foivos Jan 20, 2025
4a9a73a
Update evm/its.js
Foivos Jan 20, 2025
744ff63
Merge remote-tracking branch 'origin/main' into feat/update-its-scripts
Foivos Jan 20, 2025
44fff22
add a test for register custom token
Foivos Jan 20, 2025
fbab1c3
try fixing the test
Foivos Jan 20, 2025
aa134ea
install latest its
Foivos Jan 20, 2025
39ec04a
fix deploy remote interchain token
Foivos Jan 20, 2025
1a6fdac
fix a bug
Foivos Jan 20, 2025
db64b2e
add deployRemoteInterchainToken back to the list
Foivos Jan 20, 2025
a5823f5
debug
Foivos Jan 20, 2025
da62165
fix a check
Foivos Jan 20, 2025
855b4dd
prettier
Foivos Jan 20, 2025
5334c58
add flow limit setter/getter
Foivos Jan 20, 2025
d883c84
fix spelling
Foivos Jan 20, 2025
62c6c23
properly handle event
Foivos Jan 20, 2025
d3127cc
stash
Foivos Jan 24, 2025
3d6ea08
Merge remote-tracking branch 'origin/main' into feat/sui-pause
Foivos Jan 24, 2025
f01faa0
Merge branch 'feat/update-its-scripts' into feat/sui-pause
Foivos Jan 24, 2025
30b30b1
update naming, cgp-sui package version should be uptdated after release
Foivos Jan 27, 2025
1e7e97e
Merge remote-tracking branch 'origin/main' into feat/update-its-naming
Foivos Jan 28, 2025
c6a359f
prettier
Foivos Jan 28, 2025
d046a49
hopefully fix tests
Foivos Jan 28, 2025
e512ebf
Merge branch 'feat/update-its-naming' into feat/sui-pause
Foivos Jan 28, 2025
943ca5d
prettier
Foivos Jan 28, 2025
305cec6
remove info file
Foivos Jan 28, 2025
efc7ebd
fix sui test
Foivos Jan 28, 2025
375e068
fix sui test
Foivos Jan 28, 2025
030229a
rename ITS to InterchainTokenService in its-example as well
Foivos Jan 28, 2025
d8a6c2a
some more renaming
Foivos Jan 28, 2025
282d92d
some more renaming again
Foivos Jan 28, 2025
c511953
some renaming went wrong
Foivos Jan 28, 2025
e7c5ec5
prettier
Foivos Jan 28, 2025
89b8547
rename in its.js as well
Foivos Jan 28, 2025
a3e3a50
fix trusted addresses
Foivos Jan 28, 2025
757e6e8
prettier
Foivos Jan 28, 2025
434424b
fix its-example some
Foivos Jan 28, 2025
d074ca1
testing error fails
Foivos Jan 28, 2025
5146813
some more renaming
Foivos Jan 28, 2025
8015250
fixed some tests
Foivos Jan 28, 2025
43789a3
fix source address
Foivos Jan 28, 2025
8047bd0
try more fixes
Foivos Jan 28, 2025
fb26303
try to fix test.yaml again
Foivos Jan 28, 2025
11f69b0
more fixing
Foivos Jan 28, 2025
8a0b1e5
Merge branch 'feat/update-its-naming' into feat/sui-pause
Foivos Jan 28, 2025
7a641be
fix pausing a bit
Foivos Jan 28, 2025
637fa98
Merge branch 'main' into feat/update-its-naming
milapsheth Jan 29, 2025
25d37a7
rename all ITS to InterchainTokenService
Foivos Jan 29, 2025
17de80a
use variables for hub chain name and address
Foivos Jan 29, 2025
3495196
addressed some comments
Foivos Jan 29, 2025
02cfc16
Merge remote-tracking branch 'origin/main' into feat/update-its-naming
Foivos Jan 29, 2025
38e807e
update test-sui
Foivos Jan 29, 2025
ec915aa
update its.js
Foivos Jan 29, 2025
cb76ff4
rename ITS to InterchainTokenSercvice everywhere
Foivos Jan 29, 2025
be6c9e7
prettier
Foivos Jan 29, 2025
2cfbcdf
Merge branch 'feat/update-its-naming' into feat/sui-pause
Foivos Jan 29, 2025
2d1e7f6
fix deploy script
Foivos Jan 29, 2025
42255fd
revert evm changes
Foivos Jan 29, 2025
9c0d83b
fix local.json test
Foivos Jan 29, 2025
235384c
remove trusted address tracking on info
Foivos Jan 29, 2025
82dc686
Merge branch 'feat/update-its-naming' into feat/sui-pause
Foivos Jan 29, 2025
d281992
some comments
Foivos Jan 29, 2025
3af6734
made lint happy
Foivos Jan 29, 2025
5de573e
added a separate script to pause
Foivos Jan 30, 2025
18fb63c
added its as as pausable
Foivos Jan 30, 2025
0e64c48
revernt interchainTokenFactory changes
Foivos Jan 30, 2025
d653c4c
add tests
Foivos Jan 31, 2025
16638c3
some refactoring
Foivos Feb 4, 2025
96368d0
using most recent version
Foivos Feb 4, 2025
721c65b
stash
Foivos Feb 5, 2025
c5d8b4e
added a version option
Foivos Feb 5, 2025
8d3bf31
prettier
Foivos Feb 5, 2025
52eb9df
Merge remote-tracking branch 'origin/main' into feat/sui-pause
Foivos Feb 5, 2025
9ae1275
removed pause and unpause from gateway and its
Foivos Feb 5, 2025
02e8519
Merge remote-tracking branch 'origin/main' into feat/sui-pause
Foivos Feb 5, 2025
8c5e846
lint
Foivos Feb 6, 2025
9367476
Merge remote-tracking branch 'origin/main' into feat/sui-pause
Foivos Feb 6, 2025
5d69f40
update package-json
Foivos Feb 6, 2025
9ef0f56
fix sui tests
Foivos Feb 6, 2025
dc1448c
austoexecute pause/unpause in sui-tests
Foivos Feb 6, 2025
b232974
prettier
Foivos Feb 6, 2025
503d076
Merge branch 'main' into feat/sui-pause
milapsheth Feb 6, 2025
7d7a17f
Update .github/workflows/test-sui.yaml
Foivos Feb 6, 2025
03d8197
addressed some comments
Foivos Feb 6, 2025
604f6ca
Update sui/contract.js
milapsheth Feb 7, 2025
0243f56
Merge branch 'main' into feat/sui-pause
milapsheth Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/test-sui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ jobs:
- name: Deploy ABI
run: node sui/deploy-contract deploy Abi

- name: Deploy ITS
run: node sui/deploy-contract deploy ITS
- name: Deploy InterchainTokenService
run: node sui/deploy-contract deploy InterchainTokenService --itsHubAddress "hub_address"

- name: Deploy Example
run: node sui/deploy-contract deploy Example
Expand Down Expand Up @@ -196,7 +196,7 @@ jobs:
echo "emptyTokenName=Empty" >> $GITHUB_ENV
echo "emptyTokenDecimals=6" >> $GITHUB_ENV
config=$(cat axelar-chains-config/info/local.json)
echo "channelId=$(echo $config | jq -r '.chains.sui.contracts.ITS.objects.ChannelId')" >> $GITHUB_ENV
echo "channelId=$(echo $config | jq -r '.chains.sui.contracts.InterchainTokenService.objects.ChannelId')" >> $GITHUB_ENV
echo "destinationContractAddress=$(echo $config | jq -r '.chains.sui.contracts.Example.objects.ItsChannelId')" >> $GITHUB_ENV

- name: Deploy Test Tokens
Expand All @@ -205,8 +205,8 @@ jobs:
node sui/its-example deploy-token ${{ env.emptyTokenSymbol }} ${{ env.emptyTokenName }} ${{ env.emptyTokenDecimals }}

# Prepare additional parameters for the example:
transferInfo=$(node sui/its-example.js print-receive-transfer ${{ env.symbol }} ${{ env.sourceAddress }} ${{ env.amount }})
deploymentInfo=$(node sui/its-example.js print-receive-deployment ${{ env.emptyTokenName }} ${{ env.emptyTokenSymbol }} ${{ env.emptyTokenDecimals }})
transferInfo=$(node sui/its-example.js print-receive-transfer ${{ env.sourceChain }} ${{ env.symbol }} ${{ env.sourceAddress }} ${{ env.amount }})
deploymentInfo=$(node sui/its-example.js print-receive-deployment ${{ env.sourceChain }} ${{ env.emptyTokenName }} ${{ env.emptyTokenSymbol }} ${{ env.emptyTokenDecimals }})

echo "transferPayloadHash=$(echo $transferInfo | jq -r .payloadHash)" >> $GITHUB_ENV
echo "transferPayload=$(echo $transferInfo | jq -r .payload)" >> $GITHUB_ENV
Expand All @@ -223,17 +223,17 @@ jobs:

- name: Receive Token from another chain
run: |
node sui/gateway.js approve --proof wallet $sourceChain $transferMessageId $sourceAddress $channelId $transferPayloadHash
node sui/its-example receive-token $sourceChain $transferMessageId $sourceAddress $symbol $transferPayload
node sui/gateway.js approve --proof wallet axelar $transferMessageId hub_address $channelId $transferPayloadHash
node sui/its-example receive-token axelar $transferMessageId hub_address $symbol $transferPayload

- name: Send Token Deployment to another chain
run: |
node sui/its-example send-deployment $symbol $sourceChain 0.1 10

- name: Receive Token Deployment from another chain
run: |
node sui/gateway.js approve --proof wallet $sourceChain $deployMessageId $sourceAddress $channelId $deployPayloadHash
node sui/its-example receive-deployment $sourceChain $deployMessageId $sourceAddress $emptyTokenSymbol $deployPayload
node sui/gateway.js approve --proof wallet axelar $deployMessageId hub_address $channelId $deployPayloadHash
node sui/its-example receive-deployment axelar $deployMessageId hub_address $emptyTokenSymbol $deployPayload

###### Command: Operators ######

Expand Down
7 changes: 4 additions & 3 deletions evm/interchainTokenFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,23 @@ async function processCommand(config, chain, options) {
}

case 'registerCustomToken': {
const { tokenAddress, tokenManagerType, operator } = options;
const { tokenAddress, tokenManagerType, operator, gasValue } = options;

const deploymentSalt = getDeploymentSalt(options);

validateParameters({
isValidAddress: { tokenAddress },
isAddress: { operator },
isValidNumber: { tokenManagerType },
isValidNumber: { tokenManagerType, gasValue },
});

const tx = await interchainTokenFactory.registerCustomToken(
deploymentSalt,
tokenAddress,
tokenManagerType,
operator,
gasOptions,
gasValue,
{ value: gasValue, ...gasOptions },
Foivos marked this conversation as resolved.
Show resolved Hide resolved
);
const tokenId = await interchainTokenFactory.linkedTokenId(wallet.address, deploymentSalt);
printInfo('tokenId', tokenId);
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"homepage": "https://github.com/axelarnetwork/axelar-contract-deployments#readme",
"dependencies": {
"@axelar-network/axelar-cgp-solidity": "6.4.0",
"@axelar-network/axelar-cgp-sui": "1.0.3",
"@axelar-network/axelar-cgp-sui": "0.0.0-snapshot.02915b7",
"@axelar-network/axelar-gmp-sdk-solidity": "6.0.4",
"@axelar-network/interchain-token-service": "2.1.0",
"@axelar-network/interchain-token-service": "0.0.0-snapshot.869b412",
Foivos marked this conversation as resolved.
Show resolved Hide resolved
"@cosmjs/cosmwasm-stargate": "^0.32.1",
"@ledgerhq/hw-app-eth": "6.32.2",
"@mysten/ledgerjs-hw-app-sui": "^0.4.1",
Expand Down
49 changes: 35 additions & 14 deletions sui/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const PACKAGE_DIRS = [
'operators',
'abi',
'governance',
'its',
'interchain_token_service',
'squid',
'interchain_token',
];
Expand All @@ -59,14 +59,15 @@ const PACKAGE_DIRS = [
const PACKAGE_CONFIGS = {
cmdOptions: {
AxelarGateway: () => GATEWAY_CMD_OPTIONS,
InterchainTokenService: () => ITS_CMD_OPTIONS,
},
postDeployFunctions: {
AxelarGateway: postDeployAxelarGateway,
RelayerDiscovery: postDeployRelayerDiscovery,
GasService: postDeployGasService,
Example: postDeployExample,
Operators: postDeployOperators,
ITS: postDeployIts,
InterchainTokenService: postDeployIts,
Squid: postDeploySquid,
Utils: postDeployUtils,
},
Expand Down Expand Up @@ -136,8 +137,8 @@ async function postDeployExample(published, keypair, client, config, chain, opti
// GMP Example Params
const [gmpSingletonObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [`${published.packageId}::gmp::Singleton`]);

// ITS Example Params
const itsObjectId = chain.contracts.ITS?.objects?.ITS;
// InterchainTokenService Example Params
const itsObjectId = chain.contracts.InterchainTokenService?.objects?.InterchainTokenService;
const [itsSingletonObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [`${published.packageId}::its::Singleton`]);

const tx = new Transaction();
Expand Down Expand Up @@ -246,27 +247,41 @@ async function postDeployAxelarGateway(published, keypair, client, config, chain
async function postDeployIts(published, keypair, client, config, chain, options) {
const relayerDiscovery = chain.contracts.RelayerDiscovery?.objects?.RelayerDiscovery;

const [itsObjectId, itsv0ObjectId, ownerCapObjectId, upgradeCapObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [
`${published.packageId}::its::ITS`,
`${published.packageId}::its_v0::ITS_v0`,
const { chainName, itsHubAddress } = options;

const [ownerCapObjectId, creatorCapObjectId, upgradeCapObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [
`${published.packageId}::owner_cap::OwnerCap`,
`${published.packageId}::creator_cap::CreatorCap`,
`${suiPackageAddress}::package::UpgradeCap`,
]);

const channelId = await getItsChannelId(client, itsv0ObjectId);
let tx = new Transaction();
tx.moveCall({
target: `${published.packageId}::interchain_token_service::setup`,
arguments: [tx.object(creatorCapObjectId), tx.pure.string(chainName), tx.pure.string(itsHubAddress)],
});

const setupReceipt = await broadcast(client, keypair, tx, 'Setup');

const [InterchainTokenServiceObjectId, InterchainTokenServiceV0ObjectId] = getObjectIdsByObjectTypes(setupReceipt, [
`${published.packageId}::interchain_token_service::InterchainTokenService`,
`${published.packageId}::interchain_token_service_v0::InterchainTokenService_v0`,
]);
await new Promise((resolve) => setTimeout(resolve, 2000));
const channelId = await getItsChannelId(client, InterchainTokenServiceV0ObjectId);

chain.contracts.ITS.objects = {
ITS: itsObjectId,
ITSv0: itsv0ObjectId,
chain.contracts.InterchainTokenService.objects = {
InterchainTokenService: InterchainTokenServiceObjectId,
InterchainTokenServicev0: InterchainTokenServiceV0ObjectId,
ChannelId: channelId,
OwnerCap: ownerCapObjectId,
UpgradeCap: upgradeCapObjectId,
};

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

await broadcast(client, keypair, tx, 'Registered Transaction');
Expand All @@ -285,7 +300,11 @@ async function postDeploySquid(published, keypair, client, config, chain, option
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)],
arguments: [
tx.object(squidObjectId),
tx.object(chain.contracts.InterchainTokenService.objects.InterchainTokenService),
tx.object(relayerDiscovery),
],
});

await broadcast(client, keypair, tx, 'Registered Transaction');
Expand Down Expand Up @@ -404,6 +423,8 @@ const GATEWAY_CMD_OPTIONS = [
new Option('--previousSigners <previousSigners>', 'number of previous signers to retain').default('15'),
];

const ITS_CMD_OPTIONS = [new Option('--itsHubAddress <itsHubAddress>', 'The address of the ITS HUB').env('ITS_HUB_ADDRESS')];

const addDeployOptions = (program) => {
// Get the package name from the program name
const packageName = program.name();
Expand Down
79 changes: 76 additions & 3 deletions sui/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {
constants: { HashZero },
} = ethers;

const { saveConfig, printInfo, loadConfig, getMultisigProof, getChainConfig } = require('../common/utils');
const { saveConfig, printInfo, loadConfig, getMultisigProof, getChainConfig, writeJSON } = require('../common/utils');
const {
addBaseOptions,
addOptionsToCommands,
Expand All @@ -23,6 +23,7 @@ const {
} = require('./utils');
const secp256k1 = require('secp256k1');
const chalk = require('chalk');
const { readJSON } = require(`${__dirname}/../axelar-chains-config`);

const COMMAND_TYPE_APPROVE_MESSAGES = 0;
const COMMAND_TYPE_ROTATE_SIGNERS = 1;
Expand Down Expand Up @@ -153,6 +154,7 @@ async function approve(keypair, client, config, chain, contractConfig, args, opt
const packageId = contractConfig.address;
const [sourceChain, messageId, sourceAddress, destinationId, payloadHash] = args;

console.log([sourceChain, messageId, sourceAddress, destinationId, payloadHash]);
const encodedMessages = bcs
.vector(bcsStructs.gateway.Message)
.serialize([
Expand Down Expand Up @@ -292,7 +294,6 @@ async function allowFunctions(keypair, client, config, chain, contractConfig, ar
if (versions.length !== functionNames.length) throw new Error('Versions and Function Names must have a matching length');

const tx = new Transaction();
console.log(contractConfig.objects);

for (const i in versions) {
tx.moveCall({
Expand Down Expand Up @@ -323,7 +324,6 @@ async function disallowFunctions(keypair, client, config, chain, contractConfig,
if (versions.length !== functionNames.length) throw new Error('Versions and Function Names must have a matching length');

const tx = new Transaction();
console.log(contractConfig.objects);

for (const i in versions) {
tx.moveCall({
Expand Down Expand Up @@ -509,6 +509,65 @@ async function testNewField(value, options) {
console.log(`Set the value to ${value} and it was set to ${returnedValue}.`);
}

async function pause(keypair, client, config, chain, contracts, args, options) {
Foivos marked this conversation as resolved.
Show resolved Hide resolved
const response = await client.getObject({
id: contracts.objects.Gatewayv0,
options: {
showContent: true,
showBcs: true,
},
});
let allowedFunctionsArray = response.data.content.fields.value.fields.version_control.fields.allowed_functions;
Foivos marked this conversation as resolved.
Show resolved Hide resolved
allowedFunctionsArray = allowedFunctionsArray.map((allowedFunctions) => allowedFunctions.fields.contents);

const versionsArg = [];
const allowedFunctionsArg = [];

for (const version in allowedFunctionsArray) {
const allowedFunctions = allowedFunctionsArray[version];
Foivos marked this conversation as resolved.
Show resolved Hide resolved

// Do not dissalow `allow_function` because that locks the gateway forever.
if (Number(version) === allowedFunctionsArray.length - 1) {
const index = allowedFunctions.indexOf('allow_function');
Foivos marked this conversation as resolved.
Show resolved Hide resolved

if (index > -1) {
// only splice array when item is found
allowedFunctions.splice(index, 1); // 2nd parameter means remove one item only
}
}

printInfo(`Functions that will be disallowed for version ${version}`, allowedFunctions);

versionsArg.push(new Array(allowedFunctions.length).fill(version).join());
allowedFunctionsArg.push(allowedFunctions.join());
}

// Write the
writeJSON(
{
versions: versionsArg,
disallowedFunctions: allowedFunctionsArg,
},
`${__dirname}/../axelar-chains-config/info/sui-gateway-allowed-functions-${options.env}.json`,
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
);

return disallowFunctions(keypair, client, config, chain, contracts, [versionsArg.join(), allowedFunctionsArg.join()], options);
}

async function unpause(keypair, client, config, chain, contracts, args, options) {
const dissalowedFunctions = readJSON(`${__dirname}/../axelar-chains-config/info/sui-gateway-allowed-functions-${options.env}.json`);

return allowFunctions(
keypair,
client,
config,
chain,
contracts,
[dissalowedFunctions.versions.join(), dissalowedFunctions.disallowedFunctions.join()],
options,
);
}

async function mainProcessor(processor, args, options) {
const config = loadConfig(options.env);

Expand Down Expand Up @@ -611,6 +670,20 @@ if (require.main === module) {
testNewField(value, options);
});

program
.command('pause')
.description('Pause the gateway')
.action((options) => {
mainProcessor(pause, [], options);
});

program
.command('unpause')
.description('Unpause the gateway')
.action((options) => {
mainProcessor(unpause, [], options);
});

milapsheth marked this conversation as resolved.
Show resolved Hide resolved
addOptionsToCommands(program, addBaseOptions, { offline: true });

program.parse();
Expand Down
Loading
Loading