Skip to content

Commit

Permalink
feat(indexer): deprecated SetOracleDataIntervalIndexer Indexer & API (J…
Browse files Browse the repository at this point in the history
…ellyfishSDK/whale#749)

* feat(indexer): deprecated SetOracleDataIntervalIndexer Indexer & API

* updated deprecation notice with PR url

* fix invalid import
  • Loading branch information
fuxingloh authored Feb 3, 2022
1 parent 776c121 commit 9f85017
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 340 deletions.
2 changes: 1 addition & 1 deletion apps/whale/src/module.api/_core/api.paged.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class ApiPagedResponse<T> implements ApiResponse {
data: T[]
page?: ApiPage

private constructor (data: T[], next?: string) {
protected constructor (data: T[], next?: string) {
this.data = data
this.page = next !== undefined ? { next } : undefined
}
Expand Down
31 changes: 19 additions & 12 deletions apps/whale/src/module.api/price.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import { PriceTicker, PriceTickerMapper } from '@src/module.model/price.ticker'
import { PriceOracle } from '@whale-api-client/api/prices'
import { OraclePriceFeedMapper } from '@src/module.model/oracle.price.feed'
import { OraclePriceActive, OraclePriceActiveMapper } from '@src/module.model/oracle.price.active'
import {
OraclePriceAggregatedInterval,
OraclePriceAggregatedIntervalMapper
} from '@src/module.model/oracle.price.aggregated.interval'
import { ApiError } from '@src/module.api/_core/api.error'

@Controller('/prices')
export class PriceController {
Expand All @@ -19,8 +16,7 @@ export class PriceController {
protected readonly oracleTokenCurrencyMapper: OracleTokenCurrencyMapper,
protected readonly priceTickerMapper: PriceTickerMapper,
protected readonly priceFeedMapper: OraclePriceFeedMapper,
protected readonly oraclePriceActiveMapper: OraclePriceActiveMapper,
protected readonly oraclePriceAggregatedIntervalMapper: OraclePriceAggregatedIntervalMapper
protected readonly oraclePriceActiveMapper: OraclePriceActiveMapper
) {
}

Expand Down Expand Up @@ -68,12 +64,8 @@ export class PriceController {
@Param('key') key: string,
@Param('interval', ParseIntPipe) interval: number,
@Query() query: PaginationQuery
): Promise<ApiPagedResponse<OraclePriceAggregatedInterval>> {
const priceKey = `${key}-${interval}`
const items = await this.oraclePriceAggregatedIntervalMapper.query(priceKey, query.size, query.next)
return ApiPagedResponse.of(items, query.size, item => {
return item.sort
})
): Promise<ApiPagedResponse<any>> {
return new DeprecatedIntervalApiPagedResponse()
}

@Get('/:key/oracles')
Expand All @@ -94,3 +86,18 @@ export class PriceController {
})
}
}

class DeprecatedIntervalApiPagedResponse<T> extends ApiPagedResponse<T> {
error?: ApiError

constructor () {
super([])
this.error = {
at: Date.now(),
code: 410,
type: 'Gone',
message: 'Oracle feed interval data has been deprecated with immediate effect. See https://github.com/DeFiCh/whale/pull/749 for more information.',
url: '/:key/feed/interval/:interval'
}
}
}
3 changes: 0 additions & 3 deletions apps/whale/src/module.indexer/model/dftx.indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { AppointOracleIndexer } from '@src/module.indexer/model/dftx/appoint.ora
import { RemoveOracleIndexer } from '@src/module.indexer/model/dftx/remove.oracle'
import { UpdateOracleIndexer } from '@src/module.indexer/model/dftx/update.oracle'
import { SetOracleDataIndexer } from '@src/module.indexer/model/dftx/set.oracle.data'
import { SetOracleDataIntervalIndexer } from '@src/module.indexer/model/dftx/set.oracle.data.interval'
import { CreateMasternodeIndexer } from '@src/module.indexer/model/dftx/create.masternode'
import { ResignMasternodeIndexer } from '@src/module.indexer/model/dftx/resign.masternode'
import { Injectable, Logger } from '@nestjs/common'
Expand All @@ -24,7 +23,6 @@ export class MainDfTxIndexer extends Indexer {
private readonly removeOracle: RemoveOracleIndexer,
private readonly updateOracle: UpdateOracleIndexer,
private readonly setOracleData: SetOracleDataIndexer,
private readonly setOracleDataInterval: SetOracleDataIntervalIndexer,
private readonly createMasternode: CreateMasternodeIndexer,
private readonly resignMasternode: ResignMasternodeIndexer,
private readonly activePriceIndexer: ActivePriceIndexer,
Expand All @@ -38,7 +36,6 @@ export class MainDfTxIndexer extends Indexer {
setOracleData,
createMasternode,
resignMasternode,
setOracleDataInterval,
activePriceIndexer,
placeAuctionBidIndexer
]
Expand Down
2 changes: 0 additions & 2 deletions apps/whale/src/module.indexer/model/dftx/_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AppointOracleIndexer } from '@src/module.indexer/model/dftx/appoint.ora
import { RemoveOracleIndexer } from '@src/module.indexer/model/dftx/remove.oracle'
import { UpdateOracleIndexer } from '@src/module.indexer/model/dftx/update.oracle'
import { SetOracleDataIndexer } from '@src/module.indexer/model/dftx/set.oracle.data'
import { SetOracleDataIntervalIndexer } from '@src/module.indexer/model/dftx/set.oracle.data.interval'
import { CreateMasternodeIndexer } from '@src/module.indexer/model/dftx/create.masternode'
import { ResignMasternodeIndexer } from '@src/module.indexer/model/dftx/resign.masternode'
import { NetworkName } from '@defichain/jellyfish-network'
Expand All @@ -18,7 +17,6 @@ const indexers = [
UpdateOracleIndexer,
CreateMasternodeIndexer,
ResignMasternodeIndexer,
SetOracleDataIntervalIndexer,
ActivePriceIndexer,
PlaceAuctionBidIndexer
]
Expand Down
85 changes: 0 additions & 85 deletions apps/whale/src/module.indexer/model/dftx/oracle.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import { NestFastifyApplication } from '@nestjs/platform-fastify'
import { createTestingApp, invalidateFromHeight, stopTestingApp, waitForIndexedHeight } from '@src/e2e.module'
import { OraclePriceFeedMapper } from '@src/module.model/oracle.price.feed'
import { OraclePriceAggregatedMapper } from '@src/module.model/oracle.price.aggregated'
import {
OracleIntervalSeconds,
OraclePriceAggregatedIntervalMapper
} from '@src/module.model/oracle.price.aggregated.interval'

describe('invalidate appoint/remove/update oracle', () => {
const container = new MasterNodeRegTestContainer()
Expand Down Expand Up @@ -370,84 +366,3 @@ describe('invalidate set oracle data', () => {
}
})
})

