### Install Blend SDK Source: https://github.com/blend-capital/blend-sdk-js/blob/main/README.md Install the Blend SDK using npm. This is the first step to using the SDK in your Javascript project. ```bash npm install @blend-capital/blend-sdk ``` -------------------------------- ### Example Usage of PoolFactoryContractV2.deployPool() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-factory-contract.md This example demonstrates how to instantiate PoolFactoryContractV2 and use the deployPool method with specific arguments. Ensure you import necessary modules like PoolFactoryContractV2 and randomBytes. ```typescript import { PoolFactoryContractV2 } from '@blend-capital/blend-sdk'; import { randomBytes } from 'crypto'; const factory = new PoolFactoryContractV2('CFACTORY...'); const operation = factory.deployPool({ admin: 'GADMIN...', name: 'Blend Main Pool V2', salt: randomBytes(32), oracle: 'CORACLE...', min_collateral: BigInt(10000000), // 1 unit in oracle decimals backstop_take_rate: 4000000, // 0.4 in 7 decimals max_positions: 5, }); ``` -------------------------------- ### Install Blend SDK JS Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/README.md Install the Blend SDK JS package using npm. ```bash npm install @blend-capital/blend-sdk ``` -------------------------------- ### Execute Pool Reserve Setup Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-contract.md Executes the queued set of a reserve in the pool. Use this to finalize the setup of a reserve after it has been queued. ```typescript setReserve(asset: Address | string): string ``` -------------------------------- ### Example Usage of PoolEstimate.build() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-data-classes.md Demonstrates how to load pool and oracle data and then build a PoolEstimate for display. Ensure necessary imports are included. ```typescript import { Pool, PoolEstimate } from '@blend-capital/blend-sdk'; const pool = await PoolV1.load(network, poolId); const oracle = await pool.loadOracle(); const estimate = PoolEstimate.build(pool.reserves, oracle); console.log(`Total supplied: $${estimate.totalSupply}`); console.log(`Total borrowed: $${estimate.totalBorrowed}`); console.log(`Average borrow APY: ${estimate.avgBorrowApy * 100}%`); ``` -------------------------------- ### Example Network Configuration Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/types-and-utilities.md Demonstrates how to define network configurations for both public testnet and local Stellar RPC instances. Ensure correct passphrases and RPC endpoints are used. ```typescript import { Network } from '@blend-capital/blend-sdk'; const network: Network = { rpc: 'https://soroban-testnet.stellar.org', passphrase: 'Test SDF Network ; September 2015', maxConcurrentRequests: 10, }; // For local RPC const localNetwork: Network = { rpc: 'http://localhost:8000', passphrase: 'Standalone Network ; February 2022', opts: { allowHttp: true }, }; ``` -------------------------------- ### Example: Using PositionsEstimate.build() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-data-classes.md Demonstrates how to load pool and user data and then use `PositionsEstimate.build()` to calculate and log estimated user positions and health factor. ```typescript import { PositionsEstimate } from '@blend-capital/blend-sdk'; const pool = await PoolV1.load(network, poolId); const oracle = await pool.loadOracle(); const user = await pool.loadUser(userId); const estimate = PositionsEstimate.build(pool, oracle, user.positions); console.log(`Supplied: $${estimate.userSuppliedUsd}`); console.log(`Borrowed: $${estimate.userBorrowedUsd}`); console.log(`Health factor: ${estimate.healthFactor}`); ``` -------------------------------- ### Example Usage of BackstopPool.load() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-data-classes.md Demonstrates how to load backstop pool data and access its properties like pool tokens and Q4W percentage. Ensure the BackstopPool class is imported. ```typescript import { BackstopPool } from '@blend-capital/blend-sdk'; const backstopPool = await BackstopPool.load(network, backstopId, poolId); console.log(`Pool backstop size: ${backstopPool.tokens}`); console.log(`Q4W percent: ${backstopPool.q4wPercent}`); ``` -------------------------------- ### Example Usage of BackstopPoolUserEst.build() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-data-classes.md Demonstrates how to load necessary backstop data and use the BackstopPoolUserEst.build() method to generate and log estimates for a user's backstop position. Ensure Backstop, BackstopPool, and BackstopPoolUser objects are loaded prior to calling build. ```typescript import { BackstopPoolUserEst } from '@blend-capital/blend-sdk'; const backstop = await Backstop.load(network, backstopId); const backstopPool = await BackstopPool.load(network, backstopId, poolId); const backstopPoolUser = await BackstopPoolUser.load(network, backstopId, poolId, userId); const estimate = BackstopPoolUserEst.build(backstop, backstopPool, backstopPoolUser); console.log(`LP tokens held: ${estimate.lpTokensHeld}`); console.log(`Queued value: $${estimate.totalValueQueued}`); console.log(`Claimable BLND: ${estimate.blndClaimable}`); ``` -------------------------------- ### Handle Specific Errors with Try-Catch Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/QUICK-START.md Use a try-catch block to gracefully handle potential errors during pool loading. This example shows how to identify and respond to specific error messages like malformed ledger data or resource not found. ```typescript try { const pool = await PoolV1.load(network, poolId); } catch (error) { if (error.message.includes('LedgerEntryParseError')) { console.error('Ledger data malformed'); } else if (error.message.includes('Unable to find')) { console.error('Resource not found'); } } ``` -------------------------------- ### Get Pool Configuration Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-contract.md Fetches the current configuration settings of the pool. ```typescript getConfig(): string ``` -------------------------------- ### Load Pool and Get Estimates Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/00-START-HERE.md Load a pool and its associated oracle to build an estimate of pool reserves. This pattern is useful for understanding the current state and potential of a pool. ```typescript const pool = await PoolV1.load(network, poolId); const oracle = await pool.loadOracle(); const estimate = PoolEstimate.build(pool.reserves, oracle); ``` -------------------------------- ### Reserve.getBTokenEmissionIndex() Method Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-data-classes.md Gets the bToken (supply token) emission index. The index is calculated as config.index * 2 + 1. ```typescript getBTokenEmissionIndex(): number ``` -------------------------------- ### Reserve.getBTokenEmissionIndex() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-data-classes.md Gets the bToken (supply token) emission index. ```APIDOC ## Reserve.getBTokenEmissionIndex() ### Description Gets the bToken (supply token) emission index. ### Method `getBTokenEmissionIndex(): number` ### Parameters None ### Request Example ```typescript const bTokenIndex = reserve.getBTokenEmissionIndex(); ``` ### Response #### Success Response (200) `number` - The bToken emission index (config.index * 2 + 1). ``` -------------------------------- ### Reserve.getDTokenEmissionIndex() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-data-classes.md Gets the dToken (borrow token) emission index. ```APIDOC ## Reserve.getDTokenEmissionIndex() ### Description Gets the dToken (borrow token) emission index. ### Method `getDTokenEmissionIndex(): number` ### Parameters None ### Request Example ```typescript const dTokenIndex = reserve.getDTokenEmissionIndex(); ``` ### Response #### Success Response (200) `number` - The dToken emission index (config.index * 2). ``` -------------------------------- ### Get Pool Admin Address Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-contract.md Fetches the address of the current administrator of the pool. ```typescript getAdmin(): string ``` -------------------------------- ### Get Reserve List Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-contract.md Fetches a list containing the addresses of all reserve assets currently in the pool. ```typescript getReserveList(): string ``` -------------------------------- ### EmitterContract.initialize Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/emitter-contract.md Initializes the Emitter contract with the Blend token, backstop module, and backstop token addresses. ```APIDOC ## EmitterContract.initialize() ### Description Initializes the Emitter contract. ### Method initialize ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **contractArgs.blnd_token** (Address | string) - Required - The Blend token Address the Emitter will distribute - **contractArgs.backstop** (Address | string) - Required - The backstop module address to emit to - **contractArgs.backstop_token** (Address | string) - Required - The token the backstop takes deposits in ### Request Example ```typescript import { EmitterContract } from '@blend-capital/blend-sdk'; const emitter = new EmitterContract('CEMITTER...'); const operation = emitter.initialize({ blnd_token: 'CBLND...', backstop: 'CBACKSTOP...', backstop_token: 'CBACKSTOP_TOKEN...', }); ``` ### Response #### Success Response (200) - **string** - Base64-encoded XDR operation string #### Response Example None provided. ``` -------------------------------- ### Get Queued Backstop Swap Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/emitter-contract.md Fetches information about the currently queued backstop swap, if any exists. ```typescript emitter.getQueuedSwap() ``` -------------------------------- ### Deploy New Lending Pool V1 Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-factory-contract.md Deploys and initializes a new lending pool with specified parameters. This includes setting the admin, name, salt, oracle, backstop take rate, and maximum positions. Returns a Base64-encoded XDR operation string. ```typescript import { PoolFactoryContractV1 } from '@blend-capital/blend-sdk'; import { randomBytes } from 'crypto'; const factory = new PoolFactoryContractV1('CFACTORY...'); const operation = factory.deployPool({ admin: 'GADMIN...', name: 'Blend Main Pool', salt: randomBytes(32), oracle: 'CORACLE...', backstop_take_rate: 4000000, // 0.4 in 7 decimals max_positions: 5, }); ``` -------------------------------- ### Get Reserve Emissions Data Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-contract.md Fetches the emissions data associated with a specific reserve token ID. ```typescript getReserveEmissions(reserve_token_id: number): string ``` -------------------------------- ### Reserve.getDTokenEmissionIndex() Method Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-data-classes.md Gets the dToken (borrow token) emission index. The index is calculated as config.index * 2. ```typescript getDTokenEmissionIndex(): number ``` -------------------------------- ### Initialize Stellar RPC Server Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/README.md Instantiate a Stellar RPC Server object to load data. This requires a Stellar RPC endpoint and options. ```typescript import { rpc } from '@stellar/stellar-sdk'; const stellarRpc = new rpc.Server(network.rpc, network.opts); ``` -------------------------------- ### BackstopContractV1.initialize Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-contract.md Initializes the backstop contract with necessary token and contract addresses, as well as an initial drop list. This method is part of the V1 contract and requires detailed constructor arguments. ```APIDOC ## BackstopContractV1.initialize ### Description Initializes the backstop contract. ### Method (Not specified, likely a contract method call) ### Endpoint (Not applicable, SDK method) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body - **contractArgs.backstop_token** (Address | string) - Required - The address of the backstop token - **contractArgs.emitter** (Address | string) - Required - The address of the emitter contract - **contractArgs.usdc_token** (Address | string) - Required - The address of the USDC token - **contractArgs.blnd_token** (Address | string) - Required - The address of the BLND token - **contractArgs.pool_factory** (Address | string) - Required - The address of the pool factory - **contractArgs.drop_list** (Array<[string, i128]>) - Required - Initial drop list of addresses and amounts ### Response #### Success Response - **(string)** - Base64-encoded XDR operation string ### Request Example (Not applicable, SDK method) ### Response Example (Not applicable, SDK method) ``` -------------------------------- ### Get Current Backstop Module Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/emitter-contract.md Fetches the address of the current backstop module managed by the Emitter contract. ```typescript emitter.getBackstop() ``` -------------------------------- ### PoolContract.setReserve() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-contract.md Executes the queued set of a reserve in the pool. This method finalizes the setup process for a reserve that has been previously queued. ```APIDOC ## PoolContract.setReserve() ### Description Executes the queued set of a reserve in the pool. ### Method setReserve ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body - **asset** (Address | string) - Required - The underlying asset address to setup ### Request Example ```json { "asset": "address" } ``` ### Response #### Success Response (200) - **string** - Base64-encoded XDR operation string #### Response Example ```json { "example": "base64EncodedXdr" } ``` ### Throws Will throw if the reserve is not queued for initialization, is already setup, or has invalid metadata. ``` -------------------------------- ### BackstopPoolEst.build() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-data-classes.md Builds floating-point estimates for backstop pool data, including LP token value, BLND value, USDC value, and total value, from backstop token and pool data. ```APIDOC ## BackstopPoolEst.build() ### Description Builds estimates from backstop token and pool data. ### Method `static build(backstopToken: BackstopToken, poolBalance: i128): BackstopPoolEst` ### Parameters #### Path Parameters * **backstopToken** (BackstopToken) - Required - The backstop token data * **poolBalance** (i128) - Required - The pool's backstop share balance ### Response #### Success Response (BackstopPoolEst) - **lpTokenValue** (number) - The estimated value of LP tokens. - **blndValue** (number) - The estimated value of BLND tokens. - **usdcValue** (number) - The estimated value of USDC tokens. - **totalValue** (number) - The total estimated value. ### Request Example ```typescript import { BackstopPoolEst } from '@blend-capital/blend-sdk'; const backstop = await Backstop.load(network, backstopId); const backstopPool = await BackstopPool.load(network, backstopId, poolId); const estimate = BackstopPoolEst.build(backstop.backstopToken, backstopPool.tokens); console.log(`BLND value: $${estimate.blndValue}`); console.log(`USDC value: $${estimate.usdcValue}`); ``` ``` -------------------------------- ### Get User Emissions Data Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-contract.md Fetches the emissions data for a user's specific position within a reserve. ```typescript getUserEmissions(user: Address | string, reserve_token_id: number): string ``` -------------------------------- ### Deploy Backstop V2 Contract Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-contract.md Use this static method to deploy a new instance of the Backstop V2 contract. It requires the deployer's address, the WASM hash of the contract, and constructor arguments. An optional salt and format for the WASM hash can be provided. ```typescript static deploy( deployer: string, wasmHash: Buffer | string, args: BackstopConstructorArgs, salt?: Buffer, format?: 'hex' | 'base64' ): string ``` -------------------------------- ### Get Reserve Information Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-contract.md Fetches detailed information about a specific reserve asset, updated to the current ledger state. ```typescript getReserve(asset: Address | string): string ``` -------------------------------- ### BackstopConfig.load() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-data-classes.md Loads the backstop configuration from the ledger. This static method requires network information and the backstop contract address to fetch the configuration. ```APIDOC ## BackstopConfig.load() ### Description Loads the backstop configuration from the ledger. ### Method static async load ### Parameters #### Path Parameters - **network** (Network) - Required - The network to load from - **backstopId** (string) - Required - The backstop contract address ### Response #### Success Response (Promise) - **BackstopConfig** - The backstop configuration ``` -------------------------------- ### Configure Network Settings Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/README.md Define network configurations for connecting to the Stellar network, including testnet and local development environments. ```typescript import { Network, PoolV1 } from '@blend-capital/blend-sdk'; const network: Network = { rpc: 'https://soroban-testnet.stellar.org', passphrase: 'Test SDF Network ; September 2015', }; // For local development const localNetwork: Network = { rpc: 'http://localhost:8000', passphrase: 'Standalone Network ; February 2022', opts: { allowHttp: true }, }; ``` -------------------------------- ### SimulationHelper Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/types-and-utilities.md Utilities for simulating contract operations against an RPC and signing/submitting transactions. ```APIDOC ## SimulationHelper ### Description Utilities for simulating contract operations against an RPC and preparing transactions for submission to the Stellar network. ### Methods - `static async simulateOperation(network: Network, tx: Transaction): Promise` - `static async signAndSubmit(tx: Transaction, signer: Keypair): Promise` ### Source `src/simulation_helper.ts` ``` -------------------------------- ### Fetch Auction Details with PoolContract Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-contract.md Fetches an auction from the ledger and returns a quote based on the current block. Use this to get active auction information. ```typescript getAuction(auction_id: number): string ``` -------------------------------- ### BackstopPool.load() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-data-classes.md Loads pool-specific backstop data, including pool balance, Q4W percent, and token prices, for a given network and contract addresses. ```APIDOC ## BackstopPool.load() ### Description Loads backstop data for a specific pool. ### Method `BackstopPool.load(network: Network, backstopId: string, poolId: string): Promise` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters * **network** (Network) - Required - The network to load from * **backstopId** (string) - Required - The backstop contract address * **poolId** (string) - Required - The pool contract address ### Response #### Success Response * **backstopTkn** (string) - The backstop token address * **poolId** (string) - The pool ID * **poolBalance** (i128) - The pool balance * **q4wPercent** (i128) - The Q4W percentage * **shares** (i128) - The number of shares * **tokens** (i128) - The total tokens in the pool * **usdc** (i128) - The amount of USDC in the pool * **usdcPrice** (number) - The USDC price * **latestLedger** (number) - The latest ledger update number #### Response Example ```json { "backstopTkn": "0x...", "poolId": "0x...", "poolBalance": "1000000", "q4wPercent": "500", "shares": "1000000000000000000", "tokens": "2000000", "usdc": "1000000", "usdcPrice": 1.0, "latestLedger": 123456789 } ``` ``` -------------------------------- ### Initialize Emitter Contract Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/emitter-contract.md Initializes the Emitter contract with BLND token, backstop module, and backstop token addresses. Requires importing EmitterContract from '@blend-capital/blend-sdk'. ```typescript import { EmitterContract } from '@blend-capital/blend-sdk'; const emitter = new EmitterContract('CEMITTER...'); const operation = emitter.initialize({ blnd_token: 'CBLND...', backstop: 'CBACKSTOP...', backstop_token: 'CBACKSTOP_TOKEN...', }); ``` -------------------------------- ### Cancel Pool Reserve Initialization Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-contract.md Cancels the queued set of a reserve in the pool. This operation is restricted to admin users. Use this to abort a pending reserve setup. ```typescript cancelSetReserve(asset: Address | string): string ``` -------------------------------- ### Get Asset Price (Float) Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/oracle-and-events.md Fetches the price for a specific asset as a floating-point number. Returns undefined if the asset is not found. This is a convenient method for display purposes. ```typescript getPriceFloat(asset: string): number | undefined ``` ```typescript const oracle = await PoolOracle.load(network, oracleId, ['CUSDT...']); const price = oracle.getPriceFloat('CUSDT...'); if (price !== undefined) { console.log(`USDT price: $${price}`); } ``` -------------------------------- ### PoolContractV1.initialize Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-contract.md Initializes the pool with the provided contract arguments. Returns a Base64-encoded XDR operation string. ```APIDOC ## PoolContractV1.initialize() ### Description Initializes the pool with the specified contract arguments. ### Method initialize ### Parameters #### Request Body - **contractArgs.admin** (Address | string) - Required - The address for the admin - **contractArgs.name** (string) - Required - The name of the pool - **contractArgs.oracle** (Address | string) - Required - The contract address of the oracle - **contractArgs.bstop_rate** (u32) - Required - The take rate for the backstop (7 decimals) - **contractArgs.max_positions** (u32) - Required - The maximum number of positions a user is permitted to have - **contractArgs.backstop_id** (Address | string) - Required - The contract address of the pool's backstop module - **contractArgs.blnd_id** (Address | string) - Required - The contract ID of the BLND token ### Response #### Success Response - **string** - Base64-encoded XDR operation string ``` -------------------------------- ### Emitter Contract Methods Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/QUICK-START.md Methods for distributing BLND tokens and managing swap operations with the backstop. ```APIDOC ## Emitter Contract ### Methods - **distribute()**: Distribute BLND - **getLastDistro(backstopId)**: Get the last distribution for a backstop ID - **getBackstop()**: Get the current backstop - **queueSwapBackstop(args)**: Queue a swap to backstop - **getQueuedSwap()**: Get the currently queued swap - **cancelSwapBackstop()**: Cancel a queued backstop swap - **swapBackstop()**: Finalize a swap to backstop - **drop(list)**: Distribute BLND to a list of addresses ``` -------------------------------- ### BackstopToken.load() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-data-classes.md Loads backstop token data, including BLND and USDC balances and LP token price, from the ledger for a given network and token IDs. ```APIDOC ## BackstopToken.load() ### Description Loads backstop token data from the ledger. ### Method `BackstopToken.load(network: Network, backstopTokenId: string, blndTokenId: string, usdcTokenId: string): Promise` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Parameters * **network** (Network) - Required - The network to load from * **backstopTokenId** (string) - Required - The backstop token contract address * **blndTokenId** (string) - Required - The BLND token contract address * **usdcTokenId** (string) - Required - The USDC token contract address ### Response #### Success Response * **blndId** (string) - The BLND token ID * **usdcId** (string) - The USDC token ID * **blndBalance** (i128) - The BLND balance * **usdcBalance** (i128) - The USDC balance * **lpTokenPrice** (number) - The LP token price * **latestLedger** (number) - The latest ledger update number #### Response Example ```json { "blndId": "0x...", "usdcId": "0x...", "blndBalance": "1000000", "usdcBalance": "5000000", "lpTokenPrice": 1.5, "latestLedger": 123456789 } ``` ``` -------------------------------- ### Load Backstop Configuration Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-data-classes.md Loads the backstop configuration from the ledger using the network and backstop contract ID. Requires the `BackstopConfig` class and `Network` type. ```typescript static async load(network: Network, backstopId: string): Promise ``` -------------------------------- ### Get Asset Price (Fixed-Point) Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/oracle-and-events.md Fetches the price for a specific asset as a bigint fixed-point value with 7 decimal places. Returns undefined if the asset is not found in the oracle data. ```typescript getPrice(asset: string): i128 | undefined ``` -------------------------------- ### PoolFactoryContractV2.deploy() Static Method Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-factory-contract.md Use this static method to deploy a new instance of the Pool Factory V2 contract. It requires the deployer address, WASM hash, and pool initialization metadata. Optional parameters include a salt and the desired format for the WASM hash. ```typescript static deploy( deployer: string, wasmHash: Buffer | string, pool_init_meta: PoolInitMeta, salt?: Buffer, format?: 'hex' | 'base64' ): string ``` -------------------------------- ### PoolFactoryContractV2.deployPool() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-factory-contract.md Deploys a new instance of a Pool V2 contract using the provided contract arguments, including admin, name, salt, oracle details, and pool configuration. ```APIDOC ## PoolFactoryContractV2.deployPool() ### Description Deploys a new instance of a Pool V2 contract. ### Method Signature `deployPool(contractArgs: DeployV2Args): string` ### Parameters #### Path Parameters * **contractArgs.admin** (Address | string) - Required - The admin address for the pool * **contractArgs.name** (string) - Required - The name of the pool * **contractArgs.salt** (Buffer) - Required - The salt for the pool address (32 bytes) * **contractArgs.oracle** (Address | string) - Required - The oracle address for the pool * **contractArgs.min_collateral** (i128) - Required - Minimum collateral required to open a borrow position, in oracle's base asset decimals * **contractArgs.backstop_take_rate** (number) - Required - The backstop take rate for the pool (7 decimals) * **contractArgs.max_positions** (number) - Required - The maximum user positions supported by the pool ### Returns * **string** - Base64-encoded XDR operation string ### Example ```typescript import { PoolFactoryContractV2 } from '@blend-capital/blend-sdk'; import { randomBytes } from 'crypto'; const factory = new PoolFactoryContractV2('CFACTORY...'); const operation = factory.deployPool({ admin: 'GADMIN...', name: 'Blend Main Pool V2', salt: randomBytes(32), oracle: 'CORACLE...', min_collateral: BigInt(10000000), // 1 unit in oracle decimals backstop_take_rate: 4000000, // 0.4 in 7 decimals max_positions: 5, }); ``` ``` -------------------------------- ### Get Last Distribution Time Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/emitter-contract.md Fetches the last time the Emitter contract distributed tokens to a specified backstop module. Requires the backstop module's Address ID. ```typescript emitter.getLastDistro(backstop_id: Address | string) ``` -------------------------------- ### Initialize Backstop Contract V1 Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-contract.md Initializes the Backstop contract with essential token and contract addresses, along with an initial drop list. This is a V1-specific operation. ```typescript initialize(contractArgs: BackstopConstructorArgs): string ``` -------------------------------- ### PoolFactoryContractV1.deployPool Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-factory-contract.md Deploys and initializes a new lending pool with the specified configuration. This is the primary method for creating new pools. ```APIDOC ## PoolFactoryContractV1.deployPool() ### Description Deploys and initializes a lending pool. ### Method Signature `deployPool(contractArgs: DeployV1Args): string` ### Parameters #### Path Parameters - **contractArgs.admin** (Address | string) - Required - The admin address for the pool - **contractArgs.name** (string) - Required - The name of the pool - **contractArgs.salt** (Buffer) - Required - The salt for the pool address (32 bytes) - **contractArgs.oracle** (Address | string) - Required - The oracle address for the pool - **contractArgs.backstop_take_rate** (number) - Required - The backstop take rate for the pool (7 decimals) - **contractArgs.max_positions** (number) - Required - The maximum user positions supported by the pool ### Returns `string` - Base64-encoded XDR operation string ### Example ```typescript import { PoolFactoryContractV1 } from '@blend-capital/blend-sdk'; import { randomBytes } from 'crypto'; const factory = new PoolFactoryContractV1('CFACTORY...'); const operation = factory.deployPool({ admin: 'GADMIN...', name: 'Blend Main Pool', salt: randomBytes(32), oracle: 'CORACLE...', backstop_take_rate: 4000000, // 0.4 in 7 decimals max_positions: 5, }); ``` ``` -------------------------------- ### PoolV2.loadWithMetadata() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-data-classes.md Loads a V2 pool from the ledger, accepting pre-existing metadata. ```APIDOC ## PoolV2.loadWithMetadata() ### Description Loads a V2 pool from the ledger with pre-existing metadata. ### Method `static async loadWithMetadata(network: Network, id: string, metadata: PoolMetadata): Promise` ### Parameters #### Path Parameters - **network** (Network) - Required - The network information to load the pool from - **id** (string) - Required - The contract address of the pool - **metadata** (PoolMetadata) - Required - The metadata for the pool ### Returns `Promise` - The loaded pool object ``` -------------------------------- ### Supported Network Configurations Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/INDEX.md Defines configurations for connecting to different Stellar networks: testnet, public (mainnet), and local development. ```typescript // Testnet const testnet = { rpc: 'https://soroban-testnet.stellar.org', passphrase: 'Test SDF Network ; September 2015', }; // Public (Mainnet) const public = { rpc: 'https://soroban-mainnet.stellar.org', passphrase: 'Public Global Stellar Network ; September 2015', }; // Local const local = { rpc: 'http://localhost:8000', passphrase: 'Standalone Network ; February 2022', opts: { allowHttp: true }, }; ``` -------------------------------- ### PoolV1.loadWithMetadata() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-data-classes.md Loads a V1 pool from the ledger, accepting pre-existing metadata. ```APIDOC ## PoolV1.loadWithMetadata() ### Description Loads a V1 pool from the ledger with pre-existing metadata. ### Method `static async loadWithMetadata(network: Network, id: string, metadata: PoolMetadata): Promise` ### Parameters #### Path Parameters - **network** (Network) - Required - The network information to load the pool from - **id** (string) - Required - The contract address of the pool - **metadata** (PoolMetadata) - Required - The metadata for the pool ### Returns `Promise` - The loaded pool object ``` -------------------------------- ### EmitterContract.queueSwapBackstop Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/emitter-contract.md Queues a new backstop module for swap with a new backstop token. ```APIDOC ## EmitterContract.queueSwapBackstop() ### Description Queues a new backstop module for swap with a new backstop token. ### Method queueSwapBackstop ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **contractArgs.new_backstop** (Address | string) - Required - The new backstop module address - **contractArgs.new_backstop_token** (Address | string) - Required - The new backstop token address ### Request Example None provided. ### Response #### Success Response (200) - **string** - Base64-encoded XDR operation string #### Response Example None provided. ``` -------------------------------- ### BackstopPoolUserEst.build() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-data-classes.md Builds estimates for a user's backstop position by taking the backstop, pool, and user data as input and returning a BackstopPoolUserEst object. ```APIDOC ## BackstopPoolUserEst.build() ### Description Builds estimates for a user's backstop position. ### Method static build ### Parameters #### Path Parameters - **backstop** (Backstop) - Required - The backstop object - **backstopPool** (BackstopPool) - Required - The pool's backstop data - **backstopPoolUser** (BackstopPoolUser) - Required - The user's backstop position ### Response #### Success Response - **BackstopPoolUserEst** - Floating point estimates ### Request Example ```typescript import { BackstopPoolUserEst } from '@blend-capital/blend-sdk'; const backstop = await Backstop.load(network, backstopId); const backstopPool = await BackstopPool.load(network, backstopId, poolId); const backstopPoolUser = await BackstopPoolUser.load(network, backstopId, poolId, userId); const estimate = BackstopPoolUserEst.build(backstop, backstopPool, backstopPoolUser); console.log(`LP tokens held: ${estimate.lpTokensHeld}`); console.log(`Queued value: $${estimate.totalValueQueued}`); console.log(`Claimable BLND: ${estimate.blndClaimable}`); ``` ``` -------------------------------- ### Build Backstop User Estimate Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/QUICK-START.md Build an estimate for a backstop user position using backstop, pool, and user data. ```typescript BackstopPoolUserEst.build(backstop, backstopPool, backstopPoolUser) ``` -------------------------------- ### PoolFactoryContractV2.deployPool() Method Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-factory-contract.md Use this method to deploy a new instance of a Pool V2 contract. It takes a contractArgs object containing details like admin, name, salt, oracle, minimum collateral, backstop take rate, and maximum positions. ```typescript deployPool(contractArgs: DeployV2Args): string ``` -------------------------------- ### PoolContractV2.getConfig() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-contract.md Fetches the current configuration settings of the pool. ```APIDOC ## PoolContractV2.getConfig() ### Description Fetches the pool configuration. ### Method getConfig ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) - **string** - Base64-encoded XDR operation string #### Response Example N/A ``` -------------------------------- ### Network Configuration Object Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/00-START-HERE.md Defines the network parameters required for SDK operations. Ensure the RPC and passphrase are correct for your target network. ```typescript const network = { rpc: 'https://soroban-testnet.stellar.org', passphrase: 'Test SDF Network ; September 2015', }; ``` -------------------------------- ### ReserveConfig.load() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-data-classes.md Loads reserve configuration from the ledger for a specific asset within a pool. This includes parameters that govern the behavior of the reserve asset. ```APIDOC ## ReserveConfig.load() ### Description Loads reserve configuration from the ledger. ### Method `static async load(network: Network, poolId: string, assetId: string): Promise` ### Parameters #### Path Parameters - **network** (Network) - Required - The network information to load from - **poolId** (string) - Required - The pool contract address - **assetId** (string) - Required - The asset contract address ### Response #### Success Response (Promise) - **index** (number) - The index of the reserve asset. - **decimals** (number) - The number of decimals for the asset. - **c_factor** (number) - The collateralization factor. - **l_factor** (number) - The loan factor. - **util** (number) - The current utilization rate. - **max_util** (number) - The maximum utilization rate. - **r_base** (number) - The base interest rate. - **r_one** (number) - The interest rate for the first tier. - **r_two** (number) - The interest rate for the second tier. - **r_three** (number) - The interest rate for the third tier. - **reactivity** (number) - The interest rate reactivity. ### Request Example ```typescript import { ReserveConfig } from '@blend-capital/blend-sdk'; const config = await ReserveConfig.load(network, poolId, assetId); console.log(`Reserve decimals: ${config.decimals}`); console.log(`Max utilization: ${config.max_util}`); ``` ``` -------------------------------- ### BackstopPoolUserEst.build() Method Signature Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-data-classes.md Provides the method signature for building estimates of a user's backstop position. It requires Backstop, BackstopPool, and BackstopPoolUser objects as input. ```typescript static build( backstop: Backstop, backstopPool: BackstopPool, backstopPoolUser: BackstopPoolUser ): BackstopPoolUserEst ``` -------------------------------- ### Read Ledger Data for a Pool and a User Source: https://github.com/blend-capital/blend-sdk-js/blob/main/README.md Helper classes are provided to efficiently read ledger data for a pool, its reserves, and backstop status from an RPC. ```APIDOC ## Read Ledger Data for a Pool and a User ### Description Loads and estimates various data points related to a Blend Protocol pool, its users, and its backstop. ### Classes and Methods **Pool Data:** - `Pool.load(network, pool_id)`: Loads general pool data. - `pool.loadOracle()`: Loads the pool's oracle for price information. - `PoolEstimate.build(pool.reserves, pool_oracle)`: Estimates total value supplied and borrowed. **User Position Data:** - `pool.loadUser(user_id)`: Loads a specific user's position data. - `PositionsEstimate.build(pool, pool_oracle, pool_user.positions)`: Estimates user's borrow limit, net APR, etc. **Backstop Data:** - `Backstop.load(network, backstop_id)`: Loads general backstop contract data. - `BackstopPool.load(network, backstop_id, pool_id)`: Loads a pool's specific backstop data. - `BackstopPoolEst.build(backstop.backstopToken, backstop_pool.poolBalance)`: Estimates total BLND/USDC tokens held by the backstop. **User Backstop Position Data:** - `BackstopPoolUser.load(network, backstop_id, pool_id, user_id)`: Loads a user's position in a pool's backstop. - `BackstopPoolUserEst.build(backstop, backstop_pool, backstop_pool_user)`: Estimates user's BLND/USDC tokens, queued withdrawals, and unclaimed emissions. ### Parameters - `network` (Network): Configuration for the Stellar network (rpc URL, passphrase, optional opts). - `pool_id` (Address): The address of the pool contract. - `user_id` (Address): The address of the user whose position is being queried. - `backstop_id` (Address): The address of the backstop contract. ### Request Example ```typescript import { Backstop, BackstopPool, BackstopPoolEst, BackstopPoolUser, BackstopPoolUserEst, Network, Pool, PoolEstimate, PoolOracle, PositionsEstimate, } from '@blend-capital/blend-sdk'; const network: Network = { rpc: '// rpc URL', passphrase: '// Stellar network passphrase', opts: { allowHttp: true } }; const backstop_id = 'C... the address of the backstop contract'; const pool_id = 'C... the address of the pool contract'; const user_id = 'G... the address of a user that has taken a position in the pool'; // Load Pool Data const pool = await Pool.load(network, pool_id); const pool_oracle = await pool.loadOracle(); const pool_est = PoolEstimate.build(pool.reserves, pool_oracle); // Load User Position Data const pool_user = await pool.loadUser(user_id); const user_est = PositionsEstimate.build(pool, pool_oracle, pool_user.positions); // Load Backstop Data const backstop = await Backstop.load(network, backstop_id); const backstop_pool = await BackstopPool.load(network, backstop_id, pool_id); const backstop_pool_est = BackstopPoolEst.build(backstop.backstopToken, backstop_pool.poolBalance); // Load User Backstop Position Data const backstop_pool_user = await BackstopPoolUser.load(network, backstop_id, pool_id, user_id); const backstop_pool_user_est = BackstopPoolUserEst.build(backstop, backstop_pool, backstop_pool_user); ``` ### Response Returns various objects containing ledger data and estimates for pools, users, and backstops. ``` -------------------------------- ### EmitterContract.getBackstop Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/emitter-contract.md Fetches the current backstop module address. ```APIDOC ## EmitterContract.getBackstop() ### Description Fetches the current backstop module address. ### Method getBackstop ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None provided. ### Response #### Success Response (200) - **string** - Base64-encoded XDR operation string #### Response Example None provided. ``` -------------------------------- ### Emitter Contract Methods Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/QUICK-START.md Methods for managing BLND token distribution and swaps with the Emitter contract. ```typescript emitter.distribute() // Distribute BLND emitter.getLastDistro(backstopId) emitter.getBackstop() // Get current backstop emitter.queueSwapBackstop(args) emitter.getQueuedSwap() emitter.cancelSwapBackstop() emitter.swapBackstop() // Finalize swap emitter.drop(list) // Distribute to addresses ``` -------------------------------- ### Blend SDK JS Import Patterns Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/INDEX.md Illustrates different ways to import components from the Blend SDK JS, including specific classes, entire modules, utilities, and named exports. ```typescript // Import specific classes import { PoolV1, PoolContractV2 } from '@blend-capital/blend-sdk'; ``` ```typescript // Import entire module with namespace import * as BlendSDK from '@blend-capital/blend-sdk'; ``` ```typescript // Import utilities import * as FixedMath from '@blend-capital/blend-sdk'; ``` ```typescript // Import with named exports import { Pool, PoolEstimate, PositionsEstimate, Network, Version, RequestType, } from '@blend-capital/blend-sdk'; ``` -------------------------------- ### SimulationHelper Class Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/types-and-utilities.md Assists in simulating contract operations and preparing transactions for submission to the Stellar network. Requires network and transaction details. ```typescript export class SimulationHelper { static async simulateOperation( network: Network, tx: Transaction ): Promise { ... } static async signAndSubmit( tx: Transaction, signer: Keypair ): Promise { ... } } ``` -------------------------------- ### Pool Factory Contract Methods (V1 Only) Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/QUICK-START.md Methods specific to deploying and initializing the Pool Factory contract in V1. ```typescript // V1 only factory.initialize(meta) // Initialize factory factory.deployPool(args) // Deploy pool ``` -------------------------------- ### PoolFactoryContractV2.deploy() Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/pool-factory-contract.md Deploys a new instance of the Pool Factory V2 contract using provided deployer, WASM hash, and initialization metadata. It supports optional salt and format for the WASM hash. ```APIDOC ## PoolFactoryContractV2.deploy() ### Description Deploys a new instance of the Pool Factory V2 contract. ### Method Signature `static deploy(deployer: string, wasmHash: Buffer | string, pool_init_meta: PoolInitMeta, salt?: Buffer, format?: 'hex' | 'base64'): string` ### Parameters #### Path Parameters * **deployer** (string) - Required - The address of the deployer * **wasmHash** (Buffer | string) - Required - The hash of the WASM contract code * **pool_init_meta.pool_hash** (Buffer) - Required - The hash of the pool contract code * **pool_init_meta.backstop** (Address | string) - Required - The address of the backstop contract * **pool_init_meta.blnd_id** (Address | string) - Required - The address of the BLND token contract * **salt** (Buffer) - Optional - Salt for the contract deployment * **format** ('hex' | 'base64') - Optional - Format for the WASM hash ### Returns * **string** - Base64-encoded XDR operation string ``` -------------------------------- ### Build Backstop Pool Estimate Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/QUICK-START.md Build an estimate for a backstop pool using token and balance data. ```typescript BackstopPoolEst.build(backstopToken, poolBalance) ``` -------------------------------- ### BackstopContractV2.deploy Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-contract.md Deploys a new instance of the Backstop V2 contract. This static method takes deployment details and returns a Base64-encoded XDR operation string. ```APIDOC ## BackstopContractV2.deploy ### Description Deploys a new instance of the Backstop V2 contract. ### Method `static deploy` ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters - **deployer** (string) - Required - The address of the deployer - **wasmHash** (Buffer | string) - Required - The hash of the WASM contract code - **args.backstop_token** (Address | string) - Required - The address of the backstop token - **args.emitter** (Address | string) - Required - The address of the emitter contract - **args.usdc_token** (Address | string) - Required - The address of the USDC token - **args.blnd_token** (Address | string) - Required - The address of the BLND token - **args.pool_factory** (Address | string) - Required - The address of the pool factory - **args.drop_list** (Array<[string, i128]>) - Required - Initial drop list of addresses and amounts - **salt** (Buffer) - Optional - Salt for the contract deployment - **format** ('hex' | 'base64') - Optional - Format for the WASM hash ### Returns `string` - Base64-encoded XDR operation string ``` -------------------------------- ### BackstopToken.load() Method Signature Source: https://github.com/blend-capital/blend-sdk-js/blob/main/_autodocs/backstop-data-classes.md Asynchronously loads backstop token data from the specified network using contract addresses for the backstop token, BLND, and USDC. ```typescript static async load( network: Network, backstopTokenId: string, blndTokenId: string, usdcTokenId: string ): Promise ```