Skip to content

Commit

Permalink
Merge pull request #52 from deltaDAO/feat/oasis-pontusx-support
Browse files Browse the repository at this point in the history
Feat/oasis pontusx support
  • Loading branch information
oceanByte authored Feb 13, 2024
2 parents af1cdc2 + 090bcb6 commit 56ff5a7
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 51 deletions.
5 changes: 4 additions & 1 deletion app.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const { getDefaultChainIds, getSupportedChainIds } = require('./chains.config')
const {
getDefaultChainIds,
getSupportedChainIds
} = require('./chains.config.js')

module.exports = {
// URI of single metadata cache instance for all networks.
Expand Down
48 changes: 44 additions & 4 deletions chains.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// chain configs in ocean.js ConfigHelperConfig format
// see: https://github.com/oceanprotocol/ocean.js/blob/e07a7cb6ecea12b39ed96f994b4abe37806799a1/src/utils/ConfigHelper.ts#L8

const GEN_X_NETWORK_ID = 100

const chains = [
{
chainId: 100,
network: 'genx',
isDefault: true,
isCustom: true,
network: 'genx',
metadataCacheUri: 'https://aquarius510.v4.delta-dao.com',
nodeUri: 'https://rpc.genx.minimal-gaia-x.eu',
providerUri: 'https://provider.v4.genx.delta-dao.com',
Expand All @@ -33,6 +32,43 @@ const chains = [
DFStrategyV1: '0x1be9C72500B41c286C797D4FE727747Ae9C4E195',
veFeeEstimate: '0xCFeF55c6ae4d250586e293f29832967a04A9087d',
providerAddress: '0x68C24FA5b2319C81b34f248d1f928601D2E5246B'
},
{
chainId: 32456,
isDefault: false,
isCustom: true,
network: 'pontusx',
metadataCacheUri: 'https://aquarius.dev.pontus-x.eu',
nodeUri: 'https://rpc.dev.pontus-x.eu',
providerUri: 'https://provider.dev.pontus-x.eu',
subgraphUri: 'https://subgraph.dev.pontus-x.eu',
explorerUri: 'https://explorer.pontus-x.eu',
oceanTokenAddress: '0xdF171F74a8d3f4e2A789A566Dce9Fa4945196112',
oceanTokenSymbol: 'OCEAN',
fixedRateExchangeAddress: '0x8372715D834d286c9aECE1AcD51Da5755B32D505',
dispenserAddress: '0x5461b629E01f72E0A468931A36e039Eea394f9eA',
startBlock: 57428,
transactionBlockTimeout: 50,
transactionConfirmationBlocks: 1,
transactionPollingTimeout: 750,
gasFeeMultiplier: 1.1,
nftFactoryAddress: '0xFdC4a5DEaCDfc6D82F66e894539461a269900E13',
opfCommunityFeeCollector: '0x1f84fB438292269219f9396D57431eA9257C23d4',
veAllocate: '0x3fa1d5AC45ab1Ff9CFAe227c5583Ec0484b54Ef9',
veOCEAN: '0x061955B6980A34fce74b235f90DBe20d76f087b1',
veDelegation: '0x96E3aE4247a01C3d40a261df1F8ead70E32E7C0c',
veFeeDistributor: '0x35F1e6765750E874EB9d0675393A1A394A4749b4',
veDelegationProxy: '0x51B1b14b8bfb43a2fB0b49843787Ca440200F6b7',
DFRewards: '0x6BB265D6c08b7E7432dF9B3D3499beEAA9856232',
DFStrategyV1: '0x98FBBB6523441b960E4D1d9A98601332092F4aB6',
veFeeEstimate: '0xCFeF55c6ae4d250586e293f29832967a04A9087d',
providerAddress: '0x68C24FA5b2319C81b34f248d1f928601D2E5246B'
},
{
chainId: 80001,
isDefault: false,
metadataCacheUri: 'https://aquarius510.v4.delta-dao.com',
providerUri: 'https://provider.dev-v4.mumbai.delta-dao.com'
}
]

Expand All @@ -44,9 +80,13 @@ const getSupportedChainIds = () => {
return chains.map((c) => c.chainId)
}

const getCustomChainIds = () => {
return chains.filter((c) => c.isCustom).map((c) => c.chainId)
}

module.exports = {
chains,
getDefaultChainIds,
getSupportedChainIds,
GEN_X_NETWORK_ID
getCustomChainIds
}
32 changes: 26 additions & 6 deletions networksMetadata.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
// networks metadata to add to EVM-based Chains list
// see: https://github.com/ethereum-lists/chains

const { GEN_X_NETWORK_ID } = require('./chains.config')

const networksMetadata = [
{
chainId: 100,
networkId: 100,
name: 'GEN-X Testnet',
chain: 'GEN-X',
rpc: ['https://rpc.genx.minimal-gaia-x.eu'],
faucets: [],
nativeCurrency: {
name: 'GEN-X Token',
name: 'GX',
symbol: 'GX',
decimals: 18
},
infoURL: 'https://docs.genx.minimal-gaia-x.eu',
shortName: 'GEN-X',
chainId: GEN_X_NETWORK_ID,
networkId: GEN_X_NETWORK_ID,
explorers: [
{
name: 'Exchange Logging Service',
name: 'GEN-X Testnet Explorer',
url: 'https://explorer.pontus-x.eu',
standard: ''
}
]
},
{
chainId: 32456,
networkId: 32456,
name: 'Pontus-X Testnet',
chain: 'Pontus-X',
rpc: ['https://rpc.dev.pontus-x.eu'],
faucets: [],
nativeCurrency: {
name: 'EUROe',
symbol: 'EUROe',
decimals: 18
},
infoURL: 'https://docs.pontus-x.eu',
shortName: 'Pontus-X',
explorers: [
{
name: 'Pontus-X Testnet Explorer',
url: 'https://explorer.pontus-x.eu',
standard: ''
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/write-networks-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const bargeNetwork = {

const axios = require('axios')
const { networksMetadata } = require('../networksMetadata.config')
const { GEN_X_NETWORK_ID } = require('../chains.config')
const { getCustomChainIds } = require('../chains.config')

// https://github.com/ethereum-lists/chains
const chainDataUrl = 'https://chainid.network/chains.json'
Expand All @@ -34,7 +34,7 @@ axios(chainDataUrl).then((response) => {

// avoid having 2 nodes with the same chainId
const filteredData = response.data.filter(
(node) => node.chainId !== GEN_X_NETWORK_ID
(node) => !getCustomChainIds().includes(node.chainId)
)

// add custom networks metadata to the list
Expand Down
3 changes: 3 additions & 0 deletions src/@hooks/useNetworkMetadata/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ export function getNetworkDisplayName(data: EthereumListsChain): string {
case 100:
displayName = 'GEN-X Testnet'
break
case 32456:
displayName = 'Pontus-X Testnet'
break
default:
displayName = data
? `${data.chain}${
Expand Down
7 changes: 5 additions & 2 deletions src/@utils/ocean/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConfigHelper, Config } from '@oceanprotocol/lib'
import { chains } from '../../../chains.config'
import { chains, getCustomChainIds } from '../../../chains.config'
import { ethers } from 'ethers'
import abiDatatoken from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20TemplateEnterprise.sol/ERC20TemplateEnterprise.json'

Expand Down Expand Up @@ -29,7 +29,8 @@ export function getOceanConfig(network: string | number): Config {
const filterBy = typeof network === 'string' ? 'network' : 'chainId'
const customConfig = chains.find((c) => c[filterBy] === network)

if (network === 100) return customConfig as Config
if (getCustomChainIds().includes(network as number))
return customConfig as Config

let config = new ConfigHelper().getConfig(
network,
Expand All @@ -39,6 +40,8 @@ export function getOceanConfig(network: string | number): Config {
network === 'bsc' ||
network === 56 ||
network === 'gaiaxtestnet' ||
network === 'pontusx' ||
network === 32456 ||
network === 2021000 ||
network === 8996
? undefined
Expand Down
4 changes: 2 additions & 2 deletions src/@utils/onboarding.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GEN_X_NETWORK_ID } from '../../chains.config'
import { getSupportedChainIds } from '../../chains.config'

interface IErrorParams {
accountId: string
Expand All @@ -14,7 +14,7 @@ const getErrorMessage = ({
if (!accountId || !web3Provider) {
return 'Looks like your account is not connected to the portal, please go back to the "Connect" step.'
}
if (networkId !== GEN_X_NETWORK_ID) {
if (!getSupportedChainIds().includes(networkId)) {
return 'Looks like you are not connected to the GEN-X Testnet, please go back to the "Network" step.'
}

Expand Down
42 changes: 22 additions & 20 deletions src/@utils/wallet/chains.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import { Chain } from 'wagmi'
import * as wagmiChains from 'wagmi/chains'
import { networksMetadata } from '../../../networksMetadata.config'

export const genx = {
id: 100,
name: 'GEN-X Testnet',
network: 'genx',
nativeCurrency: {
decimals: 18,
name: 'GX',
symbol: 'GX'
},
export const additionalChains: Chain[] = networksMetadata.map((metadata) => ({
id: metadata.chainId,
name: metadata.name,
network: metadata.chain,
nativeCurrency: metadata.nativeCurrency,
rpcUrls: {
public: { http: ['https://rpc.genx.minimal-gaia-x.eu'] },
default: { http: ['https://rpc.genx.minimal-gaia-x.eu'] }
public: { http: metadata.rpc },
default: { http: metadata.rpc }
},
blockExplorers: {
default: {
name: 'GEN-X Testnet Explorer',
url: 'https://explorer.pontus-x.eu'
name: metadata.explorers[0].name,
url: metadata.explorers[0].url
}
}
} as Chain
}))

export const getSupportedChains = (chainIdsSupported: number[]): Chain[] => {
const chains = [wagmiChains, genx].map((chain) => {
return Object.values(chain).filter((chain) =>
chainIdsSupported.includes(chain.id)
)
})
const wagmiChainsFiltered = [wagmiChains]
.map((chain) => {
return Object.values(chain).filter(
(chain) =>
chainIdsSupported.includes(chain.id) &&
// ensure to overwrite custom "additional" chains
!additionalChains.map((addChain) => addChain.id).includes(chain.id)
)
})
.flat() as Chain[]

return chains.flat()
return [...wagmiChainsFiltered, ...additionalChains]
}
6 changes: 3 additions & 3 deletions src/@utils/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { createClient, erc20ABI } from 'wagmi'
import { ethers, Contract, Signer } from 'ethers'
import { formatEther } from 'ethers/lib/utils'
import { getDefaultClient } from 'connectkit'
import { polygonMumbai } from 'wagmi/chains'
import { genx } from './chains'
import { getNetworkDisplayName } from '@hooks/useNetworkMetadata'
import { getOceanConfig } from '../ocean'
import { getSupportedChains } from './chains'
import { chainIdsSupported } from '../../../app.config'

export async function getDummySigner(chainId: number): Promise<Signer> {
if (typeof chainId !== 'number') {
Expand All @@ -31,7 +31,7 @@ export const wagmiClient = createClient(
appName: 'Pontus-X',
infuraId: process.env.NEXT_PUBLIC_INFURA_PROJECT_ID,
// TODO: mapping between appConfig.chainIdsSupported and wagmi chainId
chains: [genx],
chains: getSupportedChains(chainIdsSupported),
walletConnectProjectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID
})
)
Expand Down
3 changes: 2 additions & 1 deletion src/components/@shared/AddToken/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
position: relative;
}

.symbol {
.symbol,
.network {
text-transform: none;
}

Expand Down
10 changes: 10 additions & 0 deletions src/components/@shared/AddToken/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { addTokenToWallet } from '@utils/wallet'
import Button from '@shared/atoms/Button'
import OceanLogo from '@images/logo.svg'
import styles from './index.module.css'
import { useNetwork } from 'wagmi'

const cx = classNames.bind(styles)

Expand All @@ -29,6 +30,8 @@ export default function AddToken({
className,
minimal
}: AddTokenProps): ReactElement {
const { chain } = useNetwork()

const styleClasses = cx({
button: true,
minimal,
Expand Down Expand Up @@ -57,6 +60,13 @@ export default function AddToken({
<>
{'Add '}
<span className={styles.symbol}>{symbol}</span>
{chain && (
<>
{' ('}
<span className={styles.network}>{chain.name}</span>
{')'}
</>
)}
</>
)}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import StepBody from '../StepBody'
import StepHeader from '../StepHeader'
import content from '../../../../../content/onboarding/steps/importCustomTokens.json'
import { useAccount, useNetwork, useProvider } from 'wagmi'
import { GEN_X_NETWORK_ID } from 'chains.config'
import { addTokenToWallet } from '@utils/wallet'
import { getErrorMessage } from '@utils/onboarding'
import { tokenLogos } from '@components/Header/Wallet/AddTokenList'
import { useMarketMetadata } from '@context/MarketMetadata'
import { getSupportedChainIds } from '../../../../../chains.config'

export default function ImportCustomTokens(): ReactElement {
const { title, subtitle, body, image }: OnboardingStep = content
Expand All @@ -31,7 +31,7 @@ export default function ImportCustomTokens(): ReactElement {
) => {
setLoading(true)
try {
if (chain?.id !== GEN_X_NETWORK_ID) throw new Error()
if (!getSupportedChainIds().includes(chain?.id)) throw new Error()

await addTokenToWallet(
tokenAddress,
Expand Down
8 changes: 6 additions & 2 deletions src/components/@shared/Onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import Ready from './Steps/Ready'
import { useAccount, useNetwork, useProvider } from 'wagmi'
import { useUserPreferences } from '@context/UserPreferences'
import useBalance from '@hooks/useBalance'
import { GEN_X_NETWORK_ID } from 'chains.config'
import ImportWallet from './Steps/ImportWallet'
import AutomationWalletState from './Steps/AutomationWalletState'
import { getSupportedChainIds } from '../../../../chains.config'

export interface OnboardingStep {
title: string
Expand Down Expand Up @@ -55,7 +55,11 @@ export default function OnboardingSection(): ReactElement {
}, [onboardingStep, setOnboardingStep])

useEffect(() => {
if (accountId && web3Provider && chain?.id === GEN_X_NETWORK_ID) {
if (
accountId &&
web3Provider &&
getSupportedChainIds().includes(chain?.id)
) {
setOnboardingCompleted(true)
}
}, [accountId, balance, chain?.id, web3Provider])
Expand Down
Loading

0 comments on commit 56ff5a7

Please sign in to comment.