@0dotxyz/p0-ts-sdk 2.0.0-alpha.4 → 2.0.1
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 +294 -259
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +293 -258
- package/dist/index.js.map +1 -1
- package/dist/vendor.cjs +27 -27
- package/dist/vendor.cjs.map +1 -1
- package/dist/vendor.d.cts +20 -20
- package/dist/vendor.d.ts +20 -20
- package/dist/vendor.js +32 -32
- package/dist/vendor.js.map +1 -1
- package/package.json +25 -22
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PublicKey, SolanaJSONRPCError, ComputeBudgetProgram, SystemProgram, TransactionMessage, VersionedTransaction, Transaction, AddressLookupTableAccount, SYSVAR_RENT_PUBKEY, StakeProgram, TransactionInstruction, LAMPORTS_PER_SOL, SYSVAR_INSTRUCTIONS_PUBKEY } from '@solana/web3.js';
|
|
2
2
|
import { object, string, enums, array, assert } from 'superstruct';
|
|
3
|
-
import
|
|
3
|
+
import BigNumber3, { BigNumber } from 'bignumber.js';
|
|
4
4
|
import BN11 from 'bn.js';
|
|
5
5
|
import Decimal3, { Decimal } from 'decimal.js';
|
|
6
6
|
import { BorshCoder, BorshAccountsCoder, BorshInstructionCoder, AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
@@ -242,9 +242,9 @@ var PYTH_SPONSORED_SHARD_ID = 0;
|
|
|
242
242
|
var MARGINFI_SPONSORED_SHARD_ID = 3301;
|
|
243
243
|
var DEFAULT_ORACLE_MAX_AGE = 60;
|
|
244
244
|
var ZERO_ORACLE_KEY = "DMhGWtLAKE5d56WdyHQxqeFncwUeqMEnuC2RvvZfbuur";
|
|
245
|
-
var PYTH_PRICE_CONF_INTERVALS = new
|
|
246
|
-
var SWB_PRICE_CONF_INTERVALS = new
|
|
247
|
-
var MAX_CONFIDENCE_INTERVAL_RATIO = new
|
|
245
|
+
var PYTH_PRICE_CONF_INTERVALS = new BigNumber3(2.12);
|
|
246
|
+
var SWB_PRICE_CONF_INTERVALS = new BigNumber3(1.96);
|
|
247
|
+
var MAX_CONFIDENCE_INTERVAL_RATIO = new BigNumber3(0.05);
|
|
248
248
|
var DISABLED_FLAG = 1 << 0;
|
|
249
249
|
var FLASHLOAN_ENABLED_FLAG = 1 << 2;
|
|
250
250
|
var TRANSFER_ACCOUNT_AUTHORITY_FLAG = 1 << 3;
|
|
@@ -337,7 +337,7 @@ function wrappedI80F48toBigNumber(wrapped) {
|
|
|
337
337
|
}
|
|
338
338
|
let hex = signChar + "0x" + bytesBE.map((v) => v.toString(16).padStart(2, "0")).join("");
|
|
339
339
|
let decoded = new Decimal(hex).dividedBy(I80F48_DIVISOR);
|
|
340
|
-
return new
|
|
340
|
+
return new BigNumber3(decoded.toString());
|
|
341
341
|
}
|
|
342
342
|
function bigNumberToWrappedI80F48(value) {
|
|
343
343
|
let decimalValue = new Decimal(value.toString());
|
|
@@ -368,16 +368,16 @@ function toNumber(amount) {
|
|
|
368
368
|
}
|
|
369
369
|
function toBigNumber(amount) {
|
|
370
370
|
let amt;
|
|
371
|
-
if (amount instanceof
|
|
371
|
+
if (amount instanceof BigNumber3) {
|
|
372
372
|
amt = amount;
|
|
373
373
|
} else {
|
|
374
|
-
amt = new
|
|
374
|
+
amt = new BigNumber3(amount.toString());
|
|
375
375
|
}
|
|
376
376
|
return amt;
|
|
377
377
|
}
|
|
378
378
|
function uiToNative(amount, decimals) {
|
|
379
379
|
let amt = toBigNumber(amount);
|
|
380
|
-
return new BN11(amt.times(10 ** decimals).toFixed(0,
|
|
380
|
+
return new BN11(amt.times(10 ** decimals).toFixed(0, BigNumber3.ROUND_FLOOR));
|
|
381
381
|
}
|
|
382
382
|
function uiToNativeBigNumber(amount, decimals) {
|
|
383
383
|
let amt = toBigNumber(amount);
|
|
@@ -13760,13 +13760,13 @@ function parseBankRaw(address, accountParsed, bankMetadata, mintData) {
|
|
|
13760
13760
|
const emissionsActiveLending = (flags & 2) > 0;
|
|
13761
13761
|
const emissionsRate = accountParsed.emissionsRate.toNumber();
|
|
13762
13762
|
const emissionsMint = accountParsed.emissionsMint;
|
|
13763
|
-
const emissionsRemaining = accountParsed.emissionsRemaining ? wrappedI80F48toBigNumber(accountParsed.emissionsRemaining) : new
|
|
13763
|
+
const emissionsRemaining = accountParsed.emissionsRemaining ? wrappedI80F48toBigNumber(accountParsed.emissionsRemaining) : new BigNumber3(0);
|
|
13764
13764
|
const { oracleKey } = { oracleKey: config.oracleKeys[0] };
|
|
13765
13765
|
const emode = parseEmodeSettingsRaw(accountParsed.emode);
|
|
13766
13766
|
const tokenSymbol = bankMetadata?.tokenSymbol;
|
|
13767
13767
|
const feesDestinationAccount = accountParsed.feesDestinationAccount;
|
|
13768
|
-
const lendingPositionCount = accountParsed.lendingPositionCount ? new
|
|
13769
|
-
const borrowingPositionCount = accountParsed.borrowingPositionCount ? new
|
|
13768
|
+
const lendingPositionCount = accountParsed.lendingPositionCount ? new BigNumber3(accountParsed.lendingPositionCount.toString()) : new BigNumber3(0);
|
|
13769
|
+
const borrowingPositionCount = accountParsed.borrowingPositionCount ? new BigNumber3(accountParsed.borrowingPositionCount.toString()) : new BigNumber3(0);
|
|
13770
13770
|
let kaminoIntegrationAccounts, driftIntegrationAccounts, solendIntegrationAccounts = void 0;
|
|
13771
13771
|
switch (config.assetTag) {
|
|
13772
13772
|
case 3 /* KAMINO */:
|
|
@@ -13835,34 +13835,34 @@ function dtoToBank(bankDto) {
|
|
|
13835
13835
|
group: new PublicKey(bankDto.group),
|
|
13836
13836
|
mint: new PublicKey(bankDto.mint),
|
|
13837
13837
|
mintDecimals: bankDto.mintDecimals,
|
|
13838
|
-
assetShareValue: new
|
|
13839
|
-
liabilityShareValue: new
|
|
13838
|
+
assetShareValue: new BigNumber3(bankDto.assetShareValue),
|
|
13839
|
+
liabilityShareValue: new BigNumber3(bankDto.liabilityShareValue),
|
|
13840
13840
|
liquidityVault: new PublicKey(bankDto.liquidityVault),
|
|
13841
13841
|
liquidityVaultBump: bankDto.liquidityVaultBump,
|
|
13842
13842
|
liquidityVaultAuthorityBump: bankDto.liquidityVaultAuthorityBump,
|
|
13843
13843
|
insuranceVault: new PublicKey(bankDto.insuranceVault),
|
|
13844
13844
|
insuranceVaultBump: bankDto.insuranceVaultBump,
|
|
13845
13845
|
insuranceVaultAuthorityBump: bankDto.insuranceVaultAuthorityBump,
|
|
13846
|
-
collectedInsuranceFeesOutstanding: new
|
|
13846
|
+
collectedInsuranceFeesOutstanding: new BigNumber3(bankDto.collectedInsuranceFeesOutstanding),
|
|
13847
13847
|
feeVault: new PublicKey(bankDto.feeVault),
|
|
13848
13848
|
feeVaultBump: bankDto.feeVaultBump,
|
|
13849
13849
|
feeVaultAuthorityBump: bankDto.feeVaultAuthorityBump,
|
|
13850
|
-
collectedGroupFeesOutstanding: new
|
|
13850
|
+
collectedGroupFeesOutstanding: new BigNumber3(bankDto.collectedGroupFeesOutstanding),
|
|
13851
13851
|
lastUpdate: bankDto.lastUpdate,
|
|
13852
13852
|
config: dtoToBankConfig(bankDto.config),
|
|
13853
|
-
totalAssetShares: new
|
|
13854
|
-
totalLiabilityShares: new
|
|
13853
|
+
totalAssetShares: new BigNumber3(bankDto.totalAssetShares),
|
|
13854
|
+
totalLiabilityShares: new BigNumber3(bankDto.totalLiabilityShares),
|
|
13855
13855
|
emissionsActiveBorrowing: bankDto.emissionsActiveBorrowing,
|
|
13856
13856
|
emissionsActiveLending: bankDto.emissionsActiveLending,
|
|
13857
13857
|
emissionsRate: bankDto.emissionsRate,
|
|
13858
13858
|
emissionsMint: new PublicKey(bankDto.emissionsMint),
|
|
13859
|
-
emissionsRemaining: new
|
|
13859
|
+
emissionsRemaining: new BigNumber3(bankDto.emissionsRemaining),
|
|
13860
13860
|
oracleKey: new PublicKey(bankDto.oracleKey),
|
|
13861
13861
|
emode: dtoToEmodeSettings(bankDto.emode),
|
|
13862
13862
|
tokenSymbol: bankDto.tokenSymbol,
|
|
13863
13863
|
feesDestinationAccount: bankDto.feesDestinationAccount ? new PublicKey(bankDto.feesDestinationAccount) : void 0,
|
|
13864
|
-
lendingPositionCount: bankDto.lendingPositionCount ? new
|
|
13865
|
-
borrowingPositionCount: bankDto.borrowingPositionCount ? new
|
|
13864
|
+
lendingPositionCount: bankDto.lendingPositionCount ? new BigNumber3(bankDto.lendingPositionCount) : void 0,
|
|
13865
|
+
borrowingPositionCount: bankDto.borrowingPositionCount ? new BigNumber3(bankDto.borrowingPositionCount) : void 0,
|
|
13866
13866
|
mintRate: null,
|
|
13867
13867
|
// TODO: move these out
|
|
13868
13868
|
mintPrice: 0,
|
|
@@ -13890,23 +13890,23 @@ function dtoToEmodeSettings(emodeSettingsDto) {
|
|
|
13890
13890
|
return {
|
|
13891
13891
|
collateralBankEmodeTag: entry.collateralBankEmodeTag,
|
|
13892
13892
|
flags: entry.flags,
|
|
13893
|
-
assetWeightInit: new
|
|
13894
|
-
assetWeightMaint: new
|
|
13893
|
+
assetWeightInit: new BigNumber3(entry.assetWeightInit),
|
|
13894
|
+
assetWeightMaint: new BigNumber3(entry.assetWeightMaint)
|
|
13895
13895
|
};
|
|
13896
13896
|
})
|
|
13897
13897
|
};
|
|
13898
13898
|
}
|
|
13899
13899
|
function dtoToBankConfig(bankConfigDto) {
|
|
13900
13900
|
return {
|
|
13901
|
-
assetWeightInit: new
|
|
13902
|
-
assetWeightMaint: new
|
|
13903
|
-
liabilityWeightInit: new
|
|
13904
|
-
liabilityWeightMaint: new
|
|
13905
|
-
depositLimit: new
|
|
13906
|
-
borrowLimit: new
|
|
13901
|
+
assetWeightInit: new BigNumber3(bankConfigDto.assetWeightInit),
|
|
13902
|
+
assetWeightMaint: new BigNumber3(bankConfigDto.assetWeightMaint),
|
|
13903
|
+
liabilityWeightInit: new BigNumber3(bankConfigDto.liabilityWeightInit),
|
|
13904
|
+
liabilityWeightMaint: new BigNumber3(bankConfigDto.liabilityWeightMaint),
|
|
13905
|
+
depositLimit: new BigNumber3(bankConfigDto.depositLimit),
|
|
13906
|
+
borrowLimit: new BigNumber3(bankConfigDto.borrowLimit),
|
|
13907
13907
|
riskTier: bankConfigDto.riskTier,
|
|
13908
13908
|
operationalState: bankConfigDto.operationalState,
|
|
13909
|
-
totalAssetValueInitLimit: new
|
|
13909
|
+
totalAssetValueInitLimit: new BigNumber3(bankConfigDto.totalAssetValueInitLimit),
|
|
13910
13910
|
assetTag: bankConfigDto.assetTag,
|
|
13911
13911
|
configFlags: bankConfigDto.configFlags,
|
|
13912
13912
|
oracleSetup: bankConfigDto.oracleSetup,
|
|
@@ -13914,19 +13914,19 @@ function dtoToBankConfig(bankConfigDto) {
|
|
|
13914
13914
|
oracleMaxAge: bankConfigDto.oracleMaxAge,
|
|
13915
13915
|
interestRateConfig: dtoToInterestRateConfig(bankConfigDto.interestRateConfig),
|
|
13916
13916
|
oracleMaxConfidence: bankConfigDto.oracleMaxConfidence,
|
|
13917
|
-
fixedPrice: new
|
|
13917
|
+
fixedPrice: new BigNumber3(bankConfigDto.fixedPrice)
|
|
13918
13918
|
};
|
|
13919
13919
|
}
|
|
13920
13920
|
function dtoToInterestRateConfig(interestRateConfigDto) {
|
|
13921
13921
|
return {
|
|
13922
|
-
optimalUtilizationRate: new
|
|
13923
|
-
plateauInterestRate: new
|
|
13924
|
-
maxInterestRate: new
|
|
13925
|
-
insuranceFeeFixedApr: new
|
|
13926
|
-
insuranceIrFee: new
|
|
13927
|
-
protocolFixedFeeApr: new
|
|
13928
|
-
protocolIrFee: new
|
|
13929
|
-
protocolOriginationFee: new
|
|
13922
|
+
optimalUtilizationRate: new BigNumber3(interestRateConfigDto.optimalUtilizationRate),
|
|
13923
|
+
plateauInterestRate: new BigNumber3(interestRateConfigDto.plateauInterestRate),
|
|
13924
|
+
maxInterestRate: new BigNumber3(interestRateConfigDto.maxInterestRate),
|
|
13925
|
+
insuranceFeeFixedApr: new BigNumber3(interestRateConfigDto.insuranceFeeFixedApr),
|
|
13926
|
+
insuranceIrFee: new BigNumber3(interestRateConfigDto.insuranceIrFee),
|
|
13927
|
+
protocolFixedFeeApr: new BigNumber3(interestRateConfigDto.protocolFixedFeeApr),
|
|
13928
|
+
protocolIrFee: new BigNumber3(interestRateConfigDto.protocolIrFee),
|
|
13929
|
+
protocolOriginationFee: new BigNumber3(interestRateConfigDto.protocolOriginationFee),
|
|
13930
13930
|
zeroUtilRate: interestRateConfigDto.zeroUtilRate,
|
|
13931
13931
|
hundredUtilRate: interestRateConfigDto.hundredUtilRate,
|
|
13932
13932
|
points: interestRateConfigDto.points,
|
|
@@ -14011,11 +14011,11 @@ function parseBankConfigRaw(bankConfigRaw) {
|
|
|
14011
14011
|
const assetWeightMaint = wrappedI80F48toBigNumber(bankConfigRaw.assetWeightMaint);
|
|
14012
14012
|
const liabilityWeightInit = wrappedI80F48toBigNumber(bankConfigRaw.liabilityWeightInit);
|
|
14013
14013
|
const liabilityWeightMaint = wrappedI80F48toBigNumber(bankConfigRaw.liabilityWeightMaint);
|
|
14014
|
-
const depositLimit =
|
|
14015
|
-
const borrowLimit =
|
|
14014
|
+
const depositLimit = BigNumber3(bankConfigRaw.depositLimit.toString());
|
|
14015
|
+
const borrowLimit = BigNumber3(bankConfigRaw.borrowLimit.toString());
|
|
14016
14016
|
const riskTier = parseRiskTier(bankConfigRaw.riskTier);
|
|
14017
14017
|
const operationalState = parseOperationalState(bankConfigRaw.operationalState);
|
|
14018
|
-
const totalAssetValueInitLimit =
|
|
14018
|
+
const totalAssetValueInitLimit = BigNumber3(bankConfigRaw.totalAssetValueInitLimit.toString());
|
|
14019
14019
|
const assetTag = bankConfigRaw.assetTag;
|
|
14020
14020
|
const configFlags = bankConfigRaw.configFlags;
|
|
14021
14021
|
const oracleSetup = parseOracleSetup(bankConfigRaw.oracleSetup);
|
|
@@ -14187,13 +14187,13 @@ function getLiabilityQuantity(bank, liabilityShares) {
|
|
|
14187
14187
|
}
|
|
14188
14188
|
function getAssetShares(bank, assetQuantity) {
|
|
14189
14189
|
if (bank.assetShareValue.isZero()) {
|
|
14190
|
-
return new
|
|
14190
|
+
return new BigNumber3(0);
|
|
14191
14191
|
}
|
|
14192
14192
|
return assetQuantity.div(bank.assetShareValue);
|
|
14193
14193
|
}
|
|
14194
14194
|
function getLiabilityShares(bank, liabilityQuantity) {
|
|
14195
14195
|
if (bank.liabilityShareValue.isZero()) {
|
|
14196
|
-
return new
|
|
14196
|
+
return new BigNumber3(0);
|
|
14197
14197
|
}
|
|
14198
14198
|
return liabilityQuantity.div(bank.liabilityShareValue);
|
|
14199
14199
|
}
|
|
@@ -17161,8 +17161,8 @@ var mapBrokenFeedsToOraclePrices = (banks, swbOracleAiDataByKey, birdeyeResponse
|
|
|
17161
17161
|
return bankOraclePriceMap;
|
|
17162
17162
|
};
|
|
17163
17163
|
function parseSwbOraclePriceData(price, stdDev, timestamp, oracleData) {
|
|
17164
|
-
const swbPrice = Array.isArray(price) ? new
|
|
17165
|
-
const swbConfidence = new
|
|
17164
|
+
const swbPrice = Array.isArray(price) ? new BigNumber3(median(price)) : new BigNumber3(price.toString()).div(10 ** SWITCHBOARD_ONDEMANDE_PRICE_PRECISION);
|
|
17165
|
+
const swbConfidence = new BigNumber3(stdDev.toString()).times(SWB_PRICE_CONF_INTERVALS);
|
|
17166
17166
|
const swbConfidenceCapped = capConfidenceInterval(
|
|
17167
17167
|
swbPrice,
|
|
17168
17168
|
swbConfidence,
|
|
@@ -17183,7 +17183,7 @@ function parseSwbOraclePriceData(price, stdDev, timestamp, oracleData) {
|
|
|
17183
17183
|
lowestPrice: swbLowestPrice,
|
|
17184
17184
|
highestPrice: swbHighestPrice
|
|
17185
17185
|
},
|
|
17186
|
-
timestamp: new
|
|
17186
|
+
timestamp: new BigNumber3(timestamp),
|
|
17187
17187
|
switchboardData: oracleData
|
|
17188
17188
|
};
|
|
17189
17189
|
}
|
|
@@ -17298,13 +17298,13 @@ var adjustPriceComponent = (priceComponent, priceCoeff) => ({
|
|
|
17298
17298
|
function parseRpcPythPriceData(rawData) {
|
|
17299
17299
|
function capConfidenceInterval2(price, confidence, maxConfidence) {
|
|
17300
17300
|
const maxConfidenceInterval = price.times(maxConfidence);
|
|
17301
|
-
return
|
|
17301
|
+
return BigNumber3.min(confidence, maxConfidenceInterval);
|
|
17302
17302
|
}
|
|
17303
17303
|
const bytesWithoutDiscriminator = rawData.slice(8);
|
|
17304
17304
|
const data = parsePriceInfo(bytesWithoutDiscriminator);
|
|
17305
|
-
const exponent = new
|
|
17306
|
-
const priceRealTime = new
|
|
17307
|
-
const confidenceRealTime = new
|
|
17305
|
+
const exponent = new BigNumber3(10 ** data.priceMessage.exponent);
|
|
17306
|
+
const priceRealTime = new BigNumber3(Number(data.priceMessage.price)).times(exponent);
|
|
17307
|
+
const confidenceRealTime = new BigNumber3(Number(data.priceMessage.conf)).times(exponent).times(PYTH_PRICE_CONF_INTERVALS);
|
|
17308
17308
|
const cappedConfidenceRealTime = capConfidenceInterval2(
|
|
17309
17309
|
priceRealTime,
|
|
17310
17310
|
confidenceRealTime,
|
|
@@ -17312,8 +17312,8 @@ function parseRpcPythPriceData(rawData) {
|
|
|
17312
17312
|
);
|
|
17313
17313
|
const lowestPriceRealTime = priceRealTime.minus(cappedConfidenceRealTime);
|
|
17314
17314
|
const highestPriceRealTime = priceRealTime.plus(cappedConfidenceRealTime);
|
|
17315
|
-
const priceTimeWeighted = new
|
|
17316
|
-
const confidenceTimeWeighted = new
|
|
17315
|
+
const priceTimeWeighted = new BigNumber3(Number(data.priceMessage.emaPrice)).times(exponent);
|
|
17316
|
+
const confidenceTimeWeighted = new BigNumber3(Number(data.priceMessage.emaConf)).times(exponent).times(PYTH_PRICE_CONF_INTERVALS);
|
|
17317
17317
|
const cappedConfidenceWeighted = capConfidenceInterval2(
|
|
17318
17318
|
priceTimeWeighted,
|
|
17319
17319
|
confidenceTimeWeighted,
|
|
@@ -17334,7 +17334,7 @@ function parseRpcPythPriceData(rawData) {
|
|
|
17334
17334
|
lowestPrice: lowestPriceWeighted,
|
|
17335
17335
|
highestPrice: highestPriceWeighted
|
|
17336
17336
|
},
|
|
17337
|
-
timestamp: new
|
|
17337
|
+
timestamp: new BigNumber3(Number(data.priceMessage.publishTime))
|
|
17338
17338
|
};
|
|
17339
17339
|
}
|
|
17340
17340
|
|
|
@@ -17355,7 +17355,7 @@ function getPrice(oraclePrice, priceBias = 1 /* None */, weightedPrice = false)
|
|
|
17355
17355
|
}
|
|
17356
17356
|
function capConfidenceInterval(price, confidence, maxConfidence) {
|
|
17357
17357
|
let maxConfidenceInterval = price.times(maxConfidence);
|
|
17358
|
-
return
|
|
17358
|
+
return BigNumber3.min(confidence, maxConfidenceInterval);
|
|
17359
17359
|
}
|
|
17360
17360
|
function parseOraclePriceData(oracleSetup, rawData) {
|
|
17361
17361
|
switch (oracleSetup) {
|
|
@@ -17371,18 +17371,18 @@ function parseOraclePriceData(oracleSetup, rawData) {
|
|
|
17371
17371
|
case "SwitchboardV2" /* SwitchboardV2 */: {
|
|
17372
17372
|
return {
|
|
17373
17373
|
priceRealtime: {
|
|
17374
|
-
price: new
|
|
17375
|
-
confidence: new
|
|
17376
|
-
lowestPrice: new
|
|
17377
|
-
highestPrice: new
|
|
17374
|
+
price: new BigNumber3(0),
|
|
17375
|
+
confidence: new BigNumber3(0),
|
|
17376
|
+
lowestPrice: new BigNumber3(0),
|
|
17377
|
+
highestPrice: new BigNumber3(0)
|
|
17378
17378
|
},
|
|
17379
17379
|
priceWeighted: {
|
|
17380
|
-
price: new
|
|
17381
|
-
confidence: new
|
|
17382
|
-
lowestPrice: new
|
|
17383
|
-
highestPrice: new
|
|
17380
|
+
price: new BigNumber3(0),
|
|
17381
|
+
confidence: new BigNumber3(0),
|
|
17382
|
+
lowestPrice: new BigNumber3(0),
|
|
17383
|
+
highestPrice: new BigNumber3(0)
|
|
17384
17384
|
},
|
|
17385
|
-
timestamp: new
|
|
17385
|
+
timestamp: new BigNumber3(0)
|
|
17386
17386
|
};
|
|
17387
17387
|
}
|
|
17388
17388
|
case "SwitchboardPull" /* SwitchboardPull */:
|
|
@@ -17432,18 +17432,18 @@ function oraclePriceToDto(oraclePrice) {
|
|
|
17432
17432
|
function dtoToOraclePrice(dto) {
|
|
17433
17433
|
return {
|
|
17434
17434
|
priceRealtime: {
|
|
17435
|
-
price: new
|
|
17436
|
-
confidence: new
|
|
17437
|
-
lowestPrice: new
|
|
17438
|
-
highestPrice: new
|
|
17435
|
+
price: new BigNumber3(dto.priceRealtime.price),
|
|
17436
|
+
confidence: new BigNumber3(dto.priceRealtime.confidence),
|
|
17437
|
+
lowestPrice: new BigNumber3(dto.priceRealtime.lowestPrice),
|
|
17438
|
+
highestPrice: new BigNumber3(dto.priceRealtime.highestPrice)
|
|
17439
17439
|
},
|
|
17440
17440
|
priceWeighted: {
|
|
17441
|
-
price: new
|
|
17442
|
-
confidence: new
|
|
17443
|
-
lowestPrice: new
|
|
17444
|
-
highestPrice: new
|
|
17441
|
+
price: new BigNumber3(dto.priceWeighted.price),
|
|
17442
|
+
confidence: new BigNumber3(dto.priceWeighted.confidence),
|
|
17443
|
+
lowestPrice: new BigNumber3(dto.priceWeighted.lowestPrice),
|
|
17444
|
+
highestPrice: new BigNumber3(dto.priceWeighted.highestPrice)
|
|
17445
17445
|
},
|
|
17446
|
-
timestamp: new
|
|
17446
|
+
timestamp: new BigNumber3(dto.timestamp),
|
|
17447
17447
|
switchboardData: dto.switchboardData
|
|
17448
17448
|
};
|
|
17449
17449
|
}
|
|
@@ -17714,10 +17714,10 @@ var EMPTY_HEALTH_CACHE = {
|
|
|
17714
17714
|
timestamp: new BN11(0),
|
|
17715
17715
|
flags: 0,
|
|
17716
17716
|
prices: [],
|
|
17717
|
-
assetValueMaint: bigNumberToWrappedI80F48(new
|
|
17718
|
-
liabilityValueMaint: bigNumberToWrappedI80F48(new
|
|
17719
|
-
assetValueEquity: bigNumberToWrappedI80F48(new
|
|
17720
|
-
liabilityValueEquity: bigNumberToWrappedI80F48(new
|
|
17717
|
+
assetValueMaint: bigNumberToWrappedI80F48(new BigNumber3(0)),
|
|
17718
|
+
liabilityValueMaint: bigNumberToWrappedI80F48(new BigNumber3(0)),
|
|
17719
|
+
assetValueEquity: bigNumberToWrappedI80F48(new BigNumber3(0)),
|
|
17720
|
+
liabilityValueEquity: bigNumberToWrappedI80F48(new BigNumber3(0)),
|
|
17721
17721
|
errIndex: 0,
|
|
17722
17722
|
internalErr: 0,
|
|
17723
17723
|
internalBankruptcyErr: 0,
|
|
@@ -17847,21 +17847,21 @@ function dtoToBalance(balanceDto) {
|
|
|
17847
17847
|
return {
|
|
17848
17848
|
active: balanceDto.active,
|
|
17849
17849
|
bankPk: new PublicKey(balanceDto.bankPk),
|
|
17850
|
-
assetShares: new
|
|
17851
|
-
liabilityShares: new
|
|
17852
|
-
emissionsOutstanding: new
|
|
17850
|
+
assetShares: new BigNumber3(balanceDto.assetShares),
|
|
17851
|
+
liabilityShares: new BigNumber3(balanceDto.liabilityShares),
|
|
17852
|
+
emissionsOutstanding: new BigNumber3(balanceDto.emissionsOutstanding),
|
|
17853
17853
|
lastUpdate: balanceDto.lastUpdate
|
|
17854
17854
|
};
|
|
17855
17855
|
}
|
|
17856
17856
|
function dtoToHealthCache(healthCacheDto) {
|
|
17857
17857
|
return {
|
|
17858
|
-
assetValue: new
|
|
17859
|
-
liabilityValue: new
|
|
17860
|
-
assetValueMaint: new
|
|
17861
|
-
liabilityValueMaint: new
|
|
17862
|
-
assetValueEquity: new
|
|
17863
|
-
liabilityValueEquity: new
|
|
17864
|
-
timestamp: new
|
|
17858
|
+
assetValue: new BigNumber3(healthCacheDto.assetValue),
|
|
17859
|
+
liabilityValue: new BigNumber3(healthCacheDto.liabilityValue),
|
|
17860
|
+
assetValueMaint: new BigNumber3(healthCacheDto.assetValueMaint),
|
|
17861
|
+
liabilityValueMaint: new BigNumber3(healthCacheDto.liabilityValueMaint),
|
|
17862
|
+
assetValueEquity: new BigNumber3(healthCacheDto.assetValueEquity),
|
|
17863
|
+
liabilityValueEquity: new BigNumber3(healthCacheDto.liabilityValueEquity),
|
|
17864
|
+
timestamp: new BigNumber3(healthCacheDto.timestamp),
|
|
17865
17865
|
flags: healthCacheDto.flags,
|
|
17866
17866
|
prices: healthCacheDto.prices,
|
|
17867
17867
|
simulationStatus: healthCacheDto.simulationStatus
|
|
@@ -17938,8 +17938,8 @@ function computeLowestEmodeWeights(emodePairs) {
|
|
|
17938
17938
|
});
|
|
17939
17939
|
} else {
|
|
17940
17940
|
result.set(bankPkStr, {
|
|
17941
|
-
assetWeightInit:
|
|
17942
|
-
assetWeightMaint:
|
|
17941
|
+
assetWeightInit: BigNumber3.min(existing.assetWeightInit, emodePair.assetWeightInit),
|
|
17942
|
+
assetWeightMaint: BigNumber3.min(existing.assetWeightMaint, emodePair.assetWeightMaint)
|
|
17943
17943
|
});
|
|
17944
17944
|
}
|
|
17945
17945
|
});
|
|
@@ -18178,8 +18178,8 @@ function computeQuantity(balance, bank) {
|
|
|
18178
18178
|
function computeQuantityUi(balance, bank, assetShareValueMultiplier) {
|
|
18179
18179
|
const { assets, liabilities } = computeQuantity(balance, bank);
|
|
18180
18180
|
const adjustedAssets = assetShareValueMultiplier ? assets.multipliedBy(assetShareValueMultiplier) : assets;
|
|
18181
|
-
const assetsQuantity = new
|
|
18182
|
-
const liabilitiesQuantity = new
|
|
18181
|
+
const assetsQuantity = new BigNumber3(nativeToUi(adjustedAssets, bank.mintDecimals));
|
|
18182
|
+
const liabilitiesQuantity = new BigNumber3(nativeToUi(liabilities, bank.mintDecimals));
|
|
18183
18183
|
return { assets: assetsQuantity, liabilities: liabilitiesQuantity };
|
|
18184
18184
|
}
|
|
18185
18185
|
|
|
@@ -18191,7 +18191,7 @@ function computeFreeCollateralFromCache(marginfiAccount, opts) {
|
|
|
18191
18191
|
0 /* Initial */
|
|
18192
18192
|
);
|
|
18193
18193
|
const signedFreeCollateral = assets.minus(liabilities);
|
|
18194
|
-
return _clamped ?
|
|
18194
|
+
return _clamped ? BigNumber3.max(0, signedFreeCollateral) : signedFreeCollateral;
|
|
18195
18195
|
}
|
|
18196
18196
|
function computeFreeCollateralFromBalances(params) {
|
|
18197
18197
|
const {
|
|
@@ -18211,7 +18211,7 @@ function computeFreeCollateralFromBalances(params) {
|
|
|
18211
18211
|
marginRequirement: 0 /* Initial */
|
|
18212
18212
|
});
|
|
18213
18213
|
const signedFreeCollateral = assets.minus(liabilities);
|
|
18214
|
-
return clamped ?
|
|
18214
|
+
return clamped ? BigNumber3.max(0, signedFreeCollateral) : signedFreeCollateral;
|
|
18215
18215
|
}
|
|
18216
18216
|
function computeHealthComponentsFromCache(marginfiAccount, marginRequirement) {
|
|
18217
18217
|
if (marginfiAccount.healthCache.simulationStatus === 0 /* UNSET */) {
|
|
@@ -18250,8 +18250,8 @@ function computeHealthComponentsFromBalances(params) {
|
|
|
18250
18250
|
const filteredBalances = activeBalances.filter(
|
|
18251
18251
|
(accountBalance) => !(excludedBanks ?? []).find((b) => b.equals(accountBalance.bankPk))
|
|
18252
18252
|
);
|
|
18253
|
-
let totalAssets = new
|
|
18254
|
-
let totalLiabilities = new
|
|
18253
|
+
let totalAssets = new BigNumber3(0);
|
|
18254
|
+
let totalLiabilities = new BigNumber3(0);
|
|
18255
18255
|
for (const accountBalance of filteredBalances) {
|
|
18256
18256
|
const bankKey = accountBalance.bankPk.toBase58();
|
|
18257
18257
|
const bank = banksMap.get(bankKey);
|
|
@@ -18271,11 +18271,11 @@ function computeHealthComponentsFromBalances(params) {
|
|
|
18271
18271
|
const emodeWeight = activeEmodeWeightsByBank?.get(bankKey);
|
|
18272
18272
|
const assetShareValueMultiplier = assetShareValueMultiplierByBank?.get(bankKey);
|
|
18273
18273
|
const activeEmodeWeights = emodeWeight ? {
|
|
18274
|
-
assetWeightInit:
|
|
18274
|
+
assetWeightInit: BigNumber3.max(
|
|
18275
18275
|
bank.config.assetWeightInit,
|
|
18276
18276
|
emodeWeight.assetWeightInit ?? bank.config.assetWeightInit
|
|
18277
18277
|
),
|
|
18278
|
-
assetWeightMaint:
|
|
18278
|
+
assetWeightMaint: BigNumber3.max(
|
|
18279
18279
|
bank.config.assetWeightMaint,
|
|
18280
18280
|
emodeWeight.assetWeightMaint ?? bank.config.assetWeightMaint
|
|
18281
18281
|
)
|
|
@@ -18306,8 +18306,8 @@ function computeHealthComponentsWithoutBiasFromBalances(params) {
|
|
|
18306
18306
|
const filteredBalances = activeBalances.filter(
|
|
18307
18307
|
(accountBalance) => !(excludedBanks ?? []).find((b) => b.equals(accountBalance.bankPk))
|
|
18308
18308
|
);
|
|
18309
|
-
let totalAssets = new
|
|
18310
|
-
let totalLiabilities = new
|
|
18309
|
+
let totalAssets = new BigNumber3(0);
|
|
18310
|
+
let totalLiabilities = new BigNumber3(0);
|
|
18311
18311
|
for (const accountBalance of filteredBalances) {
|
|
18312
18312
|
const bankKey = accountBalance.bankPk.toBase58();
|
|
18313
18313
|
const bank = banksMap.get(bankKey);
|
|
@@ -18327,11 +18327,11 @@ function computeHealthComponentsWithoutBiasFromBalances(params) {
|
|
|
18327
18327
|
const emodeWeight = activeEmodeWeightsByBank?.get(bankKey);
|
|
18328
18328
|
const assetShareValueMultiplier = assetShareValueMultiplierByBank?.get(bankKey);
|
|
18329
18329
|
const activeEmodeWeights = emodeWeight ? {
|
|
18330
|
-
assetWeightInit:
|
|
18330
|
+
assetWeightInit: BigNumber3.max(
|
|
18331
18331
|
bank.config.assetWeightInit,
|
|
18332
18332
|
emodeWeight.assetWeightInit ?? bank.config.assetWeightInit
|
|
18333
18333
|
),
|
|
18334
|
-
assetWeightMaint:
|
|
18334
|
+
assetWeightMaint: BigNumber3.max(
|
|
18335
18335
|
bank.config.assetWeightMaint,
|
|
18336
18336
|
emodeWeight.assetWeightMaint ?? bank.config.assetWeightMaint
|
|
18337
18337
|
)
|
|
@@ -18388,7 +18388,7 @@ function computeHealthCacheStatus(params) {
|
|
|
18388
18388
|
liabilityValueMaint,
|
|
18389
18389
|
assetValueEquity,
|
|
18390
18390
|
liabilityValueEquity,
|
|
18391
|
-
timestamp: new
|
|
18391
|
+
timestamp: new BigNumber3(0),
|
|
18392
18392
|
flags: [],
|
|
18393
18393
|
prices: [],
|
|
18394
18394
|
simulationStatus: 2 /* COMPUTED */
|
|
@@ -18435,9 +18435,9 @@ function createEmptyBalance(bankPk) {
|
|
|
18435
18435
|
const balance = {
|
|
18436
18436
|
active: false,
|
|
18437
18437
|
bankPk,
|
|
18438
|
-
assetShares: new
|
|
18439
|
-
liabilityShares: new
|
|
18440
|
-
emissionsOutstanding: new
|
|
18438
|
+
assetShares: new BigNumber3(0),
|
|
18439
|
+
liabilityShares: new BigNumber3(0),
|
|
18440
|
+
emissionsOutstanding: new BigNumber3(0),
|
|
18441
18441
|
lastUpdate: 0
|
|
18442
18442
|
};
|
|
18443
18443
|
return balance;
|
|
@@ -18508,7 +18508,7 @@ function computeNetApy(params) {
|
|
|
18508
18508
|
}).assets
|
|
18509
18509
|
).div(totalUsdValue.isEqualTo(0) ? 1 : totalUsdValue)
|
|
18510
18510
|
);
|
|
18511
|
-
}, new
|
|
18511
|
+
}, new BigNumber3(0)).toNumber();
|
|
18512
18512
|
return aprToApy(apr);
|
|
18513
18513
|
}
|
|
18514
18514
|
function computeLiquidationPriceForBank(params) {
|
|
@@ -18568,13 +18568,13 @@ function computeClaimedEmissions(balance, bank, currentTimestamp) {
|
|
|
18568
18568
|
}
|
|
18569
18569
|
if (balanceAmount) {
|
|
18570
18570
|
const lastUpdate = balance.lastUpdate;
|
|
18571
|
-
const period = new
|
|
18572
|
-
const emissionsRate = new
|
|
18571
|
+
const period = new BigNumber3(currentTimestamp - lastUpdate);
|
|
18572
|
+
const emissionsRate = new BigNumber3(bank.emissionsRate);
|
|
18573
18573
|
const emissions = period.times(balanceAmount).times(emissionsRate).div(31536e3 * Math.pow(10, bank.mintDecimals));
|
|
18574
|
-
const emissionsReal =
|
|
18574
|
+
const emissionsReal = BigNumber3.min(emissions, new BigNumber3(bank.emissionsRemaining));
|
|
18575
18575
|
return emissionsReal;
|
|
18576
18576
|
}
|
|
18577
|
-
return new
|
|
18577
|
+
return new BigNumber3(0);
|
|
18578
18578
|
}
|
|
18579
18579
|
function computeTotalOutstandingEmissions(balance, bank) {
|
|
18580
18580
|
const claimedEmissions = balance.emissionsOutstanding;
|
|
@@ -18696,9 +18696,9 @@ function computeProjectedActiveBalancesNoCpi(balances, instructions2, program, b
|
|
|
18696
18696
|
let projectedBalances = balances.map((b) => ({
|
|
18697
18697
|
active: b.active,
|
|
18698
18698
|
bankPk: b.bankPk,
|
|
18699
|
-
assetShares: new
|
|
18700
|
-
liabilityShares: new
|
|
18701
|
-
emissionsOutstanding: new
|
|
18699
|
+
assetShares: new BigNumber3(b.assetShares),
|
|
18700
|
+
liabilityShares: new BigNumber3(b.liabilityShares),
|
|
18701
|
+
emissionsOutstanding: new BigNumber3(b.emissionsOutstanding),
|
|
18702
18702
|
lastUpdate: b.lastUpdate
|
|
18703
18703
|
}));
|
|
18704
18704
|
const impactedAssetsBanks = /* @__PURE__ */ new Set();
|
|
@@ -18727,15 +18727,15 @@ function computeProjectedActiveBalancesNoCpi(balances, instructions2, program, b
|
|
|
18727
18727
|
targetBalance = projectedBalances[firstInactiveBalanceIndex];
|
|
18728
18728
|
targetBalance.active = true;
|
|
18729
18729
|
targetBalance.bankPk = targetBank;
|
|
18730
|
-
targetBalance.assetShares = new
|
|
18731
|
-
targetBalance.liabilityShares = new
|
|
18730
|
+
targetBalance.assetShares = new BigNumber3(0);
|
|
18731
|
+
targetBalance.liabilityShares = new BigNumber3(0);
|
|
18732
18732
|
}
|
|
18733
|
-
const depositTokenAmount = new
|
|
18733
|
+
const depositTokenAmount = new BigNumber3(ixArgs.amount?.toString() || "0");
|
|
18734
18734
|
const bank = banksMap.get(targetBank.toBase58());
|
|
18735
18735
|
if (!bank) {
|
|
18736
18736
|
throw Error(`Bank ${targetBank.toBase58()} not found in bankMap`);
|
|
18737
18737
|
}
|
|
18738
|
-
const assetShareValueMultiplier = assetShareValueMultiplierByBank.get(targetBank.toBase58()) ??
|
|
18738
|
+
const assetShareValueMultiplier = assetShareValueMultiplierByBank.get(targetBank.toBase58()) ?? BigNumber3(1);
|
|
18739
18739
|
const cTokenAmount = depositTokenAmount.div(assetShareValueMultiplier);
|
|
18740
18740
|
const depositShares = getAssetShares(bank, cTokenAmount);
|
|
18741
18741
|
targetBalance.assetShares = targetBalance.assetShares.plus(depositShares);
|
|
@@ -18753,10 +18753,10 @@ function computeProjectedActiveBalancesNoCpi(balances, instructions2, program, b
|
|
|
18753
18753
|
targetBalance = projectedBalances[firstInactiveBalanceIndex];
|
|
18754
18754
|
targetBalance.active = true;
|
|
18755
18755
|
targetBalance.bankPk = targetBank;
|
|
18756
|
-
targetBalance.assetShares = new
|
|
18757
|
-
targetBalance.liabilityShares = new
|
|
18756
|
+
targetBalance.assetShares = new BigNumber3(0);
|
|
18757
|
+
targetBalance.liabilityShares = new BigNumber3(0);
|
|
18758
18758
|
}
|
|
18759
|
-
const borrowTokenAmount = new
|
|
18759
|
+
const borrowTokenAmount = new BigNumber3(ixArgs.amount?.toString() || "0");
|
|
18760
18760
|
const bank = banksMap.get(targetBank.toBase58());
|
|
18761
18761
|
if (!bank) {
|
|
18762
18762
|
throw Error(`Bank ${targetBank.toBase58()} not found in bankMap`);
|
|
@@ -18776,19 +18776,19 @@ function computeProjectedActiveBalancesNoCpi(balances, instructions2, program, b
|
|
|
18776
18776
|
);
|
|
18777
18777
|
}
|
|
18778
18778
|
if (ixArgs.repayAll) {
|
|
18779
|
-
targetBalance.liabilityShares = new
|
|
18779
|
+
targetBalance.liabilityShares = new BigNumber3(0);
|
|
18780
18780
|
if (targetBalance.assetShares.eq(0)) {
|
|
18781
18781
|
targetBalance.active = false;
|
|
18782
18782
|
targetBalance.bankPk = PublicKey.default;
|
|
18783
18783
|
}
|
|
18784
18784
|
} else {
|
|
18785
|
-
const repayTokenAmount = new
|
|
18785
|
+
const repayTokenAmount = new BigNumber3(ixArgs.amount?.toString() || "0");
|
|
18786
18786
|
const bank = banksMap.get(targetBank.toBase58());
|
|
18787
18787
|
if (!bank) {
|
|
18788
18788
|
throw Error(`Bank ${targetBank.toBase58()} not found in bankMap`);
|
|
18789
18789
|
}
|
|
18790
18790
|
const repayShares = getLiabilityShares(bank, repayTokenAmount);
|
|
18791
|
-
targetBalance.liabilityShares =
|
|
18791
|
+
targetBalance.liabilityShares = BigNumber3.max(
|
|
18792
18792
|
0,
|
|
18793
18793
|
targetBalance.liabilityShares.minus(repayShares)
|
|
18794
18794
|
);
|
|
@@ -18812,19 +18812,19 @@ function computeProjectedActiveBalancesNoCpi(balances, instructions2, program, b
|
|
|
18812
18812
|
);
|
|
18813
18813
|
}
|
|
18814
18814
|
if (ixArgs.withdrawAll) {
|
|
18815
|
-
targetBalance.assetShares = new
|
|
18815
|
+
targetBalance.assetShares = new BigNumber3(0);
|
|
18816
18816
|
if (targetBalance.liabilityShares.eq(0)) {
|
|
18817
18817
|
targetBalance.active = false;
|
|
18818
18818
|
targetBalance.bankPk = PublicKey.default;
|
|
18819
18819
|
}
|
|
18820
18820
|
} else {
|
|
18821
|
-
const withdrawTokenAmount = new
|
|
18821
|
+
const withdrawTokenAmount = new BigNumber3(ixArgs.amount?.toString() || "0");
|
|
18822
18822
|
const bank = banksMap.get(targetBank.toBase58());
|
|
18823
18823
|
if (!bank) {
|
|
18824
18824
|
throw Error(`Bank ${targetBank.toBase58()} not found in bankMap`);
|
|
18825
18825
|
}
|
|
18826
18826
|
const withdrawShares = getAssetShares(bank, withdrawTokenAmount);
|
|
18827
|
-
targetBalance.assetShares =
|
|
18827
|
+
targetBalance.assetShares = BigNumber3.max(
|
|
18828
18828
|
0,
|
|
18829
18829
|
targetBalance.assetShares.minus(withdrawShares)
|
|
18830
18830
|
);
|
|
@@ -33685,7 +33685,7 @@ async function makePulseHealthIx2(program, marginfiAccountPk, banks, balances, m
|
|
|
33685
33685
|
return { instructions: [ix], keys: [] };
|
|
33686
33686
|
}
|
|
33687
33687
|
function generateDummyAccount(group, authority, accountKey) {
|
|
33688
|
-
const dummyWrappedI80F48 = bigNumberToWrappedI80F48(new
|
|
33688
|
+
const dummyWrappedI80F48 = bigNumberToWrappedI80F48(new BigNumber3(0));
|
|
33689
33689
|
const dummyBalances = Array(15).fill({
|
|
33690
33690
|
active: false,
|
|
33691
33691
|
bankPk: new PublicKey("11111111111111111111111111111111"),
|
|
@@ -33708,10 +33708,10 @@ function generateDummyAccount(group, authority, accountKey) {
|
|
|
33708
33708
|
timestamp: new BN11(0),
|
|
33709
33709
|
flags: 0,
|
|
33710
33710
|
prices: [],
|
|
33711
|
-
assetValueMaint: bigNumberToWrappedI80F48(new
|
|
33712
|
-
liabilityValueMaint: bigNumberToWrappedI80F48(new
|
|
33713
|
-
assetValueEquity: bigNumberToWrappedI80F48(new
|
|
33714
|
-
liabilityValueEquity: bigNumberToWrappedI80F48(new
|
|
33711
|
+
assetValueMaint: bigNumberToWrappedI80F48(new BigNumber3(0)),
|
|
33712
|
+
liabilityValueMaint: bigNumberToWrappedI80F48(new BigNumber3(0)),
|
|
33713
|
+
assetValueEquity: bigNumberToWrappedI80F48(new BigNumber3(0)),
|
|
33714
|
+
liabilityValueEquity: bigNumberToWrappedI80F48(new BigNumber3(0)),
|
|
33715
33715
|
errIndex: 0,
|
|
33716
33716
|
internalErr: 0,
|
|
33717
33717
|
internalBankruptcyErr: 0,
|
|
@@ -42326,8 +42326,8 @@ async function makeKaminoWithdrawTx(params) {
|
|
|
42326
42326
|
throw new Error("Bank has no kamino integration accounts");
|
|
42327
42327
|
}
|
|
42328
42328
|
const { value: amountValue, type: amountType } = resolveAmount(amount);
|
|
42329
|
-
const multiplier = assetShareValueMultiplierByBank.get(withdrawIxParams.bank.address.toBase58()) ?? new BigNumber
|
|
42330
|
-
const adjustedAmount = amountType === "cToken" ? new BigNumber
|
|
42329
|
+
const multiplier = assetShareValueMultiplierByBank.get(withdrawIxParams.bank.address.toBase58()) ?? new BigNumber(1);
|
|
42330
|
+
const adjustedAmount = amountType === "cToken" ? new BigNumber(amountValue).toNumber() : new BigNumber(amountValue).div(multiplier).toNumber();
|
|
42331
42331
|
const refreshIxs = makeRefreshKaminoBanksIxs(
|
|
42332
42332
|
params.marginfiAccount,
|
|
42333
42333
|
params.bankMap,
|
|
@@ -42569,7 +42569,7 @@ async function makeDriftDepositIx3({
|
|
|
42569
42569
|
const depositIxs = [];
|
|
42570
42570
|
const userTokenAtaPk = getAssociatedTokenAddressSync(bank.mint, authority, true, tokenProgram);
|
|
42571
42571
|
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
42572
|
-
depositIxs.push(...makeWrapSolIxs(authority, new
|
|
42572
|
+
depositIxs.push(...makeWrapSolIxs(authority, new BigNumber3(amount).minus(wSolBalanceUi)));
|
|
42573
42573
|
}
|
|
42574
42574
|
const driftState = deriveDriftState()[0];
|
|
42575
42575
|
const driftSpotMarketVault = deriveDriftSpotMarketVault(driftMarketIndex)[0];
|
|
@@ -42679,7 +42679,7 @@ async function makeKaminoDepositIx3({
|
|
|
42679
42679
|
const reserveDestinationDepositCollateral = reserve.collateral.supplyVault;
|
|
42680
42680
|
const { lendingMarketAuthority } = getAllDerivedKaminoAccounts(reserve.lendingMarket, bank.mint);
|
|
42681
42681
|
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
42682
|
-
depositIxs.push(...makeWrapSolIxs(authority, new
|
|
42682
|
+
depositIxs.push(...makeWrapSolIxs(authority, new BigNumber3(amount).minus(wSolBalanceUi)));
|
|
42683
42683
|
}
|
|
42684
42684
|
const reserveFarm = !reserve.farmCollateral.equals(
|
|
42685
42685
|
new PublicKey("11111111111111111111111111111111")
|
|
@@ -42808,7 +42808,7 @@ async function makeDepositIx3({
|
|
|
42808
42808
|
const remainingAccounts = tokenProgram.equals(TOKEN_2022_PROGRAM_ID) ? [{ pubkey: bank.mint, isSigner: false, isWritable: false }] : [];
|
|
42809
42809
|
const depositIxs = [];
|
|
42810
42810
|
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
42811
|
-
depositIxs.push(...makeWrapSolIxs(authority, new
|
|
42811
|
+
depositIxs.push(...makeWrapSolIxs(authority, new BigNumber3(amount).minus(wSolBalanceUi)));
|
|
42812
42812
|
}
|
|
42813
42813
|
const depositIx = isSync ? sync_instructions_default.makeDepositIx(
|
|
42814
42814
|
program.programId,
|
|
@@ -43023,7 +43023,7 @@ async function makeLoopTx(params) {
|
|
|
43023
43023
|
let additionalTxs = [];
|
|
43024
43024
|
if (depositOpts.depositBank.mint.equals(NATIVE_MINT) && depositOpts.inputDepositAmount) {
|
|
43025
43025
|
setupIxs.push(
|
|
43026
|
-
...makeWrapSolIxs(marginfiAccount.authority, new BigNumber
|
|
43026
|
+
...makeWrapSolIxs(marginfiAccount.authority, new BigNumber(depositOpts.inputDepositAmount))
|
|
43027
43027
|
);
|
|
43028
43028
|
}
|
|
43029
43029
|
if (setupIxs.length > 0 || additionalIxs.length > 0 || kaminoRefreshIxs.instructions.length > 0 || updateDriftMarketIxs.instructions.length > 0) {
|
|
@@ -43281,7 +43281,7 @@ async function makeRepayIx3({
|
|
|
43281
43281
|
const userAta = getAssociatedTokenAddressSync(bank.mint, authority, true, tokenProgram);
|
|
43282
43282
|
const remainingAccounts = tokenProgram.equals(TOKEN_2022_PROGRAM_ID) ? [{ pubkey: bank.mint, isSigner: false, isWritable: false }] : [];
|
|
43283
43283
|
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
43284
|
-
repayIxs.push(...makeWrapSolIxs(authority, new BigNumber
|
|
43284
|
+
repayIxs.push(...makeWrapSolIxs(authority, new BigNumber(amount).minus(wSolBalanceUi)));
|
|
43285
43285
|
}
|
|
43286
43286
|
const repayIx = !isSync || !opts.overrideInferAccounts?.group ? await instructions_default.makeRepayIx(
|
|
43287
43287
|
program,
|
|
@@ -43511,8 +43511,8 @@ async function buildRepayWithCollatFlashloanTx({
|
|
|
43511
43511
|
withdrawOpts.withdrawBank.tokenSymbol
|
|
43512
43512
|
);
|
|
43513
43513
|
}
|
|
43514
|
-
const multiplier = assetShareValueMultiplierByBank.get(withdrawOpts.withdrawBank.address.toBase58()) ?? new BigNumber
|
|
43515
|
-
const adjustedAmount = new BigNumber
|
|
43514
|
+
const multiplier = assetShareValueMultiplierByBank.get(withdrawOpts.withdrawBank.address.toBase58()) ?? new BigNumber(1);
|
|
43515
|
+
const adjustedAmount = new BigNumber(withdrawOpts.withdrawAmount).div(multiplier).times(1.0001).toNumber();
|
|
43516
43516
|
withdrawIxs = await makeKaminoWithdrawIx3({
|
|
43517
43517
|
program,
|
|
43518
43518
|
bank: withdrawOpts.withdrawBank,
|
|
@@ -43849,8 +43849,8 @@ async function buildSwapCollateralFlashloanTx({
|
|
|
43849
43849
|
withdrawOpts.withdrawBank.tokenSymbol
|
|
43850
43850
|
);
|
|
43851
43851
|
}
|
|
43852
|
-
const multiplier = assetShareValueMultiplierByBank.get(withdrawOpts.withdrawBank.address.toBase58()) ?? new BigNumber
|
|
43853
|
-
const adjustedAmount = new BigNumber
|
|
43852
|
+
const multiplier = assetShareValueMultiplierByBank.get(withdrawOpts.withdrawBank.address.toBase58()) ?? new BigNumber(1);
|
|
43853
|
+
const adjustedAmount = new BigNumber(actualWithdrawAmount).div(multiplier).times(1.0001).toNumber();
|
|
43854
43854
|
withdrawIxs = await makeKaminoWithdrawIx3({
|
|
43855
43855
|
program,
|
|
43856
43856
|
bank: withdrawBank,
|
|
@@ -44419,7 +44419,7 @@ async function simulateAccountHealthCacheWithFallback(params) {
|
|
|
44419
44419
|
liabilityValueMaint,
|
|
44420
44420
|
assetValueEquity,
|
|
44421
44421
|
liabilityValueEquity,
|
|
44422
|
-
timestamp: new
|
|
44422
|
+
timestamp: new BigNumber3(0),
|
|
44423
44423
|
flags: [],
|
|
44424
44424
|
prices: [],
|
|
44425
44425
|
simulationStatus: 2 /* COMPUTED */
|
|
@@ -44833,7 +44833,7 @@ function computeMaxBorrowForBank(params) {
|
|
|
44833
44833
|
(b) => b.config.riskTier === "Isolated" /* Isolated */ && !b.address.equals(bankAddress)
|
|
44834
44834
|
);
|
|
44835
44835
|
if (attemptingToBorrowIsolatedAssetWithActiveDebt || attemptingToBorrowNewAssetWithExistingIsolatedDebt) {
|
|
44836
|
-
return new
|
|
44836
|
+
return new BigNumber3(0);
|
|
44837
44837
|
}
|
|
44838
44838
|
const _volatilityFactor = volatilityFactor ?? 1;
|
|
44839
44839
|
const balance = getBalance(bankAddress, activeBalances);
|
|
@@ -44845,7 +44845,7 @@ function computeMaxBorrowForBank(params) {
|
|
|
44845
44845
|
activeEmodeWeightsByBank,
|
|
44846
44846
|
assetShareValueMultiplierByBank
|
|
44847
44847
|
}).times(_volatilityFactor);
|
|
44848
|
-
const untiedCollateralForBank =
|
|
44848
|
+
const untiedCollateralForBank = BigNumber3.min(
|
|
44849
44849
|
computeAssetUsdValue({
|
|
44850
44850
|
bank,
|
|
44851
44851
|
oraclePrice,
|
|
@@ -44944,7 +44944,7 @@ function computeMaxWithdrawForBank(params) {
|
|
|
44944
44944
|
);
|
|
44945
44945
|
if (bank.config.riskTier === "Isolated" /* Isolated */ || initAssetWeight.isZero() && maintAssetWeight.isZero()) {
|
|
44946
44946
|
if (freeCollateral.isZero() && !liabilitiesInit.isZero()) {
|
|
44947
|
-
return new
|
|
44947
|
+
return new BigNumber3(0);
|
|
44948
44948
|
} else {
|
|
44949
44949
|
return entireBalance;
|
|
44950
44950
|
}
|
|
@@ -44953,7 +44953,7 @@ function computeMaxWithdrawForBank(params) {
|
|
|
44953
44953
|
if (liabilitiesInit.eq(0)) {
|
|
44954
44954
|
return entireBalance;
|
|
44955
44955
|
} else if (freeCollateral.isZero()) {
|
|
44956
|
-
return new
|
|
44956
|
+
return new BigNumber3(0);
|
|
44957
44957
|
} else {
|
|
44958
44958
|
const { liabilities: maintLiabilities, assets: maintAssets } = computeHealthComponentsFromCache(account, 1 /* Maintenance */);
|
|
44959
44959
|
const maintUntiedCollateral = maintAssets.minus(maintLiabilities);
|
|
@@ -45318,9 +45318,7 @@ async function computeSmartCrank({
|
|
|
45318
45318
|
};
|
|
45319
45319
|
}
|
|
45320
45320
|
async function makeSmartCrankSwbFeedIx(params) {
|
|
45321
|
-
console.log("[makeSmartCrankSwbFeedIx] Called");
|
|
45322
45321
|
const crankResult = await computeSmartCrank(params);
|
|
45323
|
-
console.log("[makeSmartCrankSwbFeedIx] Crank result:", crankResult);
|
|
45324
45322
|
if (crankResult.uncrankableLiabilities.length > 0) {
|
|
45325
45323
|
console.log(
|
|
45326
45324
|
"Uncrankable liability details:",
|
|
@@ -45356,7 +45354,6 @@ async function makeSmartCrankSwbFeedIx(params) {
|
|
|
45356
45354
|
);
|
|
45357
45355
|
}
|
|
45358
45356
|
const oraclesToCrank = crankResult.requiredOracles;
|
|
45359
|
-
console.log("[makeSmartCrankSwbFeedIx] Oracles to crank:", oraclesToCrank);
|
|
45360
45357
|
const { instructions: instructions2, luts } = await makeUpdateSwbFeedIx({
|
|
45361
45358
|
swbPullOracles: oraclesToCrank,
|
|
45362
45359
|
feePayer: params.marginfiAccount.authority,
|
|
@@ -45393,9 +45390,6 @@ async function makeCrankSwbFeedIx(marginfiAccount, bankMap, newBanksPk, provider
|
|
|
45393
45390
|
}
|
|
45394
45391
|
}
|
|
45395
45392
|
async function makeUpdateSwbFeedIx(props) {
|
|
45396
|
-
console.log(
|
|
45397
|
-
`[makeUpdateSwbFeedIx] Called with ${props.swbPullOracles.length} oracles, feePayer: ${props.feePayer.toBase58()}`
|
|
45398
|
-
);
|
|
45399
45393
|
const seen = /* @__PURE__ */ new Set();
|
|
45400
45394
|
const uniqueOracles = props.swbPullOracles.filter((oracle) => {
|
|
45401
45395
|
const key = oracle.key.toBase58();
|
|
@@ -45403,21 +45397,12 @@ async function makeUpdateSwbFeedIx(props) {
|
|
|
45403
45397
|
seen.add(key);
|
|
45404
45398
|
return true;
|
|
45405
45399
|
});
|
|
45406
|
-
console.log(
|
|
45407
|
-
`[makeUpdateSwbFeedIx] ${uniqueOracles.length} unique oracles after dedup (removed ${props.swbPullOracles.length - uniqueOracles.length})`
|
|
45408
|
-
);
|
|
45409
|
-
uniqueOracles.forEach(
|
|
45410
|
-
(o) => console.log(
|
|
45411
|
-
`[makeUpdateSwbFeedIx] - ${o.key.toBase58()} (hasSwitchboardData: ${!!o.price?.switchboardData})`
|
|
45412
|
-
)
|
|
45413
|
-
);
|
|
45414
45400
|
const swbProgram = await AnchorUtils.loadProgramFromConnection(props.connection);
|
|
45415
45401
|
const pullFeedInstances = uniqueOracles.map((oracle) => {
|
|
45416
45402
|
const pullFeed = new PullFeed(swbProgram, oracle.key);
|
|
45417
45403
|
return pullFeed;
|
|
45418
45404
|
});
|
|
45419
45405
|
if (pullFeedInstances.length === 0) {
|
|
45420
|
-
console.log(`[makeUpdateSwbFeedIx] No pull feed instances, returning early`);
|
|
45421
45406
|
return { instructions: [], luts: [] };
|
|
45422
45407
|
}
|
|
45423
45408
|
const crossbarClient = new CrossbarClient(
|
|
@@ -45439,7 +45424,6 @@ async function makeUpdateSwbFeedIx(props) {
|
|
|
45439
45424
|
payer: props.feePayer,
|
|
45440
45425
|
crossbarClient
|
|
45441
45426
|
});
|
|
45442
|
-
console.log(`[makeUpdateSwbFeedIx] Got ${pullIx.length} instructions, ${luts.length} LUTs`);
|
|
45443
45427
|
return { instructions: pullIx, luts };
|
|
45444
45428
|
}
|
|
45445
45429
|
|
|
@@ -45781,18 +45765,18 @@ var fetchPythOraclePricesFromAPI = async (pythOracleKeys, apiEndpoint, opts) =>
|
|
|
45781
45765
|
key,
|
|
45782
45766
|
{
|
|
45783
45767
|
priceRealtime: {
|
|
45784
|
-
price:
|
|
45785
|
-
confidence:
|
|
45786
|
-
lowestPrice:
|
|
45787
|
-
highestPrice:
|
|
45768
|
+
price: BigNumber3(oraclePrice.priceRealtime.price),
|
|
45769
|
+
confidence: BigNumber3(oraclePrice.priceRealtime.confidence),
|
|
45770
|
+
lowestPrice: BigNumber3(oraclePrice.priceRealtime.lowestPrice),
|
|
45771
|
+
highestPrice: BigNumber3(oraclePrice.priceRealtime.highestPrice)
|
|
45788
45772
|
},
|
|
45789
45773
|
priceWeighted: {
|
|
45790
|
-
price:
|
|
45791
|
-
confidence:
|
|
45792
|
-
lowestPrice:
|
|
45793
|
-
highestPrice:
|
|
45774
|
+
price: BigNumber3(oraclePrice.priceWeighted.price),
|
|
45775
|
+
confidence: BigNumber3(oraclePrice.priceWeighted.confidence),
|
|
45776
|
+
lowestPrice: BigNumber3(oraclePrice.priceWeighted.lowestPrice),
|
|
45777
|
+
highestPrice: BigNumber3(oraclePrice.priceWeighted.highestPrice)
|
|
45794
45778
|
},
|
|
45795
|
-
timestamp: oraclePrice.timestamp ?
|
|
45779
|
+
timestamp: oraclePrice.timestamp ? BigNumber3(oraclePrice.timestamp) : null
|
|
45796
45780
|
}
|
|
45797
45781
|
])
|
|
45798
45782
|
);
|
|
@@ -45807,22 +45791,22 @@ var fetchPythOraclePricesFromChain = async (requestedPythOracleKeys, connection)
|
|
|
45807
45791
|
const oracleKey = requestedPythOracleKeys[index];
|
|
45808
45792
|
const priceDataRaw = oracleAis[index];
|
|
45809
45793
|
let oraclePrice = priceDataRaw && parseRpcPythPriceData(priceDataRaw.data);
|
|
45810
|
-
if (!oraclePrice || oraclePrice.priceRealtime.price.eq(new
|
|
45794
|
+
if (!oraclePrice || oraclePrice.priceRealtime.price.eq(new BigNumber3(0))) {
|
|
45811
45795
|
oraclePrice = {
|
|
45812
45796
|
...oraclePrice,
|
|
45813
45797
|
priceRealtime: {
|
|
45814
|
-
price: new
|
|
45815
|
-
confidence: new
|
|
45816
|
-
lowestPrice: new
|
|
45817
|
-
highestPrice: new
|
|
45798
|
+
price: new BigNumber3(0),
|
|
45799
|
+
confidence: new BigNumber3(0),
|
|
45800
|
+
lowestPrice: new BigNumber3(0),
|
|
45801
|
+
highestPrice: new BigNumber3(0)
|
|
45818
45802
|
},
|
|
45819
45803
|
priceWeighted: {
|
|
45820
|
-
price: new
|
|
45821
|
-
confidence: new
|
|
45822
|
-
lowestPrice: new
|
|
45823
|
-
highestPrice: new
|
|
45804
|
+
price: new BigNumber3(0),
|
|
45805
|
+
confidence: new BigNumber3(0),
|
|
45806
|
+
lowestPrice: new BigNumber3(0),
|
|
45807
|
+
highestPrice: new BigNumber3(0)
|
|
45824
45808
|
},
|
|
45825
|
-
timestamp: new
|
|
45809
|
+
timestamp: new BigNumber3(Date.now())
|
|
45826
45810
|
};
|
|
45827
45811
|
}
|
|
45828
45812
|
updatedOraclePriceByKey[oracleKey] = oraclePrice;
|
|
@@ -46099,17 +46083,17 @@ function handleFixedOracleBanks(banks) {
|
|
|
46099
46083
|
const fixedOraclePrice = {
|
|
46100
46084
|
priceRealtime: {
|
|
46101
46085
|
price: fixedPrice,
|
|
46102
|
-
confidence:
|
|
46086
|
+
confidence: BigNumber3(0),
|
|
46103
46087
|
lowestPrice: fixedPrice,
|
|
46104
46088
|
highestPrice: fixedPrice
|
|
46105
46089
|
},
|
|
46106
46090
|
priceWeighted: {
|
|
46107
46091
|
price: fixedPrice,
|
|
46108
|
-
confidence:
|
|
46092
|
+
confidence: BigNumber3(0),
|
|
46109
46093
|
lowestPrice: fixedPrice,
|
|
46110
46094
|
highestPrice: fixedPrice
|
|
46111
46095
|
},
|
|
46112
|
-
timestamp:
|
|
46096
|
+
timestamp: BigNumber3(Date.now())
|
|
46113
46097
|
};
|
|
46114
46098
|
oracleMap.set(bank.address.toBase58(), fixedOraclePrice);
|
|
46115
46099
|
});
|
|
@@ -46120,18 +46104,18 @@ function handleZeroOracleBanks(banks) {
|
|
|
46120
46104
|
banks.forEach((bank) => {
|
|
46121
46105
|
const zeroOraclePrice = {
|
|
46122
46106
|
priceRealtime: {
|
|
46123
|
-
price:
|
|
46124
|
-
confidence:
|
|
46125
|
-
lowestPrice:
|
|
46126
|
-
highestPrice:
|
|
46107
|
+
price: BigNumber3(0),
|
|
46108
|
+
confidence: BigNumber3(0),
|
|
46109
|
+
lowestPrice: BigNumber3(0),
|
|
46110
|
+
highestPrice: BigNumber3(0)
|
|
46127
46111
|
},
|
|
46128
46112
|
priceWeighted: {
|
|
46129
|
-
price:
|
|
46130
|
-
confidence:
|
|
46131
|
-
lowestPrice:
|
|
46132
|
-
highestPrice:
|
|
46113
|
+
price: BigNumber3(0),
|
|
46114
|
+
confidence: BigNumber3(0),
|
|
46115
|
+
lowestPrice: BigNumber3(0),
|
|
46116
|
+
highestPrice: BigNumber3(0)
|
|
46133
46117
|
},
|
|
46134
|
-
timestamp:
|
|
46118
|
+
timestamp: BigNumber3(Date.now())
|
|
46135
46119
|
};
|
|
46136
46120
|
oracleMap.set(bank.address.toBase58(), zeroOraclePrice);
|
|
46137
46121
|
});
|
|
@@ -46143,18 +46127,18 @@ function handleIsolatedAssetBanks(banks, staticPrices) {
|
|
|
46143
46127
|
const price = staticPrices?.[bank.address.toBase58()] ?? 0;
|
|
46144
46128
|
const oraclePrice = {
|
|
46145
46129
|
priceRealtime: {
|
|
46146
|
-
price:
|
|
46147
|
-
confidence:
|
|
46148
|
-
lowestPrice:
|
|
46149
|
-
highestPrice:
|
|
46130
|
+
price: BigNumber3(price),
|
|
46131
|
+
confidence: BigNumber3(0),
|
|
46132
|
+
lowestPrice: BigNumber3(price),
|
|
46133
|
+
highestPrice: BigNumber3(price)
|
|
46150
46134
|
},
|
|
46151
46135
|
priceWeighted: {
|
|
46152
|
-
price:
|
|
46153
|
-
confidence:
|
|
46154
|
-
lowestPrice:
|
|
46155
|
-
highestPrice:
|
|
46136
|
+
price: BigNumber3(price),
|
|
46137
|
+
confidence: BigNumber3(0),
|
|
46138
|
+
lowestPrice: BigNumber3(price),
|
|
46139
|
+
highestPrice: BigNumber3(price)
|
|
46156
46140
|
},
|
|
46157
|
-
timestamp:
|
|
46141
|
+
timestamp: BigNumber3(Date.now())
|
|
46158
46142
|
};
|
|
46159
46143
|
oracleMap.set(bank.address.toBase58(), oraclePrice);
|
|
46160
46144
|
});
|
|
@@ -46181,18 +46165,18 @@ async function handleAssetBanks(banks, opts) {
|
|
|
46181
46165
|
if (!oraclePrice) {
|
|
46182
46166
|
bankOraclePriceMap.set(bankAddress, {
|
|
46183
46167
|
priceRealtime: {
|
|
46184
|
-
price:
|
|
46185
|
-
confidence:
|
|
46186
|
-
lowestPrice:
|
|
46187
|
-
highestPrice:
|
|
46168
|
+
price: BigNumber3(0),
|
|
46169
|
+
confidence: BigNumber3(0),
|
|
46170
|
+
lowestPrice: BigNumber3(0),
|
|
46171
|
+
highestPrice: BigNumber3(0)
|
|
46188
46172
|
},
|
|
46189
46173
|
priceWeighted: {
|
|
46190
|
-
price:
|
|
46191
|
-
confidence:
|
|
46192
|
-
lowestPrice:
|
|
46193
|
-
highestPrice:
|
|
46174
|
+
price: BigNumber3(0),
|
|
46175
|
+
confidence: BigNumber3(0),
|
|
46176
|
+
lowestPrice: BigNumber3(0),
|
|
46177
|
+
highestPrice: BigNumber3(0)
|
|
46194
46178
|
},
|
|
46195
|
-
timestamp:
|
|
46179
|
+
timestamp: BigNumber3(Date.now())
|
|
46196
46180
|
});
|
|
46197
46181
|
}
|
|
46198
46182
|
});
|
|
@@ -46233,12 +46217,12 @@ function getAssetWeight(params) {
|
|
|
46233
46217
|
activeEmodeWeights,
|
|
46234
46218
|
ignoreSoftLimits
|
|
46235
46219
|
} = params;
|
|
46236
|
-
const assetWeightInit =
|
|
46237
|
-
activeEmodeWeights?.assetWeightInit ??
|
|
46220
|
+
const assetWeightInit = BigNumber3.max(
|
|
46221
|
+
activeEmodeWeights?.assetWeightInit ?? BigNumber3(0),
|
|
46238
46222
|
bank.config.assetWeightInit
|
|
46239
46223
|
);
|
|
46240
|
-
const assetWeightMaint =
|
|
46241
|
-
activeEmodeWeights?.assetWeightMaint ??
|
|
46224
|
+
const assetWeightMaint = BigNumber3.max(
|
|
46225
|
+
activeEmodeWeights?.assetWeightMaint ?? BigNumber3(0),
|
|
46242
46226
|
bank.config.assetWeightMaint
|
|
46243
46227
|
);
|
|
46244
46228
|
switch (marginRequirement) {
|
|
@@ -46262,7 +46246,7 @@ function getAssetWeight(params) {
|
|
|
46262
46246
|
case 1 /* Maintenance */:
|
|
46263
46247
|
return assetWeightMaint;
|
|
46264
46248
|
case 2 /* Equity */:
|
|
46265
|
-
return new
|
|
46249
|
+
return new BigNumber3(1);
|
|
46266
46250
|
default:
|
|
46267
46251
|
throw new Error("Invalid margin requirement type");
|
|
46268
46252
|
}
|
|
@@ -46274,7 +46258,7 @@ function getLiabilityWeight(config, marginRequirementType) {
|
|
|
46274
46258
|
case 1 /* Maintenance */:
|
|
46275
46259
|
return config.liabilityWeightMaint;
|
|
46276
46260
|
case 2 /* Equity */:
|
|
46277
|
-
return new
|
|
46261
|
+
return new BigNumber3(1);
|
|
46278
46262
|
default:
|
|
46279
46263
|
throw new Error("Invalid margin requirement type");
|
|
46280
46264
|
}
|
|
@@ -46302,17 +46286,17 @@ function computeLoopingParams(principal, targetLeverage, depositBank, borrowBank
|
|
|
46302
46286
|
);
|
|
46303
46287
|
clampedLeverage = maxLeverage;
|
|
46304
46288
|
}
|
|
46305
|
-
const totalDepositAmount = initialCollateral.times(new
|
|
46289
|
+
const totalDepositAmount = initialCollateral.times(new BigNumber3(clampedLeverage));
|
|
46306
46290
|
const additionalDepositAmount = totalDepositAmount.minus(initialCollateral);
|
|
46307
46291
|
const totalBorrowAmount = additionalDepositAmount.times(depositOracleInfo.priceWeighted.lowestPrice).div(borrowOracleInfo.priceWeighted.highestPrice);
|
|
46308
46292
|
return {
|
|
46309
46293
|
totalBorrowAmount: totalBorrowAmount.decimalPlaces(
|
|
46310
46294
|
borrowBank.mintDecimals,
|
|
46311
|
-
|
|
46295
|
+
BigNumber3.ROUND_DOWN
|
|
46312
46296
|
),
|
|
46313
46297
|
totalDepositAmount: totalDepositAmount.decimalPlaces(
|
|
46314
46298
|
depositBank.mintDecimals,
|
|
46315
|
-
|
|
46299
|
+
BigNumber3.ROUND_DOWN
|
|
46316
46300
|
)
|
|
46317
46301
|
};
|
|
46318
46302
|
}
|
|
@@ -46323,7 +46307,7 @@ function computeUsdValue(params) {
|
|
|
46323
46307
|
quantity,
|
|
46324
46308
|
priceBias,
|
|
46325
46309
|
isWeightedPrice: isWeightedPrice2,
|
|
46326
|
-
weight = new
|
|
46310
|
+
weight = new BigNumber3(1),
|
|
46327
46311
|
scaleToBase = true,
|
|
46328
46312
|
assetShareValueMultiplier
|
|
46329
46313
|
} = params;
|
|
@@ -46458,16 +46442,16 @@ function computeInterestRates(bank) {
|
|
|
46458
46442
|
const baseInterestRate = computeBaseInterestRate(bank);
|
|
46459
46443
|
const utilizationRate = computeUtilizationRate(bank);
|
|
46460
46444
|
const lendingRate = baseInterestRate.times(utilizationRate);
|
|
46461
|
-
const borrowingRate = baseInterestRate.times(new
|
|
46445
|
+
const borrowingRate = baseInterestRate.times(new BigNumber3(1).plus(rateFee)).plus(fixedFee);
|
|
46462
46446
|
return { lendingRate, borrowingRate };
|
|
46463
46447
|
}
|
|
46464
46448
|
var U32_MAX = 4294967295;
|
|
46465
46449
|
function rateFromU32(rate) {
|
|
46466
|
-
const ratio = new
|
|
46450
|
+
const ratio = new BigNumber3(rate).div(U32_MAX);
|
|
46467
46451
|
return ratio.times(10);
|
|
46468
46452
|
}
|
|
46469
46453
|
function utilFromU32(util) {
|
|
46470
|
-
return new
|
|
46454
|
+
return new BigNumber3(util).div(U32_MAX);
|
|
46471
46455
|
}
|
|
46472
46456
|
function calculateRateBetweenPoints(startX, startY, endX, endY, targetX) {
|
|
46473
46457
|
if (endX.lte(startX)) return startY;
|
|
@@ -46486,15 +46470,15 @@ function computeLegacyCurve(utilizationRate, optimalUtilizationRate, plateauInte
|
|
|
46486
46470
|
if (utilizationRate.lte(optimalUtilizationRate)) {
|
|
46487
46471
|
return utilizationRate.times(plateauInterestRate).div(optimalUtilizationRate);
|
|
46488
46472
|
} else {
|
|
46489
|
-
return utilizationRate.minus(optimalUtilizationRate).div(new
|
|
46473
|
+
return utilizationRate.minus(optimalUtilizationRate).div(new BigNumber3(1).minus(optimalUtilizationRate)).times(maxInterestRate.minus(plateauInterestRate)).plus(plateauInterestRate);
|
|
46490
46474
|
}
|
|
46491
46475
|
}
|
|
46492
46476
|
function computeMultipointCurve(utilizationRate, zeroUtilRate, hundredUtilRate, points) {
|
|
46493
46477
|
const zeroRate = rateFromU32(zeroUtilRate);
|
|
46494
46478
|
const hundredRate = rateFromU32(hundredUtilRate);
|
|
46495
|
-
const clampedUtilizationRate =
|
|
46479
|
+
const clampedUtilizationRate = BigNumber3.max(0, BigNumber3.min(1, utilizationRate));
|
|
46496
46480
|
const nonPaddingPoints = points.filter((point) => point.util !== 0);
|
|
46497
|
-
let prevUtil = new
|
|
46481
|
+
let prevUtil = new BigNumber3(0);
|
|
46498
46482
|
let prevRate = zeroRate;
|
|
46499
46483
|
for (const point of nonPaddingPoints) {
|
|
46500
46484
|
const pointUtil = utilFromU32(point.util);
|
|
@@ -46514,7 +46498,7 @@ function computeMultipointCurve(utilizationRate, zeroUtilRate, hundredUtilRate,
|
|
|
46514
46498
|
return calculateRateBetweenPoints(
|
|
46515
46499
|
prevUtil,
|
|
46516
46500
|
prevRate,
|
|
46517
|
-
new
|
|
46501
|
+
new BigNumber3(1),
|
|
46518
46502
|
hundredRate,
|
|
46519
46503
|
clampedUtilizationRate
|
|
46520
46504
|
);
|
|
@@ -46542,16 +46526,16 @@ function computeBaseInterestRate(bank) {
|
|
|
46542
46526
|
function computeUtilizationRate(bank) {
|
|
46543
46527
|
const assets = getTotalAssetQuantity(bank);
|
|
46544
46528
|
const liabilities = getTotalLiabilityQuantity(bank);
|
|
46545
|
-
if (assets.isZero()) return new
|
|
46529
|
+
if (assets.isZero()) return new BigNumber3(0);
|
|
46546
46530
|
return liabilities.div(assets);
|
|
46547
46531
|
}
|
|
46548
46532
|
var SECONDS_PER_DAY = 24 * 60 * 60;
|
|
46549
46533
|
var SECONDS_PER_YEAR = SECONDS_PER_DAY * 365.25;
|
|
46550
46534
|
function computeRemainingCapacity(bank) {
|
|
46551
46535
|
const totalDeposits = getTotalAssetQuantity(bank);
|
|
46552
|
-
const remainingCapacity =
|
|
46536
|
+
const remainingCapacity = BigNumber3.max(0, bank.config.depositLimit.minus(totalDeposits));
|
|
46553
46537
|
const totalBorrows = getTotalLiabilityQuantity(bank);
|
|
46554
|
-
const remainingBorrowCapacity =
|
|
46538
|
+
const remainingBorrowCapacity = BigNumber3.max(0, bank.config.borrowLimit.minus(totalBorrows));
|
|
46555
46539
|
const durationSinceLastAccrual = Date.now() / 1e3 - bank.lastUpdate;
|
|
46556
46540
|
const { lendingRate, borrowingRate } = computeInterestRates(bank);
|
|
46557
46541
|
const outstandingLendingInterest = lendingRate.times(durationSinceLastAccrual).dividedBy(SECONDS_PER_YEAR).times(totalDeposits);
|
|
@@ -47056,7 +47040,7 @@ async function getKaminoStatesDto(connection, kaminoBanks) {
|
|
|
47056
47040
|
}
|
|
47057
47041
|
function getKaminoCTokenMultiplier(reserve) {
|
|
47058
47042
|
const [totalLiquidity, totalCollateral] = scaledSupplies(reserve);
|
|
47059
|
-
return totalCollateral.isZero() ? new
|
|
47043
|
+
return totalCollateral.isZero() ? new BigNumber3(1) : new BigNumber3(totalLiquidity.dividedBy(totalCollateral).toString());
|
|
47060
47044
|
}
|
|
47061
47045
|
async function getDriftMetadata(options) {
|
|
47062
47046
|
const driftBanks = options.banks.filter((b) => b.config.assetTag === 4 /* DRIFT */);
|
|
@@ -47085,9 +47069,9 @@ async function getDriftMetadata(options) {
|
|
|
47085
47069
|
for (const [bankAddress, state] of Object.entries(driftStates)) {
|
|
47086
47070
|
driftMetadataMap.set(bankAddress, {
|
|
47087
47071
|
driftStates: {
|
|
47088
|
-
|
|
47089
|
-
|
|
47090
|
-
|
|
47072
|
+
spotMarketState: dtoToDriftSpotMarketRaw(state.driftSpotMarketState),
|
|
47073
|
+
userState: dtoToDriftUserRaw(state.driftUserState),
|
|
47074
|
+
userRewards: state.driftUserRewards.map((r) => dtoToDriftRewardsRaw(r))
|
|
47091
47075
|
}
|
|
47092
47076
|
});
|
|
47093
47077
|
}
|
|
@@ -47149,8 +47133,8 @@ async function getDriftStatesDto(connection, driftBanks) {
|
|
|
47149
47133
|
return driftStatesMap;
|
|
47150
47134
|
}
|
|
47151
47135
|
function getDriftCTokenMultiplier(spotMarket) {
|
|
47152
|
-
const cumulativeDepositInterest = new
|
|
47153
|
-
const SPOT_BALANCE_PRECISION = new
|
|
47136
|
+
const cumulativeDepositInterest = new BigNumber3(spotMarket.cumulativeDepositInterest.toNumber());
|
|
47137
|
+
const SPOT_BALANCE_PRECISION = new BigNumber3(10).pow(19 - spotMarket.decimals);
|
|
47154
47138
|
return cumulativeDepositInterest.dividedBy(SPOT_BALANCE_PRECISION);
|
|
47155
47139
|
}
|
|
47156
47140
|
|
|
@@ -47343,11 +47327,11 @@ var Bank = class _Bank {
|
|
|
47343
47327
|
const newBank = Object.create(_Bank.prototype);
|
|
47344
47328
|
Object.assign(newBank, bank);
|
|
47345
47329
|
newBank.config = Object.assign({}, bank.config);
|
|
47346
|
-
newBank.config.assetWeightInit =
|
|
47330
|
+
newBank.config.assetWeightInit = BigNumber3.max(
|
|
47347
47331
|
bank.config.assetWeightInit,
|
|
47348
47332
|
emodeWeights.assetWeightInit
|
|
47349
47333
|
);
|
|
47350
|
-
newBank.config.assetWeightMaint =
|
|
47334
|
+
newBank.config.assetWeightMaint = BigNumber3.max(
|
|
47351
47335
|
bank.config.assetWeightMaint,
|
|
47352
47336
|
emodeWeights.assetWeightMaint
|
|
47353
47337
|
);
|
|
@@ -48206,9 +48190,9 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48206
48190
|
*
|
|
48207
48191
|
* @see {@link makeWrapSolIxs} and {@link makeUnwrapSolIx} for wrap/unwrap implementation
|
|
48208
48192
|
*/
|
|
48209
|
-
wrapInstructionForWSol(ix, amount = new
|
|
48193
|
+
wrapInstructionForWSol(ix, amount = new BigNumber3(0)) {
|
|
48210
48194
|
return [
|
|
48211
|
-
...makeWrapSolIxs(this.authority, new
|
|
48195
|
+
...makeWrapSolIxs(this.authority, new BigNumber3(amount)),
|
|
48212
48196
|
ix,
|
|
48213
48197
|
makeUnwrapSolIx(this.authority)
|
|
48214
48198
|
];
|
|
@@ -48244,7 +48228,12 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48244
48228
|
async makeLoopTx(params) {
|
|
48245
48229
|
return makeLoopTx({
|
|
48246
48230
|
...params,
|
|
48247
|
-
marginfiAccount: this
|
|
48231
|
+
marginfiAccount: this,
|
|
48232
|
+
overrideInferAccounts: {
|
|
48233
|
+
authority: this.authority,
|
|
48234
|
+
group: this.group,
|
|
48235
|
+
...params.overrideInferAccounts
|
|
48236
|
+
}
|
|
48248
48237
|
});
|
|
48249
48238
|
}
|
|
48250
48239
|
/**
|
|
@@ -48278,7 +48267,12 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48278
48267
|
async makeRepayWithCollatTx(params) {
|
|
48279
48268
|
return makeRepayWithCollatTx({
|
|
48280
48269
|
...params,
|
|
48281
|
-
marginfiAccount: this
|
|
48270
|
+
marginfiAccount: this,
|
|
48271
|
+
overrideInferAccounts: {
|
|
48272
|
+
authority: this.authority,
|
|
48273
|
+
group: this.group,
|
|
48274
|
+
...params.overrideInferAccounts
|
|
48275
|
+
}
|
|
48282
48276
|
});
|
|
48283
48277
|
}
|
|
48284
48278
|
/**
|
|
@@ -48313,7 +48307,12 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48313
48307
|
async makeSwapCollateralTx(params) {
|
|
48314
48308
|
return makeSwapCollateralTx({
|
|
48315
48309
|
...params,
|
|
48316
|
-
marginfiAccount: this
|
|
48310
|
+
marginfiAccount: this,
|
|
48311
|
+
overrideInferAccounts: {
|
|
48312
|
+
authority: this.authority,
|
|
48313
|
+
group: this.group,
|
|
48314
|
+
...params.overrideInferAccounts
|
|
48315
|
+
}
|
|
48317
48316
|
});
|
|
48318
48317
|
}
|
|
48319
48318
|
/**
|
|
@@ -48347,7 +48346,12 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48347
48346
|
async makeSwapDebtTx(params) {
|
|
48348
48347
|
return makeSwapDebtTx({
|
|
48349
48348
|
...params,
|
|
48350
|
-
marginfiAccount: this
|
|
48349
|
+
marginfiAccount: this,
|
|
48350
|
+
overrideInferAccounts: {
|
|
48351
|
+
authority: this.authority,
|
|
48352
|
+
group: this.group,
|
|
48353
|
+
...params.overrideInferAccounts
|
|
48354
|
+
}
|
|
48351
48355
|
});
|
|
48352
48356
|
}
|
|
48353
48357
|
/**
|
|
@@ -48409,7 +48413,14 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48409
48413
|
async makeBorrowTx(params) {
|
|
48410
48414
|
return makeBorrowTx({
|
|
48411
48415
|
...params,
|
|
48412
|
-
marginfiAccount: this
|
|
48416
|
+
marginfiAccount: this,
|
|
48417
|
+
opts: {
|
|
48418
|
+
...params.opts,
|
|
48419
|
+
overrideInferAccounts: {
|
|
48420
|
+
authority: this.authority,
|
|
48421
|
+
...params.opts?.overrideInferAccounts
|
|
48422
|
+
}
|
|
48423
|
+
}
|
|
48413
48424
|
});
|
|
48414
48425
|
}
|
|
48415
48426
|
/**
|
|
@@ -48438,7 +48449,15 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48438
48449
|
async makeWithdrawTx(params) {
|
|
48439
48450
|
return makeWithdrawTx({
|
|
48440
48451
|
...params,
|
|
48441
|
-
marginfiAccount: this
|
|
48452
|
+
marginfiAccount: this,
|
|
48453
|
+
opts: {
|
|
48454
|
+
...params.opts,
|
|
48455
|
+
overrideInferAccounts: {
|
|
48456
|
+
authority: this.authority,
|
|
48457
|
+
group: this.group,
|
|
48458
|
+
...params.opts?.overrideInferAccounts
|
|
48459
|
+
}
|
|
48460
|
+
}
|
|
48442
48461
|
});
|
|
48443
48462
|
}
|
|
48444
48463
|
/**
|
|
@@ -48452,7 +48471,15 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48452
48471
|
async makeDriftWithdrawTx(params) {
|
|
48453
48472
|
return makeDriftWithdrawTx({
|
|
48454
48473
|
...params,
|
|
48455
|
-
marginfiAccount: this
|
|
48474
|
+
marginfiAccount: this,
|
|
48475
|
+
opts: {
|
|
48476
|
+
...params.opts,
|
|
48477
|
+
overrideInferAccounts: {
|
|
48478
|
+
authority: this.authority,
|
|
48479
|
+
group: this.group,
|
|
48480
|
+
...params.opts?.overrideInferAccounts
|
|
48481
|
+
}
|
|
48482
|
+
}
|
|
48456
48483
|
});
|
|
48457
48484
|
}
|
|
48458
48485
|
/**
|
|
@@ -48466,7 +48493,15 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48466
48493
|
async makeKaminoWithdrawTx(params) {
|
|
48467
48494
|
return makeKaminoWithdrawTx({
|
|
48468
48495
|
...params,
|
|
48469
|
-
marginfiAccount: this
|
|
48496
|
+
marginfiAccount: this,
|
|
48497
|
+
opts: {
|
|
48498
|
+
...params.opts,
|
|
48499
|
+
overrideInferAccounts: {
|
|
48500
|
+
authority: this.authority,
|
|
48501
|
+
group: this.group,
|
|
48502
|
+
...params.opts?.overrideInferAccounts
|
|
48503
|
+
}
|
|
48504
|
+
}
|
|
48470
48505
|
});
|
|
48471
48506
|
}
|
|
48472
48507
|
/**
|
|
@@ -48581,7 +48616,7 @@ var MarginfiAccountWrapper = class {
|
|
|
48581
48616
|
* @param opts - Optional configuration for wrapping SOL and overrides
|
|
48582
48617
|
*/
|
|
48583
48618
|
async makeDepositIx(bankAddress, amount, opts = {}) {
|
|
48584
|
-
if (new
|
|
48619
|
+
if (new BigNumber3(amount).lte(0)) {
|
|
48585
48620
|
throw Error(`Deposit amount must be positive, got ${amount}`);
|
|
48586
48621
|
}
|
|
48587
48622
|
const bank = await this.getBankFromAddress(bankAddress);
|
|
@@ -48605,7 +48640,7 @@ var MarginfiAccountWrapper = class {
|
|
|
48605
48640
|
* @param opts - Optional configuration for wrapping SOL and overrides
|
|
48606
48641
|
*/
|
|
48607
48642
|
async makeRepayIx(bankAddress, amount, repayAll = false, opts = {}) {
|
|
48608
|
-
if (!repayAll && new
|
|
48643
|
+
if (!repayAll && new BigNumber3(amount).lte(0)) {
|
|
48609
48644
|
throw Error(`Repay amount must be positive, got ${amount}`);
|
|
48610
48645
|
}
|
|
48611
48646
|
const bank = await this.getBankFromAddress(bankAddress);
|
|
@@ -48630,7 +48665,7 @@ var MarginfiAccountWrapper = class {
|
|
|
48630
48665
|
* @param opts - Optional configuration for unwrapping SOL and overrides
|
|
48631
48666
|
*/
|
|
48632
48667
|
async makeWithdrawIx(bankAddress, amount, withdrawAll = false, opts = {}) {
|
|
48633
|
-
if (!withdrawAll && new
|
|
48668
|
+
if (!withdrawAll && new BigNumber3(amount).lte(0)) {
|
|
48634
48669
|
throw Error(`Withdraw amount must be positive, got ${amount}`);
|
|
48635
48670
|
}
|
|
48636
48671
|
const bank = await this.getBankFromAddress(bankAddress);
|
|
@@ -48656,7 +48691,7 @@ var MarginfiAccountWrapper = class {
|
|
|
48656
48691
|
* @param opts - Optional configuration for unwrapping SOL and overrides
|
|
48657
48692
|
*/
|
|
48658
48693
|
async makeBorrowIx(bankAddress, amount, opts = {}) {
|
|
48659
|
-
if (new
|
|
48694
|
+
if (new BigNumber3(amount).lte(0)) {
|
|
48660
48695
|
throw Error(`Borrow amount must be positive, got ${amount}`);
|
|
48661
48696
|
}
|
|
48662
48697
|
const bank = await this.getBankFromAddress(bankAddress);
|
|
@@ -49415,7 +49450,7 @@ var Project0Client = class _Project0Client {
|
|
|
49415
49450
|
const reserve = bankIntegrationMap[bank.address.toBase58()]?.kaminoStates?.reserveState;
|
|
49416
49451
|
if (!reserve) {
|
|
49417
49452
|
console.error(`No Kamino reserve found for bank ${bank.address.toBase58()}`);
|
|
49418
|
-
assetShareMultiplierByBank.set(bank.address.toBase58(), new
|
|
49453
|
+
assetShareMultiplierByBank.set(bank.address.toBase58(), new BigNumber3(1));
|
|
49419
49454
|
break;
|
|
49420
49455
|
}
|
|
49421
49456
|
assetShareMultiplierByBank.set(
|
|
@@ -49427,7 +49462,7 @@ var Project0Client = class _Project0Client {
|
|
|
49427
49462
|
const spotMarket = bankIntegrationMap[bank.address.toBase58()]?.driftStates?.spotMarketState;
|
|
49428
49463
|
if (!spotMarket) {
|
|
49429
49464
|
console.error(`No Drift spot market found for bank ${bank.address.toBase58()}`);
|
|
49430
|
-
assetShareMultiplierByBank.set(bank.address.toBase58(), new
|
|
49465
|
+
assetShareMultiplierByBank.set(bank.address.toBase58(), new BigNumber3(1));
|
|
49431
49466
|
break;
|
|
49432
49467
|
}
|
|
49433
49468
|
assetShareMultiplierByBank.set(
|
|
@@ -49436,15 +49471,15 @@ var Project0Client = class _Project0Client {
|
|
|
49436
49471
|
);
|
|
49437
49472
|
break;
|
|
49438
49473
|
case 5 /* SOLEND */:
|
|
49439
|
-
assetShareMultiplierByBank.set(bank.address.toBase58(), new
|
|
49474
|
+
assetShareMultiplierByBank.set(bank.address.toBase58(), new BigNumber3(1));
|
|
49440
49475
|
break;
|
|
49441
49476
|
case 2 /* STAKED */:
|
|
49442
|
-
assetShareMultiplierByBank.set(bank.address.toBase58(), new
|
|
49477
|
+
assetShareMultiplierByBank.set(bank.address.toBase58(), new BigNumber3(1));
|
|
49443
49478
|
break;
|
|
49444
49479
|
case 0 /* DEFAULT */:
|
|
49445
49480
|
case 1 /* SOL */:
|
|
49446
49481
|
default:
|
|
49447
|
-
assetShareMultiplierByBank.set(bank.address.toBase58(), new
|
|
49482
|
+
assetShareMultiplierByBank.set(bank.address.toBase58(), new BigNumber3(1));
|
|
49448
49483
|
break;
|
|
49449
49484
|
}
|
|
49450
49485
|
});
|