Repository navigation
Conversation
…d typed contract clients - Replace deprecated soroban-client with @stellar/stellar-sdk rpc module - Implement full contract invocation flow in walletContext: simulate -> assemble -> sign (Freighter) -> submit -> poll - Support simulateOnly for read-only contract queries - Implement generated typed contract clients for Staking, Puzzle Rewards, AI NFTs, and Arbiter Escrow - Add typed contract registry and getContractClient helper in wallet context - Add comprehensive unit test suite covering full invocation lifecycle and typed clients
|
@Babigdk Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This branch has not been deployed
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.
feat(wallet): implement Soroban simulate-sign-submit-poll pipeline and typed contract clients
What changed and why
Problem
Previously,
frontend/context/walletContext.tsxdynamically imported the deprecatedsoroban-clientpackage and instantiated an RPC client that unconditionally threw an error ("invokeSorobanContract: implement contract-specific invocation (ABI required)"). As a result, any application feature requiring smart contract interactions—such as liquidity staking (yield_staking), puzzle rewards (game_contract), AI companion NFTs (ai_nft), and arbiter escrow releases (arbiter_escrow)—failed immediately at runtime.Solution
@stellar/stellar-sdk: Removed deprecatedsoroban-clientand upgradedwalletContext.tsxto use the official@stellar/stellar-sdk'srpcandHorizonmodules.simulate→sign→submit→poll):G.../C...) into Sorobanxdr.ScVal.rpcServer.simulateTransaction(tx)to compute footprint, resource fees, and authorization entries.options.simulateOnlysupport which extracts and decodes the return value directly from the simulation result without prompting Freighter or incurring gas fees.rpc.assembleTransaction(tx, sim).build().@stellar/freighter-api(with graceful fallback to window-injected Freighter providers) and parses the signed envelope into a StellarTransaction.rpcServer.sendTransaction(signedTx).rpcServer.pollTransaction(hash)until reaching terminal status (SUCCESSorFAILED), then decodes thereturnValueback to native JavaScript structures.frontend/lib/contracts/:YieldStakingContractClient: Handles pool staking, unstaking, yield harvesting, and escrow claims.PuzzleRewardsContractClient: Handles claiming individual and batch puzzle completion rewards and verifying on-chain puzzle balances.AiNftContractClient: Handles companion NFT minting, transfers, metadata queries, and burning.ArbiterEscrowContractClient: Handles match escrow creation, funding, settling payouts/refunds, dispute filing, and arbiter voting.getContractClienttouseAppContextand implemented in-memory client registration to prefer typed clients across the UI.Issue: Closes the wallet context contract helper issue (simulate -> sign -> submit -> poll).
Summary of changes:
frontend/package.json&package-lock.json: Removed deprecatedsoroban-clientand installed@stellar/stellar-sdkv17.frontend/context/walletContext.tsx: Replaced stubbedinvokeSorobanContractwith fullsimulate → assemble → sign → submit → pollpipeline and addedgetContractClientfactory.frontend/lib/api.ts: Centralized contract ID environment variables (CONTRACT_STAKING,CONTRACT_GAME_ESCROW,CONTRACT_ELO_REGISTRY,CONTRACT_TOURNAMENT,CONTRACT_AI_NFT).frontend/lib/contracts/: Addedtypes.ts,baseClient.ts,stakingClient.ts,puzzleRewardsClient.ts,nftClient.ts,escrowClient.ts,registry.ts, andindex.ts.frontend/__tests__/walletContractInvocation.test.ts: Created 13 unit tests covering unconnected wallet protection, full lifecycle invocation,simulateOnlyqueries, error handling (simulation, submission, execution, timeout), and typed contract clients.frontend/vitest.config.ts&vitest.setup.ts: Configured dependency inlining and cross-realmUint8Array/localStoragesupport for jsdom test runner compatibility.How it was tested
npm test):npx vitest run __tests__/walletContractInvocation.test.tspassed (13/13 unit tests).npx tsc --noEmitexecuted with 0 type errors.npm run lintexecuted with 0 ESLint warnings and 0 errors.npm run buildcompleted successfully, verifying Next.js page generation and client bundle code splitting.Contributor Checklist
npm run lintpassed with 0 warnings/errors).__tests__/walletContractInvocation.test.tscovering invocation lifecycle and typed clients; all passing.mainbranch.frontend/lib/api.ts, and updated type definitions.invokeSorobanContract(contractId, functionName, args)signature while adding typed options and returns.Additional context
Soroban Invocation Lifecycle Flow
sequenceDiagram autonumber participant App as Component / Caller participant WC as WalletContext (invokeSorobanContract) participant RPC as Soroban RPC participant F as Freighter Wallet App->>WC: invokeSorobanContract(contractId, fn, args, options) WC->>WC: Convert args to xdr.ScVal & build tx WC->>RPC: simulateTransaction(tx) alt simulateOnly is true RPC-->>WC: Simulation Result (retval) WC-->>App: Return decoded retval else Mutating Contract Call RPC-->>WC: Simulation Data & Footprint WC->>WC: assembleTransaction(tx, sim) WC->>F: signTransaction(preparedTxXDR) F-->>WC: signedEnvelopeXDR WC->>RPC: sendTransaction(signedTx) RPC-->>WC: SendTransactionResponse (hash, status) loop Poll until confirmed WC->>RPC: pollTransaction(hash) RPC-->>WC: GetTransactionResponse (status, returnValue) end WC-->>App: Return { status: "SUCCESS", hash, returnValue } end Closes #1352