@lombard.finance/sdk 2.5.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/README.md +428 -399
  2. package/dist/ccip.cjs +2 -0
  3. package/dist/ccip.cjs.map +1 -0
  4. package/dist/ccip.js +147 -0
  5. package/dist/ccip.js.map +1 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.js +68 -8269
  9. package/dist/index.js.map +1 -1
  10. package/dist/index2.cjs +53 -0
  11. package/dist/index2.cjs.map +1 -0
  12. package/dist/index2.js +21672 -0
  13. package/dist/index2.js.map +1 -0
  14. package/package.json +5 -5
  15. package/src/{sdk → api-functions}/generateDepositBtcAddress/generateDepositBtcAddress.stories.tsx +15 -14
  16. package/src/{sdk → api-functions}/generateDepositBtcAddress/generateDepositBtcAddress.ts +18 -8
  17. package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +15 -14
  18. package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddress.ts +16 -7
  19. package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddresses.stories.tsx +15 -14
  20. package/src/{sdk → api-functions}/getDepositsByAddress/getDepositsByAddress.stories.tsx +13 -12
  21. package/src/{sdk → api-functions}/getDepositsByAddress/getDepositsByAddress.ts +8 -8
  22. package/src/{sdk → api-functions}/getLBTCExchangeRate/getLBTCExchangeRate.stories.tsx +16 -10
  23. package/src/api-functions/getLBTCExchangeRate/getLBTCExchangeRate.ts +71 -0
  24. package/src/api-functions/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +56 -0
  25. package/src/{sdk → api-functions}/getNetworkFeeSignature/getNetworkFeeSignature.ts +11 -5
  26. package/src/{sdk → api-functions}/getPointsByAddress/getPointsByAddress.stories.tsx +14 -13
  27. package/src/{sdk → api-functions}/getPointsByAddress/getPointsByAddress.ts +7 -4
  28. package/src/{sdk → api-functions}/getUnstakesByAddress/getUnstakesByAddress.stories.tsx +14 -13
  29. package/src/{sdk → api-functions}/getUnstakesByAddress/getUnstakesByAddress.ts +14 -9
  30. package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +61 -0
  31. package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.ts +10 -6
  32. package/src/{sdk → api-functions}/index.ts +0 -3
  33. package/src/{sdk → api-functions}/setReferral/setReferral.ts +3 -3
  34. package/src/api-functions/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +56 -0
  35. package/src/{sdk → api-functions}/storeNetworkFeeSignature/storeNetworkFeeSignature.ts +9 -7
  36. package/src/api-functions/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +56 -0
  37. package/src/{sdk → api-functions}/storeStakeAndBakeSignature/storeStakeAndBakeSignature.ts +8 -6
  38. package/src/clients/public-client.ts +32 -0
  39. package/src/clients/rpc-url-config.ts +20 -0
  40. package/src/clients/wallet-client.ts +33 -0
  41. package/src/{sdk/apiConfig.ts → common/api-config.ts} +2 -2
  42. package/src/common/blockchain-identifier.ts +107 -0
  43. package/src/common/chains.ts +72 -0
  44. package/src/common/parameters.ts +51 -0
  45. package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +76 -0
  46. package/src/contract-functions/approveLBTC/approveLBTC.ts +64 -0
  47. package/src/{web3Sdk → contract-functions}/claimLBTC/claimLBTC.stories.tsx +22 -30
  48. package/src/contract-functions/claimLBTC/claimLBTC.ts +89 -0
  49. package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +50 -0
  50. package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +121 -0
  51. package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +15 -11
  52. package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +34 -0
  53. package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +49 -0
  54. package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +30 -0
  55. package/src/{web3Sdk → contract-functions}/getPermitNonce/getPermitNonce.stories.tsx +12 -22
  56. package/src/contract-functions/getPermitNonce/getPermitNonce.ts +39 -0
  57. package/src/{web3Sdk → contract-functions}/getShareValue/getShareValue.stories.tsx +11 -6
  58. package/src/contract-functions/getShareValue/getShareValue.ts +58 -0
  59. package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.stories.tsx +13 -8
  60. package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.ts +29 -28
  61. package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +16 -16
  62. package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +61 -0
  63. package/src/{web3Sdk → contract-functions}/index.ts +8 -7
  64. package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +32 -0
  65. package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +63 -0
  66. package/src/contract-functions/signNetworkFee/signNetworkFee.stories.tsx +91 -0
  67. package/src/contract-functions/signNetworkFee/signNetworkFee.ts +98 -0
  68. package/src/contract-functions/signStakeAndBake/index.ts +1 -0
  69. package/src/{web3Sdk → contract-functions}/signStakeAndBake/signStakeAndBake.stories.tsx +27 -40
  70. package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +140 -0
  71. package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +80 -0
  72. package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +65 -0
  73. package/src/index.ts +35 -10
  74. package/src/rewards/index.ts +26 -0
  75. package/src/rewards/lib/claim-reward.stories.tsx +82 -0
  76. package/src/rewards/lib/claim-reward.ts +84 -0
  77. package/src/rewards/lib/get-reward-balances.stories.tsx +64 -0
  78. package/src/rewards/lib/get-reward-balances.ts +81 -0
  79. package/src/rewards/lib/get-reward-signing-data.stories.tsx +76 -0
  80. package/src/rewards/lib/get-reward-signing-data.ts +52 -0
  81. package/src/rewards/lib/get-reward-withdrawal-fee.stories.tsx +61 -0
  82. package/src/rewards/lib/get-reward-withdrawal-fee.ts +37 -0
  83. package/src/rewards/lib/get-reward-withdrawals.stories.tsx +60 -0
  84. package/src/rewards/lib/get-reward-withdrawals.ts +92 -0
  85. package/src/rewards/lib/reward-tokens.ts +7 -0
  86. package/src/stories/components/Button/Button.css +10 -0
  87. package/src/stories/components/Button/Button.tsx +15 -4
  88. package/src/stories/components/CodeBlock/CodeBlock.tsx +1 -0
  89. package/src/stories/components/ConnectButton/connect-button.tsx +100 -0
  90. package/src/stories/components/ConnectButton/index.ts +1 -0
  91. package/src/stories/components/decorators/function-type.tsx +63 -0
  92. package/src/stories/components/decorators/index.ts +2 -0
  93. package/src/stories/components/decorators/wagmi-decorator.tsx +79 -0
  94. package/src/stories/components/error-block.tsx +21 -0
  95. package/src/stories/constants.ts +3 -0
  96. package/src/stories/hooks/useConnection.ts +72 -0
  97. package/src/stories/hooks/useQuery.ts +2 -2
  98. package/src/tokens/abi/LBTC_ABI.json +1761 -0
  99. package/src/tokens/abi/LBTC_BASCULE_ABI.json +850 -0
  100. package/src/tokens/lbtc-addresses.ts +54 -0
  101. package/src/tokens/lbtc-contract.ts +89 -0
  102. package/src/tokens/tokens.ts +111 -0
  103. package/src/utils/env.ts +12 -0
  104. package/src/utils/hex.ts +2 -2
  105. package/src/utils/numbers.ts +5 -0
  106. package/src/{common/utils/convertSatoshi.ts → utils/satoshi.ts} +3 -3
  107. package/src/utils/time.ts +12 -0
  108. package/src/vaults/abi/VEDA_VAULT_BASE_ASSET_ABI.json +296 -0
  109. package/src/vaults/abi/VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI.json +502 -0
  110. package/src/vaults/abi/VEDA_VAULT_SPENDER_ABI.json +408 -0
  111. package/src/vaults/abi/VEDA_VAULT_TELLER_ABI.json +700 -0
  112. package/src/vaults/index.ts +144 -36
  113. package/src/vaults/lib/cancel-withdraw.stories.tsx +79 -0
  114. package/src/vaults/lib/deposit.stories.tsx +81 -0
  115. package/src/vaults/lib/deposit.ts +151 -0
  116. package/src/vaults/lib/get-vault-deposits.stories.tsx +15 -9
  117. package/src/vaults/lib/get-vault-deposits.ts +45 -22
  118. package/src/vaults/lib/get-vault-points.stories.tsx +13 -6
  119. package/src/vaults/lib/get-vault-points.ts +14 -10
  120. package/src/vaults/lib/get-vault-withdrawals.stories.tsx +15 -8
  121. package/src/vaults/lib/get-vault-withdrawals.ts +72 -38
  122. package/src/vaults/lib/withdraw.stories.tsx +81 -0
  123. package/src/vaults/lib/withdraw.ts +224 -0
  124. package/src/common/const.ts +0 -5
  125. package/src/common/types/internalTypes.ts +0 -10
  126. package/src/common/types/types.ts +0 -57
  127. package/src/common/utils/isValidChain.ts +0 -5
  128. package/src/provider/Provider.ts +0 -171
  129. package/src/provider/ReadProvider.ts +0 -126
  130. package/src/provider/index.ts +0 -2
  131. package/src/provider/rpcUrlConfig.ts +0 -19
  132. package/src/provider/types.ts +0 -58
  133. package/src/provider/utils/getMaxPriorityFeePerGas.ts +0 -25
  134. package/src/sdk/getLBTCExchangeRate/getLBTCExchangeRate.ts +0 -65
  135. package/src/sdk/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +0 -85
  136. package/src/sdk/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +0 -86
  137. package/src/sdk/internalTypes.ts +0 -18
  138. package/src/sdk/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +0 -86
  139. package/src/sdk/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +0 -116
  140. package/src/sdk/utils/getChainIdByName.ts +0 -48
  141. package/src/sdk/utils/getChainNameById.ts +0 -41
  142. package/src/stories/const.ts +0 -1
  143. package/src/stories/hooks/useConnect.ts +0 -47
  144. package/src/stories/utils/connectInjectedWallet.ts +0 -12
  145. package/src/stories/utils/fromCamelCase.ts +0 -16
  146. package/src/stories/utils/getMetaTitle.ts +0 -7
  147. package/src/stories/utils/getWalletInfo.ts +0 -31
  148. package/src/web3Sdk/abi/BASCULE.json +0 -850
  149. package/src/web3Sdk/abi/IERC20.json +0 -222
  150. package/src/web3Sdk/abi/LBTC.json +0 -1761
  151. package/src/web3Sdk/abi/STAKE_AND_BAKE.json +0 -15
  152. package/src/web3Sdk/abi/index.ts +0 -6
  153. package/src/web3Sdk/approveLBTC/approveLBTC.stories.tsx +0 -77
  154. package/src/web3Sdk/approveLBTC/approveLBTC.ts +0 -48
  155. package/src/web3Sdk/claimLBTC/claimLBTC.ts +0 -86
  156. package/src/web3Sdk/const.ts +0 -2
  157. package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +0 -89
  158. package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.ts +0 -75
  159. package/src/web3Sdk/getBasculeDepositStatus/utils/const.ts +0 -8
  160. package/src/web3Sdk/getBasculeDepositStatus/utils/throwBasculeDepositStatusError.ts +0 -21
  161. package/src/web3Sdk/getLBTCMintingFee/getLBTCMintingFee.tsx +0 -41
  162. package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +0 -60
  163. package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.ts +0 -26
  164. package/src/web3Sdk/getPermitNonce/getPermitNonce.ts +0 -47
  165. package/src/web3Sdk/getShareValue/getShareValue.ts +0 -58
  166. package/src/web3Sdk/getStakeAndBakeFee/getStakeAndBakeFee.tsx +0 -48
  167. package/src/web3Sdk/lbtcAddressConfig.ts +0 -96
  168. package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +0 -23
  169. package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +0 -97
  170. package/src/web3Sdk/signNetworkFee/signNetworkFee.stories.tsx +0 -91
  171. package/src/web3Sdk/signNetworkFee/signNetworkFee.ts +0 -92
  172. package/src/web3Sdk/signStakeAndBake/contracts.ts +0 -80
  173. package/src/web3Sdk/signStakeAndBake/getTypedData.ts +0 -78
  174. package/src/web3Sdk/signStakeAndBake/index.ts +0 -3
  175. package/src/web3Sdk/signStakeAndBake/signStakeAndBake.ts +0 -105
  176. package/src/web3Sdk/signStakeAndBake/utils.ts +0 -23
  177. package/src/web3Sdk/types.ts +0 -16
  178. package/src/web3Sdk/unstakeLBTC/unstakeLBTC.stories.tsx +0 -77
  179. package/src/web3Sdk/unstakeLBTC/unstakeLBTC.ts +0 -51
  180. package/src/web3Sdk/utils/chainIdToEnv.ts +0 -12
  181. package/src/web3Sdk/utils/getBasculeTokenContract.ts +0 -21
  182. package/src/web3Sdk/utils/getGasMultiplier.ts +0 -20
  183. package/src/web3Sdk/utils/getLbtcTokenContract.ts +0 -36
  184. package/src/web3Sdk/utils/getRpcUrlConfigFromChain.ts +0 -34
  185. package/src/web3Sdk/utils/getTokenABI.ts +0 -12
  186. /package/src/{sdk → api-functions}/generateDepositBtcAddress/index.ts +0 -0
  187. /package/src/{sdk → api-functions}/getDepositBtcAddress/index.ts +0 -0
  188. /package/src/{sdk → api-functions}/getDepositsByAddress/index.ts +0 -0
  189. /package/src/{sdk → api-functions}/getLBTCExchangeRate/index.ts +0 -0
  190. /package/src/{sdk → api-functions}/getNetworkFeeSignature/index.ts +0 -0
  191. /package/src/{sdk → api-functions}/getPointsByAddress/index.ts +0 -0
  192. /package/src/{sdk → api-functions}/getUnstakesByAddress/index.ts +0 -0
  193. /package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/index.ts +0 -0
  194. /package/src/{sdk → api-functions}/setReferral/index.ts +0 -0
  195. /package/src/{sdk → api-functions}/storeNetworkFeeSignature/index.ts +0 -0
  196. /package/src/{sdk → api-functions}/storeStakeAndBakeSignature/index.ts +0 -0
  197. /package/src/{sdk/const.ts → common/constants.ts} +0 -0
  198. /package/src/{web3Sdk → contract-functions}/approveLBTC/index.ts +0 -0
  199. /package/src/{web3Sdk → contract-functions}/claimLBTC/index.ts +0 -0
  200. /package/src/{web3Sdk → contract-functions}/getBasculeDepositStatus/index.ts +0 -0
  201. /package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/index.ts +0 -0
  202. /package/src/{web3Sdk → contract-functions}/getLBTCTotalSupply/index.ts +0 -0
  203. /package/src/{web3Sdk → contract-functions}/getPermitNonce/index.ts +0 -0
  204. /package/src/{web3Sdk → contract-functions}/getShareValue/index.ts +0 -0
  205. /package/src/{web3Sdk → contract-functions}/getSharesByAddress/index.ts +0 -0
  206. /package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/index.ts +0 -0
  207. /package/src/{web3Sdk → contract-functions}/signLbtcDestionationAddr/index.ts +0 -0
  208. /package/src/{web3Sdk → contract-functions}/signNetworkFee/getTypedData.ts +0 -0
  209. /package/src/{web3Sdk → contract-functions}/signNetworkFee/index.ts +0 -0
  210. /package/src/{web3Sdk → contract-functions}/unstakeLBTC/index.ts +0 -0
  211. /package/src/{common/utils/getErrorMessage.ts → utils/err.ts} +0 -0
