Lombard
  • Unlocking Bitcoin's Potential
    • Introducing Lombard & LBTC
      • Our Value Proposition
      • The State of Bitcoin
      • Lombard's Mission & Vision
  • Lombard's Partners
    • Babylon's Bitcoin Staking
    • Lombard's Security Consortium
  • Bitcoin Staking Partners
  • LBTC: Liquid Bitcoin
    • Introduction to LBTC
    • DeFi Vaults
      • Lombard DeFi Vault
        • LBTC/LBTCv
      • Bitcoin Bera Vault
      • Sentora DeFi Vault
    • Lux & Luminary Program
      • Referral Program
      • Nov. '24 The Golden Bull
      • Dec. '24 Flash Event
    • Staking Yield Distribution
    • Supported Blockchains
    • User Guides
      • Staking BTC & Minting LBTC
      • Unstaking LBTC
      • Lombard DeFi Vault: Depositing & Withdrawing
      • Claiming BABY
      • LBTC Bridging to Sui
  • Technical Documentation
    • Smart Contracts
    • Protocol Fees
    • Protocol Architecture
      • Lombard Ledger (Consortium)
      • CubeSigner: Key Management
      • Bascule Drawbridge
      • LBTC Design
      • Babylon Staking
      • PMM Module
      • Trustless Relayer
    • Oracles
    • Audits & Bug Bounties
    • Sanctions & Risk Monitoring
    • Transaction Tracing
  • Frequently Asked Questions
    • FAQs
      • BABY FAQs
  • Developers
    • Lombard SDK V3
    • SDK FAQ
    • Lombard SDK V2 (deprecated)
  • Quick Links
    • Lombard Website
    • Lombard X (Twitter)
    • Lombard Dune Dashboard
    • Lombard Dune PoR
    • Lombard Discord Server
  • Legals
    • Terms of Service
    • Privacy Policy
    • UK Residents
Powered by GitBook
On this page
  • @lombard.finance/sdk
  • Installation
  • Usage
  1. Developers

Lombard SDK V3

PreviousBABY FAQsNextSDK FAQ

Last updated 29 days ago

Our TypeScript Lombard SDK can be integrated into any frontend app: wallets, portfolio management apps, staking dashboards, custody portals.

If you're interested in integrating our Lombard SDK please fill out this and we will issue you with a partner Id.

Important: You must take all measures for your app and its users to comply with our , including removing access for unauthorized countries.

The Lombard's SDK package provides a set of functions that allow interacting with the Lombard protocol and its features.

Installation

1. Dependencies installation

The SDK depends on the following packages:

  • axios

  • viem@2.23

  • bignumber.js@9

  • bitcoinjs-lib@6.1.5

  • @bitcoin-js/tiny-secp256k1-asmjs@2.2.3

You may install them by running the following command:

npm i --save viem@^2.23.15 axios@^1 bignumber.js@^9 @bitcoin-js/tiny-secp256k1-asmjs@2.2.3 bitcoinjs-lib@6.1.5

2. SDK installation

To install the SDK package, please run:

npm i --save @lombard.finance/sdk

Usage

All functions are documented with JSDoc comments. You can use your IDE's autocomplete feature to see the available methods and their parameters.

1. Depositing BTC in order to get LBTC (aka staking).

You can read more about LBTC here: https://docs.lombard.finance/lbtc-liquid-bitcoin/introduction-to-lbtc

If you'd wish to stake your BTC and get LBTC follow the below steps:

1.1 Get the current minting fee.

const fee = await getLBTCMintingFee({ chainId: ChainId.ethereum }); // The fee represented in satoshis (BigNumber)

1.2. Sign the network fee signature.

const expiry = Math.round((Date.now() + 24 * 60 * 60 * 1000) / 1000);
const { signature, typedData } = await signNetworkFee({
  fee, // The fee from step 1
  expiry, // The optional expiration unix timestamp. This parameter can be omitted, it default to 24h from now. We recommend to set this to at least 8h from now.
  account, // The destination account address from the connected wallet.
  chainId: ChainId.ethereum // The destination chain id.
  provider, // The EIP-1193 provider, e.g. the injected provider: window.ethereum
});

1.3. Store the signature to the Lombard's systems.

await storeNetworkFeeSignature({ signature, typedData, address }); // Pass the signature and typed data from step 2.

