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

Upgrade dependencies #155

Merged
merged 1 commit into from
Aug 19, 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
1,014 changes: 109 additions & 905 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"jest-junit": "^12.0.0",
"nodemon": "^3.0.2",
"rimraf": "^3.0.2",
"socket.io-client": "^4.4.1",
"socket.io-client": "^4.7.5",
"supertest": "^6.1.6",
"ts-jest": "^29.0.0",
"ts-node": "^10.9.1",
Expand All @@ -59,12 +59,12 @@
"axios": "^1.6.2",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"ethers": "^5.7.2",
"ethers": "^6.13.1",
"express": "^4.18.2",
"node-cache": "^5.1.2",
"opossum": "^8.1.3",
"rate-limiter-flexible": "^4.0.1",
"socket.io": "^4.6.1",
"socket.io": "^4.7.5",
"swagger-ui-express": "^4.5.0",
"yup": "^1.2.0"
}
Expand Down
4 changes: 2 additions & 2 deletions src/controller/httpsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import swaggerUI from 'swagger-ui-express'
import OpenApi from '../api/openapi'
import BitcoinRouter from '../service/bitcoin/BitcoinRouter'
import { ValidationError, object, string } from 'yup'
import { utils } from 'ethers'
import { AddressService } from '../service/address/AddressService'
import { supportedFiat } from '../coinmarketcap/support'
import { ethers } from 'ethers'

