@haven-fi/solauto-sdk 1.0.133 → 1.0.134
Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
|
|
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,EAA+B,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAElB,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,
|
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,EAA+B,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAElB,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAKjC,MAAM,iBAAiB,CAAC;AAezB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE9E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAW1D;AAgBD,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,kBAAkB,EAC9B,eAAe,EAAE,MAAM,GACtB,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,eAAe,EAAE,MAAM,GACtB,yBAAyB,CAgB3B;AAED,wBAAgB,oBAAoB,CAClC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C;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;IA0B9B,KAAK;IAQL,UAAU,IAAI,OAAO;CAQtB"}
|
@@ -27,7 +27,8 @@ const marginfiUtils_1 = require("../marginfiUtils");
|
|
27
27
|
function findMintByTicker(ticker) {
|
28
28
|
for (const key in constants_1.TOKEN_INFO) {
|
29
29
|
const account = constants_1.TOKEN_INFO[key];
|
30
|
-
if (account.ticker.toString().toLowerCase() ===
|
30
|
+
if (account.ticker.toString().toLowerCase() ===
|
31
|
+
ticker.toString().toLowerCase()) {
|
31
32
|
return new web3_js_1.PublicKey(key);
|
32
33
|
}
|
33
34
|
}
|
@@ -102,13 +103,17 @@ async function getSolautoManagedPositions(umi, authority) {
|
|
102
103
|
// position_id: [u8; 1]
|
103
104
|
// self_managed: u8 - (1 for true, 0 for false)
|
104
105
|
// padding: [u8; 5]
|
105
|
-
// authority:
|
106
|
+
// authority: pubkey
|
106
107
|
// lending_platform: u8
|
108
|
+
// padding: [u8; 7]
|
109
|
+
// protocol account: pubkey
|
110
|
+
// supply mint: pubkey
|
111
|
+
// debt mint: pubkey
|
107
112
|
const accounts = await umi.rpc.getProgramAccounts(generated_1.SOLAUTO_PROGRAM_ID, {
|
108
113
|
commitment: "confirmed",
|
109
114
|
dataSlice: {
|
110
115
|
offset: 0,
|
111
|
-
length: 1 + 1 + 1 + 5 + 32 + 1, // bump + position_id + self_managed + padding + authority (pubkey) + lending_platform
|
116
|
+
length: 1 + 1 + 1 + 5 + 32 + 1 + 7 + 32 + 32 + 32, // bump + position_id + self_managed + padding (5) + authority (pubkey) + lending_platform + padding (7) + protocol account (pubkey) + supply mint (pubkey) + debt mint (pubkey)
|
112
117
|
},
|
113
118
|
filters: [
|
114
119
|
{
|
@@ -142,6 +147,9 @@ async function getSolautoManagedPositions(umi, authority) {
|
|
142
147
|
authority: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.authority),
|
143
148
|
positionId: position.positionId[0],
|
144
149
|
lendingPlatform: position.position.lendingPlatform,
|
150
|
+
protocolAccount: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.position.protocolAccount),
|
151
|
+
supplyMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.position.supplyMint),
|
152
|
+
debtMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.position.debtMint),
|
145
153
|
};
|
146
154
|
});
|
147
155
|
}
|
@@ -187,29 +195,32 @@ async function getReferralsByUser(umi, user) {
|
|
187
195
|
return accounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
|
188
196
|
}
|
189
197
|
async function getAllPositionsByAuthority(umi, user) {
|
190
|
-
const
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
198
|
+
const solautoCompatiblePositions = await Promise.all([
|
199
|
+
(async () => {
|
200
|
+
const solautoManagedPositions = await getSolautoManagedPositions(umi, user);
|
201
|
+
return solautoManagedPositions.map((x) => ({
|
202
|
+
...x,
|
203
|
+
authority: user,
|
204
|
+
}));
|
205
|
+
})(),
|
206
|
+
(async () => {
|
207
|
+
let marginfiPositions = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(umi, user, true);
|
208
|
+
marginfiPositions = marginfiPositions.filter((x) => x.supplyMint &&
|
209
|
+
(x.debtMint.equals(web3_js_1.PublicKey.default) ||
|
210
|
+
constants_1.ALL_SUPPORTED_TOKENS.includes(x.debtMint.toString())));
|
211
|
+
return marginfiPositions.map((x) => ({
|
212
|
+
publicKey: x.marginfiAccount,
|
213
|
+
authority: user,
|
214
|
+
positionId: 0,
|
215
|
+
lendingPlatform: generated_1.LendingPlatform.Marginfi,
|
216
|
+
protocolAccount: x.marginfiAccount,
|
217
|
+
supplyMint: x.supplyMint,
|
218
|
+
debtMint: x.debtMint,
|
219
|
+
}));
|
220
|
+
})(),
|
221
|
+
// TODO support other platforms
|
222
|
+
]);
|
223
|
+
return solautoCompatiblePositions.flat();
|
213
224
|
}
|
214
225
|
async function positionStateWithLatestPrices(state, supplyPrice, debtPrice) {
|
215
226
|
if (!supplyPrice || !debtPrice) {
|
@@ -320,8 +331,7 @@ function createSolautoSettings(settings) {
|
|
320
331
|
padding: new Uint8Array([]),
|
321
332
|
padding1: [],
|
322
333
|
},
|
323
|
-
targetBoostToBps: (0, umi_1.isOption)(settings.targetBoostToBps) &&
|
324
|
-
(0, umi_1.isSome)(settings.targetBoostToBps)
|
334
|
+
targetBoostToBps: (0, umi_1.isOption)(settings.targetBoostToBps) && (0, umi_1.isSome)(settings.targetBoostToBps)
|
325
335
|
? settings.targetBoostToBps.value
|
326
336
|
: 0,
|
327
337
|
boostGap: settings.boostGap,
|
package/package.json
CHANGED
@@ -12,6 +12,7 @@ import {
|
|
12
12
|
getReferralStateSize,
|
13
13
|
getSolautoPositionAccountDataSerializer,
|
14
14
|
getSolautoPositionSize,
|
15
|
+
safeFetchAllSolautoPosition,
|
15
16
|
} from "../../generated";
|
16
17
|
import { currentUnixSeconds, fetchTokenPrices } from "../generalUtils";
|
17
18
|
import {
|
@@ -33,7 +34,8 @@ export function findMintByTicker(ticker: string): PublicKey {
|
|
33
34
|
for (const key in TOKEN_INFO) {
|
34
35
|
const account = TOKEN_INFO[key];
|
35
36
|
if (
|
36
|
-
account.ticker.toString().toLowerCase() ===
|
37
|
+
account.ticker.toString().toLowerCase() ===
|
38
|
+
ticker.toString().toLowerCase()
|
37
39
|
) {
|
38
40
|
return new PublicKey(key);
|
39
41
|
}
|
@@ -176,14 +178,18 @@ export async function getSolautoManagedPositions(
|
|
176
178
|
// position_id: [u8; 1]
|
177
179
|
// self_managed: u8 - (1 for true, 0 for false)
|
178
180
|
// padding: [u8; 5]
|
179
|
-
// authority:
|
181
|
+
// authority: pubkey
|
180
182
|
// lending_platform: u8
|
183
|
+
// padding: [u8; 7]
|
184
|
+
// protocol account: pubkey
|
185
|
+
// supply mint: pubkey
|
186
|
+
// debt mint: pubkey
|
181
187
|
|
182
188
|
const accounts = await umi.rpc.getProgramAccounts(SOLAUTO_PROGRAM_ID, {
|
183
189
|
commitment: "confirmed",
|
184
190
|
dataSlice: {
|
185
191
|
offset: 0,
|
186
|
-
length: 1 + 1 + 1 + 5 + 32 + 1, // bump + position_id + self_managed + padding + authority (pubkey) + lending_platform
|
192
|
+
length: 1 + 1 + 1 + 5 + 32 + 1 + 7 + 32 + 32 + 32, // bump + position_id + self_managed + padding (5) + authority (pubkey) + lending_platform + padding (7) + protocol account (pubkey) + supply mint (pubkey) + debt mint (pubkey)
|
187
193
|
},
|
188
194
|
filters: [
|
189
195
|
{
|
@@ -220,6 +226,9 @@ export async function getSolautoManagedPositions(
|
|
220
226
|
authority: toWeb3JsPublicKey(position.authority),
|
221
227
|
positionId: position.positionId[0],
|
222
228
|
lendingPlatform: position.position.lendingPlatform,
|
229
|
+
protocolAccount: toWeb3JsPublicKey(position.position.protocolAccount),
|
230
|
+
supplyMint: toWeb3JsPublicKey(position.position.supplyMint),
|
231
|
+
debtMint: toWeb3JsPublicKey(position.position.debtMint),
|
223
232
|
};
|
224
233
|
});
|
225
234
|
}
|
@@ -277,44 +286,44 @@ export async function getAllPositionsByAuthority(
|
|
277
286
|
umi: Umi,
|
278
287
|
user: PublicKey
|
279
288
|
): Promise<SolautoPositionDetails[]> {
|
280
|
-
const
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
289
|
+
const solautoCompatiblePositions: SolautoPositionDetails[][] =
|
290
|
+
await Promise.all([
|
291
|
+
(async () => {
|
292
|
+
const solautoManagedPositions = await getSolautoManagedPositions(
|
293
|
+
umi,
|
294
|
+
user
|
295
|
+
);
|
296
|
+
return solautoManagedPositions.map((x) => ({
|
297
|
+
...x,
|
298
|
+
authority: user,
|
299
|
+
}));
|
300
|
+
})(),
|
301
|
+
(async () => {
|
302
|
+
let marginfiPositions = await getAllMarginfiAccountsByAuthority(
|
303
|
+
umi,
|
304
|
+
user,
|
305
|
+
true
|
306
|
+
);
|
307
|
+
marginfiPositions = marginfiPositions.filter(
|
308
|
+
(x) =>
|
309
|
+
x.supplyMint &&
|
310
|
+
(x.debtMint!.equals(PublicKey.default) ||
|
311
|
+
ALL_SUPPORTED_TOKENS.includes(x.debtMint!.toString()))
|
312
|
+
);
|
313
|
+
return marginfiPositions.map((x) => ({
|
314
|
+
publicKey: x.marginfiAccount,
|
315
|
+
authority: user,
|
316
|
+
positionId: 0,
|
317
|
+
lendingPlatform: LendingPlatform.Marginfi,
|
318
|
+
protocolAccount: x.marginfiAccount,
|
319
|
+
supplyMint: x.supplyMint,
|
320
|
+
debtMint: x.debtMint,
|
321
|
+
}));
|
322
|
+
})(),
|
323
|
+
// TODO support other platforms
|
324
|
+
]);
|
316
325
|
|
317
|
-
return
|
326
|
+
return solautoCompatiblePositions.flat();
|
318
327
|
}
|
319
328
|
|
320
329
|
export async function positionStateWithLatestPrices(
|
@@ -441,15 +450,15 @@ export function createFakePositionState(
|
|
441
450
|
};
|
442
451
|
}
|
443
452
|
|
444
|
-
export function createSolautoSettings(
|
453
|
+
export function createSolautoSettings(
|
454
|
+
settings: SolautoSettingsParametersInpArgs
|
455
|
+
): SolautoSettingsParameters {
|
445
456
|
return {
|
446
457
|
automation:
|
447
458
|
isOption(settings.automation) && isSome(settings.automation)
|
448
459
|
? {
|
449
460
|
...settings.automation.value,
|
450
|
-
intervalSeconds: BigInt(
|
451
|
-
settings.automation.value.intervalSeconds
|
452
|
-
),
|
461
|
+
intervalSeconds: BigInt(settings.automation.value.intervalSeconds),
|
453
462
|
unixStartDate: BigInt(settings.automation.value.unixStartDate),
|
454
463
|
padding: new Uint8Array([]),
|
455
464
|
padding1: [],
|
@@ -463,8 +472,7 @@ export function createSolautoSettings(settings: SolautoSettingsParametersInpArgs
|
|
463
472
|
padding1: [],
|
464
473
|
},
|
465
474
|
targetBoostToBps:
|
466
|
-
isOption(settings.targetBoostToBps) &&
|
467
|
-
isSome(settings.targetBoostToBps)
|
475
|
+
isOption(settings.targetBoostToBps) && isSome(settings.targetBoostToBps)
|
468
476
|
? settings.targetBoostToBps.value
|
469
477
|
: 0,
|
470
478
|
boostGap: settings.boostGap,
|