@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.
Files changed (211) hide show
  1. package/README.md +428 -399
  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 +68 -8269
  9. package/dist/index.js.map +1 -1
  10. package/dist/index2.cjs +53 -0
  11. package/dist/index2.cjs.map +1 -0
  12. package/dist/index2.js +21672 -0
  13. package/dist/index2.js.map +1 -0
  14. package/package.json +5 -5
  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 +15 -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 +8 -8
  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 +14 -9
  30. package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +61 -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/clients/public-client.ts +32 -0
  39. package/src/clients/rpc-url-config.ts +20 -0
  40. package/src/clients/wallet-client.ts +33 -0
  41. package/src/{sdk/apiConfig.ts → common/api-config.ts} +2 -2
  42. package/src/common/blockchain-identifier.ts +107 -0
  43. package/src/common/chains.ts +72 -0
  44. package/src/common/parameters.ts +51 -0
  45. package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +76 -0
  46. package/src/contract-functions/approveLBTC/approveLBTC.ts +64 -0
  47. package/src/{web3Sdk → contract-functions}/claimLBTC/claimLBTC.stories.tsx +22 -30
  48. package/src/contract-functions/claimLBTC/claimLBTC.ts +89 -0
  49. package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +50 -0
  50. package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +121 -0
  51. package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +15 -11
  52. package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +34 -0
  53. package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +49 -0
  54. package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +30 -0
  55. package/src/{web3Sdk → contract-functions}/getPermitNonce/getPermitNonce.stories.tsx +12 -22
  56. package/src/contract-functions/getPermitNonce/getPermitNonce.ts +39 -0
  57. package/src/{web3Sdk → contract-functions}/getShareValue/getShareValue.stories.tsx +11 -6
  58. package/src/contract-functions/getShareValue/getShareValue.ts +58 -0
  59. package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.stories.tsx +13 -8
  60. package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.ts +29 -28
  61. package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +16 -16
  62. package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +61 -0
  63. package/src/{web3Sdk → contract-functions}/index.ts +8 -7
  64. package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +32 -0
  65. package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +63 -0
  66. package/src/contract-functions/signNetworkFee/signNetworkFee.stories.tsx +91 -0
  67. package/src/contract-functions/signNetworkFee/signNetworkFee.ts +98 -0
  68. package/src/contract-functions/signStakeAndBake/index.ts +1 -0
  69. package/src/{web3Sdk → contract-functions}/signStakeAndBake/signStakeAndBake.stories.tsx +27 -40
  70. package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +140 -0
  71. package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +80 -0
  72. package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +65 -0
  73. package/src/index.ts +35 -10
  74. package/src/rewards/index.ts +26 -0
  75. package/src/rewards/lib/claim-reward.stories.tsx +82 -0
  76. package/src/rewards/lib/claim-reward.ts +84 -0
  77. package/src/rewards/lib/get-reward-balances.stories.tsx +64 -0
  78. package/src/rewards/lib/get-reward-balances.ts +81 -0
  79. package/src/rewards/lib/get-reward-signing-data.stories.tsx +76 -0
  80. package/src/rewards/lib/get-reward-signing-data.ts +52 -0
  81. package/src/rewards/lib/get-reward-withdrawal-fee.stories.tsx +61 -0
  82. package/src/rewards/lib/get-reward-withdrawal-fee.ts +37 -0
  83. package/src/rewards/lib/get-reward-withdrawals.stories.tsx +60 -0
  84. package/src/rewards/lib/get-reward-withdrawals.ts +92 -0
  85. package/src/rewards/lib/reward-tokens.ts +7 -0
  86. package/src/stories/components/Button/Button.css +10 -0
  87. package/src/stories/components/Button/Button.tsx +15 -4
  88. package/src/stories/components/CodeBlock/CodeBlock.tsx +1 -0
  89. package/src/stories/components/ConnectButton/connect-button.tsx +100 -0
  90. package/src/stories/components/ConnectButton/index.ts +1 -0
  91. package/src/stories/components/decorators/function-type.tsx +63 -0
  92. package/src/stories/components/decorators/index.ts +2 -0
  93. package/src/stories/components/decorators/wagmi-decorator.tsx +79 -0
  94. package/src/stories/components/error-block.tsx +21 -0
  95. package/src/stories/constants.ts +3 -0
  96. package/src/stories/hooks/useConnection.ts +72 -0
  97. package/src/stories/hooks/useQuery.ts +2 -2
  98. package/src/tokens/abi/LBTC_ABI.json +1761 -0
  99. package/src/tokens/abi/LBTC_BASCULE_ABI.json +850 -0
  100. package/src/tokens/lbtc-addresses.ts +54 -0
  101. package/src/tokens/lbtc-contract.ts +89 -0
  102. package/src/tokens/tokens.ts +111 -0
  103. package/src/utils/env.ts +12 -0
  104. package/src/utils/hex.ts +2 -2
  105. package/src/utils/numbers.ts +5 -0
  106. package/src/{common/utils/convertSatoshi.ts → utils/satoshi.ts} +3 -3
  107. package/src/utils/time.ts +12 -0
  108. package/src/vaults/abi/VEDA_VAULT_BASE_ASSET_ABI.json +296 -0
  109. package/src/vaults/abi/VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI.json +502 -0
  110. package/src/vaults/abi/VEDA_VAULT_SPENDER_ABI.json +408 -0
  111. package/src/vaults/abi/VEDA_VAULT_TELLER_ABI.json +700 -0
  112. package/src/vaults/index.ts +144 -36
  113. package/src/vaults/lib/cancel-withdraw.stories.tsx +79 -0
  114. package/src/vaults/lib/deposit.stories.tsx +81 -0
  115. package/src/vaults/lib/deposit.ts +151 -0
  116. package/src/vaults/lib/get-vault-deposits.stories.tsx +15 -9
  117. package/src/vaults/lib/get-vault-deposits.ts +45 -22
  118. package/src/vaults/lib/get-vault-points.stories.tsx +13 -6
  119. package/src/vaults/lib/get-vault-points.ts +14 -10
  120. package/src/vaults/lib/get-vault-withdrawals.stories.tsx +15 -8
  121. package/src/vaults/lib/get-vault-withdrawals.ts +72 -38
  122. package/src/vaults/lib/withdraw.stories.tsx +81 -0
  123. package/src/vaults/lib/withdraw.ts +224 -0
  124. package/src/common/const.ts +0 -5
  125. package/src/common/types/internalTypes.ts +0 -10
  126. package/src/common/types/types.ts +0 -57
  127. package/src/common/utils/isValidChain.ts +0 -5
  128. package/src/provider/Provider.ts +0 -171
  129. package/src/provider/ReadProvider.ts +0 -126
  130. package/src/provider/index.ts +0 -2
  131. package/src/provider/rpcUrlConfig.ts +0 -19
  132. package/src/provider/types.ts +0 -58
  133. package/src/provider/utils/getMaxPriorityFeePerGas.ts +0 -25
  134. package/src/sdk/getLBTCExchangeRate/getLBTCExchangeRate.ts +0 -65
  135. package/src/sdk/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +0 -85
  136. package/src/sdk/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +0 -86
  137. package/src/sdk/internalTypes.ts +0 -18
  138. package/src/sdk/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +0 -86
  139. package/src/sdk/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +0 -116
  140. package/src/sdk/utils/getChainIdByName.ts +0 -48
  141. package/src/sdk/utils/getChainNameById.ts +0 -41
  142. package/src/stories/const.ts +0 -1
  143. package/src/stories/hooks/useConnect.ts +0 -47
  144. package/src/stories/utils/connectInjectedWallet.ts +0 -12
  145. package/src/stories/utils/fromCamelCase.ts +0 -16
  146. package/src/stories/utils/getMetaTitle.ts +0 -7
  147. package/src/stories/utils/getWalletInfo.ts +0 -31
  148. package/src/web3Sdk/abi/BASCULE.json +0 -850
  149. package/src/web3Sdk/abi/IERC20.json +0 -222
  150. package/src/web3Sdk/abi/LBTC.json +0 -1761
  151. package/src/web3Sdk/abi/STAKE_AND_BAKE.json +0 -15
  152. package/src/web3Sdk/abi/index.ts +0 -6
  153. package/src/web3Sdk/approveLBTC/approveLBTC.stories.tsx +0 -77
  154. package/src/web3Sdk/approveLBTC/approveLBTC.ts +0 -48
  155. package/src/web3Sdk/claimLBTC/claimLBTC.ts +0 -86
  156. package/src/web3Sdk/const.ts +0 -2
  157. package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +0 -89
  158. package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.ts +0 -75
  159. package/src/web3Sdk/getBasculeDepositStatus/utils/const.ts +0 -8
  160. package/src/web3Sdk/getBasculeDepositStatus/utils/throwBasculeDepositStatusError.ts +0 -21
  161. package/src/web3Sdk/getLBTCMintingFee/getLBTCMintingFee.tsx +0 -41
  162. package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +0 -60
  163. package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.ts +0 -26
  164. package/src/web3Sdk/getPermitNonce/getPermitNonce.ts +0 -47
  165. package/src/web3Sdk/getShareValue/getShareValue.ts +0 -58
  166. package/src/web3Sdk/getStakeAndBakeFee/getStakeAndBakeFee.tsx +0 -48
  167. package/src/web3Sdk/lbtcAddressConfig.ts +0 -96
  168. package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +0 -23
  169. package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +0 -97
  170. package/src/web3Sdk/signNetworkFee/signNetworkFee.stories.tsx +0 -91
  171. package/src/web3Sdk/signNetworkFee/signNetworkFee.ts +0 -92
  172. package/src/web3Sdk/signStakeAndBake/contracts.ts +0 -80
  173. package/src/web3Sdk/signStakeAndBake/getTypedData.ts +0 -78
  174. package/src/web3Sdk/signStakeAndBake/index.ts +0 -3
  175. package/src/web3Sdk/signStakeAndBake/signStakeAndBake.ts +0 -105
  176. package/src/web3Sdk/signStakeAndBake/utils.ts +0 -23
  177. package/src/web3Sdk/types.ts +0 -16
  178. package/src/web3Sdk/unstakeLBTC/unstakeLBTC.stories.tsx +0 -77
  179. package/src/web3Sdk/unstakeLBTC/unstakeLBTC.ts +0 -51
  180. package/src/web3Sdk/utils/chainIdToEnv.ts +0 -12
  181. package/src/web3Sdk/utils/getBasculeTokenContract.ts +0 -21
  182. package/src/web3Sdk/utils/getGasMultiplier.ts +0 -20
  183. package/src/web3Sdk/utils/getLbtcTokenContract.ts +0 -36
  184. package/src/web3Sdk/utils/getRpcUrlConfigFromChain.ts +0 -34
  185. package/src/web3Sdk/utils/getTokenABI.ts +0 -12
  186. /package/src/{sdk → api-functions}/generateDepositBtcAddress/index.ts +0 -0
  187. /package/src/{sdk → api-functions}/getDepositBtcAddress/index.ts +0 -0
  188. /package/src/{sdk → api-functions}/getDepositsByAddress/index.ts +0 -0
  189. /package/src/{sdk → api-functions}/getLBTCExchangeRate/index.ts +0 -0
  190. /package/src/{sdk → api-functions}/getNetworkFeeSignature/index.ts +0 -0
  191. /package/src/{sdk → api-functions}/getPointsByAddress/index.ts +0 -0
  192. /package/src/{sdk → api-functions}/getUnstakesByAddress/index.ts +0 -0
  193. /package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/index.ts +0 -0
  194. /package/src/{sdk → api-functions}/setReferral/index.ts +0 -0
  195. /package/src/{sdk → api-functions}/storeNetworkFeeSignature/index.ts +0 -0
  196. /package/src/{sdk → api-functions}/storeStakeAndBakeSignature/index.ts +0 -0
  197. /package/src/{sdk/const.ts → common/constants.ts} +0 -0
  198. /package/src/{web3Sdk → contract-functions}/approveLBTC/index.ts +0 -0
  199. /package/src/{web3Sdk → contract-functions}/claimLBTC/index.ts +0 -0
  200. /package/src/{web3Sdk → contract-functions}/getBasculeDepositStatus/index.ts +0 -0
  201. /package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/index.ts +0 -0
  202. /package/src/{web3Sdk → contract-functions}/getLBTCTotalSupply/index.ts +0 -0
  203. /package/src/{web3Sdk → contract-functions}/getPermitNonce/index.ts +0 -0
  204. /package/src/{web3Sdk → contract-functions}/getShareValue/index.ts +0 -0
  205. /package/src/{web3Sdk → contract-functions}/getSharesByAddress/index.ts +0 -0
  206. /package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/index.ts +0 -0
  207. /package/src/{web3Sdk → contract-functions}/signLbtcDestionationAddr/index.ts +0 -0
  208. /package/src/{web3Sdk → contract-functions}/signNetworkFee/getTypedData.ts +0 -0
  209. /package/src/{web3Sdk → contract-functions}/signNetworkFee/index.ts +0 -0
  210. /package/src/{web3Sdk → contract-functions}/unstakeLBTC/index.ts +0 -0
  211. /package/src/{common/utils/getErrorMessage.ts → utils/err.ts} +0 -0
