@haven-fi/solauto-sdk 1.0.11 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAEL,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAQJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EASvB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAKvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAInE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAGpE,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IAEvB,mBAAmB,CAAC,EAAE,SAAS,CAAC;IAChC,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAE9B,oBAAoB,CAAC,EAAE,SAAS,CAAC;IACjC,mBAAmB,CAAC,EAAE,SAAS,CAAC;CACjC;AAED,8BAAsB,aAAa;IAwC/B,OAAO,CAAC,YAAY;IACb,SAAS,CAAC;IAxCZ,GAAG,EAAG,GAAG,CAAC;IACV,UAAU,EAAG,UAAU,CAAC;IACxB,eAAe,EAAG,eAAe,CAAC;IAElC,SAAS,EAAG,SAAS,CAAC;IACtB,MAAM,EAAG,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,QAAQ,CAAC,OAAO,IAAI,kBAAkB;IAEtC,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAuFhE,QAAQ,CAAC,WAAW,CAClB,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IAErB,QAAQ,CAAC,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAE3E,QAAQ,CAAC,SAAS,CAChB,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAYlE"}
@@ -5,6 +5,7 @@ require("rpc-websockets/dist/lib/client");
5
5
  const web3_js_1 = require("@solana/web3.js");
6
6
  const umi_1 = require("@metaplex-foundation/umi");
7
7
  const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
8
+ const umi_bundle_defaults_1 = require("@metaplex-foundation/umi-bundle-defaults");
8
9
  const umi_signer_wallet_adapters_1 = require("@metaplex-foundation/umi-signer-wallet-adapters");
9
10
  const generated_1 = require("../generated");
10
11
  const accountUtils_1 = require("../utils/accountUtils");
@@ -14,7 +15,6 @@ const spl_token_1 = require("@solana/spl-token");
14
15
  const solautoConstants_1 = require("../constants/solautoConstants");
15
16
  const generalUtils_1 = require("../utils/generalUtils");
16
17
  const generalUtils_2 = require("../utils/solauto/generalUtils");
17
- const umi_bundle_defaults_1 = require("@metaplex-foundation/umi-bundle-defaults");
18
18
  class SolautoClient {
19
19
  constructor(heliusApiKey, localTest) {
20
20
  this.heliusApiKey = heliusApiKey;
@@ -1 +1 @@
1
- {"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAKA,O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,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA2C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAMhE,OAAO,CAAC,6BAA6B;IA8DrC,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IA4CrB,WAAW,CACT,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IA8ElE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAiBlE"}
@@ -50,8 +50,8 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
50
50
  this.marginfiDebtBankAccounts = (0, marginfiUtils_1.findMarginfiBankAccounts)({
51
51
  mint: this.debtLiquidityMint.toString(),
52
52
  });
53
- const existingMarginfiAccounts = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(this.umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey));
54
- const emptyMarginfiAccounts = existingMarginfiAccounts.filter((x) => x.lendingAccount.balances.find((y) => y.bankPk.toString() !== web3_js_1.PublicKey.default.toString() &&
53
+ const existingMarginfiAccounts = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(this.umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), false);
54
+ const emptyMarginfiAccounts = (await (0, marginfi_sdk_1.safeFetchAllMarginfiAccount)(this.umi, existingMarginfiAccounts.map((x) => (0, umi_1.publicKey)(x)))).filter((x) => x.lendingAccount.balances.find((y) => y.bankPk.toString() !== web3_js_1.PublicKey.default.toString() &&
55
55
  (Math.round((0, numberUtils_1.bytesToI80F48)(y.assetShares.value)) != 0 ||
56
56
  Math.round((0, numberUtils_1.bytesToI80F48)(y.liabilityShares.value)) != 0)) === undefined);
57
57
  this.intermediaryMarginfiAccountSigner =
@@ -305,7 +305,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
305
305
  if (state) {
306
306
  return state;
307
307
  }
308
- const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.supplyLiquidityMint, this.debtLiquidityMint, this.marginfiAccountPk, this.livePositionUpdates);
308
+ const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, this.supplyLiquidityMint, this.debtLiquidityMint, this.livePositionUpdates);
309
309
  this.log(freshState);
310
310
  return freshState;
311
311
  }