It is recommended to verify that the signature has been stored. Please use getNetworkFeeSignature.

const { expirationData, hasSignature, isDelayed } = await getNetworkFeeSignature({ address, chainId });

isDelayed is a flag determining whether the execution of auto-claimer using the stored signature is delayed due to the higher gas costs.

1.4. Get or generate the BTC deposit address.

let depositBtcAddress = await getDepositBtcAddress({ address, chainId });
if (!depositBtcAddress) {
  depositBtcAddress = await generateDepositBtcAddress({ 
    address,
    chainId,
    signature, // Pass here the signature from step 2.
    eip712Data: typedData // Pass here the typed data from step 2.
  });
}

1.5. Deposit BTC to the address.

Now you can deposit your BTC to the generated in the previous step BTC address. The funds will be claimed automatically by Lombard's claimer and transferred to the account (address).

1.6. Check the status of your deposit.

If you'd like to check the status of your deposit use getDepositsByAddress function.

const deposits = await getDepositsByAddress({ address });

Every entry in the result of the above function may consist of the following properties:

  • txid - the BTC transaction id,

  • index - the index of the actual deposit transaction,

  • blockHeight

  • blockTime

  • value - the amount of BTC deposited,

  • address - the destination address,

  • chainId - the destination chain id,

  • isClaimer - a flag determining whether the deposit has been already claimed,

  • claimedTxId - the corresponding claim transaction that transfer funds to the destination address,

  • rawPayload - the payload of the transaction (can be use to claim the funds manually),

  • signature - the signature used (can be used to claim the funds manually),

  • isRestricted - a flag determining whether the transaction has been marked as suspicious/restricted,

  • payload - the payload (corresponding to the Bascule drawbridge security),

  • sessionId

  • notarizationStatus - the notarization status of the deposit (pending, submitted, approved or failed),

  • sessionState - the state of the session (pending, completed, expired)

2. Manually claiming LBTC.

In case when a user deposited BTC to the BTC deposit address but the transaction has not been claimed automatically (due to expired signature or any other issue), you may want to claim LBTC manually as in the example below:

const txHash = await claimLBTC({
  data: rawPayload, // Pass the raw payload from the deposit data as presented in the previous step.
  proofSignature: signature, // Pass the signature from the deposit data.
  account, // The connected account address
  chainId, // The chain id
  provider, // The EIP-1193 provider,
  rpcUrl, // The optional RPC url.
})

The successful execution of the above will result with the transaction id.

3. Depositing BTC and automatically staking LBTC into the DeFi vault (aka stake and bake)

You can read more about the DeFi vaults here: https://docs.lombard.finance/lbtc-liquid-bitcoin/defi-vaults/lombard-defi-vault

If you'd wish to stake and bake your BTC follow the steps below.

3.1. See what's the current stake and bake fee.

To check the current stake and bake fee you may use the following function:

const fee = await getStakeAndBakeFee({
  vaultKey: Vault.Veda, // The vault identifier, currently only "veda" is accepted.
  chainId, // The chain id.
  rpcUrl, // The options RPC url.
});
const expectedLBTCAmount = BigNumber(amountToBeDeposited).minus(fee);

The fee amount will be deducted from the claimed LBTC automatically.

3.2. Sign the stake and bake signature.

const { signature, typedData } = await signStakeAndBake({
  account, // The connected account address,
  expiry, // The optional expiration unix timestamp. This parameter can be omitted, it default to 24h from now. We recommend to set this to at least 8h from now.
  value, // The amount of BTC (in satoshis)
  vaultKey: Vault.Veda, // The vault identifier, currently only "veda" is accepted.
  chainId, // The chain id.
  provider, // The EIP-1193 provider.
  rpcUrl, // The optional RPC url.
})

3.3. Store the signature to the Lombard's systems.

await storeStakeAndBakeSignature({
  signature, // Pass here the signature form the previous step.
  typedData, // Pass here the typed data from the previous step.
})

It is recommended to verify if the signature has been stored.

const data = await getUserStakeAndBakeSignature({
  userDestinationAddress: address,
  chainId,
})

3.4. Get or generate the BTC deposit address.

let depositBtcAddress = await getDepositBtcAddress({ address, chainId });
if (!depositBtcAddress) {
  depositBtcAddress = await generateDepositBtcAddress({ 
    address,
    chainId,
    signature, // Pass here the signature from step 2.
    signatureData: typedData // Pass here the typed data from step 2.
  });
}

