diff --git a/sui/deploy-contract.js b/sui/deploy-contract.js index 1e261577..cac1d767 100644 --- a/sui/deploy-contract.js +++ b/sui/deploy-contract.js @@ -237,12 +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, upgradeCapObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [ - `${published.packageId}::its::ITS`, - `${published.packageId}::its_v0::ITS_v0`, - `${published.packageId}::owner_cap::OwnerCap`, - `${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); @@ -251,6 +255,7 @@ async function postDeployIts(published, keypair, client, config, chain, options) ITSv0: itsv0ObjectId, ChannelId: channelId, OwnerCap: ownerCapObjectId, + OperatorCap: operatorCapId, UpgradeCap: upgradeCapObjectId, }; diff --git a/sui/its.js b/sui/its.js index f69838d4..37d7e3b5 100644 --- a/sui/its.js +++ b/sui/its.js @@ -18,6 +18,47 @@ 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 flow limits for ${tokenIds} to ${flowLimits}`, client, options); + } else { + await broadcastFromTxBuilder(txBuilder, keypair, 'Setup Trusted Address'); + } +} + async function setupTrustedAddress(keypair, client, config, contracts, args, options) { const [trustedChain, trustedAddress] = args; @@ -125,8 +166,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 });