Skip to content

Commit

Permalink
Merge branch 'main' into get-order
Browse files Browse the repository at this point in the history
  • Loading branch information
leomassazza authored Jul 6, 2023
2 parents 782a726 + 845adb4 commit efaa675
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ interface IAsyncOrderSettlementModule {
* @param marketId Id of the market used for the trade.
* @param accountId Id of the account used for the trade.
* @param fillPrice Price at which the order was settled.
* @param accountPnlRealized Realized PnL of the position at the time of settlement.
* @param sizeDelta Size delta from order.
* @param newSize New size of the position after settlement.
* @param collectedFees Amount of fees collected by the protocol.
* @param settelementReward Amount of fees collected by the settler.
* @param settlementReward Amount of fees collected by the settler.
* @param trackingCode Optional code for integrator tracking purposes.
* @param settler address of the settler of the order.
*/
event OrderSettled(
uint128 indexed marketId,
uint128 indexed accountId,
uint256 fillPrice,
int256 accountPnlRealized,
int128 sizeDelta,
int128 newSize,
uint256 collectedFees,
uint256 settelementReward,
uint256 settlementReward,
bytes32 indexed trackingCode,
address settler
);
Expand All @@ -47,11 +47,11 @@ interface IAsyncOrderSettlementModule {
uint128 marketId;
uint128 accountId;
int128 newPositionSize;
int128 sizeDelta;
int256 pnl;
uint256 pnlUint;
uint256 amountToDeposit;
uint256 settlementReward;
bytes32 trackingCode;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ contract AsyncOrderSettlementModule is IAsyncOrderSettlementModule, IMarketEvent
) = asyncOrder.validateOrder(settlementStrategy, price);

runtime.newPositionSize = newPosition.size;
runtime.sizeDelta = asyncOrder.sizeDelta;

PerpsMarketFactory.Data storage factory = PerpsMarketFactory.load();
PerpsAccount.Data storage perpsAccount = PerpsAccount.load(runtime.accountId);
Expand All @@ -158,7 +159,7 @@ contract AsyncOrderSettlementModule is IAsyncOrderSettlementModule, IMarketEvent
updateData.marketId,
updateData.skew,
updateData.size,
updateData.sizeDelta,
runtime.sizeDelta,
updateData.currentFundingRate,
updateData.currentFundingVelocity
);
Expand All @@ -178,21 +179,18 @@ contract AsyncOrderSettlementModule is IAsyncOrderSettlementModule, IMarketEvent
factory.depositToMarketManager(runtime.marketId, runtime.amountToDeposit);
}

// exctracted from asyncOrder before order is reset
runtime.trackingCode = asyncOrder.trackingCode;

asyncOrder.reset();

// emit event
emit OrderSettled(
runtime.marketId,
runtime.accountId,
fillPrice,
runtime.pnl,
runtime.sizeDelta,
runtime.newPositionSize,
totalFees,
runtime.settlementReward,
runtime.trackingCode,
asyncOrder.trackingCode,
msg.sender
);
}
Expand Down
3 changes: 0 additions & 3 deletions markets/perps-market/contracts/storage/PerpsMarket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ library PerpsMarket {
uint128 marketId;
int256 skew;
uint256 size;
int256 sizeDelta;
int256 currentFundingRate;
int256 currentFundingVelocity;
}
Expand All @@ -156,14 +155,12 @@ library PerpsMarket {
self.size = (self.size + MathUtil.abs(newPosition.size)) - MathUtil.abs(oldPositionSize);
self.skew += newPosition.size - oldPositionSize;
oldPosition.updatePosition(newPosition);
int128 sizeDelta = newPosition.size - oldPositionSize;
// TODO add current market debt
return
MarketUpdateData(
self.id,
self.skew,
self.size,
sizeDelta,
self.lastFundingRate,
currentFundingVelocity(self)
);
Expand Down
2 changes: 1 addition & 1 deletion markets/perps-market/storage.dump.sol
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,11 @@ interface IAsyncOrderSettlementModule {
uint128 marketId;
uint128 accountId;
int128 newPositionSize;
int128 sizeDelta;
int256 pnl;
uint256 pnlUint;
uint256 amountToDeposit;
uint256 settlementReward;
bytes32 trackingCode;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ describe('Settle Offchain Async Order test', () => {
it('emits event settle event', async () => {
const accountId = 2;
const fillPrice = calculateFillPrice(wei(0), wei(100_000), wei(1), wei(1000)).toBN();
const pnl = 0;
const sizeDelta = bn(1);
const newPositionSize = bn(1);
const totalFees = DEFAULT_SETTLEMENT_STRATEGY.settlementReward;
const settlementReward = DEFAULT_SETTLEMENT_STRATEGY.settlementReward;
Expand All @@ -395,7 +395,7 @@ describe('Settle Offchain Async Order test', () => {
ethMarketId,
accountId,
fillPrice,
pnl,
sizeDelta,
newPositionSize,
totalFees,
settlementReward,
Expand Down

0 comments on commit efaa675

Please sign in to comment.