Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/flow-limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Dec 17, 2024
2 parents 8ca2b12 + 5cb30ff commit 7a273ac
Show file tree
Hide file tree
Showing 10 changed files with 311 additions and 474 deletions.
637 changes: 210 additions & 427 deletions axelar-chains-config/info/stagenet.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion evm/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ async function processCommand(config, chain, options) {

const appContract = new Contract(options.destination, IAxelarExecutable.abi, wallet);

const tx = await appContract.execute(commandId, sourceChain, sourceAddress, payload);
const tx = await appContract.execute(commandId, sourceChain, sourceAddress, payload, gasOptions);
printInfo('Execute tx', tx.hash);
await tx.wait(chain.confirmations);

Expand Down
2 changes: 1 addition & 1 deletion evm/its.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ async function processCommand(config, chain, options) {
throw new Error(`${action} can only be performed by contract owner: ${owner}`);
}

const pauseStatus = options.pauseStatus;
const pauseStatus = options.pauseStatus === 'true';

const tx = await interchainTokenService.setPauseStatus(pauseStatus, gasOptions);

Expand Down
11 changes: 8 additions & 3 deletions stellar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ node stellar/deploy-contract.js deploy axelar_gas_service --chain-name <CHAIN_NA

### Interchain Token Service

Deploy Interchain Token wasm first.
```bash
node stellar/deploy-contract.js deploy interchain_token --chain-name <CHAIN_NAME> --wasm-path ../axelar-cgp-soroban/target/wasm32-unknown-unknown/release/interchain_token.optimized.wasm
```bash
node stellar/deploy-contract.js deploy interchain_token_service --chain-name <CHAIN_NAME> --wasm-path ../axelar-cgp-soroban/target/wasm32-unknown-unknown/release/interchain_token_service.optimized.wasm
```
Expand Down Expand Up @@ -173,16 +176,18 @@ node stellar/deploy-contract.js upgrade axelar_gateway --wasm-path ../axelar-cgp

### Interchain Token Service

#### Set Trusted Address
_Note_: Stellar ITS runs only in Hub mode. P2P connections are not supported. Therefore, rather than setting trusted ITS addresses, we set trusted chains (chains which are also registered with ITS Hub). The ITS Hub chain (axelar) itself is not a valid source/destination for direct ITS messages and so shouldn't be set as a trusted chain. All ITS messages must be sent to and received from the ITS Hub.
#### Set Trusted Chain
```bash
node stellar/its.js set-trusted-address [chain-name] [trusted-address]
node stellar/its.js set-trusted-chain [chain-name]
```
#### Remove Trusted Address
```bash
node stellar/its.js remove-trusted-address [chain-name]
node stellar/its.js remove-trusted-chain [chain-name]
```
## TTL extension and state archival recovery
Expand Down
59 changes: 39 additions & 20 deletions stellar/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ async function getInitializeArgs(config, chain, contractName, wallet, options) {
case 'interchain_token_service': {
const gatewayAddress = nativeToScVal(Address.fromString(chain?.contracts?.axelar_gateway?.address), { type: 'address' });
const gasServiceAddress = nativeToScVal(Address.fromString(chain?.contracts?.axelar_gas_service?.address), { type: 'address' });
const itsHubAddress = nativeToScVal(config.axelar?.contracts?.InterchainTokenService?.address, { type: 'string' });
const chainName = nativeToScVal('stellar', { type: 'string' });

return { owner, gatewayAddress, gasServiceAddress, chainName };
if (!chain?.contracts?.interchain_token?.wasmHash) {
throw new Error(`interchain_token contract's wasm hash does not exist.`);
}

const interchainTokenWasmHash = nativeToScVal(Buffer.from(chain?.contracts?.interchain_token?.wasmHash, 'hex'), {
type: 'bytes',
});

return { owner, gatewayAddress, gasServiceAddress, itsHubAddress, chainName, interchainTokenWasmHash };
}

case 'axelar_operators':
Expand Down Expand Up @@ -85,30 +94,40 @@ async function deploy(options, config, chain, contractName) {
return;
}

const initializeArgs = await getInitializeArgs(config, chain, contractName, wallet, options);
const serializedArgs = Object.fromEntries(
Object.entries(initializeArgs).map(([key, value]) => [key, serializeValue(scValToNative(value))]),
);
const wasmHash = await uploadWasm(wasmPath, wallet, chain);

