Skip to content

Commit

Permalink
Merge branch 'master' into i-843/fix/get-latest-submitted-value-for-a…
Browse files Browse the repository at this point in the history
…ggregator
  • Loading branch information
bayram98 authored Nov 10, 2023
2 parents 31f5f43 + ae1e7ef commit 2319501
Show file tree
Hide file tree
Showing 167 changed files with 27,302 additions and 366 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/contracts.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ on:
- "master"
paths:
- "contracts/**"

- "!contracts/**/VRFCoordinator.sol"
- "!contracts/**/VRFConsumerBase.sol"
- "!contracts/**/vrf/**"
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -28,10 +30,14 @@ jobs:
working-directory: ./contracts
- run: yarn eslint
working-directory: ./contracts
- run: npx hardhat test
- run: npx hardhat test test/v0.1/non-vrf/*.cjs
working-directory: ./contracts
env:
L2_PROVIDER: ${{ secrets.L2_PROVIDER }}
- run: yarn compile
working-directory: ./contracts
env:
L2_PROVIDER: ${{ secrets.L2_PROVIDER }}
- run: yarn build
working-directory: ./contracts
- name: Extract version from package.json
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/vrf.contracts.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "vrf contracts: test"

on:
push:
branches-ignore:
- "master"
paths:
- "contracts/**/VRFCoordinator.sol"
- "contracts/**/VRFConsumerBase.sol"
- "contracts/**/vrf/**"
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18.12"
registry-url: "https://registry.npmjs.org"
scope: "@bisonai"
always-auth: true
- run: yarn
working-directory: ./contracts
- run: yarn prettier-solidity-check
working-directory: ./contracts
- run: yarn solhint
working-directory: ./contracts
- run: yarn eslint
working-directory: ./contracts
- run: npx hardhat test test/v0.1/vrf/*.cjs
working-directory: ./contracts
- run: yarn compile
working-directory: ./contracts
- run: yarn build
working-directory: ./contracts
3 changes: 3 additions & 0 deletions api/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DATABASE_URL=postgresql://${USER}@localhost:5432/orakl?schema=public
APP_PORT=3000
ENCRYPT_PASSWORD=anything
22 changes: 16 additions & 6 deletions api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ datasource db {
}

model Chain {
id BigInt @id @default(autoincrement()) @map("chain_id")
name String @unique
Aggregator Aggregator[]
Listener Listener[]
VrfKey VrfKey[]
Reporter Reporter[]
id BigInt @id @default(autoincrement()) @map("chain_id")
name String @unique
Aggregator Aggregator[]
Listener Listener[]
VrfKey VrfKey[]
Reporter Reporter[]
L2AggregatorPair L2AggregatorPair[]
@@map("chains")
}
Expand Down Expand Up @@ -166,3 +167,12 @@ model Proxy {
@@unique([protocol, host, port])
@@map("proxies")
}

model L2AggregatorPair {
id BigInt @id @default(autoincrement())
l1AggregatorAddress String @map("l1_aggregator_addresss")
l2AggregatorAddress String @map("l2_aggregator_addresss")
active Boolean @default(false)
chainId BigInt @map("chain_id")
chain Chain @relation(fields: [chainId], references: [id])
}
4 changes: 3 additions & 1 deletion api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ReporterModule } from './reporter/reporter.module'
import { ErrorModule } from './error/error.module'
import { ProxyModule } from './proxy/proxy.module'
import { LastSubmissionModule } from './last-submission/last-submission.module'
import { L2aggregatorModule } from './l2aggregator/L2aggregator.module';

@Module({
imports: [
Expand All @@ -30,7 +31,8 @@ import { LastSubmissionModule } from './last-submission/last-submission.module'
ReporterModule,
ErrorModule,
ProxyModule,
LastSubmissionModule
LastSubmissionModule,
L2aggregatorModule
],
controllers: [AppController],
providers: [AppService, ConfigService]
Expand Down
24 changes: 24 additions & 0 deletions api/src/l2aggregator/L2aggregator.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Controller, Get, HttpException, HttpStatus, Param } from '@nestjs/common'
import { L2aggregatorService } from './L2aggregator.service'
import { ChainService } from '../chain/chain.service'

@Controller({
path: 'l2aggregator',
version: '1'
})
export class L2aggregatorController {
constructor(
private readonly l2AggregatorService: L2aggregatorService,
private readonly chainService: ChainService
) {}
@Get(':chain/:l1Address')
async getL2Address(@Param('chain') chain: string, @Param('l1Address') l1Address: string) {
// chain
const chainRecord = await this.chainService.findOne({ name: chain })
if (chainRecord == null) {
const msg = `Chain [${chain}] not found`
throw new HttpException(msg, HttpStatus.NOT_FOUND)
}
return await this.l2AggregatorService.l2Address(l1Address, chainRecord.id)
}
}
11 changes: 11 additions & 0 deletions api/src/l2aggregator/L2aggregator.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common'
import { L2aggregatorController } from './L2aggregator.controller'
import { L2aggregatorService } from './L2aggregator.service'
import { ChainService } from '../chain/chain.service'
import { PrismaService } from '../prisma.service'

@Module({
controllers: [L2aggregatorController],
providers: [L2aggregatorService, ChainService, PrismaService]
})
export class L2aggregatorModule {}
19 changes: 19 additions & 0 deletions api/src/l2aggregator/L2aggregator.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Test, TestingModule } from '@nestjs/testing'
import { L2aggregatorService } from './L2aggregator.service'
import { PrismaService } from '../prisma.service'

describe('L2aggregatorService', () => {
let service: L2aggregatorService

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [L2aggregatorService, PrismaService]
}).compile()

service = module.get<L2aggregatorService>(L2aggregatorService)
})

it('should be defined', () => {
expect(service).toBeDefined()
})
})
12 changes: 12 additions & 0 deletions api/src/l2aggregator/L2aggregator.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Injectable } from '@nestjs/common'
import { PrismaService } from '../prisma.service'

@Injectable()
export class L2aggregatorService {
constructor(private readonly prismaService: PrismaService) {}
async l2Address(l1Address: string, chainId: bigint) {
return await this.prismaService.l2AggregatorPair.findFirst({
where: { l1AggregatorAddress: l1Address, chainId }
})
}
}
8 changes: 8 additions & 0 deletions cli/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ORAKL_NETWORK_API_URL=http://127.0.0.1:3000/api/v1
ORAKL_NETWORK_DELEGATOR_URL=
LISTENER_SERVICE_HOST=http://127.0.0.1
LISTENER_SERVICE_PORT=4000
WORKER_SERVICE_HOST=http://127.0.0.1
WORKER_SERVICE_PORT=5001
REPORTER_SERVICE_HOST=http://127.0.0.1
REPORTER_SERVICE_PORT=6000
4 changes: 3 additions & 1 deletion cli/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ export function hashHandler() {
console.dir(adapterWithCorrectHash, { depth: null })
} catch (e) {
console.error('Adapter hash could not be computed. Reason:')
console.error(e.message)
const errMsg = e?.response?.data?.message ? e.response.data.message : e.message

console.error(errMsg)
}
}
return wrapper
Expand Down
2 changes: 1 addition & 1 deletion cli/src/aggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export function insertHandler() {
}: {
data
chain: string
fetcherType: number
fetcherType?: number
}) {
if (!(await isOraklNetworkApiHealthy())) return

Expand Down
19 changes: 16 additions & 3 deletions cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,23 @@ export async function isOraklNetworkApiHealthy() {
}

export async function isOraklFetcherHealthy(url: string) {
if (!(await isValidUrl(url))) {
console.error('Invalid URL')
return false
}

try {
return 200 === (await axios.get(url))?.status
} catch (e) {
console.error(`Orakl Network Fetcher [${url}] is down`)
const response = await axios.get(url)
if (response.status === 200) {
return true
} else {
console.error(`Orakl Network Fetcher [${url}] is down. HTTP Status: ${response.status}`)
return false
}
} catch (error) {
console.error(
`An error occurred while checking the Orakl Network Fetcher [${url}]: ${error.message}`
)
return false
}
}
Expand Down
31 changes: 31 additions & 0 deletions contracts/deploy/L2Endpoint/L2Endpoint.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const path = require('node:path')
const { loadJson, loadMigration, updateMigration } = require('../../scripts/v0.1/utils.cjs')

const func = async function (hre) {
const { deployments, getNamedAccounts, network } = hre
const { deploy } = deployments
const { deployer } = await getNamedAccounts()
const migrationDirPath = `./migration/${network.name}/L2Endpoint`
const migrationFilesNames = await loadMigration(migrationDirPath)
for (const migration of migrationFilesNames) {
const config = await loadJson(path.join(migrationDirPath, migration))
// Deploy L2Endpoint ////////////////////////////////////////////////////////
if (config.deploy) {
console.log('deploy')
const l2EndpointDeployment = await deploy('L2Endpoint', {
args: [],
from: deployer,
log: true
})

console.log('l2EndpointDeployment:', l2EndpointDeployment)
}

await updateMigration(migrationDirPath, migration)
}
}

func.id = 'deploy-l2Endpoint'
func.tags = ['l2Endpoint']

module.exports = func
Loading

0 comments on commit 2319501

Please sign in to comment.