Skip to content

Latest commit

 

History

History
262 lines (207 loc) · 7.05 KB

File metadata and controls

262 lines (207 loc) · 7.05 KB

WDK Capabilities for DeFi Operations

Summary

Yes, Tether's WDK can handle ALL the operations you mentioned:

  1. ✅ RPC provider connections
  2. ✅ Contract interactions (read-only calls)
  3. ✅ Encoding/decoding function data
  4. ✅ Gas estimation

Detailed Breakdown

1. RPC Provider Connections

WDK Supports:

  • Direct RPC endpoint URLs
  • EIP-1193 provider instances
  • Automatic fee rate fetching
  • Network-aware operations

Example:

const wallet = new WalletManagerEvm(seedPhrase, {
  provider: 'https://ethereum-rpc.publicnode.com',
  transferMaxFee: 100000000000000 // in wei
})

Methods:

  • getFeeRates() - Returns normal and fast fee rates
  • Automatic RPC calls for all operations

2. Contract Interactions (Read-Only)

WDK Provides:

  • getAccountData() - Read Aave account data
  • getTokenBalance(tokenAddress) - Read ERC-20 balance
  • getTokenBalances(tokenAddresses) - Batch read balances
  • getAllowance(token, spender) - Read token allowances
  • Protocol-specific read methods via lending modules

Example:

const aave = new AaveProtocolEvm(account)

// Read-only operations
const data = await aave.getAccountData()
console.log({
  totalCollateralBase: data.totalCollateralBase,
  totalDebtBase: data.totalDebtBase,
  availableBorrowsBase: data.availableBorrowsBase,
  currentLiquidationThreshold: data.currentLiquidationThreshold,
  ltv: data.ltv,
  healthFactor: data.healthFactor
})

const balance = await account.getTokenBalance('0xdAC17F958D2ee523a2206206994597C13D831ec7')

3. Encoding/Decoding Function Data

WDK Handles:

  • Automatic function encoding for all operations
  • Protocol-specific method encoding
  • Transaction data preparation
  • No manual ABI encoding needed

Example:

// WDK automatically encodes the function call
const result = await aave.supply({ 
  token: '0xdAC17F958D2ee523a2206206994597C13D831ec7', // USDT
  amount: 1000000n 
})
// Returns: { hash: '0x...', fee: BigInt(...) }

Supported Operations:

  • supply() - Encodes Aave supply function
  • withdraw() - Encodes Aave withdraw function
  • borrow() - Encodes Aave borrow function
  • repay() - Encodes Aave repay function
  • approve() - Encodes ERC-20 approve function
  • transfer() - Encodes ERC-20 transfer function

4. Gas Estimation

WDK Provides:

  • estimateFee(transaction) - Estimate transaction fee
  • quoteSupply() - Quote supply operation with fee
  • quoteWithdraw() - Quote withdraw operation with fee
  • quoteBorrow() - Quote borrow operation with fee
  • quoteRepay() - Quote repay operation with fee
  • estimateTransfer() - Estimate ERC-20 transfer fee
  • getFeeRates() - Get current network fee rates

Example:

// Get fee estimate before executing
const supplyQuote = await aave.quoteSupply({ 
  token: USDT, 
  amount: 1000000n 
})
console.log('Supply fee estimate:', supplyQuote.fee)

// Get current network fee rates
const rates = await wallet.getFeeRates()
console.log({
  normal: rates.normal,  // Base fee × 1.1
  fast: rates.fast       // Base fee × 2.0
})

WDK Modules Available

Core Wallet Module

  • Package: @tetherto/wdk-wallet-evm
  • Features: BIP-39/BIP-44 wallet management, signing, basic operations

Lending Protocol Modules

  • Aave: @tetherto/wdk-protocol-lending-aave-evm
  • Compound: @tetherto/wdk-protocol-lending-compound-evm (if available)
  • Spark: @tetherto/wdk-protocol-lending-spark-evm (if available)

Account Abstraction

  • ERC-4337: @tetherto/wdk-wallet-evm-erc-4337
  • Features: Paymaster support, bundler integration, gasless transactions

Bridge Modules

  • USDT Bridge: @tetherto/wdk-bridge-usdt0-evm
  • Cross-chain operations: Bridge USDT across chains

Comparison: ethers vs WDK

Operation ethers WDK
RPC Provider ✅ Yes ✅ Yes
Read-only calls ✅ Yes ✅ Yes
Function encoding ✅ Manual ✅ Automatic
Gas estimation ✅ Yes ✅ Yes
Transaction signing ✅ Yes ✅ Yes (WDK-native)
Protocol abstraction ❌ No ✅ Yes (Aave, Compound, etc.)
Quote operations ❌ No ✅ Yes
Account data ❌ No ✅ Yes (protocol-specific)
ERC-4337 support ⚠️ Limited ✅ Full
Paymaster support ❌ No ✅ Yes

Recommended Migration Path

Current Architecture (ethers + WDK)

ethers (RPC, contracts, encoding)
    ↓
WDK (wallet, signing)

Optimized Architecture (WDK-only)

WDK (everything)
    ├── Wallet management
    ├── RPC connections
    ├── Protocol operations
    ├── Gas estimation
    └── Transaction signing

Implementation Strategy

Phase 1: Replace RPC Provider

// Before: ethers
const provider = new ethers.JsonRpcProvider(rpcUrl)

// After: WDK
const wallet = new WalletManagerEvm(seedPhrase, { provider: rpcUrl })

Phase 2: Replace Contract Interactions

// Before: ethers
const contract = new ethers.Contract(address, abi, provider)
const data = await contract.getReserveData(tokenAddress)

// After: WDK
const aave = new AaveProtocolEvm(account)
const data = await aave.getAccountData()

Phase 3: Replace Gas Estimation

// Before: ethers
const gasLimit = await provider.estimateGas({ from, to, data })

// After: WDK
const quote = await aave.quoteSupply({ token, amount })
console.log('Fee:', quote.fee)

Phase 4: Replace Function Encoding

// Before: ethers
const iface = new ethers.Interface(abi)
const data = iface.encodeFunctionData('supply', [asset, amount, user, 0])

// After: WDK
const result = await aave.supply({ token: asset, amount })
// Encoding is automatic

Benefits of WDK-Only Approach

  1. Unified Security Model: All operations go through WDK's security layer
  2. Simplified Code: No manual ABI encoding or contract instantiation
  3. Protocol Abstraction: Built-in support for Aave, Compound, Spark
  4. Better Error Handling: Protocol-specific error messages
  5. Gas Optimization: Built-in fee estimation and optimization
  6. Account Abstraction: Native ERC-4337 support for gasless transactions
  7. Paymaster Support: Can use paymasters to cover gas fees
  8. Reduced Dependencies: One less library to maintain

Current Status

YieldKernel currently uses:

  • ✅ WDK for wallet management (correct)
  • ⚠️ ethers for RPC and contracts (can be replaced)

Recommendation: Migrate to WDK-only for:

  • Stronger security posture
  • Cleaner code
  • Better protocol integration
  • Native support for advanced features (ERC-4337, paymasters)

Next Steps

  1. Install WDK Aave module: npm install @tetherto/wdk-protocol-lending-aave-evm
  2. Replace ethers RPC provider with WDK provider
  3. Replace contract interactions with WDK protocol methods
  4. Remove ethers dependency (if not needed elsewhere)
  5. Update gas estimation to use WDK quotes
  6. Test all operations with WDK-only stack

This would make YieldKernel a pure WDK-based solution with maximum security and protocol integration.