@haven-fi/solauto-sdk 1.0.101 → 1.0.103
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +0 -8
- package/dist/transactions/transactionUtils.d.ts +2 -2
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +8 -4
- package/dist/utils/accountUtils.d.ts +2 -0
- package/dist/utils/accountUtils.d.ts.map +1 -1
- package/dist/utils/accountUtils.js +11 -0
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +3 -1
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +0 -9
- package/src/transactions/transactionUtils.ts +11 -6
- package/src/utils/accountUtils.ts +11 -1
- package/src/utils/generalUtils.ts +3 -1
- package/tests/transactions/solautoMarginfi.ts +7 -7
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solautoClient.d.ts","sourceRoot":"","sources":["../../src/clients/solautoClient.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC;AACxC,OAAO,EAEL,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,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;AAStB,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,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AG,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;IAWrC,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"}
|
@@ -124,7 +124,6 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
124
124
|
];
|
125
125
|
}
|
126
126
|
async fetchExistingAuthorityLutAccounts() {
|
127
|
-
console.log("Fetching lut accounts", this.authorityLutAddress?.toString());
|
128
127
|
const lookupTable = this.authorityLutAddress
|
129
128
|
? await this.connection.getAddressLookupTable(this.authorityLutAddress)
|
130
129
|
: null;
|
@@ -135,30 +134,25 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
135
134
|
return lookupTable?.value?.state.addresses ?? [];
|
136
135
|
}
|
137
136
|
async updateLookupTable() {
|
138
|
-
console.log("Getting existing accoutns");
|
139
137
|
const existingLutAccounts = await this.fetchExistingAuthorityLutAccounts();
|
140
|
-
console.log("existing accoutns", existingLutAccounts.length);
|
141
138
|
if (this.lutAccountsToAdd().every((element) => existingLutAccounts
|
142
139
|
.map((x) => x.toString().toLowerCase())
|
143
140
|
.includes(element.toString().toLowerCase()))) {
|
144
141
|
return undefined;
|
145
142
|
}
|
146
143
|
let tx = (0, umi_1.transactionBuilder)();
|
147
|
-
console.log("lut address", this.authorityLutAddress?.toString());
|
148
144
|
if (this.authorityLutAddress === undefined) {
|
149
145
|
const [createLookupTableInst, lookupTableAddress] = web3_js_1.AddressLookupTableProgram.createLookupTable({
|
150
146
|
authority: this.authority,
|
151
147
|
payer: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey),
|
152
148
|
recentSlot: await this.umi.rpc.getSlot({ commitment: "finalized" }),
|
153
149
|
});
|
154
|
-
console.log("new luit", lookupTableAddress.toString());
|
155
150
|
this.authorityLutAddress = lookupTableAddress;
|
156
151
|
tx = tx.add((0, solanaUtils_1.getWrappedInstruction)(this.signer, createLookupTableInst));
|
157
152
|
}
|
158
153
|
const accountsToAdd = this.lutAccountsToAdd().filter((x) => !existingLutAccounts
|
159
154
|
.map((x) => x.toString().toLowerCase())
|
160
155
|
.includes(x.toString().toLowerCase()));
|
161
|
-
console.log("add accounts", accountsToAdd.length);
|
162
156
|
if (accountsToAdd.length > 0) {
|
163
157
|
tx = tx.add((0, solanaUtils_1.getWrappedInstruction)(this.signer, web3_js_1.AddressLookupTableProgram.extendLookupTable({
|
164
158
|
payer: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(this.signer.publicKey),
|
@@ -167,14 +161,12 @@ class SolautoClient extends txHandler_1.TxHandler {
|
|
167
161
|
addresses: accountsToAdd,
|
168
162
|
})));
|
169
163
|
}
|
170
|
-
console.log("Hello");
|
171
164
|
const addingReferredBy = accountsToAdd.length === 1 &&
|
172
165
|
accountsToAdd[0].toString().toLowerCase() ===
|
173
166
|
this.referredBySupplyTa?.toString().toLowerCase();
|
174
167
|
if (tx.getInstructions().length > 0) {
|
175
168
|
this.log("Updating authority lookup table...");
|
176
169
|
}
|
177
|
-
console.log("instructions", tx.getInstructions().length);
|
178
170
|
return { updateLutTx: tx, needsToBeIsolated: !addingReferredBy };
|
179
171
|
}
|
180
172
|
solautoPositionSettings() {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { TransactionBuilder, Umi } from "@metaplex-foundation/umi";
|
2
|
-
import {
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
3
3
|
import { ReferralState } from "../generated";
|
4
4
|
import { SolautoClient } from "../clients/solautoClient";
|
5
5
|
export declare function rebalanceChoresBefore(client: SolautoClient, tx: TransactionBuilder, accountsGettingCreated: string[]): Promise<TransactionBuilder>;
|
@@ -8,5 +8,5 @@ export declare function buildSolautoRebalanceTransaction(client: SolautoClient,
|
|
8
8
|
tx: TransactionBuilder;
|
9
9
|
lookupTableAddresses: string[];
|
10
10
|
} | undefined>;
|
11
|
-
export declare function convertReferralFeesToDestination(umi: Umi, referralState: ReferralState, tokenAccount:
|
11
|
+
export declare function convertReferralFeesToDestination(umi: Umi, referralState: ReferralState, tokenAccount: PublicKey): Promise<[TransactionBuilder, string[]] | undefined>;
|
12
12
|
//# sourceMappingURL=transactionUtils.d.ts.map
|
@@ -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;
|
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;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAMxE,OAAO,EAGL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAuMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA8G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA4BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC;IACT,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACG,SAAS,CACZ,CAyHA;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"}
|
@@ -373,10 +373,14 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
373
373
|
};
|
374
374
|
}
|
375
375
|
async function convertReferralFeesToDestination(umi, referralState, tokenAccount) {
|
376
|
+
const tokenAccountData = await (0, accountUtils_1.getTokenAccountData)(umi, tokenAccount);
|
377
|
+
if (!tokenAccountData || tokenAccountData.amount === BigInt(0)) {
|
378
|
+
return undefined;
|
379
|
+
}
|
376
380
|
const { lookupTableAddresses, setupInstructions, swapIx } = await (0, jupiterUtils_1.getJupSwapTransaction)(umi.identity, {
|
377
|
-
amount:
|
381
|
+
amount: tokenAccountData.amount,
|
378
382
|
destinationWallet: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(referralState.publicKey),
|
379
|
-
inputMint:
|
383
|
+
inputMint: tokenAccountData.mint,
|
380
384
|
outputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(referralState.destFeesMint),
|
381
385
|
exactIn: true,
|
382
386
|
slippageBpsIncFactor: 0.15,
|
@@ -385,10 +389,10 @@ async function convertReferralFeesToDestination(umi, referralState, tokenAccount
|
|
385
389
|
.add(setupInstructions)
|
386
390
|
.add((0, generated_1.convertReferralFees)(umi, {
|
387
391
|
signer: umi.identity,
|
388
|
-
intermediaryTa: (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(umi.identity.publicKey),
|
392
|
+
intermediaryTa: (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(umi.identity.publicKey), tokenAccountData.mint)),
|
389
393
|
ixsSysvar: (0, umi_1.publicKey)(web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY),
|
390
394
|
referralState: referralState.publicKey,
|
391
|
-
referralFeesTa: (0, umi_1.publicKey)(tokenAccount
|
395
|
+
referralFeesTa: (0, umi_1.publicKey)(tokenAccount),
|
392
396
|
}))
|
393
397
|
.add(swapIx);
|
394
398
|
return [tx, lookupTableAddresses];
|
@@ -1,8 +1,10 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
+
import { Umi } from "@metaplex-foundation/umi";
|
2
3
|
export declare function bufferFromU8(num: number): Buffer;
|
3
4
|
export declare function bufferFromU64(num: bigint): Buffer;
|
4
5
|
export declare function getTokenAccount(wallet: PublicKey, tokenMint: PublicKey): PublicKey;
|
5
6
|
export declare function getTokenAccounts(wallet: PublicKey, tokenMints: PublicKey[]): PublicKey[];
|
7
|
+
export declare function getTokenAccountData(umi: Umi, tokenAccount: PublicKey): Promise<import("@solana/spl-token").RawAccount | undefined>;
|
6
8
|
export declare function getSolautoPositionAccount(signer: PublicKey, positionId: number): PublicKey;
|
7
9
|
export declare function getReferralState(authority: PublicKey): PublicKey;
|
8
10
|
export declare function getMarginfiAccountPDA(solautoPositionAccount: PublicKey, marginfiAccountSeedIdx: bigint): Promise<PublicKey>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"accountUtils.d.ts","sourceRoot":"","sources":["../../src/utils/accountUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"accountUtils.d.ts","sourceRoot":"","sources":["../../src/utils/accountUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIjD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,CAMlF;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAExF;AAED,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,+DAO1E;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,MAAM,aAQnB;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,aAUpD;AAED,wBAAsB,qBAAqB,CACzC,sBAAsB,EAAE,SAAS,EACjC,sBAAsB,EAAE,MAAM,sBAa/B"}
|
@@ -4,12 +4,14 @@ exports.bufferFromU8 = bufferFromU8;
|
|
4
4
|
exports.bufferFromU64 = bufferFromU64;
|
5
5
|
exports.getTokenAccount = getTokenAccount;
|
6
6
|
exports.getTokenAccounts = getTokenAccounts;
|
7
|
+
exports.getTokenAccountData = getTokenAccountData;
|
7
8
|
exports.getSolautoPositionAccount = getSolautoPositionAccount;
|
8
9
|
exports.getReferralState = getReferralState;
|
9
10
|
exports.getMarginfiAccountPDA = getMarginfiAccountPDA;
|
10
11
|
const web3_js_1 = require("@solana/web3.js");
|
11
12
|
const spl_token_1 = require("@solana/spl-token");
|
12
13
|
const generated_1 = require("../generated");
|
14
|
+
const umi_1 = require("@metaplex-foundation/umi");
|
13
15
|
function bufferFromU8(num) {
|
14
16
|
const buffer = Buffer.alloc(1);
|
15
17
|
buffer.writeUInt8(num);
|
@@ -26,6 +28,15 @@ function getTokenAccount(wallet, tokenMint) {
|
|
26
28
|
function getTokenAccounts(wallet, tokenMints) {
|
27
29
|
return tokenMints.map(x => getTokenAccount(wallet, x));
|
28
30
|
}
|
31
|
+
async function getTokenAccountData(umi, tokenAccount) {
|
32
|
+
const resp = await umi.rpc.getAccount((0, umi_1.publicKey)(tokenAccount));
|
33
|
+
if (resp.exists) {
|
34
|
+
return spl_token_1.AccountLayout.decode(resp.data);
|
35
|
+
}
|
36
|
+
else {
|
37
|
+
return undefined;
|
38
|
+
}
|
39
|
+
}
|
29
40
|
function getSolautoPositionAccount(signer, positionId) {
|
30
41
|
const [positionAccount, _] = web3_js_1.PublicKey.findProgramAddressSync([bufferFromU8(positionId), signer.toBuffer()], new web3_js_1.PublicKey(generated_1.SOLAUTO_PROGRAM_ID));
|
31
42
|
return positionAccount;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../src/utils/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAK3E,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAsB,uBAAuB,CAC3C,GAAG,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OAAO,CAU1E;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA+C1E;AAED,MAAM,MAAM,aAAa,GAAG,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,KAAK,CAAC,CAAC;AAEjE,wBAAgB,2BAA2B,CAAC,CAAC,EAC3C,EAAE,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EACtC,OAAO,GAAE,MAAU,EACnB,KAAK,GAAE,MAAY,EACnB,aAAa,CAAC,EAAE,aAAa,GAC5B,OAAO,CAAC,CAAC,CAAC,CAgCZ"}
|
@@ -92,7 +92,9 @@ function retryWithExponentialBackoff(fn, retries = 5, delay = 150, errorsToThrow
|
|
92
92
|
return;
|
93
93
|
}
|
94
94
|
if (attemptNum < retries) {
|
95
|
-
console.log(error);
|
95
|
+
console.log(error.name);
|
96
|
+
console.log(error.message);
|
97
|
+
console.log(error.stack);
|
96
98
|
setTimeout(() => {
|
97
99
|
console.log("Retrying...");
|
98
100
|
return attempt(attemptNum);
|
package/package.json
CHANGED
@@ -262,7 +262,6 @@ export abstract class SolautoClient extends TxHandler {
|
|
262
262
|
}
|
263
263
|
|
264
264
|
async fetchExistingAuthorityLutAccounts(): Promise<PublicKey[]> {
|
265
|
-
console.log("Fetching lut accounts", this.authorityLutAddress?.toString());
|
266
265
|
const lookupTable = this.authorityLutAddress
|
267
266
|
? await this.connection.getAddressLookupTable(this.authorityLutAddress)
|
268
267
|
: null;
|
@@ -276,9 +275,7 @@ export abstract class SolautoClient extends TxHandler {
|
|
276
275
|
async updateLookupTable(): Promise<
|
277
276
|
{ updateLutTx: TransactionBuilder; needsToBeIsolated: boolean } | undefined
|
278
277
|
> {
|
279
|
-
console.log("Getting existing accoutns");
|
280
278
|
const existingLutAccounts = await this.fetchExistingAuthorityLutAccounts();
|
281
|
-
console.log("existing accoutns", existingLutAccounts.length);
|
282
279
|
if (
|
283
280
|
this.lutAccountsToAdd().every((element) =>
|
284
281
|
existingLutAccounts
|
@@ -291,7 +288,6 @@ export abstract class SolautoClient extends TxHandler {
|
|
291
288
|
|
292
289
|
let tx = transactionBuilder();
|
293
290
|
|
294
|
-
console.log("lut address", this.authorityLutAddress?.toString());
|
295
291
|
if (this.authorityLutAddress === undefined) {
|
296
292
|
const [createLookupTableInst, lookupTableAddress] =
|
297
293
|
AddressLookupTableProgram.createLookupTable({
|
@@ -299,7 +295,6 @@ export abstract class SolautoClient extends TxHandler {
|
|
299
295
|
payer: toWeb3JsPublicKey(this.signer.publicKey),
|
300
296
|
recentSlot: await this.umi.rpc.getSlot({ commitment: "finalized" }),
|
301
297
|
});
|
302
|
-
console.log("new luit", lookupTableAddress.toString());
|
303
298
|
this.authorityLutAddress = lookupTableAddress;
|
304
299
|
tx = tx.add(getWrappedInstruction(this.signer, createLookupTableInst));
|
305
300
|
}
|
@@ -310,8 +305,6 @@ export abstract class SolautoClient extends TxHandler {
|
|
310
305
|
.map((x) => x.toString().toLowerCase())
|
311
306
|
.includes(x.toString().toLowerCase())
|
312
307
|
);
|
313
|
-
console.log("add accounts", accountsToAdd.length);
|
314
|
-
|
315
308
|
if (accountsToAdd.length > 0) {
|
316
309
|
tx = tx.add(
|
317
310
|
getWrappedInstruction(
|
@@ -325,7 +318,6 @@ export abstract class SolautoClient extends TxHandler {
|
|
325
318
|
)
|
326
319
|
);
|
327
320
|
}
|
328
|
-
console.log("Hello");
|
329
321
|
|
330
322
|
const addingReferredBy =
|
331
323
|
accountsToAdd.length === 1 &&
|
@@ -335,7 +327,6 @@ export abstract class SolautoClient extends TxHandler {
|
|
335
327
|
if (tx.getInstructions().length > 0) {
|
336
328
|
this.log("Updating authority lookup table...");
|
337
329
|
}
|
338
|
-
console.log("instructions", tx.getInstructions().length);
|
339
330
|
|
340
331
|
return { updateLutTx: tx, needsToBeIsolated: !addingReferredBy };
|
341
332
|
}
|
@@ -48,7 +48,7 @@ import {
|
|
48
48
|
uint8ArrayToBigInt,
|
49
49
|
} from "../utils/numberUtils";
|
50
50
|
import { eligibleForRebalance } from "../utils/solauto/generalUtils";
|
51
|
-
import { getTokenAccount } from "../utils/accountUtils";
|
51
|
+
import { getTokenAccount, getTokenAccountData } from "../utils/accountUtils";
|
52
52
|
import {
|
53
53
|
getLendingAccountBorrowInstructionDataSerializer,
|
54
54
|
getLendingAccountDepositInstructionDataSerializer,
|
@@ -684,13 +684,18 @@ export async function buildSolautoRebalanceTransaction(
|
|
684
684
|
export async function convertReferralFeesToDestination(
|
685
685
|
umi: Umi,
|
686
686
|
referralState: ReferralState,
|
687
|
-
tokenAccount:
|
687
|
+
tokenAccount: PublicKey
|
688
688
|
): Promise<[TransactionBuilder, string[]] | undefined> {
|
689
|
+
const tokenAccountData = await getTokenAccountData(umi, tokenAccount);
|
690
|
+
if (!tokenAccountData || tokenAccountData.amount === BigInt(0)) {
|
691
|
+
return undefined;
|
692
|
+
}
|
693
|
+
|
689
694
|
const { lookupTableAddresses, setupInstructions, swapIx } =
|
690
695
|
await getJupSwapTransaction(umi.identity, {
|
691
|
-
amount:
|
696
|
+
amount: tokenAccountData.amount,
|
692
697
|
destinationWallet: toWeb3JsPublicKey(referralState.publicKey),
|
693
|
-
inputMint:
|
698
|
+
inputMint: tokenAccountData.mint,
|
694
699
|
outputMint: toWeb3JsPublicKey(referralState.destFeesMint),
|
695
700
|
exactIn: true,
|
696
701
|
slippageBpsIncFactor: 0.15,
|
@@ -704,12 +709,12 @@ export async function convertReferralFeesToDestination(
|
|
704
709
|
intermediaryTa: publicKey(
|
705
710
|
getTokenAccount(
|
706
711
|
toWeb3JsPublicKey(umi.identity.publicKey),
|
707
|
-
|
712
|
+
tokenAccountData.mint
|
708
713
|
)
|
709
714
|
),
|
710
715
|
ixsSysvar: publicKey(SYSVAR_INSTRUCTIONS_PUBKEY),
|
711
716
|
referralState: referralState.publicKey,
|
712
|
-
referralFeesTa: publicKey(tokenAccount
|
717
|
+
referralFeesTa: publicKey(tokenAccount),
|
713
718
|
})
|
714
719
|
)
|
715
720
|
.add(swapIx);
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
2
|
+
import { AccountLayout as SplTokenAccountLayout, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
3
3
|
import { SOLAUTO_PROGRAM_ID } from "../generated";
|
4
|
+
import { publicKey, Umi } from "@metaplex-foundation/umi";
|
4
5
|
|
5
6
|
export function bufferFromU8(num: number): Buffer {
|
6
7
|
const buffer = Buffer.alloc(1);
|
@@ -26,6 +27,15 @@ export function getTokenAccounts(wallet: PublicKey, tokenMints: PublicKey[]): Pu
|
|
26
27
|
return tokenMints.map(x => getTokenAccount(wallet, x));
|
27
28
|
}
|
28
29
|
|
30
|
+
export async function getTokenAccountData(umi: Umi, tokenAccount: PublicKey) {
|
31
|
+
const resp = await umi.rpc.getAccount(publicKey(tokenAccount));
|
32
|
+
if (resp.exists) {
|
33
|
+
return SplTokenAccountLayout.decode(resp.data);
|
34
|
+
} else {
|
35
|
+
return undefined;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
29
39
|
export function getSolautoPositionAccount(
|
30
40
|
signer: PublicKey,
|
31
41
|
positionId: number
|
@@ -118,7 +118,9 @@ export function retryWithExponentialBackoff<T>(
|
|
118
118
|
}
|
119
119
|
|
120
120
|
if (attemptNum < retries) {
|
121
|
-
console.log(error);
|
121
|
+
console.log(error.name);
|
122
|
+
console.log(error.message);
|
123
|
+
console.log(error.stack);
|
122
124
|
setTimeout(() => {
|
123
125
|
console.log("Retrying...");
|
124
126
|
return attempt(attemptNum);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { describe, it } from "mocha";
|
2
|
-
import { none, some } from "@metaplex-foundation/umi";
|
2
|
+
import { none, publicKey, some } from "@metaplex-foundation/umi";
|
3
3
|
import { setupTest } from "../shared";
|
4
4
|
import {
|
5
5
|
SolautoMarginfiClient,
|
@@ -154,11 +154,11 @@ describe("Solauto Marginfi tests", async () => {
|
|
154
154
|
// )
|
155
155
|
// );
|
156
156
|
|
157
|
-
await new TransactionsManager(
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
).clientSend(transactionItems);
|
157
|
+
// await new TransactionsManager(
|
158
|
+
// client,
|
159
|
+
// undefined,
|
160
|
+
// !payForTransactions,
|
161
|
+
// useJitoBundle
|
162
|
+
// ).clientSend(transactionItems);
|
163
163
|
});
|
164
164
|
});
|