@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
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { IEnvParam } from '../../common/types/internalTypes';
|
|
2
|
-
import { TChainId } from '../../common/types/types';
|
|
3
|
-
import { Provider } from '../../provider';
|
|
4
|
-
import { IProviderBasedParams } from '../types';
|
|
5
|
-
import { getStakeAndBakeSpenderContract } from './contracts';
|
|
6
|
-
import { getStakeAndBakeTypedData } from './getTypedData';
|
|
7
|
-
import { getVerifyingContract } from './utils';
|
|
8
|
-
|
|
9
|
-
const NO_SIGNATURE_ERROR =
|
|
10
|
-
'Failed to obtain a valid signature. The response is undefined or invalid.';
|
|
11
|
-
|
|
12
|
-
export interface ISignStakeAndBakeParams
|
|
13
|
-
extends Pick<IProviderBasedParams, 'provider'>, IEnvParam {
|
|
14
|
-
/**
|
|
15
|
-
* The address to sign with (owner)
|
|
16
|
-
*/
|
|
17
|
-
address: string;
|
|
18
|
-
/**
|
|
19
|
-
* Chain ID for the signature
|
|
20
|
-
*/
|
|
21
|
-
chainId: TChainId;
|
|
22
|
-
/**
|
|
23
|
-
* The value to approve
|
|
24
|
-
*/
|
|
25
|
-
value: string;
|
|
26
|
-
/**
|
|
27
|
-
* Expiry date as a unix timestamp
|
|
28
|
-
*/
|
|
29
|
-
expiry: number;
|
|
30
|
-
/**
|
|
31
|
-
* Optional RPC URL for the network
|
|
32
|
-
*/
|
|
33
|
-
rpcUrl?: string;
|
|
34
|
-
/**
|
|
35
|
-
* The key of the vault to authorize
|
|
36
|
-
*/
|
|
37
|
-
vaultKey: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface ISignStakeAndBakeResult {
|
|
41
|
-
/**
|
|
42
|
-
* The signature
|
|
43
|
-
*/
|
|
44
|
-
signature: string;
|
|
45
|
-
/**
|
|
46
|
-
* The typed data used to generate the signature
|
|
47
|
-
*/
|
|
48
|
-
typedData: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Signs stake and bake authorization with EIP-712
|
|
53
|
-
*
|
|
54
|
-
* @param {ISignStakeAndBakeParams} params - Parameters for signing
|
|
55
|
-
* @returns {Promise<ISignStakeAndBakeResult>} The signature and typed data
|
|
56
|
-
*/
|
|
57
|
-
export async function signStakeAndBake({
|
|
58
|
-
address,
|
|
59
|
-
provider,
|
|
60
|
-
chainId,
|
|
61
|
-
value,
|
|
62
|
-
expiry,
|
|
63
|
-
rpcUrl,
|
|
64
|
-
vaultKey,
|
|
65
|
-
env
|
|
66
|
-
}: ISignStakeAndBakeParams): Promise<ISignStakeAndBakeResult> {
|
|
67
|
-
const providerInstance = new Provider({
|
|
68
|
-
provider,
|
|
69
|
-
account: address,
|
|
70
|
-
chainId,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const verifyingContract = getVerifyingContract(chainId, env);
|
|
74
|
-
const spender = getStakeAndBakeSpenderContract(chainId, vaultKey);
|
|
75
|
-
|
|
76
|
-
const typedDataObject = await getStakeAndBakeTypedData({
|
|
77
|
-
chainId,
|
|
78
|
-
expiry,
|
|
79
|
-
owner: address,
|
|
80
|
-
spender,
|
|
81
|
-
value,
|
|
82
|
-
rpcUrl,
|
|
83
|
-
verifyingContract,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const typedData = JSON.stringify(typedDataObject);
|
|
87
|
-
|
|
88
|
-
const signature = await providerInstance.web3?.currentProvider?.request<
|
|
89
|
-
'eth_signTypedData_v4',
|
|
90
|
-
string
|
|
91
|
-
>({
|
|
92
|
-
method: 'eth_signTypedData_v4',
|
|
93
|
-
params: [address, typedData],
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
if (typeof signature === 'string') {
|
|
97
|
-
return { signature, typedData };
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!signature?.result) {
|
|
101
|
-
throw new Error(NO_SIGNATURE_ERROR);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return { signature: signature.result, typedData };
|
|
105
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { TChainId } from '../../common/types/types';
|
|
2
|
-
import { getLbtcAddressConfig } from '../lbtcAddressConfig';
|
|
3
|
-
import { Env } from '@lombard.finance/sdk-common';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Gets the LBTC contract address for a given chain ID
|
|
7
|
-
* @param chainId The chain ID
|
|
8
|
-
* @param env
|
|
9
|
-
* @returns The LBTC contract address for the chain
|
|
10
|
-
*/
|
|
11
|
-
export const getVerifyingContract = (
|
|
12
|
-
chainId: TChainId,
|
|
13
|
-
env: Env = Env.prod,
|
|
14
|
-
): string => {
|
|
15
|
-
const lbtcAddressConfig = getLbtcAddressConfig(env);
|
|
16
|
-
const address = lbtcAddressConfig[chainId];
|
|
17
|
-
if (!address) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
`No LBTC contract address configured for chain ID ${chainId}`,
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return address;
|
|
23
|
-
};
|
package/src/web3Sdk/types.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { IEIP1193Provider, TChainId } from '../common/types/types';
|
|
2
|
-
|
|
3
|
-
export interface IProviderBasedParams {
|
|
4
|
-
/**
|
|
5
|
-
* The EIP-1193 provider instance.
|
|
6
|
-
*/
|
|
7
|
-
provider: IEIP1193Provider;
|
|
8
|
-
/**
|
|
9
|
-
* Current chain ID
|
|
10
|
-
*/
|
|
11
|
-
chainId: TChainId;
|
|
12
|
-
/**
|
|
13
|
-
* Current account address
|
|
14
|
-
*/
|
|
15
|
-
account: string;
|
|
16
|
-
}
|
|
@@ -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 { IUnstakeLBTCParams, unstakeLBTC } from './unstakeLBTC';
|
|
8
|
-
|
|
9
|
-
const meta = {
|
|
10
|
-
title: 'Web3SDK/unstakeLBTC',
|
|
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
|
-
btcAddress: '',
|
|
23
|
-
env: defaultEnv,
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
type ClaimLBTCProps = Pick<IUnstakeLBTCParams, 'btcAddress' | 'env' | 'amount'>;
|
|
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 unstakeLBTC({ ...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
|
-
Unstake LBTC
|
|
72
|
-
</Button>
|
|
73
|
-
|
|
74
|
-
<CodeBlock text={error || data} />
|
|
75
|
-
</>
|
|
76
|
-
);
|
|
77
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { getOutputScript } from '@lombard.finance/sdk-common';
|
|
2
|
-
import { IEnvParam } from '../../common/types/internalTypes';
|
|
3
|
-
import { toSatoshi } from '../../common/utils/convertSatoshi';
|
|
4
|
-
import { IWeb3SendResult, Provider } from '../../provider';
|
|
5
|
-
import { IProviderBasedParams } from '../types';
|
|
6
|
-
import { getGasMultiplier } from '../utils/getGasMultiplier';
|
|
7
|
-
import { getLbtcTokenContract } from '../utils/getLbtcTokenContract';
|
|
8
|
-
|
|
9
|
-
export interface IUnstakeLBTCParams extends IProviderBasedParams, IEnvParam {
|
|
10
|
-
/**
|
|
11
|
-
* The BTC address to send the unstaked BTC to.
|
|
12
|
-
*/
|
|
13
|
-
btcAddress: string;
|
|
14
|
-
/**
|
|
15
|
-
* The amount of LBTC to unstake.
|
|
16
|
-
*/
|
|
17
|
-
amount: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Unstakes LBTC to the specified BTC address.
|
|
22
|
-
*
|
|
23
|
-
* @param {IUnstakeLBTCParams} params
|
|
24
|
-
*
|
|
25
|
-
* @returns {Promise<IWeb3SendResult>} transaction promise
|
|
26
|
-
*/
|
|
27
|
-
export function unstakeLBTC({
|
|
28
|
-
btcAddress,
|
|
29
|
-
amount,
|
|
30
|
-
env,
|
|
31
|
-
...providerParams
|
|
32
|
-
}: IUnstakeLBTCParams): Promise<IWeb3SendResult> {
|
|
33
|
-
const provider = new Provider(providerParams);
|
|
34
|
-
const tokenContract = getLbtcTokenContract(provider, env);
|
|
35
|
-
const outputScript = getOutputScript(btcAddress, env);
|
|
36
|
-
|
|
37
|
-
const amountSat = toSatoshi(amount).toNumber();
|
|
38
|
-
|
|
39
|
-
const tx = tokenContract.methods.redeem(outputScript, amountSat);
|
|
40
|
-
|
|
41
|
-
return provider.sendTransactionAsync(
|
|
42
|
-
provider.account,
|
|
43
|
-
tokenContract.options.address,
|
|
44
|
-
{
|
|
45
|
-
data: tx.encodeABI(),
|
|
46
|
-
estimate: true,
|
|
47
|
-
estimateFee: true,
|
|
48
|
-
gasLimitMultiplier: getGasMultiplier(provider.chainId),
|
|
49
|
-
},
|
|
50
|
-
);
|
|
51
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { OChainId, TChainId } from '../../common/types/types';
|
|
2
|
-
import { Env } from '@lombard.finance/sdk-common';
|
|
3
|
-
|
|
4
|
-
const PROD_NATIVE_MINT_CHAINS = [
|
|
5
|
-
OChainId.ethereum,
|
|
6
|
-
OChainId.base,
|
|
7
|
-
OChainId.binanceSmartChain,
|
|
8
|
-
] as TChainId[];
|
|
9
|
-
|
|
10
|
-
export const chainIdToEnv = (chainId: TChainId): Env => {
|
|
11
|
-
return PROD_NATIVE_MINT_CHAINS.includes(chainId) ? Env.prod : Env.stage;
|
|
12
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Provider } from '../../provider';
|
|
2
|
-
import { BASCULE_ABI } from '../abi';
|
|
3
|
-
|
|
4
|
-
export function getBasculeTokenContract(
|
|
5
|
-
provider: Provider,
|
|
6
|
-
contractAddress: string,
|
|
7
|
-
) {
|
|
8
|
-
if (!contractAddress) {
|
|
9
|
-
throw new Error('The address for bascule module is not defined');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const contract = provider.createContract(BASCULE_ABI, contractAddress);
|
|
13
|
-
|
|
14
|
-
if (!contract.options.address) {
|
|
15
|
-
contract.options.address = contractAddress;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return contract as typeof contract & {
|
|
19
|
-
options: typeof contract.options & { address: string };
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { OChainId } from '../../common/types/types';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns the gas multiplier for the given chain ID.
|
|
5
|
-
*
|
|
6
|
-
* @param chainId - Chain ID.
|
|
7
|
-
*
|
|
8
|
-
* @returns Gas multiplier.
|
|
9
|
-
*/
|
|
10
|
-
export function getGasMultiplier(chainId: number): number {
|
|
11
|
-
switch (chainId) {
|
|
12
|
-
case OChainId.ethereum:
|
|
13
|
-
return 1.3;
|
|
14
|
-
case OChainId.holesky:
|
|
15
|
-
case OChainId.sepolia:
|
|
16
|
-
return 1.5;
|
|
17
|
-
default:
|
|
18
|
-
return 1.3;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ReadProvider } from '../../provider/ReadProvider';
|
|
2
|
-
import { Env } from '@lombard.finance/sdk-common';
|
|
3
|
-
import { isValidChain } from '../../common/utils/isValidChain';
|
|
4
|
-
import { Provider } from '../../provider';
|
|
5
|
-
import { getLbtcAddressConfig } from '../lbtcAddressConfig';
|
|
6
|
-
import { getTokenABI } from './getTokenABI';
|
|
7
|
-
|
|
8
|
-
export function getLbtcTokenContract(
|
|
9
|
-
provider: Provider | ReadProvider,
|
|
10
|
-
env?: Env,
|
|
11
|
-
) {
|
|
12
|
-
const lbtcAddressConfig = getLbtcAddressConfig(env);
|
|
13
|
-
const { chainId } = provider;
|
|
14
|
-
|
|
15
|
-
if (!isValidChain(chainId)) {
|
|
16
|
-
throw new Error(`This chain ${chainId} is not supported`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const tokenAddress = lbtcAddressConfig[chainId];
|
|
20
|
-
|
|
21
|
-
if (!tokenAddress) {
|
|
22
|
-
throw new Error(`Token address for chain ${chainId} is not defined`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const abi = getTokenABI('LBTC');
|
|
26
|
-
|
|
27
|
-
const contract = provider.createContract(abi, tokenAddress);
|
|
28
|
-
|
|
29
|
-
if (!contract.options.address) {
|
|
30
|
-
contract.options.address = tokenAddress;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return contract as typeof contract & {
|
|
34
|
-
options: typeof contract.options & { address: string };
|
|
35
|
-
};
|
|
36
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { TChainId } from '../../common/types/types';
|
|
2
|
-
import { isValidChain } from '../../common/utils/isValidChain';
|
|
3
|
-
import {
|
|
4
|
-
rpcUrlConfig as defaultRpcUrlConfig,
|
|
5
|
-
TRpcUrlConfig,
|
|
6
|
-
} from '../../provider/rpcUrlConfig';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Get RPC URL configuration for a specific chain.
|
|
10
|
-
* Validates chain support and RPC URL availability.
|
|
11
|
-
*
|
|
12
|
-
* @param {TChainId} chainId - Chain ID to get RPC config for
|
|
13
|
-
* @param {string} [rpcUrl] - Optional custom RPC URL
|
|
14
|
-
* @returns {TRpcUrlConfig} RPC URL configuration for the chain
|
|
15
|
-
* @throws {Error} If chain is not supported or RPC URL is not found
|
|
16
|
-
*/
|
|
17
|
-
export function getRpcUrlConfigFromChain(
|
|
18
|
-
chainId: TChainId,
|
|
19
|
-
rpcUrl?: string,
|
|
20
|
-
): TRpcUrlConfig {
|
|
21
|
-
if (!isValidChain(chainId)) {
|
|
22
|
-
throw new Error(`This chain ${chainId} is not supported`);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const rpcUrlConfig: TRpcUrlConfig = rpcUrl
|
|
26
|
-
? { [chainId]: rpcUrl }
|
|
27
|
-
: defaultRpcUrlConfig;
|
|
28
|
-
|
|
29
|
-
if (!rpcUrlConfig[chainId]) {
|
|
30
|
-
throw new Error(`RPC URL for chainId ${chainId} not found`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return rpcUrlConfig;
|
|
34
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|