Skip to content

Commit 0496387

Browse files
committed
feat: update extension_multicallERC20UniswapBalance Node Extension
1 parent 1b3af5c commit 0496387

File tree

9 files changed

+3879
-1827
lines changed

9 files changed

+3879
-1827
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This library is a collection of Tenderly Node Extensions. It’s used to extend
2020

2121
Node Extensions are a game-changing enhancement to our existing production node. This feature allows devs to create custom JSON-RPC method names and write custom JS/TS code snippets that are executed each time the method is called. It’s like having your very own sorcerer’s apprentice working behind the scenes! 🧙‍
2222

23-
> ### **Note:** Node Extensions require [@tenderly/actions](https://github.com/Tenderly/tenderly-actions) version >= **0.2.0**.
23+
> ### **Note:** Node Extensions require [@tenderly/actions](https://github.com/Tenderly/tenderly-actions) version >= **0.2.0**.
2424
2525
## Getting Started
2626

chainlink-price-feed/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Go to JSON-RPC Request Builder and select "Chainlink Price Feed" from the dropdo
2323

2424
Parameters
2525

26-
1. DATA, Coin pair.
26+
1. **DATA**, Coin pair.
2727

2828
Example:
2929
```json
Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# Multicall ERC20 Uniswap Balance Extension
22

3-
This extension uses [Wonderland's](https://twitter.com/defi_wonderland) multicall strategy to fetch Uniswap's ERC20 balance in the range [{{offset}}, {{offset}}+{{limit}}] of all pairs. Multicall optimizes `eth_call` performance and lower the consumption of the node RPC.
3+
This extension uses [Wonderland's](https://twitter.com/defi_wonderland) multicall strategy to fetch Uniswap's ERC20
4+
balance in the range `[{{offset}}, {{offset}}+{{limit}}]` of all pairs. Multicall optimizes `eth_call` performance and
5+
lower the consumption of the node RPC.
46

57
## Installation
68

7-
Go to the Extensions Library and search for "Multicall ERC20 Uniswap Balance". Click on the extension and click "Activate".
9+
Go to the Extensions Library and search for "Multicall ERC20 Uniswap Balance". Click on the extension and click
10+
"Activate".
811

912
## Usage
1013

11-
Go to JSON-RPC Request Builder and select "Multicall ERC20 Uniswap Balance" from the dropdown menu. You can then enter the JSON payload and click "Send Request".
14+
Go to JSON-RPC Request Builder and select "Multicall ERC20 Uniswap Balance" from the dropdown menu. You can then enter
15+
the JSON payload and click "Send Request".
1216

1317
## Method
1418

@@ -18,28 +22,36 @@ Go to JSON-RPC Request Builder and select "Multicall ERC20 Uniswap Balance" from
1822

1923
Parameters
2024

21-
1. QUANTITY, offset of the query.
22-
2. QUANTITY, limit of the query.
25+
1. **QUANTITY**, offset of the query.
26+
2. **QUANTITY**, limit of the query.
2327

2428
Example:
29+
2530
```json
2631
{
27-
"id": "1",
32+
"id": 0,
2833
"jsonrpc": "2.0",
2934
"method": "extension_multicallERC20UniswapBalance",
30-
"params": ["0x0", "0x100"]
35+
"params": [
36+
"0x0",
37+
"0x100"
38+
]
3139
}
3240
```
3341

3442
### Response
3543

36-
37-
3844
Example:
45+
3946
```json
4047
{
41-
"id":0,
48+
"id": 0,
4249
"jsonrpc": "2.0",
43-
"result": {}
50+
"result": [
51+
"0x0", "0x0", "0x0", "0x0", "0x0",
52+
"0x0", "0x0", "0x0", "0x0", "0x0",
53+
"0x0", "0x0", "0x0", "0x0", "0x0",
54+
"..."
55+
]
4456
}
4557
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TENDERLY_WEB3_GATEWAY_ACCESS_TOKEN=

