@haven-fi/solauto-sdk 1.0.685 → 1.0.686
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/README.md +8 -6
- 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/services/transactions/index.d.ts +3 -2
- package/dist/services/transactions/index.d.ts.map +1 -1
- package/dist/services/transactions/index.js +2 -1
- package/dist/services/transactions/manager/clientTransactionsManager.d.ts +10 -0
- package/dist/services/transactions/manager/clientTransactionsManager.d.ts.map +1 -0
- package/dist/services/transactions/manager/clientTransactionsManager.js +75 -0
- package/dist/services/transactions/manager/index.d.ts +3 -0
- package/dist/services/transactions/manager/index.d.ts.map +1 -0
- package/dist/services/transactions/manager/index.js +18 -0
- package/dist/services/transactions/manager/transactionsManager.d.ts +64 -0
- package/dist/services/transactions/manager/transactionsManager.d.ts.map +1 -0
- package/dist/services/transactions/{transactionsManager.js → manager/transactionsManager.js} +21 -211
- package/dist/services/transactions/types/index.d.ts +4 -0
- package/dist/services/transactions/types/index.d.ts.map +1 -0
- package/dist/services/transactions/types/index.js +19 -0
- package/dist/services/transactions/types/lookupTables.d.ts +10 -0
- package/dist/services/transactions/types/lookupTables.d.ts.map +1 -0
- package/dist/services/transactions/types/lookupTables.js +25 -0
- package/dist/services/transactions/types/transactionItem.d.ts +16 -0
- package/dist/services/transactions/types/transactionItem.d.ts.map +1 -0
- package/dist/services/transactions/types/transactionItem.js +31 -0
- package/dist/services/transactions/types/transactionSet.d.ts +20 -0
- package/dist/services/transactions/types/transactionSet.d.ts.map +1 -0
- package/dist/services/transactions/types/transactionSet.js +79 -0
- package/dist/utils/instructionUtils.d.ts.map +1 -1
- package/dist/utils/instructionUtils.js +3 -3
- package/dist/utils/switchboardUtils.d.ts +1 -0
- package/dist/utils/switchboardUtils.d.ts.map +1 -1
- package/dist/utils/switchboardUtils.js +10 -0
- package/local/txSandbox.ts +17 -23
- package/package.json +3 -1
- package/src/constants/solautoConstants.ts +2 -0
- package/src/services/transactions/index.ts +3 -2
- package/src/services/transactions/manager/clientTransactionsManager.ts +141 -0
- package/src/services/transactions/manager/index.ts +2 -0
- package/src/services/transactions/{transactionsManager.ts → manager/transactionsManager.ts} +46 -354
- package/src/services/transactions/types/index.ts +3 -0
- package/src/services/transactions/types/lookupTables.ts +37 -0
- package/src/services/transactions/types/transactionItem.ts +43 -0
- package/src/services/transactions/types/transactionSet.ts +114 -0
- package/src/utils/instructionUtils.ts +6 -3
- package/src/utils/switchboardUtils.ts +17 -2
- package/tests/transactions/shared.ts +6 -3
- package/dist/services/transactions/transactionsManager.d.ts +0 -68
- package/dist/services/transactions/transactionsManager.d.ts.map +0 -1
package/README.md
CHANGED
@@ -66,9 +66,10 @@ const transactionItems = [
|
|
66
66
|
];
|
67
67
|
|
68
68
|
// Send all transactions atomically
|
69
|
-
const
|
70
|
-
|
71
|
-
);
|
69
|
+
const txManager = await new solauto.ClientTransactionsManager({
|
70
|
+
txHandler: client,
|
71
|
+
});
|
72
|
+
const statuses = txManager.send(transactionItems);
|
72
73
|
```
|
73
74
|
|
74
75
|
## Rebalancing an existing position
|
@@ -95,7 +96,8 @@ const transactionItems = [
|
|
95
96
|
),
|
96
97
|
];
|
97
98
|
|
98
|
-
const
|
99
|
-
|
100
|
-
);
|
99
|
+
const txManager = await new solauto.ClientTransactionsManager({
|
100
|
+
txHandler: client,
|
101
|
+
});
|
102
|
+
const statuses = txManager.send(transactionItems);
|
101
103
|
```
|
@@ -13,6 +13,7 @@ export declare const PRICES: {
|
|
13
13
|
time: number;
|
14
14
|
};
|
15
15
|
};
|
16
|
+
export declare const CHORES_TX_NAME = "account chores";
|
16
17
|
export declare const JITO_TIP_ACCOUNTS: string[];
|
17
18
|
export declare const SOLAUTO_LUT = "8b7KefQDroVLGao71J5H3hFwABeyMCgCrLpXWssNFhk9";
|
18
19
|
export declare const STANDARD_LUT_ACCOUNTS: string[];
|
@@ -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,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO,CAAC;AAEvG,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,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAO,CAAC;AAEvG,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,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.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.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");
|
@@ -14,6 +14,7 @@ exports.MIN_USD_SUPPORTED_POSITION = 1000;
|
|
14
14
|
exports.OFFSET_FROM_MAX_LTV = 0.005;
|
15
15
|
exports.REFERRER_PERCENTAGE = 0.15;
|
16
16
|
exports.PRICES = {};
|
17
|
+
exports.CHORES_TX_NAME = "account chores";
|
17
18
|
exports.JITO_TIP_ACCOUNTS = [
|
18
19
|
"96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5",
|
19
20
|
"HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe",
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/transactions/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC"}
|
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./
|
17
|
+
__exportStar(require("./manager"), exports);
|
18
|
+
__exportStar(require("./types"), exports);
|
18
19
|
__exportStar(require("./transactionUtils"), exports);
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { SolautoClient } from "../../solauto";
|
2
|
+
import { TransactionsManager } from "./transactionsManager";
|
3
|
+
import { TransactionItem } from "../types";
|
4
|
+
export declare class ClientTransactionsManager extends TransactionsManager<SolautoClient> {
|
5
|
+
private updateLut;
|
6
|
+
private addSwbOraclePullTxs;
|
7
|
+
private addChoreTxs;
|
8
|
+
send(transactions: TransactionItem[]): Promise<import("./transactionsManager").TransactionManagerStatuses>;
|
9
|
+
}
|
10
|
+
//# sourceMappingURL=clientTransactionsManager.d.ts.map
|
@@ -0,0 +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;AAM5D,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAI3C,qBAAa,yBAA0B,SAAQ,mBAAmB,CAAC,aAAa,CAAC;YACjE,SAAS;YAmBT,mBAAmB;YA4BnB,WAAW;IA4CZ,IAAI,CAAC,YAAY,EAAE,eAAe,EAAE;CAiClD"}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ClientTransactionsManager = void 0;
|
4
|
+
const umi_1 = require("@metaplex-foundation/umi");
|
5
|
+
const transactionsManager_1 = require("./transactionsManager");
|
6
|
+
const utils_1 = require("../../../utils");
|
7
|
+
const types_1 = require("../types");
|
8
|
+
const transactionUtils_1 = require("../transactionUtils");
|
9
|
+
const constants_1 = require("../../../constants");
|
10
|
+
class ClientTransactionsManager extends transactionsManager_1.TransactionsManager {
|
11
|
+
async updateLut(tx, newLut) {
|
12
|
+
const lutInputs = await this.lookupTables.getLutInputs();
|
13
|
+
const updateLutTxName = `${newLut ? "create" : "update"} lookup table`;
|
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
|
+
await this.txHandler.refetchReferralState();
|
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("Requires oracle update(s)...");
|
28
|
+
const txs = switchboardMints.map((x) => new types_1.TransactionItem(async () => (0, utils_1.buildSwbSubmitResponseTx)(this.txHandler.connection, this.txHandler.signer, x), this.updateOracleTxName));
|
29
|
+
txs.unshift(...txs);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
async addChoreTxs(txs, updateLutTx) {
|
33
|
+
let [choresBefore, choresAfter] = await (0, transactionUtils_1.getTransactionChores)(this.txHandler, (0, umi_1.transactionBuilder)().add(txs
|
34
|
+
.filter((x) => x.tx && x.tx.getInstructions().length > 0)
|
35
|
+
.map((x) => x.tx)));
|
36
|
+
if (updateLutTx) {
|
37
|
+
choresBefore.prepend(updateLutTx);
|
38
|
+
}
|
39
|
+
if (choresBefore.getInstructions().length) {
|
40
|
+
const chore = new types_1.TransactionItem(async () => ({ tx: choresBefore }), constants_1.CHORES_TX_NAME);
|
41
|
+
await chore.initialize();
|
42
|
+
txs.unshift(chore);
|
43
|
+
this.txHandler.log("Chores before: ", choresBefore.getInstructions().length);
|
44
|
+
}
|
45
|
+
if (choresAfter.getInstructions().length) {
|
46
|
+
const chore = new types_1.TransactionItem(async () => ({ tx: choresAfter }), constants_1.CHORES_TX_NAME);
|
47
|
+
await chore.initialize();
|
48
|
+
txs.push(chore);
|
49
|
+
this.txHandler.log("Chores after: ", choresAfter.getInstructions().length);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
async send(transactions) {
|
53
|
+
const items = [...transactions];
|
54
|
+
const client = this.txHandler;
|
55
|
+
const updateLut = await client.updateLookupTable();
|
56
|
+
if (updateLut && (updateLut?.new || updateLut.accountsToAdd.length > 4)) {
|
57
|
+
await this.updateLut(updateLut.tx, updateLut.new);
|
58
|
+
}
|
59
|
+
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
60
|
+
await this.addSwbOraclePullTxs(items);
|
61
|
+
for (const item of items) {
|
62
|
+
await item.initialize();
|
63
|
+
}
|
64
|
+
await this.addChoreTxs(items, updateLut && !updateLut?.new ? updateLut.tx : undefined);
|
65
|
+
const result = await super.send(items).catch((e) => {
|
66
|
+
client.resetLiveTxUpdates(false);
|
67
|
+
throw e;
|
68
|
+
});
|
69
|
+
if (this.txRunType !== "only-simulate") {
|
70
|
+
await client.resetLiveTxUpdates();
|
71
|
+
}
|
72
|
+
return result;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
exports.ClientTransactionsManager = ClientTransactionsManager;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/manager/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./transactionsManager"), exports);
|
18
|
+
__exportStar(require("./clientTransactionsManager"), exports);
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import { TransactionBuilder } from "@metaplex-foundation/umi";
|
2
|
+
import { PriorityFeeSetting, TransactionRunType } from "../../../types";
|
3
|
+
import { ErrorsToThrow } from "../../../utils";
|
4
|
+
import { TxHandler } from "../../solauto";
|
5
|
+
import { LookupTables, TransactionItem } from "../types";
|
6
|
+
export declare class TransactionTooLargeError extends Error {
|
7
|
+
constructor(message: string);
|
8
|
+
}
|
9
|
+
export declare enum TransactionStatus {
|
10
|
+
Skipped = "Skipped",
|
11
|
+
Processing = "Processing",
|
12
|
+
Queued = "Queued",
|
13
|
+
Successful = "Successful",
|
14
|
+
Failed = "Failed"
|
15
|
+
}
|
16
|
+
export type TransactionManagerStatuses = {
|
17
|
+
name: string;
|
18
|
+
attemptNum: number;
|
19
|
+
status: TransactionStatus;
|
20
|
+
moreInfo?: string;
|
21
|
+
simulationSuccessful?: boolean;
|
22
|
+
txSig?: string;
|
23
|
+
}[];
|
24
|
+
interface RetryConfig {
|
25
|
+
signableRetries?: number;
|
26
|
+
totalRetries?: number;
|
27
|
+
retryDelay?: number;
|
28
|
+
}
|
29
|
+
export interface TransactionManagerArgs<T extends TxHandler> {
|
30
|
+
txHandler: T;
|
31
|
+
statusCallback?: (statuses: TransactionManagerStatuses) => void;
|
32
|
+
txRunType?: TransactionRunType;
|
33
|
+
priorityFeeSetting?: PriorityFeeSetting;
|
34
|
+
atomically?: boolean;
|
35
|
+
errorsToThrow?: ErrorsToThrow;
|
36
|
+
retryConfig?: RetryConfig;
|
37
|
+
}
|
38
|
+
export declare class TransactionsManager<T extends TxHandler> {
|
39
|
+
protected txHandler: T;
|
40
|
+
protected statusCallback?: (statuses: TransactionManagerStatuses) => void;
|
41
|
+
protected txRunType?: TransactionRunType;
|
42
|
+
protected priorityFeeSetting: PriorityFeeSetting;
|
43
|
+
protected atomically: boolean;
|
44
|
+
protected errorsToThrow?: ErrorsToThrow;
|
45
|
+
protected statuses: TransactionManagerStatuses;
|
46
|
+
protected lookupTables: LookupTables;
|
47
|
+
protected signableRetries: number;
|
48
|
+
protected totalRetries: number;
|
49
|
+
protected retryDelay: number;
|
50
|
+
updateOracleTxName: string;
|
51
|
+
constructor(args: TransactionManagerArgs<T>);
|
52
|
+
private assembleTransactionSets;
|
53
|
+
private updateStatus;
|
54
|
+
private debugAccounts;
|
55
|
+
protected getUpdatedPriorityFeeSetting(prevError: Error | undefined, attemptNum: number): PriorityFeeSetting;
|
56
|
+
private updateStatusForSets;
|
57
|
+
send(items: TransactionItem[]): Promise<TransactionManagerStatuses>;
|
58
|
+
private processTransactionsAtomically;
|
59
|
+
private processTransactionSet;
|
60
|
+
private refreshItemSets;
|
61
|
+
protected sendTransaction(tx: TransactionBuilder, txName: string, attemptNum: number, priorityFeeSetting?: PriorityFeeSetting, txRunType?: TransactionRunType): Promise<void>;
|
62
|
+
}
|
63
|
+
export {};
|
64
|
+
//# sourceMappingURL=transactionsManager.d.ts.map
|
@@ -0,0 +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,EAAE,YAAY,EAAE,eAAe,EAAkB,MAAM,UAAU,CAAC;AAEzE,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAK5B;AAED,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,UAAU,eAAe;IACzB,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,EAAE,CAAC;AAEJ,UAAU,WAAW;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,sBAAsB,CAAC,CAAC,SAAS,SAAS;IACzD,SAAS,EAAE,CAAC,CAAC;IACb,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,0BAA0B,KAAK,IAAI,CAAC;IAChE,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,qBAAa,mBAAmB,CAAC,CAAC,SAAS,SAAS;IAClD,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC;IACvB,SAAS,CAAC,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,0BAA0B,KAAK,IAAI,CAAC;IAC1E,SAAS,CAAC,SAAS,CAAC,EAAE,kBAAkB,CAAC;IACzC,SAAS,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IACjD,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC;IAC9B,SAAS,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;IACxC,SAAS,CAAC,QAAQ,EAAE,0BAA0B,CAAM;IACpD,SAAS,CAAC,YAAY,EAAE,YAAY,CAAC;IACrC,SAAS,CAAC,eAAe,EAAE,MAAM,CAAC;IAClC,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAC/B,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAE7B,kBAAkB,SAAmB;gBAEzB,IAAI,EAAE,sBAAsB,CAAC,CAAC,CAAC;YAmB7B,uBAAuB;IA0CrC,OAAO,CAAC,YAAY;YA6CN,aAAa;IAoB3B,SAAS,CAAC,4BAA4B,CACpC,SAAS,EAAE,KAAK,GAAG,SAAS,EAC5B,UAAU,EAAE,MAAM;IAcpB,OAAO,CAAC,mBAAmB;IAoBd,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,GACvB,OAAO,CAAC,0BAA0B,CAAC;YA8BxB,6BAA6B;YA8I7B,qBAAqB;YAiDrB,eAAe;cA2Db,eAAe,CAC7B,EAAE,EAAE,kBAAkB,EACtB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,kBAAkB,CAAC,EAAE,kBAAkB,EACvC,SAAS,CAAC,EAAE,kBAAkB;CAwDjC"}
|
package/dist/services/transactions/{transactionsManager.js → manager/transactionsManager.js}
RENAMED
@@ -3,16 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.TransactionsManager = exports.TransactionStatus = exports.
|
6
|
+
exports.TransactionsManager = exports.TransactionStatus = exports.TransactionTooLargeError = void 0;
|
7
7
|
const bs58_1 = __importDefault(require("bs58"));
|
8
8
|
const web3_js_1 = require("@solana/web3.js");
|
9
|
-
const
|
10
|
-
const
|
11
|
-
const
|
12
|
-
const
|
13
|
-
const transactionUtils_1 = require("./transactionUtils");
|
14
|
-
const CHORES_TX_NAME = "account chores";
|
15
|
-
const MAX_SUPPORTED_ACCOUNT_LOCKS = 64;
|
9
|
+
const types_1 = require("../../../types");
|
10
|
+
const utils_1 = require("../../../utils");
|
11
|
+
const transactionUtils_1 = require("../transactionUtils");
|
12
|
+
const types_2 = require("../types");
|
16
13
|
class TransactionTooLargeError extends Error {
|
17
14
|
constructor(message) {
|
18
15
|
super(message);
|
@@ -21,124 +18,6 @@ class TransactionTooLargeError extends Error {
|
|
21
18
|
}
|
22
19
|
}
|
23
20
|
exports.TransactionTooLargeError = TransactionTooLargeError;
|
24
|
-
class LookupTables {
|
25
|
-
constructor(defaultLuts, umi) {
|
26
|
-
this.defaultLuts = defaultLuts;
|
27
|
-
this.umi = umi;
|
28
|
-
this.cache = [];
|
29
|
-
}
|
30
|
-
async getLutInputs(additionalAddresses) {
|
31
|
-
const addresses = [...this.defaultLuts, ...(additionalAddresses ?? [])];
|
32
|
-
const currentCacheAddresses = this.cache.map((x) => x.publicKey.toString());
|
33
|
-
const missingAddresses = addresses.filter((x) => !currentCacheAddresses.includes(x));
|
34
|
-
if (missingAddresses) {
|
35
|
-
const additionalInputs = await (0, utils_1.getAddressLookupInputs)(this.umi, missingAddresses);
|
36
|
-
this.cache.push(...additionalInputs);
|
37
|
-
}
|
38
|
-
return this.cache;
|
39
|
-
}
|
40
|
-
reset() {
|
41
|
-
this.cache = this.cache.filter((x) => this.defaultLuts.includes(x.publicKey.toString()));
|
42
|
-
}
|
43
|
-
}
|
44
|
-
class TransactionItem {
|
45
|
-
constructor(fetchTx, name) {
|
46
|
-
this.fetchTx = fetchTx;
|
47
|
-
this.name = name;
|
48
|
-
this.initialized = false;
|
49
|
-
this.orderPrio = 0;
|
50
|
-
}
|
51
|
-
async initialize() {
|
52
|
-
await this.refetch(0);
|
53
|
-
this.initialized = true;
|
54
|
-
}
|
55
|
-
async refetch(attemptNum, prevError) {
|
56
|
-
const resp = await this.fetchTx(attemptNum, prevError);
|
57
|
-
this.tx = resp?.tx;
|
58
|
-
this.lookupTableAddresses = resp?.lookupTableAddresses ?? [];
|
59
|
-
this.orderPrio = resp?.orderPrio ?? 0;
|
60
|
-
}
|
61
|
-
uniqueAccounts() {
|
62
|
-
return Array.from(new Set(this.tx.getInstructions()
|
63
|
-
.map((x) => [
|
64
|
-
x.programId.toString(),
|
65
|
-
...x.keys.map((y) => y.pubkey.toString()),
|
66
|
-
])
|
67
|
-
.flat()));
|
68
|
-
}
|
69
|
-
}
|
70
|
-
exports.TransactionItem = TransactionItem;
|
71
|
-
class TransactionSet {
|
72
|
-
constructor(txHandler, lookupTables, items = []) {
|
73
|
-
this.txHandler = txHandler;
|
74
|
-
this.lookupTables = lookupTables;
|
75
|
-
this.items = items;
|
76
|
-
}
|
77
|
-
async lutInputs() {
|
78
|
-
const lutInputs = await this.lookupTables.getLutInputs(this.lutAddresses());
|
79
|
-
return lutInputs.filter((lut, index, self) => index ===
|
80
|
-
self.findIndex((item) => item.publicKey.toString() === lut.publicKey.toString()));
|
81
|
-
}
|
82
|
-
async fitsWith(item) {
|
83
|
-
if (!item.tx) {
|
84
|
-
return true;
|
85
|
-
}
|
86
|
-
const accountLocks = Array.from(new Set([
|
87
|
-
...this.items.map((x) => x.uniqueAccounts()),
|
88
|
-
...item.uniqueAccounts(),
|
89
|
-
])).length;
|
90
|
-
if (accountLocks > MAX_SUPPORTED_ACCOUNT_LOCKS) {
|
91
|
-
return false;
|
92
|
-
}
|
93
|
-
const singleTx = await this.getSingleTransaction();
|
94
|
-
const tx = (0, utils_1.addTxOptimizations)(this.txHandler.umi, singleTx, 1, 1)
|
95
|
-
.add(item.tx)
|
96
|
-
.setAddressLookupTables(await this.lookupTables.getLutInputs([
|
97
|
-
...this.lutAddresses(),
|
98
|
-
...item.lookupTableAddresses,
|
99
|
-
]));
|
100
|
-
return tx.fitsInOneTransaction(this.txHandler.umi);
|
101
|
-
}
|
102
|
-
add(...items) {
|
103
|
-
this.items.push(...items.filter((x) => x.tx && x.tx.getInstructions().length > 0));
|
104
|
-
}
|
105
|
-
prepend(...items) {
|
106
|
-
this.items.unshift(...items.filter((x) => x.tx && x.tx.getInstructions().length > 0));
|
107
|
-
}
|
108
|
-
async reset() {
|
109
|
-
await this.txHandler.resetLiveTxUpdates();
|
110
|
-
}
|
111
|
-
async refetchAll(attemptNum, prevError) {
|
112
|
-
for (const item of this.items) {
|
113
|
-
await item.refetch(attemptNum, prevError);
|
114
|
-
}
|
115
|
-
}
|
116
|
-
async getSingleTransaction() {
|
117
|
-
const transactions = this.items
|
118
|
-
.filter((x) => x.tx && x.tx.getInstructions().length > 0)
|
119
|
-
.map((x) => x.tx);
|
120
|
-
return (0, umi_1.transactionBuilder)()
|
121
|
-
.add(transactions)
|
122
|
-
.setAddressLookupTables(await this.lutInputs());
|
123
|
-
}
|
124
|
-
lutAddresses() {
|
125
|
-
return Array.from(new Set(this.items.map((x) => x.lookupTableAddresses).flat()));
|
126
|
-
}
|
127
|
-
name() {
|
128
|
-
let names = this.items
|
129
|
-
.filter((x) => x.tx && Boolean(x.name))
|
130
|
-
.map((x) => x.name.toLowerCase());
|
131
|
-
if (names.length > 1) {
|
132
|
-
names = names.filter((x) => x !== CHORES_TX_NAME);
|
133
|
-
}
|
134
|
-
if (names.length >= 3) {
|
135
|
-
return [names.slice(0, -1).join(", "), names[names.length - 1]].join(", and ");
|
136
|
-
}
|
137
|
-
else {
|
138
|
-
return names.join(" & ");
|
139
|
-
}
|
140
|
-
}
|
141
|
-
}
|
142
21
|
var TransactionStatus;
|
143
22
|
(function (TransactionStatus) {
|
144
23
|
TransactionStatus["Skipped"] = "Skipped";
|
@@ -148,21 +27,21 @@ var TransactionStatus;
|
|
148
27
|
TransactionStatus["Failed"] = "Failed";
|
149
28
|
})(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
|
150
29
|
class TransactionsManager {
|
151
|
-
constructor(
|
152
|
-
this.txHandler = txHandler;
|
153
|
-
this.statusCallback = statusCallback;
|
154
|
-
this.txType = txType;
|
155
|
-
this.priorityFeeSetting = priorityFeeSetting;
|
156
|
-
this.atomically = atomically;
|
157
|
-
this.errorsToThrow = errorsToThrow;
|
30
|
+
constructor(args) {
|
158
31
|
this.statuses = [];
|
159
32
|
this.updateOracleTxName = "update oracle";
|
160
|
-
this.
|
33
|
+
this.txHandler = args.txHandler;
|
34
|
+
this.statusCallback = args.statusCallback;
|
35
|
+
this.txRunType = args.txRunType;
|
36
|
+
this.priorityFeeSetting = args.priorityFeeSetting ?? types_1.PriorityFeeSetting.Min;
|
37
|
+
this.atomically = args.atomically ?? true;
|
38
|
+
this.errorsToThrow = args.errorsToThrow;
|
39
|
+
this.lookupTables = new types_2.LookupTables(this.txHandler.defaultLookupTables(), this.txHandler.umi);
|
161
40
|
this.signableRetries =
|
162
|
-
retryConfig?.signableRetries ?? retryConfig?.totalRetries ?? 4;
|
41
|
+
args.retryConfig?.signableRetries ?? args.retryConfig?.totalRetries ?? 4;
|
163
42
|
this.totalRetries =
|
164
|
-
retryConfig?.totalRetries ?? retryConfig?.signableRetries ?? 4;
|
165
|
-
this.retryDelay = retryConfig?.retryDelay ?? 150;
|
43
|
+
args.retryConfig?.totalRetries ?? args.retryConfig?.signableRetries ?? 4;
|
44
|
+
this.retryDelay = args.retryConfig?.retryDelay ?? 150;
|
166
45
|
}
|
167
46
|
async assembleTransactionSets(items) {
|
168
47
|
let transactionSets = [];
|
@@ -179,7 +58,7 @@ class TransactionsManager {
|
|
179
58
|
throw new TransactionTooLargeError(`Exceeds max transaction size (${transaction.getTransactionSize(this.txHandler.umi)})`);
|
180
59
|
}
|
181
60
|
else {
|
182
|
-
let newSet = new TransactionSet(this.txHandler, this.lookupTables, [
|
61
|
+
let newSet = new types_2.TransactionSet(this.txHandler, this.lookupTables, [
|
183
62
|
item,
|
184
63
|
]);
|
185
64
|
for (let j = i; j >= 0; j--) {
|
@@ -260,75 +139,6 @@ class TransactionsManager {
|
|
260
139
|
this.updateStatus(itemSet.name(), status, attemptNum, txSigs !== undefined ? txSigs[i] : undefined, simulationSuccessful, moreInfo);
|
261
140
|
});
|
262
141
|
}
|
263
|
-
async updateLut(tx, newLut) {
|
264
|
-
const lutInputs = await this.lookupTables.getLutInputs();
|
265
|
-
const updateLutTxName = `${newLut ? "create" : "update"} lookup table`;
|
266
|
-
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);
|
267
|
-
await this.txHandler.refetchReferralState();
|
268
|
-
}
|
269
|
-
async clientSend(transactions) {
|
270
|
-
const items = [...transactions];
|
271
|
-
const client = this.txHandler;
|
272
|
-
const updateLut = await client.updateLookupTable();
|
273
|
-
if (updateLut && (updateLut?.new || updateLut.accountsToAdd.length > 4)) {
|
274
|
-
await this.updateLut(updateLut.tx, updateLut.new);
|
275
|
-
}
|
276
|
-
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
277
|
-
for (const item of items) {
|
278
|
-
await item.initialize();
|
279
|
-
}
|
280
|
-
const allAccounts = items.flatMap((item) => {
|
281
|
-
return (item.tx
|
282
|
-
?.getInstructions()
|
283
|
-
.filter((ix) => {
|
284
|
-
return (ix.programId.toString() === constants_1.SOLAUTO_PROD_PROGRAM.toString() ||
|
285
|
-
ix.programId.toString() === constants_1.SOLAUTO_TEST_PROGRAM.toString());
|
286
|
-
})
|
287
|
-
.flatMap((ix) => {
|
288
|
-
return ix.keys.map((key) => key.pubkey.toString());
|
289
|
-
}) ?? []);
|
290
|
-
});
|
291
|
-
const swbOracle = allAccounts.find((x) => Object.values(constants_1.SWITCHBOARD_PRICE_FEED_IDS)
|
292
|
-
.map((x) => x.feedId)
|
293
|
-
.includes(x ?? ""));
|
294
|
-
if (swbOracle) {
|
295
|
-
const mint = new web3_js_1.PublicKey(Object.keys(constants_1.SWITCHBOARD_PRICE_FEED_IDS).find((x) => constants_1.SWITCHBOARD_PRICE_FEED_IDS[x].feedId === swbOracle));
|
296
|
-
const stale = (await (0, utils_1.getSwitchboardFeedData)(client.connection, [mint]))[0]
|
297
|
-
.stale;
|
298
|
-
if (stale) {
|
299
|
-
this.txHandler.log("Requires oracle update...");
|
300
|
-
const swbTx = new TransactionItem(async () => (0, utils_1.buildSwbSubmitResponseTx)(client.connection, client.signer, mint), this.updateOracleTxName);
|
301
|
-
await swbTx.initialize();
|
302
|
-
items.unshift(swbTx);
|
303
|
-
}
|
304
|
-
}
|
305
|
-
let [choresBefore, choresAfter] = await (0, transactionUtils_1.getTransactionChores)(client, (0, umi_1.transactionBuilder)().add(items
|
306
|
-
.filter((x) => x.tx && x.tx.getInstructions().length > 0)
|
307
|
-
.map((x) => x.tx)));
|
308
|
-
if (updateLut && !updateLut?.new) {
|
309
|
-
choresBefore = choresBefore.prepend(updateLut.tx);
|
310
|
-
}
|
311
|
-
if (choresBefore.getInstructions().length > 0) {
|
312
|
-
const chore = new TransactionItem(async () => ({ tx: choresBefore }), CHORES_TX_NAME);
|
313
|
-
await chore.initialize();
|
314
|
-
items.unshift(chore);
|
315
|
-
this.txHandler.log("Chores before: ", choresBefore.getInstructions().length);
|
316
|
-
}
|
317
|
-
if (choresAfter.getInstructions().length > 0) {
|
318
|
-
const chore = new TransactionItem(async () => ({ tx: choresAfter }), CHORES_TX_NAME);
|
319
|
-
await chore.initialize();
|
320
|
-
items.push(chore);
|
321
|
-
this.txHandler.log("Chores after: ", choresAfter.getInstructions().length);
|
322
|
-
}
|
323
|
-
const result = await this.send(items).catch((e) => {
|
324
|
-
client.resetLiveTxUpdates(false);
|
325
|
-
throw e;
|
326
|
-
});
|
327
|
-
if (this.txType !== "only-simulate") {
|
328
|
-
await client.resetLiveTxUpdates();
|
329
|
-
}
|
330
|
-
return result;
|
331
|
-
}
|
332
142
|
async send(items) {
|
333
143
|
this.statuses = [];
|
334
144
|
this.lookupTables.reset();
|
@@ -390,13 +200,13 @@ class TransactionsManager {
|
|
390
200
|
let txSigs;
|
391
201
|
let error;
|
392
202
|
try {
|
393
|
-
txSigs = await (0, utils_1.sendJitoBundledTransactions)(this.txHandler.umi, this.txHandler.connection, this.txHandler.signer, this.txHandler.otherSigners, transactions, this.
|
203
|
+
txSigs = await (0, utils_1.sendJitoBundledTransactions)(this.txHandler.umi, this.txHandler.connection, this.txHandler.signer, this.txHandler.otherSigners, transactions, this.txRunType, this.getUpdatedPriorityFeeSetting(prevError, attemptNum), () => this.updateStatusForSets(itemSets, TransactionStatus.Processing, attemptNum, undefined, true));
|
394
204
|
}
|
395
205
|
catch (e) {
|
396
206
|
error = e;
|
397
207
|
}
|
398
208
|
if (error ||
|
399
|
-
(this.
|
209
|
+
(this.txRunType !== "only-simulate" &&
|
400
210
|
(!Boolean(txSigs) || txSigs?.length === 0))) {
|
401
211
|
this.updateStatusForSets(itemSets, TransactionStatus.Failed, attemptNum, txSigs, undefined, error?.message);
|
402
212
|
throw error ? error : new Error("Unknown error");
|
@@ -475,10 +285,10 @@ class TransactionsManager {
|
|
475
285
|
}
|
476
286
|
return newItemSets;
|
477
287
|
}
|
478
|
-
async sendTransaction(tx, txName, attemptNum, priorityFeeSetting,
|
288
|
+
async sendTransaction(tx, txName, attemptNum, priorityFeeSetting, txRunType) {
|
479
289
|
this.updateStatus(txName, TransactionStatus.Processing, attemptNum);
|
480
290
|
try {
|
481
|
-
const txSig = await (0, utils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx,
|
291
|
+
const txSig = await (0, utils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx, txRunType ?? this.txRunType, priorityFeeSetting, () => this.updateStatus(txName, TransactionStatus.Processing, attemptNum, undefined, true));
|
482
292
|
this.updateStatus(txName, TransactionStatus.Successful, attemptNum, txSig ? bs58_1.default.encode(txSig) : undefined);
|
483
293
|
}
|
484
294
|
catch (e) {
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./lookupTables"), exports);
|
18
|
+
__exportStar(require("./transactionItem"), exports);
|
19
|
+
__exportStar(require("./transactionSet"), exports);
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { AddressLookupTableInput, Umi } from "@metaplex-foundation/umi";
|
2
|
+
export declare class LookupTables {
|
3
|
+
defaultLuts: string[];
|
4
|
+
private umi;
|
5
|
+
cache: AddressLookupTableInput[];
|
6
|
+
constructor(defaultLuts: string[], umi: Umi);
|
7
|
+
getLutInputs(additionalAddresses?: string[]): Promise<AddressLookupTableInput[]>;
|
8
|
+
reset(): void;
|
9
|
+
}
|
10
|
+
//# sourceMappingURL=lookupTables.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"lookupTables.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/types/lookupTables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAGxE,qBAAa,YAAY;IAId,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,CAAC,EAAE,MAAM,EAAE,GAC7B,OAAO,CAAC,uBAAuB,EAAE,CAAC;IAkBrC,KAAK;CAKN"}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.LookupTables = void 0;
|
4
|
+
const utils_1 = require("../../../utils");
|
5
|
+
class LookupTables {
|
6
|
+
constructor(defaultLuts, umi) {
|
7
|
+
this.defaultLuts = defaultLuts;
|
8
|
+
this.umi = umi;
|
9
|
+
this.cache = [];
|
10
|
+
}
|
11
|
+
async getLutInputs(additionalAddresses) {
|
12
|
+
const addresses = [...this.defaultLuts, ...(additionalAddresses ?? [])];
|
13
|
+
const currentCacheAddresses = this.cache.map((x) => x.publicKey.toString());
|
14
|
+
const missingAddresses = addresses.filter((x) => !currentCacheAddresses.includes(x));
|
15
|
+
if (missingAddresses) {
|
16
|
+
const additionalInputs = await (0, utils_1.getAddressLookupInputs)(this.umi, missingAddresses);
|
17
|
+
this.cache.push(...additionalInputs);
|
18
|
+
}
|
19
|
+
return this.cache;
|
20
|
+
}
|
21
|
+
reset() {
|
22
|
+
this.cache = this.cache.filter((x) => this.defaultLuts.includes(x.publicKey.toString()));
|
23
|
+
}
|
24
|
+
}
|
25
|
+
exports.LookupTables = LookupTables;
|