Skip to content

Commit d6a736f

Browse files
chore: added a script for gas update limit
Ticket: WIN-6723
1 parent 8eaec28 commit d6a736f

File tree

11 files changed

+772
-50
lines changed

11 files changed

+772
-50
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Update Batcher transferGasLimit
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
environment:
6+
description: "Target environment"
7+
required: true
8+
type: choice
9+
options:
10+
- testnet
11+
- mainnet
12+
network:
13+
description: "Hardhat network (e.g., tstt, stt)"
14+
required: true
15+
type: string
16+
gas_limit:
17+
description: "transferGasLimit to set (required)"
18+
required: true
19+
default: '300000'
20+
type: string
21+
batcher_address:
22+
description: "Batcher contract address (required)"
23+
required: true
24+
default: ''
25+
type: string
26+
27+
jobs:
28+
run-update:
29+
runs-on: ubuntu-latest
30+
environment: "${{ inputs.environment }}"
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: Use Node.js
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: 18.x
37+
cache: 'npm'
38+
- run: npm install
39+
- name: Run update script
40+
run: |
41+
export BATCHER_ADDRESS="${{ inputs.batcher_address }}"
42+
export TRANSFER_GAS_LIMIT="${{ inputs.gas_limit }}"
43+
npm run update-gas-limit -- ${{ inputs.network }}
44+
env:
45+
MAINNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT: ${{ secrets.MAINNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT }}
46+
TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT: ${{ secrets.TESTNET_PRIVATE_KEY_FOR_CONTRACT_DEPLOYMENT }}
47+
PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT: ${{ secrets.PRIVATE_KEY_FOR_V4_CONTRACT_DEPLOYMENT }}
48+
PRIVATE_KEY_FOR_BATCHER_CONTRACT_DEPLOYMENT: ${{ secrets.PRIVATE_KEY_FOR_BATCHER_CONTRACT_DEPLOYMENT }}

README.md

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,79 @@ Forwarder function. Initializes with a parent and a fee address. It will forward
107107

108108
Factory to create updated forwarder (contracts/ForwarderV4.sol). Deploys a small proxy which utilizes the implementation of a single forwarder contract.
109109

110+
## Batcher gas params and admin script
111+
112+
Centralized defaults used when deploying a new Batcher:
113+
- Per-chain constructor defaults: `config/configGasParams.ts`
114+
115+
Deploying Batcher (uses `config/configGasParams.ts` for constructor args):
116+
```sh
117+
npm run deploy-batcher -- --network <network>
118+
```
119+
120+
Optional constructor override during deploy:
121+
- `TRANSFER_GAS_LIMIT` or `BATCHER_TRANSFER_GAS_LIMIT` to set a custom initial transferGasLimit.
122+
Notes:
123+
- On Somnia (testnet/mainnet), the deploy script automatically enforces a high gasLimit floor and sets robust fee params; no action needed.
124+
125+
Updating transferGasLimit on an existing Batcher (env-only, simplified):
126+
- Required envs:
127+
- `BATCHER_ADDRESS` — the deployed Batcher address
128+
- `TRANSFER_GAS_LIMIT` — the new per-recipient gas stipend (number)
129+
- Behavior:
130+
- Uses signers[0] for the selected Hardhat network.
131+
- Verifies there is contract code at `BATCHER_ADDRESS` and that signers[0] is the on-chain owner; otherwise exits early.
132+
- Gas params come from `scripts/chainConfig.ts` per chain; Somnia gets high gasLimit automatically.
133+
```sh
134+
BATCHER_ADDRESS=0xYourBatcher \
135+
TRANSFER_GAS_LIMIT=300000 \
136+
npm run update-gas-limit -- --network <network>
137+
```
138+
Ensure the first account in `networks.<name>.accounts` (Hardhat config) is the Batcher owner on that chain.
139+
140+
### Testing tools: GasHeavy end-to-end retest
141+
142+
Run the GasHeavy scenario tool (low limit fails, high limit succeeds):
143+
```sh
144+
BATCHER_ADDRESS=0xYourBatcherAddress \
145+
npx hardhat run test/tools/retestGasHeavy.ts --network tstt
146+
```
147+
148+
Important:
149+
- The tool reads `BATCHER_ADDRESS` from the environment (Hardhat doesn’t forward unknown CLI flags).
150+
- Optional envs:
151+
- `OWNER_PRIVATE_KEY=0x...` to perform owner-only updates inside the tool; if omitted, owner updates are skipped and the test proceeds with current limits.
152+
- `GAS_HEAVY=0x...` to reuse a pre-deployed GasHeavy. On Somnia (50312/5031), the tool enforces a high gasLimit floor during deployment and will retry code detection; providing `GAS_HEAVY` skips deploy variance.
153+
- `LOW_LIMIT=2300`, `HIGH_LIMIT=300000`, `AMOUNT_WEI=100000000000000` to tweak behavior.
154+
- Tools under `test/tools` are not part of the Mocha test run; execute them with `hardhat run` as shown.
155+
- To change transferGasLimit for real, use the admin script in the previous section.
156+
157+
### GitHub Actions: update_transfer_gas_limit
158+
159+
Trigger a transferGasLimit update via the workflow dispatch:
160+
161+
1. In GitHub, run the workflow: Actions > "Update Batcher transferGasLimit" > Run workflow
162+
- Inputs (required):
163+
- `environment`: `testnet` or `mainnet`
164+
- `network`: Hardhat network name (e.g., `tstt`, `stt`)
165+
- `batcher_address`: the deployed Batcher address
166+
- `gas_limit`: the new transferGasLimit value
167+
168+
Behavior:
169+
- The workflow exports `BATCHER_ADDRESS` and `TRANSFER_GAS_LIMIT` for the script.
170+
- The script uses the first configured signer on that network; make sure that signer is the on-chain owner or the run will fail.
171+
172+
173+
110174
## Installation
111175

