@haven-fi/solauto-sdk 1.0.115 → 1.0.117
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/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +1 -0
- package/dist/transactions/transactionsManager.d.ts +9 -9
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +13 -12
- package/dist/types/solauto.d.ts +1 -0
- package/dist/types/solauto.d.ts.map +1 -1
- package/dist/utils/solanaUtils.d.ts +2 -2
- package/dist/utils/solanaUtils.d.ts.map +1 -1
- package/dist/utils/solanaUtils.js +8 -6
- package/local/updateSolautoLUT.ts +3 -1
- package/package.json +1 -1
- package/src/transactions/transactionUtils.ts +1 -0
- package/src/transactions/transactionsManager.ts +13 -12
- package/src/types/solauto.ts +3 -1
- package/src/utils/solanaUtils.ts +28 -26
- package/tests/transactions/solautoMarginfi.ts +48 -43
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAuMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAuMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA+G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA4BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC;IACT,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACG,SAAS,CACZ,CAwHA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,SAAS,GACtB,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAmCrD"}
|
|
@@ -149,6 +149,7 @@ async function rebalanceChoresBefore(client, tx, accountsGettingCreated) {
|
|
|
149
149
|
}
|
|
150
150
|
if (checkIntermediaryMfiAccount &&
|
|
151
151
|
!(0, generalUtils_1.rpcAccountCreated)(intermediaryMarginfiAccount)) {
|
|
152
|
+
client.log("Creating intermediary marginfi account");
|
|
152
153
|
chores = chores.add(client.createIntermediaryMarginfiAccount());
|
|
153
154
|
}
|
|
154
155
|
if (checkSignerSupplyTa &&
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AddressLookupTableInput, TransactionBuilder, Umi } from "@metaplex-foundation/umi";
|
|
2
2
|
import { SolautoClient } from "../clients/solautoClient";
|
|
3
3
|
import { ErrorsToThrow } from "../utils/generalUtils";
|
|
4
|
-
import { PriorityFeeSetting } from "../types";
|
|
4
|
+
import { PriorityFeeSetting, TransactionRunType } from "../types";
|
|
5
5
|
import { ReferralStateManager, TxHandler } from "../clients";
|
|
6
6
|
declare class LookupTables {
|
|
7
7
|
defaultLuts: string[];
|
|
@@ -39,11 +39,11 @@ declare class TransactionSet {
|
|
|
39
39
|
name(): string;
|
|
40
40
|
}
|
|
41
41
|
export declare enum TransactionStatus {
|
|
42
|
-
Skipped =
|
|
43
|
-
Processing =
|
|
44
|
-
AwaitingSignature =
|
|
45
|
-
Queued =
|
|
46
|
-
Successful =
|
|
42
|
+
Skipped = "Skipped",
|
|
43
|
+
Processing = "Processing",
|
|
44
|
+
AwaitingSignature = "Awaiting Signature",
|
|
45
|
+
Queued = "Queued",
|
|
46
|
+
Successful = "Successful"
|
|
47
47
|
}
|
|
48
48
|
export type TransactionManagerStatuses = {
|
|
49
49
|
name: string;
|
|
@@ -53,16 +53,16 @@ export type TransactionManagerStatuses = {
|
|
|
53
53
|
export declare class TransactionsManager {
|
|
54
54
|
private txHandler;
|
|
55
55
|
private statusCallback?;
|
|
56
|
-
private
|
|
56
|
+
private txType?;
|
|
57
57
|
private mustBeAtomic?;
|
|
58
58
|
private errorsToThrow?;
|
|
59
59
|
private statuses;
|
|
60
60
|
private lookupTables;
|
|
61
|
-
constructor(txHandler: SolautoClient | ReferralStateManager, statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined,
|
|
61
|
+
constructor(txHandler: SolautoClient | ReferralStateManager, statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined, txType?: TransactionRunType | undefined, mustBeAtomic?: boolean | undefined, errorsToThrow?: ErrorsToThrow | undefined);
|
|
62
62
|
private assembleTransactionSets;
|
|
63
63
|
updateStatus(name: string, status: TransactionStatus, txSig?: string): void;
|
|
64
64
|
debugAccounts(itemSet: TransactionSet, tx: TransactionBuilder): Promise<void>;
|
|
65
|
-
clientSend(
|
|
65
|
+
clientSend(transactions: TransactionItem[], prioritySetting?: PriorityFeeSetting): Promise<void>;
|
|
66
66
|
send(items: TransactionItem[], prioritySetting?: PriorityFeeSetting, initialized?: boolean): Promise<void>;
|
|
67
67
|
}
|
|
68
68
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EAEvB,kBAAkB,EAClB,GAAG,EACJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EAEvB,kBAAkB,EAClB,GAAG,EACJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG7D,cAAM,YAAY;IAIP,WAAW,EAAE,MAAM,EAAE;IAC5B,OAAO,CAAC,GAAG;IAJb,KAAK,EAAE,uBAAuB,EAAE,CAAM;gBAG7B,WAAW,EAAE,MAAM,EAAE,EACpB,GAAG,EAAE,GAAG;IAGZ,YAAY,CAChB,mBAAmB,EAAE,MAAM,EAAE,GAC5B,OAAO,CAAC,uBAAuB,EAAE,CAAC;CAiBtC;AAED,qBA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AAC,EAAE,MAAM,CAAC;CAChB,EAAE,CAAC;AAEJ,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,MAAM,CAAC;IACf,OAAO,CAAC,YAAY,CAAC;IACrB,OAAO,CAAC,aAAa,CAAC;IARxB,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,YAAY,CAAe;gBAGzB,SAAS,EAAE,aAAa,GAAG,oBAAoB,EAC/C,cAAc,CAAC,GAAE,CAAC,QAAQ,EAAE,0BAA0B,KAAK,IAAI,aAAA,EAC/D,MAAM,CAAC,EAAE,kBAAkB,YAAA,EAC3B,YAAY,CAAC,EAAE,OAAO,YAAA,EACtB,aAAa,CAAC,EAAE,aAAa,YAAA;YAQzB,uBAAuB;IAwCrC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,KAAK,CAAC,EAAE,MAAM;IAiB9D,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,kBAAkB;IAoB7D,UAAU,CACd,YAAY,EAAE,eAAe,EAAE,EAC/B,eAAe,CAAC,EAAE,kBAAkB;IAoFhC,IAAI,CACR,KAAK,EAAE,eAAe,EAAE,EACxB,eAAe,CAAC,EAAE,kBAAkB,EACpC,WAAW,CAAC,EAAE,OAAO;CA+GxB"}
|
|
@@ -109,17 +109,17 @@ class TransactionSet {
|
|
|
109
109
|
}
|
|
110
110
|
var TransactionStatus;
|
|
111
111
|
(function (TransactionStatus) {
|
|
112
|
-
TransactionStatus[
|
|
113
|
-
TransactionStatus[
|
|
114
|
-
TransactionStatus[
|
|
115
|
-
TransactionStatus[
|
|
116
|
-
TransactionStatus[
|
|
112
|
+
TransactionStatus["Skipped"] = "Skipped";
|
|
113
|
+
TransactionStatus["Processing"] = "Processing";
|
|
114
|
+
TransactionStatus["AwaitingSignature"] = "Awaiting Signature";
|
|
115
|
+
TransactionStatus["Queued"] = "Queued";
|
|
116
|
+
TransactionStatus["Successful"] = "Successful";
|
|
117
117
|
})(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
|
|
118
118
|
class TransactionsManager {
|
|
119
|
-
constructor(txHandler, statusCallback,
|
|
119
|
+
constructor(txHandler, statusCallback, txType, mustBeAtomic, errorsToThrow) {
|
|
120
120
|
this.txHandler = txHandler;
|
|
121
121
|
this.statusCallback = statusCallback;
|
|
122
|
-
this.
|
|
122
|
+
this.txType = txType;
|
|
123
123
|
this.mustBeAtomic = mustBeAtomic;
|
|
124
124
|
this.errorsToThrow = errorsToThrow;
|
|
125
125
|
this.statuses = [];
|
|
@@ -189,7 +189,8 @@ class TransactionsManager {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
async clientSend(
|
|
192
|
+
async clientSend(transactions, prioritySetting) {
|
|
193
|
+
const items = [...transactions];
|
|
193
194
|
const client = this.txHandler;
|
|
194
195
|
const updateLookupTable = await client.updateLookupTable();
|
|
195
196
|
const updateLutTxName = "update lookup table";
|
|
@@ -197,7 +198,7 @@ class TransactionsManager {
|
|
|
197
198
|
updateLookupTable.updateLutTx.getInstructions().length > 0 &&
|
|
198
199
|
updateLookupTable?.needsToBeIsolated) {
|
|
199
200
|
this.updateStatus(updateLutTxName, TransactionStatus.Processing);
|
|
200
|
-
await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, updateLookupTable.updateLutTx, this.
|
|
201
|
+
await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, updateLookupTable.updateLutTx, this.txType, attemptNum, prioritySetting, () => this.updateStatus(updateLutTxName, TransactionStatus.AwaitingSignature)), 3, 150, this.errorsToThrow);
|
|
201
202
|
this.updateStatus(updateLutTxName, TransactionStatus.Successful);
|
|
202
203
|
}
|
|
203
204
|
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
|
@@ -226,7 +227,7 @@ class TransactionsManager {
|
|
|
226
227
|
client.resetLiveTxUpdates(false);
|
|
227
228
|
throw e;
|
|
228
229
|
});
|
|
229
|
-
if (
|
|
230
|
+
if (this.txType !== "only-simulate") {
|
|
230
231
|
await client.resetLiveTxUpdates();
|
|
231
232
|
}
|
|
232
233
|
}
|
|
@@ -256,7 +257,7 @@ class TransactionsManager {
|
|
|
256
257
|
// this.updateStatus(set.name(), TransactionStatus.Successful);
|
|
257
258
|
// });
|
|
258
259
|
}
|
|
259
|
-
else if (
|
|
260
|
+
else if (this.txType !== "only-simulate" || itemSets.length === 1) {
|
|
260
261
|
for (let i = 0; i < itemSets.length; i++) {
|
|
261
262
|
const getFreshItemSet = async (itemSet, attemptNum) => {
|
|
262
263
|
await itemSet.refetchAll(attemptNum);
|
|
@@ -295,7 +296,7 @@ class TransactionsManager {
|
|
|
295
296
|
if (this.txHandler.localTest) {
|
|
296
297
|
await this.debugAccounts(itemSet, tx);
|
|
297
298
|
}
|
|
298
|
-
const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx, this.
|
|
299
|
+
const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx, this.txType, attemptNum, prioritySetting, () => this.updateStatus(itemSet.name(), TransactionStatus.AwaitingSignature));
|
|
299
300
|
this.updateStatus(itemSet.name(), TransactionStatus.Successful, txSig ? bs58_1.default.encode(txSig) : undefined);
|
|
300
301
|
}
|
|
301
302
|
}, 4, 150, this.errorsToThrow);
|
package/dist/types/solauto.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,oBAAY,kBAAkB;IAC5B,OAAO,WAAW;IAClB,IAAI,SAAS;CACd;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,oBAAY,kBAAkB;IAC5B,OAAO,WAAW;IAClB,IAAI,SAAS;CACd;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;AAExD,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,GAAG,eAAe,GAAG,QAAQ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AddressLookupTableInput, Signer, TransactionBuilder, Umi, WrappedInstruction } from "@metaplex-foundation/umi";
|
|
2
2
|
import { Connection, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
-
import { PriorityFeeSetting } from "../types";
|
|
3
|
+
import { PriorityFeeSetting, TransactionRunType } from "../types";
|
|
4
4
|
export declare function getSolanaRpcConnection(heliusApiKey: string): [Connection, Umi];
|
|
5
5
|
export declare function currentUnixSecondsSolana(umi: Umi): Promise<number>;
|
|
6
6
|
export declare function getWrappedInstruction(signer: Signer, ix: TransactionInstruction): WrappedInstruction;
|
|
@@ -13,5 +13,5 @@ export declare function splTokenTransferUmiIx(signer: Signer, fromTa: PublicKey,
|
|
|
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
15
|
export declare function getComputeUnitPriceEstimate(umi: Umi, tx: TransactionBuilder, prioritySetting: PriorityFeeSetting): Promise<number>;
|
|
16
|
-
export declare function sendSingleOptimizedTransaction(umi: Umi, connection: Connection, tx: TransactionBuilder,
|
|
16
|
+
export declare function sendSingleOptimizedTransaction(umi: Umi, connection: Connection, tx: TransactionBuilder, txType?: TransactionRunType, attemptNum?: number, prioritySetting?: PriorityFeeSetting, onAwaitingSign?: () => void): 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;
|
|
1
|
+
{"version":3,"file":"solanaUtils.d.ts","sour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kB,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,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,CA4DjC"}
|
|
@@ -154,17 +154,19 @@ async function getComputeUnitPriceEstimate(umi, tx, prioritySetting) {
|
|
|
154
154
|
const feeEstimate = Math.round(resp.priorityFeeEstimate);
|
|
155
155
|
return feeEstimate;
|
|
156
156
|
}
|
|
157
|
-
async function sendSingleOptimizedTransaction(umi, connection, tx,
|
|
157
|
+
async function sendSingleOptimizedTransaction(umi, connection, tx, txType, attemptNum, prioritySetting = types_1.PriorityFeeSetting.Default, onAwaitingSign) {
|
|
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
161
|
const feeEstimate = await getComputeUnitPriceEstimate(umi, tx, prioritySetting);
|
|
162
162
|
console.log("Compute unit price: ", feeEstimate);
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
163
|
+
if (txType !== "skip-simulation") {
|
|
164
|
+
// TODO: we should only retry simulation if it's not a solauto error
|
|
165
|
+
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))), 3);
|
|
166
|
+
const computeUnitLimit = Math.round(simulationResult.value.unitsConsumed * 1.1);
|
|
167
|
+
console.log("Compute unit limit: ", computeUnitLimit);
|
|
168
|
+
}
|
|
169
|
+
if (txType !== "only-simulate") {
|
|
168
170
|
onAwaitingSign?.();
|
|
169
171
|
const result = await assembleFinalTransaction(umi.identity, tx, feeEstimate, 800000).sendAndConfirm(umi, {
|
|
170
172
|
send: {
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { getTokenAccounts } from "../src/utils/accountUtils";
|
|
3
|
-
import { SOLAUTO_MANAGER } from "../src/constants/generalAccounts";
|
|
3
|
+
import { SOLAUTO_FEES_WALLET, SOLAUTO_MANAGER } from "../src/constants/generalAccounts";
|
|
4
4
|
import { ALL_SUPPORTED_TOKENS } from "../src/constants/tokenConstants";
|
|
5
5
|
import { updateLookupTable } from "./shared";
|
|
6
6
|
import { SOLAUTO_LUT, STANDARD_LUT_ACCOUNTS } from "../src/constants/solautoConstants";
|
|
7
7
|
|
|
8
8
|
const LOOKUP_TABLE_ADDRESS = new PublicKey(SOLAUTO_LUT);
|
|
9
9
|
const solautoManagerTokenAccounts = getTokenAccounts(SOLAUTO_MANAGER, ALL_SUPPORTED_TOKENS.map((x) => new PublicKey(x)));
|
|
10
|
+
const solautoFeeWalletTokenAccounts = getTokenAccounts(SOLAUTO_FEES_WALLET, ALL_SUPPORTED_TOKENS.map((x) => new PublicKey(x)));
|
|
10
11
|
|
|
11
12
|
export async function updateSolautoLut(additionalAccounts?: string[]) {
|
|
12
13
|
return updateLookupTable(
|
|
13
14
|
[
|
|
14
15
|
...STANDARD_LUT_ACCOUNTS,
|
|
15
16
|
...solautoManagerTokenAccounts.map((x) => x.toString()),
|
|
17
|
+
...solautoFeeWalletTokenAccounts.map(x => x.toString()),
|
|
16
18
|
...(additionalAccounts ?? [])
|
|
17
19
|
],
|
|
18
20
|
LOOKUP_TABLE_ADDRESS
|
package/package.json
CHANGED
|
@@ -298,6 +298,7 @@ export async function rebalanceChoresBefore(
|
|
|
298
298
|
checkIntermediaryMfiAccount &&
|
|
299
299
|
!rpcAccountCreated(intermediaryMarginfiAccount)
|
|
300
300
|
) {
|
|
301
|
+
client.log("Creating intermediary marginfi account");
|
|
301
302
|
chores = chores.add(
|
|
302
303
|
(client as SolautoMarginfiClient).createIntermediaryMarginfiAccount()
|
|
303
304
|
);
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
retryWithExponentialBackoff,
|
|
16
16
|
} from "../utils/generalUtils";
|
|
17
17
|
import { getTransactionChores } from "./transactionUtils";
|
|
18
|
-
import { PriorityFeeSetting } from "../types";
|
|
18
|
+
import { PriorityFeeSetting, TransactionRunType } from "../types";
|
|
19
19
|
import { ReferralStateManager, TxHandler } from "../clients";
|
|
20
20
|
// import { sendJitoBundledTransactions } from "../utils/jitoUtils";
|
|
21
21
|
|
|
@@ -164,11 +164,11 @@ class TransactionSet {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
export enum TransactionStatus {
|
|
167
|
-
Skipped,
|
|
168
|
-
Processing,
|
|
169
|
-
AwaitingSignature,
|
|
170
|
-
Queued,
|
|
171
|
-
Successful,
|
|
167
|
+
Skipped = "Skipped",
|
|
168
|
+
Processing = "Processing",
|
|
169
|
+
AwaitingSignature = "Awaiting Signature",
|
|
170
|
+
Queued = "Queued",
|
|
171
|
+
Successful = "Successful",
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
export type TransactionManagerStatuses = {
|
|
@@ -184,7 +184,7 @@ export class TransactionsManager {
|
|
|
184
184
|
constructor(
|
|
185
185
|
private txHandler: SolautoClient | ReferralStateManager,
|
|
186
186
|
private statusCallback?: (statuses: TransactionManagerStatuses) => void,
|
|
187
|
-
private
|
|
187
|
+
private txType?: TransactionRunType,
|
|
188
188
|
private mustBeAtomic?: boolean,
|
|
189
189
|
private errorsToThrow?: ErrorsToThrow
|
|
190
190
|
) {
|
|
@@ -272,9 +272,10 @@ export class TransactionsManager {
|
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
async clientSend(
|
|
275
|
-
|
|
275
|
+
transactions: TransactionItem[],
|
|
276
276
|
prioritySetting?: PriorityFeeSetting
|
|
277
277
|
) {
|
|
278
|
+
const items = [...transactions];
|
|
278
279
|
const client = this.txHandler as SolautoClient;
|
|
279
280
|
|
|
280
281
|
const updateLookupTable = await client.updateLookupTable();
|
|
@@ -291,7 +292,7 @@ export class TransactionsManager {
|
|
|
291
292
|
this.txHandler.umi,
|
|
292
293
|
this.txHandler.connection,
|
|
293
294
|
updateLookupTable.updateLutTx,
|
|
294
|
-
this.
|
|
295
|
+
this.txType,
|
|
295
296
|
attemptNum,
|
|
296
297
|
prioritySetting,
|
|
297
298
|
() =>
|
|
@@ -351,7 +352,7 @@ export class TransactionsManager {
|
|
|
351
352
|
throw e;
|
|
352
353
|
});
|
|
353
354
|
|
|
354
|
-
if (
|
|
355
|
+
if (this.txType !== "only-simulate") {
|
|
355
356
|
await client.resetLiveTxUpdates();
|
|
356
357
|
}
|
|
357
358
|
}
|
|
@@ -389,7 +390,7 @@ export class TransactionsManager {
|
|
|
389
390
|
// itemSets.forEach((set) => {
|
|
390
391
|
// this.updateStatus(set.name(), TransactionStatus.Successful);
|
|
391
392
|
// });
|
|
392
|
-
} else if (
|
|
393
|
+
} else if (this.txType !== "only-simulate" || itemSets.length === 1) {
|
|
393
394
|
for (let i = 0; i < itemSets.length; i++) {
|
|
394
395
|
const getFreshItemSet = async (
|
|
395
396
|
itemSet: TransactionSet,
|
|
@@ -447,7 +448,7 @@ export class TransactionsManager {
|
|
|
447
448
|
this.txHandler.umi,
|
|
448
449
|
this.txHandler.connection,
|
|
449
450
|
tx,
|
|
450
|
-
this.
|
|
451
|
+
this.txType,
|
|
451
452
|
attemptNum,
|
|
452
453
|
prioritySetting,
|
|
453
454
|
() =>
|
package/src/types/solauto.ts
CHANGED
package/src/utils/solanaUtils.ts
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
getLendingAccountEndFlashloanInstructionDataSerializer,
|
|
37
37
|
getLendingAccountStartFlashloanInstructionDataSerializer,
|
|
38
38
|
} from "../marginfi-sdk";
|
|
39
|
-
import { PriorityFeeSetting } from "../types";
|
|
39
|
+
import { PriorityFeeSetting, TransactionRunType } from "../types";
|
|
40
40
|
|
|
41
41
|
export function getSolanaRpcConnection(
|
|
42
42
|
heliusApiKey: string
|
|
@@ -281,7 +281,7 @@ export async function sendSingleOptimizedTransaction(
|
|
|
281
281
|
umi: Umi,
|
|
282
282
|
connection: Connection,
|
|
283
283
|
tx: TransactionBuilder,
|
|
284
|
-
|
|
284
|
+
txType?: TransactionRunType,
|
|
285
285
|
attemptNum?: number,
|
|
286
286
|
prioritySetting: PriorityFeeSetting = PriorityFeeSetting.Default,
|
|
287
287
|
onAwaitingSign?: () => void
|
|
@@ -297,31 +297,33 @@ export async function sendSingleOptimizedTransaction(
|
|
|
297
297
|
);
|
|
298
298
|
console.log("Compute unit price: ", feeEstimate);
|
|
299
299
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
await
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
300
|
+
if (txType !== "skip-simulation") {
|
|
301
|
+
// TODO: we should only retry simulation if it's not a solauto error
|
|
302
|
+
const simulationResult = await retryWithExponentialBackoff(
|
|
303
|
+
async () =>
|
|
304
|
+
await simulateTransaction(
|
|
305
|
+
connection,
|
|
306
|
+
toWeb3JsTransaction(
|
|
307
|
+
await (
|
|
308
|
+
await assembleFinalTransaction(
|
|
309
|
+
umi.identity,
|
|
310
|
+
tx,
|
|
311
|
+
feeEstimate,
|
|
312
|
+
1_400_000
|
|
313
|
+
).setLatestBlockhash(umi)
|
|
314
|
+
).build(umi)
|
|
315
|
+
)
|
|
316
|
+
),
|
|
317
|
+
3
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
const computeUnitLimit = Math.round(
|
|
321
|
+
simulationResult.value.unitsConsumed! * 1.1
|
|
322
|
+
);
|
|
323
|
+
console.log("Compute unit limit: ", computeUnitLimit);
|
|
324
|
+
}
|
|
323
325
|
|
|
324
|
-
if (
|
|
326
|
+
if (txType !== "only-simulate") {
|
|
325
327
|
onAwaitingSign?.();
|
|
326
328
|
const result = await assembleFinalTransaction(
|
|
327
329
|
umi.identity,
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { describe, it } from "mocha";
|
|
2
2
|
import { none, publicKey, some } from "@metaplex-foundation/umi";
|
|
3
3
|
import { setupTest } from "../shared";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
SolautoMarginfiClient,
|
|
6
|
+
} from "../../src/clients/solautoMarginfiClient";
|
|
5
7
|
import {
|
|
6
8
|
solautoAction,
|
|
7
9
|
SolautoSettingsParametersInpArgs,
|
|
8
10
|
} from "../../src/generated";
|
|
9
11
|
import { buildSolautoRebalanceTransaction } from "../../src/transactions/transactionUtils";
|
|
10
|
-
import {
|
|
11
|
-
maxBoostToBps,
|
|
12
|
-
maxRepayFromBps,
|
|
13
|
-
maxRepayToBps,
|
|
14
|
-
toBaseUnit,
|
|
15
|
-
} from "../../src/utils/numberUtils";
|
|
12
|
+
import { maxBoostToBps, maxRepayFromBps, maxRepayToBps, toBaseUnit } from "../../src/utils/numberUtils";
|
|
16
13
|
import { NATIVE_MINT } from "@solana/spl-token";
|
|
17
14
|
import { getTokenPrices } from "../../src/utils/generalUtils";
|
|
18
15
|
import {
|
|
@@ -21,6 +18,9 @@ import {
|
|
|
21
18
|
} from "../../src/transactions/transactionsManager";
|
|
22
19
|
import { PublicKey } from "@solana/web3.js";
|
|
23
20
|
import { USDC_MINT } from "../../src/constants";
|
|
21
|
+
import {
|
|
22
|
+
ACCOUNT_SIZE as TOKEN_ACCOUNT_SIZE,
|
|
23
|
+
} from "@solana/spl-token";
|
|
24
24
|
|
|
25
25
|
describe("Solauto Marginfi tests", async () => {
|
|
26
26
|
const signer = setupTest();
|
|
@@ -31,22 +31,25 @@ describe("Solauto Marginfi tests", async () => {
|
|
|
31
31
|
const positionId = 1;
|
|
32
32
|
|
|
33
33
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
|
34
|
+
|
|
34
35
|
const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY!, true);
|
|
35
36
|
|
|
36
37
|
const supply = NATIVE_MINT;
|
|
37
38
|
const supplyDecimals = 9;
|
|
38
39
|
const debtDecimals = 6;
|
|
39
40
|
|
|
40
|
-
await client.initialize(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
await client.initialize(
|
|
42
|
+
{
|
|
43
|
+
signer,
|
|
44
|
+
positionId,
|
|
45
|
+
// authority: new PublicKey("92xmP49BQycn3t2HkGxLAweN3jjrExxSNpywA3xF7mYY")
|
|
46
|
+
// marginfiAccount: new PublicKey(
|
|
47
|
+
// "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
|
|
48
|
+
// ),
|
|
49
|
+
// supplyMint: NATIVE_MINT,
|
|
50
|
+
// debtMint: new PublicKey(USDC_MINT),
|
|
51
|
+
}
|
|
52
|
+
);
|
|
50
53
|
|
|
51
54
|
const transactionItems: TransactionItem[] = [];
|
|
52
55
|
const settingParams: SolautoSettingsParametersInpArgs = {
|
|
@@ -67,19 +70,19 @@ describe("Solauto Marginfi tests", async () => {
|
|
|
67
70
|
// }, "open position")
|
|
68
71
|
// );
|
|
69
72
|
|
|
70
|
-
const initialSupplyUsd = 150;
|
|
71
|
-
transactionItems.push(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
);
|
|
73
|
+
// const initialSupplyUsd = 150;
|
|
74
|
+
// transactionItems.push(
|
|
75
|
+
// new TransactionItem(async () => {
|
|
76
|
+
// const [supplyPrice] = await getTokenPrices([supply]);
|
|
77
|
+
// return {
|
|
78
|
+
// tx: client.protocolInteraction(
|
|
79
|
+
// solautoAction("Deposit", [
|
|
80
|
+
// toBaseUnit(initialSupplyUsd / supplyPrice, supplyDecimals),
|
|
81
|
+
// ])
|
|
82
|
+
// ),
|
|
83
|
+
// };
|
|
84
|
+
// }, "deposit")
|
|
85
|
+
// );
|
|
83
86
|
// }
|
|
84
87
|
|
|
85
88
|
// const maxLtvBps = client.solautoPositionState!.maxLtvBps;
|
|
@@ -120,13 +123,13 @@ describe("Solauto Marginfi tests", async () => {
|
|
|
120
123
|
// }, "deposit")
|
|
121
124
|
// );
|
|
122
125
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
transactionItems.push(
|
|
127
|
+
new TransactionItem(
|
|
128
|
+
async (attemptNum) =>
|
|
129
|
+
await buildSolautoRebalanceTransaction(client, 1500, attemptNum),
|
|
130
|
+
"rebalance"
|
|
131
|
+
)
|
|
132
|
+
);
|
|
130
133
|
|
|
131
134
|
// transactionItems.push(
|
|
132
135
|
// new TransactionItem(
|
|
@@ -155,11 +158,13 @@ describe("Solauto Marginfi tests", async () => {
|
|
|
155
158
|
// )
|
|
156
159
|
// );
|
|
157
160
|
|
|
158
|
-
await new TransactionsManager(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
).clientSend(transactionItems);
|
|
161
|
+
// await new TransactionsManager(
|
|
162
|
+
// client,
|
|
163
|
+
// undefined,
|
|
164
|
+
// !payForTransactions ? "only-simulate" : "normal",
|
|
165
|
+
// useJitoBundle
|
|
166
|
+
// ).clientSend(transactionItems);
|
|
167
|
+
|
|
168
|
+
console.log((await client.umi.rpc.getRent(TOKEN_ACCOUNT_SIZE)).basisPoints);
|
|
164
169
|
});
|
|
165
170
|
});
|