This repository was archived by the owner on May 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathindex.ts
More file actions
81 lines (73 loc) · 2.07 KB
/
Copy pathindex.ts
File metadata and controls
81 lines (73 loc) · 2.07 KB
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
import type { BuilderHeaderPayload } from "@polymarket/builder-signing-sdk";
import type { ClobSigner } from "../signer.ts";
import { getSignerAddress } from "../signer.ts";
import { buildClobEip712Signature, buildPolyHmacSignature } from "../signing/index.ts";
import type {
ApiKeyCreds,
Chain,
L1PolyHeader,
L2HeaderArgs,
L2PolyHeader,
L2WithBuilderHeader,
} from "../types.ts";
export const createL1Headers = async (
signer: ClobSigner,
chainId: Chain,
nonce?: number,
timestamp?: number,
funderAddress?: string,
): Promise<L1PolyHeader> => {
let ts = Math.floor(Date.now() / 1000);
if (timestamp !== undefined) {
ts = timestamp;
}
let n = 0; // Default nonce is 0
if (nonce !== undefined) {
n = nonce;
}
const sig = await buildClobEip712Signature(signer, chainId, ts, n);
const address = funderAddress ?? (await getSignerAddress(signer));
const headers = {
POLY_ADDRESS: address,
POLY_SIGNATURE: sig,
POLY_TIMESTAMP: `${ts}`,
POLY_NONCE: `${n}`,
};
return headers;
};
export const createL2Headers = async (
signer: ClobSigner,
creds: ApiKeyCreds,
l2HeaderArgs: L2HeaderArgs,
timestamp?: number,
funderAddress?: string,
): Promise<L2PolyHeader> => {
let ts = Math.floor(Date.now() / 1000);
if (timestamp !== undefined) {
ts = timestamp;
}
const address = funderAddress ?? (await getSignerAddress(signer));
const sig = await buildPolyHmacSignature(
creds.secret,
ts,
l2HeaderArgs.method,
l2HeaderArgs.requestPath,
l2HeaderArgs.body,
);
const headers = {
POLY_ADDRESS: address,
POLY_SIGNATURE: sig,
POLY_TIMESTAMP: `${ts}`,
POLY_API_KEY: creds.key,
POLY_PASSPHRASE: creds.passphrase,
};
return headers;
};
export const injectBuilderHeaders = (
l2Header: L2PolyHeader,
builderHeaders: BuilderHeaderPayload,
): L2WithBuilderHeader =>
({
...l2Header,
...builderHeaders,
}) as L2WithBuilderHeader;