@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.
- package/README.md +483 -396
- package/dist/ccip.cjs +2 -0
- package/dist/ccip.cjs.map +1 -0
- package/dist/ccip.js +147 -0
- package/dist/ccip.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +79 -8269
- package/dist/index.js.map +1 -1
- package/dist/index2.cjs +63 -0
- package/dist/index2.cjs.map +1 -0
- package/dist/index2.js +17989 -0
- package/dist/index2.js.map +1 -0
- package/package.json +10 -10
- package/src/{sdk → api-functions}/generateDepositBtcAddress/generateDepositBtcAddress.stories.tsx +15 -14
- package/src/{sdk → api-functions}/generateDepositBtcAddress/generateDepositBtcAddress.ts +18 -8
- package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +23 -14
- package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddress.ts +16 -7
- package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddresses.stories.tsx +15 -14
- package/src/{sdk → api-functions}/getDepositsByAddress/getDepositsByAddress.stories.tsx +13 -12
- package/src/{sdk → api-functions}/getDepositsByAddress/getDepositsByAddress.ts +9 -9
- package/src/{sdk → api-functions}/getLBTCExchangeRate/getLBTCExchangeRate.stories.tsx +16 -10
- package/src/api-functions/getLBTCExchangeRate/getLBTCExchangeRate.ts +71 -0
- package/src/api-functions/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +56 -0
- package/src/{sdk → api-functions}/getNetworkFeeSignature/getNetworkFeeSignature.ts +11 -5
- package/src/{sdk → api-functions}/getPointsByAddress/getPointsByAddress.stories.tsx +14 -13
- package/src/{sdk → api-functions}/getPointsByAddress/getPointsByAddress.ts +7 -4
- package/src/{sdk → api-functions}/getUnstakesByAddress/getUnstakesByAddress.stories.tsx +14 -13
- package/src/{sdk → api-functions}/getUnstakesByAddress/getUnstakesByAddress.ts +15 -10
- package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +69 -0
- package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.ts +10 -6
- package/src/{sdk → api-functions}/index.ts +0 -3
- package/src/{sdk → api-functions}/setReferral/setReferral.ts +3 -3
- package/src/api-functions/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +56 -0
- package/src/{sdk → api-functions}/storeNetworkFeeSignature/storeNetworkFeeSignature.ts +9 -7
- package/src/api-functions/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +56 -0
- package/src/{sdk → api-functions}/storeStakeAndBakeSignature/storeStakeAndBakeSignature.ts +8 -6
- package/src/bridge/abi/CCIP_BRIDGE_ADAPTER_ABI.json +704 -0
- package/src/bridge/abi/OFT_BRIDGE_ADAPTER_ABI.json +912 -0
- package/src/bridge/index.ts +11 -0
- package/src/bridge/lib/bridge.stories.tsx +89 -0
- package/src/bridge/lib/bridge.ts +101 -0
- package/src/bridge/lib/ccip-bridge.stories.tsx +90 -0
- package/src/bridge/lib/ccip-bridge.ts +163 -0
- package/src/bridge/lib/config.ts +338 -0
- package/src/bridge/lib/oft-bridge.stories.tsx +89 -0
- package/src/bridge/lib/oft-bridge.ts +212 -0
- package/src/clients/public-client.ts +32 -0
- package/src/clients/rpc-url-config.ts +20 -0
- package/src/clients/wallet-client.ts +33 -0
- package/src/{sdk/apiConfig.ts → common/api-config.ts} +9 -3
- package/src/common/blockchain-identifier.ts +134 -0
- package/src/common/chains.ts +84 -0
- package/src/common/contract-info.ts +8 -0
- package/src/common/parameters.ts +51 -0
- package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +76 -0
- package/src/contract-functions/approveLBTC/approveLBTC.ts +65 -0
- package/src/{web3Sdk → contract-functions}/claimLBTC/claimLBTC.stories.tsx +22 -30
- package/src/contract-functions/claimLBTC/claimLBTC.ts +90 -0
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +50 -0
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +127 -0
- package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +15 -11
- package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +37 -0
- package/src/{vaults/lib/get-vault-points.stories.tsx → contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx} +13 -16
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +34 -0
- package/src/{web3Sdk → contract-functions}/getPermitNonce/getPermitNonce.stories.tsx +12 -22
- package/src/contract-functions/getPermitNonce/getPermitNonce.ts +45 -0
- package/src/{web3Sdk → contract-functions}/getShareValue/getShareValue.stories.tsx +12 -7
- package/src/contract-functions/getShareValue/getShareValue.ts +58 -0
- package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.stories.tsx +14 -9
- package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.ts +29 -28
- package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +29 -16
- package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +65 -0
- package/src/{web3Sdk → contract-functions}/index.ts +8 -7
- package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +32 -0
- package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +63 -0
- package/src/contract-functions/signNetworkFee/signNetworkFee.stories.tsx +91 -0
- package/src/contract-functions/signNetworkFee/signNetworkFee.ts +99 -0
- package/src/contract-functions/signStakeAndBake/index.ts +1 -0
- package/src/{web3Sdk → contract-functions}/signStakeAndBake/signStakeAndBake.stories.tsx +29 -41
- package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +145 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +80 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +66 -0
- package/src/index.ts +40 -17
- package/src/metrics/get-lbtc-stats.stories.tsx +51 -0
- package/src/metrics/get-lbtc-stats.ts +38 -0
- package/src/rewards/index.ts +26 -0
- package/src/rewards/lib/claim-reward.stories.tsx +82 -0
- package/src/rewards/lib/claim-reward.ts +84 -0
- package/src/rewards/lib/get-reward-balances.stories.tsx +64 -0
- package/src/rewards/lib/get-reward-balances.ts +81 -0
- package/src/rewards/lib/get-reward-signing-data.stories.tsx +76 -0
- package/src/rewards/lib/get-reward-signing-data.ts +52 -0
- package/src/rewards/lib/get-reward-withdrawal-fee.stories.tsx +61 -0
- package/src/rewards/lib/get-reward-withdrawal-fee.ts +37 -0
- package/src/rewards/lib/get-reward-withdrawals.stories.tsx +60 -0
- package/src/rewards/lib/get-reward-withdrawals.ts +92 -0
- package/src/rewards/lib/reward-tokens.ts +7 -0
- package/src/stories/components/Button/Button.css +10 -0
- package/src/stories/components/Button/Button.tsx +15 -4
- package/src/stories/components/CodeBlock/CodeBlock.tsx +1 -0
- package/src/stories/components/ConnectButton/connect-button.tsx +100 -0
- package/src/stories/components/ConnectButton/index.ts +1 -0
- package/src/stories/components/decorators/function-type.tsx +63 -0
- package/src/stories/components/decorators/index.ts +2 -0
- package/src/stories/components/decorators/wagmi-decorator.tsx +79 -0
- package/src/stories/components/error-block.tsx +21 -0
- package/src/stories/constants.ts +3 -0
- package/src/stories/hooks/useConnection.ts +72 -0
- package/src/stories/hooks/useQuery.ts +2 -2
- package/src/{web3Sdk/abi/LBTC.json → tokens/abi/LBTC_ABI.json} +1 -1
- package/src/tokens/abi/LBTC_ABI.ts +1761 -0
- package/src/tokens/abi/LBTC_BASCULE_ABI.json +850 -0
- package/src/tokens/lbtc-addresses.ts +55 -0
- package/src/tokens/token-addresses.ts +32 -0
- package/src/tokens/tokens.ts +120 -0
- package/src/utils/env.ts +12 -0
- package/src/utils/hex.ts +2 -2
- package/src/utils/numbers.ts +8 -0
- package/src/{common/utils/convertSatoshi.ts → utils/satoshi.ts} +3 -3
- package/src/utils/time.ts +12 -0
- package/src/vaults/abi/VEDA_VAULT_BASE_ASSET_ABI.json +296 -0
- package/src/vaults/abi/VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI.json +502 -0
- package/src/vaults/abi/VEDA_VAULT_SPENDER_ABI.json +408 -0
- package/src/vaults/abi/VEDA_VAULT_TELLER_ABI.json +700 -0
- package/src/vaults/index.ts +36 -69
- package/src/vaults/lib/config.ts +196 -0
- package/src/vaults/lib/metrics/get-vault-apy.stories.tsx +57 -0
- package/src/vaults/lib/metrics/get-vault-apy.ts +132 -0
- package/src/vaults/lib/metrics/get-vault-points.stories.tsx +59 -0
- package/src/vaults/lib/{get-vault-points.ts → metrics/get-vault-points.ts} +14 -10
- package/src/vaults/lib/metrics/get-vault-tvl.stories.tsx +57 -0
- package/src/vaults/lib/metrics/get-vault-tvl.ts +119 -0
- package/src/vaults/lib/ops/cancel-withdraw.stories.tsx +79 -0
- package/src/vaults/lib/ops/deposit.stories.tsx +81 -0
- package/src/vaults/lib/ops/deposit.ts +151 -0
- package/src/vaults/lib/{get-vault-deposits.stories.tsx → ops/get-vault-deposits.stories.tsx} +20 -14
- package/src/vaults/lib/{get-vault-deposits.ts → ops/get-vault-deposits.ts} +45 -22
- package/src/vaults/lib/{get-vault-withdrawals.stories.tsx → ops/get-vault-withdrawals.stories.tsx} +20 -13
- package/src/vaults/lib/{get-vault-withdrawals.ts → ops/get-vault-withdrawals.ts} +72 -38
- package/src/vaults/lib/ops/withdraw.stories.tsx +81 -0
- package/src/vaults/lib/ops/withdraw.ts +224 -0
- package/src/common/const.ts +0 -5
- package/src/common/types/internalTypes.ts +0 -10
- package/src/common/types/types.ts +0 -57
- package/src/common/utils/isValidChain.ts +0 -5
- package/src/provider/Provider.ts +0 -171
- package/src/provider/ReadProvider.ts +0 -126
- package/src/provider/index.ts +0 -2
- package/src/provider/rpcUrlConfig.ts +0 -19
- package/src/provider/types.ts +0 -58
- package/src/provider/utils/getMaxPriorityFeePerGas.ts +0 -25
- package/src/sdk/getLBTCExchangeRate/getLBTCExchangeRate.ts +0 -65
- package/src/sdk/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +0 -85
- package/src/sdk/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +0 -86
- package/src/sdk/internalTypes.ts +0 -18
- package/src/sdk/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +0 -86
- package/src/sdk/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +0 -116
- package/src/sdk/utils/getChainIdByName.ts +0 -48
- package/src/sdk/utils/getChainNameById.ts +0 -41
- package/src/stories/const.ts +0 -1
- package/src/stories/hooks/useConnect.ts +0 -47
- package/src/stories/utils/connectInjectedWallet.ts +0 -12
- package/src/stories/utils/fromCamelCase.ts +0 -16
- package/src/stories/utils/getMetaTitle.ts +0 -7
- package/src/stories/utils/getWalletInfo.ts +0 -31
- package/src/web3Sdk/abi/BASCULE.json +0 -850
- package/src/web3Sdk/abi/IERC20.json +0 -222
- package/src/web3Sdk/abi/STAKE_AND_BAKE.json +0 -15
- package/src/web3Sdk/abi/index.ts +0 -6
- package/src/web3Sdk/approveLBTC/approveLBTC.stories.tsx +0 -77
- package/src/web3Sdk/approveLBTC/approveLBTC.ts +0 -48
- package/src/web3Sdk/claimLBTC/claimLBTC.ts +0 -86
- package/src/web3Sdk/const.ts +0 -2
- package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +0 -89
- package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.ts +0 -75
- package/src/web3Sdk/getBasculeDepositStatus/utils/const.ts +0 -8
- package/src/web3Sdk/getBasculeDepositStatus/utils/throwBasculeDepositStatusError.ts +0 -21
- package/src/web3Sdk/getLBTCMintingFee/getLBTCMintingFee.tsx +0 -41
- package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +0 -60
- package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.ts +0 -26
- package/src/web3Sdk/getPermitNonce/getPermitNonce.ts +0 -47
- package/src/web3Sdk/getShareValue/getShareValue.ts +0 -58
- package/src/web3Sdk/getStakeAndBakeFee/getStakeAndBakeFee.tsx +0 -48
- package/src/web3Sdk/lbtcAddressConfig.ts +0 -96
- package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +0 -23
- package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +0 -97
- package/src/web3Sdk/signNetworkFee/signNetworkFee.stories.tsx +0 -91
- package/src/web3Sdk/signNetworkFee/signNetworkFee.ts +0 -92
- package/src/web3Sdk/signStakeAndBake/contracts.ts +0 -80
- package/src/web3Sdk/signStakeAndBake/getTypedData.ts +0 -78
- package/src/web3Sdk/signStakeAndBake/index.ts +0 -3
- package/src/web3Sdk/signStakeAndBake/signStakeAndBake.ts +0 -105
- package/src/web3Sdk/signStakeAndBake/utils.ts +0 -23
- package/src/web3Sdk/types.ts +0 -16
- package/src/web3Sdk/unstakeLBTC/unstakeLBTC.stories.tsx +0 -77
- package/src/web3Sdk/unstakeLBTC/unstakeLBTC.ts +0 -51
- package/src/web3Sdk/utils/chainIdToEnv.ts +0 -12
- package/src/web3Sdk/utils/getBasculeTokenContract.ts +0 -21
- package/src/web3Sdk/utils/getGasMultiplier.ts +0 -20
- package/src/web3Sdk/utils/getLbtcTokenContract.ts +0 -36
- package/src/web3Sdk/utils/getRpcUrlConfigFromChain.ts +0 -34
- package/src/web3Sdk/utils/getTokenABI.ts +0 -12
- /package/src/{sdk → api-functions}/generateDepositBtcAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getDepositBtcAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getDepositsByAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getLBTCExchangeRate/index.ts +0 -0
- /package/src/{sdk → api-functions}/getNetworkFeeSignature/index.ts +0 -0
- /package/src/{sdk → api-functions}/getPointsByAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getUnstakesByAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/index.ts +0 -0
- /package/src/{sdk → api-functions}/setReferral/index.ts +0 -0
- /package/src/{sdk → api-functions}/storeNetworkFeeSignature/index.ts +0 -0
- /package/src/{sdk → api-functions}/storeStakeAndBakeSignature/index.ts +0 -0
- /package/src/{sdk/const.ts → common/constants.ts} +0 -0
- /package/src/{web3Sdk → contract-functions}/approveLBTC/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/claimLBTC/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getBasculeDepositStatus/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getLBTCTotalSupply/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getPermitNonce/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getShareValue/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getSharesByAddress/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/signLbtcDestionationAddr/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/signNetworkFee/getTypedData.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/signNetworkFee/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/unstakeLBTC/index.ts +0 -0
- /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
|
|
3
|
+
The Lombard's SDK package provides a set of functions that allow interacting with the Lombard protocol and its features.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Read more about Lombard's mission: https://www.lombard.finance
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
# Table of Contents
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
[Installation](#installation)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
npm i @lombard.finance/sdk
|
|
13
|
-
```
|
|
11
|
+
1. [Dependencies installation](#1-dependencies-installation)
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
2. [SDK installation](#2-sdk-installation)
|
|
16
14
|
|
|
17
|
-
|
|
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
|
-
|
|
17
|
+
1. [Depositing BTC in order to get LBTC (aka staking)](#1-depositing-btc-in-order-to-get-lbtc-aka-staking)
|
|
22
18
|
|
|
23
|
-
|
|
19
|
+
1.1. [Get the current minting fee](#11-get-the-current-minting-fee)
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
1.2. [Sign the network fee signature](#12-sign-the-network-fee-signature)
|
|
26
22
|
|
|
27
|
-
|
|
23
|
+
1.3. [Store the signature to the Lombard's systems](#13-store-the-signature-to-the-lombards-systems)
|
|
28
24
|
|
|
29
|
-
|
|
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
|
-
|
|
27
|
+
1.5. [Deposit BTC to the address](#15-deposit-btc-to-the-address)
|
|
34
28
|
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
35
|
+
3.1. [See what's the current stake and bake fee](#31-see-whats-the-current-stake-and-bake-fee)
|
|
90
36
|
|
|
91
|
-
|
|
37
|
+
3.2. [Sign the stake and bake signature](#32-sign-the-stake-and-bake-signature)
|
|
92
38
|
|
|
93
|
-
|
|
39
|
+
3.3. [Store the signature to the Lombard's systems](#33-store-the-signature-to-the-lombards-systems)
|
|
94
40
|
|
|
95
|
-
|
|
41
|
+
3.4. [Get or generate the BTC deposit address](#34-get-or-generate-the-btc-deposit-address)
|
|
96
42
|
|
|
97
|
-
|
|
43
|
+
3.5. [Deposit BTC to the address](#35-deposit-btc-to-the-address)
|
|
98
44
|
|
|
99
|
-
|
|
45
|
+
3.6. [Check the status of your deposit](#36-check-the-status-of-your-deposit)
|
|
100
46
|
|
|
101
|
-
|
|
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
|
-
|
|
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
|
-
|
|
51
|
+
4.1. [Unstake LBTC](#41-unstake-lbtc)
|
|
116
52
|
|
|
117
|
-
|
|
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
|
-
|
|
55
|
+
5. [Depositing LBTC to the DeFi vault](#5-depositing-lbtc-to-the-defi-vault)
|
|
130
56
|
|
|
131
|
-
|
|
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
|
-
|
|
59
|
+
5.2. [Checking the deposit history](#52-checking-the-deposit-history)
|
|
135
60
|
|
|
136
|
-
|
|
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
|
-
|
|
63
|
+
6. [Withdrawing LBTC from the DeFi vault](#6-withdrawing-lbtc-from-the-defi-vault)
|
|
142
64
|
|
|
143
|
-
|
|
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
|
-
|
|
67
|
+
6.2. [Checking the withdrawal history (tracking the withdrawal request)](#62-checking-the-withdrawal-history-tracking-the-withdrawal-request)
|
|
152
68
|
|
|
153
|
-
|
|
69
|
+
6.3. [Cancelling the withdrawal](#63-cancelling-the-withdrawal)
|
|
154
70
|
|
|
155
|
-
|
|
71
|
+
7. [Getting the points earned by an address](#7-getting-the-points-earned-by-an-address)
|
|
156
72
|
|
|
157
|
-
|
|
73
|
+
8. [Getting the DeFi vault points earned by an address](#8-getting-the-defi-vault-points-earned-by-an-address)
|
|
158
74
|
|
|
159
|
-
|
|
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
|
-
|
|
77
|
+
9.1. [Checking reward balances](#91-checking-reward-balances)
|
|
166
78
|
|
|
167
|
-
|
|
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
|
-
|
|
81
|
+
9.3. [Checking the reward withdrawal fee](#93-checking-the-reward-withdrawal-fee)
|
|
177
82
|
|
|
178
|
-
|
|
83
|
+
9.4. [Getting the withdrawal history (checking withdrawal status)](#94-getting-the-withdrawal-history-checking-withdrawal-status)
|
|
179
84
|
|
|
180
|
-
|
|
181
|
-
Signing is necessary for the generation of the deposit address.
|
|
85
|
+
10. [Metrics](#10-metrics)
|
|
182
86
|
|
|
183
|
-
|
|
87
|
+
10.1. [Getting the vault's TVL](#101-getting-the-vaults-tvl)
|
|
184
88
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
97
|
+
### 1. Dependencies installation
|
|
207
98
|
|
|
208
|
-
|
|
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
|
-
|
|
107
|
+
You may install them by running the following command:
|
|
211
108
|
|
|
212
|
-
|
|
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
|
-
|
|
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
|
-
|
|
115
|
+
To install the SDK package, please run:
|
|
224
116
|
|
|
225
|
-
```
|
|
226
|
-
|
|
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
|
-
|
|
121
|
+
## Usage
|
|
242
122
|
|
|
243
|
-
|
|
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
|
-
|
|
125
|
+
### 1. Depositing BTC in order to get LBTC (aka staking).
|
|
246
126
|
|
|
247
|
-
|
|
127
|
+
You can read more about LBTC here: https://docs.lombard.finance/lbtc-liquid-bitcoin/introduction-to-lbtc
|
|
248
128
|
|
|
249
|
-
|
|
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
|
-
|
|
131
|
+
#### 1.1 Get the current minting fee.
|
|
259
132
|
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
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
|
-
####
|
|
150
|
+
#### 1.3. Store the signature to the Lombard's systems.
|
|
277
151
|
|
|
278
|
-
|
|
152
|
+
```javascript
|
|
153
|
+
await storeNetworkFeeSignature({ signature, typedData, address }); // Pass the signature and typed data from step 2.
|
|
154
|
+
```
|
|
279
155
|
|
|
280
|
-
|
|
156
|
+
It is recommended to verify that the signature has been stored. Please use `getNetworkFeeSignature`.
|
|
281
157
|
|
|
282
|
-
|
|
158
|
+
```javascript
|
|
159
|
+
const { expirationData, hasSignature, isDelayed } = await getNetworkFeeSignature({ address, chainId });
|
|
160
|
+
```
|
|
283
161
|
|
|
284
|
-
|
|
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
|
-
|
|
164
|
+
#### 1.4. Get or generate the BTC deposit address.
|
|
293
165
|
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
-
####
|
|
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
|
-
|
|
184
|
+
#### 1.6. Check the status of your deposit.
|
|
310
185
|
|
|
311
|
-
|
|
186
|
+
If you'd like to check the status of your deposit use `getDepositsByAddress` function.
|
|
312
187
|
|
|
313
|
-
|
|
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
|
-
|
|
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
|
-
|
|
227
|
+
### 3. Depositing BTC and automatically staking LBTC into the DeFi vault (aka stake and bake)
|
|
322
228
|
|
|
323
|
-
|
|
324
|
-
|
|
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
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
243
|
+
const expectedLBTCAmount = BigNumber(amountToBeDeposited).minus(fee);
|
|
331
244
|
```
|
|
245
|
+
The fee amount will be deducted from the claimed LBTC automatically.
|
|
332
246
|
|
|
333
|
-
####
|
|
247
|
+
#### 3.2. Sign the stake and bake signature.
|
|
334
248
|
|
|
335
|
-
|
|
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
|
-
|
|
261
|
+
#### 3.3. Store the signature to the Lombard's systems.
|
|
338
262
|
|
|
339
|
-
|
|
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
|
-
|
|
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
|
-
|
|
272
|
+
```javascript
|
|
273
|
+
const data = await getUserStakeAndBakeSignature({
|
|
274
|
+
userDestinationAddress: address,
|
|
275
|
+
chainId,
|
|
276
|
+
})
|
|
277
|
+
```
|
|
352
278
|
|
|
353
|
-
|
|
354
|
-
import { signStakeAndBake } from '@lombard.finance/sdk';
|
|
279
|
+
#### 3.4. Get or generate the BTC deposit address.
|
|
355
280
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
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
|
-
####
|
|
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
|
-
|
|
297
|
+
#### 3.6. Check the status of you deposit
|
|
369
298
|
|
|
370
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
321
|
+
Every LBTC is redeemable back to BTC, you can do that programmatically by following the steps:
|
|
381
322
|
|
|
382
|
-
|
|
383
|
-
import { storeStakeAndBakeSignature } from '@lombard.finance/sdk';
|
|
323
|
+
#### 4.1. Unstake LBTC.
|
|
384
324
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
-
####
|
|
336
|
+
#### 4.2. Check the status of your unstakes.
|
|
393
337
|
|
|
394
|
-
|
|
338
|
+
If you'd like to get the list of all unstaked made by an address, use this:
|
|
395
339
|
|
|
396
|
-
|
|
340
|
+
```javascript
|
|
341
|
+
const unstakes = await getUnstakesByAddress({ address });
|
|
342
|
+
```
|
|
397
343
|
|
|
398
|
-
|
|
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
|
-
|
|
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
|
-
|
|
358
|
+
If a user already has LBTC depositing to the DeFi vault can be done via the `deposit` function.
|
|
407
359
|
|
|
408
|
-
|
|
409
|
-
import { getUserStakeAndBakeSignature } from '@lombard.finance/sdk';
|
|
360
|
+
#### 5.1. Making a deposit to the DeFi vault.
|
|
410
361
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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
|
-
|
|
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
|
-
|
|
394
|
+
#### 5.3. Checking the user's DeFi vault balance.
|
|
422
395
|
|
|
423
|
-
|
|
396
|
+
In order to check the user's balance of the vault tokens, use this:
|
|
424
397
|
|
|
425
|
-
|
|
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
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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
|
-
|
|
412
|
+
### 6. Withdrawing LBTC from the DeFi vault.
|
|
435
413
|
|
|
436
|
-
|
|
437
|
-
import { storeNetworkFeeSignature } from '@lombard.finance/sdk';
|
|
414
|
+
#### 6.1. Requesting a withdrawal from the DeFi vault
|
|
438
415
|
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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
|
-
####
|
|
430
|
+
#### 6.2. Checking the withdrawal history (tracking the withdrawal request)
|
|
449
431
|
|
|
450
|
-
|
|
432
|
+
In order to check the whole history or to track the particular withdrawal please use the following function:
|
|
451
433
|
|
|
452
|
-
|
|
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
|
-
|
|
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
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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
|
-
|
|
466
|
+
#### 6.3. Cancelling the withdrawal
|
|
463
467
|
|
|
464
|
-
|
|
465
|
-
import { getNetworkFeeSignature } from '@lombard.finance/sdk';
|
|
468
|
+
If you wish to cancel you open withdrawal request use this:
|
|
466
469
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
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
|
-
|
|
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
|
-
|
|
485
|
+
```javascript
|
|
486
|
+
const points = await getPointsByAddress({ address: "0x...YOUR_ADDRESS" })
|
|
487
|
+
```
|
|
478
488
|
|
|
479
|
-
|
|
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
|
-
|
|
482
|
-
| --------- | -------- | ------------ |
|
|
483
|
-
| `chainId` | `string` | The chain ID |
|
|
523
|
+
### 8. Getting the DeFi vault points earned by an address.
|
|
484
524
|
|
|
485
|
-
|
|
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
|
-
|
|
488
|
-
import { getStakeAndBakeVaults } from '@lombard.finance/sdk';
|
|
535
|
+
### 9. Claiming rewards.
|
|
489
536
|
|
|
490
|
-
|
|
537
|
+
#### 9.1. Checking reward balances.
|
|
491
538
|
|
|
492
|
-
|
|
539
|
+
```javascript
|
|
540
|
+
const rewards = await getRewardBalances({
|
|
541
|
+
address,
|
|
542
|
+
rewardToken: RewardToken.BABY
|
|
543
|
+
});
|
|
493
544
|
```
|
|
494
545
|
|
|
495
|
-
|
|
546
|
+
The data returned by the above function contains:
|
|
496
547
|
|
|
497
|
-
|
|
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
|
-
|
|
555
|
+
#### 9.2. Claiming rewards.
|
|
500
556
|
|
|
501
|
-
|
|
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
|
-
|
|
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
|
-
|
|
570
|
+
The function returns the `RewardWithdrawal` object.
|
|
510
571
|
|
|
511
|
-
|
|
512
|
-
import { getStakeAndBakeFee } from '@lombard.finance/sdk';
|
|
572
|
+
#### 9.3. Checking the reward withdrawal fee.
|
|
513
573
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
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
|
-
|
|
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
|
-
|
|
595
|
+
### 10. Metrics
|
|
525
596
|
|
|
526
|
-
|
|
527
|
-
Signing is necessary for the auto-mint.
|
|
597
|
+
#### 10.1. Getting the vault's TVL
|
|
528
598
|
|
|
529
|
-
|
|
599
|
+
The vault's TVL can be obtained by calling the `getVaultTVL` function.
|
|
530
600
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
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
|
-
|
|
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
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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.
|