@haven-fi/solauto-sdk 1.0.82 → 1.0.84
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/index.d.ts +1 -0
- package/dist/clients/index.d.ts.map +1 -1
- package/dist/clients/index.js +1 -0
- package/dist/clients/referralStateManager.d.ts +6 -2
- package/dist/clients/referralStateManager.d.ts.map +1 -1
- package/dist/clients/referralStateManager.js +10 -4
- package/dist/clients/solautoClient.d.ts +6 -8
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +6 -12
- package/dist/clients/solautoMarginfiClient.d.ts +1 -0
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +3 -0
- package/dist/clients/txHandler.d.ts +13 -0
- package/dist/clients/txHandler.d.ts.map +1 -0
- package/dist/clients/txHandler.js +19 -0
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +1 -3
- package/dist/transactions/transactionsManager.d.ts +10 -9
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +44 -38
- package/package.json +1 -1
- package/src/clients/index.ts +2 -1
- package/src/clients/referralStateManager.ts +10 -4
- package/src/clients/solautoClient.ts +9 -17
- package/src/clients/solautoMarginfiClient.ts +4 -1
- package/src/clients/txHandler.ts +28 -0
- package/src/transactions/transactionUtils.ts +2 -4
- package/src/transactions/transactionsManager.ts +53 -42
- package/tests/transactions/solautoMarginfi.ts +15 -16
package/dist/clients/index.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/clients/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/clients/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,aAAa,CAAC"}
|
package/dist/clients/index.js
CHANGED
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./solautoMarginfiClient"), exports);
|
18
18
|
__exportStar(require("./solautoClient"), exports);
|
19
19
|
__exportStar(require("./referralStateManager"), exports);
|
20
|
+
__exportStar(require("./txHandler"), exports);
|
@@ -2,21 +2,25 @@ import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { Signer, TransactionBuilder, Umi } from "@metaplex-foundation/umi";
|
3
3
|
import { WalletAdapter } from "@metaplex-foundation/umi-signer-wallet-adapters";
|
4
4
|
import { ReferralState } from "../generated";
|
5
|
+
import { TxHandler } from "./txHandler";
|
5
6
|
interface ReferralStateManagerArgs {
|
6
7
|
referralAuthority?: PublicKey;
|
7
8
|
signer?: Signer;
|
8
9
|
wallet?: WalletAdapter;
|
9
10
|
}
|
10
|
-
export declare class ReferralStateManager {
|
11
|
+
export declare class ReferralStateManager extends TxHandler {
|
12
|
+
localTest?: boolean | undefined;
|
11
13
|
umi: Umi;
|
12
14
|
signer: Signer;
|
13
15
|
referralAuthority: PublicKey;
|
14
16
|
referralState: PublicKey;
|
15
17
|
referralStateData: ReferralState | null;
|
16
|
-
constructor(heliusApiKey: string);
|
18
|
+
constructor(heliusApiKey: string, localTest?: boolean | undefined);
|
17
19
|
initialize(args: ReferralStateManagerArgs): Promise<void>;
|
20
|
+
defaultLookupTables(): string[];
|
18
21
|
updateReferralStatesIx(destFeesMint?: PublicKey, referredBy?: PublicKey, lookupTable?: PublicKey): TransactionBuilder;
|
19
22
|
claimReferralFeesIx(destFeesMint?: PublicKey): TransactionBuilder;
|
23
|
+
resetLiveTxUpdates(): Promise<void>;
|
20
24
|
}
|
21
25
|
export {};
|
22
26
|
//# sourceMappingURL=referralStateManager.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"referralStateManager.d.ts","sourceRoot":"","sources":["../../src/clients/referralStateManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAa,MAAM,EAAkB,kBAAkB,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAEtG,OAAO,EAAE,aAAa,EAAyB,MAAM,iDAAiD,CAAC;AACvG,OAAO,EAA2C,aAAa,EAAgD,MAAM,cAAc,CAAC;
|
1
|
+
{"version":3,"file":"referralStateManager.d.ts","sourceRoot":"","sources":["../../src/clients/referralStateManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAa,MAAM,EAAkB,kBAAkB,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAEtG,OAAO,EAAE,aAAa,EAAyB,MAAM,iDAAiD,CAAC;AACvG,OAAO,EAA2C,aAAa,EAAgD,MAAM,cAAc,CAAC;AAEpI,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,UAAU,wBAAwB;IAC9B,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED,qBAAa,oBAAqB,SAAQ,SAAS;IAQN,SAAS,CAAC,EAAE,OAAO;IAPrD,GAAG,EAAG,GAAG,CAAC;IACV,MAAM,EAAG,MAAM,CAAC;IAEhB,iBAAiB,EAAG,SAAS,CAAC;IAC9B,aAAa,EAAG,SAAS,CAAC;IAC1B,iBAAiB,EAAG,aAAa,GAAG,IAAI,CAAC;gBAEpC,YAAY,EAAE,MAAM,EAAS,SAAS,CAAC,EAAE,OAAO,YAAA;IAStD,UAAU,CAAC,IAAI,EAAE,wBAAwB;IAe/C,mBAAmB,IAAI,MAAM,EAAE;IAI/B,sBAAsB,CAAC,YAAY,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,SAAS,EAAE,WAAW,CAAC,EAAE,SAAS,GAAG,kBAAkB;IAiBrH,mBAAmB,CAAC,YAAY,CAAC,EAAE,SAAS,GAAG,kBAAkB;IAwB3D,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;CAC5C"}
|
@@ -7,10 +7,12 @@ const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters"
|
|
7
7
|
const umi_signer_wallet_adapters_1 = require("@metaplex-foundation/umi-signer-wallet-adapters");
|
8
8
|
const generated_1 = require("../generated");
|
9
9
|
const utils_1 = require("../utils");
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
const txHandler_1 = require("./txHandler");
|
11
|
+
class ReferralStateManager extends txHandler_1.TxHandler {
|
12
|
+
constructor(heliusApiKey, localTest) {
|
13
|
+
super(heliusApiKey, localTest);
|
14
|
+
this.localTest = localTest;
|
15
|
+
this.umi = this.umi.use({
|
14
16
|
install(umi) {
|
15
17
|
umi.programs.add((0, generated_1.createSolautoProgram)(), false);
|
16
18
|
},
|
@@ -27,6 +29,9 @@ class ReferralStateManager {
|
|
27
29
|
this.referralState = (0, utils_1.getReferralState)(args.referralAuthority ?? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey));
|
28
30
|
this.referralStateData = await (0, generated_1.safeFetchReferralState)(this.umi, (0, umi_1.publicKey)(this.referralState));
|
29
31
|
}
|
32
|
+
defaultLookupTables() {
|
33
|
+
return this.referralStateData?.lookupTable ? [this.referralStateData?.lookupTable.toString()] : [];
|
34
|
+
}
|
30
35
|
updateReferralStatesIx(destFeesMint, referredBy, lookupTable) {
|
31
36
|
return (0, generated_1.updateReferralStates)(this.umi, {
|
32
37
|
signer: this.signer,
|
@@ -59,5 +64,6 @@ class ReferralStateManager {
|
|
59
64
|
feesDestinationTa,
|
60
65
|
});
|
61
66
|
}
|
67
|
+
async resetLiveTxUpdates() { }
|
62
68
|
}
|
63
69
|
exports.ReferralStateManager = ReferralStateManager;
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import "rpc-websockets/dist/lib/client";
|
2
|
-
import {
|
3
|
-
import { Signer, TransactionBuilder
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
3
|
+
import { Signer, TransactionBuilder } from "@metaplex-foundation/umi";
|
4
4
|
import { WalletAdapter } from "@metaplex-foundation/umi-signer-wallet-adapters";
|
5
5
|
import { DCASettings, DCASettingsInpArgs, LendingPlatform, PositionState, SolautoActionArgs, SolautoPosition, SolautoRebalanceTypeArgs, SolautoSettingsParameters, SolautoSettingsParametersInpArgs, UpdatePositionDataArgs } from "../generated";
|
6
6
|
import { JupSwapDetails } from "../utils/jupiterUtils";
|
7
7
|
import { FlashLoanDetails } from "../utils/solauto/rebalanceUtils";
|
8
8
|
import { LivePositionUpdates } from "../utils/solauto/generalUtils";
|
9
9
|
import { ReferralStateManager } from "./referralStateManager";
|
10
|
+
import { TxHandler } from "./txHandler";
|
10
11
|
export interface SolautoClientArgs {
|
11
12
|
authority?: PublicKey;
|
12
13
|
positionId: number;
|
@@ -16,11 +17,8 @@ export interface SolautoClientArgs {
|
|
16
17
|
debtMint?: PublicKey;
|
17
18
|
referredByAuthority?: PublicKey;
|
18
19
|
}
|
19
|
-
export declare abstract class SolautoClient {
|
20
|
+
export declare abstract class SolautoClient extends TxHandler {
|
20
21
|
localTest?: boolean | undefined;
|
21
|
-
private heliusApiKey;
|
22
|
-
umi: Umi;
|
23
|
-
connection: Connection;
|
24
22
|
lendingPlatform: LendingPlatform;
|
25
23
|
authority: PublicKey;
|
26
24
|
signer: Signer;
|
@@ -46,8 +44,8 @@ export declare abstract class SolautoClient {
|
|
46
44
|
livePositionUpdates: LivePositionUpdates;
|
47
45
|
constructor(heliusApiKey: string, localTest?: boolean | undefined);
|
48
46
|
initialize(args: SolautoClientArgs, lendingPlatform: LendingPlatform): Promise<void>;
|
49
|
-
|
50
|
-
|
47
|
+
resetLiveTxUpdates(): Promise<void>;
|
48
|
+
abstract protocolAccount(): PublicKey;
|
51
49
|
defaultLookupTables(): string[];
|
52
50
|
lutAccountsToAdd(): PublicKey[];
|
53
51
|
fetchExistingAuthorityLutAccounts(): Promise<PublicKey[]>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,
|
1
|
+
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAGL,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAQnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EAMvB,MAAM,cAAc,CAAC;AAStB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAMvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAMnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IAEvB,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;IAErB,mBAAmB,CAAC,EAAE,SAAS,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kB,CAAC;QAAC,iBAAiB,EAAE,OAAO,CAAA;KAAE,GAAG,SAAS,CAC5E;IA2DD,uBAAuB,IAAI,yBAAyB,GAAG,SAAS;IAOhE,wBAAwB,IAAI,WAAW,GAAG,SAAS;IAOnD,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAuBrB,gBAAgB,CAAC,IAAI,EAAE,sBAAsB,GAAG,kBAAkB;IA2DlE,eAAe,IAAI,kBAAkB;IAWrC,WAAW,IAAI,kBAAkB;IA4BjC,QAAQ,CAAC,OAAO,IAAI,kBAAkB;IAEtC,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAuFhE,QAAQ,CAAC,WAAW,CAClB,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IAErB,QAAQ,CAAC,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAE3E,QAAQ,CAAC,SAAS,CAChB,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAYlE"}
|
@@ -14,14 +14,13 @@ const solautoConstants_1 = require("../constants/solautoConstants");
|
|
14
14
|
const generalUtils_1 = require("../utils/generalUtils");
|
15
15
|
const generalUtils_2 = require("../utils/solauto/generalUtils");
|
16
16
|
const referralStateManager_1 = require("./referralStateManager");
|
17
|
-
|
17
|
+
const txHandler_1 = require("./txHandler");
|
18
|
+
class SolautoClient extends txHandler_1.TxHandler {
|
18
19
|
constructor(heliusApiKey, localTest) {
|
20
|
+
super(heliusApiKey, localTest);
|
19
21
|
this.localTest = localTest;
|
20
22
|
this.livePositionUpdates = new generalUtils_2.LivePositionUpdates();
|
21
|
-
this.
|
22
|
-
const [connection, umi] = (0, solanaUtils_1.getSolanaRpcConnection)(this.heliusApiKey);
|
23
|
-
this.connection = connection;
|
24
|
-
this.umi = umi.use({
|
23
|
+
this.umi = this.umi.use({
|
25
24
|
install(umi) {
|
26
25
|
umi.programs.add((0, generated_1.createSolautoProgram)(), false);
|
27
26
|
},
|
@@ -91,12 +90,7 @@ class SolautoClient {
|
|
91
90
|
? this.solautoPositionData?.position?.dca
|
92
91
|
: undefined);
|
93
92
|
}
|
94
|
-
|
95
|
-
if (this.localTest) {
|
96
|
-
console.log(...args);
|
97
|
-
}
|
98
|
-
}
|
99
|
-
async resetLivePositionUpdates() {
|
93
|
+
async resetLiveTxUpdates() {
|
100
94
|
if (!this.solautoPositionData) {
|
101
95
|
this.solautoPositionData = await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition));
|
102
96
|
}
|
@@ -114,7 +108,7 @@ class SolautoClient {
|
|
114
108
|
this.livePositionUpdates.reset();
|
115
109
|
}
|
116
110
|
defaultLookupTables() {
|
117
|
-
return [solautoConstants_1.SOLAUTO_LUT];
|
111
|
+
return [solautoConstants_1.SOLAUTO_LUT, ...(this.authorityLutAddress ? [this.authorityLutAddress.toString()] : [])];
|
118
112
|
}
|
119
113
|
lutAccountsToAdd() {
|
120
114
|
return [
|
@@ -27,6 +27,7 @@ export declare class SolautoMarginfiClient extends SolautoClient {
|
|
27
27
|
intermediaryMarginfiAccount?: MarginfiAccount;
|
28
28
|
initialize(args: SolautoMarginfiClientArgs): Promise<void>;
|
29
29
|
setIntermediaryMarginfiDetails(): Promise<void>;
|
30
|
+
protocolAccount(): PublicKey;
|
30
31
|
defaultLookupTables(): string[];
|
31
32
|
lutAccountsToAdd(): PublicKey[];
|
32
33
|
marginfiAccountInitialize(): TransactionBuilder;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAM1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,
|
1
|
+
{"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAM1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAUhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAWnE,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,eAAe,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACrC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAED,qBAAa,qBAAsB,SAAQ,aAAa;I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AAG,kBAAkB;IAoFlE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAiBlE"}
|
@@ -82,6 +82,9 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
82
82
|
this.intermediaryMarginfiAccount =
|
83
83
|
emptyMarginfiAccounts.length > 0 ? emptyMarginfiAccounts[0] : undefined;
|
84
84
|
}
|
85
|
+
protocolAccount() {
|
86
|
+
return this.marginfiAccountPk;
|
87
|
+
}
|
85
88
|
defaultLookupTables() {
|
86
89
|
return [marginfiAccounts_1.MARGINFI_ACCOUNTS_LOOKUP_TABLE, ...super.defaultLookupTables()];
|
87
90
|
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { Umi } from "@metaplex-foundation/umi";
|
2
|
+
import { Connection } from "@solana/web3.js";
|
3
|
+
export declare abstract class TxHandler {
|
4
|
+
localTest?: boolean | undefined;
|
5
|
+
heliusApiKey: string;
|
6
|
+
umi: Umi;
|
7
|
+
connection: Connection;
|
8
|
+
constructor(heliusApiKey: string, localTest?: boolean | undefined);
|
9
|
+
log(...args: any[]): void;
|
10
|
+
abstract defaultLookupTables(): string[];
|
11
|
+
abstract resetLiveTxUpdates(): Promise<void>;
|
12
|
+
}
|
13
|
+
//# sourceMappingURL=txHandler.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"txHandler.d.ts","sourceRoot":"","sources":["../../src/clients/txHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAI7C,8BAAsB,SAAS;IAMpB,SAAS,CAAC,EAAE,OAAO;IALrB,YAAY,EAAG,MAAM,CAAC;IACtB,GAAG,EAAG,GAAG,CAAC;IACV,UAAU,EAAG,UAAU,CAAC;gBAEnB,YAAY,EAAE,MAAM,EACvB,SAAS,CAAC,EAAE,OAAO,YAAA;IAO5B,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAMzB,QAAQ,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAExC,QAAQ,CAAC,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;CAC7C"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TxHandler = void 0;
|
4
|
+
const utils_1 = require("../utils");
|
5
|
+
class TxHandler {
|
6
|
+
constructor(heliusApiKey, localTest) {
|
7
|
+
this.localTest = localTest;
|
8
|
+
this.heliusApiKey = heliusApiKey;
|
9
|
+
const [connection, umi] = (0, utils_1.getSolanaRpcConnection)(this.heliusApiKey);
|
10
|
+
this.connection = connection;
|
11
|
+
this.umi = umi;
|
12
|
+
}
|
13
|
+
log(...args) {
|
14
|
+
if (this.localTest) {
|
15
|
+
console.log(...args);
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
exports.TxHandler = TxHandler;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAuMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA8G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA4BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CACN;IACA,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACC,SAAS,CACZ,
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAuMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA8G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA4BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CACN;IACA,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACC,SAAS,CACZ,CAyHA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,eAAe,GAC5B,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CA8BzC"}
|
@@ -323,9 +323,7 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
323
323
|
client.solautoPositionState = await client.getFreshPositionState();
|
324
324
|
if (client.solautoPositionState?.supply.amountUsed.baseUnit === BigInt(0) ||
|
325
325
|
(targetLiqUtilizationRateBps === undefined &&
|
326
|
-
!(0, generalUtils_2.eligibleForRebalance)(client.solautoPositionState, client.
|
327
|
-
client.solautoPositionData?.position.settingParams, client.livePositionUpdates.activeDca ??
|
328
|
-
client.solautoPositionData?.position.dca, (0, generalUtils_1.currentUnixSeconds)()))) {
|
326
|
+
!(0, generalUtils_2.eligibleForRebalance)(client.solautoPositionState, client.solautoPositionSettings(), client.solautoPositionActiveDca(), (0, generalUtils_1.currentUnixSeconds)()))) {
|
329
327
|
client.log("Not eligible for a rebalance");
|
330
328
|
return undefined;
|
331
329
|
}
|
@@ -1,12 +1,13 @@
|
|
1
|
-
import { AddressLookupTableInput, TransactionBuilder } from "@metaplex-foundation/umi";
|
1
|
+
import { AddressLookupTableInput, TransactionBuilder, Umi } from "@metaplex-foundation/umi";
|
2
2
|
import { SolautoClient } from "../clients/solautoClient";
|
3
3
|
import { ErrorsToThrow } from "../utils/generalUtils";
|
4
4
|
import { PriorityFeeSetting } from "../types";
|
5
|
+
import { TxHandler } from "../clients";
|
5
6
|
declare class LookupTables {
|
6
|
-
private client;
|
7
7
|
defaultLuts: string[];
|
8
|
+
private umi;
|
8
9
|
cache: AddressLookupTableInput[];
|
9
|
-
constructor(
|
10
|
+
constructor(defaultLuts: string[], umi: Umi);
|
10
11
|
getLutInputs(additionalAddresses: string[]): Promise<AddressLookupTableInput[]>;
|
11
12
|
}
|
12
13
|
export declare class TransactionItem {
|
@@ -26,10 +27,10 @@ export declare class TransactionItem {
|
|
26
27
|
uniqueAccounts(): string[];
|
27
28
|
}
|
28
29
|
declare class TransactionSet {
|
29
|
-
private
|
30
|
+
private txHandler;
|
30
31
|
lookupTables: LookupTables;
|
31
32
|
items: TransactionItem[];
|
32
|
-
constructor(
|
33
|
+
constructor(txHandler: TxHandler, lookupTables: LookupTables, items?: TransactionItem[]);
|
33
34
|
fitsWith(item: TransactionItem): Promise<boolean>;
|
34
35
|
add(...items: TransactionItem[]): void;
|
35
36
|
refetchAll(attemptNum: number): Promise<void>;
|
@@ -49,19 +50,19 @@ export type TransactionManagerStatuses = {
|
|
49
50
|
txSig?: string;
|
50
51
|
}[];
|
51
52
|
export declare class TransactionsManager {
|
52
|
-
private
|
53
|
-
private items;
|
53
|
+
private txHandler;
|
54
54
|
private statusCallback?;
|
55
55
|
private simulateOnly?;
|
56
56
|
private mustBeAtomic?;
|
57
57
|
private errorsToThrow?;
|
58
58
|
private statuses;
|
59
59
|
private lookupTables;
|
60
|
-
constructor(
|
60
|
+
constructor(txHandler: TxHandler, statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined, simulateOnly?: boolean | undefined, mustBeAtomic?: boolean | undefined, errorsToThrow?: ErrorsToThrow | undefined);
|
61
61
|
private assembleTransactionSets;
|
62
62
|
updateStatus(name: string, status: TransactionStatus, txSig?: string): void;
|
63
63
|
debugAccounts(itemSet: TransactionSet, tx: TransactionBuilder): Promise<void>;
|
64
|
-
|
64
|
+
sendWithClient(items: TransactionItem[], client: SolautoClient, prioritySetting?: PriorityFeeSetting): Promise<void>;
|
65
|
+
send(items: TransactionItem[], prioritySetting?: PriorityFeeSetting, initialized?: boolean): Promise<void>;
|
65
66
|
}
|
66
67
|
export {};
|
67
68
|
//# sourceMappingURL=transactionsManager.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EAEvB,kBAAkB,
|
1
|
+
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":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E,MAAM,EAAE,aAAa,EAAE,eAAe,CAAC,EAAE,kBAAkB;IAgEpG,IAAI,CAAC,KAAK,EAAE,eAAe,EAAE,EAAE,eAAe,CAAC,EAAE,kBAAkB,EAAE,WAAW,CAAC,EAAE,OAAO;CAyGjG"}
|
@@ -11,22 +11,20 @@ const generalUtils_1 = require("../utils/generalUtils");
|
|
11
11
|
const transactionUtils_1 = require("./transactionUtils");
|
12
12
|
// import { sendJitoBundledTransactions } from "../utils/jitoUtils";
|
13
13
|
class LookupTables {
|
14
|
-
constructor(
|
15
|
-
this.
|
16
|
-
this.
|
14
|
+
constructor(defaultLuts, umi) {
|
15
|
+
this.defaultLuts = defaultLuts;
|
16
|
+
this.umi = umi;
|
17
17
|
this.cache = [];
|
18
|
-
this.defaultLuts = [...client.defaultLookupTables()];
|
19
18
|
}
|
20
19
|
async getLutInputs(additionalAddresses) {
|
21
20
|
const addresses = [
|
22
21
|
...this.defaultLuts,
|
23
|
-
this.client.authorityLutAddress.toString(),
|
24
22
|
...additionalAddresses,
|
25
23
|
];
|
26
24
|
const currentCacheAddresses = this.cache.map((x) => x.publicKey.toString());
|
27
25
|
const missingAddresses = addresses.filter((x) => !currentCacheAddresses.includes(x));
|
28
26
|
if (missingAddresses) {
|
29
|
-
const additionalInputs = await (0, solanaUtils_1.getAdressLookupInputs)(this.
|
27
|
+
const additionalInputs = await (0, solanaUtils_1.getAdressLookupInputs)(this.umi, missingAddresses);
|
30
28
|
this.cache.push(...additionalInputs);
|
31
29
|
}
|
32
30
|
return this.cache;
|
@@ -56,8 +54,8 @@ class TransactionItem {
|
|
56
54
|
}
|
57
55
|
exports.TransactionItem = TransactionItem;
|
58
56
|
class TransactionSet {
|
59
|
-
constructor(
|
60
|
-
this.
|
57
|
+
constructor(txHandler, lookupTables, items = []) {
|
58
|
+
this.txHandler = txHandler;
|
61
59
|
this.lookupTables = lookupTables;
|
62
60
|
this.items = items;
|
63
61
|
}
|
@@ -78,13 +76,13 @@ class TransactionSet {
|
|
78
76
|
...this.lutAddresses(),
|
79
77
|
...item.lookupTableAddresses,
|
80
78
|
]))
|
81
|
-
.fitsInOneTransaction(this.
|
79
|
+
.fitsInOneTransaction(this.txHandler.umi);
|
82
80
|
}
|
83
81
|
add(...items) {
|
84
82
|
this.items.push(...items.filter((x) => x.tx && x.tx.getInstructions().length > 0));
|
85
83
|
}
|
86
84
|
async refetchAll(attemptNum) {
|
87
|
-
await this.
|
85
|
+
await this.txHandler.resetLiveTxUpdates();
|
88
86
|
for (const item of this.items) {
|
89
87
|
await item.refetch(attemptNum);
|
90
88
|
}
|
@@ -120,19 +118,18 @@ var TransactionStatus;
|
|
120
118
|
TransactionStatus["Successful"] = "Successful";
|
121
119
|
})(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {}));
|
122
120
|
class TransactionsManager {
|
123
|
-
constructor(
|
124
|
-
this.
|
125
|
-
this.items = items;
|
121
|
+
constructor(txHandler, statusCallback, simulateOnly, mustBeAtomic, errorsToThrow) {
|
122
|
+
this.txHandler = txHandler;
|
126
123
|
this.statusCallback = statusCallback;
|
127
124
|
this.simulateOnly = simulateOnly;
|
128
125
|
this.mustBeAtomic = mustBeAtomic;
|
129
126
|
this.errorsToThrow = errorsToThrow;
|
130
127
|
this.statuses = [];
|
131
|
-
this.lookupTables = new LookupTables(
|
128
|
+
this.lookupTables = new LookupTables(this.txHandler.defaultLookupTables(), this.txHandler.umi);
|
132
129
|
}
|
133
130
|
async assembleTransactionSets(items) {
|
134
131
|
let transactionSets = [];
|
135
|
-
this.
|
132
|
+
this.txHandler.log(`Reassembling ${items.length} items`);
|
136
133
|
for (let i = 0; i < items.length;) {
|
137
134
|
let item = items[i];
|
138
135
|
i++;
|
@@ -140,11 +137,11 @@ class TransactionsManager {
|
|
140
137
|
continue;
|
141
138
|
}
|
142
139
|
const transaction = item.tx.setAddressLookupTables(await this.lookupTables.getLutInputs(item.lookupTableAddresses));
|
143
|
-
if (!transaction.fitsInOneTransaction(this.
|
144
|
-
throw new Error(`Transaction exceeds max transaction size (${transaction.getTransactionSize(this.
|
140
|
+
if (!transaction.fitsInOneTransaction(this.txHandler.umi)) {
|
141
|
+
throw new Error(`Transaction exceeds max transaction size (${transaction.getTransactionSize(this.txHandler.umi)})`);
|
145
142
|
}
|
146
143
|
else {
|
147
|
-
let newSet = new TransactionSet(this.
|
144
|
+
let newSet = new TransactionSet(this.txHandler, this.lookupTables, [item]);
|
148
145
|
for (let j = i; j < items.length; j++) {
|
149
146
|
if (await newSet.fitsWith(items[j])) {
|
150
147
|
newSet.add(items[j]);
|
@@ -173,7 +170,7 @@ class TransactionsManager {
|
|
173
170
|
this.statuses.push({ name, status, txSig });
|
174
171
|
}
|
175
172
|
}
|
176
|
-
this.
|
173
|
+
this.txHandler.log(`${name} is ${status.toString().toLowerCase()}`);
|
177
174
|
this.statusCallback?.(this.statuses);
|
178
175
|
}
|
179
176
|
// TODO remove me
|
@@ -183,28 +180,29 @@ class TransactionsManager {
|
|
183
180
|
for (const ix of tx.getInstructions()) {
|
184
181
|
const ixAccounts = ix.keys.map((x) => x.pubkey);
|
185
182
|
const accountsNotInLut = ixAccounts.filter((x) => !lutAccounts.includes(x));
|
186
|
-
this.
|
183
|
+
this.txHandler.log(`Program ${ix.programId}, data len: ${ix.data.length}, LUT accounts data: ${ix.keys.filter((x) => lutAccounts.includes(x.pubkey)).length * 3}`);
|
187
184
|
if (accountsNotInLut.length > 0) {
|
188
|
-
this.
|
185
|
+
this.txHandler.log(`${accountsNotInLut.length} accounts not in LUT:`);
|
189
186
|
for (const key of accountsNotInLut) {
|
190
|
-
this.
|
187
|
+
this.txHandler.log(key.toString());
|
191
188
|
}
|
192
189
|
}
|
193
190
|
}
|
194
191
|
}
|
195
|
-
async
|
196
|
-
const updateLookupTable = await
|
192
|
+
async sendWithClient(items, client, prioritySetting) {
|
193
|
+
const updateLookupTable = await client.updateLookupTable();
|
197
194
|
if (updateLookupTable &&
|
198
195
|
updateLookupTable.updateLutTx.getInstructions().length > 0 &&
|
199
196
|
updateLookupTable?.needsToBeIsolated) {
|
200
197
|
this.updateStatus("update lookup table", TransactionStatus.Processing);
|
201
|
-
await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.
|
198
|
+
await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, updateLookupTable.updateLutTx, this.simulateOnly, attemptNum), 3, 150, this.errorsToThrow);
|
202
199
|
this.updateStatus("update lookup table", TransactionStatus.Successful);
|
203
200
|
}
|
204
|
-
|
201
|
+
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
202
|
+
for (const item of items) {
|
205
203
|
await item.initialize();
|
206
204
|
}
|
207
|
-
const [choresBefore, choresAfter] = await (0, transactionUtils_1.getTransactionChores)(
|
205
|
+
const [choresBefore, choresAfter] = await (0, transactionUtils_1.getTransactionChores)(client, (0, umi_1.transactionBuilder)().add(items
|
208
206
|
.filter((x) => x.tx && x.tx.getInstructions().length > 0)
|
209
207
|
.map((x) => x.tx)));
|
210
208
|
if (updateLookupTable && !updateLookupTable.needsToBeIsolated) {
|
@@ -213,16 +211,27 @@ class TransactionsManager {
|
|
213
211
|
if (choresBefore.getInstructions().length > 0) {
|
214
212
|
const chore = new TransactionItem(async () => ({ tx: choresBefore }), "create account(s)");
|
215
213
|
await chore.initialize();
|
216
|
-
|
217
|
-
this.
|
214
|
+
items.unshift(chore);
|
215
|
+
this.txHandler.log("Chores before: ", choresBefore.getInstructions().length);
|
218
216
|
}
|
219
217
|
if (choresAfter.getInstructions().length > 0) {
|
220
218
|
const chore = new TransactionItem(async () => ({ tx: choresAfter }));
|
221
219
|
await chore.initialize();
|
222
|
-
|
223
|
-
this.
|
220
|
+
items.push(chore);
|
221
|
+
this.txHandler.log("Chores after: ", choresAfter.getInstructions().length);
|
224
222
|
}
|
225
|
-
|
223
|
+
await this.send(items, prioritySetting, true);
|
224
|
+
if (!this.simulateOnly) {
|
225
|
+
await client.resetLiveTxUpdates();
|
226
|
+
}
|
227
|
+
}
|
228
|
+
async send(items, prioritySetting, initialized) {
|
229
|
+
if (!initialized) {
|
230
|
+
for (const item of items) {
|
231
|
+
await item.initialize();
|
232
|
+
}
|
233
|
+
}
|
234
|
+
const itemSets = await this.assembleTransactionSets(items);
|
226
235
|
const statusesStartIdx = this.statuses.length;
|
227
236
|
for (const itemSet of itemSets) {
|
228
237
|
this.updateStatus(itemSet.name(), TransactionStatus.Queued);
|
@@ -258,7 +267,7 @@ class TransactionsManager {
|
|
258
267
|
name: x.name(),
|
259
268
|
status: TransactionStatus.Queued,
|
260
269
|
})));
|
261
|
-
this.
|
270
|
+
this.txHandler.log(this.statuses);
|
262
271
|
itemSets.splice(i + 1, itemSets.length - i - 1, ...newItemSets.slice(1));
|
263
272
|
}
|
264
273
|
return newItemSets.length > 0 ? newItemSets[0] : undefined;
|
@@ -278,18 +287,15 @@ class TransactionsManager {
|
|
278
287
|
}
|
279
288
|
else {
|
280
289
|
this.updateStatus(itemSet.name(), TransactionStatus.Processing);
|
281
|
-
if (this.
|
290
|
+
if (this.txHandler.localTest) {
|
282
291
|
await this.debugAccounts(itemSet, tx);
|
283
292
|
}
|
284
|
-
const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.
|
293
|
+
const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.txHandler.umi, this.txHandler.connection, tx, this.simulateOnly, attemptNum, prioritySetting);
|
285
294
|
this.updateStatus(itemSet.name(), TransactionStatus.Successful, txSig ? bs58_1.default.encode(txSig) : undefined);
|
286
295
|
}
|
287
296
|
}, 4, 150, this.errorsToThrow);
|
288
297
|
}
|
289
298
|
}
|
290
|
-
if (!this.simulateOnly) {
|
291
|
-
await this.client.resetLivePositionUpdates();
|
292
|
-
}
|
293
299
|
}
|
294
300
|
}
|
295
301
|
exports.TransactionsManager = TransactionsManager;
|
package/package.json
CHANGED
package/src/clients/index.ts
CHANGED
@@ -5,6 +5,7 @@ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
|
5
5
|
import { WalletAdapter, walletAdapterIdentity } from "@metaplex-foundation/umi-signer-wallet-adapters";
|
6
6
|
import { claimReferralFees, createSolautoProgram, ReferralState, safeFetchReferralState, updateReferralStates } from "../generated";
|
7
7
|
import { getReferralState, getSolanaRpcConnection, getTokenAccount } from "../utils";
|
8
|
+
import { TxHandler } from "./txHandler";
|
8
9
|
|
9
10
|
interface ReferralStateManagerArgs {
|
10
11
|
referralAuthority?: PublicKey;
|
@@ -12,7 +13,7 @@ interface ReferralStateManagerArgs {
|
|
12
13
|
wallet?: WalletAdapter;
|
13
14
|
}
|
14
15
|
|
15
|
-
export class ReferralStateManager {
|
16
|
+
export class ReferralStateManager extends TxHandler {
|
16
17
|
public umi!: Umi;
|
17
18
|
public signer!: Signer;
|
18
19
|
|
@@ -20,9 +21,9 @@ export class ReferralStateManager {
|
|
20
21
|
public referralState!: PublicKey;
|
21
22
|
public referralStateData!: ReferralState | null;
|
22
23
|
|
23
|
-
constructor(heliusApiKey: string) {
|
24
|
-
|
25
|
-
this.umi = umi.use({
|
24
|
+
constructor(heliusApiKey: string, public localTest?: boolean) {
|
25
|
+
super(heliusApiKey, localTest)
|
26
|
+
this.umi = this.umi.use({
|
26
27
|
install(umi) {
|
27
28
|
umi.programs.add(createSolautoProgram(), false);
|
28
29
|
},
|
@@ -44,6 +45,10 @@ export class ReferralStateManager {
|
|
44
45
|
this.referralStateData = await safeFetchReferralState(this.umi, publicKey(this.referralState));
|
45
46
|
}
|
46
47
|
|
48
|
+
defaultLookupTables(): string[] {
|
49
|
+
return this.referralStateData?.lookupTable ? [this.referralStateData?.lookupTable.toString()] : [];
|
50
|
+
}
|
51
|
+
|
47
52
|
updateReferralStatesIx(destFeesMint?: PublicKey, referredBy?: PublicKey, lookupTable?: PublicKey): TransactionBuilder {
|
48
53
|
return updateReferralStates(this.umi, {
|
49
54
|
signer: this.signer,
|
@@ -85,4 +90,5 @@ export class ReferralStateManager {
|
|
85
90
|
});
|
86
91
|
}
|
87
92
|
|
93
|
+
async resetLiveTxUpdates(): Promise<void> { }
|
88
94
|
}
|
@@ -52,7 +52,6 @@ import {
|
|
52
52
|
splTokenTransferUmiIx,
|
53
53
|
} from "../utils/solanaUtils";
|
54
54
|
import { FlashLoanDetails } from "../utils/solauto/rebalanceUtils";
|
55
|
-
import { NATIVE_MINT } from "@solana/spl-token";
|
56
55
|
import {
|
57
56
|
MIN_POSITION_STATE_FRESHNESS_SECS,
|
58
57
|
SOLAUTO_LUT,
|
@@ -60,6 +59,7 @@ import {
|
|
60
59
|
import { currentUnixSeconds } from "../utils/generalUtils";
|
61
60
|
import { LivePositionUpdates } from "../utils/solauto/generalUtils";
|
62
61
|
import { ReferralStateManager } from "./referralStateManager";
|
62
|
+
import { TxHandler } from "./txHandler";
|
63
63
|
|
64
64
|
export interface SolautoClientArgs {
|
65
65
|
authority?: PublicKey;
|
@@ -73,10 +73,7 @@ export interface SolautoClientArgs {
|
|
73
73
|
referredByAuthority?: PublicKey;
|
74
74
|
}
|
75
75
|
|
76
|
-
export abstract class SolautoClient {
|
77
|
-
private heliusApiKey!: string;
|
78
|
-
public umi!: Umi;
|
79
|
-
public connection!: Connection;
|
76
|
+
export abstract class SolautoClient extends TxHandler {
|
80
77
|
public lendingPlatform!: LendingPlatform;
|
81
78
|
|
82
79
|
public authority!: PublicKey;
|
@@ -114,10 +111,9 @@ export abstract class SolautoClient {
|
|
114
111
|
heliusApiKey: string,
|
115
112
|
public localTest?: boolean
|
116
113
|
) {
|
117
|
-
|
118
|
-
|
119
|
-
this.
|
120
|
-
this.umi = umi.use({
|
114
|
+
super(heliusApiKey, localTest);
|
115
|
+
|
116
|
+
this.umi = this.umi.use({
|
121
117
|
install(umi) {
|
122
118
|
umi.programs.add(createSolautoProgram(), false);
|
123
119
|
},
|
@@ -231,13 +227,7 @@ export abstract class SolautoClient {
|
|
231
227
|
);
|
232
228
|
}
|
233
229
|
|
234
|
-
|
235
|
-
if (this.localTest) {
|
236
|
-
console.log(...args);
|
237
|
-
}
|
238
|
-
}
|
239
|
-
|
240
|
-
async resetLivePositionUpdates() {
|
230
|
+
async resetLiveTxUpdates() {
|
241
231
|
if (!this.solautoPositionData) {
|
242
232
|
this.solautoPositionData = await safeFetchSolautoPosition(
|
243
233
|
this.umi,
|
@@ -257,8 +247,10 @@ export abstract class SolautoClient {
|
|
257
247
|
this.livePositionUpdates.reset();
|
258
248
|
}
|
259
249
|
|
250
|
+
abstract protocolAccount(): PublicKey;
|
251
|
+
|
260
252
|
defaultLookupTables(): string[] {
|
261
|
-
return [SOLAUTO_LUT];
|
253
|
+
return [SOLAUTO_LUT, ...(this.authorityLutAddress ? [this.authorityLutAddress.toString()] : [])];
|
262
254
|
}
|
263
255
|
|
264
256
|
lutAccountsToAdd(): PublicKey[] {
|
@@ -34,7 +34,6 @@ import {
|
|
34
34
|
import { getMarginfiAccountPDA, getTokenAccount } from "../utils/accountUtils";
|
35
35
|
import { generateRandomU64 } from "../utils/generalUtils";
|
36
36
|
import {
|
37
|
-
Bank,
|
38
37
|
MARGINFI_PROGRAM_ID,
|
39
38
|
MarginfiAccount,
|
40
39
|
lendingAccountBorrow,
|
@@ -194,6 +193,10 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
194
193
|
emptyMarginfiAccounts.length > 0 ? emptyMarginfiAccounts[0] : undefined;
|
195
194
|
}
|
196
195
|
|
196
|
+
protocolAccount(): PublicKey {
|
197
|
+
return this.marginfiAccountPk;
|
198
|
+
}
|
199
|
+
|
197
200
|
defaultLookupTables(): string[] {
|
198
201
|
return [MARGINFI_ACCOUNTS_LOOKUP_TABLE, ...super.defaultLookupTables()];
|
199
202
|
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { Umi } from "@metaplex-foundation/umi";
|
2
|
+
import { Connection } from "@solana/web3.js";
|
3
|
+
import { getSolanaRpcConnection } from "../utils";
|
4
|
+
|
5
|
+
|
6
|
+
export abstract class TxHandler {
|
7
|
+
public heliusApiKey!: string;
|
8
|
+
public umi!: Umi;
|
9
|
+
public connection!: Connection;
|
10
|
+
|
11
|
+
constructor(heliusApiKey: string,
|
12
|
+
public localTest?: boolean) {
|
13
|
+
this.heliusApiKey = heliusApiKey;
|
14
|
+
const [connection, umi] = getSolanaRpcConnection(this.heliusApiKey);
|
15
|
+
this.connection = connection;
|
16
|
+
this.umi = umi;
|
17
|
+
}
|
18
|
+
|
19
|
+
log(...args: any[]): void {
|
20
|
+
if (this.localTest) {
|
21
|
+
console.log(...args);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
abstract defaultLookupTables(): string[];
|
26
|
+
|
27
|
+
abstract resetLiveTxUpdates(): Promise<void>;
|
28
|
+
}
|
@@ -565,10 +565,8 @@ export async function buildSolautoRebalanceTransaction(
|
|
565
565
|
(targetLiqUtilizationRateBps === undefined &&
|
566
566
|
!eligibleForRebalance(
|
567
567
|
client.solautoPositionState!,
|
568
|
-
client.
|
569
|
-
client.
|
570
|
-
client.livePositionUpdates.activeDca ??
|
571
|
-
client.solautoPositionData?.position.dca!,
|
568
|
+
client.solautoPositionSettings()!,
|
569
|
+
client.solautoPositionActiveDca()!,
|
572
570
|
currentUnixSeconds()
|
573
571
|
))
|
574
572
|
) {
|
@@ -3,6 +3,7 @@ import {
|
|
3
3
|
AddressLookupTableInput,
|
4
4
|
transactionBuilder,
|
5
5
|
TransactionBuilder,
|
6
|
+
Umi,
|
6
7
|
} from "@metaplex-foundation/umi";
|
7
8
|
import { SolautoClient } from "../clients/solautoClient";
|
8
9
|
import {
|
@@ -15,14 +16,14 @@ import {
|
|
15
16
|
} from "../utils/generalUtils";
|
16
17
|
import { getTransactionChores } from "./transactionUtils";
|
17
18
|
import { PriorityFeeSetting } from "../types";
|
19
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
20
|
+
import { TxHandler } from "../clients";
|
18
21
|
// import { sendJitoBundledTransactions } from "../utils/jitoUtils";
|
19
22
|
|
20
23
|
class LookupTables {
|
21
|
-
defaultLuts: string[] = [];
|
22
24
|
cache: AddressLookupTableInput[] = [];
|
23
25
|
|
24
|
-
constructor(private
|
25
|
-
this.defaultLuts = [...client.defaultLookupTables()];
|
26
|
+
constructor(public defaultLuts: string[], private umi: Umi) {
|
26
27
|
}
|
27
28
|
|
28
29
|
async getLutInputs(
|
@@ -30,7 +31,6 @@ class LookupTables {
|
|
30
31
|
): Promise<AddressLookupTableInput[]> {
|
31
32
|
const addresses = [
|
32
33
|
...this.defaultLuts,
|
33
|
-
this.client.authorityLutAddress!.toString(),
|
34
34
|
...additionalAddresses,
|
35
35
|
];
|
36
36
|
const currentCacheAddresses = this.cache.map((x) => x.publicKey.toString());
|
@@ -40,7 +40,7 @@ class LookupTables {
|
|
40
40
|
);
|
41
41
|
if (missingAddresses) {
|
42
42
|
const additionalInputs = await getAdressLookupInputs(
|
43
|
-
this.
|
43
|
+
this.umi,
|
44
44
|
missingAddresses
|
45
45
|
);
|
46
46
|
this.cache.push(...additionalInputs);
|
@@ -61,7 +61,7 @@ export class TransactionItem {
|
|
61
61
|
{ tx: TransactionBuilder; lookupTableAddresses?: string[] } | undefined
|
62
62
|
>,
|
63
63
|
public name?: string
|
64
|
-
) {}
|
64
|
+
) { }
|
65
65
|
|
66
66
|
async initialize() {
|
67
67
|
await this.refetch(0);
|
@@ -89,10 +89,10 @@ export class TransactionItem {
|
|
89
89
|
|
90
90
|
class TransactionSet {
|
91
91
|
constructor(
|
92
|
-
private
|
92
|
+
private txHandler: TxHandler,
|
93
93
|
public lookupTables: LookupTables,
|
94
94
|
public items: TransactionItem[] = []
|
95
|
-
) {}
|
95
|
+
) { }
|
96
96
|
|
97
97
|
async fitsWith(item: TransactionItem): Promise<boolean> {
|
98
98
|
if (!item.tx) {
|
@@ -117,7 +117,7 @@ class TransactionSet {
|
|
117
117
|
...item.lookupTableAddresses,
|
118
118
|
])
|
119
119
|
)
|
120
|
-
.fitsInOneTransaction(this.
|
120
|
+
.fitsInOneTransaction(this.txHandler.umi);
|
121
121
|
}
|
122
122
|
|
123
123
|
add(...items: TransactionItem[]) {
|
@@ -127,7 +127,7 @@ class TransactionSet {
|
|
127
127
|
}
|
128
128
|
|
129
129
|
async refetchAll(attemptNum: number) {
|
130
|
-
await this.
|
130
|
+
await this.txHandler.resetLiveTxUpdates();
|
131
131
|
for (const item of this.items) {
|
132
132
|
await item.refetch(attemptNum);
|
133
133
|
}
|
@@ -183,23 +183,22 @@ export class TransactionsManager {
|
|
183
183
|
private lookupTables: LookupTables;
|
184
184
|
|
185
185
|
constructor(
|
186
|
-
private
|
187
|
-
private items: TransactionItem[],
|
186
|
+
private txHandler: TxHandler,
|
188
187
|
private statusCallback?: (statuses: TransactionManagerStatuses) => void,
|
189
188
|
private simulateOnly?: boolean,
|
190
189
|
private mustBeAtomic?: boolean,
|
191
190
|
private errorsToThrow?: ErrorsToThrow
|
192
191
|
) {
|
193
|
-
this.lookupTables = new LookupTables(
|
192
|
+
this.lookupTables = new LookupTables(this.txHandler.defaultLookupTables(), this.txHandler.umi);
|
194
193
|
}
|
195
194
|
|
196
195
|
private async assembleTransactionSets(
|
197
196
|
items: TransactionItem[]
|
198
197
|
): Promise<TransactionSet[]> {
|
199
198
|
let transactionSets: TransactionSet[] = [];
|
200
|
-
this.
|
199
|
+
this.txHandler.log(`Reassembling ${items.length} items`);
|
201
200
|
|
202
|
-
for (let i = 0; i < items.length;
|
201
|
+
for (let i = 0; i < items.length;) {
|
203
202
|
let item = items[i];
|
204
203
|
i++;
|
205
204
|
|
@@ -210,12 +209,12 @@ export class TransactionsManager {
|
|
210
209
|
const transaction = item.tx.setAddressLookupTables(
|
211
210
|
await this.lookupTables.getLutInputs(item.lookupTableAddresses)
|
212
211
|
);
|
213
|
-
if (!transaction.fitsInOneTransaction(this.
|
212
|
+
if (!transaction.fitsInOneTransaction(this.txHandler.umi)) {
|
214
213
|
throw new Error(
|
215
|
-
`Transaction exceeds max transaction size (${transaction.getTransactionSize(this.
|
214
|
+
`Transaction exceeds max transaction size (${transaction.getTransactionSize(this.txHandler.umi)})`
|
216
215
|
);
|
217
216
|
} else {
|
218
|
-
let newSet = new TransactionSet(this.
|
217
|
+
let newSet = new TransactionSet(this.txHandler, this.lookupTables, [item]);
|
219
218
|
for (let j = i; j < items.length; j++) {
|
220
219
|
if (await newSet.fitsWith(items[j])) {
|
221
220
|
newSet.add(items[j]);
|
@@ -243,7 +242,7 @@ export class TransactionsManager {
|
|
243
242
|
this.statuses.push({ name, status, txSig });
|
244
243
|
}
|
245
244
|
}
|
246
|
-
this.
|
245
|
+
this.txHandler.log(`${name} is ${status.toString().toLowerCase()}`);
|
247
246
|
this.statusCallback?.(this.statuses);
|
248
247
|
}
|
249
248
|
|
@@ -256,18 +255,18 @@ export class TransactionsManager {
|
|
256
255
|
const accountsNotInLut = ixAccounts.filter(
|
257
256
|
(x) => !lutAccounts.includes(x)
|
258
257
|
);
|
259
|
-
this.
|
258
|
+
this.txHandler.log(`Program ${ix.programId}, data len: ${ix.data.length}, LUT accounts data: ${ix.keys.filter((x) => lutAccounts.includes(x.pubkey)).length * 3}`);
|
260
259
|
if (accountsNotInLut.length > 0) {
|
261
|
-
this.
|
260
|
+
this.txHandler.log(`${accountsNotInLut.length} accounts not in LUT:`);
|
262
261
|
for (const key of accountsNotInLut) {
|
263
|
-
this.
|
262
|
+
this.txHandler.log(key.toString());
|
264
263
|
}
|
265
264
|
}
|
266
265
|
}
|
267
266
|
}
|
268
267
|
|
269
|
-
async
|
270
|
-
const updateLookupTable = await
|
268
|
+
async sendWithClient(items: TransactionItem[], client: SolautoClient, prioritySetting?: PriorityFeeSetting) {
|
269
|
+
const updateLookupTable = await client.updateLookupTable();
|
271
270
|
if (
|
272
271
|
updateLookupTable &&
|
273
272
|
updateLookupTable.updateLutTx.getInstructions().length > 0 &&
|
@@ -277,8 +276,8 @@ export class TransactionsManager {
|
|
277
276
|
await retryWithExponentialBackoff(
|
278
277
|
async (attemptNum) =>
|
279
278
|
await sendSingleOptimizedTransaction(
|
280
|
-
this.
|
281
|
-
this.
|
279
|
+
this.txHandler.umi,
|
280
|
+
this.txHandler.connection,
|
282
281
|
updateLookupTable.updateLutTx,
|
283
282
|
this.simulateOnly,
|
284
283
|
attemptNum
|
@@ -290,14 +289,16 @@ export class TransactionsManager {
|
|
290
289
|
this.updateStatus("update lookup table", TransactionStatus.Successful);
|
291
290
|
}
|
292
291
|
|
293
|
-
|
292
|
+
this.lookupTables.defaultLuts = client.defaultLookupTables();
|
293
|
+
|
294
|
+
for (const item of items) {
|
294
295
|
await item.initialize();
|
295
296
|
}
|
296
297
|
|
297
298
|
const [choresBefore, choresAfter] = await getTransactionChores(
|
298
|
-
|
299
|
+
client,
|
299
300
|
transactionBuilder().add(
|
300
|
-
|
301
|
+
items
|
301
302
|
.filter((x) => x.tx && x.tx.getInstructions().length > 0)
|
302
303
|
.map((x) => x.tx!)
|
303
304
|
)
|
@@ -311,17 +312,31 @@ export class TransactionsManager {
|
|
311
312
|
"create account(s)"
|
312
313
|
);
|
313
314
|
await chore.initialize();
|
314
|
-
|
315
|
-
this.
|
315
|
+
items.unshift(chore);
|
316
|
+
this.txHandler.log("Chores before: ", choresBefore.getInstructions().length);
|
316
317
|
}
|
317
318
|
if (choresAfter.getInstructions().length > 0) {
|
318
319
|
const chore = new TransactionItem(async () => ({ tx: choresAfter }));
|
319
320
|
await chore.initialize();
|
320
|
-
|
321
|
-
this.
|
321
|
+
items.push(chore);
|
322
|
+
this.txHandler.log("Chores after: ", choresAfter.getInstructions().length);
|
322
323
|
}
|
323
324
|
|
324
|
-
|
325
|
+
await this.send(items, prioritySetting, true);
|
326
|
+
|
327
|
+
if (!this.simulateOnly) {
|
328
|
+
await client.resetLiveTxUpdates();
|
329
|
+
}
|
330
|
+
}
|
331
|
+
|
332
|
+
async send(items: TransactionItem[], prioritySetting?: PriorityFeeSetting, initialized?: boolean) {
|
333
|
+
if (!initialized) {
|
334
|
+
for (const item of items) {
|
335
|
+
await item.initialize();
|
336
|
+
}
|
337
|
+
}
|
338
|
+
|
339
|
+
const itemSets = await this.assembleTransactionSets(items);
|
325
340
|
const statusesStartIdx = this.statuses.length;
|
326
341
|
for (const itemSet of itemSets) {
|
327
342
|
this.updateStatus(itemSet.name(), TransactionStatus.Queued);
|
@@ -366,7 +381,7 @@ export class TransactionsManager {
|
|
366
381
|
status: TransactionStatus.Queued,
|
367
382
|
}))
|
368
383
|
);
|
369
|
-
this.
|
384
|
+
this.txHandler.log(this.statuses);
|
370
385
|
itemSets.splice(
|
371
386
|
i + 1,
|
372
387
|
itemSets.length - i - 1,
|
@@ -393,13 +408,13 @@ export class TransactionsManager {
|
|
393
408
|
} else {
|
394
409
|
this.updateStatus(itemSet.name(), TransactionStatus.Processing);
|
395
410
|
|
396
|
-
if (this.
|
411
|
+
if (this.txHandler.localTest) {
|
397
412
|
await this.debugAccounts(itemSet, tx);
|
398
413
|
}
|
399
414
|
|
400
415
|
const txSig = await sendSingleOptimizedTransaction(
|
401
|
-
this.
|
402
|
-
this.
|
416
|
+
this.txHandler.umi,
|
417
|
+
this.txHandler.connection,
|
403
418
|
tx,
|
404
419
|
this.simulateOnly,
|
405
420
|
attemptNum,
|
@@ -418,9 +433,5 @@ export class TransactionsManager {
|
|
418
433
|
);
|
419
434
|
}
|
420
435
|
}
|
421
|
-
|
422
|
-
if (!this.simulateOnly) {
|
423
|
-
await this.client.resetLivePositionUpdates();
|
424
|
-
}
|
425
436
|
}
|
426
437
|
}
|
@@ -66,19 +66,19 @@ describe("Solauto Marginfi tests", async () => {
|
|
66
66
|
// }, "open position")
|
67
67
|
// );
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
69
|
+
// const initialSupplyUsd = 150;
|
70
|
+
// transactionItems.push(
|
71
|
+
// new TransactionItem(async () => {
|
72
|
+
// const [supplyPrice] = await getTokenPrices([supply]);
|
73
|
+
// return {
|
74
|
+
// tx: client.protocolInteraction(
|
75
|
+
// solautoAction("Deposit", [
|
76
|
+
// toBaseUnit(initialSupplyUsd / supplyPrice, supplyDecimals),
|
77
|
+
// ])
|
78
|
+
// ),
|
79
|
+
// };
|
80
|
+
// }, "deposit")
|
81
|
+
// );
|
82
82
|
// }
|
83
83
|
|
84
84
|
// const maxLtvBps = client.solautoPositionState!.maxLtvBps;
|
@@ -118,7 +118,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
118
118
|
// };
|
119
119
|
// }, "deposit")
|
120
120
|
// );
|
121
|
-
|
121
|
+
|
122
122
|
transactionItems.push(
|
123
123
|
new TransactionItem(
|
124
124
|
async (attemptNum) =>
|
@@ -156,10 +156,9 @@ describe("Solauto Marginfi tests", async () => {
|
|
156
156
|
|
157
157
|
await new TransactionsManager(
|
158
158
|
client,
|
159
|
-
transactionItems,
|
160
159
|
undefined,
|
161
160
|
!payForTransactions,
|
162
161
|
useJitoBundle
|
163
|
-
).
|
162
|
+
).sendWithClient(transactionItems, client);
|
164
163
|
});
|
165
164
|
});
|