@haven-fi/solauto-sdk 1.0.667 → 1.0.669
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/marginfi-sdk/errors/marginfi.d.ts +209 -23
- package/dist/marginfi-sdk/errors/marginfi.d.ts.map +1 -1
- package/dist/marginfi-sdk/errors/marginfi.js +465 -123
- package/dist/marginfi-sdk/instructions/lendingAccountDeposit.d.ts +3 -1
- package/dist/marginfi-sdk/instructions/lendingAccountDeposit.d.ts.map +1 -1
- package/dist/marginfi-sdk/instructions/lendingAccountDeposit.js +1 -0
- package/dist/services/rebalance/rebalanceTxBuilder.js +1 -1
- package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoMarginfiClient.js +2 -1
- package/dist/services/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/services/transactions/transactionUtils.js +1 -0
- package/dist/solautoPosition/positionUtils.d.ts.map +1 -1
- package/dist/solautoPosition/solautoPositionEx.d.ts +3 -3
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/solautoPositionEx.js +14 -8
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/marginfi/data.d.ts +41 -0
- package/dist/utils/marginfi/data.d.ts.map +1 -0
- package/dist/utils/{marginfiUtils.js → marginfi/data.js} +8 -145
- package/dist/utils/marginfi/general.d.ts +27 -0
- package/dist/utils/marginfi/general.d.ts.map +1 -0
- package/dist/utils/marginfi/general.js +146 -0
- package/dist/utils/marginfi/index.d.ts +3 -0
- package/dist/utils/marginfi/index.d.ts.map +1 -0
- package/dist/utils/marginfi/index.js +18 -0
- package/dist/utils/solanaUtils.d.ts.map +1 -1
- package/dist/utils/solanaUtils.js +14 -13
- package/dist/utils/solautoUtils.d.ts.map +1 -1
- package/dist/utils/solautoUtils.js +4 -4
- package/local/txSandbox.ts +3 -3
- package/package.json +1 -1
- package/src/marginfi-sdk/errors/marginfi.ts +583 -122
- package/src/marginfi-sdk/instructions/lendingAccountDeposit.ts +7 -0
- package/src/services/rebalance/rebalanceTxBuilder.ts +1 -1
- package/src/services/solauto/solautoMarginfiClient.ts +2 -1
- package/src/services/transactions/transactionUtils.ts +1 -0
- package/src/solautoPosition/positionUtils.ts +0 -1
- package/src/solautoPosition/solautoPositionEx.ts +24 -9
- package/src/utils/index.ts +1 -1
- package/src/utils/{marginfiUtils.ts → marginfi/data.ts} +10 -220
- package/src/utils/marginfi/general.ts +226 -0
- package/src/utils/marginfi/index.ts +2 -0
- package/src/utils/solanaUtils.ts +12 -17
- package/src/utils/solautoUtils.ts +1 -4
- package/tests/transactions/shared.ts +3 -1
- package/tests/transactions/solautoMarginfi.ts +4 -2
- package/dist/utils/marginfiUtils.d.ts +0 -62
- package/dist/utils/marginfiUtils.d.ts.map +0 -1
package/src/utils/solanaUtils.ts
CHANGED
@@ -47,7 +47,7 @@ import {
|
|
47
47
|
retryWithExponentialBackoff,
|
48
48
|
} from "./generalUtils";
|
49
49
|
import { createDynamicSolautoProgram } from "./solautoUtils";
|
50
|
-
import { createDynamicMarginfiProgram } from "./
|
50
|
+
import { createDynamicMarginfiProgram } from "./marginfi";
|
51
51
|
|
52
52
|
export function getSolanaRpcConnection(
|
53
53
|
rpcUrl: string,
|
@@ -223,11 +223,14 @@ export function addTxOptimizations(
|
|
223
223
|
: transactionBuilder();
|
224
224
|
|
225
225
|
const allOptimizations = tx.prepend(computePriceIx).prepend(computeLimitIx);
|
226
|
-
const
|
226
|
+
const withCuPrice = tx.prepend(computePriceIx);
|
227
|
+
const withCuLimit = tx.prepend(computeLimitIx);
|
227
228
|
if (allOptimizations.fitsInOneTransaction(umi)) {
|
228
229
|
return allOptimizations;
|
229
|
-
} else if (
|
230
|
-
return
|
230
|
+
} else if (withCuPrice.fitsInOneTransaction(umi)) {
|
231
|
+
return withCuPrice;
|
232
|
+
} else if (withCuLimit.fitsInOneTransaction(umi)) {
|
233
|
+
return withCuLimit;
|
231
234
|
} else {
|
232
235
|
return tx;
|
233
236
|
}
|
@@ -448,7 +451,7 @@ export async function sendSingleOptimizedTransaction(
|
|
448
451
|
|
449
452
|
const blockhash = await connection.getLatestBlockhash("confirmed");
|
450
453
|
|
451
|
-
let
|
454
|
+
let cuLimit = undefined;
|
452
455
|
if (txType !== "skip-simulation") {
|
453
456
|
const simulationResult = await retryWithExponentialBackoff(
|
454
457
|
async () =>
|
@@ -461,28 +464,20 @@ export async function sendSingleOptimizedTransaction(
|
|
461
464
|
),
|
462
465
|
3
|
463
466
|
);
|
464
|
-
|
465
|
-
consoleLog("Compute unit limit: ",
|
467
|
+
cuLimit = Math.round(simulationResult.value.unitsConsumed! * 1.15);
|
468
|
+
consoleLog("Compute unit limit: ", cuLimit);
|
466
469
|
}
|
467
470
|
|
468
471
|
let cuPrice: number | undefined;
|
469
472
|
if (prioritySetting !== PriorityFeeSetting.None) {
|
470
473
|
cuPrice = await getComputeUnitPriceEstimate(umi, tx, prioritySetting);
|
471
|
-
|
472
|
-
cuPrice = 1_000_000;
|
473
|
-
}
|
474
|
-
cuPrice = Math.min(cuPrice, 100 * 1_000_000);
|
474
|
+
cuPrice = Math.min(cuPrice ?? 0, 100_000_000);
|
475
475
|
consoleLog("Compute unit price: ", cuPrice);
|
476
476
|
}
|
477
477
|
|
478
478
|
if (txType !== "only-simulate") {
|
479
479
|
onAwaitingSign?.();
|
480
|
-
const signedTx = await assembleFinalTransaction(
|
481
|
-
umi,
|
482
|
-
tx,
|
483
|
-
cuPrice,
|
484
|
-
computeUnitLimit
|
485
|
-
)
|
480
|
+
const signedTx = await assembleFinalTransaction(umi, tx, cuPrice, cuLimit)
|
486
481
|
.setBlockhash(blockhash)
|
487
482
|
.buildAndSign(umi);
|
488
483
|
const txSig = await spamSendTransactionUntilConfirmed(
|
@@ -37,11 +37,8 @@ import {
|
|
37
37
|
toRoundedUsdValue,
|
38
38
|
} from "./numberUtils";
|
39
39
|
import { fetchTokenPrices } from "./priceUtils";
|
40
|
-
import {
|
41
|
-
findMarginfiAccounts,
|
42
|
-
getAllMarginfiAccountsByAuthority,
|
43
|
-
} from "./marginfiUtils";
|
44
40
|
import { validPubkey } from "./generalUtils";
|
41
|
+
import { findMarginfiAccounts, getAllMarginfiAccountsByAuthority } from "./marginfi";
|
45
42
|
|
46
43
|
export function createDynamicSolautoProgram(programId?: PublicKey): Program {
|
47
44
|
return {
|
@@ -27,10 +27,12 @@ export async function e2eTransactionTest(
|
|
27
27
|
signer: Signer,
|
28
28
|
testProgram: boolean,
|
29
29
|
lendingPlatform: LendingPlatform,
|
30
|
-
withFlashLoan: boolean
|
30
|
+
withFlashLoan: boolean,
|
31
|
+
showLogs?: boolean
|
31
32
|
) {
|
32
33
|
const client = getClient(lendingPlatform, {
|
33
34
|
signer,
|
35
|
+
showLogs,
|
34
36
|
rpcUrl: LOCAL_IRONFORGE_API_URL,
|
35
37
|
programId: testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM,
|
36
38
|
});
|
@@ -5,13 +5,14 @@ import { e2eTransactionTest } from "./shared";
|
|
5
5
|
|
6
6
|
describe("Solauto Marginfi tests", async () => {
|
7
7
|
const signer = setupTest();
|
8
|
-
const testProgram =
|
8
|
+
const testProgram = false;
|
9
9
|
|
10
10
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
11
11
|
await e2eTransactionTest(
|
12
12
|
signer,
|
13
13
|
testProgram,
|
14
14
|
LendingPlatform.Marginfi,
|
15
|
+
false,
|
15
16
|
false
|
16
17
|
);
|
17
18
|
});
|
@@ -21,7 +22,8 @@ describe("Solauto Marginfi tests", async () => {
|
|
21
22
|
signer,
|
22
23
|
testProgram,
|
23
24
|
LendingPlatform.Marginfi,
|
24
|
-
true
|
25
|
+
true,
|
26
|
+
false
|
25
27
|
);
|
26
28
|
});
|
27
29
|
});
|
@@ -1,62 +0,0 @@
|
|
1
|
-
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import { AccountMeta, Program, Umi } from "@metaplex-foundation/umi";
|
3
|
-
import { ProgramEnv, MarginfiAssetAccounts } from "../types";
|
4
|
-
import { PositionState, PriceType } from "../generated";
|
5
|
-
import { MarginfiBankAccountsMap } from "../constants";
|
6
|
-
import { Balance, Bank, MarginfiAccount } from "../marginfi-sdk";
|
7
|
-
import { ContextUpdates } from "./solautoUtils";
|
8
|
-
export declare function createDynamicMarginfiProgram(env?: ProgramEnv): Program;
|
9
|
-
export declare function umiWithMarginfiProgram(umi: Umi, marginfiEnv?: ProgramEnv): Umi;
|
10
|
-
export declare function getAllBankRelatedAccounts(umi: Umi, bankAccountsMap: MarginfiBankAccountsMap): Promise<PublicKey[]>;
|
11
|
-
export declare function fetchBankAddresses(umi: Umi, bankPk: PublicKey): Promise<{
|
12
|
-
bank: PublicKey;
|
13
|
-
liquidityVault: PublicKey;
|
14
|
-
vaultAuthority: PublicKey | undefined;
|
15
|
-
priceOracle: PublicKey;
|
16
|
-
}>;
|
17
|
-
export declare function getMarginfiPriceOracle(umi: Umi, bank: {
|
18
|
-
pk?: PublicKey;
|
19
|
-
data?: Bank;
|
20
|
-
}): Promise<PublicKey>;
|
21
|
-
interface AllMarginfiAssetAccounts extends MarginfiAssetAccounts {
|
22
|
-
mint: PublicKey;
|
23
|
-
}
|
24
|
-
export declare function findMarginfiAccounts(bank: PublicKey): AllMarginfiAssetAccounts;
|
25
|
-
export declare function getRemainingAccountsForMarginfiHealthCheck(umi: Umi, balance: Balance): Promise<AccountMeta[]>;
|
26
|
-
export declare function calcMarginfiMaxLtvAndLiqThresholdBps(supplyBank: Bank, debtBank: Bank, supplyPrice: number): [number, number];
|
27
|
-
export declare function getMarginfiMaxLtvAndLiqThresholdBps(umi: Umi, marginfiGroup: PublicKey, supply: {
|
28
|
-
mint: PublicKey;
|
29
|
-
bank?: Bank | null;
|
30
|
-
}, debt: {
|
31
|
-
mint: PublicKey;
|
32
|
-
bank?: Bank | null;
|
33
|
-
}, supplyPrice?: number): Promise<[number, number]>;
|
34
|
-
export declare function getEmptyMarginfiAccountsByAuthority(umi: Umi, authority: PublicKey): Promise<MarginfiAccount[]>;
|
35
|
-
export declare function getAllMarginfiAccountsByAuthority(umi: Umi, authority: PublicKey, group?: PublicKey, compatibleWithSolauto?: boolean): Promise<{
|
36
|
-
marginfiAccount: PublicKey;
|
37
|
-
supplyMint?: PublicKey;
|
38
|
-
debtMint?: PublicKey;
|
39
|
-
}[]>;
|
40
|
-
export declare function getBankLiquidityAvailableBaseUnit(bank: Bank | null, availableToDeposit: boolean): bigint;
|
41
|
-
interface BankSelection {
|
42
|
-
mint?: PublicKey;
|
43
|
-
banksCache?: BanksCache;
|
44
|
-
}
|
45
|
-
type BanksCache = {
|
46
|
-
[group: string]: {
|
47
|
-
[mint: string]: Bank;
|
48
|
-
};
|
49
|
-
};
|
50
|
-
export declare function getMarginfiAccountPositionState(umi: Umi, lpUserAccount: {
|
51
|
-
pk?: PublicKey;
|
52
|
-
data?: MarginfiAccount | null;
|
53
|
-
}, marginfiGroup?: PublicKey, supply?: BankSelection, debt?: BankSelection, programEnv?: ProgramEnv, contextUpdates?: ContextUpdates, priceType?: PriceType): Promise<{
|
54
|
-
supplyBank: Bank | null;
|
55
|
-
debtBank: Bank | null;
|
56
|
-
state: PositionState;
|
57
|
-
} | undefined>;
|
58
|
-
export declare function calculateAnnualAPYs(bank: Bank): [number, number];
|
59
|
-
export declare function getUpToDateShareValues(bank: Bank): [number, number];
|
60
|
-
export declare function marginfiAccountEmpty(marginfiAccount: MarginfiAccount): boolean;
|
61
|
-
export {};
|
62
|
-
//# sourceMappingURL=marginfiUtils.d.ts.map
|
@@ -1 +0,0 @@
|
|
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,EAAE,WAAW,EAAE,OAAO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