@polymarket/clob-client-v2 1.0.4 → 1.0.6-main.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/client.cjs +892 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +167 -0
- package/dist/client.d.ts +169 -0
- package/dist/client.js +892 -0
- package/dist/client.js.map +1 -0
- package/dist/config.cjs +37 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +17 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.js +34 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.cjs +15 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.js +10 -0
- package/dist/constants.js.map +1 -0
- package/dist/endpoints.cjs +125 -0
- package/dist/endpoints.cjs.map +1 -0
- package/dist/endpoints.js +65 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/errors.cjs +20 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +11 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +17 -0
- package/dist/errors.js.map +1 -0
- package/dist/fees/index.cjs +21 -0
- package/dist/fees/index.cjs.map +1 -0
- package/dist/fees/index.d.cts +5 -0
- package/dist/fees/index.d.ts +5 -0
- package/dist/fees/index.js +19 -0
- package/dist/fees/index.js.map +1 -0
- package/dist/headers/index.cjs +34 -0
- package/dist/headers/index.cjs.map +1 -0
- package/dist/headers/index.d.cts +9 -0
- package/dist/headers/index.d.ts +11 -0
- package/dist/headers/index.js +33 -0
- package/dist/headers/index.js.map +1 -0
- package/dist/http-helpers/index.cjs +109 -0
- package/dist/http-helpers/index.cjs.map +1 -0
- package/dist/http-helpers/index.js +101 -0
- package/dist/http-helpers/index.js.map +1 -0
- package/dist/index.cjs +35 -2600
- package/dist/index.d.cts +15 -1039
- package/dist/index.d.ts +17 -1039
- package/dist/index.js +15 -2543
- package/dist/order-builder/helpers/buildMarketOrderCreationArgs.cjs +43 -0
- package/dist/order-builder/helpers/buildMarketOrderCreationArgs.cjs.map +1 -0
- package/dist/order-builder/helpers/buildMarketOrderCreationArgs.js +42 -0
- package/dist/order-builder/helpers/buildMarketOrderCreationArgs.js.map +1 -0
- package/dist/order-builder/helpers/buildOrder.cjs +34 -0
- package/dist/order-builder/helpers/buildOrder.cjs.map +1 -0
- package/dist/order-builder/helpers/buildOrder.js +34 -0
- package/dist/order-builder/helpers/buildOrder.js.map +1 -0
- package/dist/order-builder/helpers/buildOrderCreationArgs.cjs +45 -0
- package/dist/order-builder/helpers/buildOrderCreationArgs.cjs.map +1 -0
- package/dist/order-builder/helpers/buildOrderCreationArgs.js +44 -0
- package/dist/order-builder/helpers/buildOrderCreationArgs.js.map +1 -0
- package/dist/order-builder/helpers/calculateBuyMarketPrice.cjs +24 -0
- package/dist/order-builder/helpers/calculateBuyMarketPrice.cjs.map +1 -0
- package/dist/order-builder/helpers/calculateBuyMarketPrice.js +24 -0
- package/dist/order-builder/helpers/calculateBuyMarketPrice.js.map +1 -0
- package/dist/order-builder/helpers/calculateSellMarketPrice.cjs +24 -0
- package/dist/order-builder/helpers/calculateSellMarketPrice.cjs.map +1 -0
- package/dist/order-builder/helpers/calculateSellMarketPrice.js +24 -0
- package/dist/order-builder/helpers/calculateSellMarketPrice.js.map +1 -0
- package/dist/order-builder/helpers/createExchangeV3OrderFromAmounts.cjs +31 -0
- package/dist/order-builder/helpers/createExchangeV3OrderFromAmounts.cjs.map +1 -0
- package/dist/order-builder/helpers/createExchangeV3OrderFromAmounts.js +31 -0
- package/dist/order-builder/helpers/createExchangeV3OrderFromAmounts.js.map +1 -0
- package/dist/order-builder/helpers/createMarketOrder.cjs +34 -0
- package/dist/order-builder/helpers/createMarketOrder.cjs.map +1 -0
- package/dist/order-builder/helpers/createMarketOrder.js +34 -0
- package/dist/order-builder/helpers/createMarketOrder.js.map +1 -0
- package/dist/order-builder/helpers/createOrder.cjs +34 -0
- package/dist/order-builder/helpers/createOrder.cjs.map +1 -0
- package/dist/order-builder/helpers/createOrder.js +34 -0
- package/dist/order-builder/helpers/createOrder.js.map +1 -0
- package/dist/order-builder/helpers/getMarketOrderRawAmounts.cjs +36 -0
- package/dist/order-builder/helpers/getMarketOrderRawAmounts.cjs.map +1 -0
- package/dist/order-builder/helpers/getMarketOrderRawAmounts.js +36 -0
- package/dist/order-builder/helpers/getMarketOrderRawAmounts.js.map +1 -0
- package/dist/order-builder/helpers/getOrderRawAmounts.cjs +36 -0
- package/dist/order-builder/helpers/getOrderRawAmounts.cjs.map +1 -0
- package/dist/order-builder/helpers/getOrderRawAmounts.js +36 -0
- package/dist/order-builder/helpers/getOrderRawAmounts.js.map +1 -0
- package/dist/order-builder/helpers/roundingConfig.cjs +28 -0
- package/dist/order-builder/helpers/roundingConfig.cjs.map +1 -0
- package/dist/order-builder/helpers/roundingConfig.js +27 -0
- package/dist/order-builder/helpers/roundingConfig.js.map +1 -0
- package/dist/order-builder/index.d.ts +1 -0
- package/dist/order-builder/orderBuilder.cjs +58 -0
- package/dist/order-builder/orderBuilder.cjs.map +1 -0
- package/dist/order-builder/orderBuilder.d.cts +42 -0
- package/dist/order-builder/orderBuilder.d.ts +44 -0
- package/dist/order-builder/orderBuilder.js +58 -0
- package/dist/order-builder/orderBuilder.js.map +1 -0
- package/dist/order-utils/exchangeOrderBuilderV1.cjs +128 -0
- package/dist/order-utils/exchangeOrderBuilderV1.cjs.map +1 -0
- package/dist/order-utils/exchangeOrderBuilderV1.d.ts +2 -0
- package/dist/order-utils/exchangeOrderBuilderV1.js +127 -0
- package/dist/order-utils/exchangeOrderBuilderV1.js.map +1 -0
- package/dist/order-utils/exchangeOrderBuilderV2.cjs +196 -0
- package/dist/order-utils/exchangeOrderBuilderV2.cjs.map +1 -0
- package/dist/order-utils/exchangeOrderBuilderV2.d.ts +2 -0
- package/dist/order-utils/exchangeOrderBuilderV2.js +194 -0
- package/dist/order-utils/exchangeOrderBuilderV2.js.map +1 -0
- package/dist/order-utils/index.d.ts +7 -0
- package/dist/order-utils/model/ctfExchangeV1TypedData.cjs +60 -0
- package/dist/order-utils/model/ctfExchangeV1TypedData.cjs.map +1 -0
- package/dist/order-utils/model/ctfExchangeV1TypedData.js +57 -0
- package/dist/order-utils/model/ctfExchangeV1TypedData.js.map +1 -0
- package/dist/order-utils/model/ctfExchangeV2TypedData.cjs +58 -0
- package/dist/order-utils/model/ctfExchangeV2TypedData.cjs.map +1 -0
- package/dist/order-utils/model/ctfExchangeV2TypedData.js +54 -0
- package/dist/order-utils/model/ctfExchangeV2TypedData.js.map +1 -0
- package/dist/order-utils/model/eip712.cjs +24 -0
- package/dist/order-utils/model/eip712.cjs.map +1 -0
- package/dist/order-utils/model/eip712.d.cts +9 -0
- package/dist/order-utils/model/eip712.d.ts +9 -0
- package/dist/order-utils/model/eip712.js +23 -0
- package/dist/order-utils/model/eip712.js.map +1 -0
- package/dist/order-utils/model/order.d.cts +5 -0
- package/dist/order-utils/model/order.d.ts +5 -0
- package/dist/order-utils/model/orderDataV1.d.cts +68 -0
- package/dist/order-utils/model/orderDataV1.d.ts +69 -0
- package/dist/order-utils/model/orderDataV2.d.cts +68 -0
- package/dist/order-utils/model/orderDataV2.d.ts +69 -0
- package/dist/order-utils/model/side.cjs +11 -0
- package/dist/order-utils/model/side.cjs.map +1 -0
- package/dist/order-utils/model/side.d.cts +8 -0
- package/dist/order-utils/model/side.d.ts +8 -0
- package/dist/order-utils/model/side.js +10 -0
- package/dist/order-utils/model/side.js.map +1 -0
- package/dist/order-utils/model/signatureTypeV1.cjs +21 -0
- package/dist/order-utils/model/signatureTypeV1.cjs.map +1 -0
- package/dist/order-utils/model/signatureTypeV1.d.cts +18 -0
- package/dist/order-utils/model/signatureTypeV1.d.ts +18 -0
- package/dist/order-utils/model/signatureTypeV1.js +20 -0
- package/dist/order-utils/model/signatureTypeV1.js.map +1 -0
- package/dist/order-utils/model/signatureTypeV2.cjs +25 -0
- package/dist/order-utils/model/signatureTypeV2.cjs.map +1 -0
- package/dist/order-utils/model/signatureTypeV2.d.cts +22 -0
- package/dist/order-utils/model/signatureTypeV2.d.ts +22 -0
- package/dist/order-utils/model/signatureTypeV2.js +24 -0
- package/dist/order-utils/model/signatureTypeV2.js.map +1 -0
- package/dist/order-utils/utils.cjs +9 -0
- package/dist/order-utils/utils.cjs.map +1 -0
- package/dist/order-utils/utils.js +8 -0
- package/dist/order-utils/utils.js.map +1 -0
- package/dist/signing/constants.cjs +7 -0
- package/dist/signing/constants.cjs.map +1 -0
- package/dist/signing/constants.js +6 -0
- package/dist/signing/constants.js.map +1 -0
- package/dist/signing/eip712.cjs +51 -0
- package/dist/signing/eip712.cjs.map +1 -0
- package/dist/signing/eip712.d.ts +2 -0
- package/dist/signing/eip712.js +51 -0
- package/dist/signing/eip712.js.map +1 -0
- package/dist/signing/hmac.cjs +40 -0
- package/dist/signing/hmac.cjs.map +1 -0
- package/dist/signing/hmac.js +39 -0
- package/dist/signing/hmac.js.map +1 -0
- package/dist/signing/index.d.ts +2 -0
- package/dist/signing/signer.cjs +41 -0
- package/dist/signing/signer.cjs.map +1 -0
- package/dist/signing/signer.d.cts +17 -0
- package/dist/signing/signer.d.ts +17 -0
- package/dist/signing/signer.js +39 -0
- package/dist/signing/signer.js.map +1 -0
- package/dist/types/clob.cjs +35 -0
- package/dist/types/clob.cjs.map +1 -0
- package/dist/types/clob.d.cts +427 -0
- package/dist/types/clob.d.ts +427 -0
- package/dist/types/clob.js +32 -0
- package/dist/types/clob.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/ordersV1.cjs +29 -0
- package/dist/types/ordersV1.cjs.map +1 -0
- package/dist/types/ordersV1.d.cts +115 -0
- package/dist/types/ordersV1.d.ts +116 -0
- package/dist/types/ordersV1.js +28 -0
- package/dist/types/ordersV1.js.map +1 -0
- package/dist/types/ordersV2.cjs +30 -0
- package/dist/types/ordersV2.cjs.map +1 -0
- package/dist/types/ordersV2.d.cts +113 -0
- package/dist/types/ordersV2.d.ts +114 -0
- package/dist/types/ordersV2.js +29 -0
- package/dist/types/ordersV2.js.map +1 -0
- package/dist/types/ordersV3.d.cts +43 -0
- package/dist/types/ordersV3.d.ts +43 -0
- package/dist/types/unifiedOrder.cjs +10 -0
- package/dist/types/unifiedOrder.cjs.map +1 -0
- package/dist/types/unifiedOrder.d.cts +56 -0
- package/dist/types/unifiedOrder.d.ts +57 -0
- package/dist/types/unifiedOrder.js +9 -0
- package/dist/types/unifiedOrder.js.map +1 -0
- package/dist/utilities.cjs +50 -0
- package/dist/utilities.cjs.map +1 -0
- package/dist/utilities.js +43 -0
- package/dist/utilities.js.map +1 -0
- package/package.json +3 -3
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { bytes32Zero } from "../constants.js";
|
|
2
|
+
import { getSignerAddress, signTypedDataWithSigner } from "../signing/signer.js";
|
|
3
|
+
import { EIP712_DOMAIN } from "./model/eip712.js";
|
|
4
|
+
import { generateOrderSalt } from "./utils.js";
|
|
5
|
+
import { CTF_EXCHANGE_V2_DOMAIN_NAME, CTF_EXCHANGE_V2_DOMAIN_VERSION, CTF_EXCHANGE_V2_ORDER_STRUCT, CTF_EXCHANGE_V3_DOMAIN_VERSION } from "./model/ctfExchangeV2TypedData.js";
|
|
6
|
+
import { SignatureTypeV2 } from "./model/signatureTypeV2.js";
|
|
7
|
+
import { encodeAbiParameters, hashTypedData, keccak256, toHex } from "viem";
|
|
8
|
+
|
|
9
|
+
//#region src/order-utils/exchangeOrderBuilderV2.ts
|
|
10
|
+
const ORDER_TYPE_STRING = "Order(uint256 salt,address maker,address signer,uint256 tokenId,uint256 makerAmount,uint256 takerAmount,uint8 side,uint8 signatureType,uint256 timestamp,bytes32 metadata,bytes32 builder)";
|
|
11
|
+
const ORDER_TYPE_HASH = keccak256(toHex(ORDER_TYPE_STRING));
|
|
12
|
+
const DOMAIN_TYPE_HASH = keccak256(toHex("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"));
|
|
13
|
+
const TYPED_DATA_SIGN_STRUCT = [
|
|
14
|
+
{
|
|
15
|
+
name: "contents",
|
|
16
|
+
type: "Order"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "name",
|
|
20
|
+
type: "string"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "version",
|
|
24
|
+
type: "string"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "chainId",
|
|
28
|
+
type: "uint256"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "verifyingContract",
|
|
32
|
+
type: "address"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "salt",
|
|
36
|
+
type: "bytes32"
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
const CTF_EXCHANGE_NAME_HASH = keccak256(toHex(CTF_EXCHANGE_V2_DOMAIN_NAME));
|
|
40
|
+
var ExchangeOrderBuilderV2 = class {
|
|
41
|
+
appDomainSep;
|
|
42
|
+
constructor(contractAddress, chainId, signer, generateSalt = generateOrderSalt, domainVersion = CTF_EXCHANGE_V2_DOMAIN_VERSION) {
|
|
43
|
+
this.contractAddress = contractAddress;
|
|
44
|
+
this.chainId = chainId;
|
|
45
|
+
this.signer = signer;
|
|
46
|
+
this.generateSalt = generateSalt;
|
|
47
|
+
this.domainVersion = domainVersion;
|
|
48
|
+
this.appDomainSep = keccak256(encodeAbiParameters([
|
|
49
|
+
{ type: "bytes32" },
|
|
50
|
+
{ type: "bytes32" },
|
|
51
|
+
{ type: "bytes32" },
|
|
52
|
+
{ type: "uint256" },
|
|
53
|
+
{ type: "address" }
|
|
54
|
+
], [
|
|
55
|
+
DOMAIN_TYPE_HASH,
|
|
56
|
+
CTF_EXCHANGE_NAME_HASH,
|
|
57
|
+
keccak256(toHex(domainVersion)),
|
|
58
|
+
BigInt(chainId),
|
|
59
|
+
contractAddress
|
|
60
|
+
]));
|
|
61
|
+
}
|
|
62
|
+
async buildSignedOrder(orderData) {
|
|
63
|
+
const order = await this.buildOrder(orderData);
|
|
64
|
+
const orderTypedData = this.buildOrderTypedData(order);
|
|
65
|
+
const orderSignature = await this.buildOrderSignature(orderTypedData);
|
|
66
|
+
return {
|
|
67
|
+
...order,
|
|
68
|
+
signature: orderSignature
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async buildOrder({ maker, tokenId, makerAmount, takerAmount, side, signer, signatureType, timestamp, metadata, builder, expiration }) {
|
|
72
|
+
if (!signer) signer = maker;
|
|
73
|
+
if (signatureType !== SignatureTypeV2.POLY_1271) {
|
|
74
|
+
const signerAddress = await getSignerAddress(this.signer);
|
|
75
|
+
if (signer !== signerAddress) throw new Error("signer does not match");
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
salt: this.generateSalt(),
|
|
79
|
+
maker,
|
|
80
|
+
signer,
|
|
81
|
+
tokenId,
|
|
82
|
+
makerAmount,
|
|
83
|
+
takerAmount,
|
|
84
|
+
side,
|
|
85
|
+
signatureType: signatureType ?? SignatureTypeV2.EOA,
|
|
86
|
+
metadata: metadata ?? bytes32Zero,
|
|
87
|
+
builder: builder ?? bytes32Zero,
|
|
88
|
+
timestamp: timestamp ?? Date.now().toString(),
|
|
89
|
+
expiration: expiration ?? "0"
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
buildOrderTypedData(order) {
|
|
93
|
+
return {
|
|
94
|
+
primaryType: "Order",
|
|
95
|
+
types: {
|
|
96
|
+
EIP712Domain: EIP712_DOMAIN,
|
|
97
|
+
Order: CTF_EXCHANGE_V2_ORDER_STRUCT
|
|
98
|
+
},
|
|
99
|
+
domain: {
|
|
100
|
+
name: CTF_EXCHANGE_V2_DOMAIN_NAME,
|
|
101
|
+
version: this.domainVersion,
|
|
102
|
+
chainId: this.chainId,
|
|
103
|
+
verifyingContract: this.contractAddress
|
|
104
|
+
},
|
|
105
|
+
message: {
|
|
106
|
+
salt: order.salt,
|
|
107
|
+
maker: order.maker,
|
|
108
|
+
signer: order.signer,
|
|
109
|
+
tokenId: order.tokenId,
|
|
110
|
+
makerAmount: order.makerAmount,
|
|
111
|
+
takerAmount: order.takerAmount,
|
|
112
|
+
timestamp: order.timestamp,
|
|
113
|
+
side: order.side === "BUY" ? 0 : 1,
|
|
114
|
+
signatureType: order.signatureType,
|
|
115
|
+
metadata: order.metadata,
|
|
116
|
+
builder: order.builder
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async buildOrderSignature(typedData) {
|
|
121
|
+
delete typedData.types.EIP712Domain;
|
|
122
|
+
const msg = typedData.message;
|
|
123
|
+
if (msg.signatureType !== SignatureTypeV2.POLY_1271) return signTypedDataWithSigner({
|
|
124
|
+
signer: this.signer,
|
|
125
|
+
domain: typedData.domain,
|
|
126
|
+
types: typedData.types,
|
|
127
|
+
value: typedData.message,
|
|
128
|
+
primaryType: typedData.primaryType
|
|
129
|
+
});
|
|
130
|
+
const contentsHash = keccak256(encodeAbiParameters([
|
|
131
|
+
{ type: "bytes32" },
|
|
132
|
+
{ type: "uint256" },
|
|
133
|
+
{ type: "address" },
|
|
134
|
+
{ type: "address" },
|
|
135
|
+
{ type: "uint256" },
|
|
136
|
+
{ type: "uint256" },
|
|
137
|
+
{ type: "uint256" },
|
|
138
|
+
{ type: "uint8" },
|
|
139
|
+
{ type: "uint8" },
|
|
140
|
+
{ type: "uint256" },
|
|
141
|
+
{ type: "bytes32" },
|
|
142
|
+
{ type: "bytes32" }
|
|
143
|
+
], [
|
|
144
|
+
ORDER_TYPE_HASH,
|
|
145
|
+
BigInt(msg.salt),
|
|
146
|
+
msg.maker,
|
|
147
|
+
msg.signer,
|
|
148
|
+
BigInt(msg.tokenId),
|
|
149
|
+
BigInt(msg.makerAmount),
|
|
150
|
+
BigInt(msg.takerAmount),
|
|
151
|
+
msg.side,
|
|
152
|
+
msg.signatureType,
|
|
153
|
+
BigInt(msg.timestamp),
|
|
154
|
+
msg.metadata,
|
|
155
|
+
msg.builder
|
|
156
|
+
]));
|
|
157
|
+
const innerSig = await signTypedDataWithSigner({
|
|
158
|
+
signer: this.signer,
|
|
159
|
+
domain: {
|
|
160
|
+
name: CTF_EXCHANGE_V2_DOMAIN_NAME,
|
|
161
|
+
version: this.domainVersion,
|
|
162
|
+
chainId: this.chainId,
|
|
163
|
+
verifyingContract: this.contractAddress
|
|
164
|
+
},
|
|
165
|
+
types: {
|
|
166
|
+
TypedDataSign: TYPED_DATA_SIGN_STRUCT,
|
|
167
|
+
Order: CTF_EXCHANGE_V2_ORDER_STRUCT
|
|
168
|
+
},
|
|
169
|
+
primaryType: "TypedDataSign",
|
|
170
|
+
value: {
|
|
171
|
+
contents: typedData.message,
|
|
172
|
+
name: "DepositWallet",
|
|
173
|
+
version: "1",
|
|
174
|
+
chainId: this.chainId,
|
|
175
|
+
verifyingContract: msg.signer,
|
|
176
|
+
salt: bytes32Zero
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
const lenHex = 186 .toString(16).padStart(4, "0");
|
|
180
|
+
return `0x${innerSig.slice(2)}${this.appDomainSep.slice(2)}${contentsHash.slice(2)}${toHex(ORDER_TYPE_STRING).slice(2)}${lenHex}`;
|
|
181
|
+
}
|
|
182
|
+
buildOrderHash(orderTypedData) {
|
|
183
|
+
return hashTypedData(orderTypedData);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
var ExchangeOrderBuilderV3 = class extends ExchangeOrderBuilderV2 {
|
|
187
|
+
constructor(contractAddress, chainId, signer, generateSalt = generateOrderSalt) {
|
|
188
|
+
super(contractAddress, chainId, signer, generateSalt, CTF_EXCHANGE_V3_DOMAIN_VERSION);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
export { ExchangeOrderBuilderV2, ExchangeOrderBuilderV3 };
|
|
194
|
+
//# sourceMappingURL=exchangeOrderBuilderV2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exchangeOrderBuilderV2.js","names":["contractAddress: string","chainId: number","signer: ClobSigner"],"sources":["../../src/order-utils/exchangeOrderBuilderV2.ts"],"sourcesContent":["import { type Address, encodeAbiParameters, hashTypedData, keccak256, toHex } from \"viem\";\n\nimport { bytes32Zero } from \"../constants.js\";\nimport { type ClobSigner, getSignerAddress, signTypedDataWithSigner } from \"../signing/signer.js\";\nimport {\n\tCTF_EXCHANGE_V2_DOMAIN_NAME,\n\tCTF_EXCHANGE_V2_DOMAIN_VERSION,\n\tCTF_EXCHANGE_V2_ORDER_STRUCT,\n\tCTF_EXCHANGE_V3_DOMAIN_VERSION,\n} from \"./model/ctfExchangeV2TypedData.js\";\nimport { EIP712_DOMAIN, type EIP712TypedData } from \"./model/eip712.js\";\nimport type { OrderHash, OrderSignature } from \"./model/order.js\";\nimport type { OrderDataV2, OrderV2, SignedOrderV2 } from \"./model/orderDataV2.js\";\nimport { SignatureTypeV2 } from \"./model/signatureTypeV2.js\";\nimport { generateOrderSalt } from \"./utils.js\";\n\nconst ORDER_TYPE_STRING =\n\t\"Order(uint256 salt,address maker,address signer,uint256 tokenId,uint256 makerAmount,uint256 takerAmount,uint8 side,uint8 signatureType,uint256 timestamp,bytes32 metadata,bytes32 builder)\";\n\nconst ORDER_TYPE_HASH = keccak256(toHex(ORDER_TYPE_STRING));\n\nconst DOMAIN_TYPE_HASH = keccak256(\n\ttoHex(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\"),\n);\n\nconst TYPED_DATA_SIGN_STRUCT = [\n\t{ name: \"contents\", type: \"Order\" },\n\t{ name: \"name\", type: \"string\" },\n\t{ name: \"version\", type: \"string\" },\n\t{ name: \"chainId\", type: \"uint256\" },\n\t{ name: \"verifyingContract\", type: \"address\" },\n\t{ name: \"salt\", type: \"bytes32\" },\n];\n\nconst CTF_EXCHANGE_NAME_HASH = keccak256(toHex(CTF_EXCHANGE_V2_DOMAIN_NAME));\n\nexport class ExchangeOrderBuilderV2 {\n\tprivate readonly appDomainSep: `0x${string}`;\n\n\tconstructor(\n\t\tprivate readonly contractAddress: string,\n\t\tprivate readonly chainId: number,\n\t\tprivate readonly signer: ClobSigner,\n\t\tprivate readonly generateSalt = generateOrderSalt,\n\t\tprivate readonly domainVersion = CTF_EXCHANGE_V2_DOMAIN_VERSION,\n\t) {\n\t\tconst exchangeVersionHash = keccak256(toHex(domainVersion));\n\t\tthis.appDomainSep = keccak256(\n\t\t\tencodeAbiParameters(\n\t\t\t\t[\n\t\t\t\t\t{ type: \"bytes32\" },\n\t\t\t\t\t{ type: \"bytes32\" },\n\t\t\t\t\t{ type: \"bytes32\" },\n\t\t\t\t\t{ type: \"uint256\" },\n\t\t\t\t\t{ type: \"address\" },\n\t\t\t\t],\n\t\t\t\t[\n\t\t\t\t\tDOMAIN_TYPE_HASH,\n\t\t\t\t\tCTF_EXCHANGE_NAME_HASH,\n\t\t\t\t\texchangeVersionHash,\n\t\t\t\t\tBigInt(chainId),\n\t\t\t\t\tcontractAddress as Address,\n\t\t\t\t],\n\t\t\t),\n\t\t);\n\t}\n\n\tasync buildSignedOrder(orderData: OrderDataV2): Promise<SignedOrderV2> {\n\t\tconst order = await this.buildOrder(orderData);\n\t\tconst orderTypedData = this.buildOrderTypedData(order);\n\t\tconst orderSignature = await this.buildOrderSignature(orderTypedData);\n\n\t\treturn {\n\t\t\t...order,\n\t\t\tsignature: orderSignature,\n\t\t} as SignedOrderV2;\n\t}\n\n\tasync buildOrder({\n\t\tmaker,\n\t\ttokenId,\n\t\tmakerAmount,\n\t\ttakerAmount,\n\t\tside,\n\t\tsigner,\n\t\tsignatureType,\n\t\ttimestamp,\n\t\tmetadata,\n\t\tbuilder,\n\t\texpiration,\n\t}: OrderDataV2): Promise<OrderV2> {\n\t\tif (!signer) {\n\t\t\tsigner = maker;\n\t\t}\n\n\t\t// For POLY_1271 (deposit wallets), signer is the wallet contract — skip EOA address check\n\t\tif (signatureType !== SignatureTypeV2.POLY_1271) {\n\t\t\tconst signerAddress = await getSignerAddress(this.signer);\n\t\t\tif (signer !== signerAddress) {\n\t\t\t\tthrow new Error(\"signer does not match\");\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tsalt: this.generateSalt(),\n\t\t\tmaker,\n\t\t\tsigner,\n\t\t\ttokenId,\n\t\t\tmakerAmount,\n\t\t\ttakerAmount,\n\t\t\tside,\n\t\t\tsignatureType: signatureType ?? SignatureTypeV2.EOA,\n\t\t\tmetadata: metadata ?? bytes32Zero,\n\t\t\tbuilder: builder ?? bytes32Zero,\n\t\t\ttimestamp: timestamp ?? Date.now().toString(),\n\t\t\texpiration: expiration ?? \"0\",\n\t\t};\n\t}\n\n\tbuildOrderTypedData(order: OrderV2): EIP712TypedData {\n\t\treturn {\n\t\t\tprimaryType: \"Order\",\n\t\t\ttypes: {\n\t\t\t\tEIP712Domain: EIP712_DOMAIN,\n\t\t\t\tOrder: CTF_EXCHANGE_V2_ORDER_STRUCT,\n\t\t\t},\n\t\t\tdomain: {\n\t\t\t\tname: CTF_EXCHANGE_V2_DOMAIN_NAME,\n\t\t\t\tversion: this.domainVersion,\n\t\t\t\tchainId: this.chainId,\n\t\t\t\tverifyingContract: this.contractAddress,\n\t\t\t},\n\t\t\tmessage: {\n\t\t\t\tsalt: order.salt,\n\t\t\t\tmaker: order.maker,\n\t\t\t\tsigner: order.signer,\n\t\t\t\ttokenId: order.tokenId,\n\t\t\t\tmakerAmount: order.makerAmount,\n\t\t\t\ttakerAmount: order.takerAmount,\n\t\t\t\ttimestamp: order.timestamp,\n\t\t\t\tside: order.side === \"BUY\" ? 0 : 1,\n\t\t\t\tsignatureType: order.signatureType,\n\t\t\t\tmetadata: order.metadata,\n\t\t\t\tbuilder: order.builder,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync buildOrderSignature(typedData: EIP712TypedData): Promise<OrderSignature> {\n\t\tdelete typedData.types.EIP712Domain;\n\n\t\tconst msg = typedData.message;\n\n\t\tif ((msg.signatureType as number) !== SignatureTypeV2.POLY_1271) {\n\t\t\treturn signTypedDataWithSigner({\n\t\t\t\tsigner: this.signer,\n\t\t\t\tdomain: typedData.domain,\n\t\t\t\ttypes: typedData.types,\n\t\t\t\tvalue: typedData.message,\n\t\t\t\tprimaryType: typedData.primaryType,\n\t\t\t});\n\t\t}\n\n\t\tconst contentsHash = keccak256(\n\t\t\tencodeAbiParameters(\n\t\t\t\t[\n\t\t\t\t\t{ type: \"bytes32\" },\n\t\t\t\t\t{ type: \"uint256\" },\n\t\t\t\t\t{ type: \"address\" },\n\t\t\t\t\t{ type: \"address\" },\n\t\t\t\t\t{ type: \"uint256\" },\n\t\t\t\t\t{ type: \"uint256\" },\n\t\t\t\t\t{ type: \"uint256\" },\n\t\t\t\t\t{ type: \"uint8\" },\n\t\t\t\t\t{ type: \"uint8\" },\n\t\t\t\t\t{ type: \"uint256\" },\n\t\t\t\t\t{ type: \"bytes32\" },\n\t\t\t\t\t{ type: \"bytes32\" },\n\t\t\t\t],\n\t\t\t\t[\n\t\t\t\t\tORDER_TYPE_HASH,\n\t\t\t\t\tBigInt(msg.salt as string),\n\t\t\t\t\tmsg.maker as Address,\n\t\t\t\t\tmsg.signer as Address,\n\t\t\t\t\tBigInt(msg.tokenId as string),\n\t\t\t\t\tBigInt(msg.makerAmount as string),\n\t\t\t\t\tBigInt(msg.takerAmount as string),\n\t\t\t\t\tmsg.side as number,\n\t\t\t\t\tmsg.signatureType as number,\n\t\t\t\t\tBigInt(msg.timestamp as string),\n\t\t\t\t\tmsg.metadata as `0x${string}`,\n\t\t\t\t\tmsg.builder as `0x${string}`,\n\t\t\t\t],\n\t\t\t),\n\t\t);\n\n\t\tconst innerSig = await signTypedDataWithSigner({\n\t\t\tsigner: this.signer,\n\t\t\tdomain: {\n\t\t\t\tname: CTF_EXCHANGE_V2_DOMAIN_NAME,\n\t\t\t\tversion: this.domainVersion,\n\t\t\t\tchainId: this.chainId,\n\t\t\t\tverifyingContract: this.contractAddress,\n\t\t\t},\n\t\t\ttypes: {\n\t\t\t\tTypedDataSign: TYPED_DATA_SIGN_STRUCT,\n\t\t\t\tOrder: CTF_EXCHANGE_V2_ORDER_STRUCT,\n\t\t\t},\n\t\t\tprimaryType: \"TypedDataSign\",\n\t\t\tvalue: {\n\t\t\t\tcontents: typedData.message,\n\t\t\t\tname: \"DepositWallet\",\n\t\t\t\tversion: \"1\",\n\t\t\t\tchainId: this.chainId,\n\t\t\t\tverifyingContract: msg.signer,\n\t\t\t\tsalt: bytes32Zero,\n\t\t\t},\n\t\t});\n\n\t\t// innerSig (65) || appDomainSep (32) || contentsHash (32) || contentsType || uint16_BE(len)\n\t\tconst ctLen = ORDER_TYPE_STRING.length;\n\t\tconst lenHex = ctLen.toString(16).padStart(4, \"0\");\n\t\treturn `0x${innerSig.slice(2)}${this.appDomainSep.slice(2)}${contentsHash.slice(2)}${toHex(ORDER_TYPE_STRING).slice(2)}${lenHex}`;\n\t}\n\n\tbuildOrderHash(orderTypedData: EIP712TypedData): OrderHash {\n\t\treturn hashTypedData(orderTypedData);\n\t}\n}\n\nexport class ExchangeOrderBuilderV3 extends ExchangeOrderBuilderV2 {\n\tconstructor(\n\t\tcontractAddress: string,\n\t\tchainId: number,\n\t\tsigner: ClobSigner,\n\t\tgenerateSalt = generateOrderSalt,\n\t) {\n\t\tsuper(contractAddress, chainId, signer, generateSalt, CTF_EXCHANGE_V3_DOMAIN_VERSION);\n\t}\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { EIP712Object, EIP712ObjectValue } from "./model/eip712.js";
|
|
2
|
+
import { SignatureTypeV1 } from "./model/signatureTypeV1.js";
|
|
3
|
+
import { OrderV1, SignedOrderV1 } from "./model/orderDataV1.js";
|
|
4
|
+
import "./exchangeOrderBuilderV1.js";
|
|
5
|
+
import { SignatureTypeV2 } from "./model/signatureTypeV2.js";
|
|
6
|
+
import { OrderV2, SignedOrderV2 } from "./model/orderDataV2.js";
|
|
7
|
+
import "./exchangeOrderBuilderV2.js";
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/order-utils/model/ctfExchangeV1TypedData.ts
|
|
3
|
+
const CTF_EXCHANGE_V1_DOMAIN_NAME = "Polymarket CTF Exchange";
|
|
4
|
+
const CTF_EXCHANGE_V1_DOMAIN_VERSION = "1";
|
|
5
|
+
const CTF_EXCHANGE_V1_ORDER_STRUCT = [
|
|
6
|
+
{
|
|
7
|
+
name: "salt",
|
|
8
|
+
type: "uint256"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: "maker",
|
|
12
|
+
type: "address"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "signer",
|
|
16
|
+
type: "address"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "taker",
|
|
20
|
+
type: "address"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "tokenId",
|
|
24
|
+
type: "uint256"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "makerAmount",
|
|
28
|
+
type: "uint256"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "takerAmount",
|
|
32
|
+
type: "uint256"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "expiration",
|
|
36
|
+
type: "uint256"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "nonce",
|
|
40
|
+
type: "uint256"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "feeRateBps",
|
|
44
|
+
type: "uint256"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "side",
|
|
48
|
+
type: "uint8"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "signatureType",
|
|
52
|
+
type: "uint8"
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
exports.CTF_EXCHANGE_V1_DOMAIN_NAME = CTF_EXCHANGE_V1_DOMAIN_NAME;
|
|
58
|
+
exports.CTF_EXCHANGE_V1_DOMAIN_VERSION = CTF_EXCHANGE_V1_DOMAIN_VERSION;
|
|
59
|
+
exports.CTF_EXCHANGE_V1_ORDER_STRUCT = CTF_EXCHANGE_V1_ORDER_STRUCT;
|
|
60
|
+
//# sourceMappingURL=ctfExchangeV1TypedData.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ctfExchangeV1TypedData.cjs","names":[],"sources":["../../../src/order-utils/model/ctfExchangeV1TypedData.ts"],"sourcesContent":["export const CTF_EXCHANGE_V1_DOMAIN_NAME = \"Polymarket CTF Exchange\";\n\nexport const CTF_EXCHANGE_V1_DOMAIN_VERSION = \"1\";\n\nexport const CTF_EXCHANGE_V1_ORDER_STRUCT = [\n\t{ name: \"salt\", type: \"uint256\" },\n\t{ name: \"maker\", type: \"address\" },\n\t{ name: \"signer\", type: \"address\" },\n\t{ name: \"taker\", type: \"address\" },\n\t{ name: \"tokenId\", type: \"uint256\" },\n\t{ name: \"makerAmount\", type: \"uint256\" },\n\t{ name: \"takerAmount\", type: \"uint256\" },\n\t{ name: \"expiration\", type: \"uint256\" },\n\t{ name: \"nonce\", type: \"uint256\" },\n\t{ name: \"feeRateBps\", type: \"uint256\" },\n\t{ name: \"side\", type: \"uint8\" },\n\t{ name: \"signatureType\", type: \"uint8\" },\n];\n"],"mappings":";;AAAA,MAAa,8BAA8B;AAE3C,MAAa,iCAAiC;AAE9C,MAAa,+BAA+B;CAC3C;EAAE,MAAM;EAAQ,MAAM;EAAW;CACjC;EAAE,MAAM;EAAS,MAAM;EAAW;CAClC;EAAE,MAAM;EAAU,MAAM;EAAW;CACnC;EAAE,MAAM;EAAS,MAAM;EAAW;CAClC;EAAE,MAAM;EAAW,MAAM;EAAW;CACpC;EAAE,MAAM;EAAe,MAAM;EAAW;CACxC;EAAE,MAAM;EAAe,MAAM;EAAW;CACxC;EAAE,MAAM;EAAc,MAAM;EAAW;CACvC;EAAE,MAAM;EAAS,MAAM;EAAW;CAClC;EAAE,MAAM;EAAc,MAAM;EAAW;CACvC;EAAE,MAAM;EAAQ,MAAM;EAAS;CAC/B;EAAE,MAAM;EAAiB,MAAM;EAAS;CACxC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//#region src/order-utils/model/ctfExchangeV1TypedData.ts
|
|
2
|
+
const CTF_EXCHANGE_V1_DOMAIN_NAME = "Polymarket CTF Exchange";
|
|
3
|
+
const CTF_EXCHANGE_V1_DOMAIN_VERSION = "1";
|
|
4
|
+
const CTF_EXCHANGE_V1_ORDER_STRUCT = [
|
|
5
|
+
{
|
|
6
|
+
name: "salt",
|
|
7
|
+
type: "uint256"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
name: "maker",
|
|
11
|
+
type: "address"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: "signer",
|
|
15
|
+
type: "address"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "taker",
|
|
19
|
+
type: "address"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "tokenId",
|
|
23
|
+
type: "uint256"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "makerAmount",
|
|
27
|
+
type: "uint256"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "takerAmount",
|
|
31
|
+
type: "uint256"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "expiration",
|
|
35
|
+
type: "uint256"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "nonce",
|
|
39
|
+
type: "uint256"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: "feeRateBps",
|
|
43
|
+
type: "uint256"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "side",
|
|
47
|
+
type: "uint8"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "signatureType",
|
|
51
|
+
type: "uint8"
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { CTF_EXCHANGE_V1_DOMAIN_NAME, CTF_EXCHANGE_V1_DOMAIN_VERSION, CTF_EXCHANGE_V1_ORDER_STRUCT };
|
|
57
|
+
//# sourceMappingURL=ctfExchangeV1TypedData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ctfExchangeV1TypedData.js","names":[],"sources":["../../../src/order-utils/model/ctfExchangeV1TypedData.ts"],"sourcesContent":["export const CTF_EXCHANGE_V1_DOMAIN_NAME = \"Polymarket CTF Exchange\";\n\nexport const CTF_EXCHANGE_V1_DOMAIN_VERSION = \"1\";\n\nexport const CTF_EXCHANGE_V1_ORDER_STRUCT = [\n\t{ name: \"salt\", type: \"uint256\" },\n\t{ name: \"maker\", type: \"address\" },\n\t{ name: \"signer\", type: \"address\" },\n\t{ name: \"taker\", type: \"address\" },\n\t{ name: \"tokenId\", type: \"uint256\" },\n\t{ name: \"makerAmount\", type: \"uint256\" },\n\t{ name: \"takerAmount\", type: \"uint256\" },\n\t{ name: \"expiration\", type: \"uint256\" },\n\t{ name: \"nonce\", type: \"uint256\" },\n\t{ name: \"feeRateBps\", type: \"uint256\" },\n\t{ name: \"side\", type: \"uint8\" },\n\t{ name: \"signatureType\", type: \"uint8\" },\n];\n"],"mappings":";AAAA,MAAa,8BAA8B;AAE3C,MAAa,iCAAiC;AAE9C,MAAa,+BAA+B;CAC3C;EAAE,MAAM;EAAQ,MAAM;EAAW;CACjC;EAAE,MAAM;EAAS,MAAM;EAAW;CAClC;EAAE,MAAM;EAAU,MAAM;EAAW;CACnC;EAAE,MAAM;EAAS,MAAM;EAAW;CAClC;EAAE,MAAM;EAAW,MAAM;EAAW;CACpC;EAAE,MAAM;EAAe,MAAM;EAAW;CACxC;EAAE,MAAM;EAAe,MAAM;EAAW;CACxC;EAAE,MAAM;EAAc,MAAM;EAAW;CACvC;EAAE,MAAM;EAAS,MAAM;EAAW;CAClC;EAAE,MAAM;EAAc,MAAM;EAAW;CACvC;EAAE,MAAM;EAAQ,MAAM;EAAS;CAC/B;EAAE,MAAM;EAAiB,MAAM;EAAS;CACxC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/order-utils/model/ctfExchangeV2TypedData.ts
|
|
3
|
+
const CTF_EXCHANGE_V2_DOMAIN_NAME = "Polymarket CTF Exchange";
|
|
4
|
+
const CTF_EXCHANGE_V2_DOMAIN_VERSION = "2";
|
|
5
|
+
const CTF_EXCHANGE_V3_DOMAIN_VERSION = "3";
|
|
6
|
+
const CTF_EXCHANGE_V2_ORDER_STRUCT = [
|
|
7
|
+
{
|
|
8
|
+
name: "salt",
|
|
9
|
+
type: "uint256"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: "maker",
|
|
13
|
+
type: "address"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "signer",
|
|
17
|
+
type: "address"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "tokenId",
|
|
21
|
+
type: "uint256"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "makerAmount",
|
|
25
|
+
type: "uint256"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "takerAmount",
|
|
29
|
+
type: "uint256"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "side",
|
|
33
|
+
type: "uint8"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "signatureType",
|
|
37
|
+
type: "uint8"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "timestamp",
|
|
41
|
+
type: "uint256"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "metadata",
|
|
45
|
+
type: "bytes32"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "builder",
|
|
49
|
+
type: "bytes32"
|
|
50
|
+
}
|
|
51
|
+
];
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
exports.CTF_EXCHANGE_V2_DOMAIN_NAME = CTF_EXCHANGE_V2_DOMAIN_NAME;
|
|
55
|
+
exports.CTF_EXCHANGE_V2_DOMAIN_VERSION = CTF_EXCHANGE_V2_DOMAIN_VERSION;
|
|
56
|
+
exports.CTF_EXCHANGE_V2_ORDER_STRUCT = CTF_EXCHANGE_V2_ORDER_STRUCT;
|
|
57
|
+
exports.CTF_EXCHANGE_V3_DOMAIN_VERSION = CTF_EXCHANGE_V3_DOMAIN_VERSION;
|
|
58
|
+
//# sourceMappingURL=ctfExchangeV2TypedData.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ctfExchangeV2TypedData.cjs","names":[],"sources":["../../../src/order-utils/model/ctfExchangeV2TypedData.ts"],"sourcesContent":["export const CTF_EXCHANGE_V2_DOMAIN_NAME = \"Polymarket CTF Exchange\";\n\nexport const CTF_EXCHANGE_V2_DOMAIN_VERSION = \"2\";\n\nexport const CTF_EXCHANGE_V3_DOMAIN_VERSION = \"3\";\n\nexport const CTF_EXCHANGE_V2_ORDER_STRUCT = [\n\t{ name: \"salt\", type: \"uint256\" },\n\t{ name: \"maker\", type: \"address\" },\n\t{ name: \"signer\", type: \"address\" },\n\t{ name: \"tokenId\", type: \"uint256\" },\n\t{ name: \"makerAmount\", type: \"uint256\" },\n\t{ name: \"takerAmount\", type: \"uint256\" },\n\t{ name: \"side\", type: \"uint8\" },\n\t{ name: \"signatureType\", type: \"uint8\" },\n\t{ name: \"timestamp\", type: \"uint256\" },\n\t{ name: \"metadata\", type: \"bytes32\" },\n\t{ name: \"builder\", type: \"bytes32\" },\n];\n"],"mappings":";;AAAA,MAAa,8BAA8B;AAE3C,MAAa,iCAAiC;AAE9C,MAAa,iCAAiC;AAE9C,MAAa,+BAA+B;CAC3C;EAAE,MAAM;EAAQ,MAAM;EAAW;CACjC;EAAE,MAAM;EAAS,MAAM;EAAW;CAClC;EAAE,MAAM;EAAU,MAAM;EAAW;CACnC;EAAE,MAAM;EAAW,MAAM;EAAW;CACpC;EAAE,MAAM;EAAe,MAAM;EAAW;CACxC;EAAE,MAAM;EAAe,MAAM;EAAW;CACxC;EAAE,MAAM;EAAQ,MAAM;EAAS;CAC/B;EAAE,MAAM;EAAiB,MAAM;EAAS;CACxC;EAAE,MAAM;EAAa,MAAM;EAAW;CACtC;EAAE,MAAM;EAAY,MAAM;EAAW;CACrC;EAAE,MAAM;EAAW,MAAM;EAAW;CACpC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region src/order-utils/model/ctfExchangeV2TypedData.ts
|
|
2
|
+
const CTF_EXCHANGE_V2_DOMAIN_NAME = "Polymarket CTF Exchange";
|
|
3
|
+
const CTF_EXCHANGE_V2_DOMAIN_VERSION = "2";
|
|
4
|
+
const CTF_EXCHANGE_V3_DOMAIN_VERSION = "3";
|
|
5
|
+
const CTF_EXCHANGE_V2_ORDER_STRUCT = [
|
|
6
|
+
{
|
|
7
|
+
name: "salt",
|
|
8
|
+
type: "uint256"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: "maker",
|
|
12
|
+
type: "address"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "signer",
|
|
16
|
+
type: "address"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "tokenId",
|
|
20
|
+
type: "uint256"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "makerAmount",
|
|
24
|
+
type: "uint256"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "takerAmount",
|
|
28
|
+
type: "uint256"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "side",
|
|
32
|
+
type: "uint8"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "signatureType",
|
|
36
|
+
type: "uint8"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "timestamp",
|
|
40
|
+
type: "uint256"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "metadata",
|
|
44
|
+
type: "bytes32"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "builder",
|
|
48
|
+
type: "bytes32"
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
export { CTF_EXCHANGE_V2_DOMAIN_NAME, CTF_EXCHANGE_V2_DOMAIN_VERSION, CTF_EXCHANGE_V2_ORDER_STRUCT, CTF_EXCHANGE_V3_DOMAIN_VERSION };
|
|
54
|
+
//# sourceMappingURL=ctfExchangeV2TypedData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ctfExchangeV2TypedData.js","names":[],"sources":["../../../src/order-utils/model/ctfExchangeV2TypedData.ts"],"sourcesContent":["export const CTF_EXCHANGE_V2_DOMAIN_NAME = \"Polymarket CTF Exchange\";\n\nexport const CTF_EXCHANGE_V2_DOMAIN_VERSION = \"2\";\n\nexport const CTF_EXCHANGE_V3_DOMAIN_VERSION = \"3\";\n\nexport const CTF_EXCHANGE_V2_ORDER_STRUCT = [\n\t{ name: \"salt\", type: \"uint256\" },\n\t{ name: \"maker\", type: \"address\" },\n\t{ name: \"signer\", type: \"address\" },\n\t{ name: \"tokenId\", type: \"uint256\" },\n\t{ name: \"makerAmount\", type: \"uint256\" },\n\t{ name: \"takerAmount\", type: \"uint256\" },\n\t{ name: \"side\", type: \"uint8\" },\n\t{ name: \"signatureType\", type: \"uint8\" },\n\t{ name: \"timestamp\", type: \"uint256\" },\n\t{ name: \"metadata\", type: \"bytes32\" },\n\t{ name: \"builder\", type: \"bytes32\" },\n];\n"],"mappings":";AAAA,MAAa,8BAA8B;AAE3C,MAAa,iCAAiC;AAE9C,MAAa,iCAAiC;AAE9C,MAAa,+BAA+B;CAC3C;EAAE,MAAM;EAAQ,MAAM;EAAW;CACjC;EAAE,MAAM;EAAS,MAAM;EAAW;CAClC;EAAE,MAAM;EAAU,MAAM;EAAW;CACnC;EAAE,MAAM;EAAW,MAAM;EAAW;CACpC;EAAE,MAAM;EAAe,MAAM;EAAW;CACxC;EAAE,MAAM;EAAe,MAAM;EAAW;CACxC;EAAE,MAAM;EAAQ,MAAM;EAAS;CAC/B;EAAE,MAAM;EAAiB,MAAM;EAAS;CACxC;EAAE,MAAM;EAAa,MAAM;EAAW;CACtC;EAAE,MAAM;EAAY,MAAM;EAAW;CACrC;EAAE,MAAM;EAAW,MAAM;EAAW;CACpC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/order-utils/model/eip712.ts
|
|
3
|
+
const EIP712_DOMAIN = [
|
|
4
|
+
{
|
|
5
|
+
name: "name",
|
|
6
|
+
type: "string"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
name: "version",
|
|
10
|
+
type: "string"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: "chainId",
|
|
14
|
+
type: "uint256"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "verifyingContract",
|
|
18
|
+
type: "address"
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.EIP712_DOMAIN = EIP712_DOMAIN;
|
|
24
|
+
//# sourceMappingURL=eip712.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip712.cjs","names":[],"sources":["../../../src/order-utils/model/eip712.ts"],"sourcesContent":["export interface EIP712TypedData {\n\ttypes: EIP712Types;\n\tdomain: EIP712Object;\n\tmessage: EIP712Object;\n\tprimaryType: string;\n}\n\nexport interface EIP712Types {\n\t[key: string]: EIP712Parameter[];\n}\n\nexport interface EIP712Parameter {\n\tname: string;\n\ttype: string;\n}\n\nexport declare type EIP712ObjectValue = string | number | EIP712Object;\n\nexport interface EIP712Object {\n\t[key: string]: EIP712ObjectValue;\n}\n\nexport interface MessageTypes {\n\t[additionalProperties: string]: MessageTypeProperty[];\n\tEIP712Domain: MessageTypeProperty[];\n}\n\nexport interface MessageTypeProperty {\n\tname: string;\n\ttype: string;\n}\n\nexport const EIP712_DOMAIN = [\n\t{ name: \"name\", type: \"string\" },\n\t{ name: \"version\", type: \"string\" },\n\t{ name: \"chainId\", type: \"uint256\" },\n\t{ name: \"verifyingContract\", type: \"address\" },\n];\n"],"mappings":";;AAgCA,MAAa,gBAAgB;CAC5B;EAAE,MAAM;EAAQ,MAAM;EAAU;CAChC;EAAE,MAAM;EAAW,MAAM;EAAU;CACnC;EAAE,MAAM;EAAW,MAAM;EAAW;CACpC;EAAE,MAAM;EAAqB,MAAM;EAAW;CAC9C"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/order-utils/model/eip712.d.ts
|
|
2
|
+
|
|
3
|
+
declare type EIP712ObjectValue = string | number | EIP712Object;
|
|
4
|
+
interface EIP712Object {
|
|
5
|
+
[key: string]: EIP712ObjectValue;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { EIP712Object, EIP712ObjectValue };
|
|
9
|
+
//# sourceMappingURL=eip712.d.ts.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/order-utils/model/eip712.ts
|
|
2
|
+
const EIP712_DOMAIN = [
|
|
3
|
+
{
|
|
4
|
+
name: "name",
|
|
5
|
+
type: "string"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
name: "version",
|
|
9
|
+
type: "string"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
name: "chainId",
|
|
13
|
+
type: "uint256"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "verifyingContract",
|
|
17
|
+
type: "address"
|
|
18
|
+
}
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { EIP712_DOMAIN };
|
|
23
|
+
//# sourceMappingURL=eip712.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip712.js","names":[],"sources":["../../../src/order-utils/model/eip712.ts"],"sourcesContent":["export interface EIP712TypedData {\n\ttypes: EIP712Types;\n\tdomain: EIP712Object;\n\tmessage: EIP712Object;\n\tprimaryType: string;\n}\n\nexport interface EIP712Types {\n\t[key: string]: EIP712Parameter[];\n}\n\nexport interface EIP712Parameter {\n\tname: string;\n\ttype: string;\n}\n\nexport declare type EIP712ObjectValue = string | number | EIP712Object;\n\nexport interface EIP712Object {\n\t[key: string]: EIP712ObjectValue;\n}\n\nexport interface MessageTypes {\n\t[additionalProperties: string]: MessageTypeProperty[];\n\tEIP712Domain: MessageTypeProperty[];\n}\n\nexport interface MessageTypeProperty {\n\tname: string;\n\ttype: string;\n}\n\nexport const EIP712_DOMAIN = [\n\t{ name: \"name\", type: \"string\" },\n\t{ name: \"version\", type: \"string\" },\n\t{ name: \"chainId\", type: \"uint256\" },\n\t{ name: \"verifyingContract\", type: \"address\" },\n];\n"],"mappings":";AAgCA,MAAa,gBAAgB;CAC5B;EAAE,MAAM;EAAQ,MAAM;EAAU;CAChC;EAAE,MAAM;EAAW,MAAM;EAAU;CACnC;EAAE,MAAM;EAAW,MAAM;EAAW;CACpC;EAAE,MAAM;EAAqB,MAAM;EAAW;CAC9C"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { EIP712Object } from "./eip712.cjs";
|
|
2
|
+
import { OrderSignature } from "./order.cjs";
|
|
3
|
+
import { Side } from "./side.cjs";
|
|
4
|
+
import { SignatureTypeV1 } from "./signatureTypeV1.cjs";
|
|
5
|
+
|
|
6
|
+
//#region src/order-utils/model/orderDataV1.d.ts
|
|
7
|
+
|
|
8
|
+
interface OrderV1 extends EIP712Object {
|
|
9
|
+
/**
|
|
10
|
+
* Unique salt to ensure entropy
|
|
11
|
+
*/
|
|
12
|
+
readonly salt: string;
|
|
13
|
+
/**
|
|
14
|
+
* Maker of the order, i.e the source of funds for the order
|
|
15
|
+
*/
|
|
16
|
+
readonly maker: string;
|
|
17
|
+
/**
|
|
18
|
+
* Signer of the order
|
|
19
|
+
*/
|
|
20
|
+
readonly signer: string;
|
|
21
|
+
/**
|
|
22
|
+
* Address of the order taker. The zero address is used to indicate a public order
|
|
23
|
+
*/
|
|
24
|
+
readonly taker: string;
|
|
25
|
+
/**
|
|
26
|
+
* Token Id of the CTF ERC1155 asset to be bought or sold.
|
|
27
|
+
* If BUY, this is the tokenId of the asset to be bought, i.e the makerAssetId
|
|
28
|
+
* If SELL, this is the tokenId of the asset to be sold, i.e the takerAssetId
|
|
29
|
+
*/
|
|
30
|
+
readonly tokenId: string;
|
|
31
|
+
/**
|
|
32
|
+
* Maker amount, i.e the max amount of tokens to be sold
|
|
33
|
+
*/
|
|
34
|
+
readonly makerAmount: string;
|
|
35
|
+
/**
|
|
36
|
+
* Taker amount, i.e the minimum amount of tokens to be received
|
|
37
|
+
*/
|
|
38
|
+
readonly takerAmount: string;
|
|
39
|
+
/**
|
|
40
|
+
* Timestamp after which the order is expired
|
|
41
|
+
*/
|
|
42
|
+
readonly expiration: string;
|
|
43
|
+
/**
|
|
44
|
+
* Nonce used for onchain cancellations
|
|
45
|
+
*/
|
|
46
|
+
readonly nonce: string;
|
|
47
|
+
/**
|
|
48
|
+
* Fee rate, in basis points, charged to the order maker, charged on proceeds
|
|
49
|
+
*/
|
|
50
|
+
readonly feeRateBps: string;
|
|
51
|
+
/**
|
|
52
|
+
* The side of the order, BUY or SELL
|
|
53
|
+
*/
|
|
54
|
+
readonly side: Side;
|
|
55
|
+
/**
|
|
56
|
+
* Signature type used by the Order
|
|
57
|
+
*/
|
|
58
|
+
readonly signatureType: SignatureTypeV1;
|
|
59
|
+
}
|
|
60
|
+
interface SignedOrderV1 extends OrderV1 {
|
|
61
|
+
/**
|
|
62
|
+
* The order signature
|
|
63
|
+
*/
|
|
64
|
+
readonly signature: OrderSignature;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { SignedOrderV1 };
|
|
68
|
+
//# sourceMappingURL=orderDataV1.d.cts.map
|