@haven-fi/solauto-sdk 1.0.622 → 1.0.624
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/services/flashLoans/marginfiFlProvider.d.ts.map +1 -1
- package/dist/services/flashLoans/marginfiFlProvider.js +3 -23
- package/dist/services/solauto/solautoMarginfiClient.js +0 -1
- package/package.json +1 -1
- package/src/services/flashLoans/marginfiFlProvider.ts +3 -33
- package/src/services/solauto/solautoMarginfiClient.ts +6 -6
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiFlProvider.d.ts","sourceRoot":"","sources":["../../../src/services/flashLoans/marginfiFlProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAalC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAexE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAQ/C,qBAAa,kBAAmB,SAAQ,cAAc;IACpD,OAAO,CAAC,wBAAwB,CAAqB;IACrD,OAAO,CAAC,yBAAyB,CAAQ;IACzC,OAAO,CAAC,uBAAuB,CAAQ;IACvC,OAAO,CAAC,iBAAiB,CAAe;IACxC,OAAO,CAAC,eAAe,CAAe;IAEhC,UAAU;YAiBF,iBAAiB;IA2C/B,OAAO,CAAC,sBAAsB;IA2CxB,sBAAsB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAyC3D,gBAAgB,IAAI,SAAS,EAAE;IAY/B,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,WAAW;IAMnB,kBAAkB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM;IAI7C,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,eAAe,CAAC,EAAE,OAAO,GAAG,MAAM;IAc9D,WA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S;CAW3B"}
|
@@ -173,12 +173,12 @@ class MarginfiFlProvider extends flProviderBase_1.FlProviderBase {
|
|
173
173
|
const marginfiGroup = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.liquidityBank(flashLoan.liquiditySource).group);
|
174
174
|
const iMfiAccount = this.iMfiAccount(flashLoan.liquiditySource);
|
175
175
|
const remainingAccounts = [];
|
176
|
-
let
|
176
|
+
let flBankHadPrevBalance = false;
|
177
177
|
if (iMfiAccount?.accountData) {
|
178
178
|
iMfiAccount.accountData.lendingAccount.balances.forEach(async (x) => {
|
179
179
|
if (x.active) {
|
180
180
|
if (x.bankPk.toString() === bank.publicKey.toString()) {
|
181
|
-
|
181
|
+
flBankHadPrevBalance = true;
|
182
182
|
}
|
183
183
|
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
184
184
|
// const bankData = await safeFetchBank(this.umi, publicKey(accounts.data.bank));
|
@@ -199,27 +199,10 @@ class MarginfiFlProvider extends flProviderBase_1.FlProviderBase {
|
|
199
199
|
}
|
200
200
|
});
|
201
201
|
}
|
202
|
-
if (!includedFlashLoanToken) {
|
203
|
-
remainingAccounts.push(...[
|
204
|
-
{
|
205
|
-
pubkey: bank.publicKey,
|
206
|
-
isSigner: false,
|
207
|
-
isWritable: false,
|
208
|
-
},
|
209
|
-
{
|
210
|
-
pubkey: (0, umi_1.publicKey)(associatedBankAccs.priceOracle),
|
211
|
-
isSigner: false,
|
212
|
-
isWritable: false,
|
213
|
-
},
|
214
|
-
]);
|
215
|
-
}
|
216
|
-
const closeBalances = remainingAccounts
|
217
|
-
.filter((x, index) => index % 2 === 0 && x.pubkey.toString() !== bank.publicKey.toString())
|
218
|
-
.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.pubkey));
|
219
202
|
return (0, umi_1.transactionBuilder)()
|
220
203
|
.add((0, marginfi_sdk_1.lendingAccountRepay)(this.umi, {
|
221
204
|
amount: flashLoan.baseUnitAmount,
|
222
|
-
repayAll:
|
205
|
+
repayAll: !flBankHadPrevBalance,
|
223
206
|
bank: bank.publicKey,
|
224
207
|
bankLiquidityVault: (0, umi_1.publicKey)(associatedBankAccs.liquidityVault),
|
225
208
|
marginfiAccount: (0, umi_1.publicKey)(iMfiAccount.accountPk),
|
@@ -227,9 +210,6 @@ class MarginfiFlProvider extends flProviderBase_1.FlProviderBase {
|
|
227
210
|
signer: this.signer,
|
228
211
|
signerTokenAccount: (0, umi_1.publicKey)((0, utils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), flashLoan.mint)),
|
229
212
|
}))
|
230
|
-
.add(closeBalances.length
|
231
|
-
? closeBalances.map((bank) => this.closeBalance(iMfiAccount.accountPk, bank, marginfiGroup))
|
232
|
-
: [])
|
233
213
|
.add((0, marginfi_sdk_1.lendingAccountEndFlashloan)(this.umi, {
|
234
214
|
marginfiAccount: (0, umi_1.publicKey)(iMfiAccount.accountPk),
|
235
215
|
signer: this.signer,
|
@@ -261,7 +261,6 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
261
261
|
(postSwapRebalance &&
|
262
262
|
data.rebalanceType === generated_1.SolautoRebalanceType.FLSwapThenRebalance);
|
263
263
|
const addAuthorityTas = this.selfManaged || data.values.tokenBalanceChange !== undefined;
|
264
|
-
console.log("TARGET LIQ UTILIZATION RATE:", data.targetLiqUtilizationRateBps);
|
265
264
|
return (0, generated_1.marginfiRebalance)(this.umi, {
|
266
265
|
signer: this.signer,
|
267
266
|
marginfiProgram: (0, umi_1.publicKey)(marginfi_sdk_1.MARGINFI_PROGRAM_ID),
|
package/package.json
CHANGED
@@ -291,13 +291,13 @@ export class MarginfiFlProvider extends FlProviderBase {
|
|
291
291
|
const iMfiAccount = this.iMfiAccount(flashLoan.liquiditySource)!;
|
292
292
|
|
293
293
|
const remainingAccounts: AccountMeta[] = [];
|
294
|
-
let
|
294
|
+
let flBankHadPrevBalance = false;
|
295
295
|
|
296
296
|
if (iMfiAccount?.accountData) {
|
297
297
|
iMfiAccount.accountData.lendingAccount.balances.forEach(async (x) => {
|
298
298
|
if (x.active) {
|
299
299
|
if (x.bankPk.toString() === bank.publicKey.toString()) {
|
300
|
-
|
300
|
+
flBankHadPrevBalance = true;
|
301
301
|
}
|
302
302
|
|
303
303
|
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
@@ -324,35 +324,12 @@ export class MarginfiFlProvider extends FlProviderBase {
|
|
324
324
|
}
|
325
325
|
});
|
326
326
|
}
|
327
|
-
if (!includedFlashLoanToken) {
|
328
|
-
remainingAccounts.push(
|
329
|
-
...[
|
330
|
-
{
|
331
|
-
pubkey: bank.publicKey,
|
332
|
-
isSigner: false,
|
333
|
-
isWritable: false,
|
334
|
-
},
|
335
|
-
{
|
336
|
-
pubkey: publicKey(associatedBankAccs.priceOracle),
|
337
|
-
isSigner: false,
|
338
|
-
isWritable: false,
|
339
|
-
},
|
340
|
-
]
|
341
|
-
);
|
342
|
-
}
|
343
|
-
|
344
|
-
const closeBalances = remainingAccounts
|
345
|
-
.filter(
|
346
|
-
(x, index) =>
|
347
|
-
index % 2 === 0 && x.pubkey.toString() !== bank.publicKey.toString()
|
348
|
-
)
|
349
|
-
.map((x) => toWeb3JsPublicKey(x.pubkey));
|
350
327
|
|
351
328
|
return transactionBuilder()
|
352
329
|
.add(
|
353
330
|
lendingAccountRepay(this.umi, {
|
354
331
|
amount: flashLoan.baseUnitAmount,
|
355
|
-
repayAll:
|
332
|
+
repayAll: !flBankHadPrevBalance,
|
356
333
|
bank: bank.publicKey,
|
357
334
|
bankLiquidityVault: publicKey(associatedBankAccs.liquidityVault),
|
358
335
|
marginfiAccount: publicKey(iMfiAccount.accountPk),
|
@@ -366,13 +343,6 @@ export class MarginfiFlProvider extends FlProviderBase {
|
|
366
343
|
),
|
367
344
|
})
|
368
345
|
)
|
369
|
-
.add(
|
370
|
-
closeBalances.length
|
371
|
-
? closeBalances.map((bank) =>
|
372
|
-
this.closeBalance(iMfiAccount.accountPk, bank, marginfiGroup)
|
373
|
-
)
|
374
|
-
: []
|
375
|
-
)
|
376
346
|
.add(
|
377
347
|
lendingAccountEndFlashloan(this.umi, {
|
378
348
|
marginfiAccount: publicKey(iMfiAccount.accountPk),
|
@@ -391,10 +391,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
391
391
|
const addAuthorityTas =
|
392
392
|
this.selfManaged || data.values.tokenBalanceChange !== undefined;
|
393
393
|
|
394
|
-
console.log(
|
395
|
-
"TARGET LIQ UTILIZATION RATE:",
|
396
|
-
data.targetLiqUtilizationRateBps
|
397
|
-
);
|
398
394
|
return marginfiRebalance(this.umi, {
|
399
395
|
signer: this.signer,
|
400
396
|
marginfiProgram: publicKey(MARGINFI_PROGRAM_ID),
|
@@ -429,7 +425,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
429
425
|
supplyPriceOracle: publicKey(this.supplyPriceOracle),
|
430
426
|
positionSupplyTa: publicKey(this.positionSupplyTa),
|
431
427
|
authoritySupplyTa: addAuthorityTas
|
432
|
-
? publicKey(
|
428
|
+
? publicKey(
|
429
|
+
getTokenAccount(this.authority, this.pos.supplyMint())
|
430
|
+
)
|
433
431
|
: undefined,
|
434
432
|
vaultSupplyTa: needSupplyAccounts
|
435
433
|
? publicKey(this.marginfiSupplyAccounts.liquidityVault)
|
@@ -441,7 +439,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
441
439
|
debtPriceOracle: publicKey(this.debtPriceOracle),
|
442
440
|
positionDebtTa: publicKey(this.positionDebtTa),
|
443
441
|
authorityDebtTa: addAuthorityTas
|
444
|
-
? publicKey(
|
442
|
+
? publicKey(
|
443
|
+
getTokenAccount(this.authority, this.pos.debtMint())
|
444
|
+
)
|
445
445
|
: undefined,
|
446
446
|
vaultDebtTa: needDebtAccounts
|
447
447
|
? publicKey(this.marginfiDebtAccounts.liquidityVault)
|