@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/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("react"),e=require("bitcoinjs-lib"),n=require("big.js"),a=require("@avalabs/core-utils-sdk"),s=require("ethers"),r=require("@avalabs/core-wallets-sdk"),o=require("@avalabs/core-coingecko-sdk"),i=(t=>(t.AVALANCHE="avalanche",t.ETHEREUM="ethereum",t.BITCOIN="bitcoin",t.UNKNOWN="",t))(i||{}),c=(t=>(t.MAINNET="mainnet",t.TESTNET="testnet",t))(c||{}),u=(t=>(t.DEV="development",t.STAGING="staging",t.TEST="test",t.PROD="prod",t))(u||{}),d=(t=>(t[t.NATIVE=0]="NATIVE",t[t.ERC20=1]="ERC20",t[t.BTC=2]="BTC",t))(d||{});const p=process.env.ETHERSCAN_API_KEY||process.env.REACT_APP_ETHERSCAN_API_KEY,l=process.env.INFURA_API_KEY||process.env.REACT_APP_INFURA_API_KEY;let m;function f(t){if(t)return h[t];if(!m)throw new Error("No environment set, initialize by calling setBridgeEnvironment");return m}const y={environment:u.DEV,bridgeUrl:"http://localhost:3000",tokenInfoUrl:"https://raw.githubusercontent.com/ava-labs/avalanche-bridge-resources/main/token_list.test.json",configMismatchThreshold:1,wardenConfigURLs:["https://warden1-avax-dev-storage.s3.amazonaws.com/bridge_settings.json","https://warden2-avax-dev-storage.s3.amazonaws.com/bridge_settings.json","https://warden3-avax-dev-storage.s3.amazonaws.com/bridge_settings.json"],avalancheNetworkConfig:{chainId:"0xa869",chainName:"Avalanche Fuji Testnet",nativeCurrency:{name:"Fuji",symbol:"AVAX",decimals:18},rpcUrls:["https://api.avax-test.network/ext/bc/C/rpc"],blockExplorerUrls:["https://subnets-test.avax.network/c-chain"]},ethereumNetworkConfig:{chainId:11155111,rpcUrls:[`https://sepolia.infura.io/v3/${l}`]},disabledTokensOnNetwork:{[i.AVALANCHE]:[],[i.ETHEREUM]:["FAU"]}},w={...y,environment:u.STAGING,bridgeUrl:"https://bridge.avax-test.network",tokenInfoUrl:"https://raw.githubusercontent.com/ava-labs/avalanche-bridge-resources/main/token_list.test.json"},b={...w,environment:u.TEST,bridgeUrl:"https://bridge.avax-test.network",tokenInfoUrl:"https://raw.githubusercontent.com/ava-labs/avalanche-bridge-resources/main/token_list.test.json",configMismatchThreshold:2,wardenConfigURLs:["https://ava-warden-bucket.s3.eu-central-1.amazonaws.com/bridge_settings.json","https://ava-warden-testnet.s3.us-west-1.amazonaws.com/bridge_settings.json","https://avalabs-testnet-cce1-testnet-warden-bucket.s3.ca-central-1.amazonaws.com/bridge_settings.json","https://avalabs-warden-test-blob.s3.amazonaws.com/bridge_settings.json","https://avawarden.s3.amazonaws.com/bridge_settings.json","https://blob-storage-testnet.warden-avascan.info/bridge_settings.json","https://chainstack-ava-warden-testnet.s3.us-west-2.amazonaws.com/bridge_settings.json","https://s3.amazonaws.com/warden-mgmt-prod-testnet.blockdaemon.com/bridge_settings.json"]},g={...b,environment:u.PROD,bridgeUrl:"https://bridge.avax.network",tokenInfoUrl:"https://raw.githubusercontent.com/ava-labs/avalanche-bridge-resources/main/token_list.json",avalancheNetworkConfig:{chainId:"0xa86a",chainName:"Avalanche Mainnet C-Chain",nativeCurrency:{name:"AVAX",symbol:"AVAX",decimals:18},rpcUrls:["https://api.avax.network/ext/bc/C/rpc"],blockExplorerUrls:["https://subnets.avax.network/c-chain"]},ethereumNetworkConfig:{chainId:1,rpcUrls:[`https://mainnet.infura.io/v3/${l}`]},wardenConfigURLs:["https://ava-warden-bucket-prod.s3.eu-central-1.amazonaws.com/bridge_settings.json","https://ava-warden-mainnet.s3.us-west-1.amazonaws.com/bridge_settings.json","https://avalabs-mainnet-cce1-mainnet-warden-bucket.s3.ca-central-1.amazonaws.com/bridge_settings.json","https://avawarden-prod.s3.amazonaws.com/bridge_settings.json","https://blob-storage-mainnet.warden-avascan.info/bridge_settings.json","https://chainstack-ava-warden-mainnet.s3.us-west-2.amazonaws.com/bridge_settings.json","https://s3.amazonaws.com/warden-mgmt-prod-mainnet.blockdaemon.com/bridge_settings.json","https://warden-avax-storage.s3.amazonaws.com/bridge_settings.json"],disabledTokensOnNetwork:{[i.AVALANCHE]:[],[i.ETHEREUM]:["CRV"]}},h={[u.PROD]:g,[u.STAGING]:w,[u.TEST]:b,[u.DEV]:y};const T={},A=t.createContext(T),E=({children:e})=>{const[n,a]=t.useState();return t.useEffect((()=>{!async function(){const t=await async function(){try{const t=await fetch(f().tokenInfoUrl);return await t.json()}catch(t){return{}}}();a(t)}()}),[]),t.createElement(A.Provider,{value:n},e)};function C(){return t.useContext(A)}const v={ETH:{symbol:"ETH",tokenName:"Ether",assetType:d.NATIVE,nativeNetwork:i.ETHEREUM,wrappedAssetSymbol:"WETH",denomination:18,coingeckoId:"ethereum"}};function N(t){try{return e.address.fromBech32(t),!0}catch{return!1}}function I(t,e){return!!N(t)&&t.toLowerCase().startsWith(e?"bc":"tb")}function k(t){try{return e.address.fromBase58Check(t),!0}catch(t){return!1}}function x(t){return t.mul(1e8).toNumber()}function B(t){return new n(t).div(1e8)}const S=new n(10),M=new n(0),F=(t,{max:e,min:n})=>t.gt(e)?e:t.lt(n)?n:t;var H=(t=>(t[t.MAINNET=43114]="MAINNET",t[t.TESTNET=43113]="TESTNET",t))(H||{});const R=3;function O(t){return t.critical.networks.avalanche===H.MAINNET}function _(t,e){return JSON.stringify(U(t))!==JSON.stringify(U(e))}function U(t){if(!t.config)return;const{critical:e,criticalBitcoin:n}=t.config;return[e,n]}function V(t){return Boolean(t.critical.useNewFeeStructure)}function P(t){return Boolean(t.criticalBitcoin.useNewFeeStructure)}const L=new Intl.NumberFormat(void 0,{style:"currency",currency:"USD",currencyDisplay:"symbol",minimumFractionDigits:2,maximumFractionDigits:2}),D=({addressEVM:t,addressBTC:e,bridgeConfig:n})=>!(!t||!n.config?.critical.addressBlocklist.includes(t))||!(!e||!n.config?.criticalBitcoin.addressBlocklist.includes(e)),G=t=>t.assetType===d.NATIVE,j=t=>t.assetType===d.BTC,W=t=>t.assetType===d.ERC20;var z=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"owner",type:"address"},{indexed:!0,name:"spender",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"from",type:"address"},{indexed:!0,name:"to",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Transfer",type:"event"}],$=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"guy",type:"address"},{name:"wad",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"src",type:"address"},{name:"dst",type:"address"},{name:"wad",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"wad",type:"uint256"}],name:"withdraw",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"balanceOf",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"dst",type:"address"},{name:"wad",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[],name:"deposit",outputs:[],payable:!0,stateMutability:"payable",type:"function"},{constant:!0,inputs:[{name:"",type:"address"},{name:"",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"src",type:"address"},{indexed:!0,name:"guy",type:"address"},{indexed:!1,name:"wad",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"src",type:"address"},{indexed:!0,name:"dst",type:"address"},{indexed:!1,name:"wad",type:"uint256"}],name:"Transfer",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"dst",type:"address"},{indexed:!1,name:"wad",type:"uint256"}],name:"Deposit",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"src",type:"address"},{indexed:!1,name:"wad",type:"uint256"}],name:"Withdrawal",type:"event"}],q=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"src",type:"address"},{indexed:!0,internalType:"address",name:"guy",type:"address"},{indexed:!1,internalType:"uint256",name:"wad",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"dst",type:"address"},{indexed:!1,internalType:"uint256",name:"wad",type:"uint256"}],name:"Deposit",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"src",type:"address"},{indexed:!0,internalType:"address",name:"dst",type:"address"},{indexed:!1,internalType:"uint256",name:"wad",type:"uint256"}],name:"Transfer",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"src",type:"address"},{indexed:!1,internalType:"uint256",name:"wad",type:"uint256"}],name:"Withdrawal",type:"event"},{payable:!0,stateMutability:"payable",type:"fallback"},{constant:!0,inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"guy",type:"address"},{internalType:"uint256",name:"wad",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{internalType:"address",name:"",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[],name:"deposit",outputs:[],payable:!0,stateMutability:"payable",type:"function"},{constant:!0,inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"dst",type:"address"},{internalType:"uint256",name:"wad",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"src",type:"address"},{internalType:"address",name:"dst",type:"address"},{internalType:"uint256",name:"wad",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{internalType:"uint256",name:"wad",type:"uint256"}],name:"withdraw",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"chain_id",type:"uint256"}],name:"unwrap",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"swap",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{internalType:"address",name:"",type:"address"}],name:"swapSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"}];function K(t,e,n=!1){return n&&e?function(t,e){return new s.JsonRpcSigner(t,e)}(t,e):t}function X(t,e,n,a,r=!1){if(!s.isAddress(t)||t===s.ZeroAddress)throw Error(`Invalid 'address' parameter '${t}'.`);return new s.Contract(t,e,K(n,a,r))}function J(t,e,a){const{minimumFeeAmount:s,maximumFeeAmount:r,feePercentage:o,feePercentageDecimals:i}=a,c=new n(s).div(S.pow(e)),u=new n(r).div(S.pow(e)),d=new n(o).div(S.pow(i)).div(100),p=t.mul(d);return F(p,{min:c,max:u})}function Y({source:t,config:e,amount:a}){if(!P(e))return Z(t,e,x(a));const{wrapFeeEstimate:s,unwrapFeeEstimate:r}=e.nonCriticalBitcoin.networkInfo.btc.currentBridgeFeeEstimate;if(t===i.BITCOIN)return J(a,8,s);const{constAmount:o,numeratorPerSat:c,denominatorPerSat:u}=r.estimatedTxFee,d=o+c/u*x(a),p=J(a,8,r.bridgeToll),l=new n(d).div(S.pow(8));return p.add(l)}function Z(t,e,n){const{constUnwrapFeeAmount:a,unwrapFeeNumerator:s,unwrapFeeDenominator:r,wrapFeeAmount:o}=e.nonCriticalBitcoin.networkInfo.btc.currentBridgeFeeEstimate;return t===i.BITCOIN?B(o):B(a+s/r*n)}function Q(t){const e=t.criticalBitcoin?.bitcoinAssets||{};return e[Object.keys(e)[0]]}function tt(t,e,n){const a=function(t,e,n){if(P(e)){const a=t===i.BITCOIN,{currentBridgeFeeEstimate:s}=e.nonCriticalBitcoin.networkInfo.btc;if(a)return Number(s.wrapFeeEstimate.minimumFeeAmount);const{constAmount:r,numeratorPerSat:o,denominatorPerSat:c}=s.unwrapFeeEstimate.estimatedTxFee,u=r+o/c*n;return Number(s.unwrapFeeEstimate.bridgeToll.minimumFeeAmount)+u}const a=Y({source:t,config:e,amount:B(n)});return x(a)}(t,e,n);if(t===i.BITCOIN){const t=e.nonCriticalBitcoin.networkInfo.btc.minimumOnboardSize;return Math.max(4*a,t)}{const{dustThreshold:t}=e.nonCriticalBitcoin.networkInfo.btc.currentBridgeFeeEstimate;return 2*(a+t)}}async function et(t,e){return e.getTransaction(t)}function nt(t,e){switch(t){case i.ETHEREUM:{const n={...e.critical.assets,ETH:v.ETH};return at(t,n),n}case i.AVALANCHE:{const n={...e.critical.assets,...nt(i.BITCOIN,e)};return at(t,n),n}case i.BITCOIN:{const t=Q(e);return t?{BTC:t}:{}}default:return{}}}function at(t,e){(f().disabledTokensOnNetwork[t]||[]).forEach((t=>delete e[t]))}const st=t.createContext({});function rt(){return t.useContext(st)}function ot(){const{bridgeConfig:t}=rt();return t}function it({source:t,config:e,asset:n,amount:a}){if(!V(e))return ct(t,e,n);const{wrapFeeApproximation:s,unwrapFeeApproximation:r}=e.nonCritical,{symbol:o,denomination:c}=n;return J(a,c,t===i.ETHEREUM?s[o]:r[o])}function ct(t,e,a){const{wrapFeeApproximation:s,unwrapFeeApproximation:r}=e?.nonCritical||{},o=a.symbol,c=t===i.ETHEREUM?s?.[o]:r?.[o];return new n(c||0).div(S.pow(a.denomination))}const ut=2048;async function dt(t,e,n,a,r,o){const c=r?.nativeNetwork===t?r?.nativeContractAddress:r?.wrappedContractAddress;if(!c||!o||!n)return;const u=t===i.AVALANCHE?q:z,d=new s.Contract(c,u,e),p=t===i.AVALANCHE?"0x0000000000000000000000000000000000000000":n.critical.walletAddresses.ethereum,l=d.filters.Transfer(p,a),m=await e.getBlockNumber();let f=o-5,y=Math.min(f+ut-1,m);for(;y<=m;){const t=await d.queryFilter(l,f,y);if(0===t.length){if(f=y+1,y=Math.min(f+ut-1,m),f>y)return;continue}const n=await t[0].getTransaction();if(!n||!n.blockNumber)return{error:"no transaction or block number"};return{transaction:n,block:await e.getBlock(n.blockNumber)}}}async function pt(t,e,n,a,s){const r={};for(const o in t){const i=t[o];let c=null;i.assetType===d.ERC20?c=await lt(i,e,n,a,s):G(i)?c=await mt(i,e,n,a):j(i)&&(c=await await lt(i,e,n,a,s)),null!==c&&(r[o]=c)}return r}async function lt(t,e,r,o,c){const u=e===i.AVALANCHE?q:z;if(t.nativeNetwork!==e&&t.wrappedNetwork!==e)return null;let p;if(c&&W(t)?p=t.deprecatedTokenContractAddress:W(t)?p=e===t.nativeNetwork?t.nativeContractAddress:t.wrappedContractAddress:t.assetType===d.BTC&&(p=t.wrappedContractAddress),!p)return null;const l=new s.Contract(p,u,r),[m,f]=await a.resolve(l.balanceOf(o)),y=t.denomination??18;return m?new n(s.formatUnits(m,y)):ft(f,(()=>lt(t,e,r,o,c)))}async function mt(t,e,r,o){if(t.nativeNetwork!==e||!r)return null;const[i,c]=await a.resolve(r.getBalance(o));return i?new n(s.formatUnits(i,t.denomination)):ft(c,(()=>mt(t,e,r,o)))}async function ft(t,e){return s.isError(t,"SERVER_ERROR")?(await a.wait(1e3+Math.floor(1e3*Math.random())),e()):(console.error(t),null)}function yt(t){return t===i.AVALANCHE?"AVAX":"ETH"}async function wt({currentBlockchain:t,balance:e,currentAsset:s,assets:r,provider:o,config:i}){const c=yt(t),u=r[s||""];if(!u)return null;if(G(u)&&u.symbol===c){const t=r[u.wrappedAssetSymbol];if(!t||t.assetType!==d.ERC20)return null;if(j(t))throw new Error("Unable to calculate BTC fee data with EVM provider.");const s=X(t.nativeContractAddress,$,o),c=await o.getFeeData(),p=await s.deposit.estimateGas({value:1}),[l,m]=await a.resolve(s.transfer.estimateGas(i.critical.walletAddresses.ethereum,1));m&&console.error(m);const f=new n(p.toString()).add(l?l.toString():0).times(c.gasPrice?.toString()??0).times(2).div(a.BIG_TEN.pow(u.denomination));return f.gte(e)?null:e.minus(f)}return e}var bt=(t=>(t[t.INITIAL=0]="INITIAL",t[t.WAITING_FOR_DEPOSIT_CONFIRMATION=1]="WAITING_FOR_DEPOSIT_CONFIRMATION",t[t.WAITING_FOR_DEPOSIT=2]="WAITING_FOR_DEPOSIT",t[t.WAITING_FOR_CONFIRMATION=3]="WAITING_FOR_CONFIRMATION",t[t.COMPLETE=4]="COMPLETE",t[t.VULNERABLE_ADDRESS=5]="VULNERABLE_ADDRESS",t))(bt||{});async function gt(t,e){if(!e)return;return t.gasPrice&&a.bigintToBig(t.gasPrice*e.gasUsed,18)}function ht(t,e){return e===i.AVALANCHE?t.avalancheProvider:t.ethereumProvider}async function Tt(t){const{amount:e,addressC:a,startBlockNumber:r,symbol:o,targetChain:c}=t.bridgeTransaction,u=ht(t,c),d=t.config,p=nt(c,t.config)[o],{error:l,transaction:m}=await dt(c,u,d,a,p,r)||{};if(l)throw l;if(m){const t=await u.getTransactionReceipt(m.hash),a=await async function(t,e,a){if(!a)return;const r=t===i.AVALANCHE?q:z,o=new s.Interface(r).parseLog({data:a.logs[0].data,topics:[...a.logs[0].topics]}),c=o?.args[2];return e.minus(new n(s.formatUnits(c)))}(c,e,t),r=await gt(m,t);return{hash:m.hash,bridgeFee:a,networkFee:r,isConfirmed:!0}}}class At{closed;bridgeTransaction;onBridgeTransactionUpdate;config;avalancheProvider;ethereumProvider;bitcoinProvider;constructor({bridgeTransaction:t,onBridgeTransactionUpdate:e,config:n,avalancheProvider:a,ethereumProvider:s,bitcoinProvider:r}){this.closed=!1,this.bridgeTransaction=t,this.config=n,this.onBridgeTransactionUpdate=e,this.avalancheProvider=a,this.ethereumProvider=s,this.bitcoinProvider=r,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,n=Date.now()-e>108e5;!t&&n&&this.updateBridgeTransaction({complete:!0,completedAt:Date.now(),error:"timeout"}),(t||n)&&this.unsubscribe()}async trackSourceConfirmations(){return this.onInterval(this.bridgeTransaction.sourceChain,(async t=>{const{confirmationCount:e,requiredConfirmationCount:n,targetStartedAt:a,startBlockNumber:s}=this.bridgeTransaction;if(a)return void t();const{confirmations:r,networkFee:o}=await this.getSourceConfirmations(),i=r>=n;if(r>e&&!i){const t=await this.getTargetBlockNumber();this.updateBridgeTransaction({sourceNetworkFee:o,confirmationCount:r,startBlockNumber:t})}else if(i){const e=s||await this.getTargetBlockNumber();this.updateBridgeTransaction({sourceNetworkFee:o,confirmationCount:r,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===i.BITCOIN?async function(t){const{sourceTxHash:e}=t.bridgeTransaction,{confirmations:n,fees:a}=await et(e,t.bitcoinProvider);return{confirmations:n,networkFee:B(a)}}(this):async function(t){const{sourceChain:e,sourceTxHash:n}=t.bridgeTransaction,a=ht(t,e),s=await a.getTransaction(n),r=s&&await a.getTransactionReceipt(s.hash),o=r?await gt(s,r):void 0;return{confirmations:await(s?.confirmations())||0,networkFee:o}}(this)}async getTargetTxData(){switch(this.bridgeTransaction.targetChain){case i.BITCOIN:return async function(t){const{bridgeTransaction:e,config:n,bitcoinProvider:a}=t,{amount:s,addressBTC:r,startBlockNumber:o}=e,{confirmed:i,unconfirmed:c}=await a.getUTXOs(r,!1),u=[...i.filter((t=>!o||t.blockHeight>=o)).sort(((t,e)=>t.blockHeight-e.blockHeight)),...c];for(const t of u){const e=await et(t.txHash,a);if(e.addresses.includes(n.criticalBitcoin?.walletAddresses.btc||"")){const t=e.outputs.find((t=>1===t.addresses?.length&&t.addresses[0]===r)),n=t&&B(x(s)-t.value),a=e.confirmations>=1;return{hash:e.hash,bridgeFee:n,networkFee:B(e.fees),isConfirmed:a}}}}(this);case i.AVALANCHE:case i.ETHEREUM:return Tt(this)}}async getTargetBlockNumber(){return this.bridgeTransaction.targetChain===i.BITCOIN?async function(t){return await t.bitcoinProvider.getChainHeight()}(this):async function(t){return ht(t,t.bridgeTransaction.targetChain).getBlockNumber()}(this)}_getIntervalDelayTime(t){return t===this.bridgeTransaction.targetChain&&t===i.BITCOIN?2e4:0}onInterval(t,e){const n=function(t){return t===i.AVALANCHE?1e3:t===i.ETHEREUM?3e4:6e4}(t);return new Promise((a=>{const s=async(t=0)=>{if(this.unsubscribeIfComplete(),this.closed)a();else try{let t=!1;await e((()=>{t=!0,a()})),t||setTimeout(s,n)}catch(e){console.error(e);setTimeout((()=>s(t+1)),n*2**t)}},r=this._getIntervalDelayTime(t);setTimeout(s,r)}))}}async function Et(t,e,n,a,s,r){if(r){return async function(t,e,n,a){const s={...t,from:e},r=await n.estimateGas(s),{chainId:o}=await n.getNetwork(),i=await a({...s,chainId:o,gasLimit:r});if("string"==typeof i)return i;throw new Error("Obtained signing result is not supported")}(await t[e].populateTransaction(...n),a,s,r)}return(await t[e](...n)).hash}async function Ct(t,e,n,s,r,o){const i=!o,c=X(n.wrappedContractAddress,q,s,e,i),u=a.bigToBigInt(t,n.denomination),d=await Et(c,"unwrap",[u,0],e,s,o);return r(d),d}const vt={[i.ETHEREUM]:"0x6b7a87899490EcE95443e979cA9485CBE7E71522",[i.AVALANCHE]:"0x9b17bAADf0f21F03e35249e0e59723F34994F806"};async function Nt(t,e,n,r,o,c,d,p,l){d(bt.INITIAL);const m=c.critical.walletAddresses.ethereum||"";if(W(n))return async function(t,e,n,s,r,o,i,c){const u=!c,d=X(n.nativeContractAddress,z,r,e,u),p=a.bigToBigInt(t,n.denomination);o(bt.WAITING_FOR_CONFIRMATION);const l=await Et(d,"transfer",[s,p],e,r,c);return i(l),o(bt.COMPLETE),l}(t,e,n,m,o,d,p,l);{const y=G(n)?c.critical.assets[n.wrappedAssetSymbol]:void 0;if(!y)throw new Error("missing wrappedAsset");return async function(t,e,n,r,o,c,d,p,l,m,y){const w=!y,b=X(r.nativeContractAddress,z,d,e,w),g=a.bigToBigInt(t,n.denomination);if(n.nativeNetwork===i.ETHEREUM){const t=await async function(t,e,n,a){const r=a.critical.assets.WETH;if(!r||f().environment!==u.PROD)return!1;try{const a=new s.Contract(r.nativeContractAddress,z,n),o=await a.allowance(t,vt[i.ETHEREUM]),c=new s.Contract(r.wrappedContractAddress,z,e),u=await c.allowance(t,vt[i.AVALANCHE]);return 0n!==o||0n!==u}catch(t){return!1}}(e,c,d,p);if(t)throw l(bt.VULNERABLE_ADDRESS),new Error("Address has vulnerable token approvals");l(bt.WAITING_FOR_DEPOSIT_CONFIRMATION);const n=X(r.nativeContractAddress,$,d,e,w),a=await Et(n,"deposit",[{value:g}],e,d,y);m(a),l(bt.WAITING_FOR_DEPOSIT),await d.waitForTransaction(a)}l(bt.WAITING_FOR_CONFIRMATION);const h=await Et(b,"transfer",[o,g],e,d,y);return m(h),l(bt.COMPLETE),h}(t,e,n,y,m,r,o,c,d,p,l)}}async function It({currentBlockchain:t,amount:e,account:n,asset:a,avalancheProvider:s,ethereumProvider:r,config:o,onStatusChange:c,onTxHashChange:u,signAndSendEVM:d}){if(t===i.AVALANCHE){if(G(a))throw new Error("Cannot transfer AVAX");return Ct(e,n,a,s,u,d)}if(!W(a)&&!G(a))throw new Error("Unsupported asset type");return Nt(e,n,a,s,r,o,c,u,d)}const kt=async({amount:t,feeRate:e,config:n,onStatusChange:a,onTxHashChange:s,signAndSendBTC:r})=>{a(bt.INITIAL);const o=n.criticalBitcoin?.walletAddresses.btc||"";if(!o)throw new Error("Bridge address is not found in the config.");const c=tt(i.BITCOIN,n,Number(t));if(Number(t)<c)throw new Error(`Amount must be at least ${c} satoshis.`);if(!e)throw new Error("Fee rate is not provided.");const u=[o,t,e];a(bt.WAITING_FOR_CONFIRMATION);const d=await r(u);return a(bt.COMPLETE),s(d),d};function xt(e,n,a,s){const[r,o]=t.useState(),{config:i}=ot();t.useEffect((()=>{n.getBlockNumber().then((t=>{o(t)})).catch((t=>console.error(t)))}),[n]);return{checkHistoryForNewTx:t.useCallback((async()=>dt(e,n,i,a,s,r)),[e,n,i,a,s,r]),startBlockNumber:r}}function Bt(e,n,a,s,r,o){const[i,c]=t.useState();return t.useEffect((()=>{!async function(){if(!n)return;const t=r&&s?await pt(n,e,a,r,o):{};c(t)}()}),[r,s,n,a,e,o]),i}function St(e,a=o.VsCurrencyType.USD){const{ethereumAssets:s}=rt(),r=C(),[i,c]=t.useState(M),u=t.useCallback((async t=>{try{const e=await o.simplePrice(o.getBasicCoingeckoHttp(),{coinIds:[t],currencies:[a]});c(new n(e[t.toLowerCase()]?.[a]?.price||0))}catch(t){console.error(t),c(M)}}),[a]);return t.useEffect((()=>{if(!s||!e)return;const t=s[e];if(t&&G(t))u(t.coingeckoId);else{const t=r?.[e];u(t?.coingeckoId||e)}}),[e,s,u,r]),i}function Mt(e,a,r,o){return t.useCallback((async(t,c)=>{if(!t||!c||!o)return;const u=c===i.AVALANCHE?e:a;await u.waitForTransaction(t);const d=await u.getTransactionReceipt(t);let p="";const l=d?.to?.toUpperCase();for(const t in o){const e=o[t];if(W(e)&&(e.nativeContractAddress.toUpperCase()===l||e.wrappedContractAddress.toUpperCase()===l)){p=t;break}}const m=s.AbiCoder.defaultAbiCoder().decode(["uint256"],d?.logs?.[0]?.data??"");let f;if(p&&m[0]){const t=o[p];f=new n(m[0].toString()).div(S.pow(t.denomination))}r({tokenSymbol:p,amount:f||M})}),[r,o])}function Ft(e,n,a,r,o,c){const[u,d]=t.useState();return t.useEffect((()=>{if(c&&o)return e===i.AVALANCHE?function(){if(!c||!o)return;const t=new s.Contract(o.wrappedContractAddress,q,n),e=t.filters.Transfer(null,c);function a(n,s,r,o){"0x0000000000000000000000000000000000000000"===n&&(t.off(e,a),o.getTransaction().then((t=>d(t))).catch((t=>console.error(t))))}return t.on(e,a),()=>{t.off(e,a)}}():function(){if(!c||!r)return;const t=r.critical.walletAddresses.ethereum;let e;return a.getBlockNumber().then((n=>{e=window.setInterval((async()=>{const a=`https://api${4===r?.critical.networks.ethereum?"-rinkeby":""}.etherscan.io/api?module=account&action=tokentx&address=${c}&startblock=${n}&endblock=99999999&sort=asc&apikey=${p}`;try{const n=await fetch(a),s=(await n.json()).result.find((e=>e.from.toLowerCase()===t));s&&(window.clearInterval(e),d(s))}catch(t){console.error(t)}}),2e3)})).catch((t=>console.error(t))),()=>{window.clearInterval(e)}}()}),[o,e,c,r]),u}function Ht(){const[e,n]=t.useState(Date.now()),[a,s]=t.useState(0),[r,o]=t.useState(!1);t.useEffect((()=>{let t;return r?t=window.setInterval((()=>{s(Math.floor((Date.now()-e)/1e3))}),1e3):r||0===a||window.clearInterval(t),()=>{window.clearInterval(t)}}),[r,e,a]);const i=t.useCallback(((t,e)=>{n(t);const a=e??Date.now();s(Math.floor((a-t)/1e3))}),[]),c=t.useCallback((()=>{r||(o(!0),n(Date.now()))}),[r]),u=t.useCallback((()=>{o(!1)}),[]);return t.useMemo((()=>({isActive:r,seconds:a,start:c,stop:u,setTimerSeconds:i,started:e})),[r,a,i,e,c,u])}function Rt(e,a,r){const[o,i]=t.useState(0),[c,u]=t.useState();return t.useEffect((()=>{if(r)return a.on("block",t),a.waitForTransaction(r,e).then((async e=>{e&&i(await e.confirmations()),a.removeListener("block",t)})).catch((t=>console.error(t))),()=>{a.removeListener("block",t)};async function t(){if(r)try{const t=await a.getTransaction(r);if(!t||!t.gasPrice)return;if(i(await t.confirmations()),!c){const e=await a.getTransactionReceipt(r);if(!e)return;u(new n(s.formatUnits(t.gasPrice*e.gasUsed,18)))}}catch(t){console.error(t)}}}),[r,a,e,c]),{confirmations:o,gasCost:c}}exports.AVERAGE_TRANSFER_TX_GAS_USAGE=40000n,exports.AssetType=d,exports.BIG_TEN=S,exports.BIG_ZERO=M,exports.Blockchain=i,exports.BridgeSDKProvider=function({children:e}){const[n,a]=t.useState(),[s,r]=t.useState({}),o=t.useCallback((t=>{if(_(s,t)&&t.config){const{critical:e,criticalBitcoin:n}=t.config;a({critical:e,criticalBitcoin:n})}r(t)}),[s]),[c,u]=t.useState(),[p,l]=t.useState(i.ETHEREUM),[m,f]=t.useState(i.AVALANCHE),[y,w]=t.useState(),b=t.useMemo((()=>n?nt(i.ETHEREUM,n):{}),[n]),g=t.useMemo((()=>{const t={};for(const e in b){const n=b[e];n.assetType===d.ERC20&&(t[e]=n)}return t}),[b]),h=t.useMemo((()=>n?nt(i.BITCOIN,n):{}),[n]),T=t.useMemo((()=>n?nt(i.AVALANCHE,n):{}),[n]),A=t.useMemo((()=>{if(c)return b[c]||h[c]||T[c]}),[T,h,c,b]),C=t.useMemo((()=>p===i.AVALANCHE?T:p===i.BITCOIN?h:b),[T,h,p,b]);t.useEffect((()=>{const t=Object.keys(C);c&&t.includes(c)||u(1===t.length?t[0]:void 0)}),[c,C]);const v=t.useMemo((()=>{if(p===i.AVALANCHE){if(A?.assetType===d.ERC20)return[i.ETHEREUM];if(A?.assetType===d.BTC)return[i.BITCOIN]}else if(p===i.ETHEREUM||p===i.BITCOIN)return[i.AVALANCHE];return[]}),[p,A]);t.useEffect((()=>{v.includes(m)||f(v[0])}),[p,m,v]),t.useEffect((()=>{p===i.BITCOIN||p===i.ETHEREUM?f(i.AVALANCHE):p===i.AVALANCHE&&(A?.assetType===d.ERC20?f(i.ETHEREUM):A?.assetType===d.BTC&&f(i.BITCOIN))}),[p,A]);const N={sourceAssets:C,ethereumAssets:b,bitcoinAssets:h,ethereumWrappedAssets:g,avalancheAssets:T,bridgeConfig:s,setBridgeConfig:o,criticalConfig:n,currentAsset:c,currentAssetData:A,setCurrentAsset:u,currentBlockchain:p,setCurrentBlockchain:l,targetBlockchain:m,transactionDetails:y,setTransactionDetails:w,targetChains:v};return t.createElement(st.Provider,{value:N},t.createElement(E,null,e))},exports.ETHERSCAN_API_KEY=p,exports.Environment=u,exports.INFURA_API_KEY=l,exports.NetworkType=c,exports.TokenInfoProvider=E,exports.WrapStatus=bt,exports.btcToSatoshi=x,exports.capped=F,exports.checkHistoryForNewTxEVM=dt,exports.estimateGas=async function(t,e,n,s,r,o,c=!1){if(W(n)||j(n)){if(o===i.AVALANCHE){const r=X(n.wrappedContractAddress,q,s.avalanche,e,c),o=await r.unwrap.populateTransaction(a.bigToBigInt(t,n.denomination),0);return s.avalanche.estimateGas({...o,from:e})}if(W(n)){const r=X(n.nativeContractAddress,z,s.ethereum,e,c),o=await r.transfer.populateTransaction(e,a.bigToBigInt(t,n.denomination));return s.ethereum.estimateGas({...o,from:e})}}else if(G(n)){const o=r.critical.assets[n.wrappedAssetSymbol];if(!o)throw new Error("Cannot estimate gas: missing wrappedAsset");let u=0n;if(n.nativeNetwork===i.ETHEREUM){const r=X(o.nativeContractAddress,$,s.ethereum,e,c),i=await r.deposit.populateTransaction({value:a.bigToBigInt(t,n.denomination)});u+=await s.ethereum.estimateGas({...i,from:e})}const d=X(o.nativeContractAddress,z,s.ethereum,e,c),p=await d.transfer.populateTransaction(e,a.bigToBigInt(t,n.denomination));try{u+=await s.ethereum.estimateGas({...p,from:e})}catch{u+=40000n}return u}},exports.fetchConfig=async function(t){const[e,n]=await a.resolve(async function(t){const e=f(t),n=[];for(const t of e.wardenConfigURLs)n.push(fetch(t));const a=await Promise.allSettled(n),s=[];for(const t of a)if("rejected"!==t.status&&t.value&&t.value.ok)try{s.push(await t.value.json())}catch(t){console.error(t)}const r=s.reduce(((t,e)=>{if(e.critical.disableFrontend||e.criticalBitcoin?.disableFrontend)throw new Error("Disable frontend");const n=JSON.stringify([e.critical,e.criticalBitcoin]),a=t.findIndex((t=>t.criticalJsonString===n));return a<0?t.push({appConfig:e,count:1,criticalJsonString:n}):t[a].count++,t}),[]),o=r.reduce(((t,e)=>t.count>=e.count?t:e),r[0]);if(!o||o.count<e.wardenConfigURLs.length-e.configMismatchThreshold)throw new Error("Warden config mismatch");const c=o.appConfig;for(const t in c.critical.assets)c.critical.assets[t].assetType=d.ERC20,c.critical.assets[t].symbol=t;if(c.criticalBitcoin)for(const t in c.criticalBitcoin.bitcoinAssets)c.criticalBitcoin.bitcoinAssets[t].assetType=d.BTC,c.criticalBitcoin.bitcoinAssets[t].symbol=t.toUpperCase(),c.criticalBitcoin.bitcoinAssets[t].denomination=8,c.criticalBitcoin.bitcoinAssets[t].nativeNetwork=i.BITCOIN;return c}(t));return e?{config:e}:{error:n}},exports.fetchTokenBalances=pt,exports.formatTokenAmount=function(t,e=2){return new Intl.NumberFormat("en-US",{minimumFractionDigits:2,maximumFractionDigits:e}).format(t.toNumber())},exports.getAssets=nt,exports.getBridgeFeeEstimateBTC=Y,exports.getBridgeFeeEstimateEVM=it,exports.getBtcAsset=Q,exports.getBtcTransaction=function(t,n,a,s,o){const c=O(t);if(!I(n,c))throw new Error("Address must be bech32");if(s%1!=0)throw new Error(`Amount must be a whole number. Satoshis can not be divided. ${s}`);const u=tt(i.BITCOIN,t,s);if(s<u)throw new Error(`Amount must be at least ${u} satoshis.`);const d=t.criticalBitcoin?.walletAddresses.btc||"";if(!d)throw new Error("Bridge address is not found in the config.");if(!o)throw new Error("Fee rate is not provided in the config.");const p=c?e.networks.bitcoin:e.networks.testnet,{inputs:l,outputs:m,psbt:f,fee:y}=r.createTransferTx(d,n,s,o,a,p);if(!l||!m||!f)throw new Error("Transaction values can not be satisfied.");const w=x(Y({source:i.BITCOIN,config:t,amount:B(s)}));return{fee:y,tx:f,bridgeFee:w,receiveAmount:s-w,inputs:l,outputs:m}},exports.getBtcTransactionDetails=function(t,e,n,a,s){if(!I(e,O(t)))throw new Error("Address must be bech32");if(a%1!=0)throw new Error(`Amount must be a whole number. Satoshis can not be divided. ${a}`);const o=tt(i.BITCOIN,t,a);if(a<o)throw new Error(`Amount must be at least ${o} satoshis.`);const c=t.criticalBitcoin?.walletAddresses.btc||"";if(!c)throw new Error("Bridge address is not found in the config.");if(!s)throw new Error("Fee rate is not provided in the config.");const{inputs:u,outputs:d,fee:p}=r.getTransferTxDetails(c,e,a,s,n);if(!u||!d)throw new Error("Transaction values can not be satisfied.");const l=x(Y({source:i.BITCOIN,config:t,amount:B(a)}));return{fee:p,bridgeFee:l,receiveAmount:a-l,inputs:u,outputs:d}},exports.getMaxTransferAmount=wt,exports.getMinimumConfirmations=function(t,e){return t===i.BITCOIN?e.nonCriticalBitcoin?.networkInfo.btc.minimumConfirmations||0:e.nonCritical.minimumConfirmations[t]||0},exports.getMinimumTransferAmount=tt,exports.getNativeSymbol=function(t){switch(t){case i.AVALANCHE:return"AVAX";case i.BITCOIN:return"BTC";case i.ETHEREUM:return"ETH";default:return"???"}},exports.getRuntimeConfig=f,exports.getStaticBridgeFeeEstimateBTC=Z,exports.getStaticBridgeFeeEstimateEVM=ct,exports.getTxConfirmations=async function(t,e){return(await et(t,e)).confirmations},exports.getTxDetails=et,exports.hasCriticalChanges=_,exports.initalState=T,exports.isAddressBlocklisted=D,exports.isBase58Address=k,exports.isBase58AddressInNetwork=function(t,n){if(!k(t))return!1;const a=n?e.networks.bitcoin:e.networks.testnet;try{return e.address.toOutputScript(t,a),!0}catch(t){return!1}},exports.isBech32Address=N,exports.isBech32AddressInNetwork=I,exports.isBtcAsset=j,exports.isBtcUsingDynamicFees=P,exports.isEthAsset=W,exports.isEthUsingDynamicFees=V,exports.isMainnetConfig=O,exports.isNativeAsset=G,exports.satoshiToBtc=B,exports.setBridgeEnvironment=function(t){m=h[t]},exports.trackBridgeTransaction=function(t){return new At(t)},exports.transferAssetBTC=kt,exports.transferAssetEVM=It,exports.unwrapAsset=Ct,exports.usdFormatter=L,exports.useBridgeConfig=ot,exports.useBridgeConfigUpdater=function(e){const{bridgeConfig:n,setBridgeConfig:a}=rt();t.useEffect((()=>{async function t(){const t=await e();a(t)}n.config||n.error||t();const s=window.setInterval((()=>{t()}),15e3);return()=>{window.clearInterval(s)}}),[e,n])},exports.useBridgeFeeEstimate=function(e){const{currentAssetData:n,currentBlockchain:a,bridgeConfig:s,ethereumAssets:r,ethereumWrappedAssets:o}=rt();return t.useMemo((()=>{if(!r||!n||!s.config)return;const t=j(n)&&(a===i.AVALANCHE||a===i.BITCOIN),c=!j(n)&&(a===i.AVALANCHE||a===i.ETHEREUM);if(t)return Y({source:a,config:s.config,amount:e});if(c){const t=G(n)?o[n.wrappedAssetSymbol]:n;return it({source:a,config:s.config,asset:t,amount:e})}}),[r,n,s.config,a,e,o])},exports.useBridgeSDK=rt,exports.useCheckHistoryForNewTxEVM=xt,exports.useGetAirdropAmount=function(e,a,s,r){return t.useCallback((()=>r?.avaxPromotionAmount&&r.avaxPromotionDollarThreshold&&e===i.AVALANCHE&&s?.amount?s.amount.times(a).lt(new n(r.avaxPromotionDollarThreshold))?0:new n(r.avaxPromotionAmount).div(S.pow(18)).toNumber():0),[r,a,e,s])},exports.useGetTokenBalanceEVM=function(e,n,a,s,r,o){const{ethereumAssets:i}=rt();if(n&&G(n)&&n.nativeNetwork!==e){const t=i[n.wrappedAssetSymbol];t&&t.assetType===d.ERC20&&(n=t)}const c=Bt(e,t.useMemo((()=>n?{[n.symbol]:n}:void 0),[n]),a,s,r,o);return n&&c?c[n.symbol]:void 0},exports.useGetTokenBalancesEVM=Bt,exports.useGetTokenSymbolOnNetwork=function(){const{sourceAssets:e}=rt();return{getTokenSymbolOnNetwork:t.useCallback(((t,n)=>{const a=e[t];let s=t;return a&&n!==a.nativeNetwork?(G(a)&&(s=a.wrappedAssetSymbol),a.nativeNetwork===i.ETHEREUM?`${s}.e`:a.nativeNetwork===i.AVALANCHE?`${s}.a`:a.nativeNetwork===i.BITCOIN?`${s}.b`:s):s}),[e])}},exports.useHasEnoughForGas=function(e,a){const[s,r]=t.useState(!0);return t.useEffect((()=>{!async function(){if(!e||!a)return;const t=await a.getBalance(e),s=await a.getFeeData();r(new n(t.toString()).gte(s?.gasPrice?.toString()||"0"))}()}),[e,a]),s},exports.useIsAddressSanctioned=function(t){const e=ot();return D({addressEVM:t,addressBTC:t,bridgeConfig:e})},exports.useMaxTransferAmount=function(e,n,a){const{currentAsset:s,currentBlockchain:r,ethereumAssets:o,avalancheAssets:c,bridgeConfig:{config:u}}=rt(),d=r===i.AVALANCHE?c:o,p=d[s||""],l=yt(r),[m,f]=t.useState(null);return t.useEffect((()=>{s&&e&&a&&u?wt({currentAsset:s,currentBlockchain:r,assets:d,balance:e,provider:a,config:u}).then((t=>{f(t)})).catch((t=>console.error(t))):f(null)}),[n,p,d,e,u,s,l,a,r]),m},exports.useMinimumTransferAmount=function(e){const{currentAssetData:a,currentBlockchain:s,bridgeConfig:r,ethereumAssets:o,ethereumWrappedAssets:c}=rt();return t.useMemo((()=>{if(!o||!a||!r.config)return M;const t=j(a)&&(s===i.AVALANCHE||s===i.BITCOIN),u=!j(a)&&(s===i.AVALANCHE||s===i.ETHEREUM);if(t)return B(tt(s,r.config,x(e)));if(u){const t=G(a)?c[a.wrappedAssetSymbol]:a;return function(t,e,a){if(V(e)){const s=t===i.ETHEREUM?"wrapFeeApproximation":"unwrapFeeApproximation",{minimumFeeAmount:r}=e.nonCritical[s][a.symbol];return new n(r).div(S.pow(a.denomination)).mul(R)}return it({source:t,config:e,asset:a,amount:M}).mul(R)}(s,r.config,t)}return M}),[o,a,r.config,s,e,c])},exports.usePrice=St,exports.usePriceForChain=function(t){return St(t===i.AVALANCHE?"avalanche-2":t)},exports.useResetTransactionDetailsFromParams=Mt,exports.useSubscribeForNewTransactionFromBridgeEVM=Ft,exports.useTimer=Ht,exports.useTokenInfoContext=C,exports.useTransferAssetBTC=function(e){const{currentBlockchain:n}=rt(),{config:a}=ot(),[s,r]=t.useState(bt.INITIAL),[o,c]=t.useState("");return{transferAsset:t.useCallback((function(t,s){if(a&&n===i.BITCOIN)return kt({amount:t,feeRate:s,config:a,onStatusChange:r,onTxHashChange:c,signAndSendBTC:e})}),[a,n,e]),status:s,txHash:o}},exports.useTransferAssetEVM=function(e,n,a,s,r){const{currentBlockchain:o}=rt(),{config:c}=ot(),[u,d]=t.useState(bt.INITIAL),[p,l]=t.useState("");return{transferAsset:t.useCallback((function(t){if(e&&n&&c&&(o===i.AVALANCHE||o===i.ETHEREUM))return It({currentBlockchain:o,amount:t,account:n,asset:e,avalancheProvider:a,ethereumProvider:s,config:c,onStatusChange:d,onTxHashChange:l,signAndSendEVM:r})}),[n,e,a,c,o,s,r]),status:u,txHash:p}},exports.useTxTracker=function(e,n,a,s,r,o,c,u,d,p,l){const[m,f]=t.useState(!1),[y,w]=t.useState(!1),[b,g]=t.useState(),h=p?.[d?.tokenSymbol||""],[T,A]=t.useState(!1),E=Ht(),C=Ht(),v=e===i.AVALANCHE?s:r,N=e===i.ETHEREUM?i.AVALANCHE:i.ETHEREUM,I=e===i.AVALANCHE?r:s,k=c?.nonCritical.minimumConfirmations[e]||1e3,x=Ft(N,s,r,c,h,u),{confirmations:B,gasCost:S}=Rt(k,v,n),M=Mt(s,r,o,p),F=St(e),{checkHistoryForNewTx:H}=xt(N,I,u,h),R=t.useCallback((t=>{C.stop(),g(t),A(!0)}),[C]);t.useEffect((()=>{E.start(),E.setTimerSeconds(parseInt(a))}),[]),t.useEffect((()=>{!async function(){if(!l&&m&&C.seconds>0){f(!1);const t=await H();t&&(t.block&&C.setTimerSeconds(Math.floor((1e3*t.block.timestamp-C.started)/1e3)),t.transaction&&R(t.transaction.hash))}else l&&f(!0)}()}),[H,R,m,C,l]),t.useEffect((()=>{d||(M(n,e),w(!0))}),[M,e,d,n]),t.useEffect((()=>{if(n&&B>=k){if(d?.tokenSymbol&&B>k&&y)return void R();E.isActive&&(E.stop(),C.start())}}),[B,R,y,k,E,C,d?.tokenSymbol,n]),t.useEffect((()=>{d&&x&&B>=k&&R(x.hash)}),[B,R,k,x,d]);const O=F&&S&&F.mul(S);return{sourceNetwork:e,sourceSeconds:E.seconds,sourceTxHash:n,targetNetwork:N,targetSeconds:C.seconds,targetTxHash:b,requiredConfirmationCount:k,confirmationCount:B,complete:T,gasCost:S,gasValue:O,amount:d?.amount,symbol:d?.tokenSymbol}},exports.useWaitForConfirmations=Rt,exports.wrapAsset=Nt;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"owner",type:"address"},{indexed:!0,name:"spender",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"from",type:"address"},{indexed:!0,name:"to",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Transfer",type:"event"}];export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"src",type:"address"},{indexed:!0,internalType:"address",name:"guy",type:"address"},{indexed:!1,internalType:"uint256",name:"wad",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"dst",type:"address"},{indexed:!1,internalType:"uint256",name:"wad",type:"uint256"}],name:"Deposit",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"src",type:"address"},{indexed:!0,internalType:"address",name:"dst",type:"address"},{indexed:!1,internalType:"uint256",name:"wad",type:"uint256"}],name:"Transfer",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"src",type:"address"},{indexed:!1,internalType:"uint256",name:"wad",type:"uint256"}],name:"Withdrawal",type:"event"},{payable:!0,stateMutability:"payable",type:"fallback"},{constant:!0,inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"guy",type:"address"},{internalType:"uint256",name:"wad",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{internalType:"address",name:"",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[],name:"deposit",outputs:[],payable:!0,stateMutability:"payable",type:"function"},{constant:!0,inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"dst",type:"address"},{internalType:"uint256",name:"wad",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"src",type:"address"},{internalType:"address",name:"dst",type:"address"},{internalType:"uint256",name:"wad",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{internalType:"uint256",name:"wad",type:"uint256"}],name:"withdraw",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"chain_id",type:"uint256"}],name:"unwrap",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"swap",outputs:[{internalType:"bool",name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{internalType:"address",name:"",type:"address"}],name:"swapSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"}];export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"guy",type:"address"},{name:"wad",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"src",type:"address"},{name:"dst",type:"address"},{name:"wad",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[{name:"wad",type:"uint256"}],name:"withdraw",outputs:[],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"balanceOf",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"dst",type:"address"},{name:"wad",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!1,inputs:[],name:"deposit",outputs:[],payable:!0,stateMutability:"payable",type:"function"},{constant:!0,inputs:[{name:"",type:"address"},{name:"",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"src",type:"address"},{indexed:!0,name:"guy",type:"address"},{indexed:!1,name:"wad",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"src",type:"address"},{indexed:!0,name:"dst",type:"address"},{indexed:!1,name:"wad",type:"uint256"}],name:"Transfer",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"dst",type:"address"},{indexed:!1,name:"wad",type:"uint256"}],name:"Deposit",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"src",type:"address"},{indexed:!1,name:"wad",type:"uint256"}],name:"Withdrawal",type:"event"}];export{t as default};
|
package/esm/constants.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var T=(T=>(T[T.MAINNET=43114]="MAINNET",T[T.TESTNET=43113]="TESTNET",T))(T||{});const E=3;export{T as AvalancheNetworkIds,E as FEE_ESTIMATION_MULTIPLIER};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t,{createContext as e,useContext as s,useState as r,useCallback as i,useMemo as n,useEffect as c}from"react";import{Blockchain as o,AssetType as a}from"../types/config.js";import{TokenInfoProvider as A}from"./TokenInfoProvider.js";import{getAssets as E}from"../lib/getAssets.js";import"../utils/bignumber.js";import{hasCriticalChanges as l}from"../utils/config.js";import"@avalabs/core-utils-sdk";import"ethers";const u=e({});function C(){return s(u)}function f({children:e}){const[s,C]=r(),[f,T]=r({}),m=i((t=>{if(l(f,t)&&t.config){const{critical:e,criticalBitcoin:s}=t.config;C({critical:e,criticalBitcoin:s})}T(t)}),[f]),[p,g]=r(),[B,H]=r(o.ETHEREUM),[I,N]=r(o.AVALANCHE),[d,h]=r(),R=n((()=>s?E(o.ETHEREUM,s):{}),[s]),b=n((()=>{const t={};for(const e in R){const s=R[e];s.assetType===a.ERC20&&(t[e]=s)}return t}),[R]),y=n((()=>s?E(o.BITCOIN,s):{}),[s]),L=n((()=>s?E(o.AVALANCHE,s):{}),[s]),O=n((()=>{if(p)return R[p]||y[p]||L[p]}),[L,y,p,R]),V=n((()=>B===o.AVALANCHE?L:B===o.BITCOIN?y:R),[L,y,B,R]);c((()=>{const t=Object.keys(V);p&&t.includes(p)||g(1===t.length?t[0]:void 0)}),[p,V]);const j=n((()=>{if(B===o.AVALANCHE){if(O?.assetType===a.ERC20)return[o.ETHEREUM];if(O?.assetType===a.BTC)return[o.BITCOIN]}else if(B===o.ETHEREUM||B===o.BITCOIN)return[o.AVALANCHE];return[]}),[B,O]);c((()=>{j.includes(I)||N(j[0])}),[B,I,j]),c((()=>{B===o.BITCOIN||B===o.ETHEREUM?N(o.AVALANCHE):B===o.AVALANCHE&&(O?.assetType===a.ERC20?N(o.ETHEREUM):O?.assetType===a.BTC&&N(o.BITCOIN))}),[B,O]);const k={sourceAssets:V,ethereumAssets:R,bitcoinAssets:y,ethereumWrappedAssets:b,avalancheAssets:L,bridgeConfig:f,setBridgeConfig:m,criticalConfig:s,currentAsset:p,currentAssetData:O,setCurrentAsset:g,currentBlockchain:B,setCurrentBlockchain:H,targetBlockchain:I,transactionDetails:d,setTransactionDetails:h,targetChains:j};return t.createElement(u.Provider,{value:k},t.createElement(A,null,e))}export{f as BridgeSDKProvider,C as useBridgeSDK};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TokenInfoData } from '../types/tokenInfo.js';
|
|
2
|
+
|
|
3
|
+
declare const initalState: {};
|
|
4
|
+
declare const TokenInfoProvider: ({ children }: {
|
|
5
|
+
children: any;
|
|
6
|
+
}) => JSX.Element;
|
|
7
|
+
declare function useTokenInfoContext(): TokenInfoData | undefined;
|
|
8
|
+
|
|
9
|
+
export { TokenInfoProvider, initalState, useTokenInfoContext };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t,{createContext as n,useState as o,useEffect as r,useContext as e}from"react";import{loadTokenInfo as c}from"../utils/loadTokenInfo.js";const i={},a=n(i),s=({children:n})=>{const[e,i]=o();return r((()=>{!async function(){const t=await c();i(t)}()}),[]),t.createElement(a.Provider,{value:e},n)};function u(){return e(a)}export{s as TokenInfoProvider,i as initalState,u as useTokenInfoContext};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TransactionDetails } from '../lib/models.js';
|
|
2
|
+
import { NativeAsset, EthereumConfigAsset, BitcoinConfigAsset, EthereumConfigAssets, Assets, BitcoinConfigAssets, BridgeConfig, CriticalConfig, Blockchain, Asset } from '../types/config.js';
|
|
3
|
+
|
|
4
|
+
type EthereumAssets = Record<string, NativeAsset | EthereumConfigAsset>;
|
|
5
|
+
type AvalancheAssets = Record<string, BitcoinConfigAsset | EthereumConfigAsset>;
|
|
6
|
+
interface BridgeSDKState {
|
|
7
|
+
ethereumAssets: EthereumAssets;
|
|
8
|
+
ethereumWrappedAssets: EthereumConfigAssets;
|
|
9
|
+
avalancheAssets: AvalancheAssets;
|
|
10
|
+
sourceAssets: Assets;
|
|
11
|
+
bitcoinAssets: BitcoinConfigAssets;
|
|
12
|
+
bridgeConfig: BridgeConfig;
|
|
13
|
+
setBridgeConfig: (bridgeConfig: BridgeConfig) => void;
|
|
14
|
+
criticalConfig?: CriticalConfig;
|
|
15
|
+
currentBlockchain: Blockchain;
|
|
16
|
+
setCurrentBlockchain: (blockchain: Blockchain) => void;
|
|
17
|
+
targetBlockchain: Blockchain;
|
|
18
|
+
currentAsset?: string;
|
|
19
|
+
currentAssetData?: Asset;
|
|
20
|
+
setCurrentAsset: (symbol: string) => void;
|
|
21
|
+
transactionDetails?: TransactionDetails;
|
|
22
|
+
setTransactionDetails: (transactionDetails: TransactionDetails) => void;
|
|
23
|
+
targetChains: Blockchain[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { AvalancheAssets, BridgeSDKState, EthereumAssets };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BridgeConfig } from '../types/config.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get the bridge config from the bridge context. Use
|
|
5
|
+
* useBridgeConfigUpdater() to ensure that the bridge config is
|
|
6
|
+
* periodically re-fetch.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const { config, error } = useBridgeConfig();
|
|
10
|
+
*/
|
|
11
|
+
declare function useBridgeConfig(): BridgeConfig;
|
|
12
|
+
|
|
13
|
+
export { useBridgeConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useBridgeSDK as r}from"../contexts/BridgeSDKProvider.js";function o(){const{bridgeConfig:o}=r();return o}export{o as useBridgeConfig};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BridgeConfig } from '../types/config.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Use to periodically re-fetch the bridge config. This is needed in case any of
|
|
5
|
+
* the wardens returns disableFrontend === true which should shutdown the
|
|
6
|
+
* frontend immediately.
|
|
7
|
+
*
|
|
8
|
+
* @param fetchFn use fetchConfig() by default, this param is provided so it can
|
|
9
|
+
* be customized in the extension.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* useBridgeConfigUpdater(() => fetchConfig("main"));
|
|
13
|
+
*/
|
|
14
|
+
declare function useBridgeConfigUpdater(fetchFn: () => Promise<BridgeConfig>): void;
|
|
15
|
+
|
|
16
|
+
export { useBridgeConfigUpdater };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as r}from"react";import{useBridgeSDK as o}from"../contexts/BridgeSDKProvider.js";function n(n){const{bridgeConfig:t,setBridgeConfig:e}=o();r((()=>{async function r(){const r=await n();e(r)}t.config||t.error||r();const o=window.setInterval((()=>{r()}),15e3);return()=>{window.clearInterval(o)}}),[n,t])}export{n as useBridgeConfigUpdater};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useMemo as t}from"react";import{useBridgeSDK as r}from"../contexts/BridgeSDKProvider.js";import{Blockchain as e}from"../types/config.js";import"bitcoinjs-lib";import{getBridgeFeeEstimateBTC as i}from"../lib/btc/getBridgeFeeEstimateBTC.js";import"big.js";import"../utils/bignumber.js";import{isBtcAsset as s,isNativeAsset as o}from"../utils/asset.js";import"@avalabs/core-utils-sdk";import"ethers";import"@avalabs/core-wallets-sdk";import{getBridgeFeeEstimateEVM as m}from"../lib/getBridgeFeeEstimateEVM.js";import"../runtime/config.js";import"../runtime/nativeAssets.js";import"../lib/hasAddressVulnerableMultichainApproval.js";function n(n){const{currentAssetData:c,currentBlockchain:a,bridgeConfig:p,ethereumAssets:u,ethereumWrappedAssets:f}=r();return t((()=>{if(!u||!c||!p.config)return;const t=s(c)&&(a===e.AVALANCHE||a===e.BITCOIN),r=!s(c)&&(a===e.AVALANCHE||a===e.ETHEREUM);if(t)return i({source:a,config:p.config,amount:n});if(r){const t=o(c)?f[c.wrappedAssetSymbol]:c;return m({source:a,config:p.config,asset:t,amount:n})}}),[u,c,p.config,a,n,f])}export{n as useBridgeFeeEstimate};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Blockchain, EthereumConfigAsset } from '../types/config.js';
|
|
2
|
+
import { HistoryTxData } from '../lib/checkHistoryForNewTxEVM.js';
|
|
3
|
+
import { Provider } from 'ethers';
|
|
4
|
+
import { Maybe } from '@avalabs/core-utils-sdk';
|
|
5
|
+
|
|
6
|
+
declare function useCheckHistoryForNewTxEVM(network: Blockchain, provider: Provider, account: Maybe<string>, asset: Maybe<EthereumConfigAsset>): {
|
|
7
|
+
checkHistoryForNewTx: () => Promise<HistoryTxData | undefined>;
|
|
8
|
+
startBlockNumber: number | undefined;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { useCheckHistoryForNewTxEVM };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as r,useEffect as o,useCallback as t}from"react";import"bitcoinjs-lib";import"big.js";import"../utils/bignumber.js";import"@avalabs/core-utils-sdk";import"ethers";import"@avalabs/core-wallets-sdk";import{checkHistoryForNewTxEVM as i}from"../lib/checkHistoryForNewTxEVM.js";import"../runtime/config.js";import"../runtime/nativeAssets.js";import"../lib/hasAddressVulnerableMultichainApproval.js";import{useBridgeConfig as s}from"./useBridgeConfig.js";function e(e,m,c,n){const[a,l]=r(),{config:p}=s();o((()=>{m.getBlockNumber().then((r=>{l(r)})).catch((r=>console.error(r)))}),[m]);return{checkHistoryForNewTx:t((async()=>i(e,m,p,c,n,a)),[e,m,p,c,n,a]),startBlockNumber:a}}export{e as useCheckHistoryForNewTxEVM};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TransactionDetails } from '../lib/models.js';
|
|
2
|
+
import { Blockchain, EthereumConfigAsset, BitcoinConfigAsset } from '../types/config.js';
|
|
3
|
+
import Big from 'big.js';
|
|
4
|
+
import { Maybe } from '@avalabs/core-utils-sdk';
|
|
5
|
+
|
|
6
|
+
declare function useGetAirdropAmount(sourceNetwork: Blockchain, assetPrice: Big, transactionDetails: Maybe<TransactionDetails>, assetInfo: Maybe<EthereumConfigAsset | BitcoinConfigAsset>): () => number;
|
|
7
|
+
|
|
8
|
+
export { useGetAirdropAmount };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useCallback as o}from"react";import{Blockchain as r}from"../types/config.js";import t from"big.js";import{BIG_TEN as m}from"../utils/bignumber.js";function i(i,n,a,e){return o((()=>e?.avaxPromotionAmount&&e.avaxPromotionDollarThreshold&&i===r.AVALANCHE&&a?.amount?a.amount.times(n).lt(new t(e.avaxPromotionDollarThreshold))?0:new t(e.avaxPromotionAmount).div(m.pow(18)).toNumber():0),[e,n,i,a])}export{i as useGetAirdropAmount};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Maybe } from '@avalabs/core-utils-sdk';
|
|
2
|
+
import Big from 'big.js';
|
|
3
|
+
import { Blockchain, Asset } from '../types/config.js';
|
|
4
|
+
import { Provider } from 'ethers';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fetch the account balance for the token on Ethereum or Avalanche.
|
|
8
|
+
* @param blockchain network to get the balances on
|
|
9
|
+
* @param asset the contract token (skips fetch when not defined)
|
|
10
|
+
* @param deprecated query the deprecated token balance instead of the regular
|
|
11
|
+
*/
|
|
12
|
+
declare function useGetTokenBalanceEVM(blockchain: Blockchain.AVALANCHE | Blockchain.ETHEREUM, asset: Maybe<Asset>, provider: Provider, active: boolean, account: Maybe<string>, deprecated?: boolean): Big | undefined;
|
|
13
|
+
|
|
14
|
+
export { useGetTokenBalanceEVM };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useMemo as o}from"react";import{AssetType as t}from"../types/config.js";import{useGetTokenBalancesEVM as s}from"./useGetTokenBalancesEVM.js";import{useBridgeSDK as e}from"../contexts/BridgeSDKProvider.js";import"../contexts/TokenInfoProvider.js";import"../utils/bignumber.js";import{isNativeAsset as r}from"../utils/asset.js";import"@avalabs/core-utils-sdk";import"ethers";function i(i,m,n,p,a,c){const{ethereumAssets:f}=e();if(m&&r(m)&&m.nativeNetwork!==i){const o=f[m.wrappedAssetSymbol];o&&o.assetType===t.ERC20&&(m=o)}const l=o((()=>m?{[m.symbol]:m}:void 0),[m]),u=s(i,l,n,p,a,c);return m&&u?u[m.symbol]:void 0}export{i as useGetTokenBalanceEVM};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { Blockchain, Asset } from '../types/config.js';
|
|
3
|
+
import { Maybe } from '@avalabs/core-utils-sdk';
|
|
4
|
+
import { Provider } from 'ethers';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Fetch the account balances for the tokens.
|
|
8
|
+
* @param blockchain network to get the balances on
|
|
9
|
+
* @param tokens the list of contract tokens
|
|
10
|
+
* @param deprected query the deprecated token balance instead of the regular
|
|
11
|
+
*/
|
|
12
|
+
declare function useGetTokenBalancesEVM(blockchain: Blockchain, tokens: Maybe<Record<string, Asset>>, provider: Provider, active: boolean, account: Maybe<string>, deprecated?: boolean): {
|
|
13
|
+
[key: string]: Big;
|
|
14
|
+
} | undefined;
|
|
15
|
+
|
|
16
|
+
export { useGetTokenBalancesEVM };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as t,useEffect as n}from"react";import{fetchTokenBalances as o}from"../lib/fetchTokenBalances.js";function r(r,c,e,i,a,f){const[s,m]=t();return n((()=>{!async function(){if(!c)return;const t=a&&i?await o(c,r,e,a,f):{};m(t)}()}),[a,i,c,e,r,f]),s}export{r as useGetTokenBalancesEVM};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useCallback as t}from"react";import{useBridgeSDK as e}from"../contexts/BridgeSDKProvider.js";import{Blockchain as r}from"../types/config.js";import"../utils/bignumber.js";import{isNativeAsset as o}from"../utils/asset.js";import"@avalabs/core-utils-sdk";import"ethers";function s(){const{sourceAssets:s}=e();return{getTokenSymbolOnNetwork:t(((t,e)=>{const i=s[t];let n=t;return i&&e!==i.nativeNetwork?(o(i)&&(n=i.wrappedAssetSymbol),i.nativeNetwork===r.ETHEREUM?`${n}.e`:i.nativeNetwork===r.AVALANCHE?`${n}.a`:i.nativeNetwork===r.BITCOIN?`${n}.b`:n):n}),[s])}}export{s as useGetTokenSymbolOnNetwork};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"big.js";import{useState as n,useEffect as r}from"react";function e(e,a){const[i,o]=n(!0);return r((()=>{!async function(){if(!e||!a)return;const n=await a.getBalance(e),r=await a.getFeeData();o(new t(n.toString()).gte(r?.gasPrice?.toString()||"0"))}()}),[e,a]),i}export{e as useHasEnoughForGas};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isAddressBlocklisted as s}from"../utils/isAddressBlocklisted.js";import{useBridgeConfig as r}from"./useBridgeConfig.js";function i(i){const o=r();return s({addressEVM:i,addressBTC:i,bridgeConfig:o})}export{i as useIsAddressSanctioned};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Maybe } from '@avalabs/core-utils-sdk';
|
|
2
|
+
import Big from 'big.js';
|
|
3
|
+
import { JsonRpcProvider } from 'ethers';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Calculates the approximate maximum abount transfarable for a given asset.
|
|
7
|
+
* For ERC20s it's always the user's max balance
|
|
8
|
+
* For native assets, since gas price is payed with the native asset,
|
|
9
|
+
* it's balance minus approximate transaction fees
|
|
10
|
+
*/
|
|
11
|
+
declare function useMaxTransferAmount(balance: Maybe<Big>, account: Maybe<string>, provider: Maybe<JsonRpcProvider>): Big | null;
|
|
12
|
+
|
|
13
|
+
export { useMaxTransferAmount };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as r,useEffect as e}from"react";import{useBridgeSDK as t}from"../contexts/BridgeSDKProvider.js";import{getMaxTransferAmount as o}from"../lib/getMaxTransferAmount.js";import{getGasAsset as s}from"../utils/getGasAsset.js";import{Blockchain as n}from"../types/config.js";function c(c,i,a){const{currentAsset:m,currentBlockchain:f,ethereumAssets:l,avalancheAssets:u,bridgeConfig:{config:A}}=t(),g=f===n.AVALANCHE?u:l,p=g[m||""],h=s(f),[d,j]=r(null);return e((()=>{m&&c&&a&&A?o({currentAsset:m,currentBlockchain:f,assets:g,balance:c,provider:a,config:A}).then((r=>{j(r)})).catch((r=>console.error(r))):j(null)}),[i,p,g,c,A,m,h,a,f]),d}export{c as useMaxTransferAmount};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useMemo as r}from"react";import{useBridgeSDK as t}from"../contexts/BridgeSDKProvider.js";import{Blockchain as i}from"../types/config.js";import"bitcoinjs-lib";import"big.js";import{satoshiToBtc as s,btcToSatoshi as o}from"../lib/btc/utils.js";import{BIG_ZERO as e}from"../utils/bignumber.js";import{isBtcAsset as m,isNativeAsset as n}from"../utils/asset.js";import"@avalabs/core-utils-sdk";import"ethers";import{getMinimumTransferAmount as p}from"../lib/btc/getMinimumTransferAmount.js";import"@avalabs/core-wallets-sdk";import"../runtime/config.js";import"../runtime/nativeAssets.js";import"../lib/hasAddressVulnerableMultichainApproval.js";import{getMinimumTransferAmountEVM as u}from"../lib/getMinimumTransferAmountEVM.js";function c(c){const{currentAssetData:a,currentBlockchain:f,bridgeConfig:l,ethereumAssets:b,ethereumWrappedAssets:A}=t();return r((()=>{if(!b||!a||!l.config)return e;const r=m(a)&&(f===i.AVALANCHE||f===i.BITCOIN),t=!m(a)&&(f===i.AVALANCHE||f===i.ETHEREUM);if(r)return s(p(f,l.config,o(c)));if(t){const r=n(a)?A[a.wrappedAssetSymbol]:a;return u(f,l.config,r)}return e}),[b,a,l.config,f,c,A])}export{c as useMinimumTransferAmount};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { VsCurrencyType } from '@avalabs/core-coingecko-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the price of the input currency (default is USD)
|
|
6
|
+
* @param assetId id of the asset on coingecko, not matches the symbol
|
|
7
|
+
* @param currency currency you want the result to be in, default is 'usd'
|
|
8
|
+
*/
|
|
9
|
+
declare function usePrice(assetId: string | undefined, currency?: VsCurrencyType): Big;
|
|
10
|
+
|
|
11
|
+
export { usePrice };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as o,useCallback as r,useEffect as e}from"react";import t from"big.js";import{BIG_ZERO as s}from"../utils/bignumber.js";import{isNativeAsset as i}from"../utils/asset.js";import"@avalabs/core-utils-sdk";import"ethers";import{useBridgeSDK as c}from"../contexts/BridgeSDKProvider.js";import{useTokenInfoContext as n}from"../contexts/TokenInfoProvider.js";import{simplePrice as m,getBasicCoingeckoHttp as a,VsCurrencyType as f}from"@avalabs/core-coingecko-sdk";function p(p,u=f.USD){const{ethereumAssets:d}=c(),l=n(),[g,k]=o(s),b=r((async o=>{try{const r=await m(a(),{coinIds:[o],currencies:[u]});k(new t(r[o.toLowerCase()]?.[u]?.price||0))}catch(o){console.error(o),k(s)}}),[u]);return e((()=>{if(!d||!p)return;const o=d[p];if(o&&i(o))b(o.coingeckoId);else{const o=l?.[p];b(o?.coingeckoId||p)}}),[p,d,b,l]),g}export{p as usePrice};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Blockchain as o}from"../types/config.js";import{usePrice as r}from"./usePrice.js";function t(t){const e=t===o.AVALANCHE?"avalanche-2":t;return r(e)}export{t as usePriceForChain};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Assets, Blockchain } from '../types/config.js';
|
|
2
|
+
import { TransactionDetails } from '../lib/models.js';
|
|
3
|
+
import { Maybe } from '@avalabs/core-utils-sdk';
|
|
4
|
+
import { Provider } from 'ethers';
|
|
5
|
+
|
|
6
|
+
declare function useResetTransactionDetailsFromParams(avalancheProvider: Provider, ethereumProvider: Provider, setTransactionDetails: (details: TransactionDetails) => void, assets: Maybe<Assets>): (txHash: string, network: Blockchain) => Promise<void>;
|
|
7
|
+
|
|
8
|
+
export { useResetTransactionDetailsFromParams };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"big.js";import{useCallback as o}from"react";import{Blockchain as r}from"../types/config.js";import{BIG_TEN as e,BIG_ZERO as i}from"../utils/bignumber.js";import{isEthAsset as s}from"../utils/asset.js";import"@avalabs/core-utils-sdk";import{AbiCoder as n}from"ethers";function a(a,p,c,m){return o((async(o,d)=>{if(!o||!d||!m)return;const f=d===r.AVALANCHE?a:p;await f.waitForTransaction(o);const u=await f.getTransactionReceipt(o);let l="";const b=u?.to?.toUpperCase();for(const t in m){const o=m[t];if(s(o)&&(o.nativeContractAddress.toUpperCase()===b||o.wrappedContractAddress.toUpperCase()===b)){l=t;break}}const C=n.defaultAbiCoder().decode(["uint256"],u?.logs?.[0]?.data??"");let g;if(l&&C[0]){const o=m[l];g=new t(C[0].toString()).div(e.pow(o.denomination))}c({tokenSymbol:l,amount:g||i})}),[c,m])}export{a as useResetTransactionDetailsFromParams};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Blockchain, AppConfig, EthereumConfigAsset } from '../types/config.js';
|
|
2
|
+
import { Maybe } from '@avalabs/core-utils-sdk';
|
|
3
|
+
import { Provider, TransactionResponse } from 'ethers';
|
|
4
|
+
|
|
5
|
+
declare function useSubscribeForNewTransactionFromBridgeEVM(network: Blockchain, avalancheProvider: Provider, ethereumProvider: Provider, config: Maybe<AppConfig>, asset: Maybe<EthereumConfigAsset>, account: Maybe<string>): TransactionResponse | undefined;
|
|
6
|
+
|
|
7
|
+
export { useSubscribeForNewTransactionFromBridgeEVM };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as r,useEffect as t}from"react";import{Blockchain as e}from"../types/config.js";import o from"../abi/wavax.abi.json.js";import{ETHERSCAN_API_KEY as n}from"../runtime/config.js";import{Contract as c}from"ethers";function a(a,i,s,f,l,u){const[m,w]=r();return t((()=>{if(u&&l)return a===e.AVALANCHE?function(){if(!u||!l)return;const r=new c(l.wrappedContractAddress,o,i),t=r.filters.Transfer(null,u);function e(o,n,c,a){"0x0000000000000000000000000000000000000000"===o&&(r.off(t,e),a.getTransaction().then((r=>w(r))).catch((r=>console.error(r))))}return r.on(t,e),()=>{r.off(t,e)}}():function(){if(!u||!f)return;const r=f.critical.walletAddresses.ethereum;let t;return s.getBlockNumber().then((e=>{t=window.setInterval((async()=>{const o=`https://api${4===f?.critical.networks.ethereum?"-rinkeby":""}.etherscan.io/api?module=account&action=tokentx&address=${u}&startblock=${e}&endblock=99999999&sort=asc&apikey=${n}`;try{const e=await fetch(o),n=(await e.json()).result.find((t=>t.from.toLowerCase()===r));n&&(window.clearInterval(t),w(n))}catch(r){console.error(r)}}),2e3)})).catch((r=>console.error(r))),()=>{window.clearInterval(t)}}()}),[l,a,u,f]),m}export{a as useSubscribeForNewTransactionFromBridgeEVM};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as t,useEffect as e,useCallback as o,useMemo as n}from"react";function r(){const[r,a]=t(Date.now()),[s,c]=t(0),[w,i]=t(!1);e((()=>{let t;return w?t=window.setInterval((()=>{c(Math.floor((Date.now()-r)/1e3))}),1e3):w||0===s||window.clearInterval(t),()=>{window.clearInterval(t)}}),[w,r,s]);const l=o(((t,e)=>{a(t);const o=e??Date.now();c(Math.floor((o-t)/1e3))}),[]),d=o((()=>{w||(i(!0),a(Date.now()))}),[w]),f=o((()=>{i(!1)}),[]);return n((()=>({isActive:w,seconds:s,start:d,stop:f,setTimerSeconds:l,started:r})),[w,s,l,r,d,f])}export{r as useTimer};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TxHash, WrapStatus } from '../lib/models.js';
|
|
2
|
+
import { BtcTransactionRequest } from '../lib/transferAssetBTC.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Transfer Bitcoin asset to Avalanche.
|
|
6
|
+
*/
|
|
7
|
+
declare function useTransferAssetBTC(signAndSendBTC: (txParams: BtcTransactionRequest) => Promise<TxHash>): {
|
|
8
|
+
transferAsset: (amount: string, feeRate: number) => Promise<string> | undefined;
|
|
9
|
+
status: WrapStatus;
|
|
10
|
+
txHash: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { useTransferAssetBTC };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as t,useCallback as r}from"react";import{useBridgeSDK as o}from"../contexts/BridgeSDKProvider.js";import"../contexts/TokenInfoProvider.js";import"bitcoinjs-lib";import"big.js";import{Blockchain as i}from"../types/config.js";import"../utils/bignumber.js";import"@avalabs/core-utils-sdk";import"ethers";import"@avalabs/core-wallets-sdk";import"../runtime/config.js";import"../runtime/nativeAssets.js";import{WrapStatus as s}from"../lib/models.js";import"../lib/hasAddressVulnerableMultichainApproval.js";import{transferAssetBTC as e}from"../lib/transferAssetBTC.js";import{useBridgeConfig as n}from"./useBridgeConfig.js";function m(m){const{currentBlockchain:a}=o(),{config:p}=n(),[f,c]=t(s.INITIAL),[l,u]=t("");return{transferAsset:r((function(t,r){if(p&&a===i.BITCOIN)return e({amount:t,feeRate:r,config:p,onStatusChange:c,onTxHashChange:u,signAndSendBTC:m})}),[p,a,m]),status:f,txHash:l}}export{m as useTransferAssetBTC};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { EthereumConfigAsset, NativeAsset } from '../types/config.js';
|
|
3
|
+
import { TxHash, WrapStatus } from '../lib/models.js';
|
|
4
|
+
import { Maybe } from '@avalabs/core-utils-sdk';
|
|
5
|
+
import { JsonRpcApiProvider, TransactionRequest } from 'ethers';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Transfer an ERC20 asset.
|
|
9
|
+
* When currentBlockchain is Avalanche the asset will be transferred to
|
|
10
|
+
* Ethereum and vice versa.
|
|
11
|
+
*
|
|
12
|
+
* @param signAndSendEVM Required when the provider for the currentBlockchain
|
|
13
|
+
* @param avalancheProvider This can accept either a JsonRpcProvider or BrowserProvider. If a signAndSendEVM param is provided, then this can be a JsonRpcProvider (i.e. a provider without signing capabilities), otherwise this should be a BrowserProvider, or other provider with signing capabilities (via the provider.getSigner method)
|
|
14
|
+
* @param ethereumProvider Same comment as avalancheProvider^
|
|
15
|
+
* does not support signing transactions.
|
|
16
|
+
*/
|
|
17
|
+
declare function useTransferAssetEVM(asset: Maybe<EthereumConfigAsset | NativeAsset>, account: Maybe<string>, avalancheProvider: JsonRpcApiProvider, ethereumProvider: JsonRpcApiProvider, signAndSendEVM?: (txData: TransactionRequest) => Promise<TxHash>): {
|
|
18
|
+
transferAsset: (amount: Big) => Promise<string> | undefined;
|
|
19
|
+
status: WrapStatus;
|
|
20
|
+
txHash: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { useTransferAssetEVM };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as r,useCallback as t}from"react";import{useBridgeSDK as o}from"../contexts/BridgeSDKProvider.js";import"../contexts/TokenInfoProvider.js";import"bitcoinjs-lib";import"big.js";import{Blockchain as i}from"../types/config.js";import"../utils/bignumber.js";import"@avalabs/core-utils-sdk";import"ethers";import"@avalabs/core-wallets-sdk";import"../runtime/config.js";import"../runtime/nativeAssets.js";import{WrapStatus as s}from"../lib/models.js";import{transferAssetEVM as e}from"../lib/transferAssetEVM.js";import"../lib/hasAddressVulnerableMultichainApproval.js";import{useBridgeConfig as n}from"./useBridgeConfig.js";function a(a,m,c,p,u){const{currentBlockchain:l}=o(),{config:f}=n(),[d,g]=r(s.INITIAL),[j,b]=r("");return{transferAsset:t((function(r){if(a&&m&&f&&(l===i.AVALANCHE||l===i.ETHEREUM))return e({currentBlockchain:l,amount:r,account:m,asset:a,avalancheProvider:c,ethereumProvider:p,config:f,onStatusChange:g,onTxHashChange:b,signAndSendEVM:u})}),[m,a,c,f,l,p,u]),status:d,txHash:j}}export{a as useTransferAssetEVM};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Blockchain, AppConfig, EthereumConfigAssets } from '../types/config.js';
|
|
2
|
+
import { TransactionDetails } from '../lib/models.js';
|
|
3
|
+
import Big from 'big.js';
|
|
4
|
+
import { Maybe } from '@avalabs/core-utils-sdk';
|
|
5
|
+
import { Provider } from 'ethers';
|
|
6
|
+
|
|
7
|
+
interface TrackerViewProps {
|
|
8
|
+
sourceNetwork: Blockchain;
|
|
9
|
+
sourceSeconds: number;
|
|
10
|
+
sourceTxHash?: string;
|
|
11
|
+
targetNetwork: Blockchain;
|
|
12
|
+
targetSeconds: number;
|
|
13
|
+
targetTxHash?: string;
|
|
14
|
+
confirmationCount: number;
|
|
15
|
+
requiredConfirmationCount: number;
|
|
16
|
+
complete: boolean;
|
|
17
|
+
gasCost?: Big;
|
|
18
|
+
gasValue?: Big;
|
|
19
|
+
amount?: Big;
|
|
20
|
+
symbol?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated this hook is buggy, prefer trackBridgeTransaction instead.
|
|
24
|
+
*
|
|
25
|
+
* Track an EVM transaction
|
|
26
|
+
* @param started Start timestamp of the source transaction.
|
|
27
|
+
* @param isHidden Is the screen hidden e.g. document.hidden
|
|
28
|
+
*/
|
|
29
|
+
declare function useTxTracker(sourceNetwork: Blockchain, txId: string, started: string, avalancheProvider: Provider, ethereumProvider: Provider, setTransactionDetails: (details: TransactionDetails) => void, config: Maybe<AppConfig>, account: Maybe<string>, transactionDetails: Maybe<TransactionDetails>, ethWrappedAssets: Maybe<EthereumConfigAssets>, isHidden?: boolean): TrackerViewProps;
|
|
30
|
+
|
|
31
|
+
export { TrackerViewProps, useTxTracker };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Blockchain as o}from"../types/config.js";import{useState as t,useCallback as s,useEffect as r}from"react";import{useTimer as e}from"./useTimer.js";import{useSubscribeForNewTransactionFromBridgeEVM as i}from"./useSubscribeForNewTransactionFromBridge.js";import{useWaitForConfirmations as n}from"./useWaitForConfirmations.js";import{usePrice as a}from"./usePrice.js";import{useResetTransactionDetailsFromParams as m}from"./useResetTransactionDetailsFromParams.js";import{useCheckHistoryForNewTxEVM as c}from"./useCheckHistoryForNewTxEVM.js";function u(u,f,p,l,C,d,T,k,A,E,b){const[h,y]=t(!1),[H,S]=t(!1),[g,N]=t(),j=E?.[A?.tokenSymbol||""],[w,F]=t(!1),x=e(),V=e(),M=u===o.AVALANCHE?l:C,L=u===o.ETHEREUM?o.AVALANCHE:o.ETHEREUM,R=u===o.AVALANCHE?C:l,v=T?.nonCritical.minimumConfirmations[u]||1e3,P=i(L,l,C,T,j,k),{confirmations:U,gasCost:q}=n(v,M,f),B=m(l,C,d,E),D=a(u),{checkHistoryForNewTx:I}=c(L,R,k,j),W=s((o=>{V.stop(),N(o),F(!0)}),[V]);r((()=>{x.start(),x.setTimerSeconds(parseInt(p))}),[]),r((()=>{!async function(){if(!b&&h&&V.seconds>0){y(!1);const o=await I();o&&(o.block&&V.setTimerSeconds(Math.floor((1e3*o.block.timestamp-V.started)/1e3)),o.transaction&&W(o.transaction.hash))}else b&&y(!0)}()}),[I,W,h,V,b]),r((()=>{A||(B(f,u),S(!0))}),[B,u,A,f]),r((()=>{if(f&&U>=v){if(A?.tokenSymbol&&U>v&&H)return void W();x.isActive&&(x.stop(),V.start())}}),[U,W,H,v,x,V,A?.tokenSymbol,f]),r((()=>{A&&P&&U>=v&&W(P.hash)}),[U,W,v,P,A]);const z=D&&q&&D.mul(q);return{sourceNetwork:u,sourceSeconds:x.seconds,sourceTxHash:f,targetNetwork:L,targetSeconds:V.seconds,targetTxHash:g,requiredConfirmationCount:v,confirmationCount:U,complete:w,gasCost:q,gasValue:z,amount:A?.amount,symbol:A?.tokenSymbol}}export{u as useTxTracker};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Maybe } from '@avalabs/core-utils-sdk';
|
|
2
|
+
import Big from 'big.js';
|
|
3
|
+
import { Provider } from 'ethers';
|
|
4
|
+
|
|
5
|
+
declare function useWaitForConfirmations(requiredConfirmationCount: number, provider: Provider, txHash: Maybe<string>): {
|
|
6
|
+
confirmations: number;
|
|
7
|
+
gasCost: Big | undefined;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { useWaitForConfirmations };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import r from"big.js";import{formatUnits as t}from"ethers";import{useState as o,useEffect as n}from"react";function i(i,e,a){const[c,s]=o(0),[f,m]=o();return n((()=>{if(a)return e.on("block",o),e.waitForTransaction(a,i).then((async r=>{r&&s(await r.confirmations()),e.removeListener("block",o)})).catch((r=>console.error(r))),()=>{e.removeListener("block",o)};async function o(){if(a)try{const o=await e.getTransaction(a);if(!o||!o.gasPrice)return;if(s(await o.confirmations()),!f){const n=await e.getTransactionReceipt(a);if(!n)return;m(new r(t(o.gasPrice*n.gasUsed,18)))}}catch(r){console.error(r)}}}),[a,e,i,f]),{confirmations:c,gasCost:f}}export{i as useWaitForConfirmations};
|