Skip to content

Conversation

@0xYudhishthra
Copy link

Summary

Adds dynamic decimal detection and automatic slippage protection to support tokens with non-standard decimals (USDC, WBTC, etc.) in cross-chain vault operations. Fixes transaction failures caused by hardcoded 18-decimal assumptions and insufficient gas limits.

Problems Solved

  1. Hardcoded 18 decimals caused incorrect amount calculations for USDC (6 decimals), WBTC (8 decimals), and other tokens
  2. Insufficient gas limits (395k) caused destination transactions to fail
  3. Missing slippage tolerance on bridge hops and vault operations led to transaction reverts
  4. Human-readable amounts displayed wrong values for non-18-decimal tokens
  5. Minimal error logging made debugging quote failures difficult

Key Changes

Dynamic Decimal Detection

  • Fetches decimals dynamically from asset and share contracts
  • Correctly applies decimals based on token type (asset vs share)
  • Uses minimal ABI for reliable cross-chain compatibility

Slippage Protection

  • First hop (source to hub): 0.5% tolerance for bridge transfers
  • Vault operations: 0.5% buffer on expected output amounts
  • Uses BigNumber math to avoid precision loss

Gas and Reliability Improvements

  • Increased compose gas from 395k to 1M to prevent destination failures
  • Enhanced error logging with detailed messages and data
  • Added debug logs for amount calculations

Impact

Before:

  • USDC (6 decimals): Fails
  • WBTC (8 decimals): Fails
  • Slippage protection: None
  • Gas limit: 395k (causes failures)

After:

  • USDC (6 decimals): Works correctly
  • WBTC (8 decimals): Works correctly
  • Slippage protection: 0.5% automatic
  • Gas limit: 1M (sufficient)

Testing

Tested with:

  • USDC deposits and redemptions
  • Cross-chain flows with slippage

Files Changed

  • tasks/sendOVaultComposer.ts - Dynamic decimals, slippage protection, gas increase, enhanced logging

Breaking Changes

None. All changes are backward compatible.

…imal fetching

- Updated gas limit for cross-chain messaging to 1,000,000 to improve transaction success.
- Implemented dynamic fetching of token decimals for assets and shares instead of assuming 18 decimals.
- Adjusted vault preview calculations to use correct decimals based on token type.
- Added slippage protection for minimum output amount calculations.
- Improved error logging for quote failures to include detailed error information.
- Introduced first hop minimum amount calculation with slippage for stablecoin transfers.
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.

1 participant