@haven-fi/solauto-sdk 1.0.118 → 1.0.119
Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,
|
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,EAChC,sBAAsB,EAMvB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAKvD,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;AAExC,MAAM,WAAW,iBAAiB;IAChC,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;AAED,8BAAsB,aAAc,SAAQ,SAAS;IA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SAAS,CAC5E;IAyDD,uBAAuB,IAAI,yBAAyB,GAAG,SAAS;IAOhE,wBAAwB,IAAI,WAAW,GAAG,SAAS;IAOnD,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAuBrB,gBAAgB,CAAC,IAAI,EAAE,sBAAsB,GAAG,kBAAkB;IA2DlE,eAAe,IAAI,kBAAkB;IAYrC,WAAW,IAAI,kBAAkB;IA4BjC,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,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,SAAS,CAAC,EAAE,gBAAgB,EAC5B,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAalE"}
|
@@ -42,20 +42,24 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
42
42
|
this.solautoPositionData = await (0, generated_1.safeFetchSolautoPosition)(this.umi, (0, umi_1.publicKey)(this.solautoPosition), { commitment: "confirmed" });
|
43
43
|
this.solautoPositionState = this.solautoPositionData?.state;
|
44
44
|
this.supplyMint =
|
45
|
-
|
46
|
-
|
45
|
+
args.supplyMint ??
|
46
|
+
(this.solautoPositionData
|
47
|
+
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.solautoPositionData.position.supplyMint)
|
48
|
+
: web3_js_1.PublicKey.default);
|
47
49
|
this.positionSupplyTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.supplyMint);
|
48
50
|
this.signerSupplyTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.supplyMint);
|
49
51
|
this.debtMint =
|
50
|
-
|
51
|
-
|
52
|
+
args.debtMint ??
|
53
|
+
(this.solautoPositionData
|
54
|
+
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.solautoPositionData.position.debtMint)
|
55
|
+
: web3_js_1.PublicKey.default);
|
52
56
|
this.positionDebtTa = (0, accountUtils_1.getTokenAccount)(this.solautoPosition, this.debtMint);
|
53
57
|
this.signerDebtTa = (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey), this.debtMint);
|
54
58
|
this.referralStateManager = new referralStateManager_1.ReferralStateManager(this.heliusApiKey);
|
55
59
|
await this.referralStateManager.initialize({
|
56
60
|
referralAuthority: this.authority,
|
57
61
|
signer: args.signer,
|
58
|
-
wallet: args.wallet
|
62
|
+
wallet: args.wallet,
|
59
63
|
});
|
60
64
|
const authorityReferralStateData = this.referralStateManager.referralStateData;
|
61
65
|
const hasReferredBy = authorityReferralStateData &&
|
@@ -77,9 +81,11 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
77
81
|
}
|
78
82
|
this.solautoFeesWallet = generalAccounts_1.SOLAUTO_FEES_WALLET;
|
79
83
|
this.solautoFeesSupplyTa = (0, accountUtils_1.getTokenAccount)(this.solautoFeesWallet, this.supplyMint);
|
80
|
-
this.authorityLutAddress =
|
81
|
-
|
82
|
-
|
84
|
+
this.authorityLutAddress =
|
85
|
+
authorityReferralStateData?.lookupTable &&
|
86
|
+
!(0, umi_web3js_adapters_1.toWeb3JsPublicKey)(authorityReferralStateData.lookupTable).equals(web3_js_1.PublicKey.default)
|
87
|
+
? (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(authorityReferralStateData.lookupTable)
|
88
|
+
: undefined;
|
83
89
|
this.log("Position state: ", this.solautoPositionState);
|
84
90
|
this.log("Position settings: ", this.solautoPositionData?.position?.settingParams);
|
85
91
|
this.log("Position DCA: ", (this.solautoPositionData?.position?.dca?.automation?.targetPeriods ??
|
@@ -107,7 +113,12 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
107
113
|
this.livePositionUpdates.reset();
|
108
114
|
}
|
109
115
|
defaultLookupTables() {
|
110
|
-
return [
|
116
|
+
return [
|
117
|
+
solautoConstants_1.SOLAUTO_LUT,
|
118
|
+
...(this.authorityLutAddress
|
119
|
+
? [this.authorityLutAddress.toString()]
|
120
|
+
: []),
|
121
|
+
];
|
111
122
|
}
|
112
123
|
lutAccountsToAdd() {
|
113
124
|
return [
|
@@ -255,7 +266,7 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
255
266
|
positionSupplyTa: (0, umi_1.publicKey)(this.positionSupplyTa),
|
256
267
|
positionDebtTa: (0, umi_1.publicKey)(this.positionDebtTa),
|
257
268
|
signerDebtTa: (0, umi_1.publicKey)(this.signerDebtTa),
|
258
|
-
protocolAccount: (0, umi_1.publicKey)(this.protocolAccount())
|
269
|
+
protocolAccount: (0, umi_1.publicKey)(this.protocolAccount()),
|
259
270
|
});
|
260
271
|
}
|
261
272
|
cancelDCAIx() {
|
package/package.json
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
import "rpc-websockets/dist/lib/client";
|
2
|
-
import {
|
3
|
-
AddressLookupTableProgram,
|
4
|
-
PublicKey,
|
5
|
-
} from "@solana/web3.js";
|
2
|
+
import { AddressLookupTableProgram, PublicKey } from "@solana/web3.js";
|
6
3
|
import {
|
7
4
|
Signer,
|
8
5
|
TransactionBuilder,
|
@@ -40,9 +37,7 @@ import {
|
|
40
37
|
getSolautoPositionAccount,
|
41
38
|
getTokenAccount,
|
42
39
|
} from "../utils/accountUtils";
|
43
|
-
import {
|
44
|
-
SOLAUTO_FEES_WALLET,
|
45
|
-
} from "../constants/generalAccounts";
|
40
|
+
import { SOLAUTO_FEES_WALLET } from "../constants/generalAccounts";
|
46
41
|
import { JupSwapDetails } from "../utils/jupiterUtils";
|
47
42
|
import {
|
48
43
|
getWrappedInstruction,
|
@@ -145,7 +140,9 @@ export abstract class SolautoClient extends TxHandler {
|
|
145
140
|
|
146
141
|
this.supplyMint =
|
147
142
|
args.supplyMint ??
|
148
|
-
|
143
|
+
(this.solautoPositionData
|
144
|
+
? toWeb3JsPublicKey(this.solautoPositionData!.position.supplyMint)
|
145
|
+
: PublicKey.default);
|
149
146
|
this.positionSupplyTa = getTokenAccount(
|
150
147
|
this.solautoPosition,
|
151
148
|
this.supplyMint
|
@@ -157,29 +154,32 @@ export abstract class SolautoClient extends TxHandler {
|
|
157
154
|
|
158
155
|
this.debtMint =
|
159
156
|
args.debtMint ??
|
160
|
-
|
157
|
+
(this.solautoPositionData
|
158
|
+
? toWeb3JsPublicKey(this.solautoPositionData!.position.debtMint)
|
159
|
+
: PublicKey.default);
|
161
160
|
this.positionDebtTa = getTokenAccount(this.solautoPosition, this.debtMint);
|
162
161
|
this.signerDebtTa = getTokenAccount(
|
163
162
|
toWeb3JsPublicKey(this.signer.publicKey),
|
164
163
|
this.debtMint
|
165
164
|
);
|
166
165
|
|
167
|
-
this.referralStateManager = new ReferralStateManager(this.heliusApiKey)
|
166
|
+
this.referralStateManager = new ReferralStateManager(this.heliusApiKey);
|
168
167
|
await this.referralStateManager.initialize({
|
169
168
|
referralAuthority: this.authority,
|
170
169
|
signer: args.signer,
|
171
|
-
wallet: args.wallet
|
170
|
+
wallet: args.wallet,
|
172
171
|
});
|
173
172
|
|
174
|
-
const authorityReferralStateData =
|
173
|
+
const authorityReferralStateData =
|
174
|
+
this.referralStateManager.referralStateData;
|
175
175
|
const hasReferredBy =
|
176
176
|
authorityReferralStateData &&
|
177
177
|
authorityReferralStateData.referredByState !==
|
178
|
-
|
178
|
+
publicKey(PublicKey.default);
|
179
179
|
const referredByAuthority =
|
180
180
|
!hasReferredBy &&
|
181
|
-
|
182
|
-
|
181
|
+
args.referredByAuthority &&
|
182
|
+
!args.referredByAuthority.equals(toWeb3JsPublicKey(this.signer.publicKey))
|
183
183
|
? args.referredByAuthority
|
184
184
|
: undefined;
|
185
185
|
this.referredByState = hasReferredBy
|
@@ -201,9 +201,13 @@ export abstract class SolautoClient extends TxHandler {
|
|
201
201
|
this.supplyMint
|
202
202
|
);
|
203
203
|
|
204
|
-
this.authorityLutAddress =
|
205
|
-
|
206
|
-
|
204
|
+
this.authorityLutAddress =
|
205
|
+
authorityReferralStateData?.lookupTable &&
|
206
|
+
!toWeb3JsPublicKey(authorityReferralStateData.lookupTable).equals(
|
207
|
+
PublicKey.default
|
208
|
+
)
|
209
|
+
? toWeb3JsPublicKey(authorityReferralStateData.lookupTable)
|
210
|
+
: undefined;
|
207
211
|
|
208
212
|
this.log("Position state: ", this.solautoPositionState);
|
209
213
|
this.log(
|
@@ -244,7 +248,12 @@ export abstract class SolautoClient extends TxHandler {
|
|
244
248
|
abstract protocolAccount(): PublicKey;
|
245
249
|
|
246
250
|
defaultLookupTables(): string[] {
|
247
|
-
return [
|
251
|
+
return [
|
252
|
+
SOLAUTO_LUT,
|
253
|
+
...(this.authorityLutAddress
|
254
|
+
? [this.authorityLutAddress.toString()]
|
255
|
+
: []),
|
256
|
+
];
|
248
257
|
}
|
249
258
|
|
250
259
|
lutAccountsToAdd(): PublicKey[] {
|
@@ -324,7 +333,7 @@ export abstract class SolautoClient extends TxHandler {
|
|
324
333
|
const addingReferredBy =
|
325
334
|
accountsToAdd.length === 1 &&
|
326
335
|
accountsToAdd[0].toString().toLowerCase() ===
|
327
|
-
|
336
|
+
this.referredBySupplyTa?.toString().toLowerCase();
|
328
337
|
|
329
338
|
if (tx.getInstructions().length > 0) {
|
330
339
|
this.log("Updating authority lookup table...");
|
@@ -440,7 +449,7 @@ export abstract class SolautoClient extends TxHandler {
|
|
440
449
|
positionSupplyTa: publicKey(this.positionSupplyTa),
|
441
450
|
positionDebtTa: publicKey(this.positionDebtTa),
|
442
451
|
signerDebtTa: publicKey(this.signerDebtTa),
|
443
|
-
protocolAccount: publicKey(this.protocolAccount())
|
452
|
+
protocolAccount: publicKey(this.protocolAccount()),
|
444
453
|
});
|
445
454
|
}
|
446
455
|
|
@@ -509,7 +518,7 @@ export abstract class SolautoClient extends TxHandler {
|
|
509
518
|
BigInt(
|
510
519
|
Math.round(
|
511
520
|
Number(this.solautoPositionState!.debt.amountUsed.baseUnit) *
|
512
|
-
|
521
|
+
1.01
|
513
522
|
)
|
514
523
|
)
|
515
524
|
)
|
@@ -582,7 +591,7 @@ export abstract class SolautoClient extends TxHandler {
|
|
582
591
|
Boolean(this.solautoPositionData) &&
|
583
592
|
Boolean(this.solautoPositionState) &&
|
584
593
|
Number(this.solautoPositionState!.lastUpdated) >
|
585
|
-
|
594
|
+
currentUnixSeconds() - MIN_POSITION_STATE_FRESHNESS_SECS &&
|
586
595
|
!this.livePositionUpdates.hasUpdates()
|
587
596
|
) {
|
588
597
|
return this.solautoPositionState;
|