@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,3 +1,5 @@
1
+ import { Address, Hash } from 'viem';
2
+ import { ChainId } from '../../common/chains';
1
3
  import {
2
4
  isVedaVaultChain,
3
5
  NETWORK_TO_VEDA_VAULT_CHAIN_MAP,
@@ -5,24 +7,25 @@ import {
5
7
  VAULTS,
6
8
  VEDA_VAULT_CHAIN_TO_NETWORK_MAP,
7
9
  VedaVaultChain,
8
- } from "..";
9
- import axios from "axios";
10
- import BigNumber from "bignumber.js";
11
- import { ensureHex } from "../../utils/hex";
12
- import { orderBy } from "../../utils/array";
13
- import { TChainId } from "../../common/types/types";
14
- import { fromSatoshi } from "../../common/utils/convertSatoshi";
15
-
16
- type Address = `0x${string}`;
17
- type Hash = `0x${string}`;
10
+ } from '..';
11
+ import axios from 'axios';
12
+ import BigNumber from 'bignumber.js';
13
+ import {
14
+ fromBaseDenomination,
15
+ getAssetInfo,
16
+ TokenInfo,
17
+ } from '../../tokens/tokens';
18
+ import { ensureHex } from '../../utils/hex';
19
+ import { orderBy, unique } from '../../utils/array';
18
20
 
19
21
  const DEPOSITS_URL =
20
- "https://api.sevenseas.capital/deposits/{network}/{vault}/{account}";
22
+ 'https://api.sevenseas.capital/deposits/{network}/{vault}/{account}';
21
23
 
22
24
  export type GetVaultDepositsParameters = {
23
25
  account: Address;
24
- chainId: TChainId;
26
+ chainId: ChainId;
25
27
  vaultKey?: Vault;
28
+ rpcUrl?: string;
26
29
  };
27
30
 
