@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
@@ -1,60 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/react';
2
- import { defaultEnv } from '@lombard.finance/sdk-common';
3
- import { Button } from '../../stories/components/Button';
4
- import { CodeBlock } from '../../stories/components/CodeBlock';
5
- import { useConnect } from '../../stories/hooks/useConnect';
6
- import useQuery from '../../stories/hooks/useQuery';
7
- import {
8
- getLBTCTotalSupply,
9
- ILBTCTotalSupplyParams,
10
- } from './getLBTCTotalSupply';
11
-
12
- const meta = {
13
- title: 'Web3SDK/getLBTCTotalSupply',
14
- component: StoryView,
15
- tags: ['autodocs'],
16
- } satisfies Meta<typeof StoryView>;
17
-
18
- export default meta;
19
-
20
- type Story = StoryObj<typeof meta>;
21
-
22
- export const WithParams: Story = {
23
- args: {
24
- env: defaultEnv,
25
- },
26
- };
27
-
28
- type TotalSupplyLBTCProps = Pick<ILBTCTotalSupplyParams, 'env'>;
29
-
30
- export function StoryView(props: TotalSupplyLBTCProps) {
31
- const { data: connectData, error: connectError } = useConnect();
32
-
33
- const request = async () => {
34
- return getLBTCTotalSupply({
35
- chainId: 1,
36
- rpcUrl: 'https://rpc.ankr.com/eth',
37
- ...props,
38
- });
39
- };
40
-
41
- const { data, error, isLoading, refetch } = useQuery(request, [], false);
42
-
43
- const formattedConnectData = connectData && {
44
- account: connectData.account,
45
- chainId: connectData.chainId,
46
- };
47
-
48
- return (
49
- <>
50
- <div className="mb-4">
51
- <CodeBlock text={connectError || formattedConnectData} />
52
- </div>
53
- <Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
54
- Get Total LBTC Supply
55
- </Button>
56
-
57
- <CodeBlock text={error || data} />
58
- </>
59
- );
60
- }
@@ -1,26 +0,0 @@
1
- import { IReadProviderParams, ReadProvider } from '../../provider/ReadProvider';
2
- import { TRpcUrlConfig } from '../../provider/rpcUrlConfig';
3
- import { IEnvParam } from '../../common/types/internalTypes';
4
-
5
- import { getLbtcTokenContract } from '../utils/getLbtcTokenContract';
6
-
7
- export interface ILBTCTotalSupplyParams extends IEnvParam {
8
- rpcUrl: string;
9
- chainId: IReadProviderParams['chainId'];
10
- }
11
-
12
- export async function getLBTCTotalSupply({
13
- env,
14
- rpcUrl,
15
- chainId,
16
- }: ILBTCTotalSupplyParams): Promise<string> {
17
- const rpcUrlConfig: TRpcUrlConfig = { [chainId]: rpcUrl };
18
-
19
- const provider = new ReadProvider({ chainId, rpcUrlConfig });
20
-
21
- const tokenContract = getLbtcTokenContract(provider, env);
22
-
23
- const balance: bigint = await tokenContract.methods.totalSupply().call();
24
-
25
- return balance.toString();
26
- }
@@ -1,47 +0,0 @@
1
- import { TChainId } from '../../common/types/types';
2
- import { getErrorMessage } from '../../common/utils/getErrorMessage';
3
- import { ReadProvider } from '../../provider/ReadProvider';
4
- import { chainIdToEnv } from '../utils/chainIdToEnv';
5
- import { getLbtcTokenContract } from '../utils/getLbtcTokenContract';
6
- import { getRpcUrlConfigFromChain } from '../utils/getRpcUrlConfigFromChain';
7
-
8
- export interface IGetPermitNonceParams {
9
- /**
10
- * Owner address to check permit nonce for
11
- */
12
- owner: string;
13
- /**
14
- * Chain ID of the network
15
- */
16
- chainId: TChainId;
17
- /**
18
- * RPC URL for the network (optional)
19
- */
20
- rpcUrl?: string;
21
- }
22
-
23
- /**
24
- * Get permit nonce for a specific owner address from LBTC contract.
25
- * This nonce is used in EIP-2612 permit operations.
26
- *
27
- * @param {IGetPermitNonceParams} params - Parameters for getting permit nonce
28
- * @returns {Promise<string>} Promise that resolves to the permit nonce value
29
- */
30
- export async function getPermitNonce({
31
- owner,
32
- rpcUrl,
33
- chainId,
34
- }: IGetPermitNonceParams): Promise<string> {
35
- const rpcUrlConfig = getRpcUrlConfigFromChain(chainId, rpcUrl);
36
- const provider = new ReadProvider({ chainId, rpcUrlConfig });
37
- const env = chainIdToEnv(chainId);
38
- const tokenContract = getLbtcTokenContract(provider, env);
39
-
40
- try {
41
- const nonce: bigint = await tokenContract.methods.nonces(owner).call();
42
- return nonce.toString();
43
- } catch (error) {
44
- const errorMessage = getErrorMessage(error);
45
- throw new Error(errorMessage);
46
- }
47
- }
@@ -1,58 +0,0 @@
1
- import BigNumber from 'bignumber.js';
2
- import { TChainId } from '../../common/types/types';
3
- import { ReadProvider } from '../../provider/ReadProvider';
4
- import { getRpcUrlConfigFromChain } from '../utils/getRpcUrlConfigFromChain';
5
- import { getErrorMessage } from '../../common/utils/getErrorMessage';
6
- import { VAULTS } from '../../vaults';
7
- import { fromSatoshi } from '../../common/utils/convertSatoshi';
8
-
9
- export interface IGetShareValueParameters {
10
- /**
11
- * Chain ID for identifying the blockchain network (e.g., Ethereum, Binance Smart Chain, etc.)
12
- */
13
- chainId: TChainId;
14
- /**
15
- * Optional RPC URL to connect to the blockchain. If not provided, a default RPC URL might be used.
16
- */
17
- rpcUrl?: string;
18
- /**
19
- * Optional vault key specifying the vault in use
20
- * @default {string} - "veda"
21
- */
22
- vaultKey?: 'veda';
23
- }
24
-
25
- /**
26
- * Gets the value of a single share unit (in LBTC) from the specified vault.
27
- */
28
- export async function getShareValue({
29
- chainId,
30
- rpcUrl,
31
- vaultKey = 'veda',
32
- }: IGetShareValueParameters): Promise<BigNumber> {
33
- const vault = VAULTS[vaultKey];
34
- if (!vault) {
35
- throw new Error(`Unknown vault key: ${vaultKey}`);
36
- }
37
-
38
- if (!(vault.chains as unknown as number[]).includes(chainId)) {
39
- throw new Error(
40
- `Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.chains.join(', ')}`,
41
- );
42
- }
43
-
44
- const rpcUrlConfig = getRpcUrlConfigFromChain(chainId, rpcUrl);
45
- const provider = new ReadProvider({ chainId, rpcUrlConfig });
46
-
47
- try {
48
- const accountant = provider.createContract<
49
- typeof vault.accountantContract.abi
50
- >(vault.accountantContract.abi, vault.accountantContract.address);
51
-
52
- const exchangeRate = await accountant.methods.getRate().call();
53
- return fromSatoshi(String(exchangeRate));
54
- } catch (error) {
55
- const errorMessage = getErrorMessage(error);
56
- throw new Error(errorMessage);
57
- }
58
- }
@@ -1,48 +0,0 @@
1
- import { TChainId } from '../../common/types/types';
2
- import { ReadProvider } from '../../provider/ReadProvider';
3
- import { getRpcUrlConfigFromChain } from '../utils/getRpcUrlConfigFromChain';
4
- import { STAKE_AND_BAKE } from '../abi';
5
- import { getErrorMessage } from '../../common/utils/getErrorMessage';
6
-
7
- export interface IGetStakeAndBakeFeeParams {
8
- /**
9
- * Chain ID
10
- */
11
- chainId: TChainId;
12
- /**
13
- * RPC URL
14
- */
15
- rpcUrl?: string;
16
- /**
17
- * Vault Address
18
- */
19
- vaultAddress: string;
20
- }
21
-
22
- /**
23
- * Get Stake and bake fee.
24
- *
25
- * @param chainId - Chain ID
26
- * @param rpcUrl - RPC URL (optional)
27
- * @param vaultAddress - Vault Address
28
- *
29
- * @returns Stake and bake fee in satoshis
30
- */
31
- export async function getStakeAndBakeFee({
32
- chainId,
33
- rpcUrl,
34
- vaultAddress,
35
- }: IGetStakeAndBakeFeeParams): Promise<string> {
36
- const rpcUrlConfig = getRpcUrlConfigFromChain(chainId, rpcUrl);
37
- const provider = new ReadProvider({ chainId, rpcUrlConfig });
38
-
39
- try {
40
- const contract = provider.createContract(STAKE_AND_BAKE, vaultAddress);
41
-
42
- const fee: bigint = await contract.methods.getStakeAndBakeFee().call();
43
- return fee.toString();
44
- } catch (error) {
45
- const errorMessage = getErrorMessage(error);
46
- throw new Error(errorMessage);
47
- }
48
- }
@@ -1,96 +0,0 @@
1
- import { ZERO_ADDRESS as PLACEHOLDER_ADDRESS } from '../common/const';
2
- import { OChainId, TChainId } from '../common/types/types';
3
- import { Env, defaultEnv } from '@lombard.finance/sdk-common';
4
-
5
- type LbtcTokenConfig = Record<TChainId, string>;
6
-
7
- const stageConfig: LbtcTokenConfig = {
8
- [OChainId.holesky]: '0xED7bfd5C1790576105Af4649817f6d35A75CD818',
9
- [OChainId.ethereum]: PLACEHOLDER_ADDRESS,
10
-
11
- [OChainId.binanceSmartChainTestnet]:
12
- '0x731eFa688F3679688cf60A3993b8658138953ED6',
13
- [OChainId.binanceSmartChain]: PLACEHOLDER_ADDRESS,
14
- [OChainId.sepolia]: '0xc47e4b3124597fdf8dd07843d4a7052f2ee80c30',
15
-
16
- [OChainId.base]: PLACEHOLDER_ADDRESS,
17
- [OChainId.baseSepoliaTestnet]: '0x731eFa688F3679688cf60A3993b8658138953ED6',
18
-
19
- [OChainId.berachain]: PLACEHOLDER_ADDRESS,
20
- [OChainId.berachainBartioTestnet]:
21
- '0xc47e4b3124597FDF8DD07843D4a7052F2eE80C30',
22
-
23
- [OChainId.corn]: PLACEHOLDER_ADDRESS,
24
- [OChainId.swell]: PLACEHOLDER_ADDRESS,
25
-
26
- [OChainId.sonic]: PLACEHOLDER_ADDRESS,
27
- [OChainId.sonicBlazeTestnet]: '0x731eFa688F3679688cf60A3993b8658138953ED6',
28
-
29
- [OChainId.morph]: PLACEHOLDER_ADDRESS,
30
- [OChainId.morphHolesky]: PLACEHOLDER_ADDRESS,
31
- [OChainId.etherlink]: PLACEHOLDER_ADDRESS,
32
- };
33
-
34
- const testnetConfig: LbtcTokenConfig = {
35
- [OChainId.holesky]: '0x38A13AB20D15ffbE5A7312d2336EF1552580a4E2',
36
- [OChainId.ethereum]: PLACEHOLDER_ADDRESS,
37
-
38
- [OChainId.binanceSmartChainTestnet]:
39
- '0x107Fc7d90484534704dD2A9e24c7BD45DB4dD1B5',
40
- [OChainId.binanceSmartChain]: PLACEHOLDER_ADDRESS,
41
- [OChainId.sepolia]: '0xc47e4b3124597fdf8dd07843d4a7052f2ee80c30',
42
-
43
- [OChainId.base]: PLACEHOLDER_ADDRESS,
44
- [OChainId.baseSepoliaTestnet]: PLACEHOLDER_ADDRESS,
45
-
46
- [OChainId.berachain]: PLACEHOLDER_ADDRESS,
47
- [OChainId.berachainBartioTestnet]:
48
- '0xc47e4b3124597FDF8DD07843D4a7052F2eE80C30',
49
-
50
- [OChainId.corn]: PLACEHOLDER_ADDRESS,
51
- [OChainId.swell]: PLACEHOLDER_ADDRESS,
52
-
53
- [OChainId.sonic]: PLACEHOLDER_ADDRESS,
54
- [OChainId.sonicBlazeTestnet]: '0x107Fc7d90484534704dD2A9e24c7BD45DB4dD1B5',
55
-
56
- [OChainId.morph]: PLACEHOLDER_ADDRESS,
57
- [OChainId.morphHolesky]: PLACEHOLDER_ADDRESS,
58
- [OChainId.etherlink]: PLACEHOLDER_ADDRESS,
59
- };
60
-
61
- const prodConfig: LbtcTokenConfig = {
62
- [OChainId.ethereum]: '0x8236a87084f8b84306f72007f36f2618a5634494',
63
- [OChainId.holesky]: PLACEHOLDER_ADDRESS,
64
- [OChainId.sepolia]: PLACEHOLDER_ADDRESS,
65
-
66
- [OChainId.binanceSmartChainTestnet]: PLACEHOLDER_ADDRESS,
67
- [OChainId.binanceSmartChain]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
68
-
69
- [OChainId.base]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
70
- [OChainId.baseSepoliaTestnet]: PLACEHOLDER_ADDRESS,
71
-
72
- [OChainId.berachain]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
73
- [OChainId.berachainBartioTestnet]: PLACEHOLDER_ADDRESS,
74
-
75
- [OChainId.corn]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
76
- [OChainId.swell]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
77
-
78
- [OChainId.sonic]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
79
- [OChainId.sonicBlazeTestnet]: PLACEHOLDER_ADDRESS,
80
-
81
- [OChainId.morph]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
82
- [OChainId.morphHolesky]: PLACEHOLDER_ADDRESS,
83
-
84
- [OChainId.etherlink]: '0xecAc9C5F704e954931349Da37F60E39f515c11c1',
85
- };
86
-
87
- export function getLbtcAddressConfig(env: Env = defaultEnv): LbtcTokenConfig {
88
- switch (env) {
89
- case Env.prod:
90
- return prodConfig;
91
- case Env.testnet:
92
- return testnetConfig;
93
- default:
94
- return stageConfig;
95
- }
96
- }
@@ -1,23 +0,0 @@
1
- import { Provider } from '../../provider';
2
- import { IProviderBasedParams } from '../types';
3
-
4
- export type SignLbtcDestinationAddrParams = IProviderBasedParams;
5
-
6
- /**
7
- * Signs the destination address for the LBTC in active chain
8
- * in the current account. Signing is necessary for the
9
- * generation of the deposit address.
10
- *
11
- * @param {SignLbtcDestinationAddrParams} params
12
- *
13
- * @returns {Promise<string>} The signature of the message.
14
- */
15
- export async function signLbtcDestinationAddr(
16
- params: SignLbtcDestinationAddrParams,
17
- ): Promise<string> {
18
- const provider = new Provider(params);
19
-
20
- const message = `destination chain id is ${params.chainId}`;
21
-
22
- return provider.signMessage(message);
23
- }
@@ -1,97 +0,0 @@
1
- import type { Meta } from '@storybook/react';
2
- import Web3, { FMT_BYTES, FMT_NUMBER } from 'web3';
3
- import { OChainId, TChainId } from '../../common/types/types';
4
- import { Button } from '../../stories/components/Button';
5
- import { CodeBlock } from '../../stories/components/CodeBlock';
6
- import { useConnect } from '../../stories/hooks/useConnect';
7
- import useQuery from '../../stories/hooks/useQuery';
8
- import { fromCamelCase } from '../../stories/utils/fromCamelCase';
9
- import { signLbtcDestinationAddr } from './signLbtcDestinationAddr';
10
-
11
- const { name } = signLbtcDestinationAddr;
12
- const nameWithWhitespaces = fromCamelCase(name);
13
-
14
- const meta = {
15
- title: 'Web3SDK/signLbtcDestionationAddr',
16
- component: StoryView,
17
- tags: ['autodocs'],
18
- } satisfies Meta<typeof StoryView>;
19
-
20
- export default meta;
21
-
22
- export function StoryView() {
23
- const {
24
- data: connectData,
25
- error: connectError,
26
- isLoading: isConnectLoading,
27
- connect,
28
- } = useConnect();
29
-
30
- const request = async () => {
31
- if (!connectData) {
32
- return;
33
- }
34
-
35
- return signLbtcDestinationAddr(connectData);
36
- };
37
-
38
- const { data, error, isLoading, refetch } = useQuery(request, [], false);
39
-
40
- const formattedConnectData = connectData && {
41
- account: connectData.account,
42
- chainId: connectData.chainId,
43
- };
44
-
45
- return (
46
- <>
47
- <p>
48
- This method is used to get the signature of the Liquid BTC destination
49
- address. The signature is used for generating the deposit address.
50
- </p>
51
-
52
- <div className="mb-4">
53
- <Button
54
- onClick={connect}
55
- disabled={isConnectLoading}
56
- isLoading={isConnectLoading}
57
- >
58
- Connect
59
- </Button>
60
-
61
- <CodeBlock text={connectError || formattedConnectData} />
62
- </div>
63
-
64
- <Button
65
- onClick={refetch}
66
- disabled={isLoading || !connectData}
67
- isLoading={isLoading}
68
- >
69
- {nameWithWhitespaces}
70
- </Button>
71
-
72
- <CodeBlock text={error || data} />
73
- </>
74
- );
75
- }
76
-
77
- async function getWalletInfo(web3: Web3) {
78
- const [account] = await web3.eth.getAccounts();
79
-
80
- if (!account) {
81
- throw new Error('No account found');
82
- }
83
-
84
- const chainId = await web3.eth.getChainId({
85
- bytes: FMT_BYTES.HEX,
86
- number: FMT_NUMBER.NUMBER,
87
- });
88
-
89
- return {
90
- account,
91
- chainId,
92
- };
93
- }
94
-
95
- function isValidChain(chainId: number): chainId is TChainId {
96
- return Object.values(OChainId).includes(chainId as TChainId);
97
- }
@@ -1,91 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/react';
2
- import { defaultEnv } from '@lombard.finance/sdk-common';
3
- import { Button } from '../../stories/components/Button';
4
- import { CodeBlock } from '../../stories/components/CodeBlock';
5
- import { useConnect } from '../../stories/hooks/useConnect';
6
- import useQuery from '../../stories/hooks/useQuery';
7
- import { fromCamelCase } from '../../stories/utils/fromCamelCase';
8
- import { MS_PER_DAY } from '../const';
9
- import { ISignNetworkFeeParams, signNetworkFee } from './signNetworkFee';
10
-
11
- const { name } = signNetworkFee;
12
- const nameWithWhitespaces = fromCamelCase(name);
13
-
14
- const meta = {
15
- title: 'Web3SDK/signNetworkFee',
16
- component: StoryView,
17
- tags: ['autodocs'],
18
- } satisfies Meta<typeof StoryView>;
19
-
20
- export default meta;
21
-
22
- type Story = StoryObj<typeof meta>;
23
-
24
- export const WithParams: Story = {
25
- args: {
26
- env: defaultEnv,
27
- },
28
- };
29
-
30
- type SignNetworkFeeProps = Pick<ISignNetworkFeeParams, 'env'>;
31
-
32
- export function StoryView(props: SignNetworkFeeProps) {
33
- const {
34
- data: connectData,
35
- error: connectError,
36
- isLoading: isConnectLoading,
37
- connect,
38
- } = useConnect();
39
-
40
- const request = async () => {
41
- if (!connectData) {
42
- return;
43
- }
44
-
45
- return signNetworkFee({
46
- ...connectData,
47
- ...props,
48
- fee: '1100',
49
- expiry: Date.now() + MS_PER_DAY,
50
- address: connectData.account,
51
- });
52
- };
53
-
54
- const { data, error, isLoading, refetch } = useQuery(request, [], false);
55
-
56
- const formattedConnectData = connectData && {
57
- account: connectData.account,
58
- chainId: connectData.chainId,
59
- };
60
-
61
- return (
62
- <>
63
- <p>
64
- This method is used to get the signature of the Liquid BTC destination
65
- address. The signature is used for auto-mint feature.
66
- </p>
67
-
68
- <div className="mb-4">
69
- <Button
70
- onClick={connect}
71
- disabled={isConnectLoading}
72
- isLoading={isConnectLoading}
73
- >
74
- Connect
75
- </Button>
76
-
77
- <CodeBlock text={connectError || formattedConnectData} />
78
- </div>
79
-
80
- <Button
81
- onClick={refetch}
82
- disabled={isLoading || !connectData}
83
- isLoading={isLoading}
84
- >
85
- {nameWithWhitespaces}
86
- </Button>
87
-
88
- <CodeBlock text={error || data} />
89
- </>
90
- );
91
- }
@@ -1,92 +0,0 @@
1
- import { IEnvParam } from '../../common/types/internalTypes';
2
- import { Provider } from '../../provider';
3
- import { SECONDS_PER_DAY } from '../const';
4
- import { IProviderBasedParams } from '../types';
5
- import { getLbtcTokenContract } from '../utils/getLbtcTokenContract';
6
- import { getTypedData } from './getTypedData';
7
-
8
- const NO_SIGNATURE_ERROR =
9
- 'Failed to obtain a valid signature. The response is undefined or invalid.';
10
-
11
- export interface ISignNetworkFeeParams
12
- extends Pick<IProviderBasedParams, 'provider' | 'chainId'>,
13
- IEnvParam {
14
- /**
15
- * User address
16
- */
17
- address: string;
18
- /**
19
- * Authorization fee
20
- */
21
- fee: string;
22
- /**
23
- * Expiration time
24
- */
25
- expiry: number;
26
- }
27
-
28
- export interface ISignNetworkFeeResponse {
29
- /**
30
- * signature
31
- */
32
- signature: string;
33
- /**
34
- * JSON typed data used for the signature
35
- */
36
- typedData: string;
37
- }
38
-
39
- const getDefaultExpiryUnix = () => {
40
- return Math.floor(Date.now() / 1000 + SECONDS_PER_DAY);
41
- };
42
-
43
- /**
44
- * Signs the network fee transaction in the current account.
45
- * Signing is necessary for the auto-mint.
46
- *
47
- * @param {ISignNetworkFeeParams} params - The parameters for signing network fee
48
- * @returns {Promise<ISignNetworkFeeResponse>} A promise that resolves to the signature and typed data
49
- */
50
- export async function signNetworkFee({
51
- address,
52
- provider,
53
- fee,
54
- chainId,
55
- env,
56
- expiry = getDefaultExpiryUnix(),
57
- }: ISignNetworkFeeParams): Promise<ISignNetworkFeeResponse> {
58
- const providerInstance = new Provider({
59
- provider,
60
- account: address,
61
- chainId,
62
- });
63
-
64
- const tokenContract = getLbtcTokenContract(providerInstance, env);
65
- const verifyingContract = tokenContract.options.address;
66
- const typedData = JSON.stringify(
67
- getTypedData({
68
- chainId,
69
- verifyingContract,
70
- fee,
71
- expiry,
72
- }),
73
- );
74
-
75
- const signature = await providerInstance.web3?.currentProvider?.request<
76
- 'eth_signTypedData_v4',
77
- string
78
- >({
79
- method: 'eth_signTypedData_v4',
80
- params: [address, typedData],
81
- });
82
-
83
- if (typeof signature === 'string') {
84
- return { signature, typedData: typedData };
85
- }
86
-
87
- if (!signature?.result) {
88
- throw new Error(NO_SIGNATURE_ERROR);
89
- }
90
-
91
- return { signature: signature.result, typedData: typedData };
92
- }