feat: paying fee in wnibi
- related to https://github.com/NibiruChain/nibiru/issues/2321
📝 Walkthrough
Walkthrough
Integrates a new gastoken module, wires GasTokenKeeper into app DI and ante, adds ERC‑20 EVM helpers and Uniswap V3 embeds, implements three‑path fee verification/deduction (native, WNIBI, ERC‑20 swap), adds CLI/grpc/proto/genesis, tests, localnet Uniswap scripts, and dex‑deploy tooling.
Changes
| Cohort / File(s) | Summary |
|---|---|
App wiringapp/app.go, app/app_config.go, app/ante.go, app/ante/handler_opts.go |
Add gastoken module to ModuleBasics and DI, expose GasTokenKeeper in AnteHandlerOptions, and swap authante.NewDeductFeeDecorator for gastokenante.NewDeductFeeDecorator. |
EVM ante decorators & testsapp/evmante/... |
Extend AnteDecVerifyEthAcc and AnteDecEthGasConsume to accept AccountKeeper and GasTokenKeeper; implement three‑path verify/deduct logic; update constructors and tests (..._test.go). |
Gastoken module corex/gastoken/* |
Add full gastoken module: keeper (CRUD, params, genesis), msg server, gRPC querier, ante DeductFeeDecorator and helpers (swap/withdraw/quote), CLI (tx/query), types, codec, errors, DI provider, tests, and protobufs. |
EVM keeper & ERC‑20 helpersx/evm/keeper/*.go, x/evm/erc20.go, x/evm/evmtest/* |
Increase ERC20 gas limits, add GetCallGasWithLimit, BalanceOf/Allowance/Approve wrappers, and Keeper methods GetErc20Balance/Erc20Transfer/Erc20Approve; expose MOCK_GETH_MESSAGE and adjust tests. |
Uniswap / Quoter / Router embeds & ABIsx/evm/embeds/*, x/evm/embeds/abi/*, x/evm/embeds/artifacts/*, x/evm/embeds/contracts/* |
Add Uniswap V3 embeds/artifacts/ABIs (Pool, SwapRouter, Quoter, IQuoterV2, IV3SwapRouter, IUniswapV3PoolActions) and load them at init. |
Proto & generated APIproto/nibiru/gastoken/**, api/nibiru/gastoken/** |
Add gastoken proto files (module, feetoken, params, genesis, query, tx) and generated Pulsar-compatible Go bindings. |
CLI & testsx/gastoken/cli/*, x/gastoken/*_test.go, x/gastoken/keeper/*_test.go, x/gastoken/module_test.go |
Add CLI tx/query commands, integration/unit tests for keeper, gRPC queries, genesis, module lifecycle, and CLI wiring. |
E2E testing & TS utilsevm-e2e/test/{setup.ts,utils.ts,gastoken.test.ts} |
Use HDNodeWallet-derived accounts, add conditional WNIBI/USDC deploy helpers, and add gastoken e2e tests. |
Localnet & dex-deploy toolingcontrib/scripts/localnet*.sh, contrib/make/localnet.mk, justfile, dex-deploy/**, .gitmodules |
Add localnet-uniswap bootstrap script/targets; add dex-deploy Hardhat scaffold, Uniswap deploy-v3 submodule, and deployment scripts (create pool, swap, getPool). |
Misc: artifacts & configsx/evm/embeds/artifacts/*, contrib/scripts/localnet.sh, contrib/scripts/localnet-uniswap.sh, dex-deploy/* |
Update embedded artifacts, add genesis oracle/fee-token defaults, Hardhat config, env template, and new deployment scripts. |
Sequence Diagram(s)
sequenceDiagram
autonumber
participant User as User (submit tx)
participant Mempool as Mempool / CheckTx
participant Verify as AnteDecVerifyEthAcc
participant Deduct as DeductFeeDecorator (gastoken)
participant EVMK as EVM Keeper
participant GTK as GasToken Keeper
participant Bank as Bank Keeper
participant FC as FeeCollector (module acct)
User->>Mempool: submit EVM tx
Mempool->>Verify: AnteHandle(ctx, tx)
Note over Verify: compute tx cost\nif native balance -> pass\nelse if WNIBI -> mark useWNibi\nelse iterate fee tokens -> call quoter to quote amount
Verify-->>Deduct: ctx annotated (useWNibi/gasTokenUsed/gasTokenAmount)
Deduct->>Bank: attempt native fee deduction
alt native success
Bank-->>Deduct: success
else use WNIBI
Deduct->>GTK: GetParams (wnibi addr)
Deduct->>EVMK: Erc20Transfer(wnibi -> FC)
EVMK-->>Deduct: transfer OK
Deduct->>EVMK: WithdrawFeeToken(wnibi -> base)
EVMK-->>Deduct: withdraw OK
else ERC20 token path
Deduct->>GTK: GetParams (router/quoter)
Deduct->>EVMK: Erc20Approve(sender->router)
EVMK-->>Deduct: approve OK
Deduct->>EVMK: SwapFeeToken(token->base via router)
EVMK-->>Deduct: swap OK
Deduct->>EVMK: WithdrawFeeToken(...)
EVMK-->>Deduct: withdraw OK
end
Deduct-->>Mempool: fees covered -> continue
Estimated code review effort
🎯 5 (Critical) | ⏱️ ~120 minutes
Possibly related PRs
- NibiruChain/nibiru#2240 — Depinject/module wiring changes; directly related to registering and providing GasTokenKeeper and module wiring.
- NibiruChain/nibiru#2093 — Changes to EVM/ERC20 call APIs and gas handling; overlaps with ERC‑20 helpers and keeper additions.
- NibiruChain/nibiru#1981 — Modifies AnteDecVerifyEthAcc control flow and EVM ante verification; likely to conflict with gastoken fallback logic.
Suggested labels
x: evm
Pre-merge checks (1 passed, 2 warnings)
❌ Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description Check | ⚠️ Warning | The current PR description only references a related issue and does not follow the repository’s required template, missing the “## Purpose / Abstract” section, the “- Closes #AAA” bullet, and a clear summary of why and what this PR implements. | Please update the description to include a “## Purpose / Abstract” heading, add a “- Closes #2321” bullet, and provide a brief overview of why this PR is important and what changes it introduces. |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 22.83% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (1 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title Check | ✅ Passed | The title “feat: paying fee in wnibi” concisely summarizes the primary change of enabling transaction fees to be paid in WNIBI, aligns directly with the PR’s objective, and is clear and focused without extraneous detail. |
Poem
I’m a rabbit with a tiny patch,
Hopping fees from swap to batch.
WNIBI, tokens, routers spin—
I nibble gas and grin, grin, grin.
Onward, chain — a carrot win! 🥕
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
expertdicer/txfees-poc
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Codecov Report
:x: Patch coverage is 20.78740% with 1006 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 55.43%. Comparing base (d8e33e6) to head (311f996).
:warning: Report is 1 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #2343 +/- ##
==========================================
- Coverage 56.73% 55.43% -1.30%
==========================================
Files 334 345 +11
Lines 27154 28438 +1284
==========================================
+ Hits 15406 15765 +359
- Misses 10677 11570 +893
- Partials 1071 1103 +32
| Files with missing lines | Coverage Δ | |
|---|---|---|
| app/ante.go | 76.27% <100.00%> (ø) |
|
| app/ante/handler_opts.go | 0.00% <ø> (ø) |
|
| app/app.go | 65.23% <100.00%> (+0.12%) |
:arrow_up: |
| app/app_config.go | 100.00% <100.00%> (ø) |
|
| app/evmante/evmante_handler.go | 100.00% <100.00%> (ø) |
|
| x/evm/embeds/embeds.go | 80.48% <100.00%> (+1.54%) |
:arrow_up: |
| x/evm/evmtest/tx.go | 54.86% <ø> (ø) |
|
| x/evm/evmtest/test_deps.go | 83.60% <0.00%> (+66.55%) |
:arrow_up: |
| x/gastoken/keeper/grpc_query.go | 50.00% <50.00%> (ø) |
|
| x/gastoken/types/params.go | 0.00% <0.00%> (ø) |
|
| ... and 14 more |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.