@@ -1,6 +1,6 @@
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 { CodeBlock } from '../../stories/components/CodeBlock';
6
6
  import useQuery from '../../stories/hooks/useQuery';
@@ -8,13 +8,14 @@ import {
8
8
  getStakeAndBakeFee,
9
9
  IGetStakeAndBakeFeeParams,
10
10
  } from './getStakeAndBakeFee';
11
- import BigNumber from 'bignumber.js';
12
- import { fromSatoshi } from '../../common/utils/convertSatoshi';
11
+ import { Vault } from '../../vaults';
12
+ import { functionType } from '../../stories/components/decorators';
13
13
 
14
14
  const meta = {
15
- title: 'Web3SDK/getStakeAndBakeFee',
15
+ title: 'read/getStakeAndBakeFee',
16
16
  component: StoryView,
17
17
  tags: ['autodocs'],
18
+ decorators: [functionType('read')],
18
19
  } satisfies Meta<typeof StoryView>;
19
20
 
20
21
  export default meta;
@@ -23,16 +24,12 @@ type Story = StoryObj<typeof meta>;
23
24
 
24
25
  export const WithParams: Story = {
25
26
  args: {
26
- chainId: OChainId.binanceSmartChain,
27
- rpcUrl: 'https://rpc.ankr.com/bsc',
28
- vaultAddress: '0xC8bbF6153D7Ba105f1399D992ebd32B0541996ef',
27
+ vaultKey: Vault.Veda,
28
+ chainId: ChainId.ethereum,
29
29
  },
30
30
  };
