@aurigami/sdk 1.3.4 → 1.4.0

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.4",
2
+ "version": "1.4.0",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -14,6 +14,7 @@
14
14
  "start": "tsdx watch",
15
15
  "build": "tsdx build",
16
16
  "test": "tsdx test",
17
+ "test-hardhat": "env TS_NODE_PROJECT=\"tsconfig.test.json\" yarn hardhat test",
17
18
  "lint": "tsdx lint",
18
19
  "prepare": "tsdx build",
19
20
  "size": "size-limit",
@@ -57,10 +58,18 @@
57
58
  "typescript": "^4.5.4"
58
59
  },
59
60
  "dependencies": {
60
- "@aurigami/contracts": "2.6.0",
61
+ "@aurigami/contracts": "2.7.1",
62
+ "@nomiclabs/hardhat-ethers": "^2.0.5",
63
+ "@nomiclabs/hardhat-etherscan": "^3.0.3",
64
+ "@nomiclabs/hardhat-waffle": "^2.0.3",
65
+ "@types/mocha": "^9.1.0",
61
66
  "axios": "^0.24.0",
62
67
  "bignumber.js": "^9.0.2",
68
+ "chai": "^4.3.6",
63
69
  "dotenv": "^16.0.0",
64
- "ethers": "^5.0.0"
70
+ "ethereum-waffle": "^3.4.4",
71
+ "ethers": "^5.6.4",
72
+ "hardhat": "^2.9.3",
73
+ "ts-node": "^10.7.0"
65
74
  }
66
75
  }
@@ -8,7 +8,7 @@ import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/Au
8
8
  import EthRepayHelperABI from "@aurigami/contracts/artifacts/contracts/EthRepayHelper.sol/EthRepayHelper.json"
9
9
  import { AuErc20, AuETH, AuriLens, Comptroller, EthRepayHelper } from "@aurigami/contracts/typechain";
10
10
  import { TransactionResponse } from '@ethersproject/abstract-provider';
11
- import { networkAddresses, ETHAddress, ONE_YEAR, INF, ONE_DAY } from "./constants";
11
+ import { networkAddresses, ETHAddress, ONE_YEAR, INF, ONE_DAY, DEPOSIT_NEAR_REWARDS_PER_WEEK, BORROW_NEAR_REWARDS_PER_WEEK } from "./constants";
12
12
  import BigNumber from "bignumber.js";
13
13
  import { decimalFactor, isSameAddress, calcLMRewardApr, getCurrentTimestamp } from './helpers';
14
14
  import { Token, PLYToken } from './token';
