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: flow limits as operator #468

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 11 additions & 6 deletions sui/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -251,6 +255,7 @@ async function postDeployIts(published, keypair, client, config, chain, options)
ITSv0: itsv0ObjectId,
ChannelId: channelId,
OwnerCap: ownerCapObjectId,
OperatorCap: operatorCapId,
UpgradeCap: upgradeCapObjectId,
};

Expand Down
50 changes: 50 additions & 0 deletions sui/its.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,47 @@ function parseTrustedChains(config, trustedChain) {
return trustedChain.split(',');
}

async function setFlowLimits(keypair, client, config, contracts, args, options) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a test for set/unset test-sui.yaml for coverage. you'll need to use a snapshot release temporarily

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('<token-ids>, <coin-types> and <flow-limits> 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;

Expand Down Expand Up @@ -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 <token-ids> <coin-types> <flow-limits>')
.description(`Set flow limits for multiple tokens. <token-ids>, <coin-types> and <flow-limits> 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 });

Expand Down
Loading