diff --git a/tests/orderbook/abi/AMM.json b/tests/orderbook/abi/AMM.json index 944412f7f1..77a864d53a 100644 --- a/tests/orderbook/abi/AMM.json +++ b/tests/orderbook/abi/AMM.json @@ -1,1140 +1,1147 @@ [ - { - "inputs": [ - { - "internalType": "address", - "name": "_clearingHouse", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "asks", - "outputs": [ - { - "internalType": "uint256", - "name": "nextTick", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "asksHead", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "bids", - "outputs": [ - { - "internalType": "uint256", - "name": "nextTick", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "bidsHead", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "clearingHouse", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "cumulativePremiumFraction", - "outputs": [ - { - "internalType": "int256", - "name": "", - "type": "int256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "fundingBufferPeriod", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "fundingPeriod", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "trader", - "type": "address" - } - ], - "name": "getNotionalPositionAndUnrealizedPnl", - "outputs": [ - { - "internalType": "uint256", - "name": "notionalPosition", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "unrealizedPnl", - "type": "int256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "int256", - "name": "positionSize", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "openNotional", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "unrealizedPnl", - "type": "int256" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - } - ], - "name": "getOpenNotionalWhileReducingPosition", - "outputs": [ - { - "internalType": "uint256", - "name": "remainOpenNotional", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "realizedPnl", - "type": "int256" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "margin", - "type": "int256" - }, - { - "internalType": "enum IClearingHouse.Mode", - "name": "mode", - "type": "uint8" - } - ], - "name": "getOptimalPnl", - "outputs": [ - { - "internalType": "uint256", - "name": "notionalPosition", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "unrealizedPnl", - "type": "int256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "trader", - "type": "address" - } - ], - "name": "getPendingFundingPayment", - "outputs": [ - { - "internalType": "int256", - "name": "takerFundingPayment", - "type": "int256" - }, - { - "internalType": "int256", - "name": "latestCumulativePremiumFraction", - "type": "int256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "openNotional", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "size", - "type": "int256" - }, - { - "internalType": "int256", - "name": "margin", - "type": "int256" - } - ], - "name": "getPositionMetadata", - "outputs": [ - { - "internalType": "uint256", - "name": "notionalPos", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "uPnl", - "type": "int256" - }, - { - "internalType": "int256", - "name": "marginFraction", - "type": "int256" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [], - "name": "getUnderlyingPrice", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "intervalInSeconds", - "type": "uint256" - } - ], - "name": "getUnderlyingTwapPrice", - "outputs": [ - { - "internalType": "int256", - "name": "", - "type": "int256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "governance", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "impactMarginNotional", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "string", - "name": "_name", - "type": "string" - }, - { - "internalType": "address", - "name": "_underlyingAsset", - "type": "address" - }, - { - "internalType": "address", - "name": "_oracle", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_minSizeRequirement", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_governance", - "type": "address" - } - ], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "interestRate", - "outputs": [ - { - "internalType": "int256", - "name": "", - "type": "int256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "juror", - "outputs": [ - { - "internalType": "contract IJuror", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "lastPrice", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "lastTradePrice", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "fillAmount", - "type": "int256" - } - ], - "name": "liquidatePosition", - "outputs": [ - { - "internalType": "int256", - "name": "realizedPnl", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "quoteAsset", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "size", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "openNotional", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "longOpenInterestNotional", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "markPriceTwapData", - "outputs": [ - { - "internalType": "uint256", - "name": "lastPrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastTimestamp", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "accumulator", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "lastPeriodAccumulator", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "maxFundingRate", - "outputs": [ - { - "internalType": "int256", - "name": "", - "type": "int256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "maxLiquidationPriceSpread", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "maxLiquidationRatio", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "maxOracleSpreadRatio", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "minSizeRequirement", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "name", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "nextFundingTime", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "openInterestNotional", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "fillAmount", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "fulfillPrice", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "is2ndTrade", - "type": "bool" - } - ], - "name": "openPosition", - "outputs": [ - { - "internalType": "int256", - "name": "realizedPnl", - "type": "int256" - }, - { - "internalType": "bool", - "name": "isPositionIncreased", - "type": "bool" - }, - { - "internalType": "int256", - "name": "size", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "openNotional", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "openInterest", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "oracle", - "outputs": [ - { - "internalType": "contract IOracle", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "orderBook", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "piData", - "outputs": [ - { - "internalType": "int256", - "name": "piTwap", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "accTime", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "piLast", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "lastTS", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "positions", - "outputs": [ - { - "internalType": "int256", - "name": "size", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "openNotional", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "lastPremiumFraction", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "liquidationThreshold", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "redStoneAdapter", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "redStoneFeedId", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "samplePI", - "outputs": [ - { - "internalType": "bool", - "name": "success", - "type": "bool" - }, - { - "internalType": "int256", - "name": "premiumIndex", - "type": "int256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_fundingPeriod", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_fundingBufferPeriod", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "_maxFundingRate", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "_spotPriceTwapInterval", - "type": "uint256" - } - ], - "name": "setFundingParams", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "__governance", - "type": "address" - } - ], - "name": "setGovernace", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_impactMarginNotional", - "type": "uint256" - } - ], - "name": "setImpactMarginNotional", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "int256", - "name": "_interestRate", - "type": "int256" - } - ], - "name": "setInterestRate", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_juror", - "type": "address" - } - ], - "name": "setJuror", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_maxLiquidationRatio", - "type": "uint256" - } - ], - "name": "setLiquidationSizeRatio", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_minSizeRequirement", - "type": "uint256" - } - ], - "name": "setMinSizeRequirement", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_oracle", - "type": "address" - }, - { - "internalType": "address", - "name": "_redStoneAdapter", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "_redStoneFeedId", - "type": "bytes32" - } - ], - "name": "setOracleConfig", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_orderBook", - "type": "address" - } - ], - "name": "setOrderBook", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_maxOracleSpreadRatio", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_maxLiquidationPriceSpread", - "type": "uint256" - } - ], - "name": "setPriceSpreadParams", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_redStoneAdapter", - "type": "address" - } - ], - "name": "setRedStoneAdapterAddress", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "settleFunding", - "outputs": [ - { - "internalType": "int256", - "name": "premiumFraction", - "type": "int256" - }, - { - "internalType": "int256", - "name": "underlyingPrice", - "type": "int256" - }, - { - "internalType": "int256", - "name": "", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "shortOpenInterestNotional", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "tick", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "quantity", - "type": "int256" - } - ], - "name": "signalAddLiquidity", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "tick", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "quantity", - "type": "int256" - } - ], - "name": "signalRemoveLiquidity", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "spotPriceTwapInterval", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "startFunding", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "underlyingAsset", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "trader", - "type": "address" - } - ], - "name": "updatePosition", - "outputs": [ - { - "internalType": "bool", - "name": "isUpdated", - "type": "bool" - }, - { - "internalType": "int256", - "name": "fundingPayment", - "type": "int256" - }, - { - "internalType": "int256", - "name": "latestCumulativePremiumFraction", - "type": "int256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - } + { + "inputs": [ + { + "internalType": "address", + "name": "_clearingHouse", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "asks", + "outputs": [ + { + "internalType": "uint256", + "name": "nextTick", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "asksHead", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "bids", + "outputs": [ + { + "internalType": "uint256", + "name": "nextTick", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "bidsHead", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "clearingHouse", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "cumulativePremiumFraction", + "outputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "fundingBufferPeriod", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "fundingPeriod", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trader", + "type": "address" + } + ], + "name": "getNotionalPositionAndUnrealizedPnl", + "outputs": [ + { + "internalType": "uint256", + "name": "notionalPosition", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "unrealizedPnl", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int256", + "name": "positionSize", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "openNotional", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "unrealizedPnl", + "type": "int256" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + } + ], + "name": "getOpenNotionalWhileReducingPosition", + "outputs": [ + { + "internalType": "uint256", + "name": "remainOpenNotional", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "realizedPnl", + "type": "int256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "margin", + "type": "int256" + }, + { + "internalType": "enum IClearingHouse.Mode", + "name": "mode", + "type": "uint8" + } + ], + "name": "getOptimalPnl", + "outputs": [ + { + "internalType": "uint256", + "name": "notionalPosition", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "unrealizedPnl", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trader", + "type": "address" + } + ], + "name": "getPendingFundingPayment", + "outputs": [ + { + "internalType": "int256", + "name": "takerFundingPayment", + "type": "int256" + }, + { + "internalType": "int256", + "name": "latestCumulativePremiumFraction", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "openNotional", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "size", + "type": "int256" + }, + { + "internalType": "int256", + "name": "margin", + "type": "int256" + } + ], + "name": "getPositionMetadata", + "outputs": [ + { + "internalType": "uint256", + "name": "notionalPos", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "uPnl", + "type": "int256" + }, + { + "internalType": "int256", + "name": "marginFraction", + "type": "int256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "getUnderlyingPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "intervalInSeconds", + "type": "uint256" + } + ], + "name": "getUnderlyingTwapPrice", + "outputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "governance", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "impactMarginNotional", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_name", + "type": "string" + }, + { + "internalType": "address", + "name": "_underlyingAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "_oracle", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_minSizeRequirement", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_governance", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "initializev2", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "interestRate", + "outputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "juror", + "outputs": [ + { + "internalType": "contract IJuror", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lastPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "lastTradePrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "fillAmount", + "type": "int256" + } + ], + "name": "liquidatePosition", + "outputs": [ + { + "internalType": "int256", + "name": "realizedPnl", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "quoteAsset", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "size", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "openNotional", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "longOpenInterestNotional", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "markPriceTwapData", + "outputs": [ + { + "internalType": "uint256", + "name": "lastPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastTimestamp", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "accumulator", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lastPeriodAccumulator", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxFundingRate", + "outputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxLiquidationPriceSpread", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxLiquidationRatio", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "maxOracleSpreadRatio", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "minSizeRequirement", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "nextFundingTime", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "openInterestNotional", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "fillAmount", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "fulfillPrice", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "is2ndTrade", + "type": "bool" + } + ], + "name": "openPosition", + "outputs": [ + { + "internalType": "int256", + "name": "realizedPnl", + "type": "int256" + }, + { + "internalType": "bool", + "name": "isPositionIncreased", + "type": "bool" + }, + { + "internalType": "int256", + "name": "size", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "openNotional", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "openInterest", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "oracle", + "outputs": [ + { + "internalType": "contract IOracle", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "orderBook", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "piData", + "outputs": [ + { + "internalType": "int256", + "name": "piTwap", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "accTime", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "piLast", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "lastTS", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "positions", + "outputs": [ + { + "internalType": "int256", + "name": "size", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "openNotional", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "lastPremiumFraction", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "liquidationThreshold", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "redStoneAdapter", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "redStoneFeedId", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "samplePI", + "outputs": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + }, + { + "internalType": "int256", + "name": "premiumIndex", + "type": "int256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_fundingPeriod", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_fundingBufferPeriod", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "_maxFundingRate", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "_spotPriceTwapInterval", + "type": "uint256" + } + ], + "name": "setFundingParams", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "__governance", + "type": "address" + } + ], + "name": "setGovernace", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_impactMarginNotional", + "type": "uint256" + } + ], + "name": "setImpactMarginNotional", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int256", + "name": "_interestRate", + "type": "int256" + } + ], + "name": "setInterestRate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_juror", + "type": "address" + } + ], + "name": "setJuror", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_maxLiquidationRatio", + "type": "uint256" + } + ], + "name": "setLiquidationSizeRatio", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_minSizeRequirement", + "type": "uint256" + } + ], + "name": "setMinSizeRequirement", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_oracle", + "type": "address" + }, + { + "internalType": "address", + "name": "_redStoneAdapter", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "_redStoneFeedId", + "type": "bytes32" + } + ], + "name": "setOracleConfig", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_orderBook", + "type": "address" + } + ], + "name": "setOrderBook", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_maxOracleSpreadRatio", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_maxLiquidationPriceSpread", + "type": "uint256" + } + ], + "name": "setPriceSpreadParams", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_redStoneAdapter", + "type": "address" + } + ], + "name": "setRedStoneAdapterAddress", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "settleFunding", + "outputs": [ + { + "internalType": "int256", + "name": "premiumFraction", + "type": "int256" + }, + { + "internalType": "int256", + "name": "underlyingPrice", + "type": "int256" + }, + { + "internalType": "int256", + "name": "", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "shortOpenInterestNotional", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tick", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "quantity", + "type": "int256" + } + ], + "name": "signalAddLiquidity", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "tick", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "quantity", + "type": "int256" + } + ], + "name": "signalRemoveLiquidity", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "spotPriceTwapInterval", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "startFunding", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "underlyingAsset", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trader", + "type": "address" + } + ], + "name": "updatePosition", + "outputs": [ + { + "internalType": "bool", + "name": "isUpdated", + "type": "bool" + }, + { + "internalType": "int256", + "name": "fundingPayment", + "type": "int256" + }, + { + "internalType": "int256", + "name": "latestCumulativePremiumFraction", + "type": "int256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } ] diff --git a/tests/orderbook/abi/ClearingHouse.json b/tests/orderbook/abi/ClearingHouse.json index 38c9fed6ea..64cfcc9d36 100644 --- a/tests/orderbook/abi/ClearingHouse.json +++ b/tests/orderbook/abi/ClearingHouse.json @@ -1261,4 +1261,4 @@ "stateMutability": "nonpayable", "type": "function" } - ] +] diff --git a/tests/orderbook/abi/Juror.json b/tests/orderbook/abi/Juror.json index a3426cdf02..052a1211a8 100644 --- a/tests/orderbook/abi/Juror.json +++ b/tests/orderbook/abi/Juror.json @@ -1,982 +1,982 @@ [ - { - "inputs": [ - { - "internalType": "address", - "name": "_clearingHouse", - "type": "address" - }, - { - "internalType": "address", - "name": "_defaultOrderBook", - "type": "address" - }, - { - "internalType": "address", - "name": "_governance", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [], - "name": "clearingHouse", - "outputs": [ - { - "internalType": "contract IClearingHouse", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "amm", - "type": "address" - }, - { - "internalType": "int256", - "name": "quoteQuantity", - "type": "int256" - } - ], - "name": "getBaseQuote", - "outputs": [ - { - "internalType": "uint256", - "name": "rate", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint8", - "name": "orderType", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "expireAt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - } - ], - "internalType": "struct IImmediateOrCancelOrders.Order", - "name": "order", - "type": "tuple" - } - ], - "name": "getIOCOrderHash", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_amm", - "type": "address" - }, - { - "internalType": "bool", - "name": "isBid", - "type": "bool" - }, - { - "internalType": "uint256", - "name": "tick", - "type": "uint256" - } - ], - "name": "getPrevTick", - "outputs": [ - { - "internalType": "uint256", - "name": "prevTick", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "amm", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - } - ], - "name": "getQuote", - "outputs": [ - { - "internalType": "uint256", - "name": "rate", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "governance", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "iocOrderBook", - "outputs": [ - { - "internalType": "contract IImmediateOrCancelOrders", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "address", - "name": "sender", - "type": "address" - } - ], - "name": "isTradingAuthority", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "orderBook", - "outputs": [ - { - "internalType": "contract OrderBook", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "orderBookRollup", - "outputs": [ - { - "internalType": "contract IOrderBookRollup", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_amm", - "type": "address" - } - ], - "name": "sampleImpactAsk", - "outputs": [ - { - "internalType": "uint256", - "name": "impactAsk", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_amm", - "type": "address" - } - ], - "name": "sampleImpactBid", - "outputs": [ - { - "internalType": "uint256", - "name": "impactBid", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "__governance", - "type": "address" - } - ], - "name": "setGovernace", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_iocOrderBook", - "type": "address" - } - ], - "name": "setIOCOrderBook", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_orderBookRollup", - "type": "address" - } - ], - "name": "setOrderBookRollup", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - }, - { - "internalType": "bool", - "name": "postOnly", - "type": "bool" - } - ], - "internalType": "struct ILimitOrderBook.OrderV2", - "name": "order", - "type": "tuple" - }, - { - "internalType": "address", - "name": "sender", - "type": "address" - }, - { - "internalType": "bool", - "name": "assertLowMargin", - "type": "bool" - } - ], - "name": "validateCancelLimitOrder", - "outputs": [ - { - "internalType": "string", - "name": "err", - "type": "string" - }, - { - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "components": [ - { - "internalType": "int256", - "name": "unfilledAmount", - "type": "int256" - }, - { - "internalType": "address", - "name": "amm", - "type": "address" - } - ], - "internalType": "struct IOrderHandler.CancelOrderRes", - "name": "res", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint8", - "name": "orderType", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "expireAt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - } - ], - "internalType": "struct IImmediateOrCancelOrders.Order", - "name": "order", - "type": "tuple" - }, - { - "internalType": "enum Juror.Side", - "name": "side", - "type": "uint8" - }, - { - "internalType": "int256", - "name": "fillAmount", - "type": "int256" - } - ], - "name": "validateExecuteIOCOrder", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "blockPlaced", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - } - ], - "internalType": "struct Juror.Metadata", - "name": "metadata", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - }, - { - "internalType": "bool", - "name": "postOnly", - "type": "bool" - } - ], - "internalType": "struct ILimitOrderBook.OrderV2", - "name": "order", - "type": "tuple" - }, - { - "internalType": "enum Juror.Side", - "name": "side", - "type": "uint8" - }, - { - "internalType": "int256", - "name": "fillAmount", - "type": "int256" - } - ], - "name": "validateExecuteLimitOrder", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "blockPlaced", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - } - ], - "internalType": "struct Juror.Metadata", - "name": "metadata", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - }, - { - "internalType": "uint256", - "name": "liquidationAmount", - "type": "uint256" - } - ], - "name": "validateLiquidationOrderAndDetermineFillPrice", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "internalType": "enum IClearingHouse.OrderExecutionMode", - "name": "mode", - "type": "uint8" - } - ], - "internalType": "struct IClearingHouse.Instruction", - "name": "instruction", - "type": "tuple" - }, - { - "internalType": "uint8", - "name": "orderType", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "encodedOrder", - "type": "bytes" - }, - { - "internalType": "uint256", - "name": "fillPrice", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "fillAmount", - "type": "int256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "orderType", - "type": "uint8" - }, - { - "internalType": "bytes", - "name": "orderData", - "type": "bytes" - }, - { - "internalType": "enum Juror.Side", - "name": "side", - "type": "uint8" - }, - { - "internalType": "int256", - "name": "fillAmount", - "type": "int256" - } - ], - "name": "validateOrder", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "blockPlaced", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - } - ], - "internalType": "struct Juror.Metadata", - "name": "metadata", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes[2]", - "name": "data", - "type": "bytes[2]" - }, - { - "internalType": "int256", - "name": "fillAmount", - "type": "int256" - } - ], - "name": "validateOrdersAndDetermineFillPrice", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "internalType": "enum IClearingHouse.OrderExecutionMode", - "name": "mode", - "type": "uint8" - } - ], - "internalType": "struct IClearingHouse.Instruction[2]", - "name": "instructions", - "type": "tuple[2]" - }, - { - "internalType": "uint8[2]", - "name": "orderTypes", - "type": "uint8[2]" - }, - { - "internalType": "bytes[2]", - "name": "encodedOrders", - "type": "bytes[2]" - }, - { - "internalType": "uint256", - "name": "fillPrice", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint8", - "name": "orderType", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "expireAt", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - } - ], - "internalType": "struct IImmediateOrCancelOrders.Order[]", - "name": "orders", - "type": "tuple[]" - }, - { - "internalType": "address", - "name": "sender", - "type": "address" - } - ], - "name": "validatePlaceIOCOrders", - "outputs": [ - { - "internalType": "bytes32[]", - "name": "orderHashes", - "type": "bytes32[]" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - }, - { - "internalType": "bool", - "name": "postOnly", - "type": "bool" - } - ], - "internalType": "struct ILimitOrderBook.OrderV2", - "name": "order", - "type": "tuple" - }, - { - "internalType": "address", - "name": "sender", - "type": "address" - } - ], - "name": "validatePlaceLimitOrder", - "outputs": [ - { - "internalType": "string", - "name": "err", - "type": "string" - }, - { - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "reserveAmount", - "type": "uint256" - }, - { - "internalType": "address", - "name": "amm", - "type": "address" - } - ], - "internalType": "struct IOrderHandler.PlaceOrderRes", - "name": "res", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - } - ], - "name": "verifySigner", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "pure", - "type": "function" - } + { + "inputs": [ + { + "internalType": "address", + "name": "_clearingHouse", + "type": "address" + }, + { + "internalType": "address", + "name": "_defaultOrderBook", + "type": "address" + }, + { + "internalType": "address", + "name": "_governance", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "clearingHouse", + "outputs": [ + { + "internalType": "contract IClearingHouse", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "amm", + "type": "address" + }, + { + "internalType": "int256", + "name": "quoteQuantity", + "type": "int256" + } + ], + "name": "getBaseQuote", + "outputs": [ + { + "internalType": "uint256", + "name": "rate", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint8", + "name": "orderType", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "expireAt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + } + ], + "internalType": "struct IImmediateOrCancelOrders.Order", + "name": "order", + "type": "tuple" + } + ], + "name": "getIOCOrderHash", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_amm", + "type": "address" + }, + { + "internalType": "bool", + "name": "isBid", + "type": "bool" + }, + { + "internalType": "uint256", + "name": "tick", + "type": "uint256" + } + ], + "name": "getPrevTick", + "outputs": [ + { + "internalType": "uint256", + "name": "prevTick", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "amm", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + } + ], + "name": "getQuote", + "outputs": [ + { + "internalType": "uint256", + "name": "rate", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "governance", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "iocOrderBook", + "outputs": [ + { + "internalType": "contract IImmediateOrCancelOrders", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "isTradingAuthority", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "orderBook", + "outputs": [ + { + "internalType": "contract OrderBook", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "orderBookRollup", + "outputs": [ + { + "internalType": "contract IOrderBookRollup", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_amm", + "type": "address" + } + ], + "name": "sampleImpactAsk", + "outputs": [ + { + "internalType": "uint256", + "name": "impactAsk", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_amm", + "type": "address" + } + ], + "name": "sampleImpactBid", + "outputs": [ + { + "internalType": "uint256", + "name": "impactBid", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "__governance", + "type": "address" + } + ], + "name": "setGovernace", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_iocOrderBook", + "type": "address" + } + ], + "name": "setIOCOrderBook", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_orderBookRollup", + "type": "address" + } + ], + "name": "setOrderBookRollup", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + }, + { + "internalType": "bool", + "name": "postOnly", + "type": "bool" + } + ], + "internalType": "struct ILimitOrderBook.OrderV2", + "name": "order", + "type": "tuple" + }, + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "bool", + "name": "assertLowMargin", + "type": "bool" + } + ], + "name": "validateCancelLimitOrder", + "outputs": [ + { + "internalType": "string", + "name": "err", + "type": "string" + }, + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "components": [ + { + "internalType": "int256", + "name": "unfilledAmount", + "type": "int256" + }, + { + "internalType": "address", + "name": "amm", + "type": "address" + } + ], + "internalType": "struct IOrderHandler.CancelOrderRes", + "name": "res", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint8", + "name": "orderType", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "expireAt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + } + ], + "internalType": "struct IImmediateOrCancelOrders.Order", + "name": "order", + "type": "tuple" + }, + { + "internalType": "enum Juror.Side", + "name": "side", + "type": "uint8" + }, + { + "internalType": "int256", + "name": "fillAmount", + "type": "int256" + } + ], + "name": "validateExecuteIOCOrder", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "blockPlaced", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + } + ], + "internalType": "struct Juror.Metadata", + "name": "metadata", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + }, + { + "internalType": "bool", + "name": "postOnly", + "type": "bool" + } + ], + "internalType": "struct ILimitOrderBook.OrderV2", + "name": "order", + "type": "tuple" + }, + { + "internalType": "enum Juror.Side", + "name": "side", + "type": "uint8" + }, + { + "internalType": "int256", + "name": "fillAmount", + "type": "int256" + } + ], + "name": "validateExecuteLimitOrder", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "blockPlaced", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + } + ], + "internalType": "struct Juror.Metadata", + "name": "metadata", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "liquidationAmount", + "type": "uint256" + } + ], + "name": "validateLiquidationOrderAndDetermineFillPrice", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "internalType": "enum IClearingHouse.OrderExecutionMode", + "name": "mode", + "type": "uint8" + } + ], + "internalType": "struct IClearingHouse.Instruction", + "name": "instruction", + "type": "tuple" + }, + { + "internalType": "uint8", + "name": "orderType", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "encodedOrder", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "fillPrice", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "fillAmount", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "orderType", + "type": "uint8" + }, + { + "internalType": "bytes", + "name": "orderData", + "type": "bytes" + }, + { + "internalType": "enum Juror.Side", + "name": "side", + "type": "uint8" + }, + { + "internalType": "int256", + "name": "fillAmount", + "type": "int256" + } + ], + "name": "validateOrder", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "blockPlaced", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + } + ], + "internalType": "struct Juror.Metadata", + "name": "metadata", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes[2]", + "name": "data", + "type": "bytes[2]" + }, + { + "internalType": "int256", + "name": "fillAmount", + "type": "int256" + } + ], + "name": "validateOrdersAndDetermineFillPrice", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "internalType": "enum IClearingHouse.OrderExecutionMode", + "name": "mode", + "type": "uint8" + } + ], + "internalType": "struct IClearingHouse.Instruction[2]", + "name": "instructions", + "type": "tuple[2]" + }, + { + "internalType": "uint8[2]", + "name": "orderTypes", + "type": "uint8[2]" + }, + { + "internalType": "bytes[2]", + "name": "encodedOrders", + "type": "bytes[2]" + }, + { + "internalType": "uint256", + "name": "fillPrice", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint8", + "name": "orderType", + "type": "uint8" + }, + { + "internalType": "uint256", + "name": "expireAt", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + } + ], + "internalType": "struct IImmediateOrCancelOrders.Order[]", + "name": "orders", + "type": "tuple[]" + }, + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "validatePlaceIOCOrders", + "outputs": [ + { + "internalType": "bytes32[]", + "name": "orderHashes", + "type": "bytes32[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + }, + { + "internalType": "bool", + "name": "postOnly", + "type": "bool" + } + ], + "internalType": "struct ILimitOrderBook.OrderV2", + "name": "order", + "type": "tuple" + }, + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "validatePlaceLimitOrder", + "outputs": [ + { + "internalType": "string", + "name": "err", + "type": "string" + }, + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "reserveAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "amm", + "type": "address" + } + ], + "internalType": "struct IOrderHandler.PlaceOrderRes", + "name": "res", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "verifySigner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "pure", + "type": "function" + } ] diff --git a/tests/orderbook/abi/MarginAccount.json b/tests/orderbook/abi/MarginAccount.json index d8609e5f3a..d88396ff6f 100644 --- a/tests/orderbook/abi/MarginAccount.json +++ b/tests/orderbook/abi/MarginAccount.json @@ -1,1023 +1,1074 @@ [ { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "_trustedForwarder", - "type": "address" + "internalType": "address", + "name": "_trustedForwarder", + "type": "address" } - ], - "stateMutability": "nonpayable", - "type": "constructor" + ], + "stateMutability": "nonpayable", + "type": "constructor" }, { - "inputs": [ + "inputs": [ { - "internalType": "enum IMarginAccount.LiquidationStatus", - "name": "", - "type": "uint8" + "internalType": "enum IMarginAccount.LiquidationStatus", + "name": "", + "type": "uint8" } - ], - "name": "NOT_LIQUIDATABLE", - "type": "error" + ], + "name": "NOT_LIQUIDATABLE", + "type": "error" }, { - "anonymous": false, - "inputs": [ + "anonymous": false, + "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" }, { - "indexed": true, - "internalType": "uint256", - "name": "idx", - "type": "uint256" + "indexed": true, + "internalType": "uint256", + "name": "idx", + "type": "uint256" }, { - "indexed": false, - "internalType": "uint256", - "name": "seizeAmount", - "type": "uint256" + "indexed": false, + "internalType": "uint256", + "name": "seizeAmount", + "type": "uint256" }, { - "indexed": false, - "internalType": "uint256", - "name": "repayAmount", - "type": "uint256" + "indexed": false, + "internalType": "uint256", + "name": "repayAmount", + "type": "uint256" }, { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" } - ], - "name": "MarginAccountLiquidated", - "type": "event" + ], + "name": "MarginAccountLiquidated", + "type": "event" }, { - "anonymous": false, - "inputs": [ + "anonymous": false, + "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" }, { - "indexed": true, - "internalType": "uint256", - "name": "idx", - "type": "uint256" + "indexed": true, + "internalType": "uint256", + "name": "idx", + "type": "uint256" }, { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" }, { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" } - ], - "name": "MarginAdded", - "type": "event" + ], + "name": "MarginAdded", + "type": "event" }, { - "anonymous": false, - "inputs": [ + "anonymous": false, + "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" }, { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" } - ], - "name": "MarginReleased", - "type": "event" + ], + "name": "MarginReleased", + "type": "event" }, { - "anonymous": false, - "inputs": [ + "anonymous": false, + "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" }, { - "indexed": true, - "internalType": "uint256", - "name": "idx", - "type": "uint256" + "indexed": true, + "internalType": "uint256", + "name": "idx", + "type": "uint256" }, { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" }, { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" } - ], - "name": "MarginRemoved", - "type": "event" + ], + "name": "MarginRemoved", + "type": "event" }, { - "anonymous": false, - "inputs": [ + "anonymous": false, + "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" }, { - "indexed": false, - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" } - ], - "name": "MarginReserved", - "type": "event" + ], + "name": "MarginReserved", + "type": "event" }, { - "anonymous": false, - "inputs": [ + "anonymous": false, + "inputs": [ { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" } - ], - "name": "Paused", - "type": "event" + ], + "name": "Paused", + "type": "event" }, { - "anonymous": false, - "inputs": [ + "anonymous": false, + "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" }, { - "indexed": false, - "internalType": "int256", - "name": "realizedPnl", - "type": "int256" + "indexed": false, + "internalType": "int256", + "name": "realizedPnl", + "type": "int256" }, { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" } - ], - "name": "PnLRealized", - "type": "event" + ], + "name": "PnLRealized", + "type": "event" }, { - "anonymous": false, - "inputs": [ + "anonymous": false, + "inputs": [ { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" }, { - "indexed": false, - "internalType": "uint256[]", - "name": "seized", - "type": "uint256[]" + "indexed": false, + "internalType": "uint256[]", + "name": "seized", + "type": "uint256[]" }, { - "indexed": false, - "internalType": "uint256", - "name": "repayAmount", - "type": "uint256" + "indexed": false, + "internalType": "uint256", + "name": "repayAmount", + "type": "uint256" }, { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" } - ], - "name": "SettledBadDebt", - "type": "event" + ], + "name": "SettledBadDebt", + "type": "event" }, { - "anonymous": false, - "inputs": [ + "anonymous": false, + "inputs": [ { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" } - ], - "name": "Unpaused", - "type": "event" + ], + "name": "Unpaused", + "type": "event" }, { - "inputs": [ + "inputs": [ { - "internalType": "uint256", - "name": "idx", - "type": "uint256" + "internalType": "uint256", + "name": "idx", + "type": "uint256" }, { - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "internalType": "uint256", + "name": "amount", + "type": "uint256" } - ], - "name": "addMargin", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "addMargin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "uint256", - "name": "idx", - "type": "uint256" + "internalType": "uint256", + "name": "idx", + "type": "uint256" }, { - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "internalType": "uint256", + "name": "amount", + "type": "uint256" }, { - "internalType": "address", - "name": "to", - "type": "address" + "internalType": "address", + "name": "to", + "type": "address" } - ], - "name": "addMarginFor", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "addMarginFor", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [], - "name": "bibliophile", - "outputs": [ + "inputs": [], + "name": "bibliophile", + "outputs": [ { - "internalType": "contract IHubbleBibliophile", - "name": "", - "type": "address" + "internalType": "contract IHubbleBibliophile", + "name": "", + "type": "address" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "uint256", - "name": "idx", - "type": "uint256" + "internalType": "uint256", + "name": "idx", + "type": "uint256" }, { - "internalType": "uint256", - "name": "_weight", - "type": "uint256" + "internalType": "uint256", + "name": "_weight", + "type": "uint256" } - ], - "name": "changeCollateralWeight", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "changeCollateralWeight", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [], - "name": "clearingHouse", - "outputs": [ + "inputs": [], + "name": "clearingHouse", + "outputs": [ { - "internalType": "contract IClearingHouse", - "name": "", - "type": "address" + "internalType": "contract IClearingHouse", + "name": "", + "type": "address" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [], - "name": "credit", - "outputs": [ + "inputs": [], + "name": "credit", + "outputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "uint256", + "name": "", + "type": "uint256" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" } - ], - "name": "getAvailableMargin", - "outputs": [ + ], + "name": "getAvailableMargin", + "outputs": [ { - "internalType": "int256", - "name": "availableMargin", - "type": "int256" + "internalType": "int256", + "name": "availableMargin", + "type": "int256" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "uint256", + "name": "idx", + "type": "uint256" } - ], - "name": "getNormalizedMargin", - "outputs": [ + ], + "name": "getCollateralToken", + "outputs": [ { - "internalType": "int256", - "name": "weighted", - "type": "int256" + "internalType": "contract IERC20", + "name": "", + "type": "address" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" } - ], - "name": "getSpotCollateralValue", - "outputs": [ + ], + "name": "getNormalizedMargin", + "outputs": [ { - "internalType": "int256", - "name": "spot", - "type": "int256" + "internalType": "int256", + "name": "weighted", + "type": "int256" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [], - "name": "governance", - "outputs": [ + "inputs": [ { - "internalType": "address", - "name": "", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" } - ], - "stateMutability": "view", - "type": "function" + ], + "name": "getSpotCollateralValue", + "outputs": [ + { + "internalType": "int256", + "name": "spot", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "governance", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "_governance", - "type": "address" + "internalType": "address", + "name": "_governance", + "type": "address" }, { - "internalType": "address", - "name": "_vusd", - "type": "address" + "internalType": "address", + "name": "_vusd", + "type": "address" } - ], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [], - "name": "insuranceFund", - "outputs": [ + "inputs": [], + "name": "insuranceFund", + "outputs": [ { - "internalType": "contract IInsuranceFund", - "name": "", - "type": "address" + "internalType": "contract IInsuranceFund", + "name": "", + "type": "address" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" }, { - "internalType": "bool", - "name": "includeFunding", - "type": "bool" + "internalType": "bool", + "name": "includeFunding", + "type": "bool" } - ], - "name": "isLiquidatable", - "outputs": [ + ], + "name": "isLiquidatable", + "outputs": [ { - "internalType": "enum IMarginAccount.LiquidationStatus", - "name": "_isLiquidatable", - "type": "uint8" + "internalType": "enum IMarginAccount.LiquidationStatus", + "name": "_isLiquidatable", + "type": "uint8" }, { - "internalType": "uint256", - "name": "repayAmount", - "type": "uint256" + "internalType": "uint256", + "name": "repayAmount", + "type": "uint256" }, { - "internalType": "uint256", - "name": "incentivePerDollar", - "type": "uint256" + "internalType": "uint256", + "name": "incentivePerDollar", + "type": "uint256" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "forwarder", - "type": "address" + "internalType": "address", + "name": "forwarder", + "type": "address" } - ], - "name": "isTrustedForwarder", - "outputs": [ + ], + "name": "isTrustedForwarder", + "outputs": [ { - "internalType": "bool", - "name": "", - "type": "bool" + "internalType": "bool", + "name": "", + "type": "bool" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" }, { - "internalType": "uint256", - "name": "repay", - "type": "uint256" + "internalType": "uint256", + "name": "repay", + "type": "uint256" }, { - "internalType": "uint256", - "name": "idx", - "type": "uint256" + "internalType": "uint256", + "name": "idx", + "type": "uint256" }, { - "internalType": "uint256", - "name": "minSeizeAmount", - "type": "uint256" + "internalType": "uint256", + "name": "minSeizeAmount", + "type": "uint256" } - ], - "name": "liquidateExactRepay", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "liquidateExactRepay", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" }, { - "internalType": "uint256", - "name": "maxRepay", - "type": "uint256" + "internalType": "uint256", + "name": "maxRepay", + "type": "uint256" }, { - "internalType": "uint256", - "name": "idx", - "type": "uint256" + "internalType": "uint256", + "name": "idx", + "type": "uint256" }, { - "internalType": "uint256", - "name": "seize", - "type": "uint256" + "internalType": "uint256", + "name": "seize", + "type": "uint256" } - ], - "name": "liquidateExactSeize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "liquidateExactSeize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" }, { - "internalType": "uint256", - "name": "maxRepay", - "type": "uint256" + "internalType": "uint256", + "name": "maxRepay", + "type": "uint256" }, { - "internalType": "uint256[]", - "name": "idxs", - "type": "uint256[]" + "internalType": "uint256[]", + "name": "idxs", + "type": "uint256[]" } - ], - "name": "liquidateFlexible", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "liquidateFlexible", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [], - "name": "liquidationIncentive", - "outputs": [ + "inputs": [], + "name": "liquidationIncentive", + "outputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "uint256", + "name": "", + "type": "uint256" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "uint256", + "name": "", + "type": "uint256" }, { - "internalType": "address", - "name": "", - "type": "address" + "internalType": "address", + "name": "", + "type": "address" } - ], - "name": "margin", - "outputs": [ + ], + "name": "margin", + "outputs": [ { - "internalType": "int256", - "name": "", - "type": "int256" + "internalType": "int256", + "name": "", + "type": "int256" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [], - "name": "marginAccountHelper", - "outputs": [ + "inputs": [], + "name": "marginAccountHelper", + "outputs": [ { - "internalType": "address", - "name": "", - "type": "address" + "internalType": "address", + "name": "", + "type": "address" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [], - "name": "minAllowableMargin", - "outputs": [ + "inputs": [], + "name": "minAllowableMargin", + "outputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "uint256", + "name": "", + "type": "uint256" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [], - "name": "oracle", - "outputs": [ + "inputs": [], + "name": "oracle", + "outputs": [ { - "internalType": "contract IOracle", - "name": "", - "type": "address" + "internalType": "contract IOracle", + "name": "", + "type": "address" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [], - "name": "orderBook", - "outputs": [ + "inputs": [], + "name": "orderBook", + "outputs": [ { - "internalType": "contract IOrderBook", - "name": "", - "type": "address" + "internalType": "address", + "name": "", + "type": "address" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [], - "name": "pause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + "inputs": [], + "name": "pause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [], - "name": "paused", - "outputs": [ + "inputs": [], + "name": "paused", + "outputs": [ { - "internalType": "bool", - "name": "", - "type": "bool" + "internalType": "bool", + "name": "", + "type": "bool" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" }, { - "internalType": "int256", - "name": "realizedPnl", - "type": "int256" + "internalType": "int256", + "name": "realizedPnl", + "type": "int256" } - ], - "name": "realizePnL", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "realizePnL", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" }, { - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "internalType": "uint256", + "name": "amount", + "type": "uint256" } - ], - "name": "releaseMargin", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "releaseMargin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "uint256", - "name": "idx", - "type": "uint256" + "internalType": "uint256", + "name": "idx", + "type": "uint256" }, { - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "internalType": "uint256", + "name": "amount", + "type": "uint256" } - ], - "name": "removeMargin", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "removeMargin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "uint256", - "name": "idx", - "type": "uint256" + "internalType": "uint256", + "name": "idx", + "type": "uint256" }, { - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "internalType": "uint256", + "name": "amount", + "type": "uint256" }, { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" } - ], - "name": "removeMarginFor", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "removeMarginFor", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" }, { - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "internalType": "uint256", + "name": "amount", + "type": "uint256" } - ], - "name": "reserveMargin", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "reserveMargin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "", - "type": "address" + "internalType": "address", + "name": "", + "type": "address" } - ], - "name": "reservedMargin", - "outputs": [ + ], + "name": "reservedMargin", + "outputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "uint256", + "name": "", + "type": "uint256" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "_bibliophile", - "type": "address" + "internalType": "address", + "name": "_bibliophile", + "type": "address" } - ], - "name": "setBibliophile", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "setBibliophile", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "__governance", - "type": "address" + "internalType": "address", + "name": "__governance", + "type": "address" } - ], - "name": "setGovernace", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "setGovernace", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" } - ], - "name": "settleBadDebt", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "settleBadDebt", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [], - "name": "supportedAssets", - "outputs": [ + "inputs": [], + "name": "supportedAssets", + "outputs": [ { - "components": [ + "components": [ { - "internalType": "contract IERC20", - "name": "token", - "type": "address" + "internalType": "contract IERC20", + "name": "token", + "type": "address" }, { - "internalType": "uint256", - "name": "weight", - "type": "uint256" + "internalType": "uint256", + "name": "weight", + "type": "uint256" }, { - "internalType": "uint8", - "name": "decimals", - "type": "uint8" + "internalType": "uint8", + "name": "decimals", + "type": "uint8" } - ], - "internalType": "struct IMarginAccount.Collateral[]", - "name": "", - "type": "tuple[]" + ], + "internalType": "struct IMarginAccount.Collateral[]", + "name": "", + "type": "tuple[]" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [], - "name": "supportedAssetsLen", - "outputs": [ + "inputs": [], + "name": "supportedAssetsLen", + "outputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "uint256", + "name": "", + "type": "uint256" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "uint256", - "name": "", - "type": "uint256" + "internalType": "uint256", + "name": "", + "type": "uint256" } - ], - "name": "supportedCollateral", - "outputs": [ + ], + "name": "supportedCollateral", + "outputs": [ { - "internalType": "contract IERC20", - "name": "token", - "type": "address" + "internalType": "contract IERC20", + "name": "token", + "type": "address" }, { - "internalType": "uint256", - "name": "weight", - "type": "uint256" + "internalType": "uint256", + "name": "weight", + "type": "uint256" }, { - "internalType": "uint8", - "name": "decimals", - "type": "uint8" + "internalType": "uint8", + "name": "decimals", + "type": "uint8" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "_registry", - "type": "address" + "internalType": "address", + "name": "_registry", + "type": "address" }, { - "internalType": "uint256", - "name": "_liquidationIncentive", - "type": "uint256" + "internalType": "uint256", + "name": "_liquidationIncentive", + "type": "uint256" + } + ], + "name": "syncDeps", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_settler", + "type": "address" } - ], - "name": "syncDeps", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "toggleTrustedSettler", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "recipient", - "type": "address" + "internalType": "address", + "name": "recipient", + "type": "address" }, { - "internalType": "uint256", - "name": "amount", - "type": "uint256" + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferOutVusd", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "trustedSettlers", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" } - ], - "name": "transferOutVusd", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [], - "name": "unpause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "uint256", - "name": "_minAllowableMargin", - "type": "uint256" + "internalType": "uint256", + "name": "_minAllowableMargin", + "type": "uint256" } - ], - "name": "updateParams", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "updateParams", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "inputs": [], - "name": "vusd", - "outputs": [ + "inputs": [], + "name": "vusd", + "outputs": [ { - "internalType": "contract IERC20FlexibleSupply", - "name": "", - "type": "address" + "internalType": "contract IERC20FlexibleSupply", + "name": "", + "type": "address" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "trader", - "type": "address" + "internalType": "address", + "name": "trader", + "type": "address" } - ], - "name": "weightedAndSpotCollateral", - "outputs": [ + ], + "name": "weightedAndSpotCollateral", + "outputs": [ { - "internalType": "int256", - "name": "weighted", - "type": "int256" + "internalType": "int256", + "name": "weighted", + "type": "int256" }, { - "internalType": "int256", - "name": "spot", - "type": "int256" + "internalType": "int256", + "name": "spot", + "type": "int256" } - ], - "stateMutability": "view", - "type": "function" + ], + "stateMutability": "view", + "type": "function" }, { - "inputs": [ + "inputs": [ { - "internalType": "address", - "name": "_coin", - "type": "address" + "internalType": "address", + "name": "_coin", + "type": "address" }, { - "internalType": "uint256", - "name": "_weight", - "type": "uint256" + "internalType": "uint256", + "name": "_weight", + "type": "uint256" } - ], - "name": "whitelistCollateral", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + ], + "name": "whitelistCollateral", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" }, { - "stateMutability": "payable", - "type": "receive" + "stateMutability": "payable", + "type": "receive" } ] diff --git a/tests/orderbook/abi/OrderBook.json b/tests/orderbook/abi/OrderBook.json index 5ef8834043..604efeee8c 100644 --- a/tests/orderbook/abi/OrderBook.json +++ b/tests/orderbook/abi/OrderBook.json @@ -1,1580 +1,1667 @@ [ - { - "inputs": [ - { - "internalType": "address", - "name": "_clearingHouse", - "type": "address" - }, - { - "internalType": "address", - "name": "_marginAccount", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "version", - "type": "uint8" - } - ], - "name": "Initialized", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "string", - "name": "err", - "type": "string" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "toLiquidate", - "type": "uint256" - } - ], - "name": "LiquidationError", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "fillAmount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "openInterestNotional", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "address", - "name": "relayer", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - } - ], - "name": "LiquidationOrderMatched", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - }, - { - "internalType": "bool", - "name": "postOnly", - "type": "bool" - } - ], - "indexed": false, - "internalType": "struct ILimitOrderBook.OrderV2", - "name": "order", - "type": "tuple" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - } - ], - "name": "OrderAccepted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - } - ], - "name": "OrderCancelAccepted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "string", - "name": "err", - "type": "string" - } - ], - "name": "OrderCancelRejected", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - } - ], - "name": "OrderCancelled", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "fillAmount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "openInterestNotional", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - } - ], - "name": "OrderMatched", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "string", - "name": "err", - "type": "string" - } - ], - "name": "OrderMatchingError", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - } - ], - "indexed": false, - "internalType": "struct ILimitOrderBook.Order", - "name": "order", - "type": "tuple" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - } - ], - "name": "OrderPlaced", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - }, - { - "internalType": "bool", - "name": "postOnly", - "type": "bool" - } - ], - "indexed": false, - "internalType": "struct ILimitOrderBook.OrderV2", - "name": "order", - "type": "tuple" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "string", - "name": "err", - "type": "string" - } - ], - "name": "OrderRejected", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash0", - "type": "bytes32" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash1", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "fillAmount", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "openInterestNotional", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "address", - "name": "relayer", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - } - ], - "name": "OrdersMatched", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Paused", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "timestamp", - "type": "uint256" - } - ], - "name": "SkippedCancelOrder", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "authority", - "type": "address" - } - ], - "name": "TradingAuthorityRevoked", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "authority", - "type": "address" - } - ], - "name": "TradingAuthorityWhitelisted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Unpaused", - "type": "event" - }, - { - "inputs": [], - "name": "ORDER_TYPEHASH", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "address", - "name": "sender", - "type": "address" - } - ], - "name": "assertTradingAuthority", - "outputs": [], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "bibliophile", - "outputs": [ - { - "internalType": "contract IHubbleBibliophile", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - }, - { - "internalType": "bool", - "name": "postOnly", - "type": "bool" - } - ], - "internalType": "struct ILimitOrderBook.OrderV2[]", - "name": "orders", - "type": "tuple[]" - } - ], - "name": "cancelOrders", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - }, - { - "internalType": "bool", - "name": "postOnly", - "type": "bool" - } - ], - "internalType": "struct ILimitOrderBook.OrderV2[]", - "name": "orders", - "type": "tuple[]" - } - ], - "name": "cancelOrdersWithLowMargin", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "clearingHouse", - "outputs": [ - { - "internalType": "contract IClearingHouse", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes[2]", - "name": "data", - "type": "bytes[2]" - }, - { - "internalType": "int256", - "name": "fillAmount", - "type": "int256" - } - ], - "name": "executeMatchedOrders", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - } - ], - "internalType": "struct ILimitOrderBook.Order", - "name": "order", - "type": "tuple" - } - ], - "name": "getOrderHash", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - }, - { - "internalType": "bool", - "name": "postOnly", - "type": "bool" - } - ], - "internalType": "struct ILimitOrderBook.OrderV2", - "name": "order", - "type": "tuple" - } - ], - "name": "getOrderHashV2", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "upperBound", - "type": "uint256" - } - ], - "name": "getRequiredMargin", - "outputs": [ - { - "internalType": "uint256", - "name": "requiredMargin", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "governance", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "string", - "name": "_name", - "type": "string" - }, - { - "internalType": "string", - "name": "_version", - "type": "string" - }, - { - "internalType": "address", - "name": "_governance", - "type": "address" - } - ], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "int256", - "name": "minSize", - "type": "int256" - } - ], - "name": "initializeMinSize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "isTradingAuthority", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "isValidator", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "juror", - "outputs": [ - { - "internalType": "contract IJuror", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - }, - { - "internalType": "uint256", - "name": "liquidationAmount", - "type": "uint256" - } - ], - "name": "liquidateAndExecuteOrder", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "longOpenOrdersAmount", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "marginAccount", - "outputs": [ - { - "internalType": "contract IMarginAccount", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "minAllowableMargin", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "minSizes", - "outputs": [ - { - "internalType": "int256", - "name": "", - "type": "int256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "", - "type": "uint8" - } - ], - "name": "orderHandlers", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "name": "orderInfo", - "outputs": [ - { - "internalType": "uint256", - "name": "blockPlaced", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "filledAmount", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "reservedMargin", - "type": "uint256" - }, - { - "internalType": "enum IOrderHandler.OrderStatus", - "name": "status", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - } - ], - "name": "orderStatus", - "outputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "blockPlaced", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "filledAmount", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "reservedMargin", - "type": "uint256" - }, - { - "internalType": "enum IOrderHandler.OrderStatus", - "name": "status", - "type": "uint8" - } - ], - "internalType": "struct ILimitOrderBook.OrderInfo", - "name": "", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "string", - "name": "err", - "type": "string" - } - ], - "name": "parseMatchingError", - "outputs": [ - { - "internalType": "bytes32", - "name": "orderHash", - "type": "bytes32" - }, - { - "internalType": "string", - "name": "reason", - "type": "string" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [], - "name": "pause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "paused", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "int256", - "name": "baseAssetQuantity", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "price", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "reduceOnly", - "type": "bool" - }, - { - "internalType": "bool", - "name": "postOnly", - "type": "bool" - } - ], - "internalType": "struct ILimitOrderBook.OrderV2[]", - "name": "orders", - "type": "tuple[]" - } - ], - "name": "placeOrders", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "reduceOnlyAmount", - "outputs": [ - { - "internalType": "int256", - "name": "", - "type": "int256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "referral", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "authority", - "type": "address" - } - ], - "name": "revokeTradingAuthority", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_bibliophile", - "type": "address" - } - ], - "name": "setBibliophile", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "__governance", - "type": "address" - } - ], - "name": "setGovernace", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_juror", - "type": "address" - } - ], - "name": "setJuror", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint8", - "name": "orderType", - "type": "uint8" - }, - { - "internalType": "address", - "name": "handler", - "type": "address" - } - ], - "name": "setOrderHandler", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_referral", - "type": "address" - } - ], - "name": "setReferral", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "trader", - "type": "address" - }, - { - "internalType": "address", - "name": "authority", - "type": "address" - } - ], - "name": "setTradingAuthority", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "validator", - "type": "address" - }, - { - "internalType": "bool", - "name": "status", - "type": "bool" - } - ], - "name": "setValidatorStatus", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "settleFunding", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "shortOpenOrdersAmount", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "takerFee", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "unpause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "ammIndex", - "type": "uint256" - }, - { - "internalType": "int256", - "name": "minSize", - "type": "int256" - } - ], - "name": "updateMinSize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes", - "name": "encodedOrder", - "type": "bytes" - }, - { - "internalType": "bytes", - "name": "metadata", - "type": "bytes" - } - ], - "name": "updateOrder", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_minAllowableMargin", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_takerFee", - "type": "uint256" - } - ], - "name": "updateParams", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "useNewPricingAlgorithm", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "authority", - "type": "address" - } - ], - "name": "whitelistTradingAuthority", - "outputs": [], - "stateMutability": "payable", - "type": "function" - } + { + "inputs": [ + { + "internalType": "address", + "name": "_clearingHouse", + "type": "address" + }, + { + "internalType": "address", + "name": "_marginAccount", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [], + "name": "EIP712DomainChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint8", + "name": "version", + "type": "uint8" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "string", + "name": "err", + "type": "string" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "toLiquidate", + "type": "uint256" + } + ], + "name": "LiquidationError", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "fillAmount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "openInterestNotional", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "relayer", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "name": "LiquidationOrderMatched", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + }, + { + "internalType": "bool", + "name": "postOnly", + "type": "bool" + } + ], + "indexed": false, + "internalType": "struct ILimitOrderBook.OrderV2", + "name": "order", + "type": "tuple" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "name": "OrderAccepted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "name": "OrderCancelAccepted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "err", + "type": "string" + } + ], + "name": "OrderCancelRejected", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "name": "OrderCancelled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "fillAmount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "openInterestNotional", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "name": "OrderMatched", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "string", + "name": "err", + "type": "string" + } + ], + "name": "OrderMatchingError", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + } + ], + "indexed": false, + "internalType": "struct ILimitOrderBook.Order", + "name": "order", + "type": "tuple" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "name": "OrderPlaced", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + }, + { + "internalType": "bool", + "name": "postOnly", + "type": "bool" + } + ], + "indexed": false, + "internalType": "struct ILimitOrderBook.OrderV2", + "name": "order", + "type": "tuple" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "err", + "type": "string" + } + ], + "name": "OrderRejected", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash0", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash1", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "fillAmount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "openInterestNotional", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "address", + "name": "relayer", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "name": "OrdersMatched", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Paused", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "timestamp", + "type": "uint256" + } + ], + "name": "SkippedCancelOrder", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "authority", + "type": "address" + } + ], + "name": "TradingAuthorityRevoked", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "authority", + "type": "address" + } + ], + "name": "TradingAuthorityWhitelisted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "Unpaused", + "type": "event" + }, + { + "inputs": [], + "name": "ORDER_TYPEHASH", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "assertTradingAuthority", + "outputs": [], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "bibliophile", + "outputs": [ + { + "internalType": "contract IHubbleBibliophile", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + }, + { + "internalType": "bool", + "name": "postOnly", + "type": "bool" + } + ], + "internalType": "struct ILimitOrderBook.OrderV2[]", + "name": "orders", + "type": "tuple[]" + } + ], + "name": "cancelOrders", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + }, + { + "internalType": "bool", + "name": "postOnly", + "type": "bool" + } + ], + "internalType": "struct ILimitOrderBook.OrderV2[]", + "name": "orders", + "type": "tuple[]" + } + ], + "name": "cancelOrdersWithLowMargin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + } + ], + "internalType": "struct ILimitOrderBook.Order[]", + "name": "orders", + "type": "tuple[]" + } + ], + "name": "cancelV1Orders", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "clearingHouse", + "outputs": [ + { + "internalType": "contract IClearingHouse", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "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": "bytes[2]", + "name": "data", + "type": "bytes[2]" + }, + { + "internalType": "int256", + "name": "fillAmount", + "type": "int256" + } + ], + "name": "executeMatchedOrders", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + } + ], + "internalType": "struct ILimitOrderBook.Order", + "name": "order", + "type": "tuple" + } + ], + "name": "getOrderHash", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + }, + { + "internalType": "bool", + "name": "postOnly", + "type": "bool" + } + ], + "internalType": "struct ILimitOrderBook.OrderV2", + "name": "order", + "type": "tuple" + } + ], + "name": "getOrderHashV2", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "upperBound", + "type": "uint256" + } + ], + "name": "getRequiredMargin", + "outputs": [ + { + "internalType": "uint256", + "name": "requiredMargin", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "governance", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_name", + "type": "string" + }, + { + "internalType": "string", + "name": "_version", + "type": "string" + }, + { + "internalType": "address", + "name": "_governance", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int256", + "name": "minSize", + "type": "int256" + } + ], + "name": "initializeMinSize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "isTradingAuthority", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "isValidator", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "juror", + "outputs": [ + { + "internalType": "contract IJuror", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "liquidationAmount", + "type": "uint256" + } + ], + "name": "liquidateAndExecuteOrder", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "longOpenOrdersAmount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "marginAccount", + "outputs": [ + { + "internalType": "contract IMarginAccount", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "minAllowableMargin", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "minSizes", + "outputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "name": "orderHandlers", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "orderInfo", + "outputs": [ + { + "internalType": "uint256", + "name": "blockPlaced", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "filledAmount", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "reservedMargin", + "type": "uint256" + }, + { + "internalType": "enum IOrderHandler.OrderStatus", + "name": "status", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + } + ], + "name": "orderStatus", + "outputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "blockPlaced", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "filledAmount", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "reservedMargin", + "type": "uint256" + }, + { + "internalType": "enum IOrderHandler.OrderStatus", + "name": "status", + "type": "uint8" + } + ], + "internalType": "struct ILimitOrderBook.OrderInfo", + "name": "", + "type": "tuple" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "err", + "type": "string" + } + ], + "name": "parseMatchingError", + "outputs": [ + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "internalType": "string", + "name": "reason", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "pause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "paused", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "int256", + "name": "baseAssetQuantity", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "reduceOnly", + "type": "bool" + }, + { + "internalType": "bool", + "name": "postOnly", + "type": "bool" + } + ], + "internalType": "struct ILimitOrderBook.OrderV2[]", + "name": "orders", + "type": "tuple[]" + } + ], + "name": "placeOrders", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "reduceOnlyAmount", + "outputs": [ + { + "internalType": "int256", + "name": "", + "type": "int256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "referral", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "authority", + "type": "address" + } + ], + "name": "revokeTradingAuthority", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_bibliophile", + "type": "address" + } + ], + "name": "setBibliophile", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "__governance", + "type": "address" + } + ], + "name": "setGovernace", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_juror", + "type": "address" + } + ], + "name": "setJuror", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "orderType", + "type": "uint8" + }, + { + "internalType": "address", + "name": "handler", + "type": "address" + } + ], + "name": "setOrderHandler", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_referral", + "type": "address" + } + ], + "name": "setReferral", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "trader", + "type": "address" + }, + { + "internalType": "address", + "name": "authority", + "type": "address" + } + ], + "name": "setTradingAuthority", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "validator", + "type": "address" + }, + { + "internalType": "bool", + "name": "status", + "type": "bool" + } + ], + "name": "setValidatorStatus", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "shortOpenOrdersAmount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "takerFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "unpause", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "ammIndex", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "minSize", + "type": "int256" + } + ], + "name": "updateMinSize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "encodedOrder", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "metadata", + "type": "bytes" + } + ], + "name": "updateOrder", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_minAllowableMargin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_takerFee", + "type": "uint256" + } + ], + "name": "updateParams", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "useNewPricingAlgorithm", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "authority", + "type": "address" + } + ], + "name": "whitelistTradingAuthority", + "outputs": [], + "stateMutability": "payable", + "type": "function" + } ] diff --git a/tests/orderbook/juror/JurorTests.js b/tests/orderbook/juror/JurorTests.js new file mode 100644 index 0000000000..7b97190253 --- /dev/null +++ b/tests/orderbook/juror/JurorTests.js @@ -0,0 +1,722 @@ +const { expect } = require("chai") +const { BigNumber } = require("ethers") + +const gasLimit = 5e6 // subnet genesis file only allows for this much + +const { + _1e6, + _1e18, + alice, + bob, + charlie, + getEventsFromOrderBookTx, + getOrderV2, + getRandomSalt, + getRequiredMarginForLongOrder, + getRequiredMarginForShortOrder, + juror, + multiplyPrice, + multiplySize, + removeAllAvailableMargin, + orderBook, + addMargin, + clearingHouse, + placeOrderFromLimitOrderV2, + cancelOrderFromLimitOrderV2, + getOrderBookEvents, + marginAccount, + waitForOrdersToMatch, +} = require("../utils") + +describe.only("Juror tests", async function() { + context("Alice is a new user and tries to place a valid longOrder", async function() { + // Alice is a new user and tries to place a valid longOrder - should fail + // After user adds margin and tries to place a valid order - should succeed + // check if margin is reserved + // User tries to place same order again - should fail + // Cancel order - should succeed + // try cancel same order again - should fail + // available margin should be amount deposited + let longOrderBaseAssetQuantity = multiplySize(0.1) // 0.1 ether + let orderPrice = multiplyPrice(1800) + let market = BigNumber.from(0) + let longOrder = getOrderV2(market, alice.address, longOrderBaseAssetQuantity, orderPrice, getRandomSalt()) + + it("should fail as trader has not margin", async function() { + await removeAllAvailableMargin(alice) + output = await juror.validatePlaceLimitOrder(longOrder, alice.address) + expect(output.err).to.equal("insufficient margin") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(0) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + }) + it("should succeed after trader deposits margin and return reserve margin", async function() { + totalRequiredMargin = await getRequiredMarginForLongOrder(longOrder.price, longOrder.baseAssetQuantity) + await addMargin(alice, totalRequiredMargin) + output = await juror.validatePlaceLimitOrder(longOrder, alice.address) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(totalRequiredMargin.toNumber()) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + // place the order + output = await placeOrderFromLimitOrderV2(longOrder, alice) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(1) + expect(orderStatus.reservedMargin.toNumber()).to.equal(totalRequiredMargin.toNumber()) + expect(orderStatus.blockPlaced.toNumber()).to.equal(output.txReceipt.blockNumber) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + }) + it("should emit OrderRejected if trader tries to place same order again", async function() { + output = await juror.validatePlaceLimitOrder(longOrder, alice.address) + expect(output.err).to.equal("order already exists") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(0) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + output = await placeOrderFromLimitOrderV2(longOrder, alice) + events = await getOrderBookEvents(output.txReceipt.blockNumber) + var orderBookLogWithEvent + for(i = 0; i < events.length; i++) { + if(events[i].transactionHash == output.txReceipt.transactionHash) { + orderBookLogWithEvent = events[i] + break + } + } + expect(orderBookLogWithEvent.event).to.equal("OrderRejected") + expect(orderBookLogWithEvent.args.err).to.equal("order already exists") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(alice.address) + }) + it("should succeed if trader cancels order", async function() { + output = await juror.validateCancelLimitOrder(longOrder, alice.address, false) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.unfilledAmount.toString()).to.equal(longOrder.baseAssetQuantity.toString()) + expect(output.res.amm).to.equal(await clearingHouse.amms(market)) + + await cancelOrderFromLimitOrderV2(longOrder, alice) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(3) + expect(orderStatus.reservedMargin.toNumber()).to.equal(0) + expect(orderStatus.blockPlaced.toNumber()).to.equal(0) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + }) + it("should fail if trader tries to cancel same order again", async function() { + output = await juror.validateCancelLimitOrder(longOrder, alice.address, false) + expect(output.err).to.equal("Cancelled") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.unfilledAmount.toString()).to.equal("0") + expect(output.res.amm).to.equal("0x0000000000000000000000000000000000000000") + + output = await cancelOrderFromLimitOrderV2(longOrder, alice) + events = await getOrderBookEvents(output.txReceipt.blockNumber) + var orderBookLogWithEvent + for(i = 0; i < events.length; i++) { + if(events[i].transactionHash == output.txReceipt.transactionHash) { + orderBookLogWithEvent = events[i] + break + } + } + expect(orderBookLogWithEvent.event).to.equal("OrderCancelRejected") + expect(orderBookLogWithEvent.args.err).to.equal("Cancelled") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(alice.address) + }) + it("should have available margin equal to amount deposited", async function() { + margin = await marginAccount.getAvailableMargin(alice.address) + expect(margin.toNumber()).to.equal(totalRequiredMargin.toNumber()) + }) + }) + context("Bob is a new user and trades via a trading authority", async function() { + // Bob is also a new user and trades via a trading authority + // Trading authority tries to place a valid shortOrder from bob without authorization - should fail + // bob authorizes trading authority to place orders on his behalf + // trading authority tries to place a valid shortOrder from bob with authorization - should succeed + // Place same order again via trading authority - should fail + // Cancel order via trading authority - should succeed + // Cancel same order again via trading authority - should fail + // available margin should be amount deposited + let shortOrderBaseAssetQuantity = multiplySize(-0.1) // 0.1 ether + let orderPrice = multiplyPrice(1800) + let market = BigNumber.from(0) + let shortOrder = getOrderV2(market, bob.address, shortOrderBaseAssetQuantity, orderPrice, getRandomSalt()) + let tradingAuthority = charlie + + it("should fail as trader has no margin", async function() { + await removeAllAvailableMargin(bob) + output = await juror.validatePlaceLimitOrder(shortOrder, bob.address) + expect(output.err).to.equal("insufficient margin") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(0) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + }) + it("after depositing margin, it should fail if trading authority tries to place order without authorization", async function() { + totalRequiredMargin = await getRequiredMarginForShortOrder(shortOrder.price, shortOrder.baseAssetQuantity) + await addMargin(bob, totalRequiredMargin) + const tx = await orderBook.connect(bob).revokeTradingAuthority(tradingAuthority.address) + await tx.wait() + + output = await juror.validatePlaceLimitOrder(shortOrder, tradingAuthority.address) + expect(output.err).to.equal("no trading authority") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(0) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal("0x0000000000000000000000000000000000000000") + }) + it("should succeed if trading authority tries to place order with authorization", async function() { + const tx = await orderBook.connect(bob).whitelistTradingAuthority(tradingAuthority.address) + await tx.wait() + + output = await juror.validatePlaceLimitOrder(shortOrder, tradingAuthority.address) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(totalRequiredMargin.toNumber()) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + // place the order + output = await placeOrderFromLimitOrderV2(shortOrder, tradingAuthority) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(1) + expect(orderStatus.reservedMargin.toNumber()).to.equal(totalRequiredMargin.toNumber()) + expect(orderStatus.blockPlaced.toNumber()).to.equal(output.txReceipt.blockNumber) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + }) + it("should emit OrderRejected if trading authority tries to place same order again", async function() { + output = await juror.validatePlaceLimitOrder(shortOrder, tradingAuthority.address) + expect(output.err).to.equal("order already exists") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(0) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + output = await placeOrderFromLimitOrderV2(shortOrder, tradingAuthority) + events = await getOrderBookEvents(output.txReceipt.blockNumber) + var orderBookLogWithEvent + for(i = 0; i < events.length; i++) { + if(events[i].transactionHash == output.txReceipt.transactionHash) { + orderBookLogWithEvent = events[i] + break + } + } + expect(orderBookLogWithEvent.event).to.equal("OrderRejected") + expect(orderBookLogWithEvent.args.err).to.equal("order already exists") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(shortOrder.trader) + }) + it("should succeed if trading authority cancels order", async function() { + output = await juror.validateCancelLimitOrder(shortOrder, tradingAuthority.address, false) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.unfilledAmount.toString()).to.equal(shortOrder.baseAssetQuantity.toString()) + expect(output.res.amm).to.equal(await clearingHouse.amms(market)) + + await cancelOrderFromLimitOrderV2(shortOrder, tradingAuthority) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(3) + expect(orderStatus.reservedMargin.toNumber()).to.equal(0) + expect(orderStatus.blockPlaced.toNumber()).to.equal(0) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + }) + it("should fail if trading authority tries to cancel same order again", async function() { + output = await juror.validateCancelLimitOrder(shortOrder, tradingAuthority.address, false) + expect(output.err).to.equal("Cancelled") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.unfilledAmount.toString()).to.equal("0") + expect(output.res.amm).to.equal("0x0000000000000000000000000000000000000000") + + output = await cancelOrderFromLimitOrderV2(shortOrder, tradingAuthority) + events = await getOrderBookEvents(output.txReceipt.blockNumber) + var orderBookLogWithEvent + for(i = 0; i < events.length; i++) { + if(events[i].transactionHash == output.txReceipt.transactionHash) { + orderBookLogWithEvent = events[i] + break + } + } + expect(orderBookLogWithEvent.event).to.equal("OrderCancelRejected") + expect(orderBookLogWithEvent.args.err).to.equal("Cancelled") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(shortOrder.trader) + }) + it("should have available margin equal to amount deposited", async function() { + margin = await marginAccount.getAvailableMargin(bob.address) + expect(margin.toNumber()).to.equal(totalRequiredMargin.toNumber()) + }) + }) + + context("Market maker is trying to place/cancel orders", async function() { + // Market maker tries to place a valid postonly longOrder 1 - should pass + // Market maker tries to place a valid postonly shortOrder1 - should pass + // Market maker tries to place same order again - should fail + // Market maker tries to place postonly longOrder2 with higher or same price - should fail + // Market maker tries to place postonly longOrder2 with lower price - should succeed + // Market maker tries to cancel longOrder1 and longOrder2 - should pass + // Market maker tries to cancel same longOrders - should fail + + // Market maker tries to place same order again - should fail + // Market maker tries to place postonly shortOrder2 with lower or same price - should fail + // Market maker tries to place postonly shortOrder2 with higher price - should succeed(cancel order for cleanup) + // Market maker tries to cancel shortOrder1 and shortOrder2 - should pass + // Market maker tries to cancel same shortOrders - should fail + let marketMaker = alice + let shortOrderBaseAssetQuantity = multiplySize(-0.1) // 0.1 ether + let longOrderBaseAssetQuantity = multiplySize(0.1) // 0.1 ether + let longOrderPrice = multiplyPrice(1799) + let shortOrderPrice = multiplyPrice(1801) + let market = BigNumber.from(0) + let longOrder = getOrderV2(market, marketMaker.address, longOrderBaseAssetQuantity, longOrderPrice, getRandomSalt(), false, true) + let shortOrder = getOrderV2(market, marketMaker.address, shortOrderBaseAssetQuantity, shortOrderPrice, getRandomSalt(), false, true) + + + this.beforeAll(async function() { + await addMargin(marketMaker, multiplyPrice(150000)) + }) + this.afterAll(async function() { + await removeAllAvailableMargin(marketMaker) + }) + + context("should succeed when market maker tries to place valid postonly orders in blank orderbook", async function() { + it("should succeed if market maker tries to place a valid postonly longOrder", async function() { + totalRequiredMargin = await getRequiredMarginForLongOrder(longOrder.price, longOrder.baseAssetQuantity) + output = await juror.validatePlaceLimitOrder(longOrder, marketMaker.address) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(totalRequiredMargin.toNumber()) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + // place the order + output = await placeOrderFromLimitOrderV2(longOrder, marketMaker) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(1) + expect(orderStatus.reservedMargin.toNumber()).to.equal(totalRequiredMargin.toNumber()) + expect(orderStatus.blockPlaced.toNumber()).to.equal(output.txReceipt.blockNumber) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + }) + it("should succeed if market maker tries to place a valid postonly shortOrder", async function() { + totalRequiredMargin = await getRequiredMarginForShortOrder(shortOrder.price, shortOrder.baseAssetQuantity) + output = await juror.validatePlaceLimitOrder(shortOrder, marketMaker.address) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(totalRequiredMargin.toNumber()) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + // place the order + output = await placeOrderFromLimitOrderV2(shortOrder, marketMaker) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(1) + expect(orderStatus.reservedMargin.toNumber()).to.equal(totalRequiredMargin.toNumber()) + expect(orderStatus.blockPlaced.toNumber()).to.equal(output.txReceipt.blockNumber) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + }) + }) + context("should emit OrderRejected if market maker tries to place same orders again", async function() { + it("should emit OrderRejected if market maker tries to place same longOrder again", async function() { + output = await juror.validatePlaceLimitOrder(longOrder, marketMaker.address) + expect(output.err).to.equal("order already exists") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(0) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + output = await placeOrderFromLimitOrderV2(longOrder, marketMaker) + events = await getOrderBookEvents(output.txReceipt.blockNumber) + orderBookLogWithEvent = (await getEventsFromOrderBookTx(output.txReceipt.transactionHash))[0] + expect(orderBookLogWithEvent.event).to.equal("OrderRejected") + expect(orderBookLogWithEvent.args.err).to.equal("order already exists") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(longOrder.trader) + }) + + it("should emit OrderRejected if market maker tries to place same shortOrder again", async function() { + output = await juror.validatePlaceLimitOrder(shortOrder, marketMaker.address) + expect(output.err).to.equal("order already exists") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(0) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + output = await placeOrderFromLimitOrderV2(shortOrder, marketMaker) + events = await getOrderBookEvents(output.txReceipt.blockNumber) + orderBookLogWithEvent = (await getEventsFromOrderBookTx(output.txReceipt.transactionHash))[0] + expect(orderBookLogWithEvent.event).to.equal("OrderRejected") + expect(orderBookLogWithEvent.args.err).to.equal("order already exists") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(shortOrder.trader) + }) + }) + context("when postonly order have potential matches in orderbook", async function() { + // longOrder and shortOrder are present in orderbook. + // asksHead = 1801 * 1e6 + // bidsHead = 1799 * 1e6 + it("should fail if market maker tries to place a postonly longOrder2 with higher or same price as shortOrder", async function() { + samePrice = shortOrder.price + longOrder2 = getOrderV2(market, marketMaker.address, longOrderBaseAssetQuantity, samePrice, getRandomSalt(), false, true) + output = await juror.validatePlaceLimitOrder(longOrder2, marketMaker.address) + expect(output.err).to.equal("crossing market") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder2) + expect(output.orderHash).to.equal(expectedOrderHash) + totalRequiredMarginForLongOrder2 = await getRequiredMarginForLongOrder(longOrder2.price, longOrder2.baseAssetQuantity) + expect(output.res.reserveAmount.toNumber()).to.equal(totalRequiredMarginForLongOrder2.toNumber()) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + // place the order + output = await placeOrderFromLimitOrderV2(longOrder2, marketMaker) + orderBookLogWithEvent = (await getEventsFromOrderBookTx(output.txReceipt.transactionHash))[0] + expect(orderBookLogWithEvent.event).to.equal("OrderRejected") + expect(orderBookLogWithEvent.args.err).to.equal("crossing market") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(longOrder2.trader) + + higherPrice = shortOrderPrice.add(1) + longOrder3 = getOrderV2(market, marketMaker.address, longOrderBaseAssetQuantity, higherPrice, getRandomSalt(), false, true) + output = await juror.validatePlaceLimitOrder(longOrder3, marketMaker.address) + expect(output.err).to.equal("crossing market") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder3) + expect(output.orderHash).to.equal(expectedOrderHash) + totalRequiredMarginForLongOrder3 = await getRequiredMarginForLongOrder(longOrder3.price, longOrder3.baseAssetQuantity) + expect(output.res.reserveAmount.toNumber()).to.equal(totalRequiredMarginForLongOrder3.toNumber()) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + // place the order + output = await placeOrderFromLimitOrderV2(longOrder3, marketMaker) + orderBookLogWithEvent = (await getEventsFromOrderBookTx(output.txReceipt.transactionHash))[0] + expect(orderBookLogWithEvent.event).to.equal("OrderRejected") + expect(orderBookLogWithEvent.args.err).to.equal("crossing market") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(longOrder3.trader) + }) + it("should fail if market maker tries to place a postonly shortOrder2 with lower or same price as longOrder", async function() { + samePrice = longOrder.price + shortOrder2 = getOrderV2(market, marketMaker.address, shortOrderBaseAssetQuantity, samePrice, getRandomSalt(), false, true) + output = await juror.validatePlaceLimitOrder(shortOrder2, marketMaker.address) + expect(output.err).to.equal("crossing market") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder2) + expect(output.orderHash).to.equal(expectedOrderHash) + totalRequiredMarginForShortOrder2 = await getRequiredMarginForShortOrder(shortOrder2.price, shortOrder2.baseAssetQuantity) + expect(output.res.reserveAmount.toNumber()).to.equal(totalRequiredMarginForShortOrder2.toNumber()) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + // place the order + output = await placeOrderFromLimitOrderV2(shortOrder2, marketMaker) + orderBookLogWithEvent = (await getEventsFromOrderBookTx(output.txReceipt.transactionHash))[0] + expect(orderBookLogWithEvent.event).to.equal("OrderRejected") + expect(orderBookLogWithEvent.args.err).to.equal("crossing market") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(shortOrder2.trader) + + + lowerPrice = longOrderPrice.sub(1) + shortOrder3 = getOrderV2(market, marketMaker.address, shortOrderBaseAssetQuantity, lowerPrice, getRandomSalt(), false, true) + output = await juror.validatePlaceLimitOrder(shortOrder3, marketMaker.address) + expect(output.err).to.equal("crossing market") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder3) + expect(output.orderHash).to.equal(expectedOrderHash) + totalRequiredMarginForShortOrder3 = await getRequiredMarginForShortOrder(shortOrder3.price, shortOrder3.baseAssetQuantity) + expect(output.res.reserveAmount.toNumber()).to.equal(totalRequiredMarginForShortOrder3.toNumber()) + expectedAmmAddress = await clearingHouse.amms(market) + + // place the order + output = await placeOrderFromLimitOrderV2(shortOrder3, marketMaker) + orderBookLogWithEvent = (await getEventsFromOrderBookTx(output.txReceipt.transactionHash))[0] + expect(orderBookLogWithEvent.event).to.equal("OrderRejected") + expect(orderBookLogWithEvent.args.err).to.equal("crossing market") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(shortOrder3.trader) + }) + }) + context("when postonly order does not have potential matches in orderbook", async function() { + it("should succeed if market maker tries to place another postonly longOrder with lower price than all shortOrders", async function() { + lowerPrice = shortOrder.price.sub(1) + longOrder4 = getOrderV2(market, marketMaker.address, longOrderBaseAssetQuantity, lowerPrice, getRandomSalt(), false, true) + totalRequiredMargin = await getRequiredMarginForLongOrder(longOrder4.price, longOrder4.baseAssetQuantity) + output = await juror.validatePlaceLimitOrder(longOrder4, marketMaker.address) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder4) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(totalRequiredMargin.toNumber()) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + // place the order + output = await placeOrderFromLimitOrderV2(longOrder4, marketMaker) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(1) + expect(orderStatus.reservedMargin.toNumber()).to.equal(totalRequiredMargin.toNumber()) + expect(orderStatus.blockPlaced.toNumber()).to.equal(output.txReceipt.blockNumber) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + }) + it("should succeed if market maker tries to place another postonly shortOrder with higher price than all longOrders", async function() { + higherPrice = longOrder4.price.add(1) + shortOrder4 = getOrderV2(market, marketMaker.address, shortOrderBaseAssetQuantity, higherPrice, getRandomSalt(), false, true) + totalRequiredMargin = await getRequiredMarginForShortOrder(shortOrder4.price, shortOrder4.baseAssetQuantity) + output = await juror.validatePlaceLimitOrder(shortOrder4, marketMaker.address) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder4) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(totalRequiredMargin.toNumber()) + expectedAmmAddress = await clearingHouse.amms(market) + + // place the order + output = await placeOrderFromLimitOrderV2(shortOrder4, marketMaker) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(1) + expect(orderStatus.reservedMargin.toNumber()).to.equal(totalRequiredMargin.toNumber()) + expect(orderStatus.blockPlaced.toNumber()).to.equal(output.txReceipt.blockNumber) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + }) + }) + + context("should succeed when market maker tries to cancel postonly orders", async function() { + it("should succeed if market maker tries to cancel longOrder", async function() { + // cancel longOrder + output = await juror.validateCancelLimitOrder(longOrder, marketMaker.address, false) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.unfilledAmount.toString()).to.equal(longOrder.baseAssetQuantity.toString()) + expect(output.res.amm).to.equal(await clearingHouse.amms(market)) + + await cancelOrderFromLimitOrderV2(longOrder, marketMaker) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(3) + expect(orderStatus.reservedMargin.toNumber()).to.equal(0) + expect(orderStatus.blockPlaced.toNumber()).to.equal(0) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + + // cancel longOrder4 + output = await juror.validateCancelLimitOrder(longOrder4, marketMaker.address, false) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder4) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.unfilledAmount.toString()).to.equal(longOrder4.baseAssetQuantity.toString()) + expect(output.res.amm).to.equal(await clearingHouse.amms(market)) + + await cancelOrderFromLimitOrderV2(longOrder4, marketMaker) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(3) + expect(orderStatus.reservedMargin.toNumber()).to.equal(0) + expect(orderStatus.blockPlaced.toNumber()).to.equal(0) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + }) + it("should succeed if market maker tries to cancel shortOrder", async function() { + // cancel shortOrder + output = await juror.validateCancelLimitOrder(shortOrder, marketMaker.address, false) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.unfilledAmount.toString()).to.equal(shortOrder.baseAssetQuantity.toString()) + expect(output.res.amm).to.equal(await clearingHouse.amms(market)) + + await cancelOrderFromLimitOrderV2(shortOrder, marketMaker) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(3) + expect(orderStatus.reservedMargin.toNumber()).to.equal(0) + expect(orderStatus.blockPlaced.toNumber()).to.equal(0) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + + // cancel shortOrder4 + output = await juror.validateCancelLimitOrder(shortOrder4, marketMaker.address, false) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder4) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.unfilledAmount.toString()).to.equal(shortOrder4.baseAssetQuantity.toString()) + expect(output.res.amm).to.equal(await clearingHouse.amms(market)) + + await cancelOrderFromLimitOrderV2(shortOrder4, marketMaker) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(3) + expect(orderStatus.reservedMargin.toNumber()).to.equal(0) + expect(orderStatus.blockPlaced.toNumber()).to.equal(0) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + }) + }) + context("should fail if market maker tries to cancel same orders again", async function() { + it("should fail if market maker tries to cancel same longOrders again", async function() { + // cancel longOrder + output = await juror.validateCancelLimitOrder(longOrder, marketMaker.address, false) + expect(output.err).to.equal("Cancelled") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.unfilledAmount.toString()).to.equal("0") + expect(output.res.amm).to.equal("0x0000000000000000000000000000000000000000") + + // cancel longOrder4 + output = await juror.validateCancelLimitOrder(longOrder4, marketMaker.address, false) + expect(output.err).to.equal("Cancelled") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder4) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.unfilledAmount.toString()).to.equal("0") + expect(output.res.amm).to.equal("0x0000000000000000000000000000000000000000") + }) + it("should fail if market maker tries to cancel same shortOrders again", async function() { + // cancel shortOrder + output = await juror.validateCancelLimitOrder(shortOrder, marketMaker.address, false) + expect(output.err).to.equal("Cancelled") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.unfilledAmount.toString()).to.equal("0") + + // cancel shortOrder4 + output = await juror.validateCancelLimitOrder(shortOrder4, marketMaker.address, false) + expect(output.err).to.equal("Cancelled") + expectedOrderHash = await orderBook.getOrderHashV2(shortOrder4) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.unfilledAmount.toString()).to.equal("0") + }) + }) + }) + context.only("When users have positions and then try to place/cancel orders", async function() { + // Alice has long Position and bob has short position + // Alice tries to close half of her position via ui(so places reduceOnly order) + // If reduceOnly order is longOrder - it should fail + // If reduceOnly order is shortOrder - it should succeed + // if there are open shortOrder for alice reduceOnly order should fail + // if order"s size + openReduceOnlyAmount > posSize of alice - it should fail + let shortOrderBaseAssetQuantity = multiplySize(-0.1) // 0.1 ether + let longOrderBaseAssetQuantity = multiplySize(0.1) // 0.1 ether + let longOrderPrice = multiplyPrice(1800) + let shortOrderPrice = multiplyPrice(1800) + let market = BigNumber.from(0) + let longOrder = getOrderV2(market, alice.address, longOrderBaseAssetQuantity, longOrderPrice, getRandomSalt(), false, false) + let shortOrder = getOrderV2(market, bob.address, shortOrderBaseAssetQuantity, shortOrderPrice, getRandomSalt(), false, false) + + this.beforeAll(async function() { + await addMargin(alice, multiplyPrice(150000)) + await addMargin(bob, multiplyPrice(150000)) + await placeOrderFromLimitOrderV2(longOrder, alice) + await placeOrderFromLimitOrderV2(shortOrder, bob) + }) + this.afterAll(async function() { + let oppositeShortOrder = getOrderV2(market, alice.address, shortOrderBaseAssetQuantity, shortOrderPrice, getRandomSalt(), false, false) + let oppositeLongOrder = getOrderV2(market, bob.address, longOrderBaseAssetQuantity, longOrderPrice, getRandomSalt(), false, false) + await placeOrderFromLimitOrderV2(oppositeShortOrder, alice) + await placeOrderFromLimitOrderV2(oppositeLongOrder, bob) + await removeAllAvailableMargin(alice) + await removeAllAvailableMargin(bob) + }) + + context("alice has long position", async function() { + it("should fail if alice tries to place a long reduceOnly order", async function() { + //ensure position is created for alice + orderStatus = await orderBook.orderStatus(await orderBook.getOrderHashV2(longOrder)) + expect(orderStatus.status).to.equal(2) + expect(orderStatus.filledAmount.toString()).to.equal(longOrder.baseAssetQuantity.toString()) + expect(orderStatus.reservedMargin.toNumber()).to.equal(0) + expect(orderStatus.blockPlaced.toNumber()).to.equal(0) + + orderSize = longOrderBaseAssetQuantity.div(2) + let reduceOnlyLongOrder = getOrderV2(market, alice.address, orderSize, longOrderPrice, getRandomSalt(), true, false) + output = await juror.validatePlaceLimitOrder(reduceOnlyLongOrder, alice.address) + expect(output.err).to.equal("reduce only order must reduce position") + expectedOrderHash = await orderBook.getOrderHashV2(reduceOnlyLongOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(0) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + // place the order + output = await placeOrderFromLimitOrderV2(reduceOnlyLongOrder, alice) + orderBookLogWithEvent = (await getEventsFromOrderBookTx(output.txReceipt.transactionHash))[0] + expect(orderBookLogWithEvent.event).to.equal("OrderRejected") + expect(orderBookLogWithEvent.args.err).to.equal("reduce only order must reduce position") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(reduceOnlyLongOrder.trader) + }) + it("should fail when alice has a open shortOrder and tries to place a short reduceOnly order", async function() { + let shortOrderBaseAssetQuantity = longOrderBaseAssetQuantity.div(2).mul(-1) + let shortOrder = getOrderV2(market, alice.address, shortOrderBaseAssetQuantity, shortOrderPrice, getRandomSalt(), false, false) + requiredMargin = await getRequiredMarginForShortOrder(shortOrder.price, shortOrder.baseAssetQuantity) + await addMargin(alice, requiredMargin) + await placeOrderFromLimitOrderV2(shortOrder, alice) + + let reduceOnlyShortOrder = getOrderV2(market, alice.address, shortOrderBaseAssetQuantity, shortOrderPrice, getRandomSalt(), true, false) + output = await juror.validatePlaceLimitOrder(reduceOnlyShortOrder, alice.address) + expect(output.err).to.equal("open orders") + expectedOrderHash = await orderBook.getOrderHashV2(reduceOnlyShortOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(0) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + // place the order + output = await placeOrderFromLimitOrderV2(reduceOnlyShortOrder, alice) + orderBookLogWithEvent = (await getEventsFromOrderBookTx(output.txReceipt.transactionHash))[0] + expect(orderBookLogWithEvent.event).to.equal("OrderRejected") + expect(orderBookLogWithEvent.args.err).to.equal("open orders") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(reduceOnlyShortOrder.trader) + + await cancelOrderFromLimitOrderV2(shortOrder, alice) + }) + it("should succeed if alice tries to place a short reduceOnly order", async function() { + orderSize = longOrderBaseAssetQuantity.div(2).mul(-1) + let reduceOnlyShortOrder = getOrderV2(market, alice.address, orderSize, shortOrderPrice, getRandomSalt(), true, false) + output = await juror.validatePlaceLimitOrder(reduceOnlyShortOrder, alice.address) + expect(output.err).to.equal("") + expectedOrderHash = await orderBook.getOrderHashV2(reduceOnlyShortOrder) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(0) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + // place the order + output = await placeOrderFromLimitOrderV2(reduceOnlyShortOrder, alice) + orderStatus = await orderBook.orderStatus(expectedOrderHash) + expect(orderStatus.status).to.equal(1) + expect(orderStatus.reservedMargin.toNumber()).to.equal(0) + expect(orderStatus.blockPlaced.toNumber()).to.equal(output.txReceipt.blockNumber) + expect(orderStatus.filledAmount.toNumber()).to.equal(0) + + }) + it("should fail if alice tries to place a longOrder(reduceOnly=false) to increase her position after placing a short reduceOnly order", async function() { + let longOrder2 = getOrderV2(market, alice.address, longOrderBaseAssetQuantity, longOrderPrice, getRandomSalt(), false, false) + output = await juror.validatePlaceLimitOrder(longOrder2, alice.address) + expect(output.err).to.equal("open reduce only orders") + expectedOrderHash = await orderBook.getOrderHashV2(longOrder2) + expect(output.orderHash).to.equal(expectedOrderHash) + expect(output.res.reserveAmount.toNumber()).to.equal(0) + expectedAmmAddress = await clearingHouse.amms(market) + expect(output.res.amm).to.equal(expectedAmmAddress) + + // place the order + output = await placeOrderFromLimitOrderV2(longOrder2, alice) + orderBookLogWithEvent = (await getEventsFromOrderBookTx(output.txReceipt.transactionHash))[0] + expect(orderBookLogWithEvent.event).to.equal("OrderRejected") + expect(orderBookLogWithEvent.args.err).to.equal("open reduce only orders") + expect(orderBookLogWithEvent.args.orderHash).to.equal(expectedOrderHash) + expect(orderBookLogWithEvent.args.trader).to.equal(longOrder2.trader) + + // temporary, for cleanup - cancel reduceOnlyShortOrder + await cancelOrderFromLimitOrderV2(reduceOnlyShortOrder, alice) + }) + it("should fail if alice tries to place a short reduceOnly order with size > posSize - reduceOnlyShortOrder.baseAssetQuantity", async function() { + }) + }) + }) +}) diff --git a/tests/orderbook/utils.js b/tests/orderbook/utils.js index 63b66850c5..24f132de98 100644 --- a/tests/orderbook/utils.js +++ b/tests/orderbook/utils.js @@ -173,11 +173,10 @@ async function removeMargin(trader, amount) { async function removeAllAvailableMargin(trader) { margin = await marginAccount.getAvailableMargin(trader.address) - console.log("margin", margin.toString()) marginAccountHelper = await getMarginAccountHelper() if (margin.toNumber() > 0) { - const tx = await marginAccountHelper.connect(trader).removeMarginInUSD(5e11) - // const tx = await marginAccountHelper.connect(trader).removeMarginInUSD(margin.toNumber()) + // const tx = await marginAccountHelper.connect(trader).removeMarginInUSD(5e11) + const tx = await marginAccountHelper.connect(trader).removeMarginInUSD(margin.toNumber()) await tx.wait() } return @@ -286,13 +285,55 @@ async function getTakerFee() { async function getOrderBookEvents(fromBlock=0) { block = await provider.getBlock("latest") events = await orderBook.queryFilter("*",fromBlock,block.number) - console.log("events", events) + return events } function bnToFloat(num, decimals = 6) { return parseFloat(ethers.utils.formatUnits(num.toString(), decimals)) } +async function getRequiredMarginForLongOrder(price, baseAssetQuantity) { + minAllowableMargin = await clearingHouse.minAllowableMargin() + takerFee = await clearingHouse.takerFee() + + quoteAsset = baseAssetQuantity.mul(price).div(_1e18).abs() + requiredMargin = quoteAsset.mul(minAllowableMargin).div(_1e6) + requiredTakerFee = quoteAsset.mul(takerFee).div(_1e6) + totalRequiredMargin = requiredMargin.add(requiredTakerFee) + return totalRequiredMargin +} + +async function getRequiredMarginForShortOrder(price, baseAssetQuantity) { + minAllowableMargin = await clearingHouse.minAllowableMargin() + takerFee = await clearingHouse.takerFee() + + amm = await getAMMContract(market) + oraclePrice = await amm.getUnderlyingPrice() + maxOracleSpreadRatio = await amm.maxOracleSpreadRatio() + upperBound = oraclePrice.mul(maxOracleSpreadRatio.add(_1e6)).div(_1e6) + if (price < upperBound) { + price = upperBound + } + // for shortOrder we use upperBound to reservePrice as it is the worst price + quoteAsset = baseAssetQuantity.mul(price).div(_1e18).abs() + requiredMargin = quoteAsset.mul(minAllowableMargin).div(_1e6) + requiredTakerFee = quoteAsset.mul(takerFee).div(_1e6) + return requiredMargin.add(requiredTakerFee) +} + +async function getEventsFromOrderBookTx(transactionHash) { + tx = await provider.getTransaction(transactionHash) + events = await getOrderBookEvents(tx.blockNumber) + var orderBookLogsWithEvent = [] + for(i = 0; i < events.length; i++) { + if(events[i].transactionHash == transactionHash) { + orderBookLogsWithEvent.push(events[i]) + break + } + } + return orderBookLogsWithEvent +} + module.exports = { _1e6, _1e12, @@ -310,6 +351,7 @@ module.exports = { encodeLimitOrderWithType, getAMMContract, getDomain, + getEventsFromOrderBookTx, getIOCOrder, getOrder, getOrderV2, @@ -317,6 +359,8 @@ module.exports = { getMinSizeRequirement, getOrderBookEvents, getRandomSalt, + getRequiredMarginForLongOrder, + getRequiredMarginForShortOrder, getTakerFee, governance, hubblebibliophile,