@lombard.finance/sdk 2.5.1 → 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 -38
- 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
package/src/web3Sdk/abi/index.ts
DELETED
|
@@ -1,77 +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 { approveLBTC, IApproveLBTCParams } from './approveLBTC';
|
|
8
|
-
|
|
9
|
-
const meta = {
|
|
10
|
-
title: 'Web3SDK/approveLBTC',
|
|
11
|
-
component: StoryView,
|
|
12
|
-
tags: ['autodocs'],
|
|
13
|
-
} satisfies Meta<typeof StoryView>;
|
|
14
|
-
|
|
15
|
-
export default meta;
|
|
16
|
-
|
|
17
|
-
type Story = StoryObj<typeof meta>;
|
|
18
|
-
|
|
19
|
-
export const WithParams: Story = {
|
|
20
|
-
args: {
|
|
21
|
-
amount: 0.00001,
|
|
22
|
-
spender: '',
|
|
23
|
-
env: defaultEnv,
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
type ClaimLBTCProps = Pick<IApproveLBTCParams, 'spender' | 'amount' | 'env'>;
|
|
28
|
-
|
|
29
|
-
export function StoryView(props: ClaimLBTCProps) {
|
|
30
|
-
const {
|
|
31
|
-
data: connectData,
|
|
32
|
-
error: connectError,
|
|
33
|
-
isLoading: isConnectLoading,
|
|
34
|
-
connect,
|
|
35
|
-
} = useConnect();
|
|
36
|
-
|
|
37
|
-
const request = async () => {
|
|
38
|
-
if (!connectData) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return approveLBTC({ ...connectData, ...props });
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
46
|
-
|
|
47
|
-
const formattedConnectData = connectData && {
|
|
48
|
-
account: connectData.account,
|
|
49
|
-
chainId: connectData.chainId,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<>
|
|
54
|
-
<div className="mb-4">
|
|
55
|
-
<Button
|
|
56
|
-
onClick={connect}
|
|
57
|
-
disabled={isConnectLoading}
|
|
58
|
-
isLoading={isConnectLoading}
|
|
59
|
-
>
|
|
60
|
-
Connect
|
|
61
|
-
</Button>
|
|
62
|
-
|
|
63
|
-
<CodeBlock text={connectError || formattedConnectData} />
|
|
64
|
-
</div>
|
|
65
|
-
|
|
66
|
-
<Button
|
|
67
|
-
onClick={refetch}
|
|
68
|
-
disabled={isLoading || !connectData}
|
|
69
|
-
isLoading={isLoading}
|
|
70
|
-
>
|
|
71
|
-
Approve LBTC
|
|
72
|
-
</Button>
|
|
73
|
-
|
|
74
|
-
<CodeBlock text={error || data} />
|
|
75
|
-
</>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { IEnvParam } from '../../common/types/internalTypes';
|
|
2
|
-
import { toSatoshi } from '../../common/utils/convertSatoshi';
|
|
3
|
-
import { IWeb3SendResult, Provider } from '../../provider';
|
|
4
|
-
import { IProviderBasedParams } from '../types';
|
|
5
|
-
import { getGasMultiplier } from '../utils/getGasMultiplier';
|
|
6
|
-
import { getLbtcTokenContract } from '../utils/getLbtcTokenContract';
|
|
7
|
-
|
|
8
|
-
export interface IApproveLBTCParams extends IProviderBasedParams, IEnvParam {
|
|
9
|
-
/**
|
|
10
|
-
* Spender address
|
|
11
|
-
*/
|
|
12
|
-
spender: string;
|
|
13
|
-
/**
|
|
14
|
-
* The amount of LBTC to approve
|
|
15
|
-
*/
|
|
16
|
-
amount: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Approves the transfer of a specified amount of LBTC tokens.
|
|
21
|
-
*
|
|
22
|
-
* @param {IApproveLBTCParams} params
|
|
23
|
-
*
|
|
24
|
-
* @returns {Promise<IWeb3SendResult>} transaction promise
|
|
25
|
-
*/
|
|
26
|
-
export function approveLBTC({
|
|
27
|
-
spender,
|
|
28
|
-
amount,
|
|
29
|
-
env,
|
|
30
|
-
...providerParams
|
|
31
|
-
}: IApproveLBTCParams): Promise<IWeb3SendResult> {
|
|
32
|
-
const provider = new Provider(providerParams);
|
|
33
|
-
const tokenContract = getLbtcTokenContract(provider, env);
|
|
34
|
-
const amountSat = toSatoshi(amount).toNumber();
|
|
35
|
-
|
|
36
|
-
const tx = tokenContract.methods.approve(spender, amountSat);
|
|
37
|
-
|
|
38
|
-
return provider.sendTransactionAsync(
|
|
39
|
-
provider.account,
|
|
40
|
-
tokenContract.options.address,
|
|
41
|
-
{
|
|
42
|
-
data: tx.encodeABI(),
|
|
43
|
-
estimate: true,
|
|
44
|
-
estimateFee: true,
|
|
45
|
-
gasLimitMultiplier: getGasMultiplier(provider.chainId),
|
|
46
|
-
},
|
|
47
|
-
);
|
|
48
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BasculeDepositStatus,
|
|
3
|
-
getBasculeDepositStatus,
|
|
4
|
-
} from '../getBasculeDepositStatus';
|
|
5
|
-
import { IEnvParam } from '../../common/types/internalTypes';
|
|
6
|
-
import { getErrorMessage } from '../../common/utils/getErrorMessage';
|
|
7
|
-
import { IWeb3SendResult, Provider } from '../../provider';
|
|
8
|
-
import { IProviderBasedParams } from '../types';
|
|
9
|
-
import { getGasMultiplier } from '../utils/getGasMultiplier';
|
|
10
|
-
import { getLbtcTokenContract } from '../utils/getLbtcTokenContract';
|
|
11
|
-
import { throwBasculeDepositStatusError } from '../getBasculeDepositStatus/utils/throwBasculeDepositStatusError';
|
|
12
|
-
import { BASCULE_SUPPORTED_CHAINS } from '../getBasculeDepositStatus/utils/const';
|
|
13
|
-
|
|
14
|
-
const INSUFFICIENT_FUNDS_PARTIAL_ERROR = 'insufficient funds';
|
|
15
|
-
|
|
16
|
-
const INSUFFICIENT_FUNDS_ERROR =
|
|
17
|
-
'Insufficient funds for transfer. Make sure you have enough ETH to cover the gas cost.';
|
|
18
|
-
|
|
19
|
-
export interface IClaimLBTCParams extends IProviderBasedParams, IEnvParam {
|
|
20
|
-
/**
|
|
21
|
-
* Raw payload from deposit notarization.
|
|
22
|
-
*/
|
|
23
|
-
data: string;
|
|
24
|
-
/**
|
|
25
|
-
* Signature from deposit notarization.
|
|
26
|
-
*/
|
|
27
|
-
proofSignature: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const hexify = (hexString: string) =>
|
|
31
|
-
hexString.startsWith('0x') ? hexString : `0x${hexString}`;
|
|
32
|
-
/**
|
|
33
|
-
* Claims LBTC.
|
|
34
|
-
*
|
|
35
|
-
* @param {IClaimLBTCParams} params - The parameters for claiming LBTC.
|
|
36
|
-
*
|
|
37
|
-
* @returns {Promise<IWeb3SendResult>} transaction promise
|
|
38
|
-
*/
|
|
39
|
-
export async function claimLBTC({
|
|
40
|
-
data,
|
|
41
|
-
proofSignature,
|
|
42
|
-
env,
|
|
43
|
-
...providerParams
|
|
44
|
-
}: IClaimLBTCParams): Promise<IWeb3SendResult> {
|
|
45
|
-
const provider = new Provider(providerParams);
|
|
46
|
-
|
|
47
|
-
if (BASCULE_SUPPORTED_CHAINS.includes(provider.chainId)) {
|
|
48
|
-
const status = await getBasculeDepositStatus({
|
|
49
|
-
env,
|
|
50
|
-
rawPayload: data,
|
|
51
|
-
...providerParams,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
if (status !== BasculeDepositStatus.REPORTED) {
|
|
55
|
-
throwBasculeDepositStatusError(status);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const tokenContract = getLbtcTokenContract(provider, env);
|
|
60
|
-
|
|
61
|
-
const tx = tokenContract.methods.mint(hexify(data), hexify(proofSignature));
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
const result = await provider.sendTransactionAsync(
|
|
65
|
-
provider.account,
|
|
66
|
-
tokenContract.options.address,
|
|
67
|
-
{
|
|
68
|
-
data: tx.encodeABI(),
|
|
69
|
-
estimate: true,
|
|
70
|
-
estimateFee: true,
|
|
71
|
-
gasLimitMultiplier: getGasMultiplier(provider.chainId),
|
|
72
|
-
},
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
return result;
|
|
76
|
-
} catch (error) {
|
|
77
|
-
console.log('error', error);
|
|
78
|
-
const errorMessage = getErrorMessage(error);
|
|
79
|
-
|
|
80
|
-
if (errorMessage.includes(INSUFFICIENT_FUNDS_PARTIAL_ERROR)) {
|
|
81
|
-
throw new Error(INSUFFICIENT_FUNDS_ERROR);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
throw new Error(errorMessage);
|
|
85
|
-
}
|
|
86
|
-
}
|
package/src/web3Sdk/const.ts
DELETED
|
@@ -1,89 +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
|
-
getBasculeDepositStatus,
|
|
9
|
-
ICheckBasculeDepositStatusParams,
|
|
10
|
-
} from './getBasculeDepositStatus';
|
|
11
|
-
|
|
12
|
-
const meta = {
|
|
13
|
-
title: 'Web3SDK/getBasculeDepositStatus',
|
|
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
|
-
rawPayload: '',
|
|
25
|
-
env: defaultEnv,
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type CheckBasculeDepositStatusProps = Pick<
|
|
30
|
-
ICheckBasculeDepositStatusParams,
|
|
31
|
-
'env' | 'rawPayload'
|
|
32
|
-
>;
|
|
33
|
-
|
|
34
|
-
const BASCULE_DEPOSIT_TX_ID =
|
|
35
|
-
'0x496028cda1ff940a1cfd9a326ac3bdff8e94ca545a6ac21d03964977561cbb52';
|
|
36
|
-
|
|
37
|
-
export function StoryView(props: CheckBasculeDepositStatusProps) {
|
|
38
|
-
const {
|
|
39
|
-
data: connectData,
|
|
40
|
-
error: connectError,
|
|
41
|
-
isLoading: isConnectLoading,
|
|
42
|
-
connect,
|
|
43
|
-
} = useConnect();
|
|
44
|
-
|
|
45
|
-
const request = async () => {
|
|
46
|
-
if (!connectData) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return getBasculeDepositStatus({
|
|
51
|
-
...connectData,
|
|
52
|
-
...props,
|
|
53
|
-
rawPayload: BASCULE_DEPOSIT_TX_ID,
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
58
|
-
|
|
59
|
-
const formattedConnectData = connectData && {
|
|
60
|
-
account: connectData.account,
|
|
61
|
-
chainId: connectData.chainId,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
<>
|
|
66
|
-
<div className="mb-4">
|
|
67
|
-
<Button
|
|
68
|
-
onClick={connect}
|
|
69
|
-
disabled={isConnectLoading}
|
|
70
|
-
isLoading={isConnectLoading}
|
|
71
|
-
>
|
|
72
|
-
Connect
|
|
73
|
-
</Button>
|
|
74
|
-
|
|
75
|
-
<CodeBlock text={connectError || formattedConnectData} />
|
|
76
|
-
</div>
|
|
77
|
-
|
|
78
|
-
<Button
|
|
79
|
-
onClick={refetch}
|
|
80
|
-
disabled={isLoading || !connectData}
|
|
81
|
-
isLoading={isLoading}
|
|
82
|
-
>
|
|
83
|
-
Get Bascule Deposit Status
|
|
84
|
-
</Button>
|
|
85
|
-
|
|
86
|
-
<CodeBlock text={error || data} />
|
|
87
|
-
</>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { IEnvParam } from '../../common/types/internalTypes';
|
|
2
|
-
import { getErrorMessage } from '../../common/utils/getErrorMessage';
|
|
3
|
-
import { Provider } from '../../provider';
|
|
4
|
-
import { IProviderBasedParams } from '../types';
|
|
5
|
-
import { getBasculeTokenContract } from '../utils/getBasculeTokenContract';
|
|
6
|
-
import { getLbtcTokenContract } from '../utils/getLbtcTokenContract';
|
|
7
|
-
import { ZERO_ADDRESS } from '../../common/const';
|
|
8
|
-
|
|
9
|
-
const NO_DEPOSIT_ID_ERROR =
|
|
10
|
-
'No deposit ID provided. Please provide a deposit ID as an argument.';
|
|
11
|
-
|
|
12
|
-
// Deposit status enum
|
|
13
|
-
export enum BasculeDepositStatus {
|
|
14
|
-
UNREPORTED = 0, // potentially pending
|
|
15
|
-
REPORTED = 1,
|
|
16
|
-
WITHDRAWN = 2,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface ICheckBasculeDepositStatusParams
|
|
20
|
-
extends IProviderBasedParams,
|
|
21
|
-
IEnvParam {
|
|
22
|
-
/**
|
|
23
|
-
* raw_payload of the transaction.
|
|
24
|
-
*/
|
|
25
|
-
rawPayload?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Check bascule contract deposit status.
|
|
30
|
-
*
|
|
31
|
-
* @param {ICheckBasculeDepositStatusParams} params - The parameters to get status base on Bascule contract.
|
|
32
|
-
*
|
|
33
|
-
* @returns {Promise<BasculeDepositStatus>} Deposit status promise
|
|
34
|
-
*/
|
|
35
|
-
export async function getBasculeDepositStatus({
|
|
36
|
-
rawPayload,
|
|
37
|
-
env,
|
|
38
|
-
...providerParams
|
|
39
|
-
}: ICheckBasculeDepositStatusParams) {
|
|
40
|
-
if (!rawPayload) {
|
|
41
|
-
throw new Error(NO_DEPOSIT_ID_ERROR);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const provider = new Provider(providerParams);
|
|
45
|
-
|
|
46
|
-
const tokenContract = getLbtcTokenContract(provider, env);
|
|
47
|
-
|
|
48
|
-
const basculeAddress: string = await tokenContract.methods.Bascule().call();
|
|
49
|
-
|
|
50
|
-
if (basculeAddress === ZERO_ADDRESS) {
|
|
51
|
-
return BasculeDepositStatus.REPORTED;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const basculeContract = getBasculeTokenContract(provider, basculeAddress);
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
const legacyHash = provider
|
|
58
|
-
.getReadWeb3()
|
|
59
|
-
.utils.keccak256(
|
|
60
|
-
Buffer.from(rawPayload.slice(8), 'hex') as unknown as Uint8Array,
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
const status: bigint = await basculeContract.methods
|
|
64
|
-
.depositHistory(legacyHash)
|
|
65
|
-
.call();
|
|
66
|
-
|
|
67
|
-
const depositStatus: BasculeDepositStatus = Number(status);
|
|
68
|
-
|
|
69
|
-
return depositStatus;
|
|
70
|
-
} catch (error) {
|
|
71
|
-
const errorMessage = getErrorMessage(error);
|
|
72
|
-
|
|
73
|
-
throw new Error(errorMessage);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { BasculeDepositStatus } from '../getBasculeDepositStatus';
|
|
2
|
-
|
|
3
|
-
export function throwBasculeDepositStatusError(status: BasculeDepositStatus) {
|
|
4
|
-
let errorMessage = '';
|
|
5
|
-
|
|
6
|
-
switch (status) {
|
|
7
|
-
case BasculeDepositStatus.UNREPORTED:
|
|
8
|
-
errorMessage = 'Checking Minting Status, try again in 30 seconds.';
|
|
9
|
-
break;
|
|
10
|
-
|
|
11
|
-
case BasculeDepositStatus.WITHDRAWN:
|
|
12
|
-
errorMessage =
|
|
13
|
-
'Funds have been withdrawn. Minting is currently disabled.';
|
|
14
|
-
break;
|
|
15
|
-
|
|
16
|
-
default:
|
|
17
|
-
errorMessage = 'Unknown Error';
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
throw new Error(errorMessage, { cause: true });
|
|
21
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { TChainId } from '../../common/types/types';
|
|
3
|
-
import { fromSatoshi } from '../../common/utils/convertSatoshi';
|
|
4
|
-
import { ReadProvider } from '../../provider/ReadProvider';
|
|
5
|
-
import { chainIdToEnv } from '../utils/chainIdToEnv';
|
|
6
|
-
import { getLbtcTokenContract } from '../utils/getLbtcTokenContract';
|
|
7
|
-
import { getRpcUrlConfigFromChain } from '../utils/getRpcUrlConfigFromChain';
|
|
8
|
-
|
|
9
|
-
export interface IGetLBTCMintingFeeParams {
|
|
10
|
-
/**
|
|
11
|
-
* Chain ID
|
|
12
|
-
*/
|
|
13
|
-
chainId: TChainId;
|
|
14
|
-
/**
|
|
15
|
-
* RPC URL
|
|
16
|
-
*/
|
|
17
|
-
rpcUrl?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get LBTC minting fee.
|
|
22
|
-
*
|
|
23
|
-
* @param chainId - Chain ID
|
|
24
|
-
* @param rpcUrl - RPC URL (optional)
|
|
25
|
-
*
|
|
26
|
-
* @returns LBTC minting fee
|
|
27
|
-
*/
|
|
28
|
-
export async function getLBTCMintingFee({
|
|
29
|
-
chainId,
|
|
30
|
-
rpcUrl,
|
|
31
|
-
}: IGetLBTCMintingFeeParams): Promise<BigNumber> {
|
|
32
|
-
const rpcUrlConfig = getRpcUrlConfigFromChain(chainId, rpcUrl);
|
|
33
|
-
const provider = new ReadProvider({ chainId, rpcUrlConfig });
|
|
34
|
-
const env = chainIdToEnv(chainId);
|
|
35
|
-
const tokenContract = getLbtcTokenContract(provider, env);
|
|
36
|
-
|
|
37
|
-
const fee: bigint = await tokenContract.methods.getMintFee().call();
|
|
38
|
-
const feeBtc = new BigNumber(fromSatoshi(fee.toString(10)));
|
|
39
|
-
|
|
40
|
-
return feeBtc;
|
|
41
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { defaultEnv } from '@lombard.finance/sdk-common';
|
|
3
|
-
import { Button } from '../../stories/components/Button';
|
|
4
|
-
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
5
|
-
import { useConnect } from '../../stories/hooks/useConnect';
|
|
6
|
-
import useQuery from '../../stories/hooks/useQuery';
|
|
7
|
-
import {
|
|
8
|
-
getLBTCTotalSupply,
|
|
9
|
-
ILBTCTotalSupplyParams,
|
|
10
|
-
} from './getLBTCTotalSupply';
|
|
11
|
-
|
|
12
|
-
const meta = {
|
|
13
|
-
title: 'Web3SDK/getLBTCTotalSupply',
|
|
14
|
-
component: StoryView,
|
|
15
|
-
tags: ['autodocs'],
|
|
16
|
-
} satisfies Meta<typeof StoryView>;
|
|
17
|
-
|
|
18
|
-
export default meta;
|
|
19
|
-
|
|
20
|
-
type Story = StoryObj<typeof meta>;
|
|
21
|
-
|
|
22
|
-
export const WithParams: Story = {
|
|
23
|
-
args: {
|
|
24
|
-
env: defaultEnv,
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
type TotalSupplyLBTCProps = Pick<ILBTCTotalSupplyParams, 'env'>;
|
|
29
|
-
|
|
30
|
-
export function StoryView(props: TotalSupplyLBTCProps) {
|
|
31
|
-
const { data: connectData, error: connectError } = useConnect();
|
|
32
|
-
|
|
33
|
-
const request = async () => {
|
|
34
|
-
return getLBTCTotalSupply({
|
|
35
|
-
chainId: 1,
|
|
36
|
-
rpcUrl: 'https://rpc.ankr.com/eth',
|
|
37
|
-
...props,
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
42
|
-
|
|
43
|
-
const formattedConnectData = connectData && {
|
|
44
|
-
account: connectData.account,
|
|
45
|
-
chainId: connectData.chainId,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<>
|
|
50
|
-
<div className="mb-4">
|
|
51
|
-
<CodeBlock text={connectError || formattedConnectData} />
|
|
52
|
-
</div>
|
|
53
|
-
<Button onClick={refetch} disabled={isLoading} isLoading={isLoading}>
|
|
54
|
-
Get Total LBTC Supply
|
|
55
|
-
</Button>
|
|
56
|
-
|
|
57
|
-
<CodeBlock text={error || data} />
|
|
58
|
-
</>
|
|
59
|
-
);
|
|
60
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { IReadProviderParams, ReadProvider } from '../../provider/ReadProvider';
|
|
2
|
-
import { TRpcUrlConfig } from '../../provider/rpcUrlConfig';
|
|
3
|
-
import { IEnvParam } from '../../common/types/internalTypes';
|
|
4
|
-
|
|
5
|
-
import { getLbtcTokenContract } from '../utils/getLbtcTokenContract';
|
|
6
|
-
|
|
7
|
-
export interface ILBTCTotalSupplyParams extends IEnvParam {
|
|
8
|
-
rpcUrl: string;
|
|
9
|
-
chainId: IReadProviderParams['chainId'];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function getLBTCTotalSupply({
|
|
13
|
-
env,
|
|
14
|
-
rpcUrl,
|
|
15
|
-
chainId,
|
|
16
|
-
}: ILBTCTotalSupplyParams): Promise<string> {
|
|
17
|
-
const rpcUrlConfig: TRpcUrlConfig = { [chainId]: rpcUrl };
|
|
18
|
-
|
|
19
|
-
const provider = new ReadProvider({ chainId, rpcUrlConfig });
|
|
20
|
-
|
|
21
|
-
const tokenContract = getLbtcTokenContract(provider, env);
|
|
22
|
-
|
|
23
|
-
const balance: bigint = await tokenContract.methods.totalSupply().call();
|
|
24
|
-
|
|
25
|
-
return balance.toString();
|
|
26
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { TChainId } from '../../common/types/types';
|
|
2
|
-
import { getErrorMessage } from '../../common/utils/getErrorMessage';
|
|
3
|
-
import { ReadProvider } from '../../provider/ReadProvider';
|
|
4
|
-
import { chainIdToEnv } from '../utils/chainIdToEnv';
|
|
5
|
-
import { getLbtcTokenContract } from '../utils/getLbtcTokenContract';
|
|
6
|
-
import { getRpcUrlConfigFromChain } from '../utils/getRpcUrlConfigFromChain';
|
|
7
|
-
|
|
8
|
-
export interface IGetPermitNonceParams {
|
|
9
|
-
/**
|
|
10
|
-
* Owner address to check permit nonce for
|
|
11
|
-
*/
|
|
12
|
-
owner: string;
|
|
13
|
-
/**
|
|
14
|
-
* Chain ID of the network
|
|
15
|
-
*/
|
|
16
|
-
chainId: TChainId;
|
|
17
|
-
/**
|
|
18
|
-
* RPC URL for the network (optional)
|
|
19
|
-
*/
|
|
20
|
-
rpcUrl?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Get permit nonce for a specific owner address from LBTC contract.
|
|
25
|
-
* This nonce is used in EIP-2612 permit operations.
|
|
26
|
-
*
|
|
27
|
-
* @param {IGetPermitNonceParams} params - Parameters for getting permit nonce
|
|
28
|
-
* @returns {Promise<string>} Promise that resolves to the permit nonce value
|
|
29
|
-
*/
|
|
30
|
-
export async function getPermitNonce({
|
|
31
|
-
owner,
|
|
32
|
-
rpcUrl,
|
|
33
|
-
chainId,
|
|
34
|
-
}: IGetPermitNonceParams): Promise<string> {
|
|
35
|
-
const rpcUrlConfig = getRpcUrlConfigFromChain(chainId, rpcUrl);
|
|
36
|
-
const provider = new ReadProvider({ chainId, rpcUrlConfig });
|
|
37
|
-
const env = chainIdToEnv(chainId);
|
|
38
|
-
const tokenContract = getLbtcTokenContract(provider, env);
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
const nonce: bigint = await tokenContract.methods.nonces(owner).call();
|
|
42
|
-
return nonce.toString();
|
|
43
|
-
} catch (error) {
|
|
44
|
-
const errorMessage = getErrorMessage(error);
|
|
45
|
-
throw new Error(errorMessage);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { TChainId } from '../../common/types/types';
|
|
3
|
-
import { ReadProvider } from '../../provider/ReadProvider';
|
|
4
|
-
import { getRpcUrlConfigFromChain } from '../utils/getRpcUrlConfigFromChain';
|
|
5
|
-
import { getErrorMessage } from '../../common/utils/getErrorMessage';
|
|
6
|
-
import { VAULTS } from '../../vaults';
|
|
7
|
-
import { fromSatoshi } from '../../common/utils/convertSatoshi';
|
|
8
|
-
|
|
9
|
-
export interface IGetShareValueParameters {
|
|
10
|
-
/**
|
|
11
|
-
* Chain ID for identifying the blockchain network (e.g., Ethereum, Binance Smart Chain, etc.)
|
|
12
|
-
*/
|
|
13
|
-
chainId: TChainId;
|
|
14
|
-
/**
|
|
15
|
-
* Optional RPC URL to connect to the blockchain. If not provided, a default RPC URL might be used.
|
|
16
|
-
*/
|
|
17
|
-
rpcUrl?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Optional vault key specifying the vault in use
|
|
20
|
-
* @default {string} - "veda"
|
|
21
|
-
*/
|
|
22
|
-
vaultKey?: 'veda';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Gets the value of a single share unit (in LBTC) from the specified vault.
|
|
27
|
-
*/
|
|
28
|
-
export async function getShareValue({
|
|
29
|
-
chainId,
|
|
30
|
-
rpcUrl,
|
|
31
|
-
vaultKey = 'veda',
|
|
32
|
-
}: IGetShareValueParameters): Promise<BigNumber> {
|
|
33
|
-
const vault = VAULTS[vaultKey];
|
|
34
|
-
if (!vault) {
|
|
35
|
-
throw new Error(`Unknown vault key: ${vaultKey}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (!(vault.chains as unknown as number[]).includes(chainId)) {
|
|
39
|
-
throw new Error(
|
|
40
|
-
`Unsupported chain id: ${chainId}. Please switch to one of the supported chains: ${vault.chains.join(', ')}`,
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const rpcUrlConfig = getRpcUrlConfigFromChain(chainId, rpcUrl);
|
|
45
|
-
const provider = new ReadProvider({ chainId, rpcUrlConfig });
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
const accountant = provider.createContract<
|
|
49
|
-
typeof vault.accountantContract.abi
|
|
50
|
-
>(vault.accountantContract.abi, vault.accountantContract.address);
|
|
51
|
-
|
|
52
|
-
const exchangeRate = await accountant.methods.getRate().call();
|
|
53
|
-
return fromSatoshi(String(exchangeRate));
|
|
54
|
-
} catch (error) {
|
|
55
|
-
const errorMessage = getErrorMessage(error);
|
|
56
|
-
throw new Error(errorMessage);
|
|
57
|
-
}
|
|
58
|
-
}
|