@polymarket/relayer-client 2.0.2 → 3.0.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/abis/erc20Abi.js +1 -4
- package/dist/abis/index.d.ts +5 -5
- package/dist/abis/index.js +5 -8
- package/dist/abis/multisend.js +1 -4
- package/dist/abis/proxyFactory.js +1 -4
- package/dist/abis/safe.js +1 -4
- package/dist/abis/safeFactory.js +1 -4
- package/dist/auth/handler.d.ts +2 -2
- package/dist/auth/handler.js +3 -7
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +1 -4
- package/dist/builder/create.d.ts +2 -2
- package/dist/builder/create.js +7 -10
- package/dist/builder/derive.js +10 -15
- package/dist/builder/index.d.ts +4 -4
- package/dist/builder/index.js +4 -7
- package/dist/builder/proxy.d.ts +2 -2
- package/dist/builder/proxy.js +13 -16
- package/dist/builder/safe.d.ts +2 -2
- package/dist/builder/safe.js +14 -18
- package/dist/client.d.ts +4 -4
- package/dist/client.js +38 -43
- package/dist/config/index.js +1 -5
- package/dist/constants/index.js +3 -6
- package/dist/encode/index.d.ts +2 -2
- package/dist/encode/index.js +2 -5
- package/dist/encode/proxy.d.ts +1 -1
- package/dist/encode/proxy.js +6 -9
- package/dist/encode/safe.d.ts +1 -1
- package/dist/encode/safe.js +9 -13
- package/dist/endpoints.js +5 -8
- package/dist/http-helpers/index.js +8 -13
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -7
- package/dist/manual/index.d.ts +3 -3
- package/dist/manual/index.js +15 -18
- package/dist/response/index.d.ts +2 -2
- package/dist/response/index.js +6 -11
- package/dist/types.js +8 -11
- package/dist/utils/index.js +7 -11
- package/package.json +9 -5
package/dist/abis/erc20Abi.js
CHANGED
package/dist/abis/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from "./safeFactory";
|
|
2
|
-
export * from "./proxyFactory";
|
|
3
|
-
export * from "./erc20Abi";
|
|
4
|
-
export * from "./safe";
|
|
5
|
-
export * from "./multisend";
|
|
1
|
+
export * from "./safeFactory.ts";
|
|
2
|
+
export * from "./proxyFactory.ts";
|
|
3
|
+
export * from "./erc20Abi.ts";
|
|
4
|
+
export * from "./safe.ts";
|
|
5
|
+
export * from "./multisend.ts";
|
package/dist/abis/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
tslib_1.__exportStar(require("./erc20Abi"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./safe"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./multisend"), exports);
|
|
1
|
+
export * from "./safeFactory.js";
|
|
2
|
+
export * from "./proxyFactory.js";
|
|
3
|
+
export * from "./erc20Abi.js";
|
|
4
|
+
export * from "./safe.js";
|
|
5
|
+
export * from "./multisend.js";
|
package/dist/abis/multisend.js
CHANGED
package/dist/abis/safe.js
CHANGED
package/dist/abis/safeFactory.js
CHANGED
package/dist/auth/handler.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpClient } from "../http-helpers";
|
|
2
|
-
import { AuthArgs } from "../types";
|
|
1
|
+
import { HttpClient } from "../http-helpers/index.ts";
|
|
2
|
+
import { AuthArgs } from "../types.ts";
|
|
3
3
|
export declare class AuthHandler {
|
|
4
4
|
readonly url: string;
|
|
5
5
|
readonly httpClient: HttpClient;
|
package/dist/auth/handler.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AuthHandler = void 0;
|
|
4
|
-
const http_helpers_1 = require("../http-helpers");
|
|
1
|
+
import { GET } from "../http-helpers/index.js";
|
|
5
2
|
const POLYMARKET_COOKIE_NAME = "polymarket";
|
|
6
|
-
class AuthHandler {
|
|
3
|
+
export class AuthHandler {
|
|
7
4
|
url;
|
|
8
5
|
httpClient;
|
|
9
6
|
token;
|
|
@@ -23,7 +20,7 @@ class AuthHandler {
|
|
|
23
20
|
async login() {
|
|
24
21
|
if (this.cookie == undefined) {
|
|
25
22
|
// Logging in will set the session cookies on the httpClient
|
|
26
|
-
const resp = await this.httpClient.send(`${this.url}/login/internal`,
|
|
23
|
+
const resp = await this.httpClient.send(`${this.url}/login/internal`, GET, { Authorization: `Bearer ${this.token}` });
|
|
27
24
|
const cookies = resp.headers['set-cookie'];
|
|
28
25
|
let aggregatedCookie = "";
|
|
29
26
|
for (const cookie of cookies) {
|
|
@@ -45,4 +42,3 @@ class AuthHandler {
|
|
|
45
42
|
return this.cookie;
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
|
-
exports.AuthHandler = AuthHandler;
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./handler";
|
|
1
|
+
export * from "./handler.ts";
|
package/dist/auth/index.js
CHANGED
package/dist/builder/create.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SafeCreateTransactionArgs, TransactionRequest } from "../types";
|
|
1
|
+
import { SafeCreateTransactionArgs, TransactionRequest } from "../types.ts";
|
|
2
2
|
import { IAbstractSigner } from "@polymarket/abstract-signer";
|
|
3
|
-
import { SafeContractConfig } from "../config";
|
|
3
|
+
import { SafeContractConfig } from "../config/index.ts";
|
|
4
4
|
export declare function buildSafeCreateTransactionRequest(signer: IAbstractSigner, safeContractConfig: SafeContractConfig, args: SafeCreateTransactionArgs): Promise<TransactionRequest>;
|
package/dist/builder/create.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const derive_1 = require("./derive");
|
|
1
|
+
import { TransactionType } from "../types.js";
|
|
2
|
+
import { SAFE_FACTORY_NAME } from "../constants/index.js";
|
|
3
|
+
import { deriveSafe } from "./derive.js";
|
|
7
4
|
async function createSafeCreateSignature(signer, safeFactory, chainId, paymentToken, payment, paymentReceiver) {
|
|
8
5
|
const domain = {
|
|
9
|
-
name:
|
|
6
|
+
name: SAFE_FACTORY_NAME,
|
|
10
7
|
chainId: BigInt(chainId),
|
|
11
8
|
verifyingContract: safeFactory,
|
|
12
9
|
};
|
|
@@ -26,7 +23,7 @@ async function createSafeCreateSignature(signer, safeFactory, chainId, paymentTo
|
|
|
26
23
|
console.log(`Sig: ${sig}`);
|
|
27
24
|
return sig;
|
|
28
25
|
}
|
|
29
|
-
async function buildSafeCreateTransactionRequest(signer, safeContractConfig, args) {
|
|
26
|
+
export async function buildSafeCreateTransactionRequest(signer, safeContractConfig, args) {
|
|
30
27
|
const safeFactory = safeContractConfig.SafeFactory;
|
|
31
28
|
const sig = await createSafeCreateSignature(signer, safeFactory, args.chainId, args.paymentToken, args.payment, args.paymentReceiver);
|
|
32
29
|
const sigParams = {
|
|
@@ -34,7 +31,7 @@ async function buildSafeCreateTransactionRequest(signer, safeContractConfig, arg
|
|
|
34
31
|
payment: args.payment,
|
|
35
32
|
paymentReceiver: args.paymentReceiver,
|
|
36
33
|
};
|
|
37
|
-
const safeAddress =
|
|
34
|
+
const safeAddress = deriveSafe(args.from, safeFactory);
|
|
38
35
|
const request = {
|
|
39
36
|
from: args.from,
|
|
40
37
|
to: safeFactory,
|
|
@@ -43,7 +40,7 @@ async function buildSafeCreateTransactionRequest(signer, safeContractConfig, arg
|
|
|
43
40
|
data: "0x",
|
|
44
41
|
signature: sig,
|
|
45
42
|
signatureParams: sigParams,
|
|
46
|
-
type:
|
|
43
|
+
type: TransactionType.SAFE_CREATE,
|
|
47
44
|
};
|
|
48
45
|
console.log(`Created a SAFE-CREATE Transaction:`);
|
|
49
46
|
console.log(request);
|
package/dist/builder/derive.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const deriveProxyWallet = (address, proxyFactory) => {
|
|
7
|
-
return (0, viem_1.getCreate2Address)({
|
|
8
|
-
bytecodeHash: constants_1.PROXY_INIT_CODE_HASH,
|
|
1
|
+
import { keccak256, encodePacked, getCreate2Address, encodeAbiParameters } from 'viem';
|
|
2
|
+
import { SAFE_INIT_CODE_HASH, PROXY_INIT_CODE_HASH } from "../constants/index.js";
|
|
3
|
+
export const deriveProxyWallet = (address, proxyFactory) => {
|
|
4
|
+
return getCreate2Address({
|
|
5
|
+
bytecodeHash: PROXY_INIT_CODE_HASH,
|
|
9
6
|
from: proxyFactory,
|
|
10
|
-
salt:
|
|
7
|
+
salt: keccak256(encodePacked(["address"], [address]))
|
|
11
8
|
});
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
bytecodeHash: constants_1.SAFE_INIT_CODE_HASH,
|
|
10
|
+
export const deriveSafe = (address, safeFactory) => {
|
|
11
|
+
return getCreate2Address({
|
|
12
|
+
bytecodeHash: SAFE_INIT_CODE_HASH,
|
|
17
13
|
from: safeFactory,
|
|
18
|
-
salt:
|
|
14
|
+
salt: keccak256(encodeAbiParameters([{ name: 'address', type: 'address' }], [address]))
|
|
19
15
|
});
|
|
20
16
|
};
|
|
21
|
-
exports.deriveSafe = deriveSafe;
|
package/dist/builder/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./proxy";
|
|
2
|
-
export * from "./safe";
|
|
3
|
-
export * from "./create";
|
|
4
|
-
export * from "./derive";
|
|
1
|
+
export * from "./proxy.ts";
|
|
2
|
+
export * from "./safe.ts";
|
|
3
|
+
export * from "./create.ts";
|
|
4
|
+
export * from "./derive.ts";
|
package/dist/builder/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
tslib_1.__exportStar(require("./safe"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./create"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./derive"), exports);
|
|
1
|
+
export * from "./proxy.js";
|
|
2
|
+
export * from "./safe.js";
|
|
3
|
+
export * from "./create.js";
|
|
4
|
+
export * from "./derive.js";
|
package/dist/builder/proxy.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IAbstractSigner } from "@polymarket/abstract-signer";
|
|
2
|
-
import { ProxyTransactionArgs, TransactionRequest } from "../types";
|
|
3
|
-
import { ProxyContractConfig } from "../config";
|
|
2
|
+
import { ProxyTransactionArgs, TransactionRequest } from "../types.ts";
|
|
3
|
+
import { ProxyContractConfig } from "../config/index.ts";
|
|
4
4
|
export declare function buildProxyTransactionRequest(signer: IAbstractSigner, args: ProxyTransactionArgs, proxyContractConfig: ProxyContractConfig, metadata?: string): Promise<TransactionRequest>;
|
package/dist/builder/proxy.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const viem_1 = require("viem");
|
|
5
|
-
const types_1 = require("../types");
|
|
6
|
-
const derive_1 = require("./derive");
|
|
1
|
+
import { concat, keccak256, toHex } from "viem";
|
|
2
|
+
import { TransactionType } from "../types.js";
|
|
3
|
+
import { deriveProxyWallet } from "./derive.js";
|
|
7
4
|
function createStructHash(from, to, data, txFee, gasPrice, gasLimit, nonce, relayHubAddress, relayAddress) {
|
|
8
|
-
const relayHubPrefix =
|
|
5
|
+
const relayHubPrefix = toHex("rlx:");
|
|
9
6
|
const encodedFrom = from;
|
|
10
7
|
const encodedTo = to;
|
|
11
8
|
const encodedData = data;
|
|
12
|
-
const encodedTxFee =
|
|
13
|
-
const encodedGasPrice =
|
|
14
|
-
const encodedGasLimit =
|
|
15
|
-
const encodedNonce =
|
|
9
|
+
const encodedTxFee = toHex(BigInt(txFee), { size: 32 });
|
|
10
|
+
const encodedGasPrice = toHex(BigInt(gasPrice), { size: 32 });
|
|
11
|
+
const encodedGasLimit = toHex(BigInt(gasLimit), { size: 32 });
|
|
12
|
+
const encodedNonce = toHex(BigInt(nonce), { size: 32 });
|
|
16
13
|
const encodedRelayHubAddress = relayHubAddress;
|
|
17
14
|
const encodedRelayAddress = relayAddress;
|
|
18
|
-
const dataToHash =
|
|
15
|
+
const dataToHash = concat([
|
|
19
16
|
relayHubPrefix,
|
|
20
17
|
encodedFrom,
|
|
21
18
|
encodedTo,
|
|
@@ -27,15 +24,15 @@ function createStructHash(from, to, data, txFee, gasPrice, gasLimit, nonce, rela
|
|
|
27
24
|
encodedRelayHubAddress,
|
|
28
25
|
encodedRelayAddress,
|
|
29
26
|
]);
|
|
30
|
-
return
|
|
27
|
+
return keccak256(dataToHash);
|
|
31
28
|
}
|
|
32
29
|
async function createProxySignature(signer, structHash) {
|
|
33
30
|
return signer.signMessage(structHash);
|
|
34
31
|
}
|
|
35
|
-
async function buildProxyTransactionRequest(signer, args, proxyContractConfig, metadata) {
|
|
32
|
+
export async function buildProxyTransactionRequest(signer, args, proxyContractConfig, metadata) {
|
|
36
33
|
const proxyWalletFactory = proxyContractConfig.ProxyFactory;
|
|
37
34
|
const to = proxyWalletFactory;
|
|
38
|
-
const proxy =
|
|
35
|
+
const proxy = deriveProxyWallet(args.from, proxyWalletFactory);
|
|
39
36
|
const relayerFee = "0";
|
|
40
37
|
const relayHub = proxyContractConfig.RelayHub;
|
|
41
38
|
const gasLimit = args.gasLimit ? args.gasLimit : await signer.estimateGas({
|
|
@@ -64,7 +61,7 @@ async function buildProxyTransactionRequest(signer, args, proxyContractConfig, m
|
|
|
64
61
|
nonce: args.nonce,
|
|
65
62
|
signature: sig,
|
|
66
63
|
signatureParams: sigParams,
|
|
67
|
-
type:
|
|
64
|
+
type: TransactionType.PROXY,
|
|
68
65
|
metadata: metadata,
|
|
69
66
|
};
|
|
70
67
|
console.log(`Created Proxy Transaction Request:`);
|
package/dist/builder/safe.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAbstractSigner } from "@polymarket/abstract-signer";
|
|
2
|
-
import { SafeTransaction, SafeTransactionArgs, TransactionRequest } from "../types";
|
|
3
|
-
import { SafeContractConfig } from "../config";
|
|
2
|
+
import { SafeTransaction, SafeTransactionArgs, TransactionRequest } from "../types.ts";
|
|
3
|
+
import { SafeContractConfig } from "../config/index.ts";
|
|
4
4
|
export declare function aggregateTransaction(txns: SafeTransaction[], safeMultisend: string): SafeTransaction;
|
|
5
5
|
export declare function buildSafeTransactionRequest(signer: IAbstractSigner, args: SafeTransactionArgs, safeContractConfig: SafeContractConfig, metadata?: string): Promise<TransactionRequest>;
|
package/dist/builder/safe.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const types_1 = require("../types");
|
|
7
|
-
const derive_1 = require("./derive");
|
|
8
|
-
const safe_1 = require("../encode/safe");
|
|
9
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import { hashTypedData, zeroAddress } from "viem";
|
|
2
|
+
import { TransactionType } from "../types.js";
|
|
3
|
+
import { deriveSafe } from "./derive.js";
|
|
4
|
+
import { createSafeMultisendTransaction } from "../encode/safe.js";
|
|
5
|
+
import { splitAndPackSig } from "../utils/index.js";
|
|
10
6
|
async function createSafeSignature(signer, structHash) {
|
|
11
7
|
return signer.signMessage(structHash);
|
|
12
8
|
}
|
|
@@ -46,36 +42,36 @@ function createStructHash(chainId, safe, to, value, data, operation, safeTxGas,
|
|
|
46
42
|
};
|
|
47
43
|
// // viem hashTypedData
|
|
48
44
|
// const structHash = _TypedDataEncoder.hash(domain, types, values);
|
|
49
|
-
const structHash =
|
|
45
|
+
const structHash = hashTypedData({ primaryType: "SafeTx", domain: domain, types: types, message: values });
|
|
50
46
|
return structHash;
|
|
51
47
|
}
|
|
52
|
-
function aggregateTransaction(txns, safeMultisend) {
|
|
48
|
+
export function aggregateTransaction(txns, safeMultisend) {
|
|
53
49
|
let transaction;
|
|
54
50
|
if (txns.length == 1) {
|
|
55
51
|
transaction = txns[0];
|
|
56
52
|
}
|
|
57
53
|
else {
|
|
58
|
-
transaction =
|
|
54
|
+
transaction = createSafeMultisendTransaction(txns, safeMultisend);
|
|
59
55
|
}
|
|
60
56
|
return transaction;
|
|
61
57
|
}
|
|
62
|
-
async function buildSafeTransactionRequest(signer, args, safeContractConfig, metadata) {
|
|
58
|
+
export async function buildSafeTransactionRequest(signer, args, safeContractConfig, metadata) {
|
|
63
59
|
const safeFactory = safeContractConfig.SafeFactory;
|
|
64
60
|
const safeMultisend = safeContractConfig.SafeMultisend;
|
|
65
61
|
const transaction = aggregateTransaction(args.transactions, safeMultisend);
|
|
66
62
|
const safeTxnGas = "0";
|
|
67
63
|
const baseGas = "0";
|
|
68
64
|
const gasPrice = "0";
|
|
69
|
-
const gasToken =
|
|
70
|
-
const refundReceiver =
|
|
71
|
-
const safeAddress =
|
|
65
|
+
const gasToken = zeroAddress;
|
|
66
|
+
const refundReceiver = zeroAddress;
|
|
67
|
+
const safeAddress = deriveSafe(args.from, safeFactory);
|
|
72
68
|
// Generate the struct hash
|
|
73
69
|
// NOTE: this includes a client side optimization over the current relayers
|
|
74
70
|
// Generates struct hash locally instead of going across the network using the RPC call
|
|
75
71
|
const structHash = createStructHash(args.chainId, safeAddress, transaction.to, transaction.value, transaction.data, transaction.operation, safeTxnGas, baseGas, gasPrice, gasToken, refundReceiver, args.nonce);
|
|
76
72
|
const sig = await createSafeSignature(signer, structHash);
|
|
77
73
|
// Split the sig then pack it into Gnosis accepted rsv format
|
|
78
|
-
const packedSig =
|
|
74
|
+
const packedSig = splitAndPackSig(sig);
|
|
79
75
|
const sigParams = {
|
|
80
76
|
gasPrice,
|
|
81
77
|
operation: `${transaction.operation}`,
|
|
@@ -95,7 +91,7 @@ async function buildSafeTransactionRequest(signer, args, safeContractConfig, met
|
|
|
95
91
|
nonce: args.nonce,
|
|
96
92
|
signature: packedSig,
|
|
97
93
|
signatureParams: sigParams,
|
|
98
|
-
type:
|
|
94
|
+
type: TransactionType.SAFE,
|
|
99
95
|
metadata: metadata,
|
|
100
96
|
};
|
|
101
97
|
console.log(`Created Safe Transaction Request: `);
|
package/dist/client.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { Wallet } from "@ethersproject/wallet";
|
|
|
2
2
|
import { JsonRpcSigner } from "@ethersproject/providers";
|
|
3
3
|
import { WalletClient } from "viem";
|
|
4
4
|
import { IAbstractSigner } from "@polymarket/abstract-signer";
|
|
5
|
-
import { HttpClient } from "./http-helpers";
|
|
6
|
-
import { AddressPayload, AuthArgs, IManualTransactionResponse, ManualOverrides, NoncePayload, ProxyTransaction, RelayerTransaction, RelayerTransactionResponse, RelayPayload, SafeTransaction } from "./types";
|
|
7
|
-
import { AuthHandler } from "./auth";
|
|
8
|
-
import { ContractConfig } from "./config";
|
|
5
|
+
import { HttpClient } from "./http-helpers/index.ts";
|
|
6
|
+
import { AddressPayload, AuthArgs, IManualTransactionResponse, ManualOverrides, NoncePayload, ProxyTransaction, RelayerTransaction, RelayerTransactionResponse, RelayPayload, SafeTransaction } from "./types.ts";
|
|
7
|
+
import { AuthHandler } from "./auth/handler.ts";
|
|
8
|
+
import { ContractConfig } from "./config/index.ts";
|
|
9
9
|
export declare class RelayClient {
|
|
10
10
|
readonly relayerUrl: string;
|
|
11
11
|
readonly chainId: number;
|
package/dist/client.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const manual_1 = require("./manual");
|
|
16
|
-
const response_1 = require("./response");
|
|
17
|
-
const config_1 = require("./config");
|
|
18
|
-
class RelayClient {
|
|
1
|
+
import { isBrowser } from "browser-or-node";
|
|
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
|
+
import { AuthHandler } from "./auth/handler.js";
|
|
10
|
+
import { sleep } from "./utils/index.js";
|
|
11
|
+
import { executeManualTransactions } from "./manual/index.js";
|
|
12
|
+
import { ClientRelayerTransactionResponse } from "./response/index.js";
|
|
13
|
+
import { getContractConfig } from "./config/index.js";
|
|
14
|
+
export class RelayClient {
|
|
19
15
|
relayerUrl;
|
|
20
16
|
chainId;
|
|
21
17
|
contractConfig;
|
|
@@ -25,29 +21,29 @@ class RelayClient {
|
|
|
25
21
|
constructor(relayerUrl, chainId, signer, authArgs) {
|
|
26
22
|
this.relayerUrl = relayerUrl.endsWith("/") ? relayerUrl.slice(0, -1) : relayerUrl;
|
|
27
23
|
this.chainId = chainId;
|
|
28
|
-
this.contractConfig =
|
|
29
|
-
this.httpClient = new
|
|
24
|
+
this.contractConfig = getContractConfig(chainId);
|
|
25
|
+
this.httpClient = new HttpClient();
|
|
30
26
|
if (signer != undefined) {
|
|
31
|
-
this.signer =
|
|
27
|
+
this.signer = createAbstractSigner(chainId, signer);
|
|
32
28
|
}
|
|
33
29
|
if (authArgs !== undefined) {
|
|
34
|
-
this.authHandler = new
|
|
30
|
+
this.authHandler = new AuthHandler(this.httpClient, authArgs);
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
33
|
async getRelayAddress() {
|
|
38
|
-
return this.send(`${this.relayerUrl}${
|
|
34
|
+
return this.send(`${this.relayerUrl}${GET_ADDRESS}`, GET);
|
|
39
35
|
}
|
|
40
36
|
async getNonce(signerAddress, signerType) {
|
|
41
|
-
return this.send(`${this.relayerUrl}${
|
|
37
|
+
return this.send(`${this.relayerUrl}${GET_NONCE}?address=${signerAddress}&type=${signerType}`, GET);
|
|
42
38
|
}
|
|
43
39
|
async getRelayPayload(signerAddress, signerType) {
|
|
44
|
-
return this.send(`${this.relayerUrl}${
|
|
40
|
+
return this.send(`${this.relayerUrl}${GET_RELAY_PAYLOAD}?address=${signerAddress}&type=${signerType}`, GET);
|
|
45
41
|
}
|
|
46
42
|
async getTransaction(transactionId) {
|
|
47
|
-
return this.send(`${this.relayerUrl}${
|
|
43
|
+
return this.send(`${this.relayerUrl}${GET_TRANSACTION}?id=${transactionId}`, GET);
|
|
48
44
|
}
|
|
49
45
|
async getTransactions() {
|
|
50
|
-
return this.send(`${this.relayerUrl}${
|
|
46
|
+
return this.send(`${this.relayerUrl}${GET_TRANSACTION}s`, GET);
|
|
51
47
|
}
|
|
52
48
|
async executeProxyTransactions(txns, metadata) {
|
|
53
49
|
if (this.signer == undefined) {
|
|
@@ -55,19 +51,19 @@ class RelayClient {
|
|
|
55
51
|
}
|
|
56
52
|
const start = Date.now();
|
|
57
53
|
const from = await this.signer.getAddress();
|
|
58
|
-
const rp = await this.getRelayPayload(from,
|
|
54
|
+
const rp = await this.getRelayPayload(from, TransactionType.PROXY);
|
|
59
55
|
const args = {
|
|
60
56
|
from: from,
|
|
61
57
|
gasPrice: "0",
|
|
62
|
-
data:
|
|
58
|
+
data: encodeProxyTransactionData(txns),
|
|
63
59
|
relay: rp.address,
|
|
64
60
|
nonce: rp.nonce,
|
|
65
61
|
};
|
|
66
62
|
const proxyContractConfig = this.contractConfig.ProxyContracts;
|
|
67
|
-
const request = await
|
|
63
|
+
const request = await buildProxyTransactionRequest(this.signer, args, proxyContractConfig, metadata);
|
|
68
64
|
console.log(`Client side proxy request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
69
65
|
const resp = await this.submitTransaction(request);
|
|
70
|
-
return new
|
|
66
|
+
return new ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
|
|
71
67
|
}
|
|
72
68
|
async executeSafeTransactions(txns, metadata) {
|
|
73
69
|
if (this.signer == undefined) {
|
|
@@ -75,7 +71,7 @@ class RelayClient {
|
|
|
75
71
|
}
|
|
76
72
|
const start = Date.now();
|
|
77
73
|
const from = await this.signer.getAddress();
|
|
78
|
-
const noncePayload = await this.getNonce(from,
|
|
74
|
+
const noncePayload = await this.getNonce(from, TransactionType.SAFE);
|
|
79
75
|
const args = {
|
|
80
76
|
transactions: txns,
|
|
81
77
|
from,
|
|
@@ -83,10 +79,10 @@ class RelayClient {
|
|
|
83
79
|
chainId: this.chainId,
|
|
84
80
|
};
|
|
85
81
|
const safeContractConfig = this.contractConfig.SafeContracts;
|
|
86
|
-
const request = await
|
|
82
|
+
const request = await buildSafeTransactionRequest(this.signer, args, safeContractConfig, metadata);
|
|
87
83
|
console.log(`Client side safe request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
88
84
|
const resp = await this.submitTransaction(request);
|
|
89
|
-
return new
|
|
85
|
+
return new ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
|
|
90
86
|
}
|
|
91
87
|
async executeManualTransactions(txns, overrides) {
|
|
92
88
|
if (overrides == undefined) {
|
|
@@ -95,7 +91,7 @@ class RelayClient {
|
|
|
95
91
|
if (this.signer == undefined) {
|
|
96
92
|
throw new Error("missing signer");
|
|
97
93
|
}
|
|
98
|
-
return
|
|
94
|
+
return executeManualTransactions(this.signer, this.contractConfig.SafeContracts, txns, overrides);
|
|
99
95
|
}
|
|
100
96
|
async deploySafe() {
|
|
101
97
|
if (this.signer == undefined) {
|
|
@@ -106,15 +102,15 @@ class RelayClient {
|
|
|
106
102
|
const args = {
|
|
107
103
|
from: from,
|
|
108
104
|
chainId: this.chainId,
|
|
109
|
-
paymentToken:
|
|
105
|
+
paymentToken: zeroAddress,
|
|
110
106
|
payment: "0",
|
|
111
|
-
paymentReceiver:
|
|
107
|
+
paymentReceiver: zeroAddress,
|
|
112
108
|
};
|
|
113
109
|
const safeContractConfig = this.contractConfig.SafeContracts;
|
|
114
|
-
const request = await
|
|
110
|
+
const request = await buildSafeCreateTransactionRequest(this.signer, safeContractConfig, args);
|
|
115
111
|
console.log(`Client side deploy request creation took: ${(Date.now() - start) / 1000} seconds`);
|
|
116
112
|
const resp = await this.submitTransaction(request);
|
|
117
|
-
return new
|
|
113
|
+
return new ClientRelayerTransactionResponse(resp.transactionID, resp.state, resp.transactionHash, this);
|
|
118
114
|
}
|
|
119
115
|
/**
|
|
120
116
|
* Periodically polls the transaction id until it reaches a desired state
|
|
@@ -151,18 +147,18 @@ class RelayClient {
|
|
|
151
147
|
}
|
|
152
148
|
}
|
|
153
149
|
pollCount++;
|
|
154
|
-
await
|
|
150
|
+
await sleep(pollFreq);
|
|
155
151
|
}
|
|
156
152
|
console.log(`Transaction not found or not in given states, timing out`);
|
|
157
153
|
}
|
|
158
154
|
async submitTransaction(req) {
|
|
159
|
-
return this.send(`${this.relayerUrl}${
|
|
155
|
+
return this.send(`${this.relayerUrl}${SUBMIT_TRANSACTION}`, POST, undefined, req);
|
|
160
156
|
}
|
|
161
157
|
async send(endpoint, method, headers, data, params) {
|
|
162
158
|
// Explicitly inject the polymarket session cookies
|
|
163
159
|
// In prod environments, this will be unnecessary as the browser will have the needed cookies
|
|
164
160
|
// Needed only for local testing
|
|
165
|
-
if (!
|
|
161
|
+
if (!isBrowser && this.authHandler !== undefined) {
|
|
166
162
|
const cookie = await this.authHandler.getPolymarketCookies();
|
|
167
163
|
if (headers != undefined) {
|
|
168
164
|
headers["Cookie"] = cookie;
|
|
@@ -175,4 +171,3 @@ class RelayClient {
|
|
|
175
171
|
return resp.data;
|
|
176
172
|
}
|
|
177
173
|
}
|
|
178
|
-
exports.RelayClient = RelayClient;
|
package/dist/config/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getContractConfig = void 0;
|
|
4
1
|
;
|
|
5
2
|
const AMOY = {
|
|
6
3
|
ProxyContracts: {
|
|
@@ -22,7 +19,7 @@ const POL = {
|
|
|
22
19
|
SafeMultisend: "0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761",
|
|
23
20
|
}
|
|
24
21
|
};
|
|
25
|
-
const getContractConfig = (chainId) => {
|
|
22
|
+
export const getContractConfig = (chainId) => {
|
|
26
23
|
switch (chainId) {
|
|
27
24
|
case 137:
|
|
28
25
|
return POL;
|
|
@@ -32,4 +29,3 @@ const getContractConfig = (chainId) => {
|
|
|
32
29
|
throw new Error("Invalid network");
|
|
33
30
|
}
|
|
34
31
|
};
|
|
35
|
-
exports.getContractConfig = getContractConfig;
|
package/dist/constants/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.PROXY_INIT_CODE_HASH = "0xd21df8dc65880a8606f09fe0ce3df9b8869287ab0b058be05aa9e8af6330a00b";
|
|
5
|
-
exports.SAFE_INIT_CODE_HASH = "0x2bce2127ff07fb632d16c8347c4ebf501f4841168bed00d9e6ef715ddb6fcecf";
|
|
6
|
-
exports.SAFE_FACTORY_NAME = "Polymarket Contract Proxy Factory";
|
|
1
|
+
export const PROXY_INIT_CODE_HASH = "0xd21df8dc65880a8606f09fe0ce3df9b8869287ab0b058be05aa9e8af6330a00b";
|
|
2
|
+
export const SAFE_INIT_CODE_HASH = "0x2bce2127ff07fb632d16c8347c4ebf501f4841168bed00d9e6ef715ddb6fcecf";
|
|
3
|
+
export const SAFE_FACTORY_NAME = "Polymarket Contract Proxy Factory";
|
package/dist/encode/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./proxy";
|
|
2
|
-
export * from "./safe";
|
|
1
|
+
export * from "./proxy.ts";
|
|
2
|
+
export * from "./safe.ts";
|
package/dist/encode/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./proxy"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./safe"), exports);
|
|
1
|
+
export * from "./proxy.js";
|
|
2
|
+
export * from "./safe.js";
|
package/dist/encode/proxy.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ProxyTransaction } from "../types";
|
|
1
|
+
import { ProxyTransaction } from "../types.ts";
|
|
2
2
|
export declare function encodeProxyTransactionData(txns: ProxyTransaction[]): string;
|
package/dist/encode/proxy.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const viem_1 = require("viem");
|
|
6
|
-
const proxy = (0, viem_1.prepareEncodeFunctionData)({
|
|
7
|
-
abi: abis_1.proxyWalletFactory,
|
|
1
|
+
import { proxyWalletFactory } from "../abis/index.js";
|
|
2
|
+
import { encodeFunctionData, prepareEncodeFunctionData } from "viem";
|
|
3
|
+
const proxy = prepareEncodeFunctionData({
|
|
4
|
+
abi: proxyWalletFactory,
|
|
8
5
|
functionName: 'proxy',
|
|
9
6
|
});
|
|
10
|
-
function encodeProxyTransactionData(txns) {
|
|
11
|
-
return
|
|
7
|
+
export function encodeProxyTransactionData(txns) {
|
|
8
|
+
return encodeFunctionData({
|
|
12
9
|
...proxy,
|
|
13
10
|
args: [txns],
|
|
14
11
|
});
|
package/dist/encode/safe.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SafeTransaction } from "../types";
|
|
1
|
+
import { SafeTransaction } from "../types.ts";
|
|
2
2
|
export declare const createSafeMultisendTransaction: (txns: SafeTransaction[], safeMultisendAddress: string) => SafeTransaction;
|
package/dist/encode/safe.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const types_1 = require("../types");
|
|
7
|
-
const multisend = (0, viem_1.prepareEncodeFunctionData)({
|
|
8
|
-
abi: abis_1.multisendAbi,
|
|
1
|
+
import { concatHex, encodeFunctionData, encodePacked, prepareEncodeFunctionData, size } from "viem";
|
|
2
|
+
import { multisendAbi } from "../abis/index.js";
|
|
3
|
+
import { OperationType } from "../types.js";
|
|
4
|
+
const multisend = prepareEncodeFunctionData({
|
|
5
|
+
abi: multisendAbi,
|
|
9
6
|
functionName: "multiSend",
|
|
10
7
|
});
|
|
11
|
-
const createSafeMultisendTransaction = (txns, safeMultisendAddress) => {
|
|
8
|
+
export const createSafeMultisendTransaction = (txns, safeMultisendAddress) => {
|
|
12
9
|
const args = [
|
|
13
|
-
|
|
10
|
+
concatHex(txns.map(tx => encodePacked(["uint8", "address", "uint256", "uint256", "bytes"], [tx.operation, tx.to, BigInt(tx.value), BigInt(size(tx.data)), tx.data]))),
|
|
14
11
|
];
|
|
15
|
-
const data =
|
|
12
|
+
const data = encodeFunctionData({ ...multisend, args: args });
|
|
16
13
|
return {
|
|
17
14
|
to: safeMultisendAddress,
|
|
18
15
|
value: "0",
|
|
19
16
|
data: data,
|
|
20
|
-
operation:
|
|
17
|
+
operation: OperationType.DelegateCall,
|
|
21
18
|
};
|
|
22
19
|
};
|
|
23
|
-
exports.createSafeMultisendTransaction = createSafeMultisendTransaction;
|
package/dist/endpoints.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.GET_RELAY_PAYLOAD = "/relay-payload";
|
|
7
|
-
exports.GET_TRANSACTION = "/transaction";
|
|
8
|
-
exports.SUBMIT_TRANSACTION = "/submit";
|
|
1
|
+
export const GET_ADDRESS = "/address";
|
|
2
|
+
export const GET_NONCE = "/nonce";
|
|
3
|
+
export const GET_RELAY_PAYLOAD = "/relay-payload";
|
|
4
|
+
export const GET_TRANSACTION = "/transaction";
|
|
5
|
+
export const SUBMIT_TRANSACTION = "/submit";
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
exports.POST = "POST";
|
|
8
|
-
exports.DELETE = "DELETE";
|
|
9
|
-
exports.PUT = "PUT";
|
|
10
|
-
class HttpClient {
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
export const GET = "GET";
|
|
3
|
+
export const POST = "POST";
|
|
4
|
+
export const DELETE = "DELETE";
|
|
5
|
+
export const PUT = "PUT";
|
|
6
|
+
export class HttpClient {
|
|
11
7
|
instance;
|
|
12
8
|
constructor() {
|
|
13
|
-
this.instance =
|
|
9
|
+
this.instance = axios.create({ withCredentials: true });
|
|
14
10
|
}
|
|
15
11
|
async send(endpoint, method, headers, data, params) {
|
|
16
12
|
if (headers != undefined) {
|
|
@@ -27,7 +23,7 @@ class HttpClient {
|
|
|
27
23
|
return resp;
|
|
28
24
|
}
|
|
29
25
|
catch (err) {
|
|
30
|
-
if (
|
|
26
|
+
if (axios.isAxiosError(err)) {
|
|
31
27
|
if (err.response) {
|
|
32
28
|
const errPayload = {
|
|
33
29
|
error: "request error",
|
|
@@ -48,4 +44,3 @@ class HttpClient {
|
|
|
48
44
|
}
|
|
49
45
|
}
|
|
50
46
|
}
|
|
51
|
-
exports.HttpClient = HttpClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./client";
|
|
2
|
-
export * from "./encode";
|
|
3
|
-
export * from "./types";
|
|
4
|
-
export * from "./response";
|
|
1
|
+
export * from "./client.ts";
|
|
2
|
+
export * from "./encode/index.ts";
|
|
3
|
+
export * from "./types.ts";
|
|
4
|
+
export * from "./response/index.ts";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
tslib_1.__exportStar(require("./encode"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./response"), exports);
|
|
1
|
+
export * from "./client.js";
|
|
2
|
+
export * from "./encode/index.js";
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
export * from "./response/index.js";
|
package/dist/manual/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IAbstractSigner } from "@polymarket/abstract-signer";
|
|
2
|
-
import { SafeContractConfig } from "../config";
|
|
3
|
-
import { SafeTransaction, ManualOverrides } from "../types";
|
|
4
|
-
import { ManualTransactionResponse } from "../response";
|
|
2
|
+
import { SafeContractConfig } from "../config/index.ts";
|
|
3
|
+
import { SafeTransaction, ManualOverrides } from "../types.ts";
|
|
4
|
+
import { ManualTransactionResponse } from "../response/index.ts";
|
|
5
5
|
export declare function executeManualTransactions(signer: IAbstractSigner, safeContractConfig: SafeContractConfig, transactions: SafeTransaction[], overrides: ManualOverrides): Promise<ManualTransactionResponse>;
|
package/dist/manual/index.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const response_1 = require("../response");
|
|
9
|
-
const safeExecTransaction = (0, viem_2.prepareEncodeFunctionData)({
|
|
10
|
-
abi: abis_1.safeAbi,
|
|
1
|
+
import { encodePacked, hexToBigInt, zeroAddress } from "viem";
|
|
2
|
+
import { encodeFunctionData, prepareEncodeFunctionData } from "viem";
|
|
3
|
+
import { safeAbi } from "../abis/index.js";
|
|
4
|
+
import { aggregateTransaction, deriveSafe } from "../builder/index.js";
|
|
5
|
+
import { ManualTransactionResponse } from "../response/index.js";
|
|
6
|
+
const safeExecTransaction = prepareEncodeFunctionData({
|
|
7
|
+
abi: safeAbi,
|
|
11
8
|
functionName: 'execTransaction',
|
|
12
9
|
});
|
|
13
|
-
async function executeManualTransactions(signer, safeContractConfig, transactions, overrides) {
|
|
10
|
+
export async function executeManualTransactions(signer, safeContractConfig, transactions, overrides) {
|
|
14
11
|
const from = await signer.getAddress();
|
|
15
|
-
const aggTxn =
|
|
16
|
-
const sig =
|
|
17
|
-
const safeAddress =
|
|
12
|
+
const aggTxn = aggregateTransaction(transactions, safeContractConfig.SafeMultisend);
|
|
13
|
+
const sig = encodePacked(["uint256", "uint256", "uint8"], [BigInt(hexToBigInt(from)), BigInt(0), 1]);
|
|
14
|
+
const safeAddress = deriveSafe(from, safeContractConfig.SafeFactory);
|
|
18
15
|
// calldata
|
|
19
|
-
const data =
|
|
16
|
+
const data = encodeFunctionData({ ...safeExecTransaction, args: [
|
|
20
17
|
aggTxn.to,
|
|
21
18
|
aggTxn.value,
|
|
22
19
|
aggTxn.data,
|
|
@@ -24,8 +21,8 @@ async function executeManualTransactions(signer, safeContractConfig, transaction
|
|
|
24
21
|
0,
|
|
25
22
|
0,
|
|
26
23
|
0,
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
zeroAddress,
|
|
25
|
+
zeroAddress,
|
|
29
26
|
sig,
|
|
30
27
|
] });
|
|
31
28
|
if (overrides.gasLimit == undefined) {
|
|
@@ -46,5 +43,5 @@ async function executeManualTransactions(signer, safeContractConfig, transaction
|
|
|
46
43
|
const waitFunc = (txHash) => {
|
|
47
44
|
return signer.waitTillMined(txHash);
|
|
48
45
|
};
|
|
49
|
-
return new
|
|
46
|
+
return new ManualTransactionResponse(txHash, waitFunc);
|
|
50
47
|
}
|
package/dist/response/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RelayClient } from "../client";
|
|
2
|
-
import { IManualTransactionResponse, RelayerTransaction, RelayerTransactionResponse } from "../types";
|
|
1
|
+
import { RelayClient } from "../client.ts";
|
|
2
|
+
import { IManualTransactionResponse, RelayerTransaction, 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,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ManualTransactionResponse = exports.ClientRelayerTransactionResponse = void 0;
|
|
4
|
-
const types_1 = require("../types");
|
|
5
|
-
class ClientRelayerTransactionResponse {
|
|
1
|
+
import { RelayerTransactionState } from "../types.js";
|
|
2
|
+
export class ClientRelayerTransactionResponse {
|
|
6
3
|
client;
|
|
7
4
|
transactionID;
|
|
8
5
|
transactionHash;
|
|
@@ -20,13 +17,12 @@ class ClientRelayerTransactionResponse {
|
|
|
20
17
|
}
|
|
21
18
|
async wait() {
|
|
22
19
|
return this.client.pollUntilState(this.transactionID, [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
],
|
|
20
|
+
RelayerTransactionState.STATE_MINED,
|
|
21
|
+
RelayerTransactionState.STATE_CONFIRMED,
|
|
22
|
+
], RelayerTransactionState.STATE_FAILED, 30);
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
|
-
|
|
29
|
-
class ManualTransactionResponse {
|
|
25
|
+
export class ManualTransactionResponse {
|
|
30
26
|
hash;
|
|
31
27
|
transactionHash;
|
|
32
28
|
waitTillMined;
|
|
@@ -39,4 +35,3 @@ class ManualTransactionResponse {
|
|
|
39
35
|
return this.waitTillMined(this.hash);
|
|
40
36
|
}
|
|
41
37
|
}
|
|
42
|
-
exports.ManualTransactionResponse = ManualTransactionResponse;
|
package/dist/types.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RelayerTransactionState = exports.OperationType = exports.CallType = exports.TransactionType = void 0;
|
|
4
|
-
var TransactionType;
|
|
1
|
+
export var TransactionType;
|
|
5
2
|
(function (TransactionType) {
|
|
6
3
|
TransactionType["PROXY"] = "PROXY";
|
|
7
4
|
TransactionType["SAFE"] = "SAFE";
|
|
8
5
|
TransactionType["SAFE_CREATE"] = "SAFE-CREATE";
|
|
9
|
-
})(TransactionType || (
|
|
10
|
-
var CallType;
|
|
6
|
+
})(TransactionType || (TransactionType = {}));
|
|
7
|
+
export var CallType;
|
|
11
8
|
(function (CallType) {
|
|
12
9
|
CallType["Invalid"] = "0";
|
|
13
10
|
CallType["Call"] = "1";
|
|
14
11
|
CallType["DelegateCall"] = "2";
|
|
15
|
-
})(CallType || (
|
|
12
|
+
})(CallType || (CallType = {}));
|
|
16
13
|
// Safe Transactions
|
|
17
|
-
var OperationType;
|
|
14
|
+
export var OperationType;
|
|
18
15
|
(function (OperationType) {
|
|
19
16
|
OperationType[OperationType["Call"] = 0] = "Call";
|
|
20
17
|
OperationType[OperationType["DelegateCall"] = 1] = "DelegateCall";
|
|
21
|
-
})(OperationType || (
|
|
22
|
-
var RelayerTransactionState;
|
|
18
|
+
})(OperationType || (OperationType = {}));
|
|
19
|
+
export var RelayerTransactionState;
|
|
23
20
|
(function (RelayerTransactionState) {
|
|
24
21
|
RelayerTransactionState["STATE_NEW"] = "STATE_NEW";
|
|
25
22
|
RelayerTransactionState["STATE_EXECUTED"] = "STATE_EXECUTED";
|
|
@@ -27,5 +24,5 @@ var RelayerTransactionState;
|
|
|
27
24
|
RelayerTransactionState["STATE_INVALID"] = "STATE_INVALID";
|
|
28
25
|
RelayerTransactionState["STATE_CONFIRMED"] = "STATE_CONFIRMED";
|
|
29
26
|
RelayerTransactionState["STATE_FAILED"] = "STATE_FAILED";
|
|
30
|
-
})(RelayerTransactionState || (
|
|
27
|
+
})(RelayerTransactionState || (RelayerTransactionState = {}));
|
|
31
28
|
;
|
package/dist/utils/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.splitAndPackSig = splitAndPackSig;
|
|
4
|
-
exports.sleep = sleep;
|
|
5
|
-
const viem_1 = require("viem");
|
|
6
|
-
function splitAndPackSig(sig) {
|
|
1
|
+
import { encodePacked, hexToBigInt } from "viem";
|
|
2
|
+
export function splitAndPackSig(sig) {
|
|
7
3
|
const splitSig = splitSignature(sig);
|
|
8
|
-
const packedSig =
|
|
4
|
+
const packedSig = encodePacked(["uint256", "uint256", "uint8"], [BigInt(splitSig.r), BigInt(splitSig.s), parseInt(splitSig.v)]);
|
|
9
5
|
return packedSig;
|
|
10
6
|
}
|
|
11
7
|
function splitSignature(sig) {
|
|
@@ -24,11 +20,11 @@ function splitSignature(sig) {
|
|
|
24
20
|
}
|
|
25
21
|
sig = sig.slice(0, -2) + sigV.toString(16);
|
|
26
22
|
return {
|
|
27
|
-
r:
|
|
28
|
-
s:
|
|
29
|
-
v:
|
|
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(),
|
|
30
26
|
};
|
|
31
27
|
}
|
|
32
|
-
function sleep(ms) {
|
|
28
|
+
export function sleep(ms) {
|
|
33
29
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
34
30
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polymarket/relayer-client",
|
|
3
3
|
"description": "Client for Polymarket relayers",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"files": [
|
|
8
9
|
"/dist"
|
|
9
10
|
],
|
|
11
|
+
"sideEffects": false,
|
|
10
12
|
"scripts": {
|
|
11
13
|
"build": "make build",
|
|
12
14
|
"clean": "rm -rf ./dist",
|
|
@@ -28,15 +30,17 @@
|
|
|
28
30
|
"ts-node": "^9.1.1",
|
|
29
31
|
"tsconfig-paths": "^4.2.0",
|
|
30
32
|
"tslib": "^2.8.1",
|
|
33
|
+
"tsx": "^4.20.3",
|
|
34
|
+
"typescript": "^5.8.3",
|
|
31
35
|
"ws": "^8.11.0"
|
|
32
36
|
},
|
|
33
37
|
"dependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"
|
|
38
|
+
"@ethersproject/providers": "5.7.2",
|
|
39
|
+
"@ethersproject/wallet": "5.7.0",
|
|
40
|
+
"@polymarket/abstract-signer": "0.0.8",
|
|
41
|
+
"axios": "^1.13.2",
|
|
36
42
|
"browser-or-node": "^3.0.0",
|
|
37
43
|
"ethers": "5.7.2",
|
|
38
|
-
"tsx": "^4.20.3",
|
|
39
|
-
"typescript": "^5.8.3",
|
|
40
44
|
"viem": "^2.31.4"
|
|
41
45
|
}
|
|
42
46
|
}
|