@stas-b-woof/compound-ethers 0.0.1 → 1.0.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/README.md CHANGED
@@ -4,7 +4,7 @@ Compound Integration Kit is a collection of TypeScript tools for working with Co
4
4
 
5
5
  The collection currently includes:
6
6
 
7
- - `@stas-b-woof/compound` — the core SDK for market data, account state, rewards, liquidations, and transaction helpers.
7
+ - `@stas-b-woof/compound` — the core SDK for market data, account state, liquidations, and transaction helpers.
8
8
  - `@stas-b-woof/compound-react` — React bindings with hooks and mutations for Compound-powered UIs.
9
9
  - `@stas-b-woof/compound-viem` — Viem-based integration helpers for typed contract interactions.
10
10
  - `@stas-b-woof/compound-ethers` — Ethers.js integration helpers for protocol interactions.
@@ -14,4 +14,6 @@ For installation guidance, full usage docs, examples, and API references, see th
14
14
 
15
15
  - [Core APIs](https://github.com/stas-b-woof/compound-integration-sdk/blob/post-mvp/docs/userguides/CORE.md)
16
16
  - [React wrappers](docs/userguides/REACT.MD)
17
- - [Wagmi integration](docs/userguides/WAGMI.md)
17
+ - [Wagmi integration](docs/userguides/WAGMI.md)
18
+
19
+ Code audit: [November 2026 report (8f60c62)](https://github.com/woof-software/compound-integration-sdk/blob/7962066b615bd480d2da32ca3d98bdce3507e4ed/audits/2026-11-8f60c62.pdf).
@@ -275,4 +275,3 @@ export declare const multicall3Abi: readonly [{
275
275
  readonly name: "returnData";
276
276
  }];
277
277
  }];
278
- //# sourceMappingURL=multicall3.abi.d.ts.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.multicall3Abi = void 0;
4
+ const abitype_1 = require("abitype");
5
+ exports.multicall3Abi = (0, abitype_1.parseAbi)([
6
+ 'function aggregate((address target, bytes callData)[] calls) payable returns (uint256 blockNumber, bytes[] returnData)',
7
+ 'function aggregate3((address target, bool allowFailure, bytes callData)[] calls) payable returns ((bool success, bytes returnData)[] returnData)',
8
+ 'function aggregate3Value((address target, bool allowFailure, uint256 value, bytes callData)[] calls) payable returns ((bool success, bytes returnData)[] returnData)',
9
+ 'function blockAndAggregate((address target, bytes callData)[] calls) payable returns (uint256 blockNumber, bytes32 blockHash, (bool success, bytes returnData)[] returnData)',
10
+ 'function getBasefee() view returns (uint256 basefee)',
11
+ 'function getBlockHash(uint256 blockNumber) view returns (bytes32 blockHash)',
12
+ 'function getBlockNumber() view returns (uint256 blockNumber)',
13
+ 'function getChainId() view returns (uint256 chainid)',
14
+ 'function getCurrentBlockCoinbase() view returns (address coinbase)',
15
+ 'function getCurrentBlockDifficulty() view returns (uint256 difficulty)',
16
+ 'function getCurrentBlockGasLimit() view returns (uint256 gaslimit)',
17
+ 'function getCurrentBlockTimestamp() view returns (uint256 timestamp)',
18
+ 'function getEthBalance(address addr) view returns (uint256 balance)',
19
+ 'function getLastBlockHash() view returns (bytes32 blockHash)',
20
+ 'function tryAggregate(bool requireSuccess, (address target, bytes callData)[] calls) payable returns ((bool success, bytes returnData)[] returnData)',
21
+ 'function tryBlockAndAggregate(bool requireSuccess, (address target, bytes callData)[] calls) payable returns (uint256 blockNumber, bytes32 blockHash, (bool success, bytes returnData)[] returnData)'
22
+ ]);
@@ -1,3 +1,2 @@
1
1
  export { type EthersRpcArgs, makeEthersRpc, } from './rpc.js';
2
2
  export { type Multicall3Abi, multicall3Abi, } from './abis/multicall3.abi.js';
3
- //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.multicall3Abi = exports.makeEthersRpc = void 0;
4
+ var rpc_js_1 = require("./rpc.js");
5
+ Object.defineProperty(exports, "makeEthersRpc", { enumerable: true, get: function () { return rpc_js_1.makeEthersRpc; } });
6
+ var multicall3_abi_js_1 = require("./abis/multicall3.abi.js");
7
+ Object.defineProperty(exports, "multicall3Abi", { enumerable: true, get: function () { return multicall3_abi_js_1.multicall3Abi; } });
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,4 +1,4 @@
1
- import { type Hash } from "@stas-b-woof/compound";
1
+ import { type Hash, type EthCallParams, BigDecimal } from "@stas-b-woof/compound";
2
2
  import { type Provider, type Signer } from "ethers/providers";
3
3
  export type EthersRpcMode = 'default' | 'multicall3';
