[LWDM] feat(coin-near): add CoinModuleApi for native NEAR and staking - #20296
[LWDM] feat(coin-near): add CoinModuleApi for native NEAR and staking#20296pawell24 wants to merge 1 commit into
Conversation
Web Tools Build Status
|
There was a problem hiding this comment.
Pull request overview
Adds a CoinModuleApi (“Alpaca”) implementation for the NEAR coin-module (native + delegated staking) while keeping Ledger Live’s current NEAR routing on the legacy account bridge. To avoid duplicated behavior, shared transaction/fee logic is refactored into reusable logic/* helpers and protocol-config–derived costs are introduced behind an LRU cache for non-preload call paths.
Changes:
- Expose NEAR
CoinModuleApi(balance, history, fees, crafting, staking reads) and wire it into live-common coin-module loaders. - Refactor shared fee formula + action building so both the bridge path and the CoinModuleApi path use the same logic.
- Move NEAR “api” networking to
src/network/*and add unit + integration coverage for indexer/node/protocol config.
Reviewed changes
Copilot reviewed 54 out of 59 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| libs/ledger-live-common/src/families/near/coinModuleApi.ts | Adds local CoinModuleApi factory wiring for NEAR. |
| libs/ledger-live-common/src/families/near/banner.test.ts | Consolidates NEAR type imports. |
| libs/ledger-live-common/src/coin-modules/loaders.ts | Registers loadLocalApi for NEAR. |
| libs/ledger-live-common/.unimportedrc.json | Adds near coinModuleApi to unimported ignore list. |
| libs/coin-modules/coin-near/src/types.ts | Updates staking position type re-export to network/. |
| libs/coin-modules/coin-near/src/test/coinConfig.ts | Adds helper to set mocked infra endpoints. |
| libs/coin-modules/coin-near/src/synchronisation.ts | Switches sync imports from api to network. |
| libs/coin-modules/coin-near/src/preload.ts | Preload derives costs via cached protocol config + constants. |
| libs/coin-modules/coin-near/src/network/sdk.types.ts | Adds block header type for JSON-RPC block reads. |
| libs/coin-modules/coin-near/src/network/protocolConfig.ts | Adds cached derivation of storage/gas action costs. |
| libs/coin-modules/coin-near/src/network/protocolConfig.test.ts | Tests protocol-config cost derivation + caching. |
| libs/coin-modules/coin-near/src/network/node.ts | Implements RPC/indexer-backed node calls (account, gas, broadcast, staking, validators). |
| libs/coin-modules/coin-near/src/network/node.test.ts | Unit tests for node/indexer-backed calls. |
| libs/coin-modules/coin-near/src/network/node.mock.ts | MSW server + mocked NEAR base URL. |
| libs/coin-modules/coin-near/src/network/indexer.ts | Adds paged tx fetch and exports operation-type mapper. |
| libs/coin-modules/coin-near/src/network/indexer.test.ts | Tests operation mapping resilience and paging envelope behavior. |
| libs/coin-modules/coin-near/src/network/indexer.integ.test.ts | Mainnet integration tests for indexer-backed reads. |
| libs/coin-modules/coin-near/src/network/index.ts | Barrel export for network layer APIs. |
| libs/coin-modules/coin-near/src/network/getBlock.ts | Adds JSON-RPC block-header reads. |
| libs/coin-modules/coin-near/src/network/getBlock.test.ts | Tests block-header reads + invalid height handling. |
| libs/coin-modules/coin-near/src/logic/transaction/validateIntent.ts | Implements intent validation mirroring bridge behavior. |
| libs/coin-modules/coin-near/src/logic/transaction/validateIntent.test.ts | Unit tests for transfer + staking validation rules. |
| libs/coin-modules/coin-near/src/logic/transaction/estimateFees.ts | Implements fee estimation using protocol-config–derived costs. |
| libs/coin-modules/coin-near/src/logic/transaction/estimateFees.test.ts | Unit tests for fee estimation and gasPrice overrides. |
| libs/coin-modules/coin-near/src/logic/transaction/craftTransaction.ts | Crafts unsigned NEAR tx bytes for the framework path. |
| libs/coin-modules/coin-near/src/logic/transaction/craftTransaction.test.ts | Unit tests for crafting, staking target resolution, access-key handling. |
| libs/coin-modules/coin-near/src/logic/transaction/craftTransaction.parity.test.ts | Ensures byte parity with legacy buildTransaction. |
| libs/coin-modules/coin-near/src/logic/transaction/combine.ts | Combines crafted tx + signature into signed tx bytes. |
| libs/coin-modules/coin-near/src/logic/transaction/combine.test.ts | Unit tests for combine + signature validation. |
| libs/coin-modules/coin-near/src/logic/transaction/broadcast.ts | Framework broadcast wrapper around network broadcast. |
| libs/coin-modules/coin-near/src/logic/transaction/broadcast.test.ts | Unit tests for broadcast wrapper behavior. |
| libs/coin-modules/coin-near/src/logic/staking/getValidators.ts | Maps indexer validators to framework Validator page. |
| libs/coin-modules/coin-near/src/logic/staking/getValidators.test.ts | Unit tests for validator mapping and request size. |
| libs/coin-modules/coin-near/src/logic/staking/getStakes.ts | Maps staking positions to framework Stake entries. |
| libs/coin-modules/coin-near/src/logic/staking/getStakes.test.ts | Unit tests for stake bucketing and thresholds. |
| libs/coin-modules/coin-near/src/logic/history/listOperations.ts | Implements paginated operations for framework path. |
| libs/coin-modules/coin-near/src/logic/history/listOperations.test.ts | Unit tests for operation mapping + paging rules. |
| libs/coin-modules/coin-near/src/logic/history/lastBlock.ts | Implements latest final block metadata. |
| libs/coin-modules/coin-near/src/logic/history/getBlockInfo.ts | Implements block metadata lookup and conversion. |
| libs/coin-modules/coin-near/src/logic/history/getBlockInfo.test.ts | Unit tests for block info conversion and reads. |
| libs/coin-modules/coin-near/src/logic/fees.ts | Centralizes fee formula for bridge + framework paths. |
| libs/coin-modules/coin-near/src/logic/fees.test.ts | Unit tests for fee computation modes and implicit accounts. |
| libs/coin-modules/coin-near/src/logic/actions.ts | Centralizes NEAR action building for bridge + framework paths. |
| libs/coin-modules/coin-near/src/logic/actions.test.ts | Unit tests for action building per mode. |
| libs/coin-modules/coin-near/src/logic/account/getBalance.ts | Implements framework balances (native + staking positions). |
| libs/coin-modules/coin-near/src/logic/account/getBalance.test.ts | Unit tests for balance ordering and locked computation. |
| libs/coin-modules/coin-near/src/logic.ts | Generalizes staking gas inputs to not require bridge Transaction. |
| libs/coin-modules/coin-near/src/getTransactionStatus.ts | Switches to network for account lookup. |
| libs/coin-modules/coin-near/src/getTransactionStatus.test.ts | Updates MSW mock import path for node mocking. |
| libs/coin-modules/coin-near/src/getFeesForTransaction.ts | Uses shared computeFees + new network/node gas price. |
| libs/coin-modules/coin-near/src/constants.ts | Adds VALIDATORS_COUNT constant. |
| libs/coin-modules/coin-near/src/buildTransaction.ts | Refactors legacy bridge building to reuse buildActions. |
| libs/coin-modules/coin-near/src/broadcast.ts | Switches legacy broadcast import to network. |
| libs/coin-modules/coin-near/src/api/parity.integ.test.ts | Mainnet parity tests between bridge and CoinModuleApi. |
| libs/coin-modules/coin-near/src/api/index.ts | Implements NEAR CoinModuleApi entry point. |
| libs/coin-modules/coin-near/src/api/index.test.ts | Unit tests that API delegates to logic implementations. |
| libs/coin-modules/coin-near/src/api/index.integ.test.ts | Mainnet integration coverage for CoinModuleApi surface. |
| libs/coin-modules/coin-near/.unimportedrc.json | Updates entrypoints/ignored files after api→network move. |
| .changeset/near-coinmodule-api.md | Adds changeset for coin-near + live-common minor bumps. |
Rsdoctor Bundle Diff AnalysisFound 7 projects in monorepo, 7 projects with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 desktop-mainPath:
📁 desktop-preloaderPath:
📁 desktop-rendererPath:
📁 desktop-webviewDappPreloaderPath:
📁 desktop-webviewPreloaderPath:
📁 desktop-workersPath:
📁 mobilePath:
Generated by Rsdoctor GitHub Action |
48c4f52 to
952f357
Compare
952f357 to
cc9d58f
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 55 out of 60 changed files in this pull request and generated no new comments.
Suppressed comments (1)
libs/coin-modules/coin-near/src/logic/history/listOperations.ts:28
block_timestampis a nanosecond timestamp encoded as a string and can exceed JS safe integer precision. UsingNumber.parseFloat(...)may introduce rounding drift. Converting viaBigIntkeeps the millisecond value exact and avoids precision loss.
export function toOperation(transaction: NearTransaction, address: string): Operation {
const type = getOperationType(transaction, address);
const date = new Date(Number.parseFloat(transaction.block_timestamp) / 1e6);
|



📝 Description
Exposes the CoinModuleApi surface for NEAR alongside the existing account bridge, covering the
native asset and delegated staking (stake / unstake / withdraw).
The generic-framework flag stays off, so Ledger Live keeps routing NEAR through the account bridge
and user-facing behaviour is unchanged. Enabling it needs UI work on the NEAR screens and lands
separately.
The account bridge and the new surface now share their logic rather than duplicating it:
logic/fees.tsholds the fee formula, used by bothgetFeesForTransactionandestimateFees.logic/actions.tsholds the action builder, used by bothbuildTransactionandcraftTransaction.network/protocolConfig.tsderives gas and storage costs from the protocol config behind a30-minute cache. The new path has no preload step, and the preload defaults are zeros, so
sourcing costs from them would have produced a zero fee.
src/api/moved tosrc/network/, sincesrc/api/index.tsis now the module factory.Scope: the ticket AC also lists tokens. NEAR has no NEP-141 support anywhere in Ledger Live,
including the account bridge, so there is nothing to migrate. Adding it is separate work.
Testing: 213 unit tests, including 7 that assert the crafted transaction is byte-identical to
the account bridge's, plus 40 integration tests against mainnet. Both paths were also exercised
manually in Ledger Live Desktop (balances, history, fees, validation, send-max, device signing and
a staking broadcast on mainnet); the values matched the account bridge to 8 decimals.
Enabling the framework for NEAR also needs a one-line fix in
generic-coin-framework/utils.ts, where an optimistic operation's fee is converted withtoString()instead oftoFixed(). BigNumber switches to exponential notation from 1e21 up andBigIntcannot parse it, which a NEAR staking fee (24 decimals) reaches at 0.0015. It is notspecific to NEAR, so it ships on its own.
🔗 Context