From ea6bea38f4a40dc46d71af33f17c6201b59b484b Mon Sep 17 00:00:00 2001 From: npty <78221556+npty@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:55:37 +0700 Subject: [PATCH] feat(sui): add command to remove trusted address on sui (#461) Co-authored-by: Blockchain Guy --- sui/README.md | 20 ++++++++++++++++++++ sui/its.js | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/sui/README.md b/sui/README.md index 9d31c1ef..d5c30704 100644 --- a/sui/README.md +++ b/sui/README.md @@ -366,6 +366,26 @@ Note: - If coin type is not provided, it will split all the coins. - If transfer address is not provided, it will split the coins in the same wallet. Otherwise, it will transfer the splitted coins to the provided address. +## Setup Trusted Addresses + +Add trusted address + +```bash +node sui/its.js setup-trusted-address ,,... +``` + +or Add all evm chains that have ITS contract deployed + +```bash +node sui/its.js setup-trusted-address all-evm +``` + +Remove trusted address + +```bash +node sui/its.js remove-trusted-address ,,... +``` + ## Examples - [GMP Example Guide](docs/gmp.md) diff --git a/sui/its.js b/sui/its.js index a73fe880..f69838d4 100644 --- a/sui/its.js +++ b/sui/its.js @@ -57,6 +57,35 @@ async function setupTrustedAddress(keypair, client, config, contracts, args, opt } } +async function removeTrustedAddress(keypair, client, contracts, args, options) { + const [trustedChain] = args; + + const trustedAddressesObject = contracts.ITS.trustedAddresses; + + if (!trustedAddressesObject) throw new Error('No trusted addresses found'); + + const chainNames = trustedChain.split(','); + + if (chainNames.length === 0) throw new Error('No chain names provided'); + + const txBuilder = new TxBuilder(client); + + for (const chainName of chainNames) { + if (!trustedAddressesObject[chainName]) throw new Error(`No trusted addresses found for chain ${trustedChain}`); + } + + await txBuilder.moveCall({ + target: `${contracts.ITS.address}::its::remove_trusted_addresses`, + arguments: [contracts.ITS.objects.ITS, contracts.ITS.objects.OwnerCap, chainNames], + }); + + for (const chainName of chainNames) { + delete contracts.ITS.trustedAddresses[chainName]; + } + + await broadcastFromTxBuilder(txBuilder, keypair, 'Remove Trusted Address'); +} + async function processCommand(command, config, chain, args, options) { const [keypair, client] = getWallet(chain, options); @@ -74,7 +103,7 @@ async function mainProcessor(command, options, args, processor) { if (require.main === module) { const program = new Command(); - program.name('ITS ').description('SUI ITS scripts'); + program.name('ITS').description('SUI ITS scripts'); // This command is used to setup the trusted address on the ITS contract. // The trusted address is used to verify the message from the source chain. @@ -88,7 +117,16 @@ if (require.main === module) { mainProcessor(setupTrustedAddress, options, [trustedChain, trustedAddress], processCommand); }); + const removeTrustedAddressProgram = new Command() + .name('remove-trusted-address') + .description('Remove trusted address') + .command('remove-trusted-address ') + .action((trustedChain, options) => { + mainProcessor(removeTrustedAddress, options, [trustedChain], processCommand); + }); + program.addCommand(setupTrustedAddressProgram); + program.addCommand(removeTrustedAddressProgram); addOptionsToCommands(program, addBaseOptions, { offline: true });