@haven-fi/solauto-sdk 1.0.366 → 1.0.368
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/constants/tokenConstants.js +2 -2
- package/dist/utils/generalUtils.d.ts +1 -0
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +8 -0
- package/dist/utils/solauto/generalUtils.d.ts +2 -1
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +10 -0
- package/package.json +1 -1
- package/src/constants/tokenConstants.ts +2 -2
- package/src/utils/generalUtils.ts +11 -0
- package/src/utils/solauto/generalUtils.ts +26 -0
- package/tests/transactions/solautoMarginfi.ts +22 -22
@@ -107,12 +107,12 @@ exports.TOKEN_INFO = {
|
|
107
107
|
decimals: 6,
|
108
108
|
},
|
109
109
|
[exports.WBTC]: {
|
110
|
-
ticker: "
|
110
|
+
ticker: "wBTC",
|
111
111
|
decimals: 8,
|
112
112
|
isMajor: true,
|
113
113
|
},
|
114
114
|
[exports.WETH]: {
|
115
|
-
ticker: "
|
115
|
+
ticker: "wETH",
|
116
116
|
decimals: 8,
|
117
117
|
isMajor: true,
|
118
118
|
},
|
@@ -10,4 +10,5 @@ export declare function arraysAreEqual(arrayA: number[], arrayB: number[]): bool
|
|
10
10
|
export declare function zip<T, U>(list1: T[], list2: U[]): [T, U][];
|
11
11
|
export type ErrorsToThrow = Array<new (...args: any[]) => Error>;
|
12
12
|
export declare function retryWithExponentialBackoff<T>(fn: (attemptNum: number, prevErr?: Error) => Promise<T>, retries?: number, delay?: number, errorsToThrow?: ErrorsToThrow): Promise<T>;
|
13
|
+
export declare function toEnumValue<E extends object>(enumObj: E, value: number): E[keyof E] | undefined;
|
13
14
|
//# sourceMappingURL=generalUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":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AY,EACnB,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,CAAC,CAAC,CA8BZ;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAQ/F"}
|
@@ -9,6 +9,7 @@ exports.rpcAccountCreated = rpcAccountCreated;
|
|
9
9
|
exports.arraysAreEqual = arraysAreEqual;
|
10
10
|
exports.zip = zip;
|
11
11
|
exports.retryWithExponentialBackoff = retryWithExponentialBackoff;
|
12
|
+
exports.toEnumValue = toEnumValue;
|
12
13
|
const umi_1 = require("@metaplex-foundation/umi");
|
13
14
|
function consoleLog(...args) {
|
14
15
|
if (globalThis.LOCAL_TEST) {
|
@@ -85,3 +86,10 @@ function retryWithExponentialBackoff(fn, retries = 5, delay = 150, errorsToThrow
|
|
85
86
|
return attempt(0);
|
86
87
|
});
|
87
88
|
}
|
89
|
+
function toEnumValue(enumObj, value) {
|
90
|
+
const numericValues = Object.values(enumObj).filter(v => typeof v === "number");
|
91
|
+
if (numericValues.includes(value)) {
|
92
|
+
return value;
|
93
|
+
}
|
94
|
+
return undefined;
|
95
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { Program, Umi } from "@metaplex-foundation/umi";
|
3
|
-
import { AutomationSettings, DCASettings, DCASettingsInpArgs, PositionState, PositionType, SolautoSettingsParameters, SolautoSettingsParametersInpArgs, TokenType } from "../../generated";
|
3
|
+
import { AutomationSettings, DCASettings, DCASettingsInpArgs, LendingPlatform, PositionState, PositionType, SolautoSettingsParameters, SolautoSettingsParametersInpArgs, TokenType } from "../../generated";
|
4
4
|
import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
|
5
5
|
export declare function createDynamicSolautoProgram(programId: PublicKey): Program;
|
6
6
|
export declare function nextAutomationPeriodTimestamp(automation: AutomationSettings): number;
|
@@ -22,6 +22,7 @@ interface AssetProps {
|
|
22
22
|
}
|
23
23
|
export declare function createFakePositionState(supply: AssetProps, debt: AssetProps, maxLtvBps: number, liqThresholdBps: number): PositionState;
|
24
24
|
export declare function createSolautoSettings(settings: SolautoSettingsParametersInpArgs): SolautoSettingsParameters;
|
25
|
+
export declare function getMaxLtvBpsAndLiqThresholdBps(umi: Umi, lendingPlatform: LendingPlatform, lendingPool: PublicKey, supplyMint: PublicKey, debtMint: PublicKey, supplyPrice: number): Promise<number[]>;
|
25
26
|
type PositionAdjustment = {
|
26
27
|
type: "supply";
|
27
28
|
value: bigint;
|
@@ -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,EAGL,OAAO,EAEP,GAAG,EACJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,
|
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,EAGL,OAAO,EAEP,GAAG,EACJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,yBAAyB,EACzB,gCAAgC,EAChC,SAAS,EAMV,MAAM,iBAAiB,CAAC;AAoBzB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAI9E,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAczE;AAgBD,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,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,SAAa;IAC3B,QAAQ,EAAE,yBAAyB,GAAG,SAAS,CAAa;IAC5D,SAAS,EAAE,WAAW,GAAG,SAAS,CAAa;IAC/C,YAAY,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,SAAS,CAAA;KAAE,CAAa;IACpE,aAAa,EAAE,SAAS,GAAG,SAAS,CAAa;IAExD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IA6B9B,KAAK;IASL,UAAU,IAAI,OAAO;CAStB"}
|
@@ -15,6 +15,7 @@ exports.getAllPositionsByAuthority = getAllPositionsByAuthority;
|
|
15
15
|
exports.positionStateWithLatestPrices = positionStateWithLatestPrices;
|
16
16
|
exports.createFakePositionState = createFakePositionState;
|
17
17
|
exports.createSolautoSettings = createSolautoSettings;
|
18
|
+
exports.getMaxLtvBpsAndLiqThresholdBps = getMaxLtvBpsAndLiqThresholdBps;
|
18
19
|
const web3_js_1 = require("@solana/web3.js");
|
19
20
|
const umi_1 = require("@metaplex-foundation/umi");
|
20
21
|
const generated_1 = require("../../generated");
|
@@ -389,6 +390,15 @@ function createSolautoSettings(settings) {
|
|
389
390
|
padding1: [],
|
390
391
|
};
|
391
392
|
}
|
393
|
+
async function getMaxLtvBpsAndLiqThresholdBps(umi, lendingPlatform, lendingPool, supplyMint, debtMint, supplyPrice) {
|
394
|
+
let maxLtv = 0;
|
395
|
+
let liqThreshold = 0;
|
396
|
+
if (lendingPlatform === generated_1.LendingPlatform.Marginfi) {
|
397
|
+
[maxLtv, liqThreshold] = await (0, marginfiUtils_1.getMaxLtvAndLiqThreshold)(umi, lendingPool, { mint: supplyMint }, { mint: debtMint }, supplyPrice);
|
398
|
+
}
|
399
|
+
// TODO: PK
|
400
|
+
return [(0, numberUtils_1.toBps)(maxLtv), (0, numberUtils_1.toBps)(liqThreshold)];
|
401
|
+
}
|
392
402
|
class LivePositionUpdates {
|
393
403
|
constructor() {
|
394
404
|
this.supplyAdjustment = BigInt(0);
|
package/package.json
CHANGED
@@ -116,12 +116,12 @@ export const TOKEN_INFO: { [key: string]: TokenInfo } = {
|
|
116
116
|
decimals: 6,
|
117
117
|
},
|
118
118
|
[WBTC]: {
|
119
|
-
ticker: "
|
119
|
+
ticker: "wBTC",
|
120
120
|
decimals: 8,
|
121
121
|
isMajor: true,
|
122
122
|
},
|
123
123
|
[WETH]: {
|
124
|
-
ticker: "
|
124
|
+
ticker: "wETH",
|
125
125
|
decimals: 8,
|
126
126
|
isMajor: true,
|
127
127
|
},
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { MaybeRpcAccount, publicKey, Umi } from "@metaplex-foundation/umi";
|
3
|
+
import { LendingPlatform } from "../generated";
|
3
4
|
|
4
5
|
export function consoleLog(...args: any[]): void {
|
5
6
|
if ((globalThis as any).LOCAL_TEST) {
|
@@ -98,3 +99,13 @@ export function retryWithExponentialBackoff<T>(
|
|
98
99
|
return attempt(0);
|
99
100
|
});
|
100
101
|
}
|
102
|
+
|
103
|
+
export function toEnumValue<E extends object>(enumObj: E, value: number): E[keyof E] | undefined {
|
104
|
+
const numericValues = Object.values(enumObj).filter(v => typeof v === "number") as number[];
|
105
|
+
|
106
|
+
if (numericValues.includes(value)) {
|
107
|
+
return value as E[keyof E];
|
108
|
+
}
|
109
|
+
|
110
|
+
return undefined;
|
111
|
+
}
|
@@ -27,6 +27,7 @@ import {
|
|
27
27
|
fromBaseUnit,
|
28
28
|
getLiqUtilzationRateBps,
|
29
29
|
toBaseUnit,
|
30
|
+
toBps,
|
30
31
|
} from "../numberUtils";
|
31
32
|
import { getReferralState } from "../accountUtils";
|
32
33
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
@@ -38,6 +39,7 @@ import {
|
|
38
39
|
import {
|
39
40
|
findMarginfiAccounts,
|
40
41
|
getAllMarginfiAccountsByAuthority,
|
42
|
+
getMaxLtvAndLiqThreshold,
|
41
43
|
} from "../marginfiUtils";
|
42
44
|
import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
|
43
45
|
import { fetchTokenPrices } from "../priceUtils";
|
@@ -587,6 +589,30 @@ export function createSolautoSettings(
|
|
587
589
|
};
|
588
590
|
}
|
589
591
|
|
592
|
+
export async function getMaxLtvBpsAndLiqThresholdBps(
|
593
|
+
umi: Umi,
|
594
|
+
lendingPlatform: LendingPlatform,
|
595
|
+
lendingPool: PublicKey,
|
596
|
+
supplyMint: PublicKey,
|
597
|
+
debtMint: PublicKey,
|
598
|
+
supplyPrice: number
|
599
|
+
) {
|
600
|
+
let maxLtv: number = 0;
|
601
|
+
let liqThreshold: number = 0;
|
602
|
+
if (lendingPlatform === LendingPlatform.Marginfi) {
|
603
|
+
[maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(
|
604
|
+
umi,
|
605
|
+
lendingPool,
|
606
|
+
{ mint: supplyMint },
|
607
|
+
{ mint: debtMint },
|
608
|
+
supplyPrice
|
609
|
+
);
|
610
|
+
}
|
611
|
+
// TODO: PK
|
612
|
+
|
613
|
+
return [toBps(maxLtv), toBps(liqThreshold)];
|
614
|
+
}
|
615
|
+
|
590
616
|
type PositionAdjustment =
|
591
617
|
| { type: "supply"; value: bigint }
|
592
618
|
| { type: "debt"; value: bigint }
|
@@ -54,20 +54,20 @@ describe("Solauto Marginfi tests", async () => {
|
|
54
54
|
const supplyDecimals = 6;
|
55
55
|
const debtDecimals = 6;
|
56
56
|
|
57
|
-
await client.initialize({
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
});
|
69
|
-
|
70
|
-
|
57
|
+
// await client.initialize({
|
58
|
+
// signer,
|
59
|
+
// positionId,
|
60
|
+
// authority: new PublicKey("5FALSVLRjuRZHSmQVdT2RUZC6KadCuDmxY7gaQFWFBxf"),
|
61
|
+
// // new: true,
|
62
|
+
// // marginfiAccount: new PublicKey(
|
63
|
+
// // "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
|
64
|
+
// // ),
|
65
|
+
// // marginfiGroup: new PublicKey("G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"),
|
66
|
+
// // supplyMint: new PublicKey("3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump"),
|
67
|
+
// // debtMint: new PublicKey(USDC),
|
68
|
+
// });
|
69
|
+
|
70
|
+
console.log(await getSolautoManagedPositions(client.umi));
|
71
71
|
|
72
72
|
const transactionItems: TransactionItem[] = [];
|
73
73
|
// const settingParams: SolautoSettingsParametersInpArgs = {
|
@@ -163,14 +163,14 @@ describe("Solauto Marginfi tests", async () => {
|
|
163
163
|
// )
|
164
164
|
// );
|
165
165
|
|
166
|
-
const statuses = await new TransactionsManager(
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
).clientSend(transactionItems);
|
166
|
+
// const statuses = await new TransactionsManager(
|
167
|
+
// client,
|
168
|
+
// undefined,
|
169
|
+
// !payForTransactions ? "only-simulate" : "normal",
|
170
|
+
// PriorityFeeSetting.Low,
|
171
|
+
// true
|
172
|
+
// ).clientSend(transactionItems);
|
173
173
|
|
174
|
-
console.log(statuses);
|
174
|
+
// console.log(statuses);
|
175
175
|
});
|
176
176
|
});
|