Skip to content

Commit b75cda9

Browse files
authored
Merge branch 'main' into feat-subgraph-composition
2 parents 76bee17 + 023bac6 commit b75cda9

File tree

12 files changed

+285
-152
lines changed

12 files changed

+285
-152
lines changed

.changeset/cold-snails-bake.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

.changeset/gold-deers-kick.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

.changeset/wild-weeks-protect.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/cli/CHANGELOG.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,106 @@
11
# @graphprotocol/graph-cli
22

3+
## 0.90.1
4+
5+
### Patch Changes
6+
7+
- [#1776](https://github.com/graphprotocol/graph-tooling/pull/1776)
8+
[`c4c0590`](https://github.com/graphprotocol/graph-tooling/commit/c4c059029c391dd6e256a56b3b90bcf20b86680c)
9+
Thanks [@alinobrasil](https://github.com/alinobrasil)! - Fix testnet names for `abstract` and
10+
`corn`
11+
12+
## 0.90.0
13+
14+
### Minor Changes
15+
16+
- [`098b433`](https://github.com/graphprotocol/graph-tooling/commit/098b433815390e5aff2e0e52f22ab0ee44b9c206)
17+
Thanks [@DenisCarriere](https://github.com/DenisCarriere)! - Update deprecated endpoints and
18+
support API key for updating published subgraphs
19+
20+
### Patch Changes
21+
22+
- [#1771](https://github.com/graphprotocol/graph-tooling/pull/1771)
23+
[`93271b0`](https://github.com/graphprotocol/graph-tooling/commit/93271b07116752c74419720a39c1fdbd460c078d)
24+
Thanks [@0237h](https://github.com/0237h)! - Support parsing full path contract name from block
25+
explorers
26+
27+
- [#1774](https://github.com/graphprotocol/graph-tooling/pull/1774)
28+
[`5d9f0c9`](https://github.com/graphprotocol/graph-tooling/commit/5d9f0c9c9d714d95ed455deb02137ea5440f3e2d)
29+
Thanks [@0237h](https://github.com/0237h)! - Add new chains: `abstract-testnet`, `corn` and
30+
`corn-testnet`
31+
32+
- [#1767](https://github.com/graphprotocol/graph-tooling/pull/1767)
33+
[`6f2cb45`](https://github.com/graphprotocol/graph-tooling/commit/6f2cb45e5a07d8de2946a485763feb0b1bcfd4f0)
34+
Thanks [@0237h](https://github.com/0237h)! - Fix CLI validation for `startBlock` and
35+
`contractName` fetched from external APIs
36+
37+
## 0.89.0
38+
39+
### Minor Changes
40+
41+
- [#1763](https://github.com/graphprotocol/graph-tooling/pull/1763)
42+
[`58dbd28`](https://github.com/graphprotocol/graph-tooling/commit/58dbd2845b9e336bb06d7cee09929a92db7f2cf5)
43+
Thanks [@alinobrasil](https://github.com/alinobrasil)! - Add new chain: Lens testnet
44+
45+
### Patch Changes
46+
47+
- [#1759](https://github.com/graphprotocol/graph-tooling/pull/1759)
48+
[`1d4217a`](https://github.com/graphprotocol/graph-tooling/commit/1d4217a506b38307ad0d750a9abe37bffa0a734d)
49+
Thanks [@0237h](https://github.com/0237h)! - Refactor debug log for failed Etherscan ABI lookups
50+
51+
- [#1764](https://github.com/graphprotocol/graph-tooling/pull/1764)
52+
[`0b4cfe9`](https://github.com/graphprotocol/graph-tooling/commit/0b4cfe91091a86a0871d486f91754ea87f302b3e)
53+
Thanks [@adamazad](https://github.com/adamazad)! - chore(rpcs): update gnosis chain RPC endpoint
54+
55+
- [#1766](https://github.com/graphprotocol/graph-tooling/pull/1766)
56+
[`d2fda94`](https://github.com/graphprotocol/graph-tooling/commit/d2fda940ace2b719354df9da43890c559ebfd3a8)
57+
Thanks [@0237h](https://github.com/0237h)! - Improve ABI file path validation
58+
59+
- [#1761](https://github.com/graphprotocol/graph-tooling/pull/1761)
60+
[`baf36b4`](https://github.com/graphprotocol/graph-tooling/commit/baf36b42bc531f3aee2709c2f55682a7ec44e5ac)
61+
Thanks [@alinobrasil](https://github.com/alinobrasil)! - update soneium-testnet blockexplorer url
62+
63+
## 0.88.0
64+
65+
### Minor Changes
66+
67+
- [#1680](https://github.com/graphprotocol/graph-tooling/pull/1680)
68+
[`08914a8`](https://github.com/graphprotocol/graph-tooling/commit/08914a89179e31363765bb3a6e72945f4585e207)
69+
Thanks [@saihaj](https://github.com/saihaj)! - Breaking changes to the CLI to prepare for the
70+
sunset of the hosted service.
71+
72+
- `graph auth`
73+
- Removed `--product` flag
74+
- Removed `--studio` flag
75+
- Removed `node` argument
76+
- `graph deploy`
77+
- Removed `--product` flag
78+
- Removed `--studio` flag
79+
- Removed `--from-hosted-service` flag
80+
- `graph init`
81+
- Removed `--product` flag
82+
- Removed `--studio` flag
83+
- Removed `--allow-simple-name` flag
84+
85+
- [#1749](https://github.com/graphprotocol/graph-tooling/pull/1749)
86+
[`bf43cbf`](https://github.com/graphprotocol/graph-tooling/commit/bf43cbf8283c53f0005d7cb9dfa681c92f3a6a91)
87+
Thanks [@0237h](https://github.com/0237h)! - Add warning for available CLI updates
88+
89+
### Patch Changes
90+
91+
- [#1751](https://github.com/graphprotocol/graph-tooling/pull/1751)
92+
[`0ba99dc`](https://github.com/graphprotocol/graph-tooling/commit/0ba99dcd6783fb20779d4f5a6791fc155969939e)
93+
Thanks [@0237h](https://github.com/0237h)! - Using `graph add` with `localhost` network now
94+
prompts the user for input
95+
96+
- [#1750](https://github.com/graphprotocol/graph-tooling/pull/1750)
97+
[`d764867`](https://github.com/graphprotocol/graph-tooling/commit/d764867dc7eab32e2f1db8505419ea4fa03ed503)
98+
Thanks [@0237h](https://github.com/0237h)! - Add prompt for existing directory in `init` flow
99+
100+
- [#1756](https://github.com/graphprotocol/graph-tooling/pull/1756)
101+
[`04bd901`](https://github.com/graphprotocol/graph-tooling/commit/04bd901d3ff974c197b82fd29426309ce7de1558)
102+
Thanks [@0237h](https://github.com/0237h)! - Fix `matic` RPC endpoint and improve error message
103+
3104
## 0.87.0
4105

5106
### Minor Changes

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphprotocol/graph-cli",
3-
"version": "0.87.0",
3+
"version": "0.90.1",
44
"description": "CLI for building for and deploying to The Graph",
55
"license": "(Apache-2.0 OR MIT)",
66
"engines": {

packages/cli/src/command-helpers/abi.ts

Lines changed: 71 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ import { withSpinner } from './spinner';
77

88
const logger = debugFactory('graph-cli:abi-helpers');
99

10+
const fetchFromEtherscan = async (url: string): Promise<any | null> => {
11+
const result = await fetch(url);
12+
let json: any = {};
13+
14+
if (result.ok) {
15+
json = await result.json().catch(error => {
16+
throw new Error(`Failed to read JSON response from Etherscan: ${error}`);
17+
});
18+
19+
// Etherscan returns a JSON object that has a `status`, a `message` and
20+
// a `result` field. The `status` is '0' in case of errors and '1' in
21+
// case of success
22+
if (json.status === '1') return json;
23+
}
24+
25+
logger(
26+
'Failed to fetchFromEtherscan: [%s] %s (%s)\n%O',
27+
result.status,
28+
result.statusText,
29+
result.url,
30+
json,
31+
);
32+
return null;
33+
};
34+
1035
export const loadAbiFromEtherscan = async (
1136
ABICtor: typeof ABI,
1237
network: string,
@@ -18,16 +43,14 @@ export const loadAbiFromEtherscan = async (
1843
`Warnings while fetching ABI from Etherscan`,
1944
async () => {
2045
const scanApiUrl = getEtherscanLikeAPIUrl(network);
21-
const result = await fetch(`${scanApiUrl}?module=contract&action=getabi&address=${address}`);
22-
const json = await result.json();
46+
const json = await fetchFromEtherscan(
47+
`${scanApiUrl}?module=contract&action=getabi&address=${address}`,
48+
);
2349

24-
// Etherscan returns a JSON object that has a `status`, a `message` and
25-
// a `result` field. The `status` is '0' in case of errors and '1' in
26-
// case of success
27-
if (json.status === '1') {
50+
if (json)
2851
return new ABICtor('Contract', undefined, immutable.fromJS(JSON.parse(json.result)));
29-
}
30-
throw new Error('ABI not found, try loading it from a local file');
52+
53+
throw new Error('Try loading it from a local file');
3154
},
3255
);
3356

@@ -62,11 +85,11 @@ export const fetchDeployContractTransactionFromEtherscan = async (
6285
address: string,
6386
): Promise<string> => {
6487
const scanApiUrl = getEtherscanLikeAPIUrl(network);
65-
const json = await fetchContractCreationHashWithRetry(
88+
const json = await fetchFromEtherscan(
6689
`${scanApiUrl}?module=contract&action=getcontractcreation&contractaddresses=${address}`,
67-
5,
6890
);
69-
if (json.status === '1') {
91+
92+
if (json) {
7093
const hash = json.result[0].txHash;
7194
logger('Successfully fetchDeployContractTransactionFromEtherscan. txHash: %s', hash);
7295
return hash;
@@ -75,33 +98,13 @@ export const fetchDeployContractTransactionFromEtherscan = async (
7598
throw new Error(`Failed to fetch deploy contract transaction`);
7699
};
77100

78-
export const fetchContractCreationHashWithRetry = async (
79-
url: string,
80-
retryCount: number,
81-
): Promise<any> => {
82-
let json;
83-
for (let i = 0; i < retryCount; i++) {
84-
try {
85-
const result = await fetch(url);
86-
json = await result.json();
87-
if (json.status !== '0') {
88-
return json;
89-
}
90-
} catch (error) {
91-
logger('Failed to fetchContractCreationHashWithRetry: %O', error);
92-
/* empty */
93-
}
94-
}
95-
throw new Error(`Failed to fetch contract creation transaction hash`);
96-
};
97-
98101
export const fetchTransactionByHashFromRPC = async (
99102
network: string,
100103
transactionHash: string,
101104
): Promise<any> => {
102105
let json: any;
106+
const RPCURL = getPublicRPCEndpoint(network);
103107
try {
104-
const RPCURL = getPublicRPCEndpoint(network);
105108
if (!RPCURL) throw new Error(`Unable to fetch RPC URL for ${network}`);
106109
const result = await fetch(String(RPCURL), {
107110
method: 'POST',
@@ -120,7 +123,9 @@ export const fetchTransactionByHashFromRPC = async (
120123
return json;
121124
} catch (error) {
122125
logger('Failed to fetchTransactionByHashFromRPC: %O', error);
123-
throw new Error('Failed to fetch contract creation transaction');
126+
throw new Error(
127+
`Failed to run \`eth_getTransactionByHash\` on RPC (${RPCURL}) (run with env \`DEBUG=*\` for full error).`,
128+
);
124129
}
125130
};
126131

@@ -129,14 +134,15 @@ export const fetchSourceCodeFromEtherscan = async (
129134
address: string,
130135
): Promise<any> => {
131136
const scanApiUrl = getEtherscanLikeAPIUrl(network);
132-
const result = await fetch(
137+
const json = await fetchFromEtherscan(
133138
`${scanApiUrl}?module=contract&action=getsourcecode&address=${address}`,
134139
);
135-
const json = await result.json();
136-
if (json.status === '1') {
137-
return json;
138-
}
139-
throw new Error('Failed to fetch contract source code');
140+
141+
// Have to check that the SourceCode response is not empty due to Etherscan API bug responding with
142+
// 1 - OK on non-valid contracts.
143+
if (json.result[0].SourceCode) return json;
144+
145+
throw new Error(`Failed to fetch contract source code: ${json.result[0].ABI}`);
140146
};
141147

142148
export const getContractNameForAddress = async (
@@ -145,7 +151,13 @@ export const getContractNameForAddress = async (
145151
): Promise<string> => {
146152
try {
147153
const contractSourceCode = await fetchSourceCodeFromEtherscan(network, address);
148-
const contractName = contractSourceCode.result[0].ContractName;
154+
let contractName: string = contractSourceCode.result[0].ContractName;
155+
156+
// Some explorers will return the full path of the contract instead of just the name
157+
// Example: contracts/SyncSwapRouter.sol:SyncSwapRouter
158+
if (contractName.includes(':'))
159+
contractName = contractName.substring(contractName.lastIndexOf(':') + 1);
160+
149161
logger('Successfully getContractNameForAddress. contractName: %s', contractName);
150162
return contractName;
151163
} catch (error) {
@@ -319,7 +331,7 @@ const getEtherscanLikeAPIUrl = (network: string) => {
319331
case 'arbitrum-nova':
320332
return 'https://arbitrum-nova.abi.pinax.network/api';
321333
case 'soneium-testnet':
322-
return 'https://explorer-testnet.soneium.org/api';
334+
return 'https://soneium-minato.blockscout.com/api';
323335
case 'chiliz':
324336
return 'https://scan.chiliz.com/api';
325337
case 'chiliz-testnet':
@@ -338,6 +350,14 @@ const getEtherscanLikeAPIUrl = (network: string) => {
338350
return 'https://rootstock-testnet.blockscout.com/api';
339351
case 'unichain-testnet':
340352
return 'https://unichain-sepolia.blockscout.com/api';
353+
case 'lens-testnet':
354+
return 'https://block-explorer-api.testnet.lens.dev/api';
355+
case 'abstract-testnet':
356+
return 'https://block-explorer-api.testnet.abs.xyz/api';
357+
case 'corn':
358+
return 'https://maizenet-explorer.usecorn.com/api';
359+
case 'corn-testnet':
360+
return 'https://testnet-explorer.usecorn.com/api';
341361
default:
342362
return `https://api-${network}.etherscan.io/api`;
343363
}
@@ -383,11 +403,11 @@ const getPublicRPCEndpoint = (network: string) => {
383403
case 'goerli':
384404
return 'https://rpc.ankr.com/eth_goerli';
385405
case 'gnosis':
386-
return 'https://safe-transaction.gnosis.io';
406+
return 'https://rpc.gnosischain.com';
387407
case 'mainnet':
388408
return 'https://rpc.ankr.com/eth';
389409
case 'matic':
390-
return 'https://rpc-mainnet.maticvigil.com';
410+
return 'https://polygon-rpc.com/';
391411
case 'mbase':
392412
return 'https://rpc.moonbase.moonbeam.network';
393413
case 'mumbai':
@@ -494,6 +514,14 @@ const getPublicRPCEndpoint = (network: string) => {
494514
return 'https://public-en.kairos.node.kaia.io';
495515
case 'unichain-testnet':
496516
return 'https://sepolia.unichain.org';
517+
case 'lens-testnet':
518+
return 'https://api.staging.lens.zksync.dev';
519+
case 'abstract-testnet':
520+
return 'https://api.testnet.abs.xyz';
521+
case 'corn':
522+
return 'https://maizenet-rpc.usecorn.com';
523+
case 'corn-testnet':
524+
return 'https://testnet-rpc.usecorn.com';
497525
default:
498526
throw new Error(`Unknown network: ${network}`);
499527
}

0 commit comments

Comments
 (0)