From 354832f090df8a1fda053b2593adfdeecd2a0d87 Mon Sep 17 00:00:00 2001 From: chmanie Date: Fri, 23 Dec 2022 00:44:43 +0900 Subject: [PATCH] Adjust to new Colony RPC endpoint --- docs/api/README.md | 1 + docs/api/classes/ColonyNetwork.md | 2 +- docs/api/enums/ColonyRpcEndpoint.md | 49 +++++++++++++++++++++ docs/api/enums/MetaTxBroadCasterEndpoint.md | 6 +-- docs/getting-started/index.md | 2 +- examples/browser/src/basic.ts | 4 +- examples/browser/src/events.ts | 8 +++- examples/browser/src/index.ts | 4 +- examples/node/automation.ts | 4 +- examples/node/basic.ts | 4 +- examples/node/create.ts | 3 +- examples/node/metatx.ts | 4 +- src/ColonyNetwork/ColonyNetwork.ts | 2 +- src/constants.ts | 21 +++++++-- 14 files changed, 93 insertions(+), 21 deletions(-) create mode 100644 docs/api/enums/ColonyRpcEndpoint.md diff --git a/docs/api/README.md b/docs/api/README.md index f706e727..301f264a 100644 --- a/docs/api/README.md +++ b/docs/api/README.md @@ -8,6 +8,7 @@ - [ColonyLabelSuffix](enums/ColonyLabelSuffix.md) - [ColonyRole](enums/ColonyRole.md) +- [ColonyRpcEndpoint](enums/ColonyRpcEndpoint.md) - [Extension](enums/Extension.md) - [Id](enums/Id.md) - [MetaTxBroadCasterEndpoint](enums/MetaTxBroadCasterEndpoint.md) diff --git a/docs/api/classes/ColonyNetwork.md b/docs/api/classes/ColonyNetwork.md index 3b4e45ee..a2366478 100644 --- a/docs/api/classes/ColonyNetwork.md +++ b/docs/api/classes/ColonyNetwork.md @@ -296,7 +296,7 @@ import { providers } from 'ethers'; import { ColonyNetwork, Tokens } from '@colony/sdk'; // Connect directly to the deployed Colony Network on Gnosis Chain -const provider = new providers.JsonRpcProvider('https://xdai.colony.io/rpc2/'); +const provider = new providers.JsonRpcProvider('https://xdai.colony.io/rpc/'); // Immediately executing async function (async function() { const colonyNetwork = await ColonyNetwork.init(provider); diff --git a/docs/api/enums/ColonyRpcEndpoint.md b/docs/api/enums/ColonyRpcEndpoint.md new file mode 100644 index 00000000..731825b1 --- /dev/null +++ b/docs/api/enums/ColonyRpcEndpoint.md @@ -0,0 +1,49 @@ +# Enumeration: ColonyRpcEndpoint + +## Enumeration Members + +### Custom + +• **Custom** = ``""`` + +Colony's own RPC2 endpoint for a custom network + +___ + +### Gnosis + +• **Gnosis** = ``"https://xdai.colony.io/rpc/"`` + +Colony's own RPC2 endpoint for Gnosis chain + +___ + +### Goerli + +• **Goerli** = ``""`` + +Colony's own RPC2 endpoint for Goerli testnet + +___ + +### Mainnet + +• **Mainnet** = ``""`` + +Colony's own RPC2 endpoint for Mainnet + +___ + +### Xdai + +• **Xdai** = ``"https://xdai.colony.io/rpc/"`` + +Colony's own RPC2 endpoint for Gnosis chain (alias) + +___ + +### XdaiQa + +• **XdaiQa** = ``"https://xdai.colony.io/rpc/"`` + +Colony's own RPC2 endpoint for Gnosis chain (QA environment) diff --git a/docs/api/enums/MetaTxBroadCasterEndpoint.md b/docs/api/enums/MetaTxBroadCasterEndpoint.md index 98985d83..b4512f8e 100644 --- a/docs/api/enums/MetaTxBroadCasterEndpoint.md +++ b/docs/api/enums/MetaTxBroadCasterEndpoint.md @@ -14,7 +14,7 @@ ___ • **Gnosis** = ``"https://xdai.colony.io/metatransaction/xdai"`` -The metatransaction broadcaster endpointon Gnosis chain +The metatransaction broadcaster endpoint on Gnosis Chain ___ @@ -38,7 +38,7 @@ ___ • **Xdai** = ``"https://xdai.colony.io/metatransaction/xdai"`` -The metatransaction broadcaster endpointon Gnosis chain (alias) +The metatransaction broadcaster endpoint on Gnosis Chain (alias) ___ @@ -46,4 +46,4 @@ ___ • **XdaiQa** = ``"https://xdai.colony.io/metatransaction/xdai"`` -The metatransaction broadcaster endpointaddress on Gnosis chain +The metatransaction broadcaster endpoint on Gnosis Chain (QA environment) diff --git a/docs/getting-started/index.md b/docs/getting-started/index.md index 022a6eef..0aa475a4 100644 --- a/docs/getting-started/index.md +++ b/docs/getting-started/index.md @@ -70,7 +70,7 @@ Include the resulting bundle in an HTML file and open it in you favorite browser const { providers, Wallet } = require('ethers'); const { ColonyNetwork } = require('@colony/sdk'); -const provider = new providers.JsonRpcProvider('https://xdai.colony.io/rpc2/'); +const provider = new providers.JsonRpcProvider('https://xdai.colony.io/rpc/'); const wallet = Wallet.createRandom().connect(provider); // Get the Colony's XDAI funding in the ROOT pot (id 1) diff --git a/examples/browser/src/basic.ts b/examples/browser/src/basic.ts index 840e0a8e..eaa6b9e6 100644 --- a/examples/browser/src/basic.ts +++ b/examples/browser/src/basic.ts @@ -1,10 +1,10 @@ import { providers, utils } from 'ethers'; -import { ColonyNetwork, Tokens } from '../../../src'; +import { ColonyNetwork, ColonyRpcEndpoint, Tokens } from '../../../src'; const { formatEther, isAddress } = utils; -const provider = new providers.JsonRpcProvider('https://xdai.colony.io/rpc2/'); +const provider = new providers.JsonRpcProvider(ColonyRpcEndpoint.Gnosis); // Get the Colony's CLNY funding in the root domain (on Gnosis chain) const getColonyFunding = async (colonyAddress: string) => { diff --git a/examples/browser/src/events.ts b/examples/browser/src/events.ts index dae9d7ef..3c0bd32a 100644 --- a/examples/browser/src/events.ts +++ b/examples/browser/src/events.ts @@ -1,9 +1,13 @@ import { providers, utils } from 'ethers'; -import { ColonyEventManager, MetadataType } from '../../../src'; +import { + ColonyEventManager, + ColonyRpcEndpoint, + MetadataType, +} from '../../../src'; import type { ColonyEvent } from '../../../src'; -const provider = new providers.JsonRpcProvider('https://xdai.colony.io/rpc2/'); +const provider = new providers.JsonRpcProvider(ColonyRpcEndpoint.Gnosis); const { isAddress } = utils; // This event listener will only list for the `DomainAdded` event in the Colony of the user's choice. Run this and then create a Team in that Colony, to see it being picked up here diff --git a/examples/browser/src/index.ts b/examples/browser/src/index.ts index 60320ac2..1c95b686 100644 --- a/examples/browser/src/index.ts +++ b/examples/browser/src/index.ts @@ -1,3 +1,5 @@ +import { ColonyRpcEndpoint } from '../../../src'; + const addColonyRPC = () => { // If MetaMask is installed there will be an `ethereum` object on the `window` // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -12,7 +14,7 @@ const addColonyRPC = () => { symbol: 'XDAI', decimals: 18, }, - rpcUrls: ['https://xdai.colony.io/rpc2/'], + rpcUrls: [ColonyRpcEndpoint.Gnosis], blockExplorerUrls: ['https://blockscout.com/xdai/mainnet'], }, ], diff --git a/examples/node/automation.ts b/examples/node/automation.ts index 7c6c3404..1482b46d 100644 --- a/examples/node/automation.ts +++ b/examples/node/automation.ts @@ -1,8 +1,8 @@ import { providers, Wallet } from 'ethers'; -import { ColonyNetwork, w } from '../../src'; +import { ColonyNetwork, ColonyRpcEndpoint, w } from '../../src'; -const provider = new providers.JsonRpcProvider('https://xdai.colony.io/rpc2/'); +const provider = new providers.JsonRpcProvider(ColonyRpcEndpoint.Gnosis); const start = async () => { // Create a new wallet from a private key. This key is stored in an environment variable called `PRIATE_KEY` diff --git a/examples/node/basic.ts b/examples/node/basic.ts index 52370cbe..6393470b 100644 --- a/examples/node/basic.ts +++ b/examples/node/basic.ts @@ -1,8 +1,8 @@ import { providers } from 'ethers'; -import { ColonyNetwork, toEth } from '../../src'; +import { ColonyNetwork, ColonyRpcEndpoint, toEth } from '../../src'; -const provider = new providers.JsonRpcProvider('https://xdai.colony.io/rpc2/'); +const provider = new providers.JsonRpcProvider(ColonyRpcEndpoint.Gnosis); // Get the Colony's CLNY funding in the ROOT team (id 1) const start = async () => { diff --git a/examples/node/create.ts b/examples/node/create.ts index 62fa802e..e4e167ae 100644 --- a/examples/node/create.ts +++ b/examples/node/create.ts @@ -3,11 +3,12 @@ import { providers, Wallet } from 'ethers'; import { ColonyNetwork, ColonyRole, + ColonyRpcEndpoint, ColonyToken, SupportedExtension, } from '../../src'; -const provider = new providers.JsonRpcProvider('https://xdai.colony.io/rpc2/'); +const provider = new providers.JsonRpcProvider(ColonyRpcEndpoint.Gnosis); // Deploy a Colony with everything that's needed const start = async () => { diff --git a/examples/node/metatx.ts b/examples/node/metatx.ts index 0f162c56..749282ac 100644 --- a/examples/node/metatx.ts +++ b/examples/node/metatx.ts @@ -1,8 +1,8 @@ import { constants, providers, Wallet } from 'ethers'; -import { ColonyNetwork } from '../../src'; +import { ColonyNetwork, ColonyRpcEndpoint } from '../../src'; -const provider = new providers.JsonRpcProvider('https://xdai.colony.io/rpc2/'); +const provider = new providers.JsonRpcProvider(ColonyRpcEndpoint.Gnosis); // Claim ETH for the MetaColony using a Metatransaction const start = async () => { diff --git a/src/ColonyNetwork/ColonyNetwork.ts b/src/ColonyNetwork/ColonyNetwork.ts index 92233a42..b2e81231 100644 --- a/src/ColonyNetwork/ColonyNetwork.ts +++ b/src/ColonyNetwork/ColonyNetwork.ts @@ -103,7 +103,7 @@ export class ColonyNetwork { * import { ColonyNetwork, Tokens } from '@colony/sdk'; * * // Connect directly to the deployed Colony Network on Gnosis Chain - * const provider = new providers.JsonRpcProvider('https://xdai.colony.io/rpc2/'); + * const provider = new providers.JsonRpcProvider('https://xdai.colony.io/rpc/'); * // Immediately executing async function * (async function() { * const colonyNetwork = await ColonyNetwork.init(provider); diff --git a/src/constants.ts b/src/constants.ts index faf30e45..7f12a36c 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -5,16 +5,31 @@ export enum MetaTxBroadCasterEndpoint { Mainnet = '', /** The metatransaction broadcaster endpoint on the Görli testnet */ Goerli = '', - /** The metatransaction broadcaster endpointon Gnosis chain */ + /** The metatransaction broadcaster endpoint on Gnosis Chain */ Gnosis = 'https://xdai.colony.io/metatransaction/xdai', - /** The metatransaction broadcaster endpointon Gnosis chain (alias) */ + /** The metatransaction broadcaster endpoint on Gnosis Chain (alias) */ Xdai = 'https://xdai.colony.io/metatransaction/xdai', - /** The metatransaction broadcaster endpointaddress on Gnosis chain */ + /** The metatransaction broadcaster endpoint on Gnosis Chain (QA environment) */ XdaiQa = 'https://xdai.colony.io/metatransaction/xdai', /** The metatransaction broadcaster endpoint for a custom network */ Custom = '', } +export enum ColonyRpcEndpoint { + /** Colony's own RPC2 endpoint for Mainnet */ + Mainnet = '', + /** Colony's own RPC2 endpoint for Goerli testnet */ + Goerli = '', + /** Colony's own RPC2 endpoint for Gnosis chain */ + Gnosis = 'https://xdai.colony.io/rpc/', + /** Colony's own RPC2 endpoint for Gnosis chain (alias) */ + Xdai = 'https://xdai.colony.io/rpc/', + /** Colony's own RPC2 endpoint for Gnosis chain (QA environment) */ + XdaiQa = 'https://xdai.colony.io/rpc/', + /** Colony's own RPC2 endpoint for a custom network */ + Custom = '', +} + // TODO: Consider moving this to the metadata-parser export enum TeamColor { LightPink,