Skip to content

Commit

Permalink
CU-86du7e4k8 BSEthereum - Implement new BlockchainDataService for Neo…
Browse files Browse the repository at this point in the history
…X using Blockscout
  • Loading branch information
lopescode committed Jul 30, 2024
1 parent 77a7c4a commit f5189c7
Show file tree
Hide file tree
Showing 16 changed files with 782 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/blockchain-service",
"comment": "Implement new blokchain data service for neox using blockscout",
"type": "minor"
}
],
"packageName": "@cityofzion/blockchain-service"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-ethereum",
"comment": "Implement new blockchain data service for neox using blockscout",
"type": "minor"
}
],
"packageName": "@cityofzion/bs-ethereum"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo-legacy",
"comment": "Implement new blockchain data service for neox using blockscout",
"type": "minor"
}
],
"packageName": "@cityofzion/bs-neo-legacy"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-neo3",
"comment": "Implement new blockchain data service for neox using blockscout",
"type": "minor"
}
],
"packageName": "@cityofzion/bs-neo3"
}
95 changes: 95 additions & 0 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/blockchain-service/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './interfaces'
export * from './BSAggregator'
export * from './functions'
export * from './CryptoCompareEDS'
export * from './functions'
export * from './interfaces'
11 changes: 11 additions & 0 deletions packages/blockchain-service/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,27 @@ export type ContractParameter = {
name: string
type: string
}
export type NextPageParams = {
block_number: number
fee: string
hash: string
index: number
inserted_at: string
items_count: number
value: string
}
export type TransactionsByAddressResponse = {
totalCount?: number
limit?: number
nextCursor?: string
transactions: TransactionResponse[]
nextPageParams?: NextPageParams | null
}
export type TransactionsByAddressParams = {
address: string
page?: number
cursor?: string
nextPageParams?: NextPageParams | null
}
export type ContractMethod = {
name: string
Expand Down
12 changes: 10 additions & 2 deletions packages/bs-ethereum/src/BSEthereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import Transport from '@ledgerhq/hw-transport'
import { BSEthereumNetworkId, BSEthereumHelper } from './BSEthereumHelper'
import { MoralisBDSEthereum } from './MoralisBDSEthereum'
import { MoralisEDSEthereum } from './MoralisEDSEthereum'
import { BlockscoutNeoXBDSEthereum } from './BlockscoutNeoXBDSEthereum'
import { BlockscoutNeoXEDSEthereum } from './BlockscoutNeoXEDSEthereum'

export class BSEthereum<BSCustomName extends string = string>
implements
Expand Down Expand Up @@ -68,8 +70,14 @@ export class BSEthereum<BSCustomName extends string = string>

this.network = network

this.blockchainDataService = new MoralisBDSEthereum(network)
this.exchangeDataService = new MoralisEDSEthereum(network, this.blockchainDataService)
if (BlockscoutNeoXBDSEthereum.isSupported(network)) {
this.exchangeDataService = new BlockscoutNeoXEDSEthereum(network)
this.blockchainDataService = new BlockscoutNeoXBDSEthereum(network)
} else {
this.exchangeDataService = new MoralisEDSEthereum(network, this.blockchainDataService)
this.blockchainDataService = new MoralisBDSEthereum(network)
}

this.nftDataService = new GhostMarketNDSEthereum(network)
}

Expand Down
32 changes: 19 additions & 13 deletions packages/bs-ethereum/src/BSEthereumHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export type BSEthereumNetworkId = NetworkId<
| '43114'
| '59144'
| '11155111'
| '12227331'
| '47763'
| '12227332'
>

