@aurigami/sdk 1.4.8 → 1.5.0-dummy-1
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 +31 -0
- package/dist/SDK.d.ts +6 -7
- package/dist/airdrop-lottery.d.ts +4 -4
- package/dist/constants.d.ts +6 -2
- package/dist/helpers.d.ts +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/priceFetcher.d.ts +6 -4
- package/dist/sdk.cjs.development.js +700 -270
- 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 +690 -268
- package/dist/sdk.esm.js.map +1 -1
- package/dist/token.d.ts +1 -1
- package/dist/tokenAmount.d.ts +1 -1
- package/dist/transfer-event-query.d.ts +4 -4
- package/dist/types.d.ts +13 -9
- package/package.json +5 -11
- package/src/BlockchainEntity.ts +6 -2
- package/src/MoneyMarket.ts +317 -105
- package/src/Papermill.ts +243 -0
- package/src/SDK.ts +307 -147
- package/src/airdrop-lottery.ts +293 -248
- package/src/aurora-api-helpers.ts +11 -6
- package/src/constants.ts +82 -60
- package/src/decimals.ts +5 -3
- package/src/dummy.ts +17 -23
- package/src/helpers.ts +45 -26
- package/src/index.ts +2 -1
- package/src/priceFetcher.ts +256 -103
- package/src/token.ts +16 -16
- package/src/tokenAmount.ts +21 -21
- package/src/transfer-event-query.ts +64 -54
- package/src/types.ts +39 -19
package/src/SDK.ts
CHANGED
|
@@ -1,65 +1,82 @@
|
|
|
1
1
|
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
PlyAuroraPoolDetails,
|
|
3
|
+
PlyUsdcPoolDetails,
|
|
5
4
|
NetworkConnection,
|
|
6
5
|
UserDetails,
|
|
7
6
|
UserMarketDetails,
|
|
8
7
|
Address,
|
|
9
8
|
CurrencyAmount,
|
|
10
9
|
HypotheticalStats,
|
|
11
|
-
MarketAction
|
|
10
|
+
MarketAction,
|
|
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
|
-
import { Contract, BigNumber as BN
|
|
16
|
-
import {
|
|
23
|
+
import { Contract, BigNumber as BN } from 'ethers';
|
|
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
|
-
import {
|
|
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
|
|
26
|
-
import
|
|
27
|
-
import
|
|
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';
|
|
50
|
+
import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
|
|
51
|
+
import { PapermillRead } from './Papermill';
|
|
28
52
|
|
|
29
53
|
export class SdkRead extends BlockchainEntityRead {
|
|
30
|
-
|
|
31
54
|
protected _comptroller: Comptroller;
|
|
32
|
-
protected _tokenLock: TokenLock;
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
53
|
-
return {
|
|
54
|
-
vestingStart: REWARDCLAIMSTART, // 10 Jan 2023
|
|
55
|
-
currentUnlockPortion: (new BigNumber(denominator).minus(values[0])).div(denominator).toNumber(),
|
|
56
|
-
nextUnlockPortion: (new BigNumber(denominator).minus(values[1])).div(denominator).toNumber(),
|
|
57
|
-
};
|
|
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;
|
|
58
74
|
}
|
|
59
75
|
|
|
60
76
|
public async getUserDetails(userAddress: string): Promise<UserDetails> {
|
|
61
77
|
const marketCount = networkAddresses.auTokens.length;
|
|
62
|
-
var userMarketDetails: UserMarketDetails[] = [],
|
|
78
|
+
var userMarketDetails: UserMarketDetails[] = [],
|
|
79
|
+
assetsIn: string[];
|
|
63
80
|
var promises = [];
|
|
64
81
|
var totalBorrowLimit = new BigNumber(0);
|
|
65
82
|
var pricePromises = [];
|
|
@@ -67,197 +84,340 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
67
84
|
const userMarketDetail: UserMarketDetails = {} as UserMarketDetails;
|
|
68
85
|
userMarketDetails.push(userMarketDetail);
|
|
69
86
|
userMarketDetail.market = auToken.underlying;
|
|
70
|
-
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
+
);
|
|
78
120
|
}
|
|
79
121
|
|
|
80
|
-
promises.push(
|
|
81
|
-
|
|
122
|
+
promises.push(
|
|
123
|
+
this._comptroller.getAssetsIn(userAddress).then((res: string[]) => {
|
|
124
|
+
assetsIn = res;
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
|
|
82
128
|
await Promise.all(promises);
|
|
83
129
|
var underlyingPrices = await Promise.all(pricePromises);
|
|
84
|
-
var depositValues = []
|
|
85
|
-
for (var i = 0; i < marketCount; i
|
|
130
|
+
var depositValues = [];
|
|
131
|
+
for (var i = 0; i < marketCount; i++) {
|
|
86
132
|
const auToken = networkAddresses.auTokens[i];
|
|
87
|
-
if (
|
|
133
|
+
if (
|
|
134
|
+
assetsIn!.find((auAddress: Address) =>
|
|
135
|
+
isSameAddress(auToken.address, auAddress)
|
|
136
|
+
) !== undefined
|
|
137
|
+
) {
|
|
88
138
|
userMarketDetails[i].isCollateral = true;
|
|
89
139
|
} else {
|
|
90
140
|
userMarketDetails[i].isCollateral = false;
|
|
91
141
|
}
|
|
92
|
-
depositValues.push(
|
|
142
|
+
depositValues.push(
|
|
143
|
+
calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i])
|
|
144
|
+
);
|
|
93
145
|
}
|
|
94
146
|
|
|
95
|
-
totalBorrowLimit = depositValues.reduce(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
);
|
|
105
157
|
|
|
106
|
-
|
|
158
|
+
var accountLiquidity: [BN, BN] =
|
|
159
|
+
await this._comptroller.getAccountLiquidity(userAddress);
|
|
107
160
|
|
|
108
|
-
var borrowedvaluation: BigNumber = totalBorrowLimit.minus(
|
|
161
|
+
var borrowedvaluation: BigNumber = totalBorrowLimit.minus(
|
|
162
|
+
new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18))
|
|
163
|
+
);
|
|
109
164
|
|
|
110
|
-
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
|
|
111
167
|
borrowedvaluation = new BigNumber(0);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const bufferedBorrowLimit: BigNumber =
|
|
115
|
-
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const bufferedBorrowLimit: BigNumber =
|
|
171
|
+
totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
|
|
172
|
+
const minimumBorrowLimitAllowed =
|
|
173
|
+
borrowedvaluation.div(BORROW_LIMIT_BUFFER);
|
|
116
174
|
|
|
117
175
|
var borrowableAmount: BigNumber;
|
|
118
176
|
if (bufferedBorrowLimit.lte(borrowedvaluation)) {
|
|
119
|
-
borrowableAmount = new BigNumber(0)
|
|
177
|
+
borrowableAmount = new BigNumber(0);
|
|
120
178
|
} else {
|
|
121
179
|
borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
|
|
122
180
|
}
|
|
123
181
|
|
|
124
|
-
for (var i = 0; i < marketCount; i
|
|
182
|
+
for (var i = 0; i < marketCount; i++) {
|
|
125
183
|
const auToken = networkAddresses.auTokens[i];
|
|
126
|
-
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
);
|
|
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
|
+
);
|
|
139
209
|
}
|
|
140
210
|
|
|
141
211
|
return {
|
|
142
212
|
markets: userMarketDetails,
|
|
143
213
|
borrowLimit: {
|
|
144
|
-
currency:
|
|
145
|
-
amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
|
|
214
|
+
currency: 'USD',
|
|
215
|
+
amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION),
|
|
146
216
|
},
|
|
147
|
-
|
|
148
|
-
|
|
217
|
+
userLockingDetails: await new PapermillRead(
|
|
218
|
+
this._networkConnection
|
|
219
|
+
).getLockingDetails(userAddress),
|
|
149
220
|
borrowableAmount: {
|
|
150
|
-
currency:
|
|
151
|
-
amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
|
|
221
|
+
currency: 'USD',
|
|
222
|
+
amount: borrowableAmount.toFixed(DECIMAL_PRECISION),
|
|
152
223
|
},
|
|
153
224
|
};
|
|
154
225
|
}
|
|
155
226
|
|
|
156
|
-
public async
|
|
157
|
-
var stakedLiquidity: BN,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}));
|
|
163
|
-
await Promise.all(promises);
|
|
227
|
+
public async getPlyUsdcPoolDetails(): Promise<PlyUsdcPoolDetails> {
|
|
228
|
+
var stakedLiquidity: BN, rewardPerSeconds: BN[];
|
|
229
|
+
await this._auriFairLaunch.getPoolInfo(PlyUsdcPid).then((res) => {
|
|
230
|
+
stakedLiquidity = res.totalStake;
|
|
231
|
+
rewardPerSeconds = res.rewardPerSeconds;
|
|
232
|
+
});
|
|
164
233
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
promises.push(fetchValuation(new TokenAmount(
|
|
168
|
-
PLYToken,
|
|
169
|
-
rewardPerSecond!.toString()
|
|
170
|
-
), this._networkConnection.provider).then((res) => rewardPerSecondValuation = res));
|
|
171
|
-
promises.push(fetchValuation(new TokenAmount(
|
|
172
|
-
AURPLYToken,
|
|
234
|
+
let stakedLiquidityAmount = new TokenAmount(
|
|
235
|
+
PLYUSDCToken,
|
|
173
236
|
stakedLiquidity!.toString()
|
|
174
|
-
)
|
|
175
|
-
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
var promises = [];
|
|
240
|
+
for (let i = 0; i < rewardPerSeconds!.length; i++) {
|
|
241
|
+
let rewardTokenAddress = PLYUSDCRewardTokens[i];
|
|
242
|
+
let rewardToken = new Token(
|
|
243
|
+
rewardTokenAddress,
|
|
244
|
+
getDecimal(rewardTokenAddress)
|
|
245
|
+
);
|
|
246
|
+
let rewardPerSecond = rewardPerSeconds![i];
|
|
247
|
+
promises.push(
|
|
248
|
+
fetchValuation(
|
|
249
|
+
new TokenAmount(rewardToken, rewardPerSecond!.toString()),
|
|
250
|
+
this._networkConnection.provider
|
|
251
|
+
)
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const rewardPerSecondValuation = (await Promise.all(promises)).reduce(
|
|
256
|
+
(p: BigNumber, v: BigNumber) => p.plus(v),
|
|
257
|
+
new BigNumber(0)
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
var totalStakeValuation: BigNumber = await fetchValuation(
|
|
261
|
+
stakedLiquidityAmount,
|
|
262
|
+
this._networkConnection.provider
|
|
263
|
+
);
|
|
176
264
|
|
|
177
265
|
return {
|
|
178
|
-
totalStakedLiquidity:
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
266
|
+
totalStakedLiquidity: {
|
|
267
|
+
tokenAmount: stakedLiquidityAmount,
|
|
268
|
+
currencyAmount: {
|
|
269
|
+
currency: 'USD',
|
|
270
|
+
amount: totalStakeValuation!.toFixed(DECIMAL_PRECISION),
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
apy: calcLMRewardApr(
|
|
274
|
+
rewardPerSecondValuation,
|
|
275
|
+
totalStakeValuation,
|
|
276
|
+
ONE_DAY * 365
|
|
277
|
+
).toFixed(DECIMAL_PRECISION),
|
|
183
278
|
};
|
|
184
279
|
}
|
|
185
280
|
|
|
186
281
|
public async getTokenPrice(token: Token): Promise<CurrencyAmount> {
|
|
187
|
-
const price = await fetchPrice(
|
|
282
|
+
const price = await fetchPrice(
|
|
283
|
+
token.address,
|
|
284
|
+
this._networkConnection.provider
|
|
285
|
+
);
|
|
188
286
|
return {
|
|
189
|
-
currency:
|
|
190
|
-
amount: price.toFixed(DECIMAL_PRECISION)
|
|
191
|
-
}
|
|
287
|
+
currency: 'USD',
|
|
288
|
+
amount: price.toFixed(DECIMAL_PRECISION),
|
|
289
|
+
};
|
|
192
290
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
)
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Get amount and value in $ of staked LP tokens
|
|
294
|
+
*/
|
|
295
|
+
public async stakeBalanceOf(user: string): Promise<TokenValuation> {
|
|
296
|
+
const userInfo = await this._auriFairLaunch.getUserInfo(PlyUsdcPid, user);
|
|
297
|
+
let stakeAmount = new TokenAmount(PLYUSDCToken, userInfo.amount.toString());
|
|
298
|
+
|
|
299
|
+
return valuateToken(stakeAmount, this._networkConnection.provider);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Get amount and value in $ of LP token in user wallet
|
|
304
|
+
*/
|
|
305
|
+
public async LpBalanceOf(user: string): Promise<TokenValuation> {
|
|
306
|
+
let lpERC20 = new Contract(
|
|
307
|
+
networkAddresses.tokens.PLYUSDC,
|
|
308
|
+
EIP20InterfaceABI.abi,
|
|
309
|
+
this._networkConnection.provider
|
|
310
|
+
) as IERC20;
|
|
311
|
+
let balance = await lpERC20.balanceOf(user);
|
|
312
|
+
|
|
313
|
+
return valuateToken(
|
|
314
|
+
new TokenAmount(PLYUSDCToken, balance.toString()),
|
|
315
|
+
this._networkConnection.provider
|
|
316
|
+
);
|
|
199
317
|
}
|
|
200
318
|
|
|
201
319
|
public calcHypotheticalStats({
|
|
202
|
-
userMarketDetail,
|
|
320
|
+
userMarketDetail,
|
|
203
321
|
currentBorrowLimit,
|
|
204
322
|
currentBorrowValuation,
|
|
205
323
|
action,
|
|
206
|
-
tokenAmount
|
|
324
|
+
tokenAmount,
|
|
207
325
|
}: {
|
|
208
|
-
userMarketDetail: UserMarketDetails
|
|
209
|
-
currentBorrowLimit: CurrencyAmount
|
|
210
|
-
currentBorrowValuation: CurrencyAmount
|
|
211
|
-
action: MarketAction
|
|
212
|
-
tokenAmount?: TokenAmount
|
|
326
|
+
userMarketDetail: UserMarketDetails;
|
|
327
|
+
currentBorrowLimit: CurrencyAmount;
|
|
328
|
+
currentBorrowValuation: CurrencyAmount;
|
|
329
|
+
action: MarketAction;
|
|
330
|
+
tokenAmount?: TokenAmount;
|
|
213
331
|
}): HypotheticalStats {
|
|
214
|
-
var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
|
|
332
|
+
var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
|
|
333
|
+
newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
|
|
215
334
|
switch (action) {
|
|
216
335
|
case MarketAction.EnableCollateral:
|
|
217
336
|
case MarketAction.DisableCollateral:
|
|
218
|
-
var deltaBorrowLimit = calcValuation(
|
|
219
|
-
|
|
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);
|
|
220
347
|
break;
|
|
221
348
|
|
|
222
349
|
case MarketAction.Deposit:
|
|
223
350
|
case MarketAction.Withdraw:
|
|
224
|
-
deltaBorrowLimit = calcValuation(
|
|
225
|
-
|
|
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);
|
|
226
361
|
break;
|
|
227
362
|
|
|
228
363
|
case MarketAction.Borrow:
|
|
229
364
|
case MarketAction.Repay:
|
|
230
|
-
var deltaBorrowValuation = calcValuation(
|
|
231
|
-
|
|
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);
|
|
232
373
|
break;
|
|
233
374
|
}
|
|
234
375
|
return {
|
|
235
376
|
newBorrowLimit: {
|
|
236
377
|
amount: newBorrowLimit!.toFixed(DECIMAL_PRECISION),
|
|
237
|
-
currency:
|
|
378
|
+
currency: 'USD',
|
|
238
379
|
},
|
|
239
|
-
newBorrowUtilization: newBorrowLimit.eq(0)
|
|
240
|
-
|
|
241
|
-
|
|
380
|
+
newBorrowUtilization: newBorrowLimit.eq(0)
|
|
381
|
+
? newBorrowValuation.eq(0)
|
|
382
|
+
? 0
|
|
383
|
+
: 9999.99
|
|
384
|
+
: newBorrowValuation!.div(newBorrowLimit!).toNumber(),
|
|
385
|
+
};
|
|
242
386
|
}
|
|
243
387
|
}
|
|
244
388
|
|
|
245
389
|
export class SdkReadWrite extends SdkRead {
|
|
390
|
+
/**
|
|
391
|
+
* Claim PLY reward in all markets + staking pools
|
|
392
|
+
*/
|
|
246
393
|
public async claim(): Promise<TransactionResponse> {
|
|
247
|
-
return this._auriLens
|
|
248
|
-
this.
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
394
|
+
return this._auriLens
|
|
395
|
+
.connect(this._networkConnection.signer!)
|
|
396
|
+
.claimRewards(
|
|
397
|
+
this._comptroller.address,
|
|
398
|
+
this._auriFairLaunch.address,
|
|
399
|
+
ALL_STAKING_POOLS
|
|
400
|
+
);
|
|
252
401
|
}
|
|
402
|
+
|
|
253
403
|
public async stake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
254
|
-
return this._auriFairLaunch
|
|
404
|
+
return this._auriFairLaunch
|
|
405
|
+
.connect(this._networkConnection.signer!)
|
|
406
|
+
.deposit(PlyUsdcPid, amount.rawAmount());
|
|
255
407
|
}
|
|
408
|
+
|
|
256
409
|
public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
257
|
-
return this._auriFairLaunch
|
|
410
|
+
return this._auriFairLaunch
|
|
411
|
+
.connect(this._networkConnection.signer!)
|
|
412
|
+
.withdraw(PlyUsdcPid, amount.rawAmount());
|
|
258
413
|
}
|
|
414
|
+
|
|
259
415
|
public async faucetDrip(): Promise<TransactionResponse> {
|
|
260
|
-
const faucet = new Contract(
|
|
416
|
+
const faucet = new Contract(
|
|
417
|
+
networkAddresses.misc.FAUCET,
|
|
418
|
+
FaucetABI.abi,
|
|
419
|
+
this._networkConnection.provider
|
|
420
|
+
);
|
|
261
421
|
return faucet.connect(this._networkConnection.signer!).drip();
|
|
262
422
|
}
|
|
263
423
|
}
|