@haven-fi/solauto-sdk 1.0.625 → 1.0.627
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/README.md +115 -0
- package/dist/constants/marginfiAccounts.d.ts +10 -6
- package/dist/constants/marginfiAccounts.d.ts.map +1 -1
- package/dist/constants/marginfiAccounts.js +61 -37
- package/dist/constants/pythConstants.d.ts +4 -0
- package/dist/constants/pythConstants.d.ts.map +1 -1
- package/dist/constants/pythConstants.js +5 -1
- package/dist/services/flashLoans/marginfiFlProvider.d.ts.map +1 -1
- package/dist/services/flashLoans/marginfiFlProvider.js +9 -9
- package/dist/services/solauto/solautoClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoClient.js +6 -6
- package/dist/services/solauto/solautoMarginfiClient.d.ts +2 -1
- package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoMarginfiClient.js +15 -17
- package/dist/services/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/services/transactions/transactionUtils.js +3 -2
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts +5 -0
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/marginfiSolautoPositionEx.js +20 -6
- package/dist/solautoPosition/solautoPositionEx.d.ts +5 -1
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/solautoPositionEx.js +11 -4
- package/dist/solautoPosition/utils.js +1 -1
- package/dist/types/accounts.d.ts +0 -1
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/utils/generalUtils.d.ts +1 -0
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +10 -0
- 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/marginfiUtils.d.ts +13 -3
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +78 -20
- package/dist/utils/pythUtils.d.ts +21 -0
- package/dist/utils/pythUtils.d.ts.map +1 -0
- package/dist/utils/pythUtils.js +67 -0
- package/dist/utils/solautoUtils.js +1 -1
- package/local/txSandbox.ts +3 -3
- package/local/updateMarginfiLUT.ts +17 -26
- package/package.json +1 -1
- package/src/constants/marginfiAccounts.ts +80 -37
- package/src/constants/pythConstants.ts +8 -0
- package/src/services/flashLoans/marginfiFlProvider.ts +13 -11
- package/src/services/solauto/solautoClient.ts +7 -6
- package/src/services/solauto/solautoMarginfiClient.ts +18 -26
- package/src/services/transactions/transactionUtils.ts +1 -1
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +28 -9
- package/src/solautoPosition/solautoPositionEx.ts +18 -5
- package/src/solautoPosition/utils.ts +1 -1
- package/src/types/accounts.ts +0 -1
- package/src/utils/generalUtils.ts +12 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/marginfiUtils.ts +123 -30
- package/src/utils/pythUtils.ts +84 -0
- package/src/utils/solautoUtils.ts +1 -1
- package/tests/unit/accounts.ts +7 -13
- package/tests/unit/lookupTables.ts +27 -48
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Keypair
|
1
|
+
import { Keypair } from "@solana/web3.js";
|
2
2
|
import {
|
3
3
|
createSignerFromKeypair,
|
4
4
|
publicKey,
|
@@ -10,22 +10,20 @@ import {
|
|
10
10
|
toWeb3JsKeypair,
|
11
11
|
} from "@metaplex-foundation/umi-web3js-adapters";
|
12
12
|
import {
|
13
|
-
MARGINFI_ACCOUNTS_LOOKUP_TABLE,
|
14
|
-
MARGINFI_ACCOUNTS,
|
15
|
-
DEFAULT_MARGINFI_GROUP,
|
16
13
|
getEmptyMarginfiAccountsByAuthority,
|
17
14
|
getSolanaRpcConnection,
|
18
15
|
SOLAUTO_MANAGER,
|
19
16
|
marginfiAccountInitialize,
|
20
17
|
LOCAL_IRONFORGE_API_URL,
|
21
|
-
|
18
|
+
getMarginfiAccounts,
|
19
|
+
getAllBankRelatedAccounts,
|
22
20
|
} from "../src";
|
23
21
|
import { createAndSendV0Tx, getSecretKey, updateLookupTable } from "./shared";
|
24
22
|
|
25
|
-
const
|
26
|
-
|
27
|
-
|
28
|
-
);
|
23
|
+
const mfiAccounts = getMarginfiAccounts("Prod");
|
24
|
+
|
25
|
+
const LOOKUP_TABLE_ADDRESS = mfiAccounts.lookupTable;
|
26
|
+
let [, umi] = getSolanaRpcConnection(LOCAL_IRONFORGE_API_URL);
|
29
27
|
umi = umi.use(
|
30
28
|
signerIdentity(
|
31
29
|
createSignerFromKeypair(umi, umi.eddsa.generateKeypair()),
|
@@ -41,21 +39,14 @@ const solautoManager = createSignerFromKeypair(
|
|
41
39
|
);
|
42
40
|
|
43
41
|
async function addBanks() {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
accounts.vaultAuthority,
|
53
|
-
accounts.priceOracle,
|
54
|
-
],
|
55
|
-
LOOKUP_TABLE_ADDRESS
|
56
|
-
);
|
57
|
-
}
|
58
|
-
}
|
42
|
+
const accounts = await getAllBankRelatedAccounts(
|
43
|
+
umi,
|
44
|
+
mfiAccounts.bankAccounts
|
45
|
+
);
|
46
|
+
await updateLookupTable(
|
47
|
+
accounts.map((x) => x.toString()),
|
48
|
+
LOOKUP_TABLE_ADDRESS
|
49
|
+
);
|
59
50
|
}
|
60
51
|
|
61
52
|
async function addImfiAccounts() {
|
@@ -65,7 +56,7 @@ async function addImfiAccounts() {
|
|
65
56
|
);
|
66
57
|
|
67
58
|
const iMfiAccountsPerGrp = 2;
|
68
|
-
for (const group in
|
59
|
+
for (const group in mfiAccounts.bankAccounts) {
|
69
60
|
const emptyAccs = imfiAccounts.filter((x) => x.group.toString() === group);
|
70
61
|
if (emptyAccs.length >= iMfiAccountsPerGrp) {
|
71
62
|
await updateLookupTable(
|
@@ -97,7 +88,7 @@ async function addImfiAccounts() {
|
|
97
88
|
}
|
98
89
|
|
99
90
|
updateLookupTable(
|
100
|
-
[
|
91
|
+
[mfiAccounts.defaultGroup.toString(), mfiAccounts.program.toString()],
|
101
92
|
LOOKUP_TABLE_ADDRESS
|
102
93
|
);
|
103
94
|
|
package/package.json
CHANGED
@@ -3,136 +3,141 @@ import { NATIVE_MINT } from "@solana/spl-token";
|
|
3
3
|
import * as tokens from "./tokenConstants";
|
4
4
|
import { MarginfiAssetAccounts } from "../types/accounts";
|
5
5
|
import { SWITCHBOARD_PRICE_FEED_IDS } from "./switchboardConstants";
|
6
|
+
import { ProgramEnv } from "../types";
|
6
7
|
|
7
|
-
|
8
|
+
const MARGINFI_PROD_PROGRAM = new PublicKey(
|
8
9
|
"MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA"
|
9
10
|
);
|
10
|
-
|
11
|
+
const MARGINFI_STAGING_PROGRAM = new PublicKey(
|
11
12
|
"stag8sTKds2h4KzjUw3zKTsxbqvT4XKHdaR9X9E6Rct"
|
12
13
|
);
|
13
14
|
|
14
|
-
|
15
|
+
const PROD_DEFAULT_MARGINFI_GROUP =
|
15
16
|
"4qp6Fx6tnZkY5Wropq9wUYgtFxXKwE6viZxFHg3rdAG8";
|
16
17
|
|
17
|
-
const
|
18
|
+
const STAGING_DEFAULT_MARGINFI_GROUP =
|
19
|
+
"FCPfpHA69EbS8f9KKSreTRkXbzFpunsKuYf5qNmnJjpo";
|
18
20
|
|
19
|
-
export
|
21
|
+
export type MarginfiBankAccountsMap = {
|
20
22
|
[group: string]: { [token: string]: MarginfiAssetAccounts };
|
21
|
-
}
|
22
|
-
|
23
|
+
};
|
24
|
+
|
25
|
+
const MARGINFI_STAGING_ACCOUNTS: MarginfiBankAccountsMap = {
|
26
|
+
[STAGING_DEFAULT_MARGINFI_GROUP]: {
|
27
|
+
[NATIVE_MINT.toString()]: {
|
28
|
+
bank: "3evdJSa25nsUiZzEUzd92UNa13TPRJrje1dRyiQP5Lhp",
|
29
|
+
liquidityVault: "FVXESa7wCd1tf3o9LGroBc3Ym8Gpcq1HdsLek6oo7Ykv",
|
30
|
+
vaultAuthority: "DuYk1WGq8UsjW5ThLtaehFLrnJeupTjtF7TaPzja9LBQ",
|
31
|
+
},
|
32
|
+
[tokens.USDC]: {
|
33
|
+
bank: "Ek5JSFJFD8QgXM6rPDCzf31XhDp1q3xezaWYSkJWqbqc",
|
34
|
+
liquidityVault: "6n7xXMni5WJKUMb4Vm5Zis6UaUtGF5xEGmagZNVWWoKB",
|
35
|
+
vaultAuthority: "9mXNyA5yS4WSTpYUa5gi3yBrSJWWM7XNPNDWRzWGjdVe",
|
36
|
+
},
|
37
|
+
[tokens.USDT]: {
|
38
|
+
bank: "4WFCsVXwfnQvZG52VvPwae7CtL13PUFVWdjkw5YCRBo6",
|
39
|
+
liquidityVault: "BFSyniKfXU9rHqUvHLKeZMivQsAKWTE7HZ1fW6vZcvJp",
|
40
|
+
vaultAuthority: "Fgxe3SUMzcNuLtT9Xkv8QhhWXCmu4VxynzUMwCF4HvJd",
|
41
|
+
},
|
42
|
+
},
|
43
|
+
};
|
44
|
+
|
45
|
+
const MARGINFI_PROD_ACCOUNTS: MarginfiBankAccountsMap = {
|
46
|
+
[PROD_DEFAULT_MARGINFI_GROUP.toString()]: {
|
23
47
|
[NATIVE_MINT.toString()]: {
|
24
48
|
bank: "CCKtUs6Cgwo4aaQUmBPmyoApH2gUDErxNZCAntD6LYGh",
|
25
49
|
liquidityVault: "2eicbpitfJXDwqCuFAmPgDP7t2oUotnAzbGzRKLMgSLe",
|
26
50
|
vaultAuthority: "DD3AeAssFvjqTvRTrRAtpfjkBF8FpVKnFuwnMLN9haXD",
|
27
|
-
priceOracle: "7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE",
|
28
51
|
},
|
29
52
|
[tokens.B_SOL]: {
|
30
53
|
bank: "6hS9i46WyTq1KXcoa2Chas2Txh9TJAVr6n1t3tnrE23K",
|
31
54
|
liquidityVault: "2WMipeKDB2CENxbzdmnVrRbsxCA2LY6kCtBe6AAqDP9p",
|
32
55
|
vaultAuthority: "8RcZHucpVHkHWRRdMhJZsxBK9mqKSYnMKGqtF84U8YEo",
|
33
|
-
priceOracle: "5cN76Xm2Dtx9MnrQqBDeZZRsWruTTcw37UruznAdSvvE",
|
34
56
|
},
|
35
57
|
[tokens.M_SOL]: {
|
36
58
|
bank: "22DcjMZrMwC5Bpa5AGBsmjc5V9VuQrXG6N9ZtdUNyYGE",
|
37
59
|
liquidityVault: "B6HqNn83a2bLqo4i5ygjLHJgD11ePtQksUyx4MjD55DV",
|
38
60
|
vaultAuthority: "6YxGd65JbXzgFGWjE44jsyVeCnZp7Bb1wfL9jDia1n8w",
|
39
|
-
priceOracle: "5CKzb9j4ChgLUt8Gfm5CNGLN6khXKiqMbnGAW4cgXgxK",
|
40
61
|
},
|
41
62
|
[tokens.JITO_SOL]: {
|
42
63
|
bank: "Bohoc1ikHLD7xKJuzTyiTyCwzaL5N7ggJQu75A8mKYM8",
|
43
64
|
liquidityVault: "38VGtXd2pDPq9FMh1z6AVjcHCoHgvWyMhdNyamDTeeks",
|
44
65
|
vaultAuthority: "7Ng54qf7BrCcZLqXmKA9WSR7SVRn4q6RX1YpLksBQ21A",
|
45
|
-
priceOracle: "AxaxyeDT8JnWERSaTKvFXvPKkEdxnamKSqpWbsSjYg1g",
|
46
66
|
},
|
47
67
|
[tokens.LST]: {
|
48
68
|
bank: "DMoqjmsuoru986HgfjqrKEvPv8YBufvBGADHUonkadC5",
|
49
69
|
liquidityVault: "DMQUXpb6K5L8osgV4x3NeEPUoJCf2VBgnA8FQusDjSou",
|
50
70
|
vaultAuthority: "6PWVauGLhBFHUJspsnBVZHr56ZnbvmhSD2gS7czBHGpE",
|
51
|
-
priceOracle: "7aT9A5knp62jVvnEW33xaWopaPHa3Y7ggULyYiUsDhu8",
|
52
71
|
},
|
53
72
|
[tokens.INF]: {
|
54
73
|
bank: "AwLRW3aPMMftXEjgWhTkYwM9CGBHdtKecvahCJZBwAqY",
|
55
74
|
liquidityVault: "HQ1CGcqRshMhuonTGTnnmgw9ffcXxizGdZ6F6PKffWWi",
|
56
75
|
vaultAuthority: "AEZb1XH5bfLwqk3hBKDuLfWyJKdLTgDPCkgn64BJKcvV",
|
57
|
-
priceOracle: "Ceg5oePJv1a6RR541qKeQaTepvERA3i8SvyueX9tT8Sq",
|
58
76
|
},
|
59
77
|
[tokens.H_SOL]: {
|
60
78
|
bank: "GJCi1uj3kYPZ64puA5sLUiCQfFapxT2xnREzrbDzFkYY",
|
61
79
|
liquidityVault: "8M97jkdr4rJtPnQ4yQ9stD6qVwaUvjrBdDPDbHJnPJLf",
|
62
80
|
vaultAuthority: "8x7mgTn5RvHR8Tn3CJqexSuQwrs6MLEy8csuXCDVvvpt",
|
63
|
-
priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.H_SOL.toString()].feedId,
|
64
81
|
},
|
65
82
|
[tokens.JUP_SOL]: {
|
66
83
|
bank: "8LaUZadNqtzuCG7iCvZd7d5cbquuYfv19KjAg6GPuuCb",
|
67
84
|
liquidityVault: "B1zjqKPoYp9bTMhzFADaAvjyGb49FMitLpi6P3Pa3YR6",
|
68
85
|
vaultAuthority: "93Qqsge2jHVsWLd8vas4cWghrsZJooMUr5JKN5DtcfMX",
|
69
|
-
priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.JUP_SOL.toString()].feedId,
|
70
86
|
},
|
71
87
|
[tokens.JUP]: {
|
72
88
|
bank: "Guu5uBc8k1WK1U2ihGosNaCy57LSgCkpWAabtzQqrQf8",
|
73
89
|
liquidityVault: "4w49W4fNDn778wsBa6TNq9hvebZKU17ymsptrEZ8zrsm",
|
74
90
|
vaultAuthority: "2MBwwAhL3c73Jy7HkWd9ofzh1bU39JBabrZCFQR2tUof",
|
75
|
-
priceOracle: "7dbob1psH1iZBS7qPsm3Kwbf5DzSXK8Jyg31CTgTnxH5",
|
76
91
|
},
|
77
92
|
[tokens.JTO]: {
|
78
93
|
bank: "EdB7YADw4XUt6wErT8kHGCUok4mnTpWGzPUU9rWDebzb",
|
79
94
|
liquidityVault: "3bY1DEkXodGmPMG5f7ABA12228MBG5JdAAKf5cgkB6G1",
|
80
95
|
vaultAuthority: "H2b4f2fGSKFortxwzrMZBnYVfr2yrKVUakg4Md9be3Wv",
|
81
|
-
priceOracle: "7ajR2zA4MGMMTqRAVjghTKqPPn4kbrj3pYkAVRVwTGzP",
|
82
96
|
},
|
83
97
|
[tokens.JLP]: {
|
84
98
|
bank: "Amtw3n7GZe5SWmyhMhaFhDTi39zbTkLeWErBsmZXwpDa",
|
85
99
|
liquidityVault: "9xfyL8gxbV77VvhdgFmacHyLEG4h7d2eDWkSMfhXUPQ",
|
86
100
|
vaultAuthority: "F4RSGd4BRXscCqAVG3rFLiPVpo7v6j1drVqnvSM3rBKH",
|
87
|
-
priceOracle: "2TTGSRSezqFzeLUH8JwRUbtN66XLLaymfYsWRTMjfiMw",
|
88
101
|
},
|
89
102
|
[tokens.WBTC]: {
|
90
103
|
bank: "BKsfDJCMbYep6gr9pq8PsmJbb5XGLHbAJzUV8vmorz7a",
|
91
104
|
liquidityVault: "CMNdnjfaDQZo3VMoX31wZQBnSGu5FMmb1CnBaU4tApZk",
|
92
105
|
vaultAuthority: "7P2TQHYgVJkXv1VPaREsL5Pi1gnNjVif5aF3pJewZ9kj",
|
93
|
-
priceOracle: "4cSM2e6rvbGQUFiJbqytoVMi5GgghSMr8LwVrT9VPSPo",
|
94
106
|
},
|
95
107
|
[tokens.WETH]: {
|
96
108
|
bank: "BkUyfXjbBBALcfZvw76WAFRvYQ21xxMWWeoPtJrUqG3z",
|
97
109
|
liquidityVault: "AxPJtiTEDksJWvCqNHCziK4uUcabqfmwW41dqtZrPFkp",
|
98
110
|
vaultAuthority: "ELXogWuyXrFyUG1vevffVbEhVxdFrHf2GCJTtRGKBWdM",
|
99
|
-
priceOracle: "42amVS4KgzR9rA28tkVYqVXjq9Qa8dcZQMbH5EYFX6XC",
|
100
111
|
},
|
101
112
|
[tokens.HNT]: {
|
102
113
|
bank: "JBcir4DPRPYVUpks9hkS1jtHMXejfeBo4xJGv3AYYHg6",
|
103
114
|
liquidityVault: "E8Q7u5e9L9Uykx16em75ERT9wfbBPtkNL8gsRjoP8GB9",
|
104
115
|
vaultAuthority: "AjsyrYpgaH275DBSnvNWdGK33hVycSFuXN87FKnX6fVY",
|
105
|
-
priceOracle: "4DdmDswskDxXGpwHrXUfn2CNUm9rt21ac79GHNTN3J33",
|
106
116
|
},
|
107
117
|
[tokens.PYTH]: {
|
108
118
|
bank: "E4td8i8PT2BZkMygzW4MGHCv2KPPs57dvz5W2ZXf9Twu",
|
109
119
|
liquidityVault: "DUrAkkaMAckzes7so9T5frXm9YFFgjAAm3MMwHwTfVJq",
|
110
120
|
vaultAuthority: "9b5KdVnbbfEQ2qhLeFjWvcAx2VWe9XHx7ZgayZyL9a6C",
|
111
|
-
priceOracle: "8vjchtMuJNY4oFQdTi8yCe6mhCaNBFaUbktT482TpLPS",
|
112
121
|
},
|
113
122
|
[tokens.USDC]: {
|
114
123
|
bank: "2s37akK2eyBbp8DZgCm7RtsaEz8eJP3Nxd4urLHQv7yB",
|
115
124
|
liquidityVault: "7jaiZR5Sk8hdYN9MxTpczTcwbWpb5WEoxSANuUwveuat",
|
116
125
|
vaultAuthority: "3uxNepDbmkDNq6JhRja5Z8QwbTrfmkKP8AKZV5chYDGG",
|
117
|
-
priceOracle: USDC_PRICE_ORACLE,
|
118
126
|
},
|
119
127
|
[tokens.USDT]: {
|
120
128
|
bank: "HmpMfL8942u22htC4EMiWgLX931g3sacXFR6KjuLgKLV",
|
121
129
|
liquidityVault: "77t6Fi9qj4s4z22K1toufHtstM8rEy7Y3ytxik7mcsTy",
|
122
130
|
vaultAuthority: "9r6z6KgkEytHCdQWNxvDQH98PsfU98f1m5PCg47mY2XE",
|
123
|
-
priceOracle: "HT2PLQBcG5EiCcNSaMHAjSgd9F98ecpATbk4Sk5oYuM",
|
124
131
|
},
|
125
132
|
[tokens.BONK]: {
|
126
133
|
bank: "DeyH7QxWvnbbaVB4zFrf4hoq7Q8z1ZT14co42BGwGtfM",
|
127
134
|
liquidityVault: "7FdQsXmCW3N5JQbknj3F9Yqq73er9VZJjGhEEMS8Ct2A",
|
128
135
|
vaultAuthority: "26kcZkdjJc94PdhqiLiEaGiLCYgAVVUfpDaZyK4cqih3",
|
129
|
-
priceOracle: "DBE3N8uNjhKPRHfANdwGvCZghWXyLPdqdSbEW2XFwBiX",
|
130
136
|
},
|
131
137
|
[tokens.WIF]: {
|
132
138
|
bank: "9dpu8KL5ABYiD3WP2Cnajzg1XaotcJvZspv29Y1Y3tn1",
|
133
139
|
liquidityVault: "4kT3EXc5dDVndUU9mV6EH3Jh3CSEvpcCZjuMkwqrtxUy",
|
134
140
|
vaultAuthority: "9gNrvvZ9RuTyRWooiEEypwcXU6kyXW8yWuhXU8tWUH5L",
|
135
|
-
priceOracle: "6B23K3tkb51vLZA14jcEQVCA1pfHptzEHFA93V5dYwbT",
|
136
141
|
},
|
137
142
|
},
|
138
143
|
["DQ2jqDJw9uzTwttf6h6r217BQ7kws3jZbJXDkfbCJa1q"]: {
|
@@ -140,13 +145,11 @@ export const MARGINFI_ACCOUNTS: {
|
|
140
145
|
bank: "845oEvt1oduoBj5zQxTr21cWWaUVnRjGerJuW3yMo2nn",
|
141
146
|
liquidityVault: "At6R64ip51zay4dT6k1WnVGETSMcaiY5vggD5DVTgxri",
|
142
147
|
vaultAuthority: "dNraDCWb5usDSoW4kD1Mi2E9WsNu6EABcQZqnrDfjNb",
|
143
|
-
priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.POPCAT.toString()].feedId,
|
144
148
|
},
|
145
149
|
[tokens.USDC]: {
|
146
150
|
bank: "EXrnNVfLagt3j4hCHSD9WqK75o6dkZBtjpnrSrSC78MA",
|
147
151
|
liquidityVault: "D9HSUYz3Rg2cTH65dUPaQS1MYxofNTeLecsAjiBgVPur",
|
148
152
|
vaultAuthority: "5ivKgJnxQ9CewJcKYSPQUiQFdfJki6YS87FqohnMSsFM",
|
149
|
-
priceOracle: USDC_PRICE_ORACLE,
|
150
153
|
},
|
151
154
|
},
|
152
155
|
["EpzY5EYF1A5eFDRfjtsPXSYMPmEx1FXKaXPnouTMF4dm"]: {
|
@@ -154,14 +157,11 @@ export const MARGINFI_ACCOUNTS: {
|
|
154
157
|
bank: "3J5rKmCi7JXG6qmiobFJyAidVTnnNAMGj4jomfBxKGRM",
|
155
158
|
liquidityVault: "863K9YPVT3xbUGFZevrQJLqMux3UdRkwNQ6usAp4hJyy",
|
156
159
|
vaultAuthority: "Qsv2rnNRdv59AwRU3YmGPMCTdKT41CDAKyYAr4srCJR",
|
157
|
-
priceOracle:
|
158
|
-
SWITCHBOARD_PRICE_FEED_IDS[tokens.RETARDIO.toString()].feedId,
|
159
160
|
},
|
160
161
|
[tokens.USDC]: {
|
161
162
|
bank: "6cgYhBFWCc5sNHxkvSRhd5H9AdAHR41zKwuF37HmLry5",
|
162
163
|
liquidityVault: "7orVfNL5ZjqvdSaDgYLgBk4i5B3AnwFXNqqAvJbx6DFy",
|
163
164
|
vaultAuthority: "G4Azxk4PYtNRmDZkJppYo3rNAinkZXzYpQPG5dVDh4Nj",
|
164
|
-
priceOracle: USDC_PRICE_ORACLE,
|
165
165
|
},
|
166
166
|
},
|
167
167
|
["G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"]: {
|
@@ -169,13 +169,11 @@ export const MARGINFI_ACCOUNTS: {
|
|
169
169
|
bank: "Dj3PndQ3j1vuga5ApiFWWAfQ4h3wBtgS2SeLZBT2LD4g",
|
170
170
|
liquidityVault: "BRcRMDVPBQzXNXWtSS6bNotcGxhVsxfiAt1qf8nFVUpx",
|
171
171
|
vaultAuthority: "36SgFh1qBRyj1PEhsn7Kg9Sfwbrn7rHP7kvTM5o5n6AL",
|
172
|
-
priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.BILLY.toString()].feedId,
|
173
172
|
},
|
174
173
|
[tokens.USDC]: {
|
175
174
|
bank: "A7vBgCowCYeja7GTc3pyqUBdC9Gkue2gWaMjGZW38meM",
|
176
175
|
liquidityVault: "DBGhZ8TJTG2Pacdva27zY9etaro24o1tTA3LToSjYHbx",
|
177
176
|
vaultAuthority: "Cg6BCqkGny7A2AXCV8rikhHXM82wqqfzmdsTobEeTQkH",
|
178
|
-
priceOracle: USDC_PRICE_ORACLE,
|
179
177
|
},
|
180
178
|
},
|
181
179
|
["DESG67cExEcw7d6MmENLEzaocR8pLrhfiw9VrNtGWUKD"]: {
|
@@ -183,19 +181,64 @@ export const MARGINFI_ACCOUNTS: {
|
|
183
181
|
bank: "Br3yzg2WSb81RaFWK9UsKtq8fD5viwooZG34mKqQWxdM",
|
184
182
|
liquidityVault: "J45Je52qv2rDBuCQWPwp3bjRhf3bGzRWhKZtGDuLooCX",
|
185
183
|
vaultAuthority: "CKDsAKjNruDSz4tmUairh8PDGD1Rqh9WMTLWERYnnZrH",
|
186
|
-
priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.HMTR.toString()].feedId,
|
187
184
|
},
|
188
185
|
[tokens.USDC]: {
|
189
186
|
bank: "9yNnhJ8c1vGbu3DMf6eeeUi6TDJ2ddGgaRA88rL2R3rP",
|
190
187
|
liquidityVault: "4U1UBjXrPrW7JuQ894JbLUBqcb5LFfK9rfkWFwT7EdQ9",
|
191
188
|
vaultAuthority: "CY74V1r48kuuHA6APD3AaU2oPV1mBqe9srikrQQSHNR6",
|
192
|
-
priceOracle: USDC_PRICE_ORACLE,
|
193
189
|
},
|
194
190
|
},
|
195
191
|
};
|
196
192
|
|
197
|
-
|
193
|
+
const MARGINFI_PROD_ACCOUNTS_LOOKUP_TABLE =
|
198
194
|
"GAjmWmBPcH5Gxbiykasydj6RsCEaCLyHEvK6kHdFigc6";
|
199
195
|
|
200
|
-
|
196
|
+
const MARGINFI_STAGING_ACCOUNTS_LOOKUP_TABLE =
|
201
197
|
"EoEVYjz3MnsX6fKyxrwJkRhzMCHKjj6dvnjTCHoZLMc7";
|
198
|
+
|
199
|
+
export interface MarginfiProgramAccounts {
|
200
|
+
program: PublicKey;
|
201
|
+
defaultGroup: PublicKey;
|
202
|
+
lookupTable: PublicKey;
|
203
|
+
bankAccounts: MarginfiBankAccountsMap;
|
204
|
+
}
|
205
|
+
|
206
|
+
export function getMarginfiAccounts(
|
207
|
+
programEnv?: ProgramEnv,
|
208
|
+
marginfiGroup?: PublicKey
|
209
|
+
): MarginfiProgramAccounts {
|
210
|
+
if (programEnv === undefined) {
|
211
|
+
if (Boolean(marginfiGroup)) {
|
212
|
+
programEnv = Object.keys(MARGINFI_PROD_ACCOUNTS).includes(
|
213
|
+
marginfiGroup!.toString()
|
214
|
+
)
|
215
|
+
? "Prod"
|
216
|
+
: "Staging";
|
217
|
+
} else {
|
218
|
+
programEnv = "Prod";
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
if (programEnv === "Prod") {
|
223
|
+
return {
|
224
|
+
program: MARGINFI_PROD_PROGRAM,
|
225
|
+
defaultGroup: new PublicKey(PROD_DEFAULT_MARGINFI_GROUP),
|
226
|
+
lookupTable: new PublicKey(MARGINFI_PROD_ACCOUNTS_LOOKUP_TABLE),
|
227
|
+
bankAccounts: MARGINFI_PROD_ACCOUNTS,
|
228
|
+
};
|
229
|
+
} else {
|
230
|
+
return {
|
231
|
+
program: MARGINFI_STAGING_PROGRAM,
|
232
|
+
defaultGroup: new PublicKey(STAGING_DEFAULT_MARGINFI_GROUP),
|
233
|
+
lookupTable: new PublicKey(MARGINFI_STAGING_ACCOUNTS_LOOKUP_TABLE),
|
234
|
+
bankAccounts: MARGINFI_STAGING_ACCOUNTS,
|
235
|
+
};
|
236
|
+
}
|
237
|
+
}
|
238
|
+
|
239
|
+
export function isMarginfiProgram(programId: PublicKey) {
|
240
|
+
return (
|
241
|
+
programId.equals(MARGINFI_PROD_PROGRAM) ||
|
242
|
+
programId.equals(MARGINFI_STAGING_PROGRAM)
|
243
|
+
);
|
244
|
+
}
|
@@ -1,5 +1,13 @@
|
|
1
1
|
import { NATIVE_MINT } from "@solana/spl-token";
|
2
2
|
import * as tokens from "./tokenConstants";
|
3
|
+
import { PublicKey } from "@solana/web3.js";
|
4
|
+
|
5
|
+
export const PYTH_PUSH_PROGRAM = new PublicKey(
|
6
|
+
"pythWSnswVUd12oZpeFP8e9CVaEqJg25g1Vtc2biRsT"
|
7
|
+
);
|
8
|
+
|
9
|
+
export const PYTH_SPONSORED_SHARD_ID = 0;
|
10
|
+
export const MARGINFI_SPONSORED_SHARD_ID = 3301;
|
3
11
|
|
4
12
|
// https://pyth.network/developers/price-feed-ids#solana-stable
|
5
13
|
export const PYTH_PRICE_FEED_IDS = {
|
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
TransactionBuilder,
|
9
9
|
} from "@metaplex-foundation/umi";
|
10
10
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
11
|
-
import {
|
11
|
+
import { getMarginfiAccounts } from "../../constants";
|
12
12
|
import {
|
13
13
|
Bank,
|
14
14
|
lendingAccountBorrow,
|
@@ -29,6 +29,7 @@ import {
|
|
29
29
|
fromBaseUnit,
|
30
30
|
getBankLiquidityAvailableBaseUnit,
|
31
31
|
getEmptyMarginfiAccountsByAuthority,
|
32
|
+
getMarginfiPriceOracle,
|
32
33
|
getTokenAccount,
|
33
34
|
rpcAccountCreated,
|
34
35
|
safeGetPrice,
|
@@ -69,16 +70,18 @@ export class MarginfiFlProvider extends FlProviderBase {
|
|
69
70
|
}
|
70
71
|
|
71
72
|
private async setAvailableBanks() {
|
73
|
+
const bankAccounts = getMarginfiAccounts(this.programEnv).bankAccounts;
|
74
|
+
|
72
75
|
const availableBanks: string[] = [];
|
73
|
-
const checkIfUsable = (group: string, mint:
|
74
|
-
if (Object.keys(
|
75
|
-
availableBanks.push(
|
76
|
+
const checkIfUsable = (group: string, mint: string) => {
|
77
|
+
if (Object.keys(bankAccounts[group]).includes(mint)) {
|
78
|
+
availableBanks.push(bankAccounts[group][mint].bank);
|
76
79
|
}
|
77
80
|
};
|
78
81
|
|
79
|
-
for (const group of Object.keys(
|
80
|
-
checkIfUsable(group, this.supplyMint);
|
81
|
-
checkIfUsable(group, this.debtMint);
|
82
|
+
for (const group of Object.keys(bankAccounts)) {
|
83
|
+
checkIfUsable(group, this.supplyMint.toString());
|
84
|
+
checkIfUsable(group, this.debtMint.toString());
|
82
85
|
}
|
83
86
|
|
84
87
|
const banks = await safeFetchAllBank(
|
@@ -299,11 +302,10 @@ export class MarginfiFlProvider extends FlProviderBase {
|
|
299
302
|
flBankHadPrevBalance = true;
|
300
303
|
}
|
301
304
|
|
302
|
-
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
303
|
-
// const bankData = await safeFetchBank(this.umi, publicKey(accounts.data.bank));
|
304
|
-
// const priceOracle = bankData!.config.oracleKeys[0];
|
305
305
|
const priceOracle = publicKey(
|
306
|
-
|
306
|
+
await getMarginfiPriceOracle(this.umi, {
|
307
|
+
pk: toWeb3JsPublicKey(x.bankPk),
|
308
|
+
})
|
307
309
|
);
|
308
310
|
|
309
311
|
remainingAccounts.push(
|
@@ -102,6 +102,7 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
102
102
|
lendingPool: args.lendingPool,
|
103
103
|
lpUserAccount: args.lpUserAccount,
|
104
104
|
lendingPlatform: this.lendingPlatform,
|
105
|
+
lpEnv: this.lpEnv,
|
105
106
|
},
|
106
107
|
this.contextUpdates
|
107
108
|
);
|
@@ -204,12 +205,8 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
204
205
|
return [
|
205
206
|
this.authority,
|
206
207
|
...(this.authorityLutAddress ? [this.authorityLutAddress] : []),
|
207
|
-
|
208
|
-
|
209
|
-
: []),
|
210
|
-
...(toWeb3JsPublicKey(this.signer.publicKey).equals(this.authority)
|
211
|
-
? [this.signerDebtTa]
|
212
|
-
: []),
|
208
|
+
this.signerSupplyTa,
|
209
|
+
this.signerDebtTa,
|
213
210
|
this.pos.publicKey,
|
214
211
|
this.positionSupplyTa,
|
215
212
|
this.positionDebtTa,
|
@@ -238,6 +235,10 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
238
235
|
}
|
239
236
|
| undefined
|
240
237
|
> {
|
238
|
+
if (!toWeb3JsPublicKey(this.signer.publicKey).equals(this.authority)) {
|
239
|
+
return undefined;
|
240
|
+
}
|
241
|
+
|
241
242
|
const existingLutAccounts = await this.fetchExistingAuthorityLutAccounts();
|
242
243
|
if (
|
243
244
|
this.lutAccountsToAdd().every((element) =>
|
@@ -8,10 +8,7 @@ import {
|
|
8
8
|
} from "@metaplex-foundation/umi";
|
9
9
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
10
10
|
import { MarginfiAssetAccounts, RebalanceDetails } from "../../types";
|
11
|
-
import {
|
12
|
-
MARGINFI_ACCOUNTS,
|
13
|
-
MARGINFI_ACCOUNTS_LOOKUP_TABLE,
|
14
|
-
} from "../../constants";
|
11
|
+
import { getMarginfiAccounts, MarginfiProgramAccounts } from "../../constants";
|
15
12
|
import {
|
16
13
|
DCASettingsInpArgs,
|
17
14
|
LendingPlatform,
|
@@ -35,6 +32,7 @@ import {
|
|
35
32
|
hasFirstRebalance,
|
36
33
|
} from "../../utils";
|
37
34
|
import {
|
35
|
+
Bank,
|
38
36
|
lendingAccountBorrow,
|
39
37
|
lendingAccountDeposit,
|
40
38
|
lendingAccountRepay,
|
@@ -47,7 +45,7 @@ import { SolautoClient, SolautoClientArgs } from "./solautoClient";
|
|
47
45
|
export class SolautoMarginfiClient extends SolautoClient {
|
48
46
|
public lendingPlatform = LendingPlatform.Marginfi;
|
49
47
|
|
50
|
-
public
|
48
|
+
public mfiAccounts!: MarginfiProgramAccounts;
|
51
49
|
|
52
50
|
public marginfiAccount!: PublicKey | Signer;
|
53
51
|
public marginfiAccountPk!: PublicKey;
|
@@ -62,9 +60,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
62
60
|
async initialize(args: SolautoClientArgs) {
|
63
61
|
await super.initialize(args);
|
64
62
|
|
65
|
-
this.
|
66
|
-
this.umi.programs.get("marginfi").publicKey
|
67
|
-
);
|
63
|
+
this.mfiAccounts = getMarginfiAccounts(this.lpEnv);
|
68
64
|
|
69
65
|
this.marginfiGroup = await this.pos.lendingPool();
|
70
66
|
|
@@ -110,31 +106,27 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
110
106
|
}
|
111
107
|
|
112
108
|
this.marginfiSupplyAccounts =
|
113
|
-
|
109
|
+
this.mfiAccounts.bankAccounts[this.marginfiGroup.toString()][
|
114
110
|
this.pos.supplyMint().toString()
|
115
111
|
]!;
|
116
112
|
this.marginfiDebtAccounts =
|
117
|
-
|
113
|
+
this.mfiAccounts.bankAccounts[this.marginfiGroup.toString()][
|
118
114
|
this.pos.debtMint().toString()
|
119
115
|
]!;
|
120
116
|
|
121
|
-
|
122
|
-
|
123
|
-
// publicKey(this.marginfiSupplyAccounts.bank),
|
124
|
-
// publicKey(this.marginfiDebtAccounts.bank),
|
125
|
-
// ]);
|
126
|
-
// this.supplyPriceOracle = toWeb3JsPublicKey(supplyBank.config.oracleKeys[0]);
|
127
|
-
// this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
|
128
|
-
this.supplyPriceOracle = new PublicKey(
|
129
|
-
this.marginfiSupplyAccounts.priceOracle
|
130
|
-
);
|
131
|
-
this.debtPriceOracle = new PublicKey(this.marginfiDebtAccounts.priceOracle);
|
117
|
+
[this.supplyPriceOracle, this.debtPriceOracle] =
|
118
|
+
await this.pos.priceOracles();
|
132
119
|
|
133
120
|
this.log("Marginfi account:", this.marginfiAccountPk.toString());
|
121
|
+
this.log("Supply price oracle:", this.supplyPriceOracle.toString());
|
122
|
+
this.log("Debt price oracle:", this.debtPriceOracle.toString());
|
134
123
|
}
|
135
124
|
|
136
125
|
defaultLookupTables(): string[] {
|
137
|
-
return [
|
126
|
+
return [
|
127
|
+
this.mfiAccounts.lookupTable.toString(),
|
128
|
+
...super.defaultLookupTables(),
|
129
|
+
];
|
138
130
|
}
|
139
131
|
|
140
132
|
lutAccountsToAdd(): PublicKey[] {
|
@@ -171,7 +163,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
171
163
|
|
172
164
|
return marginfiOpenPosition(this.umi, {
|
173
165
|
signer: this.signer,
|
174
|
-
marginfiProgram: publicKey(this.
|
166
|
+
marginfiProgram: publicKey(this.mfiAccounts.program),
|
175
167
|
signerReferralState: publicKey(this.referralState),
|
176
168
|
referredByState: this.referredByState
|
177
169
|
? publicKey(this.referredByState)
|
@@ -216,7 +208,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
216
208
|
refreshIx(): TransactionBuilder {
|
217
209
|
return marginfiRefreshData(this.umi, {
|
218
210
|
signer: this.signer,
|
219
|
-
marginfiProgram: publicKey(this.
|
211
|
+
marginfiProgram: publicKey(this.mfiAccounts.program),
|
220
212
|
marginfiGroup: publicKey(this.marginfiGroup),
|
221
213
|
marginfiAccount: publicKey(this.marginfiAccount),
|
222
214
|
supplyBank: publicKey(this.marginfiSupplyAccounts.bank),
|
@@ -344,7 +336,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
344
336
|
|
345
337
|
return marginfiProtocolInteraction(this.umi, {
|
346
338
|
signer: this.signer,
|
347
|
-
marginfiProgram: publicKey(this.
|
339
|
+
marginfiProgram: publicKey(this.mfiAccounts.program),
|
348
340
|
solautoPosition: publicKey(this.pos.publicKey),
|
349
341
|
marginfiGroup: publicKey(this.marginfiGroup),
|
350
342
|
marginfiAccount: publicKey(this.marginfiAccountPk),
|
@@ -395,7 +387,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
395
387
|
|
396
388
|
return marginfiRebalance(this.umi, {
|
397
389
|
signer: this.signer,
|
398
|
-
marginfiProgram: publicKey(this.
|
390
|
+
marginfiProgram: publicKey(this.mfiAccounts.program),
|
399
391
|
ixsSysvar: publicKey(SYSVAR_INSTRUCTIONS_PUBKEY),
|
400
392
|
solautoFeesTa: publicKey(
|
401
393
|
data.values.rebalanceDirection === RebalanceDirection.Boost
|
@@ -39,7 +39,6 @@ import {
|
|
39
39
|
getTokenAccount,
|
40
40
|
getTokenAccountData,
|
41
41
|
isMarginfiClient,
|
42
|
-
isMarginfiProgram,
|
43
42
|
} from "../../utils";
|
44
43
|
import {
|
45
44
|
createMarginfiProgram,
|
@@ -56,6 +55,7 @@ import {
|
|
56
55
|
JUPITER_PROGRAM_ID,
|
57
56
|
} from "../../jupiter-sdk";
|
58
57
|
import { TransactionItemInputs, BundleSimulationError } from "../../types";
|
58
|
+
import { isMarginfiProgram } from "../../constants";
|
59
59
|
|
60
60
|
interface wSolTokenUsage {
|
61
61
|
wSolTokenAccount: PublicKey;
|