@aurigami/sdk 1.5.0-dummy → 1.5.0-dummy-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MoneyMarket.d.ts +2 -2
- package/dist/Papermill.d.ts +2 -1
- package/dist/SDK.d.ts +1 -1
- package/dist/airdrop-lottery.d.ts +4 -4
- package/dist/constants.d.ts +1 -0
- package/dist/helpers.d.ts +3 -3
- package/dist/priceFetcher.d.ts +4 -4
- package/dist/sdk.cjs.development.js +94 -63
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +95 -64
- package/dist/sdk.esm.js.map +1 -1
- package/dist/tokenAmount.d.ts +1 -1
- package/dist/transfer-event-query.d.ts +4 -4
- package/package.json +6 -12
- package/src/BlockchainEntity.ts +6 -2
- package/src/MoneyMarket.ts +317 -105
- package/src/Papermill.ts +120 -38
- package/src/SDK.ts +242 -96
- package/src/airdrop-lottery.ts +293 -248
- package/src/aurora-api-helpers.ts +11 -6
- package/src/constants.ts +60 -59
- package/src/decimals.ts +1 -1
- package/src/dummy.ts +17 -23
- package/src/helpers.ts +42 -26
- package/src/index.ts +1 -1
- package/src/priceFetcher.ts +240 -154
- package/src/token.ts +14 -14
- package/src/tokenAmount.ts +21 -21
- package/src/transfer-event-query.ts +64 -54
- package/src/types.ts +12 -12
- package/dist/hardhat.config.d.ts +0 -6
- package/dist/test/constants.d.ts +0 -6
- package/dist/test-hardhat/helper.d.ts +0 -6
package/src/priceFetcher.ts
CHANGED
|
@@ -1,212 +1,298 @@
|
|
|
1
|
-
import BigNumber from
|
|
2
|
-
import { Contract, providers, BigNumber as BN, ethers } from
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import { Contract, providers, BigNumber as BN, ethers } from 'ethers';
|
|
3
|
+
import {
|
|
4
|
+
DECIMAL_PRECISION,
|
|
5
|
+
networkAddresses,
|
|
6
|
+
PRICE_WHITELISTED,
|
|
7
|
+
} from './constants';
|
|
8
|
+
import OracleABI from './abis/Oracle.json';
|
|
9
|
+
import { isSameAddress, decimalFactor, getDecimal } from './helpers';
|
|
10
|
+
import { IUniswapV2Pair, PriceOracle } from '@aurigami/contracts/typechain';
|
|
11
|
+
import { TokenAmount } from './tokenAmount';
|
|
12
|
+
import { Address, TokenValuation } from './types';
|
|
9
13
|
import IUniswapV2PairABI from './abis/IUniswapV2Pair.json';
|
|
10
14
|
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
11
15
|
import axios from 'axios';
|
|
12
16
|
import assert from 'assert';
|
|
13
17
|
|
|
14
18
|
const hardcodePLYPrice = true;
|
|
15
|
-
export async function fetchPriceFromCoingeckoAPI(
|
|
16
|
-
|
|
19
|
+
export async function fetchPriceFromCoingeckoAPI(
|
|
20
|
+
id: string
|
|
21
|
+
): Promise<BigNumber> {
|
|
22
|
+
const price = await axios
|
|
23
|
+
.get(
|
|
17
24
|
`https://api.coingecko.com/api/v3/simple/price?ids=${id}&vs_currencies=usd`
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
)
|
|
26
|
+
.then((res: any) => {
|
|
27
|
+
return res.data;
|
|
28
|
+
});
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
return new BigNumber(price[id].usd);
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
export async function fetchPriceFromCoingecko(id: Address): Promise<BigNumber> {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
switch (id.toLowerCase()) {
|
|
35
|
+
case networkAddresses.tokens.AURORA:
|
|
36
|
+
return fetchPriceFromCoingeckoAPI('aurora-near');
|
|
29
37
|
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
case networkAddresses.tokens.TRI:
|
|
39
|
+
return fetchPriceFromCoingeckoAPI('trisolaris');
|
|
32
40
|
|
|
33
|
-
|
|
34
|
-
|
|
41
|
+
case networkAddresses.tokens.META:
|
|
42
|
+
return fetchPriceFromCoingeckoAPI('meta-pool');
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
default:
|
|
45
|
+
throw Error(`Unknown token ${id} in fetchPriceFromCoingecko`);
|
|
46
|
+
}
|
|
39
47
|
}
|
|
40
48
|
|
|
41
|
-
export async function fetchLPPositions(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
export async function fetchLPPositions(
|
|
50
|
+
LPAddress: Address,
|
|
51
|
+
provider: providers.Provider
|
|
52
|
+
): Promise<{
|
|
53
|
+
token0: Address;
|
|
54
|
+
token1: Address;
|
|
55
|
+
reserve0: BN;
|
|
56
|
+
reserve1: BN;
|
|
57
|
+
totalSupply: BN;
|
|
47
58
|
}> {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
const LPContract = new Contract(
|
|
60
|
+
LPAddress,
|
|
61
|
+
IUniswapV2PairABI.abi,
|
|
62
|
+
provider
|
|
63
|
+
) as IUniswapV2Pair;
|
|
64
|
+
var promises: any[] = [];
|
|
65
|
+
promises.push(LPContract.token0());
|
|
66
|
+
promises.push(LPContract.token1());
|
|
67
|
+
promises.push(LPContract.getReserves());
|
|
68
|
+
promises.push(LPContract.totalSupply());
|
|
69
|
+
const values: any[] = await Promise.all(promises);
|
|
55
70
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
return {
|
|
72
|
+
token0: values[0] as string,
|
|
73
|
+
token1: values[1] as string,
|
|
74
|
+
reserve0: (values[2] as { reserve0: BN; reserve1: BN }).reserve0,
|
|
75
|
+
reserve1: (values[2] as { reserve0: BN; reserve1: BN }).reserve1,
|
|
76
|
+
totalSupply: values[3] as BN,
|
|
77
|
+
};
|
|
63
78
|
}
|
|
64
79
|
|
|
65
|
-
export async function fetchLPPrice(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// Should NOT call `fetchPrice`, it will cause an infinite loop
|
|
73
|
-
// because the token can be PLY. To calculate PLY price, we need to
|
|
74
|
-
// call `fetchPrice` again...
|
|
75
|
-
const tokenPrice: BigNumber = await _fetchPrice(tokenReverse.address, provider);
|
|
76
|
-
const tokenDecimal = getDecimal(tokenReverse.address);
|
|
77
|
-
|
|
78
|
-
// reserveUSD will be divided by 10^tokenDecimal later for more precision
|
|
79
|
-
const reserveUSD: BigNumber = tokenPrice.multipliedBy(tokenReverse.reserve.toString()).multipliedBy(2);
|
|
80
|
-
return reserveUSD
|
|
81
|
-
.multipliedBy(decimalFactor(LPDecimal))
|
|
82
|
-
.dividedBy(new BigNumber(LPInfo.totalSupply.toString()))
|
|
83
|
-
.dividedBy(decimalFactor(tokenDecimal));
|
|
84
|
-
}
|
|
80
|
+
export async function fetchLPPrice(
|
|
81
|
+
address: Address,
|
|
82
|
+
provider: providers.Provider
|
|
83
|
+
): Promise<BigNumber> {
|
|
84
|
+
var LPInfo = await fetchLPPositions(address, provider);
|
|
85
|
+
const LPDecimal = getDecimal(address);
|
|
85
86
|
|
|
87
|
+
async function fetchLPPriceBy(tokenReverse: {
|
|
88
|
+
address: string;
|
|
89
|
+
reserve: BN;
|
|
90
|
+
}): Promise<BigNumber> {
|
|
91
|
+
if (tokenReverse.reserve.isZero()) return new BigNumber(0);
|
|
92
|
+
|
|
93
|
+
// Should NOT call `fetchPrice`, it will cause an infinite loop
|
|
94
|
+
// because the token can be PLY. To calculate PLY price, we need to
|
|
95
|
+
// call `fetchPrice` again...
|
|
96
|
+
const tokenPrice: BigNumber = await _fetchPrice(
|
|
97
|
+
tokenReverse.address,
|
|
98
|
+
provider
|
|
99
|
+
);
|
|
100
|
+
const tokenDecimal = getDecimal(tokenReverse.address);
|
|
101
|
+
|
|
102
|
+
// reserveUSD will be divided by 10^tokenDecimal later for more precision
|
|
103
|
+
const reserveUSD: BigNumber = tokenPrice
|
|
104
|
+
.multipliedBy(tokenReverse.reserve.toString())
|
|
105
|
+
.multipliedBy(2);
|
|
106
|
+
return reserveUSD
|
|
107
|
+
.multipliedBy(decimalFactor(LPDecimal))
|
|
108
|
+
.dividedBy(new BigNumber(LPInfo.totalSupply.toString()))
|
|
109
|
+
.dividedBy(decimalFactor(tokenDecimal));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
// MUST await here
|
|
114
|
+
return await fetchLPPriceBy({
|
|
115
|
+
address: LPInfo.token0,
|
|
116
|
+
reserve: LPInfo.reserve0,
|
|
117
|
+
});
|
|
118
|
+
} catch {
|
|
86
119
|
try {
|
|
87
|
-
|
|
88
|
-
|
|
120
|
+
// MUST await here
|
|
121
|
+
return await fetchLPPriceBy({
|
|
122
|
+
address: LPInfo.token1,
|
|
123
|
+
reserve: LPInfo.reserve1,
|
|
124
|
+
});
|
|
89
125
|
} catch {
|
|
90
|
-
|
|
91
|
-
// MUST await here
|
|
92
|
-
return await fetchLPPriceBy({address: LPInfo.token1, reserve: LPInfo.reserve1});
|
|
93
|
-
} catch {
|
|
94
|
-
throw Error(`Unable to fetch price for both tokens of LP ${address}`);
|
|
95
|
-
}
|
|
126
|
+
throw Error(`Unable to fetch price for both tokens of LP ${address}`);
|
|
96
127
|
}
|
|
128
|
+
}
|
|
97
129
|
}
|
|
98
130
|
|
|
99
131
|
function processPriceFromOracle(rawPrice: BN, underlyingDecimal: number) {
|
|
100
|
-
|
|
132
|
+
return new BigNumber(rawPrice.toString()).div(
|
|
133
|
+
decimalFactor(36 - underlyingDecimal)
|
|
134
|
+
);
|
|
101
135
|
}
|
|
102
|
-
export async function fetchPriceFromOracle(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
136
|
+
export async function fetchPriceFromOracle(
|
|
137
|
+
auTokenAddress: Address,
|
|
138
|
+
underlyingDecimal: number,
|
|
139
|
+
provider: providers.Provider
|
|
140
|
+
): Promise<BigNumber> {
|
|
141
|
+
const oracleContract: PriceOracle = new Contract(
|
|
142
|
+
networkAddresses.misc.oracle,
|
|
143
|
+
OracleABI.abi,
|
|
144
|
+
provider
|
|
145
|
+
) as PriceOracle;
|
|
146
|
+
const rawPrice = await oracleContract.getUnderlyingPrice(auTokenAddress);
|
|
147
|
+
return processPriceFromOracle(rawPrice, underlyingDecimal);
|
|
106
148
|
}
|
|
107
149
|
|
|
108
|
-
export async function fetchUnderlyingTokensPrices(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
150
|
+
export async function fetchUnderlyingTokensPrices(
|
|
151
|
+
provider: providers.Provider
|
|
152
|
+
): Promise<
|
|
153
|
+
{
|
|
154
|
+
auToken: string;
|
|
155
|
+
underlyingPrice: BigNumber;
|
|
156
|
+
}[]
|
|
157
|
+
> {
|
|
158
|
+
const auriLens: Contract = new Contract(
|
|
159
|
+
networkAddresses.misc.AURILENS,
|
|
160
|
+
AuriLensABI.abi,
|
|
161
|
+
provider
|
|
162
|
+
);
|
|
163
|
+
const auTokenAddresses = networkAddresses.auTokens.map(
|
|
164
|
+
(auToken) => auToken.address
|
|
165
|
+
);
|
|
166
|
+
const underlyingDecimals = networkAddresses.auTokens.map((auToken) =>
|
|
167
|
+
getDecimal(auToken.underlying)
|
|
168
|
+
);
|
|
169
|
+
const rawPrices = await auriLens.auTokenUnderlyingPriceAll(auTokenAddresses);
|
|
170
|
+
return rawPrices.map((res: any, ind: number) => {
|
|
171
|
+
return {
|
|
172
|
+
auToken: res.auToken,
|
|
173
|
+
underlyingPrice: processPriceFromOracle(
|
|
174
|
+
res.underlyingPrice,
|
|
175
|
+
underlyingDecimals[ind]
|
|
176
|
+
),
|
|
177
|
+
};
|
|
178
|
+
});
|
|
122
179
|
}
|
|
123
180
|
|
|
124
181
|
export async function fetchStNEARPrice(): Promise<BigNumber> {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
182
|
+
const ratioPromise = axios
|
|
183
|
+
.get('https://validators.narwallets.com/metrics_json')
|
|
184
|
+
.then((res) => res.data);
|
|
185
|
+
const nearPricePromise = fetchPriceFromCoingeckoAPI('near');
|
|
186
|
+
const [ratioRes, nearPrice]: [any, BigNumber] = await Promise.all([
|
|
187
|
+
ratioPromise,
|
|
188
|
+
nearPricePromise,
|
|
189
|
+
]);
|
|
190
|
+
const ratio = new BigNumber(ratioRes.st_near_price);
|
|
191
|
+
return ratio.multipliedBy(nearPrice);
|
|
130
192
|
}
|
|
131
193
|
|
|
132
194
|
function shouldFetchFromCoingecko(address: string) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
195
|
+
address = address.toLowerCase();
|
|
196
|
+
return (
|
|
197
|
+
address == networkAddresses.tokens.AURORA ||
|
|
198
|
+
address == networkAddresses.tokens.TRI ||
|
|
199
|
+
address == networkAddresses.tokens.META
|
|
200
|
+
);
|
|
137
201
|
}
|
|
138
202
|
|
|
139
203
|
/**
|
|
140
204
|
* Fetch price from Oracle or Coingecko
|
|
141
205
|
*/
|
|
142
|
-
async function _fetchPrice(
|
|
143
|
-
|
|
206
|
+
async function _fetchPrice(
|
|
207
|
+
address: Address,
|
|
208
|
+
provider: providers.Provider
|
|
209
|
+
): Promise<BigNumber> {
|
|
210
|
+
assert(PRICE_WHITELISTED.has(address.toLocaleLowerCase()));
|
|
144
211
|
|
|
145
|
-
|
|
146
|
-
|
|
212
|
+
if (isSameAddress(address, networkAddresses.tokens.stNEAR))
|
|
213
|
+
return fetchStNEARPrice();
|
|
214
|
+
if (shouldFetchFromCoingecko(address))
|
|
215
|
+
return fetchPriceFromCoingecko(address);
|
|
147
216
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
217
|
+
const matchingAuToken = networkAddresses.auTokens.find((auToken) => {
|
|
218
|
+
return isSameAddress(auToken.underlying, address);
|
|
219
|
+
});
|
|
151
220
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
221
|
+
if (matchingAuToken !== undefined) {
|
|
222
|
+
return fetchPriceFromOracle(
|
|
223
|
+
matchingAuToken.address,
|
|
224
|
+
getDecimal(address),
|
|
225
|
+
provider
|
|
226
|
+
);
|
|
227
|
+
} else {
|
|
228
|
+
throw Error(`Unable to fetch price for ${address}`);
|
|
229
|
+
}
|
|
157
230
|
}
|
|
158
231
|
|
|
159
|
-
export async function fetchPrice(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return
|
|
232
|
+
export async function fetchPrice(
|
|
233
|
+
address: Address,
|
|
234
|
+
provider: providers.Provider
|
|
235
|
+
): Promise<BigNumber> {
|
|
236
|
+
if (isSameAddress(address, networkAddresses.tokens.PLYUSDC)) {
|
|
237
|
+
return fetchLPPrice(address, provider);
|
|
238
|
+
} else if (isSameAddress(address, networkAddresses.tokens.PLY)) {
|
|
239
|
+
return fetchPLYPrice(provider);
|
|
240
|
+
}
|
|
241
|
+
return _fetchPrice(address, provider);
|
|
167
242
|
}
|
|
168
243
|
|
|
169
|
-
export async function fetchPLYPrice(
|
|
170
|
-
|
|
244
|
+
export async function fetchPLYPrice(
|
|
245
|
+
provider: providers.Provider
|
|
246
|
+
): Promise<BigNumber> {
|
|
247
|
+
const LPInfo = await fetchLPPositions(
|
|
248
|
+
networkAddresses.tokens.PLYUSDC,
|
|
249
|
+
provider
|
|
250
|
+
);
|
|
171
251
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
252
|
+
if (LPInfo.reserve1.isZero()) {
|
|
253
|
+
return new BigNumber(0);
|
|
254
|
+
}
|
|
175
255
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
256
|
+
const plyAddress = LPInfo.token0;
|
|
257
|
+
assert(isSameAddress(plyAddress, networkAddresses.tokens.PLY));
|
|
258
|
+
const plyDecimal = getDecimal(plyAddress);
|
|
259
|
+
|
|
260
|
+
const usdcAddress = LPInfo.token1;
|
|
261
|
+
assert(isSameAddress(usdcAddress, networkAddresses.tokens.USDC));
|
|
262
|
+
const usdcDecimal = getDecimal(usdcAddress);
|
|
263
|
+
|
|
264
|
+
// (token0Price * reserve0) / 10^decimal0 = (token1Price * reserve1) / 10^decimal1
|
|
265
|
+
// token0Price = (token1Price * reserve1) * 10^decimal0 / 10^decimal1 / reserve0
|
|
266
|
+
return (await fetchPrice(usdcAddress, provider))
|
|
267
|
+
.multipliedBy(LPInfo.reserve1.toString())
|
|
268
|
+
.multipliedBy(decimalFactor(plyDecimal))
|
|
269
|
+
.dividedBy(decimalFactor(usdcDecimal))
|
|
270
|
+
.dividedBy(LPInfo.reserve0.toString());
|
|
191
271
|
}
|
|
192
272
|
|
|
193
|
-
export async function fetchValuation(
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
273
|
+
export async function fetchValuation(
|
|
274
|
+
tokenAmount: TokenAmount,
|
|
275
|
+
provider: providers.Provider
|
|
276
|
+
): Promise<BigNumber> {
|
|
277
|
+
if (tokenAmount.rawAmount() == '0') return new BigNumber(0);
|
|
278
|
+
var price = await fetchPrice(tokenAmount.token.address, provider);
|
|
279
|
+
return calcValuation(tokenAmount, price);
|
|
197
280
|
}
|
|
198
281
|
|
|
199
282
|
export function calcValuation(tokenAmount: TokenAmount, price: BigNumber) {
|
|
200
|
-
|
|
283
|
+
return new BigNumber(tokenAmount.formattedAmount()).multipliedBy(price);
|
|
201
284
|
}
|
|
202
285
|
|
|
203
|
-
export async function valuateToken(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
286
|
+
export async function valuateToken(
|
|
287
|
+
tokenAmount: TokenAmount,
|
|
288
|
+
provider: providers.Provider
|
|
289
|
+
): Promise<TokenValuation> {
|
|
290
|
+
let tokenValuation = await fetchValuation(tokenAmount, provider);
|
|
291
|
+
return {
|
|
292
|
+
tokenAmount: tokenAmount,
|
|
293
|
+
currencyAmount: {
|
|
294
|
+
currency: 'USD',
|
|
295
|
+
amount: tokenValuation.toFixed(DECIMAL_PRECISION),
|
|
296
|
+
},
|
|
297
|
+
};
|
|
212
298
|
}
|
package/src/token.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { getDecimal } from
|
|
2
|
-
import { networkAddresses } from
|
|
1
|
+
import { getDecimal } from './helpers';
|
|
2
|
+
import { networkAddresses } from './constants';
|
|
3
3
|
|
|
4
4
|
export class Token {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
public readonly address: string;
|
|
6
|
+
public readonly decimals: number;
|
|
7
|
+
public constructor(address: string, decimals: number) {
|
|
8
|
+
this.address = address.toLowerCase();
|
|
9
|
+
this.decimals = decimals;
|
|
10
|
+
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export const PLYToken = new Token(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
14
|
+
networkAddresses.tokens.PLY,
|
|
15
|
+
getDecimal(networkAddresses.tokens.PLY)
|
|
16
|
+
);
|
|
17
17
|
|
|
18
18
|
export const PLYUSDCToken = new Token(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
19
|
+
networkAddresses.tokens.PLYUSDC,
|
|
20
|
+
getDecimal(networkAddresses.tokens.PLYUSDC)
|
|
21
|
+
);
|
package/src/tokenAmount.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { Token } from
|
|
1
|
+
import { Token } from './token';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { decimalFactor } from
|
|
3
|
+
import { decimalFactor } from './helpers';
|
|
4
4
|
|
|
5
5
|
export class TokenAmount {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
public readonly token: Token;
|
|
7
|
+
private rawAmnt: string;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
this.token = token;
|
|
9
|
+
public constructor(token: Token, amount: string, isRaw: boolean = true) {
|
|
10
|
+
if (isRaw) {
|
|
11
|
+
this.rawAmnt = amount;
|
|
12
|
+
} else {
|
|
13
|
+
this.rawAmnt = new BigNumber(amount)
|
|
14
|
+
.times(decimalFactor(token.decimals))
|
|
15
|
+
.toFixed(0);
|
|
18
16
|
}
|
|
17
|
+
this.token = token;
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
public formattedAmount(): string {
|
|
21
|
+
return new BigNumber(this.rawAmnt)
|
|
22
|
+
.div(decimalFactor(this.token.decimals))
|
|
23
|
+
.toString();
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
public rawAmount(): string {
|
|
27
|
+
return this.rawAmnt;
|
|
28
|
+
}
|
|
29
29
|
}
|