@octaflowlabs/onchain-sdk 1.2.2 → 1.3.0
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/blockchain/buildUnsignedTransferTx.d.ts +8 -3
- package/dist/blockchain/buildUnsignedTransferTx.js +50 -103
- package/dist/blockchain/estimateTransaction.d.ts +2 -0
- package/dist/blockchain/estimateTransaction.js +29 -0
- package/dist/blockchain/prepareTransaction.d.ts +2 -0
- package/dist/blockchain/prepareTransaction.js +43 -0
- package/dist/cjs/blockchain/buildUnsignedTransferTx.d.ts +8 -3
- package/dist/cjs/blockchain/buildUnsignedTransferTx.js +51 -103
- package/dist/cjs/blockchain/estimateTransaction.d.ts +2 -0
- package/dist/cjs/blockchain/estimateTransaction.js +33 -0
- package/dist/cjs/blockchain/prepareTransaction.d.ts +2 -0
- package/dist/cjs/blockchain/prepareTransaction.js +47 -0
- package/dist/cjs/index.d.ts +4 -2
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/types/common.d.ts +42 -19
- package/dist/cjs/utils/getShortenTxHash.d.ts +2 -2
- package/dist/cjs/utils/getShortenTxHash.js +6 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/types/common.d.ts +42 -19
- package/dist/utils/getShortenTxHash.d.ts +2 -2
- package/dist/utils/getShortenTxHash.js +6 -6
- package/package.json +1 -1
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
1
|
+
import { BuildBaseUnsignedTransferTxParams, BuildMaxNativeTransferTxOptions, BuildUnsignedTransferTxOptions, PrepareTransactionResult } from '../types/common';
|
|
2
|
+
export declare const buildBaseUnsignedTransferTx: ({ recipientAddress, value, tokenAddress, tokenDecimals, }: BuildBaseUnsignedTransferTxParams) => {
|
|
3
|
+
to: string;
|
|
4
|
+
data: string;
|
|
5
|
+
value: bigint;
|
|
6
|
+
};
|
|
7
|
+
export declare const buildUnsignedTransferTx: (options: BuildUnsignedTransferTxOptions) => Promise<PrepareTransactionResult>;
|
|
8
|
+
export declare const buildMaxNativeTransferTx: (options: BuildMaxNativeTransferTxOptions) => Promise<string>;
|
|
@@ -1,97 +1,46 @@
|
|
|
1
1
|
/** npm imports */
|
|
2
|
-
import { Interface, formatUnits, parseUnits } from 'ethers';
|
|
2
|
+
import { Interface, formatUnits, parseEther, parseUnits } from 'ethers';
|
|
3
3
|
/** local imports */
|
|
4
4
|
import { getProvider } from './getProvider';
|
|
5
|
-
import {
|
|
5
|
+
import { prepareTransaction } from './prepareTransaction';
|
|
6
|
+
export const buildBaseUnsignedTransferTx = ({ recipientAddress, value, tokenAddress, tokenDecimals, }) => {
|
|
7
|
+
const isNative = !tokenAddress ||
|
|
8
|
+
tokenAddress.toLowerCase() === '0x0000000000000000000000000000000000000000' ||
|
|
9
|
+
tokenAddress.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
|
|
10
|
+
if (!isNative) {
|
|
11
|
+
const erc20Interface = new Interface(['function transfer(address to, uint256 amount)']);
|
|
12
|
+
const decimals = tokenDecimals ?? 18;
|
|
13
|
+
const amountParsed = parseUnits(value, decimals);
|
|
14
|
+
return {
|
|
15
|
+
to: tokenAddress,
|
|
16
|
+
data: erc20Interface.encodeFunctionData('transfer', [recipientAddress, amountParsed]),
|
|
17
|
+
value: 0n,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
to: recipientAddress,
|
|
22
|
+
data: '0x',
|
|
23
|
+
value: parseEther(value),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
6
26
|
export const buildUnsignedTransferTx = async (options) => {
|
|
7
27
|
const provider = getProvider(options.rpcUrl, options.chainId);
|
|
8
28
|
if (!provider)
|
|
9
29
|
throw new Error('Could not create provider with given rpcUrl and chainId');
|
|
10
30
|
try {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
options.
|
|
14
|
-
options.tokenAddress
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const decimals = options.tokenDecimals ?? 18;
|
|
23
|
-
if (!options.value)
|
|
24
|
-
throw new Error('Value is required for token transfer');
|
|
25
|
-
const amountParsed = parseUnits(options.value, decimals);
|
|
26
|
-
unsignedTx = {
|
|
27
|
-
...unsignedTx,
|
|
28
|
-
data: erc20Interface.encodeFunctionData('transfer', [options.toAddress, amountParsed]),
|
|
29
|
-
value: 0n,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
if (!options.value)
|
|
34
|
-
throw new Error('Native transfer requires value');
|
|
35
|
-
unsignedTx = {
|
|
36
|
-
to: options.toAddress,
|
|
37
|
-
data: '0x',
|
|
38
|
-
value: parseUnits(options.value, 18),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
if (options.chainId)
|
|
42
|
-
unsignedTx.chainId = options.chainId;
|
|
43
|
-
const nonce = await provider.getTransactionCount(options.fromAddress, 'pending');
|
|
44
|
-
const estimateGas = await estimateGasLimitFromProvider({
|
|
45
|
-
provider: provider,
|
|
46
|
-
unsignedTx,
|
|
47
|
-
walletAddress: options.fromAddress,
|
|
31
|
+
const baseUnsignedTx = buildBaseUnsignedTransferTx({
|
|
32
|
+
recipientAddress: options.toAddress,
|
|
33
|
+
value: options.value ?? '0',
|
|
34
|
+
tokenAddress: options.tokenAddress,
|
|
35
|
+
tokenDecimals: options.tokenDecimals,
|
|
36
|
+
});
|
|
37
|
+
return prepareTransaction({
|
|
38
|
+
rpcUrl: options.rpcUrl,
|
|
39
|
+
chainId: options.chainId ?? Number((await provider.getNetwork()).chainId),
|
|
40
|
+
tx: baseUnsignedTx,
|
|
41
|
+
fromAddress: options.fromAddress,
|
|
48
42
|
defaultGasLimit: options.defaultGasLimit,
|
|
49
43
|
});
|
|
50
|
-
const unsignedTxToReturn = {
|
|
51
|
-
from: options.fromAddress,
|
|
52
|
-
to: unsignedTx.to,
|
|
53
|
-
data: unsignedTx.data,
|
|
54
|
-
value: unsignedTx.value?.toString(),
|
|
55
|
-
gasLimit: estimateGas.gasLimit.toString(),
|
|
56
|
-
chainId: unsignedTx.chainId,
|
|
57
|
-
nonce,
|
|
58
|
-
maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
|
|
59
|
-
maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
|
|
60
|
-
};
|
|
61
|
-
if (estimateGas.feeData.gasPrice)
|
|
62
|
-
unsignedTxToReturn.gasPrice = estimateGas.feeData.gasPrice.toString();
|
|
63
|
-
const gasReserve = estimateGas.feeData.maxFeePerGas
|
|
64
|
-
? estimateGas.gasLimit * estimateGas.feeData.maxFeePerGas
|
|
65
|
-
: estimateGas.feeData.gasPrice
|
|
66
|
-
? estimateGas.gasLimit * estimateGas.feeData.gasPrice
|
|
67
|
-
: undefined;
|
|
68
|
-
try {
|
|
69
|
-
await provider.call({
|
|
70
|
-
from: options.fromAddress,
|
|
71
|
-
to: unsignedTx.to,
|
|
72
|
-
data: unsignedTx.data,
|
|
73
|
-
value: unsignedTx.value,
|
|
74
|
-
gasLimit: estimateGas.gasLimit,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
throw new Error('Transaction would revert, provider call unsuccessful: ' + error.message || error);
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
unsignedTx: unsignedTxToReturn,
|
|
82
|
-
nonce,
|
|
83
|
-
gasEstimated: estimateGas.gasEstimated.toString(),
|
|
84
|
-
gasLimit: estimateGas.gasLimit.toString(),
|
|
85
|
-
gasReserve: gasReserve?.toString(),
|
|
86
|
-
bufferPercentage: estimateGas.bufferPercentage,
|
|
87
|
-
feeData: {
|
|
88
|
-
maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
|
|
89
|
-
maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
|
|
90
|
-
gasPrice: estimateGas.feeData.gasPrice?.toString(),
|
|
91
|
-
},
|
|
92
|
-
// suggestedGasFees: estimateGas.suggestedGasFees,
|
|
93
|
-
// humanReadableFees: humanReadableGasEstimation,
|
|
94
|
-
};
|
|
95
44
|
}
|
|
96
45
|
catch (error) {
|
|
97
46
|
console.error('Error building unsigned transfer transaction:', error);
|
|
@@ -99,31 +48,29 @@ export const buildUnsignedTransferTx = async (options) => {
|
|
|
99
48
|
}
|
|
100
49
|
};
|
|
101
50
|
export const buildMaxNativeTransferTx = async (options) => {
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const provisionalTx = await
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
51
|
+
const provider = getProvider(options.rpcUrl, options.chainId);
|
|
52
|
+
if (!provider)
|
|
53
|
+
throw new Error('Could not create provider with given rpcUrl and chainId');
|
|
54
|
+
const network = await provider.getNetwork();
|
|
55
|
+
const chainId = options.chainId ?? Number(network.chainId);
|
|
56
|
+
const provisionalTx = await prepareTransaction({
|
|
57
|
+
rpcUrl: options.rpcUrl,
|
|
58
|
+
chainId,
|
|
59
|
+
tx: {
|
|
60
|
+
to: options.toAddress,
|
|
61
|
+
data: '0x',
|
|
62
|
+
value: 0n,
|
|
63
|
+
},
|
|
64
|
+
fromAddress: options.fromAddress,
|
|
65
|
+
defaultGasLimit: options.defaultGasLimit,
|
|
111
66
|
});
|
|
112
67
|
if (!provisionalTx.gasReserve)
|
|
113
68
|
throw new Error('Could not determine gas reserve for max send');
|
|
114
|
-
const balanceWei =
|
|
69
|
+
const balanceWei = parseEther(options.balance);
|
|
115
70
|
const gasReserveWei = BigInt(provisionalTx.gasReserve);
|
|
116
71
|
const sendableWei = balanceWei - gasReserveWei;
|
|
117
72
|
if (sendableWei <= 0n)
|
|
118
73
|
throw new Error('Insufficient balance to cover gas reserve');
|
|
119
74
|
const sendableValue = formatUnits(sendableWei, 18);
|
|
120
|
-
|
|
121
|
-
...options,
|
|
122
|
-
value: sendableValue,
|
|
123
|
-
tokenAddress: options.tokenAddress,
|
|
124
|
-
});
|
|
125
|
-
return {
|
|
126
|
-
...finalTx,
|
|
127
|
-
sendableValue,
|
|
128
|
-
};
|
|
75
|
+
return sendableValue;
|
|
129
76
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** local imports */
|
|
2
|
+
import { estimateGasLimitFromProvider } from './estimateGasLimitFromProvider';
|
|
3
|
+
import { getProvider } from './getProvider';
|
|
4
|
+
import { formatUnits } from 'ethers';
|
|
5
|
+
export const estimateTransaction = async ({ rpcUrl, chainId, tx, fromAddress, defaultGasLimit, }) => {
|
|
6
|
+
const provider = getProvider(rpcUrl, chainId);
|
|
7
|
+
if (!provider)
|
|
8
|
+
throw new Error('Could not get provider');
|
|
9
|
+
const estimateGas = await estimateGasLimitFromProvider({
|
|
10
|
+
provider,
|
|
11
|
+
unsignedTx: tx,
|
|
12
|
+
walletAddress: fromAddress,
|
|
13
|
+
defaultGasLimit: defaultGasLimit || 21000n,
|
|
14
|
+
});
|
|
15
|
+
const gasReserve = estimateGas.feeData.maxFeePerGas
|
|
16
|
+
? estimateGas.gasLimit * estimateGas.feeData.maxFeePerGas
|
|
17
|
+
: estimateGas.feeData.gasPrice
|
|
18
|
+
? estimateGas.gasLimit * estimateGas.feeData.gasPrice
|
|
19
|
+
: undefined;
|
|
20
|
+
const humanReadableGasReserve = gasReserve ? `${formatUnits(gasReserve, 18)}` : 'N/A';
|
|
21
|
+
return {
|
|
22
|
+
gasLimit: estimateGas.gasLimit,
|
|
23
|
+
gasEstimated: estimateGas.gasEstimated,
|
|
24
|
+
feeData: estimateGas.feeData,
|
|
25
|
+
gasReserve,
|
|
26
|
+
humanReadableGasReserve,
|
|
27
|
+
bufferPercentage: estimateGas.bufferPercentage,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** local imports */
|
|
2
|
+
import { estimateTransaction } from './estimateTransaction';
|
|
3
|
+
import { getProvider } from './getProvider';
|
|
4
|
+
export const prepareTransaction = async ({ rpcUrl, chainId, tx, fromAddress, defaultGasLimit, }) => {
|
|
5
|
+
const provider = getProvider(rpcUrl, chainId);
|
|
6
|
+
if (!provider)
|
|
7
|
+
throw new Error('Could not create provider');
|
|
8
|
+
const estimation = await estimateTransaction({
|
|
9
|
+
rpcUrl,
|
|
10
|
+
chainId,
|
|
11
|
+
tx,
|
|
12
|
+
fromAddress,
|
|
13
|
+
defaultGasLimit,
|
|
14
|
+
});
|
|
15
|
+
const nonce = await provider.getTransactionCount(fromAddress, 'pending');
|
|
16
|
+
const preparedTx = {
|
|
17
|
+
from: fromAddress,
|
|
18
|
+
to: tx.to,
|
|
19
|
+
data: tx.data,
|
|
20
|
+
value: tx.value,
|
|
21
|
+
gasLimit: estimation.gasLimit,
|
|
22
|
+
chainId,
|
|
23
|
+
nonce,
|
|
24
|
+
maxFeePerGas: estimation.feeData.maxFeePerGas,
|
|
25
|
+
maxPriorityFeePerGas: estimation.feeData.maxPriorityFeePerGas,
|
|
26
|
+
};
|
|
27
|
+
if (estimation.feeData.gasPrice)
|
|
28
|
+
preparedTx.gasPrice = estimation.feeData.gasPrice;
|
|
29
|
+
return {
|
|
30
|
+
unsignedTx: preparedTx,
|
|
31
|
+
nonce,
|
|
32
|
+
gasEstimated: estimation.gasEstimated,
|
|
33
|
+
gasLimit: estimation.gasLimit,
|
|
34
|
+
gasReserve: estimation.gasReserve,
|
|
35
|
+
bufferPercentage: estimation.bufferPercentage,
|
|
36
|
+
feeData: {
|
|
37
|
+
maxFeePerGas: estimation.feeData.maxFeePerGas,
|
|
38
|
+
maxPriorityFeePerGas: estimation.feeData.maxPriorityFeePerGas,
|
|
39
|
+
gasPrice: estimation.feeData.gasPrice,
|
|
40
|
+
},
|
|
41
|
+
humanReadableGasReserve: estimation.humanReadableGasReserve,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
1
|
+
import { BuildBaseUnsignedTransferTxParams, BuildMaxNativeTransferTxOptions, BuildUnsignedTransferTxOptions, PrepareTransactionResult } from '../types/common';
|
|
2
|
+
export declare const buildBaseUnsignedTransferTx: ({ recipientAddress, value, tokenAddress, tokenDecimals, }: BuildBaseUnsignedTransferTxParams) => {
|
|
3
|
+
to: string;
|
|
4
|
+
data: string;
|
|
5
|
+
value: bigint;
|
|
6
|
+
};
|
|
7
|
+
export declare const buildUnsignedTransferTx: (options: BuildUnsignedTransferTxOptions) => Promise<PrepareTransactionResult>;
|
|
8
|
+
export declare const buildMaxNativeTransferTx: (options: BuildMaxNativeTransferTxOptions) => Promise<string>;
|
|
@@ -1,100 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildMaxNativeTransferTx = exports.buildUnsignedTransferTx = void 0;
|
|
3
|
+
exports.buildMaxNativeTransferTx = exports.buildUnsignedTransferTx = exports.buildBaseUnsignedTransferTx = void 0;
|
|
4
4
|
/** npm imports */
|
|
5
5
|
const ethers_1 = require("ethers");
|
|
6
6
|
/** local imports */
|
|
7
7
|
const getProvider_1 = require("./getProvider");
|
|
8
|
-
const
|
|
8
|
+
const prepareTransaction_1 = require("./prepareTransaction");
|
|
9
|
+
const buildBaseUnsignedTransferTx = ({ recipientAddress, value, tokenAddress, tokenDecimals, }) => {
|
|
10
|
+
const isNative = !tokenAddress ||
|
|
11
|
+
tokenAddress.toLowerCase() === '0x0000000000000000000000000000000000000000' ||
|
|
12
|
+
tokenAddress.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
|
|
13
|
+
if (!isNative) {
|
|
14
|
+
const erc20Interface = new ethers_1.Interface(['function transfer(address to, uint256 amount)']);
|
|
15
|
+
const decimals = tokenDecimals ?? 18;
|
|
16
|
+
const amountParsed = (0, ethers_1.parseUnits)(value, decimals);
|
|
17
|
+
return {
|
|
18
|
+
to: tokenAddress,
|
|
19
|
+
data: erc20Interface.encodeFunctionData('transfer', [recipientAddress, amountParsed]),
|
|
20
|
+
value: 0n,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
to: recipientAddress,
|
|
25
|
+
data: '0x',
|
|
26
|
+
value: (0, ethers_1.parseEther)(value),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.buildBaseUnsignedTransferTx = buildBaseUnsignedTransferTx;
|
|
9
30
|
const buildUnsignedTransferTx = async (options) => {
|
|
10
31
|
const provider = (0, getProvider_1.getProvider)(options.rpcUrl, options.chainId);
|
|
11
32
|
if (!provider)
|
|
12
33
|
throw new Error('Could not create provider with given rpcUrl and chainId');
|
|
13
34
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
options.
|
|
17
|
-
options.tokenAddress
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const decimals = options.tokenDecimals ?? 18;
|
|
26
|
-
if (!options.value)
|
|
27
|
-
throw new Error('Value is required for token transfer');
|
|
28
|
-
const amountParsed = (0, ethers_1.parseUnits)(options.value, decimals);
|
|
29
|
-
unsignedTx = {
|
|
30
|
-
...unsignedTx,
|
|
31
|
-
data: erc20Interface.encodeFunctionData('transfer', [options.toAddress, amountParsed]),
|
|
32
|
-
value: 0n,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
if (!options.value)
|
|
37
|
-
throw new Error('Native transfer requires value');
|
|
38
|
-
unsignedTx = {
|
|
39
|
-
to: options.toAddress,
|
|
40
|
-
data: '0x',
|
|
41
|
-
value: (0, ethers_1.parseUnits)(options.value, 18),
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
if (options.chainId)
|
|
45
|
-
unsignedTx.chainId = options.chainId;
|
|
46
|
-
const nonce = await provider.getTransactionCount(options.fromAddress, 'pending');
|
|
47
|
-
const estimateGas = await (0, estimateGasLimitFromProvider_1.estimateGasLimitFromProvider)({
|
|
48
|
-
provider: provider,
|
|
49
|
-
unsignedTx,
|
|
50
|
-
walletAddress: options.fromAddress,
|
|
35
|
+
const baseUnsignedTx = (0, exports.buildBaseUnsignedTransferTx)({
|
|
36
|
+
recipientAddress: options.toAddress,
|
|
37
|
+
value: options.value ?? '0',
|
|
38
|
+
tokenAddress: options.tokenAddress,
|
|
39
|
+
tokenDecimals: options.tokenDecimals,
|
|
40
|
+
});
|
|
41
|
+
return (0, prepareTransaction_1.prepareTransaction)({
|
|
42
|
+
rpcUrl: options.rpcUrl,
|
|
43
|
+
chainId: options.chainId ?? Number((await provider.getNetwork()).chainId),
|
|
44
|
+
tx: baseUnsignedTx,
|
|
45
|
+
fromAddress: options.fromAddress,
|
|
51
46
|
defaultGasLimit: options.defaultGasLimit,
|
|
52
47
|
});
|
|
53
|
-
const unsignedTxToReturn = {
|
|
54
|
-
from: options.fromAddress,
|
|
55
|
-
to: unsignedTx.to,
|
|
56
|
-
data: unsignedTx.data,
|
|
57
|
-
value: unsignedTx.value?.toString(),
|
|
58
|
-
gasLimit: estimateGas.gasLimit.toString(),
|
|
59
|
-
chainId: unsignedTx.chainId,
|
|
60
|
-
nonce,
|
|
61
|
-
maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
|
|
62
|
-
maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
|
|
63
|
-
};
|
|
64
|
-
if (estimateGas.feeData.gasPrice)
|
|
65
|
-
unsignedTxToReturn.gasPrice = estimateGas.feeData.gasPrice.toString();
|
|
66
|
-
const gasReserve = estimateGas.feeData.maxFeePerGas
|
|
67
|
-
? estimateGas.gasLimit * estimateGas.feeData.maxFeePerGas
|
|
68
|
-
: estimateGas.feeData.gasPrice
|
|
69
|
-
? estimateGas.gasLimit * estimateGas.feeData.gasPrice
|
|
70
|
-
: undefined;
|
|
71
|
-
try {
|
|
72
|
-
await provider.call({
|
|
73
|
-
from: options.fromAddress,
|
|
74
|
-
to: unsignedTx.to,
|
|
75
|
-
data: unsignedTx.data,
|
|
76
|
-
value: unsignedTx.value,
|
|
77
|
-
gasLimit: estimateGas.gasLimit,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
throw new Error('Transaction would revert, provider call unsuccessful: ' + error.message || error);
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
unsignedTx: unsignedTxToReturn,
|
|
85
|
-
nonce,
|
|
86
|
-
gasEstimated: estimateGas.gasEstimated.toString(),
|
|
87
|
-
gasLimit: estimateGas.gasLimit.toString(),
|
|
88
|
-
gasReserve: gasReserve?.toString(),
|
|
89
|
-
bufferPercentage: estimateGas.bufferPercentage,
|
|
90
|
-
feeData: {
|
|
91
|
-
maxFeePerGas: estimateGas.feeData.maxFeePerGas?.toString(),
|
|
92
|
-
maxPriorityFeePerGas: estimateGas.feeData.maxPriorityFeePerGas?.toString(),
|
|
93
|
-
gasPrice: estimateGas.feeData.gasPrice?.toString(),
|
|
94
|
-
},
|
|
95
|
-
// suggestedGasFees: estimateGas.suggestedGasFees,
|
|
96
|
-
// humanReadableFees: humanReadableGasEstimation,
|
|
97
|
-
};
|
|
98
48
|
}
|
|
99
49
|
catch (error) {
|
|
100
50
|
console.error('Error building unsigned transfer transaction:', error);
|
|
@@ -103,32 +53,30 @@ const buildUnsignedTransferTx = async (options) => {
|
|
|
103
53
|
};
|
|
104
54
|
exports.buildUnsignedTransferTx = buildUnsignedTransferTx;
|
|
105
55
|
const buildMaxNativeTransferTx = async (options) => {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const provisionalTx = await (0,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
56
|
+
const provider = (0, getProvider_1.getProvider)(options.rpcUrl, options.chainId);
|
|
57
|
+
if (!provider)
|
|
58
|
+
throw new Error('Could not create provider with given rpcUrl and chainId');
|
|
59
|
+
const network = await provider.getNetwork();
|
|
60
|
+
const chainId = options.chainId ?? Number(network.chainId);
|
|
61
|
+
const provisionalTx = await (0, prepareTransaction_1.prepareTransaction)({
|
|
62
|
+
rpcUrl: options.rpcUrl,
|
|
63
|
+
chainId,
|
|
64
|
+
tx: {
|
|
65
|
+
to: options.toAddress,
|
|
66
|
+
data: '0x',
|
|
67
|
+
value: 0n,
|
|
68
|
+
},
|
|
69
|
+
fromAddress: options.fromAddress,
|
|
70
|
+
defaultGasLimit: options.defaultGasLimit,
|
|
115
71
|
});
|
|
116
72
|
if (!provisionalTx.gasReserve)
|
|
117
73
|
throw new Error('Could not determine gas reserve for max send');
|
|
118
|
-
const balanceWei = (0, ethers_1.
|
|
74
|
+
const balanceWei = (0, ethers_1.parseEther)(options.balance);
|
|
119
75
|
const gasReserveWei = BigInt(provisionalTx.gasReserve);
|
|
120
76
|
const sendableWei = balanceWei - gasReserveWei;
|
|
121
77
|
if (sendableWei <= 0n)
|
|
122
78
|
throw new Error('Insufficient balance to cover gas reserve');
|
|
123
79
|
const sendableValue = (0, ethers_1.formatUnits)(sendableWei, 18);
|
|
124
|
-
|
|
125
|
-
...options,
|
|
126
|
-
value: sendableValue,
|
|
127
|
-
tokenAddress: options.tokenAddress,
|
|
128
|
-
});
|
|
129
|
-
return {
|
|
130
|
-
...finalTx,
|
|
131
|
-
sendableValue,
|
|
132
|
-
};
|
|
80
|
+
return sendableValue;
|
|
133
81
|
};
|
|
134
82
|
exports.buildMaxNativeTransferTx = buildMaxNativeTransferTx;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.estimateTransaction = void 0;
|
|
4
|
+
/** local imports */
|
|
5
|
+
const estimateGasLimitFromProvider_1 = require("./estimateGasLimitFromProvider");
|
|
6
|
+
const getProvider_1 = require("./getProvider");
|
|
7
|
+
const ethers_1 = require("ethers");
|
|
8
|
+
const estimateTransaction = async ({ rpcUrl, chainId, tx, fromAddress, defaultGasLimit, }) => {
|
|
9
|
+
const provider = (0, getProvider_1.getProvider)(rpcUrl, chainId);
|
|
10
|
+
if (!provider)
|
|
11
|
+
throw new Error('Could not get provider');
|
|
12
|
+
const estimateGas = await (0, estimateGasLimitFromProvider_1.estimateGasLimitFromProvider)({
|
|
13
|
+
provider,
|
|
14
|
+
unsignedTx: tx,
|
|
15
|
+
walletAddress: fromAddress,
|
|
16
|
+
defaultGasLimit: defaultGasLimit || 21000n,
|
|
17
|
+
});
|
|
18
|
+
const gasReserve = estimateGas.feeData.maxFeePerGas
|
|
19
|
+
? estimateGas.gasLimit * estimateGas.feeData.maxFeePerGas
|
|
20
|
+
: estimateGas.feeData.gasPrice
|
|
21
|
+
? estimateGas.gasLimit * estimateGas.feeData.gasPrice
|
|
22
|
+
: undefined;
|
|
23
|
+
const humanReadableGasReserve = gasReserve ? `${(0, ethers_1.formatUnits)(gasReserve, 18)}` : 'N/A';
|
|
24
|
+
return {
|
|
25
|
+
gasLimit: estimateGas.gasLimit,
|
|
26
|
+
gasEstimated: estimateGas.gasEstimated,
|
|
27
|
+
feeData: estimateGas.feeData,
|
|
28
|
+
gasReserve,
|
|
29
|
+
humanReadableGasReserve,
|
|
30
|
+
bufferPercentage: estimateGas.bufferPercentage,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
exports.estimateTransaction = estimateTransaction;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareTransaction = void 0;
|
|
4
|
+
/** local imports */
|
|
5
|
+
const estimateTransaction_1 = require("./estimateTransaction");
|
|
6
|
+
const getProvider_1 = require("./getProvider");
|
|
7
|
+
const prepareTransaction = async ({ rpcUrl, chainId, tx, fromAddress, defaultGasLimit, }) => {
|
|
8
|
+
const provider = (0, getProvider_1.getProvider)(rpcUrl, chainId);
|
|
9
|
+
if (!provider)
|
|
10
|
+
throw new Error('Could not create provider');
|
|
11
|
+
const estimation = await (0, estimateTransaction_1.estimateTransaction)({
|
|
12
|
+
rpcUrl,
|
|
13
|
+
chainId,
|
|
14
|
+
tx,
|
|
15
|
+
fromAddress,
|
|
16
|
+
defaultGasLimit,
|
|
17
|
+
});
|
|
18
|
+
const nonce = await provider.getTransactionCount(fromAddress, 'pending');
|
|
19
|
+
const preparedTx = {
|
|
20
|
+
from: fromAddress,
|
|
21
|
+
to: tx.to,
|
|
22
|
+
data: tx.data,
|
|
23
|
+
value: tx.value,
|
|
24
|
+
gasLimit: estimation.gasLimit,
|
|
25
|
+
chainId,
|
|
26
|
+
nonce,
|
|
27
|
+
maxFeePerGas: estimation.feeData.maxFeePerGas,
|
|
28
|
+
maxPriorityFeePerGas: estimation.feeData.maxPriorityFeePerGas,
|
|
29
|
+
};
|
|
30
|
+
if (estimation.feeData.gasPrice)
|
|
31
|
+
preparedTx.gasPrice = estimation.feeData.gasPrice;
|
|
32
|
+
return {
|
|
33
|
+
unsignedTx: preparedTx,
|
|
34
|
+
nonce,
|
|
35
|
+
gasEstimated: estimation.gasEstimated,
|
|
36
|
+
gasLimit: estimation.gasLimit,
|
|
37
|
+
gasReserve: estimation.gasReserve,
|
|
38
|
+
bufferPercentage: estimation.bufferPercentage,
|
|
39
|
+
feeData: {
|
|
40
|
+
maxFeePerGas: estimation.feeData.maxFeePerGas,
|
|
41
|
+
maxPriorityFeePerGas: estimation.feeData.maxPriorityFeePerGas,
|
|
42
|
+
gasPrice: estimation.feeData.gasPrice,
|
|
43
|
+
},
|
|
44
|
+
humanReadableGasReserve: estimation.humanReadableGasReserve,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
exports.prepareTransaction = prepareTransaction;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -5,12 +5,14 @@ export { ERC20_TOKEN_CONTRACT_ABI };
|
|
|
5
5
|
export { GAS_LIMIT_PER_TX_TYPE, MULTICALL3_ADDRESS } from './constants/constants';
|
|
6
6
|
export { NETWORKS_REGISTRY, NetworkField, NetworkRegistry } from './constants/NETWORKS_REGISTRY';
|
|
7
7
|
/** basic blockchain exports */
|
|
8
|
-
export { buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
|
|
8
|
+
export { buildBaseUnsignedTransferTx, buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
|
|
9
9
|
export { broadcastTransaction } from './blockchain/broadcastTransaction';
|
|
10
10
|
export { estimateGasLimitFromProvider } from './blockchain/estimateGasLimitFromProvider';
|
|
11
11
|
export { getProvider } from './blockchain/getProvider';
|
|
12
12
|
export { txStatus } from './blockchain/txStatus';
|
|
13
13
|
export { getBalance, getBalances } from './blockchain/getBalances';
|
|
14
|
+
export { estimateTransaction } from './blockchain/estimateTransaction';
|
|
15
|
+
export { prepareTransaction } from './blockchain/prepareTransaction';
|
|
14
16
|
/** services exports */
|
|
15
17
|
export { EvmWalletService, EvmGeneratedWallet, EvmDerivedWallet, } from './services/evm-wallet-core/evmWalletService';
|
|
16
18
|
export { EntropySource } from './services/evm-wallet-core/entropy';
|
|
@@ -24,4 +26,4 @@ export { formattedAmountForDisplay, parsedAmount } from './utils/formatAmount';
|
|
|
24
26
|
export { handleErrorMessages, errorMessagesForBroadcast, errorMessagesForGasLimitEstimation, } from './utils/handleErrorMessages';
|
|
25
27
|
export { normalizeAddress } from './utils/normalizeAddress';
|
|
26
28
|
/** types exports */
|
|
27
|
-
export { BroadcastTransactionOptions, BuildMaxNativeTransferTxOptions,
|
|
29
|
+
export { BroadcastTransactionOptions, BuildMaxNativeTransferTxOptions, BuildUnsignedTransferTxOptions, EstimateGasLimitFromProviderProps, GasEstimateResult, TxStatusOptions, BuildBaseUnsignedTransferTxParams, TxStatusResponse, EstimateTransactionOptions, EstimateTransactionResult, PrepareTransactionParams, PrepareTransactionResult, FormatAmountOptions, TransactionRequest, GetBalanceParams, GetBalancesParams, GetBalancesChainRequest, GetBalanceResult, ChainBalances, TokenBalance, ChainGroup, } from './types/common';
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.normalizeAddress = exports.errorMessagesForGasLimitEstimation = exports.errorMessagesForBroadcast = exports.handleErrorMessages = exports.parsedAmount = exports.formattedAmountForDisplay = exports.NATIVE_TOKENS = exports.transformBigInt = exports.getShortenData = exports.getShortenTransactionHashOrAddress = exports.signTransaction = exports.signMessage = exports.createWallet = exports.EvmWalletService = exports.getBalances = exports.getBalance = exports.txStatus = exports.getProvider = exports.estimateGasLimitFromProvider = exports.broadcastTransaction = exports.buildUnsignedTransferTx = exports.buildMaxNativeTransferTx = exports.NETWORKS_REGISTRY = exports.MULTICALL3_ADDRESS = exports.GAS_LIMIT_PER_TX_TYPE = exports.ERC20_TOKEN_CONTRACT_ABI = void 0;
|
|
6
|
+
exports.normalizeAddress = exports.errorMessagesForGasLimitEstimation = exports.errorMessagesForBroadcast = exports.handleErrorMessages = exports.parsedAmount = exports.formattedAmountForDisplay = exports.NATIVE_TOKENS = exports.transformBigInt = exports.getShortenData = exports.getShortenTransactionHashOrAddress = exports.signTransaction = exports.signMessage = exports.createWallet = exports.EvmWalletService = exports.prepareTransaction = exports.estimateTransaction = exports.getBalances = exports.getBalance = exports.txStatus = exports.getProvider = exports.estimateGasLimitFromProvider = exports.broadcastTransaction = exports.buildUnsignedTransferTx = exports.buildMaxNativeTransferTx = exports.buildBaseUnsignedTransferTx = exports.NETWORKS_REGISTRY = exports.MULTICALL3_ADDRESS = exports.GAS_LIMIT_PER_TX_TYPE = exports.ERC20_TOKEN_CONTRACT_ABI = void 0;
|
|
7
7
|
/** ABIs exports */
|
|
8
8
|
const ERC20_TOKEN_CONTRACT_ABI_1 = __importDefault(require("./ABIs/ERC20_TOKEN_CONTRACT_ABI"));
|
|
9
9
|
exports.ERC20_TOKEN_CONTRACT_ABI = ERC20_TOKEN_CONTRACT_ABI_1.default;
|
|
@@ -15,6 +15,7 @@ var NETWORKS_REGISTRY_1 = require("./constants/NETWORKS_REGISTRY");
|
|
|
15
15
|
Object.defineProperty(exports, "NETWORKS_REGISTRY", { enumerable: true, get: function () { return NETWORKS_REGISTRY_1.NETWORKS_REGISTRY; } });
|
|
16
16
|
/** basic blockchain exports */
|
|
17
17
|
var buildUnsignedTransferTx_1 = require("./blockchain/buildUnsignedTransferTx");
|
|
18
|
+
Object.defineProperty(exports, "buildBaseUnsignedTransferTx", { enumerable: true, get: function () { return buildUnsignedTransferTx_1.buildBaseUnsignedTransferTx; } });
|
|
18
19
|
Object.defineProperty(exports, "buildMaxNativeTransferTx", { enumerable: true, get: function () { return buildUnsignedTransferTx_1.buildMaxNativeTransferTx; } });
|
|
19
20
|
Object.defineProperty(exports, "buildUnsignedTransferTx", { enumerable: true, get: function () { return buildUnsignedTransferTx_1.buildUnsignedTransferTx; } });
|
|
20
21
|
var broadcastTransaction_1 = require("./blockchain/broadcastTransaction");
|
|
@@ -28,6 +29,10 @@ Object.defineProperty(exports, "txStatus", { enumerable: true, get: function ()
|
|
|
28
29
|
var getBalances_1 = require("./blockchain/getBalances");
|
|
29
30
|
Object.defineProperty(exports, "getBalance", { enumerable: true, get: function () { return getBalances_1.getBalance; } });
|
|
30
31
|
Object.defineProperty(exports, "getBalances", { enumerable: true, get: function () { return getBalances_1.getBalances; } });
|
|
32
|
+
var estimateTransaction_1 = require("./blockchain/estimateTransaction");
|
|
33
|
+
Object.defineProperty(exports, "estimateTransaction", { enumerable: true, get: function () { return estimateTransaction_1.estimateTransaction; } });
|
|
34
|
+
var prepareTransaction_1 = require("./blockchain/prepareTransaction");
|
|
35
|
+
Object.defineProperty(exports, "prepareTransaction", { enumerable: true, get: function () { return prepareTransaction_1.prepareTransaction; } });
|
|
31
36
|
/** services exports */
|
|
32
37
|
var evmWalletService_1 = require("./services/evm-wallet-core/evmWalletService");
|
|
33
38
|
Object.defineProperty(exports, "EvmWalletService", { enumerable: true, get: function () { return evmWalletService_1.EvmWalletService; } });
|
|
@@ -17,36 +17,59 @@ export interface GasEstimateResult {
|
|
|
17
17
|
gasPrice?: bigint;
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
+
export interface EstimateTransactionOptions {
|
|
21
|
+
rpcUrl: string;
|
|
22
|
+
chainId: number;
|
|
23
|
+
tx: TransactionRequest;
|
|
24
|
+
fromAddress: string;
|
|
25
|
+
defaultGasLimit?: bigint;
|
|
26
|
+
}
|
|
27
|
+
export interface PrepareTransactionParams extends EstimateTransactionOptions {
|
|
28
|
+
}
|
|
29
|
+
export interface EstimateTransactionResult {
|
|
30
|
+
gasLimit: bigint;
|
|
31
|
+
gasEstimated: bigint;
|
|
32
|
+
feeData: {
|
|
33
|
+
maxFeePerGas?: bigint;
|
|
34
|
+
maxPriorityFeePerGas?: bigint;
|
|
35
|
+
gasPrice?: bigint;
|
|
36
|
+
};
|
|
37
|
+
gasReserve?: bigint;
|
|
38
|
+
humanReadableGasReserve: string;
|
|
39
|
+
bufferPercentage: number;
|
|
40
|
+
}
|
|
41
|
+
export interface PrepareTransactionResult {
|
|
42
|
+
unsignedTx: TransactionRequest;
|
|
43
|
+
nonce: number;
|
|
44
|
+
gasEstimated: bigint;
|
|
45
|
+
gasLimit: bigint;
|
|
46
|
+
gasReserve?: bigint;
|
|
47
|
+
bufferPercentage: number;
|
|
48
|
+
feeData: {
|
|
49
|
+
maxFeePerGas?: bigint;
|
|
50
|
+
maxPriorityFeePerGas?: bigint;
|
|
51
|
+
gasPrice?: bigint;
|
|
52
|
+
};
|
|
53
|
+
humanReadableGasReserve: string;
|
|
54
|
+
}
|
|
55
|
+
export interface BuildBaseUnsignedTransferTxParams {
|
|
56
|
+
recipientAddress: string;
|
|
57
|
+
value: string;
|
|
58
|
+
tokenAddress?: string;
|
|
59
|
+
tokenDecimals?: number;
|
|
60
|
+
}
|
|
20
61
|
export interface BuildUnsignedTransferTxOptions {
|
|
21
62
|
fromAddress: string;
|
|
22
63
|
toAddress: string;
|
|
23
64
|
value?: string;
|
|
24
|
-
data?: string;
|
|
25
65
|
tokenAddress?: string;
|
|
26
66
|
tokenDecimals?: number;
|
|
27
67
|
rpcUrl: string;
|
|
28
68
|
chainId?: number;
|
|
29
69
|
defaultGasLimit: bigint;
|
|
30
70
|
}
|
|
31
|
-
export interface
|
|
32
|
-
unsignedTx: TransactionRequest;
|
|
33
|
-
nonce: number;
|
|
34
|
-
gasEstimated: string;
|
|
35
|
-
gasLimit: string;
|
|
36
|
-
gasReserve?: string;
|
|
37
|
-
bufferPercentage: number;
|
|
38
|
-
feeData: {
|
|
39
|
-
maxFeePerGas?: string;
|
|
40
|
-
maxPriorityFeePerGas?: string;
|
|
41
|
-
gasPrice?: string;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
export interface BuildMaxNativeTransferTxOptions extends Omit<BuildUnsignedTransferTxOptions, 'value' | 'tokenAddress' | 'tokenDecimals'> {
|
|
71
|
+
export interface BuildMaxNativeTransferTxOptions extends Omit<BuildUnsignedTransferTxOptions, 'value' | 'tokenDecimals'> {
|
|
45
72
|
balance: string;
|
|
46
|
-
tokenAddress?: string;
|
|
47
|
-
}
|
|
48
|
-
export interface BuildMaxNativeTransferTxResponse extends UnsignedTransferTxResponse {
|
|
49
|
-
sendableValue: string;
|
|
50
73
|
}
|
|
51
74
|
export interface BroadcastTransactionOptions {
|
|
52
75
|
signedTx: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const getShortenTransactionHashOrAddress: (txHashOrAddress: string) => string;
|
|
2
|
-
export declare const getShortenData: (data: string) => string;
|
|
1
|
+
export declare const getShortenTransactionHashOrAddress: (txHashOrAddress: string, firstPartLength?: number, lastPartLength?: number) => string;
|
|
2
|
+
export declare const getShortenData: (data: string, firstPartLength?: number, lastPartLength?: number) => string;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getShortenData = exports.getShortenTransactionHashOrAddress = void 0;
|
|
4
|
-
const getShortenTransactionHashOrAddress = (txHashOrAddress) => {
|
|
5
|
-
const firstCharacters = txHashOrAddress.substring(0,
|
|
6
|
-
const lastCharacters = txHashOrAddress.slice(-
|
|
4
|
+
const getShortenTransactionHashOrAddress = (txHashOrAddress, firstPartLength = 6, lastPartLength = 4) => {
|
|
5
|
+
const firstCharacters = txHashOrAddress.substring(0, firstPartLength);
|
|
6
|
+
const lastCharacters = txHashOrAddress.slice(-lastPartLength);
|
|
7
7
|
return `${firstCharacters}...${lastCharacters}`;
|
|
8
8
|
};
|
|
9
9
|
exports.getShortenTransactionHashOrAddress = getShortenTransactionHashOrAddress;
|
|
10
|
-
const getShortenData = (data) => {
|
|
11
|
-
const firstCharacters = data.substring(0,
|
|
12
|
-
const lastCharacters = data.slice(-
|
|
10
|
+
const getShortenData = (data, firstPartLength = 12, lastPartLength = 12) => {
|
|
11
|
+
const firstCharacters = data.substring(0, firstPartLength);
|
|
12
|
+
const lastCharacters = data.slice(-lastPartLength);
|
|
13
13
|
return `${firstCharacters}...${lastCharacters}`;
|
|
14
14
|
};
|
|
15
15
|
exports.getShortenData = getShortenData;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,12 +5,14 @@ export { ERC20_TOKEN_CONTRACT_ABI };
|
|
|
5
5
|
export { GAS_LIMIT_PER_TX_TYPE, MULTICALL3_ADDRESS } from './constants/constants';
|
|
6
6
|
export { NETWORKS_REGISTRY, NetworkField, NetworkRegistry } from './constants/NETWORKS_REGISTRY';
|
|
7
7
|
/** basic blockchain exports */
|
|
8
|
-
export { buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
|
|
8
|
+
export { buildBaseUnsignedTransferTx, buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
|
|
9
9
|
export { broadcastTransaction } from './blockchain/broadcastTransaction';
|
|
10
10
|
export { estimateGasLimitFromProvider } from './blockchain/estimateGasLimitFromProvider';
|
|
11
11
|
export { getProvider } from './blockchain/getProvider';
|
|
12
12
|
export { txStatus } from './blockchain/txStatus';
|
|
13
13
|
export { getBalance, getBalances } from './blockchain/getBalances';
|
|
14
|
+
export { estimateTransaction } from './blockchain/estimateTransaction';
|
|
15
|
+
export { prepareTransaction } from './blockchain/prepareTransaction';
|
|
14
16
|
/** services exports */
|
|
15
17
|
export { EvmWalletService, EvmGeneratedWallet, EvmDerivedWallet, } from './services/evm-wallet-core/evmWalletService';
|
|
16
18
|
export { EntropySource } from './services/evm-wallet-core/entropy';
|
|
@@ -24,4 +26,4 @@ export { formattedAmountForDisplay, parsedAmount } from './utils/formatAmount';
|
|
|
24
26
|
export { handleErrorMessages, errorMessagesForBroadcast, errorMessagesForGasLimitEstimation, } from './utils/handleErrorMessages';
|
|
25
27
|
export { normalizeAddress } from './utils/normalizeAddress';
|
|
26
28
|
/** types exports */
|
|
27
|
-
export { BroadcastTransactionOptions, BuildMaxNativeTransferTxOptions,
|
|
29
|
+
export { BroadcastTransactionOptions, BuildMaxNativeTransferTxOptions, BuildUnsignedTransferTxOptions, EstimateGasLimitFromProviderProps, GasEstimateResult, TxStatusOptions, BuildBaseUnsignedTransferTxParams, TxStatusResponse, EstimateTransactionOptions, EstimateTransactionResult, PrepareTransactionParams, PrepareTransactionResult, FormatAmountOptions, TransactionRequest, GetBalanceParams, GetBalancesParams, GetBalancesChainRequest, GetBalanceResult, ChainBalances, TokenBalance, ChainGroup, } from './types/common';
|
package/dist/index.js
CHANGED
|
@@ -5,12 +5,14 @@ export { ERC20_TOKEN_CONTRACT_ABI };
|
|
|
5
5
|
export { GAS_LIMIT_PER_TX_TYPE, MULTICALL3_ADDRESS } from './constants/constants';
|
|
6
6
|
export { NETWORKS_REGISTRY } from './constants/NETWORKS_REGISTRY';
|
|
7
7
|
/** basic blockchain exports */
|
|
8
|
-
export { buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
|
|
8
|
+
export { buildBaseUnsignedTransferTx, buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
|
|
9
9
|
export { broadcastTransaction } from './blockchain/broadcastTransaction';
|
|
10
10
|
export { estimateGasLimitFromProvider } from './blockchain/estimateGasLimitFromProvider';
|
|
11
11
|
export { getProvider } from './blockchain/getProvider';
|
|
12
12
|
export { txStatus } from './blockchain/txStatus';
|
|
13
13
|
export { getBalance, getBalances } from './blockchain/getBalances';
|
|
14
|
+
export { estimateTransaction } from './blockchain/estimateTransaction';
|
|
15
|
+
export { prepareTransaction } from './blockchain/prepareTransaction';
|
|
14
16
|
/** services exports */
|
|
15
17
|
export { EvmWalletService, } from './services/evm-wallet-core/evmWalletService';
|
|
16
18
|
export { createWallet, signMessage, signTransaction } from './services/evm-wallet-core/signer';
|
package/dist/types/common.d.ts
CHANGED
|
@@ -17,36 +17,59 @@ export interface GasEstimateResult {
|
|
|
17
17
|
gasPrice?: bigint;
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
+
export interface EstimateTransactionOptions {
|
|
21
|
+
rpcUrl: string;
|
|
22
|
+
chainId: number;
|
|
23
|
+
tx: TransactionRequest;
|
|
24
|
+
fromAddress: string;
|
|
25
|
+
defaultGasLimit?: bigint;
|
|
26
|
+
}
|
|
27
|
+
export interface PrepareTransactionParams extends EstimateTransactionOptions {
|
|
28
|
+
}
|
|
29
|
+
export interface EstimateTransactionResult {
|
|
30
|
+
gasLimit: bigint;
|
|
31
|
+
gasEstimated: bigint;
|
|
32
|
+
feeData: {
|
|
33
|
+
maxFeePerGas?: bigint;
|
|
34
|
+
maxPriorityFeePerGas?: bigint;
|
|
35
|
+
gasPrice?: bigint;
|
|
36
|
+
};
|
|
37
|
+
gasReserve?: bigint;
|
|
38
|
+
humanReadableGasReserve: string;
|
|
39
|
+
bufferPercentage: number;
|
|
40
|
+
}
|
|
41
|
+
export interface PrepareTransactionResult {
|
|
42
|
+
unsignedTx: TransactionRequest;
|
|
43
|
+
nonce: number;
|
|
44
|
+
gasEstimated: bigint;
|
|
45
|
+
gasLimit: bigint;
|
|
46
|
+
gasReserve?: bigint;
|
|
47
|
+
bufferPercentage: number;
|
|
48
|
+
feeData: {
|
|
49
|
+
maxFeePerGas?: bigint;
|
|
50
|
+
maxPriorityFeePerGas?: bigint;
|
|
51
|
+
gasPrice?: bigint;
|
|
52
|
+
};
|
|
53
|
+
humanReadableGasReserve: string;
|
|
54
|
+
}
|
|
55
|
+
export interface BuildBaseUnsignedTransferTxParams {
|
|
56
|
+
recipientAddress: string;
|
|
57
|
+
value: string;
|
|
58
|
+
tokenAddress?: string;
|
|
59
|
+
tokenDecimals?: number;
|
|
60
|
+
}
|
|
20
61
|
export interface BuildUnsignedTransferTxOptions {
|
|
21
62
|
fromAddress: string;
|
|
22
63
|
toAddress: string;
|
|
23
64
|
value?: string;
|
|
24
|
-
data?: string;
|
|
25
65
|
tokenAddress?: string;
|
|
26
66
|
tokenDecimals?: number;
|
|
27
67
|
rpcUrl: string;
|
|
28
68
|
chainId?: number;
|
|
29
69
|
defaultGasLimit: bigint;
|
|
30
70
|
}
|
|
31
|
-
export interface
|
|
32
|
-
unsignedTx: TransactionRequest;
|
|
33
|
-
nonce: number;
|
|
34
|
-
gasEstimated: string;
|
|
35
|
-
gasLimit: string;
|
|
36
|
-
gasReserve?: string;
|
|
37
|
-
bufferPercentage: number;
|
|
38
|
-
feeData: {
|
|
39
|
-
maxFeePerGas?: string;
|
|
40
|
-
maxPriorityFeePerGas?: string;
|
|
41
|
-
gasPrice?: string;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
export interface BuildMaxNativeTransferTxOptions extends Omit<BuildUnsignedTransferTxOptions, 'value' | 'tokenAddress' | 'tokenDecimals'> {
|
|
71
|
+
export interface BuildMaxNativeTransferTxOptions extends Omit<BuildUnsignedTransferTxOptions, 'value' | 'tokenDecimals'> {
|
|
45
72
|
balance: string;
|
|
46
|
-
tokenAddress?: string;
|
|
47
|
-
}
|
|
48
|
-
export interface BuildMaxNativeTransferTxResponse extends UnsignedTransferTxResponse {
|
|
49
|
-
sendableValue: string;
|
|
50
73
|
}
|
|
51
74
|
export interface BroadcastTransactionOptions {
|
|
52
75
|
signedTx: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const getShortenTransactionHashOrAddress: (txHashOrAddress: string) => string;
|
|
2
|
-
export declare const getShortenData: (data: string) => string;
|
|
1
|
+
export declare const getShortenTransactionHashOrAddress: (txHashOrAddress: string, firstPartLength?: number, lastPartLength?: number) => string;
|
|
2
|
+
export declare const getShortenData: (data: string, firstPartLength?: number, lastPartLength?: number) => string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export const getShortenTransactionHashOrAddress = (txHashOrAddress) => {
|
|
2
|
-
const firstCharacters = txHashOrAddress.substring(0,
|
|
3
|
-
const lastCharacters = txHashOrAddress.slice(-
|
|
1
|
+
export const getShortenTransactionHashOrAddress = (txHashOrAddress, firstPartLength = 6, lastPartLength = 4) => {
|
|
2
|
+
const firstCharacters = txHashOrAddress.substring(0, firstPartLength);
|
|
3
|
+
const lastCharacters = txHashOrAddress.slice(-lastPartLength);
|
|
4
4
|
return `${firstCharacters}...${lastCharacters}`;
|
|
5
5
|
};
|
|
6
|
-
export const getShortenData = (data) => {
|
|
7
|
-
const firstCharacters = data.substring(0,
|
|
8
|
-
const lastCharacters = data.slice(-
|
|
6
|
+
export const getShortenData = (data, firstPartLength = 12, lastPartLength = 12) => {
|
|
7
|
+
const firstCharacters = data.substring(0, firstPartLength);
|
|
8
|
+
const lastCharacters = data.slice(-lastPartLength);
|
|
9
9
|
return `${firstCharacters}...${lastCharacters}`;
|
|
10
10
|
};
|