PR #465 introduces (or will introduce, after its fix pass) two patterns in services/borrow.ts that lend/swap should also adopt:
- Narrowed wallet helper.
resolveWalletOrThrow(idToken) returns a SmartWallet narrowed to { borrow: NonNullable<...> } so call sites don't need wallet.borrow! non-null assertions.
- Typed receipt return without
as Type casts. Receipt-with-URLs shapes are constructed against the narrowed types rather than asserted.
Today:
services/lend.ts:51-52 uses wallet.lend!.openPosition(...) / wallet.lend!.closePosition(...) non-null assertions.
services/lend.ts:62 casts result with as LendTransactionReceiptWithUrls.
services/swap.ts:95 calls wallet.swap.execute(...) after a manual undefined check; could be narrowed by the same helper.
services/swap.ts similarly relies on inline shape construction without a typed helper.
If mutation request bodies in lend or swap ever adopt a { params \| quote } discriminated shape, also migrate them to z.discriminatedUnion for branch-targeted 400s (mirroring the borrow fix).
Acceptance
PR #465 introduces (or will introduce, after its fix pass) two patterns in
services/borrow.tsthat lend/swap should also adopt:resolveWalletOrThrow(idToken)returns aSmartWalletnarrowed to{ borrow: NonNullable<...> }so call sites don't needwallet.borrow!non-null assertions.as Typecasts. Receipt-with-URLs shapes are constructed against the narrowed types rather than asserted.Today:
services/lend.ts:51-52useswallet.lend!.openPosition(...)/wallet.lend!.closePosition(...)non-null assertions.services/lend.ts:62casts result withas LendTransactionReceiptWithUrls.services/swap.ts:95callswallet.swap.execute(...)after a manual undefined check; could be narrowed by the same helper.services/swap.tssimilarly relies on inline shape construction without a typed helper.If mutation request bodies in lend or swap ever adopt a
{ params \| quote }discriminated shape, also migrate them toz.discriminatedUnionfor branch-targeted 400s (mirroring the borrow fix).Acceptance
resolveWalletForProvider<P>(idToken, 'lend' \| 'swap' \| 'borrow')(or three sibling helpers) that returns the narrowed wallet type.wallet.lend!andwallet.swapusages with calls through the helper.as LendTransactionReceiptWithUrls/ similar casts by typing the constructor instead.z.discriminatedUnion.