Skip to content

fix(builder): encode ScVals with ABI-correct integer types - #583

Merged
Jaydbrown merged 2 commits into
conduit-protocol:mainfrom
p4uld4vid016-code:fix/497-paramtoscval-int-types
Aug 31, 2026
Merged

fix(builder): encode ScVals with ABI-correct integer types#583
Jaydbrown merged 2 commits into
conduit-protocol:mainfrom
p4uld4vid016-code:fix/497-paramtoscval-int-types

Conversation

@p4uld4vid016-code

Copy link
Copy Markdown
Contributor

Closes #497

Problem

paramToScVal() in src/batch-tx.ts forced every integer number to i64 and every bigint to i128. create_stream's start_time/end_time are u64 and stream IDs are u64, so passing these through the params path produced the wrong ScVal type and a contract-side type error. The map path had no way to carry per-field type information.

Changes

  • paramToScVal(value, type?) — no longer blanket-encodes integers:
    • Untyped positive integers encode as u64, negatives as i64 (the natural SDK encoding, which matches the u64-heavy ABI).
    • An explicit type hint ('u64', 'i128', ...) forces a specific width.
    • Already-encoded xdr.ScVals pass through untouched.
  • Map path per-field typesBatchOperation.types (and BuildableOperation.types) supplies per-field ScVal type hints for params map entries, e.g. { method: 'withdraw', params: { streamId: 1n }, types: { streamId: 'u64' } }. ScValType is exported from the package entry point.
  • ConduitBatcher.execute() create_stream path — now builds ABI-exact positional args: deposit_amount/rate_per_sec as i128, start_time/end_time as u64 (honoring startTime/endTime/clawbackEnabled when present), clawback_enabled as bool.
  • Drive-by: removed a duplicate let consecutiveFailures declaration in src/events.ts (introduced on main in fix(sdk): dedupe progress calc, unify NonceManager, harden event polling (#482, #483, #484, #485) #499) that made the module a SyntaxError, breaking npm run typecheck, the npm ci build, and every event-subscription test; fixed the stale startLedger assertion in events-subscribe.test.ts that could never run before.

Tests

  • New src/tests/builder-param-encoding.test.ts covering the ABI-exact execute() create_stream args (decoded from real XDR), per-field types for u64 stream IDs, bigint amounts staying i128, and pre-encoded ScVal passthrough.
  • Updated batch-real-xdr.test.ts parameter-encoding tests for the new defaults + type hints + ScVal passthrough.
  • npm run typecheck, npm run lint, npm run build, and the full vitest suite (853 passed, 2 skipped) are green.

…rotocol#497)

paramToScVal() forced every integer number to i64 and every bigint to
i128, so u64 contract parameters — create_stream's start_time/end_time
and stream IDs — arrived with the wrong ScVal type and were rejected
contract-side. Untyped positive integers now encode as u64 (negatives
as i64), explicit ScVal type hints are supported, already-encoded
xdr.ScVals pass through untouched, and BatchOperation.types supplies
per-field type information for the params map. ConduitBatcher.execute()'s
create_stream path now builds ABI-exact positional args (i128 amounts,
u64 times, bool clawback) and honors startTime/endTime/clawbackEnabled.

Also removes a duplicate `let consecutiveFailures` in src/events.ts that
made the module a SyntaxError, breaking the build and every
event-subscription test.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@p4uld4vid016-code 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! 🚀

Learn more about application limits

@Jaydbrown
Jaydbrown merged commit 246b9bd into conduit-protocol:main Aug 31, 2026
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.

paramToScVal encodes every integer number as i64 and every bigint as i128

2 participants