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