interface HttpsAPIDependencies {
app: Express,
Expand Down Expand Up @@ -52,7 +52,7 @@ export class HttpsAPI {
const addressSchema = object({
address: string().required('An address is invalid')
.trim()
.transform(address => utils.isAddress(address.toLowerCase()) ? address : '')
.transform(address => ethers.isAddress(address.toLowerCase()) ? address : '')
}).required()
const currencySchema = object({
convert: string().optional()
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function main () {
BLOCKBOOK_URL: network.BLOCKBOOK_URL,
CYPHER_ESTIMATE_FEE_URL: network.CYPHER_ESTIMATE_FEE_URL
})
nodeProvider[network.ID] = new ethers.providers.JsonRpcProvider(network.NODE_URL)
nodeProvider[network.ID] = new ethers.JsonRpcProvider(network.NODE_URL)
})
const coinMarketCapApi = new CoinMarketCapAPI(
environment.COIN_MARKET_CAP_URL,
Expand Down
2 changes: 1 addition & 1 deletion src/profiler/RbtcBalanceProfiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class RbtcBalanceProfiler extends Emitter {
private rbtcBalanceProvider: RbtcBalanceProvider
private currentBalance = {}

constructor (address: string, dataSource: DataSource, provider: ethers.providers.JsonRpcProvider) {
constructor (address: string, dataSource: DataSource, provider: ethers.JsonRpcProvider) {
super()
this.address = address
this.rbtcBalanceProvider = new RbtcBalanceProvider(this.address, dataSource, provider)
Expand Down
2 changes: 1 addition & 1 deletion src/profiler/profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Profiler extends Emitter {
tokenTransferProfiler: TokenTransferProfiler

constructor (address: string, dataSource: DataSource,
lastPrice: LastPrice, provider: ethers.providers.JsonRpcProvider) {
lastPrice: LastPrice, provider: ethers.JsonRpcProvider) {
super()
this.address = address

Expand Down
2 changes: 1 addition & 1 deletion src/repository/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export type RSKDatasource = {
}

export type RSKNodeProvider = {
[key: string] : ethers.providers.JsonRpcProvider
[key: string] : ethers.JsonRpcProvider
}

export type BitcoinDatasource = {
Expand Down
2 changes: 1 addition & 1 deletion src/service/address/AddressService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class AddressService {
const balance = await this.providerMapping[chainId].getBalance(address.toLowerCase())
const balances = await Promise.all([
this.dataSourceMapping[chainId].getTokensByAddress(address),
fromApiToRtbcBalance(balance.toHexString(), parseInt(chainId))
fromApiToRtbcBalance(`0x0${balance.toString(16)}`, parseInt(chainId))
])
return balances.flat()
}
Expand Down
8 changes: 4 additions & 4 deletions src/service/balance/rbtcBalanceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ import { PollingProvider } from '../AbstractPollingProvider'

export class RbtcBalanceProvider extends PollingProvider<Event> {
private dataSource: DataSource
private provider: ethers.providers.JsonRpcProvider
private provider: ethers.JsonRpcProvider

constructor (address: string, dataSource: DataSource, provider: ethers.providers.JsonRpcProvider) {
constructor (address: string, dataSource: DataSource, provider: ethers.JsonRpcProvider) {
super(address)
this.dataSource = dataSource
this.provider = provider
}

async poll () {
return await this.provider.getBalance(this.address.toLowerCase())
.then(balance => fromApiToRtbcBalance(balance.toHexString(), parseInt(this.dataSource.id)))
.then(balance => fromApiToRtbcBalance(balance.toString(16), parseInt(this.dataSource.id)))
.then(rbtcBalance => [{ type: 'newBalance', payload: rbtcBalance }])
.catch(() => [])
}

public async getCurrentBalance () {
return await this.provider.getBalance(this.address.toLowerCase())
.then(balance => fromApiToRtbcBalance(balance.toHexString(), parseInt(this.dataSource.id)))
.then(balance => fromApiToRtbcBalance(balance.toString(16), parseInt(this.dataSource.id)))
.catch(() => fromApiToRtbcBalance('0', parseInt(this.dataSource.id)))
}
}
10 changes: 3 additions & 7 deletions test/MockProvider.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { ethers } from 'ethers'

export class MockProvider extends ethers.providers.BaseProvider {
getBalance ():
Promise<ethers.BigNumber> {
return Promise.resolve(ethers.BigNumber.from('0x56900d33ca7fc0000'))
}
export const getBalance = ():
Promise<bigint> => {
return Promise.resolve(BigInt('0x056900d33ca7fc0000'))
}
7 changes: 5 additions & 2 deletions test/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from './mockAddressResponses'
import BitcoinCore from '../src/service/bitcoin/BitcoinCore'
import { LastPrice } from '../src/service/price/lastPrice'
import { MockProvider } from './MockProvider'
import { getBalance } from './MockProvider'
import { AddressService } from '../src/service/address/AddressService'

const setupTestApi = (dataSourceMapping: RSKDatasource) => {
Expand All @@ -19,7 +19,10 @@ const setupTestApi = (dataSourceMapping: RSKDatasource) => {
CYPHER_ESTIMATE_FEE_URL: process.env.CYPHER_ESTIMATE_FEE_URL || ''
})
const providerMapping = {}
providerMapping['31'] = new MockProvider(31)
const providerMock = {
getBalance
}
providerMapping['31'] = providerMock
const lastPrice = new LastPrice()
const addressService = new AddressService({
dataSourceMapping,
Expand Down
7 changes: 5 additions & 2 deletions test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LastPrice } from '../src/service/price/lastPrice'
import { PriceCollector } from '../src/service/price/priceCollector'
import { MockPrice } from '../src/service/price/mockPrice'
import BitcoinCore from '../src/service/bitcoin/BitcoinCore'
import { MockProvider } from './MockProvider'
import { getBalance } from './MockProvider'
import { AddressService } from '../src/service/address/AddressService'
let priceCollector

Expand All @@ -29,7 +29,10 @@ const setupTestApi = (coinMarketCapApi: CoinMarketCapAPI) => {
CYPHER_ESTIMATE_FEE_URL: process.env.CYPHER_ESTIMATE_FEE_URL || ''
})
const providerMapping = {}
providerMapping['31'] = new MockProvider(31)
const providerMock = {
getBalance
}
providerMapping['31'] = providerMock
const dataSourceMapping = { 31: {} } as any
const addressService = new AddressService({
dataSourceMapping,
Expand Down
7 changes: 5 additions & 2 deletions test/ws.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { pricesResponse } from './mockPriceResponses'
import { LastPrice } from '../src/service/price/lastPrice'
import { PriceCollector } from '../src/service/price/priceCollector'
import { Server } from 'socket.io'
import { MockProvider } from './MockProvider'
import { getBalance } from './MockProvider'
import { AddressService } from '../src/service/address/AddressService'

describe('web socket', () => {
Expand Down Expand Up @@ -54,7 +54,10 @@ describe('web socket', () => {
const dataSourceMapping = {}
dataSourceMapping['31'] = rskExplorerApiMock as any
const providerMapping = {}
providerMapping['31'] = new MockProvider(31)
const providerMock = {
getBalance
}
providerMapping['31'] = providerMock
const bitcoinMapping = {}
const addressService = new AddressService({
dataSourceMapping,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "ES2017",
"module": "commonjs",
"lib": ["es6"],
"allowJs": true,
Expand Down
Loading