impermax-sdk 1.0.1 → 1.0.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/lib/esm/abis/ImpermaxABI.d.ts +2 -0
- package/lib/esm/abis/ImpermaxABI.js +3 -0
- package/lib/esm/abis/contracts/ClaimAggregator.json +2015 -0
- package/lib/esm/abis/contracts/IBorrowable.json +13207 -0
- package/lib/esm/abis/contracts/IClaimable.json +406 -0
- package/lib/esm/abis/contracts/ICollateral.json +8952 -0
- package/lib/esm/abis/contracts/IERC20.json +2376 -0
- package/lib/esm/abis/contracts/IFactory.json +3660 -0
- package/lib/esm/abis/contracts/IFarmingPool.json +3584 -0
- package/lib/esm/abis/contracts/IMerkleDistributor.json +1134 -0
- package/lib/esm/abis/contracts/IRouter02.json +7283 -0
- package/lib/esm/abis/contracts/ISimpleUniswapOracle.json +1469 -0
- package/lib/esm/abis/contracts/IStakedLPToken.json +7309 -0
- package/lib/esm/abis/contracts/IStakingRewards.json +1036 -0
- package/lib/esm/abis/contracts/IUniswapV2Factory.json +1690 -0
- package/lib/esm/abis/contracts/IUniswapV2Pair.json +6761 -0
- package/lib/esm/abis/contracts/ImpermaxChef.json +20945 -0
- package/lib/esm/config/amms.d.ts +25 -0
- package/lib/esm/config/amms.js +196 -0
- package/lib/esm/config/contracts/claim-aggregators.d.ts +2 -0
- package/lib/esm/config/contracts/claim-aggregators.js +18 -0
- package/lib/esm/config/contracts/impermax-chef.d.ts +2 -0
- package/lib/esm/config/contracts/impermax-chef.js +18 -0
- package/lib/esm/config/contracts/imxes.d.ts +2 -0
- package/lib/esm/config/contracts/imxes.js +18 -0
- package/lib/esm/config/contracts/merkle-distributors.d.ts +4 -0
- package/lib/esm/config/contracts/merkle-distributors.js +13 -0
- package/lib/esm/config/contracts/routers.d.ts +2 -0
- package/lib/esm/config/contracts/routers.js +38 -0
- package/lib/esm/config/contracts/simple-uniswap-oracles.d.ts +2 -0
- package/lib/esm/config/contracts/simple-uniswap-oracles.js +35 -0
- package/lib/esm/config/contracts/weths.d.ts +2 -0
- package/lib/esm/config/contracts/weths.js +19 -0
- package/lib/esm/config/debank-ids.d.ts +2 -0
- package/lib/esm/config/debank-ids.js +17 -0
- package/lib/esm/config/endpoints/merkle-distributors.d.ts +4 -0
- package/lib/esm/config/endpoints/merkle-distributors.js +13 -0
- package/lib/esm/config/eth.d.ts +3 -0
- package/lib/esm/config/eth.js +32 -0
- package/lib/esm/config/factories.d.ts +6 -0
- package/lib/esm/config/factories.js +24 -0
- package/lib/esm/config/farms.d.ts +59 -0
- package/lib/esm/config/farms.js +114 -0
- package/lib/esm/config/general.d.ts +3 -0
- package/lib/esm/config/general.js +8 -0
- package/lib/esm/config/subgraphs.d.ts +5 -0
- package/lib/esm/config/subgraphs.js +68 -0
- package/lib/esm/config/types.d.ts +67 -0
- package/lib/esm/config/types.js +54 -0
- package/lib/esm/impermax-router/Account.d.ts +31 -0
- package/lib/esm/impermax-router/Account.js +154 -0
- package/lib/esm/impermax-router/AccountBorrowable.d.ts +22 -0
- package/lib/esm/impermax-router/AccountBorrowable.js +141 -0
- package/lib/esm/impermax-router/AccountCollateral.d.ts +11 -0
- package/lib/esm/impermax-router/AccountCollateral.js +63 -0
- package/lib/esm/impermax-router/AccountLendingPool.d.ts +57 -0
- package/lib/esm/impermax-router/AccountLendingPool.js +266 -0
- package/lib/esm/impermax-router/AccountPoolToken.d.ts +29 -0
- package/lib/esm/impermax-router/AccountPoolToken.js +89 -0
- package/lib/esm/impermax-router/Borrowable.d.ts +27 -0
- package/lib/esm/impermax-router/Borrowable.js +128 -0
- package/lib/esm/impermax-router/Collateral.d.ts +9 -0
- package/lib/esm/impermax-router/Collateral.js +45 -0
- package/lib/esm/impermax-router/ContractsHelper.d.ts +28 -0
- package/lib/esm/impermax-router/ContractsHelper.js +50 -0
- package/lib/esm/impermax-router/ImpermaxFactory.d.ts +15 -0
- package/lib/esm/impermax-router/ImpermaxFactory.js +42 -0
- package/lib/esm/impermax-router/Interactions.d.ts +16 -0
- package/lib/esm/impermax-router/Interactions.js +105 -0
- package/lib/esm/impermax-router/InteractionsLendingPool.d.ts +43 -0
- package/lib/esm/impermax-router/InteractionsLendingPool.js +124 -0
- package/lib/esm/impermax-router/InteractionsPoolToken.d.ts +23 -0
- package/lib/esm/impermax-router/InteractionsPoolToken.js +194 -0
- package/lib/esm/impermax-router/LendingPool.d.ts +69 -0
- package/lib/esm/impermax-router/LendingPool.js +291 -0
- package/lib/esm/impermax-router/PoolToken.d.ts +36 -0
- package/lib/esm/impermax-router/PoolToken.js +140 -0
- package/lib/esm/impermax-router/index.d.ts +20 -0
- package/lib/esm/impermax-router/index.js +34 -0
- package/lib/esm/impermax-router/interfaces.d.ts +218 -0
- package/lib/esm/impermax-router/interfaces.js +15 -0
- package/{index.ts → lib/esm/index.d.ts} +1 -3
- package/lib/esm/index.js +10 -0
- package/lib/esm/subgraph/Account.d.ts +18 -0
- package/lib/esm/subgraph/Account.js +111 -0
- package/lib/esm/subgraph/AccountLendingPool.d.ts +19 -0
- package/lib/esm/subgraph/AccountLendingPool.js +71 -0
- package/lib/esm/subgraph/AccountPoolToken.d.ts +14 -0
- package/lib/esm/subgraph/AccountPoolToken.js +75 -0
- package/lib/esm/subgraph/LendingPool.d.ts +38 -0
- package/lib/esm/subgraph/LendingPool.js +204 -0
- package/lib/esm/subgraph/PoolToken.d.ts +64 -0
- package/lib/esm/subgraph/PoolToken.js +462 -0
- package/lib/esm/subgraph/PriceHelper.d.ts +21 -0
- package/lib/esm/subgraph/PriceHelper.js +166 -0
- package/lib/esm/subgraph/SolidexHelper.d.ts +16 -0
- package/lib/esm/subgraph/SolidexHelper.js +58 -0
- package/lib/esm/subgraph/index.d.ts +73 -0
- package/lib/esm/subgraph/index.js +185 -0
- package/lib/esm/subgraph/initializer.d.ts +34 -0
- package/lib/esm/subgraph/initializer.js +517 -0
- package/lib/esm/subgraph/query.d.ts +10 -0
- package/lib/esm/subgraph/query.js +229 -0
- package/lib/esm/utils/ether-utils.d.ts +5 -0
- package/lib/esm/utils/ether-utils.js +26 -0
- package/lib/esm/utils/index.d.ts +3 -0
- package/lib/esm/utils/index.js +16 -0
- package/package.json +9 -3
- package/.idea/impermax-sdk.iml +0 -12
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/workspace.xml +0 -642
- package/abis/ImpermaxABI.ts +0 -3
- package/abis/contracts/BAllowance.json +0 -4735
- package/abis/contracts/BDeployer.json +0 -1195
- package/abis/contracts/BInterestRateModel.json +0 -10796
- package/abis/contracts/BSetter.json +0 -6219
- package/abis/contracts/BStorage.json +0 -2613
- package/abis/contracts/Borrowable.json +0 -19937
- package/abis/contracts/CDeployer.json +0 -1104
- package/abis/contracts/CSetter.json +0 -5094
- package/abis/contracts/CStorage.json +0 -516
- package/abis/contracts/ClaimAggregator.json +0 -2015
- package/abis/contracts/Collateral.json +0 -21615
- package/abis/contracts/ERC20.json +0 -819
- package/abis/contracts/Factory.json +0 -21986
- package/abis/contracts/FarmingPool.json +0 -8601
- package/abis/contracts/IBDeployer.json +0 -351
- package/abis/contracts/IBorrowTracker.json +0 -346
- package/abis/contracts/IBorrowable.json +0 -13207
- package/abis/contracts/ICDeployer.json +0 -294
- package/abis/contracts/IClaimable.json +0 -406
- package/abis/contracts/ICollateral.json +0 -8952
- package/abis/contracts/IERC20.json +0 -2376
- package/abis/contracts/IFactory.json +0 -3660
- package/abis/contracts/IFarmingPool.json +0 -3584
- package/abis/contracts/IImpermaxCallee.json +0 -679
- package/abis/contracts/IMerkleDistributor.json +0 -1134
- package/abis/contracts/IPoolToken.json +0 -5343
- package/abis/contracts/IRouter01.json +0 -6891
- package/abis/contracts/IRouter02.json +0 -7283
- package/abis/contracts/ISimpleUniswapOracle.json +0 -1469
- package/abis/contracts/IStakedLPToken.json +0 -7309
- package/abis/contracts/IStakingRewards.json +0 -1036
- package/abis/contracts/IUniswapV2Callee.json +0 -403
- package/abis/contracts/IUniswapV2ERC20.json +0 -3155
- package/abis/contracts/IUniswapV2Factory.json +0 -1690
- package/abis/contracts/IUniswapV2Pair.json +0 -6761
- package/abis/contracts/IWETH.json +0 -561
- package/abis/contracts/ImpermaxChef.json +0 -20945
- package/abis/contracts/ImpermaxERC20.json +0 -12095
- package/abis/contracts/Math.json +0 -1966
- package/abis/contracts/MockERC20.json +0 -8884
- package/abis/contracts/PoolToken.json +0 -10784
- package/abis/contracts/Router01.json +0 -43963
- package/abis/contracts/SafeMath.json +0 -6828
- package/abis/contracts/SimpleUniswapOracle.json +0 -9640
- package/abis/contracts/TransferHelper.json +0 -4875
- package/abis/contracts/UQ112x112.json +0 -1201
- package/abis/contracts/UniswapV2ERC20.json +0 -10969
- package/abis/contracts/UniswapV2Factory.json +0 -5521
- package/abis/contracts/UniswapV2Library.json +0 -13789
- package/abis/contracts/UniswapV2Pair.json +0 -30782
- package/abis/contracts/WETH9.json +0 -6613
- package/config/amms.ts +0 -199
- package/config/contracts/claim-aggregators.ts +0 -16
- package/config/contracts/impermax-chef.ts +0 -16
- package/config/contracts/imxes.ts +0 -16
- package/config/contracts/merkle-distributors.ts +0 -13
- package/config/contracts/routers.ts +0 -36
- package/config/contracts/simple-uniswap-oracles.ts +0 -33
- package/config/contracts/weths.ts +0 -18
- package/config/debank-ids.ts +0 -15
- package/config/endpoints/merkle-distributors.ts +0 -13
- package/config/eth.ts +0 -32
- package/config/factories.ts +0 -26
- package/config/farms.ts +0 -119
- package/config/general.ts +0 -8
- package/config/subgraphs.ts +0 -69
- package/config/types.ts +0 -81
- package/impermax-router/Account.ts +0 -123
- package/impermax-router/AccountBorrowable.ts +0 -110
- package/impermax-router/AccountCollateral.ts +0 -40
- package/impermax-router/AccountLendingPool.ts +0 -231
- package/impermax-router/AccountPoolToken.ts +0 -76
- package/impermax-router/Borrowable.ts +0 -86
- package/impermax-router/Collateral.ts +0 -26
- package/impermax-router/ContractsHelper.ts +0 -64
- package/impermax-router/ImpermaxFactory.ts +0 -47
- package/impermax-router/Interactions.ts +0 -94
- package/impermax-router/InteractionsLendingPool.ts +0 -129
- package/impermax-router/InteractionsPoolToken.ts +0 -187
- package/impermax-router/LendingPool.ts +0 -256
- package/impermax-router/PoolToken.ts +0 -112
- package/impermax-router/index.ts +0 -49
- package/impermax-router/interfaces.ts +0 -233
- package/subgraph/Account.ts +0 -93
- package/subgraph/AccountLendingPool.ts +0 -60
- package/subgraph/AccountPoolToken.ts +0 -60
- package/subgraph/LendingPool.ts +0 -179
- package/subgraph/PoolToken.ts +0 -381
- package/subgraph/PriceHelper.ts +0 -150
- package/subgraph/SolidexHelper.ts +0 -54
- package/subgraph/index.ts +0 -166
- package/subgraph/initializer.ts +0 -509
- package/subgraph/query.ts +0 -224
- package/tsconfig.json +0 -16
- package/utils/ether-utils.ts +0 -22
- package/utils/index.ts +0 -12
package/subgraph/query.ts
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import gql from "graphql-tag";
|
|
2
|
-
import { Address, Factory } from '../config/types';
|
|
3
|
-
import { LIQUIDATION_FEE_FACTORIES } from '../config/factories';
|
|
4
|
-
|
|
5
|
-
export function blockQuery(timestamp: number) {
|
|
6
|
-
return gql`{
|
|
7
|
-
blocks (first: 1, orderBy: timestamp, orderDirection: desc, where: { timestamp_gt: ${timestamp}, timestamp_lt: ${timestamp+600} }) {
|
|
8
|
-
number
|
|
9
|
-
}
|
|
10
|
-
_meta {
|
|
11
|
-
block {
|
|
12
|
-
number
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function lendingPoolsQuery(factory: Factory,addressesFilter: Address[]) {
|
|
19
|
-
const tokenStr = `{
|
|
20
|
-
id
|
|
21
|
-
symbol
|
|
22
|
-
name
|
|
23
|
-
decimals
|
|
24
|
-
derivedUSD
|
|
25
|
-
}`;
|
|
26
|
-
const distributorStr = `{
|
|
27
|
-
id
|
|
28
|
-
}`;
|
|
29
|
-
const farmingPoolStr = `{
|
|
30
|
-
epochAmount
|
|
31
|
-
epochBegin
|
|
32
|
-
segmentLength
|
|
33
|
-
vestingBegin
|
|
34
|
-
sharePercentage
|
|
35
|
-
distributor ${distributorStr}
|
|
36
|
-
}`;
|
|
37
|
-
const borrowableStr = `{
|
|
38
|
-
id
|
|
39
|
-
underlying ${tokenStr}
|
|
40
|
-
totalBalance
|
|
41
|
-
totalBorrows
|
|
42
|
-
borrowRate
|
|
43
|
-
reserveFactor
|
|
44
|
-
kinkBorrowRate
|
|
45
|
-
kinkUtilizationRate
|
|
46
|
-
borrowIndex
|
|
47
|
-
accrualTimestamp
|
|
48
|
-
exchangeRate
|
|
49
|
-
totalBalanceUSD
|
|
50
|
-
totalSupplyUSD
|
|
51
|
-
totalBorrowsUSD
|
|
52
|
-
farmingPool ${farmingPoolStr}
|
|
53
|
-
}`;
|
|
54
|
-
const collateralStr = `{
|
|
55
|
-
id
|
|
56
|
-
totalBalance
|
|
57
|
-
totalBalanceUSD
|
|
58
|
-
safetyMargin
|
|
59
|
-
liquidationIncentive
|
|
60
|
-
${LIQUIDATION_FEE_FACTORIES.includes(factory) ? "liquidationFee" : ""}
|
|
61
|
-
exchangeRate
|
|
62
|
-
}`;
|
|
63
|
-
const pairStr = `{
|
|
64
|
-
factory
|
|
65
|
-
reserve0
|
|
66
|
-
reserve1
|
|
67
|
-
totalSupply
|
|
68
|
-
reserveUSD
|
|
69
|
-
token0Price
|
|
70
|
-
token1Price
|
|
71
|
-
derivedUSD
|
|
72
|
-
uniswapV2PairAddress
|
|
73
|
-
uniswapV2Factory
|
|
74
|
-
isStakedLPToken
|
|
75
|
-
exchangeRate
|
|
76
|
-
stakingRewards
|
|
77
|
-
masterChef
|
|
78
|
-
pid
|
|
79
|
-
stakedTotalSupply
|
|
80
|
-
rewards {
|
|
81
|
-
id
|
|
82
|
-
rewardRate
|
|
83
|
-
rewardsToken ${tokenStr}
|
|
84
|
-
periodFinish
|
|
85
|
-
}
|
|
86
|
-
}`;
|
|
87
|
-
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
88
|
-
return gql`{
|
|
89
|
-
lendingPools(first: 1000, orderBy: totalBorrowsUSD, orderDirection: desc ${ id_in_string }) {
|
|
90
|
-
id
|
|
91
|
-
borrowable0 ${ borrowableStr }
|
|
92
|
-
borrowable1 ${ borrowableStr }
|
|
93
|
-
collateral ${ collateralStr }
|
|
94
|
-
pair ${ pairStr }
|
|
95
|
-
}
|
|
96
|
-
_meta {
|
|
97
|
-
block {
|
|
98
|
-
number
|
|
99
|
-
}
|
|
100
|
-
hasIndexingErrors
|
|
101
|
-
}
|
|
102
|
-
}`;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function lendingPoolsPastQuery(blockNumber: number, addressesFilter: Address[]) {
|
|
106
|
-
const borrowablePastStr = `{
|
|
107
|
-
borrowIndex
|
|
108
|
-
accrualTimestamp
|
|
109
|
-
exchangeRate
|
|
110
|
-
}`;
|
|
111
|
-
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
112
|
-
return gql`{
|
|
113
|
-
lendingPools(first: 1000, orderBy: totalBorrowsUSD, orderDirection: desc, block: {number: ${blockNumber}} ${ id_in_string }) {
|
|
114
|
-
id
|
|
115
|
-
borrowable0 ${ borrowablePastStr }
|
|
116
|
-
borrowable1 ${ borrowablePastStr }
|
|
117
|
-
}
|
|
118
|
-
}`;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function impermaxChefQuery() {
|
|
122
|
-
return gql`{
|
|
123
|
-
impermaxChefs(first: 1) {
|
|
124
|
-
id
|
|
125
|
-
rewardToken
|
|
126
|
-
rewardPerSec
|
|
127
|
-
totalAllocPoint
|
|
128
|
-
}
|
|
129
|
-
pools(first: 1000) {
|
|
130
|
-
id
|
|
131
|
-
allocPoint
|
|
132
|
-
rewarder {id}
|
|
133
|
-
}
|
|
134
|
-
impermaxRewarders(first: 1000) {
|
|
135
|
-
rewardToken
|
|
136
|
-
rewardPerSec
|
|
137
|
-
totalAllocPoint
|
|
138
|
-
pools(first: 1000) {
|
|
139
|
-
borrowable
|
|
140
|
-
allocPoint
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}`;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function pastVolumeQuery(blockNumber: number, addressesFilter: Address[]) {
|
|
147
|
-
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
148
|
-
return gql`{
|
|
149
|
-
pairs (block: {number: ${blockNumber}} ${id_in_string}) {
|
|
150
|
-
id
|
|
151
|
-
volumeUSD
|
|
152
|
-
}
|
|
153
|
-
}`;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export function currentVolumeAndReservesQuery(addressesFilter: Address[]) {
|
|
157
|
-
const id_in_string = addressesFilter.length > 0 ? `where: {id_in: ["${addressesFilter.join('","').toLowerCase()}"]}` : "";
|
|
158
|
-
return gql`{
|
|
159
|
-
pairs (${id_in_string}) {
|
|
160
|
-
id
|
|
161
|
-
reserveUSD
|
|
162
|
-
volumeUSD
|
|
163
|
-
}
|
|
164
|
-
}`;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export function tvlQuery() {
|
|
168
|
-
return gql`{
|
|
169
|
-
impermaxFactories(first: 1) {
|
|
170
|
-
totalBalanceUSD
|
|
171
|
-
totalSupplyUSD
|
|
172
|
-
totalBorrowsUSD
|
|
173
|
-
}
|
|
174
|
-
}`;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export function userQuery(account: Address) {
|
|
178
|
-
return gql`{
|
|
179
|
-
user(id: "${account.toLowerCase()}") {
|
|
180
|
-
collateralPositions(first:1000) {
|
|
181
|
-
balance
|
|
182
|
-
collateral {
|
|
183
|
-
lendingPool {
|
|
184
|
-
id
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
supplyPositions(first:1000) {
|
|
189
|
-
balance
|
|
190
|
-
borrowable {
|
|
191
|
-
underlying {
|
|
192
|
-
id
|
|
193
|
-
}
|
|
194
|
-
lendingPool {
|
|
195
|
-
id
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
borrowPositions(first:1000) {
|
|
200
|
-
borrowBalance
|
|
201
|
-
borrowIndex
|
|
202
|
-
borrowable {
|
|
203
|
-
underlying {
|
|
204
|
-
id
|
|
205
|
-
}
|
|
206
|
-
lendingPool {
|
|
207
|
-
id
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}`;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export function ximxQuery() {
|
|
216
|
-
return gql`{
|
|
217
|
-
ximxes(first: 1) {
|
|
218
|
-
totalSupply
|
|
219
|
-
totalBalance
|
|
220
|
-
exchangeRate
|
|
221
|
-
dailyAPR
|
|
222
|
-
}
|
|
223
|
-
}`;
|
|
224
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"outDir": "./dist/www/build",
|
|
4
|
-
"sourceMap": true,
|
|
5
|
-
"resolveJsonModule": true,
|
|
6
|
-
"noImplicitAny": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"module": "commonjs",
|
|
9
|
-
"target": "es6",
|
|
10
|
-
"jsx": "react",
|
|
11
|
-
"lib": ["es6", "dom", "es2017"]
|
|
12
|
-
},
|
|
13
|
-
"exclude": [
|
|
14
|
-
"node_modules/**/*"
|
|
15
|
-
]
|
|
16
|
-
}
|
package/utils/ether-utils.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { formatUnits, parseUnits } from 'ethers/lib/utils';
|
|
2
|
-
import { BigNumber } from 'ethers';
|
|
3
|
-
|
|
4
|
-
export function balanceToDecimal(s: string): string {
|
|
5
|
-
return formatUnits(s);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function formatToDecimals(n: number, decimals: number = 2) : string {
|
|
9
|
-
if (n === null || n === undefined || isNaN(n)) return "-";
|
|
10
|
-
if (n == Infinity) return "Infinity"; //return "∞";
|
|
11
|
-
return (Math.round(n * (10 ** decimals)) / (10 ** decimals)).toFixed(decimals);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function decimalToBalance(d: string | number, decimals = 18): BigNumber {
|
|
15
|
-
const n = parseFloat(d.toString());
|
|
16
|
-
const s = formatToDecimals(Math.max(n, 0), decimals);
|
|
17
|
-
return parseUnits(s, decimals);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function address(n: number): string {
|
|
21
|
-
return `0x${n.toString(16).padStart(40, '0')}`;
|
|
22
|
-
}
|
package/utils/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function toAPR(n: number) : number {
|
|
2
|
-
const SECONDS_IN_YEAR = 365 * 24 * 3600;
|
|
3
|
-
return n * SECONDS_IN_YEAR;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function impermanentLoss(priceSwing: number) {
|
|
7
|
-
return Math.sqrt(priceSwing) / (priceSwing + 1) * 2;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function isValidNumber(n: number) : boolean {
|
|
11
|
-
return !(n === null || n === undefined || isNaN(n));
|
|
12
|
-
}
|