@haven-fi/solauto-sdk 1.0.209 → 1.0.210

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,EAAa,MAAM,EAAkB,kBAAkB,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAEtG,OAAO,EAAE,aAAa,EAAyB,MAAM,iDAAiD,CAAC;AACvG,OAAO,EAA2C,aAAa,EAAgD,MAAM,cAAc,CAAC;AAEpI,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,UAAU,wBAAwB;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,iBAAiB,CAAC,EAAE,SAAS,CAAC;CACjC;AAED,qBAAa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,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 ? [this.referralStateData?.lookupTable.toString()] : [];
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
- : undefined,
43
- referredByAuthority: referredBy
44
- ? (0, umi_1.publicKey)(referredBy)
45
- : undefined,
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,mBAAmB,CAAC,EAAE,SAAS,CAA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kBAAkB;IAgCjC,QAAQ,CAAC,OAAO,IAAI,kBAAkB;IAEtC,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAuFhE,QAAQ,CAAC,WAAW,CAClB,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IAErB,QAAQ,CAAC,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IAE3E,QAAQ,CAAC,SAAS,CAChB,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,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 ? await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition), { commitment: "confirmed" }) : null;
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.setReferredBy(args.referredByAuthority);
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
- const authorityReferralStateData = this.referralStateManager.referralStateData;
83
- const hasReferredBy = authorityReferralStateData &&
84
- authorityReferralStateData.referredByState !==
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;AAG7C,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
+ {"version":3,"file":"txHandler.d.ts","sourceRoot":"","sources":["../../src/clients/txHandler.ts"],"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AM,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());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.209",
3
+ "version": "1.0.210",
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,94 +1,154 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
2
  import { NATIVE_MINT } from "@solana/spl-token";
3
- import { publicKey, Signer, signerIdentity, TransactionBuilder, Umi } from "@metaplex-foundation/umi";
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 { WalletAdapter, walletAdapterIdentity } from "@metaplex-foundation/umi-signer-wallet-adapters";
6
- import { claimReferralFees, createSolautoProgram, ReferralState, safeFetchReferralState, updateReferralStates } from "../generated";
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
- signer?: Signer;
12
- wallet?: WalletAdapter;
13
- referralAuthority?: PublicKey;
26
+ signer?: Signer;
27
+ wallet?: WalletAdapter;
28
+ referralAuthority?: PublicKey;
29
+ referredByAuthority?: PublicKey;
14
30
  }
15
31
 
16
32
  export class ReferralStateManager extends TxHandler {
17
- public umi!: Umi;
18
- public signer!: Signer;
33
+ public umi!: Umi;
34
+ public signer!: Signer;
19
35
 
20
- public referralAuthority!: PublicKey;
21
- public referralState!: PublicKey;
22
- public referralStateData!: ReferralState | null;
36
+ public referralAuthority!: PublicKey;
37
+ public referralState!: PublicKey;
38
+ public referralStateData!: ReferralState | null;
23
39
 
24
- constructor(heliusApiUrl: string, public localTest?: boolean) {
25
- super(heliusApiUrl, localTest)
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
- async initialize(args: ReferralStateManagerArgs) {
34
- if (!args.signer && !args.wallet) {
35
- throw new Error("Signer or wallet must be provided");
36
- }
37
- this.umi = this.umi.use(
38
- args.signer
39
- ? signerIdentity(args.signer)
40
- : walletAdapterIdentity(args.wallet!, true)
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
- this.signer = this.umi.identity;
44
- this.referralState = getReferralState(args.referralAuthority ?? toWeb3JsPublicKey(this.signer.publicKey));
45
- this.referralStateData = await safeFetchReferralState(this.umi, publicKey(this.referralState), { commitment: "confirmed" });
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
- defaultLookupTables(): string[] {
49
- return this.referralStateData?.lookupTable ? [this.referralStateData?.lookupTable.toString()] : [];
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
- updateReferralStatesIx(destFeesMint?: PublicKey, referredBy?: PublicKey, lookupTable?: PublicKey): TransactionBuilder {
53
- return updateReferralStates(this.umi, {
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
- claimReferralFeesIx(destFeesMint?: PublicKey): TransactionBuilder {
70
- const referralFeesDestMint = destFeesMint ?? toWeb3JsPublicKey(this.referralStateData!.destFeesMint);
71
- const referralDestTa = getTokenAccount(this.referralState, referralFeesDestMint);
72
- const feesDestinationTa =
73
- referralFeesDestMint !== NATIVE_MINT
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
- return claimReferralFees(this.umi, {
83
- signer: this.signer,
84
- signerWsolTa: publicKey(getTokenAccount(toWeb3JsPublicKey(this.signer.publicKey), NATIVE_MINT)),
85
- referralAuthority: publicKey(this.referralAuthority),
86
- referralState: publicKey(this.referralState),
87
- referralFeesDestTa: publicKey(referralDestTa),
88
- referralFeesDestMint: publicKey(referralFeesDestMint),
89
- feesDestinationTa,
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
- async resetLiveTxUpdates(success?: boolean): Promise<void> { }
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 ? await safeFetchSolautoPosition(
137
- this.umi,
138
- publicKey(this.solautoPosition),
139
- { commitment: "confirmed" }
140
- ) : null;
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
- this.setReferredBy(args.referredByAuthority);
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
- const authorityReferralStateData =
212
- this.referralStateManager.referralStateData;
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)
@@ -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,
@@ -139,7 +140,7 @@ async function transactionChoresBefore(
139
140
 
140
141
  if (
141
142
  client.referralStateManager.referralStateData === null ||
142
- (client.referredByState !== undefined &&
143
+ (client.referralStateManager.referredByState !== undefined &&
143
144
  client.referralStateManager.referralStateData?.referredByState ===
144
145
  publicKey(PublicKey.default)) ||
145
146
  (client.authorityLutAddress !== undefined &&
@@ -149,7 +150,7 @@ async function transactionChoresBefore(
149
150
  chores = chores.add(
150
151
  client.referralStateManager.updateReferralStatesIx(
151
152
  undefined,
152
- client.referredByAuthority,
153
+ client.referralStateManager.referredByAuthority,
153
154
  client.authorityLutAddress
154
155
  )
155
156
  );
@@ -314,7 +315,7 @@ export async function rebalanceChoresBefore(
314
315
  chores = chores.add(
315
316
  createAssociatedTokenAccountUmiIx(
316
317
  client.signer,
317
- client.referredByState!,
318
+ client.referralStateManager.referredByState!,
318
319
  client.supplyMint
319
320
  )
320
321
  );