From 46a8952d83f0336869457fa1d444db657153418c Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 11 Dec 2024 13:37:50 +0530 Subject: [PATCH 01/29] remove absolute position update, add maker delta update and updated close method --- packages/core/contracts/Market.sol | 73 +++++++------------ .../core/contracts/interfaces/IMarket.sol | 3 +- packages/core/contracts/test/MockToken.sol | 8 +- packages/core/contracts/types/Order.sol | 23 +++--- 4 files changed, 45 insertions(+), 62 deletions(-) diff --git a/packages/core/contracts/Market.sol b/packages/core/contracts/Market.sol index 5be485cc9..2e77cba12 100644 --- a/packages/core/contracts/Market.sol +++ b/packages/core/contracts/Market.sol @@ -181,57 +181,21 @@ contract Market is IMarket, Instance, ReentrancyGuard { Fixed6 amount, Fixed6 collateral, address referrer - ) external nonReentrant whenNotPaused { - (Context memory context, UpdateContext memory updateContext) = - _loadForUpdate(account, address(0), referrer, address(0), UFixed6Lib.ZERO, UFixed6Lib.ZERO); - - // create new order & guarantee - Order memory newOrder = OrderLib.from( - context.currentTimestamp, - updateContext.currentPositionLocal, - amount, - collateral, - updateContext.orderReferralFee - ); - Guarantee memory newGuarantee; // no guarantee is created for a market order - - // process update - _updateAndStore(context, updateContext, newOrder, newGuarantee, referrer, address(0)); - } - - /// @notice Updates the account's position and collateral - /// @param account The account to operate on - /// @param newMaker The new maker position for the account - /// @param newMaker The new long position for the account - /// @param newMaker The new short position for the account - /// @param collateral The collateral amount to add or remove from the account - /// @param protect Whether to put the account into a protected status for liquidations - function update( - address account, - UFixed6 newMaker, - UFixed6 newLong, - UFixed6 newShort, - Fixed6 collateral, - bool protect ) external { - update(account, newMaker, newLong, newShort, collateral, protect, address(0)); + update(account, amount, Fixed6Lib.ZERO, collateral, referrer); } /// @notice Updates the account's position and collateral /// @param account The account to operate on - /// @param newMaker The new maker position for the account - /// @param newLong The new long position for the account - /// @param newShort The new short position for the account - /// @param collateral The collateral amount to add or remove from the account - /// @param protect Whether to put the account into a protected status for liquidations + /// @param taker The taker of the order (positive for long, negative for short) + /// @param maker The maker of the order + /// @param collateral The collateral delta of the order (positive for deposit, negative for withdrawal) /// @param referrer The referrer of the order function update( address account, - UFixed6 newMaker, - UFixed6 newLong, - UFixed6 newShort, + Fixed6 taker, + Fixed6 maker, Fixed6 collateral, - bool protect, address referrer ) public nonReentrant whenNotPaused { (Context memory context, UpdateContext memory updateContext) = @@ -241,11 +205,9 @@ contract Market is IMarket, Instance, ReentrancyGuard { Order memory newOrder = OrderLib.from( context.currentTimestamp, updateContext.currentPositionLocal, + taker, + maker, collateral, - newMaker, - newLong, - newShort, - protect, updateContext.orderReferralFee ); Guarantee memory newGuarantee; // no guarantee is created for a market order @@ -258,7 +220,23 @@ contract Market is IMarket, Instance, ReentrancyGuard { /// @param account The account to operate on /// @param protect Whether to put the account into a protected status for liquidations function close(address account, bool protect) external { - update(account, UFixed6Lib.ZERO, UFixed6Lib.ZERO, UFixed6Lib.ZERO, Fixed6Lib.ZERO, protect, address(0)); + (Context memory context, UpdateContext memory updateContext) = + _loadForUpdate(account, address(0), address(0), address(0), UFixed6Lib.ZERO, UFixed6Lib.ZERO); + + // create new order & guarantee + Order memory newOrder = OrderLib.from( + context.currentTimestamp, + updateContext.currentPositionLocal, + Fixed6Lib.ZERO, + UFixed6Lib.ZERO, + UFixed6Lib.ZERO, + UFixed6Lib.ZERO, + protect, + updateContext.orderReferralFee + ); + Guarantee memory newGuarantee; // no guarantee is created for a market order + // process update + _updateAndStore(context, updateContext, newOrder, newGuarantee, address(0), address(0)); } /// @notice Updates the beneficiary of the market @@ -612,6 +590,7 @@ contract Market is IMarket, Instance, ReentrancyGuard { updateContext.currentPositionLocal, amount, Fixed6Lib.ZERO, + Fixed6Lib.ZERO, updateContext.orderReferralFee ); Guarantee memory newGuarantee = GuaranteeLib.from( diff --git a/packages/core/contracts/interfaces/IMarket.sol b/packages/core/contracts/interfaces/IMarket.sol index 3bd57c365..ed521a198 100644 --- a/packages/core/contracts/interfaces/IMarket.sol +++ b/packages/core/contracts/interfaces/IMarket.sol @@ -161,8 +161,7 @@ interface IMarket is IInstance { function settle(address account) external; function update(address account, Intent calldata intent, bytes memory signature) external; function update(address account, Fixed6 amount, Fixed6 collateral, address referrer) external; - function update(address account, UFixed6 newMaker, UFixed6 newLong, UFixed6 newShort, Fixed6 collateral, bool protect) external; - function update(address account, UFixed6 newMaker, UFixed6 newLong, UFixed6 newShort, Fixed6 collateral, bool protect, address referrer) external; + function update(address account, Fixed6 taker, Fixed6 maker, Fixed6 collateral, address referrer) external; function close(address account, bool protect) external; function parameter() external view returns (MarketParameter memory); function riskParameter() external view returns (RiskParameter memory); diff --git a/packages/core/contracts/test/MockToken.sol b/packages/core/contracts/test/MockToken.sol index 49778f5ad..19518eaae 100644 --- a/packages/core/contracts/test/MockToken.sol +++ b/packages/core/contracts/test/MockToken.sol @@ -9,7 +9,7 @@ import { IMarket } from "../interfaces/IMarket.sol"; contract MockToken is ERC20 { - enum Function{ SETTLE, UPDATE, UPDATE_MAKER, UPDATE_INTENT } + enum Function{ SETTLE, UPDATE, UPDATE_INTENT, CLOSE } Function private functionToCall; @@ -17,15 +17,15 @@ contract MockToken is ERC20 { function transferFrom(address, address, uint256) public override returns (bool) { // call method of market contract for reentrancy - if (functionToCall == Function.UPDATE_MAKER) { - IMarket(msg.sender).update(address(0), UFixed6Lib.from(0), UFixed6Lib.from(0), UFixed6Lib.from(0), Fixed6Lib.from(0), false); - } else if (functionToCall == Function.UPDATE) { + if (functionToCall == Function.UPDATE) { IMarket(msg.sender).update(address(0), Fixed6Lib.from(0), Fixed6Lib.from(0), address(0)); } else if (functionToCall == Function.UPDATE_INTENT) { Intent memory intent; IMarket(msg.sender).update(address(0), intent, ""); } else if (functionToCall == Function.SETTLE){ IMarket(msg.sender).settle(address(0)); + } else if (functionToCall == Function.CLOSE) { + IMarket(msg.sender).close(address(0), false); } return true; diff --git a/packages/core/contracts/types/Order.sol b/packages/core/contracts/types/Order.sol index e397e756e..6416377b9 100644 --- a/packages/core/contracts/types/Order.sol +++ b/packages/core/contracts/types/Order.sol @@ -83,32 +83,37 @@ library OrderLib { /// @notice Creates a new order from the an intent order request /// @param timestamp The current timestamp /// @param position The current position - /// @param amount The magnitude and direction of the order + /// @param takerAmount The magnitude and direction of taker position + /// @param makerAmount The magnitude and direction of maker position /// @param collateral The change in the collateral /// @param referralFee The referral fee /// @return newOrder The resulting order function from( uint256 timestamp, Position memory position, - Fixed6 amount, + Fixed6 takerAmount, + Fixed6 makerAmount, Fixed6 collateral, UFixed6 referralFee ) internal pure returns (Order memory newOrder) { newOrder.timestamp = timestamp; newOrder.collateral = collateral; - newOrder.orders = amount.isZero() ? 0 : 1; - newOrder.takerReferral = amount.abs().mul(referralFee); + newOrder.orders = makerAmount.isZero() && takerAmount.isZero() ? 0 : 1; + newOrder.takerReferral = makerAmount.abs().add(takerAmount.abs()).mul(referralFee); // If the order is not counter to the current position, it is opening - if (amount.sign() == 0 || position.skew().sign() == 0 || position.skew().sign() == amount.sign()) { - newOrder.longPos = amount.max(Fixed6Lib.ZERO).abs(); - newOrder.shortPos = amount.min(Fixed6Lib.ZERO).abs(); + if (takerAmount.sign() == 0 || position.skew().sign() == 0 || position.skew().sign() == takerAmount.sign()) { + newOrder.longPos = takerAmount.max(Fixed6Lib.ZERO).abs(); + newOrder.shortPos = takerAmount.min(Fixed6Lib.ZERO).abs(); // If the order is counter to the current position, it is closing } else { - newOrder.shortNeg = amount.max(Fixed6Lib.ZERO).abs(); - newOrder.longNeg = amount.min(Fixed6Lib.ZERO).abs(); + newOrder.shortNeg = takerAmount.max(Fixed6Lib.ZERO).abs(); + newOrder.longNeg = takerAmount.min(Fixed6Lib.ZERO).abs(); } + + newOrder.makerPos = makerAmount.max(Fixed6Lib.ZERO).abs(); + newOrder.makerNeg = makerAmount.min(Fixed6Lib.ZERO).abs(); } /// @notice Creates a new order from the current position and an update request From 2781eea4ae3c23aee44345bc8953f10179f06528 Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 11 Dec 2024 13:38:18 +0530 Subject: [PATCH 02/29] update multiInvoker contracts --- .../contracts/MultiInvoker/MultiInvoker.sol | 25 ++++++++----------- .../TriggerOrders/types/TriggerOrder.sol | 20 +++++++++------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/packages/periphery/contracts/MultiInvoker/MultiInvoker.sol b/packages/periphery/contracts/MultiInvoker/MultiInvoker.sol index 31f2023f3..6c2a893f1 100644 --- a/packages/periphery/contracts/MultiInvoker/MultiInvoker.sol +++ b/packages/periphery/contracts/MultiInvoker/MultiInvoker.sol @@ -131,16 +131,15 @@ contract MultiInvoker is IMultiInvoker, Initializable { ( // update data IMarket market, - UFixed6 newMaker, - UFixed6 newLong, - UFixed6 newShort, + Fixed6 taker, + Fixed6 maker, Fixed6 collateral, bool wrap, InterfaceFee memory interfaceFee1, InterfaceFee memory interfaceFee2 - ) = abi.decode(invocation.args, (IMarket, UFixed6, UFixed6, UFixed6, Fixed6, bool, InterfaceFee, InterfaceFee)); + ) = abi.decode(invocation.args, (IMarket, Fixed6, Fixed6, Fixed6, bool, InterfaceFee, InterfaceFee)); - _update(account, market, newMaker, newLong, newShort, collateral, wrap, interfaceFee1, interfaceFee2); + _update(account, market, taker, maker, collateral, wrap, interfaceFee1, interfaceFee2); } else if (invocation.action == PerennialAction.UPDATE_INTENT) { (IMarket market, Intent memory intent, bytes memory signature) = abi.decode(invocation.args, (IMarket, Intent, bytes)); @@ -171,9 +170,8 @@ contract MultiInvoker is IMultiInvoker, Initializable { /// @notice Updates market on behalf of account /// @param account Address of account to update /// @param market Address of market up update - /// @param newMaker New maker position for account in `market` - /// @param newLong New long position for account in `market` - /// @param newShort New short position for account in `market` + /// @param taker change in taker position for account in `market` + /// @param maker change in maker position for account in `market` /// @param collateral Net change in collateral for account in `market` /// @param wrap Whether to wrap/unwrap collateral on deposit/withdrawal /// @param interfaceFee1 Primary interface fee to charge @@ -181,9 +179,8 @@ contract MultiInvoker is IMultiInvoker, Initializable { function _update( address account, IMarket market, - UFixed6 newMaker, - UFixed6 newLong, - UFixed6 newShort, + Fixed6 taker, + Fixed6 maker, Fixed6 collateral, bool wrap, InterfaceFee memory interfaceFee1, @@ -196,11 +193,9 @@ contract MultiInvoker is IMultiInvoker, Initializable { market.update( account, - newMaker, - newLong, - newShort, + taker, + maker, collateral, - false, interfaceFee1.receiver == address(0) ? interfaceFee2.receiver : interfaceFee1.receiver ); diff --git a/packages/periphery/contracts/TriggerOrders/types/TriggerOrder.sol b/packages/periphery/contracts/TriggerOrders/types/TriggerOrder.sol index 420420ebe..1b0cf44ea 100644 --- a/packages/periphery/contracts/TriggerOrders/types/TriggerOrder.sol +++ b/packages/periphery/contracts/TriggerOrders/types/TriggerOrder.sol @@ -56,25 +56,31 @@ library TriggerOrderLib { IMarket market, address account ) internal { + if (self.delta.eq(MAGIC_VALUE_CLOSE_POSITION)) { + market.close(account, false); + return; + } + // settle and get the pending position of the account market.settle(account); Order memory pending = market.pendings(account); Position memory position = market.positions(account); position.update(pending); + Fixed6 takerDelta; + Fixed6 makerDelta; + // apply order to position - if (self.side == 4) position.maker = _add(position.maker, self.delta); - if (self.side == 5) position.long = _add(position.long, self.delta); - if (self.side == 6) position.short = _add(position.short, self.delta); + if (self.side == 4) makerDelta = self.delta; + if (self.side == 5) takerDelta = self.delta; + if (self.side == 6) takerDelta = self.delta.mul(Fixed6Lib.NEG_ONE); // apply position to market market.update( account, - position.maker, - position.long, - position.short, + takerDelta, + makerDelta, Fixed6Lib.ZERO, - false, self.referrer ); } From 388dcb76153d2ce24e6515b252857e356a61cc29 Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 11 Dec 2024 13:40:32 +0530 Subject: [PATCH 03/29] update vault contracts --- packages/vault/contracts/Vault.sol | 24 ++++++------------- packages/vault/contracts/libs/StrategyLib.sol | 18 +++++++++----- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/packages/vault/contracts/Vault.sol b/packages/vault/contracts/Vault.sol index d19c99c3c..ba0ed89e1 100644 --- a/packages/vault/contracts/Vault.sol +++ b/packages/vault/contracts/Vault.sol @@ -436,23 +436,13 @@ contract Vault is IVault, Instance { StrategyLib.MarketTarget memory target, bool shouldRebalance ) private { - if (shouldRebalance) { - registration.market.update( - address(this), - target.position, - UFixed6Lib.ZERO, - UFixed6Lib.ZERO, - target.collateral, - false - ); - } else { - registration.market.update( - address(this), - Fixed6Lib.ZERO, - target.collateral, - address(0) - ); - } + registration.market.update( + address(this), + Fixed6Lib.ZERO, + shouldRebalance ? target.position : Fixed6Lib.ZERO, + target.collateral, + address(0) + ); } /// @notice Loads the context for the given `account` diff --git a/packages/vault/contracts/libs/StrategyLib.sol b/packages/vault/contracts/libs/StrategyLib.sol index 02eb2f934..38e99a6f6 100644 --- a/packages/vault/contracts/libs/StrategyLib.sol +++ b/packages/vault/contracts/libs/StrategyLib.sol @@ -79,8 +79,8 @@ library StrategyLib { /// @dev The amount of change in collateral Fixed6 collateral; - /// @dev The new position - UFixed6 position; + /// @dev The amount of change in position + Fixed6 position; } /// @notice Loads the strategy context of each of the underlying markets @@ -161,10 +161,7 @@ library StrategyLib { if (marketContext.marketParameter.closed || marketAssets.lt(minAssets)) marketAssets = UFixed6Lib.ZERO; - target.position = marketAssets - .muldiv(marketContext.registration.leverage, marketContext.latestPrice.abs()) - .max(marketContext.minPosition) - .min(marketContext.maxPosition); + target.position = _getTargetPosition(marketContext, marketAssets); } /// @notice Load the context of a market @@ -205,4 +202,13 @@ library StrategyLib { marketContext.maxPosition = marketContext.currentAccountPosition.maker .add(marketContext.riskParameter.makerLimit.unsafeSub(marketContext.currentPosition.maker)); } + + function _getTargetPosition(MarketStrategyContext memory marketContext, UFixed6 marketAssets) private pure returns (Fixed6) { + return Fixed6Lib.from( + marketAssets + .muldiv(marketContext.registration.leverage, marketContext.latestPrice.abs()) + .max(marketContext.minPosition) + .min(marketContext.maxPosition) + ).sub(Fixed6Lib.from(marketContext.currentAccountPosition.maker)); + } } From a362d40373d0d8651f5d6b1fbfb2fc35e3496fd8 Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 11 Dec 2024 13:40:56 +0530 Subject: [PATCH 04/29] update test marketHelpers --- packages/periphery/test/helpers/marketHelpers.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/periphery/test/helpers/marketHelpers.ts b/packages/periphery/test/helpers/marketHelpers.ts index 1c6b9da7c..122e841d4 100644 --- a/packages/periphery/test/helpers/marketHelpers.ts +++ b/packages/periphery/test/helpers/marketHelpers.ts @@ -1,5 +1,5 @@ import { ethers } from 'hardhat' -import { BigNumber, CallOverrides, utils } from 'ethers' +import { BigNumber, CallOverrides, utils, constants } from 'ethers' import { Address } from 'hardhat-deploy/dist/types' import { CheckpointLib__factory, @@ -174,7 +174,5 @@ export async function mockMarket(token: Address): Promise { // Deposits collateral to (amount > 0) or withdraws collateral from (amount < 0) a market export async function transferCollateral(user: SignerWithAddress, market: IMarket, amount: BigNumber) { - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, amount, false) + await market.connect(user)['update(address,int256,int256,address)'](user.address, 0, amount, constants.AddressZero) } From 50da1050722cee8a2599b87be3052eb10571f0bb Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 11 Dec 2024 18:45:45 +0530 Subject: [PATCH 05/29] fix maker referral fee --- packages/core/contracts/Market.sol | 4 ++-- packages/core/contracts/types/Order.sol | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/core/contracts/Market.sol b/packages/core/contracts/Market.sol index 2e77cba12..b65858f06 100644 --- a/packages/core/contracts/Market.sol +++ b/packages/core/contracts/Market.sol @@ -187,8 +187,8 @@ contract Market is IMarket, Instance, ReentrancyGuard { /// @notice Updates the account's position and collateral /// @param account The account to operate on - /// @param taker The taker of the order (positive for long, negative for short) - /// @param maker The maker of the order + /// @param taker The taker delta amount of the order (positive for long, negative for short) + /// @param maker The maker delta amount of the order /// @param collateral The collateral delta of the order (positive for deposit, negative for withdrawal) /// @param referrer The referrer of the order function update( diff --git a/packages/core/contracts/types/Order.sol b/packages/core/contracts/types/Order.sol index 6416377b9..8ec6c0ba7 100644 --- a/packages/core/contracts/types/Order.sol +++ b/packages/core/contracts/types/Order.sol @@ -99,7 +99,8 @@ library OrderLib { newOrder.timestamp = timestamp; newOrder.collateral = collateral; newOrder.orders = makerAmount.isZero() && takerAmount.isZero() ? 0 : 1; - newOrder.takerReferral = makerAmount.abs().add(takerAmount.abs()).mul(referralFee); + newOrder.makerReferral = makerAmount.abs().mul(referralFee); + newOrder.takerReferral = takerAmount.abs().mul(referralFee); // If the order is not counter to the current position, it is opening if (takerAmount.sign() == 0 || position.skew().sign() == 0 || position.skew().sign() == takerAmount.sign()) { From e830d0385d8a75b1178f47f5a0c68951b53e0cfe Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 11 Dec 2024 18:46:18 +0530 Subject: [PATCH 06/29] fix multiInvoker integration tests --- .../test/helpers/MultiInvoker/invoke.ts | 83 +++--------- .../integration/MultiInvoker/Invoke.test.ts | 118 ++++++------------ .../integration/MultiInvoker/Pyth.test.ts | 9 +- .../integration/MultiInvoker/setupHelpers.ts | 24 ++-- 4 files changed, 64 insertions(+), 170 deletions(-) diff --git a/packages/periphery/test/helpers/MultiInvoker/invoke.ts b/packages/periphery/test/helpers/MultiInvoker/invoke.ts index b8a18dd9a..5a8f58ec5 100644 --- a/packages/periphery/test/helpers/MultiInvoker/invoke.ts +++ b/packages/periphery/test/helpers/MultiInvoker/invoke.ts @@ -28,19 +28,19 @@ export type Actions = IMultiInvoker.InvocationStruct[] export const buildUpdateMarket = ({ market, - maker, - long, - short, - collateral, - handleWrap, + makerDelta = BigNumber.from(0), + longDelta = BigNumber.from(0), + shortDelta = BigNumber.from(0), + collateral = BigNumber.from(0), + handleWrap = false, interfaceFee1, interfaceFee2, }: { market: string - maker?: BigNumberish - long?: BigNumberish - short?: BigNumberish - collateral?: BigNumberish + makerDelta?: BigNumber + longDelta?: BigNumber + shortDelta?: BigNumber + collateral?: BigNumber handleWrap?: boolean interfaceFee1?: InterfaceFeeStruct interfaceFee2?: InterfaceFeeStruct @@ -49,23 +49,13 @@ export const buildUpdateMarket = ({ { action: 1, args: utils.defaultAbiCoder.encode( - [ - 'address', - 'uint256', - 'uint256', - 'uint256', - 'int256', - 'bool', - 'tuple(uint256,address)', - 'tuple(uint256,address)', - ], + ['address', 'int256', 'int256', 'int256', 'bool', 'tuple(uint256,address)', 'tuple(uint256,address)'], [ market, - maker ?? MAX_UINT, - long ?? MAX_UINT, - short ?? MAX_UINT, - collateral ?? MIN_INT, - handleWrap ?? false, + longDelta.sub(shortDelta), + makerDelta, + collateral, + handleWrap, [interfaceFee1 ? interfaceFee1.amount : 0, interfaceFee1 ? interfaceFee1.receiver : constants.AddressZero], [interfaceFee2 ? interfaceFee2.amount : 0, interfaceFee2 ? interfaceFee2.receiver : constants.AddressZero], ], @@ -120,50 +110,6 @@ export const buildUpdateIntent = async ({ ] } -export const buildPlaceOrder = ({ - market, - maker, - long, - short, - collateral, - handleWrap, -}: { - market: string - maker?: BigNumberish - long?: BigNumberish - short?: BigNumberish - collateral: BigNumberish - handleWrap?: boolean -}): Actions => { - return [ - { - action: 1, - args: utils.defaultAbiCoder.encode( - [ - 'address', - 'uint256', - 'uint256', - 'uint256', - 'int256', - 'bool', - 'tuple(uint256,address)', - 'tuple(uint256,address)', - ], - [ - market, - maker ?? MAX_UINT, - long ?? MAX_UINT, - short ?? MAX_UINT, - collateral ?? MIN_INT, - handleWrap ?? false, - [0, constants.AddressZero], - [0, constants.AddressZero], - ], - ), - }, - ] -} - export type VaultUpdate = { vault: string depositAssets?: BigNumberish @@ -265,7 +211,6 @@ module.exports = { MIN_INT64, buildCancelOrder, buildExecOrder, - buildPlaceOrder, buildUpdateMarket, buildUpdateIntent, buildLiquidateUser, diff --git a/packages/periphery/test/integration/MultiInvoker/Invoke.test.ts b/packages/periphery/test/integration/MultiInvoker/Invoke.test.ts index c2ea15eb4..b9e18c003 100644 --- a/packages/periphery/test/integration/MultiInvoker/Invoke.test.ts +++ b/packages/periphery/test/integration/MultiInvoker/Invoke.test.ts @@ -199,41 +199,6 @@ export function RunInvokerTests( }, ] - const buildMarketUpdateAction = async ({ - market, - maker, - long, - short, - collateral, - handleWrap, - interfaceFee1, - interfaceFee2, - }: { - market: IMarket - maker?: BigNumberish - long?: BigNumberish - short?: BigNumberish - collateral?: BigNumberish - handleWrap?: boolean - interfaceFee1?: InterfaceFeeStruct - interfaceFee2?: InterfaceFeeStruct - }): Promise => { - const { user } = instanceVars - const positions = await market.positions(user.address) - collateral = collateral ?? (await market.locals(user.address)).collateral.mul(-1) - - return buildUpdateMarket({ - market: market.address, - collateral: collateral, - maker: maker ?? positions.maker, - long: long ?? positions.long, - short: short ?? positions.short, - handleWrap: handleWrap, - interfaceFee1: interfaceFee1, - interfaceFee2: interfaceFee2, - }) - } - testCases.forEach(({ context: contextStr, setup, invoke }) => { context(contextStr, async () => { beforeEach(async () => { @@ -252,7 +217,7 @@ export function RunInvokerTests( await dsu.connect(user).approve(multiInvoker.address, dsuCollateral) await expect(invoke(buildApproveTarget(market.address))).to.not.be.reverted - await expect(invoke(await buildMarketUpdateAction({ market: market, collateral: collateral }))) + await expect(invoke(buildUpdateMarket({ market: market.address, collateral: collateral }))) .to.emit(dsu, 'Transfer') .withArgs(user.address, multiInvoker.address, dsuCollateral) .to.emit(dsu, 'Transfer') @@ -273,12 +238,12 @@ export function RunInvokerTests( await dsu.connect(user).approve(multiInvoker.address, dsuCollateral) await expect(invoke(buildApproveTarget(market.address))).to.not.be.reverted - await expect(invoke(await buildMarketUpdateAction({ market: market, collateral: collateral }))).to.not.be + await expect(invoke(buildUpdateMarket({ market: market.address, collateral: collateral }))).to.not.be .reverted const userBalanceBefore = await dsu.balanceOf(user.address) - await expect(invoke(await buildMarketUpdateAction({ market: market, collateral: collateral.mul(-1) }))) + await expect(invoke(buildUpdateMarket({ market: market.address, collateral: collateral.mul(-1) }))) .to.emit(dsu, 'Transfer') .withArgs(market.address, multiInvoker.address, dsuCollateral) .to.emit(dsu, 'Transfer') @@ -300,7 +265,7 @@ export function RunInvokerTests( await expect(invoke(buildApproveTarget(market.address))).to.not.be.reverted await expect( - invoke(await buildMarketUpdateAction({ market: market, collateral: collateral, handleWrap: true })), + invoke(buildUpdateMarket({ market: market.address, collateral: collateral, handleWrap: true })), ) .to.emit(usdc, 'Transfer') .withArgs(user.address, multiInvoker.address, collateral) @@ -361,7 +326,7 @@ export function RunInvokerTests( await multiInvoker['invoke((uint8,bytes)[])'](buildApproveTarget(market.address)) await expect( - invoke(await buildMarketUpdateAction({ market: market, collateral: collateral, handleWrap: true })), + invoke(buildUpdateMarket({ market: market.address, collateral: collateral, handleWrap: true })), ) .to.emit(dsuReserve, 'Mint') .withArgs(multiInvoker.address, dsuCollateral, anyValue) @@ -458,12 +423,10 @@ export function RunInvokerTests( await dsu.connect(user).approve(multiInvoker.address, dsuCollateral) await multiInvoker['invoke((uint8,bytes)[])'](buildApproveTarget(market.address)) - await invoke(await buildMarketUpdateAction({ market: market, collateral: collateral, handleWrap: false })) + await invoke(buildUpdateMarket({ market: market.address, collateral: collateral, handleWrap: false })) await expect( - invoke( - await buildMarketUpdateAction({ market: market, collateral: collateral.mul('-1'), handleWrap: true }), - ), + invoke(buildUpdateMarket({ market: market.address, collateral: collateral.mul('-1'), handleWrap: true })), ) .to.emit(dsuReserve, 'Redeem') .withArgs(multiInvoker.address, dsuCollateral, anyValue) @@ -566,8 +529,8 @@ export function RunInvokerTests( await expect( invoke( - await buildMarketUpdateAction({ - market: market, + buildUpdateMarket({ + market: market.address, collateral: collateral, interfaceFee1: { amount: feeAmt, @@ -594,8 +557,8 @@ export function RunInvokerTests( await expect( invoke( - await buildMarketUpdateAction({ - market: market, + buildUpdateMarket({ + market: market.address, collateral: collateral, interfaceFee1: { amount: feeAmt, @@ -620,13 +583,13 @@ export function RunInvokerTests( await dsu.connect(user).approve(multiInvoker.address, dsuCollateral) await multiInvoker['invoke((uint8,bytes)[])'](buildApproveTarget(market.address)) - await expect(invoke(await buildMarketUpdateAction({ market: market, collateral: collateral }))).to.not.be + await expect(invoke(buildUpdateMarket({ market: market.address, collateral: collateral }))).to.not.be .reverted await expect( invoke( - await buildMarketUpdateAction({ - market: market, + buildUpdateMarket({ + market: market.address, collateral: collateral.sub(feeAmt).mul(-1), interfaceFee1: { amount: feeAmt, @@ -651,13 +614,13 @@ export function RunInvokerTests( await dsu.connect(user).approve(multiInvoker.address, dsuCollateral) await multiInvoker['invoke((uint8,bytes)[])'](buildApproveTarget(market.address)) - await expect(invoke(await buildMarketUpdateAction({ market: market, collateral: collateral }))).to.not.be + await expect(invoke(buildUpdateMarket({ market: market.address, collateral: collateral }))).to.not.be .reverted await expect( invoke( - await buildMarketUpdateAction({ - market: market, + buildUpdateMarket({ + market: market.address, collateral: collateral.sub(feeAmt).mul(-1), interfaceFee1: { amount: feeAmt, @@ -686,8 +649,8 @@ export function RunInvokerTests( await expect( invoke( - await buildMarketUpdateAction({ - market: market, + buildUpdateMarket({ + market: market.address, collateral: collateral, interfaceFee1: { amount: feeAmt, @@ -725,10 +688,10 @@ export function RunInvokerTests( await advanceToPrice(PRICE) await invoke( - await buildMarketUpdateAction({ - market: market, + buildUpdateMarket({ + market: market.address, collateral: collateral, - maker: parse6decimal('0.02'), + makerDelta: parse6decimal('0.02'), interfaceFee1: { amount: 0, receiver: owner.address, @@ -755,10 +718,10 @@ export function RunInvokerTests( await advanceToPrice(PRICE) await invoke( - await buildMarketUpdateAction({ - market: market, + buildUpdateMarket({ + market: market.address, collateral: collateral, - maker: parse6decimal('0.01'), + makerDelta: parse6decimal('0.01'), interfaceFee1: { amount: 0, receiver: ethers.constants.AddressZero, @@ -810,33 +773,28 @@ export function RunInvokerTests( await dsu.connect(userC).approve(market.address, ethers.utils.parseUnits('1000', 18)) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, 0, - 0, - 0, ethers.utils.parseUnits('1000', 6), - false, + constants.AddressZero, ) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userB.address, 0, - 0, - 0, ethers.utils.parseUnits('1000', 6), - false, + constants.AddressZero, ) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userC.address, - parse6decimal('1'), - 0, 0, + parse6decimal('1'), ethers.utils.parseUnits('1000', 6), - false, + constants.AddressZero, ) // set a price which matches the guarantee @@ -899,13 +857,11 @@ export function RunInvokerTests( // userB creates a maker position, referred by user await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( + ['update(address,int256,int256,int256,address)']( userB.address, - parse6decimal('3'), - 0, 0, + parse6decimal('3'), parse6decimal('600'), - false, user.address, ) await advanceToPrice() @@ -984,15 +940,13 @@ export function RunInvokerTests( it('Wraps USDC to DSU through RESERVE and unwraps DSU to USDC through RESERVE if BATCHER address == 0', async () => { await expect( - invoke(await buildMarketUpdateAction({ market: market, collateral: collateral, handleWrap: true })), + invoke(buildUpdateMarket({ market: market.address, collateral: collateral, handleWrap: true })), ) .to.emit(instanceVars.dsuReserve, 'Mint') .withArgs(multiInvoker.address, dsuCollateral, anyValue) await expect( - invoke( - await buildMarketUpdateAction({ market: market, collateral: collateral.mul(-1), handleWrap: true }), - ), + invoke(buildUpdateMarket({ market: market.address, collateral: collateral.mul(-1), handleWrap: true })), ) .to.emit(instanceVars.dsuReserve, 'Redeem') .withArgs(multiInvoker.address, dsuCollateral, anyValue) diff --git a/packages/periphery/test/integration/MultiInvoker/Pyth.test.ts b/packages/periphery/test/integration/MultiInvoker/Pyth.test.ts index ccd7ce563..28f5aa08d 100644 --- a/packages/periphery/test/integration/MultiInvoker/Pyth.test.ts +++ b/packages/periphery/test/integration/MultiInvoker/Pyth.test.ts @@ -1,5 +1,5 @@ import { expect } from 'chai' -import { BigNumber, utils } from 'ethers' +import { BigNumber, utils, constants } from 'ethers' import { loadFixture } from '@nomicfoundation/hardhat-network-helpers' import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' import { time } from '../../../../common/testutil' @@ -89,13 +89,12 @@ export function RunPythOracleTests( async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('1000'), - false, + constants.AddressZero, ), vaaVars.startingTime, ) diff --git a/packages/periphery/test/integration/MultiInvoker/setupHelpers.ts b/packages/periphery/test/integration/MultiInvoker/setupHelpers.ts index a713915de..7745c6813 100644 --- a/packages/periphery/test/integration/MultiInvoker/setupHelpers.ts +++ b/packages/periphery/test/integration/MultiInvoker/setupHelpers.ts @@ -311,43 +311,39 @@ export async function createVault( // Seed markets with some activity await ethMarket .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - parse6decimal('100'), - 0, 0, + parse6decimal('100'), parse6decimal('100000'), - false, + constants.AddressZero, ) await ethMarket .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, - 0, parse6decimal('50'), 0, parse6decimal('100000'), - false, + constants.AddressZero, ) await btcMarket .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userC.address, - parse6decimal('20'), - 0, 0, + parse6decimal('20'), parse6decimal('100000'), - false, + constants.AddressZero, ) await btcMarket .connect(userD) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userD.address, - 0, parse6decimal('10'), 0, parse6decimal('100000'), - false, + constants.AddressZero, ) return [vault, vaultFactory, ethSubOracle, btcSubOracle] From a5097911ccd87795de7f4e37aa6c049a66f2b6fe Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 11 Dec 2024 18:46:41 +0530 Subject: [PATCH 07/29] fix collateral accounts integration tests --- .../CollateralAccounts/Controller.test.ts | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/periphery/test/integration/CollateralAccounts/Controller.test.ts b/packages/periphery/test/integration/CollateralAccounts/Controller.test.ts index b2063e916..600159139 100644 --- a/packages/periphery/test/integration/CollateralAccounts/Controller.test.ts +++ b/packages/periphery/test/integration/CollateralAccounts/Controller.test.ts @@ -112,20 +112,18 @@ export function RunControllerBaseTests( // updates the market and returns the version timestamp async function changePosition( user: SignerWithAddress, - newMaker = constants.MaxUint256, - newLong = constants.MaxUint256, - newShort = constants.MaxUint256, + makerDelta: BigNumber, + longDelta: BigNumber, + shortDelta: BigNumber, ): Promise { - const positions = await ethMarket.positions(user.address) const tx = await ethMarket .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - newMaker == constants.MaxUint256 ? positions.maker : newMaker, - newLong == constants.MaxUint256 ? positions.long : newLong, - newShort == constants.MaxUint256 ? positions.short : newShort, - 0, - false, + longDelta.sub(shortDelta), + makerDelta, + BigNumber.from(0), + constants.AddressZero, TX_OVERRIDES, ) return (await getEventArguments(tx, 'OrderCreated')).order.timestamp @@ -535,7 +533,7 @@ export function RunControllerBaseTests( await transfer(depositAmount, userA) // create a maker position - currentTime = await changePosition(userA, parse6decimal('1.5')) + currentTime = await changePosition(userA, parse6decimal('1.5'), parse6decimal('0'), parse6decimal('0')) await advanceAndSettle(userA, receiver) expect((await ethMarket.positions(userA.address)).maker).to.equal(parse6decimal('1.5')) From f390103bdf6e0d90ac0cc6480e5010b92130acef Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 11 Dec 2024 18:47:12 +0530 Subject: [PATCH 08/29] fix trigger orders integration tests --- .../integration/TriggerOrders/Manager.test.ts | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/packages/periphery/test/integration/TriggerOrders/Manager.test.ts b/packages/periphery/test/integration/TriggerOrders/Manager.test.ts index c694e1f1d..d09a9351a 100644 --- a/packages/periphery/test/integration/TriggerOrders/Manager.test.ts +++ b/packages/periphery/test/integration/TriggerOrders/Manager.test.ts @@ -659,21 +659,20 @@ export function RunManagerTests(name: string, getFixture: (overrides?: CallOverr // tests interaction with markets; again userA has a maker position, userB has a long position, // userC and userD interact only with trigger orders describe('funded market', () => { - async function changePosition( + async function updatePosition( user: SignerWithAddress, - newMaker: BigNumberish = constants.MaxUint256, - newLong: BigNumberish = constants.MaxUint256, - newShort: BigNumberish = constants.MaxUint256, + makerDelta: BigNumber, + longDelta: BigNumber, + shortDelta: BigNumber, ): Promise { const tx = await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - newMaker, - newLong, - newShort, - 0, - false, + longDelta.sub(shortDelta), + makerDelta, + BigNumber.from(0), + constants.AddressZero, TX_OVERRIDES, ) return (await getEventArguments(tx, 'OrderCreated')).order.timestamp @@ -684,7 +683,7 @@ export function RunManagerTests(name: string, getFixture: (overrides?: CallOverr await ensureNoPosition(userA) await ensureNoPosition(userB) - await changePosition(userA, parse6decimal('10'), 0, 0) + await updatePosition(userA, parse6decimal('10'), BigNumber.from(0), BigNumber.from(0)) await commitPrice(parse6decimal('2000')) await market.settle(userA.address, TX_OVERRIDES) @@ -700,7 +699,7 @@ export function RunManagerTests(name: string, getFixture: (overrides?: CallOverr it('can execute an order with pending position before oracle request fulfilled', async () => { // userB has an unsettled long 1.2 position - await changePosition(userB, 0, parse6decimal('1.2'), 0) + await updatePosition(userB, BigNumber.from(0), parse6decimal('1.2'), BigNumber.from(0)) expect((await market.positions(userB.address)).long).to.equal(0) expect(await getPendingPosition(userB, Side.LONG)).to.equal(parse6decimal('1.2')) @@ -725,7 +724,7 @@ export function RunManagerTests(name: string, getFixture: (overrides?: CallOverr it('can execute an order with pending position after oracle request fulfilled', async () => { // userC has an unsettled short 0.3 position - await changePosition(userC, 0, 0, parse6decimal('1.3')) + await updatePosition(userC, BigNumber.from(0), BigNumber.from(0), parse6decimal('1.3')) expect((await market.positions(userC.address)).short).to.equal(0) expect(await getPendingPosition(userC, Side.SHORT)).to.equal(parse6decimal('1.3')) @@ -761,16 +760,16 @@ export function RunManagerTests(name: string, getFixture: (overrides?: CallOverr expect(canExecuteBefore).to.be.false // time passes, other users interact with market - let positionA = (await market.positions(userA.address)).maker - let positionC = (await market.positions(userC.address)).short + let positionADelta + let positionCDelta let marketPrice = (await oracle.latest()).price while (marketPrice.gt(triggerPrice)) { // two users change their position - positionA = positionA.add(parse6decimal('0.05')) - const timestampA = await changePosition(userA, positionA, 0, 0) - positionC = positionC.sub(parse6decimal('0.04')) - const timestampC = await changePosition(userC, 0, 0, positionC) + positionADelta = parse6decimal('0.05') + const timestampA = await updatePosition(userA, positionADelta, BigNumber.from(0), BigNumber.from(0)) + positionCDelta = parse6decimal('0.04').mul(-1) + const timestampC = await updatePosition(userC, BigNumber.from(0), BigNumber.from(0), positionCDelta) // oracle versions fulfilled marketPrice = marketPrice.sub(parse6decimal('0.35')) @@ -871,7 +870,7 @@ export function RunManagerTests(name: string, getFixture: (overrides?: CallOverr const interfaceBalanceBefore = await dsu.balanceOf(userB.address) // userD starts with a long 3 position - await changePosition(userD, 0, parse6decimal('3'), 0) + await updatePosition(userD, BigNumber.from(0), parse6decimal('3'), BigNumber.from(0)) await commitPrice(parse6decimal('2000.4')) await market.settle(userD.address, TX_OVERRIDES) expect((await market.positions(userD.address)).long).to.equal(parse6decimal('3')) @@ -916,13 +915,18 @@ export function RunManagerTests(name: string, getFixture: (overrides?: CallOverr const interfaceBalanceBefore = await dsu.balanceOf(userB.address) // userD starts with a short 2 position - await changePosition(userD, 0, 0, parse6decimal('2')) + await updatePosition(userD, BigNumber.from(0), BigNumber.from(0), parse6decimal('2')) await commitPrice(parse6decimal('2000.5')) await market.settle(userD.address, TX_OVERRIDES) expect((await market.positions(userD.address)).short).to.equal(parse6decimal('2')) // userD reduces their position by 0.35 but does not settle - const negOrderTimestamp = await changePosition(userD, 0, 0, parse6decimal('1.65')) + const negOrderTimestamp = await updatePosition( + userD, + BigNumber.from(0), + BigNumber.from(0), + parse6decimal('0.35').mul(-1), + ) expect(await getPendingPosition(userD, Side.SHORT)).to.equal(parse6decimal('1.65')) // userD closes their short position From 574cc3038ad837642abfcfaec72294ea2e3e1dbc Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 11 Dec 2024 18:47:30 +0530 Subject: [PATCH 09/29] fix vault integration tests --- .../test/integration/vault/Vault.test.ts | 110 +++++++----------- 1 file changed, 40 insertions(+), 70 deletions(-) diff --git a/packages/vault/test/integration/vault/Vault.test.ts b/packages/vault/test/integration/vault/Vault.test.ts index efb4ee088..abeaf488a 100644 --- a/packages/vault/test/integration/vault/Vault.test.ts +++ b/packages/vault/test/integration/vault/Vault.test.ts @@ -326,43 +326,39 @@ describe('Vault', () => { // Seed markets with some activity await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - parse6decimal('200'), - 0, 0, + parse6decimal('200'), parse6decimal('100000'), - false, + constants.AddressZero, ) await market .connect(user2) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user2.address, - 0, parse6decimal('100'), 0, parse6decimal('100000'), - false, + constants.AddressZero, ) await btcMarket .connect(btcUser1) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( btcUser1.address, - parse6decimal('20'), - 0, 0, + parse6decimal('20'), parse6decimal('100000'), - false, + constants.AddressZero, ) await btcMarket .connect(btcUser2) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( btcUser2.address, - 0, parse6decimal('10'), 0, parse6decimal('100000'), - false, + constants.AddressZero, ) vaultSigner = await impersonate.impersonateWithBalance(vault.address, ethers.utils.parseEther('10')) @@ -969,13 +965,12 @@ describe('Vault', () => { // risk parameters limit maker position to 1000; let a non-vault user consume most of that await asset.connect(perennialUser).approve(market.address, constants.MaxUint256) - await market.connect(perennialUser)['update(address,uint256,uint256,uint256,int256,bool)']( + await market.connect(perennialUser)['update(address,int256,int256,int256,address)']( perennialUser.address, - makerAvailable.sub(reservedForVault), // 795 - 0, 0, + makerAvailable.sub(reservedForVault), // 795 parse6decimal('662500'), - false, + constants.AddressZero, ) const deposit = parse6decimal('11000') @@ -1159,13 +1154,12 @@ describe('Vault', () => { await asset.connect(perennialUser).approve(market.address, constants.MaxUint256) await market .connect(perennialUser) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( perennialUser.address, - 0, currentPosition.maker.sub(currentNet).sub(parse6decimal('1')), 0, parse6decimal('1000000'), - false, + constants.AddressZero, ) // Settle the take position @@ -1199,13 +1193,12 @@ describe('Vault', () => { await asset.connect(perennialUser).approve(btcMarket.address, constants.MaxUint256) await btcMarket .connect(perennialUser) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( perennialUser.address, - 0, currentPosition.maker.sub(currentNet).sub(parse6decimal('0.1')), 0, parse6decimal('1000000'), - false, + constants.AddressZero, ) // Settle the take position @@ -1314,13 +1307,12 @@ describe('Vault', () => { await asset.connect(perennialUser).approve(market.address, constants.MaxUint256) await market .connect(perennialUser) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( perennialUser.address, - parse6decimal('480'), - 0, 0, + parse6decimal('480'), parse6decimal('400000'), - false, + constants.AddressZero, ) await updateOracle() await vault.rebalance(user.address) @@ -1343,13 +1335,12 @@ describe('Vault', () => { const makerAvailable = (await market.riskParameter()).makerLimit.sub((await currentPositionGlobal(market)).maker) await market .connect(perennialUser) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( perennialUser.address, - makerAvailable, - 0, 0, + makerAvailable, parse6decimal('400000'), - false, + constants.AddressZero, ) await updateOracle() @@ -1378,13 +1369,12 @@ describe('Vault', () => { await asset.connect(perennialUser).approve(market.address, constants.MaxUint256) await market .connect(perennialUser) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( perennialUser.address, - 0, parse6decimal('110'), 0, parse6decimal('1000000'), - false, + constants.AddressZero, ) await updateOracle() @@ -2006,9 +1996,7 @@ describe('Vault', () => { // 2. Settle accounts / Liquidate the vault's maker position. const EXPECTED_LIQUIDATION_FEE = BigNumber.from('5149547500') - await btcMarket - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](vault.address, 0, 0, 0, 0, true) + await btcMarket.connect(user).close(vault.address, true) expect((await btcMarket.locals(vault.address)).collateral).to.equal( BigNumber.from('4428767485').add(EXPECTED_LIQUIDATION_FEE), ) // no shortfall @@ -2042,9 +2030,7 @@ describe('Vault', () => { // 2. Settle accounts / Liquidate the vault's maker position. const EXPECTED_LIQUIDATION_FEE = BigNumber.from('8239276000') - await btcMarket - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](vault.address, 0, 0, 0, 0, true) + await btcMarket.connect(user).close(vault.address, true) expect((await btcMarket.locals(vault.address)).collateral).to.equal( BigNumber.from('-26673235277').add(EXPECTED_LIQUIDATION_FEE), ) // shortfall @@ -2075,34 +2061,28 @@ describe('Vault', () => { beforeEach(async () => { await updateOracle() - await market - .connect(user2) - ['update(address,uint256,uint256,uint256,int256,bool)'](user2.address, 0, 0, 0, 0, false) - await btcMarket - .connect(btcUser2) - ['update(address,uint256,uint256,uint256,int256,bool)'](btcUser2.address, 0, 0, 0, 0, false) + await market.connect(user2).close(user2.address, false) + await btcMarket.connect(btcUser2).close(btcUser2.address, false) await updateOracle() // get utilization closer to target in order to trigger pnl on price deviation await market .connect(user2) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user2.address, + parse6decimal('100').mul(-1), 0, - 0, - parse6decimal('100'), parse6decimal('100000'), - false, + constants.AddressZero, ) await btcMarket .connect(btcUser2) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( btcUser2.address, + parse6decimal('10').mul(-1), 0, - 0, - parse6decimal('10'), parse6decimal('100000'), - false, + constants.AddressZero, ) await updateOracle() await vault.rebalance(user.address) @@ -2117,9 +2097,7 @@ describe('Vault', () => { // 2. Settle accounts / Liquidate the vault's maker position. const EXPECTED_LIQUIDATION_FEE = BigNumber.from('2059819000') - await btcMarket - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](vault.address, 0, 0, 0, 0, true) + await btcMarket.connect(user).close(vault.address, true) expect((await btcMarket.locals(vault.address)).collateral).to.equal( BigNumber.from('350411418').add(EXPECTED_LIQUIDATION_FEE), ) // no shortfall @@ -2153,9 +2131,7 @@ describe('Vault', () => { // 2. Settle accounts / Liquidate the vault's maker position. const EXPECTED_LIQUIDATION_FEE = BigNumber.from('1956828050') - await btcMarket - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](vault.address, 0, 0, 0, 0, true) + await btcMarket.connect(user).close(vault.address, true) expect((await btcMarket.locals(vault.address)).collateral).to.equal( BigNumber.from('-480340107').add(EXPECTED_LIQUIDATION_FEE), ) // shortfall @@ -2196,13 +2172,9 @@ describe('Vault', () => { // 3. An oracle update makes the long position liquidatable, initiate take close await updateOracle(parse6decimal('10000')) - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](vault.address, 0, 0, 0, 0, true) + await market.connect(user).close(vault.address, true) await settle(market, user2) - await market - .connect(user2) - ['update(address,uint256,uint256,uint256,int256,bool)'](user2.address, 0, 0, 0, 0, false) + await market.connect(user2).close(user2.address, false) // 4. Settle the vault to recover and rebalance await updateOracle() // let take settle at high price @@ -2259,9 +2231,7 @@ describe('Vault', () => { // 3. An oracle update makes the long position liquidatable, initiate take close await updateOracle(parse6decimal('20000')) - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](vault.address, 0, 0, 0, 0, true) + await market.connect(user).close(vault.address, true) await updateOracle() await vault.connect(user).update(user.address, 0, 1, 0) // redeem 1 share to trigger rebalance From 74e1564d4d722ddc245231fa304f63eeadfb2902 Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 11 Dec 2024 19:46:16 +0530 Subject: [PATCH 10/29] fix oracle integration tests --- .../MetaQuantsOracleFactory.test.ts | 14 +- .../pyth/PythOracleFactory.test.ts | 213 ++++++++++-------- .../chainlink/ChainlinkOracleFactory.test.ts | 21 +- 3 files changed, 132 insertions(+), 116 deletions(-) diff --git a/packages/oracle/test/integration/metaquants/MetaQuantsOracleFactory.test.ts b/packages/oracle/test/integration/metaquants/MetaQuantsOracleFactory.test.ts index 5786bfdaa..d98df5c13 100644 --- a/packages/oracle/test/integration/metaquants/MetaQuantsOracleFactory.test.ts +++ b/packages/oracle/test/integration/metaquants/MetaQuantsOracleFactory.test.ts @@ -474,13 +474,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -512,13 +511,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) diff --git a/packages/oracle/test/integration/pyth/PythOracleFactory.test.ts b/packages/oracle/test/integration/pyth/PythOracleFactory.test.ts index f92709855..1e7846d1f 100644 --- a/packages/oracle/test/integration/pyth/PythOracleFactory.test.ts +++ b/packages/oracle/test/integration/pyth/PythOracleFactory.test.ts @@ -595,13 +595,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -634,13 +633,12 @@ testOracles.forEach(testOracle => { async () => await market2 .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -672,13 +670,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -705,13 +702,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -724,13 +720,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -741,7 +736,7 @@ testOracles.forEach(testOracle => { }) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 2, 0, 0, 0, false) // make request to oracle (new price) + ['update(address,int256,int256,int256,address)'](user.address, 0, 2, 0, constants.AddressZero) // make request to oracle (new price) await expect( pythOracleFactory.connect(user).commit([PYTH_ETH_USD_PRICE_FEED], STARTING_TIME, VAA, { value: 1, @@ -754,13 +749,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -778,13 +772,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -792,7 +785,7 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 2, 0, 0, 0, false), // make request to oracle (new price) + ['update(address,int256,int256,int256,address)'](user.address, 0, 2, 0, constants.AddressZero), // make request to oracle (new price) STARTING_TIME + 1, ) @@ -811,13 +804,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -825,7 +817,7 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 2, 0, 0, 0, false), // make request to oracle (new price) + ['update(address,int256,int256,int256,address)'](user.address, 0, 2, 0, constants.AddressZero), // make request to oracle (new price) STARTING_TIME + 60, ) expect(await keeperOracle.requests(1)).to.be.equal(STARTING_TIME) @@ -873,7 +865,13 @@ testOracles.forEach(testOracle => { await time.increase(30) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 1, 0, 0, parse6decimal('10'), false) // make request to oracle (new price) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + 1, + parse6decimal('10'), + constants.AddressZero, + ) // make request to oracle (new price) await pythOracleFactory.connect(user).commit([PYTH_ETH_USD_PRICE_FEED], STARTING_TIME, VAA, { value: 1, }) @@ -884,13 +882,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -910,13 +907,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -926,7 +922,7 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 2, 0, 0, 0, false), // make request to oracle (new price) + ['update(address,int256,int256,int256,address)'](user.address, 0, 2, 0, constants.AddressZero), // make request to oracle (new price) 1686199141, ) const secondRequestedVersion = await time.currentBlockTimestamp() @@ -959,13 +955,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME + 2, ) @@ -985,13 +980,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME + 1, ) @@ -1024,13 +1018,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -1051,13 +1044,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -1085,13 +1077,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -1107,10 +1098,22 @@ testOracles.forEach(testOracle => { await time.includeAt(async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 1, 0, 0, parse6decimal('10'), false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + 1, + parse6decimal('10'), + constants.AddressZero, + ) await market2 .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 1, 0, 0, parse6decimal('10'), false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + 1, + parse6decimal('10'), + constants.AddressZero, + ) }, STARTING_TIME) expect(await keeperOracle.localCallbacks(STARTING_TIME)).to.deep.eq([user.address]) @@ -1151,13 +1154,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), // make request to oracle (new price) STARTING_TIME, ) @@ -1192,13 +1194,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), // make request to oracle (new price) STARTING_TIME, ) @@ -1220,13 +1221,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), // make request to oracle (new price) STARTING_TIME, ) @@ -1245,7 +1245,13 @@ testOracles.forEach(testOracle => { it('returns the correct versions', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 1, 0, 0, parse6decimal('10'), false) // make request to oracle (new price) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + 1, + parse6decimal('10'), + constants.AddressZero, + ) // make request to oracle (new price) await pythOracleFactory.connect(user).commit([PYTH_ETH_USD_PRICE_FEED], STARTING_TIME, VAA, { value: 1, }) @@ -1265,13 +1271,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), // make request to oracle (new price) STARTING_TIME, ), @@ -1291,7 +1296,13 @@ testOracles.forEach(testOracle => { expect((await keeperOracle.global()).currentIndex).to.equal(0) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 1, 0, 0, parse6decimal('10'), false) // make request to oracle (new price) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + 1, + parse6decimal('10'), + constants.AddressZero, + ) // make request to oracle (new price) const currentTimestamp = await pythOracleFactory.current() // Now there is exactly one requested version @@ -1317,10 +1328,16 @@ testOracles.forEach(testOracle => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 1, 0, 0, parse6decimal('10'), false) // make request to oracle (new price) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + 1, + parse6decimal('10'), + constants.AddressZero, + ) // make request to oracle (new price) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 2, 0, 0, 0, false) // make request to oracle (new price) + ['update(address,int256,int256,int256,address)'](user.address, 0, 2, 0, constants.AddressZero) // make request to oracle (new price) await ethers.provider.send('evm_mine', []) @@ -1336,13 +1353,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), // make request to oracle (new price) STARTING_TIME, ) @@ -1489,13 +1505,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), // make request to oracle (new price) STARTING_TIME + 1, ) @@ -1519,7 +1534,13 @@ testOracles.forEach(testOracle => { it('returns invalid version if that version was requested but not committed', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 1, 0, 0, parse6decimal('10'), false) // make request to oracle (new price) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + 1, + parse6decimal('10'), + constants.AddressZero, + ) // make request to oracle (new price) const version = await keeperOracle.connect(user).at(STARTING_TIME) expect(version[0].valid).to.be.false }) diff --git a/packages/oracle/test/integrationSepolia/chainlink/ChainlinkOracleFactory.test.ts b/packages/oracle/test/integrationSepolia/chainlink/ChainlinkOracleFactory.test.ts index 0f153c669..20a85ec55 100644 --- a/packages/oracle/test/integrationSepolia/chainlink/ChainlinkOracleFactory.test.ts +++ b/packages/oracle/test/integrationSepolia/chainlink/ChainlinkOracleFactory.test.ts @@ -421,13 +421,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -460,13 +459,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), STARTING_TIME, ) @@ -495,13 +493,12 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 1, - 0, 0, + 1, parse6decimal('10'), - false, + constants.AddressZero, ), BATCH_STARTING_TIME, ) From bd95deacbbfb9cc7b2dbb635c9241737de49f09c Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 11 Dec 2024 19:47:19 +0530 Subject: [PATCH 11/29] update workflow to run tests on CI --- .github/workflows/CI.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 94dcab800..a998704d5 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -7,6 +7,7 @@ on: branches: - main - v2.4 + - prateek/pe-1629-remove-magic-values workflow_dispatch: env: From 255fb28e0d93bab1142bc05004d5de215a356617 Mon Sep 17 00:00:00 2001 From: Prateek Date: Thu, 12 Dec 2024 20:33:03 +0530 Subject: [PATCH 12/29] add close with referrer method --- packages/core/contracts/Market.sol | 12 ++++++++++-- packages/core/contracts/interfaces/IMarket.sol | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/core/contracts/Market.sol b/packages/core/contracts/Market.sol index b65858f06..f8fd89a00 100644 --- a/packages/core/contracts/Market.sol +++ b/packages/core/contracts/Market.sol @@ -220,8 +220,16 @@ contract Market is IMarket, Instance, ReentrancyGuard { /// @param account The account to operate on /// @param protect Whether to put the account into a protected status for liquidations function close(address account, bool protect) external { + close(account, protect, address(0)); + } + + /// @notice Closes the account's position + /// @param account The account to operate on + /// @param protect Whether to put the account into a protected status for liquidations + /// @param referrer The referrer of the order + function close(address account, bool protect, address referrer) public nonReentrant whenNotPaused { (Context memory context, UpdateContext memory updateContext) = - _loadForUpdate(account, address(0), address(0), address(0), UFixed6Lib.ZERO, UFixed6Lib.ZERO); + _loadForUpdate(account, address(0), referrer, address(0), UFixed6Lib.ZERO, UFixed6Lib.ZERO); // create new order & guarantee Order memory newOrder = OrderLib.from( @@ -236,7 +244,7 @@ contract Market is IMarket, Instance, ReentrancyGuard { ); Guarantee memory newGuarantee; // no guarantee is created for a market order // process update - _updateAndStore(context, updateContext, newOrder, newGuarantee, address(0), address(0)); + _updateAndStore(context, updateContext, newOrder, newGuarantee, referrer, address(0)); } /// @notice Updates the beneficiary of the market diff --git a/packages/core/contracts/interfaces/IMarket.sol b/packages/core/contracts/interfaces/IMarket.sol index ed521a198..27d1a4ed8 100644 --- a/packages/core/contracts/interfaces/IMarket.sol +++ b/packages/core/contracts/interfaces/IMarket.sol @@ -163,6 +163,7 @@ interface IMarket is IInstance { function update(address account, Fixed6 amount, Fixed6 collateral, address referrer) external; function update(address account, Fixed6 taker, Fixed6 maker, Fixed6 collateral, address referrer) external; function close(address account, bool protect) external; + function close(address account, bool protect, address referrer) external; function parameter() external view returns (MarketParameter memory); function riskParameter() external view returns (RiskParameter memory); function updateBeneficiary(address newBeneficiary) external; From 5570684e92afadfea979cceca85a07b2f2cbed6f Mon Sep 17 00:00:00 2001 From: Prateek Date: Thu, 12 Dec 2024 20:34:05 +0530 Subject: [PATCH 13/29] update tests with new close method --- .../arbitrum/migration/v2.3.test.ts | 12 +++--------- .../vault/test/integration/vault/Vault.test.ts | 18 +++++++++--------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/packages/deploy/test/verification/arbitrum/migration/v2.3.test.ts b/packages/deploy/test/verification/arbitrum/migration/v2.3.test.ts index 5ae7e5eee..b25b043b2 100644 --- a/packages/deploy/test/verification/arbitrum/migration/v2.3.test.ts +++ b/packages/deploy/test/verification/arbitrum/migration/v2.3.test.ts @@ -525,12 +525,8 @@ describe('Verify Arbitrum v2.3 Migration', () => { await commitPriceForIds([oracleIDs[0].id, oracleIDs[1].id], currentTimestamp) const nextVersionTimestamp = nextVersionForTimestamp(await currentBlockTimestamp()) - await ethMarket - .connect(liquidatorSigner) - ['update(address,uint256,uint256,uint256,int256,bool)'](liquidatorSigner.address, 0, 0, 0, 0, false) - await btcMarket - .connect(liquidatorSigner) - ['update(address,uint256,uint256,uint256,int256,bool)'](liquidatorSigner.address, 0, 0, 0, 0, false) + await ethMarket.connect(liquidatorSigner)['close(address,bool)'](liquidatorSigner.address, false) + await btcMarket.connect(liquidatorSigner)['close(address,bool)'](liquidatorSigner.address, false) await increase(10) @@ -562,9 +558,7 @@ describe('Verify Arbitrum v2.3 Migration', () => { .connect(ownerSigner) .updateRiskParameter({ ...riskParameter, minMargin: 500e6, minMaintenance: 500e6 }) - await ethMarket - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](perennialUser.address, 0, 0, 0, 0, true) + await ethMarket.connect(liquidator)['close(address,bool)'](perennialUser.address, true) await commitPriceForIds([oracleIDs[0].id], nextVersionForTimestamp(await currentBlockTimestamp()) + 4) await ethMarket.connect(liquidator).settle(perennialUser.address) diff --git a/packages/vault/test/integration/vault/Vault.test.ts b/packages/vault/test/integration/vault/Vault.test.ts index abeaf488a..bba75f8d3 100644 --- a/packages/vault/test/integration/vault/Vault.test.ts +++ b/packages/vault/test/integration/vault/Vault.test.ts @@ -1996,7 +1996,7 @@ describe('Vault', () => { // 2. Settle accounts / Liquidate the vault's maker position. const EXPECTED_LIQUIDATION_FEE = BigNumber.from('5149547500') - await btcMarket.connect(user).close(vault.address, true) + await btcMarket.connect(user)['close(address,bool)'](vault.address, true) expect((await btcMarket.locals(vault.address)).collateral).to.equal( BigNumber.from('4428767485').add(EXPECTED_LIQUIDATION_FEE), ) // no shortfall @@ -2030,7 +2030,7 @@ describe('Vault', () => { // 2. Settle accounts / Liquidate the vault's maker position. const EXPECTED_LIQUIDATION_FEE = BigNumber.from('8239276000') - await btcMarket.connect(user).close(vault.address, true) + await btcMarket.connect(user)['close(address,bool)'](vault.address, true) expect((await btcMarket.locals(vault.address)).collateral).to.equal( BigNumber.from('-26673235277').add(EXPECTED_LIQUIDATION_FEE), ) // shortfall @@ -2061,8 +2061,8 @@ describe('Vault', () => { beforeEach(async () => { await updateOracle() - await market.connect(user2).close(user2.address, false) - await btcMarket.connect(btcUser2).close(btcUser2.address, false) + await market.connect(user2)['close(address,bool)'](user2.address, false) + await btcMarket.connect(btcUser2)['close(address,bool)'](btcUser2.address, false) await updateOracle() // get utilization closer to target in order to trigger pnl on price deviation @@ -2097,7 +2097,7 @@ describe('Vault', () => { // 2. Settle accounts / Liquidate the vault's maker position. const EXPECTED_LIQUIDATION_FEE = BigNumber.from('2059819000') - await btcMarket.connect(user).close(vault.address, true) + await btcMarket.connect(user)['close(address,bool)'](vault.address, true) expect((await btcMarket.locals(vault.address)).collateral).to.equal( BigNumber.from('350411418').add(EXPECTED_LIQUIDATION_FEE), ) // no shortfall @@ -2131,7 +2131,7 @@ describe('Vault', () => { // 2. Settle accounts / Liquidate the vault's maker position. const EXPECTED_LIQUIDATION_FEE = BigNumber.from('1956828050') - await btcMarket.connect(user).close(vault.address, true) + await btcMarket.connect(user)['close(address,bool)'](vault.address, true) expect((await btcMarket.locals(vault.address)).collateral).to.equal( BigNumber.from('-480340107').add(EXPECTED_LIQUIDATION_FEE), ) // shortfall @@ -2172,9 +2172,9 @@ describe('Vault', () => { // 3. An oracle update makes the long position liquidatable, initiate take close await updateOracle(parse6decimal('10000')) - await market.connect(user).close(vault.address, true) + await market.connect(user)['close(address,bool)'](vault.address, true) await settle(market, user2) - await market.connect(user2).close(user2.address, false) + await market.connect(user2)['close(address,bool)'](user2.address, false) // 4. Settle the vault to recover and rebalance await updateOracle() // let take settle at high price @@ -2231,7 +2231,7 @@ describe('Vault', () => { // 3. An oracle update makes the long position liquidatable, initiate take close await updateOracle(parse6decimal('20000')) - await market.connect(user).close(vault.address, true) + await market.connect(user)['close(address,bool)'](vault.address, true) await updateOracle() await vault.connect(user).update(user.address, 0, 1, 0) // redeem 1 share to trigger rebalance From 7efa228ab1ff353618ab5fc5e3642113880e0697 Mon Sep 17 00:00:00 2001 From: Prateek Date: Thu, 12 Dec 2024 20:34:45 +0530 Subject: [PATCH 14/29] fix some core integration tests --- .../integration/core/closedProduct.test.ts | 32 +- .../core/test/integration/core/fees.test.ts | 357 ++++++++++-------- .../test/integration/core/happyPath.test.ts | 2 +- .../test/integration/core/liquidate.test.ts | 145 +++---- packages/core/test/unit/market/Market.test.ts | 8 +- 5 files changed, 276 insertions(+), 268 deletions(-) diff --git a/packages/core/test/integration/core/closedProduct.test.ts b/packages/core/test/integration/core/closedProduct.test.ts index 564ded2ec..39e5e8480 100644 --- a/packages/core/test/integration/core/closedProduct.test.ts +++ b/packages/core/test/integration/core/closedProduct.test.ts @@ -27,7 +27,7 @@ describe('Closed Market', () => { await dsu.connect(user).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) expect((await market.parameter()).closed).to.be.false @@ -56,10 +56,10 @@ describe('Closed Market', () => { await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) const parameters = { ...(await market.parameter()) } parameters.closed = true await market.updateParameter(parameters) @@ -73,7 +73,7 @@ describe('Closed Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, 0, false), + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, 0, constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketClosedError') }) @@ -82,11 +82,7 @@ describe('Closed Market', () => { await chainlink.next() - await expect( - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), - ).to.not.be.reverted + await expect(await market.connect(user)['close(address,bool)'](user.address, false)).to.not.be.reverted }) }) @@ -100,10 +96,10 @@ describe('Closed Market', () => { await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) await chainlink.next() await chainlink.next() @@ -123,8 +119,8 @@ describe('Closed Market', () => { await chainlink.nextWithPriceModification(price => price.mul(4)) const LIQUIDATION_FEE = BigNumber.from('1000000000') - await market.connect(user)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true) - await market.connect(userB)['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true) + await market.connect(user)['close(address,bool)'](user.address, true) + await market.connect(userB)['close(address,bool)'](userB.address, true) expect((await market.locals(user.address)).collateral).to.equal(userCollateralBefore) expect((await market.locals(userB.address)).collateral).to.equal(userBCollateralBefore) @@ -143,16 +139,14 @@ describe('Closed Market', () => { await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) await chainlink.next() await chainlink.nextWithPriceModification(price => price.mul(2)) - await expect( - market.connect(userB)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ).to.not.be.reverted + await expect(market.connect(userB)['close(address,bool)'](user.address, true)).to.not.be.reverted expect((await market.pendingOrders(user.address, 2)).protection).to.eq(1) const parameters = { ...(await market.parameter()) } parameters.closed = true @@ -175,7 +169,7 @@ describe('Closed Market', () => { const LIQUIDATION_FEE = BigNumber.from('1000000000') await settle(market, user) - await market.connect(userB)['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true) + await market.connect(userB)['close(address,bool)'](userB.address, true) expect((await market.locals(user.address)).collateral).to.equal(userCollateralBefore) expect((await market.locals(userB.address)).collateral).to.equal(userBCollateralBefore) diff --git a/packages/core/test/integration/core/fees.test.ts b/packages/core/test/integration/core/fees.test.ts index 059e24987..2e0880c67 100644 --- a/packages/core/test/integration/core/fees.test.ts +++ b/packages/core/test/integration/core/fees.test.ts @@ -120,7 +120,13 @@ describe('Fees', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + POSITION, + COLLATERAL, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -223,7 +229,13 @@ describe('Fees', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + POSITION, + COLLATERAL, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -240,7 +252,7 @@ describe('Fees', () => { await market.updateRiskParameter(previousRiskParams) await market.updateParameter(previousMarketParams) - await market.connect(user)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false) + await market.connect(user)['close(address,bool)'](user.address, false) // Settle the market with a new oracle version await nextWithConstantPrice() @@ -328,17 +340,22 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, MAKER_POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + MAKER_POSITION, + COLLATERAL, + constants.AddressZero, + ) await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, - 0, LONG_POSITION, 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -461,7 +478,13 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, MAKER_POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + MAKER_POSITION, + COLLATERAL, + constants.AddressZero, + ) // Settle maker to give them portion of fees await nextWithConstantPrice() @@ -470,13 +493,12 @@ describe('Fees', () => { await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, - 0, LONG_POSITION, 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -640,17 +662,22 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, MAKER_POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + MAKER_POSITION, + COLLATERAL, + constants.AddressZero, + ) await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, - 0, LONG_POSITION, 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -687,9 +714,7 @@ describe('Fees', () => { makerFee: 0, }) - await market - .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, false) + await market.connect(userB)['close(address,bool)'](userB.address, false) await nextWithConstantPrice() const txLong = await settle(market, userB) @@ -816,17 +841,22 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, MAKER_POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + MAKER_POSITION, + COLLATERAL, + constants.AddressZero, + ) await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, + SHORT_POSITION.mul(-1), 0, - 0, - SHORT_POSITION, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -949,8 +979,13 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, MAKER_POSITION, 0, 0, COLLATERAL, false) - + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + MAKER_POSITION, + COLLATERAL, + constants.AddressZero, + ) // Settle maker to give them portion of fees await nextWithConstantPrice() await settle(market, user) @@ -958,13 +993,12 @@ describe('Fees', () => { await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, + SHORT_POSITION.mul(-1), 0, - 0, - SHORT_POSITION, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -1126,17 +1160,22 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, MAKER_POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + MAKER_POSITION, + COLLATERAL, + constants.AddressZero, + ) await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, + SHORT_POSITION.mul(-1), 0, - 0, - SHORT_POSITION, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -1172,9 +1211,7 @@ describe('Fees', () => { fundingFee: BigNumber.from('0'), makerFee: 0, }) - await market - .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, false) + await market.connect(userB)['close(address,bool)'](userB.address, false) await nextWithConstantPrice() const txLong = await settle(market, userB) @@ -1315,7 +1352,13 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, MAKER_POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + MAKER_POSITION, + COLLATERAL, + constants.AddressZero, + ) await nextWithConstantPrice() await settle(market, user) }) @@ -1326,13 +1369,12 @@ describe('Fees', () => { // Bring skew from 0 to 100% -> total skew change of 100% await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, + SHORT_POSITION.mul(-1), 0, - 0, - SHORT_POSITION, COLLATERAL, - false, + constants.AddressZero, ) await nextWithConstantPrice() @@ -1355,13 +1397,12 @@ describe('Fees', () => { // Bring skew from -100% to +50% -> total skew change of 150% await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userC.address, - 0, LONG_POSITION.mul(2), 0, COLLATERAL, - false, + constants.AddressZero, ) await nextWithConstantPrice() @@ -1424,7 +1465,13 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, MAKER_POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + MAKER_POSITION, + COLLATERAL, + constants.AddressZero, + ) await nextWithConstantPrice() await settle(market, user) }) @@ -1435,13 +1482,12 @@ describe('Fees', () => { // Bring skew from 0 to 100% -> total impact change of 100% await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, + SHORT_POSITION.mul(-1), 0, - 0, - SHORT_POSITION, COLLATERAL, - false, + constants.AddressZero, ) await nextWithConstantPrice() @@ -1463,7 +1509,13 @@ describe('Fees', () => { // Bring skew from 0 to 100% -> total impact change of 100% await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, LONG_POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + LONG_POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await nextWithConstantPrice() const tx = await settle(market, userB) @@ -1484,13 +1536,12 @@ describe('Fees', () => { // Bring skew from 0 to 100% -> total impact change of 100% await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, + SHORT_POSITION.mul(-1), 0, - 0, - SHORT_POSITION, COLLATERAL, - false, + constants.AddressZero, ) await nextWithConstantPrice() @@ -1509,7 +1560,13 @@ describe('Fees', () => { // Bring skew from -100% to 0% -> total impact change of -100% await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, LONG_POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userC.address, + LONG_POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await nextWithConstantPrice() const tx = await settle(market, userC) @@ -1533,13 +1590,12 @@ describe('Fees', () => { // Bring skew from 0 to 100% -> total impact change of 100% await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, + SHORT_POSITION.mul(-1), 0, - 0, - SHORT_POSITION, COLLATERAL, - false, + constants.AddressZero, ) await nextWithConstantPrice() @@ -1558,7 +1614,13 @@ describe('Fees', () => { // Bring skew from -100% to 0% -> total impact change of -100% await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, LONG_POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userC.address, + LONG_POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await nextWithConstantPrice() const tx = await settle(market, userC) @@ -1614,7 +1676,13 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, MAKER_POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + MAKER_POSITION, + COLLATERAL, + constants.AddressZero, + ) await nextWithConstantPrice() await settle(market, user) @@ -1627,15 +1695,15 @@ describe('Fees', () => { }) it('charges settlement fee for maker', async () => { + // bring position from 10 to 20 await market .connect(instanceVars.user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( instanceVars.user.address, - MAKER_POSITION.mul(2), 0, + MAKER_POSITION, 0, - 0, - false, + constants.AddressZero, ) await nextWithConstantPrice() @@ -1661,16 +1729,21 @@ describe('Fees', () => { const { userB, userC } = instanceVars await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, LONG_POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + LONG_POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userC.address, + SHORT_POSITION.mul(-1), 0, - 0, - SHORT_POSITION, COLLATERAL, - false, + constants.AddressZero, ) await nextWithConstantPrice() @@ -1736,7 +1809,13 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, MAKER_POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + MAKER_POSITION, + COLLATERAL, + constants.AddressZero, + ) await nextWithConstantPrice() await settle(market, user) }) @@ -1746,7 +1825,13 @@ describe('Fees', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, LONG_POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + LONG_POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await nextWithConstantPrice() await settle(market, userB) @@ -1784,7 +1869,13 @@ describe('Fees', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, SHORT_POSITION, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + SHORT_POSITION.mul(-1), + 0, + COLLATERAL, + constants.AddressZero, + ) await nextWithConstantPrice() await settle(market, userB) @@ -1854,7 +1945,13 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, MAKER_POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + MAKER_POSITION, + COLLATERAL, + constants.AddressZero, + ) await nextWithConstantPrice() await settle(market, user) }) @@ -1864,7 +1961,13 @@ describe('Fees', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, LONG_POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + LONG_POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await nextWithConstantPrice() await settle(market, userB) @@ -1902,7 +2005,13 @@ describe('Fees', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, SHORT_POSITION, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + SHORT_POSITION.mul(-1), + 0, + COLLATERAL, + constants.AddressZero, + ) await nextWithConstantPrice() await settle(market, userB) @@ -1969,15 +2078,7 @@ describe('Fees', () => { // userB creates a maker position, referred by user await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( - userB.address, - POSITION, - 0, - 0, - COLLATERAL, - false, - user.address, - ) + ['update(address,int256,int256,int256,address)'](userB.address, 0, POSITION, COLLATERAL, user.address) const expectedReferral = parse6decimal('0.15').mul(3) // referralFee * position expectOrderEq(await market.pendingOrder(1), { ...DEFAULT_ORDER, @@ -2019,25 +2120,22 @@ describe('Fees', () => { // user creates a non-referred maker position to facilitate a taker order await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - POSITION.mul(2), - 0, 0, + POSITION.mul(2), COLLATERAL.mul(2), - false, + constants.AddressZero, ) // userC creates a short position referred by userB await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( + ['update(address,int256,int256,int256,address)']( userC.address, + POSITION.mul(-1), 0, - 0, - POSITION, COLLATERAL.mul(2), - false, userB.address, ) const expectedReferral = parse6decimal('0.12').mul(3) // referralFee * position @@ -2086,15 +2184,7 @@ describe('Fees', () => { // userB creates a maker position, referred by user await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( - userB.address, - POSITION, - 0, - 0, - COLLATERAL, - false, - user.address, - ) + ['update(address,int256,int256,int256,address)'](userB.address, 0, POSITION, COLLATERAL, user.address) const expectedReferral = parse6decimal('0.17').mul(3) // referralFee * position expectOrderEq(await market.pendingOrder(1), { ...DEFAULT_ORDER, @@ -2129,27 +2219,17 @@ describe('Fees', () => { // user creates a maker position order referred by userB await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( + ['update(address,int256,int256,int256,address)']( user.address, - POSITION.mul(2), - 0, 0, + POSITION.mul(2), COLLATERAL.mul(2), - false, userB.address, ) // userC creates a long position referred by user await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( - userC.address, - 0, - POSITION, - 0, - COLLATERAL.mul(2), - false, - user.address, - ) + ['update(address,int256,int256,int256,address)'](userC.address, POSITION, 0, COLLATERAL.mul(2), user.address) expectOrderEq(await market.pendingOrder(1), { ...DEFAULT_ORDER, timestamp: TIMESTAMP_1, @@ -2196,13 +2276,11 @@ describe('Fees', () => { // userD creates a short position referred by user await market .connect(userD) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( + ['update(address,int256,int256,int256,address)']( userD.address, + POSITION.mul(2).div(3).mul(-1), 0, - 0, - POSITION.mul(2).div(3), COLLATERAL, - false, user.address, ) expectOrderEq(await market.pendingOrder(2), { @@ -2234,25 +2312,22 @@ describe('Fees', () => { // user creates a non-referred maker position to facilitate a taker order await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - POSITION.mul(2), - 0, 0, + POSITION.mul(2), COLLATERAL.mul(2), - false, + constants.AddressZero, ) // userC creates a short position referred by userB await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( + ['update(address,int256,int256,int256,address)']( userC.address, + POSITION.mul(-1), 0, - 0, - POSITION, COLLATERAL.mul(2), - false, userB.address, ) const currentId = (await market.locals(userC.address)).currentId @@ -2288,9 +2363,7 @@ describe('Fees', () => { .withArgs(userB.address, userB.address, expectedClaimable) // userC closes a short position referred by user - await market - .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool,address)'](userC.address, 0, 0, 0, 0, false, user.address) + await market.connect(userC)['close(address,bool,address)'](userC.address, false, user.address) await nextWithConstantPrice() await settle(market, user) @@ -2315,9 +2388,7 @@ describe('Fees', () => { await nextWithConstantPrice() // userC opens a short position referred by no one - await market - .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, 0, false) + await market.connect(userC)['close(address,bool)'](userC.address, false) await nextWithConstantPrice() expect(await market.orderReferrers(userC.address, currentId.add(2))).to.equal(constants.AddressZero) }) @@ -2332,15 +2403,7 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( - user.address, - POSITION, - 0, - 0, - COLLATERAL, - false, - constants.AddressZero, - ) + ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) expectOrderEq(await market.pendingOrder(1), { ...DEFAULT_ORDER, @@ -2409,25 +2472,25 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, 0, 0, COLLATERAL, constants.AddressZero) await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](userB.address, 0, POSITION, COLLATERAL, constants.AddressZero) await dsu.connect(userC).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](userC.address, 0, 0, COLLATERAL, constants.AddressZero) await dsu.connect(userD).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(userD) - ['update(address,uint256,uint256,uint256,int256,bool)'](userD.address, 0, POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](userD.address, POSITION, 0, COLLATERAL, constants.AddressZero) const intent = { amount: POSITION.div(2), diff --git a/packages/core/test/integration/core/happyPath.test.ts b/packages/core/test/integration/core/happyPath.test.ts index f2dc0326e..64e41a8ff 100644 --- a/packages/core/test/integration/core/happyPath.test.ts +++ b/packages/core/test/integration/core/happyPath.test.ts @@ -1045,7 +1045,7 @@ describe('Happy Path', () => { await chainlink.next() // close userB's position - await expect(market.connect(userB).close(userB.address, false)) + await expect(market.connect(userB)['close(address,bool)'](userB.address, false)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, diff --git a/packages/core/test/integration/core/liquidate.test.ts b/packages/core/test/integration/core/liquidate.test.ts index 4acfc0498..9972ab734 100644 --- a/packages/core/test/integration/core/liquidate.test.ts +++ b/packages/core/test/integration/core/liquidate.test.ts @@ -26,14 +26,12 @@ describe('Liquidate', () => { await dsu.connect(user).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) // Settle the market with a new oracle version await chainlink.nextWithPriceModification(price => price.mul(2)) - await expect( - market.connect(userB)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ) // liquidate + await expect(market.connect(userB)['close(address,bool)'](user.address, true)) // liquidate .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -52,7 +50,7 @@ describe('Liquidate', () => { chainlink.updateParams(parse6decimal('1.0'), parse6decimal('0.1')) await chainlink.next() - await market.connect(user)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false) // settle + await market.connect(user).settle(user.address) // settle expect((await market.locals(userB.address)).claimable).to.equal(parse6decimal('10')) await market.connect(userB).claimFee(userB.address) // liquidator withdrawal @@ -62,64 +60,12 @@ describe('Liquidate', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, 0, 0, - 0, COLLATERAL.sub(parse6decimal('11')).mul(-1), - false, - ) // withdraw everything - - expect((await market.position()).timestamp).to.eq(TIMESTAMP_2) - expect((await market.pendingOrders(user.address, 2)).protection).to.eq(1) - }) - - it('liquidates a user with close', async () => { - const POSITION = parse6decimal('10') - const COLLATERAL = parse6decimal('1000') - const { user, userB, dsu, chainlink } = instanceVars - - // reset chainlink params - chainlink.updateParams(BigNumber.from(0), BigNumber.from(0)) - - const market = await createMarket(instanceVars) - await dsu.connect(user).approve(market.address, COLLATERAL.mul(1e12)) - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) - - // Settle the market with a new oracle version - await chainlink.nextWithPriceModification(price => price.mul(2)) - - // liquidate user - await market.connect(userB).close(user.address, true) - - expect((await market.pendingOrders(user.address, 2)).protection).to.eq(1) - expect(await market.liquidators(user.address, 2)).to.eq(userB.address) - - expect((await market.locals(user.address)).collateral).to.equal(COLLATERAL) - expect(await dsu.balanceOf(market.address)).to.equal(utils.parseEther('1000')) - - chainlink.updateParams(parse6decimal('1.0'), parse6decimal('0.1')) - await chainlink.next() - await market.connect(user)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false) // settle - expect((await market.locals(userB.address)).claimable).to.equal(parse6decimal('10')) - await market.connect(userB).claimFee(userB.address) // liquidator withdrawal - - expect(await dsu.balanceOf(userB.address)).to.equal(utils.parseEther('200010')) // Original 200000 + fee - expect((await market.locals(user.address)).collateral).to.equal(parse6decimal('1000').sub(parse6decimal('11'))) - expect(await dsu.balanceOf(market.address)).to.equal(utils.parseEther('1000').sub(utils.parseEther('10'))) - - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - 0, - 0, - COLLATERAL.sub(parse6decimal('11')).mul(-1), - false, + constants.AddressZero, ) // withdraw everything expect((await market.position()).timestamp).to.eq(TIMESTAMP_2) @@ -136,23 +82,21 @@ describe('Liquidate', () => { await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - POSITION, - 0, 0, + POSITION, parse6decimal('1000'), - false, + constants.AddressZero, ) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, - 0, POSITION, 0, parse6decimal('1000'), - false, + constants.AddressZero, ) // Settle the market with a new oracle version @@ -166,17 +110,16 @@ describe('Liquidate', () => { await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, 0, 0, - 0, userBCollateral.mul(-1).sub(1), - false, + constants.AddressZero, ), ).to.be.revertedWithCustomError(market, 'MarketInsufficientMarginError') // underflow - await market.connect(userB)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true) // liquidate + await market.connect(userB)['close(address,bool)'](user.address, true) // liquidate chainlink.updateParams(parse6decimal('1.0'), parse6decimal('0.1')) await chainlink.nextWithPriceModification(price => price.mul(2)) @@ -189,7 +132,13 @@ describe('Liquidate', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, userCollateral.mul(-1), false) + ['update(address,int256,int256,int256,address)']( + user.address, + 0, + 0, + userCollateral.mul(-1), + constants.AddressZero, + ) expect((await market.locals(user.address)).collateral).to.equal(0) }) @@ -206,16 +155,28 @@ describe('Liquidate', () => { await dsu.connect(userD).approve(market.address, COLLATERAL.mul(10).mul(1e12)) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](userB.address, 0, POSITION, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, POSITION, 0, COLLATERAL.mul(10), false) + ['update(address,int256,int256,int256,address)']( + userC.address, + POSITION, + 0, + COLLATERAL.mul(10), + constants.AddressZero, + ) await market .connect(userD) - ['update(address,uint256,uint256,uint256,int256,bool)'](userD.address, 0, POSITION, 0, COLLATERAL.mul(10), false) + ['update(address,int256,int256,int256,address)']( + userD.address, + POSITION, + 0, + COLLATERAL.mul(10), + constants.AddressZero, + ) // Expect the system to remain solvent totalCollateral = (await market.locals(user.address)).collateral @@ -231,9 +192,7 @@ describe('Liquidate', () => { await chainlink.nextWithPriceModification(price => price.mul(2)) // Liquidate `user` which results in taker > maker - await expect( - market.connect(userB)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ) // liquidate + await expect(market.connect(userB)['close(address,bool)'](user.address, true)) // liquidate .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -305,24 +264,22 @@ describe('Liquidate', () => { // user establishes a maker position right at minMaintenance amount await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - parse6decimal('5'), - 0, 0, + parse6decimal('5'), COLLATERAL.div(2), - false, + constants.AddressZero, ) // userB takes a short position await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, + parse6decimal('4').mul(-1), 0, - 0, - parse6decimal('4'), COLLATERAL, - false, + constants.AddressZero, ) // two price drops occur while the maker has long exposure @@ -343,9 +300,7 @@ describe('Liquidate', () => { expect(collateral).to.be.greaterThan(maintenance) // userC liquidates - await expect( - market.connect(userC)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ) // liquidate + await expect(market.connect(userC)['close(address,bool)'](user.address, true)) // liquidate .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -403,16 +358,12 @@ describe('Liquidate', () => { await dsu.connect(user).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) // Settle the market with a new oracle version await chainlink.nextWithPriceModification(price => price.mul(2)) - await expect( - market - .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool,address)'](user.address, 0, 0, 0, 0, true, userC.address), - ) // liquidate + await expect(market.connect(userB)['close(address,bool,address)'](user.address, true, userC.address)) // liquidate .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -438,7 +389,7 @@ describe('Liquidate', () => { chainlink.updateParams(parse6decimal('1.0'), parse6decimal('0.1')) await chainlink.next() - await market.connect(user)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false) // settle + await market.connect(user)['close(address,bool)'](user.address, false) // settle expect((await market.locals(userB.address)).claimable).to.equal(parse6decimal('10')) await market.connect(userB).claimFee(userB.address) // liquidator withdrawal @@ -447,7 +398,7 @@ describe('Liquidate', () => { expect((await market.locals(userC.address)).claimable).to.equal(expectedClaimable) await chainlink.next() - await market.connect(user)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false) + await market.connect(user)['close(address,bool)'](user.address, false) await chainlink.next() await settle(market, user) diff --git a/packages/core/test/unit/market/Market.test.ts b/packages/core/test/unit/market/Market.test.ts index 95c6f1bfa..0299bff0b 100644 --- a/packages/core/test/unit/market/Market.test.ts +++ b/packages/core/test/unit/market/Market.test.ts @@ -23859,7 +23859,7 @@ describe('Market', () => { oracle.request.whenCalledWith(user.address).returns() await settle(market, user) - await expect(market.connect(user).close(user.address, false)) + await expect(market.connect(user)['close(address,bool)'](user.address, false)) .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -23935,7 +23935,7 @@ describe('Market', () => { await settle(market, user) - await expect(market.connect(user).close(user.address, false)) + await expect(market.connect(user)['close(address,bool)'](user.address, false)) .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -24012,7 +24012,7 @@ describe('Market', () => { await settle(market, user) - await expect(market.connect(user).close(user.address, false)) + await expect(market.connect(user)['close(address,bool)'](user.address, false)) .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -24110,7 +24110,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect(market.connect(liquidator).close(user.address, true)) + await expect(market.connect(liquidator)['close(address,bool)'](user.address, true)) .to.emit(market, 'OrderCreated') .withArgs( user.address, From 722ede73ef838710707a232cd2a3af63e7ab4ddb Mon Sep 17 00:00:00 2001 From: Prateek Date: Mon, 16 Dec 2024 23:43:15 +0530 Subject: [PATCH 15/29] disable CI --- .github/workflows/CI.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a998704d5..94dcab800 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -7,7 +7,6 @@ on: branches: - main - v2.4 - - prateek/pe-1629-remove-magic-values workflow_dispatch: env: From 9191e0ebfb47cffd39466615a0367489997ca930 Mon Sep 17 00:00:00 2001 From: Prateek Date: Tue, 17 Dec 2024 00:27:49 +0530 Subject: [PATCH 16/29] update comment and remove absolute order --- packages/core/contracts/types/Order.sol | 48 ++----------------------- 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/packages/core/contracts/types/Order.sol b/packages/core/contracts/types/Order.sol index b6307a54a..6ed2d2ae8 100644 --- a/packages/core/contracts/types/Order.sol +++ b/packages/core/contracts/types/Order.sol @@ -80,12 +80,13 @@ library OrderLib { (UFixed6Lib.ZERO, UFixed6Lib.ZERO, UFixed6Lib.ZERO, UFixed6Lib.ZERO, UFixed6Lib.ZERO, UFixed6Lib.ZERO); } - /// @notice Creates a new order from the an intent order request + /// @notice Creates a new order from the an intent and delta order request /// @param timestamp The current timestamp /// @param position The current position /// @param makerAmount The magnitude and direction of maker position /// @param takerAmount The magnitude and direction of taker position /// @param collateral The change in the collateral + /// @param protect Whether the order is protected /// @param referralFee The referral fee /// @return newOrder The resulting order function from( @@ -119,51 +120,6 @@ library OrderLib { newOrder.makerNeg = makerAmount.min(Fixed6Lib.ZERO).abs(); } - /// @notice Creates a new order from the current position and an update request - /// @param timestamp The current timestamp - /// @param position The current position - /// @param collateral The change in the collateral - /// @param newMaker The new maker - /// @param newLong The new long - /// @param newShort The new short - /// @param protect Whether to protect the order - /// @param referralFee The referral fee - /// @return newOrder The resulting order - function from( - uint256 timestamp, - Position memory position, - Fixed6 collateral, - UFixed6 newMaker, - UFixed6 newLong, - UFixed6 newShort, - bool protect, - UFixed6 referralFee - ) internal pure returns (Order memory newOrder) { - (Fixed6 makerAmount, Fixed6 longAmount, Fixed6 shortAmount) = ( - Fixed6Lib.from(newMaker).sub(Fixed6Lib.from(position.maker)), - Fixed6Lib.from(newLong).sub(Fixed6Lib.from(position.long)), - Fixed6Lib.from(newShort).sub(Fixed6Lib.from(position.short)) - ); - - UFixed6 referral = makerAmount.abs().add(longAmount.abs()).add(shortAmount.abs()).mul(referralFee); - - newOrder = Order( - timestamp, - 0, - collateral, - makerAmount.max(Fixed6Lib.ZERO).abs(), - makerAmount.min(Fixed6Lib.ZERO).abs(), - longAmount.max(Fixed6Lib.ZERO).abs(), - longAmount.min(Fixed6Lib.ZERO).abs(), - shortAmount.max(Fixed6Lib.ZERO).abs(), - shortAmount.min(Fixed6Lib.ZERO).abs(), - protect ? 1 : 0, - makerAmount.isZero() ? UFixed6Lib.ZERO : referral, - makerAmount.isZero() ? referral : UFixed6Lib.ZERO - ); - if (!isEmpty(newOrder)) newOrder.orders = 1; - } - /// @notice Returns whether the order increases any of the account's positions /// @return Whether the order increases any of the account's positions function increasesPosition(Order memory self) internal pure returns (bool) { From 3404c094e5d26b85e51876f83d30c140065f8f45 Mon Sep 17 00:00:00 2001 From: Prateek Date: Tue, 17 Dec 2024 17:34:46 +0530 Subject: [PATCH 17/29] update tests with delta update --- .../integration/core/closedProduct.test.ts | 24 ++--- .../core/test/integration/core/fees.test.ts | 102 +++++++++--------- .../test/integration/core/liquidate.test.ts | 36 +++---- .../arbitrum/migration/v2.3.test.ts | 6 +- .../MetaQuantsOracleFactory.test.ts | 4 +- .../pyth/PythOracleFactory.test.ts | 64 +++++------ .../chainlink/ChainlinkOracleFactory.test.ts | 6 +- .../CollateralAccounts/Controller.test.ts | 2 +- .../integration/MultiInvoker/Invoke.test.ts | 4 +- .../integration/MultiInvoker/Pyth.test.ts | 2 +- .../integration/MultiInvoker/setupHelpers.ts | 8 +- .../integration/TriggerOrders/Manager.test.ts | 2 +- .../test/integration/vault/Vault.test.ts | 42 ++++---- 13 files changed, 151 insertions(+), 151 deletions(-) diff --git a/packages/core/test/integration/core/closedProduct.test.ts b/packages/core/test/integration/core/closedProduct.test.ts index 39e5e8480..6ec085b9f 100644 --- a/packages/core/test/integration/core/closedProduct.test.ts +++ b/packages/core/test/integration/core/closedProduct.test.ts @@ -56,10 +56,10 @@ describe('Closed Market', () => { await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](userB.address, 0, POSITION, COLLATERAL, constants.AddressZero) const parameters = { ...(await market.parameter()) } parameters.closed = true await market.updateParameter(parameters) @@ -73,7 +73,7 @@ describe('Closed Market', () => { await expect( market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, 0, constants.AddressZero), + ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, 0, constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketClosedError') }) @@ -82,7 +82,7 @@ describe('Closed Market', () => { await chainlink.next() - await expect(await market.connect(user)['close(address,bool)'](user.address, false)).to.not.be.reverted + await expect(await market.connect(user).close(user.address, false, constants.AddressZero)).to.not.be.reverted }) }) @@ -96,10 +96,10 @@ describe('Closed Market', () => { await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](userB.address, 0, POSITION, COLLATERAL, constants.AddressZero) await chainlink.next() await chainlink.next() @@ -119,8 +119,8 @@ describe('Closed Market', () => { await chainlink.nextWithPriceModification(price => price.mul(4)) const LIQUIDATION_FEE = BigNumber.from('1000000000') - await market.connect(user)['close(address,bool)'](user.address, true) - await market.connect(userB)['close(address,bool)'](userB.address, true) + await market.connect(user).close(user.address, true, constants.AddressZero) + await market.connect(userB).close(userB.address, true, constants.AddressZero) expect((await market.locals(user.address)).collateral).to.equal(userCollateralBefore) expect((await market.locals(userB.address)).collateral).to.equal(userBCollateralBefore) @@ -139,14 +139,14 @@ describe('Closed Market', () => { await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](userB.address, 0, POSITION, COLLATERAL, constants.AddressZero) await chainlink.next() await chainlink.nextWithPriceModification(price => price.mul(2)) - await expect(market.connect(userB)['close(address,bool)'](user.address, true)).to.not.be.reverted + await expect(market.connect(userB).close(user.address, true, constants.AddressZero)).to.not.be.reverted expect((await market.pendingOrders(user.address, 2)).protection).to.eq(1) const parameters = { ...(await market.parameter()) } parameters.closed = true @@ -169,7 +169,7 @@ describe('Closed Market', () => { const LIQUIDATION_FEE = BigNumber.from('1000000000') await settle(market, user) - await market.connect(userB)['close(address,bool)'](userB.address, true) + await market.connect(userB).close(userB.address, true, constants.AddressZero) expect((await market.locals(user.address)).collateral).to.equal(userCollateralBefore) expect((await market.locals(userB.address)).collateral).to.equal(userBCollateralBefore) diff --git a/packages/core/test/integration/core/fees.test.ts b/packages/core/test/integration/core/fees.test.ts index 2e0880c67..39d0fbc0b 100644 --- a/packages/core/test/integration/core/fees.test.ts +++ b/packages/core/test/integration/core/fees.test.ts @@ -122,8 +122,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, POSITION, + 0, COLLATERAL, constants.AddressZero, ), @@ -231,8 +231,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, POSITION, + 0, COLLATERAL, constants.AddressZero, ), @@ -252,7 +252,7 @@ describe('Fees', () => { await market.updateRiskParameter(previousRiskParams) await market.updateParameter(previousMarketParams) - await market.connect(user)['close(address,bool)'](user.address, false) + await market.connect(user).close(user.address, false, constants.AddressZero) // Settle the market with a new oracle version await nextWithConstantPrice() @@ -342,8 +342,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, MAKER_POSITION, + 0, COLLATERAL, constants.AddressZero, ) @@ -352,8 +352,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - LONG_POSITION, 0, + LONG_POSITION, COLLATERAL, constants.AddressZero, ), @@ -480,8 +480,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, MAKER_POSITION, + 0, COLLATERAL, constants.AddressZero, ) @@ -495,8 +495,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - LONG_POSITION, 0, + LONG_POSITION, COLLATERAL, constants.AddressZero, ), @@ -664,8 +664,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, MAKER_POSITION, + 0, COLLATERAL, constants.AddressZero, ) @@ -674,8 +674,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - LONG_POSITION, 0, + LONG_POSITION, COLLATERAL, constants.AddressZero, ), @@ -714,7 +714,7 @@ describe('Fees', () => { makerFee: 0, }) - await market.connect(userB)['close(address,bool)'](userB.address, false) + await market.connect(userB).close(userB.address, false, constants.AddressZero) await nextWithConstantPrice() const txLong = await settle(market, userB) @@ -843,8 +843,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, MAKER_POSITION, + 0, COLLATERAL, constants.AddressZero, ) @@ -853,8 +853,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - SHORT_POSITION.mul(-1), 0, + SHORT_POSITION.mul(-1), COLLATERAL, constants.AddressZero, ), @@ -981,8 +981,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, MAKER_POSITION, + 0, COLLATERAL, constants.AddressZero, ) @@ -995,8 +995,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - SHORT_POSITION.mul(-1), 0, + SHORT_POSITION.mul(-1), COLLATERAL, constants.AddressZero, ), @@ -1162,8 +1162,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, MAKER_POSITION, + 0, COLLATERAL, constants.AddressZero, ) @@ -1172,8 +1172,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - SHORT_POSITION.mul(-1), 0, + SHORT_POSITION.mul(-1), COLLATERAL, constants.AddressZero, ), @@ -1211,7 +1211,7 @@ describe('Fees', () => { fundingFee: BigNumber.from('0'), makerFee: 0, }) - await market.connect(userB)['close(address,bool)'](userB.address, false) + await market.connect(userB).close(userB.address, false, constants.AddressZero) await nextWithConstantPrice() const txLong = await settle(market, userB) @@ -1354,8 +1354,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, MAKER_POSITION, + 0, COLLATERAL, constants.AddressZero, ) @@ -1371,8 +1371,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - SHORT_POSITION.mul(-1), 0, + SHORT_POSITION.mul(-1), COLLATERAL, constants.AddressZero, ) @@ -1399,8 +1399,8 @@ describe('Fees', () => { .connect(userC) ['update(address,int256,int256,int256,address)']( userC.address, - LONG_POSITION.mul(2), 0, + LONG_POSITION.mul(2), COLLATERAL, constants.AddressZero, ) @@ -1467,8 +1467,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, MAKER_POSITION, + 0, COLLATERAL, constants.AddressZero, ) @@ -1484,8 +1484,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - SHORT_POSITION.mul(-1), 0, + SHORT_POSITION.mul(-1), COLLATERAL, constants.AddressZero, ) @@ -1511,8 +1511,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - LONG_POSITION, 0, + LONG_POSITION, COLLATERAL, constants.AddressZero, ) @@ -1538,8 +1538,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - SHORT_POSITION.mul(-1), 0, + SHORT_POSITION.mul(-1), COLLATERAL, constants.AddressZero, ) @@ -1562,8 +1562,8 @@ describe('Fees', () => { .connect(userC) ['update(address,int256,int256,int256,address)']( userC.address, - LONG_POSITION, 0, + LONG_POSITION, COLLATERAL, constants.AddressZero, ) @@ -1592,8 +1592,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - SHORT_POSITION.mul(-1), 0, + SHORT_POSITION.mul(-1), COLLATERAL, constants.AddressZero, ) @@ -1616,8 +1616,8 @@ describe('Fees', () => { .connect(userC) ['update(address,int256,int256,int256,address)']( userC.address, - LONG_POSITION, 0, + LONG_POSITION, COLLATERAL, constants.AddressZero, ) @@ -1678,8 +1678,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, MAKER_POSITION, + 0, COLLATERAL, constants.AddressZero, ) @@ -1700,9 +1700,9 @@ describe('Fees', () => { .connect(instanceVars.user) ['update(address,int256,int256,int256,address)']( instanceVars.user.address, - 0, MAKER_POSITION, 0, + 0, constants.AddressZero, ) @@ -1731,8 +1731,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - LONG_POSITION, 0, + LONG_POSITION, COLLATERAL, constants.AddressZero, ) @@ -1740,8 +1740,8 @@ describe('Fees', () => { .connect(userC) ['update(address,int256,int256,int256,address)']( userC.address, - SHORT_POSITION.mul(-1), 0, + SHORT_POSITION.mul(-1), COLLATERAL, constants.AddressZero, ) @@ -1811,8 +1811,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, MAKER_POSITION, + 0, COLLATERAL, constants.AddressZero, ) @@ -1827,8 +1827,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - LONG_POSITION, 0, + LONG_POSITION, COLLATERAL, constants.AddressZero, ) @@ -1871,8 +1871,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - SHORT_POSITION.mul(-1), 0, + SHORT_POSITION.mul(-1), COLLATERAL, constants.AddressZero, ) @@ -1947,8 +1947,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, MAKER_POSITION, + 0, COLLATERAL, constants.AddressZero, ) @@ -1963,8 +1963,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - LONG_POSITION, 0, + LONG_POSITION, COLLATERAL, constants.AddressZero, ) @@ -2007,8 +2007,8 @@ describe('Fees', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - SHORT_POSITION.mul(-1), 0, + SHORT_POSITION.mul(-1), COLLATERAL, constants.AddressZero, ) @@ -2078,7 +2078,7 @@ describe('Fees', () => { // userB creates a maker position, referred by user await market .connect(userB) - ['update(address,int256,int256,int256,address)'](userB.address, 0, POSITION, COLLATERAL, user.address) + ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, user.address) const expectedReferral = parse6decimal('0.15').mul(3) // referralFee * position expectOrderEq(await market.pendingOrder(1), { ...DEFAULT_ORDER, @@ -2122,8 +2122,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, POSITION.mul(2), + 0, COLLATERAL.mul(2), constants.AddressZero, ) @@ -2133,8 +2133,8 @@ describe('Fees', () => { .connect(userC) ['update(address,int256,int256,int256,address)']( userC.address, - POSITION.mul(-1), 0, + POSITION.mul(-1), COLLATERAL.mul(2), userB.address, ) @@ -2184,7 +2184,7 @@ describe('Fees', () => { // userB creates a maker position, referred by user await market .connect(userB) - ['update(address,int256,int256,int256,address)'](userB.address, 0, POSITION, COLLATERAL, user.address) + ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, user.address) const expectedReferral = parse6decimal('0.17').mul(3) // referralFee * position expectOrderEq(await market.pendingOrder(1), { ...DEFAULT_ORDER, @@ -2221,15 +2221,15 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, POSITION.mul(2), + 0, COLLATERAL.mul(2), userB.address, ) // userC creates a long position referred by user await market .connect(userC) - ['update(address,int256,int256,int256,address)'](userC.address, POSITION, 0, COLLATERAL.mul(2), user.address) + ['update(address,int256,int256,int256,address)'](userC.address, 0, POSITION, COLLATERAL.mul(2), user.address) expectOrderEq(await market.pendingOrder(1), { ...DEFAULT_ORDER, timestamp: TIMESTAMP_1, @@ -2278,8 +2278,8 @@ describe('Fees', () => { .connect(userD) ['update(address,int256,int256,int256,address)']( userD.address, - POSITION.mul(2).div(3).mul(-1), 0, + POSITION.mul(2).div(3).mul(-1), COLLATERAL, user.address, ) @@ -2314,8 +2314,8 @@ describe('Fees', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, POSITION.mul(2), + 0, COLLATERAL.mul(2), constants.AddressZero, ) @@ -2325,8 +2325,8 @@ describe('Fees', () => { .connect(userC) ['update(address,int256,int256,int256,address)']( userC.address, - POSITION.mul(-1), 0, + POSITION.mul(-1), COLLATERAL.mul(2), userB.address, ) @@ -2363,7 +2363,7 @@ describe('Fees', () => { .withArgs(userB.address, userB.address, expectedClaimable) // userC closes a short position referred by user - await market.connect(userC)['close(address,bool,address)'](userC.address, false, user.address) + await market.connect(userC).close(userC.address, false, user.address) await nextWithConstantPrice() await settle(market, user) @@ -2388,7 +2388,7 @@ describe('Fees', () => { await nextWithConstantPrice() // userC opens a short position referred by no one - await market.connect(userC)['close(address,bool)'](userC.address, false) + await market.connect(userC).close(userC.address, false, constants.AddressZero) await nextWithConstantPrice() expect(await market.orderReferrers(userC.address, currentId.add(2))).to.equal(constants.AddressZero) }) @@ -2403,7 +2403,7 @@ describe('Fees', () => { await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) expectOrderEq(await market.pendingOrder(1), { ...DEFAULT_ORDER, @@ -2478,7 +2478,7 @@ describe('Fees', () => { await market .connect(userB) - ['update(address,int256,int256,int256,address)'](userB.address, 0, POSITION, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) await dsu.connect(userC).approve(market.address, COLLATERAL.mul(1e12)) @@ -2490,7 +2490,7 @@ describe('Fees', () => { await market .connect(userD) - ['update(address,int256,int256,int256,address)'](userD.address, POSITION, 0, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](userD.address, 0, POSITION, COLLATERAL, constants.AddressZero) const intent = { amount: POSITION.div(2), diff --git a/packages/core/test/integration/core/liquidate.test.ts b/packages/core/test/integration/core/liquidate.test.ts index 311aca86d..dc63747f2 100644 --- a/packages/core/test/integration/core/liquidate.test.ts +++ b/packages/core/test/integration/core/liquidate.test.ts @@ -26,12 +26,12 @@ describe('Liquidate', () => { await dsu.connect(user).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) // Settle the market with a new oracle version await chainlink.nextWithPriceModification(price => price.mul(2)) - await expect(market.connect(userB)['close(address,bool)'](user.address, true)) // liquidate + await expect(market.connect(userB).close(user.address, true, constants.AddressZero)) // liquidate .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -65,7 +65,7 @@ describe('Liquidate', () => { 0, 0, COLLATERAL.sub(parse6decimal('11')).mul(-1), - false, + constants.AddressZero, ) // withdraw everything expect((await market.position()).timestamp).to.eq(TIMESTAMP_2) @@ -135,8 +135,8 @@ describe('Liquidate', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, POSITION, + 0, parse6decimal('1000'), constants.AddressZero, ) @@ -144,8 +144,8 @@ describe('Liquidate', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - POSITION, 0, + POSITION, parse6decimal('1000'), constants.AddressZero, ) @@ -170,7 +170,7 @@ describe('Liquidate', () => { ), ).to.be.revertedWithCustomError(market, 'MarketInsufficientMarginError') // underflow - await market.connect(userB)['close(address,bool)'](user.address, true) // liquidate + await market.connect(userB).close(user.address, true, constants.AddressZero) // liquidate chainlink.updateParams(parse6decimal('1.0'), parse6decimal('0.1')) await chainlink.nextWithPriceModification(price => price.mul(2)) @@ -206,16 +206,16 @@ describe('Liquidate', () => { await dsu.connect(userD).approve(market.address, COLLATERAL.mul(10).mul(1e12)) await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,int256,int256,int256,address)'](userB.address, 0, POSITION, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) ['update(address,int256,int256,int256,address)']( userC.address, - POSITION, 0, + POSITION, COLLATERAL.mul(10), constants.AddressZero, ) @@ -223,8 +223,8 @@ describe('Liquidate', () => { .connect(userD) ['update(address,int256,int256,int256,address)']( userD.address, - POSITION, 0, + POSITION, COLLATERAL.mul(10), constants.AddressZero, ) @@ -243,7 +243,7 @@ describe('Liquidate', () => { await chainlink.nextWithPriceModification(price => price.mul(2)) // Liquidate `user` which results in taker > maker - await expect(market.connect(userB)['close(address,bool)'](user.address, true)) // liquidate + await expect(market.connect(userB).close(user.address, true, constants.AddressZero)) // liquidate .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -317,8 +317,8 @@ describe('Liquidate', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, parse6decimal('5'), + 0, COLLATERAL.div(2), constants.AddressZero, ) @@ -327,8 +327,8 @@ describe('Liquidate', () => { .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - parse6decimal('4').mul(-1), 0, + parse6decimal('4').mul(-1), COLLATERAL, constants.AddressZero, ) @@ -351,7 +351,7 @@ describe('Liquidate', () => { expect(collateral).to.be.greaterThan(maintenance) // userC liquidates - await expect(market.connect(userC)['close(address,bool)'](user.address, true)) // liquidate + await expect(market.connect(userC).close(user.address, true, constants.AddressZero)) // liquidate .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -409,12 +409,12 @@ describe('Liquidate', () => { await dsu.connect(user).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) // Settle the market with a new oracle version await chainlink.nextWithPriceModification(price => price.mul(2)) - await expect(market.connect(userB)['close(address,bool,address)'](user.address, true, userC.address)) // liquidate + await expect(market.connect(userB).close(user.address, true, userC.address)) // liquidate .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -440,7 +440,7 @@ describe('Liquidate', () => { chainlink.updateParams(parse6decimal('1.0'), parse6decimal('0.1')) await chainlink.next() - await market.connect(user)['close(address,bool)'](user.address, false) // settle + await market.connect(user).close(user.address, false, constants.AddressZero) // settle expect((await market.locals(userB.address)).claimable).to.equal(parse6decimal('10')) await market.connect(userB).claimFee(userB.address) // liquidator withdrawal @@ -449,7 +449,7 @@ describe('Liquidate', () => { expect((await market.locals(userC.address)).claimable).to.equal(expectedClaimable) await chainlink.next() - await market.connect(user)['close(address,bool)'](user.address, false) + await market.connect(user).close(user.address, false, constants.AddressZero) await chainlink.next() await settle(market, user) diff --git a/packages/deploy/test/verification/arbitrum/migration/v2.3.test.ts b/packages/deploy/test/verification/arbitrum/migration/v2.3.test.ts index b25b043b2..7fd6a2163 100644 --- a/packages/deploy/test/verification/arbitrum/migration/v2.3.test.ts +++ b/packages/deploy/test/verification/arbitrum/migration/v2.3.test.ts @@ -525,8 +525,8 @@ describe('Verify Arbitrum v2.3 Migration', () => { await commitPriceForIds([oracleIDs[0].id, oracleIDs[1].id], currentTimestamp) const nextVersionTimestamp = nextVersionForTimestamp(await currentBlockTimestamp()) - await ethMarket.connect(liquidatorSigner)['close(address,bool)'](liquidatorSigner.address, false) - await btcMarket.connect(liquidatorSigner)['close(address,bool)'](liquidatorSigner.address, false) + await ethMarket.connect(liquidatorSigner).close(liquidatorSigner.address, false, constants.AddressZero) + await btcMarket.connect(liquidatorSigner).close(liquidatorSigner.address, false, constants.AddressZero) await increase(10) @@ -558,7 +558,7 @@ describe('Verify Arbitrum v2.3 Migration', () => { .connect(ownerSigner) .updateRiskParameter({ ...riskParameter, minMargin: 500e6, minMaintenance: 500e6 }) - await ethMarket.connect(liquidator)['close(address,bool)'](perennialUser.address, true) + await ethMarket.connect(liquidator).close(perennialUser.address, true, constants.AddressZero) await commitPriceForIds([oracleIDs[0].id], nextVersionForTimestamp(await currentBlockTimestamp()) + 4) await ethMarket.connect(liquidator).settle(perennialUser.address) diff --git a/packages/oracle/test/integration/metaquants/MetaQuantsOracleFactory.test.ts b/packages/oracle/test/integration/metaquants/MetaQuantsOracleFactory.test.ts index d98df5c13..551761333 100644 --- a/packages/oracle/test/integration/metaquants/MetaQuantsOracleFactory.test.ts +++ b/packages/oracle/test/integration/metaquants/MetaQuantsOracleFactory.test.ts @@ -476,8 +476,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -513,8 +513,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), diff --git a/packages/oracle/test/integration/pyth/PythOracleFactory.test.ts b/packages/oracle/test/integration/pyth/PythOracleFactory.test.ts index 1e7846d1f..305c9a6f0 100644 --- a/packages/oracle/test/integration/pyth/PythOracleFactory.test.ts +++ b/packages/oracle/test/integration/pyth/PythOracleFactory.test.ts @@ -597,8 +597,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -635,8 +635,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -672,8 +672,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -704,8 +704,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -722,8 +722,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -736,7 +736,7 @@ testOracles.forEach(testOracle => { }) await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, 2, 0, constants.AddressZero) // make request to oracle (new price) + ['update(address,int256,int256,int256,address)'](user.address, 2, 0, 0, constants.AddressZero) // make request to oracle (new price) await expect( pythOracleFactory.connect(user).commit([PYTH_ETH_USD_PRICE_FEED], STARTING_TIME, VAA, { value: 1, @@ -751,8 +751,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -774,8 +774,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -785,7 +785,7 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, 2, 0, constants.AddressZero), // make request to oracle (new price) + ['update(address,int256,int256,int256,address)'](user.address, 2, 0, 0, constants.AddressZero), // make request to oracle (new price) STARTING_TIME + 1, ) @@ -806,8 +806,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -817,7 +817,7 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, 2, 0, constants.AddressZero), // make request to oracle (new price) + ['update(address,int256,int256,int256,address)'](user.address, 2, 0, 0, constants.AddressZero), // make request to oracle (new price) STARTING_TIME + 60, ) expect(await keeperOracle.requests(1)).to.be.equal(STARTING_TIME) @@ -884,8 +884,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -909,8 +909,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -922,7 +922,7 @@ testOracles.forEach(testOracle => { async () => await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, 2, 0, constants.AddressZero), // make request to oracle (new price) + ['update(address,int256,int256,int256,address)'](user.address, 2, 0, 0, constants.AddressZero), // make request to oracle (new price) 1686199141, ) const secondRequestedVersion = await time.currentBlockTimestamp() @@ -957,8 +957,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -982,8 +982,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -1020,8 +1020,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -1046,8 +1046,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -1079,8 +1079,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -1100,8 +1100,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ) @@ -1109,8 +1109,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ) @@ -1156,8 +1156,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), // make request to oracle (new price) @@ -1196,8 +1196,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), // make request to oracle (new price) @@ -1223,8 +1223,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), // make request to oracle (new price) @@ -1247,8 +1247,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ) // make request to oracle (new price) @@ -1273,8 +1273,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), // make request to oracle (new price) @@ -1298,8 +1298,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ) // make request to oracle (new price) @@ -1330,14 +1330,14 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ) // make request to oracle (new price) await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, 2, 0, constants.AddressZero) // make request to oracle (new price) + ['update(address,int256,int256,int256,address)'](user.address, 2, 0, 0, constants.AddressZero) // make request to oracle (new price) await ethers.provider.send('evm_mine', []) @@ -1355,8 +1355,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), // make request to oracle (new price) @@ -1507,8 +1507,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), // make request to oracle (new price) @@ -1536,8 +1536,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ) // make request to oracle (new price) diff --git a/packages/oracle/test/integrationSepolia/chainlink/ChainlinkOracleFactory.test.ts b/packages/oracle/test/integrationSepolia/chainlink/ChainlinkOracleFactory.test.ts index 20a85ec55..e49430503 100644 --- a/packages/oracle/test/integrationSepolia/chainlink/ChainlinkOracleFactory.test.ts +++ b/packages/oracle/test/integrationSepolia/chainlink/ChainlinkOracleFactory.test.ts @@ -423,8 +423,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -461,8 +461,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), @@ -495,8 +495,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ), diff --git a/packages/periphery/test/integration/CollateralAccounts/Controller.test.ts b/packages/periphery/test/integration/CollateralAccounts/Controller.test.ts index 9160ff937..fd2b77661 100644 --- a/packages/periphery/test/integration/CollateralAccounts/Controller.test.ts +++ b/packages/periphery/test/integration/CollateralAccounts/Controller.test.ts @@ -120,8 +120,8 @@ export function RunControllerBaseTests( .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - longDelta.sub(shortDelta), makerDelta, + longDelta.sub(shortDelta), BigNumber.from(0), constants.AddressZero, TX_OVERRIDES, diff --git a/packages/periphery/test/integration/MultiInvoker/Invoke.test.ts b/packages/periphery/test/integration/MultiInvoker/Invoke.test.ts index b9e18c003..d4ce560cc 100644 --- a/packages/periphery/test/integration/MultiInvoker/Invoke.test.ts +++ b/packages/periphery/test/integration/MultiInvoker/Invoke.test.ts @@ -791,8 +791,8 @@ export function RunInvokerTests( .connect(userC) ['update(address,int256,int256,int256,address)']( userC.address, - 0, parse6decimal('1'), + 0, ethers.utils.parseUnits('1000', 6), constants.AddressZero, ) @@ -859,8 +859,8 @@ export function RunInvokerTests( .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - 0, parse6decimal('3'), + 0, parse6decimal('600'), user.address, ) diff --git a/packages/periphery/test/integration/MultiInvoker/Pyth.test.ts b/packages/periphery/test/integration/MultiInvoker/Pyth.test.ts index 28f5aa08d..70d424c96 100644 --- a/packages/periphery/test/integration/MultiInvoker/Pyth.test.ts +++ b/packages/periphery/test/integration/MultiInvoker/Pyth.test.ts @@ -91,8 +91,8 @@ export function RunPythOracleTests( .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('1000'), constants.AddressZero, ), diff --git a/packages/periphery/test/integration/MultiInvoker/setupHelpers.ts b/packages/periphery/test/integration/MultiInvoker/setupHelpers.ts index 7745c6813..99cf9df12 100644 --- a/packages/periphery/test/integration/MultiInvoker/setupHelpers.ts +++ b/packages/periphery/test/integration/MultiInvoker/setupHelpers.ts @@ -313,8 +313,8 @@ export async function createVault( .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, parse6decimal('100'), + 0, parse6decimal('100000'), constants.AddressZero, ) @@ -322,8 +322,8 @@ export async function createVault( .connect(userB) ['update(address,int256,int256,int256,address)']( userB.address, - parse6decimal('50'), 0, + parse6decimal('50'), parse6decimal('100000'), constants.AddressZero, ) @@ -331,8 +331,8 @@ export async function createVault( .connect(userC) ['update(address,int256,int256,int256,address)']( userC.address, - 0, parse6decimal('20'), + 0, parse6decimal('100000'), constants.AddressZero, ) @@ -340,8 +340,8 @@ export async function createVault( .connect(userD) ['update(address,int256,int256,int256,address)']( userD.address, - parse6decimal('10'), 0, + parse6decimal('10'), parse6decimal('100000'), constants.AddressZero, ) diff --git a/packages/periphery/test/integration/TriggerOrders/Manager.test.ts b/packages/periphery/test/integration/TriggerOrders/Manager.test.ts index d09a9351a..d86c8586a 100644 --- a/packages/periphery/test/integration/TriggerOrders/Manager.test.ts +++ b/packages/periphery/test/integration/TriggerOrders/Manager.test.ts @@ -669,8 +669,8 @@ export function RunManagerTests(name: string, getFixture: (overrides?: CallOverr .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - longDelta.sub(shortDelta), makerDelta, + longDelta.sub(shortDelta), BigNumber.from(0), constants.AddressZero, TX_OVERRIDES, diff --git a/packages/vault/test/integration/vault/Vault.test.ts b/packages/vault/test/integration/vault/Vault.test.ts index bba75f8d3..162747261 100644 --- a/packages/vault/test/integration/vault/Vault.test.ts +++ b/packages/vault/test/integration/vault/Vault.test.ts @@ -328,8 +328,8 @@ describe('Vault', () => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, parse6decimal('200'), + 0, parse6decimal('100000'), constants.AddressZero, ) @@ -337,8 +337,8 @@ describe('Vault', () => { .connect(user2) ['update(address,int256,int256,int256,address)']( user2.address, - parse6decimal('100'), 0, + parse6decimal('100'), parse6decimal('100000'), constants.AddressZero, ) @@ -346,8 +346,8 @@ describe('Vault', () => { .connect(btcUser1) ['update(address,int256,int256,int256,address)']( btcUser1.address, - 0, parse6decimal('20'), + 0, parse6decimal('100000'), constants.AddressZero, ) @@ -355,8 +355,8 @@ describe('Vault', () => { .connect(btcUser2) ['update(address,int256,int256,int256,address)']( btcUser2.address, - parse6decimal('10'), 0, + parse6decimal('10'), parse6decimal('100000'), constants.AddressZero, ) @@ -967,8 +967,8 @@ describe('Vault', () => { await asset.connect(perennialUser).approve(market.address, constants.MaxUint256) await market.connect(perennialUser)['update(address,int256,int256,int256,address)']( perennialUser.address, - 0, makerAvailable.sub(reservedForVault), // 795 + 0, parse6decimal('662500'), constants.AddressZero, ) @@ -1156,8 +1156,8 @@ describe('Vault', () => { .connect(perennialUser) ['update(address,int256,int256,int256,address)']( perennialUser.address, - currentPosition.maker.sub(currentNet).sub(parse6decimal('1')), 0, + currentPosition.maker.sub(currentNet).sub(parse6decimal('1')), parse6decimal('1000000'), constants.AddressZero, ) @@ -1195,8 +1195,8 @@ describe('Vault', () => { .connect(perennialUser) ['update(address,int256,int256,int256,address)']( perennialUser.address, - currentPosition.maker.sub(currentNet).sub(parse6decimal('0.1')), 0, + currentPosition.maker.sub(currentNet).sub(parse6decimal('0.1')), parse6decimal('1000000'), constants.AddressZero, ) @@ -1309,8 +1309,8 @@ describe('Vault', () => { .connect(perennialUser) ['update(address,int256,int256,int256,address)']( perennialUser.address, - 0, parse6decimal('480'), + 0, parse6decimal('400000'), constants.AddressZero, ) @@ -1337,8 +1337,8 @@ describe('Vault', () => { .connect(perennialUser) ['update(address,int256,int256,int256,address)']( perennialUser.address, - 0, makerAvailable, + 0, parse6decimal('400000'), constants.AddressZero, ) @@ -1371,8 +1371,8 @@ describe('Vault', () => { .connect(perennialUser) ['update(address,int256,int256,int256,address)']( perennialUser.address, - parse6decimal('110'), 0, + parse6decimal('110'), parse6decimal('1000000'), constants.AddressZero, ) @@ -1996,7 +1996,7 @@ describe('Vault', () => { // 2. Settle accounts / Liquidate the vault's maker position. const EXPECTED_LIQUIDATION_FEE = BigNumber.from('5149547500') - await btcMarket.connect(user)['close(address,bool)'](vault.address, true) + await btcMarket.connect(user).close(vault.address, true, constants.AddressZero) expect((await btcMarket.locals(vault.address)).collateral).to.equal( BigNumber.from('4428767485').add(EXPECTED_LIQUIDATION_FEE), ) // no shortfall @@ -2030,7 +2030,7 @@ describe('Vault', () => { // 2. Settle accounts / Liquidate the vault's maker position. const EXPECTED_LIQUIDATION_FEE = BigNumber.from('8239276000') - await btcMarket.connect(user)['close(address,bool)'](vault.address, true) + await btcMarket.connect(user).close(vault.address, true, constants.AddressZero) expect((await btcMarket.locals(vault.address)).collateral).to.equal( BigNumber.from('-26673235277').add(EXPECTED_LIQUIDATION_FEE), ) // shortfall @@ -2061,8 +2061,8 @@ describe('Vault', () => { beforeEach(async () => { await updateOracle() - await market.connect(user2)['close(address,bool)'](user2.address, false) - await btcMarket.connect(btcUser2)['close(address,bool)'](btcUser2.address, false) + await market.connect(user2).close(user2.address, false, constants.AddressZero) + await btcMarket.connect(btcUser2).close(btcUser2.address, false, constants.AddressZero) await updateOracle() // get utilization closer to target in order to trigger pnl on price deviation @@ -2071,8 +2071,8 @@ describe('Vault', () => { ['update(address,int256,int256,int256,address)']( user2.address, parse6decimal('100').mul(-1), - 0, parse6decimal('100000'), + 0, constants.AddressZero, ) await btcMarket @@ -2080,8 +2080,8 @@ describe('Vault', () => { ['update(address,int256,int256,int256,address)']( btcUser2.address, parse6decimal('10').mul(-1), - 0, parse6decimal('100000'), + 0, constants.AddressZero, ) await updateOracle() @@ -2097,7 +2097,7 @@ describe('Vault', () => { // 2. Settle accounts / Liquidate the vault's maker position. const EXPECTED_LIQUIDATION_FEE = BigNumber.from('2059819000') - await btcMarket.connect(user)['close(address,bool)'](vault.address, true) + await btcMarket.connect(user).close(vault.address, true, constants.AddressZero) expect((await btcMarket.locals(vault.address)).collateral).to.equal( BigNumber.from('350411418').add(EXPECTED_LIQUIDATION_FEE), ) // no shortfall @@ -2131,7 +2131,7 @@ describe('Vault', () => { // 2. Settle accounts / Liquidate the vault's maker position. const EXPECTED_LIQUIDATION_FEE = BigNumber.from('1956828050') - await btcMarket.connect(user)['close(address,bool)'](vault.address, true) + await btcMarket.connect(user).close(vault.address, true, constants.AddressZero) expect((await btcMarket.locals(vault.address)).collateral).to.equal( BigNumber.from('-480340107').add(EXPECTED_LIQUIDATION_FEE), ) // shortfall @@ -2172,9 +2172,9 @@ describe('Vault', () => { // 3. An oracle update makes the long position liquidatable, initiate take close await updateOracle(parse6decimal('10000')) - await market.connect(user)['close(address,bool)'](vault.address, true) + await market.connect(user).close(vault.address, true, constants.AddressZero) await settle(market, user2) - await market.connect(user2)['close(address,bool)'](user2.address, false) + await market.connect(user2).close(user2.address, false, constants.AddressZero) // 4. Settle the vault to recover and rebalance await updateOracle() // let take settle at high price @@ -2231,7 +2231,7 @@ describe('Vault', () => { // 3. An oracle update makes the long position liquidatable, initiate take close await updateOracle(parse6decimal('20000')) - await market.connect(user)['close(address,bool)'](vault.address, true) + await market.connect(user).close(vault.address, true, constants.AddressZero) await updateOracle() await vault.connect(user).update(user.address, 0, 1, 0) // redeem 1 share to trigger rebalance From 58c2f0b5a6bc251ff60b69717ca7f0fa3b741842 Mon Sep 17 00:00:00 2001 From: Prateek Date: Tue, 17 Dec 2024 17:37:19 +0530 Subject: [PATCH 18/29] update workflow to run tests on CI --- .github/workflows/CI.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 94dcab800..a998704d5 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -7,6 +7,7 @@ on: branches: - main - v2.4 + - prateek/pe-1629-remove-magic-values workflow_dispatch: env: From 7fb6985e1dfea2f83a607862d7fc26bdc5c82c11 Mon Sep 17 00:00:00 2001 From: Prateek Date: Tue, 17 Dec 2024 21:37:51 +0530 Subject: [PATCH 19/29] update contracts with new delta update --- .../periphery/contracts/MultiInvoker/MultiInvoker.sol | 8 ++++---- .../contracts/TriggerOrders/types/TriggerOrder.sol | 4 ++-- packages/periphery/test/helpers/MultiInvoker/invoke.ts | 4 ++-- packages/vault/contracts/Vault.sol | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/periphery/contracts/MultiInvoker/MultiInvoker.sol b/packages/periphery/contracts/MultiInvoker/MultiInvoker.sol index 6c2a893f1..619edb366 100644 --- a/packages/periphery/contracts/MultiInvoker/MultiInvoker.sol +++ b/packages/periphery/contracts/MultiInvoker/MultiInvoker.sol @@ -131,15 +131,15 @@ contract MultiInvoker is IMultiInvoker, Initializable { ( // update data IMarket market, - Fixed6 taker, Fixed6 maker, + Fixed6 taker, Fixed6 collateral, bool wrap, InterfaceFee memory interfaceFee1, InterfaceFee memory interfaceFee2 ) = abi.decode(invocation.args, (IMarket, Fixed6, Fixed6, Fixed6, bool, InterfaceFee, InterfaceFee)); - _update(account, market, taker, maker, collateral, wrap, interfaceFee1, interfaceFee2); + _update(account, market, maker, taker, collateral, wrap, interfaceFee1, interfaceFee2); } else if (invocation.action == PerennialAction.UPDATE_INTENT) { (IMarket market, Intent memory intent, bytes memory signature) = abi.decode(invocation.args, (IMarket, Intent, bytes)); @@ -179,8 +179,8 @@ contract MultiInvoker is IMultiInvoker, Initializable { function _update( address account, IMarket market, - Fixed6 taker, Fixed6 maker, + Fixed6 taker, Fixed6 collateral, bool wrap, InterfaceFee memory interfaceFee1, @@ -193,8 +193,8 @@ contract MultiInvoker is IMultiInvoker, Initializable { market.update( account, - taker, maker, + taker, collateral, interfaceFee1.receiver == address(0) ? interfaceFee2.receiver : interfaceFee1.receiver ); diff --git a/packages/periphery/contracts/TriggerOrders/types/TriggerOrder.sol b/packages/periphery/contracts/TriggerOrders/types/TriggerOrder.sol index b42979f6c..40685ee2f 100644 --- a/packages/periphery/contracts/TriggerOrders/types/TriggerOrder.sol +++ b/packages/periphery/contracts/TriggerOrders/types/TriggerOrder.sol @@ -67,8 +67,8 @@ library TriggerOrderLib { Position memory position = market.positions(account); position.update(pending); - Fixed6 takerDelta; Fixed6 makerDelta; + Fixed6 takerDelta; // apply order to position if (self.side == 4) makerDelta = self.delta; @@ -78,8 +78,8 @@ library TriggerOrderLib { // apply position to market market.update( account, - takerDelta, makerDelta, + takerDelta, Fixed6Lib.ZERO, self.referrer ); diff --git a/packages/periphery/test/helpers/MultiInvoker/invoke.ts b/packages/periphery/test/helpers/MultiInvoker/invoke.ts index 5a8f58ec5..b80371f8a 100644 --- a/packages/periphery/test/helpers/MultiInvoker/invoke.ts +++ b/packages/periphery/test/helpers/MultiInvoker/invoke.ts @@ -37,8 +37,8 @@ export const buildUpdateMarket = ({ interfaceFee2, }: { market: string - makerDelta?: BigNumber longDelta?: BigNumber + makerDelta?: BigNumber shortDelta?: BigNumber collateral?: BigNumber handleWrap?: boolean @@ -52,8 +52,8 @@ export const buildUpdateMarket = ({ ['address', 'int256', 'int256', 'int256', 'bool', 'tuple(uint256,address)', 'tuple(uint256,address)'], [ market, - longDelta.sub(shortDelta), makerDelta, + longDelta.sub(shortDelta), collateral, handleWrap, [interfaceFee1 ? interfaceFee1.amount : 0, interfaceFee1 ? interfaceFee1.receiver : constants.AddressZero], diff --git a/packages/vault/contracts/Vault.sol b/packages/vault/contracts/Vault.sol index ba0ed89e1..516aeef63 100644 --- a/packages/vault/contracts/Vault.sol +++ b/packages/vault/contracts/Vault.sol @@ -438,8 +438,8 @@ contract Vault is IVault, Instance { ) private { registration.market.update( address(this), - Fixed6Lib.ZERO, shouldRebalance ? target.position : Fixed6Lib.ZERO, + Fixed6Lib.ZERO, target.collateral, address(0) ); From 3856ad82bf404390ae06fcc7775b71ef3f9c6187 Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 18 Dec 2024 14:15:03 +0530 Subject: [PATCH 20/29] fix oracle and vault tests --- packages/core/contracts/Market.sol | 2 +- .../oracle/test/integration/pyth/PythOracleFactory.test.ts | 2 +- packages/vault/test/integration/vault/Vault.test.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/contracts/Market.sol b/packages/core/contracts/Market.sol index b281d1050..67e757e84 100644 --- a/packages/core/contracts/Market.sol +++ b/packages/core/contracts/Market.sol @@ -229,7 +229,7 @@ contract Market is IMarket, Instance, ReentrancyGuard { Fixed6 takerAmount; UFixed6 closable = context.latestPositionLocal.magnitude().sub(context.pendingLocal.neg()); - + if (updateContext.currentPositionLocal.maker.gt(UFixed6Lib.ZERO)) { makerAmount = Fixed6Lib.from(-1, closable); } else if (updateContext.currentPositionLocal.long.gt(UFixed6Lib.ZERO)) { diff --git a/packages/oracle/test/integration/pyth/PythOracleFactory.test.ts b/packages/oracle/test/integration/pyth/PythOracleFactory.test.ts index 305c9a6f0..810ec339b 100644 --- a/packages/oracle/test/integration/pyth/PythOracleFactory.test.ts +++ b/packages/oracle/test/integration/pyth/PythOracleFactory.test.ts @@ -867,8 +867,8 @@ testOracles.forEach(testOracle => { .connect(user) ['update(address,int256,int256,int256,address)']( user.address, - 0, 1, + 0, parse6decimal('10'), constants.AddressZero, ) // make request to oracle (new price) diff --git a/packages/vault/test/integration/vault/Vault.test.ts b/packages/vault/test/integration/vault/Vault.test.ts index 162747261..9b8791f50 100644 --- a/packages/vault/test/integration/vault/Vault.test.ts +++ b/packages/vault/test/integration/vault/Vault.test.ts @@ -2070,18 +2070,18 @@ describe('Vault', () => { .connect(user2) ['update(address,int256,int256,int256,address)']( user2.address, + 0, parse6decimal('100').mul(-1), parse6decimal('100000'), - 0, constants.AddressZero, ) await btcMarket .connect(btcUser2) ['update(address,int256,int256,int256,address)']( btcUser2.address, + 0, parse6decimal('10').mul(-1), parse6decimal('100000'), - 0, constants.AddressZero, ) await updateOracle() From 09cb5cbc4595bbce80d9bec3acb30837e7a23fb0 Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 18 Dec 2024 15:26:39 +0530 Subject: [PATCH 21/29] fix trigger order close position --- .../TriggerOrders/types/TriggerOrder.sol | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/periphery/contracts/TriggerOrders/types/TriggerOrder.sol b/packages/periphery/contracts/TriggerOrders/types/TriggerOrder.sol index 40685ee2f..2bd07cf9c 100644 --- a/packages/periphery/contracts/TriggerOrders/types/TriggerOrder.sol +++ b/packages/periphery/contracts/TriggerOrders/types/TriggerOrder.sol @@ -56,11 +56,6 @@ library TriggerOrderLib { IMarket market, address account ) internal { - if (self.delta.eq(MAGIC_VALUE_CLOSE_POSITION)) { - market.close(account, false, address(0)); - return; - } - // settle and get the pending position of the account market.settle(account); Order memory pending = market.pendings(account); @@ -71,9 +66,9 @@ library TriggerOrderLib { Fixed6 takerDelta; // apply order to position - if (self.side == 4) makerDelta = self.delta; - if (self.side == 5) takerDelta = self.delta; - if (self.side == 6) takerDelta = self.delta.mul(Fixed6Lib.NEG_ONE); + if (self.side == 4) makerDelta = _computeDelta(position.maker, self.delta); + if (self.side == 5) takerDelta = _computeDelta(position.long, self.delta); + if (self.side == 6) takerDelta = _computeDelta(position.short, self.delta).mul(Fixed6Lib.NEG_ONE); // apply position to market market.update( @@ -107,11 +102,12 @@ library TriggerOrderLib { } } - /// @notice Helper function to improve readability of TriggerOrderLib.execute - function _add(UFixed6 lhs, Fixed6 rhs) private pure returns (UFixed6) { - return rhs.eq(MAGIC_VALUE_CLOSE_POSITION) ? - UFixed6Lib.ZERO : - UFixed6Lib.from(Fixed6Lib.from(lhs).add(rhs)); + /// @notice Returns the delta to apply to the position + /// @dev If the delta is MAGIC_VALUE_CLOSE_POSITION, it will close the position + function _computeDelta(UFixed6 currentPosition, Fixed6 delta) private pure returns (Fixed6) { + return delta.eq(MAGIC_VALUE_CLOSE_POSITION) ? + Fixed6Lib.from(-1, currentPosition) : + delta; } /// @notice Returns user's position for the side of the order they placed From 4774f863d18cf3f7cf4d5cd3a266a45025cbd982 Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 18 Dec 2024 19:52:32 +0530 Subject: [PATCH 22/29] fix core integration tests --- .../integration/core/closedProduct.test.ts | 2 +- .../test/integration/core/happyPath.test.ts | 181 ++++++++++-------- .../test/integration/core/liquidate.test.ts | 82 +------- 3 files changed, 113 insertions(+), 152 deletions(-) diff --git a/packages/core/test/integration/core/closedProduct.test.ts b/packages/core/test/integration/core/closedProduct.test.ts index 6ec085b9f..04876a5ba 100644 --- a/packages/core/test/integration/core/closedProduct.test.ts +++ b/packages/core/test/integration/core/closedProduct.test.ts @@ -27,7 +27,7 @@ describe('Closed Market', () => { await dsu.connect(user).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, 0, POSITION, COLLATERAL, constants.AddressZero) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) expect((await market.parameter()).closed).to.be.false diff --git a/packages/core/test/integration/core/happyPath.test.ts b/packages/core/test/integration/core/happyPath.test.ts index cffa79053..de916b7ed 100644 --- a/packages/core/test/integration/core/happyPath.test.ts +++ b/packages/core/test/integration/core/happyPath.test.ts @@ -23,9 +23,7 @@ import { expectGuaranteeEq, } from '../../../../common/testutil/types' import { Market__factory } from '../../../types/generated' -import { CHAINLINK_CUSTOM_CURRENCIES } from '@perennial/v2-oracle/util/constants' import { loadFixture } from '@nomicfoundation/hardhat-network-helpers' -import { ChainlinkContext } from '../helpers/chainlinkHelpers' import { IntentStruct, RiskParameterStruct } from '../../../types/generated/contracts/Market' import { signAccessUpdateBatch, signIntent, signOperatorUpdate, signSignerUpdate } from '../../helpers/erc712' @@ -158,7 +156,7 @@ describe('Happy Path', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -279,11 +277,17 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.div(2), 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(2), + 0, + COLLATERAL, + constants.AddressZero, + ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, 0, false), + ['update(address,int256,int256,int256,address)'](user.address, POSITION.div(2), 0, 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -398,12 +402,14 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await chainlink.next() await expect( - market.connect(user)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + market + .connect(user) + ['update(address,int256,int256,int256,address)'](user.address, POSITION.mul(-1), 0, 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -476,15 +482,29 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await chainlink.next() await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.div(2), 0, 0, 0, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + 0, + constants.AddressZero, + ) await expect( - market.connect(user)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + market + .connect(user) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -562,7 +582,7 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await expect( market .connect(userB) @@ -703,7 +723,7 @@ describe('Happy Path', () => { }) }) - it('opens multiple take positions', async () => { + it('opens multiple long positions', async () => { const POSITION = parse6decimal('10') const POSITION_B = parse6decimal('1') const COLLATERAL = parse6decimal('1000') @@ -723,15 +743,15 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION_B.div(2), 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userB.address, POSITION_B.div(2), COLLATERAL, constants.AddressZero) await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION_B, 0, 0, false), + ['update(address,int256,int256,address)'](userB.address, POSITION_B.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -853,19 +873,21 @@ describe('Happy Path', () => { await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION_B, 0, COLLATERAL, false), + ['update(address,int256,int256,address)'](userB.address, POSITION_B, COLLATERAL, constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketEfficiencyUnderLimitError') await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION_B, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userB.address, POSITION_B, COLLATERAL, constants.AddressZero) await chainlink.next() await expect( - market.connect(userB)['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, false), + market + .connect(userB) + ['update(address,int256,int256,address)'](userB.address, POSITION_B.mul(-1), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -945,23 +967,25 @@ describe('Happy Path', () => { await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION_B, 0, COLLATERAL, false), + ['update(address,int256,int256,address)'](userB.address, POSITION_B, COLLATERAL, constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketEfficiencyUnderLimitError') await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION_B, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userB.address, POSITION_B, COLLATERAL, constants.AddressZero) await chainlink.next() await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION_B.div(2), 0, 0, false) + ['update(address,int256,int256,address)'](userB.address, POSITION_B.div(2).mul(-1), 0, constants.AddressZero) await expect( - market.connect(userB)['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, false), + market + .connect(userB) + ['update(address,int256,int256,address)'](userB.address, POSITION_B.div(2).mul(-1), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -1033,14 +1057,14 @@ describe('Happy Path', () => { await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION_B, 0, COLLATERAL, false), + ['update(address,int256,int256,address)'](userB.address, POSITION_B, COLLATERAL, constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketEfficiencyUnderLimitError') await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION_B, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userB.address, POSITION_B, COLLATERAL, constants.AddressZero) await chainlink.next() @@ -1129,7 +1153,7 @@ describe('Happy Path', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, parse6decimal('1000'), false), + ['update(address,int256,int256,address)'](user.address, 0, parse6decimal('1000'), constants.AddressZero), ).to.be.revertedWithCustomError(market, 'InstancePausedError') await expect(settle(market, user)).to.be.revertedWithCustomError(market, 'InstancePausedError') @@ -1225,7 +1249,7 @@ describe('Happy Path', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, parse6decimal('1000'), false), + ['update(address,int256,int256,address)'](user.address, 0, parse6decimal('1000'), constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketSettleOnlyError') }) @@ -1249,11 +1273,11 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION_B, 0, COLLATERAL, false), + ['update(address,int256,int256,address)'](userB.address, POSITION_B, COLLATERAL, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -1298,11 +1322,11 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, POSITION_B, COLLATERAL, false), + ['update(address,int256,int256,address)'](userB.address, POSITION_B.mul(-1), COLLATERAL, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -1332,7 +1356,7 @@ describe('Happy Path', () => { const POSITION = parse6decimal('10') const COLLATERAL = parse6decimal('1000') - const { user, userB, dsu, chainlink, beneficiaryB } = instanceVars + const { user, userB, dsu, chainlink } = instanceVars const riskParameter = { margin: parse6decimal('0.3'), @@ -1390,20 +1414,26 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.div(3), 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(4), + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION.div(3), 0, COLLATERAL, false) // 0 -> 1 + ['update(address,int256,int256,address)'](userB.address, POSITION.div(4), COLLATERAL, constants.AddressZero) // 0 -> 1 await chainlink.next() await chainlink.next() await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.div(2), 0, 0, 0, false) // 2 -> 3 + ['update(address,int256,int256,int256,address)'](user.address, POSITION.div(4), 0, 0, constants.AddressZero) // 2 -> 3 await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION.div(2), 0, 0, false) + ['update(address,int256,int256,address)'](userB.address, POSITION.div(4), 0, constants.AddressZero) // Ensure a->b->c await chainlink.next() @@ -1412,7 +1442,7 @@ describe('Happy Path', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, -1, false), + ['update(address,int256,int256,int256,address)'](user.address, POSITION.div(2), 0, -1, constants.AddressZero), ) // 4 -> 5 .to.emit(market, 'OrderCreated') .withArgs( @@ -1429,7 +1459,7 @@ describe('Happy Path', () => { ...DEFAULT_LOCAL, currentId: 3, latestId: 2, - collateral: '871368068', + collateral: '873156333', }) expectOrderEq(await market.pendingOrders(user.address, 3), { ...DEFAULT_ORDER, @@ -1452,7 +1482,7 @@ describe('Happy Path', () => { ...DEFAULT_GLOBAL, currentId: 3, latestId: 2, - protocolFee: '172527179', + protocolFee: '173005296', latestPrice: PRICE_4, }) expectOrderEq(await market.pendingOrder(3), { @@ -1471,8 +1501,8 @@ describe('Happy Path', () => { expectVersionEq(await market.versions(TIMESTAMP_4), { ...DEFAULT_VERSION, price: PRICE_4, - makerValue: { _value: '-3538257' }, - longValue: { _value: '3620965' }, + makerValue: { _value: '-3451030' }, + longValue: { _value: '3620966' }, shortValue: { _value: 0 }, }) }) @@ -1489,10 +1519,10 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION_B, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userB.address, POSITION_B, COLLATERAL, constants.AddressZero) await chainlink.nextWithPriceModification(price => price.mul(10)) @@ -1592,19 +1622,19 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) await dsu.connect(userC).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) const intent: IntentStruct = { amount: POSITION.div(2), @@ -1752,19 +1782,19 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) await dsu.connect(userC).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) const intent: IntentStruct = { amount: POSITION.div(2), @@ -1843,19 +1873,19 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) await dsu.connect(userC).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) const intent: IntentStruct = { amount: POSITION.div(2), @@ -1948,7 +1978,7 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) const operatorUpdate = { access: { @@ -2087,7 +2117,7 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) // try to update extension using incorrect owner await expect(marketFactory.connect(userB).updateExtension(user.address, true)) @@ -2207,17 +2237,17 @@ describe('Happy Path', () => { await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) const intent: IntentStruct = { amount: POSITION.div(2), @@ -2320,17 +2350,17 @@ describe('Happy Path', () => { await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](userB.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) const intent: IntentStruct = { amount: POSITION.div(2), @@ -2409,7 +2439,7 @@ describe('Happy Path', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await expect( market .connect(userB) @@ -2552,7 +2582,7 @@ describe('Happy Path', () => { const POSITION = parse6decimal('10') const COLLATERAL = parse6decimal('1000') - const { user, userB, dsu, beneficiaryB, payoff, chainlink } = instanceVars + const { user, userB, dsu, chainlink } = instanceVars // set delay chainlink.delay = delay @@ -2618,23 +2648,20 @@ describe('Happy Path', () => { for (let i = 0; i < delay; i++) { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - POSITION.sub(delay - i), - 0, + i == 0 ? POSITION : 1, 0, i == 0 ? COLLATERAL : 0, - false, + constants.AddressZero, ) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userB.address, - 0, - POSITION.sub(delay - i), - 0, + i == 0 ? POSITION : 1, i == 0 ? COLLATERAL : 0, - false, + constants.AddressZero, ) await nextWithConstantPrice() @@ -2650,7 +2677,7 @@ describe('Happy Path', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, -1, false), + ['update(address,int256,int256,int256,address)'](user.address, 1, 0, -1, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -2689,7 +2716,7 @@ describe('Happy Path', () => { expectPositionEq(await market.positions(user.address), { ...DEFAULT_POSITION, timestamp: (await chainlink.oracle.latest()).timestamp, - maker: POSITION.sub(1), + maker: POSITION.add(delay - 1), }) // Check global state @@ -2712,8 +2739,8 @@ describe('Happy Path', () => { expectPositionEq(await market.position(), { ...DEFAULT_POSITION, timestamp: (await chainlink.oracle.latest()).timestamp, - maker: POSITION.sub(1), - long: POSITION.sub(1), + maker: POSITION.add(delay - 1), + long: POSITION.add(delay - 1), }) }) }) diff --git a/packages/core/test/integration/core/liquidate.test.ts b/packages/core/test/integration/core/liquidate.test.ts index dc63747f2..077b69f49 100644 --- a/packages/core/test/integration/core/liquidate.test.ts +++ b/packages/core/test/integration/core/liquidate.test.ts @@ -22,61 +22,6 @@ describe('Liquidate', () => { const COLLATERAL = parse6decimal('1000') const { user, userB, dsu, chainlink } = instanceVars - const market = await createMarket(instanceVars) - await dsu.connect(user).approve(market.address, COLLATERAL.mul(1e12)) - await market - .connect(user) - ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) - - // Settle the market with a new oracle version - await chainlink.nextWithPriceModification(price => price.mul(2)) - - await expect(market.connect(userB).close(user.address, true, constants.AddressZero)) // liquidate - .to.emit(market, 'OrderCreated') - .withArgs( - user.address, - { ...DEFAULT_ORDER, timestamp: TIMESTAMP_2, orders: 1, makerNeg: POSITION, protection: 1 }, - { ...DEFAULT_GUARANTEE }, - userB.address, - constants.AddressZero, - constants.AddressZero, - ) - - expect((await market.pendingOrders(user.address, 2)).protection).to.eq(1) - expect(await market.liquidators(user.address, 2)).to.eq(userB.address) - - expect((await market.locals(user.address)).collateral).to.equal(COLLATERAL) - expect(await dsu.balanceOf(market.address)).to.equal(utils.parseEther('1000')) - - chainlink.updateParams(parse6decimal('1.0'), parse6decimal('0.1')) - await chainlink.next() - await market.connect(user).settle(user.address) // settle - expect((await market.locals(userB.address)).claimable).to.equal(parse6decimal('10')) - await market.connect(userB).claimFee(userB.address) // liquidator withdrawal - - expect(await dsu.balanceOf(userB.address)).to.equal(utils.parseEther('200010')) // Original 200000 + fee - expect((await market.locals(user.address)).collateral).to.equal(parse6decimal('1000').sub(parse6decimal('11'))) - expect(await dsu.balanceOf(market.address)).to.equal(utils.parseEther('1000').sub(utils.parseEther('10'))) - - await market - .connect(user) - ['update(address,int256,int256,int256,address)']( - user.address, - 0, - 0, - COLLATERAL.sub(parse6decimal('11')).mul(-1), - constants.AddressZero, - ) // withdraw everything - - expect((await market.position()).timestamp).to.eq(TIMESTAMP_2) - expect((await market.pendingOrders(user.address, 2)).protection).to.eq(1) - }) - - it('liquidates a user with close', async () => { - const POSITION = parse6decimal('10') - const COLLATERAL = parse6decimal('1000') - const { user, userB, dsu, chainlink } = instanceVars - // reset chainlink params chainlink.updateParams(BigNumber.from(0), BigNumber.from(0)) @@ -84,7 +29,7 @@ describe('Liquidate', () => { await dsu.connect(user).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) // Settle the market with a new oracle version await chainlink.nextWithPriceModification(price => price.mul(2)) @@ -100,7 +45,9 @@ describe('Liquidate', () => { chainlink.updateParams(parse6decimal('1.0'), parse6decimal('0.1')) await chainlink.next() - await market.connect(user)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false) // settle + await market + .connect(user) + ['update(address,int256,int256,int256,address)'](user.address, 0, 0, 0, constants.AddressZero) // settle expect((await market.locals(userB.address)).claimable).to.equal(parse6decimal('10')) await market.connect(userB).claimFee(userB.address) // liquidator withdrawal @@ -110,13 +57,12 @@ describe('Liquidate', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, 0, 0, - 0, COLLATERAL.sub(parse6decimal('11')).mul(-1), - false, + constants.AddressZero, ) // withdraw everything expect((await market.position()).timestamp).to.eq(TIMESTAMP_2) @@ -133,22 +79,10 @@ describe('Liquidate', () => { await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,int256,int256,int256,address)']( - user.address, - POSITION, - 0, - parse6decimal('1000'), - constants.AddressZero, - ) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) await market .connect(userB) - ['update(address,int256,int256,int256,address)']( - userB.address, - 0, - POSITION, - parse6decimal('1000'), - constants.AddressZero, - ) + ['update(address,int256,int256,int256,address)'](userB.address, 0, POSITION, COLLATERAL, constants.AddressZero) // Settle the market with a new oracle version await chainlink.next() From 5713d0105ef979cef7a239d3489cdafcbea46153 Mon Sep 17 00:00:00 2001 From: Prateek Date: Fri, 20 Dec 2024 23:25:48 +0530 Subject: [PATCH 23/29] fix core unit tests --- packages/core/contracts/test/MockToken.sol | 2 +- packages/core/test/unit/market/Market.test.ts | 2740 +++++++++-------- 2 files changed, 1376 insertions(+), 1366 deletions(-) diff --git a/packages/core/contracts/test/MockToken.sol b/packages/core/contracts/test/MockToken.sol index fd50e8bd0..17a355574 100644 --- a/packages/core/contracts/test/MockToken.sol +++ b/packages/core/contracts/test/MockToken.sol @@ -18,7 +18,7 @@ contract MockToken is ERC20 { function transferFrom(address, address, uint256) public override returns (bool) { // call method of market contract for reentrancy if (functionToCall == Function.UPDATE) { - IMarket(msg.sender).update(address(0), Fixed6Lib.from(0), Fixed6Lib.from(0), address(0)); + IMarket(msg.sender).update(address(0), Fixed6Lib.from(0), Fixed6Lib.from(0), Fixed6Lib.from(0), address(0)); } else if (functionToCall == Function.UPDATE_INTENT) { Intent memory intent; IMarket(msg.sender).update(address(0), intent, ""); diff --git a/packages/core/test/unit/market/Market.test.ts b/packages/core/test/unit/market/Market.test.ts index 578277151..8d9d229b2 100644 --- a/packages/core/test/unit/market/Market.test.ts +++ b/packages/core/test/unit/market/Market.test.ts @@ -820,11 +820,11 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userB.address, POSITION, COLLATERAL, constants.AddressZero) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_3.timestamp]) @@ -890,37 +890,27 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, utils.parseEther('450')).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, parse6decimal('10'), 0, - 0, parse6decimal('450'), - false, + constants.AddressZero, ) // user establishes long position dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - parse6decimal('6'), - 0, - COLLATERAL, - false, - ) + ['update(address,int256,int256,address)'](user.address, parse6decimal('6'), COLLATERAL, constants.AddressZero) // userC establishes short position dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, - 0, - parse6decimal('12'), + parse6decimal('12').mul(-1), COLLATERAL, - false, + constants.AddressZero, ) // update oracle and settle positions @@ -953,11 +943,7 @@ describe('Market', () => { const EXPECTED_LIQUIDATION_FEE = parse6decimal('10') dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(userB.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, @@ -1089,37 +1075,27 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, utils.parseEther('450')).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, parse6decimal('10'), 0, - 0, parse6decimal('450'), - false, + constants.AddressZero, ) // user establishes long position dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - parse6decimal('6'), - 0, - COLLATERAL, - false, - ) + ['update(address,int256,int256,address)'](user.address, parse6decimal('6'), COLLATERAL, constants.AddressZero) // userC establishes short position dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, - 0, - parse6decimal('12'), + parse6decimal('12').mul(-1), COLLATERAL, - false, + constants.AddressZero, ) // update oracle and settle positions @@ -1152,11 +1128,7 @@ describe('Market', () => { const EXPECTED_LIQUIDATION_FEE = parse6decimal('10') dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(userB.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, @@ -1305,7 +1277,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ), ) .to.emit(market, 'PositionProcessed') .withArgs(0, { ...DEFAULT_ORDER, timestamp: ORACLE_VERSION_1.timestamp }, DEFAULT_VERSION_ACCUMULATION_RESULT) @@ -1419,7 +1397,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ), ) .to.emit(market, 'PositionProcessed') .withArgs(0, { ...DEFAULT_ORDER, timestamp: ORACLE_VERSION_1.timestamp }, DEFAULT_VERSION_ACCUMULATION_RESULT) @@ -1540,7 +1524,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ), ).to.revertedWithCustomError(market, 'InstancePausedError') factory.paused.returns(false) @@ -1566,7 +1556,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -1619,7 +1609,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL.mul(-1), false), + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL.mul(-1), constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -1672,7 +1662,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -1731,7 +1721,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL.mul(-1), false), + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL.mul(-1), constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -1784,7 +1774,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -1842,7 +1832,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL.mul(-1), false), + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL.mul(-1), constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -1900,13 +1890,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -1989,13 +1978,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'PositionProcessed') @@ -2107,12 +2095,18 @@ describe('Market', () => { it('opens a second position (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.mul(2), 0, 0, 0, false), + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -2165,12 +2159,18 @@ describe('Market', () => { it('opens a second position and settles (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.mul(2), 0, 0, 0, false), + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -2237,7 +2237,13 @@ describe('Market', () => { it('opens a second position (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_3.timestamp]) @@ -2246,7 +2252,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.mul(2), 0, 0, 0, false), + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -2305,7 +2311,13 @@ describe('Market', () => { it('opens a second position and settles (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_3.timestamp]) @@ -2314,7 +2326,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.mul(2), 0, 0, 0, false), + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -2382,13 +2394,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -2474,13 +2485,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -2566,7 +2576,13 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) }) context('settles first', async () => { @@ -2584,7 +2600,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.mul(-1), + 0, + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -2644,7 +2666,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.mul(-1), + 0, + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -2709,12 +2737,24 @@ describe('Market', () => { it('closes a second position (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.div(2), 0, 0, 0, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + 0, + constants.AddressZero, + ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -2773,12 +2813,24 @@ describe('Market', () => { it('closes a second position and settles (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.div(2), 0, 0, 0, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + 0, + constants.AddressZero, + ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -2843,7 +2895,13 @@ describe('Market', () => { it('closes a second position (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.div(2), 0, 0, 0, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + 0, + constants.AddressZero, + ) oracle.at .whenCalledWith(ORACLE_VERSION_3.timestamp) @@ -2854,7 +2912,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -2912,7 +2976,13 @@ describe('Market', () => { it('closes a second position and settles (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.div(2), 0, 0, 0, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + 0, + constants.AddressZero, + ) oracle.at .whenCalledWith(ORACLE_VERSION_3.timestamp) @@ -2923,7 +2993,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -2988,7 +3064,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.mul(-1), + 0, + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -3072,7 +3154,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.mul(-1), + 0, + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -3157,13 +3245,12 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) }) @@ -3171,14 +3258,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - POSITION, - 0, - COLLATERAL, - false, - ), + ['update(address,int256,int256,address)'](user.address, POSITION, COLLATERAL, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -3243,14 +3323,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - POSITION, - 0, - COLLATERAL, - false, - ), + ['update(address,int256,int256,address)'](user.address, POSITION, COLLATERAL, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -3327,19 +3400,17 @@ describe('Market', () => { it('opens a second position (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -3392,19 +3463,17 @@ describe('Market', () => { it('opens a second position and settles (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -3474,13 +3543,11 @@ describe('Market', () => { it('opens a second position (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -3492,7 +3559,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -3551,13 +3618,11 @@ describe('Market', () => { it('opens a second position and settles (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -3569,7 +3634,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -3669,13 +3734,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -3801,13 +3864,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -3952,13 +4013,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -4083,23 +4142,20 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) }) @@ -4118,7 +4174,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -4178,7 +4239,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -4277,12 +4343,22 @@ describe('Market', () => { it('closes a second position (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(4), 0, 0, false) + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -4342,12 +4418,22 @@ describe('Market', () => { it('closes a second position and settles (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(4), 0, 0, false) + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -4446,7 +4532,12 @@ describe('Market', () => { it('closes a second position (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(4), 0, 0, false) + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ) oracle.at .whenCalledWith(ORACLE_VERSION_3.timestamp) @@ -4457,7 +4548,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -4559,7 +4655,12 @@ describe('Market', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(4), 0, 0, false) + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ) oracle.at .whenCalledWith(ORACLE_VERSION_3.timestamp) @@ -4570,7 +4671,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -4694,7 +4800,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -4815,7 +4926,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -4937,16 +5053,20 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) @@ -5336,24 +5456,21 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, utils.parseEther('450')).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, parse6decimal('450'), - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) }) @@ -5386,11 +5503,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(userB.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, @@ -5574,13 +5687,12 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userC.address, POSITION.div(4), 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -5612,11 +5724,7 @@ describe('Market', () => { await settle(market, userC) dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(userB.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, @@ -5892,11 +6000,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(userB.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, @@ -6032,14 +6136,7 @@ describe('Market', () => { await expect( market .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)']( - userB.address, - 0, - 0, - 0, - shortfall.mul(-1), - false, - ), + ['update(address,int256,int256,address)'](userB.address, 0, shortfall.mul(-1), constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -6084,24 +6181,21 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(user.address, market.address, utils.parseEther('216')).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, parse6decimal('216'), - false, + constants.AddressZero, ) }) @@ -6134,11 +6228,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(user.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -6344,11 +6434,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(user.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -6480,14 +6566,7 @@ describe('Market', () => { await expect( market .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - 0, - 0, - shortfall.mul(-1), - false, - ), + ['update(address,int256,int256,address)'](user.address, 0, shortfall.mul(-1), constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -6532,17 +6611,21 @@ describe('Market', () => { beforeEach(async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userB.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) @@ -6663,13 +6746,12 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) }) @@ -6677,13 +6759,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION, + POSITION.mul(-1), COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -6750,13 +6830,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION, + POSITION.mul(-1), COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -6834,19 +6912,22 @@ describe('Market', () => { it('opens a second position (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -6901,19 +6982,22 @@ describe('Market', () => { it('opens a second position and settles (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -6984,13 +7068,11 @@ describe('Market', () => { it('opens a second position (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -7002,7 +7084,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -7062,13 +7149,11 @@ describe('Market', () => { it('opens a second position and settles (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -7080,7 +7165,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -7185,13 +7275,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -7321,13 +7409,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -7475,13 +7561,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -7604,23 +7688,20 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) }) @@ -7639,7 +7720,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -7700,7 +7781,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -7800,12 +7881,12 @@ describe('Market', () => { it('closes a second position (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION.div(4), 0, false) + ['update(address,int256,int256,address)'](user.address, POSITION.div(4), 0, constants.AddressZero) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(4), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -7865,12 +7946,12 @@ describe('Market', () => { it('closes a second position and settles (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION.div(4), 0, false) + ['update(address,int256,int256,address)'](user.address, POSITION.div(4), 0, constants.AddressZero) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(4), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -7970,7 +8051,7 @@ describe('Market', () => { it('closes a second position (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION.div(4), 0, false) + ['update(address,int256,int256,address)'](user.address, POSITION.div(4), 0, constants.AddressZero) oracle.at .whenCalledWith(ORACLE_VERSION_3.timestamp) @@ -7981,7 +8062,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(4), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -8083,7 +8164,7 @@ describe('Market', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION.div(4), 0, false) + ['update(address,int256,int256,address)'](user.address, POSITION.div(4), 0, constants.AddressZero) oracle.at .whenCalledWith(ORACLE_VERSION_3.timestamp) @@ -8094,7 +8175,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(4), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -8220,7 +8301,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -8343,7 +8424,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -8466,16 +8547,20 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) @@ -8871,24 +8956,21 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, utils.parseEther('390')).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, parse6decimal('390'), - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) }) @@ -8921,11 +9003,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(userB.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, @@ -9102,13 +9180,12 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userC.address, POSITION.div(4), 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -9155,11 +9232,7 @@ describe('Market', () => { await settle(market, userC) dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(userB.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, @@ -9402,11 +9475,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(userB.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, @@ -9534,14 +9603,7 @@ describe('Market', () => { await expect( market .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)']( - userB.address, - 0, - 0, - 0, - shortfall.mul(-1), - false, - ), + ['update(address,int256,int256,address)'](userB.address, 0, shortfall.mul(-1), constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -9586,24 +9648,21 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(user.address, market.address, utils.parseEther('216')).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), parse6decimal('216'), - false, + constants.AddressZero, ) }) @@ -9636,11 +9695,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(user.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -9852,11 +9907,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(user.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -9990,14 +10041,7 @@ describe('Market', () => { await expect( market .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - 0, - 0, - shortfall.mul(-1), - false, - ), + ['update(address,int256,int256,address)'](user.address, 0, shortfall.mul(-1), constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -10042,17 +10086,21 @@ describe('Market', () => { beforeEach(async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userB.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) @@ -10185,7 +10233,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.div(2), 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -10316,24 +10370,21 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, - 0, - POSITION, + POSITION.mul(-1), COLLATERAL, - false, + constants.AddressZero, ) }) @@ -10341,14 +10392,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - POSITION, - 0, - COLLATERAL, - false, - ), + ['update(address,int256,int256,address)'](user.address, POSITION, COLLATERAL, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -10415,14 +10459,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - POSITION, - 0, - COLLATERAL, - false, - ), + ['update(address,int256,int256,address)'](user.address, POSITION, COLLATERAL, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -10501,19 +10538,17 @@ describe('Market', () => { it('opens a second position (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -10569,19 +10604,17 @@ describe('Market', () => { it('opens a second position and settles (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -10654,13 +10687,11 @@ describe('Market', () => { it('opens a second position (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -10672,7 +10703,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -10733,13 +10764,11 @@ describe('Market', () => { it('opens a second position and settles (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -10751,7 +10780,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -10868,13 +10897,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -11032,13 +11059,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -11179,13 +11204,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -11317,13 +11340,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -11449,13 +11470,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -11587,13 +11606,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -11721,36 +11738,31 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, - 0, - POSITION, + POSITION.mul(-1), COLLATERAL, - false, + constants.AddressZero, ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) }) @@ -11769,7 +11781,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -11831,7 +11848,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -11945,12 +11967,22 @@ describe('Market', () => { it('closes a second position (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(4), 0, 0, false) + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -12011,12 +12043,22 @@ describe('Market', () => { it('closes a second position and settles (same version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(4), 0, 0, false) + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -12130,7 +12172,12 @@ describe('Market', () => { it('closes a second position (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(4), 0, 0, false) + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ) oracle.at .whenCalledWith(ORACLE_VERSION_3.timestamp) @@ -12141,7 +12188,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -12251,7 +12303,12 @@ describe('Market', () => { it('closes a second position and settles (next version)', async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(4), 0, 0, false) + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ) oracle.at .whenCalledWith(ORACLE_VERSION_3.timestamp) @@ -12262,7 +12319,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(4).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -12418,7 +12480,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -12526,7 +12593,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -12624,20 +12696,29 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, POSITION, COLLATERAL, false) + ['update(address,int256,int256,address)']( + userC.address, + POSITION.mul(-1), + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) @@ -13072,36 +13153,31 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, utils.parseEther('450')).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, parse6decimal('450'), - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, - 0, - POSITION, + POSITION.mul(-1), COLLATERAL, - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) }) @@ -13134,11 +13210,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(userB.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, @@ -13407,11 +13479,7 @@ describe('Market', () => { // userB gets liquidated, eliminating the maker position dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(userB.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, @@ -13512,13 +13580,12 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userD.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userD) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userD.address, POSITION.div(5), 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -13551,11 +13618,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(userB.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, @@ -13811,11 +13874,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(userB.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( userB.address, @@ -13960,14 +14019,7 @@ describe('Market', () => { await expect( market .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)']( - userB.address, - 0, - 0, - 0, - shortfall.mul(-1), - false, - ), + ['update(address,int256,int256,address)'](userB.address, 0, shortfall.mul(-1), constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -14012,35 +14064,30 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, - 0, - POSITION, + POSITION.mul(-1), COLLATERAL, - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(user.address, market.address, utils.parseEther('216')).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, parse6decimal('216'), - false, + constants.AddressZero, ) }) @@ -14073,11 +14120,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(user.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -14343,11 +14386,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(user.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -14506,14 +14545,7 @@ describe('Market', () => { await expect( market .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - 0, - 0, - shortfall.mul(-1), - false, - ), + ['update(address,int256,int256,address)'](user.address, 0, shortfall.mul(-1), constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -14558,22 +14590,31 @@ describe('Market', () => { beforeEach(async () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userB.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, POSITION, COLLATERAL, false) + ['update(address,int256,int256,address)']( + userC.address, + POSITION.mul(-1), + COLLATERAL, + constants.AddressZero, + ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_3.timestamp]) @@ -14690,13 +14731,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, parse6decimal('1000'), 0, - 0, parse6decimal('500'), - false, + constants.AddressZero, ), ).to.be.revertedWithCustomError(market, 'MarketInsufficientMarginError') }) @@ -14731,21 +14771,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, LOWER_COLLATERAL, - false, + constants.AddressZero, ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, LOWER_COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, LOWER_COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, LOWER_COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, LOWER_COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -14793,21 +14832,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, LOWER_COLLATERAL, - false, + constants.AddressZero, ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, LOWER_COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, LOWER_COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, LOWER_COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, LOWER_COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -14849,14 +14887,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -14898,14 +14942,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -14928,7 +14978,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ), ).to.be.revertedWithCustomError(market, 'InstancePausedError') factory.paused.returns(false) }) @@ -14978,7 +15034,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ), ).to.be.revertedWithCustomError(market, 'MarketMakerOverLimitError') }) @@ -14990,40 +15052,30 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, POSITION.div(2), 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( - userB.address, - 0, - POSITION.div(2), - 0, - COLLATERAL, - false, - ) + ['update(address,int256,int256,address)'](userB.address, POSITION.div(2), COLLATERAL, constants.AddressZero) dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION, 0, 0, false), + ['update(address,int256,int256,address)'](userB.address, POSITION, 0, constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketEfficiencyUnderLimitError') }) @@ -15039,13 +15091,12 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, POSITION.div(2), 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.status.returns([ORACLE_VERSION_1, ORACLE_VERSION_2.timestamp + 1]) @@ -15054,13 +15105,12 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION.add(1), 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.status.returns([ORACLE_VERSION_1, ORACLE_VERSION_2.timestamp + 2]) @@ -15069,13 +15119,12 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userC.address, POSITION.add(2), 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.status.returns([ORACLE_VERSION_1, ORACLE_VERSION_2.timestamp + 3]) @@ -15084,7 +15133,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.add(3), 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.add(3), + 0, + 0, + constants.AddressZero, + ), ).to.be.revertedWithCustomError(market, 'MarketExceedsPendingIdLimitError') }) @@ -15100,13 +15155,12 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, POSITION.div(2), 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.status.returns([ORACLE_VERSION_1, ORACLE_VERSION_2.timestamp + 1]) @@ -15114,14 +15168,14 @@ describe('Market', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.add(1), 0, 0, 0, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION.add(1), 0, 0, constants.AddressZero) oracle.status.returns([ORACLE_VERSION_1, ORACLE_VERSION_2.timestamp + 2]) oracle.request.whenCalledWith(user.address).returns() await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.add(2), 0, 0, 0, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION.add(2), 0, 0, constants.AddressZero) oracle.status.returns([ORACLE_VERSION_1, ORACLE_VERSION_2.timestamp + 3]) oracle.request.whenCalledWith(user.address).returns() @@ -15129,7 +15183,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.add(3), 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.add(3), + 0, + 0, + constants.AddressZero, + ), ).to.be.revertedWithCustomError(market, 'MarketExceedsPendingIdLimitError') }) @@ -15139,39 +15199,36 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, POSITION, POSITION, - 0, COLLATERAL, - false, + constants.AddressZero, ), ).to.be.revertedWithCustomError(market, 'MarketNotSingleSidedError') await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, POSITION, - 0, POSITION, COLLATERAL, - false, + constants.AddressZero, ), ).to.be.revertedWithCustomError(market, 'MarketNotSingleSidedError') await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, - 0, POSITION, POSITION, COLLATERAL, - false, + constants.AddressZero, ), ).to.be.revertedWithCustomError(market, 'MarketNotSingleSidedError') }) @@ -15180,18 +15237,16 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, 0, - 0, - 0, COLLATERAL.add(1).mul(-1), - false, + constants.AddressZero, ), ).to.be.revertedWithCustomError(market, 'MarketInsufficientCollateralError') }) @@ -15207,7 +15262,13 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) oracle.at.whenCalledWith(ORACLE_VERSION_1.timestamp).returns([ORACLE_VERSION_1, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_1, ORACLE_VERSION_3.timestamp]) @@ -15217,14 +15278,20 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, -1, false), + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, -1, constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketStalePriceError') // revert if changing position await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.add(1), 0, 0, -1, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.add(1), + 0, + -1, + constants.AddressZero, + ), ).to.be.revertedWithCustomError(market, 'MarketStalePriceError') }) @@ -15242,14 +15309,20 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, -1, false), + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, -1, constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketStalePriceError') // revert if changing position await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.add(1), 0, 0, -1, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.add(1), + 0, + -1, + constants.AddressZero, + ), ).to.be.revertedWithCustomError(market, 'MarketStalePriceError') }) @@ -15264,7 +15337,13 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) oracle.at.whenCalledWith(ORACLE_VERSION_1.timestamp).returns([ORACLE_VERSION_1, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_1, ORACLE_VERSION_2.timestamp]) @@ -15274,14 +15353,20 @@ describe('Market', () => { await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, -1, false), + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, -1, constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketOperatorNotAllowedError') // revert if changing position await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION.add(1), 0, 0, -1, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION.add(1), + 0, + -1, + constants.AddressZero, + ), ).to.be.revertedWithCustomError(market, 'MarketOperatorNotAllowedError') }) @@ -15290,13 +15375,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, 1, 0, - 0, parse6decimal('99'), - false, + constants.AddressZero, ), ).to.be.revertedWithCustomError(market, 'MarketInsufficientMarginError') }) @@ -15308,7 +15392,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ), ).to.be.revertedWithCustomError(market, 'MarketClosedError') }) @@ -15316,18 +15406,22 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userB.address, - 0, POSITION.add(1), - 0, COLLATERAL, - false, + constants.AddressZero, ), ).to.be.revertedWithCustomError(market, `MarketInsufficientLiquidityError`) }) @@ -15341,17 +15435,16 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - POSITION.div(2), + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, 0, COLLATERAL, - false, + constants.AddressZero, ) + await market + .connect(user) + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), COLLATERAL, constants.AddressZero) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_3.timestamp]) @@ -15362,7 +15455,7 @@ describe('Market', () => { // open to POSITION (POSITION / 2 settled) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, 0, false) + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_4.timestamp]) @@ -15372,13 +15465,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, + POSITION.div(2).add(1).mul(-1), 0, - POSITION.div(2).sub(1), - 0, - 0, - false, + constants.AddressZero, ), ).to.revertedWithCustomError(market, 'MarketOverCloseError') @@ -15386,7 +15477,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(2), 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -15404,16 +15500,7 @@ describe('Market', () => { // can't close any more await expect( - market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - POSITION.div(2).sub(1), - 0, - 0, - false, - ), + market.connect(user)['update(address,int256,int256,address)'](user.address, -1, 0, constants.AddressZero), ).to.revertedWithCustomError(market, 'MarketOverCloseError') oracle.at.whenCalledWith(ORACLE_VERSION_3.timestamp).returns([ORACLE_VERSION_3, INITIALIZED_ORACLE_RECEIPT]) @@ -15424,7 +15511,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)']( + user.address, + POSITION.div(2).mul(-1), + 0, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -15456,25 +15548,22 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, utils.parseEther('450')).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, parse6decimal('450'), - false, + constants.AddressZero, ) dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) @@ -15498,45 +15587,32 @@ describe('Market', () => { await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION.mul(-1), + 0, + 0, + constants.AddressZero, + ), ).to.be.revertedWithCustomError(market, 'MarketInsufficientMarginError') }) it('it reverts if already liquidated', async () => { - await market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, true) + await market.connect(liquidator).close(userB.address, true, constants.AddressZero) await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ), ).to.be.revertedWithCustomError(market, 'MarketProtectedError') }) - it('it reverts if withdrawing collateral', async () => { - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, -1, true), - ).to.be.revertedWithCustomError(market, 'MarketInvalidProtectionError') - }) - - it('it reverts if position doesnt close', async () => { - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 1, 0, 0, 0, true), - ).to.be.revertedWithCustomError(market, 'MarketInvalidProtectionError') - }) - it('reverts if position increases in magnitude', async () => { const positionMaker = parse6decimal('20.000') const positionLong = parse6decimal('10.000') @@ -15555,27 +15631,20 @@ describe('Market', () => { oracle.request.returns() dsu.transferFrom.whenCalledWith(userB.address, market.address, collateral.mul(1e12)).returns(true) - await market - .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( - userB.address, - positionMaker, - 0, - 0, - collateral, - false, - ) + await market.connect(userB)['update(address,int256,int256,int256,address)']( + userB.address, + positionLong.sub(POSITION), // increase position to 20 + 0, + collateral, + constants.AddressZero, + ) dsu.transferFrom.whenCalledWith(user.address, market.address, collateral2.mul(1e12)).returns(true) - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - positionLong, - 0, - collateral2, - false, - ) + await market.connect(user)['update(address,int256,int256,address)']( + user.address, + positionLong.sub(POSITION.div(2)), // increase position to 10 + collateral2, + constants.AddressZero, + ) const oracleVersion2 = { price: parse6decimal('100'), @@ -15586,9 +15655,7 @@ describe('Market', () => { oracle.status.returns([oracleVersion2, TIMESTAMP + 7400]) oracle.request.returns() - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false) + await market.connect(user).close(user.address, false, constants.AddressZero) oracle.status.returns([oracleVersion2, TIMESTAMP + 7500]) oracle.request.returns() @@ -15596,36 +15663,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(user.address, collateralWithdraw2.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - 0, - 0, - -collateralWithdraw2, - false, - ) - - const oracleVersion3 = { - price: parse6decimal('99.9999'), - timestamp: TIMESTAMP + 7380, - valid: true, - } - oracle.at.whenCalledWith(oracleVersion3.timestamp).returns([oracleVersion3, INITIALIZED_ORACLE_RECEIPT]) - oracle.status.returns([oracleVersion3, TIMESTAMP + 7500]) - oracle.request.returns() - - await expect( - market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - collateralLiquidate, - 0, - 0, - true, - ), - ).to.be.revertedWithCustomError(market, 'MarketInvalidProtectionError') + ['update(address,int256,int256,address)'](user.address, 0, -collateralWithdraw2, constants.AddressZero) }) }) @@ -15640,26 +15678,23 @@ describe('Market', () => { beforeEach(async () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, POSITION, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, - 0, - POSITION.mul(2), + POSITION.mul(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -15674,7 +15709,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.mul(-1), 0, constants.AddressZero), ).to.not.be.reverted }) @@ -15686,14 +15721,7 @@ describe('Market', () => { await expect( market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( - userC.address, - 0, - 0, - POSITION.mul(2).add(1), - 0, - false, - ), + ['update(address,int256,int256,address)'](userC.address, -1, 0, constants.AddressZero), ).to.revertedWithCustomError(market, 'MarketEfficiencyUnderLimitError') }) @@ -15705,14 +15733,7 @@ describe('Market', () => { await expect( market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( - userC.address, - 0, - 0, - POSITION.mul(2).add(1), - 0, - false, - ), + ['update(address,int256,int256,address)'](userC.address, -1, 0, constants.AddressZero), ).to.revertedWithCustomError(market, 'MarketInsufficientLiquidityError') }) }) @@ -15721,26 +15742,30 @@ describe('Market', () => { beforeEach(async () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) + // open short position await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, COLLATERAL, false) + ['update(address,int256,int256,address)']( + user.address, + POSITION.mul(-1), + COLLATERAL, + constants.AddressZero, + ) + // open long position await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, POSITION.mul(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -15755,7 +15780,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION, 0, constants.AddressZero), ).to.not.be.reverted }) @@ -15767,14 +15792,7 @@ describe('Market', () => { await expect( market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( - userC.address, - 0, - POSITION.mul(2).add(1), - 0, - 0, - false, - ), + ['update(address,int256,int256,address)'](userC.address, 1, 0, constants.AddressZero), ).to.revertedWithCustomError(market, 'MarketEfficiencyUnderLimitError') }) @@ -15786,14 +15804,7 @@ describe('Market', () => { await expect( market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( - userC.address, - 0, - POSITION.mul(2).add(1), - 0, - 0, - false, - ), + ['update(address,int256,int256,address)'](userC.address, 1, 0, constants.AddressZero), ).to.revertedWithCustomError(market, 'MarketInsufficientLiquidityError') }) }) @@ -15802,26 +15813,30 @@ describe('Market', () => { beforeEach(async () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION, 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) + // open short position await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, COLLATERAL, false) + ['update(address,int256,int256,address)']( + user.address, + POSITION.mul(-1), + COLLATERAL, + constants.AddressZero, + ) + // open long position await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, POSITION.mul(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -15836,7 +15851,13 @@ describe('Market', () => { await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, 0, 0, 0, false), + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION.mul(-1), + 0, + 0, + constants.AddressZero, + ), ).to.revertedWithCustomError(market, 'MarketEfficiencyUnderLimitError') }) }) @@ -15853,13 +15874,12 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, parse6decimal('10'), 0, - 0, parse6decimal('1000'), - false, + constants.AddressZero, ), ).to.be.revertedWithCustomError(market, 'MarketSettleOnlyError') }) @@ -15870,17 +15890,21 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) dsu.transferFrom.whenCalledWith(user.address, market.address, utils.parseEther('216')).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, parse6decimal('216'), - false, + constants.AddressZero, ) }) @@ -15911,11 +15935,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(user.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -15929,235 +15949,91 @@ describe('Market', () => { { ...DEFAULT_GUARANTEE }, liquidator.address, constants.AddressZero, - constants.AddressZero, - ) - - expectLocalEq(await market.locals(user.address), { - ...DEFAULT_LOCAL, - currentId: 2, - latestId: 1, - collateral: parse6decimal('216') - .sub(EXPECTED_FUNDING_WITH_FEE_1_5_123.add(EXPECTED_INTEREST_5_123)) - .sub(EXPECTED_PNL), - }) - expect(await market.liquidators(user.address, 2)).to.equal(liquidator.address) - expectPositionEq(await market.positions(user.address), { - ...DEFAULT_POSITION, - timestamp: ORACLE_VERSION_3.timestamp, - long: POSITION.div(2), - }) - expectOrderEq(await market.pendingOrders(user.address, 2), { - ...DEFAULT_ORDER, - timestamp: ORACLE_VERSION_4.timestamp, - orders: 1, - longNeg: POSITION.div(2), - protection: 1, - }) - expectCheckpointEq(await market.checkpoints(user.address, ORACLE_VERSION_4.timestamp), { - ...DEFAULT_CHECKPOINT, - }) - expectLocalEq(await market.locals(userB.address), { - ...DEFAULT_LOCAL, - currentId: 1, - latestId: 1, - collateral: COLLATERAL.add(EXPECTED_FUNDING_WITHOUT_FEE_1_5_123.add(EXPECTED_INTEREST_WITHOUT_FEE_5_123)) - .add(EXPECTED_PNL) - .sub(8), // loss of precision - }) - expectPositionEq(await market.positions(userB.address), { - ...DEFAULT_POSITION, - timestamp: ORACLE_VERSION_3.timestamp, - maker: POSITION, - }) - expectOrderEq(await market.pendingOrders(userB.address, 1), { - ...DEFAULT_ORDER, - timestamp: ORACLE_VERSION_2.timestamp, - orders: 1, - makerPos: POSITION, - collateral: COLLATERAL, - }) - expectCheckpointEq(await market.checkpoints(userB.address, ORACLE_VERSION_4.timestamp), { - ...DEFAULT_CHECKPOINT, - }) - const totalFee = EXPECTED_FUNDING_FEE_1_5_123.add(EXPECTED_INTEREST_FEE_5_123) - expectGlobalEq(await market.global(), { - ...DEFAULT_GLOBAL, - currentId: 2, - latestId: 1, - protocolFee: totalFee.mul(8).div(10).sub(2), // loss of precision - oracleFee: totalFee.div(10).sub(1), // loss of precision - riskFee: totalFee.div(10).sub(1), // loss of precision - latestPrice: parse6decimal('43'), - }) - expectPositionEq(await market.position(), { - ...DEFAULT_POSITION, - timestamp: ORACLE_VERSION_3.timestamp, - maker: POSITION, - long: POSITION.div(2), - }) - expectOrderEq(await market.pendingOrder(2), { - ...DEFAULT_ORDER, - timestamp: ORACLE_VERSION_4.timestamp, - orders: 1, - longNeg: POSITION.div(2), - }) - expectVersionEq(await market.versions(ORACLE_VERSION_3.timestamp), { - ...DEFAULT_VERSION, - makerValue: { - _value: EXPECTED_FUNDING_WITHOUT_FEE_1_5_123.add(EXPECTED_INTEREST_WITHOUT_FEE_5_123) - .add(EXPECTED_PNL) - .div(10), - }, - longValue: { - _value: EXPECTED_FUNDING_WITH_FEE_1_5_123.add(EXPECTED_INTEREST_5_123).add(EXPECTED_PNL).div(5).mul(-1), - }, - shortValue: { _value: 0 }, - price: oracleVersionLowerPrice.price, - }) - }) - }) - - context('liquidation w/ partial closed', async () => { - beforeEach(async () => { - const riskParameter = { ...(await market.riskParameter()) } - riskParameter.staleAfter = BigNumber.from(14400) - await market.updateRiskParameter(riskParameter) - - dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) - await market - .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) - dsu.transferFrom.whenCalledWith(user.address, market.address, utils.parseEther('324')).returns(true) - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - 0, - POSITION.div(2), - parse6decimal('324'), - false, - ) - - oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) - oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_4.timestamp]) - oracle.request.whenCalledWith(user.address).returns() - - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - 0, - POSITION.mul(3).div(4), - 0, - false, - ) - await settle(market, userB) - }) - - it('default', async () => { - const EXPECTED_SETTLEMENT_FEE = parse6decimal('1') - const EXPECTED_LIQUIDATION_FEE = parse6decimal('10') - - const oracleVersionLowerPrice = { - price: parse6decimal('150'), - timestamp: TIMESTAMP + 7200, - valid: true, - } - oracle.at - .whenCalledWith(oracleVersionLowerPrice.timestamp) - .returns([oracleVersionLowerPrice, INITIALIZED_ORACLE_RECEIPT]) - oracle.status.returns([oracleVersionLowerPrice, ORACLE_VERSION_5.timestamp]) - oracle.request.whenCalledWith(user.address).returns() - - await settle(market, userB) - dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) - dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - 0, - POSITION.div(4).sub(1), - 0, - true, - ), - ).to.revertedWithCustomError(market, 'MarketOverCloseError') - - dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.add(1).mul(1e12)).returns(true) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION.div(4), -1, true), - ).to.revertedWithCustomError(market, 'MarketInvalidProtectionError') - - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION.div(4), 0, true), - ) - .to.emit(market, 'OrderCreated') - .withArgs( - user.address, - { - ...DEFAULT_ORDER, - timestamp: ORACLE_VERSION_5.timestamp, - orders: 1, - shortNeg: POSITION.div(2), - protection: 1, - }, - { ...DEFAULT_GUARANTEE }, - liquidator.address, - constants.AddressZero, - constants.AddressZero, - ) - - oracle.at.whenCalledWith(ORACLE_VERSION_4.timestamp).returns([ORACLE_VERSION_4, INITIALIZED_ORACLE_RECEIPT]) - oracle.at - .whenCalledWith(ORACLE_VERSION_5.timestamp) - .returns([ORACLE_VERSION_5, { ...INITIALIZED_ORACLE_RECEIPT, settlementFee: EXPECTED_SETTLEMENT_FEE }]) - oracle.status.returns([ORACLE_VERSION_5, ORACLE_VERSION_6.timestamp]) - oracle.request.whenCalledWith(user.address).returns() - - await settle(market, user) - await settle(market, userB) - - const oracleVersionLowerPrice2 = { - price: parse6decimal('150'), - timestamp: TIMESTAMP + 14400, - valid: true, - } - oracle.at - .whenCalledWith(oracleVersionLowerPrice2.timestamp) - .returns([oracleVersionLowerPrice2, INITIALIZED_ORACLE_RECEIPT]) - oracle.status.returns([oracleVersionLowerPrice2, oracleVersionLowerPrice2.timestamp + 3600]) - oracle.request.whenCalledWith(user.address).returns() - - await settle(market, user) - await settle(market, userB) + constants.AddressZero, + ) - expectLocalEq(await market.locals(liquidator.address), { + expectLocalEq(await market.locals(user.address), { ...DEFAULT_LOCAL, - currentId: 0, - latestId: 0, - claimable: EXPECTED_LIQUIDATION_FEE, + currentId: 2, + latestId: 1, + collateral: parse6decimal('216') + .sub(EXPECTED_FUNDING_WITH_FEE_1_5_123.add(EXPECTED_INTEREST_5_123)) + .sub(EXPECTED_PNL), }) + expect(await market.liquidators(user.address, 2)).to.equal(liquidator.address) expectPositionEq(await market.positions(user.address), { ...DEFAULT_POSITION, - timestamp: ORACLE_VERSION_5.timestamp, - short: POSITION.div(4), + timestamp: ORACLE_VERSION_3.timestamp, + long: POSITION.div(2), + }) + expectOrderEq(await market.pendingOrders(user.address, 2), { + ...DEFAULT_ORDER, + timestamp: ORACLE_VERSION_4.timestamp, + orders: 1, + longNeg: POSITION.div(2), + protection: 1, + }) + expectCheckpointEq(await market.checkpoints(user.address, ORACLE_VERSION_4.timestamp), { + ...DEFAULT_CHECKPOINT, + }) + expectLocalEq(await market.locals(userB.address), { + ...DEFAULT_LOCAL, + currentId: 1, + latestId: 1, + collateral: COLLATERAL.add(EXPECTED_FUNDING_WITHOUT_FEE_1_5_123.add(EXPECTED_INTEREST_WITHOUT_FEE_5_123)) + .add(EXPECTED_PNL) + .sub(8), // loss of precision + }) + expectPositionEq(await market.positions(userB.address), { + ...DEFAULT_POSITION, + timestamp: ORACLE_VERSION_3.timestamp, + maker: POSITION, + }) + expectOrderEq(await market.pendingOrders(userB.address, 1), { + ...DEFAULT_ORDER, + timestamp: ORACLE_VERSION_2.timestamp, + orders: 1, + makerPos: POSITION, + collateral: COLLATERAL, + }) + expectCheckpointEq(await market.checkpoints(userB.address, ORACLE_VERSION_4.timestamp), { + ...DEFAULT_CHECKPOINT, + }) + const totalFee = EXPECTED_FUNDING_FEE_1_5_123.add(EXPECTED_INTEREST_FEE_5_123) + expectGlobalEq(await market.global(), { + ...DEFAULT_GLOBAL, + currentId: 2, + latestId: 1, + protocolFee: totalFee.mul(8).div(10).sub(2), // loss of precision + oracleFee: totalFee.div(10).sub(1), // loss of precision + riskFee: totalFee.div(10).sub(1), // loss of precision + latestPrice: parse6decimal('43'), + }) + expectPositionEq(await market.position(), { + ...DEFAULT_POSITION, + timestamp: ORACLE_VERSION_3.timestamp, + maker: POSITION, + long: POSITION.div(2), + }) + expectOrderEq(await market.pendingOrder(2), { + ...DEFAULT_ORDER, + timestamp: ORACLE_VERSION_4.timestamp, + orders: 1, + longNeg: POSITION.div(2), + }) + expectVersionEq(await market.versions(ORACLE_VERSION_3.timestamp), { + ...DEFAULT_VERSION, + makerValue: { + _value: EXPECTED_FUNDING_WITHOUT_FEE_1_5_123.add(EXPECTED_INTEREST_WITHOUT_FEE_5_123) + .add(EXPECTED_PNL) + .div(10), + }, + longValue: { + _value: EXPECTED_FUNDING_WITH_FEE_1_5_123.add(EXPECTED_INTEREST_5_123).add(EXPECTED_PNL).div(5).mul(-1), + }, + shortValue: { _value: 0 }, + price: oracleVersionLowerPrice.price, }) - - dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) - await expect(market.connect(liquidator).claimFee(liquidator.address)) - .to.emit(market, 'FeeClaimed') - .withArgs(liquidator.address, liquidator.address, EXPECTED_LIQUIDATION_FEE) - - expectLocalEq(await market.locals(liquidator.address), DEFAULT_LOCAL) }) }) @@ -16166,17 +16042,22 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) dsu.transferFrom.whenCalledWith(user.address, market.address, utils.parseEther('216')).returns(true) + // open short position await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), parse6decimal('216'), - false, + constants.AddressZero, ) }) @@ -16206,11 +16087,7 @@ describe('Market', () => { await settle(market, userB) dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(user.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -16245,11 +16122,7 @@ describe('Market', () => { ]) oracle.request.whenCalledWith(user.address).returns() - await expect( - market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true), - ) + await expect(market.connect(liquidator).close(user.address, true, constants.AddressZero)) .to.emit(market, 'OrderCreated') .withArgs( user.address, @@ -16454,17 +16327,22 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) dsu.transferFrom.whenCalledWith(user.address, market.address, utils.parseEther('216')).returns(true) + // open long position await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, parse6decimal('216'), - false, + constants.AddressZero, ) }) @@ -16495,9 +16373,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true) + await market.connect(user).close(user.address, true, constants.AddressZero) oracle.at .whenCalledWith(ORACLE_VERSION_4.timestamp) @@ -16651,17 +16527,21 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) dsu.transferFrom.whenCalledWith(user.address, market.address, utils.parseEther('216')).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, parse6decimal('216'), - false, + constants.AddressZero, ) }) @@ -16710,17 +16590,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( - user.address, - 0, - 0, - 0, - 0, - true, - userB.address, - ) + await market.connect(liquidator).close(user.address, true, userB.address) expect((await market.locals(user.address)).currentId).to.equal(2) expect(await market.liquidators(user.address, 2)).to.equal(liquidator.address) @@ -16770,17 +16640,7 @@ describe('Market', () => { dsu.transfer.whenCalledWith(liquidator.address, EXPECTED_LIQUIDATION_FEE.mul(1e12)).returns(true) dsu.balanceOf.whenCalledWith(market.address).returns(COLLATERAL.mul(1e12)) - await market - .connect(liquidator) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( - user.address, - 0, - 0, - 0, - 0, - true, - userB.address, - ) + await market.connect(liquidator).close(user.address, true, userB.address) oracle.at.whenCalledWith(ORACLE_VERSION_4.timestamp).returns([ORACLE_VERSION_4, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_4, ORACLE_VERSION_5.timestamp]) @@ -16792,13 +16652,11 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, utils.parseEther('1000')).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(5), - 0, parse6decimal('1000'), - false, + constants.AddressZero, ) await settle(market, user) @@ -16824,7 +16682,13 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) }) it('settles the position w/o change', async () => { @@ -16848,13 +16712,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -16991,13 +16853,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -17032,7 +16892,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(2), 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -17185,13 +17045,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -17226,7 +17084,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(2), 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -17380,13 +17238,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -17409,9 +17265,7 @@ describe('Market', () => { oracle.request.whenCalledWith(user.address).returns() await expect( - market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(2), 0, 0, false), + market.connect(user)['update(address,int256,int256,address)'](user.address, 0, 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -17562,13 +17416,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -17591,9 +17443,7 @@ describe('Market', () => { oracle.request.whenCalledWith(user.address).returns() await expect( - market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(2), 0, 0, false), + market.connect(user)['update(address,int256,int256,address)'](user.address, 0, 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -17618,7 +17468,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION.div(2), 0, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -17779,13 +17629,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ), ) .to.emit(market, 'OrderCreated') @@ -17902,17 +17750,17 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - POSITION.div(2), + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, 0, COLLATERAL, - false, + constants.AddressZero, ) + // open long position + await market + .connect(user) + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), COLLATERAL, constants.AddressZero) }) it('doesnt flip funding default', async () => { @@ -17921,18 +17769,18 @@ describe('Market', () => { oracle.request.whenCalledWith(user.address).returns() dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) + // close long position await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false) + ['update(address,int256,int256,address)'](user.address, POSITION.div(2).mul(-1), 0, constants.AddressZero) + // open short position await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) oracle.at.whenCalledWith(ORACLE_VERSION_3.timestamp).returns([ORACLE_VERSION_3, INITIALIZED_ORACLE_RECEIPT]) @@ -18065,18 +17913,18 @@ describe('Market', () => { oracle.request.whenCalledWith(user.address).returns() dsu.transferFrom.whenCalledWith(userC.address, market.address, COLLATERAL.mul(1e12)).returns(true) + // close long position await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false) + ['update(address,int256,int256,address)'](user.address, POSITION.div(2).mul(-1), 0, constants.AddressZero) + // open short position await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) oracle.at.whenCalledWith(ORACLE_VERSION_3.timestamp).returns([ORACLE_VERSION_3, INITIALIZED_ORACLE_RECEIPT]) @@ -18213,7 +18061,13 @@ describe('Market', () => { await expect( market .connect(operator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -18282,7 +18136,13 @@ describe('Market', () => { await expect( market .connect(operator) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ), ).to.be.revertedWithCustomError(market, 'MarketOperatorNotAllowedError') }) }) @@ -18347,14 +18207,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -18576,14 +18442,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -18631,16 +18503,20 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) @@ -18750,16 +18626,14 @@ describe('Market', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, 0, false) + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), 0, constants.AddressZero) oracle.at.whenCalledWith(ORACLE_VERSION_3.timestamp).returns([ORACLE_VERSION_3, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_3, ORACLE_VERSION_4.timestamp]) oracle.request.whenCalledWith(user.address).returns() await expect( - market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, 0, false), + market.connect(user)['update(address,int256,int256,address)'](user.address, 0, 0, constants.AddressZero), ).to.not.reverted }) }) @@ -18769,16 +18643,21 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) + // open short await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) @@ -18886,18 +18765,17 @@ describe('Market', () => { riskParameter.takerFee = riskParameterTakerFee await market.updateRiskParameter(riskParameter) + // increase short position await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, 0, false) + ['update(address,int256,int256,address)'](user.address, POSITION.div(2).mul(-1), 0, constants.AddressZero) oracle.at.whenCalledWith(ORACLE_VERSION_3.timestamp).returns([ORACLE_VERSION_3, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_3, ORACLE_VERSION_4.timestamp]) oracle.request.whenCalledWith(user.address).returns() await expect( - market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, 0, false), + market.connect(user)['update(address,int256,int256,address)'](user.address, 0, 0, constants.AddressZero), ).to.not.reverted }) }) @@ -18920,13 +18798,12 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, collateral.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, positionMaker, 0, - 0, collateral, - false, + constants.AddressZero, ) // Increase current version so multiple pending positions are unsettled @@ -18934,14 +18811,7 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, collateral.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( - userB.address, - positionMaker, - 0, - 0, - collateral, - false, - ) + ['update(address,int256,int256,int256,address)'](userB.address, 0, 0, collateral, constants.AddressZero) // Fulfill oracle version 2 (invalid) const oracleVersion2 = { @@ -18973,9 +18843,7 @@ describe('Market', () => { // settle await expect( - market - .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, positionMaker, 0, 0, 0, false), + market.connect(userB)['update(address,int256,int256,address)'](userB.address, 0, 0, constants.AddressZero), ).to.not.be.reverted }) @@ -18996,13 +18864,12 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, collateral.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, positionMaker, 0, - 0, collateral, - false, + constants.AddressZero, ) const oracleVersion2 = { @@ -19017,7 +18884,13 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, collateral.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, positionLong, 0, collateral, false) + ['update(address,int256,int256,int256,address)']( + user.address, + positionLong, + 0, + collateral, + constants.AddressZero, + ) const collateralBefore = (await market.locals(user.address)).collateral const collateralBeforeB = (await market.locals(userB.address)).collateral @@ -19045,7 +18918,7 @@ describe('Market', () => { // reset to 0 await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, positionLong, 0, 0, false) + ['update(address,int256,int256,int256,address)'](user.address, 0, 0, 0, constants.AddressZero) // oracleVersion4 commited oracle.status.returns([oracleVersion4, oracleVersion4.timestamp + 100]) @@ -19054,7 +18927,7 @@ describe('Market', () => { // settle await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, positionMaker, 0, 0, 0, false) + ['update(address,int256,int256,int256,address)'](userB.address, 0, 0, 0, constants.AddressZero) const oracleVersion5 = { price: parse6decimal('90'), @@ -19068,10 +18941,11 @@ describe('Market', () => { // settle await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, positionMaker, 0, 0, 0, false) + ['update(address,int256,int256,int256,address)'](userB.address, positionMaker, 0, 0, constants.AddressZero) + // close long position await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false) + ['update(address,int256,int256,address)'](user.address, positionLong.mul(-1), 0, constants.AddressZero) expect((await market.locals(user.address)).collateral).to.equal(collateralBefore) expect((await market.locals(userB.address)).collateral).to.equal(collateralBeforeB) @@ -19088,81 +18962,104 @@ describe('Market', () => { it('cant switch current before settlement', async () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, POSITION, COLLATERAL, constants.AddressZero) + + // close long position + await expect( + market + .connect(user) + ['update(address,int256,int256,address)'](user.address, POSITION.mul(-1), 0, constants.AddressZero), + ) + // try to open short position await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.mul(-1), 0, constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketOverCloseError') }) it('cant switch current after latest settles', async () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, POSITION, COLLATERAL, constants.AddressZero) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_3.timestamp]) oracle.request.whenCalledWith(user.address).returns() + // close long position await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, 0, false), - ).to.be.revertedWithCustomError(market, 'MarketNotSingleSidedError') + ['update(address,int256,int256,address)'](user.address, POSITION.mul(-1), 0, constants.AddressZero), + ) - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false) + // try to open short position await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.mul(-1), 0, constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketNotSingleSidedError') }) it('can switch current after reset settles', async () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, POSITION, COLLATERAL, constants.AddressZero) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_3.timestamp]) oracle.request.whenCalledWith(user.address).returns() - await expect( - market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, 0, false), - ).to.be.revertedWithCustomError(market, 'MarketNotSingleSidedError') - + // close long position await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, false) + ['update(address,int256,int256,address)'](user.address, POSITION.mul(-1), 0, constants.AddressZero) + + // open short position await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.mul(-1), 0, constants.AddressZero), ).to.be.revertedWithCustomError(market, 'MarketNotSingleSidedError') oracle.at.whenCalledWith(ORACLE_VERSION_3.timestamp).returns([ORACLE_VERSION_3, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_3, ORACLE_VERSION_4.timestamp]) oracle.request.whenCalledWith(user.address).returns() + // open short position await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, POSITION, 0, false), + ['update(address,int256,int256,address)'](user.address, POSITION.mul(-1), 0, constants.AddressZero), ).to.not.be.reverted }) }) @@ -19205,13 +19102,11 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( + ['update(address,int256,int256,int256,address)']( user.address, POSITION, 0, - 0, COLLATERAL, - false, liquidator.address, ), ) @@ -19324,7 +19219,13 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) factory.authorization .whenCalledWith(user.address, user.address, constants.AddressZero, liquidator.address) @@ -19333,15 +19234,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( - user.address, - 0, - POSITION.div(2), - 0, - COLLATERAL, - false, - liquidator.address, - ), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), COLLATERAL, liquidator.address), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -19489,7 +19382,13 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) factory.authorization .whenCalledWith(user.address, user.address, constants.AddressZero, user.address) @@ -19498,15 +19397,7 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( - user.address, - 0, - POSITION.div(2), - 0, - COLLATERAL, - false, - user.address, - ), + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), COLLATERAL, user.address), ) .to.emit(market, 'OrderCreated') .withArgs( @@ -19689,14 +19580,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -19935,14 +19832,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -20182,14 +20085,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -20429,14 +20338,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -20692,17 +20607,23 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userD) - ['update(address,uint256,uint256,uint256,int256,bool)'](userD.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userD.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -21021,14 +20942,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -21271,14 +21198,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -21456,25 +21389,24 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( userB.address, POSITION.mul(2), 0, - 0, COLLATERAL, - false, + constants.AddressZero, ) await market .connect(userD) - ['update(address,uint256,uint256,uint256,int256,bool)'](userD.address, 0, POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userD.address, POSITION, COLLATERAL, constants.AddressZero) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -21732,20 +21664,24 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) oracle.at .whenCalledWith(ORACLE_VERSION_2.timestamp) @@ -21994,20 +21930,24 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) oracle.at .whenCalledWith(ORACLE_VERSION_2.timestamp) @@ -22256,19 +22196,23 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -22519,19 +22463,23 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -22782,26 +22730,28 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -23051,26 +23001,28 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userC.address, - 0, POSITION.div(2), - 0, COLLATERAL, - false, + constants.AddressZero, ) oracle.at @@ -23320,20 +23272,24 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) oracle.at .whenCalledWith(ORACLE_VERSION_2.timestamp) @@ -23513,14 +23469,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -23571,14 +23533,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -23629,14 +23597,20 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](user.address, 0, COLLATERAL, constants.AddressZero) await market .connect(userC) - ['update(address,uint256,uint256,uint256,int256,bool)'](userC.address, 0, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userC.address, 0, COLLATERAL, constants.AddressZero) verifier.verifyIntent.returns() @@ -23691,7 +23665,13 @@ describe('Market', () => { await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) factory.authorization .whenCalledWith(user.address, user.address, constants.AddressZero, liquidator.address) @@ -23853,7 +23833,7 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_3.timestamp]) oracle.request.whenCalledWith(user.address).returns() @@ -23918,17 +23898,16 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - POSITION.div(2), + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, 0, COLLATERAL, - false, + constants.AddressZero, ) + await market + .connect(user) + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), COLLATERAL, constants.AddressZero) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_3.timestamp]) oracle.request.whenCalledWith(user.address).returns() @@ -23995,16 +23974,20 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, - 0, - POSITION.div(2), + POSITION.div(2).mul(-1), COLLATERAL, - false, + constants.AddressZero, ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_3.timestamp]) @@ -24072,17 +24055,21 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ) dsu.transferFrom.whenCalledWith(user.address, market.address, utils.parseEther('216')).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( user.address, - 0, POSITION.div(2), - 0, parse6decimal('216'), - false, + constants.AddressZero, ) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) @@ -24233,18 +24220,17 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, POSITION, 0, 0, COLLATERAL, false) - dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) - await market - .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( - user.address, - 0, - POSITION.div(2), + ['update(address,int256,int256,int256,address)']( + userB.address, + POSITION, 0, COLLATERAL, - false, + constants.AddressZero, ) + dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) + await market + .connect(user) + ['update(address,int256,int256,address)'](user.address, POSITION.div(2), COLLATERAL, constants.AddressZero) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) @@ -24336,11 +24322,11 @@ describe('Market', () => { dsu.transferFrom.whenCalledWith(user.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) dsu.transferFrom.whenCalledWith(userB.address, market.address, COLLATERAL.mul(1e12)).returns(true) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)'](userB.address, 0, POSITION, 0, COLLATERAL, false) + ['update(address,int256,int256,address)'](userB.address, POSITION, COLLATERAL, constants.AddressZero) oracle.at.whenCalledWith(ORACLE_VERSION_2.timestamp).returns([ORACLE_VERSION_2, INITIALIZED_ORACLE_RECEIPT]) oracle.status.returns([ORACLE_VERSION_2, ORACLE_VERSION_3.timestamp]) @@ -24463,7 +24449,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ), ).to.revertedWithCustomError(market, 'ReentrancyGuardReentrantCallError') // try to re-enter into update method @@ -24471,7 +24463,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ), ).to.revertedWithCustomError(market, 'ReentrancyGuardReentrantCallError') // try to re-enter into update intent method @@ -24479,7 +24477,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ), ).to.revertedWithCustomError(market, 'ReentrancyGuardReentrantCallError') // try to re-enter into settle method @@ -24487,7 +24491,13 @@ describe('Market', () => { await expect( market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false), + ['update(address,int256,int256,int256,address)']( + user.address, + POSITION, + 0, + COLLATERAL, + constants.AddressZero, + ), ).to.revertedWithCustomError(market, 'ReentrancyGuardReentrantCallError') }) }) From 81650f0e9f73ec0909bfbb5702804f8522e9ed4d Mon Sep 17 00:00:00 2001 From: Prateek Date: Tue, 24 Dec 2024 16:42:36 +0530 Subject: [PATCH 24/29] PR feedback --- packages/core/contracts/types/Order.sol | 4 ++-- .../test/integration/TriggerOrders/Manager.test.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/core/contracts/types/Order.sol b/packages/core/contracts/types/Order.sol index 6ed2d2ae8..9dea79385 100644 --- a/packages/core/contracts/types/Order.sol +++ b/packages/core/contracts/types/Order.sol @@ -80,13 +80,13 @@ library OrderLib { (UFixed6Lib.ZERO, UFixed6Lib.ZERO, UFixed6Lib.ZERO, UFixed6Lib.ZERO, UFixed6Lib.ZERO, UFixed6Lib.ZERO); } - /// @notice Creates a new order from the an intent and delta order request + /// @notice Creates a new order from an intent or delta order request /// @param timestamp The current timestamp /// @param position The current position /// @param makerAmount The magnitude and direction of maker position /// @param takerAmount The magnitude and direction of taker position /// @param collateral The change in the collateral - /// @param protect Whether the order is protected + /// @param protect True when liquidating the position /// @param referralFee The referral fee /// @return newOrder The resulting order function from( diff --git a/packages/periphery/test/integration/TriggerOrders/Manager.test.ts b/packages/periphery/test/integration/TriggerOrders/Manager.test.ts index d86c8586a..e1a2f5546 100644 --- a/packages/periphery/test/integration/TriggerOrders/Manager.test.ts +++ b/packages/periphery/test/integration/TriggerOrders/Manager.test.ts @@ -760,16 +760,16 @@ export function RunManagerTests(name: string, getFixture: (overrides?: CallOverr expect(canExecuteBefore).to.be.false // time passes, other users interact with market - let positionADelta - let positionCDelta + let positionDeltaA + let positionDeltaC let marketPrice = (await oracle.latest()).price while (marketPrice.gt(triggerPrice)) { // two users change their position - positionADelta = parse6decimal('0.05') - const timestampA = await updatePosition(userA, positionADelta, BigNumber.from(0), BigNumber.from(0)) - positionCDelta = parse6decimal('0.04').mul(-1) - const timestampC = await updatePosition(userC, BigNumber.from(0), BigNumber.from(0), positionCDelta) + positionDeltaA = parse6decimal('0.05') + const timestampA = await updatePosition(userA, positionDeltaA, BigNumber.from(0), BigNumber.from(0)) + positionDeltaC = parse6decimal('0.04').mul(-1) + const timestampC = await updatePosition(userC, BigNumber.from(0), BigNumber.from(0), positionDeltaC) // oracle versions fulfilled marketPrice = marketPrice.sub(parse6decimal('0.35')) From 6564682851e6c16f8b7b039075a2e81dbd710df4 Mon Sep 17 00:00:00 2001 From: Prateek Date: Tue, 24 Dec 2024 18:04:56 +0530 Subject: [PATCH 25/29] fix insurance fund tests --- .../core/test/integration/core/fees.test.ts | 10 +------- .../test/integration/core/liquidate.test.ts | 24 ++++++------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/packages/core/test/integration/core/fees.test.ts b/packages/core/test/integration/core/fees.test.ts index f34c9f29f..24c45f0ab 100644 --- a/packages/core/test/integration/core/fees.test.ts +++ b/packages/core/test/integration/core/fees.test.ts @@ -2460,15 +2460,7 @@ describe('Fees', () => { await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool,address)']( - user.address, - POSITION, - 0, - 0, - COLLATERAL, - false, - constants.AddressZero, - ) + ['update(address,int256,int256,int256,address)'](user.address, POSITION, 0, COLLATERAL, constants.AddressZero) expectOrderEq(await market.pendingOrder(1), { ...DEFAULT_ORDER, diff --git a/packages/core/test/integration/core/liquidate.test.ts b/packages/core/test/integration/core/liquidate.test.ts index cb55e8a8e..868b00a9b 100644 --- a/packages/core/test/integration/core/liquidate.test.ts +++ b/packages/core/test/integration/core/liquidate.test.ts @@ -139,24 +139,16 @@ describe('Liquidate', () => { await dsu.connect(userB).approve(market.address, COLLATERAL.mul(1e12)) await market .connect(user) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,int256,address)']( user.address, POSITION, 0, - 0, parse6decimal('1000'), - false, + constants.AddressZero, ) await market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( - userB.address, - 0, - POSITION, - 0, - parse6decimal('1000'), - false, - ) + ['update(address,int256,int256,address)'](userB.address, POSITION, parse6decimal('1000'), constants.AddressZero) // Settle the market with a new oracle version await chainlink.next() @@ -169,17 +161,15 @@ describe('Liquidate', () => { await expect( market .connect(userB) - ['update(address,uint256,uint256,uint256,int256,bool)']( + ['update(address,int256,int256,address)']( userB.address, - 0, - 0, - 0, + POSITION.mul(-1), userBCollateral.mul(-1).sub(1), - false, + constants.AddressZero, ), ).to.be.revertedWithCustomError(market, 'MarketInsufficientMarginError') // underflow - await market.connect(userB)['update(address,uint256,uint256,uint256,int256,bool)'](user.address, 0, 0, 0, 0, true) // liquidate + await market.connect(userB).close(user.address, true, constants.AddressZero) // liquidate chainlink.updateParams(parse6decimal('1.0'), parse6decimal('0.1')) await chainlink.nextWithPriceModification(price => price.mul(2)) From f3b02b101c41dad86b2bba8636e6c3d960115701 Mon Sep 17 00:00:00 2001 From: Prateek Date: Mon, 30 Dec 2024 21:44:38 +0530 Subject: [PATCH 26/29] PR feedback --- packages/core/contracts/types/Order.sol | 2 +- packages/vault/contracts/Vault.sol | 2 +- packages/vault/contracts/libs/StrategyLib.sol | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/core/contracts/types/Order.sol b/packages/core/contracts/types/Order.sol index 9dea79385..3306f75fa 100644 --- a/packages/core/contracts/types/Order.sol +++ b/packages/core/contracts/types/Order.sol @@ -101,9 +101,9 @@ library OrderLib { newOrder.timestamp = timestamp; newOrder.collateral = collateral; newOrder.orders = makerAmount.isZero() && takerAmount.isZero() ? 0 : 1; + newOrder.protection = protect ? 1 : 0; newOrder.makerReferral = makerAmount.abs().mul(referralFee); newOrder.takerReferral = takerAmount.abs().mul(referralFee); - newOrder.protection = protect ? 1 : 0; // If the order is not counter to the current position, it is opening if (takerAmount.sign() == 0 || position.skew().sign() == 0 || position.skew().sign() == takerAmount.sign()) { diff --git a/packages/vault/contracts/Vault.sol b/packages/vault/contracts/Vault.sol index 166ac3baf..cc4acb274 100644 --- a/packages/vault/contracts/Vault.sol +++ b/packages/vault/contracts/Vault.sol @@ -460,7 +460,7 @@ contract Vault is IVault, Instance { ) private { registration.market.update( address(this), - shouldRebalance ? target.position : Fixed6Lib.ZERO, + shouldRebalance ? target.makerPositionDelta : Fixed6Lib.ZERO, Fixed6Lib.ZERO, target.collateral, address(0) diff --git a/packages/vault/contracts/libs/StrategyLib.sol b/packages/vault/contracts/libs/StrategyLib.sol index 38e99a6f6..03548418a 100644 --- a/packages/vault/contracts/libs/StrategyLib.sol +++ b/packages/vault/contracts/libs/StrategyLib.sol @@ -80,7 +80,7 @@ library StrategyLib { Fixed6 collateral; /// @dev The amount of change in position - Fixed6 position; + Fixed6 makerPositionDelta; } /// @notice Loads the strategy context of each of the underlying markets @@ -161,7 +161,11 @@ library StrategyLib { if (marketContext.marketParameter.closed || marketAssets.lt(minAssets)) marketAssets = UFixed6Lib.ZERO; - target.position = _getTargetPosition(marketContext, marketAssets); + UFixed6 newMaker = marketAssets.muldiv(marketContext.registration.leverage, marketContext.latestPrice.abs()) + .max(marketContext.minPosition) + .min(marketContext.maxPosition); + + target.makerPositionDelta = Fixed6Lib.from(newMaker).sub(Fixed6Lib.from(marketContext.currentAccountPosition.maker)); } /// @notice Load the context of a market From 0878a920623cd1a10fb6e813f9c349fab78659c0 Mon Sep 17 00:00:00 2001 From: Prateek Date: Tue, 7 Jan 2025 00:27:27 +0530 Subject: [PATCH 27/29] fix tests --- .../unit/MultiInvoker/MultiInvoker.test.ts | 34 +++++++------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/packages/periphery/test/unit/MultiInvoker/MultiInvoker.test.ts b/packages/periphery/test/unit/MultiInvoker/MultiInvoker.test.ts index 5b52a4b90..940c9ed9c 100644 --- a/packages/periphery/test/unit/MultiInvoker/MultiInvoker.test.ts +++ b/packages/periphery/test/unit/MultiInvoker/MultiInvoker.test.ts @@ -150,7 +150,7 @@ export function RunMultiInvokerTests(name: string, setup: () => Promise): usdc.transfer.whenCalledWith(user.address, collateral).returns(true) vault.update.returns(true) - market['update(address,uint256,uint256,uint256,int256,bool,address)'].returns(true) + market['update(address,int256,int256,int256,address)'].returns(true) } beforeEach(async () => { @@ -162,13 +162,11 @@ export function RunMultiInvokerTests(name: string, setup: () => Promise): .reverted expect(dsu.transferFrom).to.have.been.calledWith(user.address, multiInvoker.address, collateral.mul(1e12)) - expect(market['update(address,uint256,uint256,uint256,int256,bool,address)']).to.have.been.calledWith( + expect(market['update(address,int256,int256,int256,address)']).to.have.been.calledWith( user.address, - MAX_UINT, - MAX_UINT, - MAX_UINT, + 0, + 0, collateral, - false, constants.AddressZero, ) }) @@ -206,13 +204,11 @@ export function RunMultiInvokerTests(name: string, setup: () => Promise): .be.reverted expect(dsu.transfer).to.have.been.calledWith(user.address, dsuCollateral) - expect(market['update(address,uint256,uint256,uint256,int256,bool,address)']).to.have.been.calledWith( + expect(market['update(address,int256,int256,int256,address)']).to.have.been.calledWith( user.address, - MAX_UINT, - MAX_UINT, - MAX_UINT, + 0, + 0, collateral.mul(-1), - false, constants.AddressZero, ) }) @@ -581,13 +577,11 @@ export function RunMultiInvokerTests(name: string, setup: () => Promise): await expect(multiInvoker.connect(owner).claim(owner.address, true)).to.not.be.reverted expect(usdc.transfer).to.have.been.calledWith(owner.address, feeAmt) - expect(market['update(address,uint256,uint256,uint256,int256,bool,address)']).to.have.been.calledWith( + expect(market['update(address,int256,int256,int256,address)']).to.have.been.calledWith( user.address, - MAX_UINT, - MAX_UINT, - MAX_UINT, + 0, + 0, collateral.sub(feeAmt).mul(-1), - false, owner.address, ) }) @@ -627,13 +621,11 @@ export function RunMultiInvokerTests(name: string, setup: () => Promise): await expect(multiInvoker.connect(user2).claim(user2.address, true)).to.not.be.reverted expect(usdc.transfer).to.have.been.calledWith(user2.address, feeAmt) - expect(market['update(address,uint256,uint256,uint256,int256,bool,address)']).to.have.been.calledWith( + expect(market['update(address,int256,int256,int256,address)']).to.have.been.calledWith( user.address, - MAX_UINT, - MAX_UINT, - MAX_UINT, + 0, + 0, collateral.sub(feeAmt).mul(-1), - false, user2.address, ) }) From 84f256cd5ae8a847c77e2b8156a8ebbea722f3bd Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 8 Jan 2025 11:35:22 +0530 Subject: [PATCH 28/29] rename position --- packages/vault/contracts/Vault.sol | 2 +- packages/vault/contracts/libs/StrategyLib.sol | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/vault/contracts/Vault.sol b/packages/vault/contracts/Vault.sol index cc4acb274..166ac3baf 100644 --- a/packages/vault/contracts/Vault.sol +++ b/packages/vault/contracts/Vault.sol @@ -460,7 +460,7 @@ contract Vault is IVault, Instance { ) private { registration.market.update( address(this), - shouldRebalance ? target.makerPositionDelta : Fixed6Lib.ZERO, + shouldRebalance ? target.position : Fixed6Lib.ZERO, Fixed6Lib.ZERO, target.collateral, address(0) diff --git a/packages/vault/contracts/libs/StrategyLib.sol b/packages/vault/contracts/libs/StrategyLib.sol index 03548418a..ac99679fa 100644 --- a/packages/vault/contracts/libs/StrategyLib.sol +++ b/packages/vault/contracts/libs/StrategyLib.sol @@ -80,7 +80,7 @@ library StrategyLib { Fixed6 collateral; /// @dev The amount of change in position - Fixed6 makerPositionDelta; + Fixed6 position; } /// @notice Loads the strategy context of each of the underlying markets @@ -165,7 +165,7 @@ library StrategyLib { .max(marketContext.minPosition) .min(marketContext.maxPosition); - target.makerPositionDelta = Fixed6Lib.from(newMaker).sub(Fixed6Lib.from(marketContext.currentAccountPosition.maker)); + target.position = Fixed6Lib.from(newMaker).sub(Fixed6Lib.from(marketContext.currentAccountPosition.maker)); } /// @notice Load the context of a market From 62c630c7dbacde4d654ff100e12b187955ab6aca Mon Sep 17 00:00:00 2001 From: Prateek Date: Wed, 8 Jan 2025 13:16:23 +0530 Subject: [PATCH 29/29] update workflow --- .github/workflows/CI.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a998704d5..94dcab800 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -7,7 +7,6 @@ on: branches: - main - v2.4 - - prateek/pe-1629-remove-magic-values workflow_dispatch: env: