@haven-fi/solauto-sdk 1.0.685 → 1.0.687
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/README.md +8 -6
- package/dist/constants/solautoConstants.d.ts +1 -0
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +2 -1
- package/dist/services/transactions/index.d.ts +3 -2
- package/dist/services/transactions/index.d.ts.map +1 -1
- package/dist/services/transactions/index.js +2 -1
- package/dist/services/transactions/manager/clientTransactionsManager.d.ts +10 -0
- package/dist/services/transactions/manager/clientTransactionsManager.d.ts.map +1 -0
- package/dist/services/transactions/manager/clientTransactionsManager.js +75 -0
- package/dist/services/transactions/manager/index.d.ts +3 -0
- package/dist/services/transactions/manager/index.d.ts.map +1 -0
- package/dist/services/transactions/manager/index.js +18 -0
- package/dist/services/transactions/manager/transactionsManager.d.ts +64 -0
- package/dist/services/transactions/manager/transactionsManager.d.ts.map +1 -0
- package/dist/services/transactions/{transactionsManager.js → manager/transactionsManager.js} +21 -211
- package/dist/services/transactions/types/index.d.ts +4 -0
- package/dist/services/transactions/types/index.d.ts.map +1 -0
- package/dist/services/transactions/types/index.js +19 -0
- package/dist/services/transactions/types/lookupTables.d.ts +10 -0
- package/dist/services/transactions/types/lookupTables.d.ts.map +1 -0
- package/dist/services/transactions/types/lookupTables.js +25 -0
- package/dist/services/transactions/types/transactionItem.d.ts +16 -0
- package/dist/services/transactions/types/transactionItem.d.ts.map +1 -0
- package/dist/services/transactions/types/transactionItem.js +31 -0
- package/dist/services/transactions/types/transactionSet.d.ts +20 -0
- package/dist/services/transactions/types/transactionSet.d.ts.map +1 -0
- package/dist/services/transactions/types/transactionSet.js +79 -0
- package/dist/solautoPosition/positionUtils.js +1 -1
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/solautoPositionEx.js +2 -1
- package/dist/utils/instructionUtils.d.ts.map +1 -1
- package/dist/utils/instructionUtils.js +3 -3
- package/dist/utils/switchboardUtils.d.ts +1 -0
- package/dist/utils/switchboardUtils.d.ts.map +1 -1
- package/dist/utils/switchboardUtils.js +10 -0
- package/local/txSandbox.ts +17 -23
- package/package.json +3 -1
- package/src/constants/solautoConstants.ts +2 -0
- package/src/services/transactions/index.ts +3 -2
- package/src/services/transactions/manager/clientTransactionsManager.ts +141 -0
- package/src/services/transactions/manager/index.ts +2 -0
- package/src/services/transactions/{transactionsManager.ts → manager/transactionsManager.ts} +46 -354
- package/src/services/transactions/types/index.ts +3 -0
- package/src/services/transactions/types/lookupTables.ts +37 -0
- package/src/services/transactions/types/transactionItem.ts +43 -0
- package/src/services/transactions/types/transactionSet.ts +114 -0
- package/src/solautoPosition/positionUtils.ts +1 -1
- package/src/solautoPosition/solautoPositionEx.ts +11 -12
- package/src/utils/instructionUtils.ts +6 -3
- package/src/utils/switchboardUtils.ts +17 -2
- package/tests/transactions/shared.ts +6 -3
- package/dist/services/transactions/transactionsManager.d.ts +0 -68
- package/dist/services/transactions/transactionsManager.d.ts.map +0 -1
@@ -240,43 +240,41 @@ export abstract class SolautoPositionEx {
|
|
240
240
|
return this._supplyPrice ?? safeGetPrice(this.supplyMint, priceType);
|
241
241
|
}
|
242
242
|
|
243
|
-
|
244
243
|
get totalDebt() {
|
245
244
|
return calcTotalDebt(this.state);
|
246
245
|
}
|
247
|
-
|
246
|
+
|
248
247
|
debtUsd(priceType?: PriceType) {
|
249
248
|
const debtPrice = this.debtPrice(priceType);
|
250
249
|
return debtPrice
|
251
|
-
|
252
|
-
|
250
|
+
? calcTotalDebt(this.state) * debtPrice
|
251
|
+
: calcDebtUsd(this.state);
|
253
252
|
}
|
254
|
-
|
253
|
+
|
255
254
|
protected debtPrice(priceType?: PriceType) {
|
256
255
|
return this._debtPrice ?? safeGetPrice(this.debtMint, priceType);
|
257
256
|
}
|
258
|
-
|
259
|
-
|
257
|
+
|
260
258
|
get supplyLiquidityDepositable() {
|
261
259
|
return supplyLiquidityDepositable(this.state);
|
262
260
|
}
|
263
|
-
|
261
|
+
|
264
262
|
get supplyLiquidityUsdDepositable() {
|
265
263
|
return supplyLiquidityUsdDepositable(this.state);
|
266
264
|
}
|
267
|
-
|
265
|
+
|
268
266
|
get supplyLiquidityUsdAvailable() {
|
269
267
|
return this.supplyLiquidityAvailable * (this.supplyPrice() ?? 0);
|
270
268
|
}
|
271
|
-
|
269
|
+
|
272
270
|
get debtLiquidityAvailable() {
|
273
271
|
return debtLiquidityAvailable(this.state);
|
274
272
|
}
|
275
|
-
|
273
|
+
|
276
274
|
get debtLiquidityUsdAvailable() {
|
277
275
|
return debtLiquidityUsdAvailable(this.state);
|
278
276
|
}
|
279
|
-
|
277
|
+
|
280
278
|
abstract get lpSupplyAccount(): PublicKey;
|
281
279
|
abstract get lpDebtAccount(): PublicKey;
|
282
280
|
abstract get supplyLiquidityAvailable(): number;
|
@@ -308,6 +306,7 @@ export abstract class SolautoPositionEx {
|
|
308
306
|
|
309
307
|
protected canRefreshPositionState() {
|
310
308
|
if (
|
309
|
+
this.state.maxLtvBps === 0 ||
|
311
310
|
currentUnixSeconds() - Number(this.state.lastRefreshed) > 5 ||
|
312
311
|
this.contextUpdates?.positionUpdates()
|
313
312
|
) {
|
@@ -82,7 +82,8 @@ export function borrow(client: SolautoClient, baseUnitAmount: bigint) {
|
|
82
82
|
fields: [baseUnitAmount],
|
83
83
|
}),
|
84
84
|
}),
|
85
|
-
"borrow"
|
85
|
+
"borrow",
|
86
|
+
true
|
86
87
|
);
|
87
88
|
}
|
88
89
|
|
@@ -98,7 +99,8 @@ export function withdraw(client: SolautoClient, amount: "All" | bigint) {
|
|
98
99
|
],
|
99
100
|
}),
|
100
101
|
}),
|
101
|
-
"withdraw"
|
102
|
+
"withdraw",
|
103
|
+
true
|
102
104
|
);
|
103
105
|
}
|
104
106
|
|
@@ -129,7 +131,8 @@ export function rebalance(
|
|
129
131
|
targetLiqUtilizationRateBps,
|
130
132
|
attemptNum > 2 && prevError instanceof TransactionTooLargeError
|
131
133
|
).buildRebalanceTx(attemptNum),
|
132
|
-
"rebalance"
|
134
|
+
"rebalance",
|
135
|
+
true
|
133
136
|
);
|
134
137
|
}
|
135
138
|
|
@@ -8,10 +8,14 @@ import { Signer, transactionBuilder } from "@metaplex-foundation/umi";
|
|
8
8
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
9
9
|
import { AnchorProvider, Idl, Program } from "@coral-xyz/anchor";
|
10
10
|
import * as OnDemand from "@switchboard-xyz/on-demand";
|
11
|
+
import Big from "big.js";
|
11
12
|
import switchboardIdl from "../idls/switchboard.json";
|
12
|
-
import { SWITCHBOARD_PRICE_FEED_IDS } from "../constants";
|
13
|
+
import { PRICES, SWITCHBOARD_PRICE_FEED_IDS } from "../constants";
|
13
14
|
import { TransactionItemInputs } from "../types";
|
14
|
-
import {
|
15
|
+
import {
|
16
|
+
currentUnixSeconds,
|
17
|
+
retryWithExponentialBackoff,
|
18
|
+
} from "./generalUtils";
|
15
19
|
import { getWrappedInstruction } from "./solanaUtils";
|
16
20
|
|
17
21
|
export function getPullFeed(
|
@@ -62,6 +66,13 @@ export async function buildSwbSubmitResponseTx(
|
|
62
66
|
throw new Error("Unable to fetch SWB crank IX");
|
63
67
|
}
|
64
68
|
|
69
|
+
const price = (responses[0].value as Big).toNumber();
|
70
|
+
PRICES[mint.toString()] = {
|
71
|
+
realtimePrice: price,
|
72
|
+
emaPrice: price,
|
73
|
+
time: currentUnixSeconds(),
|
74
|
+
};
|
75
|
+
|
65
76
|
return {
|
66
77
|
tx: transactionBuilder([getWrappedInstruction(signer, pullIx!)]),
|
67
78
|
lookupTableAddresses: responses
|
@@ -97,3 +108,7 @@ export async function getSwitchboardFeedData(
|
|
97
108
|
|
98
109
|
return results;
|
99
110
|
}
|
111
|
+
|
112
|
+
export function isSwitchboardMint(mint: PublicKey | string) {
|
113
|
+
return Object.keys(SWITCHBOARD_PRICE_FEED_IDS).includes(mint.toString());
|
114
|
+
}
|
@@ -13,7 +13,6 @@ import {
|
|
13
13
|
SOLAUTO_TEST_PROGRAM,
|
14
14
|
SolautoSettingsParametersInpArgs,
|
15
15
|
toBaseUnit,
|
16
|
-
TransactionsManager,
|
17
16
|
USDC,
|
18
17
|
deposit,
|
19
18
|
openSolautoPosition,
|
@@ -22,6 +21,7 @@ import {
|
|
22
21
|
withdraw,
|
23
22
|
closeSolautoPosition,
|
24
23
|
getMarginfiAccounts,
|
24
|
+
ClientTransactionsManager,
|
25
25
|
} from "../../src";
|
26
26
|
|
27
27
|
export async function e2eTransactionTest(
|
@@ -79,8 +79,11 @@ export async function e2eTransactionTest(
|
|
79
79
|
closeSolautoPosition(client),
|
80
80
|
];
|
81
81
|
|
82
|
-
const txManager = new
|
83
|
-
|
82
|
+
const txManager = new ClientTransactionsManager({
|
83
|
+
txHandler: client,
|
84
|
+
txRunType: "only-simulate",
|
85
|
+
});
|
86
|
+
const statuses = await txManager.send(transactionItems);
|
84
87
|
|
85
88
|
consoleLog(statuses);
|
86
89
|
}
|
@@ -1,68 +0,0 @@
|
|
1
|
-
import { TransactionBuilder } from "@metaplex-foundation/umi";
|
2
|
-
import { PriorityFeeSetting, TransactionItemInputs, TransactionRunType } from "../../types";
|
3
|
-
import { ErrorsToThrow } from "../../utils";
|
4
|
-
import { SolautoClient, ReferralStateManager } from "../solauto";
|
5
|
-
export declare class TransactionTooLargeError extends Error {
|
6
|
-
constructor(message: string);
|
7
|
-
}
|
8
|
-
export declare class TransactionItem {
|
9
|
-
fetchTx: (attemptNum: number, prevError?: Error) => Promise<TransactionItemInputs | undefined>;
|
10
|
-
name?: string | undefined;
|
11
|
-
lookupTableAddresses: string[];
|
12
|
-
tx?: TransactionBuilder;
|
13
|
-
initialized: boolean;
|
14
|
-
orderPrio: number;
|
15
|
-
constructor(fetchTx: (attemptNum: number, prevError?: Error) => Promise<TransactionItemInputs | undefined>, name?: string | undefined);
|
16
|
-
initialize(): Promise<void>;
|
17
|
-
refetch(attemptNum: number, prevError?: Error): Promise<void>;
|
18
|
-
uniqueAccounts(): string[];
|
19
|
-
}
|
20
|
-
export declare enum TransactionStatus {
|
21
|
-
Skipped = "Skipped",
|
22
|
-
Processing = "Processing",
|
23
|
-
Queued = "Queued",
|
24
|
-
Successful = "Successful",
|
25
|
-
Failed = "Failed"
|
26
|
-
}
|
27
|
-
export type TransactionManagerStatuses = {
|
28
|
-
name: string;
|
29
|
-
attemptNum: number;
|
30
|
-
status: TransactionStatus;
|
31
|
-
moreInfo?: string;
|
32
|
-
simulationSuccessful?: boolean;
|
33
|
-
txSig?: string;
|
34
|
-
}[];
|
35
|
-
interface RetryConfig {
|
36
|
-
signableRetries?: number;
|
37
|
-
totalRetries?: number;
|
38
|
-
retryDelay?: number;
|
39
|
-
}
|
40
|
-
export declare class TransactionsManager {
|
41
|
-
private txHandler;
|
42
|
-
private statusCallback?;
|
43
|
-
private txType?;
|
44
|
-
private priorityFeeSetting;
|
45
|
-
private atomically;
|
46
|
-
private errorsToThrow?;
|
47
|
-
private statuses;
|
48
|
-
private lookupTables;
|
49
|
-
private signableRetries;
|
50
|
-
private totalRetries;
|
51
|
-
private retryDelay;
|
52
|
-
updateOracleTxName: string;
|
53
|
-
constructor(txHandler: SolautoClient | ReferralStateManager, statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined, txType?: TransactionRunType | undefined, priorityFeeSetting?: PriorityFeeSetting, atomically?: boolean, errorsToThrow?: ErrorsToThrow | undefined, retryConfig?: RetryConfig);
|
54
|
-
private assembleTransactionSets;
|
55
|
-
private updateStatus;
|
56
|
-
private debugAccounts;
|
57
|
-
private getUpdatedPriorityFeeSetting;
|
58
|
-
private updateStatusForSets;
|
59
|
-
private updateLut;
|
60
|
-
clientSend(transactions: TransactionItem[]): Promise<TransactionManagerStatuses>;
|
61
|
-
send(items: TransactionItem[]): Promise<TransactionManagerStatuses>;
|
62
|
-
private processTransactionsAtomically;
|
63
|
-
private processTransactionSet;
|
64
|
-
private refreshItemSets;
|
65
|
-
private sendTransaction;
|
66
|
-
}
|
67
|
-
export {};
|
68
|
-
//# sourceMappingURL=transactionsManager.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/transactionsManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAElB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAMrB,OAAO,EAEL,aAAa,EAQd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAM5E,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAqCD,qBAAa,eAAe;IAOjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,KAAK,KACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM;IAVtB,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACxB,WAAW,EAAE,OAAO,CAAS;IAC7B,SAAS,EAAE,MAAM,CAAK;gBAGb,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,KAAK,KACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,EACxC,IAAI,CAAC,EAAE,MAAM,YAAA;IAGhB,UAAU;IAKV,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;IAOnD,cAAc,IAAI,MAAM,EAAE;CAY3B;AAwGD,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,UAAU,eAAe;IACzB,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,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