@haven-fi/solauto-sdk 1.0.38 → 1.0.40
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/solautoClient.d.ts +1 -1
- package/dist/clients/solautoClient.d.ts.map +1 -1
- package/dist/clients/solautoClient.js +3 -3
- package/dist/clients/solautoMarginfiClient.d.ts +1 -1
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -1
- package/dist/clients/solautoMarginfiClient.js +25 -9
- package/dist/generated/instructions/marginfiRebalance.d.ts +1 -1
- package/dist/generated/instructions/marginfiRebalance.d.ts.map +1 -1
- package/dist/generated/instructions/marginfiRebalance.js +2 -2
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +15 -13
- package/dist/transactions/transactionsManager.d.ts +22 -1
- package/dist/transactions/transactionsManager.d.ts.map +1 -1
- package/dist/transactions/transactionsManager.js +33 -3
- package/dist/types/solauto.d.ts +2 -0
- package/dist/types/solauto.d.ts.map +1 -1
- package/dist/utils/generalUtils.d.ts.map +1 -1
- package/dist/utils/generalUtils.js +1 -1
- package/dist/utils/jupiterUtils.d.ts +1 -1
- package/dist/utils/jupiterUtils.d.ts.map +1 -1
- package/dist/utils/jupiterUtils.js +6 -4
- package/dist/utils/solauto/generalUtils.d.ts +1 -6
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -1
- package/dist/utils/solauto/generalUtils.js +4 -0
- package/local/shared.ts +7 -6
- package/package.json +1 -1
- package/src/clients/solautoClient.ts +6 -4
- package/src/clients/solautoMarginfiClient.ts +31 -19
- package/src/generated/instructions/marginfiRebalance.ts +3 -3
- package/src/transactions/transactionUtils.ts +37 -18
- package/src/transactions/transactionsManager.ts +50 -5
- package/src/types/solauto.ts +7 -5
- package/src/utils/generalUtils.ts +2 -1
- package/src/utils/jupiterUtils.ts +19 -13
- package/src/utils/solauto/generalUtils.ts +5 -8
- package/tests/transactions/solautoMarginfi.ts +6 -6
@@ -69,7 +69,7 @@ export declare abstract class SolautoClient {
|
|
69
69
|
protocolInteraction(args: SolautoActionArgs): TransactionBuilder;
|
70
70
|
abstract flashBorrow(flashLoanDetails: FlashLoanDetails, destinationTokenAccount: PublicKey): TransactionBuilder;
|
71
71
|
abstract flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder;
|
72
|
-
abstract rebalance(rebalanceStep: "A" | "B", swapDetails: JupSwapDetails, rebalanceType: SolautoRebalanceTypeArgs, targetLiqUtilizationRateBps?: number, limitGapBps?: number): TransactionBuilder;
|
72
|
+
abstract rebalance(rebalanceStep: "A" | "B", swapDetails: JupSwapDetails, rebalanceType: SolautoRebalanceTypeArgs, flashLoan?: FlashLoanDetails, targetLiqUtilizationRateBps?: number, limitGapBps?: number): TransactionBuilder;
|
73
73
|
getFreshPositionState(): Promise<PositionState | undefined>;
|
74
74
|
}
|
75
75
|
//# 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,EAEL,UAAU,EACV,SAAS,EACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAQJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EAEd,MAAM,iDAAiD,CAAC;AACzD,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,wBAAwB,EACxB,yBAAyB,EACzB,gCAAgC,EAChC,sBAAsB,EASvB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAMvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAInE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEpE,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,SAA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MAAM,GACnB,kBAAkB;IAEf,qBAAqB,IAAI,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;CAYlE"}
|
@@ -172,9 +172,9 @@ class SolautoClient {
|
|
172
172
|
addresses: accountsToAdd,
|
173
173
|
})));
|
174
174
|
}
|
175
|
-
const addingReferredBy = accountsToAdd.length === 1
|
176
|
-
|
177
|
-
|
175
|
+
const addingReferredBy = accountsToAdd.length === 1 &&
|
176
|
+
accountsToAdd[0].toString().toLowerCase() ===
|
177
|
+
this.referredBySupplyTa?.toString().toLowerCase();
|
178
178
|
if (tx.getInstructions().length > 0) {
|
179
179
|
this.log("Updating authority lookup table...");
|
180
180
|
}
|
@@ -34,7 +34,7 @@ export declare class SolautoMarginfiClient extends SolautoClient {
|
|
34
34
|
protocolInteraction(args: SolautoActionArgs): TransactionBuilder;
|
35
35
|
private marginfiProtocolInteractionIx;
|
36
36
|
private marginfiSolautoProtocolInteractionIx;
|
37
|
-
rebalance(rebalanceStep: "A" | "B", swapDetails: JupSwapDetails, rebalanceType: SolautoRebalanceTypeArgs, targetLiqUtilizationRateBps?: number, limitGapBps?: number): TransactionBuilder;
|
37
|
+
rebalance(rebalanceStep: "A" | "B", swapDetails: JupSwapDetails, rebalanceType: SolautoRebalanceTypeArgs, flashLoan?: FlashLoanDetails, targetLiqUtilizationRateBps?: number, limitGapBps?: number): TransactionBuilder;
|
38
38
|
flashBorrow(flashLoanDetails: FlashLoanDetails, destinationTokenAccount: PublicKey): TransactionBuilder;
|
39
39
|
flashRepay(flashLoanDetails: FlashLoanDetails): TransactionBuilder;
|
40
40
|
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,
|
1
|
+
{"version":3,"file":"sol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AmB,IAAI,MAAM,EAAE;IAI/B,gBAAgB,IAAI,SAAS,EAAE;IAQ/B,yBAAyB,IAAI,kBAAkB;IAS/C,YAAY,CACV,aAAa,CAAC,EAAE,gCAAgC,EAChD,GAAG,CAAC,EAAE,kBAAkB,GACvB,kBAAkB;IAMrB,OAAO,CAAC,sBAAsB;IA6C9B,OAAO,IAAI,kBAAkB;IAc7B,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,kBAAkB;IAUhE,OAAO,CAAC,6BAA6B;IAmErC,OAAO,CAAC,oCAAoC;IA8D5C,SAAS,CACP,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;IA4DrB,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"}
|
@@ -125,7 +125,9 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
125
125
|
settingParams: settingParams ?? null,
|
126
126
|
dca: dca ?? null,
|
127
127
|
},
|
128
|
-
marginfiAccountSeedIdx: !this.selfManaged
|
128
|
+
marginfiAccountSeedIdx: !this.selfManaged
|
129
|
+
? this.marginfiAccountSeedIdx
|
130
|
+
: null,
|
129
131
|
});
|
130
132
|
}
|
131
133
|
refresh() {
|
@@ -248,15 +250,21 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
248
250
|
solautoAction: args,
|
249
251
|
});
|
250
252
|
}
|
251
|
-
rebalance(rebalanceStep, swapDetails, rebalanceType, targetLiqUtilizationRateBps, limitGapBps) {
|
253
|
+
rebalance(rebalanceStep, swapDetails, rebalanceType, flashLoan, targetLiqUtilizationRateBps, limitGapBps) {
|
254
|
+
const inputIsSupply = swapDetails.inputMint.equals(this.supplyMint);
|
255
|
+
const outputIsSupply = swapDetails.outputMint.equals(this.supplyMint);
|
256
|
+
const needSupplyAccounts = (inputIsSupply && rebalanceStep === "A") ||
|
257
|
+
(outputIsSupply && rebalanceStep === "B") ||
|
258
|
+
(inputIsSupply && flashLoan !== undefined && rebalanceStep == "B");
|
259
|
+
const needDebtAccounts = (!inputIsSupply && rebalanceStep === "A") ||
|
260
|
+
(!outputIsSupply && rebalanceStep === "B") ||
|
261
|
+
(!inputIsSupply && flashLoan !== undefined && rebalanceStep == "B");
|
252
262
|
return (0, generated_1.marginfiRebalance)(this.umi, {
|
253
263
|
signer: this.signer,
|
254
264
|
marginfiProgram: (0, umi_1.publicKey)(marginfi_sdk_1.MARGINFI_PROGRAM_ID),
|
255
265
|
ixsSysvar: (0, umi_1.publicKey)(web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY),
|
256
266
|
solautoFeesSupplyTa: rebalanceStep === "B" ? (0, umi_1.publicKey)(this.solautoFeesSupplyTa) : undefined,
|
257
|
-
authorityReferralState:
|
258
|
-
? (0, umi_1.publicKey)(this.authorityReferralState)
|
259
|
-
: undefined,
|
267
|
+
authorityReferralState: (0, umi_1.publicKey)(this.authorityReferralState),
|
260
268
|
referredBySupplyTa: rebalanceStep === "B" && this.referredBySupplyTa
|
261
269
|
? (0, umi_1.publicKey)(this.referredBySupplyTa)
|
262
270
|
: undefined,
|
@@ -270,14 +278,22 @@ class SolautoMarginfiClient extends solautoClient_1.SolautoClient {
|
|
270
278
|
signerSupplyTa: this.selfManaged
|
271
279
|
? (0, umi_1.publicKey)(this.signerSupplyTa)
|
272
280
|
: undefined,
|
273
|
-
vaultSupplyTa:
|
274
|
-
|
281
|
+
vaultSupplyTa: needSupplyAccounts
|
282
|
+
? (0, umi_1.publicKey)(this.marginfiSupplyBankAccounts.liquidityVault)
|
283
|
+
: undefined,
|
284
|
+
supplyVaultAuthority: needSupplyAccounts
|
285
|
+
? (0, umi_1.publicKey)(this.marginfiSupplyBankAccounts.vaultAuthority)
|
286
|
+
: undefined,
|
275
287
|
debtBank: (0, umi_1.publicKey)(this.marginfiDebtBankAccounts.bank),
|
276
288
|
debtPriceOracle: (0, umi_1.publicKey)(this.marginfiDebtBankAccounts.priceOracle),
|
277
289
|
positionDebtTa: (0, umi_1.publicKey)(this.positionDebtTa),
|
278
290
|
signerDebtTa: this.selfManaged ? (0, umi_1.publicKey)(this.signerDebtTa) : undefined,
|
279
|
-
vaultDebtTa:
|
280
|
-
|
291
|
+
vaultDebtTa: needDebtAccounts
|
292
|
+
? (0, umi_1.publicKey)(this.marginfiDebtBankAccounts.liquidityVault)
|
293
|
+
: undefined,
|
294
|
+
debtVaultAuthority: needDebtAccounts
|
295
|
+
? (0, umi_1.publicKey)(this.marginfiDebtBankAccounts.vaultAuthority)
|
296
|
+
: undefined,
|
281
297
|
rebalanceType,
|
282
298
|
targetLiqUtilizationRateBps: targetLiqUtilizationRateBps ?? null,
|
283
299
|
limitGapBps: limitGapBps ?? null,
|
@@ -15,7 +15,7 @@ export type MarginfiRebalanceInstructionAccounts = {
|
|
15
15
|
tokenProgram?: PublicKey | Pda;
|
16
16
|
ixsSysvar: PublicKey | Pda;
|
17
17
|
solautoFeesSupplyTa?: PublicKey | Pda;
|
18
|
-
authorityReferralState
|
18
|
+
authorityReferralState: PublicKey | Pda;
|
19
19
|
referredBySupplyTa?: PublicKey | Pda;
|
20
20
|
solautoPosition: PublicKey | Pda;
|
21
21
|
marginfiGroup: PublicKey | Pda;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiRebalance.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/marginfiRebalance.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,GAAG,EACH,SAAS,EACT,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,UAAU,EAMX,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EAEzB,MAAM,UAAU,CAAC;AAGlB,MAAM,MAAM,oCAAoC,GAAG;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,SAAS,GAAG,GAAG,CAAC;IACjC,aAAa,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAChC,YAAY,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAC/B,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC;IAC3B,mBAAmB,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACtC,sBAAsB,
|
1
|
+
{"version":3,"file":"marginfiRebalance.d.ts","sourceRoot":"","sources":["../../../src/generated/instructions/marginfiRebalance.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,GAAG,EACH,SAAS,EACT,MAAM,EACN,kBAAkB,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,UAAU,EAMX,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EAEzB,MAAM,UAAU,CAAC;AAGlB,MAAM,MAAM,oCAAoC,GAAG;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,SAAS,GAAG,GAAG,CAAC;IACjC,aAAa,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAChC,YAAY,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IAC/B,SAAS,EAAE,SAAS,GAAG,GAAG,CAAC;IAC3B,mBAAmB,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;IACtC,sBAAsB,EAAE,SAAS,GAAG,GAAG,CAAC;IACxC,kBAAkB,CAAC,EAAE,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C,CACjC,CAoBA;AAGD,MAAM,MAAM,gCAAgC,GAC1C,oCAAoC,CAAC;AAGvC,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,EAClC,KAAK,EAAE,oCAAoC,GAAG,gCAAgC,GAC7E,kBAAkB,CA6KpB"}
|
@@ -114,7 +114,7 @@ function marginfiRebalance(context, input) {
|
|
114
114
|
},
|
115
115
|
supplyVaultAuthority: {
|
116
116
|
index: 17,
|
117
|
-
isWritable:
|
117
|
+
isWritable: false,
|
118
118
|
value: input.supplyVaultAuthority ?? null,
|
119
119
|
},
|
120
120
|
debtBank: {
|
@@ -144,7 +144,7 @@ function marginfiRebalance(context, input) {
|
|
144
144
|
},
|
145
145
|
debtVaultAuthority: {
|
146
146
|
index: 23,
|
147
|
-
isWritable:
|
147
|
+
isWritable: false,
|
148
148
|
value: input.debtVaultAuthority ?? null,
|
149
149
|
},
|
150
150
|
};
|
@@ -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;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,
|
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;AAGlC,OAAO,EAGL,OAAO,IAAI,eAAe,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAqMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAgH7B;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,CACN;IACE,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACD,SAAS,CACZ,CAgHA;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"}
|
@@ -115,8 +115,7 @@ async function rebalanceChoresBefore(client, tx, accountsGettingCreated) {
|
|
115
115
|
if (rebalanceInstructions.length === 0) {
|
116
116
|
return (0, umi_1.transactionBuilder)();
|
117
117
|
}
|
118
|
-
const usesAccount = (key) => rebalanceInstructions
|
119
|
-
.some((t) => t.keys.some((k) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(k.pubkey).equals(key)));
|
118
|
+
const usesAccount = (key) => rebalanceInstructions.some((t) => t.keys.some((k) => (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(k.pubkey).equals(key)));
|
120
119
|
const checkReferralSupplyTa = client.referredBySupplyTa && usesAccount(client.referredBySupplyTa);
|
121
120
|
const checkSolautoFeesTa = usesAccount(client.solautoFeesSupplyTa);
|
122
121
|
const checkIntermediaryMfiAccount = client.lendingPlatform === generated_1.LendingPlatform.Marginfi &&
|
@@ -134,7 +133,7 @@ async function rebalanceChoresBefore(client, tx, accountsGettingCreated) {
|
|
134
133
|
...[checkSignerSupplyTa ? client.signerSupplyTa : web3_js_1.PublicKey.default],
|
135
134
|
...[checkSignerDebtTa ? client.signerDebtTa : web3_js_1.PublicKey.default],
|
136
135
|
];
|
137
|
-
const [referredBySupplyTa, solautoFeesSupplyTa, intermediaryMarginfiAccount, signerSupplyTa, signerDebtTa] = await client.umi.rpc.getAccounts(accountsNeeded.map((x) => (0, umi_1.publicKey)(x ?? web3_js_1.PublicKey.default)));
|
136
|
+
const [referredBySupplyTa, solautoFeesSupplyTa, intermediaryMarginfiAccount, signerSupplyTa, signerDebtTa,] = await client.umi.rpc.getAccounts(accountsNeeded.map((x) => (0, umi_1.publicKey)(x ?? web3_js_1.PublicKey.default)));
|
138
137
|
let chores = (0, umi_1.transactionBuilder)();
|
139
138
|
if (checkReferralSupplyTa && !(0, generalUtils_1.rpcAccountCreated)(referredBySupplyTa)) {
|
140
139
|
client.log("Creating referred-by TA for ", client.supplyMint.toString());
|
@@ -148,12 +147,16 @@ async function rebalanceChoresBefore(client, tx, accountsGettingCreated) {
|
|
148
147
|
!(0, generalUtils_1.rpcAccountCreated)(intermediaryMarginfiAccount)) {
|
149
148
|
chores = chores.add(client.createIntermediaryMarginfiAccount());
|
150
149
|
}
|
151
|
-
if (checkSignerSupplyTa &&
|
150
|
+
if (checkSignerSupplyTa &&
|
151
|
+
!(0, generalUtils_1.rpcAccountCreated)(signerSupplyTa) &&
|
152
|
+
!accountsGettingCreated.includes(signerSupplyTa.publicKey.toString())) {
|
152
153
|
client.log("Creating signer supply token account");
|
153
154
|
chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), client.supplyMint));
|
154
155
|
accountsGettingCreated.push(signerSupplyTa.publicKey.toString());
|
155
156
|
}
|
156
|
-
if (checkSignerDebtTa &&
|
157
|
+
if (checkSignerDebtTa &&
|
158
|
+
!(0, generalUtils_1.rpcAccountCreated)(signerDebtTa) &&
|
159
|
+
!accountsGettingCreated.includes(signerDebtTa.publicKey.toString())) {
|
157
160
|
client.log("Creating signer debt token account");
|
158
161
|
chores = chores.add((0, solanaUtils_1.createAssociatedTokenAccountUmiIx)(client.signer, (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), client.debtMint));
|
159
162
|
accountsGettingCreated.push(signerDebtTa.publicKey.toString());
|
@@ -177,7 +180,7 @@ function getRebalanceInstructions(tx) {
|
|
177
180
|
const discriminator = serializer.serialize({
|
178
181
|
limitGapBps: 0,
|
179
182
|
rebalanceType: generated_1.SolautoRebalanceType.None,
|
180
|
-
targetLiqUtilizationRateBps: 0
|
183
|
+
targetLiqUtilizationRateBps: 0,
|
181
184
|
})[0];
|
182
185
|
const [data, _] = serializer.deserialize(x.data);
|
183
186
|
if (data.discriminator === discriminator) {
|
@@ -195,8 +198,7 @@ function getSolautoActions(tx) {
|
|
195
198
|
if (x.programId === generated_1.SOLAUTO_PROGRAM_ID) {
|
196
199
|
try {
|
197
200
|
const serializer = (0, generated_1.getMarginfiProtocolInteractionInstructionDataSerializer)();
|
198
|
-
const discriminator = serializer
|
199
|
-
.serialize({
|
201
|
+
const discriminator = serializer.serialize({
|
200
202
|
solautoAction: (0, generated_1.solautoAction)("Deposit", [BigInt(0)]),
|
201
203
|
})[0];
|
202
204
|
const [data, _] = serializer.deserialize(x.data);
|
@@ -328,7 +330,7 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
328
330
|
const values = (0, rebalanceUtils_1.getRebalanceValues)(client, targetLiqUtilizationRateBps);
|
329
331
|
client.log("Rebalance values: ", values);
|
330
332
|
const swapDetails = (0, rebalanceUtils_1.getJupSwapRebalanceDetails)(client, values, targetLiqUtilizationRateBps, attemptNum);
|
331
|
-
const { jupQuote, lookupTableAddresses, setupInstructions, tokenLedgerIx, swapIx, } = await (0, jupiterUtils_1.getJupSwapTransaction)(client.signer, swapDetails);
|
333
|
+
const { jupQuote, lookupTableAddresses, setupInstructions, tokenLedgerIx, swapIx, } = await (0, jupiterUtils_1.getJupSwapTransaction)(client.signer, swapDetails, attemptNum);
|
332
334
|
const flashLoan = (0, rebalanceUtils_1.getFlashLoanDetails)(client, values, jupQuote);
|
333
335
|
let tx = (0, umi_1.transactionBuilder)();
|
334
336
|
if (flashLoan) {
|
@@ -343,11 +345,11 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
343
345
|
client.flashBorrow(flashLoan, (0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(client.signer.publicKey), swapDetails.inputMint)),
|
344
346
|
...(addFirstRebalance
|
345
347
|
? [
|
346
|
-
client.rebalance("A", swapDetails, rebalanceType, targetLiqUtilizationRateBps),
|
348
|
+
client.rebalance("A", swapDetails, rebalanceType, flashLoan, targetLiqUtilizationRateBps),
|
347
349
|
]
|
348
350
|
: []),
|
349
351
|
swapIx,
|
350
|
-
client.rebalance("B", swapDetails, rebalanceType, targetLiqUtilizationRateBps),
|
352
|
+
client.rebalance("B", swapDetails, rebalanceType, flashLoan, targetLiqUtilizationRateBps),
|
351
353
|
client.flashRepay(flashLoan),
|
352
354
|
]);
|
353
355
|
}
|
@@ -356,9 +358,9 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
356
358
|
tx = tx.add([
|
357
359
|
setupInstructions,
|
358
360
|
tokenLedgerIx,
|
359
|
-
client.rebalance("A", swapDetails, rebalanceType, targetLiqUtilizationRateBps),
|
361
|
+
client.rebalance("A", swapDetails, rebalanceType, undefined, targetLiqUtilizationRateBps),
|
360
362
|
swapIx,
|
361
|
-
client.rebalance("B", swapDetails, rebalanceType, targetLiqUtilizationRateBps),
|
363
|
+
client.rebalance("B", swapDetails, rebalanceType, undefined, targetLiqUtilizationRateBps),
|
362
364
|
]);
|
363
365
|
}
|
364
366
|
if (client.solautoPositionState.liqUtilizationRateBps >
|
@@ -1,6 +1,13 @@
|
|
1
|
-
import { TransactionBuilder } from "@metaplex-foundation/umi";
|
1
|
+
import { AddressLookupTableInput, TransactionBuilder } from "@metaplex-foundation/umi";
|
2
2
|
import { SolautoClient } from "../clients/solautoClient";
|
3
3
|
import { ErrorsToThrow } from "../utils/generalUtils";
|
4
|
+
declare class LookupTables {
|
5
|
+
private client;
|
6
|
+
defaultLuts: string[];
|
7
|
+
cache: AddressLookupTableInput[];
|
8
|
+
constructor(client: SolautoClient);
|
9
|
+
getLutInputs(additionalAddresses: string[]): Promise<AddressLookupTableInput[]>;
|
10
|
+
}
|
4
11
|
export declare class TransactionItem {
|
5
12
|
fetchTx: (attemptNum: number) => Promise<{
|
6
13
|
tx: TransactionBuilder;
|
@@ -17,6 +24,18 @@ export declare class TransactionItem {
|
|
17
24
|
refetch(attemptNum: number): Promise<void>;
|
18
25
|
uniqueAccounts(): string[];
|
19
26
|
}
|
27
|
+
declare class TransactionSet {
|
28
|
+
private client;
|
29
|
+
lookupTables: LookupTables;
|
30
|
+
items: TransactionItem[];
|
31
|
+
constructor(client: SolautoClient, lookupTables: LookupTables, items?: TransactionItem[]);
|
32
|
+
fitsWith(item: TransactionItem): Promise<boolean>;
|
33
|
+
add(...items: TransactionItem[]): void;
|
34
|
+
refetchAll(attemptNum: number): Promise<void>;
|
35
|
+
getSingleTransaction(): Promise<TransactionBuilder>;
|
36
|
+
lutAddresses(): string[];
|
37
|
+
name(): string;
|
38
|
+
}
|
20
39
|
export declare enum TransactionStatus {
|
21
40
|
Skipped = "Skipped",
|
22
41
|
Processing = "Processing",
|
@@ -40,6 +59,8 @@ export declare class TransactionsManager {
|
|
40
59
|
constructor(client: SolautoClient, items: TransactionItem[], statusCallback?: ((statuses: TransactionManagerStatuses) => void) | undefined, simulateOnly?: boolean | undefined, mustBeAtomic?: boolean | undefined, errorsToThrow?: ErrorsToThrow | undefined);
|
41
60
|
private assembleTransactionSets;
|
42
61
|
updateStatus(name: string, status: TransactionStatus, txSig?: string): void;
|
62
|
+
debugAccounts(itemSet: TransactionSet, tx: TransactionBuilder): Promise<void>;
|
43
63
|
send(): Promise<void>;
|
44
64
|
}
|
65
|
+
export {};
|
45
66
|
//# sourceMappingURL=transactionsManager.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,
|
1
|
+
{"version":3,"file":"transactionsManager.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionsManager.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EAGvB,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,OAAO,EACL,aAAa,EAEd,MAAM,uBAAuB,CAAC;AAK/B,cAAM,YAAY;IAIJ,OAAO,CAAC,MAAM;IAH1B,WAAW,EAAE,MAAM,EAAE,CAAM;IAC3B,KAAK,EAAE,uBAAuB,EAAE,CAAM;gBAElB,MAAM,EAAE,aAAa;IAInC,YAAY,CAChB,mBAAmB,EAAE,MAAM,EAAE,GAC5B,OAAO,CAAC,uBAAuB,EAAE,CAAC;CAqBtC;AAED,qBAAa,eAAe;IAKjB,OAAO,EAAE,CACd,UAAU,EAAE,MAAM,KACf,OAAO,CACV;QAAE,EAAE,EAAE,kBAAkB,CAAC;QAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,SAAS,CACxE;IACM,IAAI,CAAC;IATd,oBAAoB,EAAG,MAAM,EAAE,CAAC;IAChC,EAAE,CAAC,EAAE,kBAAkB,CAAC;gBAGf,OAAO,EAA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B,KAAK,EAAE,eAAe,EAAE,EACxB,cAAc,CAAC,6CAA4C,IAAI,aAAA,EAC/D,YAAY,CAAC,qBAAS,EACtB,YAAY,CAAC,qBAAS,EACtB,aAAa,CAAC,2BAAe;YAKzB,uBAAuB;IA0CrC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,KAAK,CAAC,EAAE,MAAM;IAiB9D,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,kBAAkB;IA6B7D,IAAI;CAyJX"}
|
@@ -29,7 +29,7 @@ class LookupTables {
|
|
29
29
|
const additionalInputs = await (0, solanaUtils_1.getAdressLookupInputs)(this.client.umi, missingAddresses);
|
30
30
|
this.cache.push(...additionalInputs);
|
31
31
|
}
|
32
|
-
return this.cache
|
32
|
+
return this.cache;
|
33
33
|
}
|
34
34
|
}
|
35
35
|
class TransactionItem {
|
@@ -141,7 +141,11 @@ class TransactionsManager {
|
|
141
141
|
}
|
142
142
|
const transaction = item.tx.setAddressLookupTables(await this.lookupTables.getLutInputs(item.lookupTableAddresses));
|
143
143
|
if (!transaction.fitsInOneTransaction(this.client.umi)) {
|
144
|
-
|
144
|
+
// TODO: revert me
|
145
|
+
// throw new Error(
|
146
|
+
// `Transaction exceeds max transaction size (${transaction.getTransactionSize(this.client.umi)})`
|
147
|
+
// );
|
148
|
+
transactionSets.push(new TransactionSet(this.client, this.lookupTables, [item]));
|
145
149
|
}
|
146
150
|
else {
|
147
151
|
let newSet = new TransactionSet(this.client, this.lookupTables, [item]);
|
@@ -176,9 +180,32 @@ class TransactionsManager {
|
|
176
180
|
this.client.log(`${name} is ${status.toString().toLowerCase()}`);
|
177
181
|
this.statusCallback?.(this.statuses);
|
178
182
|
}
|
183
|
+
// TODO remove me
|
184
|
+
async debugAccounts(itemSet, tx) {
|
185
|
+
const lutInputs = await itemSet.lookupTables.getLutInputs([]);
|
186
|
+
const lutAccounts = lutInputs.map((x) => x.addresses).flat();
|
187
|
+
const keys = tx
|
188
|
+
.getInstructions()
|
189
|
+
.map((x) => x.keys)
|
190
|
+
.flat();
|
191
|
+
for (const ix of tx.getInstructions()) {
|
192
|
+
const ixAccounts = ix.keys.map((x) => x.pubkey);
|
193
|
+
const accountsNotInLut = ixAccounts.filter((x) => !lutAccounts.includes(x));
|
194
|
+
console.log("Program", ix.programId, " data ", ix.data.length, ix.keys.filter((x) => lutAccounts.includes(x.pubkey)).length * 3);
|
195
|
+
if (accountsNotInLut.length > 0) {
|
196
|
+
console.log("Accounts not in LUT:");
|
197
|
+
for (const key of accountsNotInLut) {
|
198
|
+
console.log(key.toString());
|
199
|
+
}
|
200
|
+
console.log(ix.keys.length);
|
201
|
+
}
|
202
|
+
}
|
203
|
+
}
|
179
204
|
async send() {
|
180
205
|
const updateLookupTable = await this.client.updateLookupTable();
|
181
|
-
if (updateLookupTable &&
|
206
|
+
if (updateLookupTable &&
|
207
|
+
updateLookupTable.updateLutTx.getInstructions().length > 0 &&
|
208
|
+
updateLookupTable?.needsToBeIsolated) {
|
182
209
|
this.updateStatus("update lookup table", TransactionStatus.Processing);
|
183
210
|
await (0, generalUtils_1.retryWithExponentialBackoff)(async (attemptNum) => await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.client.umi, this.client.connection, updateLookupTable.updateLutTx, this.simulateOnly, attemptNum), 3, 150, this.errorsToThrow);
|
184
211
|
this.updateStatus("update lookup table", TransactionStatus.Successful);
|
@@ -257,6 +284,9 @@ class TransactionsManager {
|
|
257
284
|
}
|
258
285
|
else {
|
259
286
|
this.updateStatus(itemSet.name(), TransactionStatus.Processing);
|
287
|
+
if (this.client.localTest) {
|
288
|
+
await this.debugAccounts(itemSet, tx);
|
289
|
+
}
|
260
290
|
const txSig = await (0, solanaUtils_1.sendSingleOptimizedTransaction)(this.client.umi, this.client.connection, tx, this.simulateOnly, attemptNum);
|
261
291
|
this.updateStatus(itemSet.name(), TransactionStatus.Successful, txSig ? bs58_1.default.encode(txSig) : undefined);
|
262
292
|
}
|
package/dist/types/solauto.d.ts
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
2
|
import { LendingPlatform } from "../generated";
|
3
3
|
export interface SolautoPositionDetails {
|
4
|
+
publicKey: PublicKey;
|
5
|
+
authority: PublicKey;
|
4
6
|
positionId: number;
|
5
7
|
lendingPlatform: LendingPlatform;
|
6
8
|
protocolAccount?: PublicKey;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,sBAAsB;
|
1
|
+
{"version":3,"file":"solauto.d.ts","sourceRoot":"","sources":["../../src/types/solauto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,CAAC,EAAE,SAAS,CAAC;IAC5B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB"}
|
@@ -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;
|
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;AAM3E,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAO1C;AAED,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,wBAAsB,uBAAuB,CAC3C,GAAG,EAAE,GAAG,EACR,EAAE,EAAE,SAAS,GACZ,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAEnE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAU1E;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAiD1E;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,CA8BZ"}
|
@@ -94,7 +94,7 @@ function retryWithExponentialBackoff(fn, retries = 5, delay = 150, errorsToThrow
|
|
94
94
|
return;
|
95
95
|
}
|
96
96
|
if (attemptNum < retries) {
|
97
|
-
console.log(error);
|
97
|
+
console.log(error.message);
|
98
98
|
setTimeout(() => {
|
99
99
|
console.log("Retrying...");
|
100
100
|
return attempt(attemptNum);
|
@@ -17,5 +17,5 @@ export interface JupSwapTransaction {
|
|
17
17
|
tokenLedgerIx: TransactionBuilder;
|
18
18
|
swapIx: TransactionBuilder;
|
19
19
|
}
|
20
|
-
export declare function getJupSwapTransaction(signer: Signer, swapDetails: JupSwapDetails): Promise<JupSwapTransaction>;
|
20
|
+
export declare function getJupSwapTransaction(signer: Signer, swapDetails: JupSwapDetails, attemptNum?: number): Promise<JupSwapTransaction>;
|
21
21
|
//# sourceMappingURL=jupiterUtils.d.ts.map
|
@@ -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;
|
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;AAMrB,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,SAAS,CAAC;IACtB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAgBD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,aAAa,CAAC;IACxB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,iBAAiB,EAAE,kBAAkB,CAAC;IACtC,aAAa,EAAE,kBAAkB,CAAC;IAClC,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,cAAc,EAC3B,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,kBAAkB,CAAC,CAsE7B"}
|
@@ -7,6 +7,7 @@ const solanaUtils_1 = require("./solanaUtils");
|
|
7
7
|
const numberUtils_1 = require("./numberUtils");
|
8
8
|
const api_1 = require("@jup-ag/api");
|
9
9
|
const accountUtils_1 = require("./accountUtils");
|
10
|
+
const generalUtils_1 = require("./generalUtils");
|
10
11
|
const jupApi = (0, api_1.createJupiterApiClient)();
|
11
12
|
function createTransactionInstruction(instruction) {
|
12
13
|
return new web3_js_1.TransactionInstruction({
|
@@ -19,9 +20,9 @@ function createTransactionInstruction(instruction) {
|
|
19
20
|
data: Buffer.from(instruction.data, "base64"),
|
20
21
|
});
|
21
22
|
}
|
22
|
-
async function getJupSwapTransaction(signer, swapDetails) {
|
23
|
+
async function getJupSwapTransaction(signer, swapDetails, attemptNum) {
|
23
24
|
console.log("Getting jup quote...");
|
24
|
-
const quoteResponse = await jupApi.quoteGet({
|
25
|
+
const quoteResponse = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => await jupApi.quoteGet({
|
25
26
|
amount: Number(swapDetails.amount),
|
26
27
|
inputMint: swapDetails.inputMint.toString(),
|
27
28
|
outputMint: swapDetails.outputMint.toString(),
|
@@ -30,8 +31,9 @@ async function getJupSwapTransaction(signer, swapDetails) {
|
|
30
31
|
: swapDetails.exactIn
|
31
32
|
? "ExactIn"
|
32
33
|
: undefined,
|
33
|
-
slippageBps: 10
|
34
|
-
|
34
|
+
slippageBps: 10,
|
35
|
+
maxAccounts: 60,
|
36
|
+
}), 3);
|
35
37
|
const finalPriceSlippageBps = Math.round(Math.max(quoteResponse.slippageBps ?? 10, Math.round((0, numberUtils_1.toBps)(parseFloat(quoteResponse.priceImpactPct)))) *
|
36
38
|
(1 + (swapDetails.slippageBpsIncFactor ?? 0)));
|
37
39
|
quoteResponse.slippageBps = finalPriceSlippageBps;
|
@@ -13,12 +13,7 @@ export declare function getSolautoFeesBps(isReferred: boolean, feeType: FeeType)
|
|
13
13
|
};
|
14
14
|
export declare function eligibileForRebalance(positionState: PositionState, positionSettings: SolautoSettingsParameters, positionDca: DCASettings): boolean;
|
15
15
|
export declare function eligibleForRefresh(positionState: PositionState, positionSettings: SolautoSettingsParameters): boolean;
|
16
|
-
export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicKey): Promise<
|
17
|
-
publicKey: PublicKey;
|
18
|
-
authority: PublicKey;
|
19
|
-
positionId: number;
|
20
|
-
lendingPlatform: LendingPlatform;
|
21
|
-
}[]>;
|
16
|
+
export declare function getSolautoManagedPositions(umi: Umi, authority?: PublicKey): Promise<SolautoPositionDetails[]>;
|
22
17
|
export declare function getAllReferralStates(umi: Umi): Promise<PublicKey[]>;
|
23
18
|
export declare function getReferralsByUser(umi: Umi, user: PublicKey): Promise<PublicKey[]>;
|
24
19
|
export declare function getAllPositionsByAuthority(umi: Umi, user: PublicKey): Promise<SolautoPositionDetails[]>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"generalUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/solauto/generalUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAoB,GAAG,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,eAAe,EACf,aAAa,EAEb,yBAAyB,EACzB,gCAAgC,EAIjC,MAAM,iBAAiB,CAAC;AAczB,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAgB7D,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,kBAAkB,GAC7B,MAAM,CAKR;AAED,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,kBAAkB,GAC7B,OAAO,CAET;AAED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C;AAED,KAAK,kBAAkB,GACnB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,gCAAgC,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAE/C,qBAAa,mBAAmB;IACvB,gBAAgB,EAAE,MAAM,CAAa;IACrC,cAAc,EAAE,MAAM,CAAa;IACnC,uBAAuB,EAAE,MAAM,CAAa;IAC5C,QAAQ,EAAE,yBAAyB,GAAG,SAAS,CAAa;IAC5D,SAAS,EAAE,WAAW,GAAG,SAAS,CAAa;IAEtD,GAAG,CAAC,MAAM,EAAE,kBAAkB;IAyD9B,KAAK;IAQL,UAAU,IAAI,OAAO;CAQtB"}
|
@@ -188,11 +188,15 @@ async function getAllPositionsByAuthority(umi, user) {
|
|
188
188
|
const allPositions = [];
|
189
189
|
const solautoManagedPositions = await getSolautoManagedPositions(umi, user);
|
190
190
|
allPositions.push(...solautoManagedPositions.map((x) => ({
|
191
|
+
publicKey: x.publicKey,
|
192
|
+
authority: user,
|
191
193
|
positionId: x.positionId,
|
192
194
|
lendingPlatform: x.lendingPlatform,
|
193
195
|
})));
|
194
196
|
const marginfiPositions = await (0, marginfiUtils_1.getAllMarginfiAccountsByAuthority)(umi, user, true);
|
195
197
|
allPositions.push(...marginfiPositions.map((x) => ({
|
198
|
+
publicKey: x.marginfiAccount,
|
199
|
+
authority: user,
|
196
200
|
positionId: 0,
|
197
201
|
lendingPlatform: generated_1.LendingPlatform.Marginfi,
|
198
202
|
protocolAccount: x.marginfiAccount,
|
package/local/shared.ts
CHANGED
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
VersionedTransaction,
|
9
9
|
PublicKey,
|
10
10
|
} from "@solana/web3.js";
|
11
|
-
import {
|
11
|
+
import { getSolanaRpcConnection } from "../src/utils/solanaUtils";
|
12
12
|
|
13
13
|
function loadSecretKey(keypairPath: string) {
|
14
14
|
const secretKey = JSON.parse(fs.readFileSync(keypairPath, "utf8"));
|
@@ -22,9 +22,10 @@ export function getSecretKey(keypairFilename: string = "id"): Uint8Array {
|
|
22
22
|
}
|
23
23
|
|
24
24
|
const keypair = Keypair.fromSecretKey(getSecretKey());
|
25
|
+
const [connection, _] = getSolanaRpcConnection(process.env.HELIUS_API_KEY ?? "");
|
25
26
|
|
26
27
|
async function createAndSendV0Tx(txInstructions: TransactionInstruction[]) {
|
27
|
-
let latestBlockhash = await
|
28
|
+
let latestBlockhash = await connection.getLatestBlockhash("finalized");
|
28
29
|
|
29
30
|
const messageV0 = new TransactionMessage({
|
30
31
|
payerKey: keypair.publicKey,
|
@@ -35,11 +36,11 @@ async function createAndSendV0Tx(txInstructions: TransactionInstruction[]) {
|
|
35
36
|
|
36
37
|
transaction.sign([keypair]);
|
37
38
|
|
38
|
-
const txid = await
|
39
|
+
const txid = await connection.sendTransaction(transaction, {
|
39
40
|
maxRetries: 5,
|
40
41
|
});
|
41
42
|
|
42
|
-
const confirmation = await
|
43
|
+
const confirmation = await connection.confirmTransaction({
|
43
44
|
signature: txid,
|
44
45
|
blockhash: latestBlockhash.blockhash,
|
45
46
|
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
|
@@ -76,13 +77,13 @@ export async function updateLookupTable(
|
|
76
77
|
lookupTableAddress?: PublicKey
|
77
78
|
) {
|
78
79
|
let lookupTable = lookupTableAddress
|
79
|
-
? await
|
80
|
+
? await connection.getAddressLookupTable(lookupTableAddress)
|
80
81
|
: null;
|
81
82
|
if (lookupTable === null) {
|
82
83
|
const [createLutIx, addr] = AddressLookupTableProgram.createLookupTable({
|
83
84
|
authority: keypair.publicKey,
|
84
85
|
payer: keypair.publicKey,
|
85
|
-
recentSlot: await
|
86
|
+
recentSlot: await connection.getSlot({ commitment: "finalized" }),
|
86
87
|
});
|
87
88
|
lookupTableAddress = addr;
|
88
89
|
console.log("Lookup Table Address:", lookupTableAddress.toString());
|
package/package.json
CHANGED
@@ -347,9 +347,10 @@ export abstract class SolautoClient {
|
|
347
347
|
);
|
348
348
|
}
|
349
349
|
|
350
|
-
const addingReferredBy =
|
351
|
-
|
352
|
-
|
350
|
+
const addingReferredBy =
|
351
|
+
accountsToAdd.length === 1 &&
|
352
|
+
accountsToAdd[0].toString().toLowerCase() ===
|
353
|
+
this.referredBySupplyTa?.toString().toLowerCase();
|
353
354
|
|
354
355
|
if (tx.getInstructions().length > 0) {
|
355
356
|
this.log("Updating authority lookup table...");
|
@@ -632,8 +633,9 @@ export abstract class SolautoClient {
|
|
632
633
|
rebalanceStep: "A" | "B",
|
633
634
|
swapDetails: JupSwapDetails,
|
634
635
|
rebalanceType: SolautoRebalanceTypeArgs,
|
636
|
+
flashLoan?: FlashLoanDetails,
|
635
637
|
targetLiqUtilizationRateBps?: number,
|
636
|
-
limitGapBps?: number
|
638
|
+
limitGapBps?: number,
|
637
639
|
): TransactionBuilder;
|
638
640
|
|
639
641
|
async getFreshPositionState(): Promise<PositionState | undefined> {
|
@@ -11,10 +11,7 @@ import {
|
|
11
11
|
createSignerFromKeypair,
|
12
12
|
AccountMeta,
|
13
13
|
} from "@metaplex-foundation/umi";
|
14
|
-
import {
|
15
|
-
PublicKey,
|
16
|
-
SYSVAR_INSTRUCTIONS_PUBKEY,
|
17
|
-
} from "@solana/web3.js";
|
14
|
+
import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY } from "@solana/web3.js";
|
18
15
|
import { SolautoClient, SolautoClientArgs } from "./solautoClient";
|
19
16
|
import { MarginfiTokenAccounts } from "../types/accounts";
|
20
17
|
import {
|
@@ -216,7 +213,7 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
216
213
|
marginfiGroup: publicKey(this.marginfiGroup),
|
217
214
|
marginfiAccount:
|
218
215
|
"publicKey" in this.marginfiAccount
|
219
|
-
? this.marginfiAccount as Signer
|
216
|
+
? (this.marginfiAccount as Signer)
|
220
217
|
: publicKey(this.marginfiAccount),
|
221
218
|
supplyMint: publicKey(this.supplyMint),
|
222
219
|
supplyBank: publicKey(this.marginfiSupplyBankAccounts.bank),
|
@@ -230,7 +227,9 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
230
227
|
settingParams: settingParams ?? null,
|
231
228
|
dca: dca ?? null,
|
232
229
|
},
|
233
|
-
marginfiAccountSeedIdx: !this.selfManaged
|
230
|
+
marginfiAccountSeedIdx: !this.selfManaged
|
231
|
+
? this.marginfiAccountSeedIdx
|
232
|
+
: null,
|
234
233
|
});
|
235
234
|
}
|
236
235
|
|
@@ -391,19 +390,28 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
391
390
|
rebalanceStep: "A" | "B",
|
392
391
|
swapDetails: JupSwapDetails,
|
393
392
|
rebalanceType: SolautoRebalanceTypeArgs,
|
393
|
+
flashLoan?: FlashLoanDetails,
|
394
394
|
targetLiqUtilizationRateBps?: number,
|
395
|
-
limitGapBps?: number
|
395
|
+
limitGapBps?: number,
|
396
396
|
): TransactionBuilder {
|
397
|
+
const inputIsSupply = swapDetails.inputMint.equals(this.supplyMint);
|
398
|
+
const outputIsSupply = swapDetails.outputMint.equals(this.supplyMint);
|
399
|
+
const needSupplyAccounts =
|
400
|
+
(inputIsSupply && rebalanceStep === "A") ||
|
401
|
+
(outputIsSupply && rebalanceStep === "B") ||
|
402
|
+
(inputIsSupply && flashLoan !== undefined && rebalanceStep == "B");
|
403
|
+
const needDebtAccounts =
|
404
|
+
(!inputIsSupply && rebalanceStep === "A") ||
|
405
|
+
(!outputIsSupply && rebalanceStep === "B") ||
|
406
|
+
(!inputIsSupply && flashLoan !== undefined && rebalanceStep == "B");
|
407
|
+
|
397
408
|
return marginfiRebalance(this.umi, {
|
398
409
|
signer: this.signer,
|
399
410
|
marginfiProgram: publicKey(MARGINFI_PROGRAM_ID),
|
400
411
|
ixsSysvar: publicKey(SYSVAR_INSTRUCTIONS_PUBKEY),
|
401
412
|
solautoFeesSupplyTa:
|
402
413
|
rebalanceStep === "B" ? publicKey(this.solautoFeesSupplyTa) : undefined,
|
403
|
-
authorityReferralState:
|
404
|
-
rebalanceStep === "B"
|
405
|
-
? publicKey(this.authorityReferralState)
|
406
|
-
: undefined,
|
414
|
+
authorityReferralState: publicKey(this.authorityReferralState),
|
407
415
|
referredBySupplyTa:
|
408
416
|
rebalanceStep === "B" && this.referredBySupplyTa
|
409
417
|
? publicKey(this.referredBySupplyTa)
|
@@ -423,18 +431,22 @@ export class SolautoMarginfiClient extends SolautoClient {
|
|
423
431
|
signerSupplyTa: this.selfManaged
|
424
432
|
? publicKey(this.signerSupplyTa)
|
425
433
|
: undefined,
|
426
|
-
vaultSupplyTa:
|
427
|
-
|
428
|
-
|
429
|
-
|
434
|
+
vaultSupplyTa: needSupplyAccounts
|
435
|
+
? publicKey(this.marginfiSupplyBankAccounts.liquidityVault)
|
436
|
+
: undefined,
|
437
|
+
supplyVaultAuthority: needSupplyAccounts
|
438
|
+
? publicKey(this.marginfiSupplyBankAccounts.vaultAuthority)
|
439
|
+
: undefined,
|
430
440
|
debtBank: publicKey(this.marginfiDebtBankAccounts.bank),
|
431
441
|
debtPriceOracle: publicKey(this.marginfiDebtBankAccounts.priceOracle),
|
432
442
|
positionDebtTa: publicKey(this.positionDebtTa),
|
433
443
|
signerDebtTa: this.selfManaged ? publicKey(this.signerDebtTa) : undefined,
|
434
|
-
vaultDebtTa:
|
435
|
-
|
436
|
-
|
437
|
-
|
444
|
+
vaultDebtTa: needDebtAccounts
|
445
|
+
? publicKey(this.marginfiDebtBankAccounts.liquidityVault)
|
446
|
+
: undefined,
|
447
|
+
debtVaultAuthority: needDebtAccounts
|
448
|
+
? publicKey(this.marginfiDebtBankAccounts.vaultAuthority)
|
449
|
+
: undefined,
|
438
450
|
rebalanceType,
|
439
451
|
targetLiqUtilizationRateBps: targetLiqUtilizationRateBps ?? null,
|
440
452
|
limitGapBps: limitGapBps ?? null,
|
@@ -43,7 +43,7 @@ export type MarginfiRebalanceInstructionAccounts = {
|
|
43
43
|
tokenProgram?: PublicKey | Pda;
|
44
44
|
ixsSysvar: PublicKey | Pda;
|
45
45
|
solautoFeesSupplyTa?: PublicKey | Pda;
|
46
|
-
authorityReferralState
|
46
|
+
authorityReferralState: PublicKey | Pda;
|
47
47
|
referredBySupplyTa?: PublicKey | Pda;
|
48
48
|
solautoPosition: PublicKey | Pda;
|
49
49
|
marginfiGroup: PublicKey | Pda;
|
@@ -206,7 +206,7 @@ export function marginfiRebalance(
|
|
206
206
|
},
|
207
207
|
supplyVaultAuthority: {
|
208
208
|
index: 17,
|
209
|
-
isWritable:
|
209
|
+
isWritable: false as boolean,
|
210
210
|
value: input.supplyVaultAuthority ?? null,
|
211
211
|
},
|
212
212
|
debtBank: {
|
@@ -236,7 +236,7 @@ export function marginfiRebalance(
|
|
236
236
|
},
|
237
237
|
debtVaultAuthority: {
|
238
238
|
index: 23,
|
239
|
-
isWritable:
|
239
|
+
isWritable: false as boolean,
|
240
240
|
value: input.debtVaultAuthority ?? null,
|
241
241
|
},
|
242
242
|
} satisfies ResolvedAccountsWithIndices;
|
@@ -103,7 +103,7 @@ async function transactionChoresBefore(
|
|
103
103
|
client: SolautoClient,
|
104
104
|
accountsGettingCreated: string[],
|
105
105
|
solautoActions?: SolautoAction[],
|
106
|
-
initiatingDcaIn?: bigint
|
106
|
+
initiatingDcaIn?: bigint
|
107
107
|
): Promise<TransactionBuilder> {
|
108
108
|
let chores = transactionBuilder();
|
109
109
|
|
@@ -233,8 +233,9 @@ export async function rebalanceChoresBefore(
|
|
233
233
|
}
|
234
234
|
|
235
235
|
const usesAccount = (key: PublicKey) =>
|
236
|
-
rebalanceInstructions
|
237
|
-
|
236
|
+
rebalanceInstructions.some((t) =>
|
237
|
+
t.keys.some((k) => toWeb3JsPublicKey(k.pubkey).equals(key))
|
238
|
+
);
|
238
239
|
|
239
240
|
const checkReferralSupplyTa =
|
240
241
|
client.referredBySupplyTa && usesAccount(client.referredBySupplyTa);
|
@@ -244,8 +245,10 @@ export async function rebalanceChoresBefore(
|
|
244
245
|
usesAccount(
|
245
246
|
(client as SolautoMarginfiClient).intermediaryMarginfiAccountPk
|
246
247
|
);
|
247
|
-
const checkSignerSupplyTa =
|
248
|
-
|
248
|
+
const checkSignerSupplyTa =
|
249
|
+
client.selfManaged && usesAccount(client.signerSupplyTa);
|
250
|
+
const checkSignerDebtTa =
|
251
|
+
client.selfManaged && usesAccount(client.signerSupplyTa);
|
249
252
|
|
250
253
|
const accountsNeeded = [
|
251
254
|
...[checkReferralSupplyTa ? client.referredBySupplyTa : PublicKey.default],
|
@@ -259,10 +262,15 @@ export async function rebalanceChoresBefore(
|
|
259
262
|
...[checkSignerDebtTa ? client.signerDebtTa : PublicKey.default],
|
260
263
|
];
|
261
264
|
|
262
|
-
const [
|
263
|
-
|
264
|
-
|
265
|
-
|
265
|
+
const [
|
266
|
+
referredBySupplyTa,
|
267
|
+
solautoFeesSupplyTa,
|
268
|
+
intermediaryMarginfiAccount,
|
269
|
+
signerSupplyTa,
|
270
|
+
signerDebtTa,
|
271
|
+
] = await client.umi.rpc.getAccounts(
|
272
|
+
accountsNeeded.map((x) => publicKey(x ?? PublicKey.default))
|
273
|
+
);
|
266
274
|
|
267
275
|
let chores = transactionBuilder();
|
268
276
|
|
@@ -297,7 +305,11 @@ export async function rebalanceChoresBefore(
|
|
297
305
|
);
|
298
306
|
}
|
299
307
|
|
300
|
-
if (
|
308
|
+
if (
|
309
|
+
checkSignerSupplyTa &&
|
310
|
+
!rpcAccountCreated(signerSupplyTa) &&
|
311
|
+
!accountsGettingCreated.includes(signerSupplyTa.publicKey.toString())
|
312
|
+
) {
|
301
313
|
client.log("Creating signer supply token account");
|
302
314
|
chores = chores.add(
|
303
315
|
createAssociatedTokenAccountUmiIx(
|
@@ -309,7 +321,11 @@ export async function rebalanceChoresBefore(
|
|
309
321
|
accountsGettingCreated.push(signerSupplyTa.publicKey.toString());
|
310
322
|
}
|
311
323
|
|
312
|
-
if (
|
324
|
+
if (
|
325
|
+
checkSignerDebtTa &&
|
326
|
+
!rpcAccountCreated(signerDebtTa) &&
|
327
|
+
!accountsGettingCreated.includes(signerDebtTa.publicKey.toString())
|
328
|
+
) {
|
313
329
|
client.log("Creating signer debt token account");
|
314
330
|
chores = chores.add(
|
315
331
|
createAssociatedTokenAccountUmiIx(
|
@@ -358,7 +374,7 @@ function getRebalanceInstructions(tx: TransactionBuilder): Instruction[] {
|
|
358
374
|
const discriminator = serializer.serialize({
|
359
375
|
limitGapBps: 0,
|
360
376
|
rebalanceType: SolautoRebalanceType.None,
|
361
|
-
targetLiqUtilizationRateBps: 0
|
377
|
+
targetLiqUtilizationRateBps: 0,
|
362
378
|
})[0];
|
363
379
|
const [data, _] = serializer.deserialize(x.data);
|
364
380
|
if (data.discriminator === discriminator) {
|
@@ -378,10 +394,9 @@ function getSolautoActions(tx: TransactionBuilder): SolautoAction[] {
|
|
378
394
|
try {
|
379
395
|
const serializer =
|
380
396
|
getMarginfiProtocolInteractionInstructionDataSerializer();
|
381
|
-
const discriminator = serializer
|
382
|
-
|
383
|
-
|
384
|
-
})[0];
|
397
|
+
const discriminator = serializer.serialize({
|
398
|
+
solautoAction: solautoAction("Deposit", [BigInt(0)]),
|
399
|
+
})[0];
|
385
400
|
const [data, _] = serializer.deserialize(x.data);
|
386
401
|
if (data.discriminator === discriminator) {
|
387
402
|
solautoActions?.push(data.solautoAction);
|
@@ -518,7 +533,7 @@ export async function getTransactionChores(
|
|
518
533
|
solautoActions,
|
519
534
|
client.livePositionUpdates.debtTaBalanceAdjustment > 0
|
520
535
|
? client.livePositionUpdates.debtTaBalanceAdjustment
|
521
|
-
: undefined
|
536
|
+
: undefined
|
522
537
|
),
|
523
538
|
await rebalanceChoresBefore(client, tx, accountsGettingCreated),
|
524
539
|
]);
|
@@ -576,7 +591,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
576
591
|
setupInstructions,
|
577
592
|
tokenLedgerIx,
|
578
593
|
swapIx,
|
579
|
-
} = await getJupSwapTransaction(client.signer, swapDetails);
|
594
|
+
} = await getJupSwapTransaction(client.signer, swapDetails, attemptNum);
|
580
595
|
const flashLoan = getFlashLoanDetails(client, values, jupQuote);
|
581
596
|
|
582
597
|
let tx = transactionBuilder();
|
@@ -604,6 +619,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
604
619
|
"A",
|
605
620
|
swapDetails,
|
606
621
|
rebalanceType,
|
622
|
+
flashLoan,
|
607
623
|
targetLiqUtilizationRateBps
|
608
624
|
),
|
609
625
|
]
|
@@ -613,6 +629,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
613
629
|
"B",
|
614
630
|
swapDetails,
|
615
631
|
rebalanceType,
|
632
|
+
flashLoan,
|
616
633
|
targetLiqUtilizationRateBps
|
617
634
|
),
|
618
635
|
client.flashRepay(flashLoan),
|
@@ -626,6 +643,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
626
643
|
"A",
|
627
644
|
swapDetails,
|
628
645
|
rebalanceType,
|
646
|
+
undefined,
|
629
647
|
targetLiqUtilizationRateBps
|
630
648
|
),
|
631
649
|
swapIx,
|
@@ -633,6 +651,7 @@ export async function buildSolautoRebalanceTransaction(
|
|
633
651
|
"B",
|
634
652
|
swapDetails,
|
635
653
|
rebalanceType,
|
654
|
+
undefined,
|
636
655
|
targetLiqUtilizationRateBps
|
637
656
|
),
|
638
657
|
]);
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import bs58 from "bs58";
|
2
2
|
import {
|
3
3
|
AddressLookupTableInput,
|
4
|
+
Instruction,
|
4
5
|
transactionBuilder,
|
5
6
|
TransactionBuilder,
|
6
7
|
} from "@metaplex-foundation/umi";
|
@@ -14,6 +15,7 @@ import {
|
|
14
15
|
retryWithExponentialBackoff,
|
15
16
|
} from "../utils/generalUtils";
|
16
17
|
import { getTransactionChores } from "./transactionUtils";
|
18
|
+
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
17
19
|
// import { sendJitoBundledTransactions } from "../utils/jitoUtils";
|
18
20
|
|
19
21
|
class LookupTables {
|
@@ -45,7 +47,7 @@ class LookupTables {
|
|
45
47
|
this.cache.push(...additionalInputs);
|
46
48
|
}
|
47
49
|
|
48
|
-
return this.cache
|
50
|
+
return this.cache;
|
49
51
|
}
|
50
52
|
}
|
51
53
|
|
@@ -89,7 +91,7 @@ export class TransactionItem {
|
|
89
91
|
class TransactionSet {
|
90
92
|
constructor(
|
91
93
|
private client: SolautoClient,
|
92
|
-
|
94
|
+
public lookupTables: LookupTables,
|
93
95
|
public items: TransactionItem[] = []
|
94
96
|
) {}
|
95
97
|
|
@@ -210,8 +212,12 @@ export class TransactionsManager {
|
|
210
212
|
await this.lookupTables.getLutInputs(item.lookupTableAddresses)
|
211
213
|
);
|
212
214
|
if (!transaction.fitsInOneTransaction(this.client.umi)) {
|
213
|
-
|
214
|
-
|
215
|
+
// TODO: revert me
|
216
|
+
// throw new Error(
|
217
|
+
// `Transaction exceeds max transaction size (${transaction.getTransactionSize(this.client.umi)})`
|
218
|
+
// );
|
219
|
+
transactionSets.push(
|
220
|
+
new TransactionSet(this.client, this.lookupTables, [item])
|
215
221
|
);
|
216
222
|
} else {
|
217
223
|
let newSet = new TransactionSet(this.client, this.lookupTables, [item]);
|
@@ -246,9 +252,43 @@ export class TransactionsManager {
|
|
246
252
|
this.statusCallback?.(this.statuses);
|
247
253
|
}
|
248
254
|
|
255
|
+
// TODO remove me
|
256
|
+
async debugAccounts(itemSet: TransactionSet, tx: TransactionBuilder) {
|
257
|
+
const lutInputs = await itemSet.lookupTables.getLutInputs([]);
|
258
|
+
const lutAccounts = lutInputs.map((x) => x.addresses).flat();
|
259
|
+
const keys = tx
|
260
|
+
.getInstructions()
|
261
|
+
.map((x) => x.keys)
|
262
|
+
.flat();
|
263
|
+
for (const ix of tx.getInstructions()) {
|
264
|
+
const ixAccounts = ix.keys.map((x) => x.pubkey);
|
265
|
+
const accountsNotInLut = ixAccounts.filter(
|
266
|
+
(x) => !lutAccounts.includes(x)
|
267
|
+
);
|
268
|
+
console.log(
|
269
|
+
"Program",
|
270
|
+
ix.programId,
|
271
|
+
" data ",
|
272
|
+
ix.data.length,
|
273
|
+
ix.keys.filter((x) => lutAccounts.includes(x.pubkey)).length * 3
|
274
|
+
);
|
275
|
+
if (accountsNotInLut.length > 0) {
|
276
|
+
console.log("Accounts not in LUT:");
|
277
|
+
for (const key of accountsNotInLut) {
|
278
|
+
console.log(key.toString());
|
279
|
+
}
|
280
|
+
console.log(ix.keys.length);
|
281
|
+
}
|
282
|
+
}
|
283
|
+
}
|
284
|
+
|
249
285
|
async send() {
|
250
286
|
const updateLookupTable = await this.client.updateLookupTable();
|
251
|
-
if (
|
287
|
+
if (
|
288
|
+
updateLookupTable &&
|
289
|
+
updateLookupTable.updateLutTx.getInstructions().length > 0 &&
|
290
|
+
updateLookupTable?.needsToBeIsolated
|
291
|
+
) {
|
252
292
|
this.updateStatus("update lookup table", TransactionStatus.Processing);
|
253
293
|
await retryWithExponentialBackoff(
|
254
294
|
async (attemptNum) =>
|
@@ -365,6 +405,11 @@ export class TransactionsManager {
|
|
365
405
|
this.updateStatus(itemSet.name(), TransactionStatus.Skipped);
|
366
406
|
} else {
|
367
407
|
this.updateStatus(itemSet.name(), TransactionStatus.Processing);
|
408
|
+
|
409
|
+
if (this.client.localTest) {
|
410
|
+
await this.debugAccounts(itemSet, tx);
|
411
|
+
}
|
412
|
+
|
368
413
|
const txSig = await sendSingleOptimizedTransaction(
|
369
414
|
this.client.umi,
|
370
415
|
this.client.connection,
|
package/src/types/solauto.ts
CHANGED
@@ -2,9 +2,11 @@ import { PublicKey } from "@solana/web3.js";
|
|
2
2
|
import { LendingPlatform } from "../generated";
|
3
3
|
|
4
4
|
export interface SolautoPositionDetails {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
publicKey: PublicKey;
|
6
|
+
authority: PublicKey;
|
7
|
+
positionId: number;
|
8
|
+
lendingPlatform: LendingPlatform;
|
9
|
+
protocolAccount?: PublicKey;
|
10
|
+
supplyMint?: PublicKey;
|
11
|
+
debtMint?: PublicKey;
|
10
12
|
}
|
@@ -3,6 +3,7 @@ import { MaybeRpcAccount, publicKey, Umi } from "@metaplex-foundation/umi";
|
|
3
3
|
import { PYTH_PRICE_FEED_IDS } from "../constants/pythConstants";
|
4
4
|
import { fromBaseUnit, toBaseUnit } from "./numberUtils";
|
5
5
|
import { PRICES } from "../constants/solautoConstants";
|
6
|
+
import { ResponseError } from "@jup-ag/api";
|
6
7
|
|
7
8
|
export function generateRandomU8(): number {
|
8
9
|
return Math.floor(Math.random() * 255 + 1);
|
@@ -120,7 +121,7 @@ export function retryWithExponentialBackoff<T>(
|
|
120
121
|
}
|
121
122
|
|
122
123
|
if (attemptNum < retries) {
|
123
|
-
console.log(error);
|
124
|
+
console.log(error.message);
|
124
125
|
setTimeout(() => {
|
125
126
|
console.log("Retrying...");
|
126
127
|
return attempt(attemptNum);
|
@@ -12,6 +12,7 @@ import {
|
|
12
12
|
QuoteResponse,
|
13
13
|
} from "@jup-ag/api";
|
14
14
|
import { getTokenAccount } from "./accountUtils";
|
15
|
+
import { retryWithExponentialBackoff } from "./generalUtils";
|
15
16
|
|
16
17
|
const jupApi = createJupiterApiClient();
|
17
18
|
|
@@ -49,21 +50,26 @@ export interface JupSwapTransaction {
|
|
49
50
|
|
50
51
|
export async function getJupSwapTransaction(
|
51
52
|
signer: Signer,
|
52
|
-
swapDetails: JupSwapDetails
|
53
|
+
swapDetails: JupSwapDetails,
|
54
|
+
attemptNum?: number
|
53
55
|
): Promise<JupSwapTransaction> {
|
54
56
|
console.log("Getting jup quote...");
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
57
|
+
const quoteResponse = await retryWithExponentialBackoff(
|
58
|
+
async () =>
|
59
|
+
await jupApi.quoteGet({
|
60
|
+
amount: Number(swapDetails.amount),
|
61
|
+
inputMint: swapDetails.inputMint.toString(),
|
62
|
+
outputMint: swapDetails.outputMint.toString(),
|
63
|
+
swapMode: swapDetails.exactOut
|
64
|
+
? "ExactOut"
|
65
|
+
: swapDetails.exactIn
|
66
|
+
? "ExactIn"
|
67
|
+
: undefined,
|
68
|
+
slippageBps: 10,
|
69
|
+
maxAccounts: 60,
|
70
|
+
}),
|
71
|
+
3
|
72
|
+
);
|
67
73
|
|
68
74
|
const finalPriceSlippageBps = Math.round(
|
69
75
|
Math.max(
|
@@ -176,14 +176,7 @@ export function eligibleForRefresh(
|
|
176
176
|
export async function getSolautoManagedPositions(
|
177
177
|
umi: Umi,
|
178
178
|
authority?: PublicKey
|
179
|
-
): Promise<
|
180
|
-
{
|
181
|
-
publicKey: PublicKey;
|
182
|
-
authority: PublicKey;
|
183
|
-
positionId: number;
|
184
|
-
lendingPlatform: LendingPlatform;
|
185
|
-
}[]
|
186
|
-
> {
|
179
|
+
): Promise<SolautoPositionDetails[]> {
|
187
180
|
// bump: [u8; 1]
|
188
181
|
// position_id: [u8; 1]
|
189
182
|
// self_managed: u8 - (1 for true, 0 for false)
|
@@ -294,6 +287,8 @@ export async function getAllPositionsByAuthority(
|
|
294
287
|
const solautoManagedPositions = await getSolautoManagedPositions(umi, user);
|
295
288
|
allPositions.push(
|
296
289
|
...solautoManagedPositions.map((x) => ({
|
290
|
+
publicKey: x.publicKey,
|
291
|
+
authority: user,
|
297
292
|
positionId: x.positionId,
|
298
293
|
lendingPlatform: x.lendingPlatform,
|
299
294
|
}))
|
@@ -306,6 +301,8 @@ export async function getAllPositionsByAuthority(
|
|
306
301
|
);
|
307
302
|
allPositions.push(
|
308
303
|
...marginfiPositions.map((x) => ({
|
304
|
+
publicKey: x.marginfiAccount,
|
305
|
+
authority: user,
|
309
306
|
positionId: 0,
|
310
307
|
lendingPlatform: LendingPlatform.Marginfi,
|
311
308
|
protocolAccount: x.marginfiAccount,
|
@@ -24,7 +24,7 @@ describe("Solauto Marginfi tests", async () => {
|
|
24
24
|
|
25
25
|
const payForTransactions = false;
|
26
26
|
const useJitoBundle = false;
|
27
|
-
const positionId =
|
27
|
+
const positionId = 0;
|
28
28
|
|
29
29
|
it("open - deposit - borrow - rebalance to 0 - withdraw - close", async () => {
|
30
30
|
const client = new SolautoMarginfiClient(process.env.HELIUS_API_KEY!, true);
|
@@ -37,11 +37,11 @@ describe("Solauto Marginfi tests", async () => {
|
|
37
37
|
{
|
38
38
|
signer,
|
39
39
|
positionId,
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
40
|
+
marginfiAccount: new PublicKey(
|
41
|
+
"4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
|
42
|
+
),
|
43
|
+
supplyMint: NATIVE_MINT,
|
44
|
+
debtMint: new PublicKey(USDC_MINT),
|
45
45
|
}
|
46
46
|
);
|
47
47
|
|