@haven-fi/solauto-sdk 1.0.688 → 1.0.689
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/local/txSandbox.ts +67 -13
- package/package.json +1 -1
- package/src/services/rebalance/rebalanceSwapManager.ts +8 -7
- package/src/services/rebalance/rebalanceTxBuilder.ts +2 -1
- package/src/services/solauto/solautoClient.ts +1 -0
- package/src/services/transactions/manager/transactionsManager.ts +2 -2
- package/src/utils/switchboardUtils.ts +10 -5
package/local/txSandbox.ts
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
import { Keypair, PublicKey } from "@solana/web3.js";
|
2
|
-
import { createSignerFromKeypair } from "@metaplex-foundation/umi";
|
2
|
+
import { createSignerFromKeypair, publicKey } from "@metaplex-foundation/umi";
|
3
3
|
import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
|
4
4
|
import {
|
5
|
+
bytesToI80F48,
|
5
6
|
ClientTransactionsManager,
|
6
7
|
consoleLog,
|
8
|
+
fetchBank,
|
9
|
+
fetchMarginfiAccount,
|
7
10
|
getBatches,
|
8
11
|
getClient,
|
12
|
+
getLiqUtilzationRateBps,
|
9
13
|
getPositionExBulk,
|
10
14
|
getSolanaRpcConnection,
|
11
15
|
getSolautoManagedPositions,
|
12
16
|
LendingPlatform,
|
13
17
|
LOCAL_IRONFORGE_API_URL,
|
18
|
+
marginfiAccountEmpty,
|
14
19
|
PriceType,
|
15
20
|
PriorityFeeSetting,
|
16
21
|
ProgramEnv,
|
@@ -23,7 +28,7 @@ import {
|
|
23
28
|
import { getSecretKey } from "./shared";
|
24
29
|
|
25
30
|
const payForTransaction = false;
|
26
|
-
const testProgram =
|
31
|
+
const testProgram = true;
|
27
32
|
const lpEnv: ProgramEnv = "Prod";
|
28
33
|
|
29
34
|
let [, umi] = getSolanaRpcConnection(
|
@@ -47,23 +52,72 @@ export async function main() {
|
|
47
52
|
});
|
48
53
|
|
49
54
|
await client.initializeExistingSolautoPosition({
|
50
|
-
positionId:
|
51
|
-
authority: new PublicKey("
|
55
|
+
positionId: 2,
|
56
|
+
authority: new PublicKey("rC5dMP5dmSsfQ66rynzfFzuc122Eex9h1RJHVDkeH6D"),
|
52
57
|
// lpUserAccount: new PublicKey(
|
53
58
|
// "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
|
54
59
|
// ),
|
55
60
|
});
|
56
61
|
|
57
|
-
const
|
62
|
+
const supplyBank = await fetchBank(
|
63
|
+
umi,
|
64
|
+
publicKey("6cgYhBFWCc5sNHxkvSRhd5H9AdAHR41zKwuF37HmLry5")
|
65
|
+
);
|
66
|
+
const debtBank = await fetchBank(
|
67
|
+
umi,
|
68
|
+
publicKey("3J5rKmCi7JXG6qmiobFJyAidVTnnNAMGj4jomfBxKGRM")
|
69
|
+
);
|
70
|
+
const supplyWeight = bytesToI80F48(supplyBank.config.assetWeightInit.value);
|
71
|
+
const debtWeight = bytesToI80F48(debtBank.config.liabilityWeightInit.value);
|
58
72
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
73
|
+
console.log(
|
74
|
+
getLiqUtilzationRateBps(
|
75
|
+
34.36833665228071,
|
76
|
+
23.61750715267401,
|
77
|
+
client.pos.state.liqThresholdBps
|
78
|
+
),
|
79
|
+
34.36833665228071 * supplyWeight,
|
80
|
+
23.61750715267401 * debtWeight
|
81
|
+
);
|
82
|
+
console.log(
|
83
|
+
getLiqUtilzationRateBps(
|
84
|
+
34.328721976,
|
85
|
+
23.575158311,
|
86
|
+
client.pos.state.liqThresholdBps
|
87
|
+
),
|
88
|
+
34.328721976 * supplyWeight,
|
89
|
+
23.575158311 * debtWeight
|
90
|
+
);
|
91
|
+
console.log(client.pos.maxBoostToBps);
|
92
|
+
|
93
|
+
// const debtBank = await fetchBank(
|
94
|
+
// umi,
|
95
|
+
// publicKey("3J5rKmCi7JXG6qmiobFJyAidVTnnNAMGj4jomfBxKGRM")
|
96
|
+
// );
|
97
|
+
// const supplyBank = await fetchBank(
|
98
|
+
// umi,
|
99
|
+
// publicKey("6cgYhBFWCc5sNHxkvSRhd5H9AdAHR41zKwuF37HmLry5")
|
100
|
+
// );
|
101
|
+
|
102
|
+
// console.log(
|
103
|
+
// bytesToI80F48(supplyBank.config.assetWeightInit.value),
|
104
|
+
// bytesToI80F48(debtBank.config.liabilityWeightInit.value)
|
105
|
+
// );
|
106
|
+
|
107
|
+
// await client.pos.refreshPositionState();
|
108
|
+
|
109
|
+
// console.log(await client.pos.utilizationRateBpsDrift());
|
110
|
+
|
111
|
+
// const transactionItems = [rebalance(client)];
|
112
|
+
|
113
|
+
// const txManager = new ClientTransactionsManager({
|
114
|
+
// txHandler: client,
|
115
|
+
// txRunType: payForTransaction ? "normal" : "only-simulate",
|
116
|
+
// priorityFeeSetting: PriorityFeeSetting.Default,
|
117
|
+
// retryConfig: { totalRetries: 5 },
|
118
|
+
// });
|
119
|
+
// const statuses = await txManager.send(transactionItems);
|
120
|
+
// consoleLog(statuses);
|
67
121
|
}
|
68
122
|
|
69
123
|
async function refreshAll() {
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@ import { FlashLoanRequirements } from "../../types";
|
|
4
4
|
import { SolautoClient } from "../solauto";
|
5
5
|
import { JupSwapManager, SwapParams, SwapInput } from "../swap";
|
6
6
|
import { RebalanceValues } from "./rebalanceValues";
|
7
|
-
import { RebalanceDirection, TokenType } from "../../generated";
|
7
|
+
import { PriceType, RebalanceDirection, TokenType } from "../../generated";
|
8
8
|
import {
|
9
9
|
consoleLog,
|
10
10
|
fromBaseUnit,
|
@@ -25,7 +25,8 @@ export class RebalanceSwapManager {
|
|
25
25
|
private client: SolautoClient,
|
26
26
|
private values: RebalanceValues,
|
27
27
|
private flRequirements?: FlashLoanRequirements,
|
28
|
-
private targetLiqUtilizationRateBps?: number
|
28
|
+
private targetLiqUtilizationRateBps?: number,
|
29
|
+
private priceType?: PriceType
|
29
30
|
) {
|
30
31
|
this.jupSwapManager = new JupSwapManager(client.signer);
|
31
32
|
}
|
@@ -39,16 +40,16 @@ export class RebalanceSwapManager {
|
|
39
40
|
}
|
40
41
|
|
41
42
|
private postRebalanceLiqUtilizationRateBps(swapOutputAmount?: bigint) {
|
42
|
-
let supplyUsd = this.client.pos.supplyUsd();
|
43
|
+
let supplyUsd = this.client.pos.supplyUsd(this.priceType);
|
43
44
|
// TODO: add token balance change
|
44
|
-
let debtUsd = this.client.pos.debtUsd();
|
45
|
+
let debtUsd = this.client.pos.debtUsd(this.priceType);
|
45
46
|
|
46
47
|
const outputToken = this.isBoost()
|
47
48
|
? this.client.pos.supplyMint
|
48
49
|
: this.client.pos.debtMint;
|
49
50
|
const swapOutputUsd = swapOutputAmount
|
50
51
|
? fromBaseUnit(swapOutputAmount, tokenInfo(outputToken).decimals) *
|
51
|
-
(safeGetPrice(outputToken) ?? 0)
|
52
|
+
(safeGetPrice(outputToken, this.priceType) ?? 0)
|
52
53
|
: this.usdToSwap();
|
53
54
|
|
54
55
|
supplyUsd = this.isBoost()
|
@@ -110,7 +111,7 @@ export class RebalanceSwapManager {
|
|
110
111
|
: this.client.pos.state.debt;
|
111
112
|
|
112
113
|
let inputAmount = toBaseUnit(
|
113
|
-
this.usdToSwap() / safeGetPrice(input.mint)!,
|
114
|
+
this.usdToSwap() / safeGetPrice(input.mint, this.priceType)!,
|
114
115
|
input.decimals
|
115
116
|
);
|
116
117
|
|
@@ -139,7 +140,7 @@ export class RebalanceSwapManager {
|
|
139
140
|
)
|
140
141
|
)
|
141
142
|
: toBaseUnit(
|
142
|
-
this.usdToSwap() / safeGetPrice(output.mint)!,
|
143
|
+
this.usdToSwap() / safeGetPrice(output.mint, this.priceType)!,
|
143
144
|
output.decimals
|
144
145
|
);
|
145
146
|
|
@@ -287,7 +287,8 @@ export class RebalanceTxBuilder {
|
|
287
287
|
this.client,
|
288
288
|
this.values,
|
289
289
|
this.flRequirements,
|
290
|
-
this.targetLiqUtilizationRateBps
|
290
|
+
this.targetLiqUtilizationRateBps,
|
291
|
+
this.priceType
|
291
292
|
);
|
292
293
|
await this.swapManager.setSwapParams(attemptNum);
|
293
294
|
|
@@ -179,6 +179,7 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
179
179
|
|
180
180
|
this.log("Position state: ", this.pos.state);
|
181
181
|
this.log("Position settings: ", this.pos.settings);
|
182
|
+
this.log("Public key:", this.pos.publicKey.toString());
|
182
183
|
this.log("Supply mint:", this.pos.supplyMint.toString());
|
183
184
|
this.log("Debt mint:", this.pos.debtMint.toString());
|
184
185
|
this.log("LP pool:", this.pos.lpPoolAccount.toString());
|
@@ -48,7 +48,7 @@ interface RetryConfig {
|
|
48
48
|
retryDelay?: number;
|
49
49
|
}
|
50
50
|
|
51
|
-
export interface
|
51
|
+
export interface TransactionsManagerArgs<T extends TxHandler> {
|
52
52
|
txHandler: T;
|
53
53
|
statusCallback?: (statuses: TransactionManagerStatuses) => void;
|
54
54
|
txRunType?: TransactionRunType;
|
@@ -73,7 +73,7 @@ export class TransactionsManager<T extends TxHandler> {
|
|
73
73
|
|
74
74
|
updateOracleTxName = "update oracle";
|
75
75
|
|
76
|
-
constructor(args:
|
76
|
+
constructor(args: TransactionsManagerArgs<T>) {
|
77
77
|
this.txHandler = args.txHandler;
|
78
78
|
this.statusCallback = args.statusCallback;
|
79
79
|
this.txRunType = args.txRunType;
|
@@ -53,12 +53,17 @@ export async function buildSwbSubmitResponseTx(
|
|
53
53
|
): Promise<TransactionItemInputs | undefined> {
|
54
54
|
const feed = getPullFeed(conn, mint, toWeb3JsPublicKey(signer.publicKey));
|
55
55
|
const [pullIx, responses] = await retryWithExponentialBackoff(
|
56
|
-
async () =>
|
57
|
-
await feed.fetchUpdateIx({
|
56
|
+
async () => {
|
57
|
+
const res = await feed.fetchUpdateIx({
|
58
58
|
chain: "solana",
|
59
59
|
network: "mainnet-beta",
|
60
|
-
})
|
61
|
-
|
60
|
+
});
|
61
|
+
if (!res[1] || !res[1][0].value) {
|
62
|
+
throw new Error("Unable to fetch Switchboard pull IX");
|
63
|
+
}
|
64
|
+
return res;
|
65
|
+
},
|
66
|
+
3,
|
62
67
|
200
|
63
68
|
);
|
64
69
|
|
@@ -111,4 +116,4 @@ export async function getSwitchboardFeedData(
|
|
111
116
|
|
112
117
|
export function isSwitchboardMint(mint: PublicKey | string) {
|
113
118
|
return Object.keys(SWITCHBOARD_PRICE_FEED_IDS).includes(mint.toString());
|
114
|
-
}
|
119
|
+
}
|