@haven-fi/solauto-sdk 1.0.624 → 1.0.625
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/{generalAccounts.d.ts → generalConstants.d.ts} +3 -1
- package/dist/constants/generalConstants.d.ts.map +1 -0
- package/dist/constants/{generalAccounts.js → generalConstants.js} +4 -1
- package/dist/constants/index.d.ts +6 -5
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +2 -1
- package/dist/constants/marginfiAccounts.d.ts +4 -1
- package/dist/constants/marginfiAccounts.d.ts.map +1 -1
- package/dist/constants/marginfiAccounts.js +7 -5
- package/dist/constants/solautoConstants.d.ts +0 -3
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +3 -8
- package/dist/services/flashLoans/flProviderAggregator.d.ts +3 -3
- package/dist/services/flashLoans/flProviderAggregator.d.ts.map +1 -1
- package/dist/services/flashLoans/flProviderAggregator.js +5 -5
- package/dist/services/flashLoans/flProviderBase.d.ts +4 -3
- package/dist/services/flashLoans/flProviderBase.d.ts.map +1 -1
- package/dist/services/flashLoans/flProviderBase.js +3 -2
- package/dist/services/flashLoans/marginfiFlProvider.d.ts +2 -2
- package/dist/services/flashLoans/marginfiFlProvider.d.ts.map +1 -1
- package/dist/services/flashLoans/marginfiFlProvider.js +2 -3
- package/dist/services/rebalance/rebalanceSwapManager.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceSwapManager.js +1 -1
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts.map +1 -1
- package/dist/services/rebalance/rebalanceTxBuilder.js +4 -4
- package/dist/services/rebalance/rebalanceValues.d.ts.map +1 -1
- package/dist/services/rebalance/solautoFees.d.ts.map +1 -1
- package/dist/services/rebalance/solautoFees.js +4 -2
- package/dist/services/solauto/solautoClient.d.ts +4 -3
- package/dist/services/solauto/solautoClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoClient.js +21 -24
- package/dist/services/solauto/solautoMarginfiClient.d.ts +3 -4
- package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoMarginfiClient.js +19 -20
- package/dist/services/solauto/txHandler.d.ts +4 -2
- package/dist/services/solauto/txHandler.d.ts.map +1 -1
- package/dist/services/solauto/txHandler.js +4 -6
- package/dist/services/swap/jupSwapManager.d.ts +1 -1
- package/dist/services/swap/jupSwapManager.d.ts.map +1 -1
- package/dist/services/swap/jupSwapManager.js +7 -10
- package/dist/services/transactions/transactionUtils.d.ts +2 -3
- package/dist/services/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/services/transactions/transactionUtils.js +43 -46
- package/dist/services/transactions/transactionsManager.d.ts +2 -3
- package/dist/services/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/services/transactions/transactionsManager.js +16 -20
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.js +1 -1
- package/dist/solautoPosition/solautoPositionEx.d.ts +1 -1
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/solautoPositionEx.js +1 -1
- package/dist/solautoPosition/utils.d.ts +2 -2
- package/dist/solautoPosition/utils.d.ts.map +1 -1
- package/dist/solautoPosition/utils.js +2 -2
- package/dist/types/solauto.d.ts +1 -0
- package/dist/types/solauto.d.ts.map +1 -1
- package/dist/utils/generalUtils.d.ts +2 -0
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +9 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +7 -8
- package/dist/utils/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.d.ts +7 -3
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +50 -19
- package/dist/utils/numberUtils.d.ts.map +1 -1
- package/dist/utils/priceUtils.d.ts.map +1 -1
- package/dist/utils/priceUtils.js +13 -15
- package/dist/utils/solanaUtils.d.ts +3 -5
- package/dist/utils/solanaUtils.d.ts.map +1 -1
- package/dist/utils/solanaUtils.js +7 -15
- package/dist/utils/solautoUtils.d.ts +3 -3
- package/dist/utils/solautoUtils.d.ts.map +1 -1
- package/dist/utils/solautoUtils.js +5 -5
- package/dist/utils/stringUtils.d.ts.map +1 -1
- package/dist/utils/stringUtils.js +3 -3
- package/dist/utils/switchboardUtils.d.ts +1 -1
- package/dist/utils/switchboardUtils.d.ts.map +1 -1
- package/dist/utils/switchboardUtils.js +4 -4
- package/local/createISMAccounts.ts +29 -12
- package/local/createTokenAccounts.ts +12 -11
- package/local/logPositions.ts +5 -5
- package/local/shared.ts +16 -10
- package/local/txSandbox.ts +5 -5
- package/local/updateMarginfiLUT.ts +35 -41
- package/local/updateSolautoLUT.ts +11 -13
- package/package.json +1 -1
- package/src/constants/{generalAccounts.ts → generalConstants.ts} +6 -1
- package/src/constants/index.ts +6 -5
- package/src/constants/marginfiAccounts.ts +15 -6
- package/src/constants/solautoConstants.ts +2 -10
- package/src/services/flashLoans/flProviderAggregator.ts +9 -7
- package/src/services/flashLoans/flProviderBase.ts +5 -4
- package/src/services/flashLoans/marginfiFlProvider.ts +3 -4
- package/src/services/rebalance/rebalanceSwapManager.ts +1 -1
- package/src/services/rebalance/rebalanceTxBuilder.ts +5 -5
- package/src/services/rebalance/rebalanceValues.ts +1 -1
- package/src/services/rebalance/solautoFees.ts +3 -4
- package/src/services/solauto/solautoClient.ts +9 -15
- package/src/services/solauto/solautoMarginfiClient.ts +21 -23
- package/src/services/solauto/txHandler.ts +10 -9
- package/src/services/swap/jupSwapManager.ts +7 -6
- package/src/services/transactions/transactionUtils.ts +17 -18
- package/src/services/transactions/transactionsManager.ts +23 -22
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +1 -2
- package/src/solautoPosition/solautoPositionEx.ts +5 -5
- package/src/solautoPosition/utils.ts +7 -7
- package/src/types/solauto.ts +2 -0
- package/src/utils/generalUtils.ts +9 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/jitoUtils.ts +17 -14
- package/src/utils/jupiterUtils.ts +1 -1
- package/src/utils/marginfiUtils.ts +56 -14
- package/src/utils/numberUtils.ts +0 -1
- package/src/utils/priceUtils.ts +7 -5
- package/src/utils/solanaUtils.ts +24 -32
- package/src/utils/solautoUtils.ts +13 -13
- package/src/utils/stringUtils.ts +3 -3
- package/src/utils/switchboardUtils.ts +4 -4
- package/tests/transactions/shared.ts +9 -14
- package/tests/transactions/solautoMarginfi.ts +13 -3
- package/tests/unit/accounts.ts +14 -17
- package/tests/unit/lookupTables.ts +5 -5
- package/tests/unit/rebalanceCalculations.ts +17 -11
- package/README.md +0 -3
- package/dist/constants/generalAccounts.d.ts.map +0 -1
- package/src/constants/README.md +0 -7
package/dist/utils/priceUtils.js
CHANGED
@@ -29,21 +29,19 @@ exports.getSwitchboardPrices = getSwitchboardPrices;
|
|
29
29
|
exports.getJupTokenPrices = getJupTokenPrices;
|
30
30
|
exports.safeGetPrice = safeGetPrice;
|
31
31
|
const web3_js_1 = require("@solana/web3.js");
|
32
|
-
const
|
32
|
+
const SwbCommon = __importStar(require("@switchboard-xyz/common"));
|
33
|
+
const constants_1 = require("../constants");
|
33
34
|
const numberUtils_1 = require("./numberUtils");
|
34
|
-
const solautoConstants_1 = require("../constants/solautoConstants");
|
35
|
-
const switchboardConstants_1 = require("../constants/switchboardConstants");
|
36
35
|
const generalUtils_1 = require("./generalUtils");
|
37
|
-
const SwbCommon = __importStar(require("@switchboard-xyz/common"));
|
38
36
|
const jupiterUtils_1 = require("./jupiterUtils");
|
39
37
|
async function fetchTokenPrices(mints) {
|
40
38
|
const currentTime = (0, generalUtils_1.currentUnixSeconds)();
|
41
|
-
if (!mints.some((mint) => !(mint.toString() in
|
42
|
-
currentTime -
|
43
|
-
return mints.map((mint) =>
|
39
|
+
if (!mints.some((mint) => !(mint.toString() in constants_1.PRICES) ||
|
40
|
+
currentTime - constants_1.PRICES[mint.toString()].time > 3)) {
|
41
|
+
return mints.map((mint) => constants_1.PRICES[mint.toString()].price);
|
44
42
|
}
|
45
|
-
const pythMints = mints.filter((x) => x.toString() in
|
46
|
-
const switchboardMints = mints.filter((x) => x.toString() in Object.keys(
|
43
|
+
const pythMints = mints.filter((x) => x.toString() in constants_1.PYTH_PRICE_FEED_IDS);
|
44
|
+
const switchboardMints = mints.filter((x) => x.toString() in Object.keys(constants_1.SWITCHBOARD_PRICE_FEED_IDS));
|
47
45
|
const otherMints = mints.filter((x) => !pythMints.includes(x) && !switchboardMints.includes(x));
|
48
46
|
const [pythData, switchboardData, jupData] = await Promise.all([
|
49
47
|
(0, generalUtils_1.zip)(pythMints, await getPythPrices(pythMints)),
|
@@ -55,7 +53,7 @@ async function fetchTokenPrices(mints) {
|
|
55
53
|
return item ? item[1] : 0;
|
56
54
|
});
|
57
55
|
for (var i = 0; i < mints.length; i++) {
|
58
|
-
|
56
|
+
constants_1.PRICES[mints[i].toString()] = {
|
59
57
|
price: Number(prices[i]),
|
60
58
|
time: (0, generalUtils_1.currentUnixSeconds)(),
|
61
59
|
};
|
@@ -66,7 +64,7 @@ async function getPythPrices(mints) {
|
|
66
64
|
if (mints.length === 0) {
|
67
65
|
return [];
|
68
66
|
}
|
69
|
-
const priceFeedIds = mints.map((mint) =>
|
67
|
+
const priceFeedIds = mints.map((mint) => constants_1.PYTH_PRICE_FEED_IDS[mint.toString()]);
|
70
68
|
const getReq = async () => await fetch(`https://hermes.pyth.network/v2/updates/price/latest?${priceFeedIds.map((x) => `ids%5B%5D=${x}`).join("&")}`);
|
71
69
|
const prices = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
72
70
|
let resp = await getReq();
|
@@ -109,7 +107,7 @@ async function getSwitchboardPrices(mints) {
|
|
109
107
|
let prices = {};
|
110
108
|
try {
|
111
109
|
prices = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
112
|
-
const resp = await crossbar.simulateFeeds(mints.map((x) =>
|
110
|
+
const resp = await crossbar.simulateFeeds(mints.map((x) => constants_1.SWITCHBOARD_PRICE_FEED_IDS[x.toString()].feedHash));
|
113
111
|
const prices = resp.flatMap((x) => x.results[0]);
|
114
112
|
if (prices.filter((x) => !x || isNaN(Number(x)) || Number(x) <= 0)
|
115
113
|
.length > 0) {
|
@@ -117,7 +115,7 @@ async function getSwitchboardPrices(mints) {
|
|
117
115
|
}
|
118
116
|
const finalMap = {};
|
119
117
|
for (const item of resp) {
|
120
|
-
for (const [k, v] of Object.entries(
|
118
|
+
for (const [k, v] of Object.entries(constants_1.SWITCHBOARD_PRICE_FEED_IDS)) {
|
121
119
|
if (item.feedHash === v.feedHash) {
|
122
120
|
finalMap[k] = Number(item.results[0]);
|
123
121
|
}
|
@@ -146,8 +144,8 @@ async function getJupTokenPrices(mints) {
|
|
146
144
|
: 0);
|
147
145
|
}
|
148
146
|
function safeGetPrice(mint) {
|
149
|
-
if (mint && mint?.toString() in
|
150
|
-
return
|
147
|
+
if (mint && mint?.toString() in constants_1.PRICES) {
|
148
|
+
return constants_1.PRICES[mint.toString()].price;
|
151
149
|
}
|
152
150
|
return undefined;
|
153
151
|
}
|
@@ -1,9 +1,7 @@
|
|
1
|
-
import { AddressLookupTableInput, Signer, TransactionBuilder, Umi, WrappedInstruction } from "@metaplex-foundation/umi";
|
2
1
|
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
3
|
-
import {
|
4
|
-
|
5
|
-
export declare function
|
6
|
-
export declare function getSolanaRpcConnection(rpcUrl: string, programId?: PublicKey, wsEndpoint?: string): [Connection, Umi];
|
2
|
+
import { AddressLookupTableInput, Signer, TransactionBuilder, Umi, WrappedInstruction } from "@metaplex-foundation/umi";
|
3
|
+
import { PriorityFeeSetting, ProgramEnv, TransactionRunType } from "../types";
|
4
|
+
export declare function getSolanaRpcConnection(rpcUrl: string, programId?: PublicKey, lpEnv?: ProgramEnv): [Connection, Umi];
|
7
5
|
export declare function getWrappedInstruction(signer: Signer, ix: TransactionInstruction): WrappedInstruction;
|
8
6
|
export declare function setComputeUnitLimitUmiIx(signer: Signer, maxComputeUnits: number): WrappedInstruction;
|
9
7
|
export declare function setComputeUnitPriceUmiIx(signer: Signer, lamports: number): WrappedInstruction;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,GAAG,EACH,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,
|
1
|
+
{"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,UAAU,EACV,SAAS,EAKT,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EACL,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,GAAG,EACH,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAe9E,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,SAAS,EACrB,KAAK,CAAC,EAAE,UAAU,GACjB,CAAC,UAAU,EAAE,GAAG,CAAC,CAWnB;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,sBAAsB,GACzB,kBAAkB,CAMpB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,GACtB,kBAAkB,CAOpB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,kBAAkB,CAOpB;AAED,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,GACd,kBAAkB,CAUpB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,SAAS,EACtB,QAAQ,EAAE,MAAM,GACf,kBAAkB,CASpB;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,SAAS,EACvB,SAAS,EAAE,SAAS,GACnB,kBAAkB,CAKpB;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,GACb,kBAAkB,CAKpB;AAED,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,SAAS,EAAE,GACtB,OAAO,CAAC,MAAM,EAAE,CAAC,CAcnB;AAED,wBAAsB,sBAAsB,CAC1C,GAAG,EAAE,GAAG,EACR,oBAAoB,EAAE,MAAM,EAAE,GAC7B,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAmBpC;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,kBAAkB,EAC/B,gBAAgB,CAAC,EAAE,MAAM,EACzB,gBAAgB,CAAC,EAAE,MAAM,sBAa1B;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,kBAAkB,EAC/B,gBAAgB,CAAC,EAAE,MAAM,EACzB,gBAAgB,CAAC,EAAE,MAAM,sBA2D1B;AAuBD,wBAAsB,6BAA6B,CACjD,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,WAAW,GAAE,MAAW,GACvB,OAAO,CAAC,GAAG,CAAC,CAKd;AAED,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,kBAAkB,EACtB,eAAe,EAAE,kBAAkB,EACnC,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAwC7B;AA+CD,wBAAsB,8BAA8B,CAClD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,kBAAkB,EACtB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,eAAe,GAAE,kBAA2C,EAC5D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAuEjC"}
|
@@ -3,8 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.buildHeliusApiUrl = buildHeliusApiUrl;
|
7
|
-
exports.buildIronforgeApiUrl = buildIronforgeApiUrl;
|
8
6
|
exports.getSolanaRpcConnection = getSolanaRpcConnection;
|
9
7
|
exports.getWrappedInstruction = getWrappedInstruction;
|
10
8
|
exports.setComputeUnitLimitUmiIx = setComputeUnitLimitUmiIx;
|
@@ -21,31 +19,25 @@ exports.getQnComputeUnitPriceEstimate = getQnComputeUnitPriceEstimate;
|
|
21
19
|
exports.getComputeUnitPriceEstimate = getComputeUnitPriceEstimate;
|
22
20
|
exports.sendSingleOptimizedTransaction = sendSingleOptimizedTransaction;
|
23
21
|
const bs58_1 = __importDefault(require("bs58"));
|
22
|
+
const web3_js_1 = require("@solana/web3.js");
|
23
|
+
const spl_token_1 = require("@solana/spl-token");
|
24
24
|
const umi_1 = require("@metaplex-foundation/umi");
|
25
25
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
26
26
|
const umi_bundle_defaults_1 = require("@metaplex-foundation/umi-bundle-defaults");
|
27
|
-
const
|
28
|
-
const
|
27
|
+
const types_1 = require("../types");
|
28
|
+
const marginfi_sdk_1 = require("../marginfi-sdk");
|
29
29
|
const accountUtils_1 = require("./accountUtils");
|
30
30
|
const generalUtils_1 = require("./generalUtils");
|
31
|
-
const marginfi_sdk_1 = require("../marginfi-sdk");
|
32
|
-
const types_1 = require("../types");
|
33
|
-
const constants_1 = require("../constants");
|
34
31
|
const solautoUtils_1 = require("./solautoUtils");
|
35
|
-
|
36
|
-
|
37
|
-
}
|
38
|
-
function buildIronforgeApiUrl(ironforgeApiKey) {
|
39
|
-
return `https://rpc.ironforge.network/mainnet?apiKey=${ironforgeApiKey}`;
|
40
|
-
}
|
41
|
-
function getSolanaRpcConnection(rpcUrl, programId = constants_1.SOLAUTO_PROD_PROGRAM, wsEndpoint) {
|
32
|
+
const marginfiUtils_1 = require("./marginfiUtils");
|
33
|
+
function getSolanaRpcConnection(rpcUrl, programId, lpEnv) {
|
42
34
|
const connection = new web3_js_1.Connection(rpcUrl, {
|
43
35
|
commitment: "confirmed",
|
44
|
-
wsEndpoint: wsEndpoint,
|
45
36
|
});
|
46
37
|
const umi = (0, umi_bundle_defaults_1.createUmi)(connection).use({
|
47
38
|
install(umi) {
|
48
39
|
umi.programs.add((0, solautoUtils_1.createDynamicSolautoProgram)(programId), false);
|
40
|
+
umi.programs.add((0, marginfiUtils_1.createDynamicMarginfiProgram)(lpEnv), false);
|
49
41
|
},
|
50
42
|
});
|
51
43
|
return [connection, umi];
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { Program, Umi } from "@metaplex-foundation/umi";
|
3
|
-
import { AutomationSettings, DCASettings, DCASettingsInpArgs, LendingPlatform, PositionState, PositionType, SolautoRebalanceType, SolautoSettingsParameters, SolautoSettingsParametersInpArgs, TokenType } from "../generated";
|
4
|
-
import { SolautoPositionDetails } from "../types/solauto";
|
5
3
|
import { QuoteResponse } from "@jup-ag/api";
|
4
|
+
import { AutomationSettings, DCASettings, DCASettingsInpArgs, LendingPlatform, PositionState, PositionType, SolautoRebalanceType, SolautoSettingsParameters, SolautoSettingsParametersInpArgs, TokenType } from "../generated";
|
5
|
+
import { SolautoPositionDetails } from "../types";
|
6
6
|
import { SolautoClient, SolautoMarginfiClient, TxHandlerProps } from "../services";
|
7
|
-
export declare function createDynamicSolautoProgram(programId
|
7
|
+
export declare function createDynamicSolautoProgram(programId?: PublicKey): Program;
|
8
8
|
export declare function nextAutomationPeriodTimestamp(automation: AutomationSettings): number;
|
9
9
|
export declare function eligibleForNextAutomationPeriod(automation: AutomationSettings, currentUnixTime: number): boolean;
|
10
10
|
export declare function getUpdatedValueFromAutomation(currValue: number, targetValue: number, automation: AutomationSettings, currentUnixTimestamp: number): number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solautoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"solautoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solautoUtils.ts"],"names":[],"mappings":"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"}
|
@@ -16,19 +16,19 @@ exports.hasFirstRebalance = hasFirstRebalance;
|
|
16
16
|
exports.hasLastRebalance = hasLastRebalance;
|
17
17
|
const web3_js_1 = require("@solana/web3.js");
|
18
18
|
const umi_1 = require("@metaplex-foundation/umi");
|
19
|
-
const generated_1 = require("../generated");
|
20
|
-
const accountUtils_1 = require("./accountUtils");
|
21
19
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
20
|
+
const generated_1 = require("../generated");
|
22
21
|
const constants_1 = require("../constants");
|
23
|
-
const marginfiUtils_1 = require("./marginfiUtils");
|
24
|
-
const solautoPosition_1 = require("../solautoPosition");
|
25
22
|
const services_1 = require("../services");
|
23
|
+
const solautoPosition_1 = require("../solautoPosition");
|
24
|
+
const accountUtils_1 = require("./accountUtils");
|
26
25
|
const numberUtils_1 = require("./numberUtils");
|
27
26
|
const priceUtils_1 = require("./priceUtils");
|
27
|
+
const marginfiUtils_1 = require("./marginfiUtils");
|
28
28
|
function createDynamicSolautoProgram(programId) {
|
29
29
|
return {
|
30
30
|
name: "solauto",
|
31
|
-
publicKey: (0, umi_1.publicKey)(programId),
|
31
|
+
publicKey: (0, umi_1.publicKey)(programId ?? constants_1.SOLAUTO_PROD_PROGRAM),
|
32
32
|
getErrorFromCode(code, cause) {
|
33
33
|
return (0, generated_1.getSolautoErrorFromCode)(code, this, cause);
|
34
34
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stringUtils.d.ts","sourceRoot":"","sources":["../../src/utils/stringUtils.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"stringUtils.d.ts","sourceRoot":"","sources":["../../src/utils/stringUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAK5C,eAAO,MAAM,aAAa,qCAAsC,CAAC;AACjE,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAoB1D,wBAAgB,SAAS,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,SAAS,UAWrE;AAED,wBAAgB,mBAAmB,CACjC,UAAU,CAAC,EAAE,SAAS,EACtB,QAAQ,CAAC,EAAE,SAAS,UAcrB;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,SAAS,EACrB,QAAQ,EAAE,SAAS,GAClB,YAAY,CAWd"}
|
@@ -4,14 +4,14 @@ exports.StrategyTypes = void 0;
|
|
4
4
|
exports.ratioName = ratioName;
|
5
5
|
exports.solautoStrategyName = solautoStrategyName;
|
6
6
|
exports.strategyType = strategyType;
|
7
|
+
const web3_js_1 = require("@solana/web3.js");
|
7
8
|
const spl_token_1 = require("@solana/spl-token");
|
8
9
|
const constants_1 = require("../constants");
|
9
|
-
const web3_js_1 = require("@solana/web3.js");
|
10
10
|
const generalUtils_1 = require("./generalUtils");
|
11
11
|
exports.StrategyTypes = ["Long", "Short", "Ratio"];
|
12
12
|
const MAJORS_PRIO = {
|
13
|
-
[constants_1.WBTC
|
14
|
-
[constants_1.WETH
|
13
|
+
[constants_1.WBTC]: 0,
|
14
|
+
[constants_1.WETH]: 1,
|
15
15
|
[spl_token_1.NATIVE_MINT.toString()]: 2,
|
16
16
|
};
|
17
17
|
function adjustedTicker(mint) {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Connection, PublicKey } from "@solana/web3.js";
|
2
|
-
import { TransactionItemInputs } from "../types";
|
3
2
|
import { Signer } from "@metaplex-foundation/umi";
|
4
3
|
import * as OnDemand from "@switchboard-xyz/on-demand";
|
4
|
+
import { TransactionItemInputs } from "../types";
|
5
5
|
export declare function getPullFeed(conn: Connection, mint: PublicKey, wallet?: PublicKey): OnDemand.PullFeed;
|
6
6
|
export declare function buildSwbSubmitResponseTx(conn: Connection, signer: Signer, mint: PublicKey): Promise<TransactionItemInputs | undefined>;
|
7
7
|
export declare function getSwitchboardFeedData(conn: Connection, mints: PublicKey[]): Promise<{
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAsB,MAAM,0BAA0B,CAAC;AAGtE,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AAGvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAIjD,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,qBAuBnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsB5C;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,CAuB/D"}
|
@@ -29,13 +29,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.getPullFeed = getPullFeed;
|
30
30
|
exports.buildSwbSubmitResponseTx = buildSwbSubmitResponseTx;
|
31
31
|
exports.getSwitchboardFeedData = getSwitchboardFeedData;
|
32
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
33
|
-
const switchboard_json_1 = __importDefault(require("../idls/switchboard.json"));
|
34
32
|
const web3_js_1 = require("@solana/web3.js");
|
35
|
-
const switchboardConstants_1 = require("../constants/switchboardConstants");
|
36
33
|
const umi_1 = require("@metaplex-foundation/umi");
|
37
34
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
35
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
38
36
|
const OnDemand = __importStar(require("@switchboard-xyz/on-demand"));
|
37
|
+
const switchboard_json_1 = __importDefault(require("../idls/switchboard.json"));
|
38
|
+
const constants_1 = require("../constants");
|
39
39
|
const generalUtils_1 = require("./generalUtils");
|
40
40
|
const solanaUtils_1 = require("./solanaUtils");
|
41
41
|
function getPullFeed(conn, mint, wallet) {
|
@@ -47,7 +47,7 @@ function getPullFeed(conn, mint, wallet) {
|
|
47
47
|
const provider = new anchor_1.AnchorProvider(conn, dummyWallet, anchor_1.AnchorProvider.defaultOptions());
|
48
48
|
const program = new anchor_1.Program(switchboard_json_1.default, provider);
|
49
49
|
const { PullFeed } = OnDemand;
|
50
|
-
return new PullFeed(program, new web3_js_1.PublicKey(
|
50
|
+
return new PullFeed(program, new web3_js_1.PublicKey(constants_1.SWITCHBOARD_PRICE_FEED_IDS[mint.toString()].feedId));
|
51
51
|
}
|
52
52
|
async function buildSwbSubmitResponseTx(conn, signer, mint) {
|
53
53
|
const feed = getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
|
@@ -5,18 +5,24 @@ import {
|
|
5
5
|
transactionBuilder,
|
6
6
|
} from "@metaplex-foundation/umi";
|
7
7
|
import {
|
8
|
-
buildHeliusApiUrl,
|
9
8
|
getSolanaRpcConnection,
|
10
9
|
sendSingleOptimizedTransaction,
|
11
|
-
|
12
|
-
|
13
|
-
import {
|
14
|
-
|
10
|
+
getAllMarginfiAccountsByAuthority,
|
11
|
+
} from "../src/utils";
|
12
|
+
import {
|
13
|
+
marginfiAccountInitialize,
|
14
|
+
safeFetchAllMarginfiAccount,
|
15
|
+
} from "../src/marginfi-sdk";
|
16
|
+
import {
|
17
|
+
LOCAL_IRONFORGE_API_URL,
|
18
|
+
MARGINFI_ACCOUNTS,
|
19
|
+
SOLAUTO_MANAGER,
|
20
|
+
} from "../src/constants";
|
15
21
|
import { updateSolautoLut } from "./updateSolautoLUT";
|
16
|
-
import {
|
22
|
+
import { getSecretKey } from "./shared";
|
17
23
|
|
18
24
|
async function createIntermediarySolautoManagerAccounts() {
|
19
|
-
let [connection, umi] = getSolanaRpcConnection(
|
25
|
+
let [connection, umi] = getSolanaRpcConnection(LOCAL_IRONFORGE_API_URL);
|
20
26
|
|
21
27
|
const secretKey = getSecretKey("solauto-manager");
|
22
28
|
const signerKeypair = umi.eddsa.createKeypairFromSecretKey(secretKey);
|
@@ -24,13 +30,24 @@ async function createIntermediarySolautoManagerAccounts() {
|
|
24
30
|
|
25
31
|
umi = umi.use(signerIdentity(signer));
|
26
32
|
|
27
|
-
const accounts = await getAllMarginfiAccountsByAuthority(
|
28
|
-
|
29
|
-
|
33
|
+
const accounts = await getAllMarginfiAccountsByAuthority(
|
34
|
+
umi,
|
35
|
+
SOLAUTO_MANAGER,
|
36
|
+
undefined,
|
37
|
+
false
|
38
|
+
);
|
39
|
+
const data = await safeFetchAllMarginfiAccount(
|
40
|
+
umi,
|
41
|
+
accounts.map((x) => publicKey(x.marginfiAccount))
|
42
|
+
);
|
43
|
+
const existingMarginfiGroups = data.map((x) => x.group.toString());
|
30
44
|
|
31
45
|
for (const group of Object.keys(MARGINFI_ACCOUNTS)) {
|
32
46
|
if (existingMarginfiGroups.includes(group.toString())) {
|
33
|
-
console.log(
|
47
|
+
console.log(
|
48
|
+
"Already have Solauto Manager Marginfi Account for group:",
|
49
|
+
group
|
50
|
+
);
|
34
51
|
continue;
|
35
52
|
}
|
36
53
|
|
@@ -45,7 +62,7 @@ async function createIntermediarySolautoManagerAccounts() {
|
|
45
62
|
authority: signer,
|
46
63
|
feePayer: signer,
|
47
64
|
});
|
48
|
-
|
65
|
+
|
49
66
|
await sendSingleOptimizedTransaction(
|
50
67
|
umi,
|
51
68
|
connection,
|
@@ -1,7 +1,16 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import { ALL_SUPPORTED_TOKENS, SOLAUTO_FEES_WALLET } from "../src/constants";
|
3
2
|
import {
|
4
|
-
|
3
|
+
createSignerFromKeypair,
|
4
|
+
publicKey,
|
5
|
+
signerIdentity,
|
6
|
+
transactionBuilder,
|
7
|
+
} from "@metaplex-foundation/umi";
|
8
|
+
import {
|
9
|
+
ALL_SUPPORTED_TOKENS,
|
10
|
+
LOCAL_IRONFORGE_API_URL,
|
11
|
+
SOLAUTO_FEES_WALLET,
|
12
|
+
} from "../src/constants";
|
13
|
+
import {
|
5
14
|
createAssociatedTokenAccountUmiIx,
|
6
15
|
getSolanaRpcConnection,
|
7
16
|
getTokenAccount,
|
@@ -9,17 +18,9 @@ import {
|
|
9
18
|
zip,
|
10
19
|
} from "../src/utils";
|
11
20
|
import { getSecretKey } from "./shared";
|
12
|
-
import {
|
13
|
-
createSignerFromKeypair,
|
14
|
-
publicKey,
|
15
|
-
signerIdentity,
|
16
|
-
transactionBuilder,
|
17
|
-
} from "@metaplex-foundation/umi";
|
18
21
|
|
19
22
|
async function createTokenAccounts(wallet: PublicKey) {
|
20
|
-
let [connection, umi] = getSolanaRpcConnection(
|
21
|
-
buildHeliusApiUrl(process.env.HELIUS_API_KEY!)
|
22
|
-
);
|
23
|
+
let [connection, umi] = getSolanaRpcConnection(LOCAL_IRONFORGE_API_URL);
|
23
24
|
|
24
25
|
const secretKey = getSecretKey();
|
25
26
|
const signerKeypair = umi.eddsa.createKeypairFromSecretKey(secretKey);
|
package/local/logPositions.ts
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
2
|
+
import path from "path";
|
3
|
+
import { config } from "dotenv";
|
1
4
|
import {
|
2
|
-
buildIronforgeApiUrl,
|
3
5
|
fetchTokenPrices,
|
4
6
|
getPositionExBulk,
|
5
7
|
getSolanaRpcConnection,
|
6
8
|
getSolautoManagedPositions,
|
9
|
+
LOCAL_IRONFORGE_API_URL,
|
7
10
|
safeGetPrice,
|
8
11
|
SOLAUTO_PROD_PROGRAM,
|
9
12
|
} from "../src";
|
10
|
-
import { PublicKey } from "@solana/web3.js";
|
11
|
-
import path from "path";
|
12
|
-
import { config } from "dotenv";
|
13
13
|
|
14
14
|
config({ path: path.join(__dirname, ".env") });
|
15
15
|
|
@@ -78,7 +78,7 @@ export function formatNumber(
|
|
78
78
|
|
79
79
|
async function main(filterWhitelist: boolean) {
|
80
80
|
const [_, umi] = getSolanaRpcConnection(
|
81
|
-
|
81
|
+
LOCAL_IRONFORGE_API_URL,
|
82
82
|
SOLAUTO_PROD_PROGRAM
|
83
83
|
);
|
84
84
|
|
package/local/shared.ts
CHANGED
@@ -9,10 +9,10 @@ import {
|
|
9
9
|
PublicKey,
|
10
10
|
} from "@solana/web3.js";
|
11
11
|
import {
|
12
|
-
buildHeliusApiUrl,
|
13
12
|
getSolanaRpcConnection,
|
14
|
-
|
15
|
-
|
13
|
+
getBatches,
|
14
|
+
buildIronforgeApiUrl,
|
15
|
+
} from "../src";
|
16
16
|
|
17
17
|
function loadSecretKey(keypairPath: string) {
|
18
18
|
const secretKey = JSON.parse(fs.readFileSync(keypairPath, "utf8"));
|
@@ -27,7 +27,7 @@ export function getSecretKey(keypairFilename: string = "id"): Uint8Array {
|
|
27
27
|
|
28
28
|
const keypair = Keypair.fromSecretKey(getSecretKey("solauto-fees"));
|
29
29
|
const [connection, _] = getSolanaRpcConnection(
|
30
|
-
|
30
|
+
buildIronforgeApiUrl(process.env.IRONFORGE_API_KEY ?? "")
|
31
31
|
);
|
32
32
|
|
33
33
|
export async function createAndSendV0Tx(
|
@@ -89,14 +89,21 @@ async function addAddressesIfNeeded(
|
|
89
89
|
}
|
90
90
|
}
|
91
91
|
|
92
|
+
const CACHE: { [key: string]: string[] } = {};
|
93
|
+
|
92
94
|
export async function updateLookupTable(
|
93
95
|
accounts: string[],
|
94
96
|
lookupTableAddress?: PublicKey
|
95
97
|
) {
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
98
|
+
if (lookupTableAddress && !(lookupTableAddress.toString() in CACHE)) {
|
99
|
+
const lookupTable =
|
100
|
+
await connection.getAddressLookupTable(lookupTableAddress);
|
101
|
+
CACHE[lookupTableAddress.toString()] = (
|
102
|
+
lookupTable?.value?.state?.addresses ?? []
|
103
|
+
).map((x) => x.toString());
|
104
|
+
}
|
105
|
+
|
106
|
+
if (!lookupTableAddress) {
|
100
107
|
const [createLutIx, addr] = AddressLookupTableProgram.createLookupTable({
|
101
108
|
authority: keypair.publicKey,
|
102
109
|
payer: keypair.publicKey,
|
@@ -107,8 +114,7 @@ export async function updateLookupTable(
|
|
107
114
|
await createAndSendV0Tx([createLutIx], keypair);
|
108
115
|
}
|
109
116
|
|
110
|
-
const existingAccounts =
|
111
|
-
lookupTable?.value?.state.addresses.map((x) => x.toString()) ?? [];
|
117
|
+
const existingAccounts = CACHE[lookupTableAddress.toString()];
|
112
118
|
console.log("Existing accounts: ", existingAccounts.length);
|
113
119
|
|
114
120
|
await addAddressesIfNeeded(lookupTableAddress!, existingAccounts, accounts);
|
package/local/txSandbox.ts
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
import { Keypair, PublicKey } from "@solana/web3.js";
|
2
|
+
import { createSignerFromKeypair } from "@metaplex-foundation/umi";
|
3
|
+
import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
|
2
4
|
import {
|
3
|
-
buildIronforgeApiUrl,
|
4
5
|
consoleLog,
|
5
6
|
getClient,
|
6
7
|
getSolanaRpcConnection,
|
7
8
|
LendingPlatform,
|
9
|
+
LOCAL_IRONFORGE_API_URL,
|
8
10
|
PriorityFeeSetting,
|
9
11
|
RebalanceTxBuilder,
|
10
12
|
SOLAUTO_PROD_PROGRAM,
|
@@ -13,15 +15,13 @@ import {
|
|
13
15
|
TransactionsManager,
|
14
16
|
} from "../src";
|
15
17
|
import { getSecretKey } from "./shared";
|
16
|
-
import { createSignerFromKeypair } from "@metaplex-foundation/umi";
|
17
|
-
import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
|
18
18
|
|
19
19
|
const payForTransaction = false;
|
20
20
|
const testProgram = true;
|
21
21
|
|
22
22
|
export async function main() {
|
23
23
|
const [, umi] = getSolanaRpcConnection(
|
24
|
-
|
24
|
+
LOCAL_IRONFORGE_API_URL,
|
25
25
|
testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM
|
26
26
|
);
|
27
27
|
|
@@ -33,7 +33,7 @@ export async function main() {
|
|
33
33
|
const client = getClient(LendingPlatform.Marginfi, {
|
34
34
|
signer,
|
35
35
|
showLogs: true,
|
36
|
-
rpcUrl:
|
36
|
+
rpcUrl: LOCAL_IRONFORGE_API_URL,
|
37
37
|
programId: testProgram ? SOLAUTO_TEST_PROGRAM : SOLAUTO_PROD_PROGRAM,
|
38
38
|
});
|
39
39
|
|
@@ -1,20 +1,4 @@
|
|
1
1
|
import { Keypair, PublicKey } from "@solana/web3.js";
|
2
|
-
import { MARGINFI_ACCOUNTS_LOOKUP_TABLE } from "../src/constants/marginfiAccounts";
|
3
|
-
import {
|
4
|
-
MARGINFI_ACCOUNTS,
|
5
|
-
DEFAULT_MARGINFI_GROUP,
|
6
|
-
} from "../src/constants/marginfiAccounts";
|
7
|
-
import {
|
8
|
-
MARGINFI_PROGRAM_ID,
|
9
|
-
marginfiAccountInitialize,
|
10
|
-
} from "../src/marginfi-sdk";
|
11
|
-
import { createAndSendV0Tx, getSecretKey, updateLookupTable } from "./shared";
|
12
|
-
import {
|
13
|
-
buildIronforgeApiUrl,
|
14
|
-
getEmptyMarginfiAccountsByAuthority,
|
15
|
-
getSolanaRpcConnection,
|
16
|
-
SOLAUTO_MANAGER,
|
17
|
-
} from "../src";
|
18
2
|
import {
|
19
3
|
createSignerFromKeypair,
|
20
4
|
publicKey,
|
@@ -25,10 +9,22 @@ import {
|
|
25
9
|
toWeb3JsInstruction,
|
26
10
|
toWeb3JsKeypair,
|
27
11
|
} from "@metaplex-foundation/umi-web3js-adapters";
|
12
|
+
import {
|
13
|
+
MARGINFI_ACCOUNTS_LOOKUP_TABLE,
|
14
|
+
MARGINFI_ACCOUNTS,
|
15
|
+
DEFAULT_MARGINFI_GROUP,
|
16
|
+
getEmptyMarginfiAccountsByAuthority,
|
17
|
+
getSolanaRpcConnection,
|
18
|
+
SOLAUTO_MANAGER,
|
19
|
+
marginfiAccountInitialize,
|
20
|
+
LOCAL_IRONFORGE_API_URL,
|
21
|
+
MARGINFI_PROD_PROGRAM,
|
22
|
+
} from "../src";
|
23
|
+
import { createAndSendV0Tx, getSecretKey, updateLookupTable } from "./shared";
|
28
24
|
|
29
25
|
const LOOKUP_TABLE_ADDRESS = new PublicKey(MARGINFI_ACCOUNTS_LOOKUP_TABLE);
|
30
26
|
let [, umi] = getSolanaRpcConnection(
|
31
|
-
|
27
|
+
LOCAL_IRONFORGE_API_URL
|
32
28
|
);
|
33
29
|
umi = umi.use(
|
34
30
|
signerIdentity(
|
@@ -68,45 +64,43 @@ async function addImfiAccounts() {
|
|
68
64
|
SOLAUTO_MANAGER
|
69
65
|
);
|
70
66
|
|
67
|
+
const iMfiAccountsPerGrp = 2;
|
71
68
|
for (const group in MARGINFI_ACCOUNTS) {
|
72
69
|
const emptyAccs = imfiAccounts.filter((x) => x.group.toString() === group);
|
73
|
-
if (emptyAccs.length
|
70
|
+
if (emptyAccs.length >= iMfiAccountsPerGrp) {
|
74
71
|
await updateLookupTable(
|
75
72
|
emptyAccs.map((x) => x.publicKey.toString()),
|
76
73
|
LOOKUP_TABLE_ADDRESS
|
77
74
|
);
|
78
75
|
} else {
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
76
|
+
for (let i = 0; i < iMfiAccountsPerGrp - emptyAccs.length; i++) {
|
77
|
+
console.log("Creating Imfi account for group:", group);
|
78
|
+
const iMfiAccountKeypair = umi.eddsa.generateKeypair();
|
79
|
+
const iMfiAccount = createSignerFromKeypair(umi, iMfiAccountKeypair);
|
80
|
+
const umiIx = marginfiAccountInitialize(umi, {
|
81
|
+
marginfiAccount: iMfiAccount,
|
82
|
+
marginfiGroup: publicKey(group),
|
83
|
+
authority: solautoManager,
|
84
|
+
feePayer: solautoManager,
|
85
|
+
});
|
86
|
+
const ix = toWeb3JsInstruction(umiIx.getInstructions()[0]);
|
87
|
+
await createAndSendV0Tx([ix], solautoManagerKeypair, [
|
88
|
+
toWeb3JsKeypair(iMfiAccountKeypair),
|
89
|
+
]);
|
90
|
+
await updateLookupTable(
|
91
|
+
[iMfiAccount.publicKey.toString()],
|
92
|
+
LOOKUP_TABLE_ADDRESS
|
93
|
+
);
|
94
|
+
}
|
96
95
|
}
|
97
96
|
}
|
98
97
|
}
|
99
98
|
|
100
99
|
updateLookupTable(
|
101
|
-
[DEFAULT_MARGINFI_GROUP,
|
100
|
+
[DEFAULT_MARGINFI_GROUP, MARGINFI_PROD_PROGRAM.toString()], // TODO
|
102
101
|
LOOKUP_TABLE_ADDRESS
|
103
102
|
);
|
104
103
|
|
105
104
|
addBanks().then((x) => x);
|
106
105
|
|
107
106
|
addImfiAccounts().then((x) => x);
|
108
|
-
|
109
|
-
// TODO: get rid of these lookup tables
|
110
|
-
// EoEVYjz3MnsX6fKyxrwJkRhzMCHKjj6dvnjTCHoZLMc7
|
111
|
-
// AuoepJfrCrkQF2PeUAgpnnJybRoiff82cNdwXTqyjjvm
|
112
|
-
// Bno3JybASPc1jNBZ9rnrdKVvbhk6UNMvSsYvgtitq3zb
|