@haven-fi/solauto-sdk 1.0.203 → 1.0.204
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +0 -1
- package/dist/generated/instructions/marginfiOpenPosition.d.ts +0 -1
- package/dist/generated/instructions/marginfiOpenPosition.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiOpenPosition.js +13 -18
- package/dist/transactions/transactionUtils.d.ts +1 -1
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +10 -10
- package/package.json +1 -1
- package/src/clients/solautoMarginfiClient.ts +0 -1
- package/src/generated/instructions/marginfiOpenPosition.ts +13 -19
- package/src/transactions/transactionUtils.ts +20 -15
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAM1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EAEb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAUhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AASnE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,eAAe,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACrC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,aAAa,CAAC,EAAE,SAAS,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AE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA6C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA0D5C,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IAqErB,WAAW,CACT,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAoFlE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CA6ClE"}
|
@@ -135,7 +135,6 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
135
135
|
return (0, generated_1.marginfiOpenPosition)(this.umi, {
|
136
136
|
signer: this.signer,
|
137
137
|
marginfiProgram: (0, umi_1.publicKey)(marginfi_sdk_1.MARGINFI_PROGRAM_ID),
|
138
|
-
solautoFeesWallet: (0, umi_1.publicKey)(this.solautoFeesWallet),
|
139
138
|
signerReferralState: (0, umi_1.publicKey)(this.referralStateManager.referralState),
|
140
139
|
referredByState: this.referredByState
|
141
140
|
? (0, umi_1.publicKey)(this.referredByState)
|
@@ -15,7 +15,6 @@ export type MarginfiOpenPositionInstructionAccounts = {
|
|
15
15
|
tokenProgram?: PublicKey | Pda;
|
16
16
|
ataProgram?: PublicKey | Pda;
|
17
17
|
rent?: PublicKey | Pda;
|
18
|
-
solautoFeesWallet: PublicKey | Pda;
|
19
18
|
signerReferralState: PublicKey | Pda;
|
20
19
|
referredByState?: PublicKey | Pda;
|
21
20
|
referredBySupplyTa?: PublicKey | Pda;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiOpenPosition.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/marginfiOpenPosition.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,GAAG,EACH,SAAS,EACT,MAAM,EACN,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,UAAU,EAMX,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EAGvB,MAAM,UAAU,CAAC;AAGlB,MAAM,MAAM,uCAAuC,GAAG;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,SAAS,GAAG,GAAG,CAAC;IACjC,aAAa,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAChC,YAAY,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAC/B,UAAU,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAC7B,IAAI,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACvB,
|
1
|
+
{"version":3,"file":"marginfiOpenPosition.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/marginfiOpenPosition.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,GAAG,EACH,SAAS,EACT,MAAM,EACN,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,UAAU,EAMX,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EAGvB,MAAM,UAAU,CAAC;AAGlB,MAAM,MAAM,uCAAuC,GAAG;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,SAAS,GAAG,GAAG,CAAC;IACjC,aAAa,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;AAGD,MAAM,MAAM,mCAAmC,GAC7C,uCAAuC,CAAC;AAG1C,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,EAClC,KAAK,EAAE,uCAAuC,GAC5C,mCAAmC,GACpC,kBAAkB,CA4JpB"}
|
@@ -53,73 +53,68 @@ function marginfiOpenPosition(context, input) {
|
|
53
53
|
value: input.ataProgram ?? null,
|
54
54
|
},
|
55
55
|
rent: { index: 5, isWritable: false, value: input.rent ?? null },
|
56
|
-
solautoFeesWallet: {
|
57
|
-
index: 6,
|
58
|
-
isWritable: false,
|
59
|
-
value: input.solautoFeesWallet ?? null,
|
60
|
-
},
|
61
56
|
signerReferralState: {
|
62
|
-
index:
|
57
|
+
index: 6,
|
63
58
|
isWritable: false,
|
64
59
|
value: input.signerReferralState ?? null,
|
65
60
|
},
|
66
61
|
referredByState: {
|
67
|
-
index:
|
62
|
+
index: 7,
|
68
63
|
isWritable: false,
|
69
64
|
value: input.referredByState ?? null,
|
70
65
|
},
|
71
66
|
referredBySupplyTa: {
|
72
|
-
index:
|
67
|
+
index: 8,
|
73
68
|
isWritable: true,
|
74
69
|
value: input.referredBySupplyTa ?? null,
|
75
70
|
},
|
76
71
|
solautoPosition: {
|
77
|
-
index:
|
72
|
+
index: 9,
|
78
73
|
isWritable: true,
|
79
74
|
value: input.solautoPosition ?? null,
|
80
75
|
},
|
81
76
|
marginfiGroup: {
|
82
|
-
index:
|
77
|
+
index: 10,
|
83
78
|
isWritable: false,
|
84
79
|
value: input.marginfiGroup ?? null,
|
85
80
|
},
|
86
81
|
marginfiAccount: {
|
87
|
-
index:
|
82
|
+
index: 11,
|
88
83
|
isWritable: true,
|
89
84
|
value: input.marginfiAccount ?? null,
|
90
85
|
},
|
91
86
|
supplyMint: {
|
92
|
-
index:
|
87
|
+
index: 12,
|
93
88
|
isWritable: false,
|
94
89
|
value: input.supplyMint ?? null,
|
95
90
|
},
|
96
91
|
supplyBank: {
|
97
|
-
index:
|
92
|
+
index: 13,
|
98
93
|
isWritable: false,
|
99
94
|
value: input.supplyBank ?? null,
|
100
95
|
},
|
101
96
|
positionSupplyTa: {
|
102
|
-
index:
|
97
|
+
index: 14,
|
103
98
|
isWritable: true,
|
104
99
|
value: input.positionSupplyTa ?? null,
|
105
100
|
},
|
106
101
|
debtMint: {
|
107
|
-
index:
|
102
|
+
index: 15,
|
108
103
|
isWritable: false,
|
109
104
|
value: input.debtMint ?? null,
|
110
105
|
},
|
111
106
|
debtBank: {
|
112
|
-
index:
|
107
|
+
index: 16,
|
113
108
|
isWritable: false,
|
114
109
|
value: input.debtBank ?? null,
|
115
110
|
},
|
116
111
|
positionDebtTa: {
|
117
|
-
index:
|
112
|
+
index: 17,
|
118
113
|
isWritable: true,
|
119
114
|
value: input.positionDebtTa ?? null,
|
120
115
|
},
|
121
116
|
signerDebtTa: {
|
122
|
-
index:
|
117
|
+
index: 18,
|
123
118
|
isWritable: true,
|
124
119
|
value: input.signerDebtTa ?? null,
|
125
120
|
},
|
@@ -4,7 +4,7 @@ import { ReferralState } from "../generated";
|
|
4
4
|
import { SolautoClient } from "../clients/solautoClient";
|
5
5
|
export declare function rebalanceChoresBefore(client: SolautoClient, tx: TransactionBuilder, accountsGettingCreated: string[]): Promise<TransactionBuilder>;
|
6
6
|
export declare function getTransactionChores(client: SolautoClient, tx: TransactionBuilder): Promise<[TransactionBuilder, TransactionBuilder]>;
|
7
|
-
export declare function requiresRefreshBeforeRebalance(client: SolautoClient): boolean
|
7
|
+
export declare function requiresRefreshBeforeRebalance(client: SolautoClient): Promise<boolean>;
|
8
8
|
export declare function buildSolautoRebalanceTransaction(client: SolautoClient, targetLiqUtilizationRateBps?: number, attemptNum?: number): Promise<{
|
9
9
|
tx: TransactionBuilder;
|
10
10
|
lookupTableAddresses: string[];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings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MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAmCrD;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG;;;;EAwC9D"}
|
@@ -20,6 +20,7 @@ const generalUtils_2 = require("../utils/solauto/generalUtils");
|
|
20
20
|
const accountUtils_1 = require("../utils/accountUtils");
|
21
21
|
const marginfi_sdk_1 = require("../marginfi-sdk");
|
22
22
|
const jupiter_sdk_1 = require("../jupiter-sdk");
|
23
|
+
const constants_1 = require("../constants");
|
23
24
|
function getWSolUsage(client, solautoActions, initiatingDcaIn, cancellingDcaIn) {
|
24
25
|
const supplyIsWsol = client.supplyMint.equals(spl_token_1.NATIVE_MINT);
|
25
26
|
const debtIsWsol = client.debtMint.equals(spl_token_1.NATIVE_MINT);
|
@@ -324,7 +325,7 @@ async function getTransactionChores(client, tx) {
|
|
324
325
|
choresAfter = choresAfter.add(transactionChoresAfter(client, solautoActions, client.livePositionUpdates.cancellingDca));
|
325
326
|
return [choresBefore, choresAfter];
|
326
327
|
}
|
327
|
-
function requiresRefreshBeforeRebalance(client) {
|
328
|
+
async function requiresRefreshBeforeRebalance(client) {
|
328
329
|
if (client.solautoPositionState.liqUtilizationRateBps >
|
329
330
|
(0, numberUtils_1.getMaxLiqUtilizationRateBps)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps, 0.01)) {
|
330
331
|
return true;
|
@@ -334,14 +335,13 @@ function requiresRefreshBeforeRebalance(client) {
|
|
334
335
|
client.livePositionUpdates.debtAdjustment > BigInt(0)) {
|
335
336
|
return false;
|
336
337
|
}
|
337
|
-
const
|
338
|
-
const
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
Math.abs(Number(debtDiff)) / Number(oldDebt) >= 0.005) {
|
338
|
+
const oldStateWithLatestPrices = await (0, generalUtils_2.positionStateWithLatestPrices)(client.solautoPositionData.state, constants_1.PRICES[client.supplyMint.toString()].price, constants_1.PRICES[client.debtMint.toString()].price);
|
339
|
+
const utilizationRateDiff = Math.abs((client.solautoPositionState?.liqUtilizationRateBps ?? 0) -
|
340
|
+
oldStateWithLatestPrices.liqUtilizationRateBps);
|
341
|
+
if (client.livePositionUpdates.supplyAdjustment === BigInt(0) &&
|
342
|
+
client.livePositionUpdates.debtAdjustment === BigInt(0) &&
|
343
|
+
utilizationRateDiff / oldStateWithLatestPrices.liqUtilizationRateBps >=
|
344
|
+
0.005) {
|
345
345
|
return true;
|
346
346
|
}
|
347
347
|
}
|
@@ -363,7 +363,7 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
363
363
|
const { jupQuote, lookupTableAddresses, setupInstructions, tokenLedgerIx, swapIx, } = await (0, jupiterUtils_1.getJupSwapTransaction)(client.signer, swapDetails, attemptNum);
|
364
364
|
const flashLoan = (0, rebalanceUtils_1.getFlashLoanDetails)(client, values, jupQuote);
|
365
365
|
let tx = (0, umi_1.transactionBuilder)();
|
366
|
-
if (requiresRefreshBeforeRebalance(client)) {
|
366
|
+
if (await requiresRefreshBeforeRebalance(client)) {
|
367
367
|
tx = tx.add(client.refresh());
|
368
368
|
}
|
369
369
|
if (flashLoan) {
|
package/package.json
CHANGED
@@ -263,7 +263,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
263
263
|
return marginfiOpenPosition(this.umi, {
|
264
264
|
signer: this.signer,
|
265
265
|
marginfiProgram: publicKey(MARGINFI_PROGRAM_ID),
|
266
|
-
solautoFeesWallet: publicKey(this.solautoFeesWallet),
|
267
266
|
signerReferralState: publicKey(this.referralStateManager.referralState),
|
268
267
|
referredByState: this.referredByState
|
269
268
|
? publicKey(this.referredByState)
|
@@ -47,7 +47,6 @@ export type MarginfiOpenPositionInstructionAccounts = {
|
|
47
47
|
tokenProgram?: PublicKey | Pda;
|
48
48
|
ataProgram?: PublicKey | Pda;
|
49
49
|
rent?: PublicKey | Pda;
|
50
|
-
solautoFeesWallet: PublicKey | Pda;
|
51
50
|
signerReferralState: PublicKey | Pda;
|
52
51
|
referredByState?: PublicKey | Pda;
|
53
52
|
referredBySupplyTa?: PublicKey | Pda;
|
@@ -146,73 +145,68 @@ export function marginfiOpenPosition(
|
|
146
145
|
value: input.ataProgram ?? null,
|
147
146
|
},
|
148
147
|
rent: { index: 5, isWritable: false as boolean, value: input.rent ?? null },
|
149
|
-
solautoFeesWallet: {
|
150
|
-
index: 6,
|
151
|
-
isWritable: false as boolean,
|
152
|
-
value: input.solautoFeesWallet ?? null,
|
153
|
-
},
|
154
148
|
signerReferralState: {
|
155
|
-
index:
|
149
|
+
index: 6,
|
156
150
|
isWritable: false as boolean,
|
157
151
|
value: input.signerReferralState ?? null,
|
158
152
|
},
|
159
153
|
referredByState: {
|
160
|
-
index:
|
154
|
+
index: 7,
|
161
155
|
isWritable: false as boolean,
|
162
156
|
value: input.referredByState ?? null,
|
163
157
|
},
|
164
158
|
referredBySupplyTa: {
|
165
|
-
index:
|
159
|
+
index: 8,
|
166
160
|
isWritable: true as boolean,
|
167
161
|
value: input.referredBySupplyTa ?? null,
|
168
162
|
},
|
169
163
|
solautoPosition: {
|
170
|
-
index:
|
164
|
+
index: 9,
|
171
165
|
isWritable: true as boolean,
|
172
166
|
value: input.solautoPosition ?? null,
|
173
167
|
},
|
174
168
|
marginfiGroup: {
|
175
|
-
index:
|
169
|
+
index: 10,
|
176
170
|
isWritable: false as boolean,
|
177
171
|
value: input.marginfiGroup ?? null,
|
178
172
|
},
|
179
173
|
marginfiAccount: {
|
180
|
-
index:
|
174
|
+
index: 11,
|
181
175
|
isWritable: true as boolean,
|
182
176
|
value: input.marginfiAccount ?? null,
|
183
177
|
},
|
184
178
|
supplyMint: {
|
185
|
-
index:
|
179
|
+
index: 12,
|
186
180
|
isWritable: false as boolean,
|
187
181
|
value: input.supplyMint ?? null,
|
188
182
|
},
|
189
183
|
supplyBank: {
|
190
|
-
index:
|
184
|
+
index: 13,
|
191
185
|
isWritable: false as boolean,
|
192
186
|
value: input.supplyBank ?? null,
|
193
187
|
},
|
194
188
|
positionSupplyTa: {
|
195
|
-
index:
|
189
|
+
index: 14,
|
196
190
|
isWritable: true as boolean,
|
197
191
|
value: input.positionSupplyTa ?? null,
|
198
192
|
},
|
199
193
|
debtMint: {
|
200
|
-
index:
|
194
|
+
index: 15,
|
201
195
|
isWritable: false as boolean,
|
202
196
|
value: input.debtMint ?? null,
|
203
197
|
},
|
204
198
|
debtBank: {
|
205
|
-
index:
|
199
|
+
index: 16,
|
206
200
|
isWritable: false as boolean,
|
207
201
|
value: input.debtBank ?? null,
|
208
202
|
},
|
209
203
|
positionDebtTa: {
|
210
|
-
index:
|
204
|
+
index: 17,
|
211
205
|
isWritable: true as boolean,
|
212
206
|
value: input.positionDebtTa ?? null,
|
213
207
|
},
|
214
208
|
signerDebtTa: {
|
215
|
-
index:
|
209
|
+
index: 18,
|
216
210
|
isWritable: true as boolean,
|
217
211
|
value: input.signerDebtTa ?? null,
|
218
212
|
},
|
@@ -51,7 +51,10 @@ import {
|
|
51
51
|
getMaxLiqUtilizationRateBps,
|
52
52
|
uint8ArrayToBigInt,
|
53
53
|
} from "../utils/numberUtils";
|
54
|
-
import {
|
54
|
+
import {
|
55
|
+
eligibleForRebalance,
|
56
|
+
positionStateWithLatestPrices,
|
57
|
+
} from "../utils/solauto/generalUtils";
|
55
58
|
import { getTokenAccount, getTokenAccountData } from "../utils/accountUtils";
|
56
59
|
import {
|
57
60
|
createMarginfiProgram,
|
@@ -68,6 +71,7 @@ import {
|
|
68
71
|
getJupiterErrorFromName,
|
69
72
|
JUPITER_PROGRAM_ID,
|
70
73
|
} from "../jupiter-sdk";
|
74
|
+
import { PRICES } from "../constants";
|
71
75
|
|
72
76
|
interface wSolTokenUsage {
|
73
77
|
wSolTokenAccount: PublicKey;
|
@@ -577,7 +581,7 @@ export async function getTransactionChores(
|
|
577
581
|
return [choresBefore, choresAfter];
|
578
582
|
}
|
579
583
|
|
580
|
-
export function requiresRefreshBeforeRebalance(client: SolautoClient) {
|
584
|
+
export async function requiresRefreshBeforeRebalance(client: SolautoClient) {
|
581
585
|
if (
|
582
586
|
client.solautoPositionState!.liqUtilizationRateBps >
|
583
587
|
getMaxLiqUtilizationRateBps(
|
@@ -595,20 +599,21 @@ export function requiresRefreshBeforeRebalance(client: SolautoClient) {
|
|
595
599
|
return false;
|
596
600
|
}
|
597
601
|
|
598
|
-
const
|
599
|
-
client.solautoPositionData.state
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
oldDebt;
|
602
|
+
const oldStateWithLatestPrices = await positionStateWithLatestPrices(
|
603
|
+
client.solautoPositionData.state,
|
604
|
+
PRICES[client.supplyMint.toString()].price,
|
605
|
+
PRICES[client.debtMint.toString()].price
|
606
|
+
);
|
607
|
+
const utilizationRateDiff = Math.abs(
|
608
|
+
(client.solautoPositionState?.liqUtilizationRateBps ?? 0) -
|
609
|
+
oldStateWithLatestPrices.liqUtilizationRateBps
|
610
|
+
);
|
608
611
|
|
609
612
|
if (
|
610
|
-
|
611
|
-
|
613
|
+
client.livePositionUpdates.supplyAdjustment === BigInt(0) &&
|
614
|
+
client.livePositionUpdates.debtAdjustment === BigInt(0) &&
|
615
|
+
utilizationRateDiff / oldStateWithLatestPrices.liqUtilizationRateBps >=
|
616
|
+
0.005
|
612
617
|
) {
|
613
618
|
return true;
|
614
619
|
}
|
@@ -674,7 +679,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
674
679
|
|
675
680
|
let tx = transactionBuilder();
|
676
681
|
|
677
|
-
if (requiresRefreshBeforeRebalance(client)) {
|
682
|
+
if (await requiresRefreshBeforeRebalance(client)) {
|
678
683
|
tx = tx.add(client.refresh());
|
679
684
|
}
|
680
685
|
|