feat: build full Soroban contract client service layer - #19
Conversation
Add the Stellar SDK as a dependency for Soroban contract interactions. Create network.ts with testnet/mainnet config resolution from env vars. Update .env.example with SOROBAN_RPC_URL and DISTRIBUTOR_CONTRACT_ID. Refs: SoroProtocol#14
Create ContractError with typed error codes matching the contract's error enum (NotFound, Unauthorized, AlreadyCancelled, etc.). Add parseContractError() to map raw SDK/Soroban errors into typed exceptions so the UI can show meaningful user-facing messages. Refs: SoroProtocol#14
Add contract ID constants from env vars, shared config values, and TypeScript interfaces for all contract function args/returns (stream, vesting, distributor). Amounts use string to preserve bigint precision. Refs: SoroProtocol#14
Implement the full transaction lifecycle: build XDR, simulate to catch errors before Freighter pops up, sign via Freighter, submit, and poll for confirmation. Includes typed error handling, network-aware RPC client, and a high-level executeContractTx() helper. Refs: SoroProtocol#14
Implement create_stream, withdraw, cancel (write methods with full sign flow), and balance_of, get_stream (read-only simulation calls). Each method encodes the correct Soroban ScVal arguments. Refs: SoroProtocol#14
Implement vesting contract methods (create, claim, revoke, vested_of, get_schedule) and distributor methods (distribute, distribute_custom). Add barrel export index.ts for clean imports. Refs: SoroProtocol#14
Provide a clean React interface for contract calls with automatic loading state, error parsing (typed ContractError codes), and clearError utility. Wraps the contract service layer for use in page components. Refs: SoroProtocol#14
… vesting Replace all fake handlers with real contract interactions: - Create stream: builds rate/amount from form, calls createStream - Withdraw: calls withdrawStream with Freighter confirmation - Cancel: calls cancelStream with Freighter confirmation - Claim vesting: calls claimVesting with Freighter confirmation All pages now show loading states, error messages from typed ContractError codes, and success toasts with truncated tx hashes. Refs: SoroProtocol#14
Covers ContractError, parseContractError, network config, and contract constants validation. Adds vitest as devDependency. Issue SoroProtocol#14
|
went through the diff — the error types and the useContract hook are clean, good call on simulating before popping up Freighter. few things that'll bite you though: the method names in streams.ts don't match the actual contract. the rust code has createStream is passing the wrong args too. contract expects token encoding — you're doing the testnet passphrase in network.ts says and CI build is failing too — probably related to the type mismatches from the wrong arg shapes. the overall structure is solid though, just needs the contract details lined up with the actual rust code. |
- Fix contract method name: create_stream → create - Fix createStream args: add sender, use ratePerSecond instead of amount - Fix token encoding: use Address.fromString().toScVal() instead of bytes32 - Fix testnet passphrase: December 2022 → December 2014 - Fix Soroban tx assembly: use rpc.assembleTransaction() after simulation - Fix SDK API: SorobanRpc → rpc namespace, loadAccount → getAccount - Fix simulation result extraction: use result.retval directly Refs: SoroProtocol#14
|
Thanks for the thorough review — all 6 points addressed:
Also fixed SDK namespace ( TypeScript compiles clean, all 18 unit tests pass. |
|
LGTM, thanks for contributing |
Closes #14
What changed
@stellar/stellar-sdkdependency and network config resolution (testnet/mainnet)ContractError,ContractErrorCode) with error parsing from SDK responsescreateStream,withdrawStream,cancelStream,getStreamBalance,getStreamcreateVestingSchedule,claimVesting,revokeVesting,getVestedOf,getVestingScheduledistribute,distributeCustomuseContractReact hook for loading/error state managementWhy
Every on-chain button in the app was faked with
setTimeoutand toast-only handlers. This adds a proper contract service layer that handles the full Soroban transaction lifecycle, enabling real on-chain interactions.How to test
npm install && npm run build— should compile without errorsnpx vitest run— 18 unit tests should pass