feat: Implement transaction builder and fee estimation module (#45) - #58
Open
amankoli09 wants to merge 1 commit into
Open
feat: Implement transaction builder and fee estimation module (#45)#58amankoli09 wants to merge 1 commit into
amankoli09 wants to merge 1 commit into
Conversation
…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.
Contributor
|
please ensure all checks pass |
Author
|
@N-thnI will make it pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-serviceandvero-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
transactionmodule to standardize building transactions, managing data payloads, securing fee bounds, and properly configuring fee bump transactions without consuming additional sequence numbers.🏗️ Proposed Changes
buildTransaction): Introduced a standardized abstraction overstellar-sdk'sTransactionBuilderto enforce centralized timeout and network configurations.buildManageData): Centralized logic for interpreting protocol-specific data keys (e.g.,reputation,task,vote) and generating the exact binary XDR payloads.buildFeeBump): Added logic to construct fee bump transactions that correctly utilize the inner transaction's sequence number.estimateFee): Introduced a bounded fee estimation mechanism that fetches live statistics from the RPC node, clamps them between configuredminFeeandmaxFeelimits, and securely fails on edge-case exceptions.jest.config.jsto ensure proper ES Module (ESM) resolution for the underlying@stellar/stellar-sdkand its sub-dependencies (uint8array-extras,@exodus,@noble).📂 Files Changed
src/transaction/builder.tsbuildTransaction,buildManageData, andbuildFeeBumpusing type-safe generics overstellar-sdk.src/transaction/fees.tsestimateFeeroutine, resolving network-spike vulnerabilities.src/transaction/index.tssrc/index.tstransactionmodule.src/__tests__/transaction.test.tspackage.json/package-lock.json@stellar/stellar-sdkas a direct dependency for the SDK wrapper functions.jest.config.jstransformIgnorePatternsregex to parse underlying ESM imports gracefully during test runtime.🧠 Design Decisions & Architectural Notes
any: InbuildManageData,unknownwas utilized with robust type-casting (e.g.,as string | Buffer | null) to ensure TypeScript correctly infers logic flows without resorting to unsafeanyassertions, preserving the strict linting environment.Operation.fromXdrObjectwas used. This ensures that the generatedManageDatapayload strictly adheres to what the actual Stellar network will receive.VeroError): If the fee bounds provided via configuration are invalid (i.e.minFee > maxFee), the estimation process deliberately halts and emits a strongly-typedVeroErrorCode.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: