@lombard.finance/sdk 2.5.2 → 3.2.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 +483 -396
- 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 +79 -8269
- package/dist/index.js.map +1 -1
- package/dist/index2.cjs +63 -0
- package/dist/index2.cjs.map +1 -0
- package/dist/index2.js +17989 -0
- package/dist/index2.js.map +1 -0
- package/package.json +10 -10
- 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 +23 -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 +9 -9
- 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 +15 -10
- package/src/api-functions/getUserStakeAndBakeSignature/getUserStakeAndBakeSignature.stories.tsx +69 -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/bridge/abi/CCIP_BRIDGE_ADAPTER_ABI.json +704 -0
- package/src/bridge/abi/OFT_BRIDGE_ADAPTER_ABI.json +912 -0
- package/src/bridge/index.ts +11 -0
- package/src/bridge/lib/bridge.stories.tsx +89 -0
- package/src/bridge/lib/bridge.ts +101 -0
- package/src/bridge/lib/ccip-bridge.stories.tsx +90 -0
- package/src/bridge/lib/ccip-bridge.ts +163 -0
- package/src/bridge/lib/config.ts +338 -0
- package/src/bridge/lib/oft-bridge.stories.tsx +89 -0
- package/src/bridge/lib/oft-bridge.ts +212 -0
- 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} +9 -3
- package/src/common/blockchain-identifier.ts +134 -0
- package/src/common/chains.ts +84 -0
- package/src/common/contract-info.ts +8 -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 +65 -0
- package/src/{web3Sdk → contract-functions}/claimLBTC/claimLBTC.stories.tsx +22 -30
- package/src/contract-functions/claimLBTC/claimLBTC.ts +90 -0
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.stories.tsx +50 -0
- package/src/contract-functions/getBasculeDepositStatus/getBasculeDepositStatus.ts +127 -0
- package/src/{web3Sdk → contract-functions}/getLBTCMintingFee/getLBTCMintingFee.stories.tsx +15 -11
- package/src/contract-functions/getLBTCMintingFee/getLBTCMintingFee.tsx +37 -0
- package/src/{vaults/lib/get-vault-points.stories.tsx → contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.stories.tsx} +13 -16
- package/src/contract-functions/getLBTCTotalSupply/getLBTCTotalSupply.ts +34 -0
- package/src/{web3Sdk → contract-functions}/getPermitNonce/getPermitNonce.stories.tsx +12 -22
- package/src/contract-functions/getPermitNonce/getPermitNonce.ts +45 -0
- package/src/{web3Sdk → contract-functions}/getShareValue/getShareValue.stories.tsx +12 -7
- package/src/contract-functions/getShareValue/getShareValue.ts +58 -0
- package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.stories.tsx +14 -9
- package/src/{web3Sdk → contract-functions}/getSharesByAddress/getSharesByAddress.ts +29 -28
- package/src/{web3Sdk → contract-functions}/getStakeAndBakeFee/getStakeAndBakeFee.stories.tsx +29 -16
- package/src/contract-functions/getStakeAndBakeFee/getStakeAndBakeFee.tsx +65 -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 +99 -0
- package/src/contract-functions/signStakeAndBake/index.ts +1 -0
- package/src/{web3Sdk → contract-functions}/signStakeAndBake/signStakeAndBake.stories.tsx +29 -41
- package/src/contract-functions/signStakeAndBake/signStakeAndBake.ts +145 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.stories.tsx +80 -0
- package/src/contract-functions/unstakeLBTC/unstakeLBTC.ts +66 -0
- package/src/index.ts +40 -17
- package/src/metrics/get-lbtc-stats.stories.tsx +51 -0
- package/src/metrics/get-lbtc-stats.ts +38 -0
- 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/{web3Sdk/abi/LBTC.json → tokens/abi/LBTC_ABI.json} +1 -1
- package/src/tokens/abi/LBTC_ABI.ts +1761 -0
- package/src/tokens/abi/LBTC_BASCULE_ABI.json +850 -0
- package/src/tokens/lbtc-addresses.ts +55 -0
- package/src/tokens/token-addresses.ts +32 -0
- package/src/tokens/tokens.ts +120 -0
- package/src/utils/env.ts +12 -0
- package/src/utils/hex.ts +2 -2
- package/src/utils/numbers.ts +8 -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 +36 -69
- package/src/vaults/lib/config.ts +196 -0
- package/src/vaults/lib/metrics/get-vault-apy.stories.tsx +57 -0
- package/src/vaults/lib/metrics/get-vault-apy.ts +132 -0
- package/src/vaults/lib/metrics/get-vault-points.stories.tsx +59 -0
- package/src/vaults/lib/{get-vault-points.ts → metrics/get-vault-points.ts} +14 -10
- package/src/vaults/lib/metrics/get-vault-tvl.stories.tsx +57 -0
- package/src/vaults/lib/metrics/get-vault-tvl.ts +119 -0
- package/src/vaults/lib/ops/cancel-withdraw.stories.tsx +79 -0
- package/src/vaults/lib/ops/deposit.stories.tsx +81 -0
- package/src/vaults/lib/ops/deposit.ts +151 -0
- package/src/vaults/lib/{get-vault-deposits.stories.tsx → ops/get-vault-deposits.stories.tsx} +20 -14
- package/src/vaults/lib/{get-vault-deposits.ts → ops/get-vault-deposits.ts} +45 -22
- package/src/vaults/lib/{get-vault-withdrawals.stories.tsx → ops/get-vault-withdrawals.stories.tsx} +20 -13
- package/src/vaults/lib/{get-vault-withdrawals.ts → ops/get-vault-withdrawals.ts} +72 -38
- package/src/vaults/lib/ops/withdraw.stories.tsx +81 -0
- package/src/vaults/lib/ops/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/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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CHAIN_ID_TO_VIEM_CHAIN_MAP, ChainId } from '../common/chains';
|
|
2
|
+
import {
|
|
3
|
+
createWalletClient,
|
|
4
|
+
custom,
|
|
5
|
+
EIP1193Provider,
|
|
6
|
+
WalletClient,
|
|
7
|
+
} from 'viem';
|
|
8
|
+
|
|
9
|
+
type MakeClientParameters = {
|
|
10
|
+
provider: EIP1193Provider;
|
|
11
|
+
chainId: ChainId;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Creates the client for specified `chainId`.
|
|
16
|
+
* @param chainId - The chain id
|
|
17
|
+
* @param rpcUrl - The overridden RPC url for specified chain id.
|
|
18
|
+
* @returns The public client instance
|
|
19
|
+
*/
|
|
20
|
+
export function makeWalletClient({
|
|
21
|
+
provider,
|
|
22
|
+
chainId,
|
|
23
|
+
}: MakeClientParameters): WalletClient {
|
|
24
|
+
const chain = CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId];
|
|
25
|
+
const transport = custom(provider);
|
|
26
|
+
|
|
27
|
+
const client = createWalletClient({
|
|
28
|
+
chain,
|
|
29
|
+
transport,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return client as WalletClient<typeof transport>;
|
|
33
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Env } from '@lombard.finance/sdk-common';
|
|
1
|
+
import { DEFAULT_ENV, Env } from '@lombard.finance/sdk-common';
|
|
3
2
|
|
|
4
3
|
interface IApiConfig {
|
|
5
4
|
baseApiUrl: string;
|
|
@@ -21,8 +20,15 @@ const prodConfig: IApiConfig = {
|
|
|
21
20
|
bffApiUrl: 'https://bff.prod.lombard.finance',
|
|
22
21
|
};
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
const devConfig: IApiConfig = {
|
|
24
|
+
baseApiUrl: 'https://staging.prod.lombard.finance',
|
|
25
|
+
bffApiUrl: 'http://localhost:8001',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const getApiConfig = (env: Env = DEFAULT_ENV): IApiConfig => {
|
|
25
29
|
switch (env) {
|
|
30
|
+
case Env.dev:
|
|
31
|
+
return devConfig;
|
|
26
32
|
case Env.prod:
|
|
27
33
|
return prodConfig;
|
|
28
34
|
case Env.testnet:
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { DEFAULT_ENV, Env } from '@lombard.finance/sdk-common';
|
|
2
|
+
import {
|
|
3
|
+
ChainId,
|
|
4
|
+
SOLANA_DEVNET_CHAIN,
|
|
5
|
+
SOLANA_MAINNET_CHAIN,
|
|
6
|
+
SOLANA_TESTNET_CHAIN,
|
|
7
|
+
SUI_MAINNET_CHAIN,
|
|
8
|
+
SUI_TESTNET_CHAIN,
|
|
9
|
+
SolanaChain,
|
|
10
|
+
SuiChain,
|
|
11
|
+
} from './chains';
|
|
12
|
+
|
|
13
|
+
export const BlockchainIdentifier = {
|
|
14
|
+
eth: 'DESTINATION_BLOCKCHAIN_ETHEREUM',
|
|
15
|
+
ethOld: 'BLOCKCHAIN_ETHEREUM',
|
|
16
|
+
|
|
17
|
+
base: 'DESTINATION_BLOCKCHAIN_BASE',
|
|
18
|
+
baseOld: 'BLOCKCHAIN_BASE',
|
|
19
|
+
|
|
20
|
+
bsc: 'DESTINATION_BLOCKCHAIN_BSC',
|
|
21
|
+
bscOld: 'BLOCKCHAIN_BSC',
|
|
22
|
+
|
|
23
|
+
sui: 'DESTINATION_BLOCKCHAIN_SUI',
|
|
24
|
+
suiOld: 'BLOCKCHAIN_SUI',
|
|
25
|
+
|
|
26
|
+
sonic: 'DESTINATION_BLOCKCHAIN_SONIC',
|
|
27
|
+
sonicOld: 'BLOCKCHAIN_SONIC',
|
|
28
|
+
|
|
29
|
+
solana: 'DESTINATION_BLOCKCHAIN_SOLANA',
|
|
30
|
+
solanaOld: 'BLOCKCHAIN_SOLANA',
|
|
31
|
+
} as const;
|
|
32
|
+
|
|
33
|
+
export type BlockchainIdentifier =
|
|
34
|
+
(typeof BlockchainIdentifier)[keyof typeof BlockchainIdentifier];
|
|
35
|
+
|
|
36
|
+
export function getChainNameById(
|
|
37
|
+
chainId: ChainId | SuiChain | SolanaChain,
|
|
38
|
+
): BlockchainIdentifier {
|
|
39
|
+
if (
|
|
40
|
+
chainId === ChainId.ethereum ||
|
|
41
|
+
chainId === ChainId.holesky ||
|
|
42
|
+
chainId === ChainId.sepolia
|
|
43
|
+
) {
|
|
44
|
+
return BlockchainIdentifier.eth;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (chainId === ChainId.base || chainId === ChainId.baseSepoliaTestnet) {
|
|
48
|
+
return BlockchainIdentifier.base;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (
|
|
52
|
+
chainId === ChainId.binanceSmartChain ||
|
|
53
|
+
chainId === ChainId.binanceSmartChainTestnet
|
|
54
|
+
) {
|
|
55
|
+
return BlockchainIdentifier.bsc;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (chainId === ChainId.sonic || chainId === ChainId.sonicBlazeTestnet) {
|
|
59
|
+
return BlockchainIdentifier.sonic;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (chainId === SUI_TESTNET_CHAIN || chainId === SUI_MAINNET_CHAIN) {
|
|
63
|
+
return BlockchainIdentifier.sui;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (
|
|
67
|
+
chainId === SOLANA_DEVNET_CHAIN ||
|
|
68
|
+
chainId === SOLANA_TESTNET_CHAIN ||
|
|
69
|
+
chainId === SOLANA_MAINNET_CHAIN
|
|
70
|
+
) {
|
|
71
|
+
return BlockchainIdentifier.solana;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
throw new Error(`Unknown chain ID: ${chainId}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const getEthNetworkByEnv = (env: Env) =>
|
|
78
|
+
env === Env.prod ? ChainId.ethereum : ChainId.holesky;
|
|
79
|
+
|
|
80
|
+
export const getBscNetworkByEnv = (env: Env) =>
|
|
81
|
+
env === Env.prod
|
|
82
|
+
? ChainId.binanceSmartChain
|
|
83
|
+
: ChainId.binanceSmartChainTestnet;
|
|
84
|
+
|
|
85
|
+
export const getBaseNetworkByEnv = (env: Env) =>
|
|
86
|
+
env === Env.prod ? ChainId.base : ChainId.baseSepoliaTestnet;
|
|
87
|
+
|
|
88
|
+
export const getSuiNetworkByEnv = (env: Env) =>
|
|
89
|
+
env === Env.prod ? SUI_MAINNET_CHAIN : SUI_TESTNET_CHAIN;
|
|
90
|
+
|
|
91
|
+
export const getSonicNetworkByEnv = (env: Env) =>
|
|
92
|
+
env === Env.prod ? ChainId.sonic : ChainId.sonicBlazeTestnet;
|
|
93
|
+
|
|
94
|
+
export const getSolanaNetworkByEnv = (env: Env) =>
|
|
95
|
+
env === Env.prod ? SOLANA_MAINNET_CHAIN : SOLANA_DEVNET_CHAIN;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param chain the chain ID
|
|
99
|
+
* @param env
|
|
100
|
+
* @returns the chain name
|
|
101
|
+
*/
|
|
102
|
+
export function getChainIdByName(
|
|
103
|
+
chain: string,
|
|
104
|
+
env: Env = DEFAULT_ENV,
|
|
105
|
+
): ChainId | SuiChain | SolanaChain {
|
|
106
|
+
switch (chain as BlockchainIdentifier) {
|
|
107
|
+
case BlockchainIdentifier.eth:
|
|
108
|
+
case BlockchainIdentifier.ethOld:
|
|
109
|
+
return getEthNetworkByEnv(env);
|
|
110
|
+
|
|
111
|
+
case BlockchainIdentifier.base:
|
|
112
|
+
case BlockchainIdentifier.baseOld:
|
|
113
|
+
return getBaseNetworkByEnv(env);
|
|
114
|
+
|
|
115
|
+
case BlockchainIdentifier.bsc:
|
|
116
|
+
case BlockchainIdentifier.bscOld:
|
|
117
|
+
return getBscNetworkByEnv(env);
|
|
118
|
+
|
|
119
|
+
case BlockchainIdentifier.sui:
|
|
120
|
+
case BlockchainIdentifier.suiOld:
|
|
121
|
+
return getSuiNetworkByEnv(env);
|
|
122
|
+
|
|
123
|
+
case BlockchainIdentifier.sonic:
|
|
124
|
+
case BlockchainIdentifier.sonicOld:
|
|
125
|
+
return getSonicNetworkByEnv(env);
|
|
126
|
+
|
|
127
|
+
case BlockchainIdentifier.solana:
|
|
128
|
+
case BlockchainIdentifier.solanaOld:
|
|
129
|
+
return getSolanaNetworkByEnv(env);
|
|
130
|
+
|
|
131
|
+
default:
|
|
132
|
+
return ChainId.ethereum;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
base,
|
|
3
|
+
baseSepolia,
|
|
4
|
+
berachain,
|
|
5
|
+
berachainTestnetbArtio,
|
|
6
|
+
bsc,
|
|
7
|
+
bscTestnet,
|
|
8
|
+
corn,
|
|
9
|
+
etherlink,
|
|
10
|
+
holesky,
|
|
11
|
+
mainnet,
|
|
12
|
+
morph,
|
|
13
|
+
morphHolesky,
|
|
14
|
+
sepolia,
|
|
15
|
+
sonic,
|
|
16
|
+
sonicBlazeTestnet,
|
|
17
|
+
swellchain,
|
|
18
|
+
} from 'viem/chains';
|
|
19
|
+
|
|
20
|
+
export const SUI_DEVNET_CHAIN = 'sui:devnet' as const;
|
|
21
|
+
export const SUI_TESTNET_CHAIN = 'sui:testnet' as const;
|
|
22
|
+
export const SUI_LOCALNET_CHAIN = 'sui:localnet' as const;
|
|
23
|
+
export const SUI_MAINNET_CHAIN = 'sui:mainnet' as const;
|
|
24
|
+
|
|
25
|
+
export type SuiChain =
|
|
26
|
+
| typeof SUI_DEVNET_CHAIN
|
|
27
|
+
| typeof SUI_TESTNET_CHAIN
|
|
28
|
+
| typeof SUI_LOCALNET_CHAIN
|
|
29
|
+
| typeof SUI_MAINNET_CHAIN;
|
|
30
|
+
|
|
31
|
+
export const SOLANA_MAINNET_CHAIN = 'solana:mainnet-beta' as const;
|
|
32
|
+
export const SOLANA_TESTNET_CHAIN = 'solana:testnet' as const;
|
|
33
|
+
export const SOLANA_DEVNET_CHAIN = 'solana:devnet' as const;
|
|
34
|
+
|
|
35
|
+
export type SolanaChain =
|
|
36
|
+
| typeof SOLANA_MAINNET_CHAIN
|
|
37
|
+
| typeof SOLANA_TESTNET_CHAIN
|
|
38
|
+
| typeof SOLANA_DEVNET_CHAIN;
|
|
39
|
+
|
|
40
|
+
export const ChainId = {
|
|
41
|
+
ethereum: 1,
|
|
42
|
+
base: 8453,
|
|
43
|
+
berachain: 80094,
|
|
44
|
+
binanceSmartChain: 56,
|
|
45
|
+
corn: 21000000,
|
|
46
|
+
etherlink: 42793,
|
|
47
|
+
morph: 2818,
|
|
48
|
+
sonic: 146,
|
|
49
|
+
swell: 1923,
|
|
50
|
+
// Testnets:
|
|
51
|
+
baseSepoliaTestnet: 84532,
|
|
52
|
+
berachainBartioTestnet: 80084,
|
|
53
|
+
binanceSmartChainTestnet: 97,
|
|
54
|
+
holesky: 17000,
|
|
55
|
+
morphHolesky: 2810,
|
|
56
|
+
sepolia: 11155111,
|
|
57
|
+
sonicBlazeTestnet: 57054,
|
|
58
|
+
} as const;
|
|
59
|
+
|
|
60
|
+
export type ChainId = (typeof ChainId)[keyof typeof ChainId];
|
|
61
|
+
|
|
62
|
+
export const CHAIN_ID_TO_VIEM_CHAIN_MAP = {
|
|
63
|
+
[ChainId.ethereum]: mainnet,
|
|
64
|
+
[ChainId.base]: base,
|
|
65
|
+
[ChainId.berachain]: berachain,
|
|
66
|
+
[ChainId.binanceSmartChain]: bsc,
|
|
67
|
+
[ChainId.corn]: corn,
|
|
68
|
+
[ChainId.etherlink]: etherlink,
|
|
69
|
+
[ChainId.morph]: morph,
|
|
70
|
+
[ChainId.sonic]: sonic,
|
|
71
|
+
[ChainId.swell]: swellchain,
|
|
72
|
+
// Testnets:
|
|
73
|
+
[ChainId.baseSepoliaTestnet]: baseSepolia,
|
|
74
|
+
[ChainId.berachainBartioTestnet]: berachainTestnetbArtio,
|
|
75
|
+
[ChainId.binanceSmartChainTestnet]: bscTestnet,
|
|
76
|
+
[ChainId.holesky]: holesky,
|
|
77
|
+
[ChainId.morphHolesky]: morphHolesky,
|
|
78
|
+
[ChainId.sepolia]: sepolia,
|
|
79
|
+
[ChainId.sonicBlazeTestnet]: sonicBlazeTestnet,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export function isValidChain(chainId: number): chainId is ChainId {
|
|
83
|
+
return Object.values(ChainId).includes(chainId as ChainId);
|
|
84
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Env } from '@lombard.finance/sdk-common';
|
|
2
|
+
import { ChainId } from './chains';
|
|
3
|
+
import { Address, EIP1193Provider } from 'viem';
|
|
4
|
+
|
|
5
|
+
export interface IEnvParam {
|
|
6
|
+
/**
|
|
7
|
+
* Optional environment identifier. If not provided, it defaults to `prod`.
|
|
8
|
+
*
|
|
9
|
+
* @default Env.prod
|
|
10
|
+
*/
|
|
11
|
+
env?: Env;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CommonParameters extends IEnvParam {
|
|
15
|
+
/**
|
|
16
|
+
* Chain ID for identifying the blockchain network (e.g., Ethereum, Binance Smart Chain, etc.)
|
|
17
|
+
*/
|
|
18
|
+
chainId: ChainId;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Optional RPC URL to connect to the blockchain. If not provided, a default RPC URL might be used.
|
|
22
|
+
*/
|
|
23
|
+
rpcUrl?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface CommonReadParameters extends CommonParameters {
|
|
27
|
+
/**
|
|
28
|
+
* The account address.
|
|
29
|
+
*/
|
|
30
|
+
account: Address;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface CommonOptionalWriteParameters extends CommonParameters {
|
|
34
|
+
/**
|
|
35
|
+
* The provider (required). An instance of the `EIP1193Provider` which adheres to the EIP-1193 standard for communication with Ethereum-compatible providers.
|
|
36
|
+
* @type {EIP1193Provider}
|
|
37
|
+
*/
|
|
38
|
+
provider?: EIP1193Provider;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface CommonWriteParameters extends CommonParameters {
|
|
42
|
+
/**
|
|
43
|
+
* The account address.
|
|
44
|
+
*/
|
|
45
|
+
account: Address;
|
|
46
|
+
/**
|
|
47
|
+
* An instance of the `EIP1193Provider` which adheres to the EIP-1193 standard for communication with Ethereum-compatible providers.
|
|
48
|
+
* @type {EIP1193Provider}
|
|
49
|
+
*/
|
|
50
|
+
provider: EIP1193Provider;
|
|
51
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Button } from '../../stories/components/Button';
|
|
3
|
+
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
4
|
+
import {
|
|
5
|
+
canPerformAction,
|
|
6
|
+
useConnection,
|
|
7
|
+
} from '../../stories/hooks/useConnection';
|
|
8
|
+
import useQuery from '../../stories/hooks/useQuery';
|
|
9
|
+
import { approveLBTC, IApproveLBTCParams } from './approveLBTC';
|
|
10
|
+
import { Vault, VAULTS } from '../../vaults/lib/config';
|
|
11
|
+
import { ChainId } from '../../common/chains';
|
|
12
|
+
import { Env } from '@lombard.finance/sdk-common';
|
|
13
|
+
import {
|
|
14
|
+
functionType,
|
|
15
|
+
wagmiDecorator,
|
|
16
|
+
} from '../../stories/components/decorators';
|
|
17
|
+
import { ConnectButton } from '../../stories/components/ConnectButton';
|
|
18
|
+
|
|
19
|
+
const meta = {
|
|
20
|
+
title: 'write/approveLBTC',
|
|
21
|
+
component: StoryView,
|
|
22
|
+
tags: ['autodocs'],
|
|
23
|
+
decorators: [wagmiDecorator, functionType('write')],
|
|
24
|
+
} satisfies Meta<typeof StoryView>;
|
|
25
|
+
|
|
26
|
+
export default meta;
|
|
27
|
+
|
|
28
|
+
type Story = StoryObj<typeof meta>;
|
|
29
|
+
|
|
30
|
+
export const WithParams: Story = {
|
|
31
|
+
args: {
|
|
32
|
+
chainId: ChainId.holesky,
|
|
33
|
+
spender: VAULTS[Vault.Veda].spenderContracts[ChainId.holesky]?.address,
|
|
34
|
+
amount: 0.00001,
|
|
35
|
+
env: Env.stage,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type Props = Omit<IApproveLBTCParams, 'account' | 'provider'>;
|
|
40
|
+
|
|
41
|
+
export function StoryView(props: Props) {
|
|
42
|
+
const connection = useConnection();
|
|
43
|
+
|
|
44
|
+
const request = async () => {
|
|
45
|
+
if (!canPerformAction(connection)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return approveLBTC({
|
|
50
|
+
...props,
|
|
51
|
+
|
|
52
|
+
account: connection.account.address,
|
|
53
|
+
// chainId: connection.account.chainId,
|
|
54
|
+
provider: connection.provider,
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<>
|
|
62
|
+
<div className="mb-4">
|
|
63
|
+
<ConnectButton />
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<Button
|
|
67
|
+
onClick={refetch}
|
|
68
|
+
disabled={isLoading || !connection.account.address}
|
|
69
|
+
isLoading={isLoading}
|
|
70
|
+
actionName={approveLBTC.name}
|
|
71
|
+
/>
|
|
72
|
+
|
|
73
|
+
<CodeBlock text={error || data} />
|
|
74
|
+
</>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CHAIN_ID_TO_VIEM_CHAIN_MAP } from '../../common/chains';
|
|
2
|
+
import { makeWalletClient } from '../../clients/wallet-client';
|
|
3
|
+
import { CommonWriteParameters } from '../../common/parameters';
|
|
4
|
+
import { toSatoshi } from '../../utils/satoshi';
|
|
5
|
+
import { Address, Hash } from 'viem';
|
|
6
|
+
import { makePublicClient } from '../../clients/public-client';
|
|
7
|
+
import BigNumber from 'bignumber.js';
|
|
8
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
9
|
+
import { Token } from '../../tokens/token-addresses';
|
|
10
|
+
|
|
11
|
+
export interface IApproveLBTCParams extends CommonWriteParameters {
|
|
12
|
+
/**
|
|
13
|
+
* The spender account address.
|
|
14
|
+
*/
|
|
15
|
+
spender: Address;
|
|
16
|
+
/**
|
|
17
|
+
* The approved amount of LBTC.
|
|
18
|
+
*/
|
|
19
|
+
amount: BigNumber.Value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Approves the provided spender to withdraw a specified amount of LBTC from
|
|
24
|
+
* your account.
|
|
25
|
+
*
|
|
26
|
+
* @param {IApproveLBTCParams} parameters - The parameters.
|
|
27
|
+
* @param {Address} spender - The spender account address.
|
|
28
|
+
* @param {BigNumber.Value} - The amount of LBTC.
|
|
29
|
+
* @param {Address} parameters.account - The EVM account address.
|
|
30
|
+
* @param {ChainId} parameters.chainId - The chain id.
|
|
31
|
+
* @param {EIP1193Provider} parameters.provider - The EIP1193 provider.
|
|
32
|
+
* @param {string} parameters.rpcUrl - The optional rpc url.
|
|
33
|
+
* @param {Env} parameters.env - The optional environment identifier.
|
|
34
|
+
*
|
|
35
|
+
* @returns {Promise<Hash>}
|
|
36
|
+
*/
|
|
37
|
+
export async function approveLBTC({
|
|
38
|
+
account,
|
|
39
|
+
spender,
|
|
40
|
+
amount,
|
|
41
|
+
chainId,
|
|
42
|
+
provider,
|
|
43
|
+
rpcUrl,
|
|
44
|
+
env,
|
|
45
|
+
}: IApproveLBTCParams): Promise<Hash> {
|
|
46
|
+
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
47
|
+
const walletClient = makeWalletClient({ chainId, provider });
|
|
48
|
+
|
|
49
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
|
|
50
|
+
|
|
51
|
+
const amountSat = toSatoshi(amount).toNumber();
|
|
52
|
+
|
|
53
|
+
const { request } = await publicClient.simulateContract({
|
|
54
|
+
address: lbtcContract.address,
|
|
55
|
+
account,
|
|
56
|
+
chain: CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId],
|
|
57
|
+
abi: lbtcContract.abi,
|
|
58
|
+
functionName: 'approve',
|
|
59
|
+
args: [spender, BigInt(amountSat)],
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const txHash = await walletClient.writeContract(request);
|
|
63
|
+
|
|
64
|
+
return txHash;
|
|
65
|
+
}
|
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_ENV } from '@lombard.finance/sdk-common';
|
|
3
3
|
import { Button } from '../../stories/components/Button';
|
|
4
4
|
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
canPerformAction,
|
|
7
|
+
useConnection,
|
|
8
|
+
} from '../../stories/hooks/useConnection';
|
|
6
9
|
import useQuery from '../../stories/hooks/useQuery';
|
|
7
10
|
import { claimLBTC, IClaimLBTCParams } from './claimLBTC';
|
|
11
|
+
import {
|
|
12
|
+
functionType,
|
|
13
|
+
wagmiDecorator,
|
|
14
|
+
} from '../../stories/components/decorators';
|
|
15
|
+
import { ConnectButton } from '../../stories/components/ConnectButton';
|
|
8
16
|
|
|
9
17
|
const meta = {
|
|
10
|
-
title: '
|
|
18
|
+
title: 'write/claimLBTC',
|
|
11
19
|
component: StoryView,
|
|
12
20
|
tags: ['autodocs'],
|
|
21
|
+
decorators: [wagmiDecorator, functionType('write')],
|
|
13
22
|
} satisfies Meta<typeof StoryView>;
|
|
14
23
|
|
|
15
24
|
export default meta;
|
|
@@ -20,59 +29,42 @@ export const WithParams: Story = {
|
|
|
20
29
|
args: {
|
|
21
30
|
proofSignature: '',
|
|
22
31
|
data: '',
|
|
23
|
-
env:
|
|
32
|
+
env: DEFAULT_ENV,
|
|
24
33
|
},
|
|
25
34
|
};
|
|
26
35
|
|
|
27
36
|
type ClaimLBTCProps = Pick<IClaimLBTCParams, 'data' | 'env' | 'proofSignature'>;
|
|
28
37
|
|
|
29
38
|
export function StoryView(props: ClaimLBTCProps) {
|
|
30
|
-
const
|
|
31
|
-
data: connectData,
|
|
32
|
-
error: connectError,
|
|
33
|
-
isLoading: isConnectLoading,
|
|
34
|
-
connect,
|
|
35
|
-
} = useConnect();
|
|
39
|
+
const connection = useConnection();
|
|
36
40
|
|
|
37
41
|
const request = async () => {
|
|
38
|
-
if (!
|
|
42
|
+
if (!canPerformAction(connection)) {
|
|
39
43
|
return;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
return claimLBTC({
|
|
43
|
-
...connectData,
|
|
44
47
|
...props,
|
|
48
|
+
account: connection.account.address,
|
|
49
|
+
chainId: connection.account.chainId,
|
|
50
|
+
provider: connection.provider,
|
|
45
51
|
});
|
|
46
52
|
};
|
|
47
53
|
|
|
48
54
|
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
49
55
|
|
|
50
|
-
const formattedConnectData = connectData && {
|
|
51
|
-
account: connectData.account,
|
|
52
|
-
chainId: connectData.chainId,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
56
|
return (
|
|
56
57
|
<>
|
|
57
58
|
<div className="mb-4">
|
|
58
|
-
<
|
|
59
|
-
onClick={connect}
|
|
60
|
-
disabled={isConnectLoading}
|
|
61
|
-
isLoading={isConnectLoading}
|
|
62
|
-
>
|
|
63
|
-
Connect
|
|
64
|
-
</Button>
|
|
65
|
-
|
|
66
|
-
<CodeBlock text={connectError || formattedConnectData} />
|
|
59
|
+
<ConnectButton />
|
|
67
60
|
</div>
|
|
68
61
|
|
|
69
62
|
<Button
|
|
70
63
|
onClick={refetch}
|
|
71
|
-
disabled={isLoading || !
|
|
64
|
+
disabled={isLoading || !connection.account.address}
|
|
72
65
|
isLoading={isLoading}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
</Button>
|
|
66
|
+
actionName={claimLBTC.name}
|
|
67
|
+
/>
|
|
76
68
|
|
|
77
69
|
<CodeBlock text={error || data} />
|
|
78
70
|
</>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BasculeDepositStatus,
|
|
3
|
+
getBasculeDepositStatus,
|
|
4
|
+
} from '../getBasculeDepositStatus';
|
|
5
|
+
import { CommonWriteParameters } from '../../common/parameters';
|
|
6
|
+
import { CHAIN_ID_TO_VIEM_CHAIN_MAP } from '../../common/chains';
|
|
7
|
+
import { makePublicClient } from '../../clients/public-client';
|
|
8
|
+
import { makeWalletClient } from '../../clients/wallet-client';
|
|
9
|
+
import { ensureHex } from '../../utils/hex';
|
|
10
|
+
import { Hash } from 'viem';
|
|
11
|
+
import { getTokenContractInfo } from '../../tokens/tokens';
|
|
12
|
+
import { Token } from '../../tokens/token-addresses';
|
|
13
|
+
|
|
14
|
+
export interface IClaimLBTCParams extends CommonWriteParameters {
|
|
15
|
+
/**
|
|
16
|
+
* Raw payload from deposit notarization.
|
|
17
|
+
*/
|
|
18
|
+
data: string;
|
|
19
|
+
/**
|
|
20
|
+
* Signature from deposit notarization.
|
|
21
|
+
*/
|
|
22
|
+
proofSignature: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Claims LBTC.
|
|
27
|
+
*
|
|
28
|
+
* @param {IClaimLBTCParams} parameters - The parameters.
|
|
29
|
+
* @param {string} data - The raw payload from the deposit, see `IDeposit.rawPayload`
|
|
30
|
+
* @param {string} proofSignature - The signature from the deposit, see `IDeposit.signature`
|
|
31
|
+
* @param {Address} parameters.account - The EVM account address.
|
|
32
|
+
* @param {ChainId} parameters.chainId - The chain id.
|
|
33
|
+
* @param {EIP1193Provider} parameters.provider - The EIP1193 provider.
|
|
34
|
+
* @param {string} parameters.rpcUrl - The optional rpc url.
|
|
35
|
+
* @param {Env} parameters.env - The optional environment identifier.
|
|
36
|
+
*
|
|
37
|
+
* @returns {Promise<Hash>} transaction promise
|
|
38
|
+
*/
|
|
39
|
+
export async function claimLBTC({
|
|
40
|
+
data,
|
|
41
|
+
proofSignature,
|
|
42
|
+
account,
|
|
43
|
+
chainId,
|
|
44
|
+
provider,
|
|
45
|
+
rpcUrl,
|
|
46
|
+
env,
|
|
47
|
+
}: IClaimLBTCParams): Promise<Hash> {
|
|
48
|
+
const lbtcContract = getTokenContractInfo(Token.LBTC, chainId, env);
|
|
49
|
+
|
|
50
|
+
// Check the deposit status against Bascule Drawbridge security.
|
|
51
|
+
// Block any deposit that is not reported.
|
|
52
|
+
const basculeStatus = await getBasculeDepositStatus({
|
|
53
|
+
chainId,
|
|
54
|
+
rawPayload: data,
|
|
55
|
+
env,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (basculeStatus !== BasculeDepositStatus.REPORTED) {
|
|
59
|
+
switch (basculeStatus) {
|
|
60
|
+
case BasculeDepositStatus.UNREPORTED:
|
|
61
|
+
throw new Error(
|
|
62
|
+
'The deposit cannot be claimed because it is unreported or potentially still pending, please try again later.',
|
|
63
|
+
);
|
|
64
|
+
case BasculeDepositStatus.WITHDRAWN:
|
|
65
|
+
throw new Error(
|
|
66
|
+
'The deposit cannot be claimed because it is withdrawn already.',
|
|
67
|
+
);
|
|
68
|
+
default: // unknown bascule deposit status
|
|
69
|
+
throw new Error(
|
|
70
|
+
'The deposit cannot be claimed because it is blocked by bridge security.',
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const publicClient = makePublicClient({ chainId, rpcUrl });
|
|
76
|
+
const walletClient = makeWalletClient({ chainId, provider });
|
|
77
|
+
|
|
78
|
+
const { request } = await publicClient.simulateContract({
|
|
79
|
+
address: lbtcContract.address,
|
|
80
|
+
account,
|
|
81
|
+
chain: CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId],
|
|
82
|
+
abi: lbtcContract.abi,
|
|
83
|
+
functionName: 'mint',
|
|
84
|
+
args: [ensureHex(data), ensureHex(proofSignature)],
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const txHash = await walletClient.writeContract(request);
|
|
88
|
+
|
|
89
|
+
return txHash;
|
|
90
|
+
}
|