@haven-fi/solauto-sdk 1.0.10 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoClient.d.ts +4 -3
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +6 -5
- package/dist/clients/solautoMarginfiClient.d.ts +1 -1
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +2 -2
- package/dist/utils/solauto/generalUtils.d.ts +8 -1
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +24 -7
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +10 -11
- package/src/clients/solautoMarginfiClient.ts +2 -2
- package/src/utils/solauto/generalUtils.ts +46 -8
- package/tests/transactions/solautoMarginfi.ts +2 -3
@@ -17,7 +17,8 @@ export interface SolautoClientArgs {
|
|
17
17
|
referredByAuthority?: PublicKey;
|
18
18
|
}
|
19
19
|
export declare abstract class SolautoClient {
|
20
|
-
|
20
|
+
private heliusApiKey;
|
21
|
+
localTest?: boolean | undefined;
|
21
22
|
umi: Umi;
|
22
23
|
connection: Connection;
|
23
24
|
lendingPlatform: LendingPlatform;
|
@@ -46,8 +47,8 @@ export declare abstract class SolautoClient {
|
|
46
47
|
authorityLutAddress?: PublicKey;
|
47
48
|
upToDateLutAccounts: PublicKey[];
|
48
49
|
livePositionUpdates: LivePositionUpdates;
|
49
|
-
constructor(localTest?: boolean);
|
50
|
-
|
50
|
+
constructor(heliusApiKey: string, localTest?: boolean | undefined);
|
51
|
+
initialize(args: SolautoClientArgs, lendingPlatform: LendingPlatform): Promise<void>;
|
51
52
|
log(...args: any[]): void;
|
52
53
|
resetLivePositionUpdates(): Promise<void>;
|
53
54
|
defaultLookupTables(): string[];
|
@@ -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;
|
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,i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mB,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"}
|
@@ -16,17 +16,18 @@ const generalUtils_1 = require("../utils/generalUtils");
|
|
16
16
|
const generalUtils_2 = require("../utils/solauto/generalUtils");
|
17
17
|
const umi_bundle_defaults_1 = require("@metaplex-foundation/umi-bundle-defaults");
|
18
18
|
class SolautoClient {
|
19
|
-
constructor(localTest) {
|
19
|
+
constructor(heliusApiKey, localTest) {
|
20
|
+
this.heliusApiKey = heliusApiKey;
|
21
|
+
this.localTest = localTest;
|
20
22
|
this.livePositionUpdates = new generalUtils_2.LivePositionUpdates();
|
21
|
-
this.
|
22
|
-
}
|
23
|
-
async baseInitialize(args, lendingPlatform, heliusApiKey) {
|
24
|
-
this.connection = new web3_js_1.Connection(`https://mainnet.helius-rpc.com/?api-key=${heliusApiKey}`, "finalized");
|
23
|
+
this.connection = new web3_js_1.Connection(`https://mainnet.helius-rpc.com/?api-key=${this.heliusApiKey}`, "finalized");
|
25
24
|
this.umi = (0, umi_bundle_defaults_1.createUmi)(this.connection).use({
|
26
25
|
install(umi) {
|
27
26
|
umi.programs.add((0, generated_1.createSolautoProgram)(), false);
|
28
27
|
},
|
29
28
|
});
|
29
|
+
}
|
30
|
+
async initialize(args, lendingPlatform) {
|
30
31
|
if (!args.signer && !args.wallet) {
|
31
32
|
throw new Error("Signer or wallet must be provided");
|
32
33
|
}
|
@@ -24,7 +24,7 @@ export declare class SolautoMarginfiClient extends SolautoClient {
|
|
24
24
|
intermediaryMarginfiAccountSigner?: Signer;
|
25
25
|
intermediaryMarginfiAccountPk: PublicKey;
|
26
26
|
intermediaryMarginfiAccount?: MarginfiAccount;
|
27
|
-
initialize(args: SolautoMarginfiClientArgs
|
27
|
+
initialize(args: SolautoMarginfiClientArgs): Promise<void>;
|
28
28
|
defaultLookupTables(): string[];
|
29
29
|
lutAccountsToAdd(): PublicKey[];
|
30
30
|
openPosition(settingParams?: SolautoSettingsParametersInpArgs, dca?: DCASettingsInpArgs): TransactionBuilder;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAEL,SAAS,EAEV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAK1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAOhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAOnE,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,eAAe,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACrC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,aAAa,CAA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8DrC,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"}
|
@@ -25,11 +25,11 @@ function newMarginfiSolautoManagedPositionArgs(positionId, signer, wallet, suppl
|
|
25
25
|
}
|
26
26
|
exports.newMarginfiSolautoManagedPositionArgs = newMarginfiSolautoManagedPositionArgs;
|
27
27
|
class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
28
|
-
async initialize(args
|
28
|
+
async initialize(args) {
|
29
29
|
if (args.marginfiAccount) {
|
30
30
|
this.marginfiAccount = args.marginfiAccount;
|
31
31
|
}
|
32
|
-
await
|
32
|
+
await super.initialize(args, generated_1.LendingPlatform.Marginfi);
|
33
33
|
this.marginfiAccountSeedIdx = args.marginfiAccountSeedIdx;
|
34
34
|
this.marginfiAccount =
|
35
35
|
this.marginfiAccountSeedIdx !== undefined
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import { PublicKey
|
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;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAoB,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,eAAe,EACf,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;AAgCzB,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,kBAAkB,GAC7B,OAAO,CAET;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,kBAAkB,EAC9B,oBAAoB,EAAE,MAAM,UAY7B;AAED,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,yBAAyB,EACnC,kBAAkB,EAAE,MAAM,GACzB,yBAAyB,CA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SAAS,GACd,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAuBnC;AA4DD,KAAK,kBAAkB,GACnB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,gCAAgC,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAE/C,qBAAa,mBAAmB;IACvB,gBAAgB,EAAE,MAAM,CAAa;IACrC,cAAc,EAAE,MAAM,CAAa;IACnC,uBAAuB,EAAE,MAAM,CAAa;IAC5C,QAAQ,EAAE,yBAAyB,GAAG,SAAS,CAAa;IAC5D,SAAS,EAAE,WAAW,GAAG,SAAS,CAAa;IAEtD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IAyD9B,KAAK;IAQL,UAAU,IAAI,OAAO;CAQtB"}
|
@@ -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(
|
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)(
|
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);
|
204
|
+
allPositions.push(...marginfiPositions.map((x) => ({
|
205
|
+
positionId: 0,
|
206
|
+
lendingPlatform: generated_1.LendingPlatform.Marginfi,
|
207
|
+
protocolAccount: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey),
|
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),
|
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
@@ -74,8 +74,6 @@ export interface SolautoClientArgs {
|
|
74
74
|
}
|
75
75
|
|
76
76
|
export abstract class SolautoClient {
|
77
|
-
public localTest: boolean;
|
78
|
-
|
79
77
|
public umi!: Umi;
|
80
78
|
public connection!: Connection;
|
81
79
|
public lendingPlatform!: LendingPlatform;
|
@@ -114,17 +112,12 @@ export abstract class SolautoClient {
|
|
114
112
|
|
115
113
|
public livePositionUpdates: LivePositionUpdates = new LivePositionUpdates();
|
116
114
|
|
117
|
-
constructor(
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
async baseInitialize(
|
122
|
-
args: SolautoClientArgs,
|
123
|
-
lendingPlatform: LendingPlatform,
|
124
|
-
heliusApiKey: string
|
115
|
+
constructor(
|
116
|
+
private heliusApiKey: string,
|
117
|
+
public localTest?: boolean
|
125
118
|
) {
|
126
119
|
this.connection = new Connection(
|
127
|
-
`https://mainnet.helius-rpc.com/?api-key=${heliusApiKey}`,
|
120
|
+
`https://mainnet.helius-rpc.com/?api-key=${this.heliusApiKey}`,
|
128
121
|
"finalized"
|
129
122
|
);
|
130
123
|
this.umi = createUmi(this.connection).use({
|
@@ -132,6 +125,12 @@ export abstract class SolautoClient {
|
|
132
125
|
umi.programs.add(createSolautoProgram(), false);
|
133
126
|
},
|
134
127
|
});
|
128
|
+
}
|
129
|
+
|
130
|
+
async initialize(
|
131
|
+
args: SolautoClientArgs,
|
132
|
+
lendingPlatform: LendingPlatform,
|
133
|
+
) {
|
135
134
|
if (!args.signer && !args.wallet) {
|
136
135
|
throw new Error("Signer or wallet must be provided");
|
137
136
|
}
|
@@ -98,12 +98,12 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
98
98
|
public intermediaryMarginfiAccountPk!: PublicKey;
|
99
99
|
public intermediaryMarginfiAccount?: MarginfiAccount;
|
100
100
|
|
101
|
-
async initialize(args: SolautoMarginfiClientArgs
|
101
|
+
async initialize(args: SolautoMarginfiClientArgs) {
|
102
102
|
if (args.marginfiAccount) {
|
103
103
|
this.marginfiAccount = args.marginfiAccount;
|
104
104
|
}
|
105
105
|
|
106
|
-
await
|
106
|
+
await super.initialize(args, LendingPlatform.Marginfi);
|
107
107
|
|
108
108
|
this.marginfiAccountSeedIdx = args.marginfiAccountSeedIdx;
|
109
109
|
this.marginfiAccount =
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
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 {
|
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(
|
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(
|
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);
|
326
|
+
allPositions.push(
|
327
|
+
...marginfiPositions.map((x) => ({
|
328
|
+
positionId: 0,
|
329
|
+
lendingPlatform: LendingPlatform.Marginfi,
|
330
|
+
protocolAccount: toWeb3JsPublicKey(x.publicKey),
|
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
|
-
|
351
|
+
protocolAccount
|
314
352
|
);
|
315
353
|
} else {
|
316
354
|
throw new Error("Lending platorm not yet supported");
|
@@ -26,7 +26,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
26
26
|
const positionId = 1;
|
27
27
|
|
28
28
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
29
|
-
const client = new SolautoMarginfiClient(true);
|
29
|
+
const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY!, true);
|
30
30
|
|
31
31
|
const supply = NATIVE_MINT;
|
32
32
|
const supplyDecimals = 9;
|
@@ -43,8 +43,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
43
43
|
{
|
44
44
|
signer,
|
45
45
|
positionId,
|
46
|
-
}
|
47
|
-
process.env.HELIUS_API_KEY!
|
46
|
+
}
|
48
47
|
);
|
49
48
|
|
50
49
|
const transactionItems: TransactionItem[] = [];
|