@haven-fi/solauto-sdk 1.0.42 → 1.0.44
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/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +0 -1
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +4 -5
- package/dist/utils/generalUtils.js +1 -1
- package/dist/utils/jupiterUtils.js +1 -1
- package/dist/utils/marginfiUtils.d.ts +7 -1
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +38 -17
- package/dist/utils/solauto/generalUtils.js +1 -1
- package/package.json +1 -1
- package/src/clients/solautoMarginfiClient.ts +0 -1
- package/src/transactions/transactionsManager.ts +4 -11
- package/src/utils/generalUtils.ts +1 -1
- package/src/utils/jupiterUtils.ts +2 -2
- package/src/utils/marginfiUtils.ts +73 -33
- package/src/utils/solauto/generalUtils.ts +1 -1
- package/tests/transactions/solautoMarginfi.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAK1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAUhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,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AAU,CAAC,IAAI,EAAE,yBAAyB;IA0C1C,8BAA8B;IA0CpC,mBAAmB,IAAI,MAAM,EAAE;IAI/B,gBAAgB,IAAI,SAAS,EAAE;IAQ/B,yBAAyB,IAAI,kBAAkB;IAS/C,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA6C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA8D5C,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IA2DrB,WAAW,CACT,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IA8ElE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAiBlE"}
|
|
@@ -261,7 +261,6 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
|
261
261
|
const needDebtAccounts = (!inputIsSupply && rebalanceStep === "A") ||
|
|
262
262
|
(!outputIsSupply && rebalanceStep === "B") ||
|
|
263
263
|
(!inputIsSupply && flashLoan !== undefined && rebalanceStep == "B");
|
|
264
|
-
console.log(rebalanceStep, needDebtAccounts);
|
|
265
264
|
return (0, generated_1.marginfiRebalance)(this.umi, {
|
|
266
265
|
signer: this.signer,
|
|
267
266
|
marginfiProgram: (0, umi_1.publicKey)(marginfi_sdk_1.MARGINFI_PROGRAM_ID),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EAGvB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAK/B,cAAM,YAAY;IAIJ,OAAO,CAAC,MAAM;IAH1B,WAAW,EAAE,MAAM,EAAE,CAAM;IAC3B,KAAK,EAAE,uBAAuB,EAAE,CAAM;gBAElB,MAAM,EAAE,aAAa;IAInC,YAAY,CAChB,mBAAmB,EAAE,MAAM,EAAE,GAC5B,OAAO,CAAC,uBAAuB,EAAE,CAAC;CAqBtC;AAED,qBAAa,eAAe;IAKjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CACV;QAAE,EAAE,EAAE,kBAAkB,CAAC;QAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,SAAS,CACxE;IACM,IAAI,CAAC;IATd,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;gBAGf,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CACV;QAAE,EAAE,EAAE,kBAAkB,CAAC;QAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,SAAS,CACxE,EACM,IAAI,CAAC,oBAAQ;IAGhB,UAAU;IAIV,OAAO,CAAC,UAAU,EAAE,MAAM;IAMhC,cAAc,IAAI,MAAM,EAAE;CAY3B;AAED,cAAM,cAAc;IAEhB,OAAO,CAAC,MAAM;IACP,YAAY,EAAE,YAAY;IAC1B,KAAK,EAAE,eAAe,EAAE;gBAFvB,MAAM,EAAE,aAAa,EACtB,YAAY,EAAE,YAAY,EAC1B,KAAK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e,EAAE;IAMzB,UAAU,CAAC,UAAU,EAAE,MAAM;IAO7B,oBAAoB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAYzD,YAAY,IAAI,MAAM,EAAE;IAMxB,IAAI,IAAI,MAAM;CAYf;AAED,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,UAAU,eAAe;CAC1B;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,EAAE,CAAC;AAEJ,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,YAAY,CAAC;IACrB,OAAO,CAAC,YAAY,CAAC;IACrB,OAAO,CAAC,aAAa,CAAC;IATxB,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,YAAY,CAAe;gBAGzB,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,eAAe,EAAE,EACxB,cAAc,CAAC,6CAA4C,IAAI,aAAA,EAC/D,YAAY,CAAC,qBAAS,EACtB,YAAY,CAAC,qBAAS,EACtB,aAAa,CAAC,2BAAe;YAKzB,uBAAuB;IA0CrC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,KAAK,CAAC,EAAE,MAAM;IAiB9D,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,kBAAkB;IAsB7D,IAAI;CAyJX"}
|
|
@@ -191,13 +191,12 @@ class TransactionsManager {
|
|
|
191
191
|
for (const ix of tx.getInstructions()) {
|
|
192
192
|
const ixAccounts = ix.keys.map((x) => x.pubkey);
|
|
193
193
|
const accountsNotInLut = ixAccounts.filter((x) => !lutAccounts.includes(x));
|
|
194
|
-
|
|
194
|
+
this.client.log(`Program ${ix.programId}, data len: ${ix.data.length}, LUT accounts data: ${ix.keys.filter((x) => lutAccounts.includes(x.pubkey)).length * 3}`);
|
|
195
195
|
if (accountsNotInLut.length > 0) {
|
|
196
|
-
|
|
196
|
+
this.client.log(`${accountsNotInLut.length} accounts not in LUT:`);
|
|
197
197
|
for (const key of accountsNotInLut) {
|
|
198
|
-
|
|
198
|
+
this.client.log(key.toString());
|
|
199
199
|
}
|
|
200
|
-
console.log(ix.keys.length);
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
202
|
}
|
|
@@ -290,7 +289,7 @@ class TransactionsManager {
|
|
|
290
289
|
const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.client.umi, this.client.connection, tx, this.simulateOnly, attemptNum);
|
|
291
290
|
this.updateStatus(itemSet.name(), TransactionStatus.Successful, txSig ? bs58_1.default.encode(txSig) : undefined);
|
|
292
291
|
}
|
|
293
|
-
},
|
|
292
|
+
}, 4, 150, this.errorsToThrow);
|
|
294
293
|
}
|
|
295
294
|
}
|
|
296
295
|
if (!this.simulateOnly) {
|
|
@@ -94,7 +94,7 @@ function retryWithExponentialBackoff(fn, retries = 5, delay = 150, errorsToThrow
|
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
96
|
if (attemptNum < retries) {
|
|
97
|
-
console.log(error
|
|
97
|
+
console.log(error);
|
|
98
98
|
setTimeout(() => {
|
|
99
99
|
console.log("Retrying...");
|
|
100
100
|
return attempt(attemptNum);
|
|
@@ -34,7 +34,7 @@ async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
|
|
|
34
34
|
slippageBps: 10,
|
|
35
35
|
maxAccounts: 60,
|
|
36
36
|
}), 3);
|
|
37
|
-
const finalPriceSlippageBps = Math.round(Math.max(quoteResponse.slippageBps
|
|
37
|
+
const finalPriceSlippageBps = Math.round(Math.max(quoteResponse.slippageBps, Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct))) + 1) *
|
|
38
38
|
(1 + (swapDetails.slippageBpsIncFactor ?? 0)));
|
|
39
39
|
quoteResponse.slippageBps = finalPriceSlippageBps;
|
|
40
40
|
console.log(quoteResponse);
|
|
@@ -8,7 +8,13 @@ export declare function findMarginfiAccounts({ mint, bank, }: {
|
|
|
8
8
|
mint?: string;
|
|
9
9
|
bank?: string;
|
|
10
10
|
}): MarginfiAssetAccounts;
|
|
11
|
-
export declare function getMaxLtvAndLiqThreshold(
|
|
11
|
+
export declare function getMaxLtvAndLiqThreshold(umi: Umi, supply: {
|
|
12
|
+
mint: PublicKey;
|
|
13
|
+
bank: Bank | null;
|
|
14
|
+
}, debt: {
|
|
15
|
+
mint: PublicKey;
|
|
16
|
+
bank: Bank | null;
|
|
17
|
+
}, supplyPrice?: number): Promise<[number, number]>;
|
|
12
18
|
export declare function getAllMarginfiAccountsByAuthority(umi: Umi, authority: PublicKey, compatibleWithSolauto?: boolean): Promise<{
|
|
13
19
|
marginfiAccount: PublicKey;
|
|
14
20
|
supplyMint?: PublicKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAKL,MAAM,iBAAiB,CAAC;AAUzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D,wBAAgB,oBAAoB,CAAC,EACnC,IAAI,EACJ,IAAI,GACL,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,qBAAqB,CAWxB;AAED,wBAAsB,wBAAwB,CAC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AAC,EAAE,SAAS,EACtB,QAAQ,CAAC,EAAE,SAAS,EACpB,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CA+IpC;AA+DD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA0B3B"}
|
|
@@ -24,23 +24,35 @@ function findMarginfiAccounts({ mint, bank, }) {
|
|
|
24
24
|
throw new Error(`Marginfi accounts not found by the mint: ${mint}`);
|
|
25
25
|
}
|
|
26
26
|
exports.findMarginfiAccounts = findMarginfiAccounts;
|
|
27
|
-
async function getMaxLtvAndLiqThreshold(
|
|
27
|
+
async function getMaxLtvAndLiqThreshold(umi, supply, debt, supplyPrice) {
|
|
28
|
+
if (!supply.bank) {
|
|
29
|
+
supply.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(findMarginfiAccounts({
|
|
30
|
+
mint: supply.mint.toString(),
|
|
31
|
+
}).bank));
|
|
32
|
+
}
|
|
33
|
+
if (!debt.bank && !debt.mint.equals(web3_js_1.PublicKey.default)) {
|
|
34
|
+
debt.bank = await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(findMarginfiAccounts({
|
|
35
|
+
mint: debt.mint.toString(),
|
|
36
|
+
}).bank));
|
|
37
|
+
}
|
|
28
38
|
if (!supplyPrice) {
|
|
29
|
-
const [price] = await (0, generalUtils_1.getTokenPrices)([
|
|
39
|
+
const [price] = await (0, generalUtils_1.getTokenPrices)([
|
|
40
|
+
(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(supply.bank.mint),
|
|
41
|
+
]);
|
|
30
42
|
supplyPrice = price;
|
|
31
43
|
}
|
|
32
|
-
if (
|
|
44
|
+
if (debt.bank === null) {
|
|
33
45
|
return [0, 0];
|
|
34
46
|
}
|
|
35
|
-
let maxLtv = (0, numberUtils_1.bytesToI80F48)(
|
|
36
|
-
(0, numberUtils_1.bytesToI80F48)(
|
|
37
|
-
const liqThreshold = (0, numberUtils_1.bytesToI80F48)(
|
|
38
|
-
(0, numberUtils_1.bytesToI80F48)(
|
|
39
|
-
const totalDepositedUsdValue = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round((0, numberUtils_1.bytesToI80F48)(
|
|
40
|
-
(0, numberUtils_1.bytesToI80F48)(
|
|
41
|
-
if (
|
|
42
|
-
totalDepositedUsdValue >
|
|
43
|
-
const discount = Number(
|
|
47
|
+
let maxLtv = (0, numberUtils_1.bytesToI80F48)(supply.bank.config.assetWeightInit.value) /
|
|
48
|
+
(0, numberUtils_1.bytesToI80F48)(debt.bank.config.liabilityWeightInit.value);
|
|
49
|
+
const liqThreshold = (0, numberUtils_1.bytesToI80F48)(supply.bank.config.assetWeightMaint.value) /
|
|
50
|
+
(0, numberUtils_1.bytesToI80F48)(debt.bank.config.liabilityWeightMaint.value);
|
|
51
|
+
const totalDepositedUsdValue = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round((0, numberUtils_1.bytesToI80F48)(supply.bank.totalAssetShares.value) *
|
|
52
|
+
(0, numberUtils_1.bytesToI80F48)(supply.bank.assetShareValue.value))), supply.bank.mintDecimals) * supplyPrice;
|
|
53
|
+
if (supply.bank.config.totalAssetValueInitLimit !== BigInt(0) &&
|
|
54
|
+
totalDepositedUsdValue > supply.bank.config.totalAssetValueInitLimit) {
|
|
55
|
+
const discount = Number(supply.bank.config.totalAssetValueInitLimit) /
|
|
44
56
|
totalDepositedUsdValue;
|
|
45
57
|
maxLtv = Math.round(maxLtv * Number(discount));
|
|
46
58
|
}
|
|
@@ -106,13 +118,16 @@ async function getTokenUsage(umi, bank, isAsset, shares, amountUsedAdjustment) {
|
|
|
106
118
|
decimals: bank?.mintDecimals ?? 0,
|
|
107
119
|
amountUsed: {
|
|
108
120
|
baseUnit: BigInt(Math.round(amountUsed)),
|
|
109
|
-
baseAmountUsdValue: bank
|
|
110
|
-
|
|
121
|
+
baseAmountUsdValue: bank
|
|
122
|
+
? (0, numberUtils_1.toBaseUnit)((0, numberUtils_1.fromBaseUnit)(BigInt(Math.round(amountUsed)), bank.mintDecimals) *
|
|
123
|
+
marketPrice, generalAccounts_1.USD_DECIMALS)
|
|
124
|
+
: BigInt(0),
|
|
111
125
|
},
|
|
112
126
|
amountCanBeUsed: {
|
|
113
127
|
baseUnit: BigInt(Math.round(amountCanBeUsed)),
|
|
114
|
-
baseAmountUsdValue: bank
|
|
115
|
-
|
|
128
|
+
baseAmountUsdValue: bank
|
|
129
|
+
? (0, numberUtils_1.toBaseUnit)((0, numberUtils_1.fromBaseUnit)(BigInt(Math.round(amountCanBeUsed)), bank.mintDecimals) * marketPrice, generalAccounts_1.USD_DECIMALS)
|
|
130
|
+
: BigInt(0),
|
|
116
131
|
},
|
|
117
132
|
baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(marketPrice, generalAccounts_1.USD_DECIMALS),
|
|
118
133
|
flashLoanFeeBps: 0,
|
|
@@ -169,7 +184,13 @@ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, supplyMin
|
|
|
169
184
|
debtUsage = await getTokenUsage(umi, debtBank, false, 0, livePositionUpdates?.debtAdjustment);
|
|
170
185
|
}
|
|
171
186
|
const supplyPrice = solautoConstants_1.PRICES[supplyMint.toString()].price;
|
|
172
|
-
let [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(
|
|
187
|
+
let [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(umi, {
|
|
188
|
+
mint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(supplyBank.mint),
|
|
189
|
+
bank: supplyBank,
|
|
190
|
+
}, {
|
|
191
|
+
mint: debtBank ? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(debtBank.mint) : web3_js_1.PublicKey.default,
|
|
192
|
+
bank: debtBank,
|
|
193
|
+
}, supplyPrice);
|
|
173
194
|
const supplyUsd = (0, numberUtils_1.fromBaseUnit)(supplyUsage.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
|
174
195
|
const debtUsd = (0, numberUtils_1.fromBaseUnit)(debtUsage?.amountUsed?.baseAmountUsdValue ?? BigInt(0), generalAccounts_1.USD_DECIMALS);
|
|
175
196
|
return {
|
|
@@ -210,7 +210,7 @@ exports.getAllPositionsByAuthority = getAllPositionsByAuthority;
|
|
|
210
210
|
async function positionStateWithLatestPrices(umi, state, protocolAccount, lendingPlatform) {
|
|
211
211
|
if ((0, generalUtils_1.currentUnixSeconds)() - Number(state.lastUpdated) > 60 * 60 * 24 * 7) {
|
|
212
212
|
if (lendingPlatform === generated_1.LendingPlatform.Marginfi) {
|
|
213
|
-
return await (0, marginfiUtils_1.getMarginfiAccountPositionState)(umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint), (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.debt.mint)
|
|
213
|
+
return await (0, marginfiUtils_1.getMarginfiAccountPositionState)(umi, protocolAccount, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint), (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.debt.mint));
|
|
214
214
|
}
|
|
215
215
|
else {
|
|
216
216
|
throw new Error("Lending platorm not yet supported");
|
package/package.json
CHANGED
|
@@ -409,7 +409,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
409
409
|
(!outputIsSupply && rebalanceStep === "B") ||
|
|
410
410
|
(!inputIsSupply && flashLoan !== undefined && rebalanceStep == "B");
|
|
411
411
|
|
|
412
|
-
console.log(rebalanceStep, needDebtAccounts);
|
|
413
412
|
return marginfiRebalance(this.umi, {
|
|
414
413
|
signer: this.signer,
|
|
415
414
|
marginfiProgram: publicKey(MARGINFI_PROGRAM_ID),
|
|
@@ -265,19 +265,12 @@ export class TransactionsManager {
|
|
|
265
265
|
const accountsNotInLut = ixAccounts.filter(
|
|
266
266
|
(x) => !lutAccounts.includes(x)
|
|
267
267
|
);
|
|
268
|
-
|
|
269
|
-
"Program",
|
|
270
|
-
ix.programId,
|
|
271
|
-
" data ",
|
|
272
|
-
ix.data.length,
|
|
273
|
-
ix.keys.filter((x) => lutAccounts.includes(x.pubkey)).length * 3
|
|
274
|
-
);
|
|
268
|
+
this.client.log(`Program ${ix.programId}, data len: ${ix.data.length}, LUT accounts data: ${ix.keys.filter((x) => lutAccounts.includes(x.pubkey)).length * 3}`);
|
|
275
269
|
if (accountsNotInLut.length > 0) {
|
|
276
|
-
|
|
270
|
+
this.client.log(`${accountsNotInLut.length} accounts not in LUT:`);
|
|
277
271
|
for (const key of accountsNotInLut) {
|
|
278
|
-
|
|
272
|
+
this.client.log(key.toString());
|
|
279
273
|
}
|
|
280
|
-
console.log(ix.keys.length);
|
|
281
274
|
}
|
|
282
275
|
}
|
|
283
276
|
}
|
|
@@ -424,7 +417,7 @@ export class TransactionsManager {
|
|
|
424
417
|
);
|
|
425
418
|
}
|
|
426
419
|
},
|
|
427
|
-
|
|
420
|
+
4,
|
|
428
421
|
150,
|
|
429
422
|
this.errorsToThrow
|
|
430
423
|
);
|
|
@@ -73,8 +73,8 @@ export async function getJupSwapTransaction(
|
|
|
73
73
|
|
|
74
74
|
const finalPriceSlippageBps = Math.round(
|
|
75
75
|
Math.max(
|
|
76
|
-
quoteResponse.slippageBps
|
|
77
|
-
Math.round(toBps(parseFloat(quoteResponse.priceImpactPct)))
|
|
76
|
+
quoteResponse.slippageBps,
|
|
77
|
+
Math.round(toBps(parseFloat(quoteResponse.priceImpactPct))) + 1
|
|
78
78
|
) *
|
|
79
79
|
(1 + (swapDetails.slippageBpsIncFactor ?? 0))
|
|
80
80
|
);
|
|
@@ -43,42 +43,73 @@ export function findMarginfiAccounts({
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export async function getMaxLtvAndLiqThreshold(
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
umi: Umi,
|
|
47
|
+
supply: {
|
|
48
|
+
mint: PublicKey;
|
|
49
|
+
bank: Bank | null;
|
|
50
|
+
},
|
|
51
|
+
debt: {
|
|
52
|
+
mint: PublicKey;
|
|
53
|
+
bank: Bank | null;
|
|
54
|
+
},
|
|
48
55
|
supplyPrice?: number
|
|
49
56
|
): Promise<[number, number]> {
|
|
57
|
+
if (!supply.bank) {
|
|
58
|
+
supply.bank = await safeFetchBank(
|
|
59
|
+
umi,
|
|
60
|
+
publicKey(
|
|
61
|
+
findMarginfiAccounts({
|
|
62
|
+
mint: supply.mint.toString(),
|
|
63
|
+
}).bank
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!debt.bank && !debt.mint.equals(PublicKey.default)) {
|
|
69
|
+
debt.bank = await safeFetchBank(
|
|
70
|
+
umi,
|
|
71
|
+
publicKey(
|
|
72
|
+
findMarginfiAccounts({
|
|
73
|
+
mint: debt.mint.toString(),
|
|
74
|
+
}).bank
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
50
79
|
if (!supplyPrice) {
|
|
51
|
-
const [price] = await getTokenPrices([
|
|
80
|
+
const [price] = await getTokenPrices([
|
|
81
|
+
toWeb3JsPublicKey(supply.bank!.mint),
|
|
82
|
+
]);
|
|
52
83
|
supplyPrice = price;
|
|
53
84
|
}
|
|
54
85
|
|
|
55
|
-
if (
|
|
86
|
+
if (debt.bank === null) {
|
|
56
87
|
return [0, 0];
|
|
57
88
|
}
|
|
58
89
|
|
|
59
90
|
let maxLtv =
|
|
60
|
-
bytesToI80F48(
|
|
61
|
-
bytesToI80F48(
|
|
91
|
+
bytesToI80F48(supply.bank!.config.assetWeightInit.value) /
|
|
92
|
+
bytesToI80F48(debt.bank.config.liabilityWeightInit.value);
|
|
62
93
|
const liqThreshold =
|
|
63
|
-
bytesToI80F48(
|
|
64
|
-
bytesToI80F48(
|
|
94
|
+
bytesToI80F48(supply.bank!.config.assetWeightMaint.value) /
|
|
95
|
+
bytesToI80F48(debt.bank.config.liabilityWeightMaint.value);
|
|
65
96
|
|
|
66
97
|
const totalDepositedUsdValue =
|
|
67
98
|
fromBaseUnit(
|
|
68
99
|
BigInt(
|
|
69
100
|
Math.round(
|
|
70
|
-
bytesToI80F48(
|
|
71
|
-
bytesToI80F48(
|
|
101
|
+
bytesToI80F48(supply.bank!.totalAssetShares.value) *
|
|
102
|
+
bytesToI80F48(supply.bank!.assetShareValue.value)
|
|
72
103
|
)
|
|
73
104
|
),
|
|
74
|
-
|
|
105
|
+
supply.bank!.mintDecimals
|
|
75
106
|
) * supplyPrice!;
|
|
76
107
|
if (
|
|
77
|
-
|
|
78
|
-
totalDepositedUsdValue >
|
|
108
|
+
supply.bank!.config.totalAssetValueInitLimit !== BigInt(0) &&
|
|
109
|
+
totalDepositedUsdValue > supply.bank!.config.totalAssetValueInitLimit
|
|
79
110
|
) {
|
|
80
111
|
const discount =
|
|
81
|
-
Number(
|
|
112
|
+
Number(supply.bank!.config.totalAssetValueInitLimit) /
|
|
82
113
|
totalDepositedUsdValue;
|
|
83
114
|
maxLtv = Math.round(maxLtv * Number(discount));
|
|
84
115
|
}
|
|
@@ -158,7 +189,7 @@ async function getTokenUsage(
|
|
|
158
189
|
);
|
|
159
190
|
const shareValue = isAsset ? assetShareValue : liabilityShareValue;
|
|
160
191
|
amountUsed = shares * shareValue + Number(amountUsedAdjustment ?? 0);
|
|
161
|
-
|
|
192
|
+
|
|
162
193
|
const totalDeposited =
|
|
163
194
|
bytesToI80F48(bank.totalAssetShares.value) * assetShareValue;
|
|
164
195
|
amountCanBeUsed = isAsset
|
|
@@ -172,19 +203,25 @@ async function getTokenUsage(
|
|
|
172
203
|
decimals: bank?.mintDecimals ?? 0,
|
|
173
204
|
amountUsed: {
|
|
174
205
|
baseUnit: BigInt(Math.round(amountUsed)),
|
|
175
|
-
baseAmountUsdValue: bank
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
206
|
+
baseAmountUsdValue: bank
|
|
207
|
+
? toBaseUnit(
|
|
208
|
+
fromBaseUnit(BigInt(Math.round(amountUsed)), bank.mintDecimals) *
|
|
209
|
+
marketPrice,
|
|
210
|
+
USD_DECIMALS
|
|
211
|
+
)
|
|
212
|
+
: BigInt(0),
|
|
180
213
|
},
|
|
181
214
|
amountCanBeUsed: {
|
|
182
215
|
baseUnit: BigInt(Math.round(amountCanBeUsed)),
|
|
183
|
-
baseAmountUsdValue: bank
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
216
|
+
baseAmountUsdValue: bank
|
|
217
|
+
? toBaseUnit(
|
|
218
|
+
fromBaseUnit(
|
|
219
|
+
BigInt(Math.round(amountCanBeUsed)),
|
|
220
|
+
bank.mintDecimals
|
|
221
|
+
) * marketPrice,
|
|
222
|
+
USD_DECIMALS
|
|
223
|
+
)
|
|
224
|
+
: BigInt(0),
|
|
188
225
|
},
|
|
189
226
|
baseAmountMarketPriceUsd: toBaseUnit(marketPrice, USD_DECIMALS),
|
|
190
227
|
flashLoanFeeBps: 0,
|
|
@@ -211,18 +248,14 @@ export async function getMarginfiAccountPositionState(
|
|
|
211
248
|
supplyMint && supplyMint !== PublicKey.default
|
|
212
249
|
? await safeFetchBank(
|
|
213
250
|
umi,
|
|
214
|
-
publicKey(
|
|
215
|
-
findMarginfiAccounts({ mint: supplyMint.toString() }).bank
|
|
216
|
-
)
|
|
251
|
+
publicKey(findMarginfiAccounts({ mint: supplyMint.toString() }).bank)
|
|
217
252
|
)
|
|
218
253
|
: null;
|
|
219
254
|
let debtBank: Bank | null =
|
|
220
255
|
debtMint && debtMint !== PublicKey.default
|
|
221
256
|
? await safeFetchBank(
|
|
222
257
|
umi,
|
|
223
|
-
publicKey(
|
|
224
|
-
findMarginfiAccounts({ mint: debtMint.toString() }).bank
|
|
225
|
-
)
|
|
258
|
+
publicKey(findMarginfiAccounts({ mint: debtMint.toString() }).bank)
|
|
226
259
|
)
|
|
227
260
|
: null;
|
|
228
261
|
|
|
@@ -306,8 +339,15 @@ export async function getMarginfiAccountPositionState(
|
|
|
306
339
|
|
|
307
340
|
const supplyPrice = PRICES[supplyMint!.toString()].price;
|
|
308
341
|
let [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(
|
|
309
|
-
|
|
310
|
-
|
|
342
|
+
umi,
|
|
343
|
+
{
|
|
344
|
+
mint: toWeb3JsPublicKey(supplyBank.mint),
|
|
345
|
+
bank: supplyBank,
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
mint: debtBank ? toWeb3JsPublicKey(debtBank.mint) : PublicKey.default,
|
|
349
|
+
bank: debtBank,
|
|
350
|
+
},
|
|
311
351
|
supplyPrice
|
|
312
352
|
);
|
|
313
353
|
const supplyUsd = fromBaseUnit(
|
|
@@ -326,9 +326,9 @@ export async function positionStateWithLatestPrices(
|
|
|
326
326
|
if (lendingPlatform === LendingPlatform.Marginfi) {
|
|
327
327
|
return await getMarginfiAccountPositionState(
|
|
328
328
|
umi,
|
|
329
|
+
protocolAccount,
|
|
329
330
|
toWeb3JsPublicKey(state.supply.mint),
|
|
330
331
|
toWeb3JsPublicKey(state.debt.mint),
|
|
331
|
-
protocolAccount
|
|
332
332
|
);
|
|
333
333
|
} else {
|
|
334
334
|
throw new Error("Lending platorm not yet supported");
|