Skip to content

Commit 74e9b6a

Browse files
committed
feat: improve tx batching
1 parent 7831782 commit 74e9b6a

File tree

32 files changed

+829
-197
lines changed

32 files changed

+829
-197
lines changed

features/defi-wrapper/defi-wrapper-factory.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ export const finalizePoolCreation = async (
101101
});
102102

103103
if (!finalizeResult.receipt || !finalizeResult.tx) {
104-
logInfo('Transaction has been sent');
104+
logInfo(
105+
'Transaction has been sent. Use "log-finalizing-pool-data" command to get the Pool data after the transaction is signed and executed',
106+
);
105107
return;
106108
}
107109

features/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export * from './lazy-oracle.js';
1313
export * from './defi-wrapper/index.js';
1414
export * from './dev-tools/index.js';
1515
export * from './metrics.js';
16+
export * from './with-report.js';

features/mint-burn/allowance.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { formatEther } from 'viem';
1+
import { formatEther, Hex, TransactionReceipt } from 'viem';
22

33
import {
44
getStethContract,
@@ -7,26 +7,31 @@ import {
77
} from 'contracts';
88
import { getAccount } from 'providers';
99
import {
10-
callReadMethod,
1110
callReadMethodSilent,
1211
callWriteMethodWithReceipt,
1312
confirmOperation,
1413
logInfo,
14+
PopulatedTx,
1515
} from 'utils';
1616

1717
export const checkAllowance = async (
1818
contract: DashboardContract,
1919
amount: bigint,
2020
token: 'steth' | 'wsteth' | 'shares',
21-
) => {
21+
populateTx?: boolean,
22+
): Promise<{
23+
receipt?: TransactionReceipt;
24+
tx?: Hex;
25+
data?: PopulatedTx;
26+
} | void> => {
2227
const accountAddress = (await getAccount()).address;
2328
const isShares = token === 'shares';
2429
let currentAmount = amount;
2530

2631
if (token === 'steth' || isShares) {
2732
const stethContract = await getStethContract();
2833

29-
const allowance = await callReadMethod(stethContract, 'allowance', [
34+
const allowance = await callReadMethodSilent(stethContract, 'allowance', [
3035
accountAddress,
3136
contract.address,
3237
]);
@@ -46,19 +51,21 @@ export const checkAllowance = async (
4651
);
4752
if (!confirm) throw new Error('Allowance not set');
4853

49-
await callWriteMethodWithReceipt({
54+
return await callWriteMethodWithReceipt({
5055
contract: stethContract,
5156
methodName: 'approve',
5257
payload: [contract.address, currentAmount],
58+
populateTx,
5359
});
5460
}
5561
} else {
5662
const wstethContract = await getWstethContract();
5763

58-
const wstethAllowance = await callReadMethod(wstethContract, 'allowance', [
59-
accountAddress,
60-
accountAddress,
61-
]);
64+
const wstethAllowance = await callReadMethodSilent(
65+
wstethContract,
66+
'allowance',
67+
[accountAddress, contract.address],
68+
);
6269
if (wstethAllowance < amount) {
6370
logInfo('Insufficient allowance');
6471

@@ -67,10 +74,11 @@ export const checkAllowance = async (
6774
);
6875
if (!confirm) throw new Error('Allowance not set');
6976

70-
await callWriteMethodWithReceipt({
77+
return await callWriteMethodWithReceipt({
7178
contract: wstethContract,
7279
methodName: 'approve',
7380
payload: [contract.address, amount],
81+
populateTx,
7482
});
7583
}
7684
}

features/mint-burn/burn-shares.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
fetchAndCalculateVaultHealthWithNewValue,
66
showSpinner,
77
confirmBurn,
8-
callWriteMethodWithReceipt,
8+
PopulatedTx,
9+
callWriteMethodWithCalls,
910
} from 'utils';
1011
import { checkLiabilityShares } from 'features';
1112

@@ -14,6 +15,7 @@ export const burnShares = async (
1415
amountOfShares: bigint,
1516
vault: Address,
1617
method: 'burnShares' | 'burnWstETH',
18+
populatedAllowance?: PopulatedTx,
1719
) => {
1820
const type = method === 'burnShares' ? 'shares' : 'wstETH';
1921

@@ -55,9 +57,10 @@ export const burnShares = async (
5557
});
5658
if (!confirm) return;
5759

58-
await callWriteMethodWithReceipt({
60+
await callWriteMethodWithCalls({
5961
contract,
6062
methodName: method,
6163
payload: [amountOfShares],
64+
calls: [...(populatedAllowance ? [populatedAllowance] : [])],
6265
});
6366
};

features/mint-burn/burn-steth.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import {
55
fetchAndCalculateVaultHealthWithNewValue,
66
showSpinner,
77
confirmBurn,
8-
callWriteMethodWithReceipt,
98
callReadMethodSilent,
9+
PopulatedTx,
10+
callWriteMethodWithCalls,
1011
} from 'utils';
1112
import { checkLiabilityShares } from 'features';
1213

1314
export const burnSteth = async (
1415
contract: DashboardContract,
1516
amountOfSteth: bigint,
1617
vault: Address,
18+
populatedAllowance?: PopulatedTx,
1719
) => {
1820
const stethContract = await getStethContract();
1921
const amountOfShares = await callReadMethodSilent(
@@ -60,9 +62,10 @@ export const burnSteth = async (
6062
});
6163
if (!confirm) return;
6264

63-
await callWriteMethodWithReceipt({
65+
await callWriteMethodWithCalls({
6466
contract,
6567
methodName: 'burnStETH',
6668
payload: [amountOfSteth],
69+
calls: [...(populatedAllowance ? [populatedAllowance] : [])],
6770
});
6871
};

features/mint-burn/mint-shares.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import {
55
fetchAndCalculateVaultHealthWithNewValue,
66
showSpinner,
77
confirmMint,
8-
callWriteMethodWithReceipt,
98
} from 'utils';
10-
import { checkIsReportFresh, checkMintingCapacity } from 'features';
9+
import {
10+
callWriteMethodsWithReportFresh,
11+
checkMintingCapacity,
12+
} from 'features';
1113

1214
export const mintShares = async (
1315
contract: DashboardContract,
@@ -18,9 +20,6 @@ export const mintShares = async (
1820
) => {
1921
const type = method === 'mintShares' ? 'shares' : 'wstETH';
2022

21-
const isReportFresh = await checkIsReportFresh(vault);
22-
if (!isReportFresh) return;
23-
2423
const isMintingCapacityOk = await checkMintingCapacity(
2524
contract,
2625
amountOfShares,
@@ -60,7 +59,8 @@ export const mintShares = async (
6059
});
6160
if (!confirm) return;
6261

63-
await callWriteMethodWithReceipt({
62+
await callWriteMethodsWithReportFresh({
63+
vault,
6464
contract,
6565
methodName: method,
6666
payload: [recipient, amountOfShares],

features/mint-burn/mint-steth.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import {
55
fetchAndCalculateVaultHealthWithNewValue,
66
showSpinner,
77
confirmMint,
8-
callWriteMethodWithReceipt,
98
callReadMethodSilent,
109
} from 'utils';
11-
import { checkIsReportFresh, checkMintingCapacity } from 'features';
10+
import {
11+
callWriteMethodsWithReportFresh,
12+
checkMintingCapacity,
13+
} from 'features';
1214

1315
export const mintSteth = async (
1416
contract: DashboardContract,
@@ -23,9 +25,6 @@ export const mintSteth = async (
2325
[amountOfSteth],
2426
);
2527

26-
const isReportFresh = await checkIsReportFresh(vault);
27-
if (!isReportFresh) return;
28-
2928
const isMintingCapacityOk = await checkMintingCapacity(
3029
contract,
3130
amountOfShares,
@@ -65,7 +64,8 @@ export const mintSteth = async (
6564
});
6665
if (!confirm) return;
6766

68-
await callWriteMethodWithReceipt({
67+
await callWriteMethodsWithReportFresh({
68+
vault,
6969
contract,
7070
methodName: 'mintStETH',
7171
payload: [recipient, amountOfSteth],

features/utils/liability-shares.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { formatEther } from 'viem';
12
import { DashboardContract } from 'contracts';
23
import { callReadMethodSilent, logError } from 'utils';
34

@@ -11,7 +12,9 @@ export const checkLiabilityShares = async (
1112
);
1213

1314
if (amountOfShares > liabilityShares) {
14-
logError('Cannot burn more shares than the liability shares');
15+
logError(
16+
`Cannot burn more shares than the liability shares (Liability shares: ${formatEther(liabilityShares)}, Amount of shares to burn: ${formatEther(amountOfShares)})`,
17+
);
1518
return false;
1619
}
1720

features/utils/report-fresh.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
confirmOperation,
77
submitReport,
88
logInfo,
9+
PopulatedTx,
910
} from 'utils';
1011

1112
const checkIsDisconnected = async (vault: Address) => {
@@ -28,11 +29,17 @@ const checkIsDisconnected = async (vault: Address) => {
2829
return false;
2930
};
3031

31-
export const checkIsReportFresh = async (vault: Address) => {
32+
export const checkIsReportFresh = async ({
33+
vault,
34+
populateTx = false,
35+
}: {
36+
vault: Address;
37+
populateTx?: boolean;
38+
}): Promise<{ isFresh: boolean; data?: PopulatedTx }> => {
3239
const vaultHubContract = await getVaultHubContract();
3340
const isDisconnected = await checkIsDisconnected(vault);
3441

35-
if (isDisconnected) return true;
42+
if (isDisconnected) return { isFresh: true, data: undefined };
3643

3744
const isReportFresh = await callReadMethodSilent(
3845
vaultHubContract,
@@ -45,16 +52,16 @@ export const checkIsReportFresh = async (vault: Address) => {
4552
const confirm = await confirmOperation(
4653
'Do you want to submit a fresh report?',
4754
);
48-
if (!confirm) return false;
55+
if (!confirm) return { isFresh: false, data: undefined };
4956

50-
const isReportSubmitted = await submitReport({ vault });
57+
const result = await submitReport({ vault, populateTx });
5158

52-
return isReportSubmitted;
59+
return result;
5360
}
5461

5562
logInfo('The report is fresh');
5663

57-
return isReportFresh;
64+
return { isFresh: true, data: undefined };
5865
};
5966

6067
export const reportFreshWarning = async (vault: Address): Promise<boolean> => {

0 commit comments

Comments
 (0)