New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@avalabs/bridge-unified

Package Overview
Dependencies
Maintainers
1
Versions
188
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@avalabs/bridge-unified - npm Package Compare versions

Comparing version 0.0.0-feat-unified-api-interface-20231129155902 to 0.0.0-feat-unified-api-interface-20231130180001

src/utils/retry-promise.test.ts

2

CHANGELOG.md
# @avalabs/unified-bridge
## 0.0.0-feat-unified-api-interface-20231129155902
## 0.0.0-feat-unified-api-interface-20231130180001

@@ -5,0 +5,0 @@ ### Major Changes

import { merge } from 'lodash';
import { custom, http, createWalletClient, publicActions, encodeFunctionData, decodeEventLog } from 'viem';
var R=(r=>(r.NATIVE="native",r.ERC20="erc20",r))(R||{});var k=(t=>(t.CCTP="cctp",t))(k||{});var S=(r=>(r.PROD="production",r.TEST="test",r))(S||{});var V={test:"https://raw.githubusercontent.com/ava-labs/avalanche-bridge-resources/main/cctp/cctp_config.test.json",production:"https://raw.githubusercontent.com/ava-labs/avalanche-bridge-resources/main/cctp/cctp_config.json"},D=async e=>{try{return await(await fetch(V[e])).json()}catch(t){throw new Error(`Error while fetching CCTP config: ${t.message}`)}},F=e=>{switch(e){case 43114:case 43113:return 1e3;default:return 2e4}};async function _(e){await e.ensureHasConfig();let t=e.config.map(r=>r.chainId);return e.config.reduce((r,s)=>(r[s.chainId]=s.tokens.map(p=>({...p,type:"erc20",destinations:t.reduce((n,o)=>(s.chainId!==o&&(n[o]||(n[o]=[]),n[o]?.push("cctp")),n),{})})),r),{})}var Y=e=>({id:e.chainId,name:e.chainName,nativeCurrency:{decimals:e.networkToken.decimals,symbol:e.networkToken.symbol,name:e.networkToken.name},network:e.chainName,rpcUrls:{default:{http:[e.rpcUrl]},public:{http:[e.rpcUrl]}},...e.utilityAddresses.multicall&&{contracts:{multicall3:{address:e.utilityAddresses.multicall}}}}),T=({chain:e,provider:t})=>{let r=Y(e),s=t?custom(t):http(e.rpcUrl,{batch:!0,retryCount:0});return createWalletClient({chain:r,transport:s}).extend(publicActions)};var h=[{inputs:[{internalType:"address",name:"circleTokenMessenger_",type:"address"},{internalType:"address",name:"burnToken_",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"AlreadyAdmin",type:"error"},{inputs:[],name:"AlreadyFeeCollector",type:"error"},{inputs:[],name:"AlreadySupportedBurnToken",type:"error"},{inputs:[],name:"AmountLessThanFee",type:"error"},{inputs:[],name:"BalanceNotIncreased",type:"error"},{inputs:[],name:"CannotRemoveLastAdmin",type:"error"},{inputs:[],name:"FeePercentageGreaterThanMax",type:"error"},{inputs:[],name:"InvalidAdminAddress",type:"error"},{inputs:[],name:"InvalidFeeCollector",type:"error"},{inputs:[],name:"InvalidMintRecipientAddress",type:"error"},{inputs:[],name:"InvalidTokenAddress",type:"error"},{inputs:[],name:"InvalidTokenMessengerAddress",type:"error"},{inputs:[],name:"MaxFeeLessThanMinFee",type:"error"},{inputs:[],name:"NotAdmin",type:"error"},{inputs:[],name:"NotFeeCollector",type:"error"},{inputs:[],name:"UnSupportedBurnToken",type:"error"},{inputs:[],name:"UnsupportedDomain",type:"error"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"admin",type:"address"}],name:"AdminAdded",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"admin",type:"address"}],name:"AdminRemoved",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"token",type:"address"}],name:"BurnTokenAdded",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"token",type:"address"}],name:"BurnTokenRemoved",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"feeCollector",type:"address"}],name:"FeeCollectorAdded",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"feeCollector",type:"address"}],name:"FeeCollectorRemoved",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint32",name:"domain",type:"uint32"},{components:[{internalType:"uint256",name:"maxFee",type:"uint256"},{internalType:"uint256",name:"minFee",type:"uint256"},{internalType:"uint32",name:"feePercentage",type:"uint32"},{internalType:"uint256",name:"txnFee",type:"uint256"},{internalType:"bool",name:"supported",type:"bool"}],indexed:!1,internalType:"struct FeeCalculator.FeeConfiguration",name:"feeConfiguration",type:"tuple"}],name:"FeeConfigurationUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint64",name:"nonce",type:"uint64"},{indexed:!1,internalType:"address",name:"burnToken",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!1,internalType:"address",name:"depositor",type:"address"},{indexed:!1,internalType:"address",name:"mintRecipient",type:"address"},{indexed:!1,internalType:"uint32",name:"destinationDomain",type:"uint32"},{indexed:!1,internalType:"uint256",name:"totalFee",type:"uint256"}],name:"TransferTokens",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"addAdmin",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"feeCollector",type:"address"}],name:"addFeeCollector",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"addSupportedBurnToken",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint32",name:"destinationDomain",type:"uint32"}],name:"calculateFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"circleTokenMessenger",outputs:[{internalType:"contract ICircleTokenMessenger",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"circleTokenMessengerAddress",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"collectFees",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"getFeeAmounts",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"}],name:"getFeeConfiguration",outputs:[{components:[{internalType:"uint256",name:"maxFee",type:"uint256"},{internalType:"uint256",name:"minFee",type:"uint256"},{internalType:"uint32",name:"feePercentage",type:"uint32"},{internalType:"uint256",name:"txnFee",type:"uint256"},{internalType:"bool",name:"supported",type:"bool"}],internalType:"struct FeeCalculator.FeeConfiguration",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"}],name:"getFeePercentage",outputs:[{internalType:"uint32",name:"",type:"uint32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"}],name:"getMaxFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"}],name:"getMinFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"}],name:"getTxnFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"isAdmin",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"isFeeCollector",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"isSupportedBurnToken",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"}],name:"isSupportedDomain",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"removeAdmin",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"feeCollector",type:"address"}],name:"removeFeeCollector",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"removeSupportedBurnToken",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"},{components:[{internalType:"uint256",name:"maxFee",type:"uint256"},{internalType:"uint256",name:"minFee",type:"uint256"},{internalType:"uint32",name:"feePercentage",type:"uint32"},{internalType:"uint256",name:"txnFee",type:"uint256"},{internalType:"bool",name:"supported",type:"bool"}],internalType:"struct FeeCalculator.FeeConfiguration",name:"feeConfiguration",type:"tuple"}],name:"setFeeConfiguration",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"supportedBurnTokens",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint32",name:"destinationDomain",type:"uint32"},{internalType:"address",name:"mintRecipient",type:"address"},{internalType:"address",name:"burnToken",type:"address"}],name:"transferTokens",outputs:[{internalType:"uint64",name:"nonce",type:"uint64"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"}];var x=({sourceChain:e,targetChain:t,amount:r,asset:s},p)=>{if(e.chainId===t.chainId)throw new Error("Source and target chains are the same");if(r<=0n)throw new Error("Amount must be greater than zero");let n=p.find(i=>i.chainId===e.chainId);if(!n)throw new Error(`Not supported on source chain "${e.chainId}"`);let o=p.find(i=>i.chainId===t.chainId);if(!o)throw new Error(`Not supported on target chain "${t.chainId}"`);let u=n.tokens.find(i=>i.symbol===s.symbol),c=o.tokens.find(i=>i.symbol===s.symbol);if(!u||!c)throw new Error(`Not supported asset "${s.symbol}"`);return {sourceChainData:n,targetChainData:o,burnToken:u,mintToken:c}};async function H(e,t){await e.ensureHasConfig();let{sourceChain:r,targetChain:s,asset:p,amount:n,provider:o}=t,{sourceChainData:u,targetChainData:c,burnToken:i}=x({sourceChain:r,targetChain:s,asset:p,amount:n},e.config),d=await T({chain:r,provider:o}).readContract({address:u.tokenRouterAddress,abi:h,functionName:"calculateFee",args:[n,c.domain]});return {[i.address]:d}}var B=[{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"}];var Z=async(e,t)=>{let{sourceChain:r,targetChain:s,asset:p,amount:n,addressC:o,sourceProvider:u}=t,{sourceChainData:c,targetChainData:i,burnToken:a}=x({sourceChain:r,targetChain:s,asset:p,amount:n},e.config),d=T({chain:r,provider:u});if(await d.readContract({address:a.address,abi:B,functionName:"allowance",args:[o,c.tokenRouterAddress]})<n)if(u.sign){let m=encodeFunctionData({abi:B,functionName:"approve",args:[c.tokenRouterAddress,n]}),l=await u.sign({from:o,to:a.address,data:m}),g=await d.sendRawTransaction({serializedTransaction:l});await d.waitForTransactionReceipt({hash:g,pollingInterval:1e3});}else {let{request:m}=await d.simulateContract({account:o,address:a.address,abi:B,functionName:"approve",args:[c.tokenRouterAddress,n]}),l=await d.writeContract(m);await d.waitForTransactionReceipt({hash:l,pollingInterval:1e3});}if(u.sign){let m=encodeFunctionData({abi:h,functionName:"transferTokens",args:[n,i.domain,o,a.address]}),l=await u.sign({from:o,to:c.tokenRouterAddress,data:m});return d.sendRawTransaction({serializedTransaction:l})}else {let{request:m}=await d.simulateContract({account:o,address:c.tokenRouterAddress,abi:h,functionName:"transferTokens",args:[n,i.domain,o,a.address]});return d.writeContract(m)}},ee=async e=>{try{return await e.getBlockNumber()}catch{return}};async function L(e,t,r){await e.ensureHasConfig();let{minimumConfirmations:s}=e.config.find(d=>d.chainId===t.sourceChain.chainId)??{},{minimumConfirmations:p}=e.config.find(d=>d.chainId===t.targetChain.chainId)??{};if(!s||!p)throw new Error("BridgeTransfer: unable to determine required confirmation counts for the given chains.");let n=await e.getFees({...t,provider:t.sourceProvider}),o=(t.asset.address&&n[t.asset.address])??0n,u=await Z(e,t),c=Date.now(),i=T({chain:t.targetChain,provider:t.targetProvider}),a=await ee(i);return {type:e.type,environment:r,addressC:t.addressC,addressBtc:t.addressBtc,amount:t.amount,symbol:t.asset.symbol,bridgeFee:o,sourceChain:t.sourceChain,sourceStartedAt:c,sourceTxHash:u,sourceConfirmationCount:0,requiredSourceConfirmationCount:s,targetChain:t.targetChain,targetConfirmationCount:0,requiredTargetConfirmationCount:p,startBlockNumber:a}}async function U(e){if(!e.config&&(await e.updateConfig(),!e.config))throw new Error("Config is not available")}var P=(e,t)=>e.gasPrice&&BigInt(e.gasPrice*t.gasUsed);var M=async e=>new Promise(t=>{setTimeout(t,e);});var I=({promise:e,delay:t})=>{let r=!1,s=!1,p=0,n,o,u=a=>{n&&r&&(r=!1,n(a));},c=()=>{s=!0,o&&r&&(r=!1,o("cancelled"));};return {result:new Promise((a,d)=>{r=!0,n=a,o=d;let y=async()=>{if(!(!r||s)){try{await e(u),await M(t);}catch(m){console.error(m.message),p+=1,await M(2**p*t);}await y();}};y();}),cancel:c}};var j=1e3*60*60*3,q=1024n,f=(e,t,r)=>{Object.assign(e,Object.fromEntries(Object.entries(t).filter(([,s])=>s!==void 0))),r({...e});},te=async(e,t)=>{let{sourceProvider:r,targetProvider:s,updateListener:p,bridgeTransfer:n}=t,o=T({chain:n.sourceChain,provider:r}),u=e.find(y=>y.chainId===n.sourceChain.chainId),c=T({chain:n.targetChain,provider:s}),i=e.find(y=>y.chainId===n.targetChain.chainId),a={...n};if(!u)throw new Error(`BridgeTransfer: unknown source chain "${n.sourceChain.chainId}"`);if(!i)throw new Error(`BridgeTransfer: unknown target chain "${n.targetChain.chainId}"`);return I({promise:async y=>{if(a.completedAt||a.metadata?.nonce)return y(a);if(a.sourceStartedAt+j<=Date.now())return f(a,{completedAt:Date.now(),error:"timeout"},p),y(a);let m=await o.getTransactionReceipt({hash:a.sourceTxHash});if(!a.sourceNetworkFee){let b=await o.getTransaction({hash:a.sourceTxHash}),A=P(b,m);A&&f(a,{sourceNetworkFee:A},p);}if(m.status==="reverted")return f(a,{completedAt:Date.now(),error:`source transaction "${a.sourceTxHash}" reverted`},p),y(a);let l=await o.getTransactionConfirmations({hash:a.sourceTxHash}),g=l>a.sourceConfirmationCount,v=l>=a.requiredSourceConfirmationCount;if(g){let b={};b.sourceConfirmationCount=Number(l),v||(b.startBlockNumber=await c.getBlockNumber()),f(a,b,p);}if(!v)return;a.startBlockNumber||f(a,{startBlockNumber:await c.getBlockNumber()},p);let C=m.logs.find(b=>b.address===u.tokenRouterAddress?decodeEventLog({abi:h,...b}).eventName==="TransferTokens":!1);if(!C)throw new Error(`BridgeTransfer: can't find a TransferTokens event in source transaction "${a.sourceTxHash}"`);let w=decodeEventLog({abi:h,eventName:"TransferTokens",...C}).args.nonce;return f(a,{targetStartedAt:Date.now(),metadata:{nonce:w}},p),y(a)},delay:F(u.chainId)})},ne=async(e,t)=>{let{targetProvider:r,updateListener:s,bridgeTransfer:p}=t,n={...p};if(!p.completedAt&&!p.metadata?.nonce)throw new Error("BridgeTransfer: nonce is missing");if(!p.startBlockNumber)throw new Error("BridgeTransfer: startBlockNumber is missing");let o=T({chain:p.targetChain,provider:r}),u=e.find(i=>i.chainId===p.targetChain.chainId);if(!u)throw new Error(`BridgeTransfer: unknown target chain "${p.targetChain.chainId}"`);return I({promise:async i=>{if(n.completedAt)return i(n);if(n.sourceStartedAt+j<=Date.now())return f(n,{completedAt:Date.now(),error:"timeout"},s),i(n);if(!n.targetTxHash){let l=await o.getBlockNumber(),g=(n.startBlockNumber??0n)-q,v=g>=0n?g:"earliest",C=(n.startBlockNumber??0n)+q,E=C<l?C:"latest",w=await o.getLogs({address:u.messageTransmitterAddress,event:{name:"MessageReceived",type:"event",inputs:[{indexed:!0,internalType:"address",name:"caller",type:"address"},{indexed:!1,internalType:"uint32",name:"sourceDomain",type:"uint32"},{indexed:!0,internalType:"uint64",name:"nonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"sender",type:"bytes32"},{indexed:!1,internalType:"bytes",name:"messageBody",type:"bytes"}]},args:{nonce:n.metadata.nonce},fromBlock:v,toBlock:E});if(w[0]?.transactionHash)f(n,{targetTxHash:w[0].transactionHash},s);else return}let a=await o.getTransactionReceipt({hash:n.targetTxHash});if(!n.targetNetworkFee){let l=await o.getTransaction({hash:n.targetTxHash}),g=P(l,a);g&&f(n,{targetNetworkFee:g},s);}if(a.status==="reverted")return f(n,{completedAt:Date.now(),error:`target transaction "${n.targetTxHash}" reverted`},s),i(n);let d=await o.getTransactionConfirmations({hash:n.targetTxHash}),y=d>n.targetConfirmationCount,m=d>=n.requiredTargetConfirmationCount;if(y&&f(n,{targetConfirmationCount:Number(d)},s),!!m)return f(n,{completedAt:Date.now()},s),i(n)},delay:F(u.chainId)})};function K(e,t){let r,s=()=>{r?.();};return {result:(async()=>{await e.ensureHasConfig();let{sourceProvider:n,targetProvider:o,updateListener:u,bridgeTransfer:c}=t,{result:i,cancel:a}=await te(e.config,{sourceProvider:n,targetProvider:o,updateListener:u,bridgeTransfer:c});r=a;let d=await i,{result:y,cancel:m}=await ne(e.config,{sourceProvider:n,targetProvider:o,updateListener:u,bridgeTransfer:d});return r=m,y})(),cancel:s}}var z=e=>({type:"cctp",config:null,updateConfig:async function(){this.config=await D(e);},ensureHasConfig:async function(){return U(this)},getAssets:async function(){return _(this)},getFees:async function(t){return H(this,t)},transferAsset:async function(t){return L(this,t,e)},trackTransfer:function(t){return K(this,t)}});var re=new Map([["cctp",z]]),G=(e,t)=>new Map([...re].filter(([r])=>!t?.includes(r)).map(([r,s])=>[r,s(e)])),N=(e,t,r)=>{let s=t.destinations[r]?.find(p=>e.has(p));if(!s)throw new Error(`No enabled implementation found for transfering ${t.symbol} to ${r}`);return {type:s,bridge:e.get(s)}};var ct=({environment:e,disabledBridgeTypes:t})=>{let r=G(e,t),s=async()=>Promise.all(Array.from(r).map(([,i])=>i.updateConfig()));return {bridges:r,init:async()=>{await s();},updateConfigs:s,getAssets:async()=>(await Promise.all(Array.from(r).map(([,a])=>a.getAssets()))).flat().reduce(merge),getFees:async i=>{let{bridge:a}=N(r,i.asset,i.targetChain.chainId);return a.getFees(i)},transferAsset:async i=>{let{bridge:a}=N(r,i.asset,i.targetChain.chainId);return a.transferAsset(i)},trackTransfer:i=>{let a=r.get(i.bridgeTransfer.type);if(!a)throw new Error(`No enabled implementation found for tracking ${i.bridgeTransfer.type} transactions.`);return a.trackTransfer(i)}}};
var R=(r=>(r.NATIVE="native",r.ERC20="erc20",r))(R||{});var k=(t=>(t.CCTP="cctp",t))(k||{});var S=(r=>(r.PROD="production",r.TEST="test",r))(S||{});var V={test:"https://raw.githubusercontent.com/ava-labs/avalanche-bridge-resources/main/cctp/cctp_config.test.json",production:"https://raw.githubusercontent.com/ava-labs/avalanche-bridge-resources/main/cctp/cctp_config.json"},D=async e=>{try{return await(await fetch(V[e])).json()}catch(t){throw new Error(`Error while fetching CCTP config: ${t.message}`)}},F=e=>{switch(e){case 43114:case 43113:return 1e3;default:return 2e4}};async function _(e){await e.ensureHasConfig();let t=e.config.map(r=>r.chainId);return e.config.reduce((r,s)=>(r[s.chainId]=s.tokens.map(p=>({...p,type:"erc20",destinations:t.reduce((n,o)=>(s.chainId!==o&&(n[o]||(n[o]=[]),n[o]?.push("cctp")),n),{})})),r),{})}var Y=e=>({id:e.chainId,name:e.chainName,nativeCurrency:{decimals:e.networkToken.decimals,symbol:e.networkToken.symbol,name:e.networkToken.name},network:e.chainName,rpcUrls:{default:{http:[e.rpcUrl]},public:{http:[e.rpcUrl]}},...e.utilityAddresses.multicall&&{contracts:{multicall3:{address:e.utilityAddresses.multicall}}}}),T=({chain:e,provider:t})=>{let r=Y(e),s=t?custom(t):http(e.rpcUrl,{batch:!0,retryCount:0});return createWalletClient({chain:r,transport:s}).extend(publicActions)};var h=[{inputs:[{internalType:"address",name:"circleTokenMessenger_",type:"address"},{internalType:"address",name:"burnToken_",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"AlreadyAdmin",type:"error"},{inputs:[],name:"AlreadyFeeCollector",type:"error"},{inputs:[],name:"AlreadySupportedBurnToken",type:"error"},{inputs:[],name:"AmountLessThanFee",type:"error"},{inputs:[],name:"BalanceNotIncreased",type:"error"},{inputs:[],name:"CannotRemoveLastAdmin",type:"error"},{inputs:[],name:"FeePercentageGreaterThanMax",type:"error"},{inputs:[],name:"InvalidAdminAddress",type:"error"},{inputs:[],name:"InvalidFeeCollector",type:"error"},{inputs:[],name:"InvalidMintRecipientAddress",type:"error"},{inputs:[],name:"InvalidTokenAddress",type:"error"},{inputs:[],name:"InvalidTokenMessengerAddress",type:"error"},{inputs:[],name:"MaxFeeLessThanMinFee",type:"error"},{inputs:[],name:"NotAdmin",type:"error"},{inputs:[],name:"NotFeeCollector",type:"error"},{inputs:[],name:"UnSupportedBurnToken",type:"error"},{inputs:[],name:"UnsupportedDomain",type:"error"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"admin",type:"address"}],name:"AdminAdded",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"admin",type:"address"}],name:"AdminRemoved",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"token",type:"address"}],name:"BurnTokenAdded",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"token",type:"address"}],name:"BurnTokenRemoved",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"feeCollector",type:"address"}],name:"FeeCollectorAdded",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"feeCollector",type:"address"}],name:"FeeCollectorRemoved",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint32",name:"domain",type:"uint32"},{components:[{internalType:"uint256",name:"maxFee",type:"uint256"},{internalType:"uint256",name:"minFee",type:"uint256"},{internalType:"uint32",name:"feePercentage",type:"uint32"},{internalType:"uint256",name:"txnFee",type:"uint256"},{internalType:"bool",name:"supported",type:"bool"}],indexed:!1,internalType:"struct FeeCalculator.FeeConfiguration",name:"feeConfiguration",type:"tuple"}],name:"FeeConfigurationUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint64",name:"nonce",type:"uint64"},{indexed:!1,internalType:"address",name:"burnToken",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"},{indexed:!1,internalType:"address",name:"depositor",type:"address"},{indexed:!1,internalType:"address",name:"mintRecipient",type:"address"},{indexed:!1,internalType:"uint32",name:"destinationDomain",type:"uint32"},{indexed:!1,internalType:"uint256",name:"totalFee",type:"uint256"}],name:"TransferTokens",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"addAdmin",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"feeCollector",type:"address"}],name:"addFeeCollector",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"addSupportedBurnToken",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint32",name:"destinationDomain",type:"uint32"}],name:"calculateFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"circleTokenMessenger",outputs:[{internalType:"contract ICircleTokenMessenger",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"circleTokenMessengerAddress",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"collectFees",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"getFeeAmounts",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"}],name:"getFeeConfiguration",outputs:[{components:[{internalType:"uint256",name:"maxFee",type:"uint256"},{internalType:"uint256",name:"minFee",type:"uint256"},{internalType:"uint32",name:"feePercentage",type:"uint32"},{internalType:"uint256",name:"txnFee",type:"uint256"},{internalType:"bool",name:"supported",type:"bool"}],internalType:"struct FeeCalculator.FeeConfiguration",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"}],name:"getFeePercentage",outputs:[{internalType:"uint32",name:"",type:"uint32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"}],name:"getMaxFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"}],name:"getMinFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"}],name:"getTxnFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"isAdmin",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"isFeeCollector",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"isSupportedBurnToken",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"}],name:"isSupportedDomain",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"removeAdmin",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"feeCollector",type:"address"}],name:"removeFeeCollector",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"removeSupportedBurnToken",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint32",name:"domain",type:"uint32"},{components:[{internalType:"uint256",name:"maxFee",type:"uint256"},{internalType:"uint256",name:"minFee",type:"uint256"},{internalType:"uint32",name:"feePercentage",type:"uint32"},{internalType:"uint256",name:"txnFee",type:"uint256"},{internalType:"bool",name:"supported",type:"bool"}],internalType:"struct FeeCalculator.FeeConfiguration",name:"feeConfiguration",type:"tuple"}],name:"setFeeConfiguration",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"supportedBurnTokens",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint32",name:"destinationDomain",type:"uint32"},{internalType:"address",name:"mintRecipient",type:"address"},{internalType:"address",name:"burnToken",type:"address"}],name:"transferTokens",outputs:[{internalType:"uint64",name:"nonce",type:"uint64"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"}];var x=({sourceChain:e,targetChain:t,amount:r,asset:s},p)=>{if(e.chainId===t.chainId)throw new Error("Source and target chains are the same");if(r<=0n)throw new Error("Amount must be greater than zero");let n=p.find(i=>i.chainId===e.chainId);if(!n)throw new Error(`Not supported on source chain "${e.chainId}"`);let o=p.find(i=>i.chainId===t.chainId);if(!o)throw new Error(`Not supported on target chain "${t.chainId}"`);let u=n.tokens.find(i=>i.symbol===s.symbol),c=o.tokens.find(i=>i.symbol===s.symbol);if(!u||!c)throw new Error(`Not supported asset "${s.symbol}"`);return {sourceChainData:n,targetChainData:o,burnToken:u,mintToken:c}};async function H(e,t){await e.ensureHasConfig();let{sourceChain:r,targetChain:s,asset:p,amount:n,provider:o}=t,{sourceChainData:u,targetChainData:c,burnToken:i}=x({sourceChain:r,targetChain:s,asset:p,amount:n},e.config),d=await T({chain:r,provider:o}).readContract({address:u.tokenRouterAddress,abi:h,functionName:"calculateFee",args:[n,c.domain]});return {[i.address]:d}}var B=[{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"}];var Z=async(e,t)=>{let{sourceChain:r,targetChain:s,asset:p,amount:n,addressC:o,sourceProvider:u}=t,{sourceChainData:c,targetChainData:i,burnToken:a}=x({sourceChain:r,targetChain:s,asset:p,amount:n},e.config),d=T({chain:r,provider:u});if(await d.readContract({address:a.address,abi:B,functionName:"allowance",args:[o,c.tokenRouterAddress]})<n)if(u.sign){let m=encodeFunctionData({abi:B,functionName:"approve",args:[c.tokenRouterAddress,n]}),l=await u.sign({from:o,to:a.address,data:m}),g=await d.sendRawTransaction({serializedTransaction:l});await d.waitForTransactionReceipt({hash:g,pollingInterval:1e3});}else {let{request:m}=await d.simulateContract({account:o,address:a.address,abi:B,functionName:"approve",args:[c.tokenRouterAddress,n]}),l=await d.writeContract(m);await d.waitForTransactionReceipt({hash:l,pollingInterval:1e3});}if(u.sign){let m=encodeFunctionData({abi:h,functionName:"transferTokens",args:[n,i.domain,o,a.address]}),l=await u.sign({from:o,to:c.tokenRouterAddress,data:m});return d.sendRawTransaction({serializedTransaction:l})}else {let{request:m}=await d.simulateContract({account:o,address:c.tokenRouterAddress,abi:h,functionName:"transferTokens",args:[n,i.domain,o,a.address]});return d.writeContract(m)}},ee=async e=>{try{return await e.getBlockNumber()}catch{return}};async function L(e,t,r){await e.ensureHasConfig();let{minimumConfirmations:s}=e.config.find(d=>d.chainId===t.sourceChain.chainId)??{},{minimumConfirmations:p}=e.config.find(d=>d.chainId===t.targetChain.chainId)??{};if(!s||!p)throw new Error("BridgeTransfer: unable to determine required confirmation counts for the given chains.");let n=await e.getFees({...t,provider:t.sourceProvider}),o=(t.asset.address&&n[t.asset.address])??0n,u=await Z(e,t),c=Date.now(),i=T({chain:t.targetChain,provider:t.targetProvider}),a=await ee(i);return {type:e.type,environment:r,addressC:t.addressC,addressBtc:t.addressBtc,amount:t.amount,symbol:t.asset.symbol,bridgeFee:o,sourceChain:t.sourceChain,sourceStartedAt:c,sourceTxHash:u,sourceConfirmationCount:0,requiredSourceConfirmationCount:s,targetChain:t.targetChain,targetConfirmationCount:0,requiredTargetConfirmationCount:p,startBlockNumber:a}}async function U(e){if(!e.config&&(await e.updateConfig(),!e.config))throw new Error("Config is not available")}var P=(e,t)=>e.gasPrice&&BigInt(e.gasPrice*t.gasUsed);var M=async e=>new Promise(t=>{setTimeout(t,e);});var I=({promise:e,delay:t})=>{let r=!1,s=!1,p=0,n,o,u=a=>{n&&r&&(r=!1,n(a));},c=()=>{s=!0,o&&r&&(r=!1,o("cancelled"));};return {result:new Promise((a,d)=>{r=!0,n=a,o=d;let y=async()=>{if(!(!r||s)){try{if(await e(u),!r||s)return;await M(t);}catch(m){console.error(m.message),p+=1,await M(2**p*t);}await y();}};y();}),cancel:c}};var j=1e3*60*60*3,q=1024n,f=(e,t,r)=>{Object.assign(e,Object.fromEntries(Object.entries(t).filter(([,s])=>s!==void 0))),r({...e});},te=async(e,t)=>{let{sourceProvider:r,targetProvider:s,updateListener:p,bridgeTransfer:n}=t,o=T({chain:n.sourceChain,provider:r}),u=e.find(y=>y.chainId===n.sourceChain.chainId),c=T({chain:n.targetChain,provider:s}),i=e.find(y=>y.chainId===n.targetChain.chainId),a={...n};if(!u)throw new Error(`BridgeTransfer: unknown source chain "${n.sourceChain.chainId}"`);if(!i)throw new Error(`BridgeTransfer: unknown target chain "${n.targetChain.chainId}"`);return I({promise:async y=>{if(a.completedAt||a.metadata?.nonce)return y(a);if(a.sourceStartedAt+j<=Date.now())return f(a,{completedAt:Date.now(),error:"timeout"},p),y(a);let m=await o.getTransactionReceipt({hash:a.sourceTxHash});if(!a.sourceNetworkFee){let b=await o.getTransaction({hash:a.sourceTxHash}),A=P(b,m);A&&f(a,{sourceNetworkFee:A},p);}if(m.status==="reverted")return f(a,{completedAt:Date.now(),error:`source transaction "${a.sourceTxHash}" reverted`},p),y(a);let l=await o.getTransactionConfirmations({hash:a.sourceTxHash}),g=l>a.sourceConfirmationCount,v=l>=a.requiredSourceConfirmationCount;if(g){let b={};b.sourceConfirmationCount=Number(l),v||(b.startBlockNumber=await c.getBlockNumber()),f(a,b,p);}if(!v)return;a.startBlockNumber||f(a,{startBlockNumber:await c.getBlockNumber()},p);let C=m.logs.find(b=>b.address===u.tokenRouterAddress?decodeEventLog({abi:h,...b}).eventName==="TransferTokens":!1);if(!C)throw new Error(`BridgeTransfer: can't find a TransferTokens event in source transaction "${a.sourceTxHash}"`);let w=decodeEventLog({abi:h,eventName:"TransferTokens",...C}).args.nonce;return f(a,{targetStartedAt:Date.now(),metadata:{nonce:w}},p),y(a)},delay:F(u.chainId)})},ne=async(e,t)=>{let{targetProvider:r,updateListener:s,bridgeTransfer:p}=t,n={...p};if(!p.completedAt&&!p.metadata?.nonce)throw new Error("BridgeTransfer: nonce is missing");if(!p.startBlockNumber)throw new Error("BridgeTransfer: startBlockNumber is missing");let o=T({chain:p.targetChain,provider:r}),u=e.find(i=>i.chainId===p.targetChain.chainId);if(!u)throw new Error(`BridgeTransfer: unknown target chain "${p.targetChain.chainId}"`);return I({promise:async i=>{if(n.completedAt)return i(n);if(n.sourceStartedAt+j<=Date.now())return f(n,{completedAt:Date.now(),error:"timeout"},s),i(n);if(!n.targetTxHash){let l=await o.getBlockNumber(),g=(n.startBlockNumber??0n)-q,v=g>=0n?g:"earliest",C=(n.startBlockNumber??0n)+q,E=C<l?C:"latest",w=await o.getLogs({address:u.messageTransmitterAddress,event:{name:"MessageReceived",type:"event",inputs:[{indexed:!0,internalType:"address",name:"caller",type:"address"},{indexed:!1,internalType:"uint32",name:"sourceDomain",type:"uint32"},{indexed:!0,internalType:"uint64",name:"nonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"sender",type:"bytes32"},{indexed:!1,internalType:"bytes",name:"messageBody",type:"bytes"}]},args:{nonce:n.metadata.nonce},fromBlock:v,toBlock:E});if(w[0]?.transactionHash)f(n,{targetTxHash:w[0].transactionHash},s);else return}let a=await o.getTransactionReceipt({hash:n.targetTxHash});if(!n.targetNetworkFee){let l=await o.getTransaction({hash:n.targetTxHash}),g=P(l,a);g&&f(n,{targetNetworkFee:g},s);}if(a.status==="reverted")return f(n,{completedAt:Date.now(),error:`target transaction "${n.targetTxHash}" reverted`},s),i(n);let d=await o.getTransactionConfirmations({hash:n.targetTxHash}),y=d>n.targetConfirmationCount,m=d>=n.requiredTargetConfirmationCount;if(y&&f(n,{targetConfirmationCount:Number(d)},s),!!m)return f(n,{completedAt:Date.now()},s),i(n)},delay:F(u.chainId)})};function K(e,t){let r,s=()=>{r?.();};return {result:(async()=>{await e.ensureHasConfig();let{sourceProvider:n,targetProvider:o,updateListener:u,bridgeTransfer:c}=t,{result:i,cancel:a}=await te(e.config,{sourceProvider:n,targetProvider:o,updateListener:u,bridgeTransfer:c});r=a;let d=await i,{result:y,cancel:m}=await ne(e.config,{sourceProvider:n,targetProvider:o,updateListener:u,bridgeTransfer:d});return r=m,y})(),cancel:s}}var z=e=>({type:"cctp",config:null,updateConfig:async function(){this.config=await D(e);},ensureHasConfig:async function(){return U(this)},getAssets:async function(){return _(this)},getFees:async function(t){return H(this,t)},transferAsset:async function(t){return L(this,t,e)},trackTransfer:function(t){return K(this,t)}});var re=new Map([["cctp",z]]),G=(e,t)=>new Map([...re].filter(([r])=>!t?.includes(r)).map(([r,s])=>[r,s(e)])),N=(e,t,r)=>{let s=t.destinations[r]?.find(p=>e.has(p));if(!s)throw new Error(`No enabled implementation found for transfering ${t.symbol} to ${r}`);return {type:s,bridge:e.get(s)}};var ct=({environment:e,disabledBridgeTypes:t})=>{let r=G(e,t),s=async()=>Promise.all(Array.from(r).map(([,i])=>i.updateConfig()));return {bridges:r,init:async()=>{await s();},updateConfigs:s,getAssets:async()=>(await Promise.all(Array.from(r).map(([,a])=>a.getAssets()))).flat().reduce(merge),getFees:async i=>{let{bridge:a}=N(r,i.asset,i.targetChain.chainId);return a.getFees(i)},transferAsset:async i=>{let{bridge:a}=N(r,i.asset,i.targetChain.chainId);return a.transferAsset(i)},trackTransfer:i=>{let a=r.get(i.bridgeTransfer.type);if(!a)throw new Error(`No enabled implementation found for tracking ${i.bridgeTransfer.type} transactions.`);return a.trackTransfer(i)}}};

@@ -6,0 +6,0 @@ export { k as BridgeType, S as Environment, R as TokenType, ct as createUnifiedBridgeService };

{
"name": "@avalabs/bridge-unified",
"version": "0.0.0-feat-unified-api-interface-20231129155902",
"version": "0.0.0-feat-unified-api-interface-20231130180001",
"main": "dist/index.js",

@@ -17,4 +17,4 @@ "type": "module",

"tsup": "7.2.0",
"@internal/tsup-config": "0.0.1",
"eslint-config-custom": "0.0.0-feat-unified-api-interface-20231129155902"
"eslint-config-custom": "0.0.0-feat-unified-api-interface-20231130180001",
"@internal/tsup-config": "0.0.1"
},

@@ -21,0 +21,0 @@ "scripts": {

@@ -45,2 +45,7 @@ import { wait } from './wait';

await promise(done);
if (!isRunning || isCancelled) {
return;
}
await wait(delay);

@@ -47,0 +52,0 @@ } catch (err) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc