@aurigami/sdk 1.5.0 → 1.5.1

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/dist/types.d.ts CHANGED
@@ -57,9 +57,13 @@ export declare type UserMarketDetails = {
57
57
  collateralRatio: number;
58
58
  underlyingPrice: string;
59
59
  };
60
+ export declare type TokenAPY = {
61
+ address: string;
62
+ apy: string;
63
+ };
60
64
  export declare type PLYWNEARPoolDetails = {
61
65
  totalStakedLiquidity: TokenValuation;
62
- apy: string;
66
+ APYs: TokenAPY[];
63
67
  };
64
68
  export declare enum MarketAction {
65
69
  Deposit = 0,
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.0",
2
+ "version": "1.5.1",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
package/src/Papermill.ts CHANGED
@@ -27,6 +27,7 @@ import { TokenAmount } from './tokenAmount';
27
27
  import { getDecimal } from './helpers';
28
28
  import BigNumber from 'bignumber.js';
29
29
 
30
+ const LOCKING_DENOMINATOR = BN.from(10000);
30
31
  export class PapermillRead extends BlockchainEntityRead {
31
32
  public plyToken: Token;
32
33
  public pulpToken: Token;
@@ -102,17 +103,18 @@ export class PapermillRead extends BlockchainEntityRead {
102
103
  );
103
104
  }
104
105
 
106
+ private getWeek(timestamp: number): number {
107
+ return BN.from(timestamp - REWARD_CLAIM_START)
108
+ .div(ONE_WEEK)
109
+ .toNumber();
110
+ }
105
111
  /**
106
112
  * Get all locking details of the user in all markets + all staking pools
107
113
  */
108
114
  public async getLockingDetails(
109
115
  userAddress: Address
110
116
  ): Promise<UserLockingDetails> {
111
- const currentTime = getCurrentTimestamp();
112
- const currentWeek = BN.from(currentTime - REWARD_CLAIM_START)
113
- .div(ONE_WEEK)
114
- .toNumber();
115
- const denominator = BN.from(10000);
117
+ const currentWeek = this.getWeek(getCurrentTimestamp());
116
118
  var promises: any[] = [];
117
119
 
118
120
  promises.push(
@@ -144,17 +146,18 @@ export class PapermillRead extends BlockchainEntityRead {
144
146
  // This doesn't take (the reward that user might earn in the next week) into account
145
147
  let plyAmountNextWeek = percentLockNextWeek
146
148
  .mul(totalRewards.rawAmount())
147
- .div(denominator);
149
+ .div(LOCKING_DENOMINATOR);
148
150
  let pulpAmountNextWeek = BN.from(totalRewards.rawAmount()).sub(
149
151
  plyAmountNextWeek
150
152
  );
151
153
 
152
154
  // we need to divide these two number by 10000 and multiple by 100 to get the percentage
153
155
  // I need to use BigNumber to do this because BN of ethers.js doesn't support floating point
154
- let currentUnlockPortion = denominator
155
- .sub(percentLockCurrentWeek)
156
- .toString();
157
- let nextUnlockPortion = denominator.sub(percentLockNextWeek).toString();
156
+ let currentUnlockPortion = LOCKING_DENOMINATOR.sub(
157
+ percentLockCurrentWeek
158
+ ).toString();
159
+ let nextUnlockPortion =
160
+ LOCKING_DENOMINATOR.sub(percentLockNextWeek).toString();
158
161
 
159
162
  return {
160
163
  vestingStart: REWARD_CLAIM_START,
@@ -197,6 +200,21 @@ export class PapermillRead extends BlockchainEntityRead {
197
200
 
198
201
  return REWARD_CLAIM_START + ONE_WEEK * weekId.toNumber();
199
202
  }
203
+
204
+ public async getUnlockPortionAt(
205
+ userAddress: Address,
206
+ timestamp: number
207
+ ): Promise<number> {
208
+ let lockPortion = await this._auriLens.getPercentLock(
209
+ this._pulp.address,
210
+ userAddress,
211
+ this.getWeek(timestamp)
212
+ );
213
+
214
+ let unlockPortion = LOCKING_DENOMINATOR.sub(lockPortion);
215
+
216
+ return unlockPortion.toNumber() / 100;
217
+ }
200
218
  }
201
219
 
202
220
  export class PapermillReadWrite extends PapermillRead {
package/src/SDK.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  HypotheticalStats,
10
10
  MarketAction,
11
11
  TokenValuation,
12
+ TokenAPY,
12
13
  } from './types';
13
14
  import {
14
15
  networkAddresses,
@@ -236,6 +237,11 @@ export class SdkRead extends BlockchainEntityRead {
236
237
  stakedLiquidity!.toString()
237
238
  );
238
239
 
240
+ var totalStakeValuation: BigNumber = await fetchValuation(
241
+ stakedLiquidityAmount,
242
+ this._networkConnection.provider
243
+ );
244
+
239
245
  var promises = [];
240
246
 
241
247
  // Calculate the reward per second in USD
@@ -254,15 +260,20 @@ export class SdkRead extends BlockchainEntityRead {
254
260
  );
255
261
  }
256
262
 
257
- const rewardPerSecondValuation = (await Promise.all(promises)).reduce(
258
- (p: BigNumber, v: BigNumber) => p.plus(v),
259
- new BigNumber(0)
260
- );
263
+ let APYs: TokenAPY[] = [];
264
+ (await Promise.all(promises)).forEach((rewardPerSecondValuation, i) => {
265
+ let rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
266
+ let apy = calcLMRewardApr(
267
+ rewardPerSecondValuation,
268
+ totalStakeValuation,
269
+ ONE_DAY * 365
270
+ ).toFixed(DECIMAL_PRECISION);
261
271
 
262
- var totalStakeValuation: BigNumber = await fetchValuation(
263
- stakedLiquidityAmount,
264
- this._networkConnection.provider
265
- );
272
+ APYs.push({
273
+ address: rewardTokenAddress,
274
+ apy: apy,
275
+ });
276
+ });
266
277
 
267
278
  return {
268
279
  totalStakedLiquidity: {
@@ -272,11 +283,7 @@ export class SdkRead extends BlockchainEntityRead {
272
283
  amount: totalStakeValuation!.toFixed(DECIMAL_PRECISION),
273
284
  },
274
285
  },
275
- apy: calcLMRewardApr(
276
- rewardPerSecondValuation,
277
- totalStakeValuation,
278
- ONE_DAY * 365
279
- ).toFixed(DECIMAL_PRECISION),
286
+ APYs: APYs,
280
287
  };
281
288
  }
282
289
 
package/src/types.ts CHANGED
@@ -81,9 +81,14 @@ export type UserMarketDetails = {
81
81
  underlyingPrice: string;
82
82
  };
83
83
 
84
+ export type TokenAPY = {
85
+ address: string;
86
+ apy: string;
87
+ };
88
+
84
89
  export type PLYWNEARPoolDetails = {
85
90
  totalStakedLiquidity: TokenValuation;
86
- apy: string;
91
+ APYs: TokenAPY[];
87
92
  };
88
93
 
89
94
  export enum MarketAction {