@elemental-stv-core/sdk 0.6.0 → 0.8.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/dist/common/ata.d.ts +13 -1
- package/dist/common/ata.js +27 -0
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.js +2 -1
- package/dist/jlpd-strategy/swap-jlp.js +1 -2
- package/dist/p-stv-core/accounts.d.ts +27 -27
- package/dist/p-stv-core/accounts.js +52 -52
- package/dist/p-stv-core/constants.d.ts +1 -0
- package/dist/p-stv-core/constants.js +3 -2
- package/dist/p-stv-core/events.js +2 -2
- package/dist/p-stv-core/remaining-accounts.d.ts +2 -4
- package/dist/p-stv-core/remaining-accounts.js +13 -29
- package/dist/p-stv-core/sol-wrap.js +1 -21
- package/dist/p-stv-core/types.d.ts +6 -4
- package/package.json +1 -1
package/dist/common/ata.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PublicKey } from "@solana/web3.js";
|
|
1
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
2
|
/**
|
|
3
3
|
* Derive an Associated Token Account (ATA) address.
|
|
4
4
|
*
|
|
@@ -12,3 +12,15 @@ import { PublicKey } from "@solana/web3.js";
|
|
|
12
12
|
* @param tokenProgram - Token program ID (SPL Token or Token-2022)
|
|
13
13
|
*/
|
|
14
14
|
export declare function findAta(mint: PublicKey, owner: PublicKey, tokenProgram: PublicKey): PublicKey;
|
|
15
|
+
/**
|
|
16
|
+
* Build an Associated Token Account `CreateIdempotent` instruction.
|
|
17
|
+
*
|
|
18
|
+
* Idempotent — safe to include on every tx; the ATA program no-ops if the
|
|
19
|
+
* account already exists. Works for both SPL Token and Token-2022.
|
|
20
|
+
*
|
|
21
|
+
* @param payer - Wallet paying rent + signing the tx
|
|
22
|
+
* @param mint - Token mint the ATA will hold
|
|
23
|
+
* @param owner - ATA owner (wallet or PDA)
|
|
24
|
+
* @param tokenProgram - SPL Token or Token-2022 program id
|
|
25
|
+
*/
|
|
26
|
+
export declare function createIdempotentAtaIx(payer: PublicKey, mint: PublicKey, owner: PublicKey, tokenProgram: PublicKey): TransactionInstruction;
|
package/dist/common/ata.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findAta = findAta;
|
|
4
|
+
exports.createIdempotentAtaIx = createIdempotentAtaIx;
|
|
4
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
6
|
const spl_token_1 = require("@solana/spl-token");
|
|
6
7
|
/**
|
|
@@ -19,3 +20,29 @@ function findAta(mint, owner, tokenProgram) {
|
|
|
19
20
|
const [ata] = web3_js_1.PublicKey.findProgramAddressSync([owner.toBuffer(), tokenProgram.toBuffer(), mint.toBuffer()], spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
20
21
|
return ata;
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Build an Associated Token Account `CreateIdempotent` instruction.
|
|
25
|
+
*
|
|
26
|
+
* Idempotent — safe to include on every tx; the ATA program no-ops if the
|
|
27
|
+
* account already exists. Works for both SPL Token and Token-2022.
|
|
28
|
+
*
|
|
29
|
+
* @param payer - Wallet paying rent + signing the tx
|
|
30
|
+
* @param mint - Token mint the ATA will hold
|
|
31
|
+
* @param owner - ATA owner (wallet or PDA)
|
|
32
|
+
* @param tokenProgram - SPL Token or Token-2022 program id
|
|
33
|
+
*/
|
|
34
|
+
function createIdempotentAtaIx(payer, mint, owner, tokenProgram) {
|
|
35
|
+
const ata = findAta(mint, owner, tokenProgram);
|
|
36
|
+
return new web3_js_1.TransactionInstruction({
|
|
37
|
+
keys: [
|
|
38
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
39
|
+
{ pubkey: ata, isSigner: false, isWritable: true },
|
|
40
|
+
{ pubkey: owner, isSigner: false, isWritable: false },
|
|
41
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
42
|
+
{ pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false },
|
|
43
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
44
|
+
],
|
|
45
|
+
programId: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
46
|
+
data: Buffer.from([1]), // CreateIdempotent
|
|
47
|
+
});
|
|
48
|
+
}
|
package/dist/common/index.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ export { PPS_DECIMALS, BPS_DENOMINATOR, SECONDS_PER_YEAR, STALENESS_THRESHOLD, D
|
|
|
3
3
|
export type { SolanaConnection } from "./connection";
|
|
4
4
|
export type { StrategyStateHeader, StvPosition, } from "./strategy-interface";
|
|
5
5
|
export { deserializeStrategyStateHeader, deserializeStvPosition, } from "./strategy-interface";
|
|
6
|
-
export { findAta } from "./ata";
|
|
6
|
+
export { findAta, createIdempotentAtaIx } from "./ata";
|
package/dist/common/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findAta = exports.deserializeStvPosition = exports.deserializeStrategyStateHeader = exports.DISC_MANAGER_ROLE = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.STALENESS_THRESHOLD = exports.SECONDS_PER_YEAR = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = exports.writeOptionalU16 = exports.writeOptionalU32 = exports.writeOptionalU64 = exports.writeOptionalPubkey = exports.writeU64 = exports.readU8 = exports.readU16 = exports.readU32 = exports.readU64 = exports.readPubkey = void 0;
|
|
3
|
+
exports.createIdempotentAtaIx = exports.findAta = exports.deserializeStvPosition = exports.deserializeStrategyStateHeader = exports.DISC_MANAGER_ROLE = exports.DISC_STV_POSITION = exports.DISC_STRATEGY_STATE = exports.STALENESS_THRESHOLD = exports.SECONDS_PER_YEAR = exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = exports.writeOptionalU16 = exports.writeOptionalU32 = exports.writeOptionalU64 = exports.writeOptionalPubkey = exports.writeU64 = exports.readU8 = exports.readU16 = exports.readU32 = exports.readU64 = exports.readPubkey = void 0;
|
|
4
4
|
var buffer_1 = require("./buffer");
|
|
5
5
|
Object.defineProperty(exports, "readPubkey", { enumerable: true, get: function () { return buffer_1.readPubkey; } });
|
|
6
6
|
Object.defineProperty(exports, "readU64", { enumerable: true, get: function () { return buffer_1.readU64; } });
|
|
@@ -25,3 +25,4 @@ Object.defineProperty(exports, "deserializeStrategyStateHeader", { enumerable: t
|
|
|
25
25
|
Object.defineProperty(exports, "deserializeStvPosition", { enumerable: true, get: function () { return strategy_interface_1.deserializeStvPosition; } });
|
|
26
26
|
var ata_1 = require("./ata");
|
|
27
27
|
Object.defineProperty(exports, "findAta", { enumerable: true, get: function () { return ata_1.findAta; } });
|
|
28
|
+
Object.defineProperty(exports, "createIdempotentAtaIx", { enumerable: true, get: function () { return ata_1.createIdempotentAtaIx; } });
|
|
@@ -330,8 +330,7 @@ async function buildBaseToJlpRebalance(args) {
|
|
|
330
330
|
address: stvAddress,
|
|
331
331
|
baseMint,
|
|
332
332
|
lendProgram: stv.lendProgram,
|
|
333
|
-
|
|
334
|
-
strategyCount: stv.strategyCount,
|
|
333
|
+
strategy: stv.strategy,
|
|
335
334
|
};
|
|
336
335
|
const depositCtx = await (0, remaining_accounts_1.buildDepositToStrategyContext)(connection, vaultInfo);
|
|
337
336
|
// Derive the JLPD strategy's position PDA in p-STV Core
|
|
@@ -16,40 +16,40 @@ import { GlobalConfig, Stv, WithdrawRequest, ManagerRole } from "./types";
|
|
|
16
16
|
*/
|
|
17
17
|
export declare function deserializeGlobalConfig(data: Buffer): GlobalConfig;
|
|
18
18
|
/**
|
|
19
|
-
* STV — per-vault state. Total 664 bytes.
|
|
19
|
+
* STV — per-vault state. Total 664 bytes (v2 layout).
|
|
20
20
|
*
|
|
21
21
|
* Layout (offsets include the 8-byte discriminator):
|
|
22
22
|
* [ 0.. 8] discriminator (sha256("account:Stv")[..8])
|
|
23
23
|
* [ 8.. 40] baseMint Pubkey
|
|
24
24
|
* [ 40.. 72] evMint Pubkey
|
|
25
|
-
* [ 72..104] strategy Pubkey (
|
|
25
|
+
* [ 72..104] strategy Pubkey (immutable strategy program)
|
|
26
26
|
* [104..136] feeReceiver Pubkey
|
|
27
27
|
* [136..168] lendProgram Pubkey (zero pubkey if lend not opted-in)
|
|
28
|
-
* [168..
|
|
29
|
-
* [
|
|
30
|
-
* [
|
|
31
|
-
* [
|
|
32
|
-
* [
|
|
33
|
-
* [
|
|
34
|
-
* [
|
|
35
|
-
* [
|
|
36
|
-
* [
|
|
37
|
-
* [
|
|
38
|
-
* [
|
|
39
|
-
* [
|
|
40
|
-
* [
|
|
41
|
-
* [
|
|
42
|
-
* [
|
|
43
|
-
* [
|
|
44
|
-
* [
|
|
45
|
-
* [
|
|
46
|
-
* [
|
|
47
|
-
* [
|
|
48
|
-
* [
|
|
49
|
-
* [
|
|
50
|
-
* [
|
|
51
|
-
* [
|
|
52
|
-
* [
|
|
28
|
+
* [168..248] childVaults[10] [u64; 10] (allocator child vault IDs)
|
|
29
|
+
* [248..256] vaultId u64
|
|
30
|
+
* [256..264] reservedBase u64 (base reserved for pending claims)
|
|
31
|
+
* [264..272] requestedShares u64 (shares pending in escrow — multiply × PPS to estimate base)
|
|
32
|
+
* [272..280] vaultCapacity u64 (0 = uncapped)
|
|
33
|
+
* [280..288] minDeposit u64
|
|
34
|
+
* [288..296] hwm u64 (high-water mark for perf fees)
|
|
35
|
+
* [296..304] lastFeeTs u64 (last fee crystallization timestamp)
|
|
36
|
+
* [304..312] epochPps u64 (locked PPS for current epoch claims)
|
|
37
|
+
* [312..320] lastNav u64 (snapshot for the rate-limit window)
|
|
38
|
+
* [320..328] dailyWithdrawnBase u64 (rate-limit accumulator)
|
|
39
|
+
* [328..332] nextEpochTs u32
|
|
40
|
+
* [332..336] epochSec u32
|
|
41
|
+
* [336..340] currentEpochId u32
|
|
42
|
+
* [340..344] pendingWithdrawals u32
|
|
43
|
+
* [344..348] withdrawWindowStart u32
|
|
44
|
+
* [348..350] mgmtFeeBps u16
|
|
45
|
+
* [350..352] perfFeeBps u16
|
|
46
|
+
* [352..354] flags u16 (FLAG_PAUSED / DEPOSITS_DISABLED / …)
|
|
47
|
+
* [354..356] dailyWithdrawLimitBps u16
|
|
48
|
+
* [356..357] childVaultCount u8
|
|
49
|
+
* [357..358] version u8
|
|
50
|
+
* [358..359] bump u8
|
|
51
|
+
* [359..360] _padding [u8; 1]
|
|
52
|
+
* [360..664] _reserved [u8; 304]
|
|
53
53
|
*/
|
|
54
54
|
export declare function deserializeStv(data: Buffer): Stv;
|
|
55
55
|
/**
|
|
@@ -54,40 +54,40 @@ function deserializeGlobalConfig(data) {
|
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
|
-
* STV — per-vault state. Total 664 bytes.
|
|
57
|
+
* STV — per-vault state. Total 664 bytes (v2 layout).
|
|
58
58
|
*
|
|
59
59
|
* Layout (offsets include the 8-byte discriminator):
|
|
60
60
|
* [ 0.. 8] discriminator (sha256("account:Stv")[..8])
|
|
61
61
|
* [ 8.. 40] baseMint Pubkey
|
|
62
62
|
* [ 40.. 72] evMint Pubkey
|
|
63
|
-
* [ 72..104] strategy Pubkey (
|
|
63
|
+
* [ 72..104] strategy Pubkey (immutable strategy program)
|
|
64
64
|
* [104..136] feeReceiver Pubkey
|
|
65
65
|
* [136..168] lendProgram Pubkey (zero pubkey if lend not opted-in)
|
|
66
|
-
* [168..
|
|
67
|
-
* [
|
|
68
|
-
* [
|
|
69
|
-
* [
|
|
70
|
-
* [
|
|
71
|
-
* [
|
|
72
|
-
* [
|
|
73
|
-
* [
|
|
74
|
-
* [
|
|
75
|
-
* [
|
|
76
|
-
* [
|
|
77
|
-
* [
|
|
78
|
-
* [
|
|
79
|
-
* [
|
|
80
|
-
* [
|
|
81
|
-
* [
|
|
82
|
-
* [
|
|
83
|
-
* [
|
|
84
|
-
* [
|
|
85
|
-
* [
|
|
86
|
-
* [
|
|
87
|
-
* [
|
|
88
|
-
* [
|
|
89
|
-
* [
|
|
90
|
-
* [
|
|
66
|
+
* [168..248] childVaults[10] [u64; 10] (allocator child vault IDs)
|
|
67
|
+
* [248..256] vaultId u64
|
|
68
|
+
* [256..264] reservedBase u64 (base reserved for pending claims)
|
|
69
|
+
* [264..272] requestedShares u64 (shares pending in escrow — multiply × PPS to estimate base)
|
|
70
|
+
* [272..280] vaultCapacity u64 (0 = uncapped)
|
|
71
|
+
* [280..288] minDeposit u64
|
|
72
|
+
* [288..296] hwm u64 (high-water mark for perf fees)
|
|
73
|
+
* [296..304] lastFeeTs u64 (last fee crystallization timestamp)
|
|
74
|
+
* [304..312] epochPps u64 (locked PPS for current epoch claims)
|
|
75
|
+
* [312..320] lastNav u64 (snapshot for the rate-limit window)
|
|
76
|
+
* [320..328] dailyWithdrawnBase u64 (rate-limit accumulator)
|
|
77
|
+
* [328..332] nextEpochTs u32
|
|
78
|
+
* [332..336] epochSec u32
|
|
79
|
+
* [336..340] currentEpochId u32
|
|
80
|
+
* [340..344] pendingWithdrawals u32
|
|
81
|
+
* [344..348] withdrawWindowStart u32
|
|
82
|
+
* [348..350] mgmtFeeBps u16
|
|
83
|
+
* [350..352] perfFeeBps u16
|
|
84
|
+
* [352..354] flags u16 (FLAG_PAUSED / DEPOSITS_DISABLED / …)
|
|
85
|
+
* [354..356] dailyWithdrawLimitBps u16
|
|
86
|
+
* [356..357] childVaultCount u8
|
|
87
|
+
* [357..358] version u8
|
|
88
|
+
* [358..359] bump u8
|
|
89
|
+
* [359..360] _padding [u8; 1]
|
|
90
|
+
* [360..664] _reserved [u8; 304]
|
|
91
91
|
*/
|
|
92
92
|
function deserializeStv(data) {
|
|
93
93
|
if (data.length < constants_1.STV_SIZE) {
|
|
@@ -97,9 +97,9 @@ function deserializeStv(data) {
|
|
|
97
97
|
if (!disc.equals(constants_1.DISC_STV)) {
|
|
98
98
|
throw new Error(`Invalid Stv discriminator`);
|
|
99
99
|
}
|
|
100
|
-
const
|
|
100
|
+
const childVaults = [];
|
|
101
101
|
for (let i = 0; i < constants_1.MAX_STRATEGIES; i++) {
|
|
102
|
-
|
|
102
|
+
childVaults.push((0, buffer_1.readU64)(data, 168 + i * 8));
|
|
103
103
|
}
|
|
104
104
|
return {
|
|
105
105
|
baseMint: (0, buffer_1.readPubkey)(data, 8),
|
|
@@ -107,29 +107,29 @@ function deserializeStv(data) {
|
|
|
107
107
|
strategy: (0, buffer_1.readPubkey)(data, 72),
|
|
108
108
|
feeReceiver: (0, buffer_1.readPubkey)(data, 104),
|
|
109
109
|
lendProgram: (0, buffer_1.readPubkey)(data, 136),
|
|
110
|
-
|
|
111
|
-
vaultId: (0, buffer_1.readU64)(data,
|
|
112
|
-
reservedBase: (0, buffer_1.readU64)(data,
|
|
113
|
-
|
|
114
|
-
vaultCapacity: (0, buffer_1.readU64)(data,
|
|
115
|
-
minDeposit: (0, buffer_1.readU64)(data,
|
|
116
|
-
hwm: (0, buffer_1.readU64)(data,
|
|
117
|
-
lastFeeTs: (0, buffer_1.readU64)(data,
|
|
118
|
-
epochPps: (0, buffer_1.readU64)(data,
|
|
119
|
-
lastNav: (0, buffer_1.readU64)(data,
|
|
120
|
-
dailyWithdrawnBase: (0, buffer_1.readU64)(data,
|
|
121
|
-
nextEpochTs: (0, buffer_1.readU32)(data,
|
|
122
|
-
epochSec: (0, buffer_1.readU32)(data,
|
|
123
|
-
currentEpochId: (0, buffer_1.readU32)(data,
|
|
124
|
-
pendingWithdrawals: (0, buffer_1.readU32)(data,
|
|
125
|
-
withdrawWindowStart: (0, buffer_1.readU32)(data,
|
|
126
|
-
mgmtFeeBps: (0, buffer_1.readU16)(data,
|
|
127
|
-
perfFeeBps: (0, buffer_1.readU16)(data,
|
|
128
|
-
flags: (0, buffer_1.readU16)(data,
|
|
129
|
-
dailyWithdrawLimitBps: (0, buffer_1.readU16)(data,
|
|
130
|
-
|
|
131
|
-
version: (0, buffer_1.readU8)(data,
|
|
132
|
-
bump: (0, buffer_1.readU8)(data,
|
|
110
|
+
childVaults,
|
|
111
|
+
vaultId: (0, buffer_1.readU64)(data, 248),
|
|
112
|
+
reservedBase: (0, buffer_1.readU64)(data, 256),
|
|
113
|
+
requestedShares: (0, buffer_1.readU64)(data, 264),
|
|
114
|
+
vaultCapacity: (0, buffer_1.readU64)(data, 272),
|
|
115
|
+
minDeposit: (0, buffer_1.readU64)(data, 280),
|
|
116
|
+
hwm: (0, buffer_1.readU64)(data, 288),
|
|
117
|
+
lastFeeTs: (0, buffer_1.readU64)(data, 296),
|
|
118
|
+
epochPps: (0, buffer_1.readU64)(data, 304),
|
|
119
|
+
lastNav: (0, buffer_1.readU64)(data, 312),
|
|
120
|
+
dailyWithdrawnBase: (0, buffer_1.readU64)(data, 320),
|
|
121
|
+
nextEpochTs: (0, buffer_1.readU32)(data, 328),
|
|
122
|
+
epochSec: (0, buffer_1.readU32)(data, 332),
|
|
123
|
+
currentEpochId: (0, buffer_1.readU32)(data, 336),
|
|
124
|
+
pendingWithdrawals: (0, buffer_1.readU32)(data, 340),
|
|
125
|
+
withdrawWindowStart: (0, buffer_1.readU32)(data, 344),
|
|
126
|
+
mgmtFeeBps: (0, buffer_1.readU16)(data, 348),
|
|
127
|
+
perfFeeBps: (0, buffer_1.readU16)(data, 350),
|
|
128
|
+
flags: (0, buffer_1.readU16)(data, 352),
|
|
129
|
+
dailyWithdrawLimitBps: (0, buffer_1.readU16)(data, 354),
|
|
130
|
+
childVaultCount: (0, buffer_1.readU8)(data, 356),
|
|
131
|
+
version: (0, buffer_1.readU8)(data, 357),
|
|
132
|
+
bump: (0, buffer_1.readU8)(data, 358),
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
@@ -56,6 +56,7 @@ export declare const FLAG_ALLOCATOR = 32;
|
|
|
56
56
|
*/
|
|
57
57
|
export declare const CFG_FLAG_GLOBAL_PAUSED = 1;
|
|
58
58
|
export { PPS_DECIMALS, BPS_DENOMINATOR, STALENESS_THRESHOLD } from "../common/constants";
|
|
59
|
+
export declare const MAX_CHILD_VAULTS = 10;
|
|
59
60
|
export declare const MAX_STRATEGIES = 10;
|
|
60
61
|
export declare const FEE_CAP_BPS = 9900;
|
|
61
62
|
export declare const GLOBAL_CONFIG_SIZE = 56;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BPS_DENOMINATOR = exports.PPS_DECIMALS = exports.CFG_FLAG_GLOBAL_PAUSED = exports.FLAG_ALLOCATOR = exports.FLAG_TEST_MODE = exports.FLAG_REBALANCE_DISABLED = exports.FLAG_WITHDRAWALS_DISABLED = exports.FLAG_DEPOSITS_DISABLED = exports.FLAG_PAUSED = exports.EVT_LEND_MIGRATED = exports.EVT_WITHDRAW_OVERRIDE_CLAIMED = exports.EVT_MANAGER_REMOVED = exports.EVT_MANAGER_ADDED = exports.EVT_STV_CLOSED = exports.EVT_FEES_SETTLED = exports.EVT_EPOCH_ADVANCED = exports.EVT_EPOCH_PROCESSED = exports.EVT_WITHDRAWN_FROM_STRATEGY = exports.EVT_DEPOSITED_TO_STRATEGY = exports.EVT_WITHDRAW_CLAIMED = exports.EVT_WITHDRAW_REQUEST_INCREASED = exports.EVT_WITHDRAW_REQUESTED = exports.EVT_DEPOSITED = exports.EVT_STV_UPDATED = exports.EVT_STV_CREATED = exports.EVT_CONFIG_UPDATED = exports.EVT_CONFIG_INITIALIZED = exports.IX_MIGRATE_LEND = exports.IX_OVERRIDE_CLAIM_WITHDRAW = exports.IX_REMOVE_MANAGER = exports.IX_ADD_MANAGER = exports.IX_CLOSE_STV = exports.IX_WITHDRAW_FROM_STRATEGY = exports.IX_DEPOSIT_TO_STRATEGY = exports.IX_PROCESS_EPOCH = exports.IX_CLAIM_WITHDRAW = exports.IX_REQUEST_WITHDRAW = exports.IX_DEPOSIT = exports.IX_INIT_OR_UPDATE_STV = exports.IX_INIT_OR_UPDATE_CONFIG = exports.DISC_MANAGER_ROLE = exports.DISC_WITHDRAW_REQUEST = exports.DISC_STV = exports.DISC_GLOBAL_CONFIG = exports.MANAGER_SEED = exports.WITHDRAW_REQUEST_SEED = exports.EV_MINT_SEED = exports.STV_SEED = exports.CONFIG_SEED = exports.PROGRAM_ID = void 0;
|
|
4
|
-
exports.MANAGER_ROLE_SIZE = exports.WITHDRAW_REQUEST_SIZE = exports.STV_SIZE = exports.GLOBAL_CONFIG_SIZE = exports.FEE_CAP_BPS = exports.MAX_STRATEGIES = exports.STALENESS_THRESHOLD = void 0;
|
|
4
|
+
exports.MANAGER_ROLE_SIZE = exports.WITHDRAW_REQUEST_SIZE = exports.STV_SIZE = exports.GLOBAL_CONFIG_SIZE = exports.FEE_CAP_BPS = exports.MAX_STRATEGIES = exports.MAX_CHILD_VAULTS = exports.STALENESS_THRESHOLD = void 0;
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
// ---------------------------------------------------------------------------
|
|
7
7
|
// Program ID
|
|
@@ -94,7 +94,8 @@ var constants_2 = require("../common/constants");
|
|
|
94
94
|
Object.defineProperty(exports, "PPS_DECIMALS", { enumerable: true, get: function () { return constants_2.PPS_DECIMALS; } });
|
|
95
95
|
Object.defineProperty(exports, "BPS_DENOMINATOR", { enumerable: true, get: function () { return constants_2.BPS_DENOMINATOR; } });
|
|
96
96
|
Object.defineProperty(exports, "STALENESS_THRESHOLD", { enumerable: true, get: function () { return constants_2.STALENESS_THRESHOLD; } });
|
|
97
|
-
exports.
|
|
97
|
+
exports.MAX_CHILD_VAULTS = 10;
|
|
98
|
+
exports.MAX_STRATEGIES = exports.MAX_CHILD_VAULTS; // backward compat
|
|
98
99
|
exports.FEE_CAP_BPS = 9900;
|
|
99
100
|
// ---------------------------------------------------------------------------
|
|
100
101
|
// Account Sizes
|
|
@@ -54,7 +54,7 @@ function parseEventsFromLogs(logs, programId = constants_1.PROGRAM_ID) {
|
|
|
54
54
|
* StvUpdated [0..1] disc | [1..9] vaultId | [9..41] feeReceiver |
|
|
55
55
|
* [41..43] flags | [43..45] mgmtFeeBps | [45..47] perfFeeBps |
|
|
56
56
|
* [47..55] vaultCapacity | [55..63] minDeposit |
|
|
57
|
-
* [63..64]
|
|
57
|
+
* [63..64] childVaultCount | [64..96] lendProgram
|
|
58
58
|
* Deposited [0..1] disc | [1..9] vaultId | [9..41] user |
|
|
59
59
|
* [41..49] amount | [49..57] sharesMinted | [57..65] pps
|
|
60
60
|
* WithdrawRequested [0..1] disc | [1..9] vaultId | [9..41] user |
|
|
@@ -100,7 +100,7 @@ function parseEventBuffer(data) {
|
|
|
100
100
|
name: "StvUpdated", vaultId: (0, buffer_1.readU64)(data, 1), feeReceiver: (0, buffer_1.readPubkey)(data, 9),
|
|
101
101
|
flags: (0, buffer_1.readU16)(data, 41), mgmtFeeBps: (0, buffer_1.readU16)(data, 43),
|
|
102
102
|
perfFeeBps: (0, buffer_1.readU16)(data, 45), vaultCapacity: (0, buffer_1.readU64)(data, 47), minDeposit: (0, buffer_1.readU64)(data, 55),
|
|
103
|
-
|
|
103
|
+
childVaultCount: data[63], lendProgram: (0, buffer_1.readPubkey)(data, 64),
|
|
104
104
|
} : null;
|
|
105
105
|
case constants_1.EVT_DEPOSITED:
|
|
106
106
|
return data.length >= 65 ? {
|
|
@@ -17,10 +17,8 @@ export interface VaultInfo {
|
|
|
17
17
|
baseMint: PublicKey;
|
|
18
18
|
/** Lend program (PublicKey.default if not active) */
|
|
19
19
|
lendProgram: PublicKey;
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
/** Number of active strategies */
|
|
23
|
-
strategyCount: number;
|
|
20
|
+
/** Immutable strategy program (PublicKey.default if none) */
|
|
21
|
+
strategy: PublicKey;
|
|
24
22
|
}
|
|
25
23
|
export interface DepositContext {
|
|
26
24
|
remainingAccounts: AccountMeta[];
|
|
@@ -47,24 +47,17 @@ function buildFixedLendAccounts(lendProgram, baseMint, stvAddress) {
|
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Build strategy pair accounts for NAV computation.
|
|
50
|
-
*
|
|
50
|
+
* Strategy-locked vaults have a single strategy: [strategy_state, stv_position].
|
|
51
51
|
*/
|
|
52
52
|
function buildStrategyPairAccounts(vault) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const [stratPos] = web3_js_1.PublicKey.findProgramAddressSync([POSITION_SEED, vault.address.toBuffer()], strategyProgram);
|
|
62
|
-
accounts.push({ pubkey: stratState, isSigner: false, isWritable: true }, { pubkey: stratPos, isSigner: false, isWritable: true });
|
|
63
|
-
// Note: strategy program is NOT added to remaining_accounts.
|
|
64
|
-
// The on-chain code expects exactly 2 accounts per strategy (state + position).
|
|
65
|
-
// The strategy program resolves from the transaction's account list via invoke_signed.
|
|
66
|
-
}
|
|
67
|
-
return accounts;
|
|
53
|
+
if (isDefault(vault.strategy))
|
|
54
|
+
return [];
|
|
55
|
+
const [stratState] = web3_js_1.PublicKey.findProgramAddressSync([STRATEGY_STATE_SEED, vault.baseMint.toBuffer()], vault.strategy);
|
|
56
|
+
const [stratPos] = web3_js_1.PublicKey.findProgramAddressSync([POSITION_SEED, vault.address.toBuffer()], vault.strategy);
|
|
57
|
+
return [
|
|
58
|
+
{ pubkey: stratState, isSigner: false, isWritable: true },
|
|
59
|
+
{ pubkey: stratPos, isSigner: false, isWritable: true },
|
|
60
|
+
];
|
|
68
61
|
}
|
|
69
62
|
/**
|
|
70
63
|
*/
|
|
@@ -136,19 +129,10 @@ async function buildDepositContext(connection, vault, payer) {
|
|
|
136
129
|
// Skip auto-route if account resolution fails
|
|
137
130
|
}
|
|
138
131
|
}
|
|
139
|
-
// 4. Strategy
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
for (let i = 0; i < vault.strategyCount; i++) {
|
|
144
|
-
const prog = vault.strategies[i];
|
|
145
|
-
if (isDefault(prog))
|
|
146
|
-
continue;
|
|
147
|
-
const key = prog.toBase58();
|
|
148
|
-
if (!seenPrograms.has(key)) {
|
|
149
|
-
seenPrograms.add(key);
|
|
150
|
-
remainingAccounts.push({ pubkey: prog, isSigner: false, isWritable: false });
|
|
151
|
-
}
|
|
132
|
+
// 4. Strategy program (after auto-route, for CPI resolution)
|
|
133
|
+
// Must be in the transaction but NOT counted as auto-route or strategy pairs.
|
|
134
|
+
if (!isDefault(vault.strategy)) {
|
|
135
|
+
remainingAccounts.push({ pubkey: vault.strategy, isSigner: false, isWritable: false });
|
|
152
136
|
}
|
|
153
137
|
return { remainingAccounts, protocolAumCount, autoRouteCount, preInstructions };
|
|
154
138
|
}
|
|
@@ -12,7 +12,6 @@ exports.findWsolAta = findWsolAta;
|
|
|
12
12
|
exports.buildWrapSolIxs = buildWrapSolIxs;
|
|
13
13
|
exports.buildUnwrapSolIx = buildUnwrapSolIx;
|
|
14
14
|
const web3_js_1 = require("@solana/web3.js");
|
|
15
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
16
15
|
const ata_1 = require("../common/ata");
|
|
17
16
|
/** Native SOL mint (wrapped SOL) */
|
|
18
17
|
exports.NATIVE_SOL_MINT = new web3_js_1.PublicKey("So11111111111111111111111111111111111111112");
|
|
@@ -39,15 +38,12 @@ function findWsolAta(owner) {
|
|
|
39
38
|
function buildWrapSolIxs(payer, lamports) {
|
|
40
39
|
const wsolAta = findWsolAta(payer);
|
|
41
40
|
return [
|
|
42
|
-
|
|
43
|
-
createAtaIxInternal(payer, exports.NATIVE_SOL_MINT, payer),
|
|
44
|
-
// Transfer SOL to wSOL ATA
|
|
41
|
+
(0, ata_1.createIdempotentAtaIx)(payer, exports.NATIVE_SOL_MINT, payer, SPL_TOKEN_PROGRAM),
|
|
45
42
|
web3_js_1.SystemProgram.transfer({
|
|
46
43
|
fromPubkey: payer,
|
|
47
44
|
toPubkey: wsolAta,
|
|
48
45
|
lamports: BigInt(lamports),
|
|
49
46
|
}),
|
|
50
|
-
// Sync native balance
|
|
51
47
|
new web3_js_1.TransactionInstruction({
|
|
52
48
|
programId: SPL_TOKEN_PROGRAM,
|
|
53
49
|
keys: [{ pubkey: wsolAta, isSigner: false, isWritable: true }],
|
|
@@ -76,19 +72,3 @@ function buildUnwrapSolIx(owner) {
|
|
|
76
72
|
data: Buffer.from([9]),
|
|
77
73
|
});
|
|
78
74
|
}
|
|
79
|
-
/** Internal: create ATA (idempotent) */
|
|
80
|
-
function createAtaIxInternal(payer, mint, owner) {
|
|
81
|
-
const ata = (0, ata_1.findAta)(mint, owner, SPL_TOKEN_PROGRAM);
|
|
82
|
-
return new web3_js_1.TransactionInstruction({
|
|
83
|
-
keys: [
|
|
84
|
-
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
85
|
-
{ pubkey: ata, isSigner: false, isWritable: true },
|
|
86
|
-
{ pubkey: owner, isSigner: false, isWritable: false },
|
|
87
|
-
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
88
|
-
{ pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false },
|
|
89
|
-
{ pubkey: SPL_TOKEN_PROGRAM, isSigner: false, isWritable: false },
|
|
90
|
-
],
|
|
91
|
-
programId: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
92
|
-
data: Buffer.from([1]), // CreateIdempotent
|
|
93
|
-
});
|
|
94
|
-
}
|
|
@@ -13,10 +13,12 @@ export interface Stv {
|
|
|
13
13
|
strategy: PublicKey;
|
|
14
14
|
feeReceiver: PublicKey;
|
|
15
15
|
lendProgram: PublicKey;
|
|
16
|
-
|
|
16
|
+
childVaults: BN[];
|
|
17
17
|
vaultId: BN;
|
|
18
18
|
reservedBase: BN;
|
|
19
|
-
|
|
19
|
+
/** Pending withdrawal shares (sum across unprocessed WithdrawRequests).
|
|
20
|
+
* Display value: requestedShares × currentPps / PPS_DECIMALS. */
|
|
21
|
+
requestedShares: BN;
|
|
20
22
|
vaultCapacity: BN;
|
|
21
23
|
minDeposit: BN;
|
|
22
24
|
hwm: BN;
|
|
@@ -33,7 +35,7 @@ export interface Stv {
|
|
|
33
35
|
perfFeeBps: number;
|
|
34
36
|
flags: number;
|
|
35
37
|
dailyWithdrawLimitBps: number;
|
|
36
|
-
|
|
38
|
+
childVaultCount: number;
|
|
37
39
|
version: number;
|
|
38
40
|
bump: number;
|
|
39
41
|
}
|
|
@@ -81,7 +83,7 @@ export interface StvUpdatedEvent {
|
|
|
81
83
|
perfFeeBps: number;
|
|
82
84
|
vaultCapacity: BN;
|
|
83
85
|
minDeposit: BN;
|
|
84
|
-
|
|
86
|
+
childVaultCount: number;
|
|
85
87
|
lendProgram: PublicKey;
|
|
86
88
|
}
|
|
87
89
|
export interface DepositedEvent {
|