@lombard.finance/sdk 2.5.2 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/README.md +483 -396
  2. package/dist/ccip.cjs +2 -0
  3. package/dist/ccip.cjs.map +1 -0
  4. package/dist/ccip.js +147 -0
  5. package/dist/ccip.js.map +1 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.js +79 -8269
  9. package/dist/index.js.map +1 -1
  10. package/dist/index2.cjs +63 -0
  11. package/dist/index2.cjs.map +1 -0
  12. package/dist/index2.js +17989 -0
  13. package/dist/index2.js.map +1 -0
  14. package/package.json +10 -10
  15. package/src/{sdk → api-functions}/generateDepositBtcAddress/generateDepositBtcAddress.stories.tsx +15 -14
  16. package/src/{sdk → api-functions}/generateDepositBtcAddress/generateDepositBtcAddress.ts +18 -8
  17. package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +23 -14
  18. package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddress.ts +16 -7
  19. package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddresses.stories.tsx +15 -14
  20. package/src/{sdk → api-functions}/getDepositsByAddress/getDepositsByAddress.stories.tsx +13 -12
  21. package/src/{sdk → api-functions}/getDepositsByAddress/getDepositsByAddress.ts +9 -9
  22. package/src/{sdk → api-functions}/getLBTCExchangeRate/getLBTCExchangeRate.stories.tsx +16 -10
  23. package/src/api-functions/getLBTCExchangeRate/getLBTCExchangeRate.ts +71 -0
  24. package/src/api-functions/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +56 -0
  25. package/src/{sdk → api-functions}/getNetworkFeeSignature/getNetworkFeeSignature.ts +11 -5
  26. package/src/{sdk → api-functions}/getPointsByAddress/getPointsByAddress.stories.tsx +14 -13
  27. package/src/{sdk → api-functions}/getPointsByAddress/getPointsByAddress.ts +7 -4
  28. package/src/{sdk → api-functions}/getUnstakesByAddress/getUnstakesByAddress.stories.tsx +14 -13
  29. package/src/{sdk → api-functions}/getUnstakesByAddress/getUnstakesByAddress.ts +15 -10
  30. package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +69 -0
  31. package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.ts +10 -6
  32. package/src/{sdk → api-functions}/index.ts +0 -3
  33. package/src/{sdk → api-functions}/setReferral/setReferral.ts +3 -3
  34. package/src/api-functions/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +56 -0
  35. package/src/{sdk → api-functions}/storeNetworkFeeSignature/storeNetworkFeeSignature.ts +9 -7
  36. package/src/api-functions/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +56 -0
  37. package/src/{sdk → api-functions}/storeStakeAndBakeSignature/storeStakeAndBakeSignature.ts +8 -6
  38. package/src/bridge/abi/CCIP_BRIDGE_ADAPTER_ABI.json +704 -0
  39. package/src/bridge/abi/OFT_BRIDGE_ADAPTER_ABI.json +912 -0
  40. package/src/bridge/index.ts +11 -0
  41. package/src/bridge/lib/bridge.stories.tsx +89 -0
  42. package/src/bridge/lib/bridge.ts +101 -0
  43. package/src/bridge/lib/ccip-bridge.stories.tsx +90 -0
  44. package/src/bridge/lib/ccip-bridge.ts +163 -0
  45. package/src/bridge/lib/config.ts +338 -0
  46. package/src/bridge/lib/oft-bridge.stories.tsx +89 -0
  47. package/src/bridge/lib/oft-bridge.ts +212 -0
  48. package/src/clients/public-client.ts +32 -0
  49. package/src/clients/rpc-url-config.ts +20 -0
  50. package/src/clients/wallet-client.ts +33 -0
  51. package/src/{sdk/apiConfig.ts → common/api-config.ts} +9 -3
  52. package/src/common/blockchain-identifier.ts +134 -0
  53. package/src/common/chains.ts +84 -0
  54. package/src/common/contract-info.ts +8 -0
  55. package/src/common/parameters.ts +51 -0
  56. package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +76 -0
  57. package/src/contract-functions/approveLBTC/approveLBTC.ts +65 -0
  58. package/src/{web3Sdk → contract-functions}/claimLBTC/claimLBTC.stories.tsx +22 -30
  59. package/src/contract-functions/claimLBTC/claimLBTC.ts +90 -0
  60. package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +50 -0
  61. package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +127 -0
  62. package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +15 -11
  63. package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +37 -0
  64. package/src/{vaults/lib/get-vault-points.stories.tsx → contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx} +13 -16
  65. package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +34 -0
  66. package/src/{web3Sdk → contract-functions}/getPermitNonce/getPermitNonce.stories.tsx +12 -22
  67. package/src/contract-functions/getPermitNonce/getPermitNonce.ts +45 -0
  68. package/src/{web3Sdk → contract-functions}/getShareValue/getShareValue.stories.tsx +12 -7
  69. package/src/contract-functions/getShareValue/getShareValue.ts +58 -0
  70. package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.stories.tsx +14 -9
  71. package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.ts +29 -28
  72. package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +29 -16
  73. package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +65 -0
  74. package/src/{web3Sdk → contract-functions}/index.ts +8 -7
  75. package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +32 -0
  76. package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +63 -0
  77. package/src/contract-functions/signNetworkFee/signNetworkFee.stories.tsx +91 -0
  78. package/src/contract-functions/signNetworkFee/signNetworkFee.ts +99 -0
  79. package/src/contract-functions/signStakeAndBake/index.ts +1 -0
  80. package/src/{web3Sdk → contract-functions}/signStakeAndBake/signStakeAndBake.stories.tsx +29 -41
  81. package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +145 -0
  82. package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +80 -0
  83. package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +66 -0
  84. package/src/index.ts +40 -17
  85. package/src/metrics/get-lbtc-stats.stories.tsx +51 -0
  86. package/src/metrics/get-lbtc-stats.ts +38 -0
  87. package/src/rewards/index.ts +26 -0
  88. package/src/rewards/lib/claim-reward.stories.tsx +82 -0
  89. package/src/rewards/lib/claim-reward.ts +84 -0
  90. package/src/rewards/lib/get-reward-balances.stories.tsx +64 -0
  91. package/src/rewards/lib/get-reward-balances.ts +81 -0
  92. package/src/rewards/lib/get-reward-signing-data.stories.tsx +76 -0
  93. package/src/rewards/lib/get-reward-signing-data.ts +52 -0
  94. package/src/rewards/lib/get-reward-withdrawal-fee.stories.tsx +61 -0
  95. package/src/rewards/lib/get-reward-withdrawal-fee.ts +37 -0
  96. package/src/rewards/lib/get-reward-withdrawals.stories.tsx +60 -0
  97. package/src/rewards/lib/get-reward-withdrawals.ts +92 -0
  98. package/src/rewards/lib/reward-tokens.ts +7 -0
  99. package/src/stories/components/Button/Button.css +10 -0
  100. package/src/stories/components/Button/Button.tsx +15 -4
  101. package/src/stories/components/CodeBlock/CodeBlock.tsx +1 -0
  102. package/src/stories/components/ConnectButton/connect-button.tsx +100 -0
  103. package/src/stories/components/ConnectButton/index.ts +1 -0
  104. package/src/stories/components/decorators/function-type.tsx +63 -0
  105. package/src/stories/components/decorators/index.ts +2 -0
  106. package/src/stories/components/decorators/wagmi-decorator.tsx +79 -0
  107. package/src/stories/components/error-block.tsx +21 -0
  108. package/src/stories/constants.ts +3 -0
  109. package/src/stories/hooks/useConnection.ts +72 -0
  110. package/src/stories/hooks/useQuery.ts +2 -2
  111. package/src/{web3Sdk/abi/LBTC.json → tokens/abi/LBTC_ABI.json} +1 -1
  112. package/src/tokens/abi/LBTC_ABI.ts +1761 -0
  113. package/src/tokens/abi/LBTC_BASCULE_ABI.json +850 -0
  114. package/src/tokens/lbtc-addresses.ts +55 -0
  115. package/src/tokens/token-addresses.ts +32 -0
  116. package/src/tokens/tokens.ts +120 -0
  117. package/src/utils/env.ts +12 -0
  118. package/src/utils/hex.ts +2 -2
  119. package/src/utils/numbers.ts +8 -0
  120. package/src/{common/utils/convertSatoshi.ts → utils/satoshi.ts} +3 -3
  121. package/src/utils/time.ts +12 -0
  122. package/src/vaults/abi/VEDA_VAULT_BASE_ASSET_ABI.json +296 -0
  123. package/src/vaults/abi/VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI.json +502 -0
  124. package/src/vaults/abi/VEDA_VAULT_SPENDER_ABI.json +408 -0
  125. package/src/vaults/abi/VEDA_VAULT_TELLER_ABI.json +700 -0
  126. package/src/vaults/index.ts +36 -69
  127. package/src/vaults/lib/config.ts +196 -0
  128. package/src/vaults/lib/metrics/get-vault-apy.stories.tsx +57 -0
  129. package/src/vaults/lib/metrics/get-vault-apy.ts +132 -0
  130. package/src/vaults/lib/metrics/get-vault-points.stories.tsx +59 -0
  131. package/src/vaults/lib/{get-vault-points.ts → metrics/get-vault-points.ts} +14 -10
  132. package/src/vaults/lib/metrics/get-vault-tvl.stories.tsx +57 -0
  133. package/src/vaults/lib/metrics/get-vault-tvl.ts +119 -0
  134. package/src/vaults/lib/ops/cancel-withdraw.stories.tsx +79 -0
  135. package/src/vaults/lib/ops/deposit.stories.tsx +81 -0
  136. package/src/vaults/lib/ops/deposit.ts +151 -0
  137. package/src/vaults/lib/{get-vault-deposits.stories.tsx → ops/get-vault-deposits.stories.tsx} +20 -14
  138. package/src/vaults/lib/{get-vault-deposits.ts → ops/get-vault-deposits.ts} +45 -22
  139. package/src/vaults/lib/{get-vault-withdrawals.stories.tsx → ops/get-vault-withdrawals.stories.tsx} +20 -13
  140. package/src/vaults/lib/{get-vault-withdrawals.ts → ops/get-vault-withdrawals.ts} +72 -38
  141. package/src/vaults/lib/ops/withdraw.stories.tsx +81 -0
  142. package/src/vaults/lib/ops/withdraw.ts +224 -0
  143. package/src/common/const.ts +0 -5
  144. package/src/common/types/internalTypes.ts +0 -10
  145. package/src/common/types/types.ts +0 -57
  146. package/src/common/utils/isValidChain.ts +0 -5
  147. package/src/provider/Provider.ts +0 -171
  148. package/src/provider/ReadProvider.ts +0 -126
  149. package/src/provider/index.ts +0 -2
  150. package/src/provider/rpcUrlConfig.ts +0 -19
  151. package/src/provider/types.ts +0 -58
  152. package/src/provider/utils/getMaxPriorityFeePerGas.ts +0 -25
  153. package/src/sdk/getLBTCExchangeRate/getLBTCExchangeRate.ts +0 -65
  154. package/src/sdk/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +0 -85
  155. package/src/sdk/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +0 -86
  156. package/src/sdk/internalTypes.ts +0 -18
  157. package/src/sdk/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +0 -86
  158. package/src/sdk/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +0 -116
  159. package/src/sdk/utils/getChainIdByName.ts +0 -48
  160. package/src/sdk/utils/getChainNameById.ts +0 -41
  161. package/src/stories/const.ts +0 -1
  162. package/src/stories/hooks/useConnect.ts +0 -47
  163. package/src/stories/utils/connectInjectedWallet.ts +0 -12
  164. package/src/stories/utils/fromCamelCase.ts +0 -16
  165. package/src/stories/utils/getMetaTitle.ts +0 -7
  166. package/src/stories/utils/getWalletInfo.ts +0 -31
  167. package/src/web3Sdk/abi/BASCULE.json +0 -850
  168. package/src/web3Sdk/abi/IERC20.json +0 -222
  169. package/src/web3Sdk/abi/STAKE_AND_BAKE.json +0 -15
  170. package/src/web3Sdk/abi/index.ts +0 -6
  171. package/src/web3Sdk/approveLBTC/approveLBTC.stories.tsx +0 -77
  172. package/src/web3Sdk/approveLBTC/approveLBTC.ts +0 -48
  173. package/src/web3Sdk/claimLBTC/claimLBTC.ts +0 -86
  174. package/src/web3Sdk/const.ts +0 -2
  175. package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +0 -89
  176. package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.ts +0 -75
  177. package/src/web3Sdk/getBasculeDepositStatus/utils/const.ts +0 -8
  178. package/src/web3Sdk/getBasculeDepositStatus/utils/throwBasculeDepositStatusError.ts +0 -21
  179. package/src/web3Sdk/getLBTCMintingFee/getLBTCMintingFee.tsx +0 -41
  180. package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +0 -60
  181. package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.ts +0 -26
  182. package/src/web3Sdk/getPermitNonce/getPermitNonce.ts +0 -47
  183. package/src/web3Sdk/getShareValue/getShareValue.ts +0 -58
  184. package/src/web3Sdk/getStakeAndBakeFee/getStakeAndBakeFee.tsx +0 -48
  185. package/src/web3Sdk/lbtcAddressConfig.ts +0 -96
  186. package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +0 -23
  187. package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +0 -97
  188. package/src/web3Sdk/signNetworkFee/signNetworkFee.stories.tsx +0 -91
  189. package/src/web3Sdk/signNetworkFee/signNetworkFee.ts +0 -92
  190. package/src/web3Sdk/signStakeAndBake/contracts.ts +0 -80
  191. package/src/web3Sdk/signStakeAndBake/getTypedData.ts +0 -78
  192. package/src/web3Sdk/signStakeAndBake/index.ts +0 -3
  193. package/src/web3Sdk/signStakeAndBake/signStakeAndBake.ts +0 -105
  194. package/src/web3Sdk/signStakeAndBake/utils.ts +0 -23
  195. package/src/web3Sdk/types.ts +0 -16
  196. package/src/web3Sdk/unstakeLBTC/unstakeLBTC.stories.tsx +0 -77
  197. package/src/web3Sdk/unstakeLBTC/unstakeLBTC.ts +0 -51
  198. package/src/web3Sdk/utils/chainIdToEnv.ts +0 -12
  199. package/src/web3Sdk/utils/getBasculeTokenContract.ts +0 -21
  200. package/src/web3Sdk/utils/getGasMultiplier.ts +0 -20
  201. package/src/web3Sdk/utils/getLbtcTokenContract.ts +0 -36
  202. package/src/web3Sdk/utils/getRpcUrlConfigFromChain.ts +0 -34
  203. package/src/web3Sdk/utils/getTokenABI.ts +0 -12
  204. /package/src/{sdk → api-functions}/generateDepositBtcAddress/index.ts +0 -0
  205. /package/src/{sdk → api-functions}/getDepositBtcAddress/index.ts +0 -0
  206. /package/src/{sdk → api-functions}/getDepositsByAddress/index.ts +0 -0
  207. /package/src/{sdk → api-functions}/getLBTCExchangeRate/index.ts +0 -0
  208. /package/src/{sdk → api-functions}/getNetworkFeeSignature/index.ts +0 -0
  209. /package/src/{sdk → api-functions}/getPointsByAddress/index.ts +0 -0
  210. /package/src/{sdk → api-functions}/getUnstakesByAddress/index.ts +0 -0
  211. /package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/index.ts +0 -0
  212. /package/src/{sdk → api-functions}/setReferral/index.ts +0 -0
  213. /package/src/{sdk → api-functions}/storeNetworkFeeSignature/index.ts +0 -0
  214. /package/src/{sdk → api-functions}/storeStakeAndBakeSignature/index.ts +0 -0
  215. /package/src/{sdk/const.ts → common/constants.ts} +0 -0
  216. /package/src/{web3Sdk → contract-functions}/approveLBTC/index.ts +0 -0
  217. /package/src/{web3Sdk → contract-functions}/claimLBTC/index.ts +0 -0
  218. /package/src/{web3Sdk → contract-functions}/getBasculeDepositStatus/index.ts +0 -0
  219. /package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/index.ts +0 -0
  220. /package/src/{web3Sdk → contract-functions}/getLBTCTotalSupply/index.ts +0 -0
  221. /package/src/{web3Sdk → contract-functions}/getPermitNonce/index.ts +0 -0
  222. /package/src/{web3Sdk → contract-functions}/getShareValue/index.ts +0 -0
  223. /package/src/{web3Sdk → contract-functions}/getSharesByAddress/index.ts +0 -0
  224. /package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/index.ts +0 -0
  225. /package/src/{web3Sdk → contract-functions}/signLbtcDestionationAddr/index.ts +0 -0
  226. /package/src/{web3Sdk → contract-functions}/signNetworkFee/getTypedData.ts +0 -0
  227. /package/src/{web3Sdk → contract-functions}/signNetworkFee/index.ts +0 -0
  228. /package/src/{web3Sdk → contract-functions}/unstakeLBTC/index.ts +0 -0
  229. /package/src/{common/utils/getErrorMessage.ts → utils/err.ts} +0 -0
