@elemental-stv-core/sdk 0.9.1 → 0.9.3
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/jlpd-strategy/jlp-data.js +32 -10
- package/dist/p-stv-core/accounts.d.ts +2 -1
- package/dist/p-stv-core/accounts.js +4 -2
- package/dist/p-stv-core/constants.d.ts +3 -2
- package/dist/p-stv-core/constants.js +4 -3
- package/dist/p-stv-core/events.js +4 -0
- package/dist/p-stv-core/types.d.ts +8 -1
- package/package.json +1 -1
|
@@ -105,19 +105,41 @@ async function fetchAllCustodies(connection) {
|
|
|
105
105
|
};
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
+
// Module-level memo for Jupiter price/v3 — 3 consumers in this file
|
|
109
|
+
// (fetchJlpCustodyData, fetchJlpPoolDetails, fetchJlpEffectiveWeights) used to
|
|
110
|
+
// each hit the API independently. A single jlp-pool-snapshot route would fire
|
|
111
|
+
// 3 redundant calls per cache miss. 30s TTL is short enough that prices stay
|
|
112
|
+
// fresh for downstream NAV/weight math, long enough to coalesce snapshot loads.
|
|
113
|
+
const PRICES_TTL_MS = 30000;
|
|
114
|
+
let pricesCache = null;
|
|
115
|
+
let pricesInFlight = null;
|
|
108
116
|
async function fetchPrices() {
|
|
117
|
+
if (pricesCache && Date.now() - pricesCache.at < PRICES_TTL_MS) {
|
|
118
|
+
return pricesCache.data;
|
|
119
|
+
}
|
|
120
|
+
if (pricesInFlight)
|
|
121
|
+
return pricesInFlight;
|
|
109
122
|
const ids = CUSTODIES.map((c) => c.mintAddress).join(",");
|
|
110
123
|
const url = `${JUPITER_PRICE_API}?ids=${ids}`;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
pricesInFlight = (async () => {
|
|
125
|
+
try {
|
|
126
|
+
const response = await fetch(url);
|
|
127
|
+
if (!response.ok) {
|
|
128
|
+
throw new Error(`Jupiter Price API error: ${response.status}`);
|
|
129
|
+
}
|
|
130
|
+
const json = (await response.json());
|
|
131
|
+
const prices = {};
|
|
132
|
+
for (const [mint, data] of Object.entries(json)) {
|
|
133
|
+
prices[mint] = data.usdPrice;
|
|
134
|
+
}
|
|
135
|
+
pricesCache = { at: Date.now(), data: prices };
|
|
136
|
+
return prices;
|
|
137
|
+
}
|
|
138
|
+
finally {
|
|
139
|
+
pricesInFlight = null;
|
|
140
|
+
}
|
|
141
|
+
})();
|
|
142
|
+
return pricesInFlight;
|
|
121
143
|
}
|
|
122
144
|
function calculateDebtTokens(raw) {
|
|
123
145
|
if (raw.debt <= raw.borrowLendInterestsAccrued)
|
|
@@ -25,7 +25,8 @@ export declare function deserializeGlobalConfig(data: Buffer): GlobalConfig;
|
|
|
25
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..
|
|
28
|
+
* [168..200] vaultAta Pubkey (canonical ATA for stv_pda+base_mint+token_program)
|
|
29
|
+
* [200..248] childVaults[6] [u64; 6] (allocator child vault IDs)
|
|
29
30
|
* [248..256] vaultId u64
|
|
30
31
|
* [256..264] reservedBase u64 (base reserved for pending claims)
|
|
31
32
|
* [264..272] requestedShares u64 (shares pending in escrow — multiply × PPS to estimate base)
|
|
@@ -63,7 +63,8 @@ function deserializeGlobalConfig(data) {
|
|
|
63
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..
|
|
66
|
+
* [168..200] vaultAta Pubkey (canonical ATA for stv_pda+base_mint+token_program)
|
|
67
|
+
* [200..248] childVaults[6] [u64; 6] (allocator child vault IDs)
|
|
67
68
|
* [248..256] vaultId u64
|
|
68
69
|
* [256..264] reservedBase u64 (base reserved for pending claims)
|
|
69
70
|
* [264..272] requestedShares u64 (shares pending in escrow — multiply × PPS to estimate base)
|
|
@@ -99,7 +100,7 @@ function deserializeStv(data) {
|
|
|
99
100
|
}
|
|
100
101
|
const childVaults = [];
|
|
101
102
|
for (let i = 0; i < constants_1.MAX_STRATEGIES; i++) {
|
|
102
|
-
childVaults.push((0, buffer_1.readU64)(data,
|
|
103
|
+
childVaults.push((0, buffer_1.readU64)(data, 200 + i * 8));
|
|
103
104
|
}
|
|
104
105
|
return {
|
|
105
106
|
baseMint: (0, buffer_1.readPubkey)(data, 8),
|
|
@@ -107,6 +108,7 @@ function deserializeStv(data) {
|
|
|
107
108
|
strategy: (0, buffer_1.readPubkey)(data, 72),
|
|
108
109
|
feeReceiver: (0, buffer_1.readPubkey)(data, 104),
|
|
109
110
|
lendProgram: (0, buffer_1.readPubkey)(data, 136),
|
|
111
|
+
vaultAta: (0, buffer_1.readPubkey)(data, 168),
|
|
110
112
|
childVaults,
|
|
111
113
|
vaultId: (0, buffer_1.readU64)(data, 248),
|
|
112
114
|
reservedBase: (0, buffer_1.readU64)(data, 256),
|
|
@@ -40,6 +40,7 @@ export declare const EVT_MANAGER_ADDED = 14;
|
|
|
40
40
|
export declare const EVT_MANAGER_REMOVED = 15;
|
|
41
41
|
export declare const EVT_WITHDRAW_OVERRIDE_CLAIMED = 16;
|
|
42
42
|
export declare const EVT_LEND_MIGRATED = 17;
|
|
43
|
+
export declare const EVT_VAULT_ATA_BACKFILLED = 18;
|
|
43
44
|
export declare const FLAG_PAUSED = 1;
|
|
44
45
|
export declare const FLAG_DEPOSITS_DISABLED = 2;
|
|
45
46
|
export declare const FLAG_WITHDRAWALS_DISABLED = 4;
|
|
@@ -56,8 +57,8 @@ export declare const FLAG_ALLOCATOR = 32;
|
|
|
56
57
|
*/
|
|
57
58
|
export declare const CFG_FLAG_GLOBAL_PAUSED = 1;
|
|
58
59
|
export { PPS_DECIMALS, BPS_DENOMINATOR, STALENESS_THRESHOLD } from "../common/constants";
|
|
59
|
-
export declare const MAX_CHILD_VAULTS =
|
|
60
|
-
export declare const MAX_STRATEGIES =
|
|
60
|
+
export declare const MAX_CHILD_VAULTS = 6;
|
|
61
|
+
export declare const MAX_STRATEGIES = 6;
|
|
61
62
|
export declare const FEE_CAP_BPS = 9900;
|
|
62
63
|
export declare const GLOBAL_CONFIG_SIZE = 56;
|
|
63
64
|
export declare const STV_SIZE = 664;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
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;
|
|
3
|
+
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_VAULT_ATA_BACKFILLED = 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.MAX_CHILD_VAULTS = exports.STALENESS_THRESHOLD = exports.BPS_DENOMINATOR = void 0;
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
// ---------------------------------------------------------------------------
|
|
7
7
|
// Program ID
|
|
@@ -67,6 +67,7 @@ exports.EVT_MANAGER_ADDED = 14;
|
|
|
67
67
|
exports.EVT_MANAGER_REMOVED = 15;
|
|
68
68
|
exports.EVT_WITHDRAW_OVERRIDE_CLAIMED = 16;
|
|
69
69
|
exports.EVT_LEND_MIGRATED = 17;
|
|
70
|
+
exports.EVT_VAULT_ATA_BACKFILLED = 18;
|
|
70
71
|
// ---------------------------------------------------------------------------
|
|
71
72
|
// Vault Flags
|
|
72
73
|
// ---------------------------------------------------------------------------
|
|
@@ -94,7 +95,7 @@ var constants_2 = require("../common/constants");
|
|
|
94
95
|
Object.defineProperty(exports, "PPS_DECIMALS", { enumerable: true, get: function () { return constants_2.PPS_DECIMALS; } });
|
|
95
96
|
Object.defineProperty(exports, "BPS_DENOMINATOR", { enumerable: true, get: function () { return constants_2.BPS_DENOMINATOR; } });
|
|
96
97
|
Object.defineProperty(exports, "STALENESS_THRESHOLD", { enumerable: true, get: function () { return constants_2.STALENESS_THRESHOLD; } });
|
|
97
|
-
exports.MAX_CHILD_VAULTS =
|
|
98
|
+
exports.MAX_CHILD_VAULTS = 6;
|
|
98
99
|
exports.MAX_STRATEGIES = exports.MAX_CHILD_VAULTS; // backward compat
|
|
99
100
|
exports.FEE_CAP_BPS = 9900;
|
|
100
101
|
// ---------------------------------------------------------------------------
|
|
@@ -170,6 +170,10 @@ function parseEventBuffer(data) {
|
|
|
170
170
|
name: "LendMigrated", vaultId: (0, buffer_1.readU64)(data, 1), oldLendProgram: (0, buffer_1.readPubkey)(data, 9),
|
|
171
171
|
newLendProgram: (0, buffer_1.readPubkey)(data, 41), sharesWithdrawn: (0, buffer_1.readU64)(data, 73), baseMigrated: (0, buffer_1.readU64)(data, 81),
|
|
172
172
|
} : null;
|
|
173
|
+
case constants_1.EVT_VAULT_ATA_BACKFILLED:
|
|
174
|
+
return data.length >= 41 ? {
|
|
175
|
+
name: "VaultAtaBackfilled", vaultId: (0, buffer_1.readU64)(data, 1), vaultAta: (0, buffer_1.readPubkey)(data, 9),
|
|
176
|
+
} : null;
|
|
173
177
|
default:
|
|
174
178
|
return null;
|
|
175
179
|
}
|
|
@@ -13,6 +13,8 @@ export interface Stv {
|
|
|
13
13
|
strategy: PublicKey;
|
|
14
14
|
feeReceiver: PublicKey;
|
|
15
15
|
lendProgram: PublicKey;
|
|
16
|
+
/** Canonical ATA for (stv_pda, base_mint, token_program). Set at init. */
|
|
17
|
+
vaultAta: PublicKey;
|
|
16
18
|
childVaults: BN[];
|
|
17
19
|
vaultId: BN;
|
|
18
20
|
reservedBase: BN;
|
|
@@ -186,4 +188,9 @@ export interface LendMigratedEvent {
|
|
|
186
188
|
sharesWithdrawn: BN;
|
|
187
189
|
baseMigrated: BN;
|
|
188
190
|
}
|
|
189
|
-
export
|
|
191
|
+
export interface VaultAtaBackfilledEvent {
|
|
192
|
+
name: "VaultAtaBackfilled";
|
|
193
|
+
vaultId: BN;
|
|
194
|
+
vaultAta: PublicKey;
|
|
195
|
+
}
|
|
196
|
+
export type StvEvent = ConfigInitializedEvent | ConfigUpdatedEvent | StvCreatedEvent | StvUpdatedEvent | DepositedEvent | WithdrawRequestedEvent | WithdrawRequestIncreasedEvent | WithdrawClaimedEvent | DepositedToStrategyEvent | WithdrawnFromStrategyEvent | EpochProcessedEvent | EpochAdvancedEvent | FeesSettledEvent | StvClosedEvent | ManagerAddedEvent | ManagerRemovedEvent | WithdrawOverrideClaimedEvent | LendMigratedEvent | VaultAtaBackfilledEvent;
|