@polymarket/relayer-client 3.0.0 → 4.1.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.
@@ -1,224 +1,224 @@
1
1
  export const safeFactoryAbi = [
2
2
  {
3
- "inputs": [
3
+ inputs: [
4
4
  {
5
- "internalType": "address",
6
- "name": "_masterCopy",
7
- "type": "address"
5
+ internalType: "address",
6
+ name: "_masterCopy",
7
+ type: "address",
8
8
  },
9
9
  {
10
- "internalType": "address",
11
- "name": "_fallbackHandler",
12
- "type": "address"
13
- }
10
+ internalType: "address",
11
+ name: "_fallbackHandler",
12
+ type: "address",
13
+ },
14
14
  ],
15
- "stateMutability": "nonpayable",
16
- "type": "constructor"
15
+ stateMutability: "nonpayable",
16
+ type: "constructor",
17
17
  },
18
18
  {
19
- "anonymous": false,
20
- "inputs": [
19
+ anonymous: false,
20
+ inputs: [
21
21
  {
22
- "indexed": false,
23
- "internalType": "contract GnosisSafe",
24
- "name": "proxy",
25
- "type": "address"
22
+ indexed: false,
23
+ internalType: "contract GnosisSafe",
24
+ name: "proxy",
25
+ type: "address",
26
26
  },
27
27
  {
28
- "indexed": false,
29
- "internalType": "address",
30
- "name": "owner",
31
- "type": "address"
32
- }
28
+ indexed: false,
29
+ internalType: "address",
30
+ name: "owner",
31
+ type: "address",
32
+ },
33
33
  ],
34
- "name": "ProxyCreation",
35
- "type": "event"
34
+ name: "ProxyCreation",
35
+ type: "event",
36
36
  },
37
37
  {
38
- "inputs": [],
39
- "name": "CREATE_PROXY_TYPEHASH",
40
- "outputs": [
41
- {
42
- "internalType": "bytes32",
43
- "name": "",
44
- "type": "bytes32"
45
- }
38
+ inputs: [],
39
+ name: "CREATE_PROXY_TYPEHASH",
40
+ outputs: [
41
+ {
42
+ internalType: "bytes32",
43
+ name: "",
44
+ type: "bytes32",
45
+ },
46
46
  ],
47
- "stateMutability": "view",
48
- "type": "function"
47
+ stateMutability: "view",
48
+ type: "function",
49
49
  },
50
50
  {
51
- "inputs": [],
52
- "name": "DOMAIN_TYPEHASH",
53
- "outputs": [
54
- {
55
- "internalType": "bytes32",
56
- "name": "",
57
- "type": "bytes32"
58
- }
51
+ inputs: [],
52
+ name: "DOMAIN_TYPEHASH",
53
+ outputs: [
54
+ {
55
+ internalType: "bytes32",
56
+ name: "",
57
+ type: "bytes32",
58
+ },
59
59
  ],
60
- "stateMutability": "view",
61
- "type": "function"
60
+ stateMutability: "view",
61
+ type: "function",
62
62
  },
63
63
  {
64
- "inputs": [],
65
- "name": "NAME",
66
- "outputs": [
67
- {
68
- "internalType": "string",
69
- "name": "",
70
- "type": "string"
71
- }
64
+ inputs: [],
65
+ name: "NAME",
66
+ outputs: [
67
+ {
68
+ internalType: "string",
69
+ name: "",
70
+ type: "string",
71
+ },
72
72
  ],
73
- "stateMutability": "view",
74
- "type": "function"
73
+ stateMutability: "view",
74
+ type: "function",
75
75
  },
76
76
  {
77
- "inputs": [
77
+ inputs: [
78
78
  {
79
- "internalType": "address",
80
- "name": "user",
81
- "type": "address"
82
- }
79
+ internalType: "address",
80
+ name: "user",
81
+ type: "address",
82
+ },
83
83
  ],
84
- "name": "computeProxyAddress",
85
- "outputs": [
84
+ name: "computeProxyAddress",
85
+ outputs: [
86
86
  {
87
- "internalType": "address",
88
- "name": "",
89
- "type": "address"
90
- }
87
+ internalType: "address",
88
+ name: "",
89
+ type: "address",
90
+ },
91
91
  ],
92
- "stateMutability": "view",
93
- "type": "function"
92
+ stateMutability: "view",
93
+ type: "function",
94
94
  },
95
95
  {
96
- "inputs": [
96
+ inputs: [
97
97
  {
98
- "internalType": "address",
99
- "name": "paymentToken",
100
- "type": "address"
98
+ internalType: "address",
99
+ name: "paymentToken",
100
+ type: "address",
101
101
  },
102
102
  {
103
- "internalType": "uint256",
104
- "name": "payment",
105
- "type": "uint256"
103
+ internalType: "uint256",
104
+ name: "payment",
105
+ type: "uint256",
106
106
  },
107
107
  {
108
- "internalType": "address payable",
109
- "name": "paymentReceiver",
110
- "type": "address"
108
+ internalType: "address payable",
109
+ name: "paymentReceiver",
110
+ type: "address",
111
111
  },
112
112
  {
113
- "components": [
113
+ components: [
114
114
  {
115
- "internalType": "uint8",
116
- "name": "v",
117
- "type": "uint8"
115
+ internalType: "uint8",
116
+ name: "v",
117
+ type: "uint8",
118
118
  },
119
119
  {
120
- "internalType": "bytes32",
121
- "name": "r",
122
- "type": "bytes32"
120
+ internalType: "bytes32",
121
+ name: "r",
122
+ type: "bytes32",
123
123
  },
124
124
  {
125
- "internalType": "bytes32",
126
- "name": "s",
127
- "type": "bytes32"
128
- }
125
+ internalType: "bytes32",
126
+ name: "s",
127
+ type: "bytes32",
128
+ },
129
129
  ],
130
- "internalType": "struct SafeProxyFactory.Sig",
131
- "name": "createSig",
132
- "type": "tuple"
133
- }
130
+ internalType: "struct SafeProxyFactory.Sig",
131
+ name: "createSig",
132
+ type: "tuple",
133
+ },
134
134
  ],
135
- "name": "createProxy",
136
- "outputs": [],
137
- "stateMutability": "nonpayable",
138
- "type": "function"
135
+ name: "createProxy",
136
+ outputs: [],
137
+ stateMutability: "nonpayable",
138
+ type: "function",
139
139
  },
140
140
  {
141
- "inputs": [],
142
- "name": "domainSeparator",
143
- "outputs": [
144
- {
145
- "internalType": "bytes32",
146
- "name": "",
147
- "type": "bytes32"
148
- }
141
+ inputs: [],
142
+ name: "domainSeparator",
143
+ outputs: [
144
+ {
145
+ internalType: "bytes32",
146
+ name: "",
147
+ type: "bytes32",
148
+ },
149
149
  ],
150
- "stateMutability": "view",
151
- "type": "function"
150
+ stateMutability: "view",
151
+ type: "function",
152
152
  },
153
153
  {
154
- "inputs": [],
155
- "name": "fallbackHandler",
156
- "outputs": [
157
- {
158
- "internalType": "address",
159
- "name": "",
160
- "type": "address"
161
- }
154
+ inputs: [],
155
+ name: "fallbackHandler",
156
+ outputs: [
157
+ {
158
+ internalType: "address",
159
+ name: "",
160
+ type: "address",
161
+ },
162
162
  ],
163
- "stateMutability": "view",
164
- "type": "function"
163
+ stateMutability: "view",
164
+ type: "function",
165
165
  },
166
166
  {
167
- "inputs": [],
168
- "name": "getContractBytecode",
169
- "outputs": [
170
- {
171
- "internalType": "bytes",
172
- "name": "",
173
- "type": "bytes"
174
- }
167
+ inputs: [],
168
+ name: "getContractBytecode",
169
+ outputs: [
170
+ {
171
+ internalType: "bytes",
172
+ name: "",
173
+ type: "bytes",
174
+ },
175
175
  ],
176
- "stateMutability": "view",
177
- "type": "function"
176
+ stateMutability: "view",
177
+ type: "function",
178
178
  },
179
179
  {
180
- "inputs": [
180
+ inputs: [
181
181
  {
182
- "internalType": "address",
183
- "name": "user",
184
- "type": "address"
185
- }
182
+ internalType: "address",
183
+ name: "user",
184
+ type: "address",
185
+ },
186
186
  ],
187
- "name": "getSalt",
188
- "outputs": [
187
+ name: "getSalt",
188
+ outputs: [
189
189
  {
190
- "internalType": "bytes32",
191
- "name": "",
192
- "type": "bytes32"
193
- }
190
+ internalType: "bytes32",
191
+ name: "",
192
+ type: "bytes32",
193
+ },
194
194
  ],
195
- "stateMutability": "pure",
196
- "type": "function"
195
+ stateMutability: "pure",
196
+ type: "function",
197
197
  },
198
198
  {
199
- "inputs": [],
200
- "name": "masterCopy",
201
- "outputs": [
202
- {
203
- "internalType": "address",
204
- "name": "",
205
- "type": "address"
206
- }
199
+ inputs: [],
200
+ name: "masterCopy",
201
+ outputs: [
202
+ {
203
+ internalType: "address",
204
+ name: "",
205
+ type: "address",
206
+ },
207
207
  ],
208
- "stateMutability": "view",
209
- "type": "function"
208
+ stateMutability: "view",
209
+ type: "function",
210
210
  },
211
211
  {
212
- "inputs": [],
213
- "name": "proxyCreationCode",
214
- "outputs": [
215
- {
216
- "internalType": "bytes",
217
- "name": "",
218
- "type": "bytes"
219
- }
212
+ inputs: [],
213
+ name: "proxyCreationCode",
214
+ outputs: [
215
+ {
216
+ internalType: "bytes",
217
+ name: "",
218
+ type: "bytes",
219
+ },
220
220
  ],
221
- "stateMutability": "pure",
222
- "type": "function"
223
- }
221
+ stateMutability: "pure",
222
+ type: "function",
223
+ },
224
224
  ];
@@ -1,5 +1,5 @@
1
- import { HttpClient } from "../http-helpers/index.ts";
2
- import { AuthArgs } from "../types.ts";
1
+ import { type HttpClient } from "../http-helpers/index.ts";
2
+ import type { AuthArgs } from "../types.ts";
3
3
  export declare class AuthHandler {
4
4
  readonly url: string;
5
5
  readonly httpClient: HttpClient;
@@ -6,7 +6,7 @@ export class AuthHandler {
6
6
  token;
7
7
  cookie;
8
8
  constructor(httpClient, args) {
9
- if (args.authUrl == undefined || args.authToken == undefined) {
9
+ if (args.authUrl === undefined || args.authToken === undefined) {
10
10
  throw new Error("invalid authorization arguments");
11
11
  }
12
12
  this.url = args.authUrl.endsWith("/") ? args.authUrl.slice(0, -1) : args.authUrl;
@@ -18,24 +18,26 @@ export class AuthHandler {
18
18
  * Extracts polymarket session cookies from the auth response header and cache it locally.
19
19
  */
20
20
  async login() {
21
- if (this.cookie == undefined) {
21
+ if (this.cookie === undefined) {
22
22
  // Logging in will set the session cookies on the httpClient
23
- const resp = await this.httpClient.send(`${this.url}/login/internal`, GET, { Authorization: `Bearer ${this.token}` });
24
- const cookies = resp.headers['set-cookie'];
23
+ const resp = await this.httpClient.send(`${this.url}/login/internal`, GET, {
24
+ Authorization: `Bearer ${this.token}`,
25
+ });
26
+ const cookies = resp.headers["set-cookie"];
25
27
  let aggregatedCookie = "";
26
28
  for (const cookie of cookies) {
27
29
  if (cookie.includes(POLYMARKET_COOKIE_NAME)) {
28
30
  aggregatedCookie += `${cookie}; `;
29
31
  }
30
32
  }
31
- if (aggregatedCookie != "") {
33
+ if (aggregatedCookie !== "") {
32
34
  this.cookie = aggregatedCookie;
33
35
  }
34
36
  console.log(`Successfully logged in!`);
35
37
  }
36
38
  }
37
39
  async getPolymarketCookies() {
38
- if (this.cookie == undefined) {
40
+ if (this.cookie === undefined) {
39
41
  console.log("Authorization not set, logging in...");
40
42
  await this.login();
41
43
  }
@@ -1,4 +1,4 @@
1
- import { SafeCreateTransactionArgs, TransactionRequest } from "../types.ts";
2
- import { IAbstractSigner } from "@polymarket/abstract-signer";
3
- import { SafeContractConfig } from "../config/index.ts";
4
- export declare function buildSafeCreateTransactionRequest(signer: IAbstractSigner, safeContractConfig: SafeContractConfig, args: SafeCreateTransactionArgs): Promise<TransactionRequest>;
1
+ import type { SafeContractConfig } from "../config/index.ts";
2
+ import type { RelayerSigner } from "../signer/index.ts";
3
+ import { type SafeCreateTransactionArgs, type TransactionRequest } from "../types.ts";
4
+ export declare function buildSafeCreateTransactionRequest(signer: RelayerSigner, safeContractConfig: SafeContractConfig, args: SafeCreateTransactionArgs): Promise<TransactionRequest>;
@@ -1,5 +1,5 @@
1
- import { TransactionType } from "../types.js";
2
1
  import { SAFE_FACTORY_NAME } from "../constants/index.js";
2
+ import { TransactionType, } from "../types.js";
3
3
  import { deriveSafe } from "./derive.js";
4
4
  async function createSafeCreateSignature(signer, safeFactory, chainId, paymentToken, payment, paymentReceiver) {
5
5
  const domain = {
@@ -1,16 +1,16 @@
1
- import { keccak256, encodePacked, getCreate2Address, encodeAbiParameters } from 'viem';
2
- import { SAFE_INIT_CODE_HASH, PROXY_INIT_CODE_HASH } from "../constants/index.js";
1
+ import { encodeAbiParameters, encodePacked, getCreate2Address, keccak256 } from "viem";
2
+ import { PROXY_INIT_CODE_HASH, SAFE_INIT_CODE_HASH } from "../constants/index.js";
3
3
  export const deriveProxyWallet = (address, proxyFactory) => {
4
4
  return getCreate2Address({
5
5
  bytecodeHash: PROXY_INIT_CODE_HASH,
6
6
  from: proxyFactory,
7
- salt: keccak256(encodePacked(["address"], [address]))
7
+ salt: keccak256(encodePacked(["address"], [address])),
8
8
  });
9
9
  };
10
10
  export const deriveSafe = (address, safeFactory) => {
11
11
  return getCreate2Address({
12
12
  bytecodeHash: SAFE_INIT_CODE_HASH,
13
13
  from: safeFactory,
14
- salt: keccak256(encodeAbiParameters([{ name: 'address', type: 'address' }], [address]))
14
+ salt: keccak256(encodeAbiParameters([{ name: "address", type: "address" }], [address])),
15
15
  });
16
16
  };
@@ -1,4 +1,4 @@
1
- export * from "./proxy.ts";
2
- export * from "./safe.ts";
3
1
  export * from "./create.ts";
4
2
  export * from "./derive.ts";
3
+ export * from "./proxy.ts";
4
+ export * from "./safe.ts";
@@ -1,4 +1,4 @@
1
- export * from "./proxy.js";
2
- export * from "./safe.js";
3
1
  export * from "./create.js";
4
2
  export * from "./derive.js";
3
+ export * from "./proxy.js";
4
+ export * from "./safe.js";
@@ -1,4 +1,4 @@
1
- import { IAbstractSigner } from "@polymarket/abstract-signer";
2
- import { ProxyTransactionArgs, TransactionRequest } from "../types.ts";
3
- import { ProxyContractConfig } from "../config/index.ts";
4
- export declare function buildProxyTransactionRequest(signer: IAbstractSigner, args: ProxyTransactionArgs, proxyContractConfig: ProxyContractConfig, metadata?: string): Promise<TransactionRequest>;
1
+ import type { ProxyContractConfig } from "../config/index.ts";
2
+ import type { RelayerSigner } from "../signer/index.ts";
3
+ import { type ProxyTransactionArgs, type TransactionRequest } from "../types.ts";
4
+ export declare function buildProxyTransactionRequest(signer: RelayerSigner, args: ProxyTransactionArgs, proxyContractConfig: ProxyContractConfig, metadata?: string): Promise<TransactionRequest>;
@@ -1,5 +1,5 @@
1
1
  import { concat, keccak256, toHex } from "viem";
2
- import { TransactionType } from "../types.js";
2
+ import { TransactionType, } from "../types.js";
3
3
  import { deriveProxyWallet } from "./derive.js";
4
4
  function createStructHash(from, to, data, txFee, gasPrice, gasLimit, nonce, relayHubAddress, relayAddress) {
5
5
  const relayHubPrefix = toHex("rlx:");
@@ -35,11 +35,13 @@ export async function buildProxyTransactionRequest(signer, args, proxyContractCo
35
35
  const proxy = deriveProxyWallet(args.from, proxyWalletFactory);
36
36
  const relayerFee = "0";
37
37
  const relayHub = proxyContractConfig.RelayHub;
38
- const gasLimit = args.gasLimit ? args.gasLimit : await signer.estimateGas({
39
- from: args.from,
40
- to: to,
41
- data: args.data,
42
- });
38
+ const gasLimit = args.gasLimit
39
+ ? args.gasLimit
40
+ : await signer.estimateGas({
41
+ from: args.from,
42
+ to: to,
43
+ data: args.data,
44
+ });
43
45
  const gasLimitStr = gasLimit.toString();
44
46
  const sigParams = {
45
47
  gasPrice: args.gasPrice,
@@ -50,7 +52,7 @@ export async function buildProxyTransactionRequest(signer, args, proxyContractCo
50
52
  };
51
53
  const txHash = createStructHash(args.from, to, args.data, relayerFee, args.gasPrice, gasLimitStr, args.nonce, relayHub, args.relay);
52
54
  const sig = await createProxySignature(signer, txHash);
53
- if (metadata == undefined) {
55
+ if (metadata === undefined) {
54
56
  metadata = "";
55
57
  }
56
58
  const req = {
@@ -1,5 +1,5 @@
1
- import { IAbstractSigner } from "@polymarket/abstract-signer";
2
- import { SafeTransaction, SafeTransactionArgs, TransactionRequest } from "../types.ts";
3
- import { SafeContractConfig } from "../config/index.ts";
1
+ import type { SafeContractConfig } from "../config/index.ts";
2
+ import type { RelayerSigner } from "../signer/index.ts";
3
+ import { type SafeTransaction, type SafeTransactionArgs, type TransactionRequest } from "../types.ts";
4
4
  export declare function aggregateTransaction(txns: SafeTransaction[], safeMultisend: string): SafeTransaction;
5
- export declare function buildSafeTransactionRequest(signer: IAbstractSigner, args: SafeTransactionArgs, safeContractConfig: SafeContractConfig, metadata?: string): Promise<TransactionRequest>;
5
+ export declare function buildSafeTransactionRequest(signer: RelayerSigner, args: SafeTransactionArgs, safeContractConfig: SafeContractConfig, metadata?: string): Promise<TransactionRequest>;
@@ -1,8 +1,8 @@
1
1
  import { hashTypedData, zeroAddress } from "viem";
2
- import { TransactionType } from "../types.js";
3
- import { deriveSafe } from "./derive.js";
4
2
  import { createSafeMultisendTransaction } from "../encode/safe.js";
3
+ import { TransactionType, } from "../types.js";
5
4
  import { splitAndPackSig } from "../utils/index.js";
5
+ import { deriveSafe } from "./derive.js";
6
6
  async function createSafeSignature(signer, structHash) {
7
7
  return signer.signMessage(structHash);
8
8
  }
@@ -16,16 +16,16 @@ function createStructHash(chainId, safe, to, value, data, operation, safeTxGas,
16
16
  // "SafeTx(address to,uint256 value,bytes data,uint8 operation,uint256 safeTxGas,uint256 baseGas,uint256 gasPrice,address gasToken,address refundReceiver,uint256 nonce)"
17
17
  // );
18
18
  SafeTx: [
19
- { name: 'to', type: 'address' },
20
- { name: 'value', type: 'uint256' },
21
- { name: 'data', type: 'bytes' },
22
- { name: 'operation', type: 'uint8' },
23
- { name: 'safeTxGas', type: 'uint256' },
24
- { name: 'baseGas', type: 'uint256' },
25
- { name: 'gasPrice', type: 'uint256' },
26
- { name: 'gasToken', type: 'address' },
27
- { name: 'refundReceiver', type: 'address' },
28
- { name: 'nonce', type: 'uint256' },
19
+ { name: "to", type: "address" },
20
+ { name: "value", type: "uint256" },
21
+ { name: "data", type: "bytes" },
22
+ { name: "operation", type: "uint8" },
23
+ { name: "safeTxGas", type: "uint256" },
24
+ { name: "baseGas", type: "uint256" },
25
+ { name: "gasPrice", type: "uint256" },
26
+ { name: "gasToken", type: "address" },
27
+ { name: "refundReceiver", type: "address" },
28
+ { name: "nonce", type: "uint256" },
29
29
  ],
30
30
  };
31
31
  const values = {
@@ -42,12 +42,17 @@ function createStructHash(chainId, safe, to, value, data, operation, safeTxGas,
42
42
  };
43
43
  // // viem hashTypedData
44
44
  // const structHash = _TypedDataEncoder.hash(domain, types, values);
45
- const structHash = hashTypedData({ primaryType: "SafeTx", domain: domain, types: types, message: values });
45
+ const structHash = hashTypedData({
46
+ primaryType: "SafeTx",
47
+ domain: domain,
48
+ types: types,
49
+ message: values,
50
+ });
46
51
  return structHash;
47
52
  }
48
53
  export function aggregateTransaction(txns, safeMultisend) {
49
54
  let transaction;
50
- if (txns.length == 1) {
55
+ if (txns.length === 1) {
51
56
  transaction = txns[0];
52
57
  }
53
58
  else {
@@ -80,7 +85,7 @@ export async function buildSafeTransactionRequest(signer, args, safeContractConf
80
85
  gasToken,
81
86
  refundReceiver,
82
87
  };
83
- if (metadata == undefined) {
88
+ if (metadata === undefined) {
84
89
  metadata = "";
85
90
  }
86
91
  const req = {
package/dist/client.d.ts CHANGED
@@ -1,19 +1,17 @@
1
- import { Wallet } from "@ethersproject/wallet";
2
- import { JsonRpcSigner } from "@ethersproject/providers";
3
- import { WalletClient } from "viem";
4
- import { IAbstractSigner } from "@polymarket/abstract-signer";
5
- import { HttpClient } from "./http-helpers/index.ts";
6
- import { AddressPayload, AuthArgs, IManualTransactionResponse, ManualOverrides, NoncePayload, ProxyTransaction, RelayerTransaction, RelayerTransactionResponse, RelayPayload, SafeTransaction } from "./types.ts";
1
+ import { type WalletClient } from "viem";
7
2
  import { AuthHandler } from "./auth/handler.ts";
8
- import { ContractConfig } from "./config/index.ts";
3
+ import { type ContractConfig } from "./config/index.ts";
4
+ import { HttpClient } from "./http-helpers/index.ts";
5
+ import { type RelayerSigner } from "./signer/index.ts";
6
+ import { type AddressPayload, type AuthArgs, type IManualTransactionResponse, type ManualOverrides, type NoncePayload, type ProxyTransaction, type RelayerTransaction, type RelayerTransactionResponse, type RelayPayload, type SafeTransaction } from "./types.ts";
9
7
  export declare class RelayClient {
10
8
  readonly relayerUrl: string;
11
9
  readonly chainId: number;
12
10
  readonly contractConfig: ContractConfig;
13
11
  readonly httpClient: HttpClient;
14
- readonly signer?: IAbstractSigner;
12
+ readonly signer?: RelayerSigner;
15
13
  readonly authHandler?: AuthHandler;
16
- constructor(relayerUrl: string, chainId: number, signer?: Wallet | JsonRpcSigner | WalletClient, authArgs?: AuthArgs);
14
+ constructor(relayerUrl: string, chainId: number, signer?: WalletClient, authArgs?: AuthArgs);
17
15
  getRelayAddress(): Promise<AddressPayload>;
18
16
  getNonce(signerAddress: string, signerType: string): Promise<NoncePayload>;
19
17
  getRelayPayload(signerAddress: string, signerType: string): Promise<RelayPayload>;