Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASL-4995] replace goerli with holesky as ethereum testnet #180

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ npm install @qubic-js/browser
```javascript
enum Network {
MAINNET,
GOERLI,
HOLESKY,
POLYGON,
MUMBAI,
BSC,
Expand Down
15 changes: 7 additions & 8 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { compareAddressAndLog } from './utils';

const qubicWalletConnector = wrappedConnectors.qubic[0] as QubicWalletConnector;

// https://goerli.etherscan.io/address/0x022E292b44B5a146F2e8ee36Ff44D3dd863C915c
const ERC_20_EXAMPLE_CONTRACT_ADDRESS = '0x022E292b44B5a146F2e8ee36Ff44D3dd863C915c';
const ERC_20_EXAMPLE_CHAIN_ID = 5;
// https://holesky.etherscan.io/address/0xe20c80EEf6911888D2A13FB181B476cd5E47f6B3
const ERC_20_EXAMPLE_CONTRACT_ADDRESS = '0xe20c80EEf6911888D2A13FB181B476cd5E47f6B3';
const ERC_20_EXAMPLE_CHAIN_ID = 17000;
const ERC_20_EXAMPLE_EXPLORER_TX = NETWORK_INFO[ERC_20_EXAMPLE_CHAIN_ID].explorerUrl + '/tx';

// These are from dev/stag/prod creator contract
Expand Down Expand Up @@ -537,11 +537,10 @@ function App() {
[address, network, web3Provider],
);

// TODO: should update contractAddress when new contract deploy
const handleGoerliMint = useCallback(async () => {
const handleHoleskyMint = useCallback(async () => {
handleNftMint({
targetNetwork: Network.GOERLI,
contractAddress: '0x5BF70eA03D7747f574A30227599AE26Bc6Be5C00',
targetNetwork: Network.HOLESKY,
contractAddress: '0x3978aaae125cba044d1d2864a68bf4e77720adbf',
});
}, [handleNftMint]);

Expand Down Expand Up @@ -634,7 +633,7 @@ function App() {

<Group>
<Title>Smart Contract</Title>
<Button onClick={handleGoerliMint}>Mint - goerli</Button>
<Button onClick={handleHoleskyMint}>Mint - holesky</Button>
<Button onClick={handleBscTestnetMint}>Mint - bsc testnet</Button>
<Button onClick={handleTransfer721}>Transfer721</Button>
</Group>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/constants/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const WALLET_URL = 'https://wallet.qubic.app';
// https://infura.io/docs/ethereum#section/Choose-a-Network
export const INFURA_NETWORK_ENDPOINTS: Record<Network, string> = {
[Network.MAINNET]: 'mainnet',
[Network.GOERLI]: 'goerli',
[Network.HOLESKY]: 'holesky',
[Network.POLYGON]: 'polygon-mainnet',
[Network.MUMBAI]: 'polygon-mumbai',
// [Network.OPTIMISTIC]: 'optimism-mainnet',
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/constants/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ export const NETWORK_INFO: Record<Network, NetworkInfo> = {
networkType: 'ethereum',
},

[Network.GOERLI]: {
name: 'goerli',
chainId: Network.GOERLI,
ensAddress: '0x112234455c3a32fd11230c42e7bccd4a84e02010',
explorerUrl: 'https://goerli.etherscan.io',
[Network.HOLESKY]: {
name: 'holesky',
chainId: Network.HOLESKY,
// ens currently does not support holesky
ensAddress: '0x0000000000000000000000000000000000000000',
explorerUrl: 'https://holesky.etherscan.io',
color: '#f6c343',
nativeToken: ETHEREUM_NATIVE_TOKEN,
networkType: 'ethereum',
Expand Down
51 changes: 39 additions & 12 deletions packages/core/src/middlewares/multiJsonRpcServerMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ interface MultiInfuraMiddlewareOptions {
const BSC_RPC_URL = 'https://bsc-dataseed1.binance.org';
const BSC_TESTNET_RPC_URL = 'https://data-seed-prebsc-1-s1.binance.org:8545';

// infura doesn't support holesky, so we use json rpc server here
const HOLESKY_RPC_URL = 'https://1rpc.io/holesky';

export const createMultiInfuraMiddleware = (
options: MultiInfuraMiddlewareOptions,
bridge: Bridge,
Expand All @@ -22,18 +25,42 @@ export const createMultiInfuraMiddleware = (
const infuraMiddlewares = new Map<Network, JsonRpcMiddleware<unknown, unknown>>();

function getCurrentMiddleware(): JsonRpcMiddleware<unknown, unknown> {
const currentMiddleware =
infuraMiddlewares.get(currentNetwork) ||
([Network.BSC, Network.BSC_TESTNET].includes(currentNetwork)
? createJsonRpcServerMiddleware({
url: currentNetwork === Network.BSC ? BSC_RPC_URL : BSC_TESTNET_RPC_URL,
})
: createInfuraMiddleware({
network: INFURA_NETWORK_ENDPOINTS[currentNetwork],
projectId: options.projectId,
}));

infuraMiddlewares.set(currentNetwork, currentMiddleware);
const existMiddleWare = infuraMiddlewares.get(currentNetwork);
if (existMiddleWare) {
return existMiddleWare;
}

let currentMiddleware;

switch (currentNetwork) {
case Network.BSC:
currentMiddleware = createJsonRpcServerMiddleware({
url: BSC_RPC_URL,
});

break;
case Network.BSC_TESTNET:
currentMiddleware = createJsonRpcServerMiddleware({
url: BSC_TESTNET_RPC_URL,
});

break;
case Network.HOLESKY:
currentMiddleware = createJsonRpcServerMiddleware({
url: HOLESKY_RPC_URL,
});

break;
default:
currentMiddleware = createInfuraMiddleware({
network: INFURA_NETWORK_ENDPOINTS[currentNetwork],
projectId: options.projectId,
});

break;
}

infuraMiddlewares.set(currentNetwork, currentMiddleware as JsonRpcMiddleware<unknown, unknown>);

return currentMiddleware;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/types/chain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export enum Network {
MAINNET = 1,
GOERLI = 5,
HOLESKY = 17000,
POLYGON = 137,
MUMBAI = 80001,
// OPTIMISTIC = 10,
Expand All @@ -16,10 +16,10 @@ export interface Token {
}

export const ALL_NETWORKS_TYPES = ['ethereum', 'polygon', 'bsc'] as const;
export type NetworkType = typeof ALL_NETWORKS_TYPES[number];
export type NetworkType = (typeof ALL_NETWORKS_TYPES)[number];

export interface NetworkInfo {
name: 'mainnet' | 'goerli' | 'polygon' | 'mumbai' | 'bsc' | 'bscTestnet';
name: 'mainnet' | 'holesky' | 'polygon' | 'mumbai' | 'bsc' | 'bscTestnet';
chainId: Network;
ensAddress: string;
explorerUrl: string; // no last `/`
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/connector/QubicConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class QubicWalletConnector extends Connector {
private eagerConnection?: Promise<void>;
private supportedChainIds = [
Network.MAINNET,
Network.GOERLI,
Network.HOLESKY,
Network.POLYGON,
Network.MUMBAI,
Network.BSC,
Expand Down