From bb95a6b0256a236988623c454a879282b5b06159 Mon Sep 17 00:00:00 2001 From: Foivos Date: Mon, 9 Dec 2024 19:06:32 +0200 Subject: [PATCH 1/4] Added support for operator and setting flow limits to sui its --- sui/deploy-contract.js | 11 ++++++-- sui/its.js | 57 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/sui/deploy-contract.js b/sui/deploy-contract.js index 9a3d853a..ab1f58ed 100644 --- a/sui/deploy-contract.js +++ b/sui/deploy-contract.js @@ -235,15 +235,22 @@ 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] = getObjectIdsByObjectTypes(published.publishTxn, [ + const [itsObjectId, itsv0ObjectId, ownerCapObjectId, operatorCapId] = getObjectIdsByObjectTypes(published.publishTxn, [ `${published.packageId}::its::ITS`, `${published.packageId}::its_v0::ITS_v0`, `${published.packageId}::owner_cap::OwnerCap`, + `${published.packageId}::operator_cap::OperatorCap`, ]); const channelId = await getItsChannelId(client, itsv0ObjectId); - chain.contracts.ITS.objects = { ITS: itsObjectId, ITSv0: itsv0ObjectId, ChannelId: channelId, OwnerCap: ownerCapObjectId }; + chain.contracts.ITS.objects = { + ITS: itsObjectId, + ITSv0: itsv0ObjectId, + ChannelId: channelId, + OwnerCap: ownerCapObjectId, + OperatorCap: operatorCapId, + }; const tx = new Transaction(); tx.moveCall({ diff --git a/sui/its.js b/sui/its.js index f69838d4..3ba75164 100644 --- a/sui/its.js +++ b/sui/its.js @@ -18,6 +18,54 @@ function parseTrustedChains(config, trustedChain) { return trustedChain.split(','); } +async function setFlowLimits(keypair, client, config, contracts, args, options) { + let [tokenIds, coinTypes, flowLimits ] = args; + + const { ITS: itsConfig } = contracts; + + const { OperatorCap, ITS } = itsConfig.objects; + + const txBuilder = new TxBuilder(client); + + tokenIds = tokenIds.split(','); + coinTypes = coinTypes.split(','); + flowLimits = flowLimits.split(',').map((flowLimit) => { + return Number(flowLimit); + }); + + if (tokenIds.length != flowLimits.length || tokenIds.length != coinTypes.length) throw new Error(', and have to have the same length.'); + + for (const i in tokenIds) { + const tokenId = await txBuilder.moveCall({ + target: `${itsConfig.address}::token_id::from_address`, + arguments: [tokenIds[i]], + }); + + await txBuilder.moveCall({ + target: `${itsConfig.address}::its::set_flow_limit_as_operator`, + arguments: [ITS, OperatorCap, tokenId, flowLimits[i]], + typeArguments: [coinTypes[i]], + }); + } + + if (options.offline) { + const tx = txBuilder.tx; + const sender = options.sender || keypair.toSuiAddress(); + tx.setSender(sender); + await saveGeneratedTx(tx, `Set trusted address for ${trustedChain} to ${trustedAddress}`, client, options); + } else { + await broadcastFromTxBuilder(txBuilder, keypair, 'Setup Trusted Address'); + } + + // Update ITS config + for (const trustedChain of trustedChains) { + // Add trusted address to ITS config + if (!contracts.ITS.trustedAddresses) contracts.ITS.trustedAddresses = {}; + + contracts.ITS.trustedAddresses[trustedChain] = trustedAddress; + } +} + async function setupTrustedAddress(keypair, client, config, contracts, args, options) { const [trustedChain, trustedAddress] = args; @@ -125,8 +173,17 @@ if (require.main === module) { mainProcessor(removeTrustedAddress, options, [trustedChain], processCommand); }); + const setFlowLimitsProgram = new Command() + .name('set-flow-limits') + .command('set-flow-limits ') + .description(`Set flow limits for multiple tokens. , and can both be comma separated lists`) + .action((tokenIds, coinTypes, flowLimits, options) => { + mainProcessor(setFlowLimits, options, [tokenIds, coinTypes, flowLimits], processCommand); + }); + program.addCommand(setupTrustedAddressProgram); program.addCommand(removeTrustedAddressProgram); + program.addCommand(setFlowLimitsProgram); addOptionsToCommands(program, addBaseOptions, { offline: true }); From 8ca2b12d33ebfc9491565d1ba9a33c292b1bba89 Mon Sep 17 00:00:00 2001 From: Foivos Date: Mon, 9 Dec 2024 19:08:19 +0200 Subject: [PATCH 2/4] made lint happy --- sui/its.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/sui/its.js b/sui/its.js index 3ba75164..37d7e3b5 100644 --- a/sui/its.js +++ b/sui/its.js @@ -19,7 +19,7 @@ function parseTrustedChains(config, trustedChain) { } async function setFlowLimits(keypair, client, config, contracts, args, options) { - let [tokenIds, coinTypes, flowLimits ] = args; + let [tokenIds, coinTypes, flowLimits] = args; const { ITS: itsConfig } = contracts; @@ -33,7 +33,8 @@ async function setFlowLimits(keypair, client, config, contracts, args, options) return Number(flowLimit); }); - if (tokenIds.length != flowLimits.length || tokenIds.length != coinTypes.length) throw new Error(', and have to have the same length.'); + if (tokenIds.length !== flowLimits.length || tokenIds.length !== coinTypes.length) + throw new Error(', and have to have the same length.'); for (const i in tokenIds) { const tokenId = await txBuilder.moveCall({ @@ -52,18 +53,10 @@ async function setFlowLimits(keypair, client, config, contracts, args, options) const tx = txBuilder.tx; const sender = options.sender || keypair.toSuiAddress(); tx.setSender(sender); - await saveGeneratedTx(tx, `Set trusted address for ${trustedChain} to ${trustedAddress}`, client, options); + await saveGeneratedTx(tx, `Set flow limits for ${tokenIds} to ${flowLimits}`, client, options); } else { await broadcastFromTxBuilder(txBuilder, keypair, 'Setup Trusted Address'); } - - // Update ITS config - for (const trustedChain of trustedChains) { - // Add trusted address to ITS config - if (!contracts.ITS.trustedAddresses) contracts.ITS.trustedAddresses = {}; - - contracts.ITS.trustedAddresses[trustedChain] = trustedAddress; - } } async function setupTrustedAddress(keypair, client, config, contracts, args, options) { From 06e924dd9b78e57859f5676e4971cf9458d6c995 Mon Sep 17 00:00:00 2001 From: Foivos Date: Tue, 17 Dec 2024 15:00:19 +0200 Subject: [PATCH 3/4] fix a small bug --- sui/deploy-contract.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sui/deploy-contract.js b/sui/deploy-contract.js index af215c59..0ebaa78f 100644 --- a/sui/deploy-contract.js +++ b/sui/deploy-contract.js @@ -237,7 +237,7 @@ 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, [ + const [itsObjectId, itsv0ObjectId, ownerCapObjectId, operatorCapId, upgradeCapObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [ `${published.packageId}::its::ITS`, `${published.packageId}::its_v0::ITS_v0`, `${published.packageId}::owner_cap::OwnerCap`, From 8f6da851d79412e288d4e961c791aa45d2c8345e Mon Sep 17 00:00:00 2001 From: Foivos Date: Tue, 17 Dec 2024 15:00:33 +0200 Subject: [PATCH 4/4] prettier --- sui/deploy-contract.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/sui/deploy-contract.js b/sui/deploy-contract.js index 0ebaa78f..cac1d767 100644 --- a/sui/deploy-contract.js +++ b/sui/deploy-contract.js @@ -237,13 +237,16 @@ 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, operatorCapId, upgradeCapObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [ - `${published.packageId}::its::ITS`, - `${published.packageId}::its_v0::ITS_v0`, - `${published.packageId}::owner_cap::OwnerCap`, - `${published.packageId}::operator_cap::OperatorCap`, - `${suiPackageAddress}::package::UpgradeCap`, - ]); + const [itsObjectId, itsv0ObjectId, ownerCapObjectId, operatorCapId, upgradeCapObjectId] = getObjectIdsByObjectTypes( + published.publishTxn, + [ + `${published.packageId}::its::ITS`, + `${published.packageId}::its_v0::ITS_v0`, + `${published.packageId}::owner_cap::OwnerCap`, + `${published.packageId}::operator_cap::OperatorCap`, + `${suiPackageAddress}::package::UpgradeCap`, + ], + ); const channelId = await getItsChannelId(client, itsv0ObjectId);