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(GasService): more gas service commands #193

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
55291d4
feat(GasService): script with gas service commands
re1ro Mar 20, 2024
b2923de
fix(GasService): moving extra gas service methods to a separate branch
re1ro Mar 20, 2024
b88ef1b
feat(GasService): more gas service commands
re1ro Mar 20, 2024
b096699
Update evm/gas-service.js
re1ro Mar 20, 2024
9a2180a
Update evm/gas-service.js
re1ro Mar 20, 2024
8805eb0
fix(GasService): moving extra gas service methods to a separate branch
re1ro Mar 20, 2024
682ba06
Update evm/gas-service.js
re1ro Mar 21, 2024
e14eccf
Update evm/gas-service.js
re1ro Mar 21, 2024
94b9f47
config(GasService): gas estimation params
re1ro Mar 21, 2024
a0db8a4
fix(GasService): PR feedback
re1ro Mar 21, 2024
0038490
Merge branch 'feat/gas-service' into feat/more-gas-methods
re1ro Mar 21, 2024
8e16381
fix(GasService): all gas service actions
re1ro Mar 21, 2024
04528e5
fix(lint): prettier
re1ro Mar 21, 2024
f7d9efe
fix(GasService): PR feedback
re1ro Mar 21, 2024
ee11bf9
Merge branch 'feat/gas-service' into feat/more-gas-methods
re1ro Mar 21, 2024
f98da48
Update axelar-chains-config/info/stagenet.json
re1ro Mar 21, 2024
d06a4b3
Update evm/gas-service.js
re1ro Mar 21, 2024
b543814
Update evm/gas-service.js
re1ro Mar 21, 2024
8a51741
Update evm/gas-service.js
re1ro Mar 21, 2024
89634fa
fix: lint error & trailing spaces
deanamiel Mar 21, 2024
08f565c
Update evm/gas-service.js
re1ro Mar 21, 2024
a0dc655
fix(GasService): PR feedback
re1ro Mar 21, 2024
e233ce8
fix(GasService): PR feedback
re1ro Mar 21, 2024
ccbe96e
feat(GasService): calling updateGasInfo through Operators
re1ro Mar 21, 2024
cf78d6b
Merge branch 'feat/gas-service' into feat/more-gas-methods
re1ro Mar 21, 2024
c63bfdf
fix(GasService): PR feedback
re1ro Mar 21, 2024
b622e3a
refactor(GasService): PR feedback
re1ro Mar 21, 2024
fda1217
refactor(GasService): calculating gas in floating numbers
re1ro Mar 21, 2024
5fadade
fix(GasService): flow
re1ro Mar 22, 2024
7a04d1e
feat(GasService): added AxelarScan gas estimate
re1ro Mar 22, 2024
0b22fec
refactor(GasService): converting floating numbers to integer strings
re1ro Mar 22, 2024
2659150
feat(GasService): adding support for express estimation
re1ro Mar 22, 2024
7fefda1
style(JS): prettier
re1ro Mar 22, 2024
eb929c8
fix(GasService): updated estimation script
re1ro Mar 24, 2024
fee1253
Merge branch 'main' into feat/gas-service
re1ro Mar 26, 2024
2d2492a
chore(npm): CGP version bump
re1ro Mar 26, 2024
996a11b
style(JS): prettier
re1ro Mar 26, 2024
3f1cd57
Merge branch 'main' into feat/gas-service
re1ro Mar 26, 2024
8cbe8c7
Merge branch 'feat/gas-service' into feat/more-gas-methods
re1ro Mar 26, 2024
5bb6ec8
style(JS): prettier
re1ro Mar 26, 2024
bfc37cd
Merge branch 'refs/heads/main' into feat/more-gas-methods
re1ro May 11, 2024
a3e407b
merge(GasService): resolved conflicts
re1ro May 11, 2024
8c9fbef
Merge branch 'main' into feat/more-gas-methods
milapsheth Nov 25, 2024
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
209 changes: 207 additions & 2 deletions evm/gas-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
const { ethers } = require('hardhat');
const {
getDefaultProvider,
BigNumber,
Contract,
constants: { AddressZero },
utils: { formatEther, parseEther },
} = ethers;
const { Command, Option } = require('commander');
const {
Expand Down Expand Up @@ -210,7 +212,36 @@
}

