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): flow limits as operator #468

Merged
merged 98 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
bb95a6b
Added support for operator and setting flow limits to sui its
Foivos Dec 9, 2024
8ca2b12
made lint happy
Foivos Dec 9, 2024
7a273ac
Merge remote-tracking branch 'origin/main' into feat/flow-limits
Foivos Dec 17, 2024
06e924d
fix a small bug
Foivos Dec 17, 2024
8f6da85
prettier
Foivos Dec 17, 2024
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
d1e4c82
Merge remote-tracking branch 'origin/main' into feat/flow-limits
Foivos Feb 4, 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
e55078a
Merge branch 'feat/sui-pause' into feat/flow-limits
Foivos Feb 6, 2025
a8df272
fixed script
Foivos Feb 6, 2025
3983cb6
made lint happy and fixed tests
Foivos Feb 6, 2025
a429480
fix small type
Foivos Feb 6, 2025
25fa39b
fix tests
Foivos Feb 6, 2025
00ce234
Merge remote-tracking branch 'origin/main' into feat/flow-limits
Foivos Feb 7, 2025
7e33a33
Merge branch 'main' into feat/flow-limits
milapsheth Feb 11, 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
7 changes: 7 additions & 0 deletions .github/workflows/test-sui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,16 @@ jobs:

echo "transferPayloadHash=$(echo $transferInfo | jq -r .payloadHash)" >> $GITHUB_ENV
echo "transferPayload=$(echo $transferInfo | jq -r .payload)" >> $GITHUB_ENV
echo "originTokenId=$(echo $transferInfo | jq -r .tokenId)" >> $GITHUB_ENV
echo "deployPayload=$(echo $deploymentInfo | jq -r .payload)" >> $GITHUB_ENV
echo "deployPayloadHash=$(echo $deploymentInfo | jq -r .payloadHash)" >> $GITHUB_ENV

- name: ITS Flow Limit Set
run: node sui/its.js set-flow-limits $originTokenId 0 -y

- name: ITS Flow Limit Remove
run: node sui/its.js set-flow-limits $originTokenId none -y

- name: Setup Trusted Addresses
run: |
node sui/its.js add-trusted-chains $sourceChain
Expand Down
4 changes: 3 additions & 1 deletion sui/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,10 @@ async function postDeployIts(published, keypair, client, config, chain, options)

const itsHubAddress = config.axelar.contracts.InterchainTokenService.address;

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

Expand All @@ -305,6 +306,7 @@ async function postDeployIts(published, keypair, client, config, chain, options)
InterchainTokenServicev0: InterchainTokenServiceV0ObjectId,
ChannelId: channelId,
OwnerCap: ownerCapObjectId,
OperatorCap: operatorCapId,
UpgradeCap: upgradeCapObjectId,
};

Expand Down
79 changes: 78 additions & 1 deletion sui/its.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const { Command } = require('commander');
const { TxBuilder } = require('@axelar-network/axelar-cgp-sui');
const { TxBuilder, STD_PACKAGE_ID } = require('@axelar-network/axelar-cgp-sui');
const { loadConfig, saveConfig, getChainConfig } = require('../common/utils');
const { addBaseOptions, addOptionsToCommands, getWallet, printWalletInfo, broadcastFromTxBuilder, saveGeneratedTx } = require('./utils');
const { bcs } = require('@mysten/sui/bcs');

const SPECIAL_CHAINS_TAGS = {
ALL_EVM: 'all-evm', // All EVM chains that have InterchainTokenService deployed
Expand All @@ -16,6 +17,73 @@ function parseTrustedChains(config, trustedChains) {
return trustedChains;
}

async function setFlowLimits(keypair, client, config, contracts, args, options) {
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
let [tokenIds, flowLimits] = args;

const { InterchainTokenService: itsConfig } = contracts;

const { OperatorCap, InterchainTokenService } = itsConfig.objects;

const txBuilder = new TxBuilder(client);

tokenIds = tokenIds.split(',');
flowLimits = flowLimits.split(',');

if (tokenIds.length !== flowLimits.length) throw new Error('<token-ids> and <flow-limits> have to have the same length.');

for (const i in tokenIds) {
const coinTypeTxBuilder = new TxBuilder(client);
let tokenId = await coinTypeTxBuilder.moveCall({
target: `${itsConfig.address}::token_id::from_address`,
arguments: [tokenIds[i]],
});

await coinTypeTxBuilder.moveCall({
target: `${itsConfig.address}::interchain_token_service::registered_coin_type`,
arguments: [InterchainTokenService, tokenId],
});

const resp = await coinTypeTxBuilder.devInspect(keypair.toSuiAddress());
const coinType = bcs.String.parse(new Uint8Array(resp.results[1].returnValues[0][0]));
Foivos marked this conversation as resolved.
Show resolved Hide resolved

tokenId = await txBuilder.moveCall({
target: `${itsConfig.address}::token_id::from_address`,
arguments: [tokenIds[i]],
});

let flowLimit;

if (flowLimits[i] === 'none') {
flowLimit = await txBuilder.moveCall({
target: `${STD_PACKAGE_ID}::option::none`,
arguments: [],
typeArguments: ['u64'],
});
} else {
flowLimit = await txBuilder.moveCall({
target: `${STD_PACKAGE_ID}::option::some`,
arguments: [txBuilder.tx.pure.u64(Number(flowLimits[i]))],
typeArguments: ['u64'],
});
}

await txBuilder.moveCall({
target: `${itsConfig.address}::interchain_token_service::set_flow_limit`,
arguments: [InterchainTokenService, OperatorCap, tokenId, flowLimit],
typeArguments: [coinType],
});
}

if (options.offline) {
const tx = txBuilder.tx;
const sender = options.sender || keypair.toSuiAddress();
tx.setSender(sender);
await saveGeneratedTx(tx, `Set flow limits for ${tokenIds} to ${flowLimits}`, client, options);
} else {
await broadcastFromTxBuilder(txBuilder, keypair, 'Setup Trusted Address', options);
}
}

async function addTrustedChains(keypair, client, config, contracts, args, options) {
const [trustedChain] = args;

Expand Down Expand Up @@ -102,6 +170,15 @@ if (require.main === module) {
mainProcessor(removeTrustedChain, options, [trustedChains], processCommand);
});

const setFlowLimitsProgram = new Command()
Foivos marked this conversation as resolved.
Show resolved Hide resolved
.name('set-flow-limits')
.command('set-flow-limits <token-ids> <flow-limits>')
.description(`Set flow limits for multiple tokens. <token-ids> and <flow-limits> can both be comma separated lists`)
Foivos marked this conversation as resolved.
Show resolved Hide resolved
.action((tokenIds, flowLimits, options) => {
mainProcessor(setFlowLimits, options, [tokenIds, flowLimits], processCommand);
});

program.addCommand(setFlowLimitsProgram);
program.addCommand(addTrustedChainsProgram);
program.addCommand(removeTrustedChainsProgram);

Expand Down