-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from QuantWealth/nova-orderbook
Nova orderbook
- Loading branch information
Showing
20 changed files
with
748 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"logLevel": "debug", | ||
"chains": { | ||
"11155111": { | ||
"providers": ["https://1rpc.io/sepolia"], | ||
"contractAddresses": { | ||
"QWManager": { | ||
"contractName": "QWManager", | ||
"address": "0x13A1A7e98E0235FCFB034452C13c1B7548fa1651" | ||
}, | ||
"QWRegistry": { | ||
"contractName": "QWRegistry", | ||
"address": "0x57dbaE44a6a9F14294E4545cbaC5CBf9a9AD9b9a" | ||
}, | ||
"QWAaveV3": { | ||
"contractName": "QWAaveV3", | ||
"address": "0xA52a11Be28bEA0d559370eCbE2f1CB8B1e8e3EcA" | ||
} | ||
} | ||
} | ||
}, | ||
"gelatoApiKey": "", | ||
"privateKey": "", | ||
"environment": "staging" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
// TOKEN_BALANCE | ||
export * from './token-balance'; | ||
|
||
//USER_SAVINGS | ||
export * from './savings'; | ||
|
||
// contract addresses | ||
export * from './address'; | ||
export * from './qw'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import * as fs from 'fs'; | ||
import Ajv from 'ajv'; | ||
import { config as dotEnvConfig } from 'dotenv'; | ||
import { NovaConfig, NovaConfigSchema } from './schema'; | ||
|
||
// Load environment variables | ||
dotEnvConfig(); | ||
|
||
export const getEnvConfig = (): NovaConfig => { | ||
let configJson: Record<string, any> = {}; | ||
let configFile: any = {}; | ||
|
||
try { | ||
configJson = JSON.parse(process.env.NOVA_CONFIG || ''); | ||
} catch (e: unknown) { | ||
console.info( | ||
'No NOVA_CONFIG exists; using config file and individual env vars.', | ||
); | ||
} | ||
|
||
try { | ||
const path = process.env.NOVA_CONFIG_FILE ?? 'config.json'; | ||
if (fs.existsSync(path)) { | ||
const json = fs.readFileSync(path, { encoding: 'utf-8' }); | ||
configFile = JSON.parse(json); | ||
} | ||
} catch (e: unknown) { | ||
console.error('Error reading config file!'); | ||
process.exit(1); | ||
} | ||
|
||
const novaConfig: NovaConfig = { | ||
chains: process.env.NOVA_CHAIN_CONFIG | ||
? JSON.parse(process.env.NOVA_CHAIN_CONFIG) | ||
: configJson.chains || configFile.chains, | ||
logLevel: | ||
process.env.NOVA_LOG_LEVEL || | ||
configJson.logLevel || | ||
configFile.logLevel || | ||
'info', | ||
environment: | ||
process.env.NOVA_ENVIRONMENT || | ||
configJson.environment || | ||
configFile.environment || | ||
'staging', | ||
gelatoApiKey: | ||
process.env.GELATO_API_KEY || | ||
configJson.gelatoApiKey || | ||
configFile.gelatoApiKey, | ||
privateKey: | ||
process.env.PRIVATE_KEY || configJson.privateKey || configFile.privateKey, | ||
}; | ||
|
||
const ajv = new Ajv(); | ||
const validate = ajv.compile(NovaConfigSchema); | ||
const valid = validate(novaConfig); | ||
if (!valid) { | ||
throw new Error( | ||
validate.errors | ||
?.map((err: any) => JSON.stringify(err, null, 2)) | ||
.join(','), | ||
); | ||
} | ||
|
||
return novaConfig; | ||
}; | ||
|
||
export let novaConfig: NovaConfig | undefined; | ||
|
||
/** | ||
* Gets and validates the nova config from the environment. | ||
* @returns The nova config with sensible defaults | ||
*/ | ||
export const getConfig = async (): Promise<NovaConfig> => { | ||
if (!novaConfig) { | ||
novaConfig = getEnvConfig(); | ||
} | ||
return novaConfig; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Type, Static } from '@sinclair/typebox'; | ||
import { TAddress, TLogLevel } from '@qw/utils'; | ||
|
||
// Define the TChainConfig schema | ||
export const TChainConfig = Type.Object({ | ||
providers: Type.Array(Type.String()), | ||
contractAddresses: Type.Object({ | ||
QWManager: Type.Object({ | ||
contractName: Type.String(), | ||
address: TAddress, | ||
}), | ||
QWRegistry: Type.Object({ | ||
contractName: Type.String(), | ||
address: TAddress, | ||
}), | ||
QWAaveV3: Type.Object({ | ||
contractName: Type.String(), | ||
address: TAddress, | ||
}), | ||
}), | ||
}); | ||
|
||
// Define the TRPCConfig schema | ||
export const TRPCConfig = Type.Object({ | ||
url: Type.String(), | ||
}); | ||
|
||
// Define the NovaConfigSchema | ||
export const NovaConfigSchema = Type.Object({ | ||
chains: Type.Record(Type.String(), TChainConfig), | ||
logLevel: TLogLevel, | ||
gelatoApiKey: Type.String(), | ||
privateKey: Type.String(), | ||
environment: Type.Union([ | ||
Type.Literal('staging'), | ||
Type.Literal('production'), | ||
]), | ||
}); | ||
|
||
export type NovaConfig = Static<typeof NovaConfigSchema>; |
18 changes: 18 additions & 0 deletions
18
packages/agents/nova/src/core/resources/orderbook/dto/approve.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty, IsString, Length } from 'class-validator'; | ||
|
||
export enum Sort { | ||
ASCENDING = 'asc', | ||
DESCENDING = 'desc', | ||
} | ||
|
||
export class DefiApyQueryDto { | ||
@IsString() | ||
@IsNotEmpty() | ||
@Length(42, 42) | ||
@ApiProperty({ | ||
description: 'The asset address', | ||
example: '0x0617b72940f105811F251967EE4fdD5E38f159d5', | ||
}) | ||
assetAddress: string; | ||
} |
18 changes: 18 additions & 0 deletions
18
packages/agents/nova/src/core/resources/orderbook/dto/batchReceiveFunds.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty, IsString, Length } from 'class-validator'; | ||
|
||
export enum Sort { | ||
ASCENDING = 'asc', | ||
DESCENDING = 'desc', | ||
} | ||
|
||
export class DefiApyQueryDto { | ||
@IsString() | ||
@IsNotEmpty() | ||
@Length(42, 42) | ||
@ApiProperty({ | ||
description: 'The asset address', | ||
example: '0x0617b72940f105811F251967EE4fdD5E38f159d5', | ||
}) | ||
assetAddress: string; | ||
} |
Oops, something went wrong.