@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
@@ -0,0 +1,16 @@
|
|
1
|
+
import { TransactionBuilder } from "@metaplex-foundation/umi";
|
2
|
+
import { TransactionItemInputs } from "../../../types";
|
3
|
+
export declare class TransactionItem {
|
4
|
+
fetchTx: (attemptNum: number, prevError?: Error) => Promise<TransactionItemInputs | undefined>;
|
5
|
+
name?: string | undefined;
|
6
|
+
oracleInteractor?: boolean | undefined;
|
7
|
+
lookupTableAddresses: string[];
|
8
|
+
tx?: TransactionBuilder;
|
9
|
+
initialized: boolean;
|
10
|
+
orderPrio: number;
|
11
|
+
constructor(fetchTx: (attemptNum: number, prevError?: Error) => Promise<TransactionItemInputs | undefined>, name?: string | undefined, oracleInteractor?: boolean | undefined);
|
12
|
+
initialize(): Promise<void>;
|
13
|
+
refetch(attemptNum: number, prevError?: Error): Promise<void>;
|
14
|
+
uniqueAccounts(): string[];
|
15
|
+
}
|
16
|
+
//# sourceMappingURL=transactionItem.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transactionItem.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/types/transactionItem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,qBAAa,eAAe;IAOjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,KAAK,KACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM;IACb,gBAAgB,CAAC,EAAE,OAAO;IAXnC,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;IACxB,WAAW,EAAE,OAAO,CAAS;IAC7B,SAAS,EAAE,MAAM,CAAK;gBAGb,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,EAClB,SAAS,CAAC,EAAE,KAAK,KACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,EACxC,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,gBAAgB,CAAC,EAAE,OAAO,YAAA;IAG7B,UAAU;IAKV,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,KAAK;IAOnD,cAAc,IAAI,MAAM,EAAE;CAY3B"}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TransactionItem = void 0;
|
4
|
+
class TransactionItem {
|
5
|
+
constructor(fetchTx, name, oracleInteractor) {
|
6
|
+
this.fetchTx = fetchTx;
|
7
|
+
this.name = name;
|
8
|
+
this.oracleInteractor = oracleInteractor;
|
9
|
+
this.initialized = false;
|
10
|
+
this.orderPrio = 0;
|
11
|
+
}
|
12
|
+
async initialize() {
|
13
|
+
await this.refetch(0);
|
14
|
+
this.initialized = true;
|
15
|
+
}
|
16
|
+
async refetch(attemptNum, prevError) {
|
17
|
+
const resp = await this.fetchTx(attemptNum, prevError);
|
18
|
+
this.tx = resp?.tx;
|
19
|
+
this.lookupTableAddresses = resp?.lookupTableAddresses ?? [];
|
20
|
+
this.orderPrio = resp?.orderPrio ?? 0;
|
21
|
+
}
|
22
|
+
uniqueAccounts() {
|
23
|
+
return Array.from(new Set(this.tx.getInstructions()
|
24
|
+
.map((x) => [
|
25
|
+
x.programId.toString(),
|
26
|
+
...x.keys.map((y) => y.pubkey.toString()),
|
27
|
+
])
|
28
|
+
.flat()));
|
29
|
+
}
|
30
|
+
}
|
31
|
+
exports.TransactionItem = TransactionItem;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { AddressLookupTableInput, TransactionBuilder } from "@metaplex-foundation/umi";
|
2
|
+
import { TxHandler } from "../../solauto";
|
3
|
+
import { LookupTables } from "./lookupTables";
|
4
|
+
import { TransactionItem } from "./transactionItem";
|
5
|
+
export declare class TransactionSet {
|
6
|
+
private txHandler;
|
7
|
+
lookupTables: LookupTables;
|
8
|
+
items: TransactionItem[];
|
9
|
+
constructor(txHandler: TxHandler, lookupTables: LookupTables, items?: TransactionItem[]);
|
10
|
+
lutInputs(): Promise<AddressLookupTableInput[]>;
|
11
|
+
fitsWith(item: TransactionItem): Promise<boolean>;
|
12
|
+
add(...items: TransactionItem[]): void;
|
13
|
+
prepend(...items: TransactionItem[]): void;
|
14
|
+
reset(): Promise<void>;
|
15
|
+
refetchAll(attemptNum: number, prevError?: Error): Promise<void>;
|
16
|
+
getSingleTransaction(): Promise<TransactionBuilder>;
|
17
|
+
lutAddresses(): string[];
|
18
|
+
name(): string;
|
19
|
+
}
|
20
|
+
//# sourceMappingURL=transactionSet.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"transactionSet.d.ts","sourceRoot":"","sources":["../../../../src/services/transactions/types/transactionSet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EAEvB,kBAAkB,EACnB,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;AAMpD,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;IA4BvD,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"}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TransactionSet = void 0;
|
4
|
+
const umi_1 = require("@metaplex-foundation/umi");
|
5
|
+
const utils_1 = require("../../../utils");
|
6
|
+
const constants_1 = require("../../../constants");
|
7
|
+
const MAX_SUPPORTED_ACCOUNT_LOCKS = 64;
|
8
|
+
class TransactionSet {
|
9
|
+
constructor(txHandler, lookupTables, items = []) {
|
10
|
+
this.txHandler = txHandler;
|
11
|
+
this.lookupTables = lookupTables;
|
12
|
+
this.items = items;
|
13
|
+
}
|
14
|
+
async lutInputs() {
|
15
|
+
const lutInputs = await this.lookupTables.getLutInputs(this.lutAddresses());
|
16
|
+
return lutInputs.filter((lut, index, self) => index ===
|
17
|
+
self.findIndex((item) => item.publicKey.toString() === lut.publicKey.toString()));
|
18
|
+
}
|
19
|
+
async fitsWith(item) {
|
20
|
+
if (!item.tx) {
|
21
|
+
return true;
|
22
|
+
}
|
23
|
+
const accountLocks = Array.from(new Set([
|
24
|
+
...this.items.map((x) => x.uniqueAccounts()),
|
25
|
+
...item.uniqueAccounts(),
|
26
|
+
])).length;
|
27
|
+
if (accountLocks > MAX_SUPPORTED_ACCOUNT_LOCKS) {
|
28
|
+
return false;
|
29
|
+
}
|
30
|
+
const singleTx = await this.getSingleTransaction();
|
31
|
+
const tx = (0, utils_1.addTxOptimizations)(this.txHandler.umi, singleTx, 1, 1)
|
32
|
+
.add(item.tx)
|
33
|
+
.setAddressLookupTables(await this.lookupTables.getLutInputs([
|
34
|
+
...this.lutAddresses(),
|
35
|
+
...item.lookupTableAddresses,
|
36
|
+
]));
|
37
|
+
return tx.fitsInOneTransaction(this.txHandler.umi);
|
38
|
+
}
|
39
|
+
add(...items) {
|
40
|
+
this.items.push(...items.filter((x) => x.tx && x.tx.getInstructions().length > 0));
|
41
|
+
}
|
42
|
+
prepend(...items) {
|
43
|
+
this.items.unshift(...items.filter((x) => x.tx && x.tx.getInstructions().length > 0));
|
44
|
+
}
|
45
|
+
async reset() {
|
46
|
+
await this.txHandler.resetLiveTxUpdates();
|
47
|
+
}
|
48
|
+
async refetchAll(attemptNum, prevError) {
|
49
|
+
for (const item of this.items) {
|
50
|
+
await item.refetch(attemptNum, prevError);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
async getSingleTransaction() {
|
54
|
+
const transactions = this.items
|
55
|
+
.filter((x) => x.tx && x.tx.getInstructions().length > 0)
|
56
|
+
.map((x) => x.tx);
|
57
|
+
return (0, umi_1.transactionBuilder)()
|
58
|
+
.add(transactions)
|
59
|
+
.setAddressLookupTables(await this.lutInputs());
|
60
|
+
}
|
61
|
+
lutAddresses() {
|
62
|
+
return Array.from(new Set(this.items.map((x) => x.lookupTableAddresses).flat()));
|
63
|
+
}
|
64
|
+
name() {
|
65
|
+
let names = this.items
|
66
|
+
.filter((x) => x.tx && Boolean(x.name))
|
67
|
+
.map((x) => x.name.toLowerCase());
|
68
|
+
if (names.length > 1) {
|
69
|
+
names = names.filter((x) => x !== constants_1.CHORES_TX_NAME);
|
70
|
+
}
|
71
|
+
if (names.length >= 3) {
|
72
|
+
return [names.slice(0, -1).join(", "), names[names.length - 1]].join(", and ");
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
return names.join(" & ");
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
exports.TransactionSet = TransactionSet;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"instructionUtils.d.ts","sourceRoot":"","sources":["../../src/utils/instructionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAsB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,gCAAgC,EACjC,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,aAAa,EAEb,eAAe,EAEhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,gCAAgC,EAC/C,GAAG,CAAC,EAAE,kBAAkB,mBAQzB;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,mBAOzD;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,gBAAgB,CAAC,gCAAgC,CAAC,EAC5D,GAAG,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,mBAY1C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,mBAOrD;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAUpE;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"instructionUtils.d.ts","sourceRoot":"","sources":["../../src/utils/instructionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAsB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,gCAAgC,EACjC,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,aAAa,EAEb,eAAe,EAEhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,gCAAgC,EAC/C,GAAG,CAAC,EAAE,kBAAkB,mBAQzB;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,mBAOzD;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,gBAAgB,CAAC,gCAAgC,CAAC,EAC5D,GAAG,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,mBAY1C;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,mBAOrD;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAUpE;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAWnE;AAED,wBAAgB,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,GAAG,MAAM,mBAerE;AAED,wBAAgB,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,GAAG,MAAM,mBAclE;AAED,wBAAgB,SAAS,CACvB,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,mBAYrC;AAED,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,SAAS,EACtB,qBAAqB,EAAE,MAAM,qBAyC9B"}
|
@@ -51,7 +51,7 @@ function borrow(client, baseUnitAmount) {
|
|
51
51
|
__kind: "Borrow",
|
52
52
|
fields: [baseUnitAmount],
|
53
53
|
}),
|
54
|
-
}), "borrow");
|
54
|
+
}), "borrow", true);
|
55
55
|
}
|
56
56
|
function withdraw(client, amount) {
|
57
57
|
return new services_1.TransactionItem(async () => ({
|
@@ -63,7 +63,7 @@ function withdraw(client, amount) {
|
|
63
63
|
: { __kind: "Some", fields: [amount] },
|
64
64
|
],
|
65
65
|
}),
|
66
|
-
}), "withdraw");
|
66
|
+
}), "withdraw", true);
|
67
67
|
}
|
68
68
|
function repay(client, amount) {
|
69
69
|
return new services_1.TransactionItem(async () => ({
|
@@ -78,7 +78,7 @@ function repay(client, amount) {
|
|
78
78
|
}), "repay");
|
79
79
|
}
|
80
80
|
function rebalance(client, targetLiqUtilizationRateBps) {
|
81
|
-
return new services_1.TransactionItem(async (attemptNum, prevError) => await new services_1.RebalanceTxBuilder(client, targetLiqUtilizationRateBps, attemptNum > 2 && prevError instanceof services_1.TransactionTooLargeError).buildRebalanceTx(attemptNum), "rebalance");
|
81
|
+
return new services_1.TransactionItem(async (attemptNum, prevError) => await new services_1.RebalanceTxBuilder(client, targetLiqUtilizationRateBps, attemptNum > 2 && prevError instanceof services_1.TransactionTooLargeError).buildRebalanceTx(attemptNum), "rebalance", true);
|
82
82
|
}
|
83
83
|
function swapThenDeposit(client, depositMint, depositAmountBaseUnit) {
|
84
84
|
return [
|
@@ -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;AAIvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAOjD,wBAAgB,WAAW,CACzB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,SAAS,EACf,MAAM,CAAC,EAAE,SAAS,qBAuBnB;AAED,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CA6B5C;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"}
|
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.getPullFeed = getPullFeed;
|
30
30
|
exports.buildSwbSubmitResponseTx = buildSwbSubmitResponseTx;
|
31
31
|
exports.getSwitchboardFeedData = getSwitchboardFeedData;
|
32
|
+
exports.isSwitchboardMint = isSwitchboardMint;
|
32
33
|
const web3_js_1 = require("@solana/web3.js");
|
33
34
|
const umi_1 = require("@metaplex-foundation/umi");
|
34
35
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
@@ -58,6 +59,12 @@ async function buildSwbSubmitResponseTx(conn, signer, mint) {
|
|
58
59
|
if (!pullIx) {
|
59
60
|
throw new Error("Unable to fetch SWB crank IX");
|
60
61
|
}
|
62
|
+
const price = responses[0].value.toNumber();
|
63
|
+
constants_1.PRICES[mint.toString()] = {
|
64
|
+
realtimePrice: price,
|
65
|
+
emaPrice: price,
|
66
|
+
time: (0, generalUtils_1.currentUnixSeconds)(),
|
67
|
+
};
|
61
68
|
return {
|
62
69
|
tx: (0, umi_1.transactionBuilder)([(0, solanaUtils_1.getWrappedInstruction)(signer, pullIx)]),
|
63
70
|
lookupTableAddresses: responses
|
@@ -79,3 +86,6 @@ async function getSwitchboardFeedData(conn, mints) {
|
|
79
86
|
}));
|
80
87
|
return results;
|
81
88
|
}
|
89
|
+
function isSwitchboardMint(mint) {
|
90
|
+
return Object.keys(constants_1.SWITCHBOARD_PRICE_FEED_IDS).includes(mint.toString());
|
91
|
+
}
|
package/local/txSandbox.ts
CHANGED
@@ -2,6 +2,7 @@ import { Keypair, PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { createSignerFromKeypair } from "@metaplex-foundation/umi";
|
3
3
|
import { fromWeb3JsKeypair } from "@metaplex-foundation/umi-web3js-adapters";
|
4
4
|
import {
|
5
|
+
ClientTransactionsManager,
|
5
6
|
consoleLog,
|
6
7
|
getBatches,
|
7
8
|
getClient,
|
@@ -18,11 +19,10 @@ import {
|
|
18
19
|
SOLAUTO_TEST_PROGRAM,
|
19
20
|
SolautoClient,
|
20
21
|
TransactionItem,
|
21
|
-
TransactionsManager,
|
22
22
|
} from "../src";
|
23
23
|
import { getSecretKey } from "./shared";
|
24
24
|
|
25
|
-
const payForTransaction =
|
25
|
+
const payForTransaction = false;
|
26
26
|
const testProgram = false;
|
27
27
|
const lpEnv: ProgramEnv = "Prod";
|
28
28
|
|
@@ -47,8 +47,8 @@ export async function main() {
|
|
47
47
|
});
|
48
48
|
|
49
49
|
await client.initializeExistingSolautoPosition({
|
50
|
-
positionId:
|
51
|
-
authority: new PublicKey("
|
50
|
+
positionId: 1,
|
51
|
+
authority: new PublicKey("5UqsR2PGzbP8pGPbXEeXx86Gjz2N2UFBAuFZUSVydAEe"),
|
52
52
|
// lpUserAccount: new PublicKey(
|
53
53
|
// "GEokw9jqbh6d1xUNA3qaeYFFetbSR5Y1nt7C3chwwgSz"
|
54
54
|
// ),
|
@@ -56,16 +56,13 @@ export async function main() {
|
|
56
56
|
|
57
57
|
const transactionItems = [rebalance(client)];
|
58
58
|
|
59
|
-
const txManager = new
|
60
|
-
client,
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
{ totalRetries: 5 }
|
67
|
-
);
|
68
|
-
const statuses = await txManager.clientSend(transactionItems);
|
59
|
+
const txManager = new ClientTransactionsManager({
|
60
|
+
txHandler: client,
|
61
|
+
txRunType: payForTransaction ? "normal" : "only-simulate",
|
62
|
+
priorityFeeSetting: PriorityFeeSetting.Default,
|
63
|
+
retryConfig: { totalRetries: 5 },
|
64
|
+
});
|
65
|
+
const statuses = await txManager.send(transactionItems);
|
69
66
|
consoleLog(statuses);
|
70
67
|
}
|
71
68
|
|
@@ -104,15 +101,12 @@ async function refreshAll() {
|
|
104
101
|
const txBatches = getBatches(transactionItems, 15);
|
105
102
|
|
106
103
|
for (const batch of txBatches) {
|
107
|
-
const txManager = new
|
108
|
-
client!,
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
undefined,
|
114
|
-
{ totalRetries: 5 }
|
115
|
-
);
|
104
|
+
const txManager = new ClientTransactionsManager({
|
105
|
+
txHandler: client!,
|
106
|
+
txRunType: payForTransaction ? "normal" : "only-simulate",
|
107
|
+
priorityFeeSetting: PriorityFeeSetting.Default,
|
108
|
+
retryConfig: { totalRetries: 5 },
|
109
|
+
});
|
116
110
|
const statuses = await txManager.send(batch);
|
117
111
|
consoleLog(statuses);
|
118
112
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@haven-fi/solauto-sdk",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.686",
|
4
4
|
"main": "dist/index.js",
|
5
5
|
"types": "dist/index.d.ts",
|
6
6
|
"description": "Typescript SDK for the Solauto program on the Solana blockchain",
|
@@ -23,12 +23,14 @@
|
|
23
23
|
"@switchboard-xyz/common": "=3.0.12",
|
24
24
|
"@switchboard-xyz/on-demand": "=1.2.51",
|
25
25
|
"axios": "^1.7.8",
|
26
|
+
"big.js": "^6.2.2",
|
26
27
|
"bs58": "^5.0.0",
|
27
28
|
"cross-fetch": "^4.0.0",
|
28
29
|
"dotenv": "^16.4.7",
|
29
30
|
"rpc-websockets": "7.11.0"
|
30
31
|
},
|
31
32
|
"devDependencies": {
|
33
|
+
"@types/big.js": "^6.2.2",
|
32
34
|
"@types/chai": "^4.3.0",
|
33
35
|
"@types/mocha": "^9.1.1",
|
34
36
|
"@types/node": "^20.16.11",
|
@@ -31,6 +31,8 @@ export const REFERRER_PERCENTAGE = 0.15;
|
|
31
31
|
|
32
32
|
export const PRICES: { [key: string]: { realtimePrice: number; emaPrice: number; time: number } } = {};
|
33
33
|
|
34
|
+
export const CHORES_TX_NAME = "account chores";
|
35
|
+
|
34
36
|
export const JITO_TIP_ACCOUNTS = [
|
35
37
|
"96gYZGLnJYVFmbjzopPSU6QiEV5fGqZNyN9nmNhvrZU5",
|
36
38
|
"HFqU5x63VTqvQss8hp11i4wVV8bD44PvwucfZ2bU7gRe",
|
@@ -1,2 +1,3 @@
|
|
1
|
-
export * from
|
2
|
-
export * from
|
1
|
+
export * from "./manager";
|
2
|
+
export * from "./types";
|
3
|
+
export * from "./transactionUtils";
|
@@ -0,0 +1,141 @@
|
|
1
|
+
import {
|
2
|
+
transactionBuilder,
|
3
|
+
TransactionBuilder,
|
4
|
+
} from "@metaplex-foundation/umi";
|
5
|
+
import { SolautoClient } from "../../solauto";
|
6
|
+
import { TransactionsManager } from "./transactionsManager";
|
7
|
+
import {
|
8
|
+
buildSwbSubmitResponseTx,
|
9
|
+
isSwitchboardMint,
|
10
|
+
retryWithExponentialBackoff,
|
11
|
+
} from "../../../utils";
|
12
|
+
import { TransactionItem } from "../types";
|
13
|
+
import { getTransactionChores } from "../transactionUtils";
|
14
|
+
import { CHORES_TX_NAME } from "../../../constants";
|
15
|
+
|
16
|
+
export class ClientTransactionsManager extends TransactionsManager<SolautoClient> {
|
17
|
+
private async updateLut(tx: TransactionBuilder, newLut: boolean) {
|
18
|
+
const lutInputs = await this.lookupTables.getLutInputs();
|
19
|
+
const updateLutTxName = `${newLut ? "create" : "update"} lookup table`;
|
20
|
+
await retryWithExponentialBackoff(
|
21
|
+
async (attemptNum, prevError) =>
|
22
|
+
await this.sendTransaction(
|
23
|
+
tx.setAddressLookupTables(lutInputs),
|
24
|
+
updateLutTxName,
|
25
|
+
attemptNum,
|
26
|
+
this.getUpdatedPriorityFeeSetting(prevError, attemptNum),
|
27
|
+
"skip-simulation"
|
28
|
+
),
|
29
|
+
this.signableRetries,
|
30
|
+
150,
|
31
|
+
this.errorsToThrow
|
32
|
+
);
|
33
|
+
await this.txHandler.refetchReferralState();
|
34
|
+
}
|
35
|
+
|
36
|
+
private async addSwbOraclePullTxs(txs: TransactionItem[]) {
|
37
|
+
const switchboardMints = [
|
38
|
+
...(isSwitchboardMint(this.txHandler.pos.supplyMint)
|
39
|
+
? [this.txHandler.pos.supplyMint]
|
40
|
+
: []),
|
41
|
+
...(isSwitchboardMint(this.txHandler.pos.debtMint)
|
42
|
+
? [this.txHandler.pos.debtMint]
|
43
|
+
: []),
|
44
|
+
];
|
45
|
+
|
46
|
+
if (txs.find((x) => x.oracleInteractor) && switchboardMints.length) {
|
47
|
+
this.txHandler.log("Requires oracle update(s)...");
|
48
|
+
const txs = switchboardMints.map(
|
49
|
+
(x) =>
|
50
|
+
new TransactionItem(
|
51
|
+
async () =>
|
52
|
+
buildSwbSubmitResponseTx(
|
53
|
+
this.txHandler.connection,
|
54
|
+
this.txHandler.signer,
|
55
|
+
x
|
56
|
+
),
|
57
|
+
this.updateOracleTxName
|
58
|
+
)
|
59
|
+
);
|
60
|
+
txs.unshift(...txs);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
private async addChoreTxs(
|
65
|
+
txs: TransactionItem[],
|
66
|
+
updateLutTx?: TransactionBuilder
|
67
|
+
) {
|
68
|
+
let [choresBefore, choresAfter] = await getTransactionChores(
|
69
|
+
this.txHandler,
|
70
|
+
transactionBuilder().add(
|
71
|
+
txs
|
72
|
+
.filter((x) => x.tx && x.tx.getInstructions().length > 0)
|
73
|
+
.map((x) => x.tx!)
|
74
|
+
)
|
75
|
+
);
|
76
|
+
|
77
|
+
if (updateLutTx) {
|
78
|
+
choresBefore.prepend(updateLutTx);
|
79
|
+
}
|
80
|
+
|
81
|
+
if (choresBefore.getInstructions().length) {
|
82
|
+
const chore = new TransactionItem(
|
83
|
+
async () => ({ tx: choresBefore }),
|
84
|
+
CHORES_TX_NAME
|
85
|
+
);
|
86
|
+
await chore.initialize();
|
87
|
+
txs.unshift(chore);
|
88
|
+
this.txHandler.log(
|
89
|
+
"Chores before: ",
|
90
|
+
choresBefore.getInstructions().length
|
91
|
+
);
|
92
|
+
}
|
93
|
+
|
94
|
+
if (choresAfter.getInstructions().length) {
|
95
|
+
const chore = new TransactionItem(
|
96
|
+
async () => ({ tx: choresAfter }),
|
97
|
+
CHORES_TX_NAME
|
98
|
+
);
|
99
|
+
await chore.initialize();
|
100
|
+
txs.push(chore);
|
101
|
+
this.txHandler.log(
|
102
|
+
"Chores after: ",
|
103
|
+
choresAfter.getInstructions().length
|
104
|
+
);
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
public async send(transactions: TransactionItem[]) {
|
109
|
+
const items = [...transactions];
|
110
|
+
const client = this.txHandler as SolautoClient;
|
111
|
+
|
112
|
+
const updateLut = await client.updateLookupTable();
|
113
|
+
|
114
|
+
if (updateLut && (updateLut?.new || updateLut.accountsToAdd.length > 4)) {
|
115
|
+
await this.updateLut(updateLut.tx, updateLut.new);
|
116
|
+
}
|
117
|
+
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
118
|
+
|
119
|
+
await this.addSwbOraclePullTxs(items);
|
120
|
+
|
121
|
+
for (const item of items) {
|
122
|
+
await item.initialize();
|
123
|
+
}
|
124
|
+
|
125
|
+
await this.addChoreTxs(
|
126
|
+
items,
|
127
|
+
updateLut && !updateLut?.new ? updateLut.tx : undefined
|
128
|
+
);
|
129
|
+
|
130
|
+
const result = await super.send(items).catch((e) => {
|
131
|
+
client.resetLiveTxUpdates(false);
|
132
|
+
throw e;
|
133
|
+
});
|
134
|
+
|
135
|
+
if (this.txRunType !== "only-simulate") {
|
136
|
+
await client.resetLiveTxUpdates();
|
137
|
+
}
|
138
|
+
|
139
|
+
return result;
|
140
|
+
}
|
141
|
+
}
|