8000 Initialize Orakl Network API through `orakl-cli` by martinkersner · Pull Request #336 · Bisonai/orakl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Initialize Orakl Network API through orakl-cli #336

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
54e2011
feat: List `chains` through Orakl Network API
martinkersner Mar 5, 2023
3349380
feat: Insert chain through orakl-cli
martinkersner Mar 5, 2023
6f8e748
feat: Remove chain
martinkersner Mar 5, 2023
73d240f
feat: Skip chain cli tests
martinkersner Mar 5, 2023
b1d503a
feat: Don't import SQLite instance to chain submodule
martinkersner Mar 5, 2023
46e37de
chore: Cleanup chain submodule
martinkersner Mar 5, 2023
9d0fc80
feat: Insert adapter
martinkersner Mar 5, 2023
e0e35be
feat: Delete adapter
martinkersner Mar 5, 2023
7878e36
chore: Skip cli-adapter tests
martinkersner Mar 5, 2023
1602f18
feat: Remove inserting adapter from other chain
martinkersner Mar 5, 2023
0d79147
fix: eslint
martinkersner Mar 5, 2023
2a4069f
chore: Change format of adapter configurations
martinkersner Mar 5, 2023
69b0b72
feat: List aggregators
martinkersner Mar 5, 2023
3f14458
feat: Fix API test & allow to pass JSON feed
martinkersner Mar 5, 2023
0c48dc0
fix: Where input aggregator
martinkersner Mar 5, 2023
5e1b47f
feat: Insert aggregator
martinkersner Mar 5, 2023
eb9008d
feat: Remove aggregator
martinkersner Mar 5, 2023
abcbdbb
chore: Format change of aggregator + cleanup
martinkersner Mar 5, 2023
b5fa833
feat: Catch error on duplicated aggregator
martinkersner Mar 5, 2023
ce6f309
feat: Remove `insertFromChain` aggregator handler
martinkersner Mar 5, 2023
3e64155
fix: eslint
martinkersner Mar 5, 2023
4b9783f
feat: Add axios dependency
martinkersner Mar 5, 2023
15a19cc
fix: Adapter test
martinkersner Mar 5, 2023
387f6d9
feat: Bump up version of `orakl-cli` to 0.3.0 & publish
martinkersner Mar 5, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ CREATE TABLE "Chain" (
CREATE TABLE "Feed" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"latestRound" INTEGER NOT NULL,
"definition" JSONB NOT NULL,
"adapterId" INTEGER NOT NULL,

Expand Down
1 change: 0 additions & 1 deletion api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ model Chain {
model Feed {
id Int @id @default(autoincrement())
name String
latestRound Int
definition Json
adapter Adapter @relation(fields: [adapterId], references: [id], onDelete: Cascade)
adapterId Int
Expand Down
7 changes: 6 additions & 1 deletion api/src/adapter/adapter.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, Post, Body, Param } from '@nestjs/common'
import { Controller, Get, Post, Body, Param, Delete } from '@nestjs/common'
import { Adapter as AdapterModel } from '@prisma/client'
import { AdapterService } from './adapter.service'
import { AdapterDto } from './dto/adapter.dto'
Expand All @@ -24,4 +24,9 @@ export class AdapterController {
findOne(@Param('id') id: string) {
return this.adapterService.findOne({ id: Number(id) })
}

@Delete(':id')
async remove(@Param('id') id: string): Promise<AdapterModel> {
return this.adapterService.remove({ id: Number(id) })
}
}
7 changes: 3 additions & 4 deletions api/src/adapter/adapter.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ describe('AdapterService', () => {
const feeds = [
{
name: 'Binance-BTC-USD',
latestRound: -1,
definition: JSON.stringify({
definition: {
url: 'https://api.binance.us/api/v3/ticker/price?symbol=BTCUSD',
headers: {
'Content-Type': 'application/json'
Expand All @@ -41,12 +40,12 @@ describe('AdapterService', () => {
function: 'ROUND'
}
]
})
}
}
]

const { id } = await adapter.create({
adapterId: '0xe63985ed9d9aae887bdcfa03b53a1bea6fd1acc58b8cd51a9a69ede43eac6235',
id: '0xe63985ed9d9aae887bdcfa03b53a1bea6fd1acc58b8cd51a9a F438 69ede43eac6235',
name: 'BTC-USD',
decimals: 8,
feeds
Expand Down
6 changes: 3 additions & 3 deletions api/src/adapter/adapter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ export class AdapterService {
constructor(private prisma: PrismaService) {}

create(adapterDto: AdapterDto): Promise<Adapter> {
// TODO validate

const data: Prisma.AdapterCreateInput = {
adapterId: adapterDto.adapterId,
adapterId: adapterDto.id,
name: adapterDto.name,
decimals: adapterDto.decimals,
feeds: {
create: adapterDto.feeds
}
}

// TODO validate

return this.prisma.adapter.create({ data })
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/adapter/dto/adapter.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FeedDto as Feed } from '../../feed/dto/feed.dto'

export class AdapterDto {
@ApiProperty()
adapterId: string
id: string

@ApiProperty()
name: string
Expand Down
38 changes: 33 additions & 5 deletions api/src/aggregator/aggregator.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { Controller, Get, Post, Body, Param } from '@nestjs/common'
import {
Controller,
Get,
Post,
Body,
Delete,
Param,
HttpException,
HttpStatus
} from '@nestjs/common'
import { Aggregator as AggregatorModel } from '@prisma/client'
import { AggregatorService } from './aggregator.service'
import { AggregatorDto } from './dto/aggregator.dto'
import { AggregatorWhereDto } from './dto/aggregator-where.dto'
import { PRISMA_ERRORS } from '../errors'

@Controller({
path: 'aggregator',
Expand All @@ -11,17 +22,34 @@ export class AggregatorController {
constructor(private readonly aggregatorService: AggregatorService) {}

@Post()
create(@Body() aggregatorDto: AggregatorDto): Promise<AggregatorModel> {
return this.aggregatorService.create(aggregatorDto)
async create(@Body() aggregatorDto: AggregatorDto) {
return await this.aggregatorService.create(aggregatorDto).catch((err) => {
throw new HttpException(
{
message: PRISMA_ERRORS[err.code](err.meta)
},
HttpStatus.BAD_REQUEST
)
})
}

@Get()
findAll() {
return this.aggregatorService.findAll({})
findAll(@Body() whereDto: AggregatorWhereDto) {
return this.aggregatorService.findAll({
where: {
chain: { name: whereDto.chain },
active: whereDto.active
}
})
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.aggregatorService.findOne({ id: Number(id) })
}

@Delete(':id')
async remove(@Param('id') id: string): Promise<AggregatorModel> {
return this.aggregatorService.remove({ id: Number(id) })
}
}
11 changes: 5 additions & 6 deletions api/src/aggregator/aggregator.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ describe('AggregatorService', () => {
const feeds = [
{
name: 'Binance-BTC-USD',
latestRound: -1,
definition: JSON.stringify({
definition: {
url: 'https://api.binance.us/api/v3/ticker/price?symbol=BTCUSD',
headers: {
'Content-Type': 'application/json'
Expand All @@ -51,27 +50,27 @@ describe('AggregatorService', () => {
function: 'ROUND'
}
]
})
}
}
]
const adapterObj = await adapter.create({
adapterId: 'adapterId-aggregator-test',
id: 'adapterId-aggregator-test',
name: 'BTC-USD',
decimals: 8,
feeds
})

// Aggregator
const aggregatorData = {
aggregatorId: 'aggregatorId-aggregator-test',
id: 'aggregatorId-aggregator-test',
active: false,
name: 'ETH-USD',
address: '0x',
heartbeat: 10_000,
threshold: 0.04,
absoluteThreshold: 0.1,
adapterId: adapterObj.adapterId,
chainName: chainObj.name
chain: chainObj.name
}
const aggregatorObj = await aggregator.create(aggregatorData)

Expand Down
6 changes: 3 additions & 3 deletions api/src/aggregator/aggregator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export class AggregatorService {

async create(aggregatorDto: AggregatorDto): Promise<Aggregator> {
const chain = await this.prisma.chain.findUnique({
where: { name: aggregatorDto.chainName }
where: { name: aggregatorDto.chain }
})

const adapter = await this.prisma.adapter.findUnique({
where: { adapterId: aggregatorDto.adapterId }
})

const data: Prisma.AggregatorUncheckedCreateInput = {
aggregatorId: aggregatorDto.aggregatorId,
aggregatorId: aggregatorDto.id,
active: aggregatorDto.active,
name: aggregatorDto.name,
address: aggregatorDto.address,
Expand All @@ -28,7 +28,7 @@ export class AggregatorService {
chainId: chain.id
}

return this.prisma.aggregator.create({ data })
return await this.prisma.aggregator.create({ data })
}

async findAll(params: {
Expand Down
9 changes: 9 additions & 0 deletions api/src/aggregator/dto/aggregator-where.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApiProperty } from '@nestjs/swagger'

export class AggregatorWhereDto {
@ApiProperty()
active?: boolean

@ApiProperty()
chain?: string
}
4 changes: 2 additions & 2 deletions api/src/aggregator/dto/aggregator.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiProperty } from '@nestjs/swagger'

export class AggregatorDto {
@ApiProperty()
aggregatorId: string
id: string

@ApiProperty()
active: boolean
Expand All @@ -26,5 +26,5 @@ export class AggregatorDto {
adapterId: string

@ApiProperty()
chainName: string
chain: string
}
11 changes: 5 additions & 6 deletions api/src/data/data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ describe('DataService', () => {
const feeds = [
{
name: 'Binance-BTC-USD',
latestRound: -1,
definition: JSON.stringify({
definition: {
url: 'https://api.binance.us/api/v3/ticker/price?symbol=BTCUSD',
headers: {
'Content-Type': 'application/json'
Expand All @@ -54,27 +53,27 @@ describe('DataService', () => {
function: 'ROUND'
}
]
})
}
}
]
const adapterObj = await adapter.create({
adapterId: 'adapterId-data-test',
id: 'adapterId-data-test',
name: 'BTC-USD',
decimals: 8,
feeds
})

// Aggregator
const aggregatorData = {
aggregatorId: 'aggregatorId-data-test',
id: 'aggregatorId-data-test',
active: false,
name: 'ETH-USD',
address: '0x',
heartbeat: 10_000,
threshold: 0.04,
absoluteThreshold: 0.1,
adapterId: adapterObj.adapterId,
chainName: chainObj.name
chain: chainObj.name
}
const aggregatorObj = await aggregator.create(aggregatorData)

Expand Down
4 changes: 4 additions & 0 deletions api/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// https://www.prisma.io/docs/reference/api-reference/error-reference
export const PRISMA_ERRORS = {
P2002: (meta) => `Unique constraint failed on the ${meta.target}`
}
5 changes: 1 addition & 4 deletions api/src/feed/dto/feed.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ export class FeedDto {
name: string

@ApiProperty()
latestRound: number

@ApiProperty()
definition: string
definition: any
}
Loading
0