@haven-fi/solauto-sdk 1.0.57 → 1.0.58
Sign up to get free protection for your applications and to get access to all the features.
- 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/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 +1 -1
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +8 -6
- package/package.json +1 -1
- package/src/constants/tokenConstants.ts +7 -2
- package/src/utils/solanaUtils.ts +1 -2
- package/src/utils/solauto/generalUtils.ts +10 -6
@@ -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
|
+
];
|
@@ -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,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AAE,SAAS,GACnB,kBAAkB,CAKpB;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,GACb,kBAAkB,CAKpB;AAED,wBAAsB,qBAAqB,CACzC,GAAG,EAAE,GAAG,EACR,oBAAoB,EAAE,MAAM,EAAE,GAC7B,OAAO,CAAC,uBAAuB,EAAE,CAAC,CAkBpC;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,kBAAkB,EACtB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,CAAC,EAAE,MAAM,sBA4D1B;AAmBD,wBAAsB,2BAA2B,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);
|
@@ -17,7 +17,7 @@ export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicK
|
|
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,OAA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;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");
|
@@ -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
@@ -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
|
+
];
|
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(
|
@@ -319,11 +319,13 @@ export async function getAllPositionsByAuthority(
|
|
319
319
|
return allPositions;
|
320
320
|
}
|
321
321
|
|
322
|
-
export async function
|
322
|
+
export async function positionStateWithPrices(
|
323
323
|
umi: Umi,
|
324
324
|
state: PositionState,
|
325
325
|
protocolAccount: PublicKey,
|
326
|
-
lendingPlatform: LendingPlatform
|
326
|
+
lendingPlatform: LendingPlatform,
|
327
|
+
supplyPrice?: number,
|
328
|
+
debtPrice?: number
|
327
329
|
): Promise<PositionState | undefined> {
|
328
330
|
if (currentUnixSeconds() - Number(state.lastUpdated) > 60 * 60 * 24 * 7) {
|
329
331
|
if (lendingPlatform === LendingPlatform.Marginfi) {
|
@@ -338,10 +340,12 @@ export async function positionStateWithLatestPrices(
|
|
338
340
|
}
|
339
341
|
}
|
340
342
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
343
|
+
if (!supplyPrice || !debtPrice) {
|
344
|
+
[supplyPrice, debtPrice] = await getTokenPrices([
|
345
|
+
toWeb3JsPublicKey(state.supply.mint),
|
346
|
+
toWeb3JsPublicKey(state.debt.mint),
|
347
|
+
]);
|
348
|
+
}
|
345
349
|
|
346
350
|
const supplyUsd =
|
347
351
|
fromBaseUnit(state.supply.amountUsed.baseUnit, state.supply.decimals) *
|