Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

fix oracle.bot.ts failing to publish due to lower than 0 price #295

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions src/module.playground/bot/oracle.bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const PriceDirectionFunctions: Record<PriceDirection, PriceDirectionFunction> =
},
[PriceDirection.RANDOM]: (price: BigNumber, priceChange: BigNumber) => {
const change = price.times(priceChange)
if (BigNumber.random().gt(0.5)) {
if (Math.random() > 0.5 || price.lt(1)) {
return price.plus(change)
} else {
return price.minus(change)
Expand Down Expand Up @@ -88,13 +88,13 @@ export class OracleBot {
},
{
token: 'CR50',
amount: new BigNumber(5000),
amount: new BigNumber(1000),
change: new BigNumber(0.33),
direction: PriceDirection.RANDOM
},
{
token: 'TR50',
amount: new BigNumber(5000),
amount: new BigNumber(1000),
change: new BigNumber(0.33),
direction: PriceDirection.RANDOM
},
Expand Down Expand Up @@ -156,7 +156,7 @@ export class OracleBot {
await this.client.oracle.setOracleData(oracleId, time, {
prices: this.feeds
.filter(value => {
return value.amount.gt(new BigNumber(0)) && value.amount.lt(new BigNumber(1_200_000_000))
return value.amount.gt(new BigNumber(0.00000001)) && value.amount.lt(new BigNumber(1_200_000_000))
})
.map(v => ({
tokenAmount: `${v.amount.toFixed(8)}@${v.token}`,
Expand Down