112-
NodeJS 16 is required.
176+
NodeJS 18+ is required.
113177

114178
```shell
115-
yarn
179+
npm install
116180
```
117181

118-
This installs hardhat.
182+
This installs dependencies including Hardhat.
119183

120184
## Wallet Solidity Contract
121185

config/coinBatcherLimits.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Coin registry: coin -> chainId -> { batcher?, transferGasLimit? }.
3+
Keep addresses as constants here (defaults). The admin script uses these unless overridden by:
4+
- CLI flag: --batcher 0x...
5+
- Env var: BATCHER_ADDRESS (e.g., set by the GitHub workflow per network)
6+
- Legacy: BATCHER (env)
7+
If unset everywhere, it will error and ask to add the address here.
8+
*/
9+
type Limits = Record<number, { batcher?: string; transferGasLimit?: number }>;
10+
import { CHAIN_IDS } from './chainIds';
11+
12+
// Fill with deployed Batcher addresses.
13+
const SOMNIA_TESTNET_BATCHER: string | undefined =
14+
'0xebe27913fcc7510eAdf10643A8F86Bf5492A9541';
15+
const SOMNIA_MAINNET_BATCHER: string | undefined =
16+
'0x3E1e5d78e44f15593B3B61ED278f12C27F0fF33e';
17+
18+
// Somnia (stt)
19+
const STT: Limits = {
20+
[CHAIN_IDS.SOMNIA_TESTNET]: {
21+
batcher: SOMNIA_TESTNET_BATCHER,
22+
// Default stipend per recipient; set here to override per-coin/chain.
23+
// Otherwise per-chain defaults come from configGasParams.
24+
transferGasLimit: 300000
25+
},
26+
[CHAIN_IDS.SOMNIA]: {
27+
batcher: SOMNIA_MAINNET_BATCHER,
28+
transferGasLimit: 300000
29+
}
30+
};
31+
32+
const REGISTRY: Record<string, Limits> = {
33+
stt: STT
34+
// Add more coins here, e.g., 'eth': { ... }
35+
};
36+
37+
export function getCoinLimits(coin: string): Limits {
38+
// Case-insensitive lookup; returns {} when unknown (caller uses fallbacks).
39+
return REGISTRY[coin.toLowerCase()] || {};
40+
}

config/configGasParams.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { CHAIN_IDS } from './chainIds';
2+
3+
// Defaults; add overrides only when required by a chain.
4+
export type BatcherGasParams = {
5+
transferGasLimit: number; // stipend per recipient for native transfers
6+
erc20BatchLimit: number; // max recipients per ERC20 batch
7+
nativeBatchTransferLimit: number; // max recipients per native batch
8+
};
9+
10+
const DEFAULTS: BatcherGasParams = {
11+
transferGasLimit: 300_000,
12+
erc20BatchLimit: 256,
13+
nativeBatchTransferLimit: 256
14+
};
15+
16+
// Chain-specific overrides.
17+
const OVERRIDES: Partial<Record<number, Partial<BatcherGasParams>>> = {
18+
// Somnia requires higher limits
19+
[CHAIN_IDS.SOMNIA]: { transferGasLimit: 800_000 },
20+
[CHAIN_IDS.SOMNIA_TESTNET]: { transferGasLimit: 800_000 }
21+
};
22+
23+
export function getBatcherGasParams(chainId: number): BatcherGasParams {
24+
const o = OVERRIDES[chainId] || {};
25+
return {
26+
transferGasLimit: o.transferGasLimit ?? DEFAULTS.transferGasLimit,
27+
erc20BatchLimit: o.erc20BatchLimit ?? DEFAULTS.erc20BatchLimit,
28+
nativeBatchTransferLimit:
29+
o.nativeBatchTransferLimit ?? DEFAULTS.nativeBatchTransferLimit
30+
};
31+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"deploy-prod": "hardhat run scripts/deploy.ts --network",
1313
"deploy-test": "hardhat run scripts/deploy.ts --network",
1414
"deploy-batcher": "hardhat run scripts/deployBatcherContract.ts --network",
15+
"update-gas-limit": "hardhat run scripts/updateTransferGasLimit.ts --network",
1516
"test": "hardhat test",
1617
"coverage": "hardhat coverage",
1718
"solhint": "./node_modules/.bin/solhint --fix 'contracts/**/*.sol'",

0 commit comments

Comments
 (0)