Skip to content

Commit

Permalink
Remove convertUnits utils fn
Browse files Browse the repository at this point in the history
  • Loading branch information
krebernisak authored and boxhock committed Jan 25, 2021
1 parent eb5def6 commit 73d22c5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
17 changes: 0 additions & 17 deletions bootstrap/src/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,3 @@ export function groupBy<K, V>(list: Array<V>, keyGetter: (input: V) => K): Map<K
*/
export const byName = (name?: string) => (a: AdapterImplementation): boolean =>
a.NAME.toUpperCase() === name?.toUpperCase()

/**
* Converts a given coin to different unit decimal places
*
* @param coin string of coin ticker name
* @param amount string of a number value
* @param unit optional string name of unit to convert to
*/
export const convertUnits = (coin: string, amount: string, unit?: string) => {
switch (coin.toLowerCase()) {
case 'btc':
// default satoshi
return new Decimal(amount).mul(10 ** 8).toString()
default:
return amount
}
}
5 changes: 3 additions & 2 deletions cryptoapis/src/endpoint/balance.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ethers } from 'ethers'
import { balance } from '@chainlink/ea-factories'
import { Requester } from '@chainlink/external-adapter'
import { Config } from '@chainlink/types'
import { isCoinType, isChainType, TESTNET_BLOCKCHAINS } from '.'
import { util } from '@chainlink/ea-bootstrap'

export const Name = 'balance'

Expand All @@ -18,7 +18,8 @@ const getBalance: balance.GetBalance = async (account, config) => {
}

const response = await Requester.request(options)
const balance = util.convertUnits(account.coin, response.data.payload.balance)
// Each BTC has 8 decimal places
const balance = ethers.utils.parseUnits(response.data.payload.balance, 8).toString()

return {
payload: response.data,
Expand Down
9 changes: 4 additions & 5 deletions dydx-stark/src/endpoint/starkex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const MAX_DECIMALS = 18
const ZERO_BN = BigNumber.from('0')
const TWO_BN = BigNumber.from('2')

const powOfTwo = (num: number) => TWO_BN.pow(BigNumber.from(num))
const powOfTwo = (num: number) => TWO_BN.pow(num)

const ERROR_MSG_PRICE_NEGATIVE = 'Price must be a positive number.'
const ERROR_MSG_PRICE_PRECISION_LOSS =
Expand Down Expand Up @@ -54,8 +54,7 @@ export const requireNormalizedPrice = (price: number | string): string => {
if (overSafeValue) logger.warn(msg)
}

const _powOfTen = (num: number) => new Decimal(10).pow(num)
return new Decimal(price).mul(_powOfTen(MAX_DECIMALS)).toFixed(0)
return new Decimal(price).mul(10 ** MAX_DECIMALS).toFixed(0)
}

/**
Expand All @@ -74,10 +73,10 @@ export const getPricePayload = async (
const keyPair = await getKeyPair(privateKey, starkMessage)

// 4. Hash the required parameters
const message = getPriceMessage(data)
const message = getPriceMessage(data).toHexString().substr(2)

// 5. Sign with your private stark key and the hash message to get r,s
const { r, s } = starkwareCrypto.sign(keyPair, message.toHexString().substr(2))
const { r, s } = starkwareCrypto.sign(keyPair, message)

// 6. Generate the public key (pub_key) with your private key
const starkPublicKey = starkwareCrypto.getStarkPublicKey(keyPair)
Expand Down
5 changes: 3 additions & 2 deletions sochain/src/endpoint/balance.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ethers } from 'ethers'
import { balance } from '@chainlink/ea-factories'
import { Requester } from '@chainlink/external-adapter'
import { Account, Config } from '@chainlink/types'
import { isCoinType, isChainType } from '.'
import { util } from '@chainlink/ea-bootstrap'

export const Name = 'balance'

Expand All @@ -19,7 +19,8 @@ const getBalance: balance.GetBalance = async (account, config) => {
}

const response = await Requester.request(options)
const balance = util.convertUnits(account.coin, response.data.data.confirmed_balance)
// Each BTC has 8 decimal places
const balance = ethers.utils.parseUnits(response.data.data.confirmed_balance, 8).toString()

return {
payload: response.data,
Expand Down

0 comments on commit 73d22c5

Please sign in to comment.