@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/SDK.ts
CHANGED
|
@@ -8,40 +8,75 @@ import {
|
|
|
8
8
|
CurrencyAmount,
|
|
9
9
|
HypotheticalStats,
|
|
10
10
|
MarketAction,
|
|
11
|
-
TokenValuation
|
|
11
|
+
TokenValuation,
|
|
12
12
|
} from './types';
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
networkAddresses,
|
|
15
|
+
BORROW_LIMIT_BUFFER,
|
|
16
|
+
DECIMAL_PRECISION,
|
|
17
|
+
ONE_DAY,
|
|
18
|
+
PlyUsdcPid,
|
|
19
|
+
ALL_STAKING_POOLS,
|
|
20
|
+
PLYUSDCRewardTokens,
|
|
21
|
+
} from './constants';
|
|
14
22
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
15
23
|
import { Contract, BigNumber as BN } from 'ethers';
|
|
16
|
-
import {
|
|
24
|
+
import {
|
|
25
|
+
isSameAddress,
|
|
26
|
+
decimalFactor,
|
|
27
|
+
calcLMRewardApr,
|
|
28
|
+
getDecimal,
|
|
29
|
+
} from './helpers';
|
|
17
30
|
import { MoneyMarketRead } from './MoneyMarket';
|
|
18
|
-
import {
|
|
19
|
-
|
|
31
|
+
import {
|
|
32
|
+
fetchValuation,
|
|
33
|
+
fetchPrice,
|
|
34
|
+
calcValuation,
|
|
35
|
+
valuateToken,
|
|
36
|
+
} from './priceFetcher';
|
|
37
|
+
import {
|
|
38
|
+
AuriFairLaunch,
|
|
39
|
+
Comptroller,
|
|
40
|
+
AuriLens,
|
|
41
|
+
IERC20,
|
|
42
|
+
} from '@aurigami/contracts/typechain';
|
|
20
43
|
import { TokenAmount } from './tokenAmount';
|
|
21
44
|
import { PLYUSDCToken, PLYToken, Token } from './token';
|
|
22
45
|
import BigNumber from 'bignumber.js';
|
|
23
46
|
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
24
47
|
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
25
|
-
import AuriFairLaunchABI from
|
|
26
|
-
import FaucetABI from
|
|
48
|
+
import AuriFairLaunchABI from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
|
|
49
|
+
import FaucetABI from '@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json';
|
|
27
50
|
import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
|
|
28
51
|
import { PapermillRead } from './Papermill';
|
|
29
52
|
|
|
30
53
|
export class SdkRead extends BlockchainEntityRead {
|
|
31
|
-
|
|
32
54
|
protected _comptroller: Comptroller;
|
|
33
55
|
protected _auriFairLaunch: AuriFairLaunch;
|
|
34
56
|
protected _auriLens: AuriLens;
|
|
35
57
|
constructor(networkConnection: NetworkConnection) {
|
|
36
58
|
super(networkConnection);
|
|
37
|
-
this._comptroller = new Contract(
|
|
38
|
-
|
|
39
|
-
|
|
59
|
+
this._comptroller = new Contract(
|
|
60
|
+
networkAddresses.misc.COMPTROLLER,
|
|
61
|
+
ComptrollerABI.abi,
|
|
62
|
+
networkConnection.provider
|
|
63
|
+
) as Comptroller;
|
|
64
|
+
this._auriFairLaunch = new Contract(
|
|
65
|
+
networkAddresses.misc.AURIFAIRLAUNCH,
|
|
66
|
+
AuriFairLaunchABI.abi,
|
|
67
|
+
networkConnection.provider
|
|
68
|
+
) as AuriFairLaunch;
|
|
69
|
+
this._auriLens = new Contract(
|
|
70
|
+
networkAddresses.misc.AURILENS,
|
|
71
|
+
AuriLensABI.abi,
|
|
72
|
+
networkConnection.provider
|
|
73
|
+
) as AuriLens;
|
|
40
74
|
}
|
|
41
75
|
|
|
42
76
|
public async getUserDetails(userAddress: string): Promise<UserDetails> {
|
|
43
77
|
const marketCount = networkAddresses.auTokens.length;
|
|
44
|
-
var userMarketDetails: UserMarketDetails[] = [],
|
|
78
|
+
var userMarketDetails: UserMarketDetails[] = [],
|
|
79
|
+
assetsIn: string[];
|
|
45
80
|
var promises = [];
|
|
46
81
|
var totalBorrowLimit = new BigNumber(0);
|
|
47
82
|
var pricePromises = [];
|
|
@@ -49,81 +84,142 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
49
84
|
const userMarketDetail: UserMarketDetails = {} as UserMarketDetails;
|
|
50
85
|
userMarketDetails.push(userMarketDetail);
|
|
51
86
|
userMarketDetail.market = auToken.underlying;
|
|
52
|
-
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
87
|
+
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
88
|
+
this._networkConnection,
|
|
89
|
+
auToken.address,
|
|
90
|
+
auToken.underlying
|
|
91
|
+
);
|
|
92
|
+
promises.push(
|
|
93
|
+
moneyMarket
|
|
94
|
+
.getUserDepositBalance(userAddress)
|
|
95
|
+
.then((res: TokenAmount) => {
|
|
96
|
+
userMarketDetail.depositBalance = res;
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
promises.push(
|
|
100
|
+
moneyMarket
|
|
101
|
+
.getUserBorrowBalance(userAddress)
|
|
102
|
+
.then((res: TokenAmount) => {
|
|
103
|
+
userMarketDetail.borrowBalance = res;
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
promises.push(
|
|
107
|
+
moneyMarket.getCollateralRatio().then((res: BigNumber) => {
|
|
108
|
+
userMarketDetail.collateralRatio = res.toNumber();
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
pricePromises.push(
|
|
112
|
+
fetchPrice(
|
|
113
|
+
moneyMarket.underlying.address,
|
|
114
|
+
this._networkConnection.provider
|
|
115
|
+
).then((res) => {
|
|
116
|
+
userMarketDetail.underlyingPrice = res.toString();
|
|
117
|
+
return res;
|
|
118
|
+
})
|
|
119
|
+
);
|
|
60
120
|
}
|
|
61
121
|
|
|
62
|
-
promises.push(
|
|
122
|
+
promises.push(
|
|
123
|
+
this._comptroller.getAssetsIn(userAddress).then((res: string[]) => {
|
|
124
|
+
assetsIn = res;
|
|
125
|
+
})
|
|
126
|
+
);
|
|
63
127
|
|
|
64
128
|
await Promise.all(promises);
|
|
65
129
|
var underlyingPrices = await Promise.all(pricePromises);
|
|
66
|
-
var depositValues = []
|
|
67
|
-
for (var i = 0; i < marketCount; i
|
|
130
|
+
var depositValues = [];
|
|
131
|
+
for (var i = 0; i < marketCount; i++) {
|
|
68
132
|
const auToken = networkAddresses.auTokens[i];
|
|
69
|
-
if (
|
|
133
|
+
if (
|
|
134
|
+
assetsIn!.find((auAddress: Address) =>
|
|
135
|
+
isSameAddress(auToken.address, auAddress)
|
|
136
|
+
) !== undefined
|
|
137
|
+
) {
|
|
70
138
|
userMarketDetails[i].isCollateral = true;
|
|
71
139
|
} else {
|
|
72
140
|
userMarketDetails[i].isCollateral = false;
|
|
73
141
|
}
|
|
74
|
-
depositValues.push(
|
|
142
|
+
depositValues.push(
|
|
143
|
+
calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i])
|
|
144
|
+
);
|
|
75
145
|
}
|
|
76
146
|
|
|
77
|
-
totalBorrowLimit = depositValues.reduce(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
147
|
+
totalBorrowLimit = depositValues.reduce(
|
|
148
|
+
(p: BigNumber, v: BigNumber, index: number) => {
|
|
149
|
+
if (userMarketDetails[index].isCollateral)
|
|
150
|
+
return p.plus(
|
|
151
|
+
v.multipliedBy(userMarketDetails[index].collateralRatio)
|
|
152
|
+
);
|
|
153
|
+
return p;
|
|
154
|
+
},
|
|
155
|
+
new BigNumber(0)
|
|
156
|
+
);
|
|
81
157
|
|
|
82
|
-
var accountLiquidity: [BN, BN] =
|
|
158
|
+
var accountLiquidity: [BN, BN] =
|
|
159
|
+
await this._comptroller.getAccountLiquidity(userAddress);
|
|
83
160
|
|
|
84
|
-
var borrowedvaluation: BigNumber = totalBorrowLimit.minus(
|
|
161
|
+
var borrowedvaluation: BigNumber = totalBorrowLimit.minus(
|
|
162
|
+
new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18))
|
|
163
|
+
);
|
|
85
164
|
|
|
86
|
-
if (borrowedvaluation.lt(
|
|
165
|
+
if (borrowedvaluation.lt('0.00001')) {
|
|
166
|
+
// Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
|
|
87
167
|
borrowedvaluation = new BigNumber(0);
|
|
88
168
|
}
|
|
89
169
|
|
|
90
|
-
const bufferedBorrowLimit: BigNumber =
|
|
91
|
-
|
|
170
|
+
const bufferedBorrowLimit: BigNumber =
|
|
171
|
+
totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
|
|
172
|
+
const minimumBorrowLimitAllowed =
|
|
173
|
+
borrowedvaluation.div(BORROW_LIMIT_BUFFER);
|
|
92
174
|
|
|
93
175
|
var borrowableAmount: BigNumber;
|
|
94
176
|
if (bufferedBorrowLimit.lte(borrowedvaluation)) {
|
|
95
|
-
borrowableAmount = new BigNumber(0)
|
|
177
|
+
borrowableAmount = new BigNumber(0);
|
|
96
178
|
} else {
|
|
97
179
|
borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
|
|
98
180
|
}
|
|
99
181
|
|
|
100
|
-
for (var i = 0; i < marketCount; i
|
|
182
|
+
for (var i = 0; i < marketCount; i++) {
|
|
101
183
|
const auToken = networkAddresses.auTokens[i];
|
|
102
|
-
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
);
|
|
184
|
+
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
185
|
+
this._networkConnection,
|
|
186
|
+
auToken.address,
|
|
187
|
+
auToken.underlying
|
|
188
|
+
);
|
|
189
|
+
const borrowLimitMargin = totalBorrowLimit
|
|
190
|
+
.minus(minimumBorrowLimitAllowed)
|
|
191
|
+
.gt(0)
|
|
192
|
+
? totalBorrowLimit.minus(minimumBorrowLimitAllowed)
|
|
193
|
+
: new BigNumber(0);
|
|
194
|
+
const maxWithdrawCap: BigNumber = borrowLimitMargin
|
|
195
|
+
.div(userMarketDetails[i].collateralRatio)
|
|
196
|
+
.div(underlyingPrices[i]);
|
|
197
|
+
userMarketDetails[i].maxWithdrawableAmount =
|
|
198
|
+
userMarketDetails[i].isCollateral &&
|
|
199
|
+
maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
|
|
200
|
+
? new TokenAmount(
|
|
201
|
+
moneyMarket.underlying,
|
|
202
|
+
maxWithdrawCap.toFixed(24),
|
|
203
|
+
false
|
|
204
|
+
)
|
|
205
|
+
: new TokenAmount(
|
|
206
|
+
moneyMarket.underlying,
|
|
207
|
+
userMarketDetails[i].depositBalance.rawAmount()
|
|
208
|
+
);
|
|
115
209
|
}
|
|
116
210
|
|
|
117
211
|
return {
|
|
118
212
|
markets: userMarketDetails,
|
|
119
213
|
borrowLimit: {
|
|
120
|
-
currency:
|
|
121
|
-
amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
|
|
214
|
+
currency: 'USD',
|
|
215
|
+
amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION),
|
|
122
216
|
},
|
|
123
|
-
userLockingDetails: await new PapermillRead(
|
|
217
|
+
userLockingDetails: await new PapermillRead(
|
|
218
|
+
this._networkConnection
|
|
219
|
+
).getLockingDetails(userAddress),
|
|
124
220
|
borrowableAmount: {
|
|
125
|
-
currency:
|
|
126
|
-
amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
|
|
221
|
+
currency: 'USD',
|
|
222
|
+
amount: borrowableAmount.toFixed(DECIMAL_PRECISION),
|
|
127
223
|
},
|
|
128
224
|
};
|
|
129
225
|
}
|
|
@@ -143,16 +239,22 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
143
239
|
var promises = [];
|
|
144
240
|
for (let i = 0; i < rewardPerSeconds!.length; i++) {
|
|
145
241
|
let rewardTokenAddress = PLYUSDCRewardTokens[i];
|
|
146
|
-
let rewardToken = new Token(
|
|
242
|
+
let rewardToken = new Token(
|
|
243
|
+
rewardTokenAddress,
|
|
244
|
+
getDecimal(rewardTokenAddress)
|
|
245
|
+
);
|
|
147
246
|
let rewardPerSecond = rewardPerSeconds![i];
|
|
148
|
-
promises.push(
|
|
247
|
+
promises.push(
|
|
248
|
+
fetchValuation(
|
|
149
249
|
new TokenAmount(rewardToken, rewardPerSecond!.toString()),
|
|
150
250
|
this._networkConnection.provider
|
|
151
|
-
|
|
251
|
+
)
|
|
252
|
+
);
|
|
152
253
|
}
|
|
153
254
|
|
|
154
255
|
const rewardPerSecondValuation = (await Promise.all(promises)).reduce(
|
|
155
|
-
(p: BigNumber, v: BigNumber) => p.plus(v),
|
|
256
|
+
(p: BigNumber, v: BigNumber) => p.plus(v),
|
|
257
|
+
new BigNumber(0)
|
|
156
258
|
);
|
|
157
259
|
|
|
158
260
|
var totalStakeValuation: BigNumber = await fetchValuation(
|
|
@@ -164,20 +266,27 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
164
266
|
totalStakedLiquidity: {
|
|
165
267
|
tokenAmount: stakedLiquidityAmount,
|
|
166
268
|
currencyAmount: {
|
|
167
|
-
currency:
|
|
168
|
-
amount: totalStakeValuation!.toFixed(DECIMAL_PRECISION)
|
|
169
|
-
}
|
|
269
|
+
currency: 'USD',
|
|
270
|
+
amount: totalStakeValuation!.toFixed(DECIMAL_PRECISION),
|
|
271
|
+
},
|
|
170
272
|
},
|
|
171
|
-
apy: calcLMRewardApr(
|
|
273
|
+
apy: calcLMRewardApr(
|
|
274
|
+
rewardPerSecondValuation,
|
|
275
|
+
totalStakeValuation,
|
|
276
|
+
ONE_DAY * 365
|
|
277
|
+
).toFixed(DECIMAL_PRECISION),
|
|
172
278
|
};
|
|
173
279
|
}
|
|
174
280
|
|
|
175
281
|
public async getTokenPrice(token: Token): Promise<CurrencyAmount> {
|
|
176
|
-
const price = await fetchPrice(
|
|
282
|
+
const price = await fetchPrice(
|
|
283
|
+
token.address,
|
|
284
|
+
this._networkConnection.provider
|
|
285
|
+
);
|
|
177
286
|
return {
|
|
178
|
-
currency:
|
|
179
|
-
amount: price.toFixed(DECIMAL_PRECISION)
|
|
180
|
-
}
|
|
287
|
+
currency: 'USD',
|
|
288
|
+
amount: price.toFixed(DECIMAL_PRECISION),
|
|
289
|
+
};
|
|
181
290
|
}
|
|
182
291
|
|
|
183
292
|
/**
|
|
@@ -185,10 +294,7 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
185
294
|
*/
|
|
186
295
|
public async stakeBalanceOf(user: string): Promise<TokenValuation> {
|
|
187
296
|
const userInfo = await this._auriFairLaunch.getUserInfo(PlyUsdcPid, user);
|
|
188
|
-
let stakeAmount = new TokenAmount(
|
|
189
|
-
PLYUSDCToken,
|
|
190
|
-
userInfo.amount.toString()
|
|
191
|
-
);
|
|
297
|
+
let stakeAmount = new TokenAmount(PLYUSDCToken, userInfo.amount.toString());
|
|
192
298
|
|
|
193
299
|
return valuateToken(stakeAmount, this._networkConnection.provider);
|
|
194
300
|
}
|
|
@@ -197,7 +303,11 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
197
303
|
* Get amount and value in $ of LP token in user wallet
|
|
198
304
|
*/
|
|
199
305
|
public async LpBalanceOf(user: string): Promise<TokenValuation> {
|
|
200
|
-
let lpERC20 = new Contract(
|
|
306
|
+
let lpERC20 = new Contract(
|
|
307
|
+
networkAddresses.tokens.PLYUSDC,
|
|
308
|
+
EIP20InterfaceABI.abi,
|
|
309
|
+
this._networkConnection.provider
|
|
310
|
+
) as IERC20;
|
|
201
311
|
let balance = await lpERC20.balanceOf(user);
|
|
202
312
|
|
|
203
313
|
return valuateToken(
|
|
@@ -211,42 +321,68 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
211
321
|
currentBorrowLimit,
|
|
212
322
|
currentBorrowValuation,
|
|
213
323
|
action,
|
|
214
|
-
tokenAmount
|
|
324
|
+
tokenAmount,
|
|
215
325
|
}: {
|
|
216
|
-
userMarketDetail: UserMarketDetails
|
|
217
|
-
currentBorrowLimit: CurrencyAmount
|
|
218
|
-
currentBorrowValuation: CurrencyAmount
|
|
219
|
-
action: MarketAction
|
|
220
|
-
tokenAmount?: TokenAmount
|
|
326
|
+
userMarketDetail: UserMarketDetails;
|
|
327
|
+
currentBorrowLimit: CurrencyAmount;
|
|
328
|
+
currentBorrowValuation: CurrencyAmount;
|
|
329
|
+
action: MarketAction;
|
|
330
|
+
tokenAmount?: TokenAmount;
|
|
221
331
|
}): HypotheticalStats {
|
|
222
|
-
var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
|
|
332
|
+
var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
|
|
333
|
+
newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
|
|
223
334
|
switch (action) {
|
|
224
335
|
case MarketAction.EnableCollateral:
|
|
225
336
|
case MarketAction.DisableCollateral:
|
|
226
|
-
var deltaBorrowLimit = calcValuation(
|
|
227
|
-
|
|
337
|
+
var deltaBorrowLimit = calcValuation(
|
|
338
|
+
userMarketDetail.depositBalance,
|
|
339
|
+
new BigNumber(userMarketDetail.underlyingPrice)
|
|
340
|
+
)
|
|
341
|
+
.multipliedBy(userMarketDetail.collateralRatio)
|
|
342
|
+
.multipliedBy(BORROW_LIMIT_BUFFER);
|
|
343
|
+
newBorrowLimit =
|
|
344
|
+
action == MarketAction.EnableCollateral
|
|
345
|
+
? newBorrowLimit.plus(deltaBorrowLimit)
|
|
346
|
+
: newBorrowLimit.minus(deltaBorrowLimit);
|
|
228
347
|
break;
|
|
229
348
|
|
|
230
349
|
case MarketAction.Deposit:
|
|
231
350
|
case MarketAction.Withdraw:
|
|
232
|
-
deltaBorrowLimit = calcValuation(
|
|
233
|
-
|
|
351
|
+
deltaBorrowLimit = calcValuation(
|
|
352
|
+
tokenAmount!,
|
|
353
|
+
new BigNumber(userMarketDetail.underlyingPrice)
|
|
354
|
+
)
|
|
355
|
+
.multipliedBy(userMarketDetail.collateralRatio)
|
|
356
|
+
.multipliedBy(BORROW_LIMIT_BUFFER);
|
|
357
|
+
newBorrowLimit =
|
|
358
|
+
action == MarketAction.Deposit
|
|
359
|
+
? newBorrowLimit.plus(deltaBorrowLimit)
|
|
360
|
+
: newBorrowLimit.minus(deltaBorrowLimit);
|
|
234
361
|
break;
|
|
235
362
|
|
|
236
363
|
case MarketAction.Borrow:
|
|
237
364
|
case MarketAction.Repay:
|
|
238
|
-
var deltaBorrowValuation = calcValuation(
|
|
239
|
-
|
|
365
|
+
var deltaBorrowValuation = calcValuation(
|
|
366
|
+
tokenAmount!,
|
|
367
|
+
new BigNumber(userMarketDetail.underlyingPrice)
|
|
368
|
+
);
|
|
369
|
+
newBorrowValuation =
|
|
370
|
+
action == MarketAction.Borrow
|
|
371
|
+
? newBorrowValuation.plus(deltaBorrowValuation)
|
|
372
|
+
: newBorrowValuation.minus(deltaBorrowValuation);
|
|
240
373
|
break;
|
|
241
374
|
}
|
|
242
375
|
return {
|
|
243
376
|
newBorrowLimit: {
|
|
244
377
|
amount: newBorrowLimit!.toFixed(DECIMAL_PRECISION),
|
|
245
|
-
currency:
|
|
378
|
+
currency: 'USD',
|
|
246
379
|
},
|
|
247
|
-
newBorrowUtilization: newBorrowLimit.eq(0)
|
|
248
|
-
|
|
249
|
-
|
|
380
|
+
newBorrowUtilization: newBorrowLimit.eq(0)
|
|
381
|
+
? newBorrowValuation.eq(0)
|
|
382
|
+
? 0
|
|
383
|
+
: 9999.99
|
|
384
|
+
: newBorrowValuation!.div(newBorrowLimit!).toNumber(),
|
|
385
|
+
};
|
|
250
386
|
}
|
|
251
387
|
}
|
|
252
388
|
|
|
@@ -255,23 +391,33 @@ export class SdkReadWrite extends SdkRead {
|
|
|
255
391
|
* Claim PLY reward in all markets + staking pools
|
|
256
392
|
*/
|
|
257
393
|
public async claim(): Promise<TransactionResponse> {
|
|
258
|
-
return this._auriLens
|
|
259
|
-
this.
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
394
|
+
return this._auriLens
|
|
395
|
+
.connect(this._networkConnection.signer!)
|
|
396
|
+
.claimRewards(
|
|
397
|
+
this._comptroller.address,
|
|
398
|
+
this._auriFairLaunch.address,
|
|
399
|
+
ALL_STAKING_POOLS
|
|
400
|
+
);
|
|
263
401
|
}
|
|
264
402
|
|
|
265
403
|
public async stake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
266
|
-
return this._auriFairLaunch
|
|
404
|
+
return this._auriFairLaunch
|
|
405
|
+
.connect(this._networkConnection.signer!)
|
|
406
|
+
.deposit(PlyUsdcPid, amount.rawAmount());
|
|
267
407
|
}
|
|
268
408
|
|
|
269
409
|
public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
270
|
-
return this._auriFairLaunch
|
|
410
|
+
return this._auriFairLaunch
|
|
411
|
+
.connect(this._networkConnection.signer!)
|
|
412
|
+
.withdraw(PlyUsdcPid, amount.rawAmount());
|
|
271
413
|
}
|
|
272
414
|
|
|
273
415
|
public async faucetDrip(): Promise<TransactionResponse> {
|
|
274
|
-
const faucet = new Contract(
|
|
416
|
+
const faucet = new Contract(
|
|
417
|
+
networkAddresses.misc.FAUCET,
|
|
418
|
+
FaucetABI.abi,
|
|
419
|
+
this._networkConnection.provider
|
|
420
|
+
);
|
|
275
421
|
return faucet.connect(this._networkConnection.signer!).drip();
|
|
276
422
|
}
|
|
277
423
|
}
|