@haven-fi/solauto-sdk 1.0.672 → 1.0.673
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.
- package/README.md +1 -0
- package/dist/constants/generalConstants.d.ts +7 -0
- package/dist/constants/generalConstants.d.ts.map +1 -0
- package/dist/constants/generalConstants.js +10 -0
- package/dist/constants/index.d.ts +7 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +22 -0
- package/dist/constants/marginfiAccounts.d.ts +17 -0
- package/dist/constants/marginfiAccounts.d.ts.map +1 -0
- package/dist/constants/marginfiAccounts.js +234 -0
- package/dist/constants/pythConstants.d.ts +24 -0
- package/dist/constants/pythConstants.d.ts.map +1 -0
- package/dist/constants/pythConstants.js +52 -0
- package/dist/constants/solautoConstants.d.ts +19 -0
- package/dist/constants/solautoConstants.d.ts.map +1 -0
- package/dist/constants/solautoConstants.js +40 -0
- package/dist/constants/switchboardConstants.d.ts +9 -0
- package/dist/constants/switchboardConstants.d.ts.map +1 -0
- package/dist/constants/switchboardConstants.js +54 -0
- package/dist/constants/tokenConstants.d.ts +40 -0
- package/dist/constants/tokenConstants.d.ts.map +1 -0
- package/dist/constants/tokenConstants.js +174 -0
- package/dist/idls/switchboard.json +1949 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts +3 -0
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.js +17 -0
- package/dist/utils/index.d.ts +14 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +29 -0
- package/dist/utils/switchboardUtils.d.ts +12 -0
- package/dist/utils/switchboardUtils.d.ts.map +1 -0
- package/dist/utils/switchboardUtils.js +81 -0
- package/package.json +1 -1
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +40 -0
- package/tests/transactions/shared.ts +2 -0
- package/tests/unit/rebalanceCalculations.ts +3 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./constants";
|
|
2
|
+
export * from "./generated/accounts";
|
|
3
|
+
export * from "./generated/instructions";
|
|
4
|
+
export * from "./generated/types";
|
|
5
|
+
export * from "./marginfi-sdk/accounts";
|
|
6
|
+
export * from "./marginfi-sdk/instructions";
|
|
7
|
+
export * from "./marginfi-sdk/types";
|
|
8
|
+
export * from "./services";
|
|
9
|
+
export * from "./solautoPosition";
|
|
10
|
+
export * from "./types";
|
|
11
|
+
export * from "./utils";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
|
18
|
+
__exportStar(require("./generated/accounts"), exports);
|
|
19
|
+
__exportStar(require("./generated/instructions"), exports);
|
|
20
|
+
__exportStar(require("./generated/types"), exports);
|
|
21
|
+
__exportStar(require("./marginfi-sdk/accounts"), exports);
|
|
22
|
+
__exportStar(require("./marginfi-sdk/instructions"), exports);
|
|
23
|
+
__exportStar(require("./marginfi-sdk/types"), exports);
|
|
24
|
+
__exportStar(require("./services"), exports);
|
|
25
|
+
__exportStar(require("./solautoPosition"), exports);
|
|
26
|
+
__exportStar(require("./types"), exports);
|
|
27
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -9,6 +9,9 @@ export declare class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
|
9
9
|
getBanks(): Promise<Bank[]>;
|
|
10
10
|
priceOracles(): Promise<PublicKey[]>;
|
|
11
11
|
maxLtvAndLiqThresholdBps(): Promise<[number, number]>;
|
|
12
|
+
private getUpToDateLiquidityAvailable;
|
|
13
|
+
updateSupplyLiquidityDepositable(banks: Bank[]): void;
|
|
14
|
+
updateDebtLiquidityAvailable(banks: Bank[]): void;
|
|
12
15
|
get supplyLiquidityAvailable(): number;
|
|
13
16
|
refreshPositionState(priceType?: PriceType): Promise<void>;
|
|
14
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAoB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAoB,MAAM,iBAAiB,CAAC;AAezD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE1D,qBAAa,yBAA0B,SAAQ,iBAAiB;IAC9D,eAAe,kBAA4B;IAE3C,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,QAAQ,CAAqB;IAE/B,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAgB3B,YAAY,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IASpC,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAa3D,OAAO,CAAC,6BAA6B;IAwBrC,gCAAgC,CAAC,KAAK,EAAE,IAAI,EAAE;IAK9C,4BAA4B,CAAC,KAAK,EAAE,IAAI,EAAE;IAQ1C,IAAI,wBAAwB,IAAI,MAAM,CAKrC;IAEK,oBAAoB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAuBjE"}
|
|
@@ -40,6 +40,23 @@ class MarginfiSolautoPositionEx extends solautoPositionEx_1.SolautoPositionEx {
|
|
|
40
40
|
const [maxLtvBps, liqThresholdBps] = (0, utils_1.calcMarginfiMaxLtvAndLiqThresholdBps)(supplyBank, debtBank, supplyPrice);
|
|
41
41
|
return [maxLtvBps, liqThresholdBps];
|
|
42
42
|
}
|
|
43
|
+
getUpToDateLiquidityAvailable(banks, mint, availableToDeposit) {
|
|
44
|
+
const bank = banks.find((x) => x.group.toString() === this.lpPoolAccount.toString() &&
|
|
45
|
+
x.mint.toString() === mint.toString());
|
|
46
|
+
const baseUnit = (0, utils_1.getBankLiquidityAvailableBaseUnit)(bank, availableToDeposit);
|
|
47
|
+
return {
|
|
48
|
+
baseUnit: baseUnit,
|
|
49
|
+
baseAmountUsdValue: (0, utils_1.toRoundedUsdValue)((0, utils_1.fromBaseUnit)(baseUnit, (0, utils_1.tokenInfo)(mint).decimals) *
|
|
50
|
+
((0, utils_1.safeGetPrice)(mint) ?? 0)),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
updateSupplyLiquidityDepositable(banks) {
|
|
54
|
+
this._data.state.supply.amountCanBeUsed =
|
|
55
|
+
this.getUpToDateLiquidityAvailable(banks, this.supplyMint, true);
|
|
56
|
+
}
|
|
57
|
+
updateDebtLiquidityAvailable(banks) {
|
|
58
|
+
this._data.state.debt.amountCanBeUsed = this.getUpToDateLiquidityAvailable(banks, this.debtMint, false);
|
|
59
|
+
}
|
|
43
60
|
get supplyLiquidityAvailable() {
|
|
44
61
|
return (0, utils_1.fromBaseUnit)((0, utils_1.getBankLiquidityAvailableBaseUnit)(this.supplyBank, false), this.supplyMintInfo.decimals);
|
|
45
62
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./accountUtils";
|
|
2
|
+
export * from "./generalUtils";
|
|
3
|
+
export * from "./instructionUtils";
|
|
4
|
+
export * from "./jitoUtils";
|
|
5
|
+
export * from "./jupiterUtils";
|
|
6
|
+
export * from "./marginfi";
|
|
7
|
+
export * from "./numberUtils";
|
|
8
|
+
export * from "./solautoUtils";
|
|
9
|
+
export * from "./solanaUtils";
|
|
10
|
+
export * from "./stringUtils";
|
|
11
|
+
export * from "./priceUtils";
|
|
12
|
+
export * from "./pythUtils";
|
|
13
|
+
export * from "./switchboardUtils";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./accountUtils"), exports);
|
|
18
|
+
__exportStar(require("./generalUtils"), exports);
|
|
19
|
+
__exportStar(require("./instructionUtils"), exports);
|
|
20
|
+
__exportStar(require("./jitoUtils"), exports);
|
|
21
|
+
__exportStar(require("./jupiterUtils"), exports);
|
|
22
|
+
__exportStar(require("./marginfi"), exports);
|
|
23
|
+
__exportStar(require("./numberUtils"), exports);
|
|
24
|
+
__exportStar(require("./solautoUtils"), exports);
|
|
25
|
+
__exportStar(require("./solanaUtils"), exports);
|
|
26
|
+
__exportStar(require("./stringUtils"), exports);
|
|
27
|
+
__exportStar(require("./priceUtils"), exports);
|
|
28
|
+
__exportStar(require("./pythUtils"), exports);
|
|
29
|
+
__exportStar(require("./switchboardUtils"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { Signer } from "@metaplex-foundation/umi";
|
|
3
|
+
import * as OnDemand from "@switchboard-xyz/on-demand";
|
|
4
|
+
import { TransactionItemInputs } from "../types";
|
|
5
|
+
export declare function getPullFeed(conn: Connection, mint: PublicKey, wallet?: PublicKey): OnDemand.PullFeed;
|
|
6
|
+
export declare function buildSwbSubmitResponseTx(conn: Connection, signer: Signer, mint: PublicKey): Promise<TransactionItemInputs | undefined>;
|
|
7
|
+
export declare function getSwitchboardFeedData(conn: Connection, mints: PublicKey[]): Promise<{
|
|
8
|
+
mint: PublicKey;
|
|
9
|
+
price: number;
|
|
10
|
+
stale: boolean;
|
|
11
|
+
}[]>;
|
|
12
|
+
//# sourceMappingURL=switchboardUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAsB,MAAM,0BAA0B,CAAC;AAGtE,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AAGvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAIjD,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,qBAuBnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsB5C;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,CAuB/D"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getPullFeed = getPullFeed;
|
|
30
|
+
exports.buildSwbSubmitResponseTx = buildSwbSubmitResponseTx;
|
|
31
|
+
exports.getSwitchboardFeedData = getSwitchboardFeedData;
|
|
32
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
33
|
+
const umi_1 = require("@metaplex-foundation/umi");
|
|
34
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
|
35
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
36
|
+
const OnDemand = __importStar(require("@switchboard-xyz/on-demand"));
|
|
37
|
+
const switchboard_json_1 = __importDefault(require("../idls/switchboard.json"));
|
|
38
|
+
const constants_1 = require("../constants");
|
|
39
|
+
const generalUtils_1 = require("./generalUtils");
|
|
40
|
+
const solanaUtils_1 = require("./solanaUtils");
|
|
41
|
+
function getPullFeed(conn, mint, wallet) {
|
|
42
|
+
const dummyWallet = {
|
|
43
|
+
publicKey: wallet ?? new web3_js_1.PublicKey("11111111111111111111111111111111"),
|
|
44
|
+
signTransaction: async (tx) => tx,
|
|
45
|
+
signAllTransactions: async (txs) => txs,
|
|
46
|
+
};
|
|
47
|
+
const provider = new anchor_1.AnchorProvider(conn, dummyWallet, anchor_1.AnchorProvider.defaultOptions());
|
|
48
|
+
const program = new anchor_1.Program(switchboard_json_1.default, provider);
|
|
49
|
+
const { PullFeed } = OnDemand;
|
|
50
|
+
return new PullFeed(program, new web3_js_1.PublicKey(constants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId));
|
|
51
|
+
}
|
|
52
|
+
async function buildSwbSubmitResponseTx(conn, signer, mint) {
|
|
53
|
+
const feed = getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
|
|
54
|
+
const [pullIx, responses] = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await feed.fetchUpdateIx({
|
|
55
|
+
chain: "solana",
|
|
56
|
+
network: "mainnet-beta",
|
|
57
|
+
}), 2, 200);
|
|
58
|
+
if (!pullIx) {
|
|
59
|
+
throw new Error("Unable to fetch SWB crank IX");
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
tx: (0, umi_1.transactionBuilder)([(0, solanaUtils_1.getWrappedInstruction)(signer, pullIx)]),
|
|
63
|
+
lookupTableAddresses: responses
|
|
64
|
+
.filter((x) => Boolean(x.oracle.lut?.key))
|
|
65
|
+
.map((x) => x.oracle.lut.key.toString()),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async function getSwitchboardFeedData(conn, mints) {
|
|
69
|
+
if (mints.length === 0) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const currSlot = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await conn.getSlot("confirmed"), 5);
|
|
73
|
+
const results = await Promise.all(mints.map(async (mint) => {
|
|
74
|
+
const feed = getPullFeed(conn, mint);
|
|
75
|
+
const result = await feed.loadData();
|
|
76
|
+
const price = Number(result.result.value) / Math.pow(10, 18);
|
|
77
|
+
const stale = currSlot > result.result.slot.toNumber() + result.maxStaleness;
|
|
78
|
+
return { mint, price, stale };
|
|
79
|
+
}));
|
|
80
|
+
return results;
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
getBankLiquidityAvailableBaseUnit,
|
|
9
9
|
getMarginfiAccountPositionState,
|
|
10
10
|
getMarginfiPriceOracle,
|
|
11
|
+
safeGetPrice,
|
|
12
|
+
tokenInfo,
|
|
13
|
+
toRoundedUsdValue,
|
|
11
14
|
validPubkey,
|
|
12
15
|
} from "../utils";
|
|
13
16
|
import { getMarginfiAccounts } from "../constants";
|
|
@@ -58,6 +61,43 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
|
58
61
|
return [maxLtvBps, liqThresholdBps];
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
private getUpToDateLiquidityAvailable(
|
|
65
|
+
banks: Bank[],
|
|
66
|
+
mint: PublicKey,
|
|
67
|
+
availableToDeposit: boolean
|
|
68
|
+
) {
|
|
69
|
+
const bank = banks.find(
|
|
70
|
+
(x) =>
|
|
71
|
+
x.group.toString() === this.lpPoolAccount.toString() &&
|
|
72
|
+
x.mint.toString() === mint.toString()
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const baseUnit = getBankLiquidityAvailableBaseUnit(
|
|
76
|
+
bank!,
|
|
77
|
+
availableToDeposit
|
|
78
|
+
);
|
|
79
|
+
return {
|
|
80
|
+
baseUnit: baseUnit,
|
|
81
|
+
baseAmountUsdValue: toRoundedUsdValue(
|
|
82
|
+
fromBaseUnit(baseUnit, tokenInfo(mint).decimals) *
|
|
83
|
+
(safeGetPrice(mint) ?? 0)
|
|
84
|
+
),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
updateSupplyLiquidityDepositable(banks: Bank[]) {
|
|
89
|
+
this._data.state.supply.amountCanBeUsed =
|
|
90
|
+
this.getUpToDateLiquidityAvailable(banks, this.supplyMint, true);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
updateDebtLiquidityAvailable(banks: Bank[]) {
|
|
94
|
+
this._data.state.debt.amountCanBeUsed = this.getUpToDateLiquidityAvailable(
|
|
95
|
+
banks,
|
|
96
|
+
this.debtMint,
|
|
97
|
+
false
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
61
101
|
get supplyLiquidityAvailable(): number {
|
|
62
102
|
return fromBaseUnit(
|
|
63
103
|
getBankLiquidityAvailableBaseUnit(this.supplyBank, false),
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
rebalance,
|
|
22
22
|
withdraw,
|
|
23
23
|
closeSolautoPosition,
|
|
24
|
+
getMarginfiAccounts,
|
|
24
25
|
} from "../../src";
|
|
25
26
|
|
|
26
27
|
export async function e2eTransactionTest(
|
|
@@ -42,6 +43,7 @@ export async function e2eTransactionTest(
|
|
|
42
43
|
|
|
43
44
|
await client.initialize({
|
|
44
45
|
positionId: 1,
|
|
46
|
+
lpPoolAccount: getMarginfiAccounts().defaultGroup,
|
|
45
47
|
supplyMint,
|
|
46
48
|
debtMint,
|
|
47
49
|
});
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
SolautoFeesBps,
|
|
21
21
|
createFakePositionState,
|
|
22
22
|
MarginfiSolautoPositionEx,
|
|
23
|
+
getMarginfiAccounts,
|
|
23
24
|
} from "../../src";
|
|
24
25
|
|
|
25
26
|
const signer = setupTest(undefined, true);
|
|
@@ -65,6 +66,7 @@ async function getFakePosition(
|
|
|
65
66
|
});
|
|
66
67
|
await client.initialize({
|
|
67
68
|
positionId: 1,
|
|
69
|
+
lpPoolAccount: getMarginfiAccounts().defaultGroup,
|
|
68
70
|
supplyMint: new PublicKey(NATIVE_MINT),
|
|
69
71
|
debtMint: new PublicKey(USDC),
|
|
70
72
|
});
|
|
@@ -105,8 +107,8 @@ async function getFakePosition(
|
|
|
105
107
|
lpUserAccount: defaultPk,
|
|
106
108
|
lpSupplyAccount: defaultPk,
|
|
107
109
|
lpDebtAccount: defaultPk,
|
|
110
|
+
lpPoolAccount: defaultPk,
|
|
108
111
|
settings,
|
|
109
|
-
dca: null,
|
|
110
112
|
padding: [],
|
|
111
113
|
padding1: [],
|
|
112
114
|
},
|