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

ci(GasService): update GasInfo every 2 hours #202

Merged
merged 57 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
57 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
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
04528e5
fix(lint): prettier
re1ro Mar 21, 2024
f7d9efe
fix(GasService): PR feedback
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
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
f15a6ef
Merge branch 'main' into feat/gas-service
re1ro Mar 28, 2024
da949af
ci(GasService): update GasInfo every 2 hours
re1ro Mar 28, 2024
9974280
style(yaml): prettier
re1ro Mar 28, 2024
c9503a9
ci(GasService): update GasInfo manually
re1ro Mar 28, 2024
da3f7a8
style(yaml): prettier
re1ro Mar 28, 2024
1600842
ci(GasService): update GasInfo on pr
re1ro Mar 28, 2024
26ccb62
ci(GasService): update GasInfo with -y
re1ro Mar 28, 2024
99bb9b8
fix(GasService): toBigNumberString
re1ro Mar 28, 2024
25c74cf
fix(GasService): better logging
re1ro Mar 28, 2024
34efbc0
feat(GasService): update for all chains
re1ro Mar 28, 2024
627d1d0
fix(GasService): testnet config
re1ro Mar 28, 2024
6e75de2
fix(GasService): error handling
re1ro Mar 29, 2024
4653b34
Merge branch 'feat/gas-service' into feat/gas-update-job
re1ro Mar 29, 2024
c6379a6
style(JS): prettier
re1ro Mar 29, 2024
db4075e
ci(GasService): test GasInfo fail
re1ro Mar 29, 2024
6bfb75c
ci(GasService): test GasInfo fail
re1ro Mar 29, 2024
8ab1bd9
ci(GasService): revert GasInfo fail
re1ro Mar 29, 2024
b37bb38
ci(GasService): remove GasUpdate on PR
re1ro Mar 29, 2024
22a0066
fix(GasService): testnet config
re1ro Mar 29, 2024
5326898
Update .github/workflows/update-gas-info.yaml
re1ro Apr 8, 2024
856d5bf
Merge branch 'refs/heads/main' into feat/gas-update-job
re1ro Apr 8, 2024
86b19db
fix(GasService): merge conflicts
re1ro Apr 8, 2024
d5b6e9d
Merge branch 'main' into feat/gas-update-job
re1ro Apr 10, 2024
9e0b757
fix(GasEstimation): estimateMultiplier
re1ro Apr 10, 2024
b562155
fix(GasService): testnet config
re1ro Apr 10, 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
50 changes: 50 additions & 0 deletions .github/workflows/update-gas-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: 'Update Gas Info on Testnet'

on:
workflow_dispatch:
inputs:
environment:
description: Environment to update gas info on
required: true
default: testnet
type: choice
options:
- testnet
- mainnet
- stagenet

jobs:
update-gas:
name: 'Update Gas Info'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
ENV="${{ github.event.inputs.environment }}"
else
ENV="testnet"
fi

case "$ENV" in
testnet)
PRIVATE_KEY="${{ secrets.TESTNET_PRIVATE_KEY }}"
;;
mainnet)
PRIVATE_KEY="${{ secrets.MAINNET_PRIVATE_KEY }}"
;;
stagenet)
PRIVATE_KEY="${{ secrets.STAGENET_PRIVATE_KEY }}"
;;
esac

echo "PRIVATE_KEY=$PRIVATE_KEY" >> .env
echo "ENV=$ENV" >> .env
echo "CHAINS=all" >> .env

