@perena/vault-sdk 1.0.49 → 1.0.50
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/README.md +4 -3
- package/dist/browser/nest.d.mts +26 -1
- package/dist/browser/nest.mjs +195 -17
- package/dist/index.d.ts +56 -12
- package/dist/index.js +283 -35
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -565,9 +565,10 @@ The builder auto-detects external liquidity slot 0 and, when it finds an active
|
|
|
565
565
|
Marginfi position for the asset, emits `execute_withdraw_from_external` instead
|
|
566
566
|
of `execute_withdraw`. That route can pull from the vault's external position in
|
|
567
567
|
the same transaction, so it draws on far more liquidity than the plain
|
|
568
|
-
`execute_withdraw`: the external-liquidity integrity service
|
|
569
|
-
|
|
570
|
-
`DEFAULT_TARGET_LOCAL_BPS`)
|
|
568
|
+
`execute_withdraw`: the external-liquidity integrity service targets local USDC
|
|
569
|
+
worth 1.5% of total vault TVL (`DEFAULT_TARGET_LOCAL_USDC_TVL_BPS`) and ~0.5% of
|
|
570
|
+
each other holding (`DEFAULT_TARGET_LOCAL_BPS`), deploying the rest into Marginfi.
|
|
571
|
+
It rebalances once local balances drift 20% from those targets, so a plain
|
|
571
572
|
withdrawal is capped at that small local buffer and will fail for anything
|
|
572
573
|
larger.
|
|
573
574
|
|
package/dist/browser/nest.d.mts
CHANGED
|
@@ -90,6 +90,29 @@ declare function decodeNestWithdrawalRequest(args: {
|
|
|
90
90
|
txBase64: string;
|
|
91
91
|
}): Promise<VaultTransactionPlan>;
|
|
92
92
|
|
|
93
|
+
interface NestDepositPlan extends VaultTransactionPlan {
|
|
94
|
+
/** Pass through to prepareVaultTransaction; the keeper's signatures are not reusable. */
|
|
95
|
+
ephemeralSignerKeys: PublicKey[];
|
|
96
|
+
}
|
|
97
|
+
/** Build a manager-funded deposit, with one event account for Squads to sign. */
|
|
98
|
+
declare function buildNestDepositRequest(args: {
|
|
99
|
+
connection: Connection;
|
|
100
|
+
owner: PublicKey;
|
|
101
|
+
rawAmountUsdc: bigint;
|
|
102
|
+
apiOptions?: NestApiOptions;
|
|
103
|
+
}): Promise<NestDepositPlan>;
|
|
104
|
+
/**
|
|
105
|
+
* Validate the USDC burn and Nest/Solana recipient. Replace the keeper rent payer
|
|
106
|
+
* with the manager, and expose the CCTP event signer for Squads PDA substitution.
|
|
107
|
+
* Nest remains trusted for the complete cross-chain payload and keeper delivery.
|
|
108
|
+
*/
|
|
109
|
+
declare function decodeNestDepositRequest(args: {
|
|
110
|
+
connection: Connection;
|
|
111
|
+
owner: PublicKey;
|
|
112
|
+
rawAmountUsdc: bigint;
|
|
113
|
+
txBase64: string;
|
|
114
|
+
}): Promise<NestDepositPlan>;
|
|
115
|
+
|
|
93
116
|
/**
|
|
94
117
|
* {@link PriceSource} adapter over the `nest` package's price API, bound to the
|
|
95
118
|
* Perena vault's Nest slug and share mint.
|
|
@@ -187,6 +210,8 @@ declare function prepareVaultTransaction(args: {
|
|
|
187
210
|
/** Skip execution simulation when proposing a transaction that depends on future funding. */
|
|
188
211
|
skipSimulation?: boolean;
|
|
189
212
|
addressLookupTableAccounts?: AddressLookupTableAccount[];
|
|
213
|
+
/** Temporary signer keys used only in account metas, replaced by Squads PDAs. */
|
|
214
|
+
ephemeralSignerKeys?: readonly PublicKey[];
|
|
190
215
|
}): Promise<PreparedVaultTransaction>;
|
|
191
216
|
|
|
192
217
|
interface SquadsProposalUpload {
|
|
@@ -205,4 +230,4 @@ declare function prepareSquadsProposalUpload(args: {
|
|
|
205
230
|
prepared: PreparedSquadsTransaction;
|
|
206
231
|
}): Promise<SquadsProposalUpload>;
|
|
207
232
|
|
|
208
|
-
export { NEST_RWA_SHARE_MINT, NEST_VAULT_SLUG, NestApiError, type NestApiOptions, type NestRedemptionQuote, type NestRedemptionStatus, type PreparedDirectTransaction, type PreparedSquadsTransaction, type PreparedVaultTransaction, type ResolvedSquadsWalletRoute, SquadsProposalExecutionSimulationError, type SquadsProposalUpload, type SquadsWalletRouteConfig, buildNestWithdrawalRequest, decodeNestWithdrawalRequest, fetchNestRedemptionQuote, fetchNestRedemptionStatus, findSquadsWalletRoute, prepareSquadsProposalUpload, prepareVaultTransaction, resolveSquadsWalletRoute, simulateSquadsProposalExecution, validateSquadsWalletRoutes, vaultAuthorityForWallet };
|
|
233
|
+
export { NEST_RWA_SHARE_MINT, NEST_VAULT_SLUG, NestApiError, type NestApiOptions, type NestDepositPlan, type NestRedemptionQuote, type NestRedemptionStatus, type PreparedDirectTransaction, type PreparedSquadsTransaction, type PreparedVaultTransaction, type ResolvedSquadsWalletRoute, SquadsProposalExecutionSimulationError, type SquadsProposalUpload, type SquadsWalletRouteConfig, buildNestDepositRequest, buildNestWithdrawalRequest, decodeNestDepositRequest, decodeNestWithdrawalRequest, fetchNestRedemptionQuote, fetchNestRedemptionStatus, findSquadsWalletRoute, prepareSquadsProposalUpload, prepareVaultTransaction, resolveSquadsWalletRoute, simulateSquadsProposalExecution, validateSquadsWalletRoutes, vaultAuthorityForWallet };
|
package/dist/browser/nest.mjs
CHANGED
|
@@ -454,14 +454,148 @@ async function decodeNestWithdrawalRequest(args) {
|
|
|
454
454
|
};
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
-
// src/
|
|
458
|
-
import
|
|
457
|
+
// src/services/nestDepositService.ts
|
|
458
|
+
import { address as address5 } from "@solana/kit";
|
|
459
459
|
import {
|
|
460
|
+
ASSOCIATED_TOKEN_PROGRAM_ID as ASSOCIATED_TOKEN_PROGRAM_ID3,
|
|
461
|
+
createAssociatedTokenAccountIdempotentInstruction,
|
|
462
|
+
getAssociatedTokenAddressSync as getAssociatedTokenAddressSync3,
|
|
463
|
+
TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2
|
|
464
|
+
} from "@solana/spl-token";
|
|
465
|
+
import {
|
|
466
|
+
ComputeBudgetProgram as ComputeBudgetProgram2,
|
|
460
467
|
PublicKey as PublicKey4,
|
|
461
|
-
|
|
468
|
+
SystemProgram,
|
|
462
469
|
TransactionMessage as TransactionMessage3,
|
|
463
470
|
VersionedTransaction as VersionedTransaction3
|
|
464
471
|
} from "@solana/web3.js";
|
|
472
|
+
var Usdc = new PublicKey4("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
|
|
473
|
+
var Messenger = new PublicKey4("CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe");
|
|
474
|
+
var Transmitter = new PublicKey4(
|
|
475
|
+
"CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC"
|
|
476
|
+
);
|
|
477
|
+
var Router = Buffer.from(
|
|
478
|
+
"0000000000000000000000007de01896d36bea9cf072ac64e41685418941d8be",
|
|
479
|
+
"hex"
|
|
480
|
+
);
|
|
481
|
+
var Composer = Buffer.from("908dcb5531691c2124c54e30bb645cf11647090d", "hex");
|
|
482
|
+
var BurnWithHook = Buffer.from([111, 245, 62, 131, 204, 108, 223, 155]);
|
|
483
|
+
var PerenaAssetId = Buffer.from(
|
|
484
|
+
"355750bed2d05a1eb92ab578335cc3ea6d572dd5f57a086088c68667f11e50d2",
|
|
485
|
+
"hex"
|
|
486
|
+
);
|
|
487
|
+
var MintAndSend = Buffer.from("fe030ec4", "hex");
|
|
488
|
+
async function buildNestDepositRequest(args) {
|
|
489
|
+
if (args.rawAmountUsdc <= 0n || args.rawAmountUsdc > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
490
|
+
throw new Error(
|
|
491
|
+
"Nest deposit must be a positive, safely representable USDC base-unit amount"
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
const options = args.apiOptions ?? {};
|
|
495
|
+
const response = await (options.fetchFn ?? fetch)(
|
|
496
|
+
`${(options.baseUrl ?? NEST_API_BASE_URL).replace(
|
|
497
|
+
/\/$/,
|
|
498
|
+
""
|
|
499
|
+
)}/solana/nest/mint/build-tx`,
|
|
500
|
+
{
|
|
501
|
+
method: "POST",
|
|
502
|
+
headers: { "Content-Type": "application/json" },
|
|
503
|
+
signal: options.signal,
|
|
504
|
+
body: JSON.stringify({
|
|
505
|
+
rawAmountUsdc: Number(args.rawAmountUsdc),
|
|
506
|
+
receiver: args.owner.toBase58(),
|
|
507
|
+
nestVaultSlug: NEST_VAULT_SLUG,
|
|
508
|
+
finality: "standard"
|
|
509
|
+
})
|
|
510
|
+
}
|
|
511
|
+
);
|
|
512
|
+
const payload = await response.json().catch(() => null);
|
|
513
|
+
if (!response.ok)
|
|
514
|
+
throw new Error(
|
|
515
|
+
`Nest deposit API (${response.status}): ${typeof payload?.error === "string" ? payload.error : response.statusText}`
|
|
516
|
+
);
|
|
517
|
+
if (typeof payload?.data?.txBase64 !== "string")
|
|
518
|
+
throw new Error("Nest API returned no deposit transaction");
|
|
519
|
+
return decodeNestDepositRequest({ ...args, txBase64: payload.data.txBase64 });
|
|
520
|
+
}
|
|
521
|
+
async function decodeNestDepositRequest(args) {
|
|
522
|
+
if (args.rawAmountUsdc <= 0n || args.rawAmountUsdc > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
523
|
+
throw new Error(
|
|
524
|
+
"Nest deposit must be a positive, safely representable USDC base-unit amount"
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
const message = VersionedTransaction3.deserialize(
|
|
528
|
+
Buffer.from(args.txBase64, "base64")
|
|
529
|
+
).message;
|
|
530
|
+
if (!message.staticAccountKeys[0].equals(args.owner))
|
|
531
|
+
throw new Error("Nest deposit payer must be the manager");
|
|
532
|
+
const tables = await Promise.all(
|
|
533
|
+
message.addressTableLookups.map(async (lookup) => {
|
|
534
|
+
const { value } = await args.connection.getAddressLookupTable(
|
|
535
|
+
lookup.accountKey
|
|
536
|
+
);
|
|
537
|
+
if (!value)
|
|
538
|
+
throw new Error(`Nest lookup table not found: ${lookup.accountKey}`);
|
|
539
|
+
return value;
|
|
540
|
+
})
|
|
541
|
+
);
|
|
542
|
+
const instructions2 = TransactionMessage3.decompile(message, {
|
|
543
|
+
addressLookupTableAccounts: tables
|
|
544
|
+
}).instructions;
|
|
545
|
+
const shareMint = new PublicKey4(NEST_RWA_SHARE_MINT2);
|
|
546
|
+
const shareAta = getAssociatedTokenAddressSync3(shareMint, args.owner, true);
|
|
547
|
+
const usdcAta = getAssociatedTokenAddressSync3(Usdc, args.owner, true);
|
|
548
|
+
let burn;
|
|
549
|
+
for (const ix of instructions2) {
|
|
550
|
+
if (ix.programId.equals(ComputeBudgetProgram2.programId)) continue;
|
|
551
|
+
if (ix.programId.equals(ASSOCIATED_TOKEN_PROGRAM_ID3)) {
|
|
552
|
+
if (ix.data.length !== 1 || ix.data[0] !== 1 || !ix.keys[0]?.pubkey.equals(args.owner) || !ix.keys[1]?.pubkey.equals(shareAta) || !ix.keys[2]?.pubkey.equals(args.owner) || !ix.keys[3]?.pubkey.equals(shareMint) || !ix.keys[4]?.pubkey.equals(SystemProgram.programId) || !ix.keys[5]?.pubkey.equals(TOKEN_PROGRAM_ID2))
|
|
553
|
+
throw new Error("Unexpected Nest deposit token account creation");
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
const d = ix.data;
|
|
557
|
+
const matches = (index, key) => ix.keys[index]?.pubkey.equals(key);
|
|
558
|
+
if (burn || !ix.programId.equals(Messenger) || ix.keys.length !== 18 || d.length < 316 || !d.subarray(0, 8).equals(BurnWithHook) || d.readBigUInt64LE(8) !== args.rawAmountUsdc || d.readUInt32LE(16) !== 22 || !d.subarray(20, 52).equals(Router) || !d.subarray(52, 84).equals(Router) || d.readBigUInt64LE(84) !== 0n || d.readUInt32LE(92) !== 2e3 || d.readUInt32LE(96) !== d.length - 100 || !d.subarray(100, 120).equals(Composer) || !d.subarray(120, 124).equals(MintAndSend) || !d.subarray(124, 156).equals(PerenaAssetId) || BigInt(`0x${d.subarray(156, 188).toString("hex")}`) !== args.rawAmountUsdc || BigInt(`0x${d.subarray(188, 220).toString("hex")}`) !== 128n || !d.subarray(220, 252).equals(Buffer.concat([Buffer.alloc(12), Composer])) || BigInt(`0x${d.subarray(252, 284).toString("hex")}`) !== 30168n || !d.subarray(284, 316).equals(args.owner.toBuffer()) || !matches(0, args.owner) || !matches(3, usdcAta) || !matches(10, Usdc) || !matches(12, Transmitter) || !matches(13, Messenger) || !matches(14, TOKEN_PROGRAM_ID2) || !matches(15, SystemProgram.programId) || !matches(17, Messenger) || ![0, 1, 11].every((index) => ix.keys[index].isSigner) || ix.keys.some(
|
|
559
|
+
(meta, index) => meta.isSigner && ![0, 1, 11].includes(index)
|
|
560
|
+
)) {
|
|
561
|
+
throw new Error(
|
|
562
|
+
"Unexpected Nest deposit instruction, amount, or recipient"
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
burn = ix;
|
|
566
|
+
}
|
|
567
|
+
if (!burn) throw new Error("Nest deposit must contain one CCTP burn");
|
|
568
|
+
const eventKey = burn.keys[11].pubkey;
|
|
569
|
+
if (eventKey.equals(args.owner) || burn.keys.some(
|
|
570
|
+
(meta, index) => index !== 11 && meta.pubkey.equals(eventKey)
|
|
571
|
+
)) {
|
|
572
|
+
throw new Error("Nest deposit event signer must be a separate account");
|
|
573
|
+
}
|
|
574
|
+
burn.keys[1] = { pubkey: args.owner, isSigner: true, isWritable: true };
|
|
575
|
+
return {
|
|
576
|
+
instructions: [
|
|
577
|
+
createAssociatedTokenAccountIdempotentInstruction(
|
|
578
|
+
args.owner,
|
|
579
|
+
shareAta,
|
|
580
|
+
args.owner,
|
|
581
|
+
shareMint
|
|
582
|
+
),
|
|
583
|
+
burn
|
|
584
|
+
].map(toKitInstruction),
|
|
585
|
+
lookupTables: tables.map((table) => address5(table.key.toBase58())),
|
|
586
|
+
ephemeralSignerKeys: [eventKey]
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// src/utils/squads.ts
|
|
591
|
+
import * as squads from "@sqds/multisig";
|
|
592
|
+
import {
|
|
593
|
+
PublicKey as PublicKey5,
|
|
594
|
+
Transaction,
|
|
595
|
+
TransactionInstruction as TransactionInstruction2,
|
|
596
|
+
TransactionMessage as TransactionMessage4,
|
|
597
|
+
VersionedTransaction as VersionedTransaction4
|
|
598
|
+
} from "@solana/web3.js";
|
|
465
599
|
var SQUADS_SIMULATION_COMMITMENT = "processed";
|
|
466
600
|
var SquadsProposalExecutionSimulationError = class extends Error {
|
|
467
601
|
constructor(transactionError, logs, unitsConsumed) {
|
|
@@ -485,8 +619,8 @@ function validateVaultIndex(vaultIndex) {
|
|
|
485
619
|
}
|
|
486
620
|
function resolveSquadsWalletRoute(route) {
|
|
487
621
|
validateVaultIndex(route.vaultIndex);
|
|
488
|
-
const wallet = new
|
|
489
|
-
const multisigPda = new
|
|
622
|
+
const wallet = new PublicKey5(route.wallet);
|
|
623
|
+
const multisigPda = new PublicKey5(route.multisigPda);
|
|
490
624
|
const [vaultPda] = squads.getVaultPda({
|
|
491
625
|
multisigPda,
|
|
492
626
|
index: route.vaultIndex
|
|
@@ -494,7 +628,7 @@ function resolveSquadsWalletRoute(route) {
|
|
|
494
628
|
return { ...route, wallet, multisigPda, vaultPda };
|
|
495
629
|
}
|
|
496
630
|
function findSquadsWalletRoute(wallet, routes) {
|
|
497
|
-
const walletKey = typeof wallet === "string" ? new
|
|
631
|
+
const walletKey = typeof wallet === "string" ? new PublicKey5(wallet) : wallet;
|
|
498
632
|
const route = routes.find(
|
|
499
633
|
(candidate) => candidate.wallet === walletKey.toBase58()
|
|
500
634
|
);
|
|
@@ -512,18 +646,18 @@ function validateSquadsWalletRoutes(routes) {
|
|
|
512
646
|
}
|
|
513
647
|
}
|
|
514
648
|
function vaultAuthorityForWallet(wallet, routes) {
|
|
515
|
-
const walletKey = typeof wallet === "string" ? new
|
|
649
|
+
const walletKey = typeof wallet === "string" ? new PublicKey5(wallet) : wallet;
|
|
516
650
|
return findSquadsWalletRoute(walletKey, routes)?.vaultPda ?? walletKey;
|
|
517
651
|
}
|
|
518
652
|
async function simulateSquadsProposalExecution(args) {
|
|
519
653
|
const { connection, feePayer, instructions: instructions2 } = args;
|
|
520
654
|
const recentBlockhash = args.recentBlockhash ?? (await connection.getLatestBlockhash(SQUADS_SIMULATION_COMMITMENT)).blockhash;
|
|
521
|
-
const message = new
|
|
655
|
+
const message = new TransactionMessage4({
|
|
522
656
|
payerKey: feePayer,
|
|
523
657
|
recentBlockhash,
|
|
524
658
|
instructions: [...instructions2]
|
|
525
659
|
}).compileToV0Message(args.addressLookupTableAccounts);
|
|
526
|
-
const transaction = new
|
|
660
|
+
const transaction = new VersionedTransaction4(message);
|
|
527
661
|
const { value } = await connection.simulateTransaction(transaction, {
|
|
528
662
|
sigVerify: false,
|
|
529
663
|
commitment: SQUADS_SIMULATION_COMMITMENT,
|
|
@@ -539,9 +673,13 @@ async function simulateSquadsProposalExecution(args) {
|
|
|
539
673
|
return value;
|
|
540
674
|
}
|
|
541
675
|
async function prepareVaultTransaction(args) {
|
|
542
|
-
const { connection, proposer
|
|
676
|
+
const { connection, proposer } = args;
|
|
677
|
+
let instructions2 = [...args.instructions];
|
|
678
|
+
const ephemeralKeys = args.ephemeralSignerKeys ?? [];
|
|
543
679
|
const route = findSquadsWalletRoute(proposer, args.squadsRoutes ?? []);
|
|
544
680
|
if (!route) {
|
|
681
|
+
if (ephemeralKeys.length)
|
|
682
|
+
throw new Error("Ephemeral signers require a Squads route");
|
|
545
683
|
return {
|
|
546
684
|
kind: "direct",
|
|
547
685
|
transaction: new Transaction().add(...instructions2),
|
|
@@ -569,6 +707,44 @@ async function prepareVaultTransaction(args) {
|
|
|
569
707
|
);
|
|
570
708
|
}
|
|
571
709
|
const transactionIndex = BigInt(multisig.transactionIndex.toString()) + 1n;
|
|
710
|
+
if (ephemeralKeys.length > 255 || new Set(ephemeralKeys.map(String)).size !== ephemeralKeys.length) {
|
|
711
|
+
throw new Error("Invalid Squads ephemeral signer keys");
|
|
712
|
+
}
|
|
713
|
+
const [transactionPda] = squads.getTransactionPda({
|
|
714
|
+
multisigPda: route.multisigPda,
|
|
715
|
+
index: transactionIndex
|
|
716
|
+
});
|
|
717
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
718
|
+
ephemeralKeys.forEach((key, index) => {
|
|
719
|
+
if (key.equals(proposer) || key.equals(route.vaultPda) || !instructions2.some(
|
|
720
|
+
(ix) => ix.keys.some((meta) => meta.isSigner && meta.pubkey.equals(key))
|
|
721
|
+
) || instructions2.some(
|
|
722
|
+
(ix) => ix.programId.equals(key) || ix.data.includes(key.toBuffer())
|
|
723
|
+
)) {
|
|
724
|
+
throw new Error(
|
|
725
|
+
"Ephemeral signer must be a separate account-meta signer, never embedded in instruction data"
|
|
726
|
+
);
|
|
727
|
+
}
|
|
728
|
+
replacements.set(
|
|
729
|
+
key.toBase58(),
|
|
730
|
+
squads.getEphemeralSignerPda({
|
|
731
|
+
transactionPda,
|
|
732
|
+
ephemeralSignerIndex: index
|
|
733
|
+
})[0]
|
|
734
|
+
);
|
|
735
|
+
});
|
|
736
|
+
if (replacements.size) {
|
|
737
|
+
instructions2 = instructions2.map(
|
|
738
|
+
(ix) => new TransactionInstruction2({
|
|
739
|
+
programId: ix.programId,
|
|
740
|
+
data: ix.data,
|
|
741
|
+
keys: ix.keys.map((meta) => ({
|
|
742
|
+
...meta,
|
|
743
|
+
pubkey: replacements.get(meta.pubkey.toBase58()) ?? meta.pubkey
|
|
744
|
+
}))
|
|
745
|
+
})
|
|
746
|
+
);
|
|
747
|
+
}
|
|
572
748
|
const { blockhash } = await connection.getLatestBlockhash("confirmed");
|
|
573
749
|
if (!args.skipSimulation) {
|
|
574
750
|
await simulateSquadsProposalExecution({
|
|
@@ -579,7 +755,7 @@ async function prepareVaultTransaction(args) {
|
|
|
579
755
|
addressLookupTableAccounts: args.addressLookupTableAccounts
|
|
580
756
|
});
|
|
581
757
|
}
|
|
582
|
-
const transactionMessage = new
|
|
758
|
+
const transactionMessage = new TransactionMessage4({
|
|
583
759
|
payerKey: route.vaultPda,
|
|
584
760
|
recentBlockhash: blockhash,
|
|
585
761
|
instructions: [...instructions2]
|
|
@@ -589,7 +765,7 @@ async function prepareVaultTransaction(args) {
|
|
|
589
765
|
transactionIndex,
|
|
590
766
|
creator: proposer,
|
|
591
767
|
vaultIndex: route.vaultIndex,
|
|
592
|
-
ephemeralSigners:
|
|
768
|
+
ephemeralSigners: ephemeralKeys.length,
|
|
593
769
|
transactionMessage,
|
|
594
770
|
addressLookupTableAccounts: args.addressLookupTableAccounts,
|
|
595
771
|
memo: route.memo
|
|
@@ -625,8 +801,8 @@ async function prepareVaultTransaction(args) {
|
|
|
625
801
|
// src/utils/squadsBuffer.ts
|
|
626
802
|
import * as squads2 from "@sqds/multisig";
|
|
627
803
|
import {
|
|
628
|
-
PublicKey as
|
|
629
|
-
SystemProgram,
|
|
804
|
+
PublicKey as PublicKey6,
|
|
805
|
+
SystemProgram as SystemProgram2,
|
|
630
806
|
Transaction as Transaction2
|
|
631
807
|
} from "@solana/web3.js";
|
|
632
808
|
var PacketSize = 1232;
|
|
@@ -637,7 +813,7 @@ async function prepareSquadsProposalUpload(args) {
|
|
|
637
813
|
const transaction = prepared.transaction;
|
|
638
814
|
const sizeProbe = new Transaction2({
|
|
639
815
|
feePayer: proposer,
|
|
640
|
-
recentBlockhash:
|
|
816
|
+
recentBlockhash: PublicKey6.default.toBase58()
|
|
641
817
|
}).add(...transaction.instructions);
|
|
642
818
|
let fits = false;
|
|
643
819
|
try {
|
|
@@ -657,7 +833,7 @@ async function prepareSquadsProposalUpload(args) {
|
|
|
657
833
|
let bufferPda;
|
|
658
834
|
let bufferIndex = 0;
|
|
659
835
|
for (; bufferIndex <= 255; bufferIndex++) {
|
|
660
|
-
const [candidate] =
|
|
836
|
+
const [candidate] = PublicKey6.findProgramAddressSync(
|
|
661
837
|
[
|
|
662
838
|
Buffer.from("multisig"),
|
|
663
839
|
prepared.multisigPda.toBuffer(),
|
|
@@ -718,7 +894,7 @@ async function prepareSquadsProposalUpload(args) {
|
|
|
718
894
|
vaultTransactionCreateItemTransaction: prepared.vaultTransactionPda,
|
|
719
895
|
vaultTransactionCreateItemCreator: proposer,
|
|
720
896
|
vaultTransactionCreateItemRentPayer: proposer,
|
|
721
|
-
vaultTransactionCreateItemSystemProgram:
|
|
897
|
+
vaultTransactionCreateItemSystemProgram: SystemProgram2.programId,
|
|
722
898
|
transactionBuffer: bufferPda,
|
|
723
899
|
creator: proposer
|
|
724
900
|
},
|
|
@@ -743,7 +919,9 @@ export {
|
|
|
743
919
|
NEST_VAULT_SLUG,
|
|
744
920
|
NestApiError,
|
|
745
921
|
SquadsProposalExecutionSimulationError,
|
|
922
|
+
buildNestDepositRequest,
|
|
746
923
|
buildNestWithdrawalRequest,
|
|
924
|
+
decodeNestDepositRequest,
|
|
747
925
|
decodeNestWithdrawalRequest,
|
|
748
926
|
fetchNestRedemptionQuote,
|
|
749
927
|
fetchNestRedemptionStatus,
|
package/dist/index.d.ts
CHANGED
|
@@ -12513,6 +12513,8 @@ declare function prepareVaultTransaction(args: {
|
|
|
12513
12513
|
/** Skip execution simulation when proposing a transaction that depends on future funding. */
|
|
12514
12514
|
skipSimulation?: boolean;
|
|
12515
12515
|
addressLookupTableAccounts?: AddressLookupTableAccount[];
|
|
12516
|
+
/** Temporary signer keys used only in account metas, replaced by Squads PDAs. */
|
|
12517
|
+
ephemeralSignerKeys?: readonly PublicKey[];
|
|
12516
12518
|
}): Promise<PreparedVaultTransaction>;
|
|
12517
12519
|
|
|
12518
12520
|
interface SquadsProposalUpload {
|
|
@@ -13953,10 +13955,10 @@ declare class ConsensusOracleService {
|
|
|
13953
13955
|
/**
|
|
13954
13956
|
* External Liquidity Integrity Service
|
|
13955
13957
|
*
|
|
13956
|
-
* Keeps
|
|
13957
|
-
*
|
|
13958
|
-
*
|
|
13959
|
-
*
|
|
13958
|
+
* Keeps USDC worth 1.5% of total vault TVL in the vault-owned token account.
|
|
13959
|
+
* Other holdings keep a small share of their own balance local (see
|
|
13960
|
+
* {@link DEFAULT_TARGET_LOCAL_BPS}) so routine payouts can be served without
|
|
13961
|
+
* a Marginfi round trip; everything
|
|
13960
13962
|
* above that target is deposited into the configured external position via
|
|
13961
13963
|
* `protocol_interaction` (a Marginfi deposit CPI).
|
|
13962
13964
|
*
|
|
@@ -14001,10 +14003,12 @@ interface ExternalLiquidityIntegrityOptions {
|
|
|
14001
14003
|
*/
|
|
14002
14004
|
minAmountUi?: number;
|
|
14003
14005
|
/**
|
|
14004
|
-
* Share of each holding (local + external) to keep in the vault's
|
|
14005
|
-
* account, in basis points. Defaults to {@link DEFAULT_TARGET_LOCAL_BPS}.
|
|
14006
|
+
* Share of each non-USDC holding (local + external) to keep in the vault's
|
|
14007
|
+
* own token account, in basis points. Defaults to {@link DEFAULT_TARGET_LOCAL_BPS}.
|
|
14006
14008
|
*/
|
|
14007
14009
|
targetLocalBps?: number;
|
|
14010
|
+
/** Share of total vault TVL to keep locally as USDC, in basis points. */
|
|
14011
|
+
targetLocalUsdcTvlBps?: number;
|
|
14008
14012
|
/**
|
|
14009
14013
|
* Hysteresis band, in basis points *of the target local amount*: the local
|
|
14010
14014
|
* balance must drift at least this far from target before a rebalance is
|
|
@@ -14014,14 +14018,17 @@ interface ExternalLiquidityIntegrityOptions {
|
|
|
14014
14018
|
}
|
|
14015
14019
|
declare const DEFAULT_MIN_AMOUNT_UI = 1;
|
|
14016
14020
|
/**
|
|
14017
|
-
* Keep 0.5% of each holding local; the
|
|
14021
|
+
* Keep 0.5% of each non-USDC holding local; the rest earns yield in Marginfi.
|
|
14018
14022
|
* Anything larger than this buffer is served by `execute_withdraw_from_external`,
|
|
14019
14023
|
* which unwinds the Marginfi position in the same transaction.
|
|
14020
14024
|
*/
|
|
14021
14025
|
declare const DEFAULT_TARGET_LOCAL_BPS = 50;
|
|
14026
|
+
/** Keep local USDC worth 1.5% of total vault TVL. */
|
|
14027
|
+
declare const DEFAULT_TARGET_LOCAL_USDC_TVL_BPS = 150;
|
|
14022
14028
|
/**
|
|
14023
14029
|
* Rebalance only once the local balance has drifted more than 20% away from its
|
|
14024
|
-
* target — i.e. outside
|
|
14030
|
+
* target — i.e. outside 1.2%–1.8% of vault TVL for USDC, or 0.4%–0.6% of
|
|
14031
|
+
* a non-USDC holding at its default 0.5% target.
|
|
14025
14032
|
* Without this band every arriving deposit or payout would trigger its own
|
|
14026
14033
|
* transaction; with it, each rebalance restores the exact target, so the next
|
|
14027
14034
|
* one is a full band away rather than one dust movement later.
|
|
@@ -14042,6 +14049,8 @@ declare function planRebalance(params: {
|
|
|
14042
14049
|
localAmount: bigint;
|
|
14043
14050
|
externalAmount: bigint;
|
|
14044
14051
|
targetLocalBps: number;
|
|
14052
|
+
/** Override the holding-based target with a raw token amount (USDC/TVL). */
|
|
14053
|
+
targetLocalAmount?: bigint;
|
|
14045
14054
|
rebalanceBandBps: number;
|
|
14046
14055
|
minRaw: bigint;
|
|
14047
14056
|
}): {
|
|
@@ -14065,6 +14074,7 @@ declare class ExternalLiquidityIntegrityService {
|
|
|
14065
14074
|
dryRun?: boolean;
|
|
14066
14075
|
minAmountUi?: number;
|
|
14067
14076
|
targetLocalBps?: number;
|
|
14077
|
+
targetLocalUsdcTvlBps?: number;
|
|
14068
14078
|
rebalanceBandBps?: number;
|
|
14069
14079
|
}): Promise<ExternalLiquidityIntegrityResult>;
|
|
14070
14080
|
/**
|
|
@@ -14081,14 +14091,19 @@ declare class ExternalLiquidityIntegrityService {
|
|
|
14081
14091
|
* payouts can be served without unwinding yield positions on demand.
|
|
14082
14092
|
*
|
|
14083
14093
|
* Idle USDC is the live balance of the vault's USDC token account plus USDC
|
|
14084
|
-
* deposits in
|
|
14094
|
+
* deposits in the first Project0 (Marginfi) external-liquidity position,
|
|
14095
|
+
* valued at the holding price.
|
|
14085
14096
|
* The holding's aggregate `external_amount` includes other deployed capital
|
|
14086
14097
|
* and must not be used as the idle reserve.
|
|
14087
14098
|
*
|
|
14088
14099
|
* When idle USDC drops below {@link IDLE_RESERVE_FLOOR_BPS} of vault TVL, the
|
|
14089
14100
|
* service swaps PST into USDC through the permissioned `jupiter_swap`
|
|
14090
14101
|
* instruction, sizing the swap to land at {@link IDLE_RESERVE_TARGET_BPS} of
|
|
14091
|
-
* TVL.
|
|
14102
|
+
* TVL. Independently, local USDC plus withdrawable Project0 deposits must cover
|
|
14103
|
+
* {@link WITHDRAWABLE_RESERVE_FLOOR_BPS} of TVL. Each bank contributes the lesser
|
|
14104
|
+
* of this vault's deposits and its available liquidity (deposits minus borrows,
|
|
14105
|
+
* floored at zero). The swap covers the larger of the two triggered shortfalls.
|
|
14106
|
+
* PST is never deployed externally, so the vault's local PST balance is
|
|
14092
14107
|
* the whole swappable inventory; if it cannot cover the full top-up the run is
|
|
14093
14108
|
* skipped rather than partially filled.
|
|
14094
14109
|
*
|
|
@@ -14101,6 +14116,8 @@ declare class ExternalLiquidityIntegrityService {
|
|
|
14101
14116
|
declare const IDLE_RESERVE_FLOOR_BPS = 400;
|
|
14102
14117
|
/** Top-ups are sized to land idle USDC at this share of TVL. */
|
|
14103
14118
|
declare const IDLE_RESERVE_TARGET_BPS = 500;
|
|
14119
|
+
/** Local USDC + withdrawable Project0 deposits must cover 1.5% of TVL. */
|
|
14120
|
+
declare const WITHDRAWABLE_RESERVE_FLOOR_BPS = 150;
|
|
14104
14121
|
declare const DEFAULT_SLIPPAGE_BPS = 30;
|
|
14105
14122
|
declare const DEFAULT_CU_PRICE_MICRO_LAMPORTS = 10000;
|
|
14106
14123
|
declare const DEFAULT_MAX_ACCOUNTS = 20;
|
|
@@ -14119,10 +14136,14 @@ interface IdleLiquidityResult {
|
|
|
14119
14136
|
reason: string;
|
|
14120
14137
|
/** Vault TVL in accounting units. */
|
|
14121
14138
|
tvl: bigint;
|
|
14122
|
-
/** Live vault USDC +
|
|
14139
|
+
/** Live vault USDC + first Project0 USDC deposits, in accounting units. */
|
|
14123
14140
|
idleValue: bigint;
|
|
14124
14141
|
/** Idle USDC as a share of TVL, in bps. */
|
|
14125
14142
|
idleBps: number;
|
|
14143
|
+
/** Local USDC + bank-liquidity-capped deposits, in accounting units. */
|
|
14144
|
+
withdrawableValue: bigint;
|
|
14145
|
+
/** Withdrawable USDC as a share of TVL, in bps. */
|
|
14146
|
+
withdrawableBps: number;
|
|
14126
14147
|
/** USDC the swap needs to produce to reach the target, in raw USDC units. */
|
|
14127
14148
|
shortfallUsdc: bigint;
|
|
14128
14149
|
/** PST spent (0 unless a swap was executed or simulated). */
|
|
@@ -14272,4 +14293,27 @@ declare function decodeNestWithdrawalRequest(args: {
|
|
|
14272
14293
|
txBase64: string;
|
|
14273
14294
|
}): Promise<VaultTransactionPlan>;
|
|
14274
14295
|
|
|
14275
|
-
export { ASSET_DECIMALS, ASSET_REBALANCE_COOLDOWN_SECS, type AccountBalanceResponse, AccountClient, type AccountYieldResponse, ActivateCircuitBreakerBuilder, type ActivateCircuitBreakerIxArgs, type ActivateCircuitBreakerTxArgs, type AddAprCashflowUpdateParams, type AddCashflowUpdateParams, type AddIncentiveRecipientArgs, AddIncentiveRecipientBuilder, type AddIncentiveRecipientIxArgs, AddIncentiveRecipientV3Builder, type AddIncentiveRecipientV3IxArgs, type AddIncentiveRecipientV3TxArgs, type AddNavCashflowUpdateParams, type AprAccountBalanceResponse, type AprAccountYieldResponse, type AssetPriceOracleConfigIxArgs, type AssetPriceOracleConfigTxArgs, type AssetPriceRefreshTarget, type AssetRefreshResult, type AssetType, BALANCE_CHANGE_BASELINE_MAX_AGE_SECS, type Bankineco, type BasicAuthCredentials, type Bigintish, type BuildMarginfiWithdrawInteractionArgs, CONSENSUS_ORACLE_VARIANT, type CancelIncentiveProposalArgs, CancelIncentiveProposalBuilder, CancelJuniorTrancheWithdrawBuilder, type CancelJuniorTrancheWithdrawIxArgs, type CancelJuniorTrancheWithdrawTxArgs, ClaimIncentiveBuilder, type ClaimIncentiveIxArgs, type ClaimIncentiveTxArgs, ClaimIncentiveV3Builder, type ClaimIncentiveV3IxArgs, type ClaimIncentiveV3TxArgs, type Clock, type CollectSamplesOptions, type ConsensusAssetUpdate, type ConsensusHoldingEntry, type ConsensusHoldingSimulation, type ConsensusOracleDeps, type ConsensusOracleHoldingConfig, ConsensusOracleService, type ConsensusOracleTarget, CrankNavBuilder, type CrankNavIxArgs, type CrankNavTxArgs, CrankPerformanceFeesBuilder, type CrankPerformanceFeesIxArgs, type CrankPerformanceFeesTxArgs, type CreateAccountParams, CreateAssetHoldingBuilder, type CreateAssetHoldingIxArgs, type CreateAssetHoldingTxArgs, CreateIncentiveBuilder, type CreateIncentiveIxArgs, type CreateIncentiveTxArgs, CreateIncentiveV3Builder, type CreateIncentiveV3IxArgs, type CreateIncentiveV3TxArgs, type CreateTokenMintIxs, CreateTrancheStateBuilder, type CreateTrancheStateIxArgs, type CreateTrancheStateTxArgs, CreateVaultBuilder, type CreateVaultClientOptions, type CreateVaultIxArgs, type CreateVaultParams, type CreateVaultTxArgs, type CreateYieldPaymentParams, DEFAULT_CU_PRICE_MICRO_LAMPORTS, DEFAULT_JUNIOR_EARLY_UNSTAKE_FEE_BPS, DEFAULT_JUNIOR_STANDARD_UNSTAKE_FEE_BPS, DEFAULT_JUNIOR_WITHDRAWAL_LOCKUP_SECS, DEFAULT_MAX_ACCEPTABLE_APY_BPS, DEFAULT_MAX_ACCOUNTS, DEFAULT_MINTS, DEFAULT_MIN_AMOUNT_UI, DEFAULT_ORACLE_STALENESS_THRESHOLD_SECS, DEFAULT_PRICE_ORACLE_ACCOUNT, DEFAULT_PRICE_STALENESS_SECS, DEFAULT_PRICE_STALENESS_THRESHOLD_SECS, DEFAULT_REBALANCE_BAND_BPS, DEFAULT_SLIPPAGE_BPS, DEFAULT_TARGET_LOCAL_BPS, DEFAULT_VAULT_ID, type DecodedHolding, type DecodedVault, type DecodedVaultTrancheState, type DeleteAccountParams, DisableCircuitBreakerBuilder, type DisableCircuitBreakerIxArgs, type DisableCircuitBreakerTxArgs, DistributeIncentiveBuilder, type DistributeIncentiveIxArgs, type DistributeIncentiveTxArgs, DistributeIncentiveV3Builder, type DistributeIncentiveV3IxArgs, type DistributeIncentiveV3TxArgs, EXTERNAL_POSITION_SAMPLES, ExecuteDepositBuilder, type ExecuteDepositIxArgs, type ExecuteDepositTxArgs, ExecuteShareSwapBuilder, type ExecuteShareSwapIxArgs, type ExecuteShareSwapTxArgs, ExecuteTrancheDepositBuilder, type ExecuteTrancheDepositIxArgs, type ExecuteTrancheDepositTxArgs, ExecuteTrancheWithdrawBuilder, type ExecuteTrancheWithdrawIxArgs, type ExecuteTrancheWithdrawTxArgs, ExecuteWithdrawBuilder, type ExecuteWithdrawIxArgs, type ExecuteWithdrawTxArgs, type ExternalLiquidityIntegrityOptions, type ExternalLiquidityIntegrityResult, ExternalLiquidityIntegrityService, type ExternalLiquidityIntegritySummary, type ExternalLiquiditySlot, type ExternalLiquiditySourceArgs, type ExternalPosition, type ExternalPositionContext, type ExternalPositionProvider, type ExternalPositionRef, ExternalPositionRegistry, FEE_VAULT_CACHE_CATEGORY, type FeeVaultAccountData, type FetchNestTokenPriceOptions, FulfillJuniorTrancheWithdrawBuilder, type FulfillJuniorTrancheWithdrawIxArgs, type FulfillJuniorTrancheWithdrawTxArgs, type FulfillSummary, type HoldingNavContribution, type HoldingUpdatePreview, IDL, IDLE_RESERVE_FLOOR_BPS, IDLE_RESERVE_TARGET_BPS, type IdleLiquidityOptions, type IdleLiquidityResult, IdleLiquidityService, type IdleLiquidityStatus, type IncentiveRecipient, type IncentiveTotals, type IncentiveUsdUpdateArgs, type IncentiveV3OracleState, type IncentiveV3Recipient, type IncentiveV3Totals, InitializeVaultRolesBuilder, type InitializeVaultRolesIxArgs, type InitializeVaultRolesTxArgs, type JuniorWithdrawalMode, JupiterPriceSource, type JupiterPriceSourceOptions, JupiterSwapBuilder, type JupiterSwapIxArgs, type JupiterSwapTxArgs, KaminoPositionProvider, LIVE_ORACLE_VARIANTS, LIVE_PRICE_REFRESH_INTERVAL_SECS, LOCAL_PROTOCOL_ADMIN, LargeBalanceChangeError, type LargeBalanceChangeViolation, type LiveConsensusOracleDepsOptions, LivePriceSource, type LivePriceSourceOptions, MANAGER_WALLET_NAV_DROP_TRIGGER_BPS, MANAGER_WALLET_NAV_TOLERANCE_BPS, MAX_APY_ANCHOR_WINDOW_SECS, MAX_BALANCE_CHANGE_BPS, MAX_CONSENSUS_SIGNERS, MAX_INCENTIVE_RECIPIENTS, MAX_INCENTIVE_REPORT_TTL, MAX_MANAGER_WITHDRAW_DESTINATIONS, MAX_PRICE_STALENESS_THRESHOLD_SECS, MIN_EXTERNAL_POSITION_SAMPLES, ManagerRedepositAssetBuilder, type ManagerRedepositAssetIxArgs, type ManagerRedepositAssetTxArgs, type ManagerWalletBalanceSource, type ManagerWalletReconciliation, ManagerWithdrawAssetBuilder, type ManagerWithdrawAssetIxArgs, type ManagerWithdrawAssetTxArgs, MarginfiPositionProvider, type MaxApyAnchorSnapshot, type MintConfig, type MintIdentifier, type MintInfo, MintRegistry, type MintRegistryOptions, type MockYieldAccountConfig, MockYieldTracker, type MockYieldTrackerOptions, NEST_API_BASE_URL, NEST_RWA_SHARE_MINT, NEST_VAULT_SLUG, type NavAccountBalanceResponse, type NavAccountValueResponse, type NavCrankBlocker, type NavCrankBlockerReason, type NavCrankReadiness, type NavCrankResult, type NavPriceConfig, type NavYieldAccount, NestApiError, type NestApiOptions, NestPriceSource, type NestPriceSourceOptions, type NestRedemptionQuote, type NestRedemptionStatus, ORACLE_ENTRIES_OFFSET, ORACLE_ENTRY_SIZE, ORACLE_SETTLED_NAV_TS_OFFSET, OracleService, PRICE_ORACLE_TYPES_BY_INDEX, PROGRAM_FEE_EXEMPT_OWNER_WHITELIST, PROTOCOL_ADMIN, PROTOCOL_FEE_RECIPIENT, PdaClient, type PendingConsensusSignerSet, type PreparedDirectTransaction, type PreparedSquadsTransaction, type PreparedVaultTransaction, type PriceOracleTypeArgs, type PriceSource, ProtocolInteractionBuilder, type ProtocolInteractionIxArgs, type ProtocolInteractionTxArgs, type QuoteFeeUnit, REPORTABLE_ORACLE_VARIANTS, type RealizedApySimulation, type RefreshLiveOraclePricesParams, RemoveAssetHoldingBuilder, type RemoveAssetHoldingIxArgs, type RemoveAssetHoldingTxArgs, ReportIncentiveV3Builder, type ReportIncentiveV3IxArgs, type ReportIncentiveV3TxArgs, RequestJuniorTrancheWithdrawBuilder, type RequestJuniorTrancheWithdrawIxArgs, type RequestJuniorTrancheWithdrawTxArgs, type ResolveExternalWithdrawArgs, type ResolvedExternalWithdraw, type ResolvedSquadsWalletRoute, type RollingLimitConfig, type RollingRebalanceLimitConfig, RpcManagerWalletBalanceSource, type RunLiveConsensusOracleOptions, type RunOptions, type RunSummary, SHARE_DECIMALS, SYSTEM_PROGRAM, SetAssetPriceOracleBuilder, type SetAssetPriceOracleIxArgs, type SetAssetPriceOracleTxArgs, SetExternalLiquidityBuilder, type SetExternalLiquidityIxArgs, type SetExternalLiquidityTxArgs, type SetIncentiveLimitsArgs, SetIncentiveLimitsBuilder, type SetIncentiveLimitsV3Args, SetIncentiveLimitsV3Builder, SetManagerWithdrawDestinationBuilder, type SetManagerWithdrawDestinationIxArgs, type SetManagerWithdrawDestinationTxArgs, SetProtocolFeeBuilder, type SetProtocolFeeIxArgs, type SetProtocolFeeTxArgs, SetVaultConfigBuilder, type SetVaultConfigIxArgs, type SetVaultConfigTxArgs, SettleIncentiveV3Builder, type SettleIncentiveV3IxArgs, type SettleIncentiveV3TxArgs, type SettleVaultParams, type SettleVaultResult, type SettlementSimulation, type SettlementSimulationSnapshot, type SimulateDryRunSettlementParams, type SimulateSettlementArgs, type SimulatedShareClass, SquadsProposalExecutionSimulationError, type SquadsProposalUpload, type SquadsWalletRouteConfig, type StaleBalanceChangeBypass, StaticPositionProvider, SubmitIncentiveBuilder, type SubmitIncentiveIxArgs, type SubmitIncentiveTxArgs, TOKEN_PROGRAM, TOKEN_PROGRAM_ID, type TimelockSettlementKind, type TimelockSettlementOptions, type TimelockSettlementRecord, TimelockSettlementService, type TimelockSettlementSummary, type TrackedAccountValue, type TrancheKindArgs, type TransactionBuilder, TransactionClient, USDC_MINT, USD_STAR_JUNIOR_MINT, USD_STAR_MINT, USD_STAR_PRINCIPAL_MINT, type UpdateAccountParams, UpdateAssetPriceBuilder, type UpdateAssetPriceIxArgs, type UpdateAssetPriceTxArgs, UpdateConsensusOracleBuilder, type UpdateConsensusOracleIxArgs, type UpdateConsensusOracleTxArgs, UpdateConsensusSignersBuilder, type UpdateConsensusSignersIxArgs, type UpdateConsensusSignersTxArgs, type UpdateDynamicAprParams, UpdateTrancheConfigBuilder, type UpdateTrancheConfigIxArgs, type UpdateTrancheConfigTxArgs, VAULT_CACHE_CATEGORY, VAULT_CREATOR_WHITELIST, VAULT_ENVIRONMENTS, VAULT_ORACLE_CACHE_CATEGORY, VAULT_PROGRAM_ID, VAULT_PROGRAM_IDS, VAULT_PROGRAM_PUBLIC_KEY, VAULT_ROLE_UPDATE_TIMELOCK_SECS, VAULT_TRANCHE_STATE_CACHE_CATEGORY, VAULT_TRANCHE_WITHDRAWAL_QUEUE_CACHE_CATEGORY, type Vault, type VaultAccountData, VaultBuilderBase, type VaultBuilderContext, type VaultCacheInvalidation, VaultClient, type VaultClientBundle, type VaultEnv, type VaultIncentiveAccount, type VaultIncentiveAccountData, type VaultIncentiveV3Account, type VaultIncentiveV3AccountData, type VaultOracleAccountData, type VaultOracleResult, type VaultPricingInputs, type VaultQuote, type VaultQuoteArgs, VaultQuoteClient, type VaultQuoteDirection, type VaultQuoteShareClass, VaultReallocationBuilder, type VaultReallocationIxArgs, type VaultReallocationTxArgs, type VaultTrancheStateAccountData, type VaultTrancheWithdrawalQueueAccountData, type VaultTransactionPlan, type WithdrawProtocolFeesIxArgs, type WithdrawProtocolFeesTxArgs, WithdrawalQueueService, type WithdrawalQueueSnapshot, type YieldAccount, type YieldAccountSnapshot, type YieldCalculationLog, type YieldCashflow, type YieldPaymentResponse, type YieldPaymentSnapshot, type YieldTracker, type YieldValuationModel, accountingUnitPriceToUsd, addCashflowUpdate, applyEffectiveApy, assertNoLargeBalanceChanges, assertNoUnconfirmedYieldPayments, buildHoldingUpdate, buildMarginfiWithdrawInteraction, buildNestWithdrawalRequest, buildUpdates, candidateGrossNav, coerceBool, collectSamples, confirmYieldPayment, createAccount, createLiveConsensusOracleDeps, createRpcFromConnection, createTokenMint, createTokenMintIxs, createVaultClient, createYieldPayment, dateToStr, decodeNestWithdrawalRequest, decodePendingConsensusSigners, defaultKeypairPath, deleteAccount, discoverVaultsForSigner, fetchExternalPositions, fetchNestRedemptionQuote, fetchNestRedemptionStatus, fetchNestTokenPrice, fetchReceiptMints, filterTargetHoldings, findLargeBalanceChanges, findSquadsWalletRoute, formatSettlementSimulation, fromUiAmount, gatherPricingInputs, getAccount, getAccounts, getAprYield, getBalance, getCashflows, getIncentiveRecipientShareAtas, getIncentiveRecipients, getIncentiveReportRecipients, getIncentiveTotals, getIncentiveV3OracleState, getIncentiveV3RecipientShareAtas, getIncentiveV3Recipients, getIncentiveV3Totals, getNavValue, getRpcUrl, getTotalOutstandingYield, getTotalTrackedValue, getTotalYield, getTrackedValue, getVaultProgramId, getYield, getYieldPayments, indexConfigByMint, isNavAccountBalance, isNavAccountValue, isNavYieldAccount, isVaultEnv, keypairAddress, loadKeypair, logProspectiveApy, makeProvider, managerReconciliationStateKey, mintTokensTo, mints, mostFrequent, parseExternalLiquidityRefs, planRebalance, prepareSquadsProposalUpload, prepareVaultTransaction, previousPhysicalNav, priceInAccountingUnit, readI64LE, readSplMintSupply, reconcileManagerWalletBalances, refreshLiveOraclePrices, resolveExternalWithdraw, resolveKeypairPath, resolveSquadsWalletRoute, resolveTrackedAmounts, roundToNextUtcMidnight, runLiveConsensusOracle, selectReportableHoldings, settleVault, signerInOracleData, simulateConsensusOracleSettlement, simulateDryRunSettlement, simulateSquadsProposalExecution, sumPositionsByMint, systemClock, toBigInt, toUiAmount, toWeb3AccountMeta, trackedValueFromResponse, updateAccount, updateDynamicApr, validateSquadsWalletRoutes, variantName, vaultAuthorityForWallet, withDiscoveredYieldAccounts };
|
|
14296
|
+
interface NestDepositPlan extends VaultTransactionPlan {
|
|
14297
|
+
/** Pass through to prepareVaultTransaction; the keeper's signatures are not reusable. */
|
|
14298
|
+
ephemeralSignerKeys: PublicKey[];
|
|
14299
|
+
}
|
|
14300
|
+
/** Build a manager-funded deposit, with one event account for Squads to sign. */
|
|
14301
|
+
declare function buildNestDepositRequest(args: {
|
|
14302
|
+
connection: Connection;
|
|
14303
|
+
owner: PublicKey;
|
|
14304
|
+
rawAmountUsdc: bigint;
|
|
14305
|
+
apiOptions?: NestApiOptions;
|
|
14306
|
+
}): Promise<NestDepositPlan>;
|
|
14307
|
+
/**
|
|
14308
|
+
* Validate the USDC burn and Nest/Solana recipient. Replace the keeper rent payer
|
|
14309
|
+
* with the manager, and expose the CCTP event signer for Squads PDA substitution.
|
|
14310
|
+
* Nest remains trusted for the complete cross-chain payload and keeper delivery.
|
|
14311
|
+
*/
|
|
14312
|
+
declare function decodeNestDepositRequest(args: {
|
|
14313
|
+
connection: Connection;
|
|
14314
|
+
owner: PublicKey;
|
|
14315
|
+
rawAmountUsdc: bigint;
|
|
14316
|
+
txBase64: string;
|
|
14317
|
+
}): Promise<NestDepositPlan>;
|
|
14318
|
+
|
|
14319
|
+
export { ASSET_DECIMALS, ASSET_REBALANCE_COOLDOWN_SECS, type AccountBalanceResponse, AccountClient, type AccountYieldResponse, ActivateCircuitBreakerBuilder, type ActivateCircuitBreakerIxArgs, type ActivateCircuitBreakerTxArgs, type AddAprCashflowUpdateParams, type AddCashflowUpdateParams, type AddIncentiveRecipientArgs, AddIncentiveRecipientBuilder, type AddIncentiveRecipientIxArgs, AddIncentiveRecipientV3Builder, type AddIncentiveRecipientV3IxArgs, type AddIncentiveRecipientV3TxArgs, type AddNavCashflowUpdateParams, type AprAccountBalanceResponse, type AprAccountYieldResponse, type AssetPriceOracleConfigIxArgs, type AssetPriceOracleConfigTxArgs, type AssetPriceRefreshTarget, type AssetRefreshResult, type AssetType, BALANCE_CHANGE_BASELINE_MAX_AGE_SECS, type Bankineco, type BasicAuthCredentials, type Bigintish, type BuildMarginfiWithdrawInteractionArgs, CONSENSUS_ORACLE_VARIANT, type CancelIncentiveProposalArgs, CancelIncentiveProposalBuilder, CancelJuniorTrancheWithdrawBuilder, type CancelJuniorTrancheWithdrawIxArgs, type CancelJuniorTrancheWithdrawTxArgs, ClaimIncentiveBuilder, type ClaimIncentiveIxArgs, type ClaimIncentiveTxArgs, ClaimIncentiveV3Builder, type ClaimIncentiveV3IxArgs, type ClaimIncentiveV3TxArgs, type Clock, type CollectSamplesOptions, type ConsensusAssetUpdate, type ConsensusHoldingEntry, type ConsensusHoldingSimulation, type ConsensusOracleDeps, type ConsensusOracleHoldingConfig, ConsensusOracleService, type ConsensusOracleTarget, CrankNavBuilder, type CrankNavIxArgs, type CrankNavTxArgs, CrankPerformanceFeesBuilder, type CrankPerformanceFeesIxArgs, type CrankPerformanceFeesTxArgs, type CreateAccountParams, CreateAssetHoldingBuilder, type CreateAssetHoldingIxArgs, type CreateAssetHoldingTxArgs, CreateIncentiveBuilder, type CreateIncentiveIxArgs, type CreateIncentiveTxArgs, CreateIncentiveV3Builder, type CreateIncentiveV3IxArgs, type CreateIncentiveV3TxArgs, type CreateTokenMintIxs, CreateTrancheStateBuilder, type CreateTrancheStateIxArgs, type CreateTrancheStateTxArgs, CreateVaultBuilder, type CreateVaultClientOptions, type CreateVaultIxArgs, type CreateVaultParams, type CreateVaultTxArgs, type CreateYieldPaymentParams, DEFAULT_CU_PRICE_MICRO_LAMPORTS, DEFAULT_JUNIOR_EARLY_UNSTAKE_FEE_BPS, DEFAULT_JUNIOR_STANDARD_UNSTAKE_FEE_BPS, DEFAULT_JUNIOR_WITHDRAWAL_LOCKUP_SECS, DEFAULT_MAX_ACCEPTABLE_APY_BPS, DEFAULT_MAX_ACCOUNTS, DEFAULT_MINTS, DEFAULT_MIN_AMOUNT_UI, DEFAULT_ORACLE_STALENESS_THRESHOLD_SECS, DEFAULT_PRICE_ORACLE_ACCOUNT, DEFAULT_PRICE_STALENESS_SECS, DEFAULT_PRICE_STALENESS_THRESHOLD_SECS, DEFAULT_REBALANCE_BAND_BPS, DEFAULT_SLIPPAGE_BPS, DEFAULT_TARGET_LOCAL_BPS, DEFAULT_TARGET_LOCAL_USDC_TVL_BPS, DEFAULT_VAULT_ID, type DecodedHolding, type DecodedVault, type DecodedVaultTrancheState, type DeleteAccountParams, DisableCircuitBreakerBuilder, type DisableCircuitBreakerIxArgs, type DisableCircuitBreakerTxArgs, DistributeIncentiveBuilder, type DistributeIncentiveIxArgs, type DistributeIncentiveTxArgs, DistributeIncentiveV3Builder, type DistributeIncentiveV3IxArgs, type DistributeIncentiveV3TxArgs, EXTERNAL_POSITION_SAMPLES, ExecuteDepositBuilder, type ExecuteDepositIxArgs, type ExecuteDepositTxArgs, ExecuteShareSwapBuilder, type ExecuteShareSwapIxArgs, type ExecuteShareSwapTxArgs, ExecuteTrancheDepositBuilder, type ExecuteTrancheDepositIxArgs, type ExecuteTrancheDepositTxArgs, ExecuteTrancheWithdrawBuilder, type ExecuteTrancheWithdrawIxArgs, type ExecuteTrancheWithdrawTxArgs, ExecuteWithdrawBuilder, type ExecuteWithdrawIxArgs, type ExecuteWithdrawTxArgs, type ExternalLiquidityIntegrityOptions, type ExternalLiquidityIntegrityResult, ExternalLiquidityIntegrityService, type ExternalLiquidityIntegritySummary, type ExternalLiquiditySlot, type ExternalLiquiditySourceArgs, type ExternalPosition, type ExternalPositionContext, type ExternalPositionProvider, type ExternalPositionRef, ExternalPositionRegistry, FEE_VAULT_CACHE_CATEGORY, type FeeVaultAccountData, type FetchNestTokenPriceOptions, FulfillJuniorTrancheWithdrawBuilder, type FulfillJuniorTrancheWithdrawIxArgs, type FulfillJuniorTrancheWithdrawTxArgs, type FulfillSummary, type HoldingNavContribution, type HoldingUpdatePreview, IDL, IDLE_RESERVE_FLOOR_BPS, IDLE_RESERVE_TARGET_BPS, type IdleLiquidityOptions, type IdleLiquidityResult, IdleLiquidityService, type IdleLiquidityStatus, type IncentiveRecipient, type IncentiveTotals, type IncentiveUsdUpdateArgs, type IncentiveV3OracleState, type IncentiveV3Recipient, type IncentiveV3Totals, InitializeVaultRolesBuilder, type InitializeVaultRolesIxArgs, type InitializeVaultRolesTxArgs, type JuniorWithdrawalMode, JupiterPriceSource, type JupiterPriceSourceOptions, JupiterSwapBuilder, type JupiterSwapIxArgs, type JupiterSwapTxArgs, KaminoPositionProvider, LIVE_ORACLE_VARIANTS, LIVE_PRICE_REFRESH_INTERVAL_SECS, LOCAL_PROTOCOL_ADMIN, LargeBalanceChangeError, type LargeBalanceChangeViolation, type LiveConsensusOracleDepsOptions, LivePriceSource, type LivePriceSourceOptions, MANAGER_WALLET_NAV_DROP_TRIGGER_BPS, MANAGER_WALLET_NAV_TOLERANCE_BPS, MAX_APY_ANCHOR_WINDOW_SECS, MAX_BALANCE_CHANGE_BPS, MAX_CONSENSUS_SIGNERS, MAX_INCENTIVE_RECIPIENTS, MAX_INCENTIVE_REPORT_TTL, MAX_MANAGER_WITHDRAW_DESTINATIONS, MAX_PRICE_STALENESS_THRESHOLD_SECS, MIN_EXTERNAL_POSITION_SAMPLES, ManagerRedepositAssetBuilder, type ManagerRedepositAssetIxArgs, type ManagerRedepositAssetTxArgs, type ManagerWalletBalanceSource, type ManagerWalletReconciliation, ManagerWithdrawAssetBuilder, type ManagerWithdrawAssetIxArgs, type ManagerWithdrawAssetTxArgs, MarginfiPositionProvider, type MaxApyAnchorSnapshot, type MintConfig, type MintIdentifier, type MintInfo, MintRegistry, type MintRegistryOptions, type MockYieldAccountConfig, MockYieldTracker, type MockYieldTrackerOptions, NEST_API_BASE_URL, NEST_RWA_SHARE_MINT, NEST_VAULT_SLUG, type NavAccountBalanceResponse, type NavAccountValueResponse, type NavCrankBlocker, type NavCrankBlockerReason, type NavCrankReadiness, type NavCrankResult, type NavPriceConfig, type NavYieldAccount, NestApiError, type NestApiOptions, type NestDepositPlan, NestPriceSource, type NestPriceSourceOptions, type NestRedemptionQuote, type NestRedemptionStatus, ORACLE_ENTRIES_OFFSET, ORACLE_ENTRY_SIZE, ORACLE_SETTLED_NAV_TS_OFFSET, OracleService, PRICE_ORACLE_TYPES_BY_INDEX, PROGRAM_FEE_EXEMPT_OWNER_WHITELIST, PROTOCOL_ADMIN, PROTOCOL_FEE_RECIPIENT, PdaClient, type PendingConsensusSignerSet, type PreparedDirectTransaction, type PreparedSquadsTransaction, type PreparedVaultTransaction, type PriceOracleTypeArgs, type PriceSource, ProtocolInteractionBuilder, type ProtocolInteractionIxArgs, type ProtocolInteractionTxArgs, type QuoteFeeUnit, REPORTABLE_ORACLE_VARIANTS, type RealizedApySimulation, type RefreshLiveOraclePricesParams, RemoveAssetHoldingBuilder, type RemoveAssetHoldingIxArgs, type RemoveAssetHoldingTxArgs, ReportIncentiveV3Builder, type ReportIncentiveV3IxArgs, type ReportIncentiveV3TxArgs, RequestJuniorTrancheWithdrawBuilder, type RequestJuniorTrancheWithdrawIxArgs, type RequestJuniorTrancheWithdrawTxArgs, type ResolveExternalWithdrawArgs, type ResolvedExternalWithdraw, type ResolvedSquadsWalletRoute, type RollingLimitConfig, type RollingRebalanceLimitConfig, RpcManagerWalletBalanceSource, type RunLiveConsensusOracleOptions, type RunOptions, type RunSummary, SHARE_DECIMALS, SYSTEM_PROGRAM, SetAssetPriceOracleBuilder, type SetAssetPriceOracleIxArgs, type SetAssetPriceOracleTxArgs, SetExternalLiquidityBuilder, type SetExternalLiquidityIxArgs, type SetExternalLiquidityTxArgs, type SetIncentiveLimitsArgs, SetIncentiveLimitsBuilder, type SetIncentiveLimitsV3Args, SetIncentiveLimitsV3Builder, SetManagerWithdrawDestinationBuilder, type SetManagerWithdrawDestinationIxArgs, type SetManagerWithdrawDestinationTxArgs, SetProtocolFeeBuilder, type SetProtocolFeeIxArgs, type SetProtocolFeeTxArgs, SetVaultConfigBuilder, type SetVaultConfigIxArgs, type SetVaultConfigTxArgs, SettleIncentiveV3Builder, type SettleIncentiveV3IxArgs, type SettleIncentiveV3TxArgs, type SettleVaultParams, type SettleVaultResult, type SettlementSimulation, type SettlementSimulationSnapshot, type SimulateDryRunSettlementParams, type SimulateSettlementArgs, type SimulatedShareClass, SquadsProposalExecutionSimulationError, type SquadsProposalUpload, type SquadsWalletRouteConfig, type StaleBalanceChangeBypass, StaticPositionProvider, SubmitIncentiveBuilder, type SubmitIncentiveIxArgs, type SubmitIncentiveTxArgs, TOKEN_PROGRAM, TOKEN_PROGRAM_ID, type TimelockSettlementKind, type TimelockSettlementOptions, type TimelockSettlementRecord, TimelockSettlementService, type TimelockSettlementSummary, type TrackedAccountValue, type TrancheKindArgs, type TransactionBuilder, TransactionClient, USDC_MINT, USD_STAR_JUNIOR_MINT, USD_STAR_MINT, USD_STAR_PRINCIPAL_MINT, type UpdateAccountParams, UpdateAssetPriceBuilder, type UpdateAssetPriceIxArgs, type UpdateAssetPriceTxArgs, UpdateConsensusOracleBuilder, type UpdateConsensusOracleIxArgs, type UpdateConsensusOracleTxArgs, UpdateConsensusSignersBuilder, type UpdateConsensusSignersIxArgs, type UpdateConsensusSignersTxArgs, type UpdateDynamicAprParams, UpdateTrancheConfigBuilder, type UpdateTrancheConfigIxArgs, type UpdateTrancheConfigTxArgs, VAULT_CACHE_CATEGORY, VAULT_CREATOR_WHITELIST, VAULT_ENVIRONMENTS, VAULT_ORACLE_CACHE_CATEGORY, VAULT_PROGRAM_ID, VAULT_PROGRAM_IDS, VAULT_PROGRAM_PUBLIC_KEY, VAULT_ROLE_UPDATE_TIMELOCK_SECS, VAULT_TRANCHE_STATE_CACHE_CATEGORY, VAULT_TRANCHE_WITHDRAWAL_QUEUE_CACHE_CATEGORY, type Vault, type VaultAccountData, VaultBuilderBase, type VaultBuilderContext, type VaultCacheInvalidation, VaultClient, type VaultClientBundle, type VaultEnv, type VaultIncentiveAccount, type VaultIncentiveAccountData, type VaultIncentiveV3Account, type VaultIncentiveV3AccountData, type VaultOracleAccountData, type VaultOracleResult, type VaultPricingInputs, type VaultQuote, type VaultQuoteArgs, VaultQuoteClient, type VaultQuoteDirection, type VaultQuoteShareClass, VaultReallocationBuilder, type VaultReallocationIxArgs, type VaultReallocationTxArgs, type VaultTrancheStateAccountData, type VaultTrancheWithdrawalQueueAccountData, type VaultTransactionPlan, WITHDRAWABLE_RESERVE_FLOOR_BPS, type WithdrawProtocolFeesIxArgs, type WithdrawProtocolFeesTxArgs, WithdrawalQueueService, type WithdrawalQueueSnapshot, type YieldAccount, type YieldAccountSnapshot, type YieldCalculationLog, type YieldCashflow, type YieldPaymentResponse, type YieldPaymentSnapshot, type YieldTracker, type YieldValuationModel, accountingUnitPriceToUsd, addCashflowUpdate, applyEffectiveApy, assertNoLargeBalanceChanges, assertNoUnconfirmedYieldPayments, buildHoldingUpdate, buildMarginfiWithdrawInteraction, buildNestDepositRequest, buildNestWithdrawalRequest, buildUpdates, candidateGrossNav, coerceBool, collectSamples, confirmYieldPayment, createAccount, createLiveConsensusOracleDeps, createRpcFromConnection, createTokenMint, createTokenMintIxs, createVaultClient, createYieldPayment, dateToStr, decodeNestDepositRequest, decodeNestWithdrawalRequest, decodePendingConsensusSigners, defaultKeypairPath, deleteAccount, discoverVaultsForSigner, fetchExternalPositions, fetchNestRedemptionQuote, fetchNestRedemptionStatus, fetchNestTokenPrice, fetchReceiptMints, filterTargetHoldings, findLargeBalanceChanges, findSquadsWalletRoute, formatSettlementSimulation, fromUiAmount, gatherPricingInputs, getAccount, getAccounts, getAprYield, getBalance, getCashflows, getIncentiveRecipientShareAtas, getIncentiveRecipients, getIncentiveReportRecipients, getIncentiveTotals, getIncentiveV3OracleState, getIncentiveV3RecipientShareAtas, getIncentiveV3Recipients, getIncentiveV3Totals, getNavValue, getRpcUrl, getTotalOutstandingYield, getTotalTrackedValue, getTotalYield, getTrackedValue, getVaultProgramId, getYield, getYieldPayments, indexConfigByMint, isNavAccountBalance, isNavAccountValue, isNavYieldAccount, isVaultEnv, keypairAddress, loadKeypair, logProspectiveApy, makeProvider, managerReconciliationStateKey, mintTokensTo, mints, mostFrequent, parseExternalLiquidityRefs, planRebalance, prepareSquadsProposalUpload, prepareVaultTransaction, previousPhysicalNav, priceInAccountingUnit, readI64LE, readSplMintSupply, reconcileManagerWalletBalances, refreshLiveOraclePrices, resolveExternalWithdraw, resolveKeypairPath, resolveSquadsWalletRoute, resolveTrackedAmounts, roundToNextUtcMidnight, runLiveConsensusOracle, selectReportableHoldings, settleVault, signerInOracleData, simulateConsensusOracleSettlement, simulateDryRunSettlement, simulateSquadsProposalExecution, sumPositionsByMint, systemClock, toBigInt, toUiAmount, toWeb3AccountMeta, trackedValueFromResponse, updateAccount, updateDynamicApr, validateSquadsWalletRoutes, variantName, vaultAuthorityForWallet, withDiscoveredYieldAccounts };
|
package/dist/index.js
CHANGED
|
@@ -149,7 +149,7 @@ var require_compat = __commonJS({
|
|
|
149
149
|
exports2.fromWeb3PublicKey = fromWeb3PublicKey;
|
|
150
150
|
exports2.toWeb3PublicKey = toWeb3PublicKey;
|
|
151
151
|
exports2.asWeb3PublicKey = asWeb3PublicKey2;
|
|
152
|
-
exports2.toKitInstruction =
|
|
152
|
+
exports2.toKitInstruction = toKitInstruction36;
|
|
153
153
|
exports2.fromKitInstruction = fromKitInstruction3;
|
|
154
154
|
var kit_1 = require("@solana/kit");
|
|
155
155
|
var web3_js_1 = require("@solana/web3.js");
|
|
@@ -165,7 +165,7 @@ var require_compat = __commonJS({
|
|
|
165
165
|
exports2.toAddress = fromWeb3PublicKey;
|
|
166
166
|
exports2.fromWeb3Pk = fromWeb3PublicKey;
|
|
167
167
|
exports2.toWeb3Pk = toWeb3PublicKey;
|
|
168
|
-
function
|
|
168
|
+
function toKitInstruction36(ix) {
|
|
169
169
|
return {
|
|
170
170
|
programAddress: ix.programId.toBase58(),
|
|
171
171
|
data: new Uint8Array(ix.data),
|
|
@@ -253,9 +253,9 @@ var require_meta = __commonJS({
|
|
|
253
253
|
exports2.toCustomAccountMeta = toCustomAccountMeta;
|
|
254
254
|
exports2.toCustomAccountMetaFromWeb3AccountMeta = toCustomAccountMetaFromWeb3AccountMeta;
|
|
255
255
|
var roles_1 = require_roles();
|
|
256
|
-
function toCustomAccountMeta(
|
|
256
|
+
function toCustomAccountMeta(address15, isWritable, requiredAtaDetails, isSigner) {
|
|
257
257
|
const role = (0, roles_1.getAccountRole)(isWritable ?? false, isSigner ?? false);
|
|
258
|
-
return { address:
|
|
258
|
+
return { address: address15, role, isRequiredAta: requiredAtaDetails };
|
|
259
259
|
}
|
|
260
260
|
function toCustomAccountMetaFromWeb3AccountMeta(web3AccountMeta) {
|
|
261
261
|
return toCustomAccountMeta(web3AccountMeta.pubkey.toBase58(), web3AccountMeta.isWritable, void 0, web3AccountMeta.isSigner);
|
|
@@ -1236,8 +1236,8 @@ var require_cpiClient = __commonJS({
|
|
|
1236
1236
|
var kit_1 = require("@solana/kit");
|
|
1237
1237
|
var common_1 = require_dist();
|
|
1238
1238
|
var constants_1 = require_constants3();
|
|
1239
|
-
function account(
|
|
1240
|
-
return { address:
|
|
1239
|
+
function account(address15, role) {
|
|
1240
|
+
return { address: address15, role };
|
|
1241
1241
|
}
|
|
1242
1242
|
function requiredAddress(value, label) {
|
|
1243
1243
|
if (!value) {
|
|
@@ -1326,7 +1326,7 @@ var require_cpiClient = __commonJS({
|
|
|
1326
1326
|
});
|
|
1327
1327
|
const bankAndOracleRemainingAccounts = [
|
|
1328
1328
|
account(this.accounts.bank, kit_1.AccountRole.READONLY),
|
|
1329
|
-
...this.accounts.oracleAccounts.map((
|
|
1329
|
+
...this.accounts.oracleAccounts.map((address15) => account(address15, kit_1.AccountRole.READONLY))
|
|
1330
1330
|
];
|
|
1331
1331
|
return {
|
|
1332
1332
|
cpiType: params.cpiType ?? common_1.CpiTypes.MARGINFI_WITHDRAW,
|
|
@@ -2978,12 +2978,12 @@ var require_routePreInstructions = __commonJS({
|
|
|
2978
2978
|
if (existingAta.value) {
|
|
2979
2979
|
continue;
|
|
2980
2980
|
}
|
|
2981
|
-
instructions2.push(
|
|
2981
|
+
instructions2.push(toKitInstruction36((0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(new web3_js_1.PublicKey(payer), new web3_js_1.PublicKey(ata), new web3_js_1.PublicKey(user), new web3_js_1.PublicKey(mint), new web3_js_1.PublicKey(tokenProgram), spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID)));
|
|
2982
2982
|
postSuccessCacheInvalidations.push({ address: ata });
|
|
2983
2983
|
}
|
|
2984
2984
|
return { instructions: instructions2, postSuccessCacheInvalidations };
|
|
2985
2985
|
}
|
|
2986
|
-
function
|
|
2986
|
+
function toKitInstruction36(ix) {
|
|
2987
2987
|
return {
|
|
2988
2988
|
programAddress: ix.programId.toBase58(),
|
|
2989
2989
|
accounts: ix.keys.map((account) => ({
|
|
@@ -3302,7 +3302,7 @@ __export(index_exports, {
|
|
|
3302
3302
|
DEFAULT_JUNIOR_WITHDRAWAL_LOCKUP_SECS: () => DEFAULT_JUNIOR_WITHDRAWAL_LOCKUP_SECS,
|
|
3303
3303
|
DEFAULT_MAX_ACCEPTABLE_APY_BPS: () => DEFAULT_MAX_ACCEPTABLE_APY_BPS,
|
|
3304
3304
|
DEFAULT_MAX_ACCOUNTS: () => DEFAULT_MAX_ACCOUNTS,
|
|
3305
|
-
DEFAULT_MINTS: () =>
|
|
3305
|
+
DEFAULT_MINTS: () => import_common62.DEFAULT_MINTS,
|
|
3306
3306
|
DEFAULT_MIN_AMOUNT_UI: () => DEFAULT_MIN_AMOUNT_UI,
|
|
3307
3307
|
DEFAULT_ORACLE_STALENESS_THRESHOLD_SECS: () => DEFAULT_ORACLE_STALENESS_THRESHOLD_SECS,
|
|
3308
3308
|
DEFAULT_PRICE_ORACLE_ACCOUNT: () => DEFAULT_PRICE_ORACLE_ACCOUNT,
|
|
@@ -3311,6 +3311,7 @@ __export(index_exports, {
|
|
|
3311
3311
|
DEFAULT_REBALANCE_BAND_BPS: () => DEFAULT_REBALANCE_BAND_BPS,
|
|
3312
3312
|
DEFAULT_SLIPPAGE_BPS: () => DEFAULT_SLIPPAGE_BPS,
|
|
3313
3313
|
DEFAULT_TARGET_LOCAL_BPS: () => DEFAULT_TARGET_LOCAL_BPS,
|
|
3314
|
+
DEFAULT_TARGET_LOCAL_USDC_TVL_BPS: () => DEFAULT_TARGET_LOCAL_USDC_TVL_BPS,
|
|
3314
3315
|
DEFAULT_VAULT_ID: () => DEFAULT_VAULT_ID,
|
|
3315
3316
|
DisableCircuitBreakerBuilder: () => DisableCircuitBreakerBuilder,
|
|
3316
3317
|
DistributeIncentiveBuilder: () => DistributeIncentiveBuilder,
|
|
@@ -3351,7 +3352,7 @@ __export(index_exports, {
|
|
|
3351
3352
|
ManagerRedepositAssetBuilder: () => ManagerRedepositAssetBuilder,
|
|
3352
3353
|
ManagerWithdrawAssetBuilder: () => ManagerWithdrawAssetBuilder,
|
|
3353
3354
|
MarginfiPositionProvider: () => MarginfiPositionProvider,
|
|
3354
|
-
MintRegistry: () =>
|
|
3355
|
+
MintRegistry: () => import_common62.MintRegistry,
|
|
3355
3356
|
MockYieldTracker: () => MockYieldTracker,
|
|
3356
3357
|
NEST_API_BASE_URL: () => import_nest2.NEST_API_BASE_URL,
|
|
3357
3358
|
NEST_RWA_SHARE_MINT: () => NEST_RWA_SHARE_MINT,
|
|
@@ -3412,6 +3413,7 @@ __export(index_exports, {
|
|
|
3412
3413
|
VaultClient: () => VaultClient,
|
|
3413
3414
|
VaultQuoteClient: () => VaultQuoteClient,
|
|
3414
3415
|
VaultReallocationBuilder: () => VaultReallocationBuilder,
|
|
3416
|
+
WITHDRAWABLE_RESERVE_FLOOR_BPS: () => WITHDRAWABLE_RESERVE_FLOOR_BPS,
|
|
3415
3417
|
WithdrawalQueueService: () => WithdrawalQueueService,
|
|
3416
3418
|
accountingUnitPriceToUsd: () => accountingUnitPriceToUsd,
|
|
3417
3419
|
addCashflowUpdate: () => addCashflowUpdate,
|
|
@@ -3421,6 +3423,7 @@ __export(index_exports, {
|
|
|
3421
3423
|
assertNoUnconfirmedYieldPayments: () => assertNoUnconfirmedYieldPayments,
|
|
3422
3424
|
buildHoldingUpdate: () => buildHoldingUpdate,
|
|
3423
3425
|
buildMarginfiWithdrawInteraction: () => buildMarginfiWithdrawInteraction,
|
|
3426
|
+
buildNestDepositRequest: () => buildNestDepositRequest,
|
|
3424
3427
|
buildNestWithdrawalRequest: () => buildNestWithdrawalRequest,
|
|
3425
3428
|
buildUpdates: () => buildUpdates,
|
|
3426
3429
|
candidateGrossNav: () => candidateGrossNav,
|
|
@@ -3435,6 +3438,7 @@ __export(index_exports, {
|
|
|
3435
3438
|
createVaultClient: () => createVaultClient,
|
|
3436
3439
|
createYieldPayment: () => createYieldPayment,
|
|
3437
3440
|
dateToStr: () => dateToStr,
|
|
3441
|
+
decodeNestDepositRequest: () => decodeNestDepositRequest,
|
|
3438
3442
|
decodeNestWithdrawalRequest: () => decodeNestWithdrawalRequest,
|
|
3439
3443
|
decodePendingConsensusSigners: () => decodePendingConsensusSigners,
|
|
3440
3444
|
defaultKeypairPath: () => defaultKeypairPath,
|
|
@@ -3484,7 +3488,7 @@ __export(index_exports, {
|
|
|
3484
3488
|
makeProvider: () => makeProvider,
|
|
3485
3489
|
managerReconciliationStateKey: () => managerReconciliationStateKey,
|
|
3486
3490
|
mintTokensTo: () => mintTokensTo,
|
|
3487
|
-
mints: () =>
|
|
3491
|
+
mints: () => import_common62.mints,
|
|
3488
3492
|
mostFrequent: () => mostFrequent,
|
|
3489
3493
|
parseExternalLiquidityRefs: () => parseExternalLiquidityRefs,
|
|
3490
3494
|
planRebalance: () => planRebalance,
|
|
@@ -17840,9 +17844,13 @@ async function simulateSquadsProposalExecution(args) {
|
|
|
17840
17844
|
return value;
|
|
17841
17845
|
}
|
|
17842
17846
|
async function prepareVaultTransaction(args) {
|
|
17843
|
-
const { connection, proposer
|
|
17847
|
+
const { connection, proposer } = args;
|
|
17848
|
+
let instructions2 = [...args.instructions];
|
|
17849
|
+
const ephemeralKeys = args.ephemeralSignerKeys ?? [];
|
|
17844
17850
|
const route = findSquadsWalletRoute(proposer, args.squadsRoutes ?? []);
|
|
17845
17851
|
if (!route) {
|
|
17852
|
+
if (ephemeralKeys.length)
|
|
17853
|
+
throw new Error("Ephemeral signers require a Squads route");
|
|
17846
17854
|
return {
|
|
17847
17855
|
kind: "direct",
|
|
17848
17856
|
transaction: new import_web324.Transaction().add(...instructions2),
|
|
@@ -17870,6 +17878,44 @@ async function prepareVaultTransaction(args) {
|
|
|
17870
17878
|
);
|
|
17871
17879
|
}
|
|
17872
17880
|
const transactionIndex = BigInt(multisig.transactionIndex.toString()) + 1n;
|
|
17881
|
+
if (ephemeralKeys.length > 255 || new Set(ephemeralKeys.map(String)).size !== ephemeralKeys.length) {
|
|
17882
|
+
throw new Error("Invalid Squads ephemeral signer keys");
|
|
17883
|
+
}
|
|
17884
|
+
const [transactionPda] = squads.getTransactionPda({
|
|
17885
|
+
multisigPda: route.multisigPda,
|
|
17886
|
+
index: transactionIndex
|
|
17887
|
+
});
|
|
17888
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
17889
|
+
ephemeralKeys.forEach((key, index) => {
|
|
17890
|
+
if (key.equals(proposer) || key.equals(route.vaultPda) || !instructions2.some(
|
|
17891
|
+
(ix) => ix.keys.some((meta) => meta.isSigner && meta.pubkey.equals(key))
|
|
17892
|
+
) || instructions2.some(
|
|
17893
|
+
(ix) => ix.programId.equals(key) || ix.data.includes(key.toBuffer())
|
|
17894
|
+
)) {
|
|
17895
|
+
throw new Error(
|
|
17896
|
+
"Ephemeral signer must be a separate account-meta signer, never embedded in instruction data"
|
|
17897
|
+
);
|
|
17898
|
+
}
|
|
17899
|
+
replacements.set(
|
|
17900
|
+
key.toBase58(),
|
|
17901
|
+
squads.getEphemeralSignerPda({
|
|
17902
|
+
transactionPda,
|
|
17903
|
+
ephemeralSignerIndex: index
|
|
17904
|
+
})[0]
|
|
17905
|
+
);
|
|
17906
|
+
});
|
|
17907
|
+
if (replacements.size) {
|
|
17908
|
+
instructions2 = instructions2.map(
|
|
17909
|
+
(ix) => new import_web324.TransactionInstruction({
|
|
17910
|
+
programId: ix.programId,
|
|
17911
|
+
data: ix.data,
|
|
17912
|
+
keys: ix.keys.map((meta) => ({
|
|
17913
|
+
...meta,
|
|
17914
|
+
pubkey: replacements.get(meta.pubkey.toBase58()) ?? meta.pubkey
|
|
17915
|
+
}))
|
|
17916
|
+
})
|
|
17917
|
+
);
|
|
17918
|
+
}
|
|
17873
17919
|
const { blockhash } = await connection.getLatestBlockhash("confirmed");
|
|
17874
17920
|
if (!args.skipSimulation) {
|
|
17875
17921
|
await simulateSquadsProposalExecution({
|
|
@@ -17890,7 +17936,7 @@ async function prepareVaultTransaction(args) {
|
|
|
17890
17936
|
transactionIndex,
|
|
17891
17937
|
creator: proposer,
|
|
17892
17938
|
vaultIndex: route.vaultIndex,
|
|
17893
|
-
ephemeralSigners:
|
|
17939
|
+
ephemeralSigners: ephemeralKeys.length,
|
|
17894
17940
|
transactionMessage,
|
|
17895
17941
|
addressLookupTableAccounts: args.addressLookupTableAccounts,
|
|
17896
17942
|
memo: route.memo
|
|
@@ -21730,6 +21776,7 @@ var import_common57 = __toESM(require_dist());
|
|
|
21730
21776
|
var import_marginfi3 = __toESM(require_dist2());
|
|
21731
21777
|
var DEFAULT_MIN_AMOUNT_UI = 1;
|
|
21732
21778
|
var DEFAULT_TARGET_LOCAL_BPS = 50;
|
|
21779
|
+
var DEFAULT_TARGET_LOCAL_USDC_TVL_BPS = 150;
|
|
21733
21780
|
var DEFAULT_REBALANCE_BAND_BPS = 2e3;
|
|
21734
21781
|
var BPS_DENOMINATOR4 = 10000n;
|
|
21735
21782
|
function toRawAmount(uiAmount, decimals) {
|
|
@@ -21773,11 +21820,12 @@ function planRebalance(params) {
|
|
|
21773
21820
|
localAmount,
|
|
21774
21821
|
externalAmount,
|
|
21775
21822
|
targetLocalBps,
|
|
21823
|
+
targetLocalAmount,
|
|
21776
21824
|
rebalanceBandBps,
|
|
21777
21825
|
minRaw
|
|
21778
21826
|
} = params;
|
|
21779
21827
|
const total = localAmount + externalAmount;
|
|
21780
|
-
const targetLocal = total * BigInt(Math.round(targetLocalBps)) / BPS_DENOMINATOR4;
|
|
21828
|
+
const targetLocal = targetLocalAmount ?? total * BigInt(Math.round(targetLocalBps)) / BPS_DENOMINATOR4;
|
|
21781
21829
|
const band = targetLocal * BigInt(Math.round(rebalanceBandBps)) / BPS_DENOMINATOR4;
|
|
21782
21830
|
const threshold = band > minRaw ? band : minRaw;
|
|
21783
21831
|
if (localAmount > targetLocal) {
|
|
@@ -21805,6 +21853,7 @@ var ExternalLiquidityIntegrityService = class {
|
|
|
21805
21853
|
const dryRun = opts.dryRun ?? false;
|
|
21806
21854
|
const minAmountUi = opts.minAmountUi ?? DEFAULT_MIN_AMOUNT_UI;
|
|
21807
21855
|
const targetLocalBps = opts.targetLocalBps ?? DEFAULT_TARGET_LOCAL_BPS;
|
|
21856
|
+
const targetLocalUsdcTvlBps = opts.targetLocalUsdcTvlBps ?? DEFAULT_TARGET_LOCAL_USDC_TVL_BPS;
|
|
21808
21857
|
const rebalanceBandBps = opts.rebalanceBandBps ?? DEFAULT_REBALANCE_BAND_BPS;
|
|
21809
21858
|
if (dryRun) {
|
|
21810
21859
|
log(
|
|
@@ -21812,7 +21861,12 @@ var ExternalLiquidityIntegrityService = class {
|
|
|
21812
21861
|
);
|
|
21813
21862
|
}
|
|
21814
21863
|
log(`Minimum rebalance: ${minAmountUi} token(s) (~$${minAmountUi})`);
|
|
21815
|
-
log(
|
|
21864
|
+
log(
|
|
21865
|
+
`Target local USDC: ${targetLocalUsdcTvlBps / 100}% of total vault TVL`
|
|
21866
|
+
);
|
|
21867
|
+
log(
|
|
21868
|
+
`Target local share: ${targetLocalBps / 100}% of each non-USDC holding`
|
|
21869
|
+
);
|
|
21816
21870
|
log(
|
|
21817
21871
|
`Rebalance band: ${rebalanceBandBps / 100}% of target (${targetLocalBps * (1 - rebalanceBandBps / 1e4) / 100}%\u2013${targetLocalBps * (1 + rebalanceBandBps / 1e4) / 100}% of holding)`
|
|
21818
21872
|
);
|
|
@@ -21832,7 +21886,13 @@ var ExternalLiquidityIntegrityService = class {
|
|
|
21832
21886
|
vaultState,
|
|
21833
21887
|
hwManager,
|
|
21834
21888
|
log,
|
|
21835
|
-
{
|
|
21889
|
+
{
|
|
21890
|
+
dryRun,
|
|
21891
|
+
minAmountUi,
|
|
21892
|
+
targetLocalBps,
|
|
21893
|
+
targetLocalUsdcTvlBps,
|
|
21894
|
+
rebalanceBandBps
|
|
21895
|
+
}
|
|
21836
21896
|
);
|
|
21837
21897
|
summary.vaultsProcessed++;
|
|
21838
21898
|
summary.totalDeposited += result.deposited;
|
|
@@ -21850,6 +21910,7 @@ var ExternalLiquidityIntegrityService = class {
|
|
|
21850
21910
|
const dryRun = opts.dryRun ?? false;
|
|
21851
21911
|
const minAmountUi = opts.minAmountUi ?? DEFAULT_MIN_AMOUNT_UI;
|
|
21852
21912
|
const targetLocalBps = opts.targetLocalBps ?? DEFAULT_TARGET_LOCAL_BPS;
|
|
21913
|
+
const targetLocalUsdcTvlBps = opts.targetLocalUsdcTvlBps ?? DEFAULT_TARGET_LOCAL_USDC_TVL_BPS;
|
|
21853
21914
|
const rebalanceBandBps = opts.rebalanceBandBps ?? DEFAULT_REBALANCE_BAND_BPS;
|
|
21854
21915
|
const result = {
|
|
21855
21916
|
vault,
|
|
@@ -21898,10 +21959,27 @@ var ExternalLiquidityIntegrityService = class {
|
|
|
21898
21959
|
const externalAmount = toBigInt3(holding.externalAmount);
|
|
21899
21960
|
const decimals = Number(holding.decimals ?? 0);
|
|
21900
21961
|
const minRaw = toRawAmount(minAmountUi, decimals);
|
|
21962
|
+
let targetLocalAmount;
|
|
21963
|
+
if (mintAddress === import_common57.USDC_MINT) {
|
|
21964
|
+
const tvl = toBigInt3(vaultState.accounting.tvl);
|
|
21965
|
+
const price = toBigInt3(holding.price);
|
|
21966
|
+
const stalenessThreshold = Number(toBigInt3(vaultState.config.priceStalenessThresholdSecs)) || DEFAULT_PRICE_STALENESS_THRESHOLD_SECS;
|
|
21967
|
+
if (tvl <= 0n || price <= 0n || Math.floor(Date.now() / 1e3) - Number(toBigInt3(holding.lastUpdateTs)) > stalenessThreshold) {
|
|
21968
|
+
log(
|
|
21969
|
+
`Vault ${vault}: cannot size local USDC target without TVL and a fresh USDC price \u2014 skipping`
|
|
21970
|
+
);
|
|
21971
|
+
result.skipped++;
|
|
21972
|
+
continue;
|
|
21973
|
+
}
|
|
21974
|
+
const numerator = tvl * BigInt(Math.round(targetLocalUsdcTvlBps)) * 10n ** BigInt(decimals);
|
|
21975
|
+
const denominator = BPS_DENOMINATOR4 * price;
|
|
21976
|
+
targetLocalAmount = (numerator + denominator - 1n) / denominator;
|
|
21977
|
+
}
|
|
21901
21978
|
const plan = planRebalance({
|
|
21902
21979
|
localAmount,
|
|
21903
21980
|
externalAmount,
|
|
21904
21981
|
targetLocalBps,
|
|
21982
|
+
targetLocalAmount,
|
|
21905
21983
|
rebalanceBandBps,
|
|
21906
21984
|
minRaw
|
|
21907
21985
|
});
|
|
@@ -22052,6 +22130,7 @@ var import_jupiter2 = __toESM(require_dist4());
|
|
|
22052
22130
|
var import_marginfi4 = __toESM(require_dist2());
|
|
22053
22131
|
var IDLE_RESERVE_FLOOR_BPS = 400;
|
|
22054
22132
|
var IDLE_RESERVE_TARGET_BPS = 500;
|
|
22133
|
+
var WITHDRAWABLE_RESERVE_FLOOR_BPS = 150;
|
|
22055
22134
|
var DEFAULT_SLIPPAGE_BPS = 30;
|
|
22056
22135
|
var DEFAULT_CU_PRICE_MICRO_LAMPORTS = 1e4;
|
|
22057
22136
|
var DEFAULT_MAX_ACCOUNTS = 20;
|
|
@@ -22205,13 +22284,20 @@ var IdleLiquidityService = class {
|
|
|
22205
22284
|
}
|
|
22206
22285
|
localAmount = tokenAccount.amount;
|
|
22207
22286
|
}
|
|
22208
|
-
const
|
|
22209
|
-
|
|
22210
|
-
|
|
22287
|
+
const slotIndex = vaultState.externalLiquidity.findIndex(
|
|
22288
|
+
(slot) => slot.data[0] === 1
|
|
22289
|
+
);
|
|
22290
|
+
if (slotIndex === -1) {
|
|
22291
|
+
return {
|
|
22292
|
+
localAmount,
|
|
22293
|
+
marginfiAmount: 0n,
|
|
22294
|
+
withdrawableMarginfiAmount: 0n,
|
|
22295
|
+
slotIndex
|
|
22296
|
+
};
|
|
22211
22297
|
}
|
|
22212
|
-
|
|
22213
|
-
if (data
|
|
22214
|
-
throw new Error(
|
|
22298
|
+
const data = vaultState.externalLiquidity[slotIndex].data;
|
|
22299
|
+
if (data.length < 40) {
|
|
22300
|
+
throw new Error(`Invalid Project0 external-liquidity slot ${slotIndex}`);
|
|
22215
22301
|
}
|
|
22216
22302
|
const positionPk = new import_web334.PublicKey(new Uint8Array(data.slice(8, 40)));
|
|
22217
22303
|
const positionInfo = await connection.getAccountInfo(
|
|
@@ -22220,7 +22306,7 @@ var IdleLiquidityService = class {
|
|
|
22220
22306
|
);
|
|
22221
22307
|
if (!positionInfo || !positionInfo.owner.equals(new import_web334.PublicKey(import_marginfi4.MARGINFI_PROGRAM_ID))) {
|
|
22222
22308
|
throw new Error(
|
|
22223
|
-
`Invalid
|
|
22309
|
+
`Invalid Project0 slot-${slotIndex} account: ${positionPk.toBase58()}`
|
|
22224
22310
|
);
|
|
22225
22311
|
}
|
|
22226
22312
|
const marginfi = await (0, import_marginfi4.createMarginfiReadClient)(
|
|
@@ -22229,9 +22315,10 @@ var IdleLiquidityService = class {
|
|
|
22229
22315
|
);
|
|
22230
22316
|
const position = await import_marginfi_client_v2.MarginfiAccountWrapper.fetch(positionPk, marginfi);
|
|
22231
22317
|
if (!position.authority.equals(vaultPk)) {
|
|
22232
|
-
throw new Error(
|
|
22318
|
+
throw new Error(`Project0 slot-${slotIndex} authority is not the vault`);
|
|
22233
22319
|
}
|
|
22234
22320
|
let marginfiAmount = 0n;
|
|
22321
|
+
let withdrawableMarginfiAmount = 0n;
|
|
22235
22322
|
for (const balance of position.activeBalances) {
|
|
22236
22323
|
const bank = marginfi.getBankByPk(balance.bankPk);
|
|
22237
22324
|
if (!bank) {
|
|
@@ -22240,11 +22327,22 @@ var IdleLiquidityService = class {
|
|
|
22240
22327
|
);
|
|
22241
22328
|
}
|
|
22242
22329
|
if (!bank.mint.equals(usdcMint)) continue;
|
|
22243
|
-
|
|
22330
|
+
const deposited = BigInt(
|
|
22244
22331
|
balance.computeQuantity(bank).assets.toFixed(0, 1)
|
|
22245
22332
|
);
|
|
22333
|
+
const available = BigInt(
|
|
22334
|
+
bank.getTotalAssetQuantity().minus(bank.getTotalLiabilityQuantity()).toFixed(0, 1)
|
|
22335
|
+
);
|
|
22336
|
+
const bankLiquidity = available > 0n ? available : 0n;
|
|
22337
|
+
marginfiAmount += deposited;
|
|
22338
|
+
withdrawableMarginfiAmount += deposited < bankLiquidity ? deposited : bankLiquidity;
|
|
22246
22339
|
}
|
|
22247
|
-
return {
|
|
22340
|
+
return {
|
|
22341
|
+
localAmount,
|
|
22342
|
+
marginfiAmount,
|
|
22343
|
+
withdrawableMarginfiAmount,
|
|
22344
|
+
slotIndex
|
|
22345
|
+
};
|
|
22248
22346
|
}
|
|
22249
22347
|
/**
|
|
22250
22348
|
* Decide whether a top-up is warranted. Returns either a terminal `result`
|
|
@@ -22259,6 +22357,8 @@ var IdleLiquidityService = class {
|
|
|
22259
22357
|
tvl,
|
|
22260
22358
|
idleValue: 0n,
|
|
22261
22359
|
idleBps: 0,
|
|
22360
|
+
withdrawableValue: 0n,
|
|
22361
|
+
withdrawableBps: 0,
|
|
22262
22362
|
shortfallUsdc: 0n,
|
|
22263
22363
|
pstSpent: 0n,
|
|
22264
22364
|
usdcReceived: 0n
|
|
@@ -22303,7 +22403,16 @@ var IdleLiquidityService = class {
|
|
|
22303
22403
|
const idleAmount = balances.localAmount + balances.marginfiAmount;
|
|
22304
22404
|
const idleValue = holdingValue2(usdc, idleAmount);
|
|
22305
22405
|
const idleBps = Number(idleValue * 10000n / tvl);
|
|
22306
|
-
const
|
|
22406
|
+
const withdrawableAmount = balances.localAmount + balances.withdrawableMarginfiAmount;
|
|
22407
|
+
const withdrawableValue = holdingValue2(usdc, withdrawableAmount);
|
|
22408
|
+
const withdrawableBps = Number(withdrawableValue * 10000n / tvl);
|
|
22409
|
+
const base = {
|
|
22410
|
+
...empty,
|
|
22411
|
+
idleValue,
|
|
22412
|
+
idleBps,
|
|
22413
|
+
withdrawableValue,
|
|
22414
|
+
withdrawableBps
|
|
22415
|
+
};
|
|
22307
22416
|
log(
|
|
22308
22417
|
`Vault ${vault}: idle USDC ${formatUi2(
|
|
22309
22418
|
idleAmount,
|
|
@@ -22311,13 +22420,21 @@ var IdleLiquidityService = class {
|
|
|
22311
22420
|
)} (vault token account ${formatUi2(
|
|
22312
22421
|
balances.localAmount,
|
|
22313
22422
|
usdc.decimals
|
|
22314
|
-
)} +
|
|
22423
|
+
)} + Project0 slot ${balances.slotIndex} ${formatUi2(
|
|
22315
22424
|
balances.marginfiAmount,
|
|
22316
22425
|
usdc.decimals
|
|
22317
22426
|
)}) = ${idleBps}bps of TVL (floor ${IDLE_RESERVE_FLOOR_BPS}bps, target ${IDLE_RESERVE_TARGET_BPS}bps)`
|
|
22318
22427
|
);
|
|
22319
|
-
|
|
22320
|
-
|
|
22428
|
+
log(
|
|
22429
|
+
`Vault ${vault}: withdrawable USDC ${formatUi2(
|
|
22430
|
+
withdrawableAmount,
|
|
22431
|
+
usdc.decimals
|
|
22432
|
+
)} = ${withdrawableBps}bps of TVL (floor ${WITHDRAWABLE_RESERVE_FLOOR_BPS}bps)`
|
|
22433
|
+
);
|
|
22434
|
+
const idleBelowFloor = idleBps < IDLE_RESERVE_FLOOR_BPS;
|
|
22435
|
+
const withdrawableBelowFloor = withdrawableBps < WITHDRAWABLE_RESERVE_FLOOR_BPS;
|
|
22436
|
+
if (!idleBelowFloor && !withdrawableBelowFloor) {
|
|
22437
|
+
const reason = `idle USDC ${idleBps}bps and withdrawable USDC ${withdrawableBps}bps are at or above their floors`;
|
|
22321
22438
|
return { result: { ...base, status: "above-floor", reason } };
|
|
22322
22439
|
}
|
|
22323
22440
|
for (const [name, holding] of [
|
|
@@ -22330,8 +22447,11 @@ var IdleLiquidityService = class {
|
|
|
22330
22447
|
return { result: { ...base, status: "rebalance-cooldown", reason } };
|
|
22331
22448
|
}
|
|
22332
22449
|
}
|
|
22333
|
-
const targetValue = tvl * BigInt(IDLE_RESERVE_TARGET_BPS) / 10000n;
|
|
22334
|
-
|
|
22450
|
+
const targetValue = (tvl * BigInt(IDLE_RESERVE_TARGET_BPS) + 9999n) / 10000n;
|
|
22451
|
+
const withdrawableTargetValue = (tvl * BigInt(WITHDRAWABLE_RESERVE_FLOOR_BPS) + 9999n) / 10000n;
|
|
22452
|
+
const idleShortfall = idleBelowFloor ? targetValue - idleValue : 0n;
|
|
22453
|
+
const withdrawableShortfall = withdrawableBelowFloor ? withdrawableTargetValue - withdrawableValue : 0n;
|
|
22454
|
+
let shortfallValue = idleShortfall > withdrawableShortfall ? idleShortfall : withdrawableShortfall;
|
|
22335
22455
|
const allowance = this.remainingRebalanceAllowance(vaultState, tvl, now);
|
|
22336
22456
|
if (allowance !== void 0 && allowance < shortfallValue) {
|
|
22337
22457
|
if (allowance === 0n) {
|
|
@@ -22344,7 +22464,7 @@ var IdleLiquidityService = class {
|
|
|
22344
22464
|
);
|
|
22345
22465
|
shortfallValue = allowance;
|
|
22346
22466
|
}
|
|
22347
|
-
const shortfallUsdc = shortfallValue * 10n ** BigInt(usdc.decimals) / usdc.price;
|
|
22467
|
+
const shortfallUsdc = (shortfallValue * 10n ** BigInt(usdc.decimals) + usdc.price - 1n) / usdc.price;
|
|
22348
22468
|
if (shortfallUsdc <= 0n) {
|
|
22349
22469
|
const reason = "computed shortfall rounds to zero";
|
|
22350
22470
|
return { result: { ...base, status: "above-floor", reason } };
|
|
@@ -22841,8 +22961,132 @@ async function decodeNestWithdrawalRequest(args) {
|
|
|
22841
22961
|
};
|
|
22842
22962
|
}
|
|
22843
22963
|
|
|
22844
|
-
// src/
|
|
22964
|
+
// src/services/nestDepositService.ts
|
|
22965
|
+
var import_kit19 = require("@solana/kit");
|
|
22966
|
+
var import_spl_token23 = require("@solana/spl-token");
|
|
22967
|
+
var import_web337 = require("@solana/web3.js");
|
|
22845
22968
|
var import_common61 = __toESM(require_dist());
|
|
22969
|
+
var import_nest5 = __toESM(require_dist3());
|
|
22970
|
+
var Usdc = new import_web337.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
|
|
22971
|
+
var Messenger = new import_web337.PublicKey("CCTPV2vPZJS2u2BBsUoscuikbYjnpFmbFsvVuJdgUMQe");
|
|
22972
|
+
var Transmitter = new import_web337.PublicKey(
|
|
22973
|
+
"CCTPV2Sm4AdWt5296sk4P66VBZ7bEhcARwFaaS9YPbeC"
|
|
22974
|
+
);
|
|
22975
|
+
var Router = Buffer.from(
|
|
22976
|
+
"0000000000000000000000007de01896d36bea9cf072ac64e41685418941d8be",
|
|
22977
|
+
"hex"
|
|
22978
|
+
);
|
|
22979
|
+
var Composer = Buffer.from("908dcb5531691c2124c54e30bb645cf11647090d", "hex");
|
|
22980
|
+
var BurnWithHook = Buffer.from([111, 245, 62, 131, 204, 108, 223, 155]);
|
|
22981
|
+
var PerenaAssetId = Buffer.from(
|
|
22982
|
+
"355750bed2d05a1eb92ab578335cc3ea6d572dd5f57a086088c68667f11e50d2",
|
|
22983
|
+
"hex"
|
|
22984
|
+
);
|
|
22985
|
+
var MintAndSend = Buffer.from("fe030ec4", "hex");
|
|
22986
|
+
async function buildNestDepositRequest(args) {
|
|
22987
|
+
if (args.rawAmountUsdc <= 0n || args.rawAmountUsdc > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
22988
|
+
throw new Error(
|
|
22989
|
+
"Nest deposit must be a positive, safely representable USDC base-unit amount"
|
|
22990
|
+
);
|
|
22991
|
+
}
|
|
22992
|
+
const options = args.apiOptions ?? {};
|
|
22993
|
+
const response = await (options.fetchFn ?? fetch)(
|
|
22994
|
+
`${(options.baseUrl ?? import_nest5.NEST_API_BASE_URL).replace(
|
|
22995
|
+
/\/$/,
|
|
22996
|
+
""
|
|
22997
|
+
)}/solana/nest/mint/build-tx`,
|
|
22998
|
+
{
|
|
22999
|
+
method: "POST",
|
|
23000
|
+
headers: { "Content-Type": "application/json" },
|
|
23001
|
+
signal: options.signal,
|
|
23002
|
+
body: JSON.stringify({
|
|
23003
|
+
rawAmountUsdc: Number(args.rawAmountUsdc),
|
|
23004
|
+
receiver: args.owner.toBase58(),
|
|
23005
|
+
nestVaultSlug: NEST_VAULT_SLUG,
|
|
23006
|
+
finality: "standard"
|
|
23007
|
+
})
|
|
23008
|
+
}
|
|
23009
|
+
);
|
|
23010
|
+
const payload = await response.json().catch(() => null);
|
|
23011
|
+
if (!response.ok)
|
|
23012
|
+
throw new Error(
|
|
23013
|
+
`Nest deposit API (${response.status}): ${typeof payload?.error === "string" ? payload.error : response.statusText}`
|
|
23014
|
+
);
|
|
23015
|
+
if (typeof payload?.data?.txBase64 !== "string")
|
|
23016
|
+
throw new Error("Nest API returned no deposit transaction");
|
|
23017
|
+
return decodeNestDepositRequest({ ...args, txBase64: payload.data.txBase64 });
|
|
23018
|
+
}
|
|
23019
|
+
async function decodeNestDepositRequest(args) {
|
|
23020
|
+
if (args.rawAmountUsdc <= 0n || args.rawAmountUsdc > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
23021
|
+
throw new Error(
|
|
23022
|
+
"Nest deposit must be a positive, safely representable USDC base-unit amount"
|
|
23023
|
+
);
|
|
23024
|
+
}
|
|
23025
|
+
const message2 = import_web337.VersionedTransaction.deserialize(
|
|
23026
|
+
Buffer.from(args.txBase64, "base64")
|
|
23027
|
+
).message;
|
|
23028
|
+
if (!message2.staticAccountKeys[0].equals(args.owner))
|
|
23029
|
+
throw new Error("Nest deposit payer must be the manager");
|
|
23030
|
+
const tables = await Promise.all(
|
|
23031
|
+
message2.addressTableLookups.map(async (lookup) => {
|
|
23032
|
+
const { value } = await args.connection.getAddressLookupTable(
|
|
23033
|
+
lookup.accountKey
|
|
23034
|
+
);
|
|
23035
|
+
if (!value)
|
|
23036
|
+
throw new Error(`Nest lookup table not found: ${lookup.accountKey}`);
|
|
23037
|
+
return value;
|
|
23038
|
+
})
|
|
23039
|
+
);
|
|
23040
|
+
const instructions2 = import_web337.TransactionMessage.decompile(message2, {
|
|
23041
|
+
addressLookupTableAccounts: tables
|
|
23042
|
+
}).instructions;
|
|
23043
|
+
const shareMint = new import_web337.PublicKey(NEST_RWA_SHARE_MINT);
|
|
23044
|
+
const shareAta = (0, import_spl_token23.getAssociatedTokenAddressSync)(shareMint, args.owner, true);
|
|
23045
|
+
const usdcAta = (0, import_spl_token23.getAssociatedTokenAddressSync)(Usdc, args.owner, true);
|
|
23046
|
+
let burn;
|
|
23047
|
+
for (const ix of instructions2) {
|
|
23048
|
+
if (ix.programId.equals(import_web337.ComputeBudgetProgram.programId)) continue;
|
|
23049
|
+
if (ix.programId.equals(import_spl_token23.ASSOCIATED_TOKEN_PROGRAM_ID)) {
|
|
23050
|
+
if (ix.data.length !== 1 || ix.data[0] !== 1 || !ix.keys[0]?.pubkey.equals(args.owner) || !ix.keys[1]?.pubkey.equals(shareAta) || !ix.keys[2]?.pubkey.equals(args.owner) || !ix.keys[3]?.pubkey.equals(shareMint) || !ix.keys[4]?.pubkey.equals(import_web337.SystemProgram.programId) || !ix.keys[5]?.pubkey.equals(import_spl_token23.TOKEN_PROGRAM_ID))
|
|
23051
|
+
throw new Error("Unexpected Nest deposit token account creation");
|
|
23052
|
+
continue;
|
|
23053
|
+
}
|
|
23054
|
+
const d = ix.data;
|
|
23055
|
+
const matches = (index, key) => ix.keys[index]?.pubkey.equals(key);
|
|
23056
|
+
if (burn || !ix.programId.equals(Messenger) || ix.keys.length !== 18 || d.length < 316 || !d.subarray(0, 8).equals(BurnWithHook) || d.readBigUInt64LE(8) !== args.rawAmountUsdc || d.readUInt32LE(16) !== 22 || !d.subarray(20, 52).equals(Router) || !d.subarray(52, 84).equals(Router) || d.readBigUInt64LE(84) !== 0n || d.readUInt32LE(92) !== 2e3 || d.readUInt32LE(96) !== d.length - 100 || !d.subarray(100, 120).equals(Composer) || !d.subarray(120, 124).equals(MintAndSend) || !d.subarray(124, 156).equals(PerenaAssetId) || BigInt(`0x${d.subarray(156, 188).toString("hex")}`) !== args.rawAmountUsdc || BigInt(`0x${d.subarray(188, 220).toString("hex")}`) !== 128n || !d.subarray(220, 252).equals(Buffer.concat([Buffer.alloc(12), Composer])) || BigInt(`0x${d.subarray(252, 284).toString("hex")}`) !== 30168n || !d.subarray(284, 316).equals(args.owner.toBuffer()) || !matches(0, args.owner) || !matches(3, usdcAta) || !matches(10, Usdc) || !matches(12, Transmitter) || !matches(13, Messenger) || !matches(14, import_spl_token23.TOKEN_PROGRAM_ID) || !matches(15, import_web337.SystemProgram.programId) || !matches(17, Messenger) || ![0, 1, 11].every((index) => ix.keys[index].isSigner) || ix.keys.some(
|
|
23057
|
+
(meta, index) => meta.isSigner && ![0, 1, 11].includes(index)
|
|
23058
|
+
)) {
|
|
23059
|
+
throw new Error(
|
|
23060
|
+
"Unexpected Nest deposit instruction, amount, or recipient"
|
|
23061
|
+
);
|
|
23062
|
+
}
|
|
23063
|
+
burn = ix;
|
|
23064
|
+
}
|
|
23065
|
+
if (!burn) throw new Error("Nest deposit must contain one CCTP burn");
|
|
23066
|
+
const eventKey = burn.keys[11].pubkey;
|
|
23067
|
+
if (eventKey.equals(args.owner) || burn.keys.some(
|
|
23068
|
+
(meta, index) => index !== 11 && meta.pubkey.equals(eventKey)
|
|
23069
|
+
)) {
|
|
23070
|
+
throw new Error("Nest deposit event signer must be a separate account");
|
|
23071
|
+
}
|
|
23072
|
+
burn.keys[1] = { pubkey: args.owner, isSigner: true, isWritable: true };
|
|
23073
|
+
return {
|
|
23074
|
+
instructions: [
|
|
23075
|
+
(0, import_spl_token23.createAssociatedTokenAccountIdempotentInstruction)(
|
|
23076
|
+
args.owner,
|
|
23077
|
+
shareAta,
|
|
23078
|
+
args.owner,
|
|
23079
|
+
shareMint
|
|
23080
|
+
),
|
|
23081
|
+
burn
|
|
23082
|
+
].map(import_common61.toKitInstruction),
|
|
23083
|
+
lookupTables: tables.map((table) => (0, import_kit19.address)(table.key.toBase58())),
|
|
23084
|
+
ephemeralSignerKeys: [eventKey]
|
|
23085
|
+
};
|
|
23086
|
+
}
|
|
23087
|
+
|
|
23088
|
+
// src/index.ts
|
|
23089
|
+
var import_common62 = __toESM(require_dist());
|
|
22846
23090
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22847
23091
|
0 && (module.exports = {
|
|
22848
23092
|
ASSET_DECIMALS,
|
|
@@ -22880,6 +23124,7 @@ var import_common61 = __toESM(require_dist());
|
|
|
22880
23124
|
DEFAULT_REBALANCE_BAND_BPS,
|
|
22881
23125
|
DEFAULT_SLIPPAGE_BPS,
|
|
22882
23126
|
DEFAULT_TARGET_LOCAL_BPS,
|
|
23127
|
+
DEFAULT_TARGET_LOCAL_USDC_TVL_BPS,
|
|
22883
23128
|
DEFAULT_VAULT_ID,
|
|
22884
23129
|
DisableCircuitBreakerBuilder,
|
|
22885
23130
|
DistributeIncentiveBuilder,
|
|
@@ -22981,6 +23226,7 @@ var import_common61 = __toESM(require_dist());
|
|
|
22981
23226
|
VaultClient,
|
|
22982
23227
|
VaultQuoteClient,
|
|
22983
23228
|
VaultReallocationBuilder,
|
|
23229
|
+
WITHDRAWABLE_RESERVE_FLOOR_BPS,
|
|
22984
23230
|
WithdrawalQueueService,
|
|
22985
23231
|
accountingUnitPriceToUsd,
|
|
22986
23232
|
addCashflowUpdate,
|
|
@@ -22990,6 +23236,7 @@ var import_common61 = __toESM(require_dist());
|
|
|
22990
23236
|
assertNoUnconfirmedYieldPayments,
|
|
22991
23237
|
buildHoldingUpdate,
|
|
22992
23238
|
buildMarginfiWithdrawInteraction,
|
|
23239
|
+
buildNestDepositRequest,
|
|
22993
23240
|
buildNestWithdrawalRequest,
|
|
22994
23241
|
buildUpdates,
|
|
22995
23242
|
candidateGrossNav,
|
|
@@ -23004,6 +23251,7 @@ var import_common61 = __toESM(require_dist());
|
|
|
23004
23251
|
createVaultClient,
|
|
23005
23252
|
createYieldPayment,
|
|
23006
23253
|
dateToStr,
|
|
23254
|
+
decodeNestDepositRequest,
|
|
23007
23255
|
decodeNestWithdrawalRequest,
|
|
23008
23256
|
decodePendingConsensusSigners,
|
|
23009
23257
|
defaultKeypairPath,
|