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