@haven-fi/solauto-sdk 1.0.81 → 1.0.82

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
1
  export * from './solautoMarginfiClient';
2
2
  export * from './solautoClient';
3
+ export * from './referralStateManager';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
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"}
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./solautoMarginfiClient"), exports);
18
18
  __exportStar(require("./solautoClient"), exports);
19
+ __exportStar(require("./referralStateManager"), exports);
@@ -0,0 +1,22 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { Signer, TransactionBuilder, Umi } from "@metaplex-foundation/umi";
3
+ import { WalletAdapter } from "@metaplex-foundation/umi-signer-wallet-adapters";
4
+ import { ReferralState } from "../generated";
5
+ interface ReferralStateManagerArgs {
6
+ referralAuthority?: PublicKey;
7
+ signer?: Signer;
8
+ wallet?: WalletAdapter;
9
+ }
10
+ export declare class ReferralStateManager {
11
+ umi: Umi;
12
+ signer: Signer;
13
+ referralAuthority: PublicKey;
14
+ referralState: PublicKey;
15
+ referralStateData: ReferralState | null;
16
+ constructor(heliusApiKey: string);
17
+ initialize(args: ReferralStateManagerArgs): Promise<void>;
18
+ updateReferralStatesIx(destFeesMint?: PublicKey, referredBy?: PublicKey, lookupTable?: PublicKey): TransactionBuilder;
19
+ claimReferralFeesIx(destFeesMint?: PublicKey): TransactionBuilder;
20
+ }
21
+ export {};
22
+ //# sourceMappingURL=referralStateManager.d.ts.map
@@ -0,0 +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;AAGpI,UAAU,wBAAwB;IAC9B,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED,qBAAa,oBAAoB;IACtB,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;IAS1B,UAAU,CAAC,IAAI,EAAE,wBAAwB;IAe/C,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;CAwBpE"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReferralStateManager = void 0;
4
+ const spl_token_1 = require("@solana/spl-token");
5
+ const umi_1 = require("@metaplex-foundation/umi");
6
+ const umi_web3js_adapters_1 = require("@metaplex-foundation/umi-web3js-adapters");
7
+ const umi_signer_wallet_adapters_1 = require("@metaplex-foundation/umi-signer-wallet-adapters");
8
+ const generated_1 = require("../generated");
9
+ const utils_1 = require("../utils");
10
+ class ReferralStateManager {
11
+ constructor(heliusApiKey) {
12
+ const [_, umi] = (0, utils_1.getSolanaRpcConnection)(heliusApiKey);
13
+ this.umi = umi.use({
14
+ install(umi) {
15
+ umi.programs.add((0, generated_1.createSolautoProgram)(), false);
16
+ },
17
+ });
18
+ }
19
+ async initialize(args) {
20
+ if (!args.signer && !args.wallet) {
21
+ throw new Error("Signer or wallet must be provided");
22
+ }
23
+ this.umi = this.umi.use(args.signer
24
+ ? (0, umi_1.signerIdentity)(args.signer)
25
+ : (0, umi_signer_wallet_adapters_1.walletAdapterIdentity)(args.wallet, true));
26
+ this.signer = this.umi.identity;
27
+ this.referralState = (0, utils_1.getReferralState)(args.referralAuthority ?? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey));
28
+ this.referralStateData = await (0, generated_1.safeFetchReferralState)(this.umi, (0, umi_1.publicKey)(this.referralState));
29
+ }
30
+ updateReferralStatesIx(destFeesMint, referredBy, lookupTable) {
31
+ return (0, generated_1.updateReferralStates)(this.umi, {
32
+ signer: this.signer,
33
+ signerReferralState: (0, umi_1.publicKey)(this.referralState),
34
+ referralFeesDestMint: destFeesMint ? (0, umi_1.publicKey)(destFeesMint) : null,
35
+ referredByState: referredBy
36
+ ? (0, umi_1.publicKey)((0, utils_1.getReferralState)(referredBy))
37
+ : undefined,
38
+ referredByAuthority: referredBy
39
+ ? (0, umi_1.publicKey)(referredBy)
40
+ : undefined,
41
+ addressLookupTable: lookupTable
42
+ ? (0, umi_1.publicKey)(lookupTable)
43
+ : null,
44
+ });
45
+ }
46
+ claimReferralFeesIx(destFeesMint) {
47
+ const referralFeesDestMint = destFeesMint ?? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.referralStateData.destFeesMint);
48
+ const referralDestTa = (0, utils_1.getTokenAccount)(this.referralState, referralFeesDestMint);
49
+ const feesDestinationTa = referralFeesDestMint !== spl_token_1.NATIVE_MINT
50
+ ? (0, umi_1.publicKey)((0, utils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), referralFeesDestMint))
51
+ : undefined;
52
+ return (0, generated_1.claimReferralFees)(this.umi, {
53
+ signer: this.signer,
54
+ signerWsolTa: (0, umi_1.publicKey)((0, utils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), spl_token_1.NATIVE_MINT)),
55
+ referralAuthority: (0, umi_1.publicKey)(this.referralAuthority),
56
+ referralState: (0, umi_1.publicKey)(this.referralState),
57
+ referralFeesDestTa: (0, umi_1.publicKey)(referralDestTa),
58
+ referralFeesDestMint: (0, umi_1.publicKey)(referralFeesDestMint),
59
+ feesDestinationTa,
60
+ });
61
+ }
62
+ }
63
+ exports.ReferralStateManager = ReferralStateManager;
@@ -2,10 +2,11 @@ import "rpc-websockets/dist/lib/client";
2
2
  import { Connection, PublicKey } from "@solana/web3.js";
3
3
  import { Signer, TransactionBuilder, Umi } from "@metaplex-foundation/umi";
4
4
  import { WalletAdapter } from "@metaplex-foundation/umi-signer-wallet-adapters";