@@ -0,0 +1,50 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { Button } from '../../stories/components/Button';
3
+ import { CodeBlock } from '../../stories/components/CodeBlock';
4
+ import useQuery from '../../stories/hooks/useQuery';
5
+ import {
6
+ getBasculeDepositStatus,
7
+ IGetBasculeDepositStatusParameters,
8
+ } from './getBasculeDepositStatus';
9
+ import { ChainId } from '../../common/chains';
10
+ import { functionType } from '../../stories/components/decorators';
11
+
12
+ const meta = {
13
+ title: 'read/getBasculeDepositStatus',
14
+ component: StoryView,
15
+ tags: ['autodocs'],
16
+ decorators: [functionType('read')],
17
+ } satisfies Meta<typeof StoryView>;
18
+
19
+ export default meta;
20
+
21
+ type Story = StoryObj<typeof meta>;
22
+
23
+ export const WithParams: Story = {
24
+ args: {
25
+ rawPayload:
26
+ 'f2e73f7c00000000000000000000000000000000000000000000000000000000000000010000000000000000000000004f3128be175467a35ec1f430264cbc36ab272f83000000000000000000000000000000000000000000000000000000000000c3500c870b82581beb090f8ee4e6a36ece9ea67df8d993c0962dd25e650d46f824bc0000000000000000000000000000000000000000000000000000000000000003',
27
+ chainId: ChainId.ethereum,
28
+ },
29
+ };
30
+
31
+ export function StoryView(props: IGetBasculeDepositStatusParameters) {
32
+ const request = async () => {
33
+ return getBasculeDepositStatus(props);
34
+ };
35
+
36
+ const { data, error, isLoading, refetch } = useQuery(request, [], false);
37
+
38
+ return (
39
+ <>
40
+ <Button
41
+ onClick={refetch}
42
+ disabled={isLoading}
43
+ isLoading={isLoading}
44
+ actionName={getBasculeDepositStatus.name}
45
+ />
46
+
47
+ <CodeBlock text={error || data} />
48
+ </>
49
+ );
50
+ }
@@ -0,0 +1,127 @@
1
+ import { CommonOptionalWriteParameters } from '../../common/parameters';
2
+ import { getErrorMessage } from '../../utils/err';
3
+ import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
4
+ import { IDeposit } from '../../api-functions/getDepositsByAddress/getDepositsByAddress';
5
+ import {
6
+ ByteArray,
7
+ Client,
8
+ getContract,
9
+ keccak256,
10
+ PublicClient,
11
+ zeroAddress,
12
+ } from 'viem';
13
+ import { makePublicClient } from '../../clients/public-client';
14
+ import { makeWalletClient } from '../../clients/wallet-client';
15
+ import LBTC_BASCULE_ABI from '../../tokens/abi/LBTC_BASCULE_ABI.json';
16
+ import { getTokenContractInfo } from '../../tokens/tokens';
17
+ import { Token } from '../../tokens/token-addresses';
18
+
19
+ /**
20
+ * The bascule drawbridge deposit status.
21
+ */
22
+ export enum BasculeDepositStatus {
23
+ /**
24
+ * The value representing that the deposit is unreported or potentially
25
+ * still pending.
26
+ */
27
+ UNREPORTED = 0,
28
+ /**
29
+ * The value representing that the deposit is reported.
30
+ */
31
+ REPORTED = 1,
32
+ /**
33
+ * The value representing that the deposit has already been withdrawn.
34
+ */
35
+ WITHDRAWN = 2,
36
+ }
37
+
38
+ export interface IGetBasculeDepositStatusParameters
39
+ extends CommonOptionalWriteParameters {
40
+ /**
41
+ * The deposit for which the bascule status will be checked.
42
+ * You can omit `rawPayload` parameter if `deposit` is provided.
43
+ */
44
+ deposit?: IDeposit;
45
+ /**
46
+ * The `rawPayload` of the deposit for which the bascule status
47
+ * will be checked.
48
+ * You can omit `deposit` parameter if `rawPayload` is provided.
49
+ */
50
+ rawPayload?: string;
51
+ }
52
+
53
+ /**
54
+ * Gets the Bascule drawbridge deposit status for given deposit.
55
+ * @param {IGetBasculeDepositStatusParameters} parameters - The parameters.
56
+ * @param {IDeposit} parameters.deposit - The deposit for which the bascule status will be checked. You can omit `rawPayload` parameter if `deposit` is provided.
57
+ * @param {string} parameters.rawPayload - The `rawPayload` of the deposit for which the bascule status will be checked. You can omit `deposit` parameter if `rawPayload` is provided.
58
+ * @param {ChainId} parameters.chainId - The chain id.
59
+ * @param {EIP1193Provider} parameters.provider - The optional EIP1193 provider.
60
+ * @param {string} parameters.rpcUrl - The optional rpc url.
61
+ * @param {Env} parameters.env - The optional environment identifier.
62
+ *
63
+ * @returns {Promise<BasculeDepositStatus>}
64
+ */
65
+ export async function getBasculeDepositStatus({
66
+ deposit,
67
+ rawPayload,
68
+ provider,
69
+ chainId,
70
+ rpcUrl,
71
+ env = DEFAULT_ENV,
72
+ }: IGetBasculeDepositStatusParameters) {
73
+ const payload = deposit?.rawPayload || rawPayload;
74
+
75
+ if (!payload) {
76
+ throw new Error(
77
+ "No 'rawPayload' or 'deposit' data provided. Please provide 'rawPayload' or 'deposit' parameter.",
78
+ );
79
+ }
80
+
81
+ const publicClient = makePublicClient({ chainId, rpcUrl });
82
+ const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
83
+
84
+ const basculeContractAddress = await publicClient.readContract({
85
+ abi: lbtcContract.abi,
86
+ address: lbtcContract.address,
87
+ functionName: 'Bascule',
88
+ });
89
+
90
+ // If there's no bascule contract address on the LBTC contract then return
91
+ // the the deposit is ok (REPORTED).
92
+ if (basculeContractAddress === zeroAddress) {
93
+ return BasculeDepositStatus.REPORTED;
94
+ }
95
+
96
+ let client: PublicClient | Client | undefined = undefined;
97
+ if (!provider) {
98
+ client = makePublicClient({ chainId, rpcUrl });
99
+ } else {
100
+ client = makeWalletClient({ provider, chainId });
101
+ }
102
+
103
+ if (!client) {
104
+ throw new Error(
105
+ "Could not determine the client for the contract interactions. Please provide the 'provider' and 'chainId' parameters or 'chainId' and optionally the 'rpcUrl' parameter.",
106
+ );
107
+ }
108
+
109
+ try {
110
+ const basculeContract = getContract({
111
+ abi: LBTC_BASCULE_ABI,
112
+ address: basculeContractAddress,
113
+ client,
114
+ });
115
+
116
+ const basculeDepositId = keccak256(
117
+ Buffer.from(payload.slice(8), 'hex') as unknown as ByteArray,
118
+ );
119
+
120
+ const status = await basculeContract.read.depositHistory([
121
+ basculeDepositId,
122
+ ]);
123
+ return status as BasculeDepositStatus;
124
+ } catch (err) {
125
+ throw new Error(getErrorMessage(err));
126
+ }
127
+ }
@@ -1,15 +1,16 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
-
3
- import { OChainId, TChainId } from '../../common/types/types';
2
+ import { ChainId } from '../../common/chains';
4
3
  import { Button } from '../../stories/components/Button';
