@aurigami/sdk 1.4.7 → 1.5.0-dummy

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.
@@ -0,0 +1,6 @@
1
+ import { ethers, Signer } from 'ethers';
2
+ export declare const AVAX_DEFAULT_PROVIDER_URL = "https://api.avax.network/ext/bc/C/rpc";
3
+ export declare const AVAX_DEFAULT_PROVIDER: ethers.providers.JsonRpcProvider;
4
+ export declare const AURORA_DEFAULT_PROVIDER_URL: string;
5
+ export declare const AURORA_DEFAULT_PROVIDER: ethers.providers.JsonRpcProvider;
6
+ export declare const AURORA_DEFAULT_SIGNER: Signer;
@@ -0,0 +1,6 @@
1
+ import { Address } from '../src/types';
2
+ import { AuriFairLaunch } from '@aurigami/contracts/typechain';
3
+ export declare function impersonate(address: Address): Promise<void>;
4
+ export declare function prepareERC20Balance(tokenAddress: Address, tokenHolder: Address, receiver: Address, amount?: string): Promise<void>;
5
+ export declare function getFairLaunchContract(): Promise<AuriFairLaunch>;
6
+ export declare function createStakingPool(stakeToken: Address): Promise<void>;
package/dist/token.d.ts CHANGED
@@ -4,4 +4,4 @@ export declare class Token {
4
4
  constructor(address: string, decimals: number);
5
5
  }
6
6
  export declare const PLYToken: Token;
7
- export declare const AURPLYToken: Token;
7
+ export declare const PLYUSDCToken: Token;
package/dist/types.d.ts CHANGED
@@ -13,6 +13,10 @@ export declare type CurrencyAmount = {
13
13
  currency: string;
14
14
  amount: string;
15
15
  };
