Skip to content

Commit

Permalink
Merge pull request Synthetixio#231 from Synthetixio/goerli
Browse files Browse the repository at this point in the history
Goerli
  • Loading branch information
0xjocke authored Aug 4, 2022
2 parents c0d01bb + ceb9d05 commit 6d33329
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 103 deletions.
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"ethers": "^5.5.3",
"prettier": "^2.3.0",
"synthetix": "^2.74.1",
"synthetix": "^2.75.2",
"typescript": "^4.4.2"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"typescript": "^4.4.2"
},
"resolutions": {
"ethers": "^5.5.3"
"ethers": "^5.5.3",
"@ethersproject/abi": "^5.6.4"
},
"husky": {
"hooks": {
Expand Down
27 changes: 18 additions & 9 deletions packages/contracts-interface/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('@synthetixio/js tests', () => {
let snxjs: SynthetixJS;

beforeAll(() => {
snxjs = synthetix({ network: NetworkNameById[42] });
snxjs = synthetix({ network: NetworkNameById[5] });
});

test('should return contracts', () => {
Expand All @@ -17,7 +17,7 @@ describe('@synthetixio/js tests', () => {

test('should return different contracts for the OVM', () => {
const snxjsGoerli = synthetix({ network: NetworkNameById[5] });
const snxjsGoerliOvm = synthetix({ network: NetworkNameById[42] });
const snxjsGoerliOvm = synthetix({ network: NetworkNameById[420] });
const synthetixContractGoerli = snxjsGoerli.contracts['Synthetix'];
const synthetixContractGoerliOvm = snxjsGoerliOvm.contracts['Synthetix'];
expect(synthetixContractGoerli.address).not.toEqual(synthetixContractGoerliOvm.address);
Expand All @@ -27,17 +27,19 @@ describe('@synthetixio/js tests', () => {
const synthetixContract = snxjs.contracts['Synthetix'];
const sUSDContract = snxjs.contracts['SynthsUSD'];
const sETHContract = snxjs.contracts['SynthsETH'];
expect(synthetixContract.address).toEqual(snxjs.targets.ProxyERC20.address);
expect(sUSDContract.address).toEqual(snxjs.targets.ProxyERC20sUSD.address);
expect(synthetixContract.address).toEqual(snxjs.targets.ProxySynthetix.address);
expect(sUSDContract.address).toEqual(snxjs.targets.ProxysUSD.address);
expect(sETHContract.address).toEqual(snxjs.targets.ProxysETH.address);
});

test('should have the right mapping with the contracts for the OVM', () => {
const snxjsGoerliOvm = synthetix({ network: NetworkNameById[5], useOvm: true });
const synthetixContractGoerliOvm = snxjsGoerliOvm.contracts['Synthetix'];
const sUSDContractGoerliOvm = snxjsGoerliOvm.contracts['SynthsUSD'];
expect(synthetixContractGoerliOvm.address).toEqual(snxjsGoerliOvm.targets.ProxyERC20.address);
expect(sUSDContractGoerliOvm.address).toEqual(snxjsGoerliOvm.targets.ProxyERC20sUSD.address);
expect(synthetixContractGoerliOvm.address).toEqual(
snxjsGoerliOvm.targets.ProxySynthetix.address
);
expect(sUSDContractGoerliOvm.address).toEqual(snxjsGoerliOvm.targets.ProxysUSD.address);
});

test('should return the ethers object', () => {
Expand All @@ -46,12 +48,19 @@ describe('@synthetixio/js tests', () => {

test('should include the supported networks', () => {
expect(snxjs.networkToChainId[NetworkNameById[1]]).toBe(NetworkIdByName.mainnet.toString());
expect(snxjs.networkToChainId[NetworkNameById[42]]).toBe(NetworkIdByName.kovan.toString());
expect(snxjs.networkToChainId[NetworkNameById[10]]).toBe(
NetworkIdByName['mainnet-ovm'].toString()
);

expect(snxjs.networkToChainId[NetworkNameById[420]]).toBe(
NetworkIdByName['goerli-ovm'].toString()
);
expect(snxjs.networkToChainId[NetworkNameById[5]]).toBe(NetworkIdByName.goerli.toString());
});

test('should include the current network', () => {
expect(snxjs.network.name).toBe(NetworkNameById[42]);
expect(snxjs.network.id).toBe(NetworkIdByName.kovan.toString());
expect(snxjs.network.name).toBe(NetworkNameById[5]);
expect(snxjs.network.id).toBe(NetworkIdByName.goerli.toString());
});

test('should return users', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts-interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@synthetixio/contracts": "workspace:*",
"ethers": "^5.5.3",
"synthetix": "^2.74.1"
"synthetix": "^2.75.2"
},
"devDependencies": {
"@babel/core": "^7.11.0",
Expand Down
4 changes: 1 addition & 3 deletions packages/contracts-interface/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ const getSynthetixContracts = (
return Object.values(targets)
.map((target) => {
if (target.name === 'Synthetix') {
target.address = targets.ProxyERC20.address;
} else if (target.name === 'SynthsUSD') {
target.address = targets.ProxyERC20sUSD.address;
target.address = targets.ProxySynthetix.address;
} else if (target.name === 'FeePool') {
target.address = targets.ProxyFeePool.address;
} else if (target.name.match(/Synth(s|i)[a-zA-Z]+$/)) {
Expand Down
9 changes: 7 additions & 2 deletions packages/contracts-interface/src/synthetix.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ declare module 'synthetix' {
fork: false,
network: 'goerli',
},
420: {
useOvm: true,
fork: false,
network: 'goerli',
},
10: {
useOvm: true,
fork: false,
Expand All @@ -128,7 +133,7 @@ declare module 'synthetix' {
'-1': {
useOvm: true,
fork: false,
network: 'goerli',
network: 'invalid',
},
} as const;
export const networkToChainId = {
Expand All @@ -138,7 +143,7 @@ declare module 'synthetix' {
kovan: 42,
'kovan-ovm': 69,
'mainnet-fork': 31337,
'goerli-ovm': '-1',
'goerli-ovm': 420,
} as const;
// eslint-disable-next-line
export function getSynths(arg: { network: NetworkName; useOvm?: boolean }): any; // Note contract interface will generate enums for this and return the correct type to consumers
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts-interface/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Synths as OptimismSynths } from '@synthetixio/contracts/build/mainnet-o
export const NetworkIdByName = {
mainnet: 1,
goerli: 5,
'goerli-ovm': 420,
'mainnet-ovm': 10,
kovan: 42,
'kovan-ovm': 69,
Expand All @@ -29,6 +30,7 @@ export const NetworkNameById = {
42: 'kovan',
10: 'mainnet-ovm',
69: 'kovan-ovm',
420: 'goerli-ovm',
31337: 'mainnet-fork',
} as const;

Expand Down
17 changes: 17 additions & 0 deletions packages/optimism-networks/__tests__/switch-to-l1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ describe('switchToL1', () => {
params: [{ chainId: '0x2a' }],
});
});
test('Switch to gorli when optimism gorli is selected', async () => {
const requestMock = jest.fn().mockResolvedValue(undefined);
const arg = {
ethereum: {
isMetaMask: true,
request: requestMock,
chainId: '0x45',
},
} as any;

await switchToL1(arg);
expect(requestMock).toBeCalledTimes(1);
expect(requestMock).toHaveBeenCalledWith({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x2a' }],
});
});
test('Switch to mainnet when unsupported network selected', async () => {
const requestMock = jest.fn().mockResolvedValue(undefined);
const arg = {
Expand Down
31 changes: 24 additions & 7 deletions packages/optimism-networks/__tests__/switch-to-l2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ describe('switchToL2', () => {
params: [{ chainId: '0x45' }],
});
});
test('Switch to Optimism Goerli when Goerli selected ', async () => {
const requestMock = jest.fn().mockResolvedValue(undefined);
const deps = {
ethereum: {
isMetaMask: true,
request: requestMock,
chainId: '0x5',
},
} as any;

await switchToL2(deps);
expect(requestMock).toBeCalledTimes(1);
expect(requestMock).toHaveBeenCalledWith({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x1a4' }],
});
});
test('Switch to Optimism mainnet when unsupported network selected ', async () => {
const requestMock = jest.fn().mockResolvedValue(undefined);
const deps = {
Expand Down Expand Up @@ -89,7 +106,7 @@ describe('switchToL2', () => {
],
});
});
test('switchToL2 adds optimism kovan network when needed', async () => {
test('switchToL2 adds optimism gorli network when needed', async () => {
const requestMock = jest
.fn()
.mockRejectedValueOnce({ code: METAMASK_MISSING_NETWORK_ERROR_CODE }) // network missing in metamask
Expand All @@ -98,28 +115,28 @@ describe('switchToL2', () => {
ethereum: {
isMetaMask: true,
request: requestMock,
chainId: '0x2a',
chainId: '5',
},
} as any;
await switchToL2(deps);

expect(requestMock).toBeCalledTimes(2);
expect(requestMock).toHaveBeenNthCalledWith(1, {
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0x45' }],
params: [{ chainId: '0x1a4' }],
});
expect(requestMock).toHaveBeenNthCalledWith(2, {
method: 'wallet_addEthereumChain',
params: [
{
blockExplorerUrls: ['https://kovan-optimistic.etherscan.io'],
chainId: '0x45',
chainName: 'Optimism Kovan',
blockExplorerUrls: ['https://goerli-optimistic.etherscan.io'],
chainId: '0x1a4',
chainName: 'Optimism Goerli',
iconUrls: [
'https://optimism.io/images/metamask_icon.svg',
'https://optimism.io/images/metamask_icon.png',
],
rpcUrls: ['https://kovan.optimism.io'],
rpcUrls: ['https://goerli.optimism.io/'],
},
],
});
Expand Down
15 changes: 8 additions & 7 deletions packages/optimism-networks/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export const DEFAULT_LAYER2_NETWORK = 10;
export const L1_TO_L2_NETWORK_MAPPER: NetworkMapper = {
1: 10,
42: 69,
31337: 420,
5: 420,
};

export const L2_TO_L1_NETWORK_MAPPER: NetworkMapper = {
10: 1,
69: 42,
420: 31337,
420: 5,
};

export const OPTIMISM_NETWORKS: Record<number, OptimismNetwork> = {
Expand All @@ -27,11 +27,12 @@ export const OPTIMISM_NETWORKS: Record<number, OptimismNetwork> = {
'https://optimism.io/images/metamask_icon.png',
],
},
69: {
chainId: '0x45',
chainName: 'Optimism Kovan',
rpcUrls: ['https://kovan.optimism.io'],
blockExplorerUrls: ['https://kovan-optimistic.etherscan.io'],

420: {
chainId: '0x1a4',
chainName: 'Optimism Goerli',
rpcUrls: ['https://goerli.optimism.io/'],
blockExplorerUrls: ['https://goerli-optimistic.etherscan.io'],
iconUrls: [
'https://optimism.io/images/metamask_icon.svg',
'https://optimism.io/images/metamask_icon.png',
Expand Down
1 change: 1 addition & 0 deletions packages/optimism-networks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type OptimismNetwork = {
export enum NetworkId {
Mainnet = 10,
Kovan = 69,
Goerli = 420,
}

export type OptimismWatcher = {
Expand Down
9 changes: 6 additions & 3 deletions packages/queries/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ This library provides React hooks for retrieving data from the [Synthetix subgra
## Usage

Install `react-query` and `@synthetixio/queries`.

```
npm i react-query @synthetixio/queries
```

Add `QueryClientProvider` and `SynthetixQueryContextProvider` in a wrapping component.

```
import {
createQueryContext,
Expand All @@ -23,7 +25,7 @@ export default function MyApp() {
<QueryClientProvider client={queryClient}>
<SynthetixQueryContextProvider
value={createQueryContext({
networkId: 1 // Options: 1 (Mainnet), 10 (Optimism), 42 (Kovan), and 69 (Optimism Kovan)
networkId: 1 // Options: 1 (Mainnet), 10 (Optimism), 42 (Kovan), 69 (Optimism Kovan),42 (Goerli) and 69 (Optimism Goerli)
})}
>
<Component />
Expand All @@ -33,7 +35,8 @@ export default function MyApp() {
}
```

In a child component, import hooks from the `useSynthetixQueries()` function.
In a child component, import hooks from the `useSynthetixQueries()` function.

```
import useSynthetixQueries from '@synthetixio/queries'
Expand All @@ -60,7 +63,7 @@ export default function Component() {

### Subgraph Queries

`useSynthetixQueries().subgraph` contains two methods for [each entity on the Synthetix Subgraph](https://github.com/Synthetixio/synthetix-subgraph/blob/main/subgraphs/main.graphql), one for querying individual entities and another for groups. They are generated by the [codegen-graph-ts](https://github.com/dbeal-eth/codegen-graph-ts) library. For example, you can retrieve the daily candles for any synth with the `useSynthetixQueries().subgraph.useGetDailyCandleById()` and `useSynthetixQueries().subgraph.useGetDailyCandles()` hooks.
`useSynthetixQueries().subgraph` contains two methods for [each entity on the Synthetix Subgraph](https://github.com/Synthetixio/synthetix-subgraph/blob/main/subgraphs/main.graphql), one for querying individual entities and another for groups. They are generated by the [codegen-graph-ts](https://github.com/dbeal-eth/codegen-graph-ts) library. For example, you can retrieve the daily candles for any synth with the `useSynthetixQueries().subgraph.useGetDailyCandleById()` and `useSynthetixQueries().subgraph.useGetDailyCandles()` hooks.

_Note that IDs follow different conventions depending on the entity. See the comments in [the GraphQL file](https://github.com/Synthetixio/synthetix-subgraph/blob/main/subgraphs/main.graphql) or [the implementation of the mappings](https://github.com/Synthetixio/synthetix-subgraph/tree/main/src) for more information._

Expand Down
7 changes: 7 additions & 0 deletions packages/queries/__tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"rules": {
"no-console": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-non-null-assertion": "off"
}
}
Loading

0 comments on commit 6d33329

Please sign in to comment.