@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,25 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import Web3 from 'web3';
|
|
3
|
-
|
|
4
|
-
export async function getMaxPriorityFeePerGas(
|
|
5
|
-
rpcUrl: string,
|
|
6
|
-
): Promise<BigNumber> {
|
|
7
|
-
const response = await fetch(rpcUrl, {
|
|
8
|
-
method: 'POST',
|
|
9
|
-
headers: {
|
|
10
|
-
'Content-Type': 'application/json',
|
|
11
|
-
},
|
|
12
|
-
body: JSON.stringify({
|
|
13
|
-
jsonrpc: '2.0',
|
|
14
|
-
id: 1,
|
|
15
|
-
method: 'eth_maxPriorityFeePerGas',
|
|
16
|
-
params: [],
|
|
17
|
-
}),
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const data = await response.json();
|
|
21
|
-
|
|
22
|
-
const convertedHexValue = Web3.utils.hexToNumber(data?.result);
|
|
23
|
-
|
|
24
|
-
return new BigNumber(Number(convertedHexValue));
|
|
25
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { IEnvParam } from '../../common/types/internalTypes';
|
|
4
|
-
import { OChainId, TChainId } from '../../common/types/types';
|
|
5
|
-
import { SATOSHI_SCALE } from '../../common/utils/convertSatoshi';
|
|
6
|
-
import { getApiConfig } from '../apiConfig';
|
|
7
|
-
import { MIN_STAKE_AMOUNT_BTC } from '../const';
|
|
8
|
-
import { getChainNameById } from '../utils/getChainNameById';
|
|
9
|
-
|
|
10
|
-
type ExchangeRateResponse = {
|
|
11
|
-
amount_out: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export interface IgetLBTCExchangeRateParams extends IEnvParam {
|
|
15
|
-
/**
|
|
16
|
-
* The chain id of the asset to get the exchange rate for. Exchange rate is the same for all chains so this param is optional.
|
|
17
|
-
*
|
|
18
|
-
* @default OChainId.ethereum
|
|
19
|
-
*/
|
|
20
|
-
chainId?: TChainId;
|
|
21
|
-
/**
|
|
22
|
-
* The amount of the asset to get the exchange rate for. If not provided, the exchange rate will be returned for 1 BTC.
|
|
23
|
-
*
|
|
24
|
-
* @default 1
|
|
25
|
-
*/
|
|
26
|
-
amount?: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface IgetLBTCExchangeRateResponse {
|
|
30
|
-
/**
|
|
31
|
-
* The exchange rate for LBTC:BTC
|
|
32
|
-
*/
|
|
33
|
-
exchangeRate: number;
|
|
34
|
-
/**
|
|
35
|
-
* The minimum amount of the asset to stake
|
|
36
|
-
*/
|
|
37
|
-
minAmount: number;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Retrieves the exchange rate for LBTC.
|
|
42
|
-
*
|
|
43
|
-
* @param {IgetLBTCExchangeRateParams} params
|
|
44
|
-
*
|
|
45
|
-
* @returns {Promise<IgetLBTCExchangeRateResponse>} - The exchange rate.
|
|
46
|
-
*/
|
|
47
|
-
export async function getLBTCExchangeRate({
|
|
48
|
-
env,
|
|
49
|
-
chainId = OChainId.ethereum,
|
|
50
|
-
amount = 1,
|
|
51
|
-
}: IgetLBTCExchangeRateParams): Promise<IgetLBTCExchangeRateResponse> {
|
|
52
|
-
const { baseApiUrl } = getApiConfig(env);
|
|
53
|
-
const chainIdName = getChainNameById(chainId);
|
|
54
|
-
|
|
55
|
-
const { data } = await axios.get<ExchangeRateResponse>(
|
|
56
|
-
`api/v1/exchange/rate/${chainIdName}`,
|
|
57
|
-
{ baseURL: baseApiUrl, params: { amount } },
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const minAmount = new BigNumber(MIN_STAKE_AMOUNT_BTC)
|
|
61
|
-
.multipliedBy(SATOSHI_SCALE)
|
|
62
|
-
.toFixed();
|
|
63
|
-
|
|
64
|
-
return { exchangeRate: +data.amount_out, minAmount: +minAmount };
|
|
65
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { defaultEnv } from '@lombard.finance/sdk-common';
|
|
3
|
-
import { Button } from '../../stories/components/Button';
|
|
4
|
-
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
5
|
-
import { useConnect } from '../../stories/hooks/useConnect';
|
|
6
|
-
import useQuery from '../../stories/hooks/useQuery';
|
|
7
|
-
import {
|
|
8
|
-
getNetworkFeeSignature,
|
|
9
|
-
IGetNetworkFeeSignatureParams,
|
|
10
|
-
} from './getNetworkFeeSignature';
|
|
11
|
-
|
|
12
|
-
const meta = {
|
|
13
|
-
title: 'SDK/getNetworkFeeSignature',
|
|
14
|
-
component: StoryView,
|
|
15
|
-
tags: ['autodocs'],
|
|
16
|
-
} satisfies Meta<typeof StoryView>;
|
|
17
|
-
|
|
18
|
-
export default meta;
|
|
19
|
-
|
|
20
|
-
type Story = StoryObj<typeof meta>;
|
|
21
|
-
|
|
22
|
-
export const WithParams: Story = {
|
|
23
|
-
args: {
|
|
24
|
-
env: defaultEnv,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
type GetNetworkFeeSignatureParamsProps = Pick<
|
|
29
|
-
IGetNetworkFeeSignatureParams,
|
|
30
|
-
'env'
|
|
31
|
-
>;
|
|
32
|
-
|
|
33
|
-
export function StoryView(props: GetNetworkFeeSignatureParamsProps) {
|
|
34
|
-
const {
|
|
35
|
-
data: connectData,
|
|
36
|
-
error: connectError,
|
|
37
|
-
isLoading: isConnectLoading,
|
|
38
|
-
connect,
|
|
39
|
-
} = useConnect();
|
|
40
|
-
|
|
41
|
-
const request = async () => {
|
|
42
|
-
if (!connectData) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return getNetworkFeeSignature({
|
|
47
|
-
chainId: connectData.chainId,
|
|
48
|
-
address: connectData.account,
|
|
49
|
-
...props,
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
54
|
-
|
|
55
|
-
const formattedConnectData = connectData && {
|
|
56
|
-
account: connectData.account,
|
|
57
|
-
chainId: connectData.chainId,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<>
|
|
62
|
-
<div className="mb-4">
|
|
63
|
-
<Button
|
|
64
|
-
onClick={connect}
|
|
65
|
-
disabled={isConnectLoading}
|
|
66
|
-
isLoading={isConnectLoading}
|
|
67
|
-
>
|
|
68
|
-
Connect
|
|
69
|
-
</Button>
|
|
70
|
-
|
|
71
|
-
<CodeBlock text={connectError || formattedConnectData} />
|
|
72
|
-
</div>
|
|
73
|
-
|
|
74
|
-
<Button
|
|
75
|
-
onClick={refetch}
|
|
76
|
-
disabled={isLoading || !connectData}
|
|
77
|
-
isLoading={isLoading}
|
|
78
|
-
>
|
|
79
|
-
Get authorization fee sign
|
|
80
|
-
</Button>
|
|
81
|
-
|
|
82
|
-
<CodeBlock text={error || data} />
|
|
83
|
-
</>
|
|
84
|
-
);
|
|
85
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { defaultEnv } from '@lombard.finance/sdk-common';
|
|
3
|
-
import { Button } from '../../stories/components/Button';
|
|
4
|
-
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
5
|
-
import { useConnect } from '../../stories/hooks/useConnect';
|
|
6
|
-
import useQuery from '../../stories/hooks/useQuery';
|
|
7
|
-
import {
|
|
8
|
-
IGetUserStakeAndBakeSignatureParams,
|
|
9
|
-
getUserStakeAndBakeSignature,
|
|
10
|
-
} from './getUserStakeAndBakeSignature';
|
|
11
|
-
|
|
12
|
-
const meta = {
|
|
13
|
-
title: 'SDK/getUserStakeAndBakeSignature',
|
|
14
|
-
component: StoryView,
|
|
15
|
-
tags: ['autodocs'],
|
|
16
|
-
} satisfies Meta<typeof StoryView>;
|
|
17
|
-
|
|
18
|
-
export default meta;
|
|
19
|
-
|
|
20
|
-
type Story = StoryObj<typeof meta>;
|
|
21
|
-
|
|
22
|
-
export const WithParams: Story = {
|
|
23
|
-
args: {
|
|
24
|
-
env: defaultEnv,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
type GetUserStakeAndBakeSignatureProps = Pick<
|
|
29
|
-
IGetUserStakeAndBakeSignatureParams,
|
|
30
|
-
'env'
|
|
31
|
-
>;
|
|
32
|
-
|
|
33
|
-
export function StoryView(props: GetUserStakeAndBakeSignatureProps) {
|
|
34
|
-
const {
|
|
35
|
-
data: connectData,
|
|
36
|
-
error: connectError,
|
|
37
|
-
isLoading: isConnectLoading,
|
|
38
|
-
connect,
|
|
39
|
-
} = useConnect();
|
|
40
|
-
|
|
41
|
-
const request = async () => {
|
|
42
|
-
if (!connectData?.account) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return getUserStakeAndBakeSignature({
|
|
47
|
-
...props,
|
|
48
|
-
userDestinationAddress: connectData.account,
|
|
49
|
-
chainId: connectData.chainId,
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
54
|
-
|
|
55
|
-
const formattedConnectData = connectData && {
|
|
56
|
-
account: connectData.account,
|
|
57
|
-
chainId: connectData.chainId,
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<>
|
|
62
|
-
<p>
|
|
63
|
-
This method gets the user's stake and bake signature from the API. The
|
|
64
|
-
signature is used to approve spending of tokens.
|
|
65
|
-
</p>
|
|
66
|
-
|
|
67
|
-
<div className="mb-4">
|
|
68
|
-
<Button
|
|
69
|
-
onClick={connect}
|
|
70
|
-
disabled={isConnectLoading}
|
|
71
|
-
isLoading={isConnectLoading}
|
|
72
|
-
>
|
|
73
|
-
Connect
|
|
74
|
-
</Button>
|
|
75
|
-
|
|
76
|
-
<CodeBlock text={connectError || formattedConnectData} />
|
|
77
|
-
</div>
|
|
78
|
-
|
|
79
|
-
<Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
|
|
80
|
-
Get User Stake and Bake Signature
|
|
81
|
-
</Button>
|
|
82
|
-
|
|
83
|
-
<CodeBlock text={error || data} />
|
|
84
|
-
</>
|
|
85
|
-
);
|
|
86
|
-
}
|
package/src/sdk/internalTypes.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const OChainName = {
|
|
2
|
-
eth: 'DESTINATION_BLOCKCHAIN_ETHEREUM',
|
|
3
|
-
ethOld: 'BLOCKCHAIN_ETHEREUM',
|
|
4
|
-
|
|
5
|
-
base: 'DESTINATION_BLOCKCHAIN_BASE',
|
|
6
|
-
baseOld: 'BLOCKCHAIN_BASE',
|
|
7
|
-
|
|
8
|
-
bsc: 'DESTINATION_BLOCKCHAIN_BSC',
|
|
9
|
-
bscOld: 'BLOCKCHAIN_BSC',
|
|
10
|
-
|
|
11
|
-
sui: 'DESTINATION_BLOCKCHAIN_SUI',
|
|
12
|
-
suiOld: 'BLOCKCHAIN_SUI',
|
|
13
|
-
|
|
14
|
-
sonic: 'DESTINATION_BLOCKCHAIN_SONIC',
|
|
15
|
-
sonicOld: 'BLOCKCHAIN_SONIC',
|
|
16
|
-
} as const;
|
|
17
|
-
|
|
18
|
-
export type TChainName = (typeof OChainName)[keyof typeof OChainName];
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { defaultEnv } from '@lombard.finance/sdk-common';
|
|
3
|
-
import { Button } from '../../stories/components/Button';
|
|
4
|
-
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
5
|
-
import { useConnect } from '../../stories/hooks/useConnect';
|
|
6
|
-
import useQuery from '../../stories/hooks/useQuery';
|
|
7
|
-
import {
|
|
8
|
-
IStoreNetworkFeeSignatureParams,
|
|
9
|
-
storeNetworkFeeSignature,
|
|
10
|
-
} from './storeNetworkFeeSignature';
|
|
11
|
-
|
|
12
|
-
const meta = {
|
|
13
|
-
title: 'SDK/storeNetworkFeeSignature',
|
|
14
|
-
component: StoryView,
|
|
15
|
-
tags: ['autodocs'],
|
|
16
|
-
} satisfies Meta<typeof StoryView>;
|
|
17
|
-
|
|
18
|
-
export default meta;
|
|
19
|
-
|
|
20
|
-
type Story = StoryObj<typeof meta>;
|
|
21
|
-
|
|
22
|
-
export const WithParams: Story = {
|
|
23
|
-
args: {
|
|
24
|
-
env: defaultEnv,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
type StoreNetworkFeeSignatureProps = Pick<
|
|
29
|
-
IStoreNetworkFeeSignatureParams,
|
|
30
|
-
'env'
|
|
31
|
-
>;
|
|
32
|
-
|
|
33
|
-
export function StoryView(props: StoreNetworkFeeSignatureProps) {
|
|
34
|
-
const {
|
|
35
|
-
data: connectData,
|
|
36
|
-
error: connectError,
|
|
37
|
-
isLoading: isConnectLoading,
|
|
38
|
-
connect,
|
|
39
|
-
} = useConnect();
|
|
40
|
-
|
|
41
|
-
const request = async () => {
|
|
42
|
-
if (!connectData) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return storeNetworkFeeSignature({
|
|
47
|
-
address: connectData.account,
|
|
48
|
-
...props,
|
|
49
|
-
signature: '',
|
|
50
|
-
typedData: '',
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
55
|
-
|
|
56
|
-
const formattedConnectData = connectData && {
|
|
57
|
-
account: connectData.account,
|
|
58
|
-
chainId: connectData.chainId,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<>
|
|
63
|
-
<div className="mb-4">
|
|
64
|
-
<Button
|
|
65
|
-
onClick={connect}
|
|
66
|
-
disabled={isConnectLoading}
|
|
67
|
-
isLoading={isConnectLoading}
|
|
68
|
-
>
|
|
69
|
-
Connect
|
|
70
|
-
</Button>
|
|
71
|
-
|
|
72
|
-
<CodeBlock text={connectError || formattedConnectData} />
|
|
73
|
-
</div>
|
|
74
|
-
|
|
75
|
-
<Button
|
|
76
|
-
onClick={refetch}
|
|
77
|
-
disabled={isLoading || !connectData}
|
|
78
|
-
isLoading={isLoading}
|
|
79
|
-
>
|
|
80
|
-
Authorize
|
|
81
|
-
</Button>
|
|
82
|
-
|
|
83
|
-
<CodeBlock text={error || data} />
|
|
84
|
-
</>
|
|
85
|
-
);
|
|
86
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { defaultEnv } from '@lombard.finance/sdk-common';
|
|
3
|
-
import { Button } from '../../stories/components/Button';
|
|
4
|
-
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
5
|
-
import { useConnect } from '../../stories/hooks/useConnect';
|
|
6
|
-
import useQuery from '../../stories/hooks/useQuery';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
ISignStakeAndBakeParams,
|
|
10
|
-
signStakeAndBake,
|
|
11
|
-
} from '../../web3Sdk/signStakeAndBake/signStakeAndBake';
|
|
12
|
-
import { storeStakeAndBakeSignature } from './storeStakeAndBakeSignature';
|
|
13
|
-
|
|
14
|
-
const meta = {
|
|
15
|
-
title: 'SDK/storeStakeAndBakeSignature',
|
|
16
|
-
component: StoryView,
|
|
17
|
-
tags: ['autodocs'],
|
|
18
|
-
} satisfies Meta<typeof StoryView>;
|
|
19
|
-
|
|
20
|
-
export default meta;
|
|
21
|
-
|
|
22
|
-
type Story = StoryObj<typeof meta>;
|
|
23
|
-
|
|
24
|
-
export const WithParams: Story = {
|
|
25
|
-
args: {
|
|
26
|
-
value: '20000',
|
|
27
|
-
expiry: 3600,
|
|
28
|
-
vaultKey: 'veda',
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
type SignStakeAndBakeParams = Pick<
|
|
33
|
-
ISignStakeAndBakeParams,
|
|
34
|
-
'value' | 'expiry' | 'vaultKey'
|
|
35
|
-
>;
|
|
36
|
-
|
|
37
|
-
export function StoryView(props: SignStakeAndBakeParams) {
|
|
38
|
-
const {
|
|
39
|
-
data: connectData,
|
|
40
|
-
error: connectError,
|
|
41
|
-
isLoading: isConnectLoading,
|
|
42
|
-
connect,
|
|
43
|
-
} = useConnect();
|
|
44
|
-
|
|
45
|
-
const request = async () => {
|
|
46
|
-
if (!connectData || !connectData.provider) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// First sign the authorization
|
|
51
|
-
const { signature, typedData } = await signStakeAndBake({
|
|
52
|
-
provider: connectData.provider,
|
|
53
|
-
address: connectData.account,
|
|
54
|
-
chainId: connectData.chainId,
|
|
55
|
-
value: props.value,
|
|
56
|
-
expiry: props.expiry,
|
|
57
|
-
vaultKey: props.vaultKey,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// Then store it
|
|
61
|
-
await storeStakeAndBakeSignature({
|
|
62
|
-
signature,
|
|
63
|
-
typedData,
|
|
64
|
-
env: defaultEnv,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
return { signature, typedData };
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
71
|
-
|
|
72
|
-
const formattedConnectData = connectData && {
|
|
73
|
-
account: connectData.account,
|
|
74
|
-
chainId: connectData.chainId,
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
return (
|
|
78
|
-
<>
|
|
79
|
-
<p>
|
|
80
|
-
This method signs and stores the stake and bake signature in the
|
|
81
|
-
backend. The signature is used to approve spending of tokens.
|
|
82
|
-
</p>
|
|
83
|
-
|
|
84
|
-
<div className="mb-4">
|
|
85
|
-
<Button
|
|
86
|
-
onClick={connect}
|
|
87
|
-
disabled={isConnectLoading}
|
|
88
|
-
isLoading={isConnectLoading}
|
|
89
|
-
>
|
|
90
|
-
Connect
|
|
91
|
-
</Button>
|
|
92
|
-
|
|
93
|
-
<CodeBlock text={connectError || formattedConnectData} />
|
|
94
|
-
</div>
|
|
95
|
-
|
|
96
|
-
<Button
|
|
97
|
-
onClick={refetch}
|
|
98
|
-
disabled={isLoading || !connectData}
|
|
99
|
-
isLoading={isLoading}
|
|
100
|
-
>
|
|
101
|
-
Sign and Store Stake and Bake Signature
|
|
102
|
-
</Button>
|
|
103
|
-
|
|
104
|
-
<CodeBlock
|
|
105
|
-
text={
|
|
106
|
-
error ||
|
|
107
|
-
(data && {
|
|
108
|
-
...data,
|
|
109
|
-
signature: data.signature,
|
|
110
|
-
typedData: data.typedData ? JSON.parse(data.typedData) : '',
|
|
111
|
-
})
|
|
112
|
-
}
|
|
113
|
-
/>
|
|
114
|
-
</>
|
|
115
|
-
);
|
|
116
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { defaultEnv } from '@lombard.finance/sdk-common';
|
|
2
|
-
import {
|
|
3
|
-
getBaseNetworkByEnv,
|
|
4
|
-
getBscNetworkByEnv,
|
|
5
|
-
getEthNetworkByEnv,
|
|
6
|
-
getSonicNetworkByEnv,
|
|
7
|
-
getSuiNetworkByEnv,
|
|
8
|
-
OChainId,
|
|
9
|
-
SuiChain,
|
|
10
|
-
TChainId,
|
|
11
|
-
} from '../../common/types/types';
|
|
12
|
-
import { Env } from '@lombard.finance/sdk-common';
|
|
13
|
-
import { OChainName, TChainName } from '../internalTypes';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param chain the chain ID
|
|
17
|
-
* @param env
|
|
18
|
-
* @returns the chain name
|
|
19
|
-
*/
|
|
20
|
-
export function getChainIdByName(
|
|
21
|
-
chain: string,
|
|
22
|
-
env: Env = defaultEnv,
|
|
23
|
-
): TChainId | SuiChain {
|
|
24
|
-
switch (chain as TChainName) {
|
|
25
|
-
case OChainName.eth:
|
|
26
|
-
case OChainName.ethOld:
|
|
27
|
-
return getEthNetworkByEnv(env);
|
|
28
|
-
|
|
29
|
-
case OChainName.base:
|
|
30
|
-
case OChainName.baseOld:
|
|
31
|
-
return getBaseNetworkByEnv(env);
|
|
32
|
-
|
|
33
|
-
case OChainName.bsc:
|
|
34
|
-
case OChainName.bscOld:
|
|
35
|
-
return getBscNetworkByEnv(env);
|
|
36
|
-
|
|
37
|
-
case OChainName.sui:
|
|
38
|
-
case OChainName.suiOld:
|
|
39
|
-
return getSuiNetworkByEnv(env);
|
|
40
|
-
|
|
41
|
-
case OChainName.sonic:
|
|
42
|
-
case OChainName.sonicOld:
|
|
43
|
-
return getSonicNetworkByEnv(env);
|
|
44
|
-
|
|
45
|
-
default:
|
|
46
|
-
return OChainId.ethereum;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { OChainId, SuiChain, TChainId } from '../../common/types/types';
|
|
2
|
-
import { OChainName, TChainName } from '../internalTypes';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param chainId the chain ID
|
|
6
|
-
*
|
|
7
|
-
* @returns the chain name
|
|
8
|
-
*/
|
|
9
|
-
export function getChainNameById(
|
|
10
|
-
chainId: TChainId | SuiChain,
|
|
11
|
-
isOld = false,
|
|
12
|
-
): TChainName {
|
|
13
|
-
if (
|
|
14
|
-
chainId === OChainId.ethereum ||
|
|
15
|
-
chainId === OChainId.holesky ||
|
|
16
|
-
chainId === OChainId.sepolia
|
|
17
|
-
) {
|
|
18
|
-
return isOld ? OChainName.ethOld : OChainName.eth;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (chainId === OChainId.base || chainId === OChainId.baseSepoliaTestnet) {
|
|
22
|
-
return isOld ? OChainName.baseOld : OChainName.base;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
chainId === OChainId.binanceSmartChain ||
|
|
27
|
-
chainId === OChainId.binanceSmartChainTestnet
|
|
28
|
-
) {
|
|
29
|
-
return isOld ? OChainName.bscOld : OChainName.bsc;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (chainId === OChainId.sonic || chainId === OChainId.sonicBlazeTestnet) {
|
|
33
|
-
return isOld ? OChainName.sonicOld : OChainName.sonic;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (chainId === 'sui:testnet' || chainId === 'sui:mainnet') {
|
|
37
|
-
return isOld ? OChainName.suiOld : OChainName.sui;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
throw new Error(`Unknown chain ID: ${chainId}`);
|
|
41
|
-
}
|
package/src/stories/const.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const exampleEvmAddress = '0x659579f1460c38c3ce3288b47b074646cef855fc';
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import Web3 from 'web3';
|
|
2
|
-
import { IEIP1193Provider, TChainId } from '../../common/types/types';
|
|
3
|
-
import { isValidChain } from '../../common/utils/isValidChain';
|
|
4
|
-
import { connectInjectedWallet } from '../utils/connectInjectedWallet';
|
|
5
|
-
import { getWalletInfo } from '../utils/getWalletInfo';
|
|
6
|
-
import useQuery from './useQuery';
|
|
7
|
-
|
|
8
|
-
interface IRequestConnect {
|
|
9
|
-
provider: IEIP1193Provider;
|
|
10
|
-
account: string;
|
|
11
|
-
chainId: TChainId;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface IUseConnect {
|
|
15
|
-
data: IRequestConnect | null;
|
|
16
|
-
error: string | null;
|
|
17
|
-
isLoading: boolean;
|
|
18
|
-
connect: () => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function useConnect(): IUseConnect {
|
|
22
|
-
const {
|
|
23
|
-
data,
|
|
24
|
-
error,
|
|
25
|
-
isLoading,
|
|
26
|
-
refetch: connect,
|
|
27
|
-
} = useQuery(requestConnect, [], false);
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
data,
|
|
31
|
-
error,
|
|
32
|
-
isLoading,
|
|
33
|
-
connect,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function requestConnect(): Promise<IRequestConnect> {
|
|
38
|
-
const provider = await connectInjectedWallet();
|
|
39
|
-
const web3 = new Web3(provider);
|
|
40
|
-
const { account, chainId } = await getWalletInfo(web3);
|
|
41
|
-
|
|
42
|
-
if (!isValidChain(chainId)) {
|
|
43
|
-
throw new Error('Invalid chain');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return { provider, account, chainId };
|
|
47
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
type TEip1559Provider = any;
|
|
2
|
-
|
|
3
|
-
export async function connectInjectedWallet(): Promise<TEip1559Provider> {
|
|
4
|
-
const { ethereum } = window as any;
|
|
5
|
-
if (!ethereum) {
|
|
6
|
-
throw new Error('Ethereum object not found');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
await ethereum.enable();
|
|
10
|
-
|
|
11
|
-
return ethereum;
|
|
12
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Convert a camelCase string to readable string with spaces.
|
|
3
|
-
*
|
|
4
|
-
* @param value - CamelCase string.
|
|
5
|
-
*
|
|
6
|
-
* @returns Readable string with spaces.
|
|
7
|
-
*/
|
|
8
|
-
export function fromCamelCase(value: string): string {
|
|
9
|
-
return (
|
|
10
|
-
value
|
|
11
|
-
// Insert a space before all caps
|
|
12
|
-
.replace(/([A-Z])/g, ' $1')
|
|
13
|
-
// Uppercase the first character
|
|
14
|
-
.replace(/^./, str => str.toUpperCase())
|
|
15
|
-
);
|
|
16
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import Web3, { FMT_BYTES, FMT_NUMBER } from 'web3';
|
|
2
|
-
|
|
3
|
-
interface IGetWalletInfo {
|
|
4
|
-
account: string;
|
|
5
|
-
chainId: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Retrieves wallet information.
|
|
10
|
-
*
|
|
11
|
-
* @param web3 - The Web3 instance.
|
|
12
|
-
* @returns A promise that resolves to an object containing the account and chainId.
|
|
13
|
-
* @throws An error if no account is found.
|
|
14
|
-
*/
|
|
15
|
-
export async function getWalletInfo(web3: Web3): Promise<IGetWalletInfo> {
|
|
16
|
-
const [account] = await web3.eth.getAccounts();
|
|
17
|
-
|
|
18
|
-
if (!account) {
|
|
19
|
-
throw new Error('No account found');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const chainId = await web3.eth.getChainId({
|
|
23
|
-
bytes: FMT_BYTES.HEX,
|
|
24
|
-
number: FMT_NUMBER.NUMBER,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
account,
|
|
29
|
-
chainId,
|
|
30
|
-
};
|
|
31
|
-
}
|