export class BSEthereumHelper {
Expand All @@ -40,7 +41,8 @@ export class BSEthereumHelper {
'43114': 'AVAX',
'59144': 'ETH',
'11155111': 'ETH',
'12227331': 'GAS',
'47763': 'GAS',
'12227332': 'GAS',
}

static #RPC_LIST_BY_NETWORK_ID: Record<BSEthereumNetworkId, string[]> = {
Expand Down Expand Up @@ -132,21 +134,28 @@ export class BSEthereumHelper {
'https://1rpc.io/sepolia',
'https://eth-sepolia.api.onfinality.io/public',
],
'12227331': ['https://neoxseed1.ngd.network'],
'47763': ['https://mainnet-1.rpc.banelabs.org'],
'12227332': ['https://neoxt4seed1.ngd.network'],
}

static DERIVATION_PATH = "m/44'/60'/0'/0/?"
static DEFAULT_PATH = "44'/60'/0'/0/0"

static NEOX_TESTNET_NETWORK_ID: BSEthereumNetworkId = '12227331'
static NEOX_NETWORK_IDS: BSEthereumNetworkId[] = [this.NEOX_TESTNET_NETWORK_ID]
static NEOX_TESTNET_NETWORK_ID: BSEthereumNetworkId = '12227332'
static NEOX_MAINNET_NETWORK_ID: BSEthereumNetworkId = '47763'
static NEOX_NETWORK_IDS: BSEthereumNetworkId[] = [this.NEOX_TESTNET_NETWORK_ID, this.NEOX_MAINNET_NETWORK_ID]

static NEOX_TESTNET_NETWORK: Network<BSEthereumNetworkId> = {
id: this.NEOX_TESTNET_NETWORK_ID,
name: 'NeoX Testnet',
url: this.#RPC_LIST_BY_NETWORK_ID[this.NEOX_TESTNET_NETWORK_ID][0],
}
static NEOX_NETWORKS: Network<BSEthereumNetworkId>[] = [this.NEOX_TESTNET_NETWORK]
static NEOX_MAINNET_NETWORK: Network<BSEthereumNetworkId> = {
id: this.NEOX_MAINNET_NETWORK_ID,
name: 'NeoX Mainnet',
url: this.#RPC_LIST_BY_NETWORK_ID[this.NEOX_MAINNET_NETWORK_ID][0],
}
static NEOX_NETWORKS: Network<BSEthereumNetworkId>[] = [this.NEOX_TESTNET_NETWORK, this.NEOX_MAINNET_NETWORK]

static MAINNET_NETWORK_IDS: BSEthereumNetworkId[] = [
'1',
Expand All @@ -160,14 +169,9 @@ export class BSEthereumHelper {
'42220',
'43114',
'59144',
this.NEOX_MAINNET_NETWORK_ID,
]
static TESTNET_NETWORK_IDS: BSEthereumNetworkId[] = [
'1101',
'80002',
'11155111',
'12227331',
this.NEOX_TESTNET_NETWORK_ID,
]
static TESTNET_NETWORK_IDS: BSEthereumNetworkId[] = ['1101', '80002', '11155111', this.NEOX_TESTNET_NETWORK_ID]
static ALL_NETWORK_IDS: BSEthereumNetworkId[] = [...this.MAINNET_NETWORK_IDS, ...this.TESTNET_NETWORK_IDS]

static MAINNET_NETWORKS: Network<BSEthereumNetworkId>[] = [
Expand Down Expand Up @@ -226,6 +230,7 @@ export class BSEthereumHelper {
name: 'Linea Mainnet',
url: this.#RPC_LIST_BY_NETWORK_ID['59144'][0],
},
this.NEOX_MAINNET_NETWORK,
]
static TESTNET_NETWORKS: Network<BSEthereumNetworkId>[] = [
{
Expand All @@ -251,6 +256,7 @@ export class BSEthereumHelper {

static getNativeAsset(network: Network<BSEthereumNetworkId>) {
const symbol = this.getNativeSymbol(network)

return { ...this.#NATIVE_ASSET, symbol, name: symbol }
}

Expand Down
Loading

0 comments on commit f5189c7

Please sign in to comment.