Skip to content

Commit

Permalink
Blockchain Services - EpicChain Lab's
Browse files Browse the repository at this point in the history
  • Loading branch information
xmoohad committed Dec 24, 2024
1 parent 0f8d011 commit 4016f5a
Show file tree
Hide file tree
Showing 19 changed files with 531 additions and 123 deletions.
409 changes: 408 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@epicchain/epicvault-api": "^1.0.1",
"@epicchain/epicvault-core": "^1.0.1",
"@epicchain/epicvault-dappkit-types": "^1.0.1",
"@epicchain/epicvault-js": "^1.0.1"
"@epicchain/epicvault-js": "^1.0.1",
"@ledgerhq/hw-transport-node-hid": "^6.29.5"
}
}
38 changes: 19 additions & 19 deletions packages/bs-epicchain/src/BSEpicChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ import {
} from '@epicchain/blockchain-service'
import { keychain } from '@epicchain/bs-asteroid-sdk'
import Neon from '@epicchain/epicvault-core'
import { NeonInvoker, NeonParser } from '@cityofzion/neon-dappkit'
import { EpicVaultInvoker, NeonParser } from '@cityofzion/neon-dappkit'
import { ContractInvocation } from '@epicchain/epicvault-dappkit-types'
import { api, u, wallet } from '@epicchain/epicvault-js'
import { BSNeo3Helper } from './helpers/BSEpicChainHelper'
import { BSEpicChainHelper } from './helpers/BSEpicChainHelper'
import { DoraBDSNeo3 } from './services/blockchain-data/EpicScanBDSEpicChain'
import { FlamingoEDSNeo3 } from './services/exchange-data/FlamingoEDSNeo3'
import { DoraESNeo3 } from './services/explorer/EpicScanESEpicChain'
import { NeonDappKitLedgerServiceNeo3 } from './services/ledger/EpicVaultDappKitLedgerServiceEpicChain'
import { EpicVaultDappKitLedgerServiceEpicChain } from './services/ledger/EpicVaultDappKitLedgerServiceEpicChain'
import { GhostMarketNDSNeo3 } from './services/nft-data/GhostMarketNDSEpicChain'
import { BSNeo3Constants, BSNeo3NetworkId } from './constants/BSEpicChainConstants'
import { BSEpicChainConstants, BSEpicChainNetworkId } from './constants/BSEpicChainConstants'
import { RpcBDSNeo3 } from './services/blockchain-data/RpcBDSEpicChain'

export class BSNeo3<BSName extends string = string>
implements
BlockchainService<BSName, BSNeo3NetworkId>,
BlockchainService<BSName, BSEpicChainNetworkId>,
BSClaimable<BSName>,
BSWithNameService,
BSCalculableFee<BSName>,
Expand All @@ -51,24 +51,24 @@ export class BSNeo3<BSName extends string = string>

blockchainDataService!: BlockchainDataService & BDSClaimable
nftDataService!: NftDataService
ledgerService: NeonDappKitLedgerServiceNeo3<BSName>
ledgerService: EpicVaultDappKitLedgerServiceEpicChain<BSName>
exchangeDataService!: ExchangeDataService
explorerService!: ExplorerService

network!: Network<BSNeo3NetworkId>
network!: Network<BSEpicChainNetworkId>

constructor(name: BSName, network?: Network<BSNeo3NetworkId>, getLedgerTransport?: GetLedgerTransport<BSName>) {
network = network ?? BSNeo3Constants.DEFAULT_NETWORK
constructor(name: BSName, network?: Network<BSEpicChainNetworkId>, getLedgerTransport?: GetLedgerTransport<BSName>) {
network = network ?? BSEpicChainConstants.DEFAULT_NETWORK

this.name = name
this.ledgerService = new NeonDappKitLedgerServiceNeo3(this, getLedgerTransport)
this.bip44DerivationPath = BSNeo3Constants.DEFAULT_BIP44_DERIVATION_PATH
this.ledgerService = new EpicVaultDappKitLedgerServiceEpicChain(this, getLedgerTransport)
this.bip44DerivationPath = BSEpicChainConstants.DEFAULT_BIP44_DERIVATION_PATH

this.setNetwork(network)
}

#setTokens(network: Network<BSNeo3NetworkId>) {
const tokens = BSNeo3Helper.getTokens(network)
#setTokens(network: Network<BSEpicChainNetworkId>) {
const tokens = BSEpicChainHelper.getTokens(network)

this.tokens = tokens
this.feeToken = tokens.find(token => token.symbol === 'XPP')!
Expand Down Expand Up @@ -138,13 +138,13 @@ export class BSNeo3<BSName extends string = string>
return invocations
}

