@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
@@ -6,18 +6,15 @@ const web3_js_1 = require("@solana/web3.js");
|
|
6
6
|
const umi_1 = require("@metaplex-foundation/umi");
|
7
7
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
8
8
|
const generated_1 = require("../../generated");
|
9
|
-
const
|
10
|
-
const
|
11
|
-
const solanaUtils_1 = require("../../utils/solanaUtils");
|
12
|
-
const solautoConstants_1 = require("../../constants/solautoConstants");
|
13
|
-
const solautoUtils_1 = require("../../utils/solautoUtils");
|
9
|
+
const utils_1 = require("../../utils");
|
10
|
+
const constants_1 = require("../../constants");
|
14
11
|
const referralStateManager_1 = require("./referralStateManager");
|
15
12
|
const solautoPosition_1 = require("../../solautoPosition");
|
16
|
-
const
|
13
|
+
const flashLoans_1 = require("../flashLoans");
|
17
14
|
class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
18
15
|
constructor() {
|
19
16
|
super(...arguments);
|
20
|
-
this.contextUpdates = new
|
17
|
+
this.contextUpdates = new utils_1.ContextUpdates();
|
21
18
|
}
|
22
19
|
async initialize(args) {
|
23
20
|
await super.initialize(args);
|
@@ -27,26 +24,27 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
27
24
|
(!args.supplyMint || !args.debtMint || !args.lpUserAccount)) {
|
28
25
|
throw new Error("Self managed position is missing arguments");
|
29
26
|
}
|
30
|
-
const positionPk = (0,
|
27
|
+
const positionPk = (0, utils_1.getSolautoPositionAccount)(this.authority, this.positionId, this.programId);
|
31
28
|
this.pos = await (0, solautoPosition_1.getOrCreatePositionEx)(this.umi, positionPk, {
|
32
29
|
supplyMint: args.supplyMint,
|
33
30
|
debtMint: args.debtMint,
|
34
31
|
lendingPool: args.lendingPool,
|
35
32
|
lpUserAccount: args.lpUserAccount,
|
36
33
|
lendingPlatform: this.lendingPlatform,
|
34
|
+
lpEnv: this.lpEnv,
|
37
35
|
}, this.contextUpdates);
|
38
|
-
this.positionSupplyTa = (0,
|
39
|
-
this.signerSupplyTa = (0,
|
40
|
-
this.positionDebtTa = (0,
|
41
|
-
this.signerDebtTa = (0,
|
42
|
-
this.solautoFeesSupplyTa = (0,
|
43
|
-
this.solautoFeesDebtTa = (0,
|
36
|
+
this.positionSupplyTa = (0, utils_1.getTokenAccount)(this.pos.publicKey, this.pos.supplyMint());
|
37
|
+
this.signerSupplyTa = (0, utils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.pos.supplyMint());
|
38
|
+
this.positionDebtTa = (0, utils_1.getTokenAccount)(this.pos.publicKey, this.pos.debtMint());
|
39
|
+
this.signerDebtTa = (0, utils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.pos.debtMint());
|
40
|
+
this.solautoFeesSupplyTa = (0, utils_1.getTokenAccount)(constants_1.SOLAUTO_FEES_WALLET, this.pos.supplyMint());
|
41
|
+
this.solautoFeesDebtTa = (0, utils_1.getTokenAccount)(constants_1.SOLAUTO_FEES_WALLET, this.pos.debtMint());
|
44
42
|
this.authorityLutAddress =
|
45
43
|
this.referralStateData?.lookupTable &&
|
46
44
|
!(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.referralStateData.lookupTable).equals(web3_js_1.PublicKey.default)
|
47
45
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.referralStateData.lookupTable)
|
48
46
|
: undefined;
|
49
|
-
this.flProvider = new
|
47
|
+
this.flProvider = new flashLoans_1.FlProviderAggregator(this.umi, this.signer, this.authority, this.pos.supplyMint(), this.pos.debtMint(), this.lpEnv);
|
50
48
|
await this.flProvider.initialize();
|
51
49
|
this.otherSigners.push(...this.flProvider.otherSigners());
|
52
50
|
this.log("Position state: ", this.pos.state());
|
@@ -57,13 +55,13 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
57
55
|
}
|
58
56
|
referredBySupplyTa() {
|
59
57
|
if (this.referredByState !== undefined) {
|
60
|
-
return (0,
|
58
|
+
return (0, utils_1.getTokenAccount)(this.referredByState, this.pos.supplyMint());
|
61
59
|
}
|
62
60
|
return undefined;
|
63
61
|
}
|
64
62
|
referredByDebtTa() {
|
65
63
|
if (this.referredByState !== undefined) {
|
66
|
-
return (0,
|
64
|
+
return (0, utils_1.getTokenAccount)(this.referredByState, this.pos.debtMint());
|
67
65
|
}
|
68
66
|
return undefined;
|
69
67
|
}
|
@@ -87,7 +85,7 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
87
85
|
}
|
88
86
|
defaultLookupTables() {
|
89
87
|
return [
|
90
|
-
|
88
|
+
constants_1.SOLAUTO_LUT,
|
91
89
|
...(this.authorityLutAddress
|
92
90
|
? [this.authorityLutAddress.toString()]
|
93
91
|
: []),
|
@@ -137,7 +135,7 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
137
135
|
});
|
138
136
|
this.authorityLutAddress = lookupTableAddress;
|
139
137
|
tx = tx
|
140
|
-
.add((0,
|
138
|
+
.add((0, utils_1.getWrappedInstruction)(this.signer, createLookupTableInst))
|
141
139
|
.add(this.updateReferralStatesIx(undefined, this.authorityLutAddress));
|
142
140
|
}
|
143
141
|
const accountsToAdd = this.lutAccountsToAdd().filter((x) => !existingLutAccounts
|
@@ -147,7 +145,7 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
147
145
|
return undefined;
|
148
146
|
}
|
149
147
|
tx = tx
|
150
|
-
.add((0,
|
148
|
+
.add((0, utils_1.getWrappedInstruction)(this.signer, web3_js_1.AddressLookupTableProgram.extendLookupTable({
|
151
149
|
payer: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey),
|
152
150
|
authority: this.authority,
|
153
151
|
lookupTable: this.authorityLutAddress,
|
@@ -165,7 +163,7 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
165
163
|
async signerBalances() {
|
166
164
|
if (!this.signerSupplyBalance || !this.signerDebtBalance) {
|
167
165
|
[this.signerSupplyBalance, this.signerDebtBalance] =
|
168
|
-
await (0,
|
166
|
+
await (0, utils_1.getWalletSplBalances)(this.connection, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), [this.pos.supplyMint(), this.pos.debtMint()]);
|
169
167
|
}
|
170
168
|
return {
|
171
169
|
supplyBalance: this.signerSupplyBalance,
|
@@ -277,14 +275,14 @@ class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
|
277
275
|
let tx = (0, umi_1.transactionBuilder)();
|
278
276
|
if (!this.selfManaged) {
|
279
277
|
if (args.__kind === "Deposit") {
|
280
|
-
tx = tx.add((0,
|
278
|
+
tx = tx.add((0, utils_1.splTokenTransferUmiIx)(this.signer, this.signerSupplyTa, this.positionSupplyTa, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), BigInt(args.fields[0])));
|
281
279
|
}
|
282
280
|
else if (args.__kind === "Repay") {
|
283
281
|
if (args.fields[0].__kind === "Some") {
|
284
|
-
tx = tx.add((0,
|
282
|
+
tx = tx.add((0, utils_1.splTokenTransferUmiIx)(this.signer, this.signerDebtTa, this.positionDebtTa, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), BigInt(args.fields[0].fields[0])));
|
285
283
|
}
|
286
284
|
else {
|
287
|
-
tx = tx.add((0,
|
285
|
+
tx = tx.add((0, utils_1.splTokenTransferUmiIx)(this.signer, this.signerDebtTa, this.positionDebtTa, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), BigInt(Math.round(Number(this.pos.state().debt.amountUsed.baseUnit) * 1.01))));
|
288
286
|
}
|
289
287
|
}
|
290
288
|
}
|
@@ -1,12 +1,12 @@
|
|
1
|
-
import { Signer, TransactionBuilder } from "@metaplex-foundation/umi";
|
2
1
|
import { PublicKey } from "@solana/web3.js";
|
3
|
-
import {
|
4
|
-
import { MarginfiAssetAccounts } from "../../types
|
2
|
+
import { Signer, TransactionBuilder } from "@metaplex-foundation/umi";
|
3
|
+
import { MarginfiAssetAccounts, RebalanceDetails } from "../../types";
|
4
|
+
import { MarginfiProgramAccounts } from "../../constants";
|
5
5
|
import { DCASettingsInpArgs, LendingPlatform, RebalanceStep, SolautoActionArgs, SolautoSettingsParametersInpArgs } from "../../generated";
|
6
|
-
import {
|
6
|
+
import { SolautoClient, SolautoClientArgs } from "./solautoClient";
|
7
7
|
export declare class SolautoMarginfiClient extends SolautoClient {
|
8
8
|
lendingPlatform: LendingPlatform;
|
9
|
-
|
9
|
+
mfiAccounts: MarginfiProgramAccounts;
|
10
10
|
marginfiAccount: PublicKey | Signer;
|
11
11
|
marginfiAccountPk: PublicKey;
|
12
12
|
marginfiGroup: PublicKey;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/solautoMarginfiClient.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/solautoMarginfiClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EACL,MAAM,EACN,kBAAkB,EAInB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAuB,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAClB,eAAe,EAGf,aAAa,EACb,iBAAiB,EAEjB,gCAAgC,EAOjC,MAAM,iBAAiB,CAAC;AAezB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEnE,qBAAa,qBAAsB,SAAQ,aAAa;IAC/C,eAAe,kBAA4B;IAE3C,WAAW,EAAG,uBAAuB,CAAC;IAEtC,eAAe,EAAG,SAAS,GAAG,MAAM,CAAC;IACrC,iBAAiB,EAAG,SAAS,CAAC;IAC9B,aAAa,EAAG,SAAS,CAAC;IAE1B,sBAAsB,EAAG,qBAAqB,CAAC;IAC/C,oBAAoB,EAAG,qBAAqB,CAAC;IAE7C,iBAAiB,EAAG,SAAS,CAAC;IAC9B,eAAe,EAAG,SAAS,CAAC;IAE7B,UAAU,CAAC,IAAI,EAAE,iBAAiB;IAwExC,mBAAmB,IAAI,MAAM,EAAE;IAO/B,gBAAgB,IAAI,SAAS,EAAE;IAI/B,yBAAyB,CAAC,eAAe,EAAE,MAAM,GAAG,kBAAkB;IAStE,cAAc,CACZ,QAAQ,CAAC,EAAE,gCAAgC,EAC3C,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA0C9B,eAAe,IAAI,kBAAkB;IAYrC,SAAS,IAAI,kBAAkB;IAc/B,qBAAqB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUlE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA0D5C,WAAW,CACT,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,gBAAgB,GACrB,kBAAkB;CAiGtB"}
|
@@ -1,16 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.SolautoMarginfiClient = void 0;
|
4
|
-
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
5
|
-
const umi_1 = require("@metaplex-foundation/umi");
|
6
4
|
const web3_js_1 = require("@solana/web3.js");
|
7
|
-
const
|
8
|
-
const
|
5
|
+
const umi_1 = require("@metaplex-foundation/umi");
|
6
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
7
|
+
const constants_1 = require("../../constants");
|
9
8
|
const generated_1 = require("../../generated");
|
10
|
-
const
|
9
|
+
const utils_1 = require("../../utils");
|
11
10
|
const marginfi_sdk_1 = require("../../marginfi-sdk");
|
12
|
-
const
|
13
|
-
const solautoUtils_1 = require("../../utils/solautoUtils");
|
11
|
+
const solautoClient_1 = require("./solautoClient");
|
14
12
|
class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
15
13
|
constructor() {
|
16
14
|
super(...arguments);
|
@@ -18,6 +16,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
18
16
|
}
|
19
17
|
async initialize(args) {
|
20
18
|
await super.initialize(args);
|
19
|
+
this.mfiAccounts = (0, constants_1.getMarginfiAccounts)(this.lpEnv);
|
21
20
|
this.marginfiGroup = await this.pos.lendingPool();
|
22
21
|
if (this.selfManaged) {
|
23
22
|
this.marginfiAccount =
|
@@ -29,9 +28,9 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
29
28
|
this.marginfiAccount = this.pos.lpUserAccount;
|
30
29
|
}
|
31
30
|
else {
|
32
|
-
const accounts = await (0,
|
31
|
+
const accounts = await (0, utils_1.getAllMarginfiAccountsByAuthority)(this.umi, this.pos.publicKey, this.marginfiGroup, false);
|
33
32
|
const reusableAccounts = accounts.length > 0
|
34
|
-
? (await (0, marginfi_sdk_1.safeFetchAllMarginfiAccount)(this.umi, accounts.map((x) => (0, umi_1.publicKey)(x.marginfiAccount)))).filter((x) => (0,
|
33
|
+
? (await (0, marginfi_sdk_1.safeFetchAllMarginfiAccount)(this.umi, accounts.map((x) => (0, umi_1.publicKey)(x.marginfiAccount)))).filter((x) => (0, utils_1.marginfiAccountEmpty)(x))
|
35
34
|
: [];
|
36
35
|
this.marginfiAccount =
|
37
36
|
reusableAccounts.length > 0
|
@@ -47,9 +46,9 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
47
46
|
this.otherSigners.push(this.marginfiAccount);
|
48
47
|
}
|
49
48
|
this.marginfiSupplyAccounts =
|
50
|
-
|
49
|
+
this.mfiAccounts.bankAccounts[this.marginfiGroup.toString()][this.pos.supplyMint().toString()];
|
51
50
|
this.marginfiDebtAccounts =
|
52
|
-
|
51
|
+
this.mfiAccounts.bankAccounts[this.marginfiGroup.toString()][this.pos.debtMint().toString()];
|
53
52
|
// TODO: Don't dynamically pull oracle from bank until Marginfi sorts out their price oracle issues.
|
54
53
|
// const [supplyBank, debtBank] = await safeFetchAllBank(this.umi, [
|
55
54
|
// publicKey(this.marginfiSupplyAccounts.bank),
|
@@ -62,7 +61,10 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
62
61
|
this.log("Marginfi account:", this.marginfiAccountPk.toString());
|
63
62
|
}
|
64
63
|
defaultLookupTables() {
|
65
|
-
return [
|
64
|
+
return [
|
65
|
+
this.mfiAccounts.lookupTable.toString(),
|
66
|
+
...super.defaultLookupTables(),
|
67
|
+
];
|
66
68
|
}
|
67
69
|
lutAccountsToAdd() {
|
68
70
|
return [...super.lutAccountsToAdd(), this.marginfiAccountPk];
|
@@ -87,7 +89,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
87
89
|
}
|
88
90
|
return (0, generated_1.marginfiOpenPosition)(this.umi, {
|
89
91
|
signer: this.signer,
|
90
|
-
marginfiProgram: (0, umi_1.publicKey)(
|
92
|
+
marginfiProgram: (0, umi_1.publicKey)(this.mfiAccounts.program),
|
91
93
|
signerReferralState: (0, umi_1.publicKey)(this.referralState),
|
92
94
|
referredByState: this.referredByState
|
93
95
|
? (0, umi_1.publicKey)(this.referredByState)
|
@@ -129,7 +131,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
129
131
|
refreshIx() {
|
130
132
|
return (0, generated_1.marginfiRefreshData)(this.umi, {
|
131
133
|
signer: this.signer,
|
132
|
-
marginfiProgram: (0, umi_1.publicKey)(
|
134
|
+
marginfiProgram: (0, umi_1.publicKey)(this.mfiAccounts.program),
|
133
135
|
marginfiGroup: (0, umi_1.publicKey)(this.marginfiGroup),
|
134
136
|
marginfiAccount: (0, umi_1.publicKey)(this.marginfiAccount),
|
135
137
|
supplyBank: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.bank),
|
@@ -229,7 +231,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
229
231
|
}
|
230
232
|
return (0, generated_1.marginfiProtocolInteraction)(this.umi, {
|
231
233
|
signer: this.signer,
|
232
|
-
marginfiProgram: (0, umi_1.publicKey)(
|
234
|
+
marginfiProgram: (0, umi_1.publicKey)(this.mfiAccounts.program),
|
233
235
|
solautoPosition: (0, umi_1.publicKey)(this.pos.publicKey),
|
234
236
|
marginfiGroup: (0, umi_1.publicKey)(this.marginfiGroup),
|
235
237
|
marginfiAccount: (0, umi_1.publicKey)(this.marginfiAccountPk),
|
@@ -257,13 +259,13 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
257
259
|
const needDebtAccounts = (!inputIsSupply && preSwapRebalance) ||
|
258
260
|
(!outputIsSupply && postSwapRebalance) ||
|
259
261
|
(!inputIsSupply && data.flashLoan !== undefined && postSwapRebalance);
|
260
|
-
const isFirstRebalance = (preSwapRebalance && (0,
|
262
|
+
const isFirstRebalance = (preSwapRebalance && (0, utils_1.hasFirstRebalance)(data.rebalanceType)) ||
|
261
263
|
(postSwapRebalance &&
|
262
264
|
data.rebalanceType === generated_1.SolautoRebalanceType.FLSwapThenRebalance);
|
263
265
|
const addAuthorityTas = this.selfManaged || data.values.tokenBalanceChange !== undefined;
|
264
266
|
return (0, generated_1.marginfiRebalance)(this.umi, {
|
265
267
|
signer: this.signer,
|
266
|
-
marginfiProgram: (0, umi_1.publicKey)(
|
268
|
+
marginfiProgram: (0, umi_1.publicKey)(this.mfiAccounts.program),
|
267
269
|
ixsSysvar: (0, umi_1.publicKey)(web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY),
|
268
270
|
solautoFeesTa: (0, umi_1.publicKey)(data.values.rebalanceDirection === generated_1.RebalanceDirection.Boost
|
269
271
|
? this.solautoFeesSupplyTa
|
@@ -280,12 +282,12 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
280
282
|
solautoPosition: (0, umi_1.publicKey)(this.pos.publicKey),
|
281
283
|
marginfiGroup: (0, umi_1.publicKey)(this.marginfiGroup),
|
282
284
|
marginfiAccount: (0, umi_1.publicKey)(this.marginfiAccountPk),
|
283
|
-
intermediaryTa: (0, umi_1.publicKey)((0,
|
285
|
+
intermediaryTa: (0, umi_1.publicKey)((0, utils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), new web3_js_1.PublicKey(data.swapQuote.inputMint))),
|
284
286
|
supplyBank: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.bank),
|
285
287
|
supplyPriceOracle: (0, umi_1.publicKey)(this.supplyPriceOracle),
|
286
288
|
positionSupplyTa: (0, umi_1.publicKey)(this.positionSupplyTa),
|
287
289
|
authoritySupplyTa: addAuthorityTas
|
288
|
-
? (0, umi_1.publicKey)((0,
|
290
|
+
? (0, umi_1.publicKey)((0, utils_1.getTokenAccount)(this.authority, this.pos.supplyMint()))
|
289
291
|
: undefined,
|
290
292
|
vaultSupplyTa: needSupplyAccounts
|
291
293
|
? (0, umi_1.publicKey)(this.marginfiSupplyAccounts.liquidityVault)
|
@@ -297,7 +299,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
297
299
|
debtPriceOracle: (0, umi_1.publicKey)(this.debtPriceOracle),
|
298
300
|
positionDebtTa: (0, umi_1.publicKey)(this.positionDebtTa),
|
299
301
|
authorityDebtTa: addAuthorityTas
|
300
|
-
? (0, umi_1.publicKey)((0,
|
302
|
+
? (0, umi_1.publicKey)((0, utils_1.getTokenAccount)(this.authority, this.pos.debtMint()))
|
301
303
|
: undefined,
|
302
304
|
vaultDebtTa: needDebtAccounts
|
303
305
|
? (0, umi_1.publicKey)(this.marginfiDebtAccounts.liquidityVault)
|
@@ -1,18 +1,20 @@
|
|
1
|
-
import { Signer, Umi } from "@metaplex-foundation/umi";
|
2
1
|
import { Connection, PublicKey } from "@solana/web3.js";
|
2
|
+
import { Signer, Umi } from "@metaplex-foundation/umi";
|
3
3
|
import { WalletAdapter } from "@metaplex-foundation/umi-signer-wallet-adapters";
|
4
|
+
import { ProgramEnv } from "../../types";
|
4
5
|
export interface TxHandlerProps {
|
5
6
|
signer?: Signer;
|
6
7
|
wallet?: WalletAdapter;
|
7
8
|
rpcUrl: string;
|
8
9
|
showLogs?: boolean;
|
9
10
|
programId?: PublicKey;
|
10
|
-
|
11
|
+
lpEnv?: ProgramEnv;
|
11
12
|
}
|
12
13
|
export declare abstract class TxHandler {
|
13
14
|
rpcUrl: string;
|
14
15
|
showLogs: boolean;
|
15
16
|
programId: PublicKey;
|
17
|
+
lpEnv: ProgramEnv;
|
16
18
|
connection: Connection;
|
17
19
|
umi: Umi;
|
18
20
|
signer: Signer;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"txHandler.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/txHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"txHandler.d.ts","sourceRoot":"","sources":["../../../src/services/solauto/txHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAkB,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AAGzD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,8BAAsB,SAAS;IACtB,MAAM,EAAG,MAAM,CAAC;IAChB,QAAQ,UAAS;IACjB,SAAS,EAAG,SAAS,CAAC;IACtB,KAAK,EAAG,UAAU,CAAC;IAEnB,UAAU,EAAG,UAAU,CAAC;IACxB,GAAG,EAAG,GAAG,CAAC;IACV,MAAM,EAAG,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAM;gBAEvB,KAAK,EAAE,cAAc;IAgCjC,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAIzB,QAAQ,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAExC,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAC9D"}
|
@@ -2,19 +2,17 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.TxHandler = void 0;
|
4
4
|
const umi_1 = require("@metaplex-foundation/umi");
|
5
|
+
const umi_signer_wallet_adapters_1 = require("@metaplex-foundation/umi-signer-wallet-adapters");
|
5
6
|
const utils_1 = require("../../utils");
|
6
7
|
const constants_1 = require("../../constants");
|
7
|
-
const umi_signer_wallet_adapters_1 = require("@metaplex-foundation/umi-signer-wallet-adapters");
|
8
8
|
class TxHandler {
|
9
9
|
constructor(props) {
|
10
10
|
this.showLogs = false;
|
11
|
-
this.programId = constants_1.SOLAUTO_PROD_PROGRAM;
|
12
11
|
this.otherSigners = [];
|
13
|
-
|
14
|
-
|
15
|
-
}
|
12
|
+
this.programId = props.programId ?? constants_1.SOLAUTO_PROD_PROGRAM;
|
13
|
+
this.lpEnv = props.lpEnv ?? "Prod";
|
16
14
|
this.rpcUrl = props.rpcUrl;
|
17
|
-
const [connection, umi] = (0, utils_1.getSolanaRpcConnection)(this.rpcUrl, this.programId,
|
15
|
+
const [connection, umi] = (0, utils_1.getSolanaRpcConnection)(this.rpcUrl, this.programId, this.lpEnv);
|
18
16
|
this.connection = connection;
|
19
17
|
this.umi = umi;
|
20
18
|
if (!props.signer && !props.wallet) {
|
@@ -1,6 +1,6 @@
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
1
2
|
import { Signer, TransactionBuilder } from "@metaplex-foundation/umi";
|
2
3
|
import { QuoteResponse } from "@jup-ag/api";
|
3
|
-
import { PublicKey } from "@solana/web3.js";
|
4
4
|
import { TransactionItemInputs } from "../../types";
|
5
5
|
export interface SwapInput {
|
6
6
|
inputMint: PublicKey;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jupSwapManager.d.ts","sourceRoot":"","sources":["../../../src/services/swap/jupSwapManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"jupSwapManager.d.ts","sourceRoot":"","sources":["../../../src/services/swap/jupSwapManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAEL,aAAa,EAEd,MAAM,aAAa,CAAC;AAUrB,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC3C,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAC9B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,kBAAkB,CAAC;IAC5B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,SAAS,EAAE,kBAAkB,CAAC;IAC9B,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC;AAED,qBAAa,cAAc;IAKb,OAAO,CAAC,MAAM;IAJ1B,MAAM,mCAA4B;IAE3B,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAa;gBAEnC,MAAM,EAAE,MAAM;IAErB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC;YAoBhD,kBAAkB;IAsChC,cAAc;IAId,OAAO,CAAC,0BAA0B;IAQlC,OAAO,CAAC,0BAA0B;IAc5B,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,sBAAsB,CAAC;IA2CnE,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAYlE"}
|
@@ -2,12 +2,9 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.JupSwapManager = void 0;
|
4
4
|
const umi_1 = require("@metaplex-foundation/umi");
|
5
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
5
6
|
const api_1 = require("@jup-ag/api");
|
6
|
-
const solanaUtils_1 = require("../../utils/solanaUtils");
|
7
|
-
const numberUtils_1 = require("../../utils/numberUtils");
|
8
|
-
const accountUtils_1 = require("../../utils/accountUtils");
|
9
7
|
const utils_1 = require("../../utils");
|
10
|
-
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
11
8
|
class JupSwapManager {
|
12
9
|
constructor(signer) {
|
13
10
|
this.signer = signer;
|
@@ -39,7 +36,7 @@ class JupSwapManager {
|
|
39
36
|
quoteResponse: this.jupQuote,
|
40
37
|
wrapAndUnwrapSol: data.wrapAndUnwrapSol ?? false,
|
41
38
|
useTokenLedger: !data.exactOut && !data.exactIn,
|
42
|
-
destinationTokenAccount: (0,
|
39
|
+
destinationTokenAccount: (0, utils_1.getTokenAccount)(data.destinationWallet ??
|
43
40
|
(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), data.outputMint).toString(),
|
44
41
|
},
|
45
42
|
});
|
@@ -54,7 +51,7 @@ class JupSwapManager {
|
|
54
51
|
return instructions;
|
55
52
|
}
|
56
53
|
priceImpactBps() {
|
57
|
-
return Math.round((0,
|
54
|
+
return Math.round((0, utils_1.toBps)(parseFloat(this.jupQuote.priceImpactPct))) + 1;
|
58
55
|
}
|
59
56
|
adaptSlippageToPriceImpact(slippageIncFactor) {
|
60
57
|
const finalPriceSlippageBps = Math.round(Math.max(20, this.jupQuote.slippageBps, this.priceImpactBps()) *
|
@@ -63,7 +60,7 @@ class JupSwapManager {
|
|
63
60
|
}
|
64
61
|
addInAmountSlippagePadding() {
|
65
62
|
(0, utils_1.consoleLog)("Raw inAmount:", this.jupQuote.inAmount);
|
66
|
-
const inc = Math.max((0,
|
63
|
+
const inc = Math.max((0, utils_1.fromBps)(this.priceImpactBps()) * 1.1, (0, utils_1.fromBps)(this.jupQuote.slippageBps) * 0.1);
|
67
64
|
(0, utils_1.consoleLog)("Inc:", inc);
|
68
65
|
this.jupQuote.inAmount = Math.round(parseInt(this.jupQuote.inAmount) +
|
69
66
|
parseInt(this.jupQuote.inAmount) * inc).toString();
|
@@ -84,13 +81,13 @@ class JupSwapManager {
|
|
84
81
|
return {
|
85
82
|
jupQuote: this.jupQuote,
|
86
83
|
lookupTableAddresses: instructions.addressLookupTableAddresses,
|
87
|
-
setupIx: (0, umi_1.transactionBuilder)((instructions.setupInstructions ?? []).map((ix) => (0,
|
84
|
+
setupIx: (0, umi_1.transactionBuilder)((instructions.setupInstructions ?? []).map((ix) => (0, utils_1.getWrappedInstruction)(this.signer, (0, utils_1.jupIxToSolanaIx)(ix)))),
|
88
85
|
swapIx: (0, umi_1.transactionBuilder)([
|
89
|
-
(0,
|
86
|
+
(0, utils_1.getWrappedInstruction)(this.signer, (0, utils_1.jupIxToSolanaIx)(instructions.swapInstruction)),
|
90
87
|
]),
|
91
88
|
cleanupIx: (0, umi_1.transactionBuilder)(instructions.cleanupInstruction
|
92
89
|
? [
|
93
|
-
(0,
|
90
|
+
(0, utils_1.getWrappedInstruction)(this.signer, (0, utils_1.jupIxToSolanaIx)(instructions.cleanupInstruction)),
|
94
91
|
]
|
95
92
|
: []),
|
96
93
|
};
|
@@ -1,7 +1,6 @@
|
|
1
|
-
import { TransactionBuilder, Umi } from "@metaplex-foundation/umi";
|
2
1
|
import { PublicKey } from "@solana/web3.js";
|
3
|
-
import {
|
4
|
-
import { ReferralStateManager } from "
|
2
|
+
import { TransactionBuilder, Umi } from "@metaplex-foundation/umi";
|
3
|
+
import { SolautoClient, ReferralStateManager } from "../solauto";
|
5
4
|
import { TransactionItemInputs } from "../../types";
|
6
5
|
export declare function rebalanceChoresBefore(client: SolautoClient, tx: TransactionBuilder, accountsGettingCreated: string[]): Promise<TransactionBuilder>;
|
7
6
|
export declare function getTransactionChores(client: SolautoClient, tx: TransactionBuilder): Promise<[TransactionBuilder, TransactionBuilder]>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAIL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAgBlC,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AA4BjE,OAAO,EAAE,qBAAqB,EAAyB,MAAM,aAAa,CAAC;AAuL3E,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAyF7B;AA6LD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAuC5C;AAED,wBAAgB,YAAY,CAC1B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,kBAAkB,EAAE,EACzB,KAAK,EAAE,KAAK,EACZ,oBAAoB,CAAC,EAAE,OAAO;;;;EA8G/B"}
|