felix-mcp 2.0.108 → 2.0.110
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 +2 -2
- package/THIRD_PARTY_NOTICES.md +28 -0
- package/dist/getting-started-guide.js +1 -1
- package/dist/index.js +1 -1
- package/dist/polymarket.js +1 -1
- package/dist/vendor/polymarket-clob-v2/client.js +985 -0
- package/dist/vendor/polymarket-clob-v2/config.js +33 -0
- package/dist/vendor/polymarket-clob-v2/constants.js +9 -0
- package/dist/vendor/polymarket-clob-v2/endpoints.js +64 -0
- package/dist/vendor/polymarket-clob-v2/errors.js +16 -0
- package/dist/vendor/polymarket-clob-v2/fees/index.js +20 -0
- package/dist/vendor/polymarket-clob-v2/headers/index.js +34 -0
- package/dist/vendor/polymarket-clob-v2/http-helpers/index.js +112 -0
- package/dist/vendor/polymarket-clob-v2/index.js +14 -0
- package/dist/vendor/polymarket-clob-v2/order-builder/helpers/buildMarketOrderCreationArgs.js +40 -0
- package/dist/vendor/polymarket-clob-v2/order-builder/helpers/buildOrder.js +32 -0
- package/dist/vendor/polymarket-clob-v2/order-builder/helpers/buildOrderCreationArgs.js +42 -0
- package/dist/vendor/polymarket-clob-v2/order-builder/helpers/calculateBuyMarketPrice.js +25 -0
- package/dist/vendor/polymarket-clob-v2/order-builder/helpers/calculateSellMarketPrice.js +25 -0
- package/dist/vendor/polymarket-clob-v2/order-builder/helpers/createExchangeV3OrderFromAmounts.js +30 -0
- package/dist/vendor/polymarket-clob-v2/order-builder/helpers/createMarketOrder.js +33 -0
- package/dist/vendor/polymarket-clob-v2/order-builder/helpers/createOrder.js +33 -0
- package/dist/vendor/polymarket-clob-v2/order-builder/helpers/getMarketOrderRawAmounts.js +37 -0
- package/dist/vendor/polymarket-clob-v2/order-builder/helpers/getOrderRawAmounts.js +37 -0
- package/dist/vendor/polymarket-clob-v2/order-builder/helpers/roundingConfig.js +36 -0
- package/dist/vendor/polymarket-clob-v2/order-builder/orderBuilder.js +57 -0
- package/dist/vendor/polymarket-clob-v2/order-utils/exchangeOrderBuilderV1.js +135 -0
- package/dist/vendor/polymarket-clob-v2/order-utils/exchangeOrderBuilderV2.js +195 -0
- package/dist/vendor/polymarket-clob-v2/order-utils/model/ctfExchangeV1TypedData.js +56 -0
- package/dist/vendor/polymarket-clob-v2/order-utils/model/ctfExchangeV2TypedData.js +53 -0
- package/dist/vendor/polymarket-clob-v2/order-utils/model/eip712.js +22 -0
- package/dist/vendor/polymarket-clob-v2/order-utils/model/side.js +9 -0
- package/dist/vendor/polymarket-clob-v2/order-utils/model/signatureTypeV1.js +19 -0
- package/dist/vendor/polymarket-clob-v2/order-utils/model/signatureTypeV2.js +23 -0
- package/dist/vendor/polymarket-clob-v2/order-utils/utils.js +7 -0
- package/dist/vendor/polymarket-clob-v2/signing/constants.js +5 -0
- package/dist/vendor/polymarket-clob-v2/signing/eip712.js +49 -0
- package/dist/vendor/polymarket-clob-v2/signing/hmac.js +43 -0
- package/dist/vendor/polymarket-clob-v2/signing/signer.js +44 -0
- package/dist/vendor/polymarket-clob-v2/types/clob.js +30 -0
- package/dist/vendor/polymarket-clob-v2/types/ordersV1.js +27 -0
- package/dist/vendor/polymarket-clob-v2/types/ordersV2.js +28 -0
- package/dist/vendor/polymarket-clob-v2/types/unifiedOrder.js +9 -0
- package/dist/vendor/polymarket-clob-v2/utilities.js +48 -0
- package/package.json +6 -3
- package/server.json +2 -2
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/order-builder/helpers/roundingConfig.ts
|
|
2
|
+
const ROUNDING_CONFIG = {
|
|
3
|
+
"0.1": {
|
|
4
|
+
price: 1,
|
|
5
|
+
size: 2,
|
|
6
|
+
amount: 3
|
|
7
|
+
},
|
|
8
|
+
"0.01": {
|
|
9
|
+
price: 2,
|
|
10
|
+
size: 2,
|
|
11
|
+
amount: 4
|
|
12
|
+
},
|
|
13
|
+
"0.005": {
|
|
14
|
+
price: 3,
|
|
15
|
+
size: 2,
|
|
16
|
+
amount: 5
|
|
17
|
+
},
|
|
18
|
+
"0.0025": {
|
|
19
|
+
price: 4,
|
|
20
|
+
size: 2,
|
|
21
|
+
amount: 6
|
|
22
|
+
},
|
|
23
|
+
"0.001": {
|
|
24
|
+
price: 3,
|
|
25
|
+
size: 2,
|
|
26
|
+
amount: 5
|
|
27
|
+
},
|
|
28
|
+
"0.0001": {
|
|
29
|
+
price: 4,
|
|
30
|
+
size: 2,
|
|
31
|
+
amount: 6
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
//#endregion
|
|
35
|
+
export { ROUNDING_CONFIG };
|
|
36
|
+
//# sourceMappingURL=roundingConfig.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { SignatureTypeV2 } from "../order-utils/model/signatureTypeV2.js";
|
|
2
|
+
import { createMarketOrder } from "./helpers/createMarketOrder.js";
|
|
3
|
+
import { createOrder } from "./helpers/createOrder.js";
|
|
4
|
+
import { createExchangeV3OrderFromAmounts } from "./helpers/createExchangeV3OrderFromAmounts.js";
|
|
5
|
+
//#region src/order-builder/orderBuilder.ts
|
|
6
|
+
var OrderBuilder = class {
|
|
7
|
+
signer;
|
|
8
|
+
chainId;
|
|
9
|
+
signatureType;
|
|
10
|
+
funderAddress;
|
|
11
|
+
/**
|
|
12
|
+
* Optional function to dynamically resolve the signer.
|
|
13
|
+
* If provided, this function will be called to obtain a fresh signer instance
|
|
14
|
+
* (e.g., for smart contract wallets or when the signer may change).
|
|
15
|
+
* Should return a Wallet or JsonRpcSigner, or a Promise resolving to one.
|
|
16
|
+
* If not provided, the static `signer` property is used.
|
|
17
|
+
*/
|
|
18
|
+
getSigner;
|
|
19
|
+
constructor(signer, chainId, signatureType, funderAddress, getSigner) {
|
|
20
|
+
this.signer = signer;
|
|
21
|
+
this.chainId = chainId;
|
|
22
|
+
this.signatureType = signatureType === void 0 ? SignatureTypeV2.EOA : signatureType;
|
|
23
|
+
this.funderAddress = funderAddress;
|
|
24
|
+
this.getSigner = getSigner;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generate and sign a order
|
|
28
|
+
*/
|
|
29
|
+
async buildOrder(userOrder, options, version) {
|
|
30
|
+
return createOrder(await this.resolveSigner(), this.chainId, this.signatureType, this.funderAddress, userOrder, options, version);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generate and sign a market order
|
|
34
|
+
*/
|
|
35
|
+
async buildMarketOrder(userMarketOrder, options, version) {
|
|
36
|
+
return createMarketOrder(await this.resolveSigner(), this.chainId, this.signatureType, this.funderAddress, userMarketOrder, options, version);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Generate and sign an ExchangeV3 order using exact base-unit amounts.
|
|
40
|
+
*/
|
|
41
|
+
async buildExchangeV3OrderFromAmounts(userOrder) {
|
|
42
|
+
return createExchangeV3OrderFromAmounts(await this.resolveSigner(), this.chainId, this.signatureType, this.funderAddress, userOrder);
|
|
43
|
+
}
|
|
44
|
+
/** Unified getter: use fresh signer if available */
|
|
45
|
+
async resolveSigner() {
|
|
46
|
+
if (this.getSigner) {
|
|
47
|
+
const s = await this.getSigner();
|
|
48
|
+
if (!s)
|
|
49
|
+
throw new Error("getSigner() function returned undefined or null");
|
|
50
|
+
return s;
|
|
51
|
+
}
|
|
52
|
+
return this.signer;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
//#endregion
|
|
56
|
+
export { OrderBuilder };
|
|
57
|
+
//# sourceMappingURL=orderBuilder.js.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { getSignerAddress, signTypedDataWithSigner } from "../signing/signer.js";
|
|
2
|
+
import { CTF_EXCHANGE_V1_DOMAIN_NAME, CTF_EXCHANGE_V1_DOMAIN_VERSION, CTF_EXCHANGE_V1_ORDER_STRUCT } from "./model/ctfExchangeV1TypedData.js";
|
|
3
|
+
import { EIP712_DOMAIN } from "./model/eip712.js";
|
|
4
|
+
import { SignatureTypeV1 } from "./model/signatureTypeV1.js";
|
|
5
|
+
import { generateOrderSalt } from "./utils.js";
|
|
6
|
+
import { hashTypedData } from "viem";
|
|
7
|
+
//#region src/order-utils/exchangeOrderBuilderV1.ts
|
|
8
|
+
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
9
|
+
var ExchangeOrderBuilderV1 = class {
|
|
10
|
+
constructor(contractAddress, chainId, signer, generateSalt = generateOrderSalt) {
|
|
11
|
+
this.contractAddress = contractAddress;
|
|
12
|
+
this.chainId = chainId;
|
|
13
|
+
this.signer = signer;
|
|
14
|
+
this.generateSalt = generateSalt;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* build an order object including the signature.
|
|
18
|
+
* @param orderData
|
|
19
|
+
* @returns a SignedOrder object (order + signature)
|
|
20
|
+
*/
|
|
21
|
+
async buildSignedOrder(orderData) {
|
|
22
|
+
const order = await this.buildOrder(orderData);
|
|
23
|
+
const orderTypedData = this.buildOrderTypedData(order);
|
|
24
|
+
const orderSignature = await this.buildOrderSignature(orderTypedData);
|
|
25
|
+
return {
|
|
26
|
+
...order,
|
|
27
|
+
signature: orderSignature
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates an Order object from order data.
|
|
32
|
+
* @param OrderData
|
|
33
|
+
* @returns a Order object (not signed)
|
|
34
|
+
*/
|
|
35
|
+
async buildOrder({ maker, taker, tokenId, makerAmount, takerAmount, side, feeRateBps, nonce, signer, expiration, signatureType }) {
|
|
36
|
+
if (!signer)
|
|
37
|
+
signer = maker;
|
|
38
|
+
const signerAddress = await getSignerAddress(this.signer);
|
|
39
|
+
if (signer !== signerAddress)
|
|
40
|
+
throw new Error("signer does not match");
|
|
41
|
+
if (!expiration)
|
|
42
|
+
expiration = "0";
|
|
43
|
+
if (!signatureType)
|
|
44
|
+
signatureType = SignatureTypeV1.EOA;
|
|
45
|
+
let takerAddress;
|
|
46
|
+
if (typeof taker !== "undefined" && taker)
|
|
47
|
+
takerAddress = taker;
|
|
48
|
+
else
|
|
49
|
+
takerAddress = ZERO_ADDRESS;
|
|
50
|
+
let feeRateBpsResolved;
|
|
51
|
+
if (typeof feeRateBps !== "undefined" && feeRateBps)
|
|
52
|
+
feeRateBpsResolved = feeRateBps.toString();
|
|
53
|
+
else
|
|
54
|
+
feeRateBpsResolved = "0";
|
|
55
|
+
let nonceResolved;
|
|
56
|
+
if (typeof nonce !== "undefined" && nonce)
|
|
57
|
+
nonceResolved = nonce.toString();
|
|
58
|
+
else
|
|
59
|
+
nonceResolved = "0";
|
|
60
|
+
return {
|
|
61
|
+
salt: this.generateSalt(),
|
|
62
|
+
maker,
|
|
63
|
+
signer,
|
|
64
|
+
taker: takerAddress,
|
|
65
|
+
tokenId,
|
|
66
|
+
makerAmount,
|
|
67
|
+
takerAmount,
|
|
68
|
+
expiration,
|
|
69
|
+
nonce: nonceResolved,
|
|
70
|
+
feeRateBps: feeRateBpsResolved,
|
|
71
|
+
side,
|
|
72
|
+
signatureType
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Parses an Order object to EIP712 typed data
|
|
77
|
+
* @param order
|
|
78
|
+
* @returns a EIP712TypedData object
|
|
79
|
+
*/
|
|
80
|
+
buildOrderTypedData(order) {
|
|
81
|
+
return {
|
|
82
|
+
primaryType: "Order",
|
|
83
|
+
types: {
|
|
84
|
+
EIP712Domain: EIP712_DOMAIN,
|
|
85
|
+
Order: CTF_EXCHANGE_V1_ORDER_STRUCT
|
|
86
|
+
},
|
|
87
|
+
domain: {
|
|
88
|
+
name: CTF_EXCHANGE_V1_DOMAIN_NAME,
|
|
89
|
+
version: CTF_EXCHANGE_V1_DOMAIN_VERSION,
|
|
90
|
+
chainId: this.chainId,
|
|
91
|
+
verifyingContract: this.contractAddress
|
|
92
|
+
},
|
|
93
|
+
message: {
|
|
94
|
+
salt: order.salt,
|
|
95
|
+
maker: order.maker,
|
|
96
|
+
signer: order.signer,
|
|
97
|
+
taker: order.taker,
|
|
98
|
+
tokenId: order.tokenId,
|
|
99
|
+
makerAmount: order.makerAmount,
|
|
100
|
+
takerAmount: order.takerAmount,
|
|
101
|
+
expiration: order.expiration,
|
|
102
|
+
nonce: order.nonce,
|
|
103
|
+
feeRateBps: order.feeRateBps,
|
|
104
|
+
side: order.side === "BUY" ? 0 : 1,
|
|
105
|
+
signatureType: order.signatureType
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Generates order's signature from a EIP712TypedData object + the signer address
|
|
111
|
+
* @param typedData
|
|
112
|
+
* @returns a OrderSignature that is an string
|
|
113
|
+
*/
|
|
114
|
+
buildOrderSignature(typedData) {
|
|
115
|
+
delete typedData.types.EIP712Domain;
|
|
116
|
+
return signTypedDataWithSigner({
|
|
117
|
+
signer: this.signer,
|
|
118
|
+
domain: typedData.domain,
|
|
119
|
+
types: typedData.types,
|
|
120
|
+
value: typedData.message,
|
|
121
|
+
primaryType: typedData.primaryType
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Generates the hash of the order from a EIP712TypedData object.
|
|
126
|
+
* @param orderTypedData
|
|
127
|
+
* @returns a OrderHash that is an string
|
|
128
|
+
*/
|
|
129
|
+
buildOrderHash(orderTypedData) {
|
|
130
|
+
return hashTypedData(orderTypedData);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
//#endregion
|
|
134
|
+
export { ExchangeOrderBuilderV1 };
|
|
135
|
+
//# sourceMappingURL=exchangeOrderBuilderV1.js.map
|
|
@@ -0,0 +1,195 @@
|
|
|
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
|
+
//#region src/order-utils/exchangeOrderBuilderV2.ts
|
|
9
|
+
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)";
|
|
10
|
+
const ORDER_TYPE_HASH = keccak256(toHex(ORDER_TYPE_STRING));
|
|
11
|
+
const DOMAIN_TYPE_HASH = keccak256(toHex("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"));
|
|
12
|
+
const TYPED_DATA_SIGN_STRUCT = [
|
|
13
|
+
{
|
|
14
|
+
name: "contents",
|
|
15
|
+
type: "Order"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "name",
|
|
19
|
+
type: "string"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "version",
|
|
23
|
+
type: "string"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "chainId",
|
|
27
|
+
type: "uint256"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "verifyingContract",
|
|
31
|
+
type: "address"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "salt",
|
|
35
|
+
type: "bytes32"
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
const CTF_EXCHANGE_NAME_HASH = keccak256(toHex(CTF_EXCHANGE_V2_DOMAIN_NAME));
|
|
39
|
+
var ExchangeOrderBuilderV2 = class {
|
|
40
|
+
appDomainSep;
|
|
41
|
+
constructor(contractAddress, chainId, signer, generateSalt = generateOrderSalt, domainVersion = CTF_EXCHANGE_V2_DOMAIN_VERSION) {
|
|
42
|
+
this.contractAddress = contractAddress;
|
|
43
|
+
this.chainId = chainId;
|
|
44
|
+
this.signer = signer;
|
|
45
|
+
this.generateSalt = generateSalt;
|
|
46
|
+
this.domainVersion = domainVersion;
|
|
47
|
+
this.appDomainSep = keccak256(encodeAbiParameters([
|
|
48
|
+
{ type: "bytes32" },
|
|
49
|
+
{ type: "bytes32" },
|
|
50
|
+
{ type: "bytes32" },
|
|
51
|
+
{ type: "uint256" },
|
|
52
|
+
{ type: "address" }
|
|
53
|
+
], [
|
|
54
|
+
DOMAIN_TYPE_HASH,
|
|
55
|
+
CTF_EXCHANGE_NAME_HASH,
|
|
56
|
+
keccak256(toHex(domainVersion)),
|
|
57
|
+
BigInt(chainId),
|
|
58
|
+
contractAddress
|
|
59
|
+
]));
|
|
60
|
+
}
|
|
61
|
+
async buildSignedOrder(orderData) {
|
|
62
|
+
const order = await this.buildOrder(orderData);
|
|
63
|
+
const orderTypedData = this.buildOrderTypedData(order);
|
|
64
|
+
const orderSignature = await this.buildOrderSignature(orderTypedData);
|
|
65
|
+
return {
|
|
66
|
+
...order,
|
|
67
|
+
signature: orderSignature
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async buildOrder({ maker, tokenId, makerAmount, takerAmount, side, signer, signatureType, timestamp, metadata, builder, expiration }) {
|
|
71
|
+
if (!signer)
|
|
72
|
+
signer = maker;
|
|
73
|
+
if (signatureType !== SignatureTypeV2.POLY_1271) {
|
|
74
|
+
const signerAddress = await getSignerAddress(this.signer);
|
|
75
|
+
if (signer !== signerAddress)
|
|
76
|
+
throw new Error("signer does not match");
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
salt: this.generateSalt(),
|
|
80
|
+
maker,
|
|
81
|
+
signer,
|
|
82
|
+
tokenId,
|
|
83
|
+
makerAmount,
|
|
84
|
+
takerAmount,
|
|
85
|
+
side,
|
|
86
|
+
signatureType: signatureType ?? SignatureTypeV2.EOA,
|
|
87
|
+
metadata: metadata ?? bytes32Zero,
|
|
88
|
+
builder: builder ?? bytes32Zero,
|
|
89
|
+
timestamp: timestamp ?? Date.now().toString(),
|
|
90
|
+
expiration: expiration ?? "0"
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
buildOrderTypedData(order) {
|
|
94
|
+
return {
|
|
95
|
+
primaryType: "Order",
|
|
96
|
+
types: {
|
|
97
|
+
EIP712Domain: EIP712_DOMAIN,
|
|
98
|
+
Order: CTF_EXCHANGE_V2_ORDER_STRUCT
|
|
99
|
+
},
|
|
100
|
+
domain: {
|
|
101
|
+
name: CTF_EXCHANGE_V2_DOMAIN_NAME,
|
|
102
|
+
version: this.domainVersion,
|
|
103
|
+
chainId: this.chainId,
|
|
104
|
+
verifyingContract: this.contractAddress
|
|
105
|
+
},
|
|
106
|
+
message: {
|
|
107
|
+
salt: order.salt,
|
|
108
|
+
maker: order.maker,
|
|
109
|
+
signer: order.signer,
|
|
110
|
+
tokenId: order.tokenId,
|
|
111
|
+
makerAmount: order.makerAmount,
|
|
112
|
+
takerAmount: order.takerAmount,
|
|
113
|
+
timestamp: order.timestamp,
|
|
114
|
+
side: order.side === "BUY" ? 0 : 1,
|
|
115
|
+
signatureType: order.signatureType,
|
|
116
|
+
metadata: order.metadata,
|
|
117
|
+
builder: order.builder
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
async buildOrderSignature(typedData) {
|
|
122
|
+
delete typedData.types.EIP712Domain;
|
|
123
|
+
const msg = typedData.message;
|
|
124
|
+
if (msg.signatureType !== SignatureTypeV2.POLY_1271)
|
|
125
|
+
return signTypedDataWithSigner({
|
|
126
|
+
signer: this.signer,
|
|
127
|
+
domain: typedData.domain,
|
|
128
|
+
types: typedData.types,
|
|
129
|
+
value: typedData.message,
|
|
130
|
+
primaryType: typedData.primaryType
|
|
131
|
+
});
|
|
132
|
+
const contentsHash = keccak256(encodeAbiParameters([
|
|
133
|
+
{ type: "bytes32" },
|
|
134
|
+
{ type: "uint256" },
|
|
135
|
+
{ type: "address" },
|
|
136
|
+
{ type: "address" },
|
|
137
|
+
{ type: "uint256" },
|
|
138
|
+
{ type: "uint256" },
|
|
139
|
+
{ type: "uint256" },
|
|
140
|
+
{ type: "uint8" },
|
|
141
|
+
{ type: "uint8" },
|
|
142
|
+
{ type: "uint256" },
|
|
143
|
+
{ type: "bytes32" },
|
|
144
|
+
{ type: "bytes32" }
|
|
145
|
+
], [
|
|
146
|
+
ORDER_TYPE_HASH,
|
|
147
|
+
BigInt(msg.salt),
|
|
148
|
+
msg.maker,
|
|
149
|
+
msg.signer,
|
|
150
|
+
BigInt(msg.tokenId),
|
|
151
|
+
BigInt(msg.makerAmount),
|
|
152
|
+
BigInt(msg.takerAmount),
|
|
153
|
+
msg.side,
|
|
154
|
+
msg.signatureType,
|
|
155
|
+
BigInt(msg.timestamp),
|
|
156
|
+
msg.metadata,
|
|
157
|
+
msg.builder
|
|
158
|
+
]));
|
|
159
|
+
const innerSig = await signTypedDataWithSigner({
|
|
160
|
+
signer: this.signer,
|
|
161
|
+
domain: {
|
|
162
|
+
name: CTF_EXCHANGE_V2_DOMAIN_NAME,
|
|
163
|
+
version: this.domainVersion,
|
|
164
|
+
chainId: this.chainId,
|
|
165
|
+
verifyingContract: this.contractAddress
|
|
166
|
+
},
|
|
167
|
+
types: {
|
|
168
|
+
TypedDataSign: TYPED_DATA_SIGN_STRUCT,
|
|
169
|
+
Order: CTF_EXCHANGE_V2_ORDER_STRUCT
|
|
170
|
+
},
|
|
171
|
+
primaryType: "TypedDataSign",
|
|
172
|
+
value: {
|
|
173
|
+
contents: typedData.message,
|
|
174
|
+
name: "DepositWallet",
|
|
175
|
+
version: "1",
|
|
176
|
+
chainId: this.chainId,
|
|
177
|
+
verifyingContract: msg.signer,
|
|
178
|
+
salt: bytes32Zero
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
const lenHex = 186..toString(16).padStart(4, "0");
|
|
182
|
+
return `0x${innerSig.slice(2)}${this.appDomainSep.slice(2)}${contentsHash.slice(2)}${toHex(ORDER_TYPE_STRING).slice(2)}${lenHex}`;
|
|
183
|
+
}
|
|
184
|
+
buildOrderHash(orderTypedData) {
|
|
185
|
+
return hashTypedData(orderTypedData);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
var ExchangeOrderBuilderV3 = class extends ExchangeOrderBuilderV2 {
|
|
189
|
+
constructor(contractAddress, chainId, signer, generateSalt = generateOrderSalt) {
|
|
190
|
+
super(contractAddress, chainId, signer, generateSalt, CTF_EXCHANGE_V3_DOMAIN_VERSION);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
//#endregion
|
|
194
|
+
export { ExchangeOrderBuilderV2, ExchangeOrderBuilderV3 };
|
|
195
|
+
//# sourceMappingURL=exchangeOrderBuilderV2.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
//#endregion
|
|
55
|
+
export { CTF_EXCHANGE_V1_DOMAIN_NAME, CTF_EXCHANGE_V1_DOMAIN_VERSION, CTF_EXCHANGE_V1_ORDER_STRUCT };
|
|
56
|
+
//# sourceMappingURL=ctfExchangeV1TypedData.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
//#endregion
|
|
52
|
+
export { CTF_EXCHANGE_V2_DOMAIN_NAME, CTF_EXCHANGE_V2_DOMAIN_VERSION, CTF_EXCHANGE_V2_ORDER_STRUCT, CTF_EXCHANGE_V3_DOMAIN_VERSION };
|
|
53
|
+
//# sourceMappingURL=ctfExchangeV2TypedData.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
//#endregion
|
|
21
|
+
export { EIP712_DOMAIN };
|
|
22
|
+
//# sourceMappingURL=eip712.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/order-utils/model/signatureTypeV1.ts
|
|
2
|
+
let SignatureTypeV1 = /* @__PURE__ */ function (SignatureTypeV1$1) {
|
|
3
|
+
/**
|
|
4
|
+
* ECDSA EIP712 signatures signed by EOAs
|
|
5
|
+
*/
|
|
6
|
+
SignatureTypeV1$1[SignatureTypeV1$1["EOA"] = 0] = "EOA";
|
|
7
|
+
/**
|
|
8
|
+
* EIP712 signatures signed by EOAs that own Polymarket Proxy wallets
|
|
9
|
+
*/
|
|
10
|
+
SignatureTypeV1$1[SignatureTypeV1$1["POLY_PROXY"] = 1] = "POLY_PROXY";
|
|
11
|
+
/**
|
|
12
|
+
* EIP712 signatures signed by EOAs that own Polymarket Gnosis safes
|
|
13
|
+
*/
|
|
14
|
+
SignatureTypeV1$1[SignatureTypeV1$1["POLY_GNOSIS_SAFE"] = 2] = "POLY_GNOSIS_SAFE";
|
|
15
|
+
return SignatureTypeV1$1;
|
|
16
|
+
}({});
|
|
17
|
+
//#endregion
|
|
18
|
+
export { SignatureTypeV1 };
|
|
19
|
+
//# sourceMappingURL=signatureTypeV1.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/order-utils/model/signatureTypeV2.ts
|
|
2
|
+
let SignatureTypeV2 = /* @__PURE__ */ function (SignatureTypeV2$1) {
|
|
3
|
+
/**
|
|
4
|
+
* ECDSA EIP712 signatures signed by EOAs
|
|
5
|
+
*/
|
|
6
|
+
SignatureTypeV2$1[SignatureTypeV2$1["EOA"] = 0] = "EOA";
|
|
7
|
+
/**
|
|
8
|
+
* EIP712 signatures signed by EOAs that own Polymarket Proxy wallets
|
|
9
|
+
*/
|
|
10
|
+
SignatureTypeV2$1[SignatureTypeV2$1["POLY_PROXY"] = 1] = "POLY_PROXY";
|
|
11
|
+
/**
|
|
12
|
+
* EIP712 signatures signed by EOAs that own Polymarket Gnosis safes
|
|
13
|
+
*/
|
|
14
|
+
SignatureTypeV2$1[SignatureTypeV2$1["POLY_GNOSIS_SAFE"] = 2] = "POLY_GNOSIS_SAFE";
|
|
15
|
+
/**
|
|
16
|
+
* EIP1271 signatures signed by smart contracts. To be used by smart contract wallets or vaults
|
|
17
|
+
*/
|
|
18
|
+
SignatureTypeV2$1[SignatureTypeV2$1["POLY_1271"] = 3] = "POLY_1271";
|
|
19
|
+
return SignatureTypeV2$1;
|
|
20
|
+
}({});
|
|
21
|
+
//#endregion
|
|
22
|
+
export { SignatureTypeV2 };
|
|
23
|
+
//# sourceMappingURL=signatureTypeV2.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { MSG_TO_SIGN } from "./constants.js";
|
|
2
|
+
import { getSignerAddress, signTypedDataWithSigner } from "./signer.js";
|
|
3
|
+
//#region src/signing/eip712.ts
|
|
4
|
+
/**
|
|
5
|
+
* Builds the canonical Polymarket CLOB EIP712 signature
|
|
6
|
+
* @param signer
|
|
7
|
+
* @param ts
|
|
8
|
+
* @returns string
|
|
9
|
+
*/
|
|
10
|
+
const buildClobEip712Signature = async (signer, chainId, timestamp, nonce, address) => {
|
|
11
|
+
const resolvedAddress = address ?? await getSignerAddress(signer);
|
|
12
|
+
const ts = timestamp.toString();
|
|
13
|
+
return await signTypedDataWithSigner({
|
|
14
|
+
signer,
|
|
15
|
+
domain: {
|
|
16
|
+
name: "ClobAuthDomain",
|
|
17
|
+
version: "1",
|
|
18
|
+
chainId
|
|
19
|
+
},
|
|
20
|
+
types: { ClobAuth: [
|
|
21
|
+
{
|
|
22
|
+
name: "address",
|
|
23
|
+
type: "address"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "timestamp",
|
|
27
|
+
type: "string"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "nonce",
|
|
31
|
+
type: "uint256"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "message",
|
|
35
|
+
type: "string"
|
|
36
|
+
}
|
|
37
|
+
] },
|
|
38
|
+
value: {
|
|
39
|
+
address: resolvedAddress,
|
|
40
|
+
timestamp: ts,
|
|
41
|
+
nonce,
|
|
42
|
+
message: MSG_TO_SIGN
|
|
43
|
+
},
|
|
44
|
+
primaryType: "ClobAuth"
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { buildClobEip712Signature };
|
|
49
|
+
//# sourceMappingURL=eip712.js.map
|