Skip to content

Commit

Permalink
feat(sui): add command to remove trusted address on sui (#461)
Browse files Browse the repository at this point in the history
Co-authored-by: Blockchain Guy <[email protected]>
  • Loading branch information
npty and blockchainguyy authored Dec 9, 2024
1 parent 181e8b1 commit ea6bea3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
20 changes: 20 additions & 0 deletions sui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sourceChain>,<sourceChain2>,... <sourceAddress>
```

or Add all evm chains that have ITS contract deployed

```bash
node sui/its.js setup-trusted-address all-evm <sourceAddress>
```

Remove trusted address

```bash
node sui/its.js remove-trusted-address <sourceChain>,<sourceChain2>,...
```

## Examples

- [GMP Example Guide](docs/gmp.md)
Expand Down
40 changes: 39 additions & 1 deletion sui/its.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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.
Expand All @@ -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 <trusted-chain>')
.action((trustedChain, options) => {
mainProcessor(removeTrustedAddress, options, [trustedChain], processCommand);
});

program.addCommand(setupTrustedAddressProgram);
program.addCommand(removeTrustedAddressProgram);

addOptionsToCommands(program, addBaseOptions, { offline: true });

Expand Down

0 comments on commit ea6bea3

Please sign in to comment.