4
4
  export type EthersRpcArgs = {
@@ -7,11 +7,15 @@ export type EthersRpcArgs = {
7
7
  mode?: EthersRpcMode;
8
8
  };
9
9
  export declare function makeEthersRpc(args: EthersRpcArgs): {
10
- ethCall: (tx: any) => Promise<`0x${string}`>;
11
- ethGasPrice: () => Promise<bigint>;
12
- ethBlockNumber: () => Promise<bigint>;
13
- ethGetTransactionCount: ({ address, block }: import("@stas-b-woof/compound").EthGetTransactionCountParams) => Promise<bigint>;
14
- ethEstimateGas: (tx: import("@stas-b-woof/compound").EthEstimateGasParams) => Promise<bigint>;
10
+ ethCall: (tx: EthCallParams) => Promise<`0x${string}`>;
11
+ getFeeData: () => Promise<{
12
+ gasPrice: BigDecimal;
13
+ maxFeePerGas: BigDecimal;
14
+ maxPriorityFeePerGas: BigDecimal;
15
+ }>;
16
+ ethBlockNumber: () => Promise<BigDecimal>;
17
+ ethGetTransactionCount: ({ address, block }: import("@stas-b-woof/compound").EthGetTransactionCountParams) => Promise<BigDecimal>;
18
+ ethEstimateGas: (tx: Partial<import("@stas-b-woof/compound").EthSendTransactionParams>) => Promise<BigDecimal>;
15
19
  ethSendTransaction: (tx: import("@stas-b-woof/compound").EthSendTransactionParams) => Promise<`0x${string}`>;
16
20
  ethGetTransactionReceipt: ({ hash }: import("@stas-b-woof/compound").EthGetTransactionReceiptParams) => Promise<{
17
21
  to: `0x${string}`;
@@ -19,12 +23,12 @@ export declare function makeEthersRpc(args: EthersRpcArgs): {
19
23
  from: `0x${string}`;
20
24
  type: import("@stas-b-woof/compound").KnownTransactionType;
21
25
  blockHash: `0x${string}`;
22
- blockNumber: bigint;
23
- gasUsed: bigint;
26
+ blockNumber: BigDecimal;
27
+ gasUsed: BigDecimal;
24
28
  status: import("@stas-b-woof/compound").KnownTransactionStatus;
25
29
  transactionHash: `0x${string}`;
26
- transactionIndex: bigint;
27
- cumulativeGasUsed: bigint;
30
+ transactionIndex: BigDecimal;
31
+ cumulativeGasUsed: BigDecimal;
28
32
  logsBloom: `0x${string}`;
29
33
  } | {
30
34
  to: null;
@@ -32,16 +36,15 @@ export declare function makeEthersRpc(args: EthersRpcArgs): {
32
36
  from: `0x${string}`;
33
37
  type: import("@stas-b-woof/compound").KnownTransactionType;
34
38
  blockHash: `0x${string}`;
35
- blockNumber: bigint;
36
- gasUsed: bigint;
39
+ blockNumber: BigDecimal;
40
+ gasUsed: BigDecimal;
37
41
  status: import("@stas-b-woof/compound").KnownTransactionStatus;
38
42
  transactionHash: `0x${string}`;
39
- transactionIndex: bigint;
40
- cumulativeGasUsed: bigint;
43
+ transactionIndex: BigDecimal;
44
+ cumulativeGasUsed: BigDecimal;
41
45
  logsBloom: `0x${string}`;
42
- } | null>;
46
+ }>;
43
47
  ethChainId: () => Promise<bigint>;
44
48
  ethSignTypedData: (args: import("@stas-b-woof/compound").EthSignTypedDataArgs) => Promise<Hash>;
45
- ethGetBalance: (address: `0x${string}`, block: import("@stas-b-woof/compound").Block | undefined) => Promise<bigint>;
49
+ ethGetBalance: (address: `0x${string}`, block: import("@stas-b-woof/compound").Block | undefined) => Promise<BigDecimal>;
46
50
  };
47
- //# sourceMappingURL=rpc.d.ts.map
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeEthersRpc = makeEthersRpc;
4
+ const compound_1 = require("@stas-b-woof/compound");
5
+ const multicall3_abi_js_1 = require("./abis/multicall3.abi.js");
6
+ function makeEthersRpc(args) {
7
+ const { mode = 'default', provider, signer, } = args;
8
+ let callsStack = [];
9
+ let currentRequest = null;
10
+ return {
11
+ ethCall: async (tx) => {
12
+ const _provider = provider();
13
+ const toEthersTx = (tx) => {
14
+ const { from, block, ...rest } = tx;
15
+ return {
16
+ ...rest,
17
+ from: from ?? null,
18
+ blockTag: compound_1.BigDecimal.isBigDecimal(block) ? block.toBigInt() : block,
19
+ };
20
+ };
21
+ if (mode === 'default') {
22
+ const data = await _provider.call(toEthersTx(tx));
23
+ return (data ?? '0x');
24
+ }
25
+ else {
26
+ return new Promise((rs, rj) => {
27
+ const currentIndex = callsStack.length;
28
+ callsStack.push(tx);
29
+ Promise
30
+ .resolve()
31
+ .then(async () => {
32
+ const [firstCall, ...restCalls] = callsStack;
33
+ (0, compound_1.asserts)(firstCall, 'No calls to process.');
34
+ if (restCalls.length > 0) {
35
+ let callPromise;
36
+ if (currentRequest) {
37
+ callPromise = currentRequest;
38
+ }
39
+ else {
40
+ const { calls: aggregate3Calls, block: aggregate3Block, } = restCalls.reduce((acc, tx) => {
41
+ if ((() => {
42
+ const a = tx.block, b = acc.block;
43
+ if (compound_1.BigDecimal.isBigDecimal(a) && compound_1.BigDecimal.isBigDecimal(b))
44
+ return !a.eq(b);
45
+ return a !== b;
46
+ })()) {
47
+ throw new Error('Block should be the same between calls using "multicall3" mode.');
48
+ }
49
+ acc.calls.push({
50
+ target: tx.to,
51
+ callData: tx.data,
52
+ allowFailure: true,
53
+ });
54
+ return acc;
55
+ }, ({
56
+ calls: [
57
+ {
58
+ target: firstCall.to,
59
+ callData: firstCall.data,
60
+ allowFailure: true,
61
+ }
62
+ ],
63
+ block: firstCall.block,
64
+ }));
65
+ const aggregate3Calldata = (0, compound_1.encodeFunctionData)(multicall3_abi_js_1.multicall3Abi, 'aggregate3', [aggregate3Calls]);
66
+ callPromise = currentRequest = _provider.call(toEthersTx({
67
+ to: '0xcA11bde05977b3631167028862bE2a173976CA11', // multicall3 address
68
+ data: aggregate3Calldata,
69
+ block: aggregate3Block,
70
+ }));
71
+ }
72
+ const aggregate3ResponseData = await callPromise;
73
+ const aggregationResults = (0, compound_1.decodeFunctionResult)(multicall3_abi_js_1.multicall3Abi, 'aggregate3', aggregate3ResponseData);
74
+ const thisOpResult = aggregationResults[currentIndex];
75
+ (0, compound_1.asserts)(thisOpResult, 'Aggregator response was not defined for operation.');
76
+ if (thisOpResult.success) {
77
+ rs(thisOpResult.returnData);
78
+ }
79
+ else {
80
+ rj(thisOpResult.returnData);
81
+ }
82
+ }
83
+ else {
84
+ const data = await _provider.call(toEthersTx(firstCall));
85
+ rs((data ?? '0x'));
86
+ }
87
+ })
88
+ .finally(() => {
89
+ currentRequest = null;
90
+ callsStack = [];
91
+ })
92
+ .catch(rj);
93
+ });
94
+ }
95
+ },
96
+ getFeeData: async () => {
97
+ const _provider = provider();
98
+ const { gasPrice, maxFeePerGas, maxPriorityFeePerGas, } = await _provider.getFeeData();
99
+ (0, compound_1.asserts)(gasPrice !== null, "gasPrice is not available");
100
+ (0, compound_1.asserts)(maxFeePerGas !== null, "maxFeePerGas is not available");
101
+ (0, compound_1.asserts)(maxPriorityFeePerGas !== null, "maxPriorityFeePerGas is not available");
102
+ return {
103
+ gasPrice: compound_1.BigDecimal.from(gasPrice),
104
+ maxFeePerGas: compound_1.BigDecimal.from(maxFeePerGas),
105
+ maxPriorityFeePerGas: compound_1.BigDecimal.from(maxPriorityFeePerGas),
106
+ };
107
+ },
108
+ ethBlockNumber: async () => {
109
+ const _provider = provider();
110
+ const block = await _provider.getBlockNumber();
111
+ return compound_1.BigDecimal.from(block);
112
+ },
113
+ ethGetTransactionCount: async ({ address, block }) => {
114
+ const _provider = provider();
115
+ const nonce = await _provider.getTransactionCount(address, compound_1.BigDecimal.isBigDecimal(block) ? block.toBigInt() : block);
116
+ return compound_1.BigDecimal.from(nonce);
117
+ },
118
+ ethEstimateGas: async (tx) => {
119
+ const _provider = provider();
120
+ const gas = await _provider.estimateGas({
121
+ ...(tx.to !== undefined ? { to: tx.to } : {}),
122
+ ...(tx.from !== undefined ? { from: tx.from } : {}),
123
+ ...(tx.data !== undefined ? { data: tx.data } : {}),
124
+ ...(tx.value !== undefined ? { value: tx.value.toBigInt() } : {}),
125
+ });
126
+ return compound_1.BigDecimal.from(gas);
127
+ },
128
+ ethSendTransaction: async (tx) => {
129
+ const _provider = signer?.();
130
+ if (!_provider) {
131
+ throw new Error("Signer is not defined. Please provide signer to use transaction sending.");
132
+ }
133
+ const { hash } = await _provider.sendTransaction({
134
+ to: tx.to,
135
+ from: tx.from,
136
+ data: tx.data,
137
+ value: tx.value.toBigInt(),
138
+ gasLimit: tx.gas?.toBigInt() ?? null,
139
+ gasPrice: tx.gasPrice?.toBigInt() ?? null,
140
+ maxFeePerGas: tx.maxFeePerGas?.toBigInt() ?? null,
141
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas?.toBigInt() ?? null,
142
+ nonce: tx.nonce.toApproximateNumber() ?? null,
143
+ });
144
+ (0, compound_1.asserts)((0, compound_1.isHash)(hash), "Transaction hash is not a hash");
145
+ return hash;
146
+ },
147
+ ethGetTransactionReceipt: async ({ hash }) => {
148
+ const _provider = provider();
149
+ const receipt = await _provider.getTransactionReceipt(hash);
150
+ (0, compound_1.asserts)(receipt !== null, "Transaction receipt not found");
151
+ (0, compound_1.asserts)((0, compound_1.isAddress)(receipt.from), "Transaction from is not an address");
152
+ (0, compound_1.asserts)((0, compound_1.isHash)(receipt.blockHash), "Transaction from is not an address");
153
+ (0, compound_1.asserts)((0, compound_1.isHash)(receipt.hash), "Transaction from is not an address");
154
+ (0, compound_1.asserts)((0, compound_1.isHex)(receipt.logsBloom), "Transaction from is not an address");
155
+ (0, compound_1.asserts)((0, compound_1.isKnownTransactionStatus)(receipt.status), "Transaction type is not 0 or 1");
156
+ (0, compound_1.asserts)((0, compound_1.isKnownTransactionType)(receipt.type), "Transaction type is not 0, 1 or 2");
157
+ const sharedTxData = {
158
+ from: receipt.from,
159
+ type: receipt.type,
160
+ blockHash: receipt.blockHash,
161
+ blockNumber: compound_1.BigDecimal.from(receipt.blockNumber),
162
+ gasUsed: compound_1.BigDecimal.from(receipt.gasUsed),
163
+ status: receipt.status,
164
+ transactionHash: receipt.hash,
165
+ transactionIndex: compound_1.BigDecimal.from(receipt.index),
166
+ cumulativeGasUsed: compound_1.BigDecimal.from(receipt.cumulativeGasUsed),
167
+ logsBloom: receipt.logsBloom,
168
+ };
169
+ if (receipt.to) {
170
+ (0, compound_1.asserts)((0, compound_1.isAddress)(receipt.to), "Transaction to is not an address");
171
+ return {
172
+ ...sharedTxData,
173
+ to: receipt.to,
174
+ contractAddress: null,
175
+ };
176
+ }
177
+ else {
178
+ (0, compound_1.asserts)((0, compound_1.isAddress)(receipt.contractAddress), "Transaction contractAddress is not an address");
179
+ return {
180
+ ...sharedTxData,
181
+ to: null,
182
+ contractAddress: receipt.contractAddress,
183
+ };
184
+ }
185
+ },
186
+ ethChainId: async () => {
187
+ const _provider = provider();
188
+ const { chainId } = await _provider.getNetwork();
189
+ return chainId;
190
+ },
191
+ ethSignTypedData: (args) => {
192
+ const { domain, types, values, } = args;
193
+ const _provider = signer?.();
194
+ if (!_provider) {
195
+ throw new Error("Signer is not defined. Please provide signer to use transaction sending.");
196
+ }
197
+ return _provider.signTypedData(domain, types, values);
198
+ },
199
+ ethGetBalance: async (address, block) => {
200
+ const _provider = provider();
201
+ const asBn = await _provider.getBalance(address, compound_1.BigDecimal.isBigDecimal(block) ? block.toBigInt() : block);
202
+ return compound_1.BigDecimal.from(asBn);
203
+ }
204
+ };
205
+ }
@@ -0,0 +1,277 @@
1
+ export type Multicall3Abi = typeof multicall3Abi;
2
+ export declare const multicall3Abi: readonly [{
3
+ readonly name: "aggregate";
4
+ readonly type: "function";
5
+ readonly stateMutability: "payable";
6
+ readonly inputs: readonly [{
7
+ readonly type: "tuple[]";
8
+ readonly components: readonly [{
9
+ readonly type: "address";
10
+ readonly name: "target";
11
+ }, {
12
+ readonly type: "bytes";
13
+ readonly name: "callData";
14
+ }];
15
+ readonly name: "calls";
16
+ }];
17
+ readonly outputs: readonly [{
18
+ readonly type: "uint256";
19
+ readonly name: "blockNumber";
20
+ }, {
21
+ readonly type: "bytes[]";
22
+ readonly name: "returnData";
23
+ }];
24
+ }, {
25
+ readonly name: "aggregate3";
26
+ readonly type: "function";
27
+ readonly stateMutability: "payable";
28
+ readonly inputs: readonly [{
29
+ readonly type: "tuple[]";
30
+ readonly components: readonly [{
31
+ readonly type: "address";
32
+ readonly name: "target";
33
+ }, {
34
+ readonly type: "bool";
35
+ readonly name: "allowFailure";
36
+ }, {
37
+ readonly type: "bytes";
38
+ readonly name: "callData";
39
+ }];
40
+ readonly name: "calls";
41
+ }];
42
+ readonly outputs: readonly [{
43
+ readonly type: "tuple[]";
44
+ readonly components: readonly [{
45
+ readonly type: "bool";
46
+ readonly name: "success";
47
+ }, {
48
+ readonly type: "bytes";
49
+ readonly name: "returnData";
50
+ }];
51
+ readonly name: "returnData";
52
+ }];
53
+ }, {
54
+ readonly name: "aggregate3Value";
55
+ readonly type: "function";
56
+ readonly stateMutability: "payable";
57
+ readonly inputs: readonly [{
58
+ readonly type: "tuple[]";
59
+ readonly components: readonly [{
60
+ readonly type: "address";
61
+ readonly name: "target";
62
+ }, {
63
+ readonly type: "bool";
64
+ readonly name: "allowFailure";
65
+ }, {
66
+ readonly type: "uint256";
67
+ readonly name: "value";
68
+ }, {
69
+ readonly type: "bytes";
70
+ readonly name: "callData";
71
+ }];
72
+ readonly name: "calls";
73
+ }];
74
+ readonly outputs: readonly [{
75
+ readonly type: "tuple[]";
76
+ readonly components: readonly [{
77
+ readonly type: "bool";
78
+ readonly name: "success";
79
+ }, {
80
+ readonly type: "bytes";
81
+ readonly name: "returnData";
82
+ }];
83
+ readonly name: "returnData";
84
+ }];
85
+ }, {
86
+ readonly name: "blockAndAggregate";
87
+ readonly type: "function";
88
+ readonly stateMutability: "payable";
89
+ readonly inputs: readonly [{
90
+ readonly type: "tuple[]";
91
+ readonly components: readonly [{
92
+ readonly type: "address";
93
+ readonly name: "target";
94
+ }, {
95
+ readonly type: "bytes";
96
+ readonly name: "callData";
97
+ }];
98
+ readonly name: "calls";
99
+ }];
100
+ readonly outputs: readonly [{
101
+ readonly type: "uint256";
102
+ readonly name: "blockNumber";
103
+ }, {
104
+ readonly type: "bytes32";
105
+ readonly name: "blockHash";
106
+ }, {
107
+ readonly type: "tuple[]";
108
+ readonly components: readonly [{
109
+ readonly type: "bool";
110
+ readonly name: "success";
111
+ }, {
112
+ readonly type: "bytes";
113
+ readonly name: "returnData";
114
+ }];
115
+ readonly name: "returnData";
116
+ }];
117
+ }, {
118
+ readonly name: "getBasefee";
119
+ readonly type: "function";
120
+ readonly stateMutability: "view";
121
+ readonly inputs: readonly [];
122
+ readonly outputs: readonly [{
123
+ readonly type: "uint256";
124
+ readonly name: "basefee";
125
+ }];
126
+ }, {
127
+ readonly name: "getBlockHash";
128
+ readonly type: "function";
129
+ readonly stateMutability: "view";
130
+ readonly inputs: readonly [{
131
+ readonly type: "uint256";
132
+ readonly name: "blockNumber";
133
+ }];
134
+ readonly outputs: readonly [{
135
+ readonly type: "bytes32";
136
+ readonly name: "blockHash";
137
+ }];
138
+ }, {
139
+ readonly name: "getBlockNumber";
140
+ readonly type: "function";
141
+ readonly stateMutability: "view";
142
+ readonly inputs: readonly [];
143
+ readonly outputs: readonly [{
144
+ readonly type: "uint256";
145
+ readonly name: "blockNumber";
146
+ }];
147
+ }, {
148
+ readonly name: "getChainId";
149
+ readonly type: "function";
150
+ readonly stateMutability: "view";
151
+ readonly inputs: readonly [];
152
+ readonly outputs: readonly [{
153
+ readonly type: "uint256";
154
+ readonly name: "chainid";
155
+ }];
156
+ }, {
157
+ readonly name: "getCurrentBlockCoinbase";
158
+ readonly type: "function";
159
+ readonly stateMutability: "view";
160
+ readonly inputs: readonly [];
161
+ readonly outputs: readonly [{
162
+ readonly type: "address";
163
+ readonly name: "coinbase";
164
+ }];
165
+ }, {
166
+ readonly name: "getCurrentBlockDifficulty";
167
+ readonly type: "function";
168
+ readonly stateMutability: "view";
169
+ readonly inputs: readonly [];
170
+ readonly outputs: readonly [{
171
+ readonly type: "uint256";
172
+ readonly name: "difficulty";
173
+ }];
174
+ }, {
175
+ readonly name: "getCurrentBlockGasLimit";
176
+ readonly type: "function";
177
+ readonly stateMutability: "view";
178
+ readonly inputs: readonly [];
179
+ readonly outputs: readonly [{
180
+ readonly type: "uint256";
181
+ readonly name: "gaslimit";
182
+ }];
183
+ }, {
184
+ readonly name: "getCurrentBlockTimestamp";
185
+ readonly type: "function";
186
+ readonly stateMutability: "view";
187
+ readonly inputs: readonly [];
188
+ readonly outputs: readonly [{
189
+ readonly type: "uint256";
190
+ readonly name: "timestamp";
191
+ }];
192
+ }, {
193
+ readonly name: "getEthBalance";
194
+ readonly type: "function";
195
+ readonly stateMutability: "view";
196
+ readonly inputs: readonly [{
197
+ readonly type: "address";
198
+ readonly name: "addr";
199
+ }];
200
+ readonly outputs: readonly [{
201
+ readonly type: "uint256";
202
+ readonly name: "balance";
203
+ }];
204
+ }, {
205
+ readonly name: "getLastBlockHash";
206
+ readonly type: "function";
207
+ readonly stateMutability: "view";
208
+ readonly inputs: readonly [];
209
+ readonly outputs: readonly [{
210
+ readonly type: "bytes32";
211
+ readonly name: "blockHash";
212
+ }];
213
+ }, {
214
+ readonly name: "tryAggregate";
215
+ readonly type: "function";
216
+ readonly stateMutability: "payable";
217
+ readonly inputs: readonly [{
218
+ readonly type: "bool";
219
+ readonly name: "requireSuccess";
220
+ }, {
221
+ readonly type: "tuple[]";
222
+ readonly components: readonly [{
223
+ readonly type: "address";
224
+ readonly name: "target";
225
+ }, {
226
+ readonly type: "bytes";
227
+ readonly name: "callData";
228
+ }];
229
+ readonly name: "calls";
230
+ }];
231
+ readonly outputs: readonly [{
232
+ readonly type: "tuple[]";
233
+ readonly components: readonly [{
234
+ readonly type: "bool";
235
+ readonly name: "success";
236
+ }, {
237
+ readonly type: "bytes";
238
+ readonly name: "returnData";
239
+ }];
240
+ readonly name: "returnData";
241
+ }];
242
+ }, {
243
+ readonly name: "tryBlockAndAggregate";
244
+ readonly type: "function";
245
+ readonly stateMutability: "payable";
246
+ readonly inputs: readonly [{
247
+ readonly type: "bool";
248
+ readonly name: "requireSuccess";
249
+ }, {
250
+ readonly type: "tuple[]";
251
+ readonly components: readonly [{
252
+ readonly type: "address";
253
+ readonly name: "target";
254
+ }, {
255
+ readonly type: "bytes";
256
+ readonly name: "callData";
257
+ }];
258
+ readonly name: "calls";
259
+ }];
260
+ readonly outputs: readonly [{
261
+ readonly type: "uint256";
262
+ readonly name: "blockNumber";
263
+ }, {
264
+ readonly type: "bytes32";
265
+ readonly name: "blockHash";
266
+ }, {
267
+ readonly type: "tuple[]";
268
+ readonly components: readonly [{
269
+ readonly type: "bool";
270
+ readonly name: "success";
271
+ }, {
272
+ readonly type: "bytes";
273
+ readonly name: "returnData";
274
+ }];
275
+ readonly name: "returnData";
276
+ }];
277
+ }];
@@ -17,4 +17,3 @@ export const multicall3Abi = parseAbi([
17
17
  'function tryAggregate(bool requireSuccess, (address target, bytes callData)[] calls) payable returns ((bool success, bytes returnData)[] returnData)',
18
18
  'function tryBlockAndAggregate(bool requireSuccess, (address target, bytes callData)[] calls) payable returns (uint256 blockNumber, bytes32 blockHash, (bool success, bytes returnData)[] returnData)'
19
19
  ]);
20
- //# sourceMappingURL=multicall3.abi.js.map
@@ -0,0 +1,2 @@
1
+ export { type EthersRpcArgs, makeEthersRpc, } from './rpc.js';
2
+ export { type Multicall3Abi, multicall3Abi, } from './abis/multicall3.abi.js';
@@ -1,3 +1,2 @@
1
1
  export { makeEthersRpc, } from './rpc.js';
2
2
  export { multicall3Abi, } from './abis/multicall3.abi.js';
3
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,50 @@
1
+ import { type Hash, type EthCallParams, BigDecimal } from "@stas-b-woof/compound";
2
+ import { type Provider, type Signer } from "ethers/providers";
3
+ export type EthersRpcMode = 'default' | 'multicall3';
4
+ export type EthersRpcArgs = {
5
+ provider: () => Provider;
6
+ signer?: () => Signer;
7
+ mode?: EthersRpcMode;
8
+ };
9
+ export declare function makeEthersRpc(args: EthersRpcArgs): {
10
+ ethCall: (tx: EthCallParams) => Promise<`0x${string}`>;
11
+ getFeeData: () => Promise<{
12
+ gasPrice: BigDecimal;
13
+ maxFeePerGas: BigDecimal;
14
+ maxPriorityFeePerGas: BigDecimal;
15
+ }>;
16
+ ethBlockNumber: () => Promise<BigDecimal>;
17
+ ethGetTransactionCount: ({ address, block }: import("@stas-b-woof/compound").EthGetTransactionCountParams) => Promise<BigDecimal>;
18
+ ethEstimateGas: (tx: Partial<import("@stas-b-woof/compound").EthSendTransactionParams>) => Promise<BigDecimal>;
19
+ ethSendTransaction: (tx: import("@stas-b-woof/compound").EthSendTransactionParams) => Promise<`0x${string}`>;
20
+ ethGetTransactionReceipt: ({ hash }: import("@stas-b-woof/compound").EthGetTransactionReceiptParams) => Promise<{
21
+ to: `0x${string}`;
22
+ contractAddress: null;
23
+ from: `0x${string}`;
24
+ type: import("@stas-b-woof/compound").KnownTransactionType;
25
+ blockHash: `0x${string}`;
26
+ blockNumber: BigDecimal;
27
+ gasUsed: BigDecimal;
28
+ status: import("@stas-b-woof/compound").KnownTransactionStatus;
29
+ transactionHash: `0x${string}`;
30
+ transactionIndex: BigDecimal;
31
+ cumulativeGasUsed: BigDecimal;
32
+ logsBloom: `0x${string}`;
33
+ } | {
34
+ to: null;
35
+ contractAddress: `0x${string}`;
36
+ from: `0x${string}`;
37
+ type: import("@stas-b-woof/compound").KnownTransactionType;
38
+ blockHash: `0x${string}`;
39
+ blockNumber: BigDecimal;
40
+ gasUsed: BigDecimal;
41
+ status: import("@stas-b-woof/compound").KnownTransactionStatus;
42
+ transactionHash: `0x${string}`;
43
+ transactionIndex: BigDecimal;
44
+ cumulativeGasUsed: BigDecimal;
45
+ logsBloom: `0x${string}`;
46
+ }>;
47
+ ethChainId: () => Promise<bigint>;
48
+ ethSignTypedData: (args: import("@stas-b-woof/compound").EthSignTypedDataArgs) => Promise<Hash>;
49
+ ethGetBalance: (address: `0x${string}`, block: import("@stas-b-woof/compound").Block | undefined) => Promise<BigDecimal>;
50
+ };
@@ -0,0 +1,203 @@
1
+ import { decodeFunctionResult, encodeFunctionData, asserts, isAddress, isHash, isHex, isKnownTransactionStatus, isKnownTransactionType, BigDecimal, } from "@stas-b-woof/compound";
2
+ import {} from "ethers/providers";
3
+ import { multicall3Abi } from "./abis/multicall3.abi.js";
4
+ export function makeEthersRpc(args) {
5
+ const { mode = 'default', provider, signer, } = args;
6
+ let callsStack = [];
7
+ let currentRequest = null;
8
+ return {
9
+ ethCall: async (tx) => {
10
+ const _provider = provider();
11
+ const toEthersTx = (tx) => {
12
+ const { from, block, ...rest } = tx;
13
+ return {
14
+ ...rest,
15
+ from: from ?? null,
16
+ blockTag: BigDecimal.isBigDecimal(block) ? block.toBigInt() : block,
17
+ };
18
+ };
19
+ if (mode === 'default') {
20
+ const data = await _provider.call(toEthersTx(tx));
21
+ return (data ?? '0x');
22
+ }
23
+ else {
24
+ return new Promise((rs, rj) => {
25
+ const currentIndex = callsStack.length;
26
+ callsStack.push(tx);
27
+ Promise
28
+ .resolve()
29
+ .then(async () => {
30
+ const [firstCall, ...restCalls] = callsStack;
31
+ asserts(firstCall, 'No calls to process.');
32
+ if (restCalls.length > 0) {
33
+ let callPromise;
34
+ if (currentRequest) {
35
+ callPromise = currentRequest;
36
+ }
37
+ else {
38
+ const { calls: aggregate3Calls, block: aggregate3Block, } = restCalls.reduce((acc, tx) => {
39
+ if ((() => {
40
+ const a = tx.block, b = acc.block;
41
+ if (BigDecimal.isBigDecimal(a) && BigDecimal.isBigDecimal(b))
42
+ return !a.eq(b);
43
+ return a !== b;
44
+ })()) {
45
+ throw new Error('Block should be the same between calls using "multicall3" mode.');
46
+ }
47
+ acc.calls.push({
48
+ target: tx.to,
49
+ callData: tx.data,
50
+ allowFailure: true,
51
+ });
52
+ return acc;
53
+ }, ({
54
+ calls: [
55
+ {
56
+ target: firstCall.to,
57
+ callData: firstCall.data,
58
+ allowFailure: true,
59
+ }
60
+ ],
61
+ block: firstCall.block,
62
+ }));
63
+ const aggregate3Calldata = encodeFunctionData(multicall3Abi, 'aggregate3', [aggregate3Calls]);
64
+ callPromise = currentRequest = _provider.call(toEthersTx({
65
+ to: '0xcA11bde05977b3631167028862bE2a173976CA11', // multicall3 address
66
+ data: aggregate3Calldata,
67
+ block: aggregate3Block,
68
+ }));
69
+ }
70
+ const aggregate3ResponseData = await callPromise;
71
+ const aggregationResults = decodeFunctionResult(multicall3Abi, 'aggregate3', aggregate3ResponseData);
72
+ const thisOpResult = aggregationResults[currentIndex];
73
+ asserts(thisOpResult, 'Aggregator response was not defined for operation.');
74
+ if (thisOpResult.success) {
75
+ rs(thisOpResult.returnData);
76
+ }
77
+ else {
78
+ rj(thisOpResult.returnData);
79
+ }
80
+ }
81
+ else {
82
+ const data = await _provider.call(toEthersTx(firstCall));
83
+ rs((data ?? '0x'));
84
+ }
85
+ })
86
+ .finally(() => {
87
+ currentRequest = null;
88
+ callsStack = [];
89
+ })
90
+ .catch(rj);
91
+ });
92
+ }
93
+ },
94
+ getFeeData: async () => {
95
+ const _provider = provider();
96
+ const { gasPrice, maxFeePerGas, maxPriorityFeePerGas, } = await _provider.getFeeData();
97
+ asserts(gasPrice !== null, "gasPrice is not available");
98
+ asserts(maxFeePerGas !== null, "maxFeePerGas is not available");
99
+ asserts(maxPriorityFeePerGas !== null, "maxPriorityFeePerGas is not available");
100
+ return {
101
+ gasPrice: BigDecimal.from(gasPrice),
102
+ maxFeePerGas: BigDecimal.from(maxFeePerGas),
103
+ maxPriorityFeePerGas: BigDecimal.from(maxPriorityFeePerGas),
104
+ };
105
+ },
106
+ ethBlockNumber: async () => {
107
+ const _provider = provider();
108
+ const block = await _provider.getBlockNumber();
109
+ return BigDecimal.from(block);
110
+ },
111
+ ethGetTransactionCount: async ({ address, block }) => {
112
+ const _provider = provider();
113
+ const nonce = await _provider.getTransactionCount(address, BigDecimal.isBigDecimal(block) ? block.toBigInt() : block);
114
+ return BigDecimal.from(nonce);
115
+ },
116
+ ethEstimateGas: async (tx) => {
117
+ const _provider = provider();
118
+ const gas = await _provider.estimateGas({
119
+ ...(tx.to !== undefined ? { to: tx.to } : {}),
120
+ ...(tx.from !== undefined ? { from: tx.from } : {}),
121
+ ...(tx.data !== undefined ? { data: tx.data } : {}),
122
+ ...(tx.value !== undefined ? { value: tx.value.toBigInt() } : {}),
123
+ });
124
+ return BigDecimal.from(gas);
125
+ },
126
+ ethSendTransaction: async (tx) => {
127
+ const _provider = signer?.();
128
+ if (!_provider) {
129
+ throw new Error("Signer is not defined. Please provide signer to use transaction sending.");
130
+ }
131
+ const { hash } = await _provider.sendTransaction({
132
+ to: tx.to,
133
+ from: tx.from,
134
+ data: tx.data,
135
+ value: tx.value.toBigInt(),
136
+ gasLimit: tx.gas?.toBigInt() ?? null,
137
+ gasPrice: tx.gasPrice?.toBigInt() ?? null,
138
+ maxFeePerGas: tx.maxFeePerGas?.toBigInt() ?? null,
139
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas?.toBigInt() ?? null,
140
+ nonce: tx.nonce.toApproximateNumber() ?? null,
141
+ });
142
+ asserts(isHash(hash), "Transaction hash is not a hash");
143
+ return hash;
144
+ },
145
+ ethGetTransactionReceipt: async ({ hash }) => {
146
+ const _provider = provider();
147
+ const receipt = await _provider.getTransactionReceipt(hash);
148
+ asserts(receipt !== null, "Transaction receipt not found");
149
+ asserts(isAddress(receipt.from), "Transaction from is not an address");
150
+ asserts(isHash(receipt.blockHash), "Transaction from is not an address");
151
+ asserts(isHash(receipt.hash), "Transaction from is not an address");
152
+ asserts(isHex(receipt.logsBloom), "Transaction from is not an address");
153
+ asserts(isKnownTransactionStatus(receipt.status), "Transaction type is not 0 or 1");
154
+ asserts(isKnownTransactionType(receipt.type), "Transaction type is not 0, 1 or 2");
155
+ const sharedTxData = {
156
+ from: receipt.from,
157
+ type: receipt.type,
158
+ blockHash: receipt.blockHash,
159
+ blockNumber: BigDecimal.from(receipt.blockNumber),
160
+ gasUsed: BigDecimal.from(receipt.gasUsed),
161
+ status: receipt.status,
162
+ transactionHash: receipt.hash,
163
+ transactionIndex: BigDecimal.from(receipt.index),
164
+ cumulativeGasUsed: BigDecimal.from(receipt.cumulativeGasUsed),
165
+ logsBloom: receipt.logsBloom,
166
+ };
167
+ if (receipt.to) {
168
+ asserts(isAddress(receipt.to), "Transaction to is not an address");
169
+ return {
170
+ ...sharedTxData,
171
+ to: receipt.to,
172
+ contractAddress: null,
173
+ };
174
+ }
175
+ else {
176
+ asserts(isAddress(receipt.contractAddress), "Transaction contractAddress is not an address");
177
+ return {
178
+ ...sharedTxData,
179
+ to: null,
180
+ contractAddress: receipt.contractAddress,
181
+ };
182
+ }
183
+ },
184
+ ethChainId: async () => {
185
+ const _provider = provider();
186
+ const { chainId } = await _provider.getNetwork();
187
+ return chainId;
188
+ },
189
+ ethSignTypedData: (args) => {
190
+ const { domain, types, values, } = args;
191
+ const _provider = signer?.();
192
+ if (!_provider) {
193
+ throw new Error("Signer is not defined. Please provide signer to use transaction sending.");
194
+ }
195
+ return _provider.signTypedData(domain, types, values);
196
+ },
197
+ ethGetBalance: async (address, block) => {
198
+ const _provider = provider();
199
+ const asBn = await _provider.getBalance(address, BigDecimal.isBigDecimal(block) ? block.toBigInt() : block);
200
+ return BigDecimal.from(asBn);
201
+ }
202
+ };
203
+ }
package/package.json CHANGED
@@ -1,17 +1,31 @@
1
1
  {
2
2
  "name": "@stas-b-woof/compound-ethers",
3
- "version": "0.0.1",
3
+ "version": "1.0.0",
4
4
  "description": "Integration library bridging the Compound SDK with Ethers.js, providing seamless contract interactions and transaction execution.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
9
- "types": "./dist/src/index.d.ts",
10
- "default": "./dist/src/index.js"
9
+ "import": {
10
+ "types": "./dist/esm/index.d.ts",
11
+ "default": "./dist/esm/index.js"
12
+ },
13
+ "require": {
14
+ "types": "./dist/cjs/index.d.ts",
15
+ "default": "./dist/cjs/index.js"
16
+ },
17
+ "default": "./dist/esm/index.js"
11
18
  },
12
19
  "./*": {
13
- "types": "./dist/src/*.d.ts",
14
- "default": "./dist/src/*.js"
20
+ "import": {
21
+ "types": "./dist/esm/*.d.ts",
22
+ "default": "./dist/esm/*.js"
23
+ },
24
+ "require": {
25
+ "types": "./dist/cjs/*.d.ts",
26
+ "default": "./dist/cjs/*.js"
27
+ },
28
+ "default": "./dist/esm/*.js"
15
29
  }
16
30
  },
17
31
  "files": [
@@ -22,13 +36,22 @@
22
36
  "ethers": "^6"
23
37
  },
24
38
  "peerDependencies": {
25
- "@stas-b-woof/compound": "0.0.1"
39
+ "@stas-b-woof/compound": "1.0.0"
26
40
  },
41
+ "devDependencies": {
42
+ "viem": "^2.55.10",
43
+ "vite": "^8.2.0"
44
+ },
45
+ "main": "./dist/cjs/index.js",
46
+ "module": "./dist/esm/index.js",
47
+ "types": "./dist/esm/index.d.ts",
27
48
  "scripts": {
28
49
  "lint": "eslint .",
29
- "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
50
+ "build": "pnpm run build:esm && pnpm run build:cjs",
30
51
  "typecheck": "tsc -p tsconfig.json --noEmit",
31
52
  "test": "vitest run",
32
- "publish:local": "pnpm pack"
53
+ "publish:local": "pnpm pack",
54
+ "build:esm": "rm -rf dist && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
55
+ "build:cjs": "rm -rf dist/cjs && cp -R dist/esm dist/cjs && tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json"
33
56
  }
34
57
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"multicall3.abi.d.ts","sourceRoot":"","sources":["../../../src/abis/multicall3.abi.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC;AAEjD,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBzB,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"multicall3.abi.js","sourceRoot":"","sources":["../../../src/abis/multicall3.abi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAIjC,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,CACnC;IACE,wHAAwH;IACxH,kJAAkJ;IAClJ,sKAAsK;IACtK,8KAA8K;IAC9K,sDAAsD;IACtD,6EAA6E;IAC7E,8DAA8D;IAC9D,sDAAsD;IACtD,oEAAoE;IACpE,wEAAwE;IACxE,oEAAoE;IACpE,sEAAsE;IACtE,qEAAqE;IACrE,8DAA8D;IAC9D,sJAAsJ;IACtJ,sMAAsM;CACvM,CACF,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,aAAa,GACd,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,KAAK,aAAa,EAClB,aAAa,GACd,MAAM,0BAA0B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,GACd,MAAM,UAAU,CAAC;AAElB,OAAO,EAEL,aAAa,GACd,MAAM,0BAA0B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../../src/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,IAAI,EAeV,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAI9D,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,YAAY,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,QAAQ,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,aAAa,CAAC;CACtB,CAAC;AAEF,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa;kBAW/B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sFA4M0C,OAAO,CAAC,IAAI,CAAC;;EAQ3E"}
package/dist/src/rpc.js DELETED
@@ -1,179 +0,0 @@
1
- import { decodeFunctionResult, encodeFunctionData, asserts, isAddress, isHash, isHex, isKnownTransactionStatus, isKnownTransactionType, } from "@stas-b-woof/compound";
2
- import {} from "ethers/providers";
3
- import { multicall3Abi } from "./abis/multicall3.abi.js";
4
- export function makeEthersRpc(args) {
5
- const { mode = 'default', provider, signer, } = args;
6
- let callsStack = [];
7
- let currentRequest = null;
8
- return {
9
- ethCall: (tx) => {
10
- const _provider = provider();
11
- if (mode === 'default') {
12
- return _provider.call(tx);
13
- }
14
- else {
15
- return new Promise((rs, rj) => {
16
- const currentIndex = callsStack.length;
17
- callsStack.push(tx);
18
- const nextTick = Promise.resolve();
19
- nextTick.then(() => {
20
- if (callsStack.length > 1) {
21
- let callPromise;
22
- if (currentRequest) {
23
- callPromise = currentRequest;
24
- }
25
- else {
26
- const calls = callsStack.map((call) => ({
27
- target: call.to,
28
- callData: call.data || '0x',
29
- allowFailure: true,
30
- }));
31
- const data = encodeFunctionData(multicall3Abi, 'aggregate3', [calls]);
32
- callPromise = currentRequest = _provider.call({
33
- to: '0xcA11bde05977b3631167028862bE2a173976CA11', // multicall3 address
34
- data: data,
35
- });
36
- }
37
- const promise = callPromise;
38
- promise.then((bytes) => {
39
- const results = decodeFunctionResult(multicall3Abi, 'aggregate3', bytes);
40
- results.forEach((result, index) => {
41
- if (index !== currentIndex || !result)
42
- return;
43
- if (result.success) {
44
- rs(result.returnData);
45
- }
46
- else {
47
- rj(result.returnData);
48
- }
49
- });
50
- }, () => {
51
- throw new Error("Failed to make call");
52
- });
53
- promise.catch(rj);
54
- promise.finally(() => {
55
- currentRequest = null;
56
- callsStack = [];
57
- });
58
- }
59
- else {
60
- const call = callsStack[0];
61
- if (!call) {
62
- throw new Error("No call to make");
63
- }
64
- const promise = _provider.call(call);
65
- promise.then(rs, rj);
66
- promise.catch(rj);
67
- promise.finally(() => {
68
- currentRequest = null;
69
- callsStack = [];
70
- });
71
- }
72
- });
73
- });
74
- }
75
- },
76
- ethGasPrice: async () => {
77
- const _provider = provider();
78
- const { gasPrice } = await _provider.getFeeData();
79
- return gasPrice || 0n;
80
- },
81
- ethBlockNumber: async () => {
82
- const _provider = provider();
83
- const block = await _provider.getBlockNumber();
84
- return BigInt(block);
85
- },
86
- ethGetTransactionCount: async ({ address, block }) => {
87
- const _provider = provider();
88
- const nonce = await _provider.getTransactionCount(address, block);
89
- return BigInt(nonce) || 0n;
90
- },
91
- ethEstimateGas: async (tx) => {
92
- const _provider = provider();
93
- const gas = await _provider.estimateGas({
94
- ...(tx.to !== undefined ? { to: tx.to } : {}),
95
- ...(tx.from !== undefined ? { from: tx.from } : {}),
96
- ...(tx.data !== undefined ? { data: tx.data } : {}),
97
- ...(tx.value !== undefined ? { value: `0x${tx.value.toString(16)}` } : {}),
98
- });
99
- return gas;
100
- },
101
- ethSendTransaction: async (tx) => {
102
- const _provider = signer?.();
103
- if (!_provider) {
104
- throw new Error("Signer is not defined. Please provide signer to use transaction sending.");
105
- }
106
- const { hash } = await _provider.sendTransaction({
107
- ...(tx.to !== undefined ? { to: tx.to } : {}),
108
- ...(tx.from !== undefined ? { from: tx.from } : {}),
109
- ...(tx.data !== undefined ? { data: tx.data } : {}),
110
- ...(tx.value !== undefined ? { value: tx.value } : {}),
111
- ...(tx.gasPrice !== undefined ? { gasPrice: tx.gasPrice } : {}),
112
- ...(tx.maxFeePerGas !== undefined ? { maxFeePerGas: tx.maxFeePerGas } : {}),
113
- ...(tx.maxPriorityFeePerGas !== undefined ? { maxPriorityFeePerGas: tx.maxPriorityFeePerGas } : {}),
114
- ...(tx.nonce !== undefined ? { nonce: Number(tx.nonce) } : {}),
115
- });
116
- asserts(isHash(hash), "Transaction hash is not a hash");
117
- return hash;
118
- },
119
- ethGetTransactionReceipt: async ({ hash }) => {
120
- const _provider = provider();
121
- const receipt = await _provider.getTransactionReceipt(hash);
122
- if (receipt === null) {
123
- return null;
124
- }
125
- asserts(isAddress(receipt.from), "Transaction from is not an address");
126
- asserts(isHash(receipt.blockHash), "Transaction from is not an address");
127
- asserts(isHash(receipt.hash), "Transaction from is not an address");
128
- asserts(isHex(receipt.logsBloom), "Transaction from is not an address");
129
- asserts(isKnownTransactionStatus(receipt.status), "Transaction type is not 0 or 1");
130
- asserts(isKnownTransactionType(receipt.type), "Transaction type is not 0, 1 or 2");
131
- const sharedTxData = {
132
- from: receipt.from,
133
- type: receipt.type,
134
- blockHash: receipt.blockHash,
135
- blockNumber: BigInt(receipt.blockNumber),
136
- gasUsed: receipt.gasUsed,
137
- status: receipt.status,
138
- transactionHash: receipt.hash,
139
- transactionIndex: BigInt(receipt.index),
140
- cumulativeGasUsed: receipt.cumulativeGasUsed,
141
- logsBloom: receipt.logsBloom,
142
- };
143
- if (receipt.to) {
144
- asserts(isAddress(receipt.to), "Transaction to is not an address");
145
- return {
146
- ...sharedTxData,
147
- to: receipt.to,
148
- contractAddress: null,
149
- };
150
- }
151
- else {
152
- asserts(isAddress(receipt.contractAddress), "Transaction contractAddress is not an address");
153
- return {
154
- ...sharedTxData,
155
- to: null,
156
- contractAddress: receipt.contractAddress,
157
- };
158
- }
159
- },
160
- ethChainId: async () => {
161
- const _provider = provider();
162
- const { chainId } = await _provider.getNetwork();
163
- return BigInt(chainId);
164
- },
165
- ethSignTypedData: (args) => {
166
- const { domain, types, values, } = args;
167
- const _provider = signer?.();
168
- if (!_provider) {
169
- throw new Error("Signer is not defined. Please provide signer to use transaction sending.");
170
- }
171
- return _provider.signTypedData(domain, types, values);
172
- },
173
- ethGetBalance: (address, block) => {
174
- const _provider = provider();
175
- return _provider.getBalance(address, block);
176
- }
177
- };
178
- }
179
- //# sourceMappingURL=rpc.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../src/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,oBAAoB,EACpB,kBAAkB,EAClB,OAAO,EACP,SAAS,EACT,MAAM,EACN,KAAK,EACL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAA8B,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAUzD,MAAM,UAAU,aAAa,CAAC,IAAmB;IAC/C,MAAM,EACJ,IAAI,GAAG,SAAS,EAChB,QAAQ,EACR,MAAM,GACP,GAAG,IAAI,CAAC;IAET,IAAI,UAAU,GAAoB,EAAE,CAAC;IACrC,IAAI,cAAc,GAA2B,IAAI,CAAC;IAElD,OAAO;QACL,OAAO,EAAE,CAAC,EAAO,EAAE,EAAE;YACnB,MAAM,SAAS,GAAG,QAAQ,EAAE,CAAC;YAE7B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,OAAO,SAAS,CAAC,IAAI,CAAC,EAAE,CAAiB,CAAC;YAC5C,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,OAAO,CAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE;oBACjC,MAAM,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC;oBAEvC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oBAEpB,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;oBAEnC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE;wBACjB,IAAI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