@haven-fi/solauto-sdk 1.0.44 → 1.0.46
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +1 -2
- package/dist/clients/solautoMarginfiClient.js +1 -1
- package/dist/constants/solautoConstants.d.ts +1 -0
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +2 -1
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +2 -2
- package/dist/utils/solanaUtils.js +21 -4
- package/dist/utils/solauto/rebalanceUtils.js +1 -1
- package/local/createSolautoManagerAccount.ts +47 -0
- package/local/updateMarginfiLUT.ts +3 -3
- package/local/updateSolautoLUT.ts +14 -7
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +2 -3
- package/src/clients/solautoMarginfiClient.ts +1 -1
- package/src/constants/solautoConstants.ts +2 -0
- package/src/transactions/transactionUtils.ts +2 -4
- package/src/utils/solanaUtils.ts +21 -21
- package/src/utils/solauto/rebalanceUtils.ts +1 -1
- package/tests/transactions/solautoMarginfi.ts +9 -7
- package/tests/unit/lookupTables.ts +0 -4
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAEL,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAQJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EASvB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,cAAc,EAAE,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BAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAYlE"}
|
@@ -77,7 +77,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
77
77
|
return [
|
78
78
|
...super.lutAccountsToAdd(),
|
79
79
|
this.marginfiAccountPk,
|
80
|
-
this.intermediaryMarginfiAccountPk,
|
80
|
+
...(this.signer.publicKey.toString() === this.authority.toString() ? [this.intermediaryMarginfiAccountPk] : []),
|
81
81
|
];
|
82
82
|
}
|
83
83
|
marginfiAccountInitialize() {
|
@@ -8,6 +8,7 @@ export declare const PRICES: {
|
|
8
8
|
time: number;
|
9
9
|
};
|
10
10
|
};
|
11
|
+
export declare const SOLAUTO_LUT = "9D4xwZwDf46n9ft5gQxZzq3rBbdRXsXojKQLZbBdskPY";
|
11
12
|
export declare const JUPITER_PROGRAM_ID = "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";
|
12
13
|
export declare const STANDARD_LUT_ACCOUNTS: string[];
|
13
14
|
//# sourceMappingURL=solautoConstants.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAC9C,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAQrC,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;KAAE,CAAA;CAAO,CAAC;AAE9E,eAAO,MAAM,kBAAkB,gDAAgD,CAAC;AAEhF,eAAO,MAAM,qBAAqB,UAWjC,CAAC"}
|
1
|
+
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,yBAAyB,OAAO,CAAC;AAC9C,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAQrC,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;KAAE,CAAA;CAAO,CAAC;AAE9E,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAE1E,eAAO,MAAM,kBAAkB,gDAAgD,CAAC;AAEhF,eAAO,MAAM,qBAAqB,UAWjC,CAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.STANDARD_LUT_ACCOUNTS = exports.JUPITER_PROGRAM_ID = exports.PRICES = exports.MAX_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.DEFAULT_LIMIT_GAP_BPS = exports.DEFAULT_RISK_AVERSION_BPS = void 0;
|
3
|
+
exports.STANDARD_LUT_ACCOUNTS = exports.JUPITER_PROGRAM_ID = exports.SOLAUTO_LUT = exports.PRICES = exports.MAX_REPAY_GAP_BPS = exports.MIN_POSITION_STATE_FRESHNESS_SECS = exports.DEFAULT_LIMIT_GAP_BPS = exports.DEFAULT_RISK_AVERSION_BPS = void 0;
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
5
5
|
const spl_token_1 = require("@solana/spl-token");
|
6
6
|
// import { JitoRpcConnection } from "jito-ts";
|
@@ -16,6 +16,7 @@ exports.MAX_REPAY_GAP_BPS = 100;
|
|
16
16
|
// "finalized"
|
17
17
|
// );
|
18
18
|
exports.PRICES = {};
|
19
|
+
exports.SOLAUTO_LUT = "9D4xwZwDf46n9ft5gQxZzq3rBbdRXsXojKQLZbBdskPY";
|
19
20
|
exports.JUPITER_PROGRAM_ID = "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";
|
20
21
|
exports.STANDARD_LUT_ACCOUNTS = [
|
21
22
|
web3_js_1.PublicKey.default.toString(),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA8G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA4BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CACN;IACE,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACD,SAAS,CACZ,CAgHA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,eAAe,GAC5B,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CA8BzC"}
|
@@ -120,8 +120,8 @@ async function rebalanceChoresBefore(client, tx, accountsGettingCreated) {
|
|
120
120
|
const checkSolautoFeesTa = usesAccount(client.solautoFeesSupplyTa);
|
121
121
|
const checkIntermediaryMfiAccount = client.lendingPlatform === generated_1.LendingPlatform.Marginfi &&
|
122
122
|
usesAccount(client.intermediaryMarginfiAccountPk);
|
123
|
-
const checkSignerSupplyTa =
|
124
|
-
const checkSignerDebtTa =
|
123
|
+
const checkSignerSupplyTa = usesAccount(client.signerSupplyTa);
|
124
|
+
const checkSignerDebtTa = usesAccount(client.signerDebtTa);
|
125
125
|
const accountsNeeded = [
|
126
126
|
...[checkReferralSupplyTa ? client.referredBySupplyTa : web3_js_1.PublicKey.default],
|
127
127
|
...[checkSolautoFeesTa ? client.solautoFeesSupplyTa : web3_js_1.PublicKey.default],
|
@@ -159,11 +159,28 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, simulateOnly,
|
|
159
159
|
console.log("Serialized transaction size: ", tx.getTransactionSize(umi));
|
160
160
|
const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, attemptNum);
|
161
161
|
console.log("Compute unit price: ", feeEstimate);
|
162
|
-
const simulationResult = await
|
163
|
-
|
164
|
-
|
162
|
+
// const simulationResult = await retryWithExponentialBackoff(
|
163
|
+
// async () =>
|
164
|
+
// await simulateTransaction(
|
165
|
+
// connection,
|
166
|
+
// toWeb3JsTransaction(
|
167
|
+
// await (
|
168
|
+
// await assembleFinalTransaction(
|
169
|
+
// umi.identity,
|
170
|
+
// tx,
|
171
|
+
// feeEstimate,
|
172
|
+
// 1_400_000
|
173
|
+
// ).setLatestBlockhash(umi)
|
174
|
+
// ).build(umi)
|
175
|
+
// )
|
176
|
+
// )
|
177
|
+
// );
|
178
|
+
// const computeUnitLimit = Math.round(
|
179
|
+
// simulationResult.value.unitsConsumed! * 1.1
|
180
|
+
// );
|
181
|
+
// console.log("Compute unit limit: ", computeUnitLimit);
|
165
182
|
if (!simulateOnly) {
|
166
|
-
const result = await assembleFinalTransaction(umi.identity, tx, feeEstimate,
|
183
|
+
const result = await assembleFinalTransaction(umi.identity, tx, feeEstimate, 800000).sendAndConfirm(umi, {
|
167
184
|
send: {
|
168
185
|
skipPreflight: true,
|
169
186
|
commitment: "finalized",
|
@@ -187,7 +187,7 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
187
187
|
outputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint),
|
188
188
|
destinationWallet: client.solautoPosition,
|
189
189
|
// slippageBpsIncFactor: (!values.increasingLeverage ? 0.1 : 0) + ((attemptNum ?? 0) * 0.15),
|
190
|
-
slippageBpsIncFactor: (attemptNum ?? 0) * 0.
|
190
|
+
slippageBpsIncFactor: (attemptNum ?? 0) * 0.2,
|
191
191
|
amount: rebalancingToZero
|
192
192
|
? client.solautoPositionState.debt.amountUsed.baseUnit +
|
193
193
|
BigInt(Math.round(Number(client.solautoPositionState.debt.amountUsed.baseUnit) *
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import {
|
2
|
+
createSignerFromKeypair,
|
3
|
+
publicKey,
|
4
|
+
signerIdentity,
|
5
|
+
transactionBuilder,
|
6
|
+
} from "@metaplex-foundation/umi";
|
7
|
+
import {
|
8
|
+
getSolanaRpcConnection,
|
9
|
+
sendSingleOptimizedTransaction,
|
10
|
+
} from "../src/utils/solanaUtils";
|
11
|
+
import { marginfiAccountInitialize } from "../src/marginfi-sdk";
|
12
|
+
import { DEFAULT_MARGINFI_GROUP } from "../src/constants";
|
13
|
+
import { getSecretKey } from "./shared";
|
14
|
+
import { updateSolautoLut } from "./updateSolautoLUT";
|
15
|
+
|
16
|
+
async function create() {
|
17
|
+
let [connection, umi] = getSolanaRpcConnection(process.env.HELIUS_API_KEY!);
|
18
|
+
|
19
|
+
const secretKey = getSecretKey("solauto-manager");
|
20
|
+
const signerKeypair = umi.eddsa.createKeypairFromSecretKey(secretKey);
|
21
|
+
const signer = createSignerFromKeypair(umi, signerKeypair);
|
22
|
+
|
23
|
+
umi = umi.use(signerIdentity(signer));
|
24
|
+
|
25
|
+
const marginfiAccount = createSignerFromKeypair(
|
26
|
+
umi,
|
27
|
+
umi.eddsa.generateKeypair()
|
28
|
+
);
|
29
|
+
console.log(marginfiAccount.publicKey);
|
30
|
+
|
31
|
+
const tx = marginfiAccountInitialize(umi, {
|
32
|
+
marginfiAccount,
|
33
|
+
marginfiGroup: publicKey(DEFAULT_MARGINFI_GROUP),
|
34
|
+
authority: signer,
|
35
|
+
feePayer: signer,
|
36
|
+
});
|
37
|
+
|
38
|
+
await sendSingleOptimizedTransaction(
|
39
|
+
umi,
|
40
|
+
connection,
|
41
|
+
transactionBuilder().add(tx)
|
42
|
+
);
|
43
|
+
|
44
|
+
await updateSolautoLut([marginfiAccount.publicKey.toString()]);
|
45
|
+
}
|
46
|
+
|
47
|
+
create();
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import { MARGINFI_ACCOUNTS_LOOKUP_TABLE } from "../constants/marginfiAccounts";
|
2
|
+
import { MARGINFI_ACCOUNTS_LOOKUP_TABLE } from "../src/constants/marginfiAccounts";
|
3
3
|
import {
|
4
4
|
MARGINFI_ACCOUNTS,
|
5
5
|
DEFAULT_MARGINFI_GROUP,
|
6
|
-
} from "../constants/marginfiAccounts";
|
7
|
-
import { MARGINFI_PROGRAM_ID } from "../marginfi-sdk";
|
6
|
+
} from "../src/constants/marginfiAccounts";
|
7
|
+
import { MARGINFI_PROGRAM_ID } from "../src/marginfi-sdk";
|
8
8
|
import { updateLookupTable } from "./shared";
|
9
9
|
|
10
10
|
const LOOKUP_TABLE_ADDRESS = new PublicKey(MARGINFI_ACCOUNTS_LOOKUP_TABLE);
|
@@ -3,13 +3,20 @@ import { getTokenAccounts } from "../src/utils/accountUtils";
|
|
3
3
|
import { SOLAUTO_MANAGER } from "../src/constants/generalAccounts";
|
4
4
|
import { ALL_SUPPORTED_TOKENS } from "../src/constants/tokenConstants";
|
5
5
|
import { updateLookupTable } from "./shared";
|
6
|
-
import { STANDARD_LUT_ACCOUNTS } from "../src/constants/solautoConstants";
|
6
|
+
import { SOLAUTO_LUT, STANDARD_LUT_ACCOUNTS } from "../src/constants/solautoConstants";
|
7
7
|
|
8
|
+
const LOOKUP_TABLE_ADDRESS = new PublicKey(SOLAUTO_LUT);
|
8
9
|
const solautoManagerTokenAccounts = getTokenAccounts(SOLAUTO_MANAGER, ALL_SUPPORTED_TOKENS.map((x) => new PublicKey(x)));
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
)
|
11
|
+
export async function updateSolautoLut(additionalAccounts?: string[]) {
|
12
|
+
return updateLookupTable(
|
13
|
+
[
|
14
|
+
...STANDARD_LUT_ACCOUNTS,
|
15
|
+
...solautoManagerTokenAccounts.map((x) => x.toString()),
|
16
|
+
...(additionalAccounts ?? [])
|
17
|
+
],
|
18
|
+
LOOKUP_TABLE_ADDRESS
|
19
|
+
);
|
20
|
+
}
|
21
|
+
|
22
|
+
updateSolautoLut();
|
package/package.json
CHANGED
@@ -56,7 +56,7 @@ import {
|
|
56
56
|
} from "../utils/solanaUtils";
|
57
57
|
import { FlashLoanDetails } from "../utils/solauto/rebalanceUtils";
|
58
58
|
import { NATIVE_MINT } from "@solana/spl-token";
|
59
|
-
import { MIN_POSITION_STATE_FRESHNESS_SECS } from "../constants/solautoConstants";
|
59
|
+
import { MIN_POSITION_STATE_FRESHNESS_SECS, SOLAUTO_LUT } from "../constants/solautoConstants";
|
60
60
|
import { currentUnixSeconds } from "../utils/generalUtils";
|
61
61
|
import { LivePositionUpdates } from "../utils/solauto/generalUtils";
|
62
62
|
|
@@ -267,8 +267,7 @@ export abstract class SolautoClient {
|
|
267
267
|
}
|
268
268
|
|
269
269
|
defaultLookupTables(): string[] {
|
270
|
-
|
271
|
-
return [];
|
270
|
+
return [SOLAUTO_LUT];
|
272
271
|
}
|
273
272
|
|
274
273
|
lutAccountsToAdd(): PublicKey[] {
|
@@ -170,7 +170,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
170
170
|
return [
|
171
171
|
...super.lutAccountsToAdd(),
|
172
172
|
this.marginfiAccountPk,
|
173
|
-
this.intermediaryMarginfiAccountPk,
|
173
|
+
...(this.signer.publicKey.toString() === this.authority.toString() ? [this.intermediaryMarginfiAccountPk] : []),
|
174
174
|
];
|
175
175
|
}
|
176
176
|
|
@@ -26,6 +26,8 @@ export const MAX_REPAY_GAP_BPS = 100;
|
|
26
26
|
|
27
27
|
export const PRICES: { [key: string]: { price: number; time: number; } } = {};
|
28
28
|
|
29
|
+
export const SOLAUTO_LUT = "9D4xwZwDf46n9ft5gQxZzq3rBbdRXsXojKQLZbBdskPY";
|
30
|
+
|
29
31
|
export const JUPITER_PROGRAM_ID = "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4";
|
30
32
|
|
31
33
|
export const STANDARD_LUT_ACCOUNTS = [
|
@@ -245,10 +245,8 @@ export async function rebalanceChoresBefore(
|
|
245
245
|
usesAccount(
|
246
246
|
(client as SolautoMarginfiClient).intermediaryMarginfiAccountPk
|
247
247
|
);
|
248
|
-
const checkSignerSupplyTa =
|
249
|
-
|
250
|
-
const checkSignerDebtTa =
|
251
|
-
client.selfManaged && usesAccount(client.signerSupplyTa);
|
248
|
+
const checkSignerSupplyTa = usesAccount(client.signerSupplyTa);
|
249
|
+
const checkSignerDebtTa = usesAccount(client.signerDebtTa);
|
252
250
|
|
253
251
|
const accountsNeeded = [
|
254
252
|
...[checkReferralSupplyTa ? client.referredBySupplyTa : PublicKey.default],
|
package/src/utils/solanaUtils.ts
CHANGED
@@ -288,34 +288,34 @@ export async function sendSingleOptimizedTransaction(
|
|
288
288
|
const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, attemptNum);
|
289
289
|
console.log("Compute unit price: ", feeEstimate);
|
290
290
|
|
291
|
-
const simulationResult = await retryWithExponentialBackoff(
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
);
|
291
|
+
// const simulationResult = await retryWithExponentialBackoff(
|
292
|
+
// async () =>
|
293
|
+
// await simulateTransaction(
|
294
|
+
// connection,
|
295
|
+
// toWeb3JsTransaction(
|
296
|
+
// await (
|
297
|
+
// await assembleFinalTransaction(
|
298
|
+
// umi.identity,
|
299
|
+
// tx,
|
300
|
+
// feeEstimate,
|
301
|
+
// 1_400_000
|
302
|
+
// ).setLatestBlockhash(umi)
|
303
|
+
// ).build(umi)
|
304
|
+
// )
|
305
|
+
// )
|
306
|
+
// );
|
307
307
|
|
308
|
-
const computeUnitLimit = Math.round(
|
309
|
-
|
310
|
-
);
|
311
|
-
console.log("Compute unit limit: ", computeUnitLimit);
|
308
|
+
// const computeUnitLimit = Math.round(
|
309
|
+
// simulationResult.value.unitsConsumed! * 1.1
|
310
|
+
// );
|
311
|
+
// console.log("Compute unit limit: ", computeUnitLimit);
|
312
312
|
|
313
313
|
if (!simulateOnly) {
|
314
314
|
const result = await assembleFinalTransaction(
|
315
315
|
umi.identity,
|
316
316
|
tx,
|
317
317
|
feeEstimate,
|
318
|
-
|
318
|
+
800_000
|
319
319
|
).sendAndConfirm(umi, {
|
320
320
|
send: {
|
321
321
|
skipPreflight: true,
|
@@ -343,7 +343,7 @@ export function getJupSwapRebalanceDetails(
|
|
343
343
|
outputMint: toWeb3JsPublicKey(output.mint),
|
344
344
|
destinationWallet: client.solautoPosition,
|
345
345
|
// slippageBpsIncFactor: (!values.increasingLeverage ? 0.1 : 0) + ((attemptNum ?? 0) * 0.15),
|
346
|
-
slippageBpsIncFactor: (attemptNum ?? 0) * 0.
|
346
|
+
slippageBpsIncFactor: (attemptNum ?? 0) * 0.2,
|
347
347
|
amount: rebalancingToZero
|
348
348
|
? client.solautoPositionState!.debt.amountUsed.baseUnit +
|
349
349
|
BigInt(
|
@@ -21,10 +21,11 @@ import { USDC_MINT } from "../../src/constants";
|
|
21
21
|
|
22
22
|
describe("Solauto Marginfi tests", async () => {
|
23
23
|
const signer = setupTest();
|
24
|
+
// const signer = setupTest("solauto-manager");
|
24
25
|
|
25
26
|
const payForTransactions = false;
|
26
27
|
const useJitoBundle = false;
|
27
|
-
const positionId =
|
28
|
+
const positionId = 1;
|
28
29
|
|
29
30
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
30
31
|
const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY!, true);
|
@@ -37,11 +38,12 @@ describe("Solauto Marginfi tests", async () => {
|
|
37
38
|
{
|
38
39
|
signer,
|
39
40
|
positionId,
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
authority: new PublicKey("AprYCPiVeKMCgjQ2ZufwChMzvQ5kFjJo2ekTLSkXsQDm")
|
42
|
+
// marginfiAccount: new PublicKey(
|
43
|
+
// "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
|
44
|
+
// ),
|
45
|
+
// supplyMint: NATIVE_MINT,
|
46
|
+
// debtMint: new PublicKey(USDC_MINT),
|
45
47
|
}
|
46
48
|
);
|
47
49
|
|
@@ -115,7 +117,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
115
117
|
transactionItems.push(
|
116
118
|
new TransactionItem(
|
117
119
|
async (attemptNum) =>
|
118
|
-
await buildSolautoRebalanceTransaction(client,
|
120
|
+
await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
|
119
121
|
"rebalance"
|
120
122
|
)
|
121
123
|
);
|