@@ -1,6 +1,6 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { Umi } from "@metaplex-foundation/umi";
3
- import { Bank, MarginfiAccount } from "../marginfi-sdk";
3
+ import { Bank } from "../marginfi-sdk";
4
4
  import { MarginfiTokenAccounts } from "../types/accounts";
5
5
  import { PositionState } from "../generated";
6
6
  import { LivePositionUpdates } from "./solauto/generalUtils";
@@ -9,7 +9,7 @@ export declare function findMarginfiBankAccounts({ mint, bank, }: {
9
9
  bank?: string;
10
10
  }): MarginfiTokenAccounts;
11
11
  export declare function getMaxLtvAndLiqThreshold(supplyBank: Bank, debtBank: Bank, supplyPrice?: number): Promise<[number, number]>;
12
- export declare function getAllMarginfiAccountsByAuthority(umi: Umi, authority: PublicKey): Promise<MarginfiAccount[]>;
13
- export declare function getMarginfiAccountPositionState(umi: Umi, supplyMint: PublicKey, debtMint: PublicKey, marginfiAccountPk: PublicKey, livePositionUpdates?: LivePositionUpdates): Promise<PositionState | undefined>;
12
+ export declare function getAllMarginfiAccountsByAuthority(umi: Umi, authority: PublicKey, compatibleWithSolauto?: boolean): Promise<PublicKey[]>;
13
+ export declare function getMarginfiAccountPositionState(umi: Umi, marginfiAccountPk: PublicKey, supplyMint?: PublicKey, debtMint?: PublicKey, livePositionUpdates?: LivePositionUpdates): Promise<PositionState | undefined>;
14
14
  export declare function getUpToDateShareValues(umi: Umi, bank: Bank): Promise<[number, number]>;
15
15
  //# sourceMappingURL=marginfiUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAGJ,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAUzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D,wBAAgB,wBAAwB,CAAC,EACvC,IAAI,EACJ,IAAI,GACL,EAAE;IACD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,qBAAqB,CAWxB;AAED,wBAAsB,wBAAwB,CAC5C,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,IAAI,EACd,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAkC3B;AAED,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,eAAe,EAAE,CAAC,CA2B5B;AAoDD,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,SAAS,EACrB,QAAQ,EAAE,SAAS,EACnB,iBAAiB,EAAE,SAAS,EAC5B,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,OAAO,CAAC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GAAG,SAAS,CAAC,CA4IpC;AA+DD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CA0B3B"}
@@ -44,7 +44,7 @@ async function getMaxLtvAndLiqThreshold(supplyBank, debtBank, supplyPrice) {
44
44
  return [maxLtv, liqThreshold];
45
45
  }
46
46
  exports.getMaxLtvAndLiqThreshold = getMaxLtvAndLiqThreshold;
47
- async function getAllMarginfiAccountsByAuthority(umi, authority) {
47
+ async function getAllMarginfiAccountsByAuthority(umi, authority, compatibleWithSolauto) {
48
48
  const marginfiAccounts = await umi.rpc.getProgramAccounts(marginfi_sdk_1.MARGINFI_PROGRAM_ID, {
49
49
  commitment: "finalized",
50
50
  dataSlice: {
@@ -63,7 +63,18 @@ async function getAllMarginfiAccountsByAuthority(umi, authority) {
63
63
  },
64
64
  ],
65
65
  });
66
- return (0, marginfi_sdk_1.safeFetchAllMarginfiAccount)(umi, marginfiAccounts.map((x) => x.publicKey));
66
+ if (compatibleWithSolauto) {
67
+ const compatiblePositions = await Promise.all(marginfiAccounts.map((x) => ({
68
+ publicKey: x.publicKey,
69
+ state: getMarginfiAccountPositionState(umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey)),
70
+ })));
71
+ return compatiblePositions
72
+ .filter((x) => x.state !== undefined)
73
+ .map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
74
+ }
75
+ else {
76
+ return marginfiAccounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
77
+ }
67
78
  }
68
79
  exports.getAllMarginfiAccountsByAuthority = getAllMarginfiAccountsByAuthority;
69
80
  async function getTokenUsage(umi, bank, isAsset, shares, amountUsedAdjustment) {
@@ -97,7 +108,7 @@ async function getTokenUsage(umi, bank, isAsset, shares, amountUsedAdjustment) {
97
108
  padding: new Uint8Array([]),
98
109
  };
99
110
  }
