Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contract/test/Day4PriceUpdate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import "./utils/ExchangeFixture.sol";
import "../../src/core/ExchangeStorage.sol";
import "../src/core/ExchangeStorage.sol";
// import "./mocks/MockPyth.sol";

// Day 4: Pyth 价格更新(模板级别,使用本地 mock)
Expand Down
30 changes: 15 additions & 15 deletions contract/test/PositionMargin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,22 @@ contract PositionMarginTest is Test {

// 诊断信息
aliceMargin = exchange.margin(alice);
MonadPerpExchange.Position memory alicePos = exchange.getPosition(alice);
MonadPerpExchange.Position memory alicePosAfterTrade = exchange.getPosition(alice);
console.log("\nDiagnostics:");
console.log(" Alice margin:", aliceMargin / 1e18, "ETH");
console.log(" Alice position size:", uint256(alicePos.size));
console.log(" Alice position entry:", alicePos.entryPrice / 1e18, "ETH");
console.log(" Alice position size:", uint256(alicePosAfterTrade.size));
console.log(" Alice position entry:", alicePosAfterTrade.entryPrice / 1e18, "ETH");

// 计算理论保证金需求
uint256 positionNotional = uint256(alicePos.size) * exchange.markPrice() / 1e18;
uint256 positionNotional = uint256(alicePosAfterTrade.size) * exchange.markPrice() / 1e18;
uint256 positionMargin = positionNotional * exchange.initialMarginBps() / 10_000;
console.log(" Current position margin needed:", positionMargin / 1e18, "ETH");

uint256 newOrderNotional = 0.02 ether * 1520 ether / 1e18;
uint256 newOrderMargin = newOrderNotional * exchange.initialMarginBps() / 10_000;
console.log(" New order margin needed:", newOrderMargin / 1e18, "ETH");

fail("Trade #2 failed");
assertTrue(false, "Trade #2 failed");
}

// Step 5: Trade #3 - 1490 @ 0.015 ETH
Expand All @@ -144,7 +144,7 @@ contract PositionMarginTest is Test {
} catch Error(string memory reason) {
console.log("FAILED: Alice buy order failed!");
console.log("Reason:", reason);
fail("Trade #3 failed");
assertTrue(false, "Trade #3 failed");
}

// Step 6: Trade #4 - 1550 @ 0.03 ETH
Expand All @@ -164,7 +164,7 @@ contract PositionMarginTest is Test {
} catch Error(string memory reason) {
console.log("FAILED: Alice buy order failed!");
console.log("Reason:", reason);
fail("Trade #4 failed");
assertTrue(false, "Trade #4 failed");
}

console.log("\n===========================================");
Expand All @@ -181,7 +181,7 @@ contract PositionMarginTest is Test {
} catch Error(string memory reason) {
console.log("FAILED: Alice buy @ 1400 failed!");
console.log("Reason:", reason);
fail("Alice buy order @ 1400 failed");
assertTrue(false, "Alice buy order @ 1400 failed");
}

vm.prank(alice);
Expand All @@ -190,7 +190,7 @@ contract PositionMarginTest is Test {
} catch Error(string memory reason) {
console.log("FAILED: Alice buy @ 1450 failed!");
console.log("Reason:", reason);
fail("Alice buy order @ 1450 failed");
assertTrue(false, "Alice buy order @ 1450 failed");
}

vm.prank(bob);
Expand All @@ -199,7 +199,7 @@ contract PositionMarginTest is Test {
} catch Error(string memory reason) {
console.log("FAILED: Bob sell @ 1600 failed!");
console.log("Reason:", reason);
fail("Bob sell order @ 1600 failed");
assertTrue(false, "Bob sell order @ 1600 failed");
}

vm.prank(bob);
Expand All @@ -208,7 +208,7 @@ contract PositionMarginTest is Test {
} catch Error(string memory reason) {
console.log("FAILED: Bob sell @ 1650 failed!");
console.log("Reason:", reason);
fail("Bob sell order @ 1650 failed");
assertTrue(false, "Bob sell order @ 1650 failed");
}

// Step 8: Creating Partial Fills
Expand All @@ -222,7 +222,7 @@ contract PositionMarginTest is Test {
} catch Error(string memory reason) {
console.log("FAILED: Alice buy @ 1580 failed!");
console.log("Reason:", reason);
fail("Alice buy order @ 1580 failed");
assertTrue(false, "Alice buy order @ 1580 failed");
}

vm.prank(bob);
Expand All @@ -231,7 +231,7 @@ contract PositionMarginTest is Test {
} catch Error(string memory reason) {
console.log("FAILED: Bob sell @ 1580 failed!");
console.log("Reason:", reason);
fail("Bob sell @ 1580 failed");
assertTrue(false, "Bob sell @ 1580 failed");
}

// Scenario 2: Bob Sell 0.02 @ 1620, Alice Buy 0.005 @ 1620
Expand All @@ -241,7 +241,7 @@ contract PositionMarginTest is Test {
} catch Error(string memory reason) {
console.log("FAILED: Bob sell @ 1620 failed!");
console.log("Reason:", reason);
fail("Bob sell @ 1620 failed");
assertTrue(false, "Bob sell @ 1620 failed");
}

vm.prank(alice);
Expand All @@ -250,7 +250,7 @@ contract PositionMarginTest is Test {
} catch Error(string memory reason) {
console.log("FAILED: Alice buy @ 1620 failed!");
console.log("Reason:", reason);
fail("Alice buy @ 1620 failed");
assertTrue(false, "Alice buy @ 1620 failed");
}

console.log("\n===========================================");
Expand Down
2 changes: 1 addition & 1 deletion contract/test/utils/MonadPerpExchangeHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.20;
import "../../src/Exchange.sol";

contract MonadPerpExchangeHarness is MonadPerpExchange {
constructor() MonadPerpExchange() {}
constructor() {}

bool public manualPriceMode;

Expand Down