@haven-fi/solauto-sdk 1.0.31 → 1.0.32
Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAGL,SAAS,EAEV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAK1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAUhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAOnE,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,eAAe,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACrC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAED,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,MAAM,EAAE,aAAa,GAAG,SAAS,EACjC,UAAU,EAAE,SAAS,EACrB,QAAQ,EAAE,SAAS,EACnB,mBAAmB,CAAC,EAAE,SAAS,GAC9B,yBAAyB,CAe3B;AAED,qBAAa,qBAAsB,SAAQ,aAAa;IAC/C,eAAe,EAAG,SAAS,CAAC;IAE5B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,e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AAG,kBAAkB;IA8ElE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAiBlE"}
|
@@ -31,9 +31,6 @@ function newSolautoMarginfiPositionArgs(positionId, signer, wallet, supplyMint,
|
|
31
31
|
exports.newSolautoMarginfiPositionArgs = newSolautoMarginfiPositionArgs;
|
32
32
|
class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
33
33
|
async initialize(args) {
|
34
|
-
if (args.marginfiAccount) {
|
35
|
-
this.marginfiAccount = args.marginfiAccount;
|
36
|
-
}
|
37
34
|
await super.initialize(args, generated_1.LendingPlatform.Marginfi);
|
38
35
|
this.marginfiAccountSeedIdx = args.marginfiAccountSeedIdx;
|
39
36
|
this.marginfiAccount =
|
@@ -55,7 +52,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
55
52
|
this.marginfiDebtBankAccounts = (0, marginfiUtils_1.findMarginfiBankAccounts)({
|
56
53
|
mint: this.debtMint.toString(),
|
57
54
|
});
|
58
|
-
const existingMarginfiAccounts = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(this.umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), false);
|
55
|
+
const existingMarginfiAccounts = (await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(this.umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), false)).filter((x) => x.marginfiAccount.equals(this.marginfiAccountPk));
|
59
56
|
const emptyMarginfiAccounts = (await (0, marginfi_sdk_1.safeFetchAllMarginfiAccount)(this.umi, existingMarginfiAccounts.map((x) => (0, umi_1.publicKey)(x.marginfiAccount)))).filter((x) => x.lendingAccount.balances.find((y) => y.bankPk.toString() !== web3_js_1.PublicKey.default.toString() &&
|
60
57
|
(Math.round((0, numberUtils_1.bytesToI80F48)(y.assetShares.value)) != 0 ||
|
61
58
|
Math.round((0, numberUtils_1.bytesToI80F48)(y.liabilityShares.value)) != 0)) === undefined);
|
@@ -270,7 +267,9 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
270
267
|
supplyBank: (0, umi_1.publicKey)(this.marginfiSupplyBankAccounts.bank),
|
271
268
|
supplyPriceOracle: (0, umi_1.publicKey)(this.marginfiSupplyBankAccounts.priceOracle),
|
272
269
|
positionSupplyTa: (0, umi_1.publicKey)(this.positionSupplyTa),
|
273
|
-
signerSupplyTa: this.selfManaged
|
270
|
+
signerSupplyTa: this.selfManaged
|
271
|
+
? (0, umi_1.publicKey)(this.signerSupplyTa)
|
272
|
+
: undefined,
|
274
273
|
vaultSupplyTa: (0, umi_1.publicKey)(this.marginfiSupplyBankAccounts.liquidityVault),
|
275
274
|
supplyVaultAuthority: (0, umi_1.publicKey)(this.marginfiSupplyBankAccounts.vaultAuthority),
|
276
275
|
debtBank: (0, umi_1.publicKey)(this.marginfiDebtBankAccounts.bank),
|
package/package.json
CHANGED
@@ -109,10 +109,6 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
109
109
|
public intermediaryMarginfiAccount?: MarginfiAccount;
|
110
110
|
|
111
111
|
async initialize(args: SolautoMarginfiClientArgs) {
|
112
|
-
if (args.marginfiAccount) {
|
113
|
-
this.marginfiAccount = args.marginfiAccount;
|
114
|
-
}
|
115
|
-
|
116
112
|
await super.initialize(args, LendingPlatform.Marginfi);
|
117
113
|
|
118
114
|
this.marginfiAccountSeedIdx = args.marginfiAccountSeedIdx;
|
@@ -144,11 +140,13 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
144
140
|
mint: this.debtMint.toString(),
|
145
141
|
})!;
|
146
142
|
|
147
|
-
const existingMarginfiAccounts =
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
143
|
+
const existingMarginfiAccounts = (
|
144
|
+
await getAllMarginfiAccountsByAuthority(
|
145
|
+
this.umi,
|
146
|
+
toWeb3JsPublicKey(this.signer.publicKey),
|
147
|
+
false
|
148
|
+
)
|
149
|
+
).filter((x) => x.marginfiAccount.equals(this.marginfiAccountPk));
|
152
150
|
const emptyMarginfiAccounts = (
|
153
151
|
await safeFetchAllMarginfiAccount(
|
154
152
|
this.umi,
|
@@ -284,7 +282,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
284
282
|
marginfiAccount: publicKey(this.marginfiAccountPk),
|
285
283
|
marginfiGroup: publicKey(this.marginfiGroup),
|
286
284
|
bank: publicKey(this.marginfiSupplyBankAccounts.bank),
|
287
|
-
bankLiquidityVault: publicKey(
|
285
|
+
bankLiquidityVault: publicKey(
|
286
|
+
this.marginfiSupplyBankAccounts.liquidityVault
|
287
|
+
),
|
288
288
|
});
|
289
289
|
}
|
290
290
|
case "Borrow": {
|
@@ -295,33 +295,45 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
295
295
|
marginfiAccount: publicKey(this.marginfiAccountPk),
|
296
296
|
marginfiGroup: publicKey(this.marginfiGroup),
|
297
297
|
bank: publicKey(this.marginfiDebtBankAccounts.bank),
|
298
|
-
bankLiquidityVault: publicKey(
|
299
|
-
|
298
|
+
bankLiquidityVault: publicKey(
|
299
|
+
this.marginfiDebtBankAccounts.liquidityVault
|
300
|
+
),
|
301
|
+
bankLiquidityVaultAuthority: publicKey(
|
302
|
+
this.marginfiDebtBankAccounts.vaultAuthority
|
303
|
+
),
|
300
304
|
});
|
301
305
|
}
|
302
306
|
case "Repay": {
|
303
307
|
return lendingAccountRepay(this.umi, {
|
304
|
-
amount:
|
308
|
+
amount:
|
309
|
+
args.fields[0].__kind === "Some" ? args.fields[0].fields[0] : 0,
|
305
310
|
repayAll: args.fields[0].__kind === "All" ? true : false,
|
306
311
|
signer: this.signer,
|
307
312
|
signerTokenAccount: publicKey(this.signerDebtTa),
|
308
313
|
marginfiAccount: publicKey(this.marginfiAccountPk),
|
309
314
|
marginfiGroup: publicKey(this.marginfiGroup),
|
310
315
|
bank: publicKey(this.marginfiDebtBankAccounts.bank),
|
311
|
-
bankLiquidityVault: publicKey(
|
316
|
+
bankLiquidityVault: publicKey(
|
317
|
+
this.marginfiDebtBankAccounts.liquidityVault
|
318
|
+
),
|
312
319
|
});
|
313
320
|
}
|
314
321
|
case "Withdraw": {
|
315
322
|
return lendingAccountWithdraw(this.umi, {
|
316
|
-
amount:
|
323
|
+
amount:
|
324
|
+
args.fields[0].__kind === "Some" ? args.fields[0].fields[0] : 0,
|
317
325
|
withdrawAll: args.fields[0].__kind === "All" ? true : false,
|
318
326
|
signer: this.signer,
|
319
327
|
destinationTokenAccount: publicKey(this.signerSupplyTa),
|
320
328
|
marginfiAccount: publicKey(this.marginfiAccountPk),
|
321
329
|
marginfiGroup: publicKey(this.marginfiGroup),
|
322
330
|
bank: publicKey(this.marginfiSupplyBankAccounts.bank),
|
323
|
-
bankLiquidityVault: publicKey(
|
324
|
-
|
331
|
+
bankLiquidityVault: publicKey(
|
332
|
+
this.marginfiSupplyBankAccounts.liquidityVault
|
333
|
+
),
|
334
|
+
bankLiquidityVaultAuthority: publicKey(
|
335
|
+
this.marginfiSupplyBankAccounts.vaultAuthority
|
336
|
+
),
|
325
337
|
});
|
326
338
|
}
|
327
339
|
}
|
@@ -422,7 +434,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
422
434
|
supplyBank: publicKey(this.marginfiSupplyBankAccounts.bank),
|
423
435
|
supplyPriceOracle: publicKey(this.marginfiSupplyBankAccounts.priceOracle),
|
424
436
|
positionSupplyTa: publicKey(this.positionSupplyTa),
|
425
|
-
signerSupplyTa: this.selfManaged
|
437
|
+
signerSupplyTa: this.selfManaged
|
438
|
+
? publicKey(this.signerSupplyTa)
|
439
|
+
: undefined,
|
426
440
|
vaultSupplyTa: publicKey(this.marginfiSupplyBankAccounts.liquidityVault),
|
427
441
|
supplyVaultAuthority: publicKey(
|
428
442
|
this.marginfiSupplyBankAccounts.vaultAuthority
|
@@ -261,7 +261,6 @@ describe("Rebalance tests", async () => {
|
|
261
261
|
let supplyPrice: number, debtPrice: number;
|
262
262
|
|
263
263
|
before(async () => {
|
264
|
-
console.log("Fetching prices for test");
|
265
264
|
[supplyPrice, debtPrice] = await getTokenPrices([
|
266
265
|
NATIVE_MINT,
|
267
266
|
new PublicKey(USDC_MINT),
|