@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
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.6.4",
2
+ "version": "1.6.5",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -8,7 +8,7 @@
8
8
  "src"
9
9
  ],
10
10
  "engines": {
11
- "node": ">=10"
11
+ "node": ">=14"
12
12
  },
13
13
  "scripts": {
14
14
  "start": "tsdx watch",
@@ -33,20 +33,22 @@
33
33
  "size-limit": [
34
34
  {
35
35
  "path": "dist/sdk.cjs.production.min.js",
36
- "limit": "10 KB"
36
+ "limit": "300 KB"
37
37
  },
38
38
  {
39
39
  "path": "dist/sdk.esm.js",
40
- "limit": "10 KB"
40
+ "limit": "300 KB"
41
41
  }
42
42
  ],
43
43
  "devDependencies": {
44
44
  "@nomiclabs/hardhat-ethers": "^2.0.5",
45
45
  "@nomiclabs/hardhat-etherscan": "^3.0.3",
46
46
  "@nomiclabs/hardhat-waffle": "^2.0.3",
47
- "@size-limit/preset-small-lib": "^7.0.8",
47
+ "@size-limit/preset-big-lib": "^7.0.8",
48
+ "@size-limit/webpack-why": "^7.0.8",
48
49
  "@types/mocha": "^9.1.0",
49
50
  "chai": "^4.3.6",
51
+ "dotenv": "^16.0.1",
50
52
  "eslint-config-prettier": "^8.3.0",
51
53
  "eslint-plugin-prettier": "^4.0.0",
52
54
  "ethereum-waffle": "^3.4.4",
@@ -63,7 +65,6 @@
63
65
  "@aurigami/contracts": "3.6.0",
64
66
  "axios": "^0.26.1",
65
67
  "bignumber.js": "^9.0.2",
66
- "dotenv": "^16.0.0",
67
68
  "ethers": "^5.6.4"
68
69
  }
69
70
  }
package/src/SDK.ts CHANGED
@@ -1,213 +1,22 @@
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 FaucetABI from '@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json';
5
- import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
6
- import {
7
- AuriFairLaunch,
8
- AuriLens,
9
- Comptroller,
10
- IERC20,
11
- } from '@aurigami/contracts/typechain';
12
1
  import { TransactionResponse } from '@ethersproject/abstract-provider';
13
- import BigNumber from 'bignumber.js';
14
- import { BigNumber as BN, Contract } from 'ethers';
15
2
  import * as consts from './consts';
16
- import {
17
- MoneyMarketRead,
18
- PapermillRead,
19
- StakingRead,
20
- StakingReadWrite,
21
- } from './contracts';
22
- import {
23
- BlockchainEntity,
24
- BlockchainEntityRead,
25
- PLYToken,
26
- Token,
27
- TokenAmount,
28
- } from './entities';
29
- import { decimalFactor, isSameAddress } from './helpers/helpers';
30
- import { calcValuation, fetchPrice } from './helpers/priceFetcher';
3
+ import { MiscRead, StakingRead, StakingReadWrite } from './contracts';
4
+ import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from './entities';
31
5
  import * as types from './types';
32
- import { MulticallRead } from './contracts/Multicall';
33
6
 
