@aurigami/sdk 1.5.0-dummy → 1.5.0-dummy-2

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/src/Papermill.ts CHANGED
@@ -1,21 +1,32 @@
1
1
  import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
2
2
  import { NetworkConnection, Address, UserLockingDetails } from './types';
3
3
  import { Contract, BigNumber as BN } from 'ethers';
4
- import AuriFairLaunchABI from "@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json";
4
+ import AuriFairLaunchABI from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
5
5
  import PulpABI from '@aurigami/contracts/artifacts/contracts/PULP.sol/PULP.json';
6
6
  import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
7
7
  import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
8
8
  import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
9
- import { AuriFairLaunch, AuriLens, Comptroller, IERC20, PULP } from "@aurigami/contracts/typechain";
9
+ import {
10
+ AuriFairLaunch,
11
+ AuriLens,
12
+ Comptroller,
13
+ IERC20,
14
+ PULP,
15
+ } from '@aurigami/contracts/typechain';
10
16
  import { TransactionResponse } from '@ethersproject/abstract-provider';
11
- import { networkAddresses, ONE_DAY, ALL_STAKING_POOLS, REWARD_CLAIM_START } from "./constants";
17
+ import {
18
+ networkAddresses,
19
+ ONE_DAY,
20
+ ALL_STAKING_POOLS,
21
+ REWARD_CLAIM_START,
22
+ ONE_WEEK,
23
+ } from './constants';
12
24
  import { getCurrentTimestamp } from './helpers';
13
25
  import { Token } from './token';
14
26
  import { TokenAmount } from './tokenAmount';
15
27
  import { getDecimal } from './helpers';
16
28
  import BigNumber from 'bignumber.js';
17
29
 
