@sign-global/tokentable-core 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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +74 -7
- package/dist/index.d.ts +74 -7
- package/dist/index.js +265 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +263 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
- package/src/constants/chain-config.ts +5 -0
- package/src/constants/network.ts +26 -0
- package/src/contracts/aptos/AirdropService.ts +55 -0
- package/src/contracts/aptos/AptosAirdropClient.ts +27 -0
- package/src/contracts/aptos/AptosBaseDistributorClient.ts +81 -0
- package/src/contracts/aptos/AptosContractClient.ts +109 -0
- package/src/contracts/aptos/abis/fee_collector.ts +223 -0
- package/src/contracts/aptos/abis/index.ts +18 -0
- package/src/contracts/aptos/abis/md_create2.ts +252 -0
- package/src/contracts/aptos/abis/merkle_distributor.ts +330 -0
- package/src/contracts/aptos/abis/merkle_verifier.ts +34 -0
- package/src/contracts/aptos/abis/ownable.ts +106 -0
- package/src/contracts/index.ts +3 -0
- package/src/contracts/sui/DistributorWithFeeClient.ts +10 -0
- package/src/types/index.ts +14 -3
package/dist/index.mjs
CHANGED
|
@@ -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,8 @@ var ChainType = /* @__PURE__ */ ((ChainType2) => {
|
|
|
3721
3750
|
ChainType2["Ton"] = "ton";
|
|
3722
3751
|
ChainType2["Solana"] = "solana";
|
|
3723
3752
|
ChainType2["Sui"] = "sui";
|
|
3753
|
+
ChainType2["Aptos"] = "aptos";
|
|
3754
|
+
ChainType2["Cosmos"] = "cosmos";
|
|
3724
3755
|
return ChainType2;
|
|
3725
3756
|
})(ChainType || {});
|
|
3726
3757
|
var AirdropSigIdentityTypeEnum = /* @__PURE__ */ ((AirdropSigIdentityTypeEnum2) => {
|
|
@@ -3728,6 +3759,7 @@ var AirdropSigIdentityTypeEnum = /* @__PURE__ */ ((AirdropSigIdentityTypeEnum2)
|
|
|
3728
3759
|
AirdropSigIdentityTypeEnum2["SolanaWallet"] = "Solana Wallet";
|
|
3729
3760
|
AirdropSigIdentityTypeEnum2["EVMWallet"] = "EVM Wallet";
|
|
3730
3761
|
AirdropSigIdentityTypeEnum2["TONWallet"] = "TON Wallet";
|
|
3762
|
+
AirdropSigIdentityTypeEnum2["CosmosWallet"] = "Cosmos Wallet";
|
|
3731
3763
|
AirdropSigIdentityTypeEnum2["Google"] = "Google Account";
|
|
3732
3764
|
AirdropSigIdentityTypeEnum2["Discord"] = "Discord Account";
|
|
3733
3765
|
return AirdropSigIdentityTypeEnum2;
|
|
@@ -12594,6 +12626,13 @@ var SuiDistributorWithFeeClient = class extends SuiContractClientBase {
|
|
|
12594
12626
|
const clock = await this.getSharedObjectRef(tx, "0x6", false);
|
|
12595
12627
|
const hexToBytes = (hex) => Array.from(Buffer.from(hex.replace(/^0x/, ""), "hex"));
|
|
12596
12628
|
const feeTokenType = "0x2::sui::SUI";
|
|
12629
|
+
const gasBalance = await this.client.getBalance({
|
|
12630
|
+
owner: this.wallet.accounts[0].address,
|
|
12631
|
+
coinType: feeTokenType
|
|
12632
|
+
});
|
|
12633
|
+
if (BigInt(gasBalance.totalBalance) < totalFees) {
|
|
12634
|
+
throw new Error(`Insufficient SUI balance. Required: ${totalFees}, Available: ${gasBalance.totalBalance}`);
|
|
12635
|
+
}
|
|
12597
12636
|
const [feeCoin] = tx.splitCoins(
|
|
12598
12637
|
tx.gas,
|
|
12599
12638
|
// 用 gas 对象作为源
|
|
@@ -12669,9 +12708,232 @@ var SignatureAirdropService3 = class {
|
|
|
12669
12708
|
return this.feeDistributorClient.claimWithFee(this.options.coinType, feeCollector, data);
|
|
12670
12709
|
}
|
|
12671
12710
|
};
|
|
12711
|
+
|
|
12712
|
+
// src/contracts/aptos/AptosContractClient.ts
|
|
12713
|
+
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";
|
|
12714
|
+
var AptosContractClientBase = class {
|
|
12715
|
+
address;
|
|
12716
|
+
chainId;
|
|
12717
|
+
wallet;
|
|
12718
|
+
client;
|
|
12719
|
+
module;
|
|
12720
|
+
constructor(contractInfo) {
|
|
12721
|
+
this.address = contractInfo.address;
|
|
12722
|
+
this.chainId = contractInfo.chainId;
|
|
12723
|
+
this.wallet = contractInfo.account;
|
|
12724
|
+
this.module = contractInfo.module;
|
|
12725
|
+
this.client = this.initClient(contractInfo.chainRpc);
|
|
12726
|
+
}
|
|
12727
|
+
initClient(chainRpc) {
|
|
12728
|
+
const chainIdMap = {
|
|
12729
|
+
"2": Network.TESTNET,
|
|
12730
|
+
"1": Network.MAINNET
|
|
12731
|
+
};
|
|
12732
|
+
const config = new AptosConfig({
|
|
12733
|
+
network: chainIdMap[this.chainId],
|
|
12734
|
+
fullnode: chainRpc
|
|
12735
|
+
});
|
|
12736
|
+
return new Aptos(config);
|
|
12737
|
+
}
|
|
12738
|
+
async invokeContractRead(method, args) {
|
|
12739
|
+
try {
|
|
12740
|
+
const viewPayload = {
|
|
12741
|
+
function: `${this.address}::${this.module}::${method}`,
|
|
12742
|
+
functionArguments: args
|
|
12743
|
+
};
|
|
12744
|
+
return await this.client.view({ payload: viewPayload });
|
|
12745
|
+
} catch (error) {
|
|
12746
|
+
console.error(`Error invoking read method ${method}:`, error);
|
|
12747
|
+
throw error;
|
|
12748
|
+
}
|
|
12749
|
+
}
|
|
12750
|
+
async invokeContractWrite(method, args) {
|
|
12751
|
+
if (!this.wallet) {
|
|
12752
|
+
throw new Error("Account not connected");
|
|
12753
|
+
}
|
|
12754
|
+
try {
|
|
12755
|
+
const response = await this.wallet.signAndSubmitTransaction({
|
|
12756
|
+
sender: this.wallet.account?.address,
|
|
12757
|
+
data: {
|
|
12758
|
+
function: `${this.address}::${this.module}::${method}`,
|
|
12759
|
+
functionArguments: args
|
|
12760
|
+
}
|
|
12761
|
+
});
|
|
12762
|
+
await this.client.waitForTransaction({
|
|
12763
|
+
transactionHash: response.hash
|
|
12764
|
+
});
|
|
12765
|
+
return response.hash;
|
|
12766
|
+
} catch (error) {
|
|
12767
|
+
console.error(`Error invoking write method ${method}:`, error);
|
|
12768
|
+
throw error;
|
|
12769
|
+
}
|
|
12770
|
+
}
|
|
12771
|
+
async signTransaction({
|
|
12772
|
+
functionName,
|
|
12773
|
+
functionArguments,
|
|
12774
|
+
typeArguments
|
|
12775
|
+
}) {
|
|
12776
|
+
if (!this.wallet) {
|
|
12777
|
+
throw new Error("Account not connected");
|
|
12778
|
+
}
|
|
12779
|
+
try {
|
|
12780
|
+
const response = await this.wallet.signAndSubmitTransaction({
|
|
12781
|
+
sender: this.wallet.account?.address,
|
|
12782
|
+
data: {
|
|
12783
|
+
function: functionName,
|
|
12784
|
+
functionArguments,
|
|
12785
|
+
typeArguments: typeArguments || []
|
|
12786
|
+
}
|
|
12787
|
+
});
|
|
12788
|
+
const res = await this.client.waitForTransaction({
|
|
12789
|
+
transactionHash: response.hash
|
|
12790
|
+
});
|
|
12791
|
+
return response.hash;
|
|
12792
|
+
} catch (error) {
|
|
12793
|
+
throw error;
|
|
12794
|
+
}
|
|
12795
|
+
}
|
|
12796
|
+
};
|
|
12797
|
+
|
|
12798
|
+
// src/contracts/aptos/AptosAirdropClient.ts
|
|
12799
|
+
var AptosAirdropContractClient = class extends AptosContractClientBase {
|
|
12800
|
+
airdropAddress;
|
|
12801
|
+
constructor(options) {
|
|
12802
|
+
const chainConfig = getChainConfig(options.chainId);
|
|
12803
|
+
super({
|
|
12804
|
+
...options,
|
|
12805
|
+
address: chainConfig.contractAddress,
|
|
12806
|
+
module: "merkle_distributor_with_fees"
|
|
12807
|
+
});
|
|
12808
|
+
this.airdropAddress = options.address;
|
|
12809
|
+
}
|
|
12810
|
+
hexToBytes(hexStr) {
|
|
12811
|
+
const hex = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr;
|
|
12812
|
+
return Array.from(Buffer.from(hex, "hex"));
|
|
12813
|
+
}
|
|
12814
|
+
async claim({ proof, group, data, value }) {
|
|
12815
|
+
const dataBytes = this.hexToBytes(data);
|
|
12816
|
+
const proofBytes = proof.map((p) => this.hexToBytes(p));
|
|
12817
|
+
return await this.invokeContractWrite("claim", [this.airdropAddress, proofBytes, dataBytes]);
|
|
12818
|
+
}
|
|
12819
|
+
};
|
|
12820
|
+
|
|
12821
|
+
// src/contracts/aptos/AptosBaseDistributorClient.ts
|
|
12822
|
+
var AptosBaseDistributorContractClient = class extends AptosContractClientBase {
|
|
12823
|
+
airdropAddress;
|
|
12824
|
+
constructor(options) {
|
|
12825
|
+
const chainConfig = getChainConfig(options.chainId);
|
|
12826
|
+
super({
|
|
12827
|
+
...options,
|
|
12828
|
+
address: chainConfig.contractAddress,
|
|
12829
|
+
module: "base_distributor"
|
|
12830
|
+
});
|
|
12831
|
+
this.airdropAddress = options.address;
|
|
12832
|
+
}
|
|
12833
|
+
async getContractInfo() {
|
|
12834
|
+
const data = await this.invokeContractRead("get_distribution_info", [this.airdropAddress]);
|
|
12835
|
+
console.log("data", data);
|
|
12836
|
+
const [root, token, startTime, endTime, owner, version, paused] = data;
|
|
12837
|
+
return {
|
|
12838
|
+
root,
|
|
12839
|
+
token,
|
|
12840
|
+
startTime: Number(startTime),
|
|
12841
|
+
endTime: Number(endTime),
|
|
12842
|
+
owner,
|
|
12843
|
+
version,
|
|
12844
|
+
paused
|
|
12845
|
+
};
|
|
12846
|
+
}
|
|
12847
|
+
async deposit({ amount, token }) {
|
|
12848
|
+
return await this.signTransaction({
|
|
12849
|
+
functionName: `0x1::primary_fungible_store::transfer`,
|
|
12850
|
+
functionArguments: [token, this.airdropAddress, amount],
|
|
12851
|
+
typeArguments: ["0x1::fungible_asset::Metadata"]
|
|
12852
|
+
});
|
|
12853
|
+
}
|
|
12854
|
+
async isLeafUsed(leaf) {
|
|
12855
|
+
const leafBytes = leaf.startsWith("0x") ? Array.from(Buffer.from(leaf.slice(2), "hex")) : Array.from(Buffer.from(leaf, "hex"));
|
|
12856
|
+
const res = await this.invokeContractRead("is_leaf_used", [this.airdropAddress, leafBytes]);
|
|
12857
|
+
console.log("res", res);
|
|
12858
|
+
return res[0];
|
|
12859
|
+
}
|
|
12860
|
+
async batchFetchClaimed(leafs) {
|
|
12861
|
+
const res = await Promise.all(
|
|
12862
|
+
leafs.map(async (leaf) => {
|
|
12863
|
+
return this.isLeafUsed(leaf);
|
|
12864
|
+
})
|
|
12865
|
+
);
|
|
12866
|
+
return res.map((info) => ({
|
|
12867
|
+
result: info || false,
|
|
12868
|
+
status: "success"
|
|
12869
|
+
}));
|
|
12870
|
+
}
|
|
12871
|
+
hexToBytes(hexStr) {
|
|
12872
|
+
const hex = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr;
|
|
12873
|
+
return Array.from(Buffer.from(hex, "hex"));
|
|
12874
|
+
}
|
|
12875
|
+
async claim({ proof, data }) {
|
|
12876
|
+
const groupBytes = this.hexToBytes("");
|
|
12877
|
+
const dataBytes = this.hexToBytes(data);
|
|
12878
|
+
const proofBytes = proof.map((p) => this.hexToBytes(p));
|
|
12879
|
+
return await this.invokeContractWrite("claim", [this.airdropAddress, proofBytes, groupBytes, dataBytes]);
|
|
12880
|
+
}
|
|
12881
|
+
async getPaused() {
|
|
12882
|
+
const res = await this.getContractInfo();
|
|
12883
|
+
return res.paused;
|
|
12884
|
+
}
|
|
12885
|
+
async getClaimFee(contractAddress13, amount) {
|
|
12886
|
+
return 0;
|
|
12887
|
+
}
|
|
12888
|
+
};
|
|
12889
|
+
|
|
12890
|
+
// src/contracts/aptos/AirdropService.ts
|
|
12891
|
+
var AirdropService4 = class {
|
|
12892
|
+
options;
|
|
12893
|
+
constructor(options) {
|
|
12894
|
+
this.options = options;
|
|
12895
|
+
}
|
|
12896
|
+
get airdropClient() {
|
|
12897
|
+
if (!this.options) {
|
|
12898
|
+
throw new Error("options is empty");
|
|
12899
|
+
}
|
|
12900
|
+
return new AptosAirdropContractClient(this.options);
|
|
12901
|
+
}
|
|
12902
|
+
get baseClient() {
|
|
12903
|
+
if (!this.options) {
|
|
12904
|
+
throw new Error("options is empty");
|
|
12905
|
+
}
|
|
12906
|
+
return new AptosBaseDistributorContractClient(this.options);
|
|
12907
|
+
}
|
|
12908
|
+
async isLeafUsed(leaf) {
|
|
12909
|
+
return this.baseClient.isLeafUsed(leaf);
|
|
12910
|
+
}
|
|
12911
|
+
async batchFetchClaimed(leafs) {
|
|
12912
|
+
return this.baseClient.batchFetchClaimed(leafs);
|
|
12913
|
+
}
|
|
12914
|
+
async claim({ proof, group, data, value }) {
|
|
12915
|
+
return this.airdropClient.claim({
|
|
12916
|
+
proof,
|
|
12917
|
+
group,
|
|
12918
|
+
data,
|
|
12919
|
+
value
|
|
12920
|
+
});
|
|
12921
|
+
}
|
|
12922
|
+
async getVersion() {
|
|
12923
|
+
const res = await this.baseClient.getContractInfo();
|
|
12924
|
+
return res.version;
|
|
12925
|
+
}
|
|
12926
|
+
async getClaimFee(contractAddress13, amount) {
|
|
12927
|
+
return this.baseClient.getClaimFee(contractAddress13, amount);
|
|
12928
|
+
}
|
|
12929
|
+
async getPaused() {
|
|
12930
|
+
return this.baseClient.getPaused();
|
|
12931
|
+
}
|
|
12932
|
+
};
|
|
12672
12933
|
export {
|
|
12673
12934
|
AirdropSigIdentityTypeEnum,
|
|
12674
12935
|
ApiClient,
|
|
12936
|
+
AirdropService4 as AptosAirdropService,
|
|
12675
12937
|
CONST,
|
|
12676
12938
|
ChainConfig,
|
|
12677
12939
|
ChainType,
|
|
@@ -12690,6 +12952,7 @@ export {
|
|
|
12690
12952
|
TonWalletService,
|
|
12691
12953
|
ZERO_ADDRESS,
|
|
12692
12954
|
apiClient,
|
|
12955
|
+
aptosTestNet,
|
|
12693
12956
|
batchCheckClaimedForSignature,
|
|
12694
12957
|
bindWallet,
|
|
12695
12958
|
checkEligibility,
|