100
- async function getMarginfiAccountPositionState(umi, supplyMint, debtMint, marginfiAccountPk, livePositionUpdates) {
111
+ async function getMarginfiAccountPositionState(umi, marginfiAccountPk, supplyMint, debtMint, livePositionUpdates) {
101
112
  let marginfiAccount = await (0, marginfi_sdk_1.safeFetchMarginfiAccount)(umi, (0, umi_1.publicKey)(marginfiAccountPk));
102
113
  let supplyBank = supplyMint && supplyMint !== web3_js_1.PublicKey.default
103
114
  ? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(findMarginfiBankAccounts({ mint: supplyMint.toString() }).bank))
@@ -111,19 +122,27 @@ async function getMarginfiAccountPositionState(umi, supplyMint, debtMint, margin
111
122
  marginfiAccount.lendingAccount.balances.filter((x) => x.active).length > 0) {
112
123
  const supplyBalances = marginfiAccount.lendingAccount.balances.filter((balance) => balance.active && (0, numberUtils_1.bytesToI80F48)(balance.assetShares.value) > 0);
113
124
  const debtBalances = marginfiAccount.lendingAccount.balances.filter((balance) => balance.active && (0, numberUtils_1.bytesToI80F48)(balance.liabilityShares.value) > 0);
114
- for (const balance of supplyBalances) {
125
+ if (supplyBalances.length > 1 || debtBalances.length > 1) {
126
+ // Not compatible with Solauto
127
+ return undefined;
128
+ }
129
+ if (supplyBalances.length > 0) {
115
130
  if (supplyBank === null) {
116
- supplyBank = await (0, marginfi_sdk_1.safeFetchBank)(umi, balance.bankPk);
131
+ supplyBank = await (0, marginfi_sdk_1.safeFetchBank)(umi, supplyBalances[0].bankPk);
132
+ }
133
+ if (!supplyMint) {
134
+ supplyMint = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(supplyBank.mint);
117
135
  }
118
- supplyUsage = await getTokenUsage(umi, supplyBank, true, (0, numberUtils_1.bytesToI80F48)(balance.assetShares.value), livePositionUpdates?.supplyAdjustment);
119
- break;
136
+ supplyUsage = await getTokenUsage(umi, supplyBank, true, (0, numberUtils_1.bytesToI80F48)(supplyBalances[0].assetShares.value), livePositionUpdates?.supplyAdjustment);
120
137
  }
121
- for (const balance of debtBalances) {
138
+ if (debtBalances.length > 0) {
122
139
  if (debtBank === null) {
123
- debtBank = await (0, marginfi_sdk_1.safeFetchBank)(umi, balance.bankPk);
140
+ debtBank = await (0, marginfi_sdk_1.safeFetchBank)(umi, debtBalances[0].bankPk);
141
+ }
142
+ if (!debtMint) {
143
+ debtMint = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(debtBank.mint);
124
144
  }
125
- debtUsage = await getTokenUsage(umi, debtBank, false, (0, numberUtils_1.bytesToI80F48)(balance.liabilityShares.value), livePositionUpdates?.debtAdjustment);
126
- break;
145
+ debtUsage = await getTokenUsage(umi, debtBank, false, (0, numberUtils_1.bytesToI80F48)(debtBalances[0].liabilityShares.value), livePositionUpdates?.debtAdjustment);
127
146
  }
128
147
  }
129
148
  if (supplyBank !== null && !supplyUsage) {
@@ -1,4 +1,5 @@
1
- import { PublicKey, Umi } from "@metaplex-foundation/umi";
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { Umi } from "@metaplex-foundation/umi";
2
3
  import { AutomationSettings, DCASettings, DCASettingsInpArgs, FeeType, LendingPlatform, PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs } from "../../generated";
3
4
  export declare function nextAutomationPeriodTimestamp(automation: AutomationSettings): number;
4
5
  export declare function eligibleForNextAutomationPeriod(automation: AutomationSettings): boolean;
@@ -21,6 +22,12 @@ export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicK
21
22
  }[]>;
22
23
  export declare function getAllReferralStates(umi: Umi): Promise<PublicKey[]>;
23
24
  export declare function getReferralsByUser(umi: Umi, user: PublicKey): Promise<PublicKey[]>;
25
+ export interface SolautoPositionDetails {
26
+ positionId: number;
27
+ lendingPlatform: LendingPlatform;
28
+ protocolAccount?: PublicKey;
29
+ }
30
+ export declare function getAllPositionsByAuthority(umi: Umi, user: PublicKey): Promise<SolautoPositionDetails[]>;
24
31
  type PositionAdjustment = {
25
32
  type: "supply";
26
33
  value: bigint;
@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G,SAAS,CAAa;IAC5D,SAAS,EAAE,WAAW,GAAG,SAAS,CAAa;IAEtD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IAyD9B,KAAK;IAQL,UAAU,IAAI,OAAO;CAQtB"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LivePositionUpdates = exports.getReferralsByUser = exports.getAllReferralStates = exports.getSolautoManagedPositions = exports.eligibleForRefresh = exports.eligibileForRebalance = exports.maxRepayTo = exports.maxRepayFrom = exports.getMaxLiqUtilizationRate = exports.getSolautoFeesBps = exports.getAdjustedSettingsFromAutomation = exports.getUpdatedValueFromAutomation = exports.eligibleForNextAutomationPeriod = exports.nextAutomationPeriodTimestamp = void 0;
3
+ exports.LivePositionUpdates = exports.getAllPositionsByAuthority = exports.getReferralsByUser = exports.getAllReferralStates = exports.getSolautoManagedPositions = exports.eligibleForRefresh = exports.eligibileForRebalance = exports.maxRepayTo = exports.maxRepayFrom = exports.getMaxLiqUtilizationRate = exports.getSolautoFeesBps = exports.getAdjustedSettingsFromAutomation = exports.getUpdatedValueFromAutomation = exports.eligibleForNextAutomationPeriod = exports.nextAutomationPeriodTimestamp = void 0;
4
4
  const umi_1 = require("@metaplex-foundation/umi");
5
5
  const generated_1 = require("../../generated");
6
6
  const generalUtils_1 = require("../generalUtils");
@@ -129,7 +129,7 @@ async function getSolautoManagedPositions(umi, authority) {
129
129
  ? [
130
130
  {
131
131
  memcmp: {
132
- bytes: new Uint8Array((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(authority).toBuffer()),
132
+ bytes: new Uint8Array(authority.toBuffer()),
133
133
  offset: 8,
134
134
  },
135
135
  },
@@ -143,7 +143,7 @@ async function getSolautoManagedPositions(umi, authority) {
143
143
  ...Array((0, generated_1.getSolautoPositionSize)() - x.data.length).fill(0),
144
144
  ]));
145
145
  return {
146
- authority: position.authority,
146
+ authority: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.authority),
147
147
  positionId: position.positionId[0],
148
148
  lendingPlatform: position.position.lendingPlatform,
149
149
  };
@@ -163,7 +163,7 @@ async function getAllReferralStates(umi) {
163
163
  },
164
164
  ],
165
165
  });
166
- return accounts.map((x) => x.publicKey);
166
+ return accounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
167
167
  }
