@aurigami/sdk 1.6.4 → 1.6.5

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.
Files changed (55) hide show
  1. package/ChangeLog.md +159 -0
  2. package/dist/SDK.d.ts +4 -7
  3. package/dist/abis/index.d.ts +14 -0
  4. package/dist/consts/constants.d.ts +2 -2
  5. package/dist/consts/dummy.d.ts +1 -2
  6. package/dist/contracts/{airdrop-lottery.d.ts → Airdrop.d.ts} +0 -5
  7. package/dist/contracts/MoneyMarket.d.ts +3 -4
  8. package/dist/contracts/Multicall.d.ts +1 -1
  9. package/dist/contracts/Papermill.d.ts +2 -7
  10. package/dist/contracts/Staking.d.ts +2 -5
  11. package/dist/contracts/index.d.ts +2 -1
  12. package/dist/contracts/misc.d.ts +26 -0
  13. package/dist/entities/auriEnv.d.ts +13 -0
  14. package/dist/entities/index.d.ts +1 -0
  15. package/dist/entities/tokenAmount.d.ts +1 -1
  16. package/dist/helpers/priceFetcher.d.ts +1 -1
  17. package/dist/helpers/transfer-event-query.d.ts +2 -2
  18. package/dist/index.d.ts +1 -1
  19. package/dist/sdk.cjs.development.js +579 -104416
  20. package/dist/sdk.cjs.development.js.map +1 -1
  21. package/dist/sdk.cjs.production.min.js +1 -1
  22. package/dist/sdk.cjs.production.min.js.map +1 -1
  23. package/dist/sdk.esm.js +582 -104421
  24. package/dist/sdk.esm.js.map +1 -1
  25. package/package.json +7 -6
  26. package/src/SDK.ts +23 -330
  27. package/src/abis/index.ts +30 -0
  28. package/src/consts/constants.ts +15 -16
  29. package/src/consts/dummy.ts +4 -14
  30. package/src/contracts/Airdrop.ts +80 -0
  31. package/src/contracts/MoneyMarket.ts +56 -160
  32. package/src/contracts/Multicall.ts +5 -10
  33. package/src/contracts/Papermill.ts +32 -113
  34. package/src/contracts/Referral.ts +4 -7
  35. package/src/contracts/Staking.ts +18 -59
  36. package/src/contracts/index.ts +2 -1
  37. package/src/contracts/misc.ts +281 -0
  38. package/src/entities/BlockchainEntity.ts +2 -6
  39. package/src/entities/auriEnv.ts +39 -0
  40. package/src/entities/index.ts +1 -0
  41. package/src/entities/token.ts +1 -1
  42. package/src/entities/tokenAmount.ts +4 -12
  43. package/src/helpers/aurora-api-helpers.ts +3 -6
  44. package/src/helpers/helpers.ts +5 -17
  45. package/src/helpers/priceFetcher.ts +21 -62
  46. package/src/helpers/transfer-event-query.ts +4 -6
  47. package/src/index.ts +1 -1
  48. package/src/types/index.ts +1 -1
  49. package/src/abis/Faucet.json +0 -157
  50. package/src/abis/IUniswapV2Pair.json +0 -663
  51. package/src/abis/Oracle.json +0 -247
  52. package/src/abis/dummy.json +0 -3
  53. package/src/contracts/airdrop-lottery.ts +0 -320
  54. package/src/misc/airdrop_misc/auTokensInfo.json +0 -34
  55. package/src/misc/airdrop_misc/whitelist.json +0 -102629
@@ -1,7 +1,7 @@
1
- import ReferralDirectoryABI from '@aurigami/contracts/artifacts/contracts/ReferralDirectory.sol/ReferralDirectory.json';
2
1
  import { ReferralDirectory } from '@aurigami/contracts/typechain';
3
2
  import { TransactionResponse } from '@ethersproject/abstract-provider';
4
3
  import { Contract, ethers } from 'ethers';
4
+ import * as abis from '../abis';
5
5
  import * as consts from '../consts';
6
6
  import { BlockchainEntity, BlockchainEntityRead } from '../entities';
7
7
  import { Address, NetworkConnection } from '../types';
@@ -12,7 +12,7 @@ export class ReferralRead extends BlockchainEntityRead {
12
12
  super(networkConnection);
13
13
  this._referral = new Contract(
14
14
  consts.networkAddresses.misc.REFERRAL,
15
- ReferralDirectoryABI.abi,
15
+ abis.ReferralDirectoryABI.abi,
16
16
  networkConnection.provider
17
17
  ) as ReferralDirectory;
18
18
  }
@@ -26,8 +26,7 @@ export class ReferralRead extends BlockchainEntityRead {
26
26
  let numbers = '1234567890';
27
27
  let charset = letters + letters.toUpperCase() + numbers;
28
28
  let R = '';
29
- for (var i = 0; i < 10; i++)
30
- R += charset[Math.floor(Math.random() * charset.length)];
29
+ for (var i = 0; i < 10; i++) R += charset[Math.floor(Math.random() * charset.length)];
31
30
  return R;
32
31
  }
33
32
 
@@ -65,9 +64,7 @@ export class ReferralReadWrite extends ReferralRead {
65
64
  * Called when an user want to creates his own referral code
66
65
  */
67
66
  public async registerNewReferralCode(): Promise<TransactionResponse> {
68
- const referralCode = ethers.utils.formatBytes32String(
69
- this.generateReferralCode()
70
- );
67
+ const referralCode = ethers.utils.formatBytes32String(this.generateReferralCode());
71
68
  return this._referral
72
69
  .connect(this._networkConnection.signer!)
73
70
  .registerNewUserReferralCode(referralCode);
@@ -1,18 +1,11 @@
1
- import AuriFairLaunchABI from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
2
- import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
3
- import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
4
- import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
5
- import {
6
- AuriFairLaunch,
7
- AuriLens,
8
- Comptroller,
9
- IERC20,
10
- } from '@aurigami/contracts/typechain';
1
+ import { IERC20 } from '@aurigami/contracts/typechain';
11
2
  import { TransactionResponse } from '@ethersproject/abstract-provider';
12
3
  import BigNumber from 'bignumber.js';
13
4
  import { BigNumber as BN, Contract } from 'ethers';
5
+ import { EIP20InterfaceABI } from '../abis';
14
6
  import * as consts from '../consts';
15
7
  import {
8
+ AuriEnv,
16
9
  BlockchainEntity,
17
10
  BlockchainEntityRead,
18
11
  PLYWNEARToken,
@@ -24,41 +17,20 @@ import { fetchValuation } from '../helpers/priceFetcher';
24
17
  import { NetworkConnection, PLYWNEARPoolDetails, TokenAPY } from '../types';
25
18
 
26
19
  export class StakingRead extends BlockchainEntityRead {
27
- protected _comptroller: Comptroller;
28
- protected _auriFairLaunch: AuriFairLaunch;
29
- protected _auriLens: AuriLens;
20
+ protected env: AuriEnv;
30
21
  constructor(networkConnection: NetworkConnection) {
31
22
  super(networkConnection);
32
- this._comptroller = new Contract(
33
- consts.networkAddresses.misc.COMPTROLLER,
34
- ComptrollerABI.abi,
35
- networkConnection.provider
36
- ) as Comptroller;
37
- this._auriFairLaunch = new Contract(
38
- consts.networkAddresses.misc.AURIFAIRLAUNCH,
39
- AuriFairLaunchABI.abi,
40
- networkConnection.provider
41
- ) as AuriFairLaunch;
42
- this._auriLens = new Contract(
43
- consts.networkAddresses.misc.AURILENS,
44
- AuriLensABI.abi,
45
- networkConnection.provider
46
- ) as AuriLens;
23
+ this.env = new AuriEnv(networkConnection);
47
24
  }
48
25
 
49
26
  public async getPLYWNEARPoolDetails(): Promise<PLYWNEARPoolDetails> {
50
27
  var stakedLiquidity: BN, rewardPerSeconds: BN[];
51
- await this._auriFairLaunch
52
- .getPoolInfo(consts.PLYWNEAR_POOL_ID)
53
- .then((res) => {
54
- stakedLiquidity = res.totalStake;
55
- rewardPerSeconds = res.rewardPerSeconds;
56
- });
28
+ await this.env.auriFairLaunch.getPoolInfo(consts.PLYWNEAR_POOL_ID).then((res) => {
29
+ stakedLiquidity = res.totalStake;
30
+ rewardPerSeconds = res.rewardPerSeconds;
31
+ });
57
32
 
58
- let stakedLiquidityAmount = new TokenAmount(
59
- PLYWNEARToken,
60
- stakedLiquidity!.toString()
61
- );
33
+ let stakedLiquidityAmount = new TokenAmount(PLYWNEARToken, stakedLiquidity!.toString());
62
34
 
63
35
  var totalStakeValuation: BigNumber = await fetchValuation(
64
36
  stakedLiquidityAmount,
@@ -70,10 +42,7 @@ export class StakingRead extends BlockchainEntityRead {
70
42
  // Calculate the reward per second in USD
71
43
  for (let i = 0; i < rewardPerSeconds!.length; i++) {
72
44
  let rewardTokenAddress = consts.PLYWNEAR_REWARD_TOKENS[i];
73
- let rewardToken = new Token(
74
- rewardTokenAddress,
75
- getDecimal(rewardTokenAddress)
76
- );
45
+ let rewardToken = new Token(rewardTokenAddress, getDecimal(rewardTokenAddress));
77
46
  let rewardPerSecond = rewardPerSeconds![i];
78
47
  promises.push(
79
48
  fetchValuation(
@@ -108,10 +77,7 @@ export class StakingRead extends BlockchainEntityRead {
108
77
  * Get amount of staked LP tokens
109
78
  */
110
79
  public async stakeBalanceOf(user: string): Promise<TokenAmount> {
111
- const userInfo = await this._auriFairLaunch.getUserInfo(
112
- consts.PLYWNEAR_POOL_ID,
113
- user
114
- );
80
+ const userInfo = await this.env.auriFairLaunch.getUserInfo(consts.PLYWNEAR_POOL_ID, user);
115
81
  return new TokenAmount(PLYWNEARToken, userInfo.amount.toString());
116
82
  }
117
83
 
@@ -130,7 +96,7 @@ export class StakingRead extends BlockchainEntityRead {
130
96
  }
131
97
 
132
98
  public async unclaimedRewardsOf(user: string): Promise<TokenAmount[]> {
133
- let userInfo = await this._auriFairLaunch.callStatic.updateAndGetUserInfo(
99
+ let userInfo = await this.env.auriFairLaunch.callStatic.updateAndGetUserInfo(
134
100
  consts.PLYWNEAR_POOL_ID,
135
101
  user,
136
102
  { from: user }
@@ -138,17 +104,14 @@ export class StakingRead extends BlockchainEntityRead {
138
104
 
139
105
  let rewards = userInfo.unclaimedRewards;
140
106
  return rewards.map((reward, i) =>
141
- TokenAmount.fromAddressAndAmount(
142
- consts.PLYWNEAR_REWARD_TOKENS[i],
143
- reward.toString()
144
- )
107
+ TokenAmount.fromAddressAndAmount(consts.PLYWNEAR_REWARD_TOKENS[i], reward.toString())
145
108
  );
146
109
  }
147
110
  }
148
111
 
149
112
  export class StakingReadWrite extends StakingRead {
150
113
  public async stake(amount: TokenAmount): Promise<TransactionResponse> {
151
- return this._auriFairLaunch
114
+ return this.env.auriFairLaunch
152
115
  .connect(this._networkConnection.signer!)
153
116
  .deposit(consts.PLYWNEAR_POOL_ID, amount.rawAmount());
154
117
  }
@@ -156,14 +119,10 @@ export class StakingReadWrite extends StakingRead {
156
119
  public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
157
120
  const msgSender = await this._networkConnection.signer!.getAddress();
158
121
  const amountInput = BN.from(amount.rawAmount());
159
- const stakedAmount = BN.from(
160
- (await this.stakeBalanceOf(msgSender)).rawAmount()
161
- );
122
+ const stakedAmount = BN.from((await this.stakeBalanceOf(msgSender)).rawAmount());
162
123
  // unstakeAmount = min(amountInput, stakedAmount - 1)
163
- const unstakeAmount = amountInput.lt(stakedAmount)
164
- ? amountInput
165
- : stakedAmount.sub(1);
166
- return this._auriFairLaunch
124
+ const unstakeAmount = amountInput.lt(stakedAmount) ? amountInput : stakedAmount.sub(1);
125
+ return this.env.auriFairLaunch
167
126
  .connect(this._networkConnection.signer!)
168
127
  .withdraw(consts.PLYWNEAR_POOL_ID, unstakeAmount);
169
128
  }
@@ -1,4 +1,5 @@
1
- export * from './airdrop-lottery';
1
+ export * from './Airdrop';
2
+ export * from './misc';
2
3
  export * from './MoneyMarket';
3
4
  export * from './Papermill';
4
5
  export * from './Referral';
@@ -0,0 +1,281 @@
1
+ import BigNumber from 'bignumber.js';
2
+ import { BigNumber as BN } from 'ethers';
3
+ import * as consts from '../consts';
4
+ import { MoneyMarketRead, PapermillRead, StakingRead } from '../contracts';
5
+ import { MulticallRead } from '../contracts/Multicall';
6
+ import { AuriEnv, BlockchainEntityRead, PLYToken, Token, TokenAmount } from '../entities';
7
+ import { decimalFactor, isSameAddress } from '../helpers/helpers';
8
+ import { calcValuation, fetchPrice } from '../helpers/priceFetcher';
9
+ import * as types from '../types';
10
+
11
+ export class MiscRead extends BlockchainEntityRead {
12
+ protected env: AuriEnv;
13
+ protected _stakingRead: StakingRead;
14
+ constructor(networkConnection: types.NetworkConnection) {
15
+ super(networkConnection);
16
+ this._stakingRead = new StakingRead(networkConnection);
17
+ this.env = new AuriEnv(networkConnection);
18
+ }
19
+
20
+ public async getUserDetails(userAddress: string): Promise<types.UserDetails> {
21
+ const marketCount = consts.networkAddresses.auTokens.length;
22
+ var userMarketDetails: types.UserMarketDetails[] = [],
23
+ assetsIn: string[];
24
+ var promises = [];
25
+ var totalBorrowLimit = new BigNumber(0);
26
+ var pricePromises = [];
27
+ for (const auToken of consts.networkAddresses.auTokens) {
28
+ const userMarketDetail: types.UserMarketDetails = {} as types.UserMarketDetails;
29
+ userMarketDetails.push(userMarketDetail);
30
+ userMarketDetail.market = auToken.underlying;
31
+ const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
32
+ this._networkConnection,
33
+ auToken.address,
34
+ auToken.underlying
35
+ );
36
+ promises.push(
37
+ moneyMarket.getUserDepositBalance(userAddress).then((res: TokenAmount) => {
38
+ userMarketDetail.depositBalance = res;
39
+ })
40
+ );
41
+ promises.push(
42
+ moneyMarket.getUserBorrowBalance(userAddress).then((res: TokenAmount) => {
43
+ userMarketDetail.borrowBalance = res;
44
+ })
45
+ );
46
+ promises.push(
47
+ moneyMarket.getCollateralRatio().then((res: BigNumber) => {
48
+ userMarketDetail.collateralRatio = res.toNumber();
49
+ })
50
+ );
51
+ pricePromises.push(
52
+ fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider).then((res) => {
53
+ userMarketDetail.underlyingPrice = res.toString();
54
+ return res;
55
+ })
56
+ );
57
+ }
58
+
59
+ promises.push(
60
+ this.env.comptroller.getAssetsIn(userAddress).then((res: string[]) => {
61
+ assetsIn = res;
62
+ })
63
+ );
64
+
65
+ await Promise.all(promises);
66
+ var underlyingPrices = await Promise.all(pricePromises);
67
+ var depositValues = [];
68
+ for (var i = 0; i < marketCount; i++) {
69
+ const auToken = consts.networkAddresses.auTokens[i];
70
+ if (
71
+ assetsIn!.find((auAddress: types.Address) => isSameAddress(auToken.address, auAddress)) !==
72
+ undefined
73
+ ) {
74
+ userMarketDetails[i].isCollateral = true;
75
+ } else {
76
+ userMarketDetails[i].isCollateral = false;
77
+ }
78
+ depositValues.push(calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i]));
79
+ }
80
+
81
+ totalBorrowLimit = depositValues.reduce((p: BigNumber, v: BigNumber, index: number) => {
82
+ if (userMarketDetails[index].isCollateral)
83
+ return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
84
+ return p;
85
+ }, new BigNumber(0));
86
+
87
+ var accountLiquidity: [BN, BN] = await this.env.comptroller.getAccountLiquidity(userAddress);
88
+
89
+ var borrowedvaluation: BigNumber = totalBorrowLimit.minus(
90
+ new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18))
91
+ );
92
+
93
+ if (borrowedvaluation.lt('0.00001')) {
94
+ // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
95
+ borrowedvaluation = new BigNumber(0);
96
+ }
97
+
98
+ const bufferedBorrowLimit: BigNumber = totalBorrowLimit.multipliedBy(
99
+ consts.BORROW_LIMIT_BUFFER
100
+ );
101
+ const minimumBorrowLimitAllowed = borrowedvaluation.div(consts.BORROW_LIMIT_BUFFER);
102
+
103
+ var borrowableAmount: BigNumber;
104
+ if (bufferedBorrowLimit.lte(borrowedvaluation)) {
105
+ borrowableAmount = new BigNumber(0);
106
+ } else {
107
+ borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
108
+ }
109
+
110
+ for (var i = 0; i < marketCount; i++) {
111
+ const auToken = consts.networkAddresses.auTokens[i];
112
+ const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
113
+ this._networkConnection,
114
+ auToken.address,
115
+ auToken.underlying
116
+ );
117
+ const borrowLimitMargin = totalBorrowLimit.minus(minimumBorrowLimitAllowed).gt(0)
118
+ ? totalBorrowLimit.minus(minimumBorrowLimitAllowed)
119
+ : new BigNumber(0);
120
+ const maxWithdrawCap: BigNumber = borrowLimitMargin
121
+ .div(userMarketDetails[i].collateralRatio)
122
+ .div(underlyingPrices[i]);
123
+ userMarketDetails[i].maxWithdrawableAmount =
124
+ userMarketDetails[i].isCollateral &&
125
+ maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
126
+ ? new TokenAmount(moneyMarket.underlying, maxWithdrawCap.toFixed(24), false)
127
+ : new TokenAmount(
128
+ moneyMarket.underlying,
129
+ userMarketDetails[i].depositBalance.rawAmount()
130
+ );
131
+ }
132
+
133
+ return {
134
+ markets: userMarketDetails,
135
+ borrowLimit: {
136
+ currency: 'USD',
137
+ amount: bufferedBorrowLimit.toFixed(consts.DECIMAL_PRECISION),
138
+ },
139
+ userLockingDetails: await new PapermillRead(this._networkConnection).getLockingDetails(
140
+ userAddress
141
+ ),
142
+ borrowableAmount: {
143
+ currency: 'USD',
144
+ amount: borrowableAmount.toFixed(consts.DECIMAL_PRECISION),
145
+ },
146
+ };
147
+ }
148
+
149
+ public async getTokenPrice(token: Token): Promise<types.CurrencyAmount> {
150
+ const price = await fetchPrice(token.address, this._networkConnection.provider);
151
+ return {
152
+ currency: 'USD',
153
+ amount: price.toFixed(consts.DECIMAL_PRECISION),
154
+ };
155
+ }
156
+
157
+ public calcHypotheticalStats({
158
+ userMarketDetail,
159
+ currentBorrowLimit,
160
+ currentBorrowValuation,
161
+ action,
162
+ tokenAmount,
163
+ }: {
164
+ userMarketDetail: types.UserMarketDetails;
165
+ currentBorrowLimit: types.CurrencyAmount;
166
+ currentBorrowValuation: types.CurrencyAmount;
167
+ action: types.MarketAction;
168
+ tokenAmount?: TokenAmount;
169
+ }): types.HypotheticalStats {
170
+ var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
171
+ newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
172
+ switch (action) {
173
+ case types.MarketAction.EnableCollateral:
174
+ case types.MarketAction.DisableCollateral:
175
+ var deltaBorrowLimit = calcValuation(
176
+ userMarketDetail.depositBalance,
177
+ new BigNumber(userMarketDetail.underlyingPrice)
178
+ )
179
+ .multipliedBy(userMarketDetail.collateralRatio)
180
+ .multipliedBy(consts.BORROW_LIMIT_BUFFER);
181
+ newBorrowLimit =
182
+ action == types.MarketAction.EnableCollateral
183
+ ? newBorrowLimit.plus(deltaBorrowLimit)
184
+ : newBorrowLimit.minus(deltaBorrowLimit);
185
+ break;
186
+
187
+ case types.MarketAction.Deposit:
188
+ case types.MarketAction.Withdraw:
189
+ deltaBorrowLimit = calcValuation(
190
+ tokenAmount!,
191
+ new BigNumber(userMarketDetail.underlyingPrice)
192
+ )
193
+ .multipliedBy(userMarketDetail.collateralRatio)
194
+ .multipliedBy(consts.BORROW_LIMIT_BUFFER);
195
+ newBorrowLimit =
196
+ action == types.MarketAction.Deposit
197
+ ? newBorrowLimit.plus(deltaBorrowLimit)
198
+ : newBorrowLimit.minus(deltaBorrowLimit);
199
+ break;
200
+
201
+ case types.MarketAction.Borrow:
202
+ case types.MarketAction.Repay:
203
+ var deltaBorrowValuation = calcValuation(
204
+ tokenAmount!,
205
+ new BigNumber(userMarketDetail.underlyingPrice)
206
+ );
207
+ newBorrowValuation =
208
+ action == types.MarketAction.Borrow
209
+ ? newBorrowValuation.plus(deltaBorrowValuation)
210
+ : newBorrowValuation.minus(deltaBorrowValuation);
211
+ break;
212
+ }
213
+ return {
214
+ newBorrowLimit: {
215
+ amount: newBorrowLimit!.toFixed(consts.DECIMAL_PRECISION),
216
+ currency: 'USD',
217
+ },
218
+ newBorrowUtilization: newBorrowLimit.eq(0)
219
+ ? newBorrowValuation.eq(0)
220
+ ? 0
221
+ : 9999.99
222
+ : newBorrowValuation!.div(newBorrowLimit!).toNumber(),
223
+ };
224
+ }
225
+
226
+ /**
227
+ * Get ply circulating supply.
228
+ * It is calculated by the total supply, minus:
229
+ * - Ply in team multisig contract
230
+ * - Ply in comptroller contract
231
+ * - Ply in fairlaunch contract
232
+ * - Ply in vesting contract
233
+ */
234
+ public async getPlyCirculatingSupply(): Promise<TokenAmount> {
235
+ const multicallRead = new MulticallRead(this._networkConnection);
236
+ const baseBalanceOfCall = {
237
+ contract: this.env.ply,
238
+ method: 'balanceOf',
239
+ returnTypes: ['uint256'],
240
+ };
241
+
242
+ const callResults = (await multicallRead.aggregate([
243
+ // Get total supply
244
+ {
245
+ ...baseBalanceOfCall,
246
+ method: 'totalSupply',
247
+ args: [],
248
+ },
249
+ // balance in team multisig
250
+ {
251
+ ...baseBalanceOfCall,
252
+ args: [consts.networkAddresses.misc.TEAM_MULTISIG],
253
+ },
254
+ // balance in comptroller
255
+ {
256
+ ...baseBalanceOfCall,
257
+ args: [consts.networkAddresses.misc.COMPTROLLER],
258
+ },
259
+ // balance in fair launch
260
+ {
261
+ ...baseBalanceOfCall,
262
+ args: [consts.networkAddresses.misc.AURIFAIRLAUNCH],
263
+ },
264
+ // balance in vesting contract
265
+ {
266
+ ...baseBalanceOfCall,
267
+ args: [consts.networkAddresses.misc.PLY_TOKEN_LOCK],
268
+ },
269
+ ])) as BN[][];
270
+ let circulatingSupply: BN = BN.from(0);
271
+ callResults.forEach((result, i) => {
272
+ if (i === 0) {
273
+ circulatingSupply = result[0];
274
+ } else {
275
+ circulatingSupply = circulatingSupply.sub(result[0]);
276
+ }
277
+ });
278
+
279
+ return new TokenAmount(PLYToken, circulatingSupply.toString());
280
+ }
281
+ }
@@ -11,9 +11,7 @@ export class BlockchainEntityRead {
11
11
  export class BlockchainEntityReadWrite extends BlockchainEntityRead {
12
12
  public constructor(networkConnection: NetworkConnection) {
13
13
  if (!(networkConnection.signer instanceof Signer)) {
14
- throw Error(
15
- 'Signer is not provided when constructing BlockchainEntityReadWrite'
16
- );
14
+ throw Error('Signer is not provided when constructing BlockchainEntityReadWrite');
17
15
  }
18
16
  super(networkConnection);
19
17
  }
@@ -25,9 +23,7 @@ export class BlockchainEntity {
25
23
  return new BlockchainEntityRead(networkConnection);
26
24
  }
27
25
 
28
- public readWrite(
29
- networkConnection: NetworkConnection
30
- ): BlockchainEntityReadWrite {
26
+ public readWrite(networkConnection: NetworkConnection): BlockchainEntityReadWrite {
31
27
  return new BlockchainEntityReadWrite(networkConnection);
32
28
  }
33
29
  }
@@ -0,0 +1,39 @@
1
+ import { AuriFairLaunch, AuriLens, Comptroller, IERC20, PULP } from '@aurigami/contracts/typechain';
2
+ import { Contract } from 'ethers';
3
+ import * as abis from '../abis';
4
+ import { networkAddresses } from '../consts/constants';
5
+ import { NetworkConnection } from '../types';
6
+ import { BlockchainEntityRead } from './BlockchainEntity';
7
+
8
+ export class AuriEnv extends BlockchainEntityRead {
9
+ public comptroller: Comptroller;
10
+ public auriFairLaunch: AuriFairLaunch;
11
+ public auriLens: AuriLens;
12
+ public ply: IERC20;
13
+ public pulp: PULP;
14
+ // public faucet: Faucet;
15
+
16
+ public getContract<CType extends Contract>(address: string, abi: any) {
17
+ return new Contract(address, abi, this._networkConnection.provider) as CType;
18
+ }
19
+
20
+ public constructor(networkConnection: NetworkConnection) {
21
+ super(networkConnection);
22
+ this.comptroller = this.getContract<Comptroller>(
23
+ networkAddresses.misc.COMPTROLLER,
24
+ abis.ComptrollerABI.abi
25
+ );
26
+ this.auriFairLaunch = this.getContract<AuriFairLaunch>(
27
+ networkAddresses.misc.AURIFAIRLAUNCH,
28
+ abis.AuriFairLaunchABI.abi
29
+ );
30
+ this.auriLens = this.getContract<AuriLens>(
31
+ networkAddresses.misc.AURILENS,
32
+ abis.AuriLensABI.abi
33
+ );
34
+
35
+ this.ply = this.getContract<IERC20>(networkAddresses.tokens.PLY, abis.EIP20InterfaceABI.abi);
36
+ this.pulp = this.getContract<PULP>(networkAddresses.tokens.PULP, abis.PulpABI.abi);
37
+ // this.faucet = this.getContract<Faucet>(networkAddresses.misc.FAUCET, abis.FaucetABI.abi);
38
+ }
39
+ }
@@ -1,3 +1,4 @@
1
+ export * from './auriEnv';
1
2
  export * from './BlockchainEntity';
2
3
  export * from './token';
3
4
  export * from './tokenAmount';
@@ -1,5 +1,5 @@
1
- import { getDecimal } from '../helpers/helpers';
2
1
  import { networkAddresses } from '../consts/constants';
2
+ import { getDecimal } from '../helpers/helpers';
3
3
 
4
4
  export class Token {
5
5
  public readonly address: string;
@@ -1,7 +1,7 @@
1
- import { Token } from './token';
2
1
  import BigNumber from 'bignumber.js';
3
2
  import { decimalFactor, getDecimal } from '../helpers/helpers';
4
3
  import { Address } from '../types';
4
+ import { Token } from './token';
5
5
 
6
6
  export class TokenAmount {
7
7
  public readonly token: Token;
@@ -11,17 +11,13 @@ export class TokenAmount {
11
11
  if (isRaw) {
12
12
  this.rawAmnt = amount;
13
13
  } else {
14
- this.rawAmnt = new BigNumber(amount)
15
- .times(decimalFactor(token.decimals))
16
- .toFixed(0);
14
+ this.rawAmnt = new BigNumber(amount).times(decimalFactor(token.decimals)).toFixed(0);
17
15
  }
18
16
  this.token = token;
19
17
  }
20
18
 
21
19
  public formattedAmount(): string {
22
- return new BigNumber(this.rawAmnt)
23
- .div(decimalFactor(this.token.decimals))
24
- .toString();
20
+ return new BigNumber(this.rawAmnt).div(decimalFactor(this.token.decimals)).toString();
25
21
  }
26
22
 
27
23
  public rawAmount(): string {
@@ -33,10 +29,6 @@ export class TokenAmount {
33
29
  amount: string,
34
30
  isRaw: boolean = true
35
31
  ): TokenAmount {
36
- return new TokenAmount(
37
- new Token(tokenAddress, getDecimal(tokenAddress)),
38
- amount,
39
- isRaw
40
- );
32
+ return new TokenAmount(new Token(tokenAddress, getDecimal(tokenAddress)), amount, isRaw);
41
33
  }
42
34
  }
@@ -9,12 +9,9 @@ export async function getQuery(
9
9
  ): Promise<any> {
10
10
  params = { ...params, module: module, action: action };
11
11
 
12
- let resp = await axios.get(
13
- AURORA_API_BASE_URL + '?' + new URLSearchParams(params),
14
- {
15
- headers: { 'Content-Type': 'application/json' },
16
- }
17
- );
12
+ let resp = await axios.get(AURORA_API_BASE_URL + '?' + new URLSearchParams(params), {
13
+ headers: { 'Content-Type': 'application/json' },
14
+ });
18
15
 
19
16
  return resp.data.result!;
20
17
  }
@@ -1,9 +1,9 @@
1
1
  import { Provider } from '@ethersproject/abstract-provider';
2
2
  import BigNumber from 'bignumber.js';
3
3
  import { BigNumber as BN, utils } from 'ethers';
4
- import { getQuery as getAuroraAPIQuery } from './aurora-api-helpers';
5
4
  import { decimalRecords } from '../consts/decimals';
6
5
  import { Address } from '../types';
6
+ import { getQuery as getAuroraAPIQuery } from './aurora-api-helpers';
7
7
 
8
8
  export function assert(condition: boolean, message: string = ''): void {
9
9
  if (!condition) {
@@ -20,10 +20,7 @@ export function decimalFactor(decimal: number) {
20
20
  return BN.from(10).pow(decimal).toString();
21
21
  }
22
22
 
23
- export const isSameAddress = (
24
- address1: Address,
25
- address2: Address
26
- ): boolean => {
23
+ export const isSameAddress = (address1: Address, address2: Address): boolean => {
27
24
  return address1.toLowerCase() == address2.toLowerCase();
28
25
  };
29
26
 
@@ -41,10 +38,7 @@ export function validateAndParseAddress(address: Address): Address {
41
38
 
42
39
  export function getDecimal(address: Address): number {
43
40
  let addressLowercase = address.toLowerCase();
44
- assert(
45
- decimalRecords[addressLowercase] != undefined,
46
- 'Decimal not found for ' + address
47
- );
41
+ assert(decimalRecords[addressLowercase] != undefined, 'Decimal not found for ' + address);
48
42
  return decimalRecords[addressLowercase];
49
43
  }
50
44
 
@@ -63,10 +57,7 @@ export function calcLMRewardApr(
63
57
  return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
64
58
  }
65
59
 
66
- export async function getBlockTimestamp(
67
- provider: Provider,
68
- blockNumber: number
69
- ): Promise<number> {
60
+ export async function getBlockTimestamp(provider: Provider, blockNumber: number): Promise<number> {
70
61
  const block = await provider.getBlock(blockNumber);
71
62
  return block.timestamp;
72
63
  }
@@ -79,10 +70,7 @@ export async function getBlockTimestamp(
79
70
  *
80
71
  * This function is much faster than using binary search.
81
72
  */
82
- export async function getBlockBeforeTimestamp(
83
- provider: Provider,
84
- timestamp: number
85
- ) {
73
+ export async function getBlockBeforeTimestamp(provider: Provider, timestamp: number) {
86
74
  let result = await getAuroraAPIQuery('block', 'getblocknobytime', {
87
75
  timestamp: timestamp,
88
76
  closest: 'before',