@haven-fi/solauto-sdk 1.0.215 → 1.0.216
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/referralStateManager.d.ts +6 -5
- package/dist/clients/referralStateManager.d.ts.map +1 -1
- package/dist/clients/referralStateManager.js +9 -10
- package/dist/clients/solautoClient.d.ts +6 -15
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +15 -42
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +10 -9
- package/dist/clients/txHandler.d.ts +1 -4
- package/dist/clients/txHandler.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +10 -9
- package/package.json +1 -1
- package/src/clients/referralStateManager.ts +17 -15
- package/src/clients/solautoClient.ts +19 -74
- package/src/clients/solautoMarginfiClient.ts +11 -9
- package/src/clients/txHandler.ts +0 -5
- package/src/transactions/transactionUtils.ts +15 -13
- package/tests/transactions/solautoMarginfi.ts +4 -4
@@ -3,20 +3,22 @@ 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
5
|
import { TxHandler } from "./txHandler";
|
6
|
-
interface ReferralStateManagerArgs {
|
6
|
+
export interface ReferralStateManagerArgs {
|
7
7
|
signer?: Signer;
|
8
8
|
wallet?: WalletAdapter;
|
9
|
-
|
9
|
+
authority?: PublicKey;
|
10
10
|
referredByAuthority?: PublicKey;
|
11
11
|
}
|
12
12
|
export declare class ReferralStateManager extends TxHandler {
|
13
13
|
localTest?: boolean | undefined;
|
14
14
|
umi: Umi;
|
15
15
|
signer: Signer;
|
16
|
-
|
16
|
+
authority: PublicKey;
|
17
17
|
referralState: PublicKey;
|
18
18
|
referralStateData: ReferralState | null;
|
19
|
-
|
19
|
+
referredBy?: PublicKey;
|
20
|
+
referredByState?: PublicKey;
|
21
|
+
constructor(rpcUrl: string, localTest?: boolean | undefined);
|
20
22
|
initialize(args: ReferralStateManagerArgs): Promise<void>;
|
21
23
|
defaultLookupTables(): string[];
|
22
24
|
setReferredBy(referredBy?: PublicKey): void;
|
@@ -24,5 +26,4 @@ export declare class ReferralStateManager extends TxHandler {
|
|
24
26
|
claimReferralFeesIx(destFeesMint?: PublicKey): TransactionBuilder;
|
25
27
|
resetLiveTxUpdates(success?: boolean): Promise<void>;
|
26
28
|
}
|
27
|
-
export {};
|
28
29
|
//# 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,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;AAGxC,
|
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;AAGxC,MAAM,WAAW,wBAAwB;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,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,SAAS,EAAG,SAAS,CAAC;IACtB,aAAa,EAAG,SAAS,CAAC;IAC1B,iBAAiB,EAAG,aAAa,GAAG,IAAI,CAAC;IAEzC,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,eAAe,CAAC,EAAE,SAAS,CAAC;gBAGjC,MAAM,EAAE,MAAM,EACP,SAAS,CAAC,EAAE,OAAO,YAAA;IAUtB,UAAU,CAAC,IAAI,EAAE,wBAAwB;IAwB/C,mBAAmB,IAAI,MAAM,EAAE;IAS/B,aAAa,CAAC,UAAU,CAAC,EAAE,SAAS;IAmBpC,sBAAsB,CACpB,YAAY,CAAC,EAAE,SAAS,EACxB,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"}
|
@@ -11,8 +11,8 @@ const utils_1 = require("../utils");
|
|
11
11
|
const txHandler_1 = require("./txHandler");
|
12
12
|
const constants_1 = require("../constants");
|
13
13
|
class ReferralStateManager extends txHandler_1.TxHandler {
|
14
|
-
constructor(
|
15
|
-
super(
|
14
|
+
constructor(rpcUrl, localTest) {
|
15
|
+
super(rpcUrl, localTest);
|
16
16
|
this.localTest = localTest;
|
17
17
|
this.umi = this.umi.use({
|
18
18
|
install(umi) {
|
@@ -28,7 +28,8 @@ class ReferralStateManager extends txHandler_1.TxHandler {
|
|
28
28
|
? (0, umi_1.signerIdentity)(args.signer)
|
29
29
|
: (0, umi_signer_wallet_adapters_1.walletAdapterIdentity)(args.wallet, true));
|
30
30
|
this.signer = this.umi.identity;
|
31
|
-
this.
|
31
|
+
this.authority = args.authority ?? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey);
|
32
|
+
this.referralState = (0, utils_1.getReferralState)(args.authority ?? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey));
|
32
33
|
this.referralStateData = await (0, generated_1.safeFetchReferralState)(this.umi, (0, umi_1.publicKey)(this.referralState), { commitment: "confirmed" });
|
33
34
|
this.setReferredBy(args.referredByAuthority);
|
34
35
|
}
|
@@ -39,10 +40,8 @@ class ReferralStateManager extends txHandler_1.TxHandler {
|
|
39
40
|
: [constants_1.SOLAUTO_LUT];
|
40
41
|
}
|
41
42
|
setReferredBy(referredBy) {
|
42
|
-
const
|
43
|
-
|
44
|
-
authorityReferralStateData.referredByState !==
|
45
|
-
(0, umi_1.publicKey)(web3_js_1.PublicKey.default);
|
43
|
+
const hasReferredBy = this.referralStateData &&
|
44
|
+
this.referralStateData.referredByState !== (0, umi_1.publicKey)(web3_js_1.PublicKey.default);
|
46
45
|
const finalReferredBy = !hasReferredBy &&
|
47
46
|
referredBy &&
|
48
47
|
!referredBy.equals((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey))
|
@@ -51,8 +50,8 @@ class ReferralStateManager extends txHandler_1.TxHandler {
|
|
51
50
|
this.referredBy = finalReferredBy;
|
52
51
|
this.referredByState = finalReferredBy
|
53
52
|
? (0, utils_1.getReferralState)(finalReferredBy)
|
54
|
-
:
|
55
|
-
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(
|
53
|
+
: this.referralStateData
|
54
|
+
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.referralStateData.referredByState)
|
56
55
|
: undefined;
|
57
56
|
}
|
58
57
|
updateReferralStatesIx(destFeesMint, lookupTable) {
|
@@ -78,7 +77,7 @@ class ReferralStateManager extends txHandler_1.TxHandler {
|
|
78
77
|
return (0, generated_1.claimReferralFees)(this.umi, {
|
79
78
|
signer: this.signer,
|
80
79
|
signerWsolTa: (0, umi_1.publicKey)((0, utils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), spl_token_1.NATIVE_MINT)),
|
81
|
-
referralAuthority: (0, umi_1.publicKey)(this.
|
80
|
+
referralAuthority: (0, umi_1.publicKey)(this.authority),
|
82
81
|
referralState: (0, umi_1.publicKey)(this.referralState),
|
83
82
|
referralFeesDestTa: (0, umi_1.publicKey)(referralDestTa),
|
84
83
|
referralFeesDestMint: (0, umi_1.publicKey)(referralFeesDestMint),
|
@@ -1,25 +1,19 @@
|
|
1
1
|
import "rpc-websockets/dist/lib/client";
|
2
2
|
import { PublicKey } from "@solana/web3.js";
|
3
3
|
import { Signer, TransactionBuilder } from "@metaplex-foundation/umi";
|
4
|
-
import { WalletAdapter } from "@metaplex-foundation/umi-signer-wallet-adapters";
|
5
4
|
import { DCASettings, DCASettingsInpArgs, LendingPlatform, PositionState, SolautoActionArgs, SolautoPosition, SolautoRebalanceTypeArgs, SolautoSettingsParameters, SolautoSettingsParametersInpArgs, UpdatePositionDataArgs } from "../generated";
|
6
5
|
import { FlashLoanDetails } from "../utils/solauto/rebalanceUtils";
|
7
6
|
import { LivePositionUpdates } from "../utils/solauto/generalUtils";
|
8
|
-
import { ReferralStateManager } from "./referralStateManager";
|
9
|
-
import { TxHandler } from "./txHandler";
|
7
|
+
import { ReferralStateManager, ReferralStateManagerArgs } from "./referralStateManager";
|
10
8
|
import { QuoteResponse } from "@jup-ag/api";
|
11
|
-
export interface SolautoClientArgs {
|
9
|
+
export interface SolautoClientArgs extends ReferralStateManagerArgs {
|
12
10
|
new?: boolean;
|
13
|
-
authority?: PublicKey;
|
14
11
|
positionId?: number;
|
15
|
-
signer?: Signer;
|
16
|
-
wallet?: WalletAdapter;
|
17
12
|
supplyMint?: PublicKey;
|
18
13
|
debtMint?: PublicKey;
|
19
|
-
referredByAuthority?: PublicKey;
|
20
14
|
}
|
21
|
-
export declare abstract class SolautoClient extends
|
22
|
-
lendingPlatform
|
15
|
+
export declare abstract class SolautoClient extends ReferralStateManager {
|
16
|
+
lendingPlatform?: LendingPlatform;
|
23
17
|
authority: PublicKey;
|
24
18
|
signer: Signer;
|
25
19
|
positionId: number;
|
@@ -35,15 +29,12 @@ export declare abstract class SolautoClient extends TxHandler {
|
|
35
29
|
debtMint: PublicKey;
|
36
30
|
positionDebtTa: PublicKey;
|
37
31
|
signerDebtTa: PublicKey;
|
38
|
-
referralStateManager: ReferralStateManager;
|
39
|
-
referredBySupplyTa?: PublicKey;
|
40
32
|
solautoFeesWallet: PublicKey;
|
41
33
|
solautoFeesSupplyTa: PublicKey;
|
42
34
|
authorityLutAddress?: PublicKey;
|
43
35
|
livePositionUpdates: LivePositionUpdates;
|
44
|
-
|
45
|
-
|
46
|
-
setReferredBy(referredBy?: PublicKey): void;
|
36
|
+
initialize(args: SolautoClientArgs): Promise<void>;
|
37
|
+
referredBySupplyTa(): PublicKey | undefined;
|
47
38
|
resetLiveTxUpdates(success?: boolean): Promise<void>;
|
48
39
|
abstract protocolAccount(): PublicKey;
|
49
40
|
defaultLookupTables(): string[];
|
@@ -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,
|
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,EAMnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,eAAe,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qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAalE"}
|
@@ -5,7 +5,6 @@ require("rpc-websockets/dist/lib/client");
|
|
5
5
|
const web3_js_1 = require("@solana/web3.js");
|
6
6
|
const umi_1 = require("@metaplex-foundation/umi");
|
7
7
|
const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
|
8
|
-
const umi_signer_wallet_adapters_1 = require("@metaplex-foundation/umi-signer-wallet-adapters");
|
9
8
|
const generated_1 = require("../generated");
|
10
9
|
const accountUtils_1 = require("../utils/accountUtils");
|
11
10
|
const generalAccounts_1 = require("../constants/generalAccounts");
|
@@ -14,29 +13,15 @@ const solautoConstants_1 = require("../constants/solautoConstants");
|
|
14
13
|
const generalUtils_1 = require("../utils/generalUtils");
|
15
14
|
const generalUtils_2 = require("../utils/solauto/generalUtils");
|
16
15
|
const referralStateManager_1 = require("./referralStateManager");
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
super(rpcUrl, localTest);
|
16
|
+
class SolautoClient extends referralStateManager_1.ReferralStateManager {
|
17
|
+
constructor() {
|
18
|
+
super(...arguments);
|
21
19
|
this.livePositionUpdates = new generalUtils_2.LivePositionUpdates();
|
22
|
-
this.umi = this.umi.use({
|
23
|
-
install(umi) {
|
24
|
-
umi.programs.add((0, generated_1.createSolautoProgram)(), false);
|
25
|
-
},
|
26
|
-
});
|
27
20
|
}
|
28
|
-
async initialize(args
|
29
|
-
|
30
|
-
throw new Error("Signer or wallet must be provided");
|
31
|
-
}
|
32
|
-
this.umi = this.umi.use(args.signer
|
33
|
-
? (0, umi_1.signerIdentity)(args.signer)
|
34
|
-
: (0, umi_signer_wallet_adapters_1.walletAdapterIdentity)(args.wallet, true));
|
35
|
-
this.signer = this.umi.identity;
|
36
|
-
this.authority = args.authority ?? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey);
|
21
|
+
async initialize(args) {
|
22
|
+
await super.initialize(args);
|
37
23
|
this.positionId = args.positionId ?? 0;
|
38
24
|
this.selfManaged = this.positionId === 0;
|
39
|
-
this.lendingPlatform = lendingPlatform;
|
40
25
|
this.solautoPosition = (0, accountUtils_1.getSolautoPositionAccount)(this.authority, this.positionId);
|
41
26
|
this.solautoPositionData = !args.new
|
42
27
|
? await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition), { commitment: "confirmed" })
|
@@ -58,24 +43,12 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
58
43
|
: web3_js_1.PublicKey.default);
|
59
44
|
this.positionDebtTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.debtMint);
|
60
45
|
this.signerDebtTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.debtMint);
|
61
|
-
this.referralStateManager = new referralStateManager_1.ReferralStateManager(this.rpcUrl);
|
62
|
-
await this.referralStateManager.initialize({
|
63
|
-
referralAuthority: this.authority,
|
64
|
-
referredByAuthority: args.referredByAuthority,
|
65
|
-
signer: args.signer,
|
66
|
-
wallet: args.wallet,
|
67
|
-
});
|
68
|
-
console.log(this.referralStateManager.referredBy?.toString());
|
69
|
-
if (this.referralStateManager.referredByState !== undefined) {
|
70
|
-
this.referredBySupplyTa = (0, accountUtils_1.getTokenAccount)(this.referralStateManager.referredByState, this.supplyMint);
|
71
|
-
}
|
72
46
|
this.solautoFeesWallet = generalAccounts_1.SOLAUTO_FEES_WALLET;
|
73
47
|
this.solautoFeesSupplyTa = (0, accountUtils_1.getTokenAccount)(this.solautoFeesWallet, this.supplyMint);
|
74
|
-
const authorityReferralStateData = this.referralStateManager.referralStateData;
|
75
48
|
this.authorityLutAddress =
|
76
|
-
|
77
|
-
!(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(
|
78
|
-
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(
|
49
|
+
this.referralStateData?.lookupTable &&
|
50
|
+
!(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.referralStateData.lookupTable).equals(web3_js_1.PublicKey.default)
|
51
|
+
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.referralStateData.lookupTable)
|
79
52
|
: undefined;
|
80
53
|
this.log("Position state: ", this.solautoPositionState);
|
81
54
|
this.log("Position settings: ", this.solautoPositionData?.position?.settingParams);
|
@@ -84,11 +57,11 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
84
57
|
? this.solautoPositionData?.position?.dca
|
85
58
|
: undefined);
|
86
59
|
}
|
87
|
-
|
88
|
-
this.
|
89
|
-
|
90
|
-
this.referredBySupplyTa = (0, accountUtils_1.getTokenAccount)(this.referralStateManager.referredByState, this.supplyMint);
|
60
|
+
referredBySupplyTa() {
|
61
|
+
if (this.referredByState !== undefined) {
|
62
|
+
return (0, accountUtils_1.getTokenAccount)(this.referredByState, this.supplyMint);
|
91
63
|
}
|
64
|
+
return undefined;
|
92
65
|
}
|
93
66
|
async resetLiveTxUpdates(success) {
|
94
67
|
if (success) {
|
@@ -129,8 +102,8 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
129
102
|
this.solautoPosition,
|
130
103
|
this.positionSupplyTa,
|
131
104
|
this.positionDebtTa,
|
132
|
-
this.
|
133
|
-
...(this.referredBySupplyTa ? [this.referredBySupplyTa] : []),
|
105
|
+
this.referralState,
|
106
|
+
...(this.referredBySupplyTa() ? [this.referredBySupplyTa()] : []),
|
134
107
|
];
|
135
108
|
}
|
136
109
|
async fetchExistingAuthorityLutAccounts() {
|
@@ -172,7 +145,7 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
172
145
|
}
|
173
146
|
const addingReferredBy = accountsToAdd.length === 1 &&
|
174
147
|
accountsToAdd[0].toString().toLowerCase() ===
|
175
|
-
this.referredBySupplyTa?.toString().toLowerCase();
|
148
|
+
this.referredBySupplyTa()?.toString().toLowerCase();
|
176
149
|
if (tx.getInstructions().length > 0) {
|
177
150
|
this.log("Updating authority lookup table...");
|
178
151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,iCAAiC,CAAC,EAAE,MAAM,CAAC;IAC3C,6BAA6B,EAAG,SAAS,CAAC;IAC1C,2BAA2B,CAAC,EAAE,eAAe,CAAC;IAE/C,UAAU,CAAC,IAAI,EAAE,yBAAyB;IA+D1C,8BAA8B;IA0CpC,eAAe,IAAI,SAAS;IAI5B,mBAAmB,IAAI,MAAM,EAAE;IAI/B,gBAAgB,IAAI,SAAS,EAAE;IAUzB,wBAAwB,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IA0BvE,yBAAyB,IAAI,kBAAkB;IAS/C,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA6C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA0D5C,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IAqErB,WAAW,CACT,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAoFlE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CA6ClE"}
|
@@ -19,7 +19,8 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
19
19
|
this.marginfiAccountSeedIdx = BigInt(0);
|
20
20
|
}
|
21
21
|
async initialize(args) {
|
22
|
-
await super.initialize(args
|
22
|
+
await super.initialize(args);
|
23
|
+
this.lendingPlatform = generated_1.LendingPlatform.Marginfi;
|
23
24
|
if (this.selfManaged) {
|
24
25
|
this.marginfiAccount =
|
25
26
|
args.marginfiAccount ??
|
@@ -135,12 +136,12 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
135
136
|
return (0, generated_1.marginfiOpenPosition)(this.umi, {
|
136
137
|
signer: this.signer,
|
137
138
|
marginfiProgram: (0, umi_1.publicKey)(marginfi_sdk_1.MARGINFI_PROGRAM_ID),
|
138
|
-
signerReferralState: (0, umi_1.publicKey)(this.
|
139
|
-
referredByState: this.
|
140
|
-
? (0, umi_1.publicKey)(this.
|
139
|
+
signerReferralState: (0, umi_1.publicKey)(this.referralState),
|
140
|
+
referredByState: this.referredByState
|
141
|
+
? (0, umi_1.publicKey)(this.referredByState)
|
141
142
|
: undefined,
|
142
|
-
referredBySupplyTa: this.referredBySupplyTa
|
143
|
-
? (0, umi_1.publicKey)(this.referredBySupplyTa)
|
143
|
+
referredBySupplyTa: this.referredBySupplyTa()
|
144
|
+
? (0, umi_1.publicKey)(this.referredBySupplyTa())
|
144
145
|
: undefined,
|
145
146
|
solautoPosition: (0, umi_1.publicKey)(this.solautoPosition),
|
146
147
|
marginfiGroup: (0, umi_1.publicKey)(this.marginfiGroup),
|
@@ -299,9 +300,9 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
299
300
|
marginfiProgram: (0, umi_1.publicKey)(marginfi_sdk_1.MARGINFI_PROGRAM_ID),
|
300
301
|
ixsSysvar: (0, umi_1.publicKey)(web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY),
|
301
302
|
solautoFeesSupplyTa: rebalanceStep === "B" ? (0, umi_1.publicKey)(this.solautoFeesSupplyTa) : undefined,
|
302
|
-
authorityReferralState: (0, umi_1.publicKey)(this.
|
303
|
-
referredBySupplyTa: this.referredBySupplyTa
|
304
|
-
? (0, umi_1.publicKey)(this.referredBySupplyTa)
|
303
|
+
authorityReferralState: (0, umi_1.publicKey)(this.referralState),
|
304
|
+
referredBySupplyTa: this.referredBySupplyTa()
|
305
|
+
? (0, umi_1.publicKey)(this.referredBySupplyTa())
|
305
306
|
: undefined,
|
306
307
|
positionAuthority: (0, umi_1.publicKey)(this.authority),
|
307
308
|
solautoPosition: (0, umi_1.publicKey)(this.solautoPosition),
|
@@ -1,15 +1,12 @@
|
|
1
1
|
import { Umi } from "@metaplex-foundation/umi";
|
2
|
-
import { Connection
|
2
|
+
import { Connection } from "@solana/web3.js";
|
3
3
|
export declare abstract class TxHandler {
|
4
4
|
rpcUrl: string;
|
5
5
|
umi: Umi;
|
6
6
|
connection: Connection;
|
7
|
-
referredBy?: PublicKey;
|
8
|
-
referredByState?: PublicKey;
|
9
7
|
constructor(rpcUrl: string, localTest?: boolean);
|
10
8
|
log(...args: any[]): void;
|
11
9
|
abstract defaultLookupTables(): string[];
|
12
10
|
abstract resetLiveTxUpdates(success?: boolean): Promise<void>;
|
13
|
-
abstract setReferredBy(referredBy?: PublicKey): void;
|
14
11
|
}
|
15
12
|
//# 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,
|
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,EAAa,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;CAC9D"}
|
@@ -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;AAuBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,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;AAyCzD,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAO7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAqLjD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAiH7B;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,oBA2CzE;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"}
|
@@ -51,14 +51,13 @@ function getWSolUsage(client, solautoActions, initiatingDcaIn, cancellingDcaIn)
|
|
51
51
|
}
|
52
52
|
async function transactionChoresBefore(client, accountsGettingCreated, solautoActions, initiatingDcaIn) {
|
53
53
|
let chores = (0, umi_1.transactionBuilder)();
|
54
|
-
if (client.
|
55
|
-
(client.
|
56
|
-
client.
|
54
|
+
if (client.referralStateData === null ||
|
55
|
+
(client.referredBy !== undefined &&
|
56
|
+
client.referralStateData?.referredByState ===
|
57
57
|
(0, umi_1.publicKey)(web3_js_1.PublicKey.default)) ||
|
58
58
|
(client.authorityLutAddress !== undefined &&
|
59
|
-
client.
|
60
|
-
|
61
|
-
chores = chores.add(client.referralStateManager.updateReferralStatesIx(undefined, client.authorityLutAddress));
|
59
|
+
client.referralStateData.lookupTable == (0, umi_1.publicKey)(web3_js_1.PublicKey.default))) {
|
60
|
+
chores = chores.add(client.updateReferralStatesIx(undefined, client.authorityLutAddress));
|
62
61
|
}
|
63
62
|
if (client.selfManaged) {
|
64
63
|
if (client.solautoPositionData === null) {
|
@@ -127,14 +126,16 @@ async function rebalanceChoresBefore(client, tx, accountsGettingCreated) {
|
|
127
126
|
const usesAccount = (key) => tx
|
128
127
|
.getInstructions()
|
129
128
|
.some((t) => t.keys.some((k) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(k.pubkey).equals(key)));
|
130
|
-
const checkReferralSupplyTa = client.referredBySupplyTa && usesAccount(client.referredBySupplyTa);
|
129
|
+
const checkReferralSupplyTa = client.referredBySupplyTa() && usesAccount(client.referredBySupplyTa());
|
131
130
|
const checkSolautoFeesTa = usesAccount(client.solautoFeesSupplyTa);
|
132
131
|
const checkIntermediaryMfiAccount = client.lendingPlatform === generated_1.LendingPlatform.Marginfi &&
|
133
132
|
usesAccount(client.intermediaryMarginfiAccountPk);
|
134
133
|
const checkSignerSupplyTa = usesAccount(client.signerSupplyTa);
|
135
134
|
const checkSignerDebtTa = usesAccount(client.signerDebtTa);
|
136
135
|
const accountsNeeded = [
|
137
|
-
...[
|
136
|
+
...[
|
137
|
+
checkReferralSupplyTa ? client.referredBySupplyTa() : web3_js_1.PublicKey.default,
|
138
|
+
],
|
138
139
|
...[checkSolautoFeesTa ? client.solautoFeesSupplyTa : web3_js_1.PublicKey.default],
|
139
140
|
...[
|
140
141
|
checkIntermediaryMfiAccount
|
@@ -148,7 +149,7 @@ async function rebalanceChoresBefore(client, tx, accountsGettingCreated) {
|
|
148
149
|
let chores = (0, umi_1.transactionBuilder)();
|
149
150
|
if (checkReferralSupplyTa && !(0, generalUtils_1.rpcAccountCreated)(referredBySupplyTa)) {
|
150
151
|
client.log("Creating referred-by TA for ", client.supplyMint.toString());
|
151
|
-
chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.
|
152
|
+
chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, client.referredByState, client.supplyMint));
|
152
153
|
}
|
153
154
|
if (checkSolautoFeesTa && !(0, generalUtils_1.rpcAccountCreated)(solautoFeesSupplyTa)) {
|
154
155
|
client.log("Creating Solauto fees TA for ", client.supplyMint.toString());
|
package/package.json
CHANGED
@@ -23,10 +23,10 @@ import { getReferralState, getTokenAccount } from "../utils";
|
|
23
23
|
import { TxHandler } from "./txHandler";
|
24
24
|
import { SOLAUTO_LUT } from "../constants";
|
25
25
|
|
26
|
-
interface ReferralStateManagerArgs {
|
26
|
+
export interface ReferralStateManagerArgs {
|
27
27
|
signer?: Signer;
|
28
28
|
wallet?: WalletAdapter;
|
29
|
-
|
29
|
+
authority?: PublicKey;
|
30
30
|
referredByAuthority?: PublicKey;
|
31
31
|
}
|
32
32
|
|
@@ -34,15 +34,18 @@ export class ReferralStateManager extends TxHandler {
|
|
34
34
|
public umi!: Umi;
|
35
35
|
public signer!: Signer;
|
36
36
|
|
37
|
-
public
|
37
|
+
public authority!: PublicKey;
|
38
38
|
public referralState!: PublicKey;
|
39
39
|
public referralStateData!: ReferralState | null;
|
40
40
|
|
41
|
+
public referredBy?: PublicKey;
|
42
|
+
public referredByState?: PublicKey;
|
43
|
+
|
41
44
|
constructor(
|
42
|
-
|
45
|
+
rpcUrl: string,
|
43
46
|
public localTest?: boolean
|
44
47
|
) {
|
45
|
-
super(
|
48
|
+
super(rpcUrl, localTest);
|
46
49
|
this.umi = this.umi.use({
|
47
50
|
install(umi) {
|
48
51
|
umi.programs.add(createSolautoProgram(), false);
|
@@ -59,10 +62,11 @@ export class ReferralStateManager extends TxHandler {
|
|
59
62
|
? signerIdentity(args.signer)
|
60
63
|
: walletAdapterIdentity(args.wallet!, true)
|
61
64
|
);
|
62
|
-
|
63
65
|
this.signer = this.umi.identity;
|
66
|
+
this.authority = args.authority ?? toWeb3JsPublicKey(this.signer.publicKey);
|
67
|
+
|
64
68
|
this.referralState = getReferralState(
|
65
|
-
args.
|
69
|
+
args.authority ?? toWeb3JsPublicKey(this.signer.publicKey)
|
66
70
|
);
|
67
71
|
this.referralStateData = await safeFetchReferralState(
|
68
72
|
this.umi,
|
@@ -82,12 +86,10 @@ export class ReferralStateManager extends TxHandler {
|
|
82
86
|
: [SOLAUTO_LUT];
|
83
87
|
}
|
84
88
|
|
85
|
-
|
86
|
-
const authorityReferralStateData = this.referralStateData;
|
89
|
+
setReferredBy(referredBy?: PublicKey) {
|
87
90
|
const hasReferredBy =
|
88
|
-
|
89
|
-
|
90
|
-
publicKey(PublicKey.default);
|
91
|
+
this.referralStateData &&
|
92
|
+
this.referralStateData.referredByState !== publicKey(PublicKey.default);
|
91
93
|
const finalReferredBy =
|
92
94
|
!hasReferredBy &&
|
93
95
|
referredBy &&
|
@@ -98,8 +100,8 @@ export class ReferralStateManager extends TxHandler {
|
|
98
100
|
this.referredBy = finalReferredBy;
|
99
101
|
this.referredByState = finalReferredBy
|
100
102
|
? getReferralState(finalReferredBy)
|
101
|
-
:
|
102
|
-
? toWeb3JsPublicKey(
|
103
|
+
: this.referralStateData
|
104
|
+
? toWeb3JsPublicKey(this.referralStateData.referredByState)
|
103
105
|
: undefined;
|
104
106
|
}
|
105
107
|
|
@@ -143,7 +145,7 @@ export class ReferralStateManager extends TxHandler {
|
|
143
145
|
signerWsolTa: publicKey(
|
144
146
|
getTokenAccount(toWeb3JsPublicKey(this.signer.publicKey), NATIVE_MINT)
|
145
147
|
),
|
146
|
-
referralAuthority: publicKey(this.
|
148
|
+
referralAuthority: publicKey(this.authority),
|
147
149
|
referralState: publicKey(this.referralState),
|
148
150
|
referralFeesDestTa: publicKey(referralDestTa),
|
149
151
|
referralFeesDestMint: publicKey(referralFeesDestMint),
|
@@ -8,13 +8,8 @@ import {
|
|
8
8
|
PublicKey as UmiPublicKey,
|
9
9
|
isSome,
|
10
10
|
transactionBuilder,
|
11
|
-
signerIdentity,
|
12
11
|
} from "@metaplex-foundation/umi";
|
13
12
|
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
14
|
-
import {
|
15
|
-
WalletAdapter,
|
16
|
-
walletAdapterIdentity,
|
17
|
-
} from "@metaplex-foundation/umi-signer-wallet-adapters";
|
18
13
|
import {
|
19
14
|
DCASettings,
|
20
15
|
DCASettingsInpArgs,
|
@@ -29,12 +24,10 @@ import {
|
|
29
24
|
UpdatePositionDataArgs,
|
30
25
|
cancelDCA,
|
31
26
|
closePosition,
|
32
|
-
createSolautoProgram,
|
33
27
|
safeFetchSolautoPosition,
|
34
28
|
updatePosition,
|
35
29
|
} from "../generated";
|
36
30
|
import {
|
37
|
-
getReferralState,
|
38
31
|
getSolautoPositionAccount,
|
39
32
|
getTokenAccount,
|
40
33
|
} from "../utils/accountUtils";
|
@@ -50,25 +43,21 @@ import {
|
|
50
43
|
} from "../constants/solautoConstants";
|
51
44
|
import { currentUnixSeconds } from "../utils/generalUtils";
|
52
45
|
import { LivePositionUpdates } from "../utils/solauto/generalUtils";
|
53
|
-
import {
|
54
|
-
|
46
|
+
import {
|
47
|
+
ReferralStateManager,
|
48
|
+
ReferralStateManagerArgs,
|
49
|
+
} from "./referralStateManager";
|
55
50
|
import { QuoteResponse } from "@jup-ag/api";
|
56
51
|
|
57
|
-
export interface SolautoClientArgs {
|
52
|
+
export interface SolautoClientArgs extends ReferralStateManagerArgs {
|
58
53
|
new?: boolean;
|
59
|
-
authority?: PublicKey;
|
60
54
|
positionId?: number;
|
61
|
-
signer?: Signer;
|
62
|
-
wallet?: WalletAdapter;
|
63
|
-
|
64
55
|
supplyMint?: PublicKey;
|
65
56
|
debtMint?: PublicKey;
|
66
|
-
|
67
|
-
referredByAuthority?: PublicKey;
|
68
57
|
}
|
69
58
|
|
70
|
-
export abstract class SolautoClient extends
|
71
|
-
public lendingPlatform
|
59
|
+
export abstract class SolautoClient extends ReferralStateManager {
|
60
|
+
public lendingPlatform?: LendingPlatform;
|
72
61
|
|
73
62
|
public authority!: PublicKey;
|
74
63
|
public signer!: Signer;
|
@@ -90,9 +79,6 @@ export abstract class SolautoClient extends TxHandler {
|
|
90
79
|
public positionDebtTa!: PublicKey;
|
91
80
|
public signerDebtTa!: PublicKey;
|
92
81
|
|
93
|
-
public referralStateManager!: ReferralStateManager;
|
94
|
-
public referredBySupplyTa?: PublicKey;
|
95
|
-
|
96
82
|
public solautoFeesWallet!: PublicKey;
|
97
83
|
public solautoFeesSupplyTa!: PublicKey;
|
98
84
|
|
@@ -100,32 +86,11 @@ export abstract class SolautoClient extends TxHandler {
|
|
100
86
|
|
101
87
|
public livePositionUpdates: LivePositionUpdates = new LivePositionUpdates();
|
102
88
|
|
103
|
-
|
104
|
-
super(
|
105
|
-
|
106
|
-
this.umi = this.umi.use({
|
107
|
-
install(umi) {
|
108
|
-
umi.programs.add(createSolautoProgram(), false);
|
109
|
-
},
|
110
|
-
});
|
111
|
-
}
|
112
|
-
|
113
|
-
async initialize(args: SolautoClientArgs, lendingPlatform: LendingPlatform) {
|
114
|
-
if (!args.signer && !args.wallet) {
|
115
|
-
throw new Error("Signer or wallet must be provided");
|
116
|
-
}
|
117
|
-
this.umi = this.umi.use(
|
118
|
-
args.signer
|
119
|
-
? signerIdentity(args.signer)
|
120
|
-
: walletAdapterIdentity(args.wallet!, true)
|
121
|
-
);
|
122
|
-
|
123
|
-
this.signer = this.umi.identity;
|
124
|
-
this.authority = args.authority ?? toWeb3JsPublicKey(this.signer.publicKey);
|
89
|
+
async initialize(args: SolautoClientArgs) {
|
90
|
+
await super.initialize(args);
|
125
91
|
|
126
92
|
this.positionId = args.positionId ?? 0;
|
127
93
|
this.selfManaged = this.positionId === 0;
|
128
|
-
this.lendingPlatform = lendingPlatform;
|
129
94
|
this.solautoPosition = getSolautoPositionAccount(
|
130
95
|
this.authority,
|
131
96
|
this.positionId
|
@@ -167,35 +132,18 @@ export abstract class SolautoClient extends TxHandler {
|
|
167
132
|
this.debtMint
|
168
133
|
);
|
169
134
|
|
170
|
-
this.referralStateManager = new ReferralStateManager(this.rpcUrl);
|
171
|
-
await this.referralStateManager.initialize({
|
172
|
-
referralAuthority: this.authority,
|
173
|
-
referredByAuthority: args.referredByAuthority,
|
174
|
-
signer: args.signer,
|
175
|
-
wallet: args.wallet,
|
176
|
-
});
|
177
|
-
console.log(this.referralStateManager.referredBy?.toString());
|
178
|
-
if (this.referralStateManager.referredByState !== undefined) {
|
179
|
-
this.referredBySupplyTa = getTokenAccount(
|
180
|
-
this.referralStateManager.referredByState,
|
181
|
-
this.supplyMint
|
182
|
-
);
|
183
|
-
}
|
184
|
-
|
185
135
|
this.solautoFeesWallet = SOLAUTO_FEES_WALLET;
|
186
136
|
this.solautoFeesSupplyTa = getTokenAccount(
|
187
137
|
this.solautoFeesWallet,
|
188
138
|
this.supplyMint
|
189
139
|
);
|
190
140
|
|
191
|
-
const authorityReferralStateData =
|
192
|
-
this.referralStateManager.referralStateData;
|
193
141
|
this.authorityLutAddress =
|
194
|
-
|
195
|
-
!toWeb3JsPublicKey(
|
142
|
+
this.referralStateData?.lookupTable &&
|
143
|
+
!toWeb3JsPublicKey(this.referralStateData.lookupTable).equals(
|
196
144
|
PublicKey.default
|
197
145
|
)
|
198
|
-
? toWeb3JsPublicKey(
|
146
|
+
? toWeb3JsPublicKey(this.referralStateData.lookupTable)
|
199
147
|
: undefined;
|
200
148
|
|
201
149
|
this.log("Position state: ", this.solautoPositionState);
|
@@ -212,14 +160,11 @@ export abstract class SolautoClient extends TxHandler {
|
|
212
160
|
);
|
213
161
|
}
|
214
162
|
|
215
|
-
|
216
|
-
this.
|
217
|
-
|
218
|
-
this.referredBySupplyTa = getTokenAccount(
|
219
|
-
this.referralStateManager.referredByState!,
|
220
|
-
this.supplyMint
|
221
|
-
);
|
163
|
+
referredBySupplyTa(): PublicKey | undefined {
|
164
|
+
if (this.referredByState !== undefined) {
|
165
|
+
return getTokenAccount(this.referredByState, this.supplyMint);
|
222
166
|
}
|
167
|
+
return undefined;
|
223
168
|
}
|
224
169
|
|
225
170
|
async resetLiveTxUpdates(success?: boolean) {
|
@@ -268,8 +213,8 @@ export abstract class SolautoClient extends TxHandler {
|
|
268
213
|
this.solautoPosition,
|
269
214
|
this.positionSupplyTa,
|
270
215
|
this.positionDebtTa,
|
271
|
-
this.
|
272
|
-
...(this.referredBySupplyTa ? [this.referredBySupplyTa] : []),
|
216
|
+
this.referralState,
|
217
|
+
...(this.referredBySupplyTa() ? [this.referredBySupplyTa()!] : []),
|
273
218
|
];
|
274
219
|
}
|
275
220
|
|
@@ -333,7 +278,7 @@ export abstract class SolautoClient extends TxHandler {
|
|
333
278
|
const addingReferredBy =
|
334
279
|
accountsToAdd.length === 1 &&
|
335
280
|
accountsToAdd[0].toString().toLowerCase() ===
|
336
|
-
this.referredBySupplyTa?.toString().toLowerCase();
|
281
|
+
this.referredBySupplyTa()?.toString().toLowerCase();
|
337
282
|
|
338
283
|
if (tx.getInstructions().length > 0) {
|
339
284
|
this.log("Updating authority lookup table...");
|
@@ -85,7 +85,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
85
85
|
public intermediaryMarginfiAccount?: MarginfiAccount;
|
86
86
|
|
87
87
|
async initialize(args: SolautoMarginfiClientArgs) {
|
88
|
-
await super.initialize(args
|
88
|
+
await super.initialize(args);
|
89
|
+
|
90
|
+
this.lendingPlatform = LendingPlatform.Marginfi;
|
89
91
|
|
90
92
|
if (this.selfManaged) {
|
91
93
|
this.marginfiAccount =
|
@@ -262,12 +264,12 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
262
264
|
return marginfiOpenPosition(this.umi, {
|
263
265
|
signer: this.signer,
|
264
266
|
marginfiProgram: publicKey(MARGINFI_PROGRAM_ID),
|
265
|
-
signerReferralState: publicKey(this.
|
266
|
-
referredByState: this.
|
267
|
-
? publicKey(this.
|
267
|
+
signerReferralState: publicKey(this.referralState),
|
268
|
+
referredByState: this.referredByState
|
269
|
+
? publicKey(this.referredByState)
|
268
270
|
: undefined,
|
269
|
-
referredBySupplyTa: this.referredBySupplyTa
|
270
|
-
? publicKey(this.referredBySupplyTa)
|
271
|
+
referredBySupplyTa: this.referredBySupplyTa()
|
272
|
+
? publicKey(this.referredBySupplyTa()!)
|
271
273
|
: undefined,
|
272
274
|
solautoPosition: publicKey(this.solautoPosition),
|
273
275
|
marginfiGroup: publicKey(this.marginfiGroup),
|
@@ -472,10 +474,10 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
472
474
|
solautoFeesSupplyTa:
|
473
475
|
rebalanceStep === "B" ? publicKey(this.solautoFeesSupplyTa) : undefined,
|
474
476
|
authorityReferralState: publicKey(
|
475
|
-
this.
|
477
|
+
this.referralState
|
476
478
|
),
|
477
|
-
referredBySupplyTa: this.referredBySupplyTa
|
478
|
-
? publicKey(this.referredBySupplyTa)
|
479
|
+
referredBySupplyTa: this.referredBySupplyTa()
|
480
|
+
? publicKey(this.referredBySupplyTa()!)
|
479
481
|
: undefined,
|
480
482
|
positionAuthority: publicKey(this.authority),
|
481
483
|
solautoPosition: publicKey(this.solautoPosition),
|
package/src/clients/txHandler.ts
CHANGED
@@ -7,9 +7,6 @@ export abstract class TxHandler {
|
|
7
7
|
public umi!: Umi;
|
8
8
|
public connection!: Connection;
|
9
9
|
|
10
|
-
public referredBy?: PublicKey;
|
11
|
-
public referredByState?: PublicKey;
|
12
|
-
|
13
10
|
constructor(
|
14
11
|
rpcUrl: string,
|
15
12
|
localTest?: boolean
|
@@ -31,6 +28,4 @@ export abstract class TxHandler {
|
|
31
28
|
abstract defaultLookupTables(): string[];
|
32
29
|
|
33
30
|
abstract resetLiveTxUpdates(success?: boolean): Promise<void>;
|
34
|
-
|
35
|
-
abstract setReferredBy(referredBy?: PublicKey): void;
|
36
31
|
}
|
@@ -57,7 +57,11 @@ import {
|
|
57
57
|
eligibleForRebalance,
|
58
58
|
positionStateWithLatestPrices,
|
59
59
|
} from "../utils/solauto/generalUtils";
|
60
|
-
import {
|
60
|
+
import {
|
61
|
+
getReferralState,
|
62
|
+
getTokenAccount,
|
63
|
+
getTokenAccountData,
|
64
|
+
} from "../utils/accountUtils";
|
61
65
|
import {
|
62
66
|
createMarginfiProgram,
|
63
67
|
getLendingAccountBorrowInstructionDataSerializer,
|
@@ -139,19 +143,15 @@ async function transactionChoresBefore(
|
|
139
143
|
let chores = transactionBuilder();
|
140
144
|
|
141
145
|
if (
|
142
|
-
client.
|
143
|
-
(client.
|
144
|
-
client.
|
146
|
+
client.referralStateData === null ||
|
147
|
+
(client.referredBy !== undefined &&
|
148
|
+
client.referralStateData?.referredByState ===
|
145
149
|
publicKey(PublicKey.default)) ||
|
146
150
|
(client.authorityLutAddress !== undefined &&
|
147
|
-
client.
|
148
|
-
publicKey(PublicKey.default))
|
151
|
+
client.referralStateData!.lookupTable == publicKey(PublicKey.default))
|
149
152
|
) {
|
150
153
|
chores = chores.add(
|
151
|
-
client.
|
152
|
-
undefined,
|
153
|
-
client.authorityLutAddress
|
154
|
-
)
|
154
|
+
client.updateReferralStatesIx(undefined, client.authorityLutAddress)
|
155
155
|
);
|
156
156
|
}
|
157
157
|
|
@@ -275,7 +275,7 @@ export async function rebalanceChoresBefore(
|
|
275
275
|
.some((t) => t.keys.some((k) => toWeb3JsPublicKey(k.pubkey).equals(key)));
|
276
276
|
|
277
277
|
const checkReferralSupplyTa =
|
278
|
-
client.referredBySupplyTa && usesAccount(client.referredBySupplyTa);
|
278
|
+
client.referredBySupplyTa() && usesAccount(client.referredBySupplyTa()!);
|
279
279
|
const checkSolautoFeesTa = usesAccount(client.solautoFeesSupplyTa);
|
280
280
|
const checkIntermediaryMfiAccount =
|
281
281
|
client.lendingPlatform === LendingPlatform.Marginfi &&
|
@@ -286,7 +286,9 @@ export async function rebalanceChoresBefore(
|
|
286
286
|
const checkSignerDebtTa = usesAccount(client.signerDebtTa);
|
287
287
|
|
288
288
|
const accountsNeeded = [
|
289
|
-
...[
|
289
|
+
...[
|
290
|
+
checkReferralSupplyTa ? client.referredBySupplyTa() : PublicKey.default,
|
291
|
+
],
|
290
292
|
...[checkSolautoFeesTa ? client.solautoFeesSupplyTa : PublicKey.default],
|
291
293
|
...[
|
292
294
|
checkIntermediaryMfiAccount
|
@@ -314,7 +316,7 @@ export async function rebalanceChoresBefore(
|
|
314
316
|
chores = chores.add(
|
315
317
|
createAssociatedTokenAccountUmiIx(
|
316
318
|
client.signer,
|
317
|
-
client.
|
319
|
+
client.referredByState!,
|
318
320
|
client.supplyMint
|
319
321
|
)
|
320
322
|
);
|
@@ -25,10 +25,10 @@ import { buildHeliusApiUrl } from "../../src/utils";
|
|
25
25
|
import { PriorityFeeSetting } from "../../src/types";
|
26
26
|
|
27
27
|
describe("Solauto Marginfi tests", async () => {
|
28
|
-
const signer = setupTest();
|
29
|
-
|
28
|
+
// const signer = setupTest();
|
29
|
+
const signer = setupTest("solauto-manager");
|
30
30
|
|
31
|
-
const payForTransactions =
|
31
|
+
const payForTransactions = false;
|
32
32
|
const useJitoBundle = false;
|
33
33
|
const positionId = 1;
|
34
34
|
|
@@ -128,7 +128,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
128
128
|
transactionItems.push(
|
129
129
|
new TransactionItem(
|
130
130
|
async (attemptNum) =>
|
131
|
-
await buildSolautoRebalanceTransaction(client,
|
131
|
+
await buildSolautoRebalanceTransaction(client, undefined, attemptNum),
|
132
132
|
"rebalance"
|
133
133
|
)
|
134
134
|
);
|