@haven-fi/solauto-sdk 1.0.134 → 1.0.136
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.map +1 -1
- package/dist/clients/solautoClient.js +49 -39
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +2 -4
- package/dist/generated/accounts/solautoPosition.d.ts +1 -7
- package/dist/generated/accounts/solautoPosition.d.ts.map +1 -1
- package/dist/generated/accounts/solautoPosition.js +2 -6
- package/dist/generated/instructions/cancelDCA.d.ts +3 -3
- package/dist/generated/instructions/cancelDCA.d.ts.map +1 -1
- package/dist/generated/instructions/cancelDCA.js +6 -6
- package/dist/generated/instructions/closePosition.d.ts +1 -2
- package/dist/generated/instructions/closePosition.d.ts.map +1 -1
- package/dist/generated/instructions/closePosition.js +6 -11
- package/dist/generated/instructions/marginfiRebalance.d.ts +2 -2
- package/dist/generated/instructions/marginfiRebalance.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiRebalance.js +4 -4
- package/dist/generated/instructions/updatePosition.d.ts +3 -3
- package/dist/generated/instructions/updatePosition.d.ts.map +1 -1
- package/dist/generated/instructions/updatePosition.js +6 -6
- package/dist/generated/types/dCASettings.d.ts +7 -5
- package/dist/generated/types/dCASettings.d.ts.map +1 -1
- package/dist/generated/types/dCASettings.js +3 -2
- package/dist/generated/types/dCASettingsInp.d.ts +5 -3
- package/dist/generated/types/dCASettingsInp.d.ts.map +1 -1
- package/dist/generated/types/dCASettingsInp.js +2 -1
- package/dist/generated/types/index.d.ts +1 -1
- package/dist/generated/types/index.d.ts.map +1 -1
- package/dist/generated/types/index.js +1 -1
- package/dist/generated/types/{feeType.d.ts → tokenType.d.ts} +6 -6
- package/dist/generated/types/tokenType.d.ts.map +1 -0
- package/dist/generated/types/tokenType.js +22 -0
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +15 -15
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.d.ts +15 -5
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +16 -9
- package/dist/utils/solauto/rebalanceUtils.d.ts +2 -1
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -1
- package/dist/utils/solauto/rebalanceUtils.js +7 -5
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +50 -45
- package/src/clients/solautoMarginfiClient.ts +2 -4
- package/src/generated/accounts/solautoPosition.ts +2 -15
- package/src/generated/instructions/cancelDCA.ts +9 -9
- package/src/generated/instructions/closePosition.ts +7 -13
- package/src/generated/instructions/marginfiRebalance.ts +6 -6
- package/src/generated/instructions/updatePosition.ts +9 -9
- package/src/generated/types/dCASettings.ts +14 -7
- package/src/generated/types/dCASettingsInp.ts +9 -3
- package/src/generated/types/index.ts +1 -1
- package/src/generated/types/{feeType.ts → tokenType.ts} +8 -9
- package/src/transactions/transactionUtils.ts +35 -25
- package/src/utils/marginfiUtils.ts +2 -2
- package/src/utils/solauto/generalUtils.ts +21 -13
- package/src/utils/solauto/rebalanceUtils.ts +9 -8
- package/tests/unit/rebalanceCalculations.ts +14 -14
- package/dist/generated/types/feeType.d.ts.map +0 -1
- package/dist/generated/types/feeType.js +0 -20
@@ -52,13 +52,13 @@ export type MarginfiRebalanceInstructionAccounts = {
|
|
52
52
|
supplyBank: PublicKey | Pda;
|
53
53
|
supplyPriceOracle?: PublicKey | Pda;
|
54
54
|
positionSupplyTa: PublicKey | Pda;
|
55
|
-
|
55
|
+
authoritySupplyTa?: PublicKey | Pda;
|
56
56
|
vaultSupplyTa?: PublicKey | Pda;
|
57
57
|
supplyVaultAuthority?: PublicKey | Pda;
|
58
58
|
debtBank: PublicKey | Pda;
|
59
59
|
debtPriceOracle?: PublicKey | Pda;
|
60
60
|
positionDebtTa: PublicKey | Pda;
|
61
|
-
|
61
|
+
authorityDebtTa?: PublicKey | Pda;
|
62
62
|
vaultDebtTa?: PublicKey | Pda;
|
63
63
|
debtVaultAuthority?: PublicKey | Pda;
|
64
64
|
};
|
@@ -197,10 +197,10 @@ export function marginfiRebalance(
|
|
197
197
|
isWritable: true as boolean,
|
198
198
|
value: input.positionSupplyTa ?? null,
|
199
199
|
},
|
200
|
-
|
200
|
+
authoritySupplyTa: {
|
201
201
|
index: 15,
|
202
202
|
isWritable: true as boolean,
|
203
|
-
value: input.
|
203
|
+
value: input.authoritySupplyTa ?? null,
|
204
204
|
},
|
205
205
|
vaultSupplyTa: {
|
206
206
|
index: 16,
|
@@ -227,10 +227,10 @@ export function marginfiRebalance(
|
|
227
227
|
isWritable: true as boolean,
|
228
228
|
value: input.positionDebtTa ?? null,
|
229
229
|
},
|
230
|
-
|
230
|
+
authorityDebtTa: {
|
231
231
|
index: 21,
|
232
232
|
isWritable: true as boolean,
|
233
|
-
value: input.
|
233
|
+
value: input.authorityDebtTa ?? null,
|
234
234
|
},
|
235
235
|
vaultDebtTa: {
|
236
236
|
index: 22,
|
@@ -37,9 +37,9 @@ export type UpdatePositionInstructionAccounts = {
|
|
37
37
|
systemProgram?: PublicKey | Pda;
|
38
38
|
tokenProgram?: PublicKey | Pda;
|
39
39
|
solautoPosition: PublicKey | Pda;
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
dcaMint?: PublicKey | Pda;
|
41
|
+
positionDcaTa?: PublicKey | Pda;
|
42
|
+
signerDcaTa?: PublicKey | Pda;
|
43
43
|
};
|
44
44
|
|
45
45
|
// Data.
|
@@ -111,20 +111,20 @@ export function updatePosition(
|
|
111
111
|
isWritable: true as boolean,
|
112
112
|
value: input.solautoPosition ?? null,
|
113
113
|
},
|
114
|
-
|
114
|
+
dcaMint: {
|
115
115
|
index: 4,
|
116
116
|
isWritable: false as boolean,
|
117
|
-
value: input.
|
117
|
+
value: input.dcaMint ?? null,
|
118
118
|
},
|
119
|
-
|
119
|
+
positionDcaTa: {
|
120
120
|
index: 5,
|
121
121
|
isWritable: true as boolean,
|
122
|
-
value: input.
|
122
|
+
value: input.positionDcaTa ?? null,
|
123
123
|
},
|
124
|
-
|
124
|
+
signerDcaTa: {
|
125
125
|
index: 6,
|
126
126
|
isWritable: true as boolean,
|
127
|
-
value: input.
|
127
|
+
value: input.signerDcaTa ?? null,
|
128
128
|
},
|
129
129
|
} satisfies ResolvedAccountsWithIndices;
|
130
130
|
|
@@ -8,26 +8,32 @@
|
|
8
8
|
|
9
9
|
import {
|
10
10
|
Serializer,
|
11
|
-
|
11
|
+
array,
|
12
12
|
struct,
|
13
13
|
u64,
|
14
|
+
u8,
|
14
15
|
} from '@metaplex-foundation/umi/serializers';
|
15
16
|
import {
|
16
17
|
AutomationSettings,
|
17
18
|
AutomationSettingsArgs,
|
19
|
+
TokenType,
|
20
|
+
TokenTypeArgs,
|
18
21
|
getAutomationSettingsSerializer,
|
22
|
+
getTokenTypeSerializer,
|
19
23
|
} from '.';
|
20
24
|
|
21
25
|
export type DCASettings = {
|
22
26
|
automation: AutomationSettings;
|
23
|
-
|
24
|
-
|
27
|
+
dcaInBaseUnit: bigint;
|
28
|
+
tokenType: TokenType;
|
29
|
+
padding: Array<number>;
|
25
30
|
};
|
26
31
|
|
27
32
|
export type DCASettingsArgs = {
|
28
33
|
automation: AutomationSettingsArgs;
|
29
|
-
|
30
|
-
|
34
|
+
dcaInBaseUnit: number | bigint;
|
35
|
+
tokenType: TokenTypeArgs;
|
36
|
+
padding: Array<number>;
|
31
37
|
};
|
32
38
|
|
33
39
|
export function getDCASettingsSerializer(): Serializer<
|
@@ -37,8 +43,9 @@ export function getDCASettingsSerializer(): Serializer<
|
|
37
43
|
return struct<DCASettings>(
|
38
44
|
[
|
39
45
|
['automation', getAutomationSettingsSerializer()],
|
40
|
-
['
|
41
|
-
['
|
46
|
+
['dcaInBaseUnit', u64()],
|
47
|
+
['tokenType', getTokenTypeSerializer()],
|
48
|
+
['padding', array(u8(), { size: 31 })],
|
42
49
|
],
|
43
50
|
{ description: 'DCASettings' }
|
44
51
|
) as Serializer<DCASettingsArgs, DCASettings>;
|
@@ -10,17 +10,22 @@ import { Serializer, struct, u64 } from '@metaplex-foundation/umi/serializers';
|
|
10
10
|
import {
|
11
11
|
AutomationSettingsInp,
|
12
12
|
AutomationSettingsInpArgs,
|
13
|
+
TokenType,
|
14
|
+
TokenTypeArgs,
|
13
15
|
getAutomationSettingsInpSerializer,
|
16
|
+
getTokenTypeSerializer,
|
14
17
|
} from '.';
|
15
18
|
|
16
19
|
export type DCASettingsInp = {
|
17
20
|
automation: AutomationSettingsInp;
|
18
|
-
|
21
|
+
dcaInBaseUnit: bigint;
|
22
|
+
tokenType: TokenType;
|
19
23
|
};
|
20
24
|
|
21
25
|
export type DCASettingsInpArgs = {
|
22
26
|
automation: AutomationSettingsInpArgs;
|
23
|
-
|
27
|
+
dcaInBaseUnit: number | bigint;
|
28
|
+
tokenType: TokenTypeArgs;
|
24
29
|
};
|
25
30
|
|
26
31
|
export function getDCASettingsInpSerializer(): Serializer<
|
@@ -30,7 +35,8 @@ export function getDCASettingsInpSerializer(): Serializer<
|
|
30
35
|
return struct<DCASettingsInp>(
|
31
36
|
[
|
32
37
|
['automation', getAutomationSettingsInpSerializer()],
|
33
|
-
['
|
38
|
+
['dcaInBaseUnit', u64()],
|
39
|
+
['tokenType', getTokenTypeSerializer()],
|
34
40
|
],
|
35
41
|
{ description: 'DCASettingsInp' }
|
36
42
|
) as Serializer<DCASettingsInpArgs, DCASettingsInp>;
|
@@ -10,7 +10,6 @@ export * from './automationSettings';
|
|
10
10
|
export * from './automationSettingsInp';
|
11
11
|
export * from './dCASettings';
|
12
12
|
export * from './dCASettingsInp';
|
13
|
-
export * from './feeType';
|
14
13
|
export * from './lendingPlatform';
|
15
14
|
export * from './podBool';
|
16
15
|
export * from './positionData';
|
@@ -23,4 +22,5 @@ export * from './solautoSettingsParameters';
|
|
23
22
|
export * from './solautoSettingsParametersInp';
|
24
23
|
export * from './tokenAmount';
|
25
24
|
export * from './tokenBalanceAmount';
|
25
|
+
export * from './tokenType';
|
26
26
|
export * from './updatePositionData';
|
@@ -8,16 +8,15 @@
|
|
8
8
|
|
9
9
|
import { Serializer, scalarEnum } from '@metaplex-foundation/umi/serializers';
|
10
10
|
|
11
|
-
export enum
|
12
|
-
|
13
|
-
|
11
|
+
export enum TokenType {
|
12
|
+
Supply,
|
13
|
+
Debt,
|
14
14
|
}
|
15
15
|
|
16
|
-
export type
|
16
|
+
export type TokenTypeArgs = TokenType;
|
17
17
|
|
18
|
-
export function
|
19
|
-
return scalarEnum<
|
20
|
-
|
21
|
-
|
22
|
-
>;
|
18
|
+
export function getTokenTypeSerializer(): Serializer<TokenTypeArgs, TokenType> {
|
19
|
+
return scalarEnum<TokenType>(TokenType, {
|
20
|
+
description: 'TokenType',
|
21
|
+
}) as Serializer<TokenTypeArgs, TokenType>;
|
23
22
|
}
|
@@ -17,6 +17,7 @@ import {
|
|
17
17
|
SOLAUTO_PROGRAM_ID,
|
18
18
|
SolautoAction,
|
19
19
|
SolautoRebalanceType,
|
20
|
+
TokenType,
|
20
21
|
convertReferralFees,
|
21
22
|
getMarginfiProtocolInteractionInstructionDataSerializer,
|
22
23
|
getMarginfiRebalanceInstructionDataSerializer,
|
@@ -55,18 +56,20 @@ import {
|
|
55
56
|
getLendingAccountWithdrawInstructionDataSerializer,
|
56
57
|
MARGINFI_PROGRAM_ID,
|
57
58
|
} from "../marginfi-sdk";
|
58
|
-
import { PRICES } from "../constants";
|
59
59
|
|
60
60
|
interface wSolTokenUsage {
|
61
61
|
wSolTokenAccount: PublicKey;
|
62
|
-
solautoAction
|
62
|
+
solautoAction?: SolautoAction;
|
63
63
|
}
|
64
64
|
|
65
65
|
function getWSolUsage(
|
66
66
|
client: SolautoClient,
|
67
67
|
solautoActions?: SolautoAction[],
|
68
|
-
initiatingDcaIn?:
|
69
|
-
|
68
|
+
initiatingDcaIn?: {
|
69
|
+
amount: bigint;
|
70
|
+
tokenType: TokenType;
|
71
|
+
},
|
72
|
+
cancellingDcaIn?: TokenType
|
70
73
|
): wSolTokenUsage | undefined {
|
71
74
|
const supplyIsWsol = client.supplyMint.equals(NATIVE_MINT);
|
72
75
|
const debtIsWsol = client.debtMint.equals(NATIVE_MINT);
|
@@ -79,18 +82,23 @@ function getWSolUsage(
|
|
79
82
|
isSolautoAction("Deposit", args) || isSolautoAction("Withdraw", args)
|
80
83
|
);
|
81
84
|
const usingDebtTaAction = solautoActions?.find(
|
82
|
-
(args) =>
|
83
|
-
isSolautoAction("Borrow", args) ||
|
84
|
-
isSolautoAction("Repay", args) ||
|
85
|
-
initiatingDcaIn ||
|
86
|
-
cancellingDcaIn
|
85
|
+
(args) => isSolautoAction("Borrow", args) || isSolautoAction("Repay", args)
|
87
86
|
);
|
88
|
-
|
87
|
+
|
88
|
+
const dcaSupply =
|
89
|
+
(initiatingDcaIn && initiatingDcaIn.tokenType === TokenType.Supply) ||
|
90
|
+
(cancellingDcaIn !== undefined && cancellingDcaIn === TokenType.Supply);
|
91
|
+
|
92
|
+
const dcaDebt =
|
93
|
+
(initiatingDcaIn && initiatingDcaIn.tokenType === TokenType.Debt) ||
|
94
|
+
(cancellingDcaIn !== undefined && cancellingDcaIn === TokenType.Debt);
|
95
|
+
|
96
|
+
if (supplyIsWsol && (usingSupplyTaAction || dcaSupply)) {
|
89
97
|
return {
|
90
98
|
wSolTokenAccount: client.signerSupplyTa,
|
91
99
|
solautoAction: usingSupplyTaAction,
|
92
100
|
};
|
93
|
-
} else if (debtIsWsol && usingDebtTaAction) {
|
101
|
+
} else if (debtIsWsol && (usingDebtTaAction || dcaDebt)) {
|
94
102
|
return {
|
95
103
|
wSolTokenAccount: client.signerDebtTa,
|
96
104
|
solautoAction: usingDebtTaAction,
|
@@ -104,7 +112,10 @@ async function transactionChoresBefore(
|
|
104
112
|
client: SolautoClient,
|
105
113
|
accountsGettingCreated: string[],
|
106
114
|
solautoActions?: SolautoAction[],
|
107
|
-
initiatingDcaIn?:
|
115
|
+
initiatingDcaIn?: {
|
116
|
+
amount: bigint;
|
117
|
+
tokenType: TokenType;
|
118
|
+
}
|
108
119
|
): Promise<TransactionBuilder> {
|
109
120
|
let chores = transactionBuilder();
|
110
121
|
|
@@ -162,18 +173,19 @@ async function transactionChoresBefore(
|
|
162
173
|
}
|
163
174
|
|
164
175
|
let amountToTransfer = BigInt(0);
|
165
|
-
if (
|
176
|
+
if (
|
177
|
+
wSolUsage.solautoAction &&
|
178
|
+
isSolautoAction("Deposit", wSolUsage.solautoAction)
|
179
|
+
) {
|
166
180
|
amountToTransfer = BigInt(wSolUsage.solautoAction.fields[0]);
|
167
181
|
} else if (
|
182
|
+
wSolUsage.solautoAction &&
|
168
183
|
isSolautoAction("Repay", wSolUsage.solautoAction) &&
|
169
184
|
wSolUsage.solautoAction.fields[0].__kind === "Some"
|
170
185
|
) {
|
171
186
|
amountToTransfer = BigInt(wSolUsage.solautoAction.fields[0].fields[0]);
|
172
|
-
} else if (
|
173
|
-
initiatingDcaIn
|
174
|
-
client.debtMint.toString() === NATIVE_MINT.toString()
|
175
|
-
) {
|
176
|
-
amountToTransfer = initiatingDcaIn;
|
187
|
+
} else if (initiatingDcaIn) {
|
188
|
+
amountToTransfer = initiatingDcaIn.amount;
|
177
189
|
}
|
178
190
|
|
179
191
|
if (amountToTransfer > 0) {
|
@@ -349,7 +361,7 @@ export async function rebalanceChoresBefore(
|
|
349
361
|
function transactionChoresAfter(
|
350
362
|
client: SolautoClient,
|
351
363
|
solautoActions?: SolautoAction[],
|
352
|
-
cancellingDcaIn?:
|
364
|
+
cancellingDcaIn?: TokenType
|
353
365
|
): TransactionBuilder {
|
354
366
|
let chores = transactionBuilder();
|
355
367
|
|
@@ -538,9 +550,7 @@ export async function getTransactionChores(
|
|
538
550
|
client,
|
539
551
|
accountsGettingCreated,
|
540
552
|
solautoActions,
|
541
|
-
client.livePositionUpdates.
|
542
|
-
? client.livePositionUpdates.debtTaBalanceAdjustment
|
543
|
-
: undefined
|
553
|
+
client.livePositionUpdates.dcaInBalance
|
544
554
|
),
|
545
555
|
await rebalanceChoresBefore(client, tx, accountsGettingCreated),
|
546
556
|
]);
|
@@ -549,7 +559,7 @@ export async function getTransactionChores(
|
|
549
559
|
transactionChoresAfter(
|
550
560
|
client,
|
551
561
|
solautoActions,
|
552
|
-
client.livePositionUpdates.
|
562
|
+
client.livePositionUpdates.cancellingDca
|
553
563
|
)
|
554
564
|
);
|
555
565
|
|
@@ -668,8 +678,8 @@ export async function buildSolautoRebalanceTransaction(
|
|
668
678
|
"B",
|
669
679
|
swapDetails,
|
670
680
|
rebalanceType,
|
671
|
-
|
672
|
-
|
681
|
+
jupQuote.slippageBps,
|
682
|
+
undefined,
|
673
683
|
targetLiqUtilizationRateBps
|
674
684
|
),
|
675
685
|
]);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import { publicKey,
|
2
|
+
import { publicKey, Umi } from "@metaplex-foundation/umi";
|
3
3
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
4
4
|
import {
|
5
5
|
Bank,
|
@@ -16,13 +16,13 @@ import {
|
|
16
16
|
toBaseUnit,
|
17
17
|
toBps,
|
18
18
|
} from "./numberUtils";
|
19
|
-
import { PRICES } from "../constants/solautoConstants";
|
20
19
|
import { MARGINFI_ACCOUNTS } from "../constants/marginfiAccounts";
|
21
20
|
import { MarginfiAssetAccounts } from "../types/accounts";
|
22
21
|
import { PositionState, PositionTokenUsage } from "../generated";
|
23
22
|
import { USD_DECIMALS } from "../constants/generalAccounts";
|
24
23
|
import { LivePositionUpdates } from "./solauto/generalUtils";
|
25
24
|
import { currentUnixSecondsSolana } from "./solanaUtils";
|
25
|
+
import { USDC_MINT } from "../constants";
|
26
26
|
|
27
27
|
export function findMarginfiAccounts(bank: PublicKey): MarginfiAssetAccounts {
|
28
28
|
for (const key in MARGINFI_ACCOUNTS) {
|
@@ -9,6 +9,7 @@ import {
|
|
9
9
|
SOLAUTO_PROGRAM_ID,
|
10
10
|
SolautoSettingsParameters,
|
11
11
|
SolautoSettingsParametersInpArgs,
|
12
|
+
TokenType,
|
12
13
|
getReferralStateSize,
|
13
14
|
getSolautoPositionAccountDataSerializer,
|
14
15
|
getSolautoPositionSize,
|
@@ -487,24 +488,24 @@ export function createSolautoSettings(
|
|
487
488
|
type PositionAdjustment =
|
488
489
|
| { type: "supply"; value: bigint }
|
489
490
|
| { type: "debt"; value: bigint }
|
490
|
-
| { type: "debtDcaIn"; value: bigint }
|
491
491
|
| { type: "settings"; value: SolautoSettingsParametersInpArgs }
|
492
|
-
| { type: "dca"; value: DCASettingsInpArgs }
|
492
|
+
| { type: "dca"; value: DCASettingsInpArgs }
|
493
|
+
| { type: "dcaInBalance"; value: { amount: bigint; tokenType: TokenType; } }
|
494
|
+
| { type: "cancellingDca"; value: TokenType; };
|
493
495
|
|
494
496
|
export class LivePositionUpdates {
|
495
|
-
public supplyAdjustment
|
496
|
-
public debtAdjustment
|
497
|
-
public debtTaBalanceAdjustment: bigint = BigInt(0);
|
497
|
+
public supplyAdjustment = BigInt(0);
|
498
|
+
public debtAdjustment = BigInt(0);
|
498
499
|
public settings: SolautoSettingsParameters | undefined = undefined;
|
499
500
|
public activeDca: DCASettings | undefined = undefined;
|
500
|
-
|
501
|
+
public dcaInBalance?: { amount: bigint; tokenType: TokenType; } = undefined;
|
502
|
+
public cancellingDca: TokenType | undefined = undefined;
|
503
|
+
|
501
504
|
new(update: PositionAdjustment) {
|
502
505
|
if (update.type === "supply") {
|
503
506
|
this.supplyAdjustment += update.value;
|
504
507
|
} else if (update.type === "debt") {
|
505
508
|
this.debtAdjustment += update.value;
|
506
|
-
} else if (update.type === "debtDcaIn") {
|
507
|
-
this.debtTaBalanceAdjustment += update.value;
|
508
509
|
} else if (update.type === "settings") {
|
509
510
|
const settings = update.value;
|
510
511
|
this.settings = createSolautoSettings(settings);
|
@@ -518,26 +519,33 @@ export class LivePositionUpdates {
|
|
518
519
|
padding: new Uint8Array([]),
|
519
520
|
padding1: [],
|
520
521
|
},
|
521
|
-
|
522
|
-
|
522
|
+
dcaInBaseUnit: BigInt(dca.dcaInBaseUnit),
|
523
|
+
tokenType: dca.tokenType,
|
524
|
+
padding: [],
|
523
525
|
};
|
526
|
+
} else if (update.type === "cancellingDca") {
|
527
|
+
this.cancellingDca = update.value;
|
528
|
+
} else if (update.type === "dcaInBalance") {
|
529
|
+
this.dcaInBalance = update.value;
|
524
530
|
}
|
525
531
|
}
|
526
532
|
|
527
533
|
reset() {
|
528
534
|
this.supplyAdjustment = BigInt(0);
|
529
535
|
this.debtAdjustment = BigInt(0);
|
530
|
-
this.debtTaBalanceAdjustment = BigInt(0);
|
531
536
|
this.settings = undefined;
|
532
537
|
this.activeDca = undefined;
|
538
|
+
this.dcaInBalance = undefined;
|
539
|
+
this.cancellingDca = undefined;
|
533
540
|
}
|
534
541
|
|
535
542
|
hasUpdates(): boolean {
|
536
543
|
return (
|
537
544
|
this.supplyAdjustment !== BigInt(0) ||
|
538
545
|
this.debtAdjustment !== BigInt(0) ||
|
539
|
-
this.
|
540
|
-
this.settings !== undefined
|
546
|
+
this.dcaInBalance !== undefined ||
|
547
|
+
this.settings !== undefined ||
|
548
|
+
this.cancellingDca !== undefined
|
541
549
|
);
|
542
550
|
}
|
543
551
|
}
|
@@ -5,6 +5,7 @@ import {
|
|
5
5
|
PositionState,
|
6
6
|
PositionTokenUsage,
|
7
7
|
SolautoSettingsParameters,
|
8
|
+
TokenType,
|
8
9
|
} from "../../generated";
|
9
10
|
import {
|
10
11
|
eligibleForNextAutomationPeriod,
|
@@ -27,16 +28,14 @@ import {
|
|
27
28
|
import { USD_DECIMALS } from "../../constants/generalAccounts";
|
28
29
|
import {
|
29
30
|
DEFAULT_LIMIT_GAP_BPS,
|
30
|
-
MIN_POSITION_STATE_FRESHNESS_SECS,
|
31
|
-
PRICES,
|
32
31
|
} from "../../constants/solautoConstants";
|
33
32
|
|
34
33
|
function getAdditionalAmountToDcaIn(dca: DCASettings): number {
|
35
|
-
if (dca.
|
34
|
+
if (dca.dcaInBaseUnit === BigInt(0)) {
|
36
35
|
return 0;
|
37
36
|
}
|
38
37
|
|
39
|
-
const debtBalance = Number(dca.
|
38
|
+
const debtBalance = Number(dca.dcaInBaseUnit);
|
40
39
|
const updatedDebtBalance = getUpdatedValueFromAutomation(
|
41
40
|
debtBalance,
|
42
41
|
0,
|
@@ -80,7 +79,7 @@ function targetLiqUtilizationRateBpsFromDCA(
|
|
80
79
|
);
|
81
80
|
|
82
81
|
let targetRateBps = 0;
|
83
|
-
if (dca.
|
82
|
+
if (dca.dcaInBaseUnit > BigInt(0)) {
|
84
83
|
targetRateBps = Math.max(
|
85
84
|
state.liqUtilizationRateBps,
|
86
85
|
adjustedSettings.boostToBps
|
@@ -126,7 +125,7 @@ function getTargetRateAndDcaAmount(
|
|
126
125
|
dca: DCASettings | undefined,
|
127
126
|
currentUnixTime: number,
|
128
127
|
targetLiqUtilizationRateBps?: number
|
129
|
-
): { targetRateBps: number; amountToDcaIn?: number } {
|
128
|
+
): { targetRateBps: number; amountToDcaIn?: number; } {
|
130
129
|
if (targetLiqUtilizationRateBps !== undefined) {
|
131
130
|
return {
|
132
131
|
targetRateBps: targetLiqUtilizationRateBps,
|
@@ -164,6 +163,7 @@ export interface RebalanceValues {
|
|
164
163
|
debtAdjustmentUsd: number;
|
165
164
|
amountToDcaIn: number;
|
166
165
|
amountUsdToDcaIn: number;
|
166
|
+
dcaTokenType?: TokenType;
|
167
167
|
}
|
168
168
|
|
169
169
|
export function getRebalanceValues(
|
@@ -238,6 +238,7 @@ export function getRebalanceValues(
|
|
238
238
|
debtAdjustmentUsd,
|
239
239
|
amountToDcaIn: amountToDcaIn ?? 0,
|
240
240
|
amountUsdToDcaIn,
|
241
|
+
dcaTokenType: dca?.tokenType
|
241
242
|
};
|
242
243
|
}
|
243
244
|
|
@@ -254,7 +255,7 @@ export function getFlashLoanDetails(
|
|
254
255
|
let supplyUsd = fromBaseUnit(
|
255
256
|
client.solautoPositionState!.supply.amountUsed.baseAmountUsdValue,
|
256
257
|
USD_DECIMALS
|
257
|
-
);
|
258
|
+
) + (values.dcaTokenType === TokenType.Supply ? values.amountUsdToDcaIn : 0);
|
258
259
|
let debtUsd = fromBaseUnit(
|
259
260
|
client.solautoPositionState!.debt.amountUsed.baseAmountUsdValue,
|
260
261
|
USD_DECIMALS
|
@@ -333,7 +334,7 @@ export function getJupSwapRebalanceDetails(
|
|
333
334
|
: client.solautoPositionState!.debt;
|
334
335
|
|
335
336
|
const usdToSwap =
|
336
|
-
Math.abs(values.debtAdjustmentUsd) + values.amountUsdToDcaIn;
|
337
|
+
Math.abs(values.debtAdjustmentUsd) + (values.dcaTokenType === TokenType.Debt ? values.amountUsdToDcaIn : 0);
|
337
338
|
|
338
339
|
const inputPrice = values.increasingLeverage
|
339
340
|
? safeGetPrice(client.debtMint)
|
@@ -9,10 +9,10 @@ import { publicKey } from "@metaplex-foundation/umi";
|
|
9
9
|
import { SolautoClient } from "../../src/clients/solautoClient";
|
10
10
|
import {
|
11
11
|
DCASettings,
|
12
|
-
FeeType,
|
13
12
|
LendingPlatform,
|
14
13
|
SolautoRebalanceType,
|
15
14
|
SolautoSettingsParameters,
|
15
|
+
TokenType,
|
16
16
|
} from "../../src/generated";
|
17
17
|
import {
|
18
18
|
fromBaseUnit,
|
@@ -35,7 +35,6 @@ import {
|
|
35
35
|
safeGetPrice,
|
36
36
|
} from "../../src/utils/generalUtils";
|
37
37
|
import { USDC_MINT } from "../../src/constants/tokenConstants";
|
38
|
-
import { PRICES } from "../../src/constants";
|
39
38
|
|
40
39
|
const signer = setupTest(undefined, true);
|
41
40
|
|
@@ -159,8 +158,9 @@ async function getFakePosition(
|
|
159
158
|
padding1: [],
|
160
159
|
padding: new Uint8Array([]),
|
161
160
|
},
|
162
|
-
|
163
|
-
|
161
|
+
dcaInBaseUnit: BigInt(0),
|
162
|
+
tokenType: TokenType.Debt,
|
163
|
+
padding: [],
|
164
164
|
},
|
165
165
|
lendingPlatform: LendingPlatform.Marginfi,
|
166
166
|
supplyMint: publicKey(client.supplyMint),
|
@@ -180,9 +180,7 @@ async function getFakePosition(
|
|
180
180
|
padding2: [],
|
181
181
|
padding: new Uint8Array([]),
|
182
182
|
},
|
183
|
-
feeType: FeeType.Default,
|
184
183
|
padding1: [],
|
185
|
-
padding2: [],
|
186
184
|
padding: [],
|
187
185
|
publicKey: publicKey(PublicKey.default),
|
188
186
|
header: {
|
@@ -246,18 +244,18 @@ async function dcaRebalanceFromFakePosition(
|
|
246
244
|
currentUnixSeconds()
|
247
245
|
);
|
248
246
|
const expectedLiqUtilizationRateBps =
|
249
|
-
dca.
|
247
|
+
dca.dcaInBaseUnit > BigInt(0)
|
250
248
|
? Math.max(fakeLiqUtilizationRateBps, adjustedSettings.boostToBps)
|
251
249
|
: adjustedSettings.boostToBps;
|
252
250
|
|
253
251
|
const expectedDcaInAmount =
|
254
|
-
dca.
|
252
|
+
dca.dcaInBaseUnit > BigInt(0) &&
|
255
253
|
eligibleForNextAutomationPeriod(dca.automation, currentUnixSeconds())
|
256
|
-
? dca.
|
254
|
+
? dca.dcaInBaseUnit -
|
257
255
|
BigInt(
|
258
256
|
Math.round(
|
259
257
|
getUpdatedValueFromAutomation(
|
260
|
-
Number(dca.
|
258
|
+
Number(dca.dcaInBaseUnit),
|
261
259
|
0,
|
262
260
|
dca.automation,
|
263
261
|
currentUnixSeconds()
|
@@ -390,8 +388,9 @@ describe("Rebalance tests", async () => {
|
|
390
388
|
padding1: [],
|
391
389
|
padding: new Uint8Array([]),
|
392
390
|
},
|
393
|
-
|
394
|
-
|
391
|
+
dcaInBaseUnit: BigInt(0),
|
392
|
+
tokenType: TokenType.Debt,
|
393
|
+
padding: [],
|
395
394
|
};
|
396
395
|
await dcaRebalanceFromFakePosition(
|
397
396
|
supplyPrice,
|
@@ -442,8 +441,9 @@ describe("Rebalance tests", async () => {
|
|
442
441
|
padding1: [],
|
443
442
|
padding: new Uint8Array([]),
|
444
443
|
},
|
445
|
-
|
446
|
-
|
444
|
+
dcaInBaseUnit: toBaseUnit(debtPrice * 300, 6),
|
445
|
+
tokenType: TokenType.Debt,
|
446
|
+
padding: [],
|
447
447
|
};
|
448
448
|
await dcaRebalanceFromFakePosition(
|
449
449
|
supplyPrice,
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"feeType.d.ts","sourceRoot":"","sources":["../../../src/generated/types/feeType.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAc,MAAM,sCAAsC,CAAC;AAE9E,oBAAY,OAAO;IACjB,KAAK,IAAA;IACL,OAAO,IAAA;CACR;AAED,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC;AAElC,wBAAgB,oBAAoB,IAAI,UAAU,CAAC,WAAW,EAAE,OAAO,CAAC,CAKvE"}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
/**
|
3
|
-
* This code was AUTOGENERATED using the kinobi library.
|
4
|
-
* Please DO NOT EDIT THIS FILE, instead use visitors
|
5
|
-
* to add features, then rerun kinobi to update it.
|
6
|
-
*
|
7
|
-
* @see https://github.com/metaplex-foundation/kinobi
|
8
|
-
*/
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
10
|
-
exports.FeeType = void 0;
|
11
|
-
exports.getFeeTypeSerializer = getFeeTypeSerializer;
|
12
|
-
const serializers_1 = require("@metaplex-foundation/umi/serializers");
|
13
|
-
var FeeType;
|
14
|
-
(function (FeeType) {
|
15
|
-
FeeType[FeeType["Small"] = 0] = "Small";
|
16
|
-
FeeType[FeeType["Default"] = 1] = "Default";
|
17
|
-
})(FeeType || (exports.FeeType = FeeType = {}));
|
18
|
-
function getFeeTypeSerializer() {
|
19
|
-
return (0, serializers_1.scalarEnum)(FeeType, { description: 'FeeType' });
|
20
|
-
}
|