@haven-fi/solauto-sdk 1.0.303 → 1.0.305
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 +22 -26
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +5 -4
- 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 -91
- 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 -12
- 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 +1 -1
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +3 -2
- 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 +17 -28
- package/src/constants/README.md +0 -2
- package/src/transactions/transactionUtils.ts +8 -4
- package/src/transactions/transactionsManager.ts +33 -2
- package/src/utils/generalUtils.ts +2 -152
- package/src/utils/index.ts +3 -1
- package/src/utils/jupiterUtils.ts +13 -3
- package/src/utils/marginfiUtils.ts +5 -16
- package/src/utils/priceUtils.ts +154 -0
- package/src/utils/solanaUtils.ts +1 -2
- package/src/utils/solauto/generalUtils.ts +3 -3
- package/src/utils/solauto/rebalanceUtils.ts +2 -1
- package/src/utils/switchboardUtils.ts +66 -0
- package/tests/transactions/solautoMarginfi.ts +35 -33
- package/tests/unit/rebalanceCalculations.ts +6 -6
- 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,7 +33,7 @@ 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
38
|
const positionId = 3;
|
38
39
|
|
@@ -55,42 +56,48 @@ describe("Solauto Marginfi tests", async () => {
|
|
55
56
|
// marginfiAccount: new PublicKey(
|
56
57
|
// "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
|
57
58
|
// ),
|
58
|
-
marginfiGroup: new PublicKey("G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"),
|
59
|
-
supplyMint: new PublicKey("3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump"),
|
60
|
-
debtMint: new PublicKey(USDC),
|
59
|
+
// marginfiGroup: new PublicKey("G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"),
|
60
|
+
// supplyMint: new PublicKey("3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump"),
|
61
|
+
// debtMint: new PublicKey(USDC),
|
61
62
|
});
|
62
63
|
|
63
64
|
const transactionItems: TransactionItem[] = [];
|
64
65
|
const settingParams: SolautoSettingsParametersInpArgs = {
|
65
|
-
boostToBps:
|
66
|
+
boostToBps: maxBoostToBps(
|
67
|
+
client.solautoPositionState?.maxLtvBps ?? 0,
|
68
|
+
client.solautoPositionState?.liqThresholdBps ?? 0
|
69
|
+
),
|
66
70
|
boostGap: 50,
|
67
|
-
repayToBps:
|
71
|
+
repayToBps: maxRepayToBps(
|
72
|
+
client.solautoPositionState?.maxLtvBps ?? 0,
|
73
|
+
client.solautoPositionState?.liqThresholdBps ?? 0
|
74
|
+
),
|
68
75
|
repayGap: 50,
|
69
76
|
automation: none(),
|
70
77
|
targetBoostToBps: none(),
|
71
78
|
};
|
72
79
|
|
73
|
-
if (client.solautoPositionData === null) {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
// if (client.solautoPositionData === null) {
|
81
|
+
// transactionItems.push(
|
82
|
+
// new TransactionItem(async () => {
|
83
|
+
// return {
|
84
|
+
// tx: client.openPosition(settingParams),
|
85
|
+
// };
|
86
|
+
// }, "open position")
|
87
|
+
// );
|
81
88
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}
|
89
|
+
// const initialSupplyUsd = 150;
|
90
|
+
// transactionItems.push(
|
91
|
+
// new TransactionItem(async () => {
|
92
|
+
// // const [supplyPrice] = await fetchTokenPrices([supply]);
|
93
|
+
// return {
|
94
|
+
// tx: client.protocolInteraction(
|
95
|
+
// solautoAction("Deposit", [toBaseUnit(300, supplyDecimals)])
|
96
|
+
// ),
|
97
|
+
// };
|
98
|
+
// }, "deposit")
|
99
|
+
// );
|
100
|
+
// }
|
94
101
|
|
95
102
|
// const maxLtvBps = client.solautoPositionState!.maxLtvBps;
|
96
103
|
// const liqThresholdBps = client.solautoPositionState!.liqThresholdBps;
|
@@ -104,10 +111,6 @@ describe("Solauto Marginfi tests", async () => {
|
|
104
111
|
// positionId: client.positionId,
|
105
112
|
// settingParams: some({
|
106
113
|
// ...settingParams,
|
107
|
-
// boostToBps: maxBoostTo,
|
108
|
-
// boostGap: 50,
|
109
|
-
// repayToBps: maxRepayTo,
|
110
|
-
// repayGap: maxRepayFrom - maxRepayTo
|
111
114
|
// }),
|
112
115
|
// dca: null,
|
113
116
|
// }),
|
@@ -119,7 +122,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
119
122
|
transactionItems.push(
|
120
123
|
new TransactionItem(
|
121
124
|
async (attemptNum) =>
|
122
|
-
await buildSolautoRebalanceTransaction(client,
|
125
|
+
await buildSolautoRebalanceTransaction(client, 3000, attemptNum),
|
123
126
|
"rebalance"
|
124
127
|
)
|
125
128
|
);
|
@@ -160,6 +163,5 @@ describe("Solauto Marginfi tests", async () => {
|
|
160
163
|
).clientSend(transactionItems);
|
161
164
|
|
162
165
|
console.log(statuses);
|
163
|
-
|
164
166
|
});
|
165
167
|
});
|
@@ -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(
|
@@ -126,7 +127,6 @@ async function getFakePosition(
|
|
126
127
|
const maxLtvBps = 6400;
|
127
128
|
const liqThresholdBps = 8181;
|
128
129
|
client.solautoPositionState = await positionStateWithLatestPrices(
|
129
|
-
conn,
|
130
130
|
createFakePositionState(
|
131
131
|
{
|
132
132
|
amountUsed: supplyUsd / supplyPrice,
|
@@ -287,7 +287,7 @@ describe("Rebalance tests", async () => {
|
|
287
287
|
let supplyPrice: number, debtPrice: number;
|
288
288
|
|
289
289
|
before(async () => {
|
290
|
-
[supplyPrice, debtPrice] = await fetchTokenPrices(
|
290
|
+
[supplyPrice, debtPrice] = await fetchTokenPrices([
|
291
291
|
NATIVE_MINT,
|
292
292
|
new PublicKey(USDC),
|
293
293
|
]);
|
@@ -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();
|