Skip to content

Commit f6bbf06

Browse files
committed
feat: polyswap contrats v0.1
1 parent 5b36f4e commit f6bbf06

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/Polyswap.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,20 @@ import {
1010
import {ComposableCoW} from "@composable-cow/ComposableCoW.sol";
1111

1212
import {Trading} from "exchange/mixins/Trading.sol";
13+
import {OrderStatus} from "exchange/libraries/OrderStructs.sol";
1314

1415
import {PolyswapOrder} from "./PolyswapOrder.sol";
1516

17+
// --- error strings
18+
string constant INVALID_HASH = "invalid hash";
19+
string constant CONDITION_NOT_MET = "condition not met";
20+
string constant POLYMARKET_ORDER_CANCELLED = "polymarket order cancelled";
21+
22+
/**
23+
* @title Polyswap Conditional Order
24+
* @dev This contract implements the logic for generating a tradeable order based on a Polyswap order.
25+
* It inherits from BaseConditionalOrder to work with the ComposableCoW framework.
26+
**/
1627
contract Polyswap is BaseConditionalOrder {
1728
ComposableCoW public immutable composableCow;
1829
Trading public immutable polymarket;
@@ -41,5 +52,12 @@ contract Polyswap is BaseConditionalOrder {
4152
order = PolyswapOrder.orderFor(polyswapOrder, polymarket);
4253

4354
// check if the polymarket order is fulfilled
55+
OrderStatus memory status = polymarket.getOrderStatus(polyswapOrder.polymarketOrderHash);
56+
if (status.isFilledOrCancelled && status.remaining != 0) {
57+
revert IConditionalOrder.PollNever(POLYMARKET_ORDER_CANCELLED);
58+
}
59+
if (!(status.isFilledOrCancelled && status.remaining == 0)) {
60+
revert IConditionalOrder.PollTryNextBlock(CONDITION_NOT_MET);
61+
}
4462
}
4563
}

src/PolyswapOrder.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-License-Identifier: GPL-3.0
1+
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity >=0.8.0 <0.9.0;
33

44
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
@@ -58,7 +58,7 @@ library PolyswapOrder {
5858
// Check if the Polymarket order is valid and not filled or cancelled.
5959
if (!(self.polymarketOrderHash == 0)) revert IConditionalOrder.OrderNotValid(INVALID_POLYMARKET_ORDER_HASH);
6060
OrderStatus memory order = polymarket.getOrderStatus(self.polymarketOrderHash);
61-
if (!(order.remaining != 0 || order.isFilledOrCancelled == false)) {
61+
if (order.remaining == 0 && order.isFilledOrCancelled == false) {
6262
revert IConditionalOrder.OrderNotValid(INVALID_POLYMARKET_ORDER_HASH);
6363
}
6464
}
@@ -78,7 +78,7 @@ library PolyswapOrder {
7878
receiver: self.receiver,
7979
sellAmount: self.sellAmount,
8080
buyAmount: self.minBuyAmount,
81-
validTo: uint32(self.t),
81+
validTo: self.t.toUint32(),
8282
appData: self.polymarketOrderHash,
8383
feeAmount: 0,
8484
kind: GPv2Order.KIND_SELL,

0 commit comments

Comments
 (0)