Skip to content

Commit c8c0ea2

Browse files
chore: rename token selectors in js (#1612)
* rename * bump
1 parent 25ac4a4 commit c8c0ea2

File tree

6 files changed

+52
-51
lines changed

6 files changed

+52
-51
lines changed

js/compressed-token/CHANGELOG.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## [0.20.5-0.20.7] - 2025-02-24
1+
## [0.20.5-0.20.9] - 2025-02-24
22

33
### Changed
44

@@ -8,21 +8,21 @@
88

99
### Breaking Changes
1010

11-
- `selectSmartCompressedTokenAccountsForTransfer` and
12-
`selectSmartCompressedTokenAccountsForTransferIdempotent` now throw an error
11+
- `selectMinCompressedTokenAccountsForTransfer` and
12+
`selectSmartCompressedTokenAccountsForTransfer` now throw an error
1313
if not enough accounts are found. In most cases this is not a breaking
1414
change, because a proof request would fail anyway. This just makes the error
1515
message more informative.
1616

1717
### Added
1818

1919
- `selectSmartCompressedTokenAccountsForTransfer` and
20-
`selectSmartCompressedTokenAccountsForTransferIdempotent`
20+
`selectSmartCompressedTokenAccountsForTransferorPartial`
2121

2222
### Changed
2323

24-
- `selectSmartCompressedTokenAccountsForTransfer` and
25-
`selectSmartCompressedTokenAccountsForTransferIdempotent` now accept an optional
24+
- `selectMinCompressedTokenAccountsForTransfer` and
25+
`selectMinCompressedTokenAccountsForTransferorPartial` now accept an optional
2626
`maxInputs` parameter, defaulting to 4.
2727

2828
### Security

js/compressed-token/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lightprotocol/compressed-token",
3-
"version": "0.20.7",
3+
"version": "0.20.9",
44
"description": "JS client to interact with the compressed-token program",
55
"sideEffects": false,
66
"main": "dist/cjs/node/index.cjs",

js/compressed-token/src/utils/select-input-accounts.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function selectMinCompressedTokenAccountsForTransfer(
5353
accumulatedAmount,
5454
accumulatedLamports,
5555
maxPossibleAmount,
56-
] = selectMinCompressedTokenAccountsForTransferIdempotent(
56+
] = selectMinCompressedTokenAccountsForTransferOrPartial(
5757
accounts,
5858
transferAmount,
5959
maxInputs,
@@ -88,12 +88,11 @@ export function selectMinCompressedTokenAccountsForTransfer(
8888
}
8989

9090
/**
91-
* Selects the minimal number of compressed token accounts for a transfer idempotently.
92-
*
93-
* 1. Sorts accounts by amount (descending)
94-
* 2. Accumulates amount until it meets or exceeds transfer amount
91+
* Executes {@link selectMinCompressedTokenAccountsForTransfer} strategy,
92+
* returns partial amounts if insufficient accounts are found instead of
93+
* throwing an error.
9594
*/
96-
export function selectMinCompressedTokenAccountsForTransferIdempotent(
95+
export function selectMinCompressedTokenAccountsForTransferOrPartial(
9796
accounts: ParsedTokenAccount[],
9897
transferAmount: BN,
9998
maxInputs: number = 4,
@@ -138,7 +137,7 @@ export function selectMinCompressedTokenAccountsForTransferIdempotent(
138137

139138
if (accumulatedAmount.lt(bn(transferAmount))) {
140139
console.log(
141-
`Insufficient balance for transfer. Requested: ${transferAmount.toString()}, Idempotent returns max available: ${maxPossibleAmount.toString()}.`,
140+
`Insufficient balance for transfer. Requested: ${transferAmount.toString()}, Returns max available: ${maxPossibleAmount.toString()}.`,
142141
);
143142
}
144143

@@ -208,7 +207,7 @@ export function selectSmartCompressedTokenAccountsForTransfer(
208207
accumulatedAmount,
209208
accumulatedLamports,
210209
maxPossibleAmount,
211-
] = selectSmartCompressedTokenAccountsForTransferIdempotent(
210+
] = selectSmartCompressedTokenAccountsForTransferOrPartial(
212211
accounts,
213212
transferAmount,
214213
maxInputs,
@@ -243,9 +242,11 @@ export function selectSmartCompressedTokenAccountsForTransfer(
243242
}
244243

245244
/**
246-
* Idempotently runs {@link selectSmartCompressedTokenAccountsForTransfer} strategy.
245+
* Executes {@link selectMinCompressedTokenAccountsForTransfer} strategy,
246+
* returns partial amounts if insufficient accounts are found instead of
247+
* throwing an error.
247248
*/
248-
export function selectSmartCompressedTokenAccountsForTransferIdempotent(
249+
export function selectSmartCompressedTokenAccountsForTransferOrPartial(
249250
accounts: ParsedTokenAccount[],
250251
transferAmount: BN,
251252
maxInputs: number = 4,

js/compressed-token/tests/e2e/select-accounts.test.ts

+32-32
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { ParsedTokenAccount } from '@lightprotocol/stateless.js';
55

66
import {
77
selectMinCompressedTokenAccountsForTransfer,
8-
selectMinCompressedTokenAccountsForTransferIdempotent,
8+
selectMinCompressedTokenAccountsForTransferOrPartial,
99
selectSmartCompressedTokenAccountsForTransfer,
10-
selectSmartCompressedTokenAccountsForTransferIdempotent,
10+
selectSmartCompressedTokenAccountsForTransferOrPartial,
1111
} from '../../src';
1212
import { ERROR_NO_ACCOUNTS_FOUND } from '../../src/utils/select-input-accounts';
1313

@@ -251,8 +251,8 @@ describe('selectMinCompressedTokenAccountsForTransfer', () => {
251251
});
252252
});
253253

254-
describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
255-
it('min idempotent: should select the largest account for a valid transfer where 1 account is enough', () => {
254+
describe('selectMinCompressedTokenAccountsForTransferorPartial', () => {
255+
it('min orPartial: should select the largest account for a valid transfer where 1 account is enough', () => {
256256
const accounts = [
257257
{
258258
parsed: { amount: new BN(100) },
@@ -270,7 +270,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
270270
const transferAmount = new BN(75);
271271

272272
const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
273-
selectMinCompressedTokenAccountsForTransferIdempotent(
273+
selectMinCompressedTokenAccountsForTransferOrPartial(
274274
accounts,
275275
transferAmount,
276276
);
@@ -281,7 +281,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
281281
expect(maxPossibleAmount.eq(new BN(175))).toBe(true);
282282
});
283283

284-
it('min idempotent: should return the maximum possible amount if there is not enough balance', () => {
284+
it('min orPartial: should return the maximum possible amount if there is not enough balance', () => {
285285
const accounts = [
286286
{
287287
parsed: { amount: new BN(30) },
@@ -291,7 +291,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
291291
const transferAmount = new BN(75);
292292

293293
const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
294-
selectMinCompressedTokenAccountsForTransferIdempotent(
294+
selectMinCompressedTokenAccountsForTransferOrPartial(
295295
accounts,
296296
transferAmount,
297297
);
@@ -302,7 +302,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
302302
expect(maxPossibleAmount.eq(new BN(30))).toBe(true);
303303
});
304304

305-
it('min idempotent: should select multiple accounts if needed', () => {
305+
it('min orPartial: should select multiple accounts if needed', () => {
306306
const accounts = [
307307
{
308308
parsed: { amount: new BN(50) },
@@ -320,7 +320,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
320320
const transferAmount = new BN(75);
321321

322322
const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
323-
selectMinCompressedTokenAccountsForTransferIdempotent(
323+
selectMinCompressedTokenAccountsForTransferOrPartial(
324324
accounts,
325325
transferAmount,
326326
);
@@ -331,19 +331,19 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
331331
expect(maxPossibleAmount.eq(new BN(105))).toBe(true);
332332
});
333333

334-
it('min idempotent: should handle empty accounts array', () => {
334+
it('min orPartial: should handle empty accounts array', () => {
335335
const accounts: ParsedTokenAccount[] = [];
336336
const transferAmount = new BN(75);
337337

338338
expect(() =>
339-
selectMinCompressedTokenAccountsForTransferIdempotent(
339+
selectMinCompressedTokenAccountsForTransferOrPartial(
340340
accounts,
341341
transferAmount,
342342
),
343343
).toThrow(ERROR_NO_ACCOUNTS_FOUND);
344344
});
345345

346-
it('min idempotent: should ignore accounts with zero balance', () => {
346+
it('min orPartial: should ignore accounts with zero balance', () => {
347347
const accounts = [
348348
{
349349
parsed: { amount: new BN(0) },
@@ -361,7 +361,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
361361
const transferAmount = new BN(75);
362362

363363
const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
364-
selectMinCompressedTokenAccountsForTransferIdempotent(
364+
selectMinCompressedTokenAccountsForTransferOrPartial(
365365
accounts,
366366
transferAmount,
367367
);
@@ -372,7 +372,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
372372
expect(maxPossibleAmount.eq(new BN(75))).toBe(true);
373373
});
374374

375-
it('min idempotent: should handle large numbers', () => {
375+
it('min orPartial: should handle large numbers', () => {
376376
const accounts = [
377377
{
378378
parsed: { amount: new BN('1000000000000000000') },
@@ -390,7 +390,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
390390
const transferAmount = new BN('750000000000000000');
391391

392392
const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
393-
selectMinCompressedTokenAccountsForTransferIdempotent(
393+
selectMinCompressedTokenAccountsForTransferOrPartial(
394394
accounts,
395395
transferAmount,
396396
);
@@ -401,7 +401,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
401401
expect(maxPossibleAmount.eq(new BN('1750000000000000000'))).toBe(true);
402402
});
403403

404-
it('min idempotent: should handle max inputs equal to accounts length', () => {
404+
it('min orPartial: should handle max inputs equal to accounts length', () => {
405405
const accounts = [
406406
{
407407
parsed: { amount: new BN(50) },
@@ -424,7 +424,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
424424
const maxInputs = 3;
425425

426426
const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
427-
selectMinCompressedTokenAccountsForTransferIdempotent(
427+
selectMinCompressedTokenAccountsForTransferOrPartial(
428428
accounts,
429429
transferAmount,
430430
maxInputs,
@@ -436,7 +436,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
436436
expect(maxPossibleAmount.eq(new BN(105))).toBe(true);
437437
});
438438

439-
it('min idempotent: should handle max inputs less than accounts length', () => {
439+
it('min orPartial: should handle max inputs less than accounts length', () => {
440440
const accounts = [
441441
{
442442
parsed: { amount: new BN(50) },
@@ -455,7 +455,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
455455
const maxInputs = 2;
456456

457457
const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
458-
selectMinCompressedTokenAccountsForTransferIdempotent(
458+
selectMinCompressedTokenAccountsForTransferOrPartial(
459459
accounts,
460460
transferAmount,
461461
maxInputs,
@@ -467,7 +467,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
467467
expect(maxPossibleAmount.eq(new BN(80))).toBe(true);
468468
});
469469

470-
it('min idempotent: should succeed and select 2 accounts with total 80', () => {
470+
it('min orPartial: should succeed and select 2 accounts with total 80', () => {
471471
const accounts = [
472472
{
473473
parsed: { amount: new BN(50) },
@@ -486,7 +486,7 @@ describe('selectMinCompressedTokenAccountsForTransferIdempotent', () => {
486486
const maxInputs = 2;
487487

488488
const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
489-
selectMinCompressedTokenAccountsForTransferIdempotent(
489+
selectMinCompressedTokenAccountsForTransferOrPartial(
490490
accounts,
491491
transferAmount,
492492
maxInputs,
@@ -766,8 +766,8 @@ describe('selectSmartCompressedTokenAccountsForTransfer', () => {
766766
});
767767
});
768768

769-
describe('selectSmartCompressedTokenAccountsForTransferIdempotent', () => {
770-
it('smart-idempotent: should select 2 accounts for a valid transfer where 1 account is enough', () => {
769+
describe('selectSmartCompressedTokenAccountsForTransferOrPartial', () => {
770+
it('smart-orPartial: should select 2 accounts for a valid transfer where 1 account is enough', () => {
771771
const accounts = [
772772
{
773773
parsed: { amount: new BN(100) },
@@ -785,7 +785,7 @@ describe('selectSmartCompressedTokenAccountsForTransferIdempotent', () => {
785785
const transferAmount = new BN(75);
786786

787787
const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
788-
selectSmartCompressedTokenAccountsForTransferIdempotent(
788+
selectSmartCompressedTokenAccountsForTransferOrPartial(
789789
accounts,
790790
transferAmount,
791791
);
@@ -796,7 +796,7 @@ describe('selectSmartCompressedTokenAccountsForTransferIdempotent', () => {
796796
expect(maxPossibleAmount.eq(new BN(175))).toBe(true);
797797
});
798798

799-
it('smart-idempotent: should return the maximum possible amount if there is not enough balance', () => {
799+
it('smart-orPartial: should return the maximum possible amount if there is not enough balance', () => {
800800
const accounts = [
801801
{
802802
parsed: { amount: new BN(30) },
@@ -806,7 +806,7 @@ describe('selectSmartCompressedTokenAccountsForTransferIdempotent', () => {
806806
const transferAmount = new BN(75);
807807

808808
const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
809-
selectSmartCompressedTokenAccountsForTransferIdempotent(
809+
selectSmartCompressedTokenAccountsForTransferOrPartial(
810810
accounts,
811811
transferAmount,
812812
);
@@ -817,7 +817,7 @@ describe('selectSmartCompressedTokenAccountsForTransferIdempotent', () => {
817817
expect(maxPossibleAmount.eq(new BN(30))).toBe(true);
818818
});
819819

820-
it('smart-idempotent: should select multiple accounts if needed', () => {
820+
it('smart-orPartial: should select multiple accounts if needed', () => {
821821
const accounts = [
822822
{
823823
parsed: { amount: new BN(50) },
@@ -835,7 +835,7 @@ describe('selectSmartCompressedTokenAccountsForTransferIdempotent', () => {
835835
const transferAmount = new BN(75);
836836

837837
const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
838-
selectSmartCompressedTokenAccountsForTransferIdempotent(
838+
selectSmartCompressedTokenAccountsForTransferOrPartial(
839839
accounts,
840840
transferAmount,
841841
);
@@ -846,19 +846,19 @@ describe('selectSmartCompressedTokenAccountsForTransferIdempotent', () => {
846846
expect(maxPossibleAmount.eq(new BN(105))).toBe(true);
847847
});
848848

849-
it('smart-idempotent: should handle empty accounts array', () => {
849+
it('smart-orPartial: should handle empty accounts array', () => {
850850
const accounts: ParsedTokenAccount[] = [];
851851
const transferAmount = new BN(75);
852852

853853
expect(() =>
854-
selectSmartCompressedTokenAccountsForTransferIdempotent(
854+
selectSmartCompressedTokenAccountsForTransferOrPartial(
855855
accounts,
856856
transferAmount,
857857
),
858858
).toThrow(ERROR_NO_ACCOUNTS_FOUND);
859859
});
860860

861-
it('smart-idempotent: should throw if not enough accounts selected because of maxInputs lower than what WOULD be available', () => {
861+
it('smart-orPartial: should throw if not enough accounts selected because of maxInputs lower than what WOULD be available', () => {
862862
const accounts = [
863863
{
864864
parsed: { amount: new BN(50) },
@@ -876,7 +876,7 @@ describe('selectSmartCompressedTokenAccountsForTransferIdempotent', () => {
876876
const transferAmount = new BN(100);
877877
const maxInputs = 2;
878878
const [selectedAccounts, total, totalLamports, maxPossibleAmount] =
879-
selectSmartCompressedTokenAccountsForTransferIdempotent(
879+
selectSmartCompressedTokenAccountsForTransferOrPartial(
880880
accounts,
881881
transferAmount,
882882
maxInputs,

js/stateless.js/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## [0.20.5-0.20.7] - 2025-02-24
3+
## [0.20.5-0.20.9] - 2025-02-24
44

55
### Bumped to latest compressed-token sdk
66

js/stateless.js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lightprotocol/stateless.js",
3-
"version": "0.20.7",
3+
"version": "0.20.9",
44
"description": "JavaScript API for Light & ZK Compression",
55
"sideEffects": false,
66
"main": "dist/cjs/node/index.cjs",

0 commit comments

Comments
 (0)