@haven-fi/solauto-sdk 1.0.302 → 1.0.304
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 +1 -2
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +20 -24
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +4 -3
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +15 -0
- package/dist/utils/generalUtils.d.ts +2 -6
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +0 -85
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.js +10 -2
- package/dist/utils/marginfiUtils.d.ts +2 -2
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +13 -16
- package/dist/utils/priceUtils.d.ts +12 -0
- package/dist/utils/priceUtils.d.ts.map +1 -0
- package/dist/utils/priceUtils.js +97 -0
- package/dist/utils/solanaUtils.d.ts.map +1 -1
- package/dist/utils/solanaUtils.js +1 -1
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +2 -1
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +5 -4
- package/dist/utils/switchboardUtils.d.ts +7 -0
- package/dist/utils/switchboardUtils.d.ts.map +1 -0
- package/dist/utils/switchboardUtils.js +41 -0
- package/local/createISMAccounts.ts +59 -0
- package/local/updateMarginfiLUT.ts +0 -1
- package/local/updateSolautoLUT.ts +38 -7
- package/package.json +2 -1
- package/src/clients/solautoMarginfiClient.ts +18 -27
- package/src/constants/README.md +0 -2
- package/src/transactions/transactionUtils.ts +8 -3
- package/src/transactions/transactionsManager.ts +33 -2
- package/src/utils/generalUtils.ts +2 -147
- package/src/utils/index.ts +3 -1
- package/src/utils/jupiterUtils.ts +13 -3
- package/src/utils/marginfiUtils.ts +5 -25
- package/src/utils/priceUtils.ts +154 -0
- package/src/utils/solanaUtils.ts +1 -2
- package/src/utils/solauto/generalUtils.ts +3 -2
- package/src/utils/solauto/rebalanceUtils.ts +2 -1
- package/src/utils/switchboardUtils.ts +66 -0
- package/tests/transactions/solautoMarginfi.ts +29 -24
- package/tests/unit/rebalanceCalculations.ts +6 -5
- package/local/createSolautoManagerAccount.ts +0 -48
@@ -8,13 +8,14 @@ import {
|
|
8
8
|
} from "../../src/generated";
|
9
9
|
import { buildSolautoRebalanceTransaction } from "../../src/transactions/transactionUtils";
|
10
10
|
import {
|
11
|
+
getLiqUtilzationRateBps,
|
11
12
|
maxBoostToBps,
|
12
13
|
maxRepayFromBps,
|
13
14
|
maxRepayToBps,
|
14
15
|
toBaseUnit,
|
15
16
|
} from "../../src/utils/numberUtils";
|
16
17
|
import { NATIVE_MINT } from "@solana/spl-token";
|
17
|
-
import { consoleLog
|
18
|
+
import { consoleLog } from "../../src/utils/generalUtils";
|
18
19
|
import {
|
19
20
|
TransactionItem,
|
20
21
|
TransactionsManager,
|
@@ -32,9 +33,9 @@ describe("Solauto Marginfi tests", async () => {
|
|
32
33
|
const signer = setupTest();
|
33
34
|
// const signer = setupTest("solauto-manager");
|
34
35
|
|
35
|
-
const payForTransactions =
|
36
|
+
const payForTransactions = true;
|
36
37
|
const testProgram = true;
|
37
|
-
const positionId =
|
38
|
+
const positionId = 3;
|
38
39
|
|
39
40
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
40
41
|
const client = new SolautoMarginfiClient(
|
@@ -44,29 +45,38 @@ describe("Solauto Marginfi tests", async () => {
|
|
44
45
|
);
|
45
46
|
|
46
47
|
const supply = NATIVE_MINT;
|
47
|
-
const supplyDecimals =
|
48
|
+
const supplyDecimals = 6;
|
48
49
|
const debtDecimals = 6;
|
49
50
|
|
50
51
|
await client.initialize({
|
51
52
|
signer,
|
52
53
|
positionId,
|
53
54
|
authority: new PublicKey("rC5dMP5dmSsfQ66rynzfFzuc122Eex9h1RJHVDkeH6D"),
|
55
|
+
// new: true,
|
54
56
|
// marginfiAccount: new PublicKey(
|
55
57
|
// "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
|
56
58
|
// ),
|
57
|
-
//
|
59
|
+
// marginfiGroup: new PublicKey("G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"),
|
60
|
+
// supplyMint: new PublicKey("3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump"),
|
58
61
|
// debtMint: new PublicKey(USDC),
|
59
62
|
});
|
60
63
|
|
61
64
|
const transactionItems: TransactionItem[] = [];
|
62
65
|
const settingParams: SolautoSettingsParametersInpArgs = {
|
63
|
-
boostToBps:
|
66
|
+
boostToBps: maxBoostToBps(
|
67
|
+
client.solautoPositionState?.maxLtvBps ?? 0,
|
68
|
+
client.solautoPositionState?.liqThresholdBps ?? 0
|
69
|
+
),
|
64
70
|
boostGap: 50,
|
65
|
-
repayToBps:
|
71
|
+
repayToBps: maxRepayToBps(
|
72
|
+
client.solautoPositionState?.maxLtvBps ?? 0,
|
73
|
+
client.solautoPositionState?.liqThresholdBps ?? 0
|
74
|
+
),
|
66
75
|
repayGap: 50,
|
67
76
|
automation: none(),
|
68
77
|
targetBoostToBps: none(),
|
69
78
|
};
|
79
|
+
console.log(settingParams);
|
70
80
|
|
71
81
|
// if (client.solautoPositionData === null) {
|
72
82
|
// transactionItems.push(
|
@@ -77,17 +87,17 @@ describe("Solauto Marginfi tests", async () => {
|
|
77
87
|
// }, "open position")
|
78
88
|
// );
|
79
89
|
|
80
|
-
//
|
81
|
-
//
|
82
|
-
//
|
83
|
-
//
|
84
|
-
//
|
85
|
-
//
|
86
|
-
//
|
87
|
-
//
|
88
|
-
//
|
89
|
-
//
|
90
|
-
//
|
90
|
+
// const initialSupplyUsd = 150;
|
91
|
+
// transactionItems.push(
|
92
|
+
// new TransactionItem(async () => {
|
93
|
+
// // const [supplyPrice] = await fetchTokenPrices([supply]);
|
94
|
+
// return {
|
95
|
+
// tx: client.protocolInteraction(
|
96
|
+
// solautoAction("Deposit", [toBaseUnit(300, supplyDecimals)])
|
97
|
+
// ),
|
98
|
+
// };
|
99
|
+
// }, "deposit")
|
100
|
+
// );
|
91
101
|
// }
|
92
102
|
|
93
103
|
// const maxLtvBps = client.solautoPositionState!.maxLtvBps;
|
@@ -102,10 +112,6 @@ describe("Solauto Marginfi tests", async () => {
|
|
102
112
|
// positionId: client.positionId,
|
103
113
|
// settingParams: some({
|
104
114
|
// ...settingParams,
|
105
|
-
// boostToBps: maxBoostTo,
|
106
|
-
// boostGap: 50,
|
107
|
-
// repayToBps: maxRepayTo,
|
108
|
-
// repayGap: maxRepayFrom - maxRepayTo
|
109
115
|
// }),
|
110
116
|
// dca: null,
|
111
117
|
// }),
|
@@ -117,7 +123,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
117
123
|
transactionItems.push(
|
118
124
|
new TransactionItem(
|
119
125
|
async (attemptNum) =>
|
120
|
-
await buildSolautoRebalanceTransaction(client,
|
126
|
+
await buildSolautoRebalanceTransaction(client, 3000, attemptNum),
|
121
127
|
"rebalance"
|
122
128
|
)
|
123
129
|
);
|
@@ -158,6 +164,5 @@ describe("Solauto Marginfi tests", async () => {
|
|
158
164
|
).clientSend(transactionItems);
|
159
165
|
|
160
166
|
console.log(statuses);
|
161
|
-
|
162
167
|
});
|
163
168
|
});
|
@@ -31,13 +31,14 @@ import {
|
|
31
31
|
getUpdatedValueFromAutomation,
|
32
32
|
positionStateWithLatestPrices,
|
33
33
|
} from "../../src/utils/solauto/generalUtils";
|
34
|
+
import { currentUnixSeconds } from "../../src/utils/generalUtils";
|
35
|
+
import { USDC } from "../../src/constants/tokenConstants";
|
34
36
|
import {
|
35
|
-
|
37
|
+
buildHeliusApiUrl,
|
36
38
|
fetchTokenPrices,
|
39
|
+
getSolanaRpcConnection,
|
37
40
|
safeGetPrice,
|
38
|
-
} from "../../src/utils
|
39
|
-
import { USDC } from "../../src/constants/tokenConstants";
|
40
|
-
import { buildHeliusApiUrl, getSolanaRpcConnection } from "../../src/utils";
|
41
|
+
} from "../../src/utils";
|
41
42
|
|
42
43
|
const signer = setupTest(undefined, true);
|
43
44
|
const [conn, _] = getSolanaRpcConnection(
|
@@ -287,7 +288,7 @@ describe("Rebalance tests", async () => {
|
|
287
288
|
let supplyPrice: number, debtPrice: number;
|
288
289
|
|
289
290
|
before(async () => {
|
290
|
-
[supplyPrice, debtPrice] = await fetchTokenPrices(
|
291
|
+
[supplyPrice, debtPrice] = await fetchTokenPrices([
|
291
292
|
NATIVE_MINT,
|
292
293
|
new PublicKey(USDC),
|
293
294
|
]);
|
@@ -1,48 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
createSignerFromKeypair,
|
3
|
-
publicKey,
|
4
|
-
signerIdentity,
|
5
|
-
transactionBuilder,
|
6
|
-
} from "@metaplex-foundation/umi";
|
7
|
-
import {
|
8
|
-
buildHeliusApiUrl,
|
9
|
-
getSolanaRpcConnection,
|
10
|
-
sendSingleOptimizedTransaction,
|
11
|
-
} from "../src/utils/solanaUtils";
|
12
|
-
import { marginfiAccountInitialize } from "../src/marginfi-sdk";
|
13
|
-
import { DEFAULT_MARGINFI_GROUP } from "../src/constants";
|
14
|
-
import { getSecretKey } from "./shared";
|
15
|
-
import { updateSolautoLut } from "./updateSolautoLUT";
|
16
|
-
|
17
|
-
async function create() {
|
18
|
-
let [connection, umi] = getSolanaRpcConnection(buildHeliusApiUrl(process.env.HELIUS_API_KEY!));
|
19
|
-
|
20
|
-
const secretKey = getSecretKey("solauto-manager");
|
21
|
-
const signerKeypair = umi.eddsa.createKeypairFromSecretKey(secretKey);
|
22
|
-
const signer = createSignerFromKeypair(umi, signerKeypair);
|
23
|
-
|
24
|
-
umi = umi.use(signerIdentity(signer));
|
25
|
-
|
26
|
-
const marginfiAccount = createSignerFromKeypair(
|
27
|
-
umi,
|
28
|
-
umi.eddsa.generateKeypair()
|
29
|
-
);
|
30
|
-
console.log(marginfiAccount.publicKey);
|
31
|
-
|
32
|
-
const tx = marginfiAccountInitialize(umi, {
|
33
|
-
marginfiAccount,
|
34
|
-
marginfiGroup: publicKey(DEFAULT_MARGINFI_GROUP),
|
35
|
-
authority: signer,
|
36
|
-
feePayer: signer,
|
37
|
-
});
|
38
|
-
|
39
|
-
await sendSingleOptimizedTransaction(
|
40
|
-
umi,
|
41
|
-
connection,
|
42
|
-
transactionBuilder().add(tx)
|
43
|
-
);
|
44
|
-
|
45
|
-
await updateSolautoLut([marginfiAccount.publicKey.toString()]);
|
46
|
-
}
|
47
|
-
|
48
|
-
create();
|