multicall-uniswap-erc20-balance/actions/constants/constants.ts

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
21
const BatchRequestJSON = {
3-
"_format": "hh-sol-artifact-1",
4-
"contractName": "BatchRequest",
5-
"sourceName": "solidity/contracts/BatchRequest.sol",
6-
"abi": [
2+
'_format': 'hh-sol-artifact-1',
3+
'contractName': 'BatchRequest',
4+
'sourceName': 'solidity/contracts/BatchRequest.sol',
5+
'abi': [
76
{
8-
"inputs": [
7+
'inputs': [
98
{
10-
"internalType": "uint256",
11-
"name": "from",
12-
"type": "uint256"
9+
'internalType': 'uint256',
10+
'name': 'from',
11+
'type': 'uint256',
1312
},
1413
{
15-
"internalType": "uint256",
16-
"name": "step",
17-
"type": "uint256"
14+
'internalType': 'uint256',
15+
'name': 'step',
16+
'type': 'uint256',
1817
},
1918
{
20-
"internalType": "address",
21-
"name": "factory",
22-
"type": "address"
23-
}
19+
'internalType': 'address',
20+
'name': 'factory',
21+
'type': 'address',
22+
},
2423
],
25-
"stateMutability": "nonpayable",
26-
"type": "constructor"
27-
}
24+
'stateMutability': 'nonpayable',
25+
'type': 'constructor',
26+
},
2827
],
29-
"bytecode": "0x608060405234801561001057600080fd5b506040516105773803806105778339818101604052810190610032919061028c565b60008267ffffffffffffffff81111561004e5761004d6102df565b5b60405190808252806020026020018201604052801561007c5781602001602082028036833780820191505090505b50905060005b838110156101c45760008373ffffffffffffffffffffffffffffffffffffffff16631e3dd18b83886100b4919061033d565b6040518263ffffffff1660e01b81526004016100d09190610380565b6020604051808303816000875af11580156100ef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610113919061039b565b90508073ffffffffffffffffffffffffffffffffffffffff166370a08231826040518263ffffffff1660e01b815260040161014e91906103d7565b6020604051808303816000875af115801561016d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061019191906103f2565b8383815181106101a4576101a361041f565b5b6020026020010181815250505080806101bc9061044e565b915050610082565b506000816040516020016101d89190610554565b60405160208183030381529060405290506020810180590381f35b600080fd5b6000819050919050565b61020b816101f8565b811461021657600080fd5b50565b60008151905061022881610202565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006102598261022e565b9050919050565b6102698161024e565b811461027457600080fd5b50565b60008151905061028681610260565b92915050565b6000806000606084860312156102a5576102a46101f3565b5b60006102b386828701610219565b93505060206102c486828701610219565b92505060406102d586828701610277565b9150509250925092565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610348826101f8565b9150610353836101f8565b925082820190508082111561036b5761036a61030e565b5b92915050565b61037a816101f8565b82525050565b60006020820190506103956000830184610371565b92915050565b6000602082840312156103b1576103b06101f3565b5b60006103bf84828501610277565b91505092915050565b6103d18161024e565b82525050565b60006020820190506103ec60008301846103c8565b92915050565b600060208284031215610408576104076101f3565b5b600061041684828501610219565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000610459826101f8565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361048b5761048a61030e565b5b600182019050919050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6104cb816101f8565b82525050565b60006104dd83836104c2565b60208301905092915050565b6000602082019050919050565b600061050182610496565b61050b81856104a1565b9350610516836104b2565b8060005b8381101561054757815161052e88826104d1565b9750610539836104e9565b92505060018101905061051a565b5085935050505092915050565b6000602082019050818103600083015261056e81846104f6565b90509291505056fe",
30-
"deployedBytecode": "0x6080604052600080fdfea2646970667358221220daa9a04416c375c31ac088750e956109b9ae77cd014111cd20ace6b4d4746cf864736f6c63430008100033",
31-
"linkReferences": {},
32-
"deployedLinkReferences": {}
33-
}
34-
35-
28+
'bytecode': '0x608060405234801561001057600080fd5b506040516105773803806105778339818101604052810190610032919061028c565b60008267ffffffffffffffff81111561004e5761004d6102df565b5b60405190808252806020026020018201604052801561007c5781602001602082028036833780820191505090505b50905060005b838110156101c45760008373ffffffffffffffffffffffffffffffffffffffff16631e3dd18b83886100b4919061033d565b6040518263ffffffff1660e01b81526004016100d09190610380565b6020604051808303816000875af11580156100ef573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610113919061039b565b90508073ffffffffffffffffffffffffffffffffffffffff166370a08231826040518263ffffffff1660e01b815260040161014e91906103d7565b6020604051808303816000875af115801561016d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061019191906103f2565b8383815181106101a4576101a361041f565b5b6020026020010181815250505080806101bc9061044e565b915050610082565b506000816040516020016101d89190610554565b60405160208183030381529060405290506020810180590381f35b600080fd5b6000819050919050565b61020b816101f8565b811461021657600080fd5b50565b60008151905061022881610202565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006102598261022e565b9050919050565b6102698161024e565b811461027457600080fd5b50565b60008151905061028681610260565b92915050565b6000806000606084860312156102a5576102a46101f3565b5b60006102b386828701610219565b93505060206102c486828701610219565b92505060406102d586828701610277565b9150509250925092565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610348826101f8565b9150610353836101f8565b925082820190508082111561036b5761036a61030e565b5b92915050565b61037a816101f8565b82525050565b60006020820190506103956000830184610371565b92915050565b6000602082840312156103b1576103b06101f3565b5b60006103bf84828501610277565b91505092915050565b6103d18161024e565b82525050565b60006020820190506103ec60008301846103c8565b92915050565b600060208284031215610408576104076101f3565b5b600061041684828501610219565b91505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000610459826101f8565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361048b5761048a61030e565b5b600182019050919050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6104cb816101f8565b82525050565b60006104dd83836104c2565b60208301905092915050565b6000602082019050919050565b600061050182610496565b61050b81856104a1565b9350610516836104b2565b8060005b8381101561054757815161052e88826104d1565b9750610539836104e9565b92505060018101905061051a565b5085935050505092915050565b6000602082019050818103600083015261056e81846104f6565b90509291505056fe',
29+
'deployedBytecode': '0x6080604052600080fdfea2646970667358221220daa9a04416c375c31ac088750e956109b9ae77cd014111cd20ace6b4d4746cf864736f6c63430008100033',
30+
'linkReferences': {},
31+
'deployedLinkReferences': {},
32+
};
3633

