@haven-fi/solauto-sdk 1.0.73 → 1.0.74

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":"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,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAGL,eAAe,EAYhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AASnE,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,qBAAa,qBAAsB,SAAQ,aAAa;IACtD,OAAO,CAAC,WAAW,CAAkB;IAE9B,eAAe,EAAG,SAAS,CAAC;IAE5B,sBAAsB,EAAE,MAAM,CAAa;IAC3C,eAAe,EAAG,SAAS,GAAG,MAAM,CAAC;IACrC,iBAAiB,EAAG,SAAS,CAAC;IAC9B,aAAa,EAAG,SAAS,CAAC;IAE1B,sBAAsB,EAAG,qBAAqB,CAAC;IAC/C,oBAAoB,EAAG,qBAAqB,CAAC;IAE7C,iBAAiB,EAAG,SAAS,CAAC;IAC9B,eAAe,EAAG,SAAS,CAAC;IAG5B,iCAAiC,CAAC,E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CAAC,sBAAsB;IA8C9B,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,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IA2DrB,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;CAiBlE"}
@@ -13,6 +13,7 @@ const marginfi_sdk_1 = require("../marginfi-sdk");
13
13
  const marginfiUtils_1 = require("../utils/marginfiUtils");
14
14
  const numberUtils_1 = require("../utils/numberUtils");
15
15
  const constants_1 = require("../constants");
16
+ const utils_1 = require("../utils");
16
17
  class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
