@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/Papermill.d.ts +2 -0
- package/dist/sdk.cjs.development.js +80 -40
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +80 -40
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types.d.ts +5 -1
- package/package.json +1 -1
- package/src/Papermill.ts +28 -10
- package/src/SDK.ts +20 -13
- package/src/types.ts +6 -1
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
|
-
|
|
66
|
+
APYs: TokenAPY[];
|
|
63
67
|
};
|
|
64
68
|
export declare enum MarketAction {
|
|
65
69
|
Deposit = 0,
|
package/package.json
CHANGED
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
|
|
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(
|
|
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 =
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
let nextUnlockPortion =
|
|
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
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
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
|
-
|
|
91
|
+
APYs: TokenAPY[];
|
|
87
92
|
};
|
|
88
93
|
|
|
89
94
|
export enum MarketAction {
|