5
4
  import { CodeBlock } from '../../stories/components/CodeBlock';
5
+ import { functionType } from '../../stories/components/decorators';
6
6
  import useQuery from '../../stories/hooks/useQuery';
7
7
  import { getLBTCMintingFee } from './getLBTCMintingFee';
8
8
 
9
9
  const meta = {
10
- title: 'Web3SDK/getLBTCMintingFee',
10
+ title: 'read/getLBTCMintingFee',
11
11
  component: StoryView,
12
12
  tags: ['autodocs'],
13
+ decorators: [functionType('read')],
13
14
  } satisfies Meta<typeof StoryView>;
14
15
 
15
16
  export default meta;
@@ -18,18 +19,18 @@ type Story = StoryObj<typeof meta>;
18
19
 
19
20
  export const Holesky: Story = {
20
21
  args: {
21
- chainId: OChainId.holesky,
22
+ chainId: ChainId.holesky,
22
23
  },
23
24
  };
24
25
 
25
26
  export const Ethereum: Story = {
26
27
  args: {
27
- chainId: OChainId.ethereum,
28
+ chainId: ChainId.ethereum,
28
29
  },
29
30
  };
30
31
 
31
32
  type GetLBTCMintingFeeProps = {
32
- chainId: TChainId;
33
+ chainId: ChainId;
33
34
  };
