Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MarketUpdated event #1697

Merged
merged 10 commits into from
Jul 5, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ interface IAsyncOrderModule {
int128 newSize,
uint256 collectedFees,
uint256 settelementReward,
uint256 marketSize,
int256 marketSkew,
bytes32 indexed trackingCode,
address settler
);
Expand Down
9 changes: 6 additions & 3 deletions markets/perps-market/contracts/modules/AsyncOrderModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ contract AsyncOrderModule is IAsyncOrderModule {
}

// after pnl is realized, update position
PerpsMarket.loadValid(runtime.marketId).updatePositionData(runtime.accountId, newPosition);
PerpsMarket.Data storage market = PerpsMarket.loadValid(runtime.marketId);
market.updatePositionData(runtime.accountId, newPosition);

perpsAccount.updatePositionMarkets(runtime.marketId, runtime.newPositionSize);
perpsAccount.deductFromAccount(totalFees);
Expand All @@ -223,7 +224,7 @@ contract AsyncOrderModule is IAsyncOrderModule {
}

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

asyncOrder.reset();

Expand All @@ -236,7 +237,9 @@ contract AsyncOrderModule is IAsyncOrderModule {
runtime.newPositionSize,
totalFees,
runtime.settlementReward,
trackingCode,
market.size,
market.skew,
0xjocke marked this conversation as resolved.
Show resolved Hide resolved
runtime.trackingCode,
msg.sender
);
}
Expand Down
1 change: 1 addition & 0 deletions markets/perps-market/contracts/storage/AsyncOrder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ library AsyncOrder {
uint initialRequiredMargin;
uint totalRequiredMargin;
Position.Data newPosition;
bytes32 trackingCode;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, without it we get "Stack too deep." Just at the limit now 😓

}

function validateOrder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,33 @@ describe('Settle Offchain Async Order test', () => {

it('emits event', async () => {
// TODO Calculate the correct fill price instead of hardcoding

const accountId = 2;
const fillPrice = bn(1000.005);
const pnl = 0;
const newPositionSize = bn(1);
const totalFees = DEFAULT_SETTLEMENT_STRATEGY.settlementReward;
const settlementReward = DEFAULT_SETTLEMENT_STRATEGY.settlementReward;
const marketSize = bn(1);
const marketSkew = bn(1);
const trackingCode = `"${ethers.constants.HashZero}"`;
const msgSender = `"${await keeper().getAddress()}"`;
const params = [
ethMarketId,
accountId,
fillPrice,
pnl,
newPositionSize,
totalFees,
settlementReward,
marketSize,
marketSkew,
trackingCode,
msgSender,
];
await assertEvent(
settleTx,
`OrderSettled(${ethMarketId}, 2, ${fillPrice}, 0, ${bn(1)}, ${
DEFAULT_SETTLEMENT_STRATEGY.settlementReward
}, ${DEFAULT_SETTLEMENT_STRATEGY.settlementReward}, "${
ethers.constants.HashZero
}", "${await keeper().getAddress()}")`,
`OrderSettled(${params.join(', ')})`,
systems().PerpsMarket
);
});
Expand Down
Loading