Lombard 백서

Lombard

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 16쪽 중 16쪽

’ll need: Sepolia ETH — For gas fees on Ethereum Sepolia Signet BTC — For BTC staking tests Switching Environments Use environment variables to switch between environments at runtime: import { createConfig, Env } from '@lombard.finance/sdk' ; const env = process.env. LOMBARD_ENV === 'production' ? Env.prod : Env.testnet; const config = createConfig ({ env, partner: { partnerId: env === Env.prod ? 'YOUR_PARTNER_ID' : 'test' , }, providers: { evm : () => window.ethereum, }, }); Note: Use partnerId: 'test' in non-production environments to bypass captcha. See Partners for production setup. ## /build/sdk/concepts Concepts Before implementing SDK actions, it helps to understand the core patterns that govern how the SDK works. Core Concepts Action Lifecycle How SDK actions are structured, executed, and managed through their complete state machine. Fee Authorization EIP-712 signature requirements for Ethereum Mainnet transactions and signature reuse approaches. Event Handling Subscribe to action events for tracking progress, status changes, and operation completion. Error Handling The LombardError structure, error codes, validation failures, and retry logic implementation. BTC Deposit Addresses Generate and reuse blockchain-specific Bitcoin deposit addresses with signature binding. Referral System Track user acquisition by attaching referral identifiers to deposit addresses. Reference Materials For technical details, see the Reference section: TypeScript Types — Type definitions for SDK interfaces, parameters, and return values Events Reference — Event constants and payload types for observing SDK operations Error Codes — Comprehensive catalog of error codes with descriptions ## /build/sdk/concepts/action-lifecycle Action Lifecycle Actions are the core building blocks of the SDK. Each action represents a multi-step blockchain operation with state management, event updates, error handling, and retry capabilities. Core Pattern Every SDK action follows four sequential stages: 1 Create Initialize the action with configuration (chain, asset, protocol) 2 Prepare Validate parameters and verify requirements (amount, recipient) 3 Authorize Sign required messages and transactions 4 Execute Complete the primary operation Each phase transitions the action to a new state. State Management Actions maintain three independent properties: Property Type Description status string Current step in the process isLoading boolean Whether async work is happening error LombardError | null Any issue that occurred These properties operate independently, allowing an action to carry both state information and error details simultaneously. Status Tracking BTC Actions IDLE NEEDS_FEE_AUTHORIZATION READY ADDRESS_READY Or for non-Ethereum chains: BTC Actions (Non-ETH) IDLE NEEDS_ADDRESS_CONFIRMATION READY ADDRESS_READY EVM Actions IDLE NEEDS_APPROVAL READY CONFIRMING COMPLETED Non-EVM Unstake IDLE READY CONFIRMING COMPLETED Error Recovery When an error occurs, the status stays at the step where it happened. This design lets users retry the same operation without losing context or starting over. // Check status before calling next method if (stake.status === BtcActionStatus. NEEDS_FEE_AUTHORIZATION ) { await stake. authorize (); } Always inspect the status property before calling subsequent methods to ensure the action has progressed to the appropriate stage. ## /build/sdk/concepts/fee-authorization Fee Authorization Fee authorization applies when staking BTC to Ethereum Mainnet or Sepolia. The SDK requests an EIP-712 signature to authorize the network fee via the authorize() step. EVM Destinations (Ethereum Mainnet) For Ethereum-based destinations, the workflow moves through: IDLE → NEEDS_FEE_AUTHORIZATION → READY → ADDRESS_READY The prepare() method initiates this sequence, followed by authorize() to obtain the necessary signature. Signature Reusability Previously stored fee signatures can be reused. When calling prepare() again, if a valid signature exists from a previous operation, prepare() will skip directly to READY . This eliminates redundant user prompts. Non-EVM Destinations Non-EVM destinations (Base, Solana, Sui, etc.) follow a different pattern using address confirmation rather than fee authorization: IDLE → NEEDS_ADDRESS_CONFIRMATION → READY → ADDRESS_READY This involves signing a message confirming the destination chain identifier instead of authorizing network fees. Implementation Check the returned status after prepare() to determine whether fee authorization is necessary: const stake = sdk.chain.btc. stake ({ destChain: Chain. ETHEREUM , assetOut: AssetId. LBTC , }); await stake. prepare ({ amount: '0.1' , recipient: '0x1234...' , }); // Check if authorization is needed if (stake.status === BtcActionStatus. NEEDS_FEE_AUTHORIZATION ) { await stake. authorize (); } // Now ready to generate deposit address const address = await stake. generateDepositAddress ();
프로젝트로 돌아가기