@haven-fi/solauto-sdk 1.0.581 → 1.0.583
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/solautoConstants.d.ts +1 -0
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +4 -10
- package/dist/constants/switchboardConstants.d.ts.map +1 -1
- package/dist/constants/switchboardConstants.js +5 -5
- package/dist/generated/accounts/solautoPosition.js +2 -2
- package/dist/generated/errors/solauto.d.ts +14 -2
- package/dist/generated/errors/solauto.d.ts.map +1 -1
- package/dist/generated/errors/solauto.js +27 -5
- package/dist/generated/instructions/claimReferralFees.d.ts +1 -1
- package/dist/generated/instructions/claimReferralFees.d.ts.map +1 -1
- package/dist/generated/instructions/closePosition.d.ts +1 -1
- package/dist/generated/instructions/closePosition.d.ts.map +1 -1
- package/dist/generated/instructions/closePosition.js +2 -2
- package/dist/generated/instructions/marginfiOpenPosition.d.ts +1 -3
- package/dist/generated/instructions/marginfiOpenPosition.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiOpenPosition.js +0 -1
- package/dist/generated/instructions/marginfiRebalance.d.ts +7 -3
- package/dist/generated/instructions/marginfiRebalance.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiRebalance.js +3 -1
- package/dist/generated/types/index.d.ts +7 -1
- package/dist/generated/types/index.d.ts.map +1 -1
- package/dist/generated/types/index.js +7 -1
- package/dist/generated/types/positionData.d.ts +2 -2
- package/dist/generated/types/positionData.d.ts.map +1 -1
- package/dist/generated/types/positionData.js +1 -1
- package/dist/generated/types/positionState.d.ts +7 -7
- package/dist/generated/types/positionState.d.ts.map +1 -1
- package/dist/generated/types/positionState.js +3 -3
- package/dist/generated/types/{positionTokenUsage.d.ts → positionTokenState.d.ts} +6 -8
- package/dist/generated/types/positionTokenState.d.ts.map +1 -0
- package/dist/generated/types/{positionTokenUsage.js → positionTokenState.js} +6 -7
- package/dist/generated/types/rebalanceData.d.ts +7 -13
- package/dist/generated/types/rebalanceData.d.ts.map +1 -1
- package/dist/generated/types/rebalanceData.js +3 -6
- package/dist/generated/types/rebalanceDirection.d.ts +3 -2
- package/dist/generated/types/rebalanceDirection.d.ts.map +1 -1
- package/dist/generated/types/rebalanceDirection.js +3 -2
- package/dist/generated/types/rebalanceInstructionData.d.ts +27 -0
- package/dist/generated/types/rebalanceInstructionData.d.ts.map +1 -0
- package/dist/generated/types/rebalanceInstructionData.js +22 -0
- package/dist/generated/types/rebalanceStateValues.d.ts +27 -0
- package/dist/generated/types/rebalanceStateValues.d.ts.map +1 -0
- package/dist/generated/types/rebalanceStateValues.js +22 -0
- package/dist/generated/types/rebalanceStep.d.ts +15 -0
- package/dist/generated/types/rebalanceStep.d.ts.map +1 -0
- package/dist/generated/types/rebalanceStep.js +22 -0
- package/dist/generated/types/solautoRebalanceType.d.ts +4 -5
- package/dist/generated/types/solautoRebalanceType.d.ts.map +1 -1
- package/dist/generated/types/solautoRebalanceType.js +4 -5
- package/dist/generated/types/solautoSettingsParameters.d.ts +2 -15
- package/dist/generated/types/solautoSettingsParameters.d.ts.map +1 -1
- package/dist/generated/types/solautoSettingsParameters.js +1 -5
- package/dist/generated/types/solautoSettingsParametersInp.d.ts +1 -12
- package/dist/generated/types/solautoSettingsParametersInp.d.ts.map +1 -1
- package/dist/generated/types/solautoSettingsParametersInp.js +0 -3
- package/dist/generated/types/swapType.d.ts +15 -0
- package/dist/generated/types/swapType.d.ts.map +1 -0
- package/dist/generated/types/swapType.js +22 -0
- package/dist/generated/types/tokenBalanceChange.d.ts +21 -0
- package/dist/generated/types/tokenBalanceChange.d.ts.map +1 -0
- package/dist/generated/types/tokenBalanceChange.js +19 -0
- package/dist/generated/types/tokenBalanceChangeType.d.ts +18 -0
- package/dist/generated/types/tokenBalanceChangeType.d.ts.map +1 -0
- package/dist/generated/types/tokenBalanceChangeType.js +25 -0
- package/dist/generated/types/updatePositionData.d.ts +2 -2
- package/dist/generated/types/updatePositionData.d.ts.map +1 -1
- package/dist/generated/types/updatePositionData.js +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/marginfi-sdk/types/interestRateConfig.d.ts +3 -1
- package/dist/marginfi-sdk/types/interestRateConfig.d.ts.map +1 -1
- package/dist/marginfi-sdk/types/interestRateConfig.js +2 -1
- package/dist/services/flashLoans/flProviderAggregator.d.ts +19 -0
- package/dist/services/flashLoans/flProviderAggregator.d.ts.map +1 -0
- package/dist/services/flashLoans/flProviderAggregator.js +46 -0
- package/dist/services/flashLoans/flProviderBase.d.ts +23 -0
- package/dist/services/flashLoans/flProviderBase.d.ts.map +1 -0
- package/dist/services/flashLoans/flProviderBase.js +37 -0
- package/dist/services/flashLoans/index.d.ts +4 -0
- package/dist/services/flashLoans/index.d.ts.map +1 -0
- package/dist/services/flashLoans/index.js +19 -0
- package/dist/services/flashLoans/marginfiFlProvider.d.ts +25 -0
- package/dist/services/flashLoans/marginfiFlProvider.d.ts.map +1 -0
- package/dist/services/flashLoans/marginfiFlProvider.js +246 -0
- package/dist/services/index.d.ts +6 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +21 -0
- package/dist/services/rebalance/index.d.ts +3 -0
- package/dist/services/rebalance/index.d.ts.map +1 -0
- package/dist/services/rebalance/index.js +18 -0
- package/dist/services/rebalance/rebalanceSwapManager.d.ts +30 -0
- package/dist/services/rebalance/rebalanceSwapManager.d.ts.map +1 -0
- package/dist/services/rebalance/rebalanceSwapManager.js +144 -0
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts +22 -0
- package/dist/services/rebalance/rebalanceTxBuilder.d.ts.map +1 -0
- package/dist/services/rebalance/rebalanceTxBuilder.js +200 -0
- package/dist/services/rebalance/rebalanceValues.d.ts +31 -0
- package/dist/services/rebalance/rebalanceValues.d.ts.map +1 -0
- package/dist/services/rebalance/rebalanceValues.js +118 -0
- package/dist/services/rebalance/solautoFees.d.ts +13 -0
- package/dist/services/rebalance/solautoFees.d.ts.map +1 -0
- package/dist/services/rebalance/solautoFees.js +54 -0
- package/dist/services/solauto/index.d.ts +5 -0
- package/dist/services/solauto/index.d.ts.map +1 -0
- package/dist/{clients → services/solauto}/referralStateManager.d.ts +4 -5
- package/dist/services/solauto/referralStateManager.d.ts.map +1 -0
- package/dist/{clients → services/solauto}/referralStateManager.js +10 -12
- package/dist/services/solauto/solautoClient.d.ts +59 -0
- package/dist/services/solauto/solautoClient.d.ts.map +1 -0
- package/dist/{clients → services/solauto}/solautoClient.js +78 -109
- package/dist/services/solauto/solautoMarginfiClient.d.ts +34 -0
- package/dist/services/solauto/solautoMarginfiClient.d.ts.map +1 -0
- package/dist/services/solauto/solautoMarginfiClient.js +322 -0
- package/dist/{clients → services/solauto}/txHandler.d.ts +11 -2
- package/dist/services/solauto/txHandler.d.ts.map +1 -0
- package/dist/services/solauto/txHandler.js +38 -0
- package/dist/services/swap/index.d.ts +2 -0
- package/dist/services/swap/index.d.ts.map +1 -0
- package/dist/{utils/solauto → services/swap}/index.js +1 -2
- package/dist/services/swap/jupSwapManager.d.ts +37 -0
- package/dist/services/swap/jupSwapManager.d.ts.map +1 -0
- package/dist/services/swap/jupSwapManager.js +108 -0
- package/dist/services/transactions/index.d.ts.map +1 -0
- package/dist/{transactions → services/transactions}/transactionUtils.d.ts +3 -5
- package/dist/services/transactions/transactionUtils.d.ts.map +1 -0
- package/dist/{transactions → services/transactions}/transactionUtils.js +29 -137
- package/dist/{transactions → services/transactions}/transactionsManager.d.ts +4 -4
- package/dist/services/transactions/transactionsManager.d.ts.map +1 -0
- package/dist/{transactions → services/transactions}/transactionsManager.js +10 -8
- package/dist/solautoPosition/index.d.ts +4 -0
- package/dist/solautoPosition/index.d.ts.map +1 -0
- package/dist/solautoPosition/index.js +19 -0
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts +14 -0
- package/dist/solautoPosition/marginfiSolautoPositionEx.d.ts.map +1 -0
- package/dist/solautoPosition/marginfiSolautoPositionEx.js +73 -0
- package/dist/solautoPosition/solautoPositionEx.d.ts +67 -0
- package/dist/solautoPosition/solautoPositionEx.d.ts.map +1 -0
- package/dist/solautoPosition/solautoPositionEx.js +143 -0
- package/dist/solautoPosition/utils.d.ts +17 -0
- package/dist/solautoPosition/utils.d.ts.map +1 -0
- package/dist/solautoPosition/utils.js +115 -0
- package/dist/types/solauto.d.ts +19 -1
- package/dist/types/solauto.d.ts.map +1 -1
- package/dist/utils/generalUtils.d.ts +1 -0
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +9 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.d.ts +3 -28
- package/dist/utils/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.js +2 -73
- package/dist/utils/marginfiUtils.d.ts +4 -3
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +47 -18
- package/dist/utils/numberUtils.d.ts +3 -6
- package/dist/utils/numberUtils.d.ts.map +1 -1
- package/dist/utils/numberUtils.js +13 -48
- package/dist/utils/priceUtils.js +1 -1
- package/dist/utils/solanaUtils.js +2 -2
- package/dist/utils/{solauto/generalUtils.d.ts → solautoUtils.d.ts} +9 -16
- package/dist/utils/solautoUtils.d.ts.map +1 -0
- package/dist/utils/{solauto/generalUtils.js → solautoUtils.js} +48 -173
- package/dist/utils/switchboardUtils.d.ts +1 -1
- package/dist/utils/switchboardUtils.d.ts.map +1 -1
- package/dist/utils/switchboardUtils.js +10 -9
- package/local/createTokenAccounts.ts +1 -5
- package/local/logPositions.ts +22 -68
- package/local/shared.ts +29 -24
- package/local/txSandbox.ts +27 -0
- package/local/updateMarginfiLUT.ts +80 -4
- package/package.json +4 -7
- package/src/constants/solautoConstants.ts +4 -9
- package/src/constants/switchboardConstants.ts +10 -5
- package/src/generated/accounts/solautoPosition.ts +2 -2
- package/src/generated/errors/solauto.ts +45 -4
- package/src/generated/instructions/claimReferralFees.ts +1 -1
- package/src/generated/instructions/closePosition.ts +3 -3
- package/src/generated/instructions/marginfiOpenPosition.ts +0 -7
- package/src/generated/instructions/marginfiRebalance.ts +12 -3
- package/src/generated/types/index.ts +7 -1
- package/src/generated/types/positionData.ts +3 -3
- package/src/generated/types/positionState.ts +12 -12
- package/src/generated/types/{positionTokenUsage.ts → positionTokenState.ts} +13 -16
- package/src/generated/types/rebalanceData.ts +16 -27
- package/src/generated/types/rebalanceDirection.ts +1 -0
- package/src/generated/types/rebalanceInstructionData.ts +62 -0
- package/src/generated/types/rebalanceStateValues.ts +59 -0
- package/src/generated/types/rebalanceStep.ts +25 -0
- package/src/generated/types/solautoRebalanceType.ts +0 -1
- package/src/generated/types/solautoSettingsParameters.ts +4 -25
- package/src/generated/types/solautoSettingsParametersInp.ts +2 -24
- package/src/generated/types/swapType.ts +22 -0
- package/src/generated/types/tokenBalanceChange.ts +46 -0
- package/src/generated/types/tokenBalanceChangeType.ts +28 -0
- package/src/generated/types/updatePositionData.ts +3 -3
- package/src/index.ts +8 -8
- package/src/marginfi-sdk/types/interestRateConfig.ts +6 -2
- package/src/services/flashLoans/flProviderAggregator.ts +74 -0
- package/src/services/flashLoans/flProviderBase.ts +88 -0
- package/src/services/flashLoans/index.ts +3 -0
- package/src/services/flashLoans/marginfiFlProvider.ts +392 -0
- package/src/services/index.ts +5 -0
- package/src/services/rebalance/index.ts +2 -0
- package/src/services/rebalance/rebalanceSwapManager.ts +218 -0
- package/src/services/rebalance/rebalanceTxBuilder.ts +330 -0
- package/src/services/rebalance/rebalanceValues.ts +232 -0
- package/src/services/rebalance/solautoFees.ts +61 -0
- package/src/services/solauto/index.ts +4 -0
- package/src/{clients → services/solauto}/referralStateManager.ts +17 -31
- package/src/{clients → services/solauto}/solautoClient.ts +142 -205
- package/src/services/solauto/solautoMarginfiClient.ts +472 -0
- package/src/services/solauto/txHandler.ts +69 -0
- package/src/services/swap/index.ts +1 -0
- package/src/services/swap/jupSwapManager.ts +189 -0
- package/src/{transactions → services/transactions}/transactionUtils.ts +40 -280
- package/src/{transactions → services/transactions}/transactionsManager.ts +15 -10
- package/src/solautoPosition/index.ts +3 -0
- package/src/solautoPosition/marginfiSolautoPositionEx.ts +111 -0
- package/src/solautoPosition/solautoPositionEx.ts +281 -0
- package/src/solautoPosition/utils.ts +188 -0
- package/src/types/solauto.ts +30 -2
- package/src/utils/generalUtils.ts +9 -1
- package/src/utils/index.ts +2 -2
- package/src/utils/jitoUtils.ts +0 -4
- package/src/utils/jupiterUtils.ts +3 -164
- package/src/utils/marginfiUtils.ts +77 -43
- package/src/utils/numberUtils.ts +18 -77
- package/src/utils/solanaUtils.ts +1 -1
- package/src/utils/{solauto/generalUtils.ts → solautoUtils.ts} +66 -288
- package/src/utils/switchboardUtils.ts +15 -17
- package/tests/transactions/shared.ts +135 -0
- package/tests/transactions/solautoMarginfi.ts +8 -198
- package/tests/unit/accounts.ts +3 -10
- package/tests/unit/lookupTables.ts +23 -2
- package/tests/unit/rebalanceCalculations.ts +65 -343
- package/dist/clients/index.d.ts +0 -5
- package/dist/clients/index.d.ts.map +0 -1
- package/dist/clients/referralStateManager.d.ts.map +0 -1
- package/dist/clients/solautoClient.d.ts +0 -71
- package/dist/clients/solautoClient.d.ts.map +0 -1
- package/dist/clients/solautoMarginfiClient.d.ts +0 -51
- package/dist/clients/solautoMarginfiClient.d.ts.map +0 -1
- package/dist/clients/solautoMarginfiClient.js +0 -497
- package/dist/clients/txHandler.d.ts.map +0 -1
- package/dist/clients/txHandler.js +0 -23
- package/dist/generated/types/positionTokenUsage.d.ts.map +0 -1
- package/dist/transactions/index.d.ts.map +0 -1
- package/dist/transactions/transactionUtils.d.ts.map +0 -1
- package/dist/transactions/transactionsManager.d.ts.map +0 -1
- package/dist/utils/solauto/generalUtils.d.ts.map +0 -1
- package/dist/utils/solauto/index.d.ts +0 -3
- package/dist/utils/solauto/index.d.ts.map +0 -1
- package/dist/utils/solauto/rebalanceUtils.d.ts +0 -30
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +0 -1
- package/dist/utils/solauto/rebalanceUtils.js +0 -287
- package/src/clients/index.ts +0 -4
- package/src/clients/solautoMarginfiClient.ts +0 -774
- package/src/clients/txHandler.ts +0 -38
- package/src/utils/solauto/index.ts +0 -2
- package/src/utils/solauto/rebalanceUtils.ts +0 -562
- package/dist/{clients → services/solauto}/index.js +2 -2
- /package/dist/{transactions → services/transactions}/index.d.ts +0 -0
- /package/dist/{transactions → services/transactions}/index.js +0 -0
- /package/src/{transactions → services/transactions}/index.ts +0 -0
@@ -1,7 +1,11 @@
|
|
1
1
|
import "rpc-websockets/dist/lib/client";
|
2
|
-
import { AddressLookupTableProgram, PublicKey } from "@solana/web3.js";
|
3
2
|
import {
|
4
|
-
|
3
|
+
AddressLookupTableProgram,
|
4
|
+
PublicKey,
|
5
|
+
RpcResponseAndContext,
|
6
|
+
TokenAmount,
|
7
|
+
} from "@solana/web3.js";
|
8
|
+
import {
|
5
9
|
TransactionBuilder,
|
6
10
|
isOption,
|
7
11
|
publicKey,
|
@@ -11,74 +15,59 @@ import {
|
|
11
15
|
} from "@metaplex-foundation/umi";
|
12
16
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
13
17
|
import {
|
14
|
-
DCASettings,
|
15
18
|
DCASettingsInpArgs,
|
16
19
|
LendingPlatform,
|
17
|
-
|
20
|
+
RebalanceStep,
|
18
21
|
SolautoActionArgs,
|
19
|
-
SolautoPosition,
|
20
|
-
SolautoRebalanceType,
|
21
|
-
SolautoRebalanceTypeArgs,
|
22
|
-
SolautoSettingsParameters,
|
23
22
|
SolautoSettingsParametersInpArgs,
|
24
23
|
TokenType,
|
25
24
|
UpdatePositionDataArgs,
|
26
25
|
cancelDCA,
|
27
|
-
closePosition,
|
28
|
-
safeFetchSolautoPosition,
|
29
26
|
updatePosition,
|
30
|
-
} from "
|
27
|
+
} from "../../generated";
|
31
28
|
import {
|
32
29
|
getSolautoPositionAccount,
|
33
30
|
getTokenAccount,
|
34
|
-
} from "
|
35
|
-
import { SOLAUTO_FEES_WALLET } from "
|
31
|
+
} from "../../utils/accountUtils";
|
32
|
+
import { SOLAUTO_FEES_WALLET } from "../../constants/generalAccounts";
|
36
33
|
import {
|
37
34
|
getWrappedInstruction,
|
38
35
|
splTokenTransferUmiIx,
|
39
|
-
} from "
|
40
|
-
import {
|
41
|
-
|
42
|
-
RebalanceValues,
|
43
|
-
} from "../utils/solauto/rebalanceUtils";
|
44
|
-
import {
|
45
|
-
MIN_POSITION_STATE_FRESHNESS_SECS,
|
46
|
-
SOLAUTO_LUT,
|
47
|
-
} from "../constants/solautoConstants";
|
48
|
-
import { currentUnixSeconds } from "../utils/generalUtils";
|
49
|
-
import { ContextUpdates } from "../utils/solauto/generalUtils";
|
36
|
+
} from "../../utils/solanaUtils";
|
37
|
+
import { SOLAUTO_LUT } from "../../constants/solautoConstants";
|
38
|
+
import { ContextUpdates } from "../../utils/solautoUtils";
|
50
39
|
import {
|
51
40
|
ReferralStateManager,
|
52
41
|
ReferralStateManagerArgs,
|
53
42
|
} from "./referralStateManager";
|
54
|
-
import {
|
43
|
+
import {
|
44
|
+
getOrCreatePositionEx,
|
45
|
+
SolautoPositionEx,
|
46
|
+
} from "../../solautoPosition";
|
47
|
+
import { RebalanceDetails } from "../../types";
|
48
|
+
import { FlProviderAggregator } from "../flashLoans/flProviderAggregator";
|
55
49
|
|
56
50
|
export interface SolautoClientArgs extends ReferralStateManagerArgs {
|
57
51
|
new?: boolean;
|
58
52
|
positionId?: number;
|
59
53
|
supplyMint?: PublicKey;
|
60
54
|
debtMint?: PublicKey;
|
55
|
+
lendingPool?: PublicKey;
|
56
|
+
lpUserAccount?: PublicKey;
|
61
57
|
}
|
62
58
|
|
63
59
|
export abstract class SolautoClient extends ReferralStateManager {
|
64
|
-
public lendingPlatform
|
60
|
+
public lendingPlatform!: LendingPlatform;
|
65
61
|
|
66
62
|
public authority!: PublicKey;
|
67
63
|
|
68
64
|
public positionId!: number;
|
69
65
|
public selfManaged!: boolean;
|
70
|
-
public solautoPosition!:
|
71
|
-
public solautoPositionData!: SolautoPosition | null;
|
72
|
-
public solautoPositionState!: PositionState | undefined;
|
66
|
+
public solautoPosition!: SolautoPositionEx;
|
73
67
|
|
74
|
-
public maxLtvBps?: number;
|
75
|
-
public liqThresholdBps?: number;
|
76
|
-
|
77
|
-
public supplyMint!: PublicKey;
|
78
68
|
public positionSupplyTa!: PublicKey;
|
79
69
|
public signerSupplyTa!: PublicKey;
|
80
70
|
|
81
|
-
public debtMint!: PublicKey;
|
82
71
|
public positionDebtTa!: PublicKey;
|
83
72
|
public signerDebtTa!: PublicKey;
|
84
73
|
|
@@ -87,6 +76,7 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
87
76
|
|
88
77
|
public authorityLutAddress?: PublicKey;
|
89
78
|
|
79
|
+
public flProvider!: FlProviderAggregator;
|
90
80
|
public contextUpdates: ContextUpdates = new ContextUpdates();
|
91
81
|
|
92
82
|
private signerSupplyBalance: bigint | undefined;
|
@@ -97,55 +87,55 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
97
87
|
|
98
88
|
this.positionId = args.positionId ?? 0;
|
99
89
|
this.selfManaged = this.positionId === 0;
|
100
|
-
|
90
|
+
if (
|
91
|
+
this.selfManaged &&
|
92
|
+
(!args.supplyMint || !args.debtMint || !args.lpUserAccount)
|
93
|
+
) {
|
94
|
+
throw new Error("Self managed position is missing arguments");
|
95
|
+
}
|
96
|
+
|
97
|
+
const positionPk = getSolautoPositionAccount(
|
101
98
|
this.authority,
|
102
99
|
this.positionId,
|
103
100
|
this.programId
|
104
101
|
);
|
105
|
-
this.
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
102
|
+
this.solautoPosition = await getOrCreatePositionEx(
|
103
|
+
this.umi,
|
104
|
+
positionPk,
|
105
|
+
{
|
106
|
+
supplyMint: args.supplyMint,
|
107
|
+
debtMint: args.debtMint,
|
108
|
+
lpUserAccount: args.lpUserAccount,
|
109
|
+
lendingPlatform: this.lendingPlatform,
|
110
|
+
},
|
111
|
+
this.contextUpdates
|
112
|
+
);
|
116
113
|
|
117
|
-
this.supplyMint =
|
118
|
-
args.supplyMint ??
|
119
|
-
(this.solautoPositionData && !this.selfManaged
|
120
|
-
? toWeb3JsPublicKey(this.solautoPositionData!.state.supply.mint)
|
121
|
-
: PublicKey.default);
|
122
114
|
this.positionSupplyTa = getTokenAccount(
|
123
|
-
this.solautoPosition,
|
124
|
-
this.supplyMint
|
115
|
+
this.solautoPosition.publicKey,
|
116
|
+
this.solautoPosition.supplyMint()
|
125
117
|
);
|
126
118
|
this.signerSupplyTa = getTokenAccount(
|
127
119
|
toWeb3JsPublicKey(this.signer.publicKey),
|
128
|
-
this.supplyMint
|
120
|
+
this.solautoPosition.supplyMint()
|
129
121
|
);
|
130
122
|
|
131
|
-
this.
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
: PublicKey.default);
|
136
|
-
this.positionDebtTa = getTokenAccount(this.solautoPosition, this.debtMint);
|
123
|
+
this.positionDebtTa = getTokenAccount(
|
124
|
+
this.solautoPosition.publicKey,
|
125
|
+
this.solautoPosition.debtMint()
|
126
|
+
);
|
137
127
|
this.signerDebtTa = getTokenAccount(
|
138
128
|
toWeb3JsPublicKey(this.signer.publicKey),
|
139
|
-
this.debtMint
|
129
|
+
this.solautoPosition.debtMint()
|
140
130
|
);
|
141
131
|
|
142
132
|
this.solautoFeesSupplyTa = getTokenAccount(
|
143
133
|
SOLAUTO_FEES_WALLET,
|
144
|
-
this.supplyMint
|
134
|
+
this.solautoPosition.supplyMint()
|
145
135
|
);
|
146
136
|
this.solautoFeesDebtTa = getTokenAccount(
|
147
137
|
SOLAUTO_FEES_WALLET,
|
148
|
-
this.debtMint
|
138
|
+
this.solautoPosition.debtMint()
|
149
139
|
);
|
150
140
|
|
151
141
|
this.authorityLutAddress =
|
@@ -156,59 +146,59 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
156
146
|
? toWeb3JsPublicKey(this.referralStateData.lookupTable)
|
157
147
|
: undefined;
|
158
148
|
|
159
|
-
this.
|
160
|
-
|
161
|
-
|
162
|
-
this.
|
163
|
-
|
164
|
-
this.log(
|
165
|
-
"Position DCA: ",
|
166
|
-
(this.solautoPositionData?.position?.dca?.automation?.targetPeriods ??
|
167
|
-
0) > 0
|
168
|
-
? this.solautoPositionData?.position?.dca
|
169
|
-
: undefined
|
149
|
+
this.flProvider = new FlProviderAggregator(
|
150
|
+
this.umi,
|
151
|
+
this.signer,
|
152
|
+
this.solautoPosition.supplyMint(),
|
153
|
+
this.solautoPosition.debtMint()
|
170
154
|
);
|
155
|
+
await this.flProvider.initialize();
|
156
|
+
this.otherSigners.push(...this.flProvider.otherSigners());
|
157
|
+
|
158
|
+
this.log("Position state: ", this.solautoPosition.state());
|
159
|
+
this.log("Position settings: ", this.solautoPosition.settings());
|
160
|
+
this.log("Position DCA: ", this.solautoPosition.dca());
|
171
161
|
}
|
172
162
|
|
173
163
|
referredBySupplyTa(): PublicKey | undefined {
|
174
164
|
if (this.referredByState !== undefined) {
|
175
|
-
return getTokenAccount(
|
165
|
+
return getTokenAccount(
|
166
|
+
this.referredByState,
|
167
|
+
this.solautoPosition.supplyMint()
|
168
|
+
);
|
176
169
|
}
|
177
170
|
return undefined;
|
178
171
|
}
|
179
172
|
|
180
173
|
referredByDebtTa(): PublicKey | undefined {
|
181
174
|
if (this.referredByState !== undefined) {
|
182
|
-
return getTokenAccount(
|
175
|
+
return getTokenAccount(
|
176
|
+
this.referredByState,
|
177
|
+
this.solautoPosition.debtMint()
|
178
|
+
);
|
183
179
|
}
|
184
180
|
return undefined;
|
185
181
|
}
|
186
182
|
|
187
183
|
async resetLiveTxUpdates(success?: boolean) {
|
184
|
+
this.log("Resetting context updates...");
|
188
185
|
if (success) {
|
189
|
-
if (!this.
|
190
|
-
this.
|
191
|
-
this.umi,
|
192
|
-
publicKey(this.solautoPosition),
|
193
|
-
{ commitment: "confirmed" }
|
194
|
-
);
|
186
|
+
if (!this.solautoPosition.exists()) {
|
187
|
+
await this.solautoPosition.refetchPositionData();
|
195
188
|
} else {
|
196
|
-
if (this.contextUpdates.activeDca) {
|
197
|
-
this.solautoPositionData.position.dca =
|
198
|
-
this.contextUpdates.activeDca;
|
199
|
-
}
|
200
189
|
if (this.contextUpdates.settings) {
|
201
|
-
this.
|
190
|
+
this.solautoPosition.data().position!.settings =
|
202
191
|
this.contextUpdates.settings;
|
203
192
|
}
|
193
|
+
if (this.contextUpdates.dca) {
|
194
|
+
this.solautoPosition.data().position!.dca = this.contextUpdates.dca;
|
195
|
+
}
|
204
196
|
// All other live position updates can be derived by getting a fresh position state, so we don't need to do anything else form contextUpdates
|
205
197
|
}
|
206
198
|
}
|
207
199
|
this.contextUpdates.reset();
|
208
200
|
}
|
209
201
|
|
210
|
-
abstract protocolAccount(): PublicKey;
|
211
|
-
|
212
202
|
defaultLookupTables(): string[] {
|
213
203
|
return [
|
214
204
|
SOLAUTO_LUT,
|
@@ -227,12 +217,13 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
227
217
|
...(toWeb3JsPublicKey(this.signer.publicKey).equals(this.authority)
|
228
218
|
? [this.signerDebtTa]
|
229
219
|
: []),
|
230
|
-
this.solautoPosition,
|
220
|
+
this.solautoPosition.publicKey,
|
231
221
|
this.positionSupplyTa,
|
232
222
|
this.positionDebtTa,
|
233
223
|
this.referralState,
|
234
224
|
...(this.referredBySupplyTa() ? [this.referredBySupplyTa()!] : []),
|
235
225
|
...(this.referredByDebtTa() ? [this.referredByDebtTa()!] : []),
|
226
|
+
...this.flProvider.lutAccountsToAdd(),
|
236
227
|
];
|
237
228
|
}
|
238
229
|
|
@@ -254,10 +245,6 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
254
245
|
}
|
255
246
|
| undefined
|
256
247
|
> {
|
257
|
-
if (this.selfManaged) {
|
258
|
-
return undefined;
|
259
|
-
}
|
260
|
-
|
261
248
|
const existingLutAccounts = await this.fetchExistingAuthorityLutAccounts();
|
262
249
|
if (
|
263
250
|
this.lutAccountsToAdd().every((element) =>
|
@@ -279,7 +266,9 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
279
266
|
recentSlot: await this.umi.rpc.getSlot({ commitment: "finalized" }),
|
280
267
|
});
|
281
268
|
this.authorityLutAddress = lookupTableAddress;
|
282
|
-
tx = tx
|
269
|
+
tx = tx
|
270
|
+
.add(getWrappedInstruction(this.signer, createLookupTableInst))
|
271
|
+
.add(this.updateReferralStatesIx(undefined, this.authorityLutAddress));
|
283
272
|
}
|
284
273
|
|
285
274
|
const accountsToAdd: PublicKey[] = this.lutAccountsToAdd().filter(
|
@@ -292,17 +281,19 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
292
281
|
return undefined;
|
293
282
|
}
|
294
283
|
|
295
|
-
tx = tx
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
284
|
+
tx = tx
|
285
|
+
.add(
|
286
|
+
getWrappedInstruction(
|
287
|
+
this.signer,
|
288
|
+
AddressLookupTableProgram.extendLookupTable({
|
289
|
+
payer: toWeb3JsPublicKey(this.signer.publicKey),
|
290
|
+
authority: this.authority,
|
291
|
+
lookupTable: this.authorityLutAddress,
|
292
|
+
addresses: accountsToAdd,
|
293
|
+
})
|
294
|
+
)
|
304
295
|
)
|
305
|
-
|
296
|
+
.add(await this.flProvider.flAccountPrereqIxs());
|
306
297
|
|
307
298
|
this.log("Requires authority LUT update...");
|
308
299
|
return {
|
@@ -328,23 +319,29 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
328
319
|
|
329
320
|
[this.signerSupplyBalance, this.signerDebtBalance] = await Promise.all([
|
330
321
|
(async () => {
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
322
|
+
let data: RpcResponseAndContext<TokenAmount> | undefined;
|
323
|
+
try {
|
324
|
+
data = await this.connection.getTokenAccountBalance(
|
325
|
+
getTokenAccount(
|
326
|
+
toWeb3JsPublicKey(this.signer.publicKey),
|
327
|
+
this.solautoPosition.supplyMint()
|
328
|
+
),
|
329
|
+
"confirmed"
|
330
|
+
);
|
331
|
+
} catch {}
|
338
332
|
return BigInt(parseInt(data?.value.amount ?? "0"));
|
339
333
|
})(),
|
340
334
|
(async () => {
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
335
|
+
let data: RpcResponseAndContext<TokenAmount> | undefined;
|
336
|
+
try {
|
337
|
+
const data = await this.connection.getTokenAccountBalance(
|
338
|
+
getTokenAccount(
|
339
|
+
toWeb3JsPublicKey(this.signer.publicKey),
|
340
|
+
this.solautoPosition.debtMint()
|
341
|
+
),
|
342
|
+
"confirmed"
|
343
|
+
);
|
344
|
+
} catch {}
|
348
345
|
return BigInt(parseInt(data?.value.amount ?? "0"));
|
349
346
|
})(),
|
350
347
|
]);
|
@@ -355,29 +352,8 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
355
352
|
};
|
356
353
|
}
|
357
354
|
|
358
|
-
|
359
|
-
|
360
|
-
this.contextUpdates.settings ??
|
361
|
-
this.solautoPositionData?.position.settingParams
|
362
|
-
);
|
363
|
-
}
|
364
|
-
|
365
|
-
solautoPositionActiveDca(): DCASettings | undefined {
|
366
|
-
return (
|
367
|
-
this.contextUpdates.activeDca ??
|
368
|
-
this.solautoPositionData?.position.dca
|
369
|
-
);
|
370
|
-
}
|
371
|
-
|
372
|
-
async maxLtvAndLiqThresholdBps(): Promise<[number, number]> {
|
373
|
-
if (this.maxLtvBps !== undefined && this.liqThresholdBps !== undefined) {
|
374
|
-
return [this.maxLtvBps, this.liqThresholdBps];
|
375
|
-
}
|
376
|
-
return [0, 0];
|
377
|
-
}
|
378
|
-
|
379
|
-
openPosition(
|
380
|
-
settingParams?: SolautoSettingsParametersInpArgs,
|
355
|
+
openPositionIx(
|
356
|
+
settings?: SolautoSettingsParametersInpArgs,
|
381
357
|
dca?: DCASettingsInpArgs
|
382
358
|
): TransactionBuilder {
|
383
359
|
if (dca && dca.dcaInBaseUnit > 0) {
|
@@ -389,10 +365,10 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
389
365
|
},
|
390
366
|
});
|
391
367
|
}
|
392
|
-
if (
|
368
|
+
if (settings) {
|
393
369
|
this.contextUpdates.new({
|
394
370
|
type: "settings",
|
395
|
-
value:
|
371
|
+
value: settings,
|
396
372
|
});
|
397
373
|
}
|
398
374
|
if (dca) {
|
@@ -411,11 +387,11 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
411
387
|
let signerDcaTa: UmiPublicKey | undefined = undefined;
|
412
388
|
if (isOption(args.dca) && isSome(args.dca)) {
|
413
389
|
if (args.dca.value.tokenType === TokenType.Supply) {
|
414
|
-
dcaMint = publicKey(this.supplyMint);
|
390
|
+
dcaMint = publicKey(this.solautoPosition.supplyMint());
|
415
391
|
positionDcaTa = publicKey(this.positionSupplyTa);
|
416
392
|
signerDcaTa = publicKey(this.signerSupplyTa);
|
417
393
|
} else {
|
418
|
-
dcaMint = publicKey(this.debtMint);
|
394
|
+
dcaMint = publicKey(this.solautoPosition.debtMint());
|
419
395
|
positionDcaTa = publicKey(this.positionDebtTa);
|
420
396
|
signerDcaTa = publicKey(this.signerDebtTa);
|
421
397
|
}
|
@@ -435,10 +411,10 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
435
411
|
}
|
436
412
|
}
|
437
413
|
|
438
|
-
if (isOption(args.
|
414
|
+
if (isOption(args.settings) && isSome(args.settings)) {
|
439
415
|
this.contextUpdates.new({
|
440
416
|
type: "settings",
|
441
|
-
value: args.
|
417
|
+
value: args.settings.value,
|
442
418
|
});
|
443
419
|
}
|
444
420
|
|
@@ -451,7 +427,7 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
451
427
|
|
452
428
|
return updatePosition(this.umi, {
|
453
429
|
signer: this.signer,
|
454
|
-
solautoPosition: publicKey(this.solautoPosition),
|
430
|
+
solautoPosition: publicKey(this.solautoPosition.publicKey),
|
455
431
|
dcaMint,
|
456
432
|
positionDcaTa,
|
457
433
|
signerDcaTa,
|
@@ -459,53 +435,43 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
459
435
|
});
|
460
436
|
}
|
461
437
|
|
462
|
-
closePositionIx(): TransactionBuilder
|
463
|
-
return closePosition(this.umi, {
|
464
|
-
signer: this.signer,
|
465
|
-
solautoPosition: publicKey(this.solautoPosition),
|
466
|
-
signerSupplyTa: publicKey(this.signerSupplyTa),
|
467
|
-
positionSupplyTa: publicKey(this.positionSupplyTa),
|
468
|
-
positionDebtTa: publicKey(this.positionDebtTa),
|
469
|
-
signerDebtTa: publicKey(this.signerDebtTa),
|
470
|
-
protocolAccount: publicKey(this.protocolAccount()),
|
471
|
-
});
|
472
|
-
}
|
438
|
+
abstract closePositionIx(): TransactionBuilder;
|
473
439
|
|
474
440
|
cancelDCAIx(): TransactionBuilder {
|
475
441
|
let dcaMint: UmiPublicKey | undefined = undefined;
|
476
442
|
let positionDcaTa: UmiPublicKey | undefined = undefined;
|
477
443
|
let signerDcaTa: UmiPublicKey | undefined = undefined;
|
478
444
|
|
479
|
-
const currDca = this.
|
445
|
+
const currDca = this.solautoPosition.dca()!;
|
480
446
|
if (currDca.dcaInBaseUnit > 0) {
|
481
447
|
if (currDca.tokenType === TokenType.Supply) {
|
482
|
-
dcaMint = publicKey(this.supplyMint);
|
448
|
+
dcaMint = publicKey(this.solautoPosition.supplyMint());
|
483
449
|
positionDcaTa = publicKey(this.positionSupplyTa);
|
484
450
|
signerDcaTa = publicKey(this.signerSupplyTa);
|
485
451
|
} else {
|
486
|
-
dcaMint = publicKey(this.debtMint);
|
452
|
+
dcaMint = publicKey(this.solautoPosition.debtMint());
|
487
453
|
positionDcaTa = publicKey(this.positionDebtTa);
|
488
454
|
signerDcaTa = publicKey(this.signerDebtTa);
|
489
455
|
}
|
490
456
|
|
491
457
|
this.contextUpdates.new({
|
492
458
|
type: "cancellingDca",
|
493
|
-
value: this.
|
459
|
+
value: this.solautoPosition.dca()!.tokenType,
|
494
460
|
});
|
495
461
|
}
|
496
462
|
|
497
463
|
return cancelDCA(this.umi, {
|
498
464
|
signer: this.signer,
|
499
|
-
solautoPosition: publicKey(this.solautoPosition),
|
465
|
+
solautoPosition: publicKey(this.solautoPosition.publicKey),
|
500
466
|
dcaMint,
|
501
467
|
positionDcaTa,
|
502
468
|
signerDcaTa,
|
503
469
|
});
|
504
470
|
}
|
505
471
|
|
506
|
-
abstract
|
472
|
+
abstract refreshIx(): TransactionBuilder;
|
507
473
|
|
508
|
-
|
474
|
+
protocolInteractionIx(args: SolautoActionArgs): TransactionBuilder {
|
509
475
|
let tx = transactionBuilder();
|
510
476
|
|
511
477
|
if (!this.selfManaged) {
|
@@ -539,8 +505,9 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
539
505
|
toWeb3JsPublicKey(this.signer.publicKey),
|
540
506
|
BigInt(
|
541
507
|
Math.round(
|
542
|
-
Number(
|
543
|
-
|
508
|
+
Number(
|
509
|
+
this.solautoPosition.state().debt.amountUsed.baseUnit
|
510
|
+
) * 1.01
|
544
511
|
)
|
545
512
|
)
|
546
513
|
)
|
@@ -564,7 +531,7 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
564
531
|
this.contextUpdates.new({
|
565
532
|
type: "supply",
|
566
533
|
value:
|
567
|
-
(this.
|
534
|
+
(this.solautoPosition.state().supply.amountUsed.baseUnit ??
|
568
535
|
BigInt(0)) * BigInt(-1),
|
569
536
|
});
|
570
537
|
}
|
@@ -583,8 +550,8 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
583
550
|
this.contextUpdates.new({
|
584
551
|
type: "debt",
|
585
552
|
value:
|
586
|
-
(this.
|
587
|
-
|
553
|
+
(this.solautoPosition.state().debt.amountUsed.baseUnit ??
|
554
|
+
BigInt(0)) * BigInt(-1),
|
588
555
|
});
|
589
556
|
}
|
590
557
|
}
|
@@ -592,38 +559,8 @@ export abstract class SolautoClient extends ReferralStateManager {
|
|
592
559
|
return tx;
|
593
560
|
}
|
594
561
|
|
595
|
-
abstract
|
596
|
-
|
597
|
-
|
598
|
-
destinationTokenAccount: PublicKey
|
562
|
+
abstract rebalanceIx(
|
563
|
+
rebalanceStep: RebalanceStep,
|
564
|
+
data: RebalanceDetails
|
599
565
|
): TransactionBuilder;
|
600
|
-
|
601
|
-
abstract flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder;
|
602
|
-
|
603
|
-
abstract rebalance(
|
604
|
-
rebalanceStep: "A" | "B",
|
605
|
-
jupQuote: QuoteResponse,
|
606
|
-
rebalanceType: SolautoRebalanceTypeArgs,
|
607
|
-
rebalanceValues: RebalanceValues,
|
608
|
-
flashLoan?: FlashLoanDetails,
|
609
|
-
targetLiqUtilizationRateBps?: number
|
610
|
-
): TransactionBuilder;
|
611
|
-
|
612
|
-
async getFreshPositionState(): Promise<PositionState | undefined> {
|
613
|
-
if (
|
614
|
-
Boolean(this.solautoPositionData) &&
|
615
|
-
Boolean(this.solautoPositionState) &&
|
616
|
-
Number(this.solautoPositionState!.lastUpdated) >
|
617
|
-
currentUnixSeconds() - MIN_POSITION_STATE_FRESHNESS_SECS &&
|
618
|
-
!this.contextUpdates.positionUpdates()
|
619
|
-
) {
|
620
|
-
return this.solautoPositionState;
|
621
|
-
}
|
622
|
-
|
623
|
-
return undefined;
|
624
|
-
}
|
625
|
-
|
626
|
-
abstract supplyLiquidityAvailable(): bigint;
|
627
|
-
abstract supplyLiquidityDepositable(): bigint;
|
628
|
-
abstract debtLiquidityAvailable(): bigint;
|
629
566
|
}
|