Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1) approveMax / maxUint256
- In approveMax, we hardcode 2n ** 256n - 1n:
- export async function approveMax(…): Promise { return
- approve(walletClient, publicClient, { token, spender, amount: 2n **
- 256n - 1n, // I think viem exposes maxUint256 / some constant we can
- reuse? }) }
- Maybe we should use a shared constant (from viem or our own) so we don’t
- repeat this / avoid magic numbers.
- 2) Safe math utils for share/slippage math
- In packages/core/src/actions/deposit.ts:
- const minShares = expectedShares - (expectedShares *
- BigInt(slippageBps)) / 10000n
- Can we add a safeMath util (we already have something similar in
- backend/dapp) and use it consistently for these calculations? Mainly to
- avoid edge cases (underflow, rounding surprises, etc.) and keep it
- uniform.
- 3) Missing input validation
- Right now it looks like we don’t validate some basics:
- - No validation that vault addresses are supported on the current
- chain
- - No validation that amounts are > 0
- - No address format validation
- At minimum we should validate addresses + amounts. Also: do we already
- have a helper/util that exports yoVaultsAddresses (or supported vaults)
- for easy access? If not, might be worth adding.
- 4) Fragile string matching for errors
- In packages/core/src/api/user.ts:
- catch (error) { if (error instanceof Error &&
- error.message.includes(‘404’)) { return null } throw error }
- This is pretty fragile (string matching on “404”). Better to check
- status codes in a structured way if possible.
- 5) Generic errors + unclear error surface
- Currently we throw generic Errors, e.g.:
- throw new Error(‘Wallet client must have an account’)
- No error codes, no custom types. From a dev UX perspective it’s hard to
- know what actually happened / what to handle.
- Related: in packages/core/src/api/vault.ts we bypass Zod validation:
- if (!parsed.success) { return response as VaultSnapshot // returns
- unvalidated data }
- That can silently pass bad data forward.
- I’d suggest structured errors (codes + context), e.g.:
- class YoError extends Error { constructor( public code: string, message:
- string, public context?: Record<string, any> ) { super(message) } }
- class VaultNotFoundError extends YoError {} class
- InsufficientBalanceError extends YoError {} class SlippageExceededError
- extends YoError {}
- Main point: make it obvious to SDK users what error they hit and how to
- react.
- 6) useYoKit vs useYoClient
- useYoKit and useYoClient look very similar — both seem to create a
- client. Is there a real difference intended here, or can we merge /
- clarify naming?
- 7) previewDeposit vs quotePreviewDeposit
- client.previewDeposit() client.quotePreviewDeposit()
- Are these doing different things, or are they basically the same? If
- they’re meant to differ, maybe we should document the difference or
- rename for clarity.
Advertisement
Add Comment
Please, Sign In to add comment