const operation = Operation.createCustomContract({
wasmHash,
address: Address.fromString(wallet.publicKey()),
// requires that initializeArgs returns the parameters in the appropriate order
constructorArgs: Object.values(initializeArgs),
});
printInfo('Initializing contract with args', JSON.stringify(serializedArgs, null, 2));
if (contractName === 'interchain_token') {
chain.contracts[contractName] = {
deployer: wallet.publicKey(),
wasmHash: serializeValue(wasmHash),
};
} else {
const initializeArgs = await getInitializeArgs(config, chain, contractName, wallet, options);
const serializedArgs = Object.fromEntries(
Object.entries(initializeArgs).map(([key, value]) => [key, serializeValue(scValToNative(value))]),
);
const operation = Operation.createCustomContract({
wasmHash,
address: Address.fromString(wallet.publicKey()),
// requires that initializeArgs returns the parameters in the appropriate order
constructorArgs: Object.values(initializeArgs),
});
printInfo('Initializing contract with args', JSON.stringify(serializedArgs, null, 2));

const deployResponse = await broadcast(operation, wallet, chain, 'Initialized contract', options);
const contractAddress = StrKey.encodeContract(Address.fromScAddress(deployResponse.address()).toBuffer());

const deployResponse = await broadcast(operation, wallet, chain, 'Initialized contract', options);
const contractAddress = StrKey.encodeContract(Address.fromScAddress(deployResponse.address()).toBuffer());
printInfo('Contract initialized at address', contractAddress);

printInfo('Contract initialized at address', contractAddress);
chain.contracts[contractName] = {
address: contractAddress,
deployer: wallet.publicKey(),
wasmHash: serializeValue(wasmHash),
initializeArgs: serializedArgs,
};
}

chain.contracts[contractName] = {
address: contractAddress,
deployer: wallet.publicKey(),
initializeArgs: serializedArgs,
};
printInfo(contractName, JSON.stringify(chain.contracts[contractName], null, 2));
}