describe('interval set oracle data', () => {
const container = new MasterNodeRegTestContainer()
let app: NestFastifyApplication
let client: JsonRpcClient

beforeAll(async () => {
await container.start()
await container.waitForWalletCoinbaseMaturity()

app = await createTestingApp(container)
client = new JsonRpcClient(await container.getCachedRpcUrl())
})

afterAll(async () => {
await stopTestingApp(container, app)
})

it('should get interval', async () => {
const address = await container.getNewAddress()
const oracleId = await client.oracle.appointOracle(address, [
{ token: 'S1', currency: 'USD' }
], {
weightage: 1
})
await container.generate(1)

const oneMinute = 60
const timeNow = Math.floor(new Date().getTime() / 1000)
for (let i = 0; i < 60; i++) {
const mockTime = timeNow + i * oneMinute
const price = (i + 1).toFixed(2)
await client.oracle.setOracleData(oracleId, timeNow + 5 * 60 - 1, {
prices: [
{ tokenAmount: `${price}@S1`, currency: 'USD' }
]
})
await client.misc.setMockTime(mockTime)
await container.generate(1)
}

const height = await container.getBlockCount()
await container.generate(1)
await waitForIndexedHeight(app, height)

const noInterval = await app.get(OraclePriceAggregatedMapper).query('S1-USD', Number.MAX_SAFE_INTEGER)
expect(noInterval.length).toStrictEqual(60)

const interval5Minutes = await app.get(OraclePriceAggregatedIntervalMapper).query(`S1-USD-${OracleIntervalSeconds.FIVE_MINUTES}`, Number.MAX_SAFE_INTEGER)
expect(interval5Minutes.length).toStrictEqual(11)
expect(interval5Minutes.map(x => x.aggregated.amount)).toStrictEqual(
[
'58.50000000',
'53.50000000',
'47.50000000',
'41.50000000',
'35.50000000',
'29.50000000',
'23.50000000',
'17.50000000',
'11.50000000',
'5.00000000',
'1.00000000'
]
)

const interval10Minutes = await app.get(OraclePriceAggregatedIntervalMapper).query(`S1-USD-${OracleIntervalSeconds.TEN_MINUTES}`, Number.MAX_SAFE_INTEGER)
expect(interval10Minutes.length).toStrictEqual(7)
expect(interval10Minutes.map(x => x.aggregated.amount)).toStrictEqual(
[
'59.00000000',
'52.00000000',
'41.00000000',
'30.00000000',
'19.00000000',
'7.50000000',
'1.00000000'
]
)
})
})
158 changes: 0 additions & 158 deletions apps/whale/src/module.indexer/model/dftx/set.oracle.data.interval.ts

This file was deleted.

5 changes: 0 additions & 5 deletions apps/whale/src/module.model/_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { TransactionVinMapper } from '@src/module.model/transaction.vin'
import { TransactionVoutMapper } from '@src/module.model/transaction.vout'
import { OracleHistoryMapper } from '@src/module.model/oracle.history'
import { OraclePriceAggregatedMapper } from '@src/module.model/oracle.price.aggregated'
import {
OraclePriceAggregatedIntervalMapper
} from '@src/module.model/oracle.price.aggregated.interval'
import { OraclePriceFeedMapper } from '@src/module.model/oracle.price.feed'
import { OracleTokenCurrencyMapper } from '@src/module.model/oracle.token.currency'
import { OracleMapper } from '@src/module.model/oracle'
Expand All @@ -36,7 +33,6 @@ import { VaultAuctionHistoryMapper } from './vault.auction.batch.history'
TransactionVoutMapper,
OracleHistoryMapper,
OraclePriceAggregatedMapper,
OraclePriceAggregatedIntervalMapper,
OraclePriceFeedMapper,
OracleTokenCurrencyMapper,
OracleMapper,
Expand All @@ -58,7 +54,6 @@ import { VaultAuctionHistoryMapper } from './vault.auction.batch.history'
TransactionVoutMapper,
OracleHistoryMapper,
OraclePriceAggregatedMapper,
OraclePriceAggregatedIntervalMapper,
OraclePriceFeedMapper,
OracleTokenCurrencyMapper,
OracleMapper,
Expand Down
Loading

0 comments on commit 9f85017

Please sign in to comment.