@haven-fi/solauto-sdk 1.0.208 → 1.0.210
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/referralStateManager.d.ts +4 -0
- package/dist/clients/referralStateManager.d.ts.map +1 -1
- package/dist/clients/referralStateManager.js +27 -8
- package/dist/clients/solautoClient.d.ts +0 -2
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +10 -19
- package/dist/clients/solautoMarginfiClient.js +2 -2
- package/dist/clients/txHandler.d.ts +2 -1
- package/dist/clients/txHandler.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.d.ts +3 -5
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +4 -4
- package/dist/transactions/transactionsManager.d.ts +3 -9
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/types/solauto.d.ts +5 -0
- package/dist/types/solauto.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/clients/referralStateManager.ts +134 -74
- package/src/clients/solautoClient.ts +17 -30
- package/src/clients/solautoMarginfiClient.ts +2 -2
- package/src/clients/txHandler.ts +3 -1
- package/src/transactions/transactionUtils.ts +12 -13
- package/src/transactions/transactionsManager.ts +7 -9
- package/src/types/solauto.ts +8 -2
@@ -7,6 +7,7 @@ interface ReferralStateManagerArgs {
|
|
7
7
|
signer?: Signer;
|
8
8
|
wallet?: WalletAdapter;
|
9
9
|
referralAuthority?: PublicKey;
|
10
|
+
referredByAuthority?: PublicKey;
|
10
11
|
}
|
11
12
|
export declare class ReferralStateManager extends TxHandler {
|
12
13
|
localTest?: boolean | undefined;
|
@@ -15,9 +16,12 @@ export declare class ReferralStateManager extends TxHandler {
|
|
15
16
|
referralAuthority: PublicKey;
|
16
17
|
referralState: PublicKey;
|
17
18
|
referralStateData: ReferralState | null;
|
19
|
+
referredByAuthority?: PublicKey;
|
20
|
+
referredByState?: PublicKey;
|
18
21
|
constructor(heliusApiUrl: string, localTest?: boolean | undefined);
|
19
22
|
initialize(args: ReferralStateManagerArgs): Promise<void>;
|
20
23
|
defaultLookupTables(): string[];
|
24
|
+
setReferredBy(referredBy?: PublicKey): void;
|
21
25
|
updateReferralStatesIx(destFeesMint?: PublicKey, referredBy?: PublicKey, lookupTable?: PublicKey): TransactionBuilder;
|
22
26
|
claimReferralFeesIx(destFeesMint?: PublicKey): TransactionBuilder;
|
23
27
|
resetLiveTxUpdates(success?: boolean): Promise<void>;
|
@@ -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,
|
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,EAEL,MAAM,EAEN,kBAAkB,EAClB,GAAG,EACJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EAGL,aAAa,EAGd,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,UAAU,wBAAwB;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAC9B,mBAAmB,CAAC,EAAE,SAAS,CAAC;CACjC;AAED,qBAAa,oBAAqB,SAAQ,SAAS;IAaxC,SAAS,CAAC,EAAE,OAAO;IAZrB,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;IAEzC,mBAAmB,CAAC,EAAE,SAAS,CAAC;IAChC,eAAe,CAAC,EAAE,SAAS,CAAC;gBAGjC,YAAY,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,OAAO,YAAA;IAUtB,UAAU,CAAC,IAAI,EAAE,wBAAwB;IAuB/C,mBAAmB,IAAI,MAAM,EAAE;IAMxB,aAAa,CAAC,UAAU,CAAC,EAAE,SAAS;IAoB3C,sBAAsB,CACpB,YAAY,CAAC,EAAE,SAAS,EACxB,UAAU,CAAC,EAAE,SAAS,EACtB,WAAW,CAAC,EAAE,SAAS,GACtB,kBAAkB;IAerB,mBAAmB,CAAC,YAAY,CAAC,EAAE,SAAS,GAAG,kBAAkB;IA8B3D,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAC3D"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.ReferralStateManager = void 0;
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
4
5
|
const spl_token_1 = require("@solana/spl-token");
|
5
6
|
const umi_1 = require("@metaplex-foundation/umi");
|
6
7
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
@@ -28,9 +29,29 @@ class ReferralStateManager extends txHandler_1.TxHandler {
|
|
28
29
|
this.signer = this.umi.identity;
|
29
30
|
this.referralState = (0, utils_1.getReferralState)(args.referralAuthority ?? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey));
|
30
31
|
this.referralStateData = await (0, generated_1.safeFetchReferralState)(this.umi, (0, umi_1.publicKey)(this.referralState), { commitment: "confirmed" });
|
32
|
+
this.setReferredBy(args.referredByAuthority);
|
31
33
|
}
|
32
34
|
defaultLookupTables() {
|
33
|
-
return this.referralStateData?.lookupTable
|
35
|
+
return this.referralStateData?.lookupTable
|
36
|
+
? [this.referralStateData?.lookupTable.toString()]
|
37
|
+
: [];
|
38
|
+
}
|
39
|
+
setReferredBy(referredBy) {
|
40
|
+
const authorityReferralStateData = this.referralStateData;
|
41
|
+
const hasReferredBy = authorityReferralStateData &&
|
42
|
+
authorityReferralStateData.referredByState !==
|
43
|
+
(0, umi_1.publicKey)(web3_js_1.PublicKey.default);
|
44
|
+
const referredByAuthority = !hasReferredBy &&
|
45
|
+
referredBy &&
|
46
|
+
!referredBy.equals((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey))
|
47
|
+
? referredBy
|
48
|
+
: undefined;
|
49
|
+
this.referredByState = hasReferredBy
|
50
|
+
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(authorityReferralStateData.referredByState)
|
51
|
+
: referredByAuthority
|
52
|
+
? (0, utils_1.getReferralState)(referredByAuthority)
|
53
|
+
: undefined;
|
54
|
+
this.referredByAuthority = referredByAuthority;
|
34
55
|
}
|
35
56
|
updateReferralStatesIx(destFeesMint, referredBy, lookupTable) {
|
36
57
|
return (0, generated_1.updateReferralStates)(this.umi, {
|
@@ -39,13 +60,11 @@ class ReferralStateManager extends txHandler_1.TxHandler {
|
|
39
60
|
referralFeesDestMint: destFeesMint ? (0, umi_1.publicKey)(destFeesMint) : null,
|
40
61
|
referredByState: referredBy
|
41
62
|
? (0, umi_1.publicKey)((0, utils_1.getReferralState)(referredBy))
|
42
|
-
:
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
addressLookupTable: lookupTable
|
47
|
-
? (0, umi_1.publicKey)(lookupTable)
|
48
|
-
: null,
|
63
|
+
: this.referredByState
|
64
|
+
? (0, umi_1.publicKey)(this.referredByState)
|
65
|
+
: undefined,
|
66
|
+
referredByAuthority: referredBy ? (0, umi_1.publicKey)(referredBy) : undefined,
|
67
|
+
addressLookupTable: lookupTable ? (0, umi_1.publicKey)(lookupTable) : null,
|
49
68
|
});
|
50
69
|
}
|
51
70
|
claimReferralFeesIx(destFeesMint) {
|
@@ -36,8 +36,6 @@ export declare abstract class SolautoClient extends TxHandler {
|
|
36
36
|
positionDebtTa: PublicKey;
|
37
37
|
signerDebtTa: PublicKey;
|
38
38
|
referralStateManager: ReferralStateManager;
|
39
|
-
referredByState?: PublicKey;
|
40
|
-
referredByAuthority?: PublicKey;
|
41
39
|
referredBySupplyTa?: PublicKey;
|
42
40
|
solautoFeesWallet: PublicKey;
|
43
41
|
solautoFeesSupplyTa: PublicKey;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAA6B,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EACL,MAAM,EACN,kBAAkB,EAOnB,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,EAEhC,sBAAsB,EAMvB,MAAM,cAAc,CAAC;AAWtB,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;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IAEvB,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;IAErB,mBAAm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,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAalE"}
|
@@ -38,7 +38,9 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
38
38
|
this.selfManaged = this.positionId === 0;
|
39
39
|
this.lendingPlatform = lendingPlatform;
|
40
40
|
this.solautoPosition = (0, accountUtils_1.getSolautoPositionAccount)(this.authority, this.positionId);
|
41
|
-
this.solautoPositionData = !args.new
|
41
|
+
this.solautoPositionData = !args.new
|
42
|
+
? await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition), { commitment: "confirmed" })
|
43
|
+
: null;
|
42
44
|
this.solautoPositionState = this.solautoPositionData?.state;
|
43
45
|
this.maxLtvBps = undefined;
|
44
46
|
this.liqThresholdBps = undefined;
|
@@ -59,10 +61,13 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
59
61
|
this.referralStateManager = new referralStateManager_1.ReferralStateManager(this.rpcUrl);
|
60
62
|
await this.referralStateManager.initialize({
|
61
63
|
referralAuthority: this.authority,
|
64
|
+
referredByAuthority: args.referredByAuthority,
|
62
65
|
signer: args.signer,
|
63
66
|
wallet: args.wallet,
|
64
67
|
});
|
65
|
-
this.
|
68
|
+
if (this.referralStateManager.referredByState !== undefined) {
|
69
|
+
this.referredBySupplyTa = (0, accountUtils_1.getTokenAccount)(this.referralStateManager.referredByState, this.supplyMint);
|
70
|
+
}
|
66
71
|
this.solautoFeesWallet = generalAccounts_1.SOLAUTO_FEES_WALLET;
|
67
72
|
this.solautoFeesSupplyTa = (0, accountUtils_1.getTokenAccount)(this.solautoFeesWallet, this.supplyMint);
|
68
73
|
const authorityReferralStateData = this.referralStateManager.referralStateData;
|
@@ -79,23 +84,9 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
79
84
|
: undefined);
|
80
85
|
}
|
81
86
|
setReferredBy(referredBy) {
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
(0, umi_1.publicKey)(web3_js_1.PublicKey.default);
|
86
|
-
const referredByAuthority = !hasReferredBy &&
|
87
|
-
referredBy &&
|
88
|
-
!referredBy.equals((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey))
|
89
|
-
? referredBy
|
90
|
-
: undefined;
|
91
|
-
this.referredByState = hasReferredBy
|
92
|
-
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(authorityReferralStateData.referredByState)
|
93
|
-
: referredByAuthority
|
94
|
-
? (0, accountUtils_1.getReferralState)(referredByAuthority)
|
95
|
-
: undefined;
|
96
|
-
this.referredByAuthority = referredByAuthority;
|
97
|
-
if (this.referredByState !== undefined) {
|
98
|
-
this.referredBySupplyTa = (0, accountUtils_1.getTokenAccount)(this.referredByState, this.supplyMint);
|
87
|
+
this.referralStateManager.setReferredBy(referredBy);
|
88
|
+
if (this.referralStateManager.referredByState !== undefined) {
|
89
|
+
this.referredBySupplyTa = (0, accountUtils_1.getTokenAccount)(this.referralStateManager.referredByState, this.supplyMint);
|
99
90
|
}
|
100
91
|
}
|
101
92
|
async resetLiveTxUpdates(success) {
|
@@ -136,8 +136,8 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
136
136
|
signer: this.signer,
|
137
137
|
marginfiProgram: (0, umi_1.publicKey)(marginfi_sdk_1.MARGINFI_PROGRAM_ID),
|
138
138
|
signerReferralState: (0, umi_1.publicKey)(this.referralStateManager.referralState),
|
139
|
-
referredByState: this.referredByState
|
140
|
-
? (0, umi_1.publicKey)(this.referredByState)
|
139
|
+
referredByState: this.referralStateManager.referredByState
|
140
|
+
? (0, umi_1.publicKey)(this.referralStateManager.referredByState)
|
141
141
|
: undefined,
|
142
142
|
referredBySupplyTa: this.referredBySupplyTa
|
143
143
|
? (0, umi_1.publicKey)(this.referredBySupplyTa)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Umi } from "@metaplex-foundation/umi";
|
2
|
-
import { Connection } from "@solana/web3.js";
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
3
3
|
export declare abstract class TxHandler {
|
4
4
|
rpcUrl: string;
|
5
5
|
umi: Umi;
|
@@ -8,5 +8,6 @@ export declare abstract class TxHandler {
|
|
8
8
|
log(...args: any[]): void;
|
9
9
|
abstract defaultLookupTables(): string[];
|
10
10
|
abstract resetLiveTxUpdates(success?: boolean): Promise<void>;
|
11
|
+
abstract setReferredBy(referredBy?: PublicKey): void;
|
11
12
|
}
|
12
13
|
//# sourceMappingURL=txHandler.d.ts.map
|
@@ -1 +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;
|
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,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGxD,8BAAsB,SAAS;IACtB,MAAM,EAAG,MAAM,CAAC;IAChB,GAAG,EAAG,GAAG,CAAC;IACV,UAAU,EAAG,UAAU,CAAC;gBAG7B,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,OAAO;IAYrB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAIzB,QAAQ,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAExC,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAE7D,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,SAAS,GAAG,IAAI;CACrD"}
|
@@ -2,14 +2,12 @@ import { TransactionBuilder } from "@metaplex-foundation/umi";
|
|
2
2
|
import { PublicKey } from "@solana/web3.js";
|
3
3
|
import { SolautoClient } from "../clients/solautoClient";
|
4
4
|
import { ReferralStateManager } from "../clients";
|
5
|
+
import { TransactionItemInputs } from "../types";
|
5
6
|
export declare function rebalanceChoresBefore(client: SolautoClient, tx: TransactionBuilder, accountsGettingCreated: string[]): Promise<TransactionBuilder>;
|
6
7
|
export declare function getTransactionChores(client: SolautoClient, tx: TransactionBuilder): Promise<[TransactionBuilder, TransactionBuilder]>;
|
7
8
|
export declare function requiresRefreshBeforeRebalance(client: SolautoClient): Promise<boolean>;
|
8
|
-
export declare function buildSolautoRebalanceTransaction(client: SolautoClient, targetLiqUtilizationRateBps?: number, attemptNum?: number): Promise<
|
9
|
-
|
10
|
-
lookupTableAddresses: string[];
|
11
|
-
} | undefined>;
|
12
|
-
export declare function convertReferralFeesToDestination(referralManager: ReferralStateManager, tokenAccount: PublicKey, destinationMint: PublicKey): Promise<[TransactionBuilder, string[]] | undefined>;
|
9
|
+
export declare function buildSolautoRebalanceTransaction(client: SolautoClient, targetLiqUtilizationRateBps?: number, attemptNum?: number): Promise<TransactionItemInputs | undefined>;
|
10
|
+
export declare function convertReferralFeesToDestination(referralManager: ReferralStateManager, tokenAccount: PublicKey, destinationMint: PublicKey): Promise<TransactionItemInputs | undefined>;
|
13
11
|
export declare function getErrorInfo(tx: TransactionBuilder, error: any): {
|
14
12
|
errorName: string | undefined;
|
15
13
|
errorInfo: undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAInB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAInB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAuBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqCzD,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAO7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA0LjD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA+G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAsB,8BAA8B,CAAC,MAAM,EAAE,aAAa,oBAwCzE;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAkH5C;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsC5C;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG;;;;EAwC9D"}
|
@@ -52,13 +52,13 @@ function getWSolUsage(client, solautoActions, initiatingDcaIn, cancellingDcaIn)
|
|
52
52
|
async function transactionChoresBefore(client, accountsGettingCreated, solautoActions, initiatingDcaIn) {
|
53
53
|
let chores = (0, umi_1.transactionBuilder)();
|
54
54
|
if (client.referralStateManager.referralStateData === null ||
|
55
|
-
(client.referredByState !== undefined &&
|
55
|
+
(client.referralStateManager.referredByState !== undefined &&
|
56
56
|
client.referralStateManager.referralStateData?.referredByState ===
|
57
57
|
(0, umi_1.publicKey)(web3_js_1.PublicKey.default)) ||
|
58
58
|
(client.authorityLutAddress !== undefined &&
|
59
59
|
client.referralStateManager.referralStateData.lookupTable ==
|
60
60
|
(0, umi_1.publicKey)(web3_js_1.PublicKey.default))) {
|
61
|
-
chores = chores.add(client.referralStateManager.updateReferralStatesIx(undefined, client.referredByAuthority, client.authorityLutAddress));
|
61
|
+
chores = chores.add(client.referralStateManager.updateReferralStatesIx(undefined, client.referralStateManager.referredByAuthority, client.authorityLutAddress));
|
62
62
|
}
|
63
63
|
if (client.selfManaged) {
|
64
64
|
if (client.solautoPositionData === null) {
|
@@ -148,7 +148,7 @@ async function rebalanceChoresBefore(client, tx, accountsGettingCreated) {
|
|
148
148
|
let chores = (0, umi_1.transactionBuilder)();
|
149
149
|
if (checkReferralSupplyTa && !(0, generalUtils_1.rpcAccountCreated)(referredBySupplyTa)) {
|
150
150
|
client.log("Creating referred-by TA for ", client.supplyMint.toString());
|
151
|
-
chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.referredByState, client.supplyMint));
|
151
|
+
chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.referralStateManager.referredByState, client.supplyMint));
|
152
152
|
}
|
153
153
|
if (checkSolautoFeesTa && !(0, generalUtils_1.rpcAccountCreated)(solautoFeesSupplyTa)) {
|
154
154
|
client.log("Creating Solauto fees TA for ", client.supplyMint.toString());
|
@@ -423,7 +423,7 @@ async function convertReferralFeesToDestination(referralManager, tokenAccount, d
|
|
423
423
|
referralFeesTa: (0, umi_1.publicKey)(tokenAccount),
|
424
424
|
}))
|
425
425
|
.add(swapIx);
|
426
|
-
return
|
426
|
+
return { tx, lookupTableAddresses };
|
427
427
|
}
|
428
428
|
function getErrorInfo(tx, error) {
|
429
429
|
let canBeIgnored = false;
|
@@ -1,20 +1,14 @@
|
|
1
1
|
import { TransactionBuilder } from "@metaplex-foundation/umi";
|
2
2
|
import { SolautoClient } from "../clients/solautoClient";
|
3
3
|
import { ErrorsToThrow } from "../utils/generalUtils";
|
4
|
-
import { PriorityFeeSetting, TransactionRunType } from "../types";
|
4
|
+
import { PriorityFeeSetting, TransactionItemInputs, TransactionRunType } from "../types";
|
5
5
|
import { ReferralStateManager } from "../clients";
|
6
6
|
export declare class TransactionItem {
|
7
|
-
fetchTx: (attemptNum: number) => Promise<
|
8
|
-
tx: TransactionBuilder;
|
9
|
-
lookupTableAddresses?: string[];
|
10
|
-
} | undefined>;
|
7
|
+
fetchTx: (attemptNum: number) => Promise<TransactionItemInputs | undefined>;
|
11
8
|
name?: string | undefined;
|
12
9
|
lookupTableAddresses: string[];
|
13
10
|
tx?: TransactionBuilder;
|
14
|
-
constructor(fetchTx: (attemptNum: number) => Promise<
|
15
|
-
tx: TransactionBuilder;
|
16
|
-
lookupTableAddresses?: string[];
|
17
|
-
} | undefined>, name?: string | undefined);
|
11
|
+
constructor(fetchTx: (attemptNum: number) => Promise<TransactionItemInputs | undefined>, name?: string | undefined);
|
18
12
|
initialize(): Promise<void>;
|
19
13
|
refetch(attemptNum: number): Promise<void>;
|
20
14
|
uniqueAccounts(): string[];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;
|
1
|
+
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OA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,aAAa,CAAC;IACtB,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,UAAU;IAVpB,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,YAAY,CAAe;gBAGzB,SAAS,EAAE,aAAa,GAAG,oBAAoB,EAC/C,cAAc,CAAC,GAAE,CAAC,QAAQ,EAAE,0BAA0B,KAAK,IAAI,aAAA,EAC/D,MAAM,CAAC,EAAE,kBAAkB,YAAA,EAC3B,YAAY,CAAC,EAAE,OAAO,YAAA,EACtB,aAAa,CAAC,EAAE,aAAa,YAAA,EAC7B,OAAO,GAAE,MAAU,EACnB,UAAU,GAAE,MAAY;YAQpB,uBAAuB;IAwCrC,OAAO,CAAC,YAAY;YA8CN,aAAa;IAoBd,UAAU,CACrB,YAAY,EAAE,eAAe,EAAE,EAC/B,eAAe,CAAC,EAAE,kBAAkB,GACnC,OAAO,CAAC,0BAA0B,CAAC;IAyEzB,IAAI,CACf,KAAK,EAAE,eAAe,EAAE,EACxB,eAAe,CAAC,EAAE,kBAAkB,EACpC,WAAW,CAAC,EAAE,OAAO,GACpB,OAAO,CAAC,0BAA0B,CAAC;YAwGxB,eAAe;CAoD9B"}
|
package/dist/types/solauto.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { LendingPlatform, PositionType } from "../generated";
|
3
|
+
import { TransactionBuilder } from "@metaplex-foundation/umi";
|
3
4
|
export interface SolautoPositionDetails {
|
4
5
|
publicKey?: PublicKey;
|
5
6
|
authority: PublicKey;
|
@@ -16,4 +17,8 @@ export declare enum PriorityFeeSetting {
|
|
16
17
|
}
|
17
18
|
export type RebalanceAction = "boost" | "repay" | "dca";
|
18
19
|
export type TransactionRunType = "skip-simulation" | "only-simulate" | "normal";
|
20
|
+
export interface TransactionItemInputs {
|
21
|
+
tx: TransactionBuilder;
|
22
|
+
lookupTableAddresses?: string[];
|
23
|
+
}
|
19
24
|
//# sourceMappingURL=solauto.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;
|
1
|
+
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,WAAW,sBAAsB;IACrC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,oBAAY,kBAAkB;IAC5B,OAAO,WAAW;IAClB,IAAI,SAAS;CACd;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;AAExD,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,GAAG,eAAe,GAAG,QAAQ,CAAC;AAEhF,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;CACjC"}
|
package/package.json
CHANGED
@@ -1,94 +1,154 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { NATIVE_MINT } from "@solana/spl-token";
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
publicKey,
|
5
|
+
Signer,
|
6
|
+
signerIdentity,
|
7
|
+
TransactionBuilder,
|
8
|
+
Umi,
|
9
|
+
} from "@metaplex-foundation/umi";
|
4
10
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
5
|
-
import {
|
6
|
-
|
11
|
+
import {
|
12
|
+
WalletAdapter,
|
13
|
+
walletAdapterIdentity,
|
14
|
+
} from "@metaplex-foundation/umi-signer-wallet-adapters";
|
15
|
+
import {
|
16
|
+
claimReferralFees,
|
17
|
+
createSolautoProgram,
|
18
|
+
ReferralState,
|
19
|
+
safeFetchReferralState,
|
20
|
+
updateReferralStates,
|
21
|
+
} from "../generated";
|
7
22
|
import { getReferralState, getTokenAccount } from "../utils";
|
8
23
|
import { TxHandler } from "./txHandler";
|
9
24
|
|
10
25
|
interface ReferralStateManagerArgs {
|
11
|
-
|
12
|
-
|
13
|
-
|
26
|
+
signer?: Signer;
|
27
|
+
wallet?: WalletAdapter;
|
28
|
+
referralAuthority?: PublicKey;
|
29
|
+
referredByAuthority?: PublicKey;
|
14
30
|
}
|
15
31
|
|
16
32
|
export class ReferralStateManager extends TxHandler {
|
17
|
-
|
18
|
-
|
33
|
+
public umi!: Umi;
|
34
|
+
public signer!: Signer;
|
19
35
|
|
20
|
-
|
21
|
-
|
22
|
-
|
36
|
+
public referralAuthority!: PublicKey;
|
37
|
+
public referralState!: PublicKey;
|
38
|
+
public referralStateData!: ReferralState | null;
|
23
39
|
|
24
|
-
|
25
|
-
|
26
|
-
this.umi = this.umi.use({
|
27
|
-
install(umi) {
|
28
|
-
umi.programs.add(createSolautoProgram(), false);
|
29
|
-
},
|
30
|
-
});
|
31
|
-
}
|
40
|
+
public referredByAuthority?: PublicKey;
|
41
|
+
public referredByState?: PublicKey;
|
32
42
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
43
|
+
constructor(
|
44
|
+
heliusApiUrl: string,
|
45
|
+
public localTest?: boolean
|
46
|
+
) {
|
47
|
+
super(heliusApiUrl, localTest);
|
48
|
+
this.umi = this.umi.use({
|
49
|
+
install(umi) {
|
50
|
+
umi.programs.add(createSolautoProgram(), false);
|
51
|
+
},
|
52
|
+
});
|
53
|
+
}
|
42
54
|
|
43
|
-
|
44
|
-
|
45
|
-
|
55
|
+
async initialize(args: ReferralStateManagerArgs) {
|
56
|
+
if (!args.signer && !args.wallet) {
|
57
|
+
throw new Error("Signer or wallet must be provided");
|
46
58
|
}
|
59
|
+
this.umi = this.umi.use(
|
60
|
+
args.signer
|
61
|
+
? signerIdentity(args.signer)
|
62
|
+
: walletAdapterIdentity(args.wallet!, true)
|
63
|
+
);
|
47
64
|
|
48
|
-
|
49
|
-
|
50
|
-
|
65
|
+
this.signer = this.umi.identity;
|
66
|
+
this.referralState = getReferralState(
|
67
|
+
args.referralAuthority ?? toWeb3JsPublicKey(this.signer.publicKey)
|
68
|
+
);
|
69
|
+
this.referralStateData = await safeFetchReferralState(
|
70
|
+
this.umi,
|
71
|
+
publicKey(this.referralState),
|
72
|
+
{ commitment: "confirmed" }
|
73
|
+
);
|
51
74
|
|
52
|
-
|
53
|
-
|
54
|
-
signer: this.signer,
|
55
|
-
signerReferralState: publicKey(this.referralState),
|
56
|
-
referralFeesDestMint: destFeesMint ? publicKey(destFeesMint) : null,
|
57
|
-
referredByState: referredBy
|
58
|
-
? publicKey(getReferralState(referredBy))
|
59
|
-
: undefined,
|
60
|
-
referredByAuthority: referredBy
|
61
|
-
? publicKey(referredBy)
|
62
|
-
: undefined,
|
63
|
-
addressLookupTable: lookupTable
|
64
|
-
? publicKey(lookupTable)
|
65
|
-
: null,
|
66
|
-
});
|
67
|
-
}
|
75
|
+
this.setReferredBy(args.referredByAuthority);
|
76
|
+
}
|
68
77
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
? publicKey(
|
75
|
-
getTokenAccount(
|
76
|
-
toWeb3JsPublicKey(this.signer.publicKey),
|
77
|
-
referralFeesDestMint
|
78
|
-
)
|
79
|
-
)
|
80
|
-
: undefined;
|
78
|
+
defaultLookupTables(): string[] {
|
79
|
+
return this.referralStateData?.lookupTable
|
80
|
+
? [this.referralStateData?.lookupTable.toString()]
|
81
|
+
: [];
|
82
|
+
}
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
84
|
+
public setReferredBy(referredBy?: PublicKey) {
|
85
|
+
const authorityReferralStateData = this.referralStateData;
|
86
|
+
const hasReferredBy =
|
87
|
+
authorityReferralStateData &&
|
88
|
+
authorityReferralStateData.referredByState !==
|
89
|
+
publicKey(PublicKey.default);
|
90
|
+
const referredByAuthority =
|
91
|
+
!hasReferredBy &&
|
92
|
+
referredBy &&
|
93
|
+
!referredBy.equals(toWeb3JsPublicKey(this.signer.publicKey))
|
94
|
+
? referredBy
|
95
|
+
: undefined;
|
96
|
+
this.referredByState = hasReferredBy
|
97
|
+
? toWeb3JsPublicKey(authorityReferralStateData!.referredByState)
|
98
|
+
: referredByAuthority
|
99
|
+
? getReferralState(referredByAuthority!)
|
100
|
+
: undefined;
|
101
|
+
this.referredByAuthority = referredByAuthority;
|
102
|
+
}
|
92
103
|
|
93
|
-
|
94
|
-
|
104
|
+
updateReferralStatesIx(
|
105
|
+
destFeesMint?: PublicKey,
|
106
|
+
referredBy?: PublicKey,
|
107
|
+
lookupTable?: PublicKey
|
108
|
+
): TransactionBuilder {
|
109
|
+
return updateReferralStates(this.umi, {
|
110
|
+
signer: this.signer,
|
111
|
+
signerReferralState: publicKey(this.referralState),
|
112
|
+
referralFeesDestMint: destFeesMint ? publicKey(destFeesMint) : null,
|
113
|
+
referredByState: referredBy
|
114
|
+
? publicKey(getReferralState(referredBy))
|
115
|
+
: this.referredByState
|
116
|
+
? publicKey(this.referredByState)
|
117
|
+
: undefined,
|
118
|
+
referredByAuthority: referredBy ? publicKey(referredBy) : undefined,
|
119
|
+
addressLookupTable: lookupTable ? publicKey(lookupTable) : null,
|
120
|
+
});
|
121
|
+
}
|
122
|
+
|
123
|
+
claimReferralFeesIx(destFeesMint?: PublicKey): TransactionBuilder {
|
124
|
+
const referralFeesDestMint =
|
125
|
+
destFeesMint ?? toWeb3JsPublicKey(this.referralStateData!.destFeesMint);
|
126
|
+
const referralDestTa = getTokenAccount(
|
127
|
+
this.referralState,
|
128
|
+
referralFeesDestMint
|
129
|
+
);
|
130
|
+
const feesDestinationTa =
|
131
|
+
referralFeesDestMint !== NATIVE_MINT
|
132
|
+
? publicKey(
|
133
|
+
getTokenAccount(
|
134
|
+
toWeb3JsPublicKey(this.signer.publicKey),
|
135
|
+
referralFeesDestMint
|
136
|
+
)
|
137
|
+
)
|
138
|
+
: undefined;
|
139
|
+
|
140
|
+
return claimReferralFees(this.umi, {
|
141
|
+
signer: this.signer,
|
142
|
+
signerWsolTa: publicKey(
|
143
|
+
getTokenAccount(toWeb3JsPublicKey(this.signer.publicKey), NATIVE_MINT)
|
144
|
+
),
|
145
|
+
referralAuthority: publicKey(this.referralAuthority),
|
146
|
+
referralState: publicKey(this.referralState),
|
147
|
+
referralFeesDestTa: publicKey(referralDestTa),
|
148
|
+
referralFeesDestMint: publicKey(referralFeesDestMint),
|
149
|
+
feesDestinationTa,
|
150
|
+
});
|
151
|
+
}
|
152
|
+
|
153
|
+
async resetLiveTxUpdates(success?: boolean): Promise<void> {}
|
154
|
+
}
|
@@ -91,9 +91,6 @@ export abstract class SolautoClient extends TxHandler {
|
|
91
91
|
public signerDebtTa!: PublicKey;
|
92
92
|
|
93
93
|
public referralStateManager!: ReferralStateManager;
|
94
|
-
|
95
|
-
public referredByState?: PublicKey;
|
96
|
-
public referredByAuthority?: PublicKey;
|
97
94
|
public referredBySupplyTa?: PublicKey;
|
98
95
|
|
99
96
|
public solautoFeesWallet!: PublicKey;
|
@@ -133,11 +130,13 @@ export abstract class SolautoClient extends TxHandler {
|
|
133
130
|
this.authority,
|
134
131
|
this.positionId
|
135
132
|
);
|
136
|
-
this.solautoPositionData = !args.new
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
133
|
+
this.solautoPositionData = !args.new
|
134
|
+
? await safeFetchSolautoPosition(
|
135
|
+
this.umi,
|
136
|
+
publicKey(this.solautoPosition),
|
137
|
+
{ commitment: "confirmed" }
|
138
|
+
)
|
139
|
+
: null;
|
141
140
|
this.solautoPositionState = this.solautoPositionData?.state;
|
142
141
|
|
143
142
|
this.maxLtvBps = undefined;
|
@@ -171,11 +170,16 @@ export abstract class SolautoClient extends TxHandler {
|
|
171
170
|
this.referralStateManager = new ReferralStateManager(this.rpcUrl);
|
172
171
|
await this.referralStateManager.initialize({
|
173
172
|
referralAuthority: this.authority,
|
173
|
+
referredByAuthority: args.referredByAuthority,
|
174
174
|
signer: args.signer,
|
175
175
|
wallet: args.wallet,
|
176
176
|
});
|
177
|
-
|
178
|
-
|
177
|
+
if (this.referralStateManager.referredByState !== undefined) {
|
178
|
+
this.referredBySupplyTa = getTokenAccount(
|
179
|
+
this.referralStateManager.referredByState,
|
180
|
+
this.supplyMint
|
181
|
+
);
|
182
|
+
}
|
179
183
|
|
180
184
|
this.solautoFeesWallet = SOLAUTO_FEES_WALLET;
|
181
185
|
this.solautoFeesSupplyTa = getTokenAccount(
|
@@ -208,27 +212,10 @@ export abstract class SolautoClient extends TxHandler {
|
|
208
212
|
}
|
209
213
|
|
210
214
|
public setReferredBy(referredBy?: PublicKey) {
|
211
|
-
|
212
|
-
|
213
|
-
const hasReferredBy =
|
214
|
-
authorityReferralStateData &&
|
215
|
-
authorityReferralStateData.referredByState !==
|
216
|
-
publicKey(PublicKey.default);
|
217
|
-
const referredByAuthority =
|
218
|
-
!hasReferredBy &&
|
219
|
-
referredBy &&
|
220
|
-
!referredBy.equals(toWeb3JsPublicKey(this.signer.publicKey))
|
221
|
-
? referredBy
|
222
|
-
: undefined;
|
223
|
-
this.referredByState = hasReferredBy
|
224
|
-
? toWeb3JsPublicKey(authorityReferralStateData!.referredByState)
|
225
|
-
: referredByAuthority
|
226
|
-
? getReferralState(referredByAuthority!)
|
227
|
-
: undefined;
|
228
|
-
this.referredByAuthority = referredByAuthority;
|
229
|
-
if (this.referredByState !== undefined) {
|
215
|
+
this.referralStateManager.setReferredBy(referredBy);
|
216
|
+
if (this.referralStateManager.referredByState !== undefined) {
|
230
217
|
this.referredBySupplyTa = getTokenAccount(
|
231
|
-
this.referredByState,
|
218
|
+
this.referralStateManager.referredByState,
|
232
219
|
this.supplyMint
|
233
220
|
);
|
234
221
|
}
|
@@ -263,8 +263,8 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
263
263
|
signer: this.signer,
|
264
264
|
marginfiProgram: publicKey(MARGINFI_PROGRAM_ID),
|
265
265
|
signerReferralState: publicKey(this.referralStateManager.referralState),
|
266
|
-
referredByState: this.referredByState
|
267
|
-
? publicKey(this.referredByState)
|
266
|
+
referredByState: this.referralStateManager.referredByState
|
267
|
+
? publicKey(this.referralStateManager.referredByState)
|
268
268
|
: undefined,
|
269
269
|
referredBySupplyTa: this.referredBySupplyTa
|
270
270
|
? publicKey(this.referredBySupplyTa)
|
package/src/clients/txHandler.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Umi } from "@metaplex-foundation/umi";
|
2
|
-
import { Connection } from "@solana/web3.js";
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
3
3
|
import { consoleLog, getSolanaRpcConnection } from "../utils";
|
4
4
|
|
5
5
|
export abstract class TxHandler {
|
@@ -28,4 +28,6 @@ export abstract class TxHandler {
|
|
28
28
|
abstract defaultLookupTables(): string[];
|
29
29
|
|
30
30
|
abstract resetLiveTxUpdates(success?: boolean): Promise<void>;
|
31
|
+
|
32
|
+
abstract setReferredBy(referredBy?: PublicKey): void;
|
31
33
|
}
|
@@ -11,6 +11,7 @@ import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY } from "@solana/web3.js";
|
|
11
11
|
import {
|
12
12
|
ACCOUNT_SIZE as TOKEN_ACCOUNT_SIZE,
|
13
13
|
NATIVE_MINT,
|
14
|
+
RawAccount,
|
14
15
|
} from "@solana/spl-token";
|
15
16
|
import {
|
16
17
|
InvalidRebalanceConditionError,
|
@@ -73,6 +74,7 @@ import {
|
|
73
74
|
JUPITER_PROGRAM_ID,
|
74
75
|
} from "../jupiter-sdk";
|
75
76
|
import { PRICES } from "../constants";
|
77
|
+
import { TransactionItemInputs } from "../types";
|
76
78
|
|
77
79
|
interface wSolTokenUsage {
|
78
80
|
wSolTokenAccount: PublicKey;
|
@@ -138,7 +140,7 @@ async function transactionChoresBefore(
|
|
138
140
|
|
139
141
|
if (
|
140
142
|
client.referralStateManager.referralStateData === null ||
|
141
|
-
(client.referredByState !== undefined &&
|
143
|
+
(client.referralStateManager.referredByState !== undefined &&
|
142
144
|
client.referralStateManager.referralStateData?.referredByState ===
|
143
145
|
publicKey(PublicKey.default)) ||
|
144
146
|
(client.authorityLutAddress !== undefined &&
|
@@ -148,7 +150,7 @@ async function transactionChoresBefore(
|
|
148
150
|
chores = chores.add(
|
149
151
|
client.referralStateManager.updateReferralStatesIx(
|
150
152
|
undefined,
|
151
|
-
client.referredByAuthority,
|
153
|
+
client.referralStateManager.referredByAuthority,
|
152
154
|
client.authorityLutAddress
|
153
155
|
)
|
154
156
|
);
|
@@ -313,7 +315,7 @@ export async function rebalanceChoresBefore(
|
|
313
315
|
chores = chores.add(
|
314
316
|
createAssociatedTokenAccountUmiIx(
|
315
317
|
client.signer,
|
316
|
-
client.referredByState!,
|
318
|
+
client.referralStateManager.referredByState!,
|
317
319
|
client.supplyMint
|
318
320
|
)
|
319
321
|
);
|
@@ -628,13 +630,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
628
630
|
client: SolautoClient,
|
629
631
|
targetLiqUtilizationRateBps?: number,
|
630
632
|
attemptNum?: number
|
631
|
-
): Promise<
|
632
|
-
| {
|
633
|
-
tx: TransactionBuilder;
|
634
|
-
lookupTableAddresses: string[];
|
635
|
-
}
|
636
|
-
| undefined
|
637
|
-
> {
|
633
|
+
): Promise<TransactionItemInputs | undefined> {
|
638
634
|
client.solautoPositionState = await client.getFreshPositionState();
|
639
635
|
if (
|
640
636
|
(client.solautoPositionState?.supply.amountUsed.baseUnit === BigInt(0) &&
|
@@ -754,8 +750,11 @@ export async function convertReferralFeesToDestination(
|
|
754
750
|
referralManager: ReferralStateManager,
|
755
751
|
tokenAccount: PublicKey,
|
756
752
|
destinationMint: PublicKey
|
757
|
-
): Promise<
|
758
|
-
const tokenAccountData = await getTokenAccountData(
|
753
|
+
): Promise<TransactionItemInputs | undefined> {
|
754
|
+
const tokenAccountData = await getTokenAccountData(
|
755
|
+
referralManager.umi,
|
756
|
+
tokenAccount
|
757
|
+
);
|
759
758
|
if (!tokenAccountData || tokenAccountData.amount === BigInt(0)) {
|
760
759
|
return undefined;
|
761
760
|
}
|
@@ -788,7 +787,7 @@ export async function convertReferralFeesToDestination(
|
|
788
787
|
)
|
789
788
|
.add(swapIx);
|
790
789
|
|
791
|
-
return
|
790
|
+
return { tx, lookupTableAddresses };
|
792
791
|
}
|
793
792
|
|
794
793
|
export function getErrorInfo(tx: TransactionBuilder, error: any) {
|
@@ -15,12 +15,8 @@ import {
|
|
15
15
|
retryWithExponentialBackoff,
|
16
16
|
} from "../utils/generalUtils";
|
17
17
|
import { getErrorInfo, getTransactionChores } from "./transactionUtils";
|
18
|
-
import { PriorityFeeSetting, TransactionRunType } from "../types";
|
18
|
+
import { PriorityFeeSetting, TransactionItemInputs, TransactionRunType } from "../types";
|
19
19
|
import { ReferralStateManager, TxHandler } from "../clients";
|
20
|
-
import {
|
21
|
-
InvalidRebalanceConditionError,
|
22
|
-
SOLAUTO_PROGRAM_ID,
|
23
|
-
} from "../generated";
|
24
20
|
// import { sendJitoBundledTransactions } from "../utils/jitoUtils";
|
25
21
|
|
26
22
|
class LookupTables {
|
@@ -58,6 +54,8 @@ class LookupTables {
|
|
58
54
|
}
|
59
55
|
}
|
60
56
|
|
57
|
+
|
58
|
+
|
61
59
|
export class TransactionItem {
|
62
60
|
lookupTableAddresses!: string[];
|
63
61
|
tx?: TransactionBuilder;
|
@@ -65,9 +63,7 @@ export class TransactionItem {
|
|
65
63
|
constructor(
|
66
64
|
public fetchTx: (
|
67
65
|
attemptNum: number
|
68
|
-
) => Promise<
|
69
|
-
{ tx: TransactionBuilder; lookupTableAddresses?: string[] } | undefined
|
70
|
-
>,
|
66
|
+
) => Promise<TransactionItemInputs | undefined>,
|
71
67
|
public name?: string
|
72
68
|
) {}
|
73
69
|
|
@@ -542,7 +538,9 @@ export class TransactionsManager {
|
|
542
538
|
undefined,
|
543
539
|
errorDetails.errorInfo ?? errorDetails.errorName ?? "Unknown error"
|
544
540
|
);
|
545
|
-
this.txHandler.log(
|
541
|
+
this.txHandler.log(
|
542
|
+
`${errorDetails.errorName ?? "Unknown error"}: ${errorDetails.errorInfo ?? "unknown"}`
|
543
|
+
);
|
546
544
|
|
547
545
|
if (!errorDetails.canBeIgnored) {
|
548
546
|
throw e;
|
package/src/types/solauto.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { LendingPlatform, PositionType } from "../generated";
|
3
|
+
import { TransactionBuilder } from "@metaplex-foundation/umi";
|
3
4
|
|
4
5
|
export interface SolautoPositionDetails {
|
5
6
|
publicKey?: PublicKey;
|
@@ -14,9 +15,14 @@ export interface SolautoPositionDetails {
|
|
14
15
|
|
15
16
|
export enum PriorityFeeSetting {
|
16
17
|
Default = "Medium",
|
17
|
-
High = "High"
|
18
|
+
High = "High",
|
18
19
|
}
|
19
20
|
|
20
21
|
export type RebalanceAction = "boost" | "repay" | "dca";
|
21
22
|
|
22
|
-
export type TransactionRunType = "skip-simulation" | "only-simulate" | "normal";
|
23
|
+
export type TransactionRunType = "skip-simulation" | "only-simulate" | "normal";
|
24
|
+
|
25
|
+
export interface TransactionItemInputs {
|
26
|
+
tx: TransactionBuilder;
|
27
|
+
lookupTableAddresses?: string[];
|
28
|
+
}
|