@haven-fi/solauto-sdk 1.0.670 → 1.0.671
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/dist/generated/types/positionData.d.ts +3 -3
- package/dist/generated/types/positionData.d.ts.map +1 -1
- package/dist/generated/types/positionData.js +2 -2
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceTxBuilder.js +3 -0
- package/dist/services/solauto/solautoClient.d.ts +1 -1
- package/dist/services/solauto/solautoClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoClient.js +2 -5
- package/dist/services/solauto/solautoMarginfiClient.js +1 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts +0 -2
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.js +3 -17
- package/dist/solautoPosition/positionUtils.d.ts.map +1 -1
- package/dist/solautoPosition/positionUtils.js +6 -1
- package/dist/solautoPosition/solautoPositionEx.d.ts +4 -4
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/solautoPositionEx.js +13 -7
- package/dist/utils/marginfi/data.d.ts +2 -2
- package/dist/utils/marginfi/data.d.ts.map +1 -1
- package/dist/utils/marginfi/data.js +6 -2
- package/local/txSandbox.ts +67 -12
- package/package.json +1 -1
- package/src/generated/types/positionData.ts +4 -7
- package/src/services/rebalance/rebalanceTxBuilder.ts +4 -0
- package/src/services/solauto/solautoClient.ts +3 -6
- package/src/services/solauto/solautoMarginfiClient.ts +1 -1
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +4 -32
- package/src/solautoPosition/positionUtils.ts +8 -1
- package/src/solautoPosition/solautoPositionEx.ts +19 -11
- package/src/utils/marginfi/data.ts +16 -7
@@ -7,7 +7,7 @@
|
|
7
7
|
*/
|
8
8
|
import { PublicKey } from '@metaplex-foundation/umi';
|
9
9
|
import { Serializer } from '@metaplex-foundation/umi/serializers';
|
10
|
-
import {
|
10
|
+
import { LendingPlatform, LendingPlatformArgs, SolautoSettingsParameters, SolautoSettingsParametersArgs } from '.';
|
11
11
|
export type PositionData = {
|
12
12
|
lendingPlatform: LendingPlatform;
|
13
13
|
padding1: Array<number>;
|
@@ -15,7 +15,7 @@ export type PositionData = {
|
|
15
15
|
lpSupplyAccount: PublicKey;
|
16
16
|
lpDebtAccount: PublicKey;
|
17
17
|
settings: SolautoSettingsParameters;
|
18
|
-
|
18
|
+
lpPoolAccount: PublicKey;
|
19
19
|
padding: Array<number>;
|
20
20
|
};
|
21
21
|
export type PositionDataArgs = {
|
@@ -25,7 +25,7 @@ export type PositionDataArgs = {
|
|
25
25
|
lpSupplyAccount: PublicKey;
|
26
26
|
lpDebtAccount: PublicKey;
|
27
27
|
settings: SolautoSettingsParametersArgs;
|
28
|
-
|
28
|
+
lpPoolAccount: PublicKey;
|
29
29
|
padding: Array<number>;
|
30
30
|
};
|
31
31
|
export declare function getPositionDataSerializer(): Serializer<PositionDataArgs, PositionData>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"positionData.d.ts","sourceRoot":"","sources":["../../../src/generated/types/positionData.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EACL,UAAU,EAMX,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,
|
1
|
+
{"version":3,"file":"positionData.d.ts","sourceRoot":"","sources":["../../../src/generated/types/positionData.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EACL,UAAU,EAMX,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EACzB,6BAA6B,EAG9B,MAAM,GAAG,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG;IACzB,eAAe,EAAE,eAAe,CAAC;IACjC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACxB,aAAa,EAAE,SAAS,CAAC;IACzB,eAAe,EAAE,SAAS,CAAC;IAC3B,aAAa,EAAE,SAAS,CAAC;IACzB,QAAQ,EAAE,yBAAyB,CAAC;IACpC,aAAa,EAAE,SAAS,CAAC;IACzB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,eAAe,EAAE,mBAAmB,CAAC;IACrC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACxB,aAAa,EAAE,SAAS,CAAC;IACzB,eAAe,EAAE,SAAS,CAAC;IAC3B,aAAa,EAAE,SAAS,CAAC;IACzB,QAAQ,EAAE,6BAA6B,CAAC;IACxC,aAAa,EAAE,SAAS,CAAC;IACzB,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACxB,CAAC;AAEF,wBAAgB,yBAAyB,IAAI,UAAU,CACrD,gBAAgB,EAChB,YAAY,CACb,CAcA"}
|
@@ -18,7 +18,7 @@ function getPositionDataSerializer() {
|
|
18
18
|
['lpSupplyAccount', (0, serializers_1.publicKey)()],
|
19
19
|
['lpDebtAccount', (0, serializers_1.publicKey)()],
|
20
20
|
['settings', (0, _1.getSolautoSettingsParametersSerializer)()],
|
21
|
-
['
|
22
|
-
['padding', (0, serializers_1.array)((0, serializers_1.u32)(), { size:
|
21
|
+
['lpPoolAccount', (0, serializers_1.publicKey)()],
|
22
|
+
['padding', (0, serializers_1.array)((0, serializers_1.u32)(), { size: 20 })],
|
23
23
|
], { description: 'PositionData' });
|
24
24
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"rebalanceTxBuilder.d.ts","sourceRoot":"","sources":["../../../src/services/rebalance/rebalanceTxBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC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e9C"}
|
@@ -16,6 +16,9 @@ class RebalanceTxBuilder {
|
|
16
16
|
this.priceType = generated_1.PriceType.Realtime;
|
17
17
|
}
|
18
18
|
shouldProceedWithRebalance() {
|
19
|
+
if (this.client.pos.selfManaged && !this.targetLiqUtilizationRateBps) {
|
20
|
+
throw new Error("A target rate must be provided for self managed position rebalances");
|
21
|
+
}
|
19
22
|
return (this.client.pos.supplyUsd() > 0 &&
|
20
23
|
(this.targetLiqUtilizationRateBps !== undefined ||
|
21
24
|
this.client.pos.eligibleForRebalance()));
|
@@ -11,7 +11,7 @@ export interface SolautoClientArgs extends ReferralStateManagerArgs {
|
|
11
11
|
positionId?: number;
|
12
12
|
supplyMint?: PublicKey;
|
13
13
|
debtMint?: PublicKey;
|
14
|
-
|
14
|
+
lpPoolAccount?: PublicKey;
|
15
15
|
lpUserAccount?: PublicKey;
|
16
16
|
}
|
17
17
|
export declare abstract class SolautoClient extends ReferralStateManager {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACL,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,kBAAkB,EAClB,eAAe,EACf,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,gCAAgC,EAEhC,sBAAsB,EAGvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAKL,cAAc,EACf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,C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AAW,CAClB,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,gBAAgB,GACrB,kBAAkB;CACtB"}
|
@@ -22,14 +22,11 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
22
22
|
this.pos = await (0, solautoPosition_1.getOrCreatePositionEx)(this.umi, this.authority, positionId, this.programId, {
|
23
23
|
supplyMint: args.supplyMint,
|
24
24
|
debtMint: args.debtMint,
|
25
|
-
|
25
|
+
lpPoolAccount: args.lpPoolAccount,
|
26
26
|
lpUserAccount: args.lpUserAccount,
|
27
27
|
lendingPlatform: this.lendingPlatform,
|
28
28
|
lpEnv: this.lpEnv,
|
29
29
|
}, this.contextUpdates);
|
30
|
-
if (this.pos.selfManaged) {
|
31
|
-
await this.pos.refreshPositionState();
|
32
|
-
}
|
33
30
|
this.positionSupplyTa = (0, utils_1.getTokenAccount)(this.pos.publicKey, this.pos.supplyMint);
|
34
31
|
this.signerSupplyTa = (0, utils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.pos.supplyMint);
|
35
32
|
this.positionDebtTa = (0, utils_1.getTokenAccount)(this.pos.publicKey, this.pos.debtMint);
|
@@ -46,9 +43,9 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
46
43
|
this.otherSigners.push(...this.flProvider.otherSigners());
|
47
44
|
this.log("Position state: ", this.pos.state);
|
48
45
|
this.log("Position settings: ", this.pos.settings);
|
49
|
-
this.log("Position DCA: ", this.pos.dca);
|
50
46
|
this.log("Supply mint:", this.pos.supplyMint.toString());
|
51
47
|
this.log("Debt mint:", this.pos.debtMint.toString());
|
48
|
+
this.log("LP pool:", this.pos.lpPoolAccount.toString());
|
52
49
|
}
|
53
50
|
referredBySupplyTa() {
|
54
51
|
if (this.referredByState !== undefined) {
|
@@ -20,7 +20,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
20
20
|
async initialize(args) {
|
21
21
|
await super.initialize(args);
|
22
22
|
this.mfiAccounts = (0, constants_1.getMarginfiAccounts)(this.lpEnv);
|
23
|
-
this.marginfiGroup =
|
23
|
+
this.marginfiGroup = this.pos.lpPoolAccount;
|
24
24
|
if (this.pos.selfManaged) {
|
25
25
|
this.marginfiAccount =
|
26
26
|
args.lpUserAccount ??
|
@@ -4,10 +4,8 @@ import { SolautoPositionEx } from "./solautoPositionEx";
|
|
4
4
|
import { LendingPlatform, PriceType } from "../generated";
|
5
5
|
export declare class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
6
6
|
lendingPlatform: LendingPlatform;
|
7
|
-
private marginfiAccountData;
|
8
7
|
private supplyBank;
|
9
8
|
private debtBank;
|
10
|
-
lendingPool(): Promise<PublicKey>;
|
11
9
|
getBanks(): Promise<Bank[]>;
|
12
10
|
priceOracles(): Promise<PublicKey[]>;
|
13
11
|
maxLtvAndLiqThresholdBps(): Promise<[number, number]>;
|
@@ -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,
|
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;AAYzD,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,IAAI,wBAAwB,IAAI,MAAM,CAKrC;IAEK,oBAAoB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAuBjE"}
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MarginfiSolautoPositionEx = void 0;
|
4
4
|
const marginfi_sdk_1 = require("../marginfi-sdk");
|
5
5
|
const umi_1 = require("@metaplex-foundation/umi");
|
6
|
-
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
7
6
|
const utils_1 = require("../utils");
|
8
7
|
const constants_1 = require("../constants");
|
9
8
|
const solautoPositionEx_1 = require("./solautoPositionEx");
|
@@ -12,26 +11,12 @@ class MarginfiSolautoPositionEx extends solautoPositionEx_1.SolautoPositionEx {
|
|
12
11
|
constructor() {
|
13
12
|
super(...arguments);
|
14
13
|
this.lendingPlatform = generated_1.LendingPlatform.Marginfi;
|
15
|
-
this.marginfiAccountData = null;
|
16
14
|
this.supplyBank = null;
|
17
15
|
this.debtBank = null;
|
18
16
|
}
|
19
|
-
async lendingPool() {
|
20
|
-
if (this.lp) {
|
21
|
-
return this.lp;
|
22
|
-
}
|
23
|
-
if (!this.marginfiAccountData && (0, utils_1.validPubkey)(this.lpUserAccount)) {
|
24
|
-
this.marginfiAccountData = await (0, marginfi_sdk_1.fetchMarginfiAccount)(this.umi, (0, umi_1.publicKey)(this.lpUserAccount), { commitment: "confirmed" });
|
25
|
-
this.lp = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.marginfiAccountData.group);
|
26
|
-
}
|
27
|
-
if (!this.lp) {
|
28
|
-
this.lp = (0, constants_1.getMarginfiAccounts)(this.lpEnv).defaultGroup;
|
29
|
-
}
|
30
|
-
return this.lp;
|
31
|
-
}
|
32
17
|
async getBanks() {
|
33
18
|
if (!this.supplyBank || !this.debtBank) {
|
34
|
-
const group =
|
19
|
+
const group = this.lpPoolAccount.toString();
|
35
20
|
const bankAccounts = (0, constants_1.getMarginfiAccounts)(this.lpEnv).bankAccounts;
|
36
21
|
const supplyBank = bankAccounts[group][this.supplyMint.toString()].bank;
|
37
22
|
const debtBank = bankAccounts[group][this.debtMint.toString()].bank;
|
@@ -62,10 +47,11 @@ class MarginfiSolautoPositionEx extends solautoPositionEx_1.SolautoPositionEx {
|
|
62
47
|
const useDesignatedMint = !this.exists ||
|
63
48
|
!this.selfManaged ||
|
64
49
|
(this.selfManaged && !(0, utils_1.validPubkey)(this.lpUserAccount));
|
65
|
-
const resp = await (0, utils_1.getMarginfiAccountPositionState)(this.umi, { pk: this.lpUserAccount },
|
50
|
+
const resp = await (0, utils_1.getMarginfiAccountPositionState)(this.umi, { pk: this.lpUserAccount }, this._lpPoolAccount, useDesignatedMint ? { mint: this.supplyMint } : undefined, useDesignatedMint ? { mint: this.debtMint } : undefined, this.contextUpdates, priceType);
|
66
51
|
if (resp) {
|
67
52
|
this.supplyBank = resp.supplyBank;
|
68
53
|
this.debtBank = resp.debtBank;
|
54
|
+
this._lpPoolAccount = resp.marginfiGroup;
|
69
55
|
this._data.state = resp.state;
|
70
56
|
}
|
71
57
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"positionUtils.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/positionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAK/C,OAAO,EAEL,aAAa,EAGb,yBAAyB,EACzB,gCAAgC,EACjC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EASf,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,kBAAkB,EAElB,iBAAiB,EAClB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;AAED,UAAU,UAAU;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,GACtB,aAAa,CAgEf"}
|
@@ -55,11 +55,16 @@ async function getOrCreatePositionEx(umi, authority, positionId, programId, cust
|
|
55
55
|
customArgs,
|
56
56
|
contextUpdates,
|
57
57
|
};
|
58
|
+
let position;
|
58
59
|
switch (lendingPlatform) {
|
59
60
|
case generated_1.LendingPlatform.Marginfi:
|
60
|
-
|
61
|
+
position = new marginfiSolautoPositionEx_1.MarginfiSolautoPositionEx(args);
|
61
62
|
// TODO: PF
|
62
63
|
}
|
64
|
+
if (position.selfManaged) {
|
65
|
+
await position.refreshPositionState();
|
66
|
+
}
|
67
|
+
return position;
|
63
68
|
}
|
64
69
|
function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
|
65
70
|
const supplyDecimals = (0, utils_1.tokenInfo)(supply.mint).decimals;
|
@@ -8,7 +8,7 @@ export interface PositionCustomArgs {
|
|
8
8
|
lendingPlatform: LendingPlatform;
|
9
9
|
supplyMint?: PublicKey;
|
10
10
|
debtMint?: PublicKey;
|
11
|
-
|
11
|
+
lpPoolAccount?: PublicKey;
|
12
12
|
lpUserAccount?: PublicKey;
|
13
13
|
lpEnv?: ProgramEnv;
|
14
14
|
}
|
@@ -32,22 +32,22 @@ export declare abstract class SolautoPositionEx {
|
|
32
32
|
lendingPlatform: LendingPlatform;
|
33
33
|
positionId: number;
|
34
34
|
authority: PublicKey;
|
35
|
-
protected
|
36
|
-
protected lp?: PublicKey;
|
35
|
+
protected _lpPoolAccount?: PublicKey;
|
37
36
|
lpUserAccount?: PublicKey;
|
38
37
|
protected lpEnv: ProgramEnv;
|
39
38
|
private _supplyMint?;
|
40
39
|
private _debtMint?;
|
40
|
+
protected _data: SolautoPositionExData;
|
41
41
|
private readonly firstState;
|
42
42
|
private _supplyPrice?;
|
43
43
|
private _debtPrice?;
|
44
44
|
rebalance: PositionRebalanceHelper;
|
45
45
|
constructor(args: PositionExArgs);
|
46
|
-
abstract lendingPool(): Promise<PublicKey>;
|
47
46
|
get exists(): boolean;
|
48
47
|
get selfManaged(): boolean;
|
49
48
|
get positionType(): import("../generated").PositionType | undefined;
|
50
49
|
get strategyName(): string;
|
50
|
+
get lpPoolAccount(): PublicKey;
|
51
51
|
liqUtilizationRateBps(priceType?: PriceType): number;
|
52
52
|
protected get data(): SolautoPositionExData;
|
53
53
|
get state(): PositionState;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/solautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAK/C,OAAO,EACL,WAAW,EAEX,eAAe,EACf,aAAa,EACb,SAAS,EACT,eAAe,EACf,yBAAyB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAOL,cAAc,EAkBf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAMvD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,MAAM,WAAW,kBAAkB;IACjC,eAAe,EAAE,eAAe,CAAC;IACjC,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,
|
1
|
+
{"version":3,"file":"solautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/solautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iB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WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM;IA0BhC,mBAAmB;CAM1B;AAED,cAAM,uBAAuB;IACf,OAAO,CAAC,GAAG;gBAAH,GAAG,EAAE,iBAAiB;IAE1C,OAAO,CAAC,0BAA0B;IA0BlC,wBAAwB,CAAC,iBAAiB,EAAE,MAAM;IAqBlD,OAAO,CAAC,kBAAkB;IAwB1B,oBAAoB,CAClB,oBAAoB,EAAE,MAAM,EAC5B,eAAe,CAAC,EAAE,OAAO,GACxB,eAAe,GAAG,SAAS;CAwB/B"}
|
@@ -7,7 +7,6 @@ const utils_1 = require("../utils");
|
|
7
7
|
const rebalance_1 = require("../services/rebalance");
|
8
8
|
class SolautoPositionEx {
|
9
9
|
constructor(args) {
|
10
|
-
this.lp = undefined;
|
11
10
|
this.lpUserAccount = undefined;
|
12
11
|
this.umi = args.umi;
|
13
12
|
this.contextUpdates = args.contextUpdates;
|
@@ -16,15 +15,15 @@ class SolautoPositionEx {
|
|
16
15
|
(0, utils_1.getSolautoPositionAccount)(args.authority, args.positionId, args.programId);
|
17
16
|
this.positionId = args.positionId ?? args.data.positionId[0];
|
18
17
|
this.authority = args.authority ?? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(args.data.authority);
|
19
|
-
this.
|
20
|
-
this._debtMint = args.customArgs?.debtMint;
|
21
|
-
this.lp = args.customArgs?.lendingPool;
|
18
|
+
this._lpPoolAccount = args.customArgs?.lpPoolAccount;
|
22
19
|
this.lpUserAccount =
|
23
20
|
args.customArgs?.lpUserAccount ??
|
24
21
|
(args.data.position
|
25
22
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(args.data.position.lpUserAccount)
|
26
23
|
: undefined);
|
27
24
|
this.lpEnv = args.customArgs?.lpEnv ?? "Prod";
|
25
|
+
this._supplyMint = args.customArgs?.supplyMint;
|
26
|
+
this._debtMint = args.customArgs?.debtMint;
|
28
27
|
this._data = args.data;
|
29
28
|
this.firstState = { ...args.data.state };
|
30
29
|
this.rebalance = new PositionRebalanceHelper(this);
|
@@ -41,6 +40,10 @@ class SolautoPositionEx {
|
|
41
40
|
get strategyName() {
|
42
41
|
return (0, utils_1.solautoStrategyName)(this.supplyMint, this.debtMint);
|
43
42
|
}
|
43
|
+
get lpPoolAccount() {
|
44
|
+
return (this._lpPoolAccount ??
|
45
|
+
(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.data.position.lpPoolAccount));
|
46
|
+
}
|
44
47
|
liqUtilizationRateBps(priceType) {
|
45
48
|
return (0, utils_1.getLiqUtilzationRateBps)(this.supplyUsd(priceType), this.debtUsd(priceType), this.state.liqThresholdBps);
|
46
49
|
}
|
@@ -56,11 +59,14 @@ class SolautoPositionEx {
|
|
56
59
|
updateSettings(settings) {
|
57
60
|
this.data.position.settings = settings;
|
58
61
|
}
|
62
|
+
// TODO: DCA
|
59
63
|
get dca() {
|
60
|
-
return this.contextUpdates?.dca ?? this.data.position?.dca;
|
64
|
+
// return this.contextUpdates?.dca ?? this.data.position?.dca;
|
65
|
+
return undefined;
|
61
66
|
}
|
67
|
+
// TODO: DCA
|
62
68
|
updateDca(dca) {
|
63
|
-
this.data.position
|
69
|
+
// this.data.position!.dca = dca;
|
64
70
|
}
|
65
71
|
get supplyMint() {
|
66
72
|
return this._supplyMint ?? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.state.supply.mint);
|
@@ -241,7 +247,7 @@ class PositionRebalanceHelper {
|
|
241
247
|
return this.validRealtimePricesBoost(debtAdjustmentUsd);
|
242
248
|
}
|
243
249
|
eligibleForRebalance(bpsDistanceThreshold, skipExtraChecks) {
|
244
|
-
if (
|
250
|
+
if (this.pos.selfManaged || !this.pos.supplyUsd()) {
|
245
251
|
return undefined;
|
246
252
|
}
|
247
253
|
const realtimeLiqUtilRateBps = this.pos.liqUtilizationRateBps(generated_1.PriceType.Realtime);
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { Umi } from "@metaplex-foundation/umi";
|
3
|
-
import { ProgramEnv } from "../../types";
|
4
3
|
import { PositionState, PriceType } from "../../generated";
|
5
4
|
import { Bank, MarginfiAccount } from "../../marginfi-sdk";
|
6
5
|
import { ContextUpdates } from "../solautoUtils";
|
@@ -30,9 +29,10 @@ type BanksCache = {
|
|
30
29
|
export declare function getMarginfiAccountPositionState(umi: Umi, lpUserAccount: {
|
31
30
|
pk?: PublicKey;
|
32
31
|
data?: MarginfiAccount | null;
|
33
|
-
}, marginfiGroup?: PublicKey, supply?: BankSelection, debt?: BankSelection,
|
32
|
+
}, marginfiGroup?: PublicKey, supply?: BankSelection, debt?: BankSelection, contextUpdates?: ContextUpdates, priceType?: PriceType): Promise<{
|
34
33
|
supplyBank: Bank | null;
|
35
34
|
debtBank: Bank | null;
|
35
|
+
marginfiGroup: PublicKey;
|
36
36
|
state: PositionState;
|
37
37
|
} | undefined>;
|
38
38
|
export declare function calculateAnnualAPYs(bank: Bank): [number, number];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/utils/marginfi/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/utils/marginfi/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAG1D,OAAO,EAAE,aAAa,EAAsB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO/E,OAAO,EACL,IAAI,EAGJ,eAAe,EAIhB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAgBjD,wBAAsB,mCAAmC,CACvD,GA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,EACzB,MAAM,CAAC,EAAE,aAAa,EACtB,IAAI,CAAC,EAAE,aAAa,EACpB,cAAc,CAAC,EAAE,cAAc,EAC/B,SAAS,CAAC,EAAE,SAAS,GACpB,OAAO,CACN;IACE,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IACtB,aAAa,EAAE,SAAS,CAAC;IACzB,KAAK,EAAE,aAAa,CAAC;CACtB,GACD,SAAS,CACZ,CA+KA;AA+DD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,oBAU7C;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBnE"}
|
@@ -171,7 +171,7 @@ async function getBank(umi, data, marginfiGroup) {
|
|
171
171
|
? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)((0, constants_1.getMarginfiAccounts)(undefined, marginfiGroup).bankAccounts[marginfiGroup.toString()][mint].bank), { commitment: "confirmed" })
|
172
172
|
: null;
|
173
173
|
}
|
174
|
-
async function getMarginfiAccountPositionState(umi, lpUserAccount, marginfiGroup, supply, debt,
|
174
|
+
async function getMarginfiAccountPositionState(umi, lpUserAccount, marginfiGroup, supply, debt, contextUpdates, priceType) {
|
175
175
|
let marginfiAccount = lpUserAccount.data ??
|
176
176
|
((0, generalUtils_1.validPubkey)(lpUserAccount.pk)
|
177
177
|
? await (0, marginfi_sdk_1.safeFetchMarginfiAccount)(umi, (0, umi_1.publicKey)(lpUserAccount.pk), {
|
@@ -245,8 +245,11 @@ async function getMarginfiAccountPositionState(umi, lpUserAccount, marginfiGroup
|
|
245
245
|
if (!debtUsage) {
|
246
246
|
debtUsage = await getTokenUsage(debtBank, false, 0, contextUpdates?.debtAdjustment);
|
247
247
|
}
|
248
|
+
if (!marginfiGroup) {
|
249
|
+
marginfiGroup = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(supplyBank.group);
|
250
|
+
}
|
248
251
|
const supplyPrice = (0, priceUtils_1.safeGetPrice)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(supplyBank.mint));
|
249
|
-
let [maxLtvBps, liqThresholdBps] = await getMarginfiMaxLtvAndLiqThresholdBps(umi, marginfiGroup
|
252
|
+
let [maxLtvBps, liqThresholdBps] = await getMarginfiMaxLtvAndLiqThresholdBps(umi, marginfiGroup, {
|
250
253
|
mint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(supplyBank.mint),
|
251
254
|
bank: supplyBank,
|
252
255
|
}, {
|
@@ -258,6 +261,7 @@ async function getMarginfiAccountPositionState(umi, lpUserAccount, marginfiGroup
|
|
258
261
|
return {
|
259
262
|
supplyBank,
|
260
263
|
debtBank,
|
264
|
+
marginfiGroup,
|
261
265
|
state: {
|
262
266
|
liqUtilizationRateBps: (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, liqThresholdBps),
|
263
267
|
netWorth: {
|
package/local/txSandbox.ts
CHANGED
@@ -3,15 +3,21 @@ import { createSignerFromKeypair } from "@metaplex-foundation/umi";
|
|
3
3
|
import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
|
4
4
|
import {
|
5
5
|
consoleLog,
|
6
|
+
getBatches,
|
6
7
|
getClient,
|
8
|
+
getPositionExBulk,
|
7
9
|
getSolanaRpcConnection,
|
10
|
+
getSolautoManagedPositions,
|
8
11
|
LendingPlatform,
|
9
12
|
LOCAL_IRONFORGE_API_URL,
|
13
|
+
PriceType,
|
10
14
|
PriorityFeeSetting,
|
11
15
|
ProgramEnv,
|
12
16
|
rebalance,
|
13
17
|
SOLAUTO_PROD_PROGRAM,
|
14
18
|
SOLAUTO_TEST_PROGRAM,
|
19
|
+
SolautoClient,
|
20
|
+
TransactionItem,
|
15
21
|
TransactionsManager,
|
16
22
|
} from "../src";
|
17
23
|
import { getSecretKey } from "./shared";
|
@@ -20,18 +26,18 @@ const payForTransaction = false;
|
|
20
26
|
const testProgram = false;
|
21
27
|
const lpEnv: ProgramEnv = "Prod";
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
);
|
29
|
+
let [, umi] = getSolanaRpcConnection(
|
30
|
+
LOCAL_IRONFORGE_API_URL,
|
31
|
+
testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM,
|
32
|
+
lpEnv
|
33
|
+
);
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
35
|
+
const signer = createSignerFromKeypair(
|
36
|
+
umi,
|
37
|
+
fromWeb3JsKeypair(Keypair.fromSecretKey(getSecretKey()))
|
38
|
+
);
|
34
39
|
|
40
|
+
export async function main() {
|
35
41
|
const client = getClient(LendingPlatform.Marginfi, {
|
36
42
|
signer,
|
37
43
|
showLogs: true,
|
@@ -41,7 +47,7 @@ export async function main() {
|
|
41
47
|
});
|
42
48
|
|
43
49
|
await client.initialize({
|
44
|
-
positionId:
|
50
|
+
positionId: 2,
|
45
51
|
authority: new PublicKey("5UqsR2PGzbP8pGPbXEeXx86Gjz2N2UFBAuFZUSVydAEe"),
|
46
52
|
// lpUserAccount: new PublicKey(
|
47
53
|
// "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
|
@@ -60,8 +66,57 @@ export async function main() {
|
|
60
66
|
{ totalRetries: 5 }
|
61
67
|
);
|
62
68
|
const statuses = await txManager.clientSend(transactionItems);
|
63
|
-
|
64
69
|
consoleLog(statuses);
|
65
70
|
}
|
66
71
|
|
72
|
+
async function refreshAll() {
|
73
|
+
const allPositions = await getSolautoManagedPositions(umi);
|
74
|
+
const positions = await getPositionExBulk(
|
75
|
+
umi,
|
76
|
+
allPositions.map((x) => new PublicKey(x.publicKey!))
|
77
|
+
);
|
78
|
+
|
79
|
+
let client: SolautoClient | undefined;
|
80
|
+
const transactionItems: TransactionItem[] = [];
|
81
|
+
for (const pos of positions) {
|
82
|
+
client = getClient(pos.lendingPlatform, {
|
83
|
+
signer,
|
84
|
+
showLogs: true,
|
85
|
+
rpcUrl: LOCAL_IRONFORGE_API_URL,
|
86
|
+
programId: testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM,
|
87
|
+
lpEnv,
|
88
|
+
});
|
89
|
+
|
90
|
+
await client!.initialize({
|
91
|
+
positionId: pos.positionId,
|
92
|
+
authority: pos.authority,
|
93
|
+
});
|
94
|
+
|
95
|
+
const ix = client!.refreshIx(PriceType.Realtime);
|
96
|
+
transactionItems.push(
|
97
|
+
new TransactionItem(
|
98
|
+
async () => ({ tx: ix }),
|
99
|
+
`refresh ${pos.authority} (${pos.positionId})`
|
100
|
+
)
|
101
|
+
);
|
102
|
+
}
|
103
|
+
|
104
|
+
const txBatches = getBatches(transactionItems, 15);
|
105
|
+
|
106
|
+
for (const batch of txBatches) {
|
107
|
+
const txManager = new TransactionsManager(
|
108
|
+
client!,
|
109
|
+
undefined,
|
110
|
+
payForTransaction ? "normal" : "only-simulate",
|
111
|
+
PriorityFeeSetting.High,
|
112
|
+
true,
|
113
|
+
undefined,
|
114
|
+
{ totalRetries: 5 }
|
115
|
+
);
|
116
|
+
const statuses = await txManager.send(batch);
|
117
|
+
consoleLog(statuses);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
67
121
|
main();
|
122
|
+
// refreshAll();
|
package/package.json
CHANGED
@@ -16,13 +16,10 @@ import {
|
|
16
16
|
u8,
|
17
17
|
} from '@metaplex-foundation/umi/serializers';
|
18
18
|
import {
|
19
|
-
DCASettings,
|
20
|
-
DCASettingsArgs,
|
21
19
|
LendingPlatform,
|
22
20
|
LendingPlatformArgs,
|
23
21
|
SolautoSettingsParameters,
|
24
22
|
SolautoSettingsParametersArgs,
|
25
|
-
getDCASettingsSerializer,
|
26
23
|
getLendingPlatformSerializer,
|
27
24
|
getSolautoSettingsParametersSerializer,
|
28
25
|
} from '.';
|
@@ -34,7 +31,7 @@ export type PositionData = {
|
|
34
31
|
lpSupplyAccount: PublicKey;
|
35
32
|
lpDebtAccount: PublicKey;
|
36
33
|
settings: SolautoSettingsParameters;
|
37
|
-
|
34
|
+
lpPoolAccount: PublicKey;
|
38
35
|
padding: Array<number>;
|
39
36
|
};
|
40
37
|
|
@@ -45,7 +42,7 @@ export type PositionDataArgs = {
|
|
45
42
|
lpSupplyAccount: PublicKey;
|
46
43
|
lpDebtAccount: PublicKey;
|
47
44
|
settings: SolautoSettingsParametersArgs;
|
48
|
-
|
45
|
+
lpPoolAccount: PublicKey;
|
49
46
|
padding: Array<number>;
|
50
47
|
};
|
51
48
|
|
@@ -61,8 +58,8 @@ export function getPositionDataSerializer(): Serializer<
|
|
61
58
|
['lpSupplyAccount', publicKeySerializer()],
|
62
59
|
['lpDebtAccount', publicKeySerializer()],
|
63
60
|
['settings', getSolautoSettingsParametersSerializer()],
|
64
|
-
['
|
65
|
-
['padding', array(u32(), { size:
|
61
|
+
['lpPoolAccount', publicKeySerializer()],
|
62
|
+
['padding', array(u32(), { size: 20 })],
|
66
63
|
],
|
67
64
|
{ description: 'PositionData' }
|
68
65
|
) as Serializer<PositionDataArgs, PositionData>;
|
@@ -46,6 +46,10 @@ export class RebalanceTxBuilder {
|
|
46
46
|
) {}
|
47
47
|
|
48
48
|
private shouldProceedWithRebalance() {
|
49
|
+
if (this.client.pos.selfManaged && !this.targetLiqUtilizationRateBps) {
|
50
|
+
throw new Error("A target rate must be provided for self managed position rebalances");
|
51
|
+
}
|
52
|
+
|
49
53
|
return (
|
50
54
|
this.client.pos.supplyUsd() > 0 &&
|
51
55
|
(this.targetLiqUtilizationRateBps !== undefined ||
|
@@ -44,7 +44,7 @@ export interface SolautoClientArgs extends ReferralStateManagerArgs {
|
|
44
44
|
positionId?: number;
|
45
45
|
supplyMint?: PublicKey;
|
46
46
|
debtMint?: PublicKey;
|
47
|
-
|
47
|
+
lpPoolAccount?: PublicKey;
|
48
48
|
lpUserAccount?: PublicKey;
|
49
49
|
}
|
50
50
|
|
@@ -85,16 +85,13 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
85
85
|
{
|
86
86
|
supplyMint: args.supplyMint,
|
87
87
|
debtMint: args.debtMint,
|
88
|
-
|
88
|
+
lpPoolAccount: args.lpPoolAccount,
|
89
89
|
lpUserAccount: args.lpUserAccount,
|
90
90
|
lendingPlatform: this.lendingPlatform,
|
91
91
|
lpEnv: this.lpEnv,
|
92
92
|
},
|
93
93
|
this.contextUpdates
|
94
94
|
);
|
95
|
-
if (this.pos.selfManaged) {
|
96
|
-
await this.pos.refreshPositionState();
|
97
|
-
}
|
98
95
|
|
99
96
|
this.positionSupplyTa = getTokenAccount(
|
100
97
|
this.pos.publicKey,
|
@@ -144,9 +141,9 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
144
141
|
|
145
142
|
this.log("Position state: ", this.pos.state);
|
146
143
|
this.log("Position settings: ", this.pos.settings);
|
147
|
-
this.log("Position DCA: ", this.pos.dca);
|
148
144
|
this.log("Supply mint:", this.pos.supplyMint.toString());
|
149
145
|
this.log("Debt mint:", this.pos.debtMint.toString());
|
146
|
+
this.log("LP pool:", this.pos.lpPoolAccount.toString());
|
150
147
|
}
|
151
148
|
|
152
149
|
referredBySupplyTa(): PublicKey | undefined {
|
@@ -75,7 +75,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
75
75
|
|
76
76
|
this.mfiAccounts = getMarginfiAccounts(this.lpEnv);
|
77
77
|
|
78
|
-
this.marginfiGroup =
|
78
|
+
this.marginfiGroup = this.pos.lpPoolAccount;
|
79
79
|
|
80
80
|
if (this.pos.selfManaged) {
|
81
81
|
this.marginfiAccount =
|
@@ -1,12 +1,6 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import {
|
3
|
-
Bank,
|
4
|
-
fetchMarginfiAccount,
|
5
|
-
MarginfiAccount,
|
6
|
-
safeFetchAllBank,
|
7
|
-
} from "../marginfi-sdk";
|
2
|
+
import { Bank, safeFetchAllBank } from "../marginfi-sdk";
|
8
3
|
import { publicKey } from "@metaplex-foundation/umi";
|
9
|
-
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
10
4
|
import {
|
11
5
|
calcMarginfiMaxLtvAndLiqThresholdBps,
|
12
6
|
fetchTokenPrices,
|
@@ -23,34 +17,12 @@ import { LendingPlatform, PriceType } from "../generated";
|
|
23
17
|
export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
24
18
|
lendingPlatform = LendingPlatform.Marginfi;
|
25
19
|
|
26
|
-
private marginfiAccountData: MarginfiAccount | null = null;
|
27
20
|
private supplyBank: Bank | null = null;
|
28
21
|
private debtBank: Bank | null = null;
|
29
22
|
|
30
|
-
public async lendingPool(): Promise<PublicKey> {
|
31
|
-
if (this.lp) {
|
32
|
-
return this.lp;
|
33
|
-
}
|
34
|
-
|
35
|
-
if (!this.marginfiAccountData && validPubkey(this.lpUserAccount)) {
|
36
|
-
this.marginfiAccountData = await fetchMarginfiAccount(
|
37
|
-
this.umi,
|
38
|
-
publicKey(this.lpUserAccount!),
|
39
|
-
{ commitment: "confirmed" }
|
40
|
-
);
|
41
|
-
this.lp = toWeb3JsPublicKey(this.marginfiAccountData.group);
|
42
|
-
}
|
43
|
-
|
44
|
-
if (!this.lp) {
|
45
|
-
this.lp = getMarginfiAccounts(this.lpEnv).defaultGroup;
|
46
|
-
}
|
47
|
-
|
48
|
-
return this.lp;
|
49
|
-
}
|
50
|
-
|
51
23
|
async getBanks(): Promise<Bank[]> {
|
52
24
|
if (!this.supplyBank || !this.debtBank) {
|
53
|
-
const group =
|
25
|
+
const group = this.lpPoolAccount.toString();
|
54
26
|
const bankAccounts = getMarginfiAccounts(this.lpEnv).bankAccounts;
|
55
27
|
const supplyBank = bankAccounts[group][this.supplyMint.toString()].bank;
|
56
28
|
const debtBank = bankAccounts[group][this.debtMint.toString()].bank;
|
@@ -102,10 +74,9 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
102
74
|
const resp = await getMarginfiAccountPositionState(
|
103
75
|
this.umi,
|
104
76
|
{ pk: this.lpUserAccount },
|
105
|
-
|
77
|
+
this._lpPoolAccount,
|
106
78
|
useDesignatedMint ? { mint: this.supplyMint } : undefined,
|
107
79
|
useDesignatedMint ? { mint: this.debtMint } : undefined,
|
108
|
-
this.lpEnv,
|
109
80
|
this.contextUpdates,
|
110
81
|
priceType
|
111
82
|
);
|
@@ -113,6 +84,7 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
113
84
|
if (resp) {
|
114
85
|
this.supplyBank = resp.supplyBank;
|
115
86
|
this.debtBank = resp.debtBank;
|
87
|
+
this._lpPoolAccount = resp.marginfiGroup;
|
116
88
|
this._data.state = resp.state;
|
117
89
|
}
|
118
90
|
}
|
@@ -113,11 +113,18 @@ export async function getOrCreatePositionEx(
|
|
113
113
|
contextUpdates,
|
114
114
|
};
|
115
115
|
|
116
|
+
let position: SolautoPositionEx;
|
116
117
|
switch (lendingPlatform) {
|
117
118
|
case LendingPlatform.Marginfi:
|
118
|
-
|
119
|
+
position = new MarginfiSolautoPositionEx(args);
|
119
120
|
// TODO: PF
|
120
121
|
}
|
122
|
+
|
123
|
+
if (position.selfManaged) {
|
124
|
+
await position.refreshPositionState();
|
125
|
+
}
|
126
|
+
|
127
|
+
return position;
|
121
128
|
}
|
122
129
|
|
123
130
|
interface AssetProps {
|
@@ -51,7 +51,7 @@ export interface PositionCustomArgs {
|
|
51
51
|
lendingPlatform: LendingPlatform;
|
52
52
|
supplyMint?: PublicKey;
|
53
53
|
debtMint?: PublicKey;
|
54
|
-
|
54
|
+
lpPoolAccount?: PublicKey;
|
55
55
|
lpUserAccount?: PublicKey;
|
56
56
|
lpEnv?: ProgramEnv;
|
57
57
|
}
|
@@ -79,12 +79,12 @@ export abstract class SolautoPositionEx {
|
|
79
79
|
public lendingPlatform!: LendingPlatform;
|
80
80
|
public positionId!: number;
|
81
81
|
public authority!: PublicKey;
|
82
|
-
protected
|
83
|
-
protected lp?: PublicKey = undefined;
|
82
|
+
protected _lpPoolAccount?: PublicKey;
|
84
83
|
public lpUserAccount?: PublicKey = undefined;
|
85
84
|
protected lpEnv!: ProgramEnv;
|
86
85
|
private _supplyMint?: PublicKey;
|
87
86
|
private _debtMint?: PublicKey;
|
87
|
+
protected _data!: SolautoPositionExData;
|
88
88
|
|
89
89
|
private readonly firstState!: PositionState;
|
90
90
|
|
@@ -107,15 +107,15 @@ export abstract class SolautoPositionEx {
|
|
107
107
|
this.positionId = args.positionId ?? args.data.positionId![0];
|
108
108
|
this.authority = args.authority ?? toWeb3JsPublicKey(args.data.authority!);
|
109
109
|
|
110
|
-
this.
|
111
|
-
this._debtMint = args.customArgs?.debtMint;
|
112
|
-
this.lp = args.customArgs?.lendingPool;
|
110
|
+
this._lpPoolAccount = args.customArgs?.lpPoolAccount;
|
113
111
|
this.lpUserAccount =
|
114
112
|
args.customArgs?.lpUserAccount ??
|
115
113
|
(args.data.position
|
116
114
|
? toWeb3JsPublicKey(args.data.position!.lpUserAccount)
|
117
115
|
: undefined);
|
118
116
|
this.lpEnv = args.customArgs?.lpEnv ?? "Prod";
|
117
|
+
this._supplyMint = args.customArgs?.supplyMint;
|
118
|
+
this._debtMint = args.customArgs?.debtMint;
|
119
119
|
|
120
120
|
this._data = args.data;
|
121
121
|
this.firstState = { ...args.data.state };
|
@@ -123,8 +123,6 @@ export abstract class SolautoPositionEx {
|
|
123
123
|
this.rebalance = new PositionRebalanceHelper(this);
|
124
124
|
}
|
125
125
|
|
126
|
-
abstract lendingPool(): Promise<PublicKey>;
|
127
|
-
|
128
126
|
get exists() {
|
129
127
|
return this._data.position !== undefined;
|
130
128
|
}
|
@@ -141,6 +139,13 @@ export abstract class SolautoPositionEx {
|
|
141
139
|
return solautoStrategyName(this.supplyMint, this.debtMint);
|
142
140
|
}
|
143
141
|
|
142
|
+
get lpPoolAccount() {
|
143
|
+
return (
|
144
|
+
this._lpPoolAccount ??
|
145
|
+
toWeb3JsPublicKey(this.data.position!.lpPoolAccount)
|
146
|
+
);
|
147
|
+
}
|
148
|
+
|
144
149
|
liqUtilizationRateBps(priceType?: PriceType): number {
|
145
150
|
return getLiqUtilzationRateBps(
|
146
151
|
this.supplyUsd(priceType),
|
@@ -165,12 +170,15 @@ export abstract class SolautoPositionEx {
|
|
165
170
|
this.data.position!.settings = settings;
|
166
171
|
}
|
167
172
|
|
173
|
+
// TODO: DCA
|
168
174
|
get dca(): DCASettings | undefined {
|
169
|
-
return this.contextUpdates?.dca ?? this.data.position?.dca;
|
175
|
+
// return this.contextUpdates?.dca ?? this.data.position?.dca;
|
176
|
+
return undefined;
|
170
177
|
}
|
171
178
|
|
179
|
+
// TODO: DCA
|
172
180
|
updateDca(dca: DCASettings) {
|
173
|
-
this.data.position!.dca = dca;
|
181
|
+
// this.data.position!.dca = dca;
|
174
182
|
}
|
175
183
|
|
176
184
|
get supplyMint(): PublicKey {
|
@@ -488,7 +496,7 @@ class PositionRebalanceHelper {
|
|
488
496
|
bpsDistanceThreshold: number,
|
489
497
|
skipExtraChecks?: boolean
|
490
498
|
): RebalanceAction | undefined {
|
491
|
-
if (
|
499
|
+
if (this.pos.selfManaged || !this.pos.supplyUsd()) {
|
492
500
|
return undefined;
|
493
501
|
}
|
494
502
|
|
@@ -1,8 +1,6 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { publicKey, Umi } from "@metaplex-foundation/umi";
|
3
|
-
import {
|
4
|
-
toWeb3JsPublicKey,
|
5
|
-
} from "@metaplex-foundation/umi-web3js-adapters";
|
3
|
+
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
6
4
|
import { ProgramEnv } from "../../types";
|
7
5
|
import { PositionState, PositionTokenState, PriceType } from "../../generated";
|
8
6
|
import {
|
@@ -31,7 +29,10 @@ import {
|
|
31
29
|
toBaseUnit,
|
32
30
|
toBps,
|
33
31
|
} from "../numberUtils";
|
34
|
-
import {
|
32
|
+
import {
|
33
|
+
calcMarginfiMaxLtvAndLiqThresholdBps,
|
34
|
+
marginfiAccountEmpty,
|
35
|
+
} from "./general";
|
35
36
|
|
36
37
|
export async function getMarginfiMaxLtvAndLiqThresholdBps(
|
37
38
|
umi: Umi,
|
@@ -309,11 +310,15 @@ export async function getMarginfiAccountPositionState(
|
|
309
310
|
marginfiGroup?: PublicKey,
|
310
311
|
supply?: BankSelection,
|
311
312
|
debt?: BankSelection,
|
312
|
-
programEnv?: ProgramEnv,
|
313
313
|
contextUpdates?: ContextUpdates,
|
314
314
|
priceType?: PriceType
|
315
315
|
): Promise<
|
316
|
-
| {
|
316
|
+
| {
|
317
|
+
supplyBank: Bank | null;
|
318
|
+
debtBank: Bank | null;
|
319
|
+
marginfiGroup: PublicKey;
|
320
|
+
state: PositionState;
|
321
|
+
}
|
317
322
|
| undefined
|
318
323
|
> {
|
319
324
|
let marginfiAccount =
|
@@ -437,10 +442,13 @@ export async function getMarginfiAccountPositionState(
|
|
437
442
|
);
|
438
443
|
}
|
439
444
|
|
445
|
+
if (!marginfiGroup) {
|
446
|
+
marginfiGroup = toWeb3JsPublicKey(supplyBank.group);
|
447
|
+
}
|
440
448
|
const supplyPrice = safeGetPrice(toWeb3JsPublicKey(supplyBank.mint))!;
|
441
449
|
let [maxLtvBps, liqThresholdBps] = await getMarginfiMaxLtvAndLiqThresholdBps(
|
442
450
|
umi,
|
443
|
-
marginfiGroup
|
451
|
+
marginfiGroup,
|
444
452
|
{
|
445
453
|
mint: toWeb3JsPublicKey(supplyBank.mint),
|
446
454
|
bank: supplyBank,
|
@@ -463,6 +471,7 @@ export async function getMarginfiAccountPositionState(
|
|
463
471
|
return {
|
464
472
|
supplyBank,
|
465
473
|
debtBank,
|
474
|
+
marginfiGroup,
|
466
475
|
state: {
|
467
476
|
liqUtilizationRateBps: getLiqUtilzationRateBps(
|
468
477
|
supplyUsd,
|