@triadxyz/triad-protocol 3.2.9-beta → 3.3.1-beta

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/claim.d.ts CHANGED
@@ -49,7 +49,7 @@ export default class Claim {
49
49
  * @param claimVaultName - Claim vault name
50
50
  * @param mint - Mint
51
51
  */
52
- updateClaimVaultAmount({ amount, newUsers, claimVaultName, mint, merkleRoot }: UpdateClaimVaultAmountArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
52
+ updateClaimVaultAmount({ amount, newUsers, claimVaultName, mint, claimData }: UpdateClaimVaultAmountArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
53
53
  /**
54
54
  * Update Claim Vault End Ts
55
55
  * @param endTs - End ts
package/dist/claim.js CHANGED
@@ -94,7 +94,11 @@ class Claim {
94
94
  */
95
95
  createClaimVault({ totalAmount, totalUsers, name, isFirstComeFirstServed, endTs, claimData, mint }) {
96
96
  return __awaiter(this, void 0, void 0, function* () {
97
- const { merkleRoot } = (0, merkle_1.generateMerkleTree)(claimData);
97
+ let merkleRoot = null;
98
+ if (claimData) {
99
+ const { merkleRoot: root } = (0, merkle_1.generateMerkleTree)(claimData);
100
+ merkleRoot = root;
101
+ }
98
102
  const ixs = [
99
103
  yield this.program.methods
100
104
  .createClaimVault({
@@ -141,8 +145,13 @@ class Claim {
141
145
  * @param claimVaultName - Claim vault name
142
146
  * @param mint - Mint
143
147
  */
144
- updateClaimVaultAmount({ amount, newUsers, claimVaultName, mint, merkleRoot }) {
148
+ updateClaimVaultAmount({ amount, newUsers, claimVaultName, mint, claimData }) {
145
149
  return __awaiter(this, void 0, void 0, function* () {
150
+ let merkleRoot = null;
151
+ if (claimData) {
152
+ const { merkleRoot: root } = (0, merkle_1.generateMerkleTree)(claimData);
153
+ merkleRoot = root;
154
+ }
146
155
  const ixs = [
147
156
  yield this.program.methods
148
157
  .updateClaimVaultAmount({
@@ -351,7 +351,7 @@ export type UpdateClaimVaultAmountArgs = {
351
351
  newUsers: number;
352
352
  claimVaultName: string;
353
353
  mint: PublicKey;
354
- merkleRoot: number[];
354
+ claimData: ClaimData[];
355
355
  };
356
356
  export type UpdateClaimVaultEndTsArgs = {
357
357
  endTs: number;
@@ -20,3 +20,16 @@ export declare function createClaimData(data: {
20
20
  user: string;
21
21
  amount: number;
22
22
  }[]): ClaimData[];
23
+ export declare function debugMerkleProof(userPubkey: PublicKey, amount: number, merkleProof: number[][], merkleRoot: number[]): {
24
+ isValid: boolean;
25
+ steps: Array<{
26
+ step: number;
27
+ currentHash: string;
28
+ proofElement: string;
29
+ isCurrentSmaller: boolean;
30
+ combined: string;
31
+ newHash: string;
32
+ }>;
33
+ finalHash: string;
34
+ expectedRoot: string;
35
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createClaimData = exports.generateMerkleTree = exports.MerkleTree = void 0;
3
+ exports.debugMerkleProof = exports.createClaimData = exports.generateMerkleTree = exports.MerkleTree = void 0;
4
4
  const sha3_1 = require("@noble/hashes/sha3");
5
5
  const web3_js_1 = require("@solana/web3.js");
6
6
  class MerkleTree {
@@ -30,7 +30,7 @@ class MerkleTree {
30
30
  for (let i = 0; i < currentLevel.length; i += 2) {
31
31
  const left = currentLevel[i];
32
32
  const right = i + 1 < currentLevel.length ? currentLevel[i + 1] : left;
33
- const combined = left.compare(right) <= 0
33
+ const combined = left.compare(right) < 0
34
34
  ? Buffer.concat([left, right])
35
35
  : Buffer.concat([right, left]);
36
36
  nextLevel.push(Buffer.from((0, sha3_1.keccak_256)(combined)));
@@ -85,7 +85,7 @@ class MerkleTree {
85
85
  let currentHash = Buffer.from((0, sha3_1.keccak_256)(leafData));
86
86
  for (const proofElement of proof) {
87
87
  const proofBuffer = Buffer.from(proofElement);
88
- const combined = currentHash.compare(proofBuffer) <= 0
88
+ const combined = currentHash.compare(proofBuffer) < 0
89
89
  ? Buffer.concat([currentHash, proofBuffer])
90
90
  : Buffer.concat([proofBuffer, currentHash]);
91
91
  currentHash = Buffer.from((0, sha3_1.keccak_256)(combined));
@@ -110,3 +110,64 @@ function createClaimData(data) {
110
110
  }));
111
111
  }
112
112
  exports.createClaimData = createClaimData;
113
+ function debugMerkleProof(userPubkey, amount, merkleProof, merkleRoot) {
114
+ console.log('🔍 Debug Merkle Proof Validation (Rust Compatible)');
115
+ console.log('User:', userPubkey.toBase58());
116
+ console.log('Amount:', amount);
117
+ console.log('Proof length:', merkleProof.length);
118
+ console.log('Max theoretical elements:', Math.pow(2, merkleProof.length));
119
+ const leafData = Buffer.concat([
120
+ userPubkey.toBytes(),
121
+ (() => {
122
+ const amountBytes = Buffer.alloc(8);
123
+ const amountLamports = BigInt(Math.floor(amount * Math.pow(10, 6)));
124
+ amountBytes.writeBigUInt64LE(amountLamports, 0);
125
+ return amountBytes;
126
+ })()
127
+ ]);
128
+ let currentHash = Buffer.from((0, sha3_1.keccak_256)(leafData));
129
+ console.log('Initial leaf hash:', currentHash.toString('hex'));
130
+ const steps = [];
131
+ for (let i = 0; i < merkleProof.length; i++) {
132
+ const proofElement = merkleProof[i];
133
+ const proofBuffer = Buffer.from(proofElement);
134
+ const isCurrentSmaller = currentHash.compare(proofBuffer) < 0;
135
+ let combined;
136
+ if (isCurrentSmaller) {
137
+ combined = Buffer.concat([currentHash, proofBuffer]);
138
+ }
139
+ else {
140
+ combined = Buffer.concat([proofBuffer, currentHash]);
141
+ }
142
+ const newHash = Buffer.from((0, sha3_1.keccak_256)(combined));
143
+ const step = {
144
+ step: i + 1,
145
+ currentHash: currentHash.toString('hex'),
146
+ proofElement: proofBuffer.toString('hex'),
147
+ isCurrentSmaller,
148
+ combined: combined.toString('hex'),
149
+ newHash: newHash.toString('hex')
150
+ };
151
+ steps.push(step);
152
+ console.log(`Step ${i + 1}:`);
153
+ console.log(` Current: ${step.currentHash}`);
154
+ console.log(` Proof: ${step.proofElement}`);
155
+ console.log(` Order: ${isCurrentSmaller ? 'current + proof' : 'proof + current'}`);
156
+ console.log(` Result: ${step.newHash}`);
157
+ currentHash = newHash;
158
+ }
159
+ const rootBuffer = Buffer.from(merkleRoot);
160
+ const finalHash = currentHash.toString('hex');
161
+ const expectedRoot = rootBuffer.toString('hex');
162
+ const isValid = currentHash.equals(rootBuffer);
163
+ console.log('Final hash:', finalHash);
164
+ console.log('Expected root:', expectedRoot);
165
+ console.log('Valid:', isValid);
166
+ return {
167
+ isValid,
168
+ steps,
169
+ finalHash,
170
+ expectedRoot
171
+ };
172
+ }
173
+ exports.debugMerkleProof = debugMerkleProof;
@@ -9,7 +9,7 @@ export declare const swap: ({ connection, wallet, inToken, outToken, amount, pay
9
9
  }) => Promise<{
10
10
  swapIxs: TransactionInstruction[];
11
11
  addressLookupTableAccounts: AddressLookupTableAccount[];
12
- setupInstructions: TransactionInstruction[];
12
+ setupInstructions: any[];
13
13
  outAmount: any;
14
14
  }>;
15
15
  export declare const getPrice: (token: string) => Promise<any>;
@@ -37,7 +37,7 @@ const swap = ({ connection, wallet, inToken, outToken, amount, payer }) => __awa
37
37
  swapIxs: [deserializeInstruction(swapInstruction)],
38
38
  addressLookupTableAccounts: yield getAddressLookupTableAccounts(connection, addressLookupTableAddresses),
39
39
  setupInstructions: setupInstructions.length > 0
40
- ? [deserializeInstruction(setupInstructions)]
40
+ ? [...setupInstructions.map(deserializeInstruction)]
41
41
  : [],
42
42
  outAmount: quoteData.otherAmountThreshold
43
43
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "3.2.9-beta",
3
+ "version": "3.3.1-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",