@lombard.finance/sdk 2.5.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +428 -399
- package/dist/ccip.cjs +2 -0
- package/dist/ccip.cjs.map +1 -0
- package/dist/ccip.js +147 -0
- package/dist/ccip.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +68 -8269
- package/dist/index.js.map +1 -1
- package/dist/index2.cjs +53 -0
- package/dist/index2.cjs.map +1 -0
- package/dist/index2.js +21672 -0
- package/dist/index2.js.map +1 -0
- package/package.json +5 -5
- package/src/{sdk → api-functions}/generateDepositBtcAddress/generateDepositBtcAddress.stories.tsx +15 -14
- package/src/{sdk → api-functions}/generateDepositBtcAddress/generateDepositBtcAddress.ts +18 -8
- package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddress.stories.tsx +15 -14
- package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddress.ts +16 -7
- package/src/{sdk → api-functions}/getDepositBtcAddress/getDepositBtcAddresses.stories.tsx +15 -14
- package/src/{sdk → api-functions}/getDepositsByAddress/getDepositsByAddress.stories.tsx +13 -12
- package/src/{sdk → api-functions}/getDepositsByAddress/getDepositsByAddress.ts +8 -8
- package/src/{sdk → api-functions}/getLBTCExchangeRate/getLBTCExchangeRate.stories.tsx +16 -10
- package/src/api-functions/getLBTCExchangeRate/getLBTCExchangeRate.ts +71 -0
- package/src/api-functions/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +56 -0
- package/src/{sdk → api-functions}/getNetworkFeeSignature/getNetworkFeeSignature.ts +11 -5
- package/src/{sdk → api-functions}/getPointsByAddress/getPointsByAddress.stories.tsx +14 -13
- package/src/{sdk → api-functions}/getPointsByAddress/getPointsByAddress.ts +7 -4
- package/src/{sdk → api-functions}/getUnstakesByAddress/getUnstakesByAddress.stories.tsx +14 -13
- package/src/{sdk → api-functions}/getUnstakesByAddress/getUnstakesByAddress.ts +14 -9
- package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +61 -0
- package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.ts +10 -6
- package/src/{sdk → api-functions}/index.ts +0 -3
- package/src/{sdk → api-functions}/setReferral/setReferral.ts +3 -3
- package/src/api-functions/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +56 -0
- package/src/{sdk → api-functions}/storeNetworkFeeSignature/storeNetworkFeeSignature.ts +9 -7
- package/src/api-functions/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +56 -0
- package/src/{sdk → api-functions}/storeStakeAndBakeSignature/storeStakeAndBakeSignature.ts +8 -6
- package/src/clients/public-client.ts +32 -0
- package/src/clients/rpc-url-config.ts +20 -0
- package/src/clients/wallet-client.ts +33 -0
- package/src/{sdk/apiConfig.ts → common/api-config.ts} +2 -2
- package/src/common/blockchain-identifier.ts +107 -0
- package/src/common/chains.ts +72 -0
- package/src/common/parameters.ts +51 -0
- package/src/contract-functions/approveLBTC/approveLBTC.stories.tsx +76 -0
- package/src/contract-functions/approveLBTC/approveLBTC.ts +64 -0
- package/src/{web3Sdk → contract-functions}/claimLBTC/claimLBTC.stories.tsx +22 -30
- package/src/contract-functions/claimLBTC/claimLBTC.ts +89 -0
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +50 -0
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +121 -0
- package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +15 -11
- package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +34 -0
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +49 -0
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +30 -0
- package/src/{web3Sdk → contract-functions}/getPermitNonce/getPermitNonce.stories.tsx +12 -22
- package/src/contract-functions/getPermitNonce/getPermitNonce.ts +39 -0
- package/src/{web3Sdk → contract-functions}/getShareValue/getShareValue.stories.tsx +11 -6
- package/src/contract-functions/getShareValue/getShareValue.ts +58 -0
- package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.stories.tsx +13 -8
- package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.ts +29 -28
- package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +16 -16
- package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +61 -0
- package/src/{web3Sdk → contract-functions}/index.ts +8 -7
- package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +32 -0
- package/src/contract-functions/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +63 -0
- package/src/contract-functions/signNetworkFee/signNetworkFee.stories.tsx +91 -0
- package/src/contract-functions/signNetworkFee/signNetworkFee.ts +98 -0
- package/src/contract-functions/signStakeAndBake/index.ts +1 -0
- package/src/{web3Sdk → contract-functions}/signStakeAndBake/signStakeAndBake.stories.tsx +27 -40
- package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +140 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +80 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +65 -0
- package/src/index.ts +35 -10
- package/src/rewards/index.ts +26 -0
- package/src/rewards/lib/claim-reward.stories.tsx +82 -0
- package/src/rewards/lib/claim-reward.ts +84 -0
- package/src/rewards/lib/get-reward-balances.stories.tsx +64 -0
- package/src/rewards/lib/get-reward-balances.ts +81 -0
- package/src/rewards/lib/get-reward-signing-data.stories.tsx +76 -0
- package/src/rewards/lib/get-reward-signing-data.ts +52 -0
- package/src/rewards/lib/get-reward-withdrawal-fee.stories.tsx +61 -0
- package/src/rewards/lib/get-reward-withdrawal-fee.ts +37 -0
- package/src/rewards/lib/get-reward-withdrawals.stories.tsx +60 -0
- package/src/rewards/lib/get-reward-withdrawals.ts +92 -0
- package/src/rewards/lib/reward-tokens.ts +7 -0
- package/src/stories/components/Button/Button.css +10 -0
- package/src/stories/components/Button/Button.tsx +15 -4
- package/src/stories/components/CodeBlock/CodeBlock.tsx +1 -0
- package/src/stories/components/ConnectButton/connect-button.tsx +100 -0
- package/src/stories/components/ConnectButton/index.ts +1 -0
- package/src/stories/components/decorators/function-type.tsx +63 -0
- package/src/stories/components/decorators/index.ts +2 -0
- package/src/stories/components/decorators/wagmi-decorator.tsx +79 -0
- package/src/stories/components/error-block.tsx +21 -0
- package/src/stories/constants.ts +3 -0
- package/src/stories/hooks/useConnection.ts +72 -0
- package/src/stories/hooks/useQuery.ts +2 -2
- package/src/tokens/abi/LBTC_ABI.json +1761 -0
- package/src/tokens/abi/LBTC_BASCULE_ABI.json +850 -0
- package/src/tokens/lbtc-addresses.ts +54 -0
- package/src/tokens/lbtc-contract.ts +89 -0
- package/src/tokens/tokens.ts +111 -0
- package/src/utils/env.ts +12 -0
- package/src/utils/hex.ts +2 -2
- package/src/utils/numbers.ts +5 -0
- package/src/{common/utils/convertSatoshi.ts → utils/satoshi.ts} +3 -3
- package/src/utils/time.ts +12 -0
- package/src/vaults/abi/VEDA_VAULT_BASE_ASSET_ABI.json +296 -0
- package/src/vaults/abi/VEDA_VAULT_BORING_WITHDRAW_QUEUE_ABI.json +502 -0
- package/src/vaults/abi/VEDA_VAULT_SPENDER_ABI.json +408 -0
- package/src/vaults/abi/VEDA_VAULT_TELLER_ABI.json +700 -0
- package/src/vaults/index.ts +144 -36
- package/src/vaults/lib/cancel-withdraw.stories.tsx +79 -0
- package/src/vaults/lib/deposit.stories.tsx +81 -0
- package/src/vaults/lib/deposit.ts +151 -0
- package/src/vaults/lib/get-vault-deposits.stories.tsx +15 -9
- package/src/vaults/lib/get-vault-deposits.ts +45 -22
- package/src/vaults/lib/get-vault-points.stories.tsx +13 -6
- package/src/vaults/lib/get-vault-points.ts +14 -10
- package/src/vaults/lib/get-vault-withdrawals.stories.tsx +15 -8
- package/src/vaults/lib/get-vault-withdrawals.ts +72 -38
- package/src/vaults/lib/withdraw.stories.tsx +81 -0
- package/src/vaults/lib/withdraw.ts +224 -0
- package/src/common/const.ts +0 -5
- package/src/common/types/internalTypes.ts +0 -10
- package/src/common/types/types.ts +0 -57
- package/src/common/utils/isValidChain.ts +0 -5
- package/src/provider/Provider.ts +0 -171
- package/src/provider/ReadProvider.ts +0 -126
- package/src/provider/index.ts +0 -2
- package/src/provider/rpcUrlConfig.ts +0 -19
- package/src/provider/types.ts +0 -58
- package/src/provider/utils/getMaxPriorityFeePerGas.ts +0 -25
- package/src/sdk/getLBTCExchangeRate/getLBTCExchangeRate.ts +0 -65
- package/src/sdk/getNetworkFeeSignature/getNetworkFeeSignature.stories.tsx +0 -85
- package/src/sdk/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +0 -86
- package/src/sdk/internalTypes.ts +0 -18
- package/src/sdk/storeNetworkFeeSignature/storeNetworkFeeSignature.stories.tsx +0 -86
- package/src/sdk/storeStakeAndBakeSignature/storeStakeAndBakeSignature.stories.tsx +0 -116
- package/src/sdk/utils/getChainIdByName.ts +0 -48
- package/src/sdk/utils/getChainNameById.ts +0 -41
- package/src/stories/const.ts +0 -1
- package/src/stories/hooks/useConnect.ts +0 -47
- package/src/stories/utils/connectInjectedWallet.ts +0 -12
- package/src/stories/utils/fromCamelCase.ts +0 -16
- package/src/stories/utils/getMetaTitle.ts +0 -7
- package/src/stories/utils/getWalletInfo.ts +0 -31
- package/src/web3Sdk/abi/BASCULE.json +0 -850
- package/src/web3Sdk/abi/IERC20.json +0 -222
- package/src/web3Sdk/abi/LBTC.json +0 -1761
- package/src/web3Sdk/abi/STAKE_AND_BAKE.json +0 -15
- package/src/web3Sdk/abi/index.ts +0 -6
- package/src/web3Sdk/approveLBTC/approveLBTC.stories.tsx +0 -77
- package/src/web3Sdk/approveLBTC/approveLBTC.ts +0 -48
- package/src/web3Sdk/claimLBTC/claimLBTC.ts +0 -86
- package/src/web3Sdk/const.ts +0 -2
- package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +0 -89
- package/src/web3Sdk/getBasculeDepositStatus/getBasculeDepositStatus.ts +0 -75
- package/src/web3Sdk/getBasculeDepositStatus/utils/const.ts +0 -8
- package/src/web3Sdk/getBasculeDepositStatus/utils/throwBasculeDepositStatusError.ts +0 -21
- package/src/web3Sdk/getLBTCMintingFee/getLBTCMintingFee.tsx +0 -41
- package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx +0 -60
- package/src/web3Sdk/getLBTCTotalSupply/getLBTCTotalSupply.ts +0 -26
- package/src/web3Sdk/getPermitNonce/getPermitNonce.ts +0 -47
- package/src/web3Sdk/getShareValue/getShareValue.ts +0 -58
- package/src/web3Sdk/getStakeAndBakeFee/getStakeAndBakeFee.tsx +0 -48
- package/src/web3Sdk/lbtcAddressConfig.ts +0 -96
- package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestinationAddr.ts +0 -23
- package/src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.stories.tsx +0 -97
- package/src/web3Sdk/signNetworkFee/signNetworkFee.stories.tsx +0 -91
- package/src/web3Sdk/signNetworkFee/signNetworkFee.ts +0 -92
- package/src/web3Sdk/signStakeAndBake/contracts.ts +0 -80
- package/src/web3Sdk/signStakeAndBake/getTypedData.ts +0 -78
- package/src/web3Sdk/signStakeAndBake/index.ts +0 -3
- package/src/web3Sdk/signStakeAndBake/signStakeAndBake.ts +0 -105
- package/src/web3Sdk/signStakeAndBake/utils.ts +0 -23
- package/src/web3Sdk/types.ts +0 -16
- package/src/web3Sdk/unstakeLBTC/unstakeLBTC.stories.tsx +0 -77
- package/src/web3Sdk/unstakeLBTC/unstakeLBTC.ts +0 -51
- package/src/web3Sdk/utils/chainIdToEnv.ts +0 -12
- package/src/web3Sdk/utils/getBasculeTokenContract.ts +0 -21
- package/src/web3Sdk/utils/getGasMultiplier.ts +0 -20
- package/src/web3Sdk/utils/getLbtcTokenContract.ts +0 -36
- package/src/web3Sdk/utils/getRpcUrlConfigFromChain.ts +0 -34
- package/src/web3Sdk/utils/getTokenABI.ts +0 -12
- /package/src/{sdk → api-functions}/generateDepositBtcAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getDepositBtcAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getDepositsByAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getLBTCExchangeRate/index.ts +0 -0
- /package/src/{sdk → api-functions}/getNetworkFeeSignature/index.ts +0 -0
- /package/src/{sdk → api-functions}/getPointsByAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getUnstakesByAddress/index.ts +0 -0
- /package/src/{sdk → api-functions}/getUserStakeAndBakeSignature/index.ts +0 -0
- /package/src/{sdk → api-functions}/setReferral/index.ts +0 -0
- /package/src/{sdk → api-functions}/storeNetworkFeeSignature/index.ts +0 -0
- /package/src/{sdk → api-functions}/storeStakeAndBakeSignature/index.ts +0 -0
- /package/src/{sdk/const.ts → common/constants.ts} +0 -0
- /package/src/{web3Sdk → contract-functions}/approveLBTC/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/claimLBTC/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getBasculeDepositStatus/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getLBTCTotalSupply/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getPermitNonce/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getShareValue/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getSharesByAddress/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/signLbtcDestionationAddr/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/signNetworkFee/getTypedData.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/signNetworkFee/index.ts +0 -0
- /package/src/{web3Sdk → contract-functions}/unstakeLBTC/index.ts +0 -0
- /package/src/{common/utils/getErrorMessage.ts → utils/err.ts} +0 -0
|
@@ -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
|
|
10
|
-
import BigNumber from
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
22
|
+
'https://api.sevenseas.capital/deposits/{network}/{vault}/{account}';
|
|
21
23
|
|
|
22
24
|
export type GetVaultDepositsParameters = {
|
|
23
25
|
account: Address;
|
|
24
|
-
chainId:
|
|
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?:
|
|
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(
|
|
81
|
-
.replace(
|
|
82
|
-
.replace(
|
|
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
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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,
|
|
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:
|
|
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
|
-
|
|
47
|
-
</Button>
|
|
51
|
+
actionName={getVaultPoints.name}
|
|
52
|
+
/>
|
|
48
53
|
|
|
49
|
-
<
|
|
54
|
+
<ErrorBlock>{error}</ErrorBlock>
|
|
55
|
+
|
|
56
|
+
<CodeBlock text={data} />
|
|
50
57
|
</>
|
|
51
58
|
);
|
|
52
59
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
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 =
|
|
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(
|
|
41
|
+
const url = POINTS_URL.replace('{account}', account);
|
|
38
42
|
const { data } = await axios.get<Response>(url, {
|
|
39
43
|
headers: {
|
|
40
|
-
|
|
41
|
-
|
|
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 ===
|
|
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:
|
|
26
|
-
chainId:
|
|
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
|
-
|
|
54
|
-
|
|
58
|
+
actionName={getVaultWithdrawals.name}
|
|
59
|
+
/>
|
|
60
|
+
|
|
61
|
+
<ErrorBlock>{error}</ErrorBlock>
|
|
55
62
|
|
|
56
|
-
<CodeBlock text={
|
|
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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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:
|
|
21
|
+
chainId: ChainId;
|
|
21
22
|
vaultKey?: Vault;
|
|
23
|
+
rpcUrl?: string;
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
export type VaultWithdrawal = {
|
|
25
|
-
token?:
|
|
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
|
-
|
|
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(
|
|
117
|
-
.replace(
|
|
118
|
-
.replace(
|
|
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
|
|
123
|
-
|
|
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:
|
|
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(
|
|
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:
|
|
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(
|
|
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:
|
|
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:
|
|
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:
|
|
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(
|
|
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:
|
|
205
|
+
shareAmount: fromBaseDenomination(w.amount, vault.decimals),
|
|
172
206
|
timestamp: w.timestamp,
|
|
173
207
|
txHash: ensureHex(w.transactionHash),
|
|
174
208
|
token,
|
|
175
|
-
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,
|
|
182
|
-
expired: orderBy(expired,
|
|
215
|
+
cancelled: orderBy(cancelled, a => a.timestamp, 'desc'),
|
|
216
|
+
expired: orderBy(expired, a => a.timestamp, 'desc'),
|
|
183
217
|
fulfilled: orderBy(
|
|
184
218
|
fulfilled,
|
|
185
|
-
|
|
186
|
-
|
|
219
|
+
a => a.fulfilledTimestamp || a.timestamp,
|
|
220
|
+
'desc',
|
|
187
221
|
),
|
|
188
|
-
open: orderBy(open,
|
|
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
|
+
}
|