@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,338 @@
|
|
|
1
|
+
import { Abi } from 'viem';
|
|
2
|
+
import { ChainId } from '../../common/chains';
|
|
3
|
+
import CCIP_BRIDGE_ADAPTER_ABI from '../abi/CCIP_BRIDGE_ADAPTER_ABI.json';
|
|
4
|
+
import OFT_BRIDGE_ADAPTER_ABI from '../abi/OFT_BRIDGE_ADAPTER_ABI.json';
|
|
5
|
+
import { ContractInfo } from '../../common/contract-info';
|
|
6
|
+
import BigNumber from 'bignumber.js';
|
|
7
|
+
import { unique } from '../../utils/array';
|
|
8
|
+
|
|
9
|
+
export const MIN_BRIDGE_AMOUNT = BigNumber(0.000001);
|
|
10
|
+
|
|
11
|
+
export enum BridgeType {
|
|
12
|
+
/** CCIP - (Chainlink) Cross-Chain Interoperability Protocol */
|
|
13
|
+
CCIP = 'CCIP',
|
|
14
|
+
|
|
15
|
+
/** OFT - (LayerZero) Omnichain Fungible Token */
|
|
16
|
+
OFT = 'OFT',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const BRIDGE_EXPLORER_URL_MAP = {
|
|
20
|
+
[BridgeType.CCIP]: 'https://ccip.chain.link/tx/{txHash}',
|
|
21
|
+
[BridgeType.OFT]: 'https://layerzeroscan.com/tx/{txHash}',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const CCIP_BRIDGE_CHAINS = [
|
|
25
|
+
// Mainnets:
|
|
26
|
+
ChainId.ethereum,
|
|
27
|
+
ChainId.base,
|
|
28
|
+
ChainId.binanceSmartChain,
|
|
29
|
+
// Testnets:
|
|
30
|
+
ChainId.baseSepoliaTestnet,
|
|
31
|
+
ChainId.holesky,
|
|
32
|
+
];
|
|
33
|
+
export type CCIPBridgeChain = (typeof CCIP_BRIDGE_CHAINS)[number];
|
|
34
|
+
|
|
35
|
+
export const OFT_BRIDGE_CHAINS = [
|
|
36
|
+
// Mainnets:
|
|
37
|
+
ChainId.ethereum,
|
|
38
|
+
ChainId.berachain,
|
|
39
|
+
ChainId.corn,
|
|
40
|
+
ChainId.etherlink,
|
|
41
|
+
ChainId.sonic,
|
|
42
|
+
ChainId.swell,
|
|
43
|
+
// Testnets:
|
|
44
|
+
ChainId.berachainBartioTestnet,
|
|
45
|
+
ChainId.sepolia,
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export const BRIDGE_CHAINS = unique([
|
|
49
|
+
...CCIP_BRIDGE_CHAINS,
|
|
50
|
+
...OFT_BRIDGE_CHAINS,
|
|
51
|
+
]);
|
|
52
|
+
export type BridgeChain = CCIPBridgeChain | OFTBridgeChain;
|
|
53
|
+
|
|
54
|
+
export const OFT_GAS_LIMIT = 90_000;
|
|
55
|
+
export const OFT_HI_GAS_LIMIT = 200_000;
|
|
56
|
+
export const OFT_HI_GAS_LIMIT_CHAINS = [
|
|
57
|
+
// Mainnets:
|
|
58
|
+
ChainId.berachain,
|
|
59
|
+
ChainId.sonic,
|
|
60
|
+
// Testnets:
|
|
61
|
+
ChainId.berachainBartioTestnet,
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
export type OFTBridgeChain = (typeof OFT_BRIDGE_CHAINS)[number];
|
|
65
|
+
|
|
66
|
+
type BridgeIdentifier<Ch extends CCIPBridgeChain | OFTBridgeChain> =
|
|
67
|
+
`[from:${Ch}, to: ${Ch}]`;
|
|
68
|
+
|
|
69
|
+
const bridgeIdentifier = <Ch extends CCIPBridgeChain | OFTBridgeChain>([
|
|
70
|
+
from,
|
|
71
|
+
to,
|
|
72
|
+
]: [from: Ch, to: Ch]): BridgeIdentifier<Ch> => `[from:${from}, to: ${to}]`;
|
|
73
|
+
|
|
74
|
+
type BridgeInfo = { type: BridgeType; contract: ContractInfo };
|
|
75
|
+
|
|
76
|
+
type CCIPBridgesConfig = [
|
|
77
|
+
BridgeIdentifier<CCIPBridgeChain>,
|
|
78
|
+
{ type: BridgeType.CCIP; contract: ContractInfo },
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const CCIP_BRIDGES: CCIPBridgesConfig[] = [
|
|
82
|
+
// Mainnets:
|
|
83
|
+
|
|
84
|
+
[
|
|
85
|
+
bridgeIdentifier([ChainId.ethereum, ChainId.base]),
|
|
86
|
+
{
|
|
87
|
+
type: BridgeType.CCIP,
|
|
88
|
+
contract: {
|
|
89
|
+
address: '0xa869817b48b25eee986bdf4be04062e6fd2c418b',
|
|
90
|
+
abi: CCIP_BRIDGE_ADAPTER_ABI as Abi,
|
|
91
|
+
chainId: ChainId.ethereum,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
bridgeIdentifier([ChainId.ethereum, ChainId.binanceSmartChain]),
|
|
97
|
+
{
|
|
98
|
+
type: BridgeType.CCIP,
|
|
99
|
+
contract: {
|
|
100
|
+
address: '0xa869817b48b25eee986bdf4be04062e6fd2c418b',
|
|
101
|
+
abi: CCIP_BRIDGE_ADAPTER_ABI as Abi,
|
|
102
|
+
chainId: ChainId.ethereum,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
|
|
107
|
+
[
|
|
108
|
+
bridgeIdentifier([ChainId.base, ChainId.ethereum]),
|
|
109
|
+
{
|
|
110
|
+
type: BridgeType.CCIP,
|
|
111
|
+
contract: {
|
|
112
|
+
address: '0xa869817b48b25eee986bdf4be04062e6fd2c418b',
|
|
113
|
+
abi: CCIP_BRIDGE_ADAPTER_ABI as Abi,
|
|
114
|
+
chainId: ChainId.base,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
[
|
|
119
|
+
bridgeIdentifier([ChainId.base, ChainId.binanceSmartChain]),
|
|
120
|
+
{
|
|
121
|
+
type: BridgeType.CCIP,
|
|
122
|
+
contract: {
|
|
123
|
+
address: '0xa869817b48b25eee986bdf4be04062e6fd2c418b',
|
|
124
|
+
abi: CCIP_BRIDGE_ADAPTER_ABI as Abi,
|
|
125
|
+
chainId: ChainId.base,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
|
|
130
|
+
[
|
|
131
|
+
bridgeIdentifier([ChainId.binanceSmartChain, ChainId.ethereum]),
|
|
132
|
+
{
|
|
133
|
+
type: BridgeType.CCIP,
|
|
134
|
+
contract: {
|
|
135
|
+
address: '0xa869817b48b25eee986bdf4be04062e6fd2c418b',
|
|
136
|
+
abi: CCIP_BRIDGE_ADAPTER_ABI as Abi,
|
|
137
|
+
chainId: ChainId.binanceSmartChain,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
[
|
|
142
|
+
bridgeIdentifier([ChainId.binanceSmartChain, ChainId.base]),
|
|
143
|
+
{
|
|
144
|
+
type: BridgeType.CCIP,
|
|
145
|
+
contract: {
|
|
146
|
+
address: '0xa869817b48b25eee986bdf4be04062e6fd2c418b',
|
|
147
|
+
abi: CCIP_BRIDGE_ADAPTER_ABI as Abi,
|
|
148
|
+
chainId: ChainId.binanceSmartChain,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
|
|
153
|
+
// Testnets:
|
|
154
|
+
|
|
155
|
+
[
|
|
156
|
+
bridgeIdentifier([ChainId.baseSepoliaTestnet, ChainId.holesky]),
|
|
157
|
+
{
|
|
158
|
+
type: BridgeType.CCIP,
|
|
159
|
+
contract: {
|
|
160
|
+
address: '0x38247C4c846D549CAAd2C6c0b6fec0c402b77a0F',
|
|
161
|
+
abi: CCIP_BRIDGE_ADAPTER_ABI as Abi,
|
|
162
|
+
chainId: ChainId.baseSepoliaTestnet,
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
|
|
167
|
+
[
|
|
168
|
+
bridgeIdentifier([ChainId.holesky, ChainId.baseSepoliaTestnet]),
|
|
169
|
+
{
|
|
170
|
+
type: BridgeType.CCIP,
|
|
171
|
+
contract: {
|
|
172
|
+
address: '0x38247C4c846D549CAAd2C6c0b6fec0c402b77a0F',
|
|
173
|
+
abi: CCIP_BRIDGE_ADAPTER_ABI as Abi,
|
|
174
|
+
chainId: ChainId.holesky,
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
type OFTBridgeConfig = [
|
|
181
|
+
BridgeIdentifier<OFTBridgeChain>,
|
|
182
|
+
{ type: BridgeType.OFT; contract: ContractInfo },
|
|
183
|
+
];
|
|
184
|
+
const OFT_BRIDGES: OFTBridgeConfig[] = [
|
|
185
|
+
// Mainnets:
|
|
186
|
+
|
|
187
|
+
[
|
|
188
|
+
bridgeIdentifier([ChainId.ethereum, ChainId.berachain]),
|
|
189
|
+
{
|
|
190
|
+
type: BridgeType.OFT,
|
|
191
|
+
contract: {
|
|
192
|
+
address: '0x1290A6b480f7eF14925229fdB66f5680aD8F44AD',
|
|
193
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
194
|
+
chainId: ChainId.ethereum,
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
[
|
|
199
|
+
bridgeIdentifier([ChainId.ethereum, ChainId.corn]),
|
|
200
|
+
{
|
|
201
|
+
type: BridgeType.OFT,
|
|
202
|
+
contract: {
|
|
203
|
+
address: '0x6bc15d7930839ec18a57f6f7df72ae1b439d077f',
|
|
204
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
205
|
+
chainId: ChainId.ethereum,
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
[
|
|
210
|
+
bridgeIdentifier([ChainId.ethereum, ChainId.etherlink]),
|
|
211
|
+
{
|
|
212
|
+
type: BridgeType.OFT,
|
|
213
|
+
contract: {
|
|
214
|
+
address: '0x3a7647c1323144a16e7D0D71A581E3FE5BD95299',
|
|
215
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
216
|
+
chainId: ChainId.ethereum,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
[
|
|
221
|
+
bridgeIdentifier([ChainId.ethereum, ChainId.sonic]),
|
|
222
|
+
{
|
|
223
|
+
type: BridgeType.OFT,
|
|
224
|
+
contract: {
|
|
225
|
+
address: '0xcFEAc622BC6464acC759ACd9741a6D78F8b0d3Cd',
|
|
226
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
227
|
+
chainId: ChainId.ethereum,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
[
|
|
232
|
+
bridgeIdentifier([ChainId.ethereum, ChainId.swell]),
|
|
233
|
+
{
|
|
234
|
+
type: BridgeType.OFT,
|
|
235
|
+
contract: {
|
|
236
|
+
address: '0x37E92d760a15231e652a2C502182a6b44c7510c0',
|
|
237
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
238
|
+
chainId: ChainId.ethereum,
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
|
|
243
|
+
[
|
|
244
|
+
bridgeIdentifier([ChainId.berachain, ChainId.ethereum]),
|
|
245
|
+
{
|
|
246
|
+
type: BridgeType.OFT,
|
|
247
|
+
contract: {
|
|
248
|
+
address: '0x630e12D53D4E041b8C5451aD035Ea841E08391d7',
|
|
249
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
250
|
+
chainId: ChainId.berachain,
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
|
|
255
|
+
[
|
|
256
|
+
bridgeIdentifier([ChainId.corn, ChainId.ethereum]),
|
|
257
|
+
{
|
|
258
|
+
type: BridgeType.OFT,
|
|
259
|
+
contract: {
|
|
260
|
+
address: '0xfc7B20D9B59A8A466f4fC3d34aA69a7D98e71d7A',
|
|
261
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
262
|
+
chainId: ChainId.corn,
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
|
|
267
|
+
[
|
|
268
|
+
bridgeIdentifier([ChainId.etherlink, ChainId.ethereum]),
|
|
269
|
+
{
|
|
270
|
+
type: BridgeType.OFT,
|
|
271
|
+
contract: {
|
|
272
|
+
address: '0xC832183d4d5fc5831daaC892a93dBBfd798034E3',
|
|
273
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
274
|
+
chainId: ChainId.etherlink,
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
|
|
279
|
+
[
|
|
280
|
+
bridgeIdentifier([ChainId.sonic, ChainId.ethereum]),
|
|
281
|
+
{
|
|
282
|
+
type: BridgeType.OFT,
|
|
283
|
+
contract: {
|
|
284
|
+
address: '0x630e12D53D4E041b8C5451aD035Ea841E08391d7',
|
|
285
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
286
|
+
chainId: ChainId.sonic,
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
|
|
291
|
+
[
|
|
292
|
+
bridgeIdentifier([ChainId.swell, ChainId.ethereum]),
|
|
293
|
+
{
|
|
294
|
+
type: BridgeType.OFT,
|
|
295
|
+
contract: {
|
|
296
|
+
address: '0x7B3784AD646C10A8Ddf42b47a4f4bd9aFD351E54',
|
|
297
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
298
|
+
chainId: ChainId.swell,
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
|
|
303
|
+
// Testnets:
|
|
304
|
+
|
|
305
|
+
[
|
|
306
|
+
bridgeIdentifier([ChainId.berachainBartioTestnet, ChainId.sepolia]),
|
|
307
|
+
{
|
|
308
|
+
type: BridgeType.OFT,
|
|
309
|
+
contract: {
|
|
310
|
+
address: '0x1977013acaf27856ac8048C42EE2ed0134d53895',
|
|
311
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
312
|
+
chainId: ChainId.berachainBartioTestnet,
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
|
|
317
|
+
[
|
|
318
|
+
bridgeIdentifier([ChainId.sepolia, ChainId.berachainBartioTestnet]),
|
|
319
|
+
{
|
|
320
|
+
type: BridgeType.OFT,
|
|
321
|
+
contract: {
|
|
322
|
+
address: '0xe3748bF0Ec0A76767539eE28610B3367e35fe2C2',
|
|
323
|
+
abi: OFT_BRIDGE_ADAPTER_ABI as Abi,
|
|
324
|
+
chainId: ChainId.sepolia,
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
],
|
|
328
|
+
];
|
|
329
|
+
|
|
330
|
+
export const BRIDGES = new Map<BridgeIdentifier<BridgeChain>, BridgeInfo>([
|
|
331
|
+
...CCIP_BRIDGES,
|
|
332
|
+
...OFT_BRIDGES,
|
|
333
|
+
]);
|
|
334
|
+
|
|
335
|
+
/** Gets the bridge information */
|
|
336
|
+
export const getBridgeInfo = (from: BridgeChain, to: BridgeChain) => {
|
|
337
|
+
return BRIDGES.get(bridgeIdentifier([from, to]));
|
|
338
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Button } from '../../stories/components/Button';
|
|
3
|
+
import { CodeBlock } from '../../stories/components/CodeBlock';
|
|
4
|
+
import {
|
|
5
|
+
canPerformAction,
|
|
6
|
+
useConnection,
|
|
7
|
+
} from '../../stories/hooks/useConnection';
|
|
8
|
+
import useQuery from '../../stories/hooks/useQuery';
|
|
9
|
+
import { ConnectButton } from '../../stories/components/ConnectButton';
|
|
10
|
+
import {
|
|
11
|
+
functionType,
|
|
12
|
+
wagmiDecorator,
|
|
13
|
+
} from '../../stories/components/decorators';
|
|
14
|
+
import { ErrorBlock } from '../../stories/components/error-block';
|
|
15
|
+
import { ChainId } from '../../common/chains';
|
|
16
|
+
import { OFT_BRIDGE_CHAINS } from './config';
|
|
17
|
+
import { bridgeOFT, BridgeOFTParameters } from './oft-bridge';
|
|
18
|
+
|
|
19
|
+
const meta = {
|
|
20
|
+
title: 'bridge/bridgeOFT',
|
|
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
|
+
to: ChainId.sonic,
|
|
33
|
+
amount: '0.0001',
|
|
34
|
+
approve: true,
|
|
35
|
+
env: 'prod',
|
|
36
|
+
},
|
|
37
|
+
argTypes: {
|
|
38
|
+
to: {
|
|
39
|
+
mapping: ChainId,
|
|
40
|
+
options: OFT_BRIDGE_CHAINS.map(
|
|
41
|
+
ch => Object.entries(ChainId).find(([k, v]) => v === ch)?.[0],
|
|
42
|
+
),
|
|
43
|
+
control: { type: 'select' },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type Props = Omit<BridgeOFTParameters, 'account' | 'chainId' | 'provider'>;
|
|
49
|
+
|
|
50
|
+
export function StoryView(props: Props) {
|
|
51
|
+
const connection = useConnection();
|
|
52
|
+
|
|
53
|
+
const request = async () => {
|
|
54
|
+
if (!canPerformAction(connection)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return bridgeOFT({
|
|
59
|
+
...props,
|
|
60
|
+
|
|
61
|
+
account: connection.account.address,
|
|
62
|
+
chainId: connection.account.chainId,
|
|
63
|
+
provider: connection.provider,
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const { data, error, isLoading, refetch } = useQuery(request, [], false);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<>
|
|
71
|
+
<p>This method bridges funds between chains.</p>
|
|
72
|
+
|
|
73
|
+
<div className="mb-4">
|
|
74
|
+
<ConnectButton />
|
|
75
|
+
</div>
|
|
76
|
+
|
|
77
|
+
<Button
|
|
78
|
+
onClick={refetch}
|
|
79
|
+
disabled={isLoading || !canPerformAction(connection)}
|
|
80
|
+
isLoading={isLoading}
|
|
81
|
+
actionName={bridgeOFT.name}
|
|
82
|
+
/>
|
|
83
|
+
|
|
84
|
+
<ErrorBlock>{error}</ErrorBlock>
|
|
85
|
+
|
|
86
|
+
<CodeBlock text={data} />
|
|
87
|
+
</>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import { CommonWriteParameters } from '../../common/parameters';
|
|
3
|
+
import {
|
|
4
|
+
BridgeType,
|
|
5
|
+
getBridgeInfo,
|
|
6
|
+
MIN_BRIDGE_AMOUNT,
|
|
7
|
+
OFT_BRIDGE_CHAINS,
|
|
8
|
+
OFT_GAS_LIMIT,
|
|
9
|
+
OFT_HI_GAS_LIMIT,
|
|
10
|
+
OFT_HI_GAS_LIMIT_CHAINS,
|
|
11
|
+
OFTBridgeChain,
|
|
12
|
+
} from './config';
|
|
13
|
+
import { makePublicClient } from '../../clients/public-client';
|
|
14
|
+
import { makeWalletClient } from '../../clients/wallet-client';
|
|
15
|
+
import {
|
|
16
|
+
fromBaseDenomination,
|
|
17
|
+
getTokenInfo,
|
|
18
|
+
toBaseDenomination,
|
|
19
|
+
} from '../../tokens/tokens';
|
|
20
|
+
import { getErrorMessage } from '../../utils/err';
|
|
21
|
+
import toBigInt from '../../utils/numbers';
|
|
22
|
+
import { Address, numberToHex, pad, parseEther, toBytes, toHex } from 'viem';
|
|
23
|
+
import { approveLBTC } from '../../contract-functions';
|
|
24
|
+
import { ChainId } from '../../common/chains';
|
|
25
|
+
import { Options } from '@layerzerolabs/lz-v2-utilities';
|
|
26
|
+
import { Token } from '../../tokens/token-addresses';
|
|
27
|
+
|
|
28
|
+
const DESTINATION_ENDPOINT_ID_MAP: Record<OFTBridgeChain, number> = {
|
|
29
|
+
// Mainnets:
|
|
30
|
+
[ChainId.ethereum]: 30101,
|
|
31
|
+
[ChainId.berachain]: 30362,
|
|
32
|
+
[ChainId.corn]: 30331,
|
|
33
|
+
[ChainId.etherlink]: 30292,
|
|
34
|
+
[ChainId.sonic]: 30332,
|
|
35
|
+
[ChainId.swell]: 30335,
|
|
36
|
+
// Testnets:
|
|
37
|
+
[ChainId.sepolia]: 40161,
|
|
38
|
+
[ChainId.berachainBartioTestnet]: 40291,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type BridgeOFTParameters = {
|
|
42
|
+
/** The destination chain id. */
|
|
43
|
+
to: OFTBridgeChain;
|
|
44
|
+
/** The LBTC amount. */
|
|
45
|
+
amount: BigNumber.Value;
|
|
46
|
+
/**
|
|
47
|
+
* A flag determining whether the amount should be approved within
|
|
48
|
+
* the execution of this function. If set to `false` it will
|
|
49
|
+
* throw an error when the deposit amount exceeds allowance.
|
|
50
|
+
*/
|
|
51
|
+
approve?: boolean;
|
|
52
|
+
/** The destination address. If omitted the same as the account address. */
|
|
53
|
+
recipient?: Address;
|
|
54
|
+
} & CommonWriteParameters;
|
|
55
|
+
export async function bridgeOFT({
|
|
56
|
+
to,
|
|
57
|
+
amount: amountRaw,
|
|
58
|
+
approve,
|
|
59
|
+
recipient: optionalRecipient,
|
|
60
|
+
account,
|
|
61
|
+
chainId: from,
|
|
62
|
+
provider,
|
|
63
|
+
env,
|
|
64
|
+
rpcUrl,
|
|
65
|
+
}: BridgeOFTParameters) {
|
|
66
|
+
const amount = BigNumber(amountRaw);
|
|
67
|
+
const recipient = optionalRecipient || account;
|
|
68
|
+
|
|
69
|
+
const bridgeInfo = getBridgeInfo(from as OFTBridgeChain, to);
|
|
70
|
+
if (!bridgeInfo || bridgeInfo.type !== BridgeType.OFT) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Unsupported bridge from ${from} to ${to}. Please switch to the supported chains: ${OFT_BRIDGE_CHAINS.join(', ')}`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const bridgeContract = bridgeInfo.contract;
|
|
77
|
+
|
|
78
|
+
const lbtcContract = await getTokenInfo(Token.LBTC, from, env, rpcUrl);
|
|
79
|
+
if (!lbtcContract) {
|
|
80
|
+
throw new Error('Could not retrieve LBTC contract info.');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const publicClient = makePublicClient({ chainId: from, rpcUrl });
|
|
84
|
+
const walletClient = makeWalletClient({ provider, chainId: from });
|
|
85
|
+
|
|
86
|
+
const amountBase = toBigInt(
|
|
87
|
+
toBaseDenomination(amount, lbtcContract.decimals),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
if (amount.isLessThan(MIN_BRIDGE_AMOUNT)) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`The amount is smaller than the minimum amount allowed: ${MIN_BRIDGE_AMOUNT.toFixed()}`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const balanceRaw = await publicClient.readContract({
|
|
97
|
+
address: lbtcContract.address,
|
|
98
|
+
abi: lbtcContract.abi,
|
|
99
|
+
functionName: 'balanceOf',
|
|
100
|
+
args: [account],
|
|
101
|
+
});
|
|
102
|
+
const balance = fromBaseDenomination(
|
|
103
|
+
String(balanceRaw),
|
|
104
|
+
lbtcContract.decimals,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
// check if amount exceeds balance
|
|
108
|
+
if (amount.isGreaterThan(balance)) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`The amount exceeds the account's balance. \nAmount: ${amount.toFixed()} \nBalance: ${balance.toFixed()}`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const allowanceRaw = await publicClient.readContract({
|
|
115
|
+
address: lbtcContract.address,
|
|
116
|
+
abi: lbtcContract.abi,
|
|
117
|
+
functionName: 'allowance',
|
|
118
|
+
args: [account, bridgeContract.address],
|
|
119
|
+
});
|
|
120
|
+
const allowance = fromBaseDenomination(
|
|
121
|
+
String(allowanceRaw),
|
|
122
|
+
lbtcContract.decimals,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
// check if amount exceeds allowance
|
|
126
|
+
if (amount.isGreaterThan(allowance)) {
|
|
127
|
+
const exceededMessage = `The amount exceeds allowance. \nAmount: ${amount.toFixed()} \nAllowance: ${allowance.toFixed()}`;
|
|
128
|
+
if (!approve) {
|
|
129
|
+
throw new Error(exceededMessage);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// try to approve new amount
|
|
133
|
+
console.info(exceededMessage);
|
|
134
|
+
try {
|
|
135
|
+
const txHash = await approveLBTC({
|
|
136
|
+
account,
|
|
137
|
+
spender: bridgeContract.address,
|
|
138
|
+
amount,
|
|
139
|
+
chainId: from,
|
|
140
|
+
provider,
|
|
141
|
+
rpcUrl,
|
|
142
|
+
env,
|
|
143
|
+
});
|
|
144
|
+
console.info(`Approve tx hash: ${txHash}`);
|
|
145
|
+
console.info(`Approved ${amountBase} for ${bridgeContract.address}`);
|
|
146
|
+
} catch (err) {
|
|
147
|
+
const msg = getErrorMessage(err);
|
|
148
|
+
throw new Error(
|
|
149
|
+
`Could not approve ${amountBase} for ${bridgeContract.address}. \nReason: ${msg}`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const extraOptions = Options.newOptions().addExecutorLzReceiveOption(
|
|
155
|
+
(OFT_HI_GAS_LIMIT_CHAINS as number[]).includes(to)
|
|
156
|
+
? OFT_HI_GAS_LIMIT
|
|
157
|
+
: OFT_GAS_LIMIT,
|
|
158
|
+
0,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
/** _sendParam */
|
|
162
|
+
const sendParam = [
|
|
163
|
+
/** dstEid - uint32 */
|
|
164
|
+
DESTINATION_ENDPOINT_ID_MAP[to],
|
|
165
|
+
/** to - bytes32 */
|
|
166
|
+
pad(recipient),
|
|
167
|
+
/** amountLD - uint256 */
|
|
168
|
+
amountBase,
|
|
169
|
+
/** minAmountLD - uint256 */
|
|
170
|
+
amountBase,
|
|
171
|
+
/** extraOptions - bytes */
|
|
172
|
+
extraOptions.toHex(),
|
|
173
|
+
/** composeMsg - bytes */
|
|
174
|
+
'0x',
|
|
175
|
+
/** oftCmd - bytes */
|
|
176
|
+
'0x',
|
|
177
|
+
];
|
|
178
|
+
|
|
179
|
+
const { nativeFee, lzTokenFee } = (await publicClient.readContract({
|
|
180
|
+
abi: bridgeContract.abi,
|
|
181
|
+
address: bridgeContract.address,
|
|
182
|
+
account,
|
|
183
|
+
functionName: 'quoteSend',
|
|
184
|
+
args: [sendParam, false],
|
|
185
|
+
})) as { nativeFee: bigint; lzTokenFee: bigint };
|
|
186
|
+
|
|
187
|
+
const bridgeArgs = [
|
|
188
|
+
/** _sendParam */
|
|
189
|
+
sendParam,
|
|
190
|
+
/** _fee */
|
|
191
|
+
[
|
|
192
|
+
/** nativeFee - uint256 */
|
|
193
|
+
nativeFee,
|
|
194
|
+
/** lzTokenFee - uint256 */
|
|
195
|
+
lzTokenFee,
|
|
196
|
+
],
|
|
197
|
+
/** address - address */
|
|
198
|
+
account,
|
|
199
|
+
];
|
|
200
|
+
|
|
201
|
+
const { request } = await publicClient.simulateContract({
|
|
202
|
+
abi: bridgeContract.abi,
|
|
203
|
+
address: bridgeContract.address,
|
|
204
|
+
account,
|
|
205
|
+
functionName: 'send',
|
|
206
|
+
args: bridgeArgs,
|
|
207
|
+
value: nativeFee,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
const txHash = await walletClient.writeContract(request);
|
|
211
|
+
return txHash;
|
|
212
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { rpcUrlConfig } from './rpc-url-config';
|
|
2
|
+
import { CHAIN_ID_TO_VIEM_CHAIN_MAP, ChainId } from '../common/chains';
|
|
3
|
+
import { createPublicClient, http, PublicClient } from 'viem';
|
|
4
|
+
|
|
5
|
+
type MakePublicClientParameters = {
|
|
6
|
+
chainId: ChainId;
|
|
7
|
+
rpcUrl?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Creates the public (read-only) client for specified `chainId`.
|
|
12
|
+
* @param chainId - The chain id
|
|
13
|
+
* @param rpcUrl - The overridden RPC url for specified chain id.
|
|
14
|
+
* @returns The public client instance
|
|
15
|
+
*/
|
|
16
|
+
export function makePublicClient({
|
|
17
|
+
chainId,
|
|
18
|
+
rpcUrl,
|
|
19
|
+
}: MakePublicClientParameters): PublicClient {
|
|
20
|
+
const override = rpcUrl ? { [chainId]: rpcUrl } : undefined;
|
|
21
|
+
const rpcUrls = { ...rpcUrlConfig, ...override };
|
|
22
|
+
|
|
23
|
+
const chain = CHAIN_ID_TO_VIEM_CHAIN_MAP[chainId];
|
|
24
|
+
const transport = http(rpcUrls[chainId]);
|
|
25
|
+
|
|
26
|
+
const publicClient = createPublicClient({
|
|
27
|
+
chain,
|
|
28
|
+
transport,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return publicClient as PublicClient<typeof transport>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ChainId } from '../common/chains';
|
|
2
|
+
|
|
3
|
+
export type TRpcUrlConfig = Record<number, string>;
|
|
4
|
+
|
|
5
|
+
export const RPC_URL = 'https://bff.prod.lombard.finance/multi-rpc/proxy';
|
|
6
|
+
|
|
7
|
+
export const rpcUrlConfig: TRpcUrlConfig = {
|
|
8
|
+
[ChainId.ethereum]: `${RPC_URL}/eth`,
|
|
9
|
+
[ChainId.base]: `${RPC_URL}/base`,
|
|
10
|
+
[ChainId.binanceSmartChain]: 'https://bsc-dataseed.bnbchain.org',
|
|
11
|
+
[ChainId.corn]: `${RPC_URL}/corn_maizenet`,
|
|
12
|
+
[ChainId.sonic]: `${RPC_URL}/sonic_mainnet`,
|
|
13
|
+
// Testnets:
|
|
14
|
+
[ChainId.baseSepoliaTestnet]: `${RPC_URL}/base_sepolia`,
|
|
15
|
+
[ChainId.binanceSmartChainTestnet]:
|
|
16
|
+
'https://bsc-testnet-dataseed.bnbchain.org',
|
|
17
|
+
[ChainId.holesky]: `${RPC_URL}/eth_holesky`,
|
|
18
|
+
[ChainId.sepolia]: `${RPC_URL}/eth_sepolia`,
|
|
19
|
+
[ChainId.sonicBlazeTestnet]: `${RPC_URL}/sonic_blaze_testnet`,
|
|
20
|
+
};
|