@polymarket/relayer-client 0.0.1
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 +1 -0
- package/dist/abis/erc20Abi.d.ts +38 -0
- package/dist/abis/erc20Abi.js +225 -0
- package/dist/abis/index.d.ts +5 -0
- package/dist/abis/index.js +8 -0
- package/dist/abis/multisend.d.ts +13 -0
- package/dist/abis/multisend.js +20 -0
- package/dist/abis/proxyFactory.d.ts +66 -0
- package/dist/abis/proxyFactory.js +322 -0
- package/dist/abis/safe.d.ts +35 -0
- package/dist/abis/safe.js +1141 -0
- package/dist/abis/safeFactory.d.ts +60 -0
- package/dist/abis/safeFactory.js +227 -0
- package/dist/auth/handler.d.ts +12 -0
- package/dist/auth/handler.js +62 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.js +4 -0
- package/dist/builder/create.d.ts +4 -0
- package/dist/builder/create.js +55 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/index.js +5 -0
- package/dist/builder/proxy.d.ts +4 -0
- package/dist/builder/proxy.js +88 -0
- package/dist/builder/safe.d.ts +4 -0
- package/dist/builder/safe.js +125 -0
- package/dist/builder/utils.d.ts +2 -0
- package/dist/builder/utils.js +12 -0
- package/dist/client.d.ts +21 -0
- package/dist/client.js +159 -0
- package/dist/constants/index.d.ts +6 -0
- package/dist/constants/index.js +9 -0
- package/dist/encode/index.d.ts +1 -0
- package/dist/encode/index.js +4 -0
- package/dist/encode/proxy.d.ts +2 -0
- package/dist/encode/proxy.js +9 -0
- package/dist/encode/safe.d.ts +2 -0
- package/dist/encode/safe.js +20 -0
- package/dist/encode/utils.d.ts +6 -0
- package/dist/encode/utils.js +47 -0
- package/dist/endpoints.d.ts +6 -0
- package/dist/endpoints.js +9 -0
- package/dist/http-helpers/index.d.ts +16 -0
- package/dist/http-helpers/index.js +58 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +17 -0
- package/dist/types.d.ts +92 -0
- package/dist/types.js +21 -0
- package/package.json +47 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export declare const safeFactoryAbi: ({
|
|
2
|
+
inputs: {
|
|
3
|
+
internalType: string;
|
|
4
|
+
name: string;
|
|
5
|
+
type: string;
|
|
6
|
+
}[];
|
|
7
|
+
stateMutability: string;
|
|
8
|
+
type: string;
|
|
9
|
+
anonymous?: undefined;
|
|
10
|
+
name?: undefined;
|
|
11
|
+
outputs?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
anonymous: boolean;
|
|
14
|
+
inputs: {
|
|
15
|
+
indexed: boolean;
|
|
16
|
+
internalType: string;
|
|
17
|
+
name: string;
|
|
18
|
+
type: string;
|
|
19
|
+
}[];
|
|
20
|
+
name: string;
|
|
21
|
+
type: string;
|
|
22
|
+
stateMutability?: undefined;
|
|
23
|
+
outputs?: undefined;
|
|
24
|
+
} | {
|
|
25
|
+
inputs: {
|
|
26
|
+
internalType: string;
|
|
27
|
+
name: string;
|
|
28
|
+
type: string;
|
|
29
|
+
}[];
|
|
30
|
+
name: string;
|
|
31
|
+
outputs: {
|
|
32
|
+
internalType: string;
|
|
33
|
+
name: string;
|
|
34
|
+
type: string;
|
|
35
|
+
}[];
|
|
36
|
+
stateMutability: string;
|
|
37
|
+
type: string;
|
|
38
|
+
anonymous?: undefined;
|
|
39
|
+
} | {
|
|
40
|
+
inputs: ({
|
|
41
|
+
internalType: string;
|
|
42
|
+
name: string;
|
|
43
|
+
type: string;
|
|
44
|
+
components?: undefined;
|
|
45
|
+
} | {
|
|
46
|
+
components: {
|
|
47
|
+
internalType: string;
|
|
48
|
+
name: string;
|
|
49
|
+
type: string;
|
|
50
|
+
}[];
|
|
51
|
+
internalType: string;
|
|
52
|
+
name: string;
|
|
53
|
+
type: string;
|
|
54
|
+
})[];
|
|
55
|
+
name: string;
|
|
56
|
+
outputs: never[];
|
|
57
|
+
stateMutability: string;
|
|
58
|
+
type: string;
|
|
59
|
+
anonymous?: undefined;
|
|
60
|
+
})[];
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeFactoryAbi = void 0;
|
|
4
|
+
exports.safeFactoryAbi = [
|
|
5
|
+
{
|
|
6
|
+
"inputs": [
|
|
7
|
+
{
|
|
8
|
+
"internalType": "address",
|
|
9
|
+
"name": "_masterCopy",
|
|
10
|
+
"type": "address"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"internalType": "address",
|
|
14
|
+
"name": "_fallbackHandler",
|
|
15
|
+
"type": "address"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"stateMutability": "nonpayable",
|
|
19
|
+
"type": "constructor"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"anonymous": false,
|
|
23
|
+
"inputs": [
|
|
24
|
+
{
|
|
25
|
+
"indexed": false,
|
|
26
|
+
"internalType": "contract GnosisSafe",
|
|
27
|
+
"name": "proxy",
|
|
28
|
+
"type": "address"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"indexed": false,
|
|
32
|
+
"internalType": "address",
|
|
33
|
+
"name": "owner",
|
|
34
|
+
"type": "address"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"name": "ProxyCreation",
|
|
38
|
+
"type": "event"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"inputs": [],
|
|
42
|
+
"name": "CREATE_PROXY_TYPEHASH",
|
|
43
|
+
"outputs": [
|
|
44
|
+
{
|
|
45
|
+
"internalType": "bytes32",
|
|
46
|
+
"name": "",
|
|
47
|
+
"type": "bytes32"
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
"stateMutability": "view",
|
|
51
|
+
"type": "function"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"inputs": [],
|
|
55
|
+
"name": "DOMAIN_TYPEHASH",
|
|
56
|
+
"outputs": [
|
|
57
|
+
{
|
|
58
|
+
"internalType": "bytes32",
|
|
59
|
+
"name": "",
|
|
60
|
+
"type": "bytes32"
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"stateMutability": "view",
|
|
64
|
+
"type": "function"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"inputs": [],
|
|
68
|
+
"name": "NAME",
|
|
69
|
+
"outputs": [
|
|
70
|
+
{
|
|
71
|
+
"internalType": "string",
|
|
72
|
+
"name": "",
|
|
73
|
+
"type": "string"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"stateMutability": "view",
|
|
77
|
+
"type": "function"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"inputs": [
|
|
81
|
+
{
|
|
82
|
+
"internalType": "address",
|
|
83
|
+
"name": "user",
|
|
84
|
+
"type": "address"
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
"name": "computeProxyAddress",
|
|
88
|
+
"outputs": [
|
|
89
|
+
{
|
|
90
|
+
"internalType": "address",
|
|
91
|
+
"name": "",
|
|
92
|
+
"type": "address"
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"stateMutability": "view",
|
|
96
|
+
"type": "function"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"inputs": [
|
|
100
|
+
{
|
|
101
|
+
"internalType": "address",
|
|
102
|
+
"name": "paymentToken",
|
|
103
|
+
"type": "address"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"internalType": "uint256",
|
|
107
|
+
"name": "payment",
|
|
108
|
+
"type": "uint256"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"internalType": "address payable",
|
|
112
|
+
"name": "paymentReceiver",
|
|
113
|
+
"type": "address"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"components": [
|
|
117
|
+
{
|
|
118
|
+
"internalType": "uint8",
|
|
119
|
+
"name": "v",
|
|
120
|
+
"type": "uint8"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"internalType": "bytes32",
|
|
124
|
+
"name": "r",
|
|
125
|
+
"type": "bytes32"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"internalType": "bytes32",
|
|
129
|
+
"name": "s",
|
|
130
|
+
"type": "bytes32"
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
"internalType": "struct SafeProxyFactory.Sig",
|
|
134
|
+
"name": "createSig",
|
|
135
|
+
"type": "tuple"
|
|
136
|
+
}
|
|
137
|
+
],
|
|
138
|
+
"name": "createProxy",
|
|
139
|
+
"outputs": [],
|
|
140
|
+
"stateMutability": "nonpayable",
|
|
141
|
+
"type": "function"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"inputs": [],
|
|
145
|
+
"name": "domainSeparator",
|
|
146
|
+
"outputs": [
|
|
147
|
+
{
|
|
148
|
+
"internalType": "bytes32",
|
|
149
|
+
"name": "",
|
|
150
|
+
"type": "bytes32"
|
|
151
|
+
}
|
|
152
|
+
],
|
|
153
|
+
"stateMutability": "view",
|
|
154
|
+
"type": "function"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"inputs": [],
|
|
158
|
+
"name": "fallbackHandler",
|
|
159
|
+
"outputs": [
|
|
160
|
+
{
|
|
161
|
+
"internalType": "address",
|
|
162
|
+
"name": "",
|
|
163
|
+
"type": "address"
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
"stateMutability": "view",
|
|
167
|
+
"type": "function"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"inputs": [],
|
|
171
|
+
"name": "getContractBytecode",
|
|
172
|
+
"outputs": [
|
|
173
|
+
{
|
|
174
|
+
"internalType": "bytes",
|
|
175
|
+
"name": "",
|
|
176
|
+
"type": "bytes"
|
|
177
|
+
}
|
|
178
|
+
],
|
|
179
|
+
"stateMutability": "view",
|
|
180
|
+
"type": "function"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"inputs": [
|
|
184
|
+
{
|
|
185
|
+
"internalType": "address",
|
|
186
|
+
"name": "user",
|
|
187
|
+
"type": "address"
|
|
188
|
+
}
|
|
189
|
+
],
|
|
190
|
+
"name": "getSalt",
|
|
191
|
+
"outputs": [
|
|
192
|
+
{
|
|
193
|
+
"internalType": "bytes32",
|
|
194
|
+
"name": "",
|
|
195
|
+
"type": "bytes32"
|
|
196
|
+
}
|
|
197
|
+
],
|
|
198
|
+
"stateMutability": "pure",
|
|
199
|
+
"type": "function"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"inputs": [],
|
|
203
|
+
"name": "masterCopy",
|
|
204
|
+
"outputs": [
|
|
205
|
+
{
|
|
206
|
+
"internalType": "address",
|
|
207
|
+
"name": "",
|
|
208
|
+
"type": "address"
|
|
209
|
+
}
|
|
210
|
+
],
|
|
211
|
+
"stateMutability": "view",
|
|
212
|
+
"type": "function"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"inputs": [],
|
|
216
|
+
"name": "proxyCreationCode",
|
|
217
|
+
"outputs": [
|
|
218
|
+
{
|
|
219
|
+
"internalType": "bytes",
|
|
220
|
+
"name": "",
|
|
221
|
+
"type": "bytes"
|
|
222
|
+
}
|
|
223
|
+
],
|
|
224
|
+
"stateMutability": "pure",
|
|
225
|
+
"type": "function"
|
|
226
|
+
}
|
|
227
|
+
];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AxiosRequestHeaders } from "axios";
|
|
2
|
+
import { AuthArgs } from "../../src/types";
|
|
3
|
+
export declare class AuthHandler {
|
|
4
|
+
readonly url: string;
|
|
5
|
+
readonly token?: string;
|
|
6
|
+
private cookie?;
|
|
7
|
+
constructor(args: AuthArgs);
|
|
8
|
+
login(): Promise<void>;
|
|
9
|
+
isLoggedIn(): boolean;
|
|
10
|
+
getAuthHeader(): Promise<AxiosRequestHeaders>;
|
|
11
|
+
getPolymarketCookies(): Promise<string>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthHandler = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const http_helpers_1 = require("../../src/http-helpers");
|
|
6
|
+
const POLYMARKET_COOKIE_NAME = "polymarket";
|
|
7
|
+
class AuthHandler {
|
|
8
|
+
constructor(args) {
|
|
9
|
+
if (args.token == undefined && args.cookie == undefined) {
|
|
10
|
+
throw new Error("invalid authorization arguments");
|
|
11
|
+
}
|
|
12
|
+
this.url = args.authUrl.endsWith("/") ? args.authUrl.slice(0, -1) : args.authUrl;
|
|
13
|
+
;
|
|
14
|
+
if (args.token !== undefined) {
|
|
15
|
+
this.token = args.token;
|
|
16
|
+
}
|
|
17
|
+
if (args.cookie !== undefined) {
|
|
18
|
+
this.cookie = args.cookie;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
login() {
|
|
22
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
if (this.token == undefined) {
|
|
24
|
+
throw new Error("authorization token missing");
|
|
25
|
+
}
|
|
26
|
+
const resp = yield http_helpers_1.raw_get(`${this.url}/login`, {
|
|
27
|
+
headers: {
|
|
28
|
+
Authorization: `Bearer ${this.token}`
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
const cookies = resp.headers['set-cookie'];
|
|
32
|
+
let aggregatedCookie = "";
|
|
33
|
+
for (const cookie of cookies) {
|
|
34
|
+
if (cookie.includes(POLYMARKET_COOKIE_NAME)) {
|
|
35
|
+
aggregatedCookie += `${cookie}; `;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (aggregatedCookie != "") {
|
|
39
|
+
this.cookie = aggregatedCookie;
|
|
40
|
+
console.log(`Successfully logged in!`);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
isLoggedIn() {
|
|
45
|
+
return this.cookie != undefined;
|
|
46
|
+
}
|
|
47
|
+
getAuthHeader() {
|
|
48
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return { "Cookie": yield this.getPolymarketCookies() };
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
getPolymarketCookies() {
|
|
53
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
if (!this.isLoggedIn()) {
|
|
55
|
+
console.log("Authorization not set, logging in...");
|
|
56
|
+
yield this.login();
|
|
57
|
+
}
|
|
58
|
+
return this.cookie;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.AuthHandler = AuthHandler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./handler";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Wallet } from "@ethersproject/wallet";
|
|
2
|
+
import { JsonRpcSigner } from "@ethersproject/providers";
|
|
3
|
+
import { SafeCreateTransactionArgs, TransactionRequest } from "../types";
|
|
4
|
+
export declare function buildSafeCreateTransactionRequest(signer: Wallet | JsonRpcSigner, args: SafeCreateTransactionArgs): Promise<TransactionRequest>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildSafeCreateTransactionRequest = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
function createSafeCreateSignature(signer, chainId, paymentToken, payment, paymentReceiver) {
|
|
10
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
const domain = {
|
|
12
|
+
name: constants_1.SAFE_FACTORY_NAME,
|
|
13
|
+
chainId: ethers_1.BigNumber.from(chainId).toHexString(),
|
|
14
|
+
verifyingContract: constants_1.SAFE_FACTORY_ADDRESS,
|
|
15
|
+
};
|
|
16
|
+
const types = {
|
|
17
|
+
CreateProxy: [
|
|
18
|
+
{ name: "paymentToken", type: "address" },
|
|
19
|
+
{ name: "payment", type: "uint256" },
|
|
20
|
+
{ name: "paymentReceiver", type: "address" },
|
|
21
|
+
],
|
|
22
|
+
};
|
|
23
|
+
const values = {
|
|
24
|
+
paymentToken,
|
|
25
|
+
payment: ethers_1.BigNumber.from(payment),
|
|
26
|
+
paymentReceiver,
|
|
27
|
+
};
|
|
28
|
+
return signer._signTypedData(domain, types, values);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function buildSafeCreateTransactionRequest(signer, args) {
|
|
32
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const sig = yield createSafeCreateSignature(signer, args.chainId, args.paymentToken, args.payment, args.paymentReceiver);
|
|
34
|
+
const sigParams = {
|
|
35
|
+
paymentToken: args.paymentToken,
|
|
36
|
+
payment: args.payment,
|
|
37
|
+
paymentReceiver: args.paymentReceiver,
|
|
38
|
+
};
|
|
39
|
+
const safeAddress = utils_1.deriveSafe(args.from);
|
|
40
|
+
const request = {
|
|
41
|
+
from: args.from,
|
|
42
|
+
to: constants_1.SAFE_FACTORY_ADDRESS,
|
|
43
|
+
// Note: obviously the safe here does not exist yet but useful to have this data in the db
|
|
44
|
+
proxyWallet: safeAddress,
|
|
45
|
+
data: "0x",
|
|
46
|
+
signature: sig,
|
|
47
|
+
signatureParams: sigParams,
|
|
48
|
+
type: types_1.TransactionType.SAFE_CREATE,
|
|
49
|
+
};
|
|
50
|
+
console.log(`Created a SAFE-CREATE Transaction:`);
|
|
51
|
+
console.log(request);
|
|
52
|
+
return request;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.buildSafeCreateTransactionRequest = buildSafeCreateTransactionRequest;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Wallet } from "@ethersproject/wallet";
|
|
2
|
+
import { JsonRpcSigner } from "@ethersproject/providers";
|
|
3
|
+
import { ProxyTransactionArgs, TransactionRequest } from "../types";
|
|
4
|
+
export declare function buildProxyTransactionRequest(signer: Wallet | JsonRpcSigner, args: ProxyTransactionArgs): Promise<TransactionRequest>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildProxyTransactionRequest = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const web3_utils_1 = tslib_1.__importDefault(require("web3-utils"));
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const types_1 = require("../types");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const ethers_1 = require("ethers");
|
|
10
|
+
const utils_2 = require("ethers/lib/utils");
|
|
11
|
+
const relayPrefix = "rlx:";
|
|
12
|
+
const zeroPad = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
13
|
+
function padTo64(_hex) {
|
|
14
|
+
let hex = _hex;
|
|
15
|
+
if (hex.length < 64) {
|
|
16
|
+
hex = (zeroPad + hex).slice(-64);
|
|
17
|
+
}
|
|
18
|
+
return hex;
|
|
19
|
+
}
|
|
20
|
+
function removeHexPrefix(hex) {
|
|
21
|
+
return hex.replace(/^0x/, "");
|
|
22
|
+
}
|
|
23
|
+
function toUint256NoPrefix(hexString) {
|
|
24
|
+
return padTo64(removeHexPrefix(hexString));
|
|
25
|
+
}
|
|
26
|
+
function bytesToHexNoPrefix(bytes) {
|
|
27
|
+
let hex = removeHexPrefix(web3_utils_1.default.toHex(bytes));
|
|
28
|
+
if (hex.length % 2 !== 0) {
|
|
29
|
+
hex = "0" + hex;
|
|
30
|
+
}
|
|
31
|
+
return hex;
|
|
32
|
+
}
|
|
33
|
+
function createStructHash(from, to, data, txFee, gasPrice, gasLimit, nonce, relayHubAddress, relayAddress) {
|
|
34
|
+
const txhstr = bytesToHexNoPrefix(data);
|
|
35
|
+
const dataToHash = Buffer.from(relayPrefix).toString("hex") +
|
|
36
|
+
removeHexPrefix(from) +
|
|
37
|
+
removeHexPrefix(to) +
|
|
38
|
+
txhstr +
|
|
39
|
+
toUint256NoPrefix(ethers_1.BigNumber.from(txFee).toHexString()) +
|
|
40
|
+
toUint256NoPrefix(ethers_1.BigNumber.from(gasPrice).toHexString()) +
|
|
41
|
+
toUint256NoPrefix(ethers_1.BigNumber.from(gasLimit).toHexString()) +
|
|
42
|
+
toUint256NoPrefix(ethers_1.BigNumber.from(nonce).toHexString()) +
|
|
43
|
+
removeHexPrefix(relayHubAddress) +
|
|
44
|
+
removeHexPrefix(relayAddress);
|
|
45
|
+
return utils_2.keccak256("0x" + dataToHash);
|
|
46
|
+
}
|
|
47
|
+
function createProxySignature(signer, structHash) {
|
|
48
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return signer.signMessage(utils_2.arrayify(structHash));
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function buildProxyTransactionRequest(signer, args) {
|
|
53
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const to = constants_1.PROXY_WALLET_FACTORY_ADDRESS;
|
|
55
|
+
const proxy = utils_1.deriveProxyWallet(args.from);
|
|
56
|
+
const relayerFee = "0";
|
|
57
|
+
const relayHub = constants_1.RELAY_HUB_ADDRESS;
|
|
58
|
+
const gasLimit = yield signer.provider.estimateGas({
|
|
59
|
+
to: to,
|
|
60
|
+
data: args.data,
|
|
61
|
+
});
|
|
62
|
+
const gasLimitStr = gasLimit.toString();
|
|
63
|
+
console.log(`GasLimit: ${gasLimitStr}`);
|
|
64
|
+
const sigParams = {
|
|
65
|
+
gasPrice: args.gasPrice,
|
|
66
|
+
gasLimit: gasLimitStr,
|
|
67
|
+
relayerFee: relayerFee,
|
|
68
|
+
relayHub: constants_1.RELAY_HUB_ADDRESS,
|
|
69
|
+
relay: args.relay,
|
|
70
|
+
};
|
|
71
|
+
const txHash = createStructHash(args.from, to, args.data, relayerFee, args.gasPrice, gasLimitStr, args.nonce, relayHub, args.relay);
|
|
72
|
+
const sig = yield createProxySignature(signer, txHash);
|
|
73
|
+
const req = {
|
|
74
|
+
from: args.from,
|
|
75
|
+
to: to,
|
|
76
|
+
proxyWallet: proxy,
|
|
77
|
+
data: args.data,
|
|
78
|
+
nonce: args.nonce,
|
|
79
|
+
signature: sig,
|
|
80
|
+
signatureParams: sigParams,
|
|
81
|
+
type: types_1.TransactionType.PROXY,
|
|
82
|
+
};
|
|
83
|
+
console.log(`Created Proxy Transaction Request:`);
|
|
84
|
+
console.log(req);
|
|
85
|
+
return req;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
exports.buildProxyTransactionRequest = buildProxyTransactionRequest;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Wallet } from "@ethersproject/wallet";
|
|
2
|
+
import { JsonRpcSigner } from "@ethersproject/providers";
|
|
3
|
+
import { SafeTransactionArgs, TransactionRequest } from "../types";
|
|
4
|
+
export declare function buildSafeTransactionRequest(signer: Wallet | JsonRpcSigner, args: SafeTransactionArgs): Promise<TransactionRequest>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildSafeTransactionRequest = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
|
+
const ethers_1 = require("ethers");
|
|
8
|
+
const utils_2 = require("ethers/lib/utils");
|
|
9
|
+
const safe_1 = require("../encode/safe");
|
|
10
|
+
const utils_3 = require("../encode/utils");
|
|
11
|
+
function createSafeSignature(signer, structHash) {
|
|
12
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
return signer.signMessage(ethers_1.ethers.utils.arrayify(structHash));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function splitSignature(sig) {
|
|
17
|
+
let sigV = parseInt(sig.slice(-2), 16);
|
|
18
|
+
switch (sigV) {
|
|
19
|
+
case 0:
|
|
20
|
+
case 1:
|
|
21
|
+
sigV += 31;
|
|
22
|
+
break;
|
|
23
|
+
case 27:
|
|
24
|
+
case 28:
|
|
25
|
+
sigV += 4;
|
|
26
|
+
break;
|
|
27
|
+
default:
|
|
28
|
+
throw new Error("Invalid signature");
|
|
29
|
+
}
|
|
30
|
+
sig = sig.slice(0, -2) + sigV.toString(16);
|
|
31
|
+
return {
|
|
32
|
+
r: ethers_1.BigNumber.from("0x" + sig.slice(2, 66)).toString(),
|
|
33
|
+
s: ethers_1.BigNumber.from("0x" + sig.slice(66, 130)).toString(),
|
|
34
|
+
v: ethers_1.BigNumber.from("0x" + sig.slice(130, 132)).toString(),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function createStructHash(chainId, safe, to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, nonce) {
|
|
38
|
+
const domain = {
|
|
39
|
+
chainId: chainId,
|
|
40
|
+
verifyingContract: safe,
|
|
41
|
+
};
|
|
42
|
+
const types = {
|
|
43
|
+
// keccak256(
|
|
44
|
+
// "SafeTx(address to,uint256 value,bytes data,uint8 operation,uint256 safeTxGas,uint256 baseGas,uint256 gasPrice,address gasToken,address refundReceiver,uint256 nonce)"
|
|
45
|
+
// );
|
|
46
|
+
SafeTx: [
|
|
47
|
+
{ name: 'to', type: 'address' },
|
|
48
|
+
{ name: 'value', type: 'uint256' },
|
|
49
|
+
{ name: 'data', type: 'bytes' },
|
|
50
|
+
{ name: 'operation', type: 'uint8' },
|
|
51
|
+
{ name: 'safeTxGas', type: 'uint256' },
|
|
52
|
+
{ name: 'baseGas', type: 'uint256' },
|
|
53
|
+
{ name: 'gasPrice', type: 'uint256' },
|
|
54
|
+
{ name: 'gasToken', type: 'address' },
|
|
55
|
+
{ name: 'refundReceiver', type: 'address' },
|
|
56
|
+
{ name: 'nonce', type: 'uint256' },
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
const values = {
|
|
60
|
+
to: to,
|
|
61
|
+
value: value,
|
|
62
|
+
data: data,
|
|
63
|
+
operation: operation,
|
|
64
|
+
safeTxGas: safeTxGas,
|
|
65
|
+
baseGas: baseGas,
|
|
66
|
+
gasPrice: gasPrice,
|
|
67
|
+
gasToken: gasToken,
|
|
68
|
+
refundReceiver: refundReceiver,
|
|
69
|
+
nonce: nonce,
|
|
70
|
+
};
|
|
71
|
+
const structHash = utils_2._TypedDataEncoder.hash(domain, types, values);
|
|
72
|
+
// console.log(`Safe Struct Hash: ${structHash}`);
|
|
73
|
+
return structHash;
|
|
74
|
+
}
|
|
75
|
+
function aggregateTransaction(txns) {
|
|
76
|
+
let transaction;
|
|
77
|
+
if (txns.length == 1) {
|
|
78
|
+
transaction = txns[0];
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
transaction = safe_1.createSafeMultisendTransaction(txns);
|
|
82
|
+
}
|
|
83
|
+
return transaction;
|
|
84
|
+
}
|
|
85
|
+
function buildSafeTransactionRequest(signer, args) {
|
|
86
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const transaction = aggregateTransaction(args.transactions);
|
|
88
|
+
const safeTxnGas = "0";
|
|
89
|
+
const baseGas = "0";
|
|
90
|
+
const gasPrice = "0";
|
|
91
|
+
const gasToken = ethers_1.ethers.constants.AddressZero;
|
|
92
|
+
const refundReceiver = ethers_1.ethers.constants.AddressZero;
|
|
93
|
+
const safeAddress = utils_1.deriveSafe(args.from);
|
|
94
|
+
// Generate the struct hash
|
|
95
|
+
// NOTE: this includes a client side optimization over the current relayers
|
|
96
|
+
// Generates struct hash locally instead of going across the network using the RPC call
|
|
97
|
+
const structHash = createStructHash(args.chainId, safeAddress, transaction.to, transaction.value, transaction.data, transaction.operation, safeTxnGas, baseGas, gasPrice, gasToken, refundReceiver, args.nonce);
|
|
98
|
+
const sig = yield createSafeSignature(signer, structHash);
|
|
99
|
+
// Split the sig then pack it into Gnosis accepted rsv format
|
|
100
|
+
const splitSig = splitSignature(sig);
|
|
101
|
+
const packedSig = utils_3.abiEncodePacked({ type: "uint256", value: splitSig.r }, { type: "uint256", value: splitSig.s }, { type: "uint8", value: splitSig.v });
|
|
102
|
+
const sigParams = {
|
|
103
|
+
gasPrice,
|
|
104
|
+
operation: `${transaction.operation}`,
|
|
105
|
+
safeTxnGas,
|
|
106
|
+
baseGas,
|
|
107
|
+
gasToken,
|
|
108
|
+
refundReceiver,
|
|
109
|
+
};
|
|
110
|
+
const req = {
|
|
111
|
+
from: args.from,
|
|
112
|
+
to: transaction.to,
|
|
113
|
+
proxyWallet: safeAddress,
|
|
114
|
+
data: transaction.data,
|
|
115
|
+
nonce: args.nonce,
|
|
116
|
+
signature: packedSig,
|
|
117
|
+
signatureParams: sigParams,
|
|
118
|
+
type: types_1.TransactionType.SAFE,
|
|
119
|
+
};
|
|
120
|
+
console.log(`Created Safe Transaction Request: `);
|
|
121
|
+
console.log(req);
|
|
122
|
+
return req;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
exports.buildSafeTransactionRequest = buildSafeTransactionRequest;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deriveSafe = exports.deriveProxyWallet = void 0;
|
|
4
|
+
const sdk_1 = require("@polymarket/sdk");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
exports.deriveProxyWallet = (address) => {
|
|
8
|
+
return sdk_1.getProxyWalletAddress(constants_1.PROXY_WALLET_FACTORY_ADDRESS, address);
|
|
9
|
+
};
|
|
10
|
+
exports.deriveSafe = (address) => {
|
|
11
|
+
return ethers_1.ethers.utils.getCreate2Address(constants_1.SAFE_FACTORY_ADDRESS, ethers_1.ethers.utils.keccak256(ethers_1.ethers.utils.defaultAbiCoder.encode(["address"], [address])), constants_1.SAFE_INIT_CODE_HASH);
|
|
12
|
+
};
|