@haven-fi/solauto-sdk 1.0.614 → 1.0.615

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.
@@ -20,5 +20,6 @@ export declare class MarginfiFlProvider extends FlProviderBase {
20
20
  flFeeBps(source: TokenType, signerFlashLoan?: boolean): number;
21
21
  flashBorrow(flashLoan: FlashLoanDetails, destTokenAccount: PublicKey): TransactionBuilder;
22
22
  flashRepay(flashLoan: FlashLoanDetails): TransactionBuilder;
23
+ closeBalance(marginfiAccount: PublicKey, bank: PublicKey, marginfiGroup: PublicKey): TransactionBuilder;
23
24
  }
24
25
  //# sourceMappingURL=marginfiFlProvider.d.ts.map
@@ -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;IA0CxB,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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E,gBAAgB,GAAG,kBAAkB;IAyG3D,YAAY,CACV,eAAe,EAAE,SAAS,EAC1B,IAAI,EAAE,SAAS,EACf,aAAa,EAAE,SAAS;CAW3B"}
@@ -212,9 +212,9 @@ class MarginfiFlProvider extends flProviderBase_1.FlProviderBase {
212
212
  },
213
213
  ]);
214
214
  }
215
- // const banksRequiringBalanceClose = remainingAccounts
216
- // .filter((_, index) => index % 2 === 0)
217
- // .map((x) => toWeb3JsPublicKey(x.pubkey));
215
+ const closeBalances = remainingAccounts
216
+ .filter((x, index) => index % 2 === 0 && x.pubkey.toString() !== bank.publicKey.toString())
217
+ .map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.pubkey));
218
218
  return (0, umi_1.transactionBuilder)()
219
219
  .add((0, marginfi_sdk_1.lendingAccountRepay)(this.umi, {
220
220
  amount: flashLoan.baseUnitAmount,
@@ -226,15 +226,21 @@ class MarginfiFlProvider extends flProviderBase_1.FlProviderBase {
226
226
  signer: this.signer,
227
227
  signerTokenAccount: (0, umi_1.publicKey)((0, utils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), flashLoan.mint)),
228
228
  }))
229
- // .add(
230
- // banksRequiringBalanceClose.map((bank) =>
231
- // this.closeBalance(iMfiAccount.accountPk, bank, marginfiGroup)
232
- // )
233
- // )
229
+ .add(closeBalances.length
230
+ ? closeBalances.map((bank) => this.closeBalance(iMfiAccount.accountPk, bank, marginfiGroup))
231
+ : [])
234
232
  .add((0, marginfi_sdk_1.lendingAccountEndFlashloan)(this.umi, {
235
233
  marginfiAccount: (0, umi_1.publicKey)(iMfiAccount.accountPk),
236
234
  signer: this.signer,
237
235
  }).addRemainingAccounts(remainingAccounts));
238
236
  }
237
+ closeBalance(marginfiAccount, bank, marginfiGroup) {
238
+ return (0, umi_1.transactionBuilder)().add((0, marginfi_sdk_1.lendingAccountCloseBalance)(this.umi, {
239
+ signer: this.signer,
240
+ marginfiAccount: (0, umi_1.publicKey)(marginfiAccount),
241
+ bank: (0, umi_1.publicKey)(bank),
242
+ marginfiGroup: (0, umi_1.publicKey)(marginfiGroup),
243
+ }));
244
+ }
239
245
  }
240
246
  exports.MarginfiFlProvider = MarginfiFlProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.614",
3
+ "version": "1.0.615",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Typescript SDK for the Solauto program on the Solana blockchain",
@@ -340,9 +340,12 @@ export class MarginfiFlProvider extends FlProviderBase {
340
340
  );
341
341
  }
342
342
 
343
- // const banksRequiringBalanceClose = remainingAccounts
344
- // .filter((_, index) => index % 2 === 0)
345
- // .map((x) => toWeb3JsPublicKey(x.pubkey));
343
+ const closeBalances = remainingAccounts
344
+ .filter(
345
+ (x, index) =>
346
+ index % 2 === 0 && x.pubkey.toString() !== bank.publicKey.toString()
347
+ )
348
+ .map((x) => toWeb3JsPublicKey(x.pubkey));
346
349
 
347
350
  return transactionBuilder()
348
351
  .add(
@@ -362,11 +365,13 @@ export class MarginfiFlProvider extends FlProviderBase {
362
365
  ),
363
366
  })
364
367
  )
365
- // .add(
366
- // banksRequiringBalanceClose.map((bank) =>
367
- // this.closeBalance(iMfiAccount.accountPk, bank, marginfiGroup)
368
- // )
369
- // )
368
+ .add(
369
+ closeBalances.length
370
+ ? closeBalances.map((bank) =>
371
+ this.closeBalance(iMfiAccount.accountPk, bank, marginfiGroup)
372
+ )
373
+ : []
374
+ )
370
375
  .add(
371
376
  lendingAccountEndFlashloan(this.umi, {
372
377
  marginfiAccount: publicKey(iMfiAccount.accountPk),
@@ -375,18 +380,18 @@ export class MarginfiFlProvider extends FlProviderBase {
375
380
  );
376
381
  }
377
382
 
378
- // closeBalance(
379
- // marginfiAccount: PublicKey,
380
- // bank: PublicKey,
381
- // marginfiGroup: PublicKey
382
- // ) {
383
- // return transactionBuilder().add(
384
- // lendingAccountCloseBalance(this.umi, {
385
- // signer: this.signer,
386
- // marginfiAccount: publicKey(marginfiAccount),
387
- // bank: publicKey(bank),
388
- // marginfiGroup: publicKey(marginfiGroup),
389
- // })
390
- // );
391
- // }
383
+ closeBalance(
384
+ marginfiAccount: PublicKey,
385
+ bank: PublicKey,
386
+ marginfiGroup: PublicKey
387
+ ) {
388
+ return transactionBuilder().add(
389
+ lendingAccountCloseBalance(this.umi, {
390
+ signer: this.signer,
391
+ marginfiAccount: publicKey(marginfiAccount),
392
+ bank: publicKey(bank),
393
+ marginfiGroup: publicKey(marginfiGroup),
394
+ })
395
+ );
396
+ }
392
397
  }