@aurigami/sdk 1.23.1 → 1.24.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/SDK.d.ts +48 -65
- package/dist/SDK.js +165 -0
- package/dist/abis/index.d.ts +18 -18
- package/dist/abis/index.js +39 -0
- package/dist/consts/constants.d.ts +139 -139
- package/dist/consts/constants.js +185 -0
- package/dist/consts/decimals.d.ts +1 -1
- package/dist/consts/decimals.js +35 -0
- package/dist/consts/deployments.d.ts +3 -3
- package/dist/consts/deployments.js +9 -0
- package/dist/consts/dummy.d.ts +13 -13
- package/dist/consts/dummy.js +43 -0
- package/dist/consts/index.d.ts +5 -5
- package/dist/consts/index.js +9 -0
- package/dist/consts/symbols.d.ts +1 -1
- package/dist/consts/symbols.js +10 -0
- package/dist/entities/BlockchainEntity.d.ts +13 -13
- package/dist/entities/BlockchainEntity.js +36 -0
- package/dist/entities/auriEnv.d.ts +34 -40
- package/dist/entities/auriEnv.js +166 -0
- package/dist/entities/index.d.ts +4 -4
- package/dist/entities/index.js +8 -0
- package/dist/entities/token.d.ts +7 -7
- package/dist/entities/token.js +27 -0
- package/dist/entities/tokenAmount.d.ts +13 -13
- package/dist/entities/tokenAmount.js +52 -0
- package/dist/helpers/aurigami-api.d.ts +13 -13
- package/dist/helpers/aurigami-api.js +26 -0
- package/dist/helpers/aurora-api-helpers.d.ts +1 -1
- package/dist/helpers/aurora-api-helpers.js +15 -0
- package/dist/helpers/graphql-helpers.d.ts +1 -1
- package/dist/helpers/graphql-helpers.js +13 -0
- package/dist/helpers/helpers.d.ts +23 -40
- package/dist/helpers/helpers.js +148 -0
- package/dist/helpers/historicalPriceFetcher.d.ts +15 -15
- package/dist/helpers/historicalPriceFetcher.js +142 -0
- package/dist/helpers/index.d.ts +7 -7
- package/dist/helpers/index.js +11 -0
- package/dist/helpers/kyber-aggregator-api.d.ts +5 -5
- package/dist/helpers/kyber-aggregator-api.js +27 -0
- package/dist/helpers/multicall.d.ts +40 -0
- package/dist/helpers/multicall.js +203 -0
- package/dist/helpers/notification-api.d.ts +2 -2
- package/dist/helpers/notification-api.js +21 -0
- package/dist/helpers/one-inch-aggregator-api.d.ts +21 -21
- package/dist/helpers/one-inch-aggregator-api.js +19 -0
- package/dist/helpers/priceFetcher.d.ts +36 -36
- package/dist/helpers/priceFetcher.js +292 -0
- package/dist/helpers/subgraphQuery.d.ts +1 -1
- package/dist/helpers/subgraphQuery.js +22 -0
- package/dist/helpers/transfer-event-query.d.ts +17 -26
- package/dist/helpers/transfer-event-query.js +41 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +17 -8
- package/dist/interactors/Airdrop.d.ts +17 -26
- package/dist/interactors/Airdrop.js +48 -0
- package/dist/interactors/MoneyMarket.d.ts +63 -63
- package/dist/interactors/MoneyMarket.js +392 -0
- package/dist/interactors/Multicall.d.ts +15 -18
- package/dist/interactors/Multicall.js +36 -0
- package/dist/interactors/Papermill.d.ts +27 -57
- package/dist/interactors/Papermill.js +125 -0
- package/dist/interactors/PlyGame.d.ts +30 -42
- package/dist/interactors/PlyGame.js +146 -0
- package/dist/interactors/PlyTokenLock.d.ts +16 -16
- package/dist/interactors/PlyTokenLock.js +44 -0
- package/dist/interactors/Pulp.d.ts +17 -17
- package/dist/interactors/Pulp.js +43 -0
- package/dist/interactors/Referral.d.ts +35 -78
- package/dist/interactors/Referral.js +158 -0
- package/dist/interactors/Staking.d.ts +20 -26
- package/dist/interactors/Staking.js +106 -0
- package/dist/interactors/index.d.ts +9 -9
- package/dist/interactors/index.js +13 -0
- package/dist/interactors/misc.d.ts +31 -39
- package/dist/interactors/misc.js +318 -0
- package/dist/types/index.d.ts +175 -197
- package/dist/types/index.js +18 -0
- package/package.json +4 -16
- package/dist/sdk.cjs.development.js +0 -6325
- package/dist/sdk.cjs.development.js.map +0 -1
- package/dist/sdk.cjs.production.min.js +0 -2
- package/dist/sdk.cjs.production.min.js.map +0 -1
- package/dist/sdk.esm.js +0 -6193
- package/dist/sdk.esm.js.map +0 -1
- package/src/SDK.ts +0 -223
- package/src/abis/index.ts +0 -38
- package/src/consts/constants.ts +0 -210
- package/src/consts/decimals.ts +0 -31
- package/src/consts/deployments.ts +0 -4
- package/src/consts/dummy.ts +0 -51
- package/src/consts/index.ts +0 -5
- package/src/consts/symbols.ts +0 -9
- package/src/entities/BlockchainEntity.ts +0 -29
- package/src/entities/auriEnv.ts +0 -178
- package/src/entities/index.ts +0 -4
- package/src/entities/token.ts +0 -21
- package/src/entities/tokenAmount.ts +0 -48
- package/src/helpers/aurigami-api.ts +0 -42
- package/src/helpers/aurora-api-helpers.ts +0 -17
- package/src/helpers/graphql-helpers.ts +0 -8
- package/src/helpers/helpers.ts +0 -212
- package/src/helpers/historicalPriceFetcher.ts +0 -203
- package/src/helpers/index.ts +0 -7
- package/src/helpers/kyber-aggregator-api.ts +0 -37
- package/src/helpers/notification-api.ts +0 -22
- package/src/helpers/one-inch-aggregator-api.ts +0 -45
- package/src/helpers/priceFetcher.ts +0 -389
- package/src/helpers/subgraphQuery.ts +0 -17
- package/src/helpers/transfer-event-query.ts +0 -68
- package/src/index.ts +0 -14
- package/src/interactors/Airdrop.ts +0 -72
- package/src/interactors/MoneyMarket.ts +0 -482
- package/src/interactors/Multicall.ts +0 -50
- package/src/interactors/Papermill.ts +0 -185
- package/src/interactors/PlyGame.ts +0 -172
- package/src/interactors/PlyTokenLock.ts +0 -47
- package/src/interactors/Pulp.ts +0 -39
- package/src/interactors/Referral.ts +0 -214
- package/src/interactors/Staking.ts +0 -152
- package/src/interactors/index.ts +0 -9
- package/src/interactors/misc.ts +0 -431
- package/src/types/index.ts +0 -222
package/src/interactors/misc.ts
DELETED
|
@@ -1,431 +0,0 @@
|
|
|
1
|
-
import { AuToken } from '@aurigami/contracts/typechain';
|
|
2
|
-
import BigNumber from 'bignumber.js';
|
|
3
|
-
import { BigNumber as BN } from 'ethers';
|
|
4
|
-
import * as abis from '../abis';
|
|
5
|
-
import * as consts from '../consts';
|
|
6
|
-
import { AuriEnv, BlockchainEntityRead, PLYToken, Token, TokenAmount } from '../entities';
|
|
7
|
-
import { decimalFactor, getDecimal, getSymbol, isSameAddress } from '../helpers/helpers';
|
|
8
|
-
import { calcValuation, fetchPrice } from '../helpers/priceFetcher';
|
|
9
|
-
import * as types from '../types';
|
|
10
|
-
import { MoneyMarketRead } from './MoneyMarket';
|
|
11
|
-
import { MulticallRead } from './Multicall';
|
|
12
|
-
import { StakingRead } from './Staking';
|
|
13
|
-
|
|
14
|
-
export class MiscRead extends BlockchainEntityRead {
|
|
15
|
-
public readonly env: AuriEnv;
|
|
16
|
-
public readonly stakingRead: StakingRead;
|
|
17
|
-
constructor(networkConnection: types.NetworkConnection) {
|
|
18
|
-
super(networkConnection);
|
|
19
|
-
this.stakingRead = new StakingRead(networkConnection);
|
|
20
|
-
this.env = new AuriEnv(networkConnection);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public async getUserDetails(userAddress: string): Promise<types.UserDetails> {
|
|
24
|
-
const marketCount = consts.networkAddresses.auTokens.length;
|
|
25
|
-
var userMarketDetails: types.UserMarketDetails[] = [],
|
|
26
|
-
assetsIn: string[];
|
|
27
|
-
var totalBorrowLimit = new BigNumber(0);
|
|
28
|
-
for (const auToken of consts.networkAddresses.auTokens) {
|
|
29
|
-
const userMarketDetail: types.UserMarketDetails = {} as types.UserMarketDetails;
|
|
30
|
-
userMarketDetails.push(userMarketDetail);
|
|
31
|
-
userMarketDetail.market = auToken.underlying;
|
|
32
|
-
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
33
|
-
this._networkConnection,
|
|
34
|
-
auToken.address,
|
|
35
|
-
auToken.underlying
|
|
36
|
-
);
|
|
37
|
-
const [depositBalance, borrowBalance, collateralRatio, underlyingPrice] = await Promise.all([
|
|
38
|
-
moneyMarket.getUserDepositBalance(userAddress),
|
|
39
|
-
moneyMarket.getUserBorrowBalance(userAddress),
|
|
40
|
-
moneyMarket.getCollateralRatio(),
|
|
41
|
-
fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider),
|
|
42
|
-
]);
|
|
43
|
-
|
|
44
|
-
userMarketDetail.depositBalance = depositBalance;
|
|
45
|
-
userMarketDetail.borrowBalance = borrowBalance;
|
|
46
|
-
userMarketDetail.collateralRatio = collateralRatio.toNumber();
|
|
47
|
-
userMarketDetail.underlyingPrice = underlyingPrice.toString();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
assetsIn = await this.env.comptroller.getAssetsIn(userAddress);
|
|
51
|
-
|
|
52
|
-
var depositValues = [];
|
|
53
|
-
for (var i = 0; i < marketCount; i++) {
|
|
54
|
-
const auToken = consts.networkAddresses.auTokens[i];
|
|
55
|
-
if (
|
|
56
|
-
assetsIn!.find((auAddress: types.Address) => isSameAddress(auToken.address, auAddress)) !==
|
|
57
|
-
undefined
|
|
58
|
-
) {
|
|
59
|
-
userMarketDetails[i].isCollateral = true;
|
|
60
|
-
} else {
|
|
61
|
-
userMarketDetails[i].isCollateral = false;
|
|
62
|
-
}
|
|
63
|
-
depositValues.push(
|
|
64
|
-
calcValuation(
|
|
65
|
-
userMarketDetails[i].depositBalance,
|
|
66
|
-
new BigNumber(userMarketDetails[i].underlyingPrice)
|
|
67
|
-
)
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
totalBorrowLimit = depositValues.reduce((p: BigNumber, v: BigNumber, index: number) => {
|
|
72
|
-
if (userMarketDetails[index].isCollateral)
|
|
73
|
-
return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
|
|
74
|
-
return p;
|
|
75
|
-
}, new BigNumber(0));
|
|
76
|
-
|
|
77
|
-
var accountLiquidity: [BN, BN] = await this.env.comptroller.getAccountLiquidity(userAddress);
|
|
78
|
-
|
|
79
|
-
var borrowedvaluation: BigNumber = totalBorrowLimit.minus(
|
|
80
|
-
new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18))
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
if (borrowedvaluation.lt('0.00001')) {
|
|
84
|
-
// Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
|
|
85
|
-
borrowedvaluation = new BigNumber(0);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const bufferedBorrowLimit: BigNumber = totalBorrowLimit.multipliedBy(
|
|
89
|
-
consts.BORROW_LIMIT_BUFFER
|
|
90
|
-
);
|
|
91
|
-
const minimumBorrowLimitAllowed = borrowedvaluation.div(consts.BORROW_LIMIT_BUFFER);
|
|
92
|
-
|
|
93
|
-
var borrowableAmount: BigNumber;
|
|
94
|
-
if (bufferedBorrowLimit.lte(borrowedvaluation)) {
|
|
95
|
-
borrowableAmount = new BigNumber(0);
|
|
96
|
-
} else {
|
|
97
|
-
borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
for (var i = 0; i < marketCount; i++) {
|
|
101
|
-
const auToken = consts.networkAddresses.auTokens[i];
|
|
102
|
-
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
103
|
-
this._networkConnection,
|
|
104
|
-
auToken.address,
|
|
105
|
-
auToken.underlying
|
|
106
|
-
);
|
|
107
|
-
const borrowLimitMargin = totalBorrowLimit.minus(minimumBorrowLimitAllowed).gt(0)
|
|
108
|
-
? totalBorrowLimit.minus(minimumBorrowLimitAllowed)
|
|
109
|
-
: new BigNumber(0);
|
|
110
|
-
const maxWithdrawCap: BigNumber = borrowLimitMargin
|
|
111
|
-
.div(userMarketDetails[i].collateralRatio)
|
|
112
|
-
.div(userMarketDetails[i].underlyingPrice);
|
|
113
|
-
userMarketDetails[i].maxWithdrawableAmount =
|
|
114
|
-
userMarketDetails[i].isCollateral &&
|
|
115
|
-
maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
|
|
116
|
-
? new TokenAmount(moneyMarket.underlying, maxWithdrawCap.toFixed(24), false)
|
|
117
|
-
: new TokenAmount(
|
|
118
|
-
moneyMarket.underlying,
|
|
119
|
-
userMarketDetails[i].depositBalance.rawAmount()
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
markets: userMarketDetails,
|
|
125
|
-
borrowLimit: {
|
|
126
|
-
currency: 'USD',
|
|
127
|
-
amount: bufferedBorrowLimit.toFixed(consts.DECIMAL_PRECISION),
|
|
128
|
-
},
|
|
129
|
-
borrowableAmount: {
|
|
130
|
-
currency: 'USD',
|
|
131
|
-
amount: borrowableAmount.toFixed(consts.DECIMAL_PRECISION),
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
public async getTokenPrice(token: Token): Promise<types.CurrencyAmount> {
|
|
137
|
-
const price = await fetchPrice(token.address, this._networkConnection.provider);
|
|
138
|
-
return {
|
|
139
|
-
currency: 'USD',
|
|
140
|
-
amount: price.toFixed(consts.DECIMAL_PRECISION),
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
public async calcBorrowPower(tokenAmount: TokenAmount) {
|
|
145
|
-
const autoken = consts.networkAddresses.auTokens.find((auToken) =>
|
|
146
|
-
isSameAddress(auToken.underlying, tokenAmount.token.address)
|
|
147
|
-
)!;
|
|
148
|
-
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
149
|
-
this._networkConnection,
|
|
150
|
-
autoken.address,
|
|
151
|
-
autoken.underlying
|
|
152
|
-
);
|
|
153
|
-
const collateralRatio = await moneyMarket.getCollateralRatio();
|
|
154
|
-
const underlyingPrice = await fetchPrice(
|
|
155
|
-
tokenAmount.token.address,
|
|
156
|
-
this._networkConnection.provider
|
|
157
|
-
);
|
|
158
|
-
const borrowPower = calcValuation(tokenAmount!, new BigNumber(underlyingPrice))
|
|
159
|
-
.multipliedBy(collateralRatio)
|
|
160
|
-
.multipliedBy(consts.BORROW_LIMIT_BUFFER);
|
|
161
|
-
return {
|
|
162
|
-
currency: 'USD',
|
|
163
|
-
amount: borrowPower.toFixed(consts.DECIMAL_PRECISION),
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
public calcHypotheticalStats({
|
|
168
|
-
userMarketDetail,
|
|
169
|
-
currentBorrowLimit,
|
|
170
|
-
currentBorrowValuation,
|
|
171
|
-
action,
|
|
172
|
-
tokenAmount,
|
|
173
|
-
}: {
|
|
174
|
-
userMarketDetail: types.UserMarketDetails;
|
|
175
|
-
currentBorrowLimit: types.CurrencyAmount;
|
|
176
|
-
currentBorrowValuation: types.CurrencyAmount;
|
|
177
|
-
action: types.MarketAction;
|
|
178
|
-
tokenAmount?: TokenAmount;
|
|
179
|
-
}): types.HypotheticalStats {
|
|
180
|
-
var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
|
|
181
|
-
newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
|
|
182
|
-
switch (action) {
|
|
183
|
-
case types.MarketAction.EnableCollateral:
|
|
184
|
-
case types.MarketAction.DisableCollateral:
|
|
185
|
-
var deltaBorrowLimit = calcValuation(
|
|
186
|
-
userMarketDetail.depositBalance,
|
|
187
|
-
new BigNumber(userMarketDetail.underlyingPrice)
|
|
188
|
-
)
|
|
189
|
-
.multipliedBy(userMarketDetail.collateralRatio)
|
|
190
|
-
.multipliedBy(consts.BORROW_LIMIT_BUFFER);
|
|
191
|
-
newBorrowLimit =
|
|
192
|
-
action == types.MarketAction.EnableCollateral
|
|
193
|
-
? newBorrowLimit.plus(deltaBorrowLimit)
|
|
194
|
-
: newBorrowLimit.minus(deltaBorrowLimit);
|
|
195
|
-
break;
|
|
196
|
-
|
|
197
|
-
case types.MarketAction.Deposit:
|
|
198
|
-
case types.MarketAction.Withdraw:
|
|
199
|
-
deltaBorrowLimit = calcValuation(
|
|
200
|
-
tokenAmount!,
|
|
201
|
-
new BigNumber(userMarketDetail.underlyingPrice)
|
|
202
|
-
)
|
|
203
|
-
.multipliedBy(userMarketDetail.collateralRatio)
|
|
204
|
-
.multipliedBy(consts.BORROW_LIMIT_BUFFER);
|
|
205
|
-
newBorrowLimit =
|
|
206
|
-
action == types.MarketAction.Deposit
|
|
207
|
-
? newBorrowLimit.plus(deltaBorrowLimit)
|
|
208
|
-
: newBorrowLimit.minus(deltaBorrowLimit);
|
|
209
|
-
break;
|
|
210
|
-
|
|
211
|
-
case types.MarketAction.Borrow:
|
|
212
|
-
case types.MarketAction.Repay:
|
|
213
|
-
var deltaBorrowValuation = calcValuation(
|
|
214
|
-
tokenAmount!,
|
|
215
|
-
new BigNumber(userMarketDetail.underlyingPrice)
|
|
216
|
-
);
|
|
217
|
-
newBorrowValuation =
|
|
218
|
-
action == types.MarketAction.Borrow
|
|
219
|
-
? newBorrowValuation.plus(deltaBorrowValuation)
|
|
220
|
-
: newBorrowValuation.minus(deltaBorrowValuation);
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
newBorrowLimit: {
|
|
225
|
-
amount: newBorrowLimit!.toFixed(consts.DECIMAL_PRECISION),
|
|
226
|
-
currency: 'USD',
|
|
227
|
-
},
|
|
228
|
-
newBorrowUtilization: newBorrowLimit.eq(0)
|
|
229
|
-
? newBorrowValuation.eq(0)
|
|
230
|
-
? 0
|
|
231
|
-
: 9999.99
|
|
232
|
-
: newBorrowValuation!.div(newBorrowLimit!).toNumber(),
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Get ply circulating supply.
|
|
238
|
-
* It is calculated by the total supply, minus:
|
|
239
|
-
* - Ply in team multisig contract
|
|
240
|
-
* - Ply in comptroller contract
|
|
241
|
-
* - Ply in fairlaunch contract
|
|
242
|
-
* - Ply in vesting contract
|
|
243
|
-
*/
|
|
244
|
-
public async getPlyCirculatingSupply(): Promise<TokenAmount> {
|
|
245
|
-
const multicallRead = new MulticallRead(this._networkConnection);
|
|
246
|
-
const baseBalanceOfCall = {
|
|
247
|
-
contract: this.env.ply,
|
|
248
|
-
method: 'balanceOf',
|
|
249
|
-
returnTypes: ['uint256'],
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
const listAddrs = [
|
|
253
|
-
consts.networkAddresses.misc.TEAM_MULTISIG,
|
|
254
|
-
consts.networkAddresses.misc.COMPTROLLER,
|
|
255
|
-
consts.networkAddresses.misc.AURIFAIRLAUNCH,
|
|
256
|
-
consts.networkAddresses.misc.PLY_TOKEN_LOCK,
|
|
257
|
-
consts.networkAddresses.misc.TEAM_MULTISIG_AURORA_PLUS,
|
|
258
|
-
consts.networkAddresses.misc.AURORA_PLUS,
|
|
259
|
-
consts.networkAddresses.misc.PULP_CONTRACT,
|
|
260
|
-
];
|
|
261
|
-
|
|
262
|
-
const calls = listAddrs.map((addr) => ({
|
|
263
|
-
...baseBalanceOfCall,
|
|
264
|
-
args: [addr],
|
|
265
|
-
}));
|
|
266
|
-
|
|
267
|
-
const callResults = (await multicallRead.aggregate(calls)) as BN[][];
|
|
268
|
-
|
|
269
|
-
let circulatingSupply: BN = BN.from(
|
|
270
|
-
'1' + '0'.repeat(10) + '0'.repeat(getDecimal(this.env.ply.address))
|
|
271
|
-
);
|
|
272
|
-
callResults.forEach((result, i) => {
|
|
273
|
-
circulatingSupply = circulatingSupply.sub(result[0]);
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
return new TokenAmount(PLYToken, circulatingSupply.toString());
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
public async getUtilisation(userAddr: types.Address): Promise<BigNumber> {
|
|
280
|
-
let accountDetail =
|
|
281
|
-
await this.env.auriInternalLens.callStatic.getAccountLiquidityAccrueInterest(userAddr);
|
|
282
|
-
let sumBorrow = new BigNumber(accountDetail.sumBorrowPlusEffects.toString());
|
|
283
|
-
let sumCol = new BigNumber(accountDetail.sumCollateral.toString());
|
|
284
|
-
return sumBorrow.dividedBy(sumCol);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
public async sneakAccounts(
|
|
288
|
-
accounts: string[],
|
|
289
|
-
tokenAddresses: string[],
|
|
290
|
-
dust: BigNumber = new BigNumber(0.1)
|
|
291
|
-
): Promise<types.AccountAuTokensInfo[]> {
|
|
292
|
-
const _1E18 = BN.from(10).pow(18);
|
|
293
|
-
const oracle = this.env.oracle;
|
|
294
|
-
const tokens = tokenAddresses.map((addr) =>
|
|
295
|
-
this.env.getContract<AuToken>(addr, abis.AuTokenABI.abi)
|
|
296
|
-
);
|
|
297
|
-
const prices = await oracle.getUnderlyingPrices(tokenAddresses);
|
|
298
|
-
const exrate = await this.env.auriInternalLens.callStatic.getExchangeRates(tokenAddresses);
|
|
299
|
-
|
|
300
|
-
const res: types.AccountAuTokensInfo[] = [];
|
|
301
|
-
|
|
302
|
-
for (let addr of accounts) {
|
|
303
|
-
const infos: types.AccountAuTokenInfo[] = [];
|
|
304
|
-
for (let i = 0; i < tokens.length; ++i) {
|
|
305
|
-
const snapshot = await tokens[i].getAccountSnapshot(addr);
|
|
306
|
-
const bal = snapshot[0].mul(exrate[i]).div(_1E18).mul(prices[i]).div(_1E18);
|
|
307
|
-
const bor = snapshot[1].mul(prices[i]).div(_1E18);
|
|
308
|
-
|
|
309
|
-
let balR = new BigNumber(bal.toString()).dividedBy(_1E18.toString());
|
|
310
|
-
let borR = new BigNumber(bor.toString()).dividedBy(_1E18.toString());
|
|
311
|
-
|
|
312
|
-
if (balR.lte(dust) && borR.lte(dust)) continue;
|
|
313
|
-
|
|
314
|
-
infos.push({
|
|
315
|
-
token: getSymbol(tokenAddresses[i]),
|
|
316
|
-
deposit: balR,
|
|
317
|
-
borrow: borR,
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
res.push({
|
|
321
|
-
address: addr,
|
|
322
|
-
tokens: infos,
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
return res;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
public async getLTVAndLiquidationThreshold(userAddr: types.Address) {
|
|
329
|
-
let totalSuppliedValue = new BigNumber(0);
|
|
330
|
-
let totalBorrowedValue = new BigNumber(0);
|
|
331
|
-
let collateralValue = new BigNumber(0);
|
|
332
|
-
const assetsIn = await this.env.comptroller.getAssetsIn(userAddr);
|
|
333
|
-
const marketValues = await Promise.all(
|
|
334
|
-
consts.networkAddresses.auTokens.map(async (auToken) => {
|
|
335
|
-
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
336
|
-
this._networkConnection,
|
|
337
|
-
auToken.address,
|
|
338
|
-
auToken.underlying
|
|
339
|
-
);
|
|
340
|
-
return Promise.all([
|
|
341
|
-
moneyMarket.getCollateralRatio(),
|
|
342
|
-
moneyMarket.getDepositBorrowValue(userAddr),
|
|
343
|
-
]);
|
|
344
|
-
})
|
|
345
|
-
);
|
|
346
|
-
consts.networkAddresses.auTokens.forEach(async (auToken, i) => {});
|
|
347
|
-
for (var i = 0; i < marketValues.length; i++) {
|
|
348
|
-
const auToken = consts.networkAddresses.auTokens[i];
|
|
349
|
-
const [collateralRatio, depositBorrowValue] = marketValues[i];
|
|
350
|
-
if (
|
|
351
|
-
assetsIn!.find((auAddress: types.Address) => isSameAddress(auToken.address, auAddress)) !==
|
|
352
|
-
undefined
|
|
353
|
-
) {
|
|
354
|
-
totalSuppliedValue = totalSuppliedValue.plus(depositBorrowValue.suppliedValue);
|
|
355
|
-
collateralValue = collateralValue.plus(
|
|
356
|
-
depositBorrowValue.suppliedValue.times(collateralRatio)
|
|
357
|
-
);
|
|
358
|
-
}
|
|
359
|
-
totalBorrowedValue = totalBorrowedValue.plus(depositBorrowValue.borrowedValue);
|
|
360
|
-
}
|
|
361
|
-
const ltv = totalBorrowedValue.div(totalSuppliedValue);
|
|
362
|
-
const liquidationThreshold = collateralValue.div(totalSuppliedValue);
|
|
363
|
-
return {
|
|
364
|
-
ltv,
|
|
365
|
-
liquidationThreshold,
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
public async getNetApyWithoutIncentive(userAddress: types.Address): Promise<BigNumber> {
|
|
370
|
-
let sum = new BigNumber(0);
|
|
371
|
-
let totalSuppliedValue = new BigNumber(0);
|
|
372
|
-
let totalBorrowedValue = new BigNumber(0);
|
|
373
|
-
let netApy = new BigNumber(0);
|
|
374
|
-
|
|
375
|
-
const apys = await Promise.all(
|
|
376
|
-
consts.networkAddresses.auTokens.map((auToken) => {
|
|
377
|
-
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
378
|
-
this._networkConnection,
|
|
379
|
-
auToken.address,
|
|
380
|
-
auToken.underlying
|
|
381
|
-
);
|
|
382
|
-
const apyWithoutIncentive = moneyMarket.getApyWithoutIncentive(userAddress);
|
|
383
|
-
return apyWithoutIncentive;
|
|
384
|
-
})
|
|
385
|
-
);
|
|
386
|
-
|
|
387
|
-
for (const apy of apys) {
|
|
388
|
-
sum = sum.plus(apy.sum);
|
|
389
|
-
totalSuppliedValue = totalSuppliedValue.plus(apy.suppliedValue);
|
|
390
|
-
totalBorrowedValue = totalBorrowedValue.plus(apy.borrowedValue);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
if (sum.gt(0)) {
|
|
394
|
-
netApy = sum.div(totalSuppliedValue);
|
|
395
|
-
} else if (sum.lt(0)) {
|
|
396
|
-
netApy = sum.div(totalBorrowedValue);
|
|
397
|
-
}
|
|
398
|
-
return netApy;
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
public async getNetApyWithIncentive(userAddress: types.Address): Promise<BigNumber> {
|
|
402
|
-
let sum = new BigNumber(0);
|
|
403
|
-
let totalSuppliedValue = new BigNumber(0);
|
|
404
|
-
let totalBorrowedValue = new BigNumber(0);
|
|
405
|
-
let netApy = new BigNumber(0);
|
|
406
|
-
const apys = await Promise.all(
|
|
407
|
-
consts.networkAddresses.auTokens.map((auToken) => {
|
|
408
|
-
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
409
|
-
this._networkConnection,
|
|
410
|
-
auToken.address,
|
|
411
|
-
auToken.underlying
|
|
412
|
-
);
|
|
413
|
-
const apyWithIncentive = moneyMarket.getApyWithIncentive(userAddress);
|
|
414
|
-
return apyWithIncentive;
|
|
415
|
-
})
|
|
416
|
-
);
|
|
417
|
-
|
|
418
|
-
for (const apy of apys) {
|
|
419
|
-
sum = sum.plus(apy.sum);
|
|
420
|
-
totalSuppliedValue = totalSuppliedValue.plus(apy.suppliedValue);
|
|
421
|
-
totalBorrowedValue = totalBorrowedValue.plus(apy.borrowedValue);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
if (sum.gt(0)) {
|
|
425
|
-
netApy = sum.div(totalSuppliedValue);
|
|
426
|
-
} else if (sum.lt(0)) {
|
|
427
|
-
netApy = sum.div(totalBorrowedValue);
|
|
428
|
-
}
|
|
429
|
-
return netApy;
|
|
430
|
-
}
|
|
431
|
-
}
|
package/src/types/index.ts
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import { AuToken } from '@aurigami/contracts/typechain';
|
|
2
|
-
import { TypedEvent } from '@aurigami/contracts/typechain/common';
|
|
3
|
-
import BigNumber from 'bignumber.js';
|
|
4
|
-
import type { providers, Signer } from 'ethers';
|
|
5
|
-
import { BigNumber as BN } from 'ethers';
|
|
6
|
-
import { TokenAmount } from '../entities/tokenAmount';
|
|
7
|
-
|
|
8
|
-
export enum ComptrollerRewardType {
|
|
9
|
-
PLY = 0,
|
|
10
|
-
AURORA,
|
|
11
|
-
}
|
|
12
|
-
export type NetworkConnection = {
|
|
13
|
-
provider: providers.Provider;
|
|
14
|
-
signer?: Signer;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export type Address = string;
|
|
18
|
-
|
|
19
|
-
export type CurrencyAmount = {
|
|
20
|
-
currency: string;
|
|
21
|
-
amount: string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export type TokenValuation = {
|
|
25
|
-
tokenAmount: TokenAmount;
|
|
26
|
-
currencyAmount: CurrencyAmount;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type MoneyMarketDetails = {
|
|
30
|
-
auTokenAddress: string;
|
|
31
|
-
totalTokenDeposited: TokenAmount;
|
|
32
|
-
totalTokenBorrowed: TokenAmount;
|
|
33
|
-
depositApy: number;
|
|
34
|
-
depositPlyApy: number;
|
|
35
|
-
borrowApy: number;
|
|
36
|
-
borrowPlyApy: number;
|
|
37
|
-
collateralRatio: number;
|
|
38
|
-
depositPlyPerWeek: TokenAmount;
|
|
39
|
-
borrowPlyPerWeek: TokenAmount;
|
|
40
|
-
depositMETAApy: number;
|
|
41
|
-
depositNEARApy: number;
|
|
42
|
-
borrowNEARApy: number;
|
|
43
|
-
staderDepositApy: number;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export type UserDetails = {
|
|
47
|
-
markets: UserMarketDetails[];
|
|
48
|
-
borrowLimit: CurrencyAmount;
|
|
49
|
-
borrowableAmount: CurrencyAmount;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export type UserLockingDetails = {
|
|
53
|
-
vestingStart: number;
|
|
54
|
-
/** % of reward they will receive in PLY, if they claim this week */
|
|
55
|
-
currentUnlockPortion: number;
|
|
56
|
-
//** Amount of PLY rewards that a user has. Equal to currentPly + currentPulp */
|
|
57
|
-
accruedPly: TokenAmount;
|
|
58
|
-
/** Amount of PLY they will receive, if they claim this week */
|
|
59
|
-
currentPly: TokenAmount;
|
|
60
|
-
/** Amount of PULP they will receive, if they claim this week */
|
|
61
|
-
currentPulp: TokenAmount;
|
|
62
|
-
/** % of reward they will receive in PLY, if they claim next week */
|
|
63
|
-
nextUnlockPortion: number;
|
|
64
|
-
/**
|
|
65
|
-
* Amount of PLY they will receive, if they claim next week.
|
|
66
|
-
* This doesn't include the additional reward that they will earn
|
|
67
|
-
* in the next week.
|
|
68
|
-
*/
|
|
69
|
-
nextPly: TokenAmount;
|
|
70
|
-
/**
|
|
71
|
-
* Amount of PULP they will receive, if they claim next week.
|
|
72
|
-
* This doesn't include the additional reward that they will earn
|
|
73
|
-
* in the next week.
|
|
74
|
-
*/
|
|
75
|
-
nextPulp: TokenAmount;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export type UserMarketDetails = {
|
|
79
|
-
market: string;
|
|
80
|
-
depositBalance: TokenAmount;
|
|
81
|
-
borrowBalance: TokenAmount;
|
|
82
|
-
isCollateral: boolean;
|
|
83
|
-
maxWithdrawableAmount: TokenAmount;
|
|
84
|
-
collateralRatio: number;
|
|
85
|
-
underlyingPrice: string;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export type TokenAPY = {
|
|
89
|
-
address: string;
|
|
90
|
-
apy: string;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export type PLYWNEARPoolDetails = {
|
|
94
|
-
totalStakedLiquidity: TokenAmount;
|
|
95
|
-
APYs: TokenAPY[];
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export enum MarketAction {
|
|
99
|
-
Deposit = 0,
|
|
100
|
-
Borrow,
|
|
101
|
-
Withdraw,
|
|
102
|
-
Repay,
|
|
103
|
-
EnableCollateral,
|
|
104
|
-
DisableCollateral,
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export type HypotheticalStats = {
|
|
108
|
-
newBorrowLimit: CurrencyAmount;
|
|
109
|
-
newBorrowUtilization: number;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export type AccountAuTokenInfo = {
|
|
113
|
-
token: string;
|
|
114
|
-
deposit: BigNumber;
|
|
115
|
-
borrow: BigNumber;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export type AccountAuTokensInfo = {
|
|
119
|
-
address: string;
|
|
120
|
-
tokens: AccountAuTokenInfo[];
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
export type AuTokenWithUnderlying = AuToken & {
|
|
124
|
-
underlying: string;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
export type ReferralReward = {
|
|
128
|
-
campaign: string;
|
|
129
|
-
/**
|
|
130
|
-
* Truncated user address.
|
|
131
|
-
*/
|
|
132
|
-
userAddr: string;
|
|
133
|
-
/**
|
|
134
|
-
* start timetamp of the referral round
|
|
135
|
-
*/
|
|
136
|
-
startTime: number;
|
|
137
|
-
/**
|
|
138
|
-
* end timetamp of the referral round
|
|
139
|
-
*/
|
|
140
|
-
endTime: number;
|
|
141
|
-
/**
|
|
142
|
-
* referrer's rewards
|
|
143
|
-
*/
|
|
144
|
-
isReferrer: boolean;
|
|
145
|
-
/**
|
|
146
|
-
* reward amount
|
|
147
|
-
*/
|
|
148
|
-
rewardTokenAmount: TokenAmount;
|
|
149
|
-
/**
|
|
150
|
-
* hash of the transaction on aurorascan (if no, return null)
|
|
151
|
-
*/
|
|
152
|
-
transactionHash: string | null;
|
|
153
|
-
|
|
154
|
-
refereeAddress: string | null;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export type PlyGameBetResult = {
|
|
158
|
-
player: string;
|
|
159
|
-
/**
|
|
160
|
-
* Bet outcome result
|
|
161
|
-
*/
|
|
162
|
-
outcome: string;
|
|
163
|
-
/**
|
|
164
|
-
* ply lost amount
|
|
165
|
-
*/
|
|
166
|
-
lostAmount: TokenAmount;
|
|
167
|
-
unlockedPulpAmount: TokenAmount;
|
|
168
|
-
|
|
169
|
-
block: number;
|
|
170
|
-
timestamp: number;
|
|
171
|
-
/**
|
|
172
|
-
* hash of the transaction on aurorascan (if no, return null)
|
|
173
|
-
*/
|
|
174
|
-
transactionHash: string;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
export type PlyGameLeaderboardItem = {
|
|
178
|
-
player: string;
|
|
179
|
-
gamesPlayed: number;
|
|
180
|
-
unlockedPulpAmount: TokenAmount;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
export type PlyBetMadeEvent = TypedEvent<
|
|
184
|
-
[string, BN, number] & { player: string; amount: BN; outcome: number }
|
|
185
|
-
>;
|
|
186
|
-
|
|
187
|
-
export type Apy = {
|
|
188
|
-
sum: BigNumber;
|
|
189
|
-
suppliedValue: BigNumber;
|
|
190
|
-
borrowedValue: BigNumber;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
export type UserNotification = {
|
|
194
|
-
message: string;
|
|
195
|
-
userSetting: {
|
|
196
|
-
address: Address;
|
|
197
|
-
mail: string;
|
|
198
|
-
utilisation: number;
|
|
199
|
-
liquidation: boolean;
|
|
200
|
-
}[];
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
export type LiquidationEventEntity = {
|
|
204
|
-
liquidator: string;
|
|
205
|
-
borrower: string;
|
|
206
|
-
/** bigint string */
|
|
207
|
-
repayAmount: string;
|
|
208
|
-
marketRepayToken: string;
|
|
209
|
-
/** bigint string */
|
|
210
|
-
seizeTokens: string;
|
|
211
|
-
auTokenCollateral: string;
|
|
212
|
-
txnHash: string;
|
|
213
|
-
blockNumber: number;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
export type LiquidationDetail = {
|
|
217
|
-
liquidationTime: Timestamp;
|
|
218
|
-
tokenAmount: TokenAmount;
|
|
219
|
-
transactionId: string;
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
export type Timestamp = number;
|