@haven-fi/solauto-sdk 1.0.209 → 1.0.211

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,11 @@ export declare class ReferralStateManager extends TxHandler {
15
16
  referralAuthority: PublicKey;
16
17
  referralState: PublicKey;
17
18
  referralStateData: ReferralState | null;
19
+ referredByState?: PublicKey;
18
20
  constructor(heliusApiUrl: string, localTest?: boolean | undefined);
19
21
  initialize(args: ReferralStateManagerArgs): Promise<void>;
20
22
  defaultLookupTables(): string[];
23
+ setReferredBy(referredBy?: PublicKey): void;
21
24
  updateReferralStatesIx(destFeesMint?: PublicKey, referredBy?: PublicKey, lookupTable?: PublicKey): TransactionBuilder;
22
25
  claimReferralFeesIx(destFeesMint?: PublicKey): TransactionBuilder;
23
26
  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,EAA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,SAAS,CAAC,EAAE,OAAO;IAXrB,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,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.referredBy = 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,CAAC;CACjC;AA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gCjC,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,12 +1,14 @@
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;
6
6
  connection: Connection;
7
+ referredBy?: PublicKey;
7
8
  constructor(rpcUrl: string, localTest?: boolean);
8
9
  log(...args: any[]): void;
9
10
  abstract defaultLookupTables(): string[];
10
11
  abstract resetLiveTxUpdates(success?: boolean): Promise<void>;
12
+ abstract setReferredBy(referredBy?: PublicKey): void;
11
13
  }
12
14
  //# 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"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGxD,8BAAsB,SAAS;IACtB,MAAM,EAAG,MAAM,CAAC;IAChB,GAAG,EAAG,GAAG,CAAC;IACV,UAAU,EAAG,UAAU,CAAC;IAExB,UAAU,CAAC,EAAE,SAAS,CAAC;gBAG5B,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,OAAO;IAYrB,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAIzB,QAAQ,CAAC,mBAAmB,IAAI,MAAM,EAAE;IAExC,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAE7D,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,SAAS,GAAG,IAAI;CACrD"}
