@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
@@ -0,0 +1,17 @@
|
|
1
|
+
import { Umi } from "@metaplex-foundation/umi";
|
2
|
+
import { PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs } from "../generated";
|
3
|
+
import { PublicKey } from "@solana/web3.js";
|
4
|
+
import { PositionCustomArgs, SolautoPositionEx } from "./solautoPositionEx";
|
5
|
+
import { ContextUpdates } from "../utils";
|
6
|
+
export declare function createSolautoSettings(settings: SolautoSettingsParametersInpArgs): SolautoSettingsParameters;
|
7
|
+
export declare function getPositionExBulk(umi: Umi, publicKeys: PublicKey[]): Promise<SolautoPositionEx[]>;
|
8
|
+
export declare function getOrCreatePositionEx(umi: Umi, publicKey: PublicKey, customArgs?: PositionCustomArgs, contextUpdates?: ContextUpdates): Promise<SolautoPositionEx>;
|
9
|
+
interface AssetProps {
|
10
|
+
mint: PublicKey;
|
11
|
+
price?: number;
|
12
|
+
amountUsed?: number;
|
13
|
+
amountCanBeUsed?: number;
|
14
|
+
}
|
15
|
+
export declare function createFakePositionState(supply: AssetProps, debt: AssetProps, maxLtvBps: number, liqThresholdBps: number): PositionState;
|
16
|
+
export {};
|
17
|
+
//# sourceMappingURL=utils.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/solautoPosition/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAEL,aAAa,EAGb,yBAAyB,EACzB,gCAAgC,EACjC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAM5E,OAAO,EACL,cAAc,EAOf,MAAM,UAAU,CAAC;AAGlB,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"}
|
@@ -0,0 +1,115 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createSolautoSettings = createSolautoSettings;
|
4
|
+
exports.getPositionExBulk = getPositionExBulk;
|
5
|
+
exports.getOrCreatePositionEx = getOrCreatePositionEx;
|
6
|
+
exports.createFakePositionState = createFakePositionState;
|
7
|
+
const generated_1 = require("../generated");
|
8
|
+
const web3_js_1 = require("@solana/web3.js");
|
9
|
+
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
10
|
+
const marginfiSolautoPositionEx_1 = require("./marginfiSolautoPositionEx");
|
11
|
+
const utils_1 = require("../utils");
|
12
|
+
const constants_1 = require("../constants");
|
13
|
+
function createSolautoSettings(settings) {
|
14
|
+
return {
|
15
|
+
boostGap: settings.boostGap,
|
16
|
+
boostToBps: settings.boostToBps,
|
17
|
+
repayGap: settings.repayGap,
|
18
|
+
repayToBps: settings.repayToBps,
|
19
|
+
padding: [],
|
20
|
+
};
|
21
|
+
}
|
22
|
+
async function getPositionExBulk(umi, publicKeys) {
|
23
|
+
const batches = (0, utils_1.getBatches)(publicKeys, 30);
|
24
|
+
const data = (await Promise.all(batches.map(async (pubkeys) => {
|
25
|
+
return (0, utils_1.retryWithExponentialBackoff)(async () => await (0, generated_1.safeFetchAllSolautoPosition)(umi, pubkeys.map((x) => (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(x))));
|
26
|
+
}))).flat();
|
27
|
+
return data.map((x) => {
|
28
|
+
switch (x.position.lendingPlatform) {
|
29
|
+
case generated_1.LendingPlatform.Marginfi:
|
30
|
+
return new marginfiSolautoPositionEx_1.MarginfiSolautoPositionEx({
|
31
|
+
umi,
|
32
|
+
publicKey: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey),
|
33
|
+
data: x,
|
34
|
+
});
|
35
|
+
// TODO: PF
|
36
|
+
}
|
37
|
+
});
|
38
|
+
}
|
39
|
+
async function getOrCreatePositionEx(umi, publicKey, customArgs, contextUpdates) {
|
40
|
+
const data = await (0, generated_1.safeFetchSolautoPosition)(umi, (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(publicKey));
|
41
|
+
const placeholderState = createFakePositionState({
|
42
|
+
mint: customArgs?.supplyMint ?? web3_js_1.PublicKey.default,
|
43
|
+
}, { mint: customArgs?.debtMint ?? web3_js_1.PublicKey.default }, 0, 0);
|
44
|
+
const lendingPlatform = data
|
45
|
+
? data.position.lendingPlatform
|
46
|
+
: customArgs.lendingPlatform;
|
47
|
+
switch (lendingPlatform) {
|
48
|
+
case generated_1.LendingPlatform.Marginfi:
|
49
|
+
return new marginfiSolautoPositionEx_1.MarginfiSolautoPositionEx({
|
50
|
+
umi,
|
51
|
+
publicKey,
|
52
|
+
data: data ?? {
|
53
|
+
state: placeholderState,
|
54
|
+
},
|
55
|
+
customArgs,
|
56
|
+
contextUpdates,
|
57
|
+
});
|
58
|
+
// TODO: PF
|
59
|
+
}
|
60
|
+
}
|
61
|
+
function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
|
62
|
+
const supplyDecimals = constants_1.TOKEN_INFO[supply.mint.toString()].decimals;
|
63
|
+
const debtDecimals = constants_1.TOKEN_INFO[debt.mint.toString()].decimals;
|
64
|
+
const supplyUsd = (supply.amountUsed ?? 0) * (supply.price ?? 0);
|
65
|
+
const debtUsd = (debt.amountUsed ?? 0) * (debt.price ?? 0);
|
66
|
+
return {
|
67
|
+
liqUtilizationRateBps: (0, utils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, liqThresholdBps),
|
68
|
+
supply: {
|
69
|
+
amountUsed: {
|
70
|
+
baseUnit: (0, utils_1.toBaseUnit)(supply.amountUsed ?? 0, supplyDecimals),
|
71
|
+
baseAmountUsdValue: (0, utils_1.toRoundedUsdValue)(supplyUsd),
|
72
|
+
},
|
73
|
+
amountCanBeUsed: {
|
74
|
+
baseUnit: (0, utils_1.toBaseUnit)(supply.amountCanBeUsed ?? 0, supplyDecimals),
|
75
|
+
baseAmountUsdValue: (0, utils_1.toRoundedUsdValue)((supply.amountCanBeUsed ?? 0) * (supply.price ?? 0)),
|
76
|
+
},
|
77
|
+
baseAmountMarketPriceUsd: (0, utils_1.toRoundedUsdValue)(supply.price ?? 0),
|
78
|
+
borrowFeeBps: 0,
|
79
|
+
decimals: supplyDecimals,
|
80
|
+
mint: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(supply.mint),
|
81
|
+
padding1: [],
|
82
|
+
padding2: [],
|
83
|
+
padding: new Uint8Array([]),
|
84
|
+
},
|
85
|
+
debt: {
|
86
|
+
amountUsed: {
|
87
|
+
baseUnit: (0, utils_1.toBaseUnit)(debt.amountUsed ?? 0, debtDecimals),
|
88
|
+
baseAmountUsdValue: (0, utils_1.toRoundedUsdValue)(debtUsd),
|
89
|
+
},
|
90
|
+
amountCanBeUsed: {
|
91
|
+
baseUnit: (0, utils_1.toBaseUnit)(debt.amountCanBeUsed ?? 0, debtDecimals),
|
92
|
+
baseAmountUsdValue: (0, utils_1.toRoundedUsdValue)((debt.amountCanBeUsed ?? 0) * (debt.price ?? 0)),
|
93
|
+
},
|
94
|
+
baseAmountMarketPriceUsd: (0, utils_1.toRoundedUsdValue)(debt.price ?? 0),
|
95
|
+
borrowFeeBps: 0,
|
96
|
+
decimals: debtDecimals,
|
97
|
+
mint: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(debt.mint),
|
98
|
+
padding1: [],
|
99
|
+
padding2: [],
|
100
|
+
padding: new Uint8Array([]),
|
101
|
+
},
|
102
|
+
netWorth: {
|
103
|
+
baseUnit: supply.price
|
104
|
+
? (0, utils_1.toBaseUnit)((supplyUsd - debtUsd) / supply.price, supplyDecimals)
|
105
|
+
: BigInt(0),
|
106
|
+
baseAmountUsdValue: (0, utils_1.toRoundedUsdValue)(supplyUsd - debtUsd),
|
107
|
+
},
|
108
|
+
maxLtvBps,
|
109
|
+
liqThresholdBps,
|
110
|
+
lastRefreshed: BigInt((0, utils_1.currentUnixSeconds)()),
|
111
|
+
padding1: [],
|
112
|
+
padding2: [],
|
113
|
+
padding: [],
|
114
|
+
};
|
115
|
+
}
|
package/dist/types/solauto.d.ts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import { LendingPlatform, PositionType } from "../generated";
|
2
|
+
import { LendingPlatform, PositionType, SolautoRebalanceType, TokenType } from "../generated";
|
3
3
|
import { TransactionBuilder } from "@metaplex-foundation/umi";
|
4
|
+
import { RebalanceValues } from "../services/rebalance";
|
5
|
+
import { QuoteResponse } from "@jup-ag/api";
|
4
6
|
export interface SolautoPositionDetails {
|
5
7
|
publicKey?: PublicKey;
|
6
8
|
authority: PublicKey;
|
@@ -27,4 +29,20 @@ export interface TransactionItemInputs {
|
|
27
29
|
lookupTableAddresses?: string[];
|
28
30
|
orderPrio?: number;
|
29
31
|
}
|
32
|
+
export interface FlashLoanRequirements {
|
33
|
+
liquiditySource: TokenType;
|
34
|
+
signerFlashLoan?: boolean;
|
35
|
+
flFeeBps?: number;
|
36
|
+
}
|
37
|
+
export interface FlashLoanDetails extends FlashLoanRequirements {
|
38
|
+
baseUnitAmount: bigint;
|
39
|
+
mint: PublicKey;
|
40
|
+
}
|
41
|
+
export interface RebalanceDetails {
|
42
|
+
values: RebalanceValues;
|
43
|
+
rebalanceType: SolautoRebalanceType;
|
44
|
+
flashLoan?: FlashLoanDetails;
|
45
|
+
swapQuote: QuoteResponse;
|
46
|
+
targetLiqUtilizationRateBps?: number;
|
47
|
+
}
|
30
48
|
//# sourceMappingURL=solauto.d.ts.map
|
@@ -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,
|
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,CA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IACzB,2BAA2B,CAAC,EAAE,MAAM,CAAC;CACtC"}
|
@@ -5,6 +5,7 @@ export declare function consoleLog(...args: any[]): void;
|
|
5
5
|
export declare function tokenInfo(mint?: PublicKey): TokenInfo;
|
6
6
|
export declare function findMintByTicker(ticker: string): PublicKey;
|
7
7
|
export declare function tokenInfoByTicker(ticker: string): TokenInfo | undefined;
|
8
|
+
export declare function getBatches<T>(items: T[], batchSize: number): T[][];
|
8
9
|
export declare function generateRandomU8(): number;
|
9
10
|
export declare function generateRandomU64(): bigint;
|
10
11
|
export declare function currentUnixSeconds(): number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAc,SAAS,EAAE,MAAM,cAAc,CAAC;AAGrD,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAI/C;AAED,wBAAgB,SAAS,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,CAErD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAW1D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,yBAQ/C;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,SAAS,GACZ,OAAO,CAAC,OAAO,CAAC,CAKlB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEnE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAA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AAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAUxB;AAED,wBAAsB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,gBAuBzE"}
|
@@ -7,6 +7,7 @@ exports.consoleLog = consoleLog;
|
|
7
7
|
exports.tokenInfo = tokenInfo;
|
8
8
|
exports.findMintByTicker = findMintByTicker;
|
9
9
|
exports.tokenInfoByTicker = tokenInfoByTicker;
|
10
|
+
exports.getBatches = getBatches;
|
10
11
|
exports.generateRandomU8 = generateRandomU8;
|
11
12
|
exports.generateRandomU64 = generateRandomU64;
|
12
13
|
exports.currentUnixSeconds = currentUnixSeconds;
|
@@ -22,7 +23,7 @@ const umi_1 = require("@metaplex-foundation/umi");
|
|
22
23
|
const constants_1 = require("../constants");
|
23
24
|
const axios_1 = __importDefault(require("axios"));
|
24
25
|
function consoleLog(...args) {
|
25
|
-
if (globalThis.
|
26
|
+
if (globalThis.SHOW_LOGS) {
|
26
27
|
console.log(...args);
|
27
28
|
}
|
28
29
|
}
|
@@ -48,6 +49,13 @@ function tokenInfoByTicker(ticker) {
|
|
48
49
|
}
|
49
50
|
return undefined;
|
50
51
|
}
|
52
|
+
function getBatches(items, batchSize) {
|
53
|
+
const batches = [];
|
54
|
+
for (let i = 0; i < items.length; i += batchSize) {
|
55
|
+
batches.push(items.slice(i, i + batchSize));
|
56
|
+
}
|
57
|
+
return batches;
|
58
|
+
}
|
51
59
|
function generateRandomU8() {
|
52
60
|
return Math.floor(Math.random() * 255 + 1);
|
53
61
|
}
|
package/dist/utils/index.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
export * from "./solauto/index";
|
2
1
|
export * from "./accountUtils";
|
3
2
|
export * from "./generalUtils";
|
4
3
|
export * from "./jupiterUtils";
|
5
4
|
export * from "./marginfiUtils";
|
6
5
|
export * from "./numberUtils";
|
6
|
+
export * from "./solautoUtils";
|
7
7
|
export * from "./solanaUtils";
|
8
8
|
export * from "./stringUtils";
|
9
9
|
export * from "./priceUtils";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
package/dist/utils/index.js
CHANGED
@@ -14,12 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./solauto/index"), exports);
|
18
17
|
__exportStar(require("./accountUtils"), exports);
|
19
18
|
__exportStar(require("./generalUtils"), exports);
|
20
19
|
__exportStar(require("./jupiterUtils"), exports);
|
21
20
|
__exportStar(require("./marginfiUtils"), exports);
|
22
21
|
__exportStar(require("./numberUtils"), exports);
|
22
|
+
__exportStar(require("./solautoUtils"), exports);
|
23
23
|
__exportStar(require("./solanaUtils"), exports);
|
24
24
|
__exportStar(require("./stringUtils"), exports);
|
25
25
|
__exportStar(require("./priceUtils"), exports);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,
|
1
|
+
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAIV,MAAM,iBAAiB,CAAC;AAKzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEH,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAYlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAKlE,wBAAgB,mBAAmB,IAAI,SAAS,CAG/C;AA0MD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB;;;;IAkB7D;AAED,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,EACtB,GAAG,EAAE,kBAAkB,EAAE,EACzB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CA+F/B"}
|
@@ -1,31 +1,6 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
|
4
|
-
export interface JupSwapInput {
|
5
|
-
inputMint: PublicKey;
|
6
|
-
outputMint: PublicKey;
|
7
|
-
amount: bigint;
|
8
|
-
exactIn?: boolean;
|
9
|
-
exactOut?: boolean;
|
10
|
-
}
|
11
|
-
export interface JupSwapDetails extends JupSwapInput {
|
12
|
-
destinationWallet: PublicKey;
|
13
|
-
slippageIncFactor?: number;
|
14
|
-
addPadding?: boolean;
|
15
|
-
jupQuote?: QuoteResponse;
|
16
|
-
wrapAndUnwrapSol?: boolean;
|
17
|
-
}
|
18
|
-
export declare function getJupQuote(swapDetails: JupSwapInput): Promise<QuoteResponse>;
|
19
|
-
export interface JupSwapTransaction {
|
20
|
-
jupQuote: QuoteResponse;
|
21
|
-
priceImpactBps: number;
|
22
|
-
lookupTableAddresses: string[];
|
23
|
-
setupInstructions: TransactionBuilder;
|
24
|
-
tokenLedgerIx?: TransactionBuilder;
|
25
|
-
swapIx: TransactionBuilder;
|
26
|
-
cleanupIx: TransactionBuilder;
|
27
|
-
}
|
28
|
-
export declare function getJupSwapTransaction(signer: Signer, swapDetails: JupSwapDetails, attemptNum?: number): Promise<JupSwapTransaction>;
|
1
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
2
|
+
import { Instruction } from "@jup-ag/api";
|
3
|
+
export declare function jupIxToSolanaIx(instruction: Instruction): TransactionInstruction;
|
29
4
|
export declare function getJupPriceData(mints: PublicKey[]): Promise<{
|
30
5
|
[key: string]: any;
|
31
6
|
}>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,wBAAgB,eAAe,CAC7B,WAAW,EAAE,WAAW,GACvB,sBAAsB,CAUxB;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE;;GA4BvD"}
|
@@ -1,17 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
exports.getJupSwapTransaction = getJupSwapTransaction;
|
3
|
+
exports.jupIxToSolanaIx = jupIxToSolanaIx;
|
5
4
|
exports.getJupPriceData = getJupPriceData;
|
6
|
-
const umi_1 = require("@metaplex-foundation/umi");
|
7
5
|
const web3_js_1 = require("@solana/web3.js");
|
8
|
-
const solanaUtils_1 = require("./solanaUtils");
|
9
|
-
const numberUtils_1 = require("./numberUtils");
|
10
|
-
const api_1 = require("@jup-ag/api");
|
11
|
-
const accountUtils_1 = require("./accountUtils");
|
12
6
|
const generalUtils_1 = require("./generalUtils");
|
13
|
-
|
14
|
-
function createTransactionInstruction(instruction) {
|
7
|
+
function jupIxToSolanaIx(instruction) {
|
15
8
|
return new web3_js_1.TransactionInstruction({
|
16
9
|
programId: new web3_js_1.PublicKey(instruction.programId),
|
17
10
|
keys: instruction.accounts.map((key) => ({
|
@@ -22,70 +15,6 @@ function createTransactionInstruction(instruction) {
|
|
22
15
|
data: Buffer.from(instruction.data, "base64"),
|
23
16
|
});
|
24
17
|
}
|
25
|
-
async function getJupQuote(swapDetails) {
|
26
|
-
return await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => await jupApi.quoteGet({
|
27
|
-
amount: Number(swapDetails.amount),
|
28
|
-
inputMint: swapDetails.inputMint.toString(),
|
29
|
-
outputMint: swapDetails.outputMint.toString(),
|
30
|
-
swapMode: swapDetails.exactOut
|
31
|
-
? "ExactOut"
|
32
|
-
: swapDetails.exactIn
|
33
|
-
? "ExactIn"
|
34
|
-
: undefined,
|
35
|
-
slippageBps: 300,
|
36
|
-
maxAccounts: !swapDetails.exactOut ? 15 + attemptNum * 5 : undefined,
|
37
|
-
}), 3, 200);
|
38
|
-
}
|
39
|
-
async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
|
40
|
-
const quoteResponse = swapDetails.jupQuote ?? (await getJupQuote(swapDetails));
|
41
|
-
const priceImpactBps = Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct))) + 1;
|
42
|
-
const finalPriceSlippageBps = Math.round(Math.max(50, quoteResponse.slippageBps, priceImpactBps) *
|
43
|
-
(1 + (swapDetails.slippageIncFactor ?? 0)));
|
44
|
-
quoteResponse.slippageBps = finalPriceSlippageBps;
|
45
|
-
(0, generalUtils_1.consoleLog)("Quote:", quoteResponse);
|
46
|
-
(0, generalUtils_1.consoleLog)("Getting jup instructions...");
|
47
|
-
const instructions = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
48
|
-
const res = await jupApi.swapInstructionsPost({
|
49
|
-
swapRequest: {
|
50
|
-
userPublicKey: signer.publicKey.toString(),
|
51
|
-
quoteResponse,
|
52
|
-
wrapAndUnwrapSol: swapDetails.wrapAndUnwrapSol ?? false,
|
53
|
-
useTokenLedger: !swapDetails.exactOut && !swapDetails.exactIn,
|
54
|
-
destinationTokenAccount: (0, accountUtils_1.getTokenAccount)(swapDetails.destinationWallet, swapDetails.outputMint).toString(),
|
55
|
-
},
|
56
|
-
});
|
57
|
-
if (!res) {
|
58
|
-
throw new Error("No instructions retrieved");
|
59
|
-
}
|
60
|
-
return res;
|
61
|
-
}, 4, 200);
|
62
|
-
if (!instructions.swapInstruction) {
|
63
|
-
throw new Error("No swap instruction was returned by Jupiter");
|
64
|
-
}
|
65
|
-
(0, generalUtils_1.consoleLog)("Raw price impact bps:", priceImpactBps);
|
66
|
-
const finalPriceImpactBps = priceImpactBps * (1 + (swapDetails.slippageIncFactor ?? 0));
|
67
|
-
(0, generalUtils_1.consoleLog)("Increased price impact bps:", finalPriceImpactBps);
|
68
|
-
if (swapDetails.addPadding) {
|
69
|
-
(0, generalUtils_1.consoleLog)("Raw inAmount:", quoteResponse.inAmount);
|
70
|
-
const inc = Math.max((0, numberUtils_1.fromBps)(finalPriceImpactBps) * 1.1, (0, numberUtils_1.fromBps)(finalPriceSlippageBps) * 0.05);
|
71
|
-
(0, generalUtils_1.consoleLog)("Inc:", inc);
|
72
|
-
quoteResponse.inAmount = Math.round(parseInt(quoteResponse.inAmount) + parseInt(quoteResponse.inAmount) * inc).toString();
|
73
|
-
(0, generalUtils_1.consoleLog)("Increased inAmount:", quoteResponse.inAmount);
|
74
|
-
}
|
75
|
-
return {
|
76
|
-
jupQuote: quoteResponse,
|
77
|
-
priceImpactBps: finalPriceImpactBps,
|
78
|
-
lookupTableAddresses: instructions.addressLookupTableAddresses,
|
79
|
-
setupInstructions: (0, umi_1.transactionBuilder)().add((instructions.setupInstructions ?? []).map((ix) => (0, solanaUtils_1.getWrappedInstruction)(signer, createTransactionInstruction(ix)))),
|
80
|
-
tokenLedgerIx: instructions.tokenLedgerInstruction
|
81
|
-
? (0, umi_1.transactionBuilder)().add((0, solanaUtils_1.getWrappedInstruction)(signer, createTransactionInstruction(instructions.tokenLedgerInstruction)))
|
82
|
-
: undefined,
|
83
|
-
swapIx: (0, umi_1.transactionBuilder)().add((0, solanaUtils_1.getWrappedInstruction)(signer, createTransactionInstruction(instructions.swapInstruction))),
|
84
|
-
cleanupIx: instructions.cleanupInstruction
|
85
|
-
? (0, umi_1.transactionBuilder)().add((0, solanaUtils_1.getWrappedInstruction)(signer, createTransactionInstruction(instructions.cleanupInstruction)))
|
86
|
-
: (0, umi_1.transactionBuilder)(),
|
87
|
-
};
|
88
|
-
}
|
89
18
|
async function getJupPriceData(mints) {
|
90
19
|
const data = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
91
20
|
const res = await (await fetch("https://api.jup.ag/price/v2?ids=" +
|
@@ -3,7 +3,7 @@ import { Umi } from "@metaplex-foundation/umi";
|
|
3
3
|
import { Bank, MarginfiAccount } from "../marginfi-sdk";
|
4
4
|
import { MarginfiAssetAccounts } from "../types/accounts";
|
5
5
|
import { PositionState } from "../generated";
|
6
|
-
import { ContextUpdates } from "./
|
6
|
+
import { ContextUpdates } from "./solautoUtils";
|
7
7
|
interface AllMarginfiAssetAccounts extends MarginfiAssetAccounts {
|
8
8
|
mint: PublicKey;
|
9
9
|
}
|
@@ -16,6 +16,7 @@ export declare function getMarginfiMaxLtvAndLiqThreshold(umi: Umi, marginfiGroup
|
|
16
16
|
mint: PublicKey;
|
17
17
|
bank?: Bank | null;
|
18
18
|
}, supplyPrice?: number): Promise<[number, number]>;
|
19
|
+
export declare function getEmptyMarginfiAccountsByAuthority(umi: Umi, authority: PublicKey): Promise<MarginfiAccount[]>;
|
19
20
|
export declare function getAllMarginfiAccountsByAuthority(umi: Umi, authority: PublicKey, group?: PublicKey, compatibleWithSolauto?: boolean): Promise<{
|
20
21
|
marginfiAccount: PublicKey;
|
21
22
|
supplyMint?: PublicKey;
|
@@ -32,8 +33,8 @@ type BanksCache = {
|
|
32
33
|
};
|
33
34
|
};
|
34
35
|
export declare function getMarginfiAccountPositionState(umi: Umi, protocolAccount: {
|
35
|
-
pk
|
36
|
-
data?: MarginfiAccount;
|
36
|
+
pk?: PublicKey;
|
37
|
+
data?: MarginfiAccount | null;
|
37
38
|
}, marginfiGroup?: PublicKey, supply?: BankSelection, debt?: BankSelection, contextUpdates?: ContextUpdates): Promise<{
|
38
39
|
supplyBank: Bank | null;
|
39
40
|
debtBank: Bank | null;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAIJ,eAAe,EAIhB,MAAM,iBAAiB,CAAC;AAczB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAIhD,UAAU,wBAAyB,SAAQ,qBAAqB;IAC9D,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,SAAS,GACd,wBAAwB,CAY1B;AAED,wBAAgB,iCAAiC,CAC/C,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,IAAI,EACd,WAAW,EAAE,MAAM,GAClB,CAAC,MAAM,EAAE,MAAM,CAA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CAAA;CAAE,EAClE,aAAa,CAAC,EAAE,SAAS,EACzB,MAAM,CAAC,EAAE,aAAa,EACtB,IAAI,CAAC,EAAE,aAAa,EACpB,cAAc,CAAC,EAAE,cAAc,GAC9B,OAAO,CACN;IAAE,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,aAAa,CAAA;CAAE,GACxE,SAAS,CACZ,CAyKA;AA+DD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,oBAU7C;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBnE;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,WASpE"}
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findMarginfiAccounts = findMarginfiAccounts;
|
4
4
|
exports.calcMarginfiMaxLtvAndLiqThreshold = calcMarginfiMaxLtvAndLiqThreshold;
|
5
5
|
exports.getMarginfiMaxLtvAndLiqThreshold = getMarginfiMaxLtvAndLiqThreshold;
|
6
|
+
exports.getEmptyMarginfiAccountsByAuthority = getEmptyMarginfiAccountsByAuthority;
|
6
7
|
exports.getAllMarginfiAccountsByAuthority = getAllMarginfiAccountsByAuthority;
|
7
8
|
exports.getBankLiquidityAvailableBaseUnit = getBankLiquidityAvailableBaseUnit;
|
8
9
|
exports.getMarginfiAccountPositionState = getMarginfiAccountPositionState;
|
@@ -67,6 +68,32 @@ async function getMarginfiMaxLtvAndLiqThreshold(umi, marginfiGroup, supply, debt
|
|
67
68
|
}
|
68
69
|
return calcMarginfiMaxLtvAndLiqThreshold(supply.bank, debt.bank, supplyPrice);
|
69
70
|
}
|
71
|
+
async function getEmptyMarginfiAccountsByAuthority(umi, authority) {
|
72
|
+
const marginfiAccounts = await umi.rpc.getProgramAccounts(marginfi_sdk_1.MARGINFI_PROGRAM_ID, {
|
73
|
+
commitment: "confirmed",
|
74
|
+
filters: [
|
75
|
+
{
|
76
|
+
dataSize: (0, marginfi_sdk_1.getMarginfiAccountSize)(),
|
77
|
+
},
|
78
|
+
{
|
79
|
+
memcmp: {
|
80
|
+
bytes: new Uint8Array(authority.toBuffer()),
|
81
|
+
offset: 8 + 32, // Anchor account discriminator + group pubkey
|
82
|
+
},
|
83
|
+
},
|
84
|
+
{
|
85
|
+
// First balance is not active
|
86
|
+
memcmp: {
|
87
|
+
bytes: new Uint8Array([0]),
|
88
|
+
offset: 8 + 32 + 32,
|
89
|
+
},
|
90
|
+
},
|
91
|
+
],
|
92
|
+
});
|
93
|
+
return marginfiAccounts
|
94
|
+
.map((x) => (0, marginfi_sdk_1.deserializeMarginfiAccount)(x))
|
95
|
+
.filter((x) => marginfiAccountEmpty(x));
|
96
|
+
}
|
70
97
|
async function getAllMarginfiAccountsByAuthority(umi, authority, group, compatibleWithSolauto) {
|
71
98
|
const marginfiAccounts = await umi.rpc.getProgramAccounts(marginfi_sdk_1.MARGINFI_PROGRAM_ID, {
|
72
99
|
commitment: "confirmed",
|
@@ -134,12 +161,14 @@ async function getTokenUsage(bank, isAsset, shares, amountUsedAdjustment) {
|
|
134
161
|
let amountUsed = 0;
|
135
162
|
let amountCanBeUsed = BigInt(0);
|
136
163
|
let marketPrice = 0;
|
164
|
+
let originationFee = 0;
|
137
165
|
if (bank !== null) {
|
138
166
|
[marketPrice] = await (0, priceUtils_1.fetchTokenPrices)([(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(bank.mint)]);
|
139
167
|
const [assetShareValue, liabilityShareValue] = getUpToDateShareValues(bank);
|
140
168
|
const shareValue = isAsset ? assetShareValue : liabilityShareValue;
|
141
169
|
amountUsed = shares * shareValue + Number(amountUsedAdjustment ?? 0);
|
142
170
|
amountCanBeUsed = getBankLiquidityAvailableBaseUnit(bank, isAsset);
|
171
|
+
originationFee = (0, numberUtils_1.bytesToI80F48)(bank?.config.interestRateConfig.protocolOriginationFee.value);
|
143
172
|
}
|
144
173
|
return {
|
145
174
|
mint: bank?.mint ?? (0, umi_1.publicKey)(web3_js_1.PublicKey.default),
|
@@ -158,18 +187,26 @@ async function getTokenUsage(bank, isAsset, shares, amountUsedAdjustment) {
|
|
158
187
|
: BigInt(0),
|
159
188
|
},
|
160
189
|
baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(marketPrice, generalAccounts_1.USD_DECIMALS),
|
161
|
-
|
162
|
-
borrowFeeBps: 0,
|
190
|
+
borrowFeeBps: isAsset ? 0 : (0, numberUtils_1.toBps)(originationFee),
|
163
191
|
padding1: [],
|
164
192
|
padding2: [],
|
165
193
|
padding: new Uint8Array([]),
|
166
194
|
};
|
167
195
|
}
|
196
|
+
async function getBank(umi, data, marginfiGroup) {
|
197
|
+
return data?.banksCache && data.mint && marginfiGroup
|
198
|
+
? data.banksCache[marginfiGroup.toString()][data?.mint?.toString()]
|
199
|
+
: data?.mint && data?.mint !== web3_js_1.PublicKey.default
|
200
|
+
? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[marginfiGroup?.toString() ?? ""][data?.mint.toString()].bank), { commitment: "confirmed" })
|
201
|
+
: null;
|
202
|
+
}
|
168
203
|
async function getMarginfiAccountPositionState(umi, protocolAccount, marginfiGroup, supply, debt, contextUpdates) {
|
169
204
|
let marginfiAccount = protocolAccount.data ??
|
170
|
-
(
|
171
|
-
|
172
|
-
|
205
|
+
(protocolAccount.pk
|
206
|
+
? await (0, marginfi_sdk_1.safeFetchMarginfiAccount)(umi, (0, umi_1.publicKey)(protocolAccount.pk), {
|
207
|
+
commitment: "confirmed",
|
208
|
+
})
|
209
|
+
: null);
|
173
210
|
if (!supply) {
|
174
211
|
supply = {};
|
175
212
|
}
|
@@ -179,16 +216,8 @@ async function getMarginfiAccountPositionState(umi, protocolAccount, marginfiGro
|
|
179
216
|
if (!marginfiGroup && marginfiAccount) {
|
180
217
|
marginfiGroup = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(marginfiAccount.group);
|
181
218
|
}
|
182
|
-
let supplyBank =
|
183
|
-
|
184
|
-
: supply?.mint && supply?.mint !== web3_js_1.PublicKey.default
|
185
|
-
? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[marginfiGroup?.toString() ?? ""][supply?.mint.toString()].bank), { commitment: "confirmed" })
|
186
|
-
: null;
|
187
|
-
let debtBank = debt?.banksCache && debt.mint && marginfiGroup
|
188
|
-
? debt.banksCache[marginfiGroup.toString()][debt?.mint?.toString()]
|
189
|
-
: debt?.mint && debt?.mint !== web3_js_1.PublicKey.default
|
190
|
-
? await (0, marginfi_sdk_1.safeFetchBank)(umi, (0, umi_1.publicKey)(marginfiAccounts_1.MARGINFI_ACCOUNTS[marginfiGroup?.toString() ?? ""][debt?.mint.toString()].bank), { commitment: "confirmed" })
|
191
|
-
: null;
|
219
|
+
let supplyBank = await getBank(umi, supply, marginfiGroup);
|
220
|
+
let debtBank = await getBank(umi, debt, marginfiGroup);
|
192
221
|
let supplyUsage = undefined;
|
193
222
|
let debtUsage = undefined;
|
194
223
|
if (marginfiAccount !== null &&
|
@@ -268,7 +297,7 @@ async function getMarginfiAccountPositionState(umi, protocolAccount, marginfiGro
|
|
268
297
|
debt: debtUsage,
|
269
298
|
maxLtvBps: (0, numberUtils_1.toBps)(maxLtv),
|
270
299
|
liqThresholdBps: (0, numberUtils_1.toBps)(liqThreshold),
|
271
|
-
|
300
|
+
lastRefreshed: BigInt((0, generalUtils_1.currentUnixSeconds)()),
|
272
301
|
padding1: [],
|
273
302
|
padding2: [],
|
274
303
|
padding: [],
|
@@ -322,6 +351,6 @@ function getUpToDateShareValues(bank) {
|
|
322
351
|
}
|
323
352
|
function marginfiAccountEmpty(marginfiAccount) {
|
324
353
|
return (marginfiAccount.lendingAccount.balances.find((x) => x.bankPk.toString() !== web3_js_1.PublicKey.default.toString() &&
|
325
|
-
(
|
326
|
-
|
354
|
+
((0, numberUtils_1.bytesToI80F48)(x.assetShares.value) > 0.000001 ||
|
355
|
+
(0, numberUtils_1.bytesToI80F48)(x.liabilityShares.value) > 0.000001)) === undefined);
|
327
356
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { PositionState
|
1
|
+
import { PositionState } from "../generated";
|
2
2
|
export declare function calcNetWorthUsd(state?: PositionState): number;
|
3
3
|
export declare function calcSupplyUsd(state?: PositionState): number;
|
4
4
|
export declare function calcDebtUsd(state?: PositionState): number;
|
@@ -7,6 +7,8 @@ export declare function calcTotalSupply(state?: PositionState): number;
|
|
7
7
|
export declare function calcTotalDebt(state?: PositionState): number;
|
8
8
|
export declare function debtLiquidityUsdAvailable(state?: PositionState): number;
|
9
9
|
export declare function supplyLiquidityUsdDepositable(state?: PositionState): number;
|
10
|
+
export declare function fromRoundedUsdValue(number: bigint): number;
|
11
|
+
export declare function toRoundedUsdValue(number: number): bigint;
|
10
12
|
export declare function getLiqUtilzationRateBps(supplyUsd: number, debtUsd: number, liqThresholdBps: number): number;
|
11
13
|
export declare function toBaseUnit(value: number, decimals: number): bigint;
|
12
14
|
export declare function fromBaseUnit(value: bigint, decimals: number): number;
|
@@ -15,11 +17,6 @@ export declare function toBps(value: number): number;
|
|
15
17
|
export declare function bytesToI80F48(bytes: number[]): number;
|
16
18
|
export declare function uint8ArrayToBigInt(uint8Array: Uint8Array): bigint;
|
17
19
|
export declare function getDebtAdjustmentUsd(liqThresholdBps: number, supplyUsd: number, debtUsd: number, targetLiqUtilizationRateBps: number, adjustmentFeeBps?: number): number;
|
18
|
-
export declare function getSolautoFeesBps(isReferred: boolean, targetLiqUtilizationRateBps: number | undefined, positionNetWorthUsd: number, rebalanceDirection: RebalanceDirection): {
|
19
|
-
solauto: number;
|
20
|
-
referrer: number;
|
21
|
-
total: number;
|
22
|
-
};
|
23
20
|
export declare function getMaxLiqUtilizationRateBps(maxLtvBps: number, liqThresholdBps: number, offsetFromMaxLtv: number): number;
|
24
21
|
export declare function maxRepayFromBps(maxLtvBps: number, liqThresholdBps: number): number;
|
25
22
|
export declare function maxRepayToBps(maxLtvBps: number, liqThresholdBps: number): number;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"numberUtils.d.ts","sourceRoot":"","sources":["../../src/utils/numberUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,
|
1
|
+
{"version":3,"file":"numberUtils.d.ts","sourceRoot":"","sources":["../../src/utils/numberUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,aAAa,UAEpD;AAED,wBAAgB,aAAa,CAAC,KAAK,CAAC,EAAE,aAAa,UAIlD;AAED,wBAAgB,WAAW,CAAC,KAAK,CAAC,EAAE,aAAa,UAIhD;AAED,wBAAgB,YAAY,CAAC,KAAK,CAAC,EAAE,aAAa,UAKjD;AAED,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,aAAa,UAKpD;AAED,wBAAgB,aAAa,CAAC,KAAK,CAAC,EAAE,aAAa,UAKlD;AAED,wBAAgB,yBAAyB,CAAC,KAAK,CAAC,EAAE,aAAa,UAI9D;AAED,wBAAgB,6BAA6B,CAAC,KAAK,CAAC,EAAE,aAAa,UAIlE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,UAEjD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,UAE/C;AAED,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,GACtB,MAAM,CAMR;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKlE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EA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