17
18
  constructor() {
18
19
  super(...arguments);
@@ -52,6 +53,10 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
52
53
  // this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
53
54
  this.supplyPriceOracle = new web3_js_1.PublicKey(this.marginfiSupplyAccounts.priceOracle);
54
55
  this.debtPriceOracle = new web3_js_1.PublicKey(this.marginfiDebtAccounts.priceOracle);
56
+ if (!this.solautoPositionState) {
57
+ const [maxLtv, liqThreshold] = await (0, marginfiUtils_1.getMaxLtvAndLiqThreshold)(this.umi, { mint: this.supplyMint }, { mint: this.debtMint });
58
+ this.solautoPositionState = (0, utils_1.createFakePositionState)({ mint: this.supplyMint }, { mint: this.debtMint }, (0, numberUtils_1.toBps)(maxLtv), (0, numberUtils_1.toBps)(liqThreshold));
59
+ }
55
60
  if (!this.initialized) {
56
61
  await this.setIntermediaryMarginfiDetails();
57
62
  }
@@ -15,8 +15,8 @@ export declare function getAllPositionsByAuthority(umi: Umi, user: PublicKey): P
15
15
  export declare function positionStateWithLatestPrices(state: PositionState, supplyPrice?: number, debtPrice?: number): Promise<PositionState>;
16
16
  interface AssetProps {
17
17
  mint: PublicKey;
18
- price: number;
19
- amountUsed: number;
18
+ price?: number;
19
+ amountUsed?: number;
20
20
  }
21
21
  export declare function createFakePositionState(supply: AssetProps, debt: AssetProps, maxLtvBps: number, liqThresholdBps: number): PositionState;
22
22
  type PositionAdjustment = {
@@ -1 +1 @@
1
- {"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAA+B,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAElB,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;AAiBzB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAgB9E,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,kBAAkB,EAC9B,eAAe,EAAE,MAAM,GACtB,OAAO,CAET;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,kBAAkB,EAC9B,oBAAoB,EAAE,MAAM,UAY7B;AAED,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,EACnC,eAAe,E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AAM,EACjB,eAAe,EAAE,MAAM,GACtB,aAAa,CA8Df;AAED,KAAK,kBAAkB,GACnB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,gCAAgC,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAE/C,qBAAa,mBAAmB;IACvB,gBAAgB,EAAE,MAAM,CAAa;IACrC,cAAc,EAAE,MAAM,CAAa;IACnC,uBAAuB,EAAE,MAAM,CAAa;IAC5C,QAAQ,EAAE,yBAAyB,GAAG,SAAS,CAAa;IAC5D,SAAS,EAAE,WAAW,GAAG,SAAS,CAAa;IAEtD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IAyD9B,KAAK;IAQL,UAAU,IAAI,OAAO;CAQtB"}
@@ -237,20 +237,20 @@ async function positionStateWithLatestPrices(state, supplyPrice, debtPrice) {
237
237
  function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
238
238
  const supplyDecimals = constants_1.TOKEN_INFO[supply.mint.toString()].decimals;
239
239
  const debtDecimals = constants_1.TOKEN_INFO[debt.mint.toString()].decimals;
240
- const supplyUsd = supply.amountUsed * supply.price;
241
- const debtUsd = debt.amountUsed * debt.price;
240
+ const supplyUsd = (supply.amountUsed ?? 0) * (supply.price ?? 0);
241
+ const debtUsd = (debt.amountUsed ?? 0) * (debt.price ?? 0);
242
242
  return {
243
243
  liqUtilizationRateBps: (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, liqThresholdBps),
244
244
  supply: {
245
245
  amountUsed: {
246
- baseUnit: (0, numberUtils_1.toBaseUnit)(supply.amountUsed, supplyDecimals),
246
+ baseUnit: (0, numberUtils_1.toBaseUnit)(supply.amountUsed ?? 0, supplyDecimals),
247
247
  baseAmountUsdValue: (0, numberUtils_1.toBaseUnit)(supplyUsd, constants_1.USD_DECIMALS),
248
248
  },
249
249
  amountCanBeUsed: {
250
250
  baseUnit: (0, numberUtils_1.toBaseUnit)(1000000, supplyDecimals),
251
- baseAmountUsdValue: BigInt(Math.round(1000000 * supply.price)),
251
+ baseAmountUsdValue: BigInt(Math.round(1000000 * (supply.price ?? 0))),
252
252
  },
253
- baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(supply.price, constants_1.USD_DECIMALS),
253
+ baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(supply.price ?? 0, constants_1.USD_DECIMALS),
254
254
  borrowFeeBps: 0,
255
255
  decimals: supplyDecimals,
256
256
  flashLoanFeeBps: 0,
@@ -261,14 +261,14 @@ function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
261
261
  },
262
262
  debt: {
263
263
  amountUsed: {
264
- baseUnit: (0, numberUtils_1.toBaseUnit)(debt.amountUsed, debtDecimals),
264
+ baseUnit: (0, numberUtils_1.toBaseUnit)(debt.amountUsed ?? 0, debtDecimals),
265
265
  baseAmountUsdValue: (0, numberUtils_1.toBaseUnit)(debtUsd, constants_1.USD_DECIMALS),
266
266
  },
267
267
  amountCanBeUsed: {
268
268
  baseUnit: (0, numberUtils_1.toBaseUnit)(1000000, debtDecimals),
269
- baseAmountUsdValue: BigInt(Math.round(1000000 * debt.price)),
269
+ baseAmountUsdValue: BigInt(Math.round(1000000 * (debt.price ?? 0))),
270
270
  },
271
- baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(debt.price, constants_1.USD_DECIMALS),
271
+ baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(debt.price ?? 0, constants_1.USD_DECIMALS),
272
272
  borrowFeeBps: 0,
273
273
  decimals: debtDecimals,
274
274
  flashLoanFeeBps: 0,
@@ -278,7 +278,9 @@ function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
278
278
  padding: new Uint8Array([]),
279
279
  },
280
280
  netWorth: {
281
- baseUnit: (0, numberUtils_1.toBaseUnit)((supplyUsd - debtUsd) / supply.price, supplyDecimals),
281
+ baseUnit: supply.price
282
+ ? (0, numberUtils_1.toBaseUnit)((supplyUsd - debtUsd) / supply.price, supplyDecimals)
283
+ : BigInt(0),
282
284
  baseAmountUsdValue: (0, numberUtils_1.toBaseUnit)(supplyUsd - debtUsd, constants_1.USD_DECIMALS),
283
285
  },
284
286
  maxLtvBps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.73",
3
+ "version": "1.0.74",
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",
@@ -55,9 +55,11 @@ import {
55
55
  findMarginfiAccounts,
56
56
  getAllMarginfiAccountsByAuthority,
57
57
  getMarginfiAccountPositionState,
58
+ getMaxLtvAndLiqThreshold,
58
59
  } from "../utils/marginfiUtils";
59
- import { bytesToI80F48 } from "../utils/numberUtils";
60
+ import { bytesToI80F48, toBps } from "../utils/numberUtils";
60
61
  import { SOLAUTO_MANAGER } from "../constants";
62
+ import { createFakePositionState } from "../utils";
61
63
 
62
64
  export interface SolautoMarginfiClientArgs extends SolautoClientArgs {
63
65
  marginfiAccount?: PublicKey | Signer;
@@ -127,9 +129,25 @@ export class SolautoMarginfiClient extends SolautoClient {
127
129
  // this.supplyPriceOracle = toWeb3JsPublicKey(supplyBank.config.oracleKeys[0]);
128
130
  // this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
129
131
 
130
- this.supplyPriceOracle = new PublicKey(this.marginfiSupplyAccounts.priceOracle);
132
+ this.supplyPriceOracle = new PublicKey(
133
+ this.marginfiSupplyAccounts.priceOracle
134
+ );
131
135
  this.debtPriceOracle = new PublicKey(this.marginfiDebtAccounts.priceOracle);
132
136
 
137
+ if (!this.solautoPositionState) {
138
+ const [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(
139
+ this.umi,
140
+ { mint: this.supplyMint },
141
+ { mint: this.debtMint }
142
+ );
143
+ this.solautoPositionState = createFakePositionState(
144
+ { mint: this.supplyMint },
145
+ { mint: this.debtMint },
146
+ toBps(maxLtv),
147
+ toBps(liqThreshold)
148
+ );
149
+ }
150
+
133
151
  if (!this.initialized) {
134
152
  await this.setIntermediaryMarginfiDetails();
135
153
  }
@@ -510,33 +528,37 @@ export class SolautoMarginfiClient extends SolautoClient {
510
528
  let includedFlashLoanToken = false;
511
529
 
512
530
  if (this.intermediaryMarginfiAccount) {
513
- this.intermediaryMarginfiAccount.lendingAccount.balances.forEach(async (x) => {
514
- if (x.active) {
515
- if (x.bankPk === accounts.data.bank) {
516
- includedFlashLoanToken = true;
531
+ this.intermediaryMarginfiAccount.lendingAccount.balances.forEach(
532
+ async (x) => {
533
+ if (x.active) {
534
+ if (x.bankPk === accounts.data.bank) {
535
+ includedFlashLoanToken = true;
536
+ }
537
+
538
+ // TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
539
+ // const bankData = await safeFetchBank(this.umi, publicKey(accounts.data.bank));
540
+ // const priceOracle = bankData!.config.oracleKeys[0];
541
+ const priceOracle = publicKey(
542
+ findMarginfiAccounts(toWeb3JsPublicKey(x.bankPk)).priceOracle
543
+ );
544
+
545
+ remainingAccounts.push(
546
+ ...[
547
+ {
548
+ pubkey: x.bankPk,
549
+ isSigner: false,
550
+ isWritable: false,
551
+ },
552
+ {
553
+ pubkey: priceOracle,
554
+ isSigner: false,
555
+ isWritable: false,
556
+ },
557
+ ]
558
+ );
517
559
  }
518
-
519
- // TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
520
- // const bankData = await safeFetchBank(this.umi, publicKey(accounts.data.bank));
521
- // const priceOracle = bankData!.config.oracleKeys[0];
522
- const priceOracle = publicKey(findMarginfiAccounts(toWeb3JsPublicKey(x.bankPk)).priceOracle);
523
-
524
- remainingAccounts.push(
525
- ...[
526
- {
527
- pubkey: x.bankPk,
528
- isSigner: false,
529
- isWritable: false,
530
- },
531
- {
532
- pubkey: priceOracle,
533
- isSigner: false,
534
- isWritable: false,
535
- },
536
- ]
537
- );
538
560
  }
539
- });
561
+ );
540
562
  }
541
563
  if (!this.intermediaryMarginfiAccount || !includedFlashLoanToken) {
542
564
  remainingAccounts.push(
@@ -26,9 +26,7 @@ import {
26
26
  TOKEN_INFO,
27
27
  USD_DECIMALS,
28
28
  } from "../../constants";
29
- import {
30
- getAllMarginfiAccountsByAuthority,
31
- } from "../marginfiUtils";
29
+ import { getAllMarginfiAccountsByAuthority } from "../marginfiUtils";
32
30
  import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
33
31
 
34
32
  function newPeriodsPassed(
@@ -358,8 +356,8 @@ export async function positionStateWithLatestPrices(
358
356
 
359
357
  interface AssetProps {
360
358
  mint: PublicKey;
361
- price: number;
362
- amountUsed: number;
359
+ price?: number;
360
+ amountUsed?: number;
363
361
  }
364
362
 
365
363
  export function createFakePositionState(
@@ -371,8 +369,8 @@ export function createFakePositionState(
371
369
  const supplyDecimals = TOKEN_INFO[supply.mint.toString()].decimals;
372
370
  const debtDecimals = TOKEN_INFO[debt.mint.toString()].decimals;
373
371
 
374
- const supplyUsd = supply.amountUsed * supply.price;
375
- const debtUsd = debt.amountUsed * debt.price;
372
+ const supplyUsd = (supply.amountUsed ?? 0) * (supply.price ?? 0);
373
+ const debtUsd = (debt.amountUsed ?? 0) * (debt.price ?? 0);
376
374
 
377
375
  return {
378
376
  liqUtilizationRateBps: getLiqUtilzationRateBps(
@@ -382,14 +380,14 @@ export function createFakePositionState(
382
380
  ),
383
381
  supply: {
384
382
  amountUsed: {
385
- baseUnit: toBaseUnit(supply.amountUsed, supplyDecimals),
383
+ baseUnit: toBaseUnit(supply.amountUsed ?? 0, supplyDecimals),
386
384
  baseAmountUsdValue: toBaseUnit(supplyUsd, USD_DECIMALS),
387
385
  },
388
386
  amountCanBeUsed: {
389
387
  baseUnit: toBaseUnit(1000000, supplyDecimals),
390
- baseAmountUsdValue: BigInt(Math.round(1000000 * supply.price)),
388
+ baseAmountUsdValue: BigInt(Math.round(1000000 * (supply.price ?? 0))),
391
389
  },
392
- baseAmountMarketPriceUsd: toBaseUnit(supply.price, USD_DECIMALS),
390
+ baseAmountMarketPriceUsd: toBaseUnit(supply.price ?? 0, USD_DECIMALS),
393
391
  borrowFeeBps: 0,
394
392
  decimals: supplyDecimals,
395
393
  flashLoanFeeBps: 0,
@@ -400,14 +398,14 @@ export function createFakePositionState(
400
398
  },
401
399
  debt: {
402
400
  amountUsed: {
403
- baseUnit: toBaseUnit(debt.amountUsed, debtDecimals),
401
+ baseUnit: toBaseUnit(debt.amountUsed ?? 0, debtDecimals),
404
402
  baseAmountUsdValue: toBaseUnit(debtUsd, USD_DECIMALS),
405
403
  },
406
404
  amountCanBeUsed: {
407
405
  baseUnit: toBaseUnit(1000000, debtDecimals),
408
- baseAmountUsdValue: BigInt(Math.round(1000000 * debt.price)),
406
+ baseAmountUsdValue: BigInt(Math.round(1000000 * (debt.price ?? 0))),
409
407
  },
410
- baseAmountMarketPriceUsd: toBaseUnit(debt.price, USD_DECIMALS),
408
+ baseAmountMarketPriceUsd: toBaseUnit(debt.price ?? 0, USD_DECIMALS),
411
409
  borrowFeeBps: 0,
412
410
  decimals: debtDecimals,
413
411
  flashLoanFeeBps: 0,
@@ -417,10 +415,9 @@ export function createFakePositionState(
417
415
  padding: new Uint8Array([]),
418
416
  },
419
417
  netWorth: {
420
- baseUnit: toBaseUnit(
421
- (supplyUsd - debtUsd) / supply.price,
422
- supplyDecimals
423
- ),
418
+ baseUnit: supply.price
419
+ ? toBaseUnit((supplyUsd - debtUsd) / supply.price, supplyDecimals)
420
+ : BigInt(0),
424
421
  baseAmountUsdValue: toBaseUnit(supplyUsd - debtUsd, USD_DECIMALS),
425
422
  },
426
423
  maxLtvBps,