16
+ export declare type TokenValuation = {
17
+ tokenAmount: TokenAmount;
18
+ currencyAmount: CurrencyAmount;
19
+ };
16
20
  export declare type MoneyMarketDetails = {
17
21
  auTokenAddress: string;
18
22
  totalTokenDeposited: TokenAmount;
@@ -31,18 +35,18 @@ export declare type MoneyMarketDetails = {
31
35
  export declare type UserDetails = {
32
36
  markets: UserMarketDetails[];
33
37
  borrowLimit: CurrencyAmount;
34
- accruedPly: TokenAmount;
35
- lockedPly: TokenAmount;
38
+ userLockingDetails: UserLockingDetails;
36
39
  borrowableAmount: CurrencyAmount;
37
40
  };
38
- export declare type LockingDetails = {
41
+ export declare type UserLockingDetails = {
39
42
  vestingStart: number;
40
43
  currentUnlockPortion: number;
44
+ accruedPly: TokenAmount;
45
+ currentPly: TokenAmount;
46
+ currentPulp: TokenAmount;
41
47
  nextUnlockPortion: number;
42
- };
43
- export declare type PlyAuroraPool = {
44
- totalStakedLiquidity: CurrencyAmount;
45
- apy: number;
48
+ nextPly: TokenAmount;
49
+ nextPulp: TokenAmount;
46
50
  };
47
51
  export declare type UserMarketDetails = {
48
52
  market: string;
@@ -53,8 +57,8 @@ export declare type UserMarketDetails = {
53
57
  collateralRatio: number;
54
58
  underlyingPrice: string;
55
59
  };
56
- export declare type PlyAuroraPoolDetails = {
57
- totalStakedLiquidity: TokenAmount;
60
+ export declare type PlyUsdcPoolDetails = {
61
+ totalStakedLiquidity: TokenValuation;
58
62
  apy: string;
59
63
  };
60
64
  export declare enum MarketAction {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.7",
2
+ "version": "1.5.0-dummy",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -13,8 +13,8 @@
13
13
  "scripts": {
14
14
  "start": "tsdx watch",
15
15
  "build": "tsdx build",
16
- "test": "tsdx test",
17
- "test-hardhat": "env TS_NODE_PROJECT=\"tsconfig.test.json\" yarn hardhat test",
16
+ "test": "tsdx test --no-cache",
17
+ "w-hardhat": "env TS_NODE_PROJECT=\"tsconfig.test.json\" yarn hardhat",
18
18
  "lint": "tsdx lint",
19
19
  "prepare": "tsdx build",
20
20
  "size": "size-limit",
@@ -58,7 +58,7 @@
58
58
  "typescript": "^4.5.4"
59
59
  },
60
60
  "dependencies": {
61
- "@aurigami/contracts": "2.7.1",
61
+ "@aurigami/contracts": "3.0.1",
62
62
  "@nomiclabs/hardhat-ethers": "^2.0.5",
63
63
  "@nomiclabs/hardhat-etherscan": "^3.0.3",
64
64
  "@nomiclabs/hardhat-waffle": "^2.0.3",
@@ -0,0 +1,162 @@
1
+ import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
2
+ import { NetworkConnection, Address, UserLockingDetails } from './types';
3
+ import { Contract, BigNumber as BN } from 'ethers';
4
+ import AuriFairLaunchABI from "@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json";
5
+ import PulpABI from '@aurigami/contracts/artifacts/contracts/PULP.sol/PULP.json';
6
+ import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
7
+ import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
8
+ import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
9
+ import { AuriFairLaunch, AuriLens, Comptroller, IERC20, PULP } from "@aurigami/contracts/typechain";
10
+ import { TransactionResponse } from '@ethersproject/abstract-provider';
11
+ import { networkAddresses, ONE_DAY, ALL_STAKING_POOLS, REWARD_CLAIM_START } from "./constants";
12
+ import { getCurrentTimestamp } from './helpers';
13
+ import { Token } from './token';
14
+ import { TokenAmount } from './tokenAmount';
15
+ import { getDecimal } from './helpers';
16
+ import BigNumber from 'bignumber.js';
17
+
18
+
19
+ export class PapermillRead extends BlockchainEntityRead {
20
+ public plyToken: Token;
21
+ public pulpToken: Token;
22
+
23
+ protected _ply: IERC20;
24
+ protected _pulp: PULP;
25
+ protected _comptroller: Comptroller;
26
+ protected _auriFairLaunch: AuriFairLaunch;
27
+ protected _auriLens: AuriLens;
28
+
29
+ constructor(networkConnection: NetworkConnection) {
30
+ super(networkConnection);
31
+
32
+ let plyAddress = networkAddresses.tokens.PLY;
33
+ let pulpAddress = networkAddresses.tokens.PULP;
34
+
35
+ this.plyToken = new Token(
36
+ plyAddress,
37
+ getDecimal(plyAddress),
38
+ );
39
+ this.pulpToken = new Token(
40
+ pulpAddress,
41
+ getDecimal(pulpAddress),
42
+ );
43
+
44
+ this._comptroller = new Contract(networkAddresses.misc.COMPTROLLER, ComptrollerABI.abi, networkConnection.provider) as Comptroller;
45
+ this._auriFairLaunch = new Contract(networkAddresses.misc.AURIFAIRLAUNCH, AuriFairLaunchABI.abi, networkConnection.provider) as AuriFairLaunch;
46
+ this._auriLens = new Contract(networkAddresses.misc.AURILENS, AuriLensABI.abi, networkConnection.provider) as AuriLens;
47
+ this._ply = new Contract(plyAddress, EIP20InterfaceABI.abi, networkConnection.provider) as IERC20;
48
+ this._pulp = new Contract(pulpAddress, PulpABI.abi, networkConnection.provider) as PULP;
49
+ }
50
+
51
+ public async getPlyBalance(userAddress: Address): Promise<TokenAmount> {
52
+ const plyBalance = await this._ply.balanceOf(userAddress);
53
+ return new TokenAmount(this.plyToken, plyBalance.toString());
54
+ }
55
+
56
+ public async getPulpBalance(userAddress: Address): Promise<TokenAmount> {
57
+ const pulpBalance = await this._pulp.balanceOf(userAddress);
58
+ return new TokenAmount(this.pulpToken, pulpBalance.toString());
59
+ }
60
+
61
+ /**
62
+ * Get all unclaimed PLY reward of the user in all markets + all staking pools
63
+ */
64
+ public async getUnclaimedPlyReward(userAddress: Address): Promise<TokenAmount> {
65
+ let rewardBalancesMetadata = await this._auriLens.callStatic.claimRewards(
66
+ this._comptroller.address,
67
+ this._auriFairLaunch.address,
68
+ ALL_STAKING_POOLS,
69
+ {from: userAddress}
70
+ );
71
+
72
+ return new TokenAmount(this.plyToken, rewardBalancesMetadata.plyAccrured.toString());
73
+ }
74
+
75
+ /**
76
+ * Get all locking details of the user in all markets + all staking pools
77
+ */
78
+ public async getLockingDetails(userAddress: Address): Promise<UserLockingDetails> {
79
+ const currentTime = getCurrentTimestamp();
80
+ const currentWeek = BN.from(currentTime - REWARD_CLAIM_START).div(7 * ONE_DAY).toNumber();
81
+ const denominator = BN.from(10000);
82
+ var promises: any[] = [];
83
+
84
+ promises.push(this._auriLens.getPercentLock(this._pulp.address, userAddress, currentWeek));
85
+ promises.push(this._auriLens.getPercentLock(this._pulp.address, userAddress, currentWeek + 1));
86
+ promises.push(this.getUnclaimedPlyReward(userAddress));
87
+
88
+ var values: any[] = await Promise.all(promises);
89
+
90
+ let percentLockCurrentWeek = BN.from(values[0]);
91
+ let percentLockNextWeek = BN.from(values[1]);
92
+ let totalRewards = values[2] as TokenAmount;
93
+
94
+ let [
95
+ pulpAmountCurrentWeek,
96
+ plyAmountCurrentWeek
97
+ ] = await this._pulp.calcLockAmount(userAddress, totalRewards.rawAmount());
98
+
99
+
100
+ // Predict next week lock amount = totalRewards * percentLock next week
101
+ // This doesn't take (the reward that user might earn in the next week) into account
102
+ let plyAmountNextWeek = percentLockNextWeek.mul(totalRewards.rawAmount()).div(denominator);
103
+ let pulpAmountNextWeek = BN.from(totalRewards.rawAmount()).sub(plyAmountNextWeek);
104
+
105
+ // we need to divide these two number by 10000 and multiple by 100 to get the percentage
106
+ // I need to use BigNumber to do this because BN of ethers.js doesn't support floating point
107
+ let currentUnlockPortion = denominator.sub(percentLockCurrentWeek).toString();
108
+ let nextUnlockPortion = denominator.sub(percentLockNextWeek).toString();
109
+
110
+ return {
111
+ vestingStart: REWARD_CLAIM_START,
112
+ currentUnlockPortion: new BigNumber(currentUnlockPortion).dividedBy(100).toNumber(),
113
+ accruedPly: totalRewards,
114
+ currentPly: new TokenAmount(this.plyToken, plyAmountCurrentWeek.toString()),
115
+ currentPulp: new TokenAmount(this.pulpToken, pulpAmountCurrentWeek.toString()),
116
+ //
117
+ nextUnlockPortion: new BigNumber(nextUnlockPortion).dividedBy(100).toNumber(),
118
+ nextPly: new TokenAmount(this.plyToken, plyAmountNextWeek.toString()),
119
+ nextPulp: new TokenAmount(this.pulpToken, pulpAmountNextWeek.toString()),
120
+ };
121
+ }
122
+ }
123
+
124
+ export class PapermillReadWrite extends PapermillRead {
125
+
126
+ constructor(networkConnection: NetworkConnection) {
127
+ super(networkConnection);
128
+ }
129
+
130
+ /**
131
+ * Redeem PLY from PULP and transfer PLY to another address
132
+ * @param recipient Address that will receive the PLY.
133
+ * @param amount Amount of PULP to be converted to PLY.
134
+ * Set to ethers.constants.MaxUint256 for max redeem.
135
+ */
136
+ public async redeem(recipient: Address, amount: TokenAmount): Promise<TransactionResponse> {
137
+ return this._pulp.redeem(recipient, amount.rawAmount());
138
+ }
139
+
140
+ /**
141
+ * Redeem PLY from PULP and transfer PLY to msg.sender
142
+ * @param amount Amount of PULP to be converted to PLY.
143
+ * Set to ethers.constants.MaxUint256 for max redeem.
144
+ */
145
+ public async selfRedeem(amount: TokenAmount): Promise<TransactionResponse> {
146
+ let msgSender: string = await this._networkConnection.signer!.getAddress();
147
+ return this.redeem(msgSender, amount);
148
+ }
149
+ }
150
+
151
+ export class Papermill extends BlockchainEntity {
152
+ constructor() {
153
+ super();
154
+ }
155
+ public read(networkConnection: NetworkConnection): PapermillRead {
156
+ return new PapermillRead(networkConnection);
157
+ }
158
+
159
+ public readWrite(networkConnection: NetworkConnection): PapermillReadWrite {
160
+ return new PapermillReadWrite(networkConnection);
161
+ }
162
+ }
package/src/SDK.ts CHANGED
@@ -1,62 +1,42 @@
1
1
  import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
2
2
  import {
3
- LockingDetails,
4
- PlyAuroraPoolDetails,
3
+ PlyUsdcPoolDetails,
5
4
  NetworkConnection,
6
5
  UserDetails,
7
6
  UserMarketDetails,
8
7
  Address,
9
8
  CurrencyAmount,
10
9
  HypotheticalStats,
11
- MarketAction
10
+ MarketAction,
11
+ TokenValuation
12
12
  } from './types';
13
- import { networkAddresses, BORROW_LIMIT_BUFFER, DECIMAL_PRECISION, REWARDCLAIMSTART, ONE_DAY, AurPlyPid } from './constants';
13
+ import { networkAddresses, BORROW_LIMIT_BUFFER, DECIMAL_PRECISION, ONE_DAY, PlyUsdcPid, ALL_STAKING_POOLS, PLYUSDCRewardTokens } from './constants';
14
14
  import { TransactionResponse } from '@ethersproject/abstract-provider';
15
- import { Contract, BigNumber as BN, ethers, providers } from 'ethers';
16
- import { isSameAddress, decimalFactor, getCurrentTimestamp, calcLMRewardApr } from './helpers';
15
+ import { Contract, BigNumber as BN } from 'ethers';
16
+ import { isSameAddress, decimalFactor, calcLMRewardApr, getDecimal } from './helpers';
17
17
  import { MoneyMarketRead } from './MoneyMarket';
18
- import { fetchValuation, fetchPrice, calcValuation } from './priceFetcher';
19
- import { AuriFairLaunch, Comptroller, TokenLock, AuriLens } from '@aurigami/contracts/typechain';
18
+ import { fetchValuation, fetchPrice, calcValuation, valuateToken } from './priceFetcher';
19
+ import { AuriFairLaunch, Comptroller, AuriLens, IERC20 } from '@aurigami/contracts/typechain';
20
20
  import { TokenAmount } from './tokenAmount';
21
- import { AURPLYToken, PLYToken, Token } from './token';
21
+ import { PLYUSDCToken, PLYToken, Token } from './token';
22
22
  import BigNumber from 'bignumber.js';
23
23
  import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
24
24
  import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
25
- import TokenLockABI from "@aurigami/contracts/artifacts/contracts/TokenLock.sol/TokenLock.json";
26
25
  import AuriFairLaunchABI from "@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json";
27
26
  import FaucetABI from "@aurigami/contracts/artifacts/contracts/mock/Faucet.sol/Faucet.json";
27
+ import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
28
+ import { PapermillRead } from './Papermill';
28
29
 
29
30
  export class SdkRead extends BlockchainEntityRead {
30
31
 
31
32
  protected _comptroller: Comptroller;
32
- protected _tokenLock: TokenLock;
33
33
  protected _auriFairLaunch: AuriFairLaunch;
34
34
  protected _auriLens: AuriLens;
35
- protected _fakeComptroller: Comptroller;
36
35
  constructor(networkConnection: NetworkConnection) {
37
36
  super(networkConnection);
38
37
  this._comptroller = new Contract(networkAddresses.misc.COMPTROLLER, ComptrollerABI.abi, networkConnection.provider) as Comptroller;
39
- this._tokenLock = new Contract(networkAddresses.misc.TOKENLOCK, TokenLockABI.abi, networkConnection.provider) as TokenLock;
40
38
  this._auriFairLaunch = new Contract(networkAddresses.misc.AURIFAIRLAUNCH, AuriFairLaunchABI.abi, networkConnection.provider) as AuriFairLaunch;
41
39
  this._auriLens = new Contract(networkAddresses.misc.AURILENS, AuriLensABI.abi, networkConnection.provider) as AuriLens;
42
- this._fakeComptroller = new Contract(networkAddresses.misc.FAKE_COMPTROLLER, ComptrollerABI.abi, networkConnection.provider) as Comptroller;
43
- }
44
-
45
- public async getLockingDetails(): Promise<LockingDetails> {
46
- const currentTime = getCurrentTimestamp();
47
- const currentWeek = BN.from(currentTime - REWARDCLAIMSTART).div(7 * ONE_DAY).toNumber();
48
- const denominator = 10000;
49
- var promises = [];
50
- promises.push(this._tokenLock.percentageLock(currentWeek));
51
- promises.push(this._tokenLock.percentageLock(currentWeek + 1).catch((err: any) => {return denominator}));
52
- var values: string[] = await Promise.all(promises).then((res) => {
53
- return res.map((v) => {return v.toString()})
54
- });
55
- return {
56
- vestingStart: REWARDCLAIMSTART, // 10 Jan 2023
57
- currentUnlockPortion: (new BigNumber(denominator).minus(values[0])).div(denominator).toNumber(),
58
- nextUnlockPortion: (new BigNumber(denominator).minus(values[1])).div(denominator).toNumber(),
59
- };
60
40
  }
61
41
 
62
42
  public async getUserDetails(userAddress: string): Promise<UserDetails> {
@@ -80,7 +60,7 @@ export class SdkRead extends BlockchainEntityRead {
80
60
  }
81
61
 
82
62
  promises.push(this._comptroller.getAssetsIn(userAddress).then((res: string[]) => {assetsIn = res}));
83
-
63
+
84
64
  await Promise.all(promises);
85
65
  var underlyingPrices = await Promise.all(pricePromises);
86
66
  var depositValues = []
@@ -99,20 +79,14 @@ export class SdkRead extends BlockchainEntityRead {
99
79
  return p;
100
80
  }, new BigNumber(0))
101
81
 
102
- promises = new Array(3);
103
- var accountLiquidity: [BN, BN], rewardBalancesMetadata, lockedAmount: BN;
104
- promises[0] = this._fakeComptroller.getAccountLiquidity(userAddress);
105
- promises[1] = this._auriLens.callStatic.claimAndGetRewardBalancesMetadata(this._comptroller.address, this._auriFairLaunch.address, [], {from: userAddress});
106
- promises[2] = this._tokenLock.lockedAmounts(userAddress);
107
- var values = await Promise.all(promises);
82
+ var accountLiquidity: [BN, BN] = await this._comptroller.getAccountLiquidity(userAddress);
108
83
 
109
- accountLiquidity = values[0]; rewardBalancesMetadata = values[1]; lockedAmount = values[2];
110
84
  var borrowedvaluation: BigNumber = totalBorrowLimit.minus(new BigNumber(accountLiquidity[0].toString()).div(decimalFactor(18)));
111
85
 
112
86
  if (borrowedvaluation.lt("0.00001")) { // Igore dust, dust could be the result of network delay causing collateral valuation calc to be different on vs off chain
113
87
  borrowedvaluation = new BigNumber(0);
114
- }
115
-
88
+ }
89
+
116
90
  const bufferedBorrowLimit: BigNumber = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
117
91
  const minimumBorrowLimitAllowed = borrowedvaluation.div(BORROW_LIMIT_BUFFER);
118
92
 
@@ -128,7 +102,7 @@ export class SdkRead extends BlockchainEntityRead {
128
102
  const moneyMarket: MoneyMarketRead = new MoneyMarketRead(this._networkConnection, auToken.address, auToken.underlying);
129
103
  const borrowLimitMargin = totalBorrowLimit.minus(minimumBorrowLimitAllowed).gt(0) ? totalBorrowLimit.minus(minimumBorrowLimitAllowed) : new BigNumber(0);
130
104
  const maxWithdrawCap: BigNumber = borrowLimitMargin.div(userMarketDetails[i].collateralRatio).div(underlyingPrices[i]);
131
- userMarketDetails[i].maxWithdrawableAmount = userMarketDetails[i].isCollateral && maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
105
+ userMarketDetails[i].maxWithdrawableAmount = userMarketDetails[i].isCollateral && maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
132
106
  ? new TokenAmount(
133
107
  moneyMarket.underlying,
134
108
  maxWithdrawCap.toFixed(24),
@@ -146,8 +120,7 @@ export class SdkRead extends BlockchainEntityRead {
146
120
  currency: "USD",
147
121
  amount: bufferedBorrowLimit.toFixed(DECIMAL_PRECISION)
148
122
  },
149
- accruedPly: new TokenAmount(PLYToken, rewardBalancesMetadata.plyAccrued.toString()),
150
- lockedPly: new TokenAmount(PLYToken, lockedAmount.toString()),
123
+ userLockingDetails: await new PapermillRead(this._networkConnection).getLockingDetails(userAddress),
151
124
  borrowableAmount: {
152
125
  currency: "USD",
153
126
  amount: borrowableAmount.toFixed(DECIMAL_PRECISION)
@@ -155,33 +128,47 @@ export class SdkRead extends BlockchainEntityRead {
155
128
  };
156
129
  }
157
130
 
158
- public async getPlyAuroraPoolDetails(): Promise<PlyAuroraPoolDetails> {
159
- var stakedLiquidity: BN, rewardPerSecond: BN;
160
- var promises = [];
161
- promises.push(this._auriFairLaunch.getPoolInfo(AurPlyPid).then((res) => {
162
- stakedLiquidity = res.totalStake;
163
- rewardPerSecond = res.rewardPerSecond;
164
- }));
165
- await Promise.all(promises);
131
+ public async getPlyUsdcPoolDetails(): Promise<PlyUsdcPoolDetails> {
132
+ var stakedLiquidity: BN, rewardPerSeconds: BN[];
133
+ await this._auriFairLaunch.getPoolInfo(PlyUsdcPid).then((res) => {
134
+ stakedLiquidity = res.totalStake;
135
+ rewardPerSeconds = res.rewardPerSeconds;
136
+ });
166
137
 
167
- promises = [];
168
- var rewardPerSecondValuation: BigNumber, totalStakeValuation: BigNumber;
169
- promises.push(fetchValuation(new TokenAmount(
170
- PLYToken,
171
- rewardPerSecond!.toString()
172
- ), this._networkConnection.provider).then((res) => rewardPerSecondValuation = res));
173
- promises.push(fetchValuation(new TokenAmount(
174
- AURPLYToken,
138
+ let stakedLiquidityAmount = new TokenAmount(
139
+ PLYUSDCToken,
175
140
  stakedLiquidity!.toString()
176
- ), this._networkConnection.provider).then((res) => totalStakeValuation = res));
177
- await Promise.all(promises);
141
+ );
142
+
143
+ var promises = [];
144
+ for (let i = 0; i < rewardPerSeconds!.length; i++) {
145
+ let rewardTokenAddress = PLYUSDCRewardTokens[i];
146
+ let rewardToken = new Token(rewardTokenAddress, getDecimal(rewardTokenAddress));
147
+ let rewardPerSecond = rewardPerSeconds![i];
148
+ promises.push(fetchValuation(
149
+ new TokenAmount(rewardToken, rewardPerSecond!.toString()),
150
+ this._networkConnection.provider
151
+ ));
152
+ }
153
+
154
+ const rewardPerSecondValuation = (await Promise.all(promises)).reduce(
155
+ (p: BigNumber, v: BigNumber) => p.plus(v), new BigNumber(0)
156
+ );
157
+
158
+ var totalStakeValuation: BigNumber = await fetchValuation(
159
+ stakedLiquidityAmount,
160
+ this._networkConnection.provider
161
+ );
178
162
 
179
163
  return {
180
- totalStakedLiquidity: new TokenAmount(
181
- AURPLYToken,
182
- stakedLiquidity!.toString()
183
- ),
184
- apy: calcLMRewardApr(rewardPerSecondValuation!, totalStakeValuation!, ONE_DAY * 365).toFixed(DECIMAL_PRECISION),
164
+ totalStakedLiquidity: {
165
+ tokenAmount: stakedLiquidityAmount,
166
+ currencyAmount: {
167
+ currency: "USD",
168
+ amount: totalStakeValuation!.toFixed(DECIMAL_PRECISION)
169
+ }
170
+ },
171
+ apy: calcLMRewardApr(rewardPerSecondValuation, totalStakeValuation, ONE_DAY * 365).toFixed(DECIMAL_PRECISION),
185
172
  };
186
173
  }
187
174
 
@@ -192,24 +179,43 @@ export class SdkRead extends BlockchainEntityRead {
192
179
  amount: price.toFixed(DECIMAL_PRECISION)
193
180
  }
194
181
  }
195
- public async stakeBalanceOf(user: string): Promise<TokenAmount> {
196
- const userInfo = await this._auriFairLaunch.getUserInfo(AurPlyPid, user);
197
- return new TokenAmount(
198
- AURPLYToken,
182
+
183
+ /**
184
+ * Get amount and value in $ of staked LP tokens
185
+ */
186
+ public async stakeBalanceOf(user: string): Promise<TokenValuation> {
187
+ const userInfo = await this._auriFairLaunch.getUserInfo(PlyUsdcPid, user);
188
+ let stakeAmount = new TokenAmount(
189
+ PLYUSDCToken,
199
190
  userInfo.amount.toString()
200
- )
191
+ );
192
+
193
+ return valuateToken(stakeAmount, this._networkConnection.provider);
194
+ }
195
+
196
+ /**
197
+ * Get amount and value in $ of LP token in user wallet
198
+ */
199
+ public async LpBalanceOf(user: string): Promise<TokenValuation> {
200
+ let lpERC20 = new Contract(networkAddresses.tokens.PLYUSDC, EIP20InterfaceABI.abi, this._networkConnection.provider) as IERC20;
201
+ let balance = await lpERC20.balanceOf(user);
202
+
203
+ return valuateToken(
204
+ new TokenAmount(PLYUSDCToken, balance.toString()),
205
+ this._networkConnection.provider
206
+ );
201
207
  }
202
208
 
203
209
  public calcHypotheticalStats({
204
- userMarketDetail,
210
+ userMarketDetail,
205
211
  currentBorrowLimit,
206
212
  currentBorrowValuation,
207
213
  action,
208
214
  tokenAmount
209
215
  }: {
210
216
  userMarketDetail: UserMarketDetails,
211
- currentBorrowLimit: CurrencyAmount,
212
- currentBorrowValuation: CurrencyAmount,
217
+ currentBorrowLimit: CurrencyAmount,
218
+ currentBorrowValuation: CurrencyAmount,
213
219
  action: MarketAction,
214
220
  tokenAmount?: TokenAmount
215
221
  }): HypotheticalStats {
@@ -245,19 +251,25 @@ export class SdkRead extends BlockchainEntityRead {
245
251
  }
246
252
 
247
253
  export class SdkReadWrite extends SdkRead {
254
+ /**
255
+ * Claim PLY reward in all markets + staking pools
256
+ */
248
257
  public async claim(): Promise<TransactionResponse> {
249
258
  return this._auriLens.connect(this._networkConnection.signer!).claimRewards(
250
259
  this._comptroller.address,
251
260
  this._auriFairLaunch.address,
252
- [AurPlyPid]
261
+ ALL_STAKING_POOLS,
253
262
  );
254
263
  }
264
+
255
265
  public async stake(amount: TokenAmount): Promise<TransactionResponse> {
256
- return this._auriFairLaunch.connect(this._networkConnection.signer!).deposit(AurPlyPid, amount.rawAmount());
266
+ return this._auriFairLaunch.connect(this._networkConnection.signer!).deposit(PlyUsdcPid, amount.rawAmount());
257
267
  }
268
+
258
269
  public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
259
- return this._auriFairLaunch.connect(this._networkConnection.signer!).withdraw(AurPlyPid, amount.rawAmount());
270
+ return this._auriFairLaunch.connect(this._networkConnection.signer!).withdraw(PlyUsdcPid, amount.rawAmount());
260
271
  }
272
+
261
273
  public async faucetDrip(): Promise<TransactionResponse> {
262
274
  const faucet = new Contract(networkAddresses.misc.FAUCET, FaucetABI.abi, this._networkConnection.provider);
263
275
  return faucet.connect(this._networkConnection.signer!).drip();
package/src/constants.ts CHANGED
@@ -66,34 +66,54 @@ export const networkAddresses: NetworkAddresses = {
66
66
  ],
67
67
  misc: {
68
68
  COMPTROLLER: "0x817af6cfAF35BdC1A634d6cC94eE9e4c68369Aeb".toLowerCase(),
69
- FAKE_COMPTROLLER: "0x8072b287b6a95e1Db6C8404BBd78642387dFA16C".toLowerCase(),
70
69
  oracle: "0xC6e5185438e1730959c1eF3551059A3feC744E90".toLowerCase(),
71
- AURIFAIRLAUNCH: "0x9F9ceE911509abC6Af899c12ED625B0A6580D6e6".toLowerCase(),
72
- AURILENS: '0xC41a5C1625d492436600789469c1CE2eA20CEA6B'.toLowerCase(),
70
+ AURIFAIRLAUNCH: "0x6f068608573c840bB27b39458d7d87eB865e19Cc".toLowerCase(),
71
+ AURILENS: '0xFfdFfBDB966Cb84B50e62d70105f2Dbf2e0A1e70'.toLowerCase(),
73
72
  TOKENLOCK: '0xDACC02a4Ff16Ea3c1515AdbfdCeb7B1F448B79c8'.toLowerCase(),
74
73
  ETHREPAYHELPER: "0xa308A5003fA1A25BFdD9418FcEE51d48Dbe441e6".toLowerCase(),
75
74
  AURI_AIRDROP: "0x6C42aA5b128B62D6CCf357726D7d13F3888335EC".toLowerCase()
76
75
  },
77
76
  tokens: {
78
77
  AURORA: "0x8bec47865ade3b172a928df8f990bc7f2a3b9f79".toLowerCase(),
79
- PLY: "0x981bD5832EAB9C8F607940E0e9faCBf8C09ee20a".toLowerCase(),
78
+ PLY: "0x09c9d464b58d96837f8d8b6f4d9fe4ad408d3a4f".toLowerCase(),
80
79
  stNEAR: "0x07f9f7f963c5cd2bbffd30ccfb964be114332e30".toLowerCase(),
81
80
  USDC: '0xb12bfca5a55806aaf64e99521918a4bf0fc40802'.toLowerCase(),
82
81
  WNEAR: '0xC42C30aC6Cc15faC9bD938618BcaA1a1FaE8501d'.toLowerCase(),
83
82
  TRI: '0xFa94348467f64D5A457F75F8bc40495D33c65aBB'.toLowerCase(),
84
83
  META: '0xc21ff01229e982d7c8b8691163b0a3cb8f357453'.toLocaleLowerCase(),
85
- AURPLY: dummyAddress.toLowerCase() // This is dummy
84
+ PULP: '0x04Ac48711BCdc45b4d223fb021E09DA73c71095e'.toLowerCase(),
85
+ PLYUSDC: '0x37cae2b29c18e05ece60111fa01d3ca217046016'.toLowerCase(),
86
86
  }
87
87
  }
88
88
 
89
- export const BORROW_LIMIT_BUFFER = new BigNumber(1);
89
+ // All token that we can calculate the price via oracle + coingecko
90
+ export const PRICE_WHITELISTED = new Set([
91
+ ...networkAddresses.auTokens.map(t => t.underlying),
92
+ networkAddresses.tokens.AURORA,
93
+ networkAddresses.tokens.TRI,
94
+ networkAddresses.tokens.META,
95
+ networkAddresses.tokens.stNEAR,
96
+ ]);
97
+
90
98
 
91
- export const REWARDCLAIMSTART = 1640995200;
99
+ export const REWARD_CLAIM_START = 1651762800; // 5 May 2022 15:00:00 UTC
100
+
101
+ export const BORROW_LIMIT_BUFFER = new BigNumber(1);
92
102
 
93
103
  export const ONE_DAY = 86400;
94
104
  export const ONE_YEAR = ONE_DAY * 365;
95
105
 
96
- export const AurPlyPid = 0;
106
+ export const PlyUsdcPid = 0;
107
+ export const PLYUSDCRewardTokens = [
108
+ '0x09C9D464b58d96837f8d8b6f4d9fE4aD408d3A4f', // PLY
109
+ '0xC42C30aC6Cc15faC9bD938618BcaA1a1FaE8501d', // WNEAR
110
+ '0x8BEc47865aDe3B172A928df8f990Bc7f2A3b9f79', // AURORA
111
+ '0xFa94348467f64D5A457F75F8bc40495D33c65aBB', // TRI
112
+ ]
113
+ // could call RPC to get all the staking pools but it's not necessary for now
114
+ // export const ALL_STAKING_POOLS = [PlyUsdcPid];
115
+ // TODO: fix this
116
+ export const ALL_STAKING_POOLS = [];
97
117
  export const INF = BN.from(2).pow(256).sub(1)
98
118
 
99
119
 
package/src/decimals.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export const decimalRecords: Record<string, number> = {
2
2
  '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee': 18,
3
- '0x981bd5832eab9c8f607940e0e9facbf8c09ee20a': 18,
3
+ '0x09c9d464b58d96837f8d8b6f4d9fe4ad408d3a4f': 18,
4
4
  '0x3195949f267702723bc614cae037cdc8d1e94786': 8,
5
5
  '0xfa94348467f64d5a457f75f8bc40495d33c65abb': 18,
6
6
  '0x07f9f7f963c5cd2bbffd30ccfb964be114332e30': 24,
@@ -18,5 +18,7 @@ export const decimalRecords: Record<string, number> = {
18
18
  '0xae4fac24dcdae0132c6d04f564dcf059616e9423': 8,
19
19
  '0xce4166363e3a584dac84a47bcd3414b43efcdd1c': 8,
20
20
  '0xf4eb217ba2454613b15dbdea6e5f22276410e89e': 8,
21
- '0xc21ff01229e982d7c8b8691163b0a3cb8f357453': 24
21
+ '0xc21ff01229e982d7c8b8691163b0a3cb8f357453': 24,
22
+ '0x04ac48711bcdc45b4d223fb021e09da73c71095e': 18, // PULP
23
+ '0x37cae2b29c18e05ece60111fa01d3ca217046016': 18, // PLYUSDC
22
24
  }
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "deployer": "0xb969526EBc8dd4b1d816Da846eE08180515fFBbC",
3
3
  "unitroller": "0x817af6cfAF35BdC1A634d6cC94eE9e4c68369Aeb",
4
- "comptrollerImpl": "0x45F710Fc648A05f1ed32a72DD7C91c8e73f6b412",
4
+ "comptrollerImpl": "0x559c68b1276d070CB9d6Da75ECeA90FFB6497b18",
5
5
  "comptroller": "0x817af6cfAF35BdC1A634d6cC94eE9e4c68369Aeb",
6
- "PLY": "0x981bD5832EAB9C8F607940E0e9faCBf8C09ee20a",
6
+ "PLY": "0x09c9d464b58d96837f8d8b6f4d9fe4ad408d3a4f",
7
7
  "jumpRateModel": "0x0Bc03bd8d4aF1e8bab2194860268F5774C9d400a",
8
8
  "oracle": "0xC6e5185438e1730959c1eF3551059A3feC744E90",
9
9
  "auTokens": {
@@ -17,10 +17,14 @@
17
17
  "AURORA": "0x8888682E24dd4Df7B7Ff2B91fccB575737E433bf",
18
18
  "TRI": "0x6Ea6C03061bDdCE23d4Ec60B6E6e880c33d24dca"
19
19
  },
20
- "tokenLock": "0xDACC02a4Ff16Ea3c1515AdbfdCeb7B1F448B79c8",
21
- "fairLaunch": "0x9F9ceE911509abC6Af899c12ED625B0A6580D6e6",
22
- "auriLens": "0xC41a5C1625d492436600789469c1CE2eA20CEA6B",
20
+ "fairLaunch": "0x6f068608573c840bB27b39458d7d87eB865e19Cc",
21
+ "auriLens": "0xFfdFfBDB966Cb84B50e62d70105f2Dbf2e0A1e70",
22
+ "auriLensImpl": "0x5Dd06745574b6E40F53E90468e5866fFB37173a0",
23
23
  "ethRepayHelper": "0xa308A5003fA1A25BFdD9418FcEE51d48Dbe441e6",
24
24
  "configReader": "0x347B321c466663D6A0fE9C0ccfCF8cEa86F8ecD3",
25
+ "auriAirdropImpl": "0x94cdA0Da833b384B901d33D5c56FccDE21D5E6e7",
26
+ "auriAirdrop": "0x6C42aA5b128B62D6CCf357726D7d13F3888335EC",
27
+ "ply_usdc_lp": "0x37cAe2B29c18E05ece60111Fa01d3ca217046016",
28
+ "PULP": "0x04Ac48711BCdc45b4d223fb021E09DA73c71095e",
25
29
  "test": {}
26
- }
30
+ }