node evm/operators.js --action updateGasInfo --chains all -y
40 changes: 36 additions & 4 deletions axelar-chains-config/info/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@
"gasOptions": {
"gasLimit": 8000000
},
"finality": "finalized",
"approxFinalityWaitTime": 40,
"onchainGasEstimate": {
"chainName": "ethereum",
"blobBaseFee": 50187563959
}
},
"finality": "finalized",
"approxFinalityWaitTime": 40
},
"avalanche": {
"name": "Avalanche",
Expand Down Expand Up @@ -1010,6 +1011,9 @@
"gasOptions": {
"gasLimit": 300000000
},
"onchainGasEstimate": {
"chainName": "filecoin"
re1ro marked this conversation as resolved.
Show resolved Hide resolved
},
"confirmations": 3,
"eip1559": true,
"finality": "120",
Expand Down Expand Up @@ -1125,6 +1129,9 @@
"gasOptions": {
"gasPrice": 3000000000
},
"onchainGasEstimate": {
"l1ChainName": "ethereum"
},
"confirmations": 4,
"finality": "400",
"approxFinalityWaitTime": 30
Expand Down Expand Up @@ -1237,6 +1244,10 @@
"gasLimit": 7000000,
"gasPriceAdjustment": 0.25
},
"onchainGasEstimate": {
"l1ChainName": "ethereum",
"gasEstimationType": 1
},
"finality": "finalized",
"approxFinalityWaitTime": 60
},
Expand Down Expand Up @@ -1436,7 +1447,11 @@
"api": "https://api-sepolia.arbiscan.io/api"
},
"finality": "finalized",
"approxFinalityWaitTime": 25
"approxFinalityWaitTime": 25,
"onchainGasEstimate": {
"chainName": "arbitrum",
"l1ChainName": "ethereum"
}
},
"centrifuge": {
"name": "Centrifuge",
Expand Down Expand Up @@ -1522,6 +1537,9 @@
"gasOptions": {
"gasLimit": 8000000
},
"onchainGasEstimate": {
"chainName": "centrifuge"
},
"explorer": {
"name": "",
"url": ""
Expand All @@ -1539,6 +1557,10 @@
"gasOptions": {
"gasLimit": 8000000
},
"onchainGasEstimate": {
"l1ChainName": "ethereum",
"gasEstimationType": 1
},
"contracts": {
"InterchainGovernance": {
"minimumTimeDelay": 300,
Expand Down Expand Up @@ -1872,6 +1894,11 @@
"gasOptions": {
"gasLimit": 8000000
},
"onchainGasEstimate": {
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
"chainName": "blast",
"l1ChainName": "ethereum",
"gasEstimationType": 1
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
},
"confirmations": 2,
"explorer": {
"name": "Blastscan",
Expand Down Expand Up @@ -1981,6 +2008,11 @@
"gasOptions": {
"gasLimit": 50000000000
},
"onchainGasEstimate": {
"chainName": "mantle",
"l1ChainName": "ethereum",
"gasEstimationType": 1
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
},
"explorer": {
"name": "Mantle Explorer",
"url": "https://explorer.sepolia.mantle.xyz",
Expand Down
76 changes: 49 additions & 27 deletions evm/gas-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,54 @@ const {
isValidAddress,
validateParameters,
httpPost,
toBigNumberString,
} = require('./utils');
const { addBaseOptions } = require('./cli-utils');
const { getWallet } = require('./sign-utils');

let failedChainUpdates = [];

function addFailedChainUpdate(chain, destinationChain) {
failedChainUpdates.push({ chain, destinationChain });
}

function printFailedChainUpdates() {
if (failedChainUpdates.length > 0) {
printError('Failed to update gas info for following chain combinations');

failedChainUpdates.forEach(({ chain, destinationChain }) => {
printError(`${chain} -> ${destinationChain}`);
});

failedChainUpdates = [];

throw new Error('Failed to update gas info for the chain combinations above');
}
}

async function getGasUpdates(config, env, chain, destinationChains) {
const api = config.axelar.axelarscanApi;

validateParameters({
isNonEmptyStringArray: { destinationChains },
});

if (destinationChains.includes('all')) {
destinationChains = Object.keys(config.chains);
}

let gasUpdates = await Promise.all(
destinationChains.map(async (destinationChain) => {
const destinationConfig = config.chains[destinationChain];

if (!destinationConfig) {
printError(`Error: chain ${destinationChain} not found in config.`);
printError(`Skipping ${destinationChain}.`);
failedChainUpdates.push({ chain: chain.axelarId, destinationChain });
addFailedChainUpdate(chain.axelarId, destinationChain);
return null;
}

const { axelarId, onchainGasEstimate: { gasEstimationType = 0, blobBaseFee = 0 } = {} } = destinationConfig;
const { axelarId, onchainGasEstimate: { gasEstimationType = 0, blobBaseFee = 0, multiplier: estimateMultiplier = 1.1 } = {} } = destinationConfig;

let data;

Expand All @@ -57,7 +80,7 @@ async function getGasUpdates(config, env, chain, destinationChains) {
} catch (e) {
printError(`Error getting gas info for ${chain.axelarId} -> ${axelarId}`);
printError(e);
failedChainUpdates.push({ chain: chain.axelarId, destinationChain: axelarId });
addFailedChainUpdate(chain.axelarId, axelarId);
return null;
}

Expand All @@ -75,15 +98,15 @@ async function getGasUpdates(config, env, chain, destinationChains) {
execute_gas_multiplier: multiplier = 1.1,
} = data.result;

const axelarBaseFee = Math.ceil(parseFloat(sourceBaseFee) * Math.pow(10, decimals)).toString();
const expressFee = Math.ceil(parseFloat(sourceExpressFee) * Math.pow(10, decimals)).toString();
const relativeGasPrice = Math.ceil(parseFloat(gasPrice) * parseFloat(multiplier)).toString();
const axelarBaseFee = parseFloat(sourceBaseFee) * Math.pow(10, decimals);
const expressFee = parseFloat(sourceExpressFee) * Math.pow(10, decimals);
const relativeGasPrice = parseFloat(gasPrice) * parseFloat(multiplier) * parseFloat(estimateMultiplier);
const gasPriceRatio = parseFloat(destinationTokenPrice) / parseFloat(srcTokenPrice);
const relativeBlobBaseFee = Math.ceil(blobBaseFee * gasPriceRatio).toString();
const relativeBlobBaseFee = blobBaseFee * gasPriceRatio;

return {
chain: destinationChain,
gasInfo: [gasEstimationType, axelarBaseFee, expressFee, relativeGasPrice, relativeBlobBaseFee],
gasInfo: [gasEstimationType, axelarBaseFee, expressFee, relativeGasPrice, relativeBlobBaseFee].map(toBigNumberString),
};
}),
);
Expand Down Expand Up @@ -129,18 +152,6 @@ async function getGasUpdates(config, env, chain, destinationChains) {
};
}

function printFailedChainUpdates() {
if (failedChainUpdates.length > 0) {
printError('Failed to update gas info for following chain combinations');

failedChainUpdates.forEach(({ chain, destinationChain }) => {
printError(`${chain} -> ${destinationChain}`);
});
}

failedChainUpdates = [];
}

async function processCommand(config, chain, options) {
const { env, contractName, address, action, privateKey, chains, destinationChain, destinationAddress, isExpress, yes } = options;
const executionGasLimit = parseInt(options.executionGasLimit);
Expand Down Expand Up @@ -224,20 +235,30 @@ async function processCommand(config, chain, options) {

const { chainsToUpdate, gasInfoUpdates } = await getGasUpdates(config, env, chain, chains);

if (prompt(`Update gas info for following chains ${chainsToUpdate.join(', ')}?`, yes)) {
printInfo('Collected gas info for the following chain names', chainsToUpdate.join(', '));

if (prompt(`Update gas info?`, yes)) {
return;
}

const tx = await gasService.updateGasInfo(chainsToUpdate, gasInfoUpdates, gasOptions);
try {
const tx = await gasService.updateGasInfo(chainsToUpdate, gasInfoUpdates, gasOptions);

printInfo('TX', tx.hash);

printInfo('TX', tx.hash);
const receipt = await tx.wait(chain.confirmations);

const receipt = await tx.wait(chain.confirmations);
const eventEmitted = wasEventEmitted(receipt, gasService, 'GasInfoUpdated');

const eventEmitted = wasEventEmitted(receipt, gasService, 'GasInfoUpdated');
if (!eventEmitted) {
printWarn('Event not emitted in receipt.');
}
} catch (error) {
for (let i = 0; i < chainsToUpdate.length; i++) {
addFailedChainUpdate(chain.name, chainsToUpdate[i]);
}

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

break;
Expand Down Expand Up @@ -286,4 +307,5 @@ if (require.main === module) {
}

exports.getGasUpdates = getGasUpdates;
exports.addFailedChainUpdate = addFailedChainUpdate;
exports.printFailedChainUpdates = printFailedChainUpdates;
10 changes: 8 additions & 2 deletions evm/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const {
getContractJSON,
} = require('./utils');
const { addBaseOptions } = require('./cli-utils');
const { getGasUpdates, printFailedChainUpdates } = require('./gas-service');
const { getGasUpdates, printFailedChainUpdates, addFailedChainUpdate } = require('./gas-service');

async function processCommand(config, chain, options) {
const {
Expand Down Expand Up @@ -251,7 +251,9 @@ async function processCommand(config, chain, options) {

const { chainsToUpdate, gasInfoUpdates } = await getGasUpdates(config, env, chain, chains);

if (prompt(`Update gas info for following chains ${chainsToUpdate.join(', ')}?`, yes)) {
printInfo('Collected gas info for the following chain names', chainsToUpdate.join(', '));

if (prompt(`Submit gas update transaction?`, yes)) {
return;
}

Expand All @@ -263,6 +265,10 @@ async function processCommand(config, chain, options) {
printInfo('TX', tx.hash);
await tx.wait(chain.confirmations);
} catch (error) {
for (let i = 0; i < chainsToUpdate.length; i++) {
addFailedChainUpdate(chain.name, chainsToUpdate[i]);
}

printError(error);
}

Expand Down
5 changes: 5 additions & 0 deletions evm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,10 @@ function isValidChain(config, chainName) {
}
}

function toBigNumberString(number) {
return Math.ceil(number).toLocaleString('en', { useGrouping: false });
}

module.exports = {
deployCreate,
deployCreate2,
Expand Down Expand Up @@ -1231,4 +1235,5 @@ module.exports = {
getSaltFromKey,
getDeployOptions,
isValidChain,
toBigNumberString,
};
Loading