@defiverse/balancer-sdk-megaeth 0.1.260 → 0.1.261
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -485,5 +485,5 @@ ${gn`
|
|
|
485
485
|
}
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
|
-
`,ys=(e,t,a)=>e();function bs(e){return Wn(new W(e))}function fs(e){return function(e,t=ys){return{GaugeShare:(a,n)=>t((t=>e.request(ds,a,{...n,...t})),"GaugeShare","query"),GaugeShares:(a,n)=>t((t=>e.request(cs,a,{...n,...t})),"GaugeShares","query"),LiquidityGauges:(a,n)=>t((t=>e.request(ls,a,{...n,...t})),"LiquidityGauges","query"),Pools:(a,n)=>t((t=>e.request(ps,a,{...n,...t})),"Pools","query"),PoolGauges:(a,n)=>t((t=>e.request(us,a,{...n,...t})),"PoolGauges","query")}}(new W(e))}const ms=["function aggregate(tuple[](address target, bytes callData) memory calls) public view returns (uint256 blockNumber, bytes[] memory returnData)"],hs=(e,t)=>new u(e,ms,t);class Ts{constructor(e,a,n,s={}){this.options={},this.calls=[],this.paths=[],this.multiAddress=e,this.provider=a,this.interface=new t(n),this.options=s}call(e,t,a,n){return this.calls.push([t,a,n]),this.paths.push(e),this}async execute(e={}){const t=e;return(await this.executeMulticall()).forEach(((e,a)=>I(t,this.paths[a],e.length>1?e:e[0]))),this.calls=[],this.paths=[],t}async executeMulticall(){const e=hs(this.multiAddress,this.provider),[,t]=await e.aggregate(this.calls.map((([e,t,a])=>[e,this.interface.encodeFunctionData(t,a)])),this.options);return t.map(((e,t)=>this.interface.decodeFunctionResult(this.calls[t][1],e)))}}var gs=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"},{internalType:"contract IERC20[]",name:"tokens",type:"address[]"},{internalType:"uint256[]",name:"normalizedWeights",type:"uint256[]"},{internalType:"uint256",name:"swapFeePercentage",type:"uint256"},{internalType:"uint256",name:"pauseWindowDuration",type:"uint256"},{internalType:"uint256",name:"bufferPeriodDuration",type:"uint256"},{internalType:"address",name:"owner",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"paused",type:"bool"}],name:"PausedStateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"SwapFeePercentageChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"decreaseApproval",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"getActionId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAuthorizer",outputs:[{internalType:"contract IAuthorizer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getInvariant",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLastInvariant",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getNormalizedWeights",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPausedState",outputs:[{internalType:"bool",name:"paused",type:"bool"},{internalType:"uint256",name:"pauseWindowEndTime",type:"uint256"},{internalType:"uint256",name:"bufferPeriodEndTime",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPoolId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getSwapFeePercentage",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"increaseApproval",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onExitPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onJoinPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IERC20",name:"tokenIn",type:"address"},{internalType:"contract IERC20",name:"tokenOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IPoolSwapStructs.SwapRequest",name:"request",type:"tuple"},{internalType:"uint256",name:"balanceTokenIn",type:"uint256"},{internalType:"uint256",name:"balanceTokenOut",type:"uint256"}],name:"onSwap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryExit",outputs:[{internalType:"uint256",name:"bptIn",type:"uint256"},{internalType:"uint256[]",name:"amountsOut",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryJoin",outputs:[{internalType:"uint256",name:"bptOut",type:"uint256"},{internalType:"uint256[]",name:"amountsIn",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"paused",type:"bool"}],name:"setPaused",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"setSwapFeePercentage",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],Is=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"},{internalType:"contract IERC20[]",name:"tokens",type:"address[]"},{internalType:"uint256",name:"amplificationParameter",type:"uint256"},{internalType:"uint256",name:"swapFeePercentage",type:"uint256"},{internalType:"uint256",name:"pauseWindowDuration",type:"uint256"},{internalType:"uint256",name:"bufferPeriodDuration",type:"uint256"},{internalType:"address",name:"owner",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"startValue",type:"uint256"},{indexed:!1,internalType:"uint256",name:"endValue",type:"uint256"},{indexed:!1,internalType:"uint256",name:"startTime",type:"uint256"},{indexed:!1,internalType:"uint256",name:"endTime",type:"uint256"}],name:"AmpUpdateStarted",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"currentValue",type:"uint256"}],name:"AmpUpdateStopped",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"paused",type:"bool"}],name:"PausedStateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"SwapFeePercentageChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"getActionId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAmplificationParameter",outputs:[{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"isUpdating",type:"bool"},{internalType:"uint256",name:"precision",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAuthorizer",outputs:[{internalType:"contract IAuthorizer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPausedState",outputs:[{internalType:"bool",name:"paused",type:"bool"},{internalType:"uint256",name:"pauseWindowEndTime",type:"uint256"},{internalType:"uint256",name:"bufferPeriodEndTime",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPoolId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getSwapFeePercentage",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onExitPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onJoinPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IERC20",name:"tokenIn",type:"address"},{internalType:"contract IERC20",name:"tokenOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IPoolSwapStructs.SwapRequest",name:"swapRequest",type:"tuple"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"indexIn",type:"uint256"},{internalType:"uint256",name:"indexOut",type:"uint256"}],name:"onSwap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IERC20",name:"tokenIn",type:"address"},{internalType:"contract IERC20",name:"tokenOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IPoolSwapStructs.SwapRequest",name:"request",type:"tuple"},{internalType:"uint256",name:"balanceTokenIn",type:"uint256"},{internalType:"uint256",name:"balanceTokenOut",type:"uint256"}],name:"onSwap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryExit",outputs:[{internalType:"uint256",name:"bptIn",type:"uint256"},{internalType:"uint256[]",name:"amountsOut",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryJoin",outputs:[{internalType:"uint256",name:"bptOut",type:"uint256"},{internalType:"uint256[]",name:"amountsIn",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"},{internalType:"bytes",name:"poolConfig",type:"bytes"}],name:"setAssetManagerPoolConfig",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bool",name:"paused",type:"bool"}],name:"setPaused",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"setSwapFeePercentage",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"rawEndValue",type:"uint256"},{internalType:"uint256",name:"endTime",type:"uint256"}],name:"startAmplificationParameterUpdate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"stopAmplificationParameterUpdate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],ws=[{inputs:[{internalType:"contract IERC20",name:"_underlying",type:"address"},{internalType:"contract IERC20",name:"_bond",type:"address"},{internalType:"uint256",name:"_expiration",type:"uint256"},{internalType:"uint256",name:"_unitSeconds",type:"uint256"},{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"uint256",name:"_percentFee",type:"uint256"},{internalType:"uint256",name:"_percentFeeGov",type:"uint256"},{internalType:"address",name:"_governance",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"collectedBase",type:"uint256"},{indexed:!1,internalType:"uint256",name:"collectedBond",type:"uint256"},{indexed:!1,internalType:"uint256",name:"remainingBase",type:"uint256"},{indexed:!1,internalType:"uint256",name:"remainingBond",type:"uint256"}],name:"FeeCollection",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"FEE_BOUND",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"bond",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"bondDecimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"decreaseApproval",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"expiration",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"feesBond",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"view",type:"function"},{inputs:[],name:"feesUnderlying",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPoolId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"governance",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"increaseApproval",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"currentBalances",type:"uint256[]"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"uint256",name:"protocolSwapFee",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onExitPool",outputs:[{internalType:"uint256[]",name:"amountsOut",type:"uint256[]"},{internalType:"uint256[]",name:"dueProtocolFeeAmounts",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"currentBalances",type:"uint256[]"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"uint256",name:"protocolSwapFee",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onJoinPool",outputs:[{internalType:"uint256[]",name:"amountsIn",type:"uint256[]"},{internalType:"uint256[]",name:"dueProtocolFeeAmounts",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IERC20",name:"tokenIn",type:"address"},{internalType:"contract IERC20",name:"tokenOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IPoolSwapStructs.SwapRequest",name:"swapRequest",type:"tuple"},{internalType:"uint256",name:"currentBalanceTokenIn",type:"uint256"},{internalType:"uint256",name:"currentBalanceTokenOut",type:"uint256"}],name:"onSwap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"percentFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"percentFeeGov",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amountX",type:"uint256"},{internalType:"uint256",name:"reserveX",type:"uint256"},{internalType:"uint256",name:"reserveY",type:"uint256"},{internalType:"bool",name:"out",type:"bool"}],name:"solveTradeInvariant",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"underlying",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"underlyingDecimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"unitSeconds",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"}],Es=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"},{internalType:"contract IERC20",name:"mainToken",type:"address"},{internalType:"contract IERC20",name:"wrappedToken",type:"address"},{internalType:"uint256",name:"upperTarget",type:"uint256"},{internalType:"uint256",name:"swapFeePercentage",type:"uint256"},{internalType:"uint256",name:"pauseWindowDuration",type:"uint256"},{internalType:"uint256",name:"bufferPeriodDuration",type:"uint256"},{internalType:"address",name:"owner",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"paused",type:"bool"}],name:"PausedStateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"SwapFeePercentageChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract IERC20",name:"token",type:"address"},{indexed:!1,internalType:"uint256",name:"lowerTarget",type:"uint256"},{indexed:!1,internalType:"uint256",name:"upperTarget",type:"uint256"}],name:"TargetsSet",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"getActionId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAuthorizer",outputs:[{internalType:"contract IAuthorizer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getBptIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getMainIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getMainToken",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPausedState",outputs:[{internalType:"bool",name:"paused",type:"bool"},{internalType:"uint256",name:"pauseWindowEndTime",type:"uint256"},{internalType:"uint256",name:"bufferPeriodEndTime",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPoolId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getScalingFactors",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getSwapFeePercentage",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getTargets",outputs:[{internalType:"uint256",name:"lowerTarget",type:"uint256"},{internalType:"uint256",name:"upperTarget",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVirtualSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getWrappedIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getWrappedToken",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getWrappedTokenRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onExitPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onJoinPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IERC20",name:"tokenIn",type:"address"},{internalType:"contract IERC20",name:"tokenOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IPoolSwapStructs.SwapRequest",name:"request",type:"tuple"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"indexIn",type:"uint256"},{internalType:"uint256",name:"indexOut",type:"uint256"}],name:"onSwap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryExit",outputs:[{internalType:"uint256",name:"bptIn",type:"uint256"},{internalType:"uint256[]",name:"amountsOut",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryJoin",outputs:[{internalType:"uint256",name:"bptOut",type:"uint256"},{internalType:"uint256[]",name:"amountsIn",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"},{internalType:"bytes",name:"poolConfig",type:"bytes"}],name:"setAssetManagerPoolConfig",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bool",name:"paused",type:"bool"}],name:"setPaused",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"setSwapFeePercentage",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"newLowerTarget",type:"uint256"},{internalType:"uint256",name:"newUpperTarget",type:"uint256"}],name:"setTargets",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],xs=[{inputs:[{components:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"contract IProtocolFeePercentagesProvider",name:"protocolFeeProvider",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"},{internalType:"contract IERC20[]",name:"tokens",type:"address[]"},{internalType:"contract IRateProvider[]",name:"rateProviders",type:"address[]"},{internalType:"uint256[]",name:"tokenRateCacheDurations",type:"uint256[]"},{internalType:"bool[]",name:"exemptFromYieldProtocolFeeFlags",type:"bool[]"},{internalType:"uint256",name:"amplificationParameter",type:"uint256"},{internalType:"uint256",name:"swapFeePercentage",type:"uint256"},{internalType:"uint256",name:"pauseWindowDuration",type:"uint256"},{internalType:"uint256",name:"bufferPeriodDuration",type:"uint256"},{internalType:"address",name:"owner",type:"address"}],internalType:"struct ComposableStablePool.NewPoolParams",name:"params",type:"tuple"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"startValue",type:"uint256"},{indexed:!1,internalType:"uint256",name:"endValue",type:"uint256"},{indexed:!1,internalType:"uint256",name:"startTime",type:"uint256"},{indexed:!1,internalType:"uint256",name:"endTime",type:"uint256"}],name:"AmpUpdateStarted",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"currentValue",type:"uint256"}],name:"AmpUpdateStopped",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"paused",type:"bool"}],name:"PausedStateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"feeType",type:"uint256"},{indexed:!1,internalType:"uint256",name:"protocolFeePercentage",type:"uint256"}],name:"ProtocolFeePercentageCacheUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"enabled",type:"bool"}],name:"RecoveryModeStateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"SwapFeePercentageChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"tokenIndex",type:"uint256"},{indexed:!1,internalType:"uint256",name:"rate",type:"uint256"}],name:"TokenRateCacheUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"tokenIndex",type:"uint256"},{indexed:!0,internalType:"contract IRateProvider",name:"provider",type:"address"},{indexed:!1,internalType:"uint256",name:"cacheDuration",type:"uint256"}],name:"TokenRateProviderSet",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DELEGATE_PROTOCOL_SWAP_FEES_SENTINEL",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"disableRecoveryMode",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"enableRecoveryMode",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"getActionId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getActualSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAmplificationParameter",outputs:[{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"isUpdating",type:"bool"},{internalType:"uint256",name:"precision",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAuthorizer",outputs:[{internalType:"contract IAuthorizer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getBptIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getDomainSeparator",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLastJoinExitData",outputs:[{internalType:"uint256",name:"lastJoinExitAmplification",type:"uint256"},{internalType:"uint256",name:"lastPostJoinExitInvariant",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getMinimumBpt",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"getNextNonce",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPausedState",outputs:[{internalType:"bool",name:"paused",type:"bool"},{internalType:"uint256",name:"pauseWindowEndTime",type:"uint256"},{internalType:"uint256",name:"bufferPeriodEndTime",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPoolId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"feeType",type:"uint256"}],name:"getProtocolFeePercentageCache",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getProtocolFeesCollector",outputs:[{internalType:"contract IProtocolFeesCollector",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getProtocolSwapFeeDelegation",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRateProviders",outputs:[{internalType:"contract IRateProvider[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getScalingFactors",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getSwapFeePercentage",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"}],name:"getTokenRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"}],name:"getTokenRateCache",outputs:[{internalType:"uint256",name:"rate",type:"uint256"},{internalType:"uint256",name:"oldRate",type:"uint256"},{internalType:"uint256",name:"duration",type:"uint256"},{internalType:"uint256",name:"expires",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"inRecoveryMode",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"}],name:"isTokenExemptFromYieldProtocolFee",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onExitPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onJoinPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IERC20",name:"tokenIn",type:"address"},{internalType:"contract IERC20",name:"tokenOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IPoolSwapStructs.SwapRequest",name:"swapRequest",type:"tuple"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"indexIn",type:"uint256"},{internalType:"uint256",name:"indexOut",type:"uint256"}],name:"onSwap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryExit",outputs:[{internalType:"uint256",name:"bptIn",type:"uint256"},{internalType:"uint256[]",name:"amountsOut",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryJoin",outputs:[{internalType:"uint256",name:"bptOut",type:"uint256"},{internalType:"uint256[]",name:"amountsIn",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"},{internalType:"bytes",name:"poolConfig",type:"bytes"}],name:"setAssetManagerPoolConfig",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"setSwapFeePercentage",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"},{internalType:"uint256",name:"duration",type:"uint256"}],name:"setTokenRateCacheDuration",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"rawEndValue",type:"uint256"},{internalType:"uint256",name:"endTime",type:"uint256"}],name:"startAmplificationParameterUpdate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"stopAmplificationParameterUpdate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"updateProtocolFeePercentageCache",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"}],name:"updateTokenRateCache",outputs:[],stateMutability:"nonpayable",type:"function"}];async function As(e,t,a,n){if(0===e.length)return e;const s=Object.values(Object.fromEntries([...L.abi,...Te,...gs,...Is,...ws,...Es,...xs].map((e=>[e.name,e])))),i=new Ts(t,n,s),r=Object.values(C),o=[];e.forEach((e=>{r.includes(e.poolType)?(o.push(e),i.call(`${e.id}.poolTokens`,a,"getPoolTokens",[e.id]),i.call(`${e.id}.totalSupply`,e.address,"totalSupply"),(e.poolType.includes("Linear")||"StablePhantom"===e.poolType)&&i.call(`${e.id}.virtualSupply`,e.address,"getVirtualSupply"),"ComposableStable"===e.poolType&&i.call(`${e.id}.actualSupply`,e.address,"getActualSupply"),"Weighted"===e.poolType||"LiquidityBootstrapping"===e.poolType||"Investment"===e.poolType?(i.call(`${e.id}.weights`,e.address,"getNormalizedWeights"),i.call(`${e.id}.swapFee`,e.address,"getSwapFeePercentage")):"Stable"===e.poolType||"MetaStable"===e.poolType||"StablePhantom"===e.poolType||"ComposableStable"===e.poolType?(i.call(`${e.id}.amp`,e.address,"getAmplificationParameter"),i.call(`${e.id}.swapFee`,e.address,"getSwapFeePercentage")):"Element"===e.poolType?i.call(`${e.id}.swapFee`,e.address,"percentFee"):e.poolType.toString().includes("Linear")?(i.call(`${e.id}.swapFee`,e.address,"getSwapFeePercentage"),i.call(`${e.id}.targets`,e.address,"getTargets"),i.call(`${e.id}.rate`,e.address,"getWrappedTokenRate")):e.poolType.toString().includes("Gyro")&&i.call(`${e.id}.swapFee`,e.address,"getSwapFeePercentage")):console.error(`Unknown pool type: ${e.poolType} ${e.id}`)}));let d={};try{d=await i.execute()}catch(e){throw"Issue with multicall execution."}const c=[];return Object.entries(d).forEach((([e,t],a)=>{try{const{poolTokens:n,swapFee:s,weights:i,totalSupply:r,virtualSupply:d,actualSupply:p}=t;if("Stable"===o[a].poolType||"MetaStable"===o[a].poolType||"StablePhantom"===o[a].poolType||"ComposableStable"===o[a].poolType){if(!t.amp)return void console.error(`Stable Pool Missing Amp: ${e}`);o[a].amp=l(t.amp[0],3)}if(o[a].poolType.includes("Linear")){if(!t.targets)return void console.error(`Linear Pool Missing Targets: ${e}`);o[a].lowerTarget=l(t.targets[0],18),o[a].upperTarget=l(t.targets[1],18);const n=o[a].wrappedIndex;if(void 0===n||void 0===t.rate)return void console.error(`Linear Pool Missing WrappedIndex or PriceRate: ${e}`);o[a].tokens[n].priceRate=l(t.rate,18)}if(o[a].swapFee=l(s,18),n.tokens.forEach(((t,s)=>{const r=o[a].tokens.find((e=>Pt(e.address,t)));if(!r)throw`Pool Missing Expected Token: ${e} ${t}`;r.balance=l(n.balances[s],r.decimals),i&&(r.weight=l(i[s],18))})),o[a].poolType.includes("Linear")||"StablePhantom"===o[a].poolType){if(void 0===d)return void console.error(`Pool with pre-minted BPT missing Virtual Supply: ${e}`);o[a].totalShares=l(d,18)}else if("ComposableStable"===o[a].poolType){if(void 0===p)return void console.error(`ComposableStable missing Actual Supply: ${e}`);o[a].totalShares=l(p,18)}else o[a].totalShares=l(r,18);c.push(o[a])}catch(e){throw`Issue with pool onchain data: ${e}`}})),c}class Ss{constructor(e,t,a,n){this.client=e,this.provider=t,this.network=a,this.sorConfig=n}async getPools(){const e=function(e){return e.map((e=>({...e,poolType:e.poolType||"",tokens:(e.tokens||[]).map((e=>({...e,weight:e.weight||null}))),totalWeight:e.totalWeight||void 0,amp:e.amp||void 0,expiryTime:e.expiryTime?w(e.expiryTime):void 0,unitSeconds:e.unitSeconds?w(e.unitSeconds):void 0,principalToken:e.principalToken||void 0,baseToken:e.baseToken||void 0})))}((await this.getSubgraphPools()).filter((e=>{if(!this.network.poolsToIgnore)return!0;return-1===this.network.poolsToIgnore.findIndex((t=>Pt(t,e.address)))})));return!1===this.sorConfig.fetchOnChainBalances?e:As(e,this.network.addresses.contracts.multicall,this.network.addresses.contracts.vault,this.provider)}async getSubgraphPools(){const{pool0:e,pool1000:t,pool2000:a}=await this.client.AllPools({where:{swapEnabled:!0,totalShares_gt:"0.000000000001"},orderBy:on.TotalLiquidity,orderDirection:en.Desc});return[...e,...t,...a]}}class Ps{constructor(e){this.chainId=e}async getNativeAssetPriceInToken(e){const t=await this.getTokenPriceInNativeAsset(e);return""+1/parseFloat(t)}async getTokenPriceInNativeAsset(e){const t=`https://api.coingecko.com/api/v3/simple/token_price/${this.platformId}?contract_addresses=${e}&vs_currencies=${this.nativeAssetId}`,{data:a}=await h.get(t,{headers:{Accept:"application/json","Content-Type":"application/json"}});if(void 0===a[e.toLowerCase()][this.nativeAssetId])throw Error("No price returned from Coingecko");return a[e.toLowerCase()][this.nativeAssetId]}get platformId(){switch(this.chainId){case 1:case 42:case 248:case 16116:case 17117:return"ethereum";case 137:return"polygon-pos";case 42161:return"arbitrum-one";case 100:return"xdai"}return"3"}get nativeAssetId(){switch(this.chainId){case 1:case 42:case 42161:case 248:case 16116:case 17117:return"eth";case 137:return"";case 100:return"xdai"}return""}}class _s{constructor(e,t){this.client=e,this.weth=t.toLowerCase()}async getNativeAssetPriceInToken(e){const t=await this.getLatestPriceInEthFromSubgraph(e);if(!t)throw Error("No price found in the subgraph");return""+1/t}async getLatestPriceInEthFromSubgraph(e){e=e.toLowerCase();const{latestPrices:t}=await this.client.TokenLatestPrices({where:{asset_in:[e,this.weth]}}),a=E(t,"id");if(a[`${e}-${this.weth}`])return parseFloat(a[`${e}-${this.weth}`].price);const n=t.filter((t=>t.asset===e));for(const e of n){const t=a[`${e.pricingAsset}-${this.weth}`];if(t)return parseFloat(e.price)*parseFloat(t.price)}return null}}function vs(e){var t,a;if("number"==typeof e.network){const a=Lt[e.network];return{...a,urls:{...a.urls,subgraph:null!==(t=e.customSubgraphUrl)&&void 0!==t?t:a.urls.subgraph},tenderly:e.tenderly}}return{...e.network,urls:{...e.network.urls,subgraph:null!==(a=e.customSubgraphUrl)&&void 0!==a?a:e.network.urls.subgraph},tenderly:e.network.tenderly}}class Os extends F{constructor(e){const t=vs(e),a=Os.getSorConfig(e),n=Os.getSorNetworkConfig(t),s=new q(e.rpcUrl,e.network),i=bs(t.urls.subgraph);super(s,n,Os.getPoolDataService(t,a,s,i),Os.getTokenPriceService(t,a,i))}static getSorConfig(e){return{tokenPriceService:"coingecko",poolDataService:"subgraph",fetchOnChainBalances:!0,...e.sor}}static getSorNetworkConfig(e){var t;return{...e,vault:e.addresses.contracts.vault,weth:e.addresses.tokens.wrappedNativeAsset,lbpRaisingTokens:null===(t=e.addresses.tokens)||void 0===t?void 0:t.lbpRaisingTokens,wETHwstETH:e.pools.wETHwstETH,connectingTokens:e.sorConnectingTokens}}static getPoolDataService(e,t,a,n){return"object"==typeof t.poolDataService?t.poolDataService:new Ss(n,a,e,t)}static getTokenPriceService(e,t,a){return"object"==typeof t.tokenPriceService?t.tokenPriceService:("subgraph"===t.tokenPriceService&&new _s(a,e.addresses.tokens.wrappedNativeAsset),new Ps(e.chainId))}}function Bs(e){if(e.poolIds.length>2)throw new Error("Simple flash swap only supports a maximum of two pools");if(e.assets.length>2)throw new Error("Simple flash swap only supports a maximum of to two assets (tokens)")}function ks(e,t){return[{poolId:e[0],assetInIndex:0,assetOutIndex:1,amount:t,userData:"0x"},{poolId:e[1],assetInIndex:1,assetOutIndex:0,amount:"0",userData:"0x"}]}function Ds(e){return-1*Number(e)}function Ns(e){return x(e)}var Cs=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"contract IERC20",name:"wstETH",type:"address"},{internalType:"contract IBalancerMinter",name:"minter",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approveVault",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{components:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"assetInIndex",type:"uint256"},{internalType:"uint256",name:"assetOutIndex",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IVault.BatchSwapStep[]",name:"swaps",type:"tuple[]"},{internalType:"contract IAsset[]",name:"assets",type:"address[]"},{components:[{internalType:"address",name:"sender",type:"address"},{internalType:"bool",name:"fromInternalBalance",type:"bool"},{internalType:"address payable",name:"recipient",type:"address"},{internalType:"bool",name:"toInternalBalance",type:"bool"}],internalType:"struct IVault.FundManagement",name:"funds",type:"tuple"},{internalType:"int256[]",name:"limits",type:"int256[]"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{components:[{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"key",type:"uint256"}],internalType:"struct VaultActions.OutputReference[]",name:"outputReferences",type:"tuple[]"}],name:"batchSwap",outputs:[{internalType:"int256[]",name:"",type:"int256[]"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"enum VaultActions.PoolKind",name:"kind",type:"uint8"},{internalType:"address",name:"sender",type:"address"},{internalType:"address payable",name:"recipient",type:"address"},{components:[{internalType:"contract IAsset[]",name:"assets",type:"address[]"},{internalType:"uint256[]",name:"minAmountsOut",type:"uint256[]"},{internalType:"bytes",name:"userData",type:"bytes"},{internalType:"bool",name:"toInternalBalance",type:"bool"}],internalType:"struct IVault.ExitPoolRequest",name:"request",type:"tuple"},{components:[{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"key",type:"uint256"}],internalType:"struct VaultActions.OutputReference[]",name:"outputReferences",type:"tuple[]"}],name:"exitPool",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IStakingLiquidityGauge[]",name:"gauges",type:"address[]"}],name:"gaugeClaimRewards",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IStakingLiquidityGauge",name:"gauge",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"gaugeDeposit",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address[]",name:"gauges",type:"address[]"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"gaugeMint",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"bool",name:"approval",type:"bool"},{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"gaugeSetMinterApproval",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IStakingLiquidityGauge",name:"gauge",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"gaugeWithdraw",outputs:[],stateMutability:"payable",type:"function"},{inputs:[],name:"getEntrypoint",outputs:[{internalType:"contract IBalancerRelayer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"enum VaultActions.PoolKind",name:"kind",type:"uint8"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{components:[{internalType:"contract IAsset[]",name:"assets",type:"address[]"},{internalType:"uint256[]",name:"maxAmountsIn",type:"uint256[]"},{internalType:"bytes",name:"userData",type:"bytes"},{internalType:"bool",name:"fromInternalBalance",type:"bool"}],internalType:"struct IVault.JoinPoolRequest",name:"request",type:"tuple"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"joinPool",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{components:[{internalType:"enum IVault.UserBalanceOpKind",name:"kind",type:"uint8"},{internalType:"contract IAsset",name:"asset",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"address",name:"sender",type:"address"},{internalType:"address payable",name:"recipient",type:"address"}],internalType:"struct IVault.UserBalanceOp[]",name:"ops",type:"tuple[]"},{internalType:"uint256",name:"value",type:"uint256"}],name:"manageUserBalance",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"uint256",name:"ref",type:"uint256"}],name:"peekChainedReferenceValue",outputs:[{internalType:"uint256",name:"value",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"relayer",type:"address"},{internalType:"bool",name:"approved",type:"bool"},{internalType:"bytes",name:"authorisation",type:"bytes"}],name:"setRelayerApproval",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"stakeETH",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"stakeETHAndWrap",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{components:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IAsset",name:"assetIn",type:"address"},{internalType:"contract IAsset",name:"assetOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IVault.SingleSwap",name:"singleSwap",type:"tuple"},{components:[{internalType:"address",name:"sender",type:"address"},{internalType:"bool",name:"fromInternalBalance",type:"bool"},{internalType:"address payable",name:"recipient",type:"address"},{internalType:"bool",name:"toInternalBalance",type:"bool"}],internalType:"struct IVault.FundManagement",name:"funds",type:"tuple"},{internalType:"uint256",name:"limit",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"swap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IStaticATokenLM",name:"staticToken",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bool",name:"toUnderlying",type:"bool"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"unwrapAaveStaticToken",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC4626",name:"wrappedToken",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"unwrapERC4626",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IUnbuttonToken",name:"wrapperToken",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"unwrapUnbuttonToken",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"unwrapWstETH",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC20Permit",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"vaultPermit",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC20PermitDAI",name:"token",type:"address"},{internalType:"address",name:"holder",type:"address"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"expiry",type:"uint256"},{internalType:"bool",name:"allowed",type:"bool"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"vaultPermitDAI",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IStaticATokenLM",name:"staticToken",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bool",name:"fromUnderlying",type:"bool"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"wrapAaveDynamicToken",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC4626",name:"wrappedToken",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"wrapERC4626",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"wrapStETH",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IUnbuttonToken",name:"wrapperToken",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"uAmount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"wrapUnbuttonToken",outputs:[],stateMutability:"payable",type:"function"}];const Fs={"0xae7ab96520de3a18e5e111b5eaab095312d7fe84":"0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0","0xd46ba6d942050d489dbd938a2c909a5d5039a161":"0xedb171c18ce90b633db442f2a6f72874093b49ef","0x1e6bb68acec8fefbd87d192be09bb274170a0548":"0xF03387d8d0FF326ab586A58E0ab4121d106147DF"};function Rs(e){let t=e;return Fs.hasOwnProperty(e)&&(t=Fs[e]),t}var Ms;function Ls(e,t,a){const{tokens:n,contracts:s}=Ut(a);let i={id:Ms.vault,address:s.vault};return n.stETH&&s.lidoRelayer&&[e,t].includes(n.stETH)&&(i={id:Ms.lido,address:s.lidoRelayer}),i}function Us(e){let t=L.abi;e.id===Ms.lido&&(t=Cs);return t.filter((e=>e.name&&["swap","batchSwap"].includes(e.name)))}function Gs(e){return{amount:e,max:t=>e.mul(1e3+t).div(1e3),min:t=>e.mul(1e3-t).div(1e3)}}function $s(e,t){const a=t===kt.SwapExactIn?e.swapAmount:e.returnAmount,n=t===kt.SwapExactIn?e.returnAmount:e.swapAmount,s=t===kt.SwapExactIn?e.swapAmountForSwaps||e.swapAmount:e.returnAmountFromSwaps||e.returnAmount,i=t===kt.SwapExactIn?e.returnAmountFromSwaps||e.returnAmount:e.swapAmountForSwaps||e.swapAmount,r=Rs(e.tokenIn),o=Rs(e.tokenOut);return{...e,amountIn:a,amountOut:n,amountInForLimits:Gs(s),amountOutForLimits:Gs(i),tokenInForSwaps:r,tokenOutFromSwaps:o}}!function(e){e[e.vault=1]="vault",e[e.lido=2]="lido"}(Ms||(Ms={}));class qs{constructor(e,t,a){this.kind=t,this.chainId=a,this.functionName="swap",this.swapInfo=$s(e,t),this.relayer=Ls(this.swapInfo.tokenIn,this.swapInfo.tokenOut,this.chainId)}setFunds(e,t){this.funds={sender:e,recipient:t||e,fromInternalBalance:!1,toInternalBalance:!1}}setDeadline(e){this.deadline=e.toString()}get amount(){return this.kind===kt.SwapExactOut?this.swapInfo.amountOutForLimits.amount:this.swapInfo.amountInForLimits.amount}setLimits(e){this.limit=this.kind===kt.SwapExactIn?this.swapInfo.amountOutForLimits.min(e).toString():this.swapInfo.amountInForLimits.max(e).toString()}get singleSwap(){return{poolId:this.swapInfo.swaps[0].poolId,kind:this.kind,assetIn:this.swapInfo.tokenInForSwaps,assetOut:this.swapInfo.tokenOutFromSwaps,amount:this.amount.toString(),userData:"0x"}}attributes(){var e;if(!this.funds||!this.limit||!this.deadline)throw new Error("Uninitialized arguments");let t={request:this.singleSwap,funds:this.funds,limit:this.limit,deadline:this.deadline};const a=this.fragment();return a[0].inputs&&(null===(e=a[0].inputs)||void 0===e?void 0:e.length)>4&&(t={...t,value:"0",outputReference:"0"}),t}data(){return new t(this.fragment()).encodeFunctionData("swap",Object.values(this.attributes()))}value(e){let t=d.from(0);return this.swapInfo.tokenIn===i&&(t=this.kind===kt.SwapExactIn?this.swapInfo.amountIn:this.swapInfo.amountInForLimits.max(e)),t}to(){return this.relayer.address}fragment(){return Us(this.relayer).filter((e=>e.name===this.functionName))}}class Ws{constructor(e,t,a){this.kind=t,this.chainId=a,this.functionName="batchSwap",this.swapInfo=$s(e,t),this.relayer=Ls(this.swapInfo.tokenIn,this.swapInfo.tokenOut,this.chainId)}setFunds(e,t){this.funds={sender:e,recipient:t||e,fromInternalBalance:!1,toInternalBalance:!1}}setDeadline(e){this.deadline=e}minAmountOut(e){return this.kind===kt.SwapExactIn?this.swapInfo.amountOutForLimits.min(e):this.swapInfo.amountOutForLimits.amount}maxAmountIn(e){return this.kind===kt.SwapExactOut?this.swapInfo.amountInForLimits.max(e):this.swapInfo.amountInForLimits.amount}setLimits(e){this.limits=this.swapInfo.tokenAddresses.map((t=>{let a=d.from(0);return t===this.swapInfo.tokenInForSwaps&&(a=this.maxAmountIn(e)),t===this.swapInfo.tokenOutFromSwaps&&(a=this.minAmountOut(e).mul(-1)),a})).map((e=>e.toString().split(".")[0]))}attributes(){var e;if(!this.funds||!this.limits||!this.deadline)throw new Error("Uninitialized arguments");let t={kind:this.kind,swaps:this.swapInfo.swaps,assets:this.swapInfo.tokenAddresses,funds:this.funds,limits:this.limits,deadline:this.deadline};const a=this.fragment();return a[0].inputs&&(null===(e=a[0].inputs)||void 0===e?void 0:e.length)>6&&(t={...t,value:"0",outputReferences:[]}),t}data(){return new t(this.fragment()).encodeFunctionData("batchSwap",Object.values(this.attributes()))}value(e){let t=d.from(0);return this.swapInfo.tokenIn===i&&(t=this.maxAmountIn(e)),t}to(){return this.relayer.address}fragment(){return Us(this.relayer).filter((e=>e.name===this.functionName))}}class Vs{constructor(e){e instanceof F?(this.sor=e,this.chainId=this.sor.provider._network.chainId):(this.sor=new Os(e),this.chainId=e.network),this.vaultContract=L.connect(Mt,this.sor.provider)}static getLimitsForSlippage(e,t,a,n,s,i){return Dt(e,t,a,n,s,i).map((e=>e.toString()))}async findRouteGivenIn({tokenIn:e,tokenOut:t,amount:a,gasPrice:n,maxPools:s=4}){return this.sor.getSwaps(e,t,N.SwapExactIn,a,{gasPrice:n,maxPools:s})}async findRouteGivenOut({tokenIn:e,tokenOut:t,amount:a,gasPrice:n,maxPools:s}){return this.sor.getSwaps(e,t,N.SwapExactOut,a,{gasPrice:n,maxPools:s})}buildSwap({userAddress:e,recipient:t,swapInfo:a,kind:n,deadline:s,maxSlippage:i}){if(!this.chainId)throw"Missing network configuration";const r=a.swaps.length>1?new Ws(a,n,this.chainId):new qs(a,n,this.chainId);r.setFunds(e,t),r.setDeadline(s),r.setLimits(i);const o=r.to(),{functionName:d}=r;return{to:o,functionName:d,attributes:r.attributes(),data:r.data(),value:r.value(i)}}static encodeBatchSwap(e){return L.createInterface().encodeFunctionData("batchSwap",[e.kind,e.swaps,e.assets,e.funds,e.limits,e.deadline])}static encodeSimpleFlashSwap(e){return this.encodeBatchSwap(function({poolIds:e,assets:t,flashLoanAmount:a,walletAddress:n}){Bs({poolIds:e,assets:t});const s=ks(e,a),i={sender:n,fromInternalBalance:!1,recipient:n,toInternalBalance:!1};return{kind:kt.SwapExactIn,swaps:s,assets:t,funds:i,limits:["0","0"],deadline:"999999999999999999"}}(e))}async fetchPools(){return this.sor.fetchPools()}getPools(){return this.sor.getPools()}async queryBatchSwap(e){return await _a(this.vaultContract,e.kind,e.swaps,e.assets)}async queryBatchSwapWithSor(e){return await va(this.sor,this.vaultContract,e)}async querySimpleFlashSwap(e){return await async function(e){Bs(e);const[t,a]=e.assets;try{const n=await _a(e.vaultContract,kt.SwapExactIn,ks(e.poolIds,e.flashLoanAmount),e.assets),s={[t]:Ds(n[0]).toString(),[a]:Ds(n[1]).toString()};return{profits:s,isProfitable:Ns([s[t],s[a]])>0}}catch(e){throw`Failed to querySimpleFlashSwap: ${e}`}}({...e,vaultContract:this.vaultContract})}async getSorSwap(e){return await Oa(e.tokenIn,e.tokenOut,e.swapType,e.amount,this.sor)}}const Hs=new t(Cs);class js{constructor(e){this.swaps=e instanceof Vs?e:new Vs(e)}static isChainedReference(e){const t=d.from(e),a=d.from("0xfff0000000000000000000000000000000000000000000000000000000000000"),n=t.toBigInt()&a.toBigInt();return"0xba10000000000000000000000000000000000000000000000000000000000000"===d.from(n)._hex.toString()}static encodeApproveVault(e,t){return Hs.encodeFunctionData("approveVault",[e,t])}static encodeSetRelayerApproval(e,t,a){return Hs.encodeFunctionData("setRelayerApproval",[e,t,a])}static encodeGaugeWithdraw(e,t,a,n){return Hs.encodeFunctionData("gaugeWithdraw",[e,t,a,n])}static encodeGaugeDeposit(e,t,a,n){return Hs.encodeFunctionData("gaugeDeposit",[e,t,a,n])}static encodeBatchSwap(e){return Hs.encodeFunctionData("batchSwap",[e.swapType,e.swaps,e.assets,e.funds,e.limits,e.deadline,e.value,e.outputReferences])}static encodeExitPool(e){return Hs.encodeFunctionData("exitPool",[e.poolId,e.poolKind,e.sender,e.recipient,e.exitPoolRequest,e.outputReferences])}static encodeJoinPool(e){return Hs.encodeFunctionData("joinPool",[e.poolId,e.kind,e.sender,e.recipient,e.joinPoolRequest,e.value,e.outputReference])}static encodeWrapAaveDynamicToken(e){return Hs.encodeFunctionData("wrapAaveDynamicToken",[e.staticToken,e.sender,e.recipient,e.amount,e.fromUnderlying,e.outputReference])}static encodeUnwrapAaveStaticToken(e){return Hs.encodeFunctionData("unwrapAaveStaticToken",[e.staticToken,e.sender,e.recipient,e.amount,e.toUnderlying,e.outputReferences])}static encodePeekChainedReferenceValue(e){return Hs.encodeFunctionData("peekChainedReferenceValue",[e])}static toChainedReference(e,t=!0){const a=t?js.CHAINED_REFERENCE_TEMP_PREFIX:js.CHAINED_REFERENCE_READONLY_PREFIX,n=`0x${a}${"0".repeat(64-a.length)}`;return d.from(n).add(e)}static fromChainedReference(e,t=!0){const a=t?js.CHAINED_REFERENCE_TEMP_PREFIX:js.CHAINED_REFERENCE_READONLY_PREFIX,n=`0x${a}${"0".repeat(64-a.length)}`;return d.from(e).sub(d.from(n))}static constructExitCall(e){const{assets:t,minAmountsOut:a,userData:n,toInternalBalance:s,poolId:i,poolKind:r,sender:o,recipient:d,outputReferences:c}=e,l={poolId:i,poolKind:r,sender:o,recipient:d,outputReferences:c,exitPoolRequest:{assets:t,minAmountsOut:a,userData:n,toInternalBalance:s}};return js.encodeExitPool(l)}static constructJoinCall(e){const{assets:t,maxAmountsIn:a,userData:n,fromInternalBalance:s,poolId:i,kind:r,sender:o,recipient:d,value:c,outputReference:l}=e,p={poolId:i,kind:r,sender:o,recipient:d,value:c,outputReference:l,joinPoolRequest:{assets:t,maxAmountsIn:a,userData:n,fromInternalBalance:s}};return js.encodeJoinPool(p)}async fetchPools(){return this.swaps.fetchPools()}getPools(){return this.swaps.getPools()}async exitPoolAndBatchSwap(e){const t=n.sub(d.from(e.slippage)),a=e.expectedAmountsOut.map((e=>d.from(e).mul(t).div(n).toString())),s=[];e.exitTokens.forEach(((e,t)=>{const a=js.toChainedReference(t);s.push({index:t,key:a})}));const i=js.constructExitCall({assets:e.exitTokens,minAmountsOut:a,userData:e.userData,toInternalBalance:!0,poolId:e.poolId,poolKind:0,sender:e.exiter,recipient:e.exiter,outputReferences:s,exitPoolRequest:{}}),o=await this.swaps.queryBatchSwapWithSor({tokensIn:e.exitTokens,tokensOut:e.finalTokensOut,swapType:kt.SwapExactIn,amounts:a,fetchPools:e.fetchPools});if(o.returnAmounts.includes("0"))throw new $t(Gt.SWAP_ZERO_RETURN_AMOUNT);o.swaps.forEach((t=>{const a=o.assets[t.assetInIndex],n=e.exitTokens.indexOf(a);-1!==n&&(t.amount=s[n].key.toString())}));const c=n.add(e.slippage);e.exitTokens.forEach(((t,a)=>{const s=o.assets.map((e=>e.toLowerCase())).indexOf(t.toLowerCase());-1!==s&&(o.deltas[s]=d.from(e.expectedAmountsOut[a]).mul(c).div(n).toString())}));const l=Vs.getLimitsForSlippage(e.exitTokens,e.finalTokensOut,kt.SwapExactIn,o.deltas,o.assets,"0"),p={sender:e.exiter,recipient:e.swapRecipient,fromInternalBalance:!0,toInternalBalance:!1};return{function:"multicall",params:[i,js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:o.swaps,assets:o.assets,funds:p,limits:l.map((e=>e.toString())),deadline:r,value:"0",outputReferences:[]})],outputs:{amountsOut:o.returnAmounts}}}async swapUnwrapAaveStaticExactIn(e,t,a,i,r,o,c={fetchPools:!0,fetchOnChain:!1}){const l=await this.swaps.queryBatchSwapWithSor({tokensIn:e,tokensOut:t,swapType:kt.SwapExactIn,amounts:a,fetchPools:c});if(l.returnAmounts.includes("0"))throw new $t(Gt.SWAP_ZERO_RETURN_AMOUNT);const p=Vs.getLimitsForSlippage(e,t,kt.SwapExactIn,l.deltas,l.assets,o);return{function:"multicall",params:this.encodeSwapUnwrap(t,kt.SwapExactIn,l.swaps,l.assets,r,p),outputs:{amountsOut:l.returnAmounts.map(((e,t)=>{const a=d.from(e).abs().mul(i[t]).div(n);if(!a.gt(s))throw new $t(Gt.UNWRAP_ZERO_AMOUNT);return a.toString()}))}}}async swapUnwrapAaveStaticExactOut(e,t,a,i,r,o,c={fetchPools:!0,fetchOnChain:!1}){const l=a.map(((e,t)=>{const a=d.from(e).mul(n).div(i[t]);if(!a.gt(s))throw new $t(Gt.WRAP_ZERO_AMOUNT);return a.toString()})),p=await this.swaps.queryBatchSwapWithSor({tokensIn:e,tokensOut:t,swapType:kt.SwapExactOut,amounts:l,fetchPools:c});if(p.returnAmounts.includes("0"))throw new $t(Gt.SWAP_ZERO_RETURN_AMOUNT);const u=Vs.getLimitsForSlippage(e,t,kt.SwapExactOut,p.deltas,p.assets,o);return{function:"multicall",params:this.encodeSwapUnwrap(t,kt.SwapExactOut,p.swaps,p.assets,r,u),outputs:{amountsIn:p.returnAmounts.map((e=>e.toString()))}}}encodeSwapUnwrap(e,t,a,n,s,i){const o=[],d=[];e.forEach(((e,t)=>{const a=n.findIndex((t=>t.toLowerCase()===e.toLowerCase()));if(-1===a)return;const i=js.toChainedReference(t);o.push({index:a,key:i});const r=js.encodeUnwrapAaveStaticToken({staticToken:e,sender:s.recipient,recipient:s.sender,amount:i,toUnderlying:!0,outputReferences:0});d.push(r)}));return[js.encodeBatchSwap({swapType:t,swaps:a,assets:n,funds:s,limits:i.map((e=>e.toString())),deadline:r,value:"0",outputReferences:o}),...d]}}js.CHAINED_REFERENCE_TEMP_PREFIX="ba10",js.CHAINED_REFERENCE_READONLY_PREFIX="ba11",js.signRelayerApproval=async(e,t,a,n)=>{const s=n.interface.encodeFunctionData("setRelayerApproval",[t,e,!0]),i=await Pe.signSetRelayerApprovalAuthorization(n,a,e,s);return Pe.encodeCalldataAuthorization("0x",r,i)};class Xs{constructor(e){this.url=vs(e).urls.subgraph,this.client=this.initClient()}initClient(){return Wn(new W(this.url))}}class Ks{constructor(e,t){this.swaps=t||new Vs(e)}async fetchPools(){return this.swaps.fetchPools()}getPools(){return this.swaps.getPools()}async getSpotPrice(e,t,a=[]){0===a.length&&(await this.fetchPools(),a=this.getPools());const n=R(a,0),s=this.swaps.sor.routeProposer.getCandidatePathsFromDict(e,t,0,n,4);if(0===s.length)throw new $t(Gt.UNSUPPORTED_PAIR);return M(s[0],0,P).toString()}}var Ys=[{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"}];function Js(e){return Math.round(Date.now()/1e3)-e<86400}var Zs=[{name:"Deposit",inputs:[{name:"provider",type:"address",indexed:!0},{name:"value",type:"uint256",indexed:!1},{name:"locktime",type:"uint256",indexed:!0},{name:"type",type:"int128",indexed:!1},{name:"ts",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{name:"Withdraw",inputs:[{name:"provider",type:"address",indexed:!0},{name:"value",type:"uint256",indexed:!1},{name:"ts",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{name:"Supply",inputs:[{name:"prevSupply",type:"uint256",indexed:!1},{name:"supply",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{stateMutability:"nonpayable",type:"constructor",inputs:[{name:"token_addr",type:"address"},{name:"_name",type:"string"},{name:"_symbol",type:"string"},{name:"_authorizer_adaptor",type:"address"}],outputs:[]},{stateMutability:"view",type:"function",name:"token",inputs:[],outputs:[{name:"",type:"address"}]},{stateMutability:"view",type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string"}]},{stateMutability:"view",type:"function",name:"symbol",inputs:[],outputs:[{name:"",type:"string"}]},{stateMutability:"view",type:"function",name:"decimals",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"admin",inputs:[],outputs:[{name:"",type:"address"}]},{stateMutability:"nonpayable",type:"function",name:"commit_smart_wallet_checker",inputs:[{name:"addr",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"apply_smart_wallet_checker",inputs:[],outputs:[]},{stateMutability:"view",type:"function",name:"get_last_user_slope",inputs:[{name:"addr",type:"address"}],outputs:[{name:"",type:"int128"}]},{stateMutability:"view",type:"function",name:"user_point_history__ts",inputs:[{name:"_addr",type:"address"},{name:"_idx",type:"uint256"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"locked__end",inputs:[{name:"_addr",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"nonpayable",type:"function",name:"checkpoint",inputs:[],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"deposit_for",inputs:[{name:"_addr",type:"address"},{name:"_value",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"create_lock",inputs:[{name:"_value",type:"uint256"},{name:"_unlock_time",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"increase_amount",inputs:[{name:"_value",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"increase_unlock_time",inputs:[{name:"_unlock_time",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"withdraw",inputs:[],outputs:[]},{stateMutability:"view",type:"function",name:"balanceOf",inputs:[{name:"addr",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"balanceOf",inputs:[{name:"addr",type:"address"},{name:"_t",type:"uint256"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"balanceOfAt",inputs:[{name:"addr",type:"address"},{name:"_block",type:"uint256"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"totalSupply",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"totalSupply",inputs:[{name:"t",type:"uint256"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"totalSupplyAt",inputs:[{name:"_block",type:"uint256"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"supply",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"locked",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"tuple",components:[{name:"amount",type:"int128"},{name:"end",type:"uint256"}]}]},{stateMutability:"view",type:"function",name:"epoch",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"point_history",inputs:[{name:"arg0",type:"uint256"}],outputs:[{name:"",type:"tuple",components:[{name:"bias",type:"int128"},{name:"slope",type:"int128"},{name:"ts",type:"uint256"},{name:"blk",type:"uint256"}]}]},{stateMutability:"view",type:"function",name:"user_point_history",inputs:[{name:"arg0",type:"address"},{name:"arg1",type:"uint256"}],outputs:[{name:"",type:"tuple",components:[{name:"bias",type:"int128"},{name:"slope",type:"int128"},{name:"ts",type:"uint256"},{name:"blk",type:"uint256"}]}]},{stateMutability:"view",type:"function",name:"user_point_epoch",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"slope_changes",inputs:[{name:"arg0",type:"uint256"}],outputs:[{name:"",type:"int128"}]},{stateMutability:"view",type:"function",name:"future_smart_wallet_checker",inputs:[],outputs:[{name:"",type:"address"}]},{stateMutability:"view",type:"function",name:"smart_wallet_checker",inputs:[],outputs:[{name:"",type:"address"}]}];class zs{constructor(e,t){this.addresses=e,this.provider=t}async getLockInfo(e){if(!this.addresses.veBal)throw new Error("veBal address must be defined");const t=new Ts(this.addresses.multicall,this.provider,Zs);t.call("locked",this.addresses.veBal,"locked",[e]),t.call("epoch",this.addresses.veBal,"epoch"),t.call("totalSupply",this.addresses.veBal,"totalSupply()");const a=await t.execute();return this.formatLockInfo(a)}formatLockInfo(e){const[t,a]=e.locked,n=t.gt(0),s=1e3*a.toNumber();const i=n&&Date.now()>s;return{lockedEndDate:s,lockedAmount:rt(t),totalSupply:rt(e.totalSupply),epoch:rt(e.epoch,0),hasExistingLock:n,isExpired:i}}}var Qs=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"contract IERC20",name:"votingEscrow",type:"address"},{internalType:"contract IVeDelegation",name:"delegation",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"newImplementation",type:"address"}],name:"DelegationImplementationUpdated",type:"event"},{inputs:[{internalType:"address",name:"user",type:"address"}],name:"adjustedBalanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"}],name:"adjusted_balance_of",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"getActionId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAuthorizer",outputs:[{internalType:"contract IAuthorizer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getDelegationImplementation",outputs:[{internalType:"contract IVeDelegation",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVotingEscrow",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"killDelegation",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IVeDelegation",name:"delegation",type:"address"}],name:"setDelegation",outputs:[],stateMutability:"nonpayable",type:"function"}];class ei{constructor(e,t){if(!e.veBalProxy)throw new Error("veBalProxy address must be defined");this.instance=new u(e.veBalProxy,Qs,t)}async getAdjustedBalance(e){return rt(await this.instance.adjustedBalanceOf(e))}}var ti=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"address",name:"libraryAddress",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"getLibrary",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes[]",name:"data",type:"bytes[]"}],name:"multicall",outputs:[{internalType:"bytes[]",name:"results",type:"bytes[]"}],stateMutability:"payable",type:"function"},{stateMutability:"payable",type:"receive"}],ai=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"address",name:"libraryAddress",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"getLibrary",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes[]",name:"data",type:"bytes[]"}],name:"multicall",outputs:[{internalType:"bytes[]",name:"results",type:"bytes[]"}],stateMutability:"payable",type:"function"},{stateMutability:"payable",type:"receive"}];const ni=(e,t,a)=>{switch(a){case 3:return new u(e,ai,t);case 4:return new u(e,ti,t);default:throw new Error("relayer not supported")}};var si=[{name:"Deposit",inputs:[{name:"provider",type:"address",indexed:!0},{name:"value",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{name:"Withdraw",inputs:[{name:"provider",type:"address",indexed:!0},{name:"value",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{name:"UpdateLiquidityLimit",inputs:[{name:"user",type:"address",indexed:!0},{name:"original_balance",type:"uint256",indexed:!1},{name:"original_supply",type:"uint256",indexed:!1},{name:"working_balance",type:"uint256",indexed:!1},{name:"working_supply",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{name:"Transfer",inputs:[{name:"_from",type:"address",indexed:!0},{name:"_to",type:"address",indexed:!0},{name:"_value",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{name:"Approval",inputs:[{name:"_owner",type:"address",indexed:!0},{name:"_spender",type:"address",indexed:!0},{name:"_value",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{stateMutability:"nonpayable",type:"constructor",inputs:[{name:"minter",type:"address"},{name:"veBoostProxy",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"deposit",inputs:[{name:"_value",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"deposit",inputs:[{name:"_value",type:"uint256"},{name:"_addr",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"deposit",inputs:[{name:"_value",type:"uint256"},{name:"_addr",type:"address"},{name:"_claim_rewards",type:"bool"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"withdraw",inputs:[{name:"_value",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"withdraw",inputs:[{name:"_value",type:"uint256"},{name:"_claim_rewards",type:"bool"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"claim_rewards",inputs:[],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"claim_rewards",inputs:[{name:"_addr",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"claim_rewards",inputs:[{name:"_addr",type:"address"},{name:"_receiver",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"transferFrom",inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"transfer",inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"approve",inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"permit",inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"},{name:"_value",type:"uint256"},{name:"_deadline",type:"uint256"},{name:"_v",type:"uint8"},{name:"_r",type:"bytes32"},{name:"_s",type:"bytes32"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"increaseAllowance",inputs:[{name:"_spender",type:"address"},{name:"_added_value",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"decreaseAllowance",inputs:[{name:"_spender",type:"address"},{name:"_subtracted_value",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"user_checkpoint",inputs:[{name:"addr",type:"address"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"set_rewards_receiver",inputs:[{name:"_receiver",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"kick",inputs:[{name:"addr",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"deposit_reward_token",inputs:[{name:"_reward_token",type:"address"},{name:"_amount",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"add_reward",inputs:[{name:"_reward_token",type:"address"},{name:"_distributor",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"set_reward_distributor",inputs:[{name:"_reward_token",type:"address"},{name:"_distributor",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"set_killed",inputs:[{name:"_is_killed",type:"bool"}],outputs:[]},{stateMutability:"view",type:"function",name:"claimed_reward",inputs:[{name:"_addr",type:"address"},{name:"_token",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"claimable_reward",inputs:[{name:"_user",type:"address"},{name:"_reward_token",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"claimable_reward_write",inputs:[{name:"_addr",type:"address"},{name:"_token",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"claimable_tokens",inputs:[{name:"addr",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"integrate_checkpoint",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"future_epoch_time",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"inflation_rate",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"decimals",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"version",inputs:[],outputs:[{name:"",type:"string"}]},{stateMutability:"view",type:"function",name:"allowance",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"nonpayable",type:"function",name:"initialize",inputs:[{name:"_lp_token",type:"address"}],outputs:[]},{stateMutability:"view",type:"function",name:"balanceOf",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"totalSupply",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string"}]},{stateMutability:"view",type:"function",name:"symbol",inputs:[],outputs:[{name:"",type:"string"}]},{stateMutability:"view",type:"function",name:"DOMAIN_SEPARATOR",inputs:[],outputs:[{name:"",type:"bytes32"}]},{stateMutability:"view",type:"function",name:"nonces",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"factory",inputs:[],outputs:[{name:"",type:"address"}]},{stateMutability:"view",type:"function",name:"lp_token",inputs:[],outputs:[{name:"",type:"address"}]},{stateMutability:"view",type:"function",name:"is_killed",inputs:[],outputs:[{name:"",type:"bool"}]},{stateMutability:"view",type:"function",name:"reward_count",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"reward_data",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"tuple",components:[{name:"token",type:"address"},{name:"distributor",type:"address"},{name:"period_finish",type:"uint256"},{name:"rate",type:"uint256"},{name:"last_update",type:"uint256"},{name:"integral",type:"uint256"}]}]},{stateMutability:"view",type:"function",name:"rewards_receiver",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"address"}]},{stateMutability:"view",type:"function",name:"reward_integral_for",inputs:[{name:"arg0",type:"address"},{name:"arg1",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"working_balances",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"working_supply",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"integrate_inv_supply_of",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"integrate_checkpoint_of",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"integrate_fraction",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"period",inputs:[],outputs:[{name:"",type:"int128"}]},{stateMutability:"view",type:"function",name:"reward_tokens",inputs:[{name:"arg0",type:"uint256"}],outputs:[{name:"",type:"address"}]},{stateMutability:"view",type:"function",name:"period_timestamp",inputs:[{name:"arg0",type:"uint256"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"integrate_inv_supply",inputs:[{name:"arg0",type:"uint256"}],outputs:[{name:"",type:"uint256"}]}];class ii{constructor(e,t){this.contractAddresses="number"==typeof e?Lt[e].addresses.contracts:e,this.vault=L.connect(this.contractAddresses.vault,t),this.balancerHelpers=U.connect(this.contractAddresses.balancerHelpers,t),this.contractAddresses.lidoRelayer&&(this.lidoRelayer=G.connect(this.contractAddresses.lidoRelayer,t)),this.multicall=hs(this.contractAddresses.multicall,t),this.contractAddresses.relayerV3&&(this.relayerV3=ni(this.contractAddresses.relayerV3,t,3)),this.contractAddresses.relayerV4&&(this.relayerV4=ni(this.contractAddresses.relayerV4,t,4)),this.contractAddresses.veBal&&(this.veBal=new zs(this.contractAddresses,t)),this.contractAddresses.veBalProxy&&(this.veBalProxy=new ei(this.contractAddresses,t))}get contracts(){return{vault:this.vault,balancerHelpers:this.balancerHelpers,lidoRelayer:this.lidoRelayer,multicall:this.multicall,relayerV3:this.relayerV3,relayerV4:this.relayerV4,veBal:this.veBal,veBalProxy:this.veBalProxy,ERC20:this.getErc20,liquidityGauge:this.getLiquidityGauge}}getErc20(e,t){return((e,t)=>new u(e,Ys,t))(e,t)}getLiquidityGauge(e,t){return((e,t)=>new u(e,si,t))(e,t)}}const ri={1:{relayer:"0x886A3Ec7bcC508B8795990B60Fa21f85F9dB7948",staBal3:{id:"0x06df3b2bbb68adc8b0e302443692037ed9f91b42000000000000000000000063",address:"0x06df3b2bbb68adc8b0e302443692037ed9f91b42",gauge:"0x34f33cdaed8ba0e1ceece80e5f4a73bcf234cfac",assetOrder:["DAI","USDC","USDT"]},bbausd1:{id:"0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb20000000000000000000000fe",address:"0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb2",gauge:"0x68d019f64a7aa97e2d4e7363aee42251d08124fb",assetOrder:["bb-a-USDT","bb-a-DAI","bb-a-USDC"]},bbausd2:{id:"0xa13a9247ea42d743238089903570127dda72fe4400000000000000000000035d",address:"0xa13a9247ea42d743238089903570127dda72fe44",gauge:"0xa6325e799d266632d347e41265a69af111b05403"},linearUsdc1:{id:"0x9210f1204b5a24742eba12f710636d76240df3d00000000000000000000000fc",address:"0x9210F1204b5a24742Eba12f710636D76240dF3d0"},linearDai1:{id:"0x804cdb9116a10bb78768d3252355a1b18067bf8f0000000000000000000000fb",address:"0x804CdB9116a10bB78768D3252355a1b18067bF8f"},linearUsdt1:{id:"0x2bbf681cc4eb09218bee85ea2a5d3d13fa40fc0c0000000000000000000000fd",address:"0x2BBf681cC4eb09218BEe85EA2a5d3D13Fa40fC0C"},linearUsdc2:{id:"0x82698AECC9E28E9BB27608BD52CF57F704BD1B83000000000000000000000336",address:"0x82698aeCc9E28e9Bb27608Bd52cF57f704BD1B83"},linearDai2:{id:"0xAE37D54AE477268B9997D4161B96B8200755935C000000000000000000000337",address:"0xae37D54Ae477268B9997d4161B96b8200755935c"},linearUsdt2:{id:"0x2F4EB100552EF93840D5ADC30560E5513DFFFACB000000000000000000000334",address:"0x2F4eb100552ef93840d5aDC30560E5513DFfFACb"},maiusd:{id:"",address:"",gauge:"",assetOrder:["USDT","miMATIC","DAI","USDC"]},maibbausd:{id:"",address:"",gauge:"",assetOrder:["bb-a-USD","miMATIC"]},DAI:"0x6b175474e89094c44da98b954eedeac495271d0f",USDC:"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",USDT:"0xdAC17F958D2ee523a2206206994597C13D831ec7",waDAI:"0x02d60b84491589974263d922d9cc7a3152618ef6",waUSDC:"0xd093fa4fb80d09bb30817fdcd442d4d02ed3e5de",waUSDT:"0xf8fd466f12e236f4c96f7cce6c79eadb819abf58",miMATIC:""},5:{relayer:"0x7b9B6f094DC2Bd1c12024b0D9CC63d6993Be1888",staBal3:{id:"0xdcdd4a3d36dec8d57594e89763d069a7e9b223e2000000000000000000000062",address:"0xdcdd4a3d36dec8d57594e89763d069a7e9b223e2",gauge:"0xfd364cda96bb7db06b65706182c448a73f0a5f9a",assetOrder:["USDT","DAI","USDC"]},staBal3_2:{id:"0xff9d677474d4344379924e10b68c8fea67e03294000000000000000000000072",address:"0xff9d677474d4344379924e10b68c8fea67e03294",gauge:"0x4e4ebf2aa90e41174d716a5168895357762d68af",assetOrder:["USDT","DAI","USDC"]},staBal3_3:{id:"0x3bfc8a0509f1a68aefd446f6c19bf37b3c75a8fc0000000000000000000000a5",address:"0x3bfc8a0509f1a68aefd446f6c19bf37b3c75a8fc",gauge:"0x7776e1008d7c20ab54aa57a7c44fc7de602de29a",assetOrder:["USDT","DAI","USDC"]},bbausd1:{id:"0x13acd41c585d7ebb4a9460f7c8f50be60dc080cd00000000000000000000005f",address:"0x13acd41c585d7ebb4a9460f7c8f50be60dc080cd",gauge:"0xa2d0ea81a47d68598922cd54c59249ff58c2a3ff",assetOrder:["bb-a-USDC","bb-a-DAI","bb-a-USDT"]},bbausd2:{id:"0x13acd41c585d7ebb4a9460f7c8f50be60dc080cd00000000000000000000005f",address:"0x13acd41c585d7ebb4a9460f7c8f50be60dc080cd",gauge:"0xa2d0ea81a47d68598922cd54c59249ff58c2a3ff"},linearUsdc1:{id:"0x0595d1df64279ddb51f1bdc405fe2d0b4cc8668100000000000000000000005c",address:"0x0595d1df64279ddb51f1bdc405fe2d0b4cc86681"},linearDai1:{id:"0x5cea6a84ed13590ed14903925fa1a73c36297d9900000000000000000000005d",address:"0x5cea6a84ed13590ed14903925fa1a73c36297d99"},linearUsdt1:{id:"0xefd681a82970ac5d980b9b2d40499735e7bf3f1f00000000000000000000005e",address:"0xefd681a82970ac5d980b9b2d40499735e7bf3f1f"},linearUsdc2:{id:"0x0595d1df64279ddb51f1bdc405fe2d0b4cc8668100000000000000000000005c",address:"0x0595d1df64279ddb51f1bdc405fe2d0b4cc86681"},linearDai2:{id:"0x5cea6a84ed13590ed14903925fa1a73c36297d9900000000000000000000005d",address:"0x5cea6a84ed13590ed14903925fa1a73c36297d99"},linearUsdt2:{id:"0xefd681a82970ac5d980b9b2d40499735e7bf3f1f00000000000000000000005e",address:"0xefd681a82970ac5d980b9b2d40499735e7bf3f1f"},maiusd:{id:"0x6a8f9ab364b85725973d2a33cb9aae2dac43b5e30000000000000000000000a6",address:"0x6a8f9ab364b85725973d2a33cb9aae2dac43b5e3",gauge:"0x58141bdcecb7fbae006964f4131cf6f65c948357",assetOrder:["USDT","miMATIC","DAI","USDC"]},maibbausd:{id:"0xb04b03b78cf79788a1931545bd2744161029648f0000000000000000000000a8",address:"0xb04b03b78cf79788a1931545bd2744161029648f",gauge:"0xdc3f6fc8898830e53c777543fe252b14f22680d4",assetOrder:["bb-a-USD","miMATIC","MAI BSP"]},USDT:"0x1f1f156e0317167c11aa412e3d1435ea29dc3cce",DAI:"0x8c9e6c40d3402480ace624730524facc5482798c",USDC:"0xe0c9275e44ea80ef17579d33c55136b7da269aeb",waDAI:"0x89534a24450081aa267c79b07411e9617d984052",waUSDC:"0x811151066392fd641fe74a9b55a712670572d161",waUSDT:"0x4cb1892fddf14f772b2e39e299f44b2e5da90d04",miMATIC:"0x398106564948feeb1fedea0709ae7d969d62a391"},137:{relayer:"0xcf6a66E32dCa0e26AcC3426b851FD8aCbF12Dac7",staBal3:{id:"",address:"",gauge:"",assetOrder:["USDT","DAI","USDC"]},bbausd1:{id:"",address:"",gauge:"",assetOrder:["bb-a-USDC","bb-a-DAI","bb-a-USDT"]},bbausd2:{id:"0x48e6b98ef6329f8f0a30ebb8c7c960330d64808500000000000000000000075b",address:"0x48e6b98ef6329f8f0a30ebb8c7c960330d648085",gauge:""},linearUsdc1:{id:"",address:""},linearDai1:{id:"",address:""},linearUsdt1:{id:"",address:""},linearUsdc2:{id:"0xf93579002dbe8046c43fefe86ec78b1112247bb8000000000000000000000759",address:"0xf93579002dbe8046c43fefe86ec78b1112247bb8"},linearDai2:{id:"0x178e029173417b1f9c8bc16dcec6f697bc323746000000000000000000000758",address:"0x178e029173417b1f9c8bc16dcec6f697bc323746"},linearUsdt2:{id:"0xff4ce5aaab5a627bf82f4a571ab1ce94aa365ea600000000000000000000075a",address:"0xff4ce5aaab5a627bf82f4a571ab1ce94aa365ea6"},maiusd:{id:"0x06df3b2bbb68adc8b0e302443692037ed9f91b42000000000000000000000012",address:"0x06df3b2bbb68adc8b0e302443692037ed9f91b42",gauge:"0x72843281394e68de5d55bcf7072bb9b2ebc24150",assetOrder:["USDC","DAI","miMATIC","USDT"]},maibbausd:{id:"0xb54b2125b711cd183edd3dd09433439d5396165200000000000000000000075e",address:"0xb54b2125b711cd183edd3dd09433439d53961652",gauge:"0x9a105ef22a59484aa2731c357049f6a13d0891f5",assetOrder:["bb-a-USD","miMATIC"]},USDT:"0xc2132d05d31c914a87c6611c10748aeb04b58e8f",DAI:"0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",USDC:"0x2791bca1f2de4661ed88a30c99a7a9449aa84174",waDAI:"0xEE029120c72b0607344f35B17cdD90025e647B00",waUSDC:"0x221836a597948Dce8F3568E044fF123108aCc42A",waUSDT:"0x19C60a251e525fa88Cd6f3768416a8024e98fC19",miMATIC:"0xa3fa99a148fa48d14ed51d610c367c61876997f1"}},oi=new t(ai),di=js.toChainedReference("21"),ci=js.toChainedReference("22"),li=js.toChainedReference("23"),pi=js.toChainedReference("24");class ui{constructor(e){this.addresses=ri[e]}calldata(e,t,a,n,s){if(d.from(t).lte(0))throw new $t(Gt.INPUT_ZERO_NOT_ALLOWED);const i=this.addresses.relayer;let r=[];s&&(r=[this.buildSetRelayerApproval(s)]),r=n?[...r,this.buildWithdraw(e,t),this.buildExit(i,t),this.buildSwap(a,i),this.buildDeposit(e)]:[...r,this.buildExit(e,t),this.buildSwap(a,e)];return{to:i,data:oi.encodeFunctionData("multicall",[r])}}buildExit(e,t){const{assetOrder:a}=this.addresses.staBal3,n=a.map((e=>this.addresses[e])),s=Z.exitExactBPTInForTokensOut(t),i=[{index:a.indexOf("DAI"),key:di},{index:a.indexOf("USDC"),key:ci},{index:a.indexOf("USDT"),key:li}];return js.constructExitCall({assets:n,minAmountsOut:["0","0","0"],userData:s,toInternalBalance:!0,poolId:this.addresses.staBal3.id,poolKind:0,sender:e,recipient:this.addresses.relayer,outputReferences:i,exitPoolRequest:{}})}buildSwap(e,t){const a=[this.addresses.bbausd2.address,this.addresses.DAI,this.addresses.linearDai2.address,this.addresses.USDC,this.addresses.linearUsdc2.address,this.addresses.USDT,this.addresses.linearUsdt2.address],n=[{index:0,key:pi}],s=[{poolId:this.addresses.linearDai2.id,assetInIndex:1,assetOutIndex:2,amount:di.toString(),userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:2,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.linearUsdc2.id,assetInIndex:3,assetOutIndex:4,amount:ci.toString(),userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:4,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.linearUsdt2.id,assetInIndex:5,assetOutIndex:6,amount:li.toString(),userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:6,assetOutIndex:0,amount:"0",userData:"0x"}],i=[d.from(e).mul(-1).toString(),o.toString(),"0",o.toString(),"0",o.toString(),"0"],r={sender:this.addresses.relayer,recipient:t,fromInternalBalance:!0,toInternalBalance:!1};return js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:s,assets:a,funds:r,limits:i,deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:n})}buildWithdraw(e,t){return js.encodeGaugeWithdraw(this.addresses.staBal3.gauge,e,this.addresses.relayer,t)}buildDeposit(e){return js.encodeGaugeDeposit(this.addresses.bbausd2.gauge,this.addresses.relayer,e,pi.toString())}buildSetRelayerApproval(e){return js.encodeSetRelayerApproval(this.addresses.relayer,!0,e)}}const yi=new t(ai),bi=js.toChainedReference("24");class fi{constructor(e){this.addresses=ri[e]}calldata(e,t,a,n,s,i){if(d.from(t).lte(0))throw new $t(Gt.INPUT_ZERO_NOT_ALLOWED);const r=this.addresses.relayer;let o=[];i&&(o=[this.buildSetRelayerApproval(i)]),o=n?[...o,this.buildWithdraw(e,t),this.buildSwap(t,a,r,r,s),this.buildDeposit(e)]:[...o,this.buildSwap(t,a,e,e,s)];const c=yi.encodeFunctionData("multicall",[o]);return{to:this.addresses.relayer,data:c}}buildSwap(e,t,a,n,i){const r=[this.addresses.bbausd2.address,this.addresses.waDAI,this.addresses.linearDai1.address,this.addresses.linearDai2.address,this.addresses.waUSDC,this.addresses.linearUsdc1.address,this.addresses.linearUsdc2.address,this.addresses.waUSDT,this.addresses.linearUsdt1.address,this.addresses.linearUsdt2.address,this.addresses.bbausd1.address],o=[{index:0,key:bi}],c=i.reduce(((e,t)=>e.add(d.from(t))),s),{assetOrder:l}=this.addresses.bbausd1,p=d.from(e).mul(i[l.indexOf("bb-a-USDC")]).div(c).toString(),u=d.from(e).mul(i[l.indexOf("bb-a-DAI")]).div(c).toString(),y=d.from(e).sub(p).sub(u).toString(),b=[{poolId:this.addresses.bbausd1.id,assetInIndex:10,assetOutIndex:2,amount:u,userData:"0x"},{poolId:this.addresses.linearDai1.id,assetInIndex:2,assetOutIndex:1,amount:"0",userData:"0x"},{poolId:this.addresses.linearDai2.id,assetInIndex:1,assetOutIndex:3,amount:"0",userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:3,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.bbausd1.id,assetInIndex:10,assetOutIndex:5,amount:p,userData:"0x"},{poolId:this.addresses.linearUsdc1.id,assetInIndex:5,assetOutIndex:4,amount:"0",userData:"0x"},{poolId:this.addresses.linearUsdc2.id,assetInIndex:4,assetOutIndex:6,amount:"0",userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:6,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.bbausd1.id,assetInIndex:10,assetOutIndex:8,amount:y,userData:"0x"},{poolId:this.addresses.linearUsdt1.id,assetInIndex:8,assetOutIndex:7,amount:"0",userData:"0x"},{poolId:this.addresses.linearUsdt2.id,assetInIndex:7,assetOutIndex:9,amount:"0",userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:9,assetOutIndex:0,amount:"0",userData:"0x"}],f=[d.from(t).mul(-1).toString(),"0","0","0","0","0","0","0","0","0",e],m={sender:a,recipient:n,fromInternalBalance:!1,toInternalBalance:!1};return js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:b,assets:r,funds:m,limits:f,deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:o})}buildWithdraw(e,t){return js.encodeGaugeWithdraw(this.addresses.bbausd1.gauge,e,this.addresses.relayer,t)}buildDeposit(e){return js.encodeGaugeDeposit(this.addresses.bbausd2.gauge,this.addresses.relayer,e,bi.toString())}buildSetRelayerApproval(e){return js.encodeSetRelayerApproval(this.addresses.relayer,!0,e)}}const mi=new t(ai),hi=js.toChainedReference("0"),Ti=[];class gi{constructor(e){this.addresses=ri[e]}calldata(e,t,a,n,s,i,r,o){if(i&&(null==t.gauge||null==a.gauge))throw new Error("Staked flow migration requires gauge addresses to be provided");const d=this.addresses.relayer;let c=[];o&&(c=[this.buildSetRelayerApproval(o)]),c=i?[...c,this.buildWithdraw(e,n,t.gauge),this.buildExit(t.id,d,n,r),this.buildSwap(s,d,a.id,a.address,r),this.buildDeposit(e,a.gauge)]:[...c,this.buildExit(t.id,e,n,r),this.buildSwap(s,e,a.id,a.address,r)];const l=mi.encodeFunctionData("multicall",[c]);return{to:this.addresses.relayer,data:l}}buildExit(e,t,a,n){const s=Z.exitExactBPTInForTokensOut(a),i=[];for(let e=0;e<n.length;e++)i[e]={index:e,key:js.toChainedReference(`${e+1}`)},Ti.push(i[e].key);const r=Array(n.length).fill("0");return js.constructExitCall({assets:n,minAmountsOut:r,userData:s,toInternalBalance:!0,poolId:e,poolKind:0,sender:t,recipient:this.addresses.relayer,outputReferences:i,exitPoolRequest:{}})}buildSwap(e,t,a,n,s){const i=[n,...s],r=[{index:0,key:hi}],c=[];for(let e=0;e<s.length;e++)c.push({poolId:a,assetInIndex:e+1,assetOutIndex:0,amount:Ti[e].toString(),userData:"0x"});const l=[d.from(e).mul(-1).toString()];for(let e=0;e<s.length;e++)l.push(o.toString());const p={sender:this.addresses.relayer,recipient:t,fromInternalBalance:!0,toInternalBalance:!1};return js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:c,assets:i,funds:p,limits:l,deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:r})}buildWithdraw(e,t,a){return js.encodeGaugeWithdraw(a,e,this.addresses.relayer,t)}buildDeposit(e,t){return js.encodeGaugeDeposit(t,this.addresses.relayer,e,hi.toString())}buildSetRelayerApproval(e){return js.encodeSetRelayerApproval(this.addresses.relayer,!0,e)}}const Ii=new t(ai),wi=js.toChainedReference("20"),Ei=js.toChainedReference("21"),xi=js.toChainedReference("22"),Ai=js.toChainedReference("23"),Si=js.toChainedReference("24");class Pi{constructor(e){this.addresses=ri[e]}calldata(e,t,a,n,s){if(d.from(t).lte(0))throw new $t(Gt.INPUT_ZERO_NOT_ALLOWED);const i=this.addresses.relayer;let r=[];s&&(r=[this.buildSetRelayerApproval(s)]),r=n?[...r,this.buildWithdraw(e,t),this.buildExit(i,t),this.buildSwap(i,a),this.buildDeposit(e)]:[...r,this.buildExit(e,t),this.buildSwap(e,a)];return{to:i,data:Ii.encodeFunctionData("multicall",[r])}}buildExit(e,t){const{assetOrder:a}=this.addresses.maiusd,n=a.map((e=>this.addresses[e])),s=Z.exitExactBPTInForTokensOut(t),i=[{index:a.indexOf("miMATIC"),key:wi},{index:a.indexOf("DAI"),key:Ei},{index:a.indexOf("USDC"),key:xi},{index:a.indexOf("USDT"),key:Ai}],r=Array(n.length).fill("0");return js.constructExitCall({assets:n,minAmountsOut:r,userData:s,toInternalBalance:!0,poolId:this.addresses.maiusd.id,poolKind:0,sender:e,recipient:this.addresses.relayer,outputReferences:i,exitPoolRequest:{}})}buildSwap(e,t){const a=[this.addresses.bbausd2.address,this.addresses.DAI,this.addresses.linearDai2.address,this.addresses.USDC,this.addresses.linearUsdc2.address,this.addresses.USDT,this.addresses.linearUsdt2.address,this.addresses.miMATIC,this.addresses.maibbausd.address],n=[{index:8,key:Si}],s=[{poolId:this.addresses.linearDai2.id,assetInIndex:1,assetOutIndex:2,amount:Ei.toString(),userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:2,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.maibbausd.id,assetInIndex:0,assetOutIndex:8,amount:"0",userData:"0x"},{poolId:this.addresses.linearUsdc2.id,assetInIndex:3,assetOutIndex:4,amount:xi.toString(),userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:4,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.maibbausd.id,assetInIndex:0,assetOutIndex:8,amount:"0",userData:"0x"},{poolId:this.addresses.linearUsdt2.id,assetInIndex:5,assetOutIndex:6,amount:Ai.toString(),userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:6,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.maibbausd.id,assetInIndex:0,assetOutIndex:8,amount:"0",userData:"0x"},{poolId:this.addresses.maibbausd.id,assetInIndex:7,assetOutIndex:8,amount:wi.toString(),userData:"0x"}],i=["0",o.toString(),"0",o.toString(),"0",o.toString(),"0",o.toString(),d.from(t).mul(-1).toString()],r={sender:this.addresses.relayer,recipient:e,fromInternalBalance:!0,toInternalBalance:!1};return js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:s,assets:a,funds:r,limits:i,deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:n})}buildWithdraw(e,t){return js.encodeGaugeWithdraw(this.addresses.maiusd.gauge,e,this.addresses.relayer,t)}buildDeposit(e){return js.encodeGaugeDeposit(this.addresses.maibbausd.gauge,this.addresses.relayer,e,Si.toString())}buildSetRelayerApproval(e){return js.encodeSetRelayerApproval(this.addresses.relayer,!0,e)}}class _i{constructor(e){this.network=e}stabal3(t,a,n,s,i){const r=new ui(this.network).calldata(t,a,n,s,i);return{to:r.to,data:r.data,decode:(t,a)=>{let n=a?2:1;i&&(n+=1);const s=e.decode(["bytes[]"],t);return e.decode(["int256[]"],s[0][n])[0][0].abs().toString()}}}bbaUsd(t,a,n,s,i,r){const o=new fi(this.network).calldata(t,a,n,s,i,r);return{to:o.to,data:o.data,decode:(t,a)=>{let n=a?1:0;r&&(n+=1);const s=e.decode(["bytes[]"],t);return e.decode(["int256[]"],s[0][n])[0][0].abs().toString()}}}stables(t,a,n,s,i,r,o,d){const c=new gi(this.network).calldata(t,a,n,s,i,r,o,d);return{to:c.to,data:c.data,decode:(t,a)=>{let n=a?2:1;d&&(n+=1);const s=e.decode(["bytes[]"],t);return e.decode(["int256[]"],s[0][n])[0][0].abs().toString()}}}maiusd(t,a,n,s,i){const r=new Pi(this.network).calldata(t,a,n,s,i);return{to:r.to,data:r.data,decode:(t,a)=>{let n=a?2:1;i&&(n+=1);const s=e.decode(["bytes[]"],t);return e.decode(["int256[]"],s[0][n])[0][8].abs().toString()}}}}class vi{constructor(e){this.network=e,this.migrations=new _i(e)}}class Oi{constructor(e,t){this.tokenPrices=e,this.tokenHistoricalPrices=t}async calcImpLoss(e,t){if(1e3*e>=Date.now())throw console.error(`[ImpermanentLossService][calcImpLoss]Error: ${$t.getMessage(Gt.TIMESTAMP_IN_THE_FUTURE)}`),new $t(Gt.TIMESTAMP_IN_THE_FUTURE);const a=await this.prepareData(e,t),n=this.getPoolValueDelta(a),s=this.getHoldValueDelta(a);return this.calculateImpermanentLoss(n,s)}calculateImpermanentLoss(e,t){return Math.floor(100*Math.abs(e/t-1)*100)/100}getPoolValueDelta(e){return e.reduce(((e,t)=>e*Math.pow(Math.abs(t.priceDelta+1),t.weight)),1)}getHoldValueDelta(e){return e.reduce(((e,t)=>e+Math.abs(t.priceDelta+1)*t.weight),0)}async prepareData(e,t){const a=t.tokens.filter((e=>e.address!==t.address)),n=this.getWeights(a),s=a.map((e=>e.address)),i=await this.getEntryPrices(e,s),r=await this.getExitPrices(a);return this.getAssets(a,r,i,n)}getAssets(e,t,a,n){return e.map(((e,s)=>({priceDelta:this.getDelta(a[e.address],t[e.address]),weight:n[s]})))}getDelta(e,t){if(0===e)throw console.error(`[ImpermanentLossService][getDelta]Error: ${$t.getMessage(Gt.ILLEGAL_PARAMETER)}: entry price is 0`),new $t(Gt.ILLEGAL_PARAMETER);return(t-e)/e}getWeights(e){const t=e.every((e=>!e.weight)),a=Math.round(1/e.length*100)/100,n=t?e.map((()=>a)):e.map((e=>{var t;return Number(null!==(t=e.weight)&&void 0!==t?t:0)}));if(n.some((e=>0===e)))throw console.error(`[ImpermanentLossService][getWeights]Error: ${$t.getMessage(Gt.MISSING_WEIGHT)}`),new $t(Gt.MISSING_WEIGHT);return n}async getExitPrices(e){var t;const a=await Promise.all(e.map((e=>this.tokenPrices.find(e.address)))).catch((()=>[]));if(!a.length||a.some((e=>void 0===(null==e?void 0:e.usd))))throw console.error(`[ImpermanentLossService][getExitPrices]Error: ${$t.getMessage(Gt.MISSING_PRICE_RATE)}`),new $t(Gt.MISSING_PRICE_RATE);const n=e.map(((e,t)=>({...e,price:a[t]}))),s={};for(const e of n)(null===(t=e.price)||void 0===t?void 0:t.usd)&&(s[e.address]=+e.price.usd);return s}async getEntryPrices(e,t){const a={};for(const n of t){const t=await this.tokenHistoricalPrices.findBy(n,e).catch((e=>{console.error(`[ImpermanentLossService][getEntryPrices]Error: ${e.message}`)}));if(!(null==t?void 0:t.usd))throw console.error(`[ImpermanentLossService][getEntryPrices]Error: ${$t.getMessage(Gt.MISSING_PRICE_RATE)}`),new $t(Gt.MISSING_PRICE_RATE);a[n]=+t.usd}return a}}const Bi=335e3,ki=1765411200,Di=(e=Math.round((new Date).getTime()/1e3))=>Bi;var Ni=Object.freeze({__proto__:null,INITIAL_RATE:Bi,START_EPOCH_TIME:ki,weekly:Di,total:e=>365*(Di()/7),between:(e,t)=>{if(e<ki)throw"start timestamp before emission schedule deployment";if(t<e)throw"cannot finish before starting";const a=t-e,n=Di()/7;return Math.round(a/86400)*n}});class Ci{constructor(e,t){this.repository=e,this.tokenPrices=t}async data(e=Date.now()){const t=await this.repository.multicallData(e),a=await this.tokenPrices.find(t.balAddress);if(!a||!a.usd)throw"No BAL USD price found";return{lastWeekBalRevenue:t.balAmount*parseFloat(a.usd),lastWeekBBAUsdRevenue:t.bbAUsdAmount*t.bbAUsdPrice,veBalSupply:t.veBalSupply}}}class Fi{constructor(e){this.yesterdaysPools=e}async last24h(e){let t;return this.yesterdaysPools&&(t=await this.yesterdaysPools.find(e.id)),e.totalSwapFee?(null==t?void 0:t.totalSwapFee)?parseFloat(e.totalSwapFee)-parseFloat(t.totalSwapFee):e.createTime&&Js(e.createTime)?parseFloat(e.totalSwapFee):0:0}}class Ri{constructor(e,t,a,n,s,i,r,o){this.pools=e,this.tokenPrices=t,this.tokenMeta=a,this.tokenYields=n,this.feeCollector=s,this.yesterdaysPools=i,this.liquidityGauges=r,this.feeDistributor=o}async swapFees(e){const t=await this.last24hFees(e),a=await this.totalLiquidity(e);if(!t||!a)return 0;const n=t*(1-await this.protocolSwapFeePercentage(e))/parseFloat(a)*1e4;return Math.round(365*n)}async tokenAprs(e){return{total:0,breakdown:{}}}async stakingApr(e,t=1){if(!this.liquidityGauges)return 0;const a=await this.liquidityGauges.findBy("poolId",e.id);if(!a||(248==e.chainId||9372==e.chainId||6343==e.chainId||4326==e.chainId)&&0==a.workingSupply||248!=e.chainId&&9372!=e.chainId&&6343!=e.chainId&&4326!=e.chainId&&0==a.totalSupply)return 0;const n=Lt[e.chainId].addresses.tokens.bal;if(!n)return 0;const[s,i]=await Promise.all([this.tokenPrices.find(n),this.bptPrice(e)]);if(!(null==s?void 0:s.usd))throw"Missing BAL price";const r=parseFloat(s.usd),o=Di()/7*365*a.relativeWeight*r,d=(a.workingSupply+.4)/.4*i;return Math.round(1e4*t*o/d)}async stakingAprNextPeriod(e,t=1){if(!this.liquidityGauges)return 0;const a=await this.liquidityGauges.findBy("poolId",e.id);if(!a)return 0;if(0==a.workingSupply)return a.relativeWeightNextPeriod&&a.relativeWeightNextPeriod>0?-1:0;const n=Lt[e.chainId].addresses.tokens.bal;if(!n)return 0;const[s,i]=await Promise.all([this.tokenPrices.find(n),this.bptPrice(e)]);if(!(null==s?void 0:s.usd))throw"Missing BAL price";const r=parseFloat(s.usd),o=Di()/7*365*(a.relativeWeightNextPeriod||0)*r,d=(a.workingSupply+.4)/.4*i;return Math.round(1e4*t*o/d)}async rewardAprs(e){if(!this.liquidityGauges)return{total:0,breakdown:{}};const t=await this.liquidityGauges.findBy("poolId",e.id);if(!t)return{total:0,breakdown:{}};if(!t.rewardTokens)return{total:0,breakdown:{}};if(Object.keys(t.rewardTokens).length<1)return{total:0,breakdown:{}};const a=Lt[e.chainId].addresses.tokens.bal,n=Object.keys(t.rewardTokens).filter((e=>e!=a)).map((async e=>{const a=t.rewardTokens[e];return this.rewardTokenApr(e,a)})),s=await this.bptPrice(e),i=t.totalSupply*s,r={};let o=0;for await(const e of Object.values(n)){const t=i>0?e.value/i:0,a=Math.round(1e4*t);o+=a,r[e.address]=a}return{total:o,breakdown:r}}async protocolApr(e){if(""!=e.id||!this.feeDistributor)return 0;const t=new Ci(this.feeDistributor,this.tokenPrices),{lastWeekBalRevenue:a,lastWeekBBAUsdRevenue:n,veBalSupply:s}=await t.data(),i=await this.bptPrice(e);if(!i)throw"bptPrice for veBal pool missing";const r=(a+n)/7;return Math.round(365*r*1e4/(i*s))}async apr(e){const[t,a,n,s,i,r]=await Promise.all([this.swapFees(e),this.tokenAprs(e),this.stakingApr(e),this.stakingApr(e,2.5),this.rewardAprs(e),this.protocolApr(e)]);return{swapFees:t,tokenAprs:a,stakingApr:{min:n,max:s},rewardAprs:i,protocolApr:r,min:t+a.total+i.total+n,max:t+a.total+i.total+r+s}}async aprNextPeriod(e){const[t,a,n,s,i,r]=await Promise.all([this.swapFees(e),this.tokenAprs(e),this.stakingAprNextPeriod(e),this.stakingAprNextPeriod(e,2.5),this.rewardAprs(e),this.protocolApr(e)]);return{swapFees:t,tokenAprs:a,stakingApr:{min:n,max:s},rewardAprs:i,protocolApr:r,min:t+a.total+i.total+n,max:t+a.total+i.total+r+s}}async last24hFees(e){return new Fi(this.yesterdaysPools).last24h(e)}async totalLiquidity(e){try{const t=new Pa(this.pools,this.tokenPrices);return await t.getLiquidity(e)}catch(t){return console.error("Liquidity calculcation failed, falling back to subgraph"),e.totalLiquidity}}async bptPrice(e){const t=await this.totalLiquidity(e),a=e.totalShares;return parseFloat(t)/parseFloat(a)}async protocolSwapFeePercentage(e){let t=0;return t="ComposableStable"==e.poolType||"Weighted"==e.poolType&&2==e.poolTypeVersion?0:e.protocolSwapFeeCache?parseFloat(e.protocolSwapFeeCache):await this.feeCollector.find("")||0,t}async rewardTokenApr(e,t){if(t.period_finish.toNumber()<Date.now()/1e3)return{address:e,value:0};{const a=t.rate.mul(86400).mul(365),n=await this.tokenPrices.find(e);if(n&&n.usd){let s=18;if(t.decimals)s=t.decimals;else{const t=await this.tokenMeta.find(e);t&&void 0!==t.decimals&&(s=t.decimals)}return{address:e,value:parseFloat(rt(a,s))*parseFloat(n.usd)}}throw`No USD price for ${e}`}}}const Mi=new Map;Mi.set(Xe.AaveLinear,"batchSwap"),Mi.set(Xe.EulerLinear,"batchSwap"),Mi.set(Xe.ERC4626Linear,"batchSwap"),Mi.set(Xe.Element,"batchSwap"),Mi.set(Xe.Investment,"joinPool"),Mi.set(Xe.LiquidityBootstrapping,"joinPool"),Mi.set(Xe.MetaStable,"joinPool"),Mi.set(Xe.Stable,"joinPool"),Mi.set(Xe.StablePhantom,"batchSwap"),Mi.set(Xe.Weighted,"joinPool"),Mi.set(Xe.ComposableStable,"joinPool");const Li=new Map;Li.set(Xe.AaveLinear,"batchSwap"),Mi.set(Xe.EulerLinear,"batchSwap"),Li.set(Xe.ERC4626Linear,"batchSwap"),Li.set(Xe.Element,"batchSwap"),Li.set(Xe.Investment,"exitPool"),Li.set(Xe.LiquidityBootstrapping,"exitPool"),Li.set(Xe.MetaStable,"exitPool"),Li.set(Xe.Stable,"exitPool"),Li.set(Xe.StablePhantom,"batchSwap"),Li.set(Xe.Weighted,"exitPool"),Li.set(Xe.ComposableStable,"exitPool");class Ui{constructor(e){this.pools=e}async buildGraphFromRootPool(e,t){const a=await this.pools.find(e);if(!a)throw new $t(Gt.POOL_DOESNT_EXIST);return(await this.buildGraphFromPool(a.address,0,void 0,n,t))[0]}getTokenTotal(e){const t=e.tokensList.indexOf(e.address);let a=s;const{parsedBalances:n}=Le(e);return n.forEach(((e,n)=>{t!==n&&(a=a.add(e))})),a}async buildGraphFromPool(e,t,a,n,s){var i;const r=await this.pools.findBy("address",e);if(!r){if(a){const s=await this.pools.findBy("address",a.address),r=null!==(i=s.tokens[s.tokensList.indexOf(e)].decimals)&&void 0!==i?i:18;return Ui.createInputTokenNode(t,e,r,a,n)}throw new $t(Gt.POOL_DOESNT_EXIST)}const o=Mi.get(r.poolType),l=Li.get(r.poolType);if(!o||!l)throw new $t(Gt.UNSUPPORTED_POOL_TYPE);const p=this.getTokenTotal(r),{spotPriceCalculator:u}=Sa.from(r.poolType),y={};let b=18;r.tokens.forEach((e=>{if(Pt(e.address,r.address))return void(b=e.decimals?e.decimals:18);const t=u.calcPoolSpotPrice(e.address,r.address,r);y[e.address]=t}));let f={address:r.address,id:r.id,type:r.poolType,joinAction:o,exitAction:l,children:[],marked:!1,index:t.toString(),parent:a,proportionOfParent:n,isLeaf:!1,spotPrices:y,decimals:b};if(t++,r.poolType.toString().includes("Linear"))[f,t]=this.createLinearNodeChildren(f,t,r,s);else{const{parsedBalances:e}=Le(r);for(let a=0;a<r.tokens.length;a++){if(Pt(r.tokens[a].address,r.address))continue;let i;if("Weighted"===r.poolType){const e=r.tokens[a].weight;i=c(e,18)}else i=d.from(e[a]).mul(1e18.toString()).div(p);const o=i.mul(n).div(1e18.toString()),l=await this.buildGraphFromPool(r.tokens[a].address,t,f,o,s);t=l[1],l[0]&&f.children.push(l[0])}}return[f,t]}createLinearNodeChildren(e,t,a,n){var s;if(n){const n=this.createWrappedTokenNode(a,t,e,e.proportionOfParent);return e.children.push(n[0]),[e,n[1]]}{if(void 0===a.mainIndex)throw new Error("Issue With Linear Pool");const n=null!==(s=a.tokens[a.mainIndex].decimals)&&void 0!==s?s:18,i=Ui.createInputTokenNode(t,a.tokensList[a.mainIndex],n,e,e.proportionOfParent);return e.children.push(i[0]),[e,t=i[1]]}}createWrappedTokenNode(e,t,a,n){var s;if(void 0===e.wrappedIndex||void 0===e.mainIndex)throw new Error("Issue With Linear Pool");let i="wrapAaveDynamicToken";if(e.poolType===Xe.ERC4626Linear)i="wrapERC4626";let r="unwrapAaveStaticToken";if(e.poolType===Xe.ERC4626Linear)r="unwrapERC4626";const o={type:"WrappedToken",address:e.tokensList[e.wrappedIndex],id:"N/A",children:[],marked:!1,joinAction:i,exitAction:r,index:t.toString(),parent:a,proportionOfParent:n,isLeaf:!1,spotPrices:{},decimals:18};t++;const d=null!==(s=e.tokens[e.mainIndex].decimals)&&void 0!==s?s:18,c=Ui.createInputTokenNode(t,e.tokensList[e.mainIndex],d,o,n);return o.children=[c[0]],[o,t=c[1]]}static createInputTokenNode(e,t,a,n,s){return[{address:t,id:"N/A",type:"Input",children:[],marked:!1,joinAction:"input",exitAction:"output",index:e.toString(),parent:n,proportionOfParent:s,isLeaf:!0,spotPrices:{},decimals:a},e+1]}static orderByBfs(e){const t=[],a=[];for(e.marked=!0,t.push(e);t.length>0;){const e=t.shift();e&&a.push(e),null==e||e.children.forEach((e=>{e.marked||(e.marked=!0,t.push(e))}))}return a}static getLeafAddresses(e){return e.filter((e=>e.isLeaf)).map((e=>e.address))}}Ui.getGraphNodes=async(e,t,a,n)=>{if(!await a.find(t))throw new $t(Gt.POOL_DOESNT_EXIST);const s=new Ui(a),i=await s.buildGraphFromRootPool(t,n);if(i.id!==t)throw new Error("Error creating graph nodes");return e?Ui.orderByBfs(i).reverse():Ui.orderByBfs(i)};class Gi{constructor(e,t){this.chainId=e,this.simulateMulticall=async(e,t,a,n)=>{const s={...await this.encodeBalanceAndAllowanceOverrides(a,n),...await this.encodeRelayerApprovalOverride(a,e)};return this.simulateTransaction(e,t,a,s)},this.simulateTransaction=async(e,t,a,n)=>{const s=Object.fromEntries(Object.keys(n).map((e=>[e,{storage:n[e].value}]))),i={network_id:this.chainId.toString(),block_number:this.blockNumber,from:a,to:e,input:t,save_if_fails:!0,simulation_type:"quick",state_objects:s},r=this.tenderlyUrl+"simulate";return(await h.post(r,i,this.opts)).data.transaction.transaction_info.call_trace.output},this.encodeRelayerApprovalOverride=async(e,t)=>{const a={[`${this.vaultAddress}`]:{value:{[`_approvedRelayers[${e}][${t}]`]:(!0).toString()}}};return await this.requestStateOverrides(a)},this.encodeBalanceAndAllowanceOverrides=async(e,t)=>{if(0===t.length)return{};let a={};t.forEach((t=>a={...a,[`${t}`]:{value:{[`_balances[${e}]`]:o.toString(),[`_allowances[${e}][${this.vaultAddress}]`]:o.toString(),[`balanceOf[${e}]`]:o.toString(),[`allowance[${e}][${this.vaultAddress}]`]:o.toString(),[`balances[${e}]`]:o.toString(),[`allowed[${e}][${this.vaultAddress}]`]:o.toString()}}}));const n=await this.requestStateOverrides(a);if(Object.keys(n).some((e=>2!==Object.keys(n[e].value).length)))throw new Error("Couldn't encode state overrides - states should match the ones in the contracts");return n},this.requestStateOverrides=async e=>{const t=this.tenderlyUrl+"contracts/encode-states",a={networkID:this.chainId.toString(),stateOverrides:e},n=(await h.post(t,a,this.opts)).data.stateOverrides;if(!n||Object.keys(n).length!==Object.keys(e).length)throw new Error("Couldn't encode state overrides - contracts should be verified and whitelisted on Tenderly");return n};const{contracts:a}=Ut(this.chainId);this.vaultAddress=a.vault,(null==t?void 0:t.user)&&(null==t?void 0:t.project)?this.tenderlyUrl=`https://api.tenderly.co/api/v1/account/${t.user}/project/${t.project}/`:this.tenderlyUrl="https://api.balancer.fi/tenderly/",(null==t?void 0:t.accessKey)&&(this.opts={headers:{"X-Access-Key":t.accessKey}}),this.blockNumber=null==t?void 0:t.blockNumber}}var $i;const qi=new t(ti);class Wi{constructor(t,a){this.pools=t,this.createCalls=async(e,t,a,n)=>{const{calls:s,outputIndexes:i,deltas:r}=this.createActionCalls(e,t,a);n&&s.unshift(this.createSetRelayerApproval(n));return{callData:qi.encodeFunctionData("multicall",[s]),outputIndexes:n?i.map((e=>e+1)):i,deltas:r}},this.amountsOutByJoinPath=async(t,a,n,s)=>{const i=[],r=await this.tenderlyHelper.simulateMulticall(this.relayer,a,t,n),o=e.decode(["bytes[]"],r)[0];let c=d.from("0");return s.forEach((t=>{const a=e.decode(["uint256"],o[t]);i.push(a.toString()),c=c.add(a.toString())})),{amountsOut:i,totalAmountOut:c.toString()}},this.minAmountsOutByJoinPath=(e,t,a)=>({minAmountsOut:t.map((t=>Ft(d.from(t),d.from(e)).toString())),totalMinAmountOut:Ft(d.from(a),d.from(e)).toString()}),this.createActionCalls=(e,t,a)=>{const n=[],s=[],i=!a,r={};return e.forEach(((e,o)=>{const d=e[0].isLeaf;if(e.forEach(((s,i)=>{let c;if(c=d?e.filter((e=>{var t;return s.children.map((e=>e.address)).includes(e.address)&&s.index===(null===(t=e.parent)||void 0===t?void 0:t.index)})):i>0?[e[i-1]]:[],c.length>0&&0===c.filter((e=>"0"!==e.index)).length)return void(s.index="0");c.some((e=>"input"===e.joinAction||"wrapAaveDynamicToken"===e.joinAction));const l=t,p=i===e.length-1,u=t,y=p&&a?a[o]:"0";switch(s.joinAction){case"wrapAaveDynamicToken":n.push(this.createAaveWrap(s,c,o,l,t));break;case"batchSwap":{const[e,t,a]=this.createBatchSwap(s,c,o,y,l,u);n.push(e),this.updateDeltas(r,t,a);break}case"joinPool":{const[e,t,a,i]=this.createJoinPool(s,c,o,y,l,u);n.push(e),this.updateDeltas(r,[s.address,...t],[i,...a]);break}}})),i){const e=100*o,t=js.encodePeekChainedReferenceValue(js.toChainedReference(e,!1));n.push(t),s.push(n.indexOf(t))}})),{calls:n,outputIndexes:s,deltas:r}},this.createSetRelayerApproval=e=>js.encodeSetRelayerApproval(this.relayer,!0,e),this.createAaveWrap=(e,t,a,n,s)=>{if(1!==t.length)throw new Error("aaveWrap nodes should always have a single child node");const i=t[0],r=e.address,o=i.index;return js.encodeWrapAaveDynamicToken({staticToken:r,sender:n,recipient:s,amount:o,fromUnderlying:!0,outputReference:this.getOutputRefValue(a,e).value})},this.createBatchSwap=(e,t,a,n,s,i)=>{if(1!==t.length)throw new Error("Unsupported batchswap");const r=t[0].address,c=this.getOutputRefValue(a,t[0]),l=[e.address,r],p=[d.from(n).mul(-1).toString(),c.isRef?o.toString():c.value],u=[{poolId:e.id,assetInIndex:1,assetOutIndex:0,amount:c.value,userData:"0x"}],y={sender:s,recipient:i,fromInternalBalance:s===this.relayer,toInternalBalance:i===this.relayer},b=[{index:l.map((e=>e.toLowerCase())).indexOf(e.address.toLowerCase()),key:d.from(this.getOutputRefValue(a,e).value)}],f=js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:u,assets:l,funds:y,limits:p,deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:b}),m=s===this.relayer?"0":p[1];return[f,l,[i===this.relayer?"0":p[0],m]]},this.createJoinPool=(e,t,a,n,r,o)=>{const d=[],c=[];e.children.forEach((e=>{d.push(e.address);const n=t.find((t=>Pt(t.address,e.address)));n?c.push(this.getOutputRefValue(a,n).value):c.push("0")})),e.type===Xe.ComposableStable&&(d.push(e.address),c.push("0"));const l=new we(this.wrappedNativeAsset),[p,u]=l.sortTokens(d,c);let y=[];const b=p.map((e=>e.toLowerCase())).indexOf(e.address.toLowerCase());let f;y=-1===b?u:[...u.slice(0,b),...u.slice(b+1)],f=e.type===Xe.Weighted?z.joinExactTokensInForBPTOut(y,n):Z.joinExactTokensInForBPTOut(y,n);const m=p.indexOf(i),h=-1===m?"0":u[m],T=js.constructJoinCall({poolId:e.id,kind:0,sender:r,recipient:o,value:h,outputReference:this.getOutputRefValue(a,e).value,joinPoolRequest:{},assets:p,maxAmountsIn:u,userData:f,fromInternalBalance:r===this.relayer}),g=u.map((e=>js.isChainedReference(e)?"0":e)),I=js.isChainedReference(n)?"0":n;return[T,r===this.relayer?[]:p,r===this.relayer?[]:g,o===this.relayer?s.toString():s.sub(I).toString()]},this.getOutputRefValue=(e,t)=>"input"===t.joinAction?{value:t.index,isRef:!1}:"0"===t.index&&t.parent?{value:"0",isRef:!0}:{value:js.toChainedReference(d.from(t.index).add(100*e)).toString(),isRef:!0};const{tokens:n,contracts:r}=Ut(a.chainId);this.relayer=r.relayerV4,this.wrappedNativeAsset=n.wrappedNativeAsset,this.tenderlyHelper=new Gi(a.chainId,a.tenderly)}async joinPool(e,t,a,n,s,i,r){if(t.length!=a.length)throw new $t(Gt.INPUT_LENGTH_MISMATCH);const o=await Ui.getGraphNodes(!0,e,this.pools,s),d=Wi.getJoinPaths(o,t,a),c=Wi.totalBptZeroPriceImpact(d),{callData:l,outputIndexes:p}=await this.createCalls(d,n,void 0,r),{amountsOut:u,totalAmountOut:y}=await this.amountsOutByJoinPath(n,l,t,p),{minAmountsOut:b,totalMinAmountOut:f}=this.minAmountsOutByJoinPath(i,u,y),m=jt(BigInt(y),c.toBigInt(),!0).toString(),{callData:h,deltas:T}=await this.createCalls(d,n,b,r);return this.assertDeltas(e,T,t,a,f),{to:this.relayer,callData:h,expectedOut:y,minOut:f,priceImpact:m}}assertDeltas(e,t,a,n,s){var i;const r=ce(e);if(t[r.toLowerCase()].add(s).abs().gt(3))throw console.error("join assertDeltas, bptOut: ",r,s,null===(i=t[r.toLowerCase()])||void 0===i?void 0:i.toString()),new $t(Gt.JOIN_DELTA_AMOUNTS);delete t[r.toLowerCase()],a.forEach(((e,a)=>{var s,i;if(!d.from(n[a]).eq(0)&&(null===(s=t[e.toLowerCase()])||void 0===s?void 0:s.toString())!==n[a])throw console.error("join assertDeltas, tokenIn: ",e,n[a],null===(i=t[e.toLowerCase()])||void 0===i?void 0:i.toString()),new $t(Gt.JOIN_DELTA_AMOUNTS);delete t[e.toLowerCase()]}));for(const e in t)if("0"!==t[e].toString())throw console.error("join assertDeltas, non-input token should be 0: ",e,t[e].toString()),new $t(Gt.JOIN_DELTA_AMOUNTS)}updateDeltas(e,t,a){return t.forEach(((t,n)=>{const i=t.toLowerCase();e[i]||(e[i]=s),e[i]=e[i].add(a[n])})),e}}$i=Wi,Wi.getJoinPaths=(e,t,a)=>{const s=[],i=e.filter((e=>t.filter(((e,t)=>d.from(a[t]).gt(0))).map((e=>e.toLowerCase())).includes(e.address.toLowerCase())));i.some((e=>e.isLeaf))&&s.push(e);const r=i.filter((e=>!e.isLeaf));return r.forEach((e=>{const i=a.find(((a,n)=>Pt(t[n],e.address))),o=r.filter((t=>Pt(t.address,e.address))).reduce(((e,t)=>e.add(t.proportionOfParent)),d.from(0)),c=d.from(i).mul(e.proportionOfParent).div(o).toString(),[l]=Ui.createInputTokenNode(0,e.address,e.decimals,e.parent,n);l.index=c,l.isLeaf=!1;const p=[l];let u=e.parent;for(;u;)p.push(g(u)),u=u.parent;s.push(p)})),$i.updateInputAmounts(s,t,a),s},Wi.updateInputAmounts=(e,t,a)=>{const n=(e,t)=>{if(e.length>1){const a=e.reduce(((e,t)=>e.add(t.index)),d.from(0)),n=d.from(t).sub(a);e[0].index=n.add(e[0].index).toString()}},s=e.find((e=>e[0].isLeaf));if(s){const e=$i.updateTotalProportions(s);s.forEach((n=>{"input"===n.joinAction&&(n=$i.updateNodeAmount(n,t,a,e))})),t.forEach(((e,t)=>{const i=s.filter((t=>t.isLeaf&&Pt(t.address,e)));n(i,a[t])}))}const i=e.filter((e=>!e[0].isLeaf));i.length>1&&t.forEach(((e,t)=>{const s=i.map((e=>e[0])).filter((t=>Pt(t.address,e)));n(s,a[t])}))},Wi.totalBptZeroPriceImpact=e=>{let t=d.from("0");return e.forEach((e=>{if(e[0].isLeaf){e.filter((e=>e.isLeaf)).forEach((e=>{const a=$i.bptOutZeroPiForInputNode(e);t=t.add(a)}))}else{const a=$i.bptOutZeroPiForInputNode(e[0]);t=t.add(a)}})),t},Wi.bptOutZeroPiForInputNode=e=>{if("0"===e.index||"input"!==e.joinAction)return BigInt(0);let t=1,a=e.parent,n=e.address;for(;void 0!==a;){if("batchSwap"===a.joinAction||"joinPool"===a.joinAction){const e=a.spotPrices[n.toLowerCase()];t*=parseFloat(e),n=a.address}a=a.parent}const s=c(t.toFixed(18),18),i=Ne(BigInt(e.decimals)),r=Ce(BigInt(e.index),i);return Re.divDownFixed(r,s.toBigInt())},Wi.updateTotalProportions=e=>{const t={};return e.forEach((e=>{t[e.address]?t[e.address]=t[e.address].add(e.proportionOfParent):t[e.address]=e.proportionOfParent})),t},Wi.updateNodeAmount=(e,t,a,n)=>{const s=t.map((e=>e.toLowerCase())).indexOf(e.address.toLowerCase());if(-1===s)return e.index="0",e;const i=n[e.address],r=e.proportionOfParent.mul(1e18.toString()).div(i).mul(a[s]).div(1e18.toString());return e.index=r.toString(),e};const Vi=new t(ti);class Hi{constructor(t,a){this.pools=t,this.amountsOutByExitPath=async(t,a,n,s,i)=>{const r=await this.tenderlyHelper.simulateMulticall(this.relayer,a,t,[n]),o=e.decode(["bytes[]"],r)[0],c=s.map((t=>e.decode(["uint256"],o[t]).toString())),l=c.map((e=>Ft(d.from(e),d.from(i)).toString()));return{expectedAmountsOutByExitPath:c,minAmountsOutByExitPath:l}},this.amountsOutByTokenOut=(e,t,a,n)=>{const i={};t.forEach(((e,t)=>{var n;return i[e]=(null!==(n=i[e])&&void 0!==n?n:s).add(a[t])}));const r=e.map((e=>i[e].toString())),o=r.map((e=>Ft(d.from(e),d.from(n)).toString()));return{expectedAmountsOut:r,minAmountsOut:o}},this.getExitPaths=(e,t)=>{const a=e.map((e=>{const a=[e];for(;a[0].parent;)a.unshift(g(a[0].parent));return a[0].index=a[a.length-1].proportionOfParent.mul(t).div(n).toString(),a})),i=a.reduce(((e,t)=>{const a=t[0].index;return d.from(a).add(e)}),s),r=d.from(t).sub(i);return a[a.length-1][0].index=r.add(a[a.length-1][0].index).toString(),a},this.getOutputRef=(e,t)=>100*e+parseInt(t);const{tokens:i,contracts:r}=Ut(a.chainId);this.wrappedNativeAsset=i.wrappedNativeAsset,this.relayer=r.relayerV4,this.tenderlyHelper=new Gi(a.chainId,a.tenderly)}async exitPool(e,t,a,n,s){const i=await Ui.getGraphNodes(!1,e,this.pools,!1),r=i.filter((e=>"output"===e.exitAction)),o=this.getExitPaths(r,t),d=r.map((e=>e.address.toLowerCase())),c=[...new Set(d)].sort(),l=await this.createCalls(o,a,void 0,s),{expectedAmountsOutByExitPath:p,minAmountsOutByExitPath:u}=await this.amountsOutByExitPath(a,l.callData,i[0].address,l.outputIndexes,n),{callData:y,deltas:b}=await this.createCalls(o,a,u,s),{expectedAmountsOut:f,minAmountsOut:m}=this.amountsOutByTokenOut(c,d,p,n);this.assertDeltas(e,b,t,c,m);const h=await this.calculatePriceImpact(e,c,f,t);return{to:this.relayer,callData:y,tokensOut:c,expectedAmountsOut:f,minAmountsOut:m,priceImpact:h}}async calculatePriceImpact(e,t,a,n){const s=await Ui.getGraphNodes(!0,e,this.pools,!1),i=Wi.getJoinPaths(s,t,a),r=Wi.totalBptZeroPriceImpact(i);return jt(BigInt(n),r.toBigInt(),!1).toString()}assertDeltas(e,t,a,n,s){var i;const r=ce(e);if(t[r.toLowerCase()].sub(a).abs().gt(3))throw console.error("exit assertDeltas, bptIn: ",r,a,null===(i=t[r.toLowerCase()])||void 0===i?void 0:i.toString()),new $t(Gt.EXIT_DELTA_AMOUNTS);delete t[r.toLowerCase()],n.forEach(((e,a)=>{var n;if(t[e.toLowerCase()].add(s[a]).abs().gt(1))throw console.error("exit assertDeltas, tokenOut: ",e,s[a],null===(n=t[e.toLowerCase()])||void 0===n?void 0:n.toString()),new $t(Gt.EXIT_DELTA_AMOUNTS);delete t[e.toLowerCase()]}));for(const e in t)if("0"!==t[e].toString())throw console.error("exit assertDeltas, non-input token should be 0: ",e,t[e].toString()),new $t(Gt.EXIT_DELTA_AMOUNTS)}async createCalls(e,t,a,n){const{calls:s,outputIndexes:i,deltas:r}=this.createActionCalls(g(e),t,a);n&&s.unshift(js.encodeSetRelayerApproval(this.relayer,!0,n));return{callData:Vi.encodeFunctionData("multicall",[s]),outputIndexes:n?i.map((e=>e+1)):i,deltas:r}}updateDeltas(e,t,a){return t.forEach(((t,n)=>{const i=t.toLowerCase();e[i]||(e[i]=s),e[i]=e[i].add(a[n])})),e}createActionCalls(e,t,a){const n=[],s=[],i=!a,r={};return e.forEach(((e,o)=>{e.forEach((d=>{const c=!d.parent?t:this.relayer,l=d.children.find((t=>e.map((e=>e.index)).includes(t.index))),p="output"===(null==l?void 0:l.exitAction),u=p?t:this.relayer,y=p&&a?a[o]:"0";switch(d.exitAction){case"batchSwap":{const[e,t,a]=this.createBatchSwap(d,l,o,y,c,u);n.push(e),this.updateDeltas(r,t,a);break}case"exitPool":{const[e,t,a,s]=this.createExitPool(d,l,o,y,c,u);n.push(e),this.updateDeltas(r,[d.address,...a],[t,...s]);break}case"output":i&&(n.push(js.encodePeekChainedReferenceValue(js.toChainedReference(this.getOutputRef(o,d.index),!1))),s.push(n.length-1));break;default:return}}))})),{calls:n,outputIndexes:s,deltas:r}}createBatchSwap(e,t,a,n,s,i){const r=!e.parent?e.index:js.toChainedReference(this.getOutputRef(a,e.index)).toString(),c=t.address,l=[c,e.address],p=[d.from(n).mul(-1).toString(),js.isChainedReference(r)?o.toString():r],u=[{poolId:e.id,assetInIndex:1,assetOutIndex:0,amount:r,userData:"0x"}],y={sender:s,recipient:i,fromInternalBalance:!1,toInternalBalance:!1},b=[{index:l.map((e=>e.toLowerCase())).indexOf(c.toLowerCase()),key:js.toChainedReference(this.getOutputRef(a,t.index))}],f=js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:u,assets:l,funds:y,limits:p,deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:b});let m=p[0];const h=p[1],T=s===this.relayer?"0":h;return m=i===this.relayer?"0":m,[f,l,[m,T]]}createExitPool(e,t,a,n,i,r){const o=t.address,d=!e.parent?e.index:js.toChainedReference(this.getOutputRef(a,e.index)).toString(),c=[],l=[];e.children.forEach((e=>{c.push(e.address),l.push(e.address===o?n:"0")})),e.type===Xe.ComposableStable&&(c.push(e.address),l.push("0"));const p=new we(this.wrappedNativeAsset),[u,y]=p.sortTokens(c,l);let b=[];const f=u.map((e=>e.toLowerCase())).indexOf(e.address.toLowerCase());let m;b=-1===f?u:[...u.slice(0,f),...u.slice(f+1)],m=e.type===Xe.Weighted?z.exitExactBPTInForOneTokenOut(d,b.indexOf(o)):Z.exitExactBPTInForOneTokenOut(d,b.indexOf(o));const h=[{index:u.map((e=>e.toLowerCase())).indexOf(o.toLowerCase()),key:js.toChainedReference(this.getOutputRef(a,t.index))}],T=js.constructExitCall({poolId:e.id,poolKind:0,sender:i,recipient:r,outputReferences:h,exitPoolRequest:{},assets:u,minAmountsOut:y,userData:m,toInternalBalance:!1}),g=y.map((e=>js.isChainedReference(e)?"0":s.sub(e).toString())),I=js.isChainedReference(d)?"0":d;return[T,i===this.relayer?s.toString():I,r===this.relayer?[]:u,r===this.relayer?[]:g]}}class ji{constructor(e){this.yesterdaysPools=e}async last24h(e){let t;return this.yesterdaysPools&&(t=await this.yesterdaysPools.find(e.id)),e.totalSwapVolume?(null==t?void 0:t.totalSwapVolume)?parseFloat(e.totalSwapVolume)-parseFloat(t.totalSwapVolume):e.createTime&&Js(e.createTime)?parseFloat(e.totalSwapVolume):0:0}}var Xi=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"contract IProtocolFeePercentagesProvider",name:"protocolFeeProvider",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[],name:"FactoryDisabled",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"pool",type:"address"}],name:"PoolCreated",type:"event"},{inputs:[{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"},{internalType:"contract IERC20[]",name:"tokens",type:"address[]"},{internalType:"uint256",name:"amplificationParameter",type:"uint256"},{internalType:"contract IRateProvider[]",name:"rateProviders",type:"address[]"},{internalType:"uint256[]",name:"tokenRateCacheDurations",type:"uint256[]"},{internalType:"bool[]",name:"exemptFromYieldProtocolFeeFlags",type:"bool[]"},{internalType:"uint256",name:"swapFeePercentage",type:"uint256"},{internalType:"address",name:"owner",type:"address"}],name:"create",outputs:[{internalType:"contract ComposableStablePool",name:"",type:"address"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"disable",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"getActionId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAuthorizer",outputs:[{internalType:"contract IAuthorizer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCreationCode",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCreationCodeContracts",outputs:[{internalType:"address",name:"contractA",type:"address"},{internalType:"address",name:"contractB",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPauseConfiguration",outputs:[{internalType:"uint256",name:"pauseWindowDuration",type:"uint256"},{internalType:"uint256",name:"bufferPeriodDuration",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"isDisabled",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"pool",type:"address"}],name:"isPoolFromFactory",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"}];class Ki{constructor(e){const{tokens:t}=Ut(e.chainId);this.wrappedNativeAsset=t.wrappedNativeAsset}create({factoryAddress:e,name:n,symbol:s,tokenAddresses:i,amplificationParameter:r,rateProviders:o,tokenRateCacheDurations:d,exemptFromYieldProtocolFeeFlags:c,swapFee:l,owner:p}){const u=xt(`${l}`),y=new we(this.wrappedNativeAsset),[b,f,m,h]=y.sortTokens(i,o,d,c),T=[n,s,b,r,f,m,h,u.toString(),p],g=new t(Xi),I=Xi.find((({name:e})=>"create"===e));if(!I)throw new $t(Gt.INTERNAL_ERROR_INVALID_ABI);const w=a.from(I);return{to:e,data:g.encodeFunctionData(w,T)}}buildInitJoin({joiner:e,poolId:t,poolAddress:a,tokensIn:n,amountsIn:s}){throw new Error("To be implemented")}}class Yi{constructor(e){const{tokens:t}=Ut(e.chainId);this.wrappedNativeAsset=t.wrappedNativeAsset}create({factoryAddress:e,name:n,symbol:s,tokenAddresses:i,weights:r,swapFee:o,owner:d}){const c=xt(`${o}`),l=new we(this.wrappedNativeAsset),[p,u]=l.sortTokens(i,r),y=[n,s,p,u,c.toString(),d],b=new t($.abi),f=$.abi.find((({name:e})=>"create"===e));if(!f)throw new $t(Gt.INTERNAL_ERROR_INVALID_ABI);const m=a.from(f);return{to:e,data:b.encodeFunctionData(m,y)}}buildInitJoin({joiner:e,poolId:t,tokensIn:a,amountsIn:n}){const s=new we(this.wrappedNativeAsset),[i,r]=s.sortTokens(a,n),o="joinPool",d={poolId:t,sender:e,recipient:e,joinPoolRequest:{assets:i,maxAmountsIn:r,userData:z.joinInit(r),fromInternalBalance:!1}},c=L.createInterface().encodeFunctionData(o,[d.poolId,d.sender,d.recipient,d.joinPoolRequest]);return{to:Mt,functionName:o,attributes:d,data:c}}}class Ji{constructor(e){this.networkConfig=e}of(e){switch(e){case"Weighted":return new Yi(this.networkConfig);case"Investment":case"LiquidityBootstrapping":case"Stable":case"MetaStable":case"StablePhantom":case"AaveLinear":case"ERC4626Linear":default:throw new $t(Gt.UNSUPPORTED_POOL_TYPE);case"ComposableStable":return new Ki(this.networkConfig)}}}class Zi{constructor(e){this.pool=e;const t=(e=>{switch(e){case Xe.Weighted:return z;case Xe.Stable:case Xe.MetaStable:case Xe.StablePhantom:case Xe.AaveLinear:case Xe.EulerLinear:case Xe.ERC4626Linear:case Xe.Element:case Xe.Gyro2:case Xe.Gyro3:return Z;case Xe.ComposableStable:return se}})(e.poolType);if(!t)throw"Pool type not supported";this.encoder=t}buildQueryJoinExactIn({sender:e=i,recipient:t=e,maxAmountsIn:a,minimumBPT:n=s,fromInternalBalance:r=!1}){const o=this.pool.tokensList.findIndex((e=>this.pool.id.includes(e))),d=[...this.pool.tokensList];o&&o>-1&&a.splice(o,1);const c=this.encoder.joinExactTokensInForBPTOut(a,n);return[this.pool.id,e,t,{assets:d,maxAmountsIn:a,userData:c,fromInternalBalance:r}]}buildQueryJoinExactOut({sender:e=i,recipient:t=e,maxAmountsIn:a=[],bptOut:n,tokenIn:s,fromInternalBalance:r=!1}){const o=this.pool.tokensList.indexOf(s),d=this.encoder.joinTokenInForExactBPTOut(n,o);return[this.pool.id,e,t,{assets:this.pool.tokensList,maxAmountsIn:a,userData:d,fromInternalBalance:r}]}buildQueryExitToSingleToken({sender:e=i,recipient:t=e,minAmountsOut:a=[],bptIn:n,tokenOut:s,toInternalBalance:r=!1}){const o=this.pool.tokensList.indexOf(s),d=this.encoder.exitExactBPTInForOneTokenOut(n,o);return[this.pool.id,e,t,{assets:this.pool.tokensList,minAmountsOut:a,userData:d,toInternalBalance:r}]}buildQueryExitProportionally({sender:e=i,recipient:t=e,minAmountsOut:a=[],bptIn:n,toInternalBalance:s=!1}){if(!this.encoder.exitExactBPTInForTokensOut)throw"Proportional exit not implemented";const r=this.encoder.exitExactBPTInForTokensOut(n);return[this.pool.id,e,t,{assets:this.pool.tokensList,minAmountsOut:a,userData:r,toInternalBalance:s}]}buildQueryExitExactOut({sender:e=i,recipient:t=e,minAmountsOut:a,maxBptIn:n=r,toInternalBalance:s=!1}){const o=this.pool.tokensList.findIndex((e=>this.pool.id.includes(e)));o&&o>-1&&a.splice(o,1);const d=this.encoder.exitBPTInForExactTokensOut(a,n);return[this.pool.id,e,t,{assets:this.pool.tokensList,minAmountsOut:a,userData:d,toInternalBalance:s}]}}class zi{constructor(e){this.liquidityGaugesRepository=e}async relativeWeight(e){const t=await this.liquidityGaugesRepository.findBy("poolId",e);return t?t.relativeWeight:0}async weekly(e){return Di()*await this.relativeWeight(e)}}const Qi=(e,t,a)=>{const n=e.tokens.filter((t=>!e.id.toLowerCase().includes(t.address.toLowerCase()))),s=n.findIndex((e=>e.address.toLowerCase()===t.toLowerCase()));if(-1==s)throw new Error("Token not found in pool");const i=n.map((e=>ot(e.balance,e.decimals))),r=d.from(a),o=i.map((e=>e.mul(r).div(i[s])));return{tokens:n.map((e=>e.address)),amounts:o.map((e=>e.toString()))}},er=(e,t)=>()=>{throw`${t} for poolType ${e} not implemented`};class tr{constructor(e,t){this.networkConfig=e,this.repositories=t,this.aprService=new Ri(this.repositories.pools,this.repositories.tokenPrices,this.repositories.tokenMeta,this.repositories.tokenYields,this.repositories.feeCollector,this.repositories.yesterdaysPools,this.repositories.liquidityGauges,this.repositories.feeDistributor),this.liquidityService=new Pa(t.pools,t.tokenPrices),this.joinService=new Wi(this.repositories.poolsOnChain,e),this.exitService=new Hi(this.repositories.poolsOnChain,e),this.feesService=new Fi(t.yesterdaysPools),this.volumeService=new ji(t.yesterdaysPools),this.poolFactory=new Ji(e),this.impermanentLossService=new Oi(t.tokenPrices,t.tokenHistoricalPrices),t.liquidityGauges&&(this.emissionsService=new zi(t.liquidityGauges)),this.proportionalAmounts=Qi}dataSource(){return this.repositories.pools}async apr(e){return this.aprService.apr(e)}async aprNextPeriod(e){return this.aprService.aprNextPeriod(e)}async impermanentLoss(e,t){return this.impermanentLossService.calcImpLoss(e,t)}async liquidity(e){return this.liquidityService.getLiquidity(e)}async generalisedJoin(e,t,a,n,s,i,r){return this.joinService.joinPool(e,t,a,n,s,i,r)}async generalisedExit(e,t,a,n,s){return this.exitService.exitPool(e,t,a,n,s)}async fees(e){return this.feesService.last24h(e)}async volume(e){return this.volumeService.last24h(e)}static wrap(e,t){let a,n,s;try{a=Sa.from(e.poolType),s={buildJoin:(t,n,s,r)=>a.join.buildJoin({joiner:t,pool:e,tokensIn:n,amountsIn:s,slippage:r,wrappedNativeAsset:i}),calcPriceImpact:async(t,n,s)=>a.priceImpactCalculator.calcPriceImpact(e,t,n,s),buildExitExactBPTIn:(t,n,s,r=!1,o)=>{if(a.exit.buildExitExactBPTIn)return a.exit.buildExitExactBPTIn({exiter:t,pool:e,bptIn:n,slippage:s,shouldUnwrapNativeAsset:r,wrappedNativeAsset:i,singleTokenMaxOut:o});throw"ExitExactBPTIn not supported"},buildExitExactTokensOut:(t,n,s,r)=>a.exit.buildExitExactTokensOut({exiter:t,pool:e,tokensOut:n,amountsOut:s,slippage:r,wrappedNativeAsset:i}),calcSpotPrice:(t,n)=>a.spotPriceCalculator.calcPoolSpotPrice(t,n,e),calcProportionalAmounts:(t,a)=>Qi(e,t,a)}}catch(t){"UNSUPPORTED_POOL_TYPE"!=t.code&&console.error(t),s={buildJoin:er(e.poolType,"buildJoin"),calcPriceImpact:er(e.poolType,"calcPriceImpact"),buildExitExactBPTIn:er(e.poolType,"buildExitExactBPTIn"),buildExitExactTokensOut:er(e.poolType,"buildExitExactTokensOut"),calcSpotPrice:er(e.poolType,"calcSpotPrice")}}try{n=new Zi(e),s={...s,buildQueryJoinExactIn:n.buildQueryJoinExactIn.bind(n),buildQueryJoinExactOut:n.buildQueryJoinExactOut.bind(n),buildQueryExitExactOut:n.buildQueryExitExactOut.bind(n),buildQueryExitToSingleToken:n.buildQueryExitToSingleToken.bind(n),buildQueryExitProportionally:n.buildQueryExitProportionally.bind(n)}}catch(t){s={...s,buildQueryJoinExactIn:er(e.poolType,"buildQueryJoinExactIn"),buildQueryJoinExactOut:er(e.poolType,"buildQueryJoinExactOut"),buildQueryExitExactOut:er(e.poolType,"buildQueryExitExactOut"),buildQueryExitToSingleToken:er(e.poolType,"buildQueryExitToSingleToken"),buildQueryExitProportionally:er(e.poolType,"buildQueryExitProportionally")}}const i=t.addresses.tokens.wrappedNativeAsset.toLowerCase();return{...e,...s}}async find(e){const t=await this.dataSource().find(e);if(t)return tr.wrap(t,this.networkConfig)}async findBy(e,t){if("id"==e)return this.find(t);if("address"==e){const e=await this.dataSource().findBy("address",t);if(!e)return;return tr.wrap(e,this.networkConfig)}throw`search by ${e} not implemented`}async all(){const e=await this.dataSource().all();return e?e.map((e=>tr.wrap(e,this.networkConfig))).filter((e=>e)):[]}async where(e){const t=await this.dataSource().where(e);if(!t)return[];return t.map((e=>tr.wrap(e,this.networkConfig))).filter((e=>e))}}const ar=new t(["function gauge_relative_weight(address gauge, uint timestamp) view returns (uint)","function gauge_relative_weight_write(address gauge, uint timestamp) returns (uint)"]);class nr{constructor(e,t,a){this.gaugeControllerAddress=t,this.multicall=hs(e,a)}async getRelativeWeights(e,t){const a=e.map((e=>[this.gaugeControllerAddress,ar.encodeFunctionData("gauge_relative_weight_write",[p(e),t||Math.floor(Date.now()/1e3)])])),[,n]=await this.multicall.aggregate(a);return e.reduce(((e,t,a)=>(e[t]||(e[t]=parseFloat(rt(n[a],18))),e)),{})}}class sr{async get(e){const t=await this.query(e);return(null==t?void 0:t.length)>0?t[0]:void 0}async find(e){return this.get({where:{id:e}})}async findBy(e,t){return this.get({where:{[String(e)]:t}})}async findAllBy(e,t,a=1e3,n=0){const s={where:{[String(e)]:t},first:a,skip:n};return this.query(s)}}class ir extends sr{constructor(e,t,a){super(),this.chainId=t,this.blockHeight=a,this.client=bs(e)}}class rr extends sr{constructor(e,t,a){super(),this.chainId=t,this.blockHeight=a,this.client=fs(e)}}class or extends rr{async query(e){e.orderBy||(e.orderBy=jn.Balance),e.orderDirection||(e.orderDirection=Zn.Desc),!e.block&&this.blockHeight&&(e.block={number:await this.blockHeight()});const{gaugeShares:t}=await this.client.GaugeShares(e);return t.map(this.mapType)}mapType(e){var t;return{id:e.id,balance:e.balance,userAddress:null===(t=e.user)||void 0===t?void 0:t.id,gauge:{id:e.gauge.id,poolId:e.gauge.poolId||void 0,isKilled:e.gauge.isKilled,totalSupply:e.gauge.totalSupply}}}async findByUser(e,t,a){return this.findAllBy(We.UserAddress,e,t,a)}async findByGauge(e,t,a){return this.findAllBy(We.GaugeId,e,t,a)}}const dr=new t(["function totalSupply() view returns (uint)","function working_supply() view returns (uint)","function reward_count() view returns (uint)","function reward_tokens(uint rewardIndex) view returns (address)","function reward_data(address rewardToken) view returns (tuple(address token, address distributor, uint period_finish, uint rate, uint last_update, uint integral) data)"]);class cr{constructor(e,t,a){this.chainId=t,this.multicall=hs(e,a)}async getTotalSupplies(e){const t=e.map((e=>[e,dr.encodeFunctionData("totalSupply",[])])),[,a]=await this.multicall.aggregate(t),n=a.map((e=>"0x"==e?"0x0":e));return e.reduce(((e,t,a)=>(e[t]||(e[t]=parseFloat(rt(n[a],18))),e)),{})}async getWorkingSupplies(e){const t=e.map((e=>[e,dr.encodeFunctionData("working_supply",[])])),[,a]=await this.multicall.aggregate(t),n=a.map((e=>"0x"==e?"0x0":e));return e.reduce(((e,t,a)=>(e[t]||(e[t]=parseFloat(rt(n[a],18))),e)),{})}async getRewardCounts(e){let t;if(248==this.chainId||9372==this.chainId||6343==this.chainId||4326==this.chainId){const a=e.map((e=>[e,dr.encodeFunctionData("reward_count",[])])),[,n]=await this.multicall.aggregate(a),s=n.map((e=>"0x"==e?"0x0":e));t=e.reduce(((e,t,a)=>(e[t]||(e[t]=parseInt(s[a])),e)),{})}else t=e.reduce(((e,t)=>(e[t]||(e[t]=1),e)),{});return t}async getRewardTokens(e,t){const a=t||await this.getRewardCounts(e),n=e.filter((e=>a[e]>0)),s=[0],i=n.map(((e,t)=>{const n=[];for(let t=0;t<a[e];t++)n.push([e,dr.encodeFunctionData("reward_tokens",[t])]);return s[t+1]=s[t]+a[e],n})).flat(),[,r]=await this.multicall.aggregate(i);return n.reduce(((e,t,a)=>{const n=s[a],i=s[a+1],o=[];for(let e=n;e<i;e++)o.push(dr.decodeFunctionResult("reward_tokens",r[e])[0]);return e[t]||(e[t]=o),e}),{})}async getRewardData(e,t){const a=t||await this.getRewardTokens(e),n=[0],s=Object.keys(a).map(((e,t)=>{const s=[];for(let t=0;t<a[e].length;t++)s.push([e,dr.encodeFunctionData("reward_data",[a[e][t]])]);return n[t+1]=n[t]+a[e].length,s})).flat(),[,i]=await this.multicall.aggregate(s),r=i.map((e=>dr.decodeFunctionResult("reward_data",e)[0]));return Object.keys(a).reduce(((e,t,s)=>{const i=n[s],o=a[t].reduce(((e,t,a)=>(e[t]||(e[t]=r[i+a]),e)),{});return e[t]||(e[t]=o),e}),{})}}class lr{constructor(e){this.gauges=[],this.client=fs(e)}async fetch(){const e=(await this.client.Pools({where:{preferentialGauge_not:null},first:1e3})).pools.map((e=>e.preferentialGauge));return this.gauges=e,this.gauges}async find(e){return 0==this.gauges.length&&await this.fetch(),this.gauges.find((t=>t.id==e))}async findBy(e,t){if(0==this.gauges.length&&await this.fetch(),"id"==e)return this.find(t);if("poolId"==e)return this.gauges.find((e=>e.poolId==t));if("poolAddress"==e)return this.gauges.find((e=>e.poolAddress==t));throw`search by ${e} not implemented`}}const pr=6048e5;class ur{constructor(e,t,a,n,s){this.chainId=n,this.workingSupplies={},this.workingSuppliesNextPeriod={},this.relativeWeights={},this.relativeWeightsNextPeriod={},this.rewardData={},a&&(this.gaugeController=new nr(t,a,s)),this.multicall=new cr(t,n,s),this.subgraph=new lr(e)}async fetch(){const e=await this.subgraph.fetch(),t=e.map((e=>e.id));if(248!=this.chainId&&9372!=this.chainId&&6343!=this.chainId&&4326!=this.chainId||(this.workingSupplies=await this.multicall.getWorkingSupplies(t)),this.gaugeController){this.relativeWeights=await this.gaugeController.getRelativeWeights(t);const e=Math.round(Math.floor((Date.now()+pr)/pr)*pr)/1e3;this.relativeWeightsNextPeriod=await this.gaugeController.getRelativeWeights(t,e)}let a=!1;return this.rewardData=e.reduce(((e,t)=>{var n;return e[n=t.id]||(e[n]=t.tokens?Object.fromEntries(t.tokens.map((e=>[e.id.split("-")[0],{distributor:"",last_update:d.from(0),integral:d.from(0),token:e.id.split("-")[0],decimals:e.decimals,rate:ot(e.rate||"0",e.decimals),period_finish:d.from(e.periodFinish||"0")}]))):{}),t.tokens&&t.tokens.length>0&&(a=!0),e}),{}),a||(this.rewardData=await this.multicall.getRewardData(t)),e.map(this.compose.bind(this))}async find(e){return this.gauges||(this.gauges=this.fetch()),(await this.gauges).find((t=>t.id==e))}async findBy(e,t){let a;if(this.gauges||(this.gauges=this.fetch()),"id"==e)return this.find(t);if("address"==e)return this.find(t);if("poolId"==e)a=(await this.gauges).find((e=>e.poolId==t));else{if("poolAddress"!=e)throw`search by ${e} not implemented`;a=(await this.gauges).find((e=>e.poolAddress==t))}return a}compose(e){return{id:e.id,address:e.id,name:e.symbol,poolId:e.poolId,poolAddress:e.poolAddress,totalSupply:parseFloat(e.totalSupply),workingSupply:this.workingSupplies[e.id],relativeWeight:this.relativeWeights[e.id],relativeWeightNextPeriod:this.relativeWeightsNextPeriod[e.id],rewardTokens:this.rewardData[e.id]}}}class yr{constructor(e,t){this.url=e,this.apiKey=t}async get(e){try{const t=this.toPayload(e),{data:a}=await h.post(this.url,t,{headers:{"x-api-key":this.apiKey}});if(a.errors)throw new Error(a.errors.map((e=>e.message)).join(","));return a.data}catch(e){throw console.error(e),e}return[]}toPayload(e){return JSON.stringify({query:H({query:e})})}}class br{constructor(e){var t,a;this.pools=[],this.skip=0,this.client=new yr(e.url,e.apiKey);this.query={args:Object.assign({},(null===(t=e.query)||void 0===t?void 0:t.args)||{orderBy:"totalLiquidity",orderDirection:"desc",where:{swapEnabled:{eq:!0}}}),attrs:Object.assign({},(null===(a=e.query)||void 0===a?void 0:a.attrs)||{id:!0,address:!0})},delete this.query.args.skip}fetchFromCache(e){const t=(null==e?void 0:e.first)||10,a=(null==e?void 0:e.skip)||0,n=this.pools.slice(a,t+a);return this.skip=a+t,n}async fetch(e){if(this.pools.length>((null==e?void 0:e.first)||10)+((null==e?void 0:e.skip)||0))return this.fetchFromCache(e);this.nextToken&&(this.query.args.nextToken=this.nextToken),(null==e?void 0:e.first)&&(this.query.args.first=2*e.first);const t=new Bt(this.query.args).format(new vt),a=this.query.attrs;a.nextToken=!0;const n={pools:{__args:t,...a}},s=(await this.client.get(n)).pools;return this.nextToken=s.nextToken,this.pools=this.pools.concat(s.pools.map(this.format)),this.skip=this.pools.length,this.fetchFromCache(e)}async find(e){return 0==this.pools.length&&await this.fetch(),this.findBy("id",e)}async findBy(e,t){0==this.pools.length&&await this.fetch();const a=this.pools.find((a=>a[e]==t));if(a)return this.format(a)}format(e){var t,a,n,s;if(null===(t=e.apr)||void 0===t?void 0:t.rewardAprs.breakdown){const t=JSON.parse(null===(a=e.apr)||void 0===a?void 0:a.rewardAprs.breakdown);e.apr.rewardAprs.breakdown=t}if(null===(n=e.apr)||void 0===n?void 0:n.tokenAprs.breakdown){const t=JSON.parse(null===(s=e.apr)||void 0===s?void 0:s.tokenAprs.breakdown);e.apr.tokenAprs.breakdown=t}return e}}class fr{constructor(e,t={}){this.providers=e,this.currentProviderIdx=0,this.timeout=t.timeout||1e4}async fetch(e){return this.fallbackQuery("fetch",[e])}get currentProvider(){if(this.providers.length&&!(this.currentProviderIdx>=this.providers.length))return this.providers[this.currentProviderIdx]}async find(e){return this.fallbackQuery("find",[e])}async findBy(e,t){return this.fallbackQuery("findBy",[e,t])}async fallbackQuery(e,t){if(this.currentProviderIdx>=this.providers.length)throw new Error("No working providers found");let a;try{const n=this.providers[this.currentProviderIdx];a=await Promise.race([n[e].apply(n,t),new Promise(((e,t)=>setTimeout((()=>t(new Error("timeout"))),this.timeout)))])}catch(n){const s=n.message;"timeout"===s?console.error("Provider "+this.currentProviderIdx+" timed out, falling back to next provider"):console.error("Provider "+this.currentProviderIdx+" failed with error: ",s,", falling back to next provider"),this.currentProviderIdx++,a=await this.fallbackQuery.call(this,e,t)}return a}}class mr{constructor(e){this.pools=e}async find(e){return this.pools.find((t=>t.id.toLowerCase()===e.toLowerCase()))}async findBy(e,t){return this.pools.find((a=>a[e]===t))}async all(){return this.pools}async where(e){return(await this.all()).filter(e)}}class hr{constructor(e){var t,a;this.skip=0,this.client=bs(e.url),this.blockHeight=e.blockHeight,this.chainId=e.chainId;const n={orderBy:on.TotalLiquidity,orderDirection:en.Desc,where:{swapEnabled:{eq:!0}}},s=Object.assign({},(null===(t=e.query)||void 0===t?void 0:t.args)||n),i=Object.assign({},(null===(a=e.query)||void 0===a?void 0:a.attrs)||{});this.query={args:s,attrs:i}}async fetchDefault(){const{pool0:e,pool1000:t,pool2000:a}=await this.client.AllPools({where:{swapEnabled:!0},orderBy:on.TotalLiquidity,orderDirection:en.Desc,block:await this.block()});return[...e,...t,...a].map(this.mapType.bind(this))}async fetch(e){(null==e?void 0:e.skip)&&(this.query.args.skip=e.skip),this.blockHeight&&(this.query.args.block={number:await this.blockHeight()}),this.query.args.first=(null==e?void 0:e.first)||1e3;const t=new Bt(this.query.args).format(new Ot),{pools:a}=await this.client.Pools(t);return this.skip=((null==e?void 0:e.skip)||0)+a.length,a.map(this.mapType.bind(this))}async find(e){return await this.findBy("id",e)}async findBy(e,t){return this.pools||(this.pools=this.fetchDefault()),(await this.pools).find((a=>a[e]==t))}async all(){return this.pools||(this.pools=this.fetchDefault()),this.pools}async block(){return this.blockHeight?{number:await this.blockHeight()}:void 0}async where(e){return this.pools||(this.pools=this.fetchDefault()),(await this.pools).filter(e)}mapType(e){var t,a,n,s,i,r,o,d,c;return{id:e.id,name:e.name||"",address:e.address,chainId:this.chainId,poolType:e.poolType,poolTypeVersion:e.poolTypeVersion||1,swapFee:e.swapFee,swapEnabled:e.swapEnabled,protocolYieldFeeCache:e.protocolYieldFeeCache||"0",protocolSwapFeeCache:e.protocolSwapFeeCache||"0",amp:null!==(t=e.amp)&&void 0!==t?t:void 0,owner:null!==(a=e.owner)&&void 0!==a?a:void 0,factory:null!==(n=e.factory)&&void 0!==n?n:void 0,symbol:null!==(s=e.symbol)&&void 0!==s?s:void 0,tokens:(e.tokens||[]).map(this.mapToken.bind(this)),tokensList:e.tokensList,tokenAddresses:(e.tokens||[]).map((e=>e.address)),totalLiquidity:e.totalLiquidity,totalShares:e.totalShares,totalSwapFee:e.totalSwapFee,totalSwapVolume:e.totalSwapVolume,priceRateProviders:null!==(i=e.priceRateProviders)&&void 0!==i?i:void 0,createTime:e.createTime,mainIndex:null!==(r=e.mainIndex)&&void 0!==r?r:void 0,wrappedIndex:null!==(o=e.wrappedIndex)&&void 0!==o?o:void 0,totalWeight:e.totalWeight||"1",lowerTarget:null!==(d=e.lowerTarget)&&void 0!==d?d:"0",upperTarget:null!==(c=e.upperTarget)&&void 0!==c?c:"0"}}mapToken(e){const t=this.mapSubPools(e.token);return{...e,isExemptFromYieldProtocolFee:e.isExemptFromYieldProtocolFee||!1,token:t}}mapSubPools(e){let t=null;return e.pool&&(t={id:e.pool.id,address:e.pool.address,totalShares:e.pool.totalShares,poolType:e.pool.poolType,mainIndex:e.pool.mainIndex||0},(null==e?void 0:e.pool.tokens)&&(t.tokens=e.pool.tokens.map(this.mapSubPoolToken.bind(this)))),{pool:t,latestUSDPrice:e.latestUSDPrice||void 0}}mapSubPoolToken(e){return{address:e.address,decimals:e.decimals,symbol:e.symbol,balance:e.balance,priceRate:e.priceRate,weight:e.weight,isExemptFromYieldProtocolFee:e.isExemptFromYieldProtocolFee||void 0,token:e.token?this.mapSubPools(e.token):void 0}}}class Tr{constructor(e){this.skip=0,this.poolsSubgraph=new hr({url:e.url,chainId:e.chainId,blockHeight:e.blockHeight,query:e.query}),this.provider=e.provider,this.multicall=e.multicall,this.vault=e.vault}async fetchDefault(){const e=await this.poolsSubgraph.fetch();return await As(e,this.multicall,this.vault,this.provider)}async fetch(e){const t=await this.poolsSubgraph.fetch(e);return await As(t,this.multicall,this.vault,this.provider)}async find(e){return await this.findBy("id",e)}async findBy(e,t){return this.pools||(this.pools=this.fetchDefault()),(await this.pools).find((a=>a[e]==t))}async all(){return this.pools||(this.pools=this.fetchDefault()),this.pools}async where(e){return this.pools||(this.pools=this.fetchDefault()),(await this.pools).filter(e)}}class gr extends rr{async query(e){!e.block&&this.blockHeight&&(e.block={number:await this.blockHeight()});const{pools:t}=await this.client.PoolGauges(e);return t.map(this.mapType)}mapType(e){return e}}var Ir;!function(e){e.Pool="pool",e.Sender="sender"}(Ir||(Ir={}));class wr extends ir{async query(e){e.orderBy||(e.orderBy=Ja.Timestamp),e.orderDirection||(e.orderDirection=en.Asc),!e.block&&this.blockHeight&&(e.block={number:await this.blockHeight()});const{joinExits:t}=await this.client.JoinExits(e);return t.map(this.mapType)}mapType(e){return{id:e.id,userAddress:e.user.id,poolId:e.pool.id,timestamp:e.timestamp,type:e.type,amounts:e.amounts,tokens:e.pool.tokensList}}async findByUser(e,t,a){return this.findAllBy(Ir.Sender,e,t,a)}async findJoins(e,t){return this.query({where:{sender:e,pool:t,type:"Join"}})}async findExits(e,t){return this.query({where:{sender:e,pool:t,type:"Exit"}})}async findByPool(e,t,a){return this.findAllBy(Ir.Pool,e,t,a)}}class Er extends ir{async query(e){e.orderBy||(e.orderBy=nn.Balance),e.orderDirection||(e.orderDirection=en.Desc),!e.block&&this.blockHeight&&(e.block={number:await this.blockHeight()});const{poolShares:t}=await this.client.PoolShares(e);return t.map(this.mapType)}mapType(e){return{id:e.id,userAddress:e.userAddress.id,poolId:e.poolId.id,balance:e.balance}}async findByUser(e,t,a){return this.findAllBy(qe.UserAddress,e,t,a)}async findByPool(e,t,a){return this.findAllBy(qe.PoolId,e,t,a)}}class xr{constructor(e){this.tokens=e}async find(e){return this.tokens.find((t=>t.address.toLowerCase()===e.toLowerCase()))}async findBy(e,t){return this.tokens.find((a=>a[e]===t))}}class Ar{constructor(e){this.tokenPrices=Object.fromEntries(Object.entries(e).map((([e,t])=>[e.toLowerCase(),t])))}async find(e){const t=e.toLowerCase(),a=this.tokenPrices[t];if(a)return a}async findBy(e,t){if("address"==e)return this.find(t)}}class Sr{constructor(e,t=1){this.chainId=t,this.prices={},this.baseTokenAddresses=e.map(ht),this.urlBase=`${Lt[t].urls.priceUrl}/price/?vs_currencies=usd,eth`,this.debouncer=new It(this.fetch.bind(this),200)}fetch(e,{signal:t}={}){return e.length,h.get(this.url(e),{signal:t}).then((({data:e})=>e)).finally((()=>{e.length}))}fetchNative({signal:e}={}){let t;!function(e){e.ETH="ethereum",e.MATIC="matic-network",e.XDAI="xdai",e.OAS="oasys"}(t||(t={}));const a=t.OAS,n=this.url(["0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000"]);return h.get(n,{signal:e}).then((({data:e})=>e[a])).finally((()=>{}))}find(e){const t=e.toLowerCase();if(!this.prices[t]){if(0===Object.keys(this.prices).length)for(const e of this.baseTokenAddresses)this.prices[e]=this.debouncer.fetch(e).then((t=>t[e]));this.prices[t]=this.debouncer.fetch(t).then((e=>e[t]))}return this.prices[t]}async findBy(e,t){if("address"==e)return this.find(t)}platform(e){switch(e){case 1:case 5:case 42:case 31337:case 248:case 9372:case 6343:case 4326:case 16116:case 17117:return"ethereum";case 100:return"xdai";case 137:return"polygon-pos";case 42161:return"arbitrum-one"}return"3"}url(e){return`${this.urlBase}&contract_addresses=${e.join(",")}`}}class Pr{constructor(e=1){this.chainId=e,this.prices={},this.urlBase=`https://api.coingecko.com/api/v3/coins/${this.platform(e)}/contract/%TOKEN_ADDRESS%/market_chart/range?vs_currency=usd`}fetch(e,t,{signal:a}={}){const n=this.urlRange(e,t);return h.get(n,{signal:a}).then((({data:e})=>e)).finally((()=>{}))}async find(e){throw"Historic price requires point-in-time timestamp, please use findBy(address, timestamp)"}async findBy(e,t){const a=ht(e,this.chainId);return{usd:`${(await this.fetch(a,t)).prices[0][1]}`}}platform(e){switch(e){case 1:case 5:case 42:case 31337:case 248:case 9372:case 6343:case 4326:case 16116:case 17117:return"ethereum";case 137:return"polygon-pos";case 42161:return"arbitrum-one";case 100:return"xdai"}return"2"}urlRange(e,t){const a=t-3600,n=t+3600;return`${this.urlBase.replace("%TOKEN_ADDRESS%",e)}&from=${a}&to=${n}`}}class _r{constructor(e,t=1){this.subgraphUrl=e,this.chainId=t,this.prices={},this.debouncer=new It(this.fetch.bind(this),200)}async fetch(e,{signal:t}={}){return e.length,h.post(this.subgraphUrl,{variables:{addresses:e},query:"query($addresses: [String!]) {\n tokens(\n where: {\n id_in: $addresses\n }\n ) {\n address\n latestUSDPrice\n }\n }"},{signal:t}).then((e=>e.data.data)).then((({tokens:e})=>Object.fromEntries(e.map((e=>[e.address,{usd:e.latestUSDPrice||void 0}]))))).finally((()=>{e.length}))}async find(e){const t=ht(e,this.chainId);return this.prices[t]||(this.prices[t]=this.debouncer.fetch(t).then((e=>e[t]))),this.prices[t]}async findBy(e,t){if("address"==e)return this.find(t)}}class vr{constructor(e,t,a){this.coingeckoRepository=e,this.subgraphRepository=t,this.aaveRates=a}async find(e){let t;try{try{if(t=await this.coingeckoRepository.find(e),!(null==t?void 0:t.usd))throw new Error(`Price not found:${e}`)}catch(a){console.error(`Coingecko API error: ${e} ${a}`),t=await this.subgraphRepository.find(e)}}catch(e){console.error(e),t={eth:"0",usd:"0.1"}}return t}async findBy(e,t){if("address"===e)return this.find(t);throw`Token price search by ${e} not implemented`}}class Or{constructor(e,t){this.coingeckoRepository=e,this.aaveRates=t}async find(e){return this.findBy(e,Math.floor(Date.now()/1e3))}async findBy(e,t){const a=await this.coingeckoRepository.findBy(e,t),n=await this.aaveRates.getRate(e)||1;return a&&a.usd?{...a,usd:(parseFloat(a.usd)*n).toString()}:a}}const Br=new t(["function rate() view returns (uint256)"]);class kr{constructor(e,t,a){this.network=a,this.multicall=hs(e,t)}async fetch(e){const t=Object.values(dt[e]),a=t.map((e=>[e,Br.encodeFunctionData("rate",[])])),[,n]=await this.multicall.aggregate(a);return t.reduce(((e,t,a)=>(e[t]||(e[t]="0x"==n[a]?0:parseFloat(rt(n[a],27))),e)),{})}async getRate(e){return this.network!=ue.MAINNET&&this.network!=ue.POLYGON?1:Object.values(dt[this.network]).includes(e)?(this.rates||(this.rates=this.fetch(this.network)),(await this.rates)[e]):1}}const Dr=new t(["function getTokensDistributedInWeek(address token, uint timestamp) view returns (uint)"]),Nr=new t(["function totalSupply() view returns (uint)"]),Cr=new t(["function getRate() view returns (uint)"]);class Fr{constructor(e,t,a,n,s,i){this.feeDistributorAddress=t,this.balAddress=a,this.veBalAddress=n,this.bbAUsdAddress=s,this.multicall=hs(e,i)}async fetch(e){const t=this.getPreviousWeek(e),a=[[this.feeDistributorAddress,Dr.encodeFunctionData("getTokensDistributedInWeek",[p(this.balAddress),t])],[this.feeDistributorAddress,Dr.encodeFunctionData("getTokensDistributedInWeek",[p(this.bbAUsdAddress),t])],[this.veBalAddress,Nr.encodeFunctionData("totalSupply",[])],[this.bbAUsdAddress,Cr.encodeFunctionData("getRate",[])]],[,n]=await this.multicall.aggregate(a);return{balAmount:parseFloat(rt(n[0],18)),bbAUsdAmount:parseFloat(rt(n[1],18)),veBalSupply:parseFloat(rt(n[2],18)),bbAUsdPrice:parseFloat(rt(n[3],18)),balAddress:this.balAddress}}async multicallData(e){return this.data||(this.data=await this.fetch(e)),this.data}getPreviousWeek(e){const t=new Date(e);t.setUTCHours(0),t.setUTCMinutes(0),t.setUTCSeconds(0),t.setUTCMilliseconds(0);let a=t.getUTCDay()-4;return a<0&&(a+=7),a+=7,Math.floor(t.getTime()/1e3)-86400*a}}const Rr=new t(["function getProtocolFeesCollector() view returns (address)"]),Mr=new t(["function getSwapFeePercentage() view returns (uint)"]);let Lr;class Ur{constructor(e,t){this.provider=t,this.vault=new u(e,Rr,this.provider)}async fetch(){const e=await this.vault.getProtocolFeesCollector(),t=new u(e,Mr,this.provider),a=await t.getSwapFeePercentage();return parseFloat(rt(a,18))}async find(){return Lr||(Lr=this.fetch()),this.swapFeePercentage=await Lr,this.swapFeePercentage}async findBy(){return this.find()}}const Gr=new t(["function getSwapFeePercentage() view returns (uint)"]);let $r;class qr{constructor(e,t,a){this.protocolFeePercentagesProviderAddress=t,this.multicall=hs(e,a)}async fetch(){const e=[[this.protocolFeePercentagesProviderAddress,Gr.encodeFunctionData("getFeeTypePercentage",[0])],[this.protocolFeePercentagesProviderAddress,Gr.encodeFunctionData("getFeeTypePercentage",[2])]],[,t]=await this.multicall.aggregate(e);return{swapFee:parseFloat(rt(t[0],18)),yieldFee:parseFloat(rt(t[2],18))}}async getFees(){return $r||($r=this.fetch()),this.protocolFees=await $r,this.protocolFees}}const Wr={stETH:"0xae7ab96520de3a18e5e111b5eaab095312d7fe84",wstETH:"0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",arbitrumStEth:"0x5979d7b546e38e414f7e9822514be443a4800529"},Vr=async()=>{let e=0;try{const t=await h.get("https://lido-aprs-proxy.balancer.workers.dev/?network=1"),{data:a}=t.data;e=Math.round(100*parseFloat(a.smaApr))}catch(e){console.error("Failed to fetch stETH APR:",e)}return{[Wr.stETH]:e,[Wr.wstETH]:e,[Wr.arbitrumStEth]:e}},Hr={rETH:"0xae78736cd615f374d3085123a210448e74fc6393"},jr=async()=>{let e=0;try{const t=await h.get("https://api.rocketpool.net/api/apr"),{yearlyAPR:a}=t.data;e=Math.round(100*parseFloat(a))}catch(e){console.error("Failed to fetch APR:",e)}return{[Hr.rETH]:e}},Xr={stMATIC:"0x3a58a54c066fdc0f2d55fc9c89f0415c92ebf3c4"},Kr=async()=>{let e=0;try{const t=await h.get("https://lido-aprs-proxy.balancer.workers.dev/?network=137"),{apr:a}=t.data;e=Math.round(100*parseFloat(a))}catch(e){console.error("Failed to fetch stMATIC APR:",e)}return{[Xr.stMATIC]:e}},Yr={usdcUSDplus:"0x1aafc31091d93c3ff003cff5d2d8f7ba2e728425",usdcUSDplus2:"0x6933ec1ca55c06a894107860c92acdfd2dd8512f"},Jr=async()=>{let e=0;try{const{data:t}=await h.get("https://app.overnight.fi/api/balancer/week/apr");e=Math.round(1e4*parseFloat(t)/100)}catch(e){console.error("Failed to fetch USD+ APR:",e)}return Object.fromEntries(Object.values(Yr).map((t=>[t,e])))},Zr={sfrxETH:"0xac3e018457b222d93114458476f3e3416abbe38f"},zr=async()=>{let e=0;try{const t=await h.get("https://api.frax.finance/v2/frxeth/summary/latest"),{sfrxethApr:a}=t.data;e=Math.round(100*parseFloat(a))}catch(e){console.error("Failed to fetch APR:",e)}return{[Zr.sfrxETH]:e}},Qr={maticX:"0xfa68fb4628dff1028cfec22b4162fccd0d45efb6"},eo=async()=>{let e=0;try{const t=await h.get("https://generic-apr-proxy.balancer.workers.dev/?provider=stader"),{value:a}=t.data;e=Math.round(100*parseFloat(a))}catch(e){console.error("Failed to fetch APR:",e)}return{[Qr.maticX]:e}},to={qETH:"0x93ef1ea305d11a9b2a3ebb9bb4fcc34695292e7d"},ao=async()=>{let e=0;try{const t=await h.get("https://generic-apr-proxy.balancer.workers.dev/?provider=tranchess"),[{weeklyAveragePnlPercentage:a}]=t.data;e=Math.round(parseFloat(rt(d.from(a).mul(365).mul(1e4),18)))}catch(e){console.error("Failed to fetch qETH APR:",e)}return{[to.qETH]:e}},no={USDR:"0xaf0d9d65fc54de245cda37af3d18cbec860a4d4b"},so=async()=>{let e=0;try{const t=await h.get("https://generic-apr-proxy.balancer.workers.dev/?provider=usdr"),{usdr:a}=t.data;e=Math.round(100*parseFloat(a))}catch(e){console.error("Failed to fetch USDR APR:",e)}return{[no.USDR]:e}},io={rETH:"0x9559aaa82d9649c7a7b220e7c461d2e74c9a3593"},ro=async()=>{let e=0;try{const t=await h.get("https://drop-api.stafi.io/reth/v1/poolData/"),{stakeApr:a}=t.data.data;e=Math.round(100*parseFloat(a))}catch(e){console.error("Failed to fetch APR:",e)}return{[io.rETH]:e}},oo=new q("https://rpc.ankr.com/eth",1),co={getPoolsUI:new u("0x5954aB967Bc958940b7EB73ee84797Dc8a2AFbb9",[{inputs:[],name:"getPoolsUI",outputs:[{components:[{internalType:"uint256",name:"poolId",type:"uint256"},{internalType:"uint256",name:"stakedAmount",type:"uint256"},{components:[{internalType:"uint48",name:"startTimestampHour",type:"uint48"},{internalType:"uint48",name:"endTimestampHour",type:"uint48"},{internalType:"uint96",name:"rewardsPerHour",type:"uint96"},{internalType:"uint96",name:"capPerPosition",type:"uint96"}],internalType:"struct ApeCoinStaking.TimeRange",name:"currentTimeRange",type:"tuple"}],internalType:"struct ApeCoinStaking.PoolUI",name:"",type:"tuple"},{components:[{internalType:"uint256",name:"poolId",type:"uint256"},{internalType:"uint256",name:"stakedAmount",type:"uint256"},{components:[{internalType:"uint48",name:"startTimestampHour",type:"uint48"},{internalType:"uint48",name:"endTimestampHour",type:"uint48"},{internalType:"uint96",name:"rewardsPerHour",type:"uint96"},{internalType:"uint96",name:"capPerPosition",type:"uint96"}],internalType:"struct ApeCoinStaking.TimeRange",name:"currentTimeRange",type:"tuple"}],internalType:"struct ApeCoinStaking.PoolUI",name:"",type:"tuple"},{components:[{internalType:"uint256",name:"poolId",type:"uint256"},{internalType:"uint256",name:"stakedAmount",type:"uint256"},{components:[{internalType:"uint48",name:"startTimestampHour",type:"uint48"},{internalType:"uint48",name:"endTimestampHour",type:"uint48"},{internalType:"uint96",name:"rewardsPerHour",type:"uint96"},{internalType:"uint96",name:"capPerPosition",type:"uint96"}],internalType:"struct ApeCoinStaking.TimeRange",name:"currentTimeRange",type:"tuple"}],internalType:"struct ApeCoinStaking.PoolUI",name:"",type:"tuple"},{components:[{internalType:"uint256",name:"poolId",type:"uint256"},{internalType:"uint256",name:"stakedAmount",type:"uint256"},{components:[{internalType:"uint48",name:"startTimestampHour",type:"uint48"},{internalType:"uint48",name:"endTimestampHour",type:"uint48"},{internalType:"uint96",name:"rewardsPerHour",type:"uint96"},{internalType:"uint96",name:"capPerPosition",type:"uint96"}],internalType:"struct ApeCoinStaking.TimeRange",name:"currentTimeRange",type:"tuple"}],internalType:"struct ApeCoinStaking.PoolUI",name:"",type:"tuple"}],stateMutability:"view",type:"function"}],oo).getPoolsUI},lo={sApe:"0x7966c5bae631294d7cffcea5430b78c2f76db6fa"},po=async(e=1,t=co)=>{let a=0;try{const e=(await t.getPoolsUI())[0],n=e.stakedAmount,s=e.currentTimeRange.rewardsPerHour.mul(8760);a=Number(s.mul(1e4).div(n))}catch(e){console.error("Failed to fetch Tessera Ape Coin APR:",e)}return{[lo.sApe]:a}},uo={eUSDC:"0xeb91861f8a4e1c12333f42dce8fb0ecdc28da716",eDAI:"0xe025e3ca2be02316033184551d4d3aa22024d9dc",eUSDT:"0x4d19f33948b99800b6113ff3e83bec9b537c85d2",eFRAX:"0x5484451a88a35cd0878a1be177435ca8a0e4054e"},yo={[ue.MAINNET]:"https://api.thegraph.com/subgraphs/name/euler-xyz/euler-mainnet"},bo=async()=>{const e=ue.MAINNET,t={operationName:"getAssetsAPY",query:"\n query getAssetsAPY($eTokenAddress_in: [String!]) {\n assets(\n where: {\n eTokenAddress_in: $eTokenAddress_in\n }\n ) {\n eTokenAddress\n supplyAPY\n }\n }\n",variables:{eTokenAddress_in:Object.values(uo)}},a=await h.post(yo[e],t),{data:{assets:n}}=a.data,s={eUSDT:0,eDAI:0,eUSDC:0,eFRAX:0};return n.forEach((({eTokenAddress:e,supplyAPY:t})=>{const a=Object.entries(uo).filter((([,t])=>t.toLocaleLowerCase()===e.toLocaleLowerCase()))[0][0];s[a]=Math.round(1e4*parseFloat(rt(d.from(t),27)))})),{[uo.eUSDT]:s.eUSDT,[uo.eDAI]:s.eDAI,[uo.eUSDC]:s.eUSDC,[uo.eFRAX]:s.eFRAX}},fo=Object.fromEntries([...Object.values(Wr).map((e=>[e,Vr])),...Object.values(Xr).map((e=>[e,Kr])),...Object.values(ct).map((e=>[e,ft])),...Object.values(Yr).map((e=>[e,Jr])),...Object.values(Hr).map((e=>[e,jr])),...Object.values(Zr).map((e=>[e,zr])),...Object.values(Qr).map((e=>[e,eo])),...Object.values(to).map((e=>[e,ao])),...Object.values(no).map((e=>[e,so])),...Object.values(io).map((e=>[e,ro])),...Object.values(lo).map((e=>[e,po])),...Object.values(uo).map((e=>[e,bo]))]);class mo{constructor(e,t=fo){this.network=e,this.sources=t,this.yields={}}async fetch(e){const t=await this.sources[e](this.network);this.yields={...this.yields,...t}}async find(e){const t=e.toLocaleLowerCase();return Object.keys(this.sources).includes(t)&&!Object.keys(this.yields).includes(t)&&await this.fetch(t),this.yields[t]}async findBy(e,t){if("address"==e)return this.find(t)}}const ho=e=>`{\n blocks(first: 1, orderBy: timestamp, orderDirection: asc, where: { timestamp_gt: ${e} }) {\n number\n }\n}`,To=async(e,t)=>{const a={query:ho(t)},n=await h.post(e,a),{data:{blocks:s}}=n.data;return parseInt(s[0].number)};class go{constructor(e){this.endpoint=e,this.blocks={}}async find(e){if("dayAgo"==e){const e=""+(Math.floor(Date.now()/1e3)-86400);return this.blocks[e]||(this.blocks={...this.blocks,[e]:To(this.endpoint,e)}),this.blocks[e]}}async findBy(e="",t=""){}}var Io,wo,Eo=[{chainId:1,address:"0x8888801af4d980682e47f1a9036e589479e835c5",symbol:"mph"},{chainId:1,address:"0x27054b13b1b798b345b591a4d22e6562d47ea75a",symbol:"ast"},{chainId:1,address:"0x3301ee63fb29f863f2333bd4466acb46cd8323e6",symbol:"akita"},{chainId:1,address:"0x616e8bfa43f920657b3497dbf40d6b1a02d4608d",symbol:"aurabal"},{chainId:1,address:"0xc0c293ce456ff0ed870add98a0828dd4d2903dbf",symbol:"aura"},{chainId:1,address:"0x3472a5a71965499acd81997a54bba8d852c6e53d",symbol:"badger"},{chainId:1,address:"0xba100000625a3754423978a60c9317c58a424e3d",symbol:"bal"},{chainId:1,address:"0x804cdb9116a10bb78768d3252355a1b18067bf8f",symbol:"bb-a-dai"},{chainId:1,address:"0x9210f1204b5a24742eba12f710636d76240df3d0",symbol:"bb-a-usdc"},{chainId:1,address:"0x2bbf681cc4eb09218bee85ea2a5d3d13fa40fc0c",symbol:"bb-a-usdt"},{chainId:1,address:"0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb2",symbol:"bb-a-usd"},{chainId:1,address:"0x2d94aa3e47d9d5024503ca8491fce9a2fb4da198",symbol:"bank"},{chainId:1,address:"0x0d8775f648430679a709e98d2b0cb6250d2887ef",symbol:"bat"},{chainId:1,address:"0xf17e65822b568b3903685a7c9f496cf7656cc6c2",symbol:"bico"},{chainId:1,address:"0x799ebfabe77a6e34311eeee9825190b9ece32824",symbol:"btrst"},{chainId:1,address:"0x514910771af9ca656af840dff83e8264ecf986ca",symbol:"link"},{chainId:1,address:"0x3506424f91fd33084466f402d5d97f05f8e3b4af",symbol:"chz"},{chainId:1,address:"0x41e5560054824ea6b0732e656e3ad64e20e94e45",symbol:"cvc"},{chainId:1,address:"0xc00e94cb662c3520282e6f5717214004a7f26888",symbol:"comp"},{chainId:1,address:"0xdef1ca1fb7fbcdc777520aa7f396b4e015f497ab",symbol:"cow"},{chainId:1,address:"0xd533a949740bb3306d119cc777fa900ba034cd52",symbol:"crv"},{chainId:1,address:"0x6b175474e89094c44da98b954eedeac495271d0f",symbol:"dai"},{chainId:1,address:"0xf2051511b9b121394fa75b8f7d4e7424337af687",symbol:"haus"},{chainId:1,address:"0x888888435fde8e7d4c54cab67f206e4199454c60",symbol:"dfx"},{chainId:1,address:"0x798d1be841a82a273720ce31c822c61a67a601c3",symbol:"digg"},{chainId:1,address:"0xf629cbd94d3791c9250152bd8dfbdf380e2a3b9c",symbol:"enj"},{chainId:1,address:"0xc18360217d8f7ab5e7c516566761ea12ce7f9d72",symbol:"ens"},{chainId:1,address:"0x4e15361fd6b4bb609fa63c81a2be19d873717870",symbol:"ftm"},{chainId:1,address:"0x956f47f50a910163d8bf957cf5846d573e7f87ca",symbol:"fei"},{chainId:1,address:"0xed1480d12be41d92f36f5f7bdd88212e381a3677",symbol:"fdt"},{chainId:1,address:"0x586aa273f262909eef8fa02d90ab65f5015e0516",symbol:"fiat"},{chainId:1,address:"0xde30da39c46104798bb5aa3fe8b9e0e1f348163f",symbol:"gtc"},{chainId:1,address:"0x900db999074d9277c5da2a43f252d74366230da0",symbol:"giv"},{chainId:1,address:"0x6810e776880c02933d47db1b9fc05908e5386b96",symbol:"gno"},{chainId:1,address:"0xba485b556399123261a5f9c95d413b4f93107407",symbol:"graviaura"},{chainId:1,address:"0x3ec8798b81485a254928b70cda1cf0a2bb0b74d7",symbol:"gro"},{chainId:1,address:"0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f",symbol:"snx"},{chainId:1,address:"0x5a98fcbea516cf06857215779fd812ca3bef1b32",symbol:"ldo"},{chainId:1,address:"0x6dea81c8171d0ba574754ef6f8b412f2ed88c54d",symbol:"lqty"},{chainId:1,address:"0x5f98805a4e8be255a32880fdec7f6728c6568ba0",symbol:"lusd"},{chainId:1,address:"0x965d79f1a1016b574a62986e13ca8ab04dfdd15c",symbol:"m2"},{chainId:1,address:"0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2",symbol:"mkr"},{chainId:1,address:"0xd084944d3c05cd115c09d072b9f44ba3e0e45921",symbol:"fold"},{chainId:1,address:"0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0",symbol:"matic"},{chainId:1,address:"0xa3bed4e1c75d00fa6f4e5e6922db7261b5e9acd2",symbol:"mta"},{chainId:1,address:"0x4b13006980acb09645131b91d259eaa111eaf5ba",symbol:"myc"},{chainId:1,address:"0x333a4823466879eef910a04d473505da62142069",symbol:"nation"},{chainId:1,address:"0xcfeaead4947f0705a14ec42ac3d44129e1ef3ed5",symbol:"note"},{chainId:1,address:"0x967da4048cd07ab37855c090aaf366e4ce1b9f48",symbol:"ocean"},{chainId:1,address:"0x64aa3364f17a4d01c6f1751fd97c2bd3d7e7f1d5",symbol:"ohm"},{chainId:1,address:"0xab846fb6c81370327e784ae7cbb6d6a6af6ff4bf",symbol:"pal"},{chainId:1,address:"0xcafe001067cdef266afb7eb5a286dcfd277f3de5",symbol:"psp"},{chainId:1,address:"0x68037790a0229e9ce6eaa8a99ea92964106c4703",symbol:"par"},{chainId:1,address:"0x45804880de22913dafe09f4980848ece6ecbaf78",symbol:"paxg"},{chainId:1,address:"0x89ab32156e46f46d02ade3fecbe5fc4243b9aaed",symbol:"pnt"},{chainId:1,address:"0x9992ec3cf6a55b00978cddf2b27bc6882d88d1ec",symbol:"poly"},{chainId:1,address:"0x43d4a3cd90ddd2f8f4f693170c9c8098163502ad",symbol:"d2d"},{chainId:1,address:"0xeb4c2781e4eba804ce9a9803c67d0893436bb27d",symbol:"renbtc"},{chainId:1,address:"0x408e41876cccdc0f92210600ef50372656052a38",symbol:"ren"},{chainId:1,address:"0xfb5453340c03db5ade474b27e68b6a9c6b2823eb",symbol:"robot"},{chainId:1,address:"0xd33526068d116ce69f19a9ee46f0bd304f21a51f",symbol:"rpl"},{chainId:1,address:"0xae78736cd615f374d3085123a210448e74fc6393",symbol:"reth"},{chainId:1,address:"0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6",symbol:"sbtc"},{chainId:1,address:"0x476c5e26a75bd202a9683ffd34359c0cc15be0ff",symbol:"srm"},{chainId:1,address:"0x35e78b3982e87ecfd5b3f3265b601c046cdbe232",symbol:"xai"},{chainId:1,address:"0x3affcca64c2a6f4e3b6bd9c64cd2c969efd1ecbe",symbol:"dsla"},{chainId:1,address:"0xf24d8651578a55b0c119b9910759a351a3458895",symbol:"sdbal"},{chainId:1,address:"0x11c1a6b3ed6bb362954b29d3183cfa97a0c806aa",symbol:"str"},{chainId:1,address:"0x8f693ca8d21b157107184d29d398a8d082b38b76",symbol:"data"},{chainId:1,address:"0x470ebf5f030ed85fc1ed4c2d36b9dd02e77cf1b7",symbol:"temple"},{chainId:1,address:"0xa36fdbbae3c9d55a1d67ee5821d53b50b63a1ab9",symbol:"temp"},{chainId:1,address:"0xdac17f958d2ee523a2206206994597c13d831ec7",symbol:"usdt"},{chainId:1,address:"0x9c4a4204b79dd291d6b6571c5be8bbcd0622f050",symbol:"tcr"},{chainId:1,address:"0x226f7b842e0f0120b7e194d05432b3fd14773a9d",symbol:"unn"},{chainId:1,address:"0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",symbol:"uni"},{chainId:1,address:"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",symbol:"usdc"},{chainId:1,address:"0x81f8f0bb1cb2a06649e51913a151f0e7ef6fa321",symbol:"vita"},{chainId:1,address:"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",symbol:"weth"},{chainId:1,address:"0xedb171c18ce90b633db442f2a6f72874093b49ef",symbol:"wampl"},{chainId:1,address:"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",symbol:"wbtc"},{chainId:1,address:"0xf203ca1769ca8e9e8fe1da9d147db68b6c919817",symbol:"wncg"},{chainId:1,address:"0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",symbol:"wsteth"},{chainId:1,address:"0x79c71d3436f39ce382d0f58f1b011d88100b9d91",symbol:"xns"},{chainId:1,address:"0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e",symbol:"yfi"},{chainId:1,address:"0xbcca60bb61934080951369a648fb03df4f96263c",symbol:"ausdc"},{chainId:1,address:"0x028171bca77440897b824ca71d1c56cac55b68a3",symbol:"adai"},{chainId:1,address:"0x3ed3b47dd13ec9a98b44e6204a523e766b225811",symbol:"ausdt"},{chainId:137,address:"0x9c2c5fd7b07e95ee044ddeba0e97a665f142394f",symbol:"1inch"},{chainId:137,address:"0xd6df932a45c0f255f85145f286ea0b292b21c90b",symbol:"aave"},{chainId:137,address:"0xc3fdbadc7c795ef1d6ba111e06ff8f16a20ea539",symbol:"addy"},{chainId:137,address:"0xf84bd51eab957c2e7b7d646a3427c5a50848281d",symbol:"agar"},{chainId:137,address:"0x033d942a6b495c4071083f4cde1f17e986fe856c",symbol:"aga"},{chainId:137,address:"0x0e9b89007eee9c958c0eda24ef70723c2c93dd58",symbol:"amaticc"},{chainId:137,address:"0x034b2090b579228482520c589dbd397c53fc51cc",symbol:"vision"},{chainId:137,address:"0x2c89bbc92bd86f8075d1decc58c7f4e0107f286b",symbol:"avax"},{chainId:137,address:"0x49690541e3f6e933a9aa3cffee6010a7bb5b72d7",symbol:"axiav3"},{chainId:137,address:"0x9a71012b13ca4d3d0cdc72a177df3ef03b0e76a3",symbol:"bal"},{chainId:137,address:"0xdb7cb471dd0b49b29cab4a1c14d070f27216a0ab",symbol:"bank"},{chainId:137,address:"0xfbdd194376de19a88118e84e279b977f165d01b8",symbol:"bifi"},{chainId:137,address:"0xd6ca869a4ec9ed2c7e618062cdc45306d8dbbc14",symbol:"btc2x-fli-p"},{chainId:137,address:"0x53e0bca35ec356bd5dddfebbd1fc0fd03fabad39",symbol:"link"},{chainId:137,address:"0x172370d5cd63279efa6d502dab29171933a610af",symbol:"crv"},{chainId:137,address:"0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",symbol:"dai"},{chainId:137,address:"0x1d607faa0a51518a7728580c238d912747e71f7a",symbol:"data"},{chainId:137,address:"0x85955046df4668e1dd369d2de9f3aeb98dd2a369",symbol:"dpi"},{chainId:137,address:"0xe7804d91dfcde7f776c90043e03eaa6df87e6395",symbol:"dfx"},{chainId:137,address:"0xf28164a485b0b2c90639e47b0f377b4a438a16b1",symbol:"dquick"},{chainId:137,address:"0x45c32fa6df82ead1e2ef74d17b76547eddfaff89",symbol:"frax"},{chainId:137,address:"0x50b728d8d964fd00c2d0aad81718b71311fef68a",symbol:"snx"},{chainId:137,address:"0x72928d5436ff65e57f72d5566dcd3baedc649a88",symbol:"hdao"},{chainId:137,address:"0x3ad707da309f3845cd602059901e39c4dcd66473",symbol:"eth2x-fli-p"},{chainId:137,address:"0x4f025829c4b13df652f38abd2ab901185ff1e609",symbol:"ieth-fli-p"},{chainId:137,address:"0x340f412860da7b7823df372a2b59ff78b7ae6abc",symbol:"imatic-fli-p"},{chainId:137,address:"0xf287d97b6345bad3d88856b26fb7c0ab3f2c7976",symbol:"matic2x-fli-p"},{chainId:137,address:"0x130ce4e4f76c2265f94a961d70618562de0bb8d2",symbol:"ibtc-fli-p"},{chainId:137,address:"0x596ebe76e2db4470966ea395b0d063ac6197a8c5",symbol:"jrt"},{chainId:137,address:"0x3a58a54c066fdc0f2d55fc9c89f0415c92ebf3c4",symbol:"stmatic"},{chainId:137,address:"0xf501dd45a1198c2e1b5aef5314a68b9006d842e0",symbol:"mta"},{chainId:137,address:"0xeaecc18198a475c921b24b8a6c1c1f0f5f3f7ea0",symbol:"seed"},{chainId:137,address:"0xfe712251173a2cd5f5be2b46bb528328ea3565e1",symbol:"mvi"},{chainId:137,address:"0xa3fa99a148fa48d14ed51d610c367c61876997f1",symbol:"mimatic"},{chainId:137,address:"0xa486c6bc102f409180ccb8a94ba045d39f8fc7cb",symbol:"nex"},{chainId:137,address:"0xe2aa7db6da1dae97c5f5c6914d285fbfcc32a128",symbol:"par"},{chainId:137,address:"0x580a84c73811e1839f75d86d75d88cca0c241ff4",symbol:"qi"},{chainId:137,address:"0x831753dd7087cac61ab5644b308642cc1c33dc13",symbol:"quick"},{chainId:137,address:"0xb5c064f955d8e7f38fe0460c556a72987494ee17",symbol:"quick"},{chainId:137,address:"0x00e5646f60ac6fb446f621d146b6e1886f002905",symbol:"rai"},{chainId:137,address:"0x431cd3c9ac9fc73644bf68bf5691f4b83f9e104f",symbol:"rbw"},{chainId:137,address:"0xdbf31df14b66535af65aac99c32e9ea844e14501",symbol:"renbtc"},{chainId:137,address:"0x501ace9c35e60f03a2af4d484f49f9b1efde9f40",symbol:"solace"},{chainId:137,address:"0xfa68fb4628dff1028cfec22b4162fccd0d45efb6",symbol:"maticx"},{chainId:137,address:"0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a",symbol:"sushi"},{chainId:137,address:"0xdf7837de1f2fa4631d716cf2502f8b230f1dcc32",symbol:"tel"},{chainId:137,address:"0xe6469ba6d2fd6130788e0ea9c0a0515900563b59",symbol:"ust"},{chainId:137,address:"0xc2132d05d31c914a87c6611c10748aeb04b58e8f",symbol:"usdt"},{chainId:137,address:"0x5fe2b58c013d7601147dcdd68c143a77499f5531",symbol:"grt"},{chainId:137,address:"0xbbba073c31bf03b8acf7c28ef0738decf3695683",symbol:"sand"},{chainId:137,address:"0x2934b36ca9a4b31e633c5be670c8c8b28b6aa015",symbol:"thx"},{chainId:137,address:"0x2f800db0fdb5223b3c3f354886d907a671414a7f",symbol:"bct"},{chainId:137,address:"0x2e1ad108ff1d8c782fcbbb89aad783ac49586756",symbol:"tusd"},{chainId:137,address:"0x3809dcdd5dde24b37abe64a5a339784c3323c44f",symbol:"swap"},{chainId:137,address:"0x7fbc10850cae055b27039af31bd258430e714c62",symbol:"ubt"},{chainId:137,address:"0x2791bca1f2de4661ed88a30c99a7a9449aa84174",symbol:"usdc"},{chainId:137,address:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",symbol:"weth"},{chainId:137,address:"0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",symbol:"wmatic"},{chainId:137,address:"0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6",symbol:"wbtc"},{chainId:137,address:"0x24834bbec7e39ef42f4a75eaf8e5b6486d3f0e57",symbol:"lunc"},{chainId:137,address:"0xf153eff70dc0bf3b085134928daeea248d9b30d0",symbol:"xmark"},{chainId:42161,address:"0x9f20de1fc9b161b34089cbeae888168b44b03461",symbol:"arbis"},{chainId:42161,address:"0x040d1edc9569d4bab2d15287dc5a4f10f56a56b8",symbol:"bal"},{chainId:42161,address:"0x031d35296154279dc1984dcd93e392b1f946737b",symbol:"cap"},{chainId:42161,address:"0xf97f4df75117a78c1a5a0dbb814af92458539fb4",symbol:"link"},{chainId:42161,address:"0x354a6da3fcde098f8389cad84b0182725c6c91de",symbol:"comp"},{chainId:42161,address:"0xf4d48ce3ee1ac3651998971541badbb9a14d7234",symbol:"cream"},{chainId:42161,address:"0x11cdb42b0eb46d95f990bedd4695a6e3fa034978",symbol:"crv"},{chainId:42161,address:"0xda10009cbd5d07dd0cecc66161fc93d7c9000da1",symbol:"dai"},{chainId:42161,address:"0x8038f3c971414fd1fc220ba727f2d4a0fc98cb65",symbol:"dht"},{chainId:42161,address:"0xf0b5ceefc89684889e5f7e0a7775bd100fcd3709",symbol:"dusd"},{chainId:42161,address:"0x6c2c06790b3e3e3c38e12ee22f8183b37a13ee55",symbol:"dpx"},{chainId:42161,address:"0x32eb7902d4134bf98a28b963d26de779af92a212",symbol:"rdpx"},{chainId:42161,address:"0xc3ae0333f0f34aa734d5493276223d95b8f9cb37",symbol:"dxd"},{chainId:42161,address:"0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a",symbol:"gmx"},{chainId:42161,address:"0xa0b862f60edef4452f25b4160f177db44deb6cf1",symbol:"gno"},{chainId:42161,address:"0xb965029343d55189c25a7f3e0c9394dc0f5d41b1",symbol:"ndx"},{chainId:42161,address:"0x539bde0d7dbd336b79148aa742883198bbf60342",symbol:"magic"},{chainId:42161,address:"0x4e352cf164e64adcbad318c3a1e222e9eba4ce42",symbol:"mcb"},{chainId:42161,address:"0x3f56e0c36d275367b8c502090edf38289b3dea0d",symbol:"mimatic"},{chainId:42161,address:"0x965772e0e9c84b6f359c8597c891108dcf1c5b1a",symbol:"pickle"},{chainId:42161,address:"0x6694340fc020c5e6b96567843da2df01b2ce1eb6",symbol:"stg"},{chainId:42161,address:"0xd4d42f0b6def4ce0383636770ef773390d85c61a",symbol:"sushi"},{chainId:42161,address:"0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",symbol:"usdt"},{chainId:42161,address:"0x23a941036ae778ac51ab04cea08ed6e2fe103614",symbol:"grt"},{chainId:42161,address:"0xa72159fc390f0e3c6d415e658264c7c4051e9b87",symbol:"tcr"},{chainId:42161,address:"0x4d15a3a2286d883af0aa1b3f21367843fac63e07",symbol:"tusd"},{chainId:42161,address:"0xfa7f8980b0f1e64a2062791cc3b0871572f1f7f0",symbol:"uni"},{chainId:42161,address:"0xff970a61a04b1ca14834a43f5de4533ebddb5cc8",symbol:"usdc"},{chainId:42161,address:"0xa684cd057951541187f288294a1e1c2646aa2d24",symbol:"vsta"},{chainId:42161,address:"0x64343594ab9b56e99087bfa6f2335db24c2d1f17",symbol:"vst"},{chainId:42161,address:"0x82af49447d8a07e3bd95bd0d56f35241523fbab1",symbol:"weth"},{chainId:42161,address:"0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f",symbol:"wbtc"},{chainId:42161,address:"0x82e3a8f066a6989666b031d916c43672085b1582",symbol:"yfi"},{chainId:16116,address:"0x5a89E11Cb554E00c2f51C4bb7F05bc7Ab0Fa6351",symbol:"weth"},{chainId:9372,address:"0x5200000000000000000000000000000000000001",symbol:"weth"},{chainId:248,address:"0x5200000000000000000000000000000000000001",symbol:"weth"},{chainId:6343,address:"0xAba76Cdc5910F6627856EB75Bcce0171376999C7",symbol:"weth"},{chainId:4326,address:"0x4200000000000000000000000000000000000006",symbol:"weth"}];class xo{constructor(e,t,a){this.pools=new hr({url:e.urls.subgraph,chainId:e.chainId}),this.poolsOnChain=new Tr({url:e.urls.subgraph,chainId:e.chainId,provider:t,multicall:e.addresses.contracts.multicall,vault:e.addresses.contracts.vault,query:a}),this.poolShares=new Er(e.urls.subgraph,e.chainId),this.poolJoinExits=new wr(e.urls.subgraph,e.chainId),e.urls.gaugesSubgraph&&(this.poolGauges=new gr(e.urls.gaugesSubgraph,e.chainId),this.gaugeShares=new or(e.urls.gaugesSubgraph,e.chainId)),e.urls.blockNumberSubgraph&&(this.blockNumbers=new go(e.urls.blockNumberSubgraph));this.yesterdaysPools=new hr({url:e.urls.subgraph,chainId:e.chainId,blockHeight:async()=>{const e=await t.getBlockNumber();return Number(e)-5e3}});const n=Eo.filter((t=>t.chainId==e.chainId)).map((e=>e.address)),s=new Sr(n,e.chainId),i=new _r(e.urls.subgraph,e.chainId),r=new kr(e.addresses.contracts.multicall,t,e.chainId);this.tokenPrices=new vr(s,i,r);const o=new Pr(e.chainId);this.tokenHistoricalPrices=new Or(o,r),this.tokenMeta=new xr([]),e.urls.gaugesSubgraph&&(this.liquidityGauges=new ur(e.urls.gaugesSubgraph,e.addresses.contracts.multicall,e.addresses.contracts.gaugeController||"",e.chainId,t)),e.addresses.contracts.feeDistributor&&e.addresses.tokens.bal&&e.addresses.tokens.veBal&&e.addresses.tokens.bbaUsd&&(this.feeDistributor=new Fr(e.addresses.contracts.multicall,e.addresses.contracts.feeDistributor,e.addresses.tokens.bal,e.addresses.tokens.veBal,e.addresses.tokens.bbaUsd,t)),this.feeCollector=new Ur(e.addresses.contracts.vault,t),e.addresses.contracts.protocolFeePercentagesProvider&&(this.protocolFees=new qr(e.addresses.contracts.multicall,e.addresses.contracts.protocolFeePercentagesProvider,t)),this.tokenYields=new mo(e.chainId)}}class Ao{constructor(e,t=new Os(e),a=new Xs(e)){this.config=e,this.sor=t,this.subgraph=a,this.networkConfig=vs(e),this.provider=t.provider,this.data=new xo(this.networkConfig,t.provider,e.subgraphQuery),this.swaps=new Vs(this.config),this.relayer=new js(this.swaps),this.pricing=new Ks(e,this.swaps),this.pools=new tr(this.networkConfig,this.data),this.balancerContracts=new ii(this.networkConfig.addresses.contracts,t.provider),this.zaps=new vi(this.networkConfig.chainId)}get rpcProvider(){return this.sor.provider}get contracts(){return this.balancerContracts.contracts}}!function(e){e[e.Direct=0]="Direct",e[e.TokenIn=1]="TokenIn",e[e.TokenOut=2]="TokenOut",e[e.Middle=3]="Middle"}(Io||(Io={})),function(e){e[e.Swap=0]="Swap",e[e.BatchSwap=1]="BatchSwap",e[e.Join=2]="Join",e[e.Exit=3]="Exit"}(wo||(wo={}));const So={type:wo.BatchSwap,swaps:[],opRef:[],minOut:"0",assets:[],hasTokenIn:!1,hasTokenOut:!1,fromInternal:!1,toInternal:!1,limits:[],approveTokens:[],sender:"",receiver:""},Po=new t(ai);function _o(e,t){return e.some((e=>e.address.toLowerCase()===t.toLowerCase()))}function vo(e,t,a){return e!==N.SwapExactOut&&t.toLowerCase()!==i.toLowerCase()&&a.toLowerCase()!==i.toLowerCase()}function Oo(e,t){const a=t[e.assetOutIndex],n=ce(e.poolId);return a.toLowerCase()===n.toLowerCase()}function Bo(e,t){const a=t[e.assetInIndex],n=ce(e.poolId);return a.toLowerCase()===n.toLowerCase()}function ko(e,t,a){return t.some((t=>function(e,t,a){const n=e.find((e=>e.id===t.poolId));return"Weighted"===(null==n?void 0:n.poolType)&&[a[t.assetInIndex],a[t.assetOutIndex]].includes(n.address)}(e,t,a)))}function Do(e,t,a){let n={};var s;return e!==Io.TokenIn&&e!==Io.Middle||(s=a,n={index:t,key:js.toChainedReference(s)},a++),[n,a]}function No(e,t){return Ft(d.from(e),d.from(t)).toString()}function Co(e,t,a,n){let s=e.amount;return(a===Io.TokenOut||a===Io.Middle&&t===wo.Join||a===Io.Middle&&t===wo.Exit)&&(s=js.toChainedReference(n-1).toString()),s}function Fo(e,t,a,n){let s;return s=a===e&&n===t?Io.Direct:a===e?Io.TokenIn:n===t?Io.TokenOut:Io.Middle,s}function Ro(e,t){const a=function(e){const t=[],a=[],n=[];for(const s of e)s.type===wo.Exit||s.type===wo.Join?s.hasTokenIn?t.push(s):s.hasTokenOut?a.push(s):n.push(s):n.push(s);return[...t,...n,...a]}(e),n=function(e,t){const a=[];let n=g(So);n.assets=t,n.limits=Array(t.length).fill(d.from("0"));let s=!0,i={};for(const r of e)r.type===wo.Swap?(s&&(i=r,s=!1),r.isBptIn&&n.approveTokens.push(r.assets[r.swap.assetInIndex]),r.fromInternal===i.fromInternal&&r.toInternal===i.toInternal&&r.receiver===i.receiver&&r.sender===i.sender||n.swaps.length>0&&(a.push(n),n=g(So),n.assets=t,n.limits=Array(t.length).fill(d.from("0"))),n.swaps.push(r.swap),n.opRef.push(...r.opRef),n.fromInternal=r.fromInternal,n.toInternal=r.toInternal,n.sender=r.sender,n.receiver=r.receiver,r.hasTokenIn?(n.hasTokenIn=!0,n.limits[r.swap.assetInIndex]=n.limits[r.swap.assetInIndex].add(r.amountIn)):n.limits[r.swap.assetInIndex]=o,r.hasTokenOut&&(n.hasTokenOut=!0,n.limits[r.swap.assetOutIndex]=n.limits[r.swap.assetOutIndex].sub(r.minOut)),i=r):(n.swaps.length>0&&(a.push(n),n=g(So),n.assets=t,n.limits=Array(t.length).fill(d.from("0"))),a.push(r));return n.swaps.length>0&&a.push(n),a}(a,t);return n}function Mo(e,t,a,n,s,i,r,o){var d;const c=Fo(t,a,e.assetInIndex,e.assetOutIndex),l=Co(e,wo.Join,c,n),p=No(null!==(d=e.returnAmount)&&void 0!==d?d:"0",i),[u,y]=Do(c,e.assetOutIndex,n);let b=o,f=!0,m=!1;c!==Io.Direct&&c!==Io.TokenIn||(b=r,f=!1,m=!0);let h=o,T=!1;c!==Io.Direct&&c!==Io.TokenOut||(h=r,T=!0);return[{type:wo.Join,poolId:e.poolId,tokenIn:s[e.assetInIndex],bpt:s[e.assetOutIndex],opRef:u,minOut:p,amountIn:l,assets:s,actionStep:c,sender:b,receiver:h,fromInternal:f,hasTokenIn:m,hasTokenOut:T},y]}function Lo(e,t,a,n,s,i,r,o){var d;const c=Fo(t,a,e.assetInIndex,e.assetOutIndex),l=Co(e,wo.Exit,c,n),p=No(null!==(d=e.returnAmount)&&void 0!==d?d:"0",i),[u,y]=Do(c,e.assetOutIndex,n);let b=o,f=!1;c!==Io.Direct&&c!==Io.TokenIn||(b=r,f=!0);let m=!1,h=!0,T=o;c!==Io.Direct&&c!==Io.TokenOut||(T=r,h=!1,m=!0);return[{type:wo.Exit,poolId:e.poolId,tokenOut:s[e.assetOutIndex],bpt:s[e.assetInIndex],opRef:u.key?[u]:[],minOut:p,amountIn:l,assets:s,actionStep:c,sender:b,receiver:T,toInternal:h,hasTokenIn:f,hasTokenOut:m},y]}function Uo(e,t,a,n,s,i,r,o,d){var c;const l=Fo(t,a,e.assetInIndex,e.assetOutIndex),p=Co(e,wo.Swap,l,n);e.amount=p;const u=No(null!==(c=e.returnAmount)&&void 0!==c?c:"0",i),[y,b]=Do(l,e.assetOutIndex,n),f=l===Io.Direct||l===Io.TokenIn,m=l===Io.Direct||l===Io.TokenOut,h=_o(r,s[e.assetInIndex]);let T=!0;(f||h)&&(T=!1);let g,I,w=!0;(m||_o(r,s[e.assetOutIndex]))&&(w=!1),g=f?o:d,I=m?o:d;return[{type:wo.Swap,opRef:y.key?[y]:[],minOut:u,amountIn:p,assets:s,swap:e,hasTokenIn:f,hasTokenOut:m,fromInternal:T,toInternal:w,isBptIn:h,sender:g,receiver:I},b]}function Go(e,t,a){const n=e.tokensList,s=new we(a),[i]=s.sortTokens(n),r=t.tokenOut,o=i.findIndex((e=>e.toLowerCase()===r.toLowerCase())),d=Array(n.length).fill("0");d[o]=t.minOut;const c=t.amountIn,l={assets:i,minAmountsOut:d,userData:z.exitExactBPTInForOneTokenOut(c,o),toInternalBalance:t.toInternal,poolId:t.poolId,poolKind:0,sender:t.sender,recipient:t.receiver,outputReferences:t.opRef,exitPoolRequest:{}},p=js.constructExitCall(l),u=t.hasTokenOut?d[o]:"0";return[p,t.hasTokenIn?c:"0",u]}function $o(e,t,a){const n=e.tokensList,s=new we(a),[i]=s.sortTokens(n),r=t.tokenIn,o=i.findIndex((e=>e.toLowerCase()===r.toLowerCase())),d=Array(n.length).fill("0");d[o]=t.amountIn;const c=t.minOut,l=z.joinExactTokensInForBPTOut(d,c),p={poolId:t.poolId,sender:t.sender,recipient:t.receiver,kind:0,joinPoolRequest:{assets:i,maxAmountsIn:d,userData:l,fromInternalBalance:t.fromInternal},value:"0",outputReference:t.opRef.key?t.opRef.key.toString():"0"},u=js.encodeJoinPool(p),y=t.hasTokenOut?c:"0";return[u,t.hasTokenIn?d[o]:"0",y]}function qo(e,t,a){const n=[];for(const t of e.approveTokens){const e=js.encodeApproveVault(t,r.toString());n.push(e)}const s={sender:e.sender,recipient:e.receiver,fromInternalBalance:e.fromInternal,toInternalBalance:e.toInternal},i={swapType:kt.SwapExactIn,swaps:e.swaps,assets:e.assets,funds:s,limits:e.limits.map((e=>e.toString())),deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:e.opRef},o=js.encodeBatchSwap(i);n.push(o);const c=e.assets.findIndex((e=>e.toLowerCase()===t.toLowerCase())),l=e.assets.findIndex((e=>e.toLowerCase()===a.toLowerCase()));return[n,e.hasTokenIn?e.limits[c].toString():"0",e.hasTokenOut?e.limits[l].abs().toString():"0"]}function Wo(e,t,a,n,s,i,r){const o=function(e,t,a,n,s,i,r,o){const d=n.findIndex((t=>t.toLowerCase()===e.toLowerCase())),c=n.findIndex((e=>e.toLowerCase()===t.toLowerCase())),l=[];let p=0,u={};for(const e of a)if(Oo(e,n)){const[t,a]=Mo(e,d,c,p,n,s,r,o);p=a,l.push(t),u=t}else{if(!Bo(e,n)){const t=e.amount,[a,y]=Uo(e,d,c,p,n,s,i,r,o);u.type===wo.Swap&&"0"===t&&(u.receiver=u.sender,u.toInternal=u.fromInternal,u.opRef=[],a.sender=u.receiver,a.fromInternal=u.fromInternal,a.amountIn="0",a.swap.amount="0"),p=y,l.push(a),u=a;continue}{const[t,a]=Lo(e,d,c,p,n,s,r,o);p=a,l.push(t),u=t}}return l}(e.tokenIn,e.tokenOut,e.swaps,e.tokenAddresses,i,t,a,n),c=Ro(o,e.tokenAddresses),l=[],p=[],u=[];r&&l.push(function(e,t){return js.encodeSetRelayerApproval(t,!0,e)}(r,n));for(const a of c){if(a.type===wo.Exit){const e=t.find((e=>e.id===a.poolId));if(void 0===e)throw new $t(Gt.NO_POOL_DATA);const[n,i,r]=Go(e,a,s);l.push(n),p.push(d.from(i)),u.push(d.from(r))}if(a.type===wo.Join){const e=t.find((e=>e.id===a.poolId));if(void 0===e)throw new $t(Gt.NO_POOL_DATA);const[n,i,r]=$o(e,a,s);l.push(n),p.push(d.from(i)),u.push(d.from(r))}if(a.type===wo.BatchSwap){const[t,n,s]=qo(a,e.tokenIn,e.tokenOut);l.push(...t),p.push(d.from(n)),u.push(d.from(s))}}!function(e,t,a,n){const s=e.reduce(((e=d.from(0),t)=>e.add(t))),i=t.reduce(((e=d.from(0),t)=>e.add(t))),r=i.sub(Ft(a.returnAmount,d.from(n)));if(!s.eq(a.swapAmount)||!r.lt("3"))throw new $t(Gt.RELAY_SWAP_AMOUNTS)}(p,u,e,i);return{to:n,data:Po.encodeFunctionData("multicall",[l]),rawCalls:l}}export{ye as APR_THRESHOLD,ge as AaveHelpers,kr as AaveRates,we as AssetHelpers,vt as BalancerAPIArgsFormatter,$t as BalancerError,Gt as BalancerErrorCode,xe as BalancerErrors,_e as BalancerMinterAuthorization,Ao as BalancerSDK,go as BlockNumberRepository,Pr as CoingeckoHistoricalPriceRepository,Sr as CoingeckoPriceRepository,se as ComposableStablePoolEncoder,ne as ComposableStablePoolExitKind,ae as ComposableStablePoolJoinKind,xo as Data,It as Debouncer,Ur as FeeCollectorRepository,Fr as FeeDistributorRepository,nr as GaugeControllerMulticallRepository,We as GaugeShareAttributes,or as GaugeSharesRepository,Bt as GraphQLArgsBuilder,Or as HistoricalPriceProvider,Pa as Liquidity,ur as LiquidityGaugeSubgraphRPCProvider,cr as LiquidityGaugesMulticallRepository,lr as LiquidityGaugesSubgraphRepository,Q as ManagedPoolEncoder,ue as Network,he as POOLS,je as PoolBalanceOpKind,$e as PoolGaugesAttributes,gr as PoolGaugesRepository,Ir as PoolJoinExitAttributes,wr as PoolJoinExitRepository,qe as PoolShareAttributes,Er as PoolSharesRepository,Ve as PoolSpecialization,Xe as PoolType,tr as Pools,br as PoolsBalancerAPIRepository,fr as PoolsFallbackRepository,mr as PoolsStaticRepository,Tr as PoolsSubgraphOnChainRepository,hr as PoolsSubgraphRepository,qr as ProtocolFeesProvider,js as Relayer,Se as RelayerAction,Pe as RelayerAuthorization,be as SHALLOW_COMPOSABLE_STABLE_BUFFER,Os as Sor,X as StablePhantomPoolJoinKind,Z as StablePoolEncoder,K as StablePoolExitKind,j as StablePoolJoinKind,Ar as StaticTokenPriceProvider,xr as StaticTokenProvider,Xs as Subgraph,Ot as SubgraphArgsFormatter,_r as SubgraphPriceRepository,kt as SwapType,Vs as Swaps,vr as TokenPriceProvider,mo as TokenYieldsRepository,He as UserBalanceOpKind,z as WeightedPoolEncoder,J as WeightedPoolExitKind,Y as WeightedPoolJoinKind,Ae as accountToAddress,Tt as addressMapIn,Ni as balEmissions,St as bn,Wo as buildRelayerCalls,vo as canUseJoinExit,Et as formatFixed,At as formatFromBigInt18,Dt as getLimitsForSlippage,ce as getPoolAddress,pe as getPoolNonce,le as getPoolSpecialization,_t as insert,te as isNormalizedWeights,Pt as isSameAddress,wt as parseFixed,Le as parsePoolInfo,xt as parseToBigInt18,ve as signPermit,ko as someJoinExit,de as splitPoolId,ee as toNormalizedWeights,ht as tokenAddressForPricing,mt as tokensToTokenPrices,gt as unwrapToken};
|
|
488
|
+
`,ys=(e,t,a)=>e();function bs(e){return Wn(new W(e))}function fs(e){return function(e,t=ys){return{GaugeShare:(a,n)=>t((t=>e.request(ds,a,{...n,...t})),"GaugeShare","query"),GaugeShares:(a,n)=>t((t=>e.request(cs,a,{...n,...t})),"GaugeShares","query"),LiquidityGauges:(a,n)=>t((t=>e.request(ls,a,{...n,...t})),"LiquidityGauges","query"),Pools:(a,n)=>t((t=>e.request(ps,a,{...n,...t})),"Pools","query"),PoolGauges:(a,n)=>t((t=>e.request(us,a,{...n,...t})),"PoolGauges","query")}}(new W(e))}const ms=["function aggregate(tuple[](address target, bytes callData) memory calls) public view returns (uint256 blockNumber, bytes[] memory returnData)"],hs=(e,t)=>new u(e,ms,t);class Ts{constructor(e,a,n,s={}){this.options={},this.calls=[],this.paths=[],this.multiAddress=e,this.provider=a,this.interface=new t(n),this.options=s}call(e,t,a,n){return this.calls.push([t,a,n]),this.paths.push(e),this}async execute(e={}){const t=e;return(await this.executeMulticall()).forEach(((e,a)=>I(t,this.paths[a],e.length>1?e:e[0]))),this.calls=[],this.paths=[],t}async executeMulticall(){const e=hs(this.multiAddress,this.provider),[,t]=await e.aggregate(this.calls.map((([e,t,a])=>[e,this.interface.encodeFunctionData(t,a)])),this.options);return t.map(((e,t)=>this.interface.decodeFunctionResult(this.calls[t][1],e)))}}var gs=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"},{internalType:"contract IERC20[]",name:"tokens",type:"address[]"},{internalType:"uint256[]",name:"normalizedWeights",type:"uint256[]"},{internalType:"uint256",name:"swapFeePercentage",type:"uint256"},{internalType:"uint256",name:"pauseWindowDuration",type:"uint256"},{internalType:"uint256",name:"bufferPeriodDuration",type:"uint256"},{internalType:"address",name:"owner",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"paused",type:"bool"}],name:"PausedStateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"SwapFeePercentageChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"decreaseApproval",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"getActionId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAuthorizer",outputs:[{internalType:"contract IAuthorizer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getInvariant",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLastInvariant",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getNormalizedWeights",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPausedState",outputs:[{internalType:"bool",name:"paused",type:"bool"},{internalType:"uint256",name:"pauseWindowEndTime",type:"uint256"},{internalType:"uint256",name:"bufferPeriodEndTime",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPoolId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getSwapFeePercentage",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"increaseApproval",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onExitPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onJoinPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IERC20",name:"tokenIn",type:"address"},{internalType:"contract IERC20",name:"tokenOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IPoolSwapStructs.SwapRequest",name:"request",type:"tuple"},{internalType:"uint256",name:"balanceTokenIn",type:"uint256"},{internalType:"uint256",name:"balanceTokenOut",type:"uint256"}],name:"onSwap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryExit",outputs:[{internalType:"uint256",name:"bptIn",type:"uint256"},{internalType:"uint256[]",name:"amountsOut",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryJoin",outputs:[{internalType:"uint256",name:"bptOut",type:"uint256"},{internalType:"uint256[]",name:"amountsIn",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"paused",type:"bool"}],name:"setPaused",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"setSwapFeePercentage",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],Is=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"},{internalType:"contract IERC20[]",name:"tokens",type:"address[]"},{internalType:"uint256",name:"amplificationParameter",type:"uint256"},{internalType:"uint256",name:"swapFeePercentage",type:"uint256"},{internalType:"uint256",name:"pauseWindowDuration",type:"uint256"},{internalType:"uint256",name:"bufferPeriodDuration",type:"uint256"},{internalType:"address",name:"owner",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"startValue",type:"uint256"},{indexed:!1,internalType:"uint256",name:"endValue",type:"uint256"},{indexed:!1,internalType:"uint256",name:"startTime",type:"uint256"},{indexed:!1,internalType:"uint256",name:"endTime",type:"uint256"}],name:"AmpUpdateStarted",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"currentValue",type:"uint256"}],name:"AmpUpdateStopped",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"paused",type:"bool"}],name:"PausedStateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"SwapFeePercentageChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"getActionId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAmplificationParameter",outputs:[{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"isUpdating",type:"bool"},{internalType:"uint256",name:"precision",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAuthorizer",outputs:[{internalType:"contract IAuthorizer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPausedState",outputs:[{internalType:"bool",name:"paused",type:"bool"},{internalType:"uint256",name:"pauseWindowEndTime",type:"uint256"},{internalType:"uint256",name:"bufferPeriodEndTime",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPoolId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getSwapFeePercentage",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onExitPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onJoinPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IERC20",name:"tokenIn",type:"address"},{internalType:"contract IERC20",name:"tokenOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IPoolSwapStructs.SwapRequest",name:"swapRequest",type:"tuple"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"indexIn",type:"uint256"},{internalType:"uint256",name:"indexOut",type:"uint256"}],name:"onSwap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IERC20",name:"tokenIn",type:"address"},{internalType:"contract IERC20",name:"tokenOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IPoolSwapStructs.SwapRequest",name:"request",type:"tuple"},{internalType:"uint256",name:"balanceTokenIn",type:"uint256"},{internalType:"uint256",name:"balanceTokenOut",type:"uint256"}],name:"onSwap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryExit",outputs:[{internalType:"uint256",name:"bptIn",type:"uint256"},{internalType:"uint256[]",name:"amountsOut",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryJoin",outputs:[{internalType:"uint256",name:"bptOut",type:"uint256"},{internalType:"uint256[]",name:"amountsIn",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"},{internalType:"bytes",name:"poolConfig",type:"bytes"}],name:"setAssetManagerPoolConfig",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bool",name:"paused",type:"bool"}],name:"setPaused",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"setSwapFeePercentage",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"rawEndValue",type:"uint256"},{internalType:"uint256",name:"endTime",type:"uint256"}],name:"startAmplificationParameterUpdate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"stopAmplificationParameterUpdate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],ws=[{inputs:[{internalType:"contract IERC20",name:"_underlying",type:"address"},{internalType:"contract IERC20",name:"_bond",type:"address"},{internalType:"uint256",name:"_expiration",type:"uint256"},{internalType:"uint256",name:"_unitSeconds",type:"uint256"},{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"uint256",name:"_percentFee",type:"uint256"},{internalType:"uint256",name:"_percentFeeGov",type:"uint256"},{internalType:"address",name:"_governance",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"collectedBase",type:"uint256"},{indexed:!1,internalType:"uint256",name:"collectedBond",type:"uint256"},{indexed:!1,internalType:"uint256",name:"remainingBase",type:"uint256"},{indexed:!1,internalType:"uint256",name:"remainingBond",type:"uint256"}],name:"FeeCollection",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"FEE_BOUND",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"bond",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"bondDecimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"decreaseApproval",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"expiration",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"feesBond",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"view",type:"function"},{inputs:[],name:"feesUnderlying",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPoolId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"governance",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"increaseApproval",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"currentBalances",type:"uint256[]"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"uint256",name:"protocolSwapFee",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onExitPool",outputs:[{internalType:"uint256[]",name:"amountsOut",type:"uint256[]"},{internalType:"uint256[]",name:"dueProtocolFeeAmounts",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"currentBalances",type:"uint256[]"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"uint256",name:"protocolSwapFee",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onJoinPool",outputs:[{internalType:"uint256[]",name:"amountsIn",type:"uint256[]"},{internalType:"uint256[]",name:"dueProtocolFeeAmounts",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IERC20",name:"tokenIn",type:"address"},{internalType:"contract IERC20",name:"tokenOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IPoolSwapStructs.SwapRequest",name:"swapRequest",type:"tuple"},{internalType:"uint256",name:"currentBalanceTokenIn",type:"uint256"},{internalType:"uint256",name:"currentBalanceTokenOut",type:"uint256"}],name:"onSwap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"percentFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"percentFeeGov",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amountX",type:"uint256"},{internalType:"uint256",name:"reserveX",type:"uint256"},{internalType:"uint256",name:"reserveY",type:"uint256"},{internalType:"bool",name:"out",type:"bool"}],name:"solveTradeInvariant",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"underlying",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"underlyingDecimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"unitSeconds",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"}],Es=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"},{internalType:"contract IERC20",name:"mainToken",type:"address"},{internalType:"contract IERC20",name:"wrappedToken",type:"address"},{internalType:"uint256",name:"upperTarget",type:"uint256"},{internalType:"uint256",name:"swapFeePercentage",type:"uint256"},{internalType:"uint256",name:"pauseWindowDuration",type:"uint256"},{internalType:"uint256",name:"bufferPeriodDuration",type:"uint256"},{internalType:"address",name:"owner",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"paused",type:"bool"}],name:"PausedStateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"SwapFeePercentageChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract IERC20",name:"token",type:"address"},{indexed:!1,internalType:"uint256",name:"lowerTarget",type:"uint256"},{indexed:!1,internalType:"uint256",name:"upperTarget",type:"uint256"}],name:"TargetsSet",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"getActionId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAuthorizer",outputs:[{internalType:"contract IAuthorizer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getBptIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getMainIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getMainToken",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPausedState",outputs:[{internalType:"bool",name:"paused",type:"bool"},{internalType:"uint256",name:"pauseWindowEndTime",type:"uint256"},{internalType:"uint256",name:"bufferPeriodEndTime",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPoolId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getScalingFactors",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getSwapFeePercentage",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getTargets",outputs:[{internalType:"uint256",name:"lowerTarget",type:"uint256"},{internalType:"uint256",name:"upperTarget",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVirtualSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getWrappedIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getWrappedToken",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getWrappedTokenRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onExitPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onJoinPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IERC20",name:"tokenIn",type:"address"},{internalType:"contract IERC20",name:"tokenOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IPoolSwapStructs.SwapRequest",name:"request",type:"tuple"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"indexIn",type:"uint256"},{internalType:"uint256",name:"indexOut",type:"uint256"}],name:"onSwap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryExit",outputs:[{internalType:"uint256",name:"bptIn",type:"uint256"},{internalType:"uint256[]",name:"amountsOut",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryJoin",outputs:[{internalType:"uint256",name:"bptOut",type:"uint256"},{internalType:"uint256[]",name:"amountsIn",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"},{internalType:"bytes",name:"poolConfig",type:"bytes"}],name:"setAssetManagerPoolConfig",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bool",name:"paused",type:"bool"}],name:"setPaused",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"setSwapFeePercentage",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"newLowerTarget",type:"uint256"},{internalType:"uint256",name:"newUpperTarget",type:"uint256"}],name:"setTargets",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],xs=[{inputs:[{components:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"contract IProtocolFeePercentagesProvider",name:"protocolFeeProvider",type:"address"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"},{internalType:"contract IERC20[]",name:"tokens",type:"address[]"},{internalType:"contract IRateProvider[]",name:"rateProviders",type:"address[]"},{internalType:"uint256[]",name:"tokenRateCacheDurations",type:"uint256[]"},{internalType:"bool[]",name:"exemptFromYieldProtocolFeeFlags",type:"bool[]"},{internalType:"uint256",name:"amplificationParameter",type:"uint256"},{internalType:"uint256",name:"swapFeePercentage",type:"uint256"},{internalType:"uint256",name:"pauseWindowDuration",type:"uint256"},{internalType:"uint256",name:"bufferPeriodDuration",type:"uint256"},{internalType:"address",name:"owner",type:"address"}],internalType:"struct ComposableStablePool.NewPoolParams",name:"params",type:"tuple"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"startValue",type:"uint256"},{indexed:!1,internalType:"uint256",name:"endValue",type:"uint256"},{indexed:!1,internalType:"uint256",name:"startTime",type:"uint256"},{indexed:!1,internalType:"uint256",name:"endTime",type:"uint256"}],name:"AmpUpdateStarted",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"currentValue",type:"uint256"}],name:"AmpUpdateStopped",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"paused",type:"bool"}],name:"PausedStateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"feeType",type:"uint256"},{indexed:!1,internalType:"uint256",name:"protocolFeePercentage",type:"uint256"}],name:"ProtocolFeePercentageCacheUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"enabled",type:"bool"}],name:"RecoveryModeStateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"SwapFeePercentageChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"tokenIndex",type:"uint256"},{indexed:!1,internalType:"uint256",name:"rate",type:"uint256"}],name:"TokenRateCacheUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"tokenIndex",type:"uint256"},{indexed:!0,internalType:"contract IRateProvider",name:"provider",type:"address"},{indexed:!1,internalType:"uint256",name:"cacheDuration",type:"uint256"}],name:"TokenRateProviderSet",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DELEGATE_PROTOCOL_SWAP_FEES_SENTINEL",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"disableRecoveryMode",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"enableRecoveryMode",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"getActionId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getActualSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAmplificationParameter",outputs:[{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bool",name:"isUpdating",type:"bool"},{internalType:"uint256",name:"precision",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAuthorizer",outputs:[{internalType:"contract IAuthorizer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getBptIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getDomainSeparator",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLastJoinExitData",outputs:[{internalType:"uint256",name:"lastJoinExitAmplification",type:"uint256"},{internalType:"uint256",name:"lastPostJoinExitInvariant",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getMinimumBpt",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"getNextNonce",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPausedState",outputs:[{internalType:"bool",name:"paused",type:"bool"},{internalType:"uint256",name:"pauseWindowEndTime",type:"uint256"},{internalType:"uint256",name:"bufferPeriodEndTime",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPoolId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"feeType",type:"uint256"}],name:"getProtocolFeePercentageCache",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getProtocolFeesCollector",outputs:[{internalType:"contract IProtocolFeesCollector",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getProtocolSwapFeeDelegation",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getRateProviders",outputs:[{internalType:"contract IRateProvider[]",name:"",type:"address[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getScalingFactors",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getSwapFeePercentage",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"}],name:"getTokenRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"}],name:"getTokenRateCache",outputs:[{internalType:"uint256",name:"rate",type:"uint256"},{internalType:"uint256",name:"oldRate",type:"uint256"},{internalType:"uint256",name:"duration",type:"uint256"},{internalType:"uint256",name:"expires",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"inRecoveryMode",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"}],name:"isTokenExemptFromYieldProtocolFee",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onExitPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"onJoinPool",outputs:[{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IERC20",name:"tokenIn",type:"address"},{internalType:"contract IERC20",name:"tokenOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IPoolSwapStructs.SwapRequest",name:"swapRequest",type:"tuple"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"indexIn",type:"uint256"},{internalType:"uint256",name:"indexOut",type:"uint256"}],name:"onSwap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryExit",outputs:[{internalType:"uint256",name:"bptIn",type:"uint256"},{internalType:"uint256[]",name:"amountsOut",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256[]",name:"balances",type:"uint256[]"},{internalType:"uint256",name:"lastChangeBlock",type:"uint256"},{internalType:"uint256",name:"protocolSwapFeePercentage",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],name:"queryJoin",outputs:[{internalType:"uint256",name:"bptOut",type:"uint256"},{internalType:"uint256[]",name:"amountsIn",type:"uint256[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"},{internalType:"bytes",name:"poolConfig",type:"bytes"}],name:"setAssetManagerPoolConfig",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"swapFeePercentage",type:"uint256"}],name:"setSwapFeePercentage",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"},{internalType:"uint256",name:"duration",type:"uint256"}],name:"setTokenRateCacheDuration",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"rawEndValue",type:"uint256"},{internalType:"uint256",name:"endTime",type:"uint256"}],name:"startAmplificationParameterUpdate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"stopAmplificationParameterUpdate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"updateProtocolFeePercentageCache",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"}],name:"updateTokenRateCache",outputs:[],stateMutability:"nonpayable",type:"function"}];async function As(e,t,a,n){if(0===e.length)return e;const s=Object.values(Object.fromEntries([...L.abi,...Te,...gs,...Is,...ws,...Es,...xs].map((e=>[e.name,e])))),i=new Ts(t,n,s),r=Object.values(C),o=[];e.forEach((e=>{r.includes(e.poolType)?(o.push(e),i.call(`${e.id}.poolTokens`,a,"getPoolTokens",[e.id]),i.call(`${e.id}.totalSupply`,e.address,"totalSupply"),(e.poolType.includes("Linear")||"StablePhantom"===e.poolType)&&i.call(`${e.id}.virtualSupply`,e.address,"getVirtualSupply"),"ComposableStable"===e.poolType&&i.call(`${e.id}.actualSupply`,e.address,"getActualSupply"),"Weighted"===e.poolType||"LiquidityBootstrapping"===e.poolType||"Investment"===e.poolType?(i.call(`${e.id}.weights`,e.address,"getNormalizedWeights"),i.call(`${e.id}.swapFee`,e.address,"getSwapFeePercentage")):"Stable"===e.poolType||"MetaStable"===e.poolType||"StablePhantom"===e.poolType||"ComposableStable"===e.poolType?(i.call(`${e.id}.amp`,e.address,"getAmplificationParameter"),i.call(`${e.id}.swapFee`,e.address,"getSwapFeePercentage")):"Element"===e.poolType?i.call(`${e.id}.swapFee`,e.address,"percentFee"):e.poolType.toString().includes("Linear")?(i.call(`${e.id}.swapFee`,e.address,"getSwapFeePercentage"),i.call(`${e.id}.targets`,e.address,"getTargets"),i.call(`${e.id}.rate`,e.address,"getWrappedTokenRate")):e.poolType.toString().includes("Gyro")&&i.call(`${e.id}.swapFee`,e.address,"getSwapFeePercentage")):console.error(`Unknown pool type: ${e.poolType} ${e.id}`)}));let d={};try{d=await i.execute()}catch(e){throw"Issue with multicall execution."}const c=[];return Object.entries(d).forEach((([e,t],a)=>{try{const{poolTokens:n,swapFee:s,weights:i,totalSupply:r,virtualSupply:d,actualSupply:p}=t;if("Stable"===o[a].poolType||"MetaStable"===o[a].poolType||"StablePhantom"===o[a].poolType||"ComposableStable"===o[a].poolType){if(!t.amp)return void console.error(`Stable Pool Missing Amp: ${e}`);o[a].amp=l(t.amp[0],3)}if(o[a].poolType.includes("Linear")){if(!t.targets)return void console.error(`Linear Pool Missing Targets: ${e}`);o[a].lowerTarget=l(t.targets[0],18),o[a].upperTarget=l(t.targets[1],18);const n=o[a].wrappedIndex;if(void 0===n||void 0===t.rate)return void console.error(`Linear Pool Missing WrappedIndex or PriceRate: ${e}`);o[a].tokens[n].priceRate=l(t.rate,18)}if(o[a].swapFee=l(s,18),n.tokens.forEach(((t,s)=>{const r=o[a].tokens.find((e=>Pt(e.address,t)));if(!r)throw`Pool Missing Expected Token: ${e} ${t}`;r.balance=l(n.balances[s],r.decimals),i&&(r.weight=l(i[s],18))})),o[a].poolType.includes("Linear")||"StablePhantom"===o[a].poolType){if(void 0===d)return void console.error(`Pool with pre-minted BPT missing Virtual Supply: ${e}`);o[a].totalShares=l(d,18)}else if("ComposableStable"===o[a].poolType){if(void 0===p)return void console.error(`ComposableStable missing Actual Supply: ${e}`);o[a].totalShares=l(p,18)}else o[a].totalShares=l(r,18);c.push(o[a])}catch(e){throw`Issue with pool onchain data: ${e}`}})),c}class Ss{constructor(e,t,a,n){this.client=e,this.provider=t,this.network=a,this.sorConfig=n}async getPools(){const e=function(e){return e.map((e=>({...e,poolType:e.poolType||"",tokens:(e.tokens||[]).map((e=>({...e,weight:e.weight||null}))),totalWeight:e.totalWeight||void 0,amp:e.amp||void 0,expiryTime:e.expiryTime?w(e.expiryTime):void 0,unitSeconds:e.unitSeconds?w(e.unitSeconds):void 0,principalToken:e.principalToken||void 0,baseToken:e.baseToken||void 0})))}((await this.getSubgraphPools()).filter((e=>{if(!this.network.poolsToIgnore)return!0;return-1===this.network.poolsToIgnore.findIndex((t=>Pt(t,e.address)))})));return!1===this.sorConfig.fetchOnChainBalances?e:As(e,this.network.addresses.contracts.multicall,this.network.addresses.contracts.vault,this.provider)}async getSubgraphPools(){const{pool0:e,pool1000:t,pool2000:a}=await this.client.AllPools({where:{swapEnabled:!0,totalShares_gt:"0.000000000001"},orderBy:on.TotalLiquidity,orderDirection:en.Desc});return[...e,...t,...a]}}class Ps{constructor(e){this.chainId=e}async getNativeAssetPriceInToken(e){const t=await this.getTokenPriceInNativeAsset(e);return""+1/parseFloat(t)}async getTokenPriceInNativeAsset(e){const t=`https://api.coingecko.com/api/v3/simple/token_price/${this.platformId}?contract_addresses=${e}&vs_currencies=${this.nativeAssetId}`,{data:a}=await h.get(t,{headers:{Accept:"application/json","Content-Type":"application/json"}});if(void 0===a[e.toLowerCase()][this.nativeAssetId])throw Error("No price returned from Coingecko");return a[e.toLowerCase()][this.nativeAssetId]}get platformId(){switch(this.chainId){case 1:case 42:case 248:case 16116:case 17117:return"ethereum";case 137:return"polygon-pos";case 42161:return"arbitrum-one";case 100:return"xdai"}return"3"}get nativeAssetId(){switch(this.chainId){case 1:case 42:case 42161:case 248:case 16116:case 17117:return"eth";case 137:return"";case 100:return"xdai"}return""}}class _s{constructor(e,t){this.client=e,this.weth=t.toLowerCase()}async getNativeAssetPriceInToken(e){const t=await this.getLatestPriceInEthFromSubgraph(e);if(!t)throw Error("No price found in the subgraph");return""+1/t}async getLatestPriceInEthFromSubgraph(e){e=e.toLowerCase();const{latestPrices:t}=await this.client.TokenLatestPrices({where:{asset_in:[e,this.weth]}}),a=E(t,"id");if(a[`${e}-${this.weth}`])return parseFloat(a[`${e}-${this.weth}`].price);const n=t.filter((t=>t.asset===e));for(const e of n){const t=a[`${e.pricingAsset}-${this.weth}`];if(t)return parseFloat(e.price)*parseFloat(t.price)}return null}}function vs(e){var t,a;if("number"==typeof e.network){const a=Lt[e.network];return{...a,urls:{...a.urls,subgraph:null!==(t=e.customSubgraphUrl)&&void 0!==t?t:a.urls.subgraph},tenderly:e.tenderly}}return{...e.network,urls:{...e.network.urls,subgraph:null!==(a=e.customSubgraphUrl)&&void 0!==a?a:e.network.urls.subgraph},tenderly:e.network.tenderly}}class Os extends F{constructor(e){const t=vs(e),a=Os.getSorConfig(e),n=Os.getSorNetworkConfig(t),s=new q(e.rpcUrl,e.network),i=bs(t.urls.subgraph);super(s,n,Os.getPoolDataService(t,a,s,i),Os.getTokenPriceService(t,a,i))}static getSorConfig(e){return{tokenPriceService:"coingecko",poolDataService:"subgraph",fetchOnChainBalances:!0,...e.sor}}static getSorNetworkConfig(e){var t;return{...e,vault:e.addresses.contracts.vault,weth:e.addresses.tokens.wrappedNativeAsset,lbpRaisingTokens:null===(t=e.addresses.tokens)||void 0===t?void 0:t.lbpRaisingTokens,wETHwstETH:e.pools.wETHwstETH,connectingTokens:e.sorConnectingTokens}}static getPoolDataService(e,t,a,n){return"object"==typeof t.poolDataService?t.poolDataService:new Ss(n,a,e,t)}static getTokenPriceService(e,t,a){return"object"==typeof t.tokenPriceService?t.tokenPriceService:("subgraph"===t.tokenPriceService&&new _s(a,e.addresses.tokens.wrappedNativeAsset),new Ps(e.chainId))}}function Bs(e){if(e.poolIds.length>2)throw new Error("Simple flash swap only supports a maximum of two pools");if(e.assets.length>2)throw new Error("Simple flash swap only supports a maximum of to two assets (tokens)")}function ks(e,t){return[{poolId:e[0],assetInIndex:0,assetOutIndex:1,amount:t,userData:"0x"},{poolId:e[1],assetInIndex:1,assetOutIndex:0,amount:"0",userData:"0x"}]}function Ds(e){return-1*Number(e)}function Ns(e){return x(e)}var Cs=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"contract IERC20",name:"wstETH",type:"address"},{internalType:"contract IBalancerMinter",name:"minter",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[{internalType:"contract IERC20",name:"token",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approveVault",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{components:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"uint256",name:"assetInIndex",type:"uint256"},{internalType:"uint256",name:"assetOutIndex",type:"uint256"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IVault.BatchSwapStep[]",name:"swaps",type:"tuple[]"},{internalType:"contract IAsset[]",name:"assets",type:"address[]"},{components:[{internalType:"address",name:"sender",type:"address"},{internalType:"bool",name:"fromInternalBalance",type:"bool"},{internalType:"address payable",name:"recipient",type:"address"},{internalType:"bool",name:"toInternalBalance",type:"bool"}],internalType:"struct IVault.FundManagement",name:"funds",type:"tuple"},{internalType:"int256[]",name:"limits",type:"int256[]"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{components:[{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"key",type:"uint256"}],internalType:"struct VaultActions.OutputReference[]",name:"outputReferences",type:"tuple[]"}],name:"batchSwap",outputs:[{internalType:"int256[]",name:"",type:"int256[]"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"enum VaultActions.PoolKind",name:"kind",type:"uint8"},{internalType:"address",name:"sender",type:"address"},{internalType:"address payable",name:"recipient",type:"address"},{components:[{internalType:"contract IAsset[]",name:"assets",type:"address[]"},{internalType:"uint256[]",name:"minAmountsOut",type:"uint256[]"},{internalType:"bytes",name:"userData",type:"bytes"},{internalType:"bool",name:"toInternalBalance",type:"bool"}],internalType:"struct IVault.ExitPoolRequest",name:"request",type:"tuple"},{components:[{internalType:"uint256",name:"index",type:"uint256"},{internalType:"uint256",name:"key",type:"uint256"}],internalType:"struct VaultActions.OutputReference[]",name:"outputReferences",type:"tuple[]"}],name:"exitPool",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IStakingLiquidityGauge[]",name:"gauges",type:"address[]"}],name:"gaugeClaimRewards",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IStakingLiquidityGauge",name:"gauge",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"gaugeDeposit",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address[]",name:"gauges",type:"address[]"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"gaugeMint",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"bool",name:"approval",type:"bool"},{internalType:"address",name:"user",type:"address"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"gaugeSetMinterApproval",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IStakingLiquidityGauge",name:"gauge",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"gaugeWithdraw",outputs:[],stateMutability:"payable",type:"function"},{inputs:[],name:"getEntrypoint",outputs:[{internalType:"contract IBalancerRelayer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"enum VaultActions.PoolKind",name:"kind",type:"uint8"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{components:[{internalType:"contract IAsset[]",name:"assets",type:"address[]"},{internalType:"uint256[]",name:"maxAmountsIn",type:"uint256[]"},{internalType:"bytes",name:"userData",type:"bytes"},{internalType:"bool",name:"fromInternalBalance",type:"bool"}],internalType:"struct IVault.JoinPoolRequest",name:"request",type:"tuple"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"joinPool",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{components:[{internalType:"enum IVault.UserBalanceOpKind",name:"kind",type:"uint8"},{internalType:"contract IAsset",name:"asset",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"address",name:"sender",type:"address"},{internalType:"address payable",name:"recipient",type:"address"}],internalType:"struct IVault.UserBalanceOp[]",name:"ops",type:"tuple[]"},{internalType:"uint256",name:"value",type:"uint256"}],name:"manageUserBalance",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"uint256",name:"ref",type:"uint256"}],name:"peekChainedReferenceValue",outputs:[{internalType:"uint256",name:"value",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"relayer",type:"address"},{internalType:"bool",name:"approved",type:"bool"},{internalType:"bytes",name:"authorisation",type:"bytes"}],name:"setRelayerApproval",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"stakeETH",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"stakeETHAndWrap",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{components:[{internalType:"bytes32",name:"poolId",type:"bytes32"},{internalType:"enum IVault.SwapKind",name:"kind",type:"uint8"},{internalType:"contract IAsset",name:"assetIn",type:"address"},{internalType:"contract IAsset",name:"assetOut",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bytes",name:"userData",type:"bytes"}],internalType:"struct IVault.SingleSwap",name:"singleSwap",type:"tuple"},{components:[{internalType:"address",name:"sender",type:"address"},{internalType:"bool",name:"fromInternalBalance",type:"bool"},{internalType:"address payable",name:"recipient",type:"address"},{internalType:"bool",name:"toInternalBalance",type:"bool"}],internalType:"struct IVault.FundManagement",name:"funds",type:"tuple"},{internalType:"uint256",name:"limit",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"swap",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IStaticATokenLM",name:"staticToken",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bool",name:"toUnderlying",type:"bool"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"unwrapAaveStaticToken",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC4626",name:"wrappedToken",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"unwrapERC4626",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IUnbuttonToken",name:"wrapperToken",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"unwrapUnbuttonToken",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"unwrapWstETH",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC20Permit",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"vaultPermit",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC20PermitDAI",name:"token",type:"address"},{internalType:"address",name:"holder",type:"address"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"expiry",type:"uint256"},{internalType:"bool",name:"allowed",type:"bool"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"vaultPermitDAI",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IStaticATokenLM",name:"staticToken",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"bool",name:"fromUnderlying",type:"bool"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"wrapAaveDynamicToken",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC4626",name:"wrappedToken",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"wrapERC4626",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"wrapStETH",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IUnbuttonToken",name:"wrapperToken",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"uAmount",type:"uint256"},{internalType:"uint256",name:"outputReference",type:"uint256"}],name:"wrapUnbuttonToken",outputs:[],stateMutability:"payable",type:"function"}];const Fs={"0xae7ab96520de3a18e5e111b5eaab095312d7fe84":"0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0","0xd46ba6d942050d489dbd938a2c909a5d5039a161":"0xedb171c18ce90b633db442f2a6f72874093b49ef","0x1e6bb68acec8fefbd87d192be09bb274170a0548":"0xF03387d8d0FF326ab586A58E0ab4121d106147DF"};function Rs(e){let t=e;return Fs.hasOwnProperty(e)&&(t=Fs[e]),t}var Ms;function Ls(e,t,a){const{tokens:n,contracts:s}=Ut(a);let i={id:Ms.vault,address:s.vault};return n.stETH&&s.lidoRelayer&&[e,t].includes(n.stETH)&&(i={id:Ms.lido,address:s.lidoRelayer}),i}function Us(e){let t=L.abi;e.id===Ms.lido&&(t=Cs);return t.filter((e=>e.name&&["swap","batchSwap"].includes(e.name)))}function Gs(e){return{amount:e,max:t=>e.mul(1e3+t).div(1e3),min:t=>e.mul(1e3-t).div(1e3)}}function $s(e,t){const a=t===kt.SwapExactIn?e.swapAmount:e.returnAmount,n=t===kt.SwapExactIn?e.returnAmount:e.swapAmount,s=t===kt.SwapExactIn?e.swapAmountForSwaps||e.swapAmount:e.returnAmountFromSwaps||e.returnAmount,i=t===kt.SwapExactIn?e.returnAmountFromSwaps||e.returnAmount:e.swapAmountForSwaps||e.swapAmount,r=Rs(e.tokenIn),o=Rs(e.tokenOut);return{...e,amountIn:a,amountOut:n,amountInForLimits:Gs(s),amountOutForLimits:Gs(i),tokenInForSwaps:r,tokenOutFromSwaps:o}}!function(e){e[e.vault=1]="vault",e[e.lido=2]="lido"}(Ms||(Ms={}));class qs{constructor(e,t,a){this.kind=t,this.chainId=a,this.functionName="swap",this.swapInfo=$s(e,t),this.relayer=Ls(this.swapInfo.tokenIn,this.swapInfo.tokenOut,this.chainId)}setFunds(e,t){this.funds={sender:e,recipient:t||e,fromInternalBalance:!1,toInternalBalance:!1}}setDeadline(e){this.deadline=e.toString()}get amount(){return this.kind===kt.SwapExactOut?this.swapInfo.amountOutForLimits.amount:this.swapInfo.amountInForLimits.amount}setLimits(e){this.limit=this.kind===kt.SwapExactIn?this.swapInfo.amountOutForLimits.min(e).toString():this.swapInfo.amountInForLimits.max(e).toString()}get singleSwap(){return{poolId:this.swapInfo.swaps[0].poolId,kind:this.kind,assetIn:this.swapInfo.tokenInForSwaps,assetOut:this.swapInfo.tokenOutFromSwaps,amount:this.amount.toString(),userData:"0x"}}attributes(){var e;if(!this.funds||!this.limit||!this.deadline)throw new Error("Uninitialized arguments");let t={request:this.singleSwap,funds:this.funds,limit:this.limit,deadline:this.deadline};const a=this.fragment();return a[0].inputs&&(null===(e=a[0].inputs)||void 0===e?void 0:e.length)>4&&(t={...t,value:"0",outputReference:"0"}),t}data(){return new t(this.fragment()).encodeFunctionData("swap",Object.values(this.attributes()))}value(e){let t=d.from(0);return this.swapInfo.tokenIn===i&&(t=this.kind===kt.SwapExactIn?this.swapInfo.amountIn:this.swapInfo.amountInForLimits.max(e)),t}to(){return this.relayer.address}fragment(){return Us(this.relayer).filter((e=>e.name===this.functionName))}}class Ws{constructor(e,t,a){this.kind=t,this.chainId=a,this.functionName="batchSwap",this.swapInfo=$s(e,t),this.relayer=Ls(this.swapInfo.tokenIn,this.swapInfo.tokenOut,this.chainId)}setFunds(e,t){this.funds={sender:e,recipient:t||e,fromInternalBalance:!1,toInternalBalance:!1}}setDeadline(e){this.deadline=e}minAmountOut(e){return this.kind===kt.SwapExactIn?this.swapInfo.amountOutForLimits.min(e):this.swapInfo.amountOutForLimits.amount}maxAmountIn(e){return this.kind===kt.SwapExactOut?this.swapInfo.amountInForLimits.max(e):this.swapInfo.amountInForLimits.amount}setLimits(e){this.limits=this.swapInfo.tokenAddresses.map((t=>{let a=d.from(0);return t===this.swapInfo.tokenInForSwaps&&(a=this.maxAmountIn(e)),t===this.swapInfo.tokenOutFromSwaps&&(a=this.minAmountOut(e).mul(-1)),a})).map((e=>e.toString().split(".")[0]))}attributes(){var e;if(!this.funds||!this.limits||!this.deadline)throw new Error("Uninitialized arguments");let t={kind:this.kind,swaps:this.swapInfo.swaps,assets:this.swapInfo.tokenAddresses,funds:this.funds,limits:this.limits,deadline:this.deadline};const a=this.fragment();return a[0].inputs&&(null===(e=a[0].inputs)||void 0===e?void 0:e.length)>6&&(t={...t,value:"0",outputReferences:[]}),t}data(){return new t(this.fragment()).encodeFunctionData("batchSwap",Object.values(this.attributes()))}value(e){let t=d.from(0);return this.swapInfo.tokenIn===i&&(t=this.maxAmountIn(e)),t}to(){return this.relayer.address}fragment(){return Us(this.relayer).filter((e=>e.name===this.functionName))}}class Vs{constructor(e){e instanceof F?(this.sor=e,this.chainId=this.sor.provider._network.chainId):(this.sor=new Os(e),this.chainId=e.network),this.vaultContract=L.connect(Mt,this.sor.provider)}static getLimitsForSlippage(e,t,a,n,s,i){return Dt(e,t,a,n,s,i).map((e=>e.toString()))}async findRouteGivenIn({tokenIn:e,tokenOut:t,amount:a,gasPrice:n,maxPools:s=4}){return this.sor.getSwaps(e,t,N.SwapExactIn,a,{gasPrice:n,maxPools:s})}async findRouteGivenOut({tokenIn:e,tokenOut:t,amount:a,gasPrice:n,maxPools:s}){return this.sor.getSwaps(e,t,N.SwapExactOut,a,{gasPrice:n,maxPools:s})}buildSwap({userAddress:e,recipient:t,swapInfo:a,kind:n,deadline:s,maxSlippage:i}){if(!this.chainId)throw"Missing network configuration";const r=a.swaps.length>1?new Ws(a,n,this.chainId):new qs(a,n,this.chainId);r.setFunds(e,t),r.setDeadline(s),r.setLimits(i);const o=r.to(),{functionName:d}=r;return{to:o,functionName:d,attributes:r.attributes(),data:r.data(),value:r.value(i)}}static encodeBatchSwap(e){return L.createInterface().encodeFunctionData("batchSwap",[e.kind,e.swaps,e.assets,e.funds,e.limits,e.deadline])}static encodeSimpleFlashSwap(e){return this.encodeBatchSwap(function({poolIds:e,assets:t,flashLoanAmount:a,walletAddress:n}){Bs({poolIds:e,assets:t});const s=ks(e,a),i={sender:n,fromInternalBalance:!1,recipient:n,toInternalBalance:!1};return{kind:kt.SwapExactIn,swaps:s,assets:t,funds:i,limits:["0","0"],deadline:"999999999999999999"}}(e))}async fetchPools(){return this.sor.fetchPools()}getPools(){return this.sor.getPools()}async queryBatchSwap(e){return await _a(this.vaultContract,e.kind,e.swaps,e.assets)}async queryBatchSwapWithSor(e){return await va(this.sor,this.vaultContract,e)}async querySimpleFlashSwap(e){return await async function(e){Bs(e);const[t,a]=e.assets;try{const n=await _a(e.vaultContract,kt.SwapExactIn,ks(e.poolIds,e.flashLoanAmount),e.assets),s={[t]:Ds(n[0]).toString(),[a]:Ds(n[1]).toString()};return{profits:s,isProfitable:Ns([s[t],s[a]])>0}}catch(e){throw`Failed to querySimpleFlashSwap: ${e}`}}({...e,vaultContract:this.vaultContract})}async getSorSwap(e){return await Oa(e.tokenIn,e.tokenOut,e.swapType,e.amount,this.sor)}}const Hs=new t(Cs);class js{constructor(e){this.swaps=e instanceof Vs?e:new Vs(e)}static isChainedReference(e){const t=d.from(e),a=d.from("0xfff0000000000000000000000000000000000000000000000000000000000000"),n=t.toBigInt()&a.toBigInt();return"0xba10000000000000000000000000000000000000000000000000000000000000"===d.from(n)._hex.toString()}static encodeApproveVault(e,t){return Hs.encodeFunctionData("approveVault",[e,t])}static encodeSetRelayerApproval(e,t,a){return Hs.encodeFunctionData("setRelayerApproval",[e,t,a])}static encodeGaugeWithdraw(e,t,a,n){return Hs.encodeFunctionData("gaugeWithdraw",[e,t,a,n])}static encodeGaugeDeposit(e,t,a,n){return Hs.encodeFunctionData("gaugeDeposit",[e,t,a,n])}static encodeBatchSwap(e){return Hs.encodeFunctionData("batchSwap",[e.swapType,e.swaps,e.assets,e.funds,e.limits,e.deadline,e.value,e.outputReferences])}static encodeExitPool(e){return Hs.encodeFunctionData("exitPool",[e.poolId,e.poolKind,e.sender,e.recipient,e.exitPoolRequest,e.outputReferences])}static encodeJoinPool(e){return Hs.encodeFunctionData("joinPool",[e.poolId,e.kind,e.sender,e.recipient,e.joinPoolRequest,e.value,e.outputReference])}static encodeWrapAaveDynamicToken(e){return Hs.encodeFunctionData("wrapAaveDynamicToken",[e.staticToken,e.sender,e.recipient,e.amount,e.fromUnderlying,e.outputReference])}static encodeUnwrapAaveStaticToken(e){return Hs.encodeFunctionData("unwrapAaveStaticToken",[e.staticToken,e.sender,e.recipient,e.amount,e.toUnderlying,e.outputReferences])}static encodePeekChainedReferenceValue(e){return Hs.encodeFunctionData("peekChainedReferenceValue",[e])}static toChainedReference(e,t=!0){const a=t?js.CHAINED_REFERENCE_TEMP_PREFIX:js.CHAINED_REFERENCE_READONLY_PREFIX,n=`0x${a}${"0".repeat(64-a.length)}`;return d.from(n).add(e)}static fromChainedReference(e,t=!0){const a=t?js.CHAINED_REFERENCE_TEMP_PREFIX:js.CHAINED_REFERENCE_READONLY_PREFIX,n=`0x${a}${"0".repeat(64-a.length)}`;return d.from(e).sub(d.from(n))}static constructExitCall(e){const{assets:t,minAmountsOut:a,userData:n,toInternalBalance:s,poolId:i,poolKind:r,sender:o,recipient:d,outputReferences:c}=e,l={poolId:i,poolKind:r,sender:o,recipient:d,outputReferences:c,exitPoolRequest:{assets:t,minAmountsOut:a,userData:n,toInternalBalance:s}};return js.encodeExitPool(l)}static constructJoinCall(e){const{assets:t,maxAmountsIn:a,userData:n,fromInternalBalance:s,poolId:i,kind:r,sender:o,recipient:d,value:c,outputReference:l}=e,p={poolId:i,kind:r,sender:o,recipient:d,value:c,outputReference:l,joinPoolRequest:{assets:t,maxAmountsIn:a,userData:n,fromInternalBalance:s}};return js.encodeJoinPool(p)}async fetchPools(){return this.swaps.fetchPools()}getPools(){return this.swaps.getPools()}async exitPoolAndBatchSwap(e){const t=n.sub(d.from(e.slippage)),a=e.expectedAmountsOut.map((e=>d.from(e).mul(t).div(n).toString())),s=[];e.exitTokens.forEach(((e,t)=>{const a=js.toChainedReference(t);s.push({index:t,key:a})}));const i=js.constructExitCall({assets:e.exitTokens,minAmountsOut:a,userData:e.userData,toInternalBalance:!0,poolId:e.poolId,poolKind:0,sender:e.exiter,recipient:e.exiter,outputReferences:s,exitPoolRequest:{}}),o=await this.swaps.queryBatchSwapWithSor({tokensIn:e.exitTokens,tokensOut:e.finalTokensOut,swapType:kt.SwapExactIn,amounts:a,fetchPools:e.fetchPools});if(o.returnAmounts.includes("0"))throw new $t(Gt.SWAP_ZERO_RETURN_AMOUNT);o.swaps.forEach((t=>{const a=o.assets[t.assetInIndex],n=e.exitTokens.indexOf(a);-1!==n&&(t.amount=s[n].key.toString())}));const c=n.add(e.slippage);e.exitTokens.forEach(((t,a)=>{const s=o.assets.map((e=>e.toLowerCase())).indexOf(t.toLowerCase());-1!==s&&(o.deltas[s]=d.from(e.expectedAmountsOut[a]).mul(c).div(n).toString())}));const l=Vs.getLimitsForSlippage(e.exitTokens,e.finalTokensOut,kt.SwapExactIn,o.deltas,o.assets,"0"),p={sender:e.exiter,recipient:e.swapRecipient,fromInternalBalance:!0,toInternalBalance:!1};return{function:"multicall",params:[i,js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:o.swaps,assets:o.assets,funds:p,limits:l.map((e=>e.toString())),deadline:r,value:"0",outputReferences:[]})],outputs:{amountsOut:o.returnAmounts}}}async swapUnwrapAaveStaticExactIn(e,t,a,i,r,o,c={fetchPools:!0,fetchOnChain:!1}){const l=await this.swaps.queryBatchSwapWithSor({tokensIn:e,tokensOut:t,swapType:kt.SwapExactIn,amounts:a,fetchPools:c});if(l.returnAmounts.includes("0"))throw new $t(Gt.SWAP_ZERO_RETURN_AMOUNT);const p=Vs.getLimitsForSlippage(e,t,kt.SwapExactIn,l.deltas,l.assets,o);return{function:"multicall",params:this.encodeSwapUnwrap(t,kt.SwapExactIn,l.swaps,l.assets,r,p),outputs:{amountsOut:l.returnAmounts.map(((e,t)=>{const a=d.from(e).abs().mul(i[t]).div(n);if(!a.gt(s))throw new $t(Gt.UNWRAP_ZERO_AMOUNT);return a.toString()}))}}}async swapUnwrapAaveStaticExactOut(e,t,a,i,r,o,c={fetchPools:!0,fetchOnChain:!1}){const l=a.map(((e,t)=>{const a=d.from(e).mul(n).div(i[t]);if(!a.gt(s))throw new $t(Gt.WRAP_ZERO_AMOUNT);return a.toString()})),p=await this.swaps.queryBatchSwapWithSor({tokensIn:e,tokensOut:t,swapType:kt.SwapExactOut,amounts:l,fetchPools:c});if(p.returnAmounts.includes("0"))throw new $t(Gt.SWAP_ZERO_RETURN_AMOUNT);const u=Vs.getLimitsForSlippage(e,t,kt.SwapExactOut,p.deltas,p.assets,o);return{function:"multicall",params:this.encodeSwapUnwrap(t,kt.SwapExactOut,p.swaps,p.assets,r,u),outputs:{amountsIn:p.returnAmounts.map((e=>e.toString()))}}}encodeSwapUnwrap(e,t,a,n,s,i){const o=[],d=[];e.forEach(((e,t)=>{const a=n.findIndex((t=>t.toLowerCase()===e.toLowerCase()));if(-1===a)return;const i=js.toChainedReference(t);o.push({index:a,key:i});const r=js.encodeUnwrapAaveStaticToken({staticToken:e,sender:s.recipient,recipient:s.sender,amount:i,toUnderlying:!0,outputReferences:0});d.push(r)}));return[js.encodeBatchSwap({swapType:t,swaps:a,assets:n,funds:s,limits:i.map((e=>e.toString())),deadline:r,value:"0",outputReferences:o}),...d]}}js.CHAINED_REFERENCE_TEMP_PREFIX="ba10",js.CHAINED_REFERENCE_READONLY_PREFIX="ba11",js.signRelayerApproval=async(e,t,a,n)=>{const s=n.interface.encodeFunctionData("setRelayerApproval",[t,e,!0]),i=await Pe.signSetRelayerApprovalAuthorization(n,a,e,s);return Pe.encodeCalldataAuthorization("0x",r,i)};class Xs{constructor(e){this.url=vs(e).urls.subgraph,this.client=this.initClient()}initClient(){return Wn(new W(this.url))}}class Ks{constructor(e,t){this.swaps=t||new Vs(e)}async fetchPools(){return this.swaps.fetchPools()}getPools(){return this.swaps.getPools()}async getSpotPrice(e,t,a=[]){0===a.length&&(await this.fetchPools(),a=this.getPools());const n=R(a,0),s=this.swaps.sor.routeProposer.getCandidatePathsFromDict(e,t,0,n,4);if(0===s.length)throw new $t(Gt.UNSUPPORTED_PAIR);return M(s[0],0,P).toString()}}var Ys=[{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"}];function Js(e){return Math.round(Date.now()/1e3)-e<86400}var Zs=[{name:"Deposit",inputs:[{name:"provider",type:"address",indexed:!0},{name:"value",type:"uint256",indexed:!1},{name:"locktime",type:"uint256",indexed:!0},{name:"type",type:"int128",indexed:!1},{name:"ts",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{name:"Withdraw",inputs:[{name:"provider",type:"address",indexed:!0},{name:"value",type:"uint256",indexed:!1},{name:"ts",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{name:"Supply",inputs:[{name:"prevSupply",type:"uint256",indexed:!1},{name:"supply",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{stateMutability:"nonpayable",type:"constructor",inputs:[{name:"token_addr",type:"address"},{name:"_name",type:"string"},{name:"_symbol",type:"string"},{name:"_authorizer_adaptor",type:"address"}],outputs:[]},{stateMutability:"view",type:"function",name:"token",inputs:[],outputs:[{name:"",type:"address"}]},{stateMutability:"view",type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string"}]},{stateMutability:"view",type:"function",name:"symbol",inputs:[],outputs:[{name:"",type:"string"}]},{stateMutability:"view",type:"function",name:"decimals",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"admin",inputs:[],outputs:[{name:"",type:"address"}]},{stateMutability:"nonpayable",type:"function",name:"commit_smart_wallet_checker",inputs:[{name:"addr",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"apply_smart_wallet_checker",inputs:[],outputs:[]},{stateMutability:"view",type:"function",name:"get_last_user_slope",inputs:[{name:"addr",type:"address"}],outputs:[{name:"",type:"int128"}]},{stateMutability:"view",type:"function",name:"user_point_history__ts",inputs:[{name:"_addr",type:"address"},{name:"_idx",type:"uint256"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"locked__end",inputs:[{name:"_addr",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"nonpayable",type:"function",name:"checkpoint",inputs:[],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"deposit_for",inputs:[{name:"_addr",type:"address"},{name:"_value",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"create_lock",inputs:[{name:"_value",type:"uint256"},{name:"_unlock_time",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"increase_amount",inputs:[{name:"_value",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"increase_unlock_time",inputs:[{name:"_unlock_time",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"withdraw",inputs:[],outputs:[]},{stateMutability:"view",type:"function",name:"balanceOf",inputs:[{name:"addr",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"balanceOf",inputs:[{name:"addr",type:"address"},{name:"_t",type:"uint256"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"balanceOfAt",inputs:[{name:"addr",type:"address"},{name:"_block",type:"uint256"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"totalSupply",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"totalSupply",inputs:[{name:"t",type:"uint256"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"totalSupplyAt",inputs:[{name:"_block",type:"uint256"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"supply",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"locked",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"tuple",components:[{name:"amount",type:"int128"},{name:"end",type:"uint256"}]}]},{stateMutability:"view",type:"function",name:"epoch",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"point_history",inputs:[{name:"arg0",type:"uint256"}],outputs:[{name:"",type:"tuple",components:[{name:"bias",type:"int128"},{name:"slope",type:"int128"},{name:"ts",type:"uint256"},{name:"blk",type:"uint256"}]}]},{stateMutability:"view",type:"function",name:"user_point_history",inputs:[{name:"arg0",type:"address"},{name:"arg1",type:"uint256"}],outputs:[{name:"",type:"tuple",components:[{name:"bias",type:"int128"},{name:"slope",type:"int128"},{name:"ts",type:"uint256"},{name:"blk",type:"uint256"}]}]},{stateMutability:"view",type:"function",name:"user_point_epoch",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"slope_changes",inputs:[{name:"arg0",type:"uint256"}],outputs:[{name:"",type:"int128"}]},{stateMutability:"view",type:"function",name:"future_smart_wallet_checker",inputs:[],outputs:[{name:"",type:"address"}]},{stateMutability:"view",type:"function",name:"smart_wallet_checker",inputs:[],outputs:[{name:"",type:"address"}]}];class zs{constructor(e,t){this.addresses=e,this.provider=t}async getLockInfo(e){if(!this.addresses.veBal)throw new Error("veBal address must be defined");const t=new Ts(this.addresses.multicall,this.provider,Zs);t.call("locked",this.addresses.veBal,"locked",[e]),t.call("epoch",this.addresses.veBal,"epoch"),t.call("totalSupply",this.addresses.veBal,"totalSupply()");const a=await t.execute();return this.formatLockInfo(a)}formatLockInfo(e){const[t,a]=e.locked,n=t.gt(0),s=1e3*a.toNumber();const i=n&&Date.now()>s;return{lockedEndDate:s,lockedAmount:rt(t),totalSupply:rt(e.totalSupply),epoch:rt(e.epoch,0),hasExistingLock:n,isExpired:i}}}var Qs=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"contract IERC20",name:"votingEscrow",type:"address"},{internalType:"contract IVeDelegation",name:"delegation",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"newImplementation",type:"address"}],name:"DelegationImplementationUpdated",type:"event"},{inputs:[{internalType:"address",name:"user",type:"address"}],name:"adjustedBalanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"user",type:"address"}],name:"adjusted_balance_of",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"getActionId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAuthorizer",outputs:[{internalType:"contract IAuthorizer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getDelegationImplementation",outputs:[{internalType:"contract IVeDelegation",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVotingEscrow",outputs:[{internalType:"contract IERC20",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"killDelegation",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract IVeDelegation",name:"delegation",type:"address"}],name:"setDelegation",outputs:[],stateMutability:"nonpayable",type:"function"}];class ei{constructor(e,t){if(!e.veBalProxy)throw new Error("veBalProxy address must be defined");this.instance=new u(e.veBalProxy,Qs,t)}async getAdjustedBalance(e){return rt(await this.instance.adjustedBalanceOf(e))}}var ti=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"address",name:"libraryAddress",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"getLibrary",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes[]",name:"data",type:"bytes[]"}],name:"multicall",outputs:[{internalType:"bytes[]",name:"results",type:"bytes[]"}],stateMutability:"payable",type:"function"},{stateMutability:"payable",type:"receive"}],ai=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"address",name:"libraryAddress",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"getLibrary",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes[]",name:"data",type:"bytes[]"}],name:"multicall",outputs:[{internalType:"bytes[]",name:"results",type:"bytes[]"}],stateMutability:"payable",type:"function"},{stateMutability:"payable",type:"receive"}];const ni=(e,t,a)=>{switch(a){case 3:return new u(e,ai,t);case 4:return new u(e,ti,t);default:throw new Error("relayer not supported")}};var si=[{name:"Deposit",inputs:[{name:"provider",type:"address",indexed:!0},{name:"value",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{name:"Withdraw",inputs:[{name:"provider",type:"address",indexed:!0},{name:"value",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{name:"UpdateLiquidityLimit",inputs:[{name:"user",type:"address",indexed:!0},{name:"original_balance",type:"uint256",indexed:!1},{name:"original_supply",type:"uint256",indexed:!1},{name:"working_balance",type:"uint256",indexed:!1},{name:"working_supply",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{name:"Transfer",inputs:[{name:"_from",type:"address",indexed:!0},{name:"_to",type:"address",indexed:!0},{name:"_value",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{name:"Approval",inputs:[{name:"_owner",type:"address",indexed:!0},{name:"_spender",type:"address",indexed:!0},{name:"_value",type:"uint256",indexed:!1}],anonymous:!1,type:"event"},{stateMutability:"nonpayable",type:"constructor",inputs:[{name:"minter",type:"address"},{name:"veBoostProxy",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"deposit",inputs:[{name:"_value",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"deposit",inputs:[{name:"_value",type:"uint256"},{name:"_addr",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"deposit",inputs:[{name:"_value",type:"uint256"},{name:"_addr",type:"address"},{name:"_claim_rewards",type:"bool"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"withdraw",inputs:[{name:"_value",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"withdraw",inputs:[{name:"_value",type:"uint256"},{name:"_claim_rewards",type:"bool"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"claim_rewards",inputs:[],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"claim_rewards",inputs:[{name:"_addr",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"claim_rewards",inputs:[{name:"_addr",type:"address"},{name:"_receiver",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"transferFrom",inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"transfer",inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"approve",inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"permit",inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"},{name:"_value",type:"uint256"},{name:"_deadline",type:"uint256"},{name:"_v",type:"uint8"},{name:"_r",type:"bytes32"},{name:"_s",type:"bytes32"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"increaseAllowance",inputs:[{name:"_spender",type:"address"},{name:"_added_value",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"decreaseAllowance",inputs:[{name:"_spender",type:"address"},{name:"_subtracted_value",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"user_checkpoint",inputs:[{name:"addr",type:"address"}],outputs:[{name:"",type:"bool"}]},{stateMutability:"nonpayable",type:"function",name:"set_rewards_receiver",inputs:[{name:"_receiver",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"kick",inputs:[{name:"addr",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"deposit_reward_token",inputs:[{name:"_reward_token",type:"address"},{name:"_amount",type:"uint256"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"add_reward",inputs:[{name:"_reward_token",type:"address"},{name:"_distributor",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"set_reward_distributor",inputs:[{name:"_reward_token",type:"address"},{name:"_distributor",type:"address"}],outputs:[]},{stateMutability:"nonpayable",type:"function",name:"set_killed",inputs:[{name:"_is_killed",type:"bool"}],outputs:[]},{stateMutability:"view",type:"function",name:"claimed_reward",inputs:[{name:"_addr",type:"address"},{name:"_token",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"claimable_reward",inputs:[{name:"_user",type:"address"},{name:"_reward_token",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"claimable_reward_write",inputs:[{name:"_addr",type:"address"},{name:"_token",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"claimable_tokens",inputs:[{name:"addr",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"integrate_checkpoint",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"future_epoch_time",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"inflation_rate",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"decimals",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"version",inputs:[],outputs:[{name:"",type:"string"}]},{stateMutability:"view",type:"function",name:"allowance",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"nonpayable",type:"function",name:"initialize",inputs:[{name:"_lp_token",type:"address"}],outputs:[]},{stateMutability:"view",type:"function",name:"balanceOf",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"totalSupply",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string"}]},{stateMutability:"view",type:"function",name:"symbol",inputs:[],outputs:[{name:"",type:"string"}]},{stateMutability:"view",type:"function",name:"DOMAIN_SEPARATOR",inputs:[],outputs:[{name:"",type:"bytes32"}]},{stateMutability:"view",type:"function",name:"nonces",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"factory",inputs:[],outputs:[{name:"",type:"address"}]},{stateMutability:"view",type:"function",name:"lp_token",inputs:[],outputs:[{name:"",type:"address"}]},{stateMutability:"view",type:"function",name:"is_killed",inputs:[],outputs:[{name:"",type:"bool"}]},{stateMutability:"view",type:"function",name:"reward_count",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"reward_data",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"tuple",components:[{name:"token",type:"address"},{name:"distributor",type:"address"},{name:"period_finish",type:"uint256"},{name:"rate",type:"uint256"},{name:"last_update",type:"uint256"},{name:"integral",type:"uint256"}]}]},{stateMutability:"view",type:"function",name:"rewards_receiver",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"address"}]},{stateMutability:"view",type:"function",name:"reward_integral_for",inputs:[{name:"arg0",type:"address"},{name:"arg1",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"working_balances",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"working_supply",inputs:[],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"integrate_inv_supply_of",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"integrate_checkpoint_of",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"integrate_fraction",inputs:[{name:"arg0",type:"address"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"period",inputs:[],outputs:[{name:"",type:"int128"}]},{stateMutability:"view",type:"function",name:"reward_tokens",inputs:[{name:"arg0",type:"uint256"}],outputs:[{name:"",type:"address"}]},{stateMutability:"view",type:"function",name:"period_timestamp",inputs:[{name:"arg0",type:"uint256"}],outputs:[{name:"",type:"uint256"}]},{stateMutability:"view",type:"function",name:"integrate_inv_supply",inputs:[{name:"arg0",type:"uint256"}],outputs:[{name:"",type:"uint256"}]}];class ii{constructor(e,t){this.contractAddresses="number"==typeof e?Lt[e].addresses.contracts:e,this.vault=L.connect(this.contractAddresses.vault,t),this.balancerHelpers=U.connect(this.contractAddresses.balancerHelpers,t),this.contractAddresses.lidoRelayer&&(this.lidoRelayer=G.connect(this.contractAddresses.lidoRelayer,t)),this.multicall=hs(this.contractAddresses.multicall,t),this.contractAddresses.relayerV3&&(this.relayerV3=ni(this.contractAddresses.relayerV3,t,3)),this.contractAddresses.relayerV4&&(this.relayerV4=ni(this.contractAddresses.relayerV4,t,4)),this.contractAddresses.veBal&&(this.veBal=new zs(this.contractAddresses,t)),this.contractAddresses.veBalProxy&&(this.veBalProxy=new ei(this.contractAddresses,t))}get contracts(){return{vault:this.vault,balancerHelpers:this.balancerHelpers,lidoRelayer:this.lidoRelayer,multicall:this.multicall,relayerV3:this.relayerV3,relayerV4:this.relayerV4,veBal:this.veBal,veBalProxy:this.veBalProxy,ERC20:this.getErc20,liquidityGauge:this.getLiquidityGauge}}getErc20(e,t){return((e,t)=>new u(e,Ys,t))(e,t)}getLiquidityGauge(e,t){return((e,t)=>new u(e,si,t))(e,t)}}const ri={1:{relayer:"0x886A3Ec7bcC508B8795990B60Fa21f85F9dB7948",staBal3:{id:"0x06df3b2bbb68adc8b0e302443692037ed9f91b42000000000000000000000063",address:"0x06df3b2bbb68adc8b0e302443692037ed9f91b42",gauge:"0x34f33cdaed8ba0e1ceece80e5f4a73bcf234cfac",assetOrder:["DAI","USDC","USDT"]},bbausd1:{id:"0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb20000000000000000000000fe",address:"0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb2",gauge:"0x68d019f64a7aa97e2d4e7363aee42251d08124fb",assetOrder:["bb-a-USDT","bb-a-DAI","bb-a-USDC"]},bbausd2:{id:"0xa13a9247ea42d743238089903570127dda72fe4400000000000000000000035d",address:"0xa13a9247ea42d743238089903570127dda72fe44",gauge:"0xa6325e799d266632d347e41265a69af111b05403"},linearUsdc1:{id:"0x9210f1204b5a24742eba12f710636d76240df3d00000000000000000000000fc",address:"0x9210F1204b5a24742Eba12f710636D76240dF3d0"},linearDai1:{id:"0x804cdb9116a10bb78768d3252355a1b18067bf8f0000000000000000000000fb",address:"0x804CdB9116a10bB78768D3252355a1b18067bF8f"},linearUsdt1:{id:"0x2bbf681cc4eb09218bee85ea2a5d3d13fa40fc0c0000000000000000000000fd",address:"0x2BBf681cC4eb09218BEe85EA2a5d3D13Fa40fC0C"},linearUsdc2:{id:"0x82698AECC9E28E9BB27608BD52CF57F704BD1B83000000000000000000000336",address:"0x82698aeCc9E28e9Bb27608Bd52cF57f704BD1B83"},linearDai2:{id:"0xAE37D54AE477268B9997D4161B96B8200755935C000000000000000000000337",address:"0xae37D54Ae477268B9997d4161B96b8200755935c"},linearUsdt2:{id:"0x2F4EB100552EF93840D5ADC30560E5513DFFFACB000000000000000000000334",address:"0x2F4eb100552ef93840d5aDC30560E5513DFfFACb"},maiusd:{id:"",address:"",gauge:"",assetOrder:["USDT","miMATIC","DAI","USDC"]},maibbausd:{id:"",address:"",gauge:"",assetOrder:["bb-a-USD","miMATIC"]},DAI:"0x6b175474e89094c44da98b954eedeac495271d0f",USDC:"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",USDT:"0xdAC17F958D2ee523a2206206994597C13D831ec7",waDAI:"0x02d60b84491589974263d922d9cc7a3152618ef6",waUSDC:"0xd093fa4fb80d09bb30817fdcd442d4d02ed3e5de",waUSDT:"0xf8fd466f12e236f4c96f7cce6c79eadb819abf58",miMATIC:""},5:{relayer:"0x7b9B6f094DC2Bd1c12024b0D9CC63d6993Be1888",staBal3:{id:"0xdcdd4a3d36dec8d57594e89763d069a7e9b223e2000000000000000000000062",address:"0xdcdd4a3d36dec8d57594e89763d069a7e9b223e2",gauge:"0xfd364cda96bb7db06b65706182c448a73f0a5f9a",assetOrder:["USDT","DAI","USDC"]},staBal3_2:{id:"0xff9d677474d4344379924e10b68c8fea67e03294000000000000000000000072",address:"0xff9d677474d4344379924e10b68c8fea67e03294",gauge:"0x4e4ebf2aa90e41174d716a5168895357762d68af",assetOrder:["USDT","DAI","USDC"]},staBal3_3:{id:"0x3bfc8a0509f1a68aefd446f6c19bf37b3c75a8fc0000000000000000000000a5",address:"0x3bfc8a0509f1a68aefd446f6c19bf37b3c75a8fc",gauge:"0x7776e1008d7c20ab54aa57a7c44fc7de602de29a",assetOrder:["USDT","DAI","USDC"]},bbausd1:{id:"0x13acd41c585d7ebb4a9460f7c8f50be60dc080cd00000000000000000000005f",address:"0x13acd41c585d7ebb4a9460f7c8f50be60dc080cd",gauge:"0xa2d0ea81a47d68598922cd54c59249ff58c2a3ff",assetOrder:["bb-a-USDC","bb-a-DAI","bb-a-USDT"]},bbausd2:{id:"0x13acd41c585d7ebb4a9460f7c8f50be60dc080cd00000000000000000000005f",address:"0x13acd41c585d7ebb4a9460f7c8f50be60dc080cd",gauge:"0xa2d0ea81a47d68598922cd54c59249ff58c2a3ff"},linearUsdc1:{id:"0x0595d1df64279ddb51f1bdc405fe2d0b4cc8668100000000000000000000005c",address:"0x0595d1df64279ddb51f1bdc405fe2d0b4cc86681"},linearDai1:{id:"0x5cea6a84ed13590ed14903925fa1a73c36297d9900000000000000000000005d",address:"0x5cea6a84ed13590ed14903925fa1a73c36297d99"},linearUsdt1:{id:"0xefd681a82970ac5d980b9b2d40499735e7bf3f1f00000000000000000000005e",address:"0xefd681a82970ac5d980b9b2d40499735e7bf3f1f"},linearUsdc2:{id:"0x0595d1df64279ddb51f1bdc405fe2d0b4cc8668100000000000000000000005c",address:"0x0595d1df64279ddb51f1bdc405fe2d0b4cc86681"},linearDai2:{id:"0x5cea6a84ed13590ed14903925fa1a73c36297d9900000000000000000000005d",address:"0x5cea6a84ed13590ed14903925fa1a73c36297d99"},linearUsdt2:{id:"0xefd681a82970ac5d980b9b2d40499735e7bf3f1f00000000000000000000005e",address:"0xefd681a82970ac5d980b9b2d40499735e7bf3f1f"},maiusd:{id:"0x6a8f9ab364b85725973d2a33cb9aae2dac43b5e30000000000000000000000a6",address:"0x6a8f9ab364b85725973d2a33cb9aae2dac43b5e3",gauge:"0x58141bdcecb7fbae006964f4131cf6f65c948357",assetOrder:["USDT","miMATIC","DAI","USDC"]},maibbausd:{id:"0xb04b03b78cf79788a1931545bd2744161029648f0000000000000000000000a8",address:"0xb04b03b78cf79788a1931545bd2744161029648f",gauge:"0xdc3f6fc8898830e53c777543fe252b14f22680d4",assetOrder:["bb-a-USD","miMATIC","MAI BSP"]},USDT:"0x1f1f156e0317167c11aa412e3d1435ea29dc3cce",DAI:"0x8c9e6c40d3402480ace624730524facc5482798c",USDC:"0xe0c9275e44ea80ef17579d33c55136b7da269aeb",waDAI:"0x89534a24450081aa267c79b07411e9617d984052",waUSDC:"0x811151066392fd641fe74a9b55a712670572d161",waUSDT:"0x4cb1892fddf14f772b2e39e299f44b2e5da90d04",miMATIC:"0x398106564948feeb1fedea0709ae7d969d62a391"},137:{relayer:"0xcf6a66E32dCa0e26AcC3426b851FD8aCbF12Dac7",staBal3:{id:"",address:"",gauge:"",assetOrder:["USDT","DAI","USDC"]},bbausd1:{id:"",address:"",gauge:"",assetOrder:["bb-a-USDC","bb-a-DAI","bb-a-USDT"]},bbausd2:{id:"0x48e6b98ef6329f8f0a30ebb8c7c960330d64808500000000000000000000075b",address:"0x48e6b98ef6329f8f0a30ebb8c7c960330d648085",gauge:""},linearUsdc1:{id:"",address:""},linearDai1:{id:"",address:""},linearUsdt1:{id:"",address:""},linearUsdc2:{id:"0xf93579002dbe8046c43fefe86ec78b1112247bb8000000000000000000000759",address:"0xf93579002dbe8046c43fefe86ec78b1112247bb8"},linearDai2:{id:"0x178e029173417b1f9c8bc16dcec6f697bc323746000000000000000000000758",address:"0x178e029173417b1f9c8bc16dcec6f697bc323746"},linearUsdt2:{id:"0xff4ce5aaab5a627bf82f4a571ab1ce94aa365ea600000000000000000000075a",address:"0xff4ce5aaab5a627bf82f4a571ab1ce94aa365ea6"},maiusd:{id:"0x06df3b2bbb68adc8b0e302443692037ed9f91b42000000000000000000000012",address:"0x06df3b2bbb68adc8b0e302443692037ed9f91b42",gauge:"0x72843281394e68de5d55bcf7072bb9b2ebc24150",assetOrder:["USDC","DAI","miMATIC","USDT"]},maibbausd:{id:"0xb54b2125b711cd183edd3dd09433439d5396165200000000000000000000075e",address:"0xb54b2125b711cd183edd3dd09433439d53961652",gauge:"0x9a105ef22a59484aa2731c357049f6a13d0891f5",assetOrder:["bb-a-USD","miMATIC"]},USDT:"0xc2132d05d31c914a87c6611c10748aeb04b58e8f",DAI:"0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",USDC:"0x2791bca1f2de4661ed88a30c99a7a9449aa84174",waDAI:"0xEE029120c72b0607344f35B17cdD90025e647B00",waUSDC:"0x221836a597948Dce8F3568E044fF123108aCc42A",waUSDT:"0x19C60a251e525fa88Cd6f3768416a8024e98fC19",miMATIC:"0xa3fa99a148fa48d14ed51d610c367c61876997f1"}},oi=new t(ai),di=js.toChainedReference("21"),ci=js.toChainedReference("22"),li=js.toChainedReference("23"),pi=js.toChainedReference("24");class ui{constructor(e){this.addresses=ri[e]}calldata(e,t,a,n,s){if(d.from(t).lte(0))throw new $t(Gt.INPUT_ZERO_NOT_ALLOWED);const i=this.addresses.relayer;let r=[];s&&(r=[this.buildSetRelayerApproval(s)]),r=n?[...r,this.buildWithdraw(e,t),this.buildExit(i,t),this.buildSwap(a,i),this.buildDeposit(e)]:[...r,this.buildExit(e,t),this.buildSwap(a,e)];return{to:i,data:oi.encodeFunctionData("multicall",[r])}}buildExit(e,t){const{assetOrder:a}=this.addresses.staBal3,n=a.map((e=>this.addresses[e])),s=Z.exitExactBPTInForTokensOut(t),i=[{index:a.indexOf("DAI"),key:di},{index:a.indexOf("USDC"),key:ci},{index:a.indexOf("USDT"),key:li}];return js.constructExitCall({assets:n,minAmountsOut:["0","0","0"],userData:s,toInternalBalance:!0,poolId:this.addresses.staBal3.id,poolKind:0,sender:e,recipient:this.addresses.relayer,outputReferences:i,exitPoolRequest:{}})}buildSwap(e,t){const a=[this.addresses.bbausd2.address,this.addresses.DAI,this.addresses.linearDai2.address,this.addresses.USDC,this.addresses.linearUsdc2.address,this.addresses.USDT,this.addresses.linearUsdt2.address],n=[{index:0,key:pi}],s=[{poolId:this.addresses.linearDai2.id,assetInIndex:1,assetOutIndex:2,amount:di.toString(),userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:2,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.linearUsdc2.id,assetInIndex:3,assetOutIndex:4,amount:ci.toString(),userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:4,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.linearUsdt2.id,assetInIndex:5,assetOutIndex:6,amount:li.toString(),userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:6,assetOutIndex:0,amount:"0",userData:"0x"}],i=[d.from(e).mul(-1).toString(),o.toString(),"0",o.toString(),"0",o.toString(),"0"],r={sender:this.addresses.relayer,recipient:t,fromInternalBalance:!0,toInternalBalance:!1};return js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:s,assets:a,funds:r,limits:i,deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:n})}buildWithdraw(e,t){return js.encodeGaugeWithdraw(this.addresses.staBal3.gauge,e,this.addresses.relayer,t)}buildDeposit(e){return js.encodeGaugeDeposit(this.addresses.bbausd2.gauge,this.addresses.relayer,e,pi.toString())}buildSetRelayerApproval(e){return js.encodeSetRelayerApproval(this.addresses.relayer,!0,e)}}const yi=new t(ai),bi=js.toChainedReference("24");class fi{constructor(e){this.addresses=ri[e]}calldata(e,t,a,n,s,i){if(d.from(t).lte(0))throw new $t(Gt.INPUT_ZERO_NOT_ALLOWED);const r=this.addresses.relayer;let o=[];i&&(o=[this.buildSetRelayerApproval(i)]),o=n?[...o,this.buildWithdraw(e,t),this.buildSwap(t,a,r,r,s),this.buildDeposit(e)]:[...o,this.buildSwap(t,a,e,e,s)];const c=yi.encodeFunctionData("multicall",[o]);return{to:this.addresses.relayer,data:c}}buildSwap(e,t,a,n,i){const r=[this.addresses.bbausd2.address,this.addresses.waDAI,this.addresses.linearDai1.address,this.addresses.linearDai2.address,this.addresses.waUSDC,this.addresses.linearUsdc1.address,this.addresses.linearUsdc2.address,this.addresses.waUSDT,this.addresses.linearUsdt1.address,this.addresses.linearUsdt2.address,this.addresses.bbausd1.address],o=[{index:0,key:bi}],c=i.reduce(((e,t)=>e.add(d.from(t))),s),{assetOrder:l}=this.addresses.bbausd1,p=d.from(e).mul(i[l.indexOf("bb-a-USDC")]).div(c).toString(),u=d.from(e).mul(i[l.indexOf("bb-a-DAI")]).div(c).toString(),y=d.from(e).sub(p).sub(u).toString(),b=[{poolId:this.addresses.bbausd1.id,assetInIndex:10,assetOutIndex:2,amount:u,userData:"0x"},{poolId:this.addresses.linearDai1.id,assetInIndex:2,assetOutIndex:1,amount:"0",userData:"0x"},{poolId:this.addresses.linearDai2.id,assetInIndex:1,assetOutIndex:3,amount:"0",userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:3,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.bbausd1.id,assetInIndex:10,assetOutIndex:5,amount:p,userData:"0x"},{poolId:this.addresses.linearUsdc1.id,assetInIndex:5,assetOutIndex:4,amount:"0",userData:"0x"},{poolId:this.addresses.linearUsdc2.id,assetInIndex:4,assetOutIndex:6,amount:"0",userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:6,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.bbausd1.id,assetInIndex:10,assetOutIndex:8,amount:y,userData:"0x"},{poolId:this.addresses.linearUsdt1.id,assetInIndex:8,assetOutIndex:7,amount:"0",userData:"0x"},{poolId:this.addresses.linearUsdt2.id,assetInIndex:7,assetOutIndex:9,amount:"0",userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:9,assetOutIndex:0,amount:"0",userData:"0x"}],f=[d.from(t).mul(-1).toString(),"0","0","0","0","0","0","0","0","0",e],m={sender:a,recipient:n,fromInternalBalance:!1,toInternalBalance:!1};return js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:b,assets:r,funds:m,limits:f,deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:o})}buildWithdraw(e,t){return js.encodeGaugeWithdraw(this.addresses.bbausd1.gauge,e,this.addresses.relayer,t)}buildDeposit(e){return js.encodeGaugeDeposit(this.addresses.bbausd2.gauge,this.addresses.relayer,e,bi.toString())}buildSetRelayerApproval(e){return js.encodeSetRelayerApproval(this.addresses.relayer,!0,e)}}const mi=new t(ai),hi=js.toChainedReference("0"),Ti=[];class gi{constructor(e){this.addresses=ri[e]}calldata(e,t,a,n,s,i,r,o){if(i&&(null==t.gauge||null==a.gauge))throw new Error("Staked flow migration requires gauge addresses to be provided");const d=this.addresses.relayer;let c=[];o&&(c=[this.buildSetRelayerApproval(o)]),c=i?[...c,this.buildWithdraw(e,n,t.gauge),this.buildExit(t.id,d,n,r),this.buildSwap(s,d,a.id,a.address,r),this.buildDeposit(e,a.gauge)]:[...c,this.buildExit(t.id,e,n,r),this.buildSwap(s,e,a.id,a.address,r)];const l=mi.encodeFunctionData("multicall",[c]);return{to:this.addresses.relayer,data:l}}buildExit(e,t,a,n){const s=Z.exitExactBPTInForTokensOut(a),i=[];for(let e=0;e<n.length;e++)i[e]={index:e,key:js.toChainedReference(`${e+1}`)},Ti.push(i[e].key);const r=Array(n.length).fill("0");return js.constructExitCall({assets:n,minAmountsOut:r,userData:s,toInternalBalance:!0,poolId:e,poolKind:0,sender:t,recipient:this.addresses.relayer,outputReferences:i,exitPoolRequest:{}})}buildSwap(e,t,a,n,s){const i=[n,...s],r=[{index:0,key:hi}],c=[];for(let e=0;e<s.length;e++)c.push({poolId:a,assetInIndex:e+1,assetOutIndex:0,amount:Ti[e].toString(),userData:"0x"});const l=[d.from(e).mul(-1).toString()];for(let e=0;e<s.length;e++)l.push(o.toString());const p={sender:this.addresses.relayer,recipient:t,fromInternalBalance:!0,toInternalBalance:!1};return js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:c,assets:i,funds:p,limits:l,deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:r})}buildWithdraw(e,t,a){return js.encodeGaugeWithdraw(a,e,this.addresses.relayer,t)}buildDeposit(e,t){return js.encodeGaugeDeposit(t,this.addresses.relayer,e,hi.toString())}buildSetRelayerApproval(e){return js.encodeSetRelayerApproval(this.addresses.relayer,!0,e)}}const Ii=new t(ai),wi=js.toChainedReference("20"),Ei=js.toChainedReference("21"),xi=js.toChainedReference("22"),Ai=js.toChainedReference("23"),Si=js.toChainedReference("24");class Pi{constructor(e){this.addresses=ri[e]}calldata(e,t,a,n,s){if(d.from(t).lte(0))throw new $t(Gt.INPUT_ZERO_NOT_ALLOWED);const i=this.addresses.relayer;let r=[];s&&(r=[this.buildSetRelayerApproval(s)]),r=n?[...r,this.buildWithdraw(e,t),this.buildExit(i,t),this.buildSwap(i,a),this.buildDeposit(e)]:[...r,this.buildExit(e,t),this.buildSwap(e,a)];return{to:i,data:Ii.encodeFunctionData("multicall",[r])}}buildExit(e,t){const{assetOrder:a}=this.addresses.maiusd,n=a.map((e=>this.addresses[e])),s=Z.exitExactBPTInForTokensOut(t),i=[{index:a.indexOf("miMATIC"),key:wi},{index:a.indexOf("DAI"),key:Ei},{index:a.indexOf("USDC"),key:xi},{index:a.indexOf("USDT"),key:Ai}],r=Array(n.length).fill("0");return js.constructExitCall({assets:n,minAmountsOut:r,userData:s,toInternalBalance:!0,poolId:this.addresses.maiusd.id,poolKind:0,sender:e,recipient:this.addresses.relayer,outputReferences:i,exitPoolRequest:{}})}buildSwap(e,t){const a=[this.addresses.bbausd2.address,this.addresses.DAI,this.addresses.linearDai2.address,this.addresses.USDC,this.addresses.linearUsdc2.address,this.addresses.USDT,this.addresses.linearUsdt2.address,this.addresses.miMATIC,this.addresses.maibbausd.address],n=[{index:8,key:Si}],s=[{poolId:this.addresses.linearDai2.id,assetInIndex:1,assetOutIndex:2,amount:Ei.toString(),userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:2,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.maibbausd.id,assetInIndex:0,assetOutIndex:8,amount:"0",userData:"0x"},{poolId:this.addresses.linearUsdc2.id,assetInIndex:3,assetOutIndex:4,amount:xi.toString(),userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:4,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.maibbausd.id,assetInIndex:0,assetOutIndex:8,amount:"0",userData:"0x"},{poolId:this.addresses.linearUsdt2.id,assetInIndex:5,assetOutIndex:6,amount:Ai.toString(),userData:"0x"},{poolId:this.addresses.bbausd2.id,assetInIndex:6,assetOutIndex:0,amount:"0",userData:"0x"},{poolId:this.addresses.maibbausd.id,assetInIndex:0,assetOutIndex:8,amount:"0",userData:"0x"},{poolId:this.addresses.maibbausd.id,assetInIndex:7,assetOutIndex:8,amount:wi.toString(),userData:"0x"}],i=["0",o.toString(),"0",o.toString(),"0",o.toString(),"0",o.toString(),d.from(t).mul(-1).toString()],r={sender:this.addresses.relayer,recipient:e,fromInternalBalance:!0,toInternalBalance:!1};return js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:s,assets:a,funds:r,limits:i,deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:n})}buildWithdraw(e,t){return js.encodeGaugeWithdraw(this.addresses.maiusd.gauge,e,this.addresses.relayer,t)}buildDeposit(e){return js.encodeGaugeDeposit(this.addresses.maibbausd.gauge,this.addresses.relayer,e,Si.toString())}buildSetRelayerApproval(e){return js.encodeSetRelayerApproval(this.addresses.relayer,!0,e)}}class _i{constructor(e){this.network=e}stabal3(t,a,n,s,i){const r=new ui(this.network).calldata(t,a,n,s,i);return{to:r.to,data:r.data,decode:(t,a)=>{let n=a?2:1;i&&(n+=1);const s=e.decode(["bytes[]"],t);return e.decode(["int256[]"],s[0][n])[0][0].abs().toString()}}}bbaUsd(t,a,n,s,i,r){const o=new fi(this.network).calldata(t,a,n,s,i,r);return{to:o.to,data:o.data,decode:(t,a)=>{let n=a?1:0;r&&(n+=1);const s=e.decode(["bytes[]"],t);return e.decode(["int256[]"],s[0][n])[0][0].abs().toString()}}}stables(t,a,n,s,i,r,o,d){const c=new gi(this.network).calldata(t,a,n,s,i,r,o,d);return{to:c.to,data:c.data,decode:(t,a)=>{let n=a?2:1;d&&(n+=1);const s=e.decode(["bytes[]"],t);return e.decode(["int256[]"],s[0][n])[0][0].abs().toString()}}}maiusd(t,a,n,s,i){const r=new Pi(this.network).calldata(t,a,n,s,i);return{to:r.to,data:r.data,decode:(t,a)=>{let n=a?2:1;i&&(n+=1);const s=e.decode(["bytes[]"],t);return e.decode(["int256[]"],s[0][n])[0][8].abs().toString()}}}}class vi{constructor(e){this.network=e,this.migrations=new _i(e)}}class Oi{constructor(e,t){this.tokenPrices=e,this.tokenHistoricalPrices=t}async calcImpLoss(e,t){if(1e3*e>=Date.now())throw console.error(`[ImpermanentLossService][calcImpLoss]Error: ${$t.getMessage(Gt.TIMESTAMP_IN_THE_FUTURE)}`),new $t(Gt.TIMESTAMP_IN_THE_FUTURE);const a=await this.prepareData(e,t),n=this.getPoolValueDelta(a),s=this.getHoldValueDelta(a);return this.calculateImpermanentLoss(n,s)}calculateImpermanentLoss(e,t){return Math.floor(100*Math.abs(e/t-1)*100)/100}getPoolValueDelta(e){return e.reduce(((e,t)=>e*Math.pow(Math.abs(t.priceDelta+1),t.weight)),1)}getHoldValueDelta(e){return e.reduce(((e,t)=>e+Math.abs(t.priceDelta+1)*t.weight),0)}async prepareData(e,t){const a=t.tokens.filter((e=>e.address!==t.address)),n=this.getWeights(a),s=a.map((e=>e.address)),i=await this.getEntryPrices(e,s),r=await this.getExitPrices(a);return this.getAssets(a,r,i,n)}getAssets(e,t,a,n){return e.map(((e,s)=>({priceDelta:this.getDelta(a[e.address],t[e.address]),weight:n[s]})))}getDelta(e,t){if(0===e)throw console.error(`[ImpermanentLossService][getDelta]Error: ${$t.getMessage(Gt.ILLEGAL_PARAMETER)}: entry price is 0`),new $t(Gt.ILLEGAL_PARAMETER);return(t-e)/e}getWeights(e){const t=e.every((e=>!e.weight)),a=Math.round(1/e.length*100)/100,n=t?e.map((()=>a)):e.map((e=>{var t;return Number(null!==(t=e.weight)&&void 0!==t?t:0)}));if(n.some((e=>0===e)))throw console.error(`[ImpermanentLossService][getWeights]Error: ${$t.getMessage(Gt.MISSING_WEIGHT)}`),new $t(Gt.MISSING_WEIGHT);return n}async getExitPrices(e){var t;const a=await Promise.all(e.map((e=>this.tokenPrices.find(e.address)))).catch((()=>[]));if(!a.length||a.some((e=>void 0===(null==e?void 0:e.usd))))throw console.error(`[ImpermanentLossService][getExitPrices]Error: ${$t.getMessage(Gt.MISSING_PRICE_RATE)}`),new $t(Gt.MISSING_PRICE_RATE);const n=e.map(((e,t)=>({...e,price:a[t]}))),s={};for(const e of n)(null===(t=e.price)||void 0===t?void 0:t.usd)&&(s[e.address]=+e.price.usd);return s}async getEntryPrices(e,t){const a={};for(const n of t){const t=await this.tokenHistoricalPrices.findBy(n,e).catch((e=>{console.error(`[ImpermanentLossService][getEntryPrices]Error: ${e.message}`)}));if(!(null==t?void 0:t.usd))throw console.error(`[ImpermanentLossService][getEntryPrices]Error: ${$t.getMessage(Gt.MISSING_PRICE_RATE)}`),new $t(Gt.MISSING_PRICE_RATE);a[n]=+t.usd}return a}}const Bi=335e3,ki=1765411200,Di=(e=Math.round((new Date).getTime()/1e3))=>Bi;var Ni=Object.freeze({__proto__:null,INITIAL_RATE:Bi,START_EPOCH_TIME:ki,weekly:Di,total:e=>365*(Di()/7),between:(e,t)=>{if(e<ki)throw"start timestamp before emission schedule deployment";if(t<e)throw"cannot finish before starting";const a=t-e,n=Di()/7;return Math.round(a/86400)*n}});class Ci{constructor(e,t){this.repository=e,this.tokenPrices=t}async data(e=Date.now()){const t=await this.repository.multicallData(e),a=await this.tokenPrices.find(t.balAddress);if(!a||!a.usd)throw"No BAL USD price found";return{lastWeekBalRevenue:t.balAmount*parseFloat(a.usd),lastWeekBBAUsdRevenue:t.bbAUsdAmount*t.bbAUsdPrice,veBalSupply:t.veBalSupply}}}class Fi{constructor(e){this.yesterdaysPools=e}async last24h(e){let t;return this.yesterdaysPools&&(t=await this.yesterdaysPools.find(e.id)),e.totalSwapFee?(null==t?void 0:t.totalSwapFee)?parseFloat(e.totalSwapFee)-parseFloat(t.totalSwapFee):e.createTime&&Js(e.createTime)?parseFloat(e.totalSwapFee):0:0}}class Ri{constructor(e,t,a,n,s,i,r,o){this.pools=e,this.tokenPrices=t,this.tokenMeta=a,this.tokenYields=n,this.feeCollector=s,this.yesterdaysPools=i,this.liquidityGauges=r,this.feeDistributor=o}async swapFees(e){const t=await this.last24hFees(e),a=await this.totalLiquidity(e);if(!t||!a)return 0;const n=t*(1-await this.protocolSwapFeePercentage(e))/parseFloat(a)*1e4;return Math.round(365*n)}async tokenAprs(e){return{total:0,breakdown:{}}}async stakingApr(e,t=1){if(!this.liquidityGauges)return 0;const a=await this.liquidityGauges.findBy("poolId",e.id);if(!a||(248==e.chainId||9372==e.chainId||6343==e.chainId||4326==e.chainId)&&0==a.workingSupply||248!=e.chainId&&9372!=e.chainId&&6343!=e.chainId&&4326!=e.chainId&&0==a.totalSupply)return 0;const n=Lt[e.chainId].addresses.tokens.bal;if(!n)return 0;const[s,i]=await Promise.all([this.tokenPrices.find(n),this.bptPrice(e)]);if(!(null==s?void 0:s.usd))throw"Missing BAL price";const r=parseFloat(s.usd),o=Di()/7*365*a.relativeWeight*r,d=(a.workingSupply+.4)/.4*i;return Math.round(1e4*t*o/d)}async stakingAprNextPeriod(e,t=1){if(!this.liquidityGauges)return 0;const a=await this.liquidityGauges.findBy("poolId",e.id);if(!a)return 0;if(0==a.workingSupply)return a.relativeWeightNextPeriod&&a.relativeWeightNextPeriod>0?-1:0;const n=Lt[e.chainId].addresses.tokens.bal;if(!n)return 0;const[s,i]=await Promise.all([this.tokenPrices.find(n),this.bptPrice(e)]);if(!(null==s?void 0:s.usd))throw"Missing BAL price";const r=parseFloat(s.usd),o=Di()/7*365*(a.relativeWeightNextPeriod||0)*r,d=(a.workingSupply+.4)/.4*i;return Math.round(1e4*t*o/d)}async rewardAprs(e){if(!this.liquidityGauges)return{total:0,breakdown:{}};const t=await this.liquidityGauges.findBy("poolId",e.id);if(!t)return{total:0,breakdown:{}};if(!t.rewardTokens)return{total:0,breakdown:{}};if(Object.keys(t.rewardTokens).length<1)return{total:0,breakdown:{}};const a=Lt[e.chainId].addresses.tokens.bal,n=Object.keys(t.rewardTokens).filter((e=>e!=a)).map((async e=>{const a=t.rewardTokens[e];return this.rewardTokenApr(e,a)})),s=await this.bptPrice(e),i=t.totalSupply*s,r={};let o=0;for await(const e of Object.values(n)){const t=i>0?e.value/i:0,a=Math.round(1e4*t);o+=a,r[e.address]=a}return{total:o,breakdown:r}}async protocolApr(e){if(""!=e.id||!this.feeDistributor)return 0;const t=new Ci(this.feeDistributor,this.tokenPrices),{lastWeekBalRevenue:a,lastWeekBBAUsdRevenue:n,veBalSupply:s}=await t.data(),i=await this.bptPrice(e);if(!i)throw"bptPrice for veBal pool missing";const r=(a+n)/7;return Math.round(365*r*1e4/(i*s))}async apr(e){const[t,a,n,s,i,r]=await Promise.all([this.swapFees(e),this.tokenAprs(e),this.stakingApr(e),this.stakingApr(e,2.5),this.rewardAprs(e),this.protocolApr(e)]);return{swapFees:t,tokenAprs:a,stakingApr:{min:n,max:s},rewardAprs:i,protocolApr:r,min:t+a.total+i.total+n,max:t+a.total+i.total+r+s}}async aprNextPeriod(e){const[t,a,n,s,i,r]=await Promise.all([this.swapFees(e),this.tokenAprs(e),this.stakingAprNextPeriod(e),this.stakingAprNextPeriod(e,2.5),this.rewardAprs(e),this.protocolApr(e)]);return{swapFees:t,tokenAprs:a,stakingApr:{min:n,max:s},rewardAprs:i,protocolApr:r,min:t+a.total+i.total+n,max:t+a.total+i.total+r+s}}async last24hFees(e){return new Fi(this.yesterdaysPools).last24h(e)}async totalLiquidity(e){try{const t=new Pa(this.pools,this.tokenPrices);return await t.getLiquidity(e)}catch(t){return console.error("Liquidity calculcation failed, falling back to subgraph"),e.totalLiquidity}}async bptPrice(e){const t=await this.totalLiquidity(e),a=e.totalShares;return parseFloat(t)/parseFloat(a)}async protocolSwapFeePercentage(e){let t=0;return t="ComposableStable"==e.poolType||"Weighted"==e.poolType&&2==e.poolTypeVersion?0:e.protocolSwapFeeCache?parseFloat(e.protocolSwapFeeCache):await this.feeCollector.find("")||0,t}async rewardTokenApr(e,t){if(t.period_finish.toNumber()<Date.now()/1e3)return{address:e,value:0};{const a=t.rate.mul(86400).mul(365),n=await this.tokenPrices.find(e);if(n&&n.usd){let s=18;if(t.decimals)s=t.decimals;else{const t=await this.tokenMeta.find(e);t&&void 0!==t.decimals&&(s=t.decimals)}return{address:e,value:parseFloat(rt(a,s))*parseFloat(n.usd)}}throw`No USD price for ${e}`}}}const Mi=new Map;Mi.set(Xe.AaveLinear,"batchSwap"),Mi.set(Xe.EulerLinear,"batchSwap"),Mi.set(Xe.ERC4626Linear,"batchSwap"),Mi.set(Xe.Element,"batchSwap"),Mi.set(Xe.Investment,"joinPool"),Mi.set(Xe.LiquidityBootstrapping,"joinPool"),Mi.set(Xe.MetaStable,"joinPool"),Mi.set(Xe.Stable,"joinPool"),Mi.set(Xe.StablePhantom,"batchSwap"),Mi.set(Xe.Weighted,"joinPool"),Mi.set(Xe.ComposableStable,"joinPool");const Li=new Map;Li.set(Xe.AaveLinear,"batchSwap"),Mi.set(Xe.EulerLinear,"batchSwap"),Li.set(Xe.ERC4626Linear,"batchSwap"),Li.set(Xe.Element,"batchSwap"),Li.set(Xe.Investment,"exitPool"),Li.set(Xe.LiquidityBootstrapping,"exitPool"),Li.set(Xe.MetaStable,"exitPool"),Li.set(Xe.Stable,"exitPool"),Li.set(Xe.StablePhantom,"batchSwap"),Li.set(Xe.Weighted,"exitPool"),Li.set(Xe.ComposableStable,"exitPool");class Ui{constructor(e){this.pools=e}async buildGraphFromRootPool(e,t){const a=await this.pools.find(e);if(!a)throw new $t(Gt.POOL_DOESNT_EXIST);return(await this.buildGraphFromPool(a.address,0,void 0,n,t))[0]}getTokenTotal(e){const t=e.tokensList.indexOf(e.address);let a=s;const{parsedBalances:n}=Le(e);return n.forEach(((e,n)=>{t!==n&&(a=a.add(e))})),a}async buildGraphFromPool(e,t,a,n,s){var i;const r=await this.pools.findBy("address",e);if(!r){if(a){const s=await this.pools.findBy("address",a.address),r=null!==(i=s.tokens[s.tokensList.indexOf(e)].decimals)&&void 0!==i?i:18;return Ui.createInputTokenNode(t,e,r,a,n)}throw new $t(Gt.POOL_DOESNT_EXIST)}const o=Mi.get(r.poolType),l=Li.get(r.poolType);if(!o||!l)throw new $t(Gt.UNSUPPORTED_POOL_TYPE);const p=this.getTokenTotal(r),{spotPriceCalculator:u}=Sa.from(r.poolType),y={};let b=18;r.tokens.forEach((e=>{if(Pt(e.address,r.address))return void(b=e.decimals?e.decimals:18);const t=u.calcPoolSpotPrice(e.address,r.address,r);y[e.address]=t}));let f={address:r.address,id:r.id,type:r.poolType,joinAction:o,exitAction:l,children:[],marked:!1,index:t.toString(),parent:a,proportionOfParent:n,isLeaf:!1,spotPrices:y,decimals:b};if(t++,r.poolType.toString().includes("Linear"))[f,t]=this.createLinearNodeChildren(f,t,r,s);else{const{parsedBalances:e}=Le(r);for(let a=0;a<r.tokens.length;a++){if(Pt(r.tokens[a].address,r.address))continue;let i;if("Weighted"===r.poolType){const e=r.tokens[a].weight;i=c(e,18)}else i=d.from(e[a]).mul(1e18.toString()).div(p);const o=i.mul(n).div(1e18.toString()),l=await this.buildGraphFromPool(r.tokens[a].address,t,f,o,s);t=l[1],l[0]&&f.children.push(l[0])}}return[f,t]}createLinearNodeChildren(e,t,a,n){var s;if(n){const n=this.createWrappedTokenNode(a,t,e,e.proportionOfParent);return e.children.push(n[0]),[e,n[1]]}{if(void 0===a.mainIndex)throw new Error("Issue With Linear Pool");const n=null!==(s=a.tokens[a.mainIndex].decimals)&&void 0!==s?s:18,i=Ui.createInputTokenNode(t,a.tokensList[a.mainIndex],n,e,e.proportionOfParent);return e.children.push(i[0]),[e,t=i[1]]}}createWrappedTokenNode(e,t,a,n){var s;if(void 0===e.wrappedIndex||void 0===e.mainIndex)throw new Error("Issue With Linear Pool");let i="wrapAaveDynamicToken";if(e.poolType===Xe.ERC4626Linear)i="wrapERC4626";let r="unwrapAaveStaticToken";if(e.poolType===Xe.ERC4626Linear)r="unwrapERC4626";const o={type:"WrappedToken",address:e.tokensList[e.wrappedIndex],id:"N/A",children:[],marked:!1,joinAction:i,exitAction:r,index:t.toString(),parent:a,proportionOfParent:n,isLeaf:!1,spotPrices:{},decimals:18};t++;const d=null!==(s=e.tokens[e.mainIndex].decimals)&&void 0!==s?s:18,c=Ui.createInputTokenNode(t,e.tokensList[e.mainIndex],d,o,n);return o.children=[c[0]],[o,t=c[1]]}static createInputTokenNode(e,t,a,n,s){return[{address:t,id:"N/A",type:"Input",children:[],marked:!1,joinAction:"input",exitAction:"output",index:e.toString(),parent:n,proportionOfParent:s,isLeaf:!0,spotPrices:{},decimals:a},e+1]}static orderByBfs(e){const t=[],a=[];for(e.marked=!0,t.push(e);t.length>0;){const e=t.shift();e&&a.push(e),null==e||e.children.forEach((e=>{e.marked||(e.marked=!0,t.push(e))}))}return a}static getLeafAddresses(e){return e.filter((e=>e.isLeaf)).map((e=>e.address))}}Ui.getGraphNodes=async(e,t,a,n)=>{if(!await a.find(t))throw new $t(Gt.POOL_DOESNT_EXIST);const s=new Ui(a),i=await s.buildGraphFromRootPool(t,n);if(i.id!==t)throw new Error("Error creating graph nodes");return e?Ui.orderByBfs(i).reverse():Ui.orderByBfs(i)};class Gi{constructor(e,t){this.chainId=e,this.simulateMulticall=async(e,t,a,n)=>{const s={...await this.encodeBalanceAndAllowanceOverrides(a,n),...await this.encodeRelayerApprovalOverride(a,e)};return this.simulateTransaction(e,t,a,s)},this.simulateTransaction=async(e,t,a,n)=>{const s=Object.fromEntries(Object.keys(n).map((e=>[e,{storage:n[e].value}]))),i={network_id:this.chainId.toString(),block_number:this.blockNumber,from:a,to:e,input:t,save_if_fails:!0,simulation_type:"quick",state_objects:s},r=this.tenderlyUrl+"simulate";return(await h.post(r,i,this.opts)).data.transaction.transaction_info.call_trace.output},this.encodeRelayerApprovalOverride=async(e,t)=>{const a={[`${this.vaultAddress}`]:{value:{[`_approvedRelayers[${e}][${t}]`]:(!0).toString()}}};return await this.requestStateOverrides(a)},this.encodeBalanceAndAllowanceOverrides=async(e,t)=>{if(0===t.length)return{};let a={};t.forEach((t=>a={...a,[`${t}`]:{value:{[`_balances[${e}]`]:o.toString(),[`_allowances[${e}][${this.vaultAddress}]`]:o.toString(),[`balanceOf[${e}]`]:o.toString(),[`allowance[${e}][${this.vaultAddress}]`]:o.toString(),[`balances[${e}]`]:o.toString(),[`allowed[${e}][${this.vaultAddress}]`]:o.toString()}}}));const n=await this.requestStateOverrides(a);if(Object.keys(n).some((e=>2!==Object.keys(n[e].value).length)))throw new Error("Couldn't encode state overrides - states should match the ones in the contracts");return n},this.requestStateOverrides=async e=>{const t=this.tenderlyUrl+"contracts/encode-states",a={networkID:this.chainId.toString(),stateOverrides:e},n=(await h.post(t,a,this.opts)).data.stateOverrides;if(!n||Object.keys(n).length!==Object.keys(e).length)throw new Error("Couldn't encode state overrides - contracts should be verified and whitelisted on Tenderly");return n};const{contracts:a}=Ut(this.chainId);this.vaultAddress=a.vault,(null==t?void 0:t.user)&&(null==t?void 0:t.project)?this.tenderlyUrl=`https://api.tenderly.co/api/v1/account/${t.user}/project/${t.project}/`:this.tenderlyUrl="https://api.balancer.fi/tenderly/",(null==t?void 0:t.accessKey)&&(this.opts={headers:{"X-Access-Key":t.accessKey}}),this.blockNumber=null==t?void 0:t.blockNumber}}var $i;const qi=new t(ti);class Wi{constructor(t,a){this.pools=t,this.createCalls=async(e,t,a,n)=>{const{calls:s,outputIndexes:i,deltas:r}=this.createActionCalls(e,t,a);n&&s.unshift(this.createSetRelayerApproval(n));return{callData:qi.encodeFunctionData("multicall",[s]),outputIndexes:n?i.map((e=>e+1)):i,deltas:r}},this.amountsOutByJoinPath=async(t,a,n,s)=>{const i=[],r=await this.tenderlyHelper.simulateMulticall(this.relayer,a,t,n),o=e.decode(["bytes[]"],r)[0];let c=d.from("0");return s.forEach((t=>{const a=e.decode(["uint256"],o[t]);i.push(a.toString()),c=c.add(a.toString())})),{amountsOut:i,totalAmountOut:c.toString()}},this.minAmountsOutByJoinPath=(e,t,a)=>({minAmountsOut:t.map((t=>Ft(d.from(t),d.from(e)).toString())),totalMinAmountOut:Ft(d.from(a),d.from(e)).toString()}),this.createActionCalls=(e,t,a)=>{const n=[],s=[],i=!a,r={};return e.forEach(((e,o)=>{const d=e[0].isLeaf;if(e.forEach(((s,i)=>{let c;if(c=d?e.filter((e=>{var t;return s.children.map((e=>e.address)).includes(e.address)&&s.index===(null===(t=e.parent)||void 0===t?void 0:t.index)})):i>0?[e[i-1]]:[],c.length>0&&0===c.filter((e=>"0"!==e.index)).length)return void(s.index="0");c.some((e=>"input"===e.joinAction||"wrapAaveDynamicToken"===e.joinAction));const l=t,p=i===e.length-1,u=t,y=p&&a?a[o]:"0";switch(s.joinAction){case"wrapAaveDynamicToken":n.push(this.createAaveWrap(s,c,o,l,t));break;case"batchSwap":{const[e,t,a]=this.createBatchSwap(s,c,o,y,l,u);n.push(e),this.updateDeltas(r,t,a);break}case"joinPool":{const[e,t,a,i]=this.createJoinPool(s,c,o,y,l,u);n.push(e),this.updateDeltas(r,[s.address,...t],[i,...a]);break}}})),i){const e=100*o,t=js.encodePeekChainedReferenceValue(js.toChainedReference(e,!1));n.push(t),s.push(n.indexOf(t))}})),{calls:n,outputIndexes:s,deltas:r}},this.createSetRelayerApproval=e=>js.encodeSetRelayerApproval(this.relayer,!0,e),this.createAaveWrap=(e,t,a,n,s)=>{if(1!==t.length)throw new Error("aaveWrap nodes should always have a single child node");const i=t[0],r=e.address,o=i.index;return js.encodeWrapAaveDynamicToken({staticToken:r,sender:n,recipient:s,amount:o,fromUnderlying:!0,outputReference:this.getOutputRefValue(a,e).value})},this.createBatchSwap=(e,t,a,n,s,i)=>{if(1!==t.length)throw new Error("Unsupported batchswap");const r=t[0].address,c=this.getOutputRefValue(a,t[0]),l=[e.address,r],p=[d.from(n).mul(-1).toString(),c.isRef?o.toString():c.value],u=[{poolId:e.id,assetInIndex:1,assetOutIndex:0,amount:c.value,userData:"0x"}],y={sender:s,recipient:i,fromInternalBalance:s===this.relayer,toInternalBalance:i===this.relayer},b=[{index:l.map((e=>e.toLowerCase())).indexOf(e.address.toLowerCase()),key:d.from(this.getOutputRefValue(a,e).value)}],f=js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:u,assets:l,funds:y,limits:p,deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:b}),m=s===this.relayer?"0":p[1];return[f,l,[i===this.relayer?"0":p[0],m]]},this.createJoinPool=(e,t,a,n,r,o)=>{const d=[],c=[];e.children.forEach((e=>{d.push(e.address);const n=t.find((t=>Pt(t.address,e.address)));n?c.push(this.getOutputRefValue(a,n).value):c.push("0")})),e.type===Xe.ComposableStable&&(d.push(e.address),c.push("0"));const l=new we(this.wrappedNativeAsset),[p,u]=l.sortTokens(d,c);let y=[];const b=p.map((e=>e.toLowerCase())).indexOf(e.address.toLowerCase());let f;y=-1===b?u:[...u.slice(0,b),...u.slice(b+1)],f=e.type===Xe.Weighted?z.joinExactTokensInForBPTOut(y,n):Z.joinExactTokensInForBPTOut(y,n);const m=p.indexOf(i),h=-1===m?"0":u[m],T=js.constructJoinCall({poolId:e.id,kind:0,sender:r,recipient:o,value:h,outputReference:this.getOutputRefValue(a,e).value,joinPoolRequest:{},assets:p,maxAmountsIn:u,userData:f,fromInternalBalance:r===this.relayer}),g=u.map((e=>js.isChainedReference(e)?"0":e)),I=js.isChainedReference(n)?"0":n;return[T,r===this.relayer?[]:p,r===this.relayer?[]:g,o===this.relayer?s.toString():s.sub(I).toString()]},this.getOutputRefValue=(e,t)=>"input"===t.joinAction?{value:t.index,isRef:!1}:"0"===t.index&&t.parent?{value:"0",isRef:!0}:{value:js.toChainedReference(d.from(t.index).add(100*e)).toString(),isRef:!0};const{tokens:n,contracts:r}=Ut(a.chainId);this.relayer=r.relayerV4,this.wrappedNativeAsset=n.wrappedNativeAsset,this.tenderlyHelper=new Gi(a.chainId,a.tenderly)}async joinPool(e,t,a,n,s,i,r){if(t.length!=a.length)throw new $t(Gt.INPUT_LENGTH_MISMATCH);const o=await Ui.getGraphNodes(!0,e,this.pools,s),d=Wi.getJoinPaths(o,t,a),c=Wi.totalBptZeroPriceImpact(d),{callData:l,outputIndexes:p}=await this.createCalls(d,n,void 0,r),{amountsOut:u,totalAmountOut:y}=await this.amountsOutByJoinPath(n,l,t,p),{minAmountsOut:b,totalMinAmountOut:f}=this.minAmountsOutByJoinPath(i,u,y),m=jt(BigInt(y),c.toBigInt(),!0).toString(),{callData:h,deltas:T}=await this.createCalls(d,n,b,r);return this.assertDeltas(e,T,t,a,f),{to:this.relayer,callData:h,expectedOut:y,minOut:f,priceImpact:m}}assertDeltas(e,t,a,n,s){var i;const r=ce(e);if(t[r.toLowerCase()].add(s).abs().gt(3))throw console.error("join assertDeltas, bptOut: ",r,s,null===(i=t[r.toLowerCase()])||void 0===i?void 0:i.toString()),new $t(Gt.JOIN_DELTA_AMOUNTS);delete t[r.toLowerCase()],a.forEach(((e,a)=>{var s,i;if(!d.from(n[a]).eq(0)&&(null===(s=t[e.toLowerCase()])||void 0===s?void 0:s.toString())!==n[a])throw console.error("join assertDeltas, tokenIn: ",e,n[a],null===(i=t[e.toLowerCase()])||void 0===i?void 0:i.toString()),new $t(Gt.JOIN_DELTA_AMOUNTS);delete t[e.toLowerCase()]}));for(const e in t)if("0"!==t[e].toString())throw console.error("join assertDeltas, non-input token should be 0: ",e,t[e].toString()),new $t(Gt.JOIN_DELTA_AMOUNTS)}updateDeltas(e,t,a){return t.forEach(((t,n)=>{const i=t.toLowerCase();e[i]||(e[i]=s),e[i]=e[i].add(a[n])})),e}}$i=Wi,Wi.getJoinPaths=(e,t,a)=>{const s=[],i=e.filter((e=>t.filter(((e,t)=>d.from(a[t]).gt(0))).map((e=>e.toLowerCase())).includes(e.address.toLowerCase())));i.some((e=>e.isLeaf))&&s.push(e);const r=i.filter((e=>!e.isLeaf));return r.forEach((e=>{const i=a.find(((a,n)=>Pt(t[n],e.address))),o=r.filter((t=>Pt(t.address,e.address))).reduce(((e,t)=>e.add(t.proportionOfParent)),d.from(0)),c=d.from(i).mul(e.proportionOfParent).div(o).toString(),[l]=Ui.createInputTokenNode(0,e.address,e.decimals,e.parent,n);l.index=c,l.isLeaf=!1;const p=[l];let u=e.parent;for(;u;)p.push(g(u)),u=u.parent;s.push(p)})),$i.updateInputAmounts(s,t,a),s},Wi.updateInputAmounts=(e,t,a)=>{const n=(e,t)=>{if(e.length>1){const a=e.reduce(((e,t)=>e.add(t.index)),d.from(0)),n=d.from(t).sub(a);e[0].index=n.add(e[0].index).toString()}},s=e.find((e=>e[0].isLeaf));if(s){const e=$i.updateTotalProportions(s);s.forEach((n=>{"input"===n.joinAction&&(n=$i.updateNodeAmount(n,t,a,e))})),t.forEach(((e,t)=>{const i=s.filter((t=>t.isLeaf&&Pt(t.address,e)));n(i,a[t])}))}const i=e.filter((e=>!e[0].isLeaf));i.length>1&&t.forEach(((e,t)=>{const s=i.map((e=>e[0])).filter((t=>Pt(t.address,e)));n(s,a[t])}))},Wi.totalBptZeroPriceImpact=e=>{let t=d.from("0");return e.forEach((e=>{if(e[0].isLeaf){e.filter((e=>e.isLeaf)).forEach((e=>{const a=$i.bptOutZeroPiForInputNode(e);t=t.add(a)}))}else{const a=$i.bptOutZeroPiForInputNode(e[0]);t=t.add(a)}})),t},Wi.bptOutZeroPiForInputNode=e=>{if("0"===e.index||"input"!==e.joinAction)return BigInt(0);let t=1,a=e.parent,n=e.address;for(;void 0!==a;){if("batchSwap"===a.joinAction||"joinPool"===a.joinAction){const e=a.spotPrices[n.toLowerCase()];t*=parseFloat(e),n=a.address}a=a.parent}const s=c(t.toFixed(18),18),i=Ne(BigInt(e.decimals)),r=Ce(BigInt(e.index),i);return Re.divDownFixed(r,s.toBigInt())},Wi.updateTotalProportions=e=>{const t={};return e.forEach((e=>{t[e.address]?t[e.address]=t[e.address].add(e.proportionOfParent):t[e.address]=e.proportionOfParent})),t},Wi.updateNodeAmount=(e,t,a,n)=>{const s=t.map((e=>e.toLowerCase())).indexOf(e.address.toLowerCase());if(-1===s)return e.index="0",e;const i=n[e.address],r=e.proportionOfParent.mul(1e18.toString()).div(i).mul(a[s]).div(1e18.toString());return e.index=r.toString(),e};const Vi=new t(ti);class Hi{constructor(t,a){this.pools=t,this.amountsOutByExitPath=async(t,a,n,s,i)=>{const r=await this.tenderlyHelper.simulateMulticall(this.relayer,a,t,[n]),o=e.decode(["bytes[]"],r)[0],c=s.map((t=>e.decode(["uint256"],o[t]).toString())),l=c.map((e=>Ft(d.from(e),d.from(i)).toString()));return{expectedAmountsOutByExitPath:c,minAmountsOutByExitPath:l}},this.amountsOutByTokenOut=(e,t,a,n)=>{const i={};t.forEach(((e,t)=>{var n;return i[e]=(null!==(n=i[e])&&void 0!==n?n:s).add(a[t])}));const r=e.map((e=>i[e].toString())),o=r.map((e=>Ft(d.from(e),d.from(n)).toString()));return{expectedAmountsOut:r,minAmountsOut:o}},this.getExitPaths=(e,t)=>{const a=e.map((e=>{const a=[e];for(;a[0].parent;)a.unshift(g(a[0].parent));return a[0].index=a[a.length-1].proportionOfParent.mul(t).div(n).toString(),a})),i=a.reduce(((e,t)=>{const a=t[0].index;return d.from(a).add(e)}),s),r=d.from(t).sub(i);return a[a.length-1][0].index=r.add(a[a.length-1][0].index).toString(),a},this.getOutputRef=(e,t)=>100*e+parseInt(t);const{tokens:i,contracts:r}=Ut(a.chainId);this.wrappedNativeAsset=i.wrappedNativeAsset,this.relayer=r.relayerV4,this.tenderlyHelper=new Gi(a.chainId,a.tenderly)}async exitPool(e,t,a,n,s){const i=await Ui.getGraphNodes(!1,e,this.pools,!1),r=i.filter((e=>"output"===e.exitAction)),o=this.getExitPaths(r,t),d=r.map((e=>e.address.toLowerCase())),c=[...new Set(d)].sort(),l=await this.createCalls(o,a,void 0,s),{expectedAmountsOutByExitPath:p,minAmountsOutByExitPath:u}=await this.amountsOutByExitPath(a,l.callData,i[0].address,l.outputIndexes,n),{callData:y,deltas:b}=await this.createCalls(o,a,u,s),{expectedAmountsOut:f,minAmountsOut:m}=this.amountsOutByTokenOut(c,d,p,n);this.assertDeltas(e,b,t,c,m);const h=await this.calculatePriceImpact(e,c,f,t);return{to:this.relayer,callData:y,tokensOut:c,expectedAmountsOut:f,minAmountsOut:m,priceImpact:h}}async calculatePriceImpact(e,t,a,n){const s=await Ui.getGraphNodes(!0,e,this.pools,!1),i=Wi.getJoinPaths(s,t,a),r=Wi.totalBptZeroPriceImpact(i);return jt(BigInt(n),r.toBigInt(),!1).toString()}assertDeltas(e,t,a,n,s){var i;const r=ce(e);if(t[r.toLowerCase()].sub(a).abs().gt(3))throw console.error("exit assertDeltas, bptIn: ",r,a,null===(i=t[r.toLowerCase()])||void 0===i?void 0:i.toString()),new $t(Gt.EXIT_DELTA_AMOUNTS);delete t[r.toLowerCase()],n.forEach(((e,a)=>{var n;if(t[e.toLowerCase()].add(s[a]).abs().gt(1))throw console.error("exit assertDeltas, tokenOut: ",e,s[a],null===(n=t[e.toLowerCase()])||void 0===n?void 0:n.toString()),new $t(Gt.EXIT_DELTA_AMOUNTS);delete t[e.toLowerCase()]}));for(const e in t)if("0"!==t[e].toString())throw console.error("exit assertDeltas, non-input token should be 0: ",e,t[e].toString()),new $t(Gt.EXIT_DELTA_AMOUNTS)}async createCalls(e,t,a,n){const{calls:s,outputIndexes:i,deltas:r}=this.createActionCalls(g(e),t,a);n&&s.unshift(js.encodeSetRelayerApproval(this.relayer,!0,n));return{callData:Vi.encodeFunctionData("multicall",[s]),outputIndexes:n?i.map((e=>e+1)):i,deltas:r}}updateDeltas(e,t,a){return t.forEach(((t,n)=>{const i=t.toLowerCase();e[i]||(e[i]=s),e[i]=e[i].add(a[n])})),e}createActionCalls(e,t,a){const n=[],s=[],i=!a,r={};return e.forEach(((e,o)=>{e.forEach((d=>{const c=!d.parent?t:this.relayer,l=d.children.find((t=>e.map((e=>e.index)).includes(t.index))),p="output"===(null==l?void 0:l.exitAction),u=p?t:this.relayer,y=p&&a?a[o]:"0";switch(d.exitAction){case"batchSwap":{const[e,t,a]=this.createBatchSwap(d,l,o,y,c,u);n.push(e),this.updateDeltas(r,t,a);break}case"exitPool":{const[e,t,a,s]=this.createExitPool(d,l,o,y,c,u);n.push(e),this.updateDeltas(r,[d.address,...a],[t,...s]);break}case"output":i&&(n.push(js.encodePeekChainedReferenceValue(js.toChainedReference(this.getOutputRef(o,d.index),!1))),s.push(n.length-1));break;default:return}}))})),{calls:n,outputIndexes:s,deltas:r}}createBatchSwap(e,t,a,n,s,i){const r=!e.parent?e.index:js.toChainedReference(this.getOutputRef(a,e.index)).toString(),c=t.address,l=[c,e.address],p=[d.from(n).mul(-1).toString(),js.isChainedReference(r)?o.toString():r],u=[{poolId:e.id,assetInIndex:1,assetOutIndex:0,amount:r,userData:"0x"}],y={sender:s,recipient:i,fromInternalBalance:!1,toInternalBalance:!1},b=[{index:l.map((e=>e.toLowerCase())).indexOf(c.toLowerCase()),key:js.toChainedReference(this.getOutputRef(a,t.index))}],f=js.encodeBatchSwap({swapType:kt.SwapExactIn,swaps:u,assets:l,funds:y,limits:p,deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:b});let m=p[0];const h=p[1],T=s===this.relayer?"0":h;return m=i===this.relayer?"0":m,[f,l,[m,T]]}createExitPool(e,t,a,n,i,r){const o=t.address,d=!e.parent?e.index:js.toChainedReference(this.getOutputRef(a,e.index)).toString(),c=[],l=[];e.children.forEach((e=>{c.push(e.address),l.push(e.address===o?n:"0")})),e.type===Xe.ComposableStable&&(c.push(e.address),l.push("0"));const p=new we(this.wrappedNativeAsset),[u,y]=p.sortTokens(c,l);let b=[];const f=u.map((e=>e.toLowerCase())).indexOf(e.address.toLowerCase());let m;b=-1===f?u:[...u.slice(0,f),...u.slice(f+1)],m=e.type===Xe.Weighted?z.exitExactBPTInForOneTokenOut(d,b.indexOf(o)):Z.exitExactBPTInForOneTokenOut(d,b.indexOf(o));const h=[{index:u.map((e=>e.toLowerCase())).indexOf(o.toLowerCase()),key:js.toChainedReference(this.getOutputRef(a,t.index))}],T=js.constructExitCall({poolId:e.id,poolKind:0,sender:i,recipient:r,outputReferences:h,exitPoolRequest:{},assets:u,minAmountsOut:y,userData:m,toInternalBalance:!1}),g=y.map((e=>js.isChainedReference(e)?"0":s.sub(e).toString())),I=js.isChainedReference(d)?"0":d;return[T,i===this.relayer?s.toString():I,r===this.relayer?[]:u,r===this.relayer?[]:g]}}class ji{constructor(e){this.yesterdaysPools=e}async last24h(e){let t;return this.yesterdaysPools&&(t=await this.yesterdaysPools.find(e.id)),e.totalSwapVolume?(null==t?void 0:t.totalSwapVolume)?parseFloat(e.totalSwapVolume)-parseFloat(t.totalSwapVolume):e.createTime&&Js(e.createTime)?parseFloat(e.totalSwapVolume):0:0}}var Xi=[{inputs:[{internalType:"contract IVault",name:"vault",type:"address"},{internalType:"contract IProtocolFeePercentagesProvider",name:"protocolFeeProvider",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[],name:"FactoryDisabled",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"pool",type:"address"}],name:"PoolCreated",type:"event"},{inputs:[{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"},{internalType:"contract IERC20[]",name:"tokens",type:"address[]"},{internalType:"uint256",name:"amplificationParameter",type:"uint256"},{internalType:"contract IRateProvider[]",name:"rateProviders",type:"address[]"},{internalType:"uint256[]",name:"tokenRateCacheDurations",type:"uint256[]"},{internalType:"bool[]",name:"exemptFromYieldProtocolFeeFlags",type:"bool[]"},{internalType:"uint256",name:"swapFeePercentage",type:"uint256"},{internalType:"address",name:"owner",type:"address"}],name:"create",outputs:[{internalType:"contract ComposableStablePool",name:"",type:"address"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"disable",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"}],name:"getActionId",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAuthorizer",outputs:[{internalType:"contract IAuthorizer",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCreationCode",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCreationCodeContracts",outputs:[{internalType:"address",name:"contractA",type:"address"},{internalType:"address",name:"contractB",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getPauseConfiguration",outputs:[{internalType:"uint256",name:"pauseWindowDuration",type:"uint256"},{internalType:"uint256",name:"bufferPeriodDuration",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getVault",outputs:[{internalType:"contract IVault",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"isDisabled",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"pool",type:"address"}],name:"isPoolFromFactory",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"}];class Ki{constructor(e){const{tokens:t}=Ut(e.chainId);this.wrappedNativeAsset=t.wrappedNativeAsset}create({factoryAddress:e,name:n,symbol:s,tokenAddresses:i,amplificationParameter:r,rateProviders:o,tokenRateCacheDurations:d,exemptFromYieldProtocolFeeFlags:c,swapFee:l,owner:p}){const u=xt(`${l}`),y=new we(this.wrappedNativeAsset),[b,f,m,h]=y.sortTokens(i,o,d,c),T=[n,s,b,r,f,m,h,u.toString(),p],g=new t(Xi),I=Xi.find((({name:e})=>"create"===e));if(!I)throw new $t(Gt.INTERNAL_ERROR_INVALID_ABI);const w=a.from(I);return{to:e,data:g.encodeFunctionData(w,T)}}buildInitJoin({joiner:e,poolId:t,poolAddress:a,tokensIn:n,amountsIn:s}){throw new Error("To be implemented")}}class Yi{constructor(e){const{tokens:t}=Ut(e.chainId);this.wrappedNativeAsset=t.wrappedNativeAsset}create({factoryAddress:e,name:n,symbol:s,tokenAddresses:i,weights:r,swapFee:o,owner:d}){const c=xt(`${o}`),l=new we(this.wrappedNativeAsset),[p,u]=l.sortTokens(i,r),y=[n,s,p,u,c.toString(),d],b=new t($.abi),f=$.abi.find((({name:e})=>"create"===e));if(!f)throw new $t(Gt.INTERNAL_ERROR_INVALID_ABI);const m=a.from(f);return{to:e,data:b.encodeFunctionData(m,y)}}buildInitJoin({joiner:e,poolId:t,tokensIn:a,amountsIn:n}){const s=new we(this.wrappedNativeAsset),[i,r]=s.sortTokens(a,n),o="joinPool",d={poolId:t,sender:e,recipient:e,joinPoolRequest:{assets:i,maxAmountsIn:r,userData:z.joinInit(r),fromInternalBalance:!1}},c=L.createInterface().encodeFunctionData(o,[d.poolId,d.sender,d.recipient,d.joinPoolRequest]);return{to:Mt,functionName:o,attributes:d,data:c}}}class Ji{constructor(e){this.networkConfig=e}of(e){switch(e){case"Weighted":return new Yi(this.networkConfig);case"Investment":case"LiquidityBootstrapping":case"Stable":case"MetaStable":case"StablePhantom":case"AaveLinear":case"ERC4626Linear":default:throw new $t(Gt.UNSUPPORTED_POOL_TYPE);case"ComposableStable":return new Ki(this.networkConfig)}}}class Zi{constructor(e){this.pool=e;const t=(e=>{switch(e){case Xe.Weighted:return z;case Xe.Stable:case Xe.MetaStable:case Xe.StablePhantom:case Xe.AaveLinear:case Xe.EulerLinear:case Xe.ERC4626Linear:case Xe.Element:case Xe.Gyro2:case Xe.Gyro3:return Z;case Xe.ComposableStable:return se}})(e.poolType);if(!t)throw"Pool type not supported";this.encoder=t}buildQueryJoinExactIn({sender:e=i,recipient:t=e,maxAmountsIn:a,minimumBPT:n=s,fromInternalBalance:r=!1}){const o=this.pool.tokensList.findIndex((e=>this.pool.id.includes(e))),d=[...this.pool.tokensList];o&&o>-1&&a.splice(o,1);const c=this.encoder.joinExactTokensInForBPTOut(a,n);return[this.pool.id,e,t,{assets:d,maxAmountsIn:a,userData:c,fromInternalBalance:r}]}buildQueryJoinExactOut({sender:e=i,recipient:t=e,maxAmountsIn:a=[],bptOut:n,tokenIn:s,fromInternalBalance:r=!1}){const o=this.pool.tokensList.indexOf(s),d=this.encoder.joinTokenInForExactBPTOut(n,o);return[this.pool.id,e,t,{assets:this.pool.tokensList,maxAmountsIn:a,userData:d,fromInternalBalance:r}]}buildQueryExitToSingleToken({sender:e=i,recipient:t=e,minAmountsOut:a=[],bptIn:n,tokenOut:s,toInternalBalance:r=!1}){const o=this.pool.tokensList.indexOf(s),d=this.encoder.exitExactBPTInForOneTokenOut(n,o);return[this.pool.id,e,t,{assets:this.pool.tokensList,minAmountsOut:a,userData:d,toInternalBalance:r}]}buildQueryExitProportionally({sender:e=i,recipient:t=e,minAmountsOut:a=[],bptIn:n,toInternalBalance:s=!1}){if(!this.encoder.exitExactBPTInForTokensOut)throw"Proportional exit not implemented";const r=this.encoder.exitExactBPTInForTokensOut(n);return[this.pool.id,e,t,{assets:this.pool.tokensList,minAmountsOut:a,userData:r,toInternalBalance:s}]}buildQueryExitExactOut({sender:e=i,recipient:t=e,minAmountsOut:a,maxBptIn:n=r,toInternalBalance:s=!1}){const o=this.pool.tokensList.findIndex((e=>this.pool.id.includes(e)));o&&o>-1&&a.splice(o,1);const d=this.encoder.exitBPTInForExactTokensOut(a,n);return[this.pool.id,e,t,{assets:this.pool.tokensList,minAmountsOut:a,userData:d,toInternalBalance:s}]}}class zi{constructor(e){this.liquidityGaugesRepository=e}async relativeWeight(e){const t=await this.liquidityGaugesRepository.findBy("poolId",e);return t?t.relativeWeight:0}async weekly(e){return Di()*await this.relativeWeight(e)}}const Qi=(e,t,a)=>{const n=e.tokens.filter((t=>!e.id.toLowerCase().includes(t.address.toLowerCase()))),s=n.findIndex((e=>e.address.toLowerCase()===t.toLowerCase()));if(-1==s)throw new Error("Token not found in pool");const i=n.map((e=>ot(e.balance,e.decimals))),r=d.from(a),o=i.map((e=>e.mul(r).div(i[s])));return{tokens:n.map((e=>e.address)),amounts:o.map((e=>e.toString()))}},er=(e,t)=>()=>{throw`${t} for poolType ${e} not implemented`};class tr{constructor(e,t){this.networkConfig=e,this.repositories=t,this.aprService=new Ri(this.repositories.pools,this.repositories.tokenPrices,this.repositories.tokenMeta,this.repositories.tokenYields,this.repositories.feeCollector,this.repositories.yesterdaysPools,this.repositories.liquidityGauges,this.repositories.feeDistributor),this.liquidityService=new Pa(t.pools,t.tokenPrices),this.joinService=new Wi(this.repositories.poolsOnChain,e),this.exitService=new Hi(this.repositories.poolsOnChain,e),this.feesService=new Fi(t.yesterdaysPools),this.volumeService=new ji(t.yesterdaysPools),this.poolFactory=new Ji(e),this.impermanentLossService=new Oi(t.tokenPrices,t.tokenHistoricalPrices),t.liquidityGauges&&(this.emissionsService=new zi(t.liquidityGauges)),this.proportionalAmounts=Qi}dataSource(){return this.repositories.pools}async apr(e){return this.aprService.apr(e)}async aprNextPeriod(e){return this.aprService.aprNextPeriod(e)}async impermanentLoss(e,t){return this.impermanentLossService.calcImpLoss(e,t)}async liquidity(e){return this.liquidityService.getLiquidity(e)}async generalisedJoin(e,t,a,n,s,i,r){return this.joinService.joinPool(e,t,a,n,s,i,r)}async generalisedExit(e,t,a,n,s){return this.exitService.exitPool(e,t,a,n,s)}async fees(e){return this.feesService.last24h(e)}async volume(e){return this.volumeService.last24h(e)}static wrap(e,t){let a,n,s;try{a=Sa.from(e.poolType),s={buildJoin:(t,n,s,r)=>a.join.buildJoin({joiner:t,pool:e,tokensIn:n,amountsIn:s,slippage:r,wrappedNativeAsset:i}),calcPriceImpact:async(t,n,s)=>a.priceImpactCalculator.calcPriceImpact(e,t,n,s),buildExitExactBPTIn:(t,n,s,r=!1,o)=>{if(a.exit.buildExitExactBPTIn)return a.exit.buildExitExactBPTIn({exiter:t,pool:e,bptIn:n,slippage:s,shouldUnwrapNativeAsset:r,wrappedNativeAsset:i,singleTokenMaxOut:o});throw"ExitExactBPTIn not supported"},buildExitExactTokensOut:(t,n,s,r)=>a.exit.buildExitExactTokensOut({exiter:t,pool:e,tokensOut:n,amountsOut:s,slippage:r,wrappedNativeAsset:i}),calcSpotPrice:(t,n)=>a.spotPriceCalculator.calcPoolSpotPrice(t,n,e),calcProportionalAmounts:(t,a)=>Qi(e,t,a)}}catch(t){"UNSUPPORTED_POOL_TYPE"!=t.code&&console.error(t),s={buildJoin:er(e.poolType,"buildJoin"),calcPriceImpact:er(e.poolType,"calcPriceImpact"),buildExitExactBPTIn:er(e.poolType,"buildExitExactBPTIn"),buildExitExactTokensOut:er(e.poolType,"buildExitExactTokensOut"),calcSpotPrice:er(e.poolType,"calcSpotPrice")}}try{n=new Zi(e),s={...s,buildQueryJoinExactIn:n.buildQueryJoinExactIn.bind(n),buildQueryJoinExactOut:n.buildQueryJoinExactOut.bind(n),buildQueryExitExactOut:n.buildQueryExitExactOut.bind(n),buildQueryExitToSingleToken:n.buildQueryExitToSingleToken.bind(n),buildQueryExitProportionally:n.buildQueryExitProportionally.bind(n)}}catch(t){s={...s,buildQueryJoinExactIn:er(e.poolType,"buildQueryJoinExactIn"),buildQueryJoinExactOut:er(e.poolType,"buildQueryJoinExactOut"),buildQueryExitExactOut:er(e.poolType,"buildQueryExitExactOut"),buildQueryExitToSingleToken:er(e.poolType,"buildQueryExitToSingleToken"),buildQueryExitProportionally:er(e.poolType,"buildQueryExitProportionally")}}const i=t.addresses.tokens.wrappedNativeAsset.toLowerCase();return{...e,...s}}async find(e){const t=await this.dataSource().find(e);if(t)return tr.wrap(t,this.networkConfig)}async findBy(e,t){if("id"==e)return this.find(t);if("address"==e){const e=await this.dataSource().findBy("address",t);if(!e)return;return tr.wrap(e,this.networkConfig)}throw`search by ${e} not implemented`}async all(){const e=await this.dataSource().all();return e?e.map((e=>tr.wrap(e,this.networkConfig))).filter((e=>e)):[]}async where(e){const t=await this.dataSource().where(e);if(!t)return[];return t.map((e=>tr.wrap(e,this.networkConfig))).filter((e=>e))}}const ar=new t(["function gauge_relative_weight(address gauge, uint timestamp) view returns (uint)","function gauge_relative_weight_write(address gauge, uint timestamp) returns (uint)"]);class nr{constructor(e,t,a){this.gaugeControllerAddress=t,this.multicall=hs(e,a)}async getRelativeWeights(e,t){const a=e.map((e=>[this.gaugeControllerAddress,ar.encodeFunctionData("gauge_relative_weight_write",[p(e),t||Math.floor(Date.now()/1e3)])])),[,n]=await this.multicall.aggregate(a);return e.reduce(((e,t,a)=>(e[t]||(e[t]=parseFloat(rt(n[a],18))),e)),{})}}class sr{async get(e){const t=await this.query(e);return(null==t?void 0:t.length)>0?t[0]:void 0}async find(e){return this.get({where:{id:e}})}async findBy(e,t){return this.get({where:{[String(e)]:t}})}async findAllBy(e,t,a=1e3,n=0){const s={where:{[String(e)]:t},first:a,skip:n};return this.query(s)}}class ir extends sr{constructor(e,t,a){super(),this.chainId=t,this.blockHeight=a,this.client=bs(e)}}class rr extends sr{constructor(e,t,a){super(),this.chainId=t,this.blockHeight=a,this.client=fs(e)}}class or extends rr{async query(e){e.orderBy||(e.orderBy=jn.Balance),e.orderDirection||(e.orderDirection=Zn.Desc),!e.block&&this.blockHeight&&(e.block={number:await this.blockHeight()});const{gaugeShares:t}=await this.client.GaugeShares(e);return t.map(this.mapType)}mapType(e){var t;return{id:e.id,balance:e.balance,userAddress:null===(t=e.user)||void 0===t?void 0:t.id,gauge:{id:e.gauge.id,poolId:e.gauge.poolId||void 0,isKilled:e.gauge.isKilled,totalSupply:e.gauge.totalSupply}}}async findByUser(e,t,a){return this.findAllBy(We.UserAddress,e,t,a)}async findByGauge(e,t,a){return this.findAllBy(We.GaugeId,e,t,a)}}const dr=new t(["function totalSupply() view returns (uint)","function working_supply() view returns (uint)","function reward_count() view returns (uint)","function reward_tokens(uint rewardIndex) view returns (address)","function reward_data(address rewardToken) view returns (tuple(address token, address distributor, uint period_finish, uint rate, uint last_update, uint integral) data)"]);class cr{constructor(e,t,a){this.chainId=t,this.multicall=hs(e,a)}async getTotalSupplies(e){const t=e.map((e=>[e,dr.encodeFunctionData("totalSupply",[])])),[,a]=await this.multicall.aggregate(t),n=a.map((e=>"0x"==e?"0x0":e));return e.reduce(((e,t,a)=>(e[t]||(e[t]=parseFloat(rt(n[a],18))),e)),{})}async getWorkingSupplies(e){const t=e.map((e=>[e,dr.encodeFunctionData("working_supply",[])])),[,a]=await this.multicall.aggregate(t),n=a.map((e=>"0x"==e?"0x0":e));return e.reduce(((e,t,a)=>(e[t]||(e[t]=parseFloat(rt(n[a],18))),e)),{})}async getRewardCounts(e){let t;if(248==this.chainId||9372==this.chainId||6343==this.chainId||4326==this.chainId){const a=e.map((e=>[e,dr.encodeFunctionData("reward_count",[])])),[,n]=await this.multicall.aggregate(a),s=n.map((e=>"0x"==e?"0x0":e));t=e.reduce(((e,t,a)=>(e[t]||(e[t]=parseInt(s[a])),e)),{})}else t=e.reduce(((e,t)=>(e[t]||(e[t]=1),e)),{});return t}async getRewardTokens(e,t){const a=t||await this.getRewardCounts(e),n=e.filter((e=>a[e]>0)),s=[0],i=n.map(((e,t)=>{const n=[];for(let t=0;t<a[e];t++)n.push([e,dr.encodeFunctionData("reward_tokens",[t])]);return s[t+1]=s[t]+a[e],n})).flat(),[,r]=await this.multicall.aggregate(i);return n.reduce(((e,t,a)=>{const n=s[a],i=s[a+1],o=[];for(let e=n;e<i;e++)o.push(dr.decodeFunctionResult("reward_tokens",r[e])[0]);return e[t]||(e[t]=o),e}),{})}async getRewardData(e,t){const a=t||await this.getRewardTokens(e),n=[0],s=Object.keys(a).map(((e,t)=>{const s=[];for(let t=0;t<a[e].length;t++)s.push([e,dr.encodeFunctionData("reward_data",[a[e][t]])]);return n[t+1]=n[t]+a[e].length,s})).flat(),[,i]=await this.multicall.aggregate(s),r=i.map((e=>dr.decodeFunctionResult("reward_data",e)[0]));return Object.keys(a).reduce(((e,t,s)=>{const i=n[s],o=a[t].reduce(((e,t,a)=>(e[t]||(e[t]=r[i+a]),e)),{});return e[t]||(e[t]=o),e}),{})}}class lr{constructor(e){this.gauges=[],this.client=fs(e)}async fetch(){const e=(await this.client.Pools({where:{preferentialGauge_not:null},first:1e3})).pools.map((e=>e.preferentialGauge));return this.gauges=e,this.gauges}async find(e){return 0==this.gauges.length&&await this.fetch(),this.gauges.find((t=>t.id==e))}async findBy(e,t){if(0==this.gauges.length&&await this.fetch(),"id"==e)return this.find(t);if("poolId"==e)return this.gauges.find((e=>e.poolId==t));if("poolAddress"==e)return this.gauges.find((e=>e.poolAddress==t));throw`search by ${e} not implemented`}}const pr=6048e5;class ur{constructor(e,t,a,n,s){this.chainId=n,this.workingSupplies={},this.workingSuppliesNextPeriod={},this.relativeWeights={},this.relativeWeightsNextPeriod={},this.rewardData={},a&&(this.gaugeController=new nr(t,a,s)),this.multicall=new cr(t,n,s),this.subgraph=new lr(e)}async fetch(){const e=await this.subgraph.fetch(),t=e.map((e=>e.id));if(248!=this.chainId&&9372!=this.chainId&&6343!=this.chainId&&4326!=this.chainId||(this.workingSupplies=await this.multicall.getWorkingSupplies(t)),this.gaugeController){this.relativeWeights=await this.gaugeController.getRelativeWeights(t);const e=Math.round(Math.floor((Date.now()+pr)/pr)*pr)/1e3;this.relativeWeightsNextPeriod=await this.gaugeController.getRelativeWeights(t,e)}let a=!1;return this.rewardData=e.reduce(((e,t)=>{var n;return e[n=t.id]||(e[n]=t.tokens?Object.fromEntries(t.tokens.map((e=>[e.id.split("-")[0],{distributor:"",last_update:d.from(0),integral:d.from(0),token:e.id.split("-")[0],decimals:e.decimals,rate:ot(e.rate||"0",e.decimals),period_finish:d.from(e.periodFinish||"0")}]))):{}),t.tokens&&t.tokens.length>0&&(a=!0),e}),{}),a||(this.rewardData=await this.multicall.getRewardData(t)),e.map(this.compose.bind(this))}async find(e){return this.gauges||(this.gauges=this.fetch()),(await this.gauges).find((t=>t.id==e))}async findBy(e,t){let a;if(this.gauges||(this.gauges=this.fetch()),"id"==e)return this.find(t);if("address"==e)return this.find(t);if("poolId"==e)a=(await this.gauges).find((e=>e.poolId==t));else{if("poolAddress"!=e)throw`search by ${e} not implemented`;a=(await this.gauges).find((e=>e.poolAddress==t))}return a}compose(e){return{id:e.id,address:e.id,name:e.symbol,poolId:e.poolId,poolAddress:e.poolAddress,totalSupply:parseFloat(e.totalSupply),workingSupply:this.workingSupplies[e.id],relativeWeight:this.relativeWeights[e.id],relativeWeightNextPeriod:this.relativeWeightsNextPeriod[e.id],rewardTokens:this.rewardData[e.id]}}}class yr{constructor(e,t){this.url=e,this.apiKey=t}async get(e){try{const t=this.toPayload(e),{data:a}=await h.post(this.url,t,{headers:{"x-api-key":this.apiKey}});if(a.errors)throw new Error(a.errors.map((e=>e.message)).join(","));return a.data}catch(e){throw console.error(e),e}return[]}toPayload(e){return JSON.stringify({query:H({query:e})})}}class br{constructor(e){var t,a;this.pools=[],this.skip=0,this.client=new yr(e.url,e.apiKey);this.query={args:Object.assign({},(null===(t=e.query)||void 0===t?void 0:t.args)||{chainId:4326,orderBy:"totalLiquidity",orderDirection:"desc",where:{swapEnabled:{eq:!0}}}),attrs:Object.assign({},(null===(a=e.query)||void 0===a?void 0:a.attrs)||{id:!0,address:!0})},delete this.query.args.skip}fetchFromCache(e){const t=(null==e?void 0:e.first)||10,a=(null==e?void 0:e.skip)||0,n=this.pools.slice(a,t+a);return this.skip=a+t,n}async fetch(e){if(this.pools.length>((null==e?void 0:e.first)||10)+((null==e?void 0:e.skip)||0))return this.fetchFromCache(e);this.nextToken&&(this.query.args.nextToken=this.nextToken),(null==e?void 0:e.first)&&(this.query.args.first=2*e.first);const t=new Bt(this.query.args).format(new vt),a=this.query.attrs;a.nextToken=!0;const n={pools:{__args:t,...a}},s=(await this.client.get(n)).pools;return this.nextToken=s.nextToken,this.pools=this.pools.concat(s.pools.map(this.format)),this.skip=this.pools.length,this.fetchFromCache(e)}async find(e){return 0==this.pools.length&&await this.fetch(),this.findBy("id",e)}async findBy(e,t){0==this.pools.length&&await this.fetch();const a=this.pools.find((a=>a[e]==t));if(a)return this.format(a)}format(e){var t,a,n,s;if(null===(t=e.apr)||void 0===t?void 0:t.rewardAprs.breakdown){const t=JSON.parse(null===(a=e.apr)||void 0===a?void 0:a.rewardAprs.breakdown);e.apr.rewardAprs.breakdown=t}if(null===(n=e.apr)||void 0===n?void 0:n.tokenAprs.breakdown){const t=JSON.parse(null===(s=e.apr)||void 0===s?void 0:s.tokenAprs.breakdown);e.apr.tokenAprs.breakdown=t}return e}}class fr{constructor(e,t={}){this.providers=e,this.currentProviderIdx=0,this.timeout=t.timeout||1e4}async fetch(e){return this.fallbackQuery("fetch",[e])}get currentProvider(){if(this.providers.length&&!(this.currentProviderIdx>=this.providers.length))return this.providers[this.currentProviderIdx]}async find(e){return this.fallbackQuery("find",[e])}async findBy(e,t){return this.fallbackQuery("findBy",[e,t])}async fallbackQuery(e,t){if(this.currentProviderIdx>=this.providers.length)throw new Error(`No working providers found ${this.currentProviderIdx}/${this.providers.length}`);let a;try{const n=this.providers[this.currentProviderIdx];a=await Promise.race([n[e].apply(n,t),new Promise(((e,t)=>setTimeout((()=>t(new Error("timeout"))),this.timeout)))])}catch(n){const s=n.message;"timeout"===s?console.error("Provider "+this.currentProviderIdx+" timed out, falling back to next provider"):console.error("Provider "+this.currentProviderIdx+" failed with error: ",s,", falling back to next provider"),this.currentProviderIdx++,a=await this.fallbackQuery.call(this,e,t)}return a}}class mr{constructor(e){this.pools=e}async find(e){return this.pools.find((t=>t.id.toLowerCase()===e.toLowerCase()))}async findBy(e,t){return this.pools.find((a=>a[e]===t))}async all(){return this.pools}async where(e){return(await this.all()).filter(e)}}class hr{constructor(e){var t,a;this.skip=0,this.client=bs(e.url),this.blockHeight=e.blockHeight,this.chainId=e.chainId;const n={orderBy:on.TotalLiquidity,orderDirection:en.Desc,where:{swapEnabled:{eq:!0}}},s=Object.assign({},(null===(t=e.query)||void 0===t?void 0:t.args)||n),i=Object.assign({},(null===(a=e.query)||void 0===a?void 0:a.attrs)||{});this.query={args:s,attrs:i}}async fetchDefault(){const{pool0:e,pool1000:t,pool2000:a}=await this.client.AllPools({where:{swapEnabled:!0},orderBy:on.TotalLiquidity,orderDirection:en.Desc,block:await this.block()});return[...e,...t,...a].map(this.mapType.bind(this))}async fetch(e){(null==e?void 0:e.skip)&&(this.query.args.skip=e.skip),this.blockHeight&&(this.query.args.block={number:await this.blockHeight()}),this.query.args.first=(null==e?void 0:e.first)||1e3;const t=new Bt(this.query.args).format(new Ot),{pools:a}=await this.client.Pools(t);return this.skip=((null==e?void 0:e.skip)||0)+a.length,a.map(this.mapType.bind(this))}async find(e){return await this.findBy("id",e)}async findBy(e,t){return this.pools||(this.pools=this.fetchDefault()),(await this.pools).find((a=>a[e]==t))}async all(){return this.pools||(this.pools=this.fetchDefault()),this.pools}async block(){return this.blockHeight?{number:await this.blockHeight()}:void 0}async where(e){return this.pools||(this.pools=this.fetchDefault()),(await this.pools).filter(e)}mapType(e){var t,a,n,s,i,r,o,d,c;return{id:e.id,name:e.name||"",address:e.address,chainId:this.chainId,poolType:e.poolType,poolTypeVersion:e.poolTypeVersion||1,swapFee:e.swapFee,swapEnabled:e.swapEnabled,protocolYieldFeeCache:e.protocolYieldFeeCache||"0",protocolSwapFeeCache:e.protocolSwapFeeCache||"0",amp:null!==(t=e.amp)&&void 0!==t?t:void 0,owner:null!==(a=e.owner)&&void 0!==a?a:void 0,factory:null!==(n=e.factory)&&void 0!==n?n:void 0,symbol:null!==(s=e.symbol)&&void 0!==s?s:void 0,tokens:(e.tokens||[]).map(this.mapToken.bind(this)),tokensList:e.tokensList,tokenAddresses:(e.tokens||[]).map((e=>e.address)),totalLiquidity:e.totalLiquidity,totalShares:e.totalShares,totalSwapFee:e.totalSwapFee,totalSwapVolume:e.totalSwapVolume,priceRateProviders:null!==(i=e.priceRateProviders)&&void 0!==i?i:void 0,createTime:e.createTime,mainIndex:null!==(r=e.mainIndex)&&void 0!==r?r:void 0,wrappedIndex:null!==(o=e.wrappedIndex)&&void 0!==o?o:void 0,totalWeight:e.totalWeight||"1",lowerTarget:null!==(d=e.lowerTarget)&&void 0!==d?d:"0",upperTarget:null!==(c=e.upperTarget)&&void 0!==c?c:"0"}}mapToken(e){const t=this.mapSubPools(e.token);return{...e,isExemptFromYieldProtocolFee:e.isExemptFromYieldProtocolFee||!1,token:t}}mapSubPools(e){let t=null;return e.pool&&(t={id:e.pool.id,address:e.pool.address,totalShares:e.pool.totalShares,poolType:e.pool.poolType,mainIndex:e.pool.mainIndex||0},(null==e?void 0:e.pool.tokens)&&(t.tokens=e.pool.tokens.map(this.mapSubPoolToken.bind(this)))),{pool:t,latestUSDPrice:e.latestUSDPrice||void 0}}mapSubPoolToken(e){return{address:e.address,decimals:e.decimals,symbol:e.symbol,balance:e.balance,priceRate:e.priceRate,weight:e.weight,isExemptFromYieldProtocolFee:e.isExemptFromYieldProtocolFee||void 0,token:e.token?this.mapSubPools(e.token):void 0}}}class Tr{constructor(e){this.skip=0,this.poolsSubgraph=new hr({url:e.url,chainId:e.chainId,blockHeight:e.blockHeight,query:e.query}),this.provider=e.provider,this.multicall=e.multicall,this.vault=e.vault}async fetchDefault(){const e=await this.poolsSubgraph.fetch();return await As(e,this.multicall,this.vault,this.provider)}async fetch(e){const t=await this.poolsSubgraph.fetch(e);return await As(t,this.multicall,this.vault,this.provider)}async find(e){return await this.findBy("id",e)}async findBy(e,t){return this.pools||(this.pools=this.fetchDefault()),(await this.pools).find((a=>a[e]==t))}async all(){return this.pools||(this.pools=this.fetchDefault()),this.pools}async where(e){return this.pools||(this.pools=this.fetchDefault()),(await this.pools).filter(e)}}class gr extends rr{async query(e){!e.block&&this.blockHeight&&(e.block={number:await this.blockHeight()});const{pools:t}=await this.client.PoolGauges(e);return t.map(this.mapType)}mapType(e){return e}}var Ir;!function(e){e.Pool="pool",e.Sender="sender"}(Ir||(Ir={}));class wr extends ir{async query(e){e.orderBy||(e.orderBy=Ja.Timestamp),e.orderDirection||(e.orderDirection=en.Asc),!e.block&&this.blockHeight&&(e.block={number:await this.blockHeight()});const{joinExits:t}=await this.client.JoinExits(e);return t.map(this.mapType)}mapType(e){return{id:e.id,userAddress:e.user.id,poolId:e.pool.id,timestamp:e.timestamp,type:e.type,amounts:e.amounts,tokens:e.pool.tokensList}}async findByUser(e,t,a){return this.findAllBy(Ir.Sender,e,t,a)}async findJoins(e,t){return this.query({where:{sender:e,pool:t,type:"Join"}})}async findExits(e,t){return this.query({where:{sender:e,pool:t,type:"Exit"}})}async findByPool(e,t,a){return this.findAllBy(Ir.Pool,e,t,a)}}class Er extends ir{async query(e){e.orderBy||(e.orderBy=nn.Balance),e.orderDirection||(e.orderDirection=en.Desc),!e.block&&this.blockHeight&&(e.block={number:await this.blockHeight()});const{poolShares:t}=await this.client.PoolShares(e);return t.map(this.mapType)}mapType(e){return{id:e.id,userAddress:e.userAddress.id,poolId:e.poolId.id,balance:e.balance}}async findByUser(e,t,a){return this.findAllBy(qe.UserAddress,e,t,a)}async findByPool(e,t,a){return this.findAllBy(qe.PoolId,e,t,a)}}class xr{constructor(e){this.tokens=e}async find(e){return this.tokens.find((t=>t.address.toLowerCase()===e.toLowerCase()))}async findBy(e,t){return this.tokens.find((a=>a[e]===t))}}class Ar{constructor(e){this.tokenPrices=Object.fromEntries(Object.entries(e).map((([e,t])=>[e.toLowerCase(),t])))}async find(e){const t=e.toLowerCase(),a=this.tokenPrices[t];if(a)return a}async findBy(e,t){if("address"==e)return this.find(t)}}class Sr{constructor(e,t=1){this.chainId=t,this.prices={},this.baseTokenAddresses=e.map(ht),this.urlBase=`${Lt[t].urls.priceUrl}/price/?vs_currencies=usd,eth`,this.debouncer=new It(this.fetch.bind(this),200)}fetch(e,{signal:t}={}){return e.length,h.get(this.url(e),{signal:t}).then((({data:e})=>e)).finally((()=>{e.length}))}fetchNative({signal:e}={}){let t;!function(e){e.ETH="ethereum",e.MATIC="matic-network",e.XDAI="xdai",e.OAS="oasys"}(t||(t={}));const a=t.OAS,n=this.url(["0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000"]);return h.get(n,{signal:e}).then((({data:e})=>e[a])).finally((()=>{}))}find(e){const t=e.toLowerCase();if(!this.prices[t]){if(0===Object.keys(this.prices).length)for(const e of this.baseTokenAddresses)this.prices[e]=this.debouncer.fetch(e).then((t=>t[e]));this.prices[t]=this.debouncer.fetch(t).then((e=>e[t]))}return this.prices[t]}async findBy(e,t){if("address"==e)return this.find(t)}platform(e){switch(e){case 1:case 5:case 42:case 31337:case 248:case 9372:case 6343:case 4326:case 16116:case 17117:return"ethereum";case 100:return"xdai";case 137:return"polygon-pos";case 42161:return"arbitrum-one"}return"3"}url(e){return`${this.urlBase}&contract_addresses=${e.join(",")}`}}class Pr{constructor(e=1){this.chainId=e,this.prices={},this.urlBase=`https://api.coingecko.com/api/v3/coins/${this.platform(e)}/contract/%TOKEN_ADDRESS%/market_chart/range?vs_currency=usd`}fetch(e,t,{signal:a}={}){const n=this.urlRange(e,t);return h.get(n,{signal:a}).then((({data:e})=>e)).finally((()=>{}))}async find(e){throw"Historic price requires point-in-time timestamp, please use findBy(address, timestamp)"}async findBy(e,t){const a=ht(e,this.chainId);return{usd:`${(await this.fetch(a,t)).prices[0][1]}`}}platform(e){switch(e){case 1:case 5:case 42:case 31337:case 248:case 9372:case 6343:case 4326:case 16116:case 17117:return"ethereum";case 137:return"polygon-pos";case 42161:return"arbitrum-one";case 100:return"xdai"}return"2"}urlRange(e,t){const a=t-3600,n=t+3600;return`${this.urlBase.replace("%TOKEN_ADDRESS%",e)}&from=${a}&to=${n}`}}class _r{constructor(e,t=1){this.subgraphUrl=e,this.chainId=t,this.prices={},this.debouncer=new It(this.fetch.bind(this),200)}async fetch(e,{signal:t}={}){return e.length,h.post(this.subgraphUrl,{variables:{addresses:e},query:"query($addresses: [String!]) {\n tokens(\n where: {\n id_in: $addresses\n }\n ) {\n address\n latestUSDPrice\n }\n }"},{signal:t}).then((e=>e.data.data)).then((({tokens:e})=>Object.fromEntries(e.map((e=>[e.address,{usd:e.latestUSDPrice||void 0}]))))).finally((()=>{e.length}))}async find(e){const t=ht(e,this.chainId);return this.prices[t]||(this.prices[t]=this.debouncer.fetch(t).then((e=>e[t]))),this.prices[t]}async findBy(e,t){if("address"==e)return this.find(t)}}class vr{constructor(e,t,a){this.coingeckoRepository=e,this.subgraphRepository=t,this.aaveRates=a}async find(e){let t;try{try{if(t=await this.coingeckoRepository.find(e),!(null==t?void 0:t.usd))throw new Error(`Price not found:${e}`)}catch(a){console.error(`Coingecko API error: ${e} ${a}`),t=await this.subgraphRepository.find(e)}}catch(e){console.error(e),t={eth:"0",usd:"0.1"}}return t}async findBy(e,t){if("address"===e)return this.find(t);throw`Token price search by ${e} not implemented`}}class Or{constructor(e,t){this.coingeckoRepository=e,this.aaveRates=t}async find(e){return this.findBy(e,Math.floor(Date.now()/1e3))}async findBy(e,t){const a=await this.coingeckoRepository.findBy(e,t),n=await this.aaveRates.getRate(e)||1;return a&&a.usd?{...a,usd:(parseFloat(a.usd)*n).toString()}:a}}const Br=new t(["function rate() view returns (uint256)"]);class kr{constructor(e,t,a){this.network=a,this.multicall=hs(e,t)}async fetch(e){const t=Object.values(dt[e]),a=t.map((e=>[e,Br.encodeFunctionData("rate",[])])),[,n]=await this.multicall.aggregate(a);return t.reduce(((e,t,a)=>(e[t]||(e[t]="0x"==n[a]?0:parseFloat(rt(n[a],27))),e)),{})}async getRate(e){return this.network!=ue.MAINNET&&this.network!=ue.POLYGON?1:Object.values(dt[this.network]).includes(e)?(this.rates||(this.rates=this.fetch(this.network)),(await this.rates)[e]):1}}const Dr=new t(["function getTokensDistributedInWeek(address token, uint timestamp) view returns (uint)"]),Nr=new t(["function totalSupply() view returns (uint)"]),Cr=new t(["function getRate() view returns (uint)"]);class Fr{constructor(e,t,a,n,s,i){this.feeDistributorAddress=t,this.balAddress=a,this.veBalAddress=n,this.bbAUsdAddress=s,this.multicall=hs(e,i)}async fetch(e){const t=this.getPreviousWeek(e),a=[[this.feeDistributorAddress,Dr.encodeFunctionData("getTokensDistributedInWeek",[p(this.balAddress),t])],[this.feeDistributorAddress,Dr.encodeFunctionData("getTokensDistributedInWeek",[p(this.bbAUsdAddress),t])],[this.veBalAddress,Nr.encodeFunctionData("totalSupply",[])],[this.bbAUsdAddress,Cr.encodeFunctionData("getRate",[])]],[,n]=await this.multicall.aggregate(a);return{balAmount:parseFloat(rt(n[0],18)),bbAUsdAmount:parseFloat(rt(n[1],18)),veBalSupply:parseFloat(rt(n[2],18)),bbAUsdPrice:parseFloat(rt(n[3],18)),balAddress:this.balAddress}}async multicallData(e){return this.data||(this.data=await this.fetch(e)),this.data}getPreviousWeek(e){const t=new Date(e);t.setUTCHours(0),t.setUTCMinutes(0),t.setUTCSeconds(0),t.setUTCMilliseconds(0);let a=t.getUTCDay()-4;return a<0&&(a+=7),a+=7,Math.floor(t.getTime()/1e3)-86400*a}}const Rr=new t(["function getProtocolFeesCollector() view returns (address)"]),Mr=new t(["function getSwapFeePercentage() view returns (uint)"]);let Lr;class Ur{constructor(e,t){this.provider=t,this.vault=new u(e,Rr,this.provider)}async fetch(){const e=await this.vault.getProtocolFeesCollector(),t=new u(e,Mr,this.provider),a=await t.getSwapFeePercentage();return parseFloat(rt(a,18))}async find(){return Lr||(Lr=this.fetch()),this.swapFeePercentage=await Lr,this.swapFeePercentage}async findBy(){return this.find()}}const Gr=new t(["function getSwapFeePercentage() view returns (uint)"]);let $r;class qr{constructor(e,t,a){this.protocolFeePercentagesProviderAddress=t,this.multicall=hs(e,a)}async fetch(){const e=[[this.protocolFeePercentagesProviderAddress,Gr.encodeFunctionData("getFeeTypePercentage",[0])],[this.protocolFeePercentagesProviderAddress,Gr.encodeFunctionData("getFeeTypePercentage",[2])]],[,t]=await this.multicall.aggregate(e);return{swapFee:parseFloat(rt(t[0],18)),yieldFee:parseFloat(rt(t[2],18))}}async getFees(){return $r||($r=this.fetch()),this.protocolFees=await $r,this.protocolFees}}const Wr={stETH:"0xae7ab96520de3a18e5e111b5eaab095312d7fe84",wstETH:"0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",arbitrumStEth:"0x5979d7b546e38e414f7e9822514be443a4800529"},Vr=async()=>{let e=0;try{const t=await h.get("https://lido-aprs-proxy.balancer.workers.dev/?network=1"),{data:a}=t.data;e=Math.round(100*parseFloat(a.smaApr))}catch(e){console.error("Failed to fetch stETH APR:",e)}return{[Wr.stETH]:e,[Wr.wstETH]:e,[Wr.arbitrumStEth]:e}},Hr={rETH:"0xae78736cd615f374d3085123a210448e74fc6393"},jr=async()=>{let e=0;try{const t=await h.get("https://api.rocketpool.net/api/apr"),{yearlyAPR:a}=t.data;e=Math.round(100*parseFloat(a))}catch(e){console.error("Failed to fetch APR:",e)}return{[Hr.rETH]:e}},Xr={stMATIC:"0x3a58a54c066fdc0f2d55fc9c89f0415c92ebf3c4"},Kr=async()=>{let e=0;try{const t=await h.get("https://lido-aprs-proxy.balancer.workers.dev/?network=137"),{apr:a}=t.data;e=Math.round(100*parseFloat(a))}catch(e){console.error("Failed to fetch stMATIC APR:",e)}return{[Xr.stMATIC]:e}},Yr={usdcUSDplus:"0x1aafc31091d93c3ff003cff5d2d8f7ba2e728425",usdcUSDplus2:"0x6933ec1ca55c06a894107860c92acdfd2dd8512f"},Jr=async()=>{let e=0;try{const{data:t}=await h.get("https://app.overnight.fi/api/balancer/week/apr");e=Math.round(1e4*parseFloat(t)/100)}catch(e){console.error("Failed to fetch USD+ APR:",e)}return Object.fromEntries(Object.values(Yr).map((t=>[t,e])))},Zr={sfrxETH:"0xac3e018457b222d93114458476f3e3416abbe38f"},zr=async()=>{let e=0;try{const t=await h.get("https://api.frax.finance/v2/frxeth/summary/latest"),{sfrxethApr:a}=t.data;e=Math.round(100*parseFloat(a))}catch(e){console.error("Failed to fetch APR:",e)}return{[Zr.sfrxETH]:e}},Qr={maticX:"0xfa68fb4628dff1028cfec22b4162fccd0d45efb6"},eo=async()=>{let e=0;try{const t=await h.get("https://generic-apr-proxy.balancer.workers.dev/?provider=stader"),{value:a}=t.data;e=Math.round(100*parseFloat(a))}catch(e){console.error("Failed to fetch APR:",e)}return{[Qr.maticX]:e}},to={qETH:"0x93ef1ea305d11a9b2a3ebb9bb4fcc34695292e7d"},ao=async()=>{let e=0;try{const t=await h.get("https://generic-apr-proxy.balancer.workers.dev/?provider=tranchess"),[{weeklyAveragePnlPercentage:a}]=t.data;e=Math.round(parseFloat(rt(d.from(a).mul(365).mul(1e4),18)))}catch(e){console.error("Failed to fetch qETH APR:",e)}return{[to.qETH]:e}},no={USDR:"0xaf0d9d65fc54de245cda37af3d18cbec860a4d4b"},so=async()=>{let e=0;try{const t=await h.get("https://generic-apr-proxy.balancer.workers.dev/?provider=usdr"),{usdr:a}=t.data;e=Math.round(100*parseFloat(a))}catch(e){console.error("Failed to fetch USDR APR:",e)}return{[no.USDR]:e}},io={rETH:"0x9559aaa82d9649c7a7b220e7c461d2e74c9a3593"},ro=async()=>{let e=0;try{const t=await h.get("https://drop-api.stafi.io/reth/v1/poolData/"),{stakeApr:a}=t.data.data;e=Math.round(100*parseFloat(a))}catch(e){console.error("Failed to fetch APR:",e)}return{[io.rETH]:e}},oo=new q("https://rpc.ankr.com/eth",1),co={getPoolsUI:new u("0x5954aB967Bc958940b7EB73ee84797Dc8a2AFbb9",[{inputs:[],name:"getPoolsUI",outputs:[{components:[{internalType:"uint256",name:"poolId",type:"uint256"},{internalType:"uint256",name:"stakedAmount",type:"uint256"},{components:[{internalType:"uint48",name:"startTimestampHour",type:"uint48"},{internalType:"uint48",name:"endTimestampHour",type:"uint48"},{internalType:"uint96",name:"rewardsPerHour",type:"uint96"},{internalType:"uint96",name:"capPerPosition",type:"uint96"}],internalType:"struct ApeCoinStaking.TimeRange",name:"currentTimeRange",type:"tuple"}],internalType:"struct ApeCoinStaking.PoolUI",name:"",type:"tuple"},{components:[{internalType:"uint256",name:"poolId",type:"uint256"},{internalType:"uint256",name:"stakedAmount",type:"uint256"},{components:[{internalType:"uint48",name:"startTimestampHour",type:"uint48"},{internalType:"uint48",name:"endTimestampHour",type:"uint48"},{internalType:"uint96",name:"rewardsPerHour",type:"uint96"},{internalType:"uint96",name:"capPerPosition",type:"uint96"}],internalType:"struct ApeCoinStaking.TimeRange",name:"currentTimeRange",type:"tuple"}],internalType:"struct ApeCoinStaking.PoolUI",name:"",type:"tuple"},{components:[{internalType:"uint256",name:"poolId",type:"uint256"},{internalType:"uint256",name:"stakedAmount",type:"uint256"},{components:[{internalType:"uint48",name:"startTimestampHour",type:"uint48"},{internalType:"uint48",name:"endTimestampHour",type:"uint48"},{internalType:"uint96",name:"rewardsPerHour",type:"uint96"},{internalType:"uint96",name:"capPerPosition",type:"uint96"}],internalType:"struct ApeCoinStaking.TimeRange",name:"currentTimeRange",type:"tuple"}],internalType:"struct ApeCoinStaking.PoolUI",name:"",type:"tuple"},{components:[{internalType:"uint256",name:"poolId",type:"uint256"},{internalType:"uint256",name:"stakedAmount",type:"uint256"},{components:[{internalType:"uint48",name:"startTimestampHour",type:"uint48"},{internalType:"uint48",name:"endTimestampHour",type:"uint48"},{internalType:"uint96",name:"rewardsPerHour",type:"uint96"},{internalType:"uint96",name:"capPerPosition",type:"uint96"}],internalType:"struct ApeCoinStaking.TimeRange",name:"currentTimeRange",type:"tuple"}],internalType:"struct ApeCoinStaking.PoolUI",name:"",type:"tuple"}],stateMutability:"view",type:"function"}],oo).getPoolsUI},lo={sApe:"0x7966c5bae631294d7cffcea5430b78c2f76db6fa"},po=async(e=1,t=co)=>{let a=0;try{const e=(await t.getPoolsUI())[0],n=e.stakedAmount,s=e.currentTimeRange.rewardsPerHour.mul(8760);a=Number(s.mul(1e4).div(n))}catch(e){console.error("Failed to fetch Tessera Ape Coin APR:",e)}return{[lo.sApe]:a}},uo={eUSDC:"0xeb91861f8a4e1c12333f42dce8fb0ecdc28da716",eDAI:"0xe025e3ca2be02316033184551d4d3aa22024d9dc",eUSDT:"0x4d19f33948b99800b6113ff3e83bec9b537c85d2",eFRAX:"0x5484451a88a35cd0878a1be177435ca8a0e4054e"},yo={[ue.MAINNET]:"https://api.thegraph.com/subgraphs/name/euler-xyz/euler-mainnet"},bo=async()=>{const e=ue.MAINNET,t={operationName:"getAssetsAPY",query:"\n query getAssetsAPY($eTokenAddress_in: [String!]) {\n assets(\n where: {\n eTokenAddress_in: $eTokenAddress_in\n }\n ) {\n eTokenAddress\n supplyAPY\n }\n }\n",variables:{eTokenAddress_in:Object.values(uo)}},a=await h.post(yo[e],t),{data:{assets:n}}=a.data,s={eUSDT:0,eDAI:0,eUSDC:0,eFRAX:0};return n.forEach((({eTokenAddress:e,supplyAPY:t})=>{const a=Object.entries(uo).filter((([,t])=>t.toLocaleLowerCase()===e.toLocaleLowerCase()))[0][0];s[a]=Math.round(1e4*parseFloat(rt(d.from(t),27)))})),{[uo.eUSDT]:s.eUSDT,[uo.eDAI]:s.eDAI,[uo.eUSDC]:s.eUSDC,[uo.eFRAX]:s.eFRAX}},fo=Object.fromEntries([...Object.values(Wr).map((e=>[e,Vr])),...Object.values(Xr).map((e=>[e,Kr])),...Object.values(ct).map((e=>[e,ft])),...Object.values(Yr).map((e=>[e,Jr])),...Object.values(Hr).map((e=>[e,jr])),...Object.values(Zr).map((e=>[e,zr])),...Object.values(Qr).map((e=>[e,eo])),...Object.values(to).map((e=>[e,ao])),...Object.values(no).map((e=>[e,so])),...Object.values(io).map((e=>[e,ro])),...Object.values(lo).map((e=>[e,po])),...Object.values(uo).map((e=>[e,bo]))]);class mo{constructor(e,t=fo){this.network=e,this.sources=t,this.yields={}}async fetch(e){const t=await this.sources[e](this.network);this.yields={...this.yields,...t}}async find(e){const t=e.toLocaleLowerCase();return Object.keys(this.sources).includes(t)&&!Object.keys(this.yields).includes(t)&&await this.fetch(t),this.yields[t]}async findBy(e,t){if("address"==e)return this.find(t)}}const ho=e=>`{\n blocks(first: 1, orderBy: timestamp, orderDirection: asc, where: { timestamp_gt: ${e} }) {\n number\n }\n}`,To=async(e,t)=>{const a={query:ho(t)},n=await h.post(e,a),{data:{blocks:s}}=n.data;return parseInt(s[0].number)};class go{constructor(e){this.endpoint=e,this.blocks={}}async find(e){if("dayAgo"==e){const e=""+(Math.floor(Date.now()/1e3)-86400);return this.blocks[e]||(this.blocks={...this.blocks,[e]:To(this.endpoint,e)}),this.blocks[e]}}async findBy(e="",t=""){}}var Io,wo,Eo=[{chainId:1,address:"0x8888801af4d980682e47f1a9036e589479e835c5",symbol:"mph"},{chainId:1,address:"0x27054b13b1b798b345b591a4d22e6562d47ea75a",symbol:"ast"},{chainId:1,address:"0x3301ee63fb29f863f2333bd4466acb46cd8323e6",symbol:"akita"},{chainId:1,address:"0x616e8bfa43f920657b3497dbf40d6b1a02d4608d",symbol:"aurabal"},{chainId:1,address:"0xc0c293ce456ff0ed870add98a0828dd4d2903dbf",symbol:"aura"},{chainId:1,address:"0x3472a5a71965499acd81997a54bba8d852c6e53d",symbol:"badger"},{chainId:1,address:"0xba100000625a3754423978a60c9317c58a424e3d",symbol:"bal"},{chainId:1,address:"0x804cdb9116a10bb78768d3252355a1b18067bf8f",symbol:"bb-a-dai"},{chainId:1,address:"0x9210f1204b5a24742eba12f710636d76240df3d0",symbol:"bb-a-usdc"},{chainId:1,address:"0x2bbf681cc4eb09218bee85ea2a5d3d13fa40fc0c",symbol:"bb-a-usdt"},{chainId:1,address:"0x7b50775383d3d6f0215a8f290f2c9e2eebbeceb2",symbol:"bb-a-usd"},{chainId:1,address:"0x2d94aa3e47d9d5024503ca8491fce9a2fb4da198",symbol:"bank"},{chainId:1,address:"0x0d8775f648430679a709e98d2b0cb6250d2887ef",symbol:"bat"},{chainId:1,address:"0xf17e65822b568b3903685a7c9f496cf7656cc6c2",symbol:"bico"},{chainId:1,address:"0x799ebfabe77a6e34311eeee9825190b9ece32824",symbol:"btrst"},{chainId:1,address:"0x514910771af9ca656af840dff83e8264ecf986ca",symbol:"link"},{chainId:1,address:"0x3506424f91fd33084466f402d5d97f05f8e3b4af",symbol:"chz"},{chainId:1,address:"0x41e5560054824ea6b0732e656e3ad64e20e94e45",symbol:"cvc"},{chainId:1,address:"0xc00e94cb662c3520282e6f5717214004a7f26888",symbol:"comp"},{chainId:1,address:"0xdef1ca1fb7fbcdc777520aa7f396b4e015f497ab",symbol:"cow"},{chainId:1,address:"0xd533a949740bb3306d119cc777fa900ba034cd52",symbol:"crv"},{chainId:1,address:"0x6b175474e89094c44da98b954eedeac495271d0f",symbol:"dai"},{chainId:1,address:"0xf2051511b9b121394fa75b8f7d4e7424337af687",symbol:"haus"},{chainId:1,address:"0x888888435fde8e7d4c54cab67f206e4199454c60",symbol:"dfx"},{chainId:1,address:"0x798d1be841a82a273720ce31c822c61a67a601c3",symbol:"digg"},{chainId:1,address:"0xf629cbd94d3791c9250152bd8dfbdf380e2a3b9c",symbol:"enj"},{chainId:1,address:"0xc18360217d8f7ab5e7c516566761ea12ce7f9d72",symbol:"ens"},{chainId:1,address:"0x4e15361fd6b4bb609fa63c81a2be19d873717870",symbol:"ftm"},{chainId:1,address:"0x956f47f50a910163d8bf957cf5846d573e7f87ca",symbol:"fei"},{chainId:1,address:"0xed1480d12be41d92f36f5f7bdd88212e381a3677",symbol:"fdt"},{chainId:1,address:"0x586aa273f262909eef8fa02d90ab65f5015e0516",symbol:"fiat"},{chainId:1,address:"0xde30da39c46104798bb5aa3fe8b9e0e1f348163f",symbol:"gtc"},{chainId:1,address:"0x900db999074d9277c5da2a43f252d74366230da0",symbol:"giv"},{chainId:1,address:"0x6810e776880c02933d47db1b9fc05908e5386b96",symbol:"gno"},{chainId:1,address:"0xba485b556399123261a5f9c95d413b4f93107407",symbol:"graviaura"},{chainId:1,address:"0x3ec8798b81485a254928b70cda1cf0a2bb0b74d7",symbol:"gro"},{chainId:1,address:"0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f",symbol:"snx"},{chainId:1,address:"0x5a98fcbea516cf06857215779fd812ca3bef1b32",symbol:"ldo"},{chainId:1,address:"0x6dea81c8171d0ba574754ef6f8b412f2ed88c54d",symbol:"lqty"},{chainId:1,address:"0x5f98805a4e8be255a32880fdec7f6728c6568ba0",symbol:"lusd"},{chainId:1,address:"0x965d79f1a1016b574a62986e13ca8ab04dfdd15c",symbol:"m2"},{chainId:1,address:"0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2",symbol:"mkr"},{chainId:1,address:"0xd084944d3c05cd115c09d072b9f44ba3e0e45921",symbol:"fold"},{chainId:1,address:"0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0",symbol:"matic"},{chainId:1,address:"0xa3bed4e1c75d00fa6f4e5e6922db7261b5e9acd2",symbol:"mta"},{chainId:1,address:"0x4b13006980acb09645131b91d259eaa111eaf5ba",symbol:"myc"},{chainId:1,address:"0x333a4823466879eef910a04d473505da62142069",symbol:"nation"},{chainId:1,address:"0xcfeaead4947f0705a14ec42ac3d44129e1ef3ed5",symbol:"note"},{chainId:1,address:"0x967da4048cd07ab37855c090aaf366e4ce1b9f48",symbol:"ocean"},{chainId:1,address:"0x64aa3364f17a4d01c6f1751fd97c2bd3d7e7f1d5",symbol:"ohm"},{chainId:1,address:"0xab846fb6c81370327e784ae7cbb6d6a6af6ff4bf",symbol:"pal"},{chainId:1,address:"0xcafe001067cdef266afb7eb5a286dcfd277f3de5",symbol:"psp"},{chainId:1,address:"0x68037790a0229e9ce6eaa8a99ea92964106c4703",symbol:"par"},{chainId:1,address:"0x45804880de22913dafe09f4980848ece6ecbaf78",symbol:"paxg"},{chainId:1,address:"0x89ab32156e46f46d02ade3fecbe5fc4243b9aaed",symbol:"pnt"},{chainId:1,address:"0x9992ec3cf6a55b00978cddf2b27bc6882d88d1ec",symbol:"poly"},{chainId:1,address:"0x43d4a3cd90ddd2f8f4f693170c9c8098163502ad",symbol:"d2d"},{chainId:1,address:"0xeb4c2781e4eba804ce9a9803c67d0893436bb27d",symbol:"renbtc"},{chainId:1,address:"0x408e41876cccdc0f92210600ef50372656052a38",symbol:"ren"},{chainId:1,address:"0xfb5453340c03db5ade474b27e68b6a9c6b2823eb",symbol:"robot"},{chainId:1,address:"0xd33526068d116ce69f19a9ee46f0bd304f21a51f",symbol:"rpl"},{chainId:1,address:"0xae78736cd615f374d3085123a210448e74fc6393",symbol:"reth"},{chainId:1,address:"0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6",symbol:"sbtc"},{chainId:1,address:"0x476c5e26a75bd202a9683ffd34359c0cc15be0ff",symbol:"srm"},{chainId:1,address:"0x35e78b3982e87ecfd5b3f3265b601c046cdbe232",symbol:"xai"},{chainId:1,address:"0x3affcca64c2a6f4e3b6bd9c64cd2c969efd1ecbe",symbol:"dsla"},{chainId:1,address:"0xf24d8651578a55b0c119b9910759a351a3458895",symbol:"sdbal"},{chainId:1,address:"0x11c1a6b3ed6bb362954b29d3183cfa97a0c806aa",symbol:"str"},{chainId:1,address:"0x8f693ca8d21b157107184d29d398a8d082b38b76",symbol:"data"},{chainId:1,address:"0x470ebf5f030ed85fc1ed4c2d36b9dd02e77cf1b7",symbol:"temple"},{chainId:1,address:"0xa36fdbbae3c9d55a1d67ee5821d53b50b63a1ab9",symbol:"temp"},{chainId:1,address:"0xdac17f958d2ee523a2206206994597c13d831ec7",symbol:"usdt"},{chainId:1,address:"0x9c4a4204b79dd291d6b6571c5be8bbcd0622f050",symbol:"tcr"},{chainId:1,address:"0x226f7b842e0f0120b7e194d05432b3fd14773a9d",symbol:"unn"},{chainId:1,address:"0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",symbol:"uni"},{chainId:1,address:"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",symbol:"usdc"},{chainId:1,address:"0x81f8f0bb1cb2a06649e51913a151f0e7ef6fa321",symbol:"vita"},{chainId:1,address:"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",symbol:"weth"},{chainId:1,address:"0xedb171c18ce90b633db442f2a6f72874093b49ef",symbol:"wampl"},{chainId:1,address:"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",symbol:"wbtc"},{chainId:1,address:"0xf203ca1769ca8e9e8fe1da9d147db68b6c919817",symbol:"wncg"},{chainId:1,address:"0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0",symbol:"wsteth"},{chainId:1,address:"0x79c71d3436f39ce382d0f58f1b011d88100b9d91",symbol:"xns"},{chainId:1,address:"0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e",symbol:"yfi"},{chainId:1,address:"0xbcca60bb61934080951369a648fb03df4f96263c",symbol:"ausdc"},{chainId:1,address:"0x028171bca77440897b824ca71d1c56cac55b68a3",symbol:"adai"},{chainId:1,address:"0x3ed3b47dd13ec9a98b44e6204a523e766b225811",symbol:"ausdt"},{chainId:137,address:"0x9c2c5fd7b07e95ee044ddeba0e97a665f142394f",symbol:"1inch"},{chainId:137,address:"0xd6df932a45c0f255f85145f286ea0b292b21c90b",symbol:"aave"},{chainId:137,address:"0xc3fdbadc7c795ef1d6ba111e06ff8f16a20ea539",symbol:"addy"},{chainId:137,address:"0xf84bd51eab957c2e7b7d646a3427c5a50848281d",symbol:"agar"},{chainId:137,address:"0x033d942a6b495c4071083f4cde1f17e986fe856c",symbol:"aga"},{chainId:137,address:"0x0e9b89007eee9c958c0eda24ef70723c2c93dd58",symbol:"amaticc"},{chainId:137,address:"0x034b2090b579228482520c589dbd397c53fc51cc",symbol:"vision"},{chainId:137,address:"0x2c89bbc92bd86f8075d1decc58c7f4e0107f286b",symbol:"avax"},{chainId:137,address:"0x49690541e3f6e933a9aa3cffee6010a7bb5b72d7",symbol:"axiav3"},{chainId:137,address:"0x9a71012b13ca4d3d0cdc72a177df3ef03b0e76a3",symbol:"bal"},{chainId:137,address:"0xdb7cb471dd0b49b29cab4a1c14d070f27216a0ab",symbol:"bank"},{chainId:137,address:"0xfbdd194376de19a88118e84e279b977f165d01b8",symbol:"bifi"},{chainId:137,address:"0xd6ca869a4ec9ed2c7e618062cdc45306d8dbbc14",symbol:"btc2x-fli-p"},{chainId:137,address:"0x53e0bca35ec356bd5dddfebbd1fc0fd03fabad39",symbol:"link"},{chainId:137,address:"0x172370d5cd63279efa6d502dab29171933a610af",symbol:"crv"},{chainId:137,address:"0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",symbol:"dai"},{chainId:137,address:"0x1d607faa0a51518a7728580c238d912747e71f7a",symbol:"data"},{chainId:137,address:"0x85955046df4668e1dd369d2de9f3aeb98dd2a369",symbol:"dpi"},{chainId:137,address:"0xe7804d91dfcde7f776c90043e03eaa6df87e6395",symbol:"dfx"},{chainId:137,address:"0xf28164a485b0b2c90639e47b0f377b4a438a16b1",symbol:"dquick"},{chainId:137,address:"0x45c32fa6df82ead1e2ef74d17b76547eddfaff89",symbol:"frax"},{chainId:137,address:"0x50b728d8d964fd00c2d0aad81718b71311fef68a",symbol:"snx"},{chainId:137,address:"0x72928d5436ff65e57f72d5566dcd3baedc649a88",symbol:"hdao"},{chainId:137,address:"0x3ad707da309f3845cd602059901e39c4dcd66473",symbol:"eth2x-fli-p"},{chainId:137,address:"0x4f025829c4b13df652f38abd2ab901185ff1e609",symbol:"ieth-fli-p"},{chainId:137,address:"0x340f412860da7b7823df372a2b59ff78b7ae6abc",symbol:"imatic-fli-p"},{chainId:137,address:"0xf287d97b6345bad3d88856b26fb7c0ab3f2c7976",symbol:"matic2x-fli-p"},{chainId:137,address:"0x130ce4e4f76c2265f94a961d70618562de0bb8d2",symbol:"ibtc-fli-p"},{chainId:137,address:"0x596ebe76e2db4470966ea395b0d063ac6197a8c5",symbol:"jrt"},{chainId:137,address:"0x3a58a54c066fdc0f2d55fc9c89f0415c92ebf3c4",symbol:"stmatic"},{chainId:137,address:"0xf501dd45a1198c2e1b5aef5314a68b9006d842e0",symbol:"mta"},{chainId:137,address:"0xeaecc18198a475c921b24b8a6c1c1f0f5f3f7ea0",symbol:"seed"},{chainId:137,address:"0xfe712251173a2cd5f5be2b46bb528328ea3565e1",symbol:"mvi"},{chainId:137,address:"0xa3fa99a148fa48d14ed51d610c367c61876997f1",symbol:"mimatic"},{chainId:137,address:"0xa486c6bc102f409180ccb8a94ba045d39f8fc7cb",symbol:"nex"},{chainId:137,address:"0xe2aa7db6da1dae97c5f5c6914d285fbfcc32a128",symbol:"par"},{chainId:137,address:"0x580a84c73811e1839f75d86d75d88cca0c241ff4",symbol:"qi"},{chainId:137,address:"0x831753dd7087cac61ab5644b308642cc1c33dc13",symbol:"quick"},{chainId:137,address:"0xb5c064f955d8e7f38fe0460c556a72987494ee17",symbol:"quick"},{chainId:137,address:"0x00e5646f60ac6fb446f621d146b6e1886f002905",symbol:"rai"},{chainId:137,address:"0x431cd3c9ac9fc73644bf68bf5691f4b83f9e104f",symbol:"rbw"},{chainId:137,address:"0xdbf31df14b66535af65aac99c32e9ea844e14501",symbol:"renbtc"},{chainId:137,address:"0x501ace9c35e60f03a2af4d484f49f9b1efde9f40",symbol:"solace"},{chainId:137,address:"0xfa68fb4628dff1028cfec22b4162fccd0d45efb6",symbol:"maticx"},{chainId:137,address:"0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a",symbol:"sushi"},{chainId:137,address:"0xdf7837de1f2fa4631d716cf2502f8b230f1dcc32",symbol:"tel"},{chainId:137,address:"0xe6469ba6d2fd6130788e0ea9c0a0515900563b59",symbol:"ust"},{chainId:137,address:"0xc2132d05d31c914a87c6611c10748aeb04b58e8f",symbol:"usdt"},{chainId:137,address:"0x5fe2b58c013d7601147dcdd68c143a77499f5531",symbol:"grt"},{chainId:137,address:"0xbbba073c31bf03b8acf7c28ef0738decf3695683",symbol:"sand"},{chainId:137,address:"0x2934b36ca9a4b31e633c5be670c8c8b28b6aa015",symbol:"thx"},{chainId:137,address:"0x2f800db0fdb5223b3c3f354886d907a671414a7f",symbol:"bct"},{chainId:137,address:"0x2e1ad108ff1d8c782fcbbb89aad783ac49586756",symbol:"tusd"},{chainId:137,address:"0x3809dcdd5dde24b37abe64a5a339784c3323c44f",symbol:"swap"},{chainId:137,address:"0x7fbc10850cae055b27039af31bd258430e714c62",symbol:"ubt"},{chainId:137,address:"0x2791bca1f2de4661ed88a30c99a7a9449aa84174",symbol:"usdc"},{chainId:137,address:"0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",symbol:"weth"},{chainId:137,address:"0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",symbol:"wmatic"},{chainId:137,address:"0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6",symbol:"wbtc"},{chainId:137,address:"0x24834bbec7e39ef42f4a75eaf8e5b6486d3f0e57",symbol:"lunc"},{chainId:137,address:"0xf153eff70dc0bf3b085134928daeea248d9b30d0",symbol:"xmark"},{chainId:42161,address:"0x9f20de1fc9b161b34089cbeae888168b44b03461",symbol:"arbis"},{chainId:42161,address:"0x040d1edc9569d4bab2d15287dc5a4f10f56a56b8",symbol:"bal"},{chainId:42161,address:"0x031d35296154279dc1984dcd93e392b1f946737b",symbol:"cap"},{chainId:42161,address:"0xf97f4df75117a78c1a5a0dbb814af92458539fb4",symbol:"link"},{chainId:42161,address:"0x354a6da3fcde098f8389cad84b0182725c6c91de",symbol:"comp"},{chainId:42161,address:"0xf4d48ce3ee1ac3651998971541badbb9a14d7234",symbol:"cream"},{chainId:42161,address:"0x11cdb42b0eb46d95f990bedd4695a6e3fa034978",symbol:"crv"},{chainId:42161,address:"0xda10009cbd5d07dd0cecc66161fc93d7c9000da1",symbol:"dai"},{chainId:42161,address:"0x8038f3c971414fd1fc220ba727f2d4a0fc98cb65",symbol:"dht"},{chainId:42161,address:"0xf0b5ceefc89684889e5f7e0a7775bd100fcd3709",symbol:"dusd"},{chainId:42161,address:"0x6c2c06790b3e3e3c38e12ee22f8183b37a13ee55",symbol:"dpx"},{chainId:42161,address:"0x32eb7902d4134bf98a28b963d26de779af92a212",symbol:"rdpx"},{chainId:42161,address:"0xc3ae0333f0f34aa734d5493276223d95b8f9cb37",symbol:"dxd"},{chainId:42161,address:"0xfc5a1a6eb076a2c7ad06ed22c90d7e710e35ad0a",symbol:"gmx"},{chainId:42161,address:"0xa0b862f60edef4452f25b4160f177db44deb6cf1",symbol:"gno"},{chainId:42161,address:"0xb965029343d55189c25a7f3e0c9394dc0f5d41b1",symbol:"ndx"},{chainId:42161,address:"0x539bde0d7dbd336b79148aa742883198bbf60342",symbol:"magic"},{chainId:42161,address:"0x4e352cf164e64adcbad318c3a1e222e9eba4ce42",symbol:"mcb"},{chainId:42161,address:"0x3f56e0c36d275367b8c502090edf38289b3dea0d",symbol:"mimatic"},{chainId:42161,address:"0x965772e0e9c84b6f359c8597c891108dcf1c5b1a",symbol:"pickle"},{chainId:42161,address:"0x6694340fc020c5e6b96567843da2df01b2ce1eb6",symbol:"stg"},{chainId:42161,address:"0xd4d42f0b6def4ce0383636770ef773390d85c61a",symbol:"sushi"},{chainId:42161,address:"0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9",symbol:"usdt"},{chainId:42161,address:"0x23a941036ae778ac51ab04cea08ed6e2fe103614",symbol:"grt"},{chainId:42161,address:"0xa72159fc390f0e3c6d415e658264c7c4051e9b87",symbol:"tcr"},{chainId:42161,address:"0x4d15a3a2286d883af0aa1b3f21367843fac63e07",symbol:"tusd"},{chainId:42161,address:"0xfa7f8980b0f1e64a2062791cc3b0871572f1f7f0",symbol:"uni"},{chainId:42161,address:"0xff970a61a04b1ca14834a43f5de4533ebddb5cc8",symbol:"usdc"},{chainId:42161,address:"0xa684cd057951541187f288294a1e1c2646aa2d24",symbol:"vsta"},{chainId:42161,address:"0x64343594ab9b56e99087bfa6f2335db24c2d1f17",symbol:"vst"},{chainId:42161,address:"0x82af49447d8a07e3bd95bd0d56f35241523fbab1",symbol:"weth"},{chainId:42161,address:"0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f",symbol:"wbtc"},{chainId:42161,address:"0x82e3a8f066a6989666b031d916c43672085b1582",symbol:"yfi"},{chainId:16116,address:"0x5a89E11Cb554E00c2f51C4bb7F05bc7Ab0Fa6351",symbol:"weth"},{chainId:9372,address:"0x5200000000000000000000000000000000000001",symbol:"weth"},{chainId:248,address:"0x5200000000000000000000000000000000000001",symbol:"weth"},{chainId:6343,address:"0xAba76Cdc5910F6627856EB75Bcce0171376999C7",symbol:"weth"},{chainId:4326,address:"0x4200000000000000000000000000000000000006",symbol:"weth"}];class xo{constructor(e,t,a){this.pools=new hr({url:e.urls.subgraph,chainId:e.chainId}),this.poolsOnChain=new Tr({url:e.urls.subgraph,chainId:e.chainId,provider:t,multicall:e.addresses.contracts.multicall,vault:e.addresses.contracts.vault,query:a}),this.poolShares=new Er(e.urls.subgraph,e.chainId),this.poolJoinExits=new wr(e.urls.subgraph,e.chainId),e.urls.gaugesSubgraph&&(this.poolGauges=new gr(e.urls.gaugesSubgraph,e.chainId),this.gaugeShares=new or(e.urls.gaugesSubgraph,e.chainId)),e.urls.blockNumberSubgraph&&(this.blockNumbers=new go(e.urls.blockNumberSubgraph));this.yesterdaysPools=new hr({url:e.urls.subgraph,chainId:e.chainId,blockHeight:async()=>{const e=await t.getBlockNumber();return Number(e)-5e3}});const n=Eo.filter((t=>t.chainId==e.chainId)).map((e=>e.address)),s=new Sr(n,e.chainId),i=new _r(e.urls.subgraph,e.chainId),r=new kr(e.addresses.contracts.multicall,t,e.chainId);this.tokenPrices=new vr(s,i,r);const o=new Pr(e.chainId);this.tokenHistoricalPrices=new Or(o,r),this.tokenMeta=new xr([]),e.urls.gaugesSubgraph&&(this.liquidityGauges=new ur(e.urls.gaugesSubgraph,e.addresses.contracts.multicall,e.addresses.contracts.gaugeController||"",e.chainId,t)),e.addresses.contracts.feeDistributor&&e.addresses.tokens.bal&&e.addresses.tokens.veBal&&e.addresses.tokens.bbaUsd&&(this.feeDistributor=new Fr(e.addresses.contracts.multicall,e.addresses.contracts.feeDistributor,e.addresses.tokens.bal,e.addresses.tokens.veBal,e.addresses.tokens.bbaUsd,t)),this.feeCollector=new Ur(e.addresses.contracts.vault,t),e.addresses.contracts.protocolFeePercentagesProvider&&(this.protocolFees=new qr(e.addresses.contracts.multicall,e.addresses.contracts.protocolFeePercentagesProvider,t)),this.tokenYields=new mo(e.chainId)}}class Ao{constructor(e,t=new Os(e),a=new Xs(e)){this.config=e,this.sor=t,this.subgraph=a,this.networkConfig=vs(e),this.provider=t.provider,this.data=new xo(this.networkConfig,t.provider,e.subgraphQuery),this.swaps=new Vs(this.config),this.relayer=new js(this.swaps),this.pricing=new Ks(e,this.swaps),this.pools=new tr(this.networkConfig,this.data),this.balancerContracts=new ii(this.networkConfig.addresses.contracts,t.provider),this.zaps=new vi(this.networkConfig.chainId)}get rpcProvider(){return this.sor.provider}get contracts(){return this.balancerContracts.contracts}}!function(e){e[e.Direct=0]="Direct",e[e.TokenIn=1]="TokenIn",e[e.TokenOut=2]="TokenOut",e[e.Middle=3]="Middle"}(Io||(Io={})),function(e){e[e.Swap=0]="Swap",e[e.BatchSwap=1]="BatchSwap",e[e.Join=2]="Join",e[e.Exit=3]="Exit"}(wo||(wo={}));const So={type:wo.BatchSwap,swaps:[],opRef:[],minOut:"0",assets:[],hasTokenIn:!1,hasTokenOut:!1,fromInternal:!1,toInternal:!1,limits:[],approveTokens:[],sender:"",receiver:""},Po=new t(ai);function _o(e,t){return e.some((e=>e.address.toLowerCase()===t.toLowerCase()))}function vo(e,t,a){return e!==N.SwapExactOut&&t.toLowerCase()!==i.toLowerCase()&&a.toLowerCase()!==i.toLowerCase()}function Oo(e,t){const a=t[e.assetOutIndex],n=ce(e.poolId);return a.toLowerCase()===n.toLowerCase()}function Bo(e,t){const a=t[e.assetInIndex],n=ce(e.poolId);return a.toLowerCase()===n.toLowerCase()}function ko(e,t,a){return t.some((t=>function(e,t,a){const n=e.find((e=>e.id===t.poolId));return"Weighted"===(null==n?void 0:n.poolType)&&[a[t.assetInIndex],a[t.assetOutIndex]].includes(n.address)}(e,t,a)))}function Do(e,t,a){let n={};var s;return e!==Io.TokenIn&&e!==Io.Middle||(s=a,n={index:t,key:js.toChainedReference(s)},a++),[n,a]}function No(e,t){return Ft(d.from(e),d.from(t)).toString()}function Co(e,t,a,n){let s=e.amount;return(a===Io.TokenOut||a===Io.Middle&&t===wo.Join||a===Io.Middle&&t===wo.Exit)&&(s=js.toChainedReference(n-1).toString()),s}function Fo(e,t,a,n){let s;return s=a===e&&n===t?Io.Direct:a===e?Io.TokenIn:n===t?Io.TokenOut:Io.Middle,s}function Ro(e,t){const a=function(e){const t=[],a=[],n=[];for(const s of e)s.type===wo.Exit||s.type===wo.Join?s.hasTokenIn?t.push(s):s.hasTokenOut?a.push(s):n.push(s):n.push(s);return[...t,...n,...a]}(e),n=function(e,t){const a=[];let n=g(So);n.assets=t,n.limits=Array(t.length).fill(d.from("0"));let s=!0,i={};for(const r of e)r.type===wo.Swap?(s&&(i=r,s=!1),r.isBptIn&&n.approveTokens.push(r.assets[r.swap.assetInIndex]),r.fromInternal===i.fromInternal&&r.toInternal===i.toInternal&&r.receiver===i.receiver&&r.sender===i.sender||n.swaps.length>0&&(a.push(n),n=g(So),n.assets=t,n.limits=Array(t.length).fill(d.from("0"))),n.swaps.push(r.swap),n.opRef.push(...r.opRef),n.fromInternal=r.fromInternal,n.toInternal=r.toInternal,n.sender=r.sender,n.receiver=r.receiver,r.hasTokenIn?(n.hasTokenIn=!0,n.limits[r.swap.assetInIndex]=n.limits[r.swap.assetInIndex].add(r.amountIn)):n.limits[r.swap.assetInIndex]=o,r.hasTokenOut&&(n.hasTokenOut=!0,n.limits[r.swap.assetOutIndex]=n.limits[r.swap.assetOutIndex].sub(r.minOut)),i=r):(n.swaps.length>0&&(a.push(n),n=g(So),n.assets=t,n.limits=Array(t.length).fill(d.from("0"))),a.push(r));return n.swaps.length>0&&a.push(n),a}(a,t);return n}function Mo(e,t,a,n,s,i,r,o){var d;const c=Fo(t,a,e.assetInIndex,e.assetOutIndex),l=Co(e,wo.Join,c,n),p=No(null!==(d=e.returnAmount)&&void 0!==d?d:"0",i),[u,y]=Do(c,e.assetOutIndex,n);let b=o,f=!0,m=!1;c!==Io.Direct&&c!==Io.TokenIn||(b=r,f=!1,m=!0);let h=o,T=!1;c!==Io.Direct&&c!==Io.TokenOut||(h=r,T=!0);return[{type:wo.Join,poolId:e.poolId,tokenIn:s[e.assetInIndex],bpt:s[e.assetOutIndex],opRef:u,minOut:p,amountIn:l,assets:s,actionStep:c,sender:b,receiver:h,fromInternal:f,hasTokenIn:m,hasTokenOut:T},y]}function Lo(e,t,a,n,s,i,r,o){var d;const c=Fo(t,a,e.assetInIndex,e.assetOutIndex),l=Co(e,wo.Exit,c,n),p=No(null!==(d=e.returnAmount)&&void 0!==d?d:"0",i),[u,y]=Do(c,e.assetOutIndex,n);let b=o,f=!1;c!==Io.Direct&&c!==Io.TokenIn||(b=r,f=!0);let m=!1,h=!0,T=o;c!==Io.Direct&&c!==Io.TokenOut||(T=r,h=!1,m=!0);return[{type:wo.Exit,poolId:e.poolId,tokenOut:s[e.assetOutIndex],bpt:s[e.assetInIndex],opRef:u.key?[u]:[],minOut:p,amountIn:l,assets:s,actionStep:c,sender:b,receiver:T,toInternal:h,hasTokenIn:f,hasTokenOut:m},y]}function Uo(e,t,a,n,s,i,r,o,d){var c;const l=Fo(t,a,e.assetInIndex,e.assetOutIndex),p=Co(e,wo.Swap,l,n);e.amount=p;const u=No(null!==(c=e.returnAmount)&&void 0!==c?c:"0",i),[y,b]=Do(l,e.assetOutIndex,n),f=l===Io.Direct||l===Io.TokenIn,m=l===Io.Direct||l===Io.TokenOut,h=_o(r,s[e.assetInIndex]);let T=!0;(f||h)&&(T=!1);let g,I,w=!0;(m||_o(r,s[e.assetOutIndex]))&&(w=!1),g=f?o:d,I=m?o:d;return[{type:wo.Swap,opRef:y.key?[y]:[],minOut:u,amountIn:p,assets:s,swap:e,hasTokenIn:f,hasTokenOut:m,fromInternal:T,toInternal:w,isBptIn:h,sender:g,receiver:I},b]}function Go(e,t,a){const n=e.tokensList,s=new we(a),[i]=s.sortTokens(n),r=t.tokenOut,o=i.findIndex((e=>e.toLowerCase()===r.toLowerCase())),d=Array(n.length).fill("0");d[o]=t.minOut;const c=t.amountIn,l={assets:i,minAmountsOut:d,userData:z.exitExactBPTInForOneTokenOut(c,o),toInternalBalance:t.toInternal,poolId:t.poolId,poolKind:0,sender:t.sender,recipient:t.receiver,outputReferences:t.opRef,exitPoolRequest:{}},p=js.constructExitCall(l),u=t.hasTokenOut?d[o]:"0";return[p,t.hasTokenIn?c:"0",u]}function $o(e,t,a){const n=e.tokensList,s=new we(a),[i]=s.sortTokens(n),r=t.tokenIn,o=i.findIndex((e=>e.toLowerCase()===r.toLowerCase())),d=Array(n.length).fill("0");d[o]=t.amountIn;const c=t.minOut,l=z.joinExactTokensInForBPTOut(d,c),p={poolId:t.poolId,sender:t.sender,recipient:t.receiver,kind:0,joinPoolRequest:{assets:i,maxAmountsIn:d,userData:l,fromInternalBalance:t.fromInternal},value:"0",outputReference:t.opRef.key?t.opRef.key.toString():"0"},u=js.encodeJoinPool(p),y=t.hasTokenOut?c:"0";return[u,t.hasTokenIn?d[o]:"0",y]}function qo(e,t,a){const n=[];for(const t of e.approveTokens){const e=js.encodeApproveVault(t,r.toString());n.push(e)}const s={sender:e.sender,recipient:e.receiver,fromInternalBalance:e.fromInternal,toInternalBalance:e.toInternal},i={swapType:kt.SwapExactIn,swaps:e.swaps,assets:e.assets,funds:s,limits:e.limits.map((e=>e.toString())),deadline:d.from(Math.ceil(Date.now()/1e3)+3600),value:"0",outputReferences:e.opRef},o=js.encodeBatchSwap(i);n.push(o);const c=e.assets.findIndex((e=>e.toLowerCase()===t.toLowerCase())),l=e.assets.findIndex((e=>e.toLowerCase()===a.toLowerCase()));return[n,e.hasTokenIn?e.limits[c].toString():"0",e.hasTokenOut?e.limits[l].abs().toString():"0"]}function Wo(e,t,a,n,s,i,r){const o=function(e,t,a,n,s,i,r,o){const d=n.findIndex((t=>t.toLowerCase()===e.toLowerCase())),c=n.findIndex((e=>e.toLowerCase()===t.toLowerCase())),l=[];let p=0,u={};for(const e of a)if(Oo(e,n)){const[t,a]=Mo(e,d,c,p,n,s,r,o);p=a,l.push(t),u=t}else{if(!Bo(e,n)){const t=e.amount,[a,y]=Uo(e,d,c,p,n,s,i,r,o);u.type===wo.Swap&&"0"===t&&(u.receiver=u.sender,u.toInternal=u.fromInternal,u.opRef=[],a.sender=u.receiver,a.fromInternal=u.fromInternal,a.amountIn="0",a.swap.amount="0"),p=y,l.push(a),u=a;continue}{const[t,a]=Lo(e,d,c,p,n,s,r,o);p=a,l.push(t),u=t}}return l}(e.tokenIn,e.tokenOut,e.swaps,e.tokenAddresses,i,t,a,n),c=Ro(o,e.tokenAddresses),l=[],p=[],u=[];r&&l.push(function(e,t){return js.encodeSetRelayerApproval(t,!0,e)}(r,n));for(const a of c){if(a.type===wo.Exit){const e=t.find((e=>e.id===a.poolId));if(void 0===e)throw new $t(Gt.NO_POOL_DATA);const[n,i,r]=Go(e,a,s);l.push(n),p.push(d.from(i)),u.push(d.from(r))}if(a.type===wo.Join){const e=t.find((e=>e.id===a.poolId));if(void 0===e)throw new $t(Gt.NO_POOL_DATA);const[n,i,r]=$o(e,a,s);l.push(n),p.push(d.from(i)),u.push(d.from(r))}if(a.type===wo.BatchSwap){const[t,n,s]=qo(a,e.tokenIn,e.tokenOut);l.push(...t),p.push(d.from(n)),u.push(d.from(s))}}!function(e,t,a,n){const s=e.reduce(((e=d.from(0),t)=>e.add(t))),i=t.reduce(((e=d.from(0),t)=>e.add(t))),r=i.sub(Ft(a.returnAmount,d.from(n)));if(!s.eq(a.swapAmount)||!r.lt("3"))throw new $t(Gt.RELAY_SWAP_AMOUNTS)}(p,u,e,i);return{to:n,data:Po.encodeFunctionData("multicall",[l]),rawCalls:l}}export{ye as APR_THRESHOLD,ge as AaveHelpers,kr as AaveRates,we as AssetHelpers,vt as BalancerAPIArgsFormatter,$t as BalancerError,Gt as BalancerErrorCode,xe as BalancerErrors,_e as BalancerMinterAuthorization,Ao as BalancerSDK,go as BlockNumberRepository,Pr as CoingeckoHistoricalPriceRepository,Sr as CoingeckoPriceRepository,se as ComposableStablePoolEncoder,ne as ComposableStablePoolExitKind,ae as ComposableStablePoolJoinKind,xo as Data,It as Debouncer,Ur as FeeCollectorRepository,Fr as FeeDistributorRepository,nr as GaugeControllerMulticallRepository,We as GaugeShareAttributes,or as GaugeSharesRepository,Bt as GraphQLArgsBuilder,Or as HistoricalPriceProvider,Pa as Liquidity,ur as LiquidityGaugeSubgraphRPCProvider,cr as LiquidityGaugesMulticallRepository,lr as LiquidityGaugesSubgraphRepository,Q as ManagedPoolEncoder,ue as Network,he as POOLS,je as PoolBalanceOpKind,$e as PoolGaugesAttributes,gr as PoolGaugesRepository,Ir as PoolJoinExitAttributes,wr as PoolJoinExitRepository,qe as PoolShareAttributes,Er as PoolSharesRepository,Ve as PoolSpecialization,Xe as PoolType,tr as Pools,br as PoolsBalancerAPIRepository,fr as PoolsFallbackRepository,mr as PoolsStaticRepository,Tr as PoolsSubgraphOnChainRepository,hr as PoolsSubgraphRepository,qr as ProtocolFeesProvider,js as Relayer,Se as RelayerAction,Pe as RelayerAuthorization,be as SHALLOW_COMPOSABLE_STABLE_BUFFER,Os as Sor,X as StablePhantomPoolJoinKind,Z as StablePoolEncoder,K as StablePoolExitKind,j as StablePoolJoinKind,Ar as StaticTokenPriceProvider,xr as StaticTokenProvider,Xs as Subgraph,Ot as SubgraphArgsFormatter,_r as SubgraphPriceRepository,kt as SwapType,Vs as Swaps,vr as TokenPriceProvider,mo as TokenYieldsRepository,He as UserBalanceOpKind,z as WeightedPoolEncoder,J as WeightedPoolExitKind,Y as WeightedPoolJoinKind,Ae as accountToAddress,Tt as addressMapIn,Ni as balEmissions,St as bn,Wo as buildRelayerCalls,vo as canUseJoinExit,Et as formatFixed,At as formatFromBigInt18,Dt as getLimitsForSlippage,ce as getPoolAddress,pe as getPoolNonce,le as getPoolSpecialization,_t as insert,te as isNormalizedWeights,Pt as isSameAddress,wt as parseFixed,Le as parsePoolInfo,xt as parseToBigInt18,ve as signPermit,ko as someJoinExit,de as splitPoolId,ee as toNormalizedWeights,ht as tokenAddressForPricing,mt as tokensToTokenPrices,gt as unwrapToken};
|
|
489
489
|
//# sourceMappingURL=index.esm.js.map
|