3.5. Deposit BTC to the address.

Now you can deposit your BTC to the BTC deposit address from above. The funds will be automatically claimed and deposited to the DeFi vault.

3.6. Check the status of you deposit

const deposits = await getDepositsByAddress({ address });

3.7. Check the amount of shares acquired.

const { balance, exchangeRate, balanceLbtc } = await getSharesByAddress({
  vaultKey: Vault.Veda, // The vault identifier.
  address, // The account address.
  chainId, // The chain id.
  rpcUrl, // The optional RPC url
});

The above code results with:

  • balance - The amount of LBTCv shares owned by the account,

  • exchangeRate - The current LBTCv to LBTC exchange rate,

  • balanceLbtc - The value of the owned shares is LBTC.

4. Unstaking LBTC and getting BTC back.

Every LBTC is redeemable back to BTC, you can do that programmatically by following the steps:

4.1. Unstake LBTC.

const txaHash = await unstakeLBTC({
  btcAddress, // The address to which the funds will be redeemed.
  amount, // The amount of LBTC to unstake.
  account, // The account address.
  chainId, // The chain id.
  provider, // The EIP-1193 provider.
  rpcUrl, // The optional RPC url.
});

4.2. Check the status of your unstakes.

If you'd like to get the list of all unstaked made by an address, use this:

const unstakes = await getUnstakesByAddress({ address });

Every entry in the result of the above may consist of:

  • txHash - The unstake transaction hash,

  • chainId,

  • blockHeight,

  • unstakeDate,

  • fromAddress - The EVM source address,

  • toAddress - The BTC destination address of the funds,

  • amount - The amount unstaked,

  • payoutTxHash - The BTC transaction hash,

  • payoutTxIndex - The index of the actual payout transfer,

  • sanctioned - A flag indicating whether the unstake transaction has been sanctioned and flagged as suspicious.

5. Depositing LBTC to the DeFi vault.

If a user already has LBTC depositing to the DeFi vault can be done via the deposit function.

5.1. Making a deposit to the DeFi vault.

const txHash = await deposit({
  amount, // The deposit amount, e.g. 1.23 (LBTC)
  approve = true, // The optional flag determining whether approval should be done within deposit execution.
  token = 'LBTC', // The optional deposit token.
  vaultKey = Vault.Veda, // The optional vault identifier.
  account, // The account address.
  chainId, // The chain id.
  provider, // The EIP-1193 provider
  rpcUrl, // The optional RPC url
})

5.2. Checking the deposit history.

const deposits = await getVaultDeposits({
  account, // The account address.
  chainId, // The chain id.
  vaultKey = Vault.Veda // The optional vault identifier.
});

The above function returns an array of deposit data made by the specified user. Each entry contains:

  • txHash - the transaction hash,

  • blockNumber - the transaction's block number,

  • chainId - the chain id,

  • amount - the deposited amount,

  • shareAmount - the amount of shares received,

  • token - the deposit token.

5.3. Checking the user's DeFi vault balance.

In order to check the user's balance of the vault tokens, use this:

const { balance, exchangeRate, balanceLbtc } = await getSharesByAddress({
  vaultKey: Vault.Veda, // The vault identifier.
  address, // The account address.
  chainId, // The chain id.
  rpcUrl, // The optional RPC url
});

The above function returns the:

  • balance - balance of LBTCv,

  • exchangeRate - the current exchange rate between LBTCv and LBTC,

  • balanceLbtc - the value of LBTCv represented in LBTC.

6. Withdrawing LBTC from the DeFi vault.

6.1. Requesting a withdrawal from the DeFi vault

Requesting a withdrawal from the DeFi vault can be done via:

const txHash = await withdraw({
  amount, // The amount of shares.
  approve = true, // The optional flag determining if approve action should be done within this execution.
  token = 'LBTC', // The optional withdraw token.
  vaultKey = Vault.Veda, // The optional vault identifier.
  account, // The account address.
  chainId, // The chain id.
  provider, // The EIP-1192 provider.
  rpcUrl, // The optional RPC url
})

6.2. Checking the withdrawal history (tracking the withdrawal request)

In order to check the whole history or to track the particular withdrawal please use the following function:

const withdrawals = await getVaultWithdrawals({
  account, // The account address.
  chainId, // The chain id.
  vaultKey = Vault.Veda, // The optional vault identifier.
  rpcUrl, // The optional RPC url
})

The result of the above is an object with broken down withdrawals by their state:

{
  cancelled: [...], // The cancelled requests.
  expired: [...], // The requests that expired.
  fulfilled: [...], // The fulfilled requests (funds were transferred).
  open: [...], // The open withdrawal requests (still to be processed).
}

Each of the arrays from above consist of:

  • token - the withdrawal token (LBTC),

  • shareAmount - the amount of shares withdrawn,

  • amount - the amount of funds withdrawn,

  • minPrice - the min price of a share,

  • deadline - the expiration timestamp,

  • timestamp - the request timestamp,

  • txHash - the withdraw request transaction hash,

  • blockNumber - the request block number,

  • fulfilledTimestamp - the fulfilment timestamp,

  • fulfilledTxHash - the funds transfer transaction hash,

  • fulfilledBlockNumber - the fulfilment block number.

6.3. Cancelling the withdrawal

If you wish to cancel you open withdrawal request use this:

const txHash = await cancelWithdraw({
  token = 'LBTC', // The optional withdrawal asset.
  vaultKey = Vault.Veda, // The optional vault identifier.
  account, // The account address.
  chainId, // The chain id.
  provider, // The EIP-1193 provider.
  rpcUrl, // The optional RPC url.
});

7. Getting the points earned by an address.

If you'd like to check the amount of LUX points earned by an address then simply run the following function:

const points = await getPointsByAddress({ address: "0x...YOUR_ADDRESS" })

The function returns the object of shape:

  {
    /**
     * The number of points earned by holding LBTC.
     */
    holdingPoints: number;
    /**
     * The number of points earned by taking positions in DeFi vaults.
     */
    protocolPoints: number;
    /**
     * The number of points earned by your referrals.
     */
    referralPoints: number;
    /**
     * The number of points earned in the OKX campaign.
     */
    okxPoints: number;
    /**
     * The number of points earned by participating in the flash events.
     */
    flashEventPoints: number;
    /**
     * The total number of points.
     */
    totalPoints: number;
    /**
     * The breakdown of points earned from each protocol.
     */
    protocolPointsBreakdown: IProtocolPointsBreakdown;
  }

8. Getting the DeFi vault points earned by an address.

const { 
  totalPoints, // The total points earned in the DeFi vault.
  pointsBreakdown // The points breakdown by network (chain).
} = await getVaultPoints({
  account, // The account address.
  vaultKey // The optional vault identifier.
})

9. Claiming rewards.

9.1. Checking reward balances.

const rewards = await getRewardBalances({
  address,
  rewardToken: RewardToken.BABY
});

The data returned by the above function contains:

  • address - the address of the reward earner (claimer),

  • availableBalance - the available balance of the reward token (ready to be withdrawn),

  • lockedBalance - the locked balance (in processing),

  • pendingBalance - the pending balance to be credited,

  • rewardToken - the reward token,

  • timestamp - the timestamp.

9.2. Claiming rewards.

const withdrawal = await claimReward({
  account, // The account address.
  rewardToken, // The reward token, e.g. RewardToken.BABY
  amount, // The amount to be claimed (withdrawn)
  to, // The destination address, e.g. BABYLON chain address.
  chainId, // The chain id
  provider, // The EIP-1193 provider.
});

The function will ask a user to sign a message that consists of the amount, destination address and also a withdrawal fee and after obtaining this signature it will request a reward withdrawal from the pool to the provided destination address.

The function returns the RewardWithdrawal object.

9.3. Checking the reward withdrawal fee.

const withdrawalFee = await getRewardWithdrawalFee({ address, rewardToken });

9.4. Getting the withdrawal history (checking withdrawal status).

const withdrawals = await getRewardWithdrawals({ address })

The function returns an array of:

  • amount - the withdrawn (claimed) amount of rewards token,

  • rewardToken - the reward token,

  • fee - the applied withdrawal fee,

  • to - the destination address,

  • signature - the signature used,

  • status - the withdrawal status,

  • estimatedTimeSent - the estimated time when the funds are sent,

  • timestamp - the timestamp.

Google Form
Terms of Service
@lombard.finance/sdk