@haven-fi/solauto-sdk 1.0.190 → 1.0.191
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/solautoMarginfiClient.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 +21 -12
- package/package.json +1 -1
- package/src/clients/solautoMarginfiClient.ts +2 -2
- package/src/utils/solanaUtils.ts +22 -13
- package/tests/transactions/solautoMarginfi.ts +7 -9
@@ -434,7 +434,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
434
434
|
if (state) {
|
435
435
|
return state;
|
436
436
|
}
|
437
|
-
const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, undefined, undefined, this.livePositionUpdates);
|
437
|
+
const freshState = await (0, marginfiUtils_1.getMarginfiAccountPositionState)(this.umi, this.marginfiAccountPk, this.selfManaged ? undefined : this.supplyMint, this.selfManaged ? undefined : this.debtMint, this.livePositionUpdates);
|
438
438
|
if (freshState) {
|
439
439
|
this.log("Fresh state", freshState);
|
440
440
|
const supplyPrice = (0, generalUtils_1.safeGetPrice)(freshState?.supply.mint);
|
@@ -13,6 +13,6 @@ export declare function closeTokenAccountUmiIx(signer: Signer, tokenAccount: Pub
|
|
13
13
|
export declare function splTokenTransferUmiIx(signer: Signer, fromTa: PublicKey, toTa: PublicKey, authority: PublicKey, amount: bigint): WrappedInstruction;
|
14
14
|
export declare function getAdressLookupInputs(umi: Umi, lookupTableAddresses: string[]): Promise<AddressLookupTableInput[]>;
|
15
15
|
export declare function assembleFinalTransaction(signer: Signer, tx: TransactionBuilder, computeUnitPrice: number, computeUnitLimit?: number): TransactionBuilder;
|
16
|
-
export declare function getComputeUnitPriceEstimate(umi: Umi, tx: TransactionBuilder, prioritySetting: PriorityFeeSetting): Promise<number>;
|
16
|
+
export declare function getComputeUnitPriceEstimate(umi: Umi, tx: TransactionBuilder, prioritySetting: PriorityFeeSetting): Promise<number | undefined>;
|
17
17
|
export declare function sendSingleOptimizedTransaction(umi: Umi, connection: Connection, tx: TransactionBuilder, txType?: TransactionRunType, attemptNum?: number, prioritySetting?: PriorityFeeSetting, onAwaitingSign?: () => void): Promise<Uint8Array | undefined>;
|
18
18
|
//# 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,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAElE,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,UAErD;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,MAAM,UAE3D;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,GACb,CAAC,UAAU,EAAE,GAAG,CAAC,CAInB;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,EACd,QAAQ,EAAE,MAAM,GACf,kBAAkB,CAOpB;AAED,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,SAAS,GACd,kBAAkB,CAUpB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,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8BAA8B,CAClD,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,EAAE,EAAE,kBAAkB,EACtB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,UAAU,CAAC,EAAE,MAAM,EACnB,eAAe,GAAE,kBAA+C,EAChE,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAkEjC"}
|
@@ -141,33 +141,42 @@ async function simulateTransaction(connection, transaction) {
|
|
141
141
|
async function getComputeUnitPriceEstimate(umi, tx, prioritySetting) {
|
142
142
|
const web3Transaction = (0, umi_web3js_adapters_1.toWeb3JsTransaction)((await tx.setLatestBlockhash(umi, { commitment: "finalized" })).build(umi));
|
143
143
|
const serializedTransaction = bs58_1.default.encode(web3Transaction.serialize());
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
144
|
+
let feeEstimate;
|
145
|
+
try {
|
146
|
+
const resp = await umi.rpc.call("getPriorityFeeEstimate", [
|
147
|
+
{
|
148
|
+
transaction: serializedTransaction,
|
149
|
+
options: {
|
150
|
+
priorityLevel: prioritySetting.toString(),
|
151
|
+
},
|
149
152
|
},
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
+
]);
|
154
|
+
feeEstimate = Math.round(resp.priorityFeeEstimate);
|
155
|
+
}
|
156
|
+
catch (e) {
|
157
|
+
console.error(e);
|
158
|
+
}
|
153
159
|
return feeEstimate;
|
154
160
|
}
|
155
161
|
async function sendSingleOptimizedTransaction(umi, connection, tx, txType, attemptNum, prioritySetting = types_1.PriorityFeeSetting.Default, onAwaitingSign) {
|
156
162
|
(0, generalUtils_1.consoleLog)("Sending single optimized transaction...");
|
157
163
|
(0, generalUtils_1.consoleLog)("Instructions: ", tx.getInstructions().length);
|
158
164
|
(0, generalUtils_1.consoleLog)("Serialized transaction size: ", tx.getTransactionSize(umi));
|
159
|
-
|
160
|
-
(
|
165
|
+
let cuPrice = await getComputeUnitPriceEstimate(umi, tx, prioritySetting);
|
166
|
+
if (!cuPrice) {
|
167
|
+
cuPrice = 1000000;
|
168
|
+
}
|
169
|
+
(0, generalUtils_1.consoleLog)("Compute unit price: ", cuPrice);
|
161
170
|
let computeUnitLimit = undefined;
|
162
171
|
if (txType !== "skip-simulation") {
|
163
172
|
// TODO: we should only retry simulation if it's not a solauto error
|
164
|
-
const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction(connection, (0, umi_web3js_adapters_1.toWeb3JsTransaction)(await (await assembleFinalTransaction(umi.identity, tx,
|
173
|
+
const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await simulateTransaction(connection, (0, umi_web3js_adapters_1.toWeb3JsTransaction)(await (await assembleFinalTransaction(umi.identity, tx, cuPrice, 1400000).setLatestBlockhash(umi)).build(umi))), 3);
|
165
174
|
computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.1);
|
166
175
|
(0, generalUtils_1.consoleLog)("Compute unit limit: ", computeUnitLimit);
|
167
176
|
}
|
168
177
|
if (txType !== "only-simulate") {
|
169
178
|
onAwaitingSign?.();
|
170
|
-
const result = await assembleFinalTransaction(umi.identity, tx,
|
179
|
+
const result = await assembleFinalTransaction(umi.identity, tx, cuPrice, computeUnitLimit).sendAndConfirm(umi, {
|
171
180
|
send: {
|
172
181
|
skipPreflight: true,
|
173
182
|
commitment: "confirmed",
|
package/package.json
CHANGED
@@ -651,8 +651,8 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
651
651
|
const freshState = await getMarginfiAccountPositionState(
|
652
652
|
this.umi,
|
653
653
|
this.marginfiAccountPk,
|
654
|
-
undefined,
|
655
|
-
undefined,
|
654
|
+
this.selfManaged ? undefined : this.supplyMint,
|
655
|
+
this.selfManaged ? undefined : this.debtMint,
|
656
656
|
this.livePositionUpdates
|
657
657
|
);
|
658
658
|
|
package/src/utils/solanaUtils.ts
CHANGED
@@ -254,20 +254,26 @@ export async function getComputeUnitPriceEstimate(
|
|
254
254
|
umi: Umi,
|
255
255
|
tx: TransactionBuilder,
|
256
256
|
prioritySetting: PriorityFeeSetting
|
257
|
-
): Promise<number> {
|
257
|
+
): Promise<number | undefined> {
|
258
258
|
const web3Transaction = toWeb3JsTransaction(
|
259
259
|
(await tx.setLatestBlockhash(umi, { commitment: "finalized" })).build(umi)
|
260
260
|
);
|
261
261
|
const serializedTransaction = bs58.encode(web3Transaction.serialize());
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
262
|
+
|
263
|
+
let feeEstimate: number | undefined;
|
264
|
+
try {
|
265
|
+
const resp = await umi.rpc.call("getPriorityFeeEstimate", [
|
266
|
+
{
|
267
|
+
transaction: serializedTransaction,
|
268
|
+
options: {
|
269
|
+
priorityLevel: prioritySetting.toString(),
|
270
|
+
},
|
267
271
|
},
|
268
|
-
|
269
|
-
|
270
|
-
|
272
|
+
]);
|
273
|
+
feeEstimate = Math.round((resp as any).priorityFeeEstimate as number);
|
274
|
+
} catch (e) {
|
275
|
+
console.error(e);
|
276
|
+
}
|
271
277
|
|
272
278
|
return feeEstimate;
|
273
279
|
}
|
@@ -285,12 +291,15 @@ export async function sendSingleOptimizedTransaction(
|
|
285
291
|
consoleLog("Instructions: ", tx.getInstructions().length);
|
286
292
|
consoleLog("Serialized transaction size: ", tx.getTransactionSize(umi));
|
287
293
|
|
288
|
-
|
294
|
+
let cuPrice = await getComputeUnitPriceEstimate(
|
289
295
|
umi,
|
290
296
|
tx,
|
291
297
|
prioritySetting
|
292
298
|
);
|
293
|
-
|
299
|
+
if (!cuPrice) {
|
300
|
+
cuPrice = 1000000;
|
301
|
+
}
|
302
|
+
consoleLog("Compute unit price: ", cuPrice);
|
294
303
|
|
295
304
|
let computeUnitLimit = undefined;
|
296
305
|
if (txType !== "skip-simulation") {
|
@@ -304,7 +313,7 @@ export async function sendSingleOptimizedTransaction(
|
|
304
313
|
await assembleFinalTransaction(
|
305
314
|
umi.identity,
|
306
315
|
tx,
|
307
|
-
|
316
|
+
cuPrice,
|
308
317
|
1_400_000
|
309
318
|
).setLatestBlockhash(umi)
|
310
319
|
).build(umi)
|
@@ -324,7 +333,7 @@ export async function sendSingleOptimizedTransaction(
|
|
324
333
|
const result = await assembleFinalTransaction(
|
325
334
|
umi.identity,
|
326
335
|
tx,
|
327
|
-
|
336
|
+
cuPrice,
|
328
337
|
computeUnitLimit
|
329
338
|
).sendAndConfirm(umi, {
|
330
339
|
send: {
|
@@ -24,7 +24,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
24
24
|
// const signer = setupTest();
|
25
25
|
const signer = setupTest("solauto-manager");
|
26
26
|
|
27
|
-
const payForTransactions =
|
27
|
+
const payForTransactions = true;
|
28
28
|
const useJitoBundle = false;
|
29
29
|
const positionId = 1;
|
30
30
|
|
@@ -159,13 +159,11 @@ describe("Solauto Marginfi tests", async () => {
|
|
159
159
|
// )
|
160
160
|
// );
|
161
161
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
console.log(await getMarginfiAccountPositionState(client.umi, new PublicKey("8SZUhT1Jwiz1LKkeSsBwvwZyKH1UrzW3r8yiC6R3LLf7")));
|
162
|
+
await new TransactionsManager(
|
163
|
+
client,
|
164
|
+
undefined,
|
165
|
+
!payForTransactions ? "only-simulate" : "normal",
|
166
|
+
useJitoBundle
|
167
|
+
).clientSend(transactionItems);
|
170
168
|
});
|
171
169
|
});
|