@@ -211,9 +211,12 @@ export class MoneyMarketRead extends BlockchainEntityRead {
211
211
 
212
212
  private getDepositNEARRewardPerWeek(): TokenAmount {
213
213
  const NEARToken = new Token(networkAddresses.tokens.WNEAR, getDecimal(networkAddresses.tokens.WNEAR));
214
- const rewardStopTime = 1650463200;
215
- if (isSameAddress(this.underlying.address, networkAddresses.tokens.USDC) && getCurrentTimestamp() <= rewardStopTime) {
216
- return new TokenAmount(NEARToken, "1250", false);
214
+ const rewardStartTime = 1650636000;
215
+ const rewardStopTime = 1651845600; // May 06, 2022 2 PM GMT
216
+ const currentTime = getCurrentTimestamp();
217
+ if (currentTime <= rewardStopTime && currentTime > rewardStartTime) {
218
+ const reward = DEPOSIT_NEAR_REWARDS_PER_WEEK[this.underlying.address.toLocaleLowerCase()] ?? "0";
219
+ return new TokenAmount(NEARToken, reward, false);
217
220
  } else {
218
221
  return new TokenAmount(NEARToken, "0");
219
222
  }
@@ -221,9 +224,12 @@ export class MoneyMarketRead extends BlockchainEntityRead {
221
224
 
222
225
  private getBorrowNEARRewardPerWeek(): TokenAmount {
223
226
  const NEARToken = new Token(networkAddresses.tokens.WNEAR, getDecimal(networkAddresses.tokens.WNEAR));
224
- const rewardStopTime = 1650463200;
225
- if (isSameAddress(this.underlying.address, networkAddresses.tokens.USDC) && getCurrentTimestamp() <= rewardStopTime) {
226
- return new TokenAmount(NEARToken, "3750", false);
227
+ const rewardStartTime = 1650636000;
228
+ const rewardStopTime = 1651845600; // May 06, 2022 2 PM GMT
229
+ const currentTime = getCurrentTimestamp();
230
+ if (currentTime <= rewardStopTime && currentTime > rewardStartTime) {
231
+ const reward = BORROW_NEAR_REWARDS_PER_WEEK[this.underlying.address.toLocaleLowerCase()] ?? "0";
232
+ return new TokenAmount(NEARToken, reward, false);
227
233
  } else {
228
234
  return new TokenAmount(NEARToken, "0");
229
235
  }
@@ -1,12 +1,18 @@
1
1
  import { Provider } from "@ethersproject/abstract-provider";
2
+ import { TransactionResponse } from '@ethersproject/abstract-provider';
2
3
  import { BlockchainEntity, BlockchainEntityRead } from "./BlockchainEntity";
3
- import { NetworkConnection } from "./types";
4
- import { BigNumber as BN } from "ethers";
4
+ import { Address, NetworkConnection } from "./types";
5
+ import { BigNumber as BN, Contract, utils } from "ethers";
5
6
  import { TransferEventQuery } from "./transfer-event-query";
6
- import { AIRDROP_START_TIMESTAMP, AIRDROP_KEEP_THRESHOLD, AIRDROP_END_TIMESTAMP } from "./constants";
7
- import { getBlockBeforeTimestamp, getCurrentTimestamp } from "./helpers";
7
+ import { AIRDROP_START_TIMESTAMP, AIRDROP_KEEP_THRESHOLD, AIRDROP_END_TIMESTAMP, networkAddresses } from "./constants";
8
+ import AuriAirdropABI from "@aurigami/contracts/artifacts/contracts/AuriAirdrop.sol/AuriAirdrop.json"
9
+ import { getBlockBeforeTimestamp, getCurrentTimestamp, getDecimal } from "./helpers";
8
10
  import AIRDROP_AUTOKEN_INFO from "./airdrop_misc/auTokensInfo.json"
9
11
  import AIRDROP_WHITELIST_ADDRESSES from "./airdrop_misc/whitelist.json"
12
+ import { AuriAirdrop } from "@aurigami/contracts/typechain";
13
+ import assert from 'assert';
14
+ import { TokenAmount } from "./tokenAmount";
15
+ import { Token } from "./token";
10
16
 
11
17
  type AirdropUnderlyingInfo = {
12
18
  minDeposit: BN,
@@ -162,10 +168,16 @@ class AirdropAuTokenKeepTracker extends BlockchainEntityRead {
162
168
  }
163
169
 
164
170
  export class AirdropRead extends BlockchainEntityRead {
171
+ protected _airDrop: AuriAirdrop;
165
172
  private _whitelistedAddresses: Set<string>;
166
173
  private keepTrackers: AirdropAuTokenKeepTracker[] = [];
167
174
  public constructor(networkConnection: NetworkConnection) {
168
175
  super(networkConnection);
176
+ this._airDrop = new Contract(
177
+ networkAddresses.misc.AURI_AIRDROP,
178
+ AuriAirdropABI.abi,
179
+ networkConnection.provider
180
+ ) as AuriAirdrop;
169
181
 
170
182
  this._whitelistedAddresses = new Set(
171
183
  (AIRDROP_WHITELIST_ADDRESSES as string[]).map(e => e.toLocaleLowerCase())
@@ -218,6 +230,45 @@ export class AirdropRead extends BlockchainEntityRead {
218
230
  return keepTracker.isEligible(user);
219
231
  }))).includes(true);
220
232
  }
233
+
234
+ /**
235
+ * Get redeemable rewards amount of user
236
+ */
237
+ public async getRedeemableReward(campaign: string, token: Address, user: Address): Promise<TokenAmount> {
238
+ let tokenInstance: Token = new Token(
239
+ token,
240
+ getDecimal(token),
241
+ );
242
+
243
+ let rewards: BN = await this._airDrop.getRedeemableReward(
244
+ utils.formatBytes32String(campaign),
245
+ token,
246
+ user
247
+ )
248
+
249
+ return new TokenAmount(tokenInstance, rewards.toString());
250
+ }
251
+ }
252
+
253
+ export class AirdropReadWrite extends AirdropRead {
254
+ /**
255
+ * Transfer rewards from multiple campaigns to msg.sender
256
+ */
257
+ public async redeemMultiple(campaigns: string[], tokens: Address[]): Promise<TransactionResponse> {
258
+ assert(campaigns.length == tokens.length, "campaigns and tokens must have the same length");
259
+ return this._airDrop.connect(this._networkConnection.signer!).redeem(
260
+ campaigns.map(e => utils.formatBytes32String(e)),
261
+ tokens,
262
+ await this._networkConnection.signer!.getAddress(),
263
+ );
264
+ }
265
+
266
+ /**
267
+ * Redeem reward from a single campaign
268
+ */
269
+ public async redeemSingle(campaign: string, token: Address): Promise<TransactionResponse> {
270
+ return this.redeemMultiple([campaign], [token]);
271
+ }
221
272
  }
222
273
 
223
274
  export class Airdrop extends BlockchainEntity {
@@ -227,5 +278,7 @@ export class Airdrop extends BlockchainEntity {
227
278
  public read(networkConnection: NetworkConnection): AirdropRead {
228
279
  return new AirdropRead(networkConnection);
229
280
  }
230
-
281
+ public readWrite(networkConnection: NetworkConnection): AirdropReadWrite {
282
+ return new AirdropReadWrite(networkConnection);
283
+ }
231
284
  }
package/src/constants.ts CHANGED
@@ -70,7 +70,8 @@ export const networkAddresses: NetworkAddresses = {
70
70
  AURIFAIRLAUNCH: "0x9F9ceE911509abC6Af899c12ED625B0A6580D6e6".toLowerCase(),
71
71
  AURILENS: '0xC41a5C1625d492436600789469c1CE2eA20CEA6B'.toLowerCase(),
72
72
  TOKENLOCK: '0xDACC02a4Ff16Ea3c1515AdbfdCeb7B1F448B79c8'.toLowerCase(),
73
- ETHREPAYHELPER: "0xa308A5003fA1A25BFdD9418FcEE51d48Dbe441e6".toLowerCase()
73
+ ETHREPAYHELPER: "0xa308A5003fA1A25BFdD9418FcEE51d48Dbe441e6".toLowerCase(),
74
+ AURI_AIRDROP: "0x6C42aA5b128B62D6CCf357726D7d13F3888335EC".toLowerCase()
74
75
  },
75
76
  tokens: {
76
77
  AURORA: "0x8bec47865ade3b172a928df8f990bc7f2a3b9f79".toLowerCase(),
@@ -97,3 +98,18 @@ export const INF = BN.from(2).pow(256).sub(1)
97
98
  export const AIRDROP_START_TIMESTAMP = 1649858400;
98
99
  export const AIRDROP_END_TIMESTAMP = 1651068000;
99
100
  export const AIRDROP_KEEP_THRESHOLD = 7 * 86400;
101
+
102
+ export const DEPOSIT_NEAR_REWARDS_PER_WEEK: {[k : string]: string} = Object.fromEntries(
103
+ // lower case all addresses
104
+ Object.entries({
105
+ '0xb12bfca5a55806aaf64e99521918a4bf0fc40802': '36375', // USDC
106
+ '0x4988a896b1227218e4a686fde5eabdcabd91571f': '14550', // USDT
107
+ '0xf4eb217ba2454613b15dbdea6e5f22276410e89e': '3638', // WBTC
108
+ '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE': '14550', // ETH
109
+ '0xc42c30ac6cc15fac9bd938618bcaa1a1fae8501d': '3638', // WNEAR
110
+ }).map(([k, v]) => [k.toLowerCase(), v])
111
+ );
112
+
113
+ export const BORROW_NEAR_REWARDS_PER_WEEK: {[k : string]: string} = {
114
+ // currently 0 for all markets
115
+ }
package/src/decimals.ts CHANGED
@@ -17,5 +17,6 @@ export const decimalRecords: Record<string, number> = {
17
17
  '0x8888682e24dd4df7b7ff2b91fccb575737e433bf': 8,
18
18
  '0xae4fac24dcdae0132c6d04f564dcf059616e9423': 8,
19
19
  '0xce4166363e3a584dac84a47bcd3414b43efcdd1c': 8,
20
- '0xf4eb217ba2454613b15dbdea6e5f22276410e89e': 8
21
- }
20
+ '0xf4eb217ba2454613b15dbdea6e5f22276410e89e': 8,
21
+ '0xc21ff01229e982d7c8b8691163b0a3cb8f357453': 24
22
+ }
package/src/helpers.ts CHANGED
@@ -1,6 +1,8 @@
1
+ import EIP20InterfaceABI from "@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json"
2
+ import { EIP20Interface, IERC20 } from "@aurigami/contracts/typechain";
1
3
  import { Provider } from "@ethersproject/abstract-provider";
2
4
  import BigNumber from "bignumber.js";
3
- import { BigNumber as BN, providers, utils } from "ethers";
5
+ import { BigNumber as BN, Contract, providers, utils } from "ethers";
4
6
  import { decimalRecords } from "./decimals";
5
7
  import { Address, NetworkConnection } from "./types";
6
8
 
@@ -31,6 +33,19 @@ export function validateAndParseAddress(address: Address): Address {
31
33
  export function getDecimal(address: Address): number {
32
34
  return decimalRecords[address.toLowerCase()];
33
35
  }
36
+
37
+ /**
38
+ * Get the decimals of a token via EIP20Interface
39
+ */
40
+ export async function getDecimalsViaContract(address: Address, provider: Provider): Promise<number> {
41
+ let result = getDecimal(address);
42
+ if (result) {
43
+ return result;
44
+ }
45
+ let token: EIP20Interface = new Contract(address, EIP20InterfaceABI.abi, provider) as EIP20Interface;
46
+ return token.decimals();
47
+ }
48
+
34
49
  export function calcLMRewardApr(rewardsValue: BigNumber, totalStakeValue: BigNumber, frequencyPerYear: number): BigNumber {
35
50
  if (totalStakeValue.lte(0)) { // avoid division by zero when there is no stake
36
51
  return new BigNumber('999999999');