@haven-fi/solauto-sdk 1.0.194 → 1.0.196
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoClient.d.ts +2 -2
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +24 -18
- package/dist/clients/solautoMarginfiClient.d.ts +1 -2
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +4 -4
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +6 -6
- package/dist/utils/numberUtils.js +1 -1
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +35 -31
- package/src/clients/solautoMarginfiClient.ts +3 -4
- package/src/transactions/transactionUtils.ts +2 -6
- package/src/utils/numberUtils.ts +1 -1
@@ -3,7 +3,6 @@ import { PublicKey } from "@solana/web3.js";
|
|
3
3
|
import { Signer, TransactionBuilder } from "@metaplex-foundation/umi";
|
4
4
|
import { WalletAdapter } from "@metaplex-foundation/umi-signer-wallet-adapters";
|
5
5
|
import { DCASettings, DCASettingsInpArgs, LendingPlatform, PositionState, SolautoActionArgs, SolautoPosition, SolautoRebalanceTypeArgs, SolautoSettingsParameters, SolautoSettingsParametersInpArgs, UpdatePositionDataArgs } from "../generated";
|
6
|
-
import { JupSwapDetails } from "../utils/jupiterUtils";
|
7
6
|
import { FlashLoanDetails } from "../utils/solauto/rebalanceUtils";
|
8
7
|
import { LivePositionUpdates } from "../utils/solauto/generalUtils";
|
9
8
|
import { ReferralStateManager } from "./referralStateManager";
|
@@ -45,6 +44,7 @@ export declare abstract class SolautoClient extends TxHandler {
|
|
45
44
|
livePositionUpdates: LivePositionUpdates;
|
46
45
|
constructor(heliusApiUrl: string, localTest?: boolean);
|
47
46
|
initialize(args: SolautoClientArgs, lendingPlatform: LendingPlatform): Promise<void>;
|
47
|
+
setReferredBy(referredBy: PublicKey): void;
|
48
48
|
resetLiveTxUpdates(success?: boolean): Promise<void>;
|
49
49
|
abstract protocolAccount(): PublicKey;
|
50
50
|
defaultLookupTables(): string[];
|
@@ -65,7 +65,7 @@ export declare abstract class SolautoClient extends TxHandler {
|
|
65
65
|
protocolInteraction(args: SolautoActionArgs): TransactionBuilder;
|
66
66
|
abstract flashBorrow(flashLoanDetails: FlashLoanDetails, destinationTokenAccount: PublicKey): TransactionBuilder;
|
67
67
|
abstract flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder;
|
68
|
-
abstract rebalance(rebalanceStep: "A" | "B",
|
68
|
+
abstract rebalance(rebalanceStep: "A" | "B", jupQuote: QuoteResponse, rebalanceType: SolautoRebalanceTypeArgs, flashLoan?: FlashLoanDetails, targetLiqUtilizationRateBps?: number): TransactionBuilder;
|
69
69
|
getFreshPositionState(): Promise<PositionState | undefined>;
|
70
70
|
}
|
71
71
|
//# sourceMappingURL=solautoClient.d.ts.map
|
@@ -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;
|
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,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B;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"}
|
@@ -60,14 +60,33 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
60
60
|
signer: args.signer,
|
61
61
|
wallet: args.wallet,
|
62
62
|
});
|
63
|
+
if (args.referredByAuthority) {
|
64
|
+
this.setReferredBy(args.referredByAuthority);
|
65
|
+
}
|
66
|
+
this.solautoFeesWallet = generalAccounts_1.SOLAUTO_FEES_WALLET;
|
67
|
+
this.solautoFeesSupplyTa = (0, accountUtils_1.getTokenAccount)(this.solautoFeesWallet, this.supplyMint);
|
68
|
+
const authorityReferralStateData = this.referralStateManager.referralStateData;
|
69
|
+
this.authorityLutAddress =
|
70
|
+
authorityReferralStateData?.lookupTable &&
|
71
|
+
!(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(authorityReferralStateData.lookupTable).equals(web3_js_1.PublicKey.default)
|
72
|
+
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(authorityReferralStateData.lookupTable)
|
73
|
+
: undefined;
|
74
|
+
this.log("Position state: ", this.solautoPositionState);
|
75
|
+
this.log("Position settings: ", this.solautoPositionData?.position?.settingParams);
|
76
|
+
this.log("Position DCA: ", (this.solautoPositionData?.position?.dca?.automation?.targetPeriods ??
|
77
|
+
0) > 0
|
78
|
+
? this.solautoPositionData?.position?.dca
|
79
|
+
: undefined);
|
80
|
+
}
|
81
|
+
setReferredBy(referredBy) {
|
63
82
|
const authorityReferralStateData = this.referralStateManager.referralStateData;
|
64
83
|
const hasReferredBy = authorityReferralStateData &&
|
65
84
|
authorityReferralStateData.referredByState !==
|
66
85
|
(0, umi_1.publicKey)(web3_js_1.PublicKey.default);
|
67
86
|
const referredByAuthority = !hasReferredBy &&
|
68
|
-
|
69
|
-
!
|
70
|
-
?
|
87
|
+
referredBy &&
|
88
|
+
!referredBy.equals((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey))
|
89
|
+
? referredBy
|
71
90
|
: undefined;
|
72
91
|
this.referredByState = hasReferredBy
|
73
92
|
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(authorityReferralStateData.referredByState)
|
@@ -78,19 +97,6 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
78
97
|
if (this.referredByState !== undefined) {
|
79
98
|
this.referredBySupplyTa = (0, accountUtils_1.getTokenAccount)(this.referredByState, this.supplyMint);
|
80
99
|
}
|
81
|
-
this.solautoFeesWallet = generalAccounts_1.SOLAUTO_FEES_WALLET;
|
82
|
-
this.solautoFeesSupplyTa = (0, accountUtils_1.getTokenAccount)(this.solautoFeesWallet, this.supplyMint);
|
83
|
-
this.authorityLutAddress =
|
84
|
-
authorityReferralStateData?.lookupTable &&
|
85
|
-
!(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(authorityReferralStateData.lookupTable).equals(web3_js_1.PublicKey.default)
|
86
|
-
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(authorityReferralStateData.lookupTable)
|
87
|
-
: undefined;
|
88
|
-
this.log("Position state: ", this.solautoPositionState);
|
89
|
-
this.log("Position settings: ", this.solautoPositionData?.position?.settingParams);
|
90
|
-
this.log("Position DCA: ", (this.solautoPositionData?.position?.dca?.automation?.targetPeriods ??
|
91
|
-
0) > 0
|
92
|
-
? this.solautoPositionData?.position?.dca
|
93
|
-
: undefined);
|
94
100
|
}
|
95
101
|
async resetLiveTxUpdates(success) {
|
96
102
|
if (success) {
|
@@ -200,7 +206,7 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
200
206
|
type: "dcaInBalance",
|
201
207
|
value: {
|
202
208
|
amount: BigInt(dca.dcaInBaseUnit),
|
203
|
-
tokenType: dca.tokenType
|
209
|
+
tokenType: dca.tokenType,
|
204
210
|
},
|
205
211
|
});
|
206
212
|
}
|
@@ -241,7 +247,7 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
241
247
|
type: "dcaInBalance",
|
242
248
|
value: {
|
243
249
|
amount: BigInt(args.dca.value.dcaInBaseUnit),
|
244
|
-
tokenType: args.dca.value.tokenType
|
250
|
+
tokenType: args.dca.value.tokenType,
|
245
251
|
},
|
246
252
|
});
|
247
253
|
addingToPos = true;
|
@@ -4,7 +4,6 @@ import { SolautoClient, SolautoClientArgs } from "./solautoClient";
|
|
4
4
|
import { MarginfiAssetAccounts } from "../types/accounts";
|
5
5
|
import { DCASettingsInpArgs, PositionState, SolautoActionArgs, SolautoRebalanceTypeArgs, SolautoSettingsParametersInpArgs } from "../generated";
|
6
6
|
import { MarginfiAccount } from "../marginfi-sdk";
|
7
|
-
import { JupSwapDetails } from "../utils/jupiterUtils";
|
8
7
|
import { FlashLoanDetails } from "../utils/solauto/rebalanceUtils";
|
9
8
|
import { QuoteResponse } from "@jup-ag/api";
|
10
9
|
export interface SolautoMarginfiClientArgs extends SolautoClientArgs {
|
@@ -39,7 +38,7 @@ export declare class SolautoMarginfiClient extends SolautoClient {
|
|
39
38
|
protocolInteraction(args: SolautoActionArgs): TransactionBuilder;
|
40
39
|
private marginfiProtocolInteractionIx;
|
41
40
|
private marginfiSolautoProtocolInteractionIx;
|
42
|
-
rebalance(rebalanceStep: "A" | "B",
|
41
|
+
rebalance(rebalanceStep: "A" | "B", jupQuote: QuoteResponse, rebalanceType: SolautoRebalanceTypeArgs, flashLoan?: FlashLoanDetails, targetLiqUtilizationRateBps?: number): TransactionBuilder;
|
43
42
|
flashBorrow(flashLoanDetails: FlashLoanDetails, destinationTokenAccount: PublicKey): TransactionBuilder;
|
44
43
|
flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder;
|
45
44
|
createIntermediaryMarginfiAccount(): TransactionBuilder;
|
@@ -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,EAEb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAUhB,MAAM,iBAAiB,CAAC;
|
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,EAEb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAUhB,MAAM,iBAA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kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA0D5C,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,QAAQ,EAAE,aAAa,EACvB,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,GACnC,kBAAkB;IAgErB,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;CA4ClE"}
|
@@ -291,9 +291,9 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
291
291
|
solautoAction: args,
|
292
292
|
});
|
293
293
|
}
|
294
|
-
rebalance(rebalanceStep,
|
295
|
-
const inputIsSupply =
|
296
|
-
const outputIsSupply =
|
294
|
+
rebalance(rebalanceStep, jupQuote, rebalanceType, flashLoan, targetLiqUtilizationRateBps) {
|
295
|
+
const inputIsSupply = (new web3_js_1.PublicKey(jupQuote.inputMint)).equals(this.supplyMint);
|
296
|
+
const outputIsSupply = (new web3_js_1.PublicKey(jupQuote.outputMint)).equals(this.supplyMint);
|
297
297
|
const needSupplyAccounts = (inputIsSupply && rebalanceStep === "A") ||
|
298
298
|
(outputIsSupply && rebalanceStep === "B") ||
|
299
299
|
(inputIsSupply && flashLoan !== undefined && rebalanceStep == "B");
|
@@ -313,7 +313,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
313
313
|
solautoPosition: (0, umi_1.publicKey)(this.solautoPosition),
|
314
314
|
marginfiGroup: (0, umi_1.publicKey)(this.marginfiGroup),
|
315
315
|
marginfiAccount: (0, umi_1.publicKey)(this.marginfiAccountPk),
|
316
|
-
intermediaryTa: (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey),
|
316
|
+
intermediaryTa: (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), new web3_js_1.PublicKey(jupQuote.inputMint))),
|
317
317
|
supplyBank: (0, umi_1.publicKey)(this.marginfiSupplyAccounts.bank),
|
318
318
|
supplyPriceOracle: (0, umi_1.publicKey)(this.supplyPriceOracle),
|
319
319
|
positionSupplyTa: (0, umi_1.publicKey)(this.positionSupplyTa),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAGL,aAAa,EAYd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAiOzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA+G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,aAAa,WAwCnE;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,
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAKxE,OAAO,EAGL,aAAa,EAYd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAiOzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA+G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;AAED,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,aAAa,WAwCnE;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,CAkHA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,SAAS,GACtB,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAmCrD;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG;;;;EAwC9D"}
|
@@ -340,8 +340,8 @@ function requiresRefreshBeforeRebalance(client) {
|
|
340
340
|
oldSupply;
|
341
341
|
const debtDiff = (client.solautoPositionState?.debt.amountUsed.baseUnit ?? BigInt(0)) -
|
342
342
|
oldDebt;
|
343
|
-
if (Math.abs(Number(supplyDiff)) / Number(oldSupply) >= 0.
|
344
|
-
Math.abs(Number(debtDiff)) / Number(oldDebt) >= 0.
|
343
|
+
if (Math.abs(Number(supplyDiff)) / Number(oldSupply) >= 0.005 ||
|
344
|
+
Math.abs(Number(debtDiff)) / Number(oldDebt) >= 0.005) {
|
345
345
|
return true;
|
346
346
|
}
|
347
347
|
}
|
@@ -378,11 +378,11 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
378
378
|
client.flashBorrow(flashLoan, (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), swapDetails.inputMint)),
|
379
379
|
...(addFirstRebalance
|
380
380
|
? [
|
381
|
-
client.rebalance("A",
|
381
|
+
client.rebalance("A", jupQuote, rebalanceType, flashLoan, targetLiqUtilizationRateBps),
|
382
382
|
]
|
383
383
|
: []),
|
384
384
|
swapIx,
|
385
|
-
client.rebalance("B",
|
385
|
+
client.rebalance("B", jupQuote, rebalanceType, flashLoan, targetLiqUtilizationRateBps),
|
386
386
|
client.flashRepay(flashLoan),
|
387
387
|
]);
|
388
388
|
}
|
@@ -391,9 +391,9 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
391
391
|
tx = tx.add([
|
392
392
|
setupInstructions,
|
393
393
|
tokenLedgerIx,
|
394
|
-
client.rebalance("A",
|
394
|
+
client.rebalance("A", jupQuote, rebalanceType, undefined, targetLiqUtilizationRateBps),
|
395
395
|
swapIx,
|
396
|
-
client.rebalance("B",
|
396
|
+
client.rebalance("B", jupQuote, rebalanceType, undefined, targetLiqUtilizationRateBps),
|
397
397
|
]);
|
398
398
|
}
|
399
399
|
return {
|
package/package.json
CHANGED
@@ -103,10 +103,7 @@ export abstract class SolautoClient extends TxHandler {
|
|
103
103
|
|
104
104
|
public livePositionUpdates: LivePositionUpdates = new LivePositionUpdates();
|
105
105
|
|
106
|
-
constructor(
|
107
|
-
heliusApiUrl: string,
|
108
|
-
localTest?: boolean
|
109
|
-
) {
|
106
|
+
constructor(heliusApiUrl: string, localTest?: boolean) {
|
110
107
|
super(heliusApiUrl, localTest);
|
111
108
|
|
112
109
|
this.umi = this.umi.use({
|
@@ -175,29 +172,8 @@ export abstract class SolautoClient extends TxHandler {
|
|
175
172
|
wallet: args.wallet,
|
176
173
|
});
|
177
174
|
|
178
|
-
|
179
|
-
this.
|
180
|
-
const hasReferredBy =
|
181
|
-
authorityReferralStateData &&
|
182
|
-
authorityReferralStateData.referredByState !==
|
183
|
-
publicKey(PublicKey.default);
|
184
|
-
const referredByAuthority =
|
185
|
-
!hasReferredBy &&
|
186
|
-
args.referredByAuthority &&
|
187
|
-
!args.referredByAuthority.equals(toWeb3JsPublicKey(this.signer.publicKey))
|
188
|
-
? args.referredByAuthority
|
189
|
-
: undefined;
|
190
|
-
this.referredByState = hasReferredBy
|
191
|
-
? toWeb3JsPublicKey(authorityReferralStateData!.referredByState)
|
192
|
-
: referredByAuthority
|
193
|
-
? getReferralState(referredByAuthority!)
|
194
|
-
: undefined;
|
195
|
-
this.referredByAuthority = referredByAuthority;
|
196
|
-
if (this.referredByState !== undefined) {
|
197
|
-
this.referredBySupplyTa = getTokenAccount(
|
198
|
-
this.referredByState,
|
199
|
-
this.supplyMint
|
200
|
-
);
|
175
|
+
if (args.referredByAuthority) {
|
176
|
+
this.setReferredBy(args.referredByAuthority);
|
201
177
|
}
|
202
178
|
|
203
179
|
this.solautoFeesWallet = SOLAUTO_FEES_WALLET;
|
@@ -206,6 +182,8 @@ export abstract class SolautoClient extends TxHandler {
|
|
206
182
|
this.supplyMint
|
207
183
|
);
|
208
184
|
|
185
|
+
const authorityReferralStateData =
|
186
|
+
this.referralStateManager.referralStateData;
|
209
187
|
this.authorityLutAddress =
|
210
188
|
authorityReferralStateData?.lookupTable &&
|
211
189
|
!toWeb3JsPublicKey(authorityReferralStateData.lookupTable).equals(
|
@@ -228,6 +206,33 @@ export abstract class SolautoClient extends TxHandler {
|
|
228
206
|
);
|
229
207
|
}
|
230
208
|
|
209
|
+
public setReferredBy(referredBy: PublicKey) {
|
210
|
+
const authorityReferralStateData =
|
211
|
+
this.referralStateManager.referralStateData;
|
212
|
+
const hasReferredBy =
|
213
|
+
authorityReferralStateData &&
|
214
|
+
authorityReferralStateData.referredByState !==
|
215
|
+
publicKey(PublicKey.default);
|
216
|
+
const referredByAuthority =
|
217
|
+
!hasReferredBy &&
|
218
|
+
referredBy &&
|
219
|
+
!referredBy.equals(toWeb3JsPublicKey(this.signer.publicKey))
|
220
|
+
? referredBy
|
221
|
+
: undefined;
|
222
|
+
this.referredByState = hasReferredBy
|
223
|
+
? toWeb3JsPublicKey(authorityReferralStateData!.referredByState)
|
224
|
+
: referredByAuthority
|
225
|
+
? getReferralState(referredByAuthority!)
|
226
|
+
: undefined;
|
227
|
+
this.referredByAuthority = referredByAuthority;
|
228
|
+
if (this.referredByState !== undefined) {
|
229
|
+
this.referredBySupplyTa = getTokenAccount(
|
230
|
+
this.referredByState,
|
231
|
+
this.supplyMint
|
232
|
+
);
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
231
236
|
async resetLiveTxUpdates(success?: boolean) {
|
232
237
|
if (success) {
|
233
238
|
if (!this.solautoPositionData) {
|
@@ -378,7 +383,7 @@ export abstract class SolautoClient extends TxHandler {
|
|
378
383
|
type: "dcaInBalance",
|
379
384
|
value: {
|
380
385
|
amount: BigInt(dca.dcaInBaseUnit),
|
381
|
-
tokenType: dca.tokenType
|
386
|
+
tokenType: dca.tokenType,
|
382
387
|
},
|
383
388
|
});
|
384
389
|
}
|
@@ -423,7 +428,7 @@ export abstract class SolautoClient extends TxHandler {
|
|
423
428
|
type: "dcaInBalance",
|
424
429
|
value: {
|
425
430
|
amount: BigInt(args.dca.value.dcaInBaseUnit),
|
426
|
-
tokenType: args.dca.value.tokenType
|
431
|
+
tokenType: args.dca.value.tokenType,
|
427
432
|
},
|
428
433
|
});
|
429
434
|
addingToPos = true;
|
@@ -596,11 +601,10 @@ export abstract class SolautoClient extends TxHandler {
|
|
596
601
|
|
597
602
|
abstract rebalance(
|
598
603
|
rebalanceStep: "A" | "B",
|
599
|
-
swapDetails: JupSwapDetails,
|
600
604
|
jupQuote: QuoteResponse,
|
601
605
|
rebalanceType: SolautoRebalanceTypeArgs,
|
602
606
|
flashLoan?: FlashLoanDetails,
|
603
|
-
targetLiqUtilizationRateBps?: number
|
607
|
+
targetLiqUtilizationRateBps?: number
|
604
608
|
): TransactionBuilder;
|
605
609
|
|
606
610
|
async getFreshPositionState(): Promise<PositionState | undefined> {
|
@@ -454,14 +454,13 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
454
454
|
|
455
455
|
rebalance(
|
456
456
|
rebalanceStep: "A" | "B",
|
457
|
-
swapDetails: JupSwapDetails,
|
458
457
|
jupQuote: QuoteResponse,
|
459
458
|
rebalanceType: SolautoRebalanceTypeArgs,
|
460
459
|
flashLoan?: FlashLoanDetails,
|
461
460
|
targetLiqUtilizationRateBps?: number
|
462
461
|
): TransactionBuilder {
|
463
|
-
const inputIsSupply =
|
464
|
-
const outputIsSupply =
|
462
|
+
const inputIsSupply = (new PublicKey(jupQuote.inputMint)).equals(this.supplyMint);
|
463
|
+
const outputIsSupply = (new PublicKey(jupQuote.outputMint)).equals(this.supplyMint);
|
465
464
|
const needSupplyAccounts =
|
466
465
|
(inputIsSupply && rebalanceStep === "A") ||
|
467
466
|
(outputIsSupply && rebalanceStep === "B") ||
|
@@ -490,7 +489,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
490
489
|
intermediaryTa: publicKey(
|
491
490
|
getTokenAccount(
|
492
491
|
toWeb3JsPublicKey(this.signer.publicKey),
|
493
|
-
|
492
|
+
new PublicKey(jupQuote.inputMint)
|
494
493
|
)
|
495
494
|
),
|
496
495
|
supplyBank: publicKey(this.marginfiSupplyAccounts.bank),
|
@@ -607,8 +607,8 @@ export function requiresRefreshBeforeRebalance(client: SolautoClient) {
|
|
607
607
|
oldDebt;
|
608
608
|
|
609
609
|
if (
|
610
|
-
Math.abs(Number(supplyDiff)) / Number(oldSupply) >= 0.
|
611
|
-
Math.abs(Number(debtDiff)) / Number(oldDebt) >= 0.
|
610
|
+
Math.abs(Number(supplyDiff)) / Number(oldSupply) >= 0.005 ||
|
611
|
+
Math.abs(Number(debtDiff)) / Number(oldDebt) >= 0.005
|
612
612
|
) {
|
613
613
|
return true;
|
614
614
|
}
|
@@ -699,7 +699,6 @@ export async function buildSolautoRebalanceTransaction(
|
|
699
699
|
? [
|
700
700
|
client.rebalance(
|
701
701
|
"A",
|
702
|
-
swapDetails,
|
703
702
|
jupQuote,
|
704
703
|
rebalanceType,
|
705
704
|
flashLoan,
|
@@ -710,7 +709,6 @@ export async function buildSolautoRebalanceTransaction(
|
|
710
709
|
swapIx,
|
711
710
|
client.rebalance(
|
712
711
|
"B",
|
713
|
-
swapDetails,
|
714
712
|
jupQuote,
|
715
713
|
rebalanceType,
|
716
714
|
flashLoan,
|
@@ -725,7 +723,6 @@ export async function buildSolautoRebalanceTransaction(
|
|
725
723
|
tokenLedgerIx,
|
726
724
|
client.rebalance(
|
727
725
|
"A",
|
728
|
-
swapDetails,
|
729
726
|
jupQuote,
|
730
727
|
rebalanceType,
|
731
728
|
undefined,
|
@@ -734,7 +731,6 @@ export async function buildSolautoRebalanceTransaction(
|
|
734
731
|
swapIx,
|
735
732
|
client.rebalance(
|
736
733
|
"B",
|
737
|
-
swapDetails,
|
738
734
|
jupQuote,
|
739
735
|
rebalanceType,
|
740
736
|
undefined,
|