@haven-fi/solauto-sdk 1.0.199 → 1.0.201
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoClient.d.ts +1 -0
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +1 -1
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +5 -8
- package/dist/utils/accountUtils.d.ts +1 -1
- package/dist/utils/accountUtils.d.ts.map +1 -1
- package/dist/utils/accountUtils.js +2 -2
- package/dist/utils/marginfiUtils.d.ts +1 -0
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +17 -13
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +3 -3
- package/src/clients/solautoMarginfiClient.ts +9 -18
- package/src/utils/accountUtils.ts +2 -2
- package/src/utils/marginfiUtils.ts +61 -34
@@ -9,6 +9,7 @@ import { ReferralStateManager } from "./referralStateManager";
|
|
9
9
|
import { TxHandler } from "./txHandler";
|
10
10
|
import { QuoteResponse } from "@jup-ag/api";
|
11
11
|
export interface SolautoClientArgs {
|
12
|
+
new?: boolean;
|
12
13
|
authority?: PublicKey;
|
13
14
|
positionId?: number;
|
14
15
|
signer?: Signer;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACL,MAAM,EACN,kBAAkB,EAOnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAEhC,sBAAsB,EAMvB,MAAM,cAAc,CAAC;
|
1
|
+
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AwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAOvE,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IA0BrB,gBAAgB,CAAC,IAAI,EAAE,sBAAsB,GAAG,kBAAkB;IAwDlE,eAAe,IAAI,kBAAkB;IAYrC,WAAW,IAAI,kBAAkB;IAgCjC,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,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAalE"}
|
@@ -38,7 +38,7 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
38
38
|
this.selfManaged = this.positionId === 0;
|
39
39
|
this.lendingPlatform = lendingPlatform;
|
40
40
|
this.solautoPosition = (0, accountUtils_1.getSolautoPositionAccount)(this.authority, this.positionId);
|
41
|
-
this.solautoPositionData = await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition), { commitment: "confirmed" });
|
41
|
+
this.solautoPositionData = !args.new ? await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition), { commitment: "confirmed" }) : null;
|
42
42
|
this.solautoPositionState = this.solautoPositionData?.state;
|
43
43
|
this.maxLtvBps = undefined;
|
44
44
|
this.liqThresholdBps = undefined;
|
@@ -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,EAEb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAUhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AASnE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,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,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,CAAC;IAC9B,eAAe,EAAG,SAAS,CAAC;IAG5B,iCAAiC,CAAC,EAAE,MAAM,CAAC;IAC3C,6BAA6B,EAAG,SAAS,CAAC;IAC1C,2BAA2B,CAAC,EAAE,eAAe,CAAC;IAE/C,UAAU,CAAC,IAAI,EAAE,yBAAyB;IA6D1C,8BAA8B;IA0CpC,eAAe,IAAI,SAAS;IAI5B,mBAAmB,IAAI,MAAM,EAAE;IAI/B,gBAAgB,IAAI,SAAS,EAAE;IAUzB,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IA0BvE,yBAAyB,IAAI,kBAAkB;IAS/C,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,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,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IAqErB,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;CA6ClE"}
|
@@ -12,7 +12,6 @@ const generalUtils_1 = require("../utils/generalUtils");
|
|
12
12
|
const marginfi_sdk_1 = require("../marginfi-sdk");
|
13
13
|
const marginfiUtils_1 = require("../utils/marginfiUtils");
|
14
14
|
const numberUtils_1 = require("../utils/numberUtils");
|
15
|
-
const utils_1 = require("../utils");
|
16
15
|
class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
17
16
|
constructor() {
|
18
17
|
super(...arguments);
|
@@ -30,13 +29,15 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
30
29
|
this.marginfiAccountSeedIdx = (0, generalUtils_1.generateRandomU64)();
|
31
30
|
this.marginfiAccount = this.solautoPositionData
|
32
31
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.solautoPositionData.position.protocolAccount)
|
33
|
-
:
|
32
|
+
: (0, accountUtils_1.getMarginfiAccountPDA)(this.solautoPosition, this.marginfiAccountSeedIdx);
|
34
33
|
}
|
35
34
|
this.marginfiAccountPk =
|
36
35
|
"publicKey" in this.marginfiAccount
|
37
36
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.marginfiAccount.publicKey)
|
38
37
|
: this.marginfiAccount;
|
39
|
-
const marginfiAccountData =
|
38
|
+
const marginfiAccountData = !args.new
|
39
|
+
? await (0, marginfi_sdk_1.safeFetchMarginfiAccount)(this.umi, (0, umi_1.publicKey)(this.marginfiAccountPk), { commitment: "confirmed" })
|
40
|
+
: null;
|
40
41
|
this.marginfiGroup = new web3_js_1.PublicKey(marginfiAccountData
|
41
42
|
? marginfiAccountData.group.toString()
|
42
43
|
: (args.marginfiGroup ?? marginfiAccounts_1.DEFAULT_MARGINFI_GROUP));
|
@@ -44,7 +45,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
44
45
|
marginfiAccounts_1.MARGINFI_ACCOUNTS[this.marginfiGroup.toString()][this.supplyMint.toString()];
|
45
46
|
this.marginfiDebtAccounts =
|
46
47
|
marginfiAccounts_1.MARGINFI_ACCOUNTS[this.marginfiGroup.toString()][this.debtMint.toString()];
|
47
|
-
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
48
|
+
// TODO: Don't dynamically pull oracle from bank until Marginfi sorts out their price oracle issues.
|
48
49
|
// const [supplyBank, debtBank] = await safeFetchAllBank(this.umi, [
|
49
50
|
// publicKey(this.marginfiSupplyAccounts.bank),
|
50
51
|
// publicKey(this.marginfiDebtAccounts.bank),
|
@@ -53,10 +54,6 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
53
54
|
// this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
|
54
55
|
this.supplyPriceOracle = new web3_js_1.PublicKey(this.marginfiSupplyAccounts.priceOracle);
|
55
56
|
this.debtPriceOracle = new web3_js_1.PublicKey(this.marginfiDebtAccounts.priceOracle);
|
56
|
-
if (!this.solautoPositionState) {
|
57
|
-
const result = await this.maxLtvAndLiqThresholdBps();
|
58
|
-
this.solautoPositionState = (0, utils_1.createFakePositionState)({ mint: this.supplyMint }, { mint: this.debtMint }, result ? result[0] : 0, result ? result[1] : 0);
|
59
|
-
}
|
60
57
|
if (!this.initialized) {
|
61
58
|
await this.setIntermediaryMarginfiDetails();
|
62
59
|
}
|
@@ -7,5 +7,5 @@ export declare function getTokenAccounts(wallet: PublicKey, tokenMints: PublicKe
|
|
7
7
|
export declare function getTokenAccountData(umi: Umi, tokenAccount: PublicKey): Promise<import("@solana/spl-token").RawAccount | undefined>;
|
8
8
|
export declare function getSolautoPositionAccount(signer: PublicKey, positionId: number): PublicKey;
|
9
9
|
export declare function getReferralState(authority: PublicKey): PublicKey;
|
10
|
-
export declare function getMarginfiAccountPDA(solautoPositionAccount: PublicKey, marginfiAccountSeedIdx: bigint):
|
10
|
+
export declare function getMarginfiAccountPDA(solautoPositionAccount: PublicKey, marginfiAccountSeedIdx: bigint): PublicKey;
|
11
11
|
//# sourceMappingURL=accountUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"accountUtils.d.ts","sourceRoot":"","sources":["../../src/utils/accountUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAi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AAM,aAQnB;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,aAUpD;AAED,wBAAgB,qBAAqB,CACnC,sBAAsB,EAAE,SAAS,EACjC,sBAAsB,EAAE,MAAM,aAa/B"}
|
@@ -47,11 +47,11 @@ function getReferralState(authority) {
|
|
47
47
|
const [ReferralState, _] = web3_js_1.PublicKey.findProgramAddressSync([strBuffer, authority.toBuffer()], new web3_js_1.PublicKey(generated_1.SOLAUTO_PROGRAM_ID));
|
48
48
|
return ReferralState;
|
49
49
|
}
|
50
|
-
|
50
|
+
function getMarginfiAccountPDA(solautoPositionAccount, marginfiAccountSeedIdx) {
|
51
51
|
const seeds = [
|
52
52
|
solautoPositionAccount.toBuffer(),
|
53
53
|
bufferFromU64(marginfiAccountSeedIdx),
|
54
54
|
];
|
55
|
-
const [marginfiAccount, _] =
|
55
|
+
const [marginfiAccount, _] = web3_js_1.PublicKey.findProgramAddressSync(seeds, new web3_js_1.PublicKey(generated_1.SOLAUTO_PROGRAM_ID));
|
56
56
|
return marginfiAccount;
|
57
57
|
}
|
@@ -5,6 +5,7 @@ import { MarginfiAssetAccounts } from "../types/accounts";
|
|
5
5
|
import { PositionState } from "../generated";
|
6
6
|
import { LivePositionUpdates } from "./solauto/generalUtils";
|
7
7
|
export declare function findMarginfiAccounts(bank: PublicKey): MarginfiAssetAccounts;
|
8
|
+
export declare function marginfiMaxLtvAndLiqThresholdBps(supplyBank: Bank, debtBank: Bank, supplyPrice: number): [number, number];
|
8
9
|
export declare function getMaxLtvAndLiqThreshold(umi: Umi, marginfiGroup: PublicKey, supply: {
|
9
10
|
mint: PublicKey;
|
10
11
|
bank?: Bank | null;
|
@@ -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,0B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AQ,CAAC,EAAE,SAAS,CAAA;CAAE,EAAE,CAC/E,CAwDA;AAgED,wBAAsB,+BAA+B,CACnD,GAAG,EAAE,GAAG,EACR,iBAAiB,EAAE,SAAS,EAC5B,aAAa,CAAC,EAAE,SAAS,EACzB,UAAU,CAAC,EAAE,SAAS,EACtB,QAAQ,CAAC,EAAE,SAAS,EACpB,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAmLpC;AA+DD,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAyB3B"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.findMarginfiAccounts = findMarginfiAccounts;
|
4
|
+
exports.marginfiMaxLtvAndLiqThresholdBps = marginfiMaxLtvAndLiqThresholdBps;
|
4
5
|
exports.getMaxLtvAndLiqThreshold = getMaxLtvAndLiqThreshold;
|
5
6
|
exports.getAllMarginfiAccountsByAuthority = getAllMarginfiAccountsByAuthority;
|
6
7
|
exports.getMarginfiAccountPositionState = getMarginfiAccountPositionState;
|
@@ -25,6 +26,21 @@ function findMarginfiAccounts(bank) {
|
|
25
26
|
}
|
26
27
|
throw new Error(`Marginfi accounts not found by the bank: ${bank}`);
|
27
28
|
}
|
29
|
+
function marginfiMaxLtvAndLiqThresholdBps(supplyBank, debtBank, supplyPrice) {
|
30
|
+
let maxLtv = (0, numberUtils_1.bytesToI80F48)(supplyBank.config.assetWeightInit.value) /
|
31
|
+
(0, numberUtils_1.bytesToI80F48)(debtBank.config.liabilityWeightInit.value);
|
32
|
+
const liqThreshold = (0, numberUtils_1.bytesToI80F48)(supplyBank.config.assetWeightMaint.value) /
|
33
|
+
(0, numberUtils_1.bytesToI80F48)(debtBank.config.liabilityWeightMaint.value);
|
34
|
+
const totalDepositedUsdValue = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round((0, numberUtils_1.bytesToI80F48)(supplyBank.totalAssetShares.value) *
|
35
|
+
(0, numberUtils_1.bytesToI80F48)(supplyBank.assetShareValue.value))), supplyBank.mintDecimals) * supplyPrice;
|
36
|
+
if (supplyBank.config.totalAssetValueInitLimit !== BigInt(0) &&
|
37
|
+
totalDepositedUsdValue > supplyBank.config.totalAssetValueInitLimit) {
|
38
|
+
const discount = Number(supplyBank.config.totalAssetValueInitLimit) /
|
39
|
+
totalDepositedUsdValue;
|
40
|
+
maxLtv = Math.round(maxLtv * Number(discount));
|
41
|
+
}
|
42
|
+
return [maxLtv, liqThreshold];
|
43
|
+
}
|
28
44
|
async function getMaxLtvAndLiqThreshold(umi, marginfiGroup, supply, debt, supplyPrice) {
|
29
45
|
if (!supply.bank && supply.mint.equals(web3_js_1.PublicKey.default)) {
|
30
46
|
return [0, 0];
|
@@ -45,19 +61,7 @@ async function getMaxLtvAndLiqThreshold(umi, marginfiGroup, supply, debt, supply
|
|
45
61
|
if (!debt.bank || debt.bank === null) {
|
46
62
|
return [0, 0];
|
47
63
|
}
|
48
|
-
|
49
|
-
(0, numberUtils_1.bytesToI80F48)(debt.bank.config.liabilityWeightInit.value);
|
50
|
-
const liqThreshold = (0, numberUtils_1.bytesToI80F48)(supply.bank.config.assetWeightMaint.value) /
|
51
|
-
(0, numberUtils_1.bytesToI80F48)(debt.bank.config.liabilityWeightMaint.value);
|
52
|
-
const totalDepositedUsdValue = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round((0, numberUtils_1.bytesToI80F48)(supply.bank.totalAssetShares.value) *
|
53
|
-
(0, numberUtils_1.bytesToI80F48)(supply.bank.assetShareValue.value))), supply.bank.mintDecimals) * supplyPrice;
|
54
|
-
if (supply.bank.config.totalAssetValueInitLimit !== BigInt(0) &&
|
55
|
-
totalDepositedUsdValue > supply.bank.config.totalAssetValueInitLimit) {
|
56
|
-
const discount = Number(supply.bank.config.totalAssetValueInitLimit) /
|
57
|
-
totalDepositedUsdValue;
|
58
|
-
maxLtv = Math.round(maxLtv * Number(discount));
|
59
|
-
}
|
60
|
-
return [maxLtv, liqThreshold];
|
64
|
+
return marginfiMaxLtvAndLiqThresholdBps(supply.bank, debt.bank, supplyPrice);
|
61
65
|
}
|
62
66
|
async function getAllMarginfiAccountsByAuthority(umi, authority, compatibleWithSolauto) {
|
63
67
|
const marginfiAccounts = await umi.rpc.getProgramAccounts(marginfi_sdk_1.MARGINFI_PROGRAM_ID, {
|
package/package.json
CHANGED
@@ -39,7 +39,6 @@ import {
|
|
39
39
|
getTokenAccount,
|
40
40
|
} from "../utils/accountUtils";
|
41
41
|
import { SOLAUTO_FEES_WALLET } from "../constants/generalAccounts";
|
42
|
-
import { JupSwapDetails } from "../utils/jupiterUtils";
|
43
42
|
import {
|
44
43
|
getWrappedInstruction,
|
45
44
|
splTokenTransferUmiIx,
|
@@ -56,6 +55,7 @@ import { TxHandler } from "./txHandler";
|
|
56
55
|
import { QuoteResponse } from "@jup-ag/api";
|
57
56
|
|
58
57
|
export interface SolautoClientArgs {
|
58
|
+
new?: boolean;
|
59
59
|
authority?: PublicKey;
|
60
60
|
positionId?: number;
|
61
61
|
signer?: Signer;
|
@@ -133,11 +133,11 @@ export abstract class SolautoClient extends TxHandler {
|
|
133
133
|
this.authority,
|
134
134
|
this.positionId
|
135
135
|
);
|
136
|
-
this.solautoPositionData = await safeFetchSolautoPosition(
|
136
|
+
this.solautoPositionData = !args.new ? await safeFetchSolautoPosition(
|
137
137
|
this.umi,
|
138
138
|
publicKey(this.solautoPosition),
|
139
139
|
{ commitment: "confirmed" }
|
140
|
-
);
|
140
|
+
) : null;
|
141
141
|
this.solautoPositionState = this.solautoPositionData?.state;
|
142
142
|
|
143
143
|
this.maxLtvBps = undefined;
|
@@ -96,7 +96,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
96
96
|
this.marginfiAccountSeedIdx = generateRandomU64();
|
97
97
|
this.marginfiAccount = this.solautoPositionData
|
98
98
|
? toWeb3JsPublicKey(this.solautoPositionData.position.protocolAccount)
|
99
|
-
:
|
99
|
+
: getMarginfiAccountPDA(
|
100
100
|
this.solautoPosition,
|
101
101
|
this.marginfiAccountSeedIdx
|
102
102
|
);
|
@@ -106,11 +106,13 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
106
106
|
? toWeb3JsPublicKey(this.marginfiAccount.publicKey)
|
107
107
|
: this.marginfiAccount;
|
108
108
|
|
109
|
-
const marginfiAccountData =
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
109
|
+
const marginfiAccountData = !args.new
|
110
|
+
? await safeFetchMarginfiAccount(
|
111
|
+
this.umi,
|
112
|
+
publicKey(this.marginfiAccountPk),
|
113
|
+
{ commitment: "confirmed" }
|
114
|
+
)
|
115
|
+
: null;
|
114
116
|
this.marginfiGroup = new PublicKey(
|
115
117
|
marginfiAccountData
|
116
118
|
? marginfiAccountData.group.toString()
|
@@ -126,29 +128,18 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
126
128
|
this.debtMint.toString()
|
127
129
|
]!;
|
128
130
|
|
129
|
-
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
131
|
+
// TODO: Don't dynamically pull oracle from bank until Marginfi sorts out their price oracle issues.
|
130
132
|
// const [supplyBank, debtBank] = await safeFetchAllBank(this.umi, [
|
131
133
|
// publicKey(this.marginfiSupplyAccounts.bank),
|
132
134
|
// publicKey(this.marginfiDebtAccounts.bank),
|
133
135
|
// ]);
|
134
136
|
// this.supplyPriceOracle = toWeb3JsPublicKey(supplyBank.config.oracleKeys[0]);
|
135
137
|
// this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
|
136
|
-
|
137
138
|
this.supplyPriceOracle = new PublicKey(
|
138
139
|
this.marginfiSupplyAccounts.priceOracle
|
139
140
|
);
|
140
141
|
this.debtPriceOracle = new PublicKey(this.marginfiDebtAccounts.priceOracle);
|
141
142
|
|
142
|
-
if (!this.solautoPositionState) {
|
143
|
-
const result = await this.maxLtvAndLiqThresholdBps()!;
|
144
|
-
this.solautoPositionState = createFakePositionState(
|
145
|
-
{ mint: this.supplyMint },
|
146
|
-
{ mint: this.debtMint },
|
147
|
-
result ? result[0] : 0,
|
148
|
-
result ? result[1] : 0
|
149
|
-
);
|
150
|
-
}
|
151
|
-
|
152
143
|
if (!this.initialized) {
|
153
144
|
await this.setIntermediaryMarginfiDetails();
|
154
145
|
}
|
@@ -60,7 +60,7 @@ export function getReferralState(authority: PublicKey) {
|
|
60
60
|
return ReferralState;
|
61
61
|
}
|
62
62
|
|
63
|
-
export
|
63
|
+
export function getMarginfiAccountPDA(
|
64
64
|
solautoPositionAccount: PublicKey,
|
65
65
|
marginfiAccountSeedIdx: bigint
|
66
66
|
) {
|
@@ -69,7 +69,7 @@ export async function getMarginfiAccountPDA(
|
|
69
69
|
bufferFromU64(marginfiAccountSeedIdx),
|
70
70
|
];
|
71
71
|
|
72
|
-
const [marginfiAccount, _] =
|
72
|
+
const [marginfiAccount, _] = PublicKey.findProgramAddressSync(
|
73
73
|
seeds,
|
74
74
|
new PublicKey(SOLAUTO_PROGRAM_ID)
|
75
75
|
);
|
@@ -20,7 +20,10 @@ import {
|
|
20
20
|
toBaseUnit,
|
21
21
|
toBps,
|
22
22
|
} from "./numberUtils";
|
23
|
-
import {
|
23
|
+
import {
|
24
|
+
DEFAULT_MARGINFI_GROUP,
|
25
|
+
MARGINFI_ACCOUNTS,
|
26
|
+
} from "../constants/marginfiAccounts";
|
24
27
|
import { MarginfiAssetAccounts } from "../types/accounts";
|
25
28
|
import { PositionState, PositionTokenUsage } from "../generated";
|
26
29
|
import { USD_DECIMALS } from "../constants/generalAccounts";
|
@@ -41,6 +44,41 @@ export function findMarginfiAccounts(bank: PublicKey): MarginfiAssetAccounts {
|
|
41
44
|
throw new Error(`Marginfi accounts not found by the bank: ${bank}`);
|
42
45
|
}
|
43
46
|
|
47
|
+
export function marginfiMaxLtvAndLiqThresholdBps(
|
48
|
+
supplyBank: Bank,
|
49
|
+
debtBank: Bank,
|
50
|
+
supplyPrice: number
|
51
|
+
): [number, number] {
|
52
|
+
let maxLtv =
|
53
|
+
bytesToI80F48(supplyBank.config.assetWeightInit.value) /
|
54
|
+
bytesToI80F48(debtBank.config.liabilityWeightInit.value);
|
55
|
+
const liqThreshold =
|
56
|
+
bytesToI80F48(supplyBank.config.assetWeightMaint.value) /
|
57
|
+
bytesToI80F48(debtBank.config.liabilityWeightMaint.value);
|
58
|
+
|
59
|
+
const totalDepositedUsdValue =
|
60
|
+
fromBaseUnit(
|
61
|
+
BigInt(
|
62
|
+
Math.round(
|
63
|
+
bytesToI80F48(supplyBank.totalAssetShares.value) *
|
64
|
+
bytesToI80F48(supplyBank.assetShareValue.value)
|
65
|
+
)
|
66
|
+
),
|
67
|
+
supplyBank.mintDecimals
|
68
|
+
) * supplyPrice!;
|
69
|
+
if (
|
70
|
+
supplyBank.config.totalAssetValueInitLimit !== BigInt(0) &&
|
71
|
+
totalDepositedUsdValue > supplyBank.config.totalAssetValueInitLimit
|
72
|
+
) {
|
73
|
+
const discount =
|
74
|
+
Number(supplyBank.config.totalAssetValueInitLimit) /
|
75
|
+
totalDepositedUsdValue;
|
76
|
+
maxLtv = Math.round(maxLtv * Number(discount));
|
77
|
+
}
|
78
|
+
|
79
|
+
return [maxLtv, liqThreshold];
|
80
|
+
}
|
81
|
+
|
44
82
|
export async function getMaxLtvAndLiqThreshold(
|
45
83
|
umi: Umi,
|
46
84
|
marginfiGroup: PublicKey,
|
@@ -61,7 +99,9 @@ export async function getMaxLtvAndLiqThreshold(
|
|
61
99
|
if (!supply.bank || supply.bank === null) {
|
62
100
|
supply.bank = await safeFetchBank(
|
63
101
|
umi,
|
64
|
-
publicKey(
|
102
|
+
publicKey(
|
103
|
+
MARGINFI_ACCOUNTS[marginfiGroup.toString()][supply.mint.toString()].bank
|
104
|
+
),
|
65
105
|
{ commitment: "confirmed" }
|
66
106
|
);
|
67
107
|
}
|
@@ -72,7 +112,9 @@ export async function getMaxLtvAndLiqThreshold(
|
|
72
112
|
) {
|
73
113
|
debt.bank = await safeFetchBank(
|
74
114
|
umi,
|
75
|
-
publicKey(
|
115
|
+
publicKey(
|
116
|
+
MARGINFI_ACCOUNTS[marginfiGroup.toString()][debt.mint.toString()].bank
|
117
|
+
),
|
76
118
|
{ commitment: "confirmed" }
|
77
119
|
);
|
78
120
|
}
|
@@ -88,34 +130,7 @@ export async function getMaxLtvAndLiqThreshold(
|
|
88
130
|
return [0, 0];
|
89
131
|
}
|
90
132
|
|
91
|
-
|
92
|
-
bytesToI80F48(supply.bank!.config.assetWeightInit.value) /
|
93
|
-
bytesToI80F48(debt.bank.config.liabilityWeightInit.value);
|
94
|
-
const liqThreshold =
|
95
|
-
bytesToI80F48(supply.bank!.config.assetWeightMaint.value) /
|
96
|
-
bytesToI80F48(debt.bank.config.liabilityWeightMaint.value);
|
97
|
-
|
98
|
-
const totalDepositedUsdValue =
|
99
|
-
fromBaseUnit(
|
100
|
-
BigInt(
|
101
|
-
Math.round(
|
102
|
-
bytesToI80F48(supply.bank!.totalAssetShares.value) *
|
103
|
-
bytesToI80F48(supply.bank!.assetShareValue.value)
|
104
|
-
)
|
105
|
-
),
|
106
|
-
supply.bank!.mintDecimals
|
107
|
-
) * supplyPrice!;
|
108
|
-
if (
|
109
|
-
supply.bank!.config.totalAssetValueInitLimit !== BigInt(0) &&
|
110
|
-
totalDepositedUsdValue > supply.bank!.config.totalAssetValueInitLimit
|
111
|
-
) {
|
112
|
-
const discount =
|
113
|
-
Number(supply.bank!.config.totalAssetValueInitLimit) /
|
114
|
-
totalDepositedUsdValue;
|
115
|
-
maxLtv = Math.round(maxLtv * Number(discount));
|
116
|
-
}
|
117
|
-
|
118
|
-
return [maxLtv, liqThreshold];
|
133
|
+
return marginfiMaxLtvAndLiqThresholdBps(supply.bank!, debt.bank, supplyPrice);
|
119
134
|
}
|
120
135
|
|
121
136
|
export async function getAllMarginfiAccountsByAuthority(
|
@@ -266,7 +281,11 @@ export async function getMarginfiAccountPositionState(
|
|
266
281
|
supplyMint && supplyMint !== PublicKey.default
|
267
282
|
? await safeFetchBank(
|
268
283
|
umi,
|
269
|
-
publicKey(
|
284
|
+
publicKey(
|
285
|
+
MARGINFI_ACCOUNTS[marginfiGroup?.toString() ?? ""][
|
286
|
+
supplyMint.toString()
|
287
|
+
].bank
|
288
|
+
),
|
270
289
|
{ commitment: "confirmed" }
|
271
290
|
)
|
272
291
|
: null;
|
@@ -274,7 +293,11 @@ export async function getMarginfiAccountPositionState(
|
|
274
293
|
debtMint && debtMint !== PublicKey.default
|
275
294
|
? await safeFetchBank(
|
276
295
|
umi,
|
277
|
-
publicKey(
|
296
|
+
publicKey(
|
297
|
+
MARGINFI_ACCOUNTS[marginfiGroup?.toString() ?? ""][
|
298
|
+
debtMint.toString()
|
299
|
+
].bank
|
300
|
+
),
|
278
301
|
{ commitment: "confirmed" }
|
279
302
|
)
|
280
303
|
: null;
|
@@ -341,7 +364,11 @@ export async function getMarginfiAccountPositionState(
|
|
341
364
|
return undefined;
|
342
365
|
}
|
343
366
|
|
344
|
-
if (
|
367
|
+
if (
|
368
|
+
!toWeb3JsPublicKey(supplyBank.group).equals(
|
369
|
+
new PublicKey(DEFAULT_MARGINFI_GROUP)
|
370
|
+
)
|
371
|
+
) {
|
345
372
|
// Temporarily disabled for now
|
346
373
|
return undefined;
|
347
374
|
}
|