@polymarket/clob-client-v2 0.1.0 → 0.2.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/dist/config.js +4 -4
- package/dist/order-utils/abi/ExchangeV2.d.ts +186 -43
- package/dist/order-utils/abi/ExchangeV2.js +233 -49
- package/dist/order-utils/abi/ExchangeV2.js.map +1 -1
- package/dist/order-utils/exchangeOrderBuilderV1.js +8 -2
- package/dist/order-utils/exchangeOrderBuilderV1.js.map +1 -1
- package/dist/order-utils/exchangeOrderBuilderV2.js +8 -2
- package/dist/order-utils/exchangeOrderBuilderV2.js.map +1 -1
- package/dist/order-utils/index.d.ts +2703 -0
- package/dist/order-utils/index.js +3 -0
- package/dist/order-utils/index.js.map +1 -1
- package/dist/signing/eip712.js +8 -2
- package/dist/signing/eip712.js.map +1 -1
- package/dist/signing/signer.d.ts +20 -7
- package/dist/signing/signer.js +38 -18
- package/dist/signing/signer.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from "./exchangeOrderBuilderV1.js";
|
|
2
2
|
export * from "./exchangeOrderBuilderV2.js";
|
|
3
3
|
// export * from "./eip712TypedDataV1.js";
|
|
4
|
+
import { exchangeV1Abi } from "./abi/ExchangeV1.js";
|
|
5
|
+
import { exchangeV2Abi } from "./abi/ExchangeV2.js";
|
|
6
|
+
export const ABIs = { exchangeV1: exchangeV1Abi, exchangeV2: exchangeV2Abi };
|
|
4
7
|
export * from "./model/abi.js";
|
|
5
8
|
export * from "./model/eip712.js";
|
|
6
9
|
export * from "./model/orderDataV1.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/order-utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/order-utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,6BAA6B,CAAC;AAE5C,0CAA0C;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;AAE7E,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,wBAAwB,CAAC;AACvC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC"}
|
package/dist/signing/eip712.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MSG_TO_SIGN } from "./constants.js";
|
|
2
|
-
import { getSignerAddress,
|
|
2
|
+
import { getSignerAddress, signTypedDataWithSigner } from "./signer.js";
|
|
3
3
|
/**
|
|
4
4
|
* Builds the canonical Polymarket CLOB EIP712 signature
|
|
5
5
|
* @param signer
|
|
@@ -28,7 +28,13 @@ export const buildClobEip712Signature = async (signer, chainId, timestamp, nonce
|
|
|
28
28
|
nonce,
|
|
29
29
|
message: MSG_TO_SIGN,
|
|
30
30
|
};
|
|
31
|
-
const sig = await
|
|
31
|
+
const sig = await signTypedDataWithSigner({
|
|
32
|
+
signer,
|
|
33
|
+
domain,
|
|
34
|
+
types,
|
|
35
|
+
value,
|
|
36
|
+
primaryType: "ClobAuth",
|
|
37
|
+
});
|
|
32
38
|
return sig;
|
|
33
39
|
};
|
|
34
40
|
//# sourceMappingURL=eip712.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eip712.js","sourceRoot":"","sources":["../../src/signing/eip712.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAmB,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"eip712.js","sourceRoot":"","sources":["../../src/signing/eip712.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAmB,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEzF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAC5C,MAAkB,EAClB,OAAc,EACd,SAAiB,EACjB,KAAa,EACK,EAAE;IACpB,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;IAEhC,MAAM,MAAM,GAAG;QACd,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,GAAG;QACZ,OAAO,EAAE,OAAO;KAChB,CAAC;IAEF,MAAM,KAAK,GAAG;QACb,QAAQ,EAAE;YACT,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;YACpC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE;YACrC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;YAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;SACnC;KACD,CAAC;IACF,MAAM,KAAK,GAAG;QACb,OAAO;QACP,SAAS,EAAE,EAAE;QACb,KAAK;QACL,OAAO,EAAE,WAAW;KACpB,CAAC;IACF,MAAM,GAAG,GAAG,MAAM,uBAAuB,CAAC;QACzC,MAAM;QACN,MAAM;QACN,KAAK;QACL,KAAK;QACL,WAAW,EAAE,UAAU;KACvB,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC"}
|
package/dist/signing/signer.d.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type ClobSigner = Wallet | JsonRpcSigner | WalletClient;
|
|
5
|
-
export declare const getSignerAddress: (signer: ClobSigner) => Promise<string>;
|
|
6
|
-
export declare const signTypedData: (signer: ClobSigner, domain: Record<string, unknown>, types: Record<string, {
|
|
1
|
+
import type { Address, WalletClient } from "viem";
|
|
2
|
+
type TypedDataDomain = Record<string, unknown>;
|
|
3
|
+
type TypedDataTypes = Record<string, Array<{
|
|
7
4
|
name: string;
|
|
8
5
|
type: string;
|
|
9
|
-
}
|
|
6
|
+
}>>;
|
|
7
|
+
type TypedDataValue = Record<string, unknown>;
|
|
8
|
+
interface EthersSigner {
|
|
9
|
+
_signTypedData(domain: TypedDataDomain, types: TypedDataTypes, value: TypedDataValue): Promise<string>;
|
|
10
|
+
getAddress(): Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
export type ClobSigner = EthersSigner | WalletClient;
|
|
13
|
+
export declare const getWalletClientAddress: (walletClient: WalletClient) => Promise<Address>;
|
|
14
|
+
export declare const getSignerAddress: (signer: ClobSigner) => Promise<string>;
|
|
15
|
+
export declare const signTypedDataWithSigner: ({ signer, domain, types, value, primaryType, }: {
|
|
16
|
+
signer: ClobSigner;
|
|
17
|
+
domain: TypedDataDomain;
|
|
18
|
+
types: TypedDataTypes;
|
|
19
|
+
value: TypedDataValue;
|
|
20
|
+
primaryType?: string;
|
|
21
|
+
}) => Promise<string>;
|
|
22
|
+
export {};
|
package/dist/signing/signer.js
CHANGED
|
@@ -1,30 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
const isEthersTypedDataSigner = (signer) =>
|
|
2
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
3
|
+
typeof signer._signTypedData === "function";
|
|
4
|
+
const isWalletClientSigner = (signer) => typeof signer.signTypedData === "function";
|
|
5
|
+
export const getWalletClientAddress = async (walletClient) => {
|
|
6
|
+
const accountAddress = walletClient.account?.address;
|
|
7
|
+
if (typeof accountAddress === "string" && accountAddress.length > 0) {
|
|
8
|
+
return accountAddress;
|
|
9
|
+
}
|
|
10
|
+
if (typeof walletClient.requestAddresses === "function") {
|
|
11
|
+
const [address] = await walletClient.requestAddresses();
|
|
12
|
+
if (typeof address === "string" && address.length > 0) {
|
|
13
|
+
return address;
|
|
9
14
|
}
|
|
10
|
-
const addresses = await signer.getAddresses();
|
|
11
|
-
return addresses[0];
|
|
12
15
|
}
|
|
13
|
-
|
|
16
|
+
if (typeof walletClient.getAddresses === "function") {
|
|
17
|
+
const [address] = await walletClient.getAddresses();
|
|
18
|
+
if (typeof address === "string" && address.length > 0) {
|
|
19
|
+
return address;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
throw new Error("wallet client is missing account address");
|
|
14
23
|
};
|
|
15
|
-
export const
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
export const getSignerAddress = async (signer) => {
|
|
25
|
+
if (isEthersTypedDataSigner(signer)) {
|
|
26
|
+
return signer.getAddress();
|
|
27
|
+
}
|
|
28
|
+
if (isWalletClientSigner(signer)) {
|
|
29
|
+
return getWalletClientAddress(signer);
|
|
30
|
+
}
|
|
31
|
+
throw new Error("unsupported signer type");
|
|
32
|
+
};
|
|
33
|
+
export const signTypedDataWithSigner = async ({ signer, domain, types, value, primaryType, }) => {
|
|
34
|
+
if (isEthersTypedDataSigner(signer)) {
|
|
35
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
36
|
+
return signer._signTypedData(domain, types, value);
|
|
37
|
+
}
|
|
38
|
+
if (isWalletClientSigner(signer)) {
|
|
39
|
+
const account = signer.account ?? (await getWalletClientAddress(signer));
|
|
19
40
|
return signer.signTypedData({
|
|
20
41
|
account,
|
|
21
42
|
domain,
|
|
22
43
|
types,
|
|
23
44
|
primaryType,
|
|
24
|
-
message,
|
|
45
|
+
message: value,
|
|
25
46
|
});
|
|
26
47
|
}
|
|
27
|
-
|
|
28
|
-
return signer._signTypedData(domain, types, message);
|
|
48
|
+
throw new Error("unsupported signer type");
|
|
29
49
|
};
|
|
30
50
|
//# sourceMappingURL=signer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/signing/signer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signer.js","sourceRoot":"","sources":["../../src/signing/signer.ts"],"names":[],"mappings":"AAiBA,MAAM,uBAAuB,GAAG,CAAC,MAAkB,EAA0B,EAAE;AAC9E,gDAAgD;AAChD,OAAQ,MAAuB,CAAC,cAAc,KAAK,UAAU,CAAC;AAE/D,MAAM,oBAAoB,GAAG,CAAC,MAAkB,EAA0B,EAAE,CAC3E,OAAQ,MAAuB,CAAC,aAAa,KAAK,UAAU,CAAC;AAE9D,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,YAA0B,EAAoB,EAAE;IAC5F,MAAM,cAAc,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC;IACrD,IAAI,OAAO,cAAc,KAAK,QAAQ,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrE,OAAO,cAAyB,CAAC;IAClC,CAAC;IAED,IAAI,OAAO,YAAY,CAAC,gBAAgB,KAAK,UAAU,EAAE,CAAC;QACzD,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,YAAY,CAAC,gBAAgB,EAAE,CAAC;QACxD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACvD,OAAO,OAAkB,CAAC;QAC3B,CAAC;IACF,CAAC;IAED,IAAI,OAAO,YAAY,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;QACrD,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,YAAY,CAAC,YAAY,EAAE,CAAC;QACpD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,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