34
7
  export class SdkRead extends BlockchainEntityRead {
35
- protected _comptroller: Comptroller;
36
- protected _auriFairLaunch: AuriFairLaunch;
37
- protected _auriLens: AuriLens;
8
+ protected env: AuriEnv;
38
9
  protected _stakingRead: StakingRead;
10
+ protected _misc: MiscRead;
39
11
  constructor(networkConnection: types.NetworkConnection) {
40
12
  super(networkConnection);
13
+ this.env = new AuriEnv(networkConnection);
41
14
  this._stakingRead = new StakingRead(networkConnection);
42
- this._comptroller = new Contract(
43
- consts.networkAddresses.misc.COMPTROLLER,
44
- ComptrollerABI.abi,
45
- networkConnection.provider
46
- ) as Comptroller;
47
- this._auriFairLaunch = new Contract(
48
- consts.networkAddresses.misc.AURIFAIRLAUNCH,
49
- AuriFairLaunchABI.abi,
50
- networkConnection.provider
51
- ) as AuriFairLaunch;
52
- this._auriLens = new Contract(
53
- consts.networkAddresses.misc.AURILENS,
54
- AuriLensABI.abi,
55
- networkConnection.provider
56
- ) as AuriLens;
15
+ this._misc = new MiscRead(networkConnection);
57
16
  }
58
17
 
59
18
  public async getUserDetails(userAddress: string): Promise<types.UserDetails> {
60
- const marketCount = consts.networkAddresses.auTokens.length;
61
- var userMarketDetails: types.UserMarketDetails[] = [],
62
- assetsIn: string[];
63
- var promises = [];
64
- var totalBorrowLimit = new BigNumber(0);
65
- var pricePromises = [];
66
- for (const auToken of consts.networkAddresses.auTokens) {
67
- const userMarketDetail: types.UserMarketDetails =
68
- {} as types.UserMarketDetails;
69
- userMarketDetails.push(userMarketDetail);
70
- userMarketDetail.market = auToken.underlying;
71
- const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
72
- this._networkConnection,
73
- auToken.address,
74
- auToken.underlying
75
- );
76
- promises.push(
77
- moneyMarket
78
- .getUserDepositBalance(userAddress)
79
- .then((res: TokenAmount) => {
80
- userMarketDetail.depositBalance = res;
81
- })
82
- );
83
- promises.push(
84
- moneyMarket
85
- .getUserBorrowBalance(userAddress)
86
- .then((res: TokenAmount) => {
87
- userMarketDetail.borrowBalance = res;
88
- })
89
- );
90
- promises.push(
91
- moneyMarket.getCollateralRatio().then((res: BigNumber) => {
92
- userMarketDetail.collateralRatio = res.toNumber();
93
- })
94
- );
95
- pricePromises.push(
96
- fetchPrice(
97
- moneyMarket.underlying.address,
98
- this._networkConnection.provider
99
- ).then((res) => {
100
- userMarketDetail.underlyingPrice = res.toString();
101
- return res;
102
- })
103
- );
104
- }
105
-
106
- promises.push(
107
- this._comptroller.getAssetsIn(userAddress).then((res: string[]) => {
108
- assetsIn = res;
109
- })
110
- );
111
-
112
- await Promise.all(promises);
113
- var underlyingPrices = await Promise.all(pricePromises);
114
- var depositValues = [];
115
- for (var i = 0; i < marketCount; i++) {
116
- const auToken = consts.networkAddresses.auTokens[i];
117
- if (
118
- assetsIn!.find((auAddress: types.Address) =>
119
- isSameAddress(auToken.address, auAddress)
120
- ) !== undefined
121
- ) {
122
- userMarketDetails[i].isCollateral = true;
123
- } else {
124
- userMarketDetails[i].isCollateral = false;
125
- }
126
- depositValues.push(
127
- calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i])
128
- );
129
- }
130
-
131
- totalBorrowLimit = depositValues.reduce(
132
- (p: BigNumber, v: BigNumber, index: number) => {
133
- if (userMarketDetails[index].isCollateral)
134
- return p.plus(
135
- v.multipliedBy(userMarketDetails[index].collateralRatio)
136
- );
137
- return p;
138
- },
139
- new BigNumber(0)
140
- );
141
-
142
- var accountLiquidity: [BN, BN] =
143
- await this._comptroller.getAccountLiquidity(userAddress);
144
-
145
- var borrowedvaluation: BigNumber = totalBorrowLimit.minus(
146
- new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18))
147
- );
148
-
149
- if (borrowedvaluation.lt('0.00001')) {
150
- // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
151
- borrowedvaluation = new BigNumber(0);
152
- }
153
-
154
- const bufferedBorrowLimit: BigNumber = totalBorrowLimit.multipliedBy(
155
- consts.BORROW_LIMIT_BUFFER
156
- );
157
- const minimumBorrowLimitAllowed = borrowedvaluation.div(
158
- consts.BORROW_LIMIT_BUFFER
159
- );
160
-
161
- var borrowableAmount: BigNumber;
162
- if (bufferedBorrowLimit.lte(borrowedvaluation)) {
163
- borrowableAmount = new BigNumber(0);
164
- } else {
165
- borrowableAmount = bufferedBorrowLimit.minus(borrowedvaluation);
166
- }
167
-
168
- for (var i = 0; i < marketCount; i++) {
169
- const auToken = consts.networkAddresses.auTokens[i];
170
- const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
171
- this._networkConnection,
172
- auToken.address,
173
- auToken.underlying
174
- );
175
- const borrowLimitMargin = totalBorrowLimit
176
- .minus(minimumBorrowLimitAllowed)
177
- .gt(0)
178
- ? totalBorrowLimit.minus(minimumBorrowLimitAllowed)
179
- : new BigNumber(0);
180
- const maxWithdrawCap: BigNumber = borrowLimitMargin
181
- .div(userMarketDetails[i].collateralRatio)
182
- .div(underlyingPrices[i]);
183
- userMarketDetails[i].maxWithdrawableAmount =
184
- userMarketDetails[i].isCollateral &&
185
- maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
186
- ? new TokenAmount(
187
- moneyMarket.underlying,
188
- maxWithdrawCap.toFixed(24),
189
- false
190
- )
191
- : new TokenAmount(
192
- moneyMarket.underlying,
193
- userMarketDetails[i].depositBalance.rawAmount()
194
- );
195
- }
196
-
197
- return {
198
- markets: userMarketDetails,
199
- borrowLimit: {
200
- currency: 'USD',
201
- amount: bufferedBorrowLimit.toFixed(consts.DECIMAL_PRECISION),
202
- },
203
- userLockingDetails: await new PapermillRead(
204
- this._networkConnection
205
- ).getLockingDetails(userAddress),
206
- borrowableAmount: {
207
- currency: 'USD',
208
- amount: borrowableAmount.toFixed(consts.DECIMAL_PRECISION),
209
- },
210
- };
19
+ return this._misc.getUserDetails(userAddress);
211
20
  }