async testNetwork(network: Network<BSNeo3NetworkId>) {
async testNetwork(network: Network<BSEpicChainNetworkId>) {
const blockchainDataServiceClone = new RpcBDSNeo3(network, this.feeToken, this.claimToken, this.tokens)

await blockchainDataServiceClone.getBlockHeight()
}

setNetwork(network: Network<BSNeo3NetworkId>) {
setNetwork(network: Network<BSEpicChainNetworkId>) {
this.#setTokens(network)
this.network = network

Expand Down Expand Up @@ -212,7 +212,7 @@ export class BSNeo3<BSName extends string = string>
async calculateTransferFee(param: TransferParam<BSName>): Promise<string> {
const { neonJsAccount } = await this.generateSigningCallback(param.senderAccount)

const invoker = await NeonInvoker.init({
const invoker = await EpicVaultInvoker.init({
rpcAddress: this.network.url,
account: neonJsAccount,
})
Expand All @@ -230,7 +230,7 @@ export class BSNeo3<BSName extends string = string>
async transfer(param: TransferParam<BSName>): Promise<string[]> {
const { neonJsAccount, signingCallback } = await this.generateSigningCallback(param.senderAccount)

const invoker = await NeonInvoker.init({
const invoker = await EpicVaultInvoker.init({
rpcAddress: this.network.url,
account: neonJsAccount,
signingCallback: signingCallback,
Expand Down Expand Up @@ -258,11 +258,11 @@ export class BSNeo3<BSName extends string = string>

async resolveNameServiceDomain(domainName: string): Promise<any> {
const parser = NeonParser
const invoker = await NeonInvoker.init({ rpcAddress: this.network.url })
const invoker = await EpicVaultInvoker.init({ rpcAddress: this.network.url })
const response = await invoker.testInvoke({
invocations: [
{
scriptHash: BSNeo3Constants.NEO_NS_HASH,
scriptHash: BSEpicChainConstants.NEO_NS_HASH,
operation: 'ownerOf',
args: [{ type: 'String', value: domainName }],
},
Expand Down
20 changes: 10 additions & 10 deletions packages/bs-epicchain/src/__tests__/services/BSNeo3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Network } from '@epicchain/blockchain-service'
import { generateMnemonic } from '@epicchain/bs-asteroid-sdk'
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import { BSNeo3 } from '../../BSEpicChain'
import { BSNeo3Constants, BSNeo3NetworkId } from '../../constants/BSEpicChainConstants'
import { BSNeo3Helper } from '../../helpers/BSEpicChainHelper'
import { BSEpicChainConstants, BSEpicChainNetworkId } from '../../constants/BSEpicChainConstants'
import { BSEpicChainHelper } from '../../helpers/BSEpicChainHelper'

let bsNeo3: BSNeo3<'neo3'>
let network: Network<BSNeo3NetworkId>
let network: Network<BSEpicChainNetworkId>

describe('BSNeo3', () => {
beforeAll(async () => {
network = BSNeo3Constants.TESTNET_NETWORKS[0]
network = BSEpicChainConstants.TESTNET_NETWORKS[0]
bsNeo3 = new BSNeo3('neo3', network)
}, 60000)

Expand Down Expand Up @@ -170,8 +170,8 @@ describe('BSNeo3', () => {

it.skip('Should be able to calculate transfer fee more than one intent', async () => {
const account = bsNeo3.generateAccountFromKey(process.env.TESTNET_PRIVATE_KEY as string)
const NEO = BSNeo3Helper.getTokens(network).find(token => token.symbol === 'NEO')!
const GAS = BSNeo3Helper.getTokens(network).find(token => token.symbol === 'GAS')!
const NEO = BSEpicChainHelper.getTokens(network).find(token => token.symbol === 'XPR')!
const GAS = BSEpicChainHelper.getTokens(network).find(token => token.symbol === 'XPP')!

const fee = await bsNeo3.calculateTransferFee({
senderAccount: account,
Expand All @@ -198,8 +198,8 @@ describe('BSNeo3', () => {
const account = bsNeo3.generateAccountFromKey(process.env.TESTNET_PRIVATE_KEY as string)
const balance = await bsNeo3.blockchainDataService.getBalance(account.address)

const NEO = BSNeo3Helper.getTokens(network).find(token => token.symbol === 'NEO')!
const GAS = BSNeo3Helper.getTokens(network).find(token => token.symbol === 'GAS')!
const NEO = BSEpicChainHelper.getTokens(network).find(token => token.symbol === 'XPR')!
const GAS = BSEpicChainHelper.getTokens(network).find(token => token.symbol === 'XPP')!

const gasBalance = balance.find(b => b.token.symbol === GAS.symbol)
expect(Number(gasBalance?.amount)).toBeGreaterThan(0.00000001)
Expand Down Expand Up @@ -236,8 +236,8 @@ describe('BSNeo3', () => {

const balance = await service.blockchainDataService.getBalance(account.address)

const NEO = BSNeo3Helper.getTokens(network).find(token => token.symbol === 'NEO')!
const GAS = BSNeo3Helper.getTokens(network).find(token => token.symbol === 'GAS')!
const NEO = BSEpicChainHelper.getTokens(network).find(token => token.symbol === 'XPR')!
const GAS = BSEpicChainHelper.getTokens(network).find(token => token.symbol === 'XPP')!

const gasBalance = balance.find(b => b.token.symbol === GAS.symbol)
expect(Number(gasBalance?.amount)).toBeGreaterThan(0.00000001)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BSNeo3Constants } from '../../../constants/BSEpicChainConstants'
import { BSNeo3Helper } from '../../../helpers/BSEpicChainHelper'
import { BSEpicChainConstants } from '../../../constants/BSEpicChainConstants'
import { BSEpicChainHelper } from '../../../helpers/BSEpicChainHelper'
import { DoraBDSNeo3 } from '../../../services/blockchain-data/EpicScanBDSEpicChain'

const network = BSNeo3Constants.TESTNET_NETWORKS[0]
const tokens = BSNeo3Helper.getTokens(network)
const network = BSEpicChainConstants.TESTNET_NETWORKS[0]
const tokens = BSEpicChainHelper.getTokens(network)

const GAS = tokens.find(token => token.symbol === 'GAS')!
const GAS = tokens.find(token => token.symbol === 'XPP')!

let doraBDSNeo3: DoraBDSNeo3

Expand Down Expand Up @@ -91,7 +91,7 @@ describe('DoraBDSNeo3', () => {
decimals: 8,
hash,
name: 'GasToken',
symbol: 'GAS',
symbol: 'XPP',
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BSNeo3Constants } from '../../../constants/BSEpicChainConstants'
import { BSNeo3Helper } from '../../../helpers/BSEpicChainHelper'
import { BSEpicChainConstants } from '../../../constants/BSEpicChainConstants'
import { BSEpicChainHelper } from '../../../helpers/BSEpicChainHelper'
import { RpcBDSNeo3 } from '../../../services/blockchain-data/RpcBDSEpicChain'

const network = BSNeo3Constants.TESTNET_NETWORKS[0]
const tokens = BSNeo3Helper.getTokens(network)
const network = BSEpicChainConstants.TESTNET_NETWORKS[0]
const tokens = BSEpicChainHelper.getTokens(network)

const GAS = tokens.find(token => token.symbol === 'GAS')!
const GAS = tokens.find(token => token.symbol === 'XPP')!

let rpcBDSNeo3: RpcBDSNeo3

Expand Down Expand Up @@ -55,8 +55,8 @@ describe('RpcBDSNeo3', () => {
expect(token).toEqual({
decimals: 8,
hash: 'd2a4cff31913016155e38e474a2c06d08be276cf',
name: 'GAS',
symbol: 'GAS',
name: 'XPP',
symbol: 'XPP',
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Network } from '@epicchain/blockchain-service'
import { BSNeo3Constants, BSNeo3NetworkId } from '../../../constants/BSEpicChainConstants'
import { BSNeo3Helper } from '../../../helpers/BSEpicChainHelper'
import { BSEpicChainConstants, BSEpicChainNetworkId } from '../../../constants/BSEpicChainConstants'
import { BSEpicChainHelper } from '../../../helpers/BSEpicChainHelper'
import { FlamingoEDSNeo3 } from '../../../services/exchange-data/FlamingoEDSNeo3'

let flamingoEDSNeo3: FlamingoEDSNeo3
let network: Network<BSNeo3NetworkId>
let network: Network<BSEpicChainNetworkId>

describe('FlamingoEDSNeo3', () => {
beforeAll(() => {
network = BSNeo3Constants.DEFAULT_NETWORK
network = BSEpicChainConstants.DEFAULT_NETWORK
flamingoEDSNeo3 = new FlamingoEDSNeo3(network)
})

it('Should return a list with prices of tokens using USD', async () => {
const tokenPriceList = await flamingoEDSNeo3.getTokenPrices({ tokens: BSNeo3Helper.getTokens(network) })
const tokenPriceList = await flamingoEDSNeo3.getTokenPrices({ tokens: BSEpicChainHelper.getTokens(network) })

tokenPriceList.forEach(tokenPrice => {
expect(tokenPrice).toEqual({
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('FlamingoEDSNeo3', () => {
})

it("Should return the token's price history", async () => {
const token = BSNeo3Helper.getTokens(network).find(token => token.symbol === 'GAS')!
const token = BSEpicChainHelper.getTokens(network).find(token => token.symbol === 'XPP')!
const tokenPriceHistory = await flamingoEDSNeo3.getTokenPriceHistory({
token,
limit: 24,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BSNeo3Constants } from '../../../constants/BSEpicChainConstants'
import { BSEpicChainConstants } from '../../../constants/BSEpicChainConstants'
import { DoraESNeo3 } from '../../../services/explorer/EpicScanESEpicChain'

let doraESNeo3: DoraESNeo3

describe('DoraESNeo3', () => {
beforeAll(() => {
doraESNeo3 = new DoraESNeo3(BSNeo3Constants.DEFAULT_NETWORK)
doraESNeo3 = new DoraESNeo3(BSEpicChainConstants.DEFAULT_NETWORK)
})
it('Should return a transaction url', async () => {
const hash = '0x775d824a54d4e9bebf3c522a7d8dede550348323d833ce68fbcf0ab953d579e8'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import Transport from '@ledgerhq/hw-transport'
import { NeonDappKitLedgerServiceNeo3 } from '../../../services/ledger/EpicVaultDappKitLedgerServiceEpicChain'
import { EpicVaultDappKitLedgerServiceEpicChain } from '../../../services/ledger/EpicVaultDappKitLedgerServiceEpicChain'
import { BSNeo3 } from '../../../BSEpicChain'
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import { BSNeo3Constants } from '../../../constants/BSEpicChainConstants'
import { BSEpicChainConstants } from '../../../constants/BSEpicChainConstants'

let ledgerService: NeonDappKitLedgerServiceNeo3
let ledgerService: EpicVaultDappKitLedgerServiceEpicChain
let transport: Transport
let bsNeo3: BSNeo3

describe.skip('NeonDappKitLedgerServiceNeo3.spec', () => {
describe.skip('EpicVaultDappKitLedgerServiceEpicChain.spec', () => {
beforeAll(async () => {
const network = BSNeo3Constants.TESTNET_NETWORKS[0]!
const network = BSEpicChainConstants.TESTNET_NETWORKS[0]!
bsNeo3 = new BSNeo3('neo3', network)

transport = await TransportNodeHid.create()
ledgerService = new NeonDappKitLedgerServiceNeo3(bsNeo3, async () => transport)
ledgerService = new EpicVaultDappKitLedgerServiceEpicChain(bsNeo3, async () => transport)
}, 60000)

it('Should be able to get all accounts', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BSNeo3Constants } from '../../../constants/BSEpicChainConstants'
import { BSEpicChainConstants } from '../../../constants/BSEpicChainConstants'
import { GhostMarketNDSNeo3 } from '../../../services/nft-data/GhostMarketNDSEpicChain'

let ghostMarketNDSNeo3: GhostMarketNDSNeo3

describe('GhostMarketNDSNeo3', () => {
beforeAll(() => {
ghostMarketNDSNeo3 = new GhostMarketNDSNeo3(BSNeo3Constants.DEFAULT_NETWORK)
ghostMarketNDSNeo3 = new GhostMarketNDSNeo3(BSEpicChainConstants.DEFAULT_NETWORK)
})

describe('TTM', () => {
Expand Down
20 changes: 10 additions & 10 deletions packages/bs-epicchain/src/constants/BSEpicChainConstants.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Network, NetworkId, Token } from '@epicchain/blockchain-service'
import mainnetTokens from '../assets/tokens/mainnet.json'

export type BSNeo3NetworkId = NetworkId<'mainnet' | 'testnet'>
export type BSEpicChainNetworkId = NetworkId<'mainnet' | 'testnet'>

export class BSNeo3Constants {
static EXTRA_TOKENS_BY_NETWORK_ID: Partial<Record<BSNeo3NetworkId, Token[]>> = {
export class BSEpicChainConstants {
static EXTRA_TOKENS_BY_NETWORK_ID: Partial<Record<BSEpicChainNetworkId, Token[]>> = {
mainnet: mainnetTokens,
}

static RPC_LIST_BY_NETWORK_ID: Partial<Record<BSNeo3NetworkId, string[]>> = {
static RPC_LIST_BY_NETWORK_ID: Partial<Record<BSEpicChainNetworkId, string[]>> = {
mainnet: [
'http://mainnet1-seed.epic-chain.org:10111',
'http://mainnet2-seed.epic-chain.org:10111',
Expand All @@ -25,25 +25,25 @@ export class BSNeo3Constants {
],
}

static MAINNET_NETWORK_IDS: BSNeo3NetworkId[] = ['mainnet']
static TESTNET_NETWORK_IDS: BSNeo3NetworkId[] = ['testnet']
static ALL_NETWORK_IDS: BSNeo3NetworkId[] = [...this.MAINNET_NETWORK_IDS, ...this.TESTNET_NETWORK_IDS]
static MAINNET_NETWORK_IDS: BSEpicChainNetworkId[] = ['mainnet']
static TESTNET_NETWORK_IDS: BSEpicChainNetworkId[] = ['testnet']
static ALL_NETWORK_IDS: BSEpicChainNetworkId[] = [...this.MAINNET_NETWORK_IDS, ...this.TESTNET_NETWORK_IDS]

static MAINNET_NETWORKS: Network<BSNeo3NetworkId>[] = [
static MAINNET_NETWORKS: Network<BSEpicChainNetworkId>[] = [
{
id: 'mainnet',
name: 'Mainnet',
url: this.RPC_LIST_BY_NETWORK_ID['mainnet']![0],
},
]
static TESTNET_NETWORKS: Network<BSNeo3NetworkId>[] = [
static TESTNET_NETWORKS: Network<BSEpicChainNetworkId>[] = [
{
id: 'testnet',
name: 'Testnet',
url: this.RPC_LIST_BY_NETWORK_ID['testnet']![0],
},
]
static ALL_NETWORKS: Network<BSNeo3NetworkId>[] = [...this.MAINNET_NETWORKS, ...this.TESTNET_NETWORKS]
static ALL_NETWORKS: Network<BSEpicChainNetworkId>[] = [...this.MAINNET_NETWORKS, ...this.TESTNET_NETWORKS]

static DEFAULT_NETWORK = this.MAINNET_NETWORKS[0]

Expand Down
20 changes: 10 additions & 10 deletions packages/bs-epicchain/src/helpers/BSEpicChainHelper.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Network } from '@epicchain/blockchain-service'
import commonTokens from '../assets/tokens/common.json'
import { BSNeo3Constants, BSNeo3NetworkId } from '../constants/BSEpicChainConstants'
import { BSEpicChainConstants, BSEpicChainNetworkId } from '../constants/BSEpicChainConstants'

export class BSNeo3Helper {
static getTokens(network: Network<BSNeo3NetworkId>) {
const extraTokens = BSNeo3Constants.EXTRA_TOKENS_BY_NETWORK_ID[network.id] ?? []
export class BSEpicChainHelper {
static getTokens(network: Network<BSEpicChainNetworkId>) {
const extraTokens = BSEpicChainConstants.EXTRA_TOKENS_BY_NETWORK_ID[network.id] ?? []
return [...extraTokens, ...commonTokens]
}

static getRpcList(network: Network<BSNeo3NetworkId>) {
return BSNeo3Constants.RPC_LIST_BY_NETWORK_ID[network.id] ?? []
static getRpcList(network: Network<BSEpicChainNetworkId>) {
return BSEpicChainConstants.RPC_LIST_BY_NETWORK_ID[network.id] ?? []
}

static isMainnet(network: Network<BSNeo3NetworkId>) {
return BSNeo3Constants.MAINNET_NETWORK_IDS.includes(network.id)
static isMainnet(network: Network<BSEpicChainNetworkId>) {
return BSEpicChainConstants.MAINNET_NETWORK_IDS.includes(network.id)
}

static isCustomNet(network: Network<BSNeo3NetworkId>) {
return !BSNeo3Constants.ALL_NETWORK_IDS.includes(network.id)
static isCustomNet(network: Network<BSEpicChainNetworkId>) {
return !BSEpicChainConstants.ALL_NETWORK_IDS.includes(network.id)
}

static normalizeHash(hash: string): string {
Expand Down
Loading

0 comments on commit 4016f5a

Please sign in to comment.