Skip to content

Commit 8649768

Browse files
committed
feat: add simple tests + minor changes on the core contracts
1 parent d98b668 commit 8649768

8 files changed

Lines changed: 601 additions & 12 deletions

File tree

.env.sample

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ POLYMARKET_ORDER_HASH=0x40000000000000000000000000000000000000000000000000000000
1010
SPENDER=0xC92E8bdf79f0507f65a392b0ab4667716BFE0110 # GPv2VaultRelayer contract on Polygon
1111

1212
SELL_TOKEN=0xc2132D05D31c914a87C6611C10748AEb04B58e8F # USDT on Polygon
13-
BUY_TOKEN=0x2791bca1f2de4661ed88a30c99a7a9449aa84174 # USDC on Polygon
13+
BUY_TOKEN=0x2791bca1f2de4661ed88a30c99a7a9449aa84174 # USDC on Polygon
14+
15+
RPC_URL_POLYGON=https://1rpc.io/matic

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Compiler files
22
cache/
33
out/
4-
4+
**/.DS_Store
55
# Ignores development broadcast logs
66
!/broadcast
77
/broadcast/*/31337/

foundry.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"lib/composable-cow": {
3+
"rev": "54ee414d8e8291a915b387e4f29b04d9cd0ebbbd"
4+
},
5+
"lib/ctf-exchange": {
6+
"rev": "503c0af02f9199177227f69ffcd5a7e4ca7b5d47"
7+
},
8+
"lib/extensible-fallback-handler": {
9+
"rev": "11273c1f08eda18ed8ff49ec1d4abec5e451ff21"
10+
},
11+
"lib/forge-std": {
12+
"rev": "77041d2ce690e692d6e03cc812b57d1ddaa4d505"
13+
},
14+
"lib/openzeppelin-contracts": {
15+
"rev": "e4f70216d759d8e6a64144a9e1f7bbeed78e7079"
16+
}
17+
}

foundry.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ src = "src"
33
out = "out"
44
libs = ["lib"]
55

6+
[rpc_endpoints]
7+
polygon = "${RPC_URL_POLYGON}"
8+
9+
10+
611
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

remappings.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@openzeppelin/=lib/composable-cow/lib/@openzeppelin/
1+
@openzeppelin/=lib/openzeppelin-contracts/
22
common/=lib/ctf-exchange/src/common/
33
composable-cow/=lib/composable-cow/
44
@composable-cow/=lib/composable-cow/src
@@ -10,3 +10,4 @@ openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/
1010
openzeppelin/=lib/composable-cow/lib/@openzeppelin/contracts/
1111
safe/=lib/composable-cow/lib/safe/contracts/
1212
safe/=lib/extensible-fallback-handler/contracts/
13+

src/Polyswap.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ contract Polyswap is BaseConditionalOrder {
5757
if (status.isFilledOrCancelled && status.remaining != 0) {
5858
revert IConditionalOrder.PollNever(POLYMARKET_ORDER_CANCELLED);
5959
}
60-
if (!(status.isFilledOrCancelled && status.remaining == 0)) {
60+
if (status.isFilledOrCancelled == false || status.remaining != 0) {
6161
revert IConditionalOrder.PollTryNextBlock(CONDITION_NOT_MET);
6262
}
6363
}

src/PolyswapOrder.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ library PolyswapOrder {
4747
* @param self The PolyswapOrder order to validate
4848
*/
4949
function validate(Data memory self, Trading polymarket) internal view {
50-
if (!(self.sellToken != self.buyToken)) revert IConditionalOrder.OrderNotValid(INVALID_SAME_TOKEN);
51-
if (!(address(self.sellToken) != address(0) && address(self.buyToken) != address(0))) {
50+
if (self.sellToken == self.buyToken) revert IConditionalOrder.OrderNotValid(INVALID_SAME_TOKEN);
51+
if (address(self.sellToken) == address(0) || address(self.buyToken) == address(0)) {
5252
revert IConditionalOrder.OrderNotValid(INVALID_TOKEN);
5353
}
54-
if (!(self.t0 < type(uint32).max)) revert IConditionalOrder.OrderNotValid(INVALID_START_DATE);
55-
if (!(self.t > self.t0 && self.t < type(uint32).max)) revert IConditionalOrder.OrderNotValid(INVALID_END_DATE);
56-
if (!(self.sellAmount > 0)) revert IConditionalOrder.OrderNotValid(INVALID_SELL_AMOUNT);
57-
if (!(self.minBuyAmount > 0)) revert IConditionalOrder.OrderNotValid(INVALID_MIN_BUY_AMOUNT);
54+
if (self.t0 > block.timestamp) revert IConditionalOrder.OrderNotValid(INVALID_START_DATE);
55+
if (self.t <= self.t0 || self.t < block.timestamp) revert IConditionalOrder.OrderNotValid(INVALID_END_DATE);
56+
if (self.sellAmount < 0) revert IConditionalOrder.OrderNotValid(INVALID_SELL_AMOUNT);
57+
if (self.minBuyAmount < 0) revert IConditionalOrder.OrderNotValid(INVALID_MIN_BUY_AMOUNT);
5858

5959
// Check if the Polymarket order is valid and not filled or cancelled.
60-
if (!(self.polymarketOrderHash != 0)) revert IConditionalOrder.OrderNotValid(INVALID_POLYMARKET_ORDER_HASH);
60+
if (self.polymarketOrderHash == 0) revert IConditionalOrder.OrderNotValid(INVALID_POLYMARKET_ORDER_HASH);
6161
OrderStatus memory order = polymarket.getOrderStatus(self.polymarketOrderHash);
6262
if (order.remaining == 0 && order.isFilledOrCancelled == false) {
6363
revert IConditionalOrder.OrderNotValid(INVALID_POLYMARKET_ORDER_HASH);
@@ -81,7 +81,7 @@ library PolyswapOrder {
8181
buyAmount: self.minBuyAmount,
8282
validTo: self.t.toUint32(),
8383
appData: self.appData,
84-
feeAmount: 0,
84+
feeAmount: 0, // TODO we should allow for some fees
8585
kind: GPv2Order.KIND_SELL,
8686
partiallyFillable: false,
8787
sellTokenBalance: GPv2Order.BALANCE_ERC20,

0 commit comments

Comments
 (0)