@veilo/sdk-core 0.3.3 → 0.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/LICENSE +15 -0
- package/README.md +289 -1262
- package/dist/cjs/accounts/admin.d.ts +84 -0
- package/dist/cjs/accounts/admin.js +208 -0
- package/dist/cjs/accounts/errors.d.ts +6 -0
- package/dist/cjs/accounts/errors.js +98 -0
- package/dist/cjs/accounts/index.d.ts +4 -0
- package/dist/cjs/accounts/index.js +20 -0
- package/dist/cjs/accounts/pdas.d.ts +23 -0
- package/dist/cjs/accounts/pdas.js +44 -0
- package/dist/cjs/accounts/queries.d.ts +41 -0
- package/dist/cjs/accounts/queries.js +95 -0
- package/dist/cjs/client.d.ts +2 -407
- package/dist/cjs/client.js +17 -912
- package/dist/cjs/cloak/client.d.ts +28 -0
- package/dist/cjs/cloak/client.js +68 -0
- package/dist/cjs/cloak/errors.d.ts +13 -0
- package/dist/cjs/cloak/errors.js +25 -0
- package/dist/cjs/cloak/helpers.d.ts +6 -0
- package/dist/cjs/cloak/helpers.js +35 -0
- package/dist/cjs/cloak/index.d.ts +6 -0
- package/dist/cjs/cloak/index.js +24 -0
- package/dist/cjs/cloak/polling.d.ts +7 -0
- package/dist/cjs/cloak/polling.js +66 -0
- package/dist/cjs/cloak/transport.d.ts +15 -0
- package/dist/cjs/cloak/transport.js +119 -0
- package/dist/cjs/cloak/types.d.ts +188 -0
- package/dist/cjs/cloak/types.js +5 -0
- package/dist/cjs/cloak.d.ts +1 -0
- package/dist/cjs/cloak.js +18 -0
- package/dist/cjs/compactNote.d.ts +128 -0
- package/dist/cjs/compactNote.js +191 -0
- package/dist/cjs/events.d.ts +1 -1
- package/dist/cjs/events.js +2 -2
- package/dist/cjs/idl/privacy_pool.d.ts +5 -0
- package/dist/cjs/idl/privacy_pool.js +15218 -0
- package/dist/cjs/index.d.ts +17 -13
- package/dist/cjs/index.js +43 -30
- package/dist/cjs/merkle.d.ts +13 -0
- package/dist/cjs/merkle.js +31 -8
- package/dist/cjs/notes/encryption.d.ts +41 -0
- package/dist/cjs/notes/encryption.js +75 -0
- package/dist/cjs/notes/index.d.ts +5 -0
- package/dist/cjs/notes/index.js +21 -0
- package/dist/cjs/notes/mailbox.d.ts +70 -0
- package/dist/cjs/notes/mailbox.js +164 -0
- package/dist/cjs/notes/model.d.ts +91 -0
- package/dist/cjs/notes/model.js +109 -0
- package/dist/cjs/notes/nullifier.d.ts +27 -0
- package/dist/cjs/notes/nullifier.js +45 -0
- package/dist/cjs/notes/recovery.d.ts +10 -0
- package/dist/cjs/notes/recovery.js +31 -0
- package/dist/cjs/program.d.ts +11 -0
- package/dist/cjs/program.js +26 -3
- package/dist/cjs/proof.d.ts +1 -183
- package/dist/cjs/proof.js +16 -290
- package/dist/cjs/proofs/encoding.d.ts +17 -0
- package/dist/cjs/proofs/encoding.js +72 -0
- package/dist/cjs/proofs/formatting.d.ts +6 -0
- package/dist/cjs/proofs/formatting.js +34 -0
- package/dist/cjs/proofs/index.d.ts +5 -0
- package/dist/cjs/proofs/index.js +21 -0
- package/dist/cjs/proofs/swap.d.ts +87 -0
- package/dist/cjs/proofs/swap.js +144 -0
- package/dist/cjs/proofs/transaction.d.ts +28 -0
- package/dist/cjs/proofs/transaction.js +110 -0
- package/dist/cjs/proofs/types.d.ts +70 -0
- package/dist/cjs/proofs/types.js +2 -0
- package/dist/cjs/prover.d.ts +4 -1
- package/dist/cjs/prover.js +12 -2
- package/dist/cjs/random.d.ts +16 -0
- package/dist/cjs/random.js +28 -0
- package/dist/cjs/relayer/client.d.ts +61 -0
- package/dist/cjs/relayer/client.js +151 -0
- package/dist/cjs/relayer/crypto.d.ts +5 -0
- package/dist/cjs/relayer/crypto.js +26 -0
- package/dist/cjs/relayer/encoding.d.ts +2 -0
- package/dist/cjs/relayer/encoding.js +23 -0
- package/dist/cjs/relayer/errors.d.ts +7 -0
- package/dist/cjs/relayer/errors.js +17 -0
- package/dist/cjs/relayer/index.d.ts +3 -0
- package/dist/cjs/relayer/index.js +19 -0
- package/dist/cjs/relayer/transport.d.ts +17 -0
- package/dist/cjs/relayer/transport.js +63 -0
- package/dist/cjs/relayer/types.d.ts +276 -0
- package/dist/cjs/relayer/types.js +5 -0
- package/dist/cjs/relayer.d.ts +1 -295
- package/dist/cjs/relayer.js +15 -243
- package/dist/cjs/shield/alt.d.ts +87 -0
- package/dist/cjs/shield/alt.js +194 -0
- package/dist/cjs/shield/computeBudget.d.ts +61 -0
- package/dist/cjs/shield/computeBudget.js +64 -0
- package/dist/cjs/shield/errors.d.ts +58 -0
- package/dist/cjs/shield/errors.js +121 -0
- package/dist/cjs/shield/finalize.d.ts +45 -0
- package/dist/cjs/shield/finalize.js +119 -0
- package/dist/cjs/shield/index.d.ts +35 -0
- package/dist/cjs/shield/index.js +68 -0
- package/dist/cjs/shield/ix.d.ts +54 -0
- package/dist/cjs/shield/ix.js +119 -0
- package/dist/cjs/shield/owner.d.ts +36 -0
- package/dist/cjs/shield/owner.js +127 -0
- package/dist/cjs/shield/ports.d.ts +43 -0
- package/dist/cjs/shield/ports.js +153 -0
- package/dist/cjs/shield/preflight.d.ts +30 -0
- package/dist/cjs/shield/preflight.js +154 -0
- package/dist/cjs/shield/shield.d.ts +68 -0
- package/dist/cjs/shield/shield.js +500 -0
- package/dist/cjs/shield/types.d.ts +202 -0
- package/dist/cjs/shield/types.js +2 -0
- package/dist/cjs/transactions/deposit.d.ts +94 -0
- package/dist/cjs/transactions/deposit.js +234 -0
- package/dist/cjs/transactions/index.d.ts +7 -0
- package/dist/cjs/transactions/index.js +26 -0
- package/dist/cjs/transactions/swap.d.ts +71 -0
- package/dist/cjs/transactions/swap.js +184 -0
- package/dist/cjs/transactions/transact.d.ts +34 -0
- package/dist/cjs/transactions/transact.js +146 -0
- package/dist/cjs/transactions/transfer.d.ts +51 -0
- package/dist/cjs/transactions/transfer.js +106 -0
- package/dist/cjs/transactions/withdraw.d.ts +52 -0
- package/dist/cjs/transactions/withdraw.js +104 -0
- package/dist/cjs/utxo.d.ts +1 -215
- package/dist/cjs/utxo.js +15 -391
- package/dist/esm/accounts/admin.d.ts +84 -0
- package/dist/esm/accounts/admin.js +165 -0
- package/dist/esm/accounts/errors.d.ts +6 -0
- package/dist/esm/accounts/errors.js +95 -0
- package/dist/esm/accounts/index.d.ts +4 -0
- package/dist/esm/accounts/index.js +4 -0
- package/dist/esm/accounts/pdas.d.ts +23 -0
- package/dist/esm/accounts/pdas.js +38 -0
- package/dist/esm/accounts/queries.d.ts +41 -0
- package/dist/esm/accounts/queries.js +88 -0
- package/dist/esm/client.d.ts +2 -0
- package/dist/esm/client.js +3 -887
- package/dist/esm/cloak/client.d.ts +28 -0
- package/dist/esm/cloak/client.js +64 -0
- package/dist/esm/cloak/errors.d.ts +13 -0
- package/dist/esm/cloak/errors.js +21 -0
- package/dist/esm/cloak/helpers.d.ts +6 -0
- package/dist/esm/cloak/helpers.js +31 -0
- package/dist/esm/cloak/index.d.ts +6 -0
- package/dist/esm/cloak/index.js +6 -0
- package/dist/esm/cloak/polling.d.ts +7 -0
- package/dist/esm/cloak/polling.js +63 -0
- package/dist/esm/cloak/transport.d.ts +15 -0
- package/dist/esm/cloak/transport.js +115 -0
- package/dist/esm/cloak/types.d.ts +188 -0
- package/dist/esm/cloak/types.js +4 -0
- package/dist/esm/cloak.d.ts +1 -0
- package/dist/esm/cloak.js +2 -0
- package/dist/esm/compactNote.d.ts +128 -0
- package/dist/esm/compactNote.js +179 -0
- package/dist/esm/config.d.ts +82 -0
- package/dist/esm/events.d.ts +77 -0
- package/dist/esm/events.js +1 -1
- package/dist/esm/idl/privacy_pool.d.ts +5 -0
- package/dist/esm/idl/privacy_pool.js +15216 -0
- package/dist/esm/index.d.ts +17 -0
- package/dist/esm/index.js +20 -11
- package/dist/esm/merkle.d.ts +77 -0
- package/dist/esm/merkle.js +23 -1
- package/dist/esm/notes/encryption.d.ts +41 -0
- package/dist/esm/notes/encryption.js +67 -0
- package/dist/esm/notes/index.d.ts +5 -0
- package/dist/esm/notes/index.js +5 -0
- package/dist/esm/notes/mailbox.d.ts +70 -0
- package/dist/esm/notes/mailbox.js +154 -0
- package/dist/esm/notes/model.d.ts +91 -0
- package/dist/esm/notes/model.js +99 -0
- package/dist/esm/notes/nullifier.d.ts +27 -0
- package/dist/esm/notes/nullifier.js +40 -0
- package/dist/esm/notes/recovery.d.ts +10 -0
- package/dist/esm/notes/recovery.js +28 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/poseidon.d.ts +29 -0
- package/dist/esm/program.d.ts +37 -0
- package/dist/esm/program.js +23 -1
- package/dist/esm/proof.d.ts +1 -0
- package/dist/esm/proof.js +2 -281
- package/dist/esm/proofs/encoding.d.ts +17 -0
- package/dist/esm/proofs/encoding.js +68 -0
- package/dist/esm/proofs/formatting.d.ts +6 -0
- package/dist/esm/proofs/formatting.js +31 -0
- package/dist/esm/proofs/index.d.ts +5 -0
- package/dist/esm/proofs/index.js +5 -0
- package/dist/esm/proofs/swap.d.ts +87 -0
- package/dist/esm/proofs/swap.js +138 -0
- package/dist/esm/proofs/transaction.d.ts +28 -0
- package/dist/esm/proofs/transaction.js +105 -0
- package/dist/esm/proofs/types.d.ts +70 -0
- package/dist/esm/proofs/types.js +1 -0
- package/dist/esm/prover.d.ts +57 -0
- package/dist/esm/prover.js +10 -1
- package/dist/esm/random.d.ts +16 -0
- package/dist/esm/random.js +21 -0
- package/dist/esm/relayer/client.d.ts +61 -0
- package/dist/esm/relayer/client.js +144 -0
- package/dist/esm/relayer/crypto.d.ts +5 -0
- package/dist/esm/relayer/crypto.js +20 -0
- package/dist/esm/relayer/encoding.d.ts +2 -0
- package/dist/esm/relayer/encoding.js +19 -0
- package/dist/esm/relayer/errors.d.ts +7 -0
- package/dist/esm/relayer/errors.js +13 -0
- package/dist/esm/relayer/index.d.ts +3 -0
- package/dist/esm/relayer/index.js +3 -0
- package/dist/esm/relayer/transport.d.ts +17 -0
- package/dist/esm/relayer/transport.js +59 -0
- package/dist/esm/relayer/types.d.ts +276 -0
- package/dist/esm/relayer/types.js +4 -0
- package/dist/esm/relayer.d.ts +1 -0
- package/dist/esm/relayer.js +2 -238
- package/dist/esm/retry.d.ts +32 -0
- package/dist/esm/shield/alt.d.ts +87 -0
- package/dist/esm/shield/alt.js +186 -0
- package/dist/esm/shield/computeBudget.d.ts +61 -0
- package/dist/esm/shield/computeBudget.js +61 -0
- package/dist/esm/shield/errors.d.ts +58 -0
- package/dist/esm/shield/errors.js +115 -0
- package/dist/esm/shield/finalize.d.ts +45 -0
- package/dist/esm/shield/finalize.js +83 -0
- package/dist/esm/shield/index.d.ts +35 -0
- package/dist/esm/shield/index.js +32 -0
- package/dist/esm/shield/ix.d.ts +54 -0
- package/dist/esm/shield/ix.js +82 -0
- package/dist/esm/shield/owner.d.ts +36 -0
- package/dist/esm/shield/owner.js +123 -0
- package/dist/esm/shield/ports.d.ts +43 -0
- package/dist/esm/shield/ports.js +147 -0
- package/dist/esm/shield/preflight.d.ts +30 -0
- package/dist/esm/shield/preflight.js +151 -0
- package/dist/esm/shield/shield.d.ts +68 -0
- package/dist/esm/shield/shield.js +493 -0
- package/dist/esm/shield/types.d.ts +202 -0
- package/dist/esm/shield/types.js +1 -0
- package/dist/esm/transactions/deposit.d.ts +94 -0
- package/dist/esm/transactions/deposit.js +198 -0
- package/dist/esm/transactions/index.d.ts +7 -0
- package/dist/esm/transactions/index.js +7 -0
- package/dist/esm/transactions/swap.d.ts +71 -0
- package/dist/esm/transactions/swap.js +144 -0
- package/dist/esm/transactions/transact.d.ts +34 -0
- package/dist/esm/transactions/transact.js +110 -0
- package/dist/esm/transactions/transfer.d.ts +51 -0
- package/dist/esm/transactions/transfer.js +103 -0
- package/dist/esm/transactions/withdraw.d.ts +52 -0
- package/dist/esm/transactions/withdraw.js +101 -0
- package/dist/esm/utxo.d.ts +1 -0
- package/dist/esm/utxo.js +2 -372
- package/package.json +111 -15
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor";
|
|
2
|
+
import type { Program, Idl } from "@coral-xyz/anchor";
|
|
3
|
+
import { Keypair, PublicKey } from "@solana/web3.js";
|
|
4
|
+
import type { PrivacyConfigAccount } from "../config.js";
|
|
5
|
+
/**
|
|
6
|
+
* Initialize the global config (one-time setup).
|
|
7
|
+
*/
|
|
8
|
+
export declare function initializeGlobalConfig<T extends Idl>(params: {
|
|
9
|
+
program: Program<T>;
|
|
10
|
+
admin: anchor.Wallet;
|
|
11
|
+
payer: Keypair;
|
|
12
|
+
}): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Initialize a privacy pool with the new parameters.
|
|
15
|
+
* Creates the first merkle tree (tree ID 0).
|
|
16
|
+
*/
|
|
17
|
+
export declare function initializePool<T extends Idl>(params: {
|
|
18
|
+
program: Program<T>;
|
|
19
|
+
admin: anchor.Wallet;
|
|
20
|
+
payer: Keypair;
|
|
21
|
+
feeBps: number;
|
|
22
|
+
mintAddress: PublicKey;
|
|
23
|
+
minDepositAmount?: bigint;
|
|
24
|
+
maxDepositAmount?: bigint;
|
|
25
|
+
minWithdrawAmount?: bigint;
|
|
26
|
+
maxWithdrawAmount?: bigint;
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Update pool configuration.
|
|
30
|
+
*/
|
|
31
|
+
export declare function updatePoolConfig<T extends Idl>(params: {
|
|
32
|
+
program: Program<T>;
|
|
33
|
+
admin: anchor.Wallet;
|
|
34
|
+
mintAddress: PublicKey;
|
|
35
|
+
minDepositAmount?: bigint;
|
|
36
|
+
maxDepositAmount?: bigint;
|
|
37
|
+
minWithdrawAmount?: bigint;
|
|
38
|
+
maxWithdrawAmount?: bigint;
|
|
39
|
+
feeBps?: number;
|
|
40
|
+
feeErrorMarginBps?: number;
|
|
41
|
+
minWithdrawalFee?: bigint;
|
|
42
|
+
minSwapFee?: bigint;
|
|
43
|
+
swapFeeBps?: number;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Add a new Merkle tree to the pool.
|
|
47
|
+
* The treeId must equal the current num_trees value in the pool config.
|
|
48
|
+
*/
|
|
49
|
+
export declare function addMerkleTree<T extends Idl>(params: {
|
|
50
|
+
program: Program<T>;
|
|
51
|
+
relayer: Keypair;
|
|
52
|
+
mintAddress: PublicKey;
|
|
53
|
+
treeId: number;
|
|
54
|
+
}): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Get the pool configuration account.
|
|
57
|
+
*/
|
|
58
|
+
export declare function getPoolConfig<T extends Idl>(program: Program<T>, mintAddress: PublicKey): Promise<PrivacyConfigAccount>;
|
|
59
|
+
/**
|
|
60
|
+
* Add a relayer to the pool.
|
|
61
|
+
*/
|
|
62
|
+
export declare function addRelayer<T extends Idl>(params: {
|
|
63
|
+
program: Program<T>;
|
|
64
|
+
admin: anchor.Wallet;
|
|
65
|
+
mintAddress: PublicKey;
|
|
66
|
+
newRelayer: PublicKey;
|
|
67
|
+
}): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Set the paused state of a pool.
|
|
70
|
+
*/
|
|
71
|
+
export declare function setPaused<T extends Idl>(params: {
|
|
72
|
+
program: Program<T>;
|
|
73
|
+
admin: anchor.Wallet;
|
|
74
|
+
mintAddress: PublicKey;
|
|
75
|
+
paused: boolean;
|
|
76
|
+
}): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Update the global config.
|
|
79
|
+
* Currently takes no extra args — only admin verification.
|
|
80
|
+
*/
|
|
81
|
+
export declare function updateGlobalConfig<T extends Idl>(params: {
|
|
82
|
+
program: Program<T>;
|
|
83
|
+
admin: anchor.Wallet;
|
|
84
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import * as anchor from "@coral-xyz/anchor";
|
|
2
|
+
import { SystemProgram } from "@solana/web3.js";
|
|
3
|
+
import { getGlobalConfigPda, getNoteTreePda, getPoolPdas } from "./pdas.js";
|
|
4
|
+
// Anchor is CJS and does not expose BN as a detectable Node ESM named export.
|
|
5
|
+
const { BN } = anchor;
|
|
6
|
+
// -----------------------------------------------------------------------------
|
|
7
|
+
// Global Config Initialization
|
|
8
|
+
// -----------------------------------------------------------------------------
|
|
9
|
+
/**
|
|
10
|
+
* Initialize the global config (one-time setup).
|
|
11
|
+
*/
|
|
12
|
+
export async function initializeGlobalConfig(params) {
|
|
13
|
+
const { program, admin, payer } = params;
|
|
14
|
+
const globalConfig = getGlobalConfigPda(program.programId);
|
|
15
|
+
await program.methods
|
|
16
|
+
.initializeGlobalConfig()
|
|
17
|
+
.accounts({
|
|
18
|
+
globalConfig,
|
|
19
|
+
admin: admin.publicKey,
|
|
20
|
+
payer: payer.publicKey,
|
|
21
|
+
systemProgram: SystemProgram.programId,
|
|
22
|
+
})
|
|
23
|
+
.signers([payer])
|
|
24
|
+
.rpc();
|
|
25
|
+
}
|
|
26
|
+
// -----------------------------------------------------------------------------
|
|
27
|
+
// Pool Initialization
|
|
28
|
+
// -----------------------------------------------------------------------------
|
|
29
|
+
/**
|
|
30
|
+
* Initialize a privacy pool with the new parameters.
|
|
31
|
+
* Creates the first merkle tree (tree ID 0).
|
|
32
|
+
*/
|
|
33
|
+
export async function initializePool(params) {
|
|
34
|
+
const { program, admin, payer, feeBps, mintAddress, minDepositAmount, maxDepositAmount, minWithdrawAmount, maxWithdrawAmount, } = params;
|
|
35
|
+
const { config, vault, nullifiers } = getPoolPdas(program.programId, mintAddress);
|
|
36
|
+
const noteTree = getNoteTreePda(program.programId, mintAddress, 0);
|
|
37
|
+
await program.methods
|
|
38
|
+
.initialize(feeBps, mintAddress, minDepositAmount ? new BN(minDepositAmount.toString()) : null, maxDepositAmount ? new BN(maxDepositAmount.toString()) : null, minWithdrawAmount ? new BN(minWithdrawAmount.toString()) : null, maxWithdrawAmount ? new BN(maxWithdrawAmount.toString()) : null)
|
|
39
|
+
.accounts({
|
|
40
|
+
config,
|
|
41
|
+
vault,
|
|
42
|
+
noteTree,
|
|
43
|
+
nullifiers,
|
|
44
|
+
admin: admin.publicKey,
|
|
45
|
+
payer: payer.publicKey,
|
|
46
|
+
systemProgram: SystemProgram.programId,
|
|
47
|
+
})
|
|
48
|
+
.signers([payer])
|
|
49
|
+
.rpc();
|
|
50
|
+
}
|
|
51
|
+
// -----------------------------------------------------------------------------
|
|
52
|
+
// Pool Config Updates
|
|
53
|
+
// -----------------------------------------------------------------------------
|
|
54
|
+
/**
|
|
55
|
+
* Update pool configuration.
|
|
56
|
+
*/
|
|
57
|
+
export async function updatePoolConfig(params) {
|
|
58
|
+
const { program, admin, mintAddress, minDepositAmount, maxDepositAmount, minWithdrawAmount, maxWithdrawAmount, feeBps, feeErrorMarginBps, minWithdrawalFee, minSwapFee, swapFeeBps, } = params;
|
|
59
|
+
const { config } = getPoolPdas(program.programId, mintAddress);
|
|
60
|
+
await program.methods
|
|
61
|
+
.updatePoolConfig(mintAddress, minDepositAmount ? new BN(minDepositAmount.toString()) : null, maxDepositAmount ? new BN(maxDepositAmount.toString()) : null, minWithdrawAmount ? new BN(minWithdrawAmount.toString()) : null, maxWithdrawAmount ? new BN(maxWithdrawAmount.toString()) : null, feeBps != null ? new BN(feeBps) : null, minWithdrawalFee ? new BN(minWithdrawalFee.toString()) : null, feeErrorMarginBps != null ? new BN(feeErrorMarginBps) : null, minSwapFee ? new BN(minSwapFee.toString()) : null, swapFeeBps != null ? new BN(swapFeeBps) : null)
|
|
62
|
+
.accounts({
|
|
63
|
+
config,
|
|
64
|
+
admin: admin.publicKey,
|
|
65
|
+
})
|
|
66
|
+
.rpc();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Add a new Merkle tree to the pool.
|
|
70
|
+
* The treeId must equal the current num_trees value in the pool config.
|
|
71
|
+
*/
|
|
72
|
+
export async function addMerkleTree(params) {
|
|
73
|
+
const { program, relayer, mintAddress, treeId } = params;
|
|
74
|
+
const { config } = getPoolPdas(program.programId, mintAddress);
|
|
75
|
+
const noteTree = getNoteTreePda(program.programId, mintAddress, treeId);
|
|
76
|
+
await program.methods
|
|
77
|
+
.addMerkleTree(mintAddress, treeId)
|
|
78
|
+
.accounts({
|
|
79
|
+
config,
|
|
80
|
+
noteTree,
|
|
81
|
+
relayer: relayer.publicKey,
|
|
82
|
+
systemProgram: SystemProgram.programId,
|
|
83
|
+
})
|
|
84
|
+
.signers([relayer])
|
|
85
|
+
.rpc();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the pool configuration account.
|
|
89
|
+
*/
|
|
90
|
+
export async function getPoolConfig(program, mintAddress) {
|
|
91
|
+
const { config } = getPoolPdas(program.programId, mintAddress);
|
|
92
|
+
const account = await program.account.privacyConfig.fetch(config);
|
|
93
|
+
return {
|
|
94
|
+
bump: account.bump,
|
|
95
|
+
vaultBump: account.vaultBump,
|
|
96
|
+
admin: account.admin,
|
|
97
|
+
feeBps: account.feeBps,
|
|
98
|
+
feeErrorMarginBps: account.feeErrorMarginBps,
|
|
99
|
+
minWithdrawalFee: BigInt(account.minWithdrawalFee.toString()),
|
|
100
|
+
minSwapFee: account.minSwapFee != null ? BigInt(account.minSwapFee.toString()) : 0n,
|
|
101
|
+
swapFeeBps: account.swapFeeBps ?? 0,
|
|
102
|
+
totalTvl: BigInt(account.totalTvl.toString()),
|
|
103
|
+
mintAddress: account.mintAddress,
|
|
104
|
+
minDepositAmount: BigInt(account.minDepositAmount.toString()),
|
|
105
|
+
maxDepositAmount: BigInt(account.maxDepositAmount.toString()),
|
|
106
|
+
minWithdrawAmount: BigInt(account.minWithdrawAmount.toString()),
|
|
107
|
+
maxWithdrawAmount: BigInt(account.maxWithdrawAmount.toString()),
|
|
108
|
+
numRelayers: account.numRelayers,
|
|
109
|
+
relayers: account.relayers,
|
|
110
|
+
numTrees: account.numTrees,
|
|
111
|
+
nextTreeIndex: account.nextTreeIndex,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// -----------------------------------------------------------------------------
|
|
115
|
+
// Relayer Management
|
|
116
|
+
// -----------------------------------------------------------------------------
|
|
117
|
+
/**
|
|
118
|
+
* Add a relayer to the pool.
|
|
119
|
+
*/
|
|
120
|
+
export async function addRelayer(params) {
|
|
121
|
+
const { program, admin, mintAddress, newRelayer } = params;
|
|
122
|
+
const { config } = getPoolPdas(program.programId, mintAddress);
|
|
123
|
+
await program.methods
|
|
124
|
+
.addRelayer(mintAddress, newRelayer)
|
|
125
|
+
.accounts({
|
|
126
|
+
config,
|
|
127
|
+
admin: admin.publicKey,
|
|
128
|
+
})
|
|
129
|
+
.rpc();
|
|
130
|
+
}
|
|
131
|
+
// -----------------------------------------------------------------------------
|
|
132
|
+
// Pause/Unpause
|
|
133
|
+
// -----------------------------------------------------------------------------
|
|
134
|
+
/**
|
|
135
|
+
* Set the paused state of a pool.
|
|
136
|
+
*/
|
|
137
|
+
export async function setPaused(params) {
|
|
138
|
+
const { program, admin, mintAddress, paused } = params;
|
|
139
|
+
const { config } = getPoolPdas(program.programId, mintAddress);
|
|
140
|
+
await program.methods
|
|
141
|
+
.setPaused(mintAddress, paused)
|
|
142
|
+
.accounts({
|
|
143
|
+
config,
|
|
144
|
+
admin: admin.publicKey,
|
|
145
|
+
})
|
|
146
|
+
.rpc();
|
|
147
|
+
}
|
|
148
|
+
// -----------------------------------------------------------------------------
|
|
149
|
+
// Global Config
|
|
150
|
+
// -----------------------------------------------------------------------------
|
|
151
|
+
/**
|
|
152
|
+
* Update the global config.
|
|
153
|
+
* Currently takes no extra args — only admin verification.
|
|
154
|
+
*/
|
|
155
|
+
export async function updateGlobalConfig(params) {
|
|
156
|
+
const { program, admin } = params;
|
|
157
|
+
const globalConfig = getGlobalConfigPda(program.programId);
|
|
158
|
+
await program.methods
|
|
159
|
+
.updateGlobalConfig()
|
|
160
|
+
.accounts({
|
|
161
|
+
globalConfig,
|
|
162
|
+
admin: admin.publicKey,
|
|
163
|
+
})
|
|
164
|
+
.rpc();
|
|
165
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a Solana/Anchor transaction error into a user-friendly message.
|
|
3
|
+
* Maps privacy_pool program error codes (6000–6060) to readable strings.
|
|
4
|
+
* Mirrors relayer-server/src/controllers/transaction.helpers.ts `parseOnChainError`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseOnChainError(error: any): string;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Program error normalization is dependency-free by design.
|
|
2
|
+
// -----------------------------------------------------------------------------
|
|
3
|
+
// Error Parsing
|
|
4
|
+
// -----------------------------------------------------------------------------
|
|
5
|
+
/**
|
|
6
|
+
* Convert a Solana/Anchor transaction error into a user-friendly message.
|
|
7
|
+
* Maps privacy_pool program error codes (6000–6060) to readable strings.
|
|
8
|
+
* Mirrors relayer-server/src/controllers/transaction.helpers.ts `parseOnChainError`.
|
|
9
|
+
*/
|
|
10
|
+
export function parseOnChainError(error) {
|
|
11
|
+
const raw = (error?.message ?? error?.toString() ?? "").toLowerCase();
|
|
12
|
+
const hexMatch = raw.match(/custom program error:\s*0x([0-9a-f]+)/);
|
|
13
|
+
const numMatch = raw.match(/error number:\s*(\d+)/);
|
|
14
|
+
const code = hexMatch
|
|
15
|
+
? parseInt(hexMatch[1], 16)
|
|
16
|
+
: numMatch
|
|
17
|
+
? parseInt(numMatch[1], 10)
|
|
18
|
+
: null;
|
|
19
|
+
const PROGRAM_ERRORS = {
|
|
20
|
+
6000: "The pool is temporarily paused. Please try again later.",
|
|
21
|
+
6001: "No denominations configured for this pool.",
|
|
22
|
+
6002: "Too many denominations configured.",
|
|
23
|
+
6003: "Bad denomination index.",
|
|
24
|
+
6004: "Math overflow in the contract. Please try again.",
|
|
25
|
+
6005: "These funds have already been spent.",
|
|
26
|
+
6006: "The nullifier table is full. Please contact support.",
|
|
27
|
+
6007: "The relayer is out of sync with the network. Please wait a moment and try again.",
|
|
28
|
+
6008: "This relayer is not authorised for this pool.",
|
|
29
|
+
6009: "The pool does not have enough funds to fulfil this request.",
|
|
30
|
+
6010: "Too many relayers registered for this pool.",
|
|
31
|
+
6011: "Proof encoding is invalid. Please try again.",
|
|
32
|
+
6012: "Zero-knowledge proof verification failed. Please try again.",
|
|
33
|
+
6013: "The pool is at capacity. Please try again later.",
|
|
34
|
+
6014: "Merkle hash computation failed. Please try again.",
|
|
35
|
+
6015: "Transaction data mismatch. Please refresh and try again.",
|
|
36
|
+
6016: "Recipient address mismatch.",
|
|
37
|
+
6017: "Invalid token address.",
|
|
38
|
+
6018: "The fee exceeds the allowed limit.",
|
|
39
|
+
6019: "The relayer fee was insufficient. Please try again.",
|
|
40
|
+
6020: "Arithmetic error in the contract. Please try again.",
|
|
41
|
+
6021: "Your balance is not enough to cover the withdrawal including network fees.",
|
|
42
|
+
6022: "Your balance is not enough to cover the fee.",
|
|
43
|
+
6023: "Invalid transaction amount. Please try again.",
|
|
44
|
+
6024: "Invalid fee amount. Please try again.",
|
|
45
|
+
6025: "Duplicate fund inputs detected. Please refresh and try again.",
|
|
46
|
+
6026: "Duplicate output detected. Please refresh and try again.",
|
|
47
|
+
6027: "Token account required for SPL token operations.",
|
|
48
|
+
6028: "Token program required for SPL token operations.",
|
|
49
|
+
6029: "Invalid token account authority.",
|
|
50
|
+
6030: "Relayer account does not match the expected relayer.",
|
|
51
|
+
6031: "Relayer token account not owned by the expected relayer.",
|
|
52
|
+
6032: "Recipient token account not owned by the expected recipient.",
|
|
53
|
+
6033: "Depositor token account not owned or delegated to the relayer.",
|
|
54
|
+
6034: "Private transfers must have zero fee and refund.",
|
|
55
|
+
6035: "Amount is below the pool minimum.",
|
|
56
|
+
6036: "Amount exceeds the pool maximum.",
|
|
57
|
+
6037: "Withdrawal amount is below the pool minimum.",
|
|
58
|
+
6038: "Withdrawal amount exceeds the pool maximum.",
|
|
59
|
+
6039: "Invalid pool configuration: minimum exceeds maximum.",
|
|
60
|
+
6040: "Fee basis points exceed the maximum allowed (1%).",
|
|
61
|
+
6041: "Fee error margin exceeds the maximum allowed (50%).",
|
|
62
|
+
6042: "Only the authorized admin can initialize.",
|
|
63
|
+
6043: "Unauthorized: only admin or relayers can perform this action.",
|
|
64
|
+
6044: "Invalid tree ID: tree does not exist.",
|
|
65
|
+
6045: "Maximum number of Merkle trees reached for this pool.",
|
|
66
|
+
6046: "Deposits must use zero nullifiers (no notes consumed).",
|
|
67
|
+
6047: "Nullifier cannot be zero for withdrawals or transfers.",
|
|
68
|
+
6048: "Output commitment cannot be zero.",
|
|
69
|
+
6049: "Token account must be owned by SPL Token Program.",
|
|
70
|
+
6050: "Vault token account must be the canonical Associated Token Account.",
|
|
71
|
+
6051: "Amount is too small to cover the minimum fee. Try a larger amount.",
|
|
72
|
+
6052: "Nullifier marker account does not correspond to zero nullifier for deposits.",
|
|
73
|
+
6053: "Insufficient token delegation for deposit.",
|
|
74
|
+
6054: "Invalid swap program. Please try again.",
|
|
75
|
+
6055: "Invalid swap accounts. Please refresh and try again.",
|
|
76
|
+
6056: "Jupiter swap requires additional routing accounts.",
|
|
77
|
+
6057: "Swap instruction is invalid or unsupported. Please try again.",
|
|
78
|
+
6058: "Swap parameters are inconsistent. Please refresh and try again.",
|
|
79
|
+
6059: "Missing required swap instructions in transaction. Both fund_native_source and transact_swap must be present.",
|
|
80
|
+
6060: "The transaction deadline expired. Please try again.",
|
|
81
|
+
};
|
|
82
|
+
if (code !== null && PROGRAM_ERRORS[code])
|
|
83
|
+
return PROGRAM_ERRORS[code];
|
|
84
|
+
if (raw.includes("blockhash not found") ||
|
|
85
|
+
raw.includes("block height exceeded"))
|
|
86
|
+
return "The transaction expired before it could be confirmed. Please try again.";
|
|
87
|
+
if (raw.includes("insufficient funds") ||
|
|
88
|
+
raw.includes("insufficient lamports"))
|
|
89
|
+
return "Insufficient SOL to pay for the transaction fee.";
|
|
90
|
+
if (raw.includes("timeout") || raw.includes("timed out"))
|
|
91
|
+
return "The request timed out. Please try again.";
|
|
92
|
+
if (raw.includes("simulation failed"))
|
|
93
|
+
return "Transaction simulation failed. Please refresh and try again.";
|
|
94
|
+
return "The transaction could not be completed. Your funds are safe — please try again.";
|
|
95
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get pool PDAs for a given mint address.
|
|
4
|
+
* Note: All seeds use "v3" suffix.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getPoolPdas(programId: PublicKey, mintAddress: PublicKey): {
|
|
7
|
+
config: PublicKey;
|
|
8
|
+
vault: PublicKey;
|
|
9
|
+
nullifiers: PublicKey;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Get the note tree PDA for a specific tree ID.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getNoteTreePda(programId: PublicKey, mintAddress: PublicKey, treeId: number): PublicKey;
|
|
15
|
+
/**
|
|
16
|
+
* Get the global config PDA.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getGlobalConfigPda(programId: PublicKey): PublicKey;
|
|
19
|
+
/**
|
|
20
|
+
* Get the nullifier marker PDA for a specific nullifier.
|
|
21
|
+
* NOTE: Nullifier markers are global (no tree_id) to prevent cross-tree double-spend.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getNullifierMarkerPda(programId: PublicKey, mintAddress: PublicKey, nullifier: Uint8Array): PublicKey;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
// -----------------------------------------------------------------------------
|
|
3
|
+
// PDA Helpers
|
|
4
|
+
// -----------------------------------------------------------------------------
|
|
5
|
+
/**
|
|
6
|
+
* Get pool PDAs for a given mint address.
|
|
7
|
+
* Note: All seeds use "v3" suffix.
|
|
8
|
+
*/
|
|
9
|
+
export function getPoolPdas(programId, mintAddress) {
|
|
10
|
+
const [config] = PublicKey.findProgramAddressSync([Buffer.from("privacy_config_v3"), mintAddress.toBuffer()], programId);
|
|
11
|
+
const [vault] = PublicKey.findProgramAddressSync([Buffer.from("privacy_vault_v3"), mintAddress.toBuffer()], programId);
|
|
12
|
+
const [nullifiers] = PublicKey.findProgramAddressSync([Buffer.from("privacy_nullifiers_v3"), mintAddress.toBuffer()], programId);
|
|
13
|
+
return { config, vault, nullifiers };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get the note tree PDA for a specific tree ID.
|
|
17
|
+
*/
|
|
18
|
+
export function getNoteTreePda(programId, mintAddress, treeId) {
|
|
19
|
+
const treeIdBuffer = Buffer.alloc(2);
|
|
20
|
+
treeIdBuffer.writeUInt16LE(treeId);
|
|
21
|
+
const [noteTree] = PublicKey.findProgramAddressSync([Buffer.from("privacy_note_tree_v3"), mintAddress.toBuffer(), treeIdBuffer], programId);
|
|
22
|
+
return noteTree;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the global config PDA.
|
|
26
|
+
*/
|
|
27
|
+
export function getGlobalConfigPda(programId) {
|
|
28
|
+
const [globalConfig] = PublicKey.findProgramAddressSync([Buffer.from("global_config_v1")], programId);
|
|
29
|
+
return globalConfig;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get the nullifier marker PDA for a specific nullifier.
|
|
33
|
+
* NOTE: Nullifier markers are global (no tree_id) to prevent cross-tree double-spend.
|
|
34
|
+
*/
|
|
35
|
+
export function getNullifierMarkerPda(programId, mintAddress, nullifier) {
|
|
36
|
+
const [marker] = PublicKey.findProgramAddressSync([Buffer.from("nullifier_v3"), mintAddress.toBuffer(), nullifier], programId);
|
|
37
|
+
return marker;
|
|
38
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Program, Idl } from "@coral-xyz/anchor";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import type { PrivacyConfigAccount } from "../config.js";
|
|
4
|
+
/**
|
|
5
|
+
* Fetch and decode the on-chain PrivacyConfig account for a pool.
|
|
6
|
+
*/
|
|
7
|
+
export declare function fetchPoolConfig<T extends Idl>(program: Program<T>, mintAddress: PublicKey): Promise<PrivacyConfigAccount>;
|
|
8
|
+
/**
|
|
9
|
+
* Check whether a nullifier has been spent on-chain.
|
|
10
|
+
* Returns true if the nullifier marker PDA exists (funds already spent).
|
|
11
|
+
*/
|
|
12
|
+
export declare function checkNullifierSpent<T extends Idl>(program: Program<T>, mintAddress: PublicKey, nullifier: Uint8Array): Promise<boolean>;
|
|
13
|
+
/** On-chain tree utilization info */
|
|
14
|
+
export type TreeInfo = {
|
|
15
|
+
treeId: number;
|
|
16
|
+
leafCount: number;
|
|
17
|
+
capacity: number;
|
|
18
|
+
utilizationPercent: number;
|
|
19
|
+
remainingCapacity: number;
|
|
20
|
+
isFull: boolean;
|
|
21
|
+
treePDA: PublicKey;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Fetch utilization info for a specific tree.
|
|
25
|
+
* Returns null if the tree does not exist yet.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getTreeInfo<T extends Idl>(program: Program<T>, mintAddress: PublicKey, treeId: number): Promise<TreeInfo | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Fetch utilization info for all trees in a pool.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getAllTreeInfo<T extends Idl>(program: Program<T>, mintAddress: PublicKey): Promise<TreeInfo[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Find the best tree to deposit into.
|
|
34
|
+
*
|
|
35
|
+
* Strategy (matches veilo-dapp):
|
|
36
|
+
* 1. Discard full trees.
|
|
37
|
+
* 2. Prefer the LOWEST tree ID with remaining capacity ≥ minCapacity (default 0.01%).
|
|
38
|
+
* 3. Ensures trees fill sequentially: 0 → 1 → 2 → …
|
|
39
|
+
* 4. Fallback to the tree with the most remaining capacity.
|
|
40
|
+
*/
|
|
41
|
+
export declare function getBestTreeForDeposit<T extends Idl>(program: Program<T>, mintAddress: PublicKey, minCapacity?: number): Promise<TreeInfo | null>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { getNoteTreePda, getNullifierMarkerPda, getPoolPdas, } from "./pdas.js";
|
|
2
|
+
// -----------------------------------------------------------------------------
|
|
3
|
+
// On-Chain Account Fetchers
|
|
4
|
+
// -----------------------------------------------------------------------------
|
|
5
|
+
/**
|
|
6
|
+
* Fetch and decode the on-chain PrivacyConfig account for a pool.
|
|
7
|
+
*/
|
|
8
|
+
export async function fetchPoolConfig(program, mintAddress) {
|
|
9
|
+
const { config } = getPoolPdas(program.programId, mintAddress);
|
|
10
|
+
return program.account.privacyConfig.fetch(config);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Check whether a nullifier has been spent on-chain.
|
|
14
|
+
* Returns true if the nullifier marker PDA exists (funds already spent).
|
|
15
|
+
*/
|
|
16
|
+
export async function checkNullifierSpent(program, mintAddress, nullifier) {
|
|
17
|
+
const marker = getNullifierMarkerPda(program.programId, mintAddress, nullifier);
|
|
18
|
+
const info = await program.provider.connection.getAccountInfo(marker);
|
|
19
|
+
return info !== null;
|
|
20
|
+
}
|
|
21
|
+
const TREE_CAPACITY = Math.pow(2, 22); // 4,194,304 leaves (depth 22)
|
|
22
|
+
/**
|
|
23
|
+
* Fetch utilization info for a specific tree.
|
|
24
|
+
* Returns null if the tree does not exist yet.
|
|
25
|
+
*/
|
|
26
|
+
export async function getTreeInfo(program, mintAddress, treeId) {
|
|
27
|
+
try {
|
|
28
|
+
const treePDA = getNoteTreePda(program.programId, mintAddress, treeId);
|
|
29
|
+
const tree = await program.account.merkleTreeAccount.fetch(treePDA);
|
|
30
|
+
const leafCount = Number(tree.nextIndex);
|
|
31
|
+
const remainingCapacity = TREE_CAPACITY - leafCount;
|
|
32
|
+
return {
|
|
33
|
+
treeId,
|
|
34
|
+
leafCount,
|
|
35
|
+
capacity: TREE_CAPACITY,
|
|
36
|
+
utilizationPercent: (leafCount / TREE_CAPACITY) * 100,
|
|
37
|
+
remainingCapacity,
|
|
38
|
+
isFull: leafCount >= TREE_CAPACITY,
|
|
39
|
+
treePDA,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Fetch utilization info for all trees in a pool.
|
|
48
|
+
*/
|
|
49
|
+
export async function getAllTreeInfo(program, mintAddress) {
|
|
50
|
+
try {
|
|
51
|
+
const { config } = getPoolPdas(program.programId, mintAddress);
|
|
52
|
+
const cfg = await program.account.privacyConfig.fetch(config);
|
|
53
|
+
const numTrees = Number(cfg.numTrees);
|
|
54
|
+
const results = [];
|
|
55
|
+
for (let id = 0; id < numTrees; id++) {
|
|
56
|
+
const info = await getTreeInfo(program, mintAddress, id);
|
|
57
|
+
if (info)
|
|
58
|
+
results.push(info);
|
|
59
|
+
}
|
|
60
|
+
return results;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Find the best tree to deposit into.
|
|
68
|
+
*
|
|
69
|
+
* Strategy (matches veilo-dapp):
|
|
70
|
+
* 1. Discard full trees.
|
|
71
|
+
* 2. Prefer the LOWEST tree ID with remaining capacity ≥ minCapacity (default 0.01%).
|
|
72
|
+
* 3. Ensures trees fill sequentially: 0 → 1 → 2 → …
|
|
73
|
+
* 4. Fallback to the tree with the most remaining capacity.
|
|
74
|
+
*/
|
|
75
|
+
export async function getBestTreeForDeposit(program, mintAddress, minCapacity = Math.floor(TREE_CAPACITY * 0.0001)) {
|
|
76
|
+
const trees = await getAllTreeInfo(program, mintAddress);
|
|
77
|
+
const available = trees.filter((t) => !t.isFull);
|
|
78
|
+
if (available.length === 0)
|
|
79
|
+
return null;
|
|
80
|
+
// Prefer lowest-id tree that still has meaningful capacity
|
|
81
|
+
const preferred = available
|
|
82
|
+
.filter((t) => t.remainingCapacity >= minCapacity)
|
|
83
|
+
.sort((a, b) => a.treeId - b.treeId);
|
|
84
|
+
if (preferred.length > 0)
|
|
85
|
+
return preferred[0];
|
|
86
|
+
// Fallback: most remaining capacity
|
|
87
|
+
return available.sort((a, b) => b.remainingCapacity - a.remainingCapacity)[0];
|
|
88
|
+
}
|