@avalabs/core-bridge-sdk 2.8.0-alpha.197
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/LICENSE +9 -0
- package/README.md +10 -0
- package/dist/index.d.ts +850 -0
- package/dist/index.js +1 -0
- package/esm/abi/erc20.abi.json.js +1 -0
- package/esm/abi/wavax.abi.json.js +1 -0
- package/esm/abi/weth.abi.json.js +1 -0
- package/esm/constants.js +1 -0
- package/esm/contexts/BridgeSDKProvider.d.ts +8 -0
- package/esm/contexts/BridgeSDKProvider.js +1 -0
- package/esm/contexts/TokenInfoProvider.d.ts +9 -0
- package/esm/contexts/TokenInfoProvider.js +1 -0
- package/esm/contexts/models.d.ts +26 -0
- package/esm/hooks/useBridgeConfig.d.ts +13 -0
- package/esm/hooks/useBridgeConfig.js +1 -0
- package/esm/hooks/useBridgeConfigUpdater.d.ts +16 -0
- package/esm/hooks/useBridgeConfigUpdater.js +1 -0
- package/esm/hooks/useBridgeFeeEstimate.d.ts +9 -0
- package/esm/hooks/useBridgeFeeEstimate.js +1 -0
- package/esm/hooks/useCheckHistoryForNewTxEVM.d.ts +11 -0
- package/esm/hooks/useCheckHistoryForNewTxEVM.js +1 -0
- package/esm/hooks/useGetAirdropAmount.d.ts +8 -0
- package/esm/hooks/useGetAirdropAmount.js +1 -0
- package/esm/hooks/useGetTokenBalanceEVM.d.ts +14 -0
- package/esm/hooks/useGetTokenBalanceEVM.js +1 -0
- package/esm/hooks/useGetTokenBalancesEVM.d.ts +16 -0
- package/esm/hooks/useGetTokenBalancesEVM.js +1 -0
- package/esm/hooks/useGetTokenSymbolOnNetwork.d.ts +7 -0
- package/esm/hooks/useGetTokenSymbolOnNetwork.js +1 -0
- package/esm/hooks/useHasEnoughForGas.d.ts +6 -0
- package/esm/hooks/useHasEnoughForGas.js +1 -0
- package/esm/hooks/useIsAddressSanctioned.d.ts +3 -0
- package/esm/hooks/useIsAddressSanctioned.js +1 -0
- package/esm/hooks/useMaxTransferAmount.d.ts +13 -0
- package/esm/hooks/useMaxTransferAmount.js +1 -0
- package/esm/hooks/useMinimumTransferAmount.d.ts +9 -0
- package/esm/hooks/useMinimumTransferAmount.js +1 -0
- package/esm/hooks/usePrice.d.ts +11 -0
- package/esm/hooks/usePrice.js +1 -0
- package/esm/hooks/usePriceForChain.d.ts +6 -0
- package/esm/hooks/usePriceForChain.js +1 -0
- package/esm/hooks/useResetTransactionDetailsFromParams.d.ts +8 -0
- package/esm/hooks/useResetTransactionDetailsFromParams.js +1 -0
- package/esm/hooks/useSubscribeForNewTransactionFromBridge.d.ts +7 -0
- package/esm/hooks/useSubscribeForNewTransactionFromBridge.js +1 -0
- package/esm/hooks/useTimer.d.ts +10 -0
- package/esm/hooks/useTimer.js +1 -0
- package/esm/hooks/useTransferAssetBTC.d.ts +13 -0
- package/esm/hooks/useTransferAssetBTC.js +1 -0
- package/esm/hooks/useTransferAssetEVM.d.ts +23 -0
- package/esm/hooks/useTransferAssetEVM.js +1 -0
- package/esm/hooks/useTxTracker.d.ts +31 -0
- package/esm/hooks/useTxTracker.js +1 -0
- package/esm/hooks/useWaitForConfirmations.d.ts +10 -0
- package/esm/hooks/useWaitForConfirmations.js +1 -0
- package/esm/index.d.ts +56 -0
- package/esm/index.js +1 -0
- package/esm/lib/btc/address.d.ts +17 -0
- package/esm/lib/btc/address.js +1 -0
- package/esm/lib/btc/getBridgeFeeEstimateBTC.d.ts +18 -0
- package/esm/lib/btc/getBridgeFeeEstimateBTC.js +1 -0
- package/esm/lib/btc/getBtcAsset.d.ts +8 -0
- package/esm/lib/btc/getBtcAsset.js +1 -0
- package/esm/lib/btc/getBtcTransaction.d.ts +24 -0
- package/esm/lib/btc/getBtcTransaction.js +1 -0
- package/esm/lib/btc/getBtcTransactionDetails.d.ts +22 -0
- package/esm/lib/btc/getBtcTransactionDetails.js +1 -0
- package/esm/lib/btc/getMinimumTransferAmount.d.ts +12 -0
- package/esm/lib/btc/getMinimumTransferAmount.js +1 -0
- package/esm/lib/btc/getTxConfirmations.d.ts +12 -0
- package/esm/lib/btc/getTxConfirmations.js +1 -0
- package/esm/lib/btc/models.d.ts +5 -0
- package/esm/lib/btc/utils.d.ts +6 -0
- package/esm/lib/btc/utils.js +1 -0
- package/esm/lib/checkHistoryForNewTxEVM.d.ts +15 -0
- package/esm/lib/checkHistoryForNewTxEVM.js +1 -0
- package/esm/lib/fetchConfig.d.ts +8 -0
- package/esm/lib/fetchConfig.js +1 -0
- package/esm/lib/fetchTokenBalances.d.ts +10 -0
- package/esm/lib/fetchTokenBalances.js +1 -0
- package/esm/lib/getAssets.d.ts +14 -0
- package/esm/lib/getAssets.js +1 -0
- package/esm/lib/getBridgeFeeEstimateEVM.d.ts +20 -0
- package/esm/lib/getBridgeFeeEstimateEVM.js +1 -0
- package/esm/lib/getDynamicFeeAmount.js +1 -0
- package/esm/lib/getMaxTransferAmount.d.ts +16 -0
- package/esm/lib/getMaxTransferAmount.js +1 -0
- package/esm/lib/getMinimumTransferAmountEVM.js +1 -0
- package/esm/lib/hasAddressVulnerableMultichainApproval.js +1 -0
- package/esm/lib/models.d.ts +62 -0
- package/esm/lib/models.js +1 -0
- package/esm/lib/tracker/Tracker.js +1 -0
- package/esm/lib/tracker/getBlockNumberBitcoin.js +1 -0
- package/esm/lib/tracker/getBlockNumberEVM.js +1 -0
- package/esm/lib/tracker/getBridgeFeeActualEVM.js +1 -0
- package/esm/lib/tracker/getEVMProvider.js +1 -0
- package/esm/lib/tracker/getIntervalTime.js +1 -0
- package/esm/lib/tracker/getNetworkFeeEVM.js +1 -0
- package/esm/lib/tracker/getSourceTxDataBitcoin.js +1 -0
- package/esm/lib/tracker/getSourceTxDataEVM.js +1 -0
- package/esm/lib/tracker/getTargetTxDataBitcoin.js +1 -0
- package/esm/lib/tracker/getTargetTxDataEVM.js +1 -0
- package/esm/lib/tracker/models.d.ts +15 -0
- package/esm/lib/tracker/trackBridgeTransaction.d.ts +28 -0
- package/esm/lib/tracker/trackBridgeTransaction.js +1 -0
- package/esm/lib/transferAssetBTC.d.ts +19 -0
- package/esm/lib/transferAssetBTC.js +1 -0
- package/esm/lib/transferAssetEVM.d.ts +28 -0
- package/esm/lib/transferAssetEVM.js +1 -0
- package/esm/lib/unwrapAsset.d.ts +11 -0
- package/esm/lib/unwrapAsset.js +1 -0
- package/esm/lib/wrapAsset.d.ts +17 -0
- package/esm/lib/wrapAsset.js +1 -0
- package/esm/runtime/config.d.ts +17 -0
- package/esm/runtime/config.js +1 -0
- package/esm/runtime/nativeAssets.js +1 -0
- package/esm/types/config.d.ts +297 -0
- package/esm/types/config.js +1 -0
- package/esm/types/tokenInfo.d.ts +7 -0
- package/esm/utils/asset.d.ts +7 -0
- package/esm/utils/asset.js +1 -0
- package/esm/utils/bignumber.d.ts +10 -0
- package/esm/utils/bignumber.js +1 -0
- package/esm/utils/config.d.ts +15 -0
- package/esm/utils/config.js +1 -0
- package/esm/utils/estimateGas.d.ts +17 -0
- package/esm/utils/estimateGas.js +1 -0
- package/esm/utils/formatTokenAmount.d.ts +5 -0
- package/esm/utils/formatTokenAmount.js +1 -0
- package/esm/utils/getContract.js +1 -0
- package/esm/utils/getGasAsset.js +1 -0
- package/esm/utils/getNativeSymbol.d.ts +5 -0
- package/esm/utils/getNativeSymbol.js +1 -0
- package/esm/utils/isAddressBlocklisted.d.ts +9 -0
- package/esm/utils/isAddressBlocklisted.js +1 -0
- package/esm/utils/loadTokenInfo.js +1 -0
- package/esm/utils/usdFormatter.d.ts +3 -0
- package/esm/utils/usdFormatter.js +1 -0
- package/esm/utils/wrapUtils.js +1 -0
- package/package.json +51 -0
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export { BridgeSDKProvider, useBridgeSDK } from './contexts/BridgeSDKProvider.js';
|
|
2
|
+
export { AvalancheAssets, BridgeSDKState, EthereumAssets } from './contexts/models.js';
|
|
3
|
+
export { TokenInfoProvider, initalState, useTokenInfoContext } from './contexts/TokenInfoProvider.js';
|
|
4
|
+
export { useBridgeConfig } from './hooks/useBridgeConfig.js';
|
|
5
|
+
export { useBridgeConfigUpdater } from './hooks/useBridgeConfigUpdater.js';
|
|
6
|
+
export { useCheckHistoryForNewTxEVM } from './hooks/useCheckHistoryForNewTxEVM.js';
|
|
7
|
+
export { useGetAirdropAmount } from './hooks/useGetAirdropAmount.js';
|
|
8
|
+
export { useGetTokenBalanceEVM } from './hooks/useGetTokenBalanceEVM.js';
|
|
9
|
+
export { useGetTokenBalancesEVM } from './hooks/useGetTokenBalancesEVM.js';
|
|
10
|
+
export { useGetTokenSymbolOnNetwork } from './hooks/useGetTokenSymbolOnNetwork.js';
|
|
11
|
+
export { useHasEnoughForGas } from './hooks/useHasEnoughForGas.js';
|
|
12
|
+
export { useIsAddressSanctioned } from './hooks/useIsAddressSanctioned.js';
|
|
13
|
+
export { useMaxTransferAmount } from './hooks/useMaxTransferAmount.js';
|
|
14
|
+
export { usePrice } from './hooks/usePrice.js';
|
|
15
|
+
export { usePriceForChain } from './hooks/usePriceForChain.js';
|
|
16
|
+
export { useResetTransactionDetailsFromParams } from './hooks/useResetTransactionDetailsFromParams.js';
|
|
17
|
+
export { useSubscribeForNewTransactionFromBridgeEVM } from './hooks/useSubscribeForNewTransactionFromBridge.js';
|
|
18
|
+
export { useTimer } from './hooks/useTimer.js';
|
|
19
|
+
export { useBridgeFeeEstimate } from './hooks/useBridgeFeeEstimate.js';
|
|
20
|
+
export { useTransferAssetEVM } from './hooks/useTransferAssetEVM.js';
|
|
21
|
+
export { useTransferAssetBTC } from './hooks/useTransferAssetBTC.js';
|
|
22
|
+
export { TrackerViewProps, useTxTracker } from './hooks/useTxTracker.js';
|
|
23
|
+
export { useWaitForConfirmations } from './hooks/useWaitForConfirmations.js';
|
|
24
|
+
export { useMinimumTransferAmount } from './hooks/useMinimumTransferAmount.js';
|
|
25
|
+
export { isBase58Address, isBase58AddressInNetwork, isBech32Address, isBech32AddressInNetwork } from './lib/btc/address.js';
|
|
26
|
+
export { getBridgeFeeEstimateBTC, getStaticBridgeFeeEstimateBTC } from './lib/btc/getBridgeFeeEstimateBTC.js';
|
|
27
|
+
export { getBtcAsset } from './lib/btc/getBtcAsset.js';
|
|
28
|
+
export { getBtcTransaction } from './lib/btc/getBtcTransaction.js';
|
|
29
|
+
export { getBtcTransactionDetails } from './lib/btc/getBtcTransactionDetails.js';
|
|
30
|
+
export { getMinimumTransferAmount } from './lib/btc/getMinimumTransferAmount.js';
|
|
31
|
+
export { getTxConfirmations, getTxDetails } from './lib/btc/getTxConfirmations.js';
|
|
32
|
+
export { BtcBlockchains } from './lib/btc/models.js';
|
|
33
|
+
export { btcToSatoshi, satoshiToBtc } from './lib/btc/utils.js';
|
|
34
|
+
export { getBridgeFeeEstimateEVM, getStaticBridgeFeeEstimateEVM } from './lib/getBridgeFeeEstimateEVM.js';
|
|
35
|
+
export { HistoryTxData, checkHistoryForNewTxEVM } from './lib/checkHistoryForNewTxEVM.js';
|
|
36
|
+
export { fetchConfig } from './lib/fetchConfig.js';
|
|
37
|
+
export { fetchTokenBalances } from './lib/fetchTokenBalances.js';
|
|
38
|
+
export { getAssets } from './lib/getAssets.js';
|
|
39
|
+
export { getMaxTransferAmount } from './lib/getMaxTransferAmount.js';
|
|
40
|
+
export { BridgeTransaction, EthChains, TransactionDetails, TxHash, WrapStatus } from './lib/models.js';
|
|
41
|
+
export { TrackerSubscription, trackBridgeTransaction } from './lib/tracker/trackBridgeTransaction.js';
|
|
42
|
+
export { TransferAssetEVMParams, transferAssetEVM } from './lib/transferAssetEVM.js';
|
|
43
|
+
export { BtcTransactionRequest, TransferAssetBTCParams, transferAssetBTC } from './lib/transferAssetBTC.js';
|
|
44
|
+
export { unwrapAsset } from './lib/unwrapAsset.js';
|
|
45
|
+
export { wrapAsset } from './lib/wrapAsset.js';
|
|
46
|
+
export { ETHERSCAN_API_KEY, INFURA_API_KEY, getRuntimeConfig, setBridgeEnvironment } from './runtime/config.js';
|
|
47
|
+
export { AddEthereumChainParameter, AppConfig, AppConfigWithDynamicFeesForBitcoin, AppConfigWithDynamicFeesForEthereum, AppConfigWithFullDynamicFees, AppConfigWithFullStaticFees, AppConfigWithStaticFeesForBitcoin, AppConfigWithStaticFeesForEthereum, Asset, AssetBase, AssetType, Assets, BitcoinConfigAsset, BitcoinConfigAssets, BitcoinDynamicFeeConfig, BitcoinDynamicFeeConfigAsset, BitcoinDynamicFeeConfigAssets, BitcoinDynamicFeeCriticalConfig, BitcoinStaticFeeConfig, BitcoinStaticFeeConfigAsset, BitcoinStaticFeeConfigAssets, BitcoinStaticFeeCriticalConfig, Blockchain, BridgeConfig, CriticalConfig, DynamicFeeEstimation, Environment, EthereumAssetConfigBase, EthereumConfigAsset, EthereumConfigAssets, EthereumDynamicFeeAssetConfig, EthereumDynamicFeeConfig, EthereumDynamicFeeConfigAssets, EthereumStaticFeeAssetConfig, EthereumStaticFeeConfig, EthereumStaticFeeConfigAssets, NativeAsset, NetworkType, NonCriticalConfig, RuntimeConfig } from './types/config.js';
|
|
48
|
+
export { TokenInfo, TokenInfoData } from './types/tokenInfo.js';
|
|
49
|
+
export { BIG_TEN, BIG_ZERO, capped } from './utils/bignumber.js';
|
|
50
|
+
export { getMinimumConfirmations, hasCriticalChanges, isBtcUsingDynamicFees, isEthUsingDynamicFees, isMainnetConfig } from './utils/config.js';
|
|
51
|
+
export { formatTokenAmount } from './utils/formatTokenAmount.js';
|
|
52
|
+
export { getNativeSymbol } from './utils/getNativeSymbol.js';
|
|
53
|
+
export { usdFormatter } from './utils/usdFormatter.js';
|
|
54
|
+
export { isAddressBlocklisted } from './utils/isAddressBlocklisted.js';
|
|
55
|
+
export { isBtcAsset, isEthAsset, isNativeAsset } from './utils/asset.js';
|
|
56
|
+
export { AVERAGE_TRANSFER_TX_GAS_USAGE, estimateGas } from './utils/estimateGas.js';
|
package/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{BridgeSDKProvider,useBridgeSDK}from"./contexts/BridgeSDKProvider.js";export{TokenInfoProvider,initalState,useTokenInfoContext}from"./contexts/TokenInfoProvider.js";export{useBridgeConfig}from"./hooks/useBridgeConfig.js";export{useBridgeConfigUpdater}from"./hooks/useBridgeConfigUpdater.js";export{useCheckHistoryForNewTxEVM}from"./hooks/useCheckHistoryForNewTxEVM.js";export{useGetAirdropAmount}from"./hooks/useGetAirdropAmount.js";export{useGetTokenBalanceEVM}from"./hooks/useGetTokenBalanceEVM.js";export{useGetTokenBalancesEVM}from"./hooks/useGetTokenBalancesEVM.js";export{useGetTokenSymbolOnNetwork}from"./hooks/useGetTokenSymbolOnNetwork.js";export{useHasEnoughForGas}from"./hooks/useHasEnoughForGas.js";export{useIsAddressSanctioned}from"./hooks/useIsAddressSanctioned.js";export{useMaxTransferAmount}from"./hooks/useMaxTransferAmount.js";export{usePrice}from"./hooks/usePrice.js";export{usePriceForChain}from"./hooks/usePriceForChain.js";export{useResetTransactionDetailsFromParams}from"./hooks/useResetTransactionDetailsFromParams.js";export{useSubscribeForNewTransactionFromBridgeEVM}from"./hooks/useSubscribeForNewTransactionFromBridge.js";export{useTimer}from"./hooks/useTimer.js";export{useBridgeFeeEstimate}from"./hooks/useBridgeFeeEstimate.js";export{useTransferAssetEVM}from"./hooks/useTransferAssetEVM.js";export{useTransferAssetBTC}from"./hooks/useTransferAssetBTC.js";export{useTxTracker}from"./hooks/useTxTracker.js";export{useWaitForConfirmations}from"./hooks/useWaitForConfirmations.js";export{useMinimumTransferAmount}from"./hooks/useMinimumTransferAmount.js";export{isBase58Address,isBase58AddressInNetwork,isBech32Address,isBech32AddressInNetwork}from"./lib/btc/address.js";export{getBridgeFeeEstimateBTC,getStaticBridgeFeeEstimateBTC}from"./lib/btc/getBridgeFeeEstimateBTC.js";export{getBtcAsset}from"./lib/btc/getBtcAsset.js";export{getBtcTransaction}from"./lib/btc/getBtcTransaction.js";export{getBtcTransactionDetails}from"./lib/btc/getBtcTransactionDetails.js";export{getMinimumTransferAmount}from"./lib/btc/getMinimumTransferAmount.js";export{getTxConfirmations,getTxDetails}from"./lib/btc/getTxConfirmations.js";export{btcToSatoshi,satoshiToBtc}from"./lib/btc/utils.js";export{getBridgeFeeEstimateEVM,getStaticBridgeFeeEstimateEVM}from"./lib/getBridgeFeeEstimateEVM.js";export{checkHistoryForNewTxEVM}from"./lib/checkHistoryForNewTxEVM.js";export{fetchConfig}from"./lib/fetchConfig.js";export{fetchTokenBalances}from"./lib/fetchTokenBalances.js";export{getAssets}from"./lib/getAssets.js";export{getMaxTransferAmount}from"./lib/getMaxTransferAmount.js";export{WrapStatus}from"./lib/models.js";export{trackBridgeTransaction}from"./lib/tracker/trackBridgeTransaction.js";export{transferAssetEVM}from"./lib/transferAssetEVM.js";export{transferAssetBTC}from"./lib/transferAssetBTC.js";export{unwrapAsset}from"./lib/unwrapAsset.js";export{wrapAsset}from"./lib/wrapAsset.js";export{ETHERSCAN_API_KEY,INFURA_API_KEY,getRuntimeConfig,setBridgeEnvironment}from"./runtime/config.js";export{AssetType,Blockchain,Environment,NetworkType}from"./types/config.js";export{BIG_TEN,BIG_ZERO,capped}from"./utils/bignumber.js";export{getMinimumConfirmations,hasCriticalChanges,isBtcUsingDynamicFees,isEthUsingDynamicFees,isMainnetConfig}from"./utils/config.js";export{formatTokenAmount}from"./utils/formatTokenAmount.js";export{getNativeSymbol}from"./utils/getNativeSymbol.js";export{usdFormatter}from"./utils/usdFormatter.js";export{isAddressBlocklisted}from"./utils/isAddressBlocklisted.js";export{isBtcAsset,isEthAsset,isNativeAsset}from"./utils/asset.js";export{AVERAGE_TRANSFER_TX_GAS_USAGE,estimateGas}from"./utils/estimateGas.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare function isBech32Address(btcAddress: string): boolean;
|
|
2
|
+
/**
|
|
3
|
+
* In addition to Bech32 validation, it makes sure that the address is from the correct network.
|
|
4
|
+
*/
|
|
5
|
+
declare function isBech32AddressInNetwork(btcAddress: string, isMainnet: boolean): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Verify if its a valid base 58 encoded address
|
|
8
|
+
*/
|
|
9
|
+
declare function isBase58Address(addr: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Verify if address is valid base58 and matches the network
|
|
12
|
+
* @param addr P2PKH or P2SH address to verify
|
|
13
|
+
* @param isMainnet If true will verify it's a valid mainnet address
|
|
14
|
+
*/
|
|
15
|
+
declare function isBase58AddressInNetwork(addr: string, isMainnet: boolean): boolean;
|
|
16
|
+
|
|
17
|
+
export { isBase58Address, isBase58AddressInNetwork, isBech32Address, isBech32AddressInNetwork };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{address as t,networks as r}from"bitcoinjs-lib";function n(r){try{return t.fromBech32(r),!0}catch{return!1}}function c(t,r){return!!n(t)&&t.toLowerCase().startsWith(r?"bc":"tb")}function e(r){try{return t.fromBase58Check(r),!0}catch(t){return!1}}function o(n,c){if(!e(n))return!1;const o=c?r.bitcoin:r.testnet;try{return t.toOutputScript(n,o),!0}catch(t){return!1}}export{e as isBase58Address,o as isBase58AddressInNetwork,n as isBech32Address,c as isBech32AddressInNetwork};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { AppConfig, AppConfigWithStaticFeesForBitcoin } from '../../types/config.js';
|
|
3
|
+
import { BtcBlockchains } from './models.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Return the estimated bridge fee that will be paid to the bridge operators.
|
|
7
|
+
*/
|
|
8
|
+
declare function getBridgeFeeEstimateBTC({ source, config, amount, }: {
|
|
9
|
+
source: BtcBlockchains;
|
|
10
|
+
config: AppConfig;
|
|
11
|
+
amount: Big;
|
|
12
|
+
}): Big;
|
|
13
|
+
/**
|
|
14
|
+
* Legacy (static) fee estimation for BTC
|
|
15
|
+
*/
|
|
16
|
+
declare function getStaticBridgeFeeEstimateBTC(source: BtcBlockchains, config: AppConfigWithStaticFeesForBitcoin, amountInSatoshis: number): Big;
|
|
17
|
+
|
|
18
|
+
export { getBridgeFeeEstimateBTC, getStaticBridgeFeeEstimateBTC };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"big.js";import{Blockchain as e}from"../../types/config.js";import{btcToSatoshi as r,satoshiToBtc as o}from"./utils.js";import{getDynamicFeeAmount as n}from"../getDynamicFeeAmount.js";import{BIG_TEN as i}from"../../utils/bignumber.js";import{isBtcUsingDynamicFees as m}from"../../utils/config.js";import"@avalabs/core-utils-sdk";import"ethers";function a({source:o,config:a,amount:u}){if(!m(a))return s(o,a,r(u));const{wrapFeeEstimate:c,unwrapFeeEstimate:p}=a.nonCriticalBitcoin.networkInfo.btc.currentBridgeFeeEstimate;if(o===e.BITCOIN)return n(u,8,c);const{constAmount:f,numeratorPerSat:w,denominatorPerSat:F}=p.estimatedTxFee,d=f+w/F*r(u),g=n(u,8,p.bridgeToll),l=new t(d).div(i.pow(8));return g.add(l)}function s(t,r,n){const{constUnwrapFeeAmount:i,unwrapFeeNumerator:m,unwrapFeeDenominator:a,wrapFeeAmount:s}=r.nonCriticalBitcoin.networkInfo.btc.currentBridgeFeeEstimate;return t===e.BITCOIN?o(s):o(i+m/a*n)}export{a as getBridgeFeeEstimateBTC,s as getStaticBridgeFeeEstimateBTC};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t){const c=t.criticalBitcoin?.bitcoinAssets||{};return c[Object.keys(c)[0]]}export{t as getBtcAsset};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AppConfig } from '../../types/config.js';
|
|
2
|
+
import { Psbt } from 'bitcoinjs-lib';
|
|
3
|
+
import { BitcoinInputUTXO, BitcoinOutputUTXO } from '@avalabs/core-wallets-sdk';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Bitcoin to Avalanche
|
|
7
|
+
* @param changeAddress: The user's C-chain derived BTC address. Change UTXO will be sent to this address.
|
|
8
|
+
* @param config: Configuration file for the bridge.
|
|
9
|
+
* @param utxos: The available UTXOs to consume.
|
|
10
|
+
* @param amount: The amount to wrap in satoshis. Must cover the `bridgeFee`.
|
|
11
|
+
* @param feeRate: Fee rate given in satoshis per byte.
|
|
12
|
+
* @throws when the transaction cannot be created
|
|
13
|
+
*/
|
|
14
|
+
declare function getBtcTransaction(config: AppConfig, changeAddress: string, utxos: BitcoinInputUTXO[], amount: number, feeRate: number): {
|
|
15
|
+
/** The total fee (bridge fee + tx fee) */
|
|
16
|
+
fee: number;
|
|
17
|
+
tx: Psbt;
|
|
18
|
+
bridgeFee: number;
|
|
19
|
+
receiveAmount: number;
|
|
20
|
+
inputs: BitcoinInputUTXO[];
|
|
21
|
+
outputs: BitcoinOutputUTXO[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { getBtcTransaction };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Blockchain as t}from"../../types/config.js";import{networks as o}from"bitcoinjs-lib";import{isBech32AddressInNetwork as r}from"./address.js";import{getMinimumTransferAmount as e}from"./getMinimumTransferAmount.js";import{getBridgeFeeEstimateBTC as i}from"./getBridgeFeeEstimateBTC.js";import{isMainnetConfig as s}from"../../utils/config.js";import{createTransferTx as n}from"@avalabs/core-wallets-sdk";import{satoshiToBtc as m,btcToSatoshi as f}from"./utils.js";function c(c,a,u,d,p){const w=s(c);if(!r(a,w))throw new Error("Address must be bech32");if(d%1!=0)throw new Error(`Amount must be a whole number. Satoshis can not be divided. ${d}`);const b=e(t.BITCOIN,c,d);if(d<b)throw new Error(`Amount must be at least ${b} satoshis.`);const h=c.criticalBitcoin?.walletAddresses.btc||"";if(!h)throw new Error("Bridge address is not found in the config.");if(!p)throw new Error("Fee rate is not provided in the config.");const l=w?o.bitcoin:o.testnet,{inputs:g,outputs:j,psbt:E,fee:A}=n(h,a,d,p,u,l);if(!g||!j||!E)throw new Error("Transaction values can not be satisfied.");const B=i({source:t.BITCOIN,config:c,amount:m(d)}),v=f(B);return{fee:A,tx:E,bridgeFee:v,receiveAmount:d-v,inputs:g,outputs:j}}export{c as getBtcTransaction};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AppConfig } from '../../types/config.js';
|
|
2
|
+
import { BitcoinInputUTXOWithOptionalScript, BitcoinOutputUTXO } from '@avalabs/core-wallets-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Bitcoin to Avalanche
|
|
6
|
+
* @param config: Configuration file for the bridge.
|
|
7
|
+
* @param changeAddress: The user's C-chain derived BTC address. Change UTXO will be sent to this address.
|
|
8
|
+
* @param utxos: The available UTXOs to consume.
|
|
9
|
+
* @param amount: The amount to wrap in satoshis. Must cover the `bridgeFee`.
|
|
10
|
+
* @param feeRate: Fee rate given in satoshis per byte.
|
|
11
|
+
* @throws when the transaction is invalid
|
|
12
|
+
*/
|
|
13
|
+
declare function getBtcTransactionDetails(config: AppConfig, changeAddress: string, utxos: BitcoinInputUTXOWithOptionalScript[], amount: number, feeRate: number): {
|
|
14
|
+
/** The total fee (bridge fee + tx fee) */
|
|
15
|
+
fee: number;
|
|
16
|
+
bridgeFee: number;
|
|
17
|
+
receiveAmount: number;
|
|
18
|
+
inputs: BitcoinInputUTXOWithOptionalScript[];
|
|
19
|
+
outputs: BitcoinOutputUTXO[];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { getBtcTransactionDetails };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Blockchain as t}from"../../types/config.js";import{isBech32AddressInNetwork as o}from"./address.js";import{getMinimumTransferAmount as r}from"./getMinimumTransferAmount.js";import{getBridgeFeeEstimateBTC as e}from"./getBridgeFeeEstimateBTC.js";import{isMainnetConfig as s}from"../../utils/config.js";import{getTransferTxDetails as i}from"@avalabs/core-wallets-sdk";import{satoshiToBtc as n,btcToSatoshi as m}from"./utils.js";function f(f,a,u,c,d){const w=s(f);if(!o(a,w))throw new Error("Address must be bech32");if(c%1!=0)throw new Error(`Amount must be a whole number. Satoshis can not be divided. ${c}`);const p=r(t.BITCOIN,f,c);if(c<p)throw new Error(`Amount must be at least ${p} satoshis.`);const h=f.criticalBitcoin?.walletAddresses.btc||"";if(!h)throw new Error("Bridge address is not found in the config.");if(!d)throw new Error("Fee rate is not provided in the config.");const{inputs:l,outputs:b,fee:g}=i(h,a,c,d,u);if(!l||!b)throw new Error("Transaction values can not be satisfied.");const E=e({source:t.BITCOIN,config:f,amount:n(c)}),j=m(E);return{fee:g,bridgeFee:j,receiveAmount:c-j,inputs:l,outputs:b}}export{f as getBtcTransactionDetails};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AppConfig } from '../../types/config.js';
|
|
2
|
+
import { BtcBlockchains } from './models.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the minimum amount (in satoshis) can be sent to the bridge.
|
|
6
|
+
* @param source
|
|
7
|
+
* @param config
|
|
8
|
+
* @param amount
|
|
9
|
+
*/
|
|
10
|
+
declare function getMinimumTransferAmount(source: BtcBlockchains, config: AppConfig, amount: number): number;
|
|
11
|
+
|
|
12
|
+
export { getMinimumTransferAmount };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Blockchain as t}from"../../types/config.js";import{getBridgeFeeEstimateBTC as e}from"./getBridgeFeeEstimateBTC.js";import{satoshiToBtc as r,btcToSatoshi as i}from"./utils.js";import"../../utils/bignumber.js";import{isBtcUsingDynamicFees as n}from"../../utils/config.js";import"@avalabs/core-utils-sdk";import"ethers";function o(o,m,s){const u=function(o,m,s){if(n(m)){const e=o===t.BITCOIN,{currentBridgeFeeEstimate:r}=m.nonCriticalBitcoin.networkInfo.btc;if(e)return Number(r.wrapFeeEstimate.minimumFeeAmount);const{constAmount:i,numeratorPerSat:n,denominatorPerSat:u}=r.unwrapFeeEstimate.estimatedTxFee,c=i+n/u*s;return Number(r.unwrapFeeEstimate.bridgeToll.minimumFeeAmount)+c}const u=e({source:o,config:m,amount:r(s)});return i(u)}(o,m,s);if(o===t.BITCOIN){const t=m.nonCriticalBitcoin.networkInfo.btc.minimumOnboardSize;return Math.max(4*u,t)}{const{dustThreshold:t}=m.nonCriticalBitcoin.networkInfo.btc.currentBridgeFeeEstimate;return 2*(u+t)}}export{o as getMinimumTransferAmount};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as _avalabs_core_wallets_sdk from '@avalabs/core-wallets-sdk';
|
|
2
|
+
import { BitcoinProvider } from '@avalabs/core-wallets-sdk';
|
|
3
|
+
|
|
4
|
+
declare function getTxDetails(txHash: string, provider: BitcoinProvider): Promise<_avalabs_core_wallets_sdk.BitcoinTx>;
|
|
5
|
+
/**
|
|
6
|
+
* Get the number of confirmations for a given transaction hash.
|
|
7
|
+
* @param txHash
|
|
8
|
+
* @param config
|
|
9
|
+
*/
|
|
10
|
+
declare function getTxConfirmations(txHash: string, provider: BitcoinProvider): Promise<number>;
|
|
11
|
+
|
|
12
|
+
export { getTxConfirmations, getTxDetails };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
async function n(n,t){return t.getTransaction(n)}async function t(t,a){return(await n(t,a)).confirmations}export{t as getTxConfirmations,n as getTxDetails};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import r from"big.js";function e(r){return r.mul(1e8).toNumber()}function n(e){return new r(e).div(1e8)}export{e as btcToSatoshi,n as satoshiToBtc};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Maybe } from '@avalabs/core-utils-sdk';
|
|
2
|
+
import { Blockchain, AppConfig, EthereumConfigAsset } from '../types/config.js';
|
|
3
|
+
import { TransactionResponse, Block, Provider } from 'ethers';
|
|
4
|
+
|
|
5
|
+
interface HistoryTxData {
|
|
6
|
+
transaction?: TransactionResponse;
|
|
7
|
+
block?: Block | null;
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* EVM specific function to search for a new bridge transaction.
|
|
12
|
+
*/
|
|
13
|
+
declare function checkHistoryForNewTxEVM(network: Blockchain, provider: Provider, config: Maybe<AppConfig>, account: Maybe<string>, asset: Maybe<EthereumConfigAsset>, startBlockNumber: Maybe<number>): Promise<HistoryTxData | undefined>;
|
|
14
|
+
|
|
15
|
+
export { HistoryTxData, checkHistoryForNewTxEVM };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import r from"../abi/wavax.abi.json.js";import t from"../abi/erc20.abi.json.js";import{Blockchain as e}from"../types/config.js";import{Contract as o}from"ethers";async function n(n,a,i,s,c,m){const f=c?.nativeNetwork===n?c?.nativeContractAddress:c?.wrappedContractAddress;if(!f||!m||!i)return;const l=n===e.AVALANCHE?r:t,b=new o(f,l,a),u=n===e.AVALANCHE?"0x0000000000000000000000000000000000000000":i.critical.walletAddresses.ethereum,w=b.filters.Transfer(u,s),A=await a.getBlockNumber();let p=m-5,d=Math.min(p+2048-1,A);for(;d<=A;){const r=await b.queryFilter(w,p,d);if(0===r.length){if(p=d+1,d=Math.min(p+2048-1,A),p>d)return;continue}const t=await r[0].getTransaction();if(!t||!t.blockNumber)return{error:"no transaction or block number"};return{transaction:t,block:await a.getBlock(t.blockNumber)}}}export{n as checkHistoryForNewTxEVM};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{resolve as i}from"@avalabs/core-utils-sdk";import{getRuntimeConfig as t}from"../runtime/config.js";import{AssetType as c,Blockchain as o}from"../types/config.js";async function n(n){const[s,r]=await i(async function(i){const n=t(i),s=[];for(const i of n.wardenConfigURLs)s.push(fetch(i));const r=await Promise.allSettled(s),e=[];for(const i of r)if("rejected"!==i.status&&i.value&&i.value.ok)try{e.push(await i.value.json())}catch(i){console.error(i)}const a=e.reduce(((i,t)=>{if(t.critical.disableFrontend||t.criticalBitcoin?.disableFrontend)throw new Error("Disable frontend");const c=JSON.stringify([t.critical,t.criticalBitcoin]),o=i.findIndex((i=>i.criticalJsonString===c));return o<0?i.push({appConfig:t,count:1,criticalJsonString:c}):i[o].count++,i}),[]),l=a.reduce(((i,t)=>i.count>=t.count?i:t),a[0]);if(!l||l.count<n.wardenConfigURLs.length-n.configMismatchThreshold)throw new Error("Warden config mismatch");const f=l.appConfig;for(const i in f.critical.assets)f.critical.assets[i].assetType=c.ERC20,f.critical.assets[i].symbol=i;if(f.criticalBitcoin)for(const i in f.criticalBitcoin.bitcoinAssets)f.criticalBitcoin.bitcoinAssets[i].assetType=c.BTC,f.criticalBitcoin.bitcoinAssets[i].symbol=i.toUpperCase(),f.criticalBitcoin.bitcoinAssets[i].denomination=8,f.criticalBitcoin.bitcoinAssets[i].nativeNetwork=o.BITCOIN;return f}(n));return s?{config:s}:{error:r}}export{n as fetchConfig};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { Asset, Blockchain } from '../types/config.js';
|
|
3
|
+
import { Provider } from 'ethers';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Fetch token balances for EVM
|
|
7
|
+
*/
|
|
8
|
+
declare function fetchTokenBalances(tokens: Record<string, Asset>, blockchain: Blockchain, provider: Provider, account: string, deprecated?: boolean): Promise<Record<string, Big>>;
|
|
9
|
+
|
|
10
|
+
export { fetchTokenBalances };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"big.js";import n from"../abi/erc20.abi.json.js";import r from"../abi/wavax.abi.json.js";import{AssetType as e,Blockchain as a}from"../types/config.js";import{resolve as o,wait as i}from"@avalabs/core-utils-sdk";import"../utils/bignumber.js";import{isNativeAsset as s,isBtcAsset as c,isEthAsset as l}from"../utils/asset.js";import{Contract as u,formatUnits as m,isError as p}from"ethers";async function f(t,n,r,a,o){const i={};for(const l in t){const u=t[l];let m=null;u.assetType===e.ERC20?m=await w(u,n,r,a,o):s(u)?m=await d(u,n,r,a):c(u)&&(m=await await w(u,n,r,a,o)),null!==m&&(i[l]=m)}return i}async function w(i,s,c,p,f){const d=s===a.AVALANCHE?r:n;if(i.nativeNetwork!==s&&i.wrappedNetwork!==s)return null;let j;if(f&&l(i)?j=i.deprecatedTokenContractAddress:l(i)?j=s===i.nativeNetwork?i.nativeContractAddress:i.wrappedContractAddress:i.assetType===e.BTC&&(j=i.wrappedContractAddress),!j)return null;const y=new u(j,d,c),[A,C]=await o(y.balanceOf(p)),k=i.denomination??18;return A?new t(m(A,k)):b(C,(()=>w(i,s,c,p,f)))}async function d(n,r,e,a){if(n.nativeNetwork!==r||!e)return null;const[i,s]=await o(e.getBalance(a));return i?new t(m(i,n.denomination)):b(s,(()=>d(n,r,e,a)))}async function b(t,n){return p(t,"SERVER_ERROR")?(await i(1e3+Math.floor(1e3*Math.random())),n()):(console.error(t),null)}export{f as fetchTokenBalances};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AvalancheAssets, EthereumAssets } from '../contexts/models.js';
|
|
2
|
+
import { Blockchain, CriticalConfig, BitcoinConfigAssets, Assets } from '../types/config.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Return the assets available for the given chain
|
|
6
|
+
* @param blockchain The blockchain to get asset dict for
|
|
7
|
+
* @param config The config of the bridge
|
|
8
|
+
*/
|
|
9
|
+
declare function getAssets(blockchain: Blockchain.AVALANCHE, config: CriticalConfig): AvalancheAssets;
|
|
10
|
+
declare function getAssets(blockchain: Blockchain.BITCOIN, config: CriticalConfig): BitcoinConfigAssets;
|
|
11
|
+
declare function getAssets(blockchain: Blockchain.ETHEREUM, config: CriticalConfig): EthereumAssets;
|
|
12
|
+
declare function getAssets(blockchain: Blockchain, config: CriticalConfig): Assets;
|
|
13
|
+
|
|
14
|
+
export { getAssets };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getRuntimeConfig as t}from"../runtime/config.js";import s from"../runtime/nativeAssets.js";import{Blockchain as r}from"../types/config.js";import"bitcoinjs-lib";import"big.js";import"../utils/bignumber.js";import"@avalabs/core-utils-sdk";import"ethers";import{getBtcAsset as e}from"./btc/getBtcAsset.js";import"@avalabs/core-wallets-sdk";function i(t,c){switch(t){case r.ETHEREUM:{const r={...c.critical.assets,ETH:s.ETH};return o(t,r),r}case r.AVALANCHE:{const s={...c.critical.assets,...i(r.BITCOIN,c)};return o(t,s),s}case r.BITCOIN:{const t=e(c);return t?{BTC:t}:{}}default:return{}}}function o(s,r){(t().disabledTokensOnNetwork[s]||[]).forEach((t=>delete r[t]))}export{i as getAssets};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AppConfigWithStaticFeesForEthereum, EthereumConfigAsset, AppConfig } from '../types/config.js';
|
|
2
|
+
import Big from 'big.js';
|
|
3
|
+
import { EthChains } from './models.js';
|
|
4
|
+
|
|
5
|
+
type Args = {
|
|
6
|
+
source: EthChains;
|
|
7
|
+
config: AppConfig;
|
|
8
|
+
asset: EthereumConfigAsset;
|
|
9
|
+
amount: Big;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Get Ethereum <-> Avalanche bridge fee estimate.
|
|
13
|
+
*/
|
|
14
|
+
declare function getBridgeFeeEstimateEVM({ source, config, asset, amount, }: Args): Big;
|
|
15
|
+
/**
|
|
16
|
+
* Legacy (static) fee estimation for Ethereum
|
|
17
|
+
*/
|
|
18
|
+
declare function getStaticBridgeFeeEstimateEVM(source: EthChains, config: AppConfigWithStaticFeesForEthereum, asset: EthereumConfigAsset): Big;
|
|
19
|
+
|
|
20
|
+
export { getBridgeFeeEstimateEVM, getStaticBridgeFeeEstimateEVM };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Blockchain as o}from"../types/config.js";import i from"big.js";import{BIG_TEN as n}from"../utils/bignumber.js";import{isEthUsingDynamicFees as r}from"../utils/config.js";import"@avalabs/core-utils-sdk";import"ethers";import{getDynamicFeeAmount as t}from"./getDynamicFeeAmount.js";function e({source:i,config:n,asset:e,amount:p}){if(!r(n))return m(i,n,e);const{wrapFeeApproximation:s,unwrapFeeApproximation:a}=n.nonCritical,{symbol:u,denomination:c}=e,f=i===o.ETHEREUM?s[u]:a[u];return t(p,c,f)}function m(r,t,e){const{wrapFeeApproximation:m,unwrapFeeApproximation:p}=t?.nonCritical||{},s=e.symbol,a=r===o.ETHEREUM?m?.[s]:p?.[s];return new i(a||0).div(n.pow(e.denomination))}export{e as getBridgeFeeEstimateEVM,m as getStaticBridgeFeeEstimateEVM};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"big.js";import{BIG_TEN as m,capped as i}from"../utils/bignumber.js";import"@avalabs/core-utils-sdk";import"ethers";function o(o,t,n){const{minimumFeeAmount:r,maximumFeeAmount:u,feePercentage:s,feePercentageDecimals:a}=n,p=new e(r).div(m.pow(t)),c=new e(u).div(m.pow(t)),w=new e(s).div(m.pow(a)).div(100),d=o.mul(w);return i(d,{min:p,max:c})}export{o as getDynamicFeeAmount};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { Blockchain, AppConfig } from '../types/config.js';
|
|
3
|
+
import { EthereumAssets, AvalancheAssets } from '../contexts/models.js';
|
|
4
|
+
import { JsonRpcProvider } from 'ethers';
|
|
5
|
+
|
|
6
|
+
type GetMaxTransferAmountParams = {
|
|
7
|
+
currentBlockchain: Blockchain;
|
|
8
|
+
currentAsset: string;
|
|
9
|
+
balance: Big;
|
|
10
|
+
assets: EthereumAssets | AvalancheAssets;
|
|
11
|
+
provider: JsonRpcProvider;
|
|
12
|
+
config: AppConfig;
|
|
13
|
+
};
|
|
14
|
+
declare function getMaxTransferAmount({ currentBlockchain, balance, currentAsset, assets, provider, config, }: GetMaxTransferAmountParams): Promise<Big | null>;
|
|
15
|
+
|
|
16
|
+
export { getMaxTransferAmount };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"big.js";import{AssetType as e}from"../types/config.js";import{getGasAsset as r}from"../utils/getGasAsset.js";import{getContract as s}from"../utils/getContract.js";import i from"../abi/weth.abi.json.js";import{resolve as o,BIG_TEN as a}from"@avalabs/core-utils-sdk";import"../utils/bignumber.js";import{isNativeAsset as n,isBtcAsset as m}from"../utils/asset.js";async function l({currentBlockchain:l,balance:c,currentAsset:u,assets:p,provider:f,config:d}){const g=r(l),w=p[u||""];if(!w)return null;if(n(w)&&w.symbol===g){const r=p[w.wrappedAssetSymbol];if(!r||r.assetType!==e.ERC20)return null;if(m(r))throw new Error("Unable to calculate BTC fee data with EVM provider.");const n=s(r.nativeContractAddress,i,f),l=await f.getFeeData(),u=await n.deposit.estimateGas({value:1}),[g,b]=await o(n.transfer.estimateGas(d.critical.walletAddresses.ethereum,1));b&&console.error(b);const j=new t(u.toString()).add(g?g.toString():0).times(l.gasPrice?.toString()??0).times(2).div(a.pow(w.denomination));return j.gte(c)?null:c.minus(j)}return c}export{l as getMaxTransferAmount};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import o from"big.js";import{Blockchain as i}from"../types/config.js";import{BIG_TEN as t,BIG_ZERO as r}from"../utils/bignumber.js";import{isEthUsingDynamicFees as m}from"../utils/config.js";import"@avalabs/core-utils-sdk";import"ethers";import{getBridgeFeeEstimateEVM as e}from"./getBridgeFeeEstimateEVM.js";import{FEE_ESTIMATION_MULTIPLIER as n}from"../constants.js";function s(s,p,u){if(m(p)){const r=s===i.ETHEREUM?"wrapFeeApproximation":"unwrapFeeApproximation",{minimumFeeAmount:m}=p.nonCritical[r][u.symbol];return new o(m).div(t.pow(u.denomination)).mul(n)}return e({source:s,config:p,asset:u,amount:r}).mul(n)}export{s as getMinimumTransferAmountEVM};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Contract as t}from"ethers";import r from"../abi/erc20.abi.json.js";import{getRuntimeConfig as n}from"../runtime/config.js";import{Blockchain as e,Environment as o}from"../types/config.js";const a={[e.ETHEREUM]:"0x6b7a87899490EcE95443e979cA9485CBE7E71522",[e.AVALANCHE]:"0x9b17bAADf0f21F03e35249e0e59723F34994F806"};async function c(c,i,s,E){const A=E.critical.assets.WETH;if(!A||n().environment!==o.PROD)return!1;try{const n=new t(A.nativeContractAddress,r,s),o=await n.allowance(c,a[e.ETHEREUM]),E=new t(A.wrappedContractAddress,r,i),f=await E.allowance(c,a[e.AVALANCHE]);return 0n!==o||0n!==f}catch(t){return!1}}export{c as hasAddressVulnerableMultichainApproval};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { Blockchain } from '../types/config.js';
|
|
3
|
+
|
|
4
|
+
interface TransactionDetails {
|
|
5
|
+
tokenSymbol: string;
|
|
6
|
+
amount: Big;
|
|
7
|
+
}
|
|
8
|
+
type EthChains = Blockchain.ETHEREUM | Blockchain.AVALANCHE;
|
|
9
|
+
interface BridgeTransaction {
|
|
10
|
+
/** C-chain address */
|
|
11
|
+
addressC: string;
|
|
12
|
+
/** C-chain derived BTC address */
|
|
13
|
+
addressBTC: string;
|
|
14
|
+
/** The amount requested by the user to transfer */
|
|
15
|
+
amount: Big;
|
|
16
|
+
/** Token being transferred */
|
|
17
|
+
symbol: string;
|
|
18
|
+
/**
|
|
19
|
+
* The transaction was successfully created on the target blockchain and
|
|
20
|
+
* bridging is finished.
|
|
21
|
+
*/
|
|
22
|
+
complete: boolean;
|
|
23
|
+
completedAt?: number;
|
|
24
|
+
/** Set when there is an error with transaction tracking */
|
|
25
|
+
error?: any;
|
|
26
|
+
/** The network environment */
|
|
27
|
+
environment: 'main' | 'test';
|
|
28
|
+
sourceChain: Blockchain;
|
|
29
|
+
/** When tracking the source confirmations started */
|
|
30
|
+
sourceStartedAt: number;
|
|
31
|
+
sourceTxHash: string;
|
|
32
|
+
sourceNetworkFee?: Big;
|
|
33
|
+
confirmationCount: number;
|
|
34
|
+
requiredConfirmationCount: number;
|
|
35
|
+
targetChain: Blockchain;
|
|
36
|
+
/** When tracking the target transaction started */
|
|
37
|
+
targetStartedAt?: number;
|
|
38
|
+
targetTxHash?: string;
|
|
39
|
+
/**
|
|
40
|
+
* The fee paid to the bridge operators
|
|
41
|
+
* (paid from the transferred asset e.g. LINK or WETH)
|
|
42
|
+
*/
|
|
43
|
+
targetBridgeFee?: Big;
|
|
44
|
+
/**
|
|
45
|
+
* The fee paid to the blockchain
|
|
46
|
+
* (paid in the native token e.g. ETH or AVAX)
|
|
47
|
+
*/
|
|
48
|
+
targetNetworkFee?: Big;
|
|
49
|
+
/** Block number used to find the target transaction hash */
|
|
50
|
+
startBlockNumber?: number;
|
|
51
|
+
}
|
|
52
|
+
type TxHash = string;
|
|
53
|
+
declare enum WrapStatus {
|
|
54
|
+
INITIAL = 0,
|
|
55
|
+
WAITING_FOR_DEPOSIT_CONFIRMATION = 1,
|
|
56
|
+
WAITING_FOR_DEPOSIT = 2,
|
|
57
|
+
WAITING_FOR_CONFIRMATION = 3,
|
|
58
|
+
COMPLETE = 4,
|
|
59
|
+
VULNERABLE_ADDRESS = 5
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { BridgeTransaction, EthChains, TransactionDetails, TxHash, WrapStatus };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var I=(I=>(I[I.INITIAL=0]="INITIAL",I[I.WAITING_FOR_DEPOSIT_CONFIRMATION=1]="WAITING_FOR_DEPOSIT_CONFIRMATION",I[I.WAITING_FOR_DEPOSIT=2]="WAITING_FOR_DEPOSIT",I[I.WAITING_FOR_CONFIRMATION=3]="WAITING_FOR_CONFIRMATION",I[I.COMPLETE=4]="COMPLETE",I[I.VULNERABLE_ADDRESS=5]="VULNERABLE_ADDRESS",I))(I||{});export{I as WrapStatus};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Blockchain as t}from"../../types/config.js";import{getBlockNumberBitcoin as e}from"./getBlockNumberBitcoin.js";import{getSourceTxDataBitcoin as r}from"./getSourceTxDataBitcoin.js";import{getSourceTxDataEVM as i}from"./getSourceTxDataEVM.js";import{getTargetTxDataBitcoin as a}from"./getTargetTxDataBitcoin.js";import{getTargetTxDataEVM as o}from"./getTargetTxDataEVM.js";import{getBlockNumberEVM as n}from"./getBlockNumberEVM.js";import{getIntervalTime as s}from"./getIntervalTime.js";const c=108e5;class g{closed;bridgeTransaction;onBridgeTransactionUpdate;config;avalancheProvider;ethereumProvider;bitcoinProvider;constructor({bridgeTransaction:t,onBridgeTransactionUpdate:e,config:r,avalancheProvider:i,ethereumProvider:a,bitcoinProvider:o}){this.closed=!1,this.bridgeTransaction=t,this.config=r,this.onBridgeTransactionUpdate=e,this.avalancheProvider=i,this.ethereumProvider=a,this.bitcoinProvider=o,this.start()}unsubscribe(){this.closed=!0}async start(){try{await this.trackSourceConfirmations(),await this.trackTargetTransaction()}catch(t){console.error(t),this.unsubscribe(),this.updateBridgeTransaction({error:t})}}unsubscribeIfComplete(){const{complete:t,sourceStartedAt:e}=this.bridgeTransaction,r=Date.now()-e>c;!t&&r&&this.updateBridgeTransaction({complete:!0,completedAt:Date.now(),error:"timeout"}),(t||r)&&this.unsubscribe()}async trackSourceConfirmations(){return this.onInterval(this.bridgeTransaction.sourceChain,(async t=>{const{confirmationCount:e,requiredConfirmationCount:r,targetStartedAt:i,startBlockNumber:a}=this.bridgeTransaction;if(i)return void t();const{confirmations:o,networkFee:n}=await this.getSourceConfirmations(),s=o>=r;if(o>e&&!s){const t=await this.getTargetBlockNumber();this.updateBridgeTransaction({sourceNetworkFee:n,confirmationCount:o,startBlockNumber:t})}else if(s){const e=a||await this.getTargetBlockNumber();this.updateBridgeTransaction({sourceNetworkFee:n,confirmationCount:o,targetStartedAt:Date.now(),startBlockNumber:e}),t()}}))}async trackTargetTransaction(){return this.onInterval(this.bridgeTransaction.targetChain,(async t=>{const e=await this.getTargetTxData();e&&(this.updateBridgeTransaction({targetTxHash:e.hash,targetBridgeFee:e.bridgeFee,targetNetworkFee:e.networkFee}),e.isConfirmed&&(this.updateBridgeTransaction({complete:!0,completedAt:Date.now()}),this.unsubscribe(),t()))}))}updateBridgeTransaction(t){this.bridgeTransaction={...this.bridgeTransaction,...t},this.onBridgeTransactionUpdate(this.bridgeTransaction)}async getSourceConfirmations(){return this.bridgeTransaction.sourceChain===t.BITCOIN?r(this):i(this)}async getTargetTxData(){switch(this.bridgeTransaction.targetChain){case t.BITCOIN:return a(this);case t.AVALANCHE:case t.ETHEREUM:return o(this)}}async getTargetBlockNumber(){return this.bridgeTransaction.targetChain===t.BITCOIN?e(this):n(this)}_getIntervalDelayTime(e){return e===this.bridgeTransaction.targetChain&&e===t.BITCOIN?2e4:0}onInterval(t,e){const r=s(t);return new Promise((i=>{const a=async(t=0)=>{if(this.unsubscribeIfComplete(),this.closed)i();else try{let t=!1;await e((()=>{t=!0,i()})),t||setTimeout(a,r)}catch(e){console.error(e);setTimeout((()=>a(t+1)),r*2**t)}},o=this._getIntervalDelayTime(t);setTimeout(a,o)}))}}export{c as TRACKING_LIMIT_MS,g as Tracker};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
async function i(i){return await i.bitcoinProvider.getChainHeight()}export{i as getBlockNumberBitcoin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getEVMProvider as r}from"./getEVMProvider.js";async function t(t){return r(t,t.bridgeTransaction.targetChain).getBlockNumber()}export{t as getBlockNumberEVM};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import o from"big.js";import r from"../../abi/erc20.abi.json.js";import s from"../../abi/wavax.abi.json.js";import{Blockchain as i}from"../../types/config.js";import{Interface as t,formatUnits as a}from"ethers";async function n(n,m,e){if(!e)return;const p=n===i.AVALANCHE?s:r,f=new t(p).parseLog({data:e.logs[0].data,topics:[...e.logs[0].topics]}),c=f?.args[2];return m.minus(new o(a(c)))}export{n as getBridgeFeeActualEVM};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Blockchain as r}from"../../types/config.js";function e(e,o){return o===r.AVALANCHE?e.avalancheProvider:e.ethereumProvider}export{e as getEVMProvider};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Blockchain as e}from"../../types/config.js";function o(o){return o===e.AVALANCHE?1e3:o===e.ETHEREUM?3e4:6e4}export{o as getIntervalTime};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{bigintToBig as r}from"@avalabs/core-utils-sdk";async function s(s,a){if(!a)return;return s.gasPrice&&r(s.gasPrice*a.gasUsed,18)}export{s as getNetworkFeeEVM};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"bitcoinjs-lib";import"big.js";import{satoshiToBtc as i}from"../btc/utils.js";import"../../utils/bignumber.js";import"@avalabs/core-utils-sdk";import"ethers";import"@avalabs/core-wallets-sdk";import{getTxDetails as t}from"../btc/getTxConfirmations.js";async function o(o){const{sourceTxHash:r}=o.bridgeTransaction,{confirmations:s,fees:e}=await t(r,o.bitcoinProvider);return{confirmations:s,networkFee:i(e)}}export{o as getSourceTxDataBitcoin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getNetworkFeeEVM as t}from"./getNetworkFeeEVM.js";import{getEVMProvider as a}from"./getEVMProvider.js";async function o(o){const{sourceChain:i,sourceTxHash:r}=o.bridgeTransaction,e=a(o,i),n=await e.getTransaction(r),s=n&&await e.getTransactionReceipt(n.hash),c=s?await t(n,s):void 0;return{confirmations:await(n?.confirmations())||0,networkFee:c}}export{o as getSourceTxDataEVM};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"bitcoinjs-lib";import"big.js";import{satoshiToBtc as t,btcToSatoshi as s}from"../btc/utils.js";import"../../utils/bignumber.js";import"@avalabs/core-utils-sdk";import"ethers";import"@avalabs/core-wallets-sdk";import{getTxDetails as i}from"../btc/getTxConfirmations.js";async function e(e){const{bridgeTransaction:o,config:r,bitcoinProvider:a}=e,{amount:n,addressBTC:c,startBlockNumber:d}=o,{confirmed:l,unconfirmed:m}=await a.getUTXOs(c,!1),b=[...l.filter((t=>!d||t.blockHeight>=d)).sort(((t,s)=>t.blockHeight-s.blockHeight)),...m];for(const e of b){const o=await i(e.txHash,a);if(o.addresses.includes(r.criticalBitcoin?.walletAddresses.btc||"")){const i=o.outputs.find((t=>1===t.addresses?.length&&t.addresses[0]===c)),e=i&&t(s(n)-i.value),r=o.confirmations>=1;return{hash:o.hash,bridgeFee:e,networkFee:t(o.fees),isConfirmed:r}}}}export{e as getTargetTxDataBitcoin};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{checkHistoryForNewTxEVM as t}from"../checkHistoryForNewTxEVM.js";import{getAssets as r}from"../getAssets.js";import{getBridgeFeeActualEVM as e}from"./getBridgeFeeActualEVM.js";import{getNetworkFeeEVM as o}from"./getNetworkFeeEVM.js";import{getEVMProvider as i}from"./getEVMProvider.js";async function a(a){const{amount:s,addressC:n,startBlockNumber:c,symbol:m,targetChain:f}=a.bridgeTransaction,g=i(a,f),h=a.config,w=r(f,a.config)[m],{error:d,transaction:p}=await t(f,g,h,n,w,c)||{};if(d)throw d;if(p){const t=await g.getTransactionReceipt(p.hash),r=await e(f,s,t),i=await o(p,t);return{hash:p.hash,bridgeFee:r,networkFee:i,isConfirmed:!0}}}export{a as getTargetTxDataEVM};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AppConfig } from '../../types/config.js';
|
|
2
|
+
import { BridgeTransaction } from '../models.js';
|
|
3
|
+
import { BitcoinProvider } from '@avalabs/core-wallets-sdk';
|
|
4
|
+
import { Provider } from 'ethers';
|
|
5
|
+
|
|
6
|
+
interface TrackerArgs {
|
|
7
|
+
bridgeTransaction: BridgeTransaction;
|
|
8
|
+
onBridgeTransactionUpdate: (bridgeTransaction: BridgeTransaction) => void;
|
|
9
|
+
config: AppConfig;
|
|
10
|
+
avalancheProvider: Provider;
|
|
11
|
+
ethereumProvider: Provider;
|
|
12
|
+
bitcoinProvider: BitcoinProvider;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { TrackerArgs };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TrackerArgs } from './models.js';
|
|
2
|
+
|
|
3
|
+
interface TrackerSubscription {
|
|
4
|
+
/** Cancel tracking */
|
|
5
|
+
unsubscribe(): void;
|
|
6
|
+
/** A flag to indicate whether this has already been unsubscribed */
|
|
7
|
+
readonly closed: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Track a bridge transaction to completion.
|
|
11
|
+
*
|
|
12
|
+
* The process consists of two steps:
|
|
13
|
+
* - Ensure that the source blockchain has reached the required number of
|
|
14
|
+
* confirmations.
|
|
15
|
+
* - Watch for the new transaction to be created on the target blockchain.
|
|
16
|
+
*
|
|
17
|
+
* During the process `onBridgeTransactionUpdate` will be called when the state
|
|
18
|
+
* of the `bridgeTransaction` changes e.g. `confirmationCount`
|
|
19
|
+
*
|
|
20
|
+
* When the two steps finish `onBridgeTransactionUpdate` will be called a final
|
|
21
|
+
* time with `complete` set to true.
|
|
22
|
+
*
|
|
23
|
+
* @returns a subscription object that can be used to unsubscribe
|
|
24
|
+
* (e.g. when used in a `useEffect` hook)
|
|
25
|
+
*/
|
|
26
|
+
declare function trackBridgeTransaction(args: TrackerArgs): TrackerSubscription;
|
|
27
|
+
|
|
28
|
+
export { TrackerSubscription, trackBridgeTransaction };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Tracker as r}from"./Tracker.js";function e(e){return new r(e)}export{e as trackBridgeTransaction};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AppConfig } from '../types/config.js';
|
|
2
|
+
import { WrapStatus, TxHash } from './models.js';
|
|
3
|
+
|
|
4
|
+
type BtcTransactionRequest = [
|
|
5
|
+
toAddress: string,
|
|
6
|
+
amount: string,
|
|
7
|
+
feeRate: number
|
|
8
|
+
];
|
|
9
|
+
type TransferAssetBTCParams = {
|
|
10
|
+
amount: string;
|
|
11
|
+
feeRate: number;
|
|
12
|
+
config: AppConfig;
|
|
13
|
+
onStatusChange: (status: WrapStatus) => void;
|
|
14
|
+
onTxHashChange: (txHash: string) => void;
|
|
15
|
+
signAndSendBTC: (txParams: BtcTransactionRequest) => Promise<TxHash>;
|
|
16
|
+
};
|
|
17
|
+
declare const transferAssetBTC: ({ amount, feeRate, config, onStatusChange, onTxHashChange, signAndSendBTC, }: TransferAssetBTCParams) => Promise<string>;
|
|
18
|
+
|
|
19
|
+
export { BtcTransactionRequest, TransferAssetBTCParams, transferAssetBTC };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Blockchain as t}from"../types/config.js";import{WrapStatus as o}from"./models.js";import"bitcoinjs-lib";import"big.js";import"../utils/bignumber.js";import"@avalabs/core-utils-sdk";import"ethers";import{getMinimumTransferAmount as r}from"./btc/getMinimumTransferAmount.js";import"@avalabs/core-wallets-sdk";const s=async({amount:s,feeRate:i,config:e,onStatusChange:n,onTxHashChange:a,signAndSendBTC:m})=>{n(o.INITIAL);const c=e.criticalBitcoin?.walletAddresses.btc||"";if(!c)throw new Error("Bridge address is not found in the config.");const d=r(t.BITCOIN,e,Number(s));if(Number(s)<d)throw new Error(`Amount must be at least ${d} satoshis.`);if(!i)throw new Error("Fee rate is not provided.");const u=[c,s,i];n(o.WAITING_FOR_CONFIRMATION);const b=await m(u);return n(o.COMPLETE),a(b),b};export{s as transferAssetBTC};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { Blockchain, Asset, AppConfig } from '../types/config.js';
|
|
3
|
+
import { JsonRpcApiProvider, TransactionRequest } from 'ethers';
|
|
4
|
+
import { WrapStatus, TxHash } from './models.js';
|
|
5
|
+
|
|
6
|
+
type TransferAssetEVMParams = {
|
|
7
|
+
currentBlockchain: Blockchain.AVALANCHE | Blockchain.ETHEREUM;
|
|
8
|
+
amount: Big;
|
|
9
|
+
account: string;
|
|
10
|
+
asset: Asset;
|
|
11
|
+
avalancheProvider: JsonRpcApiProvider;
|
|
12
|
+
ethereumProvider: JsonRpcApiProvider;
|
|
13
|
+
config: AppConfig;
|
|
14
|
+
onStatusChange: (status: WrapStatus) => void;
|
|
15
|
+
onTxHashChange: (txHash: string) => void;
|
|
16
|
+
signAndSendEVM?: (txData: TransactionRequest) => Promise<TxHash>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Transfer an ERC20 asset.
|
|
20
|
+
* When currentBlockchain is Avalanche the asset will be transferred to
|
|
21
|
+
* Ethereum and vice versa.
|
|
22
|
+
*
|
|
23
|
+
* @param signAndSendEVM Required when the provider for the currentBlockchain
|
|
24
|
+
* does not support signing transactions.
|
|
25
|
+
*/
|
|
26
|
+
declare function transferAssetEVM({ currentBlockchain, amount, account, asset, avalancheProvider, ethereumProvider, config, onStatusChange, onTxHashChange, signAndSendEVM, }: TransferAssetEVMParams): Promise<TxHash>;
|
|
27
|
+
|
|
28
|
+
export { TransferAssetEVMParams, transferAssetEVM };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Blockchain as r}from"../types/config.js";import{unwrapAsset as t}from"./unwrapAsset.js";import{wrapAsset as o}from"./wrapAsset.js";import"../utils/bignumber.js";import{isNativeAsset as e,isEthAsset as s}from"../utils/asset.js";import"@avalabs/core-utils-sdk";import"ethers";async function n({currentBlockchain:n,amount:a,account:i,asset:m,avalancheProvider:p,ethereumProvider:u,config:c,onStatusChange:f,onTxHashChange:h,signAndSendEVM:A}){if(n===r.AVALANCHE){if(e(m))throw new Error("Cannot transfer AVAX");return t(a,i,m,p,h,A)}if(!s(m)&&!e(m))throw new Error("Unsupported asset type");return o(a,i,m,p,u,c,f,h,A)}export{n as transferAssetEVM};
|