@haven-fi/solauto-sdk 1.0.26 → 1.0.27

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"solautoMarginfiClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoMarginfiClient.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,MAAM,EACN,kBAAkB,EAMnB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAGL,SAAS,EAEV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAK1D,OAAO,EACL,kBAAkB,EAElB,aAAa,EACb,iBAAiB,EACjB,wBAAwB,EACxB,gCAAgC,EAKjC,MAAM,cAAc,CAAC;AAGtB,OAAO,EAEL,eAAe,EAUhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAOnE,OAAO,EAAE,aAAa,EAAE,MAAM,iDAAiD,CAAC;AAEhF,MAAM,WAAW,yBAA0B,SAAQ,iBAAiB;IAClE,eAAe,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IACrC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,aAAa,CAAC,EAAE,SAAS,CAAC;CAC3B;AAED,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,MAAM,EAAE,aAAa,GAAG,SAAS,EACjC,UAAU,EAAE,SAAS,EACrB,QAAQ,EAAE,SAAS,EACnB,mBAAmB,CAAC,EAAE,SAAS,GAC9B,yBAAyB,CAe3B;AAED,qBAAa,qBAAsB,SAAQ,aAAa;IAC/C,eAAe,EAAG,SAAS,CAAC;IAE5B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,eAAe,EAA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A2B,CAAC,EAAE,eAAe,CAAC;IAE/C,UAAU,CAAC,IAAI,EAAE,yBAAyB;IAoEhD,mBAAmB,IAAI,MAAM,EAAE;IAI/B,gBAAgB,IAAI,SAAS,EAAE;IAQ/B,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA2C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAsDrC,OAAO,CAAC,oCAAoC;IA8D5C,SAAS,CACP,aAAa,EAAE,GAAG,GAAG,GAAG,EACxB,WAAW,EAAE,cAAc,EAC3B,aAAa,EAAE,wBAAwB,EACvC,2BAA2B,CAAC,EAAE,MAAM,EACpC,WAAW,CAAC,EAAE,MAAM,GACnB,kBAAkB;IA8CrB,WAAW,CACT,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,EAAE,SAAS,GACjC,kBAAkB;IA2BrB,UAAU,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,kBAAkB;IA8ElE,iCAAiC,IAAI,kBAAkB;IASjD,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAiBlE"}
@@ -147,6 +147,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
147
147
  marginfiProtocolInteractionIx(args) {
148
148
  switch (args.__kind) {
149
149
  case "Deposit": {
150
+ console.log(args.fields[0]);
150
151
  return (0, marginfi_sdk_1.lendingAccountDeposit)(this.umi, {
151
152
  amount: args.fields[0],
152
153
  signer: this.signer,
@@ -1 +1 @@
1
- {"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAGL,OAAO,IAA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B,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA0BnD;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,CA2GA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,eAAe,GAC5B,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC,CA8BzC"}
@@ -13,6 +13,7 @@ const generalUtils_1 = require("../utils/generalUtils");
13
13
  const numberUtils_1 = require("../utils/numberUtils");
14
14
  const generalUtils_2 = require("../utils/solauto/generalUtils");
15
15
  const accountUtils_1 = require("../utils/accountUtils");
16
+ const marginfi_sdk_1 = require("../marginfi-sdk");
16
17
  function getWSolUsage(client, solautoActions, initiatingDcaIn, cancellingDcaIn) {
17
18
  const supplyIsWsol = client.supplyMint.equals(spl_token_1.NATIVE_MINT);
18
19
  const debtIsWsol = client.debtMint.equals(spl_token_1.NATIVE_MINT);
@@ -148,22 +149,111 @@ function transactionChoresAfter(client, solautoActions, cancellingDcaIn) {
148
149
  function getSolautoActions(tx) {
149
150
  let solautoActions = [];
150
151
  tx.getInstructions().forEach((x) => {
151
- if (x.programId !== generated_1.SOLAUTO_PROGRAM_ID) {
152
- return;
152
+ if (x.programId === generated_1.SOLAUTO_PROGRAM_ID) {
153
+ try {
154
+ const serializer = (0, generated_1.getMarginfiProtocolInteractionInstructionDataSerializer)();
155
+ const discriminator = serializer
156
+ .serialize({
157
+ solautoAction: (0, generated_1.solautoAction)("Deposit", [BigInt(0)]),
158
+ })
159
+ .slice(0, 1)[0];
160
+ const [data, _] = serializer.deserialize(x.data);
161
+ if (data.discriminator === discriminator) {
162
+ solautoActions?.push(data.solautoAction);
163
+ }
164
+ }
165
+ catch { }
153
166
  }
154
- try {
155
- const serializer = (0, generated_1.getMarginfiProtocolInteractionInstructionDataSerializer)();
156
- const discriminator = (0, numberUtils_1.uint8ArrayToBigInt)(serializer
157
- .serialize({
158
- solautoAction: (0, generated_1.solautoAction)("Deposit", [BigInt(0)]),
159
- })
160
- .slice(0, 8));
161
- const [data, _] = serializer.deserialize(x.data);
162
- if (BigInt(data.discriminator) === discriminator) {
163
- solautoActions?.push(data.solautoAction);
167
+ if (x.programId === marginfi_sdk_1.MARGINFI_PROGRAM_ID) {
168
+ try {
169
+ const serializer = (0, marginfi_sdk_1.getLendingAccountDepositInstructionDataSerializer)();
170
+ const discriminator = (0, numberUtils_1.uint8ArrayToBigInt)(serializer
171
+ .serialize({
172
+ amount: 0,
173
+ })
174
+ .slice(0, 8));
175
+ const [data, _] = serializer.deserialize(x.data);
176
+ if ((0, numberUtils_1.uint8ArrayToBigInt)(new Uint8Array(data.discriminator)) ===
177
+ discriminator) {
178
+ solautoActions?.push({
179
+ __kind: "Deposit",
180
+ fields: [data.amount],
181
+ });
182
+ }
183
+ }
184
+ catch { }
185
+ try {
186
+ const serializer = (0, marginfi_sdk_1.getLendingAccountBorrowInstructionDataSerializer)();
187
+ const discriminator = (0, numberUtils_1.uint8ArrayToBigInt)(serializer
188
+ .serialize({
189
+ amount: 0,
190
+ })
191
+ .slice(0, 8));
192
+ const [data, _] = serializer.deserialize(x.data);
193
+ if ((0, numberUtils_1.uint8ArrayToBigInt)(new Uint8Array(data.discriminator)) ===
194
+ discriminator) {
195
+ solautoActions?.push({
196
+ __kind: "Borrow",
197
+ fields: [data.amount],
198
+ });
199
+ }
200
+ }
201
+ catch { }
202
+ try {
203
+ const serializer = (0, marginfi_sdk_1.getLendingAccountWithdrawInstructionDataSerializer)();
204
+ const discriminator = (0, numberUtils_1.uint8ArrayToBigInt)(serializer
205
+ .serialize({
206
+ amount: 0,
207
+ withdrawAll: false,
208
+ })
209
+ .slice(0, 8));
210
+ const [data, _] = serializer.deserialize(x.data);
211
+ if ((0, numberUtils_1.uint8ArrayToBigInt)(new Uint8Array(data.discriminator)) ===
212
+ discriminator) {
213
+ solautoActions?.push({
214
+ __kind: "Withdraw",
215
+ fields: [
216
+ data.withdrawAll
217
+ ? {
218
+ __kind: "All",
219
+ }
220
+ : {
221
+ __kind: "Some",
222
+ fields: [data.amount],
223
+ },
224
+ ],
225
+ });
226
+ }
227
+ }
228
+ catch { }
229
+ try {
230
+ const serializer = (0, marginfi_sdk_1.getLendingAccountRepayInstructionDataSerializer)();
231
+ const discriminator = (0, numberUtils_1.uint8ArrayToBigInt)(serializer
232
+ .serialize({
233
+ amount: 0,
234
+ repayAll: false,
235
+ })
236
+ .slice(0, 8));
237
+ const [data, _] = serializer.deserialize(x.data);
238
+ if ((0, numberUtils_1.uint8ArrayToBigInt)(new Uint8Array(data.discriminator)) ===
239
+ discriminator) {
240
+ solautoActions?.push({
241
+ __kind: "Repay",
242
+ fields: [
243
+ data.repayAll
244
+ ? {
245
+ __kind: "All",
246
+ }
247
+ : {
248
+ __kind: "Some",
249
+ fields: [data.amount],
250
+ },
251
+ ],
252
+ });
253
+ }
164
254
  }
255
+ catch { }
165
256
  }
166
- catch { }
167
257
  // TODO support other platforms
168
258
  });
169
259
  return solautoActions;
@@ -1 +1 @@
1
- {"version":3,"file":"jupiterUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jupiterUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAKrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,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;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,GAC1B,OAAO,CAAC,kBAAkB,CAAC,CAkE7B"}
@@ -30,6 +30,7 @@ async function getJupSwapTransaction(signer, swapDetails) {
30
30
  : swapDetails.exactIn
31
31
  ? "ExactIn"
32
32
  : undefined,
33
+ slippageBps: 10
33
34
  });
34
35
  const finalPriceSlippageBps = Math.round(Math.max(quoteResponse.slippageBps ?? 10, Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct)))) *
35
36
  (1 + (swapDetails.slippageBpsIncFactor ?? 0)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haven-fi/solauto-sdk",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
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",
@@ -267,6 +267,7 @@ export class SolautoMarginfiClient extends SolautoClient {
267
267
  private marginfiProtocolInteractionIx(args: SolautoActionArgs) {
268
268
  switch (args.__kind) {
269
269
  case "Deposit": {
270
+ console.log(args.fields[0]);
270
271
  return lendingAccountDeposit(this.umi, {
271
272
  amount: args.fields[0],
272
273
  signer: this.signer,
@@ -40,11 +40,19 @@ import {
40
40
  rpcAccountCreated,
41
41
  } from "../utils/generalUtils";
42
42
  import { SolautoMarginfiClient } from "../clients/solautoMarginfiClient";
43
- import { getMaxLiqUtilizationRate, uint8ArrayToBigInt } from "../utils/numberUtils";
44
43
  import {
45
- eligibileForRebalance,
46
- } from "../utils/solauto/generalUtils";
44
+ getMaxLiqUtilizationRate,
45
+ uint8ArrayToBigInt,
46
+ } from "../utils/numberUtils";
47
+ import { eligibileForRebalance } from "../utils/solauto/generalUtils";
47
48
  import { getTokenAccount } from "../utils/accountUtils";
49
+ import {
50
+ getLendingAccountBorrowInstructionDataSerializer,
51
+ getLendingAccountDepositInstructionDataSerializer,
52
+ getLendingAccountRepayInstructionDataSerializer,
53
+ getLendingAccountWithdrawInstructionDataSerializer,
54
+ MARGINFI_PROGRAM_ID,
55
+ } from "../marginfi-sdk";
48
56
 
49
57
  interface wSolTokenUsage {
50
58
  wSolTokenAccount: PublicKey;
@@ -235,10 +243,7 @@ export async function rebalanceChoresBefore(
235
243
  let chores = transactionBuilder();
236
244
 
237
245
  if (checkReferralSupplyTa && !rpcAccountCreated(referredBySupplyTa)) {
238
- client.log(
239
- "Creating referred-by TA for ",
240
- client.supplyMint.toString()
241
- );
246
+ client.log("Creating referred-by TA for ", client.supplyMint.toString());
242
247
  chores = chores.add(
243
248
  createAssociatedTokenAccountUmiIx(
244
249
  client.signer,
@@ -249,10 +254,7 @@ export async function rebalanceChoresBefore(
249
254
  }
250
255
 
251
256
  if (checkSolautoFeesTa && !rpcAccountCreated(solautoFeesSupplyTa)) {
252
- client.log(
253
- "Creating Solauto fees TA for ",
254
- client.supplyMint.toString()
255
- );
257
+ client.log("Creating Solauto fees TA for ", client.supplyMint.toString());
256
258
  chores = chores.add(
257
259
  createAssociatedTokenAccountUmiIx(
258
260
  client.signer,
@@ -304,25 +306,127 @@ function getSolautoActions(tx: TransactionBuilder): SolautoAction[] {
304
306
  let solautoActions: SolautoAction[] = [];
305
307
 
306
308
  tx.getInstructions().forEach((x) => {
307
- if (x.programId !== SOLAUTO_PROGRAM_ID) {
308
- return;
309
- }
310
-
311
- try {
312
- const serializer =
313
- getMarginfiProtocolInteractionInstructionDataSerializer();
314
- const discriminator = uint8ArrayToBigInt(
315
- serializer
309
+ if (x.programId === SOLAUTO_PROGRAM_ID) {
310
+ try {
311
+ const serializer =
312
+ getMarginfiProtocolInteractionInstructionDataSerializer();
313
+ const discriminator = serializer
316
314
  .serialize({
317
315
  solautoAction: solautoAction("Deposit", [BigInt(0)]),
318
316
  })
319
- .slice(0, 8)
320
- );
321
- const [data, _] = serializer.deserialize(x.data);
322
- if (BigInt(data.discriminator) === discriminator) {
323
- solautoActions?.push(data.solautoAction);
324
- }
325
- } catch {}
317
+ .slice(0, 1)[0];
318
+ const [data, _] = serializer.deserialize(x.data);
319
+ if (data.discriminator === discriminator) {
320
+ solautoActions?.push(data.solautoAction);
321
+ }
322
+ } catch {}
323
+ }
324
+
325
+ if (x.programId === MARGINFI_PROGRAM_ID) {
326
+ try {
327
+ const serializer = getLendingAccountDepositInstructionDataSerializer();
328
+ const discriminator = uint8ArrayToBigInt(
329
+ serializer
330
+ .serialize({
331
+ amount: 0,
332
+ })
333
+ .slice(0, 8)
334
+ );
335
+ const [data, _] = serializer.deserialize(x.data);
336
+ if (
337
+ uint8ArrayToBigInt(new Uint8Array(data.discriminator)) ===
338
+ discriminator
339
+ ) {
340
+ solautoActions?.push({
341
+ __kind: "Deposit",
342
+ fields: [data.amount],
343
+ });
344
+ }
345
+ } catch {}
346
+
347
+ try {
348
+ const serializer = getLendingAccountBorrowInstructionDataSerializer();
349
+ const discriminator = uint8ArrayToBigInt(
350
+ serializer
351
+ .serialize({
352
+ amount: 0,
353
+ })
354
+ .slice(0, 8)
355
+ );
356
+ const [data, _] = serializer.deserialize(x.data);
357
+ if (
358
+ uint8ArrayToBigInt(new Uint8Array(data.discriminator)) ===
359
+ discriminator
360
+ ) {
361
+ solautoActions?.push({
362
+ __kind: "Borrow",
363
+ fields: [data.amount],
364
+ });
365
+ }
366
+ } catch {}
367
+
368
+ try {
369
+ const serializer = getLendingAccountWithdrawInstructionDataSerializer();
370
+ const discriminator = uint8ArrayToBigInt(
371
+ serializer
372
+ .serialize({
373
+ amount: 0,
374
+ withdrawAll: false,
375
+ })
376
+ .slice(0, 8)
377
+ );
378
+ const [data, _] = serializer.deserialize(x.data);
379
+ if (
380
+ uint8ArrayToBigInt(new Uint8Array(data.discriminator)) ===
381
+ discriminator
382
+ ) {
383
+ solautoActions?.push({
384
+ __kind: "Withdraw",
385
+ fields: [
386
+ data.withdrawAll
387
+ ? {
388
+ __kind: "All",
389
+ }
390
+ : {
391
+ __kind: "Some",
392
+ fields: [data.amount],
393
+ },
394
+ ],
395
+ });
396
+ }
397
+ } catch {}
398
+
399
+ try {
400
+ const serializer = getLendingAccountRepayInstructionDataSerializer();
401
+ const discriminator = uint8ArrayToBigInt(
402
+ serializer
403
+ .serialize({
404
+ amount: 0,
405
+ repayAll: false,
406
+ })
407
+ .slice(0, 8)
408
+ );
409
+ const [data, _] = serializer.deserialize(x.data);
410
+ if (
411
+ uint8ArrayToBigInt(new Uint8Array(data.discriminator)) ===
412
+ discriminator
413
+ ) {
414
+ solautoActions?.push({
415
+ __kind: "Repay",
416
+ fields: [
417
+ data.repayAll
418
+ ? {
419
+ __kind: "All",
420
+ }
421
+ : {
422
+ __kind: "Some",
423
+ fields: [data.amount],
424
+ },
425
+ ],
426
+ });
427
+ }
428
+ } catch {}
429
+ }
326
430
 
327
431
  // TODO support other platforms
328
432
  });
@@ -483,7 +587,7 @@ export async function buildSolautoRebalanceTransaction(
483
587
  export async function convertReferralFeesToDestination(
484
588
  umi: Umi,
485
589
  referralState: ReferralState,
486
- tokenAccount: SplTokenAccount,
590
+ tokenAccount: SplTokenAccount
487
591
  ): Promise<[TransactionBuilder, string[]]> {
488
592
  const { lookupTableAddresses, setupInstructions, swapIx } =
489
593
  await getJupSwapTransaction(umi.identity, {
@@ -62,6 +62,7 @@ export async function getJupSwapTransaction(
62
62
  : swapDetails.exactIn
63
63
  ? "ExactIn"
64
64
  : undefined,
65
+ slippageBps: 10
65
66
  });
66
67
 
67
68
  const finalPriceSlippageBps = Math.round(
@@ -45,9 +45,11 @@ describe("Solauto Marginfi tests", async () => {
45
45
  {
46
46
  signer,
47
47
  positionId,
48
- marginfiAccount: new PublicKey("4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"),
48
+ marginfiAccount: new PublicKey(
49
+ "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
50
+ ),
49
51
  supplyMint: NATIVE_MINT,
50
- debtMint: new PublicKey(USDC_MINT)
52
+ debtMint: new PublicKey(USDC_MINT),
51
53
  }
52
54
  );
53
55
 
@@ -104,6 +106,20 @@ describe("Solauto Marginfi tests", async () => {
104
106
  // )
105
107
  // );
106
108
 
109
+ // const initialSupplyUsd = 50;
110
+ // transactionItems.push(
111
+ // new TransactionItem(async () => {
112
+ // const [supplyPrice] = await getTokenPrices([supply]);
113
+ // return {
114
+ // tx: client.protocolInteraction(
115
+ // solautoAction("Deposit", [
116
+ // toBaseUnit(initialSupplyUsd / supplyPrice, supplyDecimals),
117
+ // ])
118
+ // ),
119
+ // };
120
+ // }, "deposit")
121
+ // );
122
+
107
123
  transactionItems.push(
108
124
  new TransactionItem(
109
125
  async (attemptNum) =>