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

chore: add case for appproving execute tx using batch data #228

Merged
merged 4 commits into from
May 14, 2024
Merged
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
45 changes: 45 additions & 0 deletions evm/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
mainProcessor,
printError,
getGasOptions,
httpGet,
} = require('./utils');
const { addBaseOptions } = require('./cli-utils');
const { getWallet } = require('./sign-utils');
Expand Down Expand Up @@ -55,6 +56,17 @@ const getSignedWeightedExecuteInput = async (data, operators, weights, threshold
);
};

const fetchBatchData = async (apiUrl, batchId) => {
try {
const response = await httpGet(`${apiUrl}/${batchId}`);
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
const data = response?.execute_data;
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved

return '0x' + data;
} catch (error) {
throw new Error(`Failed to fetch batch data: ${error.message}`);
}
};

async function processCommand(config, chain, options) {
const { privateKey, address, action, yes } = options;

Expand Down Expand Up @@ -183,6 +195,38 @@ async function processCommand(config, chain, options) {
break;
}

case 'approveWithBatch': {
const { batchID, api } = options;
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved

if (!batchID) {
throw new Error('Batch ID is required for the approve action');
}

const batchId = batchID.startsWith('0x') ? batchID.substring(2) : batchID;
let apiUrl = api || `${config.axelar.lcd}/axelar/evm/v1beta1/batched_commands/${chain.name.toLowerCase()}`;
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved
apiUrl = apiUrl.endsWith('/') ? apiUrl.slice(0, -1) : apiUrl;
blockchainguyy marked this conversation as resolved.
Show resolved Hide resolved

const executeData = await fetchBatchData(apiUrl, batchId);

const tx = {
to: gatewayAddress,
data: executeData,
...gasOptions,
};

const response = await wallet.sendTransaction(tx);
printInfo('Approve tx', response.hash);

const receipt = await response.wait(chain.confirmations);
const eventEmitted = wasEventEmitted(receipt, gateway, 'ContractCallApproved');

if (!eventEmitted) {
printWarn('Event not emitted in receipt.');
}

break;
}

case 'approve':

// eslint-disable-next-line no-fallthrough
Expand Down Expand Up @@ -389,6 +433,7 @@ if (require.main === module) {
'transferMintLimiter',
'mintLimit',
'params',
'approveWithBatch',
])
.makeOptionMandatory(true),
);
Expand Down
Loading