1- import { BigNumber } from 'ethers '
1+ import { Decimal } from 'decimal.js '
22
3- import { bn } from '../helpers/numbers'
3+ import { decimal } from '../helpers/numbers'
44import Logger from '../helpers/logger'
55
66import Asset from '../models/Asset'
@@ -25,7 +25,7 @@ class MigratedValueCalculator {
2525 const balances = await organization . balances ( )
2626 const values = await Promise . all ( balances . map ( balance => this . _calcOrganizationBalanceValue ( balance , createdAt ) ) )
2727
28- const valueUSD = values . reduce ( ( total , value ) => total . add ( value ) , bn ( 0 ) )
28+ const valueUSD = values . reduce ( ( total , value ) => total . add ( value ) , decimal ( 0 ) )
2929 const ant = await this . _getAntPrice ( createdAt )
3030 const valueANT = valueUSD . mul ( ant )
3131 const computedAt = new Date ( ) . getTime ( )
@@ -36,21 +36,21 @@ class MigratedValueCalculator {
3636 }
3737 }
3838
39- private async _calcOrganizationBalanceValue ( balance : OrganizationBalance , createdAt : string ) : Promise < BigNumber > {
39+ private async _calcOrganizationBalanceValue ( balance : OrganizationBalance , createdAt : string ) : Promise < Decimal > {
4040 const asset = await Asset . findById ( balance . assetId )
4141 const price = await this . _getAssetPrice ( asset ! . address , createdAt )
42- const value = bn ( balance . amount ) . mul ( price )
42+ const value = decimal ( balance . amount ) . mul ( price )
4343 await balance . $query ( ) . update ( { price : price . toString ( ) , value : value . toString ( ) } )
4444 return value
4545 }
4646
47- async _getAntPrice ( createdAt : string ) : Promise < BigNumber > {
47+ async _getAntPrice ( createdAt : string ) : Promise < Decimal > {
4848 return this . _getAssetPrice ( ANT_ADDRESS , createdAt )
4949 }
5050
51- async _getAssetPrice ( address : string , createdAt : string ) : Promise < BigNumber > {
51+ async _getAssetPrice ( address : string , createdAt : string ) : Promise < Decimal > {
5252 // TODO: fetch price from coin-gecko
53- return bn ( 0 )
53+ return decimal ( 0 )
5454 }
5555}
5656
0 commit comments