@0dotxyz/p0-ts-sdk 2.0.0 → 2.0.2
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 +296 -260
- 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 +295 -259
- 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 +22 -25
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var web3_js = require('@solana/web3.js');
|
|
4
4
|
var superstruct = require('superstruct');
|
|
5
|
-
var
|
|
5
|
+
var BigNumber3 = require('bignumber.js');
|
|
6
6
|
var BN11 = require('bn.js');
|
|
7
7
|
var Decimal3 = require('decimal.js');
|
|
8
8
|
var anchor = require('@coral-xyz/anchor');
|
|
@@ -35,7 +35,7 @@ function _interopNamespace(e) {
|
|
|
35
35
|
return Object.freeze(n);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
var
|
|
38
|
+
var BigNumber3__default = /*#__PURE__*/_interopDefault(BigNumber3);
|
|
39
39
|
var BN11__default = /*#__PURE__*/_interopDefault(BN11);
|
|
40
40
|
var Decimal3__default = /*#__PURE__*/_interopDefault(Decimal3);
|
|
41
41
|
var borsh__namespace = /*#__PURE__*/_interopNamespace(borsh);
|
|
@@ -268,9 +268,9 @@ var PYTH_SPONSORED_SHARD_ID = 0;
|
|
|
268
268
|
var MARGINFI_SPONSORED_SHARD_ID = 3301;
|
|
269
269
|
var DEFAULT_ORACLE_MAX_AGE = 60;
|
|
270
270
|
var ZERO_ORACLE_KEY = "DMhGWtLAKE5d56WdyHQxqeFncwUeqMEnuC2RvvZfbuur";
|
|
271
|
-
var PYTH_PRICE_CONF_INTERVALS = new
|
|
272
|
-
var SWB_PRICE_CONF_INTERVALS = new
|
|
273
|
-
var MAX_CONFIDENCE_INTERVAL_RATIO = new
|
|
271
|
+
var PYTH_PRICE_CONF_INTERVALS = new BigNumber3__default.default(2.12);
|
|
272
|
+
var SWB_PRICE_CONF_INTERVALS = new BigNumber3__default.default(1.96);
|
|
273
|
+
var MAX_CONFIDENCE_INTERVAL_RATIO = new BigNumber3__default.default(0.05);
|
|
274
274
|
var DISABLED_FLAG = 1 << 0;
|
|
275
275
|
var FLASHLOAN_ENABLED_FLAG = 1 << 2;
|
|
276
276
|
var TRANSFER_ACCOUNT_AUTHORITY_FLAG = 1 << 3;
|
|
@@ -285,7 +285,8 @@ var ADDRESS_LOOKUP_TABLE_FOR_GROUP = {
|
|
|
285
285
|
"4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8": [
|
|
286
286
|
new web3_js.PublicKey("BrWF8J3CEuHaXsWk3kqGZ6VHvRp4SJuG9AzvB6ei2kbV"),
|
|
287
287
|
new web3_js.PublicKey("8GLUprtyzv6HGrgox7F43EQM5GqE2uKrAHLs69r8DgRj"),
|
|
288
|
-
new web3_js.PublicKey("Eg4WY6fmrbhDGfdgSrrTUe6peoUeVhkdXAWT6uvcGKjs")
|
|
288
|
+
new web3_js.PublicKey("Eg4WY6fmrbhDGfdgSrrTUe6peoUeVhkdXAWT6uvcGKjs"),
|
|
289
|
+
new web3_js.PublicKey("qmH8NYYdHkbLYwAdAwnrqiPdBvayjn3DQwRUi9MoXX4")
|
|
289
290
|
],
|
|
290
291
|
// Main pool
|
|
291
292
|
FCPfpHA69EbS8f9KKSreTRkXbzFpunsKuYf5qNmnJjpo: [
|
|
@@ -363,7 +364,7 @@ function wrappedI80F48toBigNumber(wrapped) {
|
|
|
363
364
|
}
|
|
364
365
|
let hex = signChar + "0x" + bytesBE.map((v) => v.toString(16).padStart(2, "0")).join("");
|
|
365
366
|
let decoded = new Decimal3.Decimal(hex).dividedBy(I80F48_DIVISOR);
|
|
366
|
-
return new
|
|
367
|
+
return new BigNumber3__default.default(decoded.toString());
|
|
367
368
|
}
|
|
368
369
|
function bigNumberToWrappedI80F48(value) {
|
|
369
370
|
let decimalValue = new Decimal3.Decimal(value.toString());
|
|
@@ -394,16 +395,16 @@ function toNumber(amount) {
|
|
|
394
395
|
}
|
|
395
396
|
function toBigNumber(amount) {
|
|
396
397
|
let amt;
|
|
397
|
-
if (amount instanceof
|
|
398
|
+
if (amount instanceof BigNumber3__default.default) {
|
|
398
399
|
amt = amount;
|
|
399
400
|
} else {
|
|
400
|
-
amt = new
|
|
401
|
+
amt = new BigNumber3__default.default(amount.toString());
|
|
401
402
|
}
|
|
402
403
|
return amt;
|
|
403
404
|
}
|
|
404
405
|
function uiToNative(amount, decimals) {
|
|
405
406
|
let amt = toBigNumber(amount);
|
|
406
|
-
return new BN11__default.default(amt.times(10 ** decimals).toFixed(0,
|
|
407
|
+
return new BN11__default.default(amt.times(10 ** decimals).toFixed(0, BigNumber3__default.default.ROUND_FLOOR));
|
|
407
408
|
}
|
|
408
409
|
function uiToNativeBigNumber(amount, decimals) {
|
|
409
410
|
let amt = toBigNumber(amount);
|
|
@@ -13786,13 +13787,13 @@ function parseBankRaw(address, accountParsed, bankMetadata, mintData) {
|
|
|
13786
13787
|
const emissionsActiveLending = (flags & 2) > 0;
|
|
13787
13788
|
const emissionsRate = accountParsed.emissionsRate.toNumber();
|
|
13788
13789
|
const emissionsMint = accountParsed.emissionsMint;
|
|
13789
|
-
const emissionsRemaining = accountParsed.emissionsRemaining ? wrappedI80F48toBigNumber(accountParsed.emissionsRemaining) : new
|
|
13790
|
+
const emissionsRemaining = accountParsed.emissionsRemaining ? wrappedI80F48toBigNumber(accountParsed.emissionsRemaining) : new BigNumber3__default.default(0);
|
|
13790
13791
|
const { oracleKey } = { oracleKey: config.oracleKeys[0] };
|
|
13791
13792
|
const emode = parseEmodeSettingsRaw(accountParsed.emode);
|
|
13792
13793
|
const tokenSymbol = bankMetadata?.tokenSymbol;
|
|
13793
13794
|
const feesDestinationAccount = accountParsed.feesDestinationAccount;
|
|
13794
|
-
const lendingPositionCount = accountParsed.lendingPositionCount ? new
|
|
13795
|
-
const borrowingPositionCount = accountParsed.borrowingPositionCount ? new
|
|
13795
|
+
const lendingPositionCount = accountParsed.lendingPositionCount ? new BigNumber3__default.default(accountParsed.lendingPositionCount.toString()) : new BigNumber3__default.default(0);
|
|
13796
|
+
const borrowingPositionCount = accountParsed.borrowingPositionCount ? new BigNumber3__default.default(accountParsed.borrowingPositionCount.toString()) : new BigNumber3__default.default(0);
|
|
13796
13797
|
let kaminoIntegrationAccounts, driftIntegrationAccounts, solendIntegrationAccounts = void 0;
|
|
13797
13798
|
switch (config.assetTag) {
|
|
13798
13799
|
case 3 /* KAMINO */:
|
|
@@ -13861,34 +13862,34 @@ function dtoToBank(bankDto) {
|
|
|
13861
13862
|
group: new web3_js.PublicKey(bankDto.group),
|
|
13862
13863
|
mint: new web3_js.PublicKey(bankDto.mint),
|
|
13863
13864
|
mintDecimals: bankDto.mintDecimals,
|
|
13864
|
-
assetShareValue: new
|
|
13865
|
-
liabilityShareValue: new
|
|
13865
|
+
assetShareValue: new BigNumber3__default.default(bankDto.assetShareValue),
|
|
13866
|
+
liabilityShareValue: new BigNumber3__default.default(bankDto.liabilityShareValue),
|
|
13866
13867
|
liquidityVault: new web3_js.PublicKey(bankDto.liquidityVault),
|
|
13867
13868
|
liquidityVaultBump: bankDto.liquidityVaultBump,
|
|
13868
13869
|
liquidityVaultAuthorityBump: bankDto.liquidityVaultAuthorityBump,
|
|
13869
13870
|
insuranceVault: new web3_js.PublicKey(bankDto.insuranceVault),
|
|
13870
13871
|
insuranceVaultBump: bankDto.insuranceVaultBump,
|
|
13871
13872
|
insuranceVaultAuthorityBump: bankDto.insuranceVaultAuthorityBump,
|
|
13872
|
-
collectedInsuranceFeesOutstanding: new
|
|
13873
|
+
collectedInsuranceFeesOutstanding: new BigNumber3__default.default(bankDto.collectedInsuranceFeesOutstanding),
|
|
13873
13874
|
feeVault: new web3_js.PublicKey(bankDto.feeVault),
|
|
13874
13875
|
feeVaultBump: bankDto.feeVaultBump,
|
|
13875
13876
|
feeVaultAuthorityBump: bankDto.feeVaultAuthorityBump,
|
|
13876
|
-
collectedGroupFeesOutstanding: new
|
|
13877
|
+
collectedGroupFeesOutstanding: new BigNumber3__default.default(bankDto.collectedGroupFeesOutstanding),
|
|
13877
13878
|
lastUpdate: bankDto.lastUpdate,
|
|
13878
13879
|
config: dtoToBankConfig(bankDto.config),
|
|
13879
|
-
totalAssetShares: new
|
|
13880
|
-
totalLiabilityShares: new
|
|
13880
|
+
totalAssetShares: new BigNumber3__default.default(bankDto.totalAssetShares),
|
|
13881
|
+
totalLiabilityShares: new BigNumber3__default.default(bankDto.totalLiabilityShares),
|
|
13881
13882
|
emissionsActiveBorrowing: bankDto.emissionsActiveBorrowing,
|
|
13882
13883
|
emissionsActiveLending: bankDto.emissionsActiveLending,
|
|
13883
13884
|
emissionsRate: bankDto.emissionsRate,
|
|
13884
13885
|
emissionsMint: new web3_js.PublicKey(bankDto.emissionsMint),
|
|
13885
|
-
emissionsRemaining: new
|
|
13886
|
+
emissionsRemaining: new BigNumber3__default.default(bankDto.emissionsRemaining),
|
|
13886
13887
|
oracleKey: new web3_js.PublicKey(bankDto.oracleKey),
|
|
13887
13888
|
emode: dtoToEmodeSettings(bankDto.emode),
|
|
13888
13889
|
tokenSymbol: bankDto.tokenSymbol,
|
|
13889
13890
|
feesDestinationAccount: bankDto.feesDestinationAccount ? new web3_js.PublicKey(bankDto.feesDestinationAccount) : void 0,
|
|
13890
|
-
lendingPositionCount: bankDto.lendingPositionCount ? new
|
|
13891
|
-
borrowingPositionCount: bankDto.borrowingPositionCount ? new
|
|
13891
|
+
lendingPositionCount: bankDto.lendingPositionCount ? new BigNumber3__default.default(bankDto.lendingPositionCount) : void 0,
|
|
13892
|
+
borrowingPositionCount: bankDto.borrowingPositionCount ? new BigNumber3__default.default(bankDto.borrowingPositionCount) : void 0,
|
|
13892
13893
|
mintRate: null,
|
|
13893
13894
|
// TODO: move these out
|
|
13894
13895
|
mintPrice: 0,
|
|
@@ -13916,23 +13917,23 @@ function dtoToEmodeSettings(emodeSettingsDto) {
|
|
|
13916
13917
|
return {
|
|
13917
13918
|
collateralBankEmodeTag: entry.collateralBankEmodeTag,
|
|
13918
13919
|
flags: entry.flags,
|
|
13919
|
-
assetWeightInit: new
|
|
13920
|
-
assetWeightMaint: new
|
|
13920
|
+
assetWeightInit: new BigNumber3__default.default(entry.assetWeightInit),
|
|
13921
|
+
assetWeightMaint: new BigNumber3__default.default(entry.assetWeightMaint)
|
|
13921
13922
|
};
|
|
13922
13923
|
})
|
|
13923
13924
|
};
|
|
13924
13925
|
}
|
|
13925
13926
|
function dtoToBankConfig(bankConfigDto) {
|
|
13926
13927
|
return {
|
|
13927
|
-
assetWeightInit: new
|
|
13928
|
-
assetWeightMaint: new
|
|
13929
|
-
liabilityWeightInit: new
|
|
13930
|
-
liabilityWeightMaint: new
|
|
13931
|
-
depositLimit: new
|
|
13932
|
-
borrowLimit: new
|
|
13928
|
+
assetWeightInit: new BigNumber3__default.default(bankConfigDto.assetWeightInit),
|
|
13929
|
+
assetWeightMaint: new BigNumber3__default.default(bankConfigDto.assetWeightMaint),
|
|
13930
|
+
liabilityWeightInit: new BigNumber3__default.default(bankConfigDto.liabilityWeightInit),
|
|
13931
|
+
liabilityWeightMaint: new BigNumber3__default.default(bankConfigDto.liabilityWeightMaint),
|
|
13932
|
+
depositLimit: new BigNumber3__default.default(bankConfigDto.depositLimit),
|
|
13933
|
+
borrowLimit: new BigNumber3__default.default(bankConfigDto.borrowLimit),
|
|
13933
13934
|
riskTier: bankConfigDto.riskTier,
|
|
13934
13935
|
operationalState: bankConfigDto.operationalState,
|
|
13935
|
-
totalAssetValueInitLimit: new
|
|
13936
|
+
totalAssetValueInitLimit: new BigNumber3__default.default(bankConfigDto.totalAssetValueInitLimit),
|
|
13936
13937
|
assetTag: bankConfigDto.assetTag,
|
|
13937
13938
|
configFlags: bankConfigDto.configFlags,
|
|
13938
13939
|
oracleSetup: bankConfigDto.oracleSetup,
|
|
@@ -13940,19 +13941,19 @@ function dtoToBankConfig(bankConfigDto) {
|
|
|
13940
13941
|
oracleMaxAge: bankConfigDto.oracleMaxAge,
|
|
13941
13942
|
interestRateConfig: dtoToInterestRateConfig(bankConfigDto.interestRateConfig),
|
|
13942
13943
|
oracleMaxConfidence: bankConfigDto.oracleMaxConfidence,
|
|
13943
|
-
fixedPrice: new
|
|
13944
|
+
fixedPrice: new BigNumber3__default.default(bankConfigDto.fixedPrice)
|
|
13944
13945
|
};
|
|
13945
13946
|
}
|
|
13946
13947
|
function dtoToInterestRateConfig(interestRateConfigDto) {
|
|
13947
13948
|
return {
|
|
13948
|
-
optimalUtilizationRate: new
|
|
13949
|
-
plateauInterestRate: new
|
|
13950
|
-
maxInterestRate: new
|
|
13951
|
-
insuranceFeeFixedApr: new
|
|
13952
|
-
insuranceIrFee: new
|
|
13953
|
-
protocolFixedFeeApr: new
|
|
13954
|
-
protocolIrFee: new
|
|
13955
|
-
protocolOriginationFee: new
|
|
13949
|
+
optimalUtilizationRate: new BigNumber3__default.default(interestRateConfigDto.optimalUtilizationRate),
|
|
13950
|
+
plateauInterestRate: new BigNumber3__default.default(interestRateConfigDto.plateauInterestRate),
|
|
13951
|
+
maxInterestRate: new BigNumber3__default.default(interestRateConfigDto.maxInterestRate),
|
|
13952
|
+
insuranceFeeFixedApr: new BigNumber3__default.default(interestRateConfigDto.insuranceFeeFixedApr),
|
|
13953
|
+
insuranceIrFee: new BigNumber3__default.default(interestRateConfigDto.insuranceIrFee),
|
|
13954
|
+
protocolFixedFeeApr: new BigNumber3__default.default(interestRateConfigDto.protocolFixedFeeApr),
|
|
13955
|
+
protocolIrFee: new BigNumber3__default.default(interestRateConfigDto.protocolIrFee),
|
|
13956
|
+
protocolOriginationFee: new BigNumber3__default.default(interestRateConfigDto.protocolOriginationFee),
|
|
13956
13957
|
zeroUtilRate: interestRateConfigDto.zeroUtilRate,
|
|
13957
13958
|
hundredUtilRate: interestRateConfigDto.hundredUtilRate,
|
|
13958
13959
|
points: interestRateConfigDto.points,
|
|
@@ -14037,11 +14038,11 @@ function parseBankConfigRaw(bankConfigRaw) {
|
|
|
14037
14038
|
const assetWeightMaint = wrappedI80F48toBigNumber(bankConfigRaw.assetWeightMaint);
|
|
14038
14039
|
const liabilityWeightInit = wrappedI80F48toBigNumber(bankConfigRaw.liabilityWeightInit);
|
|
14039
14040
|
const liabilityWeightMaint = wrappedI80F48toBigNumber(bankConfigRaw.liabilityWeightMaint);
|
|
14040
|
-
const depositLimit =
|
|
14041
|
-
const borrowLimit =
|
|
14041
|
+
const depositLimit = BigNumber3__default.default(bankConfigRaw.depositLimit.toString());
|
|
14042
|
+
const borrowLimit = BigNumber3__default.default(bankConfigRaw.borrowLimit.toString());
|
|
14042
14043
|
const riskTier = parseRiskTier(bankConfigRaw.riskTier);
|
|
14043
14044
|
const operationalState = parseOperationalState(bankConfigRaw.operationalState);
|
|
14044
|
-
const totalAssetValueInitLimit =
|
|
14045
|
+
const totalAssetValueInitLimit = BigNumber3__default.default(bankConfigRaw.totalAssetValueInitLimit.toString());
|
|
14045
14046
|
const assetTag = bankConfigRaw.assetTag;
|
|
14046
14047
|
const configFlags = bankConfigRaw.configFlags;
|
|
14047
14048
|
const oracleSetup = parseOracleSetup(bankConfigRaw.oracleSetup);
|
|
@@ -14213,13 +14214,13 @@ function getLiabilityQuantity(bank, liabilityShares) {
|
|
|
14213
14214
|
}
|
|
14214
14215
|
function getAssetShares(bank, assetQuantity) {
|
|
14215
14216
|
if (bank.assetShareValue.isZero()) {
|
|
14216
|
-
return new
|
|
14217
|
+
return new BigNumber3__default.default(0);
|
|
14217
14218
|
}
|
|
14218
14219
|
return assetQuantity.div(bank.assetShareValue);
|
|
14219
14220
|
}
|
|
14220
14221
|
function getLiabilityShares(bank, liabilityQuantity) {
|
|
14221
14222
|
if (bank.liabilityShareValue.isZero()) {
|
|
14222
|
-
return new
|
|
14223
|
+
return new BigNumber3__default.default(0);
|
|
14223
14224
|
}
|
|
14224
14225
|
return liabilityQuantity.div(bank.liabilityShareValue);
|
|
14225
14226
|
}
|
|
@@ -17187,8 +17188,8 @@ var mapBrokenFeedsToOraclePrices = (banks, swbOracleAiDataByKey, birdeyeResponse
|
|
|
17187
17188
|
return bankOraclePriceMap;
|
|
17188
17189
|
};
|
|
17189
17190
|
function parseSwbOraclePriceData(price, stdDev, timestamp, oracleData) {
|
|
17190
|
-
const swbPrice = Array.isArray(price) ? new
|
|
17191
|
-
const swbConfidence = new
|
|
17191
|
+
const swbPrice = Array.isArray(price) ? new BigNumber3__default.default(median(price)) : new BigNumber3__default.default(price.toString()).div(10 ** SWITCHBOARD_ONDEMANDE_PRICE_PRECISION);
|
|
17192
|
+
const swbConfidence = new BigNumber3__default.default(stdDev.toString()).times(SWB_PRICE_CONF_INTERVALS);
|
|
17192
17193
|
const swbConfidenceCapped = capConfidenceInterval(
|
|
17193
17194
|
swbPrice,
|
|
17194
17195
|
swbConfidence,
|
|
@@ -17209,7 +17210,7 @@ function parseSwbOraclePriceData(price, stdDev, timestamp, oracleData) {
|
|
|
17209
17210
|
lowestPrice: swbLowestPrice,
|
|
17210
17211
|
highestPrice: swbHighestPrice
|
|
17211
17212
|
},
|
|
17212
|
-
timestamp: new
|
|
17213
|
+
timestamp: new BigNumber3__default.default(timestamp),
|
|
17213
17214
|
switchboardData: oracleData
|
|
17214
17215
|
};
|
|
17215
17216
|
}
|
|
@@ -17324,13 +17325,13 @@ var adjustPriceComponent = (priceComponent, priceCoeff) => ({
|
|
|
17324
17325
|
function parseRpcPythPriceData(rawData) {
|
|
17325
17326
|
function capConfidenceInterval2(price, confidence, maxConfidence) {
|
|
17326
17327
|
const maxConfidenceInterval = price.times(maxConfidence);
|
|
17327
|
-
return
|
|
17328
|
+
return BigNumber3__default.default.min(confidence, maxConfidenceInterval);
|
|
17328
17329
|
}
|
|
17329
17330
|
const bytesWithoutDiscriminator = rawData.slice(8);
|
|
17330
17331
|
const data = parsePriceInfo(bytesWithoutDiscriminator);
|
|
17331
|
-
const exponent = new
|
|
17332
|
-
const priceRealTime = new
|
|
17333
|
-
const confidenceRealTime = new
|
|
17332
|
+
const exponent = new BigNumber3__default.default(10 ** data.priceMessage.exponent);
|
|
17333
|
+
const priceRealTime = new BigNumber3__default.default(Number(data.priceMessage.price)).times(exponent);
|
|
17334
|
+
const confidenceRealTime = new BigNumber3__default.default(Number(data.priceMessage.conf)).times(exponent).times(PYTH_PRICE_CONF_INTERVALS);
|
|
17334
17335
|
const cappedConfidenceRealTime = capConfidenceInterval2(
|
|
17335
17336
|
priceRealTime,
|
|
17336
17337
|
confidenceRealTime,
|
|
@@ -17338,8 +17339,8 @@ function parseRpcPythPriceData(rawData) {
|
|
|
17338
17339
|
);
|
|
17339
17340
|
const lowestPriceRealTime = priceRealTime.minus(cappedConfidenceRealTime);
|
|
17340
17341
|
const highestPriceRealTime = priceRealTime.plus(cappedConfidenceRealTime);
|
|
17341
|
-
const priceTimeWeighted = new
|
|
17342
|
-
const confidenceTimeWeighted = new
|
|
17342
|
+
const priceTimeWeighted = new BigNumber3__default.default(Number(data.priceMessage.emaPrice)).times(exponent);
|
|
17343
|
+
const confidenceTimeWeighted = new BigNumber3__default.default(Number(data.priceMessage.emaConf)).times(exponent).times(PYTH_PRICE_CONF_INTERVALS);
|
|
17343
17344
|
const cappedConfidenceWeighted = capConfidenceInterval2(
|
|
17344
17345
|
priceTimeWeighted,
|
|
17345
17346
|
confidenceTimeWeighted,
|
|
@@ -17360,7 +17361,7 @@ function parseRpcPythPriceData(rawData) {
|
|
|
17360
17361
|
lowestPrice: lowestPriceWeighted,
|
|
17361
17362
|
highestPrice: highestPriceWeighted
|
|
17362
17363
|
},
|
|
17363
|
-
timestamp: new
|
|
17364
|
+
timestamp: new BigNumber3__default.default(Number(data.priceMessage.publishTime))
|
|
17364
17365
|
};
|
|
17365
17366
|
}
|
|
17366
17367
|
|
|
@@ -17381,7 +17382,7 @@ function getPrice(oraclePrice, priceBias = 1 /* None */, weightedPrice = false)
|
|
|
17381
17382
|
}
|
|
17382
17383
|
function capConfidenceInterval(price, confidence, maxConfidence) {
|
|
17383
17384
|
let maxConfidenceInterval = price.times(maxConfidence);
|
|
17384
|
-
return
|
|
17385
|
+
return BigNumber3__default.default.min(confidence, maxConfidenceInterval);
|
|
17385
17386
|
}
|
|
17386
17387
|
function parseOraclePriceData(oracleSetup, rawData) {
|
|
17387
17388
|
switch (oracleSetup) {
|
|
@@ -17397,18 +17398,18 @@ function parseOraclePriceData(oracleSetup, rawData) {
|
|
|
17397
17398
|
case "SwitchboardV2" /* SwitchboardV2 */: {
|
|
17398
17399
|
return {
|
|
17399
17400
|
priceRealtime: {
|
|
17400
|
-
price: new
|
|
17401
|
-
confidence: new
|
|
17402
|
-
lowestPrice: new
|
|
17403
|
-
highestPrice: new
|
|
17401
|
+
price: new BigNumber3__default.default(0),
|
|
17402
|
+
confidence: new BigNumber3__default.default(0),
|
|
17403
|
+
lowestPrice: new BigNumber3__default.default(0),
|
|
17404
|
+
highestPrice: new BigNumber3__default.default(0)
|
|
17404
17405
|
},
|
|
17405
17406
|
priceWeighted: {
|
|
17406
|
-
price: new
|
|
17407
|
-
confidence: new
|
|
17408
|
-
lowestPrice: new
|
|
17409
|
-
highestPrice: new
|
|
17407
|
+
price: new BigNumber3__default.default(0),
|
|
17408
|
+
confidence: new BigNumber3__default.default(0),
|
|
17409
|
+
lowestPrice: new BigNumber3__default.default(0),
|
|
17410
|
+
highestPrice: new BigNumber3__default.default(0)
|
|
17410
17411
|
},
|
|
17411
|
-
timestamp: new
|
|
17412
|
+
timestamp: new BigNumber3__default.default(0)
|
|
17412
17413
|
};
|
|
17413
17414
|
}
|
|
17414
17415
|
case "SwitchboardPull" /* SwitchboardPull */:
|
|
@@ -17458,18 +17459,18 @@ function oraclePriceToDto(oraclePrice) {
|
|
|
17458
17459
|
function dtoToOraclePrice(dto) {
|
|
17459
17460
|
return {
|
|
17460
17461
|
priceRealtime: {
|
|
17461
|
-
price: new
|
|
17462
|
-
confidence: new
|
|
17463
|
-
lowestPrice: new
|
|
17464
|
-
highestPrice: new
|
|
17462
|
+
price: new BigNumber3__default.default(dto.priceRealtime.price),
|
|
17463
|
+
confidence: new BigNumber3__default.default(dto.priceRealtime.confidence),
|
|
17464
|
+
lowestPrice: new BigNumber3__default.default(dto.priceRealtime.lowestPrice),
|
|
17465
|
+
highestPrice: new BigNumber3__default.default(dto.priceRealtime.highestPrice)
|
|
17465
17466
|
},
|
|
17466
17467
|
priceWeighted: {
|
|
17467
|
-
price: new
|
|
17468
|
-
confidence: new
|
|
17469
|
-
lowestPrice: new
|
|
17470
|
-
highestPrice: new
|
|
17468
|
+
price: new BigNumber3__default.default(dto.priceWeighted.price),
|
|
17469
|
+
confidence: new BigNumber3__default.default(dto.priceWeighted.confidence),
|
|
17470
|
+
lowestPrice: new BigNumber3__default.default(dto.priceWeighted.lowestPrice),
|
|
17471
|
+
highestPrice: new BigNumber3__default.default(dto.priceWeighted.highestPrice)
|
|
17471
17472
|
},
|
|
17472
|
-
timestamp: new
|
|
17473
|
+
timestamp: new BigNumber3__default.default(dto.timestamp),
|
|
17473
17474
|
switchboardData: dto.switchboardData
|
|
17474
17475
|
};
|
|
17475
17476
|
}
|
|
@@ -17740,10 +17741,10 @@ var EMPTY_HEALTH_CACHE = {
|
|
|
17740
17741
|
timestamp: new BN11__default.default(0),
|
|
17741
17742
|
flags: 0,
|
|
17742
17743
|
prices: [],
|
|
17743
|
-
assetValueMaint: bigNumberToWrappedI80F48(new
|
|
17744
|
-
liabilityValueMaint: bigNumberToWrappedI80F48(new
|
|
17745
|
-
assetValueEquity: bigNumberToWrappedI80F48(new
|
|
17746
|
-
liabilityValueEquity: bigNumberToWrappedI80F48(new
|
|
17744
|
+
assetValueMaint: bigNumberToWrappedI80F48(new BigNumber3__default.default(0)),
|
|
17745
|
+
liabilityValueMaint: bigNumberToWrappedI80F48(new BigNumber3__default.default(0)),
|
|
17746
|
+
assetValueEquity: bigNumberToWrappedI80F48(new BigNumber3__default.default(0)),
|
|
17747
|
+
liabilityValueEquity: bigNumberToWrappedI80F48(new BigNumber3__default.default(0)),
|
|
17747
17748
|
errIndex: 0,
|
|
17748
17749
|
internalErr: 0,
|
|
17749
17750
|
internalBankruptcyErr: 0,
|
|
@@ -17873,21 +17874,21 @@ function dtoToBalance(balanceDto) {
|
|
|
17873
17874
|
return {
|
|
17874
17875
|
active: balanceDto.active,
|
|
17875
17876
|
bankPk: new web3_js.PublicKey(balanceDto.bankPk),
|
|
17876
|
-
assetShares: new
|
|
17877
|
-
liabilityShares: new
|
|
17878
|
-
emissionsOutstanding: new
|
|
17877
|
+
assetShares: new BigNumber3__default.default(balanceDto.assetShares),
|
|
17878
|
+
liabilityShares: new BigNumber3__default.default(balanceDto.liabilityShares),
|
|
17879
|
+
emissionsOutstanding: new BigNumber3__default.default(balanceDto.emissionsOutstanding),
|
|
17879
17880
|
lastUpdate: balanceDto.lastUpdate
|
|
17880
17881
|
};
|
|
17881
17882
|
}
|
|
17882
17883
|
function dtoToHealthCache(healthCacheDto) {
|
|
17883
17884
|
return {
|
|
17884
|
-
assetValue: new
|
|
17885
|
-
liabilityValue: new
|
|
17886
|
-
assetValueMaint: new
|
|
17887
|
-
liabilityValueMaint: new
|
|
17888
|
-
assetValueEquity: new
|
|
17889
|
-
liabilityValueEquity: new
|
|
17890
|
-
timestamp: new
|
|
17885
|
+
assetValue: new BigNumber3__default.default(healthCacheDto.assetValue),
|
|
17886
|
+
liabilityValue: new BigNumber3__default.default(healthCacheDto.liabilityValue),
|
|
17887
|
+
assetValueMaint: new BigNumber3__default.default(healthCacheDto.assetValueMaint),
|
|
17888
|
+
liabilityValueMaint: new BigNumber3__default.default(healthCacheDto.liabilityValueMaint),
|
|
17889
|
+
assetValueEquity: new BigNumber3__default.default(healthCacheDto.assetValueEquity),
|
|
17890
|
+
liabilityValueEquity: new BigNumber3__default.default(healthCacheDto.liabilityValueEquity),
|
|
17891
|
+
timestamp: new BigNumber3__default.default(healthCacheDto.timestamp),
|
|
17891
17892
|
flags: healthCacheDto.flags,
|
|
17892
17893
|
prices: healthCacheDto.prices,
|
|
17893
17894
|
simulationStatus: healthCacheDto.simulationStatus
|
|
@@ -17964,8 +17965,8 @@ function computeLowestEmodeWeights(emodePairs) {
|
|
|
17964
17965
|
});
|
|
17965
17966
|
} else {
|
|
17966
17967
|
result.set(bankPkStr, {
|
|
17967
|
-
assetWeightInit:
|
|
17968
|
-
assetWeightMaint:
|
|
17968
|
+
assetWeightInit: BigNumber3__default.default.min(existing.assetWeightInit, emodePair.assetWeightInit),
|
|
17969
|
+
assetWeightMaint: BigNumber3__default.default.min(existing.assetWeightMaint, emodePair.assetWeightMaint)
|
|
17969
17970
|
});
|
|
17970
17971
|
}
|
|
17971
17972
|
});
|
|
@@ -18204,8 +18205,8 @@ function computeQuantity(balance, bank) {
|
|
|
18204
18205
|
function computeQuantityUi(balance, bank, assetShareValueMultiplier) {
|
|
18205
18206
|
const { assets, liabilities } = computeQuantity(balance, bank);
|
|
18206
18207
|
const adjustedAssets = assetShareValueMultiplier ? assets.multipliedBy(assetShareValueMultiplier) : assets;
|
|
18207
|
-
const assetsQuantity = new
|
|
18208
|
-
const liabilitiesQuantity = new
|
|
18208
|
+
const assetsQuantity = new BigNumber3__default.default(nativeToUi(adjustedAssets, bank.mintDecimals));
|
|
18209
|
+
const liabilitiesQuantity = new BigNumber3__default.default(nativeToUi(liabilities, bank.mintDecimals));
|
|
18209
18210
|
return { assets: assetsQuantity, liabilities: liabilitiesQuantity };
|
|
18210
18211
|
}
|
|
18211
18212
|
|
|
@@ -18217,7 +18218,7 @@ function computeFreeCollateralFromCache(marginfiAccount, opts) {
|
|
|
18217
18218
|
0 /* Initial */
|
|
18218
18219
|
);
|
|
18219
18220
|
const signedFreeCollateral = assets.minus(liabilities);
|
|
18220
|
-
return _clamped ?
|
|
18221
|
+
return _clamped ? BigNumber3__default.default.max(0, signedFreeCollateral) : signedFreeCollateral;
|
|
18221
18222
|
}
|
|
18222
18223
|
function computeFreeCollateralFromBalances(params) {
|
|
18223
18224
|
const {
|
|
@@ -18237,7 +18238,7 @@ function computeFreeCollateralFromBalances(params) {
|
|
|
18237
18238
|
marginRequirement: 0 /* Initial */
|
|
18238
18239
|
});
|
|
18239
18240
|
const signedFreeCollateral = assets.minus(liabilities);
|
|
18240
|
-
return clamped ?
|
|
18241
|
+
return clamped ? BigNumber3__default.default.max(0, signedFreeCollateral) : signedFreeCollateral;
|
|
18241
18242
|
}
|
|
18242
18243
|
function computeHealthComponentsFromCache(marginfiAccount, marginRequirement) {
|
|
18243
18244
|
if (marginfiAccount.healthCache.simulationStatus === 0 /* UNSET */) {
|
|
@@ -18276,8 +18277,8 @@ function computeHealthComponentsFromBalances(params) {
|
|
|
18276
18277
|
const filteredBalances = activeBalances.filter(
|
|
18277
18278
|
(accountBalance) => !(excludedBanks ?? []).find((b) => b.equals(accountBalance.bankPk))
|
|
18278
18279
|
);
|
|
18279
|
-
let totalAssets = new
|
|
18280
|
-
let totalLiabilities = new
|
|
18280
|
+
let totalAssets = new BigNumber3__default.default(0);
|
|
18281
|
+
let totalLiabilities = new BigNumber3__default.default(0);
|
|
18281
18282
|
for (const accountBalance of filteredBalances) {
|
|
18282
18283
|
const bankKey = accountBalance.bankPk.toBase58();
|
|
18283
18284
|
const bank = banksMap.get(bankKey);
|
|
@@ -18297,11 +18298,11 @@ function computeHealthComponentsFromBalances(params) {
|
|
|
18297
18298
|
const emodeWeight = activeEmodeWeightsByBank?.get(bankKey);
|
|
18298
18299
|
const assetShareValueMultiplier = assetShareValueMultiplierByBank?.get(bankKey);
|
|
18299
18300
|
const activeEmodeWeights = emodeWeight ? {
|
|
18300
|
-
assetWeightInit:
|
|
18301
|
+
assetWeightInit: BigNumber3__default.default.max(
|
|
18301
18302
|
bank.config.assetWeightInit,
|
|
18302
18303
|
emodeWeight.assetWeightInit ?? bank.config.assetWeightInit
|
|
18303
18304
|
),
|
|
18304
|
-
assetWeightMaint:
|
|
18305
|
+
assetWeightMaint: BigNumber3__default.default.max(
|
|
18305
18306
|
bank.config.assetWeightMaint,
|
|
18306
18307
|
emodeWeight.assetWeightMaint ?? bank.config.assetWeightMaint
|
|
18307
18308
|
)
|
|
@@ -18332,8 +18333,8 @@ function computeHealthComponentsWithoutBiasFromBalances(params) {
|
|
|
18332
18333
|
const filteredBalances = activeBalances.filter(
|
|
18333
18334
|
(accountBalance) => !(excludedBanks ?? []).find((b) => b.equals(accountBalance.bankPk))
|
|
18334
18335
|
);
|
|
18335
|
-
let totalAssets = new
|
|
18336
|
-
let totalLiabilities = new
|
|
18336
|
+
let totalAssets = new BigNumber3__default.default(0);
|
|
18337
|
+
let totalLiabilities = new BigNumber3__default.default(0);
|
|
18337
18338
|
for (const accountBalance of filteredBalances) {
|
|
18338
18339
|
const bankKey = accountBalance.bankPk.toBase58();
|
|
18339
18340
|
const bank = banksMap.get(bankKey);
|
|
@@ -18353,11 +18354,11 @@ function computeHealthComponentsWithoutBiasFromBalances(params) {
|
|
|
18353
18354
|
const emodeWeight = activeEmodeWeightsByBank?.get(bankKey);
|
|
18354
18355
|
const assetShareValueMultiplier = assetShareValueMultiplierByBank?.get(bankKey);
|
|
18355
18356
|
const activeEmodeWeights = emodeWeight ? {
|
|
18356
|
-
assetWeightInit:
|
|
18357
|
+
assetWeightInit: BigNumber3__default.default.max(
|
|
18357
18358
|
bank.config.assetWeightInit,
|
|
18358
18359
|
emodeWeight.assetWeightInit ?? bank.config.assetWeightInit
|
|
18359
18360
|
),
|
|
18360
|
-
assetWeightMaint:
|
|
18361
|
+
assetWeightMaint: BigNumber3__default.default.max(
|
|
18361
18362
|
bank.config.assetWeightMaint,
|
|
18362
18363
|
emodeWeight.assetWeightMaint ?? bank.config.assetWeightMaint
|
|
18363
18364
|
)
|
|
@@ -18414,7 +18415,7 @@ function computeHealthCacheStatus(params) {
|
|
|
18414
18415
|
liabilityValueMaint,
|
|
18415
18416
|
assetValueEquity,
|
|
18416
18417
|
liabilityValueEquity,
|
|
18417
|
-
timestamp: new
|
|
18418
|
+
timestamp: new BigNumber3__default.default(0),
|
|
18418
18419
|
flags: [],
|
|
18419
18420
|
prices: [],
|
|
18420
18421
|
simulationStatus: 2 /* COMPUTED */
|
|
@@ -18461,9 +18462,9 @@ function createEmptyBalance(bankPk) {
|
|
|
18461
18462
|
const balance = {
|
|
18462
18463
|
active: false,
|
|
18463
18464
|
bankPk,
|
|
18464
|
-
assetShares: new
|
|
18465
|
-
liabilityShares: new
|
|
18466
|
-
emissionsOutstanding: new
|
|
18465
|
+
assetShares: new BigNumber3__default.default(0),
|
|
18466
|
+
liabilityShares: new BigNumber3__default.default(0),
|
|
18467
|
+
emissionsOutstanding: new BigNumber3__default.default(0),
|
|
18467
18468
|
lastUpdate: 0
|
|
18468
18469
|
};
|
|
18469
18470
|
return balance;
|
|
@@ -18534,7 +18535,7 @@ function computeNetApy(params) {
|
|
|
18534
18535
|
}).assets
|
|
18535
18536
|
).div(totalUsdValue.isEqualTo(0) ? 1 : totalUsdValue)
|
|
18536
18537
|
);
|
|
18537
|
-
}, new
|
|
18538
|
+
}, new BigNumber3__default.default(0)).toNumber();
|
|
18538
18539
|
return aprToApy(apr);
|
|
18539
18540
|
}
|
|
18540
18541
|
function computeLiquidationPriceForBank(params) {
|
|
@@ -18594,13 +18595,13 @@ function computeClaimedEmissions(balance, bank, currentTimestamp) {
|
|
|
18594
18595
|
}
|
|
18595
18596
|
if (balanceAmount) {
|
|
18596
18597
|
const lastUpdate = balance.lastUpdate;
|
|
18597
|
-
const period = new
|
|
18598
|
-
const emissionsRate = new
|
|
18598
|
+
const period = new BigNumber3__default.default(currentTimestamp - lastUpdate);
|
|
18599
|
+
const emissionsRate = new BigNumber3__default.default(bank.emissionsRate);
|
|
18599
18600
|
const emissions = period.times(balanceAmount).times(emissionsRate).div(31536e3 * Math.pow(10, bank.mintDecimals));
|
|
18600
|
-
const emissionsReal =
|
|
18601
|
+
const emissionsReal = BigNumber3__default.default.min(emissions, new BigNumber3__default.default(bank.emissionsRemaining));
|
|
18601
18602
|
return emissionsReal;
|
|
18602
18603
|
}
|
|
18603
|
-
return new
|
|
18604
|
+
return new BigNumber3__default.default(0);
|
|
18604
18605
|
}
|
|
18605
18606
|
function computeTotalOutstandingEmissions(balance, bank) {
|
|
18606
18607
|
const claimedEmissions = balance.emissionsOutstanding;
|
|
@@ -18722,9 +18723,9 @@ function computeProjectedActiveBalancesNoCpi(balances, instructions2, program, b
|
|
|
18722
18723
|
let projectedBalances = balances.map((b) => ({
|
|
18723
18724
|
active: b.active,
|
|
18724
18725
|
bankPk: b.bankPk,
|
|
18725
|
-
assetShares: new
|
|
18726
|
-
liabilityShares: new
|
|
18727
|
-
emissionsOutstanding: new
|
|
18726
|
+
assetShares: new BigNumber3__default.default(b.assetShares),
|
|
18727
|
+
liabilityShares: new BigNumber3__default.default(b.liabilityShares),
|
|
18728
|
+
emissionsOutstanding: new BigNumber3__default.default(b.emissionsOutstanding),
|
|
18728
18729
|
lastUpdate: b.lastUpdate
|
|
18729
18730
|
}));
|
|
18730
18731
|
const impactedAssetsBanks = /* @__PURE__ */ new Set();
|
|
@@ -18753,15 +18754,15 @@ function computeProjectedActiveBalancesNoCpi(balances, instructions2, program, b
|
|
|
18753
18754
|
targetBalance = projectedBalances[firstInactiveBalanceIndex];
|
|
18754
18755
|
targetBalance.active = true;
|
|
18755
18756
|
targetBalance.bankPk = targetBank;
|
|
18756
|
-
targetBalance.assetShares = new
|
|
18757
|
-
targetBalance.liabilityShares = new
|
|
18757
|
+
targetBalance.assetShares = new BigNumber3__default.default(0);
|
|
18758
|
+
targetBalance.liabilityShares = new BigNumber3__default.default(0);
|
|
18758
18759
|
}
|
|
18759
|
-
const depositTokenAmount = new
|
|
18760
|
+
const depositTokenAmount = new BigNumber3__default.default(ixArgs.amount?.toString() || "0");
|
|
18760
18761
|
const bank = banksMap.get(targetBank.toBase58());
|
|
18761
18762
|
if (!bank) {
|
|
18762
18763
|
throw Error(`Bank ${targetBank.toBase58()} not found in bankMap`);
|
|
18763
18764
|
}
|
|
18764
|
-
const assetShareValueMultiplier = assetShareValueMultiplierByBank.get(targetBank.toBase58()) ??
|
|
18765
|
+
const assetShareValueMultiplier = assetShareValueMultiplierByBank.get(targetBank.toBase58()) ?? BigNumber3__default.default(1);
|
|
18765
18766
|
const cTokenAmount = depositTokenAmount.div(assetShareValueMultiplier);
|
|
18766
18767
|
const depositShares = getAssetShares(bank, cTokenAmount);
|
|
18767
18768
|
targetBalance.assetShares = targetBalance.assetShares.plus(depositShares);
|
|
@@ -18779,10 +18780,10 @@ function computeProjectedActiveBalancesNoCpi(balances, instructions2, program, b
|
|
|
18779
18780
|
targetBalance = projectedBalances[firstInactiveBalanceIndex];
|
|
18780
18781
|
targetBalance.active = true;
|
|
18781
18782
|
targetBalance.bankPk = targetBank;
|
|
18782
|
-
targetBalance.assetShares = new
|
|
18783
|
-
targetBalance.liabilityShares = new
|
|
18783
|
+
targetBalance.assetShares = new BigNumber3__default.default(0);
|
|
18784
|
+
targetBalance.liabilityShares = new BigNumber3__default.default(0);
|
|
18784
18785
|
}
|
|
18785
|
-
const borrowTokenAmount = new
|
|
18786
|
+
const borrowTokenAmount = new BigNumber3__default.default(ixArgs.amount?.toString() || "0");
|
|
18786
18787
|
const bank = banksMap.get(targetBank.toBase58());
|
|
18787
18788
|
if (!bank) {
|
|
18788
18789
|
throw Error(`Bank ${targetBank.toBase58()} not found in bankMap`);
|
|
@@ -18802,19 +18803,19 @@ function computeProjectedActiveBalancesNoCpi(balances, instructions2, program, b
|
|
|
18802
18803
|
);
|
|
18803
18804
|
}
|
|
18804
18805
|
if (ixArgs.repayAll) {
|
|
18805
|
-
targetBalance.liabilityShares = new
|
|
18806
|
+
targetBalance.liabilityShares = new BigNumber3__default.default(0);
|
|
18806
18807
|
if (targetBalance.assetShares.eq(0)) {
|
|
18807
18808
|
targetBalance.active = false;
|
|
18808
18809
|
targetBalance.bankPk = web3_js.PublicKey.default;
|
|
18809
18810
|
}
|
|
18810
18811
|
} else {
|
|
18811
|
-
const repayTokenAmount = new
|
|
18812
|
+
const repayTokenAmount = new BigNumber3__default.default(ixArgs.amount?.toString() || "0");
|
|
18812
18813
|
const bank = banksMap.get(targetBank.toBase58());
|
|
18813
18814
|
if (!bank) {
|
|
18814
18815
|
throw Error(`Bank ${targetBank.toBase58()} not found in bankMap`);
|
|
18815
18816
|
}
|
|
18816
18817
|
const repayShares = getLiabilityShares(bank, repayTokenAmount);
|
|
18817
|
-
targetBalance.liabilityShares =
|
|
18818
|
+
targetBalance.liabilityShares = BigNumber3__default.default.max(
|
|
18818
18819
|
0,
|
|
18819
18820
|
targetBalance.liabilityShares.minus(repayShares)
|
|
18820
18821
|
);
|
|
@@ -18838,19 +18839,19 @@ function computeProjectedActiveBalancesNoCpi(balances, instructions2, program, b
|
|
|
18838
18839
|
);
|
|
18839
18840
|
}
|
|
18840
18841
|
if (ixArgs.withdrawAll) {
|
|
18841
|
-
targetBalance.assetShares = new
|
|
18842
|
+
targetBalance.assetShares = new BigNumber3__default.default(0);
|
|
18842
18843
|
if (targetBalance.liabilityShares.eq(0)) {
|
|
18843
18844
|
targetBalance.active = false;
|
|
18844
18845
|
targetBalance.bankPk = web3_js.PublicKey.default;
|
|
18845
18846
|
}
|
|
18846
18847
|
} else {
|
|
18847
|
-
const withdrawTokenAmount = new
|
|
18848
|
+
const withdrawTokenAmount = new BigNumber3__default.default(ixArgs.amount?.toString() || "0");
|
|
18848
18849
|
const bank = banksMap.get(targetBank.toBase58());
|
|
18849
18850
|
if (!bank) {
|
|
18850
18851
|
throw Error(`Bank ${targetBank.toBase58()} not found in bankMap`);
|
|
18851
18852
|
}
|
|
18852
18853
|
const withdrawShares = getAssetShares(bank, withdrawTokenAmount);
|
|
18853
|
-
targetBalance.assetShares =
|
|
18854
|
+
targetBalance.assetShares = BigNumber3__default.default.max(
|
|
18854
18855
|
0,
|
|
18855
18856
|
targetBalance.assetShares.minus(withdrawShares)
|
|
18856
18857
|
);
|
|
@@ -33711,7 +33712,7 @@ async function makePulseHealthIx2(program, marginfiAccountPk, banks, balances, m
|
|
|
33711
33712
|
return { instructions: [ix], keys: [] };
|
|
33712
33713
|
}
|
|
33713
33714
|
function generateDummyAccount(group, authority, accountKey) {
|
|
33714
|
-
const dummyWrappedI80F48 = bigNumberToWrappedI80F48(new
|
|
33715
|
+
const dummyWrappedI80F48 = bigNumberToWrappedI80F48(new BigNumber3__default.default(0));
|
|
33715
33716
|
const dummyBalances = Array(15).fill({
|
|
33716
33717
|
active: false,
|
|
33717
33718
|
bankPk: new web3_js.PublicKey("11111111111111111111111111111111"),
|
|
@@ -33734,10 +33735,10 @@ function generateDummyAccount(group, authority, accountKey) {
|
|
|
33734
33735
|
timestamp: new BN11__default.default(0),
|
|
33735
33736
|
flags: 0,
|
|
33736
33737
|
prices: [],
|
|
33737
|
-
assetValueMaint: bigNumberToWrappedI80F48(new
|
|
33738
|
-
liabilityValueMaint: bigNumberToWrappedI80F48(new
|
|
33739
|
-
assetValueEquity: bigNumberToWrappedI80F48(new
|
|
33740
|
-
liabilityValueEquity: bigNumberToWrappedI80F48(new
|
|
33738
|
+
assetValueMaint: bigNumberToWrappedI80F48(new BigNumber3__default.default(0)),
|
|
33739
|
+
liabilityValueMaint: bigNumberToWrappedI80F48(new BigNumber3__default.default(0)),
|
|
33740
|
+
assetValueEquity: bigNumberToWrappedI80F48(new BigNumber3__default.default(0)),
|
|
33741
|
+
liabilityValueEquity: bigNumberToWrappedI80F48(new BigNumber3__default.default(0)),
|
|
33741
33742
|
errIndex: 0,
|
|
33742
33743
|
internalErr: 0,
|
|
33743
33744
|
internalBankruptcyErr: 0,
|
|
@@ -42352,8 +42353,8 @@ async function makeKaminoWithdrawTx(params) {
|
|
|
42352
42353
|
throw new Error("Bank has no kamino integration accounts");
|
|
42353
42354
|
}
|
|
42354
42355
|
const { value: amountValue, type: amountType } = resolveAmount(amount);
|
|
42355
|
-
const multiplier = assetShareValueMultiplierByBank.get(withdrawIxParams.bank.address.toBase58()) ?? new
|
|
42356
|
-
const adjustedAmount = amountType === "cToken" ? new
|
|
42356
|
+
const multiplier = assetShareValueMultiplierByBank.get(withdrawIxParams.bank.address.toBase58()) ?? new BigNumber3.BigNumber(1);
|
|
42357
|
+
const adjustedAmount = amountType === "cToken" ? new BigNumber3.BigNumber(amountValue).toNumber() : new BigNumber3.BigNumber(amountValue).div(multiplier).toNumber();
|
|
42357
42358
|
const refreshIxs = makeRefreshKaminoBanksIxs(
|
|
42358
42359
|
params.marginfiAccount,
|
|
42359
42360
|
params.bankMap,
|
|
@@ -42595,7 +42596,7 @@ async function makeDriftDepositIx3({
|
|
|
42595
42596
|
const depositIxs = [];
|
|
42596
42597
|
const userTokenAtaPk = getAssociatedTokenAddressSync(bank.mint, authority, true, tokenProgram);
|
|
42597
42598
|
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
42598
|
-
depositIxs.push(...makeWrapSolIxs(authority, new
|
|
42599
|
+
depositIxs.push(...makeWrapSolIxs(authority, new BigNumber3__default.default(amount).minus(wSolBalanceUi)));
|
|
42599
42600
|
}
|
|
42600
42601
|
const driftState = deriveDriftState()[0];
|
|
42601
42602
|
const driftSpotMarketVault = deriveDriftSpotMarketVault(driftMarketIndex)[0];
|
|
@@ -42705,7 +42706,7 @@ async function makeKaminoDepositIx3({
|
|
|
42705
42706
|
const reserveDestinationDepositCollateral = reserve.collateral.supplyVault;
|
|
42706
42707
|
const { lendingMarketAuthority } = getAllDerivedKaminoAccounts(reserve.lendingMarket, bank.mint);
|
|
42707
42708
|
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
42708
|
-
depositIxs.push(...makeWrapSolIxs(authority, new
|
|
42709
|
+
depositIxs.push(...makeWrapSolIxs(authority, new BigNumber3__default.default(amount).minus(wSolBalanceUi)));
|
|
42709
42710
|
}
|
|
42710
42711
|
const reserveFarm = !reserve.farmCollateral.equals(
|
|
42711
42712
|
new web3_js.PublicKey("11111111111111111111111111111111")
|
|
@@ -42834,7 +42835,7 @@ async function makeDepositIx3({
|
|
|
42834
42835
|
const remainingAccounts = tokenProgram.equals(TOKEN_2022_PROGRAM_ID) ? [{ pubkey: bank.mint, isSigner: false, isWritable: false }] : [];
|
|
42835
42836
|
const depositIxs = [];
|
|
42836
42837
|
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
42837
|
-
depositIxs.push(...makeWrapSolIxs(authority, new
|
|
42838
|
+
depositIxs.push(...makeWrapSolIxs(authority, new BigNumber3__default.default(amount).minus(wSolBalanceUi)));
|
|
42838
42839
|
}
|
|
42839
42840
|
const depositIx = isSync ? sync_instructions_default.makeDepositIx(
|
|
42840
42841
|
program.programId,
|
|
@@ -43049,7 +43050,7 @@ async function makeLoopTx(params) {
|
|
|
43049
43050
|
let additionalTxs = [];
|
|
43050
43051
|
if (depositOpts.depositBank.mint.equals(NATIVE_MINT) && depositOpts.inputDepositAmount) {
|
|
43051
43052
|
setupIxs.push(
|
|
43052
|
-
...makeWrapSolIxs(marginfiAccount.authority, new
|
|
43053
|
+
...makeWrapSolIxs(marginfiAccount.authority, new BigNumber3.BigNumber(depositOpts.inputDepositAmount))
|
|
43053
43054
|
);
|
|
43054
43055
|
}
|
|
43055
43056
|
if (setupIxs.length > 0 || additionalIxs.length > 0 || kaminoRefreshIxs.instructions.length > 0 || updateDriftMarketIxs.instructions.length > 0) {
|
|
@@ -43307,7 +43308,7 @@ async function makeRepayIx3({
|
|
|
43307
43308
|
const userAta = getAssociatedTokenAddressSync(bank.mint, authority, true, tokenProgram);
|
|
43308
43309
|
const remainingAccounts = tokenProgram.equals(TOKEN_2022_PROGRAM_ID) ? [{ pubkey: bank.mint, isSigner: false, isWritable: false }] : [];
|
|
43309
43310
|
if (bank.mint.equals(NATIVE_MINT) && wrapAndUnwrapSol) {
|
|
43310
|
-
repayIxs.push(...makeWrapSolIxs(authority, new
|
|
43311
|
+
repayIxs.push(...makeWrapSolIxs(authority, new BigNumber3.BigNumber(amount).minus(wSolBalanceUi)));
|
|
43311
43312
|
}
|
|
43312
43313
|
const repayIx = !isSync || !opts.overrideInferAccounts?.group ? await instructions_default.makeRepayIx(
|
|
43313
43314
|
program,
|
|
@@ -43537,8 +43538,8 @@ async function buildRepayWithCollatFlashloanTx({
|
|
|
43537
43538
|
withdrawOpts.withdrawBank.tokenSymbol
|
|
43538
43539
|
);
|
|
43539
43540
|
}
|
|
43540
|
-
const multiplier = assetShareValueMultiplierByBank.get(withdrawOpts.withdrawBank.address.toBase58()) ?? new
|
|
43541
|
-
const adjustedAmount = new
|
|
43541
|
+
const multiplier = assetShareValueMultiplierByBank.get(withdrawOpts.withdrawBank.address.toBase58()) ?? new BigNumber3.BigNumber(1);
|
|
43542
|
+
const adjustedAmount = new BigNumber3.BigNumber(withdrawOpts.withdrawAmount).div(multiplier).times(1.0001).toNumber();
|
|
43542
43543
|
withdrawIxs = await makeKaminoWithdrawIx3({
|
|
43543
43544
|
program,
|
|
43544
43545
|
bank: withdrawOpts.withdrawBank,
|
|
@@ -43875,8 +43876,8 @@ async function buildSwapCollateralFlashloanTx({
|
|
|
43875
43876
|
withdrawOpts.withdrawBank.tokenSymbol
|
|
43876
43877
|
);
|
|
43877
43878
|
}
|
|
43878
|
-
const multiplier = assetShareValueMultiplierByBank.get(withdrawOpts.withdrawBank.address.toBase58()) ?? new
|
|
43879
|
-
const adjustedAmount = new
|
|
43879
|
+
const multiplier = assetShareValueMultiplierByBank.get(withdrawOpts.withdrawBank.address.toBase58()) ?? new BigNumber3.BigNumber(1);
|
|
43880
|
+
const adjustedAmount = new BigNumber3.BigNumber(actualWithdrawAmount).div(multiplier).times(1.0001).toNumber();
|
|
43880
43881
|
withdrawIxs = await makeKaminoWithdrawIx3({
|
|
43881
43882
|
program,
|
|
43882
43883
|
bank: withdrawBank,
|
|
@@ -44445,7 +44446,7 @@ async function simulateAccountHealthCacheWithFallback(params) {
|
|
|
44445
44446
|
liabilityValueMaint,
|
|
44446
44447
|
assetValueEquity,
|
|
44447
44448
|
liabilityValueEquity,
|
|
44448
|
-
timestamp: new
|
|
44449
|
+
timestamp: new BigNumber3__default.default(0),
|
|
44449
44450
|
flags: [],
|
|
44450
44451
|
prices: [],
|
|
44451
44452
|
simulationStatus: 2 /* COMPUTED */
|
|
@@ -44859,7 +44860,7 @@ function computeMaxBorrowForBank(params) {
|
|
|
44859
44860
|
(b) => b.config.riskTier === "Isolated" /* Isolated */ && !b.address.equals(bankAddress)
|
|
44860
44861
|
);
|
|
44861
44862
|
if (attemptingToBorrowIsolatedAssetWithActiveDebt || attemptingToBorrowNewAssetWithExistingIsolatedDebt) {
|
|
44862
|
-
return new
|
|
44863
|
+
return new BigNumber3__default.default(0);
|
|
44863
44864
|
}
|
|
44864
44865
|
const _volatilityFactor = volatilityFactor ?? 1;
|
|
44865
44866
|
const balance = getBalance(bankAddress, activeBalances);
|
|
@@ -44871,7 +44872,7 @@ function computeMaxBorrowForBank(params) {
|
|
|
44871
44872
|
activeEmodeWeightsByBank,
|
|
44872
44873
|
assetShareValueMultiplierByBank
|
|
44873
44874
|
}).times(_volatilityFactor);
|
|
44874
|
-
const untiedCollateralForBank =
|
|
44875
|
+
const untiedCollateralForBank = BigNumber3__default.default.min(
|
|
44875
44876
|
computeAssetUsdValue({
|
|
44876
44877
|
bank,
|
|
44877
44878
|
oraclePrice,
|
|
@@ -44970,7 +44971,7 @@ function computeMaxWithdrawForBank(params) {
|
|
|
44970
44971
|
);
|
|
44971
44972
|
if (bank.config.riskTier === "Isolated" /* Isolated */ || initAssetWeight.isZero() && maintAssetWeight.isZero()) {
|
|
44972
44973
|
if (freeCollateral.isZero() && !liabilitiesInit.isZero()) {
|
|
44973
|
-
return new
|
|
44974
|
+
return new BigNumber3__default.default(0);
|
|
44974
44975
|
} else {
|
|
44975
44976
|
return entireBalance;
|
|
44976
44977
|
}
|
|
@@ -44979,7 +44980,7 @@ function computeMaxWithdrawForBank(params) {
|
|
|
44979
44980
|
if (liabilitiesInit.eq(0)) {
|
|
44980
44981
|
return entireBalance;
|
|
44981
44982
|
} else if (freeCollateral.isZero()) {
|
|
44982
|
-
return new
|
|
44983
|
+
return new BigNumber3__default.default(0);
|
|
44983
44984
|
} else {
|
|
44984
44985
|
const { liabilities: maintLiabilities, assets: maintAssets } = computeHealthComponentsFromCache(account, 1 /* Maintenance */);
|
|
44985
44986
|
const maintUntiedCollateral = maintAssets.minus(maintLiabilities);
|
|
@@ -45344,9 +45345,7 @@ async function computeSmartCrank({
|
|
|
45344
45345
|
};
|
|
45345
45346
|
}
|
|
45346
45347
|
async function makeSmartCrankSwbFeedIx(params) {
|
|
45347
|
-
console.log("[makeSmartCrankSwbFeedIx] Called");
|
|
45348
45348
|
const crankResult = await computeSmartCrank(params);
|
|
45349
|
-
console.log("[makeSmartCrankSwbFeedIx] Crank result:", crankResult);
|
|
45350
45349
|
if (crankResult.uncrankableLiabilities.length > 0) {
|
|
45351
45350
|
console.log(
|
|
45352
45351
|
"Uncrankable liability details:",
|
|
@@ -45382,7 +45381,6 @@ async function makeSmartCrankSwbFeedIx(params) {
|
|
|
45382
45381
|
);
|
|
45383
45382
|
}
|
|
45384
45383
|
const oraclesToCrank = crankResult.requiredOracles;
|
|
45385
|
-
console.log("[makeSmartCrankSwbFeedIx] Oracles to crank:", oraclesToCrank);
|
|
45386
45384
|
const { instructions: instructions2, luts } = await makeUpdateSwbFeedIx({
|
|
45387
45385
|
swbPullOracles: oraclesToCrank,
|
|
45388
45386
|
feePayer: params.marginfiAccount.authority,
|
|
@@ -45419,9 +45417,6 @@ async function makeCrankSwbFeedIx(marginfiAccount, bankMap, newBanksPk, provider
|
|
|
45419
45417
|
}
|
|
45420
45418
|
}
|
|
45421
45419
|
async function makeUpdateSwbFeedIx(props) {
|
|
45422
|
-
console.log(
|
|
45423
|
-
`[makeUpdateSwbFeedIx] Called with ${props.swbPullOracles.length} oracles, feePayer: ${props.feePayer.toBase58()}`
|
|
45424
|
-
);
|
|
45425
45420
|
const seen = /* @__PURE__ */ new Set();
|
|
45426
45421
|
const uniqueOracles = props.swbPullOracles.filter((oracle) => {
|
|
45427
45422
|
const key = oracle.key.toBase58();
|
|
@@ -45429,21 +45424,12 @@ async function makeUpdateSwbFeedIx(props) {
|
|
|
45429
45424
|
seen.add(key);
|
|
45430
45425
|
return true;
|
|
45431
45426
|
});
|
|
45432
|
-
console.log(
|
|
45433
|
-
`[makeUpdateSwbFeedIx] ${uniqueOracles.length} unique oracles after dedup (removed ${props.swbPullOracles.length - uniqueOracles.length})`
|
|
45434
|
-
);
|
|
45435
|
-
uniqueOracles.forEach(
|
|
45436
|
-
(o) => console.log(
|
|
45437
|
-
`[makeUpdateSwbFeedIx] - ${o.key.toBase58()} (hasSwitchboardData: ${!!o.price?.switchboardData})`
|
|
45438
|
-
)
|
|
45439
|
-
);
|
|
45440
45427
|
const swbProgram = await onDemand.AnchorUtils.loadProgramFromConnection(props.connection);
|
|
45441
45428
|
const pullFeedInstances = uniqueOracles.map((oracle) => {
|
|
45442
45429
|
const pullFeed = new onDemand.PullFeed(swbProgram, oracle.key);
|
|
45443
45430
|
return pullFeed;
|
|
45444
45431
|
});
|
|
45445
45432
|
if (pullFeedInstances.length === 0) {
|
|
45446
|
-
console.log(`[makeUpdateSwbFeedIx] No pull feed instances, returning early`);
|
|
45447
45433
|
return { instructions: [], luts: [] };
|
|
45448
45434
|
}
|
|
45449
45435
|
const crossbarClient = new common.CrossbarClient(
|
|
@@ -45465,7 +45451,6 @@ async function makeUpdateSwbFeedIx(props) {
|
|
|
45465
45451
|
payer: props.feePayer,
|
|
45466
45452
|
crossbarClient
|
|
45467
45453
|
});
|
|
45468
|
-
console.log(`[makeUpdateSwbFeedIx] Got ${pullIx.length} instructions, ${luts.length} LUTs`);
|
|
45469
45454
|
return { instructions: pullIx, luts };
|
|
45470
45455
|
}
|
|
45471
45456
|
|
|
@@ -45807,18 +45792,18 @@ var fetchPythOraclePricesFromAPI = async (pythOracleKeys, apiEndpoint, opts) =>
|
|
|
45807
45792
|
key,
|
|
45808
45793
|
{
|
|
45809
45794
|
priceRealtime: {
|
|
45810
|
-
price:
|
|
45811
|
-
confidence:
|
|
45812
|
-
lowestPrice:
|
|
45813
|
-
highestPrice:
|
|
45795
|
+
price: BigNumber3__default.default(oraclePrice.priceRealtime.price),
|
|
45796
|
+
confidence: BigNumber3__default.default(oraclePrice.priceRealtime.confidence),
|
|
45797
|
+
lowestPrice: BigNumber3__default.default(oraclePrice.priceRealtime.lowestPrice),
|
|
45798
|
+
highestPrice: BigNumber3__default.default(oraclePrice.priceRealtime.highestPrice)
|
|
45814
45799
|
},
|
|
45815
45800
|
priceWeighted: {
|
|
45816
|
-
price:
|
|
45817
|
-
confidence:
|
|
45818
|
-
lowestPrice:
|
|
45819
|
-
highestPrice:
|
|
45801
|
+
price: BigNumber3__default.default(oraclePrice.priceWeighted.price),
|
|
45802
|
+
confidence: BigNumber3__default.default(oraclePrice.priceWeighted.confidence),
|
|
45803
|
+
lowestPrice: BigNumber3__default.default(oraclePrice.priceWeighted.lowestPrice),
|
|
45804
|
+
highestPrice: BigNumber3__default.default(oraclePrice.priceWeighted.highestPrice)
|
|
45820
45805
|
},
|
|
45821
|
-
timestamp: oraclePrice.timestamp ?
|
|
45806
|
+
timestamp: oraclePrice.timestamp ? BigNumber3__default.default(oraclePrice.timestamp) : null
|
|
45822
45807
|
}
|
|
45823
45808
|
])
|
|
45824
45809
|
);
|
|
@@ -45833,22 +45818,22 @@ var fetchPythOraclePricesFromChain = async (requestedPythOracleKeys, connection)
|
|
|
45833
45818
|
const oracleKey = requestedPythOracleKeys[index];
|
|
45834
45819
|
const priceDataRaw = oracleAis[index];
|
|
45835
45820
|
let oraclePrice = priceDataRaw && parseRpcPythPriceData(priceDataRaw.data);
|
|
45836
|
-
if (!oraclePrice || oraclePrice.priceRealtime.price.eq(new
|
|
45821
|
+
if (!oraclePrice || oraclePrice.priceRealtime.price.eq(new BigNumber3__default.default(0))) {
|
|
45837
45822
|
oraclePrice = {
|
|
45838
45823
|
...oraclePrice,
|
|
45839
45824
|
priceRealtime: {
|
|
45840
|
-
price: new
|
|
45841
|
-
confidence: new
|
|
45842
|
-
lowestPrice: new
|
|
45843
|
-
highestPrice: new
|
|
45825
|
+
price: new BigNumber3__default.default(0),
|
|
45826
|
+
confidence: new BigNumber3__default.default(0),
|
|
45827
|
+
lowestPrice: new BigNumber3__default.default(0),
|
|
45828
|
+
highestPrice: new BigNumber3__default.default(0)
|
|
45844
45829
|
},
|
|
45845
45830
|
priceWeighted: {
|
|
45846
|
-
price: new
|
|
45847
|
-
confidence: new
|
|
45848
|
-
lowestPrice: new
|
|
45849
|
-
highestPrice: new
|
|
45831
|
+
price: new BigNumber3__default.default(0),
|
|
45832
|
+
confidence: new BigNumber3__default.default(0),
|
|
45833
|
+
lowestPrice: new BigNumber3__default.default(0),
|
|
45834
|
+
highestPrice: new BigNumber3__default.default(0)
|
|
45850
45835
|
},
|
|
45851
|
-
timestamp: new
|
|
45836
|
+
timestamp: new BigNumber3__default.default(Date.now())
|
|
45852
45837
|
};
|
|
45853
45838
|
}
|
|
45854
45839
|
updatedOraclePriceByKey[oracleKey] = oraclePrice;
|
|
@@ -46125,17 +46110,17 @@ function handleFixedOracleBanks(banks) {
|
|
|
46125
46110
|
const fixedOraclePrice = {
|
|
46126
46111
|
priceRealtime: {
|
|
46127
46112
|
price: fixedPrice,
|
|
46128
|
-
confidence:
|
|
46113
|
+
confidence: BigNumber3__default.default(0),
|
|
46129
46114
|
lowestPrice: fixedPrice,
|
|
46130
46115
|
highestPrice: fixedPrice
|
|
46131
46116
|
},
|
|
46132
46117
|
priceWeighted: {
|
|
46133
46118
|
price: fixedPrice,
|
|
46134
|
-
confidence:
|
|
46119
|
+
confidence: BigNumber3__default.default(0),
|
|
46135
46120
|
lowestPrice: fixedPrice,
|
|
46136
46121
|
highestPrice: fixedPrice
|
|
46137
46122
|
},
|
|
46138
|
-
timestamp:
|
|
46123
|
+
timestamp: BigNumber3__default.default(Date.now())
|
|
46139
46124
|
};
|
|
46140
46125
|
oracleMap.set(bank.address.toBase58(), fixedOraclePrice);
|
|
46141
46126
|
});
|
|
@@ -46146,18 +46131,18 @@ function handleZeroOracleBanks(banks) {
|
|
|
46146
46131
|
banks.forEach((bank) => {
|
|
46147
46132
|
const zeroOraclePrice = {
|
|
46148
46133
|
priceRealtime: {
|
|
46149
|
-
price:
|
|
46150
|
-
confidence:
|
|
46151
|
-
lowestPrice:
|
|
46152
|
-
highestPrice:
|
|
46134
|
+
price: BigNumber3__default.default(0),
|
|
46135
|
+
confidence: BigNumber3__default.default(0),
|
|
46136
|
+
lowestPrice: BigNumber3__default.default(0),
|
|
46137
|
+
highestPrice: BigNumber3__default.default(0)
|
|
46153
46138
|
},
|
|
46154
46139
|
priceWeighted: {
|
|
46155
|
-
price:
|
|
46156
|
-
confidence:
|
|
46157
|
-
lowestPrice:
|
|
46158
|
-
highestPrice:
|
|
46140
|
+
price: BigNumber3__default.default(0),
|
|
46141
|
+
confidence: BigNumber3__default.default(0),
|
|
46142
|
+
lowestPrice: BigNumber3__default.default(0),
|
|
46143
|
+
highestPrice: BigNumber3__default.default(0)
|
|
46159
46144
|
},
|
|
46160
|
-
timestamp:
|
|
46145
|
+
timestamp: BigNumber3__default.default(Date.now())
|
|
46161
46146
|
};
|
|
46162
46147
|
oracleMap.set(bank.address.toBase58(), zeroOraclePrice);
|
|
46163
46148
|
});
|
|
@@ -46169,18 +46154,18 @@ function handleIsolatedAssetBanks(banks, staticPrices) {
|
|
|
46169
46154
|
const price = staticPrices?.[bank.address.toBase58()] ?? 0;
|
|
46170
46155
|
const oraclePrice = {
|
|
46171
46156
|
priceRealtime: {
|
|
46172
|
-
price:
|
|
46173
|
-
confidence:
|
|
46174
|
-
lowestPrice:
|
|
46175
|
-
highestPrice:
|
|
46157
|
+
price: BigNumber3__default.default(price),
|
|
46158
|
+
confidence: BigNumber3__default.default(0),
|
|
46159
|
+
lowestPrice: BigNumber3__default.default(price),
|
|
46160
|
+
highestPrice: BigNumber3__default.default(price)
|
|
46176
46161
|
},
|
|
46177
46162
|
priceWeighted: {
|
|
46178
|
-
price:
|
|
46179
|
-
confidence:
|
|
46180
|
-
lowestPrice:
|
|
46181
|
-
highestPrice:
|
|
46163
|
+
price: BigNumber3__default.default(price),
|
|
46164
|
+
confidence: BigNumber3__default.default(0),
|
|
46165
|
+
lowestPrice: BigNumber3__default.default(price),
|
|
46166
|
+
highestPrice: BigNumber3__default.default(price)
|
|
46182
46167
|
},
|
|
46183
|
-
timestamp:
|
|
46168
|
+
timestamp: BigNumber3__default.default(Date.now())
|
|
46184
46169
|
};
|
|
46185
46170
|
oracleMap.set(bank.address.toBase58(), oraclePrice);
|
|
46186
46171
|
});
|
|
@@ -46207,18 +46192,18 @@ async function handleAssetBanks(banks, opts) {
|
|
|
46207
46192
|
if (!oraclePrice) {
|
|
46208
46193
|
bankOraclePriceMap.set(bankAddress, {
|
|
46209
46194
|
priceRealtime: {
|
|
46210
|
-
price:
|
|
46211
|
-
confidence:
|
|
46212
|
-
lowestPrice:
|
|
46213
|
-
highestPrice:
|
|
46195
|
+
price: BigNumber3__default.default(0),
|
|
46196
|
+
confidence: BigNumber3__default.default(0),
|
|
46197
|
+
lowestPrice: BigNumber3__default.default(0),
|
|
46198
|
+
highestPrice: BigNumber3__default.default(0)
|
|
46214
46199
|
},
|
|
46215
46200
|
priceWeighted: {
|
|
46216
|
-
price:
|
|
46217
|
-
confidence:
|
|
46218
|
-
lowestPrice:
|
|
46219
|
-
highestPrice:
|
|
46201
|
+
price: BigNumber3__default.default(0),
|
|
46202
|
+
confidence: BigNumber3__default.default(0),
|
|
46203
|
+
lowestPrice: BigNumber3__default.default(0),
|
|
46204
|
+
highestPrice: BigNumber3__default.default(0)
|
|
46220
46205
|
},
|
|
46221
|
-
timestamp:
|
|
46206
|
+
timestamp: BigNumber3__default.default(Date.now())
|
|
46222
46207
|
});
|
|
46223
46208
|
}
|
|
46224
46209
|
});
|
|
@@ -46259,12 +46244,12 @@ function getAssetWeight(params) {
|
|
|
46259
46244
|
activeEmodeWeights,
|
|
46260
46245
|
ignoreSoftLimits
|
|
46261
46246
|
} = params;
|
|
46262
|
-
const assetWeightInit =
|
|
46263
|
-
activeEmodeWeights?.assetWeightInit ??
|
|
46247
|
+
const assetWeightInit = BigNumber3__default.default.max(
|
|
46248
|
+
activeEmodeWeights?.assetWeightInit ?? BigNumber3__default.default(0),
|
|
46264
46249
|
bank.config.assetWeightInit
|
|
46265
46250
|
);
|
|
46266
|
-
const assetWeightMaint =
|
|
46267
|
-
activeEmodeWeights?.assetWeightMaint ??
|
|
46251
|
+
const assetWeightMaint = BigNumber3__default.default.max(
|
|
46252
|
+
activeEmodeWeights?.assetWeightMaint ?? BigNumber3__default.default(0),
|
|
46268
46253
|
bank.config.assetWeightMaint
|
|
46269
46254
|
);
|
|
46270
46255
|
switch (marginRequirement) {
|
|
@@ -46288,7 +46273,7 @@ function getAssetWeight(params) {
|
|
|
46288
46273
|
case 1 /* Maintenance */:
|
|
46289
46274
|
return assetWeightMaint;
|
|
46290
46275
|
case 2 /* Equity */:
|
|
46291
|
-
return new
|
|
46276
|
+
return new BigNumber3__default.default(1);
|
|
46292
46277
|
default:
|
|
46293
46278
|
throw new Error("Invalid margin requirement type");
|
|
46294
46279
|
}
|
|
@@ -46300,7 +46285,7 @@ function getLiabilityWeight(config, marginRequirementType) {
|
|
|
46300
46285
|
case 1 /* Maintenance */:
|
|
46301
46286
|
return config.liabilityWeightMaint;
|
|
46302
46287
|
case 2 /* Equity */:
|
|
46303
|
-
return new
|
|
46288
|
+
return new BigNumber3__default.default(1);
|
|
46304
46289
|
default:
|
|
46305
46290
|
throw new Error("Invalid margin requirement type");
|
|
46306
46291
|
}
|
|
@@ -46328,17 +46313,17 @@ function computeLoopingParams(principal, targetLeverage, depositBank, borrowBank
|
|
|
46328
46313
|
);
|
|
46329
46314
|
clampedLeverage = maxLeverage;
|
|
46330
46315
|
}
|
|
46331
|
-
const totalDepositAmount = initialCollateral.times(new
|
|
46316
|
+
const totalDepositAmount = initialCollateral.times(new BigNumber3__default.default(clampedLeverage));
|
|
46332
46317
|
const additionalDepositAmount = totalDepositAmount.minus(initialCollateral);
|
|
46333
46318
|
const totalBorrowAmount = additionalDepositAmount.times(depositOracleInfo.priceWeighted.lowestPrice).div(borrowOracleInfo.priceWeighted.highestPrice);
|
|
46334
46319
|
return {
|
|
46335
46320
|
totalBorrowAmount: totalBorrowAmount.decimalPlaces(
|
|
46336
46321
|
borrowBank.mintDecimals,
|
|
46337
|
-
|
|
46322
|
+
BigNumber3__default.default.ROUND_DOWN
|
|
46338
46323
|
),
|
|
46339
46324
|
totalDepositAmount: totalDepositAmount.decimalPlaces(
|
|
46340
46325
|
depositBank.mintDecimals,
|
|
46341
|
-
|
|
46326
|
+
BigNumber3__default.default.ROUND_DOWN
|
|
46342
46327
|
)
|
|
46343
46328
|
};
|
|
46344
46329
|
}
|
|
@@ -46349,7 +46334,7 @@ function computeUsdValue(params) {
|
|
|
46349
46334
|
quantity,
|
|
46350
46335
|
priceBias,
|
|
46351
46336
|
isWeightedPrice: isWeightedPrice2,
|
|
46352
|
-
weight = new
|
|
46337
|
+
weight = new BigNumber3__default.default(1),
|
|
46353
46338
|
scaleToBase = true,
|
|
46354
46339
|
assetShareValueMultiplier
|
|
46355
46340
|
} = params;
|
|
@@ -46484,16 +46469,16 @@ function computeInterestRates(bank) {
|
|
|
46484
46469
|
const baseInterestRate = computeBaseInterestRate(bank);
|
|
46485
46470
|
const utilizationRate = computeUtilizationRate(bank);
|
|
46486
46471
|
const lendingRate = baseInterestRate.times(utilizationRate);
|
|
46487
|
-
const borrowingRate = baseInterestRate.times(new
|
|
46472
|
+
const borrowingRate = baseInterestRate.times(new BigNumber3__default.default(1).plus(rateFee)).plus(fixedFee);
|
|
46488
46473
|
return { lendingRate, borrowingRate };
|
|
46489
46474
|
}
|
|
46490
46475
|
var U32_MAX = 4294967295;
|
|
46491
46476
|
function rateFromU32(rate) {
|
|
46492
|
-
const ratio = new
|
|
46477
|
+
const ratio = new BigNumber3__default.default(rate).div(U32_MAX);
|
|
46493
46478
|
return ratio.times(10);
|
|
46494
46479
|
}
|
|
46495
46480
|
function utilFromU32(util) {
|
|
46496
|
-
return new
|
|
46481
|
+
return new BigNumber3__default.default(util).div(U32_MAX);
|
|
46497
46482
|
}
|
|
46498
46483
|
function calculateRateBetweenPoints(startX, startY, endX, endY, targetX) {
|
|
46499
46484
|
if (endX.lte(startX)) return startY;
|
|
@@ -46512,15 +46497,15 @@ function computeLegacyCurve(utilizationRate, optimalUtilizationRate, plateauInte
|
|
|
46512
46497
|
if (utilizationRate.lte(optimalUtilizationRate)) {
|
|
46513
46498
|
return utilizationRate.times(plateauInterestRate).div(optimalUtilizationRate);
|
|
46514
46499
|
} else {
|
|
46515
|
-
return utilizationRate.minus(optimalUtilizationRate).div(new
|
|
46500
|
+
return utilizationRate.minus(optimalUtilizationRate).div(new BigNumber3__default.default(1).minus(optimalUtilizationRate)).times(maxInterestRate.minus(plateauInterestRate)).plus(plateauInterestRate);
|
|
46516
46501
|
}
|
|
46517
46502
|
}
|
|
46518
46503
|
function computeMultipointCurve(utilizationRate, zeroUtilRate, hundredUtilRate, points) {
|
|
46519
46504
|
const zeroRate = rateFromU32(zeroUtilRate);
|
|
46520
46505
|
const hundredRate = rateFromU32(hundredUtilRate);
|
|
46521
|
-
const clampedUtilizationRate =
|
|
46506
|
+
const clampedUtilizationRate = BigNumber3__default.default.max(0, BigNumber3__default.default.min(1, utilizationRate));
|
|
46522
46507
|
const nonPaddingPoints = points.filter((point) => point.util !== 0);
|
|
46523
|
-
let prevUtil = new
|
|
46508
|
+
let prevUtil = new BigNumber3__default.default(0);
|
|
46524
46509
|
let prevRate = zeroRate;
|
|
46525
46510
|
for (const point of nonPaddingPoints) {
|
|
46526
46511
|
const pointUtil = utilFromU32(point.util);
|
|
@@ -46540,7 +46525,7 @@ function computeMultipointCurve(utilizationRate, zeroUtilRate, hundredUtilRate,
|
|
|
46540
46525
|
return calculateRateBetweenPoints(
|
|
46541
46526
|
prevUtil,
|
|
46542
46527
|
prevRate,
|
|
46543
|
-
new
|
|
46528
|
+
new BigNumber3__default.default(1),
|
|
46544
46529
|
hundredRate,
|
|
46545
46530
|
clampedUtilizationRate
|
|
46546
46531
|
);
|
|
@@ -46568,16 +46553,16 @@ function computeBaseInterestRate(bank) {
|
|
|
46568
46553
|
function computeUtilizationRate(bank) {
|
|
46569
46554
|
const assets = getTotalAssetQuantity(bank);
|
|
46570
46555
|
const liabilities = getTotalLiabilityQuantity(bank);
|
|
46571
|
-
if (assets.isZero()) return new
|
|
46556
|
+
if (assets.isZero()) return new BigNumber3__default.default(0);
|
|
46572
46557
|
return liabilities.div(assets);
|
|
46573
46558
|
}
|
|
46574
46559
|
var SECONDS_PER_DAY = 24 * 60 * 60;
|
|
46575
46560
|
var SECONDS_PER_YEAR = SECONDS_PER_DAY * 365.25;
|
|
46576
46561
|
function computeRemainingCapacity(bank) {
|
|
46577
46562
|
const totalDeposits = getTotalAssetQuantity(bank);
|
|
46578
|
-
const remainingCapacity =
|
|
46563
|
+
const remainingCapacity = BigNumber3__default.default.max(0, bank.config.depositLimit.minus(totalDeposits));
|
|
46579
46564
|
const totalBorrows = getTotalLiabilityQuantity(bank);
|
|
46580
|
-
const remainingBorrowCapacity =
|
|
46565
|
+
const remainingBorrowCapacity = BigNumber3__default.default.max(0, bank.config.borrowLimit.minus(totalBorrows));
|
|
46581
46566
|
const durationSinceLastAccrual = Date.now() / 1e3 - bank.lastUpdate;
|
|
46582
46567
|
const { lendingRate, borrowingRate } = computeInterestRates(bank);
|
|
46583
46568
|
const outstandingLendingInterest = lendingRate.times(durationSinceLastAccrual).dividedBy(SECONDS_PER_YEAR).times(totalDeposits);
|
|
@@ -47082,7 +47067,7 @@ async function getKaminoStatesDto(connection, kaminoBanks) {
|
|
|
47082
47067
|
}
|
|
47083
47068
|
function getKaminoCTokenMultiplier(reserve) {
|
|
47084
47069
|
const [totalLiquidity, totalCollateral] = scaledSupplies(reserve);
|
|
47085
|
-
return totalCollateral.isZero() ? new
|
|
47070
|
+
return totalCollateral.isZero() ? new BigNumber3__default.default(1) : new BigNumber3__default.default(totalLiquidity.dividedBy(totalCollateral).toString());
|
|
47086
47071
|
}
|
|
47087
47072
|
async function getDriftMetadata(options) {
|
|
47088
47073
|
const driftBanks = options.banks.filter((b) => b.config.assetTag === 4 /* DRIFT */);
|
|
@@ -47111,9 +47096,9 @@ async function getDriftMetadata(options) {
|
|
|
47111
47096
|
for (const [bankAddress, state] of Object.entries(driftStates)) {
|
|
47112
47097
|
driftMetadataMap.set(bankAddress, {
|
|
47113
47098
|
driftStates: {
|
|
47114
|
-
|
|
47115
|
-
|
|
47116
|
-
|
|
47099
|
+
spotMarketState: dtoToDriftSpotMarketRaw(state.driftSpotMarketState),
|
|
47100
|
+
userState: dtoToDriftUserRaw(state.driftUserState),
|
|
47101
|
+
userRewards: state.driftUserRewards.map((r) => dtoToDriftRewardsRaw(r))
|
|
47117
47102
|
}
|
|
47118
47103
|
});
|
|
47119
47104
|
}
|
|
@@ -47175,8 +47160,8 @@ async function getDriftStatesDto(connection, driftBanks) {
|
|
|
47175
47160
|
return driftStatesMap;
|
|
47176
47161
|
}
|
|
47177
47162
|
function getDriftCTokenMultiplier(spotMarket) {
|
|
47178
|
-
const cumulativeDepositInterest = new
|
|
47179
|
-
const SPOT_BALANCE_PRECISION = new
|
|
47163
|
+
const cumulativeDepositInterest = new BigNumber3__default.default(spotMarket.cumulativeDepositInterest.toNumber());
|
|
47164
|
+
const SPOT_BALANCE_PRECISION = new BigNumber3__default.default(10).pow(19 - spotMarket.decimals);
|
|
47180
47165
|
return cumulativeDepositInterest.dividedBy(SPOT_BALANCE_PRECISION);
|
|
47181
47166
|
}
|
|
47182
47167
|
|
|
@@ -47369,11 +47354,11 @@ var Bank = class _Bank {
|
|
|
47369
47354
|
const newBank = Object.create(_Bank.prototype);
|
|
47370
47355
|
Object.assign(newBank, bank);
|
|
47371
47356
|
newBank.config = Object.assign({}, bank.config);
|
|
47372
|
-
newBank.config.assetWeightInit =
|
|
47357
|
+
newBank.config.assetWeightInit = BigNumber3__default.default.max(
|
|
47373
47358
|
bank.config.assetWeightInit,
|
|
47374
47359
|
emodeWeights.assetWeightInit
|
|
47375
47360
|
);
|
|
47376
|
-
newBank.config.assetWeightMaint =
|
|
47361
|
+
newBank.config.assetWeightMaint = BigNumber3__default.default.max(
|
|
47377
47362
|
bank.config.assetWeightMaint,
|
|
47378
47363
|
emodeWeights.assetWeightMaint
|
|
47379
47364
|
);
|
|
@@ -48232,9 +48217,9 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48232
48217
|
*
|
|
48233
48218
|
* @see {@link makeWrapSolIxs} and {@link makeUnwrapSolIx} for wrap/unwrap implementation
|
|
48234
48219
|
*/
|
|
48235
|
-
wrapInstructionForWSol(ix, amount = new
|
|
48220
|
+
wrapInstructionForWSol(ix, amount = new BigNumber3__default.default(0)) {
|
|
48236
48221
|
return [
|
|
48237
|
-
...makeWrapSolIxs(this.authority, new
|
|
48222
|
+
...makeWrapSolIxs(this.authority, new BigNumber3__default.default(amount)),
|
|
48238
48223
|
ix,
|
|
48239
48224
|
makeUnwrapSolIx(this.authority)
|
|
48240
48225
|
];
|
|
@@ -48270,7 +48255,12 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48270
48255
|
async makeLoopTx(params) {
|
|
48271
48256
|
return makeLoopTx({
|
|
48272
48257
|
...params,
|
|
48273
|
-
marginfiAccount: this
|
|
48258
|
+
marginfiAccount: this,
|
|
48259
|
+
overrideInferAccounts: {
|
|
48260
|
+
authority: this.authority,
|
|
48261
|
+
group: this.group,
|
|
48262
|
+
...params.overrideInferAccounts
|
|
48263
|
+
}
|
|
48274
48264
|
});
|
|
48275
48265
|
}
|
|
48276
48266
|
/**
|
|
@@ -48304,7 +48294,12 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48304
48294
|
async makeRepayWithCollatTx(params) {
|
|
48305
48295
|
return makeRepayWithCollatTx({
|
|
48306
48296
|
...params,
|
|
48307
|
-
marginfiAccount: this
|
|
48297
|
+
marginfiAccount: this,
|
|
48298
|
+
overrideInferAccounts: {
|
|
48299
|
+
authority: this.authority,
|
|
48300
|
+
group: this.group,
|
|
48301
|
+
...params.overrideInferAccounts
|
|
48302
|
+
}
|
|
48308
48303
|
});
|
|
48309
48304
|
}
|
|
48310
48305
|
/**
|
|
@@ -48339,7 +48334,12 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48339
48334
|
async makeSwapCollateralTx(params) {
|
|
48340
48335
|
return makeSwapCollateralTx({
|
|
48341
48336
|
...params,
|
|
48342
|
-
marginfiAccount: this
|
|
48337
|
+
marginfiAccount: this,
|
|
48338
|
+
overrideInferAccounts: {
|
|
48339
|
+
authority: this.authority,
|
|
48340
|
+
group: this.group,
|
|
48341
|
+
...params.overrideInferAccounts
|
|
48342
|
+
}
|
|
48343
48343
|
});
|
|
48344
48344
|
}
|
|
48345
48345
|
/**
|
|
@@ -48373,7 +48373,12 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48373
48373
|
async makeSwapDebtTx(params) {
|
|
48374
48374
|
return makeSwapDebtTx({
|
|
48375
48375
|
...params,
|
|
48376
|
-
marginfiAccount: this
|
|
48376
|
+
marginfiAccount: this,
|
|
48377
|
+
overrideInferAccounts: {
|
|
48378
|
+
authority: this.authority,
|
|
48379
|
+
group: this.group,
|
|
48380
|
+
...params.overrideInferAccounts
|
|
48381
|
+
}
|
|
48377
48382
|
});
|
|
48378
48383
|
}
|
|
48379
48384
|
/**
|
|
@@ -48435,7 +48440,14 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48435
48440
|
async makeBorrowTx(params) {
|
|
48436
48441
|
return makeBorrowTx({
|
|
48437
48442
|
...params,
|
|
48438
|
-
marginfiAccount: this
|
|
48443
|
+
marginfiAccount: this,
|
|
48444
|
+
opts: {
|
|
48445
|
+
...params.opts,
|
|
48446
|
+
overrideInferAccounts: {
|
|
48447
|
+
authority: this.authority,
|
|
48448
|
+
...params.opts?.overrideInferAccounts
|
|
48449
|
+
}
|
|
48450
|
+
}
|
|
48439
48451
|
});
|
|
48440
48452
|
}
|
|
48441
48453
|
/**
|
|
@@ -48464,7 +48476,15 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48464
48476
|
async makeWithdrawTx(params) {
|
|
48465
48477
|
return makeWithdrawTx({
|
|
48466
48478
|
...params,
|
|
48467
|
-
marginfiAccount: this
|
|
48479
|
+
marginfiAccount: this,
|
|
48480
|
+
opts: {
|
|
48481
|
+
...params.opts,
|
|
48482
|
+
overrideInferAccounts: {
|
|
48483
|
+
authority: this.authority,
|
|
48484
|
+
group: this.group,
|
|
48485
|
+
...params.opts?.overrideInferAccounts
|
|
48486
|
+
}
|
|
48487
|
+
}
|
|
48468
48488
|
});
|
|
48469
48489
|
}
|
|
48470
48490
|
/**
|
|
@@ -48478,7 +48498,15 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48478
48498
|
async makeDriftWithdrawTx(params) {
|
|
48479
48499
|
return makeDriftWithdrawTx({
|
|
48480
48500
|
...params,
|
|
48481
|
-
marginfiAccount: this
|
|
48501
|
+
marginfiAccount: this,
|
|
48502
|
+
opts: {
|
|
48503
|
+
...params.opts,
|
|
48504
|
+
overrideInferAccounts: {
|
|
48505
|
+
authority: this.authority,
|
|
48506
|
+
group: this.group,
|
|
48507
|
+
...params.opts?.overrideInferAccounts
|
|
48508
|
+
}
|
|
48509
|
+
}
|
|
48482
48510
|
});
|
|
48483
48511
|
}
|
|
48484
48512
|
/**
|
|
@@ -48492,7 +48520,15 @@ var MarginfiAccount = class _MarginfiAccount {
|
|
|
48492
48520
|
async makeKaminoWithdrawTx(params) {
|
|
48493
48521
|
return makeKaminoWithdrawTx({
|
|
48494
48522
|
...params,
|
|
48495
|
-
marginfiAccount: this
|
|
48523
|
+
marginfiAccount: this,
|
|
48524
|
+
opts: {
|
|
48525
|
+
...params.opts,
|
|
48526
|
+
overrideInferAccounts: {
|
|
48527
|
+
authority: this.authority,
|
|
48528
|
+
group: this.group,
|
|
48529
|
+
...params.opts?.overrideInferAccounts
|
|
48530
|
+
}
|
|
48531
|
+
}
|
|
48496
48532
|
});
|
|
48497
48533
|
}
|
|
48498
48534
|
/**
|
|
@@ -48607,7 +48643,7 @@ var MarginfiAccountWrapper = class {
|
|
|
48607
48643
|
* @param opts - Optional configuration for wrapping SOL and overrides
|
|
48608
48644
|
*/
|
|
48609
48645
|
async makeDepositIx(bankAddress, amount, opts = {}) {
|
|
48610
|
-
if (new
|
|
48646
|
+
if (new BigNumber3__default.default(amount).lte(0)) {
|
|
48611
48647
|
throw Error(`Deposit amount must be positive, got ${amount}`);
|
|
48612
48648
|
}
|
|
48613
48649
|
const bank = await this.getBankFromAddress(bankAddress);
|
|
@@ -48631,7 +48667,7 @@ var MarginfiAccountWrapper = class {
|
|
|
48631
48667
|
* @param opts - Optional configuration for wrapping SOL and overrides
|
|
48632
48668
|
*/
|
|
48633
48669
|
async makeRepayIx(bankAddress, amount, repayAll = false, opts = {}) {
|
|
48634
|
-
if (!repayAll && new
|
|
48670
|
+
if (!repayAll && new BigNumber3__default.default(amount).lte(0)) {
|
|
48635
48671
|
throw Error(`Repay amount must be positive, got ${amount}`);
|
|
48636
48672
|
}
|
|
48637
48673
|
const bank = await this.getBankFromAddress(bankAddress);
|
|
@@ -48656,7 +48692,7 @@ var MarginfiAccountWrapper = class {
|
|
|
48656
48692
|
* @param opts - Optional configuration for unwrapping SOL and overrides
|
|
48657
48693
|
*/
|
|
48658
48694
|
async makeWithdrawIx(bankAddress, amount, withdrawAll = false, opts = {}) {
|
|
48659
|
-
if (!withdrawAll && new
|
|
48695
|
+
if (!withdrawAll && new BigNumber3__default.default(amount).lte(0)) {
|
|
48660
48696
|
throw Error(`Withdraw amount must be positive, got ${amount}`);
|
|
48661
48697
|
}
|
|
48662
48698
|
const bank = await this.getBankFromAddress(bankAddress);
|
|
@@ -48682,7 +48718,7 @@ var MarginfiAccountWrapper = class {
|
|
|
48682
48718
|
* @param opts - Optional configuration for unwrapping SOL and overrides
|
|
48683
48719
|
*/
|
|
48684
48720
|
async makeBorrowIx(bankAddress, amount, opts = {}) {
|
|
48685
|
-
if (new
|
|
48721
|
+
if (new BigNumber3__default.default(amount).lte(0)) {
|
|
48686
48722
|
throw Error(`Borrow amount must be positive, got ${amount}`);
|
|
48687
48723
|
}
|
|
48688
48724
|
const bank = await this.getBankFromAddress(bankAddress);
|
|
@@ -49441,7 +49477,7 @@ var Project0Client = class _Project0Client {
|
|
|
49441
49477
|
const reserve = bankIntegrationMap[bank.address.toBase58()]?.kaminoStates?.reserveState;
|
|
49442
49478
|
if (!reserve) {
|
|
49443
49479
|
console.error(`No Kamino reserve found for bank ${bank.address.toBase58()}`);
|
|
49444
|
-
assetShareMultiplierByBank.set(bank.address.toBase58(), new
|
|
49480
|
+
assetShareMultiplierByBank.set(bank.address.toBase58(), new BigNumber3__default.default(1));
|
|
49445
49481
|
break;
|
|
49446
49482
|
}
|
|
49447
49483
|
assetShareMultiplierByBank.set(
|
|
@@ -49453,7 +49489,7 @@ var Project0Client = class _Project0Client {
|
|
|
49453
49489
|
const spotMarket = bankIntegrationMap[bank.address.toBase58()]?.driftStates?.spotMarketState;
|
|
49454
49490
|
if (!spotMarket) {
|
|
49455
49491
|
console.error(`No Drift spot market found for bank ${bank.address.toBase58()}`);
|
|
49456
|
-
assetShareMultiplierByBank.set(bank.address.toBase58(), new
|
|
49492
|
+
assetShareMultiplierByBank.set(bank.address.toBase58(), new BigNumber3__default.default(1));
|
|
49457
49493
|
break;
|
|
49458
49494
|
}
|
|
49459
49495
|
assetShareMultiplierByBank.set(
|
|
@@ -49462,15 +49498,15 @@ var Project0Client = class _Project0Client {
|
|
|
49462
49498
|
);
|
|
49463
49499
|
break;
|
|
49464
49500
|
case 5 /* SOLEND */:
|
|
49465
|
-
assetShareMultiplierByBank.set(bank.address.toBase58(), new
|
|
49501
|
+
assetShareMultiplierByBank.set(bank.address.toBase58(), new BigNumber3__default.default(1));
|
|
49466
49502
|
break;
|
|
49467
49503
|
case 2 /* STAKED */:
|
|
49468
|
-
assetShareMultiplierByBank.set(bank.address.toBase58(), new
|
|
49504
|
+
assetShareMultiplierByBank.set(bank.address.toBase58(), new BigNumber3__default.default(1));
|
|
49469
49505
|
break;
|
|
49470
49506
|
case 0 /* DEFAULT */:
|
|
49471
49507
|
case 1 /* SOL */:
|
|
49472
49508
|
default:
|
|
49473
|
-
assetShareMultiplierByBank.set(bank.address.toBase58(), new
|
|
49509
|
+
assetShareMultiplierByBank.set(bank.address.toBase58(), new BigNumber3__default.default(1));
|
|
49474
49510
|
break;
|
|
49475
49511
|
}
|
|
49476
49512
|
});
|