@haven-fi/solauto-sdk 1.0.626 → 1.0.628
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 +73 -0
- package/dist/constants/marginfiAccounts.d.ts +3 -4
- package/dist/constants/marginfiAccounts.d.ts.map +1 -1
- package/dist/constants/marginfiAccounts.js +9 -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 +7 -8
- package/dist/services/solauto/solautoClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoClient.js +5 -6
- package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoMarginfiClient.js +4 -9
- 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 +15 -2
- package/dist/solautoPosition/solautoPositionEx.d.ts +2 -0
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- 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 +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/instructionUtils.d.ts +15 -0
- package/dist/utils/instructionUtils.d.ts.map +1 -0
- package/dist/utils/instructionUtils.js +121 -0
- package/dist/utils/marginfiUtils.d.ts +7 -2
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +44 -11
- 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 +9 -15
- package/package.json +1 -1
- package/src/constants/marginfiAccounts.ts +13 -39
- package/src/constants/pythConstants.ts +8 -0
- package/src/services/flashLoans/marginfiFlProvider.ts +9 -9
- package/src/services/solauto/solautoClient.ts +6 -6
- package/src/services/solauto/solautoMarginfiClient.ts +5 -11
- package/src/services/transactions/transactionUtils.ts +1 -1
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +22 -3
- package/src/solautoPosition/solautoPositionEx.ts +2 -0
- 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 +2 -0
- package/src/utils/instructionUtils.ts +181 -0
- package/src/utils/marginfiUtils.ts +75 -17
- package/src/utils/pythUtils.ts +84 -0
- package/src/utils/solautoUtils.ts +1 -1
- package/tests/transactions/shared.ts +22 -66
- package/tests/unit/accounts.ts +7 -13
- package/tests/unit/lookupTables.ts +27 -48
@@ -5,10 +5,10 @@ import { MarginfiAssetAccounts } from "../types/accounts";
|
|
5
5
|
import { SWITCHBOARD_PRICE_FEED_IDS } from "./switchboardConstants";
|
6
6
|
import { ProgramEnv } from "../types";
|
7
7
|
|
8
|
-
|
8
|
+
const MARGINFI_PROD_PROGRAM = new PublicKey(
|
9
9
|
"MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA"
|
10
10
|
);
|
11
|
-
|
11
|
+
const MARGINFI_STAGING_PROGRAM = new PublicKey(
|
12
12
|
"stag8sTKds2h4KzjUw3zKTsxbqvT4XKHdaR9X9E6Rct"
|
13
13
|
);
|
14
14
|
|
@@ -18,150 +18,126 @@ const PROD_DEFAULT_MARGINFI_GROUP =
|
|
18
18
|
const STAGING_DEFAULT_MARGINFI_GROUP =
|
19
19
|
"FCPfpHA69EbS8f9KKSreTRkXbzFpunsKuYf5qNmnJjpo";
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
export type MarginfiAccountsMap = {
|
21
|
+
export type MarginfiBankAccountsMap = {
|
24
22
|
[group: string]: { [token: string]: MarginfiAssetAccounts };
|
25
23
|
};
|
26
24
|
|
27
|
-
const MARGINFI_STAGING_ACCOUNTS:
|
25
|
+
const MARGINFI_STAGING_ACCOUNTS: MarginfiBankAccountsMap = {
|
28
26
|
[STAGING_DEFAULT_MARGINFI_GROUP]: {
|
29
27
|
[NATIVE_MINT.toString()]: {
|
30
28
|
bank: "3evdJSa25nsUiZzEUzd92UNa13TPRJrje1dRyiQP5Lhp",
|
31
29
|
liquidityVault: "FVXESa7wCd1tf3o9LGroBc3Ym8Gpcq1HdsLek6oo7Ykv",
|
32
30
|
vaultAuthority: "DuYk1WGq8UsjW5ThLtaehFLrnJeupTjtF7TaPzja9LBQ",
|
33
|
-
priceOracle: "7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE",
|
34
31
|
},
|
35
32
|
[tokens.USDC]: {
|
36
33
|
bank: "Ek5JSFJFD8QgXM6rPDCzf31XhDp1q3xezaWYSkJWqbqc",
|
37
34
|
liquidityVault: "6n7xXMni5WJKUMb4Vm5Zis6UaUtGF5xEGmagZNVWWoKB",
|
38
35
|
vaultAuthority: "9mXNyA5yS4WSTpYUa5gi3yBrSJWWM7XNPNDWRzWGjdVe",
|
39
|
-
priceOracle: USDC_PRICE_ORACLE,
|
40
36
|
},
|
41
37
|
[tokens.USDT]: {
|
42
38
|
bank: "4WFCsVXwfnQvZG52VvPwae7CtL13PUFVWdjkw5YCRBo6",
|
43
39
|
liquidityVault: "BFSyniKfXU9rHqUvHLKeZMivQsAKWTE7HZ1fW6vZcvJp",
|
44
40
|
vaultAuthority: "Fgxe3SUMzcNuLtT9Xkv8QhhWXCmu4VxynzUMwCF4HvJd",
|
45
|
-
priceOracle: "HT2PLQBcG5EiCcNSaMHAjSgd9F98ecpATbk4Sk5oYuM",
|
46
41
|
},
|
47
42
|
},
|
48
43
|
};
|
49
44
|
|
50
|
-
const MARGINFI_PROD_ACCOUNTS:
|
45
|
+
const MARGINFI_PROD_ACCOUNTS: MarginfiBankAccountsMap = {
|
51
46
|
[PROD_DEFAULT_MARGINFI_GROUP.toString()]: {
|
52
47
|
[NATIVE_MINT.toString()]: {
|
53
48
|
bank: "CCKtUs6Cgwo4aaQUmBPmyoApH2gUDErxNZCAntD6LYGh",
|
54
49
|
liquidityVault: "2eicbpitfJXDwqCuFAmPgDP7t2oUotnAzbGzRKLMgSLe",
|
55
50
|
vaultAuthority: "DD3AeAssFvjqTvRTrRAtpfjkBF8FpVKnFuwnMLN9haXD",
|
56
|
-
priceOracle: "7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE",
|
57
51
|
},
|
58
52
|
[tokens.B_SOL]: {
|
59
53
|
bank: "6hS9i46WyTq1KXcoa2Chas2Txh9TJAVr6n1t3tnrE23K",
|
60
54
|
liquidityVault: "2WMipeKDB2CENxbzdmnVrRbsxCA2LY6kCtBe6AAqDP9p",
|
61
55
|
vaultAuthority: "8RcZHucpVHkHWRRdMhJZsxBK9mqKSYnMKGqtF84U8YEo",
|
62
|
-
priceOracle: "5cN76Xm2Dtx9MnrQqBDeZZRsWruTTcw37UruznAdSvvE",
|
63
56
|
},
|
64
57
|
[tokens.M_SOL]: {
|
65
58
|
bank: "22DcjMZrMwC5Bpa5AGBsmjc5V9VuQrXG6N9ZtdUNyYGE",
|
66
59
|
liquidityVault: "B6HqNn83a2bLqo4i5ygjLHJgD11ePtQksUyx4MjD55DV",
|
67
60
|
vaultAuthority: "6YxGd65JbXzgFGWjE44jsyVeCnZp7Bb1wfL9jDia1n8w",
|
68
|
-
priceOracle: "5CKzb9j4ChgLUt8Gfm5CNGLN6khXKiqMbnGAW4cgXgxK",
|
69
61
|
},
|
70
62
|
[tokens.JITO_SOL]: {
|
71
63
|
bank: "Bohoc1ikHLD7xKJuzTyiTyCwzaL5N7ggJQu75A8mKYM8",
|
72
64
|
liquidityVault: "38VGtXd2pDPq9FMh1z6AVjcHCoHgvWyMhdNyamDTeeks",
|
73
65
|
vaultAuthority: "7Ng54qf7BrCcZLqXmKA9WSR7SVRn4q6RX1YpLksBQ21A",
|
74
|
-
priceOracle: "AxaxyeDT8JnWERSaTKvFXvPKkEdxnamKSqpWbsSjYg1g",
|
75
66
|
},
|
76
67
|
[tokens.LST]: {
|
77
68
|
bank: "DMoqjmsuoru986HgfjqrKEvPv8YBufvBGADHUonkadC5",
|
78
69
|
liquidityVault: "DMQUXpb6K5L8osgV4x3NeEPUoJCf2VBgnA8FQusDjSou",
|
79
70
|
vaultAuthority: "6PWVauGLhBFHUJspsnBVZHr56ZnbvmhSD2gS7czBHGpE",
|
80
|
-
priceOracle: "7aT9A5knp62jVvnEW33xaWopaPHa3Y7ggULyYiUsDhu8",
|
81
71
|
},
|
82
72
|
[tokens.INF]: {
|
83
73
|
bank: "AwLRW3aPMMftXEjgWhTkYwM9CGBHdtKecvahCJZBwAqY",
|
84
74
|
liquidityVault: "HQ1CGcqRshMhuonTGTnnmgw9ffcXxizGdZ6F6PKffWWi",
|
85
75
|
vaultAuthority: "AEZb1XH5bfLwqk3hBKDuLfWyJKdLTgDPCkgn64BJKcvV",
|
86
|
-
priceOracle: "Ceg5oePJv1a6RR541qKeQaTepvERA3i8SvyueX9tT8Sq",
|
87
76
|
},
|
88
77
|
[tokens.H_SOL]: {
|
89
78
|
bank: "GJCi1uj3kYPZ64puA5sLUiCQfFapxT2xnREzrbDzFkYY",
|
90
79
|
liquidityVault: "8M97jkdr4rJtPnQ4yQ9stD6qVwaUvjrBdDPDbHJnPJLf",
|
91
80
|
vaultAuthority: "8x7mgTn5RvHR8Tn3CJqexSuQwrs6MLEy8csuXCDVvvpt",
|
92
|
-
priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.H_SOL.toString()].feedId,
|
93
81
|
},
|
94
82
|
[tokens.JUP_SOL]: {
|
95
83
|
bank: "8LaUZadNqtzuCG7iCvZd7d5cbquuYfv19KjAg6GPuuCb",
|
96
84
|
liquidityVault: "B1zjqKPoYp9bTMhzFADaAvjyGb49FMitLpi6P3Pa3YR6",
|
97
85
|
vaultAuthority: "93Qqsge2jHVsWLd8vas4cWghrsZJooMUr5JKN5DtcfMX",
|
98
|
-
priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.JUP_SOL.toString()].feedId,
|
99
86
|
},
|
100
87
|
[tokens.JUP]: {
|
101
88
|
bank: "Guu5uBc8k1WK1U2ihGosNaCy57LSgCkpWAabtzQqrQf8",
|
102
89
|
liquidityVault: "4w49W4fNDn778wsBa6TNq9hvebZKU17ymsptrEZ8zrsm",
|
103
90
|
vaultAuthority: "2MBwwAhL3c73Jy7HkWd9ofzh1bU39JBabrZCFQR2tUof",
|
104
|
-
priceOracle: "7dbob1psH1iZBS7qPsm3Kwbf5DzSXK8Jyg31CTgTnxH5",
|
105
91
|
},
|
106
92
|
[tokens.JTO]: {
|
107
93
|
bank: "EdB7YADw4XUt6wErT8kHGCUok4mnTpWGzPUU9rWDebzb",
|
108
94
|
liquidityVault: "3bY1DEkXodGmPMG5f7ABA12228MBG5JdAAKf5cgkB6G1",
|
109
95
|
vaultAuthority: "H2b4f2fGSKFortxwzrMZBnYVfr2yrKVUakg4Md9be3Wv",
|
110
|
-
priceOracle: "7ajR2zA4MGMMTqRAVjghTKqPPn4kbrj3pYkAVRVwTGzP",
|
111
96
|
},
|
112
97
|
[tokens.JLP]: {
|
113
98
|
bank: "Amtw3n7GZe5SWmyhMhaFhDTi39zbTkLeWErBsmZXwpDa",
|
114
99
|
liquidityVault: "9xfyL8gxbV77VvhdgFmacHyLEG4h7d2eDWkSMfhXUPQ",
|
115
100
|
vaultAuthority: "F4RSGd4BRXscCqAVG3rFLiPVpo7v6j1drVqnvSM3rBKH",
|
116
|
-
priceOracle: "2TTGSRSezqFzeLUH8JwRUbtN66XLLaymfYsWRTMjfiMw",
|
117
101
|
},
|
118
102
|
[tokens.WBTC]: {
|
119
103
|
bank: "BKsfDJCMbYep6gr9pq8PsmJbb5XGLHbAJzUV8vmorz7a",
|
120
104
|
liquidityVault: "CMNdnjfaDQZo3VMoX31wZQBnSGu5FMmb1CnBaU4tApZk",
|
121
105
|
vaultAuthority: "7P2TQHYgVJkXv1VPaREsL5Pi1gnNjVif5aF3pJewZ9kj",
|
122
|
-
priceOracle: "4cSM2e6rvbGQUFiJbqytoVMi5GgghSMr8LwVrT9VPSPo",
|
123
106
|
},
|
124
107
|
[tokens.WETH]: {
|
125
108
|
bank: "BkUyfXjbBBALcfZvw76WAFRvYQ21xxMWWeoPtJrUqG3z",
|
126
109
|
liquidityVault: "AxPJtiTEDksJWvCqNHCziK4uUcabqfmwW41dqtZrPFkp",
|
127
110
|
vaultAuthority: "ELXogWuyXrFyUG1vevffVbEhVxdFrHf2GCJTtRGKBWdM",
|
128
|
-
priceOracle: "42amVS4KgzR9rA28tkVYqVXjq9Qa8dcZQMbH5EYFX6XC",
|
129
111
|
},
|
130
112
|
[tokens.HNT]: {
|
131
113
|
bank: "JBcir4DPRPYVUpks9hkS1jtHMXejfeBo4xJGv3AYYHg6",
|
132
114
|
liquidityVault: "E8Q7u5e9L9Uykx16em75ERT9wfbBPtkNL8gsRjoP8GB9",
|
133
115
|
vaultAuthority: "AjsyrYpgaH275DBSnvNWdGK33hVycSFuXN87FKnX6fVY",
|
134
|
-
priceOracle: "4DdmDswskDxXGpwHrXUfn2CNUm9rt21ac79GHNTN3J33",
|
135
116
|
},
|
136
117
|
[tokens.PYTH]: {
|
137
118
|
bank: "E4td8i8PT2BZkMygzW4MGHCv2KPPs57dvz5W2ZXf9Twu",
|
138
119
|
liquidityVault: "DUrAkkaMAckzes7so9T5frXm9YFFgjAAm3MMwHwTfVJq",
|
139
120
|
vaultAuthority: "9b5KdVnbbfEQ2qhLeFjWvcAx2VWe9XHx7ZgayZyL9a6C",
|
140
|
-
priceOracle: "8vjchtMuJNY4oFQdTi8yCe6mhCaNBFaUbktT482TpLPS",
|
141
121
|
},
|
142
122
|
[tokens.USDC]: {
|
143
123
|
bank: "2s37akK2eyBbp8DZgCm7RtsaEz8eJP3Nxd4urLHQv7yB",
|
144
124
|
liquidityVault: "7jaiZR5Sk8hdYN9MxTpczTcwbWpb5WEoxSANuUwveuat",
|
145
125
|
vaultAuthority: "3uxNepDbmkDNq6JhRja5Z8QwbTrfmkKP8AKZV5chYDGG",
|
146
|
-
priceOracle: USDC_PRICE_ORACLE,
|
147
126
|
},
|
148
127
|
[tokens.USDT]: {
|
149
128
|
bank: "HmpMfL8942u22htC4EMiWgLX931g3sacXFR6KjuLgKLV",
|
150
129
|
liquidityVault: "77t6Fi9qj4s4z22K1toufHtstM8rEy7Y3ytxik7mcsTy",
|
151
130
|
vaultAuthority: "9r6z6KgkEytHCdQWNxvDQH98PsfU98f1m5PCg47mY2XE",
|
152
|
-
priceOracle: "HT2PLQBcG5EiCcNSaMHAjSgd9F98ecpATbk4Sk5oYuM",
|
153
131
|
},
|
154
132
|
[tokens.BONK]: {
|
155
133
|
bank: "DeyH7QxWvnbbaVB4zFrf4hoq7Q8z1ZT14co42BGwGtfM",
|
156
134
|
liquidityVault: "7FdQsXmCW3N5JQbknj3F9Yqq73er9VZJjGhEEMS8Ct2A",
|
157
135
|
vaultAuthority: "26kcZkdjJc94PdhqiLiEaGiLCYgAVVUfpDaZyK4cqih3",
|
158
|
-
priceOracle: "DBE3N8uNjhKPRHfANdwGvCZghWXyLPdqdSbEW2XFwBiX",
|
159
136
|
},
|
160
137
|
[tokens.WIF]: {
|
161
138
|
bank: "9dpu8KL5ABYiD3WP2Cnajzg1XaotcJvZspv29Y1Y3tn1",
|
162
139
|
liquidityVault: "4kT3EXc5dDVndUU9mV6EH3Jh3CSEvpcCZjuMkwqrtxUy",
|
163
140
|
vaultAuthority: "9gNrvvZ9RuTyRWooiEEypwcXU6kyXW8yWuhXU8tWUH5L",
|
164
|
-
priceOracle: "6B23K3tkb51vLZA14jcEQVCA1pfHptzEHFA93V5dYwbT",
|
165
141
|
},
|
166
142
|
},
|
167
143
|
["DQ2jqDJw9uzTwttf6h6r217BQ7kws3jZbJXDkfbCJa1q"]: {
|
@@ -169,13 +145,11 @@ const MARGINFI_PROD_ACCOUNTS: MarginfiAccountsMap = {
|
|
169
145
|
bank: "845oEvt1oduoBj5zQxTr21cWWaUVnRjGerJuW3yMo2nn",
|
170
146
|
liquidityVault: "At6R64ip51zay4dT6k1WnVGETSMcaiY5vggD5DVTgxri",
|
171
147
|
vaultAuthority: "dNraDCWb5usDSoW4kD1Mi2E9WsNu6EABcQZqnrDfjNb",
|
172
|
-
priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.POPCAT.toString()].feedId,
|
173
148
|
},
|
174
149
|
[tokens.USDC]: {
|
175
150
|
bank: "EXrnNVfLagt3j4hCHSD9WqK75o6dkZBtjpnrSrSC78MA",
|
176
151
|
liquidityVault: "D9HSUYz3Rg2cTH65dUPaQS1MYxofNTeLecsAjiBgVPur",
|
177
152
|
vaultAuthority: "5ivKgJnxQ9CewJcKYSPQUiQFdfJki6YS87FqohnMSsFM",
|
178
|
-
priceOracle: USDC_PRICE_ORACLE,
|
179
153
|
},
|
180
154
|
},
|
181
155
|
["EpzY5EYF1A5eFDRfjtsPXSYMPmEx1FXKaXPnouTMF4dm"]: {
|
@@ -183,14 +157,11 @@ const MARGINFI_PROD_ACCOUNTS: MarginfiAccountsMap = {
|
|
183
157
|
bank: "3J5rKmCi7JXG6qmiobFJyAidVTnnNAMGj4jomfBxKGRM",
|
184
158
|
liquidityVault: "863K9YPVT3xbUGFZevrQJLqMux3UdRkwNQ6usAp4hJyy",
|
185
159
|
vaultAuthority: "Qsv2rnNRdv59AwRU3YmGPMCTdKT41CDAKyYAr4srCJR",
|
186
|
-
priceOracle:
|
187
|
-
SWITCHBOARD_PRICE_FEED_IDS[tokens.RETARDIO.toString()].feedId,
|
188
160
|
},
|
189
161
|
[tokens.USDC]: {
|
190
162
|
bank: "6cgYhBFWCc5sNHxkvSRhd5H9AdAHR41zKwuF37HmLry5",
|
191
163
|
liquidityVault: "7orVfNL5ZjqvdSaDgYLgBk4i5B3AnwFXNqqAvJbx6DFy",
|
192
164
|
vaultAuthority: "G4Azxk4PYtNRmDZkJppYo3rNAinkZXzYpQPG5dVDh4Nj",
|
193
|
-
priceOracle: USDC_PRICE_ORACLE,
|
194
165
|
},
|
195
166
|
},
|
196
167
|
["G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"]: {
|
@@ -198,13 +169,11 @@ const MARGINFI_PROD_ACCOUNTS: MarginfiAccountsMap = {
|
|
198
169
|
bank: "Dj3PndQ3j1vuga5ApiFWWAfQ4h3wBtgS2SeLZBT2LD4g",
|
199
170
|
liquidityVault: "BRcRMDVPBQzXNXWtSS6bNotcGxhVsxfiAt1qf8nFVUpx",
|
200
171
|
vaultAuthority: "36SgFh1qBRyj1PEhsn7Kg9Sfwbrn7rHP7kvTM5o5n6AL",
|
201
|
-
priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.BILLY.toString()].feedId,
|
202
172
|
},
|
203
173
|
[tokens.USDC]: {
|
204
174
|
bank: "A7vBgCowCYeja7GTc3pyqUBdC9Gkue2gWaMjGZW38meM",
|
205
175
|
liquidityVault: "DBGhZ8TJTG2Pacdva27zY9etaro24o1tTA3LToSjYHbx",
|
206
176
|
vaultAuthority: "Cg6BCqkGny7A2AXCV8rikhHXM82wqqfzmdsTobEeTQkH",
|
207
|
-
priceOracle: USDC_PRICE_ORACLE,
|
208
177
|
},
|
209
178
|
},
|
210
179
|
["DESG67cExEcw7d6MmENLEzaocR8pLrhfiw9VrNtGWUKD"]: {
|
@@ -212,13 +181,11 @@ const MARGINFI_PROD_ACCOUNTS: MarginfiAccountsMap = {
|
|
212
181
|
bank: "Br3yzg2WSb81RaFWK9UsKtq8fD5viwooZG34mKqQWxdM",
|
213
182
|
liquidityVault: "J45Je52qv2rDBuCQWPwp3bjRhf3bGzRWhKZtGDuLooCX",
|
214
183
|
vaultAuthority: "CKDsAKjNruDSz4tmUairh8PDGD1Rqh9WMTLWERYnnZrH",
|
215
|
-
priceOracle: SWITCHBOARD_PRICE_FEED_IDS[tokens.HMTR.toString()].feedId,
|
216
184
|
},
|
217
185
|
[tokens.USDC]: {
|
218
186
|
bank: "9yNnhJ8c1vGbu3DMf6eeeUi6TDJ2ddGgaRA88rL2R3rP",
|
219
187
|
liquidityVault: "4U1UBjXrPrW7JuQ894JbLUBqcb5LFfK9rfkWFwT7EdQ9",
|
220
188
|
vaultAuthority: "CY74V1r48kuuHA6APD3AaU2oPV1mBqe9srikrQQSHNR6",
|
221
|
-
priceOracle: USDC_PRICE_ORACLE,
|
222
189
|
},
|
223
190
|
},
|
224
191
|
};
|
@@ -233,7 +200,7 @@ export interface MarginfiProgramAccounts {
|
|
233
200
|
program: PublicKey;
|
234
201
|
defaultGroup: PublicKey;
|
235
202
|
lookupTable: PublicKey;
|
236
|
-
bankAccounts:
|
203
|
+
bankAccounts: MarginfiBankAccountsMap;
|
237
204
|
}
|
238
205
|
|
239
206
|
export function getMarginfiAccounts(
|
@@ -268,3 +235,10 @@ export function getMarginfiAccounts(
|
|
268
235
|
};
|
269
236
|
}
|
270
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 = {
|
@@ -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,
|
@@ -72,15 +73,15 @@ export class MarginfiFlProvider extends FlProviderBase {
|
|
72
73
|
const bankAccounts = getMarginfiAccounts(this.programEnv).bankAccounts;
|
73
74
|
|
74
75
|
const availableBanks: string[] = [];
|
75
|
-
const checkIfUsable = (group: string, mint:
|
76
|
-
if (Object.keys(bankAccounts[group]).includes(mint
|
77
|
-
availableBanks.push(bankAccounts[group][mint
|
76
|
+
const checkIfUsable = (group: string, mint: string) => {
|
77
|
+
if (Object.keys(bankAccounts[group]).includes(mint)) {
|
78
|
+
availableBanks.push(bankAccounts[group][mint].bank);
|
78
79
|
}
|
79
80
|
};
|
80
81
|
|
81
82
|
for (const group of Object.keys(bankAccounts)) {
|
82
|
-
checkIfUsable(group, this.supplyMint);
|
83
|
-
checkIfUsable(group, this.debtMint);
|
83
|
+
checkIfUsable(group, this.supplyMint.toString());
|
84
|
+
checkIfUsable(group, this.debtMint.toString());
|
84
85
|
}
|
85
86
|
|
86
87
|
const banks = await safeFetchAllBank(
|
@@ -301,11 +302,10 @@ export class MarginfiFlProvider extends FlProviderBase {
|
|
301
302
|
flBankHadPrevBalance = true;
|
302
303
|
}
|
303
304
|
|
304
|
-
// TODO: Don't dynamically pull from bank until Marginfi sorts out their price oracle issues.
|
305
|
-
// const bankData = await safeFetchBank(this.umi, publicKey(accounts.data.bank));
|
306
|
-
// const priceOracle = bankData!.config.oracleKeys[0];
|
307
305
|
const priceOracle = publicKey(
|
308
|
-
|
306
|
+
await getMarginfiPriceOracle(this.umi, {
|
307
|
+
pk: toWeb3JsPublicKey(x.bankPk),
|
308
|
+
})
|
309
309
|
);
|
310
310
|
|
311
311
|
remainingAccounts.push(
|
@@ -205,12 +205,8 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
205
205
|
return [
|
206
206
|
this.authority,
|
207
207
|
...(this.authorityLutAddress ? [this.authorityLutAddress] : []),
|
208
|
-
|
209
|
-
|
210
|
-
: []),
|
211
|
-
...(toWeb3JsPublicKey(this.signer.publicKey).equals(this.authority)
|
212
|
-
? [this.signerDebtTa]
|
213
|
-
: []),
|
208
|
+
this.signerSupplyTa,
|
209
|
+
this.signerDebtTa,
|
214
210
|
this.pos.publicKey,
|
215
211
|
this.positionSupplyTa,
|
216
212
|
this.positionDebtTa,
|
@@ -239,6 +235,10 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
239
235
|
}
|
240
236
|
| undefined
|
241
237
|
> {
|
238
|
+
if (!toWeb3JsPublicKey(this.signer.publicKey).equals(this.authority)) {
|
239
|
+
return undefined;
|
240
|
+
}
|
241
|
+
|
242
242
|
const existingLutAccounts = await this.fetchExistingAuthorityLutAccounts();
|
243
243
|
if (
|
244
244
|
this.lutAccountsToAdd().every((element) =>
|
@@ -32,6 +32,7 @@ import {
|
|
32
32
|
hasFirstRebalance,
|
33
33
|
} from "../../utils";
|
34
34
|
import {
|
35
|
+
Bank,
|
35
36
|
lendingAccountBorrow,
|
36
37
|
lendingAccountDeposit,
|
37
38
|
lendingAccountRepay,
|
@@ -113,19 +114,12 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
113
114
|
this.pos.debtMint().toString()
|
114
115
|
]!;
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
// publicKey(this.marginfiSupplyAccounts.bank),
|
119
|
-
// publicKey(this.marginfiDebtAccounts.bank),
|
120
|
-
// ]);
|
121
|
-
// this.supplyPriceOracle = toWeb3JsPublicKey(supplyBank.config.oracleKeys[0]);
|
122
|
-
// this.debtPriceOracle = toWeb3JsPublicKey(debtBank.config.oracleKeys[0]);
|
123
|
-
this.supplyPriceOracle = new PublicKey(
|
124
|
-
this.marginfiSupplyAccounts.priceOracle
|
125
|
-
);
|
126
|
-
this.debtPriceOracle = new PublicKey(this.marginfiDebtAccounts.priceOracle);
|
117
|
+
[this.supplyPriceOracle, this.debtPriceOracle] =
|
118
|
+
await this.pos.priceOracles();
|
127
119
|
|
128
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());
|
129
123
|
}
|
130
124
|
|
131
125
|
defaultLookupTables(): string[] {
|
@@ -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;
|
@@ -13,11 +13,15 @@ import {
|
|
13
13
|
fromBaseUnit,
|
14
14
|
getBankLiquidityAvailableBaseUnit,
|
15
15
|
getMarginfiAccountPositionState,
|
16
|
+
getMarginfiPriceOracle,
|
16
17
|
} from "../utils";
|
17
18
|
import { getMarginfiAccounts } from "../constants";
|
18
19
|
import { SolautoPositionEx } from "./solautoPositionEx";
|
20
|
+
import { LendingPlatform } from "../generated";
|
19
21
|
|
20
22
|
export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
23
|
+
lendingPlatform = LendingPlatform.Marginfi;
|
24
|
+
|
21
25
|
private marginfiAccountData: MarginfiAccount | null = null;
|
22
26
|
private supplyBank: Bank | null = null;
|
23
27
|
private debtBank: Bank | null = null;
|
@@ -47,7 +51,7 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
47
51
|
return this.lp;
|
48
52
|
}
|
49
53
|
|
50
|
-
async
|
54
|
+
async getBanks(): Promise<Bank[]> {
|
51
55
|
if (!this.supplyBank || !this.debtBank) {
|
52
56
|
const group = (await this.lendingPool()).toString();
|
53
57
|
const bankAccounts = getMarginfiAccounts(this.lpEnv).bankAccounts;
|
@@ -60,10 +64,25 @@ export class MarginfiSolautoPositionEx extends SolautoPositionEx {
|
|
60
64
|
]);
|
61
65
|
}
|
62
66
|
|
67
|
+
return [this.supplyBank!, this.debtBank!];
|
68
|
+
}
|
69
|
+
|
70
|
+
async priceOracles(): Promise<PublicKey[]> {
|
71
|
+
const [supplyBank, debtBank] = await this.getBanks();
|
72
|
+
|
73
|
+
return await Promise.all([
|
74
|
+
getMarginfiPriceOracle(this.umi, { data: supplyBank }),
|
75
|
+
getMarginfiPriceOracle(this.umi, { data: debtBank }),
|
76
|
+
]);
|
77
|
+
}
|
78
|
+
|
79
|
+
async maxLtvAndLiqThresholdBps(): Promise<[number, number]> {
|
80
|
+
const [supplyBank, debtBank] = await this.getBanks();
|
81
|
+
|
63
82
|
const [supplyPrice] = await fetchTokenPrices([this.supplyMint()]);
|
64
83
|
const [maxLtvBps, liqThresholdBps] = calcMarginfiMaxLtvAndLiqThresholdBps(
|
65
|
-
|
66
|
-
|
84
|
+
supplyBank,
|
85
|
+
debtBank,
|
67
86
|
supplyPrice
|
68
87
|
);
|
69
88
|
|
@@ -67,6 +67,7 @@ interface PositionExArgs {
|
|
67
67
|
}
|
68
68
|
|
69
69
|
export abstract class SolautoPositionEx {
|
70
|
+
public lendingPlatform!: LendingPlatform;
|
70
71
|
public umi!: Umi;
|
71
72
|
public publicKey!: PublicKey;
|
72
73
|
protected _data!: SolautoPositionExData;
|
@@ -226,6 +227,7 @@ export abstract class SolautoPositionEx {
|
|
226
227
|
}
|
227
228
|
|
228
229
|
abstract maxLtvAndLiqThresholdBps(): Promise<[number, number]>;
|
230
|
+
abstract priceOracles(): Promise<PublicKey[]>;
|
229
231
|
abstract supplyLiquidityAvailable(): number;
|
230
232
|
|
231
233
|
sufficientLiquidityToBoost() {
|
package/src/types/accounts.ts
CHANGED
@@ -184,3 +184,15 @@ export async function customRpcCall(umi: Umi, method: string, params?: any) {
|
|
184
184
|
return data;
|
185
185
|
}
|
186
186
|
}
|
187
|
+
|
188
|
+
export function u16ToArrayBufferLE(value: number): Uint8Array {
|
189
|
+
// Create a buffer of 2 bytes
|
190
|
+
const buffer = new ArrayBuffer(2);
|
191
|
+
const dataView = new DataView(buffer);
|
192
|
+
|
193
|
+
// Set the Uint16 value in little-endian order
|
194
|
+
dataView.setUint16(0, value, true);
|
195
|
+
|
196
|
+
// Return the buffer
|
197
|
+
return new Uint8Array(buffer);
|
198
|
+
}
|
package/src/utils/index.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
export * from "./accountUtils";
|
2
2
|
export * from "./generalUtils";
|
3
|
+
export * from "./instructionUtils";
|
3
4
|
export * from "./jitoUtils";
|
4
5
|
export * from "./jupiterUtils";
|
5
6
|
export * from "./marginfiUtils";
|
@@ -8,4 +9,5 @@ export * from "./solautoUtils";
|
|
8
9
|
export * from "./solanaUtils";
|
9
10
|
export * from "./stringUtils";
|
10
11
|
export * from "./priceUtils";
|
12
|
+
export * from "./pythUtils";
|
11
13
|
export * from "./switchboardUtils";
|
@@ -0,0 +1,181 @@
|
|
1
|
+
import { OptionOrNullable, transactionBuilder } from "@metaplex-foundation/umi";
|
2
|
+
import {
|
3
|
+
DCASettingsInpArgs,
|
4
|
+
SolautoSettingsParametersInpArgs,
|
5
|
+
} from "../generated";
|
6
|
+
import {
|
7
|
+
JupSwapManager,
|
8
|
+
RebalanceTxBuilder,
|
9
|
+
SolautoClient,
|
10
|
+
SwapInput,
|
11
|
+
TransactionItem,
|
12
|
+
} from "../services";
|
13
|
+
import { PublicKey } from "@solana/web3.js";
|
14
|
+
import { tokenInfo } from "./generalUtils";
|
15
|
+
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
16
|
+
|
17
|
+
export function openSolautoPosition(
|
18
|
+
client: SolautoClient,
|
19
|
+
settingParams: SolautoSettingsParametersInpArgs,
|
20
|
+
dca?: DCASettingsInpArgs
|
21
|
+
) {
|
22
|
+
return new TransactionItem(
|
23
|
+
async () => ({
|
24
|
+
tx: client!.openPositionIx(settingParams, dca),
|
25
|
+
}),
|
26
|
+
"open position"
|
27
|
+
);
|
28
|
+
}
|
29
|
+
|
30
|
+
export function closeSolautoPosition(client: SolautoClient) {
|
31
|
+
return new TransactionItem(
|
32
|
+
async () => ({
|
33
|
+
tx: client.closePositionIx(),
|
34
|
+
}),
|
35
|
+
"close position"
|
36
|
+
);
|
37
|
+
}
|
38
|
+
|
39
|
+
export function updateSolautoPosition(
|
40
|
+
client: SolautoClient,
|
41
|
+
settings: OptionOrNullable<SolautoSettingsParametersInpArgs>,
|
42
|
+
dca: OptionOrNullable<DCASettingsInpArgs>
|
43
|
+
) {
|
44
|
+
return new TransactionItem(
|
45
|
+
async () => ({
|
46
|
+
tx: client.updatePositionIx({
|
47
|
+
positionId: client.positionId,
|
48
|
+
settings,
|
49
|
+
dca,
|
50
|
+
}),
|
51
|
+
}),
|
52
|
+
"update position"
|
53
|
+
);
|
54
|
+
}
|
55
|
+
|
56
|
+
export function cancelSolautoDca(client: SolautoClient) {
|
57
|
+
return new TransactionItem(
|
58
|
+
async () => ({
|
59
|
+
tx: client.cancelDCAIx(),
|
60
|
+
}),
|
61
|
+
"cancel DCA"
|
62
|
+
);
|
63
|
+
}
|
64
|
+
|
65
|
+
export function deposit(client: SolautoClient, baseUnitAmount: bigint) {
|
66
|
+
return new TransactionItem(
|
67
|
+
async () => ({
|
68
|
+
tx: client.protocolInteractionIx({
|
69
|
+
__kind: "Deposit",
|
70
|
+
fields: [baseUnitAmount],
|
71
|
+
}),
|
72
|
+
}),
|
73
|
+
"deposit"
|
74
|
+
);
|
75
|
+
}
|
76
|
+
|
77
|
+
export function borrow(client: SolautoClient, baseUnitAmount: bigint) {
|
78
|
+
return new TransactionItem(
|
79
|
+
async () => ({
|
80
|
+
tx: client.protocolInteractionIx({
|
81
|
+
__kind: "Borrow",
|
82
|
+
fields: [baseUnitAmount],
|
83
|
+
}),
|
84
|
+
}),
|
85
|
+
"borrow"
|
86
|
+
);
|
87
|
+
}
|
88
|
+
|
89
|
+
export function withdraw(client: SolautoClient, amount: "All" | bigint) {
|
90
|
+
return new TransactionItem(
|
91
|
+
async () => ({
|
92
|
+
tx: client.protocolInteractionIx({
|
93
|
+
__kind: "Withdraw",
|
94
|
+
fields: [
|
95
|
+
amount === "All"
|
96
|
+
? { __kind: "All" }
|
97
|
+
: { __kind: "Some", fields: [amount] },
|
98
|
+
],
|
99
|
+
}),
|
100
|
+
}),
|
101
|
+
"withdraw"
|
102
|
+
);
|
103
|
+
}
|
104
|
+
|
105
|
+
export function repay(client: SolautoClient, amount: "All" | bigint) {
|
106
|
+
return new TransactionItem(
|
107
|
+
async () => ({
|
108
|
+
tx: client.protocolInteractionIx({
|
109
|
+
__kind: "Repay",
|
110
|
+
fields: [
|
111
|
+
amount === "All"
|
112
|
+
? { __kind: "All" }
|
113
|
+
: { __kind: "Some", fields: [amount] },
|
114
|
+
],
|
115
|
+
}),
|
116
|
+
}),
|
117
|
+
"repay"
|
118
|
+
);
|
119
|
+
}
|
120
|
+
|
121
|
+
export function rebalance(
|
122
|
+
client: SolautoClient,
|
123
|
+
targetLiqUtilizationRateBps?: number
|
124
|
+
) {
|
125
|
+
return new TransactionItem(
|
126
|
+
async (attemptNum) =>
|
127
|
+
await new RebalanceTxBuilder(
|
128
|
+
client,
|
129
|
+
targetLiqUtilizationRateBps
|
130
|
+
).buildRebalanceTx(attemptNum),
|
131
|
+
"rebalance"
|
132
|
+
);
|
133
|
+
}
|
134
|
+
|
135
|
+
export function swapThenDeposit(
|
136
|
+
client: SolautoClient,
|
137
|
+
depositMint: PublicKey,
|
138
|
+
depositAmountBaseUnit: bigint
|
139
|
+
) {
|
140
|
+
return [
|
141
|
+
new TransactionItem(async () => {
|
142
|
+
const memeSwap = tokenInfo(client.pos.supplyMint()).isMeme;
|
143
|
+
const swapInput: SwapInput = {
|
144
|
+
inputMint: depositMint,
|
145
|
+
outputMint: client.pos.supplyMint(),
|
146
|
+
amount: depositAmountBaseUnit,
|
147
|
+
exactIn: true,
|
148
|
+
slippageBps: memeSwap ? 300 : 50,
|
149
|
+
};
|
150
|
+
const jupSwapManager = new JupSwapManager(client.signer);
|
151
|
+
const { setupIx, swapIx, cleanupIx, lookupTableAddresses } =
|
152
|
+
await jupSwapManager.getJupSwapTxData({
|
153
|
+
...swapInput,
|
154
|
+
destinationWallet: toWeb3JsPublicKey(client.signer.publicKey),
|
155
|
+
wrapAndUnwrapSol: true,
|
156
|
+
});
|
157
|
+
|
158
|
+
client.contextUpdates.new({
|
159
|
+
type: "jupSwap",
|
160
|
+
value: jupSwapManager.jupQuote!,
|
161
|
+
});
|
162
|
+
|
163
|
+
return {
|
164
|
+
tx: transactionBuilder().add([setupIx, swapIx, cleanupIx]),
|
165
|
+
lookupTableAddresses,
|
166
|
+
orderPrio: -1,
|
167
|
+
};
|
168
|
+
}, "swap"),
|
169
|
+
new TransactionItem(async () => {
|
170
|
+
const quoteOutAmount = client.contextUpdates.jupSwap?.outAmount;
|
171
|
+
return {
|
172
|
+
tx: transactionBuilder().add(
|
173
|
+
client.protocolInteractionIx({
|
174
|
+
__kind: "Deposit",
|
175
|
+
fields: [BigInt(Math.round(parseInt(quoteOutAmount!) * 0.995))],
|
176
|
+
})
|
177
|
+
),
|
178
|
+
};
|
179
|
+
}, "deposit"),
|
180
|
+
];
|
181
|
+
}
|