@avalabs/core-bridge-sdk 3.1.0-alpha.60 → 3.1.0-alpha.62

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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var t=require("react/jsx-runtime"),e=require("react"),n=require("@avalabs/core-utils-sdk"),a=require("bitcoinjs-lib"),s=require("big.js"),r=require("ethers"),o=require("@avalabs/core-wallets-sdk"),i=require("@avalabs/core-coingecko-sdk"),c=(t=>(t.AVALANCHE="avalanche",t.ETHEREUM="ethereum",t.BITCOIN="bitcoin",t.UNKNOWN="",t))(c||{}),u=(t=>(t.MAINNET="mainnet",t.TESTNET="testnet",t))(u||{}),d=(t=>(t.DEV="development",t.STAGING="staging",t.TEST="test",t.PROD="prod",t))(d||{}),p=(t=>(t[t.NATIVE=0]="NATIVE",t[t.ERC20=1]="ERC20",t[t.BTC=2]="BTC",t))(p||{});const l=process.env.ETHERSCAN_API_KEY||process.env.REACT_APP_ETHERSCAN_API_KEY,m=process.env.INFURA_API_KEY||process.env.REACT_APP_INFURA_API_KEY;let f;function y(t){if(t)return T[t];if(!f)throw new Error("No environment set, initialize by calling setBridgeEnvironment");return f}const w={environment:d.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/${m}`]},disabledTokensOnNetwork:{[c.AVALANCHE]:[],[c.ETHEREUM]:["FAU"]}},b={...w,environment:d.STAGING,bridgeUrl:"https://bridge.avax-test.network",tokenInfoUrl:"https://raw.githubusercontent.com/ava-labs/avalanche-bridge-resources/main/token_list.test.json"},g={...b,environment:d.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://assets.warden-testnet.avalanche.protofire.io/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"]},h={...g,environment:d.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/${m}`]},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://assets.warden-mainnet.avalanche.protofire.io/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:{[c.AVALANCHE]:[],[c.ETHEREUM]:["CRV"]}},T={[d.PROD]:h,[d.STAGING]:b,[d.TEST]:g,[d.DEV]:w};const A={},E=e.createContext(A),C=({children:a})=>{const[s,r]=e.useState();return e.useEffect((()=>{!async function(){const t=await async function(){try{const t=await n.promiseResolveWithBackoff((()=>fetch(y().tokenInfoUrl)),(()=>!1),0,10);return await t.json()}catch(t){return console.error(t),{}}}();r(t)}()}),[]),t.jsx(E.Provider,{value:s,children:a})};function v(){return e.useContext(E)}const N={ETH:{symbol:"ETH",tokenName:"Ether",assetType:p.NATIVE,nativeNetwork:c.ETHEREUM,wrappedAssetSymbol:"WETH",denomination:18,coingeckoId:"ethereum"}};function I(t){try{return a.address.fromBech32(t),!0}catch{return!1}}function k(t,e){return!!I(t)&&t.toLowerCase().startsWith(e?"bc":"tb")}function x(t){try{return a.address.fromBase58Check(t),!0}catch(t){return!1}}function B(t){return t.mul(1e8).toNumber()}function S(t){return new s(t).div(1e8)}const M=new s(10),F=new s(0),R=(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 O=3;function _(t){return t.critical.networks.avalanche===H.MAINNET}function U(t,e){return JSON.stringify(V(t))!==JSON.stringify(V(e))}function V(t){if(!t.config)return;const{critical:e,criticalBitcoin:n}=t.config;return[e,n]}function P(t){return Boolean(t.critical.useNewFeeStructure)}function L(t){return Boolean(t.criticalBitcoin.useNewFeeStructure)}const D=new Intl.NumberFormat(void 0,{style:"currency",currency:"USD",currencyDisplay:"symbol",minimumFractionDigits:2,maximumFractionDigits:2}),j=({addressEVM:t,addressBTC:e,bridgeConfig:n})=>!(!t||!n.config?.critical.addressBlocklist.includes(t))||!(!e||!n.config?.criticalBitcoin.addressBlocklist.includes(e)),G=t=>t.assetType===p.NATIVE,W=t=>t.assetType===p.BTC,z=t=>t.assetType===p.ERC20;var $=[{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"}],q=[{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"}],K=[{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 X(t,e,n=!1){return n&&e?function(t,e){return new r.JsonRpcSigner(t,e)}(t,e):t}function J(t,e,n,a,s=!1){if(!r.isAddress(t)||t===r.ZeroAddress)throw Error(`Invalid 'address' parameter '${t}'.`);return new r.Contract(t,e,X(n,a,s))}function Y(t,e,n){const{minimumFeeAmount:a,maximumFeeAmount:r,feePercentage:o,feePercentageDecimals:i}=n,c=new s(a).div(M.pow(e)),u=new s(r).div(M.pow(e)),d=new s(o).div(M.pow(i)).div(100),p=t.mul(d);return R(p,{min:c,max:u})}function Z({source:t,config:e,amount:n}){if(!L(e))return Q(t,e,B(n));const{wrapFeeEstimate:a,unwrapFeeEstimate:r}=e.nonCriticalBitcoin.networkInfo.btc.currentBridgeFeeEstimate;if(t===c.BITCOIN)return Y(n,8,a);const{constAmount:o,numeratorPerSat:i,denominatorPerSat:u}=r.estimatedTxFee,d=o+i/u*B(n),p=Y(n,8,r.bridgeToll),l=new s(d).div(M.pow(8));return p.add(l)}function Q(t,e,n){const{constUnwrapFeeAmount:a,unwrapFeeNumerator:s,unwrapFeeDenominator:r,wrapFeeAmount:o}=e.nonCriticalBitcoin.networkInfo.btc.currentBridgeFeeEstimate;return t===c.BITCOIN?S(o):S(a+s/r*n)}function tt(t){const e=t.criticalBitcoin?.bitcoinAssets||{};return e[Object.keys(e)[0]]}function et(t,e,n){const a=function(t,e,n){if(L(e)){const a=t===c.BITCOIN,{currentBridgeFeeEstimate:s}=e.nonCriticalBitcoin.networkInfo.btc;if(a)return Number(s.wrapFeeEstimate.minimumFeeAmount);const{constAmount:r,numeratorPerSat:o,denominatorPerSat:i}=s.unwrapFeeEstimate.estimatedTxFee,u=r+o/i*n;return Number(s.unwrapFeeEstimate.bridgeToll.minimumFeeAmount)+u}const a=Z({source:t,config:e,amount:S(n)});return B(a)}(t,e,n);if(t===c.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 nt(t,e){return e.getTransaction(t)}function at(t,e){switch(t){case c.ETHEREUM:{const n={...e.critical.assets,ETH:N.ETH};return st(t,n),n}case c.AVALANCHE:{const n={...e.critical.assets,...at(c.BITCOIN,e)};return st(t,n),n}case c.BITCOIN:{const t=tt(e);return t?{BTC:t}:{}}default:return{}}}function st(t,e){(y().disabledTokensOnNetwork[t]||[]).forEach((t=>delete e[t]))}const rt=e.createContext({});function ot(){return e.useContext(rt)}function it(){const{bridgeConfig:t}=ot();return t}function ct({source:t,config:e,asset:n,amount:a}){if(!P(e))return ut(t,e,n);const{wrapFeeApproximation:s,unwrapFeeApproximation:r}=e.nonCritical,{symbol:o,denomination:i}=n;return Y(a,i,t===c.ETHEREUM?s[o]:r[o])}function ut(t,e,n){const{wrapFeeApproximation:a,unwrapFeeApproximation:r}=e?.nonCritical||{},o=n.symbol,i=t===c.ETHEREUM?a?.[o]:r?.[o];return new s(i||0).div(M.pow(n.denomination))}const dt=2048;async function pt(t,e,n,a,s,o){const i=s?.nativeNetwork===t?s?.nativeContractAddress:s?.wrappedContractAddress;if(!i||!o||!n)return;const u=t===c.AVALANCHE?K:$,d=new r.Contract(i,u,e),p=t===c.AVALANCHE?"0x0000000000000000000000000000000000000000":n.critical.walletAddresses.ethereum,l=d.filters.Transfer(p,a),m=await e.getBlockNumber();let f=o-5,y=Math.min(f+dt-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+dt-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 lt(t,e,n,a,s){const r={};for(const o in t){const i=t[o];let c=null;i.assetType===p.ERC20?c=await mt(i,e,n,a,s):G(i)?c=await ft(i,e,n,a):W(i)&&(c=await await mt(i,e,n,a,s)),null!==c&&(r[o]=c)}return r}async function mt(t,e,a,o,i){const u=e===c.AVALANCHE?K:$;if(t.nativeNetwork!==e&&t.wrappedNetwork!==e)return null;let d;if(i&&z(t)?d=t.deprecatedTokenContractAddress:z(t)?d=e===t.nativeNetwork?t.nativeContractAddress:t.wrappedContractAddress:t.assetType===p.BTC&&(d=t.wrappedContractAddress),!d)return null;const l=new r.Contract(d,u,a),[m,f]=await n.resolve(l.balanceOf(o)),y=t.denomination??18;return m?new s(r.formatUnits(m,y)):yt(f,(()=>mt(t,e,a,o,i)))}async function ft(t,e,a,o){if(t.nativeNetwork!==e||!a)return null;const[i,c]=await n.resolve(a.getBalance(o));return i?new s(r.formatUnits(i,t.denomination)):yt(c,(()=>ft(t,e,a,o)))}async function yt(t,e){return r.isError(t,"SERVER_ERROR")?(await n.wait(1e3+Math.floor(1e3*Math.random())),e()):(console.error(t),null)}function wt(t){return t===c.AVALANCHE?"AVAX":"ETH"}async function bt({currentBlockchain:t,balance:e,currentAsset:a,assets:r,provider:o,config:i}){const c=wt(t),u=r[a||""];if(!u)return null;if(G(u)&&u.symbol===c){const t=r[u.wrappedAssetSymbol];if(!t||t.assetType!==p.ERC20)return null;if(W(t))throw new Error("Unable to calculate BTC fee data with EVM provider.");const a=J(t.nativeContractAddress,q,o),c=await o.getFeeData(),d=await a.deposit.estimateGas({value:1}),[l,m]=await n.resolve(a.transfer.estimateGas(i.critical.walletAddresses.ethereum,1));m&&console.error(m);const f=new s(d.toString()).add(l?l.toString():0).times(c.gasPrice?.toString()??0).times(2).div(n.BIG_TEN.pow(u.denomination));return f.gte(e)?null:e.minus(f)}return e}var gt=(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))(gt||{});async function ht(t,e){if(!e)return;return t.gasPrice&&n.bigintToBig(t.gasPrice*e.gasUsed,18)}function Tt(t,e){return e===c.AVALANCHE?t.avalancheProvider:t.ethereumProvider}async function At(t){const{amount:e,addressC:n,startBlockNumber:a,symbol:o,targetChain:i}=t.bridgeTransaction,u=Tt(t,i),d=t.config,p=at(i,t.config)[o],{error:l,transaction:m}=await pt(i,u,d,n,p,a)||{};if(l)throw l;if(m){const t=await u.getTransactionReceipt(m.hash),n=await async function(t,e,n){if(!n)return;const a=t===c.AVALANCHE?K:$,o=new r.Interface(a).parseLog({data:n.logs[0].data,topics:[...n.logs[0].topics]}),i=o?.args[2];return e.minus(new s(r.formatUnits(i)))}(i,e,t),a=await ht(m,t);return{hash:m.hash,bridgeFee:n,networkFee:a,isConfirmed:!0}}}class Et{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===c.BITCOIN?async function(t){const{sourceTxHash:e}=t.bridgeTransaction,{confirmations:n,fees:a}=await nt(e,t.bitcoinProvider);return{confirmations:n,networkFee:S(a)}}(this):async function(t){const{sourceChain:e,sourceTxHash:n}=t.bridgeTransaction,a=Tt(t,e),s=await a.getTransaction(n),r=s&&await a.getTransactionReceipt(s.hash),o=r?await ht(s,r):void 0;return{confirmations:await(s?.confirmations())||0,networkFee:o}}(this)}async getTargetTxData(){switch(this.bridgeTransaction.targetChain){case c.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 nt(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&&S(B(s)-t.value),a=e.confirmations>=1;return{hash:e.hash,bridgeFee:n,networkFee:S(e.fees),isConfirmed:a}}}}(this);case c.AVALANCHE:case c.ETHEREUM:return At(this)}}async getTargetBlockNumber(){return this.bridgeTransaction.targetChain===c.BITCOIN?async function(t){return await t.bitcoinProvider.getChainHeight()}(this):async function(t){return Tt(t,t.bridgeTransaction.targetChain).getBlockNumber()}(this)}_getIntervalDelayTime(t){return t===this.bridgeTransaction.targetChain&&t===c.BITCOIN?2e4:0}onInterval(t,e){const n=function(t){return t===c.AVALANCHE?1e3:t===c.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 Ct(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 vt(t,e,a,s,r,o){const i=!o,c=J(a.wrappedContractAddress,K,s,e,i),u=n.bigToBigInt(t,a.denomination),d=await Ct(c,"unwrap",[u,0],e,s,o);return r(d),d}const Nt={[c.ETHEREUM]:"0x6b7a87899490EcE95443e979cA9485CBE7E71522",[c.AVALANCHE]:"0x9b17bAADf0f21F03e35249e0e59723F34994F806"};async function It(t,e,a,s,o,i,u,p,l){u(gt.INITIAL);const m=i.critical.walletAddresses.ethereum||"";if(z(a))return async function(t,e,a,s,r,o,i,c){const u=!c,d=J(a.nativeContractAddress,$,r,e,u),p=n.bigToBigInt(t,a.denomination);o(gt.WAITING_FOR_CONFIRMATION);const l=await Ct(d,"transfer",[s,p],e,r,c);return i(l),o(gt.COMPLETE),l}(t,e,a,m,o,u,p,l);{const f=G(a)?i.critical.assets[a.wrappedAssetSymbol]:void 0;if(!f)throw new Error("missing wrappedAsset");return async function(t,e,a,s,o,i,u,p,l,m,f){const w=!f,b=J(s.nativeContractAddress,$,u,e,w),g=n.bigToBigInt(t,a.denomination);if(a.nativeNetwork===c.ETHEREUM){const t=await async function(t,e,n,a){const s=a.critical.assets.WETH;if(!s||y().environment!==d.PROD)return!1;try{const a=new r.Contract(s.nativeContractAddress,$,n),o=await a.allowance(t,Nt[c.ETHEREUM]),i=new r.Contract(s.wrappedContractAddress,$,e),u=await i.allowance(t,Nt[c.AVALANCHE]);return 0n!==o||0n!==u}catch(t){return!1}}(e,i,u,p);if(t)throw l(gt.VULNERABLE_ADDRESS),new Error("Address has vulnerable token approvals");l(gt.WAITING_FOR_DEPOSIT_CONFIRMATION);const n=J(s.nativeContractAddress,q,u,e,w),a=await Ct(n,"deposit",[{value:g}],e,u,f);m(a),l(gt.WAITING_FOR_DEPOSIT),await u.waitForTransaction(a)}l(gt.WAITING_FOR_CONFIRMATION);const h=await Ct(b,"transfer",[o,g],e,u,f);return m(h),l(gt.COMPLETE),h}(t,e,a,f,m,s,o,i,u,p,l)}}async function kt({currentBlockchain:t,amount:e,account:n,asset:a,avalancheProvider:s,ethereumProvider:r,config:o,onStatusChange:i,onTxHashChange:u,signAndSendEVM:d}){if(t===c.AVALANCHE){if(G(a))throw new Error("Cannot transfer AVAX");return vt(e,n,a,s,u,d)}if(!z(a)&&!G(a))throw new Error("Unsupported asset type");return It(e,n,a,s,r,o,i,u,d)}const xt=async({fromAccount:t,amount:e,feeRate:n,config:a,onStatusChange:s,onTxHashChange:r,signAndSendBTC:o})=>{s(gt.INITIAL);const i=a.criticalBitcoin?.walletAddresses.btc||"";if(!i)throw new Error("Bridge address is not found in the config.");const u=et(c.BITCOIN,a,Number(e));if(Number(e)<u)throw new Error(`Amount must be at least ${u} satoshis.`);if(!n)throw new Error("Fee rate is not provided.");const d={from:t,to:i,amount:e,feeRate:n};s(gt.WAITING_FOR_CONFIRMATION);const p=await o(d);return s(gt.COMPLETE),r(p),p};function Bt(t,n,a,s){const[r,o]=e.useState(),{config:i}=it();e.useEffect((()=>{n.getBlockNumber().then((t=>{o(t)})).catch((t=>console.error(t)))}),[n]);return{checkHistoryForNewTx:e.useCallback((async()=>pt(t,n,i,a,s,r)),[t,n,i,a,s,r]),startBlockNumber:r}}function St(t,n,a,s,r,o){const[i,c]=e.useState();return e.useEffect((()=>{!async function(){if(!n)return;const e=r&&s?await lt(n,t,a,r,o):{};c(e)}()}),[r,s,n,a,t,o]),i}function Mt(t,n=i.VsCurrencyType.USD){const{ethereumAssets:a}=ot(),r=v(),[o,c]=e.useState(F),u=e.useCallback((async t=>{try{const e=await i.simplePrice(i.getBasicCoingeckoHttp(),{coinIds:[t],currencies:[n]});c(new s(e[t.toLowerCase()]?.[n]?.price||0))}catch(t){console.error(t),c(F)}}),[n]);return e.useEffect((()=>{if(!a||!t)return;const e=a[t];if(e&&G(e))u(e.coingeckoId);else{const e=r?.[t];u(e?.coingeckoId||t)}}),[t,a,u,r]),o}function Ft(t,n,a,o){return e.useCallback((async(e,i)=>{if(!e||!i||!o)return;const u=i===c.AVALANCHE?t:n;await u.waitForTransaction(e);const d=await u.getTransactionReceipt(e);let p="";const l=d?.to?.toUpperCase();for(const t in o){const e=o[t];if(z(e)&&(e.nativeContractAddress.toUpperCase()===l||e.wrappedContractAddress.toUpperCase()===l)){p=t;break}}const m=r.AbiCoder.defaultAbiCoder().decode(["uint256"],d?.logs?.[0]?.data??"");let f;if(p&&m[0]){const t=o[p];f=new s(m[0].toString()).div(M.pow(t.denomination))}a({tokenSymbol:p,amount:f||F})}),[a,o])}function Rt(t,n,a,s,o,i){const[u,d]=e.useState();return e.useEffect((()=>{if(i&&o)return t===c.AVALANCHE?function(){if(!i||!o)return;const t=new r.Contract(o.wrappedContractAddress,K,n),e=t.filters.Transfer(null,i);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(!i||!s)return;const t=s.critical.walletAddresses.ethereum;let e;return a.getBlockNumber().then((n=>{e=window.setInterval((async()=>{const a=`https://api${4===s?.critical.networks.ethereum?"-rinkeby":""}.etherscan.io/api?module=account&action=tokentx&address=${i}&startblock=${n}&endblock=99999999&sort=asc&apikey=${l}`;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,t,i,s]),u}function Ht(){const[t,n]=e.useState(Date.now()),[a,s]=e.useState(0),[r,o]=e.useState(!1);e.useEffect((()=>{let e;return r?e=window.setInterval((()=>{s(Math.floor((Date.now()-t)/1e3))}),1e3):r||0===a||window.clearInterval(e),()=>{window.clearInterval(e)}}),[r,t,a]);const i=e.useCallback(((t,e)=>{n(t);const a=e??Date.now();s(Math.floor((a-t)/1e3))}),[]),c=e.useCallback((()=>{r||(o(!0),n(Date.now()))}),[r]),u=e.useCallback((()=>{o(!1)}),[]);return e.useMemo((()=>({isActive:r,seconds:a,start:c,stop:u,setTimerSeconds:i,started:t})),[r,a,i,t,c,u])}function Ot(t,n,a){const[o,i]=e.useState(0),[c,u]=e.useState();return e.useEffect((()=>{if(a)return n.on("block",e),n.waitForTransaction(a,t).then((async t=>{t&&i(await t.confirmations()),n.removeListener("block",e)})).catch((t=>console.error(t))),()=>{n.removeListener("block",e)};async function e(){if(a)try{const t=await n.getTransaction(a);if(!t||!t.gasPrice)return;if(i(await t.confirmations()),!c){const e=await n.getTransactionReceipt(a);if(!e)return;u(new s(r.formatUnits(t.gasPrice*e.gasUsed,18)))}}catch(t){console.error(t)}}}),[a,n,t,c]),{confirmations:o,gasCost:c}}exports.AVERAGE_TRANSFER_TX_GAS_USAGE=40000n,exports.AssetType=p,exports.BIG_TEN=M,exports.BIG_ZERO=F,exports.Blockchain=c,exports.BridgeSDKProvider=function({children:n}){const[a,s]=e.useState(),[r,o]=e.useState({}),i=e.useCallback((t=>{if(U(r,t)&&t.config){const{critical:e,criticalBitcoin:n}=t.config;s({critical:e,criticalBitcoin:n})}o(t)}),[r]),[u,d]=e.useState(),[l,m]=e.useState(c.ETHEREUM),[f,y]=e.useState(c.AVALANCHE),[w,b]=e.useState(),g=e.useMemo((()=>a?at(c.ETHEREUM,a):{}),[a]),h=e.useMemo((()=>{const t={};for(const e in g){const n=g[e];n.assetType===p.ERC20&&(t[e]=n)}return t}),[g]),T=e.useMemo((()=>a?at(c.BITCOIN,a):{}),[a]),A=e.useMemo((()=>a?at(c.AVALANCHE,a):{}),[a]),E=e.useMemo((()=>{if(u)return g[u]||T[u]||A[u]}),[A,T,u,g]),v=e.useMemo((()=>l===c.AVALANCHE?A:l===c.BITCOIN?T:g),[A,T,l,g]);e.useEffect((()=>{const t=Object.keys(v);u&&t.includes(u)||d(1===t.length?t[0]:void 0)}),[u,v]);const N=e.useMemo((()=>{if(l===c.AVALANCHE){if(E?.assetType===p.ERC20)return[c.ETHEREUM];if(E?.assetType===p.BTC)return[c.BITCOIN]}else if(l===c.ETHEREUM||l===c.BITCOIN)return[c.AVALANCHE];return[]}),[l,E]);e.useEffect((()=>{N.includes(f)||y(N[0])}),[l,f,N]),e.useEffect((()=>{l===c.BITCOIN||l===c.ETHEREUM?y(c.AVALANCHE):l===c.AVALANCHE&&(E?.assetType===p.ERC20?y(c.ETHEREUM):E?.assetType===p.BTC&&y(c.BITCOIN))}),[l,E]);const I={sourceAssets:v,ethereumAssets:g,bitcoinAssets:T,ethereumWrappedAssets:h,avalancheAssets:A,bridgeConfig:r,setBridgeConfig:i,criticalConfig:a,currentAsset:u,currentAssetData:E,setCurrentAsset:d,currentBlockchain:l,setCurrentBlockchain:m,targetBlockchain:f,transactionDetails:w,setTransactionDetails:b,targetChains:N};return t.jsx(rt.Provider,{value:I,children:t.jsx(C,{children:n})})},exports.ETHERSCAN_API_KEY=l,exports.Environment=d,exports.INFURA_API_KEY=m,exports.NetworkType=u,exports.TokenInfoProvider=C,exports.WrapStatus=gt,exports.btcToSatoshi=B,exports.capped=R,exports.checkHistoryForNewTxEVM=pt,exports.estimateGas=async function(t,e,a,s,r,o,i=!1){if(z(a)||W(a)){if(o===c.AVALANCHE){const r=J(a.wrappedContractAddress,K,s.avalanche,e,i),o=await r.unwrap.populateTransaction(n.bigToBigInt(t,a.denomination),0);return s.avalanche.estimateGas({...o,from:e})}if(z(a)){const r=J(a.nativeContractAddress,$,s.ethereum,e,i),o=await r.transfer.populateTransaction(e,n.bigToBigInt(t,a.denomination));return s.ethereum.estimateGas({...o,from:e})}}else if(G(a)){const o=r.critical.assets[a.wrappedAssetSymbol];if(!o)throw new Error("Cannot estimate gas: missing wrappedAsset");let u=0n;if(a.nativeNetwork===c.ETHEREUM){const r=J(o.nativeContractAddress,q,s.ethereum,e,i),c=await r.deposit.populateTransaction({value:n.bigToBigInt(t,a.denomination)});u+=await s.ethereum.estimateGas({...c,from:e})}const d=J(o.nativeContractAddress,$,s.ethereum,e,i),p=await d.transfer.populateTransaction(e,n.bigToBigInt(t,a.denomination));try{u+=await s.ethereum.estimateGas({...p,from:e})}catch{u+=40000n}return u}},exports.fetchConfig=async function(t){const[e,a]=await n.resolve(async function(t){const e=y(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 i=o.appConfig;for(const t in i.critical.assets)i.critical.assets[t].assetType=p.ERC20,i.critical.assets[t].symbol=t;if(i.criticalBitcoin)for(const t in i.criticalBitcoin.bitcoinAssets)i.criticalBitcoin.bitcoinAssets[t].assetType=p.BTC,i.criticalBitcoin.bitcoinAssets[t].symbol=t.toUpperCase(),i.criticalBitcoin.bitcoinAssets[t].denomination=8,i.criticalBitcoin.bitcoinAssets[t].nativeNetwork=c.BITCOIN;return i}(t));return e?{config:e}:{error:a}},exports.fetchTokenBalances=lt,exports.formatTokenAmount=function(t,e=2){return new Intl.NumberFormat("en-US",{minimumFractionDigits:2,maximumFractionDigits:e}).format(t.toNumber())},exports.getAssets=at,exports.getBridgeFeeEstimateBTC=Z,exports.getBridgeFeeEstimateEVM=ct,exports.getBtcAsset=tt,exports.getBtcTransaction=function(t,e,n,s,r){const i=_(t);if(!k(e,i))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=et(c.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(!r)throw new Error("Fee rate is not provided in the config.");const p=i?a.networks.bitcoin:a.networks.testnet,{inputs:l,outputs:m,psbt:f,fee:y}=o.createTransferTx(d,e,s,r,n,p);if(!l||!m||!f)throw new Error("Transaction values can not be satisfied.");const w=B(Z({source:c.BITCOIN,config:t,amount:S(s)}));return{fee:y,tx:f,bridgeFee:w,receiveAmount:s-w,inputs:l,outputs:m}},exports.getBtcTransactionDetails=function(t,e,n,a,s){if(!k(e,_(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 r=et(c.BITCOIN,t,a);if(a<r)throw new Error(`Amount must be at least ${r} satoshis.`);const i=t.criticalBitcoin?.walletAddresses.btc||"";if(!i)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}=o.getTransferTxDetails(i,e,a,s,n);if(!u||!d)throw new Error("Transaction values can not be satisfied.");const l=B(Z({source:c.BITCOIN,config:t,amount:S(a)}));return{fee:p,bridgeFee:l,receiveAmount:a-l,inputs:u,outputs:d}},exports.getMaxTransferAmount=bt,exports.getMinimumConfirmations=function(t,e){return t===c.BITCOIN?e.nonCriticalBitcoin?.networkInfo.btc.minimumConfirmations||0:e.nonCritical.minimumConfirmations[t]||0},exports.getMinimumTransferAmount=et,exports.getNativeSymbol=function(t){switch(t){case c.AVALANCHE:return"AVAX";case c.BITCOIN:return"BTC";case c.ETHEREUM:return"ETH";default:return"???"}},exports.getRuntimeConfig=y,exports.getStaticBridgeFeeEstimateBTC=Q,exports.getStaticBridgeFeeEstimateEVM=ut,exports.getTxConfirmations=async function(t,e){return(await nt(t,e)).confirmations},exports.getTxDetails=nt,exports.hasCriticalChanges=U,exports.initalState=A,exports.isAddressBlocklisted=j,exports.isBase58Address=x,exports.isBase58AddressInNetwork=function(t,e){if(!x(t))return!1;const n=e?a.networks.bitcoin:a.networks.testnet;try{return a.address.toOutputScript(t,n),!0}catch(t){return!1}},exports.isBech32Address=I,exports.isBech32AddressInNetwork=k,exports.isBtcAsset=W,exports.isBtcUsingDynamicFees=L,exports.isEthAsset=z,exports.isEthUsingDynamicFees=P,exports.isMainnetConfig=_,exports.isNativeAsset=G,exports.satoshiToBtc=S,exports.setBridgeEnvironment=function(t){f=T[t]},exports.trackBridgeTransaction=function(t){return new Et(t)},exports.transferAssetBTC=xt,exports.transferAssetEVM=kt,exports.unwrapAsset=vt,exports.usdFormatter=D,exports.useBridgeConfig=it,exports.useBridgeConfigUpdater=function(t){const{bridgeConfig:n,setBridgeConfig:a}=ot();e.useEffect((()=>{async function e(){const e=await t();a(e)}n.config||n.error||e();const s=window.setInterval((()=>{e()}),15e3);return()=>{window.clearInterval(s)}}),[t,n])},exports.useBridgeFeeEstimate=function(t){const{currentAssetData:n,currentBlockchain:a,bridgeConfig:s,ethereumAssets:r,ethereumWrappedAssets:o}=ot();return e.useMemo((()=>{if(!r||!n||!s.config)return;const e=W(n)&&(a===c.AVALANCHE||a===c.BITCOIN),i=!W(n)&&(a===c.AVALANCHE||a===c.ETHEREUM);if(e)return Z({source:a,config:s.config,amount:t});if(i){const e=G(n)?o[n.wrappedAssetSymbol]:n;return ct({source:a,config:s.config,asset:e,amount:t})}}),[r,n,s.config,a,t,o])},exports.useBridgeSDK=ot,exports.useCheckHistoryForNewTxEVM=Bt,exports.useGetAirdropAmount=function(t,n,a,r){return e.useCallback((()=>r?.avaxPromotionAmount&&r.avaxPromotionDollarThreshold&&t===c.AVALANCHE&&a?.amount?a.amount.times(n).lt(new s(r.avaxPromotionDollarThreshold))?0:new s(r.avaxPromotionAmount).div(M.pow(18)).toNumber():0),[r,n,t,a])},exports.useGetTokenBalanceEVM=function(t,n,a,s,r,o){const{ethereumAssets:i}=ot();if(n&&G(n)&&n.nativeNetwork!==t){const t=i[n.wrappedAssetSymbol];t&&t.assetType===p.ERC20&&(n=t)}const c=St(t,e.useMemo((()=>n?{[n.symbol]:n}:void 0),[n]),a,s,r,o);return n&&c?c[n.symbol]:void 0},exports.useGetTokenBalancesEVM=St,exports.useGetTokenSymbolOnNetwork=function(){const{sourceAssets:t}=ot();return{getTokenSymbolOnNetwork:e.useCallback(((e,n)=>{const a=t[e];let s=e;return a&&n!==a.nativeNetwork?(G(a)&&(s=a.wrappedAssetSymbol),a.nativeNetwork===c.ETHEREUM?`${s}.e`:a.nativeNetwork===c.AVALANCHE?`${s}.a`:a.nativeNetwork===c.BITCOIN?`${s}.b`:s):s}),[t])}},exports.useHasEnoughForGas=function(t,n){const[a,r]=e.useState(!0);return e.useEffect((()=>{!async function(){if(!t||!n)return;const e=await n.getBalance(t),a=await n.getFeeData();r(new s(e.toString()).gte(a?.gasPrice?.toString()||"0"))}()}),[t,n]),a},exports.useIsAddressSanctioned=function(t){const e=it();return j({addressEVM:t,addressBTC:t,bridgeConfig:e})},exports.useMaxTransferAmount=function(t,n,a){const{currentAsset:s,currentBlockchain:r,ethereumAssets:o,avalancheAssets:i,bridgeConfig:{config:u}}=ot(),d=r===c.AVALANCHE?i:o,p=d[s||""],l=wt(r),[m,f]=e.useState(null);return e.useEffect((()=>{s&&t&&a&&u?bt({currentAsset:s,currentBlockchain:r,assets:d,balance:t,provider:a,config:u}).then((t=>{f(t)})).catch((t=>console.error(t))):f(null)}),[n,p,d,t,u,s,l,a,r]),m},exports.useMinimumTransferAmount=function(t){const{currentAssetData:n,currentBlockchain:a,bridgeConfig:r,ethereumAssets:o,ethereumWrappedAssets:i}=ot();return e.useMemo((()=>{if(!o||!n||!r.config)return F;const e=W(n)&&(a===c.AVALANCHE||a===c.BITCOIN),u=!W(n)&&(a===c.AVALANCHE||a===c.ETHEREUM);if(e)return S(et(a,r.config,B(t)));if(u){const t=G(n)?i[n.wrappedAssetSymbol]:n;return function(t,e,n){if(P(e)){const a=t===c.ETHEREUM?"wrapFeeApproximation":"unwrapFeeApproximation",{minimumFeeAmount:r}=e.nonCritical[a][n.symbol];return new s(r).div(M.pow(n.denomination)).mul(O)}return ct({source:t,config:e,asset:n,amount:F}).mul(O)}(a,r.config,t)}return F}),[o,n,r.config,a,t,i])},exports.usePrice=Mt,exports.usePriceForChain=function(t){return Mt(t===c.AVALANCHE?"avalanche-2":t)},exports.useResetTransactionDetailsFromParams=Ft,exports.useSubscribeForNewTransactionFromBridgeEVM=Rt,exports.useTimer=Ht,exports.useTokenInfoContext=v,exports.useTransferAssetBTC=function(t){const{currentBlockchain:n}=ot(),{config:a}=it(),[s,r]=e.useState(gt.INITIAL),[o,i]=e.useState("");return{transferAsset:e.useCallback((function({fromAccount:e,amount:s,feeRate:o}){if(a&&n===c.BITCOIN)return xt({fromAccount:e,amount:s,feeRate:o,config:a,onStatusChange:r,onTxHashChange:i,signAndSendBTC:t})}),[a,n,t]),status:s,txHash:o}},exports.useTransferAssetEVM=function(t,n,a,s,r){const{currentBlockchain:o}=ot(),{config:i}=it(),[u,d]=e.useState(gt.INITIAL),[p,l]=e.useState("");return{transferAsset:e.useCallback((function(e){if(t&&n&&i&&(o===c.AVALANCHE||o===c.ETHEREUM))return kt({currentBlockchain:o,amount:e,account:n,asset:t,avalancheProvider:a,ethereumProvider:s,config:i,onStatusChange:d,onTxHashChange:l,signAndSendEVM:r})}),[n,t,a,i,o,s,r]),status:u,txHash:p}},exports.useTxTracker=function(t,n,a,s,r,o,i,u,d,p,l){const[m,f]=e.useState(!1),[y,w]=e.useState(!1),[b,g]=e.useState(),h=p?.[d?.tokenSymbol||""],[T,A]=e.useState(!1),E=Ht(),C=Ht(),v=t===c.AVALANCHE?s:r,N=t===c.ETHEREUM?c.AVALANCHE:c.ETHEREUM,I=t===c.AVALANCHE?r:s,k=i?.nonCritical.minimumConfirmations[t]||1e3,x=Rt(N,s,r,i,h,u),{confirmations:B,gasCost:S}=Ot(k,v,n),M=Ft(s,r,o,p),F=Mt(t),{checkHistoryForNewTx:R}=Bt(N,I,u,h),H=e.useCallback((t=>{C.stop(),g(t),A(!0)}),[C]);e.useEffect((()=>{E.start(),E.setTimerSeconds(parseInt(a))}),[]),e.useEffect((()=>{!async function(){if(!l&&m&&C.seconds>0){f(!1);const t=await R();t&&(t.block&&C.setTimerSeconds(Math.floor((1e3*t.block.timestamp-C.started)/1e3)),t.transaction&&H(t.transaction.hash))}else l&&f(!0)}()}),[R,H,m,C,l]),e.useEffect((()=>{d||(M(n,t),w(!0))}),[M,t,d,n]),e.useEffect((()=>{if(n&&B>=k){if(d?.tokenSymbol&&B>k&&y)return void H();E.isActive&&(E.stop(),C.start())}}),[B,H,y,k,E,C,d?.tokenSymbol,n]),e.useEffect((()=>{d&&x&&B>=k&&H(x.hash)}),[B,H,k,x,d]);const O=F&&S&&F.mul(S);return{sourceNetwork:t,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=Ot,exports.wrapAsset=It;
1
+ "use strict";var t=require("react/jsx-runtime"),e=require("react"),n=require("@avalabs/core-utils-sdk"),a=require("bitcoinjs-lib"),s=require("big.js"),r=require("ethers"),o=require("@avalabs/core-wallets-sdk"),i=require("@avalabs/core-coingecko-sdk"),c=(t=>(t.AVALANCHE="avalanche",t.ETHEREUM="ethereum",t.BITCOIN="bitcoin",t.UNKNOWN="",t))(c||{}),u=(t=>(t.MAINNET="mainnet",t.TESTNET="testnet",t))(u||{}),d=(t=>(t.DEV="development",t.STAGING="staging",t.TEST="test",t.PROD="prod",t))(d||{}),p=(t=>(t[t.NATIVE=0]="NATIVE",t[t.ERC20=1]="ERC20",t[t.BTC=2]="BTC",t))(p||{});const l=process.env.ETHERSCAN_API_KEY||process.env.REACT_APP_ETHERSCAN_API_KEY,m=process.env.INFURA_API_KEY||process.env.REACT_APP_INFURA_API_KEY;let f;function y(t){if(t)return T[t];if(!f)throw new Error("No environment set, initialize by calling setBridgeEnvironment");return f}const w={environment:d.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/${m}`]},disabledTokensOnNetwork:{[c.AVALANCHE]:[],[c.ETHEREUM]:["FAU"]}},b={...w,environment:d.STAGING,bridgeUrl:"https://bridge.avax-test.network",tokenInfoUrl:"https://raw.githubusercontent.com/ava-labs/avalanche-bridge-resources/main/token_list.test.json"},g={...b,environment:d.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://assets.warden-testnet.avalanche.protofire.io/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"]},h={...g,environment:d.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/${m}`]},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://assets.warden-mainnet.avalanche.protofire.io/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:{[c.AVALANCHE]:[],[c.ETHEREUM]:["CRV"]}},T={[d.PROD]:h,[d.STAGING]:b,[d.TEST]:g,[d.DEV]:w};const A={},E=e.createContext(A),C=({children:a})=>{const[s,r]=e.useState();return e.useEffect(()=>{!async function(){const t=await async function(){try{const t=await n.promiseResolveWithBackoff(()=>fetch(y().tokenInfoUrl),()=>!1,0,10);return await t.json()}catch(t){return console.error(t),{}}}();r(t)}()},[]),t.jsx(E.Provider,{value:s,children:a})};function v(){return e.useContext(E)}const N={ETH:{symbol:"ETH",tokenName:"Ether",assetType:p.NATIVE,nativeNetwork:c.ETHEREUM,wrappedAssetSymbol:"WETH",denomination:18,coingeckoId:"ethereum"}};function I(t){try{return a.address.fromBech32(t),!0}catch{return!1}}function k(t,e){return!!I(t)&&t.toLowerCase().startsWith(e?"bc":"tb")}function x(t){try{return a.address.fromBase58Check(t),!0}catch(t){return!1}}function B(t){return t.mul(1e8).toNumber()}function S(t){return new s(t).div(1e8)}const M=new s(10),F=new s(0),R=(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||{});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)),j=t=>t.assetType===p.NATIVE,G=t=>t.assetType===p.BTC,W=t=>t.assetType===p.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 r.JsonRpcSigner(t,e)}(t,e):t}function X(t,e,n,a,s=!1){if(!r.isAddress(t)||t===r.ZeroAddress)throw Error(`Invalid 'address' parameter '${t}'.`);return new r.Contract(t,e,K(n,a,s))}function J(t,e,n){const{minimumFeeAmount:a,maximumFeeAmount:r,feePercentage:o,feePercentageDecimals:i}=n,c=new s(a).div(M.pow(e)),u=new s(r).div(M.pow(e)),d=new s(o).div(M.pow(i)).div(100),p=t.mul(d);return R(p,{min:c,max:u})}function Y({source:t,config:e,amount:n}){if(!P(e))return Z(t,e,B(n));const{wrapFeeEstimate:a,unwrapFeeEstimate:r}=e.nonCriticalBitcoin.networkInfo.btc.currentBridgeFeeEstimate;if(t===c.BITCOIN)return J(n,8,a);const{constAmount:o,numeratorPerSat:i,denominatorPerSat:u}=r.estimatedTxFee,d=o+i/u*B(n),p=J(n,8,r.bridgeToll),l=new s(d).div(M.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===c.BITCOIN?S(o):S(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===c.BITCOIN,{currentBridgeFeeEstimate:s}=e.nonCriticalBitcoin.networkInfo.btc;if(a)return Number(s.wrapFeeEstimate.minimumFeeAmount);const{constAmount:r,numeratorPerSat:o,denominatorPerSat:i}=s.unwrapFeeEstimate.estimatedTxFee,u=r+o/i*n;return Number(s.unwrapFeeEstimate.bridgeToll.minimumFeeAmount)+u}const a=Y({source:t,config:e,amount:S(n)});return B(a)}(t,e,n);if(t===c.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 c.ETHEREUM:{const n={...e.critical.assets,ETH:N.ETH};return at(t,n),n}case c.AVALANCHE:{const n={...e.critical.assets,...nt(c.BITCOIN,e)};return at(t,n),n}case c.BITCOIN:{const t=Q(e);return t?{BTC:t}:{}}default:return{}}}function at(t,e){(y().disabledTokensOnNetwork[t]||[]).forEach(t=>delete e[t])}const st=e.createContext({});function rt(){return e.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:i}=n;return J(a,i,t===c.ETHEREUM?s[o]:r[o])}function ct(t,e,n){const{wrapFeeApproximation:a,unwrapFeeApproximation:r}=e?.nonCritical||{},o=n.symbol,i=t===c.ETHEREUM?a?.[o]:r?.[o];return new s(i||0).div(M.pow(n.denomination))}async function ut(t,e,n,a,s,o){const i=s?.nativeNetwork===t?s?.nativeContractAddress:s?.wrappedContractAddress;if(!i||!o||!n)return;const u=t===c.AVALANCHE?q:z,d=new r.Contract(i,u,e),p=t===c.AVALANCHE?"0x0000000000000000000000000000000000000000":n.critical.walletAddresses.ethereum,l=d.filters.Transfer(p,a),m=await e.getBlockNumber();let f=o-5,y=Math.min(f+2048-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+2048-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 dt(t,e,n,a,s){const r={};for(const o in t){const i=t[o];let c=null;i.assetType===p.ERC20?c=await pt(i,e,n,a,s):j(i)?c=await lt(i,e,n,a):G(i)&&(c=await await pt(i,e,n,a,s)),null!==c&&(r[o]=c)}return r}async function pt(t,e,a,o,i){const u=e===c.AVALANCHE?q:z;if(t.nativeNetwork!==e&&t.wrappedNetwork!==e)return null;let d;if(i&&W(t)?d=t.deprecatedTokenContractAddress:W(t)?d=e===t.nativeNetwork?t.nativeContractAddress:t.wrappedContractAddress:t.assetType===p.BTC&&(d=t.wrappedContractAddress),!d)return null;const l=new r.Contract(d,u,a),[m,f]=await n.resolve(l.balanceOf(o)),y=t.denomination??18;return m?new s(r.formatUnits(m,y)):mt(f,()=>pt(t,e,a,o,i))}async function lt(t,e,a,o){if(t.nativeNetwork!==e||!a)return null;const[i,c]=await n.resolve(a.getBalance(o));return i?new s(r.formatUnits(i,t.denomination)):mt(c,()=>lt(t,e,a,o))}async function mt(t,e){return r.isError(t,"SERVER_ERROR")?(await n.wait(1e3+Math.floor(1e3*Math.random())),e()):(console.error(t),null)}function ft(t){return t===c.AVALANCHE?"AVAX":"ETH"}async function yt({currentBlockchain:t,balance:e,currentAsset:a,assets:r,provider:o,config:i}){const c=ft(t),u=r[a||""];if(!u)return null;if(j(u)&&u.symbol===c){const t=r[u.wrappedAssetSymbol];if(!t||t.assetType!==p.ERC20)return null;if(G(t))throw new Error("Unable to calculate BTC fee data with EVM provider.");const a=X(t.nativeContractAddress,$,o),c=await o.getFeeData(),d=await a.deposit.estimateGas({value:1}),[l,m]=await n.resolve(a.transfer.estimateGas(i.critical.walletAddresses.ethereum,1));m&&console.error(m);const f=new s(d.toString()).add(l?l.toString():0).times(c.gasPrice?.toString()??0).times(2).div(n.BIG_TEN.pow(u.denomination));return f.gte(e)?null:e.minus(f)}return e}var wt=(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))(wt||{});async function bt(t,e){if(!e)return;return t.gasPrice&&n.bigintToBig(t.gasPrice*e.gasUsed,18)}function gt(t,e){return e===c.AVALANCHE?t.avalancheProvider:t.ethereumProvider}async function ht(t){const{amount:e,addressC:n,startBlockNumber:a,symbol:o,targetChain:i}=t.bridgeTransaction,u=gt(t,i),d=t.config,p=nt(i,t.config)[o],{error:l,transaction:m}=await ut(i,u,d,n,p,a)||{};if(l)throw l;if(m){const t=await u.getTransactionReceipt(m.hash),n=await async function(t,e,n){if(!n)return;const a=t===c.AVALANCHE?q:z,o=new r.Interface(a).parseLog({data:n.logs[0].data,topics:[...n.logs[0].topics]}),i=o?.args[2];return e.minus(new s(r.formatUnits(i)))}(i,e,t),a=await bt(m,t);return{hash:m.hash,bridgeFee:n,networkFee:a,isConfirmed:!0}}}class Tt{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===c.BITCOIN?async function(t){const{sourceTxHash:e}=t.bridgeTransaction,{confirmations:n,fees:a}=await et(e,t.bitcoinProvider);return{confirmations:n,networkFee:S(a)}}(this):async function(t){const{sourceChain:e,sourceTxHash:n}=t.bridgeTransaction,a=gt(t,e),s=await a.getTransaction(n),r=s&&await a.getTransactionReceipt(s.hash),o=r?await bt(s,r):void 0;return{confirmations:await(s?.confirmations())||0,networkFee:o}}(this)}async getTargetTxData(){switch(this.bridgeTransaction.targetChain){case c.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&&S(B(s)-t.value),a=e.confirmations>=1;return{hash:e.hash,bridgeFee:n,networkFee:S(e.fees),isConfirmed:a}}}}(this);case c.AVALANCHE:case c.ETHEREUM:return ht(this)}}async getTargetBlockNumber(){return this.bridgeTransaction.targetChain===c.BITCOIN?async function(t){return await t.bitcoinProvider.getChainHeight()}(this):async function(t){return gt(t,t.bridgeTransaction.targetChain).getBlockNumber()}(this)}_getIntervalDelayTime(t){return t===this.bridgeTransaction.targetChain&&t===c.BITCOIN?2e4:0}onInterval(t,e){const n=function(t){return t===c.AVALANCHE?1e3:t===c.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 At(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 Et(t,e,a,s,r,o){const i=!o,c=X(a.wrappedContractAddress,q,s,e,i),u=n.bigToBigInt(t,a.denomination),d=await At(c,"unwrap",[u,0],e,s,o);return r(d),d}const Ct={[c.ETHEREUM]:"0x6b7a87899490EcE95443e979cA9485CBE7E71522",[c.AVALANCHE]:"0x9b17bAADf0f21F03e35249e0e59723F34994F806"};async function vt(t,e,a,s,o,i,u,p,l){u(wt.INITIAL);const m=i.critical.walletAddresses.ethereum||"";if(W(a))return async function(t,e,a,s,r,o,i,c){const u=!c,d=X(a.nativeContractAddress,z,r,e,u),p=n.bigToBigInt(t,a.denomination);o(wt.WAITING_FOR_CONFIRMATION);const l=await At(d,"transfer",[s,p],e,r,c);return i(l),o(wt.COMPLETE),l}(t,e,a,m,o,u,p,l);{const f=j(a)?i.critical.assets[a.wrappedAssetSymbol]:void 0;if(!f)throw new Error("missing wrappedAsset");return async function(t,e,a,s,o,i,u,p,l,m,f){const w=!f,b=X(s.nativeContractAddress,z,u,e,w),g=n.bigToBigInt(t,a.denomination);if(a.nativeNetwork===c.ETHEREUM){const t=await async function(t,e,n,a){const s=a.critical.assets.WETH;if(!s||y().environment!==d.PROD)return!1;try{const a=new r.Contract(s.nativeContractAddress,z,n),o=await a.allowance(t,Ct[c.ETHEREUM]),i=new r.Contract(s.wrappedContractAddress,z,e),u=await i.allowance(t,Ct[c.AVALANCHE]);return 0n!==o||0n!==u}catch(t){return!1}}(e,i,u,p);if(t)throw l(wt.VULNERABLE_ADDRESS),new Error("Address has vulnerable token approvals");l(wt.WAITING_FOR_DEPOSIT_CONFIRMATION);const n=X(s.nativeContractAddress,$,u,e,w),a=await At(n,"deposit",[{value:g}],e,u,f);m(a),l(wt.WAITING_FOR_DEPOSIT),await u.waitForTransaction(a)}l(wt.WAITING_FOR_CONFIRMATION);const h=await At(b,"transfer",[o,g],e,u,f);return m(h),l(wt.COMPLETE),h}(t,e,a,f,m,s,o,i,u,p,l)}}async function Nt({currentBlockchain:t,amount:e,account:n,asset:a,avalancheProvider:s,ethereumProvider:r,config:o,onStatusChange:i,onTxHashChange:u,signAndSendEVM:d}){if(t===c.AVALANCHE){if(j(a))throw new Error("Cannot transfer AVAX");return Et(e,n,a,s,u,d)}if(!W(a)&&!j(a))throw new Error("Unsupported asset type");return vt(e,n,a,s,r,o,i,u,d)}const It=async({fromAccount:t,amount:e,feeRate:n,config:a,onStatusChange:s,onTxHashChange:r,signAndSendBTC:o})=>{s(wt.INITIAL);const i=a.criticalBitcoin?.walletAddresses.btc||"";if(!i)throw new Error("Bridge address is not found in the config.");const u=tt(c.BITCOIN,a,Number(e));if(Number(e)<u)throw new Error(`Amount must be at least ${u} satoshis.`);if(!n)throw new Error("Fee rate is not provided.");const d={from:t,to:i,amount:e,feeRate:n};s(wt.WAITING_FOR_CONFIRMATION);const p=await o(d);return s(wt.COMPLETE),r(p),p};function kt(t,n,a,s){const[r,o]=e.useState(),{config:i}=ot();e.useEffect(()=>{n.getBlockNumber().then(t=>{o(t)}).catch(t=>console.error(t))},[n]);return{checkHistoryForNewTx:e.useCallback(async()=>ut(t,n,i,a,s,r),[t,n,i,a,s,r]),startBlockNumber:r}}function xt(t,n,a,s,r,o){const[i,c]=e.useState();return e.useEffect(()=>{!async function(){if(!n)return;const e=r&&s?await dt(n,t,a,r,o):{};c(e)}()},[r,s,n,a,t,o]),i}function Bt(t,n=i.VsCurrencyType.USD){const{ethereumAssets:a}=rt(),r=v(),[o,c]=e.useState(F),u=e.useCallback(async t=>{try{const e=await i.simplePrice(i.getBasicCoingeckoHttp(),{coinIds:[t],currencies:[n]});c(new s(e[t.toLowerCase()]?.[n]?.price||0))}catch(t){console.error(t),c(F)}},[n]);return e.useEffect(()=>{if(!a||!t)return;const e=a[t];if(e&&j(e))u(e.coingeckoId);else{const e=r?.[t];u(e?.coingeckoId||t)}},[t,a,u,r]),o}function St(t,n,a,o){return e.useCallback(async(e,i)=>{if(!e||!i||!o)return;const u=i===c.AVALANCHE?t:n;await u.waitForTransaction(e);const d=await u.getTransactionReceipt(e);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=r.AbiCoder.defaultAbiCoder().decode(["uint256"],d?.logs?.[0]?.data??"");let f;if(p&&m[0]){const t=o[p];f=new s(m[0].toString()).div(M.pow(t.denomination))}a({tokenSymbol:p,amount:f||F})},[a,o])}function Mt(t,n,a,s,o,i){const[u,d]=e.useState();return e.useEffect(()=>{if(i&&o)return t===c.AVALANCHE?function(){if(!i||!o)return;const t=new r.Contract(o.wrappedContractAddress,q,n),e=t.filters.Transfer(null,i);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(!i||!s)return;const t=s.critical.walletAddresses.ethereum;let e;return a.getBlockNumber().then(n=>{e=window.setInterval(async()=>{const a=`https://api${4===s?.critical.networks.ethereum?"-rinkeby":""}.etherscan.io/api?module=account&action=tokentx&address=${i}&startblock=${n}&endblock=99999999&sort=asc&apikey=${l}`;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,t,i,s]),u}function Ft(){const[t,n]=e.useState(Date.now()),[a,s]=e.useState(0),[r,o]=e.useState(!1);e.useEffect(()=>{let e;return r?e=window.setInterval(()=>{s(Math.floor((Date.now()-t)/1e3))},1e3):r||0===a||window.clearInterval(e),()=>{window.clearInterval(e)}},[r,t,a]);const i=e.useCallback((t,e)=>{n(t);const a=e??Date.now();s(Math.floor((a-t)/1e3))},[]),c=e.useCallback(()=>{r||(o(!0),n(Date.now()))},[r]),u=e.useCallback(()=>{o(!1)},[]);return e.useMemo(()=>({isActive:r,seconds:a,start:c,stop:u,setTimerSeconds:i,started:t}),[r,a,i,t,c,u])}function Rt(t,n,a){const[o,i]=e.useState(0),[c,u]=e.useState();return e.useEffect(()=>{if(a)return n.on("block",e),n.waitForTransaction(a,t).then(async t=>{t&&i(await t.confirmations()),n.removeListener("block",e)}).catch(t=>console.error(t)),()=>{n.removeListener("block",e)};async function e(){if(a)try{const t=await n.getTransaction(a);if(!t||!t.gasPrice)return;if(i(await t.confirmations()),!c){const e=await n.getTransactionReceipt(a);if(!e)return;u(new s(r.formatUnits(t.gasPrice*e.gasUsed,18)))}}catch(t){console.error(t)}}},[a,n,t,c]),{confirmations:o,gasCost:c}}exports.AVERAGE_TRANSFER_TX_GAS_USAGE=40000n,exports.AssetType=p,exports.BIG_TEN=M,exports.BIG_ZERO=F,exports.Blockchain=c,exports.BridgeSDKProvider=function({children:n}){const[a,s]=e.useState(),[r,o]=e.useState({}),i=e.useCallback(t=>{if(_(r,t)&&t.config){const{critical:e,criticalBitcoin:n}=t.config;s({critical:e,criticalBitcoin:n})}o(t)},[r]),[u,d]=e.useState(),[l,m]=e.useState(c.ETHEREUM),[f,y]=e.useState(c.AVALANCHE),[w,b]=e.useState(),g=e.useMemo(()=>a?nt(c.ETHEREUM,a):{},[a]),h=e.useMemo(()=>{const t={};for(const e in g){const n=g[e];n.assetType===p.ERC20&&(t[e]=n)}return t},[g]),T=e.useMemo(()=>a?nt(c.BITCOIN,a):{},[a]),A=e.useMemo(()=>a?nt(c.AVALANCHE,a):{},[a]),E=e.useMemo(()=>{if(u)return g[u]||T[u]||A[u]},[A,T,u,g]),v=e.useMemo(()=>l===c.AVALANCHE?A:l===c.BITCOIN?T:g,[A,T,l,g]);e.useEffect(()=>{const t=Object.keys(v);u&&t.includes(u)||d(1===t.length?t[0]:void 0)},[u,v]);const N=e.useMemo(()=>{if(l===c.AVALANCHE){if(E?.assetType===p.ERC20)return[c.ETHEREUM];if(E?.assetType===p.BTC)return[c.BITCOIN]}else if(l===c.ETHEREUM||l===c.BITCOIN)return[c.AVALANCHE];return[]},[l,E]);e.useEffect(()=>{N.includes(f)||y(N[0])},[l,f,N]),e.useEffect(()=>{l===c.BITCOIN||l===c.ETHEREUM?y(c.AVALANCHE):l===c.AVALANCHE&&(E?.assetType===p.ERC20?y(c.ETHEREUM):E?.assetType===p.BTC&&y(c.BITCOIN))},[l,E]);const I={sourceAssets:v,ethereumAssets:g,bitcoinAssets:T,ethereumWrappedAssets:h,avalancheAssets:A,bridgeConfig:r,setBridgeConfig:i,criticalConfig:a,currentAsset:u,currentAssetData:E,setCurrentAsset:d,currentBlockchain:l,setCurrentBlockchain:m,targetBlockchain:f,transactionDetails:w,setTransactionDetails:b,targetChains:N};return t.jsx(st.Provider,{value:I,children:t.jsx(C,{children:n})})},exports.ETHERSCAN_API_KEY=l,exports.Environment=d,exports.INFURA_API_KEY=m,exports.NetworkType=u,exports.TokenInfoProvider=C,exports.WrapStatus=wt,exports.btcToSatoshi=B,exports.capped=R,exports.checkHistoryForNewTxEVM=ut,exports.estimateGas=async function(t,e,a,s,r,o,i=!1){if(W(a)||G(a)){if(o===c.AVALANCHE){const r=X(a.wrappedContractAddress,q,s.avalanche,e,i),o=await r.unwrap.populateTransaction(n.bigToBigInt(t,a.denomination),0);return s.avalanche.estimateGas({...o,from:e})}if(W(a)){const r=X(a.nativeContractAddress,z,s.ethereum,e,i),o=await r.transfer.populateTransaction(e,n.bigToBigInt(t,a.denomination));return s.ethereum.estimateGas({...o,from:e})}}else if(j(a)){const o=r.critical.assets[a.wrappedAssetSymbol];if(!o)throw new Error("Cannot estimate gas: missing wrappedAsset");let u=0n;if(a.nativeNetwork===c.ETHEREUM){const r=X(o.nativeContractAddress,$,s.ethereum,e,i),c=await r.deposit.populateTransaction({value:n.bigToBigInt(t,a.denomination)});u+=await s.ethereum.estimateGas({...c,from:e})}const d=X(o.nativeContractAddress,z,s.ethereum,e,i),p=await d.transfer.populateTransaction(e,n.bigToBigInt(t,a.denomination));try{u+=await s.ethereum.estimateGas({...p,from:e})}catch{u+=40000n}return u}},exports.fetchConfig=async function(t){const[e,a]=await n.resolve(async function(t){const e=y(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 i=o.appConfig;for(const t in i.critical.assets)i.critical.assets[t].assetType=p.ERC20,i.critical.assets[t].symbol=t;if(i.criticalBitcoin)for(const t in i.criticalBitcoin.bitcoinAssets)i.criticalBitcoin.bitcoinAssets[t].assetType=p.BTC,i.criticalBitcoin.bitcoinAssets[t].symbol=t.toUpperCase(),i.criticalBitcoin.bitcoinAssets[t].denomination=8,i.criticalBitcoin.bitcoinAssets[t].nativeNetwork=c.BITCOIN;return i}(t));return e?{config:e}:{error:a}},exports.fetchTokenBalances=dt,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,e,n,s,r){const i=O(t);if(!k(e,i))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(c.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(!r)throw new Error("Fee rate is not provided in the config.");const p=i?a.networks.bitcoin:a.networks.testnet,{inputs:l,outputs:m,psbt:f,fee:y}=o.createTransferTx(d,e,s,r,n,p);if(!l||!m||!f)throw new Error("Transaction values can not be satisfied.");const w=B(Y({source:c.BITCOIN,config:t,amount:S(s)}));return{fee:y,tx:f,bridgeFee:w,receiveAmount:s-w,inputs:l,outputs:m}},exports.getBtcTransactionDetails=function(t,e,n,a,s){if(!k(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 r=tt(c.BITCOIN,t,a);if(a<r)throw new Error(`Amount must be at least ${r} satoshis.`);const i=t.criticalBitcoin?.walletAddresses.btc||"";if(!i)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}=o.getTransferTxDetails(i,e,a,s,n);if(!u||!d)throw new Error("Transaction values can not be satisfied.");const l=B(Y({source:c.BITCOIN,config:t,amount:S(a)}));return{fee:p,bridgeFee:l,receiveAmount:a-l,inputs:u,outputs:d}},exports.getMaxTransferAmount=yt,exports.getMinimumConfirmations=function(t,e){return t===c.BITCOIN?e.nonCriticalBitcoin?.networkInfo.btc.minimumConfirmations||0:e.nonCritical.minimumConfirmations[t]||0},exports.getMinimumTransferAmount=tt,exports.getNativeSymbol=function(t){switch(t){case c.AVALANCHE:return"AVAX";case c.BITCOIN:return"BTC";case c.ETHEREUM:return"ETH";default:return"???"}},exports.getRuntimeConfig=y,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=A,exports.isAddressBlocklisted=D,exports.isBase58Address=x,exports.isBase58AddressInNetwork=function(t,e){if(!x(t))return!1;const n=e?a.networks.bitcoin:a.networks.testnet;try{return a.address.toOutputScript(t,n),!0}catch(t){return!1}},exports.isBech32Address=I,exports.isBech32AddressInNetwork=k,exports.isBtcAsset=G,exports.isBtcUsingDynamicFees=P,exports.isEthAsset=W,exports.isEthUsingDynamicFees=V,exports.isMainnetConfig=O,exports.isNativeAsset=j,exports.satoshiToBtc=S,exports.setBridgeEnvironment=function(t){f=T[t]},exports.trackBridgeTransaction=function(t){return new Tt(t)},exports.transferAssetBTC=It,exports.transferAssetEVM=Nt,exports.unwrapAsset=Et,exports.usdFormatter=L,exports.useBridgeConfig=ot,exports.useBridgeConfigUpdater=function(t){const{bridgeConfig:n,setBridgeConfig:a}=rt();e.useEffect(()=>{async function e(){const e=await t();a(e)}n.config||n.error||e();const s=window.setInterval(()=>{e()},15e3);return()=>{window.clearInterval(s)}},[t,n])},exports.useBridgeFeeEstimate=function(t){const{currentAssetData:n,currentBlockchain:a,bridgeConfig:s,ethereumAssets:r,ethereumWrappedAssets:o}=rt();return e.useMemo(()=>{if(!r||!n||!s.config)return;const e=G(n)&&(a===c.AVALANCHE||a===c.BITCOIN),i=!G(n)&&(a===c.AVALANCHE||a===c.ETHEREUM);if(e)return Y({source:a,config:s.config,amount:t});if(i){const e=j(n)?o[n.wrappedAssetSymbol]:n;return it({source:a,config:s.config,asset:e,amount:t})}},[r,n,s.config,a,t,o])},exports.useBridgeSDK=rt,exports.useCheckHistoryForNewTxEVM=kt,exports.useGetAirdropAmount=function(t,n,a,r){return e.useCallback(()=>r?.avaxPromotionAmount&&r.avaxPromotionDollarThreshold&&t===c.AVALANCHE&&a?.amount?a.amount.times(n).lt(new s(r.avaxPromotionDollarThreshold))?0:new s(r.avaxPromotionAmount).div(M.pow(18)).toNumber():0,[r,n,t,a])},exports.useGetTokenBalanceEVM=function(t,n,a,s,r,o){const{ethereumAssets:i}=rt();if(n&&j(n)&&n.nativeNetwork!==t){const t=i[n.wrappedAssetSymbol];t&&t.assetType===p.ERC20&&(n=t)}const c=xt(t,e.useMemo(()=>n?{[n.symbol]:n}:void 0,[n]),a,s,r,o);return n&&c?c[n.symbol]:void 0},exports.useGetTokenBalancesEVM=xt,exports.useGetTokenSymbolOnNetwork=function(){const{sourceAssets:t}=rt();return{getTokenSymbolOnNetwork:e.useCallback((e,n)=>{const a=t[e];let s=e;return a&&n!==a.nativeNetwork?(j(a)&&(s=a.wrappedAssetSymbol),a.nativeNetwork===c.ETHEREUM?`${s}.e`:a.nativeNetwork===c.AVALANCHE?`${s}.a`:a.nativeNetwork===c.BITCOIN?`${s}.b`:s):s},[t])}},exports.useHasEnoughForGas=function(t,n){const[a,r]=e.useState(!0);return e.useEffect(()=>{!async function(){if(!t||!n)return;const e=await n.getBalance(t),a=await n.getFeeData();r(new s(e.toString()).gte(a?.gasPrice?.toString()||"0"))}()},[t,n]),a},exports.useIsAddressSanctioned=function(t){const e=ot();return D({addressEVM:t,addressBTC:t,bridgeConfig:e})},exports.useMaxTransferAmount=function(t,n,a){const{currentAsset:s,currentBlockchain:r,ethereumAssets:o,avalancheAssets:i,bridgeConfig:{config:u}}=rt(),d=r===c.AVALANCHE?i:o,p=d[s||""],l=ft(r),[m,f]=e.useState(null);return e.useEffect(()=>{s&&t&&a&&u?yt({currentAsset:s,currentBlockchain:r,assets:d,balance:t,provider:a,config:u}).then(t=>{f(t)}).catch(t=>console.error(t)):f(null)},[n,p,d,t,u,s,l,a,r]),m},exports.useMinimumTransferAmount=function(t){const{currentAssetData:n,currentBlockchain:a,bridgeConfig:r,ethereumAssets:o,ethereumWrappedAssets:i}=rt();return e.useMemo(()=>{if(!o||!n||!r.config)return F;const e=G(n)&&(a===c.AVALANCHE||a===c.BITCOIN),u=!G(n)&&(a===c.AVALANCHE||a===c.ETHEREUM);if(e)return S(tt(a,r.config,B(t)));if(u){const t=j(n)?i[n.wrappedAssetSymbol]:n;return function(t,e,n){if(V(e)){const a=t===c.ETHEREUM?"wrapFeeApproximation":"unwrapFeeApproximation",{minimumFeeAmount:r}=e.nonCritical[a][n.symbol];return new s(r).div(M.pow(n.denomination)).mul(3)}return it({source:t,config:e,asset:n,amount:F}).mul(3)}(a,r.config,t)}return F},[o,n,r.config,a,t,i])},exports.usePrice=Bt,exports.usePriceForChain=function(t){return Bt(t===c.AVALANCHE?"avalanche-2":t)},exports.useResetTransactionDetailsFromParams=St,exports.useSubscribeForNewTransactionFromBridgeEVM=Mt,exports.useTimer=Ft,exports.useTokenInfoContext=v,exports.useTransferAssetBTC=function(t){const{currentBlockchain:n}=rt(),{config:a}=ot(),[s,r]=e.useState(wt.INITIAL),[o,i]=e.useState("");return{transferAsset:e.useCallback(function({fromAccount:e,amount:s,feeRate:o}){if(a&&n===c.BITCOIN)return It({fromAccount:e,amount:s,feeRate:o,config:a,onStatusChange:r,onTxHashChange:i,signAndSendBTC:t})},[a,n,t]),status:s,txHash:o}},exports.useTransferAssetEVM=function(t,n,a,s,r){const{currentBlockchain:o}=rt(),{config:i}=ot(),[u,d]=e.useState(wt.INITIAL),[p,l]=e.useState("");return{transferAsset:e.useCallback(function(e){if(t&&n&&i&&(o===c.AVALANCHE||o===c.ETHEREUM))return Nt({currentBlockchain:o,amount:e,account:n,asset:t,avalancheProvider:a,ethereumProvider:s,config:i,onStatusChange:d,onTxHashChange:l,signAndSendEVM:r})},[n,t,a,i,o,s,r]),status:u,txHash:p}},exports.useTxTracker=function(t,n,a,s,r,o,i,u,d,p,l){const[m,f]=e.useState(!1),[y,w]=e.useState(!1),[b,g]=e.useState(),h=p?.[d?.tokenSymbol||""],[T,A]=e.useState(!1),E=Ft(),C=Ft(),v=t===c.AVALANCHE?s:r,N=t===c.ETHEREUM?c.AVALANCHE:c.ETHEREUM,I=t===c.AVALANCHE?r:s,k=i?.nonCritical.minimumConfirmations[t]||1e3,x=Mt(N,s,r,i,h,u),{confirmations:B,gasCost:S}=Rt(k,v,n),M=St(s,r,o,p),F=Bt(t),{checkHistoryForNewTx:R}=kt(N,I,u,h),H=e.useCallback(t=>{C.stop(),g(t),A(!0)},[C]);e.useEffect(()=>{E.start(),E.setTimerSeconds(parseInt(a))},[]),e.useEffect(()=>{!async function(){if(!l&&m&&C.seconds>0){f(!1);const t=await R();t&&(t.block&&C.setTimerSeconds(Math.floor((1e3*t.block.timestamp-C.started)/1e3)),t.transaction&&H(t.transaction.hash))}else l&&f(!0)}()},[R,H,m,C,l]),e.useEffect(()=>{d||(M(n,t),w(!0))},[M,t,d,n]),e.useEffect(()=>{if(n&&B>=k){if(d?.tokenSymbol&&B>k&&y)return void H();E.isActive&&(E.stop(),C.start())}},[B,H,y,k,E,C,d?.tokenSymbol,n]),e.useEffect(()=>{d&&x&&B>=k&&H(x.hash)},[B,H,k,x,d]);const O=F&&S&&F.mul(S);return{sourceNetwork:t,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=vt;
@@ -1 +1 @@
1
- import{jsx as t}from"react/jsx-runtime";import{createContext as e,useState as r,useCallback as s,useMemo as i,useEffect as n,useContext 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 u}from"../utils/config.js";import"@avalabs/core-utils-sdk";import"ethers";const l=e({});function C(){return c(l)}function f({children:e}){const[c,C]=r(),[f,T]=r({}),m=s((t=>{if(u(f,t)&&t.config){const{critical:e,criticalBitcoin:r}=t.config;C({critical:e,criticalBitcoin:r})}T(t)}),[f]),[p,g]=r(),[B,H]=r(o.ETHEREUM),[I,N]=r(o.AVALANCHE),[d,h]=r(),R=i((()=>c?E(o.ETHEREUM,c):{}),[c]),b=i((()=>{const t={};for(const e in R){const r=R[e];r.assetType===a.ERC20&&(t[e]=r)}return t}),[R]),j=i((()=>c?E(o.BITCOIN,c):{}),[c]),y=i((()=>c?E(o.AVALANCHE,c):{}),[c]),L=i((()=>{if(p)return R[p]||j[p]||y[p]}),[y,j,p,R]),O=i((()=>B===o.AVALANCHE?y:B===o.BITCOIN?j:R),[y,j,B,R]);n((()=>{const t=Object.keys(O);p&&t.includes(p)||g(1===t.length?t[0]:void 0)}),[p,O]);const V=i((()=>{if(B===o.AVALANCHE){if(L?.assetType===a.ERC20)return[o.ETHEREUM];if(L?.assetType===a.BTC)return[o.BITCOIN]}else if(B===o.ETHEREUM||B===o.BITCOIN)return[o.AVALANCHE];return[]}),[B,L]);n((()=>{V.includes(I)||N(V[0])}),[B,I,V]),n((()=>{B===o.BITCOIN||B===o.ETHEREUM?N(o.AVALANCHE):B===o.AVALANCHE&&(L?.assetType===a.ERC20?N(o.ETHEREUM):L?.assetType===a.BTC&&N(o.BITCOIN))}),[B,L]);const k={sourceAssets:O,ethereumAssets:R,bitcoinAssets:j,ethereumWrappedAssets:b,avalancheAssets:y,bridgeConfig:f,setBridgeConfig:m,criticalConfig:c,currentAsset:p,currentAssetData:L,setCurrentAsset:g,currentBlockchain:B,setCurrentBlockchain:H,targetBlockchain:I,transactionDetails:d,setTransactionDetails:h,targetChains:V};return t(l.Provider,{value:k,children:t(A,{children:e})})}export{f as BridgeSDKProvider,C as useBridgeSDK};
1
+ import{jsx as t}from"react/jsx-runtime";import{createContext as e,useState as r,useCallback as s,useMemo as i,useEffect as n,useContext 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 u}from"../utils/config.js";import"@avalabs/core-utils-sdk";import"ethers";const l=e({});function C(){return c(l)}function f({children:e}){const[c,C]=r(),[f,T]=r({}),m=s(t=>{if(u(f,t)&&t.config){const{critical:e,criticalBitcoin:r}=t.config;C({critical:e,criticalBitcoin:r})}T(t)},[f]),[p,g]=r(),[B,H]=r(o.ETHEREUM),[I,N]=r(o.AVALANCHE),[d,h]=r(),R=i(()=>c?E(o.ETHEREUM,c):{},[c]),b=i(()=>{const t={};for(const e in R){const r=R[e];r.assetType===a.ERC20&&(t[e]=r)}return t},[R]),j=i(()=>c?E(o.BITCOIN,c):{},[c]),y=i(()=>c?E(o.AVALANCHE,c):{},[c]),L=i(()=>{if(p)return R[p]||j[p]||y[p]},[y,j,p,R]),O=i(()=>B===o.AVALANCHE?y:B===o.BITCOIN?j:R,[y,j,B,R]);n(()=>{const t=Object.keys(O);p&&t.includes(p)||g(1===t.length?t[0]:void 0)},[p,O]);const V=i(()=>{if(B===o.AVALANCHE){if(L?.assetType===a.ERC20)return[o.ETHEREUM];if(L?.assetType===a.BTC)return[o.BITCOIN]}else if(B===o.ETHEREUM||B===o.BITCOIN)return[o.AVALANCHE];return[]},[B,L]);n(()=>{V.includes(I)||N(V[0])},[B,I,V]),n(()=>{B===o.BITCOIN||B===o.ETHEREUM?N(o.AVALANCHE):B===o.AVALANCHE&&(L?.assetType===a.ERC20?N(o.ETHEREUM):L?.assetType===a.BTC&&N(o.BITCOIN))},[B,L]);const k={sourceAssets:O,ethereumAssets:R,bitcoinAssets:j,ethereumWrappedAssets:b,avalancheAssets:y,bridgeConfig:f,setBridgeConfig:m,criticalConfig:c,currentAsset:p,currentAssetData:L,setCurrentAsset:g,currentBlockchain:B,setCurrentBlockchain:H,targetBlockchain:I,transactionDetails:d,setTransactionDetails:h,targetChains:V};return t(l.Provider,{value:k,children:t(A,{children:e})})}export{f as BridgeSDKProvider,C as useBridgeSDK};
@@ -1 +1 @@
1
- import{jsx as r}from"react/jsx-runtime";import{createContext as o,useState as t,useEffect as n,useContext as e}from"react";import{loadTokenInfo as i}from"../utils/loadTokenInfo.js";const c={},a=o(c),m=({children:o})=>{const[e,c]=t();return n((()=>{!async function(){const r=await i();c(r)}()}),[]),r(a.Provider,{value:e,children:o})};function s(){return e(a)}export{m as TokenInfoProvider,c as initalState,s as useTokenInfoContext};
1
+ import{jsx as r}from"react/jsx-runtime";import{createContext as o,useState as t,useEffect as n,useContext as e}from"react";import{loadTokenInfo as i}from"../utils/loadTokenInfo.js";const c={},a=o(c),m=({children:o})=>{const[e,c]=t();return n(()=>{!async function(){const r=await i();c(r)}()},[]),r(a.Provider,{value:e,children:o})};function s(){return e(a)}export{m as TokenInfoProvider,c as initalState,s as useTokenInfoContext};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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{VsCurrencyType as m,simplePrice as a,getBasicCoingeckoHttp as f}from"@avalabs/core-coingecko-sdk";function p(p,u=m.USD){const{ethereumAssets:d}=c(),l=n(),[g,k]=o(s),b=r((async o=>{try{const r=await a(f(),{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};
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{VsCurrencyType as m,simplePrice as a,getBasicCoingeckoHttp as f}from"@avalabs/core-coingecko-sdk";function p(p,u=m.USD){const{ethereumAssets:d}=c(),l=n(),[g,k]=o(s),b=r(async o=>{try{const r=await a(f(),{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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +1 @@
1
- import{useState as t,useCallback as o}from"react";import{useBridgeSDK as r}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}=r(),{config:c}=n(),[f,p]=t(s.INITIAL),[u,l]=t("");return{transferAsset:o((function({fromAccount:t,amount:o,feeRate:r}){if(c&&a===i.BITCOIN)return e({fromAccount:t,amount:o,feeRate:r,config:c,onStatusChange:p,onTxHashChange:l,signAndSendBTC:m})}),[c,a,m]),status:f,txHash:u}}export{m as useTransferAssetBTC};
1
+ import{useState as t,useCallback as o}from"react";import{useBridgeSDK as r}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}=r(),{config:c}=n(),[f,p]=t(s.INITIAL),[u,l]=t("");return{transferAsset:o(function({fromAccount:t,amount:o,feeRate:r}){if(c&&a===i.BITCOIN)return e({fromAccount:t,amount:o,feeRate:r,config:c,onStatusChange:p,onTxHashChange:l,signAndSendBTC:m})},[c,a,m]),status:f,txHash:u}}export{m as useTransferAssetBTC};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +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};
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};
@@ -1 +1 @@
1
- import{promiseResolveWithBackoff as r}from"@avalabs/core-utils-sdk";import{getRuntimeConfig as o}from"../runtime/config.js";async function t(){try{const t=await r((()=>fetch(o().tokenInfoUrl)),(()=>!1),0,10);return await t.json()}catch(r){return console.error(r),{}}}export{t as loadTokenInfo};
1
+ import{promiseResolveWithBackoff as r}from"@avalabs/core-utils-sdk";import{getRuntimeConfig as o}from"../runtime/config.js";async function t(){try{const t=await r(()=>fetch(o().tokenInfoUrl),()=>!1,0,10);return await t.json()}catch(r){return console.error(r),{}}}export{t as loadTokenInfo};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avalabs/core-bridge-sdk",
3
- "version": "3.1.0-alpha.60",
3
+ "version": "3.1.0-alpha.62",
4
4
  "license": "Limited Ecosystem License",
5
5
  "private": false,
6
6
  "type": "module",
@@ -43,9 +43,9 @@
43
43
  "ts-jest": "29.1.2"
44
44
  },
45
45
  "dependencies": {
46
- "@avalabs/core-coingecko-sdk": "3.1.0-alpha.60",
47
- "@avalabs/core-utils-sdk": "3.1.0-alpha.60",
48
- "@avalabs/core-wallets-sdk": "3.1.0-alpha.60"
46
+ "@avalabs/core-coingecko-sdk": "3.1.0-alpha.62",
47
+ "@avalabs/core-utils-sdk": "3.1.0-alpha.62",
48
+ "@avalabs/core-wallets-sdk": "3.1.0-alpha.62"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "big.js": "^6.2.1",
@@ -54,5 +54,5 @@
54
54
  "ethers": "^6.7.1",
55
55
  "react": "^17.0.2"
56
56
  },
57
- "gitHead": "9659709ad71ca8f1ee32b490cfb239311111f067"
57
+ "gitHead": "1b35a68401d23f1413810ef9fdf7e9f520c83678"
58
58
  }