@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.
- package/README.md +7 -9
- package/dist/abis/erc20Abi.js +155 -155
- package/dist/abis/index.d.ts +3 -3
- package/dist/abis/index.js +3 -3
- package/dist/abis/multisend.js +12 -12
- package/dist/abis/proxyFactory.js +216 -216
- package/dist/abis/safe.js +769 -769
- package/dist/abis/safeFactory.js +159 -159
- package/dist/auth/handler.d.ts +2 -2
- package/dist/auth/handler.js +8 -6
- package/dist/builder/create.d.ts +4 -4
- package/dist/builder/create.js +1 -1
- package/dist/builder/derive.js +4 -4
- package/dist/builder/index.d.ts +2 -2
- package/dist/builder/index.js +2 -2
- package/dist/builder/proxy.d.ts +4 -4
- package/dist/builder/proxy.js +9 -7
- package/dist/builder/safe.d.ts +4 -4
- package/dist/builder/safe.js +20 -15
- package/dist/client.d.ts +7 -9
- package/dist/client.js +21 -21
- package/dist/config/index.js +4 -5
- package/dist/encode/proxy.d.ts +1 -1
- package/dist/encode/proxy.js +2 -2
- package/dist/encode/safe.d.ts +1 -1
- package/dist/encode/safe.js +8 -2
- package/dist/http-helpers/index.d.ts +1 -1
- package/dist/http-helpers/index.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/manual/index.d.ts +4 -4
- package/dist/manual/index.js +8 -6
- package/dist/response/index.d.ts +2 -2
- package/dist/response/index.js +2 -5
- package/dist/signer/index.d.ts +26 -0
- package/dist/signer/index.js +109 -0
- package/dist/types.js +0 -1
- package/dist/utils/index.js +4 -4
- package/package.json +17 -24
package/dist/client.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { isBrowser } from "browser-or-node";
|
|
2
2
|
import { zeroAddress } from "viem";
|
|
3
|
-
import { createAbstractSigner } from "@polymarket/abstract-signer";
|
|
4
|
-
import { GET, POST, HttpClient, } from "./http-helpers/index.js";
|
|
5
|
-
import { TransactionType } from "./types.js";
|
|
6
|
-
import { GET_ADDRESS, GET_NONCE, GET_RELAY_PAYLOAD, GET_TRANSACTION, SUBMIT_TRANSACTION, } from "./endpoints.js";
|
|
7
|
-
import { buildProxyTransactionRequest, buildSafeTransactionRequest, buildSafeCreateTransactionRequest, } from "./builder/index.js";
|
|
8
|
-
import { encodeProxyTransactionData } from "./encode/index.js";
|
|
9
3
|
import { AuthHandler } from "./auth/handler.js";
|
|
10
|
-
import {
|
|
4
|
+
import { buildProxyTransactionRequest, buildSafeCreateTransactionRequest, buildSafeTransactionRequest, } from "./builder/index.js";
|
|
5
|
+
import { getContractConfig } from "./config/index.js";
|
|
6
|
+
import { encodeProxyTransactionData } from "./encode/index.js";
|
|
7
|
+
import { GET_ADDRESS, GET_NONCE, GET_RELAY_PAYLOAD, GET_TRANSACTION, SUBMIT_TRANSACTION, } from "./endpoints.js";
|
|
8
|
+
import { GET, HttpClient, POST } from "./http-helpers/index.js";
|
|
11
9
|
import { executeManualTransactions } from "./manual/index.js";
|
|
12
10
|
import { ClientRelayerTransactionResponse } from "./response/index.js";
|
|
13
|
-
import {
|
|
11
|
+
import { createViemSigner } from "./signer/index.js";
|
|
12
|
+
import { TransactionType, } from "./types.js";
|
|
13
|
+
import { sleep } from "./utils/index.js";
|
|
14
14
|
export class RelayClient {
|
|
15
15
|
relayerUrl;
|
|
16
16
|
chainId;
|
|
@@ -23,8 +23,8 @@ export class RelayClient {
|
|
|
23
23
|
this.chainId = chainId;
|
|
24
24
|
this.contractConfig = getContractConfig(chainId);
|
|
25
25
|
this.httpClient = new HttpClient();
|
|
26
|
-
if (signer
|
|
27
|
-
this.signer =
|
|
26
|
+
if (signer !== undefined) {
|
|
27
|
+
this.signer = createViemSigner(chainId, signer);
|
|
28
28
|
}
|
|
29
29
|
if (authArgs !== undefined) {
|
|
30
30
|
this.authHandler = new AuthHandler(this.httpClient, authArgs);
|
|
@@ -46,7 +46,7 @@ export class RelayClient {
|
|
|
46
46
|
return this.send(`${this.relayerUrl}${GET_TRANSACTION}s`, GET);
|
|
47
47
|
}
|
|
48
48
|
async executeProxyTransactions(txns, metadata) {
|
|
49
|
-
if (this.signer
|
|
49
|
+
if (this.signer === undefined) {
|
|
50
50
|
throw new Error("missing signer");
|
|
51
51
|
}
|
|
52
52
|
const start = Date.now();
|
|
@@ -66,7 +66,7 @@ export class RelayClient {
|
|
|
66
66
|
return new ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
|
|
67
67
|
}
|
|
68
68
|
async executeSafeTransactions(txns, metadata) {
|
|
69
|
-
if (this.signer
|
|
69
|
+
if (this.signer === undefined) {
|
|
70
70
|
throw new Error("missing signer");
|
|
71
71
|
}
|
|
72
72
|
const start = Date.now();
|
|
@@ -85,16 +85,16 @@ export class RelayClient {
|
|
|
85
85
|
return new ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
|
|
86
86
|
}
|
|
87
87
|
async executeManualTransactions(txns, overrides) {
|
|
88
|
-
if (overrides
|
|
88
|
+
if (overrides === undefined) {
|
|
89
89
|
overrides = {};
|
|
90
90
|
}
|
|
91
|
-
if (this.signer
|
|
91
|
+
if (this.signer === undefined) {
|
|
92
92
|
throw new Error("missing signer");
|
|
93
93
|
}
|
|
94
94
|
return executeManualTransactions(this.signer, this.contractConfig.SafeContracts, txns, overrides);
|
|
95
95
|
}
|
|
96
96
|
async deploySafe() {
|
|
97
|
-
if (this.signer
|
|
97
|
+
if (this.signer === undefined) {
|
|
98
98
|
throw new Error("missing signer");
|
|
99
99
|
}
|
|
100
100
|
const start = Date.now();
|
|
@@ -126,9 +126,9 @@ export class RelayClient {
|
|
|
126
126
|
*/
|
|
127
127
|
async pollUntilState(transactionId, states, failState, maxPolls, pollFrequency) {
|
|
128
128
|
console.log(`Waiting for transaction ${transactionId} matching states: ${states}...`);
|
|
129
|
-
const maxPollCount = maxPolls
|
|
129
|
+
const maxPollCount = maxPolls !== undefined ? maxPolls : 10;
|
|
130
130
|
let pollFreq = 2000; // Default to polling every 2 seconds
|
|
131
|
-
if (pollFrequency
|
|
131
|
+
if (pollFrequency !== undefined) {
|
|
132
132
|
if (pollFrequency >= 1000) {
|
|
133
133
|
pollFreq = pollFrequency;
|
|
134
134
|
}
|
|
@@ -141,7 +141,7 @@ export class RelayClient {
|
|
|
141
141
|
if (states.includes(txn.state)) {
|
|
142
142
|
return txn;
|
|
143
143
|
}
|
|
144
|
-
if (failState
|
|
144
|
+
if (failState !== undefined && txn.state === failState) {
|
|
145
145
|
// Return undefined if txn reaches the fail state
|
|
146
146
|
return undefined;
|
|
147
147
|
}
|
|
@@ -160,11 +160,11 @@ export class RelayClient {
|
|
|
160
160
|
// Needed only for local testing
|
|
161
161
|
if (!isBrowser && this.authHandler !== undefined) {
|
|
162
162
|
const cookie = await this.authHandler.getPolymarketCookies();
|
|
163
|
-
if (headers
|
|
164
|
-
headers
|
|
163
|
+
if (headers !== undefined) {
|
|
164
|
+
headers.Cookie = cookie;
|
|
165
165
|
}
|
|
166
166
|
else {
|
|
167
|
-
headers = {
|
|
167
|
+
headers = { Cookie: cookie };
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
const resp = await this.httpClient.send(endpoint, method, headers, data, params);
|
package/dist/config/index.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
;
|
|
2
1
|
const AMOY = {
|
|
3
2
|
ProxyContracts: {
|
|
4
3
|
ProxyFactory: "",
|
|
5
|
-
RelayHub: ""
|
|
4
|
+
RelayHub: "",
|
|
6
5
|
},
|
|
7
6
|
SafeContracts: {
|
|
8
7
|
SafeFactory: "",
|
|
9
8
|
SafeMultisend: "",
|
|
10
|
-
}
|
|
9
|
+
},
|
|
11
10
|
};
|
|
12
11
|
const POL = {
|
|
13
12
|
ProxyContracts: {
|
|
14
13
|
ProxyFactory: "0xaB45c5A4B0c941a2F231C04C3f49182e1A254052",
|
|
15
|
-
RelayHub: "0xD216153c06E857cD7f72665E0aF1d7D82172F494"
|
|
14
|
+
RelayHub: "0xD216153c06E857cD7f72665E0aF1d7D82172F494",
|
|
16
15
|
},
|
|
17
16
|
SafeContracts: {
|
|
18
17
|
SafeFactory: "0xaacFeEa03eb1561C4e67d661e40682Bd20E3541b",
|
|
19
18
|
SafeMultisend: "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761",
|
|
20
|
-
}
|
|
19
|
+
},
|
|
21
20
|
};
|
|
22
21
|
export const getContractConfig = (chainId) => {
|
|
23
22
|
switch (chainId) {
|
package/dist/encode/proxy.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ProxyTransaction } from "../types.ts";
|
|
1
|
+
import type { ProxyTransaction } from "../types.ts";
|
|
2
2
|
export declare function encodeProxyTransactionData(txns: ProxyTransaction[]): string;
|
package/dist/encode/proxy.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { proxyWalletFactory } from "../abis/index.js";
|
|
2
1
|
import { encodeFunctionData, prepareEncodeFunctionData } from "viem";
|
|
2
|
+
import { proxyWalletFactory } from "../abis/index.js";
|
|
3
3
|
const proxy = prepareEncodeFunctionData({
|
|
4
4
|
abi: proxyWalletFactory,
|
|
5
|
-
functionName:
|
|
5
|
+
functionName: "proxy",
|
|
6
6
|
});
|
|
7
7
|
export function encodeProxyTransactionData(txns) {
|
|
8
8
|
return encodeFunctionData({
|
package/dist/encode/safe.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SafeTransaction } from "../types.ts";
|
|
1
|
+
import { type SafeTransaction } from "../types.ts";
|
|
2
2
|
export declare const createSafeMultisendTransaction: (txns: SafeTransaction[], safeMultisendAddress: string) => SafeTransaction;
|
package/dist/encode/safe.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { concatHex, encodeFunctionData, encodePacked, prepareEncodeFunctionData, size } from "viem";
|
|
1
|
+
import { concatHex, encodeFunctionData, encodePacked, prepareEncodeFunctionData, size, } from "viem";
|
|
2
2
|
import { multisendAbi } from "../abis/index.js";
|
|
3
3
|
import { OperationType } from "../types.js";
|
|
4
4
|
const multisend = prepareEncodeFunctionData({
|
|
@@ -7,7 +7,13 @@ const multisend = prepareEncodeFunctionData({
|
|
|
7
7
|
});
|
|
8
8
|
export const createSafeMultisendTransaction = (txns, safeMultisendAddress) => {
|
|
9
9
|
const args = [
|
|
10
|
-
concatHex(txns.map(tx => encodePacked(["uint8", "address", "uint256", "uint256", "bytes"], [
|
|
10
|
+
concatHex(txns.map(tx => encodePacked(["uint8", "address", "uint256", "uint256", "bytes"], [
|
|
11
|
+
tx.operation,
|
|
12
|
+
tx.to,
|
|
13
|
+
BigInt(tx.value),
|
|
14
|
+
BigInt(size(tx.data)),
|
|
15
|
+
tx.data,
|
|
16
|
+
]))),
|
|
11
17
|
];
|
|
12
18
|
const data = encodeFunctionData({ ...multisend, args: args });
|
|
13
19
|
return {
|
|
@@ -9,7 +9,7 @@ export class HttpClient {
|
|
|
9
9
|
this.instance = axios.create({ withCredentials: true });
|
|
10
10
|
}
|
|
11
11
|
async send(endpoint, method, headers, data, params) {
|
|
12
|
-
if (headers
|
|
12
|
+
if (headers !== undefined) {
|
|
13
13
|
headers["Access-Control-Allow-Credentials"] = true;
|
|
14
14
|
}
|
|
15
15
|
try {
|
|
@@ -18,7 +18,7 @@ export class HttpClient {
|
|
|
18
18
|
url: endpoint,
|
|
19
19
|
headers,
|
|
20
20
|
data,
|
|
21
|
-
params
|
|
21
|
+
params,
|
|
22
22
|
});
|
|
23
23
|
return resp;
|
|
24
24
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/manual/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SafeContractConfig } from "../config/index.ts";
|
|
3
|
-
import { SafeTransaction, ManualOverrides } from "../types.ts";
|
|
1
|
+
import type { SafeContractConfig } from "../config/index.ts";
|
|
4
2
|
import { ManualTransactionResponse } from "../response/index.ts";
|
|
5
|
-
|
|
3
|
+
import type { RelayerSigner } from "../signer/index.ts";
|
|
4
|
+
import type { ManualOverrides, SafeTransaction } from "../types.ts";
|
|
5
|
+
export declare function executeManualTransactions(signer: RelayerSigner, safeContractConfig: SafeContractConfig, transactions: SafeTransaction[], overrides: ManualOverrides): Promise<ManualTransactionResponse>;
|
package/dist/manual/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { encodePacked, hexToBigInt, zeroAddress } from "viem";
|
|
2
|
-
import { encodeFunctionData, prepareEncodeFunctionData } from "viem";
|
|
1
|
+
import { encodeFunctionData, encodePacked, hexToBigInt, prepareEncodeFunctionData, zeroAddress, } from "viem";
|
|
3
2
|
import { safeAbi } from "../abis/index.js";
|
|
4
3
|
import { aggregateTransaction, deriveSafe } from "../builder/index.js";
|
|
5
4
|
import { ManualTransactionResponse } from "../response/index.js";
|
|
6
5
|
const safeExecTransaction = prepareEncodeFunctionData({
|
|
7
6
|
abi: safeAbi,
|
|
8
|
-
functionName:
|
|
7
|
+
functionName: "execTransaction",
|
|
9
8
|
});
|
|
10
9
|
export async function executeManualTransactions(signer, safeContractConfig, transactions, overrides) {
|
|
11
10
|
const from = await signer.getAddress();
|
|
@@ -13,7 +12,9 @@ export async function executeManualTransactions(signer, safeContractConfig, tran
|
|
|
13
12
|
const sig = encodePacked(["uint256", "uint256", "uint8"], [BigInt(hexToBigInt(from)), BigInt(0), 1]);
|
|
14
13
|
const safeAddress = deriveSafe(from, safeContractConfig.SafeFactory);
|
|
15
14
|
// calldata
|
|
16
|
-
const data = encodeFunctionData({
|
|
15
|
+
const data = encodeFunctionData({
|
|
16
|
+
...safeExecTransaction,
|
|
17
|
+
args: [
|
|
17
18
|
aggTxn.to,
|
|
18
19
|
aggTxn.value,
|
|
19
20
|
aggTxn.data,
|
|
@@ -24,8 +25,9 @@ export async function executeManualTransactions(signer, safeContractConfig, tran
|
|
|
24
25
|
zeroAddress,
|
|
25
26
|
zeroAddress,
|
|
26
27
|
sig,
|
|
27
|
-
]
|
|
28
|
-
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
if (overrides.gasLimit === undefined) {
|
|
29
31
|
const gasLimit = await signer.estimateGas({
|
|
30
32
|
to: safeAddress,
|
|
31
33
|
data: data,
|
package/dist/response/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RelayClient } from "../client.ts";
|
|
2
|
-
import { IManualTransactionResponse, RelayerTransaction, RelayerTransactionResponse } from "../types.ts";
|
|
1
|
+
import type { RelayClient } from "../client.ts";
|
|
2
|
+
import { type IManualTransactionResponse, type RelayerTransaction, type RelayerTransactionResponse } from "../types.ts";
|
|
3
3
|
export declare class ClientRelayerTransactionResponse implements RelayerTransactionResponse {
|
|
4
4
|
readonly client: RelayClient;
|
|
5
5
|
readonly transactionID: string;
|
package/dist/response/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RelayerTransactionState } from "../types.js";
|
|
1
|
+
import { RelayerTransactionState, } from "../types.js";
|
|
2
2
|
export class ClientRelayerTransactionResponse {
|
|
3
3
|
client;
|
|
4
4
|
transactionID;
|
|
@@ -16,10 +16,7 @@ export class ClientRelayerTransactionResponse {
|
|
|
16
16
|
return this.client.getTransaction(this.transactionID);
|
|
17
17
|
}
|
|
18
18
|
async wait() {
|
|
19
|
-
return this.client.pollUntilState(this.transactionID, [
|
|
20
|
-
RelayerTransactionState.STATE_MINED,
|
|
21
|
-
RelayerTransactionState.STATE_CONFIRMED,
|
|
22
|
-
], RelayerTransactionState.STATE_FAILED, 30);
|
|
19
|
+
return this.client.pollUntilState(this.transactionID, [RelayerTransactionState.STATE_MINED, RelayerTransactionState.STATE_CONFIRMED], RelayerTransactionState.STATE_FAILED, 30);
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
22
|
export class ManualTransactionResponse {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type WalletClient } from "viem";
|
|
2
|
+
type TypedDataDomain = Record<string, unknown>;
|
|
3
|
+
type TypedDataTypes = Record<string, Array<{
|
|
4
|
+
name: string;
|
|
5
|
+
type: string;
|
|
6
|
+
}>>;
|
|
7
|
+
type TypedDataValue = Record<string, unknown>;
|
|
8
|
+
export interface Transaction {
|
|
9
|
+
from?: string;
|
|
10
|
+
to?: string;
|
|
11
|
+
nonce?: number;
|
|
12
|
+
gasLimit?: bigint;
|
|
13
|
+
gasPrice?: bigint;
|
|
14
|
+
data?: string;
|
|
15
|
+
value?: bigint;
|
|
16
|
+
}
|
|
17
|
+
export interface RelayerSigner {
|
|
18
|
+
signMessage(message: string): Promise<string>;
|
|
19
|
+
signTypedData(domain: TypedDataDomain, types: TypedDataTypes, value: TypedDataValue, primaryType?: string): Promise<string>;
|
|
20
|
+
getAddress(): Promise<string>;
|
|
21
|
+
estimateGas(tx: Transaction): Promise<bigint>;
|
|
22
|
+
sendTransaction(tx: Transaction): Promise<string>;
|
|
23
|
+
waitTillMined(txHash: string): Promise<unknown>;
|
|
24
|
+
}
|
|
25
|
+
export declare function createViemSigner(chainId: number, walletClient: WalletClient): RelayerSigner;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { createPublicClient, toBytes, } from "viem";
|
|
2
|
+
import { polygon, polygonAmoy } from "viem/chains";
|
|
3
|
+
function chainIdToChain(chainId) {
|
|
4
|
+
switch (chainId) {
|
|
5
|
+
case 137:
|
|
6
|
+
return polygon;
|
|
7
|
+
case 80002:
|
|
8
|
+
return polygonAmoy;
|
|
9
|
+
default:
|
|
10
|
+
throw new Error(`unsupported chainId ${chainId}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function getWalletClientAddress(walletClient) {
|
|
14
|
+
const accountAddress = walletClient.account?.address;
|
|
15
|
+
if (typeof accountAddress === "string" && accountAddress.length > 0) {
|
|
16
|
+
return accountAddress;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const [address] = await walletClient.getAddresses();
|
|
20
|
+
if (typeof address === "string" && address.length > 0) {
|
|
21
|
+
return address;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Fall back to requestAddresses for wallets that require user interaction.
|
|
26
|
+
}
|
|
27
|
+
const [requestedAddress] = await walletClient.requestAddresses();
|
|
28
|
+
if (typeof requestedAddress === "string" && requestedAddress.length > 0) {
|
|
29
|
+
return requestedAddress;
|
|
30
|
+
}
|
|
31
|
+
throw new Error("wallet client is missing account address");
|
|
32
|
+
}
|
|
33
|
+
async function getWalletClientAccount(walletClient) {
|
|
34
|
+
if (walletClient.account !== undefined) {
|
|
35
|
+
return walletClient.account;
|
|
36
|
+
}
|
|
37
|
+
return getWalletClientAddress(walletClient);
|
|
38
|
+
}
|
|
39
|
+
export function createViemSigner(chainId, walletClient) {
|
|
40
|
+
if (walletClient.chain !== undefined && walletClient.chain.id !== chainId) {
|
|
41
|
+
throw new Error("wallet client chain id does not match chain id");
|
|
42
|
+
}
|
|
43
|
+
const chain = walletClient.chain ?? chainIdToChain(chainId);
|
|
44
|
+
const walletTransport = walletClient.transport;
|
|
45
|
+
const transport = () => ({
|
|
46
|
+
config: walletTransport.config,
|
|
47
|
+
name: walletTransport.name,
|
|
48
|
+
request: walletTransport.request,
|
|
49
|
+
type: walletTransport.type,
|
|
50
|
+
value: walletTransport.value,
|
|
51
|
+
});
|
|
52
|
+
const publicClient = createPublicClient({
|
|
53
|
+
chain,
|
|
54
|
+
transport,
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
async signMessage(message) {
|
|
58
|
+
const account = await getWalletClientAccount(walletClient);
|
|
59
|
+
return walletClient.signMessage({
|
|
60
|
+
account,
|
|
61
|
+
message: { raw: toBytes(message) },
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
async signTypedData(domain, types, value, primaryType) {
|
|
65
|
+
if (primaryType === undefined) {
|
|
66
|
+
throw new Error("primaryType is required in viem signers");
|
|
67
|
+
}
|
|
68
|
+
const account = await getWalletClientAccount(walletClient);
|
|
69
|
+
return walletClient.signTypedData({
|
|
70
|
+
account,
|
|
71
|
+
domain,
|
|
72
|
+
types,
|
|
73
|
+
primaryType,
|
|
74
|
+
message: value,
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
async getAddress() {
|
|
78
|
+
return getWalletClientAddress(walletClient);
|
|
79
|
+
},
|
|
80
|
+
async estimateGas(tx) {
|
|
81
|
+
const account = tx.from ?? (await getWalletClientAddress(walletClient));
|
|
82
|
+
return publicClient.estimateGas({
|
|
83
|
+
account: account,
|
|
84
|
+
to: tx.to,
|
|
85
|
+
data: tx.data,
|
|
86
|
+
value: tx.value,
|
|
87
|
+
nonce: tx.nonce,
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
async sendTransaction(tx) {
|
|
91
|
+
const account = await getWalletClientAccount(walletClient);
|
|
92
|
+
return walletClient.sendTransaction({
|
|
93
|
+
account,
|
|
94
|
+
chain,
|
|
95
|
+
to: tx.to,
|
|
96
|
+
data: tx.data,
|
|
97
|
+
value: tx.value,
|
|
98
|
+
gas: tx.gasLimit,
|
|
99
|
+
gasPrice: tx.gasPrice,
|
|
100
|
+
nonce: tx.nonce,
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
async waitTillMined(txHash) {
|
|
104
|
+
return publicClient.waitForTransactionReceipt({
|
|
105
|
+
hash: txHash,
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
}
|
package/dist/types.js
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { encodePacked, hexToBigInt } from "viem";
|
|
2
2
|
export function splitAndPackSig(sig) {
|
|
3
3
|
const splitSig = splitSignature(sig);
|
|
4
|
-
const packedSig = encodePacked(["uint256", "uint256", "uint8"], [BigInt(splitSig.r), BigInt(splitSig.s), parseInt(splitSig.v)]);
|
|
4
|
+
const packedSig = encodePacked(["uint256", "uint256", "uint8"], [BigInt(splitSig.r), BigInt(splitSig.s), parseInt(splitSig.v, 10)]);
|
|
5
5
|
return packedSig;
|
|
6
6
|
}
|
|
7
7
|
function splitSignature(sig) {
|
|
@@ -20,9 +20,9 @@ function splitSignature(sig) {
|
|
|
20
20
|
}
|
|
21
21
|
sig = sig.slice(0, -2) + sigV.toString(16);
|
|
22
22
|
return {
|
|
23
|
-
r: hexToBigInt(
|
|
24
|
-
s: hexToBigInt(
|
|
25
|
-
v: hexToBigInt(
|
|
23
|
+
r: hexToBigInt(`0x${sig.slice(2, 66)}`).toString(),
|
|
24
|
+
s: hexToBigInt(`0x${sig.slice(66, 130)}`).toString(),
|
|
25
|
+
v: hexToBigInt(`0x${sig.slice(130, 132)}`).toString(),
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
export function sleep(ms) {
|
package/package.json
CHANGED
|
@@ -1,46 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polymarket/relayer-client",
|
|
3
3
|
"description": "Client for Polymarket relayers",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.1.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
8
14
|
"files": [
|
|
9
15
|
"/dist"
|
|
10
16
|
],
|
|
11
17
|
"sideEffects": false,
|
|
12
18
|
"scripts": {
|
|
13
|
-
"build": "
|
|
19
|
+
"build": "tsc --project tsconfig.production.json",
|
|
20
|
+
"check": "biome check .",
|
|
14
21
|
"clean": "rm -rf ./dist",
|
|
15
|
-
"
|
|
22
|
+
"format": "biome format --write .",
|
|
23
|
+
"test": "vitest run"
|
|
16
24
|
},
|
|
17
25
|
"devDependencies": {
|
|
18
|
-
"@
|
|
19
|
-
"@types/
|
|
20
|
-
"@types/node": "^18.7.18",
|
|
26
|
+
"@biomejs/biome": "2.4.5",
|
|
27
|
+
"@types/node": "^22.13.10",
|
|
21
28
|
"@types/ws": "^8.5.3",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"jsdom": "^20.0.0",
|
|
26
|
-
"jsdom-global": "^3.0.2",
|
|
27
|
-
"mocha": "9.2.2",
|
|
28
|
-
"path": "^0.12.7",
|
|
29
|
-
"prettier": "^2.7.1",
|
|
30
|
-
"ts-node": "^9.1.1",
|
|
31
|
-
"tsconfig-paths": "^4.2.0",
|
|
32
|
-
"tslib": "^2.8.1",
|
|
33
|
-
"tsx": "^4.20.3",
|
|
34
|
-
"typescript": "^5.8.3",
|
|
29
|
+
"dotenv": "^17.3.1",
|
|
30
|
+
"typescript": "^5.9.3",
|
|
31
|
+
"vitest": "^4.0.18",
|
|
35
32
|
"ws": "^8.11.0"
|
|
36
33
|
},
|
|
37
34
|
"dependencies": {
|
|
38
|
-
"@ethersproject/providers": "5.7.2",
|
|
39
|
-
"@ethersproject/wallet": "5.7.0",
|
|
40
|
-
"@polymarket/abstract-signer": "0.0.8",
|
|
41
35
|
"axios": "^1.13.2",
|
|
42
36
|
"browser-or-node": "^3.0.0",
|
|
43
|
-
"
|
|
44
|
-
"viem": "^2.31.4"
|
|
37
|
+
"viem": "^2.47.0"
|
|
45
38
|
}
|
|
46
39
|
}
|