Skip to content

Commit 5e95a0a

Browse files
committed
[FEAT]: appData is now passed in calldata and update readme
1 parent a813af5 commit 5e95a0a

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ This repository contains the core smart contracts of **PolySwap**, a protocol th
99
PolySwap lets users define CoW Swap orders that become valid only when a specific prediction market condition is met.
1010
The contract checks the status of a Polymarket order and activates the swap only if that order has been fully filled (indicating the prediction condition was reached).
1111

12-
## 🧱 Contract Overview (not finished yet)
12+
## 🧱 Contract Overview
1313

14-
* `IConditionalOrderGenerator`: Interface for condition-based CoW Swap orders.
15-
* `PolySwapOrderVerifier`: Verifies whether the Polymarket condition (order filled) is satisfied.
14+
* `BaseConditionalOrder`: Abstract contract to inherit for compatibility with ComposableCoW.
15+
* `Polyswap`: Main contract that inherits from `BaseConditionalOrder` and verifies if the Polymarket order is filled.
16+
* `PolySwapOrder`: Verifies if the Polyswap order parameters are correct and defines the order struct.
1617

17-
The core logic uses the Polymarket `CTFExchange` contract to check if:
18+
The `Polyswap` contract uses the Polymarket `CTFExchange` contract to check, via the `getOrderStatus()` function, whether:
1819

1920
* the order is filled or cancelled, and
2021
* the remaining amount is `0`.
2122

23+
If both conditions are met, the swap is executed using the Composable CoW Swap protocol.
24+
2225
## 🧪 Stack
2326

2427
* [Solidity](https://soliditylang.org)

script/SubmitSingleOrder.s.sol

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {IValueFactory} from "composable-cow/src/interfaces/IValueFactory.sol";
1919
import {PolyswapOrder} from "../src/PolyswapOrder.sol";
2020
import {Polyswap} from "../src/Polyswap.sol";
2121

22-
2322
contract SubmitSingleOrder is Script {
2423
using SafeLib for Safe;
2524

@@ -42,7 +41,8 @@ contract SubmitSingleOrder is Script {
4241
minBuyAmount: 80000, // 0.08 buy token
4342
t0: block.timestamp,
4443
t: block.timestamp + 1 days,
45-
polymarketOrderHash: polymarketOrderHash
44+
polymarketOrderHash: polymarketOrderHash,
45+
appData: bytes32(0x053e648e24f8653eb9cffe71f170227d25f8fd69c135bcf2125ae24f4d210b9b) // twap app data for the test
4646
});
4747

4848
IConditionalOrder.ConditionalOrderParams memory params = IConditionalOrder.ConditionalOrderParams({
@@ -88,13 +88,7 @@ contract ApproveSellTokenOnSafe is Script {
8888
safe.executeSingleOwner(
8989
address(sellToken),
9090
0,
91-
abi.encodeCall(
92-
sellToken.approve,
93-
(
94-
spender,
95-
type(uint256).max
96-
)
97-
),
91+
abi.encodeCall(sellToken.approve, (spender, type(uint256).max)),
9892
Enum.Operation.Call,
9993
vm.addr(deployerPrivateKey)
10094
);

src/PolyswapOrder.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ library PolyswapOrder {
3737
uint256 t0; // start valide date of the order
3838
uint256 t; // maximum date for the order to be valid
3939
bytes32 polymarketOrderHash; // hash of the Polymarket order
40+
bytes32 appData;
4041
}
4142

4243
// --- functions
@@ -79,7 +80,7 @@ library PolyswapOrder {
7980
sellAmount: self.sellAmount,
8081
buyAmount: self.minBuyAmount,
8182
validTo: self.t.toUint32(),
82-
appData: bytes32(0x053e648e24f8653eb9cffe71f170227d25f8fd69c135bcf2125ae24f4d210b9b), // need to create our own app data
83+
appData: self.appData,
8384
feeAmount: 0,
8485
kind: GPv2Order.KIND_SELL,
8586
partiallyFillable: false,

test/MockPolymarket.sol

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ struct OrderStatus {
99
contract MockPolymarket {
1010
mapping(bytes32 => OrderStatus) public orderStatus;
1111
// Mock function to simulate the Polymarket order status
12+
1213
function getOrderStatus(bytes32 orderHash) public view returns (OrderStatus memory) {
13-
return orderStatus[ orderHash];
14+
return orderStatus[orderHash];
1415
}
1516

1617
function setOrderStatus(bytes32 orderHash, bool isFilledOrCancelled, uint256 remaining) public {
17-
orderStatus[orderHash] = OrderStatus({
18-
isFilledOrCancelled: isFilledOrCancelled,
19-
remaining: remaining
20-
});
18+
orderStatus[orderHash] = OrderStatus({isFilledOrCancelled: isFilledOrCancelled, remaining: remaining});
2119
}
2220
}

0 commit comments

Comments
 (0)