Skip to content

feat: Implement transaction builder and fee estimation module (#45) - #58

Open
amankoli09 wants to merge 1 commit into
Vero-protocol:mainfrom
amankoli09:feat/issue-45-transaction-module
Open

feat: Implement transaction builder and fee estimation module (#45)#58
amankoli09 wants to merge 1 commit into
Vero-protocol:mainfrom
amankoli09:feat/issue-45-transaction-module

Conversation

@amankoli09

Copy link
Copy Markdown

Title:

feat: Implement Transaction Construction and Fee Estimation Module (#45)

Closes #45

📖 Description & Motivation

This PR resolves #45 by delivering a unified, safe, and heavily tested transaction-construction module for the Vero SDK.

Historically, transaction building was duplicated across services (vero-relayer-service and vero-guardian-dashboard) with divergent default configurations for fees, timeouts, and networks. This fragmentation often led to non-obvious failure states, particularly during network congestion. Crucially, the lack of upper bounds on network fee polling exposed the protocol to fund-loss risks during network fee spikes.

This PR establishes a centralized transaction module to standardize building transactions, managing data payloads, securing fee bounds, and properly configuring fee bump transactions without consuming additional sequence numbers.

🏗️ Proposed Changes

  • Transaction Builder Wrapper (buildTransaction): Introduced a standardized abstraction over stellar-sdk's TransactionBuilder to enforce centralized timeout and network configurations.
  • Manage Data Abstraction (buildManageData): Centralized logic for interpreting protocol-specific data keys (e.g., reputation, task, vote) and generating the exact binary XDR payloads.
  • Fee Bump Integration (buildFeeBump): Added logic to construct fee bump transactions that correctly utilize the inner transaction's sequence number.
  • Safe Fee Estimation (estimateFee): Introduced a bounded fee estimation mechanism that fetches live statistics from the RPC node, clamps them between configured minFee and maxFee limits, and securely fails on edge-case exceptions.
  • Jest Configuration Overhaul: Enhanced the local jest.config.js to ensure proper ES Module (ESM) resolution for the underlying @stellar/stellar-sdk and its sub-dependencies (uint8array-extras, @exodus, @noble).

📂 Files Changed

File Path Type Description
src/transaction/builder.ts New Exposes buildTransaction, buildManageData, and buildFeeBump using type-safe generics over stellar-sdk.
src/transaction/fees.ts New Enforces the bounded estimateFee routine, resolving network-spike vulnerabilities.
src/transaction/index.ts New Module entry point exporting all builder and fee abstractions.
src/index.ts Modified Updated the global SDK export to expose the new transaction module.
src/__tests__/transaction.test.ts New Comprehensive test suite enforcing logic boundaries, XDR parsing checks, and RPC exception handling.
package.json / package-lock.json Modified Installed @stellar/stellar-sdk as a direct dependency for the SDK wrapper functions.
jest.config.js Modified Updated transformIgnorePatterns regex to parse underlying ESM imports gracefully during test runtime.

🧠 Design Decisions & Architectural Notes

  1. Type Safety over any: In buildManageData, unknown was utilized with robust type-casting (e.g., as string | Buffer | null) to ensure TypeScript correctly infers logic flows without resorting to unsafe any assertions, preserving the strict linting environment.
  2. XDR De-serialization in Testing: Instead of interacting directly with raw JS-XDR buffers in tests, Operation.fromXdrObject was used. This ensures that the generated ManageData payload strictly adheres to what the actual Stellar network will receive.
  3. Graceful Failures (VeroError): If the fee bounds provided via configuration are invalid (i.e. minFee > maxFee), the estimation process deliberately halts and emits a strongly-typed VeroErrorCode.Unknown, allowing upstream services to catch and gracefully exit.

🧪 Testing & Validation

All configurations have been strictly verified. The test suite simulates actual payload generation and evaluates the resulting XDR signatures.

Test Results:

> @vero-protocol/sdk@0.1.0 test
> jest

PASS src/account/__tests__/data.test.ts
PASS src/account/__tests__/loader.test.ts
PASS src/__tests__/errors.test.ts
PASS src/__tests__/nonce.concurrency.test.ts
PASS src/__tests__/transaction.test.ts
PASS src/account/__tests__/index.test.ts
PASS src/account/__tests__/balances.test.ts
PASS src/__tests__/network.test.ts
PASS src/__tests__/rpc.test.ts
PASS src/__tests__/types.test.ts

Test Suites: 10 passed, 10 total
Tests:       132 passed, 132 total
Snapshots:   0 total
Time:        2.956 s
Ran all test suites.

…rotocol#45)

- Added src/transaction/builder.ts to wrap TransactionBuilder functionality with proper type handling and manageData serialization.
- Added src/transaction/fees.ts to implement bounded fee estimation, throwing VeroError when network estimates exceed configured bounds.
- Configured Jest tests for building and estimating fees, and updated jest configuration to support stellar-sdk ESM resolution.
- Exported transaction module in index.ts.
@N-thnI

N-thnI commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

please ensure all checks pass

@amankoli09

Copy link
Copy Markdown
Author

@N-thnI will make it pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the transaction module: builder, fee estimation, and fee bump

2 participants