@0dotxyz/p0-ts-sdk 2.7.4 → 2.8.0-alpha.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/index.cjs +619 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +101 -8
- package/dist/index.d.ts +101 -8
- package/dist/index.js +612 -40
- package/dist/index.js.map +1 -1
- package/dist/instructions.d.cts +1 -1
- package/dist/instructions.d.ts +1 -1
- package/dist/{types-DJqANTTA.d.cts → types-CqP5W-Bu.d.cts} +252 -9
- package/dist/{types-sisv3J7l.d.ts → types-DEoJ8ewV.d.ts} +252 -9
- package/dist/types-cfCsUNXw.d.cts +230 -0
- package/dist/types-cfCsUNXw.d.ts +230 -0
- package/dist/vendor.cjs +100 -9
- package/dist/vendor.cjs.map +1 -1
- package/dist/vendor.d.cts +6880 -6981
- package/dist/vendor.d.ts +6880 -6981
- package/dist/vendor.js +81 -3
- package/dist/vendor.js.map +1 -1
- package/package.json +1 -1
- package/dist/types-DLZaKA17.d.cts +0 -88
- package/dist/types-DLZaKA17.d.ts +0 -88
package/dist/index.cjs
CHANGED
|
@@ -14354,13 +14354,13 @@ var marginfi_0_1_10_default = {
|
|
|
14354
14354
|
type: "u16"
|
|
14355
14355
|
},
|
|
14356
14356
|
{
|
|
14357
|
-
name: "
|
|
14358
|
-
|
|
14359
|
-
|
|
14360
|
-
|
|
14361
|
-
|
|
14362
|
-
|
|
14363
|
-
|
|
14357
|
+
name: "scope_entry_index",
|
|
14358
|
+
docs: [
|
|
14359
|
+
"Entry index into the Scope OraclePrices price list. Only read when",
|
|
14360
|
+
"oracle_setup == OracleSetup::Scope; ignored (and zero) for every other setup.",
|
|
14361
|
+
"Occupies what was previously _padding0, so the layout is unchanged."
|
|
14362
|
+
],
|
|
14363
|
+
type: "u16"
|
|
14364
14364
|
},
|
|
14365
14365
|
{
|
|
14366
14366
|
name: "oracle_max_confidence",
|
|
@@ -19311,6 +19311,144 @@ var marginfi_0_1_10_default = {
|
|
|
19311
19311
|
},
|
|
19312
19312
|
{
|
|
19313
19313
|
name: "FixedJuplend"
|
|
19314
|
+
},
|
|
19315
|
+
{
|
|
19316
|
+
name: "Scope"
|
|
19317
|
+
},
|
|
19318
|
+
{
|
|
19319
|
+
name: "PythMSOL"
|
|
19320
|
+
},
|
|
19321
|
+
{
|
|
19322
|
+
name: "KaminoMSOL"
|
|
19323
|
+
},
|
|
19324
|
+
{
|
|
19325
|
+
name: "JuplendMSOL"
|
|
19326
|
+
},
|
|
19327
|
+
{
|
|
19328
|
+
name: "PythLST"
|
|
19329
|
+
},
|
|
19330
|
+
{
|
|
19331
|
+
name: "KaminoLST"
|
|
19332
|
+
},
|
|
19333
|
+
{
|
|
19334
|
+
name: "JuplendLST"
|
|
19335
|
+
},
|
|
19336
|
+
{
|
|
19337
|
+
name: "PTPyth"
|
|
19338
|
+
},
|
|
19339
|
+
{
|
|
19340
|
+
name: "PTFixed"
|
|
19341
|
+
},
|
|
19342
|
+
{
|
|
19343
|
+
name: "Reserved27"
|
|
19344
|
+
},
|
|
19345
|
+
{
|
|
19346
|
+
name: "Reserved28"
|
|
19347
|
+
},
|
|
19348
|
+
{
|
|
19349
|
+
name: "Reserved29"
|
|
19350
|
+
},
|
|
19351
|
+
{
|
|
19352
|
+
name: "Reserved30"
|
|
19353
|
+
},
|
|
19354
|
+
{
|
|
19355
|
+
name: "Reserved31"
|
|
19356
|
+
},
|
|
19357
|
+
{
|
|
19358
|
+
name: "Reserved32"
|
|
19359
|
+
},
|
|
19360
|
+
{
|
|
19361
|
+
name: "Reserved33"
|
|
19362
|
+
},
|
|
19363
|
+
{
|
|
19364
|
+
name: "Reserved34"
|
|
19365
|
+
},
|
|
19366
|
+
{
|
|
19367
|
+
name: "Reserved35"
|
|
19368
|
+
},
|
|
19369
|
+
{
|
|
19370
|
+
name: "Reserved36"
|
|
19371
|
+
},
|
|
19372
|
+
{
|
|
19373
|
+
name: "Reserved37"
|
|
19374
|
+
},
|
|
19375
|
+
{
|
|
19376
|
+
name: "Reserved38"
|
|
19377
|
+
},
|
|
19378
|
+
{
|
|
19379
|
+
name: "Reserved39"
|
|
19380
|
+
},
|
|
19381
|
+
{
|
|
19382
|
+
name: "Reserved40"
|
|
19383
|
+
},
|
|
19384
|
+
{
|
|
19385
|
+
name: "Reserved41"
|
|
19386
|
+
},
|
|
19387
|
+
{
|
|
19388
|
+
name: "Reserved42"
|
|
19389
|
+
},
|
|
19390
|
+
{
|
|
19391
|
+
name: "Reserved43"
|
|
19392
|
+
},
|
|
19393
|
+
{
|
|
19394
|
+
name: "Reserved44"
|
|
19395
|
+
},
|
|
19396
|
+
{
|
|
19397
|
+
name: "Reserved45"
|
|
19398
|
+
},
|
|
19399
|
+
{
|
|
19400
|
+
name: "Reserved46"
|
|
19401
|
+
},
|
|
19402
|
+
{
|
|
19403
|
+
name: "Reserved47"
|
|
19404
|
+
},
|
|
19405
|
+
{
|
|
19406
|
+
name: "Reserved48"
|
|
19407
|
+
},
|
|
19408
|
+
{
|
|
19409
|
+
name: "Reserved49"
|
|
19410
|
+
},
|
|
19411
|
+
{
|
|
19412
|
+
name: "Reserved50"
|
|
19413
|
+
},
|
|
19414
|
+
{
|
|
19415
|
+
name: "Reserved51"
|
|
19416
|
+
},
|
|
19417
|
+
{
|
|
19418
|
+
name: "Reserved52"
|
|
19419
|
+
},
|
|
19420
|
+
{
|
|
19421
|
+
name: "Reserved53"
|
|
19422
|
+
},
|
|
19423
|
+
{
|
|
19424
|
+
name: "Reserved54"
|
|
19425
|
+
},
|
|
19426
|
+
{
|
|
19427
|
+
name: "Reserved55"
|
|
19428
|
+
},
|
|
19429
|
+
{
|
|
19430
|
+
name: "Reserved56"
|
|
19431
|
+
},
|
|
19432
|
+
{
|
|
19433
|
+
name: "Reserved57"
|
|
19434
|
+
},
|
|
19435
|
+
{
|
|
19436
|
+
name: "Reserved58"
|
|
19437
|
+
},
|
|
19438
|
+
{
|
|
19439
|
+
name: "Reserved59"
|
|
19440
|
+
},
|
|
19441
|
+
{
|
|
19442
|
+
name: "Reserved60"
|
|
19443
|
+
},
|
|
19444
|
+
{
|
|
19445
|
+
name: "Reserved61"
|
|
19446
|
+
},
|
|
19447
|
+
{
|
|
19448
|
+
name: "Reserved62"
|
|
19449
|
+
},
|
|
19450
|
+
{
|
|
19451
|
+
name: "Reserved63"
|
|
19314
19452
|
}
|
|
19315
19453
|
]
|
|
19316
19454
|
}
|
|
@@ -20731,6 +20869,16 @@ var OracleSetup = /* @__PURE__ */ ((OracleSetup3) => {
|
|
|
20731
20869
|
OracleSetup3["JuplendPythPull"] = "JuplendPythPull";
|
|
20732
20870
|
OracleSetup3["JuplendSwitchboardPull"] = "JuplendSwitchboardPull";
|
|
20733
20871
|
OracleSetup3["FixedJuplend"] = "FixedJuplend";
|
|
20872
|
+
OracleSetup3["Scope"] = "Scope";
|
|
20873
|
+
OracleSetup3["PythMSOL"] = "PythMSOL";
|
|
20874
|
+
OracleSetup3["KaminoMSOL"] = "KaminoMSOL";
|
|
20875
|
+
OracleSetup3["JuplendMSOL"] = "JuplendMSOL";
|
|
20876
|
+
OracleSetup3["PythLST"] = "PythLST";
|
|
20877
|
+
OracleSetup3["KaminoLST"] = "KaminoLST";
|
|
20878
|
+
OracleSetup3["JuplendLST"] = "JuplendLST";
|
|
20879
|
+
OracleSetup3["PTPyth"] = "PTPyth";
|
|
20880
|
+
OracleSetup3["PTFixed"] = "PTFixed";
|
|
20881
|
+
OracleSetup3["Unknown"] = "Unknown";
|
|
20734
20882
|
return OracleSetup3;
|
|
20735
20883
|
})(OracleSetup || {});
|
|
20736
20884
|
var AssetTag = /* @__PURE__ */ ((AssetTag3) => {
|
|
@@ -21792,8 +21940,26 @@ function serializeOracleSetupToIndex(oracleSetup) {
|
|
|
21792
21940
|
return 16;
|
|
21793
21941
|
case "FixedJuplend" /* FixedJuplend */:
|
|
21794
21942
|
return 17;
|
|
21943
|
+
case "Scope" /* Scope */:
|
|
21944
|
+
return 18;
|
|
21945
|
+
case "PythMSOL" /* PythMSOL */:
|
|
21946
|
+
return 19;
|
|
21947
|
+
case "KaminoMSOL" /* KaminoMSOL */:
|
|
21948
|
+
return 20;
|
|
21949
|
+
case "JuplendMSOL" /* JuplendMSOL */:
|
|
21950
|
+
return 21;
|
|
21951
|
+
case "PythLST" /* PythLST */:
|
|
21952
|
+
return 22;
|
|
21953
|
+
case "KaminoLST" /* KaminoLST */:
|
|
21954
|
+
return 23;
|
|
21955
|
+
case "JuplendLST" /* JuplendLST */:
|
|
21956
|
+
return 24;
|
|
21957
|
+
case "PTPyth" /* PTPyth */:
|
|
21958
|
+
return 25;
|
|
21959
|
+
case "PTFixed" /* PTFixed */:
|
|
21960
|
+
return 26;
|
|
21795
21961
|
default:
|
|
21796
|
-
|
|
21962
|
+
throw new Error(`Cannot serialize oracle setup "${oracleSetup}"`);
|
|
21797
21963
|
}
|
|
21798
21964
|
}
|
|
21799
21965
|
function serializeOracleSetup(oracleSetup) {
|
|
@@ -21834,6 +22000,24 @@ function serializeOracleSetup(oracleSetup) {
|
|
|
21834
22000
|
return { juplendSwitchboardPull: {} };
|
|
21835
22001
|
case "FixedJuplend" /* FixedJuplend */:
|
|
21836
22002
|
return { fixedJuplend: {} };
|
|
22003
|
+
case "Scope" /* Scope */:
|
|
22004
|
+
return { scope: {} };
|
|
22005
|
+
case "PythMSOL" /* PythMSOL */:
|
|
22006
|
+
return { pythMsol: {} };
|
|
22007
|
+
case "KaminoMSOL" /* KaminoMSOL */:
|
|
22008
|
+
return { kaminoMsol: {} };
|
|
22009
|
+
case "JuplendMSOL" /* JuplendMSOL */:
|
|
22010
|
+
return { juplendMsol: {} };
|
|
22011
|
+
case "PythLST" /* PythLST */:
|
|
22012
|
+
return { pythLst: {} };
|
|
22013
|
+
case "KaminoLST" /* KaminoLST */:
|
|
22014
|
+
return { kaminoLst: {} };
|
|
22015
|
+
case "JuplendLST" /* JuplendLST */:
|
|
22016
|
+
return { juplendLst: {} };
|
|
22017
|
+
case "PTPyth" /* PTPyth */:
|
|
22018
|
+
return { ptPyth: {} };
|
|
22019
|
+
case "PTFixed" /* PTFixed */:
|
|
22020
|
+
return { ptFixed: {} };
|
|
21837
22021
|
default:
|
|
21838
22022
|
throw new Error(`Invalid oracle setup "${oracleSetup}"`);
|
|
21839
22023
|
}
|
|
@@ -21947,7 +22131,8 @@ function toBankConfigDto(bankConfig) {
|
|
|
21947
22131
|
interestRateConfig: toInterestRateConfigDto(bankConfig.interestRateConfig),
|
|
21948
22132
|
configFlags: bankConfig.configFlags,
|
|
21949
22133
|
oracleMaxConfidence: bankConfig.oracleMaxConfidence,
|
|
21950
|
-
fixedPrice: bankConfig.fixedPrice.toString()
|
|
22134
|
+
fixedPrice: bankConfig.fixedPrice.toString(),
|
|
22135
|
+
scopeEntryIndex: bankConfig.scopeEntryIndex
|
|
21951
22136
|
};
|
|
21952
22137
|
}
|
|
21953
22138
|
function toInterestRateConfigDto(interestRateConfig) {
|
|
@@ -22053,7 +22238,8 @@ function bankConfigToBankConfigRaw(config) {
|
|
|
22053
22238
|
totalAssetValueInitLimit: new BN9__default.default(config.totalAssetValueInitLimit.toString()),
|
|
22054
22239
|
oracleMaxAge: config.oracleMaxAge,
|
|
22055
22240
|
oracleMaxConfidence: config.oracleMaxConfidence,
|
|
22056
|
-
fixedPrice: bigNumberToWrappedI80F48(config.fixedPrice)
|
|
22241
|
+
fixedPrice: bigNumberToWrappedI80F48(config.fixedPrice),
|
|
22242
|
+
scopeEntryIndex: config.scopeEntryIndex
|
|
22057
22243
|
};
|
|
22058
22244
|
}
|
|
22059
22245
|
function bankConfigRawToDto(bankConfigRaw) {
|
|
@@ -22074,7 +22260,8 @@ function bankConfigRawToDto(bankConfigRaw) {
|
|
|
22074
22260
|
interestRateConfig: bankConfigRaw.interestRateConfig,
|
|
22075
22261
|
configFlags: bankConfigRaw.configFlags,
|
|
22076
22262
|
oracleMaxConfidence: bankConfigRaw.oracleMaxConfidence,
|
|
22077
|
-
fixedPrice: bankConfigRaw.fixedPrice
|
|
22263
|
+
fixedPrice: bankConfigRaw.fixedPrice,
|
|
22264
|
+
scopeEntryIndex: bankConfigRaw.scopeEntryIndex
|
|
22078
22265
|
};
|
|
22079
22266
|
}
|
|
22080
22267
|
|
|
@@ -22362,7 +22549,8 @@ function dtoToBankConfig(bankConfigDto) {
|
|
|
22362
22549
|
oracleMaxAge: bankConfigDto.oracleMaxAge,
|
|
22363
22550
|
interestRateConfig: dtoToInterestRateConfig(bankConfigDto.interestRateConfig),
|
|
22364
22551
|
oracleMaxConfidence: bankConfigDto.oracleMaxConfidence,
|
|
22365
|
-
fixedPrice: new BigNumber3__default.default(bankConfigDto.fixedPrice)
|
|
22552
|
+
fixedPrice: new BigNumber3__default.default(bankConfigDto.fixedPrice),
|
|
22553
|
+
scopeEntryIndex: bankConfigDto.scopeEntryIndex ?? 0
|
|
22366
22554
|
};
|
|
22367
22555
|
}
|
|
22368
22556
|
function dtoToInterestRateConfig(interestRateConfigDto) {
|
|
@@ -22475,7 +22663,8 @@ function dtoToBankConfigRaw(bankConfigDto) {
|
|
|
22475
22663
|
oracleMaxAge: bankConfigDto.oracleMaxAge,
|
|
22476
22664
|
interestRateConfig: bankConfigDto.interestRateConfig,
|
|
22477
22665
|
oracleMaxConfidence: bankConfigDto.oracleMaxConfidence,
|
|
22478
|
-
fixedPrice: bankConfigDto.fixedPrice
|
|
22666
|
+
fixedPrice: bankConfigDto.fixedPrice,
|
|
22667
|
+
scopeEntryIndex: bankConfigDto.scopeEntryIndex ?? 0
|
|
22479
22668
|
};
|
|
22480
22669
|
}
|
|
22481
22670
|
function parseBankConfigRaw(bankConfigRaw) {
|
|
@@ -22515,6 +22704,7 @@ function parseBankConfigRaw(bankConfigRaw) {
|
|
|
22515
22704
|
};
|
|
22516
22705
|
const oracleMaxConfidence = bankConfigRaw.oracleMaxConfidence;
|
|
22517
22706
|
const fixedPrice = wrappedI80F48toBigNumber(bankConfigRaw.fixedPrice);
|
|
22707
|
+
const scopeEntryIndex = bankConfigRaw.scopeEntryIndex ?? 0;
|
|
22518
22708
|
return {
|
|
22519
22709
|
assetWeightInit,
|
|
22520
22710
|
assetWeightMaint,
|
|
@@ -22532,7 +22722,8 @@ function parseBankConfigRaw(bankConfigRaw) {
|
|
|
22532
22722
|
oracleMaxAge,
|
|
22533
22723
|
interestRateConfig,
|
|
22534
22724
|
oracleMaxConfidence,
|
|
22535
|
-
fixedPrice
|
|
22725
|
+
fixedPrice,
|
|
22726
|
+
scopeEntryIndex
|
|
22536
22727
|
};
|
|
22537
22728
|
}
|
|
22538
22729
|
function parseRiskTier(riskTierRaw) {
|
|
@@ -22594,18 +22785,36 @@ function parseOracleSetup(oracleSetupRaw) {
|
|
|
22594
22785
|
return "SolendPythPull" /* SolendPythPull */;
|
|
22595
22786
|
case "solendswitchboardpull":
|
|
22596
22787
|
return "SolendSwitchboardPull" /* SolendSwitchboardPull */;
|
|
22597
|
-
case "
|
|
22788
|
+
case "fixedkamino":
|
|
22598
22789
|
return "FixedKamino" /* FixedKamino */;
|
|
22599
|
-
case "
|
|
22790
|
+
case "fixeddrift":
|
|
22600
22791
|
return "FixedDrift" /* FixedDrift */;
|
|
22601
22792
|
case "juplendpythpull":
|
|
22602
22793
|
return "JuplendPythPull" /* JuplendPythPull */;
|
|
22603
22794
|
case "juplendswitchboardpull":
|
|
22604
22795
|
return "JuplendSwitchboardPull" /* JuplendSwitchboardPull */;
|
|
22605
|
-
case "
|
|
22796
|
+
case "fixedjuplend":
|
|
22606
22797
|
return "FixedJuplend" /* FixedJuplend */;
|
|
22798
|
+
case "scope":
|
|
22799
|
+
return "Scope" /* Scope */;
|
|
22800
|
+
case "pythmsol":
|
|
22801
|
+
return "PythMSOL" /* PythMSOL */;
|
|
22802
|
+
case "kaminomsol":
|
|
22803
|
+
return "KaminoMSOL" /* KaminoMSOL */;
|
|
22804
|
+
case "juplendmsol":
|
|
22805
|
+
return "JuplendMSOL" /* JuplendMSOL */;
|
|
22806
|
+
case "pythlst":
|
|
22807
|
+
return "PythLST" /* PythLST */;
|
|
22808
|
+
case "kaminolst":
|
|
22809
|
+
return "KaminoLST" /* KaminoLST */;
|
|
22810
|
+
case "juplendlst":
|
|
22811
|
+
return "JuplendLST" /* JuplendLST */;
|
|
22812
|
+
case "ptpyth":
|
|
22813
|
+
return "PTPyth" /* PTPyth */;
|
|
22814
|
+
case "ptfixed":
|
|
22815
|
+
return "PTFixed" /* PTFixed */;
|
|
22607
22816
|
default:
|
|
22608
|
-
return "
|
|
22817
|
+
return "Unknown" /* Unknown */;
|
|
22609
22818
|
}
|
|
22610
22819
|
}
|
|
22611
22820
|
function getActiveEmodeFlags(flags) {
|
|
@@ -25736,6 +25945,17 @@ var categorizePythBanks = (banks) => {
|
|
|
25736
25945
|
const juplendPythPullBanks = banks.filter(
|
|
25737
25946
|
(bank) => bank.config.oracleSetup === "JuplendPythPull" /* JuplendPythPull */
|
|
25738
25947
|
);
|
|
25948
|
+
const pythMultipliedBanks = banks.filter(
|
|
25949
|
+
(bank) => [
|
|
25950
|
+
"PythMSOL" /* PythMSOL */,
|
|
25951
|
+
"KaminoMSOL" /* KaminoMSOL */,
|
|
25952
|
+
"JuplendMSOL" /* JuplendMSOL */,
|
|
25953
|
+
"PythLST" /* PythLST */,
|
|
25954
|
+
"KaminoLST" /* KaminoLST */,
|
|
25955
|
+
"JuplendLST" /* JuplendLST */,
|
|
25956
|
+
"PTPyth" /* PTPyth */
|
|
25957
|
+
].includes(bank.config.oracleSetup)
|
|
25958
|
+
);
|
|
25739
25959
|
return {
|
|
25740
25960
|
pythLegacyBanks,
|
|
25741
25961
|
pythPushBanks,
|
|
@@ -25743,7 +25963,8 @@ var categorizePythBanks = (banks) => {
|
|
|
25743
25963
|
pythPushKaminosBanks,
|
|
25744
25964
|
driftPythPullBanks,
|
|
25745
25965
|
solendPythPullBanks,
|
|
25746
|
-
juplendPythPullBanks
|
|
25966
|
+
juplendPythPullBanks,
|
|
25967
|
+
pythMultipliedBanks
|
|
25747
25968
|
};
|
|
25748
25969
|
};
|
|
25749
25970
|
var convertVoteAccCoeffsToBankCoeffs = (pythStakedCollateralBanks, validatorVoteAccountByBank, voteAccCoeffs) => {
|
|
@@ -25760,7 +25981,7 @@ var extractPythOracleKeys = (pythBanks) => {
|
|
|
25760
25981
|
const keys = pythBanks.map((bank) => bank.config.oracleKeys[0].toBase58());
|
|
25761
25982
|
return [...keys];
|
|
25762
25983
|
};
|
|
25763
|
-
var mapPythBanksToOraclePrices = (pythPushBanks,
|
|
25984
|
+
var mapPythBanksToOraclePrices = (pythPushBanks, multipliedBanks, oraclePrices, priceCoeffByBank) => {
|
|
25764
25985
|
const bankOraclePriceMap = /* @__PURE__ */ new Map();
|
|
25765
25986
|
pythPushBanks.forEach((bank) => {
|
|
25766
25987
|
const oracleKey = bank.config.oracleKeys[0].toBase58();
|
|
@@ -25769,7 +25990,7 @@ var mapPythBanksToOraclePrices = (pythPushBanks, pythStakedCollateralBanks, orac
|
|
|
25769
25990
|
bankOraclePriceMap.set(bank.address.toBase58(), oraclePrice);
|
|
25770
25991
|
}
|
|
25771
25992
|
});
|
|
25772
|
-
|
|
25993
|
+
multipliedBanks.forEach((bank) => {
|
|
25773
25994
|
const priceCoeff = priceCoeffByBank[bank.address.toBase58()];
|
|
25774
25995
|
const oracleKey = bank.config.oracleKeys[0]?.toBase58();
|
|
25775
25996
|
if (oracleKey && priceCoeff !== void 0) {
|
|
@@ -25787,7 +26008,7 @@ var mapPythBanksToOraclePrices = (pythPushBanks, pythStakedCollateralBanks, orac
|
|
|
25787
26008
|
};
|
|
25788
26009
|
var adjustPriceComponent = (priceComponent, priceCoeff) => ({
|
|
25789
26010
|
price: priceComponent.price.multipliedBy(priceCoeff),
|
|
25790
|
-
confidence: priceComponent.confidence,
|
|
26011
|
+
confidence: priceComponent.confidence.multipliedBy(priceCoeff),
|
|
25791
26012
|
lowestPrice: priceComponent.lowestPrice.multipliedBy(priceCoeff),
|
|
25792
26013
|
highestPrice: priceComponent.highestPrice.multipliedBy(priceCoeff)
|
|
25793
26014
|
});
|
|
@@ -25839,6 +26060,7 @@ var ORACLE_SOURCES = {
|
|
|
25839
26060
|
switchboard: "Switchboard",
|
|
25840
26061
|
pyth: "Pyth",
|
|
25841
26062
|
fixed: "Fixed",
|
|
26063
|
+
scope: "Scope",
|
|
25842
26064
|
unknown: "Unknown"
|
|
25843
26065
|
};
|
|
25844
26066
|
function getOracleSourceNameFromKey(oracleSourceKey) {
|
|
@@ -25865,14 +26087,25 @@ function getOracleSourceFromOracleSetup(oracleSetup) {
|
|
|
25865
26087
|
case "DriftPythPull" /* DriftPythPull */:
|
|
25866
26088
|
case "SolendPythPull" /* SolendPythPull */:
|
|
25867
26089
|
case "JuplendPythPull" /* JuplendPythPull */:
|
|
26090
|
+
case "PythMSOL" /* PythMSOL */:
|
|
26091
|
+
case "KaminoMSOL" /* KaminoMSOL */:
|
|
26092
|
+
case "JuplendMSOL" /* JuplendMSOL */:
|
|
26093
|
+
case "PythLST" /* PythLST */:
|
|
26094
|
+
case "KaminoLST" /* KaminoLST */:
|
|
26095
|
+
case "JuplendLST" /* JuplendLST */:
|
|
26096
|
+
case "PTPyth" /* PTPyth */:
|
|
25868
26097
|
oracleSourceKey = "pyth";
|
|
25869
26098
|
break;
|
|
25870
26099
|
case "Fixed" /* Fixed */:
|
|
25871
26100
|
case "FixedKamino" /* FixedKamino */:
|
|
25872
26101
|
case "FixedDrift" /* FixedDrift */:
|
|
25873
26102
|
case "FixedJuplend" /* FixedJuplend */:
|
|
26103
|
+
case "PTFixed" /* PTFixed */:
|
|
25874
26104
|
oracleSourceKey = "fixed";
|
|
25875
26105
|
break;
|
|
26106
|
+
case "Scope" /* Scope */:
|
|
26107
|
+
oracleSourceKey = "scope";
|
|
26108
|
+
break;
|
|
25876
26109
|
default:
|
|
25877
26110
|
oracleSourceKey = "unknown";
|
|
25878
26111
|
break;
|
|
@@ -27347,6 +27580,19 @@ function computeBankRiskAccountKeys(bank) {
|
|
|
27347
27580
|
if (bank.config.assetTag === 3 /* KAMINO */ || bank.config.assetTag === 4 /* DRIFT */ || bank.config.assetTag === 5 /* SOLEND */ || bank.config.assetTag === 6 /* JUPLEND */) {
|
|
27348
27581
|
keys.push(bank.config.oracleKeys[1]);
|
|
27349
27582
|
}
|
|
27583
|
+
switch (bank.config.oracleSetup) {
|
|
27584
|
+
case "PythMSOL" /* PythMSOL */:
|
|
27585
|
+
case "PythLST" /* PythLST */:
|
|
27586
|
+
case "PTPyth" /* PTPyth */:
|
|
27587
|
+
keys.push(bank.config.oracleKeys[1]);
|
|
27588
|
+
break;
|
|
27589
|
+
case "KaminoMSOL" /* KaminoMSOL */:
|
|
27590
|
+
case "JuplendMSOL" /* JuplendMSOL */:
|
|
27591
|
+
case "KaminoLST" /* KaminoLST */:
|
|
27592
|
+
case "JuplendLST" /* JuplendLST */:
|
|
27593
|
+
keys.push(bank.config.oracleKeys[2]);
|
|
27594
|
+
break;
|
|
27595
|
+
}
|
|
27350
27596
|
if (bank.config.assetTag === 2 /* STAKED */) {
|
|
27351
27597
|
keys.push(bank.config.oracleKeys[1], bank.config.oracleKeys[2]);
|
|
27352
27598
|
const onrampKey = bank.config.oracleKeys[3];
|
|
@@ -72101,7 +72347,9 @@ function decodeExponentVault(data) {
|
|
|
72101
72347
|
finalSyExchangeRate: exponentNumberToBigNumber(
|
|
72102
72348
|
get("final_sy_exchange_rate", "finalSyExchangeRate")
|
|
72103
72349
|
),
|
|
72104
|
-
status: Number(get("status", "status") ?? 0)
|
|
72350
|
+
status: Number(get("status", "status") ?? 0),
|
|
72351
|
+
startTs: Number(get("start_ts", "startTs") ?? 0),
|
|
72352
|
+
duration: Number(get("duration", "duration") ?? 0)
|
|
72105
72353
|
};
|
|
72106
72354
|
}
|
|
72107
72355
|
function decodeExponentMarketVault(data) {
|
|
@@ -74970,6 +75218,82 @@ function makeRefreshIntegrationBanksIxs(marginfiAccount, bankMap, banksToExclude
|
|
|
74970
75218
|
keys: [...kaminoRefreshIxs.keys, ...updateDriftMarketIxs.keys, ...updateJupLendRateIxs.keys]
|
|
74971
75219
|
};
|
|
74972
75220
|
}
|
|
75221
|
+
new web3_js.PublicKey("HFn8GnPADiny6XqUoWE8uRPPxb29ikn4yTuPa9MF2fWJ");
|
|
75222
|
+
var SCOPE_ORACLE_PRICES_DISCRIMINATOR = Buffer.from([89, 128, 118, 221, 6, 72, 180, 146]);
|
|
75223
|
+
var SCOPE_MAX_ENTRIES = 512;
|
|
75224
|
+
var ENTRIES_OFFSET = 40;
|
|
75225
|
+
var DATED_PRICE_SIZE = 56;
|
|
75226
|
+
var SCOPE_ORACLE_PRICES_SIZE = ENTRIES_OFFSET + SCOPE_MAX_ENTRIES * DATED_PRICE_SIZE;
|
|
75227
|
+
function decodeScopePriceAtIndex(data, entryIndex) {
|
|
75228
|
+
if (data.length !== SCOPE_ORACLE_PRICES_SIZE) {
|
|
75229
|
+
throw new Error(`Invalid Scope OraclePrices account size: ${data.length}`);
|
|
75230
|
+
}
|
|
75231
|
+
if (!data.subarray(0, 8).equals(SCOPE_ORACLE_PRICES_DISCRIMINATOR)) {
|
|
75232
|
+
throw new Error("Invalid Scope OraclePrices discriminator");
|
|
75233
|
+
}
|
|
75234
|
+
if (entryIndex < 0 || entryIndex >= SCOPE_MAX_ENTRIES) {
|
|
75235
|
+
throw new Error(`Scope entry index out of range: ${entryIndex}`);
|
|
75236
|
+
}
|
|
75237
|
+
const offset = ENTRIES_OFFSET + entryIndex * DATED_PRICE_SIZE;
|
|
75238
|
+
const value = data.readBigUInt64LE(offset);
|
|
75239
|
+
const exp = data.readBigUInt64LE(offset + 8);
|
|
75240
|
+
const lastUpdatedSlot = data.readBigUInt64LE(offset + 16);
|
|
75241
|
+
const unixTimestamp = data.readBigUInt64LE(offset + 24);
|
|
75242
|
+
const price = new BigNumber3__default.default(value.toString()).shiftedBy(-Number(exp));
|
|
75243
|
+
return {
|
|
75244
|
+
price,
|
|
75245
|
+
lastUpdatedSlot: Number(lastUpdatedSlot),
|
|
75246
|
+
unixTimestamp: Number(unixTimestamp)
|
|
75247
|
+
};
|
|
75248
|
+
}
|
|
75249
|
+
new web3_js.PublicKey("MarBmsSgKXdrN1egZf5sqe1TMai9K1rChYNDJgjq7aD");
|
|
75250
|
+
var MARINADE_STATE_SIZE = 520;
|
|
75251
|
+
var MSOL_PRICE_OFFSET = 512;
|
|
75252
|
+
var MSOL_PRICE_PRECISION = new BigNumber3__default.default(2).pow(32);
|
|
75253
|
+
function decodeMarinadeState(data) {
|
|
75254
|
+
if (data.length !== MARINADE_STATE_SIZE) {
|
|
75255
|
+
throw new Error(`Invalid Marinade State account size: ${data.length}`);
|
|
75256
|
+
}
|
|
75257
|
+
const msolPriceRaw = data.readBigUInt64LE(MSOL_PRICE_OFFSET);
|
|
75258
|
+
return {
|
|
75259
|
+
msolPrice: new BigNumber3__default.default(msolPriceRaw.toString()).div(MSOL_PRICE_PRECISION)
|
|
75260
|
+
};
|
|
75261
|
+
}
|
|
75262
|
+
new web3_js.PublicKey(
|
|
75263
|
+
"SPoo1Ku8WFXoNDMHPsrGSTSG1Y47rzgn41SLUNakuHy"
|
|
75264
|
+
);
|
|
75265
|
+
new web3_js.PublicKey(
|
|
75266
|
+
"SP12tWFxD9oJsVWNavTTBZvMbA6gkAmxtVgxdqvyvhY"
|
|
75267
|
+
);
|
|
75268
|
+
new web3_js.PublicKey(
|
|
75269
|
+
"SPMBzsVUuoHA4Jm6KunbsotaahvVikZs1JyTW6iJvbn"
|
|
75270
|
+
);
|
|
75271
|
+
var ACCOUNT_TYPE_STAKE_POOL = 1;
|
|
75272
|
+
var TOTAL_LAMPORTS_OFFSET = 258;
|
|
75273
|
+
var POOL_TOKEN_SUPPLY_OFFSET = 266;
|
|
75274
|
+
var LAST_UPDATE_EPOCH_OFFSET = 274;
|
|
75275
|
+
function decodeStakePool(data) {
|
|
75276
|
+
if (data.length < LAST_UPDATE_EPOCH_OFFSET + 8) {
|
|
75277
|
+
throw new Error(`Invalid StakePool account size: ${data.length}`);
|
|
75278
|
+
}
|
|
75279
|
+
if (data[0] !== ACCOUNT_TYPE_STAKE_POOL) {
|
|
75280
|
+
throw new Error(`Invalid StakePool account type: ${data[0]}`);
|
|
75281
|
+
}
|
|
75282
|
+
const totalLamports = data.readBigUInt64LE(TOTAL_LAMPORTS_OFFSET);
|
|
75283
|
+
const poolTokenSupply = data.readBigUInt64LE(POOL_TOKEN_SUPPLY_OFFSET);
|
|
75284
|
+
const lastUpdateEpoch = Number(data.readBigUInt64LE(LAST_UPDATE_EPOCH_OFFSET));
|
|
75285
|
+
if (poolTokenSupply === 0n) {
|
|
75286
|
+
throw new Error("StakePool has zero token supply");
|
|
75287
|
+
}
|
|
75288
|
+
return {
|
|
75289
|
+
totalLamports,
|
|
75290
|
+
poolTokenSupply,
|
|
75291
|
+
lastUpdateEpoch,
|
|
75292
|
+
exchangeRate: new BigNumber3__default.default(totalLamports.toString()).div(
|
|
75293
|
+
new BigNumber3__default.default(poolTokenSupply.toString())
|
|
75294
|
+
)
|
|
75295
|
+
};
|
|
75296
|
+
}
|
|
74973
75297
|
var GAMMA_VAULT_PROGRAM_ID = new web3_js.PublicKey(
|
|
74974
75298
|
"GaMmanX9i4jGmqDZZD2tbD6B2v9p21btenPneMXnTczV"
|
|
74975
75299
|
);
|
|
@@ -80577,16 +80901,17 @@ function chunkArray(array4, chunkSize) {
|
|
|
80577
80901
|
}
|
|
80578
80902
|
|
|
80579
80903
|
// src/services/price/services/pyth-oracle.service.ts
|
|
80580
|
-
var fetchPythOracleData = async (banks, opts) => {
|
|
80904
|
+
var fetchPythOracleData = async (banks, opts, priceCoeffByBank = {}) => {
|
|
80581
80905
|
const {
|
|
80582
80906
|
pythPushBanks,
|
|
80583
80907
|
pythStakedCollateralBanks,
|
|
80584
80908
|
pythPushKaminosBanks,
|
|
80585
80909
|
driftPythPullBanks,
|
|
80586
80910
|
solendPythPullBanks,
|
|
80587
|
-
juplendPythPullBanks
|
|
80911
|
+
juplendPythPullBanks,
|
|
80912
|
+
pythMultipliedBanks
|
|
80588
80913
|
} = categorizePythBanks(banks);
|
|
80589
|
-
if (!pythPushBanks.length && !pythStakedCollateralBanks.length && !pythPushKaminosBanks.length && !driftPythPullBanks.length && !solendPythPullBanks.length && !juplendPythPullBanks.length) {
|
|
80914
|
+
if (!pythPushBanks.length && !pythStakedCollateralBanks.length && !pythPushKaminosBanks.length && !driftPythPullBanks.length && !solendPythPullBanks.length && !juplendPythPullBanks.length && !pythMultipliedBanks.length) {
|
|
80590
80915
|
return {
|
|
80591
80916
|
bankOraclePriceMap: /* @__PURE__ */ new Map()
|
|
80592
80917
|
};
|
|
@@ -80597,9 +80922,9 @@ var fetchPythOracleData = async (banks, opts) => {
|
|
|
80597
80922
|
...pythPushKaminosBanks,
|
|
80598
80923
|
...driftPythPullBanks,
|
|
80599
80924
|
...solendPythPullBanks,
|
|
80600
|
-
...juplendPythPullBanks
|
|
80925
|
+
...juplendPythPullBanks,
|
|
80926
|
+
...pythMultipliedBanks
|
|
80601
80927
|
];
|
|
80602
|
-
const priceCoeffByBank = {};
|
|
80603
80928
|
const pythOracleKeys = extractPythOracleKeys(combinedPythBanks);
|
|
80604
80929
|
const uniquePythOracleKeys = Array.from(new Set(pythOracleKeys));
|
|
80605
80930
|
let oraclePrices;
|
|
@@ -80614,10 +80939,15 @@ var fetchPythOracleData = async (banks, opts) => {
|
|
|
80614
80939
|
}
|
|
80615
80940
|
const bankOraclePriceMap = mapPythBanksToOraclePrices(
|
|
80616
80941
|
combinedPythBanks,
|
|
80617
|
-
pythStakedCollateralBanks,
|
|
80942
|
+
[...pythStakedCollateralBanks, ...pythMultipliedBanks],
|
|
80618
80943
|
oraclePrices,
|
|
80619
80944
|
priceCoeffByBank
|
|
80620
80945
|
);
|
|
80946
|
+
pythMultipliedBanks.forEach((bank) => {
|
|
80947
|
+
if (priceCoeffByBank[bank.address.toBase58()] === void 0) {
|
|
80948
|
+
bankOraclePriceMap.delete(bank.address.toBase58());
|
|
80949
|
+
}
|
|
80950
|
+
});
|
|
80621
80951
|
return {
|
|
80622
80952
|
bankOraclePriceMap
|
|
80623
80953
|
};
|
|
@@ -80889,16 +81219,242 @@ async function fetchSingleCrossbarChunk(endpoint, swbFeedIdsChunk, isPrimary) {
|
|
|
80889
81219
|
throw error;
|
|
80890
81220
|
}
|
|
80891
81221
|
}
|
|
81222
|
+
var scopeRequestKey = (bank) => `${bank.config.oracleKeys[0].toBase58()}:${bank.config.scopeEntryIndex}`;
|
|
81223
|
+
var fetchScopeOracleData = async (banks, opts) => {
|
|
81224
|
+
const scopeBanks = banks.filter((bank) => getOracleSourceFromBank(bank).key === "scope");
|
|
81225
|
+
if (!scopeBanks.length) {
|
|
81226
|
+
return {
|
|
81227
|
+
bankOraclePriceMap: /* @__PURE__ */ new Map()
|
|
81228
|
+
};
|
|
81229
|
+
}
|
|
81230
|
+
const uniqueRequestKeys = Array.from(new Set(scopeBanks.map(scopeRequestKey)));
|
|
81231
|
+
let oraclePrices;
|
|
81232
|
+
if (opts.mode === "api") {
|
|
81233
|
+
oraclePrices = await fetchScopeOraclePricesFromAPI(
|
|
81234
|
+
uniqueRequestKeys,
|
|
81235
|
+
opts.scopeOnchainData.endpoint,
|
|
81236
|
+
{ queryKey: opts.scopeOnchainData.queryKey }
|
|
81237
|
+
);
|
|
81238
|
+
} else {
|
|
81239
|
+
oraclePrices = await fetchScopeOraclePricesFromChain(uniqueRequestKeys, opts.connection);
|
|
81240
|
+
}
|
|
81241
|
+
const bankOraclePriceMap = /* @__PURE__ */ new Map();
|
|
81242
|
+
const nowSeconds = Math.floor(Date.now() / 1e3);
|
|
81243
|
+
scopeBanks.forEach((bank) => {
|
|
81244
|
+
let oraclePrice = oraclePrices[scopeRequestKey(bank)];
|
|
81245
|
+
const isStale = !oraclePrice || nowSeconds - oraclePrice.timestamp.toNumber() > bank.config.oracleMaxAge;
|
|
81246
|
+
if (isStale) {
|
|
81247
|
+
oraclePrice = {
|
|
81248
|
+
priceRealtime: {
|
|
81249
|
+
price: new BigNumber3__default.default(0),
|
|
81250
|
+
confidence: new BigNumber3__default.default(0),
|
|
81251
|
+
lowestPrice: new BigNumber3__default.default(0),
|
|
81252
|
+
highestPrice: new BigNumber3__default.default(0)
|
|
81253
|
+
},
|
|
81254
|
+
priceWeighted: {
|
|
81255
|
+
price: new BigNumber3__default.default(0),
|
|
81256
|
+
confidence: new BigNumber3__default.default(0),
|
|
81257
|
+
lowestPrice: new BigNumber3__default.default(0),
|
|
81258
|
+
highestPrice: new BigNumber3__default.default(0)
|
|
81259
|
+
},
|
|
81260
|
+
timestamp: oraclePrice?.timestamp ?? new BigNumber3__default.default(0)
|
|
81261
|
+
};
|
|
81262
|
+
}
|
|
81263
|
+
bankOraclePriceMap.set(bank.address.toBase58(), oraclePrice);
|
|
81264
|
+
});
|
|
81265
|
+
return {
|
|
81266
|
+
bankOraclePriceMap
|
|
81267
|
+
};
|
|
81268
|
+
};
|
|
81269
|
+
var fetchScopeOraclePricesFromAPI = async (requestKeys, apiEndpoint, opts) => {
|
|
81270
|
+
const queryKey = opts?.queryKey ?? "scopeKeys";
|
|
81271
|
+
const response = await fetch(`${apiEndpoint}?${queryKey}=${requestKeys.join(",")}`);
|
|
81272
|
+
if (!response.ok) {
|
|
81273
|
+
throw new Error("Failed to fetch scope oracle data");
|
|
81274
|
+
}
|
|
81275
|
+
const { data } = await response.json();
|
|
81276
|
+
return Object.fromEntries(
|
|
81277
|
+
Object.entries(data).map(([key, oraclePrice]) => [
|
|
81278
|
+
key,
|
|
81279
|
+
{
|
|
81280
|
+
priceRealtime: {
|
|
81281
|
+
price: BigNumber3__default.default(oraclePrice.priceRealtime.price),
|
|
81282
|
+
confidence: BigNumber3__default.default(oraclePrice.priceRealtime.confidence),
|
|
81283
|
+
lowestPrice: BigNumber3__default.default(oraclePrice.priceRealtime.lowestPrice),
|
|
81284
|
+
highestPrice: BigNumber3__default.default(oraclePrice.priceRealtime.highestPrice)
|
|
81285
|
+
},
|
|
81286
|
+
priceWeighted: {
|
|
81287
|
+
price: BigNumber3__default.default(oraclePrice.priceWeighted.price),
|
|
81288
|
+
confidence: BigNumber3__default.default(oraclePrice.priceWeighted.confidence),
|
|
81289
|
+
lowestPrice: BigNumber3__default.default(oraclePrice.priceWeighted.lowestPrice),
|
|
81290
|
+
highestPrice: BigNumber3__default.default(oraclePrice.priceWeighted.highestPrice)
|
|
81291
|
+
},
|
|
81292
|
+
timestamp: BigNumber3__default.default(oraclePrice.timestamp)
|
|
81293
|
+
}
|
|
81294
|
+
])
|
|
81295
|
+
);
|
|
81296
|
+
};
|
|
81297
|
+
var fetchScopeOraclePricesFromChain = async (requestKeys, connection) => {
|
|
81298
|
+
const uniqueOracleKeys = Array.from(new Set(requestKeys.map((key) => key.split(":")[0])));
|
|
81299
|
+
const oracleAis = await chunkedGetRawMultipleAccountInfoOrdered(connection, uniqueOracleKeys);
|
|
81300
|
+
const accountDataByKey = {};
|
|
81301
|
+
uniqueOracleKeys.forEach((oracleKey, index) => {
|
|
81302
|
+
accountDataByKey[oracleKey] = oracleAis[index]?.data;
|
|
81303
|
+
});
|
|
81304
|
+
const oraclePriceByRequestKey = {};
|
|
81305
|
+
for (const requestKey of requestKeys) {
|
|
81306
|
+
const [oracleKey, entryIndexRaw] = requestKey.split(":");
|
|
81307
|
+
const data = accountDataByKey[oracleKey];
|
|
81308
|
+
let price = new BigNumber3__default.default(0);
|
|
81309
|
+
let timestamp = new BigNumber3__default.default(0);
|
|
81310
|
+
if (data) {
|
|
81311
|
+
try {
|
|
81312
|
+
const entry = decodeScopePriceAtIndex(data, Number(entryIndexRaw));
|
|
81313
|
+
price = entry.price;
|
|
81314
|
+
timestamp = new BigNumber3__default.default(entry.unixTimestamp);
|
|
81315
|
+
} catch (e) {
|
|
81316
|
+
console.error(`Failed to decode scope entry ${requestKey}`, e);
|
|
81317
|
+
}
|
|
81318
|
+
}
|
|
81319
|
+
oraclePriceByRequestKey[requestKey] = {
|
|
81320
|
+
priceRealtime: {
|
|
81321
|
+
price,
|
|
81322
|
+
confidence: new BigNumber3__default.default(0),
|
|
81323
|
+
lowestPrice: price,
|
|
81324
|
+
highestPrice: price
|
|
81325
|
+
},
|
|
81326
|
+
priceWeighted: {
|
|
81327
|
+
price,
|
|
81328
|
+
confidence: new BigNumber3__default.default(0),
|
|
81329
|
+
lowestPrice: price,
|
|
81330
|
+
highestPrice: price
|
|
81331
|
+
},
|
|
81332
|
+
timestamp
|
|
81333
|
+
};
|
|
81334
|
+
}
|
|
81335
|
+
return oraclePriceByRequestKey;
|
|
81336
|
+
};
|
|
81337
|
+
function multiplierAccountKey(bank) {
|
|
81338
|
+
switch (bank.config.oracleSetup) {
|
|
81339
|
+
case "PythMSOL" /* PythMSOL */:
|
|
81340
|
+
case "PythLST" /* PythLST */:
|
|
81341
|
+
case "PTPyth" /* PTPyth */:
|
|
81342
|
+
return bank.config.oracleKeys[1];
|
|
81343
|
+
case "KaminoMSOL" /* KaminoMSOL */:
|
|
81344
|
+
case "JuplendMSOL" /* JuplendMSOL */:
|
|
81345
|
+
case "KaminoLST" /* KaminoLST */:
|
|
81346
|
+
case "JuplendLST" /* JuplendLST */:
|
|
81347
|
+
return bank.config.oracleKeys[2];
|
|
81348
|
+
case "PTFixed" /* PTFixed */:
|
|
81349
|
+
return bank.config.oracleKeys[0];
|
|
81350
|
+
default:
|
|
81351
|
+
return void 0;
|
|
81352
|
+
}
|
|
81353
|
+
}
|
|
81354
|
+
function computePtMultiplier(vault, startPrice, nowSeconds) {
|
|
81355
|
+
const maturity = vault.startTs + vault.duration;
|
|
81356
|
+
let expectedRate;
|
|
81357
|
+
if (vault.duration <= 0 || nowSeconds <= vault.startTs) {
|
|
81358
|
+
expectedRate = startPrice;
|
|
81359
|
+
} else if (nowSeconds >= maturity) {
|
|
81360
|
+
expectedRate = new BigNumber3__default.default(1);
|
|
81361
|
+
} else {
|
|
81362
|
+
const progress = new BigNumber3__default.default(nowSeconds - vault.startTs).div(vault.duration);
|
|
81363
|
+
expectedRate = startPrice.plus(new BigNumber3__default.default(1).minus(startPrice).times(progress));
|
|
81364
|
+
}
|
|
81365
|
+
if (vault.ptSupply === 0n) {
|
|
81366
|
+
throw new Error("Exponent vault has zero PT supply");
|
|
81367
|
+
}
|
|
81368
|
+
const syPerPt = new BigNumber3__default.default(vault.syForPt.toString()).div(
|
|
81369
|
+
new BigNumber3__default.default(vault.ptSupply.toString())
|
|
81370
|
+
);
|
|
81371
|
+
const redemptionCap = syPerPt.times(vault.lastSeenSyExchangeRate);
|
|
81372
|
+
return BigNumber3__default.default.min(expectedRate, redemptionCap);
|
|
81373
|
+
}
|
|
81374
|
+
var fetchOracleMultipliers = async (banks, opts) => {
|
|
81375
|
+
const multipliedBanks = banks.filter((bank) => multiplierAccountKey(bank) !== void 0);
|
|
81376
|
+
if (!multipliedBanks.length) {
|
|
81377
|
+
return {};
|
|
81378
|
+
}
|
|
81379
|
+
if (opts.mode === "api") {
|
|
81380
|
+
return fetchOracleMultipliersFromAPI(
|
|
81381
|
+
multipliedBanks.map((bank) => bank.address.toBase58()),
|
|
81382
|
+
opts.multiplierData.endpoint,
|
|
81383
|
+
{ queryKey: opts.multiplierData.queryKey }
|
|
81384
|
+
);
|
|
81385
|
+
}
|
|
81386
|
+
return fetchOracleMultipliersFromChain(multipliedBanks, opts.connection);
|
|
81387
|
+
};
|
|
81388
|
+
var fetchOracleMultipliersFromAPI = async (bankAddresses, apiEndpoint, opts) => {
|
|
81389
|
+
const queryKey = opts?.queryKey ?? "bankAddresses";
|
|
81390
|
+
const response = await fetch(`${apiEndpoint}?${queryKey}=${bankAddresses.join(",")}`);
|
|
81391
|
+
if (!response.ok) {
|
|
81392
|
+
throw new Error("Failed to fetch price multiplier data");
|
|
81393
|
+
}
|
|
81394
|
+
const { data } = await response.json();
|
|
81395
|
+
return Object.fromEntries(
|
|
81396
|
+
Object.entries(data).map(([bankAddress, multiplier]) => [bankAddress, Number(multiplier)])
|
|
81397
|
+
);
|
|
81398
|
+
};
|
|
81399
|
+
var fetchOracleMultipliersFromChain = async (multipliedBanks, connection) => {
|
|
81400
|
+
const accountKeyByBank = new Map(
|
|
81401
|
+
multipliedBanks.map((bank) => [bank.address.toBase58(), multiplierAccountKey(bank).toBase58()])
|
|
81402
|
+
);
|
|
81403
|
+
const uniqueAccountKeys = Array.from(new Set(accountKeyByBank.values()));
|
|
81404
|
+
const accountAis = await chunkedGetRawMultipleAccountInfoOrdered(connection, uniqueAccountKeys);
|
|
81405
|
+
const accountDataByKey = {};
|
|
81406
|
+
uniqueAccountKeys.forEach((accountKey, index) => {
|
|
81407
|
+
accountDataByKey[accountKey] = accountAis[index]?.data;
|
|
81408
|
+
});
|
|
81409
|
+
const multiplierByBank = {};
|
|
81410
|
+
const nowSeconds = Math.floor(Date.now() / 1e3);
|
|
81411
|
+
for (const bank of multipliedBanks) {
|
|
81412
|
+
const bankAddress = bank.address.toBase58();
|
|
81413
|
+
const data = accountDataByKey[accountKeyByBank.get(bankAddress)];
|
|
81414
|
+
if (!data) {
|
|
81415
|
+
console.error(`Missing multiplier account for bank ${bankAddress}`);
|
|
81416
|
+
continue;
|
|
81417
|
+
}
|
|
81418
|
+
try {
|
|
81419
|
+
switch (bank.config.oracleSetup) {
|
|
81420
|
+
case "PythMSOL" /* PythMSOL */:
|
|
81421
|
+
case "KaminoMSOL" /* KaminoMSOL */:
|
|
81422
|
+
case "JuplendMSOL" /* JuplendMSOL */:
|
|
81423
|
+
multiplierByBank[bankAddress] = decodeMarinadeState(data).msolPrice.toNumber();
|
|
81424
|
+
break;
|
|
81425
|
+
case "PythLST" /* PythLST */:
|
|
81426
|
+
case "KaminoLST" /* KaminoLST */:
|
|
81427
|
+
case "JuplendLST" /* JuplendLST */:
|
|
81428
|
+
multiplierByBank[bankAddress] = decodeStakePool(data).exchangeRate.toNumber();
|
|
81429
|
+
break;
|
|
81430
|
+
case "PTPyth" /* PTPyth */:
|
|
81431
|
+
case "PTFixed" /* PTFixed */:
|
|
81432
|
+
multiplierByBank[bankAddress] = computePtMultiplier(
|
|
81433
|
+
decodeExponentVault(data),
|
|
81434
|
+
bank.config.fixedPrice,
|
|
81435
|
+
nowSeconds
|
|
81436
|
+
).toNumber();
|
|
81437
|
+
break;
|
|
81438
|
+
}
|
|
81439
|
+
} catch (e) {
|
|
81440
|
+
console.error(`Failed to compute multiplier for bank ${bankAddress}`, e);
|
|
81441
|
+
}
|
|
81442
|
+
}
|
|
81443
|
+
return multiplierByBank;
|
|
81444
|
+
};
|
|
80892
81445
|
var fetchOracleData = async (banks, opts) => {
|
|
80893
81446
|
const { zeroOracleBanks, isolatedAssetBanks, collateralAssetBanks, fixedAssetBanks } = classifyBanksForOracleStrategy(banks);
|
|
80894
81447
|
const zeroResults = handleZeroOracleBanks(zeroOracleBanks);
|
|
80895
81448
|
const fetchIsolatedPrice = opts?.isolatedBanksOpts?.fetchPrices ?? false;
|
|
80896
81449
|
const isolatedResults = fetchIsolatedPrice ? handleIsolatedAssetBanks(isolatedAssetBanks, opts?.isolatedBanksOpts?.staticPricesByBank) : /* @__PURE__ */ new Map();
|
|
80897
|
-
const
|
|
81450
|
+
const multiplierByBank = await fetchOracleMultipliers(banks, opts.oracleMultiplierOpts);
|
|
81451
|
+
const fixedResults = handleFixedOracleBanks(fixedAssetBanks, multiplierByBank);
|
|
80898
81452
|
const assetBanks = [...collateralAssetBanks, ...fetchIsolatedPrice ? isolatedAssetBanks : []];
|
|
80899
81453
|
const assetResults = await handleAssetBanks(assetBanks, {
|
|
80900
81454
|
pythOpts: opts.pythOpts,
|
|
80901
|
-
swbOpts: opts.swbOpts
|
|
81455
|
+
swbOpts: opts.swbOpts,
|
|
81456
|
+
scopeOpts: opts.scopeOpts,
|
|
81457
|
+
priceCoeffByBank: multiplierByBank
|
|
80902
81458
|
});
|
|
80903
81459
|
return mergeOracleResults([zeroResults, isolatedResults, assetResults, fixedResults], banks);
|
|
80904
81460
|
};
|
|
@@ -80932,10 +81488,11 @@ function classifyBanksForOracleStrategy(banks) {
|
|
|
80932
81488
|
fixedAssetBanks
|
|
80933
81489
|
};
|
|
80934
81490
|
}
|
|
80935
|
-
function handleFixedOracleBanks(banks) {
|
|
81491
|
+
function handleFixedOracleBanks(banks, multiplierByBank) {
|
|
80936
81492
|
const oracleMap = /* @__PURE__ */ new Map();
|
|
80937
81493
|
banks.forEach((bank) => {
|
|
80938
|
-
const
|
|
81494
|
+
const multiplier = multiplierByBank[bank.address.toBase58()];
|
|
81495
|
+
const fixedPrice = bank.config.oracleSetup === "PTFixed" /* PTFixed */ && multiplier !== void 0 ? BigNumber3__default.default(multiplier) : bank.config.fixedPrice;
|
|
80939
81496
|
const fixedOraclePrice = {
|
|
80940
81497
|
priceRealtime: {
|
|
80941
81498
|
price: fixedPrice,
|
|
@@ -81004,9 +81561,10 @@ async function handleAssetBanks(banks, opts) {
|
|
|
81004
81561
|
if (banks.length === 0) {
|
|
81005
81562
|
return /* @__PURE__ */ new Map();
|
|
81006
81563
|
}
|
|
81007
|
-
const [pythData, swbData] = await Promise.all([
|
|
81008
|
-
fetchPythOracleData(banks, opts.pythOpts),
|
|
81009
|
-
fetchSwbOracleData(banks, opts.swbOpts)
|
|
81564
|
+
const [pythData, swbData, scopeData] = await Promise.all([
|
|
81565
|
+
fetchPythOracleData(banks, opts.pythOpts, opts.priceCoeffByBank),
|
|
81566
|
+
fetchSwbOracleData(banks, opts.swbOpts),
|
|
81567
|
+
fetchScopeOracleData(banks, opts.scopeOpts)
|
|
81010
81568
|
]);
|
|
81011
81569
|
const bankOraclePriceMap = /* @__PURE__ */ new Map();
|
|
81012
81570
|
pythData.bankOraclePriceMap.forEach((oraclePrice, bankAddress) => {
|
|
@@ -81015,6 +81573,9 @@ async function handleAssetBanks(banks, opts) {
|
|
|
81015
81573
|
swbData.bankOraclePriceMap.forEach((oraclePrice, bankAddress) => {
|
|
81016
81574
|
bankOraclePriceMap.set(bankAddress, oraclePrice);
|
|
81017
81575
|
});
|
|
81576
|
+
scopeData.bankOraclePriceMap.forEach((oraclePrice, bankAddress) => {
|
|
81577
|
+
bankOraclePriceMap.set(bankAddress, oraclePrice);
|
|
81578
|
+
});
|
|
81018
81579
|
banks.forEach((bank) => {
|
|
81019
81580
|
const bankAddress = bank.address.toBase58();
|
|
81020
81581
|
const oraclePrice = bankOraclePriceMap.get(bankAddress);
|
|
@@ -83397,7 +83958,8 @@ var Bank = class _Bank {
|
|
|
83397
83958
|
bankType.config.operationalState,
|
|
83398
83959
|
bankType.config.oracleMaxConfidence,
|
|
83399
83960
|
bankType.config.fixedPrice,
|
|
83400
|
-
bankType.config.configFlags
|
|
83961
|
+
bankType.config.configFlags,
|
|
83962
|
+
bankType.config.scopeEntryIndex
|
|
83401
83963
|
);
|
|
83402
83964
|
return new _Bank(
|
|
83403
83965
|
bankType.address,
|
|
@@ -83566,7 +84128,7 @@ var Bank = class _Bank {
|
|
|
83566
84128
|
}
|
|
83567
84129
|
};
|
|
83568
84130
|
var BankConfig = class _BankConfig {
|
|
83569
|
-
constructor(assetWeightInit, assetWeightMaint, liabilityWeightInit, liabilityWeightMaint, depositLimit, borrowLimit, riskTier, totalAssetValueInitLimit, assetTag, oracleSetup, oracleKeys, oracleMaxAge, interestRateConfig, operationalState, oracleMaxConfidence, fixedPrice, configFlags) {
|
|
84131
|
+
constructor(assetWeightInit, assetWeightMaint, liabilityWeightInit, liabilityWeightMaint, depositLimit, borrowLimit, riskTier, totalAssetValueInitLimit, assetTag, oracleSetup, oracleKeys, oracleMaxAge, interestRateConfig, operationalState, oracleMaxConfidence, fixedPrice, configFlags, scopeEntryIndex = 0) {
|
|
83570
84132
|
this.assetWeightInit = assetWeightInit;
|
|
83571
84133
|
this.assetWeightMaint = assetWeightMaint;
|
|
83572
84134
|
this.liabilityWeightInit = liabilityWeightInit;
|
|
@@ -83584,6 +84146,7 @@ var BankConfig = class _BankConfig {
|
|
|
83584
84146
|
this.oracleMaxConfidence = oracleMaxConfidence;
|
|
83585
84147
|
this.fixedPrice = fixedPrice;
|
|
83586
84148
|
this.configFlags = configFlags;
|
|
84149
|
+
this.scopeEntryIndex = scopeEntryIndex;
|
|
83587
84150
|
}
|
|
83588
84151
|
static fromAccountParsed(bankConfigRaw) {
|
|
83589
84152
|
const bankConfig = parseBankConfigRaw(bankConfigRaw);
|
|
@@ -83604,7 +84167,8 @@ var BankConfig = class _BankConfig {
|
|
|
83604
84167
|
bankConfig.operationalState,
|
|
83605
84168
|
bankConfig.oracleMaxConfidence,
|
|
83606
84169
|
bankConfig.fixedPrice,
|
|
83607
|
-
bankConfig.configFlags
|
|
84170
|
+
bankConfig.configFlags,
|
|
84171
|
+
bankConfig.scopeEntryIndex
|
|
83608
84172
|
);
|
|
83609
84173
|
}
|
|
83610
84174
|
};
|
|
@@ -84783,6 +85347,14 @@ var Project0Client = class _Project0Client {
|
|
|
84783
85347
|
mode: "on-chain",
|
|
84784
85348
|
connection
|
|
84785
85349
|
},
|
|
85350
|
+
scopeOpts: {
|
|
85351
|
+
mode: "on-chain",
|
|
85352
|
+
connection
|
|
85353
|
+
},
|
|
85354
|
+
oracleMultiplierOpts: {
|
|
85355
|
+
mode: "on-chain",
|
|
85356
|
+
connection
|
|
85357
|
+
},
|
|
84786
85358
|
isolatedBanksOpts: {
|
|
84787
85359
|
fetchPrices: true
|
|
84788
85360
|
}
|
|
@@ -85054,6 +85626,7 @@ exports.computeBankMetrics = computeBankMetrics;
|
|
|
85054
85626
|
exports.computeBankPoolSize = computeBankPoolSize;
|
|
85055
85627
|
exports.computeBankProjectedAvailableLiquidity = computeBankProjectedAvailableLiquidity;
|
|
85056
85628
|
exports.computeBankRateLimitRemaining = computeBankRateLimitRemaining;
|
|
85629
|
+
exports.computeBankRiskAccountKeys = computeBankRiskAccountKeys;
|
|
85057
85630
|
exports.computeBankSupplyApy = computeBankSupplyApy;
|
|
85058
85631
|
exports.computeBankTotalBorrows = computeBankTotalBorrows;
|
|
85059
85632
|
exports.computeBankTotalBorrowsUsd = computeBankTotalBorrowsUsd;
|
|
@@ -85087,6 +85660,7 @@ exports.computeMaxWithdrawForBank = computeMaxWithdrawForBank;
|
|
|
85087
85660
|
exports.computeNetApy = computeNetApy;
|
|
85088
85661
|
exports.computeProjectedActiveBalancesNoCpi = computeProjectedActiveBalancesNoCpi;
|
|
85089
85662
|
exports.computeProjectedActiveBanksNoCpi = computeProjectedActiveBanksNoCpi;
|
|
85663
|
+
exports.computePtMultiplier = computePtMultiplier;
|
|
85090
85664
|
exports.computeQuantity = computeQuantity;
|
|
85091
85665
|
exports.computeQuantityUi = computeQuantityUi;
|
|
85092
85666
|
exports.computeRateLimitWindowRemainingCapacity = computeRateLimitWindowRemainingCapacity;
|
|
@@ -85151,10 +85725,16 @@ exports.fetchMarginfiAccountData = fetchMarginfiAccountData;
|
|
|
85151
85725
|
exports.fetchMultipleBanks = fetchMultipleBanks;
|
|
85152
85726
|
exports.fetchNativeStakeAccounts = fetchNativeStakeAccounts;
|
|
85153
85727
|
exports.fetchOracleData = fetchOracleData;
|
|
85728
|
+
exports.fetchOracleMultipliers = fetchOracleMultipliers;
|
|
85729
|
+
exports.fetchOracleMultipliersFromAPI = fetchOracleMultipliersFromAPI;
|
|
85730
|
+
exports.fetchOracleMultipliersFromChain = fetchOracleMultipliersFromChain;
|
|
85154
85731
|
exports.fetchProgramForMints = fetchProgramForMints;
|
|
85155
85732
|
exports.fetchPythOracleData = fetchPythOracleData;
|
|
85156
85733
|
exports.fetchPythOraclePricesFromAPI = fetchPythOraclePricesFromAPI;
|
|
85157
85734
|
exports.fetchPythOraclePricesFromChain = fetchPythOraclePricesFromChain;
|
|
85735
|
+
exports.fetchScopeOracleData = fetchScopeOracleData;
|
|
85736
|
+
exports.fetchScopeOraclePricesFromAPI = fetchScopeOraclePricesFromAPI;
|
|
85737
|
+
exports.fetchScopeOraclePricesFromChain = fetchScopeOraclePricesFromChain;
|
|
85158
85738
|
exports.fetchStakeAccount = fetchStakeAccount;
|
|
85159
85739
|
exports.fetchStakePoolActiveStates = fetchStakePoolActiveStates;
|
|
85160
85740
|
exports.fetchStakePoolMev = fetchStakePoolMev;
|