@haven-fi/solauto-sdk 1.0.483 → 1.0.484
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.d.ts +1 -2
- package/dist/constants/tokenConstants.d.ts.map +1 -1
- package/dist/utils/generalUtils.d.ts +4 -0
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +28 -1
- package/dist/utils/index.d.ts +10 -9
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.js +1 -0
- package/dist/utils/stringUtils.d.ts +6 -0
- package/dist/utils/stringUtils.d.ts.map +1 -0
- package/dist/utils/stringUtils.js +61 -0
- package/local/logPositions.ts +1 -58
- package/package.json +1 -1
- package/src/constants/tokenConstants.ts +1 -1
- package/src/utils/generalUtils.ts +38 -5
- package/src/utils/index.ts +10 -9
- package/src/utils/jupiterUtils.ts +1 -0
- package/src/utils/stringUtils.ts +69 -0
- package/tests/transactions/solautoMarginfi.ts +6 -6
@@ -21,7 +21,7 @@ export declare const RETARDIO = "6ogzHhzdrQr9Pgv6hZ2MNze7UrzBMAFyBBWUYp1Fhitx";
|
|
21
21
|
export declare const BILLY = "3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump";
|
22
22
|
export declare const HMTR = "7JhmUcZrrfhyt5nTSu3AfsrUq2L9992a7AhwdSDxdoL2";
|
23
23
|
export declare const ALL_SUPPORTED_TOKENS: string[];
|
24
|
-
interface TokenInfo {
|
24
|
+
export interface TokenInfo {
|
25
25
|
ticker: string;
|
26
26
|
decimals: number;
|
27
27
|
isStableCoin?: boolean;
|
@@ -32,5 +32,4 @@ interface TokenInfo {
|
|
32
32
|
export declare const TOKEN_INFO: {
|
33
33
|
[key: string]: TokenInfo;
|
34
34
|
};
|
35
|
-
export {};
|
36
35
|
//# sourceMappingURL=tokenConstants.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"tokenConstants.d.ts","sourceRoot":"","sources":["../../src/constants/tokenConstants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK,gDAAgD,CAAC;AACnE,eAAO,MAAM,QAAQ,iDAAiD,CAAC;AACvE,eAAO,MAAM,GAAG,gDAAgD,CAAC;AACjE,eAAO,MAAM,KAAK,gDAAgD,CAAC;AACnE,eAAO,MAAM,GAAG,iDAAiD,CAAC;AAClE,eAAO,MAAM,KAAK,gDAAgD,CAAC;AACnE,eAAO,MAAM,OAAO,gDAAgD,CAAC;AACrE,eAAO,MAAM,GAAG,gDAAgD,CAAC;AACjE,eAAO,MAAM,GAAG,gDAAgD,CAAC;AACjE,eAAO,MAAM,GAAG,iDAAiD,CAAC;AAClE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AACnE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AACnE,eAAO,MAAM,GAAG,gDAAgD,CAAC;AACjE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AACnE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AACnE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AACnE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AACnE,eAAO,MAAM,GAAG,iDAAiD,CAAC;AAClE,eAAO,MAAM,MAAM,iDAAiD,CAAC;AACrE,eAAO,MAAM,QAAQ,iDAAiD,CAAC;AACvE,eAAO,MAAM,KAAK,iDAAiD,CAAC;AACpE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AAEnE,eAAO,MAAM,oBAAoB,UAwBhC,CAAC;AAEF,
|
1
|
+
{"version":3,"file":"tokenConstants.d.ts","sourceRoot":"","sources":["../../src/constants/tokenConstants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,KAAK,gDAAgD,CAAC;AACnE,eAAO,MAAM,QAAQ,iDAAiD,CAAC;AACvE,eAAO,MAAM,GAAG,gDAAgD,CAAC;AACjE,eAAO,MAAM,KAAK,gDAAgD,CAAC;AACnE,eAAO,MAAM,GAAG,iDAAiD,CAAC;AAClE,eAAO,MAAM,KAAK,gDAAgD,CAAC;AACnE,eAAO,MAAM,OAAO,gDAAgD,CAAC;AACrE,eAAO,MAAM,GAAG,gDAAgD,CAAC;AACjE,eAAO,MAAM,GAAG,gDAAgD,CAAC;AACjE,eAAO,MAAM,GAAG,iDAAiD,CAAC;AAClE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AACnE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AACnE,eAAO,MAAM,GAAG,gDAAgD,CAAC;AACjE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AACnE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AACnE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AACnE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AACnE,eAAO,MAAM,GAAG,iDAAiD,CAAC;AAClE,eAAO,MAAM,MAAM,iDAAiD,CAAC;AACrE,eAAO,MAAM,QAAQ,iDAAiD,CAAC;AACvE,eAAO,MAAM,KAAK,iDAAiD,CAAC;AACpE,eAAO,MAAM,IAAI,iDAAiD,CAAC;AAEnE,eAAO,MAAM,oBAAoB,UAwBhC,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,UAAU,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAmHlD,CAAC"}
|
@@ -1,6 +1,10 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { MaybeRpcAccount, Umi } from "@metaplex-foundation/umi";
|
3
|
+
import { TokenInfo } from "../constants";
|
3
4
|
export declare function consoleLog(...args: any[]): void;
|
5
|
+
export declare function tokenInfo(mint?: PublicKey): TokenInfo;
|
6
|
+
export declare function findMintByTicker(ticker: string): PublicKey;
|
7
|
+
export declare function tokenInfoByTicker(ticker: string): TokenInfo | undefined;
|
4
8
|
export declare function generateRandomU8(): number;
|
5
9
|
export declare function generateRandomU64(): bigint;
|
6
10
|
export declare function currentUnixSeconds(): number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAc,SAAS,EAAE,MAAM,cAAc,CAAC;AAErD,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAI/C;AAED,wBAAgB,SAAS,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,CAErD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAW1D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,yBAQ/C;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,SAAS,GACZ,OAAO,CAAC,OAAO,CAAC,CAKlB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEnE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAU1E;AAED,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAS1D;AAED,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC,CAAC;AAEjE,wBAAgB,2BAA2B,CAAC,CAAC,EAC3C,EAAE,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,EACvD,OAAO,GAAE,MAAU,EACnB,KAAK,GAAE,MAAY,EACnB,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,CAAC,CAAC,CA8BZ;AAED,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAC1C,OAAO,EAAE,CAAC,EACV,KAAK,EAAE,MAAM,GACZ,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAUxB"}
|
@@ -1,6 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.consoleLog = consoleLog;
|
4
|
+
exports.tokenInfo = tokenInfo;
|
5
|
+
exports.findMintByTicker = findMintByTicker;
|
6
|
+
exports.tokenInfoByTicker = tokenInfoByTicker;
|
4
7
|
exports.generateRandomU8 = generateRandomU8;
|
5
8
|
exports.generateRandomU64 = generateRandomU64;
|
6
9
|
exports.currentUnixSeconds = currentUnixSeconds;
|
@@ -10,12 +13,36 @@ exports.arraysAreEqual = arraysAreEqual;
|
|
10
13
|
exports.zip = zip;
|
11
14
|
exports.retryWithExponentialBackoff = retryWithExponentialBackoff;
|
12
15
|
exports.toEnumValue = toEnumValue;
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
13
17
|
const umi_1 = require("@metaplex-foundation/umi");
|
18
|
+
const constants_1 = require("../constants");
|
14
19
|
function consoleLog(...args) {
|
15
20
|
if (globalThis.LOCAL_TEST) {
|
16
21
|
console.log(...args);
|
17
22
|
}
|
18
23
|
}
|
24
|
+
function tokenInfo(mint) {
|
25
|
+
return constants_1.TOKEN_INFO[mint ? mint.toString() : web3_js_1.PublicKey.default.toString()];
|
26
|
+
}
|
27
|
+
function findMintByTicker(ticker) {
|
28
|
+
for (const key in constants_1.TOKEN_INFO) {
|
29
|
+
const account = constants_1.TOKEN_INFO[key];
|
30
|
+
if (account.ticker.toString().toLowerCase() ===
|
31
|
+
ticker.toString().toLowerCase()) {
|
32
|
+
return new web3_js_1.PublicKey(key);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
throw new Error(`Token mint not found by the ticker: ${ticker}`);
|
36
|
+
}
|
37
|
+
function tokenInfoByTicker(ticker) {
|
38
|
+
for (const key in constants_1.TOKEN_INFO) {
|
39
|
+
const token = constants_1.TOKEN_INFO[key];
|
40
|
+
if (token.ticker.toLowerCase() === ticker.toLowerCase()) {
|
41
|
+
return token;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
return undefined;
|
45
|
+
}
|
19
46
|
function generateRandomU8() {
|
20
47
|
return Math.floor(Math.random() * 255 + 1);
|
21
48
|
}
|
@@ -87,7 +114,7 @@ function retryWithExponentialBackoff(fn, retries = 5, delay = 150, errorsToThrow
|
|
87
114
|
});
|
88
115
|
}
|
89
116
|
function toEnumValue(enumObj, value) {
|
90
|
-
const numericValues = Object.values(enumObj).filter(v => typeof v === "number");
|
117
|
+
const numericValues = Object.values(enumObj).filter((v) => typeof v === "number");
|
91
118
|
if (numericValues.includes(value)) {
|
92
119
|
return value;
|
93
120
|
}
|
package/dist/utils/index.d.ts
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
export * from
|
2
|
-
export * from
|
3
|
-
export * from
|
4
|
-
export * from
|
5
|
-
export * from
|
6
|
-
export * from
|
7
|
-
export * from
|
8
|
-
export * from
|
9
|
-
export * from
|
1
|
+
export * from "./solauto/index";
|
2
|
+
export * from "./accountUtils";
|
3
|
+
export * from "./generalUtils";
|
4
|
+
export * from "./jupiterUtils";
|
5
|
+
export * from "./marginfiUtils";
|
6
|
+
export * from "./numberUtils";
|
7
|
+
export * from "./solanaUtils";
|
8
|
+
export * from "./stringUtils";
|
9
|
+
export * from "./priceUtils";
|
10
|
+
export * from "./switchboardUtils";
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
package/dist/utils/index.js
CHANGED
@@ -21,5 +21,6 @@ __exportStar(require("./jupiterUtils"), exports);
|
|
21
21
|
__exportStar(require("./marginfiUtils"), exports);
|
22
22
|
__exportStar(require("./numberUtils"), exports);
|
23
23
|
__exportStar(require("./solanaUtils"), exports);
|
24
|
+
__exportStar(require("./stringUtils"), exports);
|
24
25
|
__exportStar(require("./priceUtils"), exports);
|
25
26
|
__exportStar(require("./switchboardUtils"), exports);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,
|
1
|
+
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,CAsG7B;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,CAAC,EAAE,OAAO;;GA0B5E"}
|
@@ -25,6 +25,7 @@ function createTransactionInstruction(instruction) {
|
|
25
25
|
async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
|
26
26
|
const memecoinSwap = constants_1.TOKEN_INFO[swapDetails.inputMint.toString()].isMeme ||
|
27
27
|
constants_1.TOKEN_INFO[swapDetails.outputMint.toString()].isMeme;
|
28
|
+
// TEMP REVERT ME
|
28
29
|
const usingPyth = swapDetails.inputMint.equals(new web3_js_1.PublicKey(constants_1.PYTH)) ||
|
29
30
|
swapDetails.outputMint.equals(new web3_js_1.PublicKey(constants_1.PYTH));
|
30
31
|
const quoteResponse = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await jupApi.quoteGet({
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
2
|
+
export declare const StrategyTypes: readonly ["Long", "Short", "Ratio"];
|
3
|
+
export type StrategyType = (typeof StrategyTypes)[number];
|
4
|
+
export declare function solautoStrategyName(supplyMint?: PublicKey, debtMint?: PublicKey): string;
|
5
|
+
export declare function strategyType(supplyMint: PublicKey, debtMint: PublicKey): StrategyType;
|
6
|
+
//# sourceMappingURL=stringUtils.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"stringUtils.d.ts","sourceRoot":"","sources":["../../src/utils/stringUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,eAAO,MAAM,aAAa,qCAAsC,CAAC;AACjE,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAoB1D,wBAAgB,mBAAmB,CACjC,UAAU,CAAC,EAAE,SAAS,EACtB,QAAQ,CAAC,EAAE,SAAS,UAwBrB;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,SAAS,EACrB,QAAQ,EAAE,SAAS,GAClB,YAAY,CAWd"}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.StrategyTypes = void 0;
|
4
|
+
exports.solautoStrategyName = solautoStrategyName;
|
5
|
+
exports.strategyType = strategyType;
|
6
|
+
const spl_token_1 = require("@solana/spl-token");
|
7
|
+
const constants_1 = require("../constants");
|
8
|
+
const web3_js_1 = require("@solana/web3.js");
|
9
|
+
const generalUtils_1 = require("./generalUtils");
|
10
|
+
exports.StrategyTypes = ["Long", "Short", "Ratio"];
|
11
|
+
const MAJORS_PRIO = {
|
12
|
+
[constants_1.WBTC.toString()]: 0,
|
13
|
+
[constants_1.WETH.toString()]: 1,
|
14
|
+
[spl_token_1.NATIVE_MINT.toString()]: 2,
|
15
|
+
};
|
16
|
+
function adjustedTicker(mint) {
|
17
|
+
const info = (0, generalUtils_1.tokenInfo)(mint);
|
18
|
+
if (info.ticker.toLowerCase() === "wbtc") {
|
19
|
+
return "BTC";
|
20
|
+
}
|
21
|
+
else if (info.ticker.toLowerCase() === "weth") {
|
22
|
+
return "ETH";
|
23
|
+
}
|
24
|
+
else {
|
25
|
+
return info.ticker;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
function solautoStrategyName(supplyMint, debtMint) {
|
29
|
+
const supplyInfo = (0, generalUtils_1.tokenInfo)(supplyMint);
|
30
|
+
const strat = strategyType(supplyMint ?? web3_js_1.PublicKey.default, debtMint ?? web3_js_1.PublicKey.default);
|
31
|
+
if (strat === "Long") {
|
32
|
+
return `${adjustedTicker(supplyMint)} Long`;
|
33
|
+
}
|
34
|
+
else if (strat === "Ratio") {
|
35
|
+
if ((supplyInfo.isLST && debtMint?.equals(spl_token_1.NATIVE_MINT)) ||
|
36
|
+
(supplyMint &&
|
37
|
+
debtMint &&
|
38
|
+
MAJORS_PRIO[supplyMint.toString()] > MAJORS_PRIO[debtMint.toString()])) {
|
39
|
+
return `${adjustedTicker(supplyMint)}/${adjustedTicker(debtMint)} Long`;
|
40
|
+
}
|
41
|
+
else {
|
42
|
+
return `${adjustedTicker(debtMint)}/${adjustedTicker(supplyMint)} Short`;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
return `${adjustedTicker(debtMint)} Short`;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
function strategyType(supplyMint, debtMint) {
|
50
|
+
const supplyInfo = (0, generalUtils_1.tokenInfo)(supplyMint);
|
51
|
+
const debtInfo = (0, generalUtils_1.tokenInfo)(debtMint);
|
52
|
+
if (!supplyInfo.isStableCoin && !debtInfo.isStableCoin) {
|
53
|
+
return "Ratio";
|
54
|
+
}
|
55
|
+
else if (debtInfo.isStableCoin) {
|
56
|
+
return "Long";
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
return "Short";
|
60
|
+
}
|
61
|
+
}
|
package/local/logPositions.ts
CHANGED
@@ -13,16 +13,13 @@ import {
|
|
13
13
|
safeFetchAllSolautoPosition,
|
14
14
|
safeGetPrice,
|
15
15
|
SOLAUTO_PROD_PROGRAM,
|
16
|
-
|
16
|
+
solautoStrategyName,
|
17
17
|
USD_DECIMALS,
|
18
|
-
WBTC,
|
19
|
-
WETH,
|
20
18
|
} from "../src";
|
21
19
|
import { PublicKey } from "@solana/web3.js";
|
22
20
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
23
21
|
import path from "path";
|
24
22
|
import { config } from "dotenv";
|
25
|
-
import { NATIVE_MINT } from "@solana/spl-token";
|
26
23
|
|
27
24
|
config({ path: path.join(__dirname, ".env") });
|
28
25
|
|
@@ -34,60 +31,6 @@ function getBatches<T>(items: T[], batchSize: number): T[][] {
|
|
34
31
|
return batches;
|
35
32
|
}
|
36
33
|
|
37
|
-
export function tokenInfo(mint?: PublicKey) {
|
38
|
-
return TOKEN_INFO[mint ? mint.toString() : PublicKey.default.toString()];
|
39
|
-
}
|
40
|
-
|
41
|
-
type StrategyType = "Long" | "Ratio" | "Short";
|
42
|
-
|
43
|
-
const MAJORS_PRIO = {
|
44
|
-
[WBTC.toString()]: 0,
|
45
|
-
[WETH.toString()]: 1,
|
46
|
-
[NATIVE_MINT.toString()]: 2,
|
47
|
-
};
|
48
|
-
|
49
|
-
function solautoStrategyName(supplyMint?: PublicKey, debtMint?: PublicKey) {
|
50
|
-
const supplyInfo = tokenInfo(supplyMint);
|
51
|
-
const debtInfo = tokenInfo(debtMint);
|
52
|
-
const strat = strategyType(
|
53
|
-
supplyMint ?? PublicKey.default,
|
54
|
-
debtMint ?? PublicKey.default
|
55
|
-
);
|
56
|
-
|
57
|
-
if (strat === "Long") {
|
58
|
-
return `${supplyInfo.ticker} Long`;
|
59
|
-
} else if (strat === "Ratio") {
|
60
|
-
if (
|
61
|
-
(supplyInfo.isLST && debtMint?.equals(NATIVE_MINT)) ||
|
62
|
-
(supplyMint &&
|
63
|
-
debtMint &&
|
64
|
-
MAJORS_PRIO[supplyMint!.toString()] > MAJORS_PRIO[debtMint!.toString()])
|
65
|
-
) {
|
66
|
-
return `${supplyInfo.ticker}/${debtInfo.ticker} Long`;
|
67
|
-
} else {
|
68
|
-
return `${debtInfo.ticker}/${supplyInfo.ticker} Short`;
|
69
|
-
}
|
70
|
-
} else {
|
71
|
-
return `${debtInfo.ticker} Short`;
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
function strategyType(
|
76
|
-
supplyMint: PublicKey,
|
77
|
-
debtMint: PublicKey
|
78
|
-
): StrategyType {
|
79
|
-
const supplyInfo = tokenInfo(supplyMint);
|
80
|
-
const debtInfo = tokenInfo(debtMint);
|
81
|
-
|
82
|
-
if (!supplyInfo.isStableCoin && !debtInfo.isStableCoin) {
|
83
|
-
return "Ratio";
|
84
|
-
} else if (debtInfo.isStableCoin) {
|
85
|
-
return "Long";
|
86
|
-
} else {
|
87
|
-
return "Short";
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
34
|
export function roundToDecimals(value: number, decimals: number = 2): number {
|
92
35
|
if (!value || isNaN(value)) {
|
93
36
|
return value;
|
package/package.json
CHANGED
@@ -1,12 +1,40 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { MaybeRpcAccount, publicKey, Umi } from "@metaplex-foundation/umi";
|
3
|
-
import {
|
3
|
+
import { TOKEN_INFO, TokenInfo } from "../constants";
|
4
4
|
|
5
5
|
export function consoleLog(...args: any[]): void {
|
6
6
|
if ((globalThis as any).LOCAL_TEST) {
|
7
7
|
console.log(...args);
|
8
8
|
}
|
9
9
|
}
|
10
|
+
|
11
|
+
export function tokenInfo(mint?: PublicKey): TokenInfo {
|
12
|
+
return TOKEN_INFO[mint ? mint.toString() : PublicKey.default.toString()];
|
13
|
+
}
|
14
|
+
|
15
|
+
export function findMintByTicker(ticker: string): PublicKey {
|
16
|
+
for (const key in TOKEN_INFO) {
|
17
|
+
const account = TOKEN_INFO[key];
|
18
|
+
if (
|
19
|
+
account.ticker.toString().toLowerCase() ===
|
20
|
+
ticker.toString().toLowerCase()
|
21
|
+
) {
|
22
|
+
return new PublicKey(key);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
throw new Error(`Token mint not found by the ticker: ${ticker}`);
|
26
|
+
}
|
27
|
+
|
28
|
+
export function tokenInfoByTicker(ticker: string) {
|
29
|
+
for (const key in TOKEN_INFO) {
|
30
|
+
const token = TOKEN_INFO[key];
|
31
|
+
if (token.ticker.toLowerCase() === ticker.toLowerCase()) {
|
32
|
+
return token;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
return undefined;
|
36
|
+
}
|
37
|
+
|
10
38
|
export function generateRandomU8(): number {
|
11
39
|
return Math.floor(Math.random() * 255 + 1);
|
12
40
|
}
|
@@ -100,12 +128,17 @@ export function retryWithExponentialBackoff<T>(
|
|
100
128
|
});
|
101
129
|
}
|
102
130
|
|
103
|
-
export function toEnumValue<E extends object>(
|
104
|
-
|
131
|
+
export function toEnumValue<E extends object>(
|
132
|
+
enumObj: E,
|
133
|
+
value: number
|
134
|
+
): E[keyof E] | undefined {
|
135
|
+
const numericValues = Object.values(enumObj).filter(
|
136
|
+
(v) => typeof v === "number"
|
137
|
+
) as number[];
|
105
138
|
|
106
139
|
if (numericValues.includes(value)) {
|
107
140
|
return value as E[keyof E];
|
108
141
|
}
|
109
|
-
|
142
|
+
|
110
143
|
return undefined;
|
111
|
-
}
|
144
|
+
}
|
package/src/utils/index.ts
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
export * from
|
2
|
-
export * from
|
3
|
-
export * from
|
4
|
-
export * from
|
5
|
-
export * from
|
6
|
-
export * from
|
7
|
-
export * from
|
8
|
-
export * from
|
9
|
-
export * from
|
1
|
+
export * from "./solauto/index";
|
2
|
+
export * from "./accountUtils";
|
3
|
+
export * from "./generalUtils";
|
4
|
+
export * from "./jupiterUtils";
|
5
|
+
export * from "./marginfiUtils";
|
6
|
+
export * from "./numberUtils";
|
7
|
+
export * from "./solanaUtils";
|
8
|
+
export * from "./stringUtils";
|
9
|
+
export * from "./priceUtils";
|
10
|
+
export * from "./switchboardUtils";
|
@@ -60,6 +60,7 @@ export async function getJupSwapTransaction(
|
|
60
60
|
TOKEN_INFO[swapDetails.inputMint.toString()].isMeme ||
|
61
61
|
TOKEN_INFO[swapDetails.outputMint.toString()].isMeme;
|
62
62
|
|
63
|
+
// TEMP REVERT ME
|
63
64
|
const usingPyth =
|
64
65
|
swapDetails.inputMint.equals(new PublicKey(PYTH)) ||
|
65
66
|
swapDetails.outputMint.equals(new PublicKey(PYTH));
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import { NATIVE_MINT } from "@solana/spl-token";
|
2
|
+
import { WBTC, WETH } from "../constants";
|
3
|
+
import { PublicKey } from "@solana/web3.js";
|
4
|
+
import { tokenInfo } from "./generalUtils";
|
5
|
+
|
6
|
+
export const StrategyTypes = ["Long", "Short", "Ratio"] as const;
|
7
|
+
export type StrategyType = (typeof StrategyTypes)[number];
|
8
|
+
|
9
|
+
const MAJORS_PRIO = {
|
10
|
+
[WBTC.toString()]: 0,
|
11
|
+
[WETH.toString()]: 1,
|
12
|
+
[NATIVE_MINT.toString()]: 2,
|
13
|
+
};
|
14
|
+
|
15
|
+
function adjustedTicker(mint?: PublicKey) {
|
16
|
+
const info = tokenInfo(mint);
|
17
|
+
|
18
|
+
if (info.ticker.toLowerCase() === "wbtc") {
|
19
|
+
return "BTC";
|
20
|
+
} else if (info.ticker.toLowerCase() === "weth") {
|
21
|
+
return "ETH";
|
22
|
+
} else {
|
23
|
+
return info.ticker;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
export function solautoStrategyName(
|
28
|
+
supplyMint?: PublicKey,
|
29
|
+
debtMint?: PublicKey
|
30
|
+
) {
|
31
|
+
const supplyInfo = tokenInfo(supplyMint);
|
32
|
+
const strat = strategyType(
|
33
|
+
supplyMint ?? PublicKey.default,
|
34
|
+
debtMint ?? PublicKey.default
|
35
|
+
);
|
36
|
+
|
37
|
+
if (strat === "Long") {
|
38
|
+
return `${adjustedTicker(supplyMint)} Long`;
|
39
|
+
} else if (strat === "Ratio") {
|
40
|
+
if (
|
41
|
+
(supplyInfo.isLST && debtMint?.equals(NATIVE_MINT)) ||
|
42
|
+
(supplyMint &&
|
43
|
+
debtMint &&
|
44
|
+
MAJORS_PRIO[supplyMint!.toString()] > MAJORS_PRIO[debtMint!.toString()])
|
45
|
+
) {
|
46
|
+
return `${adjustedTicker(supplyMint)}/${adjustedTicker(debtMint)} Long`;
|
47
|
+
} else {
|
48
|
+
return `${adjustedTicker(debtMint)}/${adjustedTicker(supplyMint)} Short`;
|
49
|
+
}
|
50
|
+
} else {
|
51
|
+
return `${adjustedTicker(debtMint)} Short`;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
export function strategyType(
|
56
|
+
supplyMint: PublicKey,
|
57
|
+
debtMint: PublicKey
|
58
|
+
): StrategyType {
|
59
|
+
const supplyInfo = tokenInfo(supplyMint);
|
60
|
+
const debtInfo = tokenInfo(debtMint);
|
61
|
+
|
62
|
+
if (!supplyInfo.isStableCoin && !debtInfo.isStableCoin) {
|
63
|
+
return "Ratio";
|
64
|
+
} else if (debtInfo.isStableCoin) {
|
65
|
+
return "Long";
|
66
|
+
} else {
|
67
|
+
return "Short";
|
68
|
+
}
|
69
|
+
}
|
@@ -51,12 +51,12 @@ export function getFlooredTimestampByMinute(
|
|
51
51
|
}
|
52
52
|
|
53
53
|
describe("Solauto Marginfi tests", async () => {
|
54
|
-
|
55
|
-
const signer = setupTest("solauto-manager");
|
54
|
+
const signer = setupTest();
|
55
|
+
// const signer = setupTest("solauto-manager");
|
56
56
|
|
57
|
-
const payForTransactions =
|
57
|
+
const payForTransactions = false;
|
58
58
|
const testProgram = false;
|
59
|
-
const positionId =
|
59
|
+
const positionId = 3;
|
60
60
|
|
61
61
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
62
62
|
const client = new SolautoMarginfiClient(
|
@@ -72,7 +72,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
72
72
|
await client.initialize({
|
73
73
|
signer,
|
74
74
|
positionId,
|
75
|
-
authority: new PublicKey("
|
75
|
+
authority: new PublicKey("7GMmfZdCgJSCawA7roGiGgvueU3XoEHQXUtiCnuDYUde"),
|
76
76
|
// new: true,
|
77
77
|
// marginfiAccount: new PublicKey(
|
78
78
|
// ""
|
@@ -169,7 +169,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
169
169
|
transactionItems.push(
|
170
170
|
new TransactionItem(
|
171
171
|
async (attemptNum) =>
|
172
|
-
await buildSolautoRebalanceTransaction(client,
|
172
|
+
await buildSolautoRebalanceTransaction(client, 4000, attemptNum),
|
173
173
|
"rebalance"
|
174
174
|
)
|
175
175
|
);
|