@haven-fi/solauto-sdk 1.0.26 → 1.0.28

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,6 +27,7 @@ export declare class SolautoMarginfiClient extends SolautoClient {
27
27
  initialize(args: SolautoMarginfiClientArgs): Promise<void>;
28
28
  defaultLookupTables(): string[];
29
29
  lutAccountsToAdd(): PublicKey[];
30
+ marginfiAccountInitialize(): TransactionBuilder;
30
31
  openPosition(settingParams?: SolautoSettingsParametersInpArgs, dca?: DCASettingsInpArgs): TransactionBuilder;
31
32
  private marginfiOpenPositionIx;
32
33
  refresh(): TransactionBuilder;
@@ -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,EACl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];
82
82
  }
83
+ marginfiAccountInitialize() {
84
+ return (0, marginfi_sdk_1.marginfiAccountInitialize)(this.umi, {
85
+ marginfiAccount: this.marginfiAccount,
86
+ marginfiGroup: (0, umi_1.publicKey)(this.marginfiGroup),
87
+ authority: this.signer,
88
+ feePayer: this.signer,
89
+ });
90
+ }
83
91
  openPosition(settingParams, dca) {
84
92
  return super
85
93
  .openPosition(settingParams, dca)
@@ -147,6 +155,7 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
147
155
  marginfiProtocolInteractionIx(args) {
148
156
  switch (args.__kind) {
149
157
  case "Deposit": {
158
+ console.log(args.fields[0]);
150
159
  return (0, marginfi_sdk_1.lendingAccountDeposit)(this.umi, {
151
160
  amount: args.fields[0],
152
161
  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,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EAQd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAgLzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,kBAAkB,CAAC,CAsE7B;AA0DD,wBAAsB,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"}
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,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EAQd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,kBAAkB,CAAC,CAgE7B;AAgKD,wBAAsB,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);
@@ -52,8 +53,15 @@ async function transactionChoresBefore(client, solautoActions, initiatingDcaIn)
52
53
  (0, umi_1.publicKey)(web3_js_1.PublicKey.default))) {
53
54
  chores = chores.add(client.updateReferralStatesIx());
54
55
  }
55
- if (client.selfManaged && client.solautoPositionData === undefined) {
56
- chores = chores.add(client.openPosition());
56
+ if (client.selfManaged) {
57
+ if (client.solautoPositionData === undefined) {
58
+ chores = chores.add(client.openPosition());
59
+ }
60
+ else if (client.lendingPlatform === generated_1.LendingPlatform.Marginfi &&
61
+ !(await (0, generalUtils_1.getSolanaAccountCreated)(client.umi, client.marginfiAccountPk))) {
62
+ chores = chores.add(client.marginfiAccountInitialize());
63
+ }
64
+ // TODO: support other platforms
57
65
  }
58
66
  const wSolUsage = getWSolUsage(client, solautoActions, initiatingDcaIn, undefined);
59
67
  if (wSolUsage !== undefined) {
@@ -148,22 +156,111 @@ function transactionChoresAfter(client, solautoActions, cancellingDcaIn) {
148
156
  function getSolautoActions(tx) {
149
157
  let solautoActions = [];
150
158
  tx.getInstructions().forEach((x) => {
151
- if (x.programId !== generated_1.SOLAUTO_PROGRAM_ID) {
152
- return;
159
+ if (x.programId === generated_1.SOLAUTO_PROGRAM_ID) {
160
+ try {
161
+ const serializer = (0, generated_1.getMarginfiProtocolInteractionInstructionDataSerializer)();
162
+ const discriminator = serializer
163
+ .serialize({
164
+ solautoAction: (0, generated_1.solautoAction)("Deposit", [BigInt(0)]),
165
+ })
166
+ .slice(0, 1)[0];
167
+ const [data, _] = serializer.deserialize(x.data);
168
+ if (data.discriminator === discriminator) {
169
+ solautoActions?.push(data.solautoAction);
170
+ }
171
+ }
172
+ catch { }
153
173
  }
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);
174
+ if (x.programId === marginfi_sdk_1.MARGINFI_PROGRAM_ID) {
175
+ try {
176
+ const serializer = (0, marginfi_sdk_1.getLendingAccountDepositInstructionDataSerializer)();
177
+ const discriminator = (0, numberUtils_1.uint8ArrayToBigInt)(serializer
178
+ .serialize({
179
+ amount: 0,
180
+ })
181
+ .slice(0, 8));
182
+ const [data, _] = serializer.deserialize(x.data);
183
+ if ((0, numberUtils_1.uint8ArrayToBigInt)(new Uint8Array(data.discriminator)) ===
184
+ discriminator) {
185
+ solautoActions?.push({
186
+ __kind: "Deposit",
187
+ fields: [data.amount],
188
+ });
189
+ }
190
+ }
191
+ catch { }
192
+ try {
193
+ const serializer = (0, marginfi_sdk_1.getLendingAccountBorrowInstructionDataSerializer)();
194
+ const discriminator = (0, numberUtils_1.uint8ArrayToBigInt)(serializer
195
+ .serialize({
196
+ amount: 0,
197
+ })
198
+ .slice(0, 8));
199
+ const [data, _] = serializer.deserialize(x.data);
200
+ if ((0, numberUtils_1.uint8ArrayToBigInt)(new Uint8Array(data.discriminator)) ===
201
+ discriminator) {
202
+ solautoActions?.push({
203
+ __kind: "Borrow",
204
+ fields: [data.amount],
205
+ });
206
+ }
207
+ }
208
+ catch { }
209
+ try {
210
+ const serializer = (0, marginfi_sdk_1.getLendingAccountWithdrawInstructionDataSerializer)();
211
+ const discriminator = (0, numberUtils_1.uint8ArrayToBigInt)(serializer
212
+ .serialize({
213
+ amount: 0,
214
+ withdrawAll: false,
215
+ })
216
+ .slice(0, 8));
217
+ const [data, _] = serializer.deserialize(x.data);
218
+ if ((0, numberUtils_1.uint8ArrayToBigInt)(new Uint8Array(data.discriminator)) ===
219
+ discriminator) {
220
+ solautoActions?.push({
221
+ __kind: "Withdraw",
222
+ fields: [
223
+ data.withdrawAll
224
+ ? {
225
+ __kind: "All",
226
+ }
227
+ : {
228
+ __kind: "Some",
229
+ fields: [data.amount],
230
+ },
231
+ ],
232
+ });
233
+ }
234
+ }
235
+ catch { }
236
+ try {
237
+ const serializer = (0, marginfi_sdk_1.getLendingAccountRepayInstructionDataSerializer)();
238
+ const discriminator = (0, numberUtils_1.uint8ArrayToBigInt)(serializer
239
+ .serialize({
240
+ amount: 0,
241
+ repayAll: false,
242
+ })
243
+ .slice(0, 8));
244
+ const [data, _] = serializer.deserialize(x.data);
245
+ if ((0, numberUtils_1.uint8ArrayToBigInt)(new Uint8Array(data.discriminator)) ===
246
+ discriminator) {
247
+ solautoActions?.push({
248
+ __kind: "Repay",
249
+ fields: [
250
+ data.repayAll
251
+ ? {
252
+ __kind: "All",
253
+ }
254
+ : {
255
+ __kind: "Some",
256
+ fields: [data.amount],
257
+ },
258
+ ],
259
+ });
260
+ }
164
261
  }
262
+ catch { }
165
263
  }
166
- catch { }
167
264
  // TODO support other platforms
168
265
  });
169
266
  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,EAAE,SAAS,CAAC;IACtB,iBAAi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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.28",
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",
@@ -188,6 +188,15 @@ export class SolautoMarginfiClient extends SolautoClient {
188
188
  ];
189
189
  }
190
190
 
191
+ marginfiAccountInitialize(): TransactionBuilder {
192
+ return marginfiAccountInitialize(this.umi, {
193
+ marginfiAccount: this.marginfiAccount as Signer,
194
+ marginfiGroup: publicKey(this.marginfiGroup),
195
+ authority: this.signer,
196
+ feePayer: this.signer,
197
+ });
198
+ }
199
+
191
200
  openPosition(
192
201
  settingParams?: SolautoSettingsParametersInpArgs,
193
202
  dca?: DCASettingsInpArgs
@@ -267,6 +276,7 @@ export class SolautoMarginfiClient extends SolautoClient {
267
276
  private marginfiProtocolInteractionIx(args: SolautoActionArgs) {
268
277
  switch (args.__kind) {
269
278
  case "Deposit": {
279
+ console.log(args.fields[0]);
270
280
  return lendingAccountDeposit(this.umi, {
271
281
  amount: args.fields[0],
272
282
  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;
@@ -109,8 +117,21 @@ async function transactionChoresBefore(
109
117
  chores = chores.add(client.updateReferralStatesIx());
110
118
  }
111
119
 
112
- if (client.selfManaged && client.solautoPositionData === undefined) {
113
- chores = chores.add(client.openPosition());
120
+ if (client.selfManaged) {
121
+ if (client.solautoPositionData === undefined) {
122
+ chores = chores.add(client.openPosition());
123
+ } else if (
124
+ client.lendingPlatform === LendingPlatform.Marginfi &&
125
+ !(await getSolanaAccountCreated(
126
+ client.umi,
127
+ (client as SolautoMarginfiClient).marginfiAccountPk
128
+ ))
129
+ ) {
130
+ chores = chores.add(
131
+ (client as SolautoMarginfiClient).marginfiAccountInitialize()
132
+ );
133
+ }
134
+ // TODO: support other platforms
114
135
  }
115
136
 
116
137
  const wSolUsage = getWSolUsage(
@@ -235,10 +256,7 @@ export async function rebalanceChoresBefore(
235
256
  let chores = transactionBuilder();
236
257
 
237
258
  if (checkReferralSupplyTa && !rpcAccountCreated(referredBySupplyTa)) {
238
- client.log(
239
- "Creating referred-by TA for ",
240
- client.supplyMint.toString()
241
- );
259
+ client.log("Creating referred-by TA for ", client.supplyMint.toString());
242
260
  chores = chores.add(
243
261
  createAssociatedTokenAccountUmiIx(
244
262
  client.signer,
@@ -249,10 +267,7 @@ export async function rebalanceChoresBefore(
249
267
  }
250
268
 
251
269
  if (checkSolautoFeesTa && !rpcAccountCreated(solautoFeesSupplyTa)) {
252
- client.log(
253
- "Creating Solauto fees TA for ",
254
- client.supplyMint.toString()
255
- );
270
+ client.log("Creating Solauto fees TA for ", client.supplyMint.toString());
256
271
  chores = chores.add(
257
272
  createAssociatedTokenAccountUmiIx(
258
273
  client.signer,
@@ -304,25 +319,127 @@ function getSolautoActions(tx: TransactionBuilder): SolautoAction[] {
304
319
  let solautoActions: SolautoAction[] = [];
305
320
 
306
321
  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
322
+ if (x.programId === SOLAUTO_PROGRAM_ID) {
323
+ try {
324
+ const serializer =
325
+ getMarginfiProtocolInteractionInstructionDataSerializer();
326
+ const discriminator = serializer
316
327
  .serialize({
317
328
  solautoAction: solautoAction("Deposit", [BigInt(0)]),
318
329
  })
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 {}
330
+ .slice(0, 1)[0];
331
+ const [data, _] = serializer.deserialize(x.data);
332
+ if (data.discriminator === discriminator) {
333
+ solautoActions?.push(data.solautoAction);
334
+ }
335
+ } catch {}
336
+ }
337
+
338
+ if (x.programId === MARGINFI_PROGRAM_ID) {
339
+ try {
340
+ const serializer = getLendingAccountDepositInstructionDataSerializer();
341
+ const discriminator = uint8ArrayToBigInt(
342
+ serializer
343
+ .serialize({
344
+ amount: 0,
345
+ })
346
+ .slice(0, 8)
347
+ );
348
+ const [data, _] = serializer.deserialize(x.data);
349
+ if (
350
+ uint8ArrayToBigInt(new Uint8Array(data.discriminator)) ===
351
+ discriminator
352
+ ) {
353
+ solautoActions?.push({
354
+ __kind: "Deposit",
355
+ fields: [data.amount],
356
+ });
357
+ }
358
+ } catch {}
359
+
360
+ try {
361
+ const serializer = getLendingAccountBorrowInstructionDataSerializer();
362
+ const discriminator = uint8ArrayToBigInt(
363
+ serializer
364
+ .serialize({
365
+ amount: 0,
366
+ })
367
+ .slice(0, 8)
368
+ );
369
+ const [data, _] = serializer.deserialize(x.data);
370
+ if (
371
+ uint8ArrayToBigInt(new Uint8Array(data.discriminator)) ===
372
+ discriminator
373
+ ) {
374
+ solautoActions?.push({
375
+ __kind: "Borrow",
376
+ fields: [data.amount],
377
+ });
378
+ }
379
+ } catch {}
380
+
381
+ try {
382
+ const serializer = getLendingAccountWithdrawInstructionDataSerializer();
383
+ const discriminator = uint8ArrayToBigInt(
384
+ serializer
385
+ .serialize({
386
+ amount: 0,
387
+ withdrawAll: false,
388
+ })
389
+ .slice(0, 8)
390
+ );
391
+ const [data, _] = serializer.deserialize(x.data);
392
+ if (
393
+ uint8ArrayToBigInt(new Uint8Array(data.discriminator)) ===
394
+ discriminator
395
+ ) {
396
+ solautoActions?.push({
397
+ __kind: "Withdraw",
398
+ fields: [
399
+ data.withdrawAll
400
+ ? {
401
+ __kind: "All",
402
+ }
403
+ : {
404
+ __kind: "Some",
405
+ fields: [data.amount],
406
+ },
407
+ ],
408
+ });
409
+ }
410
+ } catch {}
411
+
412
+ try {
413
+ const serializer = getLendingAccountRepayInstructionDataSerializer();
414
+ const discriminator = uint8ArrayToBigInt(
415
+ serializer
416
+ .serialize({
417
+ amount: 0,
418
+ repayAll: false,
419
+ })
420
+ .slice(0, 8)
421
+ );
422
+ const [data, _] = serializer.deserialize(x.data);
423
+ if (
424
+ uint8ArrayToBigInt(new Uint8Array(data.discriminator)) ===
425
+ discriminator
426
+ ) {
427
+ solautoActions?.push({
428
+ __kind: "Repay",
429
+ fields: [
430
+ data.repayAll
431
+ ? {
432
+ __kind: "All",
433
+ }
434
+ : {
435
+ __kind: "Some",
436
+ fields: [data.amount],
437
+ },
438
+ ],
439
+ });
440
+ }
441
+ } catch {}
442
+ }
326
443
 
327
444
  // TODO support other platforms
328
445
  });
@@ -483,7 +600,7 @@ export async function buildSolautoRebalanceTransaction(
483
600
  export async function convertReferralFeesToDestination(
484
601
  umi: Umi,
485
602
  referralState: ReferralState,
486
- tokenAccount: SplTokenAccount,
603
+ tokenAccount: SplTokenAccount
487
604
  ): Promise<[TransactionBuilder, string[]]> {
488
605
  const { lookupTableAddresses, setupInstructions, swapIx } =
489
606
  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) =>