async function processCommand(config, chain, options) {
const { env, contractName, address, action, privateKey, chains, destinationChain, destinationAddress, isExpress, yes } = options;
const {
env,
contractName,
address,
action,
privateKey,

chains,

destinationChain,
destinationAddress,
isExpress,

txHash,
logIndex,

receiver,
token,
amount,

collectorReceiver,
collectTokens,
collectAmounts,

gasToken,
gasFeeAmount,
refundAddress,

yes,
} = options;
const executionGasLimit = parseInt(options.executionGasLimit);

const contracts = chain.contracts;
Expand Down Expand Up @@ -325,6 +356,150 @@
break;
}

case 'refund': {
validateParameters({
isKeccak256Hash: { txHash },
isNumber: { logIndex, amount },
isValidAddress: { receiver, token },
});

const refundAmount = parseEther(amount);

const balance = await provider.getBalance(gasService.address);

if (balance.lt(refundAmount)) {
throw new Error(
`Contract balance ${formatEther(BigNumber.from(balance))} is less than refund amount: ${formatEther(
BigNumber.from(refundAmount),
)}`,
);
}

const tx = await gasService.refund(txHash, logIndex, receiver, token, refundAmount, gasOptions);

printInfo('Call refund', tx.hash);

const receipt = await tx.wait(chain.confirmations);

const eventEmitted = wasEventEmitted(receipt, gasService, 'Refunded');

Check failure on line 384 in evm/gas-service.js

View workflow job for this annotation

GitHub Actions / lint

'wasEventEmitted' is not defined

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

break;
}

case 'collectFees': {
validateParameters({
isValidAddress: { collectorReceiver },
isNonEmptyAddressArray: { collectTokens },
isNonEmptyNumberArray: { collectAmounts },
});

const tx = await gasService.collectFees(collectorReceiver, collectTokens, collectAmounts, gasOptions);

printInfo('Call collectFees', tx.hash);

const receipt = await tx.wait(chain.confirmations);

const eventEmitted = wasEventEmitted(receipt, gasService, 'FeesCollected');

Check failure on line 406 in evm/gas-service.js

View workflow job for this annotation

GitHub Actions / lint

'wasEventEmitted' is not defined

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

break;
}

case 'addGas': {
validateParameters({
isKeccak256Hash: { txHash },
isNumber: { logIndex, gasFeeAmount },
isValidAddress: { gasToken, refundAddress },
});

const tx = await gasService.addGas(txHash, logIndex, gasToken, gasFeeAmount, refundAddress, gasOptions);

printInfo('Call addGas', tx.hash);

const receipt = await tx.wait(chain.confirmations);

const eventEmitted = wasEventEmitted(receipt, gasService, 'GasAdded');

Check failure on line 428 in evm/gas-service.js

View workflow job for this annotation

GitHub Actions / lint

'wasEventEmitted' is not defined

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

break;
}

case 'addNativeGas': {
validateParameters({
isKeccak256Hash: { txHash },
isNumber: { logIndex },
isValidAddress: { refundAddress },
});

const tx = await gasService.addNativeGas(txHash, logIndex, refundAddress, { ...gasOptions, value: amount });

printInfo('Call addNativeGas', tx.hash);

const receipt = await tx.wait(chain.confirmations);

const eventEmitted = wasEventEmitted(receipt, gasService, 'NativeGasAdded');

Check failure on line 450 in evm/gas-service.js

View workflow job for this annotation

GitHub Actions / lint

'wasEventEmitted' is not defined

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

break;
}

