@haven-fi/solauto-sdk 1.0.624 → 1.0.626
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 +12 -4
- package/dist/constants/marginfiAccounts.d.ts.map +1 -1
- package/dist/constants/marginfiAccounts.js +62 -8
- 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 +6 -6
- 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 +22 -24
- package/dist/services/solauto/solautoMarginfiClient.d.ts +5 -5
- package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/services/solauto/solautoMarginfiClient.js +22 -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 +6 -5
- package/dist/solautoPosition/solautoPositionEx.d.ts +4 -2
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -1
- package/dist/solautoPosition/solautoPositionEx.js +12 -5
- 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 +13 -4
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +78 -22
- 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 +40 -49
- 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 +88 -10
- 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 +9 -8
- 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 +10 -15
- package/src/services/solauto/solautoMarginfiClient.ts +26 -30
- 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 +7 -8
- package/src/solautoPosition/solautoPositionEx.ts +21 -10
- 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 +105 -28
- 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
@@ -4,20 +4,16 @@ exports.rebalanceChoresBefore = rebalanceChoresBefore;
|
|
4
4
|
exports.getTransactionChores = getTransactionChores;
|
5
5
|
exports.convertReferralFeesToDestination = convertReferralFeesToDestination;
|
6
6
|
exports.getErrorInfo = getErrorInfo;
|
7
|
-
const umi_1 = require("@metaplex-foundation/umi");
|
8
|
-
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
9
7
|
const web3_js_1 = require("@solana/web3.js");
|
10
8
|
const spl_token_1 = require("@solana/spl-token");
|
9
|
+
const umi_1 = require("@metaplex-foundation/umi");
|
10
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
11
11
|
const generated_1 = require("../../generated");
|
12
|
-
const
|
13
|
-
const generalUtils_1 = require("../../utils/generalUtils");
|
14
|
-
const numberUtils_1 = require("../../utils/numberUtils");
|
15
|
-
const accountUtils_1 = require("../../utils/accountUtils");
|
12
|
+
const utils_1 = require("../../utils");
|
16
13
|
const marginfi_sdk_1 = require("../../marginfi-sdk");
|
17
|
-
const
|
14
|
+
const swap_1 = require("../swap");
|
18
15
|
const jupiter_sdk_1 = require("../../jupiter-sdk");
|
19
|
-
const
|
20
|
-
const transactions_1 = require("../../types/transactions");
|
16
|
+
const types_1 = require("../../types");
|
21
17
|
function getWSolUsage(client, solautoActions, initiatingDcaIn, cancellingDcaIn) {
|
22
18
|
const supplyIsWsol = client.pos.supplyMint().equals(spl_token_1.NATIVE_MINT);
|
23
19
|
const debtIsWsol = client.pos.debtMint().equals(spl_token_1.NATIVE_MINT);
|
@@ -57,7 +53,7 @@ async function transactionChoresBefore(client, accountsGettingCreated, solautoAc
|
|
57
53
|
}
|
58
54
|
if (client.selfManaged) {
|
59
55
|
if ((0, utils_1.isMarginfiClient)(client) &&
|
60
|
-
!(await (0,
|
56
|
+
!(await (0, utils_1.getSolanaAccountCreated)(client.umi, client.marginfiAccountPk))) {
|
61
57
|
chores = chores.add(client.marginfiAccountInitialize(client.marginfiAccount));
|
62
58
|
}
|
63
59
|
// TODO: PF
|
@@ -67,9 +63,9 @@ async function transactionChoresBefore(client, accountsGettingCreated, solautoAc
|
|
67
63
|
}
|
68
64
|
const wSolUsage = getWSolUsage(client, solautoActions, initiatingDcaIn, undefined);
|
69
65
|
if (wSolUsage !== undefined) {
|
70
|
-
if (await (0,
|
66
|
+
if (await (0, utils_1.getSolanaAccountCreated)(client.umi, wSolUsage.wSolTokenAccount)) {
|
71
67
|
client.log(`Closing signer wSol TA`);
|
72
|
-
chores = chores.add((0,
|
68
|
+
chores = chores.add((0, utils_1.closeTokenAccountUmiIx)(client.signer, wSolUsage.wSolTokenAccount, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey)));
|
73
69
|
}
|
74
70
|
let amountToTransfer = BigInt(0);
|
75
71
|
if (wSolUsage.solautoAction &&
|
@@ -88,10 +84,10 @@ async function transactionChoresBefore(client, accountsGettingCreated, solautoAc
|
|
88
84
|
const amount = amountToTransfer +
|
89
85
|
(await client.umi.rpc.getRent(spl_token_1.ACCOUNT_SIZE)).basisPoints;
|
90
86
|
client.log(`Transferring ${amount} lamports to signer wSol TA`);
|
91
|
-
chores = chores.add((0,
|
87
|
+
chores = chores.add((0, utils_1.systemTransferUmiIx)(client.signer, wSolUsage.wSolTokenAccount, amount));
|
92
88
|
}
|
93
89
|
client.log("Creating signer wSol TA");
|
94
|
-
chores = chores.add((0,
|
90
|
+
chores = chores.add((0, utils_1.createAssociatedTokenAccountUmiIx)(client.signer, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), spl_token_1.NATIVE_MINT));
|
95
91
|
accountsGettingCreated.push(wSolUsage.wSolTokenAccount.toString());
|
96
92
|
}
|
97
93
|
for (const solautoAction of solautoActions ?? []) {
|
@@ -105,8 +101,8 @@ async function transactionChoresBefore(client, accountsGettingCreated, solautoAc
|
|
105
101
|
if (accountsGettingCreated.includes(tokenAccount.toString())) {
|
106
102
|
continue;
|
107
103
|
}
|
108
|
-
if (!(0,
|
109
|
-
chores = chores.add((0,
|
104
|
+
if (!(0, utils_1.getSolanaAccountCreated)(client.umi, tokenAccount)) {
|
105
|
+
chores = chores.add((0, utils_1.createAssociatedTokenAccountUmiIx)(client.signer, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), (0, generated_1.isSolautoAction)("Withdraw", solautoAction)
|
110
106
|
? client.pos.supplyMint()
|
111
107
|
: client.pos.debtMint()));
|
112
108
|
accountsGettingCreated.push(tokenAccount.toString());
|
@@ -136,26 +132,26 @@ async function rebalanceChoresBefore(client, tx, accountsGettingCreated) {
|
|
136
132
|
];
|
137
133
|
const [referredBySupplyTa, referredByDebtTa, signerSupplyTa, signerDebtTa] = await client.umi.rpc.getAccounts(accountsNeeded.map((x) => (0, umi_1.publicKey)(x ?? web3_js_1.PublicKey.default)));
|
138
134
|
let chores = (0, umi_1.transactionBuilder)();
|
139
|
-
if (checkReferralSupplyTa && !(0,
|
135
|
+
if (checkReferralSupplyTa && !(0, utils_1.rpcAccountCreated)(referredBySupplyTa)) {
|
140
136
|
client.log("Creating referred-by supply TA");
|
141
|
-
chores = chores.add((0,
|
137
|
+
chores = chores.add((0, utils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.referredByState, client.pos.supplyMint()));
|
142
138
|
}
|
143
|
-
if (checkReferralDebtTa && !(0,
|
139
|
+
if (checkReferralDebtTa && !(0, utils_1.rpcAccountCreated)(referredByDebtTa)) {
|
144
140
|
client.log("Creating referred-by debt TA");
|
145
|
-
chores = chores.add((0,
|
141
|
+
chores = chores.add((0, utils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.referredByState, client.pos.debtMint()));
|
146
142
|
}
|
147
143
|
if (checkSignerSupplyTa &&
|
148
|
-
!(0,
|
144
|
+
!(0, utils_1.rpcAccountCreated)(signerSupplyTa) &&
|
149
145
|
!accountsGettingCreated.includes(signerSupplyTa.publicKey.toString())) {
|
150
146
|
client.log("Creating signer supply token account");
|
151
|
-
chores = chores.add((0,
|
147
|
+
chores = chores.add((0, utils_1.createAssociatedTokenAccountUmiIx)(client.signer, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), client.pos.supplyMint()));
|
152
148
|
accountsGettingCreated.push(signerSupplyTa.publicKey.toString());
|
153
149
|
}
|
154
150
|
if (checkSignerDebtTa &&
|
155
|
-
!(0,
|
151
|
+
!(0, utils_1.rpcAccountCreated)(signerDebtTa) &&
|
156
152
|
!accountsGettingCreated.includes(signerDebtTa.publicKey.toString())) {
|
157
153
|
client.log("Creating signer debt token account");
|
158
|
-
chores = chores.add((0,
|
154
|
+
chores = chores.add((0, utils_1.createAssociatedTokenAccountUmiIx)(client.signer, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), client.pos.debtMint()));
|
159
155
|
accountsGettingCreated.push(signerDebtTa.publicKey.toString());
|
160
156
|
}
|
161
157
|
return chores;
|
@@ -164,7 +160,7 @@ function transactionChoresAfter(client, solautoActions, cancellingDcaIn) {
|
|
164
160
|
let chores = (0, umi_1.transactionBuilder)();
|
165
161
|
const wSolUsage = getWSolUsage(client, solautoActions, undefined, cancellingDcaIn);
|
166
162
|
if (wSolUsage) {
|
167
|
-
chores = chores.add((0,
|
163
|
+
chores = chores.add((0, utils_1.closeTokenAccountUmiIx)(client.signer, wSolUsage.wSolTokenAccount, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey)));
|
168
164
|
}
|
169
165
|
return chores;
|
170
166
|
}
|
@@ -208,16 +204,16 @@ function getSolautoActions(umi, tx) {
|
|
208
204
|
}
|
209
205
|
catch { }
|
210
206
|
}
|
211
|
-
if (
|
207
|
+
if ((0, utils_1.isMarginfiProgram)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.programId))) {
|
212
208
|
try {
|
213
209
|
const serializer = (0, marginfi_sdk_1.getLendingAccountDepositInstructionDataSerializer)();
|
214
|
-
const discriminator = (0,
|
210
|
+
const discriminator = (0, utils_1.uint8ArrayToBigInt)(serializer
|
215
211
|
.serialize({
|
216
212
|
amount: 0,
|
217
213
|
})
|
218
214
|
.slice(0, 8));
|
219
215
|
const [data, _] = serializer.deserialize(x.data);
|
220
|
-
if ((0,
|
216
|
+
if ((0, utils_1.uint8ArrayToBigInt)(new Uint8Array(data.discriminator)) ===
|
221
217
|
discriminator) {
|
222
218
|
solautoActions?.push({
|
223
219
|
__kind: "Deposit",
|
@@ -228,13 +224,13 @@ function getSolautoActions(umi, tx) {
|
|
228
224
|
catch { }
|
229
225
|
try {
|
230
226
|
const serializer = (0, marginfi_sdk_1.getLendingAccountBorrowInstructionDataSerializer)();
|
231
|
-
const discriminator = (0,
|
227
|
+
const discriminator = (0, utils_1.uint8ArrayToBigInt)(serializer
|
232
228
|
.serialize({
|
233
229
|
amount: 0,
|
234
230
|
})
|
235
231
|
.slice(0, 8));
|
236
232
|
const [data, _] = serializer.deserialize(x.data);
|
237
|
-
if ((0,
|
233
|
+
if ((0, utils_1.uint8ArrayToBigInt)(new Uint8Array(data.discriminator)) ===
|
238
234
|
discriminator) {
|
239
235
|
solautoActions?.push({
|
240
236
|
__kind: "Borrow",
|
@@ -245,14 +241,14 @@ function getSolautoActions(umi, tx) {
|
|
245
241
|
catch { }
|
246
242
|
try {
|
247
243
|
const serializer = (0, marginfi_sdk_1.getLendingAccountWithdrawInstructionDataSerializer)();
|
248
|
-
const discriminator = (0,
|
244
|
+
const discriminator = (0, utils_1.uint8ArrayToBigInt)(serializer
|
249
245
|
.serialize({
|
250
246
|
amount: 0,
|
251
247
|
withdrawAll: false,
|
252
248
|
})
|
253
249
|
.slice(0, 8));
|
254
250
|
const [data, _] = serializer.deserialize(x.data);
|
255
|
-
if ((0,
|
251
|
+
if ((0, utils_1.uint8ArrayToBigInt)(new Uint8Array(data.discriminator)) ===
|
256
252
|
discriminator) {
|
257
253
|
solautoActions?.push({
|
258
254
|
__kind: "Withdraw",
|
@@ -272,14 +268,14 @@ function getSolautoActions(umi, tx) {
|
|
272
268
|
catch { }
|
273
269
|
try {
|
274
270
|
const serializer = (0, marginfi_sdk_1.getLendingAccountRepayInstructionDataSerializer)();
|
275
|
-
const discriminator = (0,
|
271
|
+
const discriminator = (0, utils_1.uint8ArrayToBigInt)(serializer
|
276
272
|
.serialize({
|
277
273
|
amount: 0,
|
278
274
|
repayAll: false,
|
279
275
|
})
|
280
276
|
.slice(0, 8));
|
281
277
|
const [data, _] = serializer.deserialize(x.data);
|
282
|
-
if ((0,
|
278
|
+
if ((0, utils_1.uint8ArrayToBigInt)(new Uint8Array(data.discriminator)) ===
|
283
279
|
discriminator) {
|
284
280
|
solautoActions?.push({
|
285
281
|
__kind: "Repay",
|
@@ -315,11 +311,11 @@ async function getTransactionChores(client, tx) {
|
|
315
311
|
return [choresBefore, choresAfter];
|
316
312
|
}
|
317
313
|
async function convertReferralFeesToDestination(referralManager, tokenAccount, destinationMint) {
|
318
|
-
const tokenAccountData = await (0,
|
314
|
+
const tokenAccountData = await (0, utils_1.getTokenAccountData)(referralManager.umi, tokenAccount);
|
319
315
|
if (!tokenAccountData || tokenAccountData.amount === BigInt(0)) {
|
320
316
|
return undefined;
|
321
317
|
}
|
322
|
-
const jupSwapManager = new
|
318
|
+
const jupSwapManager = new swap_1.JupSwapManager(referralManager.umi.identity);
|
323
319
|
const { lookupTableAddresses, setupIx, swapIx, cleanupIx } = await jupSwapManager.getJupSwapTxData({
|
324
320
|
amount: tokenAccountData.amount,
|
325
321
|
destinationWallet: referralManager.referralState,
|
@@ -332,7 +328,7 @@ async function convertReferralFeesToDestination(referralManager, tokenAccount, d
|
|
332
328
|
.add(setupIx)
|
333
329
|
.add((0, generated_1.convertReferralFees)(referralManager.umi, {
|
334
330
|
signer: referralManager.signer,
|
335
|
-
intermediaryTa: (0, umi_1.publicKey)((0,
|
331
|
+
intermediaryTa: (0, umi_1.publicKey)((0, utils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(referralManager.umi.identity.publicKey), tokenAccountData.mint)),
|
336
332
|
ixsSysvar: (0, umi_1.publicKey)(web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY),
|
337
333
|
referralState: (0, umi_1.publicKey)(referralManager.referralState),
|
338
334
|
referralFeesTa: (0, umi_1.publicKey)(tokenAccount),
|
@@ -350,7 +346,7 @@ function getErrorInfo(umi, txs, error, simulationSuccessful) {
|
|
350
346
|
let errName;
|
351
347
|
const computeIxs = simulationSuccessful ? 2 : 1; // sub ixs to account for computeUnitLimit and computeUnitPrice that get added
|
352
348
|
try {
|
353
|
-
if (error instanceof
|
349
|
+
if (error instanceof types_1.BundleSimulationError) {
|
354
350
|
errTxIdx = error.details.transactionIdx;
|
355
351
|
errIxIdx = error.details.instructionIdx - computeIxs;
|
356
352
|
errCode = error.details.errorCode;
|
@@ -365,7 +361,7 @@ function getErrorInfo(umi, txs, error, simulationSuccessful) {
|
|
365
361
|
: undefined;
|
366
362
|
errName = errCode === undefined ? err[1] : undefined;
|
367
363
|
}
|
368
|
-
(0,
|
364
|
+
(0, utils_1.consoleLog)("Transaction instructions:", txs.map((x) => x
|
369
365
|
.getInstructions()
|
370
366
|
.map((y) => y.programId.toString())
|
371
367
|
.join(",")));
|
@@ -374,10 +370,10 @@ function getErrorInfo(umi, txs, error, simulationSuccessful) {
|
|
374
370
|
const errIx = errTxIdx !== undefined && errIxIdx !== undefined
|
375
371
|
? txs[errTxIdx].getInstructions()[Math.max(0, errIxIdx)]
|
376
372
|
: undefined;
|
377
|
-
(0,
|
378
|
-
(0,
|
379
|
-
(0,
|
380
|
-
(0,
|
373
|
+
(0, utils_1.consoleLog)("Error transaction index:", errTxIdx);
|
374
|
+
(0, utils_1.consoleLog)("Error instruction index:", errIxIdx);
|
375
|
+
(0, utils_1.consoleLog)("Error code:", errCode);
|
376
|
+
(0, utils_1.consoleLog)("Error instruction program:", errIx?.programId.toString());
|
381
377
|
const solautoError = (0, generated_1.getSolautoErrorFromCode)(errCode ?? -1, (0, generated_1.createSolautoProgram)());
|
382
378
|
const marginfiError = (0, marginfi_sdk_1.getMarginfiErrorFromCode)(errCode ?? -1, (0, marginfi_sdk_1.createMarginfiProgram)());
|
383
379
|
if (errCode !== undefined &&
|
@@ -391,7 +387,8 @@ function getErrorInfo(umi, txs, error, simulationSuccessful) {
|
|
391
387
|
}
|
392
388
|
}
|
393
389
|
else if (errCode !== undefined &&
|
394
|
-
errIx
|
390
|
+
errIx &&
|
391
|
+
(0, utils_1.isMarginfiProgram)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(errIx.programId))) {
|
395
392
|
programName = "Marginfi";
|
396
393
|
programError = marginfiError;
|
397
394
|
}
|
@@ -410,13 +407,13 @@ function getErrorInfo(umi, txs, error, simulationSuccessful) {
|
|
410
407
|
}
|
411
408
|
}
|
412
409
|
catch (e) {
|
413
|
-
(0,
|
410
|
+
(0, utils_1.consoleLog)(e);
|
414
411
|
}
|
415
412
|
const errData = {
|
416
413
|
errorName,
|
417
414
|
errorInfo,
|
418
415
|
canBeIgnored,
|
419
416
|
};
|
420
|
-
(0,
|
417
|
+
(0, utils_1.consoleLog)(errData);
|
421
418
|
return errData;
|
422
419
|
}
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import { TransactionBuilder } from "@metaplex-foundation/umi";
|
2
|
-
import { SolautoClient } from "../solauto/solautoClient";
|
3
|
-
import { ErrorsToThrow } from "../../utils/generalUtils";
|
4
2
|
import { PriorityFeeSetting, TransactionItemInputs, TransactionRunType } from "../../types";
|
5
|
-
import {
|
3
|
+
import { ErrorsToThrow } from "../../utils";
|
4
|
+
import { SolautoClient, ReferralStateManager } from "../solauto";
|
6
5
|
export declare class TransactionTooLargeError extends Error {
|
7
6
|
constructor(message: string);
|
8
7
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/transactionsManager.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/transactionsManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAElB,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAMrB,OAAO,EAEL,aAAa,EAQd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAM5E,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAqCD,qBAAa,eAAe;IAOjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM;IATtB,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACxB,WAAW,EAAE,OAAO,CAAS;IAC7B,SAAS,EAAE,MAAM,CAAK;gBAGb,OAAO,EAAE,CACd,UAAU,EAA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AC/D,UAAU,GAAE,OAAc,EAC1B,aAAa,CAAC,EAAE,aAAa,YAAA,EACrC,WAAW,CAAC,EAAE,WAAW;YAab,uBAAuB;IA0CrC,OAAO,CAAC,YAAY;YA6CN,aAAa;IAoB3B,OAAO,CAAC,4BAA4B;IAgBpC,OAAO,CAAC,mBAAmB;YAoBb,SAAS;IAmBV,UAAU,CACrB,YAAY,EAAE,eAAe,EAAE,GAC9B,OAAO,CAAC,0BAA0B,CAAC;IA4GzB,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;YA8BxB,6BAA6B;YA4I7B,qBAAqB;YAgDrB,eAAe;YA0Df,eAAe;CA4D9B"}
|
@@ -5,16 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.TransactionsManager = exports.TransactionStatus = exports.TransactionItem = exports.TransactionTooLargeError = void 0;
|
7
7
|
const bs58_1 = __importDefault(require("bs58"));
|
8
|
+
const web3_js_1 = require("@solana/web3.js");
|
8
9
|
const umi_1 = require("@metaplex-foundation/umi");
|
9
|
-
const solanaUtils_1 = require("../../utils/solanaUtils");
|
10
|
-
const generalUtils_1 = require("../../utils/generalUtils");
|
11
|
-
const transactionUtils_1 = require("./transactionUtils");
|
12
10
|
const types_1 = require("../../types");
|
13
|
-
const web3_js_1 = require("@solana/web3.js");
|
14
|
-
const switchboardConstants_1 = require("../../constants/switchboardConstants");
|
15
|
-
const utils_1 = require("../../utils");
|
16
|
-
const jitoUtils_1 = require("../../utils/jitoUtils");
|
17
11
|
const constants_1 = require("../../constants");
|
12
|
+
const utils_1 = require("../../utils");
|
13
|
+
const transactionUtils_1 = require("./transactionUtils");
|
18
14
|
const CHORES_TX_NAME = "account chores";
|
19
15
|
const MAX_SUPPORTED_ACCOUNT_LOCKS = 64;
|
20
16
|
class TransactionTooLargeError extends Error {
|
@@ -36,7 +32,7 @@ class LookupTables {
|
|
36
32
|
const currentCacheAddresses = this.cache.map((x) => x.publicKey.toString());
|
37
33
|
const missingAddresses = addresses.filter((x) => !currentCacheAddresses.includes(x));
|
38
34
|
if (missingAddresses) {
|
39
|
-
const additionalInputs = await (0,
|
35
|
+
const additionalInputs = await (0, utils_1.getAddressLookupInputs)(this.umi, missingAddresses);
|
40
36
|
this.cache.push(...additionalInputs);
|
41
37
|
}
|
42
38
|
return this.cache;
|
@@ -95,7 +91,7 @@ class TransactionSet {
|
|
95
91
|
return false;
|
96
92
|
}
|
97
93
|
const singleTx = await this.getSingleTransaction();
|
98
|
-
const tx = (0,
|
94
|
+
const tx = (0, utils_1.addTxOptimizations)(this.txHandler.umi.identity, singleTx, 1, 1)
|
99
95
|
.add(item.tx)
|
100
96
|
.setAddressLookupTables(await this.lookupTables.getLutInputs([
|
101
97
|
...this.lutAddresses(),
|
@@ -152,7 +148,7 @@ var TransactionStatus;
|
|
152
148
|
TransactionStatus["Failed"] = "Failed";
|
153
149
|
})(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
|
154
150
|
class TransactionsManager {
|
155
|
-
constructor(txHandler, statusCallback, txType, priorityFeeSetting = types_1.PriorityFeeSetting.Min, atomically =
|
151
|
+
constructor(txHandler, statusCallback, txType, priorityFeeSetting = types_1.PriorityFeeSetting.Min, atomically = true, errorsToThrow, retryConfig) {
|
156
152
|
this.txHandler = txHandler;
|
157
153
|
this.statusCallback = statusCallback;
|
158
154
|
this.txType = txType;
|
@@ -163,7 +159,7 @@ class TransactionsManager {
|
|
163
159
|
this.updateOracleTxName = "update oracle";
|
164
160
|
this.lookupTables = new LookupTables(this.txHandler.defaultLookupTables(), this.txHandler.umi);
|
165
161
|
this.signableRetries =
|
166
|
-
retryConfig?.signableRetries ?? retryConfig?.totalRetries ??
|
162
|
+
retryConfig?.signableRetries ?? retryConfig?.totalRetries ?? 4;
|
167
163
|
this.totalRetries =
|
168
164
|
retryConfig?.totalRetries ?? retryConfig?.signableRetries ?? 4;
|
169
165
|
this.retryDelay = retryConfig?.retryDelay ?? 150;
|
@@ -267,7 +263,7 @@ class TransactionsManager {
|
|
267
263
|
async updateLut(tx, newLut) {
|
268
264
|
const lutInputs = await this.lookupTables.getLutInputs();
|
269
265
|
const updateLutTxName = `${newLut ? "create" : "update"} lookup table`;
|
270
|
-
await (0,
|
266
|
+
await (0, utils_1.retryWithExponentialBackoff)(async (attemptNum, prevError) => await this.sendTransaction(tx.setAddressLookupTables(lutInputs), updateLutTxName, attemptNum, this.getUpdatedPriorityFeeSetting(prevError, attemptNum), "skip-simulation"), this.signableRetries, 150, this.errorsToThrow);
|
271
267
|
await this.txHandler.refetchReferralState();
|
272
268
|
}
|
273
269
|
async clientSend(transactions) {
|
@@ -293,11 +289,11 @@ class TransactionsManager {
|
|
293
289
|
return ix.keys.map((key) => key.pubkey.toString());
|
294
290
|
}) ?? []);
|
295
291
|
});
|
296
|
-
const swbOracle = allAccounts.find((x) => Object.values(
|
292
|
+
const swbOracle = allAccounts.find((x) => Object.values(constants_1.SWITCHBOARD_PRICE_FEED_IDS)
|
297
293
|
.map((x) => x.feedId)
|
298
294
|
.includes(x ?? ""));
|
299
295
|
if (swbOracle) {
|
300
|
-
const mint = new web3_js_1.PublicKey(Object.keys(
|
296
|
+
const mint = new web3_js_1.PublicKey(Object.keys(constants_1.SWITCHBOARD_PRICE_FEED_IDS).find((x) => constants_1.SWITCHBOARD_PRICE_FEED_IDS[x].feedId === swbOracle));
|
301
297
|
const stale = (await (0, utils_1.getSwitchboardFeedData)(client.connection, [mint]))[0]
|
302
298
|
.stale;
|
303
299
|
if (stale) {
|
@@ -337,7 +333,7 @@ class TransactionsManager {
|
|
337
333
|
async send(items) {
|
338
334
|
this.statuses = [];
|
339
335
|
this.lookupTables.reset();
|
340
|
-
const itemSets = await (0,
|
336
|
+
const itemSets = await (0, utils_1.retryWithExponentialBackoff)(async () => {
|
341
337
|
for (const item of items) {
|
342
338
|
if (!item.initialized) {
|
343
339
|
await item.initialize();
|
@@ -363,7 +359,7 @@ class TransactionsManager {
|
|
363
359
|
async processTransactionsAtomically(itemSets) {
|
364
360
|
let num = 0;
|
365
361
|
let transactions = [];
|
366
|
-
await (0,
|
362
|
+
await (0, utils_1.retryWithExponentialBackoff)(async (attemptNum, prevError) => {
|
367
363
|
if (prevError &&
|
368
364
|
this.statuses.filter((x) => x.simulationSuccessful).length >
|
369
365
|
this.signableRetries) {
|
@@ -395,7 +391,7 @@ class TransactionsManager {
|
|
395
391
|
let txSigs;
|
396
392
|
let error;
|
397
393
|
try {
|
398
|
-
txSigs = await (0,
|
394
|
+
txSigs = await (0, utils_1.sendJitoBundledTransactions)(this.txHandler.umi, this.txHandler.connection, this.txHandler.signer, this.txHandler.otherSigners, transactions, this.txType, this.getUpdatedPriorityFeeSetting(prevError, attemptNum), () => this.updateStatusForSets(itemSets, TransactionStatus.Processing, attemptNum, undefined, true));
|
399
395
|
}
|
400
396
|
catch (e) {
|
401
397
|
error = e;
|
@@ -424,7 +420,7 @@ class TransactionsManager {
|
|
424
420
|
}
|
425
421
|
async processTransactionSet(itemSets, currentIndex) {
|
426
422
|
let itemSet = itemSets[currentIndex];
|
427
|
-
await (0,
|
423
|
+
await (0, utils_1.retryWithExponentialBackoff)(async (attemptNum, prevError) => {
|
428
424
|
if (prevError &&
|
429
425
|
this.statuses.filter((x) => x.simulationSuccessful).length >
|
430
426
|
this.signableRetries) {
|
@@ -465,7 +461,7 @@ class TransactionsManager {
|
|
465
461
|
const newItemSetNames = newItemSets.map((x) => x.name());
|
466
462
|
if (newItemSetNames.length === 1 &&
|
467
463
|
newItemSetNames[0] === this.updateOracleTxName) {
|
468
|
-
(0,
|
464
|
+
(0, utils_1.consoleLog)("Skipping unnecessary oracle update");
|
469
465
|
return undefined;
|
470
466
|
}
|
471
467
|
if (currentIndex !== undefined && newItemSets.length > 1) {
|
@@ -482,7 +478,7 @@ class TransactionsManager {
|
|
482
478
|
async sendTransaction(tx, txName, attemptNum, priorityFeeSetting, txType) {
|
483
479
|
this.updateStatus(txName, TransactionStatus.Processing, attemptNum);
|
484
480
|
try {
|
485
|
-
const txSig = await (0,
|
481
|
+
const txSig = await (0, utils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx, txType ?? this.txType, priorityFeeSetting, () => this.updateStatus(txName, TransactionStatus.Processing, attemptNum, undefined, true));
|
486
482
|
this.updateStatus(txName, TransactionStatus.Successful, attemptNum, txSig ? bs58_1.default.encode(txSig) : undefined);
|
487
483
|
}
|
488
484
|
catch (e) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"marginfiSolautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/marginfiSolautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAiB5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,qBAAa,yBAA0B,SAAQ,iBAAiB;IAC9D,OAAO,CAAC,mBAAmB,CAAgC;IAC3D,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,QAAQ,CAAqB;IAExB,WAAW,IAAI,OAAO,CAAC,SAAS,CAAC;IAyBxC,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAuB3D,wBAAwB,IAAI,MAAM;IAO5B,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;CA0B5C"}
|
@@ -2,12 +2,12 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.MarginfiSolautoPositionEx = void 0;
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
5
|
-
const solautoPositionEx_1 = require("./solautoPositionEx");
|
6
5
|
const marginfi_sdk_1 = require("../marginfi-sdk");
|
7
6
|
const umi_1 = require("@metaplex-foundation/umi");
|
8
7
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
9
8
|
const utils_1 = require("../utils");
|
10
9
|
const constants_1 = require("../constants");
|
10
|
+
const solautoPositionEx_1 = require("./solautoPositionEx");
|
11
11
|
class MarginfiSolautoPositionEx extends solautoPositionEx_1.SolautoPositionEx {
|
12
12
|
constructor() {
|
13
13
|
super(...arguments);
|
@@ -26,15 +26,16 @@ class MarginfiSolautoPositionEx extends solautoPositionEx_1.SolautoPositionEx {
|
|
26
26
|
this.lp = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.marginfiAccountData.group);
|
27
27
|
}
|
28
28
|
if (!this.lp) {
|
29
|
-
this.lp =
|
29
|
+
this.lp = (0, constants_1.getMarginfiAccounts)(this.lpEnv).defaultGroup;
|
30
30
|
}
|
31
31
|
return this.lp;
|
32
32
|
}
|
33
33
|
async maxLtvAndLiqThresholdBps() {
|
34
34
|
if (!this.supplyBank || !this.debtBank) {
|
35
35
|
const group = (await this.lendingPool()).toString();
|
36
|
-
const
|
37
|
-
const
|
36
|
+
const bankAccounts = (0, constants_1.getMarginfiAccounts)(this.lpEnv).bankAccounts;
|
37
|
+
const supplyBank = bankAccounts[group][this.supplyMint().toString()].bank;
|
38
|
+
const debtBank = bankAccounts[group][this.debtMint().toString()].bank;
|
38
39
|
[this.supplyBank, this.debtBank] = await (0, marginfi_sdk_1.safeFetchAllBank)(this.umi, [
|
39
40
|
(0, umi_1.publicKey)(supplyBank),
|
40
41
|
(0, umi_1.publicKey)(debtBank),
|
@@ -56,7 +57,7 @@ class MarginfiSolautoPositionEx extends solautoPositionEx_1.SolautoPositionEx {
|
|
56
57
|
? { mint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.state().supply.mint) }
|
57
58
|
: undefined, useDesignatedMint
|
58
59
|
? { mint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.state().debt.mint) }
|
59
|
-
: undefined, this.contextUpdates);
|
60
|
+
: undefined, this.lpEnv, this.contextUpdates);
|
60
61
|
if (resp) {
|
61
62
|
this.supplyBank = resp.supplyBank;
|
62
63
|
this.debtBank = resp.debtBank;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import { DCASettings, LendingPlatform, PositionState, SolautoPosition, SolautoSettingsParameters } from "../generated";
|
3
2
|
import { Umi } from "@metaplex-foundation/umi";
|
3
|
+
import { DCASettings, LendingPlatform, PositionState, SolautoPosition, SolautoSettingsParameters } from "../generated";
|
4
4
|
import { ContextUpdates } from "../utils";
|
5
|
-
import { RebalanceAction } from "../types";
|
5
|
+
import { ProgramEnv, RebalanceAction } from "../types";
|
6
6
|
import { TokenInfo } from "../constants";
|
7
7
|
export interface PositionCustomArgs {
|
8
8
|
lendingPlatform: LendingPlatform;
|
@@ -10,6 +10,7 @@ export interface PositionCustomArgs {
|
|
10
10
|
debtMint?: PublicKey;
|
11
11
|
lendingPool?: PublicKey;
|
12
12
|
lpUserAccount?: PublicKey;
|
13
|
+
lpEnv?: ProgramEnv;
|
13
14
|
}
|
14
15
|
interface SolautoPositionExData extends Partial<SolautoPosition> {
|
15
16
|
state: PositionState;
|
@@ -26,6 +27,7 @@ export declare abstract class SolautoPositionEx {
|
|
26
27
|
publicKey: PublicKey;
|
27
28
|
protected _data: SolautoPositionExData;
|
28
29
|
protected lp?: PublicKey;
|
30
|
+
protected lpEnv: ProgramEnv;
|
29
31
|
lpUserAccount?: PublicKey;
|
30
32
|
protected contextUpdates?: ContextUpdates;
|
31
33
|
private readonly firstState;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoPositionEx.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/solautoPositionEx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,WAA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C,WAAW,CAAC,EAAE,MAAM;IAUnC,wBAAwB;IAQlB,sBAAsB,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;IAiBrE,iBAAiB,CACf,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM;IAkBhC,mBAAmB;CAM1B"}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.SolautoPositionEx = void 0;
|
4
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
4
5
|
const generated_1 = require("../generated");
|
5
6
|
const utils_1 = require("../utils");
|
6
7
|
const rebalance_1 = require("../services/rebalance");
|
7
8
|
const constants_1 = require("../constants");
|
8
|
-
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
9
9
|
class SolautoPositionEx {
|
10
10
|
constructor(args) {
|
11
11
|
this.lp = undefined;
|
@@ -19,6 +19,7 @@ class SolautoPositionEx {
|
|
19
19
|
(args.data.position
|
20
20
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(args.data.position.protocolUserAccount)
|
21
21
|
: undefined);
|
22
|
+
this.lpEnv = args.customArgs?.lpEnv ?? "Prod";
|
22
23
|
this._data = args.data;
|
23
24
|
this.firstState = { ...args.data.state };
|
24
25
|
}
|
@@ -82,13 +83,19 @@ class SolautoPositionEx {
|
|
82
83
|
return (0, utils_1.calcTotalSupply)(this.state());
|
83
84
|
}
|
84
85
|
supplyUsd() {
|
85
|
-
|
86
|
+
const supplyPrice = (0, utils_1.safeGetPrice)(this.supplyMint());
|
87
|
+
return supplyPrice
|
88
|
+
? (0, utils_1.calcTotalSupply)(this.state()) * supplyPrice
|
89
|
+
: (0, utils_1.calcSupplyUsd)(this.state());
|
86
90
|
}
|
87
91
|
totalDebt() {
|
88
92
|
return (0, utils_1.calcTotalDebt)(this.state());
|
89
93
|
}
|
90
94
|
debtUsd() {
|
91
|
-
|
95
|
+
const debtPrice = (0, utils_1.safeGetPrice)(this.debtMint());
|
96
|
+
return debtPrice
|
97
|
+
? (0, utils_1.calcTotalDebt)(this.state()) * debtPrice
|
98
|
+
: (0, utils_1.calcDebtUsd)(this.state());
|
92
99
|
}
|
93
100
|
supplyLiquidityDepositable() {
|
94
101
|
return (0, utils_1.supplyLiquidityDepositable)(this.state());
|
@@ -97,7 +104,7 @@ class SolautoPositionEx {
|
|
97
104
|
return (0, utils_1.supplyLiquidityUsdDepositable)(this.state());
|
98
105
|
}
|
99
106
|
supplyLiquidityUsdAvailable() {
|
100
|
-
return this.supplyLiquidityAvailable() * ((0, utils_1.safeGetPrice)(this.supplyMint()) ?? 0);
|
107
|
+
return (this.supplyLiquidityAvailable() * ((0, utils_1.safeGetPrice)(this.supplyMint()) ?? 0));
|
101
108
|
}
|
102
109
|
debtLiquidityAvailable() {
|
103
110
|
return (0, utils_1.debtLiquidityAvailable)(this.state());
|
@@ -121,7 +128,7 @@ class SolautoPositionEx {
|
|
121
128
|
return true;
|
122
129
|
}
|
123
130
|
eligibleForRebalance(bpsDistanceThreshold = 0) {
|
124
|
-
if (!this.settings() || !
|
131
|
+
if (!this.settings() || !this.supplyUsd()) {
|
125
132
|
return undefined;
|
126
133
|
}
|
127
134
|
if (this.state().liqUtilizationRateBps - this.boostFromBps() <=
|
@@ -1,8 +1,8 @@
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
1
2
|
import { Umi } from "@metaplex-foundation/umi";
|
2
3
|
import { PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs } from "../generated";
|
3
|
-
import { PublicKey } from "@solana/web3.js";
|
4
|
-
import { PositionCustomArgs, SolautoPositionEx } from "./solautoPositionEx";
|
5
4
|
import { ContextUpdates } from "../utils";
|
5
|
+
import { PositionCustomArgs, SolautoPositionEx } from "./solautoPositionEx";
|
6
6
|
export declare function createSolautoSettings(settings: SolautoSettingsParametersInpArgs): SolautoSettingsParameters;
|
7
7
|
export declare function getPositionExBulk(umi: Umi, publicKeys: PublicKey[]): Promise<SolautoPositionEx[]>;
|
8
8
|
export declare function getOrCreatePositionEx(umi: Umi, publicKey: PublicKey, customArgs?: PositionCustomArgs, contextUpdates?: ContextUpdates): Promise<SolautoPositionEx>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAK/C,OAAO,EAEL,aAAa,EAGb,yBAAyB,EACzB,gCAAgC,EACjC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EAQf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAG5E,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,gCAAgC,GACzC,yBAAyB,CAQ3B;AAED,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,SAAS,EAAE,GACtB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CA4B9B;AAED,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,EACpB,UAAU,CAAC,EAAE,kBAAkB,EAC/B,cAAc,CAAC,EAAE,cAAc,GAC9B,OAAO,CAAC,iBAAiB,CAAC,CAgC5B;AAED,UAAU,UAAU;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,GACtB,aAAa,CAgEf"}
|
@@ -4,11 +4,11 @@ exports.createSolautoSettings = createSolautoSettings;
|
|
4
4
|
exports.getPositionExBulk = getPositionExBulk;
|
5
5
|
exports.getOrCreatePositionEx = getOrCreatePositionEx;
|
6
6
|
exports.createFakePositionState = createFakePositionState;
|
7
|
-
const generated_1 = require("../generated");
|
8
7
|
const web3_js_1 = require("@solana/web3.js");
|
9
8
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
10
|
-
const
|
9
|
+
const generated_1 = require("../generated");
|
11
10
|
const utils_1 = require("../utils");
|
11
|
+
const marginfiSolautoPositionEx_1 = require("./marginfiSolautoPositionEx");
|
12
12
|
function createSolautoSettings(settings) {
|
13
13
|
return {
|
14
14
|
boostGap: settings.boostGap,
|
package/dist/types/solauto.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,YAAY,CAA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