@haven-fi/solauto-sdk 1.0.14 → 1.0.16
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/clients/solautoClient.d.ts +4 -4
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +22 -21
- package/dist/clients/solautoMarginfiClient.d.ts +1 -1
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +15 -12
- package/dist/constants/tokenConstants.d.ts +4 -0
- package/dist/constants/tokenConstants.d.ts.map +1 -1
- package/dist/constants/tokenConstants.js +5 -1
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +10 -10
- package/dist/utils/generalUtils.js +1 -1
- package/dist/utils/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.js +2 -3
- package/dist/utils/numberUtils.d.ts +3 -0
- package/dist/utils/numberUtils.d.ts.map +1 -1
- package/dist/utils/numberUtils.js +14 -1
- package/dist/utils/solanaUtils.js +1 -1
- package/dist/utils/solauto/generalUtils.d.ts +0 -3
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +1 -14
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +11 -10
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +27 -28
- package/src/clients/solautoMarginfiClient.ts +19 -11
- package/src/constants/tokenConstants.ts +6 -1
- package/src/transactions/transactionUtils.ts +10 -11
- package/src/utils/generalUtils.ts +1 -1
- package/src/utils/jupiterUtils.ts +10 -8
- package/src/utils/numberUtils.ts +23 -0
- package/src/utils/solanaUtils.ts +1 -1
- package/src/utils/solauto/generalUtils.ts +0 -24
- package/src/utils/solauto/rebalanceUtils.ts +13 -12
- package/tests/transactions/solautoMarginfi.ts +6 -4
- package/tests/unit/rebalanceCalculations.ts +6 -4
|
@@ -11,8 +11,8 @@ export interface SolautoClientArgs {
|
|
|
11
11
|
positionId: number;
|
|
12
12
|
signer?: Signer;
|
|
13
13
|
wallet?: WalletAdapter;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
supplyMint?: PublicKey;
|
|
15
|
+
debtMint?: PublicKey;
|
|
16
16
|
referralFeesDestMint?: PublicKey;
|
|
17
17
|
referredByAuthority?: PublicKey;
|
|
18
18
|
}
|
|
@@ -29,10 +29,10 @@ export declare abstract class SolautoClient {
|
|
|
29
29
|
solautoPosition: PublicKey;
|
|
30
30
|
solautoPositionData: SolautoPosition | null;
|
|
31
31
|
solautoPositionState: PositionState | undefined;
|
|
32
|
-
|
|
32
|
+
supplyMint: PublicKey;
|
|
33
33
|
positionSupplyLiquidityTa: PublicKey;
|
|
34
34
|
signerSupplyLiquidityTa: PublicKey;
|
|
35
|
-
|
|
35
|
+
debtMint: PublicKey;
|
|
36
36
|
positionDebtLiquidityTa: PublicKey;
|
|
37
37
|
signerDebtLiquidityTa: PublicKey;
|
|
38
38
|
authorityReferralState: PublicKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAEL,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAQJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EASvB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAKvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAInE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEpE,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IAEvB,
|
|
1
|
+
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"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"}
|
|
@@ -43,16 +43,16 @@ class SolautoClient {
|
|
|
43
43
|
this.solautoPosition = await (0, accountUtils_1.getSolautoPositionAccount)(this.authority, this.positionId);
|
|
44
44
|
this.solautoPositionData = await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition));
|
|
45
45
|
this.solautoPositionState = this.solautoPositionData?.state;
|
|
46
|
-
this.
|
|
47
|
-
args.
|
|
46
|
+
this.supplyMint =
|
|
47
|
+
args.supplyMint ??
|
|
48
48
|
(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.solautoPositionData.position.supplyMint);
|
|
49
|
-
this.positionSupplyLiquidityTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.
|
|
50
|
-
this.signerSupplyLiquidityTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.
|
|
51
|
-
this.
|
|
52
|
-
args.
|
|
49
|
+
this.positionSupplyLiquidityTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.supplyMint);
|
|
50
|
+
this.signerSupplyLiquidityTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.supplyMint);
|
|
51
|
+
this.debtMint =
|
|
52
|
+
args.debtMint ??
|
|
53
53
|
(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.solautoPositionData.position.debtMint);
|
|
54
|
-
this.positionDebtLiquidityTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.
|
|
55
|
-
this.signerDebtLiquidityTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.
|
|
54
|
+
this.positionDebtLiquidityTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.debtMint);
|
|
55
|
+
this.signerDebtLiquidityTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.debtMint);
|
|
56
56
|
this.authorityReferralState = await (0, accountUtils_1.getReferralState)(this.authority);
|
|
57
57
|
this.authorityReferralStateData = await (0, generated_1.safeFetchReferralState)(this.umi, (0, umi_1.publicKey)(this.authorityReferralState));
|
|
58
58
|
this.authorityReferralFeesDestMint = args.referralFeesDestMint
|
|
@@ -61,24 +61,25 @@ class SolautoClient {
|
|
|
61
61
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.authorityReferralStateData?.destFeesMint)
|
|
62
62
|
: spl_token_1.NATIVE_MINT;
|
|
63
63
|
this.authorityReferralDestTa = (0, accountUtils_1.getTokenAccount)(this.authorityReferralState, this.authorityReferralFeesDestMint);
|
|
64
|
-
const
|
|
64
|
+
const hasReferredBy = this.authorityReferralStateData &&
|
|
65
|
+
this.authorityReferralStateData.referredByState !==
|
|
66
|
+
(0, umi_1.publicKey)(web3_js_1.PublicKey.default);
|
|
67
|
+
const referredByAuthority = !hasReferredBy &&
|
|
68
|
+
args.referredByAuthority &&
|
|
65
69
|
!args.referredByAuthority.equals((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey))
|
|
66
70
|
? args.referredByAuthority
|
|
67
71
|
: undefined;
|
|
68
|
-
this.referredByState =
|
|
69
|
-
this.authorityReferralStateData
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
: referredByAuthority
|
|
74
|
-
? await (0, accountUtils_1.getReferralState)(referredByAuthority)
|
|
75
|
-
: undefined;
|
|
72
|
+
this.referredByState = hasReferredBy
|
|
73
|
+
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.authorityReferralStateData.referredByState)
|
|
74
|
+
: referredByAuthority
|
|
75
|
+
? await (0, accountUtils_1.getReferralState)(referredByAuthority)
|
|
76
|
+
: undefined;
|
|
76
77
|
this.referredByAuthority = referredByAuthority;
|
|
77
78
|
if (this.referredByState !== undefined) {
|
|
78
|
-
this.referredBySupplyTa = (0, accountUtils_1.getTokenAccount)(this.referredByState, this.
|
|
79
|
+
this.referredBySupplyTa = (0, accountUtils_1.getTokenAccount)(this.referredByState, this.supplyMint);
|
|
79
80
|
}
|
|
80
81
|
this.solautoFeesWallet = generalAccounts_1.SOLAUTO_FEES_WALLET;
|
|
81
|
-
this.solautoFeesSupplyTa = (0, accountUtils_1.getTokenAccount)(this.solautoFeesWallet, this.
|
|
82
|
+
this.solautoFeesSupplyTa = (0, accountUtils_1.getTokenAccount)(this.solautoFeesWallet, this.supplyMint);
|
|
82
83
|
this.authorityLutAddress = this.authorityReferralStateData?.lookupTable
|
|
83
84
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.authorityReferralStateData?.lookupTable)
|
|
84
85
|
: undefined;
|
|
@@ -241,7 +242,7 @@ class SolautoClient {
|
|
|
241
242
|
let positionDebtTa = undefined;
|
|
242
243
|
let signerDebtTa = undefined;
|
|
243
244
|
if ((0, umi_1.isOption)(args.dca) && (0, umi_1.isSome)(args.dca)) {
|
|
244
|
-
debtMint = (0, umi_1.publicKey)(this.
|
|
245
|
+
debtMint = (0, umi_1.publicKey)(this.debtMint);
|
|
245
246
|
positionDebtTa = (0, umi_1.publicKey)(this.positionDebtLiquidityTa);
|
|
246
247
|
signerDebtTa = (0, umi_1.publicKey)(this.signerDebtLiquidityTa);
|
|
247
248
|
let addingToPos = false;
|
|
@@ -301,7 +302,7 @@ class SolautoClient {
|
|
|
301
302
|
if (this.solautoPositionData !== null && !this.selfManaged) {
|
|
302
303
|
const positionData = this.solautoPositionData.position;
|
|
303
304
|
if (positionData.dca.debtToAddBaseUnit) {
|
|
304
|
-
debtMint = (0, umi_1.publicKey)(this.
|
|
305
|
+
debtMint = (0, umi_1.publicKey)(this.debtMint);
|
|
305
306
|
positionDebtTa = (0, umi_1.publicKey)(this.positionDebtLiquidityTa);
|
|
306
307
|
signerDebtTa = (0, umi_1.publicKey)(this.signerDebtLiquidityTa);
|
|
307
308
|
this.livePositionUpdates.new({
|
|
@@ -12,7 +12,7 @@ export interface SolautoMarginfiClientArgs extends SolautoClientArgs {
|
|
|
12
12
|
marginfiAccountSeedIdx?: bigint;
|
|
13
13
|
marginfiGroup?: PublicKey;
|
|
14
14
|
}
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function newSolautoMarginfiPositionArgs(positionId: number, signer: Signer | undefined, wallet: WalletAdapter | undefined, supplyMint: PublicKey, debtMint: PublicKey, referredByAuthority?: PublicKey): SolautoMarginfiClientArgs;
|
|
16
16
|
export declare class SolautoMarginfiClient extends SolautoClient {
|
|
17
17
|
marginfiProgram: PublicKey;
|
|
18
18
|
marginfiAccountSeedIdx?: bigint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,MAAM,EACN,kBAAkB,
|
|
1
|
+
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,MAAM,EACN,kBAAkB,EAOnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAEL,SAAS,EAEV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAK1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAQhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAOnE,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,eAAe,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACrC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAED,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,MAAM,EAAE,aAAa,GAAG,SAAS,EACjC,UAAU,EAAE,SAAS,EACrB,QAAQ,EAAE,SAAS,EACnB,mBAAmB,CAAC,EAAE,SAAS,GAC9B,yBAAyB,CAiB3B;AAED,qBAAa,qBAAsB,SAAQ,aAAa;IAC/C,eAAe,EAAG,SAAS,CAAC;IAE5B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,eAAe,EAAG,SAAS,GAAG,MAAM,CAAC;IACrC,iBAAiB,EAAG,SAAS,CAAC;IAC9B,aAAa,EAAG,SAAS,CAAC;IAE1B,0BAA0B,EAAG,qBAAqB,CAAC;IACnD,wBAAwB,EAAG,qBAAqB,CAAC;IAGjD,iCAAiC,CAAC,EAAE,MAAM,CAAC;IAC3C,6BAA6B,EAAG,SAAS,CAAC;IAC1C,2BAA2B,CAAC,EAAE,eAAe,CAAC;IAE/C,UAAU,CAAC,IAAI,EAAE,yBAAyB;IAuEhD,mBAAmB,IAAI,MAAM,EAAE;IAI/B,gBAAgB,IAAI,SAAS,EAAE;IAQ/B,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA2C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAMhE,OAAO,CAAC,6BAA6B;IA8DrC,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IA4CrB,WAAW,CACT,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IA8ElE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAiBlE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SolautoMarginfiClient = exports.
|
|
3
|
+
exports.SolautoMarginfiClient = exports.newSolautoMarginfiPositionArgs = void 0;
|
|
4
4
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
|
5
5
|
const umi_1 = require("@metaplex-foundation/umi");
|
|
6
6
|
const web3_js_1 = require("@solana/web3.js");
|
|
@@ -12,18 +12,21 @@ const generalUtils_1 = require("../utils/generalUtils");
|
|
|
12
12
|
const marginfi_sdk_1 = require("../marginfi-sdk");
|
|
13
13
|
const marginfiUtils_1 = require("../utils/marginfiUtils");
|
|
14
14
|
const numberUtils_1 = require("../utils/numberUtils");
|
|
15
|
-
function
|
|
15
|
+
function newSolautoMarginfiPositionArgs(positionId, signer, wallet, supplyMint, debtMint, referredByAuthority) {
|
|
16
16
|
return {
|
|
17
17
|
positionId,
|
|
18
18
|
signer,
|
|
19
19
|
wallet,
|
|
20
|
+
marginfiAccount: positionId === 0
|
|
21
|
+
? (0, umi_1.createSignerFromKeypair)((0, umi_1.createUmi)(), (0, umi_web3js_adapters_1.fromWeb3JsKeypair)(web3_js_1.Keypair.generate()))
|
|
22
|
+
: undefined,
|
|
20
23
|
marginfiAccountSeedIdx: positionId > 0 ? (0, generalUtils_1.generateRandomU64)() : undefined,
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
supplyMint: supplyMint,
|
|
25
|
+
debtMint: debtMint,
|
|
23
26
|
referredByAuthority,
|
|
24
27
|
};
|
|
25
28
|
}
|
|
26
|
-
exports.
|
|
29
|
+
exports.newSolautoMarginfiPositionArgs = newSolautoMarginfiPositionArgs;
|
|
27
30
|
class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
28
31
|
async initialize(args) {
|
|
29
32
|
if (args.marginfiAccount) {
|
|
@@ -45,10 +48,10 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
|
45
48
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(marginfiAccountData.group)
|
|
46
49
|
: args.marginfiGroup ?? new web3_js_1.PublicKey(marginfiAccounts_1.DEFAULT_MARGINFI_GROUP);
|
|
47
50
|
this.marginfiSupplyBankAccounts = (0, marginfiUtils_1.findMarginfiBankAccounts)({
|
|
48
|
-
mint: this.
|
|
51
|
+
mint: this.supplyMint.toString(),
|
|
49
52
|
});
|
|
50
53
|
this.marginfiDebtBankAccounts = (0, marginfiUtils_1.findMarginfiBankAccounts)({
|
|
51
|
-
mint: this.
|
|
54
|
+
mint: this.debtMint.toString(),
|
|
52
55
|
});
|
|
53
56
|
const existingMarginfiAccounts = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(this.umi, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), false);
|
|
54
57
|
const emptyMarginfiAccounts = (await (0, marginfi_sdk_1.safeFetchAllMarginfiAccount)(this.umi, existingMarginfiAccounts.map((x) => (0, umi_1.publicKey)(x)))).filter((x) => x.lendingAccount.balances.find((y) => y.bankPk.toString() !== web3_js_1.PublicKey.default.toString() &&
|
|
@@ -102,10 +105,10 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
|
102
105
|
marginfiAccount: this.marginfiAccountSeedIdx !== undefined
|
|
103
106
|
? (0, umi_1.publicKey)(this.marginfiAccount)
|
|
104
107
|
: this.marginfiAccount,
|
|
105
|
-
supplyMint: (0, umi_1.publicKey)(this.
|
|
108
|
+
supplyMint: (0, umi_1.publicKey)(this.supplyMint),
|
|
106
109
|
supplyBank: (0, umi_1.publicKey)(this.marginfiSupplyBankAccounts.bank),
|
|
107
110
|
positionSupplyTa: (0, umi_1.publicKey)(this.positionSupplyLiquidityTa),
|
|
108
|
-
debtMint: (0, umi_1.publicKey)(this.
|
|
111
|
+
debtMint: (0, umi_1.publicKey)(this.debtMint),
|
|
109
112
|
debtBank: (0, umi_1.publicKey)(this.marginfiDebtBankAccounts.bank),
|
|
110
113
|
positionDebtTa: (0, umi_1.publicKey)(this.positionDebtLiquidityTa),
|
|
111
114
|
signerDebtTa: signerDebtLiquidityTa,
|
|
@@ -213,7 +216,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
|
213
216
|
});
|
|
214
217
|
}
|
|
215
218
|
flashBorrow(flashLoanDetails, destinationTokenAccount) {
|
|
216
|
-
const bank = flashLoanDetails.mint.equals(this.
|
|
219
|
+
const bank = flashLoanDetails.mint.equals(this.supplyMint)
|
|
217
220
|
? this.marginfiSupplyBankAccounts
|
|
218
221
|
: this.marginfiDebtBankAccounts;
|
|
219
222
|
return (0, umi_1.transactionBuilder)()
|
|
@@ -235,7 +238,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
|
235
238
|
}));
|
|
236
239
|
}
|
|
237
240
|
flashRepay(flashLoanDetails) {
|
|
238
|
-
const bank = flashLoanDetails.mint.equals(this.
|
|
241
|
+
const bank = flashLoanDetails.mint.equals(this.supplyMint)
|
|
239
242
|
? this.marginfiSupplyBankAccounts
|
|
240
243
|
: this.marginfiDebtBankAccounts;
|
|
241
244
|
const remainingAccounts = [];
|
|
@@ -305,7 +308,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
|
305
308
|
if (state) {
|
|
306
309
|
return state;
|
|
307
310
|
}
|
|
308
|
-
const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, this.
|
|
311
|
+
const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, this.supplyMint, this.debtMint, this.livePositionUpdates);
|
|
309
312
|
this.log(freshState);
|
|
310
313
|
return freshState;
|
|
311
314
|
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export declare const USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
2
2
|
export declare const ALL_SUPPORTED_TOKENS: string[];
|
|
3
|
+
export declare const TOKEN_DECIMALS: {
|
|
4
|
+
[x: string]: number;
|
|
5
|
+
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: number;
|
|
6
|
+
};
|
|
3
7
|
//# sourceMappingURL=tokenConstants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenConstants.d.ts","sourceRoot":"","sources":["../../src/constants/tokenConstants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,iDAAiD,CAAC;AAGxE,eAAO,MAAM,oBAAoB,UAGhC,CAAC"}
|
|
1
|
+
{"version":3,"file":"tokenConstants.d.ts","sourceRoot":"","sources":["../../src/constants/tokenConstants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,iDAAiD,CAAC;AAGxE,eAAO,MAAM,oBAAoB,UAGhC,CAAC;AAEF,eAAO,MAAM,cAAc;;;CAG1B,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ALL_SUPPORTED_TOKENS = exports.USDC_MINT = void 0;
|
|
3
|
+
exports.TOKEN_DECIMALS = exports.ALL_SUPPORTED_TOKENS = exports.USDC_MINT = void 0;
|
|
4
4
|
const spl_token_1 = require("@solana/spl-token");
|
|
5
5
|
exports.USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
6
6
|
// When adding token ensure a price feed is provided in pythConstants.ts
|
|
@@ -8,3 +8,7 @@ exports.ALL_SUPPORTED_TOKENS = [
|
|
|
8
8
|
spl_token_1.NATIVE_MINT.toString(),
|
|
9
9
|
exports.USDC_MINT,
|
|
10
10
|
];
|
|
11
|
+
exports.TOKEN_DECIMALS = {
|
|
12
|
+
[spl_token_1.NATIVE_MINT.toString()]: 9,
|
|
13
|
+
[exports.USDC_MINT]: 6
|
|
14
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EAQd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EAQd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAgLzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,kBAAkB,CAAC,CAsE7B;AA0DD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CACN;IACE,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACD,SAAS,CACZ,CA2GA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,eAAe,GAC5B,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CA8BzC"}
|
|
@@ -14,8 +14,8 @@ const numberUtils_1 = require("../utils/numberUtils");
|
|
|
14
14
|
const generalUtils_2 = require("../utils/solauto/generalUtils");
|
|
15
15
|
const accountUtils_1 = require("../utils/accountUtils");
|
|
16
16
|
function getWSolUsage(client, solautoActions, initiatingDcaIn, cancellingDcaIn) {
|
|
17
|
-
const supplyIsWsol = client.
|
|
18
|
-
const debtIsWsol = client.
|
|
17
|
+
const supplyIsWsol = client.supplyMint.equals(spl_token_1.NATIVE_MINT);
|
|
18
|
+
const debtIsWsol = client.debtMint.equals(spl_token_1.NATIVE_MINT);
|
|
19
19
|
if (!supplyIsWsol && !debtIsWsol) {
|
|
20
20
|
return undefined;
|
|
21
21
|
}
|
|
@@ -70,7 +70,7 @@ async function transactionChoresBefore(client, solautoActions, initiatingDcaIn)
|
|
|
70
70
|
amountToTransfer += BigInt(wSolUsage.solautoAction.fields[0].fields[0]);
|
|
71
71
|
}
|
|
72
72
|
else if (initiatingDcaIn &&
|
|
73
|
-
client.
|
|
73
|
+
client.debtMint.toString() === spl_token_1.NATIVE_MINT.toString()) {
|
|
74
74
|
amountToTransfer += initiatingDcaIn;
|
|
75
75
|
}
|
|
76
76
|
if (amountToTransfer > 0) {
|
|
@@ -96,8 +96,8 @@ async function transactionChoresBefore(client, solautoActions, initiatingDcaIn)
|
|
|
96
96
|
}
|
|
97
97
|
if (!(0, generalUtils_1.getSolanaAccountCreated)(client.umi, tokenAccount)) {
|
|
98
98
|
chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), (0, generated_1.isSolautoAction)("Withdraw", solautoAction)
|
|
99
|
-
? client.
|
|
100
|
-
: client.
|
|
99
|
+
? client.supplyMint
|
|
100
|
+
: client.debtMint));
|
|
101
101
|
accountsGettingCreated.push(tokenAccount.toString());
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -123,12 +123,12 @@ async function rebalanceChoresBefore(client, tx) {
|
|
|
123
123
|
const [referredBySupplyTa, solautoFeesSupplyTa, intermediaryMarginfiAccount] = await client.umi.rpc.getAccounts(accountsNeeded.map((x) => (0, umi_1.publicKey)(x ?? web3_js_1.PublicKey.default)));
|
|
124
124
|
let chores = (0, umi_1.transactionBuilder)();
|
|
125
125
|
if (checkReferralSupplyTa && !(0, generalUtils_1.rpcAccountCreated)(referredBySupplyTa)) {
|
|
126
|
-
client.log("Creating referred-by TA for ", client.
|
|
127
|
-
chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.referredByState, client.
|
|
126
|
+
client.log("Creating referred-by TA for ", client.supplyMint.toString());
|
|
127
|
+
chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.referredByState, client.supplyMint));
|
|
128
128
|
}
|
|
129
129
|
if (checkSolautoFeesTa && !(0, generalUtils_1.rpcAccountCreated)(solautoFeesSupplyTa)) {
|
|
130
|
-
client.log("Creating Solauto fees TA for ", client.
|
|
131
|
-
chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.solautoFeesWallet, client.
|
|
130
|
+
client.log("Creating Solauto fees TA for ", client.supplyMint.toString());
|
|
131
|
+
chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.solautoFeesWallet, client.supplyMint));
|
|
132
132
|
}
|
|
133
133
|
if (checkIntermediaryMfiAccount &&
|
|
134
134
|
!(0, generalUtils_1.rpcAccountCreated)(intermediaryMarginfiAccount)) {
|
|
@@ -228,7 +228,7 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
|
228
228
|
]);
|
|
229
229
|
}
|
|
230
230
|
if (client.solautoPositionState.liqUtilizationRateBps >
|
|
231
|
-
(0,
|
|
231
|
+
(0, numberUtils_1.getMaxLiqUtilizationRate)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps)) {
|
|
232
232
|
tx = tx.prepend(client.refresh());
|
|
233
233
|
}
|
|
234
234
|
return {
|
|
@@ -45,7 +45,7 @@ function arraysAreEqual(arrayA, arrayB) {
|
|
|
45
45
|
exports.arraysAreEqual = arraysAreEqual;
|
|
46
46
|
async function getTokenPrices(mints) {
|
|
47
47
|
const currentTime = currentUnixSeconds();
|
|
48
|
-
if (!mints.some(mint => !(mint.toString() in solautoConstants_1.PRICES) || currentTime - solautoConstants_1.PRICES[mint.toString()].time >
|
|
48
|
+
if (!mints.some(mint => !(mint.toString() in solautoConstants_1.PRICES) || currentTime - solautoConstants_1.PRICES[mint.toString()].time > 3)) {
|
|
49
49
|
console.log("Accessing price cache");
|
|
50
50
|
return mints.map(mint => solautoConstants_1.PRICES[mint.toString()].price);
|
|
51
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CAiE7B"}
|
|
@@ -31,9 +31,8 @@ async function getJupSwapTransaction(signer, swapDetails) {
|
|
|
31
31
|
? "ExactIn"
|
|
32
32
|
: undefined,
|
|
33
33
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
(1 + (swapDetails.slippageBpsIncFactor ?? 0))));
|
|
34
|
+
const finalPriceSlippageBps = Math.round(Math.max(quoteResponse.slippageBps ?? 10, Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct)))) *
|
|
35
|
+
(1 + (swapDetails.slippageBpsIncFactor ?? 0)));
|
|
37
36
|
quoteResponse.slippageBps = finalPriceSlippageBps;
|
|
38
37
|
console.log(quoteResponse);
|
|
39
38
|
console.log("Getting jup instructions...");
|
|
@@ -6,4 +6,7 @@ export declare function toBps(value: number): number;
|
|
|
6
6
|
export declare function bytesToI80F48(bytes: number[]): number;
|
|
7
7
|
export declare function uint8ArrayToBigInt(uint8Array: Uint8Array): bigint;
|
|
8
8
|
export declare function getDebtAdjustmentUsd(liqThresholdBps: number, supplyUsd: number, debtUsd: number, targetLiqUtilizationRateBps: number, adjustmentFeeBps?: number): number;
|
|
9
|
+
export declare function getMaxLiqUtilizationRate(maxLtvBps: number, liqThresholdBps: number): number;
|
|
10
|
+
export declare function maxRepayFrom(maxLtvBps: number, liqThresholdBps: number): number;
|
|
11
|
+
export declare function maxRepayTo(maxLtvBps: number, liqThresholdBps: number): number;
|
|
9
12
|
//# sourceMappingURL=numberUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numberUtils.d.ts","sourceRoot":"","sources":["../../src/utils/numberUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"numberUtils.d.ts","sourceRoot":"","sources":["../../src/utils/numberUtils.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAM3G;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhE;AAEH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAqBrD;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAajE;AAED,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,MAAM,EACvB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,2BAA2B,EAAE,MAAM,EACnC,gBAAgB,CAAC,EAAE,MAAM,UAQ1B;AAED,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,GACtB,MAAM,CAER;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKtE;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,UAKpE"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDebtAdjustmentUsd = exports.uint8ArrayToBigInt = exports.bytesToI80F48 = exports.toBps = exports.fromBps = exports.fromBaseUnit = exports.toBaseUnit = exports.getLiqUtilzationRateBps = void 0;
|
|
3
|
+
exports.maxRepayTo = exports.maxRepayFrom = exports.getMaxLiqUtilizationRate = exports.getDebtAdjustmentUsd = exports.uint8ArrayToBigInt = exports.bytesToI80F48 = exports.toBps = exports.fromBps = exports.fromBaseUnit = exports.toBaseUnit = exports.getLiqUtilzationRateBps = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
4
5
|
function getLiqUtilzationRateBps(supplyUsd, debtUsd, liqThresholdBps) {
|
|
5
6
|
if (supplyUsd === 0) {
|
|
6
7
|
return 0;
|
|
@@ -60,3 +61,15 @@ function getDebtAdjustmentUsd(liqThresholdBps, supplyUsd, debtUsd, targetLiqUtil
|
|
|
60
61
|
return debtAdjustmentUsd;
|
|
61
62
|
}
|
|
62
63
|
exports.getDebtAdjustmentUsd = getDebtAdjustmentUsd;
|
|
64
|
+
function getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps) {
|
|
65
|
+
return toBps((fromBps(maxLtvBps) - 0.01) / fromBps(liqThresholdBps)) - 1;
|
|
66
|
+
}
|
|
67
|
+
exports.getMaxLiqUtilizationRate = getMaxLiqUtilizationRate;
|
|
68
|
+
function maxRepayFrom(maxLtvBps, liqThresholdBps) {
|
|
69
|
+
return Math.min(9000, getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps - 1000));
|
|
70
|
+
}
|
|
71
|
+
exports.maxRepayFrom = maxRepayFrom;
|
|
72
|
+
function maxRepayTo(maxLtvBps, liqThresholdBps) {
|
|
73
|
+
return Math.min(maxRepayFrom(maxLtvBps, liqThresholdBps) - constants_1.MAX_REPAY_GAP_BPS, getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps));
|
|
74
|
+
}
|
|
75
|
+
exports.maxRepayTo = maxRepayTo;
|
|
@@ -150,7 +150,7 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, simulateOnly,
|
|
|
150
150
|
const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, attemptNum);
|
|
151
151
|
console.log("Compute unit price: ", feeEstimate);
|
|
152
152
|
const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction(connection, (0, umi_web3js_adapters_1.toWeb3JsTransaction)(await (await assembleFinalTransaction(umi.identity, tx, feeEstimate, 1400000).setLatestBlockhash(umi)).buildAndSign(umi))));
|
|
153
|
-
const computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.
|
|
153
|
+
const computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.1);
|
|
154
154
|
console.log("Compute unit limit: ", computeUnitLimit);
|
|
155
155
|
if (!simulateOnly) {
|
|
156
156
|
const result = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await assembleFinalTransaction(umi.identity, tx, feeEstimate, computeUnitLimit).sendAndConfirm(umi, {
|
|
@@ -10,9 +10,6 @@ export declare function getSolautoFeesBps(isReferred: boolean, feeType: FeeType)
|
|
|
10
10
|
referrer: number;
|
|
11
11
|
total: number;
|
|
12
12
|
};
|
|
13
|
-
export declare function getMaxLiqUtilizationRate(maxLtvBps: number, liqThresholdBps: number): number;
|
|
14
|
-
export declare function maxRepayFrom(maxLtvBps: number, liqThresholdBps: number): number;
|
|
15
|
-
export declare function maxRepayTo(maxLtvBps: number, liqThresholdBps: number): number;
|
|
16
13
|
export declare function eligibileForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings): boolean;
|
|
17
14
|
export declare function eligibleForRefresh(positionState: PositionState, positionSettings: SolautoSettingsParameters): boolean;
|
|
18
15
|
export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicKey): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAoB,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,eAAe,EACf,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LivePositionUpdates = exports.getAllPositionsByAuthority = exports.getReferralsByUser = exports.getAllReferralStates = exports.getSolautoManagedPositions = exports.eligibleForRefresh = exports.eligibileForRebalance = exports.
|
|
3
|
+
exports.LivePositionUpdates = exports.getAllPositionsByAuthority = exports.getReferralsByUser = exports.getAllReferralStates = exports.getSolautoManagedPositions = exports.eligibleForRefresh = exports.eligibileForRebalance = exports.getSolautoFeesBps = exports.getAdjustedSettingsFromAutomation = exports.getUpdatedValueFromAutomation = exports.eligibleForNextAutomationPeriod = exports.nextAutomationPeriodTimestamp = void 0;
|
|
4
4
|
const umi_1 = require("@metaplex-foundation/umi");
|
|
5
5
|
const generated_1 = require("../../generated");
|
|
6
6
|
const generalUtils_1 = require("../generalUtils");
|
|
7
7
|
const numberUtils_1 = require("../numberUtils");
|
|
8
|
-
const solautoConstants_1 = require("../../constants/solautoConstants");
|
|
9
8
|
const accountUtils_1 = require("../accountUtils");
|
|
10
9
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
|
11
10
|
const constants_1 = require("../../constants");
|
|
@@ -59,18 +58,6 @@ function getSolautoFeesBps(isReferred, feeType) {
|
|
|
59
58
|
};
|
|
60
59
|
}
|
|
61
60
|
exports.getSolautoFeesBps = getSolautoFeesBps;
|
|
62
|
-
function getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps) {
|
|
63
|
-
return (0, numberUtils_1.toBps)(((0, numberUtils_1.fromBps)(maxLtvBps) - 0.015) / (0, numberUtils_1.fromBps)(liqThresholdBps)) - 1;
|
|
64
|
-
}
|
|
65
|
-
exports.getMaxLiqUtilizationRate = getMaxLiqUtilizationRate;
|
|
66
|
-
function maxRepayFrom(maxLtvBps, liqThresholdBps) {
|
|
67
|
-
return Math.min(9000, getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps - 1000));
|
|
68
|
-
}
|
|
69
|
-
exports.maxRepayFrom = maxRepayFrom;
|
|
70
|
-
function maxRepayTo(maxLtvBps, liqThresholdBps) {
|
|
71
|
-
return Math.min(maxRepayFrom(maxLtvBps, liqThresholdBps) - solautoConstants_1.MAX_REPAY_GAP_BPS, getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps));
|
|
72
|
-
}
|
|
73
|
-
exports.maxRepayTo = maxRepayTo;
|
|
74
61
|
function eligibileForRebalance(positionState, positionSettings, positionDca) {
|
|
75
62
|
if (positionDca.automation.targetPeriods > 0 &&
|
|
76
63
|
eligibleForNextAutomationPeriod(positionDca.automation)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"rebalanceUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/rebalanceUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAS5D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AA4IjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,eAAe,CA+EjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,GACtB,gBAAgB,GAAG,SAAS,CAkE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAmChB"}
|
|
@@ -93,7 +93,7 @@ function getRebalanceValues(client, targetLiqUtilizationRateBps, limitGapBps) {
|
|
|
93
93
|
throw new Error("Requires a fresh position state to get rebalance details");
|
|
94
94
|
}
|
|
95
95
|
const { targetRateBps, amountToDcaIn } = getTargetRateAndDcaAmount(client, targetLiqUtilizationRateBps);
|
|
96
|
-
const amountUsdToDcaIn = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round(amountToDcaIn ?? 0)), client.solautoPositionState.debt.decimals) * solautoConstants_1.PRICES[client.
|
|
96
|
+
const amountUsdToDcaIn = (0, numberUtils_1.fromBaseUnit)(BigInt(Math.round(amountToDcaIn ?? 0)), client.solautoPositionState.debt.decimals) * solautoConstants_1.PRICES[client.debtMint.toString()].price;
|
|
97
97
|
const increasingLeverage = amountUsdToDcaIn > 0 ||
|
|
98
98
|
client.solautoPositionState.liqUtilizationRateBps < targetRateBps;
|
|
99
99
|
let adjustmentFeeBps = 0;
|
|
@@ -103,12 +103,13 @@ function getRebalanceValues(client, targetLiqUtilizationRateBps, limitGapBps) {
|
|
|
103
103
|
const supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS) + amountUsdToDcaIn;
|
|
104
104
|
const debtUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
|
105
105
|
let debtAdjustmentUsd = (0, numberUtils_1.getDebtAdjustmentUsd)(client.solautoPositionState.liqThresholdBps, supplyUsd, debtUsd, targetRateBps, adjustmentFeeBps);
|
|
106
|
+
debtAdjustmentUsd *= 500;
|
|
106
107
|
const input = increasingLeverage
|
|
107
108
|
? client.solautoPositionState.debt
|
|
108
109
|
: client.solautoPositionState.supply;
|
|
109
110
|
const inputMarketPrice = increasingLeverage
|
|
110
|
-
? solautoConstants_1.PRICES[client.
|
|
111
|
-
: solautoConstants_1.PRICES[client.
|
|
111
|
+
? solautoConstants_1.PRICES[client.debtMint.toString()].price
|
|
112
|
+
: solautoConstants_1.PRICES[client.supplyMint.toString()].price;
|
|
112
113
|
const limitGap = limitGapBps
|
|
113
114
|
? (0, numberUtils_1.fromBps)(limitGapBps)
|
|
114
115
|
: (0, numberUtils_1.fromBps)(solautoConstants_1.DEFAULT_LIMIT_GAP_BPS);
|
|
@@ -141,18 +142,18 @@ function getFlashLoanDetails(client, values, jupQuote) {
|
|
|
141
142
|
? debtUsd + debtAdjustmentWithSlippage
|
|
142
143
|
: debtUsd;
|
|
143
144
|
const tempLiqUtilizationRateBps = (0, numberUtils_1.getLiqUtilzationRateBps)(supplyUsd, debtUsd, client.solautoPositionState.liqThresholdBps);
|
|
144
|
-
const requiresFlashLoan = supplyUsd
|
|
145
|
+
const requiresFlashLoan = supplyUsd <= 0 ||
|
|
145
146
|
tempLiqUtilizationRateBps >
|
|
146
|
-
(0,
|
|
147
|
+
(0, numberUtils_1.getMaxLiqUtilizationRate)(client.solautoPositionState.maxLtvBps, client.solautoPositionState.liqThresholdBps);
|
|
147
148
|
let flashLoanToken = undefined;
|
|
148
149
|
let flashLoanTokenPrice = 0;
|
|
149
150
|
if (values.increasingLeverage) {
|
|
150
151
|
flashLoanToken = client.solautoPositionState.debt;
|
|
151
|
-
flashLoanTokenPrice = solautoConstants_1.PRICES[client.
|
|
152
|
+
flashLoanTokenPrice = solautoConstants_1.PRICES[client.debtMint.toString()].price;
|
|
152
153
|
}
|
|
153
154
|
else {
|
|
154
155
|
flashLoanToken = client.solautoPositionState.supply;
|
|
155
|
-
flashLoanTokenPrice = solautoConstants_1.PRICES[client.
|
|
156
|
+
flashLoanTokenPrice = solautoConstants_1.PRICES[client.supplyMint.toString()].price;
|
|
156
157
|
}
|
|
157
158
|
const exactAmountBaseUnit = jupQuote && jupQuote.swapMode === "ExactOut"
|
|
158
159
|
? BigInt(parseInt(jupQuote.inAmount))
|
|
@@ -177,15 +178,15 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
|
177
178
|
: client.solautoPositionState.debt;
|
|
178
179
|
const usdToSwap = Math.abs(values.debtAdjustmentUsd) + values.amountUsdToDcaIn;
|
|
179
180
|
const inputPrice = values.increasingLeverage
|
|
180
|
-
? solautoConstants_1.PRICES[client.
|
|
181
|
-
: solautoConstants_1.PRICES[client.
|
|
181
|
+
? solautoConstants_1.PRICES[client.debtMint.toString()].price
|
|
182
|
+
: solautoConstants_1.PRICES[client.supplyMint.toString()].price;
|
|
182
183
|
const inputAmount = (0, numberUtils_1.toBaseUnit)(usdToSwap / inputPrice, input.decimals);
|
|
183
184
|
const rebalancingToZero = targetLiqUtilizationRateBps === 0;
|
|
184
185
|
return {
|
|
185
186
|
inputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(input.mint),
|
|
186
187
|
outputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(output.mint),
|
|
187
188
|
destinationWallet: client.solautoPosition,
|
|
188
|
-
// slippageBpsIncFactor: (values.increasingLeverage ? 0.1 : 0
|
|
189
|
+
// slippageBpsIncFactor: (!values.increasingLeverage ? 0.1 : 0) + ((attemptNum ?? 0) * 0.15),
|
|
189
190
|
slippageBpsIncFactor: (attemptNum ?? 0) * 0.15,
|
|
190
191
|
amount: rebalancingToZero
|
|
191
192
|
? client.solautoPositionState.debt.amountUsed.baseUnit +
|
package/package.json
CHANGED
|
@@ -66,8 +66,8 @@ export interface SolautoClientArgs {
|
|
|
66
66
|
signer?: Signer;
|
|
67
67
|
wallet?: WalletAdapter;
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
supplyMint?: PublicKey;
|
|
70
|
+
debtMint?: PublicKey;
|
|
71
71
|
|
|
72
72
|
referralFeesDestMint?: PublicKey;
|
|
73
73
|
referredByAuthority?: PublicKey;
|
|
@@ -87,11 +87,11 @@ export abstract class SolautoClient {
|
|
|
87
87
|
public solautoPositionData!: SolautoPosition | null;
|
|
88
88
|
public solautoPositionState!: PositionState | undefined;
|
|
89
89
|
|
|
90
|
-
public
|
|
90
|
+
public supplyMint!: PublicKey;
|
|
91
91
|
public positionSupplyLiquidityTa!: PublicKey;
|
|
92
92
|
public signerSupplyLiquidityTa!: PublicKey;
|
|
93
93
|
|
|
94
|
-
public
|
|
94
|
+
public debtMint!: PublicKey;
|
|
95
95
|
public positionDebtLiquidityTa!: PublicKey;
|
|
96
96
|
public signerDebtLiquidityTa!: PublicKey;
|
|
97
97
|
|
|
@@ -127,10 +127,7 @@ export abstract class SolautoClient {
|
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
async initialize(
|
|
131
|
-
args: SolautoClientArgs,
|
|
132
|
-
lendingPlatform: LendingPlatform,
|
|
133
|
-
) {
|
|
130
|
+
async initialize(args: SolautoClientArgs, lendingPlatform: LendingPlatform) {
|
|
134
131
|
if (!args.signer && !args.wallet) {
|
|
135
132
|
throw new Error("Signer or wallet must be provided");
|
|
136
133
|
}
|
|
@@ -157,28 +154,28 @@ export abstract class SolautoClient {
|
|
|
157
154
|
);
|
|
158
155
|
this.solautoPositionState = this.solautoPositionData?.state;
|
|
159
156
|
|
|
160
|
-
this.
|
|
161
|
-
args.
|
|
157
|
+
this.supplyMint =
|
|
158
|
+
args.supplyMint ??
|
|
162
159
|
toWeb3JsPublicKey(this.solautoPositionData!.position.supplyMint);
|
|
163
160
|
this.positionSupplyLiquidityTa = getTokenAccount(
|
|
164
161
|
this.solautoPosition,
|
|
165
|
-
this.
|
|
162
|
+
this.supplyMint
|
|
166
163
|
);
|
|
167
164
|
this.signerSupplyLiquidityTa = getTokenAccount(
|
|
168
165
|
toWeb3JsPublicKey(this.signer.publicKey),
|
|
169
|
-
this.
|
|
166
|
+
this.supplyMint
|
|
170
167
|
);
|
|
171
168
|
|
|
172
|
-
this.
|
|
173
|
-
args.
|
|
169
|
+
this.debtMint =
|
|
170
|
+
args.debtMint ??
|
|
174
171
|
toWeb3JsPublicKey(this.solautoPositionData!.position.debtMint);
|
|
175
172
|
this.positionDebtLiquidityTa = getTokenAccount(
|
|
176
173
|
this.solautoPosition,
|
|
177
|
-
this.
|
|
174
|
+
this.debtMint
|
|
178
175
|
);
|
|
179
176
|
this.signerDebtLiquidityTa = getTokenAccount(
|
|
180
177
|
toWeb3JsPublicKey(this.signer.publicKey),
|
|
181
|
-
this.
|
|
178
|
+
this.debtMint
|
|
182
179
|
);
|
|
183
180
|
|
|
184
181
|
this.authorityReferralState = await getReferralState(this.authority);
|
|
@@ -196,31 +193,33 @@ export abstract class SolautoClient {
|
|
|
196
193
|
this.authorityReferralFeesDestMint
|
|
197
194
|
);
|
|
198
195
|
|
|
196
|
+
const hasReferredBy =
|
|
197
|
+
this.authorityReferralStateData &&
|
|
198
|
+
this.authorityReferralStateData.referredByState !==
|
|
199
|
+
publicKey(PublicKey.default);
|
|
199
200
|
const referredByAuthority =
|
|
201
|
+
!hasReferredBy &&
|
|
200
202
|
args.referredByAuthority &&
|
|
201
203
|
!args.referredByAuthority.equals(toWeb3JsPublicKey(this.signer.publicKey))
|
|
202
204
|
? args.referredByAuthority
|
|
203
205
|
: undefined;
|
|
204
|
-
this.referredByState =
|
|
205
|
-
this.authorityReferralStateData
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
: referredByAuthority
|
|
210
|
-
? await getReferralState(referredByAuthority!)
|
|
211
|
-
: undefined;
|
|
206
|
+
this.referredByState = hasReferredBy
|
|
207
|
+
? toWeb3JsPublicKey(this.authorityReferralStateData!.referredByState)
|
|
208
|
+
: referredByAuthority
|
|
209
|
+
? await getReferralState(referredByAuthority!)
|
|
210
|
+
: undefined;
|
|
212
211
|
this.referredByAuthority = referredByAuthority;
|
|
213
212
|
if (this.referredByState !== undefined) {
|
|
214
213
|
this.referredBySupplyTa = getTokenAccount(
|
|
215
214
|
this.referredByState,
|
|
216
|
-
this.
|
|
215
|
+
this.supplyMint
|
|
217
216
|
);
|
|
218
217
|
}
|
|
219
218
|
|
|
220
219
|
this.solautoFeesWallet = SOLAUTO_FEES_WALLET;
|
|
221
220
|
this.solautoFeesSupplyTa = getTokenAccount(
|
|
222
221
|
this.solautoFeesWallet,
|
|
223
|
-
this.
|
|
222
|
+
this.supplyMint
|
|
224
223
|
);
|
|
225
224
|
|
|
226
225
|
this.authorityLutAddress = this.authorityReferralStateData?.lookupTable
|
|
@@ -443,7 +442,7 @@ export abstract class SolautoClient {
|
|
|
443
442
|
let positionDebtTa: UmiPublicKey | undefined = undefined;
|
|
444
443
|
let signerDebtTa: UmiPublicKey | undefined = undefined;
|
|
445
444
|
if (isOption(args.dca) && isSome(args.dca)) {
|
|
446
|
-
debtMint = publicKey(this.
|
|
445
|
+
debtMint = publicKey(this.debtMint);
|
|
447
446
|
positionDebtTa = publicKey(this.positionDebtLiquidityTa);
|
|
448
447
|
signerDebtTa = publicKey(this.signerDebtLiquidityTa);
|
|
449
448
|
|
|
@@ -516,7 +515,7 @@ export abstract class SolautoClient {
|
|
|
516
515
|
if (this.solautoPositionData !== null && !this.selfManaged) {
|
|
517
516
|
const positionData = this.solautoPositionData!.position;
|
|
518
517
|
if (positionData.dca.debtToAddBaseUnit) {
|
|
519
|
-
debtMint = publicKey(this.
|
|
518
|
+
debtMint = publicKey(this.debtMint);
|
|
520
519
|
positionDebtTa = publicKey(this.positionDebtLiquidityTa);
|
|
521
520
|
signerDebtTa = publicKey(this.signerDebtLiquidityTa);
|
|
522
521
|
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
transactionBuilder,
|
|
12
12
|
createSignerFromKeypair,
|
|
13
13
|
AccountMeta,
|
|
14
|
+
createUmi,
|
|
14
15
|
} from "@metaplex-foundation/umi";
|
|
15
16
|
import {
|
|
16
17
|
Keypair,
|
|
@@ -64,7 +65,7 @@ export interface SolautoMarginfiClientArgs extends SolautoClientArgs {
|
|
|
64
65
|
marginfiGroup?: PublicKey;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
export function
|
|
68
|
+
export function newSolautoMarginfiPositionArgs(
|
|
68
69
|
positionId: number,
|
|
69
70
|
signer: Signer | undefined,
|
|
70
71
|
wallet: WalletAdapter | undefined,
|
|
@@ -76,9 +77,16 @@ export function newMarginfiSolautoManagedPositionArgs(
|
|
|
76
77
|
positionId,
|
|
77
78
|
signer,
|
|
78
79
|
wallet,
|
|
80
|
+
marginfiAccount:
|
|
81
|
+
positionId === 0
|
|
82
|
+
? createSignerFromKeypair(
|
|
83
|
+
createUmi(),
|
|
84
|
+
fromWeb3JsKeypair(Keypair.generate())
|
|
85
|
+
)
|
|
86
|
+
: undefined,
|
|
79
87
|
marginfiAccountSeedIdx: positionId > 0 ? generateRandomU64() : undefined,
|
|
80
|
-
|
|
81
|
-
|
|
88
|
+
supplyMint: supplyMint,
|
|
89
|
+
debtMint: debtMint,
|
|
82
90
|
referredByAuthority,
|
|
83
91
|
};
|
|
84
92
|
}
|
|
@@ -129,10 +137,10 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
129
137
|
: args.marginfiGroup ?? new PublicKey(DEFAULT_MARGINFI_GROUP);
|
|
130
138
|
|
|
131
139
|
this.marginfiSupplyBankAccounts = findMarginfiBankAccounts({
|
|
132
|
-
mint: this.
|
|
140
|
+
mint: this.supplyMint.toString(),
|
|
133
141
|
})!;
|
|
134
142
|
this.marginfiDebtBankAccounts = findMarginfiBankAccounts({
|
|
135
|
-
mint: this.
|
|
143
|
+
mint: this.debtMint.toString(),
|
|
136
144
|
})!;
|
|
137
145
|
|
|
138
146
|
const existingMarginfiAccounts = await getAllMarginfiAccountsByAuthority(
|
|
@@ -218,10 +226,10 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
218
226
|
this.marginfiAccountSeedIdx !== undefined
|
|
219
227
|
? publicKey(this.marginfiAccount)
|
|
220
228
|
: (this.marginfiAccount as Signer),
|
|
221
|
-
supplyMint: publicKey(this.
|
|
229
|
+
supplyMint: publicKey(this.supplyMint),
|
|
222
230
|
supplyBank: publicKey(this.marginfiSupplyBankAccounts.bank),
|
|
223
231
|
positionSupplyTa: publicKey(this.positionSupplyLiquidityTa),
|
|
224
|
-
debtMint: publicKey(this.
|
|
232
|
+
debtMint: publicKey(this.debtMint),
|
|
225
233
|
debtBank: publicKey(this.marginfiDebtBankAccounts.bank),
|
|
226
234
|
positionDebtTa: publicKey(this.positionDebtLiquidityTa),
|
|
227
235
|
signerDebtTa: signerDebtLiquidityTa,
|
|
@@ -370,7 +378,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
370
378
|
flashLoanDetails: FlashLoanDetails,
|
|
371
379
|
destinationTokenAccount: PublicKey
|
|
372
380
|
): TransactionBuilder {
|
|
373
|
-
const bank = flashLoanDetails.mint.equals(this.
|
|
381
|
+
const bank = flashLoanDetails.mint.equals(this.supplyMint)
|
|
374
382
|
? this.marginfiSupplyBankAccounts
|
|
375
383
|
: this.marginfiDebtBankAccounts;
|
|
376
384
|
return transactionBuilder()
|
|
@@ -397,7 +405,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
397
405
|
}
|
|
398
406
|
|
|
399
407
|
flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder {
|
|
400
|
-
const bank = flashLoanDetails.mint.equals(this.
|
|
408
|
+
const bank = flashLoanDetails.mint.equals(this.supplyMint)
|
|
401
409
|
? this.marginfiSupplyBankAccounts
|
|
402
410
|
: this.marginfiDebtBankAccounts;
|
|
403
411
|
|
|
@@ -492,8 +500,8 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
|
492
500
|
const freshState = await getMarginfiAccountPositionState(
|
|
493
501
|
this.umi,
|
|
494
502
|
this.marginfiAccountPk,
|
|
495
|
-
this.
|
|
496
|
-
this.
|
|
503
|
+
this.supplyMint,
|
|
504
|
+
this.debtMint,
|
|
497
505
|
this.livePositionUpdates
|
|
498
506
|
);
|
|
499
507
|
this.log(freshState);
|
|
@@ -40,10 +40,9 @@ import {
|
|
|
40
40
|
rpcAccountCreated,
|
|
41
41
|
} from "../utils/generalUtils";
|
|
42
42
|
import { SolautoMarginfiClient } from "../clients/solautoMarginfiClient";
|
|
43
|
-
import { uint8ArrayToBigInt } from "../utils/numberUtils";
|
|
43
|
+
import { getMaxLiqUtilizationRate, uint8ArrayToBigInt } from "../utils/numberUtils";
|
|
44
44
|
import {
|
|
45
45
|
eligibileForRebalance,
|
|
46
|
-
getMaxLiqUtilizationRate,
|
|
47
46
|
} from "../utils/solauto/generalUtils";
|
|
48
47
|
import { getTokenAccount } from "../utils/accountUtils";
|
|
49
48
|
|
|
@@ -58,8 +57,8 @@ function getWSolUsage(
|
|
|
58
57
|
initiatingDcaIn?: bigint,
|
|
59
58
|
cancellingDcaIn?: boolean
|
|
60
59
|
): wSolTokenUsage | undefined {
|
|
61
|
-
const supplyIsWsol = client.
|
|
62
|
-
const debtIsWsol = client.
|
|
60
|
+
const supplyIsWsol = client.supplyMint.equals(NATIVE_MINT);
|
|
61
|
+
const debtIsWsol = client.debtMint.equals(NATIVE_MINT);
|
|
63
62
|
if (!supplyIsWsol && !debtIsWsol) {
|
|
64
63
|
return undefined;
|
|
65
64
|
}
|
|
@@ -142,7 +141,7 @@ async function transactionChoresBefore(
|
|
|
142
141
|
amountToTransfer += BigInt(wSolUsage.solautoAction.fields[0].fields[0]);
|
|
143
142
|
} else if (
|
|
144
143
|
initiatingDcaIn &&
|
|
145
|
-
client.
|
|
144
|
+
client.debtMint.toString() === NATIVE_MINT.toString()
|
|
146
145
|
) {
|
|
147
146
|
amountToTransfer += initiatingDcaIn;
|
|
148
147
|
}
|
|
@@ -189,8 +188,8 @@ async function transactionChoresBefore(
|
|
|
189
188
|
client.signer,
|
|
190
189
|
toWeb3JsPublicKey(client.signer.publicKey),
|
|
191
190
|
isSolautoAction("Withdraw", solautoAction)
|
|
192
|
-
? client.
|
|
193
|
-
: client.
|
|
191
|
+
? client.supplyMint
|
|
192
|
+
: client.debtMint
|
|
194
193
|
)
|
|
195
194
|
);
|
|
196
195
|
accountsGettingCreated.push(tokenAccount.toString());
|
|
@@ -238,13 +237,13 @@ export async function rebalanceChoresBefore(
|
|
|
238
237
|
if (checkReferralSupplyTa && !rpcAccountCreated(referredBySupplyTa)) {
|
|
239
238
|
client.log(
|
|
240
239
|
"Creating referred-by TA for ",
|
|
241
|
-
client.
|
|
240
|
+
client.supplyMint.toString()
|
|
242
241
|
);
|
|
243
242
|
chores = chores.add(
|
|
244
243
|
createAssociatedTokenAccountUmiIx(
|
|
245
244
|
client.signer,
|
|
246
245
|
client.referredByState!,
|
|
247
|
-
client.
|
|
246
|
+
client.supplyMint
|
|
248
247
|
)
|
|
249
248
|
);
|
|
250
249
|
}
|
|
@@ -252,13 +251,13 @@ export async function rebalanceChoresBefore(
|
|
|
252
251
|
if (checkSolautoFeesTa && !rpcAccountCreated(solautoFeesSupplyTa)) {
|
|
253
252
|
client.log(
|
|
254
253
|
"Creating Solauto fees TA for ",
|
|
255
|
-
client.
|
|
254
|
+
client.supplyMint.toString()
|
|
256
255
|
);
|
|
257
256
|
chores = chores.add(
|
|
258
257
|
createAssociatedTokenAccountUmiIx(
|
|
259
258
|
client.signer,
|
|
260
259
|
client.solautoFeesWallet,
|
|
261
|
-
client.
|
|
260
|
+
client.supplyMint
|
|
262
261
|
)
|
|
263
262
|
);
|
|
264
263
|
}
|
|
@@ -44,7 +44,7 @@ export function arraysAreEqual(arrayA: number[], arrayB: number[]): boolean {
|
|
|
44
44
|
|
|
45
45
|
export async function getTokenPrices(mints: PublicKey[]): Promise<number[]> {
|
|
46
46
|
const currentTime = currentUnixSeconds();
|
|
47
|
-
if (!mints.some(mint => !(mint.toString() in PRICES) || currentTime - PRICES[mint.toString()].time >
|
|
47
|
+
if (!mints.some(mint => !(mint.toString() in PRICES) || currentTime - PRICES[mint.toString()].time > 3)) {
|
|
48
48
|
console.log("Accessing price cache");
|
|
49
49
|
return mints.map(mint => PRICES[mint.toString()].price);
|
|
50
50
|
}
|
|
@@ -64,13 +64,12 @@ export async function getJupSwapTransaction(
|
|
|
64
64
|
: undefined,
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
)
|
|
67
|
+
const finalPriceSlippageBps = Math.round(
|
|
68
|
+
Math.max(
|
|
69
|
+
quoteResponse.slippageBps ?? 10,
|
|
70
|
+
Math.round(toBps(parseFloat(quoteResponse.priceImpactPct)))
|
|
71
|
+
) *
|
|
72
|
+
(1 + (swapDetails.slippageBpsIncFactor ?? 0))
|
|
74
73
|
);
|
|
75
74
|
quoteResponse.slippageBps = finalPriceSlippageBps;
|
|
76
75
|
console.log(quoteResponse);
|
|
@@ -82,7 +81,10 @@ export async function getJupSwapTransaction(
|
|
|
82
81
|
quoteResponse,
|
|
83
82
|
wrapAndUnwrapSol: false,
|
|
84
83
|
useTokenLedger: !swapDetails.exactOut && !swapDetails.exactIn,
|
|
85
|
-
destinationTokenAccount: getTokenAccount(
|
|
84
|
+
destinationTokenAccount: getTokenAccount(
|
|
85
|
+
swapDetails.destinationWallet,
|
|
86
|
+
swapDetails.outputMint
|
|
87
|
+
).toString(),
|
|
86
88
|
},
|
|
87
89
|
});
|
|
88
90
|
|
package/src/utils/numberUtils.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { MAX_REPAY_GAP_BPS } from "../constants";
|
|
2
|
+
|
|
1
3
|
export function getLiqUtilzationRateBps(supplyUsd: number, debtUsd: number, liqThresholdBps: number): number {
|
|
2
4
|
if (supplyUsd === 0) {
|
|
3
5
|
return 0;
|
|
@@ -73,4 +75,25 @@ export function getDebtAdjustmentUsd(
|
|
|
73
75
|
|
|
74
76
|
const debtAdjustmentUsd = (targetLiqUtilizationRate * supplyUsd * liqThreshold - debtUsd) / (1 - targetLiqUtilizationRate * (1 - adjustmentFee) * liqThreshold);
|
|
75
77
|
return debtAdjustmentUsd;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function getMaxLiqUtilizationRate(
|
|
81
|
+
maxLtvBps: number,
|
|
82
|
+
liqThresholdBps: number
|
|
83
|
+
): number {
|
|
84
|
+
return toBps((fromBps(maxLtvBps) - 0.01) / fromBps(liqThresholdBps)) - 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function maxRepayFrom(maxLtvBps: number, liqThresholdBps: number) {
|
|
88
|
+
return Math.min(
|
|
89
|
+
9000,
|
|
90
|
+
getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps - 1000)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function maxRepayTo(maxLtvBps: number, liqThresholdBps: number) {
|
|
95
|
+
return Math.min(
|
|
96
|
+
maxRepayFrom(maxLtvBps, liqThresholdBps) - MAX_REPAY_GAP_BPS,
|
|
97
|
+
getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps)
|
|
98
|
+
);
|
|
76
99
|
}
|
package/src/utils/solanaUtils.ts
CHANGED
|
@@ -293,7 +293,7 @@ export async function sendSingleOptimizedTransaction(
|
|
|
293
293
|
);
|
|
294
294
|
|
|
295
295
|
const computeUnitLimit = Math.round(
|
|
296
|
-
simulationResult.value.unitsConsumed! * 1.
|
|
296
|
+
simulationResult.value.unitsConsumed! * 1.1
|
|
297
297
|
);
|
|
298
298
|
console.log("Compute unit limit: ", computeUnitLimit);
|
|
299
299
|
|
|
@@ -17,12 +17,9 @@ import {
|
|
|
17
17
|
import { currentUnixSeconds, getTokenPrices } from "../generalUtils";
|
|
18
18
|
import {
|
|
19
19
|
fromBaseUnit,
|
|
20
|
-
fromBps,
|
|
21
20
|
getLiqUtilzationRateBps,
|
|
22
21
|
toBaseUnit,
|
|
23
|
-
toBps,
|
|
24
22
|
} from "../numberUtils";
|
|
25
|
-
import { MAX_REPAY_GAP_BPS } from "../../constants/solautoConstants";
|
|
26
23
|
import { getReferralState } from "../accountUtils";
|
|
27
24
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
|
28
25
|
import { USD_DECIMALS } from "../../constants";
|
|
@@ -120,27 +117,6 @@ export function getSolautoFeesBps(
|
|
|
120
117
|
};
|
|
121
118
|
}
|
|
122
119
|
|
|
123
|
-
export function getMaxLiqUtilizationRate(
|
|
124
|
-
maxLtvBps: number,
|
|
125
|
-
liqThresholdBps: number
|
|
126
|
-
): number {
|
|
127
|
-
return toBps((fromBps(maxLtvBps) - 0.015) / fromBps(liqThresholdBps)) - 1;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function maxRepayFrom(maxLtvBps: number, liqThresholdBps: number) {
|
|
131
|
-
return Math.min(
|
|
132
|
-
9000,
|
|
133
|
-
getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps - 1000)
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export function maxRepayTo(maxLtvBps: number, liqThresholdBps: number) {
|
|
138
|
-
return Math.min(
|
|
139
|
-
maxRepayFrom(maxLtvBps, liqThresholdBps) - MAX_REPAY_GAP_BPS,
|
|
140
|
-
getMaxLiqUtilizationRate(maxLtvBps, liqThresholdBps)
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
120
|
export function eligibileForRebalance(
|
|
145
121
|
positionState: PositionState,
|
|
146
122
|
positionSettings: SolautoSettingsParameters,
|
|
@@ -4,7 +4,6 @@ import { PositionTokenUsage } from "../../generated";
|
|
|
4
4
|
import {
|
|
5
5
|
eligibleForNextAutomationPeriod,
|
|
6
6
|
getAdjustedSettingsFromAutomation,
|
|
7
|
-
getMaxLiqUtilizationRate,
|
|
8
7
|
getSolautoFeesBps,
|
|
9
8
|
getUpdatedValueFromAutomation,
|
|
10
9
|
} from "./generalUtils";
|
|
@@ -17,6 +16,7 @@ import {
|
|
|
17
16
|
fromBps,
|
|
18
17
|
getDebtAdjustmentUsd,
|
|
19
18
|
getLiqUtilzationRateBps,
|
|
19
|
+
getMaxLiqUtilizationRate,
|
|
20
20
|
toBaseUnit,
|
|
21
21
|
} from "../numberUtils";
|
|
22
22
|
import { USD_DECIMALS } from "../../constants/generalAccounts";
|
|
@@ -144,8 +144,7 @@ function getTargetRateAndDcaAmount(
|
|
|
144
144
|
};
|
|
145
145
|
} else {
|
|
146
146
|
return {
|
|
147
|
-
targetRateBps:
|
|
148
|
-
getStandardTargetLiqUtilizationRateBps(client),
|
|
147
|
+
targetRateBps: getStandardTargetLiqUtilizationRateBps(client),
|
|
149
148
|
};
|
|
150
149
|
}
|
|
151
150
|
}
|
|
@@ -180,7 +179,7 @@ export function getRebalanceValues(
|
|
|
180
179
|
fromBaseUnit(
|
|
181
180
|
BigInt(Math.round(amountToDcaIn ?? 0)),
|
|
182
181
|
client.solautoPositionState!.debt.decimals
|
|
183
|
-
) * PRICES[client.
|
|
182
|
+
) * PRICES[client.debtMint.toString()].price;
|
|
184
183
|
|
|
185
184
|
const increasingLeverage =
|
|
186
185
|
amountUsdToDcaIn > 0 ||
|
|
@@ -209,13 +208,14 @@ export function getRebalanceValues(
|
|
|
209
208
|
targetRateBps,
|
|
210
209
|
adjustmentFeeBps
|
|
211
210
|
);
|
|
211
|
+
debtAdjustmentUsd *= 500;
|
|
212
212
|
|
|
213
213
|
const input = increasingLeverage
|
|
214
214
|
? client.solautoPositionState!.debt
|
|
215
215
|
: client.solautoPositionState!.supply;
|
|
216
216
|
const inputMarketPrice = increasingLeverage
|
|
217
|
-
? PRICES[client.
|
|
218
|
-
: PRICES[client.
|
|
217
|
+
? PRICES[client.debtMint.toString()].price
|
|
218
|
+
: PRICES[client.supplyMint.toString()].price;
|
|
219
219
|
|
|
220
220
|
const limitGap = limitGapBps
|
|
221
221
|
? fromBps(limitGapBps)
|
|
@@ -270,13 +270,14 @@ export function getFlashLoanDetails(
|
|
|
270
270
|
values.debtAdjustmentUsd > 0
|
|
271
271
|
? debtUsd + debtAdjustmentWithSlippage
|
|
272
272
|
: debtUsd;
|
|
273
|
+
|
|
273
274
|
const tempLiqUtilizationRateBps = getLiqUtilzationRateBps(
|
|
274
275
|
supplyUsd,
|
|
275
276
|
debtUsd,
|
|
276
277
|
client.solautoPositionState!.liqThresholdBps
|
|
277
278
|
);
|
|
278
279
|
const requiresFlashLoan =
|
|
279
|
-
supplyUsd
|
|
280
|
+
supplyUsd <= 0 ||
|
|
280
281
|
tempLiqUtilizationRateBps >
|
|
281
282
|
getMaxLiqUtilizationRate(
|
|
282
283
|
client.solautoPositionState!.maxLtvBps,
|
|
@@ -287,10 +288,10 @@ export function getFlashLoanDetails(
|
|
|
287
288
|
let flashLoanTokenPrice = 0;
|
|
288
289
|
if (values.increasingLeverage) {
|
|
289
290
|
flashLoanToken = client.solautoPositionState!.debt;
|
|
290
|
-
flashLoanTokenPrice = PRICES[client.
|
|
291
|
+
flashLoanTokenPrice = PRICES[client.debtMint.toString()].price;
|
|
291
292
|
} else {
|
|
292
293
|
flashLoanToken = client.solautoPositionState!.supply;
|
|
293
|
-
flashLoanTokenPrice = PRICES[client.
|
|
294
|
+
flashLoanTokenPrice = PRICES[client.supplyMint.toString()].price;
|
|
294
295
|
}
|
|
295
296
|
|
|
296
297
|
const exactAmountBaseUnit =
|
|
@@ -333,8 +334,8 @@ export function getJupSwapRebalanceDetails(
|
|
|
333
334
|
Math.abs(values.debtAdjustmentUsd) + values.amountUsdToDcaIn;
|
|
334
335
|
|
|
335
336
|
const inputPrice = values.increasingLeverage
|
|
336
|
-
? PRICES[client.
|
|
337
|
-
: PRICES[client.
|
|
337
|
+
? PRICES[client.debtMint.toString()].price
|
|
338
|
+
: PRICES[client.supplyMint.toString()].price;
|
|
338
339
|
const inputAmount = toBaseUnit(usdToSwap / inputPrice!, input.decimals);
|
|
339
340
|
|
|
340
341
|
const rebalancingToZero = targetLiqUtilizationRateBps === 0;
|
|
@@ -342,7 +343,7 @@ export function getJupSwapRebalanceDetails(
|
|
|
342
343
|
inputMint: toWeb3JsPublicKey(input.mint),
|
|
343
344
|
outputMint: toWeb3JsPublicKey(output.mint),
|
|
344
345
|
destinationWallet: client.solautoPosition,
|
|
345
|
-
// slippageBpsIncFactor: (values.increasingLeverage ? 0.1 : 0
|
|
346
|
+
// slippageBpsIncFactor: (!values.increasingLeverage ? 0.1 : 0) + ((attemptNum ?? 0) * 0.15),
|
|
346
347
|
slippageBpsIncFactor: (attemptNum ?? 0) * 0.15,
|
|
347
348
|
amount: rebalancingToZero
|
|
348
349
|
? client.solautoPositionState!.debt.amountUsed.baseUnit +
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { describe, it } from
|
|
1
|
+
import { describe, it } from "mocha";
|
|
2
2
|
import { none, some } from "@metaplex-foundation/umi";
|
|
3
3
|
import { setupTest } from "../shared";
|
|
4
4
|
import {
|
|
5
5
|
SolautoMarginfiClient,
|
|
6
|
-
|
|
6
|
+
newSolautoMarginfiPositionArgs,
|
|
7
7
|
} from "../../src/clients/solautoMarginfiClient";
|
|
8
8
|
import {
|
|
9
9
|
solautoAction,
|
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
TransactionItem,
|
|
18
18
|
TransactionsManager,
|
|
19
19
|
} from "../../src/transactions/transactionsManager";
|
|
20
|
+
import { PublicKey } from "@solana/web3.js";
|
|
21
|
+
import { USDC_MINT } from "../../src/constants";
|
|
20
22
|
|
|
21
23
|
describe("Solauto Marginfi tests", async () => {
|
|
22
24
|
const signer = setupTest();
|
|
@@ -33,12 +35,12 @@ describe("Solauto Marginfi tests", async () => {
|
|
|
33
35
|
const debtDecimals = 6;
|
|
34
36
|
|
|
35
37
|
await client.initialize(
|
|
36
|
-
//
|
|
38
|
+
// newSolautoMarginfiPositionArgs(
|
|
37
39
|
// positionId,
|
|
38
40
|
// signer,
|
|
39
41
|
// undefined,
|
|
40
42
|
// supply,
|
|
41
|
-
//
|
|
43
|
+
// new PublicKey(USDC_MINT)
|
|
42
44
|
// )
|
|
43
45
|
{
|
|
44
46
|
signer,
|
|
@@ -92,11 +92,12 @@ async function getFakePosition(
|
|
|
92
92
|
settings: SolautoSettingsParameters,
|
|
93
93
|
dca?: DCASettings
|
|
94
94
|
): Promise<SolautoClient> {
|
|
95
|
-
const client = new SolautoMarginfiClient(true);
|
|
95
|
+
const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY ?? "", true);
|
|
96
96
|
await client.initialize(
|
|
97
97
|
newMarginfiSolautoManagedPositionArgs(
|
|
98
98
|
1,
|
|
99
99
|
signer,
|
|
100
|
+
undefined,
|
|
100
101
|
new PublicKey(NATIVE_MINT),
|
|
101
102
|
new PublicKey(MARGINFI_ACCOUNTS.USDC.mint)
|
|
102
103
|
)
|
|
@@ -124,8 +125,8 @@ async function getFakePosition(
|
|
|
124
125
|
padding: new Uint8Array([]),
|
|
125
126
|
},
|
|
126
127
|
lendingPlatform: LendingPlatform.Marginfi,
|
|
127
|
-
supplyMint: publicKey(client.
|
|
128
|
-
debtMint: publicKey(client.
|
|
128
|
+
supplyMint: publicKey(client.supplyMint),
|
|
129
|
+
debtMint: publicKey(client.debtMint),
|
|
129
130
|
protocolAccount: publicKey(PublicKey.default),
|
|
130
131
|
settingParams: settings,
|
|
131
132
|
padding1: [],
|
|
@@ -267,11 +268,12 @@ describe("Rebalance tests", async () => {
|
|
|
267
268
|
});
|
|
268
269
|
|
|
269
270
|
it("Standard rebalance with target rate", async () => {
|
|
270
|
-
const client = new SolautoMarginfiClient(true);
|
|
271
|
+
const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY ?? "", true);
|
|
271
272
|
await client.initialize(
|
|
272
273
|
newMarginfiSolautoManagedPositionArgs(
|
|
273
274
|
1,
|
|
274
275
|
signer,
|
|
276
|
+
undefined,
|
|
275
277
|
new PublicKey(NATIVE_MINT),
|
|
276
278
|
new PublicKey(MARGINFI_ACCOUNTS.USDC.mint)
|
|
277
279
|
)
|