@haven-fi/solauto-sdk 1.0.57 → 1.0.59
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/constants/tokenConstants.d.ts +1 -0
- package/dist/constants/tokenConstants.d.ts.map +1 -1
- package/dist/constants/tokenConstants.js +5 -2
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +1 -1
- package/dist/utils/solanaUtils.d.ts +1 -1
- package/dist/utils/solanaUtils.d.ts.map +1 -1
- package/dist/utils/solanaUtils.js +2 -2
- package/dist/utils/solauto/generalUtils.d.ts +5 -5
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +19 -17
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +0 -3
- package/src/constants/tokenConstants.ts +7 -2
- package/src/transactions/transactionUtils.ts +3 -1
- package/src/utils/solanaUtils.ts +1 -2
- package/src/utils/solauto/generalUtils.ts +24 -17
@@ -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;AAElC,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;
|
1
|
+
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAEL,UAAU,EACV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AAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAuBrB,gBAAgB,CAAC,IAAI,EAAE,sBAAsB,GAAG,kBAAkB;IA2DlE,eAAe,IAAI,kBAAkB;IAWrC,WAAW,IAAI,kBAAkB;IA4BjC,QAAQ,CAAC,OAAO,IAAI,kBAAkB;IAEtC,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAuFhE,QAAQ,CAAC,WAAW,CAClB,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IAErB,QAAQ,CAAC,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAE3E,QAAQ,CAAC,SAAS,CAChB,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAYlE"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"tokenConstants.d.ts","sourceRoot":"","sources":["../../src/constants/tokenConstants.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"tokenConstants.d.ts","sourceRoot":"","sources":["../../src/constants/tokenConstants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,iDAAiD,CAAC;AAGxE,eAAO,MAAM,oBAAoB,UAGhC,CAAC;AAEF,eAAO,MAAM,cAAc;;;CAG1B,CAAC;AAEF,eAAO,MAAM,WAAW,UAEvB,CAAC"}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.TOKEN_DECIMALS = exports.ALL_SUPPORTED_TOKENS = exports.USDC_MINT = void 0;
|
3
|
+
exports.STABLECOINS = exports.TOKEN_DECIMALS = exports.ALL_SUPPORTED_TOKENS = exports.USDC_MINT = void 0;
|
4
4
|
const spl_token_1 = require("@solana/spl-token");
|
5
|
+
// When adding token ensure a price feed is provided in pythConstants.ts & the token is added to the necessary lists below
|
5
6
|
exports.USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
6
|
-
// When adding token ensure a price feed is provided in pythConstants.ts
|
7
7
|
exports.ALL_SUPPORTED_TOKENS = [
|
8
8
|
spl_token_1.NATIVE_MINT.toString(),
|
9
9
|
exports.USDC_MINT,
|
@@ -12,3 +12,6 @@ exports.TOKEN_DECIMALS = {
|
|
12
12
|
[spl_token_1.NATIVE_MINT.toString()]: 9,
|
13
13
|
[exports.USDC_MINT]: 6
|
14
14
|
};
|
15
|
+
exports.STABLECOINS = [
|
16
|
+
exports.USDC_MINT
|
17
|
+
];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EASd,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,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAsMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA8G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA4BnD;AAGD,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,CAiHA;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"}
|
@@ -324,7 +324,7 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
324
324
|
(targetLiqUtilizationRateBps === undefined &&
|
325
325
|
!(0, generalUtils_2.eligibleForRebalance)(client.solautoPositionState, client.livePositionUpdates.settings ??
|
326
326
|
client.solautoPositionData?.position.settingParams, client.livePositionUpdates.activeDca ??
|
327
|
-
client.solautoPositionData?.position.dca))) {
|
327
|
+
client.solautoPositionData?.position.dca, (0, generalUtils_1.currentUnixSeconds)()))) {
|
328
328
|
client.log("Not eligible for a rebalance");
|
329
329
|
return undefined;
|
330
330
|
}
|
@@ -12,6 +12,6 @@ export declare function closeTokenAccountUmiIx(signer: Signer, tokenAccount: Pub
|
|
12
12
|
export declare function splTokenTransferUmiIx(signer: Signer, fromTa: PublicKey, toTa: PublicKey, authority: PublicKey, amount: bigint): WrappedInstruction;
|
13
13
|
export declare function getAdressLookupInputs(umi: Umi, lookupTableAddresses: string[]): Promise<AddressLookupTableInput[]>;
|
14
14
|
export declare function assembleFinalTransaction(signer: Signer, tx: TransactionBuilder, computeUnitPrice: number, computeUnitLimit?: number): TransactionBuilder;
|
15
|
-
export declare function getComputeUnitPriceEstimate(umi: Umi, tx: TransactionBuilder, prioritySetting: PriorityFeeSetting
|
15
|
+
export declare function getComputeUnitPriceEstimate(umi: Umi, tx: TransactionBuilder, prioritySetting: PriorityFeeSetting): Promise<number>;
|
16
16
|
export declare function sendSingleOptimizedTransaction(umi: Umi, connection: Connection, tx: TransactionBuilder, simulateOnly?: boolean, attemptNum?: number, prioritySetting?: PriorityFeeSetting): Promise<Uint8Array | undefined>;
|
17
17
|
//# sourceMappingURL=solanaUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solanaUtils.d.ts","sourceRoot":"","sources":["../../src/utils/solanaUtils.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,MAAM,EACN,kBAAkB,EAClB,GAAG,EACH,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAGL,UAAU,EACV,SAAS,EAIT,sBAAsB,EAEvB,MAAM,iBAAiB,CAAC;AAYzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAO9E;AAED,wBAAsB,wBAAwB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAQxE;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,sBAAsB,GACzB,kBAAkB,CAMpB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,MAAM,GACtB,kBAAkB,CAOpB;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,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AA2B,CAC/C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,kBAAkB,EACtB,eAAe,EAAE,kBAAkB,GAClC,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED,wBAAsB,8BAA8B,CAClD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,kBAAkB,EACtB,YAAY,CAAC,EAAE,OAAO,EACtB,UAAU,CAAC,EAAE,MAAM,EACnB,eAAe,GAAE,kBAA+C,GAC/D,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAmDjC"}
|
@@ -140,7 +140,7 @@ async function simulateTransaction(connection, transaction) {
|
|
140
140
|
}
|
141
141
|
return simulationResult;
|
142
142
|
}
|
143
|
-
async function getComputeUnitPriceEstimate(umi, tx, prioritySetting
|
143
|
+
async function getComputeUnitPriceEstimate(umi, tx, prioritySetting) {
|
144
144
|
const web3Transaction = (0, umi_web3js_adapters_1.toWeb3JsTransaction)((await tx.setLatestBlockhash(umi, { commitment: "finalized" })).build(umi));
|
145
145
|
const serializedTransaction = bs58_1.default.encode(web3Transaction.serialize());
|
146
146
|
const resp = await umi.rpc.call("getPriorityFeeEstimate", [
|
@@ -158,7 +158,7 @@ async function sendSingleOptimizedTransaction(umi, connection, tx, simulateOnly,
|
|
158
158
|
console.log("Sending single optimized transaction...");
|
159
159
|
console.log("Instructions: ", tx.getInstructions().length);
|
160
160
|
console.log("Serialized transaction size: ", tx.getTransactionSize(umi));
|
161
|
-
const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, prioritySetting
|
161
|
+
const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, prioritySetting);
|
162
162
|
console.log("Compute unit price: ", feeEstimate);
|
163
163
|
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)).build(umi))));
|
164
164
|
const computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.1);
|
@@ -3,21 +3,21 @@ import { Umi } from "@metaplex-foundation/umi";
|
|
3
3
|
import { AutomationSettings, DCASettings, DCASettingsInpArgs, FeeType, LendingPlatform, PositionState, SolautoSettingsParameters, SolautoSettingsParametersInpArgs } from "../../generated";
|
4
4
|
import { RebalanceAction, SolautoPositionDetails } from "../../types/solauto";
|
5
5
|
export declare function nextAutomationPeriodTimestamp(automation: AutomationSettings): number;
|
6
|
-
export declare function eligibleForNextAutomationPeriod(automation: AutomationSettings): boolean;
|
6
|
+
export declare function eligibleForNextAutomationPeriod(automation: AutomationSettings, currentUnixSecs?: number): boolean;
|
7
7
|
export declare function getUpdatedValueFromAutomation(currValue: number, targetValue: number, automation: AutomationSettings, currentUnixTimestamp: number): number;
|
8
|
-
export declare function getAdjustedSettingsFromAutomation(settings: SolautoSettingsParameters,
|
8
|
+
export declare function getAdjustedSettingsFromAutomation(settings: SolautoSettingsParameters, currentUnixSecs?: number): SolautoSettingsParameters;
|
9
9
|
export declare function getSolautoFeesBps(isReferred: boolean, feeType: FeeType): {
|
10
10
|
solauto: number;
|
11
11
|
referrer: number;
|
12
12
|
total: number;
|
13
13
|
};
|
14
|
-
export declare function eligibleForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings): RebalanceAction | undefined;
|
15
|
-
export declare function eligibleForRefresh(positionState: PositionState, positionSettings: SolautoSettingsParameters): boolean;
|
14
|
+
export declare function eligibleForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings, currentUnixSecs: number): RebalanceAction | undefined;
|
15
|
+
export declare function eligibleForRefresh(positionState: PositionState, positionSettings: SolautoSettingsParameters, currentUnixSecs?: number): boolean;
|
16
16
|
export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicKey): Promise<SolautoPositionDetails[]>;
|
17
17
|
export declare function getAllReferralStates(umi: Umi): Promise<PublicKey[]>;
|
18
18
|
export declare function getReferralsByUser(umi: Umi, user: PublicKey): Promise<PublicKey[]>;
|
19
19
|
export declare function getAllPositionsByAuthority(umi: Umi, user: PublicKey): Promise<SolautoPositionDetails[]>;
|
20
|
-
export declare function
|
20
|
+
export declare function positionStateWithPrices(umi: Umi, state: PositionState, protocolAccount: PublicKey, lendingPlatform: LendingPlatform, supplyPrice?: number, debtPrice?: number): Promise<PositionState | undefined>;
|
21
21
|
type PositionAdjustment = {
|
22
22
|
type: "supply";
|
23
23
|
value: bigint;
|
@@ -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;AAczB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAgB9E,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,kBAAkB,
|
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;AAczB,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM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AAG,EAAE,GAAG,EACR,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,sBAAsB,EAAE,CAAC,CAuCnC;AAED,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,aAAa,EACpB,eAAe,EAAE,SAAS,EAC1B,eAAe,EAAE,eAAe,EAChC,WAAW,CAAC,EAAE,MAAM,EACpB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAqDpC;AAED,KAAK,kBAAkB,GACnB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,gCAAgC,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAE/C,qBAAa,mBAAmB;IACvB,gBAAgB,EAAE,MAAM,CAAa;IACrC,cAAc,EAAE,MAAM,CAAa;IACnC,uBAAuB,EAAE,MAAM,CAAa;IAC5C,QAAQ,EAAE,yBAAyB,GAAG,SAAS,CAAa;IAC5D,SAAS,EAAE,WAAW,GAAG,SAAS,CAAa;IAEtD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IAyD9B,KAAK;IAQL,UAAU,IAAI,OAAO;CAQtB"}
|
@@ -12,7 +12,7 @@ exports.getSolautoManagedPositions = getSolautoManagedPositions;
|
|
12
12
|
exports.getAllReferralStates = getAllReferralStates;
|
13
13
|
exports.getReferralsByUser = getReferralsByUser;
|
14
14
|
exports.getAllPositionsByAuthority = getAllPositionsByAuthority;
|
15
|
-
exports.
|
15
|
+
exports.positionStateWithPrices = positionStateWithPrices;
|
16
16
|
const web3_js_1 = require("@solana/web3.js");
|
17
17
|
const umi_1 = require("@metaplex-foundation/umi");
|
18
18
|
const generated_1 = require("../../generated");
|
@@ -33,8 +33,8 @@ function nextAutomationPeriodTimestamp(automation) {
|
|
33
33
|
: Number(automation.unixStartDate) +
|
34
34
|
automation.periodsPassed * Number(automation.intervalSeconds);
|
35
35
|
}
|
36
|
-
function eligibleForNextAutomationPeriod(automation) {
|
37
|
-
return (0, generalUtils_1.currentUnixSeconds)() >= nextAutomationPeriodTimestamp(automation);
|
36
|
+
function eligibleForNextAutomationPeriod(automation, currentUnixSecs) {
|
37
|
+
return (currentUnixSecs ?? (0, generalUtils_1.currentUnixSeconds)()) >= nextAutomationPeriodTimestamp(automation);
|
38
38
|
}
|
39
39
|
function getUpdatedValueFromAutomation(currValue, targetValue, automation, currentUnixTimestamp) {
|
40
40
|
const currRateDiff = currValue - targetValue;
|
@@ -44,10 +44,10 @@ function getUpdatedValueFromAutomation(currValue, targetValue, automation, curre
|
|
44
44
|
const newValue = currValue - currRateDiff * progressPct;
|
45
45
|
return newValue;
|
46
46
|
}
|
47
|
-
function getAdjustedSettingsFromAutomation(settings,
|
47
|
+
function getAdjustedSettingsFromAutomation(settings, currentUnixSecs) {
|
48
48
|
const boostToBps = settings.automation.targetPeriods > 0 &&
|
49
|
-
eligibleForNextAutomationPeriod(settings.automation)
|
50
|
-
? getUpdatedValueFromAutomation(settings.boostToBps, settings.targetBoostToBps, settings.automation, currentUnixSeconds)
|
49
|
+
eligibleForNextAutomationPeriod(settings.automation, currentUnixSecs)
|
50
|
+
? getUpdatedValueFromAutomation(settings.boostToBps, settings.targetBoostToBps, settings.automation, currentUnixSecs ?? (0, generalUtils_1.currentUnixSeconds)())
|
51
51
|
: settings.boostToBps;
|
52
52
|
return {
|
53
53
|
...settings,
|
@@ -66,17 +66,17 @@ function getSolautoFeesBps(isReferred, feeType) {
|
|
66
66
|
total: fees,
|
67
67
|
};
|
68
68
|
}
|
69
|
-
function eligibleForRebalance(positionState, positionSettings, positionDca) {
|
69
|
+
function eligibleForRebalance(positionState, positionSettings, positionDca, currentUnixSecs) {
|
70
70
|
if (positionDca.automation.targetPeriods > 0 &&
|
71
|
-
eligibleForNextAutomationPeriod(positionDca.automation)) {
|
71
|
+
eligibleForNextAutomationPeriod(positionDca.automation, currentUnixSecs)) {
|
72
72
|
return "dca";
|
73
73
|
}
|
74
74
|
if (positionState.supply.amountUsed.baseUnit === BigInt(0)) {
|
75
75
|
return undefined;
|
76
76
|
}
|
77
|
-
const boostToBps = eligibleForRefresh(positionState, positionSettings) &&
|
77
|
+
const boostToBps = eligibleForRefresh(positionState, positionSettings, currentUnixSecs) &&
|
78
78
|
positionSettings.automation.targetPeriods > 0
|
79
|
-
? getUpdatedValueFromAutomation(positionSettings.boostToBps, positionSettings.targetBoostToBps, positionSettings.automation,
|
79
|
+
? getUpdatedValueFromAutomation(positionSettings.boostToBps, positionSettings.targetBoostToBps, positionSettings.automation, currentUnixSecs)
|
80
80
|
: positionSettings.boostToBps;
|
81
81
|
const repayFrom = positionSettings.repayToBps + positionSettings.repayGap;
|
82
82
|
const boostFrom = boostToBps - positionSettings.boostGap;
|
@@ -88,9 +88,9 @@ function eligibleForRebalance(positionState, positionSettings, positionDca) {
|
|
88
88
|
}
|
89
89
|
return undefined;
|
90
90
|
}
|
91
|
-
function eligibleForRefresh(positionState, positionSettings) {
|
91
|
+
function eligibleForRefresh(positionState, positionSettings, currentUnixSecs) {
|
92
92
|
if (positionSettings.automation.targetPeriods > 0) {
|
93
|
-
return eligibleForNextAutomationPeriod(positionSettings.automation);
|
93
|
+
return eligibleForNextAutomationPeriod(positionSettings.automation, currentUnixSecs);
|
94
94
|
}
|
95
95
|
else {
|
96
96
|
return ((0, generalUtils_1.currentUnixSeconds)() - Number(positionState.lastUpdated) >
|
@@ -211,7 +211,7 @@ async function getAllPositionsByAuthority(umi, user) {
|
|
211
211
|
// TODO support other platforms
|
212
212
|
return allPositions;
|
213
213
|
}
|
214
|
-
async function
|
214
|
+
async function positionStateWithPrices(umi, state, protocolAccount, lendingPlatform, supplyPrice, debtPrice) {
|
215
215
|
if ((0, generalUtils_1.currentUnixSeconds)() - Number(state.lastUpdated) > 60 * 60 * 24 * 7) {
|
216
216
|
if (lendingPlatform === generated_1.LendingPlatform.Marginfi) {
|
217
217
|
return await (0, marginfiUtils_1.getMarginfiAccountPositionState)(umi, protocolAccount, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint), (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.debt.mint));
|
@@ -220,10 +220,12 @@ async function positionStateWithLatestPrices(umi, state, protocolAccount, lendin
|
|
220
220
|
throw new Error("Lending platorm not yet supported");
|
221
221
|
}
|
222
222
|
}
|
223
|
-
|
224
|
-
(0,
|
225
|
-
|
226
|
-
|
223
|
+
if (!supplyPrice || !debtPrice) {
|
224
|
+
[supplyPrice, debtPrice] = await (0, generalUtils_1.getTokenPrices)([
|
225
|
+
(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.supply.mint),
|
226
|
+
(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(state.debt.mint),
|
227
|
+
]);
|
228
|
+
}
|
227
229
|
const supplyUsd = (0, numberUtils_1.fromBaseUnit)(state.supply.amountUsed.baseUnit, state.supply.decimals) *
|
228
230
|
supplyPrice;
|
229
231
|
const debtUsd = (0, numberUtils_1.fromBaseUnit)(state.debt.amountUsed.baseUnit, state.debt.decimals) *
|
package/package.json
CHANGED
@@ -49,14 +49,12 @@ import {
|
|
49
49
|
} from "../utils/accountUtils";
|
50
50
|
import {
|
51
51
|
SOLAUTO_FEES_WALLET,
|
52
|
-
SOLAUTO_MANAGER,
|
53
52
|
} from "../constants/generalAccounts";
|
54
53
|
import { JupSwapDetails } from "../utils/jupiterUtils";
|
55
54
|
import {
|
56
55
|
getSolanaRpcConnection,
|
57
56
|
getWrappedInstruction,
|
58
57
|
splTokenTransferUmiIx,
|
59
|
-
systemTransferUmiIx,
|
60
58
|
} from "../utils/solanaUtils";
|
61
59
|
import { FlashLoanDetails } from "../utils/solauto/rebalanceUtils";
|
62
60
|
import { NATIVE_MINT } from "@solana/spl-token";
|
@@ -66,7 +64,6 @@ import {
|
|
66
64
|
} from "../constants/solautoConstants";
|
67
65
|
import { currentUnixSeconds } from "../utils/generalUtils";
|
68
66
|
import { LivePositionUpdates } from "../utils/solauto/generalUtils";
|
69
|
-
import { toBaseUnit } from "../utils";
|
70
67
|
|
71
68
|
export interface SolautoClientArgs {
|
72
69
|
authority?: PublicKey;
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import { NATIVE_MINT } from "@solana/spl-token";
|
2
2
|
|
3
|
+
// When adding token ensure a price feed is provided in pythConstants.ts & the token is added to the necessary lists below
|
3
4
|
export const USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
4
5
|
|
5
|
-
|
6
|
+
|
6
7
|
export const ALL_SUPPORTED_TOKENS = [
|
7
8
|
NATIVE_MINT.toString(),
|
8
9
|
USDC_MINT,
|
@@ -11,4 +12,8 @@ export const ALL_SUPPORTED_TOKENS = [
|
|
11
12
|
export const TOKEN_DECIMALS = {
|
12
13
|
[NATIVE_MINT.toString()]: 9,
|
13
14
|
[USDC_MINT]: 6
|
14
|
-
};
|
15
|
+
};
|
16
|
+
|
17
|
+
export const STABLECOINS = [
|
18
|
+
USDC_MINT
|
19
|
+
];
|
@@ -38,6 +38,7 @@ import {
|
|
38
38
|
getRebalanceValues,
|
39
39
|
} from "../utils/solauto/rebalanceUtils";
|
40
40
|
import {
|
41
|
+
currentUnixSeconds,
|
41
42
|
getSolanaAccountCreated,
|
42
43
|
rpcAccountCreated,
|
43
44
|
} from "../utils/generalUtils";
|
@@ -568,7 +569,8 @@ export async function buildSolautoRebalanceTransaction(
|
|
568
569
|
client.livePositionUpdates.settings ??
|
569
570
|
client.solautoPositionData?.position.settingParams!,
|
570
571
|
client.livePositionUpdates.activeDca ??
|
571
|
-
client.solautoPositionData?.position.dca
|
572
|
+
client.solautoPositionData?.position.dca!,
|
573
|
+
currentUnixSeconds()
|
572
574
|
))
|
573
575
|
) {
|
574
576
|
client.log("Not eligible for a rebalance");
|
package/src/utils/solanaUtils.ts
CHANGED
@@ -257,7 +257,6 @@ export async function getComputeUnitPriceEstimate(
|
|
257
257
|
umi: Umi,
|
258
258
|
tx: TransactionBuilder,
|
259
259
|
prioritySetting: PriorityFeeSetting,
|
260
|
-
attemptNum?: number,
|
261
260
|
): Promise<number> {
|
262
261
|
const web3Transaction = toWeb3JsTransaction(
|
263
262
|
(await tx.setLatestBlockhash(umi, { commitment: "finalized" })).build(umi)
|
@@ -288,7 +287,7 @@ export async function sendSingleOptimizedTransaction(
|
|
288
287
|
console.log("Instructions: ", tx.getInstructions().length);
|
289
288
|
console.log("Serialized transaction size: ", tx.getTransactionSize(umi));
|
290
289
|
|
291
|
-
const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, prioritySetting
|
290
|
+
const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, prioritySetting);
|
292
291
|
console.log("Compute unit price: ", feeEstimate);
|
293
292
|
|
294
293
|
const simulationResult = await retryWithExponentialBackoff(
|
@@ -53,9 +53,10 @@ export function nextAutomationPeriodTimestamp(
|
|
53
53
|
}
|
54
54
|
|
55
55
|
export function eligibleForNextAutomationPeriod(
|
56
|
-
automation: AutomationSettings
|
56
|
+
automation: AutomationSettings,
|
57
|
+
currentUnixSecs?: number
|
57
58
|
): boolean {
|
58
|
-
return currentUnixSeconds() >= nextAutomationPeriodTimestamp(automation);
|
59
|
+
return (currentUnixSecs ?? currentUnixSeconds()) >= nextAutomationPeriodTimestamp(automation);
|
59
60
|
}
|
60
61
|
|
61
62
|
export function getUpdatedValueFromAutomation(
|
@@ -78,16 +79,16 @@ export function getUpdatedValueFromAutomation(
|
|
78
79
|
|
79
80
|
export function getAdjustedSettingsFromAutomation(
|
80
81
|
settings: SolautoSettingsParameters,
|
81
|
-
|
82
|
+
currentUnixSecs?: number
|
82
83
|
): SolautoSettingsParameters {
|
83
84
|
const boostToBps =
|
84
85
|
settings.automation.targetPeriods > 0 &&
|
85
|
-
eligibleForNextAutomationPeriod(settings.automation)
|
86
|
+
eligibleForNextAutomationPeriod(settings.automation, currentUnixSecs)
|
86
87
|
? getUpdatedValueFromAutomation(
|
87
88
|
settings.boostToBps,
|
88
89
|
settings.targetBoostToBps,
|
89
90
|
settings.automation,
|
90
|
-
currentUnixSeconds
|
91
|
+
currentUnixSecs ?? currentUnixSeconds()
|
91
92
|
)
|
92
93
|
: settings.boostToBps;
|
93
94
|
|
@@ -121,11 +122,12 @@ export function getSolautoFeesBps(
|
|
121
122
|
export function eligibleForRebalance(
|
122
123
|
positionState: PositionState,
|
123
124
|
positionSettings: SolautoSettingsParameters,
|
124
|
-
positionDca: DCASettings
|
125
|
+
positionDca: DCASettings,
|
126
|
+
currentUnixSecs: number
|
125
127
|
): RebalanceAction | undefined {
|
126
128
|
if (
|
127
129
|
positionDca.automation.targetPeriods > 0 &&
|
128
|
-
eligibleForNextAutomationPeriod(positionDca.automation)
|
130
|
+
eligibleForNextAutomationPeriod(positionDca.automation, currentUnixSecs)
|
129
131
|
) {
|
130
132
|
return "dca";
|
131
133
|
}
|
@@ -135,13 +137,13 @@ export function eligibleForRebalance(
|
|
135
137
|
}
|
136
138
|
|
137
139
|
const boostToBps =
|
138
|
-
eligibleForRefresh(positionState, positionSettings) &&
|
140
|
+
eligibleForRefresh(positionState, positionSettings, currentUnixSecs) &&
|
139
141
|
positionSettings.automation.targetPeriods > 0
|
140
142
|
? getUpdatedValueFromAutomation(
|
141
143
|
positionSettings.boostToBps,
|
142
144
|
positionSettings.targetBoostToBps,
|
143
145
|
positionSettings.automation,
|
144
|
-
|
146
|
+
currentUnixSecs
|
145
147
|
)
|
146
148
|
: positionSettings.boostToBps;
|
147
149
|
const repayFrom = positionSettings.repayToBps + positionSettings.repayGap;
|
@@ -158,10 +160,11 @@ export function eligibleForRebalance(
|
|
158
160
|
|
159
161
|
export function eligibleForRefresh(
|
160
162
|
positionState: PositionState,
|
161
|
-
positionSettings: SolautoSettingsParameters
|
163
|
+
positionSettings: SolautoSettingsParameters,
|
164
|
+
currentUnixSecs?: number
|
162
165
|
): boolean {
|
163
166
|
if (positionSettings.automation.targetPeriods > 0) {
|
164
|
-
return eligibleForNextAutomationPeriod(positionSettings.automation);
|
167
|
+
return eligibleForNextAutomationPeriod(positionSettings.automation, currentUnixSecs);
|
165
168
|
} else {
|
166
169
|
return (
|
167
170
|
currentUnixSeconds() - Number(positionState.lastUpdated) >
|
@@ -319,11 +322,13 @@ export async function getAllPositionsByAuthority(
|
|
319
322
|
return allPositions;
|
320
323
|
}
|
321
324
|
|
322
|
-
export async function
|
325
|
+
export async function positionStateWithPrices(
|
323
326
|
umi: Umi,
|
324
327
|
state: PositionState,
|
325
328
|
protocolAccount: PublicKey,
|
326
|
-
lendingPlatform: LendingPlatform
|
329
|
+
lendingPlatform: LendingPlatform,
|
330
|
+
supplyPrice?: number,
|
331
|
+
debtPrice?: number
|
327
332
|
): Promise<PositionState | undefined> {
|
328
333
|
if (currentUnixSeconds() - Number(state.lastUpdated) > 60 * 60 * 24 * 7) {
|
329
334
|
if (lendingPlatform === LendingPlatform.Marginfi) {
|
@@ -338,10 +343,12 @@ export async function positionStateWithLatestPrices(
|
|
338
343
|
}
|
339
344
|
}
|
340
345
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
346
|
+
if (!supplyPrice || !debtPrice) {
|
347
|
+
[supplyPrice, debtPrice] = await getTokenPrices([
|
348
|
+
toWeb3JsPublicKey(state.supply.mint),
|
349
|
+
toWeb3JsPublicKey(state.debt.mint),
|
350
|
+
]);
|
351
|
+
}
|
345
352
|
|
346
353
|
const supplyUsd =
|
347
354
|
fromBaseUnit(state.supply.amountUsed.baseUnit, state.supply.decimals) *
|