@haven-fi/solauto-sdk 1.0.813 → 1.0.815
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/constants/solautoConstants.d.ts +1 -0
- package/dist/constants/solautoConstants.d.ts.map +1 -1
- package/dist/constants/solautoConstants.js +2 -1
- package/dist/generated/instructions/marginfiProtocolInteraction.js +1 -1
- package/dist/generated/instructions/marginfiRebalance.js +1 -1
- package/dist/services/transactions/manager/clientTransactionsManager.d.ts +0 -1
- package/dist/services/transactions/manager/clientTransactionsManager.d.ts.map +1 -1
- package/dist/services/transactions/manager/clientTransactionsManager.js +1 -21
- package/dist/services/transactions/manager/transactionsManager.d.ts +0 -1
- package/dist/services/transactions/manager/transactionsManager.d.ts.map +1 -1
- package/dist/services/transactions/manager/transactionsManager.js +12 -6
- package/dist/services/transactions/types/transactionSet.d.ts +2 -1
- package/dist/services/transactions/types/transactionSet.d.ts.map +1 -1
- package/dist/services/transactions/types/transactionSet.js +11 -1
- package/dist/solautoPosition/positionUtils.js +10 -10
- package/dist/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +2 -1
- package/dist/utils/marginfi/data.js +6 -6
- package/dist/utils/solautoUtils.js +3 -3
- package/dist/utils/switchboardUtils.d.ts +2 -0
- package/dist/utils/switchboardUtils.d.ts.map +1 -1
- package/dist/utils/switchboardUtils.js +20 -1
- package/local/txSandbox.ts +26 -4
- package/package.json +1 -1
- package/src/constants/solautoConstants.ts +2 -0
- package/src/generated/instructions/marginfiProtocolInteraction.ts +1 -1
- package/src/generated/instructions/marginfiRebalance.ts +1 -1
- package/src/services/transactions/manager/clientTransactionsManager.ts +2 -41
- package/src/services/transactions/manager/transactionsManager.ts +40 -10
- package/src/services/transactions/types/transactionSet.ts +21 -1
- package/src/solautoPosition/positionUtils.ts +10 -10
- package/src/utils/jitoUtils.ts +17 -12
- package/src/utils/marginfi/data.ts +6 -6
- package/src/utils/solautoUtils.ts +3 -3
- package/src/utils/switchboardUtils.ts +44 -3
|
@@ -20,5 +20,6 @@ export declare const CHORES_TX_NAME = "account chores";
|
|
|
20
20
|
export declare const JITO_TIP_ACCOUNTS: string[];
|
|
21
21
|
export declare const SOLAUTO_LUT = "8b7KefQDroVLGao71J5H3hFwABeyMCgCrLpXWssNFhk9";
|
|
22
22
|
export declare const STANDARD_LUT_ACCOUNTS: string[];
|
|
23
|
+
export declare const UPDATE_ORACLE_TX_NAME = "update oracle";
|
|
23
24
|
export {};
|
|
24
25
|
//# sourceMappingURL=solautoConstants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AAQzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,UAAU,UAAU;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;CACd;AACD,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAO,CAAC;AAExD,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAE/C,eAAO,MAAM,iBAAiB,UAS7B,CAAC;AAEF,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAC1E,eAAO,MAAM,qBAAqB,UAYR,CAAC"}
|
|
1
|
+
{"version":3,"file":"solautoConstants.d.ts","sourceRoot":"","sources":["../../src/constants/solautoConstants.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,SAAS,EACV,MAAM,iBAAiB,CAAC;AAQzB,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AACF,eAAO,MAAM,oBAAoB,WAEhC,CAAC;AAIF,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAE/C,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,UAAU,UAAU;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;CACd;AACD,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAO,CAAC;AAExD,eAAO,MAAM,cAAc,mBAAmB,CAAC;AAE/C,eAAO,MAAM,iBAAiB,UAS7B,CAAC;AAEF,eAAO,MAAM,WAAW,iDAAiD,CAAC;AAC1E,eAAO,MAAM,qBAAqB,UAYR,CAAC;AAE3B,eAAO,MAAM,qBAAqB,kBAAkB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STANDARD_LUT_ACCOUNTS = exports.SOLAUTO_LUT = exports.JITO_TIP_ACCOUNTS = exports.CHORES_TX_NAME = exports.PRICES = exports.REFERRER_PERCENTAGE = exports.OFFSET_FROM_MAX_LTV = exports.MIN_USD_SUPPORTED_POSITION = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.SOLAUTO_TEST_PROGRAM = exports.SOLAUTO_PROD_PROGRAM = void 0;
|
|
3
|
+
exports.UPDATE_ORACLE_TX_NAME = exports.STANDARD_LUT_ACCOUNTS = exports.SOLAUTO_LUT = exports.JITO_TIP_ACCOUNTS = exports.CHORES_TX_NAME = exports.PRICES = exports.REFERRER_PERCENTAGE = exports.OFFSET_FROM_MAX_LTV = exports.MIN_USD_SUPPORTED_POSITION = exports.MIN_BOOST_GAP_BPS = exports.MIN_REPAY_GAP_BPS = exports.SOLAUTO_TEST_PROGRAM = exports.SOLAUTO_PROD_PROGRAM = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const spl_token_1 = require("@solana/spl-token");
|
|
6
6
|
const generalConstants_1 = require("./generalConstants");
|
|
@@ -39,3 +39,4 @@ exports.STANDARD_LUT_ACCOUNTS = [
|
|
|
39
39
|
web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
40
40
|
jupiter_1.JUPITER_PROGRAM_ID,
|
|
41
41
|
].map((x) => x.toString());
|
|
42
|
+
exports.UPDATE_ORACLE_TX_NAME = "update oracle";
|
|
@@ -3,7 +3,6 @@ import { TransactionsManager } from "./transactionsManager";
|
|
|
3
3
|
import { TransactionItem } from "../types";
|
|
4
4
|
export declare class ClientTransactionsManager extends TransactionsManager<SolautoClient> {
|
|
5
5
|
private updateLut;
|
|
6
|
-
private addSwbOraclePullTxs;
|
|
7
6
|
private addChoreTxs;
|
|
8
7
|
send(transactions: TransactionItem[]): Promise<import("./transactionsManager").TransactionManagerStatuses>;
|
|
9
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientTransactionsManager.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/manager/clientTransactionsManager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"clientTransactionsManager.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/manager/clientTransactionsManager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAQ5D,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAI3C,qBAAa,yBAA0B,SAAQ,mBAAmB,CAAC,aAAa,CAAC;YACjE,SAAS;YAmBT,WAAW;IA4CZ,IAAI,CAAC,YAAY,EAAE,eAAe,EAAE;CAmClD"}
|
|
@@ -14,26 +14,6 @@ class ClientTransactionsManager extends transactionsManager_1.TransactionsManage
|
|
|
14
14
|
await (0, utils_1.retryWithExponentialBackoff)(async (attemptNum, prevError) => await this.sendTransaction(tx.setAddressLookupTables(lutInputs), updateLutTxName, attemptNum, this.getUpdatedPriorityFeeSetting(prevError, attemptNum), "skip-simulation"), this.signableRetries, 150, this.errorsToThrow);
|
|
15
15
|
await this.txHandler.refetchReferralState();
|
|
16
16
|
}
|
|
17
|
-
async addSwbOraclePullTxs(txs) {
|
|
18
|
-
const switchboardMints = [
|
|
19
|
-
...((0, utils_1.isSwitchboardMint)(this.txHandler.pos.supplyMint)
|
|
20
|
-
? [this.txHandler.pos.supplyMint]
|
|
21
|
-
: []),
|
|
22
|
-
...((0, utils_1.isSwitchboardMint)(this.txHandler.pos.debtMint)
|
|
23
|
-
? [this.txHandler.pos.debtMint]
|
|
24
|
-
: []),
|
|
25
|
-
];
|
|
26
|
-
if (txs.find((x) => x.oracleInteractor) && switchboardMints.length) {
|
|
27
|
-
this.txHandler.log("Checking if oracle update(s) needed...");
|
|
28
|
-
const staleOracles = (await (0, utils_1.getSwitchboardFeedData)(this.txHandler.connection, switchboardMints)).filter((x) => x.stale).length > 0;
|
|
29
|
-
if (staleOracles) {
|
|
30
|
-
this.txHandler.log("Requires oracle update(s)...");
|
|
31
|
-
const oracleTxs = switchboardMints.map((x) => new types_1.TransactionItem(async () => await (0, utils_1.buildSwbSubmitResponseTx)(this.txHandler.connection, this.txHandler.signer, x), this.updateOracleTxName));
|
|
32
|
-
this.txHandler.log("Set crank IXs in TX");
|
|
33
|
-
txs.unshift(...oracleTxs);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
17
|
async addChoreTxs(txs, updateLutTx) {
|
|
38
18
|
let [choresBefore, choresAfter] = await (0, transactionUtils_1.getTransactionChores)(this.txHandler, (0, umi_1.transactionBuilder)().add(txs
|
|
39
19
|
.filter((x) => x.tx && x.tx.getInstructions().length > 0)
|
|
@@ -63,7 +43,7 @@ class ClientTransactionsManager extends transactionsManager_1.TransactionsManage
|
|
|
63
43
|
await this.updateLut(updateLut.tx, updateLut.new);
|
|
64
44
|
}
|
|
65
45
|
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
|
66
|
-
await this.
|
|
46
|
+
// await addSwbOraclePullTxs(this.txHandler, items);
|
|
67
47
|
for (const item of items) {
|
|
68
48
|
await item.initialize();
|
|
69
49
|
}
|
|
@@ -50,7 +50,6 @@ export declare class TransactionsManager<T extends TxHandler> {
|
|
|
50
50
|
protected totalRetries: number;
|
|
51
51
|
protected retryDelay: number;
|
|
52
52
|
protected abortController?: AbortController;
|
|
53
|
-
updateOracleTxName: string;
|
|
54
53
|
constructor(args: TransactionsManagerArgs<T>);
|
|
55
54
|
private assembleTransactionSets;
|
|
56
55
|
private updateStatus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/manager/transactionsManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EACL,kBAAkB,EAElB,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,aAAa,EAId,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C,OAAO,
|
|
1
|
+
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/manager/transactionsManager.ts"],"names":[],"mappings":"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"}
|
|
@@ -10,6 +10,10 @@ const types_1 = require("../../../types");
|
|
|
10
10
|
const utils_1 = require("../../../utils");
|
|
11
11
|
const transactionUtils_1 = require("../transactionUtils");
|
|
12
12
|
const types_2 = require("../types");
|
|
13
|
+
const constants_1 = require("../../../constants");
|
|
14
|
+
const utils_2 = require("../../../utils");
|
|
15
|
+
// Buffer for Jito tip instruction that will be added later
|
|
16
|
+
const JITO_TIP_BUFFER_BYTES = 75;
|
|
13
17
|
class TransactionTooLargeError extends Error {
|
|
14
18
|
constructor(message) {
|
|
15
19
|
super(message);
|
|
@@ -29,7 +33,6 @@ var TransactionStatus;
|
|
|
29
33
|
class TransactionsManager {
|
|
30
34
|
constructor(args) {
|
|
31
35
|
this.statuses = [];
|
|
32
|
-
this.updateOracleTxName = "update oracle";
|
|
33
36
|
this.txHandler = args.txHandler;
|
|
34
37
|
this.statusCallback = args.statusCallback;
|
|
35
38
|
this.txRunType = args.txRunType;
|
|
@@ -54,9 +57,10 @@ class TransactionsManager {
|
|
|
54
57
|
if (!item.tx) {
|
|
55
58
|
continue;
|
|
56
59
|
}
|
|
57
|
-
const transaction = item.tx.setAddressLookupTables(await this.lookupTables.getLutInputs(item.lookupTableAddresses));
|
|
58
|
-
if
|
|
59
|
-
|
|
60
|
+
const transaction = (0, utils_2.addTxOptimizations)(this.txHandler.umi, item.tx, 1, 1).setAddressLookupTables(await this.lookupTables.getLutInputs(item.lookupTableAddresses));
|
|
61
|
+
// Check if transaction fits with buffer for Jito tip instruction
|
|
62
|
+
if (!(0, types_2.fitsInOneTransactionWithBuffer)(transaction, this.txHandler.umi, JITO_TIP_BUFFER_BYTES)) {
|
|
63
|
+
throw new TransactionTooLargeError(`Exceeds max transaction size (${transaction.getTransactionSize(this.txHandler.umi)} + ~${JITO_TIP_BUFFER_BYTES} bytes for Jito tip)`);
|
|
60
64
|
}
|
|
61
65
|
else {
|
|
62
66
|
let newSet = new types_2.TransactionSet(this.txHandler, this.lookupTables, [
|
|
@@ -102,7 +106,9 @@ class TransactionsManager {
|
|
|
102
106
|
this.statuses.push(args);
|
|
103
107
|
}
|
|
104
108
|
}
|
|
105
|
-
(0, utils_1.consoleLog)(`${args.name} ${args.attemptNum} is ${args.status
|
|
109
|
+
(0, utils_1.consoleLog)(`${args.name} ${args.attemptNum} is ${args.status
|
|
110
|
+
.toString()
|
|
111
|
+
.toLowerCase()}`);
|
|
106
112
|
this.statusCallback?.([...this.statuses]);
|
|
107
113
|
}
|
|
108
114
|
async debugAccounts(itemSet, tx) {
|
|
@@ -171,7 +177,7 @@ class TransactionsManager {
|
|
|
171
177
|
}
|
|
172
178
|
const newItemSetNames = itemSets.flatMap((x) => x.items.map((y) => y.name ?? ""));
|
|
173
179
|
if (newItemSetNames.length === 1 &&
|
|
174
|
-
newItemSetNames[0] ===
|
|
180
|
+
newItemSetNames[0] === constants_1.UPDATE_ORACLE_TX_NAME) {
|
|
175
181
|
(0, utils_1.consoleLog)("Skipping unnecessary oracle update");
|
|
176
182
|
this.updateStatusForSets(itemSets.map((x) => x.name()), {
|
|
177
183
|
status: TransactionStatus.Skipped,
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { AddressLookupTableInput, TransactionBuilder } from "@metaplex-foundation/umi";
|
|
1
|
+
import { AddressLookupTableInput, TransactionBuilder, Umi } from "@metaplex-foundation/umi";
|
|
2
2
|
import { TxHandler } from "../../solauto";
|
|
3
3
|
import { LookupTables } from "./lookupTables";
|
|
4
4
|
import { TransactionItem } from "./transactionItem";
|
|
5
|
+
export declare function fitsInOneTransactionWithBuffer(tx: TransactionBuilder, umi: Umi, extraBuffer?: number): boolean;
|
|
5
6
|
export declare class TransactionSet {
|
|
6
7
|
private txHandler;
|
|
7
8
|
lookupTables: LookupTables;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactionSet.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/types/transactionSet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAEvB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"transactionSet.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/types/transactionSet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAEvB,kBAAkB,EAClB,GAAG,EACJ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAUpD,wBAAgB,8BAA8B,CAC5C,EAAE,EAAE,kBAAkB,EACtB,GAAG,EAAE,GAAG,EACR,WAAW,GAAE,MAAU,GACtB,OAAO,CAIT;AAED,qBAAa,cAAc;IAEvB,OAAO,CAAC,SAAS;IACV,YAAY,EAAE,YAAY;IAC1B,KAAK,EAAE,eAAe,EAAE;gBAFvB,SAAS,EAAE,SAAS,EACrB,YAAY,EAAE,YAAY,EAC1B,KAAK,GAAE,eAAe,EAAO;IAGhC,SAAS,IAAI,OAAO,CAAC,uBAAuB,EAAE,CAAC;IAY/C,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC;IAiCvD,GAAG,CAAC,GAAG,KAAK,EAAE,eAAe,EAAE;IAM/B,OAAO,CAAC,GAAG,KAAK,EAAE,eAAe,EAAE;IAM7B,KAAK;IAIL,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;IAMhD,oBAAoB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAUzD,YAAY,IAAI,MAAM,EAAE;IAMxB,IAAI,IAAI,MAAM;CAef"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransactionSet = void 0;
|
|
4
|
+
exports.fitsInOneTransactionWithBuffer = fitsInOneTransactionWithBuffer;
|
|
4
5
|
const umi_1 = require("@metaplex-foundation/umi");
|
|
5
6
|
const utils_1 = require("../../../utils");
|
|
6
7
|
const constants_1 = require("../../../constants");
|
|
7
8
|
const MAX_SUPPORTED_ACCOUNT_LOCKS = 64;
|
|
9
|
+
// Buffer for Jito tip instruction (~44 bytes) + potential new accounts in message
|
|
10
|
+
// This accounts for: System Transfer instruction data, Jito tip account (if new), etc.
|
|
11
|
+
const JITO_TIP_BUFFER_BYTES = 75;
|
|
12
|
+
function fitsInOneTransactionWithBuffer(tx, umi, extraBuffer = 0) {
|
|
13
|
+
const MAX_TX_SIZE = 1232;
|
|
14
|
+
const size = tx.getTransactionSize(umi);
|
|
15
|
+
return size + extraBuffer <= MAX_TX_SIZE;
|
|
16
|
+
}
|
|
8
17
|
class TransactionSet {
|
|
9
18
|
constructor(txHandler, lookupTables, items = []) {
|
|
10
19
|
this.txHandler = txHandler;
|
|
@@ -34,7 +43,8 @@ class TransactionSet {
|
|
|
34
43
|
...this.lutAddresses(),
|
|
35
44
|
...item.lookupTableAddresses,
|
|
36
45
|
]));
|
|
37
|
-
|
|
46
|
+
// Account for Jito tip instruction that will be added later
|
|
47
|
+
return fitsInOneTransactionWithBuffer(tx, this.txHandler.umi, JITO_TIP_BUFFER_BYTES);
|
|
38
48
|
}
|
|
39
49
|
add(...items) {
|
|
40
50
|
this.items.push(...items.filter((x) => x.tx && x.tx.getInstructions().length > 0));
|
|
@@ -15,7 +15,7 @@ function createSolautoSettings(settings) {
|
|
|
15
15
|
boostToBps: settings.boostToBps,
|
|
16
16
|
repayGap: settings.repayGap,
|
|
17
17
|
repayToBps: settings.repayToBps,
|
|
18
|
-
padding:
|
|
18
|
+
padding: new Array(24).fill(0),
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
async function getPositionExBulk(umi, publicKeys) {
|
|
@@ -86,9 +86,9 @@ function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
|
|
|
86
86
|
borrowFeeBps: 0,
|
|
87
87
|
decimals: supplyDecimals,
|
|
88
88
|
mint: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(supply.mint),
|
|
89
|
-
padding1:
|
|
90
|
-
padding2:
|
|
91
|
-
padding: new Uint8Array(
|
|
89
|
+
padding1: new Array(5).fill(0),
|
|
90
|
+
padding2: new Array(8).fill(0),
|
|
91
|
+
padding: new Uint8Array(32),
|
|
92
92
|
},
|
|
93
93
|
debt: {
|
|
94
94
|
amountUsed: {
|
|
@@ -103,9 +103,9 @@ function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
|
|
|
103
103
|
borrowFeeBps: 0,
|
|
104
104
|
decimals: debtDecimals,
|
|
105
105
|
mint: (0, umi_web3js_adapters_1.fromWeb3JsPublicKey)(debt.mint),
|
|
106
|
-
padding1:
|
|
107
|
-
padding2:
|
|
108
|
-
padding: new Uint8Array(
|
|
106
|
+
padding1: new Array(5).fill(0),
|
|
107
|
+
padding2: new Array(8).fill(0),
|
|
108
|
+
padding: new Uint8Array(32),
|
|
109
109
|
},
|
|
110
110
|
netWorth: {
|
|
111
111
|
baseUnit: supply.price
|
|
@@ -116,8 +116,8 @@ function createFakePositionState(supply, debt, maxLtvBps, liqThresholdBps) {
|
|
|
116
116
|
maxLtvBps,
|
|
117
117
|
liqThresholdBps,
|
|
118
118
|
lastRefreshed: BigInt((0, utils_1.currentUnixSeconds)()),
|
|
119
|
-
padding1:
|
|
120
|
-
padding2:
|
|
121
|
-
padding:
|
|
119
|
+
padding1: new Array(6).fill(0),
|
|
120
|
+
padding2: new Array(4).fill(0),
|
|
121
|
+
padding: new Array(2).fill(0),
|
|
122
122
|
};
|
|
123
123
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAIV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEH,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAiBlE,wBAAgB,mBAAmB,IAAI,SAAS,CAG/C;AAiGD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB;;;;IAkB/D;AAqHD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,EACtB,YAAY,EAAE,kBAAkB,EAAE,EAClC,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,EAC3B,eAAe,CAAC,EAAE,eAAe,GAChC,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAIV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEH,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAiBlE,wBAAgB,mBAAmB,IAAI,SAAS,CAG/C;AAiGD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB;;;;IAkB/D;AAqHD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EAAE,EACtB,YAAY,EAAE,kBAAkB,EAAE,EAClC,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,EAC3B,eAAe,CAAC,EAAE,eAAe,GAChC,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAkH/B"}
|
package/dist/utils/jitoUtils.js
CHANGED
|
@@ -187,8 +187,9 @@ async function sendJitoBundledTransactions(umi, connection, userSigner, otherSig
|
|
|
187
187
|
(0, generalUtils_1.consoleLog)("Sending Jito bundle...");
|
|
188
188
|
(0, generalUtils_1.consoleLog)("Transactions: ", txs.length);
|
|
189
189
|
(0, generalUtils_1.consoleLog)(txs.map((tx) => tx.getInstructions().map((x) => x.programId.toString())));
|
|
190
|
-
(0, generalUtils_1.consoleLog)("Transaction sizes: ", txs.map((x) => x.getTransactionSize(umi)));
|
|
190
|
+
(0, generalUtils_1.consoleLog)("Transaction sizes (before tip): ", txs.map((x) => x.getTransactionSize(umi)));
|
|
191
191
|
txs[0] = (0, solanaUtils_1.prependTx)(txs[0], [getTipInstruction(userSigner, 250000)]);
|
|
192
|
+
(0, generalUtils_1.consoleLog)("Transaction sizes (after tip): ", txs.map((x) => x.getTransactionSize(umi)));
|
|
192
193
|
const latestBlockhash = (await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await umi.rpc.getLatestBlockhash({ commitment: "confirmed" }))).blockhash;
|
|
193
194
|
if (abortController?.signal.aborted) {
|
|
194
195
|
return;
|
|
@@ -169,9 +169,9 @@ async function getTokenUsage(bank, isAsset, shares, amountUsedAdjustment, priceT
|
|
|
169
169
|
},
|
|
170
170
|
baseAmountMarketPriceUsd: (0, numberUtils_1.toBaseUnit)(marketPrice, constants_1.USD_DECIMALS),
|
|
171
171
|
borrowFeeBps: isAsset ? 0 : (0, numberUtils_1.toBps)(originationFee),
|
|
172
|
-
padding1:
|
|
173
|
-
padding2:
|
|
174
|
-
padding: new Uint8Array(
|
|
172
|
+
padding1: new Array(5).fill(0),
|
|
173
|
+
padding2: new Array(8).fill(0),
|
|
174
|
+
padding: new Uint8Array(32),
|
|
175
175
|
};
|
|
176
176
|
}
|
|
177
177
|
async function getBank(umi, data, marginfiGroup) {
|
|
@@ -287,9 +287,9 @@ async function getMarginfiAccountPositionState(umi, lpUserAccount, marginfiGroup
|
|
|
287
287
|
maxLtvBps,
|
|
288
288
|
liqThresholdBps,
|
|
289
289
|
lastRefreshed: BigInt((0, generalUtils_1.currentUnixSeconds)()),
|
|
290
|
-
padding1:
|
|
291
|
-
padding2:
|
|
292
|
-
padding:
|
|
290
|
+
padding1: new Array(6).fill(0),
|
|
291
|
+
padding2: new Array(4).fill(0),
|
|
292
|
+
padding: new Array(2).fill(0),
|
|
293
293
|
},
|
|
294
294
|
};
|
|
295
295
|
}
|
|
@@ -278,12 +278,12 @@ class ContextUpdates {
|
|
|
278
278
|
...dca.automation,
|
|
279
279
|
intervalSeconds: BigInt(dca.automation.intervalSeconds),
|
|
280
280
|
unixStartDate: BigInt(dca.automation.unixStartDate),
|
|
281
|
-
padding: new Uint8Array(
|
|
282
|
-
padding1:
|
|
281
|
+
padding: new Uint8Array(32),
|
|
282
|
+
padding1: new Array(4).fill(0),
|
|
283
283
|
},
|
|
284
284
|
dcaInBaseUnit: BigInt(dca.dcaInBaseUnit),
|
|
285
285
|
tokenType: dca.tokenType,
|
|
286
|
-
padding:
|
|
286
|
+
padding: new Array(31).fill(0),
|
|
287
287
|
};
|
|
288
288
|
}
|
|
289
289
|
else if (update.type === "cancellingDca") {
|
|
@@ -2,6 +2,7 @@ import { Connection, PublicKey } from "@solana/web3.js";
|
|
|
2
2
|
import { Signer } from "@metaplex-foundation/umi";
|
|
3
3
|
import * as OnDemand from "@switchboard-xyz/on-demand";
|
|
4
4
|
import { TransactionItemInputs } from "../types";
|
|
5
|
+
import { SolautoClient, TransactionItem } from "../services";
|
|
5
6
|
export declare function getPullFeed(conn: Connection, mint: PublicKey, wallet?: PublicKey): Promise<{
|
|
6
7
|
gateway: OnDemand.Gateway;
|
|
7
8
|
feed: OnDemand.PullFeed;
|
|
@@ -13,4 +14,5 @@ export declare function getSwitchboardFeedData(conn: Connection, mints: PublicKe
|
|
|
13
14
|
stale: boolean;
|
|
14
15
|
}[]>;
|
|
15
16
|
export declare function isSwitchboardMint(mint: PublicKey | string): boolean;
|
|
17
|
+
export declare function addSwbOraclePullTxs(client: SolautoClient, txs: TransactionItem[]): Promise<void>;
|
|
16
18
|
//# sourceMappingURL=switchboardUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAsB,MAAM,0BAA0B,CAAC;AAGtE,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"switchboardUtils.d.ts","sourceRoot":"","sources":["../../src/utils/switchboardUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EAGV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAsB,MAAM,0BAA0B,CAAC;AAGtE,OAAO,KAAK,QAAQ,MAAM,4BAA4B,CAAC;AAOvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAQjD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE7D,wBAAsB,WAAW,CAC/B,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS;;;GAkCnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAiD5C;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,SAAS,EAAE,GACjB,OAAO,CAAC;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,CAuB/D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,WAEzD;AAED,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,aAAa,EACrB,GAAG,EAAE,eAAe,EAAE,iBAkCvB"}
|
|
@@ -37,6 +37,7 @@ exports.getPullFeed = getPullFeed;
|
|
|
37
37
|
exports.buildSwbSubmitResponseTx = buildSwbSubmitResponseTx;
|
|
38
38
|
exports.getSwitchboardFeedData = getSwitchboardFeedData;
|
|
39
39
|
exports.isSwitchboardMint = isSwitchboardMint;
|
|
40
|
+
exports.addSwbOraclePullTxs = addSwbOraclePullTxs;
|
|
40
41
|
const web3_js_1 = require("@solana/web3.js");
|
|
41
42
|
const umi_1 = require("@metaplex-foundation/umi");
|
|
42
43
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
|
@@ -46,6 +47,7 @@ const constants_1 = require("../constants");
|
|
|
46
47
|
const generalUtils_1 = require("./generalUtils");
|
|
47
48
|
const solanaUtils_1 = require("./solanaUtils");
|
|
48
49
|
const common_1 = require("@switchboard-xyz/common");
|
|
50
|
+
const services_1 = require("../services");
|
|
49
51
|
async function getPullFeed(conn, mint, wallet) {
|
|
50
52
|
const dummyWallet = {
|
|
51
53
|
publicKey: wallet ?? new web3_js_1.PublicKey("11111111111111111111111111111111"),
|
|
@@ -68,7 +70,6 @@ async function getPullFeed(conn, mint, wallet) {
|
|
|
68
70
|
}
|
|
69
71
|
async function buildSwbSubmitResponseTx(conn, signer, mint) {
|
|
70
72
|
const { feed, gateway } = await getPullFeed(conn, mint, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(signer.publicKey));
|
|
71
|
-
// Try to replicate locally in the lambda docker container
|
|
72
73
|
(0, generalUtils_1.consoleLog)("Fetching crank IX...");
|
|
73
74
|
const [pullIxs, responses] = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
|
74
75
|
const res = await feed.fetchUpdateIx({
|
|
@@ -120,3 +121,21 @@ async function getSwitchboardFeedData(conn, mints) {
|
|
|
120
121
|
function isSwitchboardMint(mint) {
|
|
121
122
|
return Object.keys(constants_1.SWITCHBOARD_PRICE_FEED_IDS).includes(mint.toString());
|
|
122
123
|
}
|
|
124
|
+
async function addSwbOraclePullTxs(client, txs) {
|
|
125
|
+
const switchboardMints = [
|
|
126
|
+
...(isSwitchboardMint(client.pos.supplyMint)
|
|
127
|
+
? [client.pos.supplyMint]
|
|
128
|
+
: []),
|
|
129
|
+
...(isSwitchboardMint(client.pos.debtMint) ? [client.pos.debtMint] : []),
|
|
130
|
+
];
|
|
131
|
+
if (txs.find((x) => x.oracleInteractor) && switchboardMints.length) {
|
|
132
|
+
(0, generalUtils_1.consoleLog)("Checking if oracle update(s) needed...");
|
|
133
|
+
const staleOracles = (await getSwitchboardFeedData(client.connection, switchboardMints)).filter((x) => x.stale).length > 0;
|
|
134
|
+
if (staleOracles) {
|
|
135
|
+
(0, generalUtils_1.consoleLog)("Requires oracle update(s)...");
|
|
136
|
+
const oracleTxs = switchboardMints.map((x) => new services_1.TransactionItem(async () => await buildSwbSubmitResponseTx(client.connection, client.signer, x), constants_1.UPDATE_ORACLE_TX_NAME));
|
|
137
|
+
(0, generalUtils_1.consoleLog)("Set crank IXs in TX");
|
|
138
|
+
txs.unshift(...oracleTxs);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
package/local/txSandbox.ts
CHANGED
|
@@ -2,10 +2,13 @@ import { Keypair, PublicKey } from "@solana/web3.js";
|
|
|
2
2
|
import { createSignerFromKeypair, publicKey } from "@metaplex-foundation/umi";
|
|
3
3
|
import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
|
|
4
4
|
import {
|
|
5
|
+
buildSwbSubmitResponseTx,
|
|
5
6
|
ClientTransactionsManager,
|
|
6
7
|
consoleLog,
|
|
8
|
+
fetchBank,
|
|
7
9
|
getBatches,
|
|
8
10
|
getClient,
|
|
11
|
+
getMarginfiAccounts,
|
|
9
12
|
getPositionExBulk,
|
|
10
13
|
getSolanaRpcConnection,
|
|
11
14
|
getSolautoManagedPositions,
|
|
@@ -15,12 +18,16 @@ import {
|
|
|
15
18
|
PriorityFeeSetting,
|
|
16
19
|
ProgramEnv,
|
|
17
20
|
rebalance,
|
|
21
|
+
safeFetchBank,
|
|
22
|
+
safeFetchMarginfiAccount,
|
|
18
23
|
SOLAUTO_PROD_PROGRAM,
|
|
19
24
|
SOLAUTO_TEST_PROGRAM,
|
|
20
25
|
SolautoClient,
|
|
21
26
|
TransactionItem,
|
|
27
|
+
USDC,
|
|
22
28
|
} from "../src";
|
|
23
29
|
import { getSecretKey } from "./shared";
|
|
30
|
+
import { NATIVE_MINT } from "@solana/spl-token";
|
|
24
31
|
|
|
25
32
|
const payForTransaction = true;
|
|
26
33
|
const testProgram = false;
|
|
@@ -46,15 +53,30 @@ export async function main() {
|
|
|
46
53
|
lpEnv,
|
|
47
54
|
});
|
|
48
55
|
|
|
49
|
-
await client.
|
|
50
|
-
positionId: 1,
|
|
51
|
-
|
|
56
|
+
await client.initializeNewSolautoPosition({
|
|
57
|
+
// positionId: 1,
|
|
58
|
+
positionId: 99,
|
|
59
|
+
supplyMint: NATIVE_MINT,
|
|
60
|
+
debtMint: new PublicKey(USDC),
|
|
61
|
+
lpPoolAccount: getMarginfiAccounts().defaultGroup,
|
|
62
|
+
// lpPoolAccount: new PublicKey("GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz")
|
|
52
63
|
// lpUserAccount: new PublicKey(
|
|
53
64
|
// "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
|
|
54
65
|
// ),
|
|
55
66
|
});
|
|
56
67
|
|
|
57
|
-
const transactionItems = [rebalance(client)];
|
|
68
|
+
// const transactionItems = [rebalance(client)];
|
|
69
|
+
const transactionItems: TransactionItem[] = [
|
|
70
|
+
new TransactionItem(
|
|
71
|
+
async () =>
|
|
72
|
+
await buildSwbSubmitResponseTx(
|
|
73
|
+
client.connection,
|
|
74
|
+
client.signer,
|
|
75
|
+
new PublicKey(NATIVE_MINT)
|
|
76
|
+
// new PublicKey(JITO_SOL)
|
|
77
|
+
)!
|
|
78
|
+
),
|
|
79
|
+
];
|
|
58
80
|
|
|
59
81
|
const txManager = new ClientTransactionsManager({
|
|
60
82
|
txHandler: client,
|
package/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
import { SolautoClient } from "../../solauto";
|
|
6
6
|
import { TransactionsManager } from "./transactionsManager";
|
|
7
7
|
import {
|
|
8
|
+
addSwbOraclePullTxs,
|
|
8
9
|
buildSwbSubmitResponseTx,
|
|
9
10
|
getSwitchboardFeedData,
|
|
10
11
|
isSwitchboardMint,
|
|
@@ -34,46 +35,6 @@ export class ClientTransactionsManager extends TransactionsManager<SolautoClient
|
|
|
34
35
|
await this.txHandler.refetchReferralState();
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
private async addSwbOraclePullTxs(txs: TransactionItem[]) {
|
|
38
|
-
const switchboardMints = [
|
|
39
|
-
...(isSwitchboardMint(this.txHandler.pos.supplyMint)
|
|
40
|
-
? [this.txHandler.pos.supplyMint]
|
|
41
|
-
: []),
|
|
42
|
-
...(isSwitchboardMint(this.txHandler.pos.debtMint)
|
|
43
|
-
? [this.txHandler.pos.debtMint]
|
|
44
|
-
: []),
|
|
45
|
-
];
|
|
46
|
-
|
|
47
|
-
if (txs.find((x) => x.oracleInteractor) && switchboardMints.length) {
|
|
48
|
-
this.txHandler.log("Checking if oracle update(s) needed...");
|
|
49
|
-
const staleOracles =
|
|
50
|
-
(
|
|
51
|
-
await getSwitchboardFeedData(
|
|
52
|
-
this.txHandler.connection,
|
|
53
|
-
switchboardMints
|
|
54
|
-
)
|
|
55
|
-
).filter((x) => x.stale).length > 0;
|
|
56
|
-
|
|
57
|
-
if (staleOracles) {
|
|
58
|
-
this.txHandler.log("Requires oracle update(s)...");
|
|
59
|
-
const oracleTxs = switchboardMints.map(
|
|
60
|
-
(x) =>
|
|
61
|
-
new TransactionItem(
|
|
62
|
-
async () =>
|
|
63
|
-
await buildSwbSubmitResponseTx(
|
|
64
|
-
this.txHandler.connection,
|
|
65
|
-
this.txHandler.signer,
|
|
66
|
-
x
|
|
67
|
-
),
|
|
68
|
-
this.updateOracleTxName
|
|
69
|
-
)
|
|
70
|
-
);
|
|
71
|
-
this.txHandler.log("Set crank IXs in TX");
|
|
72
|
-
txs.unshift(...oracleTxs);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
38
|
private async addChoreTxs(
|
|
78
39
|
txs: TransactionItem[],
|
|
79
40
|
updateLutTx?: TransactionBuilder
|
|
@@ -131,7 +92,7 @@ export class ClientTransactionsManager extends TransactionsManager<SolautoClient
|
|
|
131
92
|
}
|
|
132
93
|
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
|
133
94
|
|
|
134
|
-
await this.
|
|
95
|
+
// await addSwbOraclePullTxs(this.txHandler, items);
|
|
135
96
|
|
|
136
97
|
for (const item of items) {
|
|
137
98
|
await item.initialize();
|
|
@@ -15,7 +15,17 @@ import {
|
|
|
15
15
|
} from "../../../utils";
|
|
16
16
|
import { TxHandler } from "../../solauto";
|
|
17
17
|
import { getErrorInfo } from "../transactionUtils";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
LookupTables,
|
|
20
|
+
TransactionItem,
|
|
21
|
+
TransactionSet,
|
|
22
|
+
fitsInOneTransactionWithBuffer,
|
|
23
|
+
} from "../types";
|
|
24
|
+
import { UPDATE_ORACLE_TX_NAME } from "../../../constants";
|
|
25
|
+
import { addTxOptimizations } from "../../../utils";
|
|
26
|
+
|
|
27
|
+
// Buffer for Jito tip instruction that will be added later
|
|
28
|
+
const JITO_TIP_BUFFER_BYTES = 75;
|
|
19
29
|
|
|
20
30
|
export class TransactionTooLargeError extends Error {
|
|
21
31
|
constructor(message: string) {
|
|
@@ -75,8 +85,6 @@ export class TransactionsManager<T extends TxHandler> {
|
|
|
75
85
|
protected retryDelay: number;
|
|
76
86
|
protected abortController?: AbortController;
|
|
77
87
|
|
|
78
|
-
updateOracleTxName = "update oracle";
|
|
79
|
-
|
|
80
88
|
constructor(args: TransactionsManagerArgs<T>) {
|
|
81
89
|
this.txHandler = args.txHandler;
|
|
82
90
|
this.statusCallback = args.statusCallback;
|
|
@@ -113,12 +121,26 @@ export class TransactionsManager<T extends TxHandler> {
|
|
|
113
121
|
continue;
|
|
114
122
|
}
|
|
115
123
|
|
|
116
|
-
const transaction =
|
|
124
|
+
const transaction = addTxOptimizations(
|
|
125
|
+
this.txHandler.umi,
|
|
126
|
+
item.tx,
|
|
127
|
+
1,
|
|
128
|
+
1
|
|
129
|
+
).setAddressLookupTables(
|
|
117
130
|
await this.lookupTables.getLutInputs(item.lookupTableAddresses)
|
|
118
131
|
);
|
|
119
|
-
if
|
|
132
|
+
// Check if transaction fits with buffer for Jito tip instruction
|
|
133
|
+
if (
|
|
134
|
+
!fitsInOneTransactionWithBuffer(
|
|
135
|
+
transaction,
|
|
136
|
+
this.txHandler.umi,
|
|
137
|
+
JITO_TIP_BUFFER_BYTES
|
|
138
|
+
)
|
|
139
|
+
) {
|
|
120
140
|
throw new TransactionTooLargeError(
|
|
121
|
-
`Exceeds max transaction size (${transaction.getTransactionSize(
|
|
141
|
+
`Exceeds max transaction size (${transaction.getTransactionSize(
|
|
142
|
+
this.txHandler.umi
|
|
143
|
+
)} + ~${JITO_TIP_BUFFER_BYTES} bytes for Jito tip)`
|
|
122
144
|
);
|
|
123
145
|
} else {
|
|
124
146
|
let newSet = new TransactionSet(this.txHandler, this.lookupTables, [
|
|
@@ -166,7 +188,9 @@ export class TransactionsManager<T extends TxHandler> {
|
|
|
166
188
|
}
|
|
167
189
|
}
|
|
168
190
|
consoleLog(
|
|
169
|
-
`${args.name} ${args.attemptNum} is ${args.status
|
|
191
|
+
`${args.name} ${args.attemptNum} is ${args.status
|
|
192
|
+
.toString()
|
|
193
|
+
.toLowerCase()}`
|
|
170
194
|
);
|
|
171
195
|
this.statusCallback?.([...this.statuses]);
|
|
172
196
|
}
|
|
@@ -180,7 +204,11 @@ export class TransactionsManager<T extends TxHandler> {
|
|
|
180
204
|
(x) => !lutAccounts.includes(x)
|
|
181
205
|
);
|
|
182
206
|
consoleLog(
|
|
183
|
-
`Program ${ix.programId}, data len: ${
|
|
207
|
+
`Program ${ix.programId}, data len: ${
|
|
208
|
+
ix.data.length
|
|
209
|
+
}, LUT accounts data: ${
|
|
210
|
+
ix.keys.filter((x) => lutAccounts.includes(x.pubkey)).length * 3
|
|
211
|
+
}`
|
|
184
212
|
);
|
|
185
213
|
if (accountsNotInLut.length > 0) {
|
|
186
214
|
consoleLog(`${accountsNotInLut.length} accounts not in LUT:`);
|
|
@@ -273,7 +301,7 @@ export class TransactionsManager<T extends TxHandler> {
|
|
|
273
301
|
);
|
|
274
302
|
if (
|
|
275
303
|
newItemSetNames.length === 1 &&
|
|
276
|
-
newItemSetNames[0] ===
|
|
304
|
+
newItemSetNames[0] === UPDATE_ORACLE_TX_NAME
|
|
277
305
|
) {
|
|
278
306
|
consoleLog("Skipping unnecessary oracle update");
|
|
279
307
|
this.updateStatusForSets(
|
|
@@ -570,7 +598,9 @@ export class TransactionsManager<T extends TxHandler> {
|
|
|
570
598
|
this.priorityFeeSetting
|
|
571
599
|
);
|
|
572
600
|
|
|
573
|
-
const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${
|
|
601
|
+
const errorString = `${errorDetails.errorName ?? "Unknown error"}: ${
|
|
602
|
+
errorDetails.errorInfo?.split("\n")[0] ?? "unknown"
|
|
603
|
+
}`;
|
|
574
604
|
const errorInfo =
|
|
575
605
|
errorDetails.errorName || errorDetails.errorInfo
|
|
576
606
|
? errorString
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
AddressLookupTableInput,
|
|
3
3
|
transactionBuilder,
|
|
4
4
|
TransactionBuilder,
|
|
5
|
+
Umi,
|
|
5
6
|
} from "@metaplex-foundation/umi";
|
|
6
7
|
import { TxHandler } from "../../solauto";
|
|
7
8
|
import { LookupTables } from "./lookupTables";
|
|
@@ -11,6 +12,20 @@ import { CHORES_TX_NAME } from "../../../constants";
|
|
|
11
12
|
|
|
12
13
|
const MAX_SUPPORTED_ACCOUNT_LOCKS = 64;
|
|
13
14
|
|
|
15
|
+
// Buffer for Jito tip instruction (~44 bytes) + potential new accounts in message
|
|
16
|
+
// This accounts for: System Transfer instruction data, Jito tip account (if new), etc.
|
|
17
|
+
const JITO_TIP_BUFFER_BYTES = 75;
|
|
18
|
+
|
|
19
|
+
export function fitsInOneTransactionWithBuffer(
|
|
20
|
+
tx: TransactionBuilder,
|
|
21
|
+
umi: Umi,
|
|
22
|
+
extraBuffer: number = 0
|
|
23
|
+
): boolean {
|
|
24
|
+
const MAX_TX_SIZE = 1232;
|
|
25
|
+
const size = tx.getTransactionSize(umi);
|
|
26
|
+
return size + extraBuffer <= MAX_TX_SIZE;
|
|
27
|
+
}
|
|
28
|
+
|
|
14
29
|
export class TransactionSet {
|
|
15
30
|
constructor(
|
|
16
31
|
private txHandler: TxHandler,
|
|
@@ -55,7 +70,12 @@ export class TransactionSet {
|
|
|
55
70
|
])
|
|
56
71
|
);
|
|
57
72
|
|
|
58
|
-
|
|
73
|
+
// Account for Jito tip instruction that will be added later
|
|
74
|
+
return fitsInOneTransactionWithBuffer(
|
|
75
|
+
tx,
|
|
76
|
+
this.txHandler.umi,
|
|
77
|
+
JITO_TIP_BUFFER_BYTES
|
|
78
|
+
);
|
|
59
79
|
}
|
|
60
80
|
|
|
61
81
|
add(...items: TransactionItem[]) {
|
|
@@ -38,7 +38,7 @@ export function createSolautoSettings(
|
|
|
38
38
|
boostToBps: settings.boostToBps,
|
|
39
39
|
repayGap: settings.repayGap,
|
|
40
40
|
repayToBps: settings.repayToBps,
|
|
41
|
-
padding:
|
|
41
|
+
padding: new Array(24).fill(0),
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -167,9 +167,9 @@ export function createFakePositionState(
|
|
|
167
167
|
borrowFeeBps: 0,
|
|
168
168
|
decimals: supplyDecimals,
|
|
169
169
|
mint: fromWeb3JsPublicKey(supply.mint),
|
|
170
|
-
padding1:
|
|
171
|
-
padding2:
|
|
172
|
-
padding: new Uint8Array(
|
|
170
|
+
padding1: new Array(5).fill(0),
|
|
171
|
+
padding2: new Array(8).fill(0),
|
|
172
|
+
padding: new Uint8Array(32),
|
|
173
173
|
},
|
|
174
174
|
debt: {
|
|
175
175
|
amountUsed: {
|
|
@@ -186,9 +186,9 @@ export function createFakePositionState(
|
|
|
186
186
|
borrowFeeBps: 0,
|
|
187
187
|
decimals: debtDecimals,
|
|
188
188
|
mint: fromWeb3JsPublicKey(debt.mint),
|
|
189
|
-
padding1:
|
|
190
|
-
padding2:
|
|
191
|
-
padding: new Uint8Array(
|
|
189
|
+
padding1: new Array(5).fill(0),
|
|
190
|
+
padding2: new Array(8).fill(0),
|
|
191
|
+
padding: new Uint8Array(32),
|
|
192
192
|
},
|
|
193
193
|
netWorth: {
|
|
194
194
|
baseUnit: supply.price
|
|
@@ -199,8 +199,8 @@ export function createFakePositionState(
|
|
|
199
199
|
maxLtvBps,
|
|
200
200
|
liqThresholdBps,
|
|
201
201
|
lastRefreshed: BigInt(currentUnixSeconds()),
|
|
202
|
-
padding1:
|
|
203
|
-
padding2:
|
|
204
|
-
padding:
|
|
202
|
+
padding1: new Array(6).fill(0),
|
|
203
|
+
padding2: new Array(4).fill(0),
|
|
204
|
+
padding: new Array(2).fill(0),
|
|
205
205
|
};
|
|
206
206
|
}
|
package/src/utils/jitoUtils.ts
CHANGED
|
@@ -82,8 +82,8 @@ async function simulateJitoBundle(umi: Umi, txs: VersionedTransaction[]) {
|
|
|
82
82
|
{
|
|
83
83
|
encoding: "base64",
|
|
84
84
|
commitment: "confirmed",
|
|
85
|
-
preExecutionAccountsConfigs: txs.map((_) => {}),
|
|
86
|
-
postExecutionAccountsConfigs: txs.map((_) => {}),
|
|
85
|
+
preExecutionAccountsConfigs: txs.map((_) => { }),
|
|
86
|
+
postExecutionAccountsConfigs: txs.map((_) => { }),
|
|
87
87
|
skipSigVerify: true,
|
|
88
88
|
},
|
|
89
89
|
]);
|
|
@@ -298,12 +298,17 @@ export async function sendJitoBundledTransactions(
|
|
|
298
298
|
txs.map((tx) => tx.getInstructions().map((x) => x.programId.toString()))
|
|
299
299
|
);
|
|
300
300
|
consoleLog(
|
|
301
|
-
"Transaction sizes: ",
|
|
301
|
+
"Transaction sizes (before tip): ",
|
|
302
302
|
txs.map((x) => x.getTransactionSize(umi))
|
|
303
303
|
);
|
|
304
304
|
|
|
305
305
|
txs[0] = prependTx(txs[0], [getTipInstruction(userSigner, 250_000)]);
|
|
306
306
|
|
|
307
|
+
consoleLog(
|
|
308
|
+
"Transaction sizes (after tip): ",
|
|
309
|
+
txs.map((x) => x.getTransactionSize(umi))
|
|
310
|
+
);
|
|
311
|
+
|
|
307
312
|
const latestBlockhash = (
|
|
308
313
|
await retryWithExponentialBackoff(
|
|
309
314
|
async () => await umi.rpc.getLatestBlockhash({ commitment: "confirmed" })
|
|
@@ -334,16 +339,16 @@ export async function sendJitoBundledTransactions(
|
|
|
334
339
|
|
|
335
340
|
const feeEstimates = usePriorityFee(priorityFeeSetting)
|
|
336
341
|
? await Promise.all(
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
)
|
|
342
|
+
txs.map(
|
|
343
|
+
async (x) =>
|
|
344
|
+
(await getComputeUnitPriceEstimate(
|
|
345
|
+
umi,
|
|
346
|
+
x,
|
|
347
|
+
priorityFeeSetting,
|
|
348
|
+
true
|
|
349
|
+
)) ?? 1000000
|
|
346
350
|
)
|
|
351
|
+
)
|
|
347
352
|
: undefined;
|
|
348
353
|
|
|
349
354
|
if (abortController?.signal.aborted) {
|
|
@@ -288,9 +288,9 @@ async function getTokenUsage(
|
|
|
288
288
|
},
|
|
289
289
|
baseAmountMarketPriceUsd: toBaseUnit(marketPrice, USD_DECIMALS),
|
|
290
290
|
borrowFeeBps: isAsset ? 0 : toBps(originationFee),
|
|
291
|
-
padding1:
|
|
292
|
-
padding2:
|
|
293
|
-
padding: new Uint8Array(
|
|
291
|
+
padding1: new Array(5).fill(0),
|
|
292
|
+
padding2: new Array(8).fill(0),
|
|
293
|
+
padding: new Uint8Array(32),
|
|
294
294
|
};
|
|
295
295
|
}
|
|
296
296
|
|
|
@@ -513,9 +513,9 @@ export async function getMarginfiAccountPositionState(
|
|
|
513
513
|
maxLtvBps,
|
|
514
514
|
liqThresholdBps,
|
|
515
515
|
lastRefreshed: BigInt(currentUnixSeconds()),
|
|
516
|
-
padding1:
|
|
517
|
-
padding2:
|
|
518
|
-
padding:
|
|
516
|
+
padding1: new Array(6).fill(0),
|
|
517
|
+
padding2: new Array(4).fill(0),
|
|
518
|
+
padding: new Array(2).fill(0),
|
|
519
519
|
},
|
|
520
520
|
};
|
|
521
521
|
}
|
|
@@ -403,12 +403,12 @@ export class ContextUpdates {
|
|
|
403
403
|
...dca.automation,
|
|
404
404
|
intervalSeconds: BigInt(dca.automation.intervalSeconds),
|
|
405
405
|
unixStartDate: BigInt(dca.automation.unixStartDate),
|
|
406
|
-
padding: new Uint8Array(
|
|
407
|
-
padding1:
|
|
406
|
+
padding: new Uint8Array(32),
|
|
407
|
+
padding1: new Array(4).fill(0),
|
|
408
408
|
},
|
|
409
409
|
dcaInBaseUnit: BigInt(dca.dcaInBaseUnit),
|
|
410
410
|
tokenType: dca.tokenType,
|
|
411
|
-
padding:
|
|
411
|
+
padding: new Array(31).fill(0),
|
|
412
412
|
};
|
|
413
413
|
} else if (update.type === "cancellingDca") {
|
|
414
414
|
this.cancellingDca = update.value;
|
|
@@ -9,7 +9,11 @@ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
|
|
9
9
|
import { AnchorProvider, Idl, Program } from "@coral-xyz/anchor";
|
|
10
10
|
import * as OnDemand from "@switchboard-xyz/on-demand";
|
|
11
11
|
import Big from "big.js";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
PRICES,
|
|
14
|
+
SWITCHBOARD_PRICE_FEED_IDS,
|
|
15
|
+
UPDATE_ORACLE_TX_NAME,
|
|
16
|
+
} from "../constants";
|
|
13
17
|
import { TransactionItemInputs } from "../types";
|
|
14
18
|
import {
|
|
15
19
|
consoleLog,
|
|
@@ -18,6 +22,7 @@ import {
|
|
|
18
22
|
} from "./generalUtils";
|
|
19
23
|
import { getWrappedInstruction } from "./solanaUtils";
|
|
20
24
|
import { CrossbarClient } from "@switchboard-xyz/common";
|
|
25
|
+
import { SolautoClient, TransactionItem } from "../services";
|
|
21
26
|
|
|
22
27
|
export async function getPullFeed(
|
|
23
28
|
conn: Connection,
|
|
@@ -69,8 +74,6 @@ export async function buildSwbSubmitResponseTx(
|
|
|
69
74
|
toWeb3JsPublicKey(signer.publicKey)
|
|
70
75
|
);
|
|
71
76
|
|
|
72
|
-
// Try to replicate locally in the lambda docker container
|
|
73
|
-
|
|
74
77
|
consoleLog("Fetching crank IX...");
|
|
75
78
|
const [pullIxs, responses] = await retryWithExponentialBackoff(
|
|
76
79
|
async () => {
|
|
@@ -146,3 +149,41 @@ export async function getSwitchboardFeedData(
|
|
|
146
149
|
export function isSwitchboardMint(mint: PublicKey | string) {
|
|
147
150
|
return Object.keys(SWITCHBOARD_PRICE_FEED_IDS).includes(mint.toString());
|
|
148
151
|
}
|
|
152
|
+
|
|
153
|
+
export async function addSwbOraclePullTxs(
|
|
154
|
+
client: SolautoClient,
|
|
155
|
+
txs: TransactionItem[]
|
|
156
|
+
) {
|
|
157
|
+
const switchboardMints = [
|
|
158
|
+
...(isSwitchboardMint(client.pos.supplyMint)
|
|
159
|
+
? [client.pos.supplyMint]
|
|
160
|
+
: []),
|
|
161
|
+
...(isSwitchboardMint(client.pos.debtMint) ? [client.pos.debtMint] : []),
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
if (txs.find((x) => x.oracleInteractor) && switchboardMints.length) {
|
|
165
|
+
consoleLog("Checking if oracle update(s) needed...");
|
|
166
|
+
const staleOracles =
|
|
167
|
+
(
|
|
168
|
+
await getSwitchboardFeedData(client.connection, switchboardMints)
|
|
169
|
+
).filter((x) => x.stale).length > 0;
|
|
170
|
+
|
|
171
|
+
if (staleOracles) {
|
|
172
|
+
consoleLog("Requires oracle update(s)...");
|
|
173
|
+
const oracleTxs = switchboardMints.map(
|
|
174
|
+
(x) =>
|
|
175
|
+
new TransactionItem(
|
|
176
|
+
async () =>
|
|
177
|
+
await buildSwbSubmitResponseTx(
|
|
178
|
+
client.connection,
|
|
179
|
+
client.signer,
|
|
180
|
+
x
|
|
181
|
+
),
|
|
182
|
+
UPDATE_ORACLE_TX_NAME
|
|
183
|
+
)
|
|
184
|
+
);
|
|
185
|
+
consoleLog("Set crank IXs in TX");
|
|
186
|
+
txs.unshift(...oracleTxs);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|