async function uploadWasm(filePath, wallet, chain) {
Expand Down
29 changes: 14 additions & 15 deletions stellar/its.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@ const { saveConfig, loadConfig, addOptionsToCommands, getChainConfig } = require
const { addBaseOptions, getWallet, broadcast } = require('./utils');
const { prompt } = require('../common/utils');

async function setTrustedAddress(wallet, _, chain, contractConfig, args, options) {
async function setTrustedChain(wallet, _, chain, contractConfig, arg, options) {
const contract = new Contract(contractConfig.address);
const [chainName, trustedAddress] = args;
const callArgs = [chainName, trustedAddress].map(nativeToScVal);
const callArg = nativeToScVal(arg, { type: 'string' });

const operation = contract.call('set_trusted_address', ...callArgs);
const operation = contract.call('set_trusted_chain', callArg);

await broadcast(operation, wallet, chain, 'Trusted Address Set', options);
await broadcast(operation, wallet, chain, 'Trusted Chain Set', options);
}

async function removeTrustedAddress(wallet, _, chain, contractConfig, arg, options) {
async function removeTrustedChain(wallet, _, chain, contractConfig, arg, options) {
const contract = new Contract(contractConfig.address);
const callArg = nativeToScVal(arg, { type: 'string' });

const operation = contract.call('remove_trusted_address', callArg);
const operation = contract.call('remove_trusted_chain', callArg);

await broadcast(operation, wallet, chain, 'Trusted Address Removed', options);
await broadcast(operation, wallet, chain, 'Trusted Chain Removed', options);
}

async function mainProcessor(processor, args, options) {
Expand Down Expand Up @@ -49,17 +48,17 @@ if (require.main === module) {
program.name('its').description('Interchain Token Service contract operations.');

program
.command('set-trusted-address <chainName> <trustedAddress>')
.description('set a trusted ITS address for a given chain')
.action((chainName, trustedAddress, options) => {
mainProcessor(setTrustedAddress, [chainName, trustedAddress], options);
.command('set-trusted-chain <chainName>')
.description('set a trusted ITS chain')
.action((chainName, options) => {
mainProcessor(setTrustedChain, chainName, options);
});

program
.command('remove-trusted-address <chainName>')
.description('remove a trusted ITS address for a given chain')
.command('remove-trusted-chain <chainName>')
.description('remove a trusted ITS chain')
.action((chainName, options) => {
mainProcessor(removeTrustedAddress, chainName, options);
mainProcessor(removeTrustedChain, chainName, options);
});

addOptionsToCommands(program, addBaseOptions);
Expand Down
15 changes: 11 additions & 4 deletions sui/deploy-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ const supportedPackages = PACKAGE_DIRS.map((dir) => ({
*/

async function postDeployRelayerDiscovery(published, keypair, client, config, chain, options) {
const [relayerDiscoveryObjectId, relayerDiscoveryObjectIdv0] = getObjectIdsByObjectTypes(published.publishTxn, [
const [relayerDiscoveryObjectId, relayerDiscoveryObjectIdv0, ownerCap] = getObjectIdsByObjectTypes(published.publishTxn, [
`${published.packageId}::discovery::RelayerDiscovery`,
`${published.packageId}::relayer_discovery_v0::RelayerDiscovery_v0`,
`${published.packageId}::owner_cap::OwnerCap`,
]);

chain.contracts.RelayerDiscovery.objects = {
RelayerDiscovery: relayerDiscoveryObjectId,
RelayerDiscoveryv0: relayerDiscoveryObjectIdv0,
OwnerCap: ownerCap,
};
}

Expand Down Expand Up @@ -235,11 +237,12 @@ 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, operatorCapId] = getObjectIdsByObjectTypes(published.publishTxn, [
const [itsObjectId, itsv0ObjectId, ownerCapObjectId, 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 @@ -250,6 +253,7 @@ async function postDeployIts(published, keypair, client, config, chain, options)
ChannelId: channelId,
OwnerCap: ownerCapObjectId,
OperatorCap: operatorCapId,

Check failure on line 255 in sui/deploy-contract.js

View workflow job for this annotation

GitHub Actions / lint

'operatorCapId' is not defined
UpgradeCap: upgradeCapObjectId,
};

const tx = new Transaction();
Expand All @@ -264,9 +268,12 @@ async function postDeployIts(published, keypair, client, config, chain, options)
async function postDeploySquid(published, keypair, client, config, chain, options) {
const relayerDiscovery = chain.contracts.RelayerDiscovery?.objects?.RelayerDiscovery;

const [squidObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [`${published.packageId}::squid::Squid`]);
const [squidObjectId, ownerCapObjectId] = getObjectIdsByObjectTypes(published.publishTxn, [
`${published.packageId}::squid::Squid`,
`${published.packageId}::owner_cap::OwnerCap`,
]);
const channelId = await getSquidChannelId(client, squidObjectId);
chain.contracts.Squid.objects = { Squid: squidObjectId, ChannelId: channelId };
chain.contracts.Squid.objects = { Squid: squidObjectId, ChannelId: channelId, OwnerCap: ownerCapObjectId };

const tx = new Transaction();
tx.moveCall({
Expand Down
23 changes: 23 additions & 0 deletions sui/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ async function approve(keypair, client, config, chain, contractConfig, args, opt
};
}

async function migrate(keypair, client, config, chain, contractConfig, args, options) {
const packageId = contractConfig.address;

const tx = new Transaction();

tx.moveCall({
target: `${packageId}::gateway::migrate`,
arguments: [tx.object(contractConfig.objects.Gateway)],
});

return {
tx,
message: 'Migrate',
};
}

async function submitProof(keypair, client, config, chain, contractConfig, args, options) {
const packageId = contractConfig.address;
const [multisigSessionId] = args;
Expand Down Expand Up @@ -308,6 +324,13 @@ if (require.main === module) {
mainProcessor(approve, [sourceChain, messageId, sourceAddress, destinationId, payloadHash], options);
});

program
.command('migrate')
.description('Migrate the gateway after upgrade')
.action((options) => {
mainProcessor(migrate, null, options);
});

program
.command('submitProof <multisigSessionId>')
.description('Submit proof for the provided amplifier multisig session id')
Expand Down
5 changes: 3 additions & 2 deletions sui/utils/upgrade-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ async function upgradePackage(client, keypair, packageToUpgrade, contractConfig,
arguments: [cap, receipt],
});

const sender = options.sender || keypair.toSuiAddress();
tx.setSender(sender);

if (offline) {
const sender = options.sender || keypair.toSuiAddress();
tx.setSender(sender);
await saveGeneratedTx(tx, `Transaction to upgrade ${packageDir}`, client, options);
} else {
const txBytes = await tx.build({ client });
Expand Down
2 changes: 1 addition & 1 deletion sui/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ const getStructs = async (client, packageId) => {
const structs = {};

for (const type of packageData.data.bcs.typeOriginTable) {
structs[type.datatype_name] = `${type.package}::${type.moduleName}::${type.datatype_name}`;
structs[type.datatype_name] = `${type.package}::${type.module_name}::${type.datatype_name}`;
}

return structs;
Expand Down

0 comments on commit 7a273ac

Please sign in to comment.