34
35
 
35
36
  export function StoryView(props: GetLBTCMintingFeeProps) {
@@ -43,16 +44,19 @@ export function StoryView(props: GetLBTCMintingFeeProps) {
43
44
 
44
45
  return (
45
46
  <div>
46
- <Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
47
- Get LBTC Minting Fee
48
- </Button>
47
+ <Button
48
+ onClick={refetch}
49
+ disabled={isLoading}
50
+ isLoading={isLoading}
51
+ actionName={getLBTCMintingFee.name}
52
+ />
49
53
 
50
- <CodeBlock text={error || data?.toString()} />
54
+ <CodeBlock text={error || data?.toFormat()} />
51
55
 
52
56
  {data && (
53
57
  <div className="mt-4 p-4 border rounded">
54
58
  <h3 className="text-lg font-bold mb-2">Fee Details</h3>
55
- <p>Minting Fee: {data.toString()} BTC</p>
59
+ <p>Minting Fee: {data.toFormat()} BTC</p>
56
60
  </div>
57
61
  )}
58
62
  </div>
@@ -0,0 +1,37 @@
1
+ import BigNumber from 'bignumber.js';
2
+ import { CommonParameters } from '../../common/parameters';
3
+ import { determineEnv } from '../../utils/env';
4
+ import { fromSatoshi } from '../../utils/satoshi';
5
+ import { makePublicClient } from '../../clients/public-client';
6
+ import { getTokenContractInfo } from '../../tokens/tokens';
7
+ import { Token } from '../../tokens/token-addresses';
8
+
9
+ /**
10
+ * Gets LBTC minting fee amount.
11
+ *
12
+ * @param {CommonParameters} parameters - The parameters.
13
+ * @param {ChainId} parameters.chainId - The chain id.
14
+ * @param {string} parameters.rpcUrl - The optional rpc url.
15
+ * @param {Env} parameters.env - The optional environment identifier.
16
+ *
17
+ * @return {Promise<BigNumber>}
18
+ */
19
+ export async function getLBTCMintingFee({
20
+ chainId,
21
+ rpcUrl,
22
+ env,
23
+ }: CommonParameters): Promise<BigNumber> {
24
+ const environment = env || determineEnv(chainId);
25
+
26
+ const publicClient = makePublicClient({ chainId, rpcUrl });
27
+ const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, environment);
28
+
29
+ const rawFeeValue = await publicClient.readContract({
30
+ abi: lbtcContract.abi,
31
+ address: lbtcContract.address,
32
+ functionName: 'getMintFee',
33
+ });
34
+
35
+ const lbtcMintFee = fromSatoshi(String(rawFeeValue));
36
+ return lbtcMintFee;
37
+ }
@@ -1,15 +1,17 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
+ import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
2
3
  import { Button } from '../../stories/components/Button';
3
4
  import { CodeBlock } from '../../stories/components/CodeBlock';
4
5
  import useQuery from '../../stories/hooks/useQuery';
5
- import { Vault } from '..';
6
- import { getVaultPoints, GetVaultPointsParameters } from './get-vault-points';
7
- import { exampleEvmAddress } from '../../stories/const';
6
+ import { getLBTCTotalSupply } from './getLBTCTotalSupply';
7
+ import { ChainId } from '../../common/chains';
8
+ import { functionType } from '../../stories/components/decorators';
8
9
 
9
10
  const meta = {
10
- title: 'vault/getVaultPoints',
11
+ title: 'read/getLBTCTotalSupply',
11
12
  component: StoryView,
12
13
  tags: ['autodocs'],
14
+ decorators: [functionType('read')],
13
15
  } satisfies Meta<typeof StoryView>;
14
16
 
15
17
  export default meta;
@@ -18,33 +20,28 @@ type Story = StoryObj<typeof meta>;
18
20
 
19
21
  export const WithParams: Story = {
20
22
  args: {
21
- account: exampleEvmAddress,
22
- vaultKey: Vault.Veda,
23
+ chainId: ChainId.ethereum,
24
+ env: DEFAULT_ENV,
23
25
  },
24
26
  };
25
27
 
26
- type SignNetworkFeeProps = GetVaultPointsParameters;
28
+ type TotalSupplyLBTCProps = Parameters<typeof getLBTCTotalSupply>[0];
27
29
 
28
- export function StoryView(props: SignNetworkFeeProps) {
30
+ export function StoryView(props: TotalSupplyLBTCProps) {
29
31
  const request = async () => {
30
- return getVaultPoints({
31
- ...props,
32
- });
32
+ return getLBTCTotalSupply(props);
33
33
  };
34
34
 
35
35
  const { data, error, isLoading, refetch } = useQuery(request, [], false);
36
36
 
37
37
  return (
38
38
  <>
39
- <p>This function gets the points earned by a user in the DeFi vault.</p>
40
-
41
39
  <Button
42
40
  onClick={refetch}
43
41
  disabled={isLoading}
44
42
  isLoading={isLoading}
45
- >
46
- {getVaultPoints.name}
47
- </Button>
43
+ actionName={getLBTCTotalSupply.name}
44
+ />
48
45
 
49
46
  <CodeBlock text={error || data} />
50
47
  </>
@@ -0,0 +1,34 @@
1
+ import { CommonParameters } from '../../common/parameters';
2
+ import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
3
+ import BigNumber from 'bignumber.js';
4
+ import { fromSatoshi } from '../../utils/satoshi';
5
+ import { makePublicClient } from '../../clients/public-client';
6
+ import { getTokenContractInfo } from '../../tokens/tokens';
7
+ import { Token } from '../../tokens/token-addresses';
8
+
9
+ /**
10
+ * Get the total supply of LBTC tokens.
11
+ *
12
+ * @param {CommonParameters} parameters - The parameters.
13
+ * @param {ChainId} parameters.chainId - The chain id.
14
+ * @param {string} parameters.rpcUrl - The optional rpc url.
15
+ * @param {Env} parameters.env - The optional environment identifier.
16
+ *
17
+ * @return {Promise<BigNumber>}
18
+ */
19
+ export async function getLBTCTotalSupply({
20
+ chainId,
21
+ rpcUrl,
22
+ env = DEFAULT_ENV,
23
+ }: CommonParameters): Promise<BigNumber> {
24
+ const publicClient = makePublicClient({ chainId, rpcUrl });
25
+ const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
26
+
27
+ const totalSupplyRaw = await publicClient.readContract({
28
+ abi: lbtcContract.abi,
29
+ address: lbtcContract.address,
30
+ functionName: 'totalSupply',
31
+ });
32
+
33
+ return fromSatoshi(String(totalSupplyRaw));
34
+ }
@@ -1,14 +1,15 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
2
  import { Button } from '../../stories/components/Button';
3
3
  import { CodeBlock } from '../../stories/components/CodeBlock';
4
- import { useConnect } from '../../stories/hooks/useConnect';
5
4
  import useQuery from '../../stories/hooks/useQuery';
6
5
  import { getPermitNonce, IGetPermitNonceParams } from './getPermitNonce';
6
+ import { functionType } from '../../stories/components/decorators';
7
7
 
8
8
  const meta = {
9
- title: 'Web3SDK/getPermitNonce',
9
+ title: 'read/getPermitNonce',
10
10
  component: StoryView,
11
11
  tags: ['autodocs'],
12
+ decorators: [functionType('read')],
12
13
  } satisfies Meta<typeof StoryView>;
13
14
 
14
15
  export default meta;
@@ -18,38 +19,27 @@ type Story = StoryObj<typeof meta>;
18
19
  export const WithParams: Story = {
19
20
  args: {
20
21
  owner: '0x1234567890123456789012345678901234567890',
22
+ chainId: 1,
21
23
  },
22
24
  };
23
25
 
24
- type GetPermitNonceProps = Pick<IGetPermitNonceParams, 'owner'>;
26
+ type GetPermitNonceProps = Parameters<typeof getPermitNonce>[0];
25
27
 
26
28
  export function StoryView(props: GetPermitNonceProps) {
27
- const { data: connectData, error: connectError } = useConnect();
28
-
29
29
  const request = async () => {
30
- return getPermitNonce({
31
- chainId: 1, // Ethereum mainnet
32
- rpcUrl: 'https://rpc.ankr.com/eth',
33
- ...props,
34
- });
30
+ return getPermitNonce(props);
35
31
  };
36
32
 
37
33
  const { data, error, isLoading, refetch } = useQuery(request, [], false);
38
34
 
39
- const formattedConnectData = connectData && {
40
- account: connectData.account,
41
- chainId: connectData.chainId,
42
- };
43
-
44
35
  return (
45
36
  <>
46
- <div className="mb-4">
47
- <CodeBlock text={connectError || formattedConnectData} />
48
- </div>
49
-
50
- <Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
51
- Get Permit Nonce
52
- </Button>
37
+ <Button
38
+ onClick={refetch}
39
+ disabled={isLoading}
40
+ isLoading={isLoading}
41
+ actionName={getPermitNonce.name}
42
+ />
53
43
 
54
44
  <CodeBlock text={error || data} />
55
45
 
@@ -0,0 +1,45 @@
1
+ import { CommonParameters } from '../../common/parameters';
2
+ import { determineEnv } from '../../utils/env';
3
+ import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
4
+ import { Address } from 'viem';
5
+ import { makePublicClient } from '../../clients/public-client';
6
+ import { getTokenContractInfo } from '../../tokens/tokens';
7
+ import { Token } from '../../tokens/token-addresses';
8
+
9
+ export interface IGetPermitNonceParams extends CommonParameters {
10
+ /**
11
+ * Owner address to check permit nonce for
12
+ */
13
+ owner: Address;
14
+ }
15
+
16
+ /**
17
+ * Get permit nonce for a specific owner address from LBTC contract.
18
+ * This nonce is used in EIP-2612 permit operations.
19
+ *
20
+ * @param {IGetPermitNonceParams} parameters - The parameters.
21
+ * @param {Address} parameters.owner - The account address.
22
+ * @param {ChainId} parameters.chainId - The chain id.
23
+ * @param {string} parameters.rpcUrl - The optional rpc url.
24
+ * @param {Env} parameters.env - The optional environment identifier.
25
+ */
26
+ export async function getPermitNonce({
27
+ owner,
28
+ chainId,
29
+ rpcUrl,
30
+ env = DEFAULT_ENV,
31
+ }: IGetPermitNonceParams): Promise<string> {
32
+ const environment = env || determineEnv(chainId);
33
+
34
+ const publicClient = makePublicClient({ chainId, rpcUrl });
35
+ const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, environment);
36
+
37
+ const nonce = await publicClient.readContract({
38
+ abi: lbtcContract.abi,
39
+ address: lbtcContract.address,
40
+ functionName: 'nonces',
41
+ args: [owner],
42
+ });
43
+
44
+ return String(nonce);
45
+ }
@@ -1,15 +1,17 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
2
 
3
- import { OChainId } from '../../common/types/types';
3
+ import { ChainId } from '../../common/chains';
4
4
  import { Button } from '../../stories/components/Button';
5
5
  import useQuery from '../../stories/hooks/useQuery';
6
6
  import { getShareValue, IGetShareValueParameters } from './getShareValue';
7
- import { Vault } from '../../vaults';
7
+ import { Vault } from '../../vaults/lib/config';
8
+ import { functionType } from '../../stories/components/decorators';
8
9
 
9
10
  const meta = {
10
- title: 'Web3SDK/getShareValue',
11
+ title: 'read/getShareValue',
11
12
  component: StoryView,
12
13
  tags: ['autodocs'],
14
+ decorators: [functionType('read')],
13
15
  } satisfies Meta<typeof StoryView>;
14
16
 
15
17
  export default meta;
@@ -18,7 +20,7 @@ type Story = StoryObj<typeof meta>;
18
20
 
19
21
  export const WithParams: Story = {
20
22
  args: {
21
- chainId: OChainId.ethereum,
23
+ chainId: ChainId.ethereum,
22
24
  vaultKey: Vault.Veda,
23
25
  },
24
26
  };
@@ -36,9 +38,12 @@ export function StoryView(props: IGetShareValueParameters) {
36
38
 
37
39
  return (
38
40
  <div>
39
- <Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
40
- Get LBTCv value
41
- </Button>
41
+ <Button
42
+ onClick={refetch}
43
+ disabled={isLoading}
44
+ isLoading={isLoading}
45
+ actionName={getShareValue.name}
46
+ />
42
47
 
43
48
  {data && (
44
49
  <div className="mt-4 p-4 border rounded">
@@ -0,0 +1,58 @@
1
+ import BigNumber from 'bignumber.js';
2
+ import { getErrorMessage } from '../../utils/err';
3
+ import { isVedaVaultChain, Vault, VAULTS } from '../../vaults/lib/config';
4
+ import { fromSatoshi } from '../../utils/satoshi';
5
+ import { makePublicClient } from '../../clients/public-client';
6
+ import { getContract } from 'viem';
7
+ import { CommonParameters } from '../../common/parameters';
8
+
9
+ export interface IGetShareValueParameters extends CommonParameters {
10
+ /**
11
+ * Optional DeFi vault identifier specifying the vault in use
12
+ * @default {string} - "veda"
13
+ */
14
+ vaultKey?: Vault;
15
+ }
16
+
17
+ /**
18
+ * Gets the value of a single share unit (in LBTC) from the specified vault.
19
+ *
20
+ * @param {IGetShareValueParameters} parameters - The parameters.
21
+ * @param {Vault} parameters.vaultKey - The optional DeFi vault identifier.
22
+ * @param {ChainId} parameters.chainId - The chain id.
23
+ * @param {string} parameters.rpcUrl - The optional rpc url.
24
+ *
25
+ * @returns {Promise<BigNumber>}
26
+ */
27
+ export async function getShareValue({
28
+ chainId,
29
+ rpcUrl,
30
+ vaultKey = Vault.Veda,
31
+ }: IGetShareValueParameters): Promise<BigNumber> {
32
+ const vault = VAULTS[vaultKey];
33
+ if (!vault) {
34
+ throw new Error(`Unknown vault key: ${vaultKey}`);
35
+ }
36
+
37
+ if (!isVedaVaultChain(chainId)) {
38
+ throw new Error(
39
+ `Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.chains.join(', ')}`,
40
+ );
41
+ }
42
+
43
+ try {
44
+ const client = makePublicClient({ chainId, rpcUrl });
45
+
46
+ const accountantContract = getContract({
47
+ abi: vault.accountantContract.abi,
48
+ address: vault.accountantContract.address,
49
+ client,
50
+ });
51
+
52
+ const exchangeRate = await accountantContract.read.getRate();
53
+ return fromSatoshi(String(exchangeRate));
54
+ } catch (err) {
55
+ const errorMessage = getErrorMessage(err);
56
+ throw new Error(errorMessage);
57
+ }
58
+ }
@@ -1,20 +1,22 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
2
 
3
- import { OChainId } from '../../common/types/types';
3
+ import { ChainId } from '../../common/chains';
4
4
  import { Button } from '../../stories/components/Button';
5
5
  import useQuery from '../../stories/hooks/useQuery';
6
6
  import {
7
7
  getSharesByAddress,
8
8
  IGetSharesByAddressParameters,
9
9
  } from './getSharesByAddress';
10
- import { Vault } from '../../vaults';
11
- import { exampleEvmAddress } from '../../stories/const';
10
+ import { Vault } from '../../vaults/lib/config';
11
+ import { EXAMPLE_EVM_ADDRESS } from '../../stories/constants';
12
12
  import { CodeBlock } from '../../stories/components/CodeBlock';
13
+ import { functionType } from '../../stories/components/decorators';
13
14
 
14
15
  const meta = {
15
- title: 'Web3SDK/getSharesByAddress',
16
+ title: 'read/getSharesByAddress',
16
17
  component: StoryView,
17
18
  tags: ['autodocs'],
19
+ decorators: [functionType('read')],
18
20
  } satisfies Meta<typeof StoryView>;
19
21
 
20
22
  export default meta;
@@ -23,8 +25,8 @@ type Story = StoryObj<typeof meta>;
23
25
 
24
26
  export const WithParams: Story = {
25
27
  args: {
26
- chainId: OChainId.ethereum,
27
- address: exampleEvmAddress,
28
+ chainId: ChainId.ethereum,
29
+ address: EXAMPLE_EVM_ADDRESS,
28
30
  vaultKey: Vault.Veda,
29
31
  },
30
32
  };
@@ -40,9 +42,12 @@ export function StoryView(props: IGetSharesByAddressParameters) {
40
42
 
41
43
  return (
42
44
  <div>
43
- <Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
44
- Get LBTCv shares owned
45
- </Button>
45
+ <Button
46
+ onClick={refetch}
47
+ disabled={isLoading}
48
+ isLoading={isLoading}
49
+ actionName={getSharesByAddress.name}
50
+ />
46
51
 
47
52
  <CodeBlock text={error || data} />
48
53