@sign-global/tokentable 1.4.1 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -27,10 +27,10 @@ __export(index_exports, {
27
27
  module.exports = __toCommonJS(index_exports);
28
28
 
29
29
  // src/AirdropClient.ts
30
- var import_tokentable_core5 = require("@sign-global/tokentable-core");
30
+ var import_tokentable_core6 = require("@sign-global/tokentable-core");
31
31
 
32
32
  // src/strategies/AirdropStrategyFactory.ts
33
- var import_tokentable_core4 = require("@sign-global/tokentable-core");
33
+ var import_tokentable_core5 = require("@sign-global/tokentable-core");
34
34
 
35
35
  // src/strategies/EvmAirdropStrategy.ts
36
36
  var import_tokentable_core = require("@sign-global/tokentable-core");
@@ -225,12 +225,75 @@ var TonAirdropStrategy = class {
225
225
  }
226
226
  };
227
227
 
228
+ // src/strategies/AptosAirdropStrategy.ts
229
+ var import_tokentable_core4 = require("@sign-global/tokentable-core");
230
+ var AptosAirdropStrategy = class {
231
+ service;
232
+ chainId;
233
+ chainRpc;
234
+ walletClient;
235
+ cachedVersion = null;
236
+ contractAddress;
237
+ constructor(params) {
238
+ this.chainId = params.chainId;
239
+ this.chainRpc = params.chainRpc;
240
+ this.contractAddress = params.contractAddress;
241
+ if (params.walletClient) {
242
+ this.walletClient = params.walletClient;
243
+ }
244
+ }
245
+ async initialize(walletClient) {
246
+ if (walletClient) {
247
+ this.walletClient = walletClient;
248
+ }
249
+ this.service = new import_tokentable_core4.AptosAirdropService({
250
+ chainId: this.chainId,
251
+ account: this.walletClient,
252
+ chainRpc: this.chainRpc,
253
+ address: this.contractAddress
254
+ });
255
+ }
256
+ isInitialized() {
257
+ return !!this.service;
258
+ }
259
+ async getVersion() {
260
+ if (this.cachedVersion) {
261
+ return this.cachedVersion;
262
+ }
263
+ if (!this.service) throw new Error("Strategy not initialized");
264
+ this.cachedVersion = await this.service.getVersion();
265
+ return this.cachedVersion;
266
+ }
267
+ async claim(claimData) {
268
+ if (!this.service) throw new Error("Strategy not initialized");
269
+ return this.service.claim(claimData);
270
+ }
271
+ async checkClaimed(claimData) {
272
+ if (!this.service) throw new Error("Strategy not initialized");
273
+ return this.service.isLeafUsed(claimData.leaf);
274
+ }
275
+ async batchCheckClaimed(leafs) {
276
+ if (!this.service) throw new Error("Strategy not initialized");
277
+ return this.service.batchFetchClaimed(leafs);
278
+ }
279
+ async getClaimFee(contractAddress, amount) {
280
+ if (!this.service) throw new Error("Strategy not initialized");
281
+ return this.service.getClaimFee(contractAddress, amount);
282
+ }
283
+ async getPaused() {
284
+ if (!this.service) throw new Error("Strategy not initialized");
285
+ return this.service.getPaused();
286
+ }
287
+ };
288
+
228
289
  // src/strategies/AirdropStrategyFactory.ts
229
290
  var AirdropStrategyFactory = class {
230
291
  static strategyMap = {
231
- [import_tokentable_core4.ChainType.Evm]: EvmAirdropStrategy,
232
- [import_tokentable_core4.ChainType.Ton]: TonAirdropStrategy,
233
- [import_tokentable_core4.ChainType.Solana]: SolanaAirdropStrategy
292
+ [import_tokentable_core5.ChainType.Evm]: EvmAirdropStrategy,
293
+ [import_tokentable_core5.ChainType.Ton]: TonAirdropStrategy,
294
+ [import_tokentable_core5.ChainType.Solana]: SolanaAirdropStrategy,
295
+ [import_tokentable_core5.ChainType.Aptos]: AptosAirdropStrategy,
296
+ [import_tokentable_core5.ChainType.Sui]: null
234
297
  };
235
298
  static createStrategy(params) {
236
299
  const { chainType, ...strategyParams } = params;
@@ -307,20 +370,20 @@ var AirdropClient = class {
307
370
  }
308
371
  async fetchProjectFromSlug(address) {
309
372
  if (!this.slug) return void 0;
310
- const res = await (0, import_tokentable_core5.getAirdropPro)(this.slug, this.endpoint);
373
+ const res = await (0, import_tokentable_core6.getAirdropPro)(this.slug, this.endpoint);
311
374
  const projectMap = res?.childProjectMapping || {};
312
- return (0, import_tokentable_core5.getTonProjectIdByAddress)({
375
+ return (0, import_tokentable_core6.getTonProjectIdByAddress)({
313
376
  address,
314
377
  slug: this.slug,
315
378
  data: projectMap
316
379
  });
317
380
  }
318
381
  async fetchProjectDetails(projectId) {
319
- const project = await (0, import_tokentable_core5.getAirdropProject)(projectId, this.endpoint);
382
+ const project = await (0, import_tokentable_core6.getAirdropProject)(projectId, this.endpoint);
320
383
  this.project = project;
321
384
  if (this.chainRpc) return;
322
- const chainId = project.chainType === import_tokentable_core5.ChainType.Evm ? Number(project.chainId) : project.chainId;
323
- this.chainRpc = (0, import_tokentable_core5.getChainRpc)(chainId);
385
+ const chainId = project.chainType === import_tokentable_core6.ChainType.Evm ? Number(project.chainId) : project.chainId;
386
+ this.chainRpc = (0, import_tokentable_core6.getChainRpc)(chainId);
324
387
  }
325
388
  async initializeProjects(address) {
326
389
  try {
@@ -348,7 +411,7 @@ var AirdropClient = class {
348
411
  await this.initializeProjects(data.address);
349
412
  }
350
413
  const project = await this.getProjectInfo();
351
- const res = await (0, import_tokentable_core5.getAirdropQuery)(
414
+ const res = await (0, import_tokentable_core6.getAirdropQuery)(
352
415
  {
353
416
  recipient: data.address,
354
417
  projectId: project.id,
@@ -359,7 +422,7 @@ var AirdropClient = class {
359
422
  const claimsRes = res.claims?.map((it) => ({
360
423
  ...it,
361
424
  project,
362
- claimId: project.chainType === import_tokentable_core5.ChainType.Evm ? `${project.id}:${it.leaf}` : `${project.id}:${it.index}`
425
+ claimId: project.chainType === import_tokentable_core6.ChainType.Evm ? `${project.id}:${it.leaf}` : `${project.id}:${it.index}`
363
426
  }));
364
427
  this.claims = claimsRes;
365
428
  return this.claims;
@@ -403,9 +466,9 @@ var AirdropClient = class {
403
466
  }
404
467
  async calculateClaimFee(project, claimData) {
405
468
  const claimAmount = claimData.amount;
406
- if (project.chainType === import_tokentable_core5.ChainType.Evm) {
469
+ if (project.chainType === import_tokentable_core6.ChainType.Evm) {
407
470
  const version = await this.getVersion();
408
- const isNativeFreeVersion = project.tokenType === import_tokentable_core5.ETokenType.Native && [import_tokentable_core5.EvmAirdropVersionEnum.V3, import_tokentable_core5.EvmAirdropVersionEnum.V4].includes(version);
471
+ const isNativeFreeVersion = project.tokenType === import_tokentable_core6.ETokenType.Native && [import_tokentable_core6.EvmAirdropVersionEnum.V3, import_tokentable_core6.EvmAirdropVersionEnum.V4].includes(version);
409
472
  if (isNativeFreeVersion) {
410
473
  return void 0;
411
474
  }
@@ -415,16 +478,20 @@ var AirdropClient = class {
415
478
  }
416
479
  return await this.getClaimFee(BigInt(claimAmount));
417
480
  }
418
- if (project.chainType === import_tokentable_core5.ChainType.Ton) {
481
+ if (project.chainType === import_tokentable_core6.ChainType.Ton) {
419
482
  return await this.getClaimFee(BigInt(claimAmount));
420
483
  }
484
+ if (project.chainType === import_tokentable_core6.ChainType.Aptos) {
485
+ const fees = claimData.fees;
486
+ return fees ? BigInt(fees) : 0n;
487
+ }
421
488
  return void 0;
422
489
  }
423
490
  async claimAirdrop({ claimId, walletClient }, options) {
424
491
  const claimData = this.getClaimDataById(claimId);
425
492
  const strategy = await this.getStrategy(walletClient);
426
493
  const project = await this.getProjectInfo();
427
- const extraData = project.chainType === import_tokentable_core5.ChainType.Ton ? void 0 : this.claimHook ? this.claimHook(claimData) : this.getDefaultExtraData();
494
+ const extraData = project.chainType === import_tokentable_core6.ChainType.Ton ? void 0 : this.claimHook ? this.claimHook(claimData) : this.getDefaultExtraData();
428
495
  const value = await this.calculateClaimFee(project, claimData);
429
496
  return strategy.claim(
430
497
  {
@@ -443,8 +510,8 @@ var AirdropClient = class {
443
510
  async getContractConfig() {
444
511
  try {
445
512
  const project = await this.getProjectInfo();
446
- if (!this.contractConfig && [import_tokentable_core5.ChainType.Evm, import_tokentable_core5.ChainType.Ton].includes(project.chainType)) {
447
- this.contractConfig = await (0, import_tokentable_core5.getAirdropContractConfig)(
513
+ if (!this.contractConfig && [import_tokentable_core6.ChainType.Evm, import_tokentable_core6.ChainType.Ton].includes(project.chainType)) {
514
+ this.contractConfig = await (0, import_tokentable_core6.getAirdropContractConfig)(
448
515
  {
449
516
  chainId: project.chainId,
450
517
  chainType: project.chainType,
@@ -517,7 +584,7 @@ var AirdropClient = class {
517
584
 
518
585
  // src/SignatureAirdropClient.ts
519
586
  var import_tokentable_wallets = require("@sign-global/tokentable-wallets");
520
- var import_tokentable_core6 = require("@sign-global/tokentable-core");
587
+ var import_tokentable_core7 = require("@sign-global/tokentable-core");
521
588
  var SignatureAirdropClient = class {
522
589
  projectId;
523
590
  endpoint;
@@ -538,7 +605,7 @@ var SignatureAirdropClient = class {
538
605
  } else {
539
606
  this.projectPromise = this.initializeProjects();
540
607
  }
541
- if ((0, import_tokentable_core6.isMobile)()) {
608
+ if ((0, import_tokentable_core7.isMobile)()) {
542
609
  this.authPromise = this.checkAndHandleOAuthCode();
543
610
  }
544
611
  }
@@ -551,18 +618,18 @@ var SignatureAirdropClient = class {
551
618
  if (code && this.projectId) {
552
619
  let res;
553
620
  if (type === "twitter") {
554
- res = await (0, import_tokentable_core6.connectTwitter)({ code, projectId: this.projectId }, this.endpoint);
621
+ res = await (0, import_tokentable_core7.connectTwitter)({ code, projectId: this.projectId }, this.endpoint);
555
622
  } else if (type === "google") {
556
- res = await (0, import_tokentable_core6.connectGoogleApi)({ code, projectId: this.projectId }, this.endpoint);
623
+ res = await (0, import_tokentable_core7.connectGoogleApi)({ code, projectId: this.projectId }, this.endpoint);
557
624
  } else if (type === "discord") {
558
- res = await (0, import_tokentable_core6.connectDiscordApi)({ code, projectId: this.projectId }, this.endpoint);
625
+ res = await (0, import_tokentable_core7.connectDiscordApi)({ code, projectId: this.projectId }, this.endpoint);
559
626
  }
560
627
  if (res?.sid) {
561
628
  this.setSid(this.projectId, res.sid);
562
629
  } else {
563
630
  throw new Error("Failed to connect");
564
631
  }
565
- (0, import_tokentable_core6.cleanUrlParams)(["code", "type"]);
632
+ (0, import_tokentable_core7.cleanUrlParams)(["code", "type"]);
566
633
  }
567
634
  } catch (error) {
568
635
  console.error(error);
@@ -572,11 +639,11 @@ var SignatureAirdropClient = class {
572
639
  window.localStorage.setItem(`${this.LOCAL_STORAGE_SID_PREFIX}${projectId}`, sid);
573
640
  }
574
641
  async fetchProjectDetails(projectId) {
575
- const project = await (0, import_tokentable_core6.getAirdropProject)(projectId, this.endpoint);
642
+ const project = await (0, import_tokentable_core7.getAirdropProject)(projectId, this.endpoint);
576
643
  this.project = project;
577
644
  if (this.chainRpc) return;
578
- const chainId = project.chainType === import_tokentable_core6.ChainType.Evm ? Number(project.chainId) : project.chainId;
579
- this.chainRpc = (0, import_tokentable_core6.getChainRpc)(chainId);
645
+ const chainId = project.chainType === import_tokentable_core7.ChainType.Evm ? Number(project.chainId) : project.chainId;
646
+ this.chainRpc = (0, import_tokentable_core7.getChainRpc)(chainId);
580
647
  }
581
648
  async initializeProjects() {
582
649
  try {
@@ -607,23 +674,23 @@ var SignatureAirdropClient = class {
607
674
  onError(new Error("Authorize URL not found"));
608
675
  return;
609
676
  }
610
- if ((0, import_tokentable_core6.isMobile)()) {
677
+ if ((0, import_tokentable_core7.isMobile)()) {
611
678
  const state = encodeURIComponent(window.location.href);
612
679
  window.location.href = `${authorizeUrl}&state=${state}`;
613
680
  return;
614
681
  }
615
682
  const onWindowMessage = async (message) => {
616
683
  const name = message.data?.name;
617
- if (name && [import_tokentable_core6.CONST.TWITTER_AUTH_SUCCESS, import_tokentable_core6.CONST.GOOGLE_AUTH_SUCCESS, import_tokentable_core6.CONST.DISCORD_AUTH_SUCCESS].includes(name)) {
684
+ if (name && [import_tokentable_core7.CONST.TWITTER_AUTH_SUCCESS, import_tokentable_core7.CONST.GOOGLE_AUTH_SUCCESS, import_tokentable_core7.CONST.DISCORD_AUTH_SUCCESS].includes(name)) {
618
685
  const { code } = message.data.data || {};
619
686
  try {
620
687
  let res;
621
- if (name === import_tokentable_core6.CONST.GOOGLE_AUTH_SUCCESS) {
622
- res = await (0, import_tokentable_core6.connectGoogleApi)({ code, projectId: project.id }, this.endpoint);
623
- } else if (name === import_tokentable_core6.CONST.TWITTER_AUTH_SUCCESS) {
624
- res = await (0, import_tokentable_core6.connectTwitter)({ code, projectId: project.id }, this.endpoint);
625
- } else if (name === import_tokentable_core6.CONST.DISCORD_AUTH_SUCCESS) {
626
- res = await (0, import_tokentable_core6.connectDiscordApi)({ code, projectId: project.id }, this.endpoint);
688
+ if (name === import_tokentable_core7.CONST.GOOGLE_AUTH_SUCCESS) {
689
+ res = await (0, import_tokentable_core7.connectGoogleApi)({ code, projectId: project.id }, this.endpoint);
690
+ } else if (name === import_tokentable_core7.CONST.TWITTER_AUTH_SUCCESS) {
691
+ res = await (0, import_tokentable_core7.connectTwitter)({ code, projectId: project.id }, this.endpoint);
692
+ } else if (name === import_tokentable_core7.CONST.DISCORD_AUTH_SUCCESS) {
693
+ res = await (0, import_tokentable_core7.connectDiscordApi)({ code, projectId: project.id }, this.endpoint);
627
694
  }
628
695
  if (res?.sid) {
629
696
  this.setSid(project.id, res?.sid);
@@ -645,21 +712,21 @@ var SignatureAirdropClient = class {
645
712
  await this.connectOAuth({
646
713
  onSuccess,
647
714
  onError,
648
- type: import_tokentable_core6.AirdropSigIdentityTypeEnum.Twitter
715
+ type: import_tokentable_core7.AirdropSigIdentityTypeEnum.Twitter
649
716
  });
650
717
  }
651
718
  async connectGoogle({ onSuccess, onError }) {
652
719
  await this.connectOAuth({
653
720
  onSuccess,
654
721
  onError,
655
- type: import_tokentable_core6.AirdropSigIdentityTypeEnum.Google
722
+ type: import_tokentable_core7.AirdropSigIdentityTypeEnum.Google
656
723
  });
657
724
  }
658
725
  async connectDiscord({ onSuccess, onError }) {
659
726
  await this.connectOAuth({
660
727
  onSuccess,
661
728
  onError,
662
- type: import_tokentable_core6.AirdropSigIdentityTypeEnum.Discord
729
+ type: import_tokentable_core7.AirdropSigIdentityTypeEnum.Discord
663
730
  });
664
731
  }
665
732
  async connectWallet({
@@ -672,17 +739,19 @@ var SignatureAirdropClient = class {
672
739
  const wallet = import_tokentable_wallets.WalletFactory.getWallet(chainType);
673
740
  const timestamp = Date.now();
674
741
  const recipientTypeMap = {
675
- [import_tokentable_core6.ChainType.Evm]: import_tokentable_core6.AirdropSigIdentityTypeEnum.EVMWallet,
676
- [import_tokentable_core6.ChainType.Solana]: import_tokentable_core6.AirdropSigIdentityTypeEnum.SolanaWallet,
677
- [import_tokentable_core6.ChainType.Ton]: import_tokentable_core6.AirdropSigIdentityTypeEnum.TONWallet,
678
- [import_tokentable_core6.ChainType.Sui]: ""
742
+ [import_tokentable_core7.ChainType.Evm]: import_tokentable_core7.AirdropSigIdentityTypeEnum.EVMWallet,
743
+ [import_tokentable_core7.ChainType.Solana]: import_tokentable_core7.AirdropSigIdentityTypeEnum.SolanaWallet,
744
+ [import_tokentable_core7.ChainType.Ton]: import_tokentable_core7.AirdropSigIdentityTypeEnum.TONWallet,
745
+ [import_tokentable_core7.ChainType.Sui]: "",
746
+ [import_tokentable_core7.ChainType.Aptos]: "",
747
+ [import_tokentable_core7.ChainType.Cosmos]: import_tokentable_core7.AirdropSigIdentityTypeEnum.CosmosWallet
679
748
  };
680
749
  const msg = [project.id, recipientTypeMap[chainType], timestamp].join(",");
681
750
  const signResult = await wallet.signin(msg, false);
682
751
  await wallet.disconnect();
683
752
  const { message, signature, signedMessage } = signResult || {};
684
753
  if (this.identities?.find((it) => it.value?.toLowerCase() === wallet.address?.toLowerCase())) {
685
- onError?.(import_tokentable_core6.ErrorCode.WALLET_ALREADY_CONNECTED);
754
+ onError?.(import_tokentable_core7.ErrorCode.WALLET_ALREADY_CONNECTED);
686
755
  return;
687
756
  }
688
757
  const payload = {
@@ -695,7 +764,7 @@ var SignatureAirdropClient = class {
695
764
  recipientType: recipientTypeMap[chainType],
696
765
  encodedMessage: signedMessage
697
766
  };
698
- const res = await (0, import_tokentable_core6.bindWallet)(payload, this.endpoint);
767
+ const res = await (0, import_tokentable_core7.bindWallet)(payload, this.endpoint);
699
768
  if (res?.sid) {
700
769
  this.setSid(project.id, res?.sid);
701
770
  }
@@ -709,7 +778,7 @@ var SignatureAirdropClient = class {
709
778
  if (this.authPromise) {
710
779
  await this.authPromise;
711
780
  }
712
- const res = await (0, import_tokentable_core6.checkEligibility)(
781
+ const res = await (0, import_tokentable_core7.checkEligibility)(
713
782
  {
714
783
  projectId: project.id
715
784
  },
@@ -724,7 +793,7 @@ var SignatureAirdropClient = class {
724
793
  recipient
725
794
  }) {
726
795
  const project = await this.getProjectInfo();
727
- return await (0, import_tokentable_core6.disconnectRecipient)(
796
+ return await (0, import_tokentable_core7.disconnectRecipient)(
728
797
  {
729
798
  projectId: project.id,
730
799
  recipientType,
@@ -740,11 +809,11 @@ var SignatureAirdropClient = class {
740
809
  const project = await this.getProjectInfo();
741
810
  let cacheKey = "default";
742
811
  if (walletClient) {
743
- if (project.chainType === import_tokentable_core6.ChainType.Evm) {
812
+ if (project.chainType === import_tokentable_core7.ChainType.Evm) {
744
813
  cacheKey = walletClient.account?.address;
745
- } else if (project.chainType === import_tokentable_core6.ChainType.Solana) {
814
+ } else if (project.chainType === import_tokentable_core7.ChainType.Solana) {
746
815
  cacheKey = walletClient.publicKey.toString();
747
- } else if (project.chainType === import_tokentable_core6.ChainType.Sui) {
816
+ } else if (project.chainType === import_tokentable_core7.ChainType.Sui) {
748
817
  cacheKey = walletClient.accounts[0].address;
749
818
  }
750
819
  } else {
@@ -754,24 +823,24 @@ var SignatureAirdropClient = class {
754
823
  return this.strategyCache.get(cacheKey);
755
824
  }
756
825
  let strategy = null;
757
- if (project.chainType === import_tokentable_core6.ChainType.Solana) {
758
- strategy = new import_tokentable_core6.SolanaSignatureAirdropService({
826
+ if (project.chainType === import_tokentable_core7.ChainType.Solana) {
827
+ strategy = new import_tokentable_core7.SolanaSignatureAirdropService({
759
828
  chainId: project.chainId,
760
829
  projectId: project.id,
761
830
  token: project.tokenAddress,
762
831
  walletClient,
763
832
  chainRpc: this.chainRpc
764
833
  });
765
- } else if (project.chainType === import_tokentable_core6.ChainType.Sui) {
766
- strategy = new import_tokentable_core6.SuiSignatureAirdropService({
834
+ } else if (project.chainType === import_tokentable_core7.ChainType.Sui) {
835
+ strategy = new import_tokentable_core7.SuiSignatureAirdropService({
767
836
  chainId: project.chainId,
768
837
  coinType: project.tokenAddress,
769
838
  walletClient,
770
839
  chainRpc: this.chainRpc,
771
840
  distributorId: project.contractAddress
772
841
  });
773
- } else if (project.chainType === import_tokentable_core6.ChainType.Evm) {
774
- strategy = new import_tokentable_core6.EvmSignatureAirdropService({
842
+ } else if (project.chainType === import_tokentable_core7.ChainType.Evm) {
843
+ strategy = new import_tokentable_core7.EvmSignatureAirdropService({
775
844
  chainId: Number(project.chainId),
776
845
  contractAddress: project.contractAddress,
777
846
  walletClient,
@@ -812,7 +881,7 @@ var SignatureAirdropClient = class {
812
881
  }
813
882
  const service = await this.getStrategy(walletClient);
814
883
  const project = await this.getProjectInfo();
815
- const res = await (0, import_tokentable_core6.checkGetSignatures)(
884
+ const res = await (0, import_tokentable_core7.checkGetSignatures)(
816
885
  {
817
886
  claimIds,
818
887
  projectId: this.projectId,
@@ -835,7 +904,7 @@ var SignatureAirdropClient = class {
835
904
  if (!filteredClaims.length) {
836
905
  throw new Error("No matching claims found");
837
906
  }
838
- const defaultRecipient = project.chainType === import_tokentable_core6.ChainType.Evm ? walletClient.account?.address : "";
907
+ const defaultRecipient = project.chainType === import_tokentable_core7.ChainType.Evm ? walletClient.account?.address : "";
839
908
  const claimData = filteredClaims.map((it) => {
840
909
  const signature = signatureMap[it.claimId];
841
910
  if (!signature) {