3734
export {
3835
BatchRequestJSON,

multicall-uniswap-erc20-balance/actions/extension.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {ActionFn, Context, Event, ExtensionEvent} from '@tenderly/actions';
1+
import { ActionFn, Context, Event, ExtensionEvent } from '@tenderly/actions';
22
import { ethers } from 'ethers';
3-
import {BatchRequestJSON} from "./constants/constants";
3+
import { BatchRequestJSON } from './constants/constants';
44

5-
const FACTORY = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"; // Pairs deployed: 10000835
6-
const abi = ["function allPairsLength() external view returns (uint)"];
5+
const FACTORY = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'; // Pairs deployed: 10000835
6+
const abi = ['function allPairsLength() external view returns (uint)'];
77

88
export const multicallUniswapERC20Balance: ActionFn = async (context: Context, event: Event) => {
99
// Casting the event to a ExtensionEvent
@@ -15,31 +15,31 @@ export const multicallUniswapERC20Balance: ActionFn = async (context: Context, e
1515
// Using the Ethers.js provider class to call the RPC URL
1616
const provider = new ethers.providers.JsonRpcProvider(defaultGatewayURL);
1717

18-
// Getting the input data from the webhook event
19-
const [ offsetHex, limitHex ] = params;
20-
const offset = parseInt(offsetHex)
21-
const limit = parseInt(limitHex)
18+
// Getting the input data from the node extension event
19+
const [offsetHex, limitHex] = params;
20+
const offset = parseInt(offsetHex);
21+
const limit = parseInt(limitHex);
2222

2323
const step = 200;
2424
const factory = new ethers.Contract(FACTORY, abi, provider);
2525
const pairsLength = await factory.allPairsLength();
2626

2727
if (limit > 1000) {
28-
throw new Error(`limit exceeds maximum value of 1000`);
28+
throw new Error(`Limit exceeds maximum value of 1000.`);
2929
}
3030

3131
if ((offset + limit) > pairsLength) {
32-
throw new Error('offset + limit exceeds number of pairs length');
32+
throw new Error('Offset + limit exceeds number of pairs length.');
3333
}
3434

35-
const values = []
35+
const values = [];
3636

3737
// Iterate by batches
3838
for (let i = offset; i < offset + limit; i += step) {
39-
// Get the bytecode and append the consturctor args
39+
// Get the bytecode and append the constructor args
4040
let inputData = ethers.utils.defaultAbiCoder.encode(
41-
["uint256", "uint256", "address"],
42-
[i, step, FACTORY]
41+
['uint256', 'uint256', 'address'],
42+
[i, step, FACTORY],
4343
);
4444

4545
const payload = BatchRequestJSON.bytecode.concat(inputData.slice(2));
@@ -49,13 +49,13 @@ export const multicallUniswapERC20Balance: ActionFn = async (context: Context, e
4949

5050
// Abi decode the array
5151
const [decoded] = ethers.utils.defaultAbiCoder.decode(
52-
["uint256[]"],
53-
returnedData
52+
['uint256[]'],
53+
returnedData,
5454
);
5555

5656
// add balances to the array
5757
for (let j = 0; j < decoded.length; j++) {
58-
values.push(decoded[j]._hex)
58+
values.push(decoded[j]._hex);
5959
}
6060
}
6161

0 commit comments

Comments
 (0)