@haven-fi/solauto-sdk 1.0.572 → 1.0.573
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/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +0 -1
- package/dist/clients/solautoMarginfiClient.d.ts +0 -1
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +0 -20
- package/dist/utils/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +2 -2
- package/dist/utils/priceUtils.d.ts.map +1 -1
- package/dist/utils/priceUtils.js +33 -21
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +0 -1
- package/src/clients/solautoMarginfiClient.ts +2 -38
- package/src/utils/jupiterUtils.ts +1 -0
- package/src/utils/marginfiUtils.ts +2 -2
- package/src/utils/priceUtils.ts +47 -35
- package/tests/transactions/solautoMarginfi.ts +13 -214
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAEL,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAEhC,sBAAsB,EAKvB,MAAM,cAAc,CAAC;AAUtB,OAAO,EACL,gBAAgB,EAChB,eAAe,EAChB,MAAM,iCAAiC,CAAC;AAMzC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,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AmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAuFhE,QAAQ,CAAC,WAAW,CAClB,aAAa,EAAE,oBAAoB,EACnC,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IAErB,QAAQ,CAAC,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAE3E,QAAQ,CAAC,SAAS,CAChB,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,EACvC,eAAe,EAAE,eAAe,EAChC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAcjE,QAAQ,CAAC,wBAAwB,IAAI,MAAM;IAC3C,QAAQ,CAAC,0BAA0B,IAAI,MAAM;IAC7C,QAAQ,CAAC,sBAAsB,IAAI,MAAM;CAC1C"}
|
@@ -86,7 +86,6 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
86
86
|
// All other live position updates can be derived by getting a fresh position state, so we don't need to do anything else form contextUpdates
|
87
87
|
}
|
88
88
|
}
|
89
|
-
console.log("Resetting context updates...");
|
90
89
|
this.contextUpdates.reset();
|
91
90
|
}
|
92
91
|
defaultLookupTables() {
|
@@ -43,7 +43,6 @@ export declare class SolautoMarginfiClient extends SolautoClient {
|
|
43
43
|
rebalance(rebalanceStep: "A" | "B", jupQuote: QuoteResponse, rebalanceType: SolautoRebalanceTypeArgs, rebalanceValues: RebalanceValues, flashLoan?: FlashLoanDetails, targetLiqUtilizationRateBps?: number): TransactionBuilder;
|
44
44
|
flashBorrow(rebalanceType: SolautoRebalanceType, flashLoanDetails: FlashLoanDetails, destinationTokenAccount: PublicKey): TransactionBuilder;
|
45
45
|
flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder;
|
46
|
-
closeBalance(marginfiAccount: PublicKey, bank: PublicKey): TransactionBuilder;
|
47
46
|
getFreshPositionState(): Promise<PositionState | undefined>;
|
48
47
|
supplyLiquidityAvailable(): bigint;
|
49
48
|
supplyLiquidityDepositable(): bigint;
|
@@ -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;AAM1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EAGb,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAEtB,OAAO,EAGL,eAAe,
|
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;AAM1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EAGb,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAEtB,OAAO,EAGL,eAAe,EAUhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,gBAAgB,EAChB,eAAe,EAChB,MAAM,iCAAiC,CAAC;AAUzC,OAAO,EA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,kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA0D5C,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,EACvC,eAAe,EAAE,eAAe,EAChC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IA+ErB,WAAW,CACT,aAAa,EAAE,oBAAoB,EACnC,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2CrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAwF5D,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAmDjE,wBAAwB,IAAI,MAAM;IAIlC,0BAA0B,IAAI,MAAM;IAIpC,sBAAsB,IAAI,MAAM;CAGjC"}
|
@@ -443,12 +443,6 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
443
443
|
},
|
444
444
|
]);
|
445
445
|
}
|
446
|
-
const banksRequiringBalanceClose = Array.from(new Set([
|
447
|
-
accounts.data.bank,
|
448
|
-
...(this.intermediaryMarginfiAccount?.lendingAccount.balances ?? [])
|
449
|
-
.filter((x) => x.active && (0, numberUtils_1.bytesToI80F48)(x.liabilityShares.value) > 0)
|
450
|
-
.map((x) => x.bankPk.toString()),
|
451
|
-
]));
|
452
446
|
return (0, umi_1.transactionBuilder)()
|
453
447
|
.add((0, marginfi_sdk_1.lendingAccountRepay)(this.umi, {
|
454
448
|
amount: flashLoanDetails.baseUnitAmount,
|
@@ -460,25 +454,11 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
460
454
|
signer: this.signer,
|
461
455
|
signerTokenAccount: (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), flashLoanDetails.mint)),
|
462
456
|
}))
|
463
|
-
.add(banksRequiringBalanceClose.map((x) => this.closeBalance(this.intermediaryMarginfiAccountPk, new web3_js_1.PublicKey(x)))
|
464
|
-
// this.closeBalance(
|
465
|
-
// this.intermediaryMarginfiAccountPk,
|
466
|
-
// new PublicKey(accounts.data.bank)
|
467
|
-
// )
|
468
|
-
)
|
469
457
|
.add((0, marginfi_sdk_1.lendingAccountEndFlashloan)(this.umi, {
|
470
458
|
marginfiAccount: (0, umi_1.publicKey)(this.intermediaryMarginfiAccountPk),
|
471
459
|
signer: this.signer,
|
472
460
|
}).addRemainingAccounts(remainingAccounts));
|
473
461
|
}
|
474
|
-
closeBalance(marginfiAccount, bank) {
|
475
|
-
return (0, umi_1.transactionBuilder)().add((0, marginfi_sdk_1.lendingAccountCloseBalance)(this.umi, {
|
476
|
-
signer: this.signer,
|
477
|
-
marginfiAccount: (0, umi_1.publicKey)(marginfiAccount),
|
478
|
-
bank: (0, umi_1.publicKey)(bank),
|
479
|
-
marginfiGroup: (0, umi_1.publicKey)(this.marginfiGroup),
|
480
|
-
}));
|
481
|
-
}
|
482
462
|
async getFreshPositionState() {
|
483
463
|
const state = await super.getFreshPositionState();
|
484
464
|
if (state) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;
|
1
|
+
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAUrB,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,cAAe,SAAQ,YAAY;IAClD,iBAAiB,EAAE,SAAS,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAgBD,wBAAsB,WAAW,CAAC,WAAW,EAAE,YAAY,0BAkB1D;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,SAAS,EAAE,kBAAkB,CAAC;CAC/B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,CA2F7B;AAED,wBAAsB,eAAe,CACnC,KAAK,EAAE,SAAS,EAAE,EAClB,oBAAoB,CAAC,EAAE,OAAO;;GAwC/B"}
|
@@ -322,6 +322,6 @@ function getUpToDateShareValues(bank) {
|
|
322
322
|
}
|
323
323
|
function marginfiAccountEmpty(marginfiAccount) {
|
324
324
|
return (marginfiAccount.lendingAccount.balances.find((x) => x.bankPk.toString() !== web3_js_1.PublicKey.default.toString() &&
|
325
|
-
((0, numberUtils_1.bytesToI80F48)(x.assetShares.value)
|
326
|
-
(0, numberUtils_1.bytesToI80F48)(x.liabilityShares.value)
|
325
|
+
(Math.round((0, numberUtils_1.bytesToI80F48)(x.assetShares.value)) != 0 ||
|
326
|
+
Math.round((0, numberUtils_1.bytesToI80F48)(x.liabilityShares.value)) != 0)) === undefined);
|
327
327
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"priceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/priceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAcrE,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAyC5E;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,qBAwCrD;AAkBD,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CAsDnB;AAED,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,SAAS,EAAE,EAClB,oBAAoB,CAAC,EAAE,OAAO,qBAgB/B;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,SAAS,GAAG,YAAY,GAAG,MAAM,GAAG,SAAS,GAClD,MAAM,GAAG,SAAS,CAKpB"}
|
package/dist/utils/priceUtils.js
CHANGED
@@ -28,6 +28,7 @@ exports.getPythPrices = getPythPrices;
|
|
28
28
|
exports.getSwitchboardPrices = getSwitchboardPrices;
|
29
29
|
exports.getJupTokenPrices = getJupTokenPrices;
|
30
30
|
exports.safeGetPrice = safeGetPrice;
|
31
|
+
const web3_js_1 = require("@solana/web3.js");
|
31
32
|
const pythConstants_1 = require("../constants/pythConstants");
|
32
33
|
const numberUtils_1 = require("./numberUtils");
|
33
34
|
const solautoConstants_1 = require("../constants/solautoConstants");
|
@@ -89,47 +90,58 @@ async function getPythPrices(mints) {
|
|
89
90
|
}, 5, 200);
|
90
91
|
return prices;
|
91
92
|
}
|
93
|
+
function getSortedPriceData(prices, mints) {
|
94
|
+
const sortedPrices = {};
|
95
|
+
for (const mint of mints) {
|
96
|
+
const key = mint.toString();
|
97
|
+
if (prices.hasOwnProperty(key)) {
|
98
|
+
sortedPrices[key] = prices[key];
|
99
|
+
}
|
100
|
+
}
|
101
|
+
return sortedPrices;
|
102
|
+
}
|
92
103
|
async function getSwitchboardPrices(mints) {
|
93
104
|
if (mints.length === 0) {
|
94
105
|
return [];
|
95
106
|
}
|
96
107
|
const { CrossbarClient } = OnDemand;
|
97
108
|
const crossbar = CrossbarClient.default();
|
98
|
-
let prices =
|
109
|
+
let prices = {};
|
99
110
|
try {
|
100
111
|
prices = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
101
|
-
const
|
102
|
-
const
|
103
|
-
if (
|
112
|
+
const resp = await crossbar.simulateSolanaFeeds("mainnet", mints.map((x) => switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS[x.toString()]));
|
113
|
+
const prices = resp.flatMap((x) => x.results[0]);
|
114
|
+
if (prices.filter((x) => !x || isNaN(Number(x)) || Number(x) <= 0)
|
115
|
+
.length > 0) {
|
104
116
|
throw new Error("Unable to fetch Switchboard prices");
|
105
117
|
}
|
106
|
-
|
118
|
+
const finalMap = {};
|
119
|
+
for (const item of resp) {
|
120
|
+
for (const [k, v] of Object.entries(switchboardConstants_1.SWITCHBOARD_PRICE_FEED_IDS)) {
|
121
|
+
if (item.feed === v) {
|
122
|
+
finalMap[k] = Number(item.results[0]);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
return finalMap;
|
107
127
|
}, 2, 350);
|
108
128
|
}
|
109
129
|
catch {
|
110
130
|
(0, generalUtils_1.consoleLog)("Failed to fetch Switchboard prices after multiple retries");
|
111
131
|
}
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
return prices;
|
132
|
+
const missingMints = mints.filter((x) => !prices[x.toString()]);
|
133
|
+
const jupPrices = (0, generalUtils_1.zip)(missingMints, await getJupTokenPrices(missingMints.map((x) => new web3_js_1.PublicKey(x)))).reduce((acc, [key, value]) => {
|
134
|
+
acc[key.toString()] = value;
|
135
|
+
return acc;
|
136
|
+
}, {});
|
137
|
+
return Object.values(getSortedPriceData({ ...prices, ...jupPrices }, mints));
|
119
138
|
}
|
120
139
|
async function getJupTokenPrices(mints, mayIncludeSpamTokens) {
|
121
140
|
if (mints.length == 0) {
|
122
141
|
return [];
|
123
142
|
}
|
124
|
-
const data = await (0, jupiterUtils_1.getJupPriceData)(mints, mayIncludeSpamTokens);
|
125
|
-
|
126
|
-
for (const mint of mints) {
|
127
|
-
const key = mint.toString();
|
128
|
-
if (data.hasOwnProperty(key)) {
|
129
|
-
sortedData[key] = data[key];
|
130
|
-
}
|
131
|
-
}
|
132
|
-
return Object.values(sortedData).map((x) => x !== null && typeof x === "object" && "price" in x
|
143
|
+
const data = getSortedPriceData(await (0, jupiterUtils_1.getJupPriceData)(mints, mayIncludeSpamTokens), mints);
|
144
|
+
return Object.values(data).map((x) => x !== null && typeof x === "object" && "price" in x
|
133
145
|
? parseFloat(x.price)
|
134
146
|
: 0);
|
135
147
|
}
|
package/package.json
CHANGED
@@ -204,7 +204,6 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
204
204
|
// All other live position updates can be derived by getting a fresh position state, so we don't need to do anything else form contextUpdates
|
205
205
|
}
|
206
206
|
}
|
207
|
-
console.log("Resetting context updates...");
|
208
207
|
this.contextUpdates.reset();
|
209
208
|
}
|
210
209
|
|
@@ -40,7 +40,6 @@ import {
|
|
40
40
|
MARGINFI_PROGRAM_ID,
|
41
41
|
MarginfiAccount,
|
42
42
|
lendingAccountBorrow,
|
43
|
-
lendingAccountCloseBalance,
|
44
43
|
lendingAccountDeposit,
|
45
44
|
lendingAccountEndFlashloan,
|
46
45
|
lendingAccountRepay,
|
@@ -62,7 +61,7 @@ import {
|
|
62
61
|
getMarginfiMaxLtvAndLiqThreshold,
|
63
62
|
marginfiAccountEmpty,
|
64
63
|
} from "../utils/marginfiUtils";
|
65
|
-
import {
|
64
|
+
import { fromBaseUnit, toBps } from "../utils/numberUtils";
|
66
65
|
import { QuoteResponse } from "@jup-ag/api";
|
67
66
|
import { consoleLog, safeGetPrice, splTokenTransferUmiIx } from "../utils";
|
68
67
|
|
@@ -585,10 +584,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
585
584
|
return transactionBuilder().add(
|
586
585
|
splTokenTransferUmiIx(
|
587
586
|
this.signer,
|
588
|
-
getTokenAccount(
|
589
|
-
toWeb3JsPublicKey(this.signer.publicKey),
|
590
|
-
this.debtMint
|
591
|
-
),
|
587
|
+
getTokenAccount(toWeb3JsPublicKey(this.signer.publicKey), this.debtMint),
|
592
588
|
destinationTokenAccount,
|
593
589
|
toWeb3JsPublicKey(this.signer.publicKey),
|
594
590
|
flashLoanDetails.baseUnitAmount
|
@@ -687,15 +683,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
687
683
|
);
|
688
684
|
}
|
689
685
|
|
690
|
-
const banksRequiringBalanceClose = Array.from(
|
691
|
-
new Set([
|
692
|
-
accounts.data.bank,
|
693
|
-
...(this.intermediaryMarginfiAccount?.lendingAccount.balances ?? [])
|
694
|
-
.filter((x) => x.active && bytesToI80F48(x.liabilityShares.value) > 0)
|
695
|
-
.map((x) => x.bankPk.toString()),
|
696
|
-
])
|
697
|
-
);
|
698
|
-
|
699
686
|
return transactionBuilder()
|
700
687
|
.add(
|
701
688
|
lendingAccountRepay(this.umi, {
|
@@ -714,18 +701,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
714
701
|
),
|
715
702
|
})
|
716
703
|
)
|
717
|
-
.add(
|
718
|
-
banksRequiringBalanceClose.map((x) =>
|
719
|
-
this.closeBalance(
|
720
|
-
this.intermediaryMarginfiAccountPk,
|
721
|
-
new PublicKey(x)
|
722
|
-
)
|
723
|
-
)
|
724
|
-
// this.closeBalance(
|
725
|
-
// this.intermediaryMarginfiAccountPk,
|
726
|
-
// new PublicKey(accounts.data.bank)
|
727
|
-
// )
|
728
|
-
)
|
729
704
|
.add(
|
730
705
|
lendingAccountEndFlashloan(this.umi, {
|
731
706
|
marginfiAccount: publicKey(this.intermediaryMarginfiAccountPk),
|
@@ -734,17 +709,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
734
709
|
);
|
735
710
|
}
|
736
711
|
|
737
|
-
closeBalance(marginfiAccount: PublicKey, bank: PublicKey) {
|
738
|
-
return transactionBuilder().add(
|
739
|
-
lendingAccountCloseBalance(this.umi, {
|
740
|
-
signer: this.signer,
|
741
|
-
marginfiAccount: publicKey(marginfiAccount),
|
742
|
-
bank: publicKey(bank),
|
743
|
-
marginfiGroup: publicKey(this.marginfiGroup),
|
744
|
-
})
|
745
|
-
);
|
746
|
-
}
|
747
|
-
|
748
712
|
async getFreshPositionState(): Promise<PositionState | undefined> {
|
749
713
|
const state = await super.getFreshPositionState();
|
750
714
|
if (state) {
|
@@ -591,8 +591,8 @@ export function marginfiAccountEmpty(marginfiAccount: MarginfiAccount) {
|
|
591
591
|
marginfiAccount.lendingAccount.balances.find(
|
592
592
|
(x) =>
|
593
593
|
x.bankPk.toString() !== PublicKey.default.toString() &&
|
594
|
-
(bytesToI80F48(x.assetShares.value)
|
595
|
-
bytesToI80F48(x.liabilityShares.value)
|
594
|
+
(Math.round(bytesToI80F48(x.assetShares.value)) != 0 ||
|
595
|
+
Math.round(bytesToI80F48(x.liabilityShares.value)) != 0)
|
596
596
|
) === undefined
|
597
597
|
);
|
598
598
|
}
|
package/src/utils/priceUtils.ts
CHANGED
@@ -11,8 +11,7 @@ import {
|
|
11
11
|
zip,
|
12
12
|
} from "./generalUtils";
|
13
13
|
import * as OnDemand from "@switchboard-xyz/on-demand";
|
14
|
-
import { getJupPriceData
|
15
|
-
import { QuoteGetSwapModeEnum } from "@jup-ag/api";
|
14
|
+
import { getJupPriceData } from "./jupiterUtils";
|
16
15
|
|
17
16
|
export async function fetchTokenPrices(mints: PublicKey[]): Promise<number[]> {
|
18
17
|
const currentTime = currentUnixSeconds();
|
@@ -99,35 +98,57 @@ export async function getPythPrices(mints: PublicKey[]) {
|
|
99
98
|
return prices;
|
100
99
|
}
|
101
100
|
|
101
|
+
function getSortedPriceData(
|
102
|
+
prices: Record<string, number>,
|
103
|
+
mints: PublicKey[]
|
104
|
+
) {
|
105
|
+
const sortedPrices: { [key: string]: any } = {};
|
106
|
+
|
107
|
+
for (const mint of mints) {
|
108
|
+
const key = mint.toString();
|
109
|
+
if (prices.hasOwnProperty(key)) {
|
110
|
+
sortedPrices[key] = prices[key];
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
return sortedPrices;
|
115
|
+
}
|
116
|
+
|
102
117
|
export async function getSwitchboardPrices(
|
103
118
|
mints: PublicKey[]
|
104
119
|
): Promise<number[]> {
|
105
120
|
if (mints.length === 0) {
|
106
121
|
return [];
|
107
122
|
}
|
108
|
-
|
109
123
|
const { CrossbarClient } = OnDemand;
|
110
124
|
const crossbar = CrossbarClient.default();
|
111
125
|
|
112
|
-
let prices: number
|
126
|
+
let prices: Record<string, number> = {};
|
113
127
|
try {
|
114
128
|
prices = await retryWithExponentialBackoff(
|
115
129
|
async () => {
|
116
|
-
const
|
130
|
+
const resp = await crossbar.simulateSolanaFeeds(
|
117
131
|
"mainnet",
|
118
132
|
mints.map((x) => SWITCHBOARD_PRICE_FEED_IDS[x.toString()])
|
119
133
|
);
|
120
134
|
|
121
|
-
const
|
135
|
+
const prices = resp.flatMap((x) => x.results[0]);
|
122
136
|
if (
|
123
|
-
|
137
|
+
prices.filter((x) => !x || isNaN(Number(x)) || Number(x) <= 0)
|
138
|
+
.length > 0
|
124
139
|
) {
|
125
140
|
throw new Error("Unable to fetch Switchboard prices");
|
126
141
|
}
|
127
142
|
|
128
|
-
|
129
|
-
|
130
|
-
|
143
|
+
const finalMap: Record<string, number> = {};
|
144
|
+
for (const item of resp) {
|
145
|
+
for (const [k, v] of Object.entries(SWITCHBOARD_PRICE_FEED_IDS)) {
|
146
|
+
if (item.feed === v) {
|
147
|
+
finalMap[k] = Number(item.results[0]);
|
148
|
+
}
|
149
|
+
}
|
150
|
+
}
|
151
|
+
return finalMap;
|
131
152
|
},
|
132
153
|
2,
|
133
154
|
350
|
@@ -136,23 +157,19 @@ export async function getSwitchboardPrices(
|
|
136
157
|
consoleLog("Failed to fetch Switchboard prices after multiple retries");
|
137
158
|
}
|
138
159
|
|
139
|
-
|
140
|
-
prices = Array(mints.length).fill(0);
|
141
|
-
}
|
142
|
-
|
143
|
-
const missingPrices = zip(mints, prices).filter(
|
144
|
-
(x) => !x[1] || isNaN(Number(x[1]))
|
145
|
-
);
|
160
|
+
const missingMints = mints.filter((x) => !prices[x.toString()]);
|
146
161
|
const jupPrices = zip(
|
147
|
-
|
148
|
-
await getJupTokenPrices(
|
149
|
-
)
|
150
|
-
|
151
|
-
|
152
|
-
|
162
|
+
missingMints,
|
163
|
+
await getJupTokenPrices(missingMints.map((x) => new PublicKey(x)))
|
164
|
+
).reduce(
|
165
|
+
(acc, [key, value]) => {
|
166
|
+
acc[key.toString()] = value;
|
167
|
+
return acc;
|
168
|
+
},
|
169
|
+
{} as Record<string, number>
|
153
170
|
);
|
154
171
|
|
155
|
-
return prices;
|
172
|
+
return Object.values(getSortedPriceData({ ...prices, ...jupPrices }, mints));
|
156
173
|
}
|
157
174
|
|
158
175
|
export async function getJupTokenPrices(
|
@@ -163,17 +180,12 @@ export async function getJupTokenPrices(
|
|
163
180
|
return [];
|
164
181
|
}
|
165
182
|
|
166
|
-
const data =
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
const key = mint.toString();
|
171
|
-
if (data.hasOwnProperty(key)) {
|
172
|
-
sortedData[key] = data[key];
|
173
|
-
}
|
174
|
-
}
|
183
|
+
const data = getSortedPriceData(
|
184
|
+
await getJupPriceData(mints, mayIncludeSpamTokens),
|
185
|
+
mints
|
186
|
+
);
|
175
187
|
|
176
|
-
return Object.values(
|
188
|
+
return Object.values(data).map((x) =>
|
177
189
|
x !== null && typeof x === "object" && "price" in x
|
178
190
|
? parseFloat(x.price as string)
|
179
191
|
: 0
|
@@ -187,4 +199,4 @@ export function safeGetPrice(
|
|
187
199
|
return PRICES[mint!.toString()].price;
|
188
200
|
}
|
189
201
|
return undefined;
|
190
|
-
}
|
202
|
+
}
|
@@ -1,18 +1,9 @@
|
|
1
1
|
import { describe, it } from "mocha";
|
2
|
-
import {
|
3
|
-
none,
|
4
|
-
publicKey,
|
5
|
-
some,
|
6
|
-
transactionBuilder,
|
7
|
-
Umi,
|
8
|
-
UmiError,
|
9
|
-
} from "@metaplex-foundation/umi";
|
2
|
+
import { none, publicKey, some } from "@metaplex-foundation/umi";
|
10
3
|
import { setupTest } from "../shared";
|
11
4
|
import { SolautoMarginfiClient } from "../../src/clients/solautoMarginfiClient";
|
12
5
|
import {
|
13
|
-
fetchSolautoPosition,
|
14
6
|
PositionType,
|
15
|
-
safeFetchAllSolautoPosition,
|
16
7
|
safeFetchSolautoPosition,
|
17
8
|
solautoAction,
|
18
9
|
SolautoSettingsParametersInpArgs,
|
@@ -36,8 +27,6 @@ import { PublicKey } from "@solana/web3.js";
|
|
36
27
|
import {
|
37
28
|
DEFAULT_MARGINFI_GROUP,
|
38
29
|
MARGINFI_ACCOUNTS,
|
39
|
-
POPCAT,
|
40
|
-
RETARDIO,
|
41
30
|
SOLAUTO_PROD_PROGRAM,
|
42
31
|
SOLAUTO_TEST_PROGRAM,
|
43
32
|
USDC,
|
@@ -45,122 +34,22 @@ import {
|
|
45
34
|
} from "../../src/constants";
|
46
35
|
import {
|
47
36
|
buildHeliusApiUrl,
|
48
|
-
fetchTokenPrices,
|
49
37
|
getAllPositionsByAuthority,
|
50
|
-
getBankLiquidityAvailableBaseUnit,
|
51
38
|
getQnComputeUnitPriceEstimate,
|
52
39
|
getSolautoManagedPositions,
|
53
40
|
getSolautoPositionAccount,
|
54
|
-
marginfiAccountEmpty,
|
55
41
|
retryWithExponentialBackoff,
|
56
|
-
safeGetPrice,
|
57
42
|
} from "../../src/utils";
|
58
43
|
import { PriorityFeeSetting } from "../../src/types";
|
59
|
-
import {
|
60
|
-
buildIronforgeApiUrl,
|
61
|
-
fromBaseUnit,
|
62
|
-
tokenInfo,
|
63
|
-
USD_DECIMALS,
|
64
|
-
} from "../../dist";
|
65
|
-
import {
|
66
|
-
lendingPoolAccrueBankInterest,
|
67
|
-
safeFetchBank,
|
68
|
-
safeFetchMarginfiAccount,
|
69
|
-
} from "../../src/marginfi-sdk";
|
70
|
-
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
71
|
-
|
72
|
-
async function test(
|
73
|
-
umi: Umi,
|
74
|
-
sp: PublicKey | undefined,
|
75
|
-
supplyMint: PublicKey,
|
76
|
-
sb: PublicKey,
|
77
|
-
supplyMintDecimals: number,
|
78
|
-
debtMint: PublicKey,
|
79
|
-
db: PublicKey,
|
80
|
-
debtMintDecimals: number
|
81
|
-
) {
|
82
|
-
const solautoPosition = sp
|
83
|
-
? await fetchSolautoPosition(umi, publicKey(sp))
|
84
|
-
: undefined;
|
85
|
-
|
86
|
-
const mfiAccount = solautoPosition
|
87
|
-
? await safeFetchMarginfiAccount(
|
88
|
-
umi,
|
89
|
-
solautoPosition.position.protocolUserAccount
|
90
|
-
)
|
91
|
-
: undefined;
|
92
|
-
|
93
|
-
const supplyBank = await safeFetchBank(umi, publicKey(sb));
|
94
|
-
const debtBank = await safeFetchBank(umi, publicKey(db));
|
95
|
-
|
96
|
-
await fetchTokenPrices([supplyMint, debtMint]);
|
97
|
-
|
98
|
-
console.log(supplyBank);
|
99
|
-
console.log(debtBank);
|
100
|
-
|
101
|
-
if (mfiAccount) {
|
102
|
-
console.log(mfiAccount.lendingAccount.balances);
|
103
|
-
console.log(
|
104
|
-
fromBaseUnit(
|
105
|
-
BigInt(
|
106
|
-
bytesToI80F48(
|
107
|
-
mfiAccount.lendingAccount.balances[0].assetShares.value
|
108
|
-
) * bytesToI80F48(supplyBank.assetShareValue.value)
|
109
|
-
),
|
110
|
-
supplyMintDecimals
|
111
|
-
) * safeGetPrice(supplyMint)
|
112
|
-
);
|
113
|
-
}
|
114
|
-
|
115
|
-
const imfiAccount = await safeFetchMarginfiAccount(
|
116
|
-
umi,
|
117
|
-
publicKey("E8oukAkTMW4YsAPymMzWQHWb8egmGq9yjDtmMi6gfY18")
|
118
|
-
);
|
119
|
-
|
120
|
-
console.log(
|
121
|
-
bytesToI80F48(
|
122
|
-
imfiAccount.lendingAccount.balances[0].liabilityShares.value
|
123
|
-
) * bytesToI80F48(supplyBank.liabilityShareValue.value),
|
124
|
-
bytesToI80F48(imfiAccount.lendingAccount.balances[0].assetShares.value) *
|
125
|
-
bytesToI80F48(supplyBank.assetShareValue.value)
|
126
|
-
);
|
127
|
-
console.log(
|
128
|
-
bytesToI80F48(
|
129
|
-
imfiAccount.lendingAccount.balances[1].liabilityShares.value
|
130
|
-
) * bytesToI80F48(debtBank.liabilityShareValue.value),
|
131
|
-
bytesToI80F48(imfiAccount.lendingAccount.balances[1].assetShares.value) *
|
132
|
-
bytesToI80F48(debtBank.assetShareValue.value)
|
133
|
-
);
|
134
|
-
|
135
|
-
console.log(
|
136
|
-
bytesToI80F48(supplyBank.totalAssetShares.value),
|
137
|
-
bytesToI80F48(supplyBank.totalLiabilityShares.value),
|
138
|
-
bytesToI80F48(supplyBank.totalAssetShares.value) -
|
139
|
-
bytesToI80F48(supplyBank.totalLiabilityShares.value),
|
140
|
-
fromBaseUnit(
|
141
|
-
getBankLiquidityAvailableBaseUnit(supplyBank, false),
|
142
|
-
supplyMintDecimals
|
143
|
-
) * safeGetPrice(supplyMint)
|
144
|
-
);
|
145
|
-
console.log(
|
146
|
-
bytesToI80F48(debtBank.totalAssetShares.value),
|
147
|
-
bytesToI80F48(debtBank.totalLiabilityShares.value),
|
148
|
-
bytesToI80F48(debtBank.totalAssetShares.value) -
|
149
|
-
bytesToI80F48(debtBank.totalLiabilityShares.value),
|
150
|
-
fromBaseUnit(
|
151
|
-
getBankLiquidityAvailableBaseUnit(debtBank, false),
|
152
|
-
debtMintDecimals
|
153
|
-
) * safeGetPrice(debtMint)
|
154
|
-
);
|
155
|
-
}
|
44
|
+
import { buildIronforgeApiUrl, fromBaseUnit, tokenInfo, USD_DECIMALS } from "../../dist";
|
156
45
|
|
157
46
|
describe("Solauto Marginfi tests", async () => {
|
158
|
-
const signer = setupTest();
|
159
|
-
|
47
|
+
// const signer = setupTest();
|
48
|
+
const signer = setupTest("solauto-manager");
|
160
49
|
|
161
50
|
const payForTransactions = true;
|
162
|
-
const testProgram =
|
163
|
-
const positionId =
|
51
|
+
const testProgram = false;
|
52
|
+
const positionId = 3;
|
164
53
|
|
165
54
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
166
55
|
const client = new SolautoMarginfiClient(
|
@@ -176,7 +65,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
176
65
|
await client.initialize({
|
177
66
|
signer,
|
178
67
|
positionId,
|
179
|
-
|
68
|
+
authority: new PublicKey("FKYQs7KgRvaKQHxXwb8HKfoBcFdSxLL3JvHWpPdVQ16v"),
|
180
69
|
// new: true,
|
181
70
|
// marginfiAccount: new PublicKey(
|
182
71
|
// ""
|
@@ -186,42 +75,6 @@ describe("Solauto Marginfi tests", async () => {
|
|
186
75
|
// debtMint: new PublicKey(USDC),
|
187
76
|
});
|
188
77
|
|
189
|
-
await test(
|
190
|
-
client.umi,
|
191
|
-
// new PublicKey("E8oukAkTMW4YsAPymMzWQHWb8egmGq9yjDtmMi6gfY18"),
|
192
|
-
undefined,
|
193
|
-
new PublicKey(RETARDIO),
|
194
|
-
new PublicKey("3J5rKmCi7JXG6qmiobFJyAidVTnnNAMGj4jomfBxKGRM"),
|
195
|
-
6,
|
196
|
-
new PublicKey(USDC),
|
197
|
-
new PublicKey("6cgYhBFWCc5sNHxkvSRhd5H9AdAHR41zKwuF37HmLry5"),
|
198
|
-
6
|
199
|
-
);
|
200
|
-
// await test(
|
201
|
-
// client.umi,
|
202
|
-
// new PublicKey("EcdfYZCtaePaDWVy9Cz6eiS5QbLbhThau1fHLhQTEZqs"),
|
203
|
-
// new PublicKey(USDC),
|
204
|
-
// new PublicKey("EXrnNVfLagt3j4hCHSD9WqK75o6dkZBtjpnrSrSC78MA"),
|
205
|
-
// 6,
|
206
|
-
// new PublicKey(POPCAT),
|
207
|
-
// new PublicKey("845oEvt1oduoBj5zQxTr21cWWaUVnRjGerJuW3yMo2nn"),
|
208
|
-
// 9
|
209
|
-
// );
|
210
|
-
|
211
|
-
// const mfiAccount = await safeFetchMarginfiAccount(
|
212
|
-
// client.umi,
|
213
|
-
// publicKey("E8oukAkTMW4YsAPymMzWQHWb8egmGq9yjDtmMi6gfY18")
|
214
|
-
// );
|
215
|
-
// // console.log(mfiAccount.lendingAccount.balances);
|
216
|
-
// console.log(
|
217
|
-
// mfiAccount.lendingAccount.balances.map((x) =>
|
218
|
-
// bytesToI80F48(x.liabilityShares.value)
|
219
|
-
// )
|
220
|
-
// );
|
221
|
-
// console.log(
|
222
|
-
// mfiAccount.lendingAccount.balances.map((x) => x.bankPk.toString())
|
223
|
-
// );
|
224
|
-
|
225
78
|
const transactionItems: TransactionItem[] = [];
|
226
79
|
// const settingParams: SolautoSettingsParametersInpArgs = {
|
227
80
|
// boostToBps: maxBoostToBps(
|
@@ -289,68 +142,14 @@ describe("Solauto Marginfi tests", async () => {
|
|
289
142
|
// )
|
290
143
|
// );
|
291
144
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
// );
|
299
|
-
|
300
|
-
const imfiAccount = await safeFetchMarginfiAccount(
|
301
|
-
client.umi,
|
302
|
-
// publicKey(client.intermediaryMarginfiAccountPk)
|
303
|
-
publicKey("E8oukAkTMW4YsAPymMzWQHWb8egmGq9yjDtmMi6gfY18")
|
304
|
-
);
|
305
|
-
|
306
|
-
console.log(imfiAccount.lendingAccount.balances);
|
307
|
-
console.log(
|
308
|
-
imfiAccount.lendingAccount.balances.map((x) => [
|
309
|
-
x.bankPk.toString(),
|
310
|
-
x.liabilityShares.value,
|
311
|
-
bytesToI80F48(x.liabilityShares.value),
|
312
|
-
])
|
145
|
+
transactionItems.push(
|
146
|
+
new TransactionItem(
|
147
|
+
async (attemptNum) =>
|
148
|
+
await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
|
149
|
+
"rebalance"
|
150
|
+
)
|
313
151
|
);
|
314
152
|
|
315
|
-
console.log(marginfiAccountEmpty(imfiAccount));
|
316
|
-
return;
|
317
|
-
|
318
|
-
// transactionItems.push(
|
319
|
-
// new TransactionItem(async () => ({
|
320
|
-
// tx: transactionBuilder().add([
|
321
|
-
// lendingPoolAccrueBankInterest(client.umi, {
|
322
|
-
// bank: publicKey("3J5rKmCi7JXG6qmiobFJyAidVTnnNAMGj4jomfBxKGRM"),
|
323
|
-
// marginfiGroup: publicKey(
|
324
|
-
// "EpzY5EYF1A5eFDRfjtsPXSYMPmEx1FXKaXPnouTMF4dm"
|
325
|
-
// ),
|
326
|
-
// }),
|
327
|
-
// lendingPoolAccrueBankInterest(client.umi, {
|
328
|
-
// bank: publicKey("6cgYhBFWCc5sNHxkvSRhd5H9AdAHR41zKwuF37HmLry5"),
|
329
|
-
// marginfiGroup: publicKey(
|
330
|
-
// "EpzY5EYF1A5eFDRfjtsPXSYMPmEx1FXKaXPnouTMF4dm"
|
331
|
-
// ),
|
332
|
-
// }),
|
333
|
-
// ]),
|
334
|
-
// }))
|
335
|
-
// );
|
336
|
-
|
337
|
-
// transactionItems.push(
|
338
|
-
// new TransactionItem(async () => ({
|
339
|
-
// tx: transactionBuilder().add(
|
340
|
-
// imfiAccount.lendingAccount.balances
|
341
|
-
// .filter(
|
342
|
-
// (x) => x.active && bytesToI80F48(x.liabilityShares.value) > 0
|
343
|
-
// )
|
344
|
-
// .map((x) =>
|
345
|
-
// client.closeBalance(
|
346
|
-
// client.intermediaryMarginfiAccountPk,
|
347
|
-
// toWeb3JsPublicKey(x.bankPk)
|
348
|
-
// )
|
349
|
-
// )
|
350
|
-
// ),
|
351
|
-
// }))
|
352
|
-
// );
|
353
|
-
|
354
153
|
// transactionItems.push(
|
355
154
|
// new TransactionItem(
|
356
155
|
// async () => ({ tx: client.refresh() }),
|