212
21
 
213
22
  public async getPLYWNEARPoolDetails(): Promise<types.PLYWNEARPoolDetails> {
@@ -215,14 +24,7 @@ export class SdkRead extends BlockchainEntityRead {
215
24
  }
216
25
 
217
26
  public async getTokenPrice(token: Token): Promise<types.CurrencyAmount> {
218
- const price = await fetchPrice(
219
- token.address,
220
- this._networkConnection.provider
221
- );
222
- return {
223
- currency: 'USD',
224
- amount: price.toFixed(consts.DECIMAL_PRECISION),
225
- };
27
+ return this._misc.getTokenPrice(token);
226
28
  }
227
29
 
228
30
  /**
@@ -256,60 +58,13 @@ export class SdkRead extends BlockchainEntityRead {
256
58
  action: types.MarketAction;
257
59
  tokenAmount?: TokenAmount;
258
60
  }): types.HypotheticalStats {
259
- var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
260
- newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
261
- switch (action) {
262
- case types.MarketAction.EnableCollateral:
263
- case types.MarketAction.DisableCollateral:
264
- var deltaBorrowLimit = calcValuation(
265
- userMarketDetail.depositBalance,
266
- new BigNumber(userMarketDetail.underlyingPrice)
267
- )
268
- .multipliedBy(userMarketDetail.collateralRatio)
269
- .multipliedBy(consts.BORROW_LIMIT_BUFFER);
270
- newBorrowLimit =
271
- action == types.MarketAction.EnableCollateral
272
- ? newBorrowLimit.plus(deltaBorrowLimit)
273
- : newBorrowLimit.minus(deltaBorrowLimit);
274
- break;
275
-
276
- case types.MarketAction.Deposit:
277
- case types.MarketAction.Withdraw:
278
- deltaBorrowLimit = calcValuation(
279
- tokenAmount!,
280
- new BigNumber(userMarketDetail.underlyingPrice)
281
- )
282
- .multipliedBy(userMarketDetail.collateralRatio)
283
- .multipliedBy(consts.BORROW_LIMIT_BUFFER);
284
- newBorrowLimit =
285
- action == types.MarketAction.Deposit
286
- ? newBorrowLimit.plus(deltaBorrowLimit)
287
- : newBorrowLimit.minus(deltaBorrowLimit);
288
- break;
289
-
290
- case types.MarketAction.Borrow:
291
- case types.MarketAction.Repay:
292
- var deltaBorrowValuation = calcValuation(
293
- tokenAmount!,
294
- new BigNumber(userMarketDetail.underlyingPrice)
295
- );
296
- newBorrowValuation =
297
- action == types.MarketAction.Borrow
298
- ? newBorrowValuation.plus(deltaBorrowValuation)
299
- : newBorrowValuation.minus(deltaBorrowValuation);
300
- break;
301
- }
302
- return {
303
- newBorrowLimit: {
304
- amount: newBorrowLimit!.toFixed(consts.DECIMAL_PRECISION),
305
- currency: 'USD',
306
- },
307
- newBorrowUtilization: newBorrowLimit.eq(0)
308
- ? newBorrowValuation.eq(0)
309
- ? 0
310
- : 9999.99
311
- : newBorrowValuation!.div(newBorrowLimit!).toNumber(),
312
- };
61
+ return this._misc.calcHypotheticalStats({
62
+ userMarketDetail,
63
+ currentBorrowLimit,
64
+ currentBorrowValuation,
65
+ action,
66
+ tokenAmount,
67
+ });
313
68
  }
314
69
 
315
70
  /**
@@ -321,57 +76,7 @@ export class SdkRead extends BlockchainEntityRead {
321
76
  * - Ply in vesting contract
322
77
  */
323
78
  public async getPlyCirculatingSupply(): Promise<TokenAmount> {
324
- const plyContract: IERC20 = new Contract(
325
- consts.networkAddresses.tokens.PLY,
326
- EIP20InterfaceABI.abi,
327
- this._networkConnection.provider
328
- ) as IERC20;
329
-
330
- const multicallRead = new MulticallRead(this._networkConnection);
331
- const baseBalanceOfCall = {
332
- contract: plyContract,
333
- method: 'balanceOf',
334
- returnTypes: ['uint256'],
335
- };
336
-
337
- const callResults = (await multicallRead.aggregate([
338
- // Get total supply
339
- {
340
- ...baseBalanceOfCall,
341
- method: 'totalSupply',
342
- args: [],
343
- },
344
- // balance in team multisig
345
- {
346
- ...baseBalanceOfCall,
347
- args: [consts.networkAddresses.misc.TEAM_MULTISIG],
348
- },
349
- // balance in comptroller
350
- {
351
- ...baseBalanceOfCall,
352
- args: [consts.networkAddresses.misc.COMPTROLLER],
353
- },
354
- // balance in fair launch
355
- {
356
- ...baseBalanceOfCall,
357
- args: [consts.networkAddresses.misc.AURIFAIRLAUNCH],
358
- },
359
- // balance in vesting contract
360
- {
361
- ...baseBalanceOfCall,
362
- args: [consts.networkAddresses.misc.PLY_TOKEN_LOCK],
363
- },
364
- ])) as BN[][];
365
- let circulatingSupply: BN = BN.from(0);
366
- callResults.forEach((result, i) => {
367
- if (i === 0) {
368
- circulatingSupply = result[0];
369
- } else {
370
- circulatingSupply = circulatingSupply.sub(result[0]);
371
- }
372
- });
373
-
374
- return new TokenAmount(PLYToken, circulatingSupply.toString());
79
+ return this._misc.getPlyCirculatingSupply();
375
80
  }
376
81
  }