5
- import { DCASettings, DCASettingsInpArgs, LendingPlatform, PositionState, ReferralState, SolautoActionArgs, SolautoPosition, SolautoRebalanceTypeArgs, SolautoSettingsParameters, SolautoSettingsParametersInpArgs, UpdatePositionDataArgs } from "../generated";
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
+ import { ReferralStateManager } from "./referralStateManager";
9
10
  export interface SolautoClientArgs {
10
11
  authority?: PublicKey;
11
12
  positionId: number;
@@ -13,11 +14,11 @@ export interface SolautoClientArgs {
13
14
  wallet?: WalletAdapter;
14
15
  supplyMint?: PublicKey;
15
16
  debtMint?: PublicKey;
16
- referralFeesDestMint?: PublicKey;
17
17
  referredByAuthority?: PublicKey;
18
18
  }
19
19
  export declare abstract class SolautoClient {
20
20
  localTest?: boolean | undefined;
21
+ private heliusApiKey;
21
22
  umi: Umi;
22
23
  connection: Connection;
23
24
  lendingPlatform: LendingPlatform;
@@ -34,10 +35,7 @@ export declare abstract class SolautoClient {
34
35
  debtMint: PublicKey;
35
36
  positionDebtTa: PublicKey;
36
37
  signerDebtTa: PublicKey;
37
- authorityReferralState: PublicKey;
38
- authorityReferralStateData: ReferralState | null;
39
- authorityReferralFeesDestMint: PublicKey;
40
- authorityReferralDestTa: PublicKey;
38
+ referralStateManager: ReferralStateManager;
41
39
  referredByState?: PublicKey;
42
40
  referredByAuthority?: PublicKey;
43
41
  referredBySupplyTa?: PublicKey;
@@ -59,8 +57,6 @@ export declare abstract class SolautoClient {
59
57
  } | undefined>;
60
58
  solautoPositionSettings(): SolautoSettingsParameters | undefined;
61
59
  solautoPositionActiveDca(): DCASettings | undefined;
62
- updateReferralStatesIx(): TransactionBuilder;
63
- claimReferralFeesIx(): TransactionBuilder;
64
60
  openPosition(settingParams?: SolautoSettingsParametersInpArgs, dca?: DCASettingsInpArgs): TransactionBuilder;
65
61
  updatePositionIx(args: UpdatePositionDataArgs): TransactionBuilder;
66
62
  closePositionIx(): TransactionBuilder;
@@ -1 +1 @@
1
- {"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAEL,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAQJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf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}
@@ -10,15 +10,16 @@ const generated_1 = require("../generated");
10
10
  const accountUtils_1 = require("../utils/accountUtils");
11
11
  const generalAccounts_1 = require("../constants/generalAccounts");
12
12
  const solanaUtils_1 = require("../utils/solanaUtils");
13
- const spl_token_1 = require("@solana/spl-token");
14
13
  const solautoConstants_1 = require("../constants/solautoConstants");
15
14
  const generalUtils_1 = require("../utils/generalUtils");
16
15
  const generalUtils_2 = require("../utils/solauto/generalUtils");
16
+ const referralStateManager_1 = require("./referralStateManager");
17
17
  class SolautoClient {
18
18
  constructor(heliusApiKey, localTest) {
19
19
  this.localTest = localTest;
20
20
  this.livePositionUpdates = new generalUtils_2.LivePositionUpdates();
21
- const [connection, umi] = (0, solanaUtils_1.getSolanaRpcConnection)(heliusApiKey);
21
+ this.heliusApiKey = heliusApiKey;
22
+ const [connection, umi] = (0, solanaUtils_1.getSolanaRpcConnection)(this.heliusApiKey);
22
23
  this.connection = connection;
23
24
  this.umi = umi.use({
24
25
  install(umi) {
@@ -38,7 +39,7 @@ class SolautoClient {
38
39
  this.positionId = args.positionId;
39
40
  this.selfManaged = this.positionId === 0;
40
41
  this.lendingPlatform = lendingPlatform;
41
- this.solautoPosition = await (0, accountUtils_1.getSolautoPositionAccount)(this.authority, this.positionId);
42
+ this.solautoPosition = (0, accountUtils_1.getSolautoPositionAccount)(this.authority, this.positionId);
42
43
  this.solautoPositionData = await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition));
43
44
  this.solautoPositionState = this.solautoPositionData?.state;
44
45
  this.supplyMint =
@@ -51,16 +52,15 @@ class SolautoClient {
51
52
  (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.solautoPositionData.position.debtMint);
52
53
  this.positionDebtTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.debtMint);
53
54
  this.signerDebtTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.debtMint);
54
- this.authorityReferralState = await (0, accountUtils_1.getReferralState)(this.authority);
55
- this.authorityReferralStateData = await (0, generated_1.safeFetchReferralState)(this.umi, (0, umi_1.publicKey)(this.authorityReferralState));
56
- this.authorityReferralFeesDestMint = args.referralFeesDestMint
57
- ? args.referralFeesDestMint
58
- : this.authorityReferralStateData?.destFeesMint
59
- ? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.authorityReferralStateData?.destFeesMint)
60
- : spl_token_1.NATIVE_MINT;
61
- this.authorityReferralDestTa = (0, accountUtils_1.getTokenAccount)(this.authorityReferralState, this.authorityReferralFeesDestMint);
62
- const hasReferredBy = this.authorityReferralStateData &&
63
- this.authorityReferralStateData.referredByState !==
55
+ this.referralStateManager = new referralStateManager_1.ReferralStateManager(this.heliusApiKey);
56
+ await this.referralStateManager.initialize({
57
+ referralAuthority: this.authority,
58
+ signer: args.signer,
59
+ wallet: args.wallet
60
+ });
61
+ const authorityReferralStateData = this.referralStateManager.referralStateData;
62
+ const hasReferredBy = authorityReferralStateData &&
63
+ authorityReferralStateData.referredByState !==
64
64
  (0, umi_1.publicKey)(web3_js_1.PublicKey.default);
65
65
  const referredByAuthority = !hasReferredBy &&
66
66
  args.referredByAuthority &&
@@ -68,9 +68,9 @@ class SolautoClient {
68
68
  ? args.referredByAuthority
69
69
  : undefined;
70
70
  this.referredByState = hasReferredBy
71
- ? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.authorityReferralStateData.referredByState)
71
+ ? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(authorityReferralStateData.referredByState)
72
72
  : referredByAuthority
73
- ? await (0, accountUtils_1.getReferralState)(referredByAuthority)
73
+ ? (0, accountUtils_1.getReferralState)(referredByAuthority)
74
74
  : undefined;
75
75
  this.referredByAuthority = referredByAuthority;
76
76
  if (this.referredByState !== undefined) {
@@ -78,8 +78,8 @@ class SolautoClient {
78
78
  }
79
79
  this.solautoFeesWallet = generalAccounts_1.SOLAUTO_FEES_WALLET;
80
80
  this.solautoFeesSupplyTa = (0, accountUtils_1.getTokenAccount)(this.solautoFeesWallet, this.supplyMint);
81
- this.authorityLutAddress = this.authorityReferralStateData?.lookupTable
82
- ? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.authorityReferralStateData?.lookupTable)
81
+ this.authorityLutAddress = authorityReferralStateData?.lookupTable
82
+ ? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(authorityReferralStateData?.lookupTable)
83
83
  : undefined;
84
84
  this.upToDateLutAccounts = (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey).equals(this.authority)
85
85
  ? await this.fetchExistingAuthorityLutAccounts()
@@ -128,7 +128,7 @@ class SolautoClient {
128
128
  this.solautoPosition,
129
129
  this.positionSupplyTa,
130
130
  this.positionDebtTa,
131
- this.authorityReferralState,
131
+ this.referralStateManager.referralState,
132
132
  ...(this.referredBySupplyTa ? [this.referredBySupplyTa] : []),
133
133
  ];
134
134
  }
@@ -186,36 +186,6 @@ class SolautoClient {
186
186
  return (this.livePositionUpdates.activeDca ??
187
187
  this.solautoPositionData?.position.dca);
188
188
  }
189
- updateReferralStatesIx() {
190
- return (0, generated_1.updateReferralStates)(this.umi, {
191
- signer: this.signer,
192
- signerReferralState: (0, umi_1.publicKey)(this.authorityReferralState),
193
- referralFeesDestMint: (0, umi_1.publicKey)(this.authorityReferralFeesDestMint),
194
- referredByState: this.referredByState
195
- ? (0, umi_1.publicKey)(this.referredByState)
196
- : undefined,
197
- referredByAuthority: this.referredByAuthority
198
- ? (0, umi_1.publicKey)(this.referredByAuthority)
199
- : undefined,
200
- addressLookupTable: this.authorityLutAddress
201
- ? (0, umi_1.some)((0, umi_1.publicKey)(this.authorityLutAddress))
202
- : null,
203
- });
204
- }
205
- claimReferralFeesIx() {
206
- const feesDestinationTa = this.authorityReferralFeesDestMint !== spl_token_1.NATIVE_MINT
207
- ? (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.authorityReferralFeesDestMint))
208
- : undefined;
209
- return (0, generated_1.claimReferralFees)(this.umi, {
210
- signer: this.signer,
211
- signerWsolTa: (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), spl_token_1.NATIVE_MINT)),
212
- referralAuthority: (0, umi_1.publicKey)(this.authorityReferralStateData.authority),
213
- referralState: (0, umi_1.publicKey)(this.authorityReferralState),
214
- referralFeesDestTa: (0, umi_1.publicKey)(this.authorityReferralDestTa),
215
- referralFeesDestMint: (0, umi_1.publicKey)(this.authorityReferralFeesDestMint),
216
- feesDestinationTa,
217
- });
218
- }
219
189
  openPosition(settingParams, dca) {
220
190
  if (dca && dca.debtToAddBaseUnit > 0) {
221
191
  this.livePositionUpdates.new({
@@ -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,EAGL,eAAe,EAYhB,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,EAA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G,qBAAqB,CAAC;IAE7C,iBAAiB,EAAG,SAAS,CAAC;IAC9B,eAAe,EAAG,SAAS,CAAC;IAG5B,iCAAiC,CAAC,EAAE,MAAM,CAAC;IAC3C,6BAA6B,EAAG,SAAS,CAAC;IAC1C,2BAA2B,CAAC,EAAE,eAAe,CAAC;IAE/C,UAAU,CAAC,IAAI,EAAE,yBAAyB;IAkE1C,8BAA8B;IA0CpC,mBAAmB,IAAI,MAAM,EAAE;IAI/B,gBAAgB,IAAI,SAAS,EAAE;IAU/B,yBAAyB,IAAI,kBAAkB;IAS/C,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA8C9B,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,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IA2DrB,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;CAiBlE"}
@@ -118,7 +118,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
118
118
  solautoManager: (0, umi_1.publicKey)(constants_1.SOLAUTO_MANAGER),
119
119
  solautoFeesWallet: (0, umi_1.publicKey)(this.solautoFeesWallet),
120
120
  solautoFeesSupplyTa: (0, umi_1.publicKey)(this.solautoFeesSupplyTa),
121
- signerReferralState: (0, umi_1.publicKey)(this.authorityReferralState),
121
+ signerReferralState: (0, umi_1.publicKey)(this.referralStateManager.referralState),
122
122
  referredByState: this.referredByState
123
123
  ? (0, umi_1.publicKey)(this.referredByState)
124
124
  : undefined,
@@ -281,7 +281,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
281
281
  marginfiProgram: (0, umi_1.publicKey)(marginfi_sdk_1.MARGINFI_PROGRAM_ID),
282
282
  ixsSysvar: (0, umi_1.publicKey)(web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY),
283
283
  solautoFeesSupplyTa: rebalanceStep === "B" ? (0, umi_1.publicKey)(this.solautoFeesSupplyTa) : undefined,
284
- authorityReferralState: (0, umi_1.publicKey)(this.authorityReferralState),
284
+ authorityReferralState: (0, umi_1.publicKey)(this.referralStateManager.referralState),
285
285
  referredBySupplyTa: this.referredBySupplyTa
286
286
  ? (0, umi_1.publicKey)(this.referredBySupplyTa)
287
287
  : undefined,
@@ -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;IACE,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACD,SAAS,CACZ,CA2HA;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"}
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,CA2HA;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"}
@@ -47,14 +47,14 @@ function getWSolUsage(client, solautoActions, initiatingDcaIn, cancellingDcaIn)
47
47
  }
48
48
  async function transactionChoresBefore(client, accountsGettingCreated, solautoActions, initiatingDcaIn) {
49
49
  let chores = (0, umi_1.transactionBuilder)();
50
- if (client.authorityReferralStateData === null ||
50
+ if (client.referralStateManager.referralState === null ||
51
51
  (client.referredByState !== undefined &&
52
- client.authorityReferralStateData.referredByState ===
52
+ client.referralStateManager.referralStateData.referredByState ===
53
53
  (0, umi_1.publicKey)(web3_js_1.PublicKey.default)) ||
54
54
  (client.authorityLutAddress !== undefined &&
55
- client.authorityReferralStateData.lookupTable ==
55
+ client.referralStateManager.referralStateData.lookupTable ==
56
56
  (0, umi_1.publicKey)(web3_js_1.PublicKey.default))) {
57
- chores = chores.add(client.updateReferralStatesIx());
57
+ chores = chores.add(client.referralStateManager.updateReferralStatesIx(undefined, client.referredByAuthority, client.authorityLutAddress));
58
58
  }
59
59
  if (client.selfManaged) {
60
60
  if (client.solautoPositionData === null) {
@@ -1 +1 @@
1
- {"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EAGvB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG9C,cAAM,YAAY;IAIJ,OAAO,CAAC,MAAM;IAH1B,WAAW,EAAE,MAAM,EAAE,CAAM;I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AY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,UAAU,eAAe;CAC1B;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,EAAE,CAAC;AAEJ,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,cAAc,CAAC;IACvB,OAAO,CAAC,YAAY,CAAC;IACrB,OAAO,CAAC,YAAY,CAAC;IACrB,OAAO,CAAC,aAAa,CAAC;IATxB,OAAO,CAAC,QAAQ,CAAkC;IAClD,OAAO,CAAC,YAAY,CAAe;gBAGzB,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,eAAe,EAAE,EACxB,cAAc,CAAC,GAAE,CAAC,QAAQ,EAAE,0BAA0B,KAAK,IAAI,aAAA,EAC/D,YAAY,CAAC,EAAE,OAAO,YAAA,EACtB,YAAY,CAAC,EAAE,OAAO,YAAA,EACtB,aAAa,CAAC,EAAE,aAAa,YAAA;YAKzB,uBAAuB;IAsCrC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,KAAK,CAAC,EAAE,MAAM;IAiB9D,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,kBAAkB;IAkB7D,IAAI,CAAC,eAAe,CAAC,EAAE,kBAAkB;CA6JhD"}
@@ -141,11 +141,7 @@ class TransactionsManager {
141
141
  }
142
142
  const transaction = item.tx.setAddressLookupTables(await this.lookupTables.getLutInputs(item.lookupTableAddresses));
143
143
  if (!transaction.fitsInOneTransaction(this.client.umi)) {
144
- // TODO: revert me
145
- // throw new Error(
146
- // `Transaction exceeds max transaction size (${transaction.getTransactionSize(this.client.umi)})`
147
- // );
148
- transactionSets.push(new TransactionSet(this.client, this.lookupTables, [item]));
144
+ throw new Error(`Transaction exceeds max transaction size (${transaction.getTransactionSize(this.client.umi)})`);
149
145
  }
150
146
  else {
151
147
  let newSet = new TransactionSet(this.client, this.lookupTables, [item]);
@@ -3,7 +3,7 @@ export declare function bufferFromU8(num: number): Buffer;
3
3
  export declare function bufferFromU64(num: bigint): Buffer;
4
4
  export declare function getTokenAccount(wallet: PublicKey, tokenMint: PublicKey): PublicKey;
5
5
  export declare function getTokenAccounts(wallet: PublicKey, tokenMints: PublicKey[]): PublicKey[];
6
- export declare function getSolautoPositionAccount(signer: PublicKey, positionId: number): Promise<PublicKey>;
7
- export declare function getReferralState(authority: PublicKey): Promise<PublicKey>;
6
+ export declare function getSolautoPositionAccount(signer: PublicKey, positionId: number): PublicKey;
7
+ export declare function getReferralState(authority: PublicKey): PublicKey;
8
8
  export declare function getMarginfiAccountPDA(solautoPositionAccount: PublicKey, marginfiAccountSeedIdx: bigint): Promise<PublicKey>;
9
9
  //# sourceMappingURL=accountUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"accountUtils.d.ts","sourceRoot":"","sources":["../../src/utils/accountUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIjD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,CAMlF;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAExF;AAED,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,MAAM,sBAQnB;AAED,wBAAsB,gBAAgB,CAAC,SAAS,EAAE,SAAS,sBAU1D;AAED,wBAAsB,qBAAqB,CACzC,sBAAsB,EAAE,SAAS,EACjC,sBAAsB,EAAE,MAAM,sBAa/B"}
1
+ {"version":3,"file":"accountUtils.d.ts","sourceRoot":"","sources":["../../src/utils/accountUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIjD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,CAMlF;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAExF;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,MAAM,aAQnB;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,aAUpD;AAED,wBAAsB,qBAAqB,CACzC,sBAAsB,EAAE,SAAS,EACjC,sBAAsB,EAAE,MAAM,sBAa/B"}
@@ -26,14 +26,14 @@ function getTokenAccount(wallet, tokenMint) {
26
26
  function getTokenAccounts(wallet, tokenMints) {
27
27
  return tokenMints.map(x => getTokenAccount(wallet, x));
28
28
  }
29
- async function getSolautoPositionAccount(signer, positionId) {
30
- const [positionAccount, _] = await web3_js_1.PublicKey.findProgramAddress([bufferFromU8(positionId), signer.toBuffer()], new web3_js_1.PublicKey(generated_1.SOLAUTO_PROGRAM_ID));
29
+ function getSolautoPositionAccount(signer, positionId) {
30
+ const [positionAccount, _] = web3_js_1.PublicKey.findProgramAddressSync([bufferFromU8(positionId), signer.toBuffer()], new web3_js_1.PublicKey(generated_1.SOLAUTO_PROGRAM_ID));
31
31
  return positionAccount;
32
32
  }
33
- async function getReferralState(authority) {
33
+ function getReferralState(authority) {
34
34
  const str = "referral_state";
35
35
  const strBuffer = Buffer.from(str, "utf-8");
36
- const [ReferralState, _] = await web3_js_1.PublicKey.findProgramAddress([strBuffer, authority.toBuffer()], new web3_js_1.PublicKey(generated_1.SOLAUTO_PROGRAM_ID));
36
+ const [ReferralState, _] = web3_js_1.PublicKey.findProgramAddressSync([strBuffer, authority.toBuffer()], new web3_js_1.PublicKey(generated_1.SOLAUTO_PROGRAM_ID));
37
37
  return ReferralState;
38
38
  }
39
39
  async function getMarginfiAccountPDA(solautoPositionAccount, marginfiAccountSeedIdx) {
@@ -165,7 +165,7 @@ async function getReferralsByUser(umi, user) {
165
165
  // padding: [u8; 7],
166
166
  // authority: Pubkey,
167
167
  // referred_by_state: Pubkey,
168
- const userReferralState = await (0, accountUtils_1.getReferralState)(user);
168
+ const userReferralState = (0, accountUtils_1.getReferralState)(user);
169
169
  const accounts = await umi.rpc.getProgramAccounts(generated_1.SOLAUTO_PROGRAM_ID, {
170
170
  commitment: "finalized",
171
171
  dataSlice: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.81",
3
+ "version": "1.0.82",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Typescript SDK for the Solauto program on the Solana blockchain",
@@ -1,2 +1,3 @@
1
1
  export * from './solautoMarginfiClient';
2
- export * from './solautoClient';
2
+ export * from './solautoClient';
3
+ export * from './referralStateManager';
@@ -0,0 +1,88 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { NATIVE_MINT } from "@solana/spl-token";
3
+ import { publicKey, Signer, signerIdentity, TransactionBuilder, Umi } from "@metaplex-foundation/umi";
4
+ import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
5
+ import { WalletAdapter, walletAdapterIdentity } from "@metaplex-foundation/umi-signer-wallet-adapters";
6
+ import { claimReferralFees, createSolautoProgram, ReferralState, safeFetchReferralState, updateReferralStates } from "../generated";
7
+ import { getReferralState, getSolanaRpcConnection, getTokenAccount } from "../utils";
8
+
9
+ interface ReferralStateManagerArgs {
10
+ referralAuthority?: PublicKey;
11
+ signer?: Signer;
12
+ wallet?: WalletAdapter;
13
+ }
14
+
15
+ export class ReferralStateManager {
16
+ public umi!: Umi;
17
+ public signer!: Signer;
18
+
19
+ public referralAuthority!: PublicKey;
20
+ public referralState!: PublicKey;
21
+ public referralStateData!: ReferralState | null;
22
+
23
+ constructor(heliusApiKey: string) {
24
+ const [_, umi] = getSolanaRpcConnection(heliusApiKey);
25
+ this.umi = umi.use({
26
+ install(umi) {
27
+ umi.programs.add(createSolautoProgram(), false);
28
+ },
29
+ });
30
+ }
31
+
32
+ async initialize(args: ReferralStateManagerArgs) {
33
+ if (!args.signer && !args.wallet) {
34
+ throw new Error("Signer or wallet must be provided");
35
+ }
36
+ this.umi = this.umi.use(
37
+ args.signer
38
+ ? signerIdentity(args.signer)
39
+ : walletAdapterIdentity(args.wallet!, true)
40
+ );
41
+
42
+ this.signer = this.umi.identity;
43
+ this.referralState = getReferralState(args.referralAuthority ?? toWeb3JsPublicKey(this.signer.publicKey));
44
+ this.referralStateData = await safeFetchReferralState(this.umi, publicKey(this.referralState));
45
+ }
46
+
47
+ updateReferralStatesIx(destFeesMint?: PublicKey, referredBy?: PublicKey, lookupTable?: PublicKey): TransactionBuilder {
48
+ return updateReferralStates(this.umi, {
49
+ signer: this.signer,
50
+ signerReferralState: publicKey(this.referralState),
51
+ referralFeesDestMint: destFeesMint ? publicKey(destFeesMint) : null,
52
+ referredByState: referredBy
53
+ ? publicKey(getReferralState(referredBy))
54
+ : undefined,
55
+ referredByAuthority: referredBy
56
+ ? publicKey(referredBy)
57
+ : undefined,
58
+ addressLookupTable: lookupTable
59
+ ? publicKey(lookupTable)
60
+ : null,
61
+ });
62
+ }
63
+
64
+ claimReferralFeesIx(destFeesMint?: PublicKey): TransactionBuilder {
65
+ const referralFeesDestMint = destFeesMint ?? toWeb3JsPublicKey(this.referralStateData!.destFeesMint);
66
+ const referralDestTa = getTokenAccount(this.referralState, referralFeesDestMint);
67
+ const feesDestinationTa =
68
+ referralFeesDestMint !== NATIVE_MINT
69
+ ? publicKey(
70
+ getTokenAccount(
71
+ toWeb3JsPublicKey(this.signer.publicKey),
72
+ referralFeesDestMint
73
+ )
74
+ )
75
+ : undefined;
76
+
77
+ return claimReferralFees(this.umi, {
78
+ signer: this.signer,
79
+ signerWsolTa: publicKey(getTokenAccount(toWeb3JsPublicKey(this.signer.publicKey), NATIVE_MINT)),
80
+ referralAuthority: publicKey(this.referralAuthority),
81
+ referralState: publicKey(this.referralState),
82
+ referralFeesDestTa: publicKey(referralDestTa),
83
+ referralFeesDestMint: publicKey(referralFeesDestMint),
84
+ feesDestinationTa,
85
+ });
86
+ }
87
+
88
+ }
@@ -14,7 +14,6 @@ import {
14
14
  isSome,
15
15
  transactionBuilder,
16
16
  signerIdentity,
17
- some,
18
17
  } from "@metaplex-foundation/umi";
19
18
  import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
20
19
  import {
@@ -26,7 +25,6 @@ import {
26
25
  DCASettingsInpArgs,
27
26
  LendingPlatform,
28
27
  PositionState,
29
- ReferralState,
30
28
  SolautoActionArgs,
31
29
  SolautoPosition,
32
30
  SolautoRebalanceTypeArgs,
@@ -34,13 +32,10 @@ import {
34
32
  SolautoSettingsParametersInpArgs,
35
33
  UpdatePositionDataArgs,
36
34
  cancelDCA,
37
- claimReferralFees,
38
35
  closePosition,
39
36
  createSolautoProgram,
40
- safeFetchReferralState,
41
37
  safeFetchSolautoPosition,
42
38
  updatePosition,
43
- updateReferralStates,
44
39
  } from "../generated";
45
40
  import {
46
41
  getReferralState,
@@ -64,6 +59,7 @@ import {
64
59
  } from "../constants/solautoConstants";
65
60
  import { currentUnixSeconds } from "../utils/generalUtils";
66
61
  import { LivePositionUpdates } from "../utils/solauto/generalUtils";
62
+ import { ReferralStateManager } from "./referralStateManager";
67
63
 
68
64
  export interface SolautoClientArgs {
69
65
  authority?: PublicKey;
@@ -74,11 +70,11 @@ export interface SolautoClientArgs {
74
70
  supplyMint?: PublicKey;
75
71
  debtMint?: PublicKey;
76
72
 
77
- referralFeesDestMint?: PublicKey;
78
73
  referredByAuthority?: PublicKey;
79
74
  }
80
75
 
81
76
  export abstract class SolautoClient {
77
+ private heliusApiKey!: string;
82
78
  public umi!: Umi;
83
79
  public connection!: Connection;
84
80
  public lendingPlatform!: LendingPlatform;
@@ -100,10 +96,7 @@ export abstract class SolautoClient {
100
96
  public positionDebtTa!: PublicKey;
101
97
  public signerDebtTa!: PublicKey;
102
98
 
103
- public authorityReferralState!: PublicKey;
104
- public authorityReferralStateData!: ReferralState | null;
105
- public authorityReferralFeesDestMint!: PublicKey;
106
- public authorityReferralDestTa!: PublicKey;
99
+ public referralStateManager!: ReferralStateManager;
107
100
 
108
101
  public referredByState?: PublicKey;
109
102
  public referredByAuthority?: PublicKey;
@@ -121,7 +114,8 @@ export abstract class SolautoClient {
121
114
  heliusApiKey: string,
122
115
  public localTest?: boolean
123
116
  ) {
124
- const [connection, umi] = getSolanaRpcConnection(heliusApiKey);
117
+ this.heliusApiKey = heliusApiKey;
118
+ const [connection, umi] = getSolanaRpcConnection(this.heliusApiKey);
125
119
  this.connection = connection;
126
120
  this.umi = umi.use({
127
121
  install(umi) {
@@ -146,7 +140,7 @@ export abstract class SolautoClient {
146
140
  this.positionId = args.positionId;
147
141
  this.selfManaged = this.positionId === 0;
148
142
  this.lendingPlatform = lendingPlatform;
149
- this.solautoPosition = await getSolautoPositionAccount(
143
+ this.solautoPosition = getSolautoPositionAccount(
150
144
  this.authority,
151
145
  this.positionId
152
146
  );
@@ -177,35 +171,28 @@ export abstract class SolautoClient {
177
171
  this.debtMint
178
172
  );
179
173
 
180
- this.authorityReferralState = await getReferralState(this.authority);
181
- this.authorityReferralStateData = await safeFetchReferralState(
182
- this.umi,
183
- publicKey(this.authorityReferralState)
184
- );
185
- this.authorityReferralFeesDestMint = args.referralFeesDestMint
186
- ? args.referralFeesDestMint
187
- : this.authorityReferralStateData?.destFeesMint
188
- ? toWeb3JsPublicKey(this.authorityReferralStateData?.destFeesMint)
189
- : NATIVE_MINT;
190
- this.authorityReferralDestTa = getTokenAccount(
191
- this.authorityReferralState,
192
- this.authorityReferralFeesDestMint
193
- );
174
+ this.referralStateManager = new ReferralStateManager(this.heliusApiKey)
175
+ await this.referralStateManager.initialize({
176
+ referralAuthority: this.authority,
177
+ signer: args.signer,
178
+ wallet: args.wallet
179
+ });
194
180
 
181
+ const authorityReferralStateData = this.referralStateManager.referralStateData;
195
182
  const hasReferredBy =
196
- this.authorityReferralStateData &&
197
- this.authorityReferralStateData.referredByState !==
198
- publicKey(PublicKey.default);
183
+ authorityReferralStateData &&
184
+ authorityReferralStateData.referredByState !==
185
+ publicKey(PublicKey.default);
199
186
  const referredByAuthority =
200
187
  !hasReferredBy &&
201
- args.referredByAuthority &&
202
- !args.referredByAuthority.equals(toWeb3JsPublicKey(this.signer.publicKey))
188
+ args.referredByAuthority &&
189
+ !args.referredByAuthority.equals(toWeb3JsPublicKey(this.signer.publicKey))
203
190
  ? args.referredByAuthority
204
191
  : undefined;
205
192
  this.referredByState = hasReferredBy
206
- ? toWeb3JsPublicKey(this.authorityReferralStateData!.referredByState)
193
+ ? toWeb3JsPublicKey(authorityReferralStateData!.referredByState)
207
194
  : referredByAuthority
208
- ? await getReferralState(referredByAuthority!)
195
+ ? getReferralState(referredByAuthority!)
209
196
  : undefined;
210
197
  this.referredByAuthority = referredByAuthority;
211
198
  if (this.referredByState !== undefined) {
@@ -221,8 +208,8 @@ export abstract class SolautoClient {
221
208
  this.supplyMint
222
209
  );
223
210
 
224
- this.authorityLutAddress = this.authorityReferralStateData?.lookupTable
225
- ? toWeb3JsPublicKey(this.authorityReferralStateData?.lookupTable)
211
+ this.authorityLutAddress = authorityReferralStateData?.lookupTable
212
+ ? toWeb3JsPublicKey(authorityReferralStateData?.lookupTable)
226
213
  : undefined;
227
214
  this.upToDateLutAccounts = toWeb3JsPublicKey(this.signer.publicKey).equals(
228
215
  this.authority
@@ -286,7 +273,7 @@ export abstract class SolautoClient {
286
273
  this.solautoPosition,
287
274
  this.positionSupplyTa,
288
275
  this.positionDebtTa,
289
- this.authorityReferralState,
276
+ this.referralStateManager.referralState,
290
277
  ...(this.referredBySupplyTa ? [this.referredBySupplyTa] : []),
291
278
  ];
292
279
  }
@@ -353,7 +340,7 @@ export abstract class SolautoClient {
353
340
  const addingReferredBy =
354
341
  accountsToAdd.length === 1 &&
355
342
  accountsToAdd[0].toString().toLowerCase() ===
356
- this.referredBySupplyTa?.toString().toLowerCase();
343
+ this.referredBySupplyTa?.toString().toLowerCase();
357
344
 
358
345
  if (tx.getInstructions().length > 0) {
359
346
  this.log("Updating authority lookup table...");
@@ -376,44 +363,6 @@ export abstract class SolautoClient {
376
363
  );
377
364
  }
378
365
 
379
- updateReferralStatesIx(): TransactionBuilder {
380
- return updateReferralStates(this.umi, {
381
- signer: this.signer,
382
- signerReferralState: publicKey(this.authorityReferralState),
383
- referralFeesDestMint: publicKey(this.authorityReferralFeesDestMint),
384
- referredByState: this.referredByState
385
- ? publicKey(this.referredByState)
386
- : undefined,
387
- referredByAuthority: this.referredByAuthority
388
- ? publicKey(this.referredByAuthority)
389
- : undefined,
390
- addressLookupTable: this.authorityLutAddress
391
- ? some(publicKey(this.authorityLutAddress))
392
- : null,
393
- });
394
- }
395
-
396
- claimReferralFeesIx(): TransactionBuilder {
397
- const feesDestinationTa =
398
- this.authorityReferralFeesDestMint !== NATIVE_MINT
399
- ? publicKey(
400
- getTokenAccount(
401
- toWeb3JsPublicKey(this.signer.publicKey),
402
- this.authorityReferralFeesDestMint
403
- )
404
- )
405
- : undefined;
406
- return claimReferralFees(this.umi, {
407
- signer: this.signer,
408
- signerWsolTa: publicKey(getTokenAccount(toWeb3JsPublicKey(this.signer.publicKey), NATIVE_MINT)),
409
- referralAuthority: publicKey(this.authorityReferralStateData!.authority),
410
- referralState: publicKey(this.authorityReferralState),
411
- referralFeesDestTa: publicKey(this.authorityReferralDestTa),
412
- referralFeesDestMint: publicKey(this.authorityReferralFeesDestMint),
413
- feesDestinationTa,
414
- });
415
- }
416
-
417
366
  openPosition(
418
367
  settingParams?: SolautoSettingsParametersInpArgs,
419
368
  dca?: DCASettingsInpArgs
@@ -575,7 +524,7 @@ export abstract class SolautoClient {
575
524
  BigInt(
576
525
  Math.round(
577
526
  Number(this.solautoPositionState!.debt.amountUsed.baseUnit) *
578
- 1.01
527
+ 1.01
579
528
  )
580
529
  )
581
530
  )
@@ -647,7 +596,7 @@ export abstract class SolautoClient {
647
596
  if (
648
597
  Boolean(this.solautoPositionState) &&
649
598
  Number(this.solautoPositionState!.lastUpdated) >
650
- currentUnixSeconds() - MIN_POSITION_STATE_FRESHNESS_SECS &&
599
+ currentUnixSeconds() - MIN_POSITION_STATE_FRESHNESS_SECS &&
651
600
  !this.livePositionUpdates.hasUpdates()
652
601
  ) {
653
602
  return this.solautoPositionState;
@@ -44,9 +44,7 @@ import {
44
44
  lendingAccountStartFlashloan,
45
45
  lendingAccountWithdraw,
46
46
  marginfiAccountInitialize,
47
- safeFetchAllBank,
48
47
  safeFetchAllMarginfiAccount,
49
- safeFetchBank,
50
48
  safeFetchMarginfiAccount,
51
49
  } from "../marginfi-sdk";
52
50
  import { JupSwapDetails } from "../utils/jupiterUtils";
@@ -243,7 +241,7 @@ export class SolautoMarginfiClient extends SolautoClient {
243
241
  solautoManager: publicKey(SOLAUTO_MANAGER),
244
242
  solautoFeesWallet: publicKey(this.solautoFeesWallet),
245
243
  solautoFeesSupplyTa: publicKey(this.solautoFeesSupplyTa),
246
- signerReferralState: publicKey(this.authorityReferralState),
244
+ signerReferralState: publicKey(this.referralStateManager.referralState),
247
245
  referredByState: this.referredByState
248
246
  ? publicKey(this.referredByState)
249
247
  : undefined,
@@ -448,7 +446,7 @@ export class SolautoMarginfiClient extends SolautoClient {
448
446
  ixsSysvar: publicKey(SYSVAR_INSTRUCTIONS_PUBKEY),
449
447
  solautoFeesSupplyTa:
450
448
  rebalanceStep === "B" ? publicKey(this.solautoFeesSupplyTa) : undefined,
451
- authorityReferralState: publicKey(this.authorityReferralState),
449
+ authorityReferralState: publicKey(this.referralStateManager.referralState),
452
450
  referredBySupplyTa: this.referredBySupplyTa
453
451
  ? publicKey(this.referredBySupplyTa)
454
452
  : undefined,
@@ -109,15 +109,15 @@ async function transactionChoresBefore(
109
109
  let chores = transactionBuilder();
110
110
 
111
111
  if (
112
- client.authorityReferralStateData === null ||
112
+ client.referralStateManager.referralState === null ||
113
113
  (client.referredByState !== undefined &&
114
- client.authorityReferralStateData.referredByState ===
115
- publicKey(PublicKey.default)) ||
114
+ client.referralStateManager.referralStateData!.referredByState ===
115
+ publicKey(PublicKey.default)) ||
116
116
  (client.authorityLutAddress !== undefined &&
117
- client.authorityReferralStateData.lookupTable ==
118
- publicKey(PublicKey.default))
117
+ client.referralStateManager.referralStateData!.lookupTable ==
118
+ publicKey(PublicKey.default))
119
119
  ) {
120
- chores = chores.add(client.updateReferralStatesIx());
120
+ chores = chores.add(client.referralStateManager.updateReferralStatesIx(undefined, client.referredByAuthority, client.authorityLutAddress));
121
121
  }
122
122
 
123
123
  if (client.selfManaged) {
@@ -379,7 +379,7 @@ function getRebalanceInstructions(tx: TransactionBuilder): Instruction[] {
379
379
  if (data.discriminator === discriminator) {
380
380
  return true;
381
381
  }
382
- } catch {}
382
+ } catch { }
383
383
  return false;
384
384
  }
385
385
  });
@@ -400,7 +400,7 @@ function getSolautoActions(tx: TransactionBuilder): SolautoAction[] {
400
400
  if (data.discriminator === discriminator) {
401
401
  solautoActions?.push(data.solautoAction);
402
402
  }
403
- } catch {}
403
+ } catch { }
404
404
  }
405
405
 
406
406
  if (x.programId === MARGINFI_PROGRAM_ID) {
@@ -423,7 +423,7 @@ function getSolautoActions(tx: TransactionBuilder): SolautoAction[] {
423
423
  fields: [data.amount],
424
424
  });
425
425
  }
426
- } catch {}
426
+ } catch { }
427
427
 
428
428
  try {
429
429
  const serializer = getLendingAccountBorrowInstructionDataSerializer();
@@ -444,7 +444,7 @@ function getSolautoActions(tx: TransactionBuilder): SolautoAction[] {
444
444
  fields: [data.amount],
445
445
  });
446
446
  }
447
- } catch {}
447
+ } catch { }
448
448
 
449
449
  try {
450
450
  const serializer = getLendingAccountWithdrawInstructionDataSerializer();
@@ -466,16 +466,16 @@ function getSolautoActions(tx: TransactionBuilder): SolautoAction[] {
466
466
  fields: [
467
467
  data.withdrawAll
468
468
  ? {
469
- __kind: "All",
470
- }
469
+ __kind: "All",
470
+ }
471
471
  : {
472
- __kind: "Some",
473
- fields: [data.amount],
474
- },
472
+ __kind: "Some",
473
+ fields: [data.amount],
474
+ },
475
475
  ],
476
476
  });
477
477
  }
478
- } catch {}
478
+ } catch { }
479
479
 
480
480
  try {
481
481
  const serializer = getLendingAccountRepayInstructionDataSerializer();
@@ -497,16 +497,16 @@ function getSolautoActions(tx: TransactionBuilder): SolautoAction[] {
497
497
  fields: [
498
498
  data.repayAll
499
499
  ? {
500
- __kind: "All",
501
- }
500
+ __kind: "All",
501
+ }
502
502
  : {
503
- __kind: "Some",
504
- fields: [data.amount],
505
- },
503
+ __kind: "Some",
504
+ fields: [data.amount],
505
+ },
506
506
  ],
507
507
  });
508
508
  }
509
- } catch {}
509
+ } catch { }
510
510
  }
511
511
 
512
512
  // TODO support other platforms
@@ -554,9 +554,9 @@ export async function buildSolautoRebalanceTransaction(
554
554
  attemptNum?: number
555
555
  ): Promise<
556
556
  | {
557
- tx: TransactionBuilder;
558
- lookupTableAddresses: string[];
559
- }
557
+ tx: TransactionBuilder;
558
+ lookupTableAddresses: string[];
559
+ }
560
560
  | undefined
561
561
  > {
562
562
  client.solautoPositionState = await client.getFreshPositionState();
@@ -566,9 +566,9 @@ export async function buildSolautoRebalanceTransaction(
566
566
  !eligibleForRebalance(
567
567
  client.solautoPositionState!,
568
568
  client.livePositionUpdates.settings ??
569
- client.solautoPositionData?.position.settingParams!,
569
+ client.solautoPositionData?.position.settingParams!,
570
570
  client.livePositionUpdates.activeDca ??
571
- client.solautoPositionData?.position.dca!,
571
+ client.solautoPositionData?.position.dca!,
572
572
  currentUnixSeconds()
573
573
  ))
574
574
  ) {
@@ -624,14 +624,14 @@ export async function buildSolautoRebalanceTransaction(
624
624
  ),
625
625
  ...(addFirstRebalance
626
626
  ? [
627
- client.rebalance(
628
- "A",
629
- swapDetails,
630
- rebalanceType,
631
- flashLoan,
632
- targetLiqUtilizationRateBps
633
- ),
634
- ]
627
+ client.rebalance(
628
+ "A",
629
+ swapDetails,
630
+ rebalanceType,
631
+ flashLoan,
632
+ targetLiqUtilizationRateBps
633
+ ),
634
+ ]
635
635
  : []),
636
636
  swapIx,
637
637
  client.rebalance(
@@ -1,7 +1,6 @@
1
1
  import bs58 from "bs58";
2
2
  import {
3
3
  AddressLookupTableInput,
4
- Instruction,
5
4
  transactionBuilder,
6
5
  TransactionBuilder,
7
6
  } from "@metaplex-foundation/umi";
@@ -15,7 +14,6 @@ import {
15
14
  retryWithExponentialBackoff,
16
15
  } from "../utils/generalUtils";
17
16
  import { getTransactionChores } from "./transactionUtils";
18
- import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
19
17
  import { PriorityFeeSetting } from "../types";
20
18
  // import { sendJitoBundledTransactions } from "../utils/jitoUtils";
21
19
 
@@ -213,12 +211,8 @@ export class TransactionsManager {
213
211
  await this.lookupTables.getLutInputs(item.lookupTableAddresses)
214
212
  );
215
213
  if (!transaction.fitsInOneTransaction(this.client.umi)) {
216
- // TODO: revert me
217
- // throw new Error(
218
- // `Transaction exceeds max transaction size (${transaction.getTransactionSize(this.client.umi)})`
219
- // );
220
- transactionSets.push(
221
- new TransactionSet(this.client, this.lookupTables, [item])
214
+ throw new Error(
215
+ `Transaction exceeds max transaction size (${transaction.getTransactionSize(this.client.umi)})`
222
216
  );
223
217
  } else {
224
218
  let newSet = new TransactionSet(this.client, this.lookupTables, [item]);
@@ -26,11 +26,11 @@ export function getTokenAccounts(wallet: PublicKey, tokenMints: PublicKey[]): Pu
26
26
  return tokenMints.map(x => getTokenAccount(wallet, x));
27
27
  }
28
28
 
29
- export async function getSolautoPositionAccount(
29
+ export function getSolautoPositionAccount(
30
30
  signer: PublicKey,
31
31
  positionId: number
32
32
  ) {
33
- const [positionAccount, _] = await PublicKey.findProgramAddress(
33
+ const [positionAccount, _] = PublicKey.findProgramAddressSync(
34
34
  [bufferFromU8(positionId), signer.toBuffer()],
35
35
  new PublicKey(SOLAUTO_PROGRAM_ID)
36
36
  );
@@ -38,11 +38,11 @@ export async function getSolautoPositionAccount(
38
38
  return positionAccount;
39
39
  }
40
40
 
41
- export async function getReferralState(authority: PublicKey) {
41
+ export function getReferralState(authority: PublicKey) {
42
42
  const str = "referral_state";
43
43
  const strBuffer = Buffer.from(str, "utf-8");
44
44
 
45
- const [ReferralState, _] = await PublicKey.findProgramAddress(
45
+ const [ReferralState, _] = PublicKey.findProgramAddressSync(
46
46
  [strBuffer, authority.toBuffer()],
47
47
  new PublicKey(SOLAUTO_PROGRAM_ID)
48
48
  );
@@ -250,7 +250,7 @@ export async function getReferralsByUser(
250
250
  // authority: Pubkey,
251
251
  // referred_by_state: Pubkey,
252
252
 
253
- const userReferralState = await getReferralState(user);
253
+ const userReferralState = getReferralState(user);
254
254
  const accounts = await umi.rpc.getProgramAccounts(SOLAUTO_PROGRAM_ID, {
255
255
  commitment: "finalized",
256
256
  dataSlice: {