@haven-fi/solauto-sdk 1.0.133 → 1.0.135
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +49 -39
- 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/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 +54 -37
- 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/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/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 +75 -59
- 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
@@ -1,6 +1,6 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { Umi } from "@metaplex-foundation/umi";
|
3
|
-
import { AutomationSettings, DCASettings, DCASettingsInpArgs, PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs } from "../../generated";
|
3
|
+
import { AutomationSettings, DCASettings, DCASettingsInpArgs, PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs, TokenType } from "../../generated";
|
4
4
|
import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
|
5
5
|
export declare function findMintByTicker(ticker: string): PublicKey;
|
6
6
|
export declare function nextAutomationPeriodTimestamp(automation: AutomationSettings): number;
|
@@ -27,22 +27,32 @@ type PositionAdjustment = {
|
|
27
27
|
} | {
|
28
28
|
type: "debt";
|
29
29
|
value: bigint;
|
30
|
-
} | {
|
31
|
-
type: "debtDcaIn";
|
32
|
-
value: bigint;
|
33
30
|
} | {
|
34
31
|
type: "settings";
|
35
32
|
value: SolautoSettingsParametersInpArgs;
|
36
33
|
} | {
|
37
34
|
type: "dca";
|
38
35
|
value: DCASettingsInpArgs;
|
36
|
+
} | {
|
37
|
+
type: "dcaInBalance";
|
38
|
+
value: {
|
39
|
+
amount: bigint;
|
40
|
+
tokenType: TokenType;
|
41
|
+
};
|
42
|
+
} | {
|
43
|
+
type: "cancellingDca";
|
44
|
+
value: TokenType;
|
39
45
|
};
|
40
46
|
export declare class LivePositionUpdates {
|
41
47
|
supplyAdjustment: bigint;
|
42
48
|
debtAdjustment: bigint;
|
43
|
-
debtTaBalanceAdjustment: bigint;
|
44
49
|
settings: SolautoSettingsParameters | undefined;
|
45
50
|
activeDca: DCASettings | undefined;
|
51
|
+
dcaInBalance?: {
|
52
|
+
amount: bigint;
|
53
|
+
tokenType: TokenType;
|
54
|
+
};
|
55
|
+
cancellingDca: TokenType | undefined;
|
46
56
|
new(update: PositionAdjustment): void;
|
47
57
|
reset(): void;
|
48
58
|
hasUpdates(): boolean;
|
@@ -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,EAA+B,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAElB,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,
|
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,EAA+B,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAElB,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAChC,SAAS,EAKV,MAAM,iBAAiB,CAAC;AAezB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE9E,wBAAgB,gBAAg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IAExD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IA6B9B,KAAK;IASL,UAAU,IAAI,OAAO;CAStB"}
|
@@ -27,7 +27,8 @@ const marginfiUtils_1 = require("../marginfiUtils");
|
|
27
27
|
function findMintByTicker(ticker) {
|
28
28
|
for (const key in constants_1.TOKEN_INFO) {
|
29
29
|
const account = constants_1.TOKEN_INFO[key];
|
30
|
-
if (account.ticker.toString().toLowerCase() ===
|
30
|
+
if (account.ticker.toString().toLowerCase() ===
|
31
|
+
ticker.toString().toLowerCase()) {
|
31
32
|
return new web3_js_1.PublicKey(key);
|
32
33
|
}
|
33
34
|
}
|
@@ -102,13 +103,17 @@ async function getSolautoManagedPositions(umi, authority) {
|
|
102
103
|
// position_id: [u8; 1]
|
103
104
|
// self_managed: u8 - (1 for true, 0 for false)
|
104
105
|
// padding: [u8; 5]
|
105
|
-
// authority:
|
106
|
+
// authority: pubkey
|
106
107
|
// lending_platform: u8
|
108
|
+
// padding: [u8; 7]
|
109
|
+
// protocol account: pubkey
|
110
|
+
// supply mint: pubkey
|
111
|
+
// debt mint: pubkey
|
107
112
|
const accounts = await umi.rpc.getProgramAccounts(generated_1.SOLAUTO_PROGRAM_ID, {
|
108
113
|
commitment: "confirmed",
|
109
114
|
dataSlice: {
|
110
115
|
offset: 0,
|
111
|
-
length: 1 + 1 + 1 + 5 + 32 + 1, // bump + position_id + self_managed + padding + authority (pubkey) + lending_platform
|
116
|
+
length: 1 + 1 + 1 + 5 + 32 + 1 + 7 + 32 + 32 + 32, // bump + position_id + self_managed + padding (5) + authority (pubkey) + lending_platform + padding (7) + protocol account (pubkey) + supply mint (pubkey) + debt mint (pubkey)
|
112
117
|
},
|
113
118
|
filters: [
|
114
119
|
{
|
@@ -142,6 +147,9 @@ async function getSolautoManagedPositions(umi, authority) {
|
|
142
147
|
authority: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.authority),
|
143
148
|
positionId: position.positionId[0],
|
144
149
|
lendingPlatform: position.position.lendingPlatform,
|
150
|
+
protocolAccount: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.position.protocolAccount),
|
151
|
+
supplyMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.position.supplyMint),
|
152
|
+
debtMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(position.position.debtMint),
|
145
153
|
};
|
146
154
|
});
|
147
155
|
}
|
@@ -187,29 +195,32 @@ async function getReferralsByUser(umi, user) {
|
|
187
195
|
return accounts.map((x) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(x.publicKey));
|
188
196
|
}
|
189
197
|
async function getAllPositionsByAuthority(umi, user) {
|
190
|
-
const
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
198
|
+
const solautoCompatiblePositions = await Promise.all([
|
199
|
+
(async () => {
|
200
|
+
const solautoManagedPositions = await getSolautoManagedPositions(umi, user);
|
201
|
+
return solautoManagedPositions.map((x) => ({
|
202
|
+
...x,
|
203
|
+
authority: user,
|
204
|
+
}));
|
205
|
+
})(),
|
206
|
+
(async () => {
|
207
|
+
let marginfiPositions = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(umi, user, true);
|
208
|
+
marginfiPositions = marginfiPositions.filter((x) => x.supplyMint &&
|
209
|
+
(x.debtMint.equals(web3_js_1.PublicKey.default) ||
|
210
|
+
constants_1.ALL_SUPPORTED_TOKENS.includes(x.debtMint.toString())));
|
211
|
+
return marginfiPositions.map((x) => ({
|
212
|
+
publicKey: x.marginfiAccount,
|
213
|
+
authority: user,
|
214
|
+
positionId: 0,
|
215
|
+
lendingPlatform: generated_1.LendingPlatform.Marginfi,
|
216
|
+
protocolAccount: x.marginfiAccount,
|
217
|
+
supplyMint: x.supplyMint,
|
218
|
+
debtMint: x.debtMint,
|
219
|
+
}));
|
220
|
+
})(),
|
221
|
+
// TODO support other platforms
|
222
|
+
]);
|
223
|
+
return solautoCompatiblePositions.flat();
|
213
224
|
}
|
214
225
|
async function positionStateWithLatestPrices(state, supplyPrice, debtPrice) {
|
215
226
|
if (!supplyPrice || !debtPrice) {
|
@@ -320,8 +331,7 @@ function createSolautoSettings(settings) {
|
|
320
331
|
padding: new Uint8Array([]),
|
321
332
|
padding1: [],
|
322
333
|
},
|
323
|
-
targetBoostToBps: (0, umi_1.isOption)(settings.targetBoostToBps) &&
|
324
|
-
(0, umi_1.isSome)(settings.targetBoostToBps)
|
334
|
+
targetBoostToBps: (0, umi_1.isOption)(settings.targetBoostToBps) && (0, umi_1.isSome)(settings.targetBoostToBps)
|
325
335
|
? settings.targetBoostToBps.value
|
326
336
|
: 0,
|
327
337
|
boostGap: settings.boostGap,
|
@@ -336,9 +346,10 @@ class LivePositionUpdates {
|
|
336
346
|
constructor() {
|
337
347
|
this.supplyAdjustment = BigInt(0);
|
338
348
|
this.debtAdjustment = BigInt(0);
|
339
|
-
this.debtTaBalanceAdjustment = BigInt(0);
|
340
349
|
this.settings = undefined;
|
341
350
|
this.activeDca = undefined;
|
351
|
+
this.dcaInBalance = undefined;
|
352
|
+
this.cancellingDca = undefined;
|
342
353
|
}
|
343
354
|
new(update) {
|
344
355
|
if (update.type === "supply") {
|
@@ -347,9 +358,6 @@ class LivePositionUpdates {
|
|
347
358
|
else if (update.type === "debt") {
|
348
359
|
this.debtAdjustment += update.value;
|
349
360
|
}
|
350
|
-
else if (update.type === "debtDcaIn") {
|
351
|
-
this.debtTaBalanceAdjustment += update.value;
|
352
|
-
}
|
353
361
|
else if (update.type === "settings") {
|
354
362
|
const settings = update.value;
|
355
363
|
this.settings = createSolautoSettings(settings);
|
@@ -364,23 +372,32 @@ class LivePositionUpdates {
|
|
364
372
|
padding: new Uint8Array([]),
|
365
373
|
padding1: [],
|
366
374
|
},
|
367
|
-
|
368
|
-
|
375
|
+
dcaInBaseUnit: BigInt(dca.dcaInBaseUnit),
|
376
|
+
tokenType: dca.tokenType,
|
377
|
+
padding: [],
|
369
378
|
};
|
370
379
|
}
|
380
|
+
else if (update.type === "cancellingDca") {
|
381
|
+
this.cancellingDca = update.value;
|
382
|
+
}
|
383
|
+
else if (update.type === "dcaInBalance") {
|
384
|
+
this.dcaInBalance = update.value;
|
385
|
+
}
|
371
386
|
}
|
372
387
|
reset() {
|
373
388
|
this.supplyAdjustment = BigInt(0);
|
374
389
|
this.debtAdjustment = BigInt(0);
|
375
|
-
this.debtTaBalanceAdjustment = BigInt(0);
|
376
390
|
this.settings = undefined;
|
377
391
|
this.activeDca = undefined;
|
392
|
+
this.dcaInBalance = undefined;
|
393
|
+
this.cancellingDca = undefined;
|
378
394
|
}
|
379
395
|
hasUpdates() {
|
380
396
|
return (this.supplyAdjustment !== BigInt(0) ||
|
381
397
|
this.debtAdjustment !== BigInt(0) ||
|
382
|
-
this.
|
383
|
-
this.settings !== undefined
|
398
|
+
this.dcaInBalance !== undefined ||
|
399
|
+
this.settings !== undefined ||
|
400
|
+
this.cancellingDca !== undefined);
|
384
401
|
}
|
385
402
|
}
|
386
403
|
exports.LivePositionUpdates = LivePositionUpdates;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { SolautoClient } from "../../clients/solautoClient";
|
3
|
-
import { DCASettings, PositionState, SolautoSettingsParameters } from "../../generated";
|
3
|
+
import { DCASettings, PositionState, SolautoSettingsParameters, TokenType } from "../../generated";
|
4
4
|
import { QuoteResponse } from "@jup-ag/api";
|
5
5
|
import { JupSwapDetails } from "../jupiterUtils";
|
6
6
|
export interface RebalanceValues {
|
@@ -8,6 +8,7 @@ export interface RebalanceValues {
|
|
8
8
|
debtAdjustmentUsd: number;
|
9
9
|
amountToDcaIn: number;
|
10
10
|
amountUsdToDcaIn: number;
|
11
|
+
dcaTokenType?: TokenType;
|
11
12
|
}
|
12
13
|
export declare function getRebalanceValues(state: PositionState, settings: SolautoSettingsParameters | undefined, dca: DCASettings | undefined, currentUnixTime: number, supplyPrice: number, debtPrice: number, targetLiqUtilizationRateBps?: number, limitGapBps?: number): RebalanceValues;
|
13
14
|
export interface FlashLoanDetails {
|
@@ -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;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,yBAAyB,
|
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;AAC5D,OAAO,EACL,WAAW,EACX,aAAa,EAEb,yBAAyB,EACzB,SAAS,EACV,MAAM,iBAAiB,CAAC;AAOzB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAgJjD,MAAM,WAAW,eAAe;IAC9B,kBAAkB,EAAE,OAAO,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,SAAS,CAAC;CAC1B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,yBAAyB,GAAG,SAAS,EAC/C,GAAG,EAAE,WAAW,GAAG,SAAS,EAC5B,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,eAAe,CAiEjB;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,CAmE9B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,eAAe,EACvB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,cAAc,CAkChB"}
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRebalanceValues = getRebalanceValues;
|
4
4
|
exports.getFlashLoanDetails = getFlashLoanDetails;
|
5
5
|
exports.getJupSwapRebalanceDetails = getJupSwapRebalanceDetails;
|
6
|
+
const generated_1 = require("../../generated");
|
6
7
|
const generalUtils_1 = require("./generalUtils");
|
7
8
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
8
9
|
const generalUtils_2 = require("../generalUtils");
|
@@ -10,10 +11,10 @@ const numberUtils_1 = require("../numberUtils");
|
|
10
11
|
const generalAccounts_1 = require("../../constants/generalAccounts");
|
11
12
|
const solautoConstants_1 = require("../../constants/solautoConstants");
|
12
13
|
function getAdditionalAmountToDcaIn(dca) {
|
13
|
-
if (dca.
|
14
|
+
if (dca.dcaInBaseUnit === BigInt(0)) {
|
14
15
|
return 0;
|
15
16
|
}
|
16
|
-
const debtBalance = Number(dca.
|
17
|
+
const debtBalance = Number(dca.dcaInBaseUnit);
|
17
18
|
const updatedDebtBalance = (0, generalUtils_1.getUpdatedValueFromAutomation)(debtBalance, 0, dca.automation, (0, generalUtils_2.currentUnixSeconds)());
|
18
19
|
return debtBalance - updatedDebtBalance;
|
19
20
|
}
|
@@ -34,7 +35,7 @@ function getStandardTargetLiqUtilizationRateBps(state, settings) {
|
|
34
35
|
function targetLiqUtilizationRateBpsFromDCA(state, settings, dca, currentUnixTime) {
|
35
36
|
const adjustedSettings = (0, generalUtils_1.getAdjustedSettingsFromAutomation)(settings, currentUnixTime);
|
36
37
|
let targetRateBps = 0;
|
37
|
-
if (dca.
|
38
|
+
if (dca.dcaInBaseUnit > BigInt(0)) {
|
38
39
|
targetRateBps = Math.max(state.liqUtilizationRateBps, adjustedSettings.boostToBps);
|
39
40
|
}
|
40
41
|
else {
|
@@ -110,10 +111,11 @@ function getRebalanceValues(state, settings, dca, currentUnixTime, supplyPrice,
|
|
110
111
|
debtAdjustmentUsd,
|
111
112
|
amountToDcaIn: amountToDcaIn ?? 0,
|
112
113
|
amountUsdToDcaIn,
|
114
|
+
dcaTokenType: dca?.tokenType
|
113
115
|
};
|
114
116
|
}
|
115
117
|
function getFlashLoanDetails(client, values, jupQuote) {
|
116
|
-
let supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
118
|
+
let supplyUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.supply.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS) + (values.dcaTokenType === generated_1.TokenType.Supply ? values.amountUsdToDcaIn : 0);
|
117
119
|
let debtUsd = (0, numberUtils_1.fromBaseUnit)(client.solautoPositionState.debt.amountUsed.baseAmountUsdValue, generalAccounts_1.USD_DECIMALS);
|
118
120
|
const debtAdjustmentWithSlippage = Math.abs(values.debtAdjustmentUsd) +
|
119
121
|
Math.abs(values.debtAdjustmentUsd) * (0, numberUtils_1.fromBps)(jupQuote.slippageBps);
|
@@ -159,7 +161,7 @@ function getJupSwapRebalanceDetails(client, values, targetLiqUtilizationRateBps,
|
|
159
161
|
const output = values.increasingLeverage
|
160
162
|
? client.solautoPositionState.supply
|
161
163
|
: client.solautoPositionState.debt;
|
162
|
-
const usdToSwap = Math.abs(values.debtAdjustmentUsd) + values.amountUsdToDcaIn;
|
164
|
+
const usdToSwap = Math.abs(values.debtAdjustmentUsd) + (values.dcaTokenType === generated_1.TokenType.Debt ? values.amountUsdToDcaIn : 0);
|
163
165
|
const inputPrice = values.increasingLeverage
|
164
166
|
? (0, generalUtils_2.safeGetPrice)(client.debtMint)
|
165
167
|
: (0, generalUtils_2.safeGetPrice)(client.supplyMint);
|
package/package.json
CHANGED
@@ -25,6 +25,7 @@ import {
|
|
25
25
|
SolautoRebalanceTypeArgs,
|
26
26
|
SolautoSettingsParameters,
|
27
27
|
SolautoSettingsParametersInpArgs,
|
28
|
+
TokenType,
|
28
29
|
UpdatePositionDataArgs,
|
29
30
|
cancelDCA,
|
30
31
|
closePosition,
|
@@ -360,10 +361,13 @@ export abstract class SolautoClient extends TxHandler {
|
|
360
361
|
settingParams?: SolautoSettingsParametersInpArgs,
|
361
362
|
dca?: DCASettingsInpArgs
|
362
363
|
): TransactionBuilder {
|
363
|
-
if (dca && dca.
|
364
|
+
if (dca && dca.dcaInBaseUnit > 0) {
|
364
365
|
this.livePositionUpdates.new({
|
365
|
-
type: "
|
366
|
-
value:
|
366
|
+
type: "dcaInBalance",
|
367
|
+
value: {
|
368
|
+
amount: BigInt(dca.dcaInBaseUnit),
|
369
|
+
tokenType: dca.tokenType
|
370
|
+
},
|
367
371
|
});
|
368
372
|
}
|
369
373
|
if (settingParams) {
|
@@ -383,38 +387,35 @@ export abstract class SolautoClient extends TxHandler {
|
|
383
387
|
}
|
384
388
|
|
385
389
|
updatePositionIx(args: UpdatePositionDataArgs): TransactionBuilder {
|
386
|
-
let
|
387
|
-
let
|
388
|
-
let
|
390
|
+
let dcaMint: UmiPublicKey | undefined = undefined;
|
391
|
+
let positionDcaTa: UmiPublicKey | undefined = undefined;
|
392
|
+
let signerDcaTa: UmiPublicKey | undefined = undefined;
|
389
393
|
if (isOption(args.dca) && isSome(args.dca)) {
|
390
|
-
|
391
|
-
|
392
|
-
|
394
|
+
if (args.dca.value.tokenType === TokenType.Supply) {
|
395
|
+
dcaMint = publicKey(this.supplyMint);
|
396
|
+
positionDcaTa = publicKey(this.positionSupplyTa);
|
397
|
+
signerDcaTa = publicKey(this.signerSupplyTa);
|
398
|
+
} else {
|
399
|
+
dcaMint = publicKey(this.debtMint);
|
400
|
+
positionDcaTa = publicKey(this.positionDebtTa);
|
401
|
+
signerDcaTa = publicKey(this.signerDebtTa);
|
402
|
+
}
|
393
403
|
|
394
404
|
let addingToPos = false;
|
395
405
|
if (
|
396
406
|
isOption(args.dca) &&
|
397
407
|
isSome(args.dca) &&
|
398
|
-
args.dca.value.
|
408
|
+
args.dca.value.dcaInBaseUnit > 0
|
399
409
|
) {
|
400
410
|
this.livePositionUpdates.new({
|
401
|
-
type: "
|
402
|
-
value:
|
411
|
+
type: "dcaInBalance",
|
412
|
+
value: {
|
413
|
+
amount: BigInt(args.dca.value.dcaInBaseUnit),
|
414
|
+
tokenType: args.dca.value.tokenType
|
415
|
+
},
|
403
416
|
});
|
404
417
|
addingToPos = true;
|
405
418
|
}
|
406
|
-
|
407
|
-
if (
|
408
|
-
this.solautoPositionData?.position.dca.debtToAddBaseUnit &&
|
409
|
-
!addingToPos
|
410
|
-
) {
|
411
|
-
this.livePositionUpdates.new({
|
412
|
-
type: "debtDcaIn",
|
413
|
-
value:
|
414
|
-
this.solautoPositionData.position.dca.debtToAddBaseUnit *
|
415
|
-
BigInt(-1),
|
416
|
-
});
|
417
|
-
}
|
418
419
|
}
|
419
420
|
|
420
421
|
if (isOption(args.settingParams) && isSome(args.settingParams)) {
|
@@ -434,9 +435,9 @@ export abstract class SolautoClient extends TxHandler {
|
|
434
435
|
return updatePosition(this.umi, {
|
435
436
|
signer: this.signer,
|
436
437
|
solautoPosition: publicKey(this.solautoPosition),
|
437
|
-
|
438
|
-
|
439
|
-
|
438
|
+
dcaMint,
|
439
|
+
positionDcaTa,
|
440
|
+
signerDcaTa,
|
440
441
|
updatePositionData: args,
|
441
442
|
});
|
442
443
|
}
|
@@ -454,30 +455,34 @@ export abstract class SolautoClient extends TxHandler {
|
|
454
455
|
}
|
455
456
|
|
456
457
|
cancelDCAIx(): TransactionBuilder {
|
457
|
-
let
|
458
|
-
let
|
459
|
-
let
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
if (
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
this.
|
469
|
-
|
470
|
-
|
471
|
-
});
|
458
|
+
let dcaMint: UmiPublicKey | undefined = undefined;
|
459
|
+
let positionDcaTa: UmiPublicKey | undefined = undefined;
|
460
|
+
let signerDcaTa: UmiPublicKey | undefined = undefined;
|
461
|
+
|
462
|
+
const currDca = this.solautoPositionActiveDca()!;
|
463
|
+
if (currDca.dcaInBaseUnit > 0) {
|
464
|
+
if (currDca.tokenType === TokenType.Supply) {
|
465
|
+
dcaMint = publicKey(this.supplyMint);
|
466
|
+
positionDcaTa = publicKey(this.positionSupplyTa);
|
467
|
+
signerDcaTa = publicKey(this.signerSupplyTa);
|
468
|
+
} else {
|
469
|
+
dcaMint = publicKey(this.debtMint);
|
470
|
+
positionDcaTa = publicKey(this.positionDebtTa);
|
471
|
+
signerDcaTa = publicKey(this.signerDebtTa);
|
472
472
|
}
|
473
|
+
|
474
|
+
this.livePositionUpdates.new({
|
475
|
+
type: "cancellingDca",
|
476
|
+
value: this.solautoPositionData!.position.dca.tokenType,
|
477
|
+
});
|
473
478
|
}
|
474
479
|
|
475
480
|
return cancelDCA(this.umi, {
|
476
481
|
signer: this.signer,
|
477
482
|
solautoPosition: publicKey(this.solautoPosition),
|
478
|
-
|
479
|
-
|
480
|
-
|
483
|
+
dcaMint,
|
484
|
+
positionDcaTa,
|
485
|
+
signerDcaTa,
|
481
486
|
});
|
482
487
|
}
|
483
488
|
|
@@ -28,8 +28,6 @@ import {
|
|
28
28
|
u8,
|
29
29
|
} from '@metaplex-foundation/umi/serializers';
|
30
30
|
import {
|
31
|
-
FeeType,
|
32
|
-
FeeTypeArgs,
|
33
31
|
PodBool,
|
34
32
|
PodBoolArgs,
|
35
33
|
PositionData,
|
@@ -38,7 +36,6 @@ import {
|
|
38
36
|
PositionStateArgs,
|
39
37
|
RebalanceData,
|
40
38
|
RebalanceDataArgs,
|
41
|
-
getFeeTypeSerializer,
|
42
39
|
getPodBoolSerializer,
|
43
40
|
getPositionDataSerializer,
|
44
41
|
getPositionStateSerializer,
|
@@ -56,8 +53,6 @@ export type SolautoPositionAccountData = {
|
|
56
53
|
position: PositionData;
|
57
54
|
state: PositionState;
|
58
55
|
rebalance: RebalanceData;
|
59
|
-
feeType: FeeType;
|
60
|
-
padding2: Array<number>;
|
61
56
|
padding: Array<number>;
|
62
57
|
};
|
63
58
|
|
@@ -70,8 +65,6 @@ export type SolautoPositionAccountDataArgs = {
|
|
70
65
|
position: PositionDataArgs;
|
71
66
|
state: PositionStateArgs;
|
72
67
|
rebalance: RebalanceDataArgs;
|
73
|
-
feeType: FeeTypeArgs;
|
74
|
-
padding2: Array<number>;
|
75
68
|
padding: Array<number>;
|
76
69
|
};
|
77
70
|
|
@@ -89,9 +82,7 @@ export function getSolautoPositionAccountDataSerializer(): Serializer<
|
|
89
82
|
['position', getPositionDataSerializer()],
|
90
83
|
['state', getPositionStateSerializer()],
|
91
84
|
['rebalance', getRebalanceDataSerializer()],
|
92
|
-
['
|
93
|
-
['padding2', array(u8(), { size: 7 })],
|
94
|
-
['padding', array(u32(), { size: 30 })],
|
85
|
+
['padding', array(u32(), { size: 32 })],
|
95
86
|
],
|
96
87
|
{ description: 'SolautoPositionAccountData' }
|
97
88
|
) as Serializer<SolautoPositionAccountDataArgs, SolautoPositionAccountData>;
|
@@ -179,8 +170,6 @@ export function getSolautoPositionGpaBuilder(
|
|
179
170
|
position: PositionDataArgs;
|
180
171
|
state: PositionStateArgs;
|
181
172
|
rebalance: RebalanceDataArgs;
|
182
|
-
feeType: FeeTypeArgs;
|
183
|
-
padding2: Array<number>;
|
184
173
|
padding: Array<number>;
|
185
174
|
}>({
|
186
175
|
bump: [0, array(u8(), { size: 1 })],
|
@@ -191,9 +180,7 @@ export function getSolautoPositionGpaBuilder(
|
|
191
180
|
position: [40, getPositionDataSerializer()],
|
192
181
|
state: [360, getPositionStateSerializer()],
|
193
182
|
rebalance: [648, getRebalanceDataSerializer()],
|
194
|
-
|
195
|
-
padding2: [705, array(u8(), { size: 7 })],
|
196
|
-
padding: [712, array(u32(), { size: 30 })],
|
183
|
+
padding: [704, array(u32(), { size: 32 })],
|
197
184
|
})
|
198
185
|
.deserializeUsing<SolautoPosition>((account) =>
|
199
186
|
deserializeSolautoPosition(account)
|
@@ -33,9 +33,9 @@ export type CancelDCAInstructionAccounts = {
|
|
33
33
|
tokenProgram?: PublicKey | Pda;
|
34
34
|
ataProgram?: PublicKey | Pda;
|
35
35
|
solautoPosition: PublicKey | Pda;
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
dcaMint?: PublicKey | Pda;
|
37
|
+
positionDcaTa?: PublicKey | Pda;
|
38
|
+
signerDcaTa?: PublicKey | Pda;
|
39
39
|
};
|
40
40
|
|
41
41
|
// Data.
|
@@ -97,20 +97,20 @@ export function cancelDCA(
|
|
97
97
|
isWritable: true as boolean,
|
98
98
|
value: input.solautoPosition ?? null,
|
99
99
|
},
|
100
|
-
|
100
|
+
dcaMint: {
|
101
101
|
index: 5,
|
102
102
|
isWritable: false as boolean,
|
103
|
-
value: input.
|
103
|
+
value: input.dcaMint ?? null,
|
104
104
|
},
|
105
|
-
|
105
|
+
positionDcaTa: {
|
106
106
|
index: 6,
|
107
107
|
isWritable: true as boolean,
|
108
|
-
value: input.
|
108
|
+
value: input.positionDcaTa ?? null,
|
109
109
|
},
|
110
|
-
|
110
|
+
signerDcaTa: {
|
111
111
|
index: 7,
|
112
112
|
isWritable: true as boolean,
|
113
|
-
value: input.
|
113
|
+
value: input.signerDcaTa ?? null,
|
114
114
|
},
|
115
115
|
} satisfies ResolvedAccountsWithIndices;
|
116
116
|
|
@@ -34,9 +34,8 @@ export type ClosePositionInstructionAccounts = {
|
|
34
34
|
ataProgram?: PublicKey | Pda;
|
35
35
|
solautoPosition: PublicKey | Pda;
|
36
36
|
protocolAccount: PublicKey | Pda;
|
37
|
-
signerSupplyTa: PublicKey | Pda;
|
38
37
|
positionSupplyTa: PublicKey | Pda;
|
39
|
-
|
38
|
+
signerSupplyTa: PublicKey | Pda;
|
40
39
|
positionDebtTa: PublicKey | Pda;
|
41
40
|
signerDebtTa: PublicKey | Pda;
|
42
41
|
};
|
@@ -108,28 +107,23 @@ export function closePosition(
|
|
108
107
|
isWritable: true as boolean,
|
109
108
|
value: input.protocolAccount ?? null,
|
110
109
|
},
|
111
|
-
signerSupplyTa: {
|
112
|
-
index: 6,
|
113
|
-
isWritable: true as boolean,
|
114
|
-
value: input.signerSupplyTa ?? null,
|
115
|
-
},
|
116
110
|
positionSupplyTa: {
|
117
|
-
index:
|
111
|
+
index: 6,
|
118
112
|
isWritable: true as boolean,
|
119
113
|
value: input.positionSupplyTa ?? null,
|
120
114
|
},
|
121
|
-
|
122
|
-
index:
|
115
|
+
signerSupplyTa: {
|
116
|
+
index: 7,
|
123
117
|
isWritable: true as boolean,
|
124
|
-
value: input.
|
118
|
+
value: input.signerSupplyTa ?? null,
|
125
119
|
},
|
126
120
|
positionDebtTa: {
|
127
|
-
index:
|
121
|
+
index: 8,
|
128
122
|
isWritable: true as boolean,
|
129
123
|
value: input.positionDebtTa ?? null,
|
130
124
|
},
|
131
125
|
signerDebtTa: {
|
132
|
-
index:
|
126
|
+
index: 9,
|
133
127
|
isWritable: true as boolean,
|
134
128
|
value: input.signerDebtTa ?? null,
|
135
129
|
},
|
@@ -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
|
|