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): add command to remove trusted address on sui #461

Merged
merged 8 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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()
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading