@sign-global/tokentable 0.0.4 → 0.0.5

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.
Files changed (76) hide show
  1. package/dist/cjs/airdrop/core/ton/AirdropClientV21.d.ts +29 -0
  2. package/dist/cjs/airdrop/core/ton/AirdropClientV21.js +112 -0
  3. package/dist/cjs/airdrop/core/ton/AirdropClientV21.js.map +1 -0
  4. package/dist/cjs/airdrop/core/ton/AirdropService.d.ts +11 -2
  5. package/dist/cjs/airdrop/core/ton/AirdropService.js +15 -1
  6. package/dist/cjs/airdrop/core/ton/AirdropService.js.map +1 -1
  7. package/dist/cjs/airdrop/core/ton/v21/build/Leaf.compiled.json +1 -0
  8. package/dist/cjs/airdrop/core/ton/v21/utils/constants.d.ts +44 -0
  9. package/dist/cjs/airdrop/core/ton/v21/utils/constants.js +51 -0
  10. package/dist/cjs/airdrop/core/ton/v21/utils/constants.js.map +1 -0
  11. package/dist/cjs/airdrop/core/ton/v21/utils/date.utils.d.ts +3 -0
  12. package/dist/cjs/airdrop/core/ton/v21/utils/date.utils.js +15 -0
  13. package/dist/cjs/airdrop/core/ton/v21/utils/date.utils.js.map +1 -0
  14. package/dist/cjs/airdrop/core/ton/v21/utils/index.d.ts +3 -0
  15. package/dist/cjs/airdrop/core/ton/v21/utils/index.js +20 -0
  16. package/dist/cjs/airdrop/core/ton/v21/utils/index.js.map +1 -0
  17. package/dist/cjs/airdrop/core/ton/v21/utils/ton.utils.d.ts +17 -0
  18. package/dist/cjs/airdrop/core/ton/v21/utils/ton.utils.js +87 -0
  19. package/dist/cjs/airdrop/core/ton/v21/utils/ton.utils.js.map +1 -0
  20. package/dist/cjs/airdrop/core/ton/v21/wrappers/Leaf.d.ts +24 -0
  21. package/dist/cjs/airdrop/core/ton/v21/wrappers/Leaf.js +60 -0
  22. package/dist/cjs/airdrop/core/ton/v21/wrappers/Leaf.js.map +1 -0
  23. package/dist/cjs/airdrop/core/ton/v21/wrappers/MerkleTokenDistributor.d.ts +66 -0
  24. package/dist/cjs/airdrop/core/ton/v21/wrappers/MerkleTokenDistributor.js +255 -0
  25. package/dist/cjs/airdrop/core/ton/v21/wrappers/MerkleTokenDistributor.js.map +1 -0
  26. package/dist/cjs/airdrop/core/ton/v21/wrappers/index.d.ts +2 -0
  27. package/dist/cjs/airdrop/core/ton/v21/wrappers/index.js +19 -0
  28. package/dist/cjs/airdrop/core/ton/v21/wrappers/index.js.map +1 -0
  29. package/dist/cjs/airdrop/types/index.d.ts +2 -1
  30. package/dist/cjs/airdrop/types/index.js +1 -0
  31. package/dist/cjs/airdrop/types/index.js.map +1 -1
  32. package/dist/esm/airdrop/core/ton/AirdropClientV21.d.ts +29 -0
  33. package/dist/esm/airdrop/core/ton/AirdropClientV21.js +105 -0
  34. package/dist/esm/airdrop/core/ton/AirdropClientV21.js.map +1 -0
  35. package/dist/esm/airdrop/core/ton/AirdropService.d.ts +11 -2
  36. package/dist/esm/airdrop/core/ton/AirdropService.js +15 -1
  37. package/dist/esm/airdrop/core/ton/AirdropService.js.map +1 -1
  38. package/dist/esm/airdrop/core/ton/v21/build/Leaf.compiled.json +1 -0
  39. package/dist/esm/airdrop/core/ton/v21/utils/constants.d.ts +44 -0
  40. package/dist/esm/airdrop/core/ton/v21/utils/constants.js +48 -0
  41. package/dist/esm/airdrop/core/ton/v21/utils/constants.js.map +1 -0
  42. package/dist/esm/airdrop/core/ton/v21/utils/date.utils.d.ts +3 -0
  43. package/dist/esm/airdrop/core/ton/v21/utils/date.utils.js +10 -0
  44. package/dist/esm/airdrop/core/ton/v21/utils/date.utils.js.map +1 -0
  45. package/dist/esm/airdrop/core/ton/v21/utils/index.d.ts +3 -0
  46. package/dist/esm/airdrop/core/ton/v21/utils/index.js +4 -0
  47. package/dist/esm/airdrop/core/ton/v21/utils/index.js.map +1 -0
  48. package/dist/esm/airdrop/core/ton/v21/utils/ton.utils.d.ts +17 -0
  49. package/dist/esm/airdrop/core/ton/v21/utils/ton.utils.js +69 -0
  50. package/dist/esm/airdrop/core/ton/v21/utils/ton.utils.js.map +1 -0
  51. package/dist/esm/airdrop/core/ton/v21/wrappers/Leaf.d.ts +24 -0
  52. package/dist/esm/airdrop/core/ton/v21/wrappers/Leaf.js +55 -0
  53. package/dist/esm/airdrop/core/ton/v21/wrappers/Leaf.js.map +1 -0
  54. package/dist/esm/airdrop/core/ton/v21/wrappers/MerkleTokenDistributor.d.ts +66 -0
  55. package/dist/esm/airdrop/core/ton/v21/wrappers/MerkleTokenDistributor.js +249 -0
  56. package/dist/esm/airdrop/core/ton/v21/wrappers/MerkleTokenDistributor.js.map +1 -0
  57. package/dist/esm/airdrop/core/ton/v21/wrappers/index.d.ts +2 -0
  58. package/dist/esm/airdrop/core/ton/v21/wrappers/index.js +3 -0
  59. package/dist/esm/airdrop/core/ton/v21/wrappers/index.js.map +1 -0
  60. package/dist/esm/airdrop/types/index.d.ts +2 -1
  61. package/dist/esm/airdrop/types/index.js +1 -0
  62. package/dist/esm/airdrop/types/index.js.map +1 -1
  63. package/package.json +1 -1
  64. package/src/airdrop/core/ton/AirdropClientV21.ts +131 -0
  65. package/src/airdrop/core/ton/AirdropService.ts +18 -1
  66. package/src/airdrop/core/ton/v21/build/Leaf.compiled.json +1 -0
  67. package/src/airdrop/core/ton/v21/build/MerkleTokenDistributor.compiled.json +1 -0
  68. package/src/airdrop/core/ton/v21/utils/constants.ts +48 -0
  69. package/src/airdrop/core/ton/v21/utils/date.utils.ts +11 -0
  70. package/src/airdrop/core/ton/v21/utils/index.ts +3 -0
  71. package/src/airdrop/core/ton/v21/utils/ton.utils.ts +84 -0
  72. package/src/airdrop/core/ton/v21/wrappers/Leaf.ts +69 -0
  73. package/src/airdrop/core/ton/v21/wrappers/MerkleTokenDistributor.ts +346 -0
  74. package/src/airdrop/core/ton/v21/wrappers/index.ts +2 -0
  75. package/src/airdrop/tests/index.test.ts +15 -0
  76. package/src/airdrop/types/index.ts +2 -1
@@ -0,0 +1,3 @@
1
+ export * from './Leaf';
2
+ export * from './MerkleTokenDistributor';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../src/airdrop/core/ton/v21/wrappers/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,0BAA0B,CAAC"}
@@ -91,7 +91,8 @@ export interface IAirdropData {
91
91
  export declare enum TonAirdropVersionEnum {
92
92
  V1 = "1.0.0",
93
93
  V2 = "2.0.0",
94
- LiteV1 = "11.0.0"
94
+ LiteV1 = "11.0.0",
95
+ NativeV1 = "21.0.0"
95
96
  }
96
97
  export declare enum EvmAirdropVersionEnum {
97
98
  V0 = "0.0.2",// 兼容btc减半 airdrop
@@ -14,6 +14,7 @@ export var TonAirdropVersionEnum;
14
14
  TonAirdropVersionEnum["V1"] = "1.0.0";
15
15
  TonAirdropVersionEnum["V2"] = "2.0.0";
16
16
  TonAirdropVersionEnum["LiteV1"] = "11.0.0";
17
+ TonAirdropVersionEnum["NativeV1"] = "21.0.0";
17
18
  })(TonAirdropVersionEnum || (TonAirdropVersionEnum = {}));
18
19
  export var EvmAirdropVersionEnum;
19
20
  (function (EvmAirdropVersionEnum) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/airdrop/types/index.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,wBAAW,CAAA;AACb,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;AAkDD,MAAM,CAAN,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,6BAAe,CAAA;IACf,qCAAuB,CAAA;IACvB,4BAAc,CAAA;AAChB,CAAC,EAJW,UAAU,KAAV,UAAU,QAIrB;AA6BD,MAAM,CAAN,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,qCAAY,CAAA;IACZ,qCAAY,CAAA;IACZ,0CAAiB,CAAA;AACnB,CAAC,EAJW,qBAAqB,KAArB,qBAAqB,QAIhC;AAED,MAAM,CAAN,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,qCAAY,CAAA;IACZ,qCAAY,CAAA;IACZ,qCAAY,CAAA,CAAC,yBAAyB;AACxC,CAAC,EAJW,qBAAqB,KAArB,qBAAqB,QAIhC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/airdrop/types/index.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,wBAAW,CAAA;IACX,wBAAW,CAAA;AACb,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;AAkDD,MAAM,CAAN,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,6BAAe,CAAA;IACf,qCAAuB,CAAA;IACvB,4BAAc,CAAA;AAChB,CAAC,EAJW,UAAU,KAAV,UAAU,QAIrB;AA6BD,MAAM,CAAN,IAAY,qBAKX;AALD,WAAY,qBAAqB;IAC/B,qCAAY,CAAA;IACZ,qCAAY,CAAA;IACZ,0CAAiB,CAAA;IACjB,4CAAmB,CAAA;AACrB,CAAC,EALW,qBAAqB,KAArB,qBAAqB,QAKhC;AAED,MAAM,CAAN,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,qCAAY,CAAA;IACZ,qCAAY,CAAA;IACZ,qCAAY,CAAA,CAAC,yBAAyB;AACxC,CAAC,EAJW,qBAAqB,KAArB,qBAAqB,QAIhC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sign-global/tokentable",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -0,0 +1,131 @@
1
+ import { TonContractBaseClient, IAirdropOption } from './TonContractBaseClient';
2
+ import { Leaf, MerkleTokenDistributor } from './v21/wrappers';
3
+ import { Address, Cell, fromNano } from '@ton/core';
4
+ import { IAirdropClaim } from '../../types';
5
+ import LeafCode from './v21/build/Leaf.compiled.json';
6
+ import { isBeforeByUnix } from '../../../utils';
7
+
8
+ export class TonAirdropClientV21 extends TonContractBaseClient {
9
+ version = '21.0.0';
10
+
11
+ constructor(option: IAirdropOption) {
12
+ super(option);
13
+ }
14
+
15
+ async getVersion() {
16
+ const airDropContract = await this.getAirdropContract();
17
+ const version = await airDropContract.getVersion();
18
+ this.version = version;
19
+ return version;
20
+ }
21
+
22
+ getAirdropContract = async () => {
23
+ const provider = await this.getTonClient();
24
+ const contract = new MerkleTokenDistributor(Address.parse(this.address));
25
+ return provider.open(contract);
26
+ };
27
+
28
+ getPaused = async () => {
29
+ const airDropContract = await this.getAirdropContract();
30
+ return airDropContract?.getPaused();
31
+ };
32
+
33
+ async getBaseParams() {
34
+ const airDropContract = await this.getAirdropContract();
35
+ const [startTime, endTime] = await airDropContract!.getTime();
36
+ const root = await airDropContract?.getRoot();
37
+ const adminAddress = await airDropContract?.getAdminAddress();
38
+
39
+ const owner = Address.parse(adminAddress?.toString()).toString({ bounceable: false });
40
+
41
+ const version = this.version || (await airDropContract.getVersion());
42
+
43
+ const feelessThreshold = await airDropContract?.getFeelessThreshold();
44
+ const paused = await airDropContract?.getPaused();
45
+ return {
46
+ startTime: startTime ? String(startTime?.valueOf() / 1000) : '',
47
+ endTime: endTime ? String(endTime?.valueOf() / 1000) : '',
48
+ root: root?.toString(),
49
+ owner: owner,
50
+ version,
51
+ feelessThreshold: fromNano(feelessThreshold),
52
+ paused
53
+ };
54
+ }
55
+
56
+ async getFeeInfo() {
57
+ const airDropContract = await this.getAirdropContract();
58
+ const claimFee = await airDropContract.getClaimFee();
59
+ const claimFeeReceiver = await airDropContract.getClaimFeeAddress();
60
+ return {
61
+ claimFee,
62
+ claimFeeReceiver
63
+ };
64
+ }
65
+
66
+ getFeelessThreshold = async () => {
67
+ const airDropContract = await this.getAirdropContract();
68
+ return airDropContract?.getFeelessThreshold();
69
+ };
70
+
71
+ claim = async (claimData: IAirdropClaim, options?: { onLoading?: () => void }) => {
72
+ const provider = await this.getTonClient();
73
+ const airdropContract = await this.getAirdropContract();
74
+ const index = BigInt(claimData.index);
75
+ const claimFee = await airdropContract!.getClaimFee();
76
+ const proof = Cell.fromBase64(claimData.proofBoc);
77
+
78
+ const leafCode = Cell.fromBoc(Buffer.from(LeafCode.hex, 'hex'))[0];
79
+
80
+ const leaf = provider.open(
81
+ Leaf.createFromConfig(
82
+ {
83
+ distributor: airdropContract.address,
84
+ index
85
+ },
86
+ leafCode
87
+ )
88
+ );
89
+
90
+ leaf.sendClaim(this.connection.senderDeploy, proof, index, claimFee);
91
+ const res = await this.waitForTransaction(options?.onLoading);
92
+
93
+ // while (!(await provider.isContractDeployed(leafAddress))) {
94
+ // console.log('waiting for leaf to deploy');
95
+ // await new Promise((resolve) => setTimeout(resolve, 1000));
96
+ // }
97
+ // // const res = await this.waitForTransactionForLegacy();
98
+ if (res) {
99
+ console.log(res, res.event_id, 'res');
100
+ }
101
+ return res;
102
+ };
103
+
104
+ checkClaimed = async (claimData: IAirdropClaim) => {
105
+ try {
106
+ if (isBeforeByUnix(claimData.unlockingAt)) return false;
107
+ const provider = await this.getTonClient();
108
+ const airdropContract = await this.getAirdropContract();
109
+
110
+ const index = BigInt(claimData.index);
111
+
112
+ const leafAddress = await airdropContract.getLeafAddress(index);
113
+
114
+ const isDeployed = await provider.isContractDeployed(leafAddress);
115
+
116
+ console.log(index, leafAddress.toString(), isDeployed, 'index');
117
+
118
+ if (!isDeployed) return false;
119
+
120
+ const leaf = new Leaf(leafAddress);
121
+ const leafContract = provider.open(leaf);
122
+ const isUsed = await leafContract?.getIsUsed();
123
+
124
+ console.log(isUsed, leafAddress.toString(), 'use');
125
+ return isUsed;
126
+ } catch (e: any) {
127
+ console.log(e, 'check claim err');
128
+ return false;
129
+ }
130
+ };
131
+ }
@@ -6,6 +6,7 @@ import { IAirdropOption } from './TonContractBaseClient';
6
6
  import { TonAirdropClientV3 } from './AirdropClientV3';
7
7
  import { fromNano } from '@ton/core';
8
8
  import { TonClient } from '@ton/ton';
9
+ import { TonAirdropClientV21 } from './AirdropClientV21';
9
10
 
10
11
  export class AirdropService {
11
12
  private address: string;
@@ -63,6 +64,18 @@ export class AirdropService {
63
64
  });
64
65
  }
65
66
 
67
+ private get airdropClientV21(): TonAirdropClientV21 {
68
+ if (!this?.address) {
69
+ throw new Error('Contract address is empty');
70
+ }
71
+
72
+ return new TonAirdropClientV21({
73
+ chainId: this.chainId,
74
+ address: this.address,
75
+ walletClient: this.walletClient
76
+ });
77
+ }
78
+
66
79
  async getVersion() {
67
80
  if (this.cachedVersion !== null) {
68
81
  return this.cachedVersion;
@@ -75,6 +88,10 @@ export class AirdropService {
75
88
  private async getClient() {
76
89
  const version = await this.getVersion();
77
90
 
91
+ if (version === TonAirdropVersionEnum.NativeV1) {
92
+ return this.airdropClientV21;
93
+ }
94
+
78
95
  if (version === TonAirdropVersionEnum.LiteV1) {
79
96
  return this.airdropClientV3;
80
97
  }
@@ -115,7 +132,7 @@ export class AirdropService {
115
132
  const feeInfo = await client.getFeeInfo();
116
133
  return {
117
134
  claimFee: fromNano(feeInfo.claimFee),
118
- claimFeeReceiver: feeInfo.claimFeeReceiver.toString({ bounceable: false })
135
+ claimFeeReceiver: feeInfo.claimFeeReceiver?.toString({ bounceable: false })
119
136
  };
120
137
  }
121
138
 
@@ -0,0 +1 @@
1
+ {"hex":"b5ee9c7241022a01000887000114ff00f4a413f4bcf2c80b01020162050202015804030025bbc01f057f844f842c8cb00f843cf16cb3fc98000dbaf13f057f84280202c918060201480c0702012009080019d8164658000e78b659fe4f6aa40201200b0a0025f76a268698000fc317d2000fc31e99f987c32400276be401c1cb232c072c004b2c1f2fff2743e900c20103a3c00d04f62082300de0b6b3a7640000ba9b30823025b946ebc0b36173e08200c354218235c702bd3a30fc0000be228238070c1cc73b00c80000bbb0f2f420c1008e1282300de0b6b3a76400005202a3f04712a984e020821b782dace9d9aa18bee30f01a7648238056bc75e2d6310000021822056bc75e2d631aa18bee300211716150e02f4822056bc75e2d631aa17be8e2701822056bc75e2d631aa17a101824adf0ab5a80a22c61ab5a7008238056bc75e2d63100000a984de21822056bc75e2d631aa16be8e2601822056bc75e2d631aa16a10182403f1fce3da636ea5cf8508238056bc75e2d63100000a984de21823815af1d78b58c400000bee30021140f02f482380ad78ebc5ac6200000be8e260182380ad78ebc5ac6200000a1018238280e60114edb805d038238056bc75e2d63100000a984de218238056bc75e2d63100000be8e26018238056bc75e2d63100000a10182380ebc5fb417461211108238056bc75e2d63100000a984de218232b5e3af16b1880000bee30021131001ec82315af1d78b58c40000be8e250182315af1d78b58c40000a101823806f5f17757889379378238056bc75e2d63100000a984de218238056bc75e2d6310000021a0511382380ad78ebc5ac6200000a98466a0511382381043561a8829300000a98466a05113823815af1d78b58c400000a98466a051131101ea82381b1ae4d6e2ef500000a98466a0511382382086ac351052600000a98466a05113823825f273933db5700000a98466a05113822056bc75e2d631aa16a98466a05113823830ca024f987b900000a98466a0511382383635c9adc5dea00000a98466a0511382383ba1910bf341b00000a98466a0031200428238410d586a20a4c00000a98412a08238056bc75e2d63100000a984018064a984004a018232b5e3af16b1880000a101823808f00f760a4b2db55d8238056bc75e2d63100000a984004c01823815af1d78b58c400000a101823927fa27722cc06cc5e28238056bc75e2d63100000a984003830822056bc75e2d631aa18a18261855144814a7ff805980ff0084000005020821b782dace9d9aa17be8e18821b782dace9d9aa17a182501425982cf597cd205cef73809171e20042821b782dace9d9aa18a18288195e54c5dd42177f53a27172fa9ec630262827aa2302012024190103aee01a01f62082300de0b6b3a7640000b98e1182300de0b6b3a76400005202a984f03ba3e0702182b05803bcc5cb9634ba4cfb2213f784019318ed4dcb6017880faa35be8e23308288195e54c5dd42177f53a27172fa9ec630262827aa23a904821b782dace9d9aa18de2182708bcc0026baae9e45e470190267a230cfaa18be1b02ea8e1c0182501425982cf597cd205cef7380a90401821b782dace9d9aa17a0dea76401a764208261855144814a7ff805980ff0084000be8e2a8238056bc75e2d631000008261855144814a7ff805980ff0084000a98401822056bc75e2d631aa18a001de20824adf0ab5a80a22c61ab5a700bee30020231c02f882403f1fce3da636ea5cf850be8e268238056bc75e2d6310000082403f1fce3da636ea5cf850a98401822056bc75e2d631aa16a001de20823927fa27722cc06cc5e2be8e268238056bc75e2d63100000823927fa27722cc06cc5e2a98401823815af1d78b58c400000a001de208238280e60114edb805d03bee30020221d02f482380ebc5fb41746121110be8e268238056bc75e2d6310000082380ebc5fb41746121110a984018238056bc75e2d63100000a001de20823808f00f760a4b2db55dbe8e258238056bc75e2d63100000823808f00f760a4b2db55da984018232b5e3af16b1880000a001de20823806f5f1775788937937bee30020211e01ec823806248f33704b286603be8e258238056bc75e2d63100000823806248f33704b286603a984018230ad78ebc5ac620000a001de20823805c548670b9510e7acbe8e258238056bc75e2d63100000823805c548670b9510e7aca98401823056bc75e2d6310000a001de208238056bc75e2d63100000a11f01fe8238056bc75e2d631000005122a012a98453008238056bc75e2d63100000a9845c8238056bc75e2d63100000a9842073a90413a051218238056bc75e2d63100000a9842075a90413a051218238056bc75e2d63100000a9842077a90413a051218238056bc75e2d63100000a9842079a90413a0598238056bc75e2d6310000020001ca984800ba904a0aa00a08064a904004a8238056bc75e2d63100000823806f5f1775788937937a9840182315af1d78b58c40000a001004c8238056bc75e2d631000008238280e60114edb805d03a9840182380ad78ebc5ac6200000a001004e8238056bc75e2d63100000824adf0ab5a80a22c61ab5a700a98401822056bc75e2d631aa17a00102012026250063a46410e0804c45896c678b00d180ef381038c70a023d5486531812d40950025503815210e0002298731819d5016780e4e84001d7d0c8871c02497c0f83434c0c05c6c2497c0f83e900c0074c7f4cfc8a08426871dda6ea38d8d16fc15fe10f1c17ca8f4cff4c03e1104eebcabdc3e10fe113c163000244c383e900c1c20043232c15633c5887e80b2dab260103ec03800a084140f4725eeb8c097c12103fcbc22702fcf057038210042c1d80bef2b0f842c001f268d4d33f30f864885210f90001f900baf26420d739f2aad30701c003f2ab21d765aa00a6025220f9415f03f84401d4308040f40e6fa131f2ad71f843f844f058f842f8448210d0d5f405c8cb1f15cb3f12cc13cb3f12cb0001cf16c9718010c8cb05f843cf1670fa02cb6accc9292800088306fb0000006e3bece9"}
@@ -0,0 +1 @@
1
+ {"hex":"b5ee9c7241024d01000d83000114ff00f4a413f4bcf2c80b0102016217020201200c030201200504000db8379f055f84d80201200706000db4983e0abf09d00201200b080201200a09000fad15fc13b7911840000dafd9f82afc25c0000db3aafc157e1120020158140d020158110e020120100f0010abe0f055f846f8470010a8e0f055f059f05a0201201312000cab92f055f849000ca82ff055f8430201201615000db1a7fc157e1320000db0643c157e10a00202c932180201482619020120211a0201201c1b0071d41084d0e3bb4e4658f8a659f89659f9163804a99382c65804bb880e5802c678b7164b8c008646582a801e78b387d010965b56664c0207d804020120201d0201201f1e00d70cbe13be13548c2f238bfe12b00063885c7232e3dc3232c7c073c5f25c60043232c17e12f3c5be127e80b2dab3325c7ec0258c3e13be126838b79c20043232c15400f3c59400fe80b2dab260103ec03e10be10fe113e117e11be11fe123e127e12be12fe133e135542fc15a000173e4020c27232c2b2fff274200029570c8cb00f828cf16cb3fc9f84876c8cb04ccccc980201202522020120242300754c85006fa025240cb0004c001945acf16029132e258cb0001fa0201fa02c85005cf1613cb1fcb1fccc901c904c8cb3f5003cf16cbffccccc9ed54800a75ed44d0d33f01f862fa4001f863d3ff01f864d401d0fa4001f865d31f01f866d31f01f867d430f868d430d0fa0001f869d30001f86af84ac00195fa4001f86b936df86be2d30001f86cfa0001f86dfa0030f86e800276be401c1cb232c072c004b2c1f2fff2743e900c20103a3c02704f62082300de0b6b3a7640000ba9b30823025b946ebc0b36173e08200c354218235c702bd3a30fc0000be228238070c1cc73b00c80000bbb0f2f420c1008e1282300de0b6b3a76400005202a3f04712a984e020821b782dace9d9aa18bee30f01a7648238056bc75e2d6310000021822056bc75e2d631aa18bee3002131302f2802f4822056bc75e2d631aa17be8e2701822056bc75e2d631aa17a101824adf0ab5a80a22c61ab5a7008238056bc75e2d63100000a984de21822056bc75e2d631aa16be8e2601822056bc75e2d631aa16a10182403f1fce3da636ea5cf8508238056bc75e2d63100000a984de21823815af1d78b58c400000bee300212e2902f482380ad78ebc5ac6200000be8e260182380ad78ebc5ac6200000a1018238280e60114edb805d038238056bc75e2d63100000a984de218238056bc75e2d63100000be8e26018238056bc75e2d63100000a10182380ebc5fb417461211108238056bc75e2d63100000a984de218232b5e3af16b1880000bee300212d2a01ec82315af1d78b58c40000be8e250182315af1d78b58c40000a101823806f5f17757889379378238056bc75e2d63100000a984de218238056bc75e2d6310000021a0511382380ad78ebc5ac6200000a98466a0511382381043561a8829300000a98466a05113823815af1d78b58c400000a98466a051132b01ea82381b1ae4d6e2ef500000a98466a0511382382086ac351052600000a98466a05113823825f273933db5700000a98466a05113822056bc75e2d631aa16a98466a05113823830ca024f987b900000a98466a0511382383635c9adc5dea00000a98466a0511382383ba1910bf341b00000a98466a0032c00428238410d586a20a4c00000a98412a08238056bc75e2d63100000a984018064a984004a018232b5e3af16b1880000a101823808f00f760a4b2db55d8238056bc75e2d63100000a984004c01823815af1d78b58c400000a101823927fa27722cc06cc5e28238056bc75e2d63100000a984003830822056bc75e2d631aa18a18261855144814a7ff805980ff0084000005020821b782dace9d9aa17be8e18821b782dace9d9aa17a182501425982cf597cd205cef73809171e20042821b782dace9d9aa18a18288195e54c5dd42177f53a27172fa9ec630262827aa230201203e330103aee03401f62082300de0b6b3a7640000b98e1182300de0b6b3a76400005202a984f03ba3e0702182b05803bcc5cb9634ba4cfb2213f784019318ed4dcb6017880faa35be8e23308288195e54c5dd42177f53a27172fa9ec630262827aa23a904821b782dace9d9aa18de2182708bcc0026baae9e45e470190267a230cfaa18be3502ea8e1c0182501425982cf597cd205cef7380a90401821b782dace9d9aa17a0dea76401a764208261855144814a7ff805980ff0084000be8e2a8238056bc75e2d631000008261855144814a7ff805980ff0084000a98401822056bc75e2d631aa18a001de20824adf0ab5a80a22c61ab5a700bee300203d3602f882403f1fce3da636ea5cf850be8e268238056bc75e2d6310000082403f1fce3da636ea5cf850a98401822056bc75e2d631aa16a001de20823927fa27722cc06cc5e2be8e268238056bc75e2d63100000823927fa27722cc06cc5e2a98401823815af1d78b58c400000a001de208238280e60114edb805d03bee300203c3702f482380ebc5fb41746121110be8e268238056bc75e2d6310000082380ebc5fb41746121110a984018238056bc75e2d63100000a001de20823808f00f760a4b2db55dbe8e258238056bc75e2d63100000823808f00f760a4b2db55da984018232b5e3af16b1880000a001de20823806f5f1775788937937bee300203b3801ec823806248f33704b286603be8e258238056bc75e2d63100000823806248f33704b286603a984018230ad78ebc5ac620000a001de20823805c548670b9510e7acbe8e258238056bc75e2d63100000823805c548670b9510e7aca98401823056bc75e2d6310000a001de208238056bc75e2d63100000a13901fe8238056bc75e2d631000005122a012a98453008238056bc75e2d63100000a9845c8238056bc75e2d63100000a9842073a90413a051218238056bc75e2d63100000a9842075a90413a051218238056bc75e2d63100000a9842077a90413a051218238056bc75e2d63100000a9842079a90413a0598238056bc75e2d631000003a001ca984800ba904a0aa00a08064a904004a8238056bc75e2d63100000823806f5f1775788937937a9840182315af1d78b58c40000a001004c8238056bc75e2d631000008238280e60114edb805d03a9840182380ad78ebc5ac6200000a001004e8238056bc75e2d63100000824adf0ab5a80a22c61ab5a700a98401822056bc75e2d631aa17a001020120403f0063a46410e0804c45896c678b00d180ef381038c70a023d5486531812d40950025503815210e0002298731819d5016780e4e84004f3d0c8871c02497c0f83434c0fe900c005c6c2497c0f80074c7f4cfc8a08411903f076ea38b8d16fc157e10f1c17ca8fe900c0831c03c993e10be113e117e11be11fe123e127e12be12fe133e137e13842f3c15b808a08416003133eeb8c088a08417515a406eb8c088a0841cfb70f4aeb8c088a0843e7196352ea4b4a494102fe8e6b10345f04f055f84ac000f264f8435210c705f84b12c705b1f2a3f842f843f844f845f846f847f848f849f84af84bf84cf84d70f056c88280576974686472617720636f6d706c6574656401cb8f70c8cb1f01cf17c9718010c8cb05f84bcf16f84efa02cb6accc98040fb00e0228210c46600a8bae3022282100c281f96484202feba8e3a345bf055f843c705f2a3fa003020c100f264f842f843f844f845f846f847f848f84af84bf84cf84df84e10bc10ab109a1089107810671056f056e022821010354bedbae30222821011faeb88ba8e2510345f04f055f843c705f2a3f842f843f844f845f846f847f84870206df84cf84df84ef056e022821026d65fa9474302b2ba8e3b345bf055f843c705f2a3d30030f842f843f844f845f846f847f848f849f84af84bf84df84e10bc10ab109a1089107810671056104510341023f056e022821079ce8ce5bae302028210d0d5f405bae3025f04840ff2f046440162f05501d4d33fd300fa403001f2685444405205ed44ed45ed47955b4130f05ced67ed65ed64747fed118aed41edf101f2ff4500e6f84cf2718209312d00f849a0820a625a00a0820afaf080a05240bef2b0d739f2aad30701c003f2abf84401d3ff59baf2acd43052108040f40e6fa1f2adfa40fa00d31f30f823bbf2a6f846f823bbf2a6f823f847bbf2a622f059f05a14c705f2ae820afaf080f84ea014a15220bcf27059f05b0076345bf055f843c705f2a3fa0030f842f843f844f845f846f847f848f849f84af84bf84cf84e10bc10ab109a1089107810671056104510344130f056007a345bf055f843c705f2a3fa403020c700f264f842f843f844f845f846f847f848f84971f84cf84df84e10bc10ab109a108910781067105610451034f0560072345bf055f843c705f2a3d31fd31fd3ff305321bef26420c000f264f842f843f845f848f849f84af84bf84cf84df84e109c108b10791078f05600a46c21f055f8435220c705f2a3fa00305122a1820afaf080f84ea0b9f264c88280576974686472617720636f6d706c6574656401cb8f70c8cb1f01cf17c9718010c8cb055003cf165003fa02cb6accc970fb00004e345bf055f843c705f2a3d33f30f843f844f845f846f847f848f849f84af84bf84cf84df84ef05601d8345bf055f843c705f2a3d31fd430885210f90001f900baf264218210f00aed53ba8e1df842f843f844f845f846f847f849f84af84bf84cf84df84e2c5550f056de018210cdb4d337ba8e1efb04f842f843f844f845f846f847f848f849f84af84bf84cf84df84ef0569130e24c000003a41717"}
@@ -0,0 +1,48 @@
1
+ export enum OpCode { // CRC32 hash
2
+ ChangeAdmin = 1178663965, // 0x4641444d
3
+ ChangeCode = 1476445391, // 0x57f8f8f
4
+ ChangePaused = 2809239666, // 0xa7a7a7a2
5
+ ChangeVersion = 1564829953, // 0x5d5d5d61
6
+ ClearClaimFeeAddress = 301656968, // 0x1201208
7
+ DeployLeaf = 2334832459, // 0x8b8b8b8b
8
+ Withdraw = 1944962002, // 0x73737372
9
+ WithdrawTokens = 2709472225, // 0xa1a1a1a1
10
+ WithdrawFees = 4190525652, // 0xf9f9f9f4
11
+ Claim = 1346182295, // 0x50505057
12
+ ProcessClaim = 3503682565, // 0xd0d5f405
13
+ SetBaseParams = 3295019176, // 0xc4c4c4c8
14
+ SetClaimFee = 203956118, // 0xc2c2c2c6
15
+ SetClaimFeeAddress = 271928301, // 0x103103d
16
+ SetPaused = 651583401, // 0x27272729
17
+ SetFeelessThreshold = 2043579621 // 0x79CE8CE5
18
+ }
19
+
20
+ export enum CodeType { // CRC32 hash
21
+ Leaf = 4027247955, // 0xf0f0f0f3
22
+ TokenDistributor = 3451179831 // 0xcececece
23
+ }
24
+
25
+ export enum ErrorCode {
26
+ UnknownOP = 0xffff, // 65535
27
+ ExpiredMessage = 0x20, // 32
28
+ RepeatedMessage = 0x21, // 33
29
+ InvalidSignature = 0x22, // 34
30
+ Unauthorized = 0x23, // 35
31
+ InvalidMessageParams = 0x24, // 36
32
+ UnsupportedOperation = 0x25, // 37
33
+ TimeInactive = 0x26, // 38
34
+ InvalidProof = 0x27, // 39
35
+ LeafUsed = 0x28, // 40
36
+ IncorrectFees = 0x29, // 41
37
+ IsProofExotic = 0x2a, // 42
38
+ TreeExceeded = 0x2b, // 43
39
+ InvalidTree = 0x2c, // 44
40
+ NotFound = 0x2d, // 45
41
+ WrongSender = 0x2e, // 46
42
+ InvalidIndex = 0x2f, // 47
43
+ NotEnoughTokens = 0x30, // 48
44
+ ContractPaused = 0x31 // 49
45
+ }
46
+
47
+ export const DICT_CELL_BASE64 =
48
+ 'te6cckEBBQEAagACA8/YAgEAVdQAOTo5SskfgLMwcypLhB+yLkHhU0qZ/jjQzsVCYiSLoEFAjw0YBf7mYAgCASADAwIBIAQEAFUgAcnRylZI/AWZg5lSXCD9kXIPCppUz/HGhnYqExEkXQIKBHhowC/3MwBAtoUrSg==';
@@ -0,0 +1,11 @@
1
+ export function dateToUnixTimestamp(date: Date): number {
2
+ return Math.floor(date.getTime() / 1000);
3
+ }
4
+
5
+ export function unixTimestampToDate(timestamp: number): Date {
6
+ return new Date(timestamp * 1000);
7
+ }
8
+
9
+ export function addOneHour(date: Date): Date {
10
+ return new Date(date.getTime() + 60 * 60 * 1000);
11
+ }
@@ -0,0 +1,3 @@
1
+ export * from './constants';
2
+ export * from './date.utils';
3
+ export * from './ton.utils';
@@ -0,0 +1,84 @@
1
+ import { Address, BitString, Cell, Slice, beginCell, contractAddress, crc32c, toNano } from '@ton/core';
2
+
3
+ export function stringToSlice(str: string): Slice {
4
+ return beginCell().storeStringTail(str).endCell().asSlice();
5
+ }
6
+
7
+ export function sliceToString(slice: Slice): string {
8
+ const cell = beginCell().storeSlice(slice).endCell();
9
+ return cell.beginParse().loadStringTail();
10
+ }
11
+
12
+ export function stringToInt(str: string): number {
13
+ return str ? parseInt(Buffer.from(str).toString('hex'), 16) : 0;
14
+ }
15
+
16
+ export function intToString(int: number): string {
17
+ return Buffer.from(int.toString(16), 'hex').toString('utf-8');
18
+ }
19
+
20
+ export function bufferToInt(buf: Buffer): number {
21
+ return buf.readUInt32BE(0);
22
+ }
23
+
24
+ export function intToBuffer(int: number): Buffer {
25
+ return Buffer.from(int.toString(16), 'hex');
26
+ }
27
+
28
+ export function sliceToAddress(slice: Slice): Address {
29
+ const cell = beginCell().storeSlice(slice).endCell();
30
+ return cell.beginParse().loadAddress();
31
+ }
32
+
33
+ export function addressToSlice(address: Address): Slice {
34
+ return beginCell().storeAddress(address).endCell().asSlice();
35
+ }
36
+
37
+ export function stringToBitString(str: string): BitString {
38
+ return new BitString(Buffer.from(str), 0, str.length * 8);
39
+ }
40
+
41
+ export function bitStringToString(bits: BitString, len: number): string {
42
+ const decoder = new TextDecoder();
43
+ const subBuffer = bits.subbuffer(0, len);
44
+
45
+ return subBuffer ? decoder.decode(subBuffer) : '';
46
+ }
47
+
48
+ export function stringToCell(str: string): Cell {
49
+ return beginCell().storeStringTail(str).endCell();
50
+ }
51
+
52
+ export function cellToString(cell: Cell): string {
53
+ return cell.beginParse().loadStringTail();
54
+ }
55
+
56
+ export function stringToCrc32(str: string): number {
57
+ return crc32c(Buffer.from(str)).readUint32BE();
58
+ }
59
+
60
+ export function getContractAddress(code: Cell, data: Cell): Address {
61
+ return contractAddress(0, { code, data });
62
+ }
63
+
64
+ export function arraysToCell(arrays: (Slice | Cell | Address | number)[], bits = 32): Cell {
65
+ const cell = beginCell();
66
+
67
+ arrays.forEach((item) => {
68
+ if (item instanceof Slice) {
69
+ cell.storeSlice(item);
70
+ } else if (item instanceof Cell) {
71
+ cell.storeRef(item);
72
+ } else if (item instanceof Address) {
73
+ cell.storeAddress(item);
74
+ } else if (typeof item === 'number') {
75
+ cell.storeUint(item, bits);
76
+ }
77
+ });
78
+
79
+ return cell.endCell();
80
+ }
81
+
82
+ export function coinsToSlice(coins: string): Slice {
83
+ return beginCell().storeCoins(toNano(coins)).endCell().asSlice();
84
+ }
@@ -0,0 +1,69 @@
1
+ import { Address, beginCell, Cell, Contract, contractAddress, ContractProvider, Sender, toNano } from '@ton/core';
2
+ import { OpCode } from '../utils';
3
+
4
+ export const MIN_CLAIM_FEE = toNano('0.17');
5
+
6
+ export type LeafConfig = {
7
+ used?: boolean;
8
+ distributor: Address;
9
+ index: bigint;
10
+ };
11
+
12
+ export function leafConfigToCell(config: LeafConfig): Cell {
13
+ const { distributor, index } = config;
14
+
15
+ const initState = beginCell().storeBit(false).storeAddress(distributor).storeUint(index, 64).endCell();
16
+
17
+ return initState;
18
+ }
19
+
20
+ export class Leaf implements Contract {
21
+ constructor(readonly address: Address, readonly init?: { code: Cell; data: Cell }) {}
22
+
23
+ static createFromAddress(address: Address) {
24
+ return new Leaf(address);
25
+ }
26
+
27
+ static createFromConfig(config: LeafConfig, code: Cell, workchain = 0) {
28
+ const data = leafConfigToCell(config);
29
+ const init = { code, data };
30
+ return new Leaf(contractAddress(workchain, init), init);
31
+ }
32
+
33
+ async getIsUsed(provider: ContractProvider): Promise<boolean> {
34
+ const result = await provider.get('get_is_used', []);
35
+ const isUsed = result.stack.readNumber();
36
+
37
+ return !!isUsed;
38
+ }
39
+
40
+ async getLeafData(provider: ContractProvider): Promise<LeafConfig> {
41
+ const result = await provider.get('get_leaf_data', []);
42
+ const cellHash = result.stack.readCell().beginParse();
43
+
44
+ const isUsed = cellHash.loadUint(1);
45
+ const distributor = cellHash.loadAddress();
46
+ const index = cellHash.loadUint(64);
47
+
48
+ return {
49
+ used: !!isUsed,
50
+ index: BigInt(index),
51
+ distributor
52
+ };
53
+ }
54
+
55
+ async sendClaim(provider: ContractProvider, via: Sender, proof: Cell, index: bigint, claimFee: bigint) {
56
+ const messageBody = beginCell()
57
+ .storeUint(OpCode.Claim, 32)
58
+ .storeUint(0, 64)
59
+ .storeRef(proof)
60
+ .storeUint(index, 64)
61
+ .endCell();
62
+ const result = await provider.internal(via, {
63
+ value: MIN_CLAIM_FEE + claimFee,
64
+ body: messageBody
65
+ });
66
+
67
+ return result;
68
+ }
69
+ }