@perena/vault-sdk 1.0.20 → 1.0.23
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 +35 -0
- package/dist/index.d.ts +228 -160
- package/dist/index.js +389 -204
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -233,8 +233,8 @@ var require_roles = __commonJS({
|
|
|
233
233
|
return kit_1.AccountRole.WRITABLE;
|
|
234
234
|
return role;
|
|
235
235
|
}
|
|
236
|
-
function stripSignerFromAccounts(
|
|
237
|
-
return
|
|
236
|
+
function stripSignerFromAccounts(accounts2) {
|
|
237
|
+
return accounts2.map((acc) => ({
|
|
238
238
|
...acc,
|
|
239
239
|
role: downgradeRoleFromSigner(acc.role)
|
|
240
240
|
}));
|
|
@@ -344,8 +344,8 @@ var require_refs = __commonJS({
|
|
|
344
344
|
var roles_1 = require_roles();
|
|
345
345
|
var accounts_1 = require_accounts();
|
|
346
346
|
var args_1 = require_args();
|
|
347
|
-
function buildIndicesForCpi(
|
|
348
|
-
return
|
|
347
|
+
function buildIndicesForCpi(accounts2, poolIndex) {
|
|
348
|
+
return accounts2.map((acc) => {
|
|
349
349
|
const idx = poolIndex.get(acc.address);
|
|
350
350
|
if (idx === void 0) {
|
|
351
351
|
throw new Error(`Account ${acc.address} not found in pool`);
|
|
@@ -355,8 +355,8 @@ var require_refs = __commonJS({
|
|
|
355
355
|
}
|
|
356
356
|
function buildDeduplicatedPool(accountLists) {
|
|
357
357
|
const poolMap = /* @__PURE__ */ new Map();
|
|
358
|
-
for (const
|
|
359
|
-
for (const acc of
|
|
358
|
+
for (const accounts2 of accountLists) {
|
|
359
|
+
for (const acc of accounts2) {
|
|
360
360
|
const existing = poolMap.get(acc.address);
|
|
361
361
|
if (!existing) {
|
|
362
362
|
poolMap.set(acc.address, { ...acc });
|
|
@@ -380,8 +380,8 @@ var require_refs = __commonJS({
|
|
|
380
380
|
poolIndex.set(acc.address, i);
|
|
381
381
|
}
|
|
382
382
|
});
|
|
383
|
-
for (const
|
|
384
|
-
for (const acc of
|
|
383
|
+
for (const accounts2 of accountLists) {
|
|
384
|
+
for (const acc of accounts2) {
|
|
385
385
|
const existingIdx = poolIndex.get(acc.address);
|
|
386
386
|
if (existingIdx === void 0) {
|
|
387
387
|
const idx = pool.length;
|
|
@@ -594,27 +594,27 @@ var require_transaction = __commonJS({
|
|
|
594
594
|
exports2.sendVersionedTransaction = sendVersionedTransaction;
|
|
595
595
|
var web3_js_1 = require("@solana/web3.js");
|
|
596
596
|
async function fetchLookupTables(connection, lookupTables) {
|
|
597
|
-
const
|
|
597
|
+
const accounts2 = await Promise.all(lookupTables.map(async (lookupTable) => {
|
|
598
598
|
const response = await connection.getAddressLookupTable(new web3_js_1.PublicKey(lookupTable));
|
|
599
599
|
if (!response.value) {
|
|
600
600
|
throw new Error(`Lookup table not found: ${lookupTable}`);
|
|
601
601
|
}
|
|
602
602
|
return response.value;
|
|
603
603
|
}));
|
|
604
|
-
return
|
|
604
|
+
return accounts2;
|
|
605
605
|
}
|
|
606
606
|
async function getSignatureStatus(connection, signature) {
|
|
607
607
|
return (await connection.getSignatureStatuses([signature], {
|
|
608
608
|
searchTransactionHistory: true
|
|
609
609
|
})).value[0];
|
|
610
610
|
}
|
|
611
|
-
async function sendVersionedTransaction({ connection, payer, instructions, lookupTables }) {
|
|
611
|
+
async function sendVersionedTransaction({ connection, payer, instructions: instructions2, lookupTables }) {
|
|
612
612
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
|
|
613
613
|
const lookupTableAccounts = await fetchLookupTables(connection, lookupTables);
|
|
614
614
|
const message = new web3_js_1.TransactionMessage({
|
|
615
615
|
payerKey: payer.publicKey,
|
|
616
616
|
recentBlockhash: blockhash,
|
|
617
|
-
instructions
|
|
617
|
+
instructions: instructions2
|
|
618
618
|
}).compileToV0Message(lookupTableAccounts);
|
|
619
619
|
const tx = new web3_js_1.VersionedTransaction(message);
|
|
620
620
|
tx.sign([payer]);
|
|
@@ -1209,37 +1209,37 @@ var require_cpiClient = __commonJS({
|
|
|
1209
1209
|
}
|
|
1210
1210
|
return value;
|
|
1211
1211
|
}
|
|
1212
|
-
function orderedDepositAccounts(
|
|
1212
|
+
function orderedDepositAccounts(accounts2) {
|
|
1213
1213
|
return [
|
|
1214
|
-
account(
|
|
1215
|
-
account(
|
|
1216
|
-
account(
|
|
1217
|
-
account(
|
|
1218
|
-
account(
|
|
1219
|
-
account(
|
|
1220
|
-
account(
|
|
1214
|
+
account(accounts2.group, kit_1.AccountRole.READONLY),
|
|
1215
|
+
account(accounts2.marginfiAccount, kit_1.AccountRole.WRITABLE),
|
|
1216
|
+
account(accounts2.authority, kit_1.AccountRole.READONLY_SIGNER),
|
|
1217
|
+
account(accounts2.bank, kit_1.AccountRole.WRITABLE),
|
|
1218
|
+
account(accounts2.signerTokenAccount, kit_1.AccountRole.WRITABLE),
|
|
1219
|
+
account(accounts2.liquidityVault, kit_1.AccountRole.WRITABLE),
|
|
1220
|
+
account(accounts2.tokenProgram, kit_1.AccountRole.READONLY)
|
|
1221
1221
|
];
|
|
1222
1222
|
}
|
|
1223
|
-
function orderedCreateAccountAccounts(
|
|
1223
|
+
function orderedCreateAccountAccounts(accounts2) {
|
|
1224
1224
|
return [
|
|
1225
|
-
account(
|
|
1226
|
-
account(
|
|
1227
|
-
account(
|
|
1228
|
-
account(
|
|
1229
|
-
account(
|
|
1230
|
-
account(
|
|
1225
|
+
account(accounts2.marginfiGroup, kit_1.AccountRole.READONLY),
|
|
1226
|
+
account(accounts2.marginfiAccount, kit_1.AccountRole.WRITABLE),
|
|
1227
|
+
account(accounts2.authority, kit_1.AccountRole.READONLY_SIGNER),
|
|
1228
|
+
account(accounts2.feePayer, kit_1.AccountRole.WRITABLE_SIGNER),
|
|
1229
|
+
account(accounts2.instructionsSysvar, kit_1.AccountRole.READONLY),
|
|
1230
|
+
account(accounts2.systemProgram, kit_1.AccountRole.READONLY)
|
|
1231
1231
|
];
|
|
1232
1232
|
}
|
|
1233
|
-
function orderedWithdrawAccounts(
|
|
1233
|
+
function orderedWithdrawAccounts(accounts2) {
|
|
1234
1234
|
return [
|
|
1235
|
-
account(
|
|
1236
|
-
account(
|
|
1237
|
-
account(
|
|
1238
|
-
account(
|
|
1239
|
-
account(
|
|
1240
|
-
account(
|
|
1241
|
-
account(
|
|
1242
|
-
account(
|
|
1235
|
+
account(accounts2.group, kit_1.AccountRole.WRITABLE),
|
|
1236
|
+
account(accounts2.marginfiAccount, kit_1.AccountRole.WRITABLE),
|
|
1237
|
+
account(accounts2.authority, kit_1.AccountRole.READONLY_SIGNER),
|
|
1238
|
+
account(accounts2.bank, kit_1.AccountRole.WRITABLE),
|
|
1239
|
+
account(accounts2.destinationTokenAccount, kit_1.AccountRole.WRITABLE),
|
|
1240
|
+
account(accounts2.bankLiquidityVaultAuthority, kit_1.AccountRole.READONLY),
|
|
1241
|
+
account(accounts2.liquidityVault, kit_1.AccountRole.WRITABLE),
|
|
1242
|
+
account(accounts2.tokenProgram, kit_1.AccountRole.READONLY)
|
|
1243
1243
|
];
|
|
1244
1244
|
}
|
|
1245
1245
|
var CpiClient = class {
|
|
@@ -1249,7 +1249,7 @@ var require_cpiClient = __commonJS({
|
|
|
1249
1249
|
this.accounts = config.accounts ?? constants_1.MARGINFI_MAIN_USDC_ACCOUNTS;
|
|
1250
1250
|
}
|
|
1251
1251
|
create_account_cpi(params) {
|
|
1252
|
-
const
|
|
1252
|
+
const accounts2 = params.accounts ?? this.createAccountAccounts({
|
|
1253
1253
|
marginfiAccount: params.marginfiAccount,
|
|
1254
1254
|
authority: params.authority,
|
|
1255
1255
|
feePayer: params.feePayer
|
|
@@ -1258,7 +1258,7 @@ var require_cpiClient = __commonJS({
|
|
|
1258
1258
|
cpiType: params.cpiType ?? common_1.CpiTypes.MARGINFI_ACCOUNT_INITIALIZE,
|
|
1259
1259
|
programId: this.programId,
|
|
1260
1260
|
accounts: [
|
|
1261
|
-
...orderedCreateAccountAccounts(
|
|
1261
|
+
...orderedCreateAccountAccounts(accounts2),
|
|
1262
1262
|
...params.remainingAccounts ?? []
|
|
1263
1263
|
],
|
|
1264
1264
|
data: (0, common_1.encodeU16AndOptionalU16)(params.accountIndex ?? constants_1.MARGINFI_ACCOUNT_INDEX, params.thirdPartyId ?? constants_1.MARGINFI_THIRD_PARTY_ID, "accountIndex", "thirdPartyId"),
|
|
@@ -1266,7 +1266,7 @@ var require_cpiClient = __commonJS({
|
|
|
1266
1266
|
};
|
|
1267
1267
|
}
|
|
1268
1268
|
deposit_cpi(params) {
|
|
1269
|
-
const
|
|
1269
|
+
const accounts2 = params.accounts ?? this.depositAccounts({
|
|
1270
1270
|
marginfiAccount: params.marginfiAccount,
|
|
1271
1271
|
authority: params.authority,
|
|
1272
1272
|
signerTokenAccount: params.signerTokenAccount
|
|
@@ -1275,7 +1275,7 @@ var require_cpiClient = __commonJS({
|
|
|
1275
1275
|
cpiType: params.cpiType ?? common_1.CpiTypes.MARGINFI_DEPOSIT,
|
|
1276
1276
|
programId: this.programId,
|
|
1277
1277
|
accounts: [
|
|
1278
|
-
...orderedDepositAccounts(
|
|
1278
|
+
...orderedDepositAccounts(accounts2),
|
|
1279
1279
|
...params.remainingAccounts ?? []
|
|
1280
1280
|
],
|
|
1281
1281
|
data: (0, common_1.encodeU64AndOptionalBool)(params.amount, params.depositUpToLimit),
|
|
@@ -1283,7 +1283,7 @@ var require_cpiClient = __commonJS({
|
|
|
1283
1283
|
};
|
|
1284
1284
|
}
|
|
1285
1285
|
withdraw_cpi(params) {
|
|
1286
|
-
const
|
|
1286
|
+
const accounts2 = params.accounts ?? this.withdrawAccounts({
|
|
1287
1287
|
marginfiAccount: params.marginfiAccount,
|
|
1288
1288
|
authority: params.authority,
|
|
1289
1289
|
destinationTokenAccount: params.destinationTokenAccount
|
|
@@ -1296,7 +1296,7 @@ var require_cpiClient = __commonJS({
|
|
|
1296
1296
|
cpiType: params.cpiType ?? common_1.CpiTypes.MARGINFI_WITHDRAW,
|
|
1297
1297
|
programId: this.programId,
|
|
1298
1298
|
accounts: [
|
|
1299
|
-
...orderedWithdrawAccounts(
|
|
1299
|
+
...orderedWithdrawAccounts(accounts2),
|
|
1300
1300
|
...params.remainingAccounts ?? [],
|
|
1301
1301
|
...bankAndOracleRemainingAccounts
|
|
1302
1302
|
],
|
|
@@ -1472,6 +1472,7 @@ __export(index_exports, {
|
|
|
1472
1472
|
dateToStr: () => dateToStr,
|
|
1473
1473
|
defaultKeypairPath: () => defaultKeypairPath,
|
|
1474
1474
|
deleteAccount: () => deleteAccount,
|
|
1475
|
+
findSquadsWalletRoute: () => findSquadsWalletRoute,
|
|
1475
1476
|
fromUiAmount: () => fromUiAmount,
|
|
1476
1477
|
getAccounts: () => getAccounts,
|
|
1477
1478
|
getBalance: () => getBalance,
|
|
@@ -1487,13 +1488,17 @@ __export(index_exports, {
|
|
|
1487
1488
|
loadKeypair: () => loadKeypair,
|
|
1488
1489
|
makeProvider: () => makeProvider,
|
|
1489
1490
|
mintTokensTo: () => mintTokensTo,
|
|
1491
|
+
prepareVaultTransaction: () => prepareVaultTransaction,
|
|
1490
1492
|
resolveKeypairPath: () => resolveKeypairPath,
|
|
1493
|
+
resolveSquadsWalletRoute: () => resolveSquadsWalletRoute,
|
|
1491
1494
|
roundToNextUtcMidnight: () => roundToNextUtcMidnight,
|
|
1492
1495
|
runLiveConsensusOracle: () => runLiveConsensusOracle,
|
|
1493
1496
|
systemClock: () => systemClock,
|
|
1494
1497
|
toUiAmount: () => toUiAmount,
|
|
1495
1498
|
updateAccount: () => updateAccount,
|
|
1496
|
-
updateDynamicApr: () => updateDynamicApr
|
|
1499
|
+
updateDynamicApr: () => updateDynamicApr,
|
|
1500
|
+
validateSquadsWalletRoutes: () => validateSquadsWalletRoutes,
|
|
1501
|
+
vaultAuthorityForWallet: () => vaultAuthorityForWallet
|
|
1497
1502
|
});
|
|
1498
1503
|
module.exports = __toCommonJS(index_exports);
|
|
1499
1504
|
|
|
@@ -11029,224 +11034,239 @@ var IDL = {
|
|
|
11029
11034
|
],
|
|
11030
11035
|
"errors": [
|
|
11031
11036
|
{
|
|
11032
|
-
"code":
|
|
11033
|
-
"name": "
|
|
11034
|
-
"msg": "
|
|
11037
|
+
"code": 14001,
|
|
11038
|
+
"name": "Unauthorized",
|
|
11039
|
+
"msg": "You are not authorized to perform this action."
|
|
11035
11040
|
},
|
|
11036
11041
|
{
|
|
11037
|
-
"code":
|
|
11038
|
-
"name": "
|
|
11039
|
-
"msg": "
|
|
11042
|
+
"code": 14002,
|
|
11043
|
+
"name": "InvalidBankMint",
|
|
11044
|
+
"msg": "Invalid mint"
|
|
11040
11045
|
},
|
|
11041
11046
|
{
|
|
11042
|
-
"code":
|
|
11043
|
-
"name": "
|
|
11044
|
-
"msg": "
|
|
11047
|
+
"code": 14003,
|
|
11048
|
+
"name": "AccountingIssue",
|
|
11049
|
+
"msg": "Accounting issue"
|
|
11045
11050
|
},
|
|
11046
11051
|
{
|
|
11047
|
-
"code":
|
|
11048
|
-
"name": "
|
|
11049
|
-
"msg": "
|
|
11052
|
+
"code": 14004,
|
|
11053
|
+
"name": "VaultAccountingIssue",
|
|
11054
|
+
"msg": "Vault accounting issue"
|
|
11050
11055
|
},
|
|
11051
11056
|
{
|
|
11052
|
-
"code":
|
|
11053
|
-
"name": "
|
|
11054
|
-
"msg": "
|
|
11057
|
+
"code": 14005,
|
|
11058
|
+
"name": "BankAccountingIssue",
|
|
11059
|
+
"msg": "Bank accounting issue"
|
|
11055
11060
|
},
|
|
11056
11061
|
{
|
|
11057
|
-
"code":
|
|
11058
|
-
"name": "
|
|
11059
|
-
"msg": "
|
|
11062
|
+
"code": 14006,
|
|
11063
|
+
"name": "OnchainAccountingIssue",
|
|
11064
|
+
"msg": "Onchain accounting issue"
|
|
11060
11065
|
},
|
|
11061
11066
|
{
|
|
11062
|
-
"code":
|
|
11063
|
-
"name": "
|
|
11064
|
-
"msg": "
|
|
11067
|
+
"code": 14007,
|
|
11068
|
+
"name": "ExternalAccountingIssue",
|
|
11069
|
+
"msg": "External accounting issue"
|
|
11065
11070
|
},
|
|
11066
11071
|
{
|
|
11067
|
-
"code":
|
|
11068
|
-
"name": "
|
|
11069
|
-
"msg": "
|
|
11072
|
+
"code": 14008,
|
|
11073
|
+
"name": "MintSlippage",
|
|
11074
|
+
"msg": "Minting failed due to slippage."
|
|
11070
11075
|
},
|
|
11071
11076
|
{
|
|
11072
|
-
"code":
|
|
11073
|
-
"name": "
|
|
11074
|
-
"msg": "
|
|
11077
|
+
"code": 14009,
|
|
11078
|
+
"name": "BurningSlippage",
|
|
11079
|
+
"msg": "Burning failed due to slippage."
|
|
11075
11080
|
},
|
|
11076
11081
|
{
|
|
11077
|
-
"code":
|
|
11082
|
+
"code": 14010,
|
|
11083
|
+
"name": "TeamAccountAlreadyExists",
|
|
11084
|
+
"msg": "Team account already exists"
|
|
11085
|
+
},
|
|
11086
|
+
{
|
|
11087
|
+
"code": 14011,
|
|
11088
|
+
"name": "OracleAccountAlreadyExists",
|
|
11089
|
+
"msg": "Oracle account already exists"
|
|
11090
|
+
},
|
|
11091
|
+
{
|
|
11092
|
+
"code": 14012,
|
|
11078
11093
|
"name": "StaleOracle",
|
|
11079
|
-
"msg": "
|
|
11094
|
+
"msg": "Stale oracle"
|
|
11080
11095
|
},
|
|
11081
11096
|
{
|
|
11082
|
-
"code":
|
|
11083
|
-
"name": "
|
|
11084
|
-
"msg": "
|
|
11097
|
+
"code": 14013,
|
|
11098
|
+
"name": "LocalSignificantPriceChange",
|
|
11099
|
+
"msg": "Price change is too large locally"
|
|
11085
11100
|
},
|
|
11086
11101
|
{
|
|
11087
|
-
"code":
|
|
11088
|
-
"name": "
|
|
11089
|
-
"msg": "
|
|
11102
|
+
"code": 14014,
|
|
11103
|
+
"name": "SignificantPriceChange",
|
|
11104
|
+
"msg": "Price change is too large"
|
|
11090
11105
|
},
|
|
11091
11106
|
{
|
|
11092
|
-
"code":
|
|
11093
|
-
"name": "
|
|
11094
|
-
"msg": "
|
|
11107
|
+
"code": 14015,
|
|
11108
|
+
"name": "RoundingImpact",
|
|
11109
|
+
"msg": "Rounding impacts the protocol"
|
|
11095
11110
|
},
|
|
11096
11111
|
{
|
|
11097
|
-
"code":
|
|
11098
|
-
"name": "
|
|
11099
|
-
"msg": "
|
|
11112
|
+
"code": 14016,
|
|
11113
|
+
"name": "BankIsHalted",
|
|
11114
|
+
"msg": "Bank is halted"
|
|
11100
11115
|
},
|
|
11101
11116
|
{
|
|
11102
|
-
"code":
|
|
11103
|
-
"name": "
|
|
11104
|
-
"msg": "
|
|
11117
|
+
"code": 14017,
|
|
11118
|
+
"name": "VaultIsHalted",
|
|
11119
|
+
"msg": "Vault is halted"
|
|
11105
11120
|
},
|
|
11106
11121
|
{
|
|
11107
|
-
"code":
|
|
11108
|
-
"name": "
|
|
11109
|
-
"msg": "
|
|
11122
|
+
"code": 14018,
|
|
11123
|
+
"name": "ConversionOverflow",
|
|
11124
|
+
"msg": "Conversion Overflow"
|
|
11110
11125
|
},
|
|
11111
11126
|
{
|
|
11112
|
-
"code":
|
|
11113
|
-
"name": "
|
|
11114
|
-
"msg": "
|
|
11127
|
+
"code": 14019,
|
|
11128
|
+
"name": "_Reserved8019",
|
|
11129
|
+
"msg": "Reserved"
|
|
11115
11130
|
},
|
|
11116
11131
|
{
|
|
11117
|
-
"code":
|
|
11118
|
-
"name": "
|
|
11119
|
-
"msg": "
|
|
11132
|
+
"code": 14020,
|
|
11133
|
+
"name": "InvalidArgument",
|
|
11134
|
+
"msg": "Invalid argument"
|
|
11120
11135
|
},
|
|
11121
11136
|
{
|
|
11122
|
-
"code":
|
|
11123
|
-
"name": "
|
|
11124
|
-
"msg": "
|
|
11137
|
+
"code": 14021,
|
|
11138
|
+
"name": "UserSanityCheck",
|
|
11139
|
+
"msg": "User Sanity Check"
|
|
11125
11140
|
},
|
|
11126
11141
|
{
|
|
11127
|
-
"code":
|
|
11128
|
-
"name": "
|
|
11129
|
-
"msg": "
|
|
11142
|
+
"code": 14022,
|
|
11143
|
+
"name": "MathOverflow",
|
|
11144
|
+
"msg": "Math overflow"
|
|
11130
11145
|
},
|
|
11131
11146
|
{
|
|
11132
|
-
"code":
|
|
11133
|
-
"name": "
|
|
11134
|
-
"msg": "
|
|
11147
|
+
"code": 14023,
|
|
11148
|
+
"name": "InvalidMarginFiAccount",
|
|
11149
|
+
"msg": "Invalid MarginFi account - must be correct PDA for this vault"
|
|
11135
11150
|
},
|
|
11136
11151
|
{
|
|
11137
|
-
"code":
|
|
11138
|
-
"name": "
|
|
11139
|
-
"msg": "Invalid
|
|
11152
|
+
"code": 14024,
|
|
11153
|
+
"name": "InvalidStartMarker",
|
|
11154
|
+
"msg": "Invalid start marker"
|
|
11140
11155
|
},
|
|
11141
11156
|
{
|
|
11142
|
-
"code":
|
|
11143
|
-
"name": "
|
|
11144
|
-
"msg": "
|
|
11157
|
+
"code": 14025,
|
|
11158
|
+
"name": "OracleUpdateOnEmptyReserve",
|
|
11159
|
+
"msg": "Unable to push oracle update on an empty vault reserve"
|
|
11145
11160
|
},
|
|
11146
11161
|
{
|
|
11147
|
-
"code":
|
|
11148
|
-
"name": "
|
|
11149
|
-
"msg": "
|
|
11162
|
+
"code": 14026,
|
|
11163
|
+
"name": "InvalidRemainingAccountsLength",
|
|
11164
|
+
"msg": "Invalid remaining accounts length"
|
|
11150
11165
|
},
|
|
11151
11166
|
{
|
|
11152
|
-
"code":
|
|
11153
|
-
"name": "
|
|
11154
|
-
"msg": "
|
|
11167
|
+
"code": 14027,
|
|
11168
|
+
"name": "WithdrawalExceedsBalance",
|
|
11169
|
+
"msg": "Specified withdrawal exceeds available balance"
|
|
11155
11170
|
},
|
|
11156
11171
|
{
|
|
11157
|
-
"code":
|
|
11158
|
-
"name": "
|
|
11159
|
-
"msg": "
|
|
11172
|
+
"code": 14028,
|
|
11173
|
+
"name": "InsufficientPendingYield",
|
|
11174
|
+
"msg": "Insufficient pending yield"
|
|
11160
11175
|
},
|
|
11161
11176
|
{
|
|
11162
|
-
"code":
|
|
11163
|
-
"name": "
|
|
11164
|
-
"msg": "
|
|
11177
|
+
"code": 14029,
|
|
11178
|
+
"name": "NotSupported",
|
|
11179
|
+
"msg": "Not supported"
|
|
11165
11180
|
},
|
|
11166
11181
|
{
|
|
11167
|
-
"code":
|
|
11168
|
-
"name": "
|
|
11169
|
-
"msg": "
|
|
11182
|
+
"code": 14030,
|
|
11183
|
+
"name": "ExceedsMaxYieldingTvl",
|
|
11184
|
+
"msg": "Exceeds maximum yielding TVL"
|
|
11170
11185
|
},
|
|
11171
11186
|
{
|
|
11172
|
-
"code":
|
|
11173
|
-
"name": "
|
|
11174
|
-
"msg": "
|
|
11187
|
+
"code": 14031,
|
|
11188
|
+
"name": "TranchingNotEnabled",
|
|
11189
|
+
"msg": "Tranching is not enabled for this bank"
|
|
11175
11190
|
},
|
|
11176
11191
|
{
|
|
11177
|
-
"code":
|
|
11178
|
-
"name": "
|
|
11179
|
-
"msg": "Invalid
|
|
11192
|
+
"code": 14032,
|
|
11193
|
+
"name": "InvalidLeverageFactor",
|
|
11194
|
+
"msg": "Invalid leverage factor - must be at least 10000 (1x)"
|
|
11180
11195
|
},
|
|
11181
11196
|
{
|
|
11182
|
-
"code":
|
|
11183
|
-
"name": "
|
|
11184
|
-
"msg": "
|
|
11197
|
+
"code": 14033,
|
|
11198
|
+
"name": "InsufficientStakedAmount",
|
|
11199
|
+
"msg": "Insufficient staked amount"
|
|
11185
11200
|
},
|
|
11186
11201
|
{
|
|
11187
|
-
"code":
|
|
11188
|
-
"name": "
|
|
11189
|
-
"msg": "
|
|
11202
|
+
"code": 14034,
|
|
11203
|
+
"name": "JuniorTrancheEmpty",
|
|
11204
|
+
"msg": "Junior tranche has no value"
|
|
11190
11205
|
},
|
|
11191
11206
|
{
|
|
11192
|
-
"code":
|
|
11193
|
-
"name": "
|
|
11194
|
-
"msg": "Invalid
|
|
11207
|
+
"code": 14035,
|
|
11208
|
+
"name": "InvalidTrancheConfig",
|
|
11209
|
+
"msg": "Invalid tranche config parameter"
|
|
11210
|
+
},
|
|
11211
|
+
{
|
|
11212
|
+
"code": 14036,
|
|
11213
|
+
"name": "WithdrawalQueueNotExpired",
|
|
11214
|
+
"msg": "Withdrawal queue lockup period has not expired"
|
|
11195
11215
|
},
|
|
11196
11216
|
{
|
|
11197
|
-
"code":
|
|
11198
|
-
"name": "
|
|
11199
|
-
"msg": "
|
|
11217
|
+
"code": 14037,
|
|
11218
|
+
"name": "InvalidWithdrawalQueue",
|
|
11219
|
+
"msg": "Withdrawal queue entry is not in a valid state"
|
|
11200
11220
|
},
|
|
11201
11221
|
{
|
|
11202
|
-
"code":
|
|
11203
|
-
"name": "
|
|
11204
|
-
"msg": "
|
|
11222
|
+
"code": 14038,
|
|
11223
|
+
"name": "InvalidAccount",
|
|
11224
|
+
"msg": "Account does not belong to the expected parent"
|
|
11205
11225
|
},
|
|
11206
11226
|
{
|
|
11207
|
-
"code":
|
|
11208
|
-
"name": "
|
|
11209
|
-
"msg": "
|
|
11227
|
+
"code": 14039,
|
|
11228
|
+
"name": "MissingAccount",
|
|
11229
|
+
"msg": "Required optional account is missing"
|
|
11210
11230
|
},
|
|
11211
11231
|
{
|
|
11212
|
-
"code":
|
|
11213
|
-
"name": "
|
|
11214
|
-
"msg": "
|
|
11232
|
+
"code": 14040,
|
|
11233
|
+
"name": "TrancheWipedOut",
|
|
11234
|
+
"msg": "Junior tranche is wiped out and cannot accept new stakes"
|
|
11215
11235
|
},
|
|
11216
11236
|
{
|
|
11217
|
-
"code":
|
|
11218
|
-
"name": "
|
|
11219
|
-
"msg": "
|
|
11237
|
+
"code": 14041,
|
|
11238
|
+
"name": "VaultLossNotAccepted",
|
|
11239
|
+
"msg": "Vault does not accept losses \u2014 enable losses_accepted before retrying"
|
|
11220
11240
|
},
|
|
11221
11241
|
{
|
|
11222
|
-
"code":
|
|
11223
|
-
"name": "
|
|
11224
|
-
"msg": "
|
|
11242
|
+
"code": 14042,
|
|
11243
|
+
"name": "CapitalLossExceedsReserve",
|
|
11244
|
+
"msg": "Capital loss exceeds available yielding reserve"
|
|
11225
11245
|
},
|
|
11226
11246
|
{
|
|
11227
|
-
"code":
|
|
11228
|
-
"name": "
|
|
11229
|
-
"msg": "
|
|
11247
|
+
"code": 14043,
|
|
11248
|
+
"name": "RollingWithdrawalLimitExceeded",
|
|
11249
|
+
"msg": "Rolling withdrawal limit exceeded"
|
|
11230
11250
|
},
|
|
11231
11251
|
{
|
|
11232
|
-
"code":
|
|
11233
|
-
"name": "
|
|
11234
|
-
"msg": "
|
|
11252
|
+
"code": 14044,
|
|
11253
|
+
"name": "VaultAlreadyMigrated",
|
|
11254
|
+
"msg": "Legacy vault has already been migrated"
|
|
11235
11255
|
},
|
|
11236
11256
|
{
|
|
11237
|
-
"code":
|
|
11238
|
-
"name": "
|
|
11239
|
-
"msg": "
|
|
11257
|
+
"code": 14045,
|
|
11258
|
+
"name": "InvalidMigrationState",
|
|
11259
|
+
"msg": "Legacy vault migration is incomplete or invalid"
|
|
11240
11260
|
},
|
|
11241
11261
|
{
|
|
11242
|
-
"code":
|
|
11243
|
-
"name": "
|
|
11244
|
-
"msg": "
|
|
11262
|
+
"code": 14046,
|
|
11263
|
+
"name": "InvalidMigrationMintAuthority",
|
|
11264
|
+
"msg": "Mint authority does not match the expected migration source"
|
|
11245
11265
|
},
|
|
11246
11266
|
{
|
|
11247
|
-
"code":
|
|
11248
|
-
"name": "
|
|
11249
|
-
"msg": "
|
|
11267
|
+
"code": 14047,
|
|
11268
|
+
"name": "BankMigrationIncomplete",
|
|
11269
|
+
"msg": "Legacy bank or tranche migration is incomplete \u2014 source accounting and escrow must be fully drained before mint authority transfer"
|
|
11250
11270
|
}
|
|
11251
11271
|
],
|
|
11252
11272
|
"types": [
|
|
@@ -18158,7 +18178,7 @@ var VaultReallocationBuilder = class extends VaultBuilderBase {
|
|
|
18158
18178
|
}
|
|
18159
18179
|
async buildPreambleInstructions(args) {
|
|
18160
18180
|
const payer = (0, import_common34.toWeb3Pk)(args.manager);
|
|
18161
|
-
const
|
|
18181
|
+
const instructions2 = [
|
|
18162
18182
|
(0, import_spl_token17.createAssociatedTokenAccountIdempotentInstruction)(
|
|
18163
18183
|
payer,
|
|
18164
18184
|
(0, import_common34.toWeb3Pk)(args.allocationMintAta),
|
|
@@ -18193,7 +18213,7 @@ var VaultReallocationBuilder = class extends VaultBuilderBase {
|
|
|
18193
18213
|
)
|
|
18194
18214
|
];
|
|
18195
18215
|
if (args.sourceVault && args.sourceShareMint && args.sourceVaultMintAta && args.allocationSourceShareAta) {
|
|
18196
|
-
|
|
18216
|
+
instructions2.push(
|
|
18197
18217
|
(0, import_spl_token17.createAssociatedTokenAccountIdempotentInstruction)(
|
|
18198
18218
|
payer,
|
|
18199
18219
|
(0, import_common34.toWeb3Pk)(args.sourceVaultMintAta),
|
|
@@ -18212,7 +18232,7 @@ var VaultReallocationBuilder = class extends VaultBuilderBase {
|
|
|
18212
18232
|
)
|
|
18213
18233
|
);
|
|
18214
18234
|
}
|
|
18215
|
-
return
|
|
18235
|
+
return instructions2.map(import_common34.toKitInstruction);
|
|
18216
18236
|
}
|
|
18217
18237
|
async buildPlanExtras(args) {
|
|
18218
18238
|
return {
|
|
@@ -18447,15 +18467,129 @@ function makeProvider(connection, payer) {
|
|
|
18447
18467
|
});
|
|
18448
18468
|
}
|
|
18449
18469
|
|
|
18470
|
+
// src/utils/squads.ts
|
|
18471
|
+
var squads = __toESM(require("@sqds/multisig"));
|
|
18472
|
+
var import_web321 = require("@solana/web3.js");
|
|
18473
|
+
function validateVaultIndex(vaultIndex) {
|
|
18474
|
+
if (!Number.isSafeInteger(vaultIndex) || vaultIndex < 0) {
|
|
18475
|
+
throw new Error("Squads vaultIndex must be a non-negative safe integer");
|
|
18476
|
+
}
|
|
18477
|
+
}
|
|
18478
|
+
function resolveSquadsWalletRoute(route) {
|
|
18479
|
+
validateVaultIndex(route.vaultIndex);
|
|
18480
|
+
const wallet = new import_web321.PublicKey(route.wallet);
|
|
18481
|
+
const multisigPda = new import_web321.PublicKey(route.multisigPda);
|
|
18482
|
+
const [vaultPda] = squads.getVaultPda({
|
|
18483
|
+
multisigPda,
|
|
18484
|
+
index: route.vaultIndex
|
|
18485
|
+
});
|
|
18486
|
+
return { ...route, wallet, multisigPda, vaultPda };
|
|
18487
|
+
}
|
|
18488
|
+
function findSquadsWalletRoute(wallet, routes) {
|
|
18489
|
+
const walletKey = typeof wallet === "string" ? new import_web321.PublicKey(wallet) : wallet;
|
|
18490
|
+
const route = routes.find(
|
|
18491
|
+
(candidate) => candidate.wallet === walletKey.toBase58()
|
|
18492
|
+
);
|
|
18493
|
+
return route ? resolveSquadsWalletRoute(route) : void 0;
|
|
18494
|
+
}
|
|
18495
|
+
function validateSquadsWalletRoutes(routes) {
|
|
18496
|
+
const wallets = /* @__PURE__ */ new Set();
|
|
18497
|
+
for (const route of routes) {
|
|
18498
|
+
const resolved = resolveSquadsWalletRoute(route);
|
|
18499
|
+
const wallet = resolved.wallet.toBase58();
|
|
18500
|
+
if (wallets.has(wallet)) {
|
|
18501
|
+
throw new Error(`Duplicate Squads route for wallet ${wallet}`);
|
|
18502
|
+
}
|
|
18503
|
+
wallets.add(wallet);
|
|
18504
|
+
}
|
|
18505
|
+
}
|
|
18506
|
+
function vaultAuthorityForWallet(wallet, routes) {
|
|
18507
|
+
const walletKey = typeof wallet === "string" ? new import_web321.PublicKey(wallet) : wallet;
|
|
18508
|
+
return findSquadsWalletRoute(walletKey, routes)?.vaultPda ?? walletKey;
|
|
18509
|
+
}
|
|
18510
|
+
async function prepareVaultTransaction(args) {
|
|
18511
|
+
const { connection, proposer, instructions: instructions2 } = args;
|
|
18512
|
+
const route = findSquadsWalletRoute(proposer, args.squadsRoutes ?? []);
|
|
18513
|
+
if (!route) {
|
|
18514
|
+
return {
|
|
18515
|
+
kind: "direct",
|
|
18516
|
+
transaction: new import_web321.Transaction().add(...instructions2),
|
|
18517
|
+
authority: proposer
|
|
18518
|
+
};
|
|
18519
|
+
}
|
|
18520
|
+
const multisig = await squads.accounts.Multisig.fromAccountAddress(
|
|
18521
|
+
connection,
|
|
18522
|
+
route.multisigPda
|
|
18523
|
+
);
|
|
18524
|
+
const member = multisig.members.find(
|
|
18525
|
+
(candidate) => candidate.key.equals(proposer)
|
|
18526
|
+
);
|
|
18527
|
+
if (!member) {
|
|
18528
|
+
throw new Error(
|
|
18529
|
+
`Wallet ${proposer.toBase58()} is not a member of Squads multisig ${route.multisigPda.toBase58()}`
|
|
18530
|
+
);
|
|
18531
|
+
}
|
|
18532
|
+
if (!squads.types.Permissions.has(
|
|
18533
|
+
member.permissions,
|
|
18534
|
+
squads.types.Permission.Initiate
|
|
18535
|
+
)) {
|
|
18536
|
+
throw new Error(
|
|
18537
|
+
`Wallet ${proposer.toBase58()} cannot initiate proposals for Squads multisig ${route.multisigPda.toBase58()}`
|
|
18538
|
+
);
|
|
18539
|
+
}
|
|
18540
|
+
const transactionIndex = BigInt(multisig.transactionIndex.toString()) + 1n;
|
|
18541
|
+
const { blockhash } = await connection.getLatestBlockhash("confirmed");
|
|
18542
|
+
const transactionMessage = new import_web321.TransactionMessage({
|
|
18543
|
+
payerKey: route.vaultPda,
|
|
18544
|
+
recentBlockhash: blockhash,
|
|
18545
|
+
instructions: [...instructions2]
|
|
18546
|
+
});
|
|
18547
|
+
const createVaultTransactionIx = squads.instructions.vaultTransactionCreate({
|
|
18548
|
+
multisigPda: route.multisigPda,
|
|
18549
|
+
transactionIndex,
|
|
18550
|
+
creator: proposer,
|
|
18551
|
+
vaultIndex: route.vaultIndex,
|
|
18552
|
+
ephemeralSigners: 0,
|
|
18553
|
+
transactionMessage,
|
|
18554
|
+
memo: route.memo
|
|
18555
|
+
});
|
|
18556
|
+
const createProposalIx = squads.instructions.proposalCreate({
|
|
18557
|
+
multisigPda: route.multisigPda,
|
|
18558
|
+
transactionIndex,
|
|
18559
|
+
creator: proposer
|
|
18560
|
+
});
|
|
18561
|
+
const [proposalPda] = squads.getProposalPda({
|
|
18562
|
+
multisigPda: route.multisigPda,
|
|
18563
|
+
transactionIndex
|
|
18564
|
+
});
|
|
18565
|
+
const [vaultTransactionPda] = squads.getTransactionPda({
|
|
18566
|
+
multisigPda: route.multisigPda,
|
|
18567
|
+
index: transactionIndex
|
|
18568
|
+
});
|
|
18569
|
+
return {
|
|
18570
|
+
kind: "squads",
|
|
18571
|
+
transaction: new import_web321.Transaction().add(
|
|
18572
|
+
createVaultTransactionIx,
|
|
18573
|
+
createProposalIx
|
|
18574
|
+
),
|
|
18575
|
+
authority: route.vaultPda,
|
|
18576
|
+
multisigPda: route.multisigPda,
|
|
18577
|
+
vaultIndex: route.vaultIndex,
|
|
18578
|
+
transactionIndex,
|
|
18579
|
+
proposalPda,
|
|
18580
|
+
vaultTransactionPda
|
|
18581
|
+
};
|
|
18582
|
+
}
|
|
18583
|
+
|
|
18450
18584
|
// src/utils/token.ts
|
|
18451
18585
|
var import_spl_token18 = require("@solana/spl-token");
|
|
18452
|
-
var
|
|
18586
|
+
var import_web322 = require("@solana/web3.js");
|
|
18453
18587
|
var import_common37 = __toESM(require_dist());
|
|
18454
18588
|
async function createTokenMintIxs(connection, payer, authority, decimals, tokenProgram = import_spl_token18.TOKEN_2022_PROGRAM_ID) {
|
|
18455
|
-
const mint =
|
|
18589
|
+
const mint = import_web322.Keypair.generate();
|
|
18456
18590
|
const lamports = await (0, import_spl_token18.getMinimumBalanceForRentExemptMint)(connection);
|
|
18457
18591
|
const ixs = [
|
|
18458
|
-
|
|
18592
|
+
import_web322.SystemProgram.createAccount({
|
|
18459
18593
|
fromPubkey: payer,
|
|
18460
18594
|
newAccountPubkey: mint.publicKey,
|
|
18461
18595
|
space: import_spl_token18.MINT_SIZE,
|
|
@@ -18481,7 +18615,7 @@ async function createTokenMint(connection, payer, decimals, tokenProgram = impor
|
|
|
18481
18615
|
tokenProgram
|
|
18482
18616
|
);
|
|
18483
18617
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
|
|
18484
|
-
const tx = new
|
|
18618
|
+
const tx = new import_web322.Transaction().add(...ixs);
|
|
18485
18619
|
tx.feePayer = payer.publicKey;
|
|
18486
18620
|
tx.recentBlockhash = blockhash;
|
|
18487
18621
|
tx.sign(payer, mint);
|
|
@@ -18520,7 +18654,7 @@ async function mintTokensTo(connection, payer, mint, destination, amount, tokenP
|
|
|
18520
18654
|
tokenProgramPk
|
|
18521
18655
|
)
|
|
18522
18656
|
];
|
|
18523
|
-
const tx = new
|
|
18657
|
+
const tx = new import_web322.Transaction().add(...ixs);
|
|
18524
18658
|
await connection.sendTransaction(tx, [payer]);
|
|
18525
18659
|
}
|
|
18526
18660
|
|
|
@@ -18793,8 +18927,8 @@ var WithdrawalQueueService = class {
|
|
|
18793
18927
|
/** All withdrawal-queue accounts owned by the vault program. */
|
|
18794
18928
|
async fetchAllQueues() {
|
|
18795
18929
|
const program = this.client.program.account;
|
|
18796
|
-
const
|
|
18797
|
-
return
|
|
18930
|
+
const accounts2 = await program.vaultWithdrawalQueue.all();
|
|
18931
|
+
return accounts2.map(
|
|
18798
18932
|
(entry) => this.toSnapshot((0, import_common38.fromWeb3Pk)(entry.publicKey), entry.account)
|
|
18799
18933
|
);
|
|
18800
18934
|
}
|
|
@@ -19154,7 +19288,7 @@ var JupiterPriceSource = class {
|
|
|
19154
19288
|
};
|
|
19155
19289
|
|
|
19156
19290
|
// src/services/consensusOracle/jupiterBalanceSource.ts
|
|
19157
|
-
var
|
|
19291
|
+
var import_web323 = require("@solana/web3.js");
|
|
19158
19292
|
var import_spl_token19 = require("@solana/spl-token");
|
|
19159
19293
|
var import_common40 = __toESM(require_dist());
|
|
19160
19294
|
var DEFAULT_BASE_URL2 = "https://lite-api.jup.ag/ultra/v1/balances";
|
|
@@ -19211,7 +19345,7 @@ var JupiterBalanceSource = class {
|
|
|
19211
19345
|
for (const programId of [import_spl_token19.TOKEN_PROGRAM_ID, import_spl_token19.TOKEN_2022_PROGRAM_ID]) {
|
|
19212
19346
|
const { value } = await this.connection.getParsedTokenAccountsByOwner(
|
|
19213
19347
|
ownerPk,
|
|
19214
|
-
{ programId: new
|
|
19348
|
+
{ programId: new import_web323.PublicKey(programId) }
|
|
19215
19349
|
);
|
|
19216
19350
|
for (const { account } of value) {
|
|
19217
19351
|
const info = account.data.parsed?.info;
|
|
@@ -19262,7 +19396,7 @@ var StaticPositionProvider = class {
|
|
|
19262
19396
|
|
|
19263
19397
|
// src/services/consensusOracle/kaminoPositionProvider.ts
|
|
19264
19398
|
var import_kit12 = require("@solana/kit");
|
|
19265
|
-
var
|
|
19399
|
+
var import_web324 = require("@solana/web3.js");
|
|
19266
19400
|
var import_klend_sdk = require("@kamino-finance/klend-sdk");
|
|
19267
19401
|
async function readKaminoBalance(manager, vault, sharesHolder) {
|
|
19268
19402
|
const userShares = await manager.getUserSharesBalanceSingleVault(
|
|
@@ -19299,7 +19433,7 @@ var KaminoPositionProvider = class {
|
|
|
19299
19433
|
const amount = await readKaminoBalance(
|
|
19300
19434
|
manager,
|
|
19301
19435
|
kVault,
|
|
19302
|
-
new
|
|
19436
|
+
new import_web324.PublicKey(sharesHolder)
|
|
19303
19437
|
);
|
|
19304
19438
|
out.push({ mint: ref.mint, amount });
|
|
19305
19439
|
}
|
|
@@ -19308,7 +19442,7 @@ var KaminoPositionProvider = class {
|
|
|
19308
19442
|
};
|
|
19309
19443
|
|
|
19310
19444
|
// src/services/consensusOracle/marginfiPositionProvider.ts
|
|
19311
|
-
var
|
|
19445
|
+
var import_web325 = require("@solana/web3.js");
|
|
19312
19446
|
var import_marginfi_client_v2 = require("@mrgnlabs/marginfi-client-v2");
|
|
19313
19447
|
function parseBankPksFromMarginfiAccount(data) {
|
|
19314
19448
|
const DISCRIMINATOR = 8;
|
|
@@ -19321,7 +19455,7 @@ function parseBankPksFromMarginfiAccount(data) {
|
|
|
19321
19455
|
if (base + BALANCE_SIZE > data.length) break;
|
|
19322
19456
|
const active = data[base];
|
|
19323
19457
|
if (!active) continue;
|
|
19324
|
-
out.push(new
|
|
19458
|
+
out.push(new import_web325.PublicKey(data.subarray(base + 1, base + 33)));
|
|
19325
19459
|
}
|
|
19326
19460
|
return out;
|
|
19327
19461
|
}
|
|
@@ -19359,8 +19493,8 @@ var MarginfiPositionProvider = class {
|
|
|
19359
19493
|
async positionsFor(ctx) {
|
|
19360
19494
|
const refs = ctx.refs.filter((r) => r.kind === "marginfi");
|
|
19361
19495
|
if (refs.length === 0) return [];
|
|
19362
|
-
const explicitBanks = refs.map((r) => r.marginfiBank).filter(Boolean).map((bank) => new
|
|
19363
|
-
const autoAccountPks = refs.filter((r) => !r.marginfiBank).map((r) => r.marginfiAccount).filter(Boolean).map((account) => new
|
|
19496
|
+
const explicitBanks = refs.map((r) => r.marginfiBank).filter(Boolean).map((bank) => new import_web325.PublicKey(bank));
|
|
19497
|
+
const autoAccountPks = refs.filter((r) => !r.marginfiBank).map((r) => r.marginfiAccount).filter(Boolean).map((account) => new import_web325.PublicKey(account));
|
|
19364
19498
|
const autoBanks = [];
|
|
19365
19499
|
for (const accountPk of autoAccountPks) {
|
|
19366
19500
|
try {
|
|
@@ -19391,14 +19525,14 @@ var MarginfiPositionProvider = class {
|
|
|
19391
19525
|
if (bank) {
|
|
19392
19526
|
const amount = await readMarginfiBalance(
|
|
19393
19527
|
client,
|
|
19394
|
-
new
|
|
19395
|
-
new
|
|
19528
|
+
new import_web325.PublicKey(account),
|
|
19529
|
+
new import_web325.PublicKey(bank)
|
|
19396
19530
|
);
|
|
19397
19531
|
out.push({ mint: ref.mint, amount });
|
|
19398
19532
|
} else {
|
|
19399
19533
|
const balances = await readAllMarginfiBalances(
|
|
19400
19534
|
client,
|
|
19401
|
-
new
|
|
19535
|
+
new import_web325.PublicKey(account)
|
|
19402
19536
|
);
|
|
19403
19537
|
for (const { mint, amount } of balances) {
|
|
19404
19538
|
out.push({ mint: mint.toBase58(), amount });
|
|
@@ -19418,7 +19552,11 @@ function createLiveConsensusOracleDeps(connection, opts = {}) {
|
|
|
19418
19552
|
balanceSource: new JupiterBalanceSource(connection, {
|
|
19419
19553
|
rpcOnly: opts.rpcOnly ?? false,
|
|
19420
19554
|
log
|
|
19421
|
-
})
|
|
19555
|
+
}),
|
|
19556
|
+
yieldTracker: {
|
|
19557
|
+
getTotalOutstandingYield,
|
|
19558
|
+
getYieldPayments
|
|
19559
|
+
}
|
|
19422
19560
|
};
|
|
19423
19561
|
if (opts.includeExternalPositions ?? true) {
|
|
19424
19562
|
deps.externalPositions = new ExternalPositionRegistry(
|
|
@@ -19433,7 +19571,7 @@ function createLiveConsensusOracleDeps(connection, opts = {}) {
|
|
|
19433
19571
|
}
|
|
19434
19572
|
|
|
19435
19573
|
// src/services/consensusOracle/consensusOracleService.ts
|
|
19436
|
-
var
|
|
19574
|
+
var import_web326 = require("@solana/web3.js");
|
|
19437
19575
|
var import_common41 = __toESM(require_dist());
|
|
19438
19576
|
var SYSTEM_PROGRAM2 = "11111111111111111111111111111111";
|
|
19439
19577
|
var CONSENSUS_ORACLE_VARIANT = "consensusoracle";
|
|
@@ -19467,7 +19605,7 @@ function parseExternalLiquidityRefs(vaultState) {
|
|
|
19467
19605
|
if (!data || data.length < 40) continue;
|
|
19468
19606
|
if (data[0] !== 1) continue;
|
|
19469
19607
|
const pubkeyBytes = new Uint8Array(data.slice(8, 40));
|
|
19470
|
-
const userAccount = new
|
|
19608
|
+
const userAccount = new import_web326.PublicKey(pubkeyBytes).toBase58();
|
|
19471
19609
|
refs.push({
|
|
19472
19610
|
kind: "marginfi",
|
|
19473
19611
|
mint: "",
|
|
@@ -19497,6 +19635,7 @@ var ConsensusOracleService = class {
|
|
|
19497
19635
|
log(`vault ${target.vault}: no consensus holdings, skipping`);
|
|
19498
19636
|
return { vault: target.vault, updates: [], dryRun };
|
|
19499
19637
|
}
|
|
19638
|
+
await this.assertNoUnconfirmedYieldPayments(target);
|
|
19500
19639
|
const inputs = await this.gatherPricingInputs(
|
|
19501
19640
|
target,
|
|
19502
19641
|
vaultState,
|
|
@@ -19507,7 +19646,7 @@ var ConsensusOracleService = class {
|
|
|
19507
19646
|
log(`vault ${target.vault}: dry run, ${updates.length} holding(s)`);
|
|
19508
19647
|
return { vault: target.vault, updates, dryRun: true };
|
|
19509
19648
|
}
|
|
19510
|
-
const { updateSignature, crankSignature, crankSkippedReason } = await this.settleVault(signer, target
|
|
19649
|
+
const { updateSignature, crankSignature, crankSkippedReason } = await this.settleVault(signer, target, updates, vaultState, log);
|
|
19511
19650
|
return {
|
|
19512
19651
|
vault: target.vault,
|
|
19513
19652
|
updates,
|
|
@@ -19517,6 +19656,39 @@ var ConsensusOracleService = class {
|
|
|
19517
19656
|
crankSkippedReason
|
|
19518
19657
|
};
|
|
19519
19658
|
}
|
|
19659
|
+
/**
|
|
19660
|
+
* Fail closed while any configured yield account has an unsettled payment.
|
|
19661
|
+
* The payout must be confirmed only after it is visible in the same wallet
|
|
19662
|
+
* balance source used by this service. Until then, no oracle update is safe.
|
|
19663
|
+
*/
|
|
19664
|
+
async assertNoUnconfirmedYieldPayments(target) {
|
|
19665
|
+
const accountNames = [
|
|
19666
|
+
...new Set(
|
|
19667
|
+
(target.holdings ?? []).flatMap(
|
|
19668
|
+
(holding) => holding.yieldAccountNames ?? []
|
|
19669
|
+
)
|
|
19670
|
+
)
|
|
19671
|
+
];
|
|
19672
|
+
if (accountNames.length === 0) return;
|
|
19673
|
+
if (!this.deps.yieldTracker) {
|
|
19674
|
+
throw new Error(
|
|
19675
|
+
`vault ${target.vault}: yield accounts are configured but no yield tracker is available`
|
|
19676
|
+
);
|
|
19677
|
+
}
|
|
19678
|
+
for (const accountName of accountNames) {
|
|
19679
|
+
const payments = await this.deps.yieldTracker.getYieldPayments(
|
|
19680
|
+
accountName
|
|
19681
|
+
);
|
|
19682
|
+
const unconfirmed = payments.filter(
|
|
19683
|
+
(payment) => payment.status !== "confirmed"
|
|
19684
|
+
);
|
|
19685
|
+
if (unconfirmed.length > 0) {
|
|
19686
|
+
throw new Error(
|
|
19687
|
+
`vault ${target.vault}: oracle update blocked because yield account "${accountName}" has ${unconfirmed.length} unconfirmed payment(s): ` + unconfirmed.map((payment) => payment.id).join(", ")
|
|
19688
|
+
);
|
|
19689
|
+
}
|
|
19690
|
+
}
|
|
19691
|
+
}
|
|
19520
19692
|
/**
|
|
19521
19693
|
* Drive several vaults in sequence. Non-fatal: a failure on one vault is
|
|
19522
19694
|
* recorded and the rest still run (mirrors the oracle-updater daemon).
|
|
@@ -19714,7 +19886,8 @@ var ConsensusOracleService = class {
|
|
|
19714
19886
|
}
|
|
19715
19887
|
// ── Settlement ───────────────────────────────────────────────────────────────
|
|
19716
19888
|
/** Push the consensus report for all holdings, then settle NAV. */
|
|
19717
|
-
async settleVault(signer,
|
|
19889
|
+
async settleVault(signer, target, updates, vaultState, log) {
|
|
19890
|
+
const vault = target.vault;
|
|
19718
19891
|
log(
|
|
19719
19892
|
`vault ${vault}: submitting ${updates.length} consensus asset update(s)`
|
|
19720
19893
|
);
|
|
@@ -19724,6 +19897,7 @@ var ConsensusOracleService = class {
|
|
|
19724
19897
|
);
|
|
19725
19898
|
}
|
|
19726
19899
|
await this.logProspectiveApy(vault, updates, vaultState, log);
|
|
19900
|
+
await this.assertNoUnconfirmedYieldPayments(target);
|
|
19727
19901
|
const updateSignature = await this.oracle.updateAssetConsensusPrice(
|
|
19728
19902
|
signer,
|
|
19729
19903
|
{
|
|
@@ -19868,6 +20042,12 @@ var MockYieldTracker = class {
|
|
|
19868
20042
|
}
|
|
19869
20043
|
return state;
|
|
19870
20044
|
}
|
|
20045
|
+
async getYieldPayments(accountName) {
|
|
20046
|
+
return this.require(accountName).yieldPayments.map((payment) => ({
|
|
20047
|
+
id: payment.paymentId,
|
|
20048
|
+
status: payment.status
|
|
20049
|
+
}));
|
|
20050
|
+
}
|
|
19871
20051
|
async getYield(accountName, start, end) {
|
|
19872
20052
|
const state = this.require(accountName);
|
|
19873
20053
|
const windowStartMs = Math.max(
|
|
@@ -19993,7 +20173,7 @@ var MockYieldTracker = class {
|
|
|
19993
20173
|
|
|
19994
20174
|
// src/services/externalLiquidityIntegrityService.ts
|
|
19995
20175
|
var import_kit13 = require("@solana/kit");
|
|
19996
|
-
var
|
|
20176
|
+
var import_web327 = require("@solana/web3.js");
|
|
19997
20177
|
var import_common42 = __toESM(require_dist());
|
|
19998
20178
|
var import_marginfi2 = __toESM(require_dist2());
|
|
19999
20179
|
function parseActiveSlots(externalLiquidity) {
|
|
@@ -20006,7 +20186,7 @@ function parseActiveSlots(externalLiquidity) {
|
|
|
20006
20186
|
if (discriminant === 0) continue;
|
|
20007
20187
|
if (discriminant !== 1) continue;
|
|
20008
20188
|
const pubkeyBytes = new Uint8Array(data.slice(8, 40));
|
|
20009
|
-
const userAccount = (0, import_common42.toAddress)(new
|
|
20189
|
+
const userAccount = (0, import_common42.toAddress)(new import_web327.PublicKey(pubkeyBytes));
|
|
20010
20190
|
results.push({ index: i, source: "marginfi", userAccount });
|
|
20011
20191
|
}
|
|
20012
20192
|
return results;
|
|
@@ -20072,7 +20252,7 @@ var ExternalLiquidityIntegrityService = class {
|
|
|
20072
20252
|
return result;
|
|
20073
20253
|
}
|
|
20074
20254
|
const hwManagerAddress = (0, import_common42.fromWeb3Pk)(hwManager.publicKey);
|
|
20075
|
-
const vaultPk = new
|
|
20255
|
+
const vaultPk = new import_web327.PublicKey(vault.toString());
|
|
20076
20256
|
const registeredHwManager = pubkeyStr(
|
|
20077
20257
|
vaultState.roles.hwManager
|
|
20078
20258
|
);
|
|
@@ -20273,6 +20453,7 @@ var ExternalLiquidityIntegrityService = class {
|
|
|
20273
20453
|
dateToStr,
|
|
20274
20454
|
defaultKeypairPath,
|
|
20275
20455
|
deleteAccount,
|
|
20456
|
+
findSquadsWalletRoute,
|
|
20276
20457
|
fromUiAmount,
|
|
20277
20458
|
getAccounts,
|
|
20278
20459
|
getBalance,
|
|
@@ -20288,11 +20469,15 @@ var ExternalLiquidityIntegrityService = class {
|
|
|
20288
20469
|
loadKeypair,
|
|
20289
20470
|
makeProvider,
|
|
20290
20471
|
mintTokensTo,
|
|
20472
|
+
prepareVaultTransaction,
|
|
20291
20473
|
resolveKeypairPath,
|
|
20474
|
+
resolveSquadsWalletRoute,
|
|
20292
20475
|
roundToNextUtcMidnight,
|
|
20293
20476
|
runLiveConsensusOracle,
|
|
20294
20477
|
systemClock,
|
|
20295
20478
|
toUiAmount,
|
|
20296
20479
|
updateAccount,
|
|
20297
|
-
updateDynamicApr
|
|
20480
|
+
updateDynamicApr,
|
|
20481
|
+
validateSquadsWalletRoutes,
|
|
20482
|
+
vaultAuthorityForWallet
|
|
20298
20483
|
});
|