@primuslabs/fund-js-sdk 0.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 +10 -0
- package/dist/index.d.mts +62 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.js +1383 -0
- package/dist/index.mjs +1358 -0
- package/package.json +62 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1383 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
PrimusFund: () => PrimusFund
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_ethers3 = require("ethers");
|
|
27
|
+
|
|
28
|
+
// src/classes/Fund.ts
|
|
29
|
+
var import_ethers2 = require("ethers");
|
|
30
|
+
var import_zktls_js_sdk = require("@primuslabs/zktls-js-sdk");
|
|
31
|
+
|
|
32
|
+
// src/config/constants.ts
|
|
33
|
+
var Fund_CONTRACTS = {
|
|
34
|
+
// monad testnet
|
|
35
|
+
10143: "0xcd1Ed9C1595A7e9DADe76808dd5e66aA95940A92"
|
|
36
|
+
};
|
|
37
|
+
var SUPPORTEDCHAINIDS = Object.keys(Fund_CONTRACTS).map((i) => Number(i));
|
|
38
|
+
var DATASOURCETEMPLATEMAP = {
|
|
39
|
+
x: "2e3160ae-8b1e-45e3-8c59-426366278b9d",
|
|
40
|
+
tiktok: "2b22c9f8-686d-4482-a0cf-c9c43c1181ad",
|
|
41
|
+
"google account": ""
|
|
42
|
+
};
|
|
43
|
+
var SUPPORTEDSOCIALPLATFORMS = Object.keys(DATASOURCETEMPLATEMAP);
|
|
44
|
+
|
|
45
|
+
// src/classes/Contract.ts
|
|
46
|
+
var import_ethers = require("ethers");
|
|
47
|
+
var Contract = class {
|
|
48
|
+
address;
|
|
49
|
+
provider;
|
|
50
|
+
contractInstance;
|
|
51
|
+
/**
|
|
52
|
+
* @param chainName The name of the chain, used to identify and differentiate between different chains.
|
|
53
|
+
* @param provider The provider object for the blockchain, used to establish and manage the connection with the blockchain.
|
|
54
|
+
*/
|
|
55
|
+
constructor(provider, address, abiJson) {
|
|
56
|
+
if (!provider || !address || !abiJson) {
|
|
57
|
+
throw new Error("provider, address, and abiJson are required");
|
|
58
|
+
}
|
|
59
|
+
this.address = address;
|
|
60
|
+
this.provider = provider;
|
|
61
|
+
const signer = this.provider.getSigner();
|
|
62
|
+
this.contractInstance = new import_ethers.ethers.Contract(this.address, abiJson, signer);
|
|
63
|
+
}
|
|
64
|
+
// Example method to read from the contract
|
|
65
|
+
async callMethod(functionName, functionParams) {
|
|
66
|
+
return new Promise(async (resolve, reject) => {
|
|
67
|
+
if (!this.contractInstance[functionName]) {
|
|
68
|
+
return reject(`Method ${functionName} does not exist on the contract`);
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
const result = await this.contractInstance[functionName](...functionParams);
|
|
72
|
+
return resolve(result);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
return reject(error);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
// Example method to send a transaction
|
|
79
|
+
async sendTransaction(functionName, functionParams) {
|
|
80
|
+
return new Promise(async (resolve, reject) => {
|
|
81
|
+
if (!this.contractInstance[functionName]) {
|
|
82
|
+
return reject(`Method ${functionName} does not exist on the contract`);
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
console.log("sendTransaction params:", ...functionParams);
|
|
86
|
+
const tx = await this.contractInstance[functionName](...functionParams);
|
|
87
|
+
const txreceipt = await tx.wait();
|
|
88
|
+
console.log("txreceipt", txreceipt);
|
|
89
|
+
resolve(txreceipt);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.log("sendTransaction error:", error);
|
|
92
|
+
if (error?.code === "ACTION_REJECTED") {
|
|
93
|
+
return reject("user rejected transaction");
|
|
94
|
+
}
|
|
95
|
+
if (error?.reason) {
|
|
96
|
+
return reject(error.reason);
|
|
97
|
+
}
|
|
98
|
+
if (error?.data?.message === "insufficient balance") {
|
|
99
|
+
return reject(error?.data?.message);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var Contract_default = Contract;
|
|
106
|
+
|
|
107
|
+
// src/config/abi.json
|
|
108
|
+
var abi_default = [
|
|
109
|
+
{
|
|
110
|
+
type: "function",
|
|
111
|
+
name: "addBatchIdSource",
|
|
112
|
+
inputs: [
|
|
113
|
+
{ name: "sourceName_", type: "string[]", internalType: "string[]" },
|
|
114
|
+
{ name: "url_", type: "string[]", internalType: "string[]" },
|
|
115
|
+
{ name: "jsonPath_", type: "string[]", internalType: "string[]" }
|
|
116
|
+
],
|
|
117
|
+
outputs: [],
|
|
118
|
+
stateMutability: "nonpayable"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
type: "function",
|
|
122
|
+
name: "claimByMultiSource",
|
|
123
|
+
inputs: [
|
|
124
|
+
{ name: "idSources", type: "string[]", internalType: "string[]" },
|
|
125
|
+
{
|
|
126
|
+
name: "att",
|
|
127
|
+
type: "tuple[]",
|
|
128
|
+
internalType: "struct Attestation[]",
|
|
129
|
+
components: [
|
|
130
|
+
{ name: "recipient", type: "address", internalType: "address" },
|
|
131
|
+
{
|
|
132
|
+
name: "request",
|
|
133
|
+
type: "tuple",
|
|
134
|
+
internalType: "struct AttNetworkRequest",
|
|
135
|
+
components: [
|
|
136
|
+
{ name: "url", type: "string", internalType: "string" },
|
|
137
|
+
{ name: "header", type: "string", internalType: "string" },
|
|
138
|
+
{ name: "method", type: "string", internalType: "string" },
|
|
139
|
+
{ name: "body", type: "string", internalType: "string" }
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "reponseResolve",
|
|
144
|
+
type: "tuple[]",
|
|
145
|
+
internalType: "struct AttNetworkResponseResolve[]",
|
|
146
|
+
components: [
|
|
147
|
+
{ name: "keyName", type: "string", internalType: "string" },
|
|
148
|
+
{
|
|
149
|
+
name: "parseType",
|
|
150
|
+
type: "string",
|
|
151
|
+
internalType: "string"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
name: "parsePath",
|
|
155
|
+
type: "string",
|
|
156
|
+
internalType: "string"
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
{ name: "data", type: "string", internalType: "string" },
|
|
161
|
+
{
|
|
162
|
+
name: "attConditions",
|
|
163
|
+
type: "string",
|
|
164
|
+
internalType: "string"
|
|
165
|
+
},
|
|
166
|
+
{ name: "timestamp", type: "uint64", internalType: "uint64" },
|
|
167
|
+
{
|
|
168
|
+
name: "additionParams",
|
|
169
|
+
type: "string",
|
|
170
|
+
internalType: "string"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: "attestors",
|
|
174
|
+
type: "tuple[]",
|
|
175
|
+
internalType: "struct Attestor[]",
|
|
176
|
+
components: [
|
|
177
|
+
{
|
|
178
|
+
name: "attestorAddr",
|
|
179
|
+
type: "address",
|
|
180
|
+
internalType: "address"
|
|
181
|
+
},
|
|
182
|
+
{ name: "url", type: "string", internalType: "string" }
|
|
183
|
+
]
|
|
184
|
+
},
|
|
185
|
+
{ name: "signatures", type: "bytes[]", internalType: "bytes[]" }
|
|
186
|
+
]
|
|
187
|
+
}
|
|
188
|
+
],
|
|
189
|
+
outputs: [],
|
|
190
|
+
stateMutability: "payable"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
type: "function",
|
|
194
|
+
name: "claimBySource",
|
|
195
|
+
inputs: [
|
|
196
|
+
{ name: "idSource", type: "string", internalType: "string" },
|
|
197
|
+
{
|
|
198
|
+
name: "att",
|
|
199
|
+
type: "tuple",
|
|
200
|
+
internalType: "struct Attestation",
|
|
201
|
+
components: [
|
|
202
|
+
{ name: "recipient", type: "address", internalType: "address" },
|
|
203
|
+
{
|
|
204
|
+
name: "request",
|
|
205
|
+
type: "tuple",
|
|
206
|
+
internalType: "struct AttNetworkRequest",
|
|
207
|
+
components: [
|
|
208
|
+
{ name: "url", type: "string", internalType: "string" },
|
|
209
|
+
{ name: "header", type: "string", internalType: "string" },
|
|
210
|
+
{ name: "method", type: "string", internalType: "string" },
|
|
211
|
+
{ name: "body", type: "string", internalType: "string" }
|
|
212
|
+
]
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: "reponseResolve",
|
|
216
|
+
type: "tuple[]",
|
|
217
|
+
internalType: "struct AttNetworkResponseResolve[]",
|
|
218
|
+
components: [
|
|
219
|
+
{ name: "keyName", type: "string", internalType: "string" },
|
|
220
|
+
{
|
|
221
|
+
name: "parseType",
|
|
222
|
+
type: "string",
|
|
223
|
+
internalType: "string"
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: "parsePath",
|
|
227
|
+
type: "string",
|
|
228
|
+
internalType: "string"
|
|
229
|
+
}
|
|
230
|
+
]
|
|
231
|
+
},
|
|
232
|
+
{ name: "data", type: "string", internalType: "string" },
|
|
233
|
+
{
|
|
234
|
+
name: "attConditions",
|
|
235
|
+
type: "string",
|
|
236
|
+
internalType: "string"
|
|
237
|
+
},
|
|
238
|
+
{ name: "timestamp", type: "uint64", internalType: "uint64" },
|
|
239
|
+
{
|
|
240
|
+
name: "additionParams",
|
|
241
|
+
type: "string",
|
|
242
|
+
internalType: "string"
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: "attestors",
|
|
246
|
+
type: "tuple[]",
|
|
247
|
+
internalType: "struct Attestor[]",
|
|
248
|
+
components: [
|
|
249
|
+
{
|
|
250
|
+
name: "attestorAddr",
|
|
251
|
+
type: "address",
|
|
252
|
+
internalType: "address"
|
|
253
|
+
},
|
|
254
|
+
{ name: "url", type: "string", internalType: "string" }
|
|
255
|
+
]
|
|
256
|
+
},
|
|
257
|
+
{ name: "signatures", type: "bytes[]", internalType: "bytes[]" }
|
|
258
|
+
]
|
|
259
|
+
}
|
|
260
|
+
],
|
|
261
|
+
outputs: [],
|
|
262
|
+
stateMutability: "payable"
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
type: "function",
|
|
266
|
+
name: "claimBySourceAndTipIndex",
|
|
267
|
+
inputs: [
|
|
268
|
+
{ name: "idSource", type: "string", internalType: "string" },
|
|
269
|
+
{
|
|
270
|
+
name: "att",
|
|
271
|
+
type: "tuple",
|
|
272
|
+
internalType: "struct Attestation",
|
|
273
|
+
components: [
|
|
274
|
+
{ name: "recipient", type: "address", internalType: "address" },
|
|
275
|
+
{
|
|
276
|
+
name: "request",
|
|
277
|
+
type: "tuple",
|
|
278
|
+
internalType: "struct AttNetworkRequest",
|
|
279
|
+
components: [
|
|
280
|
+
{ name: "url", type: "string", internalType: "string" },
|
|
281
|
+
{ name: "header", type: "string", internalType: "string" },
|
|
282
|
+
{ name: "method", type: "string", internalType: "string" },
|
|
283
|
+
{ name: "body", type: "string", internalType: "string" }
|
|
284
|
+
]
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: "reponseResolve",
|
|
288
|
+
type: "tuple[]",
|
|
289
|
+
internalType: "struct AttNetworkResponseResolve[]",
|
|
290
|
+
components: [
|
|
291
|
+
{ name: "keyName", type: "string", internalType: "string" },
|
|
292
|
+
{
|
|
293
|
+
name: "parseType",
|
|
294
|
+
type: "string",
|
|
295
|
+
internalType: "string"
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
name: "parsePath",
|
|
299
|
+
type: "string",
|
|
300
|
+
internalType: "string"
|
|
301
|
+
}
|
|
302
|
+
]
|
|
303
|
+
},
|
|
304
|
+
{ name: "data", type: "string", internalType: "string" },
|
|
305
|
+
{
|
|
306
|
+
name: "attConditions",
|
|
307
|
+
type: "string",
|
|
308
|
+
internalType: "string"
|
|
309
|
+
},
|
|
310
|
+
{ name: "timestamp", type: "uint64", internalType: "uint64" },
|
|
311
|
+
{
|
|
312
|
+
name: "additionParams",
|
|
313
|
+
type: "string",
|
|
314
|
+
internalType: "string"
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
name: "attestors",
|
|
318
|
+
type: "tuple[]",
|
|
319
|
+
internalType: "struct Attestor[]",
|
|
320
|
+
components: [
|
|
321
|
+
{
|
|
322
|
+
name: "attestorAddr",
|
|
323
|
+
type: "address",
|
|
324
|
+
internalType: "address"
|
|
325
|
+
},
|
|
326
|
+
{ name: "url", type: "string", internalType: "string" }
|
|
327
|
+
]
|
|
328
|
+
},
|
|
329
|
+
{ name: "signatures", type: "bytes[]", internalType: "bytes[]" }
|
|
330
|
+
]
|
|
331
|
+
},
|
|
332
|
+
{ name: "index", type: "uint32", internalType: "uint32" }
|
|
333
|
+
],
|
|
334
|
+
outputs: [],
|
|
335
|
+
stateMutability: "payable"
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
type: "function",
|
|
339
|
+
name: "claimFee",
|
|
340
|
+
inputs: [],
|
|
341
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
342
|
+
stateMutability: "view"
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
type: "function",
|
|
346
|
+
name: "feeRecipient",
|
|
347
|
+
inputs: [],
|
|
348
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
349
|
+
stateMutability: "view"
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
type: "function",
|
|
353
|
+
name: "getTipRecords",
|
|
354
|
+
inputs: [
|
|
355
|
+
{
|
|
356
|
+
name: "tipRecipient",
|
|
357
|
+
type: "tuple",
|
|
358
|
+
internalType: "struct TipRecipient",
|
|
359
|
+
components: [
|
|
360
|
+
{ name: "idSource", type: "string", internalType: "string" },
|
|
361
|
+
{ name: "id", type: "string", internalType: "string" }
|
|
362
|
+
]
|
|
363
|
+
}
|
|
364
|
+
],
|
|
365
|
+
outputs: [
|
|
366
|
+
{
|
|
367
|
+
name: "",
|
|
368
|
+
type: "tuple[]",
|
|
369
|
+
internalType: "struct TipRecord[]",
|
|
370
|
+
components: [
|
|
371
|
+
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
372
|
+
{
|
|
373
|
+
name: "tipToken",
|
|
374
|
+
type: "tuple",
|
|
375
|
+
internalType: "struct TipToken",
|
|
376
|
+
components: [
|
|
377
|
+
{
|
|
378
|
+
name: "tokenType",
|
|
379
|
+
type: "uint32",
|
|
380
|
+
internalType: "uint32"
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
name: "tokenAddress",
|
|
384
|
+
type: "address",
|
|
385
|
+
internalType: "address"
|
|
386
|
+
}
|
|
387
|
+
]
|
|
388
|
+
},
|
|
389
|
+
{ name: "timestamp", type: "uint64", internalType: "uint64" },
|
|
390
|
+
{ name: "tipper", type: "address", internalType: "address" },
|
|
391
|
+
{ name: "nftIds", type: "uint256[]", internalType: "uint256[]" }
|
|
392
|
+
]
|
|
393
|
+
}
|
|
394
|
+
],
|
|
395
|
+
stateMutability: "view"
|
|
396
|
+
},
|
|
397
|
+
{
|
|
398
|
+
type: "function",
|
|
399
|
+
name: "idSourceCache",
|
|
400
|
+
inputs: [{ name: "", type: "string", internalType: "string" }],
|
|
401
|
+
outputs: [
|
|
402
|
+
{ name: "url", type: "string", internalType: "string" },
|
|
403
|
+
{ name: "jsonPath", type: "string", internalType: "string" }
|
|
404
|
+
],
|
|
405
|
+
stateMutability: "view"
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
type: "function",
|
|
409
|
+
name: "initialize",
|
|
410
|
+
inputs: [
|
|
411
|
+
{ name: "owner", type: "address", internalType: "address" },
|
|
412
|
+
{
|
|
413
|
+
name: "primusZKTLS_",
|
|
414
|
+
type: "address",
|
|
415
|
+
internalType: "contract IPrimusZKTLS"
|
|
416
|
+
},
|
|
417
|
+
{ name: "feeRecipient_", type: "address", internalType: "address" },
|
|
418
|
+
{ name: "claimFee_", type: "uint256", internalType: "uint256" }
|
|
419
|
+
],
|
|
420
|
+
outputs: [],
|
|
421
|
+
stateMutability: "nonpayable"
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
type: "function",
|
|
425
|
+
name: "owner",
|
|
426
|
+
inputs: [],
|
|
427
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
428
|
+
stateMutability: "view"
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
type: "function",
|
|
432
|
+
name: "primusZKTLS",
|
|
433
|
+
inputs: [],
|
|
434
|
+
outputs: [
|
|
435
|
+
{ name: "", type: "address", internalType: "contract IPrimusZKTLS" }
|
|
436
|
+
],
|
|
437
|
+
stateMutability: "view"
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
type: "function",
|
|
441
|
+
name: "renounceOwnership",
|
|
442
|
+
inputs: [],
|
|
443
|
+
outputs: [],
|
|
444
|
+
stateMutability: "nonpayable"
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
type: "function",
|
|
448
|
+
name: "setClaimFee",
|
|
449
|
+
inputs: [
|
|
450
|
+
{ name: "claimFee_", type: "uint256", internalType: "uint256" }
|
|
451
|
+
],
|
|
452
|
+
outputs: [],
|
|
453
|
+
stateMutability: "nonpayable"
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
type: "function",
|
|
457
|
+
name: "setFeeRecipient",
|
|
458
|
+
inputs: [
|
|
459
|
+
{ name: "feeRecipient_", type: "address", internalType: "address" }
|
|
460
|
+
],
|
|
461
|
+
outputs: [],
|
|
462
|
+
stateMutability: "nonpayable"
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
type: "function",
|
|
466
|
+
name: "setPrimusZKTLS",
|
|
467
|
+
inputs: [
|
|
468
|
+
{
|
|
469
|
+
name: "primusZKTLS_",
|
|
470
|
+
type: "address",
|
|
471
|
+
internalType: "contract IPrimusZKTLS"
|
|
472
|
+
}
|
|
473
|
+
],
|
|
474
|
+
outputs: [],
|
|
475
|
+
stateMutability: "nonpayable"
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
type: "function",
|
|
479
|
+
name: "setWithdrawDelay",
|
|
480
|
+
inputs: [
|
|
481
|
+
{ name: "delay", type: "uint256", internalType: "uint256" }
|
|
482
|
+
],
|
|
483
|
+
outputs: [],
|
|
484
|
+
stateMutability: "nonpayable"
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
type: "function",
|
|
488
|
+
name: "tip",
|
|
489
|
+
inputs: [
|
|
490
|
+
{
|
|
491
|
+
name: "token",
|
|
492
|
+
type: "tuple",
|
|
493
|
+
internalType: "struct TipToken",
|
|
494
|
+
components: [
|
|
495
|
+
{ name: "tokenType", type: "uint32", internalType: "uint32" },
|
|
496
|
+
{
|
|
497
|
+
name: "tokenAddress",
|
|
498
|
+
type: "address",
|
|
499
|
+
internalType: "address"
|
|
500
|
+
}
|
|
501
|
+
]
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
name: "recipient",
|
|
505
|
+
type: "tuple",
|
|
506
|
+
internalType: "struct TipRecipientInfo",
|
|
507
|
+
components: [
|
|
508
|
+
{ name: "idSource", type: "string", internalType: "string" },
|
|
509
|
+
{ name: "id", type: "string", internalType: "string" },
|
|
510
|
+
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
511
|
+
{ name: "nftIds", type: "uint256[]", internalType: "uint256[]" }
|
|
512
|
+
]
|
|
513
|
+
}
|
|
514
|
+
],
|
|
515
|
+
outputs: [],
|
|
516
|
+
stateMutability: "payable"
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
type: "function",
|
|
520
|
+
name: "tipBatch",
|
|
521
|
+
inputs: [
|
|
522
|
+
{
|
|
523
|
+
name: "token",
|
|
524
|
+
type: "tuple",
|
|
525
|
+
internalType: "struct TipToken",
|
|
526
|
+
components: [
|
|
527
|
+
{ name: "tokenType", type: "uint32", internalType: "uint32" },
|
|
528
|
+
{
|
|
529
|
+
name: "tokenAddress",
|
|
530
|
+
type: "address",
|
|
531
|
+
internalType: "address"
|
|
532
|
+
}
|
|
533
|
+
]
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
name: "recipients",
|
|
537
|
+
type: "tuple[]",
|
|
538
|
+
internalType: "struct TipRecipientInfo[]",
|
|
539
|
+
components: [
|
|
540
|
+
{ name: "idSource", type: "string", internalType: "string" },
|
|
541
|
+
{ name: "id", type: "string", internalType: "string" },
|
|
542
|
+
{ name: "amount", type: "uint256", internalType: "uint256" },
|
|
543
|
+
{ name: "nftIds", type: "uint256[]", internalType: "uint256[]" }
|
|
544
|
+
]
|
|
545
|
+
}
|
|
546
|
+
],
|
|
547
|
+
outputs: [],
|
|
548
|
+
stateMutability: "payable"
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
type: "function",
|
|
552
|
+
name: "tipperWithdraw",
|
|
553
|
+
inputs: [
|
|
554
|
+
{
|
|
555
|
+
name: "tipRecipients",
|
|
556
|
+
type: "tuple[]",
|
|
557
|
+
internalType: "struct TipRecipient[]",
|
|
558
|
+
components: [
|
|
559
|
+
{ name: "idSource", type: "string", internalType: "string" },
|
|
560
|
+
{ name: "id", type: "string", internalType: "string" }
|
|
561
|
+
]
|
|
562
|
+
}
|
|
563
|
+
],
|
|
564
|
+
outputs: [],
|
|
565
|
+
stateMutability: "nonpayable"
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
type: "function",
|
|
569
|
+
name: "transferOwnership",
|
|
570
|
+
inputs: [
|
|
571
|
+
{ name: "newOwner", type: "address", internalType: "address" }
|
|
572
|
+
],
|
|
573
|
+
outputs: [],
|
|
574
|
+
stateMutability: "nonpayable"
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
type: "function",
|
|
578
|
+
name: "withdrawDelay",
|
|
579
|
+
inputs: [],
|
|
580
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
581
|
+
stateMutability: "view"
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
type: "event",
|
|
585
|
+
name: "ClaimEvent",
|
|
586
|
+
inputs: [
|
|
587
|
+
{
|
|
588
|
+
name: "recipient",
|
|
589
|
+
type: "address",
|
|
590
|
+
indexed: true,
|
|
591
|
+
internalType: "address"
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
name: "idSource",
|
|
595
|
+
type: "string",
|
|
596
|
+
indexed: false,
|
|
597
|
+
internalType: "string"
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
name: "id",
|
|
601
|
+
type: "string",
|
|
602
|
+
indexed: false,
|
|
603
|
+
internalType: "string"
|
|
604
|
+
},
|
|
605
|
+
{
|
|
606
|
+
name: "tipper",
|
|
607
|
+
type: "address",
|
|
608
|
+
indexed: false,
|
|
609
|
+
internalType: "address"
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
name: "tokenAddr",
|
|
613
|
+
type: "address",
|
|
614
|
+
indexed: false,
|
|
615
|
+
internalType: "address"
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
name: "amount",
|
|
619
|
+
type: "uint256",
|
|
620
|
+
indexed: false,
|
|
621
|
+
internalType: "uint256"
|
|
622
|
+
}
|
|
623
|
+
],
|
|
624
|
+
anonymous: false
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
type: "event",
|
|
628
|
+
name: "Initialized",
|
|
629
|
+
inputs: [
|
|
630
|
+
{
|
|
631
|
+
name: "version",
|
|
632
|
+
type: "uint64",
|
|
633
|
+
indexed: false,
|
|
634
|
+
internalType: "uint64"
|
|
635
|
+
}
|
|
636
|
+
],
|
|
637
|
+
anonymous: false
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
type: "event",
|
|
641
|
+
name: "OwnershipTransferred",
|
|
642
|
+
inputs: [
|
|
643
|
+
{
|
|
644
|
+
name: "previousOwner",
|
|
645
|
+
type: "address",
|
|
646
|
+
indexed: true,
|
|
647
|
+
internalType: "address"
|
|
648
|
+
},
|
|
649
|
+
{
|
|
650
|
+
name: "newOwner",
|
|
651
|
+
type: "address",
|
|
652
|
+
indexed: true,
|
|
653
|
+
internalType: "address"
|
|
654
|
+
}
|
|
655
|
+
],
|
|
656
|
+
anonymous: false
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
type: "event",
|
|
660
|
+
name: "TipEvent",
|
|
661
|
+
inputs: [
|
|
662
|
+
{
|
|
663
|
+
name: "idSource",
|
|
664
|
+
type: "string",
|
|
665
|
+
indexed: false,
|
|
666
|
+
internalType: "string"
|
|
667
|
+
},
|
|
668
|
+
{
|
|
669
|
+
name: "id",
|
|
670
|
+
type: "string",
|
|
671
|
+
indexed: false,
|
|
672
|
+
internalType: "string"
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
name: "tipper",
|
|
676
|
+
type: "address",
|
|
677
|
+
indexed: false,
|
|
678
|
+
internalType: "address"
|
|
679
|
+
}
|
|
680
|
+
],
|
|
681
|
+
anonymous: false
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
type: "event",
|
|
685
|
+
name: "WithdrawEvent",
|
|
686
|
+
inputs: [
|
|
687
|
+
{
|
|
688
|
+
name: "tipper",
|
|
689
|
+
type: "address",
|
|
690
|
+
indexed: true,
|
|
691
|
+
internalType: "address"
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
name: "tokenAddr",
|
|
695
|
+
type: "address",
|
|
696
|
+
indexed: true,
|
|
697
|
+
internalType: "address"
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
name: "amount",
|
|
701
|
+
type: "uint256",
|
|
702
|
+
indexed: false,
|
|
703
|
+
internalType: "uint256"
|
|
704
|
+
}
|
|
705
|
+
],
|
|
706
|
+
anonymous: false
|
|
707
|
+
},
|
|
708
|
+
{ type: "error", name: "InvalidInitialization", inputs: [] },
|
|
709
|
+
{ type: "error", name: "NotInitializing", inputs: [] },
|
|
710
|
+
{
|
|
711
|
+
type: "error",
|
|
712
|
+
name: "OwnableInvalidOwner",
|
|
713
|
+
inputs: [
|
|
714
|
+
{ name: "owner", type: "address", internalType: "address" }
|
|
715
|
+
]
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
type: "error",
|
|
719
|
+
name: "OwnableUnauthorizedAccount",
|
|
720
|
+
inputs: [
|
|
721
|
+
{ name: "account", type: "address", internalType: "address" }
|
|
722
|
+
]
|
|
723
|
+
},
|
|
724
|
+
{ type: "error", name: "ReentrancyGuardReentrantCall", inputs: [] }
|
|
725
|
+
];
|
|
726
|
+
|
|
727
|
+
// src/config/erc20Abi.json
|
|
728
|
+
var erc20Abi_default = [
|
|
729
|
+
{
|
|
730
|
+
type: "function",
|
|
731
|
+
name: "allowance",
|
|
732
|
+
inputs: [
|
|
733
|
+
{
|
|
734
|
+
name: "owner",
|
|
735
|
+
type: "address",
|
|
736
|
+
internalType: "address"
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
name: "spender",
|
|
740
|
+
type: "address",
|
|
741
|
+
internalType: "address"
|
|
742
|
+
}
|
|
743
|
+
],
|
|
744
|
+
outputs: [
|
|
745
|
+
{
|
|
746
|
+
name: "",
|
|
747
|
+
type: "uint256",
|
|
748
|
+
internalType: "uint256"
|
|
749
|
+
}
|
|
750
|
+
],
|
|
751
|
+
stateMutability: "view"
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
type: "function",
|
|
755
|
+
name: "approve",
|
|
756
|
+
inputs: [
|
|
757
|
+
{
|
|
758
|
+
name: "spender",
|
|
759
|
+
type: "address",
|
|
760
|
+
internalType: "address"
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
name: "value",
|
|
764
|
+
type: "uint256",
|
|
765
|
+
internalType: "uint256"
|
|
766
|
+
}
|
|
767
|
+
],
|
|
768
|
+
outputs: [
|
|
769
|
+
{
|
|
770
|
+
name: "",
|
|
771
|
+
type: "bool",
|
|
772
|
+
internalType: "bool"
|
|
773
|
+
}
|
|
774
|
+
],
|
|
775
|
+
stateMutability: "nonpayable"
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
type: "function",
|
|
779
|
+
name: "balanceOf",
|
|
780
|
+
inputs: [
|
|
781
|
+
{
|
|
782
|
+
name: "account",
|
|
783
|
+
type: "address",
|
|
784
|
+
internalType: "address"
|
|
785
|
+
}
|
|
786
|
+
],
|
|
787
|
+
outputs: [
|
|
788
|
+
{
|
|
789
|
+
name: "",
|
|
790
|
+
type: "uint256",
|
|
791
|
+
internalType: "uint256"
|
|
792
|
+
}
|
|
793
|
+
],
|
|
794
|
+
stateMutability: "view"
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
type: "function",
|
|
798
|
+
name: "decimals",
|
|
799
|
+
inputs: [],
|
|
800
|
+
outputs: [
|
|
801
|
+
{
|
|
802
|
+
name: "",
|
|
803
|
+
type: "uint8",
|
|
804
|
+
internalType: "uint8"
|
|
805
|
+
}
|
|
806
|
+
],
|
|
807
|
+
stateMutability: "view"
|
|
808
|
+
},
|
|
809
|
+
{
|
|
810
|
+
type: "function",
|
|
811
|
+
name: "name",
|
|
812
|
+
inputs: [],
|
|
813
|
+
outputs: [
|
|
814
|
+
{
|
|
815
|
+
name: "",
|
|
816
|
+
type: "string",
|
|
817
|
+
internalType: "string"
|
|
818
|
+
}
|
|
819
|
+
],
|
|
820
|
+
stateMutability: "view"
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
type: "function",
|
|
824
|
+
name: "symbol",
|
|
825
|
+
inputs: [],
|
|
826
|
+
outputs: [
|
|
827
|
+
{
|
|
828
|
+
name: "",
|
|
829
|
+
type: "string",
|
|
830
|
+
internalType: "string"
|
|
831
|
+
}
|
|
832
|
+
],
|
|
833
|
+
stateMutability: "view"
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
type: "function",
|
|
837
|
+
name: "totalSupply",
|
|
838
|
+
inputs: [],
|
|
839
|
+
outputs: [
|
|
840
|
+
{
|
|
841
|
+
name: "",
|
|
842
|
+
type: "uint256",
|
|
843
|
+
internalType: "uint256"
|
|
844
|
+
}
|
|
845
|
+
],
|
|
846
|
+
stateMutability: "view"
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
type: "function",
|
|
850
|
+
name: "transfer",
|
|
851
|
+
inputs: [
|
|
852
|
+
{
|
|
853
|
+
name: "to",
|
|
854
|
+
type: "address",
|
|
855
|
+
internalType: "address"
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
name: "value",
|
|
859
|
+
type: "uint256",
|
|
860
|
+
internalType: "uint256"
|
|
861
|
+
}
|
|
862
|
+
],
|
|
863
|
+
outputs: [
|
|
864
|
+
{
|
|
865
|
+
name: "",
|
|
866
|
+
type: "bool",
|
|
867
|
+
internalType: "bool"
|
|
868
|
+
}
|
|
869
|
+
],
|
|
870
|
+
stateMutability: "nonpayable"
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
type: "function",
|
|
874
|
+
name: "transferFrom",
|
|
875
|
+
inputs: [
|
|
876
|
+
{
|
|
877
|
+
name: "from",
|
|
878
|
+
type: "address",
|
|
879
|
+
internalType: "address"
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
name: "to",
|
|
883
|
+
type: "address",
|
|
884
|
+
internalType: "address"
|
|
885
|
+
},
|
|
886
|
+
{
|
|
887
|
+
name: "value",
|
|
888
|
+
type: "uint256",
|
|
889
|
+
internalType: "uint256"
|
|
890
|
+
}
|
|
891
|
+
],
|
|
892
|
+
outputs: [
|
|
893
|
+
{
|
|
894
|
+
name: "",
|
|
895
|
+
type: "bool",
|
|
896
|
+
internalType: "bool"
|
|
897
|
+
}
|
|
898
|
+
],
|
|
899
|
+
stateMutability: "nonpayable"
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
type: "event",
|
|
903
|
+
name: "Approval",
|
|
904
|
+
inputs: [
|
|
905
|
+
{
|
|
906
|
+
name: "owner",
|
|
907
|
+
type: "address",
|
|
908
|
+
indexed: true,
|
|
909
|
+
internalType: "address"
|
|
910
|
+
},
|
|
911
|
+
{
|
|
912
|
+
name: "spender",
|
|
913
|
+
type: "address",
|
|
914
|
+
indexed: true,
|
|
915
|
+
internalType: "address"
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
name: "value",
|
|
919
|
+
type: "uint256",
|
|
920
|
+
indexed: false,
|
|
921
|
+
internalType: "uint256"
|
|
922
|
+
}
|
|
923
|
+
],
|
|
924
|
+
anonymous: false
|
|
925
|
+
},
|
|
926
|
+
{
|
|
927
|
+
type: "event",
|
|
928
|
+
name: "Transfer",
|
|
929
|
+
inputs: [
|
|
930
|
+
{
|
|
931
|
+
name: "from",
|
|
932
|
+
type: "address",
|
|
933
|
+
indexed: true,
|
|
934
|
+
internalType: "address"
|
|
935
|
+
},
|
|
936
|
+
{
|
|
937
|
+
name: "to",
|
|
938
|
+
type: "address",
|
|
939
|
+
indexed: true,
|
|
940
|
+
internalType: "address"
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
name: "value",
|
|
944
|
+
type: "uint256",
|
|
945
|
+
indexed: false,
|
|
946
|
+
internalType: "uint256"
|
|
947
|
+
}
|
|
948
|
+
],
|
|
949
|
+
anonymous: false
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
type: "error",
|
|
953
|
+
name: "ERC20InsufficientAllowance",
|
|
954
|
+
inputs: [
|
|
955
|
+
{
|
|
956
|
+
name: "spender",
|
|
957
|
+
type: "address",
|
|
958
|
+
internalType: "address"
|
|
959
|
+
},
|
|
960
|
+
{
|
|
961
|
+
name: "allowance",
|
|
962
|
+
type: "uint256",
|
|
963
|
+
internalType: "uint256"
|
|
964
|
+
},
|
|
965
|
+
{
|
|
966
|
+
name: "needed",
|
|
967
|
+
type: "uint256",
|
|
968
|
+
internalType: "uint256"
|
|
969
|
+
}
|
|
970
|
+
]
|
|
971
|
+
},
|
|
972
|
+
{
|
|
973
|
+
type: "error",
|
|
974
|
+
name: "ERC20InsufficientBalance",
|
|
975
|
+
inputs: [
|
|
976
|
+
{
|
|
977
|
+
name: "sender",
|
|
978
|
+
type: "address",
|
|
979
|
+
internalType: "address"
|
|
980
|
+
},
|
|
981
|
+
{
|
|
982
|
+
name: "balance",
|
|
983
|
+
type: "uint256",
|
|
984
|
+
internalType: "uint256"
|
|
985
|
+
},
|
|
986
|
+
{
|
|
987
|
+
name: "needed",
|
|
988
|
+
type: "uint256",
|
|
989
|
+
internalType: "uint256"
|
|
990
|
+
}
|
|
991
|
+
]
|
|
992
|
+
},
|
|
993
|
+
{
|
|
994
|
+
type: "error",
|
|
995
|
+
name: "ERC20InvalidApprover",
|
|
996
|
+
inputs: [
|
|
997
|
+
{
|
|
998
|
+
name: "approver",
|
|
999
|
+
type: "address",
|
|
1000
|
+
internalType: "address"
|
|
1001
|
+
}
|
|
1002
|
+
]
|
|
1003
|
+
},
|
|
1004
|
+
{
|
|
1005
|
+
type: "error",
|
|
1006
|
+
name: "ERC20InvalidReceiver",
|
|
1007
|
+
inputs: [
|
|
1008
|
+
{
|
|
1009
|
+
name: "receiver",
|
|
1010
|
+
type: "address",
|
|
1011
|
+
internalType: "address"
|
|
1012
|
+
}
|
|
1013
|
+
]
|
|
1014
|
+
},
|
|
1015
|
+
{
|
|
1016
|
+
type: "error",
|
|
1017
|
+
name: "ERC20InvalidSender",
|
|
1018
|
+
inputs: [
|
|
1019
|
+
{
|
|
1020
|
+
name: "sender",
|
|
1021
|
+
type: "address",
|
|
1022
|
+
internalType: "address"
|
|
1023
|
+
}
|
|
1024
|
+
]
|
|
1025
|
+
},
|
|
1026
|
+
{
|
|
1027
|
+
type: "error",
|
|
1028
|
+
name: "ERC20InvalidSpender",
|
|
1029
|
+
inputs: [
|
|
1030
|
+
{
|
|
1031
|
+
name: "spender",
|
|
1032
|
+
type: "address",
|
|
1033
|
+
internalType: "address"
|
|
1034
|
+
}
|
|
1035
|
+
]
|
|
1036
|
+
}
|
|
1037
|
+
];
|
|
1038
|
+
|
|
1039
|
+
// src/classes/Fund.ts
|
|
1040
|
+
var Fund = class {
|
|
1041
|
+
_attestLoading;
|
|
1042
|
+
zkTlsSdk;
|
|
1043
|
+
fundContract;
|
|
1044
|
+
provider;
|
|
1045
|
+
_dataSourceTemplateMap = DATASOURCETEMPLATEMAP;
|
|
1046
|
+
constructor() {
|
|
1047
|
+
this._attestLoading = false;
|
|
1048
|
+
}
|
|
1049
|
+
getZkTlsSdk() {
|
|
1050
|
+
return this.zkTlsSdk;
|
|
1051
|
+
}
|
|
1052
|
+
async init(provider, chainId, appId) {
|
|
1053
|
+
return new Promise(async (resolve, reject) => {
|
|
1054
|
+
try {
|
|
1055
|
+
const network = await provider.getNetwork();
|
|
1056
|
+
const providerChainId = network.chainId;
|
|
1057
|
+
console.log("init provider", provider, network);
|
|
1058
|
+
if (providerChainId !== chainId) {
|
|
1059
|
+
return reject(`Please connect to the chain with ID ${chainId} first.`);
|
|
1060
|
+
}
|
|
1061
|
+
const fundContractAddress = Fund_CONTRACTS[chainId];
|
|
1062
|
+
if (!fundContractAddress) {
|
|
1063
|
+
return reject(`Unsupported chainId:${chainId}`);
|
|
1064
|
+
}
|
|
1065
|
+
this.fundContract = new Contract_default(provider, fundContractAddress, abi_default);
|
|
1066
|
+
this.provider = provider;
|
|
1067
|
+
if (appId) {
|
|
1068
|
+
this.zkTlsSdk = new import_zktls_js_sdk.PrimusZKTLS();
|
|
1069
|
+
const extensionVersion = await this.zkTlsSdk.init(
|
|
1070
|
+
appId
|
|
1071
|
+
);
|
|
1072
|
+
resolve(extensionVersion);
|
|
1073
|
+
} else {
|
|
1074
|
+
resolve("success");
|
|
1075
|
+
}
|
|
1076
|
+
} catch (error) {
|
|
1077
|
+
return reject(error);
|
|
1078
|
+
}
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
async fund(tokenInfo, recipientInfo) {
|
|
1082
|
+
return new Promise(async (resolve, reject) => {
|
|
1083
|
+
try {
|
|
1084
|
+
const recipientInfos = [];
|
|
1085
|
+
recipientInfos[0] = recipientInfo;
|
|
1086
|
+
let decimals = 18;
|
|
1087
|
+
let params = [];
|
|
1088
|
+
if (tokenInfo.tokenType === 0) {
|
|
1089
|
+
await this.approve(tokenInfo, recipientInfos);
|
|
1090
|
+
const erc20Contract = new import_ethers2.ethers.Contract(tokenInfo.tokenAddress, erc20Abi_default, this.provider);
|
|
1091
|
+
decimals = await erc20Contract.decimals();
|
|
1092
|
+
}
|
|
1093
|
+
const tokenAmount = import_ethers2.ethers.utils.parseUnits(recipientInfo.tokenAmount.toString(), decimals);
|
|
1094
|
+
const newFundRecipientInfo = {
|
|
1095
|
+
idSource: recipientInfo.socialPlatform,
|
|
1096
|
+
id: recipientInfo.userIdentifier,
|
|
1097
|
+
amount: tokenAmount,
|
|
1098
|
+
nftIds: []
|
|
1099
|
+
};
|
|
1100
|
+
if (tokenInfo.tokenType === 0) {
|
|
1101
|
+
params = [tokenInfo, newFundRecipientInfo];
|
|
1102
|
+
} else {
|
|
1103
|
+
params = [tokenInfo, newFundRecipientInfo, { value: tokenAmount }];
|
|
1104
|
+
}
|
|
1105
|
+
const result = await this.fundContract.sendTransaction("tip", params);
|
|
1106
|
+
resolve(result);
|
|
1107
|
+
} catch (error) {
|
|
1108
|
+
return reject(error);
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
}
|
|
1112
|
+
async refund(recipients) {
|
|
1113
|
+
return new Promise(async (resolve, reject) => {
|
|
1114
|
+
try {
|
|
1115
|
+
const newRecipients = recipients.map((i) => {
|
|
1116
|
+
return {
|
|
1117
|
+
idSource: i.socialPlatform,
|
|
1118
|
+
id: i.userIdentifier
|
|
1119
|
+
};
|
|
1120
|
+
});
|
|
1121
|
+
const result = await this.fundContract.sendTransaction("tipperWithdraw", [newRecipients]);
|
|
1122
|
+
return resolve(result);
|
|
1123
|
+
} catch (error) {
|
|
1124
|
+
return reject(error);
|
|
1125
|
+
}
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
async fundBatch(tokenInfo, recipientInfoList) {
|
|
1129
|
+
return new Promise(async (resolve, reject) => {
|
|
1130
|
+
try {
|
|
1131
|
+
let decimals = 18;
|
|
1132
|
+
let params = [];
|
|
1133
|
+
if (tokenInfo.tokenType === 0) {
|
|
1134
|
+
await this.approve(tokenInfo, recipientInfoList);
|
|
1135
|
+
const erc20Contract = new import_ethers2.ethers.Contract(tokenInfo.tokenAddress, erc20Abi_default, this.provider);
|
|
1136
|
+
decimals = await erc20Contract.decimals();
|
|
1137
|
+
}
|
|
1138
|
+
let totalFormatAmount = recipientInfoList.reduce((acc, cur) => acc.add(import_ethers2.ethers.utils.parseUnits(cur.tokenAmount.toString(), decimals)), import_ethers2.ethers.BigNumber.from(0));
|
|
1139
|
+
const newRecipientInfoList = recipientInfoList.map((i) => {
|
|
1140
|
+
const formatAmount = import_ethers2.ethers.utils.parseUnits(i.tokenAmount.toString(), decimals);
|
|
1141
|
+
return {
|
|
1142
|
+
idSource: i.socialPlatform,
|
|
1143
|
+
id: i.userIdentifier,
|
|
1144
|
+
amount: formatAmount,
|
|
1145
|
+
nftIds: []
|
|
1146
|
+
};
|
|
1147
|
+
});
|
|
1148
|
+
if (tokenInfo.tokenType === 0) {
|
|
1149
|
+
params = [tokenInfo, newRecipientInfoList];
|
|
1150
|
+
} else {
|
|
1151
|
+
params = [tokenInfo, newRecipientInfoList, { value: totalFormatAmount }];
|
|
1152
|
+
}
|
|
1153
|
+
const result = await this.fundContract.sendTransaction("tipBatch", params);
|
|
1154
|
+
return resolve(result);
|
|
1155
|
+
} catch (error) {
|
|
1156
|
+
return reject(error);
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
async approve(tokenInfo, recipientInfoList) {
|
|
1161
|
+
return new Promise(async (resolve, reject) => {
|
|
1162
|
+
try {
|
|
1163
|
+
const signer = this.provider.getSigner();
|
|
1164
|
+
const address = await signer.getAddress();
|
|
1165
|
+
const erc20Contract = new import_ethers2.ethers.Contract(tokenInfo.tokenAddress, erc20Abi_default, signer);
|
|
1166
|
+
const allowance = await erc20Contract.allowance(address, this.fundContract.address);
|
|
1167
|
+
const decimals = await erc20Contract.decimals();
|
|
1168
|
+
const requiredAllowance = recipientInfoList.reduce((acc, cur) => acc.add(import_ethers2.ethers.utils.parseUnits(cur.tokenAmount.toString(), decimals)), import_ethers2.ethers.BigNumber.from(0));
|
|
1169
|
+
if (allowance.lt(requiredAllowance)) {
|
|
1170
|
+
const tx = await erc20Contract.approve(this.fundContract.address, requiredAllowance);
|
|
1171
|
+
await tx.wait();
|
|
1172
|
+
console.log(`Approved: ${requiredAllowance.toString()}`);
|
|
1173
|
+
} else {
|
|
1174
|
+
console.log(`Already approved: ${allowance.toString()}`);
|
|
1175
|
+
}
|
|
1176
|
+
resolve("Approved");
|
|
1177
|
+
} catch (error) {
|
|
1178
|
+
console.error("Approval failed:", error);
|
|
1179
|
+
if (error?.code === "ACTION_REJECTED") {
|
|
1180
|
+
return reject("user rejected transaction");
|
|
1181
|
+
}
|
|
1182
|
+
return reject(error);
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
}
|
|
1186
|
+
async attest(socialPlatform, address, genAppSignature) {
|
|
1187
|
+
return new Promise(async (resolve, reject) => {
|
|
1188
|
+
if (!this.zkTlsSdk?.padoExtensionVersion) {
|
|
1189
|
+
return reject(`Uninitialized!`);
|
|
1190
|
+
}
|
|
1191
|
+
if (this._attestLoading) {
|
|
1192
|
+
return reject(`Under proof!`);
|
|
1193
|
+
}
|
|
1194
|
+
this._attestLoading = true;
|
|
1195
|
+
const templateId = this._dataSourceTemplateMap[socialPlatform];
|
|
1196
|
+
const attRequest = this.zkTlsSdk.generateRequestParams(
|
|
1197
|
+
templateId,
|
|
1198
|
+
address
|
|
1199
|
+
);
|
|
1200
|
+
const signParams = attRequest.toJsonString();
|
|
1201
|
+
const signature = await genAppSignature(signParams);
|
|
1202
|
+
if (!signature) {
|
|
1203
|
+
return reject(`appSignature is empty!`);
|
|
1204
|
+
}
|
|
1205
|
+
try {
|
|
1206
|
+
const formatAttestParams = {
|
|
1207
|
+
attRequest: {
|
|
1208
|
+
...JSON.parse(signParams)
|
|
1209
|
+
},
|
|
1210
|
+
appSignature: signature
|
|
1211
|
+
};
|
|
1212
|
+
const attestation = await this.zkTlsSdk.startAttestation(
|
|
1213
|
+
JSON.stringify(formatAttestParams)
|
|
1214
|
+
);
|
|
1215
|
+
this._attestLoading = false;
|
|
1216
|
+
resolve(attestation);
|
|
1217
|
+
} catch (error) {
|
|
1218
|
+
return reject(error);
|
|
1219
|
+
}
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
async claimBySource(socialPlatform, userIdentifier, attestation) {
|
|
1223
|
+
return new Promise(async (resolve, reject) => {
|
|
1224
|
+
try {
|
|
1225
|
+
const claimFee = await this.fundContract.callMethod("claimFee", []);
|
|
1226
|
+
const fundRecords = await this.fundContract.callMethod("getTipRecords", [{ idSource: socialPlatform, id: userIdentifier }]);
|
|
1227
|
+
console.log("fundRecords", fundRecords);
|
|
1228
|
+
const recordCount = fundRecords.length;
|
|
1229
|
+
if (fundRecords <= 0) {
|
|
1230
|
+
return reject(`No fund records.`);
|
|
1231
|
+
} else {
|
|
1232
|
+
const totalFee = claimFee.mul(recordCount);
|
|
1233
|
+
const txreceipt = await this.fundContract.sendTransaction("claimBySource", [socialPlatform, attestation, { value: totalFee }]);
|
|
1234
|
+
return resolve(txreceipt);
|
|
1235
|
+
}
|
|
1236
|
+
} catch (error) {
|
|
1237
|
+
return reject(error);
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
}
|
|
1241
|
+
async claimByMultiSource(socialPlatforms, userIdentifiers, attestationList) {
|
|
1242
|
+
return new Promise(async (resolve, reject) => {
|
|
1243
|
+
try {
|
|
1244
|
+
if (socialPlatforms.length !== userIdentifiers.length || socialPlatforms.length !== attestationList.length) {
|
|
1245
|
+
return reject(`socialPlatforms, userIdentifiers, attestationList length must be equal.`);
|
|
1246
|
+
}
|
|
1247
|
+
const claimFee = await this.fundContract.callMethod("claimFee", []);
|
|
1248
|
+
let allFundRecords = [];
|
|
1249
|
+
let recordCount = 0;
|
|
1250
|
+
for (const [index, value] of socialPlatforms.entries()) {
|
|
1251
|
+
const fundRecords = await this.fundContract.callMethod("getTipRecords", [{ idSource: value, id: userIdentifiers[index] }]);
|
|
1252
|
+
allFundRecords.push(...fundRecords);
|
|
1253
|
+
recordCount += fundRecords.length;
|
|
1254
|
+
}
|
|
1255
|
+
if (recordCount <= 0) {
|
|
1256
|
+
return reject(`No fund records.`);
|
|
1257
|
+
} else {
|
|
1258
|
+
const totalFee = claimFee.mul(recordCount);
|
|
1259
|
+
const txreceipt = await this.fundContract.sendTransaction("claimByMultiSource", [socialPlatforms, userIdentifiers, attestationList, { value: totalFee }]);
|
|
1260
|
+
return resolve(txreceipt);
|
|
1261
|
+
}
|
|
1262
|
+
} catch (error) {
|
|
1263
|
+
console.error("claimByMultiSource", error);
|
|
1264
|
+
return reject(error);
|
|
1265
|
+
}
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
};
|
|
1269
|
+
|
|
1270
|
+
// src/index.ts
|
|
1271
|
+
var PrimusFund = class {
|
|
1272
|
+
supportedChainIds = SUPPORTEDCHAINIDS;
|
|
1273
|
+
supportedSocialPlatforms = SUPPORTEDSOCIALPLATFORMS;
|
|
1274
|
+
_fund;
|
|
1275
|
+
async init(provider, chainId, appId) {
|
|
1276
|
+
return new Promise(async (resolve, reject) => {
|
|
1277
|
+
try {
|
|
1278
|
+
if (!this.supportedChainIds.includes(chainId)) {
|
|
1279
|
+
return reject("chainId is not supported");
|
|
1280
|
+
}
|
|
1281
|
+
this._fund = new Fund();
|
|
1282
|
+
const result = await this._fund.init(new import_ethers3.ethers.providers.Web3Provider(provider), chainId, appId);
|
|
1283
|
+
return resolve(result);
|
|
1284
|
+
} catch (error) {
|
|
1285
|
+
return reject(error);
|
|
1286
|
+
}
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
async fund(fundParam) {
|
|
1290
|
+
return new Promise(async (resolve, reject) => {
|
|
1291
|
+
try {
|
|
1292
|
+
const { tokenInfo, recipientInfos } = fundParam;
|
|
1293
|
+
if (!recipientInfos || recipientInfos.length === 0) {
|
|
1294
|
+
return reject("recipientInfos is empty");
|
|
1295
|
+
}
|
|
1296
|
+
const hasUnsupportedSocialPlatforms = recipientInfos.some((i) => !this.supportedSocialPlatforms.includes(i.socialPlatform.toLowerCase()));
|
|
1297
|
+
if (hasUnsupportedSocialPlatforms) {
|
|
1298
|
+
return reject("socialPlatform is not supported");
|
|
1299
|
+
}
|
|
1300
|
+
if (tokenInfo.tokenType === 1) {
|
|
1301
|
+
tokenInfo.tokenAddress = import_ethers3.ethers.constants.AddressZero;
|
|
1302
|
+
}
|
|
1303
|
+
const newFundRecipientInfos = recipientInfos.map((i) => {
|
|
1304
|
+
i.nftIds = [];
|
|
1305
|
+
i.socialPlatform = i.socialPlatform.toLowerCase();
|
|
1306
|
+
return i;
|
|
1307
|
+
});
|
|
1308
|
+
if (recipientInfos.length === 1) {
|
|
1309
|
+
const result = await this._fund?.fund(tokenInfo, newFundRecipientInfos[0]);
|
|
1310
|
+
return resolve(result);
|
|
1311
|
+
} else if (recipientInfos.length > 1) {
|
|
1312
|
+
const result = await this._fund?.fundBatch(tokenInfo, newFundRecipientInfos);
|
|
1313
|
+
return resolve(result);
|
|
1314
|
+
}
|
|
1315
|
+
} catch (error) {
|
|
1316
|
+
return reject(error);
|
|
1317
|
+
}
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
async refund(recipients) {
|
|
1321
|
+
return new Promise(async (resolve, reject) => {
|
|
1322
|
+
try {
|
|
1323
|
+
if (!recipients || recipients.length === 0) {
|
|
1324
|
+
return reject("recipients is empty");
|
|
1325
|
+
}
|
|
1326
|
+
const newRecipients = recipients.map((i) => {
|
|
1327
|
+
i.socialPlatform = i.socialPlatform.toLowerCase();
|
|
1328
|
+
return i;
|
|
1329
|
+
});
|
|
1330
|
+
const result = await this._fund?.refund(newRecipients);
|
|
1331
|
+
return resolve(result);
|
|
1332
|
+
} catch (error) {
|
|
1333
|
+
return reject(error);
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
}
|
|
1337
|
+
async attest(socialPlatform, address, genAppSignature) {
|
|
1338
|
+
return new Promise(async (resolve, reject) => {
|
|
1339
|
+
try {
|
|
1340
|
+
const lcSocialPlatform = socialPlatform.toLowerCase();
|
|
1341
|
+
const attestation = await this._fund?.attest(lcSocialPlatform, address, genAppSignature);
|
|
1342
|
+
return resolve(attestation);
|
|
1343
|
+
} catch (error) {
|
|
1344
|
+
return reject(error);
|
|
1345
|
+
}
|
|
1346
|
+
});
|
|
1347
|
+
}
|
|
1348
|
+
async claim(claimParams) {
|
|
1349
|
+
const claimParamList = Array.isArray(claimParams) ? claimParams : [claimParams];
|
|
1350
|
+
return new Promise(async (resolve, reject) => {
|
|
1351
|
+
if (!claimParamList || claimParamList?.length === 0) {
|
|
1352
|
+
const error = new Error("claimParams is empty");
|
|
1353
|
+
return reject(error);
|
|
1354
|
+
}
|
|
1355
|
+
const socialPlatforms = [];
|
|
1356
|
+
const userIdentifiers = [];
|
|
1357
|
+
const attestations = [];
|
|
1358
|
+
for (let i = 0; i < claimParamList.length; i++) {
|
|
1359
|
+
socialPlatforms[i] = claimParamList[i].socialPlatform.toLowerCase();
|
|
1360
|
+
attestations[i] = claimParamList[i].attestation;
|
|
1361
|
+
userIdentifiers[i] = claimParamList[i].userIdentifier;
|
|
1362
|
+
}
|
|
1363
|
+
if (socialPlatforms.length !== userIdentifiers.length || socialPlatforms.length !== attestations.length) {
|
|
1364
|
+
return reject(`claimParamList is wrong`);
|
|
1365
|
+
}
|
|
1366
|
+
try {
|
|
1367
|
+
if (socialPlatforms.length === 1) {
|
|
1368
|
+
const result = await this._fund?.claimBySource(socialPlatforms[0], userIdentifiers[0], attestations[0]);
|
|
1369
|
+
resolve(result);
|
|
1370
|
+
} else if (socialPlatforms.length > 1) {
|
|
1371
|
+
const result = await this._fund?.claimByMultiSource(socialPlatforms, userIdentifiers, attestations);
|
|
1372
|
+
return resolve(result);
|
|
1373
|
+
}
|
|
1374
|
+
} catch (error) {
|
|
1375
|
+
return reject(error);
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1381
|
+
0 && (module.exports = {
|
|
1382
|
+
PrimusFund
|
|
1383
|
+
});
|