diff --git a/src/app-toolkit/app-toolkit.interface.ts b/src/app-toolkit/app-toolkit.interface.ts index 863894a6c..792547980 100644 --- a/src/app-toolkit/app-toolkit.interface.ts +++ b/src/app-toolkit/app-toolkit.interface.ts @@ -1,4 +1,6 @@ import { StaticJsonRpcProvider } from '@ethersproject/providers'; +import { BigNumber as BigNumberJS } from 'bignumber.js'; +import { ethers } from 'ethers'; import { IContractFactory } from '~contract/contracts'; import { EthersMulticall } from '~multicall'; @@ -13,10 +15,9 @@ import { AppToolkitHelperRegistry } from './app-toolkit.helpers'; export const APP_TOOLKIT = Symbol('APP_TOOLKIT'); export interface IAppToolkit { + // Network Related get globalContracts(): IContractFactory; - get helpers(): AppToolkitHelperRegistry; - getNetworkProvider(network: Network): StaticJsonRpcProvider; getMulticall(network: Network): EthersMulticall; @@ -36,4 +37,10 @@ export interface IAppToolkit { getAppContractPositions( ...appTokenDefinition: AppGroupsDefinition[] ): Promise[]>; + + // Global Helpers + + get helpers(): AppToolkitHelperRegistry; + + getBigNumber(source: BigNumberJS.Value | ethers.BigNumber): BigNumberJS; } diff --git a/src/app-toolkit/app-toolkit.service.ts b/src/app-toolkit/app-toolkit.service.ts index 2d327d2a7..6ad574702 100644 --- a/src/app-toolkit/app-toolkit.service.ts +++ b/src/app-toolkit/app-toolkit.service.ts @@ -1,4 +1,6 @@ import { forwardRef, Inject, Injectable } from '@nestjs/common'; +import { BigNumber as BigNumberJS } from 'bignumber.js'; +import { ethers } from 'ethers'; import { ContractFactory } from '~contract'; import { EthersMulticall, MULTICALL_ADDRESSES } from '~multicall'; @@ -24,14 +26,12 @@ export class AppToolkit implements IAppToolkit { this.contractFactory = new ContractFactory((network: Network) => this.networkProviderService.getProvider(network)); } + // Network Related + get globalContracts() { return this.contractFactory; } - get helpers() { - return this.helperRegistry; - } - getNetworkProvider(network: Network) { return this.networkProviderService.getProvider(network); } @@ -59,6 +59,7 @@ export class AppToolkit implements IAppToolkit { } // Positions + getAppTokenPositions(...appTokenDefinition: AppGroupsDefinition[]) { return this.positionService.getAppTokenPositions(...appTokenDefinition); } @@ -66,4 +67,15 @@ export class AppToolkit implements IAppToolkit { getAppContractPositions(...appTokenDefinition: AppGroupsDefinition[]) { return this.positionService.getAppContractPositions(...appTokenDefinition); } + + // Global Helpers + + get helpers() { + return this.helperRegistry; + } + + getBigNumber(source: BigNumberJS.Value | ethers.BigNumber): BigNumberJS { + if (source instanceof ethers.BigNumber) return new BigNumberJS(source.toString()); + return new BigNumberJS(source); + } } diff --git a/src/app-toolkit/helpers/balance/token-balance.helper.ts b/src/app-toolkit/helpers/balance/token-balance.helper.ts index bfa5c0fa0..91ac1daf8 100644 --- a/src/app-toolkit/helpers/balance/token-balance.helper.ts +++ b/src/app-toolkit/helpers/balance/token-balance.helper.ts @@ -1,5 +1,5 @@ import { Inject, Injectable } from '@nestjs/common'; -import BigNumber from 'bignumber.js'; +import BigNumberJS from 'bignumber.js'; import { isArray, pick } from 'lodash'; import { IAppToolkit, APP_TOOLKIT } from '~app-toolkit/app-toolkit.interface'; @@ -75,7 +75,7 @@ export const drillBalance = ( balanceUSD, tokens: tokens.map((underlyingToken, i) => { const pricePerShare = isArray(token.pricePerShare) ? token.pricePerShare[i] : token.pricePerShare; - const underlyingBalanceRawBN = new BigNumber(balanceRaw) + const underlyingBalanceRawBN = new BigNumberJS(balanceRaw) .div(10 ** token.decimals) .times(10 ** underlyingToken.decimals) .times(pricePerShare);