-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat]: Implement pricing controller (#42)
* feat: Implement a pricing controller to query arbitrary token prices * fix: Make use of 'tokenId' * fix: Wait for the pricing service to be ready
- Loading branch information
1 parent
8b69899
commit ca5b1c5
Showing
9 changed files
with
152 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Controller, Get, OnModuleInit, Query } from "@nestjs/common"; | ||
import { PricingService } from './pricing.service'; | ||
import { PricingInterface } from './pricing.interface'; | ||
import { GetPriceQuery, GetPriceQueryResponse } from './pricing.types'; | ||
|
||
|
||
@Controller() | ||
export class PricingController implements OnModuleInit { | ||
private pricing!: PricingInterface; | ||
|
||
constructor( | ||
private readonly pricingService: PricingService, | ||
) {} | ||
|
||
async onModuleInit() { | ||
await this.initializePricingInterface(); | ||
} | ||
|
||
private async initializePricingInterface(): Promise<void> { | ||
const port = await this.pricingService.attachToPricing(); | ||
this.pricing = new PricingInterface(port); | ||
} | ||
|
||
@Get('getPrice') | ||
async getPrice(@Query() query: GetPriceQuery): Promise<any> { | ||
//TODO schema validate request | ||
|
||
if (query.chainId == undefined || query.amount == undefined) { | ||
return undefined; //TODO return error | ||
} | ||
|
||
const amount = BigInt(query.amount); | ||
const price = await this.pricing.getPrice( | ||
query.chainId, | ||
amount, | ||
query.tokenId, | ||
); | ||
|
||
const response: GetPriceQueryResponse = { | ||
chainId: query.chainId, | ||
tokenId: query.tokenId, | ||
amount: amount.toString(), | ||
price: price != null ? price : null, | ||
}; | ||
|
||
return response; | ||
} | ||
} |
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
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
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