168
168
  exports.getAllReferralStates = getAllReferralStates;
169
169
  async function getReferralsByUser(umi, user) {
@@ -171,7 +171,7 @@ async function getReferralsByUser(umi, user) {
171
171
  // padding: [u8; 7],
172
172
  // authority: Pubkey,
173
173
  // referred_by_state: Pubkey,
174
- const userReferralState = await (0, accountUtils_1.getReferralState)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(user));
174
+ const userReferralState = await (0, accountUtils_1.getReferralState)(user);
175
175
  const accounts = await umi.rpc.getProgramAccounts(generated_1.SOLAUTO_PROGRAM_ID, {
176
176
  commitment: "finalized",
177
177
  dataSlice: {
@@ -190,13 +190,30 @@ async function getReferralsByUser(umi, user) {
190
190
  },
191
191
  ],
192
192
  });
193
- return accounts.map((x) => x.publicKey);
193
+ return accounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
194
194
  }
195
195
  exports.getReferralsByUser = getReferralsByUser;
196
+ async function getAllPositionsByAuthority(umi, user) {
197
+ const allPositions = [];
198
+ const solautoManagedPositions = await getSolautoManagedPositions(umi, user);
199
+ allPositions.push(...solautoManagedPositions.map((x) => ({
200
+ positionId: x.positionId,
201
+ lendingPlatform: x.lendingPlatform,
202
+ })));
203
+ const marginfiPositions = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(umi, user, true);
204
+ allPositions.push(...marginfiPositions.map((pubkey) => ({
205
+ positionId: 0,
206
+ lendingPlatform: generated_1.LendingPlatform.Marginfi,
207
+ protocolAccount: pubkey,
208
+ })));
209
+ // TODO support other platforms
210
+ return [];
211
+ }
212
+ exports.getAllPositionsByAuthority = getAllPositionsByAuthority;
196
213
  async function positionStateWithLatestPrices(umi, state, protocolAccount, lendingPlatform) {
197
214
  if ((0, generalUtils_1.currentUnixSeconds)() - Number(state.lastUpdated) > 60 * 60 * 24 * 7) {
198
215
  if (lendingPlatform === generated_1.LendingPlatform.Marginfi) {
199
- return await (0, marginfiUtils_1.getMarginfiAccountPositionState)(umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint), (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.debt.mint), (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(protocolAccount));
216
+ return await (0, marginfiUtils_1.getMarginfiAccountPositionState)(umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint), (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.debt.mint), protocolAccount);
200
217
  }
201
218
  else {
202
219
  throw new Error("Lending platorm not yet supported");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
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",
@@ -17,6 +17,7 @@ import {
17
17
  some,
18
18
  } from "@metaplex-foundation/umi";
19
19
  import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
20
+ import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
20
21
  import {
21
22
  WalletAdapter,
22
23
  walletAdapterIdentity,
@@ -58,7 +59,6 @@ import { NATIVE_MINT } from "@solana/spl-token";
58
59
  import { MIN_POSITION_STATE_FRESHNESS_SECS } from "../constants/solautoConstants";
59
60
  import { currentUnixSeconds } from "../utils/generalUtils";
60
61
  import { LivePositionUpdates } from "../utils/solauto/generalUtils";
61
- import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
62
62
 
63
63
  export interface SolautoClientArgs {
64
64
  authority?: PublicKey;
@@ -45,6 +45,7 @@ import {
45
45
  lendingAccountRepay,
46
46
  lendingAccountStartFlashloan,
47
47
  marginfiAccountInitialize,
48
+ safeFetchAllMarginfiAccount,
48
49
  safeFetchMarginfiAccount,
49
50
  } from "../marginfi-sdk";
50
51
  import { JupSwapDetails } from "../utils/jupiterUtils";
@@ -136,9 +137,15 @@ export class SolautoMarginfiClient extends SolautoClient {
136
137
 
137
138
  const existingMarginfiAccounts = await getAllMarginfiAccountsByAuthority(
138
139
  this.umi,
139
- toWeb3JsPublicKey(this.signer.publicKey)
140
+ toWeb3JsPublicKey(this.signer.publicKey),
141
+ false
140
142
  );
141
- const emptyMarginfiAccounts = existingMarginfiAccounts.filter(
143
+ const emptyMarginfiAccounts = (
144
+ await safeFetchAllMarginfiAccount(
145
+ this.umi,
146
+ existingMarginfiAccounts.map((x) => publicKey(x))
147
+ )
148
+ ).filter(
142
149
  (x) =>
143
150
  x.lendingAccount.balances.find(
144
151
  (y) =>
@@ -484,13 +491,13 @@ export class SolautoMarginfiClient extends SolautoClient {
484
491
 
485
492
  const freshState = await getMarginfiAccountPositionState(
486
493
  this.umi,
494
+ this.marginfiAccountPk,
487
495
  this.supplyLiquidityMint,
488
496
  this.debtLiquidityMint,
489
- this.marginfiAccountPk,
490
497
  this.livePositionUpdates
491
498
  );
492
499
  this.log(freshState);
493
-
500
+
494
501
  return freshState;
495
502
  }
496
503
  }
@@ -86,8 +86,9 @@ export async function getMaxLtvAndLiqThreshold(
86
86
 
87
87
  export async function getAllMarginfiAccountsByAuthority(
88
88
  umi: Umi,
89
- authority: PublicKey
90
- ): Promise<MarginfiAccount[]> {
89
+ authority: PublicKey,
90
+ compatibleWithSolauto?: boolean
91
+ ): Promise<PublicKey[]> {
91
92
  const marginfiAccounts = await umi.rpc.getProgramAccounts(
92
93
  MARGINFI_PROGRAM_ID,
93
94
  {
@@ -110,10 +111,23 @@ export async function getAllMarginfiAccountsByAuthority(
110
111
  }
111
112
  );
112
113
 
113
- return safeFetchAllMarginfiAccount(
114
- umi,
115
- marginfiAccounts.map((x) => x.publicKey)
116
- );
114
+ if (compatibleWithSolauto) {
115
+ const compatiblePositions = await Promise.all(
116
+ marginfiAccounts.map((x) => ({
117
+ publicKey: x.publicKey,
118
+ state: getMarginfiAccountPositionState(
119
+ umi,
120
+ toWeb3JsPublicKey(x.publicKey)
121
+ ),
122
+ }))
123
+ );
124
+
125
+ return compatiblePositions
126
+ .filter((x) => x.state !== undefined)
127
+ .map((x) => toWeb3JsPublicKey(x.publicKey));
128
+ } else {
129
+ return marginfiAccounts.map((x) => toWeb3JsPublicKey(x.publicKey));
130
+ }
117
131
  }
118
132
 
119
133
  async function getTokenUsage(
@@ -168,9 +182,9 @@ async function getTokenUsage(
168
182
 
169
183
  export async function getMarginfiAccountPositionState(
170
184
  umi: Umi,
171
- supplyMint: PublicKey,
172
- debtMint: PublicKey,
173
185
  marginfiAccountPk: PublicKey,
186
+ supplyMint?: PublicKey,
187
+ debtMint?: PublicKey,
174
188
  livePositionUpdates?: LivePositionUpdates
175
189
  ): Promise<PositionState | undefined> {
176
190
  let marginfiAccount = await safeFetchMarginfiAccount(
@@ -213,33 +227,41 @@ export async function getMarginfiAccountPositionState(
213
227
  balance.active && bytesToI80F48(balance.liabilityShares.value) > 0
214
228
  );
215
229
 
216
- for (const balance of supplyBalances) {
230
+ if (supplyBalances.length > 1 || debtBalances.length > 1) {
231
+ // Not compatible with Solauto
232
+ return undefined;
233
+ }
234
+
235
+ if (supplyBalances.length > 0) {
217
236
  if (supplyBank === null) {
218
- supplyBank = await safeFetchBank(umi, balance.bankPk);
237
+ supplyBank = await safeFetchBank(umi, supplyBalances[0].bankPk);
238
+ }
239
+ if (!supplyMint) {
240
+ supplyMint = toWeb3JsPublicKey(supplyBank!.mint);
219
241
  }
220
-
221
242
  supplyUsage = await getTokenUsage(
222
243
  umi,
223
244
  supplyBank!,
224
245
  true,
225
- bytesToI80F48(balance.assetShares.value),
246
+ bytesToI80F48(supplyBalances[0].assetShares.value),
226
247
  livePositionUpdates?.supplyAdjustment
227
248
  );
228
- break;
229
249
  }
230
- for (const balance of debtBalances) {
250
+
251
+ if (debtBalances.length > 0) {
231
252
  if (debtBank === null) {
232
- debtBank = await safeFetchBank(umi, balance.bankPk);
253
+ debtBank = await safeFetchBank(umi, debtBalances[0].bankPk);
254
+ }
255
+ if (!debtMint) {
256
+ debtMint = toWeb3JsPublicKey(debtBank!.mint);
233
257
  }
234
-
235
258
  debtUsage = await getTokenUsage(
236
259
  umi,
237
260
  debtBank!,
238
261
  false,
239
- bytesToI80F48(balance.liabilityShares.value),
262
+ bytesToI80F48(debtBalances[0].liabilityShares.value),
240
263
  livePositionUpdates?.debtAdjustment
241
264
  );
242
- break;
243
265
  }
244
266
  }
245
267
 
@@ -267,7 +289,7 @@ export async function getMarginfiAccountPositionState(
267
289
  return undefined;
268
290
  }
269
291
 
270
- const supplyPrice = PRICES[supplyMint.toString()].price;
292
+ const supplyPrice = PRICES[supplyMint!.toString()].price;
271
293
  let [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(
272
294
  supplyBank,
273
295
  debtBank,
@@ -1,4 +1,5 @@
1
- import { isOption, isSome, PublicKey, Umi } from "@metaplex-foundation/umi";
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { isOption, isSome, Umi } from "@metaplex-foundation/umi";
2
3
  import {
3
4
  AutomationSettings,
4
5
  DCASettings,
@@ -25,7 +26,10 @@ import { MAX_REPAY_GAP_BPS } from "../../constants/solautoConstants";
25
26
  import { getReferralState } from "../accountUtils";
26
27
  import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
27
28
  import { USD_DECIMALS } from "../../constants";
28
- import { getMarginfiAccountPositionState } from "../marginfiUtils";
29
+ import {
30
+ getAllMarginfiAccountsByAuthority,
31
+ getMarginfiAccountPositionState,
32
+ } from "../marginfiUtils";
29
33
 
30
34
  function newPeriodsPassed(
31
35
  automation: AutomationSettings,
@@ -225,7 +229,7 @@ export async function getSolautoManagedPositions(
225
229
  ? [
226
230
  {
227
231
  memcmp: {
228
- bytes: new Uint8Array(toWeb3JsPublicKey(authority).toBuffer()),
232
+ bytes: new Uint8Array(authority.toBuffer()),
229
233
  offset: 8,
230
234
  },
231
235
  },
@@ -242,7 +246,7 @@ export async function getSolautoManagedPositions(
242
246
  ])
243
247
  );
244
248
  return {
245
- authority: position.authority,
249
+ authority: toWeb3JsPublicKey(position.authority),
246
250
  positionId: position.positionId[0],
247
251
  lendingPlatform: position.position.lendingPlatform,
248
252
  };
@@ -263,7 +267,7 @@ export async function getAllReferralStates(umi: Umi): Promise<PublicKey[]> {
263
267
  ],
264
268
  });
265
269
 
266
- return accounts.map((x) => x.publicKey);
270
+ return accounts.map((x) => toWeb3JsPublicKey(x.publicKey));
267
271
  }
268
272
 
269
273
  export async function getReferralsByUser(
@@ -275,7 +279,7 @@ export async function getReferralsByUser(
275
279
  // authority: Pubkey,
276
280
  // referred_by_state: Pubkey,
277
281
 
278
- const userReferralState = await getReferralState(toWeb3JsPublicKey(user));
282
+ const userReferralState = await getReferralState(user);
279
283
  const accounts = await umi.rpc.getProgramAccounts(SOLAUTO_PROGRAM_ID, {
280
284
  commitment: "finalized",
281
285
  dataSlice: {
@@ -295,7 +299,41 @@ export async function getReferralsByUser(
295
299
  ],
296
300
  });
297
301
 
298
- return accounts.map((x) => x.publicKey);
302
+ return accounts.map((x) => toWeb3JsPublicKey(x.publicKey));
303
+ }
304
+
305
+ export interface SolautoPositionDetails {
306
+ positionId: number;
307
+ lendingPlatform: LendingPlatform;
308
+ protocolAccount?: PublicKey;
309
+ }
310
+
311
+ export async function getAllPositionsByAuthority(
312
+ umi: Umi,
313
+ user: PublicKey
314
+ ): Promise<SolautoPositionDetails[]> {
315
+ const allPositions: SolautoPositionDetails[] = [];
316
+
317
+ const solautoManagedPositions = await getSolautoManagedPositions(umi, user);
318
+ allPositions.push(
319
+ ...solautoManagedPositions.map((x) => ({
320
+ positionId: x.positionId,
321
+ lendingPlatform: x.lendingPlatform,
322
+ }))
323
+ );
324
+
325
+ const marginfiPositions = await getAllMarginfiAccountsByAuthority(umi, user, true);
326
+ allPositions.push(
327
+ ...marginfiPositions.map((pubkey) => ({
328
+ positionId: 0,
329
+ lendingPlatform: LendingPlatform.Marginfi,
330
+ protocolAccount: pubkey,
331
+ }))
332
+ );
333
+
334
+ // TODO support other platforms
335
+
336
+ return [];
299
337
  }
300
338
 
301
339
  async function positionStateWithLatestPrices(
@@ -310,7 +348,7 @@ async function positionStateWithLatestPrices(
310
348
  umi,
311
349
  toWeb3JsPublicKey(state.supply.mint),
312
350
  toWeb3JsPublicKey(state.debt.mint),
313
- toWeb3JsPublicKey(protocolAccount)
351
+ protocolAccount
314
352
  );
315
353
  } else {
316
354
  throw new Error("Lending platorm not yet supported");