18
-
19
30
  export class PapermillRead extends BlockchainEntityRead {
20
31
  public plyToken: Token;
21
32
  public pulpToken: Token;
@@ -32,20 +43,34 @@ export class PapermillRead extends BlockchainEntityRead {
32
43
  let plyAddress = networkAddresses.tokens.PLY;
33
44
  let pulpAddress = networkAddresses.tokens.PULP;
34
45
 
35
- this.plyToken = new Token(
46
+ this.plyToken = new Token(plyAddress, getDecimal(plyAddress));
47
+ this.pulpToken = new Token(pulpAddress, getDecimal(pulpAddress));
48
+
49
+ this._comptroller = new Contract(
50
+ networkAddresses.misc.COMPTROLLER,
51
+ ComptrollerABI.abi,
52
+ networkConnection.provider
53
+ ) as Comptroller;
54
+ this._auriFairLaunch = new Contract(
55
+ networkAddresses.misc.AURIFAIRLAUNCH,
56
+ AuriFairLaunchABI.abi,
57
+ networkConnection.provider
58
+ ) as AuriFairLaunch;
59
+ this._auriLens = new Contract(
60
+ networkAddresses.misc.AURILENS,
61
+ AuriLensABI.abi,
62
+ networkConnection.provider
63
+ ) as AuriLens;
64
+ this._ply = new Contract(
36
65
  plyAddress,
37
- getDecimal(plyAddress),
38
- );
39
- this.pulpToken = new Token(
66
+ EIP20InterfaceABI.abi,
67
+ networkConnection.provider
68
+ ) as IERC20;
69
+ this._pulp = new Contract(
40
70
  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;
71
+ PulpABI.abi,
72
+ networkConnection.provider
73
+ ) as PULP;
49
74
  }
50
75
 
51
76
  public async getPlyBalance(userAddress: Address): Promise<TokenAmount> {
@@ -61,28 +86,49 @@ export class PapermillRead extends BlockchainEntityRead {
61
86
  /**
62
87
  * Get all unclaimed PLY reward of the user in all markets + all staking pools
63
88
  */
64
- public async getUnclaimedPlyReward(userAddress: Address): Promise<TokenAmount> {
89
+ public async getUnclaimedPlyReward(
90
+ userAddress: Address
91
+ ): Promise<TokenAmount> {
65
92
  let rewardBalancesMetadata = await this._auriLens.callStatic.claimRewards(
66
93
  this._comptroller.address,
67
94
  this._auriFairLaunch.address,
68
95
  ALL_STAKING_POOLS,
69
- {from: userAddress}
96
+ { from: userAddress }
70
97
  );
71
98
 
72
- return new TokenAmount(this.plyToken, rewardBalancesMetadata.plyAccrured.toString());
99
+ return new TokenAmount(
100
+ this.plyToken,
101
+ rewardBalancesMetadata.plyAccrured.toString()
102
+ );
73
103
  }
74
104
 
75
105
  /**
76
106
  * Get all locking details of the user in all markets + all staking pools
77
107
  */
78
- public async getLockingDetails(userAddress: Address): Promise<UserLockingDetails> {
108
+ public async getLockingDetails(
109
+ userAddress: Address
110
+ ): Promise<UserLockingDetails> {
79
111
  const currentTime = getCurrentTimestamp();
80
- const currentWeek = BN.from(currentTime - REWARD_CLAIM_START).div(7 * ONE_DAY).toNumber();
112
+ const currentWeek = BN.from(currentTime - REWARD_CLAIM_START)
113
+ .div(ONE_WEEK)
114
+ .toNumber();
81
115
  const denominator = BN.from(10000);
82
116
  var promises: any[] = [];
83
117
 
84
- promises.push(this._auriLens.getPercentLock(this._pulp.address, userAddress, currentWeek));
85
- promises.push(this._auriLens.getPercentLock(this._pulp.address, userAddress, currentWeek + 1));
118
+ promises.push(
119
+ this._auriLens.getPercentLock(
120
+ this._pulp.address,
121
+ userAddress,
122
+ currentWeek
123
+ )
124
+ );
125
+ promises.push(
126
+ this._auriLens.getPercentLock(
127
+ this._pulp.address,
128
+ userAddress,
129
+ currentWeek + 1
130
+ )
131
+ );
86
132
  promises.push(this.getUnclaimedPlyReward(userAddress));
87
133
 
88
134
  var values: any[] = await Promise.all(promises);
@@ -91,38 +137,69 @@ export class PapermillRead extends BlockchainEntityRead {
91
137
  let percentLockNextWeek = BN.from(values[1]);
92
138
  let totalRewards = values[2] as TokenAmount;
93
139
 
94
- let [
95
- pulpAmountCurrentWeek,
96
- plyAmountCurrentWeek
97
- ] = await this._pulp.calcLockAmount(userAddress, totalRewards.rawAmount());
98
-
140
+ let [pulpAmountCurrentWeek, plyAmountCurrentWeek] =
141
+ await this._pulp.calcLockAmount(userAddress, totalRewards.rawAmount());
99
142
 
100
143
  // Predict next week lock amount = totalRewards * percentLock next week
101
144
  // 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);
145
+ let plyAmountNextWeek = percentLockNextWeek
146
+ .mul(totalRewards.rawAmount())
147
+ .div(denominator);
148
+ let pulpAmountNextWeek = BN.from(totalRewards.rawAmount()).sub(
149
+ plyAmountNextWeek
150
+ );
104
151
 
105
152
  // we need to divide these two number by 10000 and multiple by 100 to get the percentage
106
153
  // 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();
154
+ let currentUnlockPortion = denominator
155
+ .sub(percentLockCurrentWeek)
156
+ .toString();
108
157
  let nextUnlockPortion = denominator.sub(percentLockNextWeek).toString();
109
158
 
110
159
  return {
111
160
  vestingStart: REWARD_CLAIM_START,
112
- currentUnlockPortion: new BigNumber(currentUnlockPortion).dividedBy(100).toNumber(),
161
+ currentUnlockPortion: new BigNumber(currentUnlockPortion)
162
+ .dividedBy(100)
163
+ .toNumber(),
113
164
  accruedPly: totalRewards,
114
- currentPly: new TokenAmount(this.plyToken, plyAmountCurrentWeek.toString()),
115
- currentPulp: new TokenAmount(this.pulpToken, pulpAmountCurrentWeek.toString()),
165
+ currentPly: new TokenAmount(
166
+ this.plyToken,
167
+ plyAmountCurrentWeek.toString()
168
+ ),
169
+ currentPulp: new TokenAmount(
170
+ this.pulpToken,
171
+ pulpAmountCurrentWeek.toString()
172
+ ),
116
173
  //
117
- nextUnlockPortion: new BigNumber(nextUnlockPortion).dividedBy(100).toNumber(),
174
+ nextUnlockPortion: new BigNumber(nextUnlockPortion)
175
+ .dividedBy(100)
176
+ .toNumber(),
118
177
  nextPly: new TokenAmount(this.plyToken, plyAmountNextWeek.toString()),
119
178
  nextPulp: new TokenAmount(this.pulpToken, pulpAmountNextWeek.toString()),
120
179
  };
121
180
  }
181
+
182
+ /**
183
+ * Get the first timestamp that the unlockPortion reach the target
184
+ *
185
+ * @param userAddress currently doesn't matter
186
+ * @param targetUnlockPortion unlockPortion target
187
+ */
188
+ public async getTimestampToUnlock(
189
+ userAddress: Address,
190
+ targetUnlockPortion: number
191
+ ): Promise<number> {
192
+ let weekId = await this._auriLens.getWeekToUnlock(
193
+ this._pulp.address,
194
+ userAddress,
195
+ targetUnlockPortion * 100
196
+ );
197
+
198
+ return REWARD_CLAIM_START + ONE_WEEK * weekId.toNumber();
199
+ }
122
200
  }
123
201
 
124
202
  export class PapermillReadWrite extends PapermillRead {
125
-
126
203
  constructor(networkConnection: NetworkConnection) {
127
204
  super(networkConnection);
128
205
  }
@@ -133,8 +210,13 @@ export class PapermillReadWrite extends PapermillRead {
133
210
  * @param amount Amount of PULP to be converted to PLY.
134
211
  * Set to ethers.constants.MaxUint256 for max redeem.
135
212
  */
136
- public async redeem(recipient: Address, amount: TokenAmount): Promise<TransactionResponse> {
137
- return this._pulp.redeem(recipient, amount.rawAmount());
213
+ public async redeem(
214
+ recipient: Address,
215
+ amount: TokenAmount
216
+ ): Promise<TransactionResponse> {
217
+ return this._pulp
218
+ .connect(this._networkConnection.signer!)
219
+ .redeem(recipient, amount.rawAmount());
138
220
  }
139
221
 
140
222
  /**