case 'addExpressGas': {
validateParameters({
isKeccak256Hash: { txHash },
isNumber: { logIndex, gasFeeAmount },
isValidAddress: { gasToken, refundAddress },
});

const tx = await gasService.addExpressGas(txHash, logIndex, gasToken, gasFeeAmount, refundAddress, gasOptions);

printInfo('Call addExpressGas', tx.hash);

const receipt = await tx.wait(chain.confirmations);

const eventEmitted = wasEventEmitted(receipt, gasService, 'ExpressGasAdded');

Check failure on line 472 in evm/gas-service.js

View workflow job for this annotation

GitHub Actions / lint

'wasEventEmitted' is not defined

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

break;
}

case 'addNativeExpressGas': {
validateParameters({
isKeccak256Hash: { txHash },
isNumber: { logIndex },
isValidAddress: { refundAddress },
});

const tx = await gasService.addNativeExpressGas(txHash, logIndex, refundAddress, { ...gasOptions, value: amount });

printInfo('Call addNativeExpressGas', tx.hash);

const receipt = await tx.wait(chain.confirmations);

const eventEmitted = wasEventEmitted(receipt, gasService, 'NativeExpressGasAdded');

Check failure on line 494 in evm/gas-service.js

View workflow job for this annotation

GitHub Actions / lint

'wasEventEmitted' is not defined

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

break;
}

default:
throw new Error(`Unknown action: ${action}`);
}
Expand All @@ -345,11 +520,27 @@

program.addOption(new Option('-c, --contractName <contractName>', 'contract name').default('AxelarGasService'));
program.addOption(
new Option('--action <action>', 'GasService action').choices(['estimateGasFee', 'updateGasInfo']).makeOptionMandatory(true),
new Option('--action <action>', 'GasService action')
.choices([
'estimateGasFee',
'updateGasInfo',
'refund',
'collectFees',
'addGas',
'addNativeGas',
'addExpressGas',
'addNativeExpressGas',
])
.makeOptionMandatory(true),
);
program.addOption(new Option('--offline', 'run script in offline mode'));
program.addOption(new Option('--nonceOffset <nonceOffset>', 'The value to add in local nonce if it deviates from actual wallet nonce'));

// common options
program.addOption(new Option('--txHash <txHash>', 'Transaction hash').makeOptionMandatory(false));
program.addOption(new Option('--logIndex <logIndex>', 'Log index').makeOptionMandatory(false));
program.addOption(new Option('--receiver <receiver>', 'Receiver address').makeOptionMandatory(false));

// options for estimateGasFee
program.addOption(new Option('--destinationChain <destinationChain>', 'Destination chain name'));
program.addOption(new Option('--destinationAddress <destinationAddress>', 'Destination contract address'));
Expand All @@ -361,6 +552,20 @@
program.addOption(new Option('--chains <chains...>', 'Chain names'));
program.addOption(new Option('--relayerAPI <relayerAPI>', 'Relay the tx through an external relayer API').env('RELAYER_API'));

// options for refund
program.addOption(new Option('--token <token>', 'Refund token address').makeOptionMandatory(false));
program.addOption(new Option('--amount <amount>', 'Refund amount').makeOptionMandatory(false));

// options for collectFees
program.addOption(new Option('--collectorReceiver <collectorReceiver>', 'Collector receiver address').makeOptionMandatory(false));
program.addOption(new Option('--collectTokens <collectTokens...>', 'Tokens to collect').makeOptionMandatory(false));
program.addOption(new Option('--collectAmounts <collectAmounts...>', 'Amounts to collect').makeOptionMandatory(false));

// options for adding gas
program.addOption(new Option('--gasToken <gasToken>', 'Gas token address').makeOptionMandatory(false));
program.addOption(new Option('--gasFeeAmount <gasFeeAmount>', 'Gas fee amount').makeOptionMandatory(false));
program.addOption(new Option('--refundAddress <refundAddress>', 'Refund address').makeOptionMandatory(false));

program.action((options) => {
main(options);
});
Expand Down
Loading