@@ -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;AAsBxE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqCzD,OAAO,EAAE,oBAAoB,EAAa,MAAM,YAAY,CAAC;AAO7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA0LjD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA+G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,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EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAkH5C;AAED,wBAAsB,gCAAgC,CACpD,eAAe,EAAE,oBAAoB,EACrC,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,GACzB,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC,CAsC5C;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG;;;;EAwC9D"}
@@ -52,13 +52,13 @@ function getWSolUsage(client, solautoActions, initiatingDcaIn, cancellingDcaIn)
52
52
  async function transactionChoresBefore(client, accountsGettingCreated, solautoActions, initiatingDcaIn) {
53
53
  let chores = (0, umi_1.transactionBuilder)();
54
54
  if (client.referralStateManager.referralStateData === null ||
55
- (client.referredByState !== undefined &&
55
+ (client.referralStateManager.referredByState !== undefined &&
56
56
  client.referralStateManager.referralStateData?.referredByState ===
57
57
  (0, umi_1.publicKey)(web3_js_1.PublicKey.default)) ||
58
58
  (client.authorityLutAddress !== undefined &&
59
59
  client.referralStateManager.referralStateData.lookupTable ==
60
60
  (0, umi_1.publicKey)(web3_js_1.PublicKey.default))) {
61
- chores = chores.add(client.referralStateManager.updateReferralStatesIx(undefined, client.referredByAuthority, client.authorityLutAddress));
61
+ chores = chores.add(client.referralStateManager.updateReferralStatesIx(undefined, client.referralStateManager.referredBy, 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.211",
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,153 @@
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 referredByState?: PublicKey;
32
41
 
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
- );
42
+ constructor(
43
+ heliusApiUrl: string,
44
+ public localTest?: boolean
45
+ ) {
46
+ super(heliusApiUrl, localTest);
47
+ this.umi = this.umi.use({
48
+ install(umi) {
49
+ umi.programs.add(createSolautoProgram(), false);
50
+ },
51
+ });
52
+ }
42
53
 
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" });
54
+ async initialize(args: ReferralStateManagerArgs) {
55
+ if (!args.signer && !args.wallet) {
56
+ throw new Error("Signer or wallet must be provided");
46
57
  }
58
+ this.umi = this.umi.use(
59
+ args.signer
60
+ ? signerIdentity(args.signer)
61
+ : walletAdapterIdentity(args.wallet!, true)
62
+ );
47
63
 
48
- defaultLookupTables(): string[] {
49
- return this.referralStateData?.lookupTable ? [this.referralStateData?.lookupTable.toString()] : [];
50
- }
64
+ this.signer = this.umi.identity;
65
+ this.referralState = getReferralState(
66
+ args.referralAuthority ?? toWeb3JsPublicKey(this.signer.publicKey)
67
+ );
68
+ this.referralStateData = await safeFetchReferralState(
69
+ this.umi,
70
+ publicKey(this.referralState),
71
+ { commitment: "confirmed" }
72
+ );
51
73
 
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
- }
74
+ this.setReferredBy(args.referredByAuthority);
75
+ }
68
76
 
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;
77
+ defaultLookupTables(): string[] {
78
+ return this.referralStateData?.lookupTable
79
+ ? [this.referralStateData?.lookupTable.toString()]
80
+ : [];
81
+ }
81
82
 
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
- }
83
+ public setReferredBy(referredBy?: PublicKey) {
84
+ const authorityReferralStateData = this.referralStateData;
85
+ const hasReferredBy =
86
+ authorityReferralStateData &&
87
+ authorityReferralStateData.referredByState !==
88
+ publicKey(PublicKey.default);
89
+ const referredByAuthority =
90
+ !hasReferredBy &&
91
+ referredBy &&
92
+ !referredBy.equals(toWeb3JsPublicKey(this.signer.publicKey))
93
+ ? referredBy
94
+ : undefined;
95
+ this.referredByState = hasReferredBy
96
+ ? toWeb3JsPublicKey(authorityReferralStateData!.referredByState)
97
+ : referredByAuthority
98
+ ? getReferralState(referredByAuthority!)
99
+ : undefined;
100
+ this.referredBy = referredByAuthority;
101
+ }
92
102
 
93
- async resetLiveTxUpdates(success?: boolean): Promise<void> { }
94
- }
103
+ updateReferralStatesIx(
104
+ destFeesMint?: PublicKey,
105
+ referredBy?: PublicKey,
106
+ lookupTable?: PublicKey
107
+ ): TransactionBuilder {
108
+ return updateReferralStates(this.umi, {
109
+ signer: this.signer,
110
+ signerReferralState: publicKey(this.referralState),
111
+ referralFeesDestMint: destFeesMint ? publicKey(destFeesMint) : null,
112
+ referredByState: referredBy
113
+ ? publicKey(getReferralState(referredBy))
114
+ : this.referredByState
115
+ ? publicKey(this.referredByState)
116
+ : undefined,
117
+ referredByAuthority: referredBy ? publicKey(referredBy) : undefined,
118
+ addressLookupTable: lookupTable ? publicKey(lookupTable) : null,
119
+ });
120
+ }
121
+
122
+ claimReferralFeesIx(destFeesMint?: PublicKey): TransactionBuilder {
123
+ const referralFeesDestMint =
124
+ destFeesMint ?? toWeb3JsPublicKey(this.referralStateData!.destFeesMint);
125
+ const referralDestTa = getTokenAccount(
126
+ this.referralState,
127
+ referralFeesDestMint
128
+ );
129
+ const feesDestinationTa =
130
+ referralFeesDestMint !== NATIVE_MINT
131
+ ? publicKey(
132
+ getTokenAccount(
133
+ toWeb3JsPublicKey(this.signer.publicKey),
134
+ referralFeesDestMint
135
+ )
136
+ )
137
+ : undefined;
138
+
139
+ return claimReferralFees(this.umi, {
140
+ signer: this.signer,
141
+ signerWsolTa: publicKey(
142
+ getTokenAccount(toWeb3JsPublicKey(this.signer.publicKey), NATIVE_MINT)
143
+ ),
144
+ referralAuthority: publicKey(this.referralAuthority),
145
+ referralState: publicKey(this.referralState),
146
+ referralFeesDestTa: publicKey(referralDestTa),
147
+ referralFeesDestMint: publicKey(referralFeesDestMint),
148
+ feesDestinationTa,
149
+ });
150
+ }
151
+
152
+ async resetLiveTxUpdates(success?: boolean): Promise<void> {}
153
+ }
@@ -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 {
@@ -7,6 +7,8 @@ export abstract class TxHandler {
7
7
  public umi!: Umi;
8
8
  public connection!: Connection;
9
9
 
10
+ public referredBy?: PublicKey;
11
+
10
12
  constructor(
11
13
  rpcUrl: string,
12
14
  localTest?: boolean
@@ -28,4 +30,6 @@ export abstract class TxHandler {
28
30
  abstract defaultLookupTables(): string[];
29
31
 
30
32
  abstract resetLiveTxUpdates(success?: boolean): Promise<void>;
33
+
34
+ abstract setReferredBy(referredBy?: PublicKey): void;
31
35
  }
@@ -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.referredBy,
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
  );