6
6
formatCurrency ,
7
7
formatAddress ,
8
8
ReachToken ,
9
- peraTokenMetadata
9
+ peraTokenMetadata ,
10
+ ReachStdLib
10
11
} from "../reach-helpers" ;
11
12
import {
12
13
FetchPoolData ,
@@ -34,6 +35,22 @@ export type FetchPoolOpts = PoolFetchOpts & {
34
35
/** ALIAS | Fetch data about a pool */
35
36
export const fetchPool = fetchLiquidityPool ;
36
37
38
+ /**
39
+ * Get minted liquidity tokens (unsafe)
40
+ * @param stdlib Reach stdlib
41
+ * @param lptBals Liquidity token balances
42
+ * @returns Minted liquidity tokens
43
+ */
44
+ export const unsafeMintedLiquidityTokens = ( stdlib : ReachStdLib ) => ( lptBals : { A : any ; B : any } ) => stdlib . bigNumberToNumber ( lptBals . B )
45
+
46
+ /**
47
+ * Get minted liquidity tokens
48
+ * @param stdlib Reach stdlib
49
+ * @param lptBals Liquidity token balances
50
+ * @returns Minted liquidity tokens
51
+ */
52
+ export const safeMintedLiquidityTokens = ( stdlib : ReachStdLib ) => ( lptBals : { A : any ; B : any } ) => stdlib . bigNumberToBigInt ( lptBals . B ) . toString ( )
53
+
37
54
/**
38
55
* Fetch data about a pool
39
56
* @param acc Reach Account instance
@@ -46,7 +63,8 @@ export async function fetchLiquidityPool(
46
63
opts : FetchPoolOpts
47
64
) : Promise < TransactionResult < FetchPoolData > > {
48
65
const reach = createReachAPI ( ) ;
49
- const big = reach . bigNumberify ;
66
+ const bn = reach . bigNumberify ;
67
+ const getMintedLiquidityTokens = safeMintedLiquidityTokens ( reach ) ;
50
68
const {
51
69
poolAddress = "" ,
52
70
n2nn = false ,
@@ -105,15 +123,15 @@ export async function fetchLiquidityPool(
105
123
onProgress ( `Calculating fees ...` ) ;
106
124
const FEE_INFO = getFeeInfo ( ) ;
107
125
const totalFees = ( protocolBal : number ) =>
108
- big ( FEE_INFO . totFee ) . div ( big ( FEE_INFO . protoFee ) ) . mul ( protocolBal ) ;
126
+ bn ( FEE_INFO . totFee ) . div ( bn ( FEE_INFO . protoFee ) ) . mul ( protocolBal ) ;
109
127
110
128
// subtract fees from token balances
111
129
const { A : aBal , B : bBal } = poolBals ;
112
130
const { A : pABal , B : pBBal } = protoBals ;
113
131
const pool : PoolDetails = {
114
132
poolAddress : ctcInfo ,
115
133
poolTokenId : parseAddress ( liquidityToken ) ,
116
- mintedLiquidityTokens : reach . bigNumberToNumber ( lptBals . B ) ,
134
+ mintedLiquidityTokens : getMintedLiquidityTokens ( lptBals ) ,
117
135
n2nn,
118
136
tokenABalance : formatCurrency ( aBal , tokA ?. decimals ) ,
119
137
tokenAFees : formatCurrency ( totalFees ( pABal ) , tokA ?. decimals ) ,
0 commit comments