28
31
  type ResponseEntry = {
@@ -48,7 +51,7 @@ export type VaultDeposit = {
48
51
  /** The amount of shares received */
49
52
  shareAmount: BigNumber;
50
53
  /** The deposit token */
51
- token?: string;
54
+ token?: Omit<TokenInfo, 'abi'>;
52
55
  };
53
56
 
54
57
  /**
@@ -57,6 +60,7 @@ export type VaultDeposit = {
57
60
  * @param parameters.account - The account address.
58
61
  * @param parameters.chainId - The chain id.
59
62
  * @param parameters.vaultKey - The optional vault identifier.
63
+ * @param parameters.rpcUrl - The optional RPC url.
60
64
  *
61
65
  * @returns {Promise<VaultDeposit[]>}
62
66
  */
@@ -64,6 +68,7 @@ export async function getVaultDeposits({
64
68
  account,
65
69
  chainId,
66
70
  vaultKey = Vault.Veda,
71
+ rpcUrl,
67
72
  }: GetVaultDepositsParameters) {
68
73
  const vault = VAULTS[vaultKey];
69
74
  if (!vault) {
@@ -72,21 +77,39 @@ export async function getVaultDeposits({
72
77
 
73
78
  if (!isVedaVaultChain(chainId)) {
74
79
  throw new Error(
75
- `Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.chains.join(", ")}`
80
+ `Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.chains.join(', ')}`,
76
81
  );
77
82
  }
78
83
 
79
84
  const network = VEDA_VAULT_CHAIN_TO_NETWORK_MAP[chainId];
80
- const url = DEPOSITS_URL.replace("{network}", network)
81
- .replace("{vault}", vault.vaultContract.address)
82
- .replace("{account}", account);
85
+ const url = DEPOSITS_URL.replace('{network}', network)
86
+ .replace('{vault}', vault.vaultContract.address)
87
+ .replace('{account}', account);
83
88
 
84
89
  const { data } = await axios.get<ResponseEntry[]>(url);
85
90
 
86
- const deposits = data.map((d) => {
87
- const token = ensureHex(d.deposit_asset);
88
- const amount = fromSatoshi(d.deposit_amount);
89
- const shareAmount = fromSatoshi(d.share_amount);
91
+ const depositAssetsAddresses = unique(
92
+ data.map(d => ensureHex(d.deposit_asset)),
93
+ );
94
+
95
+ const depositAssets: Record<Address, Omit<TokenInfo, 'abi'> | undefined> = {};
96
+ for (const asset of depositAssetsAddresses) {
97
+ const assetInfo = await getAssetInfo(asset, chainId, rpcUrl);
98
+ if (assetInfo) {
99
+ depositAssets[asset] = {
100
+ address: assetInfo.address,
101
+ decimals: assetInfo.decimals,
102
+ symbol: assetInfo.symbol,
103
+ };
104
+ } else {
105
+ depositAssets[asset] = undefined;
106
+ }
107
+ }
108
+
109
+ const deposits = data.map(d => {
110
+ const token = depositAssets[ensureHex(d.deposit_asset)];
111
+ const amount = fromBaseDenomination(d.deposit_amount, token?.decimals || 0);
112
+ const shareAmount = fromBaseDenomination(d.share_amount, vault.decimals);
90
113
 
91
114
  const vaultDeposit: VaultDeposit = {
92
115
  txHash: ensureHex(d.tx_hash),
@@ -100,5 +123,5 @@ export async function getVaultDeposits({
100
123
  return vaultDeposit;
101
124
  });
102
125
 
103
- return orderBy(deposits, (d) => d.blockNumber, "desc");
126
+ return orderBy(deposits, d => d.blockNumber, 'desc');
104
127
  }
@@ -2,14 +2,20 @@ import type { Meta, StoryObj } from '@storybook/react';
2
2
  import { Button } from '../../stories/components/Button';
3
3
  import { CodeBlock } from '../../stories/components/CodeBlock';
4
4
  import useQuery from '../../stories/hooks/useQuery';
5
+ import {
6
+ functionType,
7
+ wagmiDecorator,
8
+ } from '../../stories/components/decorators';
5
9
  import { Vault } from '..';
10
+ import { ErrorBlock } from '../../stories/components/error-block';
11
+ import { EXAMPLE_EVM_ADDRESS } from '../../stories/constants';
6
12
  import { getVaultPoints, GetVaultPointsParameters } from './get-vault-points';
7
- import { exampleEvmAddress } from '../../stories/const';
8
13
 
9
14
  const meta = {
10
15
  title: 'vault/getVaultPoints',
11
16
  component: StoryView,
12
17
  tags: ['autodocs'],
18
+ decorators: [wagmiDecorator, functionType('api-get')],
13
19
  } satisfies Meta<typeof StoryView>;
14
20
 
15
21
  export default meta;
@@ -18,7 +24,7 @@ type Story = StoryObj<typeof meta>;
18
24
 
19
25
  export const WithParams: Story = {
20
26
  args: {
21
- account: exampleEvmAddress,
27
+ account: EXAMPLE_EVM_ADDRESS,
22
28
  vaultKey: Vault.Veda,
23
29
  },
24
30
  };
@@ -42,11 +48,12 @@ export function StoryView(props: SignNetworkFeeProps) {
42
48
  onClick={refetch}
43
49
  disabled={isLoading}
44
50
  isLoading={isLoading}
45
- >
46
- {getVaultPoints.name}
47
- </Button>
51
+ actionName={getVaultPoints.name}
52
+ />
48
53
 
49
- <CodeBlock text={error || data} />
54
+ <ErrorBlock>{error}</ErrorBlock>
55
+
56
+ <CodeBlock text={data} />
50
57
  </>
51
58
  );
52
59
  }
@@ -1,14 +1,15 @@
1
- import { Vault, VAULTS } from "..";
2
- import axios from "axios";
3
-
4
- type Address = `0x${string}`;
1
+ import { Address } from 'viem';
2
+ import { Vault, VAULTS } from '..';
3
+ import axios from 'axios';
5
4
 
6
5
  export type GetVaultPointsParameters = {
6
+ /** The account address. */
7
7
  account: Address;
8
+ /** The optional vault identifier */
8
9
  vaultKey?: Vault;
9
10
  };
10
11
 
11
- const POINTS_URL = "https://api.veda.tech/points/user/{account}";
12
+ const POINTS_URL = 'https://api.veda.tech/points/user/{account}';
12
13
 
13
14
  type Response = {
14
15
  Response: {
@@ -25,6 +26,9 @@ type Response = {
25
26
  };
26
27
  };
27
28
 
29
+ /**
30
+ * Gets the points earned by specified account in the DeFi vault.
31
+ */
28
32
  export async function getVaultPoints({
29
33
  account,
30
34
  vaultKey = Vault.Veda,
@@ -34,21 +38,21 @@ export async function getVaultPoints({
34
38
  throw new Error(`Unknown vault key: ${vaultKey}`);
35
39
  }
36
40
 
37
- const url = POINTS_URL.replace("{account}", account);
41
+ const url = POINTS_URL.replace('{account}', account);
38
42
  const { data } = await axios.get<Response>(url, {
39
43
  headers: {
40
- "Access-Control-Allow-Origin": "*",
41
- "Content-Type": "application/json",
44
+ 'Access-Control-Allow-Origin': '*',
45
+ 'Content-Type': 'application/json',
42
46
  },
43
47
  });
44
48
 
45
49
  const vedaPointsBreakdown: Record<string, number> = {};
46
50
  const entries = Object.entries(data.Response);
47
51
  for (const [network, points] of entries) {
48
- if (network === "userTotalVedaPointsSum") continue;
52
+ if (network === 'userTotalVedaPointsSum') continue;
49
53
 
50
54
  const vaultPoints = Object.entries(points.vaults).find(
51
- ([v]) => v === vault.vaultContract.address
55
+ ([v]) => v === vault.vaultContract.address,
52
56
  );
53
57
  if (vaultPoints) {
54
58
  const [, data] = vaultPoints;
@@ -2,18 +2,24 @@ import type { Meta, StoryObj } from '@storybook/react';
2
2
  import { Button } from '../../stories/components/Button';
3
3
  import { CodeBlock } from '../../stories/components/CodeBlock';
4
4
  import useQuery from '../../stories/hooks/useQuery';
5
+ import {
6
+ functionType,
7
+ wagmiDecorator,
8
+ } from '../../stories/components/decorators';
5
9
  import { Vault } from '..';
10
+ import { ErrorBlock } from '../../stories/components/error-block';
11
+ import { EXAMPLE_EVM_ADDRESS } from '../../stories/constants';
12
+ import { ChainId } from '../../common/chains';
6
13
  import {
7
14
  getVaultWithdrawals,
8
15
  GetVaultWithdrawalsParameters,
9
16
  } from './get-vault-withdrawals';
10
- import { exampleEvmAddress } from '../../stories/const';
11
- import { OChainId } from '../../common/types/types';
12
17
 
13
18
  const meta = {
14
19
  title: 'vault/getVaultWithdrawals',
15
20
  component: StoryView,
16
21
  tags: ['autodocs'],
22
+ decorators: [wagmiDecorator, functionType('api-get')],
17
23
  } satisfies Meta<typeof StoryView>;
18
24
 
19
25
  export default meta;
@@ -22,8 +28,8 @@ type Story = StoryObj<typeof meta>;
22
28
 
23
29
  export const WithParams: Story = {
24
30
  args: {
25
- account: exampleEvmAddress,
26
- chainId: OChainId.ethereum,
31
+ account: EXAMPLE_EVM_ADDRESS,
32
+ chainId: ChainId.ethereum,
27
33
  vaultKey: Vault.Veda,
28
34
  },
29
35
  };
@@ -49,11 +55,12 @@ export function StoryView(props: SignNetworkFeeProps) {
49
55
  onClick={refetch}
50
56
  disabled={isLoading}
51
57
  isLoading={isLoading}
52
- >
53
- {getVaultWithdrawals.name}
54
- </Button>
58
+ actionName={getVaultWithdrawals.name}
59
+ />
60
+
61
+ <ErrorBlock>{error}</ErrorBlock>
55
62
 
56
- <CodeBlock text={error || data} />
63
+ <CodeBlock text={data} />
57
64
  </>
58
65
  );
59
66
  }
@@ -1,28 +1,30 @@
1
+ import { Address, Hash } from 'viem';
1
2
  import {
2
3
  isVedaVaultChain,
3
4
  Vault,
4
5
  VAULTS,
5
6
  VEDA_VAULT_CHAIN_TO_NETWORK_MAP,
6
- } from "..";
7
-
8
- import BigNumber from "bignumber.js";
9
- import axios from "axios";
10
- import { orderBy } from "../../utils/array";
11
- import { ensureHex } from "../../utils/hex";
12
- import { TChainId } from "../../common/types/types";
13
- import { fromSatoshi } from "../../common/utils/convertSatoshi";
14
-
15
- type Address = `0x${string}`;
16
- type Hash = `0x${string}`;
7
+ } from '..';
8
+ import { ChainId } from '../../common/chains';
9
+ import {
10
+ fromBaseDenomination,
11
+ getAssetInfo,
12
+ TokenInfo,
13
+ } from '../../tokens/tokens';
14
+ import BigNumber from 'bignumber.js';
15
+ import axios from 'axios';
16
+ import { orderBy, unique } from '../../utils/array';
17
+ import { ensureHex } from '../../utils/hex';
17
18
 
18
19
  export type GetVaultWithdrawalsParameters = {
19
20
  account: Address;
20
- chainId: TChainId;
21
+ chainId: ChainId;
21
22
  vaultKey?: Vault;
23
+ rpcUrl?: string;
22
24
  };
23
25
 
24
26
  export type VaultWithdrawal = {
25
- token?: string;
27
+ token?: Omit<TokenInfo, 'abi'>;
26
28
  /** The amount of shares withdrawn */
27
29
  shareAmount: BigNumber;
28
30
  /** The amount of funds withdrawn */
@@ -85,7 +87,7 @@ type Response = {
85
87
  };
86
88
 
87
89
  const WITHDRAWALS_URL =
88
- "https://api.sevenseas.capital/withdrawRequests/{network}/{vault}/{account}?historical=true";
90
+ 'https://api.sevenseas.capital/withdrawRequests/{network}/{vault}/{account}?historical=true';
89
91
 
90
92
  /**
91
93
  * Retrieves the withdrawals made by specified address.
@@ -93,6 +95,7 @@ const WITHDRAWALS_URL =
93
95
  * @param parameters.account - The account address.
94
96
  * @param parameters.chainId - The chain id.
95
97
  * @param parameters.vaultKey - The optional vault identifier.
98
+ * @param parameters.rpcUrl - The optional RPC url.
96
99
  *
97
100
  * @returns {Promise<VaultWithdrawals>}
98
101
  */
@@ -100,6 +103,7 @@ export async function getVaultWithdrawals({
100
103
  account,
101
104
  chainId,
102
105
  vaultKey = Vault.Veda,
106
+ rpcUrl,
103
107
  }: GetVaultWithdrawalsParameters) {
104
108
  const vault = VAULTS[vaultKey];
105
109
  if (!vault) {
@@ -108,84 +112,114 @@ export async function getVaultWithdrawals({
108
112
 
109
113
  if (!isVedaVaultChain(chainId)) {
110
114
  throw new Error(
111
- `Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.chains.join(", ")}`
115
+ `Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.chains.join(', ')}`,
112
116
  );
113
117
  }
114
118
 
115
119
  const network = VEDA_VAULT_CHAIN_TO_NETWORK_MAP[chainId];
116
- const url = WITHDRAWALS_URL.replace("{network}", network)
117
- .replace("{vault}", vault.vaultContract.address)
118
- .replace("{account}", account);
120
+ const url = WITHDRAWALS_URL.replace('{network}', network)
121
+ .replace('{vault}', vault.vaultContract.address)
122
+ .replace('{account}', account);
119
123
 
120
124
  const { data } = await axios.get<Response>(url);
121
125
 
122
- const cancelled = data.Response.cancelled_requests.map((w) => {
123
- const token = ensureHex(w.wantToken);
126
+ const withdrawAssetsAddresses = unique([
127
+ ...data.Response.cancelled_requests.map(a => ensureHex(a.wantToken)),
128
+ ...data.Response.expired_requests.map(a => ensureHex(a.wantToken)),
129
+ ...data.Response.fulfilled_requests.map(a =>
130
+ ensureHex(a.Request.wantToken),
131
+ ),
132
+ ...data.Response.open_requests.map(a => ensureHex(a.wantToken)),
133
+ ]);
134
+
135
+ const withdrawAssets: Record<Address, Omit<TokenInfo, 'abi'> | undefined> =
136
+ {};
137
+ for (const asset of withdrawAssetsAddresses) {
138
+ const assetInfo = await getAssetInfo(asset, chainId, rpcUrl);
139
+ if (assetInfo) {
140
+ withdrawAssets[asset] = {
141
+ address: assetInfo.address,
142
+ decimals: assetInfo.decimals,
143
+ symbol: assetInfo.symbol,
144
+ };
145
+ } else {
146
+ withdrawAssets[asset] = undefined;
147
+ }
148
+ }
149
+
150
+ const cancelled = data.Response.cancelled_requests.map(w => {
151
+ const token = withdrawAssets[ensureHex(w.wantToken)];
124
152
  const withdrawal: VaultWithdrawal = {
125
153
  amount: undefined,
126
154
  blockNumber: w.blockNumber,
127
155
  deadline: w.deadline,
128
- shareAmount: fromSatoshi(w.amount),
156
+ shareAmount: fromBaseDenomination(w.amount, vault.decimals),
129
157
  timestamp: w.timestamp,
130
158
  txHash: ensureHex(w.transactionHash),
131
159
  token,
132
160
  };
133
161
  return withdrawal;
134
162
  });
135
- const expired = data.Response.expired_requests.map((w) => {
136
- const token = ensureHex(w.wantToken);
163
+ const expired = data.Response.expired_requests.map(w => {
164
+ const token = withdrawAssets[ensureHex(w.wantToken)];
137
165
  const withdrawal: VaultWithdrawal = {
138
166
  amount: undefined,
139
167
  blockNumber: w.blockNumber,
140
168
  deadline: w.deadline,
141
- shareAmount: fromSatoshi(w.amount),
169
+ shareAmount: fromBaseDenomination(w.amount, vault.decimals),
142
170
  timestamp: w.timestamp,
143
171
  txHash: ensureHex(w.transactionHash),
144
172
  token,
145
173
  };
146
174
  return withdrawal;
147
175
  });
148
- const fulfilled = data.Response.fulfilled_requests.map((w) => {
149
- const token = ensureHex(w.Request.wantToken);
176
+ const fulfilled = data.Response.fulfilled_requests.map(w => {
177
+ const token = withdrawAssets[ensureHex(w.Request.wantToken)];
150
178
  const withdrawal: VaultWithdrawal = {
151
- amount: fromSatoshi(w.Fulfillment.wantAmountReceived),
179
+ amount: fromBaseDenomination(
180
+ w.Fulfillment.wantAmountReceived,
181
+ token?.decimals || 0,
182
+ ),
152
183
  blockNumber: w.Request.blockNumber,
153
184
  deadline: w.Request.deadline,
154
- shareAmount: fromSatoshi(w.Fulfillment.offerAmountSpent),
185
+ shareAmount: fromBaseDenomination(
186
+ w.Fulfillment.offerAmountSpent,
187
+ vault.decimals,
188
+ ),
155
189
  timestamp: w.Request.timestamp,
156
190
  txHash: ensureHex(w.Request.transactionHash),
157
191
  token,
158
192
  fulfilledBlockNumber: w.Fulfillment.blockNumber,
159
193
  fulfilledTimestamp: w.Fulfillment.timestamp,
160
194
  fulfilledTxHash: ensureHex(w.Fulfillment.transactionHash),
161
- minPrice: fromSatoshi(w.Request.minPrice),
195
+ minPrice: fromBaseDenomination(w.Request.minPrice, token?.decimals || 0),
162
196
  };
163
197
  return withdrawal;
164
198
  });
165
- const open = data.Response.open_requests.map((w) => {
166
- const token = ensureHex(w.wantToken);
199
+ const open = data.Response.open_requests.map(w => {
200
+ const token = withdrawAssets[ensureHex(w.wantToken)];
167
201
  const withdrawal: VaultWithdrawal = {
168
202
  amount: undefined,
169
203
  blockNumber: w.blockNumber,
170
204
  deadline: w.deadline,
171
- shareAmount: fromSatoshi(w.amount),
205
+ shareAmount: fromBaseDenomination(w.amount, vault.decimals),
172
206
  timestamp: w.timestamp,
173
207
  txHash: ensureHex(w.transactionHash),
174
208
  token,
175
- minPrice: fromSatoshi(w.minPrice),
209
+ minPrice: fromBaseDenomination(w.minPrice, token?.decimals || 0),
176
210
  };
177
211
  return withdrawal;
178
212
  });
179
213
 
180
214
  const wihdrawals: VaultWithdrawals = {
181
- cancelled: orderBy(cancelled, (a) => a.timestamp, "desc"),
182
- expired: orderBy(expired, (a) => a.timestamp, "desc"),
215
+ cancelled: orderBy(cancelled, a => a.timestamp, 'desc'),
216
+ expired: orderBy(expired, a => a.timestamp, 'desc'),
183
217
  fulfilled: orderBy(
184
218
  fulfilled,
185
- (a) => a.fulfilledTimestamp || a.timestamp,
186
- "desc"
219
+ a => a.fulfilledTimestamp || a.timestamp,
220
+ 'desc',
187
221
  ),
188
- open: orderBy(open, (a) => a.timestamp, "desc"),
222
+ open: orderBy(open, a => a.timestamp, 'desc'),
189
223
  };
190
224
 
191
225
  return wihdrawals;
@@ -0,0 +1,81 @@
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 { ConnectButton } from '../../stories/components/ConnectButton';
10
+ import {
11
+ functionType,
12
+ wagmiDecorator,
13
+ } from '../../stories/components/decorators';
14
+ import { Vault } from '..';
15
+ import { ErrorBlock } from '../../stories/components/error-block';
16
+ import { queueWithdraw, QueueWithdrawParameters } from './withdraw';
17
+
18
+ const meta = {
19
+ title: 'vault/withdraw',
20
+ component: StoryView,
21
+ tags: ['autodocs'],
22
+ decorators: [wagmiDecorator, functionType('write')],
23
+ } satisfies Meta<typeof StoryView>;
24
+
25
+ export default meta;
26
+
27
+ type Story = StoryObj<typeof meta>;
28
+
29
+ export const WithParams: Story = {
30
+ args: {
31
+ vaultKey: Vault.Veda,
32
+ amount: '0.0001',
33
+ approve: true,
34
+ },
35
+ };
36
+
37
+ type SignNetworkFeeProps = Omit<
38
+ QueueWithdrawParameters,
39
+ 'account' | 'chainId' | 'provider'
40
+ >;
41
+
42
+ export function StoryView(props: SignNetworkFeeProps) {
43
+ const connection = useConnection();
44
+
45
+ const request = async () => {
46
+ if (!canPerformAction(connection)) {
47
+ return;
48
+ }
49
+
50
+ return queueWithdraw({
51
+ ...props,
52
+
53
+ account: connection.account.address,
54
+ chainId: connection.account.chainId,
55
+ provider: connection.provider,
56
+ });
57
+ };
58
+
59
+ const { data, error, isLoading, refetch } = useQuery(request, [], false);
60
+
61
+ return (
62
+ <>
63
+ <p>This method queues withdraw from the chosen DeFi vault.</p>
64
+
65
+ <div className="mb-4">
66
+ <ConnectButton />
67
+ </div>
68
+
69
+ <Button
70
+ onClick={refetch}
71
+ disabled={isLoading || !connection.account.address}
72
+ isLoading={isLoading}
73
+ actionName={queueWithdraw.name}
74
+ />
75
+
76
+ <ErrorBlock>{error}</ErrorBlock>
77
+
78
+ <CodeBlock text={data} />
79
+ </>
80
+ );
81
+ }