package/README.md CHANGED
@@ -1,554 +1,583 @@
1
1
  # @lombard.finance/sdk
2
2
 
3
- The SDK package provides a set of tools to interact with the Lombard Protocol.
3
+ The Lombard's SDK package provides a set of functions that allow interacting with the Lombard protocol and its features.
4
4
 
5
- It includes API-based and Web3-based methods with which to interact.
5
+ Read more about Lombard's mission: https://www.lombard.finance
6
6
 
7
- Web3 methods require a Web3 provider to be set up.
7
+ # Table of Contents
8
8
 
9
- ## Installation
9
+ [Installation](#installation)
10
10
 
11
- ```bash
12
- npm i @lombard.finance/sdk
13
- ```
11
+ 1. [Dependencies installation](#1-dependencies-installation)
14
12
 
15
- Install Dependencies
13
+ 2. [SDK installation](#2-sdk-installation)
16
14
 
17
- ```bash
18
- npm i web3@^4 axios@^1 bignumber.js@^9 @bitcoin-js/tiny-secp256k1-asmjs@2.2.3 bitcoinjs-lib@6.1.5
19
- ```
15
+ [Usage](#usage)
20
16
 
21
- ## Usage
17
+ 1. [Depositing BTC in order to get LBTC (aka staking)](#1-depositing-btc-in-order-to-get-lbtc-aka-staking)
22
18
 
23
- All methods are documented with JSDoc comments. You can use your IDE's autocomplete feature to see the available methods and their parameters.
19
+ 1.1. [Get the current minting fee](#11-get-the-current-minting-fee)
24
20
 
25
- ### Importing
21
+ 1.2. [Sign the network fee signature](#12-sign-the-network-fee-signature)
26
22
 
27
- If you are using a module bundler like Vite, Webpack or Rollup, you can import the package like this:
23
+ 1.3. [Store the signature to the Lombard's systems](#13-store-the-signature-to-the-lombards-systems)
28
24
 
29
- ```typescript
30
- import { getDepositBtcAddress } from '@lombard.finance/sdk';
31
- ```
25
+ 1.4. [Get or generate the BTC deposit address](#14-get-or-generate-the-btc-deposit-address)
32
26
 
33
- If you are using a commonjs module system, you can import the package like this:
27
+ 1.5. [Deposit BTC to the address](#15-deposit-btc-to-the-address)
34
28
 
35
- ```javascript
36
- const { getDepositBtcAddress } = require('@lombard.finance/sdk');
37
- ```
38
-
39
- ### API Methods
40
-
41
- - API based
42
- - [getDepositBtcAddress](#getDepositBtcAddress)
43
- - [getDepositBtcAddresses](#getDepositBtcAddresses)
44
- - [generateDepositBtcAddress](#generateDepositBtcAddress)
45
- - [getDepositsByAddress](#getDepositsByAddress)
46
- - [getLBTCExchangeRate](#getLBTCExchangeRate)
47
- - [storeStakeAndBakeSignature](#storeStakeAndBakeSignature)
48
- - [getUserStakeAndBakeSignature](#getUserStakeAndBakeSignature)
49
- - [storeNetworkFeeSignature](#storeNetworkFeeSignature)
50
- - [getNetworkFeeSignature](#getNetworkFeeSignature)
51
- - Web3 based
52
- - [signLbtcDestionationAddr](#signLbtcDestionationAddr)
53
- - [claimLBTC](#claimLBTC)
54
- - [unstakeLBTC](#unstakeLBTC)
55
- - [getBasculeDepositStatus](#getBasculeDepositStatus)
56
- - [getLBTCTotalSupply](#getLBTCTotalSupply)
57
- - [signStakeAndBake](#signStakeAndBake)
58
- - [getStakeAndBakeFee](#getStakeAndBakeFee)
59
- - [signNetworkFee](#signNetworkFee)
60
-
61
- #### getDepositBtcAddress
62
-
63
- `@returns Promise<string>`
64
-
65
- Returns the address for depositing BTC.
66
-
67
- Parameters:
68
- | name | type | description |
69
- |-----------|----------|--------------------------------------------------------------|
70
- | `address` | `string` | The destination EVM user address where LBTC will be claimed. |
71
- | `chainId` | `TChainId` | The destination chain ID where LBTC will be claimed. |
72
- | `env` | `Env` | Environment (optional, default: 'prod') |
73
- | `partnerId` | `string` | Partner ID (optional) |
74
-
75
- Usage
29
+ 1.6. [Check the status of your deposit](#16-check-the-status-of-your-deposit)
76
30
 
77
- ```typescript
78
- import { getDepositBtcAddress } from '@lombard.finance/sdk';
79
- ...
80
- const depositBtcAddress = await getDepositBtcAddress({
81
- address: '0x...',
82
- chainId: 1,
83
- partnerId: 'YOUR_PARTNER_ID',
84
- }); // bc1q...
85
- ```
31
+ 2. [Manually claiming LBTC](#2-manually-claiming-lbtc)
86
32
 
87
- #### getDepositBtcAddresses
33
+ 3. [Depositing BTC and automatically staking LBTC into the DeFi vault (aka stake and bake)](#3-depositing-btc-and-automatically-staking-lbtc-into-the-defi-vault-aka-stake-and-bake)
88
34
 
89
- `@returns Promise<IDepositAddress[]>`
35
+ 3.1. [See what's the current stake and bake fee](#31-see-whats-the-current-stake-and-bake-fee)
90
36
 
91
- Returns the addresses for depositing BTC.
37
+ 3.2. [Sign the stake and bake signature](#32-sign-the-stake-and-bake-signature)
92
38
 
93
- Parameters are the same as for `getDepositBtcAddress`.
39
+ 3.3. [Store the signature to the Lombard's systems](#33-store-the-signature-to-the-lombards-systems)
94
40
 
95
- Probably you will not need this method. You can just use `getDepositBtcAddress`.
41
+ 3.4. [Get or generate the BTC deposit address](#34-get-or-generate-the-btc-deposit-address)
96
42
 
97
- #### generateDepositBtcAddress
43
+ 3.5. [Deposit BTC to the address](#35-deposit-btc-to-the-address)
98
44
 
99
- `@returns {Promise<string>}`
45
+ 3.6. [Check the status of your deposit](#36-check-the-status-of-your-deposit)
100
46
 
101
- Generates a BTC deposit address.
102
- If the provided EVM address is sanctioned, the function will return the `SANCTIONED_ADDRESS` variable.
47
+ 3.7. [Check the amount of shares acquired](#37-check-the-amount-of-shares-acquired)
103
48
 
104
- Parameters:
105
- | name | type | description |
106
- |----------------|------------|---------------------------------------------------------------------------------------------------|
107
- | `address` | `string` | The destination EVM user address where LBTC will be claimed. |
108
- | `chainId` | `TChainId` | The destination chain ID where LBTC will be claimed. |
109
- | `signature` | `string` | The signature of the address. The signature is generated by signing the address using EVM wallet. |
110
- | `referrerCode` | `string` | The referrer code. |
111
- | `env` | `Env` | Environment (optional, default: 'prod') |
112
- | `captchaToken` | `string` | The captcha token (optional) |
113
- | `partnerId` | `string` | The partner ID (optional) |
49
+ 4. [Unstaking LBTC and getting BTC back](#4-unstaking-lbtc-and-getting-btc-back)
114
50
 
115
- Usage
51
+ 4.1. [Unstake LBTC](#41-unstake-lbtc)
116
52
 
117
- ```typescript
118
- import { generateDepositBtcAddress } from '@lombard.finance/sdk';
119
- ...
120
- const depositBtcAddress = await generateDepositBtcAddress({
121
- address: '0x...',
122
- chainId: 1,
123
- signature: 'SIGNATURE',
124
- partnerId: 'YOUR_PARTNER_ID',
125
- referrerCode: 'YOUR_REFERRER_CODE',
126
- }); // bc1q...
127
- ```
53
+ 4.2. [Check the status of your unstakes](#42-check-the-status-of-your-unstakes)
128
54
 
129
- #### getDepositsByAddress
55
+ 5. [Depositing LBTC to the DeFi vault](#5-depositing-lbtc-to-the-defi-vault)
130
56
 
131
- `@returns Promise<IDeposit[]>`
132
- Returns all deposits for a given address.
57
+ 5.1. [Making a deposit to the DeFi vault](#51-making-a-deposit-to-the-defi-vault)
133
58
 
134
- Parameters:
59
+ 5.2. [Checking the deposit history](#52-checking-the-deposit-history)
135
60
 
136
- | name | type | description |
137
- | --------- | ------- | --------------------------------------- |
138
- | `address` | `string` | The EVM address to get deposits for |
139
- | `env` | `Env` | Environment (optional, default: 'prod') |
61
+ 5.3. [Checking the user's DeFi vault balance](#53-checking-the-users-defi-vault-balance)
140
62
 
141
- Usage
63
+ 6. [Withdrawing LBTC from the DeFi vault](#6-withdrawing-lbtc-from-the-defi-vault)
142
64
 
143
- ```typescript
144
- import { getDepositsByAddress } from '@lombard.finance/sdk';
145
- ...
146
- const deposits = await getDepositsByAddress({
147
- address: '0x...',
148
- }); // [{...}]
149
- ```
65
+ 6.1. [Requesting a withdrawal from the DeFi vault](#61-requesting-a-withdrawal-from-the-defi-vault)
150
66
 
151
- #### getLBTCExchangeRate
67
+ 6.2. [Checking the withdrawal history (tracking the withdrawal request)](#62-checking-the-withdrawal-history-tracking-the-withdrawal-request)
152
68
 
153
- `@returns Promise<number>`
69
+ 6.3. [Cancelling the withdrawal](#63-cancelling-the-withdrawal)
154
70
 
155
- Returns the exchange rate for LBTC.
71
+ 7. [Getting the points earned by an address](#7-getting-the-points-earned-by-an-address)
156
72
 
157
- Parameters:
73
+ 8. [Getting the DeFi vault points earned by an address](#8-getting-the-defi-vault-points-earned-by-an-address)
158
74
 
159
- | name | type | description |
160
- | --------- | --------- | ------------------------------------------------------ |
161
- | `chainId` | `TChainId` | The chain id of the asset to get the exchange rate for |
162
- | `amount` | `number` | The amount of the asset to get the exchange rate for |
163
- | `env` | `Env` | Environment (optional, default: 'prod') |
75
+ 9. [Claiming rewards](#9-claiming-rewards)
164
76
 
165
- Usage
77
+ 9.1. [Checking reward balances](#91-checking-reward-balances)
166
78
 
167
- ```typescript
168
- import { getLBTCExchangeRate } from '@lombard.finance/sdk';
169
- ...
170
- const exchangeRate = await getLBTCExchangeRate({
171
- chainId: 1,
172
- amount: 3,
173
- }); // 3
174
- ```
79
+ 9.2. [Claiming rewards](#92-claiming-rewards)
175
80
 
176
- #### signLbtcDestionationAddr
81
+ 9.3. [Checking the reward withdrawal fee](#93-checking-the-reward-withdrawal-fee)
177
82
 
178
- `@returns Promise<string>` - The signature of the message.
83
+ 9.4. [Getting the withdrawal history (checking withdrawal status)](#94-getting-the-withdrawal-history-checking-withdrawal-status)
179
84
 
180
- Signs the destination address for the LBTC in active chain in the current account.
181
- Signing is necessary for the generation of the deposit address.
182
85
 
183
- Parameters:
86
+ ## Installation
184
87
 
185
- | name | type | description |
186
- | ---------- | ------------------ | ------------------------------ |
187
- | `provider` | `IEIP1193Provider` | The EIP-1193 provider instance |
188
- | `account` | `string` | Current account address |
189
- | `chainId` | `TChainId` | Current chain ID |
88
+ ### 1. Dependencies installation
190
89
 
191
- Usage
90
+ The SDK depends on the following packages:
91
+ * axios
92
+ * viem@2.23
93
+ * bignumber.js@9
94
+ * bitcoinjs-lib@6.1.5
95
+ * @bitcoin-js/tiny-secp256k1-asmjs@2.2.3
192
96
 
193
- ```typescript
194
- import { signLbtcDestinationAddr } from '@lombard.finance/sdk';
97
+ You may install them by running the following command:
98
+
99
+ ```bash
100
+ 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
101
+ ```
102
+
103
+ ### 2. SDK installation
195
104
 
196
- ...
197
- // do connect to the wallet using web3.js or ethers.js or any other library
198
- // and get the provider, account and chainId
199
- const destinationAddr = await signLbtcDestinationAddr({
200
- provider: window.ethereum,
201
- account: '0x...',
202
- chainId: 1,
203
- }); // '0x...'
105
+ To install the SDK package, please run:
106
+
107
+ ```bash
108
+ npm i --save @lombard.finance/sdk
204
109
  ```
205
110
 
206
- #### claimLBTC
111
+ ## Usage
207
112
 
208
- `@returns Promise<IWeb3SendResult>` transaction promise
113
+ All functions are documented with JSDoc comments. You can use your IDE's autocomplete feature to see the available methods and their parameters.
209
114
 
210
- Claims LBTC.
115
+ ### 1. Depositing BTC in order to get LBTC (aka staking).
211
116
 
212
- Parameters:
117
+ You can read more about LBTC here: https://docs.lombard.finance/lbtc-liquid-bitcoin/introduction-to-lbtc
213
118
 
214
- | name | type | description |
215
- | ---------------- | ----------------- | -------------------------------------------------------------------------------------- |
216
- | `data` | `string` | Raw payload from deposit notarization. Can be obtained from the `getDepositsByAddress` |
217
- | `proofSignature` | `string` | Signature from deposit notarization. Can be obtained from the `getDepositsByAddress` |
218
- | `provider` | `IEIP1193Provider` | The EIP-1193 provider instance |
219
- | `account` | `string` | Current account address |
220
- | `chainId` | `TChainId` | Current chain ID |
221
- | `env` | `Env` | Environment (optional, default: 'prod') |
119
+ If you'd wish to stake your BTC and get LBTC follow the below steps:
222
120
 
223
- Usage
121
+ #### 1.1 Get the current minting fee.
224
122
 
225
- ```typescript
226
- import { claimLBTC } from '@lombard.finance/sdk';
227
- ...
228
- // do connect to the wallet using web3.js or ethers.js or any other library
229
- // and get the provider, account and chainId
230
- const { receiptPromise, transactionHash } = await claimLBTC({
231
- data: 'PAYLOAD',
232
- proofSignature: 'SIGNATURE',
233
- provider: window.ethereum,
234
- account: '0x...',
235
- chainId: 1,
123
+ ```javascript
124
+ const fee = await getLBTCMintingFee({ chainId: ChainId.ethereum }); // The fee represented in satoshis (BigNumber)
125
+ ```
126
+
127
+ #### 1.2. Sign the network fee signature.
128
+
129
+ ```javascript
130
+ const expiry = Math.round((Date.now() + 24 * 60 * 60 * 1000) / 1000);
131
+ const { signature, typedData } = await signNetworkFee({
132
+ fee, // The fee from step 1
133
+ 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.
134
+ account, // The destination account address from the connected wallet.
135
+ chainId: ChainId.ethereum // The destination chain id.
136
+ provider, // The EIP-1193 provider, e.g. the injected provider: window.ethereum
236
137
  });
237
- console.log(transactionHash); // '0x...'
238
- const receipt = await receiptPromise; // {...}
239
138
  ```
240
139
 
241
- #### unstakeLBTC
140
+ #### 1.3. Store the signature to the Lombard's systems.
242
141
 
243
- `@returns Promise<IWeb3SendResult>` transaction promise
142
+ ```javascript
143
+ await storeNetworkFeeSignature({ signature, typedData, address }); // Pass the signature and typed data from step 2.
144
+ ```
244
145
 
245
- Unstakes LBTC to the specified BTC address.
146
+ It is recommended to verify that the signature has been stored. Please use `getNetworkFeeSignature`.
246
147
 
247
- Parameters:
148
+ ```javascript
149
+ const { expirationData, hasSignature, isDelayed } = await getNetworkFeeSignature({ address, chainId });
150
+ ```
248
151
 
249
- | name | type | description |
250
- | ------------ | ----------------- | ------------------------------------------- |
251
- | `btcAddress` | `string` | The BTC address to send the unstaked BTC to |
252
- | `amount` | `string` | The amount of LBTC to unstake |
253
- | `provider` | `IEIP1193Provider` | The EIP-1193 provider instance |
254
- | `account` | `string` | Current account address |
255
- | `chainId` | `TChainId` | Current chain ID |
256
- | `env` | `Env` | Environment (optional, default: 'prod') |
152
+ `isDelayed` is a flag determining whether the execution of auto-claimer using the stored signature is delayed due to the higher gas costs.
257
153
 
258
- Usage
154
+ #### 1.4. Get or generate the BTC deposit address.
259
155
 
260
- ```typescript
261
- import { unstakeLBTC } from '@lombard.finance/sdk';
262
- ...
263
- // do connect to the wallet using web3.js or ethers.js or any other library
264
- // and get the provider, account and chainId
265
- const { receiptPromise, transactionHash } = await unstakeLBTC({
266
- btcAddress: 'bs...',
267
- amount: 1,
268
- provider: window.ethereum,
269
- account: '0x...',
270
- chainId: 1,
271
- });
272
- console.log(transactionHash); // '0x...'
273
- const receipt = await receiptPromise; // {...}
156
+ ```javascript
157
+ let depositBtcAddress = await getDepositBtcAddress({ address, chainId });
158
+ if (!depositBtcAddress) {
159
+ depositBtcAddress = await generateDepositBtcAddress({
160
+ address,
161
+ chainId,
162
+ signature, // Pass here the signature from step 2.
163
+ eip712Data: typedData // Pass here the typed data from step 2.
164
+ });
165
+ }
274
166
  ```
275
167
 
276
- #### getBasculeDepositStatus
168
+ #### 1.5. Deposit BTC to the address.
277
169
 
278
- `@returns Promise<BasculeDepositStatus>` transaction promise
170
+ Now you can deposit your BTC to the generated in the previous step BTC address.
171
+ The funds will be claimed automatically by Lombard's claimer and transferred to
172
+ the account (`address`).
279
173
 
280
- Check Deposit Status by hash id through Bascule
174
+ #### 1.6. Check the status of your deposit.
281
175
 
282
- Parameters:
176
+ If you'd like to check the status of your deposit use `getDepositsByAddress` function.
283
177
 
284
- | name | type | description |
285
- | ---------- | ----------------- | ---------------------------------------------------------------------------------- |
286
- | `txId` | `string` | Payload from deposit notarization. Can be obtained from the `getDepositsByAddress` |
287
- | `provider` | `IEIP1193Provider` | The EIP-1193 provider instance |
288
- | `account` | `string` | Current account address |
289
- | `chainId` | `TChainId` | Current chain ID |
290
- | `env` | `Env` | Environment (optional, default: 'prod') |
178
+ ```javascript
179
+ const deposits = await getDepositsByAddress({ address });
180
+ ```
291
181
 
292
- Usage
182
+ Every entry in the result of the above function may consist of the following properties:
183
+ * `txid` - the BTC transaction id,
184
+ * `index` - the index of the actual deposit transaction,
185
+ * `blockHeight`
186
+ * `blockTime`
187
+ * `value` - the amount of BTC deposited,
188
+ * `address` - the destination address,
189
+ * `chainId` - the destination chain id,
190
+ * `isClaimer` - a flag determining whether the deposit has been already claimed,
191
+ * `claimedTxId` - the corresponding claim transaction that transfer funds to the destination address,
192
+ * `rawPayload` - the payload of the transaction (can be use to claim the funds manually),
193
+ * `signature` - the signature used (can be used to claim the funds manually),
194
+ * `isRestricted` - a flag determining whether the transaction has been marked as suspicious/restricted,
195
+ * `payload` - the payload (corresponding to the Bascule drawbridge security),
196
+ * `sessionId`
197
+ * `notarizationStatus` - the notarization status of the deposit (pending, submitted, approved or failed),
198
+ * `sessionState` - the state of the session (pending, completed, expired)
199
+
200
+ ### 2. Manually claiming LBTC.
201
+
202
+ 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:
293
203
 
294
- ```typescript
295
- import { getBasculeDepositStatus } from '@lombard.finance/sdk';
296
- ...
297
- // do connect to the wallet using web3.js or ethers.js or any other library
298
- // and get the provider, account and chainId
299
- const status = await getBasculeDepositStatus({
300
- txId: 'PAYLOAD',
301
- provider: window.ethereum,
302
- chainId: 1,
303
- });
304
- console.log(status); // '0, 1, 2'
204
+ ```javascript
205
+ const txHash = await claimLBTC({
206
+ data: rawPayload, // Pass the raw payload from the deposit data as presented in the previous step.
207
+ proofSignature: signature, // Pass the signature from the deposit data.
208
+ account, // The connected account address
209
+ chainId, // The chain id
210
+ provider, // The EIP-1193 provider,
211
+ rpcUrl, // The optional RPC url.
212
+ })
305
213
  ```
306
214
 
307
- #### getLBTCTotalSupply
215
+ The successful execution of the above will result with the transaction id.
308
216
 
309
- `@returns Promise<string>` Supply promise
217
+ ### 3. Depositing BTC and automatically staking LBTC into the DeFi vault (aka stake and bake)
310
218
 
311
- Get LBTC total supply
219
+ You can read more about the DeFi vaults here: https://docs.lombard.finance/lbtc-liquid-bitcoin/defi-vaults/lombard-defi-vault
312
220
 
313
- Parameters:
221
+ If you'd wish to stake and bake your BTC follow the steps below.
314
222
 
315
- | name | type | description |
316
- | --------- | --------- | --------------------------------------- |
317
- | `rpcUrl` | `string` | Rpc url for the chain |
318
- | `chainId` | `TChainId` | Current chain ID |
319
- | `env` | `Env` | Environment (optional, default: 'prod') |
223
+ #### 3.1. See what's the current stake and bake fee.
320
224
 
321
- Usage
322
-
323
- ```typescript
324
- import { getLBTCTotalSupply } from '@lombard.finance/sdk';
225
+ To check the current stake and bake fee you may use the following function:
325
226
 
326
- const totalSupply = await getLBTCTotalSupply({
327
- rpcUrl: 'yourRpcUrl',
328
- chainId: 1,
227
+ ```javascript
228
+ const fee = await getStakeAndBakeFee({
229
+ vaultKey: Vault.Veda, // The vault identifier, currently only "veda" is accepted.
230
+ chainId, // The chain id.
231
+ rpcUrl, // The options RPC url.
329
232
  });
330
- console.log(totalSupply); // '2000000'
233
+ const expectedLBTCAmount = BigNumber(amountToBeDeposited).minus(fee);
331
234
  ```
235
+ The fee amount will be deducted from the claimed LBTC automatically.
332
236
 
333
- #### signStakeAndBake
334
-
335
- `@returns Promise<ISignStakeAndBakeResult>` Sign authorization promise
336
-
337
- Sign Stake And Bake
237
+ #### 3.2. Sign the stake and bake signature.
338
238
 
339
- ## Parameters
239
+ ```javascript
240
+ const { signature, typedData } = await signStakeAndBake({
241
+ account, // The connected account address,
242
+ 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.
243
+ value, // The amount of BTC (in satoshis)
244
+ vaultKey: Vault.Veda, // The vault identifier, currently only "veda" is accepted.
245
+ chainId, // The chain id.
246
+ provider, // The EIP-1193 provider.
247
+ rpcUrl, // The optional RPC url.
248
+ })
249
+ ```
340
250
 
341
- | name | type | description |
342
- | ---------- | ------------------- | ------------------------------------------------- |
343
- | `provider` | `IProvider` | Provider instance to interact with the blockchain |
344
- | `address` | `string` | The address to sign with (owner) |
345
- | `chainId` | `TChainId` | Chain ID for the signature |
346
- | `value` | `string` | The value to approve |
347
- | `expiry` | `number` | Expiry date as a unix timestamp |
348
- | `rpcUrl` | `string` (optional) | Optional RPC URL for the network |
349
- | `vaultKey` | `string` | The key of the vault to authorize |
251
+ #### 3.3. Store the signature to the Lombard's systems.
350
252
 
351
- Usage
253
+ ```javascript
254
+ await storeStakeAndBakeSignature({
255
+ signature, // Pass here the signature form the previous step.
256
+ typedData, // Pass here the typed data from the previous step.
257
+ })
258
+ ```
352
259
 
353
- ```typescript
354
- import { signStakeAndBake } from '@lombard.finance/sdk';
260
+ It is recommended to verify if the signature has been stored.
355
261
 
356
- const { signature, signatureData } = await signStakeAndBake({
357
- provider: window.ethereum,
358
- address: '0x...',
262
+ ```javascript
263
+ const data = await getUserStakeAndBakeSignature({
264
+ userDestinationAddress: address,
359
265
  chainId,
360
- value: toSatoshi(approvalValue.toString()).toString(),
361
- expiry: permitExpiryTime,
362
- vaultKey: selectedVault.key,
363
- });
266
+ })
364
267
  ```
365
268
 
366
- #### storeStakeAndBakeSignature
269
+ #### 3.4. Get or generate the BTC deposit address.
367
270
 
368
- `@returns Promise<IStoreStakeAndBakeSignatureStatus>` Store Stake And Bake Signature Status promise
271
+ ```javascript
272
+ let depositBtcAddress = await getDepositBtcAddress({ address, chainId });
273
+ if (!depositBtcAddress) {
274
+ depositBtcAddress = await generateDepositBtcAddress({
275
+ address,
276
+ chainId,
277
+ signature, // Pass here the signature from step 2.
278
+ signatureData: typedData // Pass here the typed data from step 2.
279
+ });
280
+ }
281
+ ```
369
282
 
370
- Store stake and bake signature
283
+ #### 3.5. Deposit BTC to the address.
371
284
 
372
- ## Parameters
285
+ 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.
373
286
 
374
- | name | type | description |
375
- | ----------- | -------- | --------------------------------------- |
376
- | `env` | `TEnv` | Environment (e.g., 'prod', 'stage', etc.) |
377
- | `signature` | `string` | The generated signature |
378
- | `typedData` | `string` | JSON typed data used for the signature |
287
+ #### 3.6. Check the status of you deposit
379
288
 
380
- Usage
289
+ ```javascript
290
+ const deposits = await getDepositsByAddress({ address });
291
+ ```
381
292
 
382
- ```typescript
383
- import { storeStakeAndBakeSignature } from '@lombard.finance/sdk';
293
+ #### 3.7. Check the amount of shares acquired.
384
294
 
385
- const status = await storeStakeAndBakeSignature({
386
- signature,
387
- signatureData,
388
- env: 'prod',
295
+ ```javascript
296
+ const { balance, exchangeRate, balanceLbtc } = await getSharesByAddress({
297
+ vaultKey: Vault.Veda, // The vault identifier.
298
+ address, // The account address.
299
+ chainId, // The chain id.
300
+ rpcUrl, // The optional RPC url
389
301
  });
390
302
  ```
391
303
 
392
- #### getUserStakeAndBakeSignature
304
+ The above code results with:
305
+ * `balance` - The amount of LBTCv shares owned by the account,
306
+ * `exchangeRate` - The current LBTCv to LBTC exchange rate,
307
+ * `balanceLbtc` - The value of the owned shares is LBTC.
393
308
 
394
- `@returns Promise<IGetUserStakeAndBakeSignatureResponse>` Promise that resolves to the signature response
309
+ ### 4. Unstaking LBTC and getting BTC back.
395
310
 
396
- Get user's stake and bake signature from the API
311
+ Every LBTC is redeemable back to BTC, you can do that programmatically by following the steps:
397
312
 
398
- ## Parameters
313
+ #### 4.1. Unstake LBTC.
399
314
 
400
- | name | type | description |
401
- | ------------------------ | ------- | --------------------------------------- |
402
- | `userDestinationAddress` | `string` | The user's destination address |
403
- | `chainId` | `string` | The chain ID |
404
- | `env` | `TEnv` | Environment (e.g., 'prod', 'stage', etc.) |
315
+ ```javascript
316
+ const txaHash = await unstakeLBTC({
317
+ btcAddress, // The address to which the funds will be redeemed.
318
+ amount, // The amount of LBTC to unstake.
319
+ account, // The account address.
320
+ chainId, // The chain id.
321
+ provider, // The EIP-1193 provider.
322
+ rpcUrl, // The optional RPC url.
323
+ });
324
+ ```
405
325
 
406
- Usage
326
+ #### 4.2. Check the status of your unstakes.
407
327
 
408
- ```typescript
409
- import { getUserStakeAndBakeSignature } from '@lombard.finance/sdk';
328
+ If you'd like to get the list of all unstaked made by an address, use this:
410
329
 
411
- const response = await getUserStakeAndBakeSignature({
412
- userDestinationAddress: address,
413
- chainId,
414
- env: 'prod',
415
- });
416
- console.log(response);
330
+ ```javascript
331
+ const unstakes = await getUnstakesByAddress({ address });
417
332
  ```
418
333
 
419
- #### storeNetworkFeeSignature
334
+ Every entry in the result of the above may consist of:
335
+ * `txHash` - The unstake transaction hash,
336
+ * `chainId`,
337
+ * `blockHeight`,
338
+ * `unstakeDate`,
339
+ * `fromAddress` - The EVM source address,
340
+ * `toAddress` - The BTC destination address of the funds,
341
+ * `amount` - The amount unstaked,
342
+ * `payoutTxHash` - The BTC transaction hash,
343
+ * `payoutTxIndex` - The index of the actual payout transfer,
344
+ * `sanctioned` - A flag indicating whether the unstake transaction has been sanctioned and flagged as suspicious.
420
345
 
421
- `@returns Promise<IStoreNetworkFeeSignatureResponse>` Response promise with statuses
346
+ ### 5. Depositing LBTC to the DeFi vault.
422
347
 
423
- Store authorize network fee
348
+ If a user already has LBTC depositing to the DeFi vault can be done via the `deposit` function.
424
349
 
425
- ## Parameters
350
+ #### 5.1. Making a deposit to the DeFi vault.
426
351
 
427
- | name | type | description |
428
- | ------------------------ | -------- | --------------------------------------- |
429
- | `signature` | `string` | The signature of signNetworkFee method |
430
- | `typedData` | `string` | JSON typed data used for the signature |
431
- | `address` | `string` | Destination address |
432
- | `env` | `TEnv` | Environment (e.g., 'prod', 'stage', etc.) |
352
+ ```javascript
353
+ const txHash = await deposit({
354
+ amount, // The deposit amount, e.g. 1.23 (LBTC)
355
+ approve = true, // The optional flag determining whether approval should be done within deposit execution.
356
+ token = 'LBTC', // The optional deposit token.
357
+ vaultKey = Vault.Veda, // The optional vault identifier.
358
+ account, // The account address.
359
+ chainId, // The chain id.
360
+ provider, // The EIP-1193 provider
361
+ rpcUrl, // The optional RPC url
362
+ })
363
+ ```
433
364
 
434
- Usage
365
+ #### 5.2. Checking the deposit history.
435
366
 
436
- ```typescript
437
- import { storeNetworkFeeSignature } from '@lombard.finance/sdk';
438
-
439
- const status = await storeNetworkFeeSignature({
440
- signature: '',
441
- typedData: '',
442
- address: '0x...',
443
- env: 'prod',
367
+ ```javascript
368
+ const deposits = await getVaultDeposits({
369
+ account, // The account address.
370
+ chainId, // The chain id.
371
+ vaultKey = Vault.Veda // The optional vault identifier.
444
372
  });
445
- console.log(status); // success
446
373
  ```
447
374
 
448
- #### getNetworkFeeSignature
375
+ The above function returns an array of deposit data made by the specified user.
376
+ Each entry contains:
377
+ * `txHash` - the transaction hash,
378
+ * `blockNumber` - the transaction's block number,
379
+ * `chainId` - the chain id,
380
+ * `amount` - the deposited amount,
381
+ * `shareAmount` - the amount of shares received,
382
+ * `token` - the deposit token.
449
383
 
450
- `@returns Promise<IStoreNetworkFeeSignatureResponse>` Response promise with statuses
384
+ #### 5.3. Checking the user's DeFi vault balance.
451
385
 
452
- Store authorize network fee
386
+ In order to check the user's balance of the vault tokens, use this:
453
387
 
454
- ## Parameters
388
+ ```javascript
389
+ const { balance, exchangeRate, balanceLbtc } = await getSharesByAddress({
390
+ vaultKey: Vault.Veda, // The vault identifier.
391
+ address, // The account address.
392
+ chainId, // The chain id.
393
+ rpcUrl, // The optional RPC url
394
+ });
395
+ ```
455
396
 
456
- | name | type | description |
457
- | ------------------------ | -------- | --------------------------------------- |
458
- | `chainId` | `number` | The chain ID |
459
- | `address` | `string` | Destination address |
460
- | `env` | `TEnv` | Environment (e.g., 'prod', 'stage', etc.) |
397
+ The above function returns the:
398
+ * `balance` - balance of LBTCv,
399
+ * `exchangeRate` - the current exchange rate between LBTCv and LBTC,
400
+ * `balanceLbtc` - the value of LBTCv represented in LBTC.
461
401
 
462
- Usage
402
+ ### 6. Withdrawing LBTC from the DeFi vault.
463
403
 
464
- ```typescript
465
- import { getNetworkFeeSignature } from '@lombard.finance/sdk';
404
+ #### 6.1. Requesting a withdrawal from the DeFi vault
466
405
 
467
- const signatureResponse = await getNetworkFeeSignature({
468
- chainId: 1,
469
- address: '0x...',
470
- env: 'prod',
471
- });
472
- console.log(signatureResponse);
406
+ Requesting a withdrawal from the DeFi vault can be done via:
407
+ ```javascript
408
+ const txHash = await withdraw({
409
+ amount, // The amount of shares.
410
+ approve = true, // The optional flag determining if approve action should be done within this execution.
411
+ token = 'LBTC', // The optional withdraw token.
412
+ vaultKey = Vault.Veda, // The optional vault identifier.
413
+ account, // The account address.
414
+ chainId, // The chain id.
415
+ provider, // The EIP-1192 provider.
416
+ rpcUrl, // The optional RPC url
417
+ })
473
418
  ```
474
419
 
475
- #### getStakeAndBakeVaults
420
+ #### 6.2. Checking the withdrawal history (tracking the withdrawal request)
476
421
 
477
- `@returns IStakeAndBakeVault[]` A list of available vaults
422
+ In order to check the whole history or to track the particular withdrawal please use the following function:
478
423
 
479
- ## Parameters
424
+ ```javascript
425
+ const withdrawals = await getVaultWithdrawals({
426
+ account, // The account address.
427
+ chainId, // The chain id.
428
+ vaultKey = Vault.Veda, // The optional vault identifier.
429
+ rpcUrl, // The optional RPC url
430
+ })
431
+ ```
480
432
 
481
- | name | type | description |
482
- | --------- | -------- | ------------ |
483
- | `chainId` | `string` | The chain ID |
433
+ The result of the above is an object with broken down withdrawals by their state:
434
+ ```javascript
435
+ {
436
+ cancelled: [...], // The cancelled requests.
437
+ expired: [...], // The requests that expired.
438
+ fulfilled: [...], // The fulfilled requests (funds were transferred).
439
+ open: [...], // The open withdrawal requests (still to be processed).
440
+ }
441
+ ```
484
442
 
485
- Usage
443
+ Each of the arrays from above consist of:
444
+ * `token` - the withdrawal token (LBTC),
445
+ * `shareAmount` - the amount of shares withdrawn,
446
+ * `amount` - the amount of funds withdrawn,
447
+ * `minPrice` - the min price of a share,
448
+ * `deadline` - the expiration timestamp,
449
+ * `timestamp` - the request timestamp,
450
+ * `txHash` - the withdraw request transaction hash,
451
+ * `blockNumber` - the request block number,
452
+ * `fulfilledTimestamp` - the fulfilment timestamp,
453
+ * `fulfilledTxHash` - the funds transfer transaction hash,
454
+ * `fulfilledBlockNumber` - the fulfilment block number.
486
455
 
487
- ```typescript
488
- import { getStakeAndBakeVaults } from '@lombard.finance/sdk';
456
+ #### 6.3. Cancelling the withdrawal
489
457
 
490
- const vaults = getStakeAndBakeVaults(1);
458
+ If you wish to cancel you open withdrawal request use this:
491
459
 
492
- console.log(vaults);
460
+ ```javascript
461
+ const txHash = await cancelWithdraw({
462
+ token = 'LBTC', // The optional withdrawal asset.
463
+ vaultKey = Vault.Veda, // The optional vault identifier.
464
+ account, // The account address.
465
+ chainId, // The chain id.
466
+ provider, // The EIP-1193 provider.
467
+ rpcUrl, // The optional RPC url.
468
+ });
493
469
  ```
494
470
 
495
- #### getStakeAndBakeFee
471
+ ### 7. Getting the points earned by an address.
472
+
473
+ If you'd like to check the amount of LUX points earned by an address then simply run the following function:
496
474
 
497
- `@returns Promise<string>` Promise that resolves stakeAndBake fee in satoshis
475
+ ```javascript
476
+ const points = await getPointsByAddress({ address: "0x...YOUR_ADDRESS" })
477
+ ```
498
478
 
499
- Get Stake and bake fee in satoshis
479
+ The function returns the object of shape:
480
+ ```typescript
481
+ {
482
+ /**
483
+ * The number of points earned by holding LBTC.
484
+ */
485
+ holdingPoints: number;
486
+ /**
487
+ * The number of points earned by taking positions in DeFi vaults.
488
+ */
489
+ protocolPoints: number;
490
+ /**
491
+ * The number of points earned by your referrals.
492
+ */
493
+ referralPoints: number;
494
+ /**
495
+ * The number of points earned in the OKX campaign.
496
+ */
497
+ okxPoints: number;
498
+ /**
499
+ * The number of points earned by participating in the flash events.
500
+ */
501
+ flashEventPoints: number;
502
+ /**
503
+ * The total number of points.
504
+ */
505
+ totalPoints: number;
506
+ /**
507
+ * The breakdown of points earned from each protocol.
508
+ */
509
+ protocolPointsBreakdown: IProtocolPointsBreakdown;
510
+ }
511
+ ```
500
512
 
501
- ## Parameters
513
+ ### 8. Getting the DeFi vault points earned by an address.
502
514
 
503
- | name | type | description |
504
- | -------------- | -------- | --------------------- |
505
- | `vaultAddress` | `string` | The vault address |
506
- | `chainId` | `string` | The chain ID |
507
- | `rpcUrl` | `string` | Rpc url for the chain |
515
+ ```javascript
516
+ const {
517
+ totalPoints, // The total points earned in the DeFi vault.
518
+ pointsBreakdown // The points breakdown by network (chain).
519
+ } = await getVaultPoints({
520
+ account, // The account address.
521
+ vaultKey // The optional vault identifier.
522
+ })
523
+ ```
508
524
 
509
- Usage
525
+ ### 9. Claiming rewards.
510
526
 
511
- ```typescript
512
- import { getStakeAndBakeFee } from '@lombard.finance/sdk';
527
+ #### 9.1. Checking reward balances.
513
528
 
514
- const response = await getStakeAndBakeFee({
515
- chainId: OChainId.binanceSmartChain,
516
- rpcUrl: 'https://rpc.ankr.com/bsc',
517
- vaultAddress: '0xC8bbF6153D7Ba105f1399D992ebd32B0541996ef',
529
+ ```javascript
530
+ const rewards = await getRewardBalances({
531
+ address,
532
+ rewardToken: RewardToken.BABY
518
533
  });
519
- console.log(response);
520
534
  ```
521
535
 
522
- #### signNetworkFee
536
+ The data returned by the above function contains:
523
537
 
524
- `@returns Promise<ISignNetworkFeeResponse>` A promise that resolves to the signature and typed data
538
+ * `address` - the address of the reward earner (claimer),
539
+ * `availableBalance` - the available balance of the reward token (ready to be withdrawn),
540
+ * `lockedBalance` - the locked balance (in processing),
541
+ * `pendingBalance` - the pending balance to be credited,
542
+ * `rewardToken` - the reward token,
543
+ * `timestamp` - the timestamp.
525
544
 
526
- Signs the network fee transaction in the current account.
527
- Signing is necessary for the auto-mint.
545
+ #### 9.2. Claiming rewards.
528
546
 
529
- ## Parameters
547
+ ```javascript
548
+ const withdrawal = await claimReward({
549
+ account, // The account address.
550
+ rewardToken, // The reward token, e.g. RewardToken.BABY
551
+ amount, // The amount to be claimed (withdrawn)
552
+ to, // The destination address, e.g. BABYLON chain address.
553
+ chainId, // The chain id
554
+ provider, // The EIP-1193 provider.
555
+ });
556
+ ```
530
557
 
531
- | name | type | description |
532
- | ---------- | ----------- | ------------------------------------------------- |
533
- | `address` | `string` | The user address |
534
- | `fee` | `string` | The Authorization fee |
535
- | `expiry` | `number` | Expiration time |
536
- | `chainId` | `string` | The chain ID |
537
- | `env` | `TEnv` | Environment (e.g., 'prod', 'stage', etc.) |
538
- | `provider` | `IProvider` | Provider instance to interact with the blockchain |
558
+ 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.
539
559
 
540
- Usage
560
+ The function returns the `RewardWithdrawal` object.
541
561
 
542
- ```typescript
543
- import { signNetworkFee } from '@lombard.finance/sdk';
544
-
545
- const response = await signNetworkFee({
546
- chainId: OChainId.binanceSmartChain,
547
- address: '0x...',
548
- provider: window.ethereum,
549
- fee: toSatoshi('0.0001'),
550
- expiry: Math.floor(Date.now() / 1000) + NETWORK_FEE_EXPIRATION_TIME_SECONDS,
551
- env: 'prod',
552
- });
553
- console.log(response);
562
+ #### 9.3. Checking the reward withdrawal fee.
563
+
564
+ ```javascript
565
+ const withdrawalFee = await getRewardWithdrawalFee({ address, rewardToken });
554
566
  ```
567
+
568
+ #### 9.4. Getting the withdrawal history (checking withdrawal status).
569
+
570
+ ```javascript
571
+ const withdrawals = await getRewardWithdrawals({ address })
572
+ ```
573
+
574
+ The function returns an array of:
575
+
576
+ * `amount` - the withdrawn (claimed) amount of rewards token,
577
+ * `rewardToken` - the reward token,
578
+ * `fee` - the applied withdrawal fee,
579
+ * `to` - the destination address,
580
+ * `signature` - the signature used,
581
+ * `status` - the withdrawal status,
582
+ * `estimatedTimeSent` - the estimated time when the funds are sent,
583
+ * `timestamp` - the timestamp.