31
31
 
32
- type GetStakeAndBakeFeeProps = Pick<
33
- IGetStakeAndBakeFeeParams,
34
- 'chainId' | 'rpcUrl' | 'vaultAddress'
35
- >;
32
+ type GetStakeAndBakeFeeProps = IGetStakeAndBakeFeeParams;
36
33
 
37
34
  export function StoryView(props: GetStakeAndBakeFeeProps) {
38
35
  const request = async () => {
@@ -43,20 +40,23 @@ export function StoryView(props: GetStakeAndBakeFeeProps) {
43
40
 
44
41
  const { data, error, isLoading, refetch } = useQuery(request, [], false);
45
42
 
46
- const value = new BigNumber(fromSatoshi(data || 0)).toString();
43
+ const value = data?.toFixed();
47
44
 
48
45
  return (
49
46
  <div>
50
- <Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
51
- Get Stake and Bake Fee
52
- </Button>
47
+ <Button
48
+ onClick={refetch}
49
+ disabled={isLoading}
50
+ isLoading={isLoading}
51
+ actionName={getStakeAndBakeFee.name}
52
+ />
53
53
 
54
54
  <CodeBlock text={error || data?.toString()} />
55
55
 
56
56
  {data && (
57
57
  <div className="mt-4 p-4 border rounded">
58
58
  <h3 className="text-lg font-bold mb-2">Fee Details</h3>
59
- <p>Stake and Bak Fee: {value} LBTC</p>
59
+ <p>Stake and Bake Fee: {value} LBTC</p>
60
60
  </div>
61
61
  )}
62
62
  </div>
@@ -0,0 +1,61 @@
1
+ import { getErrorMessage } from '../../utils/err';
2
+ import { CommonParameters } from '../../common/parameters';
3
+ import { isVedaVaultStakeAndBakeChain, Vault, VAULTS } from '../../vaults';
4
+ import { makePublicClient } from '../../clients/public-client';
5
+ import { getContract } from 'viem';
6
+ import { fromSatoshi } from '../../utils/satoshi';
7
+ import BigNumber from 'bignumber.js';
8
+
9
+ export interface IGetStakeAndBakeFeeParams
10
+ extends Omit<CommonParameters, 'env'> {
11
+ /**
12
+ * The DeFi vault identifier.
13
+ */
14
+ vaultKey?: Vault;
15
+ }
16
+
17
+ /**
18
+ * Get Stake and bake fee.
19
+ *
20
+ * @param {IGetStakeAndBakeFeeParams} 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 Stake and bake fee amount.
26
+ */
27
+ export async function getStakeAndBakeFee({
28
+ vaultKey = Vault.Veda,
29
+ chainId,
30
+ rpcUrl,
31
+ }: IGetStakeAndBakeFeeParams): Promise<BigNumber> {
32
+ const vault = VAULTS[vaultKey];
33
+ if (!vault) {
34
+ throw new Error(`Unknown vault key: ${vaultKey}`);
35
+ }
36
+
37
+ if (!isVedaVaultStakeAndBakeChain(chainId)) {
38
+ throw new Error(
39
+ `Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.stakeAndBakeChains.join(', ')}`,
40
+ );
41
+ }
42
+
43
+ const spender = vault.spenderContracts[chainId];
44
+ if (!spender) {
45
+ throw new Error('Could not retrieve the stake and bake contract.');
46
+ }
47
+
48
+ try {
49
+ const client = makePublicClient({ chainId, rpcUrl });
50
+ const spenderContract = getContract({
51
+ abi: spender.abi,
52
+ address: spender.address,
53
+ client,
54
+ });
55
+ const fee = await spenderContract.read.getStakeAndBakeFee();
56
+ return fromSatoshi(String(fee));
57
+ } catch (error) {
58
+ const errorMessage = getErrorMessage(error);
59
+ throw new Error(errorMessage);
60
+ }
61
+ }
@@ -1,17 +1,18 @@
1
- export * from './approveLBTC';
2
- export * from './claimLBTC';
1
+ // READ functions:
3
2
  export * from './getBasculeDepositStatus';
4
3
  export * from './getLBTCMintingFee';
5
4
  export * from './getLBTCTotalSupply';
6
5
  export * from './getPermitNonce';
7
- export * from './lbtcAddressConfig';
6
+ export * from './getStakeAndBakeFee';
7
+
8
+ // WRITE functions:
9
+ export * from './approveLBTC';
10
+ export * from './claimLBTC';
8
11
  export * from './signLbtcDestionationAddr';
9
12
  export * from './signNetworkFee';
10
13
  export * from './signStakeAndBake';
11
- export * from './types';
12
14
  export * from './unstakeLBTC';
13
- export * from './getBasculeDepositStatus';
14
- export * from './getLBTCTotalSupply';
15
- export * from './getStakeAndBakeFee';
15
+
16
+ // VAULT READ functions:
16
17
  export * from './getShareValue';
17
18
  export * from './getSharesByAddress';
@@ -0,0 +1,32 @@
1
+ import { CommonWriteParameters } from '../../common/parameters';
2
+ import { makeWalletClient } from '../../clients/wallet-client';
3
+
4
+ export type SignLbtcDestinationAddrParams = Omit<
5
+ CommonWriteParameters,
6
+ 'env' | 'rpcUrl'
7
+ >;
8
+
9
+ /**
10
+ * Signs the destination address for the LBTC in active chain
11
+ * in the current account. Signing is necessary for the
12
+ * generation of the deposit address.
13
+ *
14
+ * @param {SignLbtcDestinationAddrParams} parameters - The parameters.
15
+ * @param {Address} parameters.account - The EVM account address.
16
+ * @param {ChainId} parameters.chainId - The chain id.
17
+ * @param {EIP1193Provider} parameters.provider - The EIP1193 provider.
18
+ *
19
+ * @returns {Promise<string>} The signature of the message.
20
+ */
21
+ export async function signLbtcDestinationAddr({
22
+ account,
23
+ chainId,
24
+ provider,
25
+ }: SignLbtcDestinationAddrParams): Promise<string> {
26
+ const walletClient = makeWalletClient({ chainId, provider });
27
+
28
+ const message = `destination chain id is ${chainId}`;
29
+ const signed = await walletClient.signMessage({ account, message });
30
+
31
+ return signed;
32
+ }
@@ -0,0 +1,63 @@
1
+ import type { Meta } from '@storybook/react';
2
+ import { Button } from '../../stories/components/Button';
3
+ import { CodeBlock } from '../../stories/components/CodeBlock';
4
+ import {
5
+ canPerformAction,
6
+ useConnection,
7
+ } from '../../stories/hooks/useConnection';
8
+ import useQuery from '../../stories/hooks/useQuery';
9
+ import { signLbtcDestinationAddr } from './signLbtcDestinationAddr';
10
+ import { ConnectButton } from '../../stories/components/ConnectButton';
11
+ import {
12
+ functionType,
13
+ wagmiDecorator,
14
+ } from '../../stories/components/decorators';
15
+
16
+ const meta = {
17
+ title: 'write/signLbtcDestionationAddr',
18
+ component: StoryView,
19
+ tags: ['autodocs'],
20
+ decorators: [wagmiDecorator, functionType('write')],
21
+ } satisfies Meta<typeof StoryView>;
22
+
23
+ export default meta;
24
+
25
+ export function StoryView() {
26
+ const connection = useConnection();
27
+
28
+ const request = async () => {
29
+ if (!canPerformAction(connection)) {
30
+ return;
31
+ }
32
+
33
+ return signLbtcDestinationAddr({
34
+ account: connection.account.address,
35
+ chainId: connection.account.chainId,
36
+ provider: connection.provider,
37
+ });
38
+ };
39
+
40
+ const { data, error, isLoading, refetch } = useQuery(request, [], false);
41
+
42
+ return (
43
+ <>
44
+ <p>
45
+ This method is used to get the signature of the Liquid BTC destination
46
+ address. The signature is used for generating the deposit address.
47
+ </p>
48
+
49
+ <div className="mb-4">
50
+ <ConnectButton />
51
+ </div>
52
+
53
+ <Button
54
+ onClick={refetch}
55
+ disabled={isLoading || !connection.account.address}
56
+ isLoading={isLoading}
57
+ actionName={signLbtcDestinationAddr.name}
58
+ />
59
+
60
+ <CodeBlock text={error || data} />
61
+ </>
62
+ );
63
+ }
@@ -0,0 +1,91 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { Button } from '../../stories/components/Button';
3
+ import { CodeBlock } from '../../stories/components/CodeBlock';
4
+ import {
5
+ canPerformAction,
6
+ useConnection,
7
+ } from '../../stories/hooks/useConnection';
8
+ import useQuery from '../../stories/hooks/useQuery';
9
+ import { ISignNetworkFeeParams, signNetworkFee } from './signNetworkFee';
10
+ import { DAY, now, toUnix } from '../../utils/time';
11
+ import { ConnectButton } from '../../stories/components/ConnectButton';
12
+ import {
13
+ functionType,
14
+ wagmiDecorator,
15
+ } from '../../stories/components/decorators';
16
+
17
+ const meta = {
18
+ title: 'write/signNetworkFee',
19
+ component: StoryView,
20
+ tags: ['autodocs'],
21
+ decorators: [wagmiDecorator, functionType('write')],
22
+ } satisfies Meta<typeof StoryView>;
23
+
24
+ export default meta;
25
+
26
+ type Story = StoryObj<typeof meta>;
27
+
28
+ export const WithParams: Story = {
29
+ args: {
30
+ fee: '1100',
31
+ expiry: toUnix(now() + DAY),
32
+ },
33
+ };
34
+
35
+ type SignNetworkFeeProps = Omit<
36
+ ISignNetworkFeeParams,
37
+ 'account' | 'chainId' | 'provider'
38
+ >;
39
+
40
+ export function StoryView(props: SignNetworkFeeProps) {
41
+ const connection = useConnection();
42
+
43
+ const request = async () => {
44
+ if (!canPerformAction(connection)) {
45
+ return;
46
+ }
47
+
48
+ return signNetworkFee({
49
+ ...props,
50
+
51
+ account: connection.account.address,
52
+ chainId: connection.account.chainId,
53
+ provider: connection.provider,
54
+ });
55
+ };
56
+
57
+ const { data, error, isLoading, refetch } = useQuery(request, [], false);
58
+
59
+ return (
60
+ <>
61
+ <p>
62
+ This method is used to get the signature of the Liquid BTC destination
63
+ address. The signature is used for auto-mint feature.
64
+ </p>
65
+
66
+ <div className="mb-4">
67
+ <ConnectButton />
68
+ </div>
69
+
70
+ <Button
71
+ onClick={refetch}
72
+ disabled={isLoading || !connection.account.address}
73
+ isLoading={isLoading}
74
+ actionName={signNetworkFee.name}
75
+ />
76
+
77
+ <div
78
+ style={{
79
+ padding: '20px 0 0',
80
+ fontFamily: 'monospace',
81
+ fontSize: '0.8em',
82
+ }}
83
+ >
84
+ <span style={{ fontWeight: '800' }}>24 hours from now:</span>{' '}
85
+ {toUnix(now() + DAY)}
86
+ </div>
87
+
88
+ <CodeBlock text={error || data} />
89
+ </>
90
+ );
91
+ }
@@ -0,0 +1,98 @@
1
+ import BigNumber from 'bignumber.js';
2
+ import { makeWalletClient } from '../../clients/wallet-client';
3
+ import { CommonWriteParameters } from '../../common/parameters';
4
+ import { getLBTCContractInfo } from '../../tokens/lbtc-contract';
5
+ import { DAY, now, toUnix } from '../../utils/time';
6
+ import { Hex } from 'viem';
7
+
8
+ export interface ISignNetworkFeeParams extends CommonWriteParameters {
9
+ /**
10
+ * The authorized fee amount.
11
+ * Recommended amount is the same as retuned from `getLBTCMintingFee`.
12
+ */
13
+ fee: BigNumber.Value;
14
+ /**
15
+ * The expiration time of the signature.
16
+ * Defaults to 24h from now.
17
+ */
18
+ expiry?: number;
19
+ }
20
+
21
+ export interface ISignNetworkFeeResponse {
22
+ /**
23
+ * The signature.
24
+ */
25
+ signature: Hex;
26
+ /**
27
+ * The typed data (JSON string) used for generating the returned signature.
28
+ */
29
+ typedData: string;
30
+ }
31
+
32
+ /**
33
+ * Signs the network fee transaction in the current account.
34
+ * Signing is necessary for the auto-mint.
35
+ *
36
+ * @param {ISignNetworkFeeParams} parameters - The parameters for signing network fee
37
+ * @param {BigNumber.Value} parameters.fee - The fee amount (in satoshis).
38
+ * @param {number} parameters.expiry = The optional expiration UNIX time of the signature.
39
+ * @param {Address} parameters.account - The EVM account address.
40
+ * @param {ChainId} parameters.chainId - The chain id.
41
+ * @param {EIP1193Provider} parameters.provider - The EIP1193 provider.
42
+ * @param {string} parameters.rpcUrl - The optional rpc url.
43
+ *
44
+ * @returns {Promise<ISignNetworkFeeResponse>} A promise that resolves to the signature and typed data
45
+ */
46
+ export async function signNetworkFee({
47
+ fee,
48
+ expiry = toUnix(now() + DAY),
49
+ account,
50
+ chainId,
51
+ provider,
52
+ env,
53
+ }: ISignNetworkFeeParams): Promise<ISignNetworkFeeResponse> {
54
+ const lbtcContract = getLBTCContractInfo(chainId, env);
55
+ const walletClient = makeWalletClient({
56
+ chainId,
57
+ provider,
58
+ });
59
+
60
+ type TypedData = Parameters<typeof walletClient.signTypedData>[0];
61
+ const typedData: TypedData = {
62
+ account,
63
+ domain: {
64
+ name: 'Lombard Staked Bitcoin',
65
+ version: '1',
66
+ chainId,
67
+ verifyingContract: lbtcContract.address,
68
+ },
69
+ message: {
70
+ chainId,
71
+ fee: BigInt(BigNumber(fee).toFixed()),
72
+ expiry,
73
+ },
74
+ primaryType: 'feeApproval',
75
+ types: {
76
+ EIP712Domain: [
77
+ { name: 'name', type: 'string' },
78
+ { name: 'version', type: 'string' },
79
+ { name: 'chainId', type: 'uint256' },
80
+ { name: 'verifyingContract', type: 'address' },
81
+ ],
82
+ feeApproval: [
83
+ { name: 'chainId', type: 'uint256' },
84
+ { name: 'fee', type: 'uint256' },
85
+ { name: 'expiry', type: 'uint256' },
86
+ ],
87
+ },
88
+ };
89
+
90
+ const signature = await walletClient.signTypedData(typedData);
91
+
92
+ return {
93
+ signature: signature,
94
+ typedData: JSON.stringify(typedData, (_, v) =>
95
+ typeof v === 'bigint' ? v.toString() : v,
96
+ ),
97
+ };
98
+ }
@@ -0,0 +1 @@
1
+ export * from './signStakeAndBake';
@@ -1,19 +1,25 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
-
3
2
  import { Button } from '../../stories/components/Button';
4
3
  import { CodeBlock } from '../../stories/components/CodeBlock';
5
- import { useConnect } from '../../stories/hooks/useConnect';
4
+ import {
5
+ canPerformAction,
6
+ useConnection,
7
+ } from '../../stories/hooks/useConnection';
6
8
  import useQuery from '../../stories/hooks/useQuery';
7
- import { fromCamelCase } from '../../stories/utils/fromCamelCase';
8
9
  import { signStakeAndBake, ISignStakeAndBakeParams } from './signStakeAndBake';
10
+ import { ConnectButton } from '../../stories/components/ConnectButton';
11
+ import {
12
+ functionType,
13
+ wagmiDecorator,
14
+ } from '../../stories/components/decorators';
9
15
 
10
16
  const { name } = signStakeAndBake;
11
- const nameWithWhitespaces = fromCamelCase(name);
12
17
 
13
18
  const meta = {
14
- title: 'Web3SDK/signStakeAndBake',
19
+ title: 'write/signStakeAndBake',
15
20
  component: StoryView,
16
21
  tags: ['autodocs'],
22
+ decorators: [wagmiDecorator, functionType('write')],
17
23
  } satisfies Meta<typeof StoryView>;
18
24
 
19
25
  export default meta;
@@ -24,72 +30,53 @@ export const WithParams: Story = {
24
30
  args: {
25
31
  value: '20000',
26
32
  expiry: 3600,
27
- vaultKey: 'veda',
28
33
  },
29
34
  };
30
35
 
31
- type SignStakeAndBakeParams = Pick<
36
+ type SignStakeAndBakeParams = Omit<
32
37
  ISignStakeAndBakeParams,
33
- 'value' | 'expiry' | 'vaultKey'
38
+ 'account' | 'chainId' | 'provider'
34
39
  >;
35
40
 
36
41
  export function StoryView(props: SignStakeAndBakeParams) {
37
- const {
38
- data: connectData,
39
- error: connectError,
40
- isLoading: isConnectLoading,
41
- connect,
42
- } = useConnect();
42
+ const connection = useConnection();
43
43
 
44
44
  const request = async () => {
45
- if (!connectData || !connectData.provider) {
45
+ if (!canPerformAction(connection)) {
46
+ alert('Not connected.');
46
47
  return;
47
48
  }
48
49
 
49
50
  return signStakeAndBake({
50
- provider: connectData.provider,
51
- address: connectData.account,
52
- chainId: connectData.chainId,
53
-
54
51
  value: props.value,
55
52
  expiry: props.expiry,
56
- vaultKey: props.vaultKey,
53
+
54
+ account: connection.account.address,
55
+ chainId: connection.account.chainId,
56
+ provider: connection.provider,
57
57
  });
58
58
  };
59
59
 
60
60
  const { data, error, isLoading, refetch } = useQuery(request, [], false);
61
61
 
62
- const formattedConnectData = connectData && {
63
- account: connectData.account,
64
- chainId: connectData.chainId,
65
- };
66
-
67
62
  return (
68
63
  <>
69
64
  <p>
70
- This method is used to sign a permit for stake and bake operations. The
71
- signature is used to approve spending of tokens.
65
+ This function generates a signature that allows Lombard to claim
66
+ specified amount of BTC deposited to the personal account and deposit
67
+ that amount automatically to the DeFi vault.
72
68
  </p>
73
69
 
74
70
  <div className="mb-4">
75
- <Button
76
- onClick={connect}
77
- disabled={isConnectLoading}
78
- isLoading={isConnectLoading}
79
- >
80
- Connect
81
- </Button>
82
-
83
- <CodeBlock text={connectError || formattedConnectData} />
71
+ <ConnectButton />
84
72
  </div>
85
73
 
86
74
  <Button
87
75
  onClick={refetch}
88
- disabled={isLoading || !connectData}
76
+ disabled={isLoading || !connection.account.address}
89
77
  isLoading={isLoading}
90
- >
91
- {nameWithWhitespaces}
92
- </Button>
78
+ actionName={signStakeAndBake.name}
79
+ />
93
80
 
94
81
  <CodeBlock
95
82
  text={