@avacuscc/sdk 0.1.0 → 0.2.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 +246 -0
- package/package.json +1 -1
- package/packages/sdk/dist/{chunk-T5BAFYHX.mjs → chunk-XWC6XZPN.mjs} +68 -12
- package/packages/sdk/dist/index.d.mts +663 -7
- package/packages/sdk/dist/index.d.ts +663 -7
- package/packages/sdk/dist/index.js +520 -16
- package/packages/sdk/dist/index.mjs +455 -5
- package/packages/sdk/dist/{sns-D0rtlsZp.d.mts → sns-Zwan9DNM.d.mts} +24 -1
- package/packages/sdk/dist/{sns-D0rtlsZp.d.ts → sns-Zwan9DNM.d.ts} +24 -1
- package/packages/sdk/dist/sns.d.mts +1 -1
- package/packages/sdk/dist/sns.d.ts +1 -1
- package/packages/sdk/dist/sns.js +71 -12
- package/packages/sdk/dist/sns.mjs +7 -1
|
@@ -22,8 +22,12 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
AVACUS_ENDPOINTS: () => AVACUS_ENDPOINTS,
|
|
24
24
|
AvacusClient: () => AvacusClient,
|
|
25
|
+
BASE_CONNECT_SIGNED_MSG: () => BASE_CONNECT_SIGNED_MSG,
|
|
26
|
+
BASE_GAS_SPONSOR_SIGNED_MSG: () => BASE_GAS_SPONSOR_SIGNED_MSG,
|
|
27
|
+
BASE_REDIRECT_SIGNED_MSG: () => BASE_REDIRECT_SIGNED_MSG,
|
|
25
28
|
BalancerService: () => BalancerService,
|
|
26
29
|
DEFAULT_BASE_SIGNED_MESSAGE: () => DEFAULT_BASE_SIGNED_MESSAGE,
|
|
30
|
+
DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION: () => DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION,
|
|
27
31
|
GAS_ACCOUNT_SERVICE_PATH: () => GAS_ACCOUNT_SERVICE_PATH,
|
|
28
32
|
GasAccountService: () => GasAccountService,
|
|
29
33
|
HttpAdapter: () => HttpAdapter,
|
|
@@ -136,6 +140,49 @@ var HttpAdapter = class {
|
|
|
136
140
|
});
|
|
137
141
|
return this.parseResponse(response, "POST", path);
|
|
138
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Sends an HTTP PUT request with a JSON body to a path relative to this adapter base URL.
|
|
145
|
+
*
|
|
146
|
+
* @param path Relative endpoint path.
|
|
147
|
+
* @param body Serializable request payload.
|
|
148
|
+
* @param options Request behavior such as auth requirement and extra headers.
|
|
149
|
+
*/
|
|
150
|
+
async put(path, body, options = {}) {
|
|
151
|
+
const response = await fetch(this.buildUrl(path), {
|
|
152
|
+
method: "PUT",
|
|
153
|
+
headers: this.buildHeaders({
|
|
154
|
+
...options,
|
|
155
|
+
headers: {
|
|
156
|
+
"Content-Type": "application/json",
|
|
157
|
+
...options.headers
|
|
158
|
+
}
|
|
159
|
+
}),
|
|
160
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
161
|
+
});
|
|
162
|
+
return this.parseResponse(response, "PUT", path);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Sends an HTTP DELETE request with an optional JSON body to a path relative to this adapter base URL.
|
|
166
|
+
*
|
|
167
|
+
* @param path Relative endpoint path.
|
|
168
|
+
* @param body Optional serializable request payload.
|
|
169
|
+
* @param options Request behavior such as auth requirement and extra headers.
|
|
170
|
+
*/
|
|
171
|
+
async delete(path, body, options = {}) {
|
|
172
|
+
const headers = body === void 0 ? this.buildHeaders(options) : this.buildHeaders({
|
|
173
|
+
...options,
|
|
174
|
+
headers: {
|
|
175
|
+
"Content-Type": "application/json",
|
|
176
|
+
...options.headers
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
const response = await fetch(this.buildUrl(path), {
|
|
180
|
+
method: "DELETE",
|
|
181
|
+
headers,
|
|
182
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
183
|
+
});
|
|
184
|
+
return this.parseResponse(response, "DELETE", path);
|
|
185
|
+
}
|
|
139
186
|
/**
|
|
140
187
|
* Builds the final request headers by combining default headers, per-request
|
|
141
188
|
* headers, and an authorization header when the request requires auth.
|
|
@@ -187,6 +234,14 @@ var BalancerService = class {
|
|
|
187
234
|
this.http = http;
|
|
188
235
|
}
|
|
189
236
|
http;
|
|
237
|
+
/**
|
|
238
|
+
* Returns the list of balancer pools.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* const pools = await client.balancer.getPools();
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
190
245
|
async getPools() {
|
|
191
246
|
return this.http.get("balancer/pools");
|
|
192
247
|
}
|
|
@@ -194,6 +249,30 @@ var BalancerService = class {
|
|
|
194
249
|
|
|
195
250
|
// packages/sdk/src/services/gasAccount.ts
|
|
196
251
|
var GAS_ACCOUNT_SERVICE_PATH = "1/gas-account/";
|
|
252
|
+
var DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION = "1";
|
|
253
|
+
var REGISTER_WHITELIST_SPENDERS_TYPED_DATA = {
|
|
254
|
+
domain: {
|
|
255
|
+
name: "AvacusGasAccount"
|
|
256
|
+
},
|
|
257
|
+
types: {
|
|
258
|
+
SpenderEntry: [
|
|
259
|
+
{ name: "address", type: "address" },
|
|
260
|
+
{ name: "expiresAt", type: "uint256" }
|
|
261
|
+
],
|
|
262
|
+
RegisterSpenders: [
|
|
263
|
+
{ name: "owner", type: "address" },
|
|
264
|
+
{ name: "spenders", type: "SpenderEntry[]" },
|
|
265
|
+
{ name: "nonce", type: "uint256" },
|
|
266
|
+
{ name: "deadline", type: "uint256" }
|
|
267
|
+
]
|
|
268
|
+
},
|
|
269
|
+
primaryType: "RegisterSpenders"
|
|
270
|
+
};
|
|
271
|
+
function toMutableTypedDataTypes(types) {
|
|
272
|
+
return Object.fromEntries(
|
|
273
|
+
Object.entries(types).map(([key, fields]) => [key, [...fields]])
|
|
274
|
+
);
|
|
275
|
+
}
|
|
197
276
|
var GasAccountService = class {
|
|
198
277
|
/**
|
|
199
278
|
* Creates the gas-account service using a service-scoped HTTP adapter.
|
|
@@ -207,21 +286,440 @@ var GasAccountService = class {
|
|
|
207
286
|
/**
|
|
208
287
|
* Returns the deposit vault address mapping keyed by chain ID.
|
|
209
288
|
* Requires a JWT token from a successful SNS login.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* await client.sns.login({
|
|
293
|
+
* walletAddress,
|
|
294
|
+
* signMessage,
|
|
295
|
+
* });
|
|
296
|
+
*
|
|
297
|
+
* const vaults = await client.gasAccount.getDepositVaults();
|
|
298
|
+
* ```
|
|
210
299
|
*/
|
|
211
300
|
async getDepositVaults() {
|
|
212
301
|
return this.http.get("deposit_vaults", { auth: true });
|
|
213
302
|
}
|
|
214
303
|
/**
|
|
215
|
-
* Returns the authenticated gas
|
|
216
|
-
*
|
|
304
|
+
* Returns the authenticated user's gas account summary, including balances,
|
|
305
|
+
* recent transactions, and pending transactions.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```ts
|
|
309
|
+
* const summary = await client.gasAccount.getSummary();
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
async getSummary() {
|
|
313
|
+
return this.http.get("summary", { auth: true });
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Returns supported stable tokens, optionally filtered by chain ID.
|
|
317
|
+
*
|
|
318
|
+
* @param chainId Optional network chain ID used to filter supported tokens.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```ts
|
|
322
|
+
* const tokens = await client.gasAccount.getStableTokens();
|
|
323
|
+
* const bscTestnetTokens = await client.gasAccount.getStableTokens(97);
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
async getStableTokens(chainId) {
|
|
327
|
+
const searchParams = new URLSearchParams();
|
|
328
|
+
if (chainId !== void 0) {
|
|
329
|
+
searchParams.set("chainId", String(chainId));
|
|
330
|
+
}
|
|
331
|
+
const path = searchParams.size > 0 ? `stable_tokens?${searchParams.toString()}` : "stable_tokens";
|
|
332
|
+
return this.http.get(path, { auth: true });
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Returns the authenticated user's current whitelist spender entries and nonce.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```ts
|
|
339
|
+
* const whitelist = await client.gasAccount.getWhitelistSpenders();
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
async getWhitelistSpenders() {
|
|
343
|
+
return this.http.get("whitelist-spenders", { auth: true });
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Adds or updates whitelist spender entries using a signed EIP-712 payload.
|
|
347
|
+
*
|
|
348
|
+
* @param params Spenders, signature, nonce, and deadline for registration.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* const { data } = await client.gasAccount.getWhitelistSpenders();
|
|
353
|
+
* const typedData = client.gasAccount.buildRegisterWhitelistSpendersTypedData({
|
|
354
|
+
* owner: wallet.address,
|
|
355
|
+
* spenders,
|
|
356
|
+
* nonce: data.nonce,
|
|
357
|
+
* deadline: Math.floor(Date.now() / 1000) + 600,
|
|
358
|
+
* });
|
|
359
|
+
*
|
|
360
|
+
* const signature = await wallet.signTypedData(
|
|
361
|
+
* typedData.domain,
|
|
362
|
+
* typedData.types,
|
|
363
|
+
* typedData.message,
|
|
364
|
+
* );
|
|
365
|
+
*
|
|
366
|
+
* await client.gasAccount.registerWhitelistSpenders({
|
|
367
|
+
* spenders,
|
|
368
|
+
* nonce: data.nonce,
|
|
369
|
+
* deadline: typedData.message.deadline,
|
|
370
|
+
* signature,
|
|
371
|
+
* });
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
async registerWhitelistSpenders(params) {
|
|
375
|
+
return this.http.post("whitelist-spenders", params, {
|
|
376
|
+
auth: true
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Convenience helper that fetches the current whitelist nonce, builds the
|
|
381
|
+
* typed-data payload, asks the caller to sign it, and submits the request.
|
|
382
|
+
*
|
|
383
|
+
* @param params Owner address, spender entries, optional deadline, and a typed-data signer.
|
|
384
|
+
*
|
|
385
|
+
* @example
|
|
386
|
+
* ```ts
|
|
387
|
+
* await client.gasAccount.registerWhitelistSpendersWithSignature({
|
|
388
|
+
* owner: wallet.address,
|
|
389
|
+
* spenders,
|
|
390
|
+
* signTypedData: (typedData) =>
|
|
391
|
+
* wallet.signTypedData(
|
|
392
|
+
* typedData.domain,
|
|
393
|
+
* typedData.types,
|
|
394
|
+
* typedData.message,
|
|
395
|
+
* ),
|
|
396
|
+
* });
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
async registerWhitelistSpendersWithSignature(params) {
|
|
400
|
+
const { data } = await this.getWhitelistSpenders();
|
|
401
|
+
const nonce = data.nonce;
|
|
402
|
+
const deadline = params.deadline ?? Math.floor(Date.now() / 1e3) + 600;
|
|
403
|
+
const typedData = this.buildRegisterWhitelistSpendersTypedData({
|
|
404
|
+
owner: params.owner,
|
|
405
|
+
spenders: params.spenders,
|
|
406
|
+
version: params.version,
|
|
407
|
+
nonce,
|
|
408
|
+
deadline
|
|
409
|
+
});
|
|
410
|
+
const signature = await params.signTypedData(typedData);
|
|
411
|
+
return this.registerWhitelistSpenders({
|
|
412
|
+
spenders: params.spenders,
|
|
413
|
+
signature,
|
|
414
|
+
nonce,
|
|
415
|
+
deadline
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Convenience helper for ethers-compatible signers.
|
|
420
|
+
*
|
|
421
|
+
* @param params Owner address, spender entries, optional domain version/deadline, and an ethers-compatible signer.
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```ts
|
|
425
|
+
* await client.gasAccount.registerWhitelistSpendersWithEthers({
|
|
426
|
+
* owner: wallet.address,
|
|
427
|
+
* spenders,
|
|
428
|
+
* signer: wallet,
|
|
429
|
+
* });
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
async registerWhitelistSpendersWithEthers(params) {
|
|
433
|
+
return this.registerWhitelistSpendersWithSignature({
|
|
434
|
+
owner: params.owner,
|
|
435
|
+
spenders: params.spenders,
|
|
436
|
+
version: params.version,
|
|
437
|
+
deadline: params.deadline,
|
|
438
|
+
signTypedData: (typedData) => params.signer.signTypedData(
|
|
439
|
+
typedData.domain,
|
|
440
|
+
toMutableTypedDataTypes(typedData.types),
|
|
441
|
+
typedData.message
|
|
442
|
+
)
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Builds the EIP-712 typed-data payload required by whitelist registration.
|
|
447
|
+
*
|
|
448
|
+
* @param params Owner, spenders, nonce, and deadline used in the signature payload.
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```ts
|
|
452
|
+
* const typedData = client.gasAccount.buildRegisterWhitelistSpendersTypedData({
|
|
453
|
+
* owner: wallet.address,
|
|
454
|
+
* spenders,
|
|
455
|
+
* nonce: 0,
|
|
456
|
+
* deadline: Math.floor(Date.now() / 1000) + 600,
|
|
457
|
+
* });
|
|
458
|
+
* ```
|
|
459
|
+
*/
|
|
460
|
+
buildRegisterWhitelistSpendersTypedData(params) {
|
|
461
|
+
return {
|
|
462
|
+
...REGISTER_WHITELIST_SPENDERS_TYPED_DATA,
|
|
463
|
+
domain: {
|
|
464
|
+
...REGISTER_WHITELIST_SPENDERS_TYPED_DATA.domain,
|
|
465
|
+
version: params.version ?? DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION
|
|
466
|
+
},
|
|
467
|
+
message: {
|
|
468
|
+
owner: params.owner,
|
|
469
|
+
spenders: params.spenders,
|
|
470
|
+
nonce: params.nonce,
|
|
471
|
+
deadline: params.deadline
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Removes one or more whitelist spender addresses from the authenticated account.
|
|
477
|
+
*
|
|
478
|
+
* @param params Spender addresses to revoke.
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```ts
|
|
482
|
+
* await client.gasAccount.removeWhitelistSpenders({
|
|
483
|
+
* spenders: ['0x9876543210987654321098765432109876543210'],
|
|
484
|
+
* });
|
|
485
|
+
* ```
|
|
486
|
+
*/
|
|
487
|
+
async removeWhitelistSpenders(params) {
|
|
488
|
+
return this.http.delete("whitelist-spenders", params, {
|
|
489
|
+
auth: true
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Returns the authenticated user's balance summary.
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* ```ts
|
|
497
|
+
* const balance = await client.gasAccount.getBalance();
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
async getBalance() {
|
|
501
|
+
return this.http.get("gas-account-balance", { auth: true });
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Returns the authenticated user's balance summary with pending transaction lists.
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```ts
|
|
508
|
+
* const detailedBalance = await client.gasAccount.getDetailedBalance();
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
async getDetailedBalance() {
|
|
512
|
+
return this.http.get("gas-account-balance/detailed", {
|
|
513
|
+
auth: true
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Returns balance statistics for the authenticated user's gas account.
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```ts
|
|
521
|
+
* const stats = await client.gasAccount.getBalanceStats();
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
async getBalanceStats() {
|
|
525
|
+
return this.http.get("gas-account-balance/stats", {
|
|
526
|
+
auth: true
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Returns balances for a batch of addresses through the public balances endpoint.
|
|
531
|
+
*
|
|
532
|
+
* @param params Address batch to query.
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* ```ts
|
|
536
|
+
* const balances = await client.gasAccount.getBalances({
|
|
537
|
+
* addresses: [
|
|
538
|
+
* '0x3a0430580303f4De9C5320aC013f14cd92192bfA',
|
|
539
|
+
* '0x610b463d2f57d2e0d9e785a7ff423fbae36f0624',
|
|
540
|
+
* ],
|
|
541
|
+
* });
|
|
542
|
+
* ```
|
|
543
|
+
*/
|
|
544
|
+
async getBalances(params) {
|
|
545
|
+
return this.http.put("gas-account-balance/balances", params);
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Returns a paginated transaction list for the authenticated user's gas account.
|
|
549
|
+
*
|
|
550
|
+
* @param params Optional pagination and filter parameters.
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* ```ts
|
|
554
|
+
* const transactions = await client.gasAccount.listTransactions({
|
|
555
|
+
* page: 1,
|
|
556
|
+
* per: 10,
|
|
557
|
+
* type: 'DEPOSIT',
|
|
558
|
+
* status: 'CONFIRMED',
|
|
559
|
+
* });
|
|
560
|
+
* ```
|
|
561
|
+
*/
|
|
562
|
+
async listTransactions(params = {}) {
|
|
563
|
+
const searchParams = new URLSearchParams();
|
|
564
|
+
if (params.page !== void 0) {
|
|
565
|
+
searchParams.set("page", String(params.page));
|
|
566
|
+
}
|
|
567
|
+
if (params.per !== void 0) {
|
|
568
|
+
searchParams.set("per", String(params.per));
|
|
569
|
+
}
|
|
570
|
+
if (params.type) {
|
|
571
|
+
searchParams.set("type", params.type);
|
|
572
|
+
}
|
|
573
|
+
if (params.status) {
|
|
574
|
+
searchParams.set("status", params.status);
|
|
575
|
+
}
|
|
576
|
+
const path = searchParams.size > 0 ? `gas-account-transaction?${searchParams.toString()}` : "gas-account-transaction";
|
|
577
|
+
return this.http.get(path, { auth: true });
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Returns detailed data for a specific transaction ID.
|
|
581
|
+
*
|
|
582
|
+
* @param transactionId Transaction UUID.
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* ```ts
|
|
586
|
+
* const transaction = await client.gasAccount.getTransactionById(transactionId);
|
|
587
|
+
* ```
|
|
217
588
|
*/
|
|
218
|
-
async
|
|
219
|
-
return this.http.get(
|
|
589
|
+
async getTransactionById(transactionId) {
|
|
590
|
+
return this.http.get(
|
|
591
|
+
`gas-account-transaction/${transactionId}`,
|
|
592
|
+
{ auth: true }
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Creates a pending deposit transaction for the authenticated user.
|
|
597
|
+
*
|
|
598
|
+
* @param params Deposit payload.
|
|
599
|
+
*
|
|
600
|
+
* @example
|
|
601
|
+
* ```ts
|
|
602
|
+
* await client.gasAccount.createDeposit({
|
|
603
|
+
* chainId: 97,
|
|
604
|
+
* amount: '100.00000000',
|
|
605
|
+
* tokenAddress: '0x5bF5121A17e3329D07Ba43f758dEC271D9105132',
|
|
606
|
+
* txHash: '0xe3844e7bc420b2d409058e6bf5534fdba69b917907d691abf65862654df749d7',
|
|
607
|
+
* actor: walletAddress,
|
|
608
|
+
* notes: 'Deposit from wallet',
|
|
609
|
+
* });
|
|
610
|
+
* ```
|
|
611
|
+
*/
|
|
612
|
+
async createDeposit(params) {
|
|
613
|
+
return this.http.post("gas-account-transaction/deposit", params, {
|
|
614
|
+
auth: true
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Creates a gas-usage request against the caller's balance or a whitelisted source address.
|
|
619
|
+
*
|
|
620
|
+
* @param params Usage request payload.
|
|
621
|
+
*
|
|
622
|
+
* @example
|
|
623
|
+
* ```ts
|
|
624
|
+
* await client.gasAccount.useBalance({
|
|
625
|
+
* toAddress: '0x9876543210987654321098765432109876543210',
|
|
626
|
+
* chainId: 97,
|
|
627
|
+
* gasLimit: 21000,
|
|
628
|
+
* gasPrice: 5,
|
|
629
|
+
* notes: 'Gas for token transfer',
|
|
630
|
+
* });
|
|
631
|
+
* ```
|
|
632
|
+
*/
|
|
633
|
+
async useBalance(params) {
|
|
634
|
+
return this.http.post("gas-account-transaction/use-balance", params, {
|
|
635
|
+
auth: true
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Creates a sponsored transfer request.
|
|
640
|
+
*
|
|
641
|
+
* @param params Sponsored transfer payload.
|
|
642
|
+
*
|
|
643
|
+
* @example
|
|
644
|
+
* ```ts
|
|
645
|
+
* await client.gasAccount.createSponsoredTransfer({
|
|
646
|
+
* transactions: [
|
|
647
|
+
* {
|
|
648
|
+
* tokenAddress: '0x409E7b65eF7B243529e3F97be2A122123c55DE63',
|
|
649
|
+
* from: '0x1234567890123456789012345678901234567890',
|
|
650
|
+
* to: '0x9876543210987654321098765432109876543210',
|
|
651
|
+
* value: '1000000000000000000',
|
|
652
|
+
* validBefore: 1735689600,
|
|
653
|
+
* validAfter: 0,
|
|
654
|
+
* nonce: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
655
|
+
* signature: '0x...',
|
|
656
|
+
* },
|
|
657
|
+
* ],
|
|
658
|
+
* chainId: 97,
|
|
659
|
+
* type: 'ADMIN',
|
|
660
|
+
* notes: 'JPYC transfer sponsorship',
|
|
661
|
+
* });
|
|
662
|
+
* ```
|
|
663
|
+
*/
|
|
664
|
+
async createSponsoredTransfer(params) {
|
|
665
|
+
return this.http.post(
|
|
666
|
+
"gas-account-transaction/sponsored-transfers",
|
|
667
|
+
params,
|
|
668
|
+
{ auth: true }
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Cancels a pending gas-account transaction that has not yet been broadcast.
|
|
673
|
+
*
|
|
674
|
+
* @param transactionId Transaction UUID.
|
|
675
|
+
*
|
|
676
|
+
* @example
|
|
677
|
+
* ```ts
|
|
678
|
+
* await client.gasAccount.cancelTransaction(transactionId);
|
|
679
|
+
* ```
|
|
680
|
+
*/
|
|
681
|
+
async cancelTransaction(transactionId) {
|
|
682
|
+
return this.http.put(
|
|
683
|
+
`gas-account-transaction/${transactionId}/cancel`,
|
|
684
|
+
void 0,
|
|
685
|
+
{ auth: true }
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Creates an internal funding request on behalf of another service.
|
|
690
|
+
*
|
|
691
|
+
* @param params Funding request payload.
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
* ```ts
|
|
695
|
+
* await client.gasAccount.createFundingRequest({
|
|
696
|
+
* sourceAddress: '0x610b463d2f57d2e0d9e785a7ff423fbae36f0624',
|
|
697
|
+
* toAddress: '0x9876543210987654321098765432109876543210',
|
|
698
|
+
* chainId: 97,
|
|
699
|
+
* gasLimit: 21000,
|
|
700
|
+
* gasPrice: 5,
|
|
701
|
+
* notes: 'Gas for token transfer',
|
|
702
|
+
* });
|
|
703
|
+
* ```
|
|
704
|
+
*/
|
|
705
|
+
async createFundingRequest(params) {
|
|
706
|
+
return this.http.post(
|
|
707
|
+
"internal/gas-account-transaction/funding-requests",
|
|
708
|
+
params
|
|
709
|
+
);
|
|
220
710
|
}
|
|
221
711
|
};
|
|
222
712
|
|
|
223
713
|
// packages/sdk/src/services/sns.ts
|
|
224
714
|
var DEFAULT_BASE_SIGNED_MESSAGE = "Hi there from Avacus Wallet! Please sign this message to prove that you can access to secure chat. To stop hackers access to your secure chat, do not sign this message outside Avacus Wallet, and here's a unique message ID they can't guess: ";
|
|
715
|
+
var BASE_CONNECT_SIGNED_MSG = "Hi there from Avacus Connect! Please sign this message to prove that you can access our service. For security reasons, do not sign this message outside Avacus Connect, and here's a unique message ID they can't guess: ";
|
|
716
|
+
var BASE_REDIRECT_SIGNED_MSG = "Hi there from Avacus Redirect! Please sign this message to prove that you can access our service. For security reasons, do not sign this message outside Avacus Redirect, and here's a unique message ID they can't guess: ";
|
|
717
|
+
var BASE_GAS_SPONSOR_SIGNED_MSG = "Hi there from Avacus Gas Sponsor! Please sign this message to prove that you can access our service. For security reasons, do not sign this message outside Avacus Gas Sponsor, and here's a unique message ID they can't guess: ";
|
|
718
|
+
var BASE_SIGNED_MESSAGE_BY_SERVICE = {
|
|
719
|
+
connect: BASE_CONNECT_SIGNED_MSG,
|
|
720
|
+
redirect: BASE_REDIRECT_SIGNED_MSG,
|
|
721
|
+
"gas-sponsor": BASE_GAS_SPONSOR_SIGNED_MSG
|
|
722
|
+
};
|
|
225
723
|
var SNS_SERVICE_PATH = "1/secure-chat/";
|
|
226
724
|
var SnsService = class {
|
|
227
725
|
/**
|
|
@@ -255,7 +753,7 @@ var SnsService = class {
|
|
|
255
753
|
* @param params Payload expected by the SNS auth API.
|
|
256
754
|
*/
|
|
257
755
|
async requestAuthToken(params) {
|
|
258
|
-
return this.http.post("
|
|
756
|
+
return this.http.post("v2/public/users/request_auth_token", params);
|
|
259
757
|
}
|
|
260
758
|
/**
|
|
261
759
|
* Returns public user profiles for a batch of wallet addresses and/or user IDs.
|
|
@@ -332,7 +830,8 @@ var SnsService = class {
|
|
|
332
830
|
return this.requestAuthToken({
|
|
333
831
|
wallet_address: params.walletAddress,
|
|
334
832
|
message: params.message,
|
|
335
|
-
signature: params.signature
|
|
833
|
+
signature: params.signature,
|
|
834
|
+
service_name: params.serviceName
|
|
336
835
|
});
|
|
337
836
|
}
|
|
338
837
|
/**
|
|
@@ -346,14 +845,15 @@ var SnsService = class {
|
|
|
346
845
|
* @param params Wallet address and async signing callback.
|
|
347
846
|
*/
|
|
348
847
|
async login(params) {
|
|
349
|
-
const { walletAddress, signMessage } = params;
|
|
848
|
+
const { walletAddress, signMessage, serviceName } = params;
|
|
350
849
|
const { nonce } = await this.getNonce({ walletAddress });
|
|
351
|
-
const message = this.buildLoginMessage(nonce);
|
|
850
|
+
const message = this.buildLoginMessage(nonce, serviceName);
|
|
352
851
|
const signature = await signMessage(message);
|
|
353
852
|
const result = await this.authenticate({
|
|
354
853
|
walletAddress,
|
|
355
854
|
message,
|
|
356
|
-
signature
|
|
855
|
+
signature,
|
|
856
|
+
serviceName
|
|
357
857
|
});
|
|
358
858
|
const accessToken = extractAccessToken(result);
|
|
359
859
|
if (accessToken) {
|
|
@@ -364,16 +864,16 @@ var SnsService = class {
|
|
|
364
864
|
/**
|
|
365
865
|
* Builds the exact message string that the wallet must sign during login.
|
|
366
866
|
*/
|
|
367
|
-
buildLoginMessage(nonce) {
|
|
368
|
-
|
|
867
|
+
buildLoginMessage(nonce, serviceName) {
|
|
868
|
+
const baseMessage = serviceName != null ? BASE_SIGNED_MESSAGE_BY_SERVICE[serviceName] : this.options.baseSignedMessage ?? DEFAULT_BASE_SIGNED_MESSAGE;
|
|
869
|
+
return `${baseMessage}${nonce}`;
|
|
369
870
|
}
|
|
370
871
|
};
|
|
371
872
|
function extractAccessToken(result) {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
return value;
|
|
873
|
+
if ("data" in result && typeof result.data === "object" && result.data !== null) {
|
|
874
|
+
const token = result.data.token;
|
|
875
|
+
if (typeof token === "string" && token.length > 0) {
|
|
876
|
+
return token;
|
|
377
877
|
}
|
|
378
878
|
}
|
|
379
879
|
return void 0;
|
|
@@ -444,8 +944,12 @@ var SnsAuthClient = class extends SnsService {
|
|
|
444
944
|
0 && (module.exports = {
|
|
445
945
|
AVACUS_ENDPOINTS,
|
|
446
946
|
AvacusClient,
|
|
947
|
+
BASE_CONNECT_SIGNED_MSG,
|
|
948
|
+
BASE_GAS_SPONSOR_SIGNED_MSG,
|
|
949
|
+
BASE_REDIRECT_SIGNED_MSG,
|
|
447
950
|
BalancerService,
|
|
448
951
|
DEFAULT_BASE_SIGNED_MESSAGE,
|
|
952
|
+
DEFAULT_REGISTER_WHITELIST_SPENDERS_VERSION,
|
|
449
953
|
GAS_ACCOUNT_SERVICE_PATH,
|
|
450
954
|
GasAccountService,
|
|
451
955
|
HttpAdapter,
|