@myx-trade/sdk 1.0.2 → 1.0.3

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var Ia=Object.defineProperty;var Kt=s=>{throw TypeError(s)};var lt=(s,e)=>{for(var t in e)Ia(s,t,{get:e[t],enumerable:!0})};var Jt=(s,e,t)=>e.has(s)||Kt("Cannot "+t);var jt=(s,e,t)=>(Jt(s,e,"read from private field"),t?t.call(s):e.get(s)),Yt=(s,e,t)=>e.has(s)?Kt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),Xt=(s,e,t,n)=>(Jt(s,e,"write to private field"),n?n.call(s,t):e.set(s,t),t);var Et={};lt(Et,{claimBasePoolRebate:()=>Sn,claimBasePoolRebates:()=>Mn,deposit:()=>_n,getLpPrice:()=>Gn,getRewards:()=>Un,previewUserWithdrawData:()=>On,withdraw:()=>Ln,withdrawableLpAmount:()=>Bn});import{getContract as k}from"viem";var Zt=[{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"DifferentMarket",inputs:[{type:"bytes32",name:"fromPoolId"},{type:"bytes32",name:"toPoolId"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InsufficientQuoteIn",inputs:[{type:"uint256",name:"orderId"},{type:"uint256",name:"quoteIn"},{type:"uint256",name:"exchangeDelta"}]},{type:"error",name:"InvalidAmount",inputs:[{type:"uint256",name:"amount"}]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidLiquidityAmount",inputs:[]},{type:"error",name:"InvalidTpsl",inputs:[{type:"uint256",name:"orderId"}]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"NotReachedPrice",inputs:[{type:"uint256",name:"orderId"},{type:"uint256",name:"price"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"}]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"SamePoolMigration",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"SlippageExceeded",inputs:[{type:"uint256",name:"expected"},{type:"uint256",name:"actual"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"__ERC2771ContextUpgradeable_init",constant:!1,payable:!1,inputs:[{type:"address",name:"trustedForwarder_"}],outputs:[]},{type:"function",name:"addTpsl",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"poolType"},{type:"tuple[]",name:"tpslParams",components:[{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}]}],outputs:[]},{type:"function",name:"cancelTpsl",constant:!1,payable:!1,inputs:[{type:"uint256",name:"orderId"}],outputs:[]},{type:"function",name:"claimBasePoolRebate",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"bytes32",name:"poolId"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimBasePoolRebate",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimBasePoolRebates",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"bytes32[]",name:"poolIds"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimBasePoolRebates",constant:!1,payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimQuotePoolRebate",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimQuotePoolRebate",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"bytes32",name:"poolId"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimQuotePoolRebates",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"bytes32[]",name:"poolIds"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimQuotePoolRebates",constant:!1,payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"currentOrderId",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"depositBase",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"},{type:"tuple[]",name:"tpslParams",components:[{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}]}],outputs:[]},{type:"function",name:"depositBase",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"},{type:"tuple[]",name:"tpslParams",components:[{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}]}],outputs:[]},{type:"function",name:"depositQuote",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"},{type:"tuple[]",name:"tpslParams",components:[{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}]}],outputs:[]},{type:"function",name:"depositQuote",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"},{type:"tuple[]",name:"tpslParams",components:[{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}]}],outputs:[]},{type:"function",name:"executeTpsl",constant:!1,payable:!1,inputs:[{type:"uint256",name:"orderId"},{type:"uint256",name:"quoteInIfNecessary"},{type:"uint256",name:"minOut"}],outputs:[{type:"uint256",name:"baseOut"},{type:"uint256",name:"quoteOut"}]},{type:"function",name:"executeTpsl",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"uint256",name:"orderId"},{type:"uint256",name:"quoteInIfNecessary"},{type:"uint256",name:"minOut"}],outputs:[{type:"uint256",name:"baseOut"},{type:"uint256",name:"quoteOut"}]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getTpslData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint256",name:"orderId"}],outputs:[{type:"tuple",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"poolType"},{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}]},{type:"function",name:"getUserTpslOrderIds",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"user"}],outputs:[{type:"uint256[]"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"isTrustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"forwarder"}],outputs:[{type:"bool"}]},{type:"function",name:"migrateLiquidity",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"fromPoolId"},{type:"bytes32",name:"toPoolId"},{type:"uint256",name:"amount"},{type:"uint256",name:"minLpOut"}]}],outputs:[]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"trustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"withdrawBase",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"}]}],outputs:[]},{type:"function",name:"withdrawBase",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"}]}],outputs:[]},{type:"function",name:"withdrawQuote",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"}]}],outputs:[]},{type:"function",name:"withdrawQuote",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"}]}],outputs:[]}];import{createPublicClient as Aa,fallback as Ca,http as on}from"viem";var j=(r=>(r[r.LINEA_SEPOLIA=59141]="LINEA_SEPOLIA",r[r.LINEA_MAINNET=59144]="LINEA_MAINNET",r[r.ARB_TESTNET=421614]="ARB_TESTNET",r[r.ARB_MAINNET=42161]="ARB_MAINNET",r[r.BSC_TESTNET=97]="BSC_TESTNET",r[r.BSC_MAINNET=56]="BSC_MAINNET",r))(j||{});var xa=[421614,59141,97,42161,59144,56];function Ne(s){return!!s&&xa.includes(s)}var Y=10;var H={42161:130n,421614:130n,59144:130n,59141:130n,56:150n,97:150n};var en={chainId:59141,chainInfo:{explorer:"https://sepolia.lineascan.build/",explorerOfTX:"https://sepolia.lineascan.build/tx/",publicJsonRPCUrl:["https://rpc.sepolia.linea.build","https://linea-sepolia.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"],label:"Linea Sepolia",logoUrl:"",faucetUrl:"",chainSymbol:"Linea",gasPriceRatio:1.3,gasLimitRatio:1.2,gasAmountRatio:2,gasFeeReservedForCollateral:(.525+1)*Y,nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18}}};var tn={chainId:421614,chainInfo:{privateJsonRPCUrl:"",publicJsonRPCUrl:["https://sepolia-rollup.arbitrum.io/rpc"],label:" Arbitrum Sepolia",chainSymbol:"Arb Sepolia",explorer:"https://sepolia.arbiscan.io/",explorerOfTX:"https://sepolia.arbiscan.io/tx/",faucetUrl:"https://bwarelabs.com/faucets/arbitrum-sepolia",logoUrl:"",gasPriceRatio:1.5,gasLimitRatio:1.3,gasAmountRatio:2,gasFeeReservedForCollateral:(.055+1)*Y,nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18}}};var nn={chainId:97,chainInfo:{privateJsonRPCUrl:"",publicJsonRPCUrl:["https://bsc-testnet-dataseed.bnbchain.org"],label:"BNB Chain Testnet",chainSymbol:"BNB Chain Testnet",explorer:"https://testnet.bscscan.com/",explorerOfTX:"https://testnet.bscscan.com/tx/",faucetUrl:"https://docs.bnbchain.org/bnb-smart-chain/developers/faucet/",logoUrl:"",gasPriceRatio:1.5,gasLimitRatio:1.3,gasAmountRatio:2,gasFeeReservedForCollateral:(5e-4+1)*Y,nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18}}};var an={chainId:59144,chainInfo:{label:"Linea Mainnet",explorer:"https://lineascan.build/",logoUrl:"",explorerOfTX:"https://lineascan.build/tx/",publicJsonRPCUrl:["https://rpc.linea.build/","https://linea.blockpi.network/v1/rpc/public","https://1rpc.io/linea","https://rpc.linea.build"],chainSymbol:"Linea",gasPriceRatio:1.3,gasLimitRatio:1.2,gasAmountRatio:2,gasFeeReservedForCollateral:(.525+.35)*Y,nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18}}};var sn={chainId:42161,chainInfo:{privateJsonRPCUrl:"",publicJsonRPCUrl:["https://arb1.arbitrum.io/rpc"],label:" Arbitrum One",chainSymbol:"Arbitrum One",explorer:"https://arbiscan.io/",explorerOfTX:"https://arbiscan.io/tx/",logoUrl:"",gasPriceRatio:1.5,gasLimitRatio:1.3,gasAmountRatio:2,gasFeeReservedForCollateral:(.055+.175)*Y,nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18}}};var rn={chainId:56,chainInfo:{privateJsonRPCUrl:"",publicJsonRPCUrl:["https://bsc-dataseed.bnbchain.org"],label:"BNB Chain",chainSymbol:"BNB Chain",explorer:"https://bscscan.com/",explorerOfTX:"https://bscscan.com/tx/",faucetUrl:"https://docs.bnbchain.org/bnb-smart-chain/developers/faucet/",logoUrl:"",gasPriceRatio:1.5,gasLimitRatio:1.3,gasAmountRatio:2,gasFeeReservedForCollateral:(5e-4+1)*Y,nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18}}};var C={59141:en.chainInfo,421614:tn.chainInfo,97:nn.chainInfo,59144:an.chainInfo,42161:sn.chainInfo,56:rn.chainInfo};function be(s){let e=C[s];if(!e)throw new Error(`Could not find information with chain id ${s}`);return e}var mt={};function wa(s){if(!mt[s]){let e=be(s),t=[...e.privateJsonRPCUrl?[e.privateJsonRPCUrl]:[],...Array.isArray(e.publicJsonRPCUrl)?[...e.publicJsonRPCUrl]:[]].filter(Boolean);if(t.length===0)throw new Error(`${s} has no jsonRPCUrl configured`);mt[s]={id:s,name:e.label||`Chain ${s}`,nativeCurrency:e.nativeCurrency,rpcUrls:{default:{http:t}}}}return mt[s]}var yt={};function h(s){if(!yt[s]){let e=be(s),t=[...e.privateJsonRPCUrl?[e.privateJsonRPCUrl]:[],...Array.isArray(e.publicJsonRPCUrl)?[...e.publicJsonRPCUrl]:[]].filter(Boolean);if(t.length===0)throw new Error(`${s} has no jsonRPCUrl configured`);let n=t.length===1?on(t[0]):Ca(t.map(a=>on(a)));yt[s]=Aa({chain:wa(s),transport:n})}return yt[s]}var pn=null;function _e(s){pn=s}async function N(s){let e=pn;if(!e?.hasSigner())throw new Error("No signer: call auth({ signer }) or auth({ walletClient })");return e.getViemWalletClient(s)}var ft=[{type:"constructor",payable:!1,inputs:[]},{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"BaseFeeNotSoldOut",inputs:[]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidBaseToken",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"LPNotFullyMinted",inputs:[]},{type:"error",name:"MarketNotExist",inputs:[{type:"bytes32",name:"marketId"}]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"PoolExists",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"PoolNotExist",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"PositionNotEmpty",inputs:[]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"error",name:"UnexpectedPoolState",inputs:[]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"benchPool",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"string",name:"remark"}]}],outputs:[]},{type:"function",name:"checkPoolExists",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"bool"}]},{type:"function",name:"deployPool",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"marketId"},{type:"address",name:"baseToken"}]}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getMarketPool",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"address",name:"asset"}],outputs:[{type:"tuple",components:[{type:"bytes32",name:"marketId"},{type:"bytes32",name:"poolId"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"state"},{type:"address",name:"basePoolToken"},{type:"address",name:"quotePoolToken"},{type:"uint16",name:"maxPriceDeviation"},{type:"bool",name:"compoundEnabled"},{type:"uint64",name:"windowCapUsd"},{type:"address",name:"poolVault"},{type:"address",name:"tradingVault"}]}]},{type:"function",name:"getPairToken",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"}]},{type:"function",name:"getPool",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"tuple",components:[{type:"bytes32",name:"marketId"},{type:"bytes32",name:"poolId"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"state"},{type:"address",name:"basePoolToken"},{type:"address",name:"quotePoolToken"},{type:"uint16",name:"maxPriceDeviation"},{type:"bool",name:"compoundEnabled"},{type:"uint64",name:"windowCapUsd"},{type:"address",name:"poolVault"},{type:"address",name:"tradingVault"}]}]},{type:"function",name:"getPoolMarket",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"bytes32",name:"marketId"},{type:"tuple",components:[{type:"address",name:"quoteToken"},{type:"uint32",name:"baseReserveRatio"},{type:"uint32",name:"quoteReserveRatio"},{type:"uint64",name:"oracleFeeUsd"},{type:"uint64",name:"oracleRefundFeeUsd"},{type:"uint128",name:"poolPrimeThreshold"},{type:"uint128",name:"executionFee"},{type:"uint128",name:"maxExecutionFee"},{type:"uint128",name:"forwardFee"},{type:"uint128",name:"maxForwardFee"}]}]},{type:"function",name:"getPoolMarketExecutionFee",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256",name:"executionFee"}]},{type:"function",name:"getPoolMarketForwardFee",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256",name:"forwardFee"}]},{type:"function",name:"getPoolMarketId",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"bytes32",name:"marketId"}]},{type:"function",name:"getPoolRiskTier",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint8"}]},{type:"function",name:"getPoolVault",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"address"}]},{type:"function",name:"getPools",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32[]",name:"pools"}]},{type:"function",name:"getTradingVault",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"address"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"isPoolAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"addr"}],outputs:[{type:"bool"}]},{type:"function",name:"perBenchPool",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"string",name:"remark"}]}],outputs:[]},{type:"function",name:"primePool",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"referencePrice"}]}],outputs:[]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"reprimePool",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"}]}],outputs:[]},{type:"function",name:"trenchPool",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"bytes32",name:"oracleFeedId"},{type:"uint32",name:"oracleDecimals"},{type:"uint8",name:"oracleType"},{type:"uint16",name:"maxPriceDeviation"},{type:"uint8",name:"riskTier"},{type:"uint64",name:"windowCapUsd"}]}],outputs:[]},{type:"function",name:"updatePoolCompoundEnabled",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"bool",name:"enabled"}]}],outputs:[]},{type:"function",name:"updatePoolPriceDeviations",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint16",name:"maxPriceDeviation"}]}],outputs:[]},{type:"function",name:"updatePoolRiskTiers",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"riskTier"}]}],outputs:[]},{type:"function",name:"updatePoolWindowCaps",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint64",name:"windowCapUsd"}]}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]}];var Q=[{inputs:[{internalType:"string",name:"name_",type:"string"},{internalType:"string",name:"symbol_",type:"string"},{internalType:"uint8",name:"decimals_",type:"uint8"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[{internalType:"string",name:"str",type:"string"}],name:"StringTooLong",type:"error"},{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:[],name:"EIP712DomainChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!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:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"burn",outputs:[],stateMutability:"nonpayable",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:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",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:[{internalType:"address",name:"account",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"mint",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:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],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:[],name:"renounceOwnership",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:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"}];var gt=[{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InsufficientOutputAmount",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"PoolNotActive",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"PoolNotExist",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SafeCastOverflowedUintToInt",inputs:[{type:"uint256",name:"value"}]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"QuotePoolProfitDistributed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"amount",indexed:!1},{type:"uint256",name:"genesisAmount",indexed:!1},{type:"uint256",name:"price",indexed:!1},{type:"uint256",name:"exchangeRate",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"EXCHANGE_RATE_PRECISION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"POOL_TOKEN_DECIMALS",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint8"}]},{type:"function",name:"REBATE_INDEX_PRECISION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"claimUserRebate",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256",name:"rebateOut"}]},{type:"function",name:"claimUserRebates",constant:!1,payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256[]",name:"rebateOut"}]},{type:"function",name:"deposit",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256",name:"amountOut"}]},{type:"function",name:"distribute",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amount"},{type:"uint256",name:"genesisAmount"},{type:"uint256",name:"price"}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getExchangeRate",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256"}]},{type:"function",name:"getExchangeRate",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getPoolData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"tuple",components:[{type:"uint256",name:"genesisRebateIndex"}]}]},{type:"function",name:"getPoolTokenPrice",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"getUserData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"}],outputs:[{type:"tuple",components:[{type:"uint256",name:"index"},{type:"uint256",name:"accrued"}]}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"pendingUserRebates",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewLpAmountOut",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"quoteAmountIn"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewPoolTokenPrice",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewQuoteAmountOut",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"lpAmountIn"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewUserWithdrawData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"lpAmountIn"},{type:"address",name:"user"},{type:"uint256",name:"price"}],outputs:[{type:"uint256",name:"quoteAmountOut"}]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"updatePool",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"oraclePrice"}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"withdraw",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256",name:"amountOut"},{type:"uint256",name:"rebateOut"}]},{type:"function",name:"withdrawableLpAmount",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]}];var bt=[{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"ExceedMaxProfit",inputs:[]},{type:"error",name:"ExceedMinOutputAmount",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InsufficientOutputAmount",inputs:[]},{type:"error",name:"InsufficientReturnAmount",inputs:[{type:"uint256",name:"expected"},{type:"uint256",name:"received"}]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"PoolNotActive",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"PoolNotCompoundable",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"PoolNotExist",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SafeCastOverflowedUintToInt",inputs:[{type:"uint256",name:"value"}]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"BasePoolProfitDistributed",inputs:[{type:"bytes32",name:"poolId",indexed:!0},{type:"uint256",name:"baseAmount",indexed:!1},{type:"uint256",name:"quoteAmount",indexed:!1},{type:"uint256",name:"price",indexed:!1},{type:"uint256",name:"exchangeRate",indexed:!1},{type:"uint256",name:"rebateIndex",indexed:!1},{type:"uint256",name:"genesisRebateIndex",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolProfitExchanged",inputs:[{type:"bytes32",name:"poolId",indexed:!0},{type:"uint256",name:"baseIn",indexed:!1},{type:"uint256",name:"quoteOut",indexed:!1},{type:"uint256",name:"price",indexed:!1},{type:"address",name:"recipient",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolRebateIndexUpdated",inputs:[{type:"bytes32",name:"poolId",indexed:!0},{type:"uint256",name:"unexchangedProfits",indexed:!1},{type:"uint256",name:"oldIndex",indexed:!1},{type:"uint256",name:"newIndex",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"EXCHANGE_RATE_PRECISION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"POOL_TOKEN_DECIMALS",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint8"}]},{type:"function",name:"REBATE_INDEX_PRECISION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"claimUserRebate",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256",name:"rebateOut"}]},{type:"function",name:"claimUserRebates",constant:!1,payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256[]",name:"rebateOut"}]},{type:"function",name:"deposit",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256",name:"amountOut"}]},{type:"function",name:"distribute",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"},{type:"uint256",name:"genesisAmount"},{type:"uint256",name:"price"}],outputs:[]},{type:"function",name:"exchangeProfit",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"baseIn"},{type:"uint256",name:"minQuoteOut"},{type:"address",name:"recipient"},{type:"bytes",name:"data"}],outputs:[{type:"uint256",name:"quoteOut"}]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getExchangeRate",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256"}]},{type:"function",name:"getExchangeRate",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"getExchangeableProfit",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256",name:"baseIn"},{type:"uint256",name:"quoteOut"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getPoolData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"tuple",components:[{type:"uint256",name:"rebateIndex"},{type:"uint256",name:"genesisRebateIndex"},{type:"uint256",name:"exchangeableProfits"}]}]},{type:"function",name:"getPoolTokenPrice",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"getUserData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"}],outputs:[{type:"tuple",components:[{type:"uint256",name:"index"},{type:"uint256",name:"genesisIndex"},{type:"uint256",name:"accrued"},{type:"uint256",name:"genesisAccrued"}]}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"pendingUserRebates",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"uint256",name:"price"}],outputs:[{type:"uint256",name:"rebates"},{type:"uint256",name:"genesisRebates"}]},{type:"function",name:"previewBaseAmountOut",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"lpAmountIn"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewExchangeableProfit",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256",name:"baseIn"},{type:"uint256",name:"quoteOut"}]},{type:"function",name:"previewLpAmountOut",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"baseAmountIn"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewPoolTokenPrice",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewUserWithdrawData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"lpAmountIn"},{type:"address",name:"user"},{type:"uint256",name:"price"}],outputs:[{type:"uint256",name:"baseAmountOut"},{type:"uint256",name:"rebateAmount"}]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"updatePool",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"oraclePrice"}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"withdraw",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256",name:"amountOut"},{type:"uint256",name:"rebateOut"}]},{type:"function",name:"withdrawableLpAmount",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]}];var O=[{type:"constructor",payable:!1,inputs:[]},{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ECDSAInvalidSignature",inputs:[]},{type:"error",name:"ECDSAInvalidSignatureLength",inputs:[{type:"uint256",name:"length"}]},{type:"error",name:"ECDSAInvalidSignatureS",inputs:[{type:"bytes32",name:"s"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"ExpiredFeeData",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidFeeRate",inputs:[]},{type:"error",name:"InvalidFeeTier",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidParameter",inputs:[]},{type:"error",name:"NoRebateToClaim",inputs:[]},{type:"error",name:"NotActiveBroker",inputs:[{type:"address",name:"broker"}]},{type:"error",name:"NotBrokerSigner",inputs:[{type:"address",name:"signer"}]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotOrderOwner",inputs:[]},{type:"error",name:"NotPositionOwner",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"OwnableInvalidOwner",inputs:[{type:"address",name:"owner"}]},{type:"error",name:"OwnableUnauthorizedAccount",inputs:[{type:"address",name:"account"}]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"error",name:"UnsupportedAssetClass",inputs:[{type:"uint8",name:"assetClass"}]},{type:"error",name:"UnsupportedFeeTier",inputs:[{type:"uint8",name:"tier"}]},{type:"event",anonymous:!1,name:"BrokerStatusUpdated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"bool",name:"isActive",indexed:!1}]},{type:"event",anonymous:!1,name:"EIP712DomainChanged",inputs:[]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"OwnershipTransferStarted",inputs:[{type:"address",name:"previousOwner",indexed:!0},{type:"address",name:"newOwner",indexed:!0}]},{type:"event",anonymous:!1,name:"OwnershipTransferred",inputs:[{type:"address",name:"previousOwner",indexed:!0},{type:"address",name:"newOwner",indexed:!0}]},{type:"event",anonymous:!1,name:"RebateClaimed",inputs:[{type:"address",name:"user",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"SignerUpdated",inputs:[{type:"address",name:"signer",indexed:!1},{type:"bool",name:"isSigner",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"event",anonymous:!1,name:"UserFeeDataReset",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"signer",indexed:!1},{type:"uint256",name:"epoch",indexed:!1}]},{type:"event",anonymous:!1,name:"UserFeeDataUpdated",inputs:[{type:"address",name:"broker",indexed:!0},{type:"address",name:"signer",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"uint256",name:"epoch",indexed:!1},{type:"uint8",name:"tier",indexed:!1},{type:"address",name:"referrer",indexed:!1},{type:"uint32",name:"totalReferralRebatePct",indexed:!1},{type:"uint32",name:"referrerRebatePct",indexed:!1}]},{type:"function",name:"FEE_TYPEHASH",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"__ERC2771ContextUpgradeable_init",constant:!1,payable:!1,inputs:[{type:"address",name:"trustedForwarder_"}],outputs:[]},{type:"function",name:"acceptOwnership",constant:!1,payable:!1,inputs:[],outputs:[]},{type:"function",name:"activeFeeTiers",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"}],outputs:[{type:"uint256[]"}]},{type:"function",name:"activeSpecialFeeTierList",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"}],outputs:[{type:"uint256[]"}]},{type:"function",name:"addressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"batchSetSpecialFeeTiers",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"feeTier"},{type:"int32",name:"makerFeeRate"},{type:"uint32",name:"takerFeeRate"}]}],outputs:[]},{type:"function",name:"batchUpdateFeeTiers",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"feeTier"},{type:"tuple",name:"addOnFeeRate",components:[{type:"uint32",name:"takerFeeRate"},{type:"uint32",name:"makerFeeRate"}]}]}],outputs:[]},{type:"function",name:"cancelOrder",constant:!1,payable:!1,inputs:[{type:"uint256",name:"orderId"}],outputs:[]},{type:"function",name:"cancelOrders",constant:!1,payable:!1,inputs:[{type:"uint256[]",name:"orderIds"}],outputs:[]},{type:"function",name:"claimRebate",constant:!1,payable:!1,inputs:[{type:"address",name:"token"}],outputs:[]},{type:"function",name:"claimRebates",constant:!1,payable:!1,inputs:[{type:"address[]",name:"tokens"}],outputs:[]},{type:"function",name:"currentFeeDataEpoch",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"domainSeparatorV4",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"eip712Domain",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes1",name:"fields"},{type:"string",name:"name"},{type:"string",name:"version"},{type:"uint256",name:"chainId"},{type:"address",name:"verifyingContract"},{type:"bytes32",name:"salt"},{type:"uint256[]",name:"extensions"}]},{type:"function",name:"getAddOnFeeTier",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"feeTier"}],outputs:[{type:"uint32",name:"takerFeeRate"},{type:"uint32",name:"makerFeeRate"}]},{type:"function",name:"getBaseFeeRate",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint8",name:"assetClass"}],outputs:[{type:"tuple",name:"baseFeeRate",components:[{type:"uint32",name:"takerFeeRate"},{type:"uint32",name:"makerFeeRate"}]}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getSpecialFeeTier",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"feeTier"}],outputs:[{type:"int32",name:"makerFeeRate"},{type:"uint32",name:"takerFeeRate"}]},{type:"function",name:"getUserFeeDataDigest",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"user"},{type:"uint64",name:"nonce"},{type:"uint64",name:"deadline"},{type:"tuple",name:"feeData",components:[{type:"uint8",name:"tier"},{type:"address",name:"referrer"},{type:"uint32",name:"totalReferralRebatePct"},{type:"uint32",name:"referrerRebatePct"}]}],outputs:[{type:"bytes32",name:"digest"}]},{type:"function",name:"getUserFeeRate",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"user"},{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"}],outputs:[{type:"uint32",name:"takerFeeRate"},{type:"int32",name:"makerFeeRate"},{type:"uint32",name:"baseTakerFeeRate"},{type:"uint32",name:"baseMakerFeeRate"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"_addressManager"},{type:"address",name:"owner"},{type:"string",name:"_brokerName"},{type:"address[]",name:"brokerSigners"},{type:"uint8[]",name:"assetClasses"},{type:"tuple[]",name:"baseFeeRates",components:[{type:"uint32",name:"takerFeeRate"},{type:"uint32",name:"makerFeeRate"}]}],outputs:[]},{type:"function",name:"isActive",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bool"}]},{type:"function",name:"isTrustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"forwarder"}],outputs:[{type:"bool"}]},{type:"function",name:"name",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"onBrokerFee",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"address",name:"token"},{type:"uint256",name:"feeAmount"}],outputs:[{type:"uint256",name:"totalReferralRebate"},{type:"uint256",name:"referrerRebate"},{type:"address",name:"referrer"}]},{type:"function",name:"owner",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"pendingOwner",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"placeOrderWithPosition",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"bytes32",name:"positionId"},{type:"tuple",name:"depositParams",components:[{type:"address",name:"token"},{type:"uint256",name:"amount"}]},{type:"tuple",name:"orderParams",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"orderType"},{type:"uint8",name:"triggerType"},{type:"uint8",name:"operation"},{type:"uint8",name:"direction"},{type:"uint256",name:"collateralAmount"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"uint8",name:"timeInForce"},{type:"bool",name:"postOnly"},{type:"uint16",name:"slippagePct"},{type:"uint16",name:"leverage"},{type:"uint256",name:"tpSize"},{type:"uint256",name:"tpPrice"},{type:"uint256",name:"slSize"},{type:"uint256",name:"slPrice"}]}],outputs:[]},{type:"function",name:"placeOrderWithSalt",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"uint64",name:"userPositionSalt"},{type:"tuple",name:"depositParams",components:[{type:"address",name:"token"},{type:"uint256",name:"amount"}]},{type:"tuple",name:"orderParams",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"orderType"},{type:"uint8",name:"triggerType"},{type:"uint8",name:"operation"},{type:"uint8",name:"direction"},{type:"uint256",name:"collateralAmount"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"uint8",name:"timeInForce"},{type:"bool",name:"postOnly"},{type:"uint16",name:"slippagePct"},{type:"uint16",name:"leverage"},{type:"uint256",name:"tpSize"},{type:"uint256",name:"tpPrice"},{type:"uint256",name:"slSize"},{type:"uint256",name:"slPrice"}]}],outputs:[]},{type:"function",name:"placeOrdersWithPosition",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple",name:"depositParams",components:[{type:"address",name:"token"},{type:"uint256",name:"amount"}]},{type:"bytes32[]",name:"positionIds"},{type:"tuple[]",name:"orderParams",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"orderType"},{type:"uint8",name:"triggerType"},{type:"uint8",name:"operation"},{type:"uint8",name:"direction"},{type:"uint256",name:"collateralAmount"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"uint8",name:"timeInForce"},{type:"bool",name:"postOnly"},{type:"uint16",name:"slippagePct"},{type:"uint16",name:"leverage"},{type:"uint256",name:"tpSize"},{type:"uint256",name:"tpPrice"},{type:"uint256",name:"slSize"},{type:"uint256",name:"slPrice"}]}],outputs:[]},{type:"function",name:"placeOrdersWithSalt",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple",name:"depositParams",components:[{type:"address",name:"token"},{type:"uint256",name:"amount"}]},{type:"uint64[]",name:"userPositionSalts"},{type:"tuple[]",name:"orderParams",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"orderType"},{type:"uint8",name:"triggerType"},{type:"uint8",name:"operation"},{type:"uint8",name:"direction"},{type:"uint256",name:"collateralAmount"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"uint8",name:"timeInForce"},{type:"bool",name:"postOnly"},{type:"uint16",name:"slippagePct"},{type:"uint16",name:"leverage"},{type:"uint256",name:"tpSize"},{type:"uint256",name:"tpPrice"},{type:"uint256",name:"slSize"},{type:"uint256",name:"slPrice"}]}],outputs:[]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"renounceOwnership",constant:!1,payable:!1,inputs:[],outputs:[]},{type:"function",name:"resetAllUserFeeData",constant:!1,payable:!1,inputs:[],outputs:[]},{type:"function",name:"setSigner",constant:!1,payable:!1,inputs:[{type:"address",name:"signer"},{type:"bool",name:"isSigner"}],outputs:[]},{type:"function",name:"setSpecialFeeTier",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"feeTier"},{type:"int32",name:"makerFeeRate"},{type:"uint32",name:"takerFeeRate"}]}],outputs:[]},{type:"function",name:"setUserFeeData",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"user"},{type:"uint64",name:"nonce"},{type:"uint64",name:"deadline"},{type:"tuple",name:"feeData",components:[{type:"uint8",name:"tier"},{type:"address",name:"referrer"},{type:"uint32",name:"totalReferralRebatePct"},{type:"uint32",name:"referrerRebatePct"}]},{type:"bytes",name:"signature"}]}],outputs:[]},{type:"function",name:"setUserSpecialFeeTier",constant:!1,payable:!1,inputs:[{type:"address",name:"user"},{type:"uint8",name:"feeTier"}],outputs:[]},{type:"function",name:"supportedAssetClasses",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256[]"}]},{type:"function",name:"transferOwnership",constant:!1,payable:!1,inputs:[{type:"address",name:"newOwner"}],outputs:[]},{type:"function",name:"trustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"updateBaseFeeRates",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"uint8",name:"assetClass"},{type:"bool",name:"isEnable"},{type:"tuple",name:"baseFeeRate",components:[{type:"uint32",name:"takerFeeRate"},{type:"uint32",name:"makerFeeRate"}]}]}],outputs:[]},{type:"function",name:"updateBrokerStatus",constant:!1,payable:!1,inputs:[{type:"bool",name:"active"}],outputs:[]},{type:"function",name:"updateFeeTier",constant:!1,payable:!1,inputs:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"feeTier"},{type:"tuple",name:"feeRate",components:[{type:"uint32",name:"takerFeeRate"},{type:"uint32",name:"makerFeeRate"}]}],outputs:[]},{type:"function",name:"updateOrder",constant:!1,payable:!1,inputs:[{type:"tuple",name:"depositParams",components:[{type:"address",name:"token"},{type:"uint256",name:"amount"}]},{type:"tuple",name:"params",components:[{type:"uint256",name:"orderId"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"tuple",name:"tpsl",components:[{type:"uint256",name:"tpSize"},{type:"uint256",name:"tpPrice"},{type:"uint256",name:"slSize"},{type:"uint256",name:"slPrice"}]}]}],outputs:[]},{type:"function",name:"updatePriceAndAdjustCollateral",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"tuple",name:"depositParams",components:[{type:"address",name:"token"},{type:"uint256",name:"amount"}]},{type:"bytes32",name:"positionId"},{type:"int256",name:"adjustAmount"}],outputs:[]},{type:"function",name:"updateUserFeeData",constant:!1,payable:!1,inputs:[{type:"address",name:"user"},{type:"tuple",name:"feeData",components:[{type:"uint8",name:"tier"},{type:"address",name:"referrer"},{type:"uint32",name:"totalReferralRebatePct"},{type:"uint32",name:"referrerRebatePct"}]}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"userFeeData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint256",name:"userFeeDataEpoch"},{type:"address",name:"user"}],outputs:[{type:"uint8",name:"tier"},{type:"address",name:"referrer"},{type:"uint32",name:"totalReferralRebatePct"},{type:"uint32",name:"referrerRebatePct"}]},{type:"function",name:"userNonces",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"user"}],outputs:[{type:"uint64",name:"nonce"}]},{type:"function",name:"userRebates",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"user"},{type:"address",name:"token"}],outputs:[{type:"uint256",name:"rebateAmount"}]}];var It=[{type:"constructor",payable:!1,inputs:[]},{type:"error",name:"ERC20InsufficientAllowance",inputs:[{type:"address",name:"spender"},{type:"uint256",name:"allowance"},{type:"uint256",name:"needed"}]},{type:"error",name:"ERC20InsufficientBalance",inputs:[{type:"address",name:"sender"},{type:"uint256",name:"balance"},{type:"uint256",name:"needed"}]},{type:"error",name:"ERC20InvalidApprover",inputs:[{type:"address",name:"approver"}]},{type:"error",name:"ERC20InvalidReceiver",inputs:[{type:"address",name:"receiver"}]},{type:"error",name:"ERC20InvalidSender",inputs:[{type:"address",name:"sender"}]},{type:"error",name:"ERC20InvalidSpender",inputs:[{type:"address",name:"spender"}]},{type:"error",name:"InsufficientBalance",inputs:[{type:"address",name:"account"},{type:"uint256",name:"balance"},{type:"uint256",name:"needed"}]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"event",anonymous:!1,name:"Approval",inputs:[{type:"address",name:"owner",indexed:!0},{type:"address",name:"spender",indexed:!0},{type:"uint256",name:"value",indexed:!1}]},{type:"event",anonymous:!1,name:"GenesisShareBurned",inputs:[{type:"address",name:"account",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"GenesisShareMinted",inputs:[{type:"address",name:"account",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"Transfer",inputs:[{type:"address",name:"from",indexed:!0},{type:"address",name:"to",indexed:!0},{type:"uint256",name:"value",indexed:!1}]},{type:"function",name:"addressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"allowance",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"owner"},{type:"address",name:"spender"}],outputs:[{type:"uint256"}]},{type:"function",name:"approve",constant:!1,payable:!1,inputs:[{type:"address",name:"spender"},{type:"uint256",name:"value"}],outputs:[{type:"bool"}]},{type:"function",name:"balanceOf",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"}],outputs:[{type:"uint256"}]},{type:"function",name:"burnFrom",constant:!1,payable:!1,inputs:[{type:"address",name:"from"},{type:"uint256",name:"amount"}],outputs:[]},{type:"function",name:"decimals",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint8"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"_addressManager"},{type:"bytes32",name:"_poolId"},{type:"address",name:"_underlyingToken"},{type:"string",name:"name"},{type:"string",name:"symbol"}],outputs:[]},{type:"function",name:"mint",constant:!1,payable:!1,inputs:[{type:"address",name:"to"},{type:"uint256",name:"amount"}],outputs:[]},{type:"function",name:"name",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"poolId",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"symbol",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"totalGenesisShare",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"totalSupply",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"transfer",constant:!1,payable:!1,inputs:[{type:"address",name:"to"},{type:"uint256",name:"value"}],outputs:[{type:"bool"}]},{type:"function",name:"transferFrom",constant:!1,payable:!1,inputs:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"uint256",name:"value"}],outputs:[{type:"bool"}]},{type:"function",name:"underlyingToken",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"userGenesisShare",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"}],outputs:[{type:"uint256"}]}];var ht=[{type:"constructor",payable:!1,inputs:[]},{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidParameter",inputs:[]},{type:"error",name:"InvalidQuoteTokenAddress",inputs:[]},{type:"error",name:"InvalidRatioParams",inputs:[]},{type:"error",name:"MarketAlreadyExisted",inputs:[]},{type:"error",name:"MarketNotExisted",inputs:[]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"ExecutionFeeUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint256",name:"oldExecutionFee",indexed:!1},{type:"uint256",name:"newExecutionFee",indexed:!1}]},{type:"event",anonymous:!1,name:"ForwardFeeUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint256",name:"oldForwardFee",indexed:!1},{type:"uint256",name:"newForwardFee",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"MaxExecutionFeeUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint256",name:"oldMaxExecutionFee",indexed:!1},{type:"uint256",name:"newMaxExecutionFee",indexed:!1}]},{type:"event",anonymous:!1,name:"MaxForwardFeeUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint256",name:"oldMaxForwardFee",indexed:!1},{type:"uint256",name:"newMaxForwardFee",indexed:!1}]},{type:"event",anonymous:!1,name:"OracleFeeUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint64",name:"newOracleFeeUsd",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolPrimeThresholdUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint128",name:"newPoolPrimeThreshold",indexed:!1}]},{type:"event",anonymous:!1,name:"ReserveRatioUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint32",name:"newBaseReserveRatio",indexed:!1},{type:"uint32",name:"newQuoteReserveRatio",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"createMarket",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"uint64",name:"chainId"},{type:"address",name:"quoteToken"},{type:"uint32",name:"baseReserveRatio"},{type:"uint32",name:"quoteReserveRatio"},{type:"uint64",name:"oracleFeeUsd"},{type:"uint128",name:"poolPrimeThreshold"},{type:"uint128",name:"executionFee"},{type:"uint128",name:"maxExecutionFee"},{type:"uint128",name:"forwardFee"},{type:"uint128",name:"maxForwardFee"}]},{type:"tuple",name:"quoteParams",components:[{type:"address",name:"priceContract"},{type:"bool",name:"applyExchangeRate"},{type:"uint16",name:"minDeviationRatio"}]}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getExecutionFee",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"marketId"}],outputs:[{type:"uint256"}]},{type:"function",name:"getExecutionFeeByToken",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"quoteToken"}],outputs:[{type:"uint256"}]},{type:"function",name:"getForwardFee",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"marketId"}],outputs:[{type:"uint256"}]},{type:"function",name:"getForwardFeeByToken",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"quoteToken"}],outputs:[{type:"uint256"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getMarket",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"marketId"}],outputs:[{type:"tuple",components:[{type:"address",name:"quoteToken"},{type:"uint32",name:"baseReserveRatio"},{type:"uint32",name:"quoteReserveRatio"},{type:"uint64",name:"oracleFeeUsd"},{type:"uint128",name:"poolPrimeThreshold"},{type:"uint128",name:"executionFee"},{type:"uint128",name:"maxExecutionFee"},{type:"uint128",name:"forwardFee"},{type:"uint128",name:"maxForwardFee"}]}]},{type:"function",name:"getMarketIds",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32[]"}]},{type:"function",name:"getOracleFee",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"marketId"}],outputs:[{type:"uint256"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"marketExists",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"marketId"}],outputs:[{type:"bool"}]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"updateExecutionFee",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint128",name:"_executionFee"}],outputs:[]},{type:"function",name:"updateForwardFee",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint128",name:"_forwardFee"}],outputs:[]},{type:"function",name:"updateMarketQuoteConfiguration",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"tuple",name:"quoteParams",components:[{type:"address",name:"priceContract"},{type:"bool",name:"applyExchangeRate"},{type:"uint16",name:"minDeviationRatio"}]}],outputs:[]},{type:"function",name:"updateMaxExecutionFee",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint128",name:"_maxExecutionFee"}],outputs:[]},{type:"function",name:"updateMaxForwardFee",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint128",name:"_maxForwardFee"}],outputs:[]},{type:"function",name:"updateOracleFee",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint64",name:"_oracleFeeUsd"}],outputs:[]},{type:"function",name:"updatePoolPrimeThreshold",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint128",name:"_poolPrimeThreshold"}],outputs:[]},{type:"function",name:"updateReserveRatio",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint32",name:"_baseReserveRatio"},{type:"uint32",name:"_quoteReserveRatio"}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]}];var xt=[{type:"constructor",payable:!1,inputs:[{type:"address",name:"addressManager"}]},{type:"error",name:"PositionNotHealthy",inputs:[{type:"bytes32",name:"positionId"},{type:"uint256",name:"marginRatio"}]},{type:"error",name:"SafeCastOverflowedUintToInt",inputs:[{type:"uint256",name:"value"}]},{type:"function",name:"ADDRESS_MANAGER",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getAccountInfo",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"}],outputs:[{type:"tuple",name:"accountInfo",components:[{type:"uint256",name:"freeMargin"},{type:"uint256",name:"walletBalance"},{type:"uint256",name:"freeBaseAmount"},{type:"uint256",name:"baseProfit"},{type:"uint256",name:"quoteProfit"},{type:"uint256",name:"reservedAmount"},{type:"uint64",name:"releaseTime"}]}]},{type:"function",name:"getAvailableLiquiditySize",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"operation"},{type:"uint8",name:"direction"},{type:"uint256",name:"executePrice"}],outputs:[{type:"uint256"}]},{type:"function",name:"getBrokerFeeTiers",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"brokerAddress"},{type:"uint8[]",name:"assetClasses"},{type:"uint8[]",name:"riskTiers"},{type:"bool",name:"isMYXBroker"}],outputs:[{type:"tuple[]",name:"brokerFees",components:[{type:"uint8",name:"asset"},{type:"tuple[]",name:"riskTieredBrokerFees",components:[{type:"uint8",name:"riskTier"},{type:"tuple[]",name:"addOnFeeTiers",components:[{type:"uint8",name:"tier"},{type:"uint32",name:"takerFeeRate"},{type:"int32",name:"makerFeeRate"}]},{type:"tuple[]",name:"baseFeeRate",components:[{type:"uint8",name:"assetClass"},{type:"uint32",name:"makerFeeRate"},{type:"uint32",name:"takerFeeRate"}]},{type:"tuple[]",name:"specialFeeTiers",components:[{type:"uint8",name:"tier"},{type:"uint32",name:"takerFeeRate"},{type:"int32",name:"makerFeeRate"}]}]}]}]},{type:"function",name:"getExchangeables",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"uint256[]",name:"marketPrices"}],outputs:[{type:"tuple[]",name:"exchangeables",components:[{type:"uint256",name:"maxBaseIn"},{type:"uint256",name:"maxQuoteIn"},{type:"uint256",name:"maxBaseOut"},{type:"uint256",name:"maxQuoteOut"}]}]},{type:"function",name:"getLiquidationPrice",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"positionId"},{type:"uint256",name:"marketPrice"},{type:"address",name:"broker"}],outputs:[{type:"uint256"}]},{type:"function",name:"getPoolInfo",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"marketPrice"}],outputs:[{type:"tuple",components:[{type:"tuple",name:"basePool",components:[{type:"address",name:"poolToken"},{type:"uint256",name:"exchangeRate"},{type:"uint256",name:"poolTokenPrice"},{type:"uint256",name:"poolTokenSupply"},{type:"uint256",name:"totalDebt"},{type:"uint256",name:"baseCollateral"}]},{type:"tuple",name:"quotePool",components:[{type:"address",name:"poolToken"},{type:"uint256",name:"exchangeRate"},{type:"uint256",name:"poolTokenPrice"},{type:"uint256",name:"poolTokenSupply"},{type:"uint256",name:"totalDebt"},{type:"uint256",name:"baseCollateral"}]},{type:"tuple",name:"reserveInfo",components:[{type:"uint256",name:"baseTotalAmount"},{type:"uint256",name:"baseReservedAmount"},{type:"uint256",name:"quoteTotalAmount"},{type:"uint256",name:"quoteReservedAmount"}]},{type:"tuple",name:"fundingInfo",components:[{type:"int256",name:"nextFundingRate"},{type:"int256",name:"lastFundingFeeTracker"},{type:"uint256",name:"nextEpochTime"}]},{type:"tuple",name:"oi",components:[{type:"int256",name:"tracker"},{type:"uint256",name:"longSize"},{type:"uint256",name:"shortSize"},{type:"uint256",name:"poolEntryPrice"}]},{type:"tuple",name:"liquidityInfo",components:[{type:"uint256",name:"windowCaps"},{type:"int256",name:"openInterest"}]}]}]},{type:"function",name:"getPoolInfos",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"uint256[]",name:"marketPrices"}],outputs:[{type:"tuple[]",components:[{type:"tuple",name:"basePool",components:[{type:"address",name:"poolToken"},{type:"uint256",name:"exchangeRate"},{type:"uint256",name:"poolTokenPrice"},{type:"uint256",name:"poolTokenSupply"},{type:"uint256",name:"totalDebt"},{type:"uint256",name:"baseCollateral"}]},{type:"tuple",name:"quotePool",components:[{type:"address",name:"poolToken"},{type:"uint256",name:"exchangeRate"},{type:"uint256",name:"poolTokenPrice"},{type:"uint256",name:"poolTokenSupply"},{type:"uint256",name:"totalDebt"},{type:"uint256",name:"baseCollateral"}]},{type:"tuple",name:"reserveInfo",components:[{type:"uint256",name:"baseTotalAmount"},{type:"uint256",name:"baseReservedAmount"},{type:"uint256",name:"quoteTotalAmount"},{type:"uint256",name:"quoteReservedAmount"}]},{type:"tuple",name:"fundingInfo",components:[{type:"int256",name:"nextFundingRate"},{type:"int256",name:"lastFundingFeeTracker"},{type:"uint256",name:"nextEpochTime"}]},{type:"tuple",name:"oi",components:[{type:"int256",name:"tracker"},{type:"uint256",name:"longSize"},{type:"uint256",name:"shortSize"},{type:"uint256",name:"poolEntryPrice"}]},{type:"tuple",name:"liquidityInfo",components:[{type:"uint256",name:"windowCaps"},{type:"int256",name:"openInterest"}]}]}]},{type:"function",name:"getPoolTokenPrices",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"uint256[]",name:"marketPrices"}],outputs:[{type:"tuple[]",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"basePoolTokenPrice"},{type:"uint256",name:"quotePoolTokenPrice"}]}]},{type:"function",name:"getPositionFees",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"positionId"},{type:"address",name:"broker"},{type:"uint256",name:"price"}],outputs:[{type:"int256",name:"netCollateral"},{type:"uint256",name:"collateralAmount"},{type:"uint256",name:"tradingFee"},{type:"int256",name:"fundingFee"}]},{type:"function",name:"getSumProfitLock",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address[]",name:"respondents"}],outputs:[{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"},{type:"tuple[]",name:"infos",components:[{type:"address",name:"account"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"}]}]},{type:"function",name:"getUserPositionInfos",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"user"},{type:"bytes32[]",name:"poolIds"}],outputs:[{type:"tuple[]",name:"positions",components:[{type:"bytes32",name:"positionId"},{type:"bytes32",name:"poolId"},{type:"uint256",name:"size"},{type:"uint256",name:"entryPrice"},{type:"int256",name:"fundingRateIndex"},{type:"uint256",name:"earlyClosePrice"},{type:"uint8",name:"direction"},{type:"uint8",name:"riskTier"},{type:"uint64",name:"lastUpdateTime"},{type:"uint256",name:"collateralAmount"}]}]}];var Re=[{type:"constructor",payable:!1,inputs:[]},{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"ERC2771ForwarderExpiredRequest",inputs:[{type:"uint48",name:"deadline"}]},{type:"error",name:"ERC2771ForwarderInvalidSigner",inputs:[{type:"address",name:"signer"},{type:"address",name:"from"}]},{type:"error",name:"ERC2771ForwarderMismatchedValue",inputs:[{type:"uint256",name:"requestedValue"},{type:"uint256",name:"msgValue"}]},{type:"error",name:"ERC2771UntrustfulTarget",inputs:[{type:"address",name:"target"},{type:"address",name:"forwarder"}]},{type:"error",name:"ExceedsMaximumRelayFee",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InconsistentParamsLength",inputs:[]},{type:"error",name:"InsufficientBalance",inputs:[{type:"uint256",name:"balance"},{type:"uint256",name:"needed"}]},{type:"error",name:"InsufficientFeeAllowance",inputs:[{type:"address",name:"user"},{type:"uint256",name:"allowance"},{type:"uint256",name:"required"}]},{type:"error",name:"InsufficientFeeBalance",inputs:[{type:"address",name:"user"},{type:"uint256",name:"balance"},{type:"uint256",name:"required"}]},{type:"error",name:"InvalidAccountNonce",inputs:[{type:"address",name:"account"},{type:"uint256",name:"currentNonce"}]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"MismatchExecuteFee",inputs:[{type:"uint256",name:"balanceBefore"},{type:"uint256",name:"balanceAfter"},{type:"uint256",name:"expected"}]},{type:"error",name:"MismatchedSender",inputs:[{type:"address",name:"sender"}]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotAllowedTarget",inputs:[{type:"address",name:"target"}]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"OnlyRelayer",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"RelayerRegistered",inputs:[{type:"address",name:"relayer"}]},{type:"error",name:"RemoveRelayerFailed",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"AddAllowedTarget",inputs:[{type:"address",name:"target",indexed:!1}]},{type:"event",anonymous:!1,name:"ChargeForwardFee",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"feeToken",indexed:!1},{type:"uint256",name:"relayFee",indexed:!1}]},{type:"event",anonymous:!1,name:"EIP712DomainChanged",inputs:[]},{type:"event",anonymous:!1,name:"ERC20PermitFailed",inputs:[{type:"address",name:"token",indexed:!1},{type:"string",name:"reason",indexed:!1}]},{type:"event",anonymous:!1,name:"ERC20PermitLowLevelFailed",inputs:[{type:"bytes",name:"data",indexed:!1}]},{type:"event",anonymous:!1,name:"ExecutedForwardRequest",inputs:[{type:"address",name:"signer",indexed:!0},{type:"uint256",name:"nonce",indexed:!1},{type:"bool",name:"success",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"RemoveAllowedTarget",inputs:[{type:"address",name:"target",indexed:!1}]},{type:"event",anonymous:!1,name:"SetUserRelayer",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"relayer",indexed:!1},{type:"bool",name:"enable",indexed:!1}]},{type:"event",anonymous:!1,name:"UpdateAcquiescentFeeToken",inputs:[{type:"address",name:"sender",indexed:!1},{type:"address",name:"oldRelayGas",indexed:!1},{type:"address",name:"newRelayGas",indexed:!1}]},{type:"event",anonymous:!1,name:"UpdateEquilibriumGas",inputs:[{type:"address",name:"sender",indexed:!1},{type:"uint256",name:"oldRelayGas",indexed:!1},{type:"uint256",name:"newRelayGas",indexed:!1}]},{type:"event",anonymous:!1,name:"UpdateMaxRelayFee",inputs:[{type:"address",name:"sender",indexed:!1},{type:"uint256",name:"oldMaxRelayFee",indexed:!1},{type:"uint256",name:"newMaxRelayFee",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"__ERC2771ContextUpgradeable_init",constant:!1,payable:!1,inputs:[{type:"address",name:"trustedForwarder_"}],outputs:[]},{type:"function",name:"addAllowedTarget",constant:!1,payable:!1,inputs:[{type:"address",name:"target"}],outputs:[]},{type:"function",name:"batchExecuteForwarder",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"forwardFeeToken"},{type:"tuple[]",name:"bundleParams",components:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"uint256",name:"value"},{type:"uint256",name:"gas"},{type:"uint48",name:"deadline"},{type:"bytes",name:"data"},{type:"bytes",name:"signature"}]}],outputs:[]},{type:"function",name:"eip712Domain",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes1",name:"fields"},{type:"string",name:"name"},{type:"string",name:"version"},{type:"uint256",name:"chainId"},{type:"address",name:"verifyingContract"},{type:"bytes32",name:"salt"},{type:"uint256[]",name:"extensions"}]},{type:"function",name:"equilibriumGas",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"execute",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple",name:"request",components:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"uint256",name:"value"},{type:"uint256",name:"gas"},{type:"uint48",name:"deadline"},{type:"bytes",name:"data"},{type:"bytes",name:"signature"}]},{type:"address",name:"masterAccount"}],outputs:[]},{type:"function",name:"executeBatch",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"requests",components:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"uint256",name:"value"},{type:"uint256",name:"gas"},{type:"uint48",name:"deadline"},{type:"bytes",name:"data"},{type:"bytes",name:"signature"}]},{type:"address",name:"masterAccount"},{type:"address",name:"refundReceiver"}],outputs:[]},{type:"function",name:"executeForwarder",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"forwardFeeToken"},{type:"tuple",name:"params",components:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"uint256",name:"value"},{type:"uint256",name:"gas"},{type:"uint48",name:"deadline"},{type:"bytes",name:"data"},{type:"bytes",name:"signature"}]}],outputs:[]},{type:"function",name:"exitForwardMode",constant:!1,payable:!1,inputs:[],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getAllowedTargets",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address[]"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getDesignatedToken",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getEquilibriumGas",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getUserRelayers",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"}],outputs:[{type:"address[]"}]},{type:"function",name:"inForwardMode",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bool"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"},{type:"uint256",name:"_equilibriumGas"}],outputs:[]},{type:"function",name:"isAllowedTargets",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"contractAddr"}],outputs:[{type:"bool"}]},{type:"function",name:"isTrustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"forwarder"}],outputs:[{type:"bool"}]},{type:"function",name:"isUserRelayerEnabled",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"},{type:"address",name:"relayer"}],outputs:[{type:"bool"}]},{type:"function",name:"nonces",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"owner"}],outputs:[{type:"uint256"}]},{type:"function",name:"originAccount",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"relayer"}],outputs:[{type:"address",name:"account"}]},{type:"function",name:"permitAndApproveForwarder",constant:!1,payable:!1,inputs:[{type:"address",name:"relayer"},{type:"bool",name:"enable"},{type:"tuple[]",name:"permitParams",components:[{type:"address",name:"token"},{type:"address",name:"owner"},{type:"address",name:"spender"},{type:"uint256",name:"value"},{type:"uint256",name:"deadline"},{type:"uint8",name:"v"},{type:"bytes32",name:"r"},{type:"bytes32",name:"s"}]}],outputs:[]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"removeAllowedTarget",constant:!1,payable:!1,inputs:[{type:"address",name:"target"}],outputs:[]},{type:"function",name:"trustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"updateEquilibriumGas",constant:!1,payable:!1,inputs:[{type:"uint256",name:"_equilibriumGas"}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"verify",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"tuple",name:"request",components:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"uint256",name:"value"},{type:"uint256",name:"gas"},{type:"uint48",name:"deadline"},{type:"bytes",name:"data"},{type:"bytes",name:"signature"}]}],outputs:[{type:"bool"}]}];var At=[{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"AlreadyClaimed",inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"user"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidAmount",inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"user"}]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidParameter",inputs:[]},{type:"error",name:"MerkleTreeVerificationFailed",inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"user"}]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"ReimbursementValidity",inputs:[{type:"uint256",name:"caseId"}]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"TreeAlreadySet",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"ReimbursementClaimExpired",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint256",name:"baseAmount",indexed:!1},{type:"uint256",name:"quoteAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReimbursementClaimed",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint256",name:"baseAmount",indexed:!1},{type:"uint256",name:"quoteAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReimbursementInfoSet",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"bytes32",name:"merkleRoot",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint256",name:"totalBaseAmount",indexed:!1},{type:"uint256",name:"totalQuoteAmount",indexed:!1},{type:"uint256",name:"claimedBaseAmount",indexed:!1},{type:"uint256",name:"claimedQuoteAmount",indexed:!1},{type:"uint256",name:"expireTime",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"claimExpiredCases",constant:!1,payable:!1,inputs:[{type:"uint256[]",name:"caseIds"},{type:"address",name:"receiver"}],outputs:[]},{type:"function",name:"claimReimbursement",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"},{type:"bytes32[]",name:"merkleProof"}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getReimbursementInfo",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint256",name:"caseId"}],outputs:[{type:"tuple",components:[{type:"bytes32",name:"merkleRoot"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint256",name:"totalBaseAmount"},{type:"uint256",name:"totalQuoteAmount"},{type:"uint256",name:"claimedBaseAmount"},{type:"uint256",name:"claimedQuoteAmount"},{type:"uint256",name:"expireTime"}]}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"setReimbursementInfo",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"tuple",name:"reimbursementInfo",components:[{type:"bytes32",name:"merkleRoot"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint256",name:"totalBaseAmount"},{type:"uint256",name:"totalQuoteAmount"},{type:"uint256",name:"claimedBaseAmount"},{type:"uint256",name:"claimedQuoteAmount"},{type:"uint256",name:"expireTime"}]},{type:"bytes32[]",name:"zeroMerkleProof"}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]}];var ve=[{type:"constructor",payable:!1,inputs:[]},{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"AlreadyVoted",inputs:[]},{type:"error",name:"BondNotReleased",inputs:[]},{type:"error",name:"CaseAppealNotFinished",inputs:[]},{type:"error",name:"CaseDeadlineNotReached",inputs:[]},{type:"error",name:"CaseDeadlineReached",inputs:[]},{type:"error",name:"CaseNotAccepted",inputs:[]},{type:"error",name:"CaseNotExist",inputs:[{type:"uint256",name:"caseId"}]},{type:"error",name:"CaseRespondentAppealed",inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"respondent"}]},{type:"error",name:"ChainIdMismatch",inputs:[]},{type:"error",name:"DisputeNotAllowed",inputs:[]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidAccountNonce",inputs:[{type:"address",name:"account"},{type:"uint256",name:"currentNonce"}]},{type:"error",name:"InvalidContractAddress",inputs:[]},{type:"error",name:"InvalidFunctionSignature",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidParameter",inputs:[]},{type:"error",name:"InvalidPayloadLength",inputs:[{type:"uint256",name:"received"},{type:"uint256",name:"expected"}]},{type:"error",name:"InvalidPoolToken",inputs:[]},{type:"error",name:"InvalidProfitAmount",inputs:[]},{type:"error",name:"InvalidResponseVersion",inputs:[]},{type:"error",name:"InvalidSourceChain",inputs:[]},{type:"error",name:"NoChainResponse",inputs:[]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotCaseRespondent",inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"respondent"}]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"NumberOfResponsesMismatch",inputs:[]},{type:"error",name:"OnlyRelayer",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"RequestTypeMismatch",inputs:[]},{type:"error",name:"RiskCloseNotCompleted",inputs:[]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"SignatureExpired",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"error",name:"UnexpectedCaseState",inputs:[]},{type:"error",name:"UnexpectedCaseType",inputs:[]},{type:"error",name:"UnexpectedNumberOfResults",inputs:[]},{type:"error",name:"UnsupportedQueryType",inputs:[{type:"uint8",name:"received"}]},{type:"error",name:"UntrustfulVoting",inputs:[]},{type:"error",name:"VerificationFailed",inputs:[]},{type:"error",name:"VersionMismatch",inputs:[]},{type:"error",name:"WrongQueryType",inputs:[{type:"uint8",name:"received"},{type:"uint8",name:"expected"}]},{type:"error",name:"ZeroQueries",inputs:[]},{type:"event",anonymous:!1,name:"AppealCanceled",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"uint256",name:"appealCaseId",indexed:!1},{type:"address",name:"complainant",indexed:!1},{type:"bool",name:"isMalicious",indexed:!1}]},{type:"event",anonymous:!1,name:"AppealFiled",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"uint256",name:"appealCaseId",indexed:!1},{type:"address",name:"respondent",indexed:!1},{type:"address",name:"appealToken",indexed:!1},{type:"uint256",name:"appealBond",indexed:!1},{type:"uint64",name:"appealDeadline",indexed:!1}]},{type:"event",anonymous:!1,name:"AppealResolved",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"uint256",name:"appealCaseId",indexed:!1},{type:"uint8",name:"resolution",indexed:!1},{type:"address",name:"complainant",indexed:!1}]},{type:"event",anonymous:!1,name:"BondClaimed",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"CaseAppealsResolved",inputs:[{type:"uint256",name:"caseId",indexed:!1}]},{type:"event",anonymous:!1,name:"CaseRiskClosed",inputs:[{type:"uint256",name:"caseId",indexed:!1}]},{type:"event",anonymous:!1,name:"DisputeCanceled",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"address",name:"complainant",indexed:!1},{type:"bool",name:"isMalicious",indexed:!1}]},{type:"event",anonymous:!1,name:"DisputeConfigurationUpdated",inputs:[{type:"tuple",name:"newDisputeConfigration",indexed:!1,components:[{type:"address",name:"appealToken"},{type:"uint64",name:"disputeBondUsd"},{type:"uint64",name:"appealBondUsd"},{type:"uint64",name:"disputeThresholdUsd"},{type:"uint64",name:"caseDuration"},{type:"uint64",name:"voteDuration"},{type:"uint64",name:"resolveDuration"},{type:"uint32",name:"voteCountRate"},{type:"uint32",name:"effectiveVoteRate"}]}]},{type:"event",anonymous:!1,name:"DisputeFiled",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"complainant",indexed:!1},{type:"address",name:"poolToken",indexed:!1},{type:"uint256",name:"disputeBond",indexed:!1},{type:"uint64",name:"caseDeadline",indexed:!1}]},{type:"event",anonymous:!1,name:"DisputeResolved",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"uint8",name:"resolution",indexed:!1},{type:"uint64",name:"appealDeadline",indexed:!1}]},{type:"event",anonymous:!1,name:"ForfeitBondsClaimed",inputs:[{type:"address",name:"receiver",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"ReimbursementProcessed",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"tuple",name:"reimbursementInfo",indexed:!1,components:[{type:"bytes32",name:"merkleRoot"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint256",name:"totalBaseAmount"},{type:"uint256",name:"totalQuoteAmount"},{type:"uint256",name:"claimedBaseAmount"},{type:"uint256",name:"claimedQuoteAmount"},{type:"uint256",name:"expireTime"}]}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"event",anonymous:!1,name:"Voted",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"address",name:"voter",indexed:!1},{type:"uint8",name:"voteOption",indexed:!1}]},{type:"event",anonymous:!1,name:"VotingOpened",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"uint256",name:"evidenceId",indexed:!1},{type:"uint64",name:"voteDeadline",indexed:!1},{type:"address[]",name:"respondents",indexed:!1}]},{type:"event",anonymous:!1,name:"WormholeConfigurationUpdated",inputs:[{type:"tuple",name:"newWormholeConfiguration",indexed:!1,components:[{type:"address",name:"wormhole"},{type:"address",name:"staker"},{type:"bytes4",name:"selector"}]}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"appeal",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"}],outputs:[]},{type:"function",name:"canRiskControlClose",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint256",name:"caseId"}],outputs:[{type:"bool"}]},{type:"function",name:"cancelAppeal",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"uint256",name:"appealCaseId"},{type:"bool",name:"isMalicious"}],outputs:[]},{type:"function",name:"cancelDispute",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"bool",name:"isMalicious"}],outputs:[]},{type:"function",name:"caseIdSequencer",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"checkRiskControlCloseCompleted",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"}],outputs:[]},{type:"function",name:"claimBond",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"}],outputs:[]},{type:"function",name:"claimForfeitBonds",constant:!1,payable:!1,inputs:[{type:"address",name:"receiver"}],outputs:[]},{type:"function",name:"fileDispute",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"bytes32",name:"poolId"},{type:"address",name:"poolToken"}],outputs:[]},{type:"function",name:"fileDisputeFromStaker",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"bytes",name:"response"},{type:"tuple[]",name:"guardianSignatures",components:[{type:"bytes32",name:"r"},{type:"bytes32",name:"s"},{type:"uint8",name:"v"},{type:"uint8",name:"guardianIndex"}]}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getDisputeConfiguration",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"tuple",components:[{type:"address",name:"appealToken"},{type:"uint64",name:"disputeBondUsd"},{type:"uint64",name:"appealBondUsd"},{type:"uint64",name:"disputeThresholdUsd"},{type:"uint64",name:"caseDuration"},{type:"uint64",name:"voteDuration"},{type:"uint64",name:"resolveDuration"},{type:"uint32",name:"voteCountRate"},{type:"uint32",name:"effectiveVoteRate"}]}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"isCaseRespondents",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"account"}],outputs:[{type:"bool"}]},{type:"function",name:"nonces",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"owner"}],outputs:[{type:"uint256"}]},{type:"function",name:"openVoting",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"uint256",name:"evidenceId"},{type:"address[]",name:"respondents"}],outputs:[]},{type:"function",name:"processReimbursement",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"tuple",name:"reimbursementInfo",components:[{type:"bytes32",name:"merkleRoot"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint256",name:"totalBaseAmount"},{type:"uint256",name:"totalQuoteAmount"},{type:"uint256",name:"claimedBaseAmount"},{type:"uint256",name:"claimedQuoteAmount"},{type:"uint256",name:"expireTime"}]},{type:"bytes32[]",name:"zeroMerkleProof"}],outputs:[]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"resolveCaseAppeals",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"bytes",name:"response"},{type:"tuple[]",name:"guardianSignatures",components:[{type:"bytes32",name:"r"},{type:"bytes32",name:"s"},{type:"uint8",name:"v"},{type:"uint8",name:"guardianIndex"}]}],outputs:[]},{type:"function",name:"resolveDispute",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"bytes",name:"response"},{type:"tuple[]",name:"guardianSignatures",components:[{type:"bytes32",name:"r"},{type:"bytes32",name:"s"},{type:"uint8",name:"v"},{type:"uint8",name:"guardianIndex"}]}],outputs:[]},{type:"function",name:"updateDisputeConfiguration",constant:!1,payable:!1,inputs:[{type:"tuple",name:"disputeConfiguration",components:[{type:"address",name:"appealToken"},{type:"uint64",name:"disputeBondUsd"},{type:"uint64",name:"appealBondUsd"},{type:"uint64",name:"disputeThresholdUsd"},{type:"uint64",name:"caseDuration"},{type:"uint64",name:"voteDuration"},{type:"uint64",name:"resolveDuration"},{type:"uint32",name:"voteCountRate"},{type:"uint32",name:"effectiveVoteRate"}]}],outputs:[]},{type:"function",name:"updateWormholeConfiguration",constant:!1,payable:!1,inputs:[{type:"tuple",name:"wormholeConfiguration",components:[{type:"address",name:"wormhole"},{type:"address",name:"staker"},{type:"bytes4",name:"selector"}]}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"vote",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"validator"},{type:"uint8",name:"voteOption"},{type:"uint256",name:"deadline"},{type:"uint8",name:"v"},{type:"bytes32",name:"r"},{type:"bytes32",name:"s"}],outputs:[]}];var Ee=[{type:"error",name:"AccountInsufficientFreeAmount",inputs:[]},{type:"error",name:"AccountInsufficientReservedAmount",inputs:[]},{type:"error",name:"AccountInsufficientTradableAmount",inputs:[{type:"uint256",name:"accountTradableAmount"},{type:"uint256",name:"requiredTradableAmount"}]},{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"DepositToAccount",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"ExecuteCompensation",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"baseAmount",indexed:!1},{type:"uint256",name:"quoteAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"PayWithPrincipal",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"receiver",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"PayWithProfitFirst",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"receiver",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"usedFreeAmount",indexed:!1},{type:"uint256",name:"usedRestrictedAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReleaseForOrder",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"address",name:"account",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReleaseProfit",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReserveForOrder",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"address",name:"account",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"SettleToAccount",inputs:[{type:"address",name:"account",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint256",name:"freeBase",indexed:!1},{type:"uint256",name:"profitBase",indexed:!1},{type:"uint256",name:"freeAmount",indexed:!1},{type:"uint256",name:"profitAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"event",anonymous:!1,name:"WithdrawFromAccount",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"__ERC2771ContextUpgradeable_init",constant:!1,payable:!1,inputs:[{type:"address",name:"trustedForwarder_"}],outputs:[]},{type:"function",name:"deposit",constant:!1,payable:!1,inputs:[{type:"address",name:"account"},{type:"address",name:"token"},{type:"uint256",name:"amount"}],outputs:[]},{type:"function",name:"executeCompensation",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"reimbursement"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getPoolWithdrawableBaseToken",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"},{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256",name:"baseAmount"}]},{type:"function",name:"getTradableAmount",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"},{type:"bytes32",name:"poolId"}],outputs:[{type:"bool"},{type:"uint256"},{type:"uint256"},{type:"uint256"}]},{type:"function",name:"getUserAsset",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"},{type:"address",name:"token"}],outputs:[{type:"uint256",name:"amount"}]},{type:"function",name:"getUserAssets",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"}],outputs:[{type:"tuple[]",components:[{type:"address",name:"asset"},{type:"uint256",name:"amount"}]}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"isTrustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"forwarder"}],outputs:[{type:"bool"}]},{type:"function",name:"payWithPrincipal",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"account"},{type:"address",name:"token"},{type:"uint256",name:"amount"},{type:"address",name:"receiver"}],outputs:[]},{type:"function",name:"payWithProfitFirst",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"address",name:"account"},{type:"address",name:"token"},{type:"uint256",name:"amount"}],outputs:[{type:"uint256",name:"usedFreeAmount"},{type:"uint256",name:"usedRestrictedAmount"}]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"releaseForCancelOrder",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"address",name:"account"},{type:"uint256",name:"amount"}],outputs:[]},{type:"function",name:"releaseFromProfitUnlock",constant:!1,payable:!1,inputs:[{type:"address",name:"account"},{type:"bytes32",name:"poolId"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"}],outputs:[]},{type:"function",name:"reserveForOrder",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"address",name:"account"},{type:"address",name:"token"},{type:"uint256",name:"amount"}],outputs:[]},{type:"function",name:"settlementDeposit",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"positionId"},{type:"address",name:"account"},{type:"tuple",name:"pool",components:[{type:"bytes32",name:"marketId"},{type:"bytes32",name:"poolId"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"state"},{type:"address",name:"basePoolToken"},{type:"address",name:"quotePoolToken"},{type:"uint16",name:"maxPriceDeviation"},{type:"bool",name:"compoundEnabled"},{type:"uint64",name:"windowCapUsd"},{type:"address",name:"poolVault"},{type:"address",name:"tradingVault"}]},{type:"uint256",name:"freeBaseAmount"},{type:"uint256",name:"freeQuoteAmount"},{type:"uint256",name:"receivedBaseAmount"},{type:"uint256",name:"receivedQuoteAmount"}],outputs:[]},{type:"function",name:"trustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"updateAndWithdraw",constant:!1,payable:!1,inputs:[{type:"address",name:"receiver"},{type:"bytes32",name:"poolId"},{type:"bool",name:"isQuoteToken"},{type:"uint256",name:"amount"}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]}];var un={USDC:"0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",POOL_MANAGER:"0xf268D9FeD3Bd56fd9aBdb4FeEb993338613678A8",Account:"0x396a6aDb17903f4b0ED3EA55F18391C403fa3Bb4",POSITION_MANAGER:"0x89d1091Ef4aB71d688a86f3D92112715905d7B8A",ORDER_MANAGER:"0x5948bc0E0c72a7B7a90eb8f5a1951bDB0ef0f68D",PYTH:"0x4374e5a8b9C22271E9EB878A2AA31DE97DF15DAF",ERC20:"0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",LIQUIDITY_ROUTER:"0x5E16C0699de2Ee5D69a620AB38AE2c81A29a58df",BASE_POOL:"0xDb41D850e9b30fc0417F488D1aB64fdc1d0DdFdc",QUOTE_POOL:"0xF0784c1023C051Bf1D5b8470A896c536039B06B9",ORACLE:"0xb3C295769d86fc321bA70a7C43EAfa10322CC66F",EIP7702Delegation:"0xe3D34CbDfC221e064510Cfa82EFF99172651BeB9",MARKET_MANAGER:"0xB3EEc5C2eEc049b4eD4C528Dcd9a97680E3edFb7",DATA_PROVIDER:"0xeA2be692Da76Bf6851f3cBf9750075e10E9085cB",ORACLE_RESERVE:"0x247e3A9d6E9CF6D619c7D0A0eE11B7CD966FA3aa",FORWARDER:"0x065Adb8183c114c3a61d75c89051ecE6C1C9A6fB",TRADING_ROUTER:"0x6A2aF0be0629B424a6A7EfEf54a3b50a99bC1a29",REIMBURSEMENT:"0x2C294a480006703B1A4F6493eA3B1dAC7A84454b",DISPUTE_COURT:"0x09F56485B5FB01C6C27bB81f54605F4d55d7d10B"};var dn={USDC:"0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",POOL_MANAGER:"0x05314a21Fc97B74f168730153b2B63A870D25dE5",Account:"0xAC0ca67fd6C7Ff9c80DE58420B840115b6d51c6e",POSITION_MANAGER:"0x1a8cC8391Ee19c3817de64a52904D0557f519bA5",ORDER_MANAGER:"0x3138f425f11f14fE33a180e9Bbf0661C8dc6d8AD",PYTH:"0x4374e5a8b9C22271E9EB878A2AA31DE97DF15DAF",ERC20:"0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",LIQUIDITY_ROUTER:"0xfb790ECE13Cd9e296b4a06ABF38D10431360c236",BASE_POOL:"0x1F767BEa83EDe5E0C18904f439C579f52c2c0F1b",QUOTE_POOL:"0x50ad7da312c58c6689bEF028954a366cb5b8ee13",ORACLE:"0x3e437094C5687Ed6eDb1883b0bd445Efa9103a55",EIP7702Delegation:"0xc68fdf81ca68B26fdB296645F42a734c12E63751",MARKET_MANAGER:"0x71b57CcB7539aB761fd5C5767362A207a295e337",DATA_PROVIDER:"0xd4FdE3cc72D29b71507823cA43Dd6fD520644E92",ORACLE_RESERVE:"0x4fC26Cf34e5d486BFF211315bf17D77d34130971",FORWARDER:"0x58fb1a663b08871A755734231C387E1d10ac2B10",TRADING_ROUTER:"0x89ba8EDBD63f577cAA1095F25Df0A44A226f28bc",REIMBURSEMENT:"0xDbCe02B080C68671EF6EcEc1a01A789441A3a564",DISPUTE_COURT:"0x47648D171925a69b3A334898AaaE6e7cc41B1735"};var cn={USDC:"0xD984fd34f91F92DA0586e1bE82E262fF27DC431b",POOL_MANAGER:"0x784808c123B778BacB2c08782837BC083e6C5cF0",Account:"0xB219526B2DC7Aa25Eb78A8Bd5e0AeaC9880f26Ca",POSITION_MANAGER:"0xca570536de1398d855507bA62c01B0dF3ecf8FE9",ORDER_MANAGER:"0x679859C80e58e5026018401bED798C574c844560",PYTH:"0xA2aa501b19aff244D90cc15a4Cf739D2725B5729",ERC20:"0xD984fd34f91F92DA0586e1bE82E262fF27DC431b",LIQUIDITY_ROUTER:"0xf1395643D77DD839E4b8d3Bb122fd0275Cf07631",BASE_POOL:"0x31b093BBADbb2A3Bcd7E433E8Ed5bcdD76fFAFFe",QUOTE_POOL:"0xFF8A6797E2063A7a4cd1468eB7cC0db9798C753f",ORACLE:"0x0074441b86da2aE6818304B586fCf619c68C4204",EIP7702Delegation:"0x7629731046b2498b4C00B8a2208e538E706E5bfc",MARKET_MANAGER:"0x170F95d91B27d8bc7afA85B06d8B129BA34f405F",DATA_PROVIDER:"0x8873C5828fe1A903221971817b17dc67903544d6",ORACLE_RESERVE:"0xDc9321c19b02cefe57fFB2C1F70014a478D06ddF",FORWARDER:"0x2AC73d767D2c3e44741410c3E41988a05bCf9C86",TRADING_ROUTER:"0x5976abbC616520968b12EeB4b11AFa8490281453",REIMBURSEMENT:"0x257BF8df1CF76762985F3cf19c7cd1D6Adb67Bc7",DISPUTE_COURT:"0x02495c66dfb2ECeF5ebb7339a997EBb7D73DFdbf"};var ln={POOL_MANAGER:"0xcf51a6895864c6D8E507fC31EF16b9011287c5f4",Account:"0x35054EfE58Bbdae792aeCaD7bC2e4939c169560f",POSITION_MANAGER:"0x689A0C7E46785584FF7636700ceF5d5e7c141F8D",ORDER_MANAGER:"0xa0B5E5AE9D3E214096C90DDeC04D39B27ED9B272",PYTH:"0xA2aa501b19aff244D90cc15a4Cf739D2725B5729",ERC20:"0xD984fd34f91F92DA0586e1bE82E262fF27DC431b",LIQUIDITY_ROUTER:"0x0AE31989318565620c03d35889a0B2536b8fba5C",BASE_POOL:"0xc9e3826c42183207B418116A16827C1605132c51",QUOTE_POOL:"0x9A9934D3b22103dE822d94A22A3177d728FE0e5a",ORACLE:"0x0dD8293765358cF7f2646D0B91bA59804E197FC6",EIP7702Delegation:"0x4686F8a0d44b056037b2A51c4342EE7FA8e0A48F",MARKET_MANAGER:"0xe99dAB65c5546D7C87850Bbc40C6a7BEd7328Efa",DATA_PROVIDER:"0x5b6Be9839552a49302d552aB3C223b60Adb8BF1D",ORACLE_RESERVE:"0xB3D5a67223905FE73a0749e7A03525838063C54C",USDC:"0xD984fd34f91F92DA0586e1bE82E262fF27DC431b",FORWARDER:"0x6C40462A4d45BA4119af59Fb9e41b8eaC9293962",TRADING_ROUTER:"0x0000000000000000000000000000000000000000",REIMBURSEMENT:"0x0000000000000000000000000000000000000000",DISPUTE_COURT:"0x0000000000000000000000000000000000000000"};var mn={USDC:"0xe944d7c0f7005a76E898Ee3B9Ec10479EbA9Cc02",POOL_MANAGER:"0x4F917ef137b573D9790b87e3cF6dfb698cF00c9c",Account:"0xE58CC82F96c86f8F809A98BE14D9DC929d503e25",POSITION_MANAGER:"0x7A5000A1DDE26520BfC893c676a288F98F8a029c",ORDER_MANAGER:"0x343d7563eFb904375Fea81BcC4A3eCdDc0CDa8C9",PYTH:"0x5744Cbf430D99456a0A8771208b674F27f8EF0Fb",ERC20:"0xe944d7c0f7005a76E898Ee3B9Ec10479EbA9Cc02",LIQUIDITY_ROUTER:"0xe9F2E58562aD1D50AfB1eD92EAa6D367A6D0e552",BASE_POOL:"0x39506f97D1c1A91EAfD59368697E20dC1fE5eEDB",QUOTE_POOL:"0x80DAa474e7e2C9c86708e434B80636b92fb4e9EE",ORACLE:"0xB980765F0D5D3B482601F1a62Ec898619DA9c0C5",EIP7702Delegation:"0x9d43e7847f74E141E1A2B4C413D5F89520995551",MARKET_MANAGER:"0x624d1D5258b34d5C3F4f9CdCB7582F677643cdDC",DATA_PROVIDER:"0xb3c6b1448F04B3Eb9A5D83D6c32B0a10F3E7281B",ORACLE_RESERVE:"0x949e8a0284eA5509B47619e7667C3aA43B7c0336",FORWARDER:"0x73F9F9205E2F7E0Fb886afC3D2a53399C85383a5",TRADING_ROUTER:"0x0000000000000000000000000000000000000000",REIMBURSEMENT:"0x0000000000000000000000000000000000000000",DISPUTE_COURT:"0x0000000000000000000000000000000000000000"};var yn={USDC:"0xe944d7c0f7005a76E898Ee3B9Ec10479EbA9Cc02",POOL_MANAGER:"0x9E84a999e15CCdb2F64a5AF10939c25769dF6b07",Account:"0x42A1BC012CeC51Ebf3bbf79142bf2a912396FB0e",POSITION_MANAGER:"0x011a25Fe39b2f9033E49d1587CF24780242e40dA",ORDER_MANAGER:"0xfc30D3C858B72a9EDfE6679Fc3355039D276f811",PYTH:"0x5744Cbf430D99456a0A8771208b674F27f8EF0Fb",ERC20:"0xe944d7c0f7005a76E898Ee3B9Ec10479EbA9Cc02",LIQUIDITY_ROUTER:"0x0F4C6f18Fb136DD1eBd6Da3C5d86a86597CF79a3",BASE_POOL:"0x51B62554a76197d5DF2D5dC4D57FF54d40775938",QUOTE_POOL:"0x783Ed065a12e1C1D33c2a8d6408385C1843D3084",ORACLE:"0xaF26d69BC0A6f1DEf8AeB00B6DAD28398ba67a53",EIP7702Delegation:"0xc8558cD3905F273ff45B1dd6D10894445bFa622f",MARKET_MANAGER:"0x3b809daB550f9DD0DbE82567f6EA6137C174532c",DATA_PROVIDER:"0x4B5888025570934cC9D31807feBAAEDaC823Cb8e",ORACLE_RESERVE:"0x3011dA5822c1ECA7fcda64716779769D0089945D",FORWARDER:"0x2943a063ae2A772f4314FaA28E00De827A491Dd3",TRADING_ROUTER:"0xaA16801F36e49cDD4f87938032487C7E6cfbb389",REIMBURSEMENT:"0xBF72B69bA547D0bB7D1255B43Ff5D7f2615326dF",DISPUTE_COURT:"0xeD8B129a5919c45c7391AA73632eA691A471C672"};import _a from"wretch";var Be=_a(),Ba=(s,e)=>e?(e=JSON.parse(JSON.stringify(e)),s.includes("?")?s+"&"+new URLSearchParams(e).toString():s+"?"+new URLSearchParams(e).toString()):s,x={get:(s,e,t={})=>{let n=Ba(s,e);return Be.url(n).options(t).get().json()},post:(s,e,t={})=>Be.url(s).options(t).post(e).json(),put:(s,e,t={})=>Be.url(s).options(t).put(e).json(),delete:(s,e={})=>Be.url(s).options(e).delete().json()};var La=(d=>(d[d.SUCCESS=9200]="SUCCESS",d[d.SUCCESS_ORIGIN=0]="SUCCESS_ORIGIN",d[d.IDENTITY_VERIFICATION_FAILED=9401]="IDENTITY_VERIFICATION_FAILED",d[d.PERMISSION_DENIED=9403]="PERMISSION_DENIED",d[d.NOT_EXIST=9404]="NOT_EXIST",d[d.REQUEST_LIMIT=9429]="REQUEST_LIMIT",d[d.SERVICE_ERROR=9500]="SERVICE_ERROR",d[d.MISS_REQUESTED_PARAMETER=9900]="MISS_REQUESTED_PARAMETER",d[d.INVALID_PARAMETER=9901]="INVALID_PARAMETER",d.NETWORK_ERROR="ERR_NETWORK",d))(La||{}),Ie=(i=>(i[i.Cook=0]="Cook",i[i.Primed=1]="Primed",i[i.Trench=2]="Trench",i[i.PreBench=3]="PreBench",i[i.Bench=4]="Bench",i))(Ie||{}),fn=(t=>(t[t.Chainlink=1]="Chainlink",t[t.Pyth=2]="Pyth",t))(fn||{}),gn=(u=>(u[u.Minute1=1]="Minute1",u[u.Minute5=5]="Minute5",u[u.Minute15=15]="Minute15",u[u.Minute30=30]="Minute30",u[u.Hour1=60]="Hour1",u[u.Hour4=240]="Hour4",u[u.Day1=1440]="Day1",u[u.Week1=10080]="Week1",u[u.Month1=40320]="Month1",u))(gn||{}),Ua=(n=>(n[n.Contract=1]="Contract",n[n.Cook=2]="Cook",n[n.Earn=3]="Earn",n))(Ua||{}),Ga=(a=>(a[a.All=0]="All",a[a.Contract=1]="Contract",a[a.Cook=2]="Cook",a[a.Earn=3]="Earn",a))(Ga||{}),qa=(t=>(t[t.BlueChips=1]="BlueChips",t[t.Alpha=2]="Alpha",t))(qa||{}),Wa=(n=>(n[n.BlueChips=1]="BlueChips",n[n.Alpha=2]="Alpha",n[n.Favorite=3]="Favorite",n))(Wa||{});var za=(a=>(a[a.Market=0]="Market",a[a.Limit=1]="Limit",a[a.Stop=2]="Stop",a[a.Conditional=3]="Conditional",a))(za||{}),Va=(t=>(t[t.Increase=0]="Increase",t[t.Decrease=1]="Decrease",t))(Va||{}),$a=(m=>(m[m.Increase=0]="Increase",m[m.Decrease=1]="Decrease",m[m.AddMargin=2]="AddMargin",m[m.RemoveMargin=3]="RemoveMargin",m[m.CancelOrder=4]="CancelOrder",m[m.ADL=5]="ADL",m[m.Liquidation=6]="Liquidation",m[m.MarketClose=7]="MarketClose",m[m.EarlyClose=8]="EarlyClose",m[m.AddTPSL=9]="AddTPSL",m[m.SecurityDeposit=10]="SecurityDeposit",m[m.TransferToWallet=11]="TransferToWallet",m[m.MarginAccountDeposit=12]="MarginAccountDeposit",m[m.ReferralReward=13]="ReferralReward",m[m.ReferralRewardClaim=14]="ReferralRewardClaim",m))($a||{}),Ha=(n=>(n[n.Unknown=0]="Unknown",n[n.GTE=1]="GTE",n[n.LTE=2]="LTE",n))(Ha||{}),Qa=(t=>(t[t.Long=0]="Long",t[t.Short=1]="Short",t))(Qa||{}),Ka=(a=>(a[a.Cancelled=1]="Cancelled",a[a.Expired=2]="Expired",a[a.Successful=9]="Successful",a[a.PartialFilled=8]="PartialFilled",a))(Ka||{}),Ja=(u=>(u[u.Market=1]="Market",u[u.Limit=2]="Limit",u[u.TP=3]="TP",u[u.SL=4]="SL",u[u.ADL=5]="ADL",u[u.ADLTrigger=6]="ADLTrigger",u[u.Liquidation=7]="Liquidation",u[u.EarlyClose=8]="EarlyClose",u[u.MarketClose=9]="MarketClose",u))(Ja||{}),ja=(d=>(d[d.Open=0]="Open",d[d.PartialClose=1]="PartialClose",d[d.FullClose=2]="FullClose",d[d.Liquidation=3]="Liquidation",d[d.EarlyClose=4]="EarlyClose",d[d.MarketClose=5]="MarketClose",d[d.ADL=6]="ADL",d[d.TP=7]="TP",d[d.SL=8]="SL",d[d.Increase=9]="Increase",d))(ja||{}),Ya=(n=>(n[n.MarginAccount=1]="MarginAccount",n[n.WalletAccount=2]="WalletAccount",n[n.ReferralReward=3]="ReferralReward",n))(Ya||{});var Xa=(a=>(a[a.EXECUTING=1]="EXECUTING",a[a.BROADCAST_FAILED=2]="BROADCAST_FAILED",a[a.TIMEOUT_CANCEL=3]="TIMEOUT_CANCEL",a[a.EXECUTED=9]="EXECUTED",a))(Xa||{});var Ar=async()=>x.get(`${ne()}/openapi/gateway/scan/market/list`);var ne=()=>{let{isTestnet:s,isBetaMode:e}=se?.getConfigManager()?.getConfig()||{};return e?"https://api-beta.myx.finance":s?"https://api-test.myx.cash":"https://api.myx.finance"},ae=async(s,e=[])=>e.length?x.get(`${ne()}/openapi/gateway/quote/price/oracles`,{chainId:s,poolIds:e.join(",")}):Promise.reject(new Error("Invalid pool id")),bn=async(s,e)=>await x.get(`${ne()}/openapi/gateway/scan/market/info?chainId=${s}&poolId=${e}`),In=async(s,e,t)=>await x.get(`${ne()}/openapi/gateway/scan/market/pool-order/open?chainId=${t}`,void 0,{headers:{myx_openapi_access_token:s,myx_openapi_account:e}}),Tr=async({chainId:s,poolIds:e},t)=>x.get(`${ne()}/openapi/gateway/quote/candle/tickers`,{chainId:s,poolIds:e.join(",")}),Rr=async({...s})=>x.get(`${ne()}/openapi/gateway/scan/market/base-details`,s),vr=async({...s})=>x.get(`${ne()}/openapi/gateway/scan/market/detail`,s),hn=async()=>x.get(`${ne()}/openapi/gateway/scan/market`);var ke,Ct=class Ct{constructor(){this.version="1.0.2";Yt(this,ke);console.log("MxSDK version:",this.version)}setConfigManager(e){Xt(this,ke,e)}getConfigManager(){return jt(this,ke)}setProvider(e){this.provider=e}getProvider(){return this.provider}static getInstance(){return this._instance||(this._instance=new Ct),this._instance}async getMarkets(){try{let t=(await hn())?.data||[];return this.Markets=t,t}catch(e){throw e}}};ke=new WeakMap;var ue=Ct,xn=ue.getInstance(),se=xn,Za=async s=>{let e=xn.getConfigManager();if(!e?.hasSigner())throw new Error("No signer: call auth({ signer }) or auth({ walletClient })");return e.getViemWalletClient(s)};var An={USDC:"0x55d398326f99059fF775485246999027B3197955",POOL_MANAGER:"0x13F2130c2F3bfd612BBCBF35FB9E467dd32bAF3A",Account:"0xa32D0550F127fCFF0FA13D21523c5d4a2b86595D",POSITION_MANAGER:"0x93062Ec7Ef0aCf73c877A1d816A6CECc736d018e",ORDER_MANAGER:"0x9438d539e169b72FC2bEC819D4165ABe488921CD",PYTH:"0x4D7E825f80bDf85e913E0DD2A2D54927e9dE1594",ERC20:"0x55d398326f99059fF775485246999027B3197955",LIQUIDITY_ROUTER:"0x06d76c78B56D361de01A8903deA8aCEFFe6251d6",BASE_POOL:"0x59E365A627C5A1CE459e8e3489C97Ab2BEd56FEa",QUOTE_POOL:"0xB1E6df749A602892FafB27bb39Fd4F044527121E",ORACLE:"0xcb0F698f8FC931d97520a61296D0cA05688B8836",EIP7702Delegation:"0xF27e4C5bb5328453C37eD000170a3e16D6C68689",MARKET_MANAGER:"0x7fbEAd5ef0cDb301fe0e5555819f1d99F8a08468",DATA_PROVIDER:"0xD689523Ed33479DC9b5A43bC65568b9240c8D612",ORACLE_RESERVE:"0xaBde34Cb13ab013292576F3C5a0919B65C59CE80",FORWARDER:"0x54aE996239e9ca5d37a8933Df752144279aE266c",TRADING_ROUTER:"0xb2aDa5ebc0641fb81c182C1eF4E4bee0dc0Fef98",REIMBURSEMENT:"0xdE1aB9C84DFB0C2e6965889bDE152bEdD97E305a",DISPUTE_COURT:"0xc35EA4657211315de5270d7d882Ea7161F653368"};var w=s=>{let{isBetaMode:e}=se?.getConfigManager()?.getConfig()||{};switch(s){case 421614:return e?dn:un;case 59141:return e?ln:cn;case 97:return e?yn:mn;case 56:return An;default:return{}}};var Se=s=>s===421614?"0x7e248ec1721639413a280d9e82e2862cae2e6e28":s===59141?"":s===97?"0xe944d7c0f7005a76e898ee3b9ec10479eba9cc02":s===56?"0x8bfc51e1928e91e47c6734983ac018b2fc0adf4e":"";var de=(s,e)=>{let t=h(s);return k({address:e,abi:Q,client:t})},Le=async(s,e)=>{let t=await N(s);return k({address:e,abi:Q,client:t})},B=async s=>{let e=await N(s),[t]=await e.getAddresses();return t??void 0},_=async s=>{let e=w(s),t=await N(s);return k({address:e.LIQUIDITY_ROUTER,abi:Zt,client:t})},le=(s,e=1)=>{let t=w(s),n=e===0?h(s):null;return n?Promise.resolve(k({address:t.POOL_MANAGER,abi:ft,client:n})):N(s).then(a=>k({address:t.POOL_MANAGER,abi:ft,client:a}))};var ie=(s,e=0)=>{let t=w(s),n=e===0?h(s):null;return n?Promise.resolve(k({address:t.QUOTE_POOL,abi:gt,client:n})):N(s).then(a=>k({address:t.QUOTE_POOL,abi:gt,client:a}))},Z=(s,e=0)=>{let t=w(s),n=e===0?h(s):null;return n?Promise.resolve(k({address:t.BASE_POOL,abi:bt,client:n})):N(s).then(a=>k({address:t.BASE_POOL,abi:bt,client:a}))},V=async(s,e)=>{let t=await N(s);return k({address:e,abi:O,client:t})},re=(s,e)=>k({address:s,abi:O,client:e}),he=(s,e)=>{let t=h(s);return k({address:e,abi:O,client:t})};var Cn=(s,e,t=0)=>{let n=t===0?h(s):null;return n?Promise.resolve(k({address:e,abi:It,client:n})):N(s).then(a=>k({address:e,abi:It,client:a}))},oe=(s,e=0)=>{let t=w(s),n=e===0?h(s):null;return n?Promise.resolve(k({address:t.MARKET_MANAGER,abi:ht,client:n})):N(s).then(a=>k({address:t.MARKET_MANAGER,abi:ht,client:a}))},xe=(s,e=0)=>{let t=w(s),n=e===0?h(s):null;return n?Promise.resolve(k({address:t.DATA_PROVIDER,abi:xt,client:n})):N(s).then(a=>k({address:t.DATA_PROVIDER,abi:xt,client:a}))},wt=async s=>{let e=w(s),t=await N(s);return k({address:e.Account,abi:Ee,client:t})},F=(s,e=0)=>{let t=w(s),n=e===0?h(s):null;return n?Promise.resolve(k({address:t.FORWARDER,abi:Re,client:n})):N(s).then(a=>k({address:t.FORWARDER,abi:Re,client:a}))},wn=(s,e=0)=>{let t=w(s),n=e===0?h(s):null;return n?Promise.resolve(k({address:t.REIMBURSEMENT,abi:At,client:n})):N(s).then(a=>k({address:t.REIMBURSEMENT,abi:At,client:a}))},Pn=(s,e=0)=>{let t=w(s),n=e===0?h(s):null;return n?Promise.resolve(k({address:t.DISPUTE_COURT,abi:ve,client:n})):N(s).then(a=>k({address:t.DISPUTE_COURT,abi:ve,client:a}))};import{ErrorType as Tn,ErrorDecoder as es}from"ethers-decode-error";var Ae={"0xfa52dfc0":"AccountInsufficientFreeAmount()","0xe2a1a260":"AccountInsufficientReservedAmount()","0xffd10028":"AccountInsufficientTradableAmount(uint256,uint256)","0x9996b315":"AddressEmptyCode(address)","0x4c9c8ce3":"ERC1967InvalidImplementation(address)","0xb398979f":"ERC1967NonPayable()","0xd6bda275":"FailedCall()","0xf92ee8a9":"InvalidInitialization()","0x44d3438f":"NotAddressManager()","0x3fc81f20":"NotDependencyManager()","0xd7e6bcf8":"NotInitializing()","0x507f487a":"NotProxyAdmin()","0xe03f6024":"PermissionDenied(address,address)","0x5274afe7":"SafeERC20FailedOperation(address)","0xe07c8dba":"UUPSUnauthorizedCallContext()","0xaa1d49a4":"UUPSUnsupportedProxiableUUID(bytes32)","0x24775e06":"SafeCastOverflowedUintToInt(uint256)","0xba767932":"ConvertAmountMismatch(uint256,uint256)","0xd93c0665":"EnforcedPause()","0x8dfc202b":"ExpectedPause()","0x059e2f49":"InRewindMode()","0x42301c23":"InsufficientOutputAmount()","0xcaa99aac":"MismatchExecuteFee(uint256,uint256,uint256)","0x8637dfc0":"NotInRewindMode()","0x4578ddb8":"OnlyRelayer()","0x1e4fbdf7":"OwnableInvalidOwner(address)","0x118cdaa7":"OwnableUnauthorizedAccount(address)","0x3ee5aeb5":"ReentrancyGuardReentrantCall()","0x90b8ec18":"TransferFailed()","0xbe1af266":"InternalOnly()","0x3385aa1f":"ExceedOrderSize(uint256)","0xb07e3bc4":"InsufficientCollateral(uint256,uint256)","0x613970e0":"InvalidParameter()","0x27d08510":"NotActiveBroker(address)","0xf6412b5a":"NotOrderOwner()","0x70d645e3":"NotPositionOwner()","0xe75316c6":"OrderNotExist(OrderId)","0xba01b06f":"PoolNotActive(PoolId)","0xddefae28":"AlreadyMinted()","0x64283d7b":"ERC721IncorrectOwner(address,uint256,address)","0x177e802f":"ERC721InsufficientApproval(address,uint256)","0xa9fbf51f":"ERC721InvalidApprover(address)","0x5b08ba18":"ERC721InvalidOperator(address)","0x89c62b64":"ERC721InvalidOwner(address)","0x64a0ae92":"ERC721InvalidReceiver(address)","0x73c6ac6e":"ERC721InvalidSender(address)","0x7e273289":"ERC721NonexistentToken(uint256)","0xb4762117":"ExceedMaxLeverage(PositionId)","0x29143a42":"ExceedPositionSize()","0x8ea9158f":"InvalidPosition(PositionId)","0xa5afd143":"PositionNotHealthy(PositionId,uint256)","0xba0d3752":"PositionNotInitialized(PositionId)","0xc20f35b7":"UnderflowOI()","0xf4d678b8":"InsufficientBalance()","0x6aee3c1a":"InsufficientRiskReserves()","0x2c5211c6":"InvalidAmount()","0x82cb17ef":"InvalidSplitConfig()","0xe921c36b":"AlreadyMigrated(PositionId,PositionId)","0xd34e366f":"ExceedBaseCollateral(uint256,uint256)","0xc7544914":"ExceedDebt(uint256,uint256)","0xe7aa687a":"ExceedExchangeable()","0x4b3c8f33":"ExceedMaxBaseProfit()","0xdc82bd68":"ExceedMinOutputAmount()","0xdb42144d":"InsufficientBalance(address,uint256,uint256)","0x5646203f":"InsufficientCollateral(PositionId,uint256)","0x9ac13039":"InsufficientPoolProfit()","0x14be833f":"InsufficientReturnAmount(uint256,uint256)","0x419ecd12":"MatchNotSupported()","0x4ec4fd74":"PoolFundingFeeNotPositive(int256,uint256,Direction)","0xba8f5df5":"PoolNotCompoundable(PoolId)","0xf645eedf":"ECDSAInvalidSignature()","0xfce698f7":"ECDSAInvalidSignatureLength(uint256)","0xd78bce0c":"ECDSAInvalidSignatureS(bytes32)","0x48834bee":"ExpiredFeeData()","0x56d69198":"InvalidFeeRate()","0x80577032":"NoRebateToClaim()","0x6e6b79b0":"NotBrokerSigner(address)","0xff70343d":"UnsupportedAssetClass(AssetClass)","0x185676be":"UnsupportedFeeTier(uint8)","0x60b25fe4":"BrokerAlreadyExists()","0x7eb4a674":"BrokerNotFound()","0x8c3b5bf0":"NotBrokerAdmin()","0x3733548a":"InvalidFeeTier()","0x192105d7":"InitializationFunctionReverted(address,bytes)","0x97c7f537":"ExcessiveSlippage()","0x700deaad":"InvalidADLPosition(OrderId,PositionId)","0xf64fa6a8":"InvalidOrder(OrderId)","0xd4944235":"NoADLNeeded(OrderId)","0xe079169e":"NotReachedPrice(OrderId,uint256,uint256,TriggerType)","0xc60eb335":"OnlyKeeper()","0xa8ce4432":"SafeCastOverflowedIntToUint(int256)","0x17229ec4":"NotMeetEarlyCloseCriteria(PositionId)","0x0dc149f0":"AlreadyInitialized()","0x7a5c919f":"InvalidRewindPrice()","0xc53f84e7":"PositionRemainsHealthy(PositionId)","0x1dab59cf":"InvalidOrderPair(OrderId,OrderId)","0x230e8e43":"PoolNotInPreBenchState(PoolId)","0x107dec14":"RiskCloseNotAllowed()","0x664431a8":"NotAllowedTarget(address)","0x03357c6c":"ExceedsMaximumRelayFee()","0x0d10f63b":"InconsistentParamsLength()","0x38802743":"InsufficientFeeAllowance(address,uint256,uint256)","0xd95b4ad5":"InsufficientFeeBalance(address,uint256,uint256)","0xa3972305":"MismatchedSender(address)","0xc3b80e86":"RelayerRegistered(address)","0xee0844a3":"RemoveRelayerFailed()","0xc583a8da":"IncorrectFee(uint256)","0x00bfc921":"InvalidPrice()","0x148cd0dd":"VerifyPriceFailed()","0xb12d13eb":"ETHTransferFailed()","0xa83325d4":"PoolOracleFeeCharged()","0x6b75f90d":"PoolOracleFeeNotCharged()","0x42a0e2a7":"PoolOracleFeeNotExisted()","0x8ee01e1c":"PoolOracleFeeNotSoldOut()","0x5e0a829b":"ETHTransferFailed(address,uint256)","0x4ba6536f":"GasLimitExceeded(address,uint256,uint256)","0xca1aae4b":"GasLimitNotSet(address)","0x3728b83d":"InvalidAmount(uint256)","0x3484727e":"BaseFeeNotSoldOut()","0x0251bde4":"LPNotFullyMinted()","0x1acb203e":"PositionNotEmpty()","0x2be7b24b":"UnexpectedPoolState()","0x759b3876":"UnhealthyAfterRiskTierApplied(PositionId)","0x7bd42a2e":"NotEmptyAddress()","0x6697b232":"AccessControlBadConfirmation()","0xe2517d3f":"AccessControlUnauthorizedAccount(address,bytes32)","0x7c9a1cf9":"AlreadyVoted()","0x796ea3a6":"BondNotReleased()","0x6511c20d":"BondZeroAmount()","0xf38e5973":"CaseAppealNotFinished()","0x1eaa4a59":"CaseDeadlineNotReached()","0xe6c67e3a":"CaseDeadlineReached()","0x0fc957b1":"CaseNotAccepted()","0x3ddb819d":"CaseNotExist(CaseId)","0x79eab18d":"CaseRespondentAppealed(CaseId,address)","0xa179f8c9":"ChainIdMismatch()","0x311c16d3":"DisputeNotAllowed()","0x752d88c0":"InvalidAccountNonce(address,uint256)","0xa710429d":"InvalidContractAddress()","0x8076dd8a":"InvalidFunctionSignature()","0xc37906a0":"InvalidPayloadLength(uint256,uint256)","0xdcdedda9":"InvalidPoolToken()","0x3471a3c2":"InvalidProfitAmount()","0x1d9617a0":"InvalidResponseVersion()","0x9284b197":"InvalidSourceChain()","0xb9021668":"NoChainResponse()","0xc546bca4":"NotCaseRespondent(CaseId,address)","0x84ae4a30":"NumberOfResponsesMismatch()","0x02164961":"RequestTypeMismatch()","0x4cf72652":"RiskCloseNotCompleted()","0x0819bdcd":"SignatureExpired()","0xc00ca938":"UnexpectedCaseState()","0x7935e939":"UnexpectedCaseType()","0x5e7bd6ec":"UnexpectedNumberOfResults()","0x51ee5853":"UnsupportedQueryType(uint8)","0x29ca666b":"UntrustfulVoting()","0x439cc0cd":"VerificationFailed()","0x714f5513":"VersionMismatch()","0x96b8e05b":"WrongQueryType(uint8,uint8)","0xbb6b170d":"ZeroQueries()","0xa9214540":"AlreadyClaimed(CaseId,address)","0xd4ac59c1":"InvalidAmount(CaseId,address)","0x7a6f5328":"MerkleTreeVerificationFailed(CaseId,address)","0x094a5cfe":"ReimbursementValidity(CaseId)","0x8b922563":"TreeAlreadySet()","0x7b27120a":"InDisputeMode()","0xb04111ef":"InsufficientFreeCollateral(PositionId,uint256)","0x12f1b11a":"InsufficientLockedCollateral(PositionId,uint256)","0x6dfcc650":"SafeCastOverflowedUintDowncast(uint8,uint256)","0xd24b47fb":"UserProfitFrozen()","0x1c151780":"ExceedMinOutput(uint256,uint256)","0xe1f0493d":"NotAllowedCaller(address)","0xfb8f41b2":"ERC20InsufficientAllowance(address,uint256,uint256)","0xe450d38c":"ERC20InsufficientBalance(address,uint256,uint256)","0xe602df05":"ERC20InvalidApprover(address)","0xec442f05":"ERC20InvalidReceiver(address)","0x96c6fd1e":"ERC20InvalidSender(address)","0x94280d62":"ERC20InvalidSpender(address)","0x62791302":"ERC2612ExpiredSignature(uint256)","0x4b800e46":"ERC2612InvalidSigner(address,address)","0xb3512b0c":"InvalidShortString()","0x305a27a9":"StringTooLong(string)","0xfd0f789d":"ExceedMaxPriceDeviation()","0x407b87e5":"ExchangeRateAlreadyApplied()","0x5c6c5686":"ExchangeRateAlreadyDisabled()","0x1ae17fcd":"InvalidDeviationRatio()","0x18b88897":"InvalidUpdateFee()","0xf76740e3":"PriceDeviationBelowMinimum()","0x49386283":"PriceDeviationThresholdReached()","0x19abf40e":"StalePrice()","0xe351cd13":"ExceedMaxExchangeableAmount()","0x15912a6f":"NotSupportVersion()","0xf1364a74":"ArrayEmpty()","0x15ed381d":"ExceedMaxProfit()","0x51aeee6c":"PoolNotExist(PoolId)","0x70f6c197":"InvalidQuoteTokenAddress()","0x0b8457f4":"InvalidRatioParams()","0x29dae146":"MarketAlreadyExisted()","0xf040b67a":"MarketNotExisted()","0x0e442a4a":"InvalidBaseToken()","0x24e219c7":"MarketNotExist(MarketId)","0xcc36f935":"PoolExists(PoolId)","0xe84c308d":"ExceedBaseReserved(uint256,uint256)","0x3e241751":"ExceedQuoteReserved(uint256,uint256)","0xde656889":"ExceedReservable(uint256,uint256,uint256)","0xd54d0fc4":"InsufficientLiquidity(uint256,uint256,uint256)","0x7e562a65":"InvalidDistributionAmount()","0x83c7580d":"ReservableNotEnough(uint256,uint256)","0x94eef58a":"ERC2771ForwarderExpiredRequest(uint48)","0xc845a056":"ERC2771ForwarderInvalidSigner(address,address)","0x70647f79":"ERC2771ForwarderMismatchedValue(uint256,uint256)","0xd2650cd1":"ERC2771UntrustfulTarget(address,address)","0xcf479181":"InsufficientBalance(uint256,uint256)","0x4c150d8f":"DifferentMarket(PoolId,PoolId)","0xaa98b06a":"InsufficientQuoteIn(uint256,uint256,uint256)","0x3e589bee":"InvalidLiquidityAmount()","0xaebd3617":"InvalidTpsl(uint256)","0x7fe81129":"SamePoolMigration(PoolId)","0x71c4efed":"SlippageExceeded(uint256,uint256)","0x62b9bc7b":"DesignatedTokenMismatch(address,address)","0x49465eb0":"NotForwardAllowedTarget(address)","0x301b6707":"ExecutionFeeNotCollected()","0xc6e8248a":"InsufficientSize()","0xd15b4fe2":"InvalidQuoteToken()","0xd8daec7c":"MarketNotInitialized()","0xcd4891b6":"NotInDisputeMode()","0x1ad308dc":"OrderExpired(OrderId)","0x486aa307":"PoolNotInitialized()"};var ts=es.create();var D={1:"Invalid Chain",2:"Invalid Token Address",4001:"User Rejected",3:"Insufficient Balance",4:"Insufficient Amount Of Approved",4002:"Invalid Base Token Address",4003:"Invalid Slippage",4004:"Invalid Amount",4005:"Invalid Pool State",4006:"Invalid Params",4007:"Invalid Amount Withdrawable LP Amount"};function ns(s){return s?.code===4001}async function I(s){if(ns(s))return{error:D[4001]};let e=await ts.decode(s);if(console.log(e),e.type===Tn.UserRejectError||e.name==="ACTION_REJECTED")return{error:D[4001]};if(e.type===Tn.CustomError){let t=Object.keys(Ae).find(n=>n.toLowerCase()===e.selector.toLowerCase());return t?{error:{code:t,message:Ae[t]}}:{error:{code:s?.code,message:s?.reason||e.reason||s.message}}}return{error:{code:e.type,message:e.reason}}}var Rn=async(s,e,t)=>{try{return await h(s).readContract({address:t,abi:Q,functionName:"balanceOf",args:[e]})}catch(n){throw console.error(n),n}};import{maxUint256 as as,parseUnits as ss}from"viem";var vn=async(s,e,t,n,a)=>{try{return await h(s).readContract({address:t,abi:Q,functionName:"allowance",args:[e,n]})>=a}catch(i){throw i}};var En=async(s,e,t,n,a)=>{try{let i=await Le(s,t);if(!i.write)throw new Error("Wallet client required for write");let r=await i.write.approve([n,a]);await h(s).waitForTransactionReceipt({hash:r})}catch(i){throw i}};var v=async s=>{if("chainId"in s&&!Ne(s.chainId))throw new Error(D[1]);if("slippage"in s&&!(Number(s?.slippage)<=1&&Number(s?.slippage)>0))throw new Error(D[4003]);if("amount"in s&&(Number(s.amount)===Number.NaN||Number(s.amount)<0))throw new Error(D[4004]);let{tokenAddress:e,contractAddress:t,chainId:n,amount:a,decimals:i,account:r}=s;if(a&&n&&Number(i)>=0&&r){let p=ss(a.toString(),Number(i));if(e){let o=await Rn(n,r,e);if(!o||o<p)throw new Error(D[3])}t&&e&&(await vn(n,r,e,t,p)||await En(n,r,e,t,as))}};import{parseUnits as Pt}from"viem";var S=30,W=18;var R=(s,e)=>BigInt(s)*Pt(e.toString(),8)/BigInt(10**8),T=async s=>{try{let e=C[s],n=await h(s).getGasPrice();if(n==null)throw new Error("Network Error");return{gasPrice:R(n,e.gasPriceRatio)}}catch(e){throw e}},ee=(s,e=.01)=>{let t=Pt("1",8)-Pt(e.toString(),8);return s*t/BigInt(10**8)};import{isNil as is}from"lodash-es";var kn=async(s,e)=>await Promise.all(e.map(async n=>{let{publishTime:a,vaa:i,oracleType:r,nativeFee:p,price:o,poolId:u}=n,d=is(p)?1n:BigInt(p);return{poolId:u,price:o,value:d,publishTime:a,oracleType:r??2,vaa:i}})),Ce=async(s,e)=>{if(!e||!e.length)return;let t=await ae(s,e);return await kn(s,t.data)},z=async(s,e)=>{if(!e)return;let n=(await ae(s,[e]))?.data?.[0];if(!n)throw new Error(`Unable to get price for ${e} in the deposit`);return(await kn(s,[n]))?.[0]};var Sn=async s=>{try{let{chainId:e,poolId:t}=s,n=C[e],a=await B(e);await v({account:a,chainId:e});let i=await Ce(e,[t]);if(!i)return;let r=i.map(f=>f.value),p=i.map(f=>({poolId:t,oracleUpdateData:f?.vaa??"0",publishTime:f.publishTime,oracleType:f.oracleType})),o={prices:p,values:r,poolId:t,recipient:a},u=await _(e),d=await u.estimateGas.claimBasePoolRebate([p,t,a],{value:r[0]}),l=R(d,n.gasLimitRatio),{gasPrice:y}=await T(e);return await u.write.claimBasePoolRebate([p,t,a],{gasLimit:l,gasPrice:y,value:r[0]})}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}},Mn=async s=>{try{let{chainId:e,poolIds:t}=s;if(t.length===0)return;let n=C[e],a=await B(e);await v({account:a,chainId:e});let i=await Ce(e,t);if(!i)return;let r=i.map(m=>({poolId:m.poolId,oracleUpdateData:m?.vaa??"0",publishTime:m.publishTime,oracleType:m.oracleType})),o=i.map(m=>m.value).reduce((m,b)=>b+m,0n),u={prices:r,poolIds:t,value:o,recipient:a},d=await _(e),l=await d.estimateGas.claimBasePoolRebates([r,t,a],{value:o}),y=R(l,n.gasLimitRatio),{gasPrice:c}=await T(e);return await d.write.claimBasePoolRebates([r,t,a],{gasLimit:y,gasPrice:c,value:o})}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}};import{parseUnits as Nn}from"viem";import{parseUnits as Dn}from"viem";var Tt=async({chainId:s,amountIn:e,poolId:t,price:n=0n})=>{try{let a=C[s],i=await Z(s),r=await i.estimateGas.previewLpAmountOut([t,e,n]),p=R(r,a.gasLimitRatio),{gasPrice:o}=await T(s);return await i.read.previewLpAmountOut([t,e,n],{gasLimit:p,gasPrice:o})}catch(a){throw console.error(a),typeof a=="string"?a:await I(a)}},Rt=async({chainId:s,amountIn:e,poolId:t,price:n=0n})=>{try{let a=C[s],i=await Z(s),r=await i.estimateGas.previewBaseAmountOut([t,e,n]),p=R(r,a.gasLimitRatio),{gasPrice:o}=await T(s);return await i.read.previewBaseAmountOut([t,e,n],{gasLimit:p,gasPrice:o})}catch(a){throw console.error(a),typeof a=="string"?a:await I(a)}},On=async({chainId:s,account:e,poolId:t,amount:n=0})=>{try{if(!s||!e||!t)return;if(!n)return{baseAmountOut:0n,rebateAmount:0n};let a=C[s],i=18;await v({decimals:i,account:e,chainId:s,amount:Number(n)});let r=Dn(n.toString(),i),o=(await ae(s,[t])).data?.[0]?.price||"0",u=Dn(o,30),d=await Z(s),l=await d.estimateGas.previewUserWithdrawData([t,r,e,u]),y=R(l,a.gasLimitRatio),{gasPrice:c}=await T(s),f=await d.read.previewUserWithdrawData([t,r,e,u],{gasLimit:y,gasPrice:c}),{baseAmountOut:m,rebateAmount:b}=f;return{baseAmountOut:m,rebateAmount:b}}catch(a){throw typeof a=="string"?a:await I(a)}};var L=async(s,e)=>{try{return!s||!e?void 0:(await bn(s,e)).data}catch(t){throw typeof t=="string"?t:await I(t)}};import{parseUnits as vt}from"viem";function Fn(s){return s.includes(".")?s.split(".")[1].length:0}var we=(s=.01,e=[],t=18,n)=>{if(e.length===0)return[];if(e.filter(i=>i.amount&&i.triggerPrice&&i.triggerType).length===0)throw new Error(D[4006]);return e.map(i=>{let r=vt(i.amount.toString(),t),p=vt(i.triggerPrice.toString(),30),o=Fn(i.triggerPrice.toString()),u=vt(i.triggerPrice.toString(),o),d=ee(r*u*BigInt(10**n)/BigInt(10**(o+t)),s);return{amount:r,triggerPrice:p,triggerType:BigInt(i.triggerType),minQuoteOut:d}})};var _n=async s=>{try{let{poolId:e,chainId:t,amount:n,slippage:a=.01,tpsl:i=[]}=s;await v(s);let r=await L(t,e);if(!r)throw new Error(D[4006]);let p=r?.baseDecimals,o=r?.quoteDecimals,u=r?.baseToken,d=C[t],l=await B(t),c=w(t).BASE_POOL;await v({tokenAddress:u,contractAddress:c,decimals:p,account:l,chainId:t,amount:n});let f=!(Number(r?.state)===0||Number(r?.state)===1),m=[],b=Nn(n.toString(),p),A=0n,P;if(f){let J=await z(t,e);if(!J)return;let ba=Nn(J.price,30);m.push({poolId:e,oracleUpdateData:J.vaa,publishTime:BigInt(J.publishTime),oracleType:J.oracleType}),P=await Tt({chainId:t,poolId:e,amountIn:b,price:ba}),A=J.value}else P=await Tt({chainId:t,poolId:e,amountIn:b});let M=i.map(J=>({amount:n,triggerPrice:J.triggerPrice,triggerType:J.triggerType})),U=we(a,M,p,o),G={poolId:e,amountIn:b,minAmountOut:ee(P,a),recipient:l,tpslParams:U},E=await _(t),q=await E.estimateGas.depositBase([m,G],{value:A}),X=R(q,d.gasLimitRatio),{gasPrice:ge}=await T(t);return await E.write.depositBase([m,G],{gasLimit:X,gasPrice:ge,value:A})}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}};import{parseUnits as Ue}from"viem";var Bn=async s=>{try{let{chainId:e,poolId:t,price:n}=s,a=n,i=await Z(e);if(typeof n>"u"||n===null)try{let o=await z(e,t);a=Ue(o?.price||"0",30)}catch{a=Ue("0",30)}let r={poolId:t,price:a||0n};return await i.withdrawableLpAmount(t,a||0n)}catch(e){throw typeof e=="string"?e:await I(e)}},Ln=async s=>{try{let{chainId:e,poolId:t,amount:n,slippage:a=.01}=s,i=await L(e,t),r=i?.basePoolToken,p=C[e],o=await B(e),u=18;await v({tokenAddress:r,decimals:u,account:o,chainId:e,amount:n});let d=Ue(n.toString(),u),l=!(Number(i?.state)===0||Number(i?.state)===1),y=[],c=0n,f;if(l){let E=await z(e,t);if(!E)return;let q=Ue(E.price,30);y.push({poolId:t,oracleUpdateData:E.vaa,publishTime:BigInt(E.publishTime),oracleType:E.oracleType}),f=await Rt({chainId:e,poolId:t,amountIn:d,price:q}),c=E.value}else f=await Rt({chainId:e,poolId:t,amountIn:d});let m={poolId:t,amountIn:d,minAmountOut:ee(f,a),recipient:o},b=await _(e),A=await b.estimateGas.withdrawBase([y,m],{value:c}),P=R(A,p.gasLimitRatio),{gasPrice:M}=await T(e);return await(await b.write.withdrawBase([y,m],{gasLimit:P,gasPrice:M,value:c}))?.wait()}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}};import{parseUnits as rs}from"viem";var Un=async s=>{try{let{chainId:e,account:t,poolId:n}=s;if(!e||!t||!n)return;let a=C[e],i=0n,p=(await ae(e,[n])).data?.[0]?.price||"0",o=rs(p,30),u=await Z(e),d=await u.estimateGas.pendingUserRebates([n,t,o]),l=R(d,a.gasLimitRatio),{gasPrice:y}=await T(e),c=await u.read.pendingUserRebates([n,t,o],{gasLimit:l,gasPrice:y});return{rebates:c?.rebates,genesisRebates:c?.genesisRebates}}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}};import{parseUnits as os}from"viem";var Gn=async(s,e)=>{if(e)try{let t=await Z(s),n=0n,a=await z(s,e);return a?.price&&(n=os(a.price,30)),await t.getPoolTokenPrice(e,n)}catch(t){throw typeof t=="string"?t:await I(t)}};var Mt={};lt(Mt,{claimQuotePoolRebate:()=>Qn,claimQuotePoolRebates:()=>Kn,deposit:()=>Wn,getLpPrice:()=>Jn,getRewards:()=>Hn,transfer:()=>$n,withdraw:()=>Vn,withdrawableLpAmount:()=>zn});import{parseUnits as qn}from"viem";var kt=async({chainId:s,amountIn:e,poolId:t,price:n=0n})=>{try{let a=C[s],i=await ie(s),r=await i.estimateGas.previewLpAmountOut([t,e,n]),p=R(r,a.gasLimitRatio),{gasPrice:o}=await T(s);return await i.read.previewLpAmountOut([t,e,n],{gasLimit:p,gasPrice:o})}catch(a){throw console.error(a),typeof a=="string"?a:await I(a)}},St=async({chainId:s,amountIn:e,poolId:t,price:n=0n})=>{try{let a=C[s],i=await ie(s),r=await i.estimateGas.previewQuoteAmountOut([t,e,n]),p=R(r,a.gasLimitRatio),{gasPrice:o}=await T(s);return await i.read.previewQuoteAmountOut([t,e,n],{gasLimit:p,gasPrice:o})}catch(a){throw console.error(a),typeof a=="string"?a:await I(a)}};var Wn=async s=>{try{let{poolId:e,chainId:t,amount:n,slippage:a=.01,tpsl:i=[]}=s;await v(s);let r=await L(t,e);if(!r)throw new Error(D[4006]);let p=C[t],o=await B(t),d=w(t).QUOTE_POOL,l=r.quoteToken,y=r?.quoteDecimals;await v({tokenAddress:l,contractAddress:d,decimals:y,account:o,chainId:t,amount:n});let c=qn(n.toString(),y),f=!(Number(r?.state)===0||Number(r?.state)===1),m=[],b=0n,A;if(f){let $=await z(t,e);if(!$)return;let J=qn($.price,30);m.push({poolId:e,oracleUpdateData:$.vaa,publishTime:BigInt($.publishTime),oracleType:$.oracleType}),A=await kt({chainId:t,poolId:e,amountIn:c,price:J}),b=$.value}else A=await kt({chainId:t,poolId:e,amountIn:c});let P=i.map($=>({amount:n,triggerPrice:$.triggerPrice,triggerType:$.triggerType})),M=we(a,P,y,y),U={poolId:e,amountIn:c,minAmountOut:ee(A,a),recipient:o,tpslParams:M},G=await _(t),E=await G.estimateGas.depositQuote([m,U],{value:b}),q=R(E,p.gasLimitRatio),{gasPrice:X}=await T(t);return await G.write.depositQuote([m,U],{gasLimit:q,gasPrice:X,value:b})}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}};import{parseUnits as Ge}from"viem";var zn=async s=>{try{let{chainId:e,poolId:t,price:n}=s,a=n,i=await ie(e);if(typeof n>"u"||n===null)try{let o=await z(e,t);a=Ge(o?.price||"0",30)}catch{a=Ge("0",30)}let r={poolId:t,price:a||0n};return await i.withdrawableLpAmount(t,a||0n)}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}},Vn=async s=>{try{let{chainId:e,poolId:t,amount:n,slippage:a=.01}=s,i=await L(e,t),r=i?.quotePoolToken,p=C[e],o=await B(e),u=18;await v({tokenAddress:r,decimals:u,account:o,chainId:e,amount:n});let d=Ge(n.toString(),u),l=!(Number(i?.state)===0||Number(i?.state)===1),y=[],c=0n,f;if(l){let E=await z(e,t);if(!E)return;let q=Ge(E.price,30);y.push({poolId:t,oracleUpdateData:E.vaa,publishTime:BigInt(E.publishTime),oracleType:E.oracleType}),f=await St({chainId:e,poolId:t,amountIn:d,price:q}),c=E.value}else f=await St({chainId:e,poolId:t,amountIn:d});let m={poolId:t,amountIn:d,minAmountOut:ee(f,a),recipient:o},b=await _(e),A=await b.estimateGas.withdrawQuote([y,m],{value:c}),P=R(A,p.gasLimitRatio),{gasPrice:M}=await T(e);return await(await b.write.withdrawQuote([y,m],{gasLimit:P,gasPrice:M,value:c}))?.wait()}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}};import{parseUnits as ps}from"viem";var $n=async(s,e,t,n)=>{try{let a=await L(s,e),i=await L(s,t);if(!i||!a)return null;if([3,4].includes(i.state))throw new Error(D[4005]);let r=await B(s),p=C[s],o=18;await v({chainId:s,amount:n,account:r,decimals:o,tokenAddress:a.quotePoolToken});let u={fromPoolId:e,toPoolId:t,minLpOut:0n,amount:ps(n.toString(),o)},d=await _(s),l=await d.estimateGas.migrateLiquidity([u]),y=R(l,p.gasLimitRatio),{gasPrice:c}=await T(s);return await d.migrateLiquidity(u,{gasLimit:y,gasPrice:c})}catch(a){throw typeof a=="string"?a:await I(a)}};import{parseUnits as us}from"viem";var Hn=async s=>{try{let{chainId:e,account:t,poolId:n}=s;if(!e||!t||!n)return;let a=C[e],r=(await ae(e,[n])).data?.[0]?.price||"0",p=us(r,30),o=await ie(e),u=await o.estimateGas.pendingUserRebates([n,t,p]),d=R(u,a.gasLimitRatio),{gasPrice:l}=await T(e);return await o.read.pendingUserRebates([n,t,p],{gasLimit:d,gasPrice:l})}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}};var Qn=async s=>{try{let{chainId:e,poolId:t}=s,n=C[e],a=await B(e),i=18;await v({account:a,chainId:e});let r=await Ce(e,[t]);if(!r)return;let p=r.map(m=>m.value),o=r.map(m=>({poolId:m.poolId,oracleUpdateData:m?.vaa??"0",publishTime:m.publishTime,oracleType:m.oracleType})),u={prices:o,values:p,poolId:t,recipient:a},d=await _(e),l=await d.estimateGas.claimQuotePoolRebate([o,t,a],{value:p[0]}),y=R(l,n.gasLimitRatio),{gasPrice:c}=await T(e);return await d.write.claimQuotePoolRebate([o,t,a],{gasLimit:y,gasPrice:c,value:p[0]})}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}},Kn=async s=>{try{let{chainId:e,poolIds:t}=s;if(t.length===0)return;let n=C[e],a=await B(e),i=18;await v({account:a,chainId:e});let r=await Ce(e,t);if(!r)return;let p=r.map(b=>({poolId:b.poolId,oracleUpdateData:b?.vaa??"0",publishTime:b.publishTime,oracleType:b.oracleType})),u=r.map(b=>b.value).reduce((b,A)=>A+b,0n),d={prices:p,value:u,poolIds:t,recipient:a},l=await _(e),y=await l.estimateGas.claimQuotePoolRebates([p,t,a],{value:u}),c=R(y,n.gasLimitRatio),{gasPrice:f}=await T(e);return await l.write.claimQuotePoolRebates([p,t,a],{gasLimit:c,gasPrice:f,value:u})}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}};import{parseUnits as ds}from"viem";var Jn=async(s,e)=>{if(e)try{let t=await ie(s),n=0n,a=await z(s,e);return a?.price&&(n=ds(a.price,30)),await t.getPoolTokenPrice(e,n)}catch(t){throw console.error(t),typeof t=="string"?t:await I(t)}};var Dt={};lt(Dt,{getMarket:()=>jn,getOracleFee:()=>Yn});var jn=async(s,e)=>{try{return await v({chainId:s}),e?await(await oe(s)).getMarket(e):void 0}catch(t){throw console.error(t),typeof t=="string"?t:await I(t)}};var Yn=async(s,e)=>{try{return await v({chainId:s}),e?await(await oe(s)).getOracleFee(e):void 0}catch(t){throw console.error(t),typeof t=="string"?t:await I(t)}};var De=async({chainId:s,baseToken:e,marketId:t})=>{try{if(!e)throw new Error(D[2]);let n=C[s],i=w(s).POOL_MANAGER,r=await le(s,0),p=[t,e],o=await r.getMarketPool(t,e);return o.poolId==="0x0000000000000000000000000000000000000000000000000000000000000000"||!o.poolId?void 0:o.poolId}catch(n){throw console.error(n),typeof n=="string"?n:await I(n)}},Ft=async s=>{try{return await(await le(s)).getPools()||[]}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}},Nt=async(s,e,t=0n)=>{try{let a=await(await xe(s)).read.getPoolInfo([e,t]);return{quotePool:{poolToken:a.quotePool.poolToken,exchangeRate:a.quotePool.exchangeRate,poolTokenPrice:a.quotePool.poolTokenPrice,poolTokenSupply:a.quotePool.poolTokenSupply,totalDebt:a.quotePool.totalDebt,baseCollateral:a.quotePool.baseCollateral},basePool:{poolToken:a.basePool.poolToken,exchangeRate:a.basePool.exchangeRate,poolTokenPrice:a.basePool.poolTokenPrice,poolTokenSupply:a.basePool.poolTokenSupply,totalDebt:a.basePool.totalDebt,baseCollateral:a.basePool.baseCollateral},reserveInfo:{baseTotalAmount:a.reserveInfo.baseTotalAmount,baseReservedAmount:a.reserveInfo.baseReservedAmount,quoteTotalAmount:a.reserveInfo.quoteTotalAmount,quoteReservedAmount:a.reserveInfo.quoteReservedAmount},fundingInfo:{nextFundingRate:a.fundingInfo.nextFundingRate,lastFundingFeeTracker:a.fundingInfo.lastFundingFeeTracker,nextEpochTime:a.fundingInfo.nextEpochTime},ioTracker:{tracker:a.oi.tracker,longSize:a.oi.longSize,shortSize:a.oi.shortSize,poolEntryPrice:a.oi.poolEntryPrice},liquidityInfo:{windowCaps:a.liquidityInfo.windowCaps,openInterest:a.liquidityInfo.openInterest}}}catch(n){throw console.error(n),typeof n=="string"?n:await I(n)}};var _t=async({chainId:s,baseToken:e,marketId:t})=>{try{if(!e)throw new Error(D[2]);let n=C[s],a=await le(s),i={marketId:t,baseToken:e},r=await a.estimateGas.deployPool([i]),p=R(r,n.gasLimitRatio),{gasPrice:o}=await T(s);if((await(await a.deployPool(i,{gasLimit:p,gasPrice:o}))?.wait())?.hash)return await De({chainId:s,baseToken:e,marketId:t})}catch(n){throw typeof n=="string"?n:await I(n)}};var Bt=async(s,e,t)=>{try{return await(await Cn(s,e)).userGenesisShare(t)}catch(n){throw console.error(n),typeof n=="string"?n:await I(n)}};var Lt=async s=>{try{let{chainId:e,poolId:t,poolType:n,slippage:a=.01,tpsl:i=[]}=s;await v(s);let r=await L(e,t);if(!r)throw new Error(D[4006]);let p=18,o=r.quoteDecimals,u=we(a,i,p,o),d=C[e],l=await _(e),y={poolId:t,poolType:BigInt(n),tpslParams:u},c=await l.estimateGas.addTpsl([y]),f=R(c,d.gasLimitRatio),{gasPrice:m}=await T(e);return await(await l.addTpsl(y,{gasLimit:f,gasPrice:m}))?.wait()}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}};var Ut=async s=>{try{let{chainId:e,orderId:t}=s;await v(s);let n=C[e],a=await _(e),i=await a.estimateGas.cancelTpsl([t]),r=R(i,n.gasLimitRatio),{gasPrice:p}=await T(e);return await(await a.cancelTpsl(t,{gasLimit:r,gasPrice:p}))?.wait()}catch(e){throw console.error(e),typeof e=="string"?e:await I(e)}};import{getAddress as cs,formatUnits as Xn}from"viem";async function ls(s){try{return(await fetch(s,{method:"HEAD"})).ok}catch{return!1}}var gc=async(s,e,t)=>{try{let n=h(s),a=e,[i,r,p,o]=await Promise.all([n.readContract({address:a,abi:Q,functionName:"name"}),n.readContract({address:a,abi:Q,functionName:"symbol"}),n.readContract({address:a,abi:Q,functionName:"decimals"}),n.readContract({address:a,abi:Q,functionName:"totalSupply"})]),u=cs(a),d=`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/${s}/assets/${u}/logo.png`,y=await ls(d)?d:"",c;if(t){let f=await n.readContract({address:a,abi:Q,functionName:"balanceOf",args:[t]});c=Number(Xn(f,Number(p)))}return{address:e,name:i,symbol:r,decimals:Number(p),icon:y,totalSupply:Number(Xn(o,Number(p))),...t?{balance:c}:{}}}catch(n){throw console.error(n),n}};import{formatUnits as ms,parseUnits as ys}from"viem";var Gt=async(s,e,t)=>{try{await v({chainId:s});let n=await L(s,e);if(!n)throw new Error(D[4006]);let a=await B(s),r=((se?.Markets?.length?se?.Markets:await se.getMarkets())||[])?.find(f=>f.chainId===s&&f.marketId===t);if(!r)throw new Error("Invalid Market");let p=ys(r.oracleFeeUsd.toString(),n.quoteDecimals);if(!p)throw new Error("Invalid Market");await v({tokenAddress:n.quoteToken,contractAddress:w(s).ORACLE_RESERVE,decimals:n.quoteDecimals,account:a,chainId:s,amount:Number(ms(p,n.quoteDecimals))});let o=C[s],u=await le(s),d=await u.estimateGas.reprimePool([{poolId:e}]),{gasPrice:l}=await T(s);return await(await u.reprimePool([{poolId:e}],{gasPrice:l}))?.wait()}catch(n){throw console.error(n),typeof n=="string"?n:await I(n)}};var qt=async(s,e)=>{try{let t=await ue.getInstance().getConfigManager()?.getAccessToken();if(!t)throw new Error("Failed to obtain accessToken");return(await In(t,e,s)).data||[]}catch(t){throw console.error(t),t}};import{formatUnits as Zc,parseUnits as el}from"viem";var fs={createPool:_t,getMarketPoolId:De,getMarketPools:Ft,getPoolInfo:Nt,getUserGenesisShare:Bt,addTpSl:Lt,cancelTpSl:Ut,reprime:Gt,getPoolDetail:L,getOpenOrders:qt};import xs from"mitt";import{Hex as gs,MD5 as bs}from"crypto-es";var qe=(s,e)=>bs(s,{outputLength:e||32}).toString(gs);var We=s=>{switch(s.request){case"signin":return qe(s.request)}return qe(JSON.stringify(s))},Oe=s=>{let{topic:e,params:t}=s;switch(e){case"candle":return`${e}.${t.globalId}_${t.resolution}`;case"ticker":return`${e}.${t.globalId}`;case"ticker.*":case"order":case"position":return e;default:return qe(JSON.stringify({topic:e,params:t}))}},ea=({type:s})=>s==="pong"||s==="signin"||s==="subv2"||s==="unsubv2"||s==="ping"||s==="pong",hs=s=>{switch(s){case"order":case"position":case"ticker.*":return s;default:let[e]=s.split(".");return e}},ta=s=>{switch(hs(s.type)){case"ticker":{let[,t=""]=s.type.split(".");return{...s,type:Oe({topic:"ticker",params:{globalId:parseInt(t)}}),globalId:parseInt(t)}}case"candle":{let[,t=""]=s.type.split("."),[n,a]=t.split("_");return{...s,type:Oe({topic:"candle",params:{globalId:parseInt(n),resolution:a}}),globalId:parseInt(n),resolution:a}}}return s};var Pe=class{constructor(e){this.options={...e,logLevel:e?.logLevel||"info"}}debug(e,...t){this.options.logLevel!=="none"&&this.options.logLevel==="debug"&&console.log(`[MYX-SDK-DEBUG] ${e}`,...t)}info(e,...t){this.options.logLevel!=="none"&&(this.options.logLevel==="debug"||this.options.logLevel==="info")&&console.log(`[MYX-SDK-INFO] ${e}`,...t)}error(e,...t){this.options.logLevel!=="none"&&(this.options.logLevel==="debug"||this.options.logLevel==="info"||this.options.logLevel==="error")&&console.error(`[MYX-SDK-ERROR] ${e}`,...t)}warn(e,...t){this.options.logLevel!=="none"&&console.warn(`[MYX-SDK-WARN] ${e}`,...t)}};var g=class extends Error{constructor(e,t){super(t),this.name=e}toJSON(){return{code:this.name,message:this.message}}toString(){return`[MYX-ERROR-${this.name}]: ${this.message}`}};import As from"reconnecting-websocket";var na={url:"",initialReconnectDelay:1e3,maxReconnectDelay:3e4,reconnectMultiplier:1.5,maxReconnectAttempts:10,maxEnqueuedMessages:100,requestTimeout:1e4,heartbeatInterval:1e4,heartbeatMessage:"ping",noMessageTimeout:5e3,connectionTimeout:1e4},ze=class{constructor(e){this.ws=null;this.subscriptions=new Map;this.waitingRequests=new Map;this.eventBus=xs();this.heartbeatIntervalId=null;this.isFirstConnection=!0;this.lastMessageTime=0;let t={...e,logLevel:e?.logLevel||"info"},{logLevel:n,...a}=t;this.config={...na,...a},this.logger=new Pe({logLevel:e?.logLevel}),this.logger.debug("WebSocketClient constructor",this.config)}connect(){return new Promise((e,t)=>{if(this.ws?.readyState===WebSocket.OPEN||this.ws?.readyState===WebSocket.CONNECTING){e();return}try{let n={maxReconnectionDelay:this.config.maxReconnectDelay,minReconnectionDelay:this.config.initialReconnectDelay,reconnectionDelayGrowFactor:this.config.reconnectMultiplier,maxRetries:this.config.maxReconnectAttempts,maxEnqueuedMessages:this.config.maxEnqueuedMessages,connectionTimeout:this.config.connectionTimeout};this.ws=new As(this.config.url,this.config.protocols,n),this.setupEventListeners(e,t)}catch(n){t(n)}})}async onBeforeReSubscribe(){return this.config.onBeforeReSubscribe&&await this.config.onBeforeReSubscribe(),!0}setupEventListeners(e,t){this.ws&&(this.ws.onopen=async n=>{this.eventBus.emit("open",n),this.lastMessageTime=Date.now(),this.timeoutHeartbeat(),this.isFirstConnection||this.onBeforeReSubscribe().then(()=>this.resubscribeAll()),this.isFirstConnection=!1,e()},this.ws.onmessage=n=>{this.handleMessage(n)},this.ws.onclose=n=>{this.eventBus.emit("close",n),this.stopHeartbeatTimer()},this.ws.onerror=n=>{this.eventBus.emit("error",n),t(n)},this.ws.addEventListener("reconnecting",n=>{this.eventBus.emit("reconnecting",{detail:n.detail||0}),this.isFirstConnection=!1}),this.ws.addEventListener("maxreconnectattempts",()=>{this.eventBus.emit("maxreconnectattempts",void 0)}))}pong(e){this.send({request:"pong",args:e})}request(e){return new Promise((t,n)=>{let a=We(e);this.waitingRequests.has(a)?(this.waitingRequests.get(a)?.onSuccess.add(t),this.waitingRequests.get(a)?.onError.add(n)):this.waitingRequests.set(a,{onSuccess:new Set([t]),onError:new Set([n])}),this.send(e)})}subscribe(e,t){let n=Array.isArray(e)?e:[e],a=[],i=new Set;n.forEach(r=>{let p=Oe(r);if(!i.has(p))if(i.add(p),this.subscriptions.has(p))this.subscriptions.get(p).callbacks.add(t);else{let o={id:p,topic:r.topic,callbacks:new Set([t])};this.subscriptions.set(p,o),a.push(p),this.logger.debug(`create new subscription: ${p}`)}}),a.length>0&&this.send({request:"subv2",args:a})}unsubscribe(e,t){if(!e)return;let n=Array.isArray(e)?e:[e],a=[],i=new Set;n.forEach(r=>{let p=Oe(r);if(i.has(p))return;i.add(p);let o=this.subscriptions.get(p);o&&(o.callbacks.delete(t),this.logger.debug(`remove callback from subscription: ${p}`),o.callbacks.size===0&&(this.subscriptions.delete(p),a.push(p),this.logger.debug(`subscription ${p} has no callbacks, will unsubscribe`)))}),a.length>0&&this.send({request:"unsubv2",args:a})}send(e){let t=typeof e=="string"?e:JSON.stringify(e);if(!this.ws)throw new g("SOCKET_NOT_CONNECTED","WebSocket is not connected");this.ws.readyState!==WebSocket.OPEN&&this.ws.readyState!==WebSocket.CONNECTING&&this.reconnect(),this.ws.send(t)}disconnect(){this.stopHeartbeatTimer(),this.ws&&(this.ws.close(),this.ws=null)}reconnect(){this.ws?this.ws.readyState!==WebSocket.CONNECTING&&this.ws.reconnect():this.connect().catch(e=>{this.logger.error(e)})}isConnected(){return this.ws?.readyState===WebSocket.OPEN}on(e,t){this.eventBus.on(e,t)}off(e,t){this.eventBus.off(e,t)}handleMessage(e){try{let t=JSON.parse(e.data);if(this.lastMessageTime=Date.now(),t.type==="ping"){queueMicrotask(()=>{this.pong(t.data)});return}if(ea(t)){this.handleAckMessage(t);return}this.handleSubscriptionMessage(t)}catch(t){this.logger.error(`Failed to parse WebSocket message: ${t}`)}}handleAckMessage(e){let t;switch(e.type){case"signin":t=We({request:e.type,args:""});break;default:t=We({request:e.type,args:e.data.data});break}let n=this.waitingRequests.get(t),a=e.data.code===9200;a?this.logger.debug(`AcK Message:${e.type} received`):(this.logger.error(`Ack Message:${e.type} received`,e),this.eventBus.emit("error",e)),n?.onError.size&&!a&&n.onError.forEach(i=>{i(new g("REQUEST_FAILED","Request failed"))}),n?.onSuccess.size&&a&&n.onSuccess.forEach(i=>{i(e.data)})}handleSubscriptionMessage(e){let t=ta(e),n=t.type,a=this.subscriptions.get(n);a&&a.callbacks.forEach(i=>{try{i(t)}catch(r){this.logger.error(`Callback Error (${n}): ${r}`)}})}resubscribeAll(){if(this.subscriptions.size===0)return;this.logger.debug("resubscribe all...");let e=Array.from(this.subscriptions.values()).map(t=>t.id);e.length>0&&(this.send({request:"subv2",args:e}),this.logger.debug(`resubscribe ${e.length} topics`))}timeoutHeartbeat(){this.stopHeartbeatTimer(),Date.now()-this.lastMessageTime>(this.config.noMessageTimeout||na.noMessageTimeout)&&(this.logger.debug("no message timeout"),this.subscriptions.size>0?this.reconnect():this.ws?.close()),this.heartbeatIntervalId=setTimeout(()=>{this.timeoutHeartbeat()},this.config.heartbeatInterval)}stopHeartbeatTimer(){this.heartbeatIntervalId&&(clearInterval(this.heartbeatIntervalId),this.heartbeatIntervalId=null)}};var aa=[56,59144,42161],sa=[59141,421614,97],ia=[97,421614];var Ve={TestNet:"wss://oapi-test.myx.cash/ws",MainNet:"wss://oapi.myx.finance/ws",BetaNet:"wss://oapi-beta.myx.finance/ws"};var $e=class{constructor(e,t){this.clientAuth=!1;this.prevUserAddress=null;this.configManager=e,this.logger=t;let n=Ve.MainNet;e.getConfig().isBetaMode?n=Ve.BetaNet:e.getConfig().isTestnet&&(n=Ve.TestNet),this.wsClient=new ze({logLevel:this.configManager.getConfig()?.logLevel,url:n,...this.configManager.getConfig()?.socketConfig,onBeforeReSubscribe:()=>{if(this.clientAuth)return this.auth(!0).then(()=>{this.logger.debug("reconnect auth success")})}})}get isConnected(){return this.wsClient.isConnected()}connect(){this.wsClient.connect()}disconnect(){this.wsClient.disconnect()}reconnect(){this.wsClient.reconnect()}subscribeTickers(e,t){let n=Array.isArray(e)?e:[e];this.wsClient.subscribe(n.map(a=>({topic:"ticker",params:{globalId:a}})),t)}unsubscribeTickers(e,t){let n=Array.isArray(e)?e:[e];this.wsClient.unsubscribe(n.map(a=>({topic:"ticker",params:{globalId:a}})),t)}subscribeKline(e,t,n){this.logger.debug(`subscribe kline ${e} ${t}`),this.wsClient.subscribe({topic:"candle",params:{globalId:e,resolution:t}},n)}unsubscribeKline(e,t,n){this.logger.debug(`unsubscribe kline ${e} ${t}`),this.wsClient.unsubscribe({topic:"candle",params:{globalId:e,resolution:t}},n)}async getSdkAuthParams(){let e=this.configManager.getConfig();if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER");let t=await this.configManager.getSignerAddress(e.chainId);if(!t)throw new g("INVALID_SIGNER");return{userAddress:t}}async auth(e=!1){let{userAddress:t}=await this.getSdkAuthParams();if(t===this.prevUserAddress&&this.clientAuth&&!e)return Promise.resolve();this.logger.debug(`sdkaccount: ${t}`),await this.wsClient.request({request:"signin",args:`sdkaccount.${t}`}).then(()=>{this.logger.debug(`auth success ${t}`),this.clientAuth=!0,this.prevUserAddress=t})}async subscribePosition(e){this.logger.debug("subscribe position"),await this.auth(),this.wsClient.subscribe({topic:"position"},e)}unsubscribePosition(e){this.logger.debug("unsubscribe position"),this.wsClient.unsubscribe({topic:"position"},e)}async subscribeOrder(e){this.logger.debug("subscribe order"),await this.auth(),this.wsClient.subscribe({topic:"order"},e)}unsubscribeOrder(e){this.logger.debug("unsubscribe order"),this.wsClient.unsubscribe({topic:"order"},e)}on(e,t){this.wsClient.on(e,t)}off(e,t){this.wsClient.off(e,t)}};function Cs(s){return typeof s.getAddresses=="function"&&typeof s.signMessage=="function"&&typeof s.sendTransaction=="function"}function ws(s){return typeof s.getAddress=="function"&&typeof s.signMessage=="function"&&typeof s.sendTransaction=="function"}function Wt(s){let e=s;return{async getAddress(){let[t]=await s.getAddresses();if(!t)throw new Error("WalletClient: no address");return t},async signMessage(t){let n=typeof t=="string"?t:{raw:t};return await s.signMessage({message:n})},async sendTransaction(t){let n=t.to;if(!n)throw new Error("sendTransaction: to is required");return{hash:await s.sendTransaction({to:n,data:t.data,value:t.value!=null?BigInt(t.value):void 0,gas:t.gasLimit!=null?BigInt(t.gasLimit):void 0,gasPrice:t.gasPrice!=null?BigInt(t.gasPrice):void 0,maxFeePerGas:t.maxFeePerGas!=null?BigInt(t.maxFeePerGas):void 0,maxPriorityFeePerGas:t.maxPriorityFeePerGas!=null?BigInt(t.maxPriorityFeePerGas):void 0})}},...typeof e.signTypedData=="function"?{async signTypedData(t){return await e.signTypedData(t)}}:{}}}function ra(s){let e=s;return{getAddress:()=>s.getAddress(),signMessage:t=>s.signMessage(t),async sendTransaction(t){return{hash:(await s.sendTransaction({...t,value:t.value!=null?BigInt(t.value):void 0,gasLimit:t.gasLimit!=null?BigInt(t.gasLimit):void 0})).hash}},...typeof e.signTypedData=="function"?{async signTypedData(t){return e.signTypedData(t.domain,t.types,t.message)}}:{}}}function He(s){return Cs(s)?Wt(s):ws(s)?ra(s):s}import{createWalletClient as Ps,custom as Ts}from"viem";function oa(s){let e=be(s),t=[...e.privateJsonRPCUrl?[e.privateJsonRPCUrl]:[],...Array.isArray(e.publicJsonRPCUrl)?[...e.publicJsonRPCUrl]:[]].filter(Boolean);if(t.length===0)throw new Error(`${s} has no jsonRPCUrl configured`);return t[0]}var zt={};function Rs(s){if(!zt[s]){let e=be(s);zt[s]={id:s,name:e.label||`Chain ${s}`,nativeCurrency:e.nativeCurrency,rpcUrls:{default:{http:[oa(s)]}}}}return zt[s]}async function pa(s,e){let t=oa(e),n=Rs(e),i={address:await s.getAddress(),type:"local",async signMessage({message:p}){let o=typeof p=="string"?p:p.raw;return await s.signMessage(o)},async signTypedData(p){if(!s.signTypedData)throw new Error("ISigner.signTypedData required for this operation");return await s.signTypedData({domain:p.domain,types:p.types,primaryType:p.primaryType,message:p.message})},source:"custom"};return Ps({account:i,chain:n,transport:Ts({request:async p=>{if(p.method==="eth_sendTransaction"){let d=p.params?.[0]??{},{hash:l}=await s.sendTransaction({to:d.to,data:d.data,value:d.value!=null?BigInt(d.value):void 0,gasLimit:d.gas!=null?BigInt(d.gas):void 0,gasPrice:d.gasPrice!=null?BigInt(d.gasPrice):void 0,maxFeePerGas:d.maxFeePerGas!=null?BigInt(d.maxFeePerGas):void 0,maxPriorityFeePerGas:d.maxPriorityFeePerGas!=null?BigInt(d.maxPriorityFeePerGas):void 0});return l}let u=await(await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:1,method:p.method,params:p.params??[]})})).json();if(u.error)throw new Error(u.error.message);return u.result}})})}var Qe=class{constructor(e){this._normalizedSigner=null;this._getAccessTokenQueue=[];this._isGettingAccessToken=!1;let t={isTestnet:!1,isBetaMode:!1,...e};this.validateConfig(t),this.config=t}clear(){this.accessToken=void 0,this.accessTokenExpiry=void 0,this._normalizedSigner=null,this.config={...this.config,signer:void 0,walletClient:void 0,getAccessToken:void 0}}hasSigner(){return!!(this.config.walletClient||this.config.signer!=null||this._normalizedSigner!=null)}async getSignerAddress(e){if(this.config.walletClient){let[t]=await this.config.walletClient.getAddresses();if(t)return t}if(this._normalizedSigner)return this._normalizedSigner.getAddress();throw new g("INVALID_SIGNER","Invalid signer")}async getViemWalletClient(e){if(this.config.walletClient)return this.config.walletClient;if(this._normalizedSigner)return await pa(this._normalizedSigner,e);throw new g("INVALID_SIGNER","Invalid signer: call auth({ signer }) or auth({ walletClient })")}async startSeamlessMode(e){return this.config={...this.config,seamlessMode:e},this.config}updateSeamlessWallet({wallet:e,authorized:t,masterAddress:n}){this.config={...this.config,seamlessAccount:{masterAddress:n??"",wallet:e??null,authorized:t??!1}}}updateClientChainId(e,t){this.config={...this.config,chainId:e,brokerAddress:t}}auth(e){this.clear(),this.config={...this.config,...e},e.signer!=null&&(this._normalizedSigner=He(e.signer)),this.validateConfig(this.config)}validateConfig(e){let{isTestnet:t,isBetaMode:n,chainId:a}=e;if(t){if(!sa.includes(a))throw new g("INVALID_CHAIN_ID",`chainId ${a} is not in the range of TESTNET_CHAIN_IDS`)}else if(n){if(!ia.includes(a))throw new g("INVALID_CHAIN_ID",`chainId ${a} is not in the range of BETA_ENV_CHAIN_IDS`)}else if(!aa.includes(a))throw new g("INVALID_CHAIN_ID",`chainId ${a} is not in the range of MAINNET_CHAIN_IDS`)}async getAccessToken(){return this.accessToken??null}async refreshAccessToken(e=!1){return new Promise((t,n)=>{this._getAccessTokenQueue.push({resolve:t,reject:n,forceRefresh:e}),this._processAccessTokenQueue()})}_processAccessTokenQueue(){if(this._isGettingAccessToken)return;this._isGettingAccessToken=!0;let e=this._getAccessTokenQueue.shift();e?this._refreshAccessToken(e.forceRefresh).then(e.resolve).catch(e.reject).finally(()=>{this._isGettingAccessToken=!1,this._getAccessTokenQueue.length>0&&this._processAccessTokenQueue()}):this._isGettingAccessToken=!1}async _refreshAccessToken(e=!1){if(!e&&this.isAccessTokenValid())return this._isGettingAccessToken=!1,this.accessToken;if(!this.config.getAccessToken)return console.warn("No getAccessToken method provided in config"),null;try{let t=await this.config.getAccessToken()??{accessToken:"",expireAt:0};if(t&&t.accessToken){let n=3600;if(t.expireAt){let a=Math.floor(Date.now()/1e3);n=t.expireAt-a,n<=0&&(console.warn("Received expired token, using default expiry"),n=3600)}return this.setAccessToken(t.accessToken,n),t.accessToken}else return console.warn("\u274C Received empty accessToken"),null}catch(t){return console.error("\u274C Failed to refresh accessToken:",t),null}}setAccessToken(e,t=3600){this.accessToken=e,this.accessTokenExpiry=Date.now()+t*1e3}getCurrentAccessToken(){return this.accessToken}isAccessTokenValid(){return!!this.accessToken}clearAccessToken(){this.accessToken=void 0,this.accessTokenExpiry=void 0}getConfig(){return this.config}};var Ke=class{constructor(e,t,n){this.configManager=e,this.utils=t,this.api=n}getMarkets(){return Promise.resolve([])}async getPoolLevelConfig(e,t){let n=this.configManager.getConfig();return(await this.api.getPoolLevelConfig({poolId:e,chainId:t})).data}async getKlineList({interval:e,...t}){let n=this.configManager.getConfig();return(await this.api.getKlineData({...t,interval:this.utils.transferKlineResolutionToInterval(e)})).data}async getKlineLatestBar({interval:e,...t}){let n=this.configManager.getConfig();return(await this.api.getKlineLatestBar({...t,interval:this.utils.transferKlineResolutionToInterval(e)})).data}async getTickerList(e){return(await this.api.getTickerData(e)).data}async searchMarketAuth(e,t){let n=await this.configManager.getAccessToken()??"";return(await this.api.searchMarketAuth({address:t,...e,accessToken:n})).data}async searchMarket(e){return(await this.api.searchMarket(e)).data}async getFavoritesList(e,t){let n=await this.configManager.getAccessToken()??"";return(await this.api.getFavoritesList({...e,address:t,accessToken:n})).data}async addFavorite(e,t){let n=await this.configManager.getAccessToken()??"";return(await this.api.addFavorite({...e,address:t,accessToken:n})).data}async removeFavorite(e,t){let n=await this.configManager.getAccessToken()??"";return(await this.api.removeFavorite({...e,address:t,accessToken:n})).data}async getBaseDetail(e){return(await this.api.getBaseDetail(e)).data}async getMarketDetail(e){return(await this.api.getMarketDetail(e)).data}async getPoolSymbolAll(){return(await this.api.getPoolSymbolAll()).data}};import{encodeFunctionData as vs,maxUint256 as Es}from"viem";import ks from"dayjs";var Je=class{constructor(e,t,n,a,i,r){this.configManager=e,this.logger=t,this.utils=n,this.seamless=a,this.account=i,this.api=r}async listPositions(e){let t=await this.configManager.getAccessToken();try{return{code:0,data:(await this.api.getPositions(t??"",e)).data}}catch(n){return console.error("Error fetching positions:",n),{code:-1,message:"Failed to fetch positions"}}}async getPositionHistory(e,t){let n=await this.configManager.getAccessToken()??"";return{code:0,data:(await this.api.getPositionHistory({accessToken:n,...e,address:t})).data}}async adjustCollateral({poolId:e,positionId:t,adjustAmount:n,quoteToken:a,chainId:i,address:r}){let p=this.configManager.getConfig();try{let o=await this.utils.getOraclePrice(e,i);if(!o)throw new Error("Failed to get price data");let u={poolId:e,oracleType:o.oracleType,oracleUpdateData:o?.vaa??"0",publishTime:o.publishTime},d=!1;Number(n)>0&&(d=await this.utils.needsApproval(r,i,a,n,w(i).TRADING_ROUTER));let l=this.configManager.getConfig().seamlessAccount?.authorized,y=this.configManager.getConfig().seamlessAccount?.wallet,c=BigInt(0),f=BigInt(n)>0?BigInt(n):0n,m=await this.account.getAvailableMarginBalance({poolId:e,chainId:i,address:r}),b=m.code===0?m.data??0n:0n,A=BigInt(0);b<f&&(A=f-b,c=A);let P={token:a,amount:c.toString()};if(p.seamlessMode&&l&&y){if(!await this.utils.checkSeamlessGas(p.seamlessAccount?.masterAddress,i))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let E=await F(i),q=vs({abi:O,functionName:"updatePriceAndAdjustCollateral",args:[[u],P,t,n]}),X=await E.read.nonces([y.address]),ge={from:y.address??"",to:this.configManager.getConfig().brokerAddress,value:(o?.value??"1").toString(),gas:"10000000",deadline:ks().add(60,"minute").unix(),data:q,nonce:X.toString()};return{code:0,message:"adjust collateral success",data:await this.seamless.forwarderTx(ge,i,y)}}if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER","Invalid signer");let M=await V(i,p.brokerAddress);if(d){let G=await this.utils.approveAuthorization({chainId:i,quoteAddress:a,amount:Es.toString(),spenderAddress:w(i).TRADING_ROUTER});if(G.code!==0)throw new Error(G.message)}let U=await M.write.updatePriceAndAdjustCollateral([[u],P,t,n],{value:BigInt(o?.value??"1"),gas:BigInt(1e7)*H[i]/100n});return await h(i).waitForTransactionReceipt({hash:U}),{code:0,data:{hash:U},message:"Adjust collateral transaction submitted"}}catch(o){return{code:-1,message:o.message}}}};var Ss={IOC:0},me=Ss.IOC;var je={MARKET:0,LIMIT:1,STOP:2,CONDITIONAL:3},lm={NONE:0,GTE:1,LTE:2},ye={INCREASE:0,DECREASE:1},mm={LONG:0,SHORT:1},ym={IOC:0},fm={PENDING:0,PARTIAL:1,FILLED:2,CANCELLED:3,REJECTED:4,EXPIRED:5};import{encodeFunctionData as K,maxUint256 as ua}from"viem";import pe from"dayjs";var Ye=class{constructor(e,t,n,a,i,r){this.configManager=e,this.logger=t,this.utils=n,this.seamless=a,this.account=i,this.api=r}async createIncreaseOrder(e,t,n){try{let a=this.configManager.getConfig(),i=await this.utils.getNetworkFee(n,e.chainId),r=BigInt(i);e.tpSize&&BigInt(e.tpSize)>0&&(r+=BigInt(i)),e.slSize&&BigInt(e.slSize)>0&&(r+=BigInt(i));let p=BigInt(e.collateralAmount)+BigInt(t),o=await this.account.getAvailableMarginBalance({poolId:e.poolId,chainId:e.chainId,address:e.address}),u=o.code===0?o.data??0n:0n,d=p+r,l=BigInt(0),y=d-u;y>BigInt(0)&&(l=y);let c={token:e.executionFeeToken,amount:l.toString()},f={user:e.address,poolId:e.poolId,orderType:e.orderType,triggerType:e.triggerType,operation:ye.INCREASE,direction:e.direction,collateralAmount:p.toString(),size:e.size,price:e.price,timeInForce:me,postOnly:e.postOnly??!1,slippagePct:e.slippagePct??"0",leverage:e.leverage??0,tpSize:e.tpSize??"0",tpPrice:e.tpPrice??"0",slSize:e.slSize??"0",slPrice:e.slPrice??"0"},m=this.configManager.getConfig().seamlessAccount?.authorized,b=this.configManager.getConfig().seamlessAccount?.wallet;if(a.seamlessMode&&m&&b){if(!await this.utils.checkSeamlessGas(e.address,e.chainId))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let q=await F(e.chainId),X="";e.positionId?X=K({abi:O,functionName:"placeOrderWithPosition",args:[e.positionId.toString(),{...c},f]}):(this.logger.info("createIncreaseOrder placeOrderWithSalt data --->",["1",{...c},f]),X=K({abi:O,functionName:"placeOrderWithSalt",args:["1",{...c},f]}));let ge=await q.read.nonces([b.address]),$={from:b.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:X,nonce:ge.toString()};return this.logger.info("createIncreaseOrder forward tx params --->",$),{code:0,message:"create increase order success",data:await this.seamless.forwarderTx($,e.chainId,b)}}let A=await this.utils.needsApproval(e.address,e.chainId,e.executionFeeToken,e.collateralAmount,w(e.chainId).TRADING_ROUTER);if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER","Invalid signer");if(A){let E=await this.utils.approveAuthorization({chainId:e.chainId,quoteAddress:e.executionFeeToken,amount:ua.toString(),spenderAddress:w(e.chainId).TRADING_ROUTER});if(E.code!==0)throw new Error(E.message)}let P=await V(e.chainId,this.configManager.getConfig().brokerAddress),M;if(e.positionId){this.logger.info("createIncreaseOrder nft position params--->",{...f,positionId:e.positionId});let E=await P.estimateGas.placeOrderWithPosition([e.positionId.toString(),{...c},f]);M=await P.write.placeOrderWithPosition([e.positionId.toString(),{...c},f],{gasLimit:E*H[e.chainId]/100n})}else{this.logger.info("createIncreaseOrder salt position params--->",{positionSalt:"1",data:f,depositData:c});let q=await P.estimateGas.placeOrderWithSalt(["1",{...c},f]);M=await P.write.placeOrderWithSalt(["1",{...c},f],{gasLimit:q*H[e.chainId]/100n})}let U=await h(e.chainId).waitForTransactionReceipt({hash:M});return{code:0,message:"create increase order success",data:{success:!0,transactionHash:M,blockNumber:U?.blockNumber,gasUsed:U?.gasUsed?.toString(),status:U?.status==="success"?"success":"failed",confirmations:1,timestamp:Date.now(),receipt:U}}}catch(a){return this.logger.error("Error placing order:",a),{code:-1,message:a?.message}}}async closeAllPositions(e,t){try{let n=this.configManager.getConfig(),a={token:"0x0000000000000000000000000000000000000000",amount:"0"},i=t.map(c=>c.positionId.toString()),r=t.map(c=>({user:c.address,poolId:c.poolId,orderType:c.orderType,triggerType:c.triggerType,operation:ye.DECREASE,direction:c.direction,collateralAmount:c.collateralAmount,size:c.size,price:c.price,timeInForce:me,postOnly:c.postOnly,slippagePct:c.slippagePct,leverage:c.leverage,tpSize:0,tpPrice:0,slSize:0,slPrice:0}));this.logger.info("closeAllPositions params--->",a,i,r);let p=this.configManager.getConfig().seamlessAccount?.authorized,o=this.configManager.getConfig().seamlessAccount?.wallet;if(n.seamlessMode&&p&&o){if(!await this.utils.checkSeamlessGas(t[0].address,e))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let f=await F(e),m=await re(this.configManager.getConfig().brokerAddress,o),b=K({abi:O,functionName:"placeOrdersWithPosition",args:[a,i,r]}),A=await f.read.nonces([o.address]),P={from:o.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:b,nonce:A.toString()};return this.logger.info("cancel all positions forward tx params --->",P),{code:0,message:"cancel all positions success",data:await this.seamless.forwarderTx(P,e,o)}}if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER","Invalid signer");let u=await V(e,this.configManager.getConfig().brokerAddress),d=await u.estimateGas.placeOrdersWithPosition([a,i,r]),l=await u.write.placeOrdersWithPosition([a,i,r],{gasLimit:d*H[e]/100n}),y=await h(e).waitForTransactionReceipt({hash:l});return{code:0,message:"close all positions success",transactionHash:l,blockNumber:y?.blockNumber,gasUsed:y?.gasUsed?.toString(),status:y?.status==="success"?"success":"failed",confirmations:1,timestamp:Date.now(),receipt:y}}catch(n){return{code:-1,message:n?.message}}}async createDecreaseOrder(e){try{let t=this.configManager.getConfig(),n={user:e.address,poolId:e.poolId,orderType:e.orderType,triggerType:e.triggerType,operation:ye.DECREASE,direction:e.direction,collateralAmount:e.collateralAmount,size:e.size,price:e.price,timeInForce:me,postOnly:e.postOnly,slippagePct:e.slippagePct,leverage:e.leverage,tpSize:0,tpPrice:0,slSize:0,slPrice:0},a={token:"0x0000000000000000000000000000000000000000",amount:"0"},i=this.configManager.getConfig().seamlessAccount?.authorized,r=this.configManager.getConfig().seamlessAccount?.wallet;if(t.seamlessMode&&i&&r){if(!await this.utils.checkSeamlessGas(e.address,e.chainId))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let y=await F(e.chainId),c=await re(this.configManager.getConfig().brokerAddress,r),f="";e.positionId?f=K({abi:O,functionName:"placeOrderWithPosition",args:[e.positionId.toString(),{...a},n]}):f=K({abi:O,functionName:"placeOrderWithSalt",args:["1",{...a},n]});let m=await y.read.nonces([r.address]),b={from:r.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:f,nonce:m.toString()};return this.logger.info("create decrease order forward tx params --->",b),{code:0,message:"create decrease order success",data:await this.seamless.forwarderTx(b,e.chainId,r)}}if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER","Invalid signer");let p=await V(e.chainId,this.configManager.getConfig().brokerAddress),o;if(e.positionId){this.logger.info("createDecreaseOrder nft position params--->",[e.positionId,a,{data:n}]);let l=await p.estimateGas.placeOrderWithPosition([e.positionId.toString(),a,n]);o=await p.write.placeOrderWithPosition([e.positionId.toString(),a,n],{gasLimit:l*H[e.chainId]/100n})}else{this.logger.info("createDecreaseOrder salt position params--->",[1,a,{data:n}]);let y=await p.estimateGas.placeOrderWithSalt(["1",a,n]);o=await p.write.placeOrderWithSalt(["1",a,n],{gasLimit:y*H[e.chainId]/100n})}let u=await h(e.chainId).waitForTransactionReceipt({hash:o});return{code:0,message:"create decrease order success",data:{success:!0,transactionHash:o,blockNumber:u?.blockNumber,gasUsed:u?.gasUsed?.toString(),status:u?.status==="success"?"success":"failed",confirmations:1,timestamp:Date.now(),receipt:u}}}catch(t){return{code:-1,message:t?.message}}}async createPositionTpSlOrder(e){try{let t=this.configManager.getConfig();if(!this.configManager.hasSigner()&&!t.seamlessMode)throw new g("INVALID_SIGNER","Invalid signer");let n=await V(e.chainId,this.configManager.getConfig().brokerAddress);try{if(e.tpSize!=="0"&&e.slSize!=="0"){let l=[{user:e.address,poolId:e.poolId,orderType:je.STOP,triggerType:e.tpTriggerType,operation:ye.DECREASE,direction:e.direction,collateralAmount:"0",size:e.tpSize??"0",price:e.tpPrice??"0",timeInForce:me,postOnly:!1,slippagePct:e.slippagePct??"0",leverage:e.leverage,tpSize:"0",tpPrice:"0",slSize:"0",slPrice:"0"},{user:e.address,poolId:e.poolId,orderType:je.STOP,triggerType:e.slTriggerType,operation:ye.DECREASE,direction:e.direction,collateralAmount:"0",size:e.slSize??"0",price:e.slPrice??"0",timeInForce:me,postOnly:!1,slippagePct:e.slippagePct??"0",leverage:e.leverage,tpSize:"0",tpPrice:"0",slSize:"0",slPrice:"0"}],y={token:"0x0000000000000000000000000000000000000000",amount:"0"},c=this.configManager.getConfig().seamlessAccount?.authorized,f=this.configManager.getConfig().seamlessAccount?.wallet;if(t.seamlessMode&&c&&f){if(!await this.utils.checkSeamlessGas(e.address,e.chainId))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let M=await F(e.chainId),U=await re(this.configManager.getConfig().brokerAddress,f),G="";e.positionId?G=K({abi:O,functionName:"placeOrdersWithPosition",args:[y,[e.positionId.toString(),e.positionId.toString()],l]}):G=K({abi:O,functionName:"placeOrdersWithSalt",args:[y,["1","1"],l]});let E=await M.read.nonces([f.address]),q={from:f.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:G,nonce:E.toString()};return this.logger.info("createPositionTpSlOrder forward tx params --->",q),{code:0,message:"createPositionTpSlOrder success",data:await this.seamless.forwarderTx(q,e.chainId,f)}}let m;if(e.positionId){let P=await n.estimateGas.placeOrdersWithPosition([y,[e.positionId.toString(),e.positionId.toString()],l]);m=await n.write.placeOrdersWithPosition([y,[e.positionId.toString(),e.positionId.toString()],l],{gasLimit:P*H[e.chainId]/100n})}else{this.logger.info("createPositionTpSlOrder salt position data--->",l);let P=1,M=await n.estimateGas.placeOrdersWithSalt([y,[P.toString(),P.toString()],l]);m=await n.write.placeOrdersWithSalt([y,[P.toString(),P.toString()],l],{gasLimit:M*H[e.chainId]/100n})}let b=await h(e.chainId).waitForTransactionReceipt({hash:m});return{code:0,message:"create decrease order success",data:{success:!0,transactionHash:m,blockNumber:b?.blockNumber,gasUsed:b?.gasUsed?.toString(),status:b?.status==="success"?"success":"failed",confirmations:1,timestamp:Date.now(),receipt:b}}}let a={user:e.address,poolId:e.poolId,orderType:je.STOP,triggerType:e.tpSize!=="0"?e.tpTriggerType:e.slTriggerType,operation:ye.DECREASE,direction:e.direction,collateralAmount:"0",size:e.tpSize!=="0"?e.tpSize??"0":e.slSize??"0",price:e.tpPrice!=="0"?e.tpPrice??"0":e.slPrice??"0",timeInForce:me,postOnly:!1,slippagePct:e.slippagePct??"0",leverage:0,tpSize:"0",tpPrice:"0",slSize:"0",slPrice:"0"},i={token:"0x0000000000000000000000000000000000000000",amount:"0"},r=this.configManager.getConfig().seamlessAccount?.authorized,p=this.configManager.getConfig().seamlessAccount?.wallet;if(t.seamlessMode&&r&&p){if(!await this.utils.checkSeamlessGas(e.address,e.chainId))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let y=await F(e.chainId),c=await re(this.configManager.getConfig().brokerAddress,p),f="";e.positionId?f=K({abi:O,functionName:"placeOrderWithPosition",args:[e.positionId.toString(),i,a]}):f=K({abi:O,functionName:"placeOrderWithSalt",args:["1",i,a]});let m=await y.read.nonces([p.address]),b={from:p.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:f,nonce:m.toString()};return this.logger.info("createPositionTpSlOrder forward tx params --->",b),{code:0,message:"createPositionTpSlOrder success",data:await this.seamless.forwarderTx(b,e.chainId,p)}}let o;if(e.positionId){this.logger.info("createPositionTpOrSlOrder nft position data--->",a);let l=await n.estimateGas.placeOrderWithPosition([e.positionId.toString(),i,a]);o=await n.write.placeOrderWithPosition([e.positionId.toString(),i,a],{gasLimit:l*H[e.chainId]/100n})}else{this.logger.info("createPositionTpOrSlOrder salt position data--->",a);let l=1,y=await n.estimateGas.placeOrderWithSalt([l.toString(),i,a]);o=await n.write.placeOrderWithSalt([l.toString(),i,a],{gasLimit:y*H[e.chainId]/100n})}let u=await h(e.chainId).waitForTransactionReceipt({hash:o});return{code:0,message:"create decrease order success",data:{success:!0,transactionHash:o,blockNumber:u?.blockNumber,gasUsed:u?.gasUsed?.toString(),status:u?.status==="success"?"success":"failed",confirmations:1,timestamp:Date.now(),receipt:u}}}catch(a){return{code:-1,message:a?.message}}}catch(t){return{code:-1,message:t?.message}}}async cancelAllOrders(e,t){try{let n=this.configManager.getConfig(),a=this.configManager.getConfig().seamlessAccount?.authorized,i=this.configManager.getConfig().seamlessAccount?.wallet;if(n.seamlessMode&&a&&i){if(!await this.utils.checkSeamlessGas(n.seamlessAccount?.masterAddress,t))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let u=await F(t),d=await re(this.configManager.getConfig().brokerAddress,i),l=K({abi:O,functionName:"cancelOrders",args:[e]}),y=await u.read.nonces([i.address]),c={from:i.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:l,nonce:y.toString()};return this.logger.info("create decrease order forward tx params --->",c),{code:0,message:"create decrease order success",data:await this.seamless.forwarderTx(c,t,i)}}if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER","Invalid signer");let p=await(await V(t,this.configManager.getConfig().brokerAddress)).write.cancelOrders([e]);return await h(t).waitForTransactionReceipt({hash:p}),{code:0,message:"cancel all orders success"}}catch(n){return{code:-1,message:n?.message}}}async cancelOrder(e,t){try{let n=this.configManager.getConfig(),a=this.configManager.getConfig().seamlessAccount?.authorized,i=this.configManager.getConfig().seamlessAccount?.wallet;if(n.seamlessMode&&a&&i){if(!await this.utils.checkSeamlessGas(n.seamlessAccount?.masterAddress,t))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let u=await re(this.configManager.getConfig().brokerAddress,i),d=await F(t),l=K({abi:O,functionName:"cancelOrder",args:[BigInt(e)]}),y=await d.read.nonces([i.address]),c={from:i.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:l,nonce:y.toString()};return this.logger.info("createIncreaseOrder forward tx params --->",c),{code:0,message:"cancel order success",data:await this.seamless.forwarderTx(c,t,i)}}if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER","Invalid signer");let p=await(await V(t,this.configManager.getConfig().brokerAddress)).write.cancelOrder([e]);return await h(t).waitForTransactionReceipt({hash:p}),{code:0,message:"cancel order success"}}catch(n){return{code:-1,message:n?.message}}}async cancelOrders(e,t){try{let n=this.configManager.getConfig(),a=this.configManager.getConfig().seamlessAccount?.authorized,i=this.configManager.getConfig().seamlessAccount?.wallet;if(n.seamlessMode&&a&&i){if(!await this.utils.checkSeamlessGas(n.seamlessAccount?.masterAddress,t))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let u=await F(t),d=await re(this.configManager.getConfig().brokerAddress,i),l=K({abi:O,functionName:"cancelOrders",args:[e]}),y=await u.read.nonces([i.address]),c={from:i.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:l,nonce:y.toString()};return this.logger.info("cancel orders forward tx params --->",c),{code:0,message:"cancel orders success",data:await this.seamless.forwarderTx(c,t,i)}}if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER","Invalid signer");let p=await(await V(t,this.configManager.getConfig().brokerAddress)).write.cancelOrders([e]);return await h(t).waitForTransactionReceipt({hash:p}),{code:0,message:"Orders canceled success"}}catch(n){return this.logger.error("Error canceling orders:",n),{code:-1,message:n?.message}}}async updateOrderTpSl(e,t,n,a,i,r){let p=this.configManager.getConfig(),o=await this.utils.getNetworkFee(i,n),u={orderId:e.orderId,size:e.size,price:e.price,tpsl:{tpSize:r?e.tpSize:"0",tpPrice:r?e.tpPrice:"0",slSize:r?e.slSize:"0",slPrice:r?e.slPrice:"0"}},d={token:t,amount:o.toString()},l=this.configManager.getConfig().seamlessAccount?.authorized,y=this.configManager.getConfig().seamlessAccount?.wallet;if(p.seamlessMode&&l&&y){if(!await this.utils.checkSeamlessGas(p.seamlessAccount?.masterAddress,n))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let m=await re(this.configManager.getConfig().brokerAddress,y),b=await F(n),A=K({abi:O,functionName:"updateOrder",args:[d,u]}),P=await b.read.nonces([y.address]),M={from:y.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:A,nonce:P.toString()};return this.logger.info("createIncreaseOrder forward tx params --->",M),{code:0,message:"update order success",data:await this.seamless.forwarderTx(M,n,y)}}if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER","Invalid signer");let c=await V(n,p.brokerAddress);this.logger.info("updateOrderTpSl params",u);try{if(await this.utils.needsApproval(a,n,e.executionFeeToken,o.toString(),w(n).TRADING_ROUTER)){let P=await this.utils.approveAuthorization({chainId:n,quoteAddress:e.executionFeeToken,amount:ua.toString(),spenderAddress:w(n).TRADING_ROUTER});if(P.code!==0)throw new Error(P.message)}let m=await c.estimateGas.updateOrder([d,u]),b=await c.write.updateOrder([d,u],{gasLimit:m*H[n]/100n}),A=await h(n).waitForTransactionReceipt({hash:b});return this.logger.info("updateOrderTpSl receipt",A),{code:0,data:A,message:"update order success"}}catch(f){return this.logger.error("Error updating order:",f),{code:-1,message:"Failed to update order"}}}async getOrders(e){let t=await this.configManager.getAccessToken();try{return{code:0,data:(await this.api.getOrders(t??"",e)).data}}catch(n){return console.error("Error fetching orders:",n),{code:-1,message:"Failed to fetch orders"}}}async getOrderHistory(e,t){let n=await this.configManager.getAccessToken()??"";return{code:0,data:(await this.api.getHistoryOrders({accessToken:n,...e,address:t})).data}}};import{decodeEventLog as Ds,maxUint256 as Os}from"viem";var da=[{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotAllowedIdentifier",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"BlockHeader",inputs:[{type:"uint256",name:"blockNumber",indexed:!1},{type:"uint256",name:"blockTimestamp",indexed:!1},{type:"uint256",name:"sequence",indexed:!1}]},{type:"event",anonymous:!1,name:"CollateralAccepted",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"quoteDebt",indexed:!1},{type:"uint256",name:"baseCollateral",indexed:!1},{type:"uint256",name:"quoteCollateral",indexed:!1},{type:"uint256",name:"totalQuoteDebt",indexed:!1},{type:"uint256",name:"totalBaseCollateral",indexed:!1}]},{type:"event",anonymous:!1,name:"CollateralAdjusted",inputs:[{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint8",name:"direction",indexed:!1},{type:"uint256",name:"beforeCollateralAmount",indexed:!1},{type:"uint256",name:"afterCollateralAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"EnterDispute",inputs:[{type:"bytes32",name:"poolId",indexed:!1}]},{type:"event",anonymous:!1,name:"Exchanged",inputs:[{type:"address",name:"user",indexed:!1},{type:"address",name:"source",indexed:!1},{type:"address",name:"target",indexed:!1},{type:"uint256",name:"sourceAmount",indexed:!1},{type:"uint256",name:"targetAmount",indexed:!1},{type:"uint256",name:"price",indexed:!1}]},{type:"event",anonymous:!1,name:"ExecutionMatched",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256[]",name:"triggerOrderIds",indexed:!1},{type:"uint256[]",name:"matchedOrderIds",indexed:!1},{type:"uint8",name:"matchType",indexed:!1},{type:"uint256",name:"price",indexed:!1}]},{type:"event",anonymous:!1,name:"ExitDispute",inputs:[{type:"bytes32",name:"poolId",indexed:!1}]},{type:"event",anonymous:!1,name:"FeeDistributed",inputs:[{type:"address",name:"user",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"int32",name:"tradingFeeRate",indexed:!1},{type:"bool",name:"isMaker",indexed:!1},{type:"int256",name:"tradingFee",indexed:!1},{type:"uint256",name:"baseTradingFee",indexed:!1},{type:"uint256",name:"brokerTradingFee",indexed:!1},{type:"address",name:"broker",indexed:!1},{type:"uint256",name:"referralRebate",indexed:!1},{type:"uint256",name:"referrerRebate",indexed:!1},{type:"address",name:"referrer",indexed:!1},{type:"int256",name:"reserveFee",indexed:!1}]},{type:"event",anonymous:!1,name:"FundingRateUpdated",inputs:[{type:"uint64",name:"epochs",indexed:!1},{type:"uint64",name:"duration",indexed:!1},{type:"uint64",name:"previousEpochTime",indexed:!1},{type:"uint64",name:"lastEpochTime",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"int256",name:"fundingRate",indexed:!1},{type:"int256",name:"fundingRateTracker",indexed:!1},{type:"uint256",name:"price",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"LiquidityLockUpdated",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint64",name:"windowAnchor",indexed:!1},{type:"uint256",name:"priceFloor",indexed:!1},{type:"uint256",name:"priceCeiling",indexed:!1},{type:"int256",name:"openInterest",indexed:!1}]},{type:"event",anonymous:!1,name:"LiquidityMigrated",inputs:[{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"fromPoolId",indexed:!1},{type:"bytes32",name:"toPoolId",indexed:!1},{type:"uint256",name:"lpAmountIn",indexed:!1},{type:"uint256",name:"lpAmountOut",indexed:!1}]},{type:"event",anonymous:!1,name:"LiquidityStopOrderCancelled",inputs:[{type:"uint256",name:"orderId",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"string",name:"reason",indexed:!1}]},{type:"event",anonymous:!1,name:"LiquidityStopOrderCreated",inputs:[{type:"uint256",name:"orderId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"uint8",name:"poolType",indexed:!1},{type:"uint256",name:"amount",indexed:!1},{type:"uint256",name:"triggerPrice",indexed:!1},{type:"uint8",name:"triggerType",indexed:!1},{type:"uint256",name:"minQuoteOut",indexed:!1}]},{type:"event",anonymous:!1,name:"LiquidityStopOrderExecuted",inputs:[{type:"uint256",name:"orderId",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"executor",indexed:!1},{type:"uint256",name:"oraclePrice",indexed:!1},{type:"uint256",name:"poolTokenPrice",indexed:!1}]},{type:"event",anonymous:!1,name:"MarketCreated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"address",name:"deployer",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint32",name:"baseReserveRatio",indexed:!1},{type:"uint32",name:"quoteReserveRatio",indexed:!1},{type:"uint64",name:"oracleFeeUsd",indexed:!1},{type:"uint64",name:"oracleRefundFeeUsd",indexed:!1},{type:"uint128",name:"poolPrimeThreshold",indexed:!1}]},{type:"event",anonymous:!1,name:"OrderCancelled",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"string",name:"remark",indexed:!1}]},{type:"event",anonymous:!1,name:"OrderFilled",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint8",name:"orderType",indexed:!1},{type:"uint256",name:"orderSize",indexed:!1},{type:"uint256",name:"fillSize",indexed:!1},{type:"uint256",name:"filledSize",indexed:!1},{type:"uint256",name:"orderPrice",indexed:!1},{type:"uint256",name:"fillPrice",indexed:!1},{type:"int256",name:"realizedPnl",indexed:!1},{type:"int256",name:"tradingFee",indexed:!1},{type:"int256",name:"fundingFee",indexed:!1},{type:"uint256",name:"executionFeeAmount",indexed:!1},{type:"address",name:"keeper",indexed:!1}]},{type:"event",anonymous:!1,name:"OrderMarkedADL",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint256",name:"available",indexed:!1},{type:"uint256",name:"requested",indexed:!1}]},{type:"event",anonymous:!1,name:"OrderPlaced",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint8",name:"orderType",indexed:!1},{type:"uint8",name:"operation",indexed:!1},{type:"uint8",name:"direction",indexed:!1},{type:"uint8",name:"triggerType",indexed:!1},{type:"uint256",name:"collateralAmount",indexed:!1},{type:"uint256",name:"size",indexed:!1},{type:"uint256",name:"price",indexed:!1},{type:"uint8",name:"tif",indexed:!1},{type:"bool",name:"postOnly",indexed:!1},{type:"uint16",name:"slippagePct",indexed:!1},{type:"uint256",name:"executionFeeAmount",indexed:!1},{type:"uint16",name:"userLeverage",indexed:!1}]},{type:"event",anonymous:!1,name:"OrderUpdated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint256",name:"size",indexed:!1},{type:"uint256",name:"price",indexed:!1},{type:"uint256",name:"tpSize",indexed:!1},{type:"uint256",name:"tpPrice",indexed:!1},{type:"uint256",name:"slSize",indexed:!1},{type:"uint256",name:"slPrice",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolActivated",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint8",name:"oracleType",indexed:!1},{type:"bytes32",name:"oracleFeedId",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolDeactivated",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"string",name:"remark",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolDeployed",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"deployer",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"address",name:"basePoolToken",indexed:!1},{type:"address",name:"quotePoolToken",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolDeposited",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"address",name:"recipient",indexed:!1},{type:"address",name:"underlyingToken",indexed:!1},{type:"address",name:"poolToken",indexed:!1},{type:"uint256",name:"underlyingIn",indexed:!1},{type:"uint256",name:"poolTokenOut",indexed:!1},{type:"uint256",name:"oraclePrice",indexed:!1},{type:"uint256",name:"exchangeRate",indexed:!1},{type:"uint256",name:"poolTokenPrice",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolFundDistributed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"profits",indexed:!1},{type:"uint256",name:"genesisProfits",indexed:!1},{type:"uint256",name:"basePoolAmount",indexed:!1},{type:"uint256",name:"quotePoolAmount",indexed:!1},{type:"uint256",name:"genesisBasePoolAmount",indexed:!1},{type:"uint256",name:"genesisQuotePoolAmount",indexed:!1},{type:"uint256",name:"exchangedBaseFromProfits",indexed:!1},{type:"uint256",name:"exchangedBaseAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolFundingFeeSettled",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"int256",name:"prevFundingRateTracker",indexed:!1},{type:"int256",name:"nextFundingRateTracker",indexed:!1},{type:"uint256",name:"price",indexed:!1},{type:"uint8",name:"direction",indexed:!1},{type:"uint256",name:"positionSize",indexed:!1},{type:"uint256",name:"fundingFee",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolPreDeactivated",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"string",name:"remark",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolPrimed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint256",name:"baseAmount",indexed:!1},{type:"uint256",name:"quoteAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolRebateClaimed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"address",name:"recipient",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolRefunded",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"receiver",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint256",name:"baseAmount",indexed:!1},{type:"uint256",name:"quoteAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolReprimed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"primer",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolSettlementRecorded",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint256",name:"poolEntryPrice",indexed:!1},{type:"int256",name:"realizedPnl",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolWithdrawn",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"address",name:"recipient",indexed:!1},{type:"address",name:"underlyingToken",indexed:!1},{type:"address",name:"poolToken",indexed:!1},{type:"uint256",name:"poolTokenIn",indexed:!1},{type:"uint256",name:"underlyingOut",indexed:!1},{type:"uint256",name:"rebateOut",indexed:!1},{type:"uint256",name:"oraclePrice",indexed:!1},{type:"uint256",name:"exchangeRate",indexed:!1},{type:"uint256",name:"poolTokenPrice",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionEarlyClosed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"uint256",name:"positionSize",indexed:!1},{type:"uint256",name:"executeSize",indexed:!1},{type:"uint256",name:"executePrice",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionForceClosed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"uint256",name:"positionSize",indexed:!1},{type:"uint256",name:"executePrice",indexed:!1},{type:"string",name:"reason",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionLiquidated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint256",name:"positionSize",indexed:!1},{type:"uint256",name:"liquidationSize",indexed:!1},{type:"uint256",name:"liquidationPrice",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionNFTMinted",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"oldPositionId",indexed:!1},{type:"bytes32",name:"newPositionId",indexed:!1},{type:"uint256",name:"tokenId",indexed:!1},{type:"address",name:"owner",indexed:!1},{type:"address",name:"recipient",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionRiskControlDataMigrated",inputs:[{type:"bytes32",name:"from",indexed:!1},{type:"bytes32",name:"to",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionRiskControlDataUpdated",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint256",name:"freeAmount",indexed:!1},{type:"uint256",name:"lockedAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionTransfer",inputs:[{type:"address",name:"from",indexed:!1},{type:"address",name:"to",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionUpdated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"owner",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"uint8",name:"direction",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint256",name:"beforeSize",indexed:!1},{type:"uint256",name:"afterSize",indexed:!1},{type:"uint256",name:"beforeCollateralAmount",indexed:!1},{type:"uint256",name:"afterCollateralAmount",indexed:!1},{type:"uint256",name:"entryPrice",indexed:!1},{type:"int256",name:"fundingRateIndex",indexed:!1},{type:"uint8",name:"riskTier",indexed:!1},{type:"uint256",name:"earlyClosePrice",indexed:!1}]},{type:"event",anonymous:!1,name:"ReferralRebateClaimed",inputs:[{type:"address",name:"user",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReserveRebateCollected",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1},{type:"address",name:"keeper",indexed:!1},{type:"uint256",name:"poolAmount",indexed:!1},{type:"uint256",name:"stakingAmount",indexed:!1},{type:"uint256",name:"keeperAmount",indexed:!1},{type:"uint256",name:"treasuryAmount",indexed:!1},{type:"uint256",name:"reservedAmount",indexed:!1},{type:"uint256",name:"ecoFundAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReserveRebateDisbursed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1},{type:"address",name:"keeper",indexed:!1},{type:"uint256",name:"poolAmount",indexed:!1},{type:"uint256",name:"stakingAmount",indexed:!1},{type:"uint256",name:"keeperAmount",indexed:!1},{type:"uint256",name:"treasuryAmount",indexed:!1},{type:"uint256",name:"reservedAmount",indexed:!1},{type:"uint256",name:"ecoFundAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"TradingFeeTierUpdated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"uint8",name:"feeType",indexed:!1},{type:"uint8",name:"tier",indexed:!1},{type:"uint32",name:"takerFeeRate",indexed:!1},{type:"int32",name:"makerFeeRate",indexed:!1},{type:"bool",name:"isEnabled",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"event",anonymous:!1,name:"UserFeeDataUpdated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"signer",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"uint8",name:"tier",indexed:!1},{type:"address",name:"referrer",indexed:!1},{type:"uint32",name:"totalReferralRebatePct",indexed:!1},{type:"uint32",name:"referrerRebatePct",indexed:!1}]},{type:"event",anonymous:!1,name:"UserSettlementRecorded",inputs:[{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"int256",name:"charge",indexed:!1},{type:"int256",name:"realizedPnl",indexed:!1},{type:"int256",name:"tradingFee",indexed:!1},{type:"int256",name:"fundingFee",indexed:!1}]},{type:"event",anonymous:!1,name:"UserSpecialFeeTierUpdated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"uint8",name:"oldTier",indexed:!1},{type:"uint8",name:"newTier",indexed:!1}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"emitCollateralAccepted",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"quoteDebt"},{type:"uint256",name:"baseCollateral"},{type:"uint256",name:"quoteCollateral"},{type:"uint256",name:"totalQuoteDebt"},{type:"uint256",name:"totalBaseCollateral"}]}],outputs:[]},{type:"function",name:"emitCollateralAdjusted",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint8",name:"direction"},{type:"uint256",name:"beforeCollateralAmount"},{type:"uint256",name:"afterCollateralAmount"}]}],outputs:[]},{type:"function",name:"emitEnterDispute",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[]},{type:"function",name:"emitExchanged",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"user"},{type:"address",name:"source"},{type:"address",name:"target"},{type:"uint256",name:"sourceAmount"},{type:"uint256",name:"targetAmount"},{type:"uint256",name:"price"}]}],outputs:[]},{type:"function",name:"emitExecutionMatched",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256[]",name:"triggerOrderIds"},{type:"uint256[]",name:"matchedOrderIds"},{type:"uint8",name:"matchType"},{type:"uint256",name:"price"}]}],outputs:[]},{type:"function",name:"emitExitDispute",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[]},{type:"function",name:"emitFundingRateUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"uint64",name:"epochs"},{type:"uint64",name:"duration"},{type:"uint64",name:"previousEpochTime"},{type:"uint64",name:"lastEpochTime"},{type:"bytes32",name:"poolId"},{type:"int256",name:"fundingRate"},{type:"int256",name:"fundingRateTracker"},{type:"uint256",name:"price"}]}],outputs:[]},{type:"function",name:"emitLiquidityLockUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint64",name:"windowAnchor"},{type:"uint256",name:"priceFloor"},{type:"uint256",name:"priceCeiling"},{type:"int256",name:"openInterest"}]}],outputs:[]},{type:"function",name:"emitLiquidityMigrated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"user"},{type:"bytes32",name:"fromPoolId"},{type:"bytes32",name:"toPoolId"},{type:"uint256",name:"lpAmountIn"},{type:"uint256",name:"lpAmountOut"}]}],outputs:[]},{type:"function",name:"emitLiquidityStopOrderCancelled",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"uint256",name:"orderId"},{type:"bytes32",name:"poolId"},{type:"string",name:"reason"}]}],outputs:[]},{type:"function",name:"emitLiquidityStopOrderCreated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"uint256",name:"orderId"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"poolType"},{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}],outputs:[]},{type:"function",name:"emitLiquidityStopOrderExecuted",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"uint256",name:"orderId"},{type:"bytes32",name:"poolId"},{type:"address",name:"executor"},{type:"uint256",name:"oraclePrice"},{type:"uint256",name:"poolTokenPrice"}]}],outputs:[]},{type:"function",name:"emitMarketCreated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"marketId"},{type:"address",name:"deployer"},{type:"address",name:"quoteToken"},{type:"uint32",name:"baseReserveRatio"},{type:"uint32",name:"quoteReserveRatio"},{type:"uint64",name:"oracleFeeUsd"},{type:"uint64",name:"oracleRefundFeeUsd"},{type:"uint128",name:"poolPrimeThreshold"}]}],outputs:[]},{type:"function",name:"emitOrderCancelled",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"string",name:"remark"}]}],outputs:[]},{type:"function",name:"emitOrderFilled",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint256",name:"orderId"},{type:"uint8",name:"orderType"},{type:"uint256",name:"orderSize"},{type:"uint256",name:"fillSize"},{type:"uint256",name:"filledSize"},{type:"uint256",name:"orderPrice"},{type:"uint256",name:"fillPrice"},{type:"int256",name:"realizedPnl"},{type:"int256",name:"tradingFee"},{type:"int256",name:"fundingFee"},{type:"uint256",name:"executionFeeAmount"},{type:"address",name:"keeper"}]}],outputs:[]},{type:"function",name:"emitOrderMarkedADL",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"uint256",name:"available"},{type:"uint256",name:"requested"}]}],outputs:[]},{type:"function",name:"emitOrderPlaced",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint256",name:"orderId"},{type:"uint8",name:"orderType"},{type:"uint8",name:"operation"},{type:"uint8",name:"direction"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"collateralAmount"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"uint8",name:"tif"},{type:"bool",name:"postOnly"},{type:"uint16",name:"slippagePct"},{type:"uint256",name:"executionFeeAmount"},{type:"uint16",name:"userLeverage"}]}],outputs:[]},{type:"function",name:"emitOrderUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"uint256",name:"tpSize"},{type:"uint256",name:"tpPrice"},{type:"uint256",name:"slSize"},{type:"uint256",name:"slPrice"}]}],outputs:[]},{type:"function",name:"emitPoolActivated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint8",name:"oracleType"},{type:"bytes32",name:"oracleFeedId"}]}],outputs:[]},{type:"function",name:"emitPoolDeactivated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"string",name:"remark"}]}],outputs:[]},{type:"function",name:"emitPoolDeployed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"marketId"},{type:"bytes32",name:"poolId"},{type:"address",name:"deployer"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"address",name:"basePoolToken"},{type:"address",name:"quotePoolToken"}]}],outputs:[]},{type:"function",name:"emitPoolDeposited",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"address",name:"recipient"},{type:"address",name:"underlyingToken"},{type:"address",name:"poolToken"},{type:"uint256",name:"underlyingIn"},{type:"uint256",name:"poolTokenOut"},{type:"uint256",name:"oraclePrice"},{type:"uint256",name:"exchangeRate"},{type:"uint256",name:"poolTokenPrice"}]}],outputs:[]},{type:"function",name:"emitPoolFundDistributed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"profits"},{type:"uint256",name:"genesisProfits"},{type:"uint256",name:"basePoolAmount"},{type:"uint256",name:"quotePoolAmount"},{type:"uint256",name:"genesisBasePoolAmount"},{type:"uint256",name:"genesisQuotePoolAmount"},{type:"uint256",name:"exchangedBaseFromProfits"},{type:"uint256",name:"exchangedBaseAmount"}]}],outputs:[]},{type:"function",name:"emitPoolFundingFeeSettled",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"int256",name:"prevFundingRateTracker"},{type:"int256",name:"nextFundingRateTracker"},{type:"uint256",name:"price"},{type:"uint8",name:"direction"},{type:"uint256",name:"positionSize"},{type:"uint256",name:"fundingFee"}]}],outputs:[]},{type:"function",name:"emitPoolPreDeactivated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"string",name:"remark"}]}],outputs:[]},{type:"function",name:"emitPoolPrimed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"}]}],outputs:[]},{type:"function",name:"emitPoolRebateClaimed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"address",name:"recipient"},{type:"uint256",name:"amount"}]}],outputs:[]},{type:"function",name:"emitPoolRefunded",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"receiver"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"}]}],outputs:[]},{type:"function",name:"emitPoolReprimed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"primer"},{type:"address",name:"token"},{type:"uint256",name:"amount"}]}],outputs:[]},{type:"function",name:"emitPoolSettlementRecorded",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"uint256",name:"poolEntryPrice"},{type:"int256",name:"realizedPnl"}]}],outputs:[]},{type:"function",name:"emitPoolWithdrawn",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"address",name:"recipient"},{type:"address",name:"underlyingToken"},{type:"address",name:"poolToken"},{type:"uint256",name:"poolTokenIn"},{type:"uint256",name:"underlyingOut"},{type:"uint256",name:"rebateOut"},{type:"uint256",name:"oraclePrice"},{type:"uint256",name:"exchangeRate"},{type:"uint256",name:"poolTokenPrice"}]}],outputs:[]},{type:"function",name:"emitPositionEarlyClosed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint256",name:"orderId"},{type:"uint256",name:"positionSize"},{type:"uint256",name:"executeSize"},{type:"uint256",name:"executePrice"}]}],outputs:[]},{type:"function",name:"emitPositionForceClosed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint256",name:"orderId"},{type:"uint256",name:"positionSize"},{type:"uint256",name:"executePrice"},{type:"string",name:"reason"}]}],outputs:[]},{type:"function",name:"emitPositionLiquidated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint256",name:"orderId"},{type:"uint256",name:"positionSize"},{type:"uint256",name:"liquidationSize"},{type:"uint256",name:"liquidationPrice"}]}],outputs:[]},{type:"function",name:"emitPositionNFTMinted",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"bytes32",name:"oldPositionId"},{type:"bytes32",name:"newPositionId"},{type:"uint256",name:"tokenId"},{type:"address",name:"owner"},{type:"address",name:"recipient"}]}],outputs:[]},{type:"function",name:"emitPositionRiskControlDataMigrated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"from"},{type:"bytes32",name:"to"}]}],outputs:[]},{type:"function",name:"emitPositionRiskControlDataUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint256",name:"freeAmount"},{type:"uint256",name:"lockedAmount"}]}],outputs:[]},{type:"function",name:"emitPositionTransfer",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"bytes32",name:"positionId"}]}],outputs:[]},{type:"function",name:"emitPositionUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"owner"},{type:"bytes32",name:"positionId"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"direction"},{type:"uint256",name:"orderId"},{type:"uint256",name:"beforeSize"},{type:"uint256",name:"afterSize"},{type:"uint256",name:"beforeCollateralAmount"},{type:"uint256",name:"afterCollateralAmount"},{type:"uint256",name:"entryPrice"},{type:"int256",name:"fundingRateIndex"},{type:"uint8",name:"riskTier"},{type:"uint256",name:"earlyClosePrice"}]}],outputs:[]},{type:"function",name:"emitReferralRebateClaimed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"user"},{type:"address",name:"token"},{type:"uint256",name:"amount"}]}],outputs:[]},{type:"function",name:"emitReserveRebateCollected",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"token"},{type:"uint256",name:"amount"},{type:"address",name:"keeper"},{type:"uint256",name:"poolAmount"},{type:"uint256",name:"stakingAmount"},{type:"uint256",name:"keeperAmount"},{type:"uint256",name:"treasuryAmount"},{type:"uint256",name:"reservedAmount"},{type:"uint256",name:"ecoFundAmount"}]}],outputs:[]},{type:"function",name:"emitReserveRebateDisbursed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"token"},{type:"uint256",name:"amount"},{type:"address",name:"keeper"},{type:"uint256",name:"poolAmount"},{type:"uint256",name:"stakingAmount"},{type:"uint256",name:"keeperAmount"},{type:"uint256",name:"treasuryAmount"},{type:"uint256",name:"reservedAmount"},{type:"uint256",name:"ecoFundAmount"}]}],outputs:[]},{type:"function",name:"emitTradingFeeTierUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"uint8",name:"feeType"},{type:"uint8",name:"tier"},{type:"uint32",name:"takerFeeRate"},{type:"int32",name:"makerFeeRate"},{type:"bool",name:"isEnabled"}]}],outputs:[]},{type:"function",name:"emitUserFeeDataUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"signer"},{type:"address",name:"user"},{type:"uint8",name:"tier"},{type:"address",name:"referrer"},{type:"uint32",name:"totalReferralRebatePct"},{type:"uint32",name:"referrerRebatePct"}]}],outputs:[]},{type:"function",name:"emitUserFeeSettlementAndDistributed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"int256",name:"charge"},{type:"int256",name:"realizedPnl"},{type:"int256",name:"tradingFee"},{type:"int256",name:"fundingFee"},{type:"int32",name:"tradingFeeRate"},{type:"bool",name:"isMaker"},{type:"uint256",name:"baseTradingFee"},{type:"uint256",name:"brokerTradingFee"},{type:"address",name:"broker"},{type:"uint256",name:"referralRebate"},{type:"uint256",name:"referrerRebate"},{type:"address",name:"referrer"},{type:"int256",name:"reserveFee"}]}],outputs:[]},{type:"function",name:"emitUserSpecialFeeTierUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"uint8",name:"oldTier"},{type:"uint8",name:"newTier"}]}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"isBlockHeaderEmitted",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint256",name:"blockNumber"}],outputs:[{type:"bool"}]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"registerContract",constant:!1,payable:!1,inputs:[{type:"bytes32[]",name:"identifiers"}],outputs:[]},{type:"function",name:"sequencer",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]}];var Xe=class{constructor(e,t){this.configManager=e,this.logger=t}getOrderIdFromTransaction(e){if(!e||!e.logs)return null;for(let t=0;t<e.logs.length;t++){let n=e.logs[t];this.logger.info(`Log ${t}:`,{address:n.address,topics:n.topics,data:n.data});try{let a=Ds({abi:da,data:n.data??"0x",topics:n.topics??[]}),i=a.args;if(a.eventName==="OrderPlaced"&&i?.orderId!=null)return String(i.orderId)}catch{continue}}return null}async getApproveQuoteAmount(e,t,n,a){try{if(!n||typeof n=="string"&&!n.trim())throw new Error("getApproveQuoteAmount: tokenAddress is required (ERC20 contract address)");let i=a??w(t).Account,p=await de(t,n).read.allowance([e,i]);return{code:0,data:String(p)}}catch(i){throw this.logger.error("Error getting allowance:",i),typeof i=="string"?i:await I(i)}}async needsApproval(e,t,n,a,i){try{let p=(await this.getApproveQuoteAmount(e,t,n,i)).data,o=BigInt(p),u=BigInt(a);return o<u}catch(r){return this.logger.error("Error checking approval needs:",r),!0}}async approveAuthorization({chainId:e,quoteAddress:t,amount:n,spenderAddress:a}){try{let i=await Le(e,t),r=n??Os,p=a??w(e).Account,o=await this.getGasPriceByRatio(),u=await i.write.approve([p,r],{gasPrice:o});return await h(e).waitForTransactionReceipt({hash:u}),{code:0,message:"Approval success"}}catch(i){return this.logger.error("Approval error:",i),{code:-1,message:i?.message}}}async getUserTradingFeeRate(e,t,n){let a=this.configManager.getConfig(),i=a.brokerAddress;try{let r=he(n,i),p=a.seamlessMode?a.seamlessAccount?.masterAddress:await this.configManager.getSignerAddress(n),o=await r.read.getUserFeeRate([p,e,t]);return{code:0,data:{takerFeeRate:o[0].toString(),makerFeeRate:o[1].toString(),baseTakerFeeRate:o[2].toString(),baseMakerFeeRate:o[3].toString()}}}catch(r){return this.logger.error("Error getting user trading fee rate:",r),{code:-1,message:r?.message??"Unknown error"}}}async getNetworkFee(e,t){try{return(await(await oe(t,0)).read.getExecutionFee([e])).toString()}catch(n){return this.logger.error("Error getting network fee:",n),"0"}}async getOraclePrice(e,t){try{let n=await z(t,e);if(!n)throw new Error("Failed to get price data");return n}catch(n){throw this.logger.error("Error getting oracle price:",n),n}}async buildUpdatePriceParams(e,t){let n=await this.getOraclePrice(e,t);if(!n)throw new Error("Failed to get price data");return[{poolId:e,oracleUpdateData:n.vaa,publishTime:n.publishTime,oracleType:n.oracleType,value:n.value,price:n.price}]}transferKlineResolutionToInterval(e){switch(e){case"1m":return 1;case"5m":return 5;case"15m":return 15;case"30m":return 30;case"1h":return 60;case"4h":return 240;case"1d":return 1440;case"1w":return 10080;case"1M":return 40320;default:throw new g("PARAM_ERROR",`Invalid kline resolution: ${e}`)}}async getErrorMessage(e,t="Unknown error"){try{if(typeof e=="string")return e;if(e instanceof g)return e.message;let n=await I(e);return n?n.error:JSON.stringify(e)}catch(n){return n?.message??n?.toString()??t}}async checkSeamlessGas(e,t){let n=await oe(t,0),a=Se(t),i=await n.read.getForwardFeeByToken([a]),r=w(t),o=await de(t,r.ERC20).read.balanceOf([e]);return!(BigInt(i)>0n&&BigInt(o)<BigInt(i))}async getLiquidityInfo({chainId:e,poolId:t,marketPrice:n}){try{return{code:0,data:await(await xe(e,0)).read.getPoolInfo([t,n])}}catch(a){return this.logger.error("Error getting pool info:",a),{code:-1,message:a?.message}}}formatErrorMessage(e){if(typeof e=="string")return e;if(e instanceof g)return e.message;if(e?.code==="ACTION_REJECTED"||e?.code===4001||e?.info?.error?.code===4001||typeof e?.message=="string"&&(e.message.toLowerCase().includes("user rejected")||e.message.toLowerCase().includes("denied")))return"User Rejected";let t=e?.data;if(!t&&e?.message&&typeof e.message=="string"){let n=e.message.match(/data=["'](0x[0-9a-fA-F]+)["']/i);n&&n[1]&&(t=n[1])}if(t){let n=typeof t=="string"&&t.startsWith("0x")?t.slice(0,10).toLowerCase():null;if(n){let a=Object.keys(Ae).find(i=>i.toLowerCase()===n);if(a)return Ae[a]}}return e?.reason?e.reason:e?.message?e.message:JSON.stringify(e)}async getGasPriceByRatio(){let e=this.configManager.getConfig().chainId;return(await T(e)).gasPrice}async getGasLimitByRatio(e){let t=this.configManager.getConfig().chainId,n=C[t];return R(e,n?.gasLimitRatio??1.3)}};import{encodeFunctionData as Vt,maxUint256 as Fs,zeroAddress as Ns}from"viem";import Fe from"dayjs";var Ze=class{constructor(e,t,n,a){this.configManager=e,this.logger=t,this.utils=n,this.client=a}async withRetry(e,t=3,n=300){let a;for(let i=0;i<t;i++)try{return await e()}catch(r){a=r,i<t-1&&await new Promise(p=>setTimeout(p,n))}throw a}async getWalletQuoteTokenBalance(e,t){if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER","Invalid signer");let n=w(e),a=de(e,n.ERC20),i=await this.configManager.getSignerAddress(e);return{code:0,data:await a.read.balanceOf([t||i])}}async updateAndWithdraw(e,t,n,a,i){let r=this.configManager.getConfig(),p=w(i);try{let o=this.configManager.getConfig().seamlessAccount?.authorized,u=this.configManager.getConfig().seamlessAccount?.wallet;if(r.seamlessMode&&o&&u){if(!await this.utils.checkSeamlessGas(e,i))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let f=await F(i),m=Vt({abi:Ee,functionName:"updateAndWithdraw",args:[e,t,!0,a]}),b=await f.read.nonces([u.address]),A={from:u.address??"",to:p.Account,value:"0",gas:"350000",deadline:Fe().add(60,"minute").unix(),data:m,nonce:b.toString()};return{code:0,message:"withdraw success",data:await this.client.seamless.forwarderTx(A,i,u)}}let l=await(await wt(i)).write.updateAndWithdraw([e,t,n,a]);return{code:0,data:await h(i).waitForTransactionReceipt({hash:l})}}catch(o){return{code:-1,message:o.message}}}async deposit({amount:e,tokenAddress:t,chainId:n}){let a=this.configManager.getConfig(),i=this.configManager.hasSigner()?await this.configManager.getSignerAddress(n):"",r=w(n);try{let p=await this.utils.needsApproval(i,n,t,e,r.Account),o=this.configManager.getConfig().seamlessAccount?.authorized,u=this.configManager.getConfig().seamlessAccount?.wallet;if(a.seamlessMode&&o&&u){if(!await this.utils.checkSeamlessGas(i,n))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let f=await F(n),m=Vt({abi:Ee,functionName:"deposit",args:[i,t,e]}),b=await f.read.nonces([u.address]),A={from:u.address??"",to:r.Account,value:"0",gas:"350000",deadline:Fe().add(60,"minute").unix(),data:m,nonce:b.toString()};return{code:0,message:"deposit success",data:await this.client.seamless.forwarderTx(A,n,u)}}if(p){let c=await this.utils.approveAuthorization({chainId:n,quoteAddress:t,amount:Fs.toString(),spenderAddress:r.Account});if(c.code!==0)throw new Error(c.message)}let l=await(await wt(n)).write.deposit([i,t,e]);return{code:0,data:await h(n).waitForTransactionReceipt({hash:l})}}catch(p){return{code:-1,message:p.message}}}async getAvailableMarginBalance({poolId:e,chainId:t,address:n}){try{let a=await this.getAccountInfo(t,n,e);if(a.code!==0)throw new g("REQUEST_FAILED","Failed to get account info");let i=await this.client.appeal.getAppealStatus(e,t,n),r=a.data,p=BigInt(r?.quoteProfit??0),o=BigInt(r?.freeMargin??0),u=BigInt(r?.lockedMargin??0),d=i?.code===0?i.data:null,l=d?.status===1?BigInt(d?.lockedMargin??0):0n;return{code:0,data:o+p-u-l}}catch(a){return{code:-1,message:a.message}}}async getAccountInfo(e,t,n){let a=await xe(e);try{return{code:0,data:await a.read.getAccountInfo([n,t])}}catch(i){return{code:-1,message:i.message}}}async getAccountVipInfo(e,t){let n=this.configManager.getConfig(),a=he(e,n.brokerAddress),r=await h(e).getBlock({blockTag:"latest"}),p=Number(r?.timestamp??BigInt(Fe().unix()))+300,o=await this.configManager.getAccessToken()??"";try{let u=await this.client.api.getCurrentEpoch({address:t,accessToken:o,broker:n.brokerAddress});if(u.code!==9200)throw new g("REQUEST_FAILED",u.msg??"Failed to get current epoch");let d=await a.read.userFeeData([u?.data??0,t]),l;try{l=await this.withRetry(()=>a.read.userNonces([t]))}catch{l=0n}return{code:0,data:{...d,nonce:l.toString(),deadline:p}}}catch(u){return{code:-1,message:u.message}}}async getAccountVipInfoByBackend(e,t,n,a){let i=await this.configManager.getAccessToken()??"";try{let r=await this.client.api.getAccountVipInfo({address:e,accessToken:i,chainId:t,deadline:n,nonce:a});if(r.code!==9200)throw new g("REQUEST_FAILED",r.msg??"Failed to get account vip info");return{code:0,data:r.data}}catch(r){return{code:-1,message:r.message}}}async setUserFeeData(e,t,n,a,i){let r=this.configManager.getConfig(),p=this.configManager.getConfig().seamlessAccount?.authorized,o=this.configManager.getConfig().seamlessAccount?.wallet;if(n<Fe().unix())throw new g("REQUEST_FAILED","Invalid deadline, please try again");let u={user:e,nonce:a.nonce,deadline:n,feeData:{tier:a.tier,referrer:a.referrer||Ns,totalReferralRebatePct:a.totalReferralRebatePct,referrerRebatePct:a.referrerRebatePct},signature:i};try{if(r.seamlessMode&&p&&o){if(!await this.utils.checkSeamlessGas(e,t))throw new g("INSUFFICIENT_BALANCE","Insufficient relay fee");let m=await F(t),b=Vt({abi:O,functionName:"setUserFeeData",args:[u]}),A=await m.read.nonces([o.address]),P={from:o.address??"",to:r.brokerAddress,value:"0",gas:"350000",deadline:Fe().add(60,"minute").unix(),data:b,nonce:A.toString()};return{code:0,data:await this.client.seamless.forwarderTx(P,t,o)}}let d=await V(t,r.brokerAddress),l=await d.read.userNonces([e]);if(parseInt(l.toString())+1!==parseInt(a.nonce.toString()))throw new g("REQUEST_FAILED","Invalid nonce, please try again");let y=await d.write.setUserFeeData([u]);return{code:0,data:await h(t).waitForTransactionReceipt({hash:y})}}catch(d){return{code:-1,message:d.message}}}};function la(s,e){return`${encodeURIComponent(s)}=${encodeURIComponent(typeof e=="number"?e:`${e}`)}`}function _s(s,e){return la(e,s[e])}function Bs(s,e){return s[e].map(n=>la(e,n)).join("&")}function Ls(s){let e=s||{};return Object.keys(e).filter(n=>typeof e[n]<"u").map(n=>Array.isArray(e[n])?Bs(e,n):_s(e,n)).join("&")}function $t(s){let e=Ls(s);return e?`?${e}`:""}import{merge as et}from"lodash-es";var tt=class{constructor(e){this.configManager=e}getHost(){let{isTestnet:e,isBetaMode:t}=this.configManager.getConfig();return t?"https://api-beta.myx.finance":e?"https://api-test.myx.cash":"https://api.myx.finance"}async buildAuthParams(){let e=this.configManager.getConfig();if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER");let t=await this.configManager.getAccessToken()??"",n=await this.configManager.getSignerAddress(e.chainId);if(!n)throw new g("INVALID_SIGNER");return{headers:{myx_openapi_access_token:t,myx_openapi_account:n}}}buildRequestPath(e){return e.startsWith("http")?e:this.getHost()+e}async get(e,t,{auth:n=!1,...a}={}){let i=n?await this.buildAuthParams():{};return x.get(this.buildRequestPath(e),t,et(i,a))}async post(e,t,{auth:n=!1,...a}={}){let i=n?await this.buildAuthParams():{};return x.post(this.buildRequestPath(e),t,et(i,a))}async put(e,t,{auth:n=!1,...a}={}){let i=n?await this.buildAuthParams():{};return x.put(this.buildRequestPath(e),t,et(i,a))}async delete(e,{auth:t=!1,...n}={}){let a=t?await this.buildAuthParams():{};return x.delete(this.buildRequestPath(e),et(a,n))}};var nt=class extends tt{constructor(e,t){super(e),this.logger=t}async getTradeFlow({accessToken:e,address:t,...n}){return x.get(`${this.getHost()}/openapi/gateway/scan/trade/flow`,n,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async getPoolSymbolAll(){return x.get(`${this.getHost()}/openapi/gateway/scan/pools`)}async fetchForwarderGetApi(e){return await x.get(`${this.getHost()}/v2/agent/forwarder/get${$t(e)}`)}async getPoolList(){return x.get(`${this.getHost()}/openapi/gateway/scan/market/list`)}async forwarderTxApi(e,t){return x.post(`${this.getHost()}/v2/agent/forwarder/tx-v2`,e,{headers:{"myx-chain-id":t.toString()}})}async getOraclePrice(e,t=[]){if(t.length)return x.get(`${this.getHost()}/openapi/gateway/quote/price/oracles`,{chainId:e,poolIds:t.join(",")});throw new Error("Invalid pool id")}async getPoolDetail(e,t){return await x.get(`${this.getHost()}/openapi/gateway/scan/market/info?chainId=${e}&poolId=${t}`)}async getPoolLevelConfig({poolId:e,chainId:t}){return x.get(`${this.getHost()}/openapi/gateway/risk/market_pool/level_config${$t({poolId:e,chainId:t})}`)}async getPositions(e,t){return await x.get(`${this.getHost()}/openapi/gateway/scan/position/open`,void 0,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async getOrders(e,t){return await x.get(`${this.getHost()}/openapi/gateway/scan/order/open`,void 0,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async getPoolOpenOrders(e,t,n){return await x.get(`${this.getHost()}/openapi/gateway/scan/market/pool-order/open?chainId=${n}`,void 0,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async getKlineData({chainId:e,poolId:t,endTime:n,limit:a,interval:i}){return x.get(`${this.getHost()}/openapi/gateway/quote/candles`,{chainId:e,poolId:t,endTime:n,limit:a,interval:i})}async getKlineLatestBar(e){return x.get(`${this.getHost()}/openapi/gateway/quote/candle/latest`,e)}async getTickerData({chainId:e,poolIds:t}){return x.get(`${this.getHost()}/openapi/gateway/quote/candle/tickers`,{chainId:e,poolIds:t.join(",")})}async getAllTickers(){return x.get(`${this.getHost()}/v2/mx-gateway/quote/candle/all_tickers`)}async searchMarketAuth({accessToken:e,address:t,...n}){return x.get(`${this.getHost()}/openapi/gateway/scan/market/ac-search`,n,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async searchMarket({...e}){return x.get(`${this.getHost()}/openapi/gateway/scan/market/search`,e)}async addFavorite({accessToken:e,address:t,...n}){return x.get(`${this.getHost()}/openapi/gateway/scan/market/add-favorites`,n,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async removeFavorite({accessToken:e,address:t,...n}){return x.get(`${this.getHost()}/openapi/gateway/scan/market/cancel-favorites`,n,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async getFavoritesList({accessToken:e,address:t,...n}){return x.get(`${this.getHost()}/openapi/gateway/scan/market/favorites`,n,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async getBaseDetail({...e}){return x.get(`${this.getHost()}/openapi/gateway/scan/market/base-details`,e)}async getMarketDetail({...e}){return x.get(`${this.getHost()}/openapi/gateway/scan/market/detail`,e)}async getHistoryOrders({accessToken:e,address:t,...n}){return x.get(`${this.getHost()}/openapi/gateway/scan/order/closed`,n,{headers:{myx_openapi_account:t,myx_openapi_access_token:e}})}async getPositionHistory({accessToken:e,address:t,...n}){return x.get(`${this.getHost()}/openapi/gateway/scan/position/closed`,n,{headers:{myx_openapi_account:t,myx_openapi_access_token:e}})}async getMarketList(){return x.get(`${this.getHost()}/openapi/gateway/scan/market`)}async getAccountVipInfo({address:e,accessToken:t,chainId:n,deadline:a,nonce:i}){return x.get(`${this.getHost()}/openapi/gateway/vip/trade_config`,{chainId:n,deadline:a,nonce:i},{headers:{myx_openapi_account:e,myx_openapi_access_token:t}})}async getAppealList(e){return this.get("/openapi/gateway/scan/dispute/list",e,{auth:!0})}async getAppealDetail(e){return this.get("/openapi/gateway/scan/dispute/details",e,{auth:!0})}async uploadAppealEvidence(e){return this.get("/openapi/gateway/scan/dispute/upload/evidence",e,{auth:!0})}async getAppealReconsiderationList(e){return this.get("/openapi/gateway/scan/dispute/appeal/list",e,{auth:!0})}async getAppealReconsiderationDetail(e){return this.get("/openapi/gateway/scan/dispute/appeal/details",e,{auth:!0})}async getAppealReimbursementList(e){return this.get("/openapi/gateway/scan/reimbursement/list",e,{auth:!0})}async getAppealNodeVoteList(e){return this.get("/openapi/gateway/scan/node/vote-list",e)}async getAppealNodeVoteDetails(e){return this.get("/openapi/gateway/scan/node/vote-details",e)}async getIsVoteNode(e){return this.get("/openapi/gateway/scan/node/vote-node-check",e)}async postVoteSignature(e){return this.get("/openapi/gateway/scan/node/vote",e,{auth:!0})}async getPedingVoteCount(){return this.get("/openapi/gateway/scan/node/pending-vote-total",{},{auth:!0})}async getMyAppealCount(){return this.get("/openapi/gateway/scan/processing-total",{},{auth:!0})}async getWarmholeSign(e){return this.get("/openapi/gateway/scan/get-warmhole-sign",e,{auth:!0})}async getDisputeTotalCount(){return this.get("/openapi/gateway/scan/dispute/dispute-total",{},{auth:!0})}async getAppealTotalCount(){return this.get("/openapi/gateway/scan/dispute/appeal-total",{},{auth:!0})}async getReimbursementTotalCount(){return this.get("/openapi/gateway/scan/dispute/reimbursement-total",{},{auth:!0})}async getCurrentEpoch({address:e,accessToken:t,broker:n}){return x.get(`${this.getHost()}/openapi/gateway/scan/get-current-epoch`,{broker:n},{headers:{myx_openapi_account:e,myx_openapi_access_token:t}})}async getPoolAppealStatus({poolId:e,chainId:t,address:n,accessToken:a}){return x.get(`${this.getHost()}/openapi/gateway/scan/pool-id-dispute-state?poolId=${e}&chainId=${t}`,{},{headers:{myx_openapi_account:n,myx_openapi_access_token:a}})}};import{AES as at,Utf8 as fe,CBC as st,Pkcs7 as it}from"crypto-es";import{keccak256 as Us,hexToBytes as fa,toHex as Ht,isHex as ga,bytesToHex as Gs,encodeFunctionData as qs,zeroAddress as Ws,maxUint256 as ya}from"viem";import{privateKeyToAccount as pt}from"viem/accounts";import zs from"dayjs";var ma=async s=>{try{let e=await s.read.eip712Domain();return{name:e.name,version:e.version,chainId:BigInt(e.chainId),verifyingContract:e.verifyingContract}}catch(e){throw new Error(`Error fetching EIP712 domain: ${e}`)}};var Vs={ForwardRequest:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"value",type:"uint256"},{name:"gas",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint48"},{name:"data",type:"bytes"}]},$s=2,Hs=async s=>{let t=new TextEncoder().encode(s),n=await window.crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(i=>i.toString(16).padStart(2,"0")).join("")},Qs="jAkBlC4~5!6@#$%^";function Ks(s){let e=fa(s);if(e.length<65)throw new Error("Invalid signature length");let t=Ht(e.slice(0,32)),n=Ht(e.slice(32,64));return{v:e[64],r:t,s:n}}var Js=s=>{let e=new Uint8Array(new TextEncoder().encode(s)),t=Gs(e),n=Us(t),a=fa(n).slice(0,32),i=Ht(a);if(!ga(i)||i.length!==66)throw new g("INVALID_PRIVATE_KEY","Invalid private key generated");let r=pt(i);return{privateKey:i,wallet:r}},rt=s=>{if(s.length>=16)return s;let t=16-s.length,n=Math.ceil(t/s.length),a=s.repeat(n).slice(0,t);return s+a},ot=()=>fe.parse(Qs);async function js(s,e,t,n,a,i,r,p){let o=de(e,t),u=await ma(o),[d]=await s.getAddresses();if(!d)throw new g("INVALID_SIGNER","No account for signPermit");let l={Permit:[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},y={owner:n,spender:a,value:i,nonce:r,deadline:p},c=await s.signTypedData({account:d,domain:{...u,chainId:u.chainId},types:l,primaryType:"Permit",message:y});return Ks(c)}var ut=class{constructor(e,t,n,a,i){this.configManager=e,this.logger=t,this.utils=n,this.account=a,this.api=i}async onCheckRelayer(e,t,n){return await(await F(n)).read.isUserRelayerEnabled([e,t])}async getUSDPermitParams(e,t){if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER","Signer is required for permit");let n=await N(t),a=w(t),[i]=await n.getAddresses();if(!i)throw new g("INVALID_SIGNER","No account");let r=de(t,a.ERC20);try{let p=await r.read.nonces([i]),o=await js(n,t,a.ERC20,i,a.TRADING_ROUTER,ya,p,e);return[{token:a.ERC20,owner:i,spender:a.TRADING_ROUTER,value:ya.toString(),deadline:e.toString(),v:o.v,r:o.r,s:o.s}]}catch{throw new g("INVALID_PRIVATE_KEY","Invalid private key generated")}}async forwarderTx({from:e,to:t,value:n,gas:a,deadline:i,data:r,nonce:p},o,u){let l=await(await F(o)).read.eip712Domain(),y={name:l.name,version:l.version,chainId:l.chainId,verifyingContract:l.verifyingContract},c=u??await N(o),[f]=await c.getAddresses();if(!f)throw new g("INVALID_SIGNER","Missing signer for forwarderTx");let m=await c.signTypedData({account:f,domain:y,types:Vs,primaryType:"ForwardRequest",message:{from:e,to:t,value:BigInt(n),gas:BigInt(a),nonce:BigInt(p),deadline:BigInt(i),data:r}}),b=Se(o);return this.logger.info("forwarderTx-->",{from:e,to:t,value:n,gas:a,nonce:p,data:r,deadline:i,signature:m,forwardFeeToken:b},o),await this.api.forwarderTxApi({from:e,to:t,value:n,gas:a,nonce:p,data:r,deadline:i,signature:m,forwardFeeToken:b},o)}async authorizeSeamlessAccount({approve:e,seamlessAddress:t,chainId:n}){let a=this.configManager.getConfig(),i=this.configManager.hasSigner()?await this.configManager.getSignerAddress(n):"";if(e){let y=await this.account.getWalletQuoteTokenBalance(n,i);this.logger.info("balanceRes-->",y);let c=y.data,f=await oe(n),m=Se(n);this.logger.info("forwardFeeToken-->",m);let b=await f.read.getForwardFeeByToken([m]);this.logger.info("pledgeFee-->",b);let A=BigInt(b)*BigInt($s);if(this.logger.info("auth params-->",{gasFee:A,balance:c},n,m),this.logger.info("gasFee > 0 && gasFee > BigInt(balance)-->",A>0&&A>BigInt(c)),A>0&&A>BigInt(c))throw new g("INSUFFICIENT_BALANCE","Insufficient balance")}let r=zs().add(60,"minute").unix(),p=[];if(e)try{p=await this.getUSDPermitParams(r,n)}catch(y){console.warn("Failed to get USD permit params, proceeding without permit:",y),p=[]}let o=await F(n,1),u=await(await F(n)).read.nonces([i]),d=qs({abi:Re,functionName:"permitAndApproveForwarder",args:[t,e,p]}),l=await this.forwarderTx({from:i,to:o.address,value:"0",gas:"800000",nonce:u.toString(),data:d,deadline:r},n);if(l.data?.txHash){for(let f=0;f<5;f++)try{if((await this.api.fetchForwarderGetApi({requestId:l.data.requestId})).data?.status===9)return{code:0,data:{seamlessAccount:t,authorized:e}};f<4&&await new Promise(b=>setTimeout(b,1e3))}catch(m){console.error("Poll transaction from chain error:",m),f<4&&await new Promise(b=>setTimeout(b,1e3))}return{code:-1,data:null,message:"Transaction confirmation timeout, please check later"}}else return{code:-1,data:null,message:"Your request timed out, please try again"}}async unLockSeamlessWallet({masterAddress:e,password:t,apiKey:n,chainId:a}){let i=fe.parse(rt(t)),r=ot(),o=at.decrypt(n,i,{iv:r,mode:st,padding:it}).toString(fe),u=pt(o),d=await this.onCheckRelayer(e,u.address,a);return d||(await this.authorizeSeamlessAccount({approve:!0,seamlessAddress:u.address,chainId:a}),d=!0),this.configManager.updateSeamlessWallet({masterAddress:e,wallet:u,authorized:d}),{code:0,data:{masterAddress:e,seamlessAccount:u.address,authorized:d}}}async exportSeamlessPrivateKey({password:e,apiKey:t}){let n=fe.parse(rt(e)),a=ot(),r=at.decrypt(t,n,{iv:a,mode:st,padding:it}).toString(fe);if(pt(r).address!==this.configManager.getConfig().seamlessAccount?.wallet?.address)throw new g("INVALID_PRIVATE_KEY","Invalid private key");return{code:0,data:{privateKey:r}}}async importSeamlessPrivateKey({privateKey:e,password:t,chainId:n}){if(!ga(e)||e.length!==66)throw new g("INVALID_PRIVATE_KEY","Invalid private key");let a=pt(e),r=await(await F(n)).read.originAccount([a.address]);if(r===Ws)throw new g("INVALID_PRIVATE_KEY","The private key is not a senseless account");let p=await this.onCheckRelayer(r,a.address,n),o=fe.parse(rt(t)),u=ot(),l=at.encrypt(e,o,{iv:u,mode:st,padding:it}).toString();return this.configManager.updateSeamlessWallet({masterAddress:r,wallet:a,authorized:p}),{code:0,data:{masterAddress:r,seamlessAccount:a.address,authorized:p,apiKey:l}}}async startSeamlessMode({open:e}){return await this.configManager.startSeamlessMode(e),{code:0,data:{open:e}}}async createSeamless({password:e,chainId:t}){if(!this.configManager.hasSigner())throw new g("INVALID_SIGNER","Invalid signer");let n=await N(t),[a]=await n.getAddresses();if(!a)throw new g("INVALID_SIGNER","No account");try{let i=await n.signMessage({account:a,message:`${a}_${e}`}),r=await Hs(i),{privateKey:p,wallet:o}=Js(r),u=fe.parse(rt(e)),d=ot(),y=at.encrypt(p,u,{iv:d,mode:st,padding:it}).toString(),c=await this.onCheckRelayer(a,o.address,t);return this.configManager.updateSeamlessWallet({masterAddress:a,wallet:o,authorized:c}),{code:0,data:{masterAddress:a,seamlessAccount:o.address,authorized:c,apiKey:y}}}catch(i){return{code:-1,message:i.message}}}};import{decodeEventLog as Ys}from"viem";var Te=class{constructor(e){this.client=e}getConfig(){return this.client.getConfigManager()?.getConfig()}getAddressConfig(){let t=this.getConfig()?.chainId;if(!t||!Ne(t))throw new g("INVALID_CHAIN_ID","Invalid chain id");return w(t)}getBrokerContract(){let e=this.getConfig();if(!e?.brokerAddress)throw new g("INVALID_BROKER_ADDRESS","Invalid broker address");return he(e.chainId,e.brokerAddress)}get config(){return this.getConfig()}};var dt=class extends Te{constructor(e,t){super(e),this.configManager=t}getDisputeCourtContract(e=!0){return Pn(this.config.chainId,e?1:0)}getReimbursementContract(e=!0){return wn(this.config.chainId,e?1:0)}getCaseIdFromReceiptLogs(e,t){let n=t==="DisputeFiled"?"caseId":"appealCaseId";for(let a of e.logs)try{let i=Ys({abi:ve,data:a.data,topics:a.topics});if(i.eventName===t&&i.args&&n in i.args)return i.args[n]}catch{continue}return null}async submitAppeal(e,t,n){let a=this.configManager.hasSigner()?await this.configManager.getSignerAddress(this.config.chainId):"",i=await this.client.utils.needsApproval(a,this.config.chainId,t,n,this.getAddressConfig().DISPUTE_COURT);this.client.logger.debug("need-approve",i),i&&await this.client.utils.approveAuthorization({chainId:this.config.chainId,quoteAddress:t,spenderAddress:this.getAddressConfig().DISPUTE_COURT});let r=await this.getDisputeCourtContract(),p=await this.client.utils.buildUpdatePriceParams(e,this.config.chainId),o=BigInt(p[0].value.toString()||"1"),u=await r.estimateGas.fileDispute([p,e,t],{value:o}),d=await this.client.utils.getGasLimitByRatio(u),l=await this.client.utils.getGasPriceByRatio(),y=await r.write.fileDispute([p,e,t],{value:o,gasLimit:d,gasPrice:l}),c=await h(this.config.chainId).waitForTransactionReceipt({hash:y}),f=this.getCaseIdFromReceiptLogs(c,"DisputeFiled");if(f==null)throw new g("TRANSACTION_FAILED","DisputeFiledLog not found");return{transaction:c,caseId:f}}async voteForAppeal({caseId:e,validator:t,isFor:n,deadline:a,v:i,r,s:p}){let o=await this.getDisputeCourtContract(),u=await o.estimateGas.vote([e,t,n?1:0,a,i,r,p]),d=await this.client.utils.getGasLimitByRatio(u),l=await this.client.utils.getGasPriceByRatio(),y=await o.write.vote([e,t,n?1:0,a,i,r,p],{gasLimit:d,gasPrice:l});return await h(this.config.chainId).waitForTransactionReceipt({hash:y})}async claimAppealMargin(e){let t=await this.getDisputeCourtContract(),n=await t.estimateGas.claimBond([e]),a=await this.client.utils.getGasLimitByRatio(n),i=await this.client.utils.getGasPriceByRatio(),r=await t.write.claimBond([e],{gasLimit:a,gasPrice:i});return h(this.config.chainId).waitForTransactionReceipt({hash:r})}async claimReimbursement(e,t,n,a){let i=await this.getReimbursementContract(),r=await i.estimateGas.claimReimbursement([e,t,n,a]),p=await this.client.utils.getGasLimitByRatio(r),o=await this.client.utils.getGasPriceByRatio(),u=await i.write.claimReimbursement([e,t,n,a],{gasLimit:p,gasPrice:o});return h(this.config.chainId).waitForTransactionReceipt({hash:u})}async getDisputeConfiguration(){return(await this.getDisputeCourtContract(!1)).read.getDisputeConfiguration()}async submitAppealByVoteNode(e,t,n){let a=await this.getDisputeCourtContract(),i=await this.client.utils.getGasPriceByRatio(),r=await this.client.utils.getGasLimitByRatio(await a.estimateGas.fileDisputeFromStaker([e,t,n])),p=await a.write.fileDisputeFromStaker([e,t,n],{gasLimit:r,gasPrice:i}),o=await h(this.config.chainId).waitForTransactionReceipt({hash:p}),u=this.getCaseIdFromReceiptLogs(o,"DisputeFiled");if(u==null)throw new g("TRANSACTION_FAILED","DisputeFiledLog not found");return{tx:o,caseId:u}}async appealReconsideration(e,t,n){let a=await this.getDisputeCourtContract(),i=this.configManager.hasSigner()?await this.configManager.getSignerAddress(this.config.chainId):"",r=this.getAddressConfig().DISPUTE_COURT;if(await this.client.utils.needsApproval(i,this.config.chainId,t,n,r)){let f=await this.client.utils.approveAuthorization({chainId:this.config.chainId,quoteAddress:t,spenderAddress:r});if(f.code!==0)throw new g("TRANSACTION_FAILED",f.message)}let o=await a.estimateGas.appeal([e]),u=await this.client.utils.getGasLimitByRatio(o),d=await this.client.utils.getGasPriceByRatio(),l=await a.write.appeal([e],{gasLimit:u,gasPrice:d}),y=await h(this.config.chainId).waitForTransactionReceipt({hash:l}),c=this.getCaseIdFromReceiptLogs(y,"AppealFiled");if(c==null)throw new g("TRANSACTION_FAILED","AppealFiledLog not found");return{tx:y,appealCaseId:c,caseId:e}}async getAppealList(e){return this.client.api.getAppealList(e)}async getAppealDetail(e){return this.client.api.getAppealDetail(e)}async uploadAppealEvidence(e){return this.client.api.uploadAppealEvidence(e)}async getAppealReconsiderationList(e){return this.client.api.getAppealReconsiderationList(e)}async getAppealReconsiderationDetail(e){return this.client.api.getAppealReconsiderationDetail(e)}async getAppealReimbursementList(e){return this.client.api.getAppealReimbursementList(e)}async getAppealNodeVoteList(e){return this.client.api.getAppealNodeVoteList(e)}async getAppealNodeVoteDetail(e){return this.client.api.getAppealNodeVoteDetails(e)}async getIsVoteNode(e){return this.client.api.getIsVoteNode(e)}async postVoteSignature(e){return this.client.api.postVoteSignature(e)}async getPedingVoteCount(){return this.client.api.getPedingVoteCount()}async getMyAppealCount(){return this.client.api.getMyAppealCount()}async getWarmholeSign(e){return this.client.api.getWarmholeSign(e)}async getDisputeTotalCount(){return this.client.api.getDisputeTotalCount()}async getAppealTotalCount(){return this.client.api.getAppealTotalCount()}async getReimbursementTotalCount(){return this.client.api.getReimbursementTotalCount()}async getAppealStatus(e,t,n){return this.client.api.getPoolAppealStatus({poolId:e,chainId:t,address:n,accessToken:await this.configManager.getAccessToken()??""})}};var ct=class extends Te{constructor(e){super(e)}async claimRebate(e){let t=this.getConfig(),n=await V(this.config.chainId,t.brokerAddress),a=await n.estimateGas.claimRebate([e]),i=await this.client.utils.getGasLimitByRatio(a),r=await this.client.utils.getGasPriceByRatio(),p=await n.write.claimRebate([e],{gasPrice:r,gasLimit:i});return h(this.config.chainId).waitForTransactionReceipt({hash:p})}};var Xs=(o=>(o[o.UnderReview=1]="UnderReview",o[o.InitialVote=2]="InitialVote",o[o.PublicNotice=3]="PublicNotice",o[o.UnderReconsideration=4]="UnderReconsideration",o[o.Won=5]="Won",o[o.Failed=6]="Failed",o[o.PlatformRuling=7]="PlatformRuling",o[o.PlatformRevoked=8]="PlatformRevoked",o))(Xs||{}),Zs=(d=>(d[d.InitialVoting=1]="InitialVoting",d[d.PublicNotice=2]="PublicNotice",d[d.UnderReconsideration=3]="UnderReconsideration",d[d.Won=5]="Won",d[d.Failed=4]="Failed",d[d.PlatformRuling=6]="PlatformRuling",d[d.PlatformRevoked=7]="PlatformRevoked",d[d.ReconsiderationVoting=8]="ReconsiderationVoting",d[d.AppealRevert=9]="AppealRevert",d[d.NotAppealFailed=10]="NotAppealFailed",d))(Zs||{}),ei=(a=>(a[a.UnderReview=1]="UnderReview",a[a.PublicNotice=2]="PublicNotice",a[a.UnderReconsideration=3]="UnderReconsideration",a[a.Completed=4]="Completed",a))(ei||{}),ti=(t=>(t[t.ElectionNode=0]="ElectionNode",t[t.OfficialNode=1]="OfficialNode",t))(ti||{}),ni=(t=>(t[t.Reject=0]="Reject",t[t.Support=1]="Support",t))(ni||{}),ai=(t=>(t[t.UnClaimed=0]="UnClaimed",t[t.Claimed=1]="Claimed",t))(ai||{}),si=(t=>(t[t.NotVoted=0]="NotVoted",t[t.Voted=1]="Voted",t))(si||{}),ii=(t=>(t[t.Appeal=1]="Appeal",t[t.Reconsideration=2]="Reconsideration",t))(ii||{}),ri=(n=>(n[n.NoVote=0]="NoVote",n[n.Supported=1]="Supported",n[n.Rejected=2]="Rejected",n))(ri||{}),oi=(t=>(t[t.Yes=1]="Yes",t[t.No=0]="No",t))(oi||{}),ca=(t=>(t[t.None=0]="None",t[t.isAppealing=1]="isAppealing",t))(ca||{});var Qt=class{getConfigManager(){return this.configManager}constructor(e){this.configManager=new Qe(e),this.logger=new Pe({logLevel:e.logLevel});let t=ue.getInstance();t.setConfigManager(this.configManager),_e(this.configManager),t.getMarkets().then(),this.utils=new Xe(this.configManager,this.logger),this.api=new nt(this.configManager,this.logger),this.account=new Ze(this.configManager,this.logger,this.utils,this),this.seamless=new ut(this.configManager,this.logger,this.utils,this.account,this.api),this.markets=new Ke(this.configManager,this.utils,this.api),this.position=new Je(this.configManager,this.logger,this.utils,this.seamless,this.account,this.api),this.order=new Ye(this.configManager,this.logger,this.utils,this.seamless,this.account,this.api),this.subscription=new $e(this.configManager,this.logger),this.appeal=new dt(this,this.configManager),this.referrals=new ct(this)}auth(e){this.configManager.auth(e)}updateClientChainId(e,t){this.configManager.updateClientChainId(e,t)}close(){this.configManager.clear(),this.subscription.disconnect()}async getAccessToken(){return await this.configManager.getAccessToken()}async refreshAccessToken(e=!1){return await this.configManager.refreshAccessToken(e)}};var pf="1.0.2";export{ii as AppealCaseTypeEnum,ai as AppealClaimStatusEnum,ri as AppealNodeStateEnum,si as AppealNodeVotedStateEnum,Zs as AppealReconsiderationType,ei as AppealStage,ca as AppealStatus,Xs as AppealType,W as COMMON_LP_AMOUNT_DECIMALS,S as COMMON_PRICE_DECIMALS,j as ChainId,ja as CloseTypeEnum,mm as Direction,Qa as DirectionEnum,La as ErrorCode,Ja as ExecTypeEnum,Xa as ForwarderGetStatus,gn as HttpKlineIntervalEnum,oi as IsVoteNodeEnum,qa as MarketCapType,Ie as MarketPoolState,Ua as MarketType,ue as MxSDK,Qt as MyxClient,ti as NodeTypeEnum,Va as OperationEnum,ye as OperationType,fn as OracleType,fm as OrderStatus,Ka as OrderStatusEnum,je as OrderType,za as OrderTypeEnum,pf as SDK_VERSION,Wa as SearchSecondTypeEnum,Ga as SearchTypeEnum,ym as TimeInForce,Ya as TradeFlowAccountTypeEnum,$a as TradeFlowTypeEnum,lm as TriggerType,Ha as TriggerTypeEnum,ni as VoteTypeEnum,En as approve,Et as base,ee as bigintAmountSlipperCalculator,T as bigintTradingGasPriceWithRatio,R as bigintTradingGasToRatioCalculator,Zc as formatUnits,Wt as fromViemWalletClient,vn as getAllowanceApproved,Rn as getBalanceOf,Rr as getBaseDetail,ne as getBaseUrlByEnv,vr as getMarketDetail,hn as getMarketList,ae as getOraclePrice,bn as getPoolDetail,Ar as getPoolList,In as getPoolOpenOrders,z as getPriceData,Ce as getPricesData,h as getPublicClient,Tr as getTickerData,gc as getTokenInfo,N as getWalletClient,Za as getWalletProvider,Dt as market,He as normalizeSigner,el as parseUnits,fs as pool,Mt as quote,_e as setConfigManagerForViem};
1
+ var ha=Object.defineProperty;var Jt=s=>{throw TypeError(s)};var mt=(s,e)=>{for(var t in e)ha(s,t,{get:e[t],enumerable:!0})};var jt=(s,e,t)=>e.has(s)||Jt("Cannot "+t);var Yt=(s,e,t)=>(jt(s,e,"read from private field"),t?t.call(s):e.get(s)),Xt=(s,e,t)=>e.has(s)?Jt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),Zt=(s,e,t,n)=>(jt(s,e,"write to private field"),n?n.call(s,t):e.set(s,t),t);var kt={};mt(kt,{claimBasePoolRebate:()=>Mn,claimBasePoolRebates:()=>Dn,deposit:()=>Bn,getLpPrice:()=>qn,getRewards:()=>Gn,previewUserWithdrawData:()=>Fn,withdraw:()=>Un,withdrawableLpAmount:()=>Ln});import{getContract as k}from"viem";var en=[{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"DifferentMarket",inputs:[{type:"bytes32",name:"fromPoolId"},{type:"bytes32",name:"toPoolId"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InsufficientQuoteIn",inputs:[{type:"uint256",name:"orderId"},{type:"uint256",name:"quoteIn"},{type:"uint256",name:"exchangeDelta"}]},{type:"error",name:"InvalidAmount",inputs:[{type:"uint256",name:"amount"}]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidLiquidityAmount",inputs:[]},{type:"error",name:"InvalidTpsl",inputs:[{type:"uint256",name:"orderId"}]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"NotReachedPrice",inputs:[{type:"uint256",name:"orderId"},{type:"uint256",name:"price"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"}]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"SamePoolMigration",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"SlippageExceeded",inputs:[{type:"uint256",name:"expected"},{type:"uint256",name:"actual"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"__ERC2771ContextUpgradeable_init",constant:!1,payable:!1,inputs:[{type:"address",name:"trustedForwarder_"}],outputs:[]},{type:"function",name:"addTpsl",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"poolType"},{type:"tuple[]",name:"tpslParams",components:[{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}]}],outputs:[]},{type:"function",name:"cancelTpsl",constant:!1,payable:!1,inputs:[{type:"uint256",name:"orderId"}],outputs:[]},{type:"function",name:"claimBasePoolRebate",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"bytes32",name:"poolId"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimBasePoolRebate",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimBasePoolRebates",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"bytes32[]",name:"poolIds"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimBasePoolRebates",constant:!1,payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimQuotePoolRebate",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimQuotePoolRebate",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"bytes32",name:"poolId"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimQuotePoolRebates",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"bytes32[]",name:"poolIds"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"claimQuotePoolRebates",constant:!1,payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"address",name:"recipient"}],outputs:[]},{type:"function",name:"currentOrderId",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"depositBase",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"},{type:"tuple[]",name:"tpslParams",components:[{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}]}],outputs:[]},{type:"function",name:"depositBase",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"},{type:"tuple[]",name:"tpslParams",components:[{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}]}],outputs:[]},{type:"function",name:"depositQuote",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"},{type:"tuple[]",name:"tpslParams",components:[{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}]}],outputs:[]},{type:"function",name:"depositQuote",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"},{type:"tuple[]",name:"tpslParams",components:[{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}]}],outputs:[]},{type:"function",name:"executeTpsl",constant:!1,payable:!1,inputs:[{type:"uint256",name:"orderId"},{type:"uint256",name:"quoteInIfNecessary"},{type:"uint256",name:"minOut"}],outputs:[{type:"uint256",name:"baseOut"},{type:"uint256",name:"quoteOut"}]},{type:"function",name:"executeTpsl",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"uint256",name:"orderId"},{type:"uint256",name:"quoteInIfNecessary"},{type:"uint256",name:"minOut"}],outputs:[{type:"uint256",name:"baseOut"},{type:"uint256",name:"quoteOut"}]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getTpslData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint256",name:"orderId"}],outputs:[{type:"tuple",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"poolType"},{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}]},{type:"function",name:"getUserTpslOrderIds",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"user"}],outputs:[{type:"uint256[]"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"isTrustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"forwarder"}],outputs:[{type:"bool"}]},{type:"function",name:"migrateLiquidity",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"fromPoolId"},{type:"bytes32",name:"toPoolId"},{type:"uint256",name:"amount"},{type:"uint256",name:"minLpOut"}]}],outputs:[]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"trustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"withdrawBase",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"}]}],outputs:[]},{type:"function",name:"withdrawBase",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"}]}],outputs:[]},{type:"function",name:"withdrawQuote",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"}]}],outputs:[]},{type:"function",name:"withdrawQuote",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"recipient"}]}],outputs:[]}];import{createPublicClient as Ca,fallback as wa,http as pn}from"viem";var K=(r=>(r[r.LINEA_SEPOLIA=59141]="LINEA_SEPOLIA",r[r.LINEA_MAINNET=59144]="LINEA_MAINNET",r[r.ARB_TESTNET=421614]="ARB_TESTNET",r[r.ARB_MAINNET=42161]="ARB_MAINNET",r[r.BSC_TESTNET=97]="BSC_TESTNET",r[r.BSC_MAINNET=56]="BSC_MAINNET",r))(K||{});var Aa=[421614,59141,97,42161,59144,56];function _e(s){return!!s&&Aa.includes(s)}var J=10;var $={42161:130n,421614:130n,59144:130n,59141:130n,56:150n,97:150n};var tn={chainId:59141,chainInfo:{explorer:"https://sepolia.lineascan.build/",explorerOfTX:"https://sepolia.lineascan.build/tx/",publicJsonRPCUrl:["https://rpc.sepolia.linea.build","https://linea-sepolia.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161"],label:"Linea Sepolia",logoUrl:"",faucetUrl:"",chainSymbol:"Linea",gasPriceRatio:1.3,gasLimitRatio:1.2,gasAmountRatio:2,gasFeeReservedForCollateral:(.525+1)*J,nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18}}};var nn={chainId:421614,chainInfo:{privateJsonRPCUrl:"",publicJsonRPCUrl:["https://sepolia-rollup.arbitrum.io/rpc"],label:" Arbitrum Sepolia",chainSymbol:"Arb Sepolia",explorer:"https://sepolia.arbiscan.io/",explorerOfTX:"https://sepolia.arbiscan.io/tx/",faucetUrl:"https://bwarelabs.com/faucets/arbitrum-sepolia",logoUrl:"",gasPriceRatio:1.5,gasLimitRatio:1.3,gasAmountRatio:2,gasFeeReservedForCollateral:(.055+1)*J,nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18}}};var an={chainId:97,chainInfo:{privateJsonRPCUrl:"",publicJsonRPCUrl:["https://bsc-testnet-dataseed.bnbchain.org"],label:"BNB Chain Testnet",chainSymbol:"BNB Chain Testnet",explorer:"https://testnet.bscscan.com/",explorerOfTX:"https://testnet.bscscan.com/tx/",faucetUrl:"https://docs.bnbchain.org/bnb-smart-chain/developers/faucet/",logoUrl:"",gasPriceRatio:1.5,gasLimitRatio:1.3,gasAmountRatio:2,gasFeeReservedForCollateral:(5e-4+1)*J,nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18}}};var sn={chainId:59144,chainInfo:{label:"Linea Mainnet",explorer:"https://lineascan.build/",logoUrl:"",explorerOfTX:"https://lineascan.build/tx/",publicJsonRPCUrl:["https://rpc.linea.build/","https://linea.blockpi.network/v1/rpc/public","https://1rpc.io/linea","https://rpc.linea.build"],chainSymbol:"Linea",gasPriceRatio:1.3,gasLimitRatio:1.2,gasAmountRatio:2,gasFeeReservedForCollateral:(.525+.35)*J,nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18}}};var rn={chainId:42161,chainInfo:{privateJsonRPCUrl:"",publicJsonRPCUrl:["https://arb1.arbitrum.io/rpc"],label:" Arbitrum One",chainSymbol:"Arbitrum One",explorer:"https://arbiscan.io/",explorerOfTX:"https://arbiscan.io/tx/",logoUrl:"",gasPriceRatio:1.5,gasLimitRatio:1.3,gasAmountRatio:2,gasFeeReservedForCollateral:(.055+.175)*J,nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18}}};var on={chainId:56,chainInfo:{privateJsonRPCUrl:"",publicJsonRPCUrl:["https://bsc-dataseed.bnbchain.org"],label:"BNB Chain",chainSymbol:"BNB Chain",explorer:"https://bscscan.com/",explorerOfTX:"https://bscscan.com/tx/",faucetUrl:"https://docs.bnbchain.org/bnb-smart-chain/developers/faucet/",logoUrl:"",gasPriceRatio:1.5,gasLimitRatio:1.3,gasAmountRatio:2,gasFeeReservedForCollateral:(5e-4+1)*J,nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18}}};var C={59141:tn.chainInfo,421614:nn.chainInfo,97:an.chainInfo,59144:sn.chainInfo,42161:rn.chainInfo,56:on.chainInfo};function Ie(s){let e=C[s];if(!e)throw new Error(`Could not find information with chain id ${s}`);return e}var yt={};function Pa(s){if(!yt[s]){let e=Ie(s),t=[...e.privateJsonRPCUrl?[e.privateJsonRPCUrl]:[],...Array.isArray(e.publicJsonRPCUrl)?[...e.publicJsonRPCUrl]:[]].filter(Boolean);if(t.length===0)throw new Error(`${s} has no jsonRPCUrl configured`);yt[s]={id:s,name:e.label||`Chain ${s}`,nativeCurrency:e.nativeCurrency,rpcUrls:{default:{http:t}}}}return yt[s]}var ft={};function g(s){if(!ft[s]){let e=Ie(s),t=[...e.privateJsonRPCUrl?[e.privateJsonRPCUrl]:[],...Array.isArray(e.publicJsonRPCUrl)?[...e.publicJsonRPCUrl]:[]].filter(Boolean);if(t.length===0)throw new Error(`${s} has no jsonRPCUrl configured`);let n=t.length===1?pn(t[0]):wa(t.map(a=>pn(a)));ft[s]=Ca({chain:Pa(s),transport:n})}return ft[s]}var un=null;function Be(s){un=s}async function N(s){let e=un;if(!e?.hasSigner())throw new Error("No signer: call auth({ signer }) or auth({ walletClient })");return e.getViemWalletClient(s)}var gt=[{type:"constructor",payable:!1,inputs:[]},{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"BaseFeeNotSoldOut",inputs:[]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidBaseToken",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"LPNotFullyMinted",inputs:[]},{type:"error",name:"MarketNotExist",inputs:[{type:"bytes32",name:"marketId"}]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"PoolExists",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"PoolNotExist",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"PositionNotEmpty",inputs:[]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"error",name:"UnexpectedPoolState",inputs:[]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"benchPool",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"string",name:"remark"}]}],outputs:[]},{type:"function",name:"checkPoolExists",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"bool"}]},{type:"function",name:"deployPool",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"marketId"},{type:"address",name:"baseToken"}]}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getMarketPool",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"address",name:"asset"}],outputs:[{type:"tuple",components:[{type:"bytes32",name:"marketId"},{type:"bytes32",name:"poolId"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"state"},{type:"address",name:"basePoolToken"},{type:"address",name:"quotePoolToken"},{type:"uint16",name:"maxPriceDeviation"},{type:"bool",name:"compoundEnabled"},{type:"uint64",name:"windowCapUsd"},{type:"address",name:"poolVault"},{type:"address",name:"tradingVault"}]}]},{type:"function",name:"getPairToken",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"}]},{type:"function",name:"getPool",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"tuple",components:[{type:"bytes32",name:"marketId"},{type:"bytes32",name:"poolId"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"state"},{type:"address",name:"basePoolToken"},{type:"address",name:"quotePoolToken"},{type:"uint16",name:"maxPriceDeviation"},{type:"bool",name:"compoundEnabled"},{type:"uint64",name:"windowCapUsd"},{type:"address",name:"poolVault"},{type:"address",name:"tradingVault"}]}]},{type:"function",name:"getPoolMarket",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"bytes32",name:"marketId"},{type:"tuple",components:[{type:"address",name:"quoteToken"},{type:"uint32",name:"baseReserveRatio"},{type:"uint32",name:"quoteReserveRatio"},{type:"uint64",name:"oracleFeeUsd"},{type:"uint64",name:"oracleRefundFeeUsd"},{type:"uint128",name:"poolPrimeThreshold"},{type:"uint128",name:"executionFee"},{type:"uint128",name:"maxExecutionFee"},{type:"uint128",name:"forwardFee"},{type:"uint128",name:"maxForwardFee"}]}]},{type:"function",name:"getPoolMarketExecutionFee",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256",name:"executionFee"}]},{type:"function",name:"getPoolMarketForwardFee",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256",name:"forwardFee"}]},{type:"function",name:"getPoolMarketId",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"bytes32",name:"marketId"}]},{type:"function",name:"getPoolRiskTier",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint8"}]},{type:"function",name:"getPoolVault",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"address"}]},{type:"function",name:"getPools",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32[]",name:"pools"}]},{type:"function",name:"getTradingVault",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"address"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"isPoolAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"addr"}],outputs:[{type:"bool"}]},{type:"function",name:"perBenchPool",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"string",name:"remark"}]}],outputs:[]},{type:"function",name:"primePool",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"referencePrice"}]}],outputs:[]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"reprimePool",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"}]}],outputs:[]},{type:"function",name:"trenchPool",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"bytes32",name:"oracleFeedId"},{type:"uint32",name:"oracleDecimals"},{type:"uint8",name:"oracleType"},{type:"uint16",name:"maxPriceDeviation"},{type:"uint8",name:"riskTier"},{type:"uint64",name:"windowCapUsd"}]}],outputs:[]},{type:"function",name:"updatePoolCompoundEnabled",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"bool",name:"enabled"}]}],outputs:[]},{type:"function",name:"updatePoolPriceDeviations",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint16",name:"maxPriceDeviation"}]}],outputs:[]},{type:"function",name:"updatePoolRiskTiers",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"riskTier"}]}],outputs:[]},{type:"function",name:"updatePoolWindowCaps",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint64",name:"windowCapUsd"}]}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]}];var H=[{inputs:[{internalType:"string",name:"name_",type:"string"},{internalType:"string",name:"symbol_",type:"string"},{internalType:"uint8",name:"decimals_",type:"uint8"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InvalidShortString",type:"error"},{inputs:[{internalType:"string",name:"str",type:"string"}],name:"StringTooLong",type:"error"},{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:[],name:"EIP712DomainChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!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:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"burn",outputs:[],stateMutability:"nonpayable",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:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",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:[{internalType:"address",name:"account",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"mint",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:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],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:[],name:"renounceOwnership",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:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"}];var bt=[{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InsufficientOutputAmount",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"PoolNotActive",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"PoolNotExist",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SafeCastOverflowedUintToInt",inputs:[{type:"uint256",name:"value"}]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"QuotePoolProfitDistributed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"amount",indexed:!1},{type:"uint256",name:"genesisAmount",indexed:!1},{type:"uint256",name:"price",indexed:!1},{type:"uint256",name:"exchangeRate",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"EXCHANGE_RATE_PRECISION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"POOL_TOKEN_DECIMALS",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint8"}]},{type:"function",name:"REBATE_INDEX_PRECISION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"claimUserRebate",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256",name:"rebateOut"}]},{type:"function",name:"claimUserRebates",constant:!1,payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256[]",name:"rebateOut"}]},{type:"function",name:"deposit",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256",name:"amountOut"}]},{type:"function",name:"distribute",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amount"},{type:"uint256",name:"genesisAmount"},{type:"uint256",name:"price"}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getExchangeRate",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256"}]},{type:"function",name:"getExchangeRate",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getPoolData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"tuple",components:[{type:"uint256",name:"genesisRebateIndex"}]}]},{type:"function",name:"getPoolTokenPrice",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"getUserData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"}],outputs:[{type:"tuple",components:[{type:"uint256",name:"index"},{type:"uint256",name:"accrued"}]}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"pendingUserRebates",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewLpAmountOut",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"quoteAmountIn"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewPoolTokenPrice",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewQuoteAmountOut",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"lpAmountIn"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewUserWithdrawData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"lpAmountIn"},{type:"address",name:"user"},{type:"uint256",name:"price"}],outputs:[{type:"uint256",name:"quoteAmountOut"}]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"updatePool",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"oraclePrice"}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"withdraw",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256",name:"amountOut"},{type:"uint256",name:"rebateOut"}]},{type:"function",name:"withdrawableLpAmount",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]}];var It=[{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"ExceedMaxProfit",inputs:[]},{type:"error",name:"ExceedMinOutputAmount",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InsufficientOutputAmount",inputs:[]},{type:"error",name:"InsufficientReturnAmount",inputs:[{type:"uint256",name:"expected"},{type:"uint256",name:"received"}]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"PoolNotActive",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"PoolNotCompoundable",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"PoolNotExist",inputs:[{type:"bytes32",name:"poolId"}]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SafeCastOverflowedUintToInt",inputs:[{type:"uint256",name:"value"}]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"BasePoolProfitDistributed",inputs:[{type:"bytes32",name:"poolId",indexed:!0},{type:"uint256",name:"baseAmount",indexed:!1},{type:"uint256",name:"quoteAmount",indexed:!1},{type:"uint256",name:"price",indexed:!1},{type:"uint256",name:"exchangeRate",indexed:!1},{type:"uint256",name:"rebateIndex",indexed:!1},{type:"uint256",name:"genesisRebateIndex",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolProfitExchanged",inputs:[{type:"bytes32",name:"poolId",indexed:!0},{type:"uint256",name:"baseIn",indexed:!1},{type:"uint256",name:"quoteOut",indexed:!1},{type:"uint256",name:"price",indexed:!1},{type:"address",name:"recipient",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolRebateIndexUpdated",inputs:[{type:"bytes32",name:"poolId",indexed:!0},{type:"uint256",name:"unexchangedProfits",indexed:!1},{type:"uint256",name:"oldIndex",indexed:!1},{type:"uint256",name:"newIndex",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"EXCHANGE_RATE_PRECISION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"POOL_TOKEN_DECIMALS",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint8"}]},{type:"function",name:"REBATE_INDEX_PRECISION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"claimUserRebate",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256",name:"rebateOut"}]},{type:"function",name:"claimUserRebates",constant:!1,payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256[]",name:"rebateOut"}]},{type:"function",name:"deposit",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256",name:"amountOut"}]},{type:"function",name:"distribute",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"},{type:"uint256",name:"genesisAmount"},{type:"uint256",name:"price"}],outputs:[]},{type:"function",name:"exchangeProfit",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"baseIn"},{type:"uint256",name:"minQuoteOut"},{type:"address",name:"recipient"},{type:"bytes",name:"data"}],outputs:[{type:"uint256",name:"quoteOut"}]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getExchangeRate",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256"}]},{type:"function",name:"getExchangeRate",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"getExchangeableProfit",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256",name:"baseIn"},{type:"uint256",name:"quoteOut"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getPoolData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"tuple",components:[{type:"uint256",name:"rebateIndex"},{type:"uint256",name:"genesisRebateIndex"},{type:"uint256",name:"exchangeableProfits"}]}]},{type:"function",name:"getPoolTokenPrice",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"getUserData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"}],outputs:[{type:"tuple",components:[{type:"uint256",name:"index"},{type:"uint256",name:"genesisIndex"},{type:"uint256",name:"accrued"},{type:"uint256",name:"genesisAccrued"}]}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"pendingUserRebates",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"uint256",name:"price"}],outputs:[{type:"uint256",name:"rebates"},{type:"uint256",name:"genesisRebates"}]},{type:"function",name:"previewBaseAmountOut",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"lpAmountIn"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewExchangeableProfit",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256",name:"baseIn"},{type:"uint256",name:"quoteOut"}]},{type:"function",name:"previewLpAmountOut",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"baseAmountIn"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewPoolTokenPrice",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256"}]},{type:"function",name:"previewUserWithdrawData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"lpAmountIn"},{type:"address",name:"user"},{type:"uint256",name:"price"}],outputs:[{type:"uint256",name:"baseAmountOut"},{type:"uint256",name:"rebateAmount"}]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"updatePool",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"oraclePrice"}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"withdraw",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"amountIn"},{type:"uint256",name:"minAmountOut"},{type:"address",name:"user"},{type:"address",name:"recipient"}],outputs:[{type:"uint256",name:"amountOut"},{type:"uint256",name:"rebateOut"}]},{type:"function",name:"withdrawableLpAmount",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"price"}],outputs:[{type:"uint256"}]}];var O=[{type:"constructor",payable:!1,inputs:[]},{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ECDSAInvalidSignature",inputs:[]},{type:"error",name:"ECDSAInvalidSignatureLength",inputs:[{type:"uint256",name:"length"}]},{type:"error",name:"ECDSAInvalidSignatureS",inputs:[{type:"bytes32",name:"s"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"ExpiredFeeData",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidFeeRate",inputs:[]},{type:"error",name:"InvalidFeeTier",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidParameter",inputs:[]},{type:"error",name:"NoRebateToClaim",inputs:[]},{type:"error",name:"NotActiveBroker",inputs:[{type:"address",name:"broker"}]},{type:"error",name:"NotBrokerSigner",inputs:[{type:"address",name:"signer"}]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotOrderOwner",inputs:[]},{type:"error",name:"NotPositionOwner",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"OwnableInvalidOwner",inputs:[{type:"address",name:"owner"}]},{type:"error",name:"OwnableUnauthorizedAccount",inputs:[{type:"address",name:"account"}]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"error",name:"UnsupportedAssetClass",inputs:[{type:"uint8",name:"assetClass"}]},{type:"error",name:"UnsupportedFeeTier",inputs:[{type:"uint8",name:"tier"}]},{type:"event",anonymous:!1,name:"BrokerStatusUpdated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"bool",name:"isActive",indexed:!1}]},{type:"event",anonymous:!1,name:"EIP712DomainChanged",inputs:[]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"OwnershipTransferStarted",inputs:[{type:"address",name:"previousOwner",indexed:!0},{type:"address",name:"newOwner",indexed:!0}]},{type:"event",anonymous:!1,name:"OwnershipTransferred",inputs:[{type:"address",name:"previousOwner",indexed:!0},{type:"address",name:"newOwner",indexed:!0}]},{type:"event",anonymous:!1,name:"RebateClaimed",inputs:[{type:"address",name:"user",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"SignerUpdated",inputs:[{type:"address",name:"signer",indexed:!1},{type:"bool",name:"isSigner",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"event",anonymous:!1,name:"UserFeeDataReset",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"signer",indexed:!1},{type:"uint256",name:"epoch",indexed:!1}]},{type:"event",anonymous:!1,name:"UserFeeDataUpdated",inputs:[{type:"address",name:"broker",indexed:!0},{type:"address",name:"signer",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"uint256",name:"epoch",indexed:!1},{type:"uint8",name:"tier",indexed:!1},{type:"address",name:"referrer",indexed:!1},{type:"uint32",name:"totalReferralRebatePct",indexed:!1},{type:"uint32",name:"referrerRebatePct",indexed:!1}]},{type:"function",name:"FEE_TYPEHASH",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"__ERC2771ContextUpgradeable_init",constant:!1,payable:!1,inputs:[{type:"address",name:"trustedForwarder_"}],outputs:[]},{type:"function",name:"acceptOwnership",constant:!1,payable:!1,inputs:[],outputs:[]},{type:"function",name:"activeFeeTiers",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"}],outputs:[{type:"uint256[]"}]},{type:"function",name:"activeSpecialFeeTierList",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"}],outputs:[{type:"uint256[]"}]},{type:"function",name:"addressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"batchSetSpecialFeeTiers",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"feeTier"},{type:"int32",name:"makerFeeRate"},{type:"uint32",name:"takerFeeRate"}]}],outputs:[]},{type:"function",name:"batchUpdateFeeTiers",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"feeTier"},{type:"tuple",name:"addOnFeeRate",components:[{type:"uint32",name:"takerFeeRate"},{type:"uint32",name:"makerFeeRate"}]}]}],outputs:[]},{type:"function",name:"cancelOrder",constant:!1,payable:!1,inputs:[{type:"uint256",name:"orderId"}],outputs:[]},{type:"function",name:"cancelOrders",constant:!1,payable:!1,inputs:[{type:"uint256[]",name:"orderIds"}],outputs:[]},{type:"function",name:"claimRebate",constant:!1,payable:!1,inputs:[{type:"address",name:"token"}],outputs:[]},{type:"function",name:"claimRebates",constant:!1,payable:!1,inputs:[{type:"address[]",name:"tokens"}],outputs:[]},{type:"function",name:"currentFeeDataEpoch",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"domainSeparatorV4",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"eip712Domain",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes1",name:"fields"},{type:"string",name:"name"},{type:"string",name:"version"},{type:"uint256",name:"chainId"},{type:"address",name:"verifyingContract"},{type:"bytes32",name:"salt"},{type:"uint256[]",name:"extensions"}]},{type:"function",name:"getAddOnFeeTier",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"feeTier"}],outputs:[{type:"uint32",name:"takerFeeRate"},{type:"uint32",name:"makerFeeRate"}]},{type:"function",name:"getBaseFeeRate",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint8",name:"assetClass"}],outputs:[{type:"tuple",name:"baseFeeRate",components:[{type:"uint32",name:"takerFeeRate"},{type:"uint32",name:"makerFeeRate"}]}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getSpecialFeeTier",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"feeTier"}],outputs:[{type:"int32",name:"makerFeeRate"},{type:"uint32",name:"takerFeeRate"}]},{type:"function",name:"getUserFeeDataDigest",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"user"},{type:"uint64",name:"nonce"},{type:"uint64",name:"deadline"},{type:"tuple",name:"feeData",components:[{type:"uint8",name:"tier"},{type:"address",name:"referrer"},{type:"uint32",name:"totalReferralRebatePct"},{type:"uint32",name:"referrerRebatePct"}]}],outputs:[{type:"bytes32",name:"digest"}]},{type:"function",name:"getUserFeeRate",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"user"},{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"}],outputs:[{type:"uint32",name:"takerFeeRate"},{type:"int32",name:"makerFeeRate"},{type:"uint32",name:"baseTakerFeeRate"},{type:"uint32",name:"baseMakerFeeRate"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"_addressManager"},{type:"address",name:"owner"},{type:"string",name:"_brokerName"},{type:"address[]",name:"brokerSigners"},{type:"uint8[]",name:"assetClasses"},{type:"tuple[]",name:"baseFeeRates",components:[{type:"uint32",name:"takerFeeRate"},{type:"uint32",name:"makerFeeRate"}]}],outputs:[]},{type:"function",name:"isActive",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bool"}]},{type:"function",name:"isTrustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"forwarder"}],outputs:[{type:"bool"}]},{type:"function",name:"name",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"onBrokerFee",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"address",name:"token"},{type:"uint256",name:"feeAmount"}],outputs:[{type:"uint256",name:"totalReferralRebate"},{type:"uint256",name:"referrerRebate"},{type:"address",name:"referrer"}]},{type:"function",name:"owner",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"pendingOwner",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"placeOrderWithPosition",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"bytes32",name:"positionId"},{type:"tuple",name:"depositParams",components:[{type:"address",name:"token"},{type:"uint256",name:"amount"}]},{type:"tuple",name:"orderParams",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"orderType"},{type:"uint8",name:"triggerType"},{type:"uint8",name:"operation"},{type:"uint8",name:"direction"},{type:"uint256",name:"collateralAmount"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"uint8",name:"timeInForce"},{type:"bool",name:"postOnly"},{type:"uint16",name:"slippagePct"},{type:"uint16",name:"leverage"},{type:"uint256",name:"tpSize"},{type:"uint256",name:"tpPrice"},{type:"uint256",name:"slSize"},{type:"uint256",name:"slPrice"}]}],outputs:[]},{type:"function",name:"placeOrderWithSalt",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"uint64",name:"userPositionSalt"},{type:"tuple",name:"depositParams",components:[{type:"address",name:"token"},{type:"uint256",name:"amount"}]},{type:"tuple",name:"orderParams",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"orderType"},{type:"uint8",name:"triggerType"},{type:"uint8",name:"operation"},{type:"uint8",name:"direction"},{type:"uint256",name:"collateralAmount"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"uint8",name:"timeInForce"},{type:"bool",name:"postOnly"},{type:"uint16",name:"slippagePct"},{type:"uint16",name:"leverage"},{type:"uint256",name:"tpSize"},{type:"uint256",name:"tpPrice"},{type:"uint256",name:"slSize"},{type:"uint256",name:"slPrice"}]}],outputs:[]},{type:"function",name:"placeOrdersWithPosition",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple",name:"depositParams",components:[{type:"address",name:"token"},{type:"uint256",name:"amount"}]},{type:"bytes32[]",name:"positionIds"},{type:"tuple[]",name:"orderParams",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"orderType"},{type:"uint8",name:"triggerType"},{type:"uint8",name:"operation"},{type:"uint8",name:"direction"},{type:"uint256",name:"collateralAmount"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"uint8",name:"timeInForce"},{type:"bool",name:"postOnly"},{type:"uint16",name:"slippagePct"},{type:"uint16",name:"leverage"},{type:"uint256",name:"tpSize"},{type:"uint256",name:"tpPrice"},{type:"uint256",name:"slSize"},{type:"uint256",name:"slPrice"}]}],outputs:[]},{type:"function",name:"placeOrdersWithSalt",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple",name:"depositParams",components:[{type:"address",name:"token"},{type:"uint256",name:"amount"}]},{type:"uint64[]",name:"userPositionSalts"},{type:"tuple[]",name:"orderParams",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"orderType"},{type:"uint8",name:"triggerType"},{type:"uint8",name:"operation"},{type:"uint8",name:"direction"},{type:"uint256",name:"collateralAmount"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"uint8",name:"timeInForce"},{type:"bool",name:"postOnly"},{type:"uint16",name:"slippagePct"},{type:"uint16",name:"leverage"},{type:"uint256",name:"tpSize"},{type:"uint256",name:"tpPrice"},{type:"uint256",name:"slSize"},{type:"uint256",name:"slPrice"}]}],outputs:[]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"renounceOwnership",constant:!1,payable:!1,inputs:[],outputs:[]},{type:"function",name:"resetAllUserFeeData",constant:!1,payable:!1,inputs:[],outputs:[]},{type:"function",name:"setSigner",constant:!1,payable:!1,inputs:[{type:"address",name:"signer"},{type:"bool",name:"isSigner"}],outputs:[]},{type:"function",name:"setSpecialFeeTier",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"feeTier"},{type:"int32",name:"makerFeeRate"},{type:"uint32",name:"takerFeeRate"}]}],outputs:[]},{type:"function",name:"setUserFeeData",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"user"},{type:"uint64",name:"nonce"},{type:"uint64",name:"deadline"},{type:"tuple",name:"feeData",components:[{type:"uint8",name:"tier"},{type:"address",name:"referrer"},{type:"uint32",name:"totalReferralRebatePct"},{type:"uint32",name:"referrerRebatePct"}]},{type:"bytes",name:"signature"}]}],outputs:[]},{type:"function",name:"setUserSpecialFeeTier",constant:!1,payable:!1,inputs:[{type:"address",name:"user"},{type:"uint8",name:"feeTier"}],outputs:[]},{type:"function",name:"supportedAssetClasses",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256[]"}]},{type:"function",name:"transferOwnership",constant:!1,payable:!1,inputs:[{type:"address",name:"newOwner"}],outputs:[]},{type:"function",name:"trustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"updateBaseFeeRates",constant:!1,payable:!1,inputs:[{type:"tuple[]",name:"params",components:[{type:"uint8",name:"assetClass"},{type:"bool",name:"isEnable"},{type:"tuple",name:"baseFeeRate",components:[{type:"uint32",name:"takerFeeRate"},{type:"uint32",name:"makerFeeRate"}]}]}],outputs:[]},{type:"function",name:"updateBrokerStatus",constant:!1,payable:!1,inputs:[{type:"bool",name:"active"}],outputs:[]},{type:"function",name:"updateFeeTier",constant:!1,payable:!1,inputs:[{type:"uint8",name:"assetClass"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"feeTier"},{type:"tuple",name:"feeRate",components:[{type:"uint32",name:"takerFeeRate"},{type:"uint32",name:"makerFeeRate"}]}],outputs:[]},{type:"function",name:"updateOrder",constant:!1,payable:!1,inputs:[{type:"tuple",name:"depositParams",components:[{type:"address",name:"token"},{type:"uint256",name:"amount"}]},{type:"tuple",name:"params",components:[{type:"uint256",name:"orderId"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"tuple",name:"tpsl",components:[{type:"uint256",name:"tpSize"},{type:"uint256",name:"tpPrice"},{type:"uint256",name:"slSize"},{type:"uint256",name:"slPrice"}]}]}],outputs:[]},{type:"function",name:"updatePriceAndAdjustCollateral",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"tuple",name:"depositParams",components:[{type:"address",name:"token"},{type:"uint256",name:"amount"}]},{type:"bytes32",name:"positionId"},{type:"int256",name:"adjustAmount"}],outputs:[]},{type:"function",name:"updateUserFeeData",constant:!1,payable:!1,inputs:[{type:"address",name:"user"},{type:"tuple",name:"feeData",components:[{type:"uint8",name:"tier"},{type:"address",name:"referrer"},{type:"uint32",name:"totalReferralRebatePct"},{type:"uint32",name:"referrerRebatePct"}]}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"userFeeData",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint256",name:"userFeeDataEpoch"},{type:"address",name:"user"}],outputs:[{type:"uint8",name:"tier"},{type:"address",name:"referrer"},{type:"uint32",name:"totalReferralRebatePct"},{type:"uint32",name:"referrerRebatePct"}]},{type:"function",name:"userNonces",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"user"}],outputs:[{type:"uint64",name:"nonce"}]},{type:"function",name:"userRebates",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"user"},{type:"address",name:"token"}],outputs:[{type:"uint256",name:"rebateAmount"}]}];var ht=[{type:"constructor",payable:!1,inputs:[]},{type:"error",name:"ERC20InsufficientAllowance",inputs:[{type:"address",name:"spender"},{type:"uint256",name:"allowance"},{type:"uint256",name:"needed"}]},{type:"error",name:"ERC20InsufficientBalance",inputs:[{type:"address",name:"sender"},{type:"uint256",name:"balance"},{type:"uint256",name:"needed"}]},{type:"error",name:"ERC20InvalidApprover",inputs:[{type:"address",name:"approver"}]},{type:"error",name:"ERC20InvalidReceiver",inputs:[{type:"address",name:"receiver"}]},{type:"error",name:"ERC20InvalidSender",inputs:[{type:"address",name:"sender"}]},{type:"error",name:"ERC20InvalidSpender",inputs:[{type:"address",name:"spender"}]},{type:"error",name:"InsufficientBalance",inputs:[{type:"address",name:"account"},{type:"uint256",name:"balance"},{type:"uint256",name:"needed"}]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"event",anonymous:!1,name:"Approval",inputs:[{type:"address",name:"owner",indexed:!0},{type:"address",name:"spender",indexed:!0},{type:"uint256",name:"value",indexed:!1}]},{type:"event",anonymous:!1,name:"GenesisShareBurned",inputs:[{type:"address",name:"account",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"GenesisShareMinted",inputs:[{type:"address",name:"account",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"Transfer",inputs:[{type:"address",name:"from",indexed:!0},{type:"address",name:"to",indexed:!0},{type:"uint256",name:"value",indexed:!1}]},{type:"function",name:"addressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"allowance",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"owner"},{type:"address",name:"spender"}],outputs:[{type:"uint256"}]},{type:"function",name:"approve",constant:!1,payable:!1,inputs:[{type:"address",name:"spender"},{type:"uint256",name:"value"}],outputs:[{type:"bool"}]},{type:"function",name:"balanceOf",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"}],outputs:[{type:"uint256"}]},{type:"function",name:"burnFrom",constant:!1,payable:!1,inputs:[{type:"address",name:"from"},{type:"uint256",name:"amount"}],outputs:[]},{type:"function",name:"decimals",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint8"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"_addressManager"},{type:"bytes32",name:"_poolId"},{type:"address",name:"_underlyingToken"},{type:"string",name:"name"},{type:"string",name:"symbol"}],outputs:[]},{type:"function",name:"mint",constant:!1,payable:!1,inputs:[{type:"address",name:"to"},{type:"uint256",name:"amount"}],outputs:[]},{type:"function",name:"name",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"poolId",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"symbol",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"totalGenesisShare",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"totalSupply",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"transfer",constant:!1,payable:!1,inputs:[{type:"address",name:"to"},{type:"uint256",name:"value"}],outputs:[{type:"bool"}]},{type:"function",name:"transferFrom",constant:!1,payable:!1,inputs:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"uint256",name:"value"}],outputs:[{type:"bool"}]},{type:"function",name:"underlyingToken",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"userGenesisShare",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"}],outputs:[{type:"uint256"}]}];var xt=[{type:"constructor",payable:!1,inputs:[]},{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidParameter",inputs:[]},{type:"error",name:"InvalidQuoteTokenAddress",inputs:[]},{type:"error",name:"InvalidRatioParams",inputs:[]},{type:"error",name:"MarketAlreadyExisted",inputs:[]},{type:"error",name:"MarketNotExisted",inputs:[]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"ExecutionFeeUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint256",name:"oldExecutionFee",indexed:!1},{type:"uint256",name:"newExecutionFee",indexed:!1}]},{type:"event",anonymous:!1,name:"ForwardFeeUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint256",name:"oldForwardFee",indexed:!1},{type:"uint256",name:"newForwardFee",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"MaxExecutionFeeUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint256",name:"oldMaxExecutionFee",indexed:!1},{type:"uint256",name:"newMaxExecutionFee",indexed:!1}]},{type:"event",anonymous:!1,name:"MaxForwardFeeUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint256",name:"oldMaxForwardFee",indexed:!1},{type:"uint256",name:"newMaxForwardFee",indexed:!1}]},{type:"event",anonymous:!1,name:"OracleFeeUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint64",name:"newOracleFeeUsd",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolPrimeThresholdUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint128",name:"newPoolPrimeThreshold",indexed:!1}]},{type:"event",anonymous:!1,name:"ReserveRatioUpdated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"uint32",name:"newBaseReserveRatio",indexed:!1},{type:"uint32",name:"newQuoteReserveRatio",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"createMarket",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"uint64",name:"chainId"},{type:"address",name:"quoteToken"},{type:"uint32",name:"baseReserveRatio"},{type:"uint32",name:"quoteReserveRatio"},{type:"uint64",name:"oracleFeeUsd"},{type:"uint128",name:"poolPrimeThreshold"},{type:"uint128",name:"executionFee"},{type:"uint128",name:"maxExecutionFee"},{type:"uint128",name:"forwardFee"},{type:"uint128",name:"maxForwardFee"}]},{type:"tuple",name:"quoteParams",components:[{type:"address",name:"priceContract"},{type:"bool",name:"applyExchangeRate"},{type:"uint16",name:"minDeviationRatio"}]}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getExecutionFee",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"marketId"}],outputs:[{type:"uint256"}]},{type:"function",name:"getExecutionFeeByToken",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"quoteToken"}],outputs:[{type:"uint256"}]},{type:"function",name:"getForwardFee",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"marketId"}],outputs:[{type:"uint256"}]},{type:"function",name:"getForwardFeeByToken",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"quoteToken"}],outputs:[{type:"uint256"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getMarket",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"marketId"}],outputs:[{type:"tuple",components:[{type:"address",name:"quoteToken"},{type:"uint32",name:"baseReserveRatio"},{type:"uint32",name:"quoteReserveRatio"},{type:"uint64",name:"oracleFeeUsd"},{type:"uint128",name:"poolPrimeThreshold"},{type:"uint128",name:"executionFee"},{type:"uint128",name:"maxExecutionFee"},{type:"uint128",name:"forwardFee"},{type:"uint128",name:"maxForwardFee"}]}]},{type:"function",name:"getMarketIds",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32[]"}]},{type:"function",name:"getOracleFee",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"marketId"}],outputs:[{type:"uint256"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"marketExists",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"marketId"}],outputs:[{type:"bool"}]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"updateExecutionFee",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint128",name:"_executionFee"}],outputs:[]},{type:"function",name:"updateForwardFee",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint128",name:"_forwardFee"}],outputs:[]},{type:"function",name:"updateMarketQuoteConfiguration",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"tuple",name:"quoteParams",components:[{type:"address",name:"priceContract"},{type:"bool",name:"applyExchangeRate"},{type:"uint16",name:"minDeviationRatio"}]}],outputs:[]},{type:"function",name:"updateMaxExecutionFee",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint128",name:"_maxExecutionFee"}],outputs:[]},{type:"function",name:"updateMaxForwardFee",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint128",name:"_maxForwardFee"}],outputs:[]},{type:"function",name:"updateOracleFee",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint64",name:"_oracleFeeUsd"}],outputs:[]},{type:"function",name:"updatePoolPrimeThreshold",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint128",name:"_poolPrimeThreshold"}],outputs:[]},{type:"function",name:"updateReserveRatio",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"marketId"},{type:"uint32",name:"_baseReserveRatio"},{type:"uint32",name:"_quoteReserveRatio"}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]}];var At=[{type:"constructor",payable:!1,inputs:[{type:"address",name:"addressManager"}]},{type:"error",name:"PositionNotHealthy",inputs:[{type:"bytes32",name:"positionId"},{type:"uint256",name:"marginRatio"}]},{type:"error",name:"SafeCastOverflowedUintToInt",inputs:[{type:"uint256",name:"value"}]},{type:"function",name:"ADDRESS_MANAGER",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getAccountInfo",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"}],outputs:[{type:"tuple",name:"accountInfo",components:[{type:"uint256",name:"freeMargin"},{type:"uint256",name:"walletBalance"},{type:"uint256",name:"freeBaseAmount"},{type:"uint256",name:"baseProfit"},{type:"uint256",name:"quoteProfit"},{type:"uint256",name:"reservedAmount"},{type:"uint64",name:"releaseTime"}]}]},{type:"function",name:"getAvailableLiquiditySize",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"operation"},{type:"uint8",name:"direction"},{type:"uint256",name:"executePrice"}],outputs:[{type:"uint256"}]},{type:"function",name:"getBrokerFeeTiers",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"brokerAddress"},{type:"uint8[]",name:"assetClasses"},{type:"uint8[]",name:"riskTiers"},{type:"bool",name:"isMYXBroker"}],outputs:[{type:"tuple[]",name:"brokerFees",components:[{type:"uint8",name:"asset"},{type:"tuple[]",name:"riskTieredBrokerFees",components:[{type:"uint8",name:"riskTier"},{type:"tuple[]",name:"addOnFeeTiers",components:[{type:"uint8",name:"tier"},{type:"uint32",name:"takerFeeRate"},{type:"int32",name:"makerFeeRate"}]},{type:"tuple[]",name:"baseFeeRate",components:[{type:"uint8",name:"assetClass"},{type:"uint32",name:"makerFeeRate"},{type:"uint32",name:"takerFeeRate"}]},{type:"tuple[]",name:"specialFeeTiers",components:[{type:"uint8",name:"tier"},{type:"uint32",name:"takerFeeRate"},{type:"int32",name:"makerFeeRate"}]}]}]}]},{type:"function",name:"getExchangeables",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"uint256[]",name:"marketPrices"}],outputs:[{type:"tuple[]",name:"exchangeables",components:[{type:"uint256",name:"maxBaseIn"},{type:"uint256",name:"maxQuoteIn"},{type:"uint256",name:"maxBaseOut"},{type:"uint256",name:"maxQuoteOut"}]}]},{type:"function",name:"getLiquidationPrice",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"positionId"},{type:"uint256",name:"marketPrice"},{type:"address",name:"broker"}],outputs:[{type:"uint256"}]},{type:"function",name:"getPoolInfo",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"marketPrice"}],outputs:[{type:"tuple",components:[{type:"tuple",name:"basePool",components:[{type:"address",name:"poolToken"},{type:"uint256",name:"exchangeRate"},{type:"uint256",name:"poolTokenPrice"},{type:"uint256",name:"poolTokenSupply"},{type:"uint256",name:"totalDebt"},{type:"uint256",name:"baseCollateral"}]},{type:"tuple",name:"quotePool",components:[{type:"address",name:"poolToken"},{type:"uint256",name:"exchangeRate"},{type:"uint256",name:"poolTokenPrice"},{type:"uint256",name:"poolTokenSupply"},{type:"uint256",name:"totalDebt"},{type:"uint256",name:"baseCollateral"}]},{type:"tuple",name:"reserveInfo",components:[{type:"uint256",name:"baseTotalAmount"},{type:"uint256",name:"baseReservedAmount"},{type:"uint256",name:"quoteTotalAmount"},{type:"uint256",name:"quoteReservedAmount"}]},{type:"tuple",name:"fundingInfo",components:[{type:"int256",name:"nextFundingRate"},{type:"int256",name:"lastFundingFeeTracker"},{type:"uint256",name:"nextEpochTime"}]},{type:"tuple",name:"oi",components:[{type:"int256",name:"tracker"},{type:"uint256",name:"longSize"},{type:"uint256",name:"shortSize"},{type:"uint256",name:"poolEntryPrice"}]},{type:"tuple",name:"liquidityInfo",components:[{type:"uint256",name:"windowCaps"},{type:"int256",name:"openInterest"}]}]}]},{type:"function",name:"getPoolInfos",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"uint256[]",name:"marketPrices"}],outputs:[{type:"tuple[]",components:[{type:"tuple",name:"basePool",components:[{type:"address",name:"poolToken"},{type:"uint256",name:"exchangeRate"},{type:"uint256",name:"poolTokenPrice"},{type:"uint256",name:"poolTokenSupply"},{type:"uint256",name:"totalDebt"},{type:"uint256",name:"baseCollateral"}]},{type:"tuple",name:"quotePool",components:[{type:"address",name:"poolToken"},{type:"uint256",name:"exchangeRate"},{type:"uint256",name:"poolTokenPrice"},{type:"uint256",name:"poolTokenSupply"},{type:"uint256",name:"totalDebt"},{type:"uint256",name:"baseCollateral"}]},{type:"tuple",name:"reserveInfo",components:[{type:"uint256",name:"baseTotalAmount"},{type:"uint256",name:"baseReservedAmount"},{type:"uint256",name:"quoteTotalAmount"},{type:"uint256",name:"quoteReservedAmount"}]},{type:"tuple",name:"fundingInfo",components:[{type:"int256",name:"nextFundingRate"},{type:"int256",name:"lastFundingFeeTracker"},{type:"uint256",name:"nextEpochTime"}]},{type:"tuple",name:"oi",components:[{type:"int256",name:"tracker"},{type:"uint256",name:"longSize"},{type:"uint256",name:"shortSize"},{type:"uint256",name:"poolEntryPrice"}]},{type:"tuple",name:"liquidityInfo",components:[{type:"uint256",name:"windowCaps"},{type:"int256",name:"openInterest"}]}]}]},{type:"function",name:"getPoolTokenPrices",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32[]",name:"poolIds"},{type:"uint256[]",name:"marketPrices"}],outputs:[{type:"tuple[]",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"basePoolTokenPrice"},{type:"uint256",name:"quotePoolTokenPrice"}]}]},{type:"function",name:"getPositionFees",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"positionId"},{type:"address",name:"broker"},{type:"uint256",name:"price"}],outputs:[{type:"int256",name:"netCollateral"},{type:"uint256",name:"collateralAmount"},{type:"uint256",name:"tradingFee"},{type:"int256",name:"fundingFee"}]},{type:"function",name:"getSumProfitLock",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address[]",name:"respondents"}],outputs:[{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"},{type:"tuple[]",name:"infos",components:[{type:"address",name:"account"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"}]}]},{type:"function",name:"getUserPositionInfos",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"user"},{type:"bytes32[]",name:"poolIds"}],outputs:[{type:"tuple[]",name:"positions",components:[{type:"bytes32",name:"positionId"},{type:"bytes32",name:"poolId"},{type:"uint256",name:"size"},{type:"uint256",name:"entryPrice"},{type:"int256",name:"fundingRateIndex"},{type:"uint256",name:"earlyClosePrice"},{type:"uint8",name:"direction"},{type:"uint8",name:"riskTier"},{type:"uint64",name:"lastUpdateTime"},{type:"uint256",name:"collateralAmount"}]}]}];var ve=[{type:"constructor",payable:!1,inputs:[]},{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"ERC2771ForwarderExpiredRequest",inputs:[{type:"uint48",name:"deadline"}]},{type:"error",name:"ERC2771ForwarderInvalidSigner",inputs:[{type:"address",name:"signer"},{type:"address",name:"from"}]},{type:"error",name:"ERC2771ForwarderMismatchedValue",inputs:[{type:"uint256",name:"requestedValue"},{type:"uint256",name:"msgValue"}]},{type:"error",name:"ERC2771UntrustfulTarget",inputs:[{type:"address",name:"target"},{type:"address",name:"forwarder"}]},{type:"error",name:"ExceedsMaximumRelayFee",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InconsistentParamsLength",inputs:[]},{type:"error",name:"InsufficientBalance",inputs:[{type:"uint256",name:"balance"},{type:"uint256",name:"needed"}]},{type:"error",name:"InsufficientFeeAllowance",inputs:[{type:"address",name:"user"},{type:"uint256",name:"allowance"},{type:"uint256",name:"required"}]},{type:"error",name:"InsufficientFeeBalance",inputs:[{type:"address",name:"user"},{type:"uint256",name:"balance"},{type:"uint256",name:"required"}]},{type:"error",name:"InvalidAccountNonce",inputs:[{type:"address",name:"account"},{type:"uint256",name:"currentNonce"}]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"MismatchExecuteFee",inputs:[{type:"uint256",name:"balanceBefore"},{type:"uint256",name:"balanceAfter"},{type:"uint256",name:"expected"}]},{type:"error",name:"MismatchedSender",inputs:[{type:"address",name:"sender"}]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotAllowedTarget",inputs:[{type:"address",name:"target"}]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"OnlyRelayer",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"RelayerRegistered",inputs:[{type:"address",name:"relayer"}]},{type:"error",name:"RemoveRelayerFailed",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"AddAllowedTarget",inputs:[{type:"address",name:"target",indexed:!1}]},{type:"event",anonymous:!1,name:"ChargeForwardFee",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"feeToken",indexed:!1},{type:"uint256",name:"relayFee",indexed:!1}]},{type:"event",anonymous:!1,name:"EIP712DomainChanged",inputs:[]},{type:"event",anonymous:!1,name:"ERC20PermitFailed",inputs:[{type:"address",name:"token",indexed:!1},{type:"string",name:"reason",indexed:!1}]},{type:"event",anonymous:!1,name:"ERC20PermitLowLevelFailed",inputs:[{type:"bytes",name:"data",indexed:!1}]},{type:"event",anonymous:!1,name:"ExecutedForwardRequest",inputs:[{type:"address",name:"signer",indexed:!0},{type:"uint256",name:"nonce",indexed:!1},{type:"bool",name:"success",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"RemoveAllowedTarget",inputs:[{type:"address",name:"target",indexed:!1}]},{type:"event",anonymous:!1,name:"SetUserRelayer",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"relayer",indexed:!1},{type:"bool",name:"enable",indexed:!1}]},{type:"event",anonymous:!1,name:"UpdateAcquiescentFeeToken",inputs:[{type:"address",name:"sender",indexed:!1},{type:"address",name:"oldRelayGas",indexed:!1},{type:"address",name:"newRelayGas",indexed:!1}]},{type:"event",anonymous:!1,name:"UpdateEquilibriumGas",inputs:[{type:"address",name:"sender",indexed:!1},{type:"uint256",name:"oldRelayGas",indexed:!1},{type:"uint256",name:"newRelayGas",indexed:!1}]},{type:"event",anonymous:!1,name:"UpdateMaxRelayFee",inputs:[{type:"address",name:"sender",indexed:!1},{type:"uint256",name:"oldMaxRelayFee",indexed:!1},{type:"uint256",name:"newMaxRelayFee",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"__ERC2771ContextUpgradeable_init",constant:!1,payable:!1,inputs:[{type:"address",name:"trustedForwarder_"}],outputs:[]},{type:"function",name:"addAllowedTarget",constant:!1,payable:!1,inputs:[{type:"address",name:"target"}],outputs:[]},{type:"function",name:"batchExecuteForwarder",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"forwardFeeToken"},{type:"tuple[]",name:"bundleParams",components:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"uint256",name:"value"},{type:"uint256",name:"gas"},{type:"uint48",name:"deadline"},{type:"bytes",name:"data"},{type:"bytes",name:"signature"}]}],outputs:[]},{type:"function",name:"eip712Domain",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes1",name:"fields"},{type:"string",name:"name"},{type:"string",name:"version"},{type:"uint256",name:"chainId"},{type:"address",name:"verifyingContract"},{type:"bytes32",name:"salt"},{type:"uint256[]",name:"extensions"}]},{type:"function",name:"equilibriumGas",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"execute",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple",name:"request",components:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"uint256",name:"value"},{type:"uint256",name:"gas"},{type:"uint48",name:"deadline"},{type:"bytes",name:"data"},{type:"bytes",name:"signature"}]},{type:"address",name:"masterAccount"}],outputs:[]},{type:"function",name:"executeBatch",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"requests",components:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"uint256",name:"value"},{type:"uint256",name:"gas"},{type:"uint48",name:"deadline"},{type:"bytes",name:"data"},{type:"bytes",name:"signature"}]},{type:"address",name:"masterAccount"},{type:"address",name:"refundReceiver"}],outputs:[]},{type:"function",name:"executeForwarder",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"forwardFeeToken"},{type:"tuple",name:"params",components:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"uint256",name:"value"},{type:"uint256",name:"gas"},{type:"uint48",name:"deadline"},{type:"bytes",name:"data"},{type:"bytes",name:"signature"}]}],outputs:[]},{type:"function",name:"exitForwardMode",constant:!1,payable:!1,inputs:[],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getAllowedTargets",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address[]"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getDesignatedToken",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getEquilibriumGas",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getUserRelayers",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"}],outputs:[{type:"address[]"}]},{type:"function",name:"inForwardMode",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bool"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"},{type:"uint256",name:"_equilibriumGas"}],outputs:[]},{type:"function",name:"isAllowedTargets",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"contractAddr"}],outputs:[{type:"bool"}]},{type:"function",name:"isTrustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"forwarder"}],outputs:[{type:"bool"}]},{type:"function",name:"isUserRelayerEnabled",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"},{type:"address",name:"relayer"}],outputs:[{type:"bool"}]},{type:"function",name:"nonces",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"owner"}],outputs:[{type:"uint256"}]},{type:"function",name:"originAccount",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"relayer"}],outputs:[{type:"address",name:"account"}]},{type:"function",name:"permitAndApproveForwarder",constant:!1,payable:!1,inputs:[{type:"address",name:"relayer"},{type:"bool",name:"enable"},{type:"tuple[]",name:"permitParams",components:[{type:"address",name:"token"},{type:"address",name:"owner"},{type:"address",name:"spender"},{type:"uint256",name:"value"},{type:"uint256",name:"deadline"},{type:"uint8",name:"v"},{type:"bytes32",name:"r"},{type:"bytes32",name:"s"}]}],outputs:[]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"removeAllowedTarget",constant:!1,payable:!1,inputs:[{type:"address",name:"target"}],outputs:[]},{type:"function",name:"trustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"updateEquilibriumGas",constant:!1,payable:!1,inputs:[{type:"uint256",name:"_equilibriumGas"}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"verify",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"tuple",name:"request",components:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"uint256",name:"value"},{type:"uint256",name:"gas"},{type:"uint48",name:"deadline"},{type:"bytes",name:"data"},{type:"bytes",name:"signature"}]}],outputs:[{type:"bool"}]}];var Ct=[{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"AlreadyClaimed",inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"user"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidAmount",inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"user"}]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidParameter",inputs:[]},{type:"error",name:"MerkleTreeVerificationFailed",inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"user"}]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"ReimbursementValidity",inputs:[{type:"uint256",name:"caseId"}]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"TreeAlreadySet",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"ReimbursementClaimExpired",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint256",name:"baseAmount",indexed:!1},{type:"uint256",name:"quoteAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReimbursementClaimed",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint256",name:"baseAmount",indexed:!1},{type:"uint256",name:"quoteAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReimbursementInfoSet",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"bytes32",name:"merkleRoot",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint256",name:"totalBaseAmount",indexed:!1},{type:"uint256",name:"totalQuoteAmount",indexed:!1},{type:"uint256",name:"claimedBaseAmount",indexed:!1},{type:"uint256",name:"claimedQuoteAmount",indexed:!1},{type:"uint256",name:"expireTime",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"claimExpiredCases",constant:!1,payable:!1,inputs:[{type:"uint256[]",name:"caseIds"},{type:"address",name:"receiver"}],outputs:[]},{type:"function",name:"claimReimbursement",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"},{type:"bytes32[]",name:"merkleProof"}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getReimbursementInfo",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint256",name:"caseId"}],outputs:[{type:"tuple",components:[{type:"bytes32",name:"merkleRoot"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint256",name:"totalBaseAmount"},{type:"uint256",name:"totalQuoteAmount"},{type:"uint256",name:"claimedBaseAmount"},{type:"uint256",name:"claimedQuoteAmount"},{type:"uint256",name:"expireTime"}]}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"setReimbursementInfo",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"tuple",name:"reimbursementInfo",components:[{type:"bytes32",name:"merkleRoot"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint256",name:"totalBaseAmount"},{type:"uint256",name:"totalQuoteAmount"},{type:"uint256",name:"claimedBaseAmount"},{type:"uint256",name:"claimedQuoteAmount"},{type:"uint256",name:"expireTime"}]},{type:"bytes32[]",name:"zeroMerkleProof"}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]}];var Ee=[{type:"constructor",payable:!1,inputs:[]},{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"AlreadyVoted",inputs:[]},{type:"error",name:"BondNotReleased",inputs:[]},{type:"error",name:"CaseAppealNotFinished",inputs:[]},{type:"error",name:"CaseDeadlineNotReached",inputs:[]},{type:"error",name:"CaseDeadlineReached",inputs:[]},{type:"error",name:"CaseNotAccepted",inputs:[]},{type:"error",name:"CaseNotExist",inputs:[{type:"uint256",name:"caseId"}]},{type:"error",name:"CaseRespondentAppealed",inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"respondent"}]},{type:"error",name:"ChainIdMismatch",inputs:[]},{type:"error",name:"DisputeNotAllowed",inputs:[]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidAccountNonce",inputs:[{type:"address",name:"account"},{type:"uint256",name:"currentNonce"}]},{type:"error",name:"InvalidContractAddress",inputs:[]},{type:"error",name:"InvalidFunctionSignature",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidParameter",inputs:[]},{type:"error",name:"InvalidPayloadLength",inputs:[{type:"uint256",name:"received"},{type:"uint256",name:"expected"}]},{type:"error",name:"InvalidPoolToken",inputs:[]},{type:"error",name:"InvalidProfitAmount",inputs:[]},{type:"error",name:"InvalidResponseVersion",inputs:[]},{type:"error",name:"InvalidSourceChain",inputs:[]},{type:"error",name:"NoChainResponse",inputs:[]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotCaseRespondent",inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"respondent"}]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"NumberOfResponsesMismatch",inputs:[]},{type:"error",name:"OnlyRelayer",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"RequestTypeMismatch",inputs:[]},{type:"error",name:"RiskCloseNotCompleted",inputs:[]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"SignatureExpired",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"error",name:"UnexpectedCaseState",inputs:[]},{type:"error",name:"UnexpectedCaseType",inputs:[]},{type:"error",name:"UnexpectedNumberOfResults",inputs:[]},{type:"error",name:"UnsupportedQueryType",inputs:[{type:"uint8",name:"received"}]},{type:"error",name:"UntrustfulVoting",inputs:[]},{type:"error",name:"VerificationFailed",inputs:[]},{type:"error",name:"VersionMismatch",inputs:[]},{type:"error",name:"WrongQueryType",inputs:[{type:"uint8",name:"received"},{type:"uint8",name:"expected"}]},{type:"error",name:"ZeroQueries",inputs:[]},{type:"event",anonymous:!1,name:"AppealCanceled",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"uint256",name:"appealCaseId",indexed:!1},{type:"address",name:"complainant",indexed:!1},{type:"bool",name:"isMalicious",indexed:!1}]},{type:"event",anonymous:!1,name:"AppealFiled",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"uint256",name:"appealCaseId",indexed:!1},{type:"address",name:"respondent",indexed:!1},{type:"address",name:"appealToken",indexed:!1},{type:"uint256",name:"appealBond",indexed:!1},{type:"uint64",name:"appealDeadline",indexed:!1}]},{type:"event",anonymous:!1,name:"AppealResolved",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"uint256",name:"appealCaseId",indexed:!1},{type:"uint8",name:"resolution",indexed:!1},{type:"address",name:"complainant",indexed:!1}]},{type:"event",anonymous:!1,name:"BondClaimed",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"CaseAppealsResolved",inputs:[{type:"uint256",name:"caseId",indexed:!1}]},{type:"event",anonymous:!1,name:"CaseRiskClosed",inputs:[{type:"uint256",name:"caseId",indexed:!1}]},{type:"event",anonymous:!1,name:"DisputeCanceled",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"address",name:"complainant",indexed:!1},{type:"bool",name:"isMalicious",indexed:!1}]},{type:"event",anonymous:!1,name:"DisputeConfigurationUpdated",inputs:[{type:"tuple",name:"newDisputeConfigration",indexed:!1,components:[{type:"address",name:"appealToken"},{type:"uint64",name:"disputeBondUsd"},{type:"uint64",name:"appealBondUsd"},{type:"uint64",name:"disputeThresholdUsd"},{type:"uint64",name:"caseDuration"},{type:"uint64",name:"voteDuration"},{type:"uint64",name:"resolveDuration"},{type:"uint32",name:"voteCountRate"},{type:"uint32",name:"effectiveVoteRate"}]}]},{type:"event",anonymous:!1,name:"DisputeFiled",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"complainant",indexed:!1},{type:"address",name:"poolToken",indexed:!1},{type:"uint256",name:"disputeBond",indexed:!1},{type:"uint64",name:"caseDeadline",indexed:!1}]},{type:"event",anonymous:!1,name:"DisputeResolved",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"uint8",name:"resolution",indexed:!1},{type:"uint64",name:"appealDeadline",indexed:!1}]},{type:"event",anonymous:!1,name:"ForfeitBondsClaimed",inputs:[{type:"address",name:"receiver",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"ReimbursementProcessed",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"tuple",name:"reimbursementInfo",indexed:!1,components:[{type:"bytes32",name:"merkleRoot"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint256",name:"totalBaseAmount"},{type:"uint256",name:"totalQuoteAmount"},{type:"uint256",name:"claimedBaseAmount"},{type:"uint256",name:"claimedQuoteAmount"},{type:"uint256",name:"expireTime"}]}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"event",anonymous:!1,name:"Voted",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"address",name:"voter",indexed:!1},{type:"uint8",name:"voteOption",indexed:!1}]},{type:"event",anonymous:!1,name:"VotingOpened",inputs:[{type:"uint256",name:"caseId",indexed:!1},{type:"uint256",name:"evidenceId",indexed:!1},{type:"uint64",name:"voteDeadline",indexed:!1},{type:"address[]",name:"respondents",indexed:!1}]},{type:"event",anonymous:!1,name:"WormholeConfigurationUpdated",inputs:[{type:"tuple",name:"newWormholeConfiguration",indexed:!1,components:[{type:"address",name:"wormhole"},{type:"address",name:"staker"},{type:"bytes4",name:"selector"}]}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"appeal",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"}],outputs:[]},{type:"function",name:"canRiskControlClose",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint256",name:"caseId"}],outputs:[{type:"bool"}]},{type:"function",name:"cancelAppeal",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"uint256",name:"appealCaseId"},{type:"bool",name:"isMalicious"}],outputs:[]},{type:"function",name:"cancelDispute",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"bool",name:"isMalicious"}],outputs:[]},{type:"function",name:"caseIdSequencer",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"checkRiskControlCloseCompleted",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"}],outputs:[]},{type:"function",name:"claimBond",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"}],outputs:[]},{type:"function",name:"claimForfeitBonds",constant:!1,payable:!1,inputs:[{type:"address",name:"receiver"}],outputs:[]},{type:"function",name:"fileDispute",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"tuple[]",name:"prices",components:[{type:"bytes32",name:"poolId"},{type:"uint8",name:"oracleType"},{type:"uint64",name:"publishTime"},{type:"bytes",name:"oracleUpdateData"}]},{type:"bytes32",name:"poolId"},{type:"address",name:"poolToken"}],outputs:[]},{type:"function",name:"fileDisputeFromStaker",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"bytes",name:"response"},{type:"tuple[]",name:"guardianSignatures",components:[{type:"bytes32",name:"r"},{type:"bytes32",name:"s"},{type:"uint8",name:"v"},{type:"uint8",name:"guardianIndex"}]}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getDisputeConfiguration",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"tuple",components:[{type:"address",name:"appealToken"},{type:"uint64",name:"disputeBondUsd"},{type:"uint64",name:"appealBondUsd"},{type:"uint64",name:"disputeThresholdUsd"},{type:"uint64",name:"caseDuration"},{type:"uint64",name:"voteDuration"},{type:"uint64",name:"resolveDuration"},{type:"uint32",name:"voteCountRate"},{type:"uint32",name:"effectiveVoteRate"}]}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"isCaseRespondents",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"account"}],outputs:[{type:"bool"}]},{type:"function",name:"nonces",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"owner"}],outputs:[{type:"uint256"}]},{type:"function",name:"openVoting",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"uint256",name:"evidenceId"},{type:"address[]",name:"respondents"}],outputs:[]},{type:"function",name:"processReimbursement",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"tuple",name:"reimbursementInfo",components:[{type:"bytes32",name:"merkleRoot"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint256",name:"totalBaseAmount"},{type:"uint256",name:"totalQuoteAmount"},{type:"uint256",name:"claimedBaseAmount"},{type:"uint256",name:"claimedQuoteAmount"},{type:"uint256",name:"expireTime"}]},{type:"bytes32[]",name:"zeroMerkleProof"}],outputs:[]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"resolveCaseAppeals",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"bytes",name:"response"},{type:"tuple[]",name:"guardianSignatures",components:[{type:"bytes32",name:"r"},{type:"bytes32",name:"s"},{type:"uint8",name:"v"},{type:"uint8",name:"guardianIndex"}]}],outputs:[]},{type:"function",name:"resolveDispute",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"bytes",name:"response"},{type:"tuple[]",name:"guardianSignatures",components:[{type:"bytes32",name:"r"},{type:"bytes32",name:"s"},{type:"uint8",name:"v"},{type:"uint8",name:"guardianIndex"}]}],outputs:[]},{type:"function",name:"updateDisputeConfiguration",constant:!1,payable:!1,inputs:[{type:"tuple",name:"disputeConfiguration",components:[{type:"address",name:"appealToken"},{type:"uint64",name:"disputeBondUsd"},{type:"uint64",name:"appealBondUsd"},{type:"uint64",name:"disputeThresholdUsd"},{type:"uint64",name:"caseDuration"},{type:"uint64",name:"voteDuration"},{type:"uint64",name:"resolveDuration"},{type:"uint32",name:"voteCountRate"},{type:"uint32",name:"effectiveVoteRate"}]}],outputs:[]},{type:"function",name:"updateWormholeConfiguration",constant:!1,payable:!1,inputs:[{type:"tuple",name:"wormholeConfiguration",components:[{type:"address",name:"wormhole"},{type:"address",name:"staker"},{type:"bytes4",name:"selector"}]}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"vote",constant:!1,payable:!1,inputs:[{type:"uint256",name:"caseId"},{type:"address",name:"validator"},{type:"uint8",name:"voteOption"},{type:"uint256",name:"deadline"},{type:"uint8",name:"v"},{type:"bytes32",name:"r"},{type:"bytes32",name:"s"}],outputs:[]}];var ke=[{type:"error",name:"AccountInsufficientFreeAmount",inputs:[]},{type:"error",name:"AccountInsufficientReservedAmount",inputs:[]},{type:"error",name:"AccountInsufficientTradableAmount",inputs:[{type:"uint256",name:"accountTradableAmount"},{type:"uint256",name:"requiredTradableAmount"}]},{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"PermissionDenied",inputs:[{type:"address",name:"caller"},{type:"address",name:"target"}]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{type:"address",name:"token"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"DepositToAccount",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"ExecuteCompensation",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"baseAmount",indexed:!1},{type:"uint256",name:"quoteAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"PayWithPrincipal",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"receiver",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"PayWithProfitFirst",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"receiver",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"usedFreeAmount",indexed:!1},{type:"uint256",name:"usedRestrictedAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReleaseForOrder",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"address",name:"account",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReleaseProfit",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReserveForOrder",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"address",name:"account",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"SettleToAccount",inputs:[{type:"address",name:"account",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint256",name:"freeBase",indexed:!1},{type:"uint256",name:"profitBase",indexed:!1},{type:"uint256",name:"freeAmount",indexed:!1},{type:"uint256",name:"profitAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"event",anonymous:!1,name:"WithdrawFromAccount",inputs:[{type:"address",name:"account",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"__ERC2771ContextUpgradeable_init",constant:!1,payable:!1,inputs:[{type:"address",name:"trustedForwarder_"}],outputs:[]},{type:"function",name:"deposit",constant:!1,payable:!1,inputs:[{type:"address",name:"account"},{type:"address",name:"token"},{type:"uint256",name:"amount"}],outputs:[]},{type:"function",name:"executeCompensation",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"reimbursement"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getPoolWithdrawableBaseToken",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"},{type:"bytes32",name:"poolId"}],outputs:[{type:"uint256",name:"baseAmount"}]},{type:"function",name:"getTradableAmount",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"},{type:"bytes32",name:"poolId"}],outputs:[{type:"bool"},{type:"uint256"},{type:"uint256"},{type:"uint256"}]},{type:"function",name:"getUserAsset",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"},{type:"address",name:"token"}],outputs:[{type:"uint256",name:"amount"}]},{type:"function",name:"getUserAssets",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"account"}],outputs:[{type:"tuple[]",components:[{type:"address",name:"asset"},{type:"uint256",name:"amount"}]}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"isTrustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"address",name:"forwarder"}],outputs:[{type:"bool"}]},{type:"function",name:"payWithPrincipal",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"address",name:"account"},{type:"address",name:"token"},{type:"uint256",name:"amount"},{type:"address",name:"receiver"}],outputs:[]},{type:"function",name:"payWithProfitFirst",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"address",name:"account"},{type:"address",name:"token"},{type:"uint256",name:"amount"}],outputs:[{type:"uint256",name:"usedFreeAmount"},{type:"uint256",name:"usedRestrictedAmount"}]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"releaseForCancelOrder",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"address",name:"account"},{type:"uint256",name:"amount"}],outputs:[]},{type:"function",name:"releaseFromProfitUnlock",constant:!1,payable:!1,inputs:[{type:"address",name:"account"},{type:"bytes32",name:"poolId"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"}],outputs:[]},{type:"function",name:"reserveForOrder",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"address",name:"account"},{type:"address",name:"token"},{type:"uint256",name:"amount"}],outputs:[]},{type:"function",name:"settlementDeposit",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"positionId"},{type:"address",name:"account"},{type:"tuple",name:"pool",components:[{type:"bytes32",name:"marketId"},{type:"bytes32",name:"poolId"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint8",name:"riskTier"},{type:"uint8",name:"state"},{type:"address",name:"basePoolToken"},{type:"address",name:"quotePoolToken"},{type:"uint16",name:"maxPriceDeviation"},{type:"bool",name:"compoundEnabled"},{type:"uint64",name:"windowCapUsd"},{type:"address",name:"poolVault"},{type:"address",name:"tradingVault"}]},{type:"uint256",name:"freeBaseAmount"},{type:"uint256",name:"freeQuoteAmount"},{type:"uint256",name:"receivedBaseAmount"},{type:"uint256",name:"receivedQuoteAmount"}],outputs:[]},{type:"function",name:"trustedForwarder",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"updateAndWithdraw",constant:!1,payable:!1,inputs:[{type:"address",name:"receiver"},{type:"bytes32",name:"poolId"},{type:"bool",name:"isQuoteToken"},{type:"uint256",name:"amount"}],outputs:[]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]}];var dn={USDC:"0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",POOL_MANAGER:"0xf268D9FeD3Bd56fd9aBdb4FeEb993338613678A8",Account:"0x396a6aDb17903f4b0ED3EA55F18391C403fa3Bb4",POSITION_MANAGER:"0x89d1091Ef4aB71d688a86f3D92112715905d7B8A",ORDER_MANAGER:"0x5948bc0E0c72a7B7a90eb8f5a1951bDB0ef0f68D",PYTH:"0x4374e5a8b9C22271E9EB878A2AA31DE97DF15DAF",ERC20:"0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",LIQUIDITY_ROUTER:"0x5E16C0699de2Ee5D69a620AB38AE2c81A29a58df",BASE_POOL:"0xDb41D850e9b30fc0417F488D1aB64fdc1d0DdFdc",QUOTE_POOL:"0xF0784c1023C051Bf1D5b8470A896c536039B06B9",ORACLE:"0xb3C295769d86fc321bA70a7C43EAfa10322CC66F",EIP7702Delegation:"0xe3D34CbDfC221e064510Cfa82EFF99172651BeB9",MARKET_MANAGER:"0xB3EEc5C2eEc049b4eD4C528Dcd9a97680E3edFb7",DATA_PROVIDER:"0xeA2be692Da76Bf6851f3cBf9750075e10E9085cB",ORACLE_RESERVE:"0x247e3A9d6E9CF6D619c7D0A0eE11B7CD966FA3aa",FORWARDER:"0x065Adb8183c114c3a61d75c89051ecE6C1C9A6fB",TRADING_ROUTER:"0x6A2aF0be0629B424a6A7EfEf54a3b50a99bC1a29",REIMBURSEMENT:"0x2C294a480006703B1A4F6493eA3B1dAC7A84454b",DISPUTE_COURT:"0x09F56485B5FB01C6C27bB81f54605F4d55d7d10B"};var cn={USDC:"0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",POOL_MANAGER:"0x05314a21Fc97B74f168730153b2B63A870D25dE5",Account:"0xAC0ca67fd6C7Ff9c80DE58420B840115b6d51c6e",POSITION_MANAGER:"0x1a8cC8391Ee19c3817de64a52904D0557f519bA5",ORDER_MANAGER:"0x3138f425f11f14fE33a180e9Bbf0661C8dc6d8AD",PYTH:"0x4374e5a8b9C22271E9EB878A2AA31DE97DF15DAF",ERC20:"0x7E248Ec1721639413A280d9E82e2862Cae2E6E28",LIQUIDITY_ROUTER:"0xfb790ECE13Cd9e296b4a06ABF38D10431360c236",BASE_POOL:"0x1F767BEa83EDe5E0C18904f439C579f52c2c0F1b",QUOTE_POOL:"0x50ad7da312c58c6689bEF028954a366cb5b8ee13",ORACLE:"0x3e437094C5687Ed6eDb1883b0bd445Efa9103a55",EIP7702Delegation:"0xc68fdf81ca68B26fdB296645F42a734c12E63751",MARKET_MANAGER:"0x71b57CcB7539aB761fd5C5767362A207a295e337",DATA_PROVIDER:"0xd4FdE3cc72D29b71507823cA43Dd6fD520644E92",ORACLE_RESERVE:"0x4fC26Cf34e5d486BFF211315bf17D77d34130971",FORWARDER:"0x58fb1a663b08871A755734231C387E1d10ac2B10",TRADING_ROUTER:"0x89ba8EDBD63f577cAA1095F25Df0A44A226f28bc",REIMBURSEMENT:"0xDbCe02B080C68671EF6EcEc1a01A789441A3a564",DISPUTE_COURT:"0x47648D171925a69b3A334898AaaE6e7cc41B1735"};var ln={USDC:"0xD984fd34f91F92DA0586e1bE82E262fF27DC431b",POOL_MANAGER:"0x784808c123B778BacB2c08782837BC083e6C5cF0",Account:"0xB219526B2DC7Aa25Eb78A8Bd5e0AeaC9880f26Ca",POSITION_MANAGER:"0xca570536de1398d855507bA62c01B0dF3ecf8FE9",ORDER_MANAGER:"0x679859C80e58e5026018401bED798C574c844560",PYTH:"0xA2aa501b19aff244D90cc15a4Cf739D2725B5729",ERC20:"0xD984fd34f91F92DA0586e1bE82E262fF27DC431b",LIQUIDITY_ROUTER:"0xf1395643D77DD839E4b8d3Bb122fd0275Cf07631",BASE_POOL:"0x31b093BBADbb2A3Bcd7E433E8Ed5bcdD76fFAFFe",QUOTE_POOL:"0xFF8A6797E2063A7a4cd1468eB7cC0db9798C753f",ORACLE:"0x0074441b86da2aE6818304B586fCf619c68C4204",EIP7702Delegation:"0x7629731046b2498b4C00B8a2208e538E706E5bfc",MARKET_MANAGER:"0x170F95d91B27d8bc7afA85B06d8B129BA34f405F",DATA_PROVIDER:"0x8873C5828fe1A903221971817b17dc67903544d6",ORACLE_RESERVE:"0xDc9321c19b02cefe57fFB2C1F70014a478D06ddF",FORWARDER:"0x2AC73d767D2c3e44741410c3E41988a05bCf9C86",TRADING_ROUTER:"0x5976abbC616520968b12EeB4b11AFa8490281453",REIMBURSEMENT:"0x257BF8df1CF76762985F3cf19c7cd1D6Adb67Bc7",DISPUTE_COURT:"0x02495c66dfb2ECeF5ebb7339a997EBb7D73DFdbf"};var mn={POOL_MANAGER:"0xcf51a6895864c6D8E507fC31EF16b9011287c5f4",Account:"0x35054EfE58Bbdae792aeCaD7bC2e4939c169560f",POSITION_MANAGER:"0x689A0C7E46785584FF7636700ceF5d5e7c141F8D",ORDER_MANAGER:"0xa0B5E5AE9D3E214096C90DDeC04D39B27ED9B272",PYTH:"0xA2aa501b19aff244D90cc15a4Cf739D2725B5729",ERC20:"0xD984fd34f91F92DA0586e1bE82E262fF27DC431b",LIQUIDITY_ROUTER:"0x0AE31989318565620c03d35889a0B2536b8fba5C",BASE_POOL:"0xc9e3826c42183207B418116A16827C1605132c51",QUOTE_POOL:"0x9A9934D3b22103dE822d94A22A3177d728FE0e5a",ORACLE:"0x0dD8293765358cF7f2646D0B91bA59804E197FC6",EIP7702Delegation:"0x4686F8a0d44b056037b2A51c4342EE7FA8e0A48F",MARKET_MANAGER:"0xe99dAB65c5546D7C87850Bbc40C6a7BEd7328Efa",DATA_PROVIDER:"0x5b6Be9839552a49302d552aB3C223b60Adb8BF1D",ORACLE_RESERVE:"0xB3D5a67223905FE73a0749e7A03525838063C54C",USDC:"0xD984fd34f91F92DA0586e1bE82E262fF27DC431b",FORWARDER:"0x6C40462A4d45BA4119af59Fb9e41b8eaC9293962",TRADING_ROUTER:"0x0000000000000000000000000000000000000000",REIMBURSEMENT:"0x0000000000000000000000000000000000000000",DISPUTE_COURT:"0x0000000000000000000000000000000000000000"};var yn={USDC:"0xe944d7c0f7005a76E898Ee3B9Ec10479EbA9Cc02",POOL_MANAGER:"0x4F917ef137b573D9790b87e3cF6dfb698cF00c9c",Account:"0xE58CC82F96c86f8F809A98BE14D9DC929d503e25",POSITION_MANAGER:"0x7A5000A1DDE26520BfC893c676a288F98F8a029c",ORDER_MANAGER:"0x343d7563eFb904375Fea81BcC4A3eCdDc0CDa8C9",PYTH:"0x5744Cbf430D99456a0A8771208b674F27f8EF0Fb",ERC20:"0xe944d7c0f7005a76E898Ee3B9Ec10479EbA9Cc02",LIQUIDITY_ROUTER:"0xe9F2E58562aD1D50AfB1eD92EAa6D367A6D0e552",BASE_POOL:"0x39506f97D1c1A91EAfD59368697E20dC1fE5eEDB",QUOTE_POOL:"0x80DAa474e7e2C9c86708e434B80636b92fb4e9EE",ORACLE:"0xB980765F0D5D3B482601F1a62Ec898619DA9c0C5",EIP7702Delegation:"0x9d43e7847f74E141E1A2B4C413D5F89520995551",MARKET_MANAGER:"0x624d1D5258b34d5C3F4f9CdCB7582F677643cdDC",DATA_PROVIDER:"0xb3c6b1448F04B3Eb9A5D83D6c32B0a10F3E7281B",ORACLE_RESERVE:"0x949e8a0284eA5509B47619e7667C3aA43B7c0336",FORWARDER:"0x73F9F9205E2F7E0Fb886afC3D2a53399C85383a5",TRADING_ROUTER:"0x0000000000000000000000000000000000000000",REIMBURSEMENT:"0x0000000000000000000000000000000000000000",DISPUTE_COURT:"0x0000000000000000000000000000000000000000"};var fn={USDC:"0xe944d7c0f7005a76E898Ee3B9Ec10479EbA9Cc02",POOL_MANAGER:"0x9E84a999e15CCdb2F64a5AF10939c25769dF6b07",Account:"0x42A1BC012CeC51Ebf3bbf79142bf2a912396FB0e",POSITION_MANAGER:"0x011a25Fe39b2f9033E49d1587CF24780242e40dA",ORDER_MANAGER:"0xfc30D3C858B72a9EDfE6679Fc3355039D276f811",PYTH:"0x5744Cbf430D99456a0A8771208b674F27f8EF0Fb",ERC20:"0xe944d7c0f7005a76E898Ee3B9Ec10479EbA9Cc02",LIQUIDITY_ROUTER:"0x0F4C6f18Fb136DD1eBd6Da3C5d86a86597CF79a3",BASE_POOL:"0x51B62554a76197d5DF2D5dC4D57FF54d40775938",QUOTE_POOL:"0x783Ed065a12e1C1D33c2a8d6408385C1843D3084",ORACLE:"0xaF26d69BC0A6f1DEf8AeB00B6DAD28398ba67a53",EIP7702Delegation:"0xc8558cD3905F273ff45B1dd6D10894445bFa622f",MARKET_MANAGER:"0x3b809daB550f9DD0DbE82567f6EA6137C174532c",DATA_PROVIDER:"0x4B5888025570934cC9D31807feBAAEDaC823Cb8e",ORACLE_RESERVE:"0x3011dA5822c1ECA7fcda64716779769D0089945D",FORWARDER:"0x2943a063ae2A772f4314FaA28E00De827A491Dd3",TRADING_ROUTER:"0xaA16801F36e49cDD4f87938032487C7E6cfbb389",REIMBURSEMENT:"0xBF72B69bA547D0bB7D1255B43Ff5D7f2615326dF",DISPUTE_COURT:"0xeD8B129a5919c45c7391AA73632eA691A471C672"};import Ba from"wretch";var Le=Ba(),La=(s,e)=>e?(e=JSON.parse(JSON.stringify(e)),s.includes("?")?s+"&"+new URLSearchParams(e).toString():s+"?"+new URLSearchParams(e).toString()):s,A={get:(s,e,t={})=>{let n=La(s,e);return Le.url(n).options(t).get().json()},post:(s,e,t={})=>Le.url(s).options(t).post(e).json(),put:(s,e,t={})=>Le.url(s).options(t).put(e).json(),delete:(s,e={})=>Le.url(s).options(e).delete().json()};var Ua=(u=>(u[u.SUCCESS=9200]="SUCCESS",u[u.SUCCESS_ORIGIN=0]="SUCCESS_ORIGIN",u[u.IDENTITY_VERIFICATION_FAILED=9401]="IDENTITY_VERIFICATION_FAILED",u[u.PERMISSION_DENIED=9403]="PERMISSION_DENIED",u[u.NOT_EXIST=9404]="NOT_EXIST",u[u.REQUEST_LIMIT=9429]="REQUEST_LIMIT",u[u.SERVICE_ERROR=9500]="SERVICE_ERROR",u[u.MISS_REQUESTED_PARAMETER=9900]="MISS_REQUESTED_PARAMETER",u[u.INVALID_PARAMETER=9901]="INVALID_PARAMETER",u.NETWORK_ERROR="ERR_NETWORK",u))(Ua||{}),he=(i=>(i[i.Cook=0]="Cook",i[i.Primed=1]="Primed",i[i.Trench=2]="Trench",i[i.PreBench=3]="PreBench",i[i.Bench=4]="Bench",i))(he||{}),gn=(t=>(t[t.Chainlink=1]="Chainlink",t[t.Pyth=2]="Pyth",t))(gn||{}),bn=(d=>(d[d.Minute1=1]="Minute1",d[d.Minute5=5]="Minute5",d[d.Minute15=15]="Minute15",d[d.Minute30=30]="Minute30",d[d.Hour1=60]="Hour1",d[d.Hour4=240]="Hour4",d[d.Day1=1440]="Day1",d[d.Week1=10080]="Week1",d[d.Month1=40320]="Month1",d))(bn||{}),Ga=(n=>(n[n.Contract=1]="Contract",n[n.Cook=2]="Cook",n[n.Earn=3]="Earn",n))(Ga||{}),qa=(a=>(a[a.All=0]="All",a[a.Contract=1]="Contract",a[a.Cook=2]="Cook",a[a.Earn=3]="Earn",a))(qa||{}),Wa=(t=>(t[t.BlueChips=1]="BlueChips",t[t.Alpha=2]="Alpha",t))(Wa||{}),za=(n=>(n[n.BlueChips=1]="BlueChips",n[n.Alpha=2]="Alpha",n[n.Favorite=3]="Favorite",n))(za||{});var Va=(a=>(a[a.Market=0]="Market",a[a.Limit=1]="Limit",a[a.Stop=2]="Stop",a[a.Conditional=3]="Conditional",a))(Va||{}),$a=(t=>(t[t.Increase=0]="Increase",t[t.Decrease=1]="Decrease",t))($a||{}),Ha=(y=>(y[y.Increase=0]="Increase",y[y.Decrease=1]="Decrease",y[y.AddMargin=2]="AddMargin",y[y.RemoveMargin=3]="RemoveMargin",y[y.CancelOrder=4]="CancelOrder",y[y.ADL=5]="ADL",y[y.Liquidation=6]="Liquidation",y[y.MarketClose=7]="MarketClose",y[y.EarlyClose=8]="EarlyClose",y[y.AddTPSL=9]="AddTPSL",y[y.SecurityDeposit=10]="SecurityDeposit",y[y.TransferToWallet=11]="TransferToWallet",y[y.MarginAccountDeposit=12]="MarginAccountDeposit",y[y.ReferralReward=13]="ReferralReward",y[y.ReferralRewardClaim=14]="ReferralRewardClaim",y))(Ha||{}),Qa=(n=>(n[n.Unknown=0]="Unknown",n[n.GTE=1]="GTE",n[n.LTE=2]="LTE",n))(Qa||{}),Ka=(t=>(t[t.Long=0]="Long",t[t.Short=1]="Short",t))(Ka||{}),Ja=(a=>(a[a.Cancelled=1]="Cancelled",a[a.Expired=2]="Expired",a[a.Successful=9]="Successful",a[a.PartialFilled=8]="PartialFilled",a))(Ja||{}),ja=(d=>(d[d.Market=1]="Market",d[d.Limit=2]="Limit",d[d.TP=3]="TP",d[d.SL=4]="SL",d[d.ADL=5]="ADL",d[d.ADLTrigger=6]="ADLTrigger",d[d.Liquidation=7]="Liquidation",d[d.EarlyClose=8]="EarlyClose",d[d.MarketClose=9]="MarketClose",d))(ja||{}),Ya=(u=>(u[u.Open=0]="Open",u[u.PartialClose=1]="PartialClose",u[u.FullClose=2]="FullClose",u[u.Liquidation=3]="Liquidation",u[u.EarlyClose=4]="EarlyClose",u[u.MarketClose=5]="MarketClose",u[u.ADL=6]="ADL",u[u.TP=7]="TP",u[u.SL=8]="SL",u[u.Increase=9]="Increase",u))(Ya||{}),Xa=(n=>(n[n.MarginAccount=1]="MarginAccount",n[n.WalletAccount=2]="WalletAccount",n[n.ReferralReward=3]="ReferralReward",n))(Xa||{});var Za=(a=>(a[a.EXECUTING=1]="EXECUTING",a[a.BROADCAST_FAILED=2]="BROADCAST_FAILED",a[a.TIMEOUT_CANCEL=3]="TIMEOUT_CANCEL",a[a.EXECUTED=9]="EXECUTED",a))(Za||{});var Cr=async()=>A.get(`${ne()}/openapi/gateway/scan/market/list`);var ne=()=>{let{isTestnet:s,isBetaMode:e}=se?.getConfigManager()?.getConfig()||{};return e?"https://api-beta.myx.finance":s?"https://api-test.myx.cash":"https://api.myx.finance"},ae=async(s,e=[])=>e.length?A.get(`${ne()}/openapi/gateway/quote/price/oracles`,{chainId:s,poolIds:e.join(",")}):Promise.reject(new Error("Invalid pool id")),In=async(s,e)=>await A.get(`${ne()}/openapi/gateway/scan/market/info?chainId=${s}&poolId=${e}`),hn=async(s,e,t)=>await A.get(`${ne()}/openapi/gateway/scan/market/pool-order/open?chainId=${t}`,void 0,{headers:{myx_openapi_access_token:s,myx_openapi_account:e}}),Rr=async({chainId:s,poolIds:e},t)=>A.get(`${ne()}/openapi/gateway/quote/candle/tickers`,{chainId:s,poolIds:e.join(",")}),vr=async({...s})=>A.get(`${ne()}/openapi/gateway/scan/market/base-details`,s),Er=async({...s})=>A.get(`${ne()}/openapi/gateway/scan/market/detail`,s),xn=async()=>A.get(`${ne()}/openapi/gateway/scan/market`);var Se,wt=class wt{constructor(){this.version="1.0.3";Xt(this,Se);console.log("MxSDK version:",this.version)}setConfigManager(e){Zt(this,Se,e)}getConfigManager(){return Yt(this,Se)}setProvider(e){this.provider=e}getProvider(){return this.provider}static getInstance(){return this._instance||(this._instance=new wt),this._instance}async getMarkets(){try{let t=(await xn())?.data||[];return this.Markets=t,t}catch(e){throw e}}};Se=new WeakMap;var ue=wt,An=ue.getInstance(),se=An,es=async s=>{let e=An.getConfigManager();if(!e?.hasSigner())throw new Error("No signer: call auth({ signer }) or auth({ walletClient })");return e.getViemWalletClient(s)};var Cn={USDC:"0x55d398326f99059fF775485246999027B3197955",POOL_MANAGER:"0x13F2130c2F3bfd612BBCBF35FB9E467dd32bAF3A",Account:"0xa32D0550F127fCFF0FA13D21523c5d4a2b86595D",POSITION_MANAGER:"0x93062Ec7Ef0aCf73c877A1d816A6CECc736d018e",ORDER_MANAGER:"0x9438d539e169b72FC2bEC819D4165ABe488921CD",PYTH:"0x4D7E825f80bDf85e913E0DD2A2D54927e9dE1594",ERC20:"0x55d398326f99059fF775485246999027B3197955",LIQUIDITY_ROUTER:"0x06d76c78B56D361de01A8903deA8aCEFFe6251d6",BASE_POOL:"0x59E365A627C5A1CE459e8e3489C97Ab2BEd56FEa",QUOTE_POOL:"0xB1E6df749A602892FafB27bb39Fd4F044527121E",ORACLE:"0xcb0F698f8FC931d97520a61296D0cA05688B8836",EIP7702Delegation:"0xF27e4C5bb5328453C37eD000170a3e16D6C68689",MARKET_MANAGER:"0x7fbEAd5ef0cDb301fe0e5555819f1d99F8a08468",DATA_PROVIDER:"0xD689523Ed33479DC9b5A43bC65568b9240c8D612",ORACLE_RESERVE:"0xaBde34Cb13ab013292576F3C5a0919B65C59CE80",FORWARDER:"0x54aE996239e9ca5d37a8933Df752144279aE266c",TRADING_ROUTER:"0xb2aDa5ebc0641fb81c182C1eF4E4bee0dc0Fef98",REIMBURSEMENT:"0xdE1aB9C84DFB0C2e6965889bDE152bEdD97E305a",DISPUTE_COURT:"0xc35EA4657211315de5270d7d882Ea7161F653368"};var w=s=>{let{isBetaMode:e}=se?.getConfigManager()?.getConfig()||{};switch(s){case 421614:return e?cn:dn;case 59141:return e?mn:ln;case 97:return e?fn:yn;case 56:return Cn;default:return{}}};var Me=s=>s===421614?"0x7e248ec1721639413a280d9e82e2862cae2e6e28":s===59141?"":s===97?"0xe944d7c0f7005a76e898ee3b9ec10479eba9cc02":s===56?"0x8bfc51e1928e91e47c6734983ac018b2fc0adf4e":"";var de=(s,e)=>{let t=g(s);return k({address:e,abi:H,client:t})},Ue=async(s,e)=>{let t=await N(s);return k({address:e,abi:H,client:t})},L=async s=>{let e=await N(s),[t]=await e.getAddresses();return t??void 0},_=async s=>{let e=w(s),t=await N(s);return k({address:e.LIQUIDITY_ROUTER,abi:en,client:t})},me=(s,e=1)=>{let t=w(s),n=e===0?g(s):null;return n?Promise.resolve(k({address:t.POOL_MANAGER,abi:gt,client:n})):N(s).then(a=>k({address:t.POOL_MANAGER,abi:gt,client:a}))};var ie=(s,e=0)=>{let t=w(s),n=e===0?g(s):null;return n?Promise.resolve(k({address:t.QUOTE_POOL,abi:bt,client:n})):N(s).then(a=>k({address:t.QUOTE_POOL,abi:bt,client:a}))},Z=(s,e=0)=>{let t=w(s),n=e===0?g(s):null;return n?Promise.resolve(k({address:t.BASE_POOL,abi:It,client:n})):N(s).then(a=>k({address:t.BASE_POOL,abi:It,client:a}))},V=async(s,e)=>{let t=await N(s);return k({address:e,abi:O,client:t})},re=(s,e)=>k({address:s,abi:O,client:e}),xe=(s,e)=>{let t=g(s);return k({address:e,abi:O,client:t})};var wn=(s,e,t=0)=>{let n=t===0?g(s):null;return n?Promise.resolve(k({address:e,abi:ht,client:n})):N(s).then(a=>k({address:e,abi:ht,client:a}))},oe=(s,e=0)=>{let t=w(s),n=e===0?g(s):null;return n?Promise.resolve(k({address:t.MARKET_MANAGER,abi:xt,client:n})):N(s).then(a=>k({address:t.MARKET_MANAGER,abi:xt,client:a}))},Ae=(s,e=0)=>{let t=w(s),n=e===0?g(s):null;return n?Promise.resolve(k({address:t.DATA_PROVIDER,abi:At,client:n})):N(s).then(a=>k({address:t.DATA_PROVIDER,abi:At,client:a}))},Pt=async s=>{let e=w(s),t=await N(s);return k({address:e.Account,abi:ke,client:t})},F=(s,e=0)=>{let t=w(s),n=e===0?g(s):null;return n?Promise.resolve(k({address:t.FORWARDER,abi:ve,client:n})):N(s).then(a=>k({address:t.FORWARDER,abi:ve,client:a}))},Pn=(s,e=0)=>{let t=w(s),n=e===0?g(s):null;return n?Promise.resolve(k({address:t.REIMBURSEMENT,abi:Ct,client:n})):N(s).then(a=>k({address:t.REIMBURSEMENT,abi:Ct,client:a}))},Tn=(s,e=0)=>{let t=w(s),n=e===0?g(s):null;return n?Promise.resolve(k({address:t.DISPUTE_COURT,abi:Ee,client:n})):N(s).then(a=>k({address:t.DISPUTE_COURT,abi:Ee,client:a}))};import{ErrorType as Rn,ErrorDecoder as ts}from"ethers-decode-error";var Ce={"0xfa52dfc0":"AccountInsufficientFreeAmount()","0xe2a1a260":"AccountInsufficientReservedAmount()","0xffd10028":"AccountInsufficientTradableAmount(uint256,uint256)","0x9996b315":"AddressEmptyCode(address)","0x4c9c8ce3":"ERC1967InvalidImplementation(address)","0xb398979f":"ERC1967NonPayable()","0xd6bda275":"FailedCall()","0xf92ee8a9":"InvalidInitialization()","0x44d3438f":"NotAddressManager()","0x3fc81f20":"NotDependencyManager()","0xd7e6bcf8":"NotInitializing()","0x507f487a":"NotProxyAdmin()","0xe03f6024":"PermissionDenied(address,address)","0x5274afe7":"SafeERC20FailedOperation(address)","0xe07c8dba":"UUPSUnauthorizedCallContext()","0xaa1d49a4":"UUPSUnsupportedProxiableUUID(bytes32)","0x24775e06":"SafeCastOverflowedUintToInt(uint256)","0xba767932":"ConvertAmountMismatch(uint256,uint256)","0xd93c0665":"EnforcedPause()","0x8dfc202b":"ExpectedPause()","0x059e2f49":"InRewindMode()","0x42301c23":"InsufficientOutputAmount()","0xcaa99aac":"MismatchExecuteFee(uint256,uint256,uint256)","0x8637dfc0":"NotInRewindMode()","0x4578ddb8":"OnlyRelayer()","0x1e4fbdf7":"OwnableInvalidOwner(address)","0x118cdaa7":"OwnableUnauthorizedAccount(address)","0x3ee5aeb5":"ReentrancyGuardReentrantCall()","0x90b8ec18":"TransferFailed()","0xbe1af266":"InternalOnly()","0x3385aa1f":"ExceedOrderSize(uint256)","0xb07e3bc4":"InsufficientCollateral(uint256,uint256)","0x613970e0":"InvalidParameter()","0x27d08510":"NotActiveBroker(address)","0xf6412b5a":"NotOrderOwner()","0x70d645e3":"NotPositionOwner()","0xe75316c6":"OrderNotExist(OrderId)","0xba01b06f":"PoolNotActive(PoolId)","0xddefae28":"AlreadyMinted()","0x64283d7b":"ERC721IncorrectOwner(address,uint256,address)","0x177e802f":"ERC721InsufficientApproval(address,uint256)","0xa9fbf51f":"ERC721InvalidApprover(address)","0x5b08ba18":"ERC721InvalidOperator(address)","0x89c62b64":"ERC721InvalidOwner(address)","0x64a0ae92":"ERC721InvalidReceiver(address)","0x73c6ac6e":"ERC721InvalidSender(address)","0x7e273289":"ERC721NonexistentToken(uint256)","0xb4762117":"ExceedMaxLeverage(PositionId)","0x29143a42":"ExceedPositionSize()","0x8ea9158f":"InvalidPosition(PositionId)","0xa5afd143":"PositionNotHealthy(PositionId,uint256)","0xba0d3752":"PositionNotInitialized(PositionId)","0xc20f35b7":"UnderflowOI()","0xf4d678b8":"InsufficientBalance()","0x6aee3c1a":"InsufficientRiskReserves()","0x2c5211c6":"InvalidAmount()","0x82cb17ef":"InvalidSplitConfig()","0xe921c36b":"AlreadyMigrated(PositionId,PositionId)","0xd34e366f":"ExceedBaseCollateral(uint256,uint256)","0xc7544914":"ExceedDebt(uint256,uint256)","0xe7aa687a":"ExceedExchangeable()","0x4b3c8f33":"ExceedMaxBaseProfit()","0xdc82bd68":"ExceedMinOutputAmount()","0xdb42144d":"InsufficientBalance(address,uint256,uint256)","0x5646203f":"InsufficientCollateral(PositionId,uint256)","0x9ac13039":"InsufficientPoolProfit()","0x14be833f":"InsufficientReturnAmount(uint256,uint256)","0x419ecd12":"MatchNotSupported()","0x4ec4fd74":"PoolFundingFeeNotPositive(int256,uint256,Direction)","0xba8f5df5":"PoolNotCompoundable(PoolId)","0xf645eedf":"ECDSAInvalidSignature()","0xfce698f7":"ECDSAInvalidSignatureLength(uint256)","0xd78bce0c":"ECDSAInvalidSignatureS(bytes32)","0x48834bee":"ExpiredFeeData()","0x56d69198":"InvalidFeeRate()","0x80577032":"NoRebateToClaim()","0x6e6b79b0":"NotBrokerSigner(address)","0xff70343d":"UnsupportedAssetClass(AssetClass)","0x185676be":"UnsupportedFeeTier(uint8)","0x60b25fe4":"BrokerAlreadyExists()","0x7eb4a674":"BrokerNotFound()","0x8c3b5bf0":"NotBrokerAdmin()","0x3733548a":"InvalidFeeTier()","0x192105d7":"InitializationFunctionReverted(address,bytes)","0x97c7f537":"ExcessiveSlippage()","0x700deaad":"InvalidADLPosition(OrderId,PositionId)","0xf64fa6a8":"InvalidOrder(OrderId)","0xd4944235":"NoADLNeeded(OrderId)","0xe079169e":"NotReachedPrice(OrderId,uint256,uint256,TriggerType)","0xc60eb335":"OnlyKeeper()","0xa8ce4432":"SafeCastOverflowedIntToUint(int256)","0x17229ec4":"NotMeetEarlyCloseCriteria(PositionId)","0x0dc149f0":"AlreadyInitialized()","0x7a5c919f":"InvalidRewindPrice()","0xc53f84e7":"PositionRemainsHealthy(PositionId)","0x1dab59cf":"InvalidOrderPair(OrderId,OrderId)","0x230e8e43":"PoolNotInPreBenchState(PoolId)","0x107dec14":"RiskCloseNotAllowed()","0x664431a8":"NotAllowedTarget(address)","0x03357c6c":"ExceedsMaximumRelayFee()","0x0d10f63b":"InconsistentParamsLength()","0x38802743":"InsufficientFeeAllowance(address,uint256,uint256)","0xd95b4ad5":"InsufficientFeeBalance(address,uint256,uint256)","0xa3972305":"MismatchedSender(address)","0xc3b80e86":"RelayerRegistered(address)","0xee0844a3":"RemoveRelayerFailed()","0xc583a8da":"IncorrectFee(uint256)","0x00bfc921":"InvalidPrice()","0x148cd0dd":"VerifyPriceFailed()","0xb12d13eb":"ETHTransferFailed()","0xa83325d4":"PoolOracleFeeCharged()","0x6b75f90d":"PoolOracleFeeNotCharged()","0x42a0e2a7":"PoolOracleFeeNotExisted()","0x8ee01e1c":"PoolOracleFeeNotSoldOut()","0x5e0a829b":"ETHTransferFailed(address,uint256)","0x4ba6536f":"GasLimitExceeded(address,uint256,uint256)","0xca1aae4b":"GasLimitNotSet(address)","0x3728b83d":"InvalidAmount(uint256)","0x3484727e":"BaseFeeNotSoldOut()","0x0251bde4":"LPNotFullyMinted()","0x1acb203e":"PositionNotEmpty()","0x2be7b24b":"UnexpectedPoolState()","0x759b3876":"UnhealthyAfterRiskTierApplied(PositionId)","0x7bd42a2e":"NotEmptyAddress()","0x6697b232":"AccessControlBadConfirmation()","0xe2517d3f":"AccessControlUnauthorizedAccount(address,bytes32)","0x7c9a1cf9":"AlreadyVoted()","0x796ea3a6":"BondNotReleased()","0x6511c20d":"BondZeroAmount()","0xf38e5973":"CaseAppealNotFinished()","0x1eaa4a59":"CaseDeadlineNotReached()","0xe6c67e3a":"CaseDeadlineReached()","0x0fc957b1":"CaseNotAccepted()","0x3ddb819d":"CaseNotExist(CaseId)","0x79eab18d":"CaseRespondentAppealed(CaseId,address)","0xa179f8c9":"ChainIdMismatch()","0x311c16d3":"DisputeNotAllowed()","0x752d88c0":"InvalidAccountNonce(address,uint256)","0xa710429d":"InvalidContractAddress()","0x8076dd8a":"InvalidFunctionSignature()","0xc37906a0":"InvalidPayloadLength(uint256,uint256)","0xdcdedda9":"InvalidPoolToken()","0x3471a3c2":"InvalidProfitAmount()","0x1d9617a0":"InvalidResponseVersion()","0x9284b197":"InvalidSourceChain()","0xb9021668":"NoChainResponse()","0xc546bca4":"NotCaseRespondent(CaseId,address)","0x84ae4a30":"NumberOfResponsesMismatch()","0x02164961":"RequestTypeMismatch()","0x4cf72652":"RiskCloseNotCompleted()","0x0819bdcd":"SignatureExpired()","0xc00ca938":"UnexpectedCaseState()","0x7935e939":"UnexpectedCaseType()","0x5e7bd6ec":"UnexpectedNumberOfResults()","0x51ee5853":"UnsupportedQueryType(uint8)","0x29ca666b":"UntrustfulVoting()","0x439cc0cd":"VerificationFailed()","0x714f5513":"VersionMismatch()","0x96b8e05b":"WrongQueryType(uint8,uint8)","0xbb6b170d":"ZeroQueries()","0xa9214540":"AlreadyClaimed(CaseId,address)","0xd4ac59c1":"InvalidAmount(CaseId,address)","0x7a6f5328":"MerkleTreeVerificationFailed(CaseId,address)","0x094a5cfe":"ReimbursementValidity(CaseId)","0x8b922563":"TreeAlreadySet()","0x7b27120a":"InDisputeMode()","0xb04111ef":"InsufficientFreeCollateral(PositionId,uint256)","0x12f1b11a":"InsufficientLockedCollateral(PositionId,uint256)","0x6dfcc650":"SafeCastOverflowedUintDowncast(uint8,uint256)","0xd24b47fb":"UserProfitFrozen()","0x1c151780":"ExceedMinOutput(uint256,uint256)","0xe1f0493d":"NotAllowedCaller(address)","0xfb8f41b2":"ERC20InsufficientAllowance(address,uint256,uint256)","0xe450d38c":"ERC20InsufficientBalance(address,uint256,uint256)","0xe602df05":"ERC20InvalidApprover(address)","0xec442f05":"ERC20InvalidReceiver(address)","0x96c6fd1e":"ERC20InvalidSender(address)","0x94280d62":"ERC20InvalidSpender(address)","0x62791302":"ERC2612ExpiredSignature(uint256)","0x4b800e46":"ERC2612InvalidSigner(address,address)","0xb3512b0c":"InvalidShortString()","0x305a27a9":"StringTooLong(string)","0xfd0f789d":"ExceedMaxPriceDeviation()","0x407b87e5":"ExchangeRateAlreadyApplied()","0x5c6c5686":"ExchangeRateAlreadyDisabled()","0x1ae17fcd":"InvalidDeviationRatio()","0x18b88897":"InvalidUpdateFee()","0xf76740e3":"PriceDeviationBelowMinimum()","0x49386283":"PriceDeviationThresholdReached()","0x19abf40e":"StalePrice()","0xe351cd13":"ExceedMaxExchangeableAmount()","0x15912a6f":"NotSupportVersion()","0xf1364a74":"ArrayEmpty()","0x15ed381d":"ExceedMaxProfit()","0x51aeee6c":"PoolNotExist(PoolId)","0x70f6c197":"InvalidQuoteTokenAddress()","0x0b8457f4":"InvalidRatioParams()","0x29dae146":"MarketAlreadyExisted()","0xf040b67a":"MarketNotExisted()","0x0e442a4a":"InvalidBaseToken()","0x24e219c7":"MarketNotExist(MarketId)","0xcc36f935":"PoolExists(PoolId)","0xe84c308d":"ExceedBaseReserved(uint256,uint256)","0x3e241751":"ExceedQuoteReserved(uint256,uint256)","0xde656889":"ExceedReservable(uint256,uint256,uint256)","0xd54d0fc4":"InsufficientLiquidity(uint256,uint256,uint256)","0x7e562a65":"InvalidDistributionAmount()","0x83c7580d":"ReservableNotEnough(uint256,uint256)","0x94eef58a":"ERC2771ForwarderExpiredRequest(uint48)","0xc845a056":"ERC2771ForwarderInvalidSigner(address,address)","0x70647f79":"ERC2771ForwarderMismatchedValue(uint256,uint256)","0xd2650cd1":"ERC2771UntrustfulTarget(address,address)","0xcf479181":"InsufficientBalance(uint256,uint256)","0x4c150d8f":"DifferentMarket(PoolId,PoolId)","0xaa98b06a":"InsufficientQuoteIn(uint256,uint256,uint256)","0x3e589bee":"InvalidLiquidityAmount()","0xaebd3617":"InvalidTpsl(uint256)","0x7fe81129":"SamePoolMigration(PoolId)","0x71c4efed":"SlippageExceeded(uint256,uint256)","0x62b9bc7b":"DesignatedTokenMismatch(address,address)","0x49465eb0":"NotForwardAllowedTarget(address)","0x301b6707":"ExecutionFeeNotCollected()","0xc6e8248a":"InsufficientSize()","0xd15b4fe2":"InvalidQuoteToken()","0xd8daec7c":"MarketNotInitialized()","0xcd4891b6":"NotInDisputeMode()","0x1ad308dc":"OrderExpired(OrderId)","0x486aa307":"PoolNotInitialized()"};var ns=ts.create();var D={1:"Invalid Chain",2:"Invalid Token Address",4001:"User Rejected",3:"Insufficient Balance",4:"Insufficient Amount Of Approved",4002:"Invalid Base Token Address",4003:"Invalid Slippage",4004:"Invalid Amount",4005:"Invalid Pool State",4006:"Invalid Params",4007:"Invalid Amount Withdrawable LP Amount"};function as(s){return s?.code===4001}async function h(s){if(as(s))return{error:D[4001]};let e=await ns.decode(s);if(console.log(e),e.type===Rn.UserRejectError||e.name==="ACTION_REJECTED")return{error:D[4001]};if(e.type===Rn.CustomError){let t=Object.keys(Ce).find(n=>n.toLowerCase()===e.selector.toLowerCase());return t?{error:{code:t,message:Ce[t]}}:{error:{code:s?.code,message:s?.reason||e.reason||s.message}}}return{error:{code:e.type,message:e.reason}}}var vn=async(s,e,t)=>{try{return await g(s).readContract({address:t,abi:H,functionName:"balanceOf",args:[e]})}catch(n){throw console.error(n),n}};import{maxUint256 as ss,parseUnits as is}from"viem";var En=async(s,e,t,n,a)=>{try{return await g(s).readContract({address:t,abi:H,functionName:"allowance",args:[e,n]})>=a}catch(i){throw i}};var kn=async(s,e,t,n,a)=>{try{let i=await Ue(s,t);if(!i.write)throw new Error("Wallet client required for write");let r=await i.write.approve([n,a]);await g(s).waitForTransactionReceipt({hash:r})}catch(i){throw i}};var T=async s=>{if("chainId"in s&&!_e(s.chainId))throw new Error(D[1]);if("slippage"in s&&!(Number(s?.slippage)<=1&&Number(s?.slippage)>0))throw new Error(D[4003]);if("amount"in s&&(Number(s.amount)===Number.NaN||Number(s.amount)<0))throw new Error(D[4004]);let{tokenAddress:e,contractAddress:t,chainId:n,amount:a,decimals:i,account:r}=s;if(a&&n&&Number(i)>=0&&r){let o=is(a.toString(),Number(i));if(e){let p=await vn(n,r,e);if(!p||p<o)throw new Error(D[3])}t&&e&&(await En(n,r,e,t,o)||await kn(n,r,e,t,ss))}};import{parseUnits as Tt}from"viem";var S=30,W=18;var v=(s,e)=>BigInt(s)*Tt(e.toString(),8)/BigInt(10**8),E=async s=>{try{let e=C[s],n=await g(s).getGasPrice();if(n==null)throw new Error("Network Error");return{gasPrice:v(n,e.gasPriceRatio)}}catch(e){throw e}},ee=(s,e=.01)=>{let t=Tt("1",8)-Tt(e.toString(),8);return s*t/BigInt(10**8)};import{isNil as rs}from"lodash-es";var Sn=async(s,e)=>await Promise.all(e.map(async n=>{let{publishTime:a,vaa:i,oracleType:r,nativeFee:o,price:p,poolId:d}=n,u=rs(o)?1n:BigInt(o);return{poolId:d,price:p,value:u,publishTime:a,oracleType:r??2,vaa:i}})),we=async(s,e)=>{if(!e||!e.length)return;let t=await ae(s,e);return await Sn(s,t.data)},z=async(s,e)=>{if(!e)return;let n=(await ae(s,[e]))?.data?.[0];if(!n)throw new Error(`Unable to get price for ${e} in the deposit`);return(await Sn(s,[n]))?.[0]};var Mn=async s=>{try{let{chainId:e,poolId:t}=s,n=C[e],a=await L(e);await T({account:a,chainId:e});let i=await we(e,[t]);if(!i)return;let r=i.map(f=>f.value),o=i.map(f=>({poolId:t,oracleUpdateData:f?.vaa??"0",publishTime:f.publishTime,oracleType:f.oracleType})),p={prices:o,values:r,poolId:t,recipient:a},d=await _(e),u=await d.estimateGas.claimBasePoolRebate([o,t,a],{value:r[0]}),m=v(u,n.gasLimitRatio),{gasPrice:l}=await E(e);return await d.write.claimBasePoolRebate([o,t,a],{gasLimit:m,gasPrice:l,value:r[0]})}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}},Dn=async s=>{try{let{chainId:e,poolIds:t}=s;if(t.length===0)return;let n=C[e],a=await L(e);await T({account:a,chainId:e});let i=await we(e,t);if(!i)return;let r=i.map(I=>({poolId:I.poolId,oracleUpdateData:I?.vaa??"0",publishTime:I.publishTime,oracleType:I.oracleType})),p=i.map(I=>I.value).reduce((I,x)=>x+I,0n),d={prices:r,poolIds:t,value:p,recipient:a},u=await _(e),m=await u.estimateGas.claimBasePoolRebates([r,t,a],{value:p}),l=v(m,n.gasLimitRatio),{gasPrice:c}=await E(e),f=await u.write.claimBasePoolRebates([r,t,a],{gasLimit:l,gasPrice:c,value:p});return await g(e).waitForTransactionReceipt({hash:f})}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}};import{parseUnits as _n}from"viem";import{parseUnits as On}from"viem";var Rt=async({chainId:s,amountIn:e,poolId:t,price:n=0n})=>{try{let a=C[s];return await(await Z(s)).read.previewLpAmountOut([t,e,n])}catch(a){throw console.error(a),typeof a=="string"?a:await h(a)}},vt=async({chainId:s,amountIn:e,poolId:t,price:n=0n})=>{try{let a=C[s];return await(await Z(s)).read.previewBaseAmountOut([t,e,n])}catch(a){throw console.error(a),typeof a=="string"?a:await h(a)}},Fn=async({chainId:s,account:e,poolId:t,amount:n=0})=>{try{if(!s||!e||!t)return;if(!n)return{baseAmountOut:0n,rebateAmount:0n};let a=C[s],i=18;await T({decimals:i,account:e,chainId:s,amount:Number(n)});let r=On(n.toString(),i),p=(await ae(s,[t])).data?.[0]?.price||"0",d=On(p,30),m=await(await Z(s)).read.previewUserWithdrawData([t,r,e,d]),{baseAmountOut:l,rebateAmount:c}=m;return{baseAmountOut:l,rebateAmount:c}}catch(a){throw typeof a=="string"?a:await h(a)}};var U=async(s,e)=>{try{return!s||!e?void 0:(await In(s,e)).data}catch(t){throw typeof t=="string"?t:await h(t)}};import{parseUnits as Et}from"viem";function Nn(s){return s.includes(".")?s.split(".")[1].length:0}var Pe=(s=.01,e=[],t=18,n)=>{if(e.length===0)return[];if(e.filter(i=>i.amount&&i.triggerPrice&&i.triggerType).length===0)throw new Error(D[4006]);return e.map(i=>{let r=Et(i.amount.toString(),t),o=Et(i.triggerPrice.toString(),30),p=Nn(i.triggerPrice.toString()),d=Et(i.triggerPrice.toString(),p),u=ee(r*d*BigInt(10**n)/BigInt(10**(p+t)),s);return{amount:r,triggerPrice:o,triggerType:BigInt(i.triggerType),minQuoteOut:u}})};var Bn=async s=>{try{let{poolId:e,chainId:t,amount:n,slippage:a=.01,tpsl:i=[]}=s;await T(s);let r=await U(t,e);if(!r)throw new Error(D[4006]);let o=r?.baseDecimals,p=r?.quoteDecimals,d=r?.baseToken,u=C[t],m=await L(t),c=w(t).BASE_POOL;await T({tokenAddress:d,contractAddress:c,decimals:o,account:m,chainId:t,amount:n});let f=!(Number(r?.state)===0||Number(r?.state)===1),y=[],I=_n(n.toString(),o),x=0n,P;if(f){let Y=await z(t,e);if(!Y)return;let Ia=_n(Y.price,30);y.push({poolId:e,oracleUpdateData:Y.vaa,publishTime:BigInt(Y.publishTime),oracleType:Y.oracleType}),P=await Rt({chainId:t,poolId:e,amountIn:I,price:Ia}),x=Y.value}else P=await Rt({chainId:t,poolId:e,amountIn:I});let M=i.map(Y=>({amount:n,triggerPrice:Y.triggerPrice,triggerType:Y.triggerType})),B=Pe(a,M,o,p),G={poolId:e,amountIn:I,minAmountOut:ee(P,a),recipient:m,tpslParams:B},R=await _(t),q=await R.estimateGas.depositBase([y,G],{value:x}),X=v(q,u.gasLimitRatio),{gasPrice:le}=await E(t),be=await R.write.depositBase([y,G],{gasLimit:X,gasPrice:le,value:x});return await g(t).waitForTransactionReceipt({hash:be})}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}};import{parseUnits as Ge}from"viem";var Ln=async s=>{try{let{chainId:e,poolId:t,price:n}=s,a=n,i=await Z(e);if(typeof n>"u"||n===null)try{let o=await z(e,t);a=Ge(o?.price||"0",30)}catch{a=Ge("0",30)}return await i.read.withdrawableLpAmount([t,a||0n])}catch(e){throw typeof e=="string"?e:await h(e)}},Un=async s=>{try{let{chainId:e,poolId:t,amount:n,slippage:a=.01}=s,i=await U(e,t),r=i?.basePoolToken,o=C[e],p=await L(e),d=18;await T({tokenAddress:r,decimals:d,account:p,chainId:e,amount:n});let u=Ge(n.toString(),d),m=!(Number(i?.state)===0||Number(i?.state)===1),l=[],c=0n,f;if(m){let R=await z(e,t);if(!R)return;let q=Ge(R.price,30);l.push({poolId:t,oracleUpdateData:R.vaa,publishTime:BigInt(R.publishTime),oracleType:R.oracleType}),f=await vt({chainId:e,poolId:t,amountIn:u,price:q}),c=R.value}else f=await vt({chainId:e,poolId:t,amountIn:u});let y={poolId:t,amountIn:u,minAmountOut:ee(f,a),recipient:p},I=await _(e),x=await I.estimateGas.withdrawBase([l,y],{value:c}),P=v(x,o.gasLimitRatio),{gasPrice:M}=await E(e),B=await I.write.withdrawBase([l,y],{gasLimit:P,gasPrice:M,value:c});return await g(e).waitForTransactionReceipt({hash:B})}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}};import{parseUnits as os}from"viem";var Gn=async s=>{try{let{chainId:e,account:t,poolId:n}=s;if(!e||!t||!n)return;let a=C[e],i=0n,o=(await ae(e,[n])).data?.[0]?.price||"0",p=os(o,30),u=await(await Z(e)).read.pendingUserRebates([n,t,p]);return{rebates:u?.rebates,genesisRebates:u?.genesisRebates}}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}};import{parseUnits as ps}from"viem";var qn=async(s,e)=>{if(e)try{let t=await Z(s),n=0n,a=await z(s,e);return a?.price&&(n=ps(a.price,30)),await t.read.getPoolTokenPrice([e,n])}catch(t){throw typeof t=="string"?t:await h(t)}};var Dt={};mt(Dt,{claimQuotePoolRebate:()=>Kn,claimQuotePoolRebates:()=>Jn,deposit:()=>zn,getLpPrice:()=>jn,getRewards:()=>Qn,transfer:()=>Hn,withdraw:()=>$n,withdrawableLpAmount:()=>Vn});import{parseUnits as Wn}from"viem";var St=async({chainId:s,amountIn:e,poolId:t,price:n=0n})=>{try{let a=C[s];return await(await ie(s)).read.previewLpAmountOut([t,e,n])}catch(a){throw console.error(a),typeof a=="string"?a:await h(a)}},Mt=async({chainId:s,amountIn:e,poolId:t,price:n=0n})=>{try{let a=C[s];return await(await ie(s)).read.previewQuoteAmountOut([t,e,n])}catch(a){throw console.error(a),typeof a=="string"?a:await h(a)}};var zn=async s=>{try{let{poolId:e,chainId:t,amount:n,slippage:a=.01,tpsl:i=[]}=s;await T(s);let r=await U(t,e);if(!r)throw new Error(D[4006]);let o=C[t],p=await L(t),u=w(t).QUOTE_POOL,m=r.quoteToken,l=r?.quoteDecimals;await T({tokenAddress:m,contractAddress:u,decimals:l,account:p,chainId:t,amount:n});let c=Wn(n.toString(),l),f=!(Number(r?.state)===0||Number(r?.state)===1),y=[],I=0n,x;if(f){let j=await z(t,e);if(!j)return;let Y=Wn(j.price,30);y.push({poolId:e,oracleUpdateData:j.vaa,publishTime:BigInt(j.publishTime),oracleType:j.oracleType}),x=await St({chainId:t,poolId:e,amountIn:c,price:Y}),I=j.value}else x=await St({chainId:t,poolId:e,amountIn:c});let P=i.map(j=>({amount:n,triggerPrice:j.triggerPrice,triggerType:j.triggerType})),M=Pe(a,P,l,l),B={poolId:e,amountIn:c,minAmountOut:ee(x,a),recipient:p,tpslParams:M},G=await _(t),R=await G.estimateGas.depositQuote([y,B],{value:I}),q=v(R,o.gasLimitRatio),{gasPrice:X}=await E(t),le=await G.write.depositQuote([y,B],{gasLimit:q,gasPrice:X,value:I});return await g(t).waitForTransactionReceipt({hash:le})}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}};import{parseUnits as qe}from"viem";var Vn=async s=>{try{let{chainId:e,poolId:t,price:n}=s,a=n,i=await ie(e);if(typeof n>"u"||n===null)try{let o=await z(e,t);a=qe(o?.price||"0",30)}catch{a=qe("0",30)}return await i.read.withdrawableLpAmount([t,a||0n])}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}},$n=async s=>{try{let{chainId:e,poolId:t,amount:n,slippage:a=.01}=s,i=await U(e,t),r=i?.quotePoolToken,o=C[e],p=await L(e),d=18;await T({tokenAddress:r,decimals:d,account:p,chainId:e,amount:n});let u=qe(n.toString(),d),m=!(Number(i?.state)===0||Number(i?.state)===1),l=[],c=0n,f;if(m){let R=await z(e,t);if(!R)return;let q=qe(R.price,30);l.push({poolId:t,oracleUpdateData:R.vaa,publishTime:BigInt(R.publishTime),oracleType:R.oracleType}),f=await Mt({chainId:e,poolId:t,amountIn:u,price:q}),c=R.value}else f=await Mt({chainId:e,poolId:t,amountIn:u});let y={poolId:t,amountIn:u,minAmountOut:ee(f,a),recipient:p},I=await _(e),x=await I.estimateGas.withdrawQuote([l,y],{value:c}),P=v(x,o.gasLimitRatio),{gasPrice:M}=await E(e),B=await I.write.withdrawQuote([l,y],{gasLimit:P,gasPrice:M,value:c});return await g(e).waitForTransactionReceipt({hash:B})}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}};import{parseUnits as us}from"viem";var Hn=async(s,e,t,n)=>{try{let a=await U(s,e),i=await U(s,t);if(!i||!a)return null;if([3,4].includes(i.state))throw new Error(D[4005]);let r=await L(s),o=C[s],p=18;await T({chainId:s,amount:n,account:r,decimals:p,tokenAddress:a.quotePoolToken});let d={fromPoolId:e,toPoolId:t,minLpOut:0n,amount:us(n.toString(),p)},u=await _(s),m=await u.estimateGas.migrateLiquidity([d]),l=v(m,o.gasLimitRatio),{gasPrice:c}=await E(s),f=await u.write.migrateLiquidity([d],{gasLimit:l,gasPrice:c});return await g(s).waitForTransactionReceipt({hash:f})}catch(a){throw typeof a=="string"?a:await h(a)}};import{parseUnits as ds}from"viem";var Qn=async s=>{try{let{chainId:e,account:t,poolId:n}=s;if(!e||!t||!n)return;let a=C[e],r=(await ae(e,[n])).data?.[0]?.price||"0",o=ds(r,30);return await(await ie(e)).read.pendingUserRebates([n,t,o])}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}};var Kn=async s=>{try{let{chainId:e,poolId:t}=s,n=C[e],a=await L(e),i=18;await T({account:a,chainId:e});let r=await we(e,[t]);if(!r)return;let o=r.map(y=>y.value),p=r.map(y=>({poolId:y.poolId,oracleUpdateData:y?.vaa??"0",publishTime:y.publishTime,oracleType:y.oracleType})),d={prices:p,values:o,poolId:t,recipient:a},u=await _(e),m=await u.estimateGas.claimQuotePoolRebate([p,t,a],{value:o[0]}),l=v(m,n.gasLimitRatio),{gasPrice:c}=await E(e);return await u.write.claimQuotePoolRebate([p,t,a],{gasLimit:l,gasPrice:c,value:o[0]})}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}},Jn=async s=>{try{let{chainId:e,poolIds:t}=s;if(t.length===0)return;let n=C[e],a=await L(e),i=18;await T({account:a,chainId:e});let r=await we(e,t);if(!r)return;let o=r.map(x=>({poolId:x.poolId,oracleUpdateData:x?.vaa??"0",publishTime:x.publishTime,oracleType:x.oracleType})),d=r.map(x=>x.value).reduce((x,P)=>P+x,0n),u={prices:o,value:d,poolIds:t,recipient:a},m=await _(e),l=await m.estimateGas.claimQuotePoolRebates([o,t,a],{value:d}),c=v(l,n.gasLimitRatio),{gasPrice:f}=await E(e),y=await m.write.claimQuotePoolRebates([o,t,a],{gasLimit:c,gasPrice:f,value:d});return await g(e).waitForTransactionReceipt({hash:y})}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}};import{parseUnits as cs}from"viem";var jn=async(s,e)=>{if(e)try{let t=await ie(s),n=0n,a=await z(s,e);return a?.price&&(n=cs(a.price,30)),await t.read.getPoolTokenPrice([e,n])}catch(t){throw console.error(t),typeof t=="string"?t:await h(t)}};var Ot={};mt(Ot,{getMarket:()=>Yn,getOracleFee:()=>Xn});var Yn=async(s,e)=>{try{return await T({chainId:s}),e?await(await oe(s)).read.getMarket([e]):void 0}catch(t){throw console.error(t),typeof t=="string"?t:await h(t)}};var Xn=async(s,e)=>{try{return await T({chainId:s}),e?await(await oe(s)).read.getOracleFee([e]):void 0}catch(t){throw console.error(t),typeof t=="string"?t:await h(t)}};var Oe=async({chainId:s,baseToken:e,marketId:t})=>{try{if(!e)throw new Error(D[2]);let n=w(s),a=await me(s,0),i=[t,e],r=await a.read.getMarketPool(i);return r.poolId==="0x0000000000000000000000000000000000000000000000000000000000000000"||!r.poolId?void 0:r.poolId}catch(n){throw console.error(n),typeof n=="string"?n:await h(n)}},Nt=async s=>{try{return await(await me(s)).read.getPools()||[]}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}},_t=async(s,e,t=0n)=>{try{let a=await(await Ae(s)).read.getPoolInfo([e,t]);return{quotePool:{poolToken:a.quotePool.poolToken,exchangeRate:a.quotePool.exchangeRate,poolTokenPrice:a.quotePool.poolTokenPrice,poolTokenSupply:a.quotePool.poolTokenSupply,totalDebt:a.quotePool.totalDebt,baseCollateral:a.quotePool.baseCollateral},basePool:{poolToken:a.basePool.poolToken,exchangeRate:a.basePool.exchangeRate,poolTokenPrice:a.basePool.poolTokenPrice,poolTokenSupply:a.basePool.poolTokenSupply,totalDebt:a.basePool.totalDebt,baseCollateral:a.basePool.baseCollateral},reserveInfo:{baseTotalAmount:a.reserveInfo.baseTotalAmount,baseReservedAmount:a.reserveInfo.baseReservedAmount,quoteTotalAmount:a.reserveInfo.quoteTotalAmount,quoteReservedAmount:a.reserveInfo.quoteReservedAmount},fundingInfo:{nextFundingRate:a.fundingInfo.nextFundingRate,lastFundingFeeTracker:a.fundingInfo.lastFundingFeeTracker,nextEpochTime:a.fundingInfo.nextEpochTime},ioTracker:{tracker:a.oi.tracker,longSize:a.oi.longSize,shortSize:a.oi.shortSize,poolEntryPrice:a.oi.poolEntryPrice},liquidityInfo:{windowCaps:a.liquidityInfo.windowCaps,openInterest:a.liquidityInfo.openInterest}}}catch(n){throw console.error(n),typeof n=="string"?n:await h(n)}};var Bt=async({chainId:s,baseToken:e,marketId:t})=>{try{if(!e)throw new Error(D[2]);let n=C[s],a=await me(s),i={marketId:t,baseToken:e},r=await a.estimateGas.deployPool([i]),o=v(r,n.gasLimitRatio),{gasPrice:p}=await E(s),d=await a.write.deployPool([i],{gasLimit:o,gasPrice:p});if(await g(s).waitForTransactionReceipt({hash:d}))return await Oe({chainId:s,baseToken:e,marketId:t})}catch(n){throw typeof n=="string"?n:await h(n)}};var Lt=async(s,e,t)=>{try{return await(await wn(s,e)).read.userGenesisShare([t])}catch(n){throw console.error(n),typeof n=="string"?n:await h(n)}};var Ut=async s=>{try{let{chainId:e,poolId:t,poolType:n,slippage:a=.01,tpsl:i=[]}=s;await T(s);let r=await U(e,t);if(!r)throw new Error(D[4006]);let o=18,p=r.quoteDecimals,d=Pe(a,i,o,p),u=C[e],m=await _(e),l={poolId:t,poolType:BigInt(n),tpslParams:d},c=await m.estimateGas.addTpsl([l]),f=v(c,u.gasLimitRatio),{gasPrice:y}=await E(e),I=await m.write.addTpsl([l],{gasLimit:f,gasPrice:y});return await g(e).waitForTransactionReceipt({hash:I})}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}};var Gt=async s=>{try{let{chainId:e,orderId:t}=s;await T(s);let n=C[e],a=await _(e),i=await a.estimateGas.cancelTpsl([t]),r=v(i,n.gasLimitRatio),{gasPrice:o}=await E(e),p=await a.write.cancelTpsl([t],{gasLimit:r,gasPrice:o});return await g(e).waitForTransactionReceipt({hash:p})}catch(e){throw console.error(e),typeof e=="string"?e:await h(e)}};import{getAddress as ls,formatUnits as Zn}from"viem";async function ms(s){try{return(await fetch(s,{method:"HEAD"})).ok}catch{return!1}}var Cc=async(s,e,t)=>{try{let n=g(s),a=e,[i,r,o,p]=await Promise.all([n.readContract({address:a,abi:H,functionName:"name"}),n.readContract({address:a,abi:H,functionName:"symbol"}),n.readContract({address:a,abi:H,functionName:"decimals"}),n.readContract({address:a,abi:H,functionName:"totalSupply"})]),d=ls(a),u=`https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/${s}/assets/${d}/logo.png`,l=await ms(u)?u:"",c;if(t){let f=await n.readContract({address:a,abi:H,functionName:"balanceOf",args:[t]});c=Number(Zn(f,Number(o)))}return{address:e,name:i,symbol:r,decimals:Number(o),icon:l,totalSupply:Number(Zn(p,Number(o))),...t?{balance:c}:{}}}catch(n){throw console.error(n),n}};import{formatUnits as ys,parseUnits as fs}from"viem";var qt=async(s,e,t)=>{try{await T({chainId:s});let n=await U(s,e);if(!n)throw new Error(D[4006]);let a=await L(s),r=((se?.Markets?.length?se?.Markets:await se.getMarkets())||[])?.find(y=>y.chainId===s&&y.marketId===t);if(!r)throw new Error("Invalid Market");let o=fs(r.oracleFeeUsd.toString(),n.quoteDecimals);if(!o)throw new Error("Invalid Market");await T({tokenAddress:n.quoteToken,contractAddress:w(s).ORACLE_RESERVE,decimals:n.quoteDecimals,account:a,chainId:s,amount:Number(ys(o,n.quoteDecimals))});let p=C[s],d=await me(s),u=await d.estimateGas.reprimePool([{poolId:e}]),m=v(u,p.gasLimitRatio),{gasPrice:l}=await E(s),c=await d.write.reprimePool([{poolId:e}],{gasLimit:m,gasPrice:l});return await g(s).waitForTransactionReceipt({hash:c})}catch(n){throw console.error(n),typeof n=="string"?n:await h(n)}};var Wt=async(s,e)=>{try{let t=await ue.getInstance().getConfigManager()?.getAccessToken();if(!t)throw new Error("Failed to obtain accessToken");return(await hn(t,e,s)).data||[]}catch(t){throw console.error(t),t}};import{formatUnits as il,parseUnits as rl}from"viem";var gs={createPool:Bt,getMarketPoolId:Oe,getMarketPools:Nt,getPoolInfo:_t,getUserGenesisShare:Lt,addTpSl:Ut,cancelTpSl:Gt,reprime:qt,getPoolDetail:U,getOpenOrders:Wt};import As from"mitt";import{Hex as bs,MD5 as Is}from"crypto-es";var We=(s,e)=>Is(s,{outputLength:e||32}).toString(bs);var ze=s=>{switch(s.request){case"signin":return We(s.request)}return We(JSON.stringify(s))},Fe=s=>{let{topic:e,params:t}=s;switch(e){case"candle":return`${e}.${t.globalId}_${t.resolution}`;case"ticker":return`${e}.${t.globalId}`;case"ticker.*":case"order":case"position":return e;default:return We(JSON.stringify({topic:e,params:t}))}},ta=({type:s})=>s==="pong"||s==="signin"||s==="subv2"||s==="unsubv2"||s==="ping"||s==="pong",xs=s=>{switch(s){case"order":case"position":case"ticker.*":return s;default:let[e]=s.split(".");return e}},na=s=>{switch(xs(s.type)){case"ticker":{let[,t=""]=s.type.split(".");return{...s,type:Fe({topic:"ticker",params:{globalId:parseInt(t)}}),globalId:parseInt(t)}}case"candle":{let[,t=""]=s.type.split("."),[n,a]=t.split("_");return{...s,type:Fe({topic:"candle",params:{globalId:parseInt(n),resolution:a}}),globalId:parseInt(n),resolution:a}}}return s};var Te=class{constructor(e){this.options={...e,logLevel:e?.logLevel||"info"}}debug(e,...t){this.options.logLevel!=="none"&&this.options.logLevel==="debug"&&console.log(`[MYX-SDK-DEBUG] ${e}`,...t)}info(e,...t){this.options.logLevel!=="none"&&(this.options.logLevel==="debug"||this.options.logLevel==="info")&&console.log(`[MYX-SDK-INFO] ${e}`,...t)}error(e,...t){this.options.logLevel!=="none"&&(this.options.logLevel==="debug"||this.options.logLevel==="info"||this.options.logLevel==="error")&&console.error(`[MYX-SDK-ERROR] ${e}`,...t)}warn(e,...t){this.options.logLevel!=="none"&&console.warn(`[MYX-SDK-WARN] ${e}`,...t)}};var b=class extends Error{constructor(e,t){super(t),this.name=e}toJSON(){return{code:this.name,message:this.message}}toString(){return`[MYX-ERROR-${this.name}]: ${this.message}`}};import Cs from"reconnecting-websocket";var aa={url:"",initialReconnectDelay:1e3,maxReconnectDelay:3e4,reconnectMultiplier:1.5,maxReconnectAttempts:10,maxEnqueuedMessages:100,requestTimeout:1e4,heartbeatInterval:1e4,heartbeatMessage:"ping",noMessageTimeout:5e3,connectionTimeout:1e4},Ve=class{constructor(e){this.ws=null;this.subscriptions=new Map;this.waitingRequests=new Map;this.eventBus=As();this.heartbeatIntervalId=null;this.isFirstConnection=!0;this.lastMessageTime=0;let t={...e,logLevel:e?.logLevel||"info"},{logLevel:n,...a}=t;this.config={...aa,...a},this.logger=new Te({logLevel:e?.logLevel}),this.logger.debug("WebSocketClient constructor",this.config)}connect(){return new Promise((e,t)=>{if(this.ws?.readyState===WebSocket.OPEN||this.ws?.readyState===WebSocket.CONNECTING){e();return}try{let n={maxReconnectionDelay:this.config.maxReconnectDelay,minReconnectionDelay:this.config.initialReconnectDelay,reconnectionDelayGrowFactor:this.config.reconnectMultiplier,maxRetries:this.config.maxReconnectAttempts,maxEnqueuedMessages:this.config.maxEnqueuedMessages,connectionTimeout:this.config.connectionTimeout};this.ws=new Cs(this.config.url,this.config.protocols,n),this.setupEventListeners(e,t)}catch(n){t(n)}})}async onBeforeReSubscribe(){return this.config.onBeforeReSubscribe&&await this.config.onBeforeReSubscribe(),!0}setupEventListeners(e,t){this.ws&&(this.ws.onopen=async n=>{this.eventBus.emit("open",n),this.lastMessageTime=Date.now(),this.timeoutHeartbeat(),this.isFirstConnection||this.onBeforeReSubscribe().then(()=>this.resubscribeAll()),this.isFirstConnection=!1,e()},this.ws.onmessage=n=>{this.handleMessage(n)},this.ws.onclose=n=>{this.eventBus.emit("close",n),this.stopHeartbeatTimer()},this.ws.onerror=n=>{this.eventBus.emit("error",n),t(n)},this.ws.addEventListener("reconnecting",n=>{this.eventBus.emit("reconnecting",{detail:n.detail||0}),this.isFirstConnection=!1}),this.ws.addEventListener("maxreconnectattempts",()=>{this.eventBus.emit("maxreconnectattempts",void 0)}))}pong(e){this.send({request:"pong",args:e})}request(e){return new Promise((t,n)=>{let a=ze(e);this.waitingRequests.has(a)?(this.waitingRequests.get(a)?.onSuccess.add(t),this.waitingRequests.get(a)?.onError.add(n)):this.waitingRequests.set(a,{onSuccess:new Set([t]),onError:new Set([n])}),this.send(e)})}subscribe(e,t){let n=Array.isArray(e)?e:[e],a=[],i=new Set;n.forEach(r=>{let o=Fe(r);if(!i.has(o))if(i.add(o),this.subscriptions.has(o))this.subscriptions.get(o).callbacks.add(t);else{let p={id:o,topic:r.topic,callbacks:new Set([t])};this.subscriptions.set(o,p),a.push(o),this.logger.debug(`create new subscription: ${o}`)}}),a.length>0&&this.send({request:"subv2",args:a})}unsubscribe(e,t){if(!e)return;let n=Array.isArray(e)?e:[e],a=[],i=new Set;n.forEach(r=>{let o=Fe(r);if(i.has(o))return;i.add(o);let p=this.subscriptions.get(o);p&&(p.callbacks.delete(t),this.logger.debug(`remove callback from subscription: ${o}`),p.callbacks.size===0&&(this.subscriptions.delete(o),a.push(o),this.logger.debug(`subscription ${o} has no callbacks, will unsubscribe`)))}),a.length>0&&this.send({request:"unsubv2",args:a})}send(e){let t=typeof e=="string"?e:JSON.stringify(e);if(!this.ws)throw new b("SOCKET_NOT_CONNECTED","WebSocket is not connected");this.ws.readyState!==WebSocket.OPEN&&this.ws.readyState!==WebSocket.CONNECTING&&this.reconnect(),this.ws.send(t)}disconnect(){this.stopHeartbeatTimer(),this.ws&&(this.ws.close(),this.ws=null)}reconnect(){this.ws?this.ws.readyState!==WebSocket.CONNECTING&&this.ws.reconnect():this.connect().catch(e=>{this.logger.error(e)})}isConnected(){return this.ws?.readyState===WebSocket.OPEN}on(e,t){this.eventBus.on(e,t)}off(e,t){this.eventBus.off(e,t)}handleMessage(e){try{let t=JSON.parse(e.data);if(this.lastMessageTime=Date.now(),t.type==="ping"){queueMicrotask(()=>{this.pong(t.data)});return}if(ta(t)){this.handleAckMessage(t);return}this.handleSubscriptionMessage(t)}catch(t){this.logger.error(`Failed to parse WebSocket message: ${t}`)}}handleAckMessage(e){let t;switch(e.type){case"signin":t=ze({request:e.type,args:""});break;default:t=ze({request:e.type,args:e.data.data});break}let n=this.waitingRequests.get(t),a=e.data.code===9200;a?this.logger.debug(`AcK Message:${e.type} received`):(this.logger.error(`Ack Message:${e.type} received`,e),this.eventBus.emit("error",e)),n?.onError.size&&!a&&n.onError.forEach(i=>{i(new b("REQUEST_FAILED","Request failed"))}),n?.onSuccess.size&&a&&n.onSuccess.forEach(i=>{i(e.data)})}handleSubscriptionMessage(e){let t=na(e),n=t.type,a=this.subscriptions.get(n);a&&a.callbacks.forEach(i=>{try{i(t)}catch(r){this.logger.error(`Callback Error (${n}): ${r}`)}})}resubscribeAll(){if(this.subscriptions.size===0)return;this.logger.debug("resubscribe all...");let e=Array.from(this.subscriptions.values()).map(t=>t.id);e.length>0&&(this.send({request:"subv2",args:e}),this.logger.debug(`resubscribe ${e.length} topics`))}timeoutHeartbeat(){this.stopHeartbeatTimer(),Date.now()-this.lastMessageTime>(this.config.noMessageTimeout||aa.noMessageTimeout)&&(this.logger.debug("no message timeout"),this.subscriptions.size>0?this.reconnect():this.ws?.close()),this.heartbeatIntervalId=setTimeout(()=>{this.timeoutHeartbeat()},this.config.heartbeatInterval)}stopHeartbeatTimer(){this.heartbeatIntervalId&&(clearInterval(this.heartbeatIntervalId),this.heartbeatIntervalId=null)}};var sa=[56,59144,42161],ia=[59141,421614,97],ra=[97,421614];var $e={TestNet:"wss://oapi-test.myx.cash/ws",MainNet:"wss://oapi.myx.finance/ws",BetaNet:"wss://oapi-beta.myx.finance/ws"};var He=class{constructor(e,t){this.clientAuth=!1;this.prevUserAddress=null;this.configManager=e,this.logger=t;let n=$e.MainNet;e.getConfig().isBetaMode?n=$e.BetaNet:e.getConfig().isTestnet&&(n=$e.TestNet),this.wsClient=new Ve({logLevel:this.configManager.getConfig()?.logLevel,url:n,...this.configManager.getConfig()?.socketConfig,onBeforeReSubscribe:()=>{if(this.clientAuth)return this.auth(!0).then(()=>{this.logger.debug("reconnect auth success")})}})}get isConnected(){return this.wsClient.isConnected()}connect(){this.wsClient.connect()}disconnect(){this.wsClient.disconnect()}reconnect(){this.wsClient.reconnect()}subscribeTickers(e,t){let n=Array.isArray(e)?e:[e];this.wsClient.subscribe(n.map(a=>({topic:"ticker",params:{globalId:a}})),t)}unsubscribeTickers(e,t){let n=Array.isArray(e)?e:[e];this.wsClient.unsubscribe(n.map(a=>({topic:"ticker",params:{globalId:a}})),t)}subscribeKline(e,t,n){this.logger.debug(`subscribe kline ${e} ${t}`),this.wsClient.subscribe({topic:"candle",params:{globalId:e,resolution:t}},n)}unsubscribeKline(e,t,n){this.logger.debug(`unsubscribe kline ${e} ${t}`),this.wsClient.unsubscribe({topic:"candle",params:{globalId:e,resolution:t}},n)}async getSdkAuthParams(){let e=this.configManager.getConfig();if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER");let t=await this.configManager.getSignerAddress(e.chainId);if(!t)throw new b("INVALID_SIGNER");return{userAddress:t}}async auth(e=!1){let{userAddress:t}=await this.getSdkAuthParams();if(t===this.prevUserAddress&&this.clientAuth&&!e)return Promise.resolve();this.logger.debug(`sdkaccount: ${t}`),await this.wsClient.request({request:"signin",args:`sdkaccount.${t}`}).then(()=>{this.logger.debug(`auth success ${t}`),this.clientAuth=!0,this.prevUserAddress=t})}async subscribePosition(e){this.logger.debug("subscribe position"),await this.auth(),this.wsClient.subscribe({topic:"position"},e)}unsubscribePosition(e){this.logger.debug("unsubscribe position"),this.wsClient.unsubscribe({topic:"position"},e)}async subscribeOrder(e){this.logger.debug("subscribe order"),await this.auth(),this.wsClient.subscribe({topic:"order"},e)}unsubscribeOrder(e){this.logger.debug("unsubscribe order"),this.wsClient.unsubscribe({topic:"order"},e)}on(e,t){this.wsClient.on(e,t)}off(e,t){this.wsClient.off(e,t)}};function ws(s){return typeof s.getAddresses=="function"&&typeof s.signMessage=="function"&&typeof s.sendTransaction=="function"}function Ps(s){return typeof s.getAddress=="function"&&typeof s.signMessage=="function"&&typeof s.sendTransaction=="function"}function zt(s){let e=s;return{async getAddress(){let[t]=await s.getAddresses();if(!t)throw new Error("WalletClient: no address");return t},async signMessage(t){let n=typeof t=="string"?t:{raw:t};return await s.signMessage({message:n})},async sendTransaction(t){let n=t.to;if(!n)throw new Error("sendTransaction: to is required");return{hash:await s.sendTransaction({to:n,data:t.data,value:t.value!=null?BigInt(t.value):void 0,gas:t.gasLimit!=null?BigInt(t.gasLimit):void 0,gasPrice:t.gasPrice!=null?BigInt(t.gasPrice):void 0,maxFeePerGas:t.maxFeePerGas!=null?BigInt(t.maxFeePerGas):void 0,maxPriorityFeePerGas:t.maxPriorityFeePerGas!=null?BigInt(t.maxPriorityFeePerGas):void 0})}},...typeof e.signTypedData=="function"?{async signTypedData(t){return await e.signTypedData(t)}}:{}}}function oa(s){let e=s;return{getAddress:()=>s.getAddress(),signMessage:t=>s.signMessage(t),async sendTransaction(t){return{hash:(await s.sendTransaction({...t,value:t.value!=null?BigInt(t.value):void 0,gasLimit:t.gasLimit!=null?BigInt(t.gasLimit):void 0})).hash}},...typeof e.signTypedData=="function"?{async signTypedData(t){return e.signTypedData(t.domain,t.types,t.message)}}:{}}}function Qe(s){return ws(s)?zt(s):Ps(s)?oa(s):s}import{createWalletClient as Ts,custom as Rs}from"viem";function pa(s){let e=Ie(s),t=[...e.privateJsonRPCUrl?[e.privateJsonRPCUrl]:[],...Array.isArray(e.publicJsonRPCUrl)?[...e.publicJsonRPCUrl]:[]].filter(Boolean);if(t.length===0)throw new Error(`${s} has no jsonRPCUrl configured`);return t[0]}var Vt={};function vs(s){if(!Vt[s]){let e=Ie(s);Vt[s]={id:s,name:e.label||`Chain ${s}`,nativeCurrency:e.nativeCurrency,rpcUrls:{default:{http:[pa(s)]}}}}return Vt[s]}async function ua(s,e){let t=pa(e),n=vs(e),i={address:await s.getAddress(),type:"local",async signMessage({message:o}){let p=typeof o=="string"?o:o.raw;return await s.signMessage(p)},async signTypedData(o){if(!s.signTypedData)throw new Error("ISigner.signTypedData required for this operation");return await s.signTypedData({domain:o.domain,types:o.types,primaryType:o.primaryType,message:o.message})},source:"custom"};return Ts({account:i,chain:n,transport:Rs({request:async o=>{if(o.method==="eth_sendTransaction"){let u=o.params?.[0]??{},{hash:m}=await s.sendTransaction({to:u.to,data:u.data,value:u.value!=null?BigInt(u.value):void 0,gasLimit:u.gas!=null?BigInt(u.gas):void 0,gasPrice:u.gasPrice!=null?BigInt(u.gasPrice):void 0,maxFeePerGas:u.maxFeePerGas!=null?BigInt(u.maxFeePerGas):void 0,maxPriorityFeePerGas:u.maxPriorityFeePerGas!=null?BigInt(u.maxPriorityFeePerGas):void 0});return m}let d=await(await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:1,method:o.method,params:o.params??[]})})).json();if(d.error)throw new Error(d.error.message);return d.result}})})}var Ke=class{constructor(e){this._normalizedSigner=null;this._getAccessTokenQueue=[];this._isGettingAccessToken=!1;let t={isTestnet:!1,isBetaMode:!1,...e};this.validateConfig(t),this.config=t}clear(){this.accessToken=void 0,this.accessTokenExpiry=void 0,this._normalizedSigner=null,this.config={...this.config,signer:void 0,walletClient:void 0,getAccessToken:void 0}}hasSigner(){return!!(this.config.walletClient||this.config.signer!=null||this._normalizedSigner!=null)}async getSignerAddress(e){if(this.config.walletClient){let[t]=await this.config.walletClient.getAddresses();if(t)return t}if(this._normalizedSigner)return this._normalizedSigner.getAddress();throw new b("INVALID_SIGNER","Invalid signer")}async getViemWalletClient(e){if(this.config.walletClient)return this.config.walletClient;if(this._normalizedSigner)return await ua(this._normalizedSigner,e);throw new b("INVALID_SIGNER","Invalid signer: call auth({ signer }) or auth({ walletClient })")}async startSeamlessMode(e){return this.config={...this.config,seamlessMode:e},this.config}updateSeamlessWallet({wallet:e,authorized:t,masterAddress:n}){this.config={...this.config,seamlessAccount:{masterAddress:n??"",wallet:e??null,authorized:t??!1}}}updateClientChainId(e,t){this.config={...this.config,chainId:e,brokerAddress:t}}auth(e){this.clear(),this.config={...this.config,...e},e.signer!=null&&(this._normalizedSigner=Qe(e.signer)),this.validateConfig(this.config)}validateConfig(e){let{isTestnet:t,isBetaMode:n,chainId:a}=e;if(t){if(!ia.includes(a))throw new b("INVALID_CHAIN_ID",`chainId ${a} is not in the range of TESTNET_CHAIN_IDS`)}else if(n){if(!ra.includes(a))throw new b("INVALID_CHAIN_ID",`chainId ${a} is not in the range of BETA_ENV_CHAIN_IDS`)}else if(!sa.includes(a))throw new b("INVALID_CHAIN_ID",`chainId ${a} is not in the range of MAINNET_CHAIN_IDS`)}async getAccessToken(){return this.accessToken??null}async refreshAccessToken(e=!1){return new Promise((t,n)=>{this._getAccessTokenQueue.push({resolve:t,reject:n,forceRefresh:e}),this._processAccessTokenQueue()})}_processAccessTokenQueue(){if(this._isGettingAccessToken)return;this._isGettingAccessToken=!0;let e=this._getAccessTokenQueue.shift();e?this._refreshAccessToken(e.forceRefresh).then(e.resolve).catch(e.reject).finally(()=>{this._isGettingAccessToken=!1,this._getAccessTokenQueue.length>0&&this._processAccessTokenQueue()}):this._isGettingAccessToken=!1}async _refreshAccessToken(e=!1){if(!e&&this.isAccessTokenValid())return this._isGettingAccessToken=!1,this.accessToken;if(!this.config.getAccessToken)return console.warn("No getAccessToken method provided in config"),null;try{let t=await this.config.getAccessToken()??{accessToken:"",expireAt:0};if(t&&t.accessToken){let n=3600;if(t.expireAt){let a=Math.floor(Date.now()/1e3);n=t.expireAt-a,n<=0&&(console.warn("Received expired token, using default expiry"),n=3600)}return this.setAccessToken(t.accessToken,n),t.accessToken}else return console.warn("\u274C Received empty accessToken"),null}catch(t){return console.error("\u274C Failed to refresh accessToken:",t),null}}setAccessToken(e,t=3600){this.accessToken=e,this.accessTokenExpiry=Date.now()+t*1e3}getCurrentAccessToken(){return this.accessToken}isAccessTokenValid(){return!!this.accessToken}clearAccessToken(){this.accessToken=void 0,this.accessTokenExpiry=void 0}getConfig(){return this.config}};var Je=class{constructor(e,t,n){this.configManager=e,this.utils=t,this.api=n}getMarkets(){return Promise.resolve([])}async getPoolLevelConfig(e,t){let n=this.configManager.getConfig();return(await this.api.getPoolLevelConfig({poolId:e,chainId:t})).data}async getKlineList({interval:e,...t}){let n=this.configManager.getConfig();return(await this.api.getKlineData({...t,interval:this.utils.transferKlineResolutionToInterval(e)})).data}async getKlineLatestBar({interval:e,...t}){let n=this.configManager.getConfig();return(await this.api.getKlineLatestBar({...t,interval:this.utils.transferKlineResolutionToInterval(e)})).data}async getTickerList(e){return(await this.api.getTickerData(e)).data}async searchMarketAuth(e,t){let n=await this.configManager.getAccessToken()??"";return(await this.api.searchMarketAuth({address:t,...e,accessToken:n})).data}async searchMarket(e){return(await this.api.searchMarket(e)).data}async getFavoritesList(e,t){let n=await this.configManager.getAccessToken()??"";return(await this.api.getFavoritesList({...e,address:t,accessToken:n})).data}async addFavorite(e,t){let n=await this.configManager.getAccessToken()??"";return(await this.api.addFavorite({...e,address:t,accessToken:n})).data}async removeFavorite(e,t){let n=await this.configManager.getAccessToken()??"";return(await this.api.removeFavorite({...e,address:t,accessToken:n})).data}async getBaseDetail(e){return(await this.api.getBaseDetail(e)).data}async getMarketDetail(e){return(await this.api.getMarketDetail(e)).data}async getPoolSymbolAll(){return(await this.api.getPoolSymbolAll()).data}};import{encodeFunctionData as Es,maxUint256 as ks}from"viem";import Ss from"dayjs";var je=class{constructor(e,t,n,a,i,r){this.configManager=e,this.logger=t,this.utils=n,this.seamless=a,this.account=i,this.api=r}async listPositions(e){let t=await this.configManager.getAccessToken();try{return{code:0,data:(await this.api.getPositions(t??"",e)).data}}catch(n){return console.error("Error fetching positions:",n),{code:-1,message:"Failed to fetch positions"}}}async getPositionHistory(e,t){let n=await this.configManager.getAccessToken()??"";return{code:0,data:(await this.api.getPositionHistory({accessToken:n,...e,address:t})).data}}async adjustCollateral({poolId:e,positionId:t,adjustAmount:n,quoteToken:a,chainId:i,address:r}){let o=this.configManager.getConfig();try{let p=await this.utils.getOraclePrice(e,i);if(!p)throw new Error("Failed to get price data");let d={poolId:e,oracleType:p.oracleType,oracleUpdateData:p?.vaa??"0",publishTime:p.publishTime},u=!1;Number(n)>0&&(u=await this.utils.needsApproval(r,i,a,n,w(i).TRADING_ROUTER));let m=this.configManager.getConfig().seamlessAccount?.authorized,l=this.configManager.getConfig().seamlessAccount?.wallet,c=BigInt(0),f=BigInt(n)>0?BigInt(n):0n,y=await this.account.getAvailableMarginBalance({poolId:e,chainId:i,address:r}),I=y.code===0?y.data??0n:0n,x=BigInt(0);I<f&&(x=f-I,c=x);let P={token:a,amount:c.toString()};if(o.seamlessMode&&m&&l){if(!await this.utils.checkSeamlessGas(o.seamlessAccount?.masterAddress,i))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let R=await F(i),q=Es({abi:O,functionName:"updatePriceAndAdjustCollateral",args:[[d],P,t,n]}),X=await R.read.nonces([l.address]),le={from:l.address??"",to:this.configManager.getConfig().brokerAddress,value:(p?.value??"1").toString(),gas:"10000000",deadline:Ss().add(60,"minute").unix(),data:q,nonce:X.toString()};return{code:0,message:"adjust collateral success",data:await this.seamless.forwarderTx(le,i,l)}}if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER","Invalid signer");let M=await V(i,o.brokerAddress);if(u){let G=await this.utils.approveAuthorization({chainId:i,quoteAddress:a,amount:ks.toString(),spenderAddress:w(i).TRADING_ROUTER});if(G.code!==0)throw new Error(G.message)}let B=await M.write.updatePriceAndAdjustCollateral([[d],P,t,n],{value:BigInt(p?.value??"1"),gas:BigInt(1e7)*$[i]/100n});return await g(i).waitForTransactionReceipt({hash:B}),{code:0,data:{hash:B},message:"Adjust collateral transaction submitted"}}catch(p){return{code:-1,message:p.message}}}};var Ms={IOC:0},ye=Ms.IOC;var Ye={MARKET:0,LIMIT:1,STOP:2,CONDITIONAL:3},Im={NONE:0,GTE:1,LTE:2},fe={INCREASE:0,DECREASE:1},hm={LONG:0,SHORT:1},xm={IOC:0},Am={PENDING:0,PARTIAL:1,FILLED:2,CANCELLED:3,REJECTED:4,EXPIRED:5};import{encodeFunctionData as Q,maxUint256 as da}from"viem";import pe from"dayjs";var Xe=class{constructor(e,t,n,a,i,r){this.configManager=e,this.logger=t,this.utils=n,this.seamless=a,this.account=i,this.api=r}async createIncreaseOrder(e,t,n){try{let a=this.configManager.getConfig(),i=await this.utils.getNetworkFee(n,e.chainId),r=BigInt(i);e.tpSize&&BigInt(e.tpSize)>0&&(r+=BigInt(i)),e.slSize&&BigInt(e.slSize)>0&&(r+=BigInt(i));let o=BigInt(e.collateralAmount)+BigInt(t),p=await this.account.getAvailableMarginBalance({poolId:e.poolId,chainId:e.chainId,address:e.address}),d=p.code===0?p.data??0n:0n,u=o+r,m=BigInt(0),l=u-d;l>BigInt(0)&&(m=l);let c={token:e.executionFeeToken,amount:m.toString()},f={user:e.address,poolId:e.poolId,orderType:e.orderType,triggerType:e.triggerType,operation:fe.INCREASE,direction:e.direction,collateralAmount:o.toString(),size:e.size,price:e.price,timeInForce:ye,postOnly:e.postOnly??!1,slippagePct:e.slippagePct??"0",leverage:e.leverage??0,tpSize:e.tpSize??"0",tpPrice:e.tpPrice??"0",slSize:e.slSize??"0",slPrice:e.slPrice??"0"},y=this.configManager.getConfig().seamlessAccount?.authorized,I=this.configManager.getConfig().seamlessAccount?.wallet;if(a.seamlessMode&&y&&I){if(!await this.utils.checkSeamlessGas(e.address,e.chainId))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let q=await F(e.chainId),X="";e.positionId?X=Q({abi:O,functionName:"placeOrderWithPosition",args:[e.positionId.toString(),{...c},f]}):(this.logger.info("createIncreaseOrder placeOrderWithSalt data --->",["1",{...c},f]),X=Q({abi:O,functionName:"placeOrderWithSalt",args:["1",{...c},f]}));let le=await q.read.nonces([I.address]),be={from:I.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:X,nonce:le.toString()};return this.logger.info("createIncreaseOrder forward tx params --->",be),{code:0,message:"create increase order success",data:await this.seamless.forwarderTx(be,e.chainId,I)}}let x=await this.utils.needsApproval(e.address,e.chainId,e.executionFeeToken,e.collateralAmount,w(e.chainId).TRADING_ROUTER);if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER","Invalid signer");if(x){let R=await this.utils.approveAuthorization({chainId:e.chainId,quoteAddress:e.executionFeeToken,amount:da.toString(),spenderAddress:w(e.chainId).TRADING_ROUTER});if(R.code!==0)throw new Error(R.message)}let P=await V(e.chainId,this.configManager.getConfig().brokerAddress),M;if(e.positionId){this.logger.info("createIncreaseOrder nft position params--->",{...f,positionId:e.positionId});let R=await P.estimateGas.placeOrderWithPosition([e.positionId.toString(),{...c},f]);M=await P.write.placeOrderWithPosition([e.positionId.toString(),{...c},f],{gasLimit:R*$[e.chainId]/100n})}else{this.logger.info("createIncreaseOrder salt position params--->",{positionSalt:"1",data:f,depositData:c});let q=await P.estimateGas.placeOrderWithSalt(["1",{...c},f]);M=await P.write.placeOrderWithSalt(["1",{...c},f],{gasLimit:q*$[e.chainId]/100n})}let B=await g(e.chainId).waitForTransactionReceipt({hash:M});return{code:0,message:"create increase order success",data:{success:!0,transactionHash:M,blockNumber:B?.blockNumber,gasUsed:B?.gasUsed?.toString(),status:B?.status==="success"?"success":"failed",confirmations:1,timestamp:Date.now(),receipt:B}}}catch(a){return this.logger.error("Error placing order:",a),{code:-1,message:a?.message}}}async closeAllPositions(e,t){try{let n=this.configManager.getConfig(),a={token:"0x0000000000000000000000000000000000000000",amount:"0"},i=t.map(c=>c.positionId.toString()),r=t.map(c=>({user:c.address,poolId:c.poolId,orderType:c.orderType,triggerType:c.triggerType,operation:fe.DECREASE,direction:c.direction,collateralAmount:c.collateralAmount,size:c.size,price:c.price,timeInForce:ye,postOnly:c.postOnly,slippagePct:c.slippagePct,leverage:c.leverage,tpSize:0,tpPrice:0,slSize:0,slPrice:0}));this.logger.info("closeAllPositions params--->",a,i,r);let o=this.configManager.getConfig().seamlessAccount?.authorized,p=this.configManager.getConfig().seamlessAccount?.wallet;if(n.seamlessMode&&o&&p){if(!await this.utils.checkSeamlessGas(t[0].address,e))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let f=await F(e),y=await re(this.configManager.getConfig().brokerAddress,p),I=Q({abi:O,functionName:"placeOrdersWithPosition",args:[a,i,r]}),x=await f.read.nonces([p.address]),P={from:p.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:I,nonce:x.toString()};return this.logger.info("cancel all positions forward tx params --->",P),{code:0,message:"cancel all positions success",data:await this.seamless.forwarderTx(P,e,p)}}if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER","Invalid signer");let d=await V(e,this.configManager.getConfig().brokerAddress),u=await d.estimateGas.placeOrdersWithPosition([a,i,r]),m=await d.write.placeOrdersWithPosition([a,i,r],{gasLimit:u*$[e]/100n}),l=await g(e).waitForTransactionReceipt({hash:m});return{code:0,message:"close all positions success",transactionHash:m,blockNumber:l?.blockNumber,gasUsed:l?.gasUsed?.toString(),status:l?.status==="success"?"success":"failed",confirmations:1,timestamp:Date.now(),receipt:l}}catch(n){return{code:-1,message:n?.message}}}async createDecreaseOrder(e){try{let t=this.configManager.getConfig(),n={user:e.address,poolId:e.poolId,orderType:e.orderType,triggerType:e.triggerType,operation:fe.DECREASE,direction:e.direction,collateralAmount:e.collateralAmount,size:e.size,price:e.price,timeInForce:ye,postOnly:e.postOnly,slippagePct:e.slippagePct,leverage:e.leverage,tpSize:0,tpPrice:0,slSize:0,slPrice:0},a={token:"0x0000000000000000000000000000000000000000",amount:"0"},i=this.configManager.getConfig().seamlessAccount?.authorized,r=this.configManager.getConfig().seamlessAccount?.wallet;if(t.seamlessMode&&i&&r){if(!await this.utils.checkSeamlessGas(e.address,e.chainId))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let l=await F(e.chainId),c=await re(this.configManager.getConfig().brokerAddress,r),f="";e.positionId?f=Q({abi:O,functionName:"placeOrderWithPosition",args:[e.positionId.toString(),{...a},n]}):f=Q({abi:O,functionName:"placeOrderWithSalt",args:["1",{...a},n]});let y=await l.read.nonces([r.address]),I={from:r.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:f,nonce:y.toString()};return this.logger.info("create decrease order forward tx params --->",I),{code:0,message:"create decrease order success",data:await this.seamless.forwarderTx(I,e.chainId,r)}}if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER","Invalid signer");let o=await V(e.chainId,this.configManager.getConfig().brokerAddress),p;if(e.positionId){this.logger.info("createDecreaseOrder nft position params--->",[e.positionId,a,{data:n}]);let m=await o.estimateGas.placeOrderWithPosition([e.positionId.toString(),a,n]);p=await o.write.placeOrderWithPosition([e.positionId.toString(),a,n],{gasLimit:m*$[e.chainId]/100n})}else{this.logger.info("createDecreaseOrder salt position params--->",[1,a,{data:n}]);let l=await o.estimateGas.placeOrderWithSalt(["1",a,n]);p=await o.write.placeOrderWithSalt(["1",a,n],{gasLimit:l*$[e.chainId]/100n})}let d=await g(e.chainId).waitForTransactionReceipt({hash:p});return{code:0,message:"create decrease order success",data:{success:!0,transactionHash:p,blockNumber:d?.blockNumber,gasUsed:d?.gasUsed?.toString(),status:d?.status==="success"?"success":"failed",confirmations:1,timestamp:Date.now(),receipt:d}}}catch(t){return{code:-1,message:t?.message}}}async createPositionTpSlOrder(e){try{let t=this.configManager.getConfig();if(!this.configManager.hasSigner()&&!t.seamlessMode)throw new b("INVALID_SIGNER","Invalid signer");let n=await V(e.chainId,this.configManager.getConfig().brokerAddress);try{if(e.tpSize!=="0"&&e.slSize!=="0"){let m=[{user:e.address,poolId:e.poolId,orderType:Ye.STOP,triggerType:e.tpTriggerType,operation:fe.DECREASE,direction:e.direction,collateralAmount:"0",size:e.tpSize??"0",price:e.tpPrice??"0",timeInForce:ye,postOnly:!1,slippagePct:e.slippagePct??"0",leverage:e.leverage,tpSize:"0",tpPrice:"0",slSize:"0",slPrice:"0"},{user:e.address,poolId:e.poolId,orderType:Ye.STOP,triggerType:e.slTriggerType,operation:fe.DECREASE,direction:e.direction,collateralAmount:"0",size:e.slSize??"0",price:e.slPrice??"0",timeInForce:ye,postOnly:!1,slippagePct:e.slippagePct??"0",leverage:e.leverage,tpSize:"0",tpPrice:"0",slSize:"0",slPrice:"0"}],l={token:"0x0000000000000000000000000000000000000000",amount:"0"},c=this.configManager.getConfig().seamlessAccount?.authorized,f=this.configManager.getConfig().seamlessAccount?.wallet;if(t.seamlessMode&&c&&f){if(!await this.utils.checkSeamlessGas(e.address,e.chainId))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let M=await F(e.chainId),B=await re(this.configManager.getConfig().brokerAddress,f),G="";e.positionId?G=Q({abi:O,functionName:"placeOrdersWithPosition",args:[l,[e.positionId.toString(),e.positionId.toString()],m]}):G=Q({abi:O,functionName:"placeOrdersWithSalt",args:[l,["1","1"],m]});let R=await M.read.nonces([f.address]),q={from:f.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:G,nonce:R.toString()};return this.logger.info("createPositionTpSlOrder forward tx params --->",q),{code:0,message:"createPositionTpSlOrder success",data:await this.seamless.forwarderTx(q,e.chainId,f)}}let y;if(e.positionId){let P=await n.estimateGas.placeOrdersWithPosition([l,[e.positionId.toString(),e.positionId.toString()],m]);y=await n.write.placeOrdersWithPosition([l,[e.positionId.toString(),e.positionId.toString()],m],{gasLimit:P*$[e.chainId]/100n})}else{this.logger.info("createPositionTpSlOrder salt position data--->",m);let P=1,M=await n.estimateGas.placeOrdersWithSalt([l,[P.toString(),P.toString()],m]);y=await n.write.placeOrdersWithSalt([l,[P.toString(),P.toString()],m],{gasLimit:M*$[e.chainId]/100n})}let I=await g(e.chainId).waitForTransactionReceipt({hash:y});return{code:0,message:"create decrease order success",data:{success:!0,transactionHash:y,blockNumber:I?.blockNumber,gasUsed:I?.gasUsed?.toString(),status:I?.status==="success"?"success":"failed",confirmations:1,timestamp:Date.now(),receipt:I}}}let a={user:e.address,poolId:e.poolId,orderType:Ye.STOP,triggerType:e.tpSize!=="0"?e.tpTriggerType:e.slTriggerType,operation:fe.DECREASE,direction:e.direction,collateralAmount:"0",size:e.tpSize!=="0"?e.tpSize??"0":e.slSize??"0",price:e.tpPrice!=="0"?e.tpPrice??"0":e.slPrice??"0",timeInForce:ye,postOnly:!1,slippagePct:e.slippagePct??"0",leverage:0,tpSize:"0",tpPrice:"0",slSize:"0",slPrice:"0"},i={token:"0x0000000000000000000000000000000000000000",amount:"0"},r=this.configManager.getConfig().seamlessAccount?.authorized,o=this.configManager.getConfig().seamlessAccount?.wallet;if(t.seamlessMode&&r&&o){if(!await this.utils.checkSeamlessGas(e.address,e.chainId))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let l=await F(e.chainId),c=await re(this.configManager.getConfig().brokerAddress,o),f="";e.positionId?f=Q({abi:O,functionName:"placeOrderWithPosition",args:[e.positionId.toString(),i,a]}):f=Q({abi:O,functionName:"placeOrderWithSalt",args:["1",i,a]});let y=await l.read.nonces([o.address]),I={from:o.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:f,nonce:y.toString()};return this.logger.info("createPositionTpSlOrder forward tx params --->",I),{code:0,message:"createPositionTpSlOrder success",data:await this.seamless.forwarderTx(I,e.chainId,o)}}let p;if(e.positionId){this.logger.info("createPositionTpOrSlOrder nft position data--->",a);let m=await n.estimateGas.placeOrderWithPosition([e.positionId.toString(),i,a]);p=await n.write.placeOrderWithPosition([e.positionId.toString(),i,a],{gasLimit:m*$[e.chainId]/100n})}else{this.logger.info("createPositionTpOrSlOrder salt position data--->",a);let m=1,l=await n.estimateGas.placeOrderWithSalt([m.toString(),i,a]);p=await n.write.placeOrderWithSalt([m.toString(),i,a],{gasLimit:l*$[e.chainId]/100n})}let d=await g(e.chainId).waitForTransactionReceipt({hash:p});return{code:0,message:"create decrease order success",data:{success:!0,transactionHash:p,blockNumber:d?.blockNumber,gasUsed:d?.gasUsed?.toString(),status:d?.status==="success"?"success":"failed",confirmations:1,timestamp:Date.now(),receipt:d}}}catch(a){return{code:-1,message:a?.message}}}catch(t){return{code:-1,message:t?.message}}}async cancelAllOrders(e,t){try{let n=this.configManager.getConfig(),a=this.configManager.getConfig().seamlessAccount?.authorized,i=this.configManager.getConfig().seamlessAccount?.wallet;if(n.seamlessMode&&a&&i){if(!await this.utils.checkSeamlessGas(n.seamlessAccount?.masterAddress,t))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let d=await F(t),u=await re(this.configManager.getConfig().brokerAddress,i),m=Q({abi:O,functionName:"cancelOrders",args:[e]}),l=await d.read.nonces([i.address]),c={from:i.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:m,nonce:l.toString()};return this.logger.info("create decrease order forward tx params --->",c),{code:0,message:"create decrease order success",data:await this.seamless.forwarderTx(c,t,i)}}if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER","Invalid signer");let o=await(await V(t,this.configManager.getConfig().brokerAddress)).write.cancelOrders([e]);return await g(t).waitForTransactionReceipt({hash:o}),{code:0,message:"cancel all orders success"}}catch(n){return{code:-1,message:n?.message}}}async cancelOrder(e,t){try{let n=this.configManager.getConfig(),a=this.configManager.getConfig().seamlessAccount?.authorized,i=this.configManager.getConfig().seamlessAccount?.wallet;if(n.seamlessMode&&a&&i){if(!await this.utils.checkSeamlessGas(n.seamlessAccount?.masterAddress,t))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let d=await re(this.configManager.getConfig().brokerAddress,i),u=await F(t),m=Q({abi:O,functionName:"cancelOrder",args:[BigInt(e)]}),l=await u.read.nonces([i.address]),c={from:i.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:m,nonce:l.toString()};return this.logger.info("createIncreaseOrder forward tx params --->",c),{code:0,message:"cancel order success",data:await this.seamless.forwarderTx(c,t,i)}}if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER","Invalid signer");let o=await(await V(t,this.configManager.getConfig().brokerAddress)).write.cancelOrder([e]);return await g(t).waitForTransactionReceipt({hash:o}),{code:0,message:"cancel order success"}}catch(n){return{code:-1,message:n?.message}}}async cancelOrders(e,t){try{let n=this.configManager.getConfig(),a=this.configManager.getConfig().seamlessAccount?.authorized,i=this.configManager.getConfig().seamlessAccount?.wallet;if(n.seamlessMode&&a&&i){if(!await this.utils.checkSeamlessGas(n.seamlessAccount?.masterAddress,t))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let d=await F(t),u=await re(this.configManager.getConfig().brokerAddress,i),m=Q({abi:O,functionName:"cancelOrders",args:[e]}),l=await d.read.nonces([i.address]),c={from:i.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:m,nonce:l.toString()};return this.logger.info("cancel orders forward tx params --->",c),{code:0,message:"cancel orders success",data:await this.seamless.forwarderTx(c,t,i)}}if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER","Invalid signer");let o=await(await V(t,this.configManager.getConfig().brokerAddress)).write.cancelOrders([e]);return await g(t).waitForTransactionReceipt({hash:o}),{code:0,message:"Orders canceled success"}}catch(n){return this.logger.error("Error canceling orders:",n),{code:-1,message:n?.message}}}async updateOrderTpSl(e,t,n,a,i,r){let o=this.configManager.getConfig(),p=await this.utils.getNetworkFee(i,n),d={orderId:e.orderId,size:e.size,price:e.price,tpsl:{tpSize:r?e.tpSize:"0",tpPrice:r?e.tpPrice:"0",slSize:r?e.slSize:"0",slPrice:r?e.slPrice:"0"}},u={token:t,amount:p.toString()},m=this.configManager.getConfig().seamlessAccount?.authorized,l=this.configManager.getConfig().seamlessAccount?.wallet;if(o.seamlessMode&&m&&l){if(!await this.utils.checkSeamlessGas(o.seamlessAccount?.masterAddress,n))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let y=await re(this.configManager.getConfig().brokerAddress,l),I=await F(n),x=Q({abi:O,functionName:"updateOrder",args:[u,d]}),P=await I.read.nonces([l.address]),M={from:l.address??"",to:this.configManager.getConfig().brokerAddress,value:"0",gas:"800000",deadline:pe().add(60,"minute").unix(),data:x,nonce:P.toString()};return this.logger.info("createIncreaseOrder forward tx params --->",M),{code:0,message:"update order success",data:await this.seamless.forwarderTx(M,n,l)}}if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER","Invalid signer");let c=await V(n,o.brokerAddress);this.logger.info("updateOrderTpSl params",d);try{if(await this.utils.needsApproval(a,n,e.executionFeeToken,p.toString(),w(n).TRADING_ROUTER)){let P=await this.utils.approveAuthorization({chainId:n,quoteAddress:e.executionFeeToken,amount:da.toString(),spenderAddress:w(n).TRADING_ROUTER});if(P.code!==0)throw new Error(P.message)}let y=await c.estimateGas.updateOrder([u,d]),I=await c.write.updateOrder([u,d],{gasLimit:y*$[n]/100n}),x=await g(n).waitForTransactionReceipt({hash:I});return this.logger.info("updateOrderTpSl receipt",x),{code:0,data:x,message:"update order success"}}catch(f){return this.logger.error("Error updating order:",f),{code:-1,message:"Failed to update order"}}}async getOrders(e){let t=await this.configManager.getAccessToken();try{return{code:0,data:(await this.api.getOrders(t??"",e)).data}}catch(n){return console.error("Error fetching orders:",n),{code:-1,message:"Failed to fetch orders"}}}async getOrderHistory(e,t){let n=await this.configManager.getAccessToken()??"";return{code:0,data:(await this.api.getHistoryOrders({accessToken:n,...e,address:t})).data}}};import{decodeEventLog as Os,maxUint256 as Fs}from"viem";var ca=[{type:"error",name:"AddressEmptyCode",inputs:[{type:"address",name:"target"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{type:"address",name:"implementation"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"NotAddressManager",inputs:[]},{type:"error",name:"NotAllowedIdentifier",inputs:[]},{type:"error",name:"NotDependencyManager",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProxyAdmin",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{type:"bytes32",name:"slot"}]},{type:"event",anonymous:!1,name:"BlockHeader",inputs:[{type:"uint256",name:"blockNumber",indexed:!1},{type:"uint256",name:"blockTimestamp",indexed:!1},{type:"uint256",name:"sequence",indexed:!1}]},{type:"event",anonymous:!1,name:"CollateralAccepted",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"quoteDebt",indexed:!1},{type:"uint256",name:"baseCollateral",indexed:!1},{type:"uint256",name:"quoteCollateral",indexed:!1},{type:"uint256",name:"totalQuoteDebt",indexed:!1},{type:"uint256",name:"totalBaseCollateral",indexed:!1}]},{type:"event",anonymous:!1,name:"CollateralAdjusted",inputs:[{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint8",name:"direction",indexed:!1},{type:"uint256",name:"beforeCollateralAmount",indexed:!1},{type:"uint256",name:"afterCollateralAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"EnterDispute",inputs:[{type:"bytes32",name:"poolId",indexed:!1}]},{type:"event",anonymous:!1,name:"Exchanged",inputs:[{type:"address",name:"user",indexed:!1},{type:"address",name:"source",indexed:!1},{type:"address",name:"target",indexed:!1},{type:"uint256",name:"sourceAmount",indexed:!1},{type:"uint256",name:"targetAmount",indexed:!1},{type:"uint256",name:"price",indexed:!1}]},{type:"event",anonymous:!1,name:"ExecutionMatched",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256[]",name:"triggerOrderIds",indexed:!1},{type:"uint256[]",name:"matchedOrderIds",indexed:!1},{type:"uint8",name:"matchType",indexed:!1},{type:"uint256",name:"price",indexed:!1}]},{type:"event",anonymous:!1,name:"ExitDispute",inputs:[{type:"bytes32",name:"poolId",indexed:!1}]},{type:"event",anonymous:!1,name:"FeeDistributed",inputs:[{type:"address",name:"user",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"int32",name:"tradingFeeRate",indexed:!1},{type:"bool",name:"isMaker",indexed:!1},{type:"int256",name:"tradingFee",indexed:!1},{type:"uint256",name:"baseTradingFee",indexed:!1},{type:"uint256",name:"brokerTradingFee",indexed:!1},{type:"address",name:"broker",indexed:!1},{type:"uint256",name:"referralRebate",indexed:!1},{type:"uint256",name:"referrerRebate",indexed:!1},{type:"address",name:"referrer",indexed:!1},{type:"int256",name:"reserveFee",indexed:!1}]},{type:"event",anonymous:!1,name:"FundingRateUpdated",inputs:[{type:"uint64",name:"epochs",indexed:!1},{type:"uint64",name:"duration",indexed:!1},{type:"uint64",name:"previousEpochTime",indexed:!1},{type:"uint64",name:"lastEpochTime",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"int256",name:"fundingRate",indexed:!1},{type:"int256",name:"fundingRateTracker",indexed:!1},{type:"uint256",name:"price",indexed:!1}]},{type:"event",anonymous:!1,name:"Initialized",inputs:[{type:"uint64",name:"version",indexed:!1}]},{type:"event",anonymous:!1,name:"LiquidityLockUpdated",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint64",name:"windowAnchor",indexed:!1},{type:"uint256",name:"priceFloor",indexed:!1},{type:"uint256",name:"priceCeiling",indexed:!1},{type:"int256",name:"openInterest",indexed:!1}]},{type:"event",anonymous:!1,name:"LiquidityMigrated",inputs:[{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"fromPoolId",indexed:!1},{type:"bytes32",name:"toPoolId",indexed:!1},{type:"uint256",name:"lpAmountIn",indexed:!1},{type:"uint256",name:"lpAmountOut",indexed:!1}]},{type:"event",anonymous:!1,name:"LiquidityStopOrderCancelled",inputs:[{type:"uint256",name:"orderId",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"string",name:"reason",indexed:!1}]},{type:"event",anonymous:!1,name:"LiquidityStopOrderCreated",inputs:[{type:"uint256",name:"orderId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"uint8",name:"poolType",indexed:!1},{type:"uint256",name:"amount",indexed:!1},{type:"uint256",name:"triggerPrice",indexed:!1},{type:"uint8",name:"triggerType",indexed:!1},{type:"uint256",name:"minQuoteOut",indexed:!1}]},{type:"event",anonymous:!1,name:"LiquidityStopOrderExecuted",inputs:[{type:"uint256",name:"orderId",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"executor",indexed:!1},{type:"uint256",name:"oraclePrice",indexed:!1},{type:"uint256",name:"poolTokenPrice",indexed:!1}]},{type:"event",anonymous:!1,name:"MarketCreated",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"address",name:"deployer",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint32",name:"baseReserveRatio",indexed:!1},{type:"uint32",name:"quoteReserveRatio",indexed:!1},{type:"uint64",name:"oracleFeeUsd",indexed:!1},{type:"uint64",name:"oracleRefundFeeUsd",indexed:!1},{type:"uint128",name:"poolPrimeThreshold",indexed:!1}]},{type:"event",anonymous:!1,name:"OrderCancelled",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"string",name:"remark",indexed:!1}]},{type:"event",anonymous:!1,name:"OrderFilled",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint8",name:"orderType",indexed:!1},{type:"uint256",name:"orderSize",indexed:!1},{type:"uint256",name:"fillSize",indexed:!1},{type:"uint256",name:"filledSize",indexed:!1},{type:"uint256",name:"orderPrice",indexed:!1},{type:"uint256",name:"fillPrice",indexed:!1},{type:"int256",name:"realizedPnl",indexed:!1},{type:"int256",name:"tradingFee",indexed:!1},{type:"int256",name:"fundingFee",indexed:!1},{type:"uint256",name:"executionFeeAmount",indexed:!1},{type:"address",name:"keeper",indexed:!1}]},{type:"event",anonymous:!1,name:"OrderMarkedADL",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint256",name:"available",indexed:!1},{type:"uint256",name:"requested",indexed:!1}]},{type:"event",anonymous:!1,name:"OrderPlaced",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint8",name:"orderType",indexed:!1},{type:"uint8",name:"operation",indexed:!1},{type:"uint8",name:"direction",indexed:!1},{type:"uint8",name:"triggerType",indexed:!1},{type:"uint256",name:"collateralAmount",indexed:!1},{type:"uint256",name:"size",indexed:!1},{type:"uint256",name:"price",indexed:!1},{type:"uint8",name:"tif",indexed:!1},{type:"bool",name:"postOnly",indexed:!1},{type:"uint16",name:"slippagePct",indexed:!1},{type:"uint256",name:"executionFeeAmount",indexed:!1},{type:"uint16",name:"userLeverage",indexed:!1}]},{type:"event",anonymous:!1,name:"OrderUpdated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint256",name:"size",indexed:!1},{type:"uint256",name:"price",indexed:!1},{type:"uint256",name:"tpSize",indexed:!1},{type:"uint256",name:"tpPrice",indexed:!1},{type:"uint256",name:"slSize",indexed:!1},{type:"uint256",name:"slPrice",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolActivated",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint8",name:"oracleType",indexed:!1},{type:"bytes32",name:"oracleFeedId",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolDeactivated",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"string",name:"remark",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolDeployed",inputs:[{type:"bytes32",name:"marketId",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"deployer",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"address",name:"basePoolToken",indexed:!1},{type:"address",name:"quotePoolToken",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolDeposited",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"address",name:"recipient",indexed:!1},{type:"address",name:"underlyingToken",indexed:!1},{type:"address",name:"poolToken",indexed:!1},{type:"uint256",name:"underlyingIn",indexed:!1},{type:"uint256",name:"poolTokenOut",indexed:!1},{type:"uint256",name:"oraclePrice",indexed:!1},{type:"uint256",name:"exchangeRate",indexed:!1},{type:"uint256",name:"poolTokenPrice",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolFundDistributed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"profits",indexed:!1},{type:"uint256",name:"genesisProfits",indexed:!1},{type:"uint256",name:"basePoolAmount",indexed:!1},{type:"uint256",name:"quotePoolAmount",indexed:!1},{type:"uint256",name:"genesisBasePoolAmount",indexed:!1},{type:"uint256",name:"genesisQuotePoolAmount",indexed:!1},{type:"uint256",name:"exchangedBaseFromProfits",indexed:!1},{type:"uint256",name:"exchangedBaseAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolFundingFeeSettled",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"int256",name:"prevFundingRateTracker",indexed:!1},{type:"int256",name:"nextFundingRateTracker",indexed:!1},{type:"uint256",name:"price",indexed:!1},{type:"uint8",name:"direction",indexed:!1},{type:"uint256",name:"positionSize",indexed:!1},{type:"uint256",name:"fundingFee",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolPreDeactivated",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"string",name:"remark",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolPrimed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint256",name:"baseAmount",indexed:!1},{type:"uint256",name:"quoteAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolRebateClaimed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"address",name:"recipient",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolRefunded",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"receiver",indexed:!1},{type:"address",name:"baseToken",indexed:!1},{type:"address",name:"quoteToken",indexed:!1},{type:"uint256",name:"baseAmount",indexed:!1},{type:"uint256",name:"quoteAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolReprimed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"primer",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolSettlementRecorded",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint256",name:"poolEntryPrice",indexed:!1},{type:"int256",name:"realizedPnl",indexed:!1}]},{type:"event",anonymous:!1,name:"PoolWithdrawn",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"address",name:"recipient",indexed:!1},{type:"address",name:"underlyingToken",indexed:!1},{type:"address",name:"poolToken",indexed:!1},{type:"uint256",name:"poolTokenIn",indexed:!1},{type:"uint256",name:"underlyingOut",indexed:!1},{type:"uint256",name:"rebateOut",indexed:!1},{type:"uint256",name:"oraclePrice",indexed:!1},{type:"uint256",name:"exchangeRate",indexed:!1},{type:"uint256",name:"poolTokenPrice",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionEarlyClosed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"uint256",name:"positionSize",indexed:!1},{type:"uint256",name:"executeSize",indexed:!1},{type:"uint256",name:"executePrice",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionForceClosed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"uint256",name:"positionSize",indexed:!1},{type:"uint256",name:"executePrice",indexed:!1},{type:"string",name:"reason",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionLiquidated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint256",name:"positionSize",indexed:!1},{type:"uint256",name:"liquidationSize",indexed:!1},{type:"uint256",name:"liquidationPrice",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionNFTMinted",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"oldPositionId",indexed:!1},{type:"bytes32",name:"newPositionId",indexed:!1},{type:"uint256",name:"tokenId",indexed:!1},{type:"address",name:"owner",indexed:!1},{type:"address",name:"recipient",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionRiskControlDataMigrated",inputs:[{type:"bytes32",name:"from",indexed:!1},{type:"bytes32",name:"to",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionRiskControlDataUpdated",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"uint256",name:"freeAmount",indexed:!1},{type:"uint256",name:"lockedAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionTransfer",inputs:[{type:"address",name:"from",indexed:!1},{type:"address",name:"to",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1}]},{type:"event",anonymous:!1,name:"PositionUpdated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"owner",indexed:!1},{type:"bytes32",name:"positionId",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"uint8",name:"direction",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"uint256",name:"beforeSize",indexed:!1},{type:"uint256",name:"afterSize",indexed:!1},{type:"uint256",name:"beforeCollateralAmount",indexed:!1},{type:"uint256",name:"afterCollateralAmount",indexed:!1},{type:"uint256",name:"entryPrice",indexed:!1},{type:"int256",name:"fundingRateIndex",indexed:!1},{type:"uint8",name:"riskTier",indexed:!1},{type:"uint256",name:"earlyClosePrice",indexed:!1}]},{type:"event",anonymous:!1,name:"ReferralRebateClaimed",inputs:[{type:"address",name:"user",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReserveRebateCollected",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1},{type:"address",name:"keeper",indexed:!1},{type:"uint256",name:"poolAmount",indexed:!1},{type:"uint256",name:"stakingAmount",indexed:!1},{type:"uint256",name:"keeperAmount",indexed:!1},{type:"uint256",name:"treasuryAmount",indexed:!1},{type:"uint256",name:"reservedAmount",indexed:!1},{type:"uint256",name:"ecoFundAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"ReserveRebateDisbursed",inputs:[{type:"bytes32",name:"poolId",indexed:!1},{type:"address",name:"token",indexed:!1},{type:"uint256",name:"amount",indexed:!1},{type:"address",name:"keeper",indexed:!1},{type:"uint256",name:"poolAmount",indexed:!1},{type:"uint256",name:"stakingAmount",indexed:!1},{type:"uint256",name:"keeperAmount",indexed:!1},{type:"uint256",name:"treasuryAmount",indexed:!1},{type:"uint256",name:"reservedAmount",indexed:!1},{type:"uint256",name:"ecoFundAmount",indexed:!1}]},{type:"event",anonymous:!1,name:"TradingFeeTierUpdated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"uint8",name:"feeType",indexed:!1},{type:"uint8",name:"tier",indexed:!1},{type:"uint32",name:"takerFeeRate",indexed:!1},{type:"int32",name:"makerFeeRate",indexed:!1},{type:"bool",name:"isEnabled",indexed:!1}]},{type:"event",anonymous:!1,name:"Upgraded",inputs:[{type:"address",name:"implementation",indexed:!0}]},{type:"event",anonymous:!1,name:"UserFeeDataUpdated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"signer",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"uint8",name:"tier",indexed:!1},{type:"address",name:"referrer",indexed:!1},{type:"uint32",name:"totalReferralRebatePct",indexed:!1},{type:"uint32",name:"referrerRebatePct",indexed:!1}]},{type:"event",anonymous:!1,name:"UserSettlementRecorded",inputs:[{type:"address",name:"user",indexed:!1},{type:"bytes32",name:"poolId",indexed:!1},{type:"uint256",name:"orderId",indexed:!1},{type:"int256",name:"charge",indexed:!1},{type:"int256",name:"realizedPnl",indexed:!1},{type:"int256",name:"tradingFee",indexed:!1},{type:"int256",name:"fundingFee",indexed:!1}]},{type:"event",anonymous:!1,name:"UserSpecialFeeTierUpdated",inputs:[{type:"address",name:"broker",indexed:!1},{type:"address",name:"user",indexed:!1},{type:"uint8",name:"oldTier",indexed:!1},{type:"uint8",name:"newTier",indexed:!1}]},{type:"function",name:"UPGRADE_INTERFACE_VERSION",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"string"}]},{type:"function",name:"emitCollateralAccepted",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"quoteDebt"},{type:"uint256",name:"baseCollateral"},{type:"uint256",name:"quoteCollateral"},{type:"uint256",name:"totalQuoteDebt"},{type:"uint256",name:"totalBaseCollateral"}]}],outputs:[]},{type:"function",name:"emitCollateralAdjusted",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint8",name:"direction"},{type:"uint256",name:"beforeCollateralAmount"},{type:"uint256",name:"afterCollateralAmount"}]}],outputs:[]},{type:"function",name:"emitEnterDispute",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[]},{type:"function",name:"emitExchanged",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"user"},{type:"address",name:"source"},{type:"address",name:"target"},{type:"uint256",name:"sourceAmount"},{type:"uint256",name:"targetAmount"},{type:"uint256",name:"price"}]}],outputs:[]},{type:"function",name:"emitExecutionMatched",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256[]",name:"triggerOrderIds"},{type:"uint256[]",name:"matchedOrderIds"},{type:"uint8",name:"matchType"},{type:"uint256",name:"price"}]}],outputs:[]},{type:"function",name:"emitExitDispute",constant:!1,payable:!1,inputs:[{type:"bytes32",name:"poolId"}],outputs:[]},{type:"function",name:"emitFundingRateUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"uint64",name:"epochs"},{type:"uint64",name:"duration"},{type:"uint64",name:"previousEpochTime"},{type:"uint64",name:"lastEpochTime"},{type:"bytes32",name:"poolId"},{type:"int256",name:"fundingRate"},{type:"int256",name:"fundingRateTracker"},{type:"uint256",name:"price"}]}],outputs:[]},{type:"function",name:"emitLiquidityLockUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint64",name:"windowAnchor"},{type:"uint256",name:"priceFloor"},{type:"uint256",name:"priceCeiling"},{type:"int256",name:"openInterest"}]}],outputs:[]},{type:"function",name:"emitLiquidityMigrated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"user"},{type:"bytes32",name:"fromPoolId"},{type:"bytes32",name:"toPoolId"},{type:"uint256",name:"lpAmountIn"},{type:"uint256",name:"lpAmountOut"}]}],outputs:[]},{type:"function",name:"emitLiquidityStopOrderCancelled",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"uint256",name:"orderId"},{type:"bytes32",name:"poolId"},{type:"string",name:"reason"}]}],outputs:[]},{type:"function",name:"emitLiquidityStopOrderCreated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"uint256",name:"orderId"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"poolType"},{type:"uint256",name:"amount"},{type:"uint256",name:"triggerPrice"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"minQuoteOut"}]}],outputs:[]},{type:"function",name:"emitLiquidityStopOrderExecuted",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"uint256",name:"orderId"},{type:"bytes32",name:"poolId"},{type:"address",name:"executor"},{type:"uint256",name:"oraclePrice"},{type:"uint256",name:"poolTokenPrice"}]}],outputs:[]},{type:"function",name:"emitMarketCreated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"marketId"},{type:"address",name:"deployer"},{type:"address",name:"quoteToken"},{type:"uint32",name:"baseReserveRatio"},{type:"uint32",name:"quoteReserveRatio"},{type:"uint64",name:"oracleFeeUsd"},{type:"uint64",name:"oracleRefundFeeUsd"},{type:"uint128",name:"poolPrimeThreshold"}]}],outputs:[]},{type:"function",name:"emitOrderCancelled",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"string",name:"remark"}]}],outputs:[]},{type:"function",name:"emitOrderFilled",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint256",name:"orderId"},{type:"uint8",name:"orderType"},{type:"uint256",name:"orderSize"},{type:"uint256",name:"fillSize"},{type:"uint256",name:"filledSize"},{type:"uint256",name:"orderPrice"},{type:"uint256",name:"fillPrice"},{type:"int256",name:"realizedPnl"},{type:"int256",name:"tradingFee"},{type:"int256",name:"fundingFee"},{type:"uint256",name:"executionFeeAmount"},{type:"address",name:"keeper"}]}],outputs:[]},{type:"function",name:"emitOrderMarkedADL",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"uint256",name:"available"},{type:"uint256",name:"requested"}]}],outputs:[]},{type:"function",name:"emitOrderPlaced",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint256",name:"orderId"},{type:"uint8",name:"orderType"},{type:"uint8",name:"operation"},{type:"uint8",name:"direction"},{type:"uint8",name:"triggerType"},{type:"uint256",name:"collateralAmount"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"uint8",name:"tif"},{type:"bool",name:"postOnly"},{type:"uint16",name:"slippagePct"},{type:"uint256",name:"executionFeeAmount"},{type:"uint16",name:"userLeverage"}]}],outputs:[]},{type:"function",name:"emitOrderUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"uint256",name:"size"},{type:"uint256",name:"price"},{type:"uint256",name:"tpSize"},{type:"uint256",name:"tpPrice"},{type:"uint256",name:"slSize"},{type:"uint256",name:"slPrice"}]}],outputs:[]},{type:"function",name:"emitPoolActivated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint8",name:"oracleType"},{type:"bytes32",name:"oracleFeedId"}]}],outputs:[]},{type:"function",name:"emitPoolDeactivated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"string",name:"remark"}]}],outputs:[]},{type:"function",name:"emitPoolDeployed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"marketId"},{type:"bytes32",name:"poolId"},{type:"address",name:"deployer"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"address",name:"basePoolToken"},{type:"address",name:"quotePoolToken"}]}],outputs:[]},{type:"function",name:"emitPoolDeposited",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"address",name:"recipient"},{type:"address",name:"underlyingToken"},{type:"address",name:"poolToken"},{type:"uint256",name:"underlyingIn"},{type:"uint256",name:"poolTokenOut"},{type:"uint256",name:"oraclePrice"},{type:"uint256",name:"exchangeRate"},{type:"uint256",name:"poolTokenPrice"}]}],outputs:[]},{type:"function",name:"emitPoolFundDistributed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"profits"},{type:"uint256",name:"genesisProfits"},{type:"uint256",name:"basePoolAmount"},{type:"uint256",name:"quotePoolAmount"},{type:"uint256",name:"genesisBasePoolAmount"},{type:"uint256",name:"genesisQuotePoolAmount"},{type:"uint256",name:"exchangedBaseFromProfits"},{type:"uint256",name:"exchangedBaseAmount"}]}],outputs:[]},{type:"function",name:"emitPoolFundingFeeSettled",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"int256",name:"prevFundingRateTracker"},{type:"int256",name:"nextFundingRateTracker"},{type:"uint256",name:"price"},{type:"uint8",name:"direction"},{type:"uint256",name:"positionSize"},{type:"uint256",name:"fundingFee"}]}],outputs:[]},{type:"function",name:"emitPoolPreDeactivated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"string",name:"remark"}]}],outputs:[]},{type:"function",name:"emitPoolPrimed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"}]}],outputs:[]},{type:"function",name:"emitPoolRebateClaimed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"address",name:"recipient"},{type:"uint256",name:"amount"}]}],outputs:[]},{type:"function",name:"emitPoolRefunded",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"receiver"},{type:"address",name:"baseToken"},{type:"address",name:"quoteToken"},{type:"uint256",name:"baseAmount"},{type:"uint256",name:"quoteAmount"}]}],outputs:[]},{type:"function",name:"emitPoolReprimed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"primer"},{type:"address",name:"token"},{type:"uint256",name:"amount"}]}],outputs:[]},{type:"function",name:"emitPoolSettlementRecorded",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"uint256",name:"poolEntryPrice"},{type:"int256",name:"realizedPnl"}]}],outputs:[]},{type:"function",name:"emitPoolWithdrawn",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"user"},{type:"address",name:"recipient"},{type:"address",name:"underlyingToken"},{type:"address",name:"poolToken"},{type:"uint256",name:"poolTokenIn"},{type:"uint256",name:"underlyingOut"},{type:"uint256",name:"rebateOut"},{type:"uint256",name:"oraclePrice"},{type:"uint256",name:"exchangeRate"},{type:"uint256",name:"poolTokenPrice"}]}],outputs:[]},{type:"function",name:"emitPositionEarlyClosed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint256",name:"orderId"},{type:"uint256",name:"positionSize"},{type:"uint256",name:"executeSize"},{type:"uint256",name:"executePrice"}]}],outputs:[]},{type:"function",name:"emitPositionForceClosed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint256",name:"orderId"},{type:"uint256",name:"positionSize"},{type:"uint256",name:"executePrice"},{type:"string",name:"reason"}]}],outputs:[]},{type:"function",name:"emitPositionLiquidated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint256",name:"orderId"},{type:"uint256",name:"positionSize"},{type:"uint256",name:"liquidationSize"},{type:"uint256",name:"liquidationPrice"}]}],outputs:[]},{type:"function",name:"emitPositionNFTMinted",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"bytes32",name:"oldPositionId"},{type:"bytes32",name:"newPositionId"},{type:"uint256",name:"tokenId"},{type:"address",name:"owner"},{type:"address",name:"recipient"}]}],outputs:[]},{type:"function",name:"emitPositionRiskControlDataMigrated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"from"},{type:"bytes32",name:"to"}]}],outputs:[]},{type:"function",name:"emitPositionRiskControlDataUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"bytes32",name:"positionId"},{type:"uint256",name:"freeAmount"},{type:"uint256",name:"lockedAmount"}]}],outputs:[]},{type:"function",name:"emitPositionTransfer",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"from"},{type:"address",name:"to"},{type:"bytes32",name:"positionId"}]}],outputs:[]},{type:"function",name:"emitPositionUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"owner"},{type:"bytes32",name:"positionId"},{type:"bytes32",name:"poolId"},{type:"uint8",name:"direction"},{type:"uint256",name:"orderId"},{type:"uint256",name:"beforeSize"},{type:"uint256",name:"afterSize"},{type:"uint256",name:"beforeCollateralAmount"},{type:"uint256",name:"afterCollateralAmount"},{type:"uint256",name:"entryPrice"},{type:"int256",name:"fundingRateIndex"},{type:"uint8",name:"riskTier"},{type:"uint256",name:"earlyClosePrice"}]}],outputs:[]},{type:"function",name:"emitReferralRebateClaimed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"user"},{type:"address",name:"token"},{type:"uint256",name:"amount"}]}],outputs:[]},{type:"function",name:"emitReserveRebateCollected",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"token"},{type:"uint256",name:"amount"},{type:"address",name:"keeper"},{type:"uint256",name:"poolAmount"},{type:"uint256",name:"stakingAmount"},{type:"uint256",name:"keeperAmount"},{type:"uint256",name:"treasuryAmount"},{type:"uint256",name:"reservedAmount"},{type:"uint256",name:"ecoFundAmount"}]}],outputs:[]},{type:"function",name:"emitReserveRebateDisbursed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"bytes32",name:"poolId"},{type:"address",name:"token"},{type:"uint256",name:"amount"},{type:"address",name:"keeper"},{type:"uint256",name:"poolAmount"},{type:"uint256",name:"stakingAmount"},{type:"uint256",name:"keeperAmount"},{type:"uint256",name:"treasuryAmount"},{type:"uint256",name:"reservedAmount"},{type:"uint256",name:"ecoFundAmount"}]}],outputs:[]},{type:"function",name:"emitTradingFeeTierUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"uint8",name:"feeType"},{type:"uint8",name:"tier"},{type:"uint32",name:"takerFeeRate"},{type:"int32",name:"makerFeeRate"},{type:"bool",name:"isEnabled"}]}],outputs:[]},{type:"function",name:"emitUserFeeDataUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"signer"},{type:"address",name:"user"},{type:"uint8",name:"tier"},{type:"address",name:"referrer"},{type:"uint32",name:"totalReferralRebatePct"},{type:"uint32",name:"referrerRebatePct"}]}],outputs:[]},{type:"function",name:"emitUserFeeSettlementAndDistributed",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"user"},{type:"bytes32",name:"poolId"},{type:"uint256",name:"orderId"},{type:"int256",name:"charge"},{type:"int256",name:"realizedPnl"},{type:"int256",name:"tradingFee"},{type:"int256",name:"fundingFee"},{type:"int32",name:"tradingFeeRate"},{type:"bool",name:"isMaker"},{type:"uint256",name:"baseTradingFee"},{type:"uint256",name:"brokerTradingFee"},{type:"address",name:"broker"},{type:"uint256",name:"referralRebate"},{type:"uint256",name:"referrerRebate"},{type:"address",name:"referrer"},{type:"int256",name:"reserveFee"}]}],outputs:[]},{type:"function",name:"emitUserSpecialFeeTierUpdated",constant:!1,payable:!1,inputs:[{type:"tuple",name:"params",components:[{type:"address",name:"broker"},{type:"address",name:"user"},{type:"uint8",name:"oldTier"},{type:"uint8",name:"newTier"}]}],outputs:[]},{type:"function",name:"getAddressManager",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"getDependencyAddress",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"bytes32",name:"identifier"}],outputs:[{type:"address"}]},{type:"function",name:"getImplementation",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"address"}]},{type:"function",name:"initialize",constant:!1,payable:!1,inputs:[{type:"address",name:"addressManager"}],outputs:[]},{type:"function",name:"isBlockHeaderEmitted",constant:!0,stateMutability:"view",payable:!1,inputs:[{type:"uint256",name:"blockNumber"}],outputs:[{type:"bool"}]},{type:"function",name:"proxiableUUID",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"bytes32"}]},{type:"function",name:"registerContract",constant:!1,payable:!1,inputs:[{type:"bytes32[]",name:"identifiers"}],outputs:[]},{type:"function",name:"sequencer",constant:!0,stateMutability:"view",payable:!1,inputs:[],outputs:[{type:"uint256"}]},{type:"function",name:"upgradeTo",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]},{type:"function",name:"upgradeToAndCall",constant:!1,stateMutability:"payable",payable:!0,inputs:[{type:"address",name:"newImplementation"},{type:"bytes",name:"data"}],outputs:[]}];var Ze=class{constructor(e,t){this.configManager=e,this.logger=t}getOrderIdFromTransaction(e){if(!e||!e.logs)return null;for(let t=0;t<e.logs.length;t++){let n=e.logs[t];this.logger.info(`Log ${t}:`,{address:n.address,topics:n.topics,data:n.data});try{let a=Os({abi:ca,data:n.data??"0x",topics:n.topics??[]}),i=a.args;if(a.eventName==="OrderPlaced"&&i?.orderId!=null)return String(i.orderId)}catch{continue}}return null}async getApproveQuoteAmount(e,t,n,a){try{if(!n||typeof n=="string"&&!n.trim())throw new Error("getApproveQuoteAmount: tokenAddress is required (ERC20 contract address)");let i=a??w(t).Account,o=await de(t,n).read.allowance([e,i]);return{code:0,data:String(o)}}catch(i){throw this.logger.error("Error getting allowance:",i),typeof i=="string"?i:await h(i)}}async needsApproval(e,t,n,a,i){try{let o=(await this.getApproveQuoteAmount(e,t,n,i)).data,p=BigInt(o),d=BigInt(a);return p<d}catch(r){return this.logger.error("Error checking approval needs:",r),!0}}async approveAuthorization({chainId:e,quoteAddress:t,amount:n,spenderAddress:a}){try{let i=await Ue(e,t),r=n??Fs,o=a??w(e).Account,p=await this.getGasPriceByRatio(),d=await i.write.approve([o,r],{gasPrice:p});return await g(e).waitForTransactionReceipt({hash:d}),{code:0,message:"Approval success"}}catch(i){return this.logger.error("Approval error:",i),{code:-1,message:i?.message}}}async getUserTradingFeeRate(e,t,n){let a=this.configManager.getConfig(),i=a.brokerAddress;try{let r=xe(n,i),o=a.seamlessMode?a.seamlessAccount?.masterAddress:await this.configManager.getSignerAddress(n),p=await r.read.getUserFeeRate([o,e,t]);return{code:0,data:{takerFeeRate:p[0].toString(),makerFeeRate:p[1].toString(),baseTakerFeeRate:p[2].toString(),baseMakerFeeRate:p[3].toString()}}}catch(r){return this.logger.error("Error getting user trading fee rate:",r),{code:-1,message:r?.message??"Unknown error"}}}async getNetworkFee(e,t){try{return(await(await oe(t,0)).read.getExecutionFee([e])).toString()}catch(n){return this.logger.error("Error getting network fee:",n),"0"}}async getOraclePrice(e,t){try{let n=await z(t,e);if(!n)throw new Error("Failed to get price data");return n}catch(n){throw this.logger.error("Error getting oracle price:",n),n}}async buildUpdatePriceParams(e,t){let n=await this.getOraclePrice(e,t);if(!n)throw new Error("Failed to get price data");return[{poolId:e,oracleUpdateData:n.vaa,publishTime:n.publishTime,oracleType:n.oracleType,value:n.value,price:n.price}]}transferKlineResolutionToInterval(e){switch(e){case"1m":return 1;case"5m":return 5;case"15m":return 15;case"30m":return 30;case"1h":return 60;case"4h":return 240;case"1d":return 1440;case"1w":return 10080;case"1M":return 40320;default:throw new b("PARAM_ERROR",`Invalid kline resolution: ${e}`)}}async getErrorMessage(e,t="Unknown error"){try{if(typeof e=="string")return e;if(e instanceof b)return e.message;let n=await h(e);return n?n.error:JSON.stringify(e)}catch(n){return n?.message??n?.toString()??t}}async checkSeamlessGas(e,t){let n=await oe(t,0),a=Me(t),i=await n.read.getForwardFeeByToken([a]),r=w(t),p=await de(t,r.ERC20).read.balanceOf([e]);return!(BigInt(i)>0n&&BigInt(p)<BigInt(i))}async getLiquidityInfo({chainId:e,poolId:t,marketPrice:n}){try{return{code:0,data:await(await Ae(e,0)).read.getPoolInfo([t,n])}}catch(a){return this.logger.error("Error getting pool info:",a),{code:-1,message:a?.message}}}formatErrorMessage(e){if(typeof e=="string")return e;if(e instanceof b)return e.message;if(e?.code==="ACTION_REJECTED"||e?.code===4001||e?.info?.error?.code===4001||typeof e?.message=="string"&&(e.message.toLowerCase().includes("user rejected")||e.message.toLowerCase().includes("denied")))return"User Rejected";let t=e?.data;if(!t&&e?.message&&typeof e.message=="string"){let n=e.message.match(/data=["'](0x[0-9a-fA-F]+)["']/i);n&&n[1]&&(t=n[1])}if(t){let n=typeof t=="string"&&t.startsWith("0x")?t.slice(0,10).toLowerCase():null;if(n){let a=Object.keys(Ce).find(i=>i.toLowerCase()===n);if(a)return Ce[a]}}return e?.reason?e.reason:e?.message?e.message:JSON.stringify(e)}async getGasPriceByRatio(){let e=this.configManager.getConfig().chainId;return(await E(e)).gasPrice}async getGasLimitByRatio(e){let t=this.configManager.getConfig().chainId,n=C[t];return v(e,n?.gasLimitRatio??1.3)}};import{encodeFunctionData as $t,maxUint256 as Ns,zeroAddress as _s}from"viem";import Ne from"dayjs";var et=class{constructor(e,t,n,a){this.configManager=e,this.logger=t,this.utils=n,this.client=a}async withRetry(e,t=3,n=300){let a;for(let i=0;i<t;i++)try{return await e()}catch(r){a=r,i<t-1&&await new Promise(o=>setTimeout(o,n))}throw a}async getTradeFlow(e,t){let n=await this.configManager.getAccessToken()??"";return{code:0,data:(await this.client.api.getTradeFlow({accessToken:n,...e,address:t})).data}}async getWalletQuoteTokenBalance(e,t){if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER","Invalid signer");let n=w(e),a=de(e,n.ERC20),i=await this.configManager.getSignerAddress(e);return{code:0,data:await a.read.balanceOf([t||i])}}async updateAndWithdraw(e,t,n,a,i){let r=this.configManager.getConfig(),o=w(i);try{let p=this.configManager.getConfig().seamlessAccount?.authorized,d=this.configManager.getConfig().seamlessAccount?.wallet;if(r.seamlessMode&&p&&d){if(!await this.utils.checkSeamlessGas(e,i))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let f=await F(i),y=$t({abi:ke,functionName:"updateAndWithdraw",args:[e,t,!0,a]}),I=await f.read.nonces([d.address]),x={from:d.address??"",to:o.Account,value:"0",gas:"350000",deadline:Ne().add(60,"minute").unix(),data:y,nonce:I.toString()};return{code:0,message:"withdraw success",data:await this.client.seamless.forwarderTx(x,i,d)}}let m=await(await Pt(i)).write.updateAndWithdraw([e,t,n,a]);return{code:0,data:await g(i).waitForTransactionReceipt({hash:m})}}catch(p){return{code:-1,message:p.message}}}async deposit({amount:e,tokenAddress:t,chainId:n}){let a=this.configManager.getConfig(),i=this.configManager.hasSigner()?await this.configManager.getSignerAddress(n):"",r=w(n);try{let o=await this.utils.needsApproval(i,n,t,e,r.Account),p=this.configManager.getConfig().seamlessAccount?.authorized,d=this.configManager.getConfig().seamlessAccount?.wallet;if(a.seamlessMode&&p&&d){if(!await this.utils.checkSeamlessGas(i,n))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let f=await F(n),y=$t({abi:ke,functionName:"deposit",args:[i,t,e]}),I=await f.read.nonces([d.address]),x={from:d.address??"",to:r.Account,value:"0",gas:"350000",deadline:Ne().add(60,"minute").unix(),data:y,nonce:I.toString()};return{code:0,message:"deposit success",data:await this.client.seamless.forwarderTx(x,n,d)}}if(o){let c=await this.utils.approveAuthorization({chainId:n,quoteAddress:t,amount:Ns.toString(),spenderAddress:r.Account});if(c.code!==0)throw new Error(c.message)}let m=await(await Pt(n)).write.deposit([i,t,e]);return{code:0,data:await g(n).waitForTransactionReceipt({hash:m})}}catch(o){return{code:-1,message:o.message}}}async getAvailableMarginBalance({poolId:e,chainId:t,address:n}){try{let a=await this.getAccountInfo(t,n,e);if(a.code!==0)throw new b("REQUEST_FAILED","Failed to get account info");let i=await this.client.appeal.getAppealStatus(e,t,n),r=a.data,o=BigInt(r?.quoteProfit??0),p=BigInt(r?.freeMargin??0),d=BigInt(r?.lockedMargin??0),u=i?.code===0?i.data:null,m=u?.status===1?BigInt(u?.lockedMargin??0):0n;return{code:0,data:p+o-d-m}}catch(a){return{code:-1,message:a.message}}}async getAccountInfo(e,t,n){let a=await Ae(e);try{return{code:0,data:await a.read.getAccountInfo([n,t])}}catch(i){return{code:-1,message:i.message}}}async getAccountVipInfo(e,t){let n=this.configManager.getConfig(),a=xe(e,n.brokerAddress),r=await g(e).getBlock({blockTag:"latest"}),o=Number(r?.timestamp??BigInt(Ne().unix()))+300,p=await this.configManager.getAccessToken()??"";try{let d=await this.client.api.getCurrentEpoch({address:t,accessToken:p,broker:n.brokerAddress});if(d.code!==9200)throw new b("REQUEST_FAILED",d.msg??"Failed to get current epoch");let u=await a.read.userFeeData([d?.data??0,t]),m;try{m=await this.withRetry(()=>a.read.userNonces([t]))}catch{m=0n}return{code:0,data:{...u,nonce:m.toString(),deadline:o}}}catch(d){return{code:-1,message:d.message}}}async getAccountVipInfoByBackend(e,t,n,a){let i=await this.configManager.getAccessToken()??"";try{let r=await this.client.api.getAccountVipInfo({address:e,accessToken:i,chainId:t,deadline:n,nonce:a});if(r.code!==9200)throw new b("REQUEST_FAILED",r.msg??"Failed to get account vip info");return{code:0,data:r.data}}catch(r){return{code:-1,message:r.message}}}async setUserFeeData(e,t,n,a,i){let r=this.configManager.getConfig(),o=this.configManager.getConfig().seamlessAccount?.authorized,p=this.configManager.getConfig().seamlessAccount?.wallet;if(n<Ne().unix())throw new b("REQUEST_FAILED","Invalid deadline, please try again");let d={user:e,nonce:a.nonce,deadline:n,feeData:{tier:a.tier,referrer:a.referrer||_s,totalReferralRebatePct:a.totalReferralRebatePct,referrerRebatePct:a.referrerRebatePct},signature:i};try{if(r.seamlessMode&&o&&p){if(!await this.utils.checkSeamlessGas(e,t))throw new b("INSUFFICIENT_BALANCE","Insufficient relay fee");let y=await F(t),I=$t({abi:O,functionName:"setUserFeeData",args:[d]}),x=await y.read.nonces([p.address]),P={from:p.address??"",to:r.brokerAddress,value:"0",gas:"350000",deadline:Ne().add(60,"minute").unix(),data:I,nonce:x.toString()};return{code:0,data:await this.client.seamless.forwarderTx(P,t,p)}}let u=await V(t,r.brokerAddress),m=await u.read.userNonces([e]);if(parseInt(m.toString())+1!==parseInt(a.nonce.toString()))throw new b("REQUEST_FAILED","Invalid nonce, please try again");let l=await u.write.setUserFeeData([d]);return{code:0,data:await g(t).waitForTransactionReceipt({hash:l})}}catch(u){return{code:-1,message:u.message}}}};function ma(s,e){return`${encodeURIComponent(s)}=${encodeURIComponent(typeof e=="number"?e:`${e}`)}`}function Bs(s,e){return ma(e,s[e])}function Ls(s,e){return s[e].map(n=>ma(e,n)).join("&")}function Us(s){let e=s||{};return Object.keys(e).filter(n=>typeof e[n]<"u").map(n=>Array.isArray(e[n])?Ls(e,n):Bs(e,n)).join("&")}function Ht(s){let e=Us(s);return e?`?${e}`:""}import{merge as tt}from"lodash-es";var nt=class{constructor(e){this.configManager=e}getHost(){let{isTestnet:e,isBetaMode:t}=this.configManager.getConfig();return t?"https://api-beta.myx.finance":e?"https://api-test.myx.cash":"https://api.myx.finance"}async buildAuthParams(){let e=this.configManager.getConfig();if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER");let t=await this.configManager.getAccessToken()??"",n=await this.configManager.getSignerAddress(e.chainId);if(!n)throw new b("INVALID_SIGNER");return{headers:{myx_openapi_access_token:t,myx_openapi_account:n}}}buildRequestPath(e){return e.startsWith("http")?e:this.getHost()+e}async get(e,t,{auth:n=!1,...a}={}){let i=n?await this.buildAuthParams():{};return A.get(this.buildRequestPath(e),t,tt(i,a))}async post(e,t,{auth:n=!1,...a}={}){let i=n?await this.buildAuthParams():{};return A.post(this.buildRequestPath(e),t,tt(i,a))}async put(e,t,{auth:n=!1,...a}={}){let i=n?await this.buildAuthParams():{};return A.put(this.buildRequestPath(e),t,tt(i,a))}async delete(e,{auth:t=!1,...n}={}){let a=t?await this.buildAuthParams():{};return A.delete(this.buildRequestPath(e),tt(a,n))}};var at=class extends nt{constructor(e,t){super(e),this.logger=t}async getTradeFlow({accessToken:e,address:t,...n}){return A.get(`${this.getHost()}/openapi/gateway/scan/trade/flow`,n,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async getPoolSymbolAll(){return A.get(`${this.getHost()}/openapi/gateway/scan/pools`)}async fetchForwarderGetApi(e){return await A.get(`${this.getHost()}/v2/agent/forwarder/get${Ht(e)}`)}async getPoolList(){return A.get(`${this.getHost()}/openapi/gateway/scan/market/list`)}async forwarderTxApi(e,t){return A.post(`${this.getHost()}/v2/agent/forwarder/tx-v2`,e,{headers:{"myx-chain-id":t.toString()}})}async getOraclePrice(e,t=[]){if(t.length)return A.get(`${this.getHost()}/openapi/gateway/quote/price/oracles`,{chainId:e,poolIds:t.join(",")});throw new Error("Invalid pool id")}async getPoolDetail(e,t){return await A.get(`${this.getHost()}/openapi/gateway/scan/market/info?chainId=${e}&poolId=${t}`)}async getPoolLevelConfig({poolId:e,chainId:t}){return A.get(`${this.getHost()}/openapi/gateway/risk/market_pool/level_config${Ht({poolId:e,chainId:t})}`)}async getPositions(e,t){return await A.get(`${this.getHost()}/openapi/gateway/scan/position/open`,void 0,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async getOrders(e,t){return await A.get(`${this.getHost()}/openapi/gateway/scan/order/open`,void 0,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async getPoolOpenOrders(e,t,n){return await A.get(`${this.getHost()}/openapi/gateway/scan/market/pool-order/open?chainId=${n}`,void 0,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async getKlineData({chainId:e,poolId:t,endTime:n,limit:a,interval:i}){return A.get(`${this.getHost()}/openapi/gateway/quote/candles`,{chainId:e,poolId:t,endTime:n,limit:a,interval:i})}async getKlineLatestBar(e){return A.get(`${this.getHost()}/openapi/gateway/quote/candle/latest`,e)}async getTickerData({chainId:e,poolIds:t}){return A.get(`${this.getHost()}/openapi/gateway/quote/candle/tickers`,{chainId:e,poolIds:t.join(",")})}async getAllTickers(){return A.get(`${this.getHost()}/v2/mx-gateway/quote/candle/all_tickers`)}async searchMarketAuth({accessToken:e,address:t,...n}){return A.get(`${this.getHost()}/openapi/gateway/scan/market/ac-search`,n,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async searchMarket({...e}){return A.get(`${this.getHost()}/openapi/gateway/scan/market/search`,e)}async addFavorite({accessToken:e,address:t,...n}){return A.get(`${this.getHost()}/openapi/gateway/scan/market/add-favorites`,n,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async removeFavorite({accessToken:e,address:t,...n}){return A.get(`${this.getHost()}/openapi/gateway/scan/market/cancel-favorites`,n,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async getFavoritesList({accessToken:e,address:t,...n}){return A.get(`${this.getHost()}/openapi/gateway/scan/market/favorites`,n,{headers:{myx_openapi_access_token:e,myx_openapi_account:t}})}async getBaseDetail({...e}){return A.get(`${this.getHost()}/openapi/gateway/scan/market/base-details`,e)}async getMarketDetail({...e}){return A.get(`${this.getHost()}/openapi/gateway/scan/market/detail`,e)}async getHistoryOrders({accessToken:e,address:t,...n}){return A.get(`${this.getHost()}/openapi/gateway/scan/order/closed`,n,{headers:{myx_openapi_account:t,myx_openapi_access_token:e}})}async getPositionHistory({accessToken:e,address:t,...n}){return A.get(`${this.getHost()}/openapi/gateway/scan/position/closed`,n,{headers:{myx_openapi_account:t,myx_openapi_access_token:e}})}async getMarketList(){return A.get(`${this.getHost()}/openapi/gateway/scan/market`)}async getAccountVipInfo({address:e,accessToken:t,chainId:n,deadline:a,nonce:i}){return A.get(`${this.getHost()}/openapi/gateway/vip/trade_config`,{chainId:n,deadline:a,nonce:i},{headers:{myx_openapi_account:e,myx_openapi_access_token:t}})}async getAppealList(e){return this.get("/openapi/gateway/scan/dispute/list",e,{auth:!0})}async getAppealDetail(e){return this.get("/openapi/gateway/scan/dispute/details",e,{auth:!0})}async uploadAppealEvidence(e){return this.get("/openapi/gateway/scan/dispute/upload/evidence",e,{auth:!0})}async getAppealReconsiderationList(e){return this.get("/openapi/gateway/scan/dispute/appeal/list",e,{auth:!0})}async getAppealReconsiderationDetail(e){return this.get("/openapi/gateway/scan/dispute/appeal/details",e,{auth:!0})}async getAppealReimbursementList(e){return this.get("/openapi/gateway/scan/reimbursement/list",e,{auth:!0})}async getAppealNodeVoteList(e){return this.get("/openapi/gateway/scan/node/vote-list",e)}async getAppealNodeVoteDetails(e){return this.get("/openapi/gateway/scan/node/vote-details",e)}async getIsVoteNode(e){return this.get("/openapi/gateway/scan/node/vote-node-check",e)}async postVoteSignature(e){return this.get("/openapi/gateway/scan/node/vote",e,{auth:!0})}async getPedingVoteCount(){return this.get("/openapi/gateway/scan/node/pending-vote-total",{},{auth:!0})}async getMyAppealCount(){return this.get("/openapi/gateway/scan/processing-total",{},{auth:!0})}async getWarmholeSign(e){return this.get("/openapi/gateway/scan/get-warmhole-sign",e,{auth:!0})}async getDisputeTotalCount(){return this.get("/openapi/gateway/scan/dispute/dispute-total",{},{auth:!0})}async getAppealTotalCount(){return this.get("/openapi/gateway/scan/dispute/appeal-total",{},{auth:!0})}async getReimbursementTotalCount(){return this.get("/openapi/gateway/scan/dispute/reimbursement-total",{},{auth:!0})}async getCurrentEpoch({address:e,accessToken:t,broker:n}){return A.get(`${this.getHost()}/openapi/gateway/scan/get-current-epoch`,{broker:n},{headers:{myx_openapi_account:e,myx_openapi_access_token:t}})}async getPoolAppealStatus({poolId:e,chainId:t,address:n,accessToken:a}){return A.get(`${this.getHost()}/openapi/gateway/scan/pool-id-dispute-state?poolId=${e}&chainId=${t}`,{},{headers:{myx_openapi_account:n,myx_openapi_access_token:a}})}};import{AES as st,Utf8 as ge,CBC as it,Pkcs7 as rt}from"crypto-es";import{keccak256 as Gs,hexToBytes as ga,toHex as Qt,isHex as ba,bytesToHex as qs,encodeFunctionData as Ws,zeroAddress as zs,maxUint256 as fa}from"viem";import{privateKeyToAccount as ut}from"viem/accounts";import Vs from"dayjs";var ya=async s=>{try{let e=await s.read.eip712Domain();return{name:e.name,version:e.version,chainId:BigInt(e.chainId),verifyingContract:e.verifyingContract}}catch(e){throw new Error(`Error fetching EIP712 domain: ${e}`)}};var $s={ForwardRequest:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"value",type:"uint256"},{name:"gas",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint48"},{name:"data",type:"bytes"}]},Hs=2,Qs=async s=>{let t=new TextEncoder().encode(s),n=await window.crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(i=>i.toString(16).padStart(2,"0")).join("")},Ks="jAkBlC4~5!6@#$%^";function Js(s){let e=ga(s);if(e.length<65)throw new Error("Invalid signature length");let t=Qt(e.slice(0,32)),n=Qt(e.slice(32,64));return{v:e[64],r:t,s:n}}var js=s=>{let e=new Uint8Array(new TextEncoder().encode(s)),t=qs(e),n=Gs(t),a=ga(n).slice(0,32),i=Qt(a);if(!ba(i)||i.length!==66)throw new b("INVALID_PRIVATE_KEY","Invalid private key generated");let r=ut(i);return{privateKey:i,wallet:r}},ot=s=>{if(s.length>=16)return s;let t=16-s.length,n=Math.ceil(t/s.length),a=s.repeat(n).slice(0,t);return s+a},pt=()=>ge.parse(Ks);async function Ys(s,e,t,n,a,i,r,o){let p=de(e,t),d=await ya(p),[u]=await s.getAddresses();if(!u)throw new b("INVALID_SIGNER","No account for signPermit");let m={Permit:[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]},l={owner:n,spender:a,value:i,nonce:r,deadline:o},c=await s.signTypedData({account:u,domain:{...d,chainId:d.chainId},types:m,primaryType:"Permit",message:l});return Js(c)}var dt=class{constructor(e,t,n,a,i){this.configManager=e,this.logger=t,this.utils=n,this.account=a,this.api=i}async onCheckRelayer(e,t,n){return await(await F(n)).read.isUserRelayerEnabled([e,t])}async getUSDPermitParams(e,t){if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER","Signer is required for permit");let n=await N(t),a=w(t),[i]=await n.getAddresses();if(!i)throw new b("INVALID_SIGNER","No account");let r=de(t,a.ERC20);try{let o=await r.read.nonces([i]),p=await Ys(n,t,a.ERC20,i,a.TRADING_ROUTER,fa,o,e);return[{token:a.ERC20,owner:i,spender:a.TRADING_ROUTER,value:fa.toString(),deadline:e.toString(),v:p.v,r:p.r,s:p.s}]}catch{throw new b("INVALID_PRIVATE_KEY","Invalid private key generated")}}async forwarderTx({from:e,to:t,value:n,gas:a,deadline:i,data:r,nonce:o},p,d){let m=await(await F(p)).read.eip712Domain(),l={name:m.name,version:m.version,chainId:m.chainId,verifyingContract:m.verifyingContract},c=d??await N(p),[f]=await c.getAddresses();if(!f)throw new b("INVALID_SIGNER","Missing signer for forwarderTx");let y=await c.signTypedData({account:f,domain:l,types:$s,primaryType:"ForwardRequest",message:{from:e,to:t,value:BigInt(n),gas:BigInt(a),nonce:BigInt(o),deadline:BigInt(i),data:r}}),I=Me(p);return this.logger.info("forwarderTx-->",{from:e,to:t,value:n,gas:a,nonce:o,data:r,deadline:i,signature:y,forwardFeeToken:I},p),await this.api.forwarderTxApi({from:e,to:t,value:n,gas:a,nonce:o,data:r,deadline:i,signature:y,forwardFeeToken:I},p)}async authorizeSeamlessAccount({approve:e,seamlessAddress:t,chainId:n}){let a=this.configManager.getConfig(),i=this.configManager.hasSigner()?await this.configManager.getSignerAddress(n):"";if(e){let l=await this.account.getWalletQuoteTokenBalance(n,i);this.logger.info("balanceRes-->",l);let c=l.data,f=await oe(n),y=Me(n);this.logger.info("forwardFeeToken-->",y);let I=await f.read.getForwardFeeByToken([y]);this.logger.info("pledgeFee-->",I);let x=BigInt(I)*BigInt(Hs);if(this.logger.info("auth params-->",{gasFee:x,balance:c},n,y),this.logger.info("gasFee > 0 && gasFee > BigInt(balance)-->",x>0&&x>BigInt(c)),x>0&&x>BigInt(c))throw new b("INSUFFICIENT_BALANCE","Insufficient balance")}let r=Vs().add(60,"minute").unix(),o=[];if(e)try{o=await this.getUSDPermitParams(r,n)}catch(l){console.warn("Failed to get USD permit params, proceeding without permit:",l),o=[]}let p=await F(n,1),d=await(await F(n)).read.nonces([i]),u=Ws({abi:ve,functionName:"permitAndApproveForwarder",args:[t,e,o]}),m=await this.forwarderTx({from:i,to:p.address,value:"0",gas:"800000",nonce:d.toString(),data:u,deadline:r},n);if(m.data?.txHash){for(let f=0;f<5;f++)try{if((await this.api.fetchForwarderGetApi({requestId:m.data.requestId})).data?.status===9)return{code:0,data:{seamlessAccount:t,authorized:e}};f<4&&await new Promise(I=>setTimeout(I,1e3))}catch(y){console.error("Poll transaction from chain error:",y),f<4&&await new Promise(I=>setTimeout(I,1e3))}return{code:-1,data:null,message:"Transaction confirmation timeout, please check later"}}else return{code:-1,data:null,message:"Your request timed out, please try again"}}async unLockSeamlessWallet({masterAddress:e,password:t,apiKey:n,chainId:a}){let i=ge.parse(ot(t)),r=pt(),p=st.decrypt(n,i,{iv:r,mode:it,padding:rt}).toString(ge),d=ut(p),u=await this.onCheckRelayer(e,d.address,a);return u||(await this.authorizeSeamlessAccount({approve:!0,seamlessAddress:d.address,chainId:a}),u=!0),this.configManager.updateSeamlessWallet({masterAddress:e,wallet:d,authorized:u}),{code:0,data:{masterAddress:e,seamlessAccount:d.address,authorized:u}}}async exportSeamlessPrivateKey({password:e,apiKey:t}){let n=ge.parse(ot(e)),a=pt(),r=st.decrypt(t,n,{iv:a,mode:it,padding:rt}).toString(ge);if(ut(r).address!==this.configManager.getConfig().seamlessAccount?.wallet?.address)throw new b("INVALID_PRIVATE_KEY","Invalid private key");return{code:0,data:{privateKey:r}}}async importSeamlessPrivateKey({privateKey:e,password:t,chainId:n}){if(!ba(e)||e.length!==66)throw new b("INVALID_PRIVATE_KEY","Invalid private key");let a=ut(e),r=await(await F(n)).read.originAccount([a.address]);if(r===zs)throw new b("INVALID_PRIVATE_KEY","The private key is not a senseless account");let o=await this.onCheckRelayer(r,a.address,n),p=ge.parse(ot(t)),d=pt(),m=st.encrypt(e,p,{iv:d,mode:it,padding:rt}).toString();return this.configManager.updateSeamlessWallet({masterAddress:r,wallet:a,authorized:o}),{code:0,data:{masterAddress:r,seamlessAccount:a.address,authorized:o,apiKey:m}}}async startSeamlessMode({open:e}){return await this.configManager.startSeamlessMode(e),{code:0,data:{open:e}}}async createSeamless({password:e,chainId:t}){if(!this.configManager.hasSigner())throw new b("INVALID_SIGNER","Invalid signer");let n=await N(t),[a]=await n.getAddresses();if(!a)throw new b("INVALID_SIGNER","No account");try{let i=await n.signMessage({account:a,message:`${a}_${e}`}),r=await Qs(i),{privateKey:o,wallet:p}=js(r),d=ge.parse(ot(e)),u=pt(),l=st.encrypt(o,d,{iv:u,mode:it,padding:rt}).toString(),c=await this.onCheckRelayer(a,p.address,t);return this.configManager.updateSeamlessWallet({masterAddress:a,wallet:p,authorized:c}),{code:0,data:{masterAddress:a,seamlessAccount:p.address,authorized:c,apiKey:l}}}catch(i){return{code:-1,message:i.message}}}};import{decodeEventLog as Xs}from"viem";var Re=class{constructor(e){this.client=e}getConfig(){return this.client.getConfigManager()?.getConfig()}getAddressConfig(){let t=this.getConfig()?.chainId;if(!t||!_e(t))throw new b("INVALID_CHAIN_ID","Invalid chain id");return w(t)}getBrokerContract(){let e=this.getConfig();if(!e?.brokerAddress)throw new b("INVALID_BROKER_ADDRESS","Invalid broker address");return xe(e.chainId,e.brokerAddress)}get config(){return this.getConfig()}};var ct=class extends Re{constructor(e,t){super(e),this.configManager=t}getDisputeCourtContract(e=!0){return Tn(this.config.chainId,e?1:0)}getReimbursementContract(e=!0){return Pn(this.config.chainId,e?1:0)}getCaseIdFromReceiptLogs(e,t){let n=t==="DisputeFiled"?"caseId":"appealCaseId";for(let a of e.logs)try{let i=Xs({abi:Ee,data:a.data,topics:a.topics});if(i.eventName===t&&i.args&&n in i.args)return i.args[n]}catch{continue}return null}async submitAppeal(e,t,n){let a=this.configManager.hasSigner()?await this.configManager.getSignerAddress(this.config.chainId):"",i=await this.client.utils.needsApproval(a,this.config.chainId,t,n,this.getAddressConfig().DISPUTE_COURT);this.client.logger.debug("need-approve",i),i&&await this.client.utils.approveAuthorization({chainId:this.config.chainId,quoteAddress:t,spenderAddress:this.getAddressConfig().DISPUTE_COURT});let r=await this.getDisputeCourtContract(),o=await this.client.utils.buildUpdatePriceParams(e,this.config.chainId),p=BigInt(o[0].value.toString()||"1"),d=await r.estimateGas.fileDispute([o,e,t],{value:p}),u=await this.client.utils.getGasLimitByRatio(d),m=await this.client.utils.getGasPriceByRatio(),l=await r.write.fileDispute([o,e,t],{value:p,gasLimit:u,gasPrice:m}),c=await g(this.config.chainId).waitForTransactionReceipt({hash:l}),f=this.getCaseIdFromReceiptLogs(c,"DisputeFiled");if(f==null)throw new b("TRANSACTION_FAILED","DisputeFiledLog not found");return{transaction:c,caseId:f}}async voteForAppeal({caseId:e,validator:t,isFor:n,deadline:a,v:i,r,s:o}){let p=await this.getDisputeCourtContract(),d=await p.estimateGas.vote([e,t,n?1:0,a,i,r,o]),u=await this.client.utils.getGasLimitByRatio(d),m=await this.client.utils.getGasPriceByRatio(),l=await p.write.vote([e,t,n?1:0,a,i,r,o],{gasLimit:u,gasPrice:m});return await g(this.config.chainId).waitForTransactionReceipt({hash:l})}async claimAppealMargin(e){let t=await this.getDisputeCourtContract(),n=await t.estimateGas.claimBond([e]),a=await this.client.utils.getGasLimitByRatio(n),i=await this.client.utils.getGasPriceByRatio(),r=await t.write.claimBond([e],{gasLimit:a,gasPrice:i});return g(this.config.chainId).waitForTransactionReceipt({hash:r})}async claimReimbursement(e,t,n,a){let i=await this.getReimbursementContract(),r=await i.estimateGas.claimReimbursement([e,t,n,a]),o=await this.client.utils.getGasLimitByRatio(r),p=await this.client.utils.getGasPriceByRatio(),d=await i.write.claimReimbursement([e,t,n,a],{gasLimit:o,gasPrice:p});return g(this.config.chainId).waitForTransactionReceipt({hash:d})}async getDisputeConfiguration(){return(await this.getDisputeCourtContract(!1)).read.getDisputeConfiguration()}async submitAppealByVoteNode(e,t,n){let a=await this.getDisputeCourtContract(),i=await this.client.utils.getGasPriceByRatio(),r=await this.client.utils.getGasLimitByRatio(await a.estimateGas.fileDisputeFromStaker([e,t,n])),o=await a.write.fileDisputeFromStaker([e,t,n],{gasLimit:r,gasPrice:i}),p=await g(this.config.chainId).waitForTransactionReceipt({hash:o}),d=this.getCaseIdFromReceiptLogs(p,"DisputeFiled");if(d==null)throw new b("TRANSACTION_FAILED","DisputeFiledLog not found");return{tx:p,caseId:d}}async appealReconsideration(e,t,n){let a=await this.getDisputeCourtContract(),i=this.configManager.hasSigner()?await this.configManager.getSignerAddress(this.config.chainId):"",r=this.getAddressConfig().DISPUTE_COURT;if(await this.client.utils.needsApproval(i,this.config.chainId,t,n,r)){let f=await this.client.utils.approveAuthorization({chainId:this.config.chainId,quoteAddress:t,spenderAddress:r});if(f.code!==0)throw new b("TRANSACTION_FAILED",f.message)}let p=await a.estimateGas.appeal([e]),d=await this.client.utils.getGasLimitByRatio(p),u=await this.client.utils.getGasPriceByRatio(),m=await a.write.appeal([e],{gasLimit:d,gasPrice:u}),l=await g(this.config.chainId).waitForTransactionReceipt({hash:m}),c=this.getCaseIdFromReceiptLogs(l,"AppealFiled");if(c==null)throw new b("TRANSACTION_FAILED","AppealFiledLog not found");return{tx:l,appealCaseId:c,caseId:e}}async getAppealList(e){return this.client.api.getAppealList(e)}async getAppealDetail(e){return this.client.api.getAppealDetail(e)}async uploadAppealEvidence(e){return this.client.api.uploadAppealEvidence(e)}async getAppealReconsiderationList(e){return this.client.api.getAppealReconsiderationList(e)}async getAppealReconsiderationDetail(e){return this.client.api.getAppealReconsiderationDetail(e)}async getAppealReimbursementList(e){return this.client.api.getAppealReimbursementList(e)}async getAppealNodeVoteList(e){return this.client.api.getAppealNodeVoteList(e)}async getAppealNodeVoteDetail(e){return this.client.api.getAppealNodeVoteDetails(e)}async getIsVoteNode(e){return this.client.api.getIsVoteNode(e)}async postVoteSignature(e){return this.client.api.postVoteSignature(e)}async getPedingVoteCount(){return this.client.api.getPedingVoteCount()}async getMyAppealCount(){return this.client.api.getMyAppealCount()}async getWarmholeSign(e){return this.client.api.getWarmholeSign(e)}async getDisputeTotalCount(){return this.client.api.getDisputeTotalCount()}async getAppealTotalCount(){return this.client.api.getAppealTotalCount()}async getReimbursementTotalCount(){return this.client.api.getReimbursementTotalCount()}async getAppealStatus(e,t,n){return this.client.api.getPoolAppealStatus({poolId:e,chainId:t,address:n,accessToken:await this.configManager.getAccessToken()??""})}};var lt=class extends Re{constructor(e){super(e)}async claimRebate(e){let t=this.getConfig(),n=await V(this.config.chainId,t.brokerAddress),a=await n.estimateGas.claimRebate([e]),i=await this.client.utils.getGasLimitByRatio(a),r=await this.client.utils.getGasPriceByRatio(),o=await n.write.claimRebate([e],{gasPrice:r,gasLimit:i});return g(this.config.chainId).waitForTransactionReceipt({hash:o})}};var Zs=(p=>(p[p.UnderReview=1]="UnderReview",p[p.InitialVote=2]="InitialVote",p[p.PublicNotice=3]="PublicNotice",p[p.UnderReconsideration=4]="UnderReconsideration",p[p.Won=5]="Won",p[p.Failed=6]="Failed",p[p.PlatformRuling=7]="PlatformRuling",p[p.PlatformRevoked=8]="PlatformRevoked",p))(Zs||{}),ei=(u=>(u[u.InitialVoting=1]="InitialVoting",u[u.PublicNotice=2]="PublicNotice",u[u.UnderReconsideration=3]="UnderReconsideration",u[u.Won=5]="Won",u[u.Failed=4]="Failed",u[u.PlatformRuling=6]="PlatformRuling",u[u.PlatformRevoked=7]="PlatformRevoked",u[u.ReconsiderationVoting=8]="ReconsiderationVoting",u[u.AppealRevert=9]="AppealRevert",u[u.NotAppealFailed=10]="NotAppealFailed",u))(ei||{}),ti=(a=>(a[a.UnderReview=1]="UnderReview",a[a.PublicNotice=2]="PublicNotice",a[a.UnderReconsideration=3]="UnderReconsideration",a[a.Completed=4]="Completed",a))(ti||{}),ni=(t=>(t[t.ElectionNode=0]="ElectionNode",t[t.OfficialNode=1]="OfficialNode",t))(ni||{}),ai=(t=>(t[t.Reject=0]="Reject",t[t.Support=1]="Support",t))(ai||{}),si=(t=>(t[t.UnClaimed=0]="UnClaimed",t[t.Claimed=1]="Claimed",t))(si||{}),ii=(t=>(t[t.NotVoted=0]="NotVoted",t[t.Voted=1]="Voted",t))(ii||{}),ri=(t=>(t[t.Appeal=1]="Appeal",t[t.Reconsideration=2]="Reconsideration",t))(ri||{}),oi=(n=>(n[n.NoVote=0]="NoVote",n[n.Supported=1]="Supported",n[n.Rejected=2]="Rejected",n))(oi||{}),pi=(t=>(t[t.Yes=1]="Yes",t[t.No=0]="No",t))(pi||{}),la=(t=>(t[t.None=0]="None",t[t.isAppealing=1]="isAppealing",t))(la||{});var Kt=class{getConfigManager(){return this.configManager}constructor(e){this.configManager=new Ke(e),this.logger=new Te({logLevel:e.logLevel});let t=ue.getInstance();t.setConfigManager(this.configManager),Be(this.configManager),t.getMarkets().then(),this.utils=new Ze(this.configManager,this.logger),this.api=new at(this.configManager,this.logger),this.account=new et(this.configManager,this.logger,this.utils,this),this.seamless=new dt(this.configManager,this.logger,this.utils,this.account,this.api),this.markets=new Je(this.configManager,this.utils,this.api),this.position=new je(this.configManager,this.logger,this.utils,this.seamless,this.account,this.api),this.order=new Xe(this.configManager,this.logger,this.utils,this.seamless,this.account,this.api),this.subscription=new He(this.configManager,this.logger),this.appeal=new ct(this,this.configManager),this.referrals=new lt(this)}auth(e){this.configManager.auth(e)}updateClientChainId(e,t){this.configManager.updateClientChainId(e,t)}close(){this.configManager.clear(),this.subscription.disconnect()}async getAccessToken(){return await this.configManager.getAccessToken()}async refreshAccessToken(e=!1){return await this.configManager.refreshAccessToken(e)}};var yf="1.0.3";export{ri as AppealCaseTypeEnum,si as AppealClaimStatusEnum,oi as AppealNodeStateEnum,ii as AppealNodeVotedStateEnum,ei as AppealReconsiderationType,ti as AppealStage,la as AppealStatus,Zs as AppealType,W as COMMON_LP_AMOUNT_DECIMALS,S as COMMON_PRICE_DECIMALS,K as ChainId,Ya as CloseTypeEnum,hm as Direction,Ka as DirectionEnum,Ua as ErrorCode,ja as ExecTypeEnum,Za as ForwarderGetStatus,bn as HttpKlineIntervalEnum,pi as IsVoteNodeEnum,Wa as MarketCapType,he as MarketPoolState,Ga as MarketType,ue as MxSDK,Kt as MyxClient,ni as NodeTypeEnum,$a as OperationEnum,fe as OperationType,gn as OracleType,Am as OrderStatus,Ja as OrderStatusEnum,Ye as OrderType,Va as OrderTypeEnum,yf as SDK_VERSION,za as SearchSecondTypeEnum,qa as SearchTypeEnum,xm as TimeInForce,Xa as TradeFlowAccountTypeEnum,Ha as TradeFlowTypeEnum,Im as TriggerType,Qa as TriggerTypeEnum,ai as VoteTypeEnum,kn as approve,kt as base,ee as bigintAmountSlipperCalculator,E as bigintTradingGasPriceWithRatio,v as bigintTradingGasToRatioCalculator,il as formatUnits,zt as fromViemWalletClient,En as getAllowanceApproved,vn as getBalanceOf,vr as getBaseDetail,ne as getBaseUrlByEnv,Er as getMarketDetail,xn as getMarketList,ae as getOraclePrice,In as getPoolDetail,Cr as getPoolList,hn as getPoolOpenOrders,z as getPriceData,we as getPricesData,g as getPublicClient,Rr as getTickerData,Cc as getTokenInfo,N as getWalletClient,es as getWalletProvider,Ot as market,Qe as normalizeSigner,rl as parseUnits,gs as pool,Dt as quote,Be as setConfigManagerForViem};
2
2
  /**
3
3
  * MyxLogger
4
4
  * @description MyxLogger is a logger for Myx SDK