377
82
 
@@ -380,22 +85,15 @@ export class SdkReadWrite extends SdkRead {
380
85
  * Claim PLY reward in all markets + staking pools
381
86
  */
382
87
  public async claim(): Promise<TransactionResponse> {
383
- return this._comptroller
88
+ return this.env.comptroller
384
89
  .connect(this._networkConnection.signer!)
385
- ['claimReward(uint8,address)'](
386
- 0,
387
- await this._networkConnection.signer!.getAddress()
388
- );
90
+ ['claimReward(uint8,address)'](0, await this._networkConnection.signer!.getAddress());
389
91
  }
390
92
 
391
93
  public async claimLpRewards(): Promise<TransactionResponse> {
392
- return this._auriFairLaunch
94
+ return this.env.auriFairLaunch
393
95
  .connect(this._networkConnection.signer!)
394
- .harvest(
395
- await this._networkConnection.signer!.getAddress(),
396
- 0,
397
- consts.INF
398
- );
96
+ .harvest(await this._networkConnection.signer!.getAddress(), 0, consts.INF);
399
97
  }
400
98
 
401
99
  public async stake(amount: TokenAmount): Promise<TransactionResponse> {
@@ -406,14 +104,9 @@ export class SdkReadWrite extends SdkRead {
406
104
  return new StakingReadWrite(this._networkConnection).unstake(amount);
407
105
  }
408
106
 
409
- public async faucetDrip(): Promise<TransactionResponse> {
410
- const faucet = new Contract(
411
- consts.networkAddresses.misc.FAUCET,
412
- FaucetABI.abi,
413
- this._networkConnection.provider
414
- );
415
- return faucet.connect(this._networkConnection.signer!).drip();
416
- }
107
+ // public async faucetDrip(): Promise<TransactionResponse> {
108
+ // return this.env.faucet.connect(this._networkConnection.signer!).drip();
109
+ // }
417
110
  }
418
111
 
419
112
  export class SDK extends BlockchainEntity {
@@ -0,0 +1,30 @@
1
+ import AuErc20ABI from '@aurigami/contracts/artifacts/contracts/AuErc20.sol/AuErc20.json';
2
+ import AuETHABI from '@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json';
3
+ import AuriAirdropABI from '@aurigami/contracts/artifacts/contracts/AuriAirdrop.sol/AuriAirdrop.json';
4
+ import AuriFairLaunchABI from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
5
+ import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
6
+ import AuriOracleABI from '@aurigami/contracts/artifacts/contracts/AuriOracle.sol/AuriOracle.json';
7
+ import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
8
+ import EthRepayHelperABI from '@aurigami/contracts/artifacts/contracts/EthRepayHelper.sol/EthRepayHelper.json';
9
+ import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
10
+ // import FaucetABI from '@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json';
11
+ import IUniswapV2PairABI from '@aurigami/contracts/artifacts/contracts/mock/IUniswapV2Pair.sol/IUniswapV2Pair.json';
12
+ import Multicall2ABI from '@aurigami/contracts/artifacts/contracts/mock/Multicall2.sol/Multicall2.json';
13
+ import PulpABI from '@aurigami/contracts/artifacts/contracts/PULP.sol/PULP.json';
14
+ import ReferralDirectoryABI from '@aurigami/contracts/artifacts/contracts/ReferralDirectory.sol/ReferralDirectory.json';
15
+ export {
16
+ AuriOracleABI,
17
+ IUniswapV2PairABI,
18
+ AuriAirdropABI,
19
+ AuriFairLaunchABI,
20
+ AuriLensABI,
21
+ ComptrollerABI,
22
+ // FaucetABI,
23
+ EIP20InterfaceABI,
24
+ ReferralDirectoryABI,
25
+ AuErc20ABI,
26
+ AuETHABI,
27
+ EthRepayHelperABI,
28
+ Multicall2ABI,
29
+ PulpABI,
30
+ };
@@ -1,8 +1,7 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { ethers, Signer, BigNumber as BN } from 'ethers';
2
+ import { BigNumber as BN } from 'ethers';
3
3
  import { MAINNET_ADDRESSES } from './deployments';
4
- export const dummyAddress: string =
5
- '0xDEADbeEfEEeEEEeEEEeEEeeeeeEeEEeeeeEEEEeE';
4
+ export const dummyAddress: string = '0xDEADbeEfEEeEEEeEEEeEEeeeeeEeEEeeeeEEEEeE';
6
5
  export const ETHAddress: string = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
7
6
 
8
7
  export const AURORA_CHAINID = 1313161554;
@@ -136,21 +135,21 @@ export const AIRDROP_START_TIMESTAMP = 1649858400;
136
135
  export const AIRDROP_END_TIMESTAMP = 1651068000;
137
136
  export const AIRDROP_KEEP_THRESHOLD = 7 * 86400;
138
137
 
139
- export const DEPOSIT_NEAR_REWARDS_PER_WEEK: { [k: string]: string } =
140
- Object.fromEntries(
141
- // lower case all addresses
142
- Object.entries({
143
- '0xb12bfca5a55806aaf64e99521918a4bf0fc40802': '36375', // USDC
144
- '0x4988a896b1227218e4a686fde5eabdcabd91571f': '14550', // USDT
145
- '0xf4eb217ba2454613b15dbdea6e5f22276410e89e': '3638', // WBTC
146
- '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE': '14550', // ETH
147
- '0xc42c30ac6cc15fac9bd938618bcaa1a1fae8501d': '3638', // WNEAR
148
- }).map(([k, v]) => [k.toLowerCase(), v])
149
- );
138
+ export const DEPOSIT_NEAR_REWARDS_PER_WEEK: { [k: string]: string } = Object.fromEntries(
139
+ // lower case all addresses
140
+ Object.entries({
141
+ '0xb12bfca5a55806aaf64e99521918a4bf0fc40802': '36375', // USDC
142
+ '0x4988a896b1227218e4a686fde5eabdcabd91571f': '14550', // USDT
143
+ '0xf4eb217ba2454613b15dbdea6e5f22276410e89e': '3638', // WBTC
144
+ '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE': '14550', // ETH
145
+ '0xc42c30ac6cc15fac9bd938618bcaa1a1fae8501d': '3638', // WNEAR
146
+ }).map(([k, v]) => [k.toLowerCase(), v])
147
+ );
150
148
 
151
149
  export const BORROW_NEAR_REWARDS_PER_WEEK: { [k: string]: string } = {
152
150
  // currently 0 for all markets
153
151
  };
154
152
 
155
- export const HARDCODE_PRICE_TOKENS: { [k: string]: string } =
156
- Object.fromEntries([[networkAddresses.tokens.USN.toLowerCase(), '1']]);
153
+ export const HARDCODE_PRICE_TOKENS: { [k: string]: string } = Object.fromEntries([
154
+ [networkAddresses.tokens.USN.toLowerCase(), '1'],
155
+ ]);
@@ -1,21 +1,11 @@
1
- import { Token } from '../entities';
2
- import { TokenAmount } from '../entities';
1
+ import { Token, TokenAmount } from '../entities';
3
2
  import { UserMarketDetails } from '../types';
4
3
 
5
- export const dummyToken = new Token(
6
- '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
7
- 6
8
- );
4
+ export const dummyToken = new Token('0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e', 6);
9
5
 
10
- export const dummyPly = new Token(
11
- '0x8729438eb15e2c8b576fcc6aecda6a148776c0f5',
12
- 18
13
- );
6
+ export const dummyPly = new Token('0x8729438eb15e2c8b576fcc6aecda6a148776c0f5', 18);
14
7
 
15
- export const dummyPlyAurora = new Token(
16
- '0xE530dC2095Ef5653205CF5ea79F8979a7028065c',
17
- 18
18
- );
8
+ export const dummyPlyAurora = new Token('0xE530dC2095Ef5653205CF5ea79F8979a7028065c', 18);
19
9
 
20
10
  export const dummyTokenAmount = new TokenAmount(dummyToken, '123.456', false);
21
11
 
@@ -0,0 +1,80 @@
1
+ import { AuriAirdrop } from '@aurigami/contracts/typechain';
2
+ import { TransactionResponse } from '@ethersproject/abstract-provider';
3
+ import { BigNumber as BN, Contract, utils } from 'ethers';
4
+ import { AuriAirdropABI } from '../abis';
5
+ import * as consts from '../consts';
6
+ import { BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from '../entities';
7
+ import * as helpers from '../helpers';
8
+ import { Address, NetworkConnection } from '../types';
9
+
10
+ export class AirdropRead extends BlockchainEntityRead {
11
+ protected _airDrop: AuriAirdrop;
12
+
13
+ public constructor(networkConnection: NetworkConnection) {
14
+ super(networkConnection);
15
+
16
+ this._airDrop = new Contract(
17
+ consts.networkAddresses.misc.AURI_AIRDROP,
18
+ AuriAirdropABI.abi,
19
+ networkConnection.provider
20
+ ) as AuriAirdrop;
21
+ }
22
+
23
+ /**
24
+ * Get redeemable rewards amount of user
25
+ */
26
+ public async getRedeemableReward(
27
+ campaign: string,
28
+ token: Address,
29
+ user: Address
30
+ ): Promise<TokenAmount> {
31
+ let tokenInstance: Token = new Token(token, helpers.getDecimal(token));
32
+
33
+ let rewards: BN = await this._airDrop.getRedeemableReward(
34
+ utils.formatBytes32String(campaign),
35
+ token,
36
+ user
37
+ );
38
+
39
+ return new TokenAmount(tokenInstance, rewards.toString());
40
+ }
41
+ }
42
+
43
+ export class AirdropReadWrite extends AirdropRead {
44
+ /**
45
+ * Transfer rewards from multiple campaigns to msg.sender
46
+ */
47
+ public async redeemMultiple(
48
+ campaigns: string[],
49
+ tokens: Address[]
50
+ ): Promise<TransactionResponse> {
51
+ helpers.assert(
52
+ campaigns.length == tokens.length,
53
+ 'campaigns and tokens must have the same length'
54
+ );
55
+ return this._airDrop.connect(this._networkConnection.signer!).redeem(
56
+ campaigns.map((e) => utils.formatBytes32String(e)),
57
+ tokens,
58
+ await this._networkConnection.signer!.getAddress()
59
+ );
60
+ }
61
+
62
+ /**
63
+ * Redeem reward from a single campaign
64
+ */
65
+ public async redeemSingle(campaign: string, token: Address): Promise<TransactionResponse> {
66
+ return this.redeemMultiple([campaign], [token]);
67
+ }
68
+ }
69
+
70
+ export class Airdrop extends BlockchainEntity {
71
+ constructor() {
72
+ super();
73
+ }
74
+ public read(networkConnection: NetworkConnection): AirdropRead {
75
+ return new AirdropRead(networkConnection);
76
+ }
77
+ public readWrite(networkConnection: NetworkConnection): AirdropReadWrite {
78
+ return new AirdropReadWrite(networkConnection);
79
+ }
80
+ }