diff --git a/markets/perps-market/contracts/modules/LimitOrderModule.sol b/markets/perps-market/contracts/modules/LimitOrderModule.sol index 781b4ad0c1..33557edcb0 100644 --- a/markets/perps-market/contracts/modules/LimitOrderModule.sol +++ b/markets/perps-market/contracts/modules/LimitOrderModule.sol @@ -7,7 +7,6 @@ import {DecimalMath} from "@synthetixio/core-contracts/contracts/utils/DecimalMa import {SafeCastI256} from "@synthetixio/core-contracts/contracts/utils/SafeCast.sol"; import {SafeCastU256} from "@synthetixio/core-contracts/contracts/utils/SafeCast.sol"; import {FeatureFlag} from "@synthetixio/core-modules/contracts/storage/FeatureFlag.sol"; -// import {ERC2771Context} from "@synthetixio/core-contracts/contracts/utils/ERC2771Context.sol"; import {ILimitOrderModule} from "../interfaces/ILimitOrderModule.sol"; import {IMarketEvents} from "../interfaces/IMarketEvents.sol"; import {IAccountEvents} from "../interfaces/IAccountEvents.sol"; @@ -23,6 +22,7 @@ import {PerpsAccount, SNX_USD_MARKET_ID} from "../storage/PerpsAccount.sol"; import {PerpsMarketConfiguration} from "../storage/PerpsMarketConfiguration.sol"; import {MathUtil} from "../utils/MathUtil.sol"; import {Flags} from "../utils/Flags.sol"; +import "hardhat/console.sol"; /** * @title Module for settling signed P2P limit orders @@ -79,7 +79,8 @@ contract LimitOrderModule is ILimitOrderModule, IMarketEvents, IAccountEvents { LimitOrder.SignedOrderRequest calldata order, LimitOrder.Signature calldata sig ) external { - // TODO consider adding feature flag here + FeatureFlag.ensureAccessToFeature(Flags.PERPS_SYSTEM); + FeatureFlag.ensureAccessToFeature(Flags.LIMIT_ORDER); checkSigPermission(order, sig); LimitOrder.Data storage limitOrderData = LimitOrder.load(); @@ -118,6 +119,8 @@ contract LimitOrderModule is ILimitOrderModule, IMarketEvents, IAccountEvents { PerpsMarketConfiguration.Data storage marketConfig = PerpsMarketConfiguration.load( shortOrder.marketId ); + console.log("maxMarketSize", marketConfig.maxMarketSize); + console.log("maxMarketValue", marketConfig.maxMarketValue); perpsMarketData.validateLimitOrderSize( marketConfig.maxMarketSize, marketConfig.maxMarketValue, diff --git a/markets/perps-market/test/integration/LimitOrders/OffchainLimitOrder.settleLimitOrder.test.ts b/markets/perps-market/test/integration/LimitOrders/OffchainLimitOrder.settleLimitOrder.test.ts index afdbc6b18c..f350bed584 100644 --- a/markets/perps-market/test/integration/LimitOrders/OffchainLimitOrder.settleLimitOrder.test.ts +++ b/markets/perps-market/test/integration/LimitOrders/OffchainLimitOrder.settleLimitOrder.test.ts @@ -17,7 +17,7 @@ import assertRevert from '@synthetixio/core-utils/utils/assertions/assert-revert // import assert from 'assert'; // import { getTxTime } from '@synthetixio/core-utils/src/utils/hardhat/rpc'; -describe('Settle Offchain Limit Order tests', () => { +describe.only('Settle Offchain Limit Order tests', () => { const { systems, perpsMarkets, synthMarkets, provider, trader1, trader2, signers, owner } = bootstrapMarkets({ synthMarkets: [ @@ -142,7 +142,7 @@ describe('Settle Offchain Limit Order tests', () => { const restoreToSnapshot = snapshotCheckpoint(provider); - it('settles the orders and emits the proper events', async () => { + it.only('settles the orders and emits the proper events', async () => { const signedShortOrder = await signOrder( shortOrder, trader1() as ethers.Wallet, @@ -269,6 +269,52 @@ describe('Settle Offchain Limit Order tests', () => { ); }); + it.only('fails to cancel an already completed limit order', async () => { + const signedShortOrder = await signOrder( + shortOrder, + trader1() as ethers.Wallet, + systems().PerpsMarket.address + ); + await assertRevert( + systems().PerpsMarket.connect(owner()).cancelLimitOrder(shortOrder, signedShortOrder), + `LimitOrderAlreadyUsed(${shortOrder.accountId}, ${shortOrder.nonce}, ${shortOrder.price}, ${shortOrder.amount})` + ); + }); + + it.only('successfully cancels a new limit order', async () => { + const newNonceShortOrder = { ...shortOrder, nonce: 197889234 }; + const signedNewNonceShortOrder = await signOrder( + newNonceShortOrder, + trader1() as ethers.Wallet, + systems().PerpsMarket.address + ); + const successTx = await systems() + .PerpsMarket.connect(owner()) + .cancelLimitOrder(newNonceShortOrder, signedNewNonceShortOrder); + + await assertEvent( + successTx, + `LimitOrderCancelled(${newNonceShortOrder.accountId}, ${newNonceShortOrder.nonce}, ${newNonceShortOrder.price}, ${newNonceShortOrder.amount})`, + systems().PerpsMarket + ); + }); + + it.only('fails to cancel a new limit order that is already settled', async () => { + const newNonceShortOrder = { ...shortOrder, nonce: 197889234 }; + const signedNewNonceShortOrder = await signOrder( + newNonceShortOrder, + trader1() as ethers.Wallet, + systems().PerpsMarket.address + ); + await assertRevert( + systems() + .PerpsMarket.connect(owner()) + .cancelLimitOrder(newNonceShortOrder, signedNewNonceShortOrder), + `LimitOrderAlreadyUsed(${newNonceShortOrder.accountId}, ${newNonceShortOrder.nonce}, ${newNonceShortOrder.price}, ${newNonceShortOrder.amount})` + ); + }); + + // TODO add the other transaction here and call rest it('fails when the relayers are different for each order', async () => { const badLongOrder = { ...longOrder, relayer: await trader1().getAddress() }; const signedShortOrder = await signOrder( diff --git a/protocol/synthetix/contracts/storage/AccountRBAC.sol b/protocol/synthetix/contracts/storage/AccountRBAC.sol index ed90ad79da..6871c1b1ab 100644 --- a/protocol/synthetix/contracts/storage/AccountRBAC.sol +++ b/protocol/synthetix/contracts/storage/AccountRBAC.sol @@ -3,7 +3,6 @@ pragma solidity >=0.8.11 <0.9.0; import "@synthetixio/core-contracts/contracts/utils/SetUtil.sol"; import "@synthetixio/core-contracts/contracts/errors/AddressError.sol"; -import "hardhat/console.sol"; /** * @title Object for tracking an accounts permissions (role based access control). @@ -139,8 +138,6 @@ library AccountRBAC { bytes32 permission, address target ) internal view returns (bool) { - console.log("signing address aka target", target); - console.log("account owner self.owner", self.owner); return ((target == self.owner) || hasPermission(self, _ADMIN_PERMISSION, target) || hasPermission(self, permission, target));