1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
use alloy::sol;
// Define all contract interfaces using alloy's sol! macro
sol! {
/// ERC20 token interface (for USDC)
#[sol(rpc)]
interface IERC20 {
/// Get token balance of an address
function balanceOf(address owner) external view returns (uint256);
/// Get token decimals
function decimals() external view returns (uint8);
/// Approve spending
function approve(address spender, uint256 amount) external returns (bool);
/// Check allowance
function allowance(address owner, address spender) external view returns (uint256);
/// Transfer tokens
function transfer(address to, uint256 amount) external returns (bool);
/// Transfer tokens from another address
function transferFrom(address from, address to, uint256 amount) external returns (bool);
/// Get token symbol
function symbol() external view returns (string memory);
/// Get token name
function name() external view returns (string memory);
/// Get total supply
function totalSupply() external view returns (uint256);
}
}
sol! {
/// ERC1155 token interface (for CTF tokens)
#[sol(rpc)]
interface IERC1155 {
/// Get token balance for a specific ID
function balanceOf(address owner, uint256 id) external view returns (uint256);
/// Get balances for multiple owners and IDs
function balanceOfBatch(
address[] calldata owners,
uint256[] calldata ids
) external view returns (uint256[] memory);
/// Set approval for all tokens
function setApprovalForAll(address operator, bool approved) external;
/// Check if operator is approved for all tokens
function isApprovedForAll(address owner, address operator) external view returns (bool);
/// Safe transfer a specific token
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
) external;
/// Safe batch transfer multiple tokens
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}
}
sol! {
/// Conditional Tokens Framework - main contract for split/merge/redeem
#[sol(rpc)]
interface IConditionalTokens {
/// Split collateral into outcome tokens
function splitPosition(
address collateralToken,
bytes32 parentCollectionId,
bytes32 conditionId,
uint256[] calldata partition,
uint256 amount
) external;
/// Merge outcome tokens back into collateral
function mergePositions(
address collateralToken,
bytes32 parentCollectionId,
bytes32 conditionId,
uint256[] calldata partition,
uint256 amount
) external;
/// Redeem positions after market resolution
function redeemPositions(
address collateralToken,
bytes32 parentCollectionId,
bytes32 conditionId,
uint256[] calldata indexSets
) external;
/// Get balance of a specific position
function balanceOf(address owner, uint256 positionId) external view returns (uint256);
/// Calculate position ID from collateral and collection
function getPositionId(
address collateralToken,
bytes32 collectionId
) external pure returns (uint256);
/// Get collection ID from parent, condition, and index
function getCollectionId(
bytes32 parentCollectionId,
bytes32 conditionId,
uint256 indexSet
) external view returns (bytes32);
/// Get outcome slot count for a condition
function getOutcomeSlotCount(bytes32 conditionId) external view returns (uint256);
/// Check if payout has been received
function payoutDenominator(bytes32 conditionId) external view returns (uint256);
/// Get payout numerators for a condition
function payoutNumerators(bytes32 conditionId, uint256 index) external view returns (uint256);
}
}
sol! {
/// Proxy Wallet Factory - for email/Magic accounts
#[sol(rpc)]
interface IProxyFactory {
/// Proxy transaction struct
struct ProxyTransaction {
uint8 typeCode;
address to;
uint256 value;
bytes data;
}
/// Execute batch of transactions through proxy
function proxy(
ProxyTransaction[] calldata calls
) external payable returns (bytes[] memory);
/// Derive proxy wallet address from salt
function deriveInstanceAddress(bytes32 salt) external view returns (address);
/// Check if proxy wallet is deployed
function isDeployed(bytes32 salt) external view returns (bool);
}
}
sol! {
/// Gnosis Safe interface
#[sol(rpc)]
interface ISafe {
/// Execute a transaction from the Safe
function execTransaction(
address to,
uint256 value,
bytes calldata data,
uint8 operation,
uint256 safeTxGas,
uint256 baseGas,
uint256 gasPrice,
address gasToken,
address payable refundReceiver,
bytes memory signatures
) external payable returns (bool success);
/// Get transaction hash for signing
function getTransactionHash(
address to,
uint256 value,
bytes calldata data,
uint8 operation,
uint256 safeTxGas,
uint256 baseGas,
uint256 gasPrice,
address gasToken,
address refundReceiver,
uint256 _nonce
) external view returns (bytes32);
/// Get current nonce
function nonce() external view returns (uint256);
/// Get threshold (number of required signatures)
function getThreshold() external view returns (uint256);
/// Get list of owners
function getOwners() external view returns (address[] memory);
/// Check if address is an owner
function isOwner(address owner) external view returns (bool);
}
}
sol! {
/// Safe Factory for deploying new Safe wallets
#[sol(rpc)]
interface ISafeFactory {
/// Create a new Safe proxy
function createProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) external returns (address proxy);
/// Calculate proxy address
function calculateCreateProxyWithNonceAddress(
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external view returns (address proxy);
}
}
sol! {
/// Negative Risk Adapter - for neg risk markets
#[sol(rpc)]
interface INegRiskAdapter {
/// Split position in a neg risk market
function splitPosition(
address collateralToken,
bytes32 parentCollectionId,
bytes32 conditionId,
uint256[] calldata partition,
uint256 amount
) external;
/// Merge positions in a neg risk market
function mergePositions(
address collateralToken,
bytes32 parentCollectionId,
bytes32 conditionId,
uint256[] calldata partition,
uint256 amount
) external;
}
}
sol! {
/// CTF Exchange - for trading on Polymarket
#[sol(rpc)]
interface ICTFExchange {
/// Fill an order
function fillOrder(
bytes calldata order,
uint256 fillAmount,
bytes calldata signature
) external;
/// Fill multiple orders
function fillOrders(
bytes[] calldata orders,
uint256[] calldata fillAmounts,
bytes[] calldata signatures
) external;
/// Cancel an order
function cancelOrder(bytes32 orderHash) external;
/// Cancel multiple orders
function cancelOrders(bytes32[] calldata orderHashes) external;
/// Check if order is filled
function getOrderStatus(bytes32 orderHash) external view returns (uint256 filledAmount);
/// Get maker's nonce
function nonces(address maker) external view returns (uint256);
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_interfaces_compile() {
// Just verify that all the sol! macros compile correctly
// The actual contract instances would need a provider
}
}