@sign-global/tokentable-core 1.4.0 → 1.5.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.mjs CHANGED
@@ -102,10 +102,10 @@ var solanaDevNet = {
102
102
  },
103
103
  rpcUrls: {
104
104
  public: {
105
- http: ["https://devnet.helius-rpc.com/?api-key=92a10901-e587-4f65-a180-4a63b7305966"]
105
+ http: ["https://serene-empty-film.solana-devnet.quiknode.pro/7fcc62232b14dc8a6a154597ee028ebf00e0c195"]
106
106
  },
107
107
  default: {
108
- http: ["https://devnet.helius-rpc.com/?api-key=92a10901-e587-4f65-a180-4a63b7305966"]
108
+ http: ["https://serene-empty-film.solana-devnet.quiknode.pro/7fcc62232b14dc8a6a154597ee028ebf00e0c195"]
109
109
  }
110
110
  },
111
111
  blockExplorers: {
@@ -127,10 +127,10 @@ var solanaMainNet = {
127
127
  },
128
128
  rpcUrls: {
129
129
  public: {
130
- http: ["https://neat-falling-dream.solana-mainnet.quiknode.pro/55dbcc2244d010e047c4ab1e3b7964cc6204505d"]
130
+ http: ["https://serene-empty-film.solana-mainnet.quiknode.pro/7fcc62232b14dc8a6a154597ee028ebf00e0c195"]
131
131
  },
132
132
  default: {
133
- http: ["https://neat-falling-dream.solana-mainnet.quiknode.pro/55dbcc2244d010e047c4ab1e3b7964cc6204505d"]
133
+ http: ["https://serene-empty-film.solana-mainnet.quiknode.pro/7fcc62232b14dc8a6a154597ee028ebf00e0c195"]
134
134
  }
135
135
  },
136
136
  blockExplorers: {
@@ -212,6 +212,31 @@ var suiMainNet = {
212
212
  },
213
213
  testnet: false
214
214
  };
215
+ var aptosTestNet = {
216
+ id: 2,
217
+ name: "Aptos Testnet",
218
+ network: "Aptos Testnet",
219
+ nativeCurrency: {
220
+ decimals: 8,
221
+ name: "Aptos",
222
+ symbol: "APT"
223
+ },
224
+ rpcUrls: {
225
+ public: {
226
+ http: ["https://api.testnet.aptoslabs.com/v1"]
227
+ },
228
+ default: {
229
+ http: ["https://api.testnet.aptoslabs.com/v1"]
230
+ }
231
+ },
232
+ blockExplorers: {
233
+ default: {
234
+ name: "aptos scan",
235
+ url: "hhttps://explorer.aptoslabs.com/"
236
+ }
237
+ },
238
+ testnet: true
239
+ };
215
240
 
216
241
  // src/constants/chain-config.ts
217
242
  import { CHAIN as CHAIN2 } from "@tonconnect/sdk";
@@ -306,6 +331,10 @@ var ChainConfig = {
306
331
  [suiMainNet.id]: {
307
332
  contractAddress: "0x3f73ec78d3e8a99277496edb6183d6075490983c2a29542a1c3f709aa31169b5",
308
333
  rpcUrl: suiMainNet.rpcUrls.default.http[0]
334
+ },
335
+ [aptosTestNet.id]: {
336
+ contractAddress: "0x0ee860c2c1dc9e6d7c013cfc78cecfc226dfffa403b0ca212b38d958bc1048c9",
337
+ rpcUrl: aptosTestNet.rpcUrls.default.http[0]
309
338
  }
310
339
  };
311
340
  var SupportedChains = [
@@ -3721,6 +3750,7 @@ var ChainType = /* @__PURE__ */ ((ChainType2) => {
3721
3750
  ChainType2["Ton"] = "ton";
3722
3751
  ChainType2["Solana"] = "solana";
3723
3752
  ChainType2["Sui"] = "sui";
3753
+ ChainType2["Aptos"] = "aptos";
3724
3754
  return ChainType2;
3725
3755
  })(ChainType || {});
3726
3756
  var AirdropSigIdentityTypeEnum = /* @__PURE__ */ ((AirdropSigIdentityTypeEnum2) => {
@@ -12594,6 +12624,13 @@ var SuiDistributorWithFeeClient = class extends SuiContractClientBase {
12594
12624
  const clock = await this.getSharedObjectRef(tx, "0x6", false);
12595
12625
  const hexToBytes = (hex) => Array.from(Buffer.from(hex.replace(/^0x/, ""), "hex"));
12596
12626
  const feeTokenType = "0x2::sui::SUI";
12627
+ const gasBalance = await this.client.getBalance({
12628
+ owner: this.wallet.accounts[0].address,
12629
+ coinType: feeTokenType
12630
+ });
12631
+ if (BigInt(gasBalance.totalBalance) < totalFees) {
12632
+ throw new Error(`Insufficient SUI balance. Required: ${totalFees}, Available: ${gasBalance.totalBalance}`);
12633
+ }
12597
12634
  const [feeCoin] = tx.splitCoins(
12598
12635
  tx.gas,
12599
12636
  // 用 gas 对象作为源
@@ -12669,9 +12706,232 @@ var SignatureAirdropService3 = class {
12669
12706
  return this.feeDistributorClient.claimWithFee(this.options.coinType, feeCollector, data);
12670
12707
  }
12671
12708
  };
12709
+
12710
+ // src/contracts/aptos/AptosContractClient.ts
12711
+ import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
12712
+ var AptosContractClientBase = class {
12713
+ address;
12714
+ chainId;
12715
+ wallet;
12716
+ client;
12717
+ module;
12718
+ constructor(contractInfo) {
12719
+ this.address = contractInfo.address;
12720
+ this.chainId = contractInfo.chainId;
12721
+ this.wallet = contractInfo.account;
12722
+ this.module = contractInfo.module;
12723
+ this.client = this.initClient(contractInfo.chainRpc);
12724
+ }
12725
+ initClient(chainRpc) {
12726
+ const chainIdMap = {
12727
+ "2": Network.TESTNET,
12728
+ "1": Network.MAINNET
12729
+ };
12730
+ const config = new AptosConfig({
12731
+ network: chainIdMap[this.chainId],
12732
+ fullnode: chainRpc
12733
+ });
12734
+ return new Aptos(config);
12735
+ }
12736
+ async invokeContractRead(method, args) {
12737
+ try {
12738
+ const viewPayload = {
12739
+ function: `${this.address}::${this.module}::${method}`,
12740
+ functionArguments: args
12741
+ };
12742
+ return await this.client.view({ payload: viewPayload });
12743
+ } catch (error) {
12744
+ console.error(`Error invoking read method ${method}:`, error);
12745
+ throw error;
12746
+ }
12747
+ }
12748
+ async invokeContractWrite(method, args) {
12749
+ if (!this.wallet) {
12750
+ throw new Error("Account not connected");
12751
+ }
12752
+ try {
12753
+ const response = await this.wallet.signAndSubmitTransaction({
12754
+ sender: this.wallet.account?.address,
12755
+ data: {
12756
+ function: `${this.address}::${this.module}::${method}`,
12757
+ functionArguments: args
12758
+ }
12759
+ });
12760
+ await this.client.waitForTransaction({
12761
+ transactionHash: response.hash
12762
+ });
12763
+ return response.hash;
12764
+ } catch (error) {
12765
+ console.error(`Error invoking write method ${method}:`, error);
12766
+ throw error;
12767
+ }
12768
+ }
12769
+ async signTransaction({
12770
+ functionName,
12771
+ functionArguments,
12772
+ typeArguments
12773
+ }) {
12774
+ if (!this.wallet) {
12775
+ throw new Error("Account not connected");
12776
+ }
12777
+ try {
12778
+ const response = await this.wallet.signAndSubmitTransaction({
12779
+ sender: this.wallet.account?.address,
12780
+ data: {
12781
+ function: functionName,
12782
+ functionArguments,
12783
+ typeArguments: typeArguments || []
12784
+ }
12785
+ });
12786
+ const res = await this.client.waitForTransaction({
12787
+ transactionHash: response.hash
12788
+ });
12789
+ return response.hash;
12790
+ } catch (error) {
12791
+ throw error;
12792
+ }
12793
+ }
12794
+ };
12795
+
12796
+ // src/contracts/aptos/AptosAirdropClient.ts
12797
+ var AptosAirdropContractClient = class extends AptosContractClientBase {
12798
+ airdropAddress;
12799
+ constructor(options) {
12800
+ const chainConfig = getChainConfig(options.chainId);
12801
+ super({
12802
+ ...options,
12803
+ address: chainConfig.contractAddress,
12804
+ module: "merkle_distributor_with_fees"
12805
+ });
12806
+ this.airdropAddress = options.address;
12807
+ }
12808
+ hexToBytes(hexStr) {
12809
+ const hex = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr;
12810
+ return Array.from(Buffer.from(hex, "hex"));
12811
+ }
12812
+ async claim({ proof, group, data, value }) {
12813
+ const dataBytes = this.hexToBytes(data);
12814
+ const proofBytes = proof.map((p) => this.hexToBytes(p));
12815
+ return await this.invokeContractWrite("claim", [this.airdropAddress, proofBytes, dataBytes]);
12816
+ }
12817
+ };
12818
+
12819
+ // src/contracts/aptos/AptosBaseDistributorClient.ts
12820
+ var AptosBaseDistributorContractClient = class extends AptosContractClientBase {
12821
+ airdropAddress;
12822
+ constructor(options) {
12823
+ const chainConfig = getChainConfig(options.chainId);
12824
+ super({
12825
+ ...options,
12826
+ address: chainConfig.contractAddress,
12827
+ module: "base_distributor"
12828
+ });
12829
+ this.airdropAddress = options.address;
12830
+ }
12831
+ async getContractInfo() {
12832
+ const data = await this.invokeContractRead("get_distribution_info", [this.airdropAddress]);
12833
+ console.log("data", data);
12834
+ const [root, token, startTime, endTime, owner, version, paused] = data;
12835
+ return {
12836
+ root,
12837
+ token,
12838
+ startTime: Number(startTime),
12839
+ endTime: Number(endTime),
12840
+ owner,
12841
+ version,
12842
+ paused
12843
+ };
12844
+ }
12845
+ async deposit({ amount, token }) {
12846
+ return await this.signTransaction({
12847
+ functionName: `0x1::primary_fungible_store::transfer`,
12848
+ functionArguments: [token, this.airdropAddress, amount],
12849
+ typeArguments: ["0x1::fungible_asset::Metadata"]
12850
+ });
12851
+ }
12852
+ async isLeafUsed(leaf) {
12853
+ const leafBytes = leaf.startsWith("0x") ? Array.from(Buffer.from(leaf.slice(2), "hex")) : Array.from(Buffer.from(leaf, "hex"));
12854
+ const res = await this.invokeContractRead("is_leaf_used", [this.airdropAddress, leafBytes]);
12855
+ console.log("res", res);
12856
+ return res[0];
12857
+ }
12858
+ async batchFetchClaimed(leafs) {
12859
+ const res = await Promise.all(
12860
+ leafs.map(async (leaf) => {
12861
+ return this.isLeafUsed(leaf);
12862
+ })
12863
+ );
12864
+ return res.map((info) => ({
12865
+ result: info || false,
12866
+ status: "success"
12867
+ }));
12868
+ }
12869
+ hexToBytes(hexStr) {
12870
+ const hex = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr;
12871
+ return Array.from(Buffer.from(hex, "hex"));
12872
+ }
12873
+ async claim({ proof, data }) {
12874
+ const groupBytes = this.hexToBytes("");
12875
+ const dataBytes = this.hexToBytes(data);
12876
+ const proofBytes = proof.map((p) => this.hexToBytes(p));
12877
+ return await this.invokeContractWrite("claim", [this.airdropAddress, proofBytes, groupBytes, dataBytes]);
12878
+ }
12879
+ async getPaused() {
12880
+ const res = await this.getContractInfo();
12881
+ return res.paused;
12882
+ }
12883
+ async getClaimFee(contractAddress13, amount) {
12884
+ return 0;
12885
+ }
12886
+ };
12887
+
12888
+ // src/contracts/aptos/AirdropService.ts
12889
+ var AirdropService4 = class {
12890
+ options;
12891
+ constructor(options) {
12892
+ this.options = options;
12893
+ }
12894
+ get airdropClient() {
12895
+ if (!this.options) {
12896
+ throw new Error("options is empty");
12897
+ }
12898
+ return new AptosAirdropContractClient(this.options);
12899
+ }
12900
+ get baseClient() {
12901
+ if (!this.options) {
12902
+ throw new Error("options is empty");
12903
+ }
12904
+ return new AptosBaseDistributorContractClient(this.options);
12905
+ }
12906
+ async isLeafUsed(leaf) {
12907
+ return this.baseClient.isLeafUsed(leaf);
12908
+ }
12909
+ async batchFetchClaimed(leafs) {
12910
+ return this.baseClient.batchFetchClaimed(leafs);
12911
+ }
12912
+ async claim({ proof, group, data, value }) {
12913
+ return this.airdropClient.claim({
12914
+ proof,
12915
+ group,
12916
+ data,
12917
+ value
12918
+ });
12919
+ }
12920
+ async getVersion() {
12921
+ const res = await this.baseClient.getContractInfo();
12922
+ return res.version;
12923
+ }
12924
+ async getClaimFee(contractAddress13, amount) {
12925
+ return this.baseClient.getClaimFee(contractAddress13, amount);
12926
+ }
12927
+ async getPaused() {
12928
+ return this.baseClient.getPaused();
12929
+ }
12930
+ };
12672
12931
  export {
12673
12932
  AirdropSigIdentityTypeEnum,
12674
12933
  ApiClient,
12934
+ AirdropService4 as AptosAirdropService,
12675
12935
  CONST,
12676
12936
  ChainConfig,
12677
12937
  ChainType,
@@ -12690,6 +12950,7 @@ export {
12690
12950
  TonWalletService,
12691
12951
  ZERO_ADDRESS,
12692
12952
  apiClient,
12953
+ aptosTestNet,
12693
12954
  batchCheckClaimedForSignature,
12694
12955
  bindWallet,
12695
12956
  checkEligibility,