@haven-fi/solauto-sdk 1.0.62 → 1.0.64
Sign up to get free protection for your applications and to get access to all the features.
@@ -17,12 +17,11 @@ export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicK
|
|
17
17
|
export declare function getAllReferralStates(umi: Umi): Promise<PublicKey[]>;
|
18
18
|
export declare function getReferralsByUser(umi: Umi, user: PublicKey): Promise<PublicKey[]>;
|
19
19
|
export declare function getAllPositionsByAuthority(umi: Umi, user: PublicKey): Promise<SolautoPositionDetails[]>;
|
20
|
-
export declare function
|
20
|
+
export declare function positionStateWithLatestPrices(state: PositionState, supplyPrice?: number, debtPrice?: number): Promise<PositionState>;
|
21
21
|
interface AssetProps {
|
22
|
-
amountUsedBaseUnit: bigint;
|
23
|
-
decimals: number;
|
24
|
-
price: number;
|
25
22
|
mint: PublicKey;
|
23
|
+
price: number;
|
24
|
+
amountUsed: number;
|
26
25
|
}
|
27
26
|
export declare function createFakePositionState(supply: AssetProps, debt: AssetProps, maxLtvBps: number, liqThresholdBps: number): PositionState;
|
28
27
|
type PositionAdjustment = {
|
@@ -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,EAClB,OAAO,EAEP,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;
|
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,EAC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,CAAC,MAAM,EAAE,kBAAkB;IAyD9B,KAAK;IAQL,UAAU,IAAI,OAAO;CAQtB"}
|
@@ -12,7 +12,7 @@ exports.getSolautoManagedPositions = getSolautoManagedPositions;
|
|
12
12
|
exports.getAllReferralStates = getAllReferralStates;
|
13
13
|
exports.getReferralsByUser = getReferralsByUser;
|
14
14
|
exports.getAllPositionsByAuthority = getAllPositionsByAuthority;
|
15
|
-
exports.
|
15
|
+
exports.positionStateWithLatestPrices = positionStateWithLatestPrices;
|
16
16
|
exports.createFakePositionState = createFakePositionState;
|
17
17
|
const web3_js_1 = require("@solana/web3.js");
|
18
18
|
const umi_1 = require("@metaplex-foundation/umi");
|
@@ -213,7 +213,7 @@ async function getAllPositionsByAuthority(umi, user) {
|
|
213
213
|
// TODO support other platforms
|
214
214
|
return allPositions;
|
215
215
|
}
|
216
|
-
async function
|
216
|
+
async function positionStateWithLatestPrices(state, supplyPrice, debtPrice) {
|
217
217
|
if (!supplyPrice || !debtPrice) {
|
218
218
|
[supplyPrice, debtPrice] = await (0, generalUtils_1.getTokenPrices)([
|
219
219
|
(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint),
|
@@ -248,22 +248,24 @@ async function positionStateWithPrices(state, supplyPrice, debtPrice) {
|
|
248
248
|
};
|
249
249
|
}
|
250
250
|
function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
|
251
|
-
const
|
252
|
-
const
|
251
|
+
const supplyDecimals = constants_1.TOKEN_DECIMALS[supply.mint.toString()];
|
252
|
+
const debtDecimals = constants_1.TOKEN_DECIMALS[debt.mint.toString()];
|
253
|
+
const supplyUsd = supply.amountUsed * supply.price;
|
254
|
+
const debtUsd = debt.amountUsed * debt.price;
|
253
255
|
return {
|
254
256
|
liqUtilizationRateBps: (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, liqThresholdBps),
|
255
257
|
supply: {
|
256
258
|
amountUsed: {
|
257
|
-
baseUnit: supply.
|
259
|
+
baseUnit: (0, numberUtils_1.toBaseUnit)(supply.amountUsed, supplyDecimals),
|
258
260
|
baseAmountUsdValue: (0, numberUtils_1.toBaseUnit)(supplyUsd, constants_1.USD_DECIMALS),
|
259
261
|
},
|
260
262
|
amountCanBeUsed: {
|
261
|
-
baseUnit: (0, numberUtils_1.toBaseUnit)(1000000,
|
263
|
+
baseUnit: (0, numberUtils_1.toBaseUnit)(1000000, supplyDecimals),
|
262
264
|
baseAmountUsdValue: BigInt(Math.round(1000000 * supply.price)),
|
263
265
|
},
|
264
266
|
baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(supply.price, constants_1.USD_DECIMALS),
|
265
267
|
borrowFeeBps: 0,
|
266
|
-
decimals:
|
268
|
+
decimals: supplyDecimals,
|
267
269
|
flashLoanFeeBps: 0,
|
268
270
|
mint: (0, umi_1.publicKey)(supply.mint),
|
269
271
|
padding1: [],
|
@@ -272,16 +274,16 @@ function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
|
|
272
274
|
},
|
273
275
|
debt: {
|
274
276
|
amountUsed: {
|
275
|
-
baseUnit: debt.
|
277
|
+
baseUnit: (0, numberUtils_1.toBaseUnit)(debt.amountUsed, debtDecimals),
|
276
278
|
baseAmountUsdValue: (0, numberUtils_1.toBaseUnit)(debtUsd, constants_1.USD_DECIMALS),
|
277
279
|
},
|
278
280
|
amountCanBeUsed: {
|
279
|
-
baseUnit: (0, numberUtils_1.toBaseUnit)(1000000,
|
281
|
+
baseUnit: (0, numberUtils_1.toBaseUnit)(1000000, debtDecimals),
|
280
282
|
baseAmountUsdValue: BigInt(Math.round(1000000 * debt.price)),
|
281
283
|
},
|
282
284
|
baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(debt.price, constants_1.USD_DECIMALS),
|
283
285
|
borrowFeeBps: 0,
|
284
|
-
decimals:
|
286
|
+
decimals: debtDecimals,
|
285
287
|
flashLoanFeeBps: 0,
|
286
288
|
mint: (0, umi_1.publicKey)(debt.mint),
|
287
289
|
padding1: [],
|
@@ -289,7 +291,7 @@ function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
|
|
289
291
|
padding: new Uint8Array([]),
|
290
292
|
},
|
291
293
|
netWorth: {
|
292
|
-
baseUnit: (0, numberUtils_1.toBaseUnit)((supplyUsd - debtUsd) / supply.price,
|
294
|
+
baseUnit: (0, numberUtils_1.toBaseUnit)((supplyUsd - debtUsd) / supply.price, supplyDecimals),
|
293
295
|
baseAmountUsdValue: (0, numberUtils_1.toBaseUnit)(supplyUsd - debtUsd, constants_1.USD_DECIMALS),
|
294
296
|
},
|
295
297
|
maxLtvBps,
|
package/package.json
CHANGED
@@ -22,7 +22,11 @@ import {
|
|
22
22
|
} from "../numberUtils";
|
23
23
|
import { getReferralState } from "../accountUtils";
|
24
24
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
25
|
-
import {
|
25
|
+
import {
|
26
|
+
ALL_SUPPORTED_TOKENS,
|
27
|
+
TOKEN_DECIMALS,
|
28
|
+
USD_DECIMALS,
|
29
|
+
} from "../../constants";
|
26
30
|
import {
|
27
31
|
getAllMarginfiAccountsByAuthority,
|
28
32
|
getMarginfiAccountPositionState,
|
@@ -326,11 +330,11 @@ export async function getAllPositionsByAuthority(
|
|
326
330
|
return allPositions;
|
327
331
|
}
|
328
332
|
|
329
|
-
export async function
|
333
|
+
export async function positionStateWithLatestPrices(
|
330
334
|
state: PositionState,
|
331
335
|
supplyPrice?: number,
|
332
|
-
debtPrice?: number
|
333
|
-
): Promise<PositionState
|
336
|
+
debtPrice?: number
|
337
|
+
): Promise<PositionState> {
|
334
338
|
if (!supplyPrice || !debtPrice) {
|
335
339
|
[supplyPrice, debtPrice] = await getTokenPrices([
|
336
340
|
toWeb3JsPublicKey(state.supply.mint),
|
@@ -376,10 +380,9 @@ export async function positionStateWithPrices(
|
|
376
380
|
}
|
377
381
|
|
378
382
|
interface AssetProps {
|
379
|
-
amountUsedBaseUnit: bigint;
|
380
|
-
decimals: number;
|
381
|
-
price: number;
|
382
383
|
mint: PublicKey;
|
384
|
+
price: number;
|
385
|
+
amountUsed: number;
|
383
386
|
}
|
384
387
|
|
385
388
|
export function createFakePositionState(
|
@@ -388,10 +391,11 @@ export function createFakePositionState(
|
|
388
391
|
maxLtvBps: number,
|
389
392
|
liqThresholdBps: number
|
390
393
|
): PositionState {
|
391
|
-
const
|
392
|
-
|
393
|
-
|
394
|
-
|
394
|
+
const supplyDecimals = TOKEN_DECIMALS[supply.mint.toString()];
|
395
|
+
const debtDecimals = TOKEN_DECIMALS[debt.mint.toString()];
|
396
|
+
|
397
|
+
const supplyUsd = supply.amountUsed * supply.price;
|
398
|
+
const debtUsd = debt.amountUsed * debt.price;
|
395
399
|
|
396
400
|
return {
|
397
401
|
liqUtilizationRateBps: getLiqUtilzationRateBps(
|
@@ -401,16 +405,16 @@ export function createFakePositionState(
|
|
401
405
|
),
|
402
406
|
supply: {
|
403
407
|
amountUsed: {
|
404
|
-
baseUnit: supply.
|
408
|
+
baseUnit: toBaseUnit(supply.amountUsed, supplyDecimals),
|
405
409
|
baseAmountUsdValue: toBaseUnit(supplyUsd, USD_DECIMALS),
|
406
410
|
},
|
407
411
|
amountCanBeUsed: {
|
408
|
-
baseUnit: toBaseUnit(1000000,
|
412
|
+
baseUnit: toBaseUnit(1000000, supplyDecimals),
|
409
413
|
baseAmountUsdValue: BigInt(Math.round(1000000 * supply.price)),
|
410
414
|
},
|
411
415
|
baseAmountMarketPriceUsd: toBaseUnit(supply.price, USD_DECIMALS),
|
412
416
|
borrowFeeBps: 0,
|
413
|
-
decimals:
|
417
|
+
decimals: supplyDecimals,
|
414
418
|
flashLoanFeeBps: 0,
|
415
419
|
mint: publicKey(supply.mint),
|
416
420
|
padding1: [],
|
@@ -419,16 +423,16 @@ export function createFakePositionState(
|
|
419
423
|
},
|
420
424
|
debt: {
|
421
425
|
amountUsed: {
|
422
|
-
baseUnit: debt.
|
426
|
+
baseUnit: toBaseUnit(debt.amountUsed, debtDecimals),
|
423
427
|
baseAmountUsdValue: toBaseUnit(debtUsd, USD_DECIMALS),
|
424
428
|
},
|
425
429
|
amountCanBeUsed: {
|
426
|
-
baseUnit: toBaseUnit(1000000,
|
430
|
+
baseUnit: toBaseUnit(1000000, debtDecimals),
|
427
431
|
baseAmountUsdValue: BigInt(Math.round(1000000 * debt.price)),
|
428
432
|
},
|
429
433
|
baseAmountMarketPriceUsd: toBaseUnit(debt.price, USD_DECIMALS),
|
430
434
|
borrowFeeBps: 0,
|
431
|
-
decimals:
|
435
|
+
decimals: debtDecimals,
|
432
436
|
flashLoanFeeBps: 0,
|
433
437
|
mint: publicKey(debt.mint),
|
434
438
|
padding1: [],
|
@@ -438,7 +442,7 @@ export function createFakePositionState(
|
|
438
442
|
netWorth: {
|
439
443
|
baseUnit: toBaseUnit(
|
440
444
|
(supplyUsd - debtUsd) / supply.price,
|
441
|
-
|
445
|
+
supplyDecimals
|
442
446
|
),
|
443
447
|
baseAmountUsdValue: toBaseUnit(supplyUsd - debtUsd, USD_DECIMALS),
|
444
448
|
},
|
@@ -27,7 +27,7 @@ import {
|
|
27
27
|
getAdjustedSettingsFromAutomation,
|
28
28
|
getSolautoFeesBps,
|
29
29
|
getUpdatedValueFromAutomation,
|
30
|
-
|
30
|
+
positionStateWithLatestPrices,
|
31
31
|
} from "../../src/utils/solauto/generalUtils";
|
32
32
|
import {
|
33
33
|
currentUnixSeconds,
|
@@ -117,23 +117,19 @@ async function getFakePosition(
|
|
117
117
|
const supplyUsd = 1000;
|
118
118
|
const maxLtvBps = 6400;
|
119
119
|
const liqThresholdBps = 8181;
|
120
|
-
client.solautoPositionState = await
|
120
|
+
client.solautoPositionState = await positionStateWithLatestPrices(
|
121
121
|
createFakePositionState(
|
122
122
|
{
|
123
|
-
|
124
|
-
decimals: 9,
|
123
|
+
amountUsed: supplyUsd / supplyPrice,
|
125
124
|
price: PRICES[NATIVE_MINT.toString()].price,
|
126
125
|
mint: NATIVE_MINT,
|
127
126
|
},
|
128
127
|
{
|
129
|
-
|
128
|
+
amountUsed:
|
130
129
|
(supplyUsd *
|
131
130
|
fromBps(liqThresholdBps) *
|
132
131
|
fromBps(fakeLiqUtilizationRateBps)) /
|
133
|
-
|
134
|
-
6
|
135
|
-
),
|
136
|
-
decimals: 6,
|
132
|
+
debtPrice,
|
137
133
|
price: 1,
|
138
134
|
mint: new PublicKey(USDC_MINT),
|
139
135
|
},
|