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-fix-make-source-provider-optio-20240110083249 to 0.0.0-fix-make-source-provider-optio-20240110084136

2

CHANGELOG.md
# @avalabs/unified-bridge
## 0.0.0-fix-make-source-provider-optio-20240110083249
## 0.0.0-fix-make-source-provider-optio-20240110084136

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

@@ -99,3 +99,2 @@ import { Address } from 'viem';

bridgeFee: bigint;
bridgeFeeDecimals: number;
sourceChain: Chain;

@@ -102,0 +101,0 @@ sourceStartedAt: number;

import { custom, http, createWalletClient, publicActions, isAddress, encodeFunctionData, decodeEventLog } from 'viem';
import { mergeWith, isArray } from 'lodash';
var H=(r=>(r.NATIVE="native",r.ERC20="erc20",r))(H||{});var R=(t=>(t.CCTP="cctp",t))(R||{});var V=(r=>(r.PROD="production",r.TEST="test",r))(V||{});var k=(n=>(n[n.BRIDGE_NOT_AVAILABLE=5001]="BRIDGE_NOT_AVAILABLE",n[n.INITIALIZATION_FAILED=5002]="INITIALIZATION_FAILED",n[n.INVALID_PARAMS=5003]="INVALID_PARAMS",n[n.TIMEOUT=5004]="TIMEOUT",n[n.TRANSACTION_REVERTED=5005]="TRANSACTION_REVERTED",n))(k||{}),h=(i=>(i.UNKNOWN="UNKNOWN",i.CONFIG_NOT_AVAILABLE="CONFIG_NOT_AVAILABLE",i.INVALID_PARAMS="INVALID_PARAMS",i.IDENTICAL_CHAINS_PROVIDED="IDENTICAL_CHAINS_PROVIDED",i.INCORRECT_AMOUNT_PROVIDED="INCORRECT_AMOUNT_PROVIDED",i.INCORRECT_ADDRESS_PROVIDED="INCORRECT_ADDRESS_PROVIDED",i.CHAIN_NOT_SUPPORTED="CHAIN_NOT_SUPPORTED",i.ASSET_NOT_SUPPORTED="ASSET_NOT_SUPPORTED",i.CONFIRMATION_COUNT_UNKNOWN="CONFIRMATION_COUNT_UNKNOWN",i))(h||{});var I=class extends Error{constructor(r,s,u){super(r);this.code=s;this.details=u;}};var P=class extends I{constructor(t="UNKNOWN",r){super(t,5001,r),this.name="BridgeUnavailableError";}};var B=class extends I{constructor(t="UNKNOWN",r){super(t,5002,r),this.name="BridgeInitializationError";}};var f=class extends I{constructor(t="INVALID_PARAMS",r){super(t,5003,r),this.name="InvalidParamsError";}};var re={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"},K=async e=>{try{return (await(await fetch(re[e])).json()).map(s=>({...s,chainId:`eip155:${s.chainId}`}))}catch(t){throw new B("CONFIG_NOT_AVAILABLE",`Error while fetching CCTP config: ${t.message}`)}},D=e=>{switch(e){case"eip155:43114":case"eip155: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(u=>({...u,type:"erc20",destinations:t.reduce((n,o)=>(s.chainId!==o&&(n[o]||(n[o]=[]),n[o]?.push("cctp")),n),{})})),r),{})}var ae="^[-a-z0-9]{3,8}$",se="^[-_a-zA-Z0-9]{1,50}$",G=":",ie=e=>{let[t,r]=e.split(G);if(!t||!r)throw new Error("Invalid identifier provided.");if(!new RegExp(ae).test(t))throw new Error("Invalid namespace provided.");if(!new RegExp(se).test(r))throw new Error("Invalid reference provided.");return {namespace:t,reference:r}},oe=({namespace:e,reference:t})=>`${e}${G}${t}`,E={toJSON:ie,toString:oe};var me=e=>{let{reference:t}=E.toJSON(e.chainId);return {id:Number(t),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}}}}},v=({chain:e,provider:t})=>{let r=me(e),s=t?custom(t):http(e.rpcUrl,{batch:!0,retryCount:0});return createWalletClient({chain:r,transport:s}).extend(publicActions)};var N=[{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 _=({sourceChain:e,targetChain:t,amount:r,asset:s},u)=>{if(e.chainId===t.chainId)throw new f("IDENTICAL_CHAINS_PROVIDED");if(r<=0n)throw new f("INCORRECT_AMOUNT_PROVIDED","Amount must be greater than zero");let n=u.find(i=>i.chainId===e.chainId);if(!n)throw new f("CHAIN_NOT_SUPPORTED",`Not supported on source chain "${e.chainId}"`);let o=u.find(i=>i.chainId===t.chainId);if(!o)throw new f("CHAIN_NOT_SUPPORTED",`Not supported on target chain "${t.chainId}"`);let d=n.tokens.find(i=>i.symbol===s.symbol),l=o.tokens.find(i=>i.symbol===s.symbol);if(!d||!l)throw new f("ASSET_NOT_SUPPORTED");return {sourceChainData:n,targetChainData:o,burnToken:d,mintToken:l}};async function W(e,t){await e.ensureHasConfig();let{sourceChain:r,targetChain:s,asset:u,amount:n,provider:o}=t,{sourceChainData:d,targetChainData:l,burnToken:i}=_({sourceChain:r,targetChain:s,asset:u,amount:n},e.config),p=await v({chain:r,provider:o}).readContract({address:d.tokenRouterAddress,abi:N,functionName:"calculateFee",args:[n,l.domain]});return {[i.address]:p}}var F=[{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 ye=async(e,t)=>{let{sourceChain:r,targetChain:s,asset:u,amount:n,fromAddress:o,toAddress:d,sourceProvider:l,sign:i}=t,a=d??o;if(!isAddress(o)||!isAddress(a))throw new f("INCORRECT_ADDRESS_PROVIDED");let{sourceChainData:p,targetChainData:y,burnToken:m}=_({sourceChain:r,targetChain:s,asset:u,amount:n},e.config),c=v({chain:r,provider:l});if(await c.readContract({address:m.address,abi:F,functionName:"allowance",args:[o,p.tokenRouterAddress]})<n)if(i){let T=encodeFunctionData({abi:F,functionName:"approve",args:[p.tokenRouterAddress,n]}),g=await i({from:o,to:m.address,data:T},b=>c.sendRawTransaction({serializedTransaction:b}));await c.waitForTransactionReceipt({hash:g,pollingInterval:1e3});}else {let{request:T}=await c.simulateContract({account:o,address:m.address,abi:F,functionName:"approve",args:[p.tokenRouterAddress,n]}),g=await c.writeContract(T);await c.waitForTransactionReceipt({hash:g,pollingInterval:1e3});}if(i){let T=encodeFunctionData({abi:N,functionName:"transferTokens",args:[n,y.domain,a,m.address]});return i({from:o,to:p.tokenRouterAddress,data:T},g=>c.sendRawTransaction({serializedTransaction:g}))}else {let{request:T}=await c.simulateContract({account:o,address:p.tokenRouterAddress,abi:N,functionName:"transferTokens",args:[n,y.domain,a,m.address]});return c.writeContract(T)}},le=async e=>{try{return await e.getBlockNumber()}catch{return}};async function z(e,t,r){await e.ensureHasConfig();let{minimumConfirmations:s}=e.config.find(p=>p.chainId===t.sourceChain.chainId)??{},{minimumConfirmations:u}=e.config.find(p=>p.chainId===t.targetChain.chainId)??{};if(!s||!u)throw new f("CONFIRMATION_COUNT_UNKNOWN");let n=await e.getFees({...t,provider:t.sourceProvider}),o=(t.asset.address&&n[t.asset.address])??0n,d=await ye(e,t),l=Date.now(),i=v({chain:t.targetChain,provider:t.targetProvider}),a=await le(i);return {type:e.type,environment:r,fromAddress:t.fromAddress,toAddress:t.toAddress??t.fromAddress,amount:t.amount,amountDecimals:t.asset.decimals,symbol:t.asset.symbol,bridgeFee:o,bridgeFeeDecimals:t.asset.decimals,sourceChain:t.sourceChain,sourceStartedAt:l,sourceTxHash:d,sourceConfirmationCount:0,requiredSourceConfirmationCount:s,targetChain:t.targetChain,targetConfirmationCount:0,requiredTargetConfirmationCount:u,startBlockNumber:a}}async function J(e){if(!e.config&&(await e.updateConfig(),!e.config))throw new B("CONFIG_NOT_AVAILABLE")}var S=(e,t)=>e.gasPrice&&BigInt(e.gasPrice*t.gasUsed);var L=async e=>new Promise(t=>{setTimeout(t,e);});var U=({promise:e,delay:t,startAfter:r})=>{let s=!1,u=!1,n=0,o,d,l=p=>{o&&s&&(s=!1,o(p));},i=()=>{u=!0,d&&s&&(s=!1,d("cancelled"));};return {result:new Promise((p,y)=>{s=!0,o=p,d=y;let m=async()=>{if(!(!s||u)){try{if(await e(l),!s||u)return;await L(t);}catch(c){console.error(c.message),n+=1,await L(2**n*t);}await m();}};r?setTimeout(m,r):m();}),cancel:i}};var Y=1e3*60*60*3,X=1024n,Q=5e3,A=(e,t,r)=>{Object.assign(e,Object.fromEntries(Object.entries(t).filter(([,s])=>s!==void 0))),r({...e});},fe=async(e,t)=>{let{sourceProvider:r,targetProvider:s,updateListener:u,bridgeTransfer:n}=t,o=v({chain:n.sourceChain,provider:r}),d=e.find(y=>y.chainId===n.sourceChain.chainId),l=v({chain:n.targetChain,provider:s}),i=e.find(y=>y.chainId===n.targetChain.chainId),a={...n};if(!d||!i)throw new f("CHAIN_NOT_SUPPORTED");return U({promise:async y=>{if(a.completedAt||a.metadata?.nonce)return y(a);if(a.sourceStartedAt+Y<=Date.now())return A(a,{completedAt:Date.now(),errorCode:5004},u),y(a);let m=await o.getTransactionReceipt({hash:a.sourceTxHash});if(!a.sourceNetworkFee){let w=await o.getTransaction({hash:a.sourceTxHash}),O=S(w,m);O&&A(a,{sourceNetworkFee:O},u);}if(m.status==="reverted")return A(a,{completedAt:Date.now(),errorCode:5005},u),y(a);let c=await o.getTransactionConfirmations({hash:a.sourceTxHash}),C=c>a.sourceConfirmationCount,T=c>=a.requiredSourceConfirmationCount;if(C){let w={};w.sourceConfirmationCount=Number(c),T||(w.startBlockNumber=await l.getBlockNumber()),A(a,w,u);}if(!T)return;a.startBlockNumber||A(a,{startBlockNumber:await l.getBlockNumber()},u);let g=m.logs.find(w=>w.address===d.tokenRouterAddress?decodeEventLog({abi:N,...w}).eventName==="TransferTokens":!1);if(!g)throw new f("INVALID_PARAMS",`unable to find a TransferTokens event in source transaction "${a.sourceTxHash}"`);let x=decodeEventLog({abi:N,eventName:"TransferTokens",...g}).args.nonce;return A(a,{targetStartedAt:Date.now(),metadata:{nonce:x}},u),y(a)},delay:D(d.chainId),startAfter:Q})},Te=async(e,t)=>{let{targetProvider:r,updateListener:s,bridgeTransfer:u}=t,n={...u};if(!u.completedAt&&!u.metadata?.nonce)throw new f("INVALID_PARAMS","nonce is missing");if(!u.startBlockNumber)throw new f("INVALID_PARAMS","startBlockNumber is missing");let o=v({chain:u.targetChain,provider:r}),d=e.find(i=>i.chainId===u.targetChain.chainId);if(!d)throw new f("INVALID_PARAMS",`unknown target chain "${u.targetChain.chainId}"`);return U({promise:async i=>{if(n.completedAt)return i(n);if(n.sourceStartedAt+Y<=Date.now())return A(n,{completedAt:Date.now(),errorCode:5004},s),i(n);if(!n.targetTxHash){let c=await o.getBlockNumber(),C=(n.startBlockNumber??0n)-X,T=C>=0n?C:"earliest",g=(n.startBlockNumber??0n)+X,b=g<c?g:"latest",x=await o.getLogs({address:d.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:T,toBlock:b});if(x[0]?.transactionHash)A(n,{targetTxHash:x[0].transactionHash},s);else return}let a=await o.getTransactionReceipt({hash:n.targetTxHash});if(!n.targetNetworkFee){let c=await o.getTransaction({hash:n.targetTxHash}),C=S(c,a);C&&A(n,{targetNetworkFee:C},s);}if(a.status==="reverted")return A(n,{completedAt:Date.now(),errorCode:5005},s),i(n);let p=await o.getTransactionConfirmations({hash:n.targetTxHash}),y=p>n.targetConfirmationCount,m=p>=n.requiredTargetConfirmationCount;if(y&&A(n,{targetConfirmationCount:Number(p)},s),!!m)return A(n,{completedAt:Date.now()},s),i(n)},delay:D(d.chainId),startAfter:Q})};function ee(e,t){let r,s=()=>{r?.();};return {result:(async()=>{await e.ensureHasConfig();let{sourceProvider:n,targetProvider:o,updateListener:d,bridgeTransfer:l}=t,{result:i,cancel:a}=await fe(e.config,{sourceProvider:n,targetProvider:o,updateListener:d,bridgeTransfer:l});r=a;let p=await i,{result:y,cancel:m}=await Te(e.config,{sourceProvider:n,targetProvider:o,updateListener:d,bridgeTransfer:p});return r=m,y})(),cancel:s}}var te=e=>({type:"cctp",config:null,updateConfig:async function(){this.config=await K(e);},ensureHasConfig:async function(){return J(this)},getAssets:async function(){return $(this)},getFees:async function(t){return W(this,t)},transferAsset:async function(t){return z(this,t,e)},trackTransfer:function(t){return ee(this,t)}});var ge=new Map([["cctp",te]]),ne=(e,t)=>new Map([...ge].filter(([r])=>!t?.includes(r)).map(([r,s])=>[r,s(e)])),M=(e,t,r)=>{let s=t.destinations[r]?.find(u=>e.has(u));if(!s)throw new P;return {type:s,bridge:e.get(s)}};var un=({environment:e,disabledBridgeTypes:t})=>{let r=ne(e,t),s=async()=>{await Promise.allSettled(Array.from(r).map(([,a])=>a.updateConfig()));};return {environment:e,bridges:r,init:async()=>{await s();},updateConfigs:s,getAssets:async()=>(await Promise.all(Array.from(r).map(([,p])=>p.getAssets()))).reduce((p,y)=>{for(let[m,c]of Object.entries(y)){let C=p[m];if(C)for(let T of c){let g=C.findIndex(({symbol:b})=>b===T.symbol);g===-1?C.push(T):mergeWith(C[g],T,(b,x)=>{if(isArray(b))return [...new Set(b.concat(x))]});}else p[m]=c;}return p},{}),getFees:async a=>{let{bridge:p}=M(r,a.asset,a.targetChain.chainId);return p.getFees(a)},canTransferAsset:(a,p)=>{try{return M(r,a,p),!0}catch{return !1}},transferAsset:async a=>{let{bridge:p}=M(r,a.asset,a.targetChain.chainId);return p.transferAsset(a)},trackTransfer:a=>{let p=r.get(a.bridgeTransfer.type);if(!p)throw new P;return p.trackTransfer(a)}}};
var H=(r=>(r.NATIVE="native",r.ERC20="erc20",r))(H||{});var R=(t=>(t.CCTP="cctp",t))(R||{});var V=(r=>(r.PROD="production",r.TEST="test",r))(V||{});var k=(n=>(n[n.BRIDGE_NOT_AVAILABLE=5001]="BRIDGE_NOT_AVAILABLE",n[n.INITIALIZATION_FAILED=5002]="INITIALIZATION_FAILED",n[n.INVALID_PARAMS=5003]="INVALID_PARAMS",n[n.TIMEOUT=5004]="TIMEOUT",n[n.TRANSACTION_REVERTED=5005]="TRANSACTION_REVERTED",n))(k||{}),h=(i=>(i.UNKNOWN="UNKNOWN",i.CONFIG_NOT_AVAILABLE="CONFIG_NOT_AVAILABLE",i.INVALID_PARAMS="INVALID_PARAMS",i.IDENTICAL_CHAINS_PROVIDED="IDENTICAL_CHAINS_PROVIDED",i.INCORRECT_AMOUNT_PROVIDED="INCORRECT_AMOUNT_PROVIDED",i.INCORRECT_ADDRESS_PROVIDED="INCORRECT_ADDRESS_PROVIDED",i.CHAIN_NOT_SUPPORTED="CHAIN_NOT_SUPPORTED",i.ASSET_NOT_SUPPORTED="ASSET_NOT_SUPPORTED",i.CONFIRMATION_COUNT_UNKNOWN="CONFIRMATION_COUNT_UNKNOWN",i))(h||{});var I=class extends Error{constructor(r,s,u){super(r);this.code=s;this.details=u;}};var P=class extends I{constructor(t="UNKNOWN",r){super(t,5001,r),this.name="BridgeUnavailableError";}};var B=class extends I{constructor(t="UNKNOWN",r){super(t,5002,r),this.name="BridgeInitializationError";}};var f=class extends I{constructor(t="INVALID_PARAMS",r){super(t,5003,r),this.name="InvalidParamsError";}};var re={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"},K=async e=>{try{return (await(await fetch(re[e])).json()).map(s=>({...s,chainId:`eip155:${s.chainId}`}))}catch(t){throw new B("CONFIG_NOT_AVAILABLE",`Error while fetching CCTP config: ${t.message}`)}},D=e=>{switch(e){case"eip155:43114":case"eip155: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(u=>({...u,type:"erc20",destinations:t.reduce((n,o)=>(s.chainId!==o&&(n[o]||(n[o]=[]),n[o]?.push("cctp")),n),{})})),r),{})}var ae="^[-a-z0-9]{3,8}$",se="^[-_a-zA-Z0-9]{1,50}$",G=":",ie=e=>{let[t,r]=e.split(G);if(!t||!r)throw new Error("Invalid identifier provided.");if(!new RegExp(ae).test(t))throw new Error("Invalid namespace provided.");if(!new RegExp(se).test(r))throw new Error("Invalid reference provided.");return {namespace:t,reference:r}},oe=({namespace:e,reference:t})=>`${e}${G}${t}`,E={toJSON:ie,toString:oe};var me=e=>{let{reference:t}=E.toJSON(e.chainId);return {id:Number(t),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}}}}},v=({chain:e,provider:t})=>{let r=me(e),s=t?custom(t):http(e.rpcUrl,{batch:!0,retryCount:0});return createWalletClient({chain:r,transport:s}).extend(publicActions)};var N=[{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 _=({sourceChain:e,targetChain:t,amount:r,asset:s},u)=>{if(e.chainId===t.chainId)throw new f("IDENTICAL_CHAINS_PROVIDED");if(r<=0n)throw new f("INCORRECT_AMOUNT_PROVIDED","Amount must be greater than zero");let n=u.find(i=>i.chainId===e.chainId);if(!n)throw new f("CHAIN_NOT_SUPPORTED",`Not supported on source chain "${e.chainId}"`);let o=u.find(i=>i.chainId===t.chainId);if(!o)throw new f("CHAIN_NOT_SUPPORTED",`Not supported on target chain "${t.chainId}"`);let d=n.tokens.find(i=>i.symbol===s.symbol),l=o.tokens.find(i=>i.symbol===s.symbol);if(!d||!l)throw new f("ASSET_NOT_SUPPORTED");return {sourceChainData:n,targetChainData:o,burnToken:d,mintToken:l}};async function W(e,t){await e.ensureHasConfig();let{sourceChain:r,targetChain:s,asset:u,amount:n,provider:o}=t,{sourceChainData:d,targetChainData:l,burnToken:i}=_({sourceChain:r,targetChain:s,asset:u,amount:n},e.config),p=await v({chain:r,provider:o}).readContract({address:d.tokenRouterAddress,abi:N,functionName:"calculateFee",args:[n,l.domain]});return {[i.address]:p}}var F=[{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 ye=async(e,t)=>{let{sourceChain:r,targetChain:s,asset:u,amount:n,fromAddress:o,toAddress:d,sourceProvider:l,sign:i}=t,a=d??o;if(!isAddress(o)||!isAddress(a))throw new f("INCORRECT_ADDRESS_PROVIDED");let{sourceChainData:p,targetChainData:y,burnToken:m}=_({sourceChain:r,targetChain:s,asset:u,amount:n},e.config),c=v({chain:r,provider:l});if(await c.readContract({address:m.address,abi:F,functionName:"allowance",args:[o,p.tokenRouterAddress]})<n)if(i){let T=encodeFunctionData({abi:F,functionName:"approve",args:[p.tokenRouterAddress,n]}),g=await i({from:o,to:m.address,data:T},b=>c.sendRawTransaction({serializedTransaction:b}));await c.waitForTransactionReceipt({hash:g,pollingInterval:1e3});}else {let{request:T}=await c.simulateContract({account:o,address:m.address,abi:F,functionName:"approve",args:[p.tokenRouterAddress,n]}),g=await c.writeContract(T);await c.waitForTransactionReceipt({hash:g,pollingInterval:1e3});}if(i){let T=encodeFunctionData({abi:N,functionName:"transferTokens",args:[n,y.domain,a,m.address]});return i({from:o,to:p.tokenRouterAddress,data:T},g=>c.sendRawTransaction({serializedTransaction:g}))}else {let{request:T}=await c.simulateContract({account:o,address:p.tokenRouterAddress,abi:N,functionName:"transferTokens",args:[n,y.domain,a,m.address]});return c.writeContract(T)}},le=async e=>{try{return await e.getBlockNumber()}catch{return}};async function z(e,t,r){await e.ensureHasConfig();let{minimumConfirmations:s}=e.config.find(p=>p.chainId===t.sourceChain.chainId)??{},{minimumConfirmations:u}=e.config.find(p=>p.chainId===t.targetChain.chainId)??{};if(!s||!u)throw new f("CONFIRMATION_COUNT_UNKNOWN");let n=await e.getFees({...t,provider:t.sourceProvider}),o=(t.asset.address&&n[t.asset.address])??0n,d=await ye(e,t),l=Date.now(),i=v({chain:t.targetChain,provider:t.targetProvider}),a=await le(i);return {type:e.type,environment:r,fromAddress:t.fromAddress,toAddress:t.toAddress??t.fromAddress,amount:t.amount,amountDecimals:t.asset.decimals,symbol:t.asset.symbol,bridgeFee:o,sourceChain:t.sourceChain,sourceStartedAt:l,sourceTxHash:d,sourceConfirmationCount:0,requiredSourceConfirmationCount:s,targetChain:t.targetChain,targetConfirmationCount:0,requiredTargetConfirmationCount:u,startBlockNumber:a}}async function J(e){if(!e.config&&(await e.updateConfig(),!e.config))throw new B("CONFIG_NOT_AVAILABLE")}var S=(e,t)=>e.gasPrice&&BigInt(e.gasPrice*t.gasUsed);var L=async e=>new Promise(t=>{setTimeout(t,e);});var U=({promise:e,delay:t,startAfter:r})=>{let s=!1,u=!1,n=0,o,d,l=p=>{o&&s&&(s=!1,o(p));},i=()=>{u=!0,d&&s&&(s=!1,d("cancelled"));};return {result:new Promise((p,y)=>{s=!0,o=p,d=y;let m=async()=>{if(!(!s||u)){try{if(await e(l),!s||u)return;await L(t);}catch(c){console.error(c.message),n+=1,await L(2**n*t);}await m();}};r?setTimeout(m,r):m();}),cancel:i}};var Y=1e3*60*60*3,X=1024n,Q=5e3,A=(e,t,r)=>{Object.assign(e,Object.fromEntries(Object.entries(t).filter(([,s])=>s!==void 0))),r({...e});},fe=async(e,t)=>{let{sourceProvider:r,targetProvider:s,updateListener:u,bridgeTransfer:n}=t,o=v({chain:n.sourceChain,provider:r}),d=e.find(y=>y.chainId===n.sourceChain.chainId),l=v({chain:n.targetChain,provider:s}),i=e.find(y=>y.chainId===n.targetChain.chainId),a={...n};if(!d||!i)throw new f("CHAIN_NOT_SUPPORTED");return U({promise:async y=>{if(a.completedAt||a.metadata?.nonce)return y(a);if(a.sourceStartedAt+Y<=Date.now())return A(a,{completedAt:Date.now(),errorCode:5004},u),y(a);let m=await o.getTransactionReceipt({hash:a.sourceTxHash});if(!a.sourceNetworkFee){let w=await o.getTransaction({hash:a.sourceTxHash}),O=S(w,m);O&&A(a,{sourceNetworkFee:O},u);}if(m.status==="reverted")return A(a,{completedAt:Date.now(),errorCode:5005},u),y(a);let c=await o.getTransactionConfirmations({hash:a.sourceTxHash}),C=c>a.sourceConfirmationCount,T=c>=a.requiredSourceConfirmationCount;if(C){let w={};w.sourceConfirmationCount=Number(c),T||(w.startBlockNumber=await l.getBlockNumber()),A(a,w,u);}if(!T)return;a.startBlockNumber||A(a,{startBlockNumber:await l.getBlockNumber()},u);let g=m.logs.find(w=>w.address===d.tokenRouterAddress?decodeEventLog({abi:N,...w}).eventName==="TransferTokens":!1);if(!g)throw new f("INVALID_PARAMS",`unable to find a TransferTokens event in source transaction "${a.sourceTxHash}"`);let x=decodeEventLog({abi:N,eventName:"TransferTokens",...g}).args.nonce;return A(a,{targetStartedAt:Date.now(),metadata:{nonce:x}},u),y(a)},delay:D(d.chainId),startAfter:Q})},Te=async(e,t)=>{let{targetProvider:r,updateListener:s,bridgeTransfer:u}=t,n={...u};if(!u.completedAt&&!u.metadata?.nonce)throw new f("INVALID_PARAMS","nonce is missing");if(!u.startBlockNumber)throw new f("INVALID_PARAMS","startBlockNumber is missing");let o=v({chain:u.targetChain,provider:r}),d=e.find(i=>i.chainId===u.targetChain.chainId);if(!d)throw new f("INVALID_PARAMS",`unknown target chain "${u.targetChain.chainId}"`);return U({promise:async i=>{if(n.completedAt)return i(n);if(n.sourceStartedAt+Y<=Date.now())return A(n,{completedAt:Date.now(),errorCode:5004},s),i(n);if(!n.targetTxHash){let c=await o.getBlockNumber(),C=(n.startBlockNumber??0n)-X,T=C>=0n?C:"earliest",g=(n.startBlockNumber??0n)+X,b=g<c?g:"latest",x=await o.getLogs({address:d.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:T,toBlock:b});if(x[0]?.transactionHash)A(n,{targetTxHash:x[0].transactionHash},s);else return}let a=await o.getTransactionReceipt({hash:n.targetTxHash});if(!n.targetNetworkFee){let c=await o.getTransaction({hash:n.targetTxHash}),C=S(c,a);C&&A(n,{targetNetworkFee:C},s);}if(a.status==="reverted")return A(n,{completedAt:Date.now(),errorCode:5005},s),i(n);let p=await o.getTransactionConfirmations({hash:n.targetTxHash}),y=p>n.targetConfirmationCount,m=p>=n.requiredTargetConfirmationCount;if(y&&A(n,{targetConfirmationCount:Number(p)},s),!!m)return A(n,{completedAt:Date.now()},s),i(n)},delay:D(d.chainId),startAfter:Q})};function ee(e,t){let r,s=()=>{r?.();};return {result:(async()=>{await e.ensureHasConfig();let{sourceProvider:n,targetProvider:o,updateListener:d,bridgeTransfer:l}=t,{result:i,cancel:a}=await fe(e.config,{sourceProvider:n,targetProvider:o,updateListener:d,bridgeTransfer:l});r=a;let p=await i,{result:y,cancel:m}=await Te(e.config,{sourceProvider:n,targetProvider:o,updateListener:d,bridgeTransfer:p});return r=m,y})(),cancel:s}}var te=e=>({type:"cctp",config:null,updateConfig:async function(){this.config=await K(e);},ensureHasConfig:async function(){return J(this)},getAssets:async function(){return $(this)},getFees:async function(t){return W(this,t)},transferAsset:async function(t){return z(this,t,e)},trackTransfer:function(t){return ee(this,t)}});var ge=new Map([["cctp",te]]),ne=(e,t)=>new Map([...ge].filter(([r])=>!t?.includes(r)).map(([r,s])=>[r,s(e)])),M=(e,t,r)=>{let s=t.destinations[r]?.find(u=>e.has(u));if(!s)throw new P;return {type:s,bridge:e.get(s)}};var un=({environment:e,disabledBridgeTypes:t})=>{let r=ne(e,t),s=async()=>{await Promise.allSettled(Array.from(r).map(([,a])=>a.updateConfig()));};return {environment:e,bridges:r,init:async()=>{await s();},updateConfigs:s,getAssets:async()=>(await Promise.all(Array.from(r).map(([,p])=>p.getAssets()))).reduce((p,y)=>{for(let[m,c]of Object.entries(y)){let C=p[m];if(C)for(let T of c){let g=C.findIndex(({symbol:b})=>b===T.symbol);g===-1?C.push(T):mergeWith(C[g],T,(b,x)=>{if(isArray(b))return [...new Set(b.concat(x))]});}else p[m]=c;}return p},{}),getFees:async a=>{let{bridge:p}=M(r,a.asset,a.targetChain.chainId);return p.getFees(a)},canTransferAsset:(a,p)=>{try{return M(r,a,p),!0}catch{return !1}},transferAsset:async a=>{let{bridge:p}=M(r,a.asset,a.targetChain.chainId);return p.transferAsset(a)},trackTransfer:a=>{let p=r.get(a.bridgeTransfer.type);if(!p)throw new P;return p.trackTransfer(a)}}};

@@ -6,0 +6,0 @@ export { R as BridgeType, V as Environment, k as ErrorCode, h as ErrorReason, H as TokenType, E as caip2, un as createUnifiedBridgeService };

{
"name": "@avalabs/bridge-unified",
"version": "0.0.0-fix-make-source-provider-optio-20240110083249",
"version": "0.0.0-fix-make-source-provider-optio-20240110084136",
"main": "dist/index.js",

@@ -18,3 +18,3 @@ "type": "module",

"@internal/tsup-config": "0.0.1",
"eslint-config-custom": "0.0.0-fix-make-source-provider-optio-20240110083249"
"eslint-config-custom": "0.0.0-fix-make-source-provider-optio-20240110084136"
},

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

@@ -117,3 +117,2 @@ import { encodeFunctionData, isAddress } from 'viem';

amountDecimals: params.asset.decimals,
bridgeFeeDecimals: params.asset.decimals,
fromAddress: params.fromAddress,

@@ -212,3 +211,2 @@ sourceTxHash: bridgeTxHash,

amountDecimals: params.asset.decimals,
bridgeFeeDecimals: params.asset.decimals,
fromAddress: params.fromAddress,

@@ -289,3 +287,2 @@ sourceTxHash: bridgeTxHash,

amountDecimals: params.asset.decimals,
bridgeFeeDecimals: params.asset.decimals,
fromAddress: params.fromAddress,

@@ -357,3 +354,2 @@ sourceTxHash: bridgeTxHash,

amountDecimals: params.asset.decimals,
bridgeFeeDecimals: params.asset.decimals,
fromAddress: params.fromAddress,

@@ -360,0 +356,0 @@ sourceTxHash: bridgeTxHash,

@@ -149,3 +149,2 @@ import { encodeFunctionData, isAddress, type PublicClient } from 'viem';

bridgeFee,
bridgeFeeDecimals: params.asset.decimals,

@@ -152,0 +151,0 @@ sourceChain: params.sourceChain,

@@ -18,3 +18,2 @@ import type { Environment } from './environment';

bridgeFee: bigint;
bridgeFeeDecimals: number;

@@ -21,0 +20,0 @@ sourceChain: Chain;

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

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