@haven-fi/solauto-sdk 1.0.629 → 1.0.631
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 +32 -2
- package/dist/constants/marginfiAccounts.d.ts.map +1 -1
- package/dist/constants/solautoConstants.d.ts +2 -1
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiRebalance.d.ts +5 -3
- package/dist/generated/instructions/marginfiRebalance.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiRebalance.js +2 -1
- package/dist/generated/instructions/marginfiRefreshData.d.ts +7 -2
- package/dist/generated/instructions/marginfiRefreshData.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiRefreshData.js +8 -4
- package/dist/generated/types/index.d.ts +1 -0
- package/dist/generated/types/index.d.ts.map +1 -1
- package/dist/generated/types/index.js +1 -0
- package/dist/generated/types/priceType.d.ts +15 -0
- package/dist/generated/types/priceType.d.ts.map +1 -0
- package/dist/generated/types/priceType.js +22 -0
- package/dist/services/rebalance/rebalanceSwapManager.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceSwapManager.js +8 -8
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts +2 -0
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceTxBuilder.js +21 -10
- package/dist/services/rebalance/rebalanceValues.d.ts +2 -2
- package/dist/services/rebalance/rebalanceValues.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceValues.js +17 -17
- package/dist/services/solauto/solautoClient.d.ts +2 -2
- package/dist/services/solauto/solautoClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoClient.js +27 -28
- package/dist/services/solauto/solautoMarginfiClient.d.ts +2 -2
- package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoMarginfiClient.js +12 -10
- package/dist/services/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/services/transactions/transactionUtils.js +10 -9
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts +3 -3
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.js +9 -9
- package/dist/solautoPosition/solautoPositionEx.d.ts +44 -33
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/solautoPositionEx.js +112 -90
- package/dist/types/solauto.d.ts +2 -1
- package/dist/types/solauto.d.ts.map +1 -1
- package/dist/utils/instructionUtils.js +2 -2
- package/dist/utils/marginfiUtils.d.ts +2 -2
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +5 -5
- package/dist/utils/priceUtils.d.ts +11 -5
- package/dist/utils/priceUtils.d.ts.map +1 -1
- package/dist/utils/priceUtils.js +45 -21
- package/local/logPositions.ts +12 -12
- package/local/shared.ts +1 -1
- package/local/txSandbox.ts +29 -27
- package/local/updateMarginfiLUT.ts +13 -6
- package/package.json +1 -1
- package/src/constants/marginfiAccounts.ts +0 -1
- package/src/constants/solautoConstants.ts +1 -1
- package/src/generated/instructions/marginfiRebalance.ts +9 -3
- package/src/generated/instructions/marginfiRefreshData.ts +27 -7
- package/src/generated/types/index.ts +1 -0
- package/src/generated/types/priceType.ts +22 -0
- package/src/services/rebalance/rebalanceSwapManager.ts +8 -12
- package/src/services/rebalance/rebalanceTxBuilder.ts +41 -11
- package/src/services/rebalance/rebalanceValues.ts +22 -16
- package/src/services/solauto/solautoClient.ts +30 -30
- package/src/services/solauto/solautoMarginfiClient.ts +13 -10
- package/src/services/transactions/transactionUtils.ts +11 -9
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +11 -10
- package/src/solautoPosition/solautoPositionEx.ts +145 -117
- package/src/types/solauto.ts +2 -0
- package/src/utils/instructionUtils.ts +2 -2
- package/src/utils/marginfiUtils.ts +12 -8
- package/src/utils/priceUtils.ts +66 -22
- package/tests/transactions/shared.ts +2 -5
- package/tests/unit/rebalanceCalculations.ts +9 -12
@@ -12,6 +12,7 @@ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
|
12
12
|
import {
|
13
13
|
DCASettingsInpArgs,
|
14
14
|
LendingPlatform,
|
15
|
+
PriceType,
|
15
16
|
RebalanceStep,
|
16
17
|
SolautoActionArgs,
|
17
18
|
SolautoSettingsParametersInpArgs,
|
@@ -109,29 +110,29 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
109
110
|
|
110
111
|
this.positionSupplyTa = getTokenAccount(
|
111
112
|
this.pos.publicKey,
|
112
|
-
this.pos.supplyMint
|
113
|
+
this.pos.supplyMint
|
113
114
|
);
|
114
115
|
this.signerSupplyTa = getTokenAccount(
|
115
116
|
toWeb3JsPublicKey(this.signer.publicKey),
|
116
|
-
this.pos.supplyMint
|
117
|
+
this.pos.supplyMint
|
117
118
|
);
|
118
119
|
|
119
120
|
this.positionDebtTa = getTokenAccount(
|
120
121
|
this.pos.publicKey,
|
121
|
-
this.pos.debtMint
|
122
|
+
this.pos.debtMint
|
122
123
|
);
|
123
124
|
this.signerDebtTa = getTokenAccount(
|
124
125
|
toWeb3JsPublicKey(this.signer.publicKey),
|
125
|
-
this.pos.debtMint
|
126
|
+
this.pos.debtMint
|
126
127
|
);
|
127
128
|
|
128
129
|
this.solautoFeesSupplyTa = getTokenAccount(
|
129
130
|
SOLAUTO_FEES_WALLET,
|
130
|
-
this.pos.supplyMint
|
131
|
+
this.pos.supplyMint
|
131
132
|
);
|
132
133
|
this.solautoFeesDebtTa = getTokenAccount(
|
133
134
|
SOLAUTO_FEES_WALLET,
|
134
|
-
this.pos.debtMint
|
135
|
+
this.pos.debtMint
|
135
136
|
);
|
136
137
|
|
137
138
|
this.authorityLutAddress =
|
@@ -146,30 +147,30 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
146
147
|
this.umi,
|
147
148
|
this.signer,
|
148
149
|
this.authority,
|
149
|
-
this.pos.supplyMint
|
150
|
-
this.pos.debtMint
|
150
|
+
this.pos.supplyMint,
|
151
|
+
this.pos.debtMint,
|
151
152
|
this.lpEnv
|
152
153
|
);
|
153
154
|
await this.flProvider.initialize();
|
154
155
|
this.otherSigners.push(...this.flProvider.otherSigners());
|
155
156
|
|
156
|
-
this.log("Position state: ", this.pos.state
|
157
|
-
this.log("Position settings: ", this.pos.settings
|
158
|
-
this.log("Position DCA: ", this.pos.dca
|
159
|
-
this.log("Supply mint:", this.pos.supplyMint
|
160
|
-
this.log("Debt mint:", this.pos.debtMint
|
157
|
+
this.log("Position state: ", this.pos.state);
|
158
|
+
this.log("Position settings: ", this.pos.settings);
|
159
|
+
this.log("Position DCA: ", this.pos.dca);
|
160
|
+
this.log("Supply mint:", this.pos.supplyMint.toString());
|
161
|
+
this.log("Debt mint:", this.pos.debtMint.toString());
|
161
162
|
}
|
162
163
|
|
163
164
|
referredBySupplyTa(): PublicKey | undefined {
|
164
165
|
if (this.referredByState !== undefined) {
|
165
|
-
return getTokenAccount(this.referredByState, this.pos.supplyMint
|
166
|
+
return getTokenAccount(this.referredByState, this.pos.supplyMint);
|
166
167
|
}
|
167
168
|
return undefined;
|
168
169
|
}
|
169
170
|
|
170
171
|
referredByDebtTa(): PublicKey | undefined {
|
171
172
|
if (this.referredByState !== undefined) {
|
172
|
-
return getTokenAccount(this.referredByState, this.pos.debtMint
|
173
|
+
return getTokenAccount(this.referredByState, this.pos.debtMint);
|
173
174
|
}
|
174
175
|
return undefined;
|
175
176
|
}
|
@@ -177,14 +178,14 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
177
178
|
async resetLiveTxUpdates(success?: boolean) {
|
178
179
|
this.log("Resetting context updates...");
|
179
180
|
if (success) {
|
180
|
-
if (!this.pos.exists
|
181
|
+
if (!this.pos.exists) {
|
181
182
|
await this.pos.refetchPositionData();
|
182
183
|
} else {
|
183
184
|
if (this.contextUpdates.settings) {
|
184
|
-
this.pos.
|
185
|
+
this.pos.updateSettings(this.contextUpdates.settings);
|
185
186
|
}
|
186
187
|
if (this.contextUpdates.dca) {
|
187
|
-
this.pos.
|
188
|
+
this.pos.updateDca(this.contextUpdates.dca);
|
188
189
|
}
|
189
190
|
// All other live position updates can be derived by getting a fresh position state, so we don't need to do anything else form contextUpdates
|
190
191
|
}
|
@@ -307,7 +308,7 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
307
308
|
await getWalletSplBalances(
|
308
309
|
this.connection,
|
309
310
|
toWeb3JsPublicKey(this.signer.publicKey),
|
310
|
-
[this.pos.supplyMint
|
311
|
+
[this.pos.supplyMint, this.pos.debtMint]
|
311
312
|
);
|
312
313
|
}
|
313
314
|
|
@@ -352,11 +353,11 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
352
353
|
let signerDcaTa: UmiPublicKey | undefined = undefined;
|
353
354
|
if (isOption(args.dca) && isSome(args.dca)) {
|
354
355
|
if (args.dca.value.tokenType === TokenType.Supply) {
|
355
|
-
dcaMint = publicKey(this.pos.supplyMint
|
356
|
+
dcaMint = publicKey(this.pos.supplyMint);
|
356
357
|
positionDcaTa = publicKey(this.positionSupplyTa);
|
357
358
|
signerDcaTa = publicKey(this.signerSupplyTa);
|
358
359
|
} else {
|
359
|
-
dcaMint = publicKey(this.pos.debtMint
|
360
|
+
dcaMint = publicKey(this.pos.debtMint);
|
360
361
|
positionDcaTa = publicKey(this.positionDebtTa);
|
361
362
|
signerDcaTa = publicKey(this.signerDebtTa);
|
362
363
|
}
|
@@ -407,21 +408,21 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
407
408
|
let positionDcaTa: UmiPublicKey | undefined = undefined;
|
408
409
|
let signerDcaTa: UmiPublicKey | undefined = undefined;
|
409
410
|
|
410
|
-
const currDca = this.pos.dca
|
411
|
+
const currDca = this.pos.dca!;
|
411
412
|
if (currDca.dcaInBaseUnit > 0) {
|
412
413
|
if (currDca.tokenType === TokenType.Supply) {
|
413
|
-
dcaMint = publicKey(this.pos.supplyMint
|
414
|
+
dcaMint = publicKey(this.pos.supplyMint);
|
414
415
|
positionDcaTa = publicKey(this.positionSupplyTa);
|
415
416
|
signerDcaTa = publicKey(this.signerSupplyTa);
|
416
417
|
} else {
|
417
|
-
dcaMint = publicKey(this.pos.debtMint
|
418
|
+
dcaMint = publicKey(this.pos.debtMint);
|
418
419
|
positionDcaTa = publicKey(this.positionDebtTa);
|
419
420
|
signerDcaTa = publicKey(this.signerDebtTa);
|
420
421
|
}
|
421
422
|
|
422
423
|
this.contextUpdates.new({
|
423
424
|
type: "cancellingDca",
|
424
|
-
value: this.pos.dca
|
425
|
+
value: this.pos.dca!.tokenType,
|
425
426
|
});
|
426
427
|
}
|
427
428
|
|
@@ -434,7 +435,7 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
434
435
|
});
|
435
436
|
}
|
436
437
|
|
437
|
-
abstract refreshIx(): TransactionBuilder;
|
438
|
+
abstract refreshIx(priceType: PriceType): TransactionBuilder;
|
438
439
|
|
439
440
|
protocolInteractionIx(args: SolautoActionArgs): TransactionBuilder {
|
440
441
|
let tx = transactionBuilder();
|
@@ -470,7 +471,7 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
470
471
|
toWeb3JsPublicKey(this.signer.publicKey),
|
471
472
|
BigInt(
|
472
473
|
Math.round(
|
473
|
-
Number(this.pos.state
|
474
|
+
Number(this.pos.state.debt.amountUsed.baseUnit) * 1.01
|
474
475
|
)
|
475
476
|
)
|
476
477
|
)
|
@@ -494,7 +495,7 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
494
495
|
this.contextUpdates.new({
|
495
496
|
type: "supply",
|
496
497
|
value:
|
497
|
-
(this.pos.state
|
498
|
+
(this.pos.state.supply.amountUsed.baseUnit ?? BigInt(0)) *
|
498
499
|
BigInt(-1),
|
499
500
|
});
|
500
501
|
}
|
@@ -513,8 +514,7 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
513
514
|
this.contextUpdates.new({
|
514
515
|
type: "debt",
|
515
516
|
value:
|
516
|
-
(this.pos.state
|
517
|
-
BigInt(-1),
|
517
|
+
(this.pos.state.debt.amountUsed.baseUnit ?? BigInt(0)) * BigInt(-1),
|
518
518
|
});
|
519
519
|
}
|
520
520
|
}
|
@@ -13,6 +13,7 @@ import {
|
|
13
13
|
DCASettingsInpArgs,
|
14
14
|
LendingPlatform,
|
15
15
|
PositionType,
|
16
|
+
PriceType,
|
16
17
|
RebalanceDirection,
|
17
18
|
RebalanceStep,
|
18
19
|
SolautoActionArgs,
|
@@ -69,7 +70,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
69
70
|
args.lpUserAccount ??
|
70
71
|
createSignerFromKeypair(this.umi, this.umi.eddsa.generateKeypair());
|
71
72
|
} else {
|
72
|
-
if (this.pos.exists
|
73
|
+
if (this.pos.exists) {
|
73
74
|
this.marginfiAccount = this.pos.lpUserAccount!;
|
74
75
|
} else {
|
75
76
|
const accounts = await getAllMarginfiAccountsByAuthority(
|
@@ -107,11 +108,11 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
107
108
|
|
108
109
|
this.marginfiSupplyAccounts =
|
109
110
|
this.mfiAccounts.bankAccounts[this.marginfiGroup.toString()][
|
110
|
-
this.pos.supplyMint
|
111
|
+
this.pos.supplyMint.toString()
|
111
112
|
]!;
|
112
113
|
this.marginfiDebtAccounts =
|
113
114
|
this.mfiAccounts.bankAccounts[this.marginfiGroup.toString()][
|
114
|
-
this.pos.debtMint
|
115
|
+
this.pos.debtMint.toString()
|
115
116
|
]!;
|
116
117
|
|
117
118
|
[this.supplyPriceOracle, this.debtPriceOracle] =
|
@@ -177,10 +178,10 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
177
178
|
"publicKey" in this.marginfiAccount
|
178
179
|
? (this.marginfiAccount as Signer)
|
179
180
|
: publicKey(this.marginfiAccount),
|
180
|
-
supplyMint: publicKey(this.pos.supplyMint
|
181
|
+
supplyMint: publicKey(this.pos.supplyMint),
|
181
182
|
supplyBank: publicKey(this.marginfiSupplyAccounts.bank),
|
182
183
|
positionSupplyTa: publicKey(this.positionSupplyTa),
|
183
|
-
debtMint: publicKey(this.pos.debtMint
|
184
|
+
debtMint: publicKey(this.pos.debtMint),
|
184
185
|
debtBank: publicKey(this.marginfiDebtAccounts.bank),
|
185
186
|
positionDebtTa: publicKey(this.positionDebtTa),
|
186
187
|
signerDebtTa: signerDebtTa,
|
@@ -205,7 +206,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
205
206
|
});
|
206
207
|
}
|
207
208
|
|
208
|
-
refreshIx(): TransactionBuilder {
|
209
|
+
refreshIx(priceType: PriceType): TransactionBuilder {
|
209
210
|
return marginfiRefreshData(this.umi, {
|
210
211
|
signer: this.signer,
|
211
212
|
marginfiProgram: publicKey(this.mfiAccounts.program),
|
@@ -216,6 +217,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
216
217
|
debtBank: publicKey(this.marginfiDebtAccounts.bank),
|
217
218
|
debtPriceOracle: publicKey(this.debtPriceOracle),
|
218
219
|
solautoPosition: publicKey(this.pos.publicKey),
|
220
|
+
priceType,
|
219
221
|
});
|
220
222
|
}
|
221
223
|
|
@@ -359,10 +361,10 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
359
361
|
data: RebalanceDetails
|
360
362
|
): TransactionBuilder {
|
361
363
|
const inputIsSupply = new PublicKey(data.swapQuote.inputMint).equals(
|
362
|
-
this.pos.supplyMint
|
364
|
+
this.pos.supplyMint
|
363
365
|
);
|
364
366
|
const outputIsSupply = new PublicKey(data.swapQuote.outputMint).equals(
|
365
|
-
this.pos.supplyMint
|
367
|
+
this.pos.supplyMint
|
366
368
|
);
|
367
369
|
|
368
370
|
const preSwapRebalance = rebalanceStep === RebalanceStep.PreSwap;
|
@@ -419,7 +421,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
419
421
|
supplyPriceOracle: publicKey(this.supplyPriceOracle),
|
420
422
|
positionSupplyTa: publicKey(this.positionSupplyTa),
|
421
423
|
authoritySupplyTa: addAuthorityTas
|
422
|
-
? publicKey(getTokenAccount(this.authority, this.pos.supplyMint
|
424
|
+
? publicKey(getTokenAccount(this.authority, this.pos.supplyMint))
|
423
425
|
: undefined,
|
424
426
|
vaultSupplyTa: needSupplyAccounts
|
425
427
|
? publicKey(this.marginfiSupplyAccounts.liquidityVault)
|
@@ -431,7 +433,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
431
433
|
debtPriceOracle: publicKey(this.debtPriceOracle),
|
432
434
|
positionDebtTa: publicKey(this.positionDebtTa),
|
433
435
|
authorityDebtTa: addAuthorityTas
|
434
|
-
? publicKey(getTokenAccount(this.authority, this.pos.debtMint
|
436
|
+
? publicKey(getTokenAccount(this.authority, this.pos.debtMint))
|
435
437
|
: undefined,
|
436
438
|
vaultDebtTa: needDebtAccounts
|
437
439
|
? publicKey(this.marginfiDebtAccounts.liquidityVault)
|
@@ -448,6 +450,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
448
450
|
data.swapQuote.swapMode === "ExactOut" && isFirstRebalance
|
449
451
|
? SwapType.ExactOut
|
450
452
|
: null,
|
453
|
+
priceType: isFirstRebalance ? data.priceType : null,
|
451
454
|
flashLoanFeeBps:
|
452
455
|
data.flashLoan?.flFeeBps && isFirstRebalance
|
453
456
|
? data.flashLoan.flFeeBps
|
@@ -15,6 +15,7 @@ import {
|
|
15
15
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
16
16
|
import {
|
17
17
|
InvalidRebalanceConditionError,
|
18
|
+
PriceType,
|
18
19
|
SolautoAction,
|
19
20
|
SolautoRebalanceType,
|
20
21
|
SwapType,
|
@@ -71,8 +72,8 @@ function getWSolUsage(
|
|
71
72
|
},
|
72
73
|
cancellingDcaIn?: TokenType
|
73
74
|
): wSolTokenUsage | undefined {
|
74
|
-
const supplyIsWsol = client.pos.supplyMint
|
75
|
-
const debtIsWsol = client.pos.debtMint
|
75
|
+
const supplyIsWsol = client.pos.supplyMint.equals(NATIVE_MINT);
|
76
|
+
const debtIsWsol = client.pos.debtMint.equals(NATIVE_MINT);
|
76
77
|
if (!supplyIsWsol && !debtIsWsol) {
|
77
78
|
return undefined;
|
78
79
|
}
|
@@ -146,7 +147,7 @@ async function transactionChoresBefore(
|
|
146
147
|
}
|
147
148
|
// TODO: PF
|
148
149
|
|
149
|
-
if (!client.pos.exists
|
150
|
+
if (!client.pos.exists) {
|
150
151
|
chores = chores.add(client.openPositionIx());
|
151
152
|
}
|
152
153
|
}
|
@@ -227,8 +228,8 @@ async function transactionChoresBefore(
|
|
227
228
|
client.signer,
|
228
229
|
toWeb3JsPublicKey(client.signer.publicKey),
|
229
230
|
isSolautoAction("Withdraw", solautoAction)
|
230
|
-
? client.pos.supplyMint
|
231
|
-
: client.pos.debtMint
|
231
|
+
? client.pos.supplyMint
|
232
|
+
: client.pos.debtMint
|
232
233
|
)
|
233
234
|
);
|
234
235
|
accountsGettingCreated.push(tokenAccount.toString());
|
@@ -282,7 +283,7 @@ export async function rebalanceChoresBefore(
|
|
282
283
|
createAssociatedTokenAccountUmiIx(
|
283
284
|
client.signer,
|
284
285
|
client.referredByState!,
|
285
|
-
client.pos.supplyMint
|
286
|
+
client.pos.supplyMint
|
286
287
|
)
|
287
288
|
);
|
288
289
|
}
|
@@ -293,7 +294,7 @@ export async function rebalanceChoresBefore(
|
|
293
294
|
createAssociatedTokenAccountUmiIx(
|
294
295
|
client.signer,
|
295
296
|
client.referredByState!,
|
296
|
-
client.pos.debtMint
|
297
|
+
client.pos.debtMint
|
297
298
|
)
|
298
299
|
);
|
299
300
|
}
|
@@ -308,7 +309,7 @@ export async function rebalanceChoresBefore(
|
|
308
309
|
createAssociatedTokenAccountUmiIx(
|
309
310
|
client.signer,
|
310
311
|
toWeb3JsPublicKey(client.signer.publicKey),
|
311
|
-
client.pos.supplyMint
|
312
|
+
client.pos.supplyMint
|
312
313
|
)
|
313
314
|
);
|
314
315
|
accountsGettingCreated.push(signerSupplyTa.publicKey.toString());
|
@@ -324,7 +325,7 @@ export async function rebalanceChoresBefore(
|
|
324
325
|
createAssociatedTokenAccountUmiIx(
|
325
326
|
client.signer,
|
326
327
|
toWeb3JsPublicKey(client.signer.publicKey),
|
327
|
-
client.pos.debtMint
|
328
|
+
client.pos.debtMint
|
328
329
|
)
|
329
330
|
);
|
330
331
|
accountsGettingCreated.push(signerDebtTa.publicKey.toString());
|
@@ -375,6 +376,7 @@ function getRebalanceInstructions(
|
|
375
376
|
rebalanceType: SolautoRebalanceType.Regular,
|
376
377
|
swapType: SwapType.ExactIn,
|
377
378
|
targetLiqUtilizationRateBps: 0,
|
379
|
+
priceType: PriceType.Realtime,
|
378
380
|
flashLoanFeeBps: null,
|
379
381
|
})[0];
|
380
382
|
const [data, _] = serializer.deserialize(x.data);
|
@@ -17,7 +17,7 @@ import {
|
|
17
17
|
} from "../utils";
|
18
18
|
import { getMarginfiAccounts } from "../constants";
|
19
19
|
import { SolautoPositionEx } from "./solautoPositionEx";
|
20
|
-
import { LendingPlatform } from "../generated";
|
20
|
+
import { LendingPlatform, PriceType } from "../generated";
|
21
21
|
|
22
22
|
export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
23
23
|
lendingPlatform = LendingPlatform.Marginfi;
|
@@ -55,8 +55,8 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
55
55
|
if (!this.supplyBank || !this.debtBank) {
|
56
56
|
const group = (await this.lendingPool()).toString();
|
57
57
|
const bankAccounts = getMarginfiAccounts(this.lpEnv).bankAccounts;
|
58
|
-
const supplyBank = bankAccounts[group][this.supplyMint
|
59
|
-
const debtBank = bankAccounts[group][this.debtMint
|
58
|
+
const supplyBank = bankAccounts[group][this.supplyMint.toString()].bank;
|
59
|
+
const debtBank = bankAccounts[group][this.debtMint.toString()].bank;
|
60
60
|
|
61
61
|
[this.supplyBank, this.debtBank] = await safeFetchAllBank(this.umi, [
|
62
62
|
publicKey(supplyBank),
|
@@ -79,7 +79,7 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
79
79
|
async maxLtvAndLiqThresholdBps(): Promise<[number, number]> {
|
80
80
|
const [supplyBank, debtBank] = await this.getBanks();
|
81
81
|
|
82
|
-
const [supplyPrice] = await fetchTokenPrices([this.supplyMint
|
82
|
+
const [supplyPrice] = await fetchTokenPrices([this.supplyMint]);
|
83
83
|
const [maxLtvBps, liqThresholdBps] = calcMarginfiMaxLtvAndLiqThresholdBps(
|
84
84
|
supplyBank,
|
85
85
|
debtBank,
|
@@ -89,14 +89,14 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
89
89
|
return [maxLtvBps, liqThresholdBps];
|
90
90
|
}
|
91
91
|
|
92
|
-
supplyLiquidityAvailable(): number {
|
92
|
+
get supplyLiquidityAvailable(): number {
|
93
93
|
return fromBaseUnit(
|
94
94
|
getBankLiquidityAvailableBaseUnit(this.supplyBank, false),
|
95
|
-
this.state
|
95
|
+
this.state.supply.decimals
|
96
96
|
);
|
97
97
|
}
|
98
98
|
|
99
|
-
async refreshPositionState(): Promise<void> {
|
99
|
+
async refreshPositionState(priceType?: PriceType): Promise<void> {
|
100
100
|
if (!this.canRefreshPositionState()) {
|
101
101
|
return;
|
102
102
|
}
|
@@ -107,13 +107,14 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
107
107
|
{ pk: this.lpUserAccount },
|
108
108
|
await this.lendingPool(),
|
109
109
|
useDesignatedMint
|
110
|
-
? { mint: toWeb3JsPublicKey(this.state
|
110
|
+
? { mint: toWeb3JsPublicKey(this.state.supply.mint) }
|
111
111
|
: undefined,
|
112
112
|
useDesignatedMint
|
113
|
-
? { mint: toWeb3JsPublicKey(this.state
|
113
|
+
? { mint: toWeb3JsPublicKey(this.state.debt.mint) }
|
114
114
|
: undefined,
|
115
115
|
this.lpEnv,
|
116
|
-
this.contextUpdates
|
116
|
+
this.contextUpdates,
|
117
|
+
priceType
|
117
118
|
);
|
118
119
|
|
119
120
|
if (resp) {
|