@haven-fi/solauto-sdk 1.0.373 → 1.0.374
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/transactions/transactionsManager.js +8 -9
- package/dist/utils/jitoUtils.d.ts.map +1 -1
- package/dist/utils/jitoUtils.js +18 -16
- package/dist/utils/marginfiUtils.d.ts.map +1 -1
- package/dist/utils/marginfiUtils.js +7 -3
- package/local/logPositions.ts +21 -0
- package/package.json +2 -6
- package/src/transactions/transactionsManager.ts +8 -8
- package/src/utils/jitoUtils.ts +32 -24
- package/src/utils/marginfiUtils.ts +14 -4
- package/tests/transactions/solautoMarginfi.ts +65 -34
@@ -171,15 +171,14 @@ class TransactionsManager {
|
|
171
171
|
let newSet = new TransactionSet(this.txHandler, this.lookupTables, [
|
172
172
|
item,
|
173
173
|
]);
|
174
|
-
for (let j = i; j >= 0; j--) {
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
}
|
174
|
+
// for (let j = i; j >= 0; j--) {
|
175
|
+
// if (await newSet.fitsWith(items[j])) {
|
176
|
+
// newSet.prepend(items[j]);
|
177
|
+
// i--;
|
178
|
+
// } else {
|
179
|
+
// break;
|
180
|
+
// }
|
181
|
+
// }
|
183
182
|
transactionSets.unshift(newSet);
|
184
183
|
}
|
185
184
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAIV,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEJ,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAIlE,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,CAa9D;
|
1
|
+
{"version":3,"file":"jitoUtils.d.ts","sourceRoot":"","sources":["../../src/utils/jitoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAIV,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,kBAAkB,EAClB,GAAG,EAEJ,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAIlE,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,SAAS,CAAC,CAa9D;AAoKD,wBAAsB,2BAA2B,CAC/C,GAAG,EAAE,GAAG,EACR,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,kBAAkB,EAAE,EACzB,MAAM,CAAC,EAAE,kBAAkB,EAC3B,kBAAkB,GAAE,kBAA2C,EAC/D,cAAc,CAAC,EAAE,MAAM,IAAI,GAC1B,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAwE/B"}
|
package/dist/utils/jitoUtils.js
CHANGED
@@ -32,18 +32,6 @@ async function getTipInstruction(signer, tipLamports) {
|
|
32
32
|
}
|
33
33
|
async function simulateJitoBundle(umi, txs) {
|
34
34
|
const simulationResult = await (0, generalUtils_1.retryWithExponentialBackoff)(async () => {
|
35
|
-
// const resp = await umi.rpc.call("simulateBundle", [
|
36
|
-
// {
|
37
|
-
// encodedTransactions: txs.map((x) =>
|
38
|
-
// Buffer.from(x.serialize()).toString("base64")
|
39
|
-
// ),
|
40
|
-
// },
|
41
|
-
// {
|
42
|
-
// preExecutionAccountsConfigs: txs.map((_) => ""),
|
43
|
-
// postExecutionAccountsConfigs: txs.map((_) => ""),
|
44
|
-
// skipSigVerify: true,
|
45
|
-
// },
|
46
|
-
// ]);
|
47
35
|
const resp = await axios_1.default.post(umi.rpc.getEndpoint(), {
|
48
36
|
jsonrpc: "2.0",
|
49
37
|
id: 1,
|
@@ -73,6 +61,7 @@ async function simulateJitoBundle(umi, txs) {
|
|
73
61
|
(0, generalUtils_1.consoleLog)(y);
|
74
62
|
});
|
75
63
|
});
|
64
|
+
(0, generalUtils_1.consoleLog)(JSON.stringify(transactionResults, null, 2));
|
76
65
|
const txFailure = res.summary.failed.error.TransactionFailure;
|
77
66
|
throw new Error(txFailure ? txFailure[1] : res.summary.failed.toString());
|
78
67
|
}
|
@@ -113,7 +102,12 @@ async function pollBundleStatus(bundleId, interval = 1000, timeout = 40000) {
|
|
113
102
|
(0, generalUtils_1.consoleLog)("Statuses:", statuses);
|
114
103
|
const status = statuses.value[0].confirmation_status;
|
115
104
|
if (status === "confirmed") {
|
116
|
-
return statuses
|
105
|
+
return statuses.value[0].transactions;
|
106
|
+
}
|
107
|
+
const err = statuses.value[0].err;
|
108
|
+
if (err) {
|
109
|
+
(0, generalUtils_1.consoleLog)("Jito bundle err:", JSON.stringify(err, null, 2));
|
110
|
+
throw new Error(err);
|
117
111
|
}
|
118
112
|
}
|
119
113
|
}
|
@@ -146,16 +140,24 @@ async function sendJitoBundledTransactions(umi, signer, txs, txType, priorityFee
|
|
146
140
|
(0, generalUtils_1.consoleLog)("Sending Jito bundle...");
|
147
141
|
(0, generalUtils_1.consoleLog)("Transactions: ", txs.length);
|
148
142
|
(0, generalUtils_1.consoleLog)("Transaction sizes: ", txs.map((x) => x.getTransactionSize(umi)));
|
143
|
+
// consoleLog(txs.map((x) => x.getInstructions().map((x) => x.programId)));
|
149
144
|
txs[0] = txs[0].prepend(await getTipInstruction(signer, 150000));
|
150
145
|
const feeEstimates = priorityFeeSetting !== types_1.PriorityFeeSetting.None
|
151
146
|
? await Promise.all(txs.map(async (x) => (await (0, solanaUtils_1.getComputeUnitPriceEstimate)(umi, x, priorityFeeSetting)) ??
|
152
147
|
1000000))
|
153
148
|
: undefined;
|
154
149
|
const latestBlockhash = (await umi.rpc.getLatestBlockhash({ commitment: "confirmed" })).blockhash;
|
155
|
-
let builtTxs
|
156
|
-
|
150
|
+
let builtTxs;
|
151
|
+
let simulationResults;
|
152
|
+
if (txType !== "skip-simulation") {
|
153
|
+
builtTxs = await umiToVersionedTransactions(umi, latestBlockhash, signer, txs, false, feeEstimates);
|
154
|
+
(0, generalUtils_1.consoleLog)(builtTxs.map((x) => x.message.compiledInstructions.map((y) => x.message.staticAccountKeys[y.programIdIndex].toString())));
|
155
|
+
simulationResults = await simulateJitoBundle(umi, builtTxs);
|
156
|
+
}
|
157
157
|
if (txType !== "only-simulate") {
|
158
|
-
builtTxs = await umiToVersionedTransactions(umi, latestBlockhash, signer, txs, true, feeEstimates, simulationResults
|
158
|
+
builtTxs = await umiToVersionedTransactions(umi, latestBlockhash, signer, txs, true, feeEstimates, simulationResults
|
159
|
+
? simulationResults.map((x) => x.unitsConsumed * 1.15)
|
160
|
+
: undefined);
|
159
161
|
const serializedTxs = builtTxs.map((x) => x.serialize());
|
160
162
|
if (serializedTxs.find((x) => x.length > 1232)) {
|
161
163
|
throw new Error("A transaction is too large");
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"marginfiUtils.d.ts","sourceRoot":"","sources":["../../src/utils/marginfiUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EACL,IAAI,EAGJ,eAAe,EAGhB,MAAM,iBAAiB,CAAC;AAazB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAsB,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAI7D,UAAU,wBAAyB,SAAQ,qBAAqB;IAC9D,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,SAAS,GACd,wBAAwB,CAY1B;AAED,wBAAgB,iCAAiC,CAC/C,UAAU,EAAE,IAAI,EAChB,QAAQ,EAAE,IAAI,EACd,WAAW,EAAE,MAAM,GAClB,C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G,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBnE;AAED,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,WASpE"}
|
@@ -229,9 +229,13 @@ async function getMarginfiAccountPositionState(umi, protocolAccount, marginfiGro
|
|
229
229
|
if (!supplyUsage) {
|
230
230
|
supplyUsage = await getTokenUsage(supplyBank, true, 0, livePositionUpdates?.supplyAdjustment);
|
231
231
|
}
|
232
|
-
if (debtBank === null
|
233
|
-
|
234
|
-
|
232
|
+
if (debtBank === null) {
|
233
|
+
return undefined;
|
234
|
+
}
|
235
|
+
const supplyMint = constants_1.TOKEN_INFO[supplyBank.mint.toString()];
|
236
|
+
const debtMint = constants_1.TOKEN_INFO[debtBank.mint.toString()];
|
237
|
+
if ((!supplyMint.isStableCoin && !debtMint.isStableCoin) ||
|
238
|
+
(supplyMint.isStableCoin && debtMint.isStableCoin)) {
|
235
239
|
return undefined;
|
236
240
|
}
|
237
241
|
if (!debtUsage) {
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import {
|
2
|
+
buildHeliusApiUrl,
|
3
|
+
getSolanaRpcConnection,
|
4
|
+
getSolautoManagedPositions,
|
5
|
+
SOLAUTO_PROD_PROGRAM,
|
6
|
+
} from "../src";
|
7
|
+
|
8
|
+
async function main() {
|
9
|
+
const [_, umi] = getSolanaRpcConnection(
|
10
|
+
buildHeliusApiUrl(process.env.HELIUS_API_KEY!),
|
11
|
+
SOLAUTO_PROD_PROGRAM
|
12
|
+
);
|
13
|
+
const positions = await getSolautoManagedPositions(umi);
|
14
|
+
// TODO: filter out certain wallet authorities using an env variable
|
15
|
+
|
16
|
+
console.log(positions);
|
17
|
+
console.log("Total positions:", positions.length);
|
18
|
+
// TODO: log net worth / balances
|
19
|
+
}
|
20
|
+
|
21
|
+
main().then((x) => x);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@haven-fi/solauto-sdk",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.374",
|
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",
|
@@ -10,11 +10,7 @@
|
|
10
10
|
"build": "rm -rf dist && npx tsc",
|
11
11
|
"test:txs": "ts-mocha -p ./tsconfig.json -t 1000000 tests/transactions/**/*.ts",
|
12
12
|
"test:unit": "ts-mocha -p ./tsconfig.json -t 1000000 tests/unit/**/*.ts",
|
13
|
-
"test:all": "pnpm test:unit && pnpm test:txs"
|
14
|
-
"update-lut:solauto": "npx ts-node local/updateSolautoLUT.ts",
|
15
|
-
"update-lut:marginfi": "npx ts-node local/updateMarginfiLUT.ts",
|
16
|
-
"create-ism-accounts": "npx ts-node local/createISMAccounts.ts",
|
17
|
-
"create-token-accounts": "npx ts-node local/createTokenAccounts.ts"
|
13
|
+
"test:all": "pnpm test:unit && pnpm test:txs"
|
18
14
|
},
|
19
15
|
"dependencies": {
|
20
16
|
"@coral-xyz/anchor": "^0.30.1",
|
@@ -263,14 +263,14 @@ export class TransactionsManager {
|
|
263
263
|
let newSet = new TransactionSet(this.txHandler, this.lookupTables, [
|
264
264
|
item,
|
265
265
|
]);
|
266
|
-
for (let j = i; j >= 0; j--) {
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
}
|
266
|
+
// for (let j = i; j >= 0; j--) {
|
267
|
+
// if (await newSet.fitsWith(items[j])) {
|
268
|
+
// newSet.prepend(items[j]);
|
269
|
+
// i--;
|
270
|
+
// } else {
|
271
|
+
// break;
|
272
|
+
// }
|
273
|
+
// }
|
274
274
|
transactionSets.unshift(newSet);
|
275
275
|
}
|
276
276
|
}
|
package/src/utils/jitoUtils.ts
CHANGED
@@ -50,19 +50,6 @@ async function getTipInstruction(
|
|
50
50
|
|
51
51
|
async function simulateJitoBundle(umi: Umi, txs: VersionedTransaction[]) {
|
52
52
|
const simulationResult = await retryWithExponentialBackoff(async () => {
|
53
|
-
// const resp = await umi.rpc.call("simulateBundle", [
|
54
|
-
// {
|
55
|
-
// encodedTransactions: txs.map((x) =>
|
56
|
-
// Buffer.from(x.serialize()).toString("base64")
|
57
|
-
// ),
|
58
|
-
// },
|
59
|
-
// {
|
60
|
-
// preExecutionAccountsConfigs: txs.map((_) => ""),
|
61
|
-
// postExecutionAccountsConfigs: txs.map((_) => ""),
|
62
|
-
// skipSigVerify: true,
|
63
|
-
// },
|
64
|
-
// ]);
|
65
|
-
|
66
53
|
const resp = await axios.post(
|
67
54
|
umi.rpc.getEndpoint(),
|
68
55
|
{
|
@@ -102,6 +89,7 @@ async function simulateJitoBundle(umi: Umi, txs: VersionedTransaction[]) {
|
|
102
89
|
});
|
103
90
|
});
|
104
91
|
|
92
|
+
consoleLog(JSON.stringify(transactionResults, null, 2));
|
105
93
|
const txFailure = res.summary.failed.error.TransactionFailure;
|
106
94
|
throw new Error(txFailure ? txFailure[1] : res.summary.failed.toString());
|
107
95
|
}
|
@@ -171,7 +159,12 @@ async function pollBundleStatus(
|
|
171
159
|
consoleLog("Statuses:", statuses);
|
172
160
|
const status = statuses.value[0].confirmation_status;
|
173
161
|
if (status === "confirmed") {
|
174
|
-
return statuses
|
162
|
+
return statuses.value[0].transactions as string[];
|
163
|
+
}
|
164
|
+
const err = statuses.value[0].err;
|
165
|
+
if (err) {
|
166
|
+
consoleLog("Jito bundle err:", JSON.stringify(err, null, 2));
|
167
|
+
throw new Error(err);
|
175
168
|
}
|
176
169
|
}
|
177
170
|
}
|
@@ -220,6 +213,7 @@ export async function sendJitoBundledTransactions(
|
|
220
213
|
"Transaction sizes: ",
|
221
214
|
txs.map((x) => x.getTransactionSize(umi))
|
222
215
|
);
|
216
|
+
// consoleLog(txs.map((x) => x.getInstructions().map((x) => x.programId)));
|
223
217
|
|
224
218
|
txs[0] = txs[0].prepend(await getTipInstruction(signer, 150_000));
|
225
219
|
const feeEstimates =
|
@@ -236,15 +230,27 @@ export async function sendJitoBundledTransactions(
|
|
236
230
|
const latestBlockhash = (
|
237
231
|
await umi.rpc.getLatestBlockhash({ commitment: "confirmed" })
|
238
232
|
).blockhash;
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
233
|
+
|
234
|
+
let builtTxs: VersionedTransaction[];
|
235
|
+
let simulationResults: SimulatedTransactionResponse[] | undefined;
|
236
|
+
if (txType !== "skip-simulation") {
|
237
|
+
builtTxs = await umiToVersionedTransactions(
|
238
|
+
umi,
|
239
|
+
latestBlockhash,
|
240
|
+
signer,
|
241
|
+
txs,
|
242
|
+
false,
|
243
|
+
feeEstimates
|
244
|
+
);
|
245
|
+
consoleLog(
|
246
|
+
builtTxs.map((x) =>
|
247
|
+
x.message.compiledInstructions.map((y) =>
|
248
|
+
x.message.staticAccountKeys[y.programIdIndex].toString()
|
249
|
+
)
|
250
|
+
)
|
251
|
+
);
|
252
|
+
simulationResults = await simulateJitoBundle(umi, builtTxs);
|
253
|
+
}
|
248
254
|
|
249
255
|
if (txType !== "only-simulate") {
|
250
256
|
builtTxs = await umiToVersionedTransactions(
|
@@ -254,7 +260,9 @@ export async function sendJitoBundledTransactions(
|
|
254
260
|
txs,
|
255
261
|
true,
|
256
262
|
feeEstimates,
|
257
|
-
simulationResults
|
263
|
+
simulationResults
|
264
|
+
? simulationResults.map((x) => x.unitsConsumed! * 1.15)
|
265
|
+
: undefined
|
258
266
|
);
|
259
267
|
|
260
268
|
const serializedTxs = builtTxs.map((x) => x.serialize());
|
@@ -134,7 +134,11 @@ export async function getMarginfiMaxLtvAndLiqThreshold(
|
|
134
134
|
return [0, 0];
|
135
135
|
}
|
136
136
|
|
137
|
-
return calcMarginfiMaxLtvAndLiqThreshold(
|
137
|
+
return calcMarginfiMaxLtvAndLiqThreshold(
|
138
|
+
supply.bank!,
|
139
|
+
debt.bank,
|
140
|
+
supplyPrice
|
141
|
+
);
|
138
142
|
}
|
139
143
|
|
140
144
|
export async function getAllMarginfiAccountsByAuthority(
|
@@ -412,10 +416,16 @@ export async function getMarginfiAccountPositionState(
|
|
412
416
|
);
|
413
417
|
}
|
414
418
|
|
419
|
+
if (debtBank === null) {
|
420
|
+
return undefined;
|
421
|
+
}
|
422
|
+
|
423
|
+
const supplyMint = TOKEN_INFO[supplyBank.mint.toString()];
|
424
|
+
const debtMint = TOKEN_INFO[debtBank.mint.toString()];
|
425
|
+
|
415
426
|
if (
|
416
|
-
|
417
|
-
(
|
418
|
-
!TOKEN_INFO[debtBank.mint.toString()].isStableCoin)
|
427
|
+
(!supplyMint.isStableCoin && !debtMint.isStableCoin) ||
|
428
|
+
(supplyMint.isStableCoin && debtMint.isStableCoin)
|
419
429
|
) {
|
420
430
|
return undefined;
|
421
431
|
}
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import { describe, it } from "mocha";
|
2
|
-
import { none, publicKey, some } from "@metaplex-foundation/umi";
|
2
|
+
import { none, publicKey, some, transactionBuilder } from "@metaplex-foundation/umi";
|
3
3
|
import { setupTest } from "../shared";
|
4
4
|
import { SolautoMarginfiClient } from "../../src/clients/solautoMarginfiClient";
|
5
5
|
import {
|
6
|
+
PositionType,
|
6
7
|
safeFetchSolautoPosition,
|
7
8
|
solautoAction,
|
8
9
|
SolautoSettingsParametersInpArgs,
|
@@ -25,7 +26,7 @@ import {
|
|
25
26
|
SOLAUTO_TEST_PROGRAM,
|
26
27
|
USDC,
|
27
28
|
} from "../../src/constants";
|
28
|
-
import { buildHeliusApiUrl, getSolautoManagedPositions } from "../../src/utils";
|
29
|
+
import { buildHeliusApiUrl, getAllPositionsByAuthority, getSolautoManagedPositions } from "../../src/utils";
|
29
30
|
import { PriorityFeeSetting } from "../../src/types";
|
30
31
|
import { buildIronforgeApiUrl, TransactionManagerStatuses } from "../../dist";
|
31
32
|
|
@@ -48,20 +49,20 @@ describe("Solauto Marginfi tests", async () => {
|
|
48
49
|
const supplyDecimals = 6;
|
49
50
|
const debtDecimals = 6;
|
50
51
|
|
51
|
-
await client.initialize({
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
});
|
63
|
-
|
64
|
-
|
52
|
+
// await client.initialize({
|
53
|
+
// signer,
|
54
|
+
// positionId,
|
55
|
+
// authority: new PublicKey("rC5dMP5dmSsfQ66rynzfFzuc122Eex9h1RJHVDkeH6D"),
|
56
|
+
// // new: true,
|
57
|
+
// // marginfiAccount: new PublicKey(
|
58
|
+
// // "4nNvUXF5YqHFcH2nGweSiuvy1ct7V5FXfoCLKFYUN36z"
|
59
|
+
// // ),
|
60
|
+
// // marginfiGroup: new PublicKey("G1rt3EpQ43K3bY457rhukQGRAo2QxydFAGRKqnjKzyr5"),
|
61
|
+
// // supplyMint: new PublicKey("3B5wuUrMEi5yATD7on46hKfej3pfmd7t1RKgrsN3pump"),
|
62
|
+
// // debtMint: new PublicKey(USDC),
|
63
|
+
// });
|
64
|
+
|
65
|
+
console.log(await getSolautoManagedPositions(client.umi, new PublicKey("5UqsR2PGzbP8pGPbXEeXx86Gjz2N2UFBAuFZUSVydAEe"), PositionType.Leverage));
|
65
66
|
|
66
67
|
const transactionItems: TransactionItem[] = [];
|
67
68
|
// const settingParams: SolautoSettingsParametersInpArgs = {
|
@@ -169,15 +170,43 @@ describe("Solauto Marginfi tests", async () => {
|
|
169
170
|
// );
|
170
171
|
|
171
172
|
transactionItems.push(
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
173
|
+
new TransactionItem(
|
174
|
+
async () => ({
|
175
|
+
tx: transactionBuilder()
|
176
|
+
.add(
|
177
|
+
client.protocolInteraction(
|
178
|
+
solautoAction("Withdraw", [
|
179
|
+
{ __kind: "Some", fields: [toBaseUnit(0.01, 9)] },
|
180
|
+
])
|
181
|
+
)
|
182
|
+
)
|
183
|
+
}),
|
184
|
+
"withdraw"
|
185
|
+
)
|
186
|
+
);
|
187
|
+
|
188
|
+
transactionItems.push(
|
189
|
+
new TransactionItem(
|
190
|
+
async () => ({
|
191
|
+
tx: transactionBuilder()
|
192
|
+
.add(
|
193
|
+
client.protocolInteraction(
|
194
|
+
solautoAction("Withdraw", [
|
195
|
+
{ __kind: "Some", fields: [toBaseUnit(0.01, 9)] },
|
196
|
+
])
|
197
|
+
)
|
198
|
+
)
|
199
|
+
.add(
|
200
|
+
client.protocolInteraction(
|
201
|
+
solautoAction("Withdraw", [
|
202
|
+
{ __kind: "Some", fields: [toBaseUnit(300, 9)] },
|
203
|
+
])
|
204
|
+
)
|
205
|
+
)
|
206
|
+
}),
|
207
|
+
"withdraw"
|
208
|
+
)
|
209
|
+
);
|
181
210
|
|
182
211
|
// transactionItems.push(
|
183
212
|
// new TransactionItem(
|
@@ -188,16 +217,18 @@ describe("Solauto Marginfi tests", async () => {
|
|
188
217
|
// )
|
189
218
|
// );
|
190
219
|
|
191
|
-
const temp = (statuses: TransactionManagerStatuses) =>
|
220
|
+
// const temp = (statuses: TransactionManagerStatuses) =>
|
221
|
+
// console.log(statuses);
|
192
222
|
|
193
|
-
const statuses = await new TransactionsManager(
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
223
|
+
// const statuses = await new TransactionsManager(
|
224
|
+
// client,
|
225
|
+
// // temp,
|
226
|
+
// undefined,
|
227
|
+
// !payForTransactions ? "only-simulate" : "normal",
|
228
|
+
// PriorityFeeSetting.Low,
|
229
|
+
// true
|
230
|
+
// ).clientSend(transactionItems);
|
200
231
|
|
201
|
-
console.log(statuses);
|
232
|
+
// console.log(statuses);
|
202
233
|
});
|
203
234
|
});
|