Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 9d0acc5

Browse files
committed
compute total migrated value in USD
1 parent ff87c98 commit 9d0acc5

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed
Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
11
import { Request, Response } from 'express'
22

3-
import HttpError from '../lib/HttpError'
3+
import { decimal } from '../helpers/numbers'
4+
5+
import Asset from '../models/Asset'
6+
import HttpError from '../models/HttpError'
47
import Organization from '../models/Organization'
8+
import OrganizationBalance from '../models/OrganizationBalance'
9+
10+
const TARGET = decimal(100e6) // 100M USD
11+
const REWARD = decimal(100e3) // 100k ANT
12+
const OPTIONS = decimal(1e6) // 1M
13+
const CAP_PRICE = decimal(0.1) // 0.1 ANT
514

615
export default {
716
async all(request: Request, response: Response) {
8-
const total = await Organization.count()
9-
const value = await Organization.totalAntValue()
10-
response.status(200).send({ total, value })
17+
const count = await Organization.count()
18+
const last = (await Organization.last())?.createdAt || 0
19+
const total = await Organization.totalValue()
20+
const optionPrice = decimal(total).div(TARGET).mul(REWARD.div(OPTIONS))
21+
const option = optionPrice > CAP_PRICE ? CAP_PRICE : optionPrice
22+
response.status(200).send({ count, last, total, option })
1123
},
1224

1325
async show(request: Request, response: Response) {
1426
const organization = await Organization.findByAddress(request.params.address)
1527
if (!organization) throw HttpError.NOT_FOUND('Organization not found')
16-
const { createdAt, address, executor, valueUSD, valueANT, ant } = organization
17-
response.status(200).send({ createdAt, address, executor, valueUSD, valueANT, ant })
28+
29+
const orgBalances = await OrganizationBalance.findByOrganization(organization)
30+
const balances = Promise.all(orgBalances.map(async ({ assetId, price, amount, value }) => {
31+
const asset = await Asset.findById(assetId)
32+
return { asset: { address: asset?.address, symbol: asset?.symbol, decimals: asset?.decimals }, price, amount, value }
33+
}));
34+
35+
const { createdAt, address, executor, value, syncedAt } = organization
36+
response.status(200).send({ createdAt, address, executor, value, syncedAt, balances })
1837
}
1938
}

src/middlewares/error-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import HttpError from '../lib/HttpError'
1+
import HttpError from '../models/HttpError'
22
import { Request, Response, NextFunction } from 'express'
33

44
export default (err: Error, req: Request, res: Response, next: NextFunction) => {

0 commit comments

Comments
 (0)