@aurigami/sdk 1.5.0-dummy-2 → 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.d.ts +2 -2
- package/dist/constants.d.ts +2 -2
- package/dist/sdk.cjs.development.js +118 -79
- 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 +116 -77
- package/dist/sdk.esm.js.map +1 -1
- package/dist/token.d.ts +1 -1
- package/dist/types.d.ts +6 -2
- package/package.json +1 -1
- package/src/Papermill.ts +28 -10
- package/src/SDK.ts +44 -29
- package/src/constants.ts +4 -4
- package/src/decimals.ts +1 -1
- package/src/deployments/aurora_mainnet.json +1 -1
- package/src/priceFetcher.ts +9 -7
- package/src/token.ts +3 -3
- package/src/types.ts +7 -2
package/dist/token.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -57,10 +57,14 @@ export declare type UserMarketDetails = {
|
|
|
57
57
|
collateralRatio: number;
|
|
58
58
|
underlyingPrice: string;
|
|
59
59
|
};
|
|
60
|
-
export declare type
|
|
61
|
-
|
|
60
|
+
export declare type TokenAPY = {
|
|
61
|
+
address: string;
|
|
62
62
|
apy: string;
|
|
63
63
|
};
|
|
64
|
+
export declare type PLYWNEARPoolDetails = {
|
|
65
|
+
totalStakedLiquidity: TokenValuation;
|
|
66
|
+
APYs: TokenAPY[];
|
|
67
|
+
};
|
|
64
68
|
export declare enum MarketAction {
|
|
65
69
|
Deposit = 0,
|
|
66
70
|
Borrow = 1,
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
PLYWNEARPoolDetails,
|
|
4
4
|
NetworkConnection,
|
|
5
5
|
UserDetails,
|
|
6
6
|
UserMarketDetails,
|
|
@@ -9,15 +9,16 @@ import {
|
|
|
9
9
|
HypotheticalStats,
|
|
10
10
|
MarketAction,
|
|
11
11
|
TokenValuation,
|
|
12
|
+
TokenAPY,
|
|
12
13
|
} from './types';
|
|
13
14
|
import {
|
|
14
15
|
networkAddresses,
|
|
15
16
|
BORROW_LIMIT_BUFFER,
|
|
16
17
|
DECIMAL_PRECISION,
|
|
17
18
|
ONE_DAY,
|
|
18
|
-
|
|
19
|
+
PLYWNEAR_POOL_ID,
|
|
19
20
|
ALL_STAKING_POOLS,
|
|
20
|
-
|
|
21
|
+
PLYWNEAR_REWARD_TOKENS,
|
|
21
22
|
} from './constants';
|
|
22
23
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
23
24
|
import { Contract, BigNumber as BN } from 'ethers';
|
|
@@ -41,7 +42,7 @@ import {
|
|
|
41
42
|
IERC20,
|
|
42
43
|
} from '@aurigami/contracts/typechain';
|
|
43
44
|
import { TokenAmount } from './tokenAmount';
|
|
44
|
-
import {
|
|
45
|
+
import { PLYWNEARToken, PLYToken, Token } from './token';
|
|
45
46
|
import BigNumber from 'bignumber.js';
|
|
46
47
|
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
47
48
|
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
@@ -224,21 +225,28 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
224
225
|
};
|
|
225
226
|
}
|
|
226
227
|
|
|
227
|
-
public async
|
|
228
|
+
public async getPLYWNEARPoolDetails(): Promise<PLYWNEARPoolDetails> {
|
|
228
229
|
var stakedLiquidity: BN, rewardPerSeconds: BN[];
|
|
229
|
-
await this._auriFairLaunch.getPoolInfo(
|
|
230
|
+
await this._auriFairLaunch.getPoolInfo(PLYWNEAR_POOL_ID).then((res) => {
|
|
230
231
|
stakedLiquidity = res.totalStake;
|
|
231
232
|
rewardPerSeconds = res.rewardPerSeconds;
|
|
232
233
|
});
|
|
233
234
|
|
|
234
235
|
let stakedLiquidityAmount = new TokenAmount(
|
|
235
|
-
|
|
236
|
+
PLYWNEARToken,
|
|
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 = [];
|
|
246
|
+
|
|
247
|
+
// Calculate the reward per second in USD
|
|
240
248
|
for (let i = 0; i < rewardPerSeconds!.length; i++) {
|
|
241
|
-
let rewardTokenAddress =
|
|
249
|
+
let rewardTokenAddress = PLYWNEAR_REWARD_TOKENS[i];
|
|
242
250
|
let rewardToken = new Token(
|
|
243
251
|
rewardTokenAddress,
|
|
244
252
|
getDecimal(rewardTokenAddress)
|
|
@@ -252,15 +260,20 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
252
260
|
);
|
|
253
261
|
}
|
|
254
262
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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);
|
|
259
271
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
272
|
+
APYs.push({
|
|
273
|
+
address: rewardTokenAddress,
|
|
274
|
+
apy: apy,
|
|
275
|
+
});
|
|
276
|
+
});
|
|
264
277
|
|
|
265
278
|
return {
|
|
266
279
|
totalStakedLiquidity: {
|
|
@@ -270,11 +283,7 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
270
283
|
amount: totalStakeValuation!.toFixed(DECIMAL_PRECISION),
|
|
271
284
|
},
|
|
272
285
|
},
|
|
273
|
-
|
|
274
|
-
rewardPerSecondValuation,
|
|
275
|
-
totalStakeValuation,
|
|
276
|
-
ONE_DAY * 365
|
|
277
|
-
).toFixed(DECIMAL_PRECISION),
|
|
286
|
+
APYs: APYs,
|
|
278
287
|
};
|
|
279
288
|
}
|
|
280
289
|
|
|
@@ -293,8 +302,14 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
293
302
|
* Get amount and value in $ of staked LP tokens
|
|
294
303
|
*/
|
|
295
304
|
public async stakeBalanceOf(user: string): Promise<TokenValuation> {
|
|
296
|
-
const userInfo = await this._auriFairLaunch.getUserInfo(
|
|
297
|
-
|
|
305
|
+
const userInfo = await this._auriFairLaunch.getUserInfo(
|
|
306
|
+
PLYWNEAR_POOL_ID,
|
|
307
|
+
user
|
|
308
|
+
);
|
|
309
|
+
let stakeAmount = new TokenAmount(
|
|
310
|
+
PLYWNEARToken,
|
|
311
|
+
userInfo.amount.toString()
|
|
312
|
+
);
|
|
298
313
|
|
|
299
314
|
return valuateToken(stakeAmount, this._networkConnection.provider);
|
|
300
315
|
}
|
|
@@ -303,15 +318,15 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
303
318
|
* Get amount and value in $ of LP token in user wallet
|
|
304
319
|
*/
|
|
305
320
|
public async LpBalanceOf(user: string): Promise<TokenValuation> {
|
|
306
|
-
let
|
|
307
|
-
networkAddresses.tokens.
|
|
321
|
+
let lpContract = new Contract(
|
|
322
|
+
networkAddresses.tokens.PLYWNEAR,
|
|
308
323
|
EIP20InterfaceABI.abi,
|
|
309
324
|
this._networkConnection.provider
|
|
310
325
|
) as IERC20;
|
|
311
|
-
let balance = await
|
|
326
|
+
let balance = await lpContract.balanceOf(user);
|
|
312
327
|
|
|
313
328
|
return valuateToken(
|
|
314
|
-
new TokenAmount(
|
|
329
|
+
new TokenAmount(PLYWNEARToken, balance.toString()),
|
|
315
330
|
this._networkConnection.provider
|
|
316
331
|
);
|
|
317
332
|
}
|
|
@@ -403,13 +418,13 @@ export class SdkReadWrite extends SdkRead {
|
|
|
403
418
|
public async stake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
404
419
|
return this._auriFairLaunch
|
|
405
420
|
.connect(this._networkConnection.signer!)
|
|
406
|
-
.deposit(
|
|
421
|
+
.deposit(PLYWNEAR_POOL_ID, amount.rawAmount());
|
|
407
422
|
}
|
|
408
423
|
|
|
409
424
|
public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
|
|
410
425
|
return this._auriFairLaunch
|
|
411
426
|
.connect(this._networkConnection.signer!)
|
|
412
|
-
.withdraw(
|
|
427
|
+
.withdraw(PLYWNEAR_POOL_ID, amount.rawAmount());
|
|
413
428
|
}
|
|
414
429
|
|
|
415
430
|
public async faucetDrip(): Promise<TransactionResponse> {
|
package/src/constants.ts
CHANGED
|
@@ -83,7 +83,7 @@ export const networkAddresses: NetworkAddresses = {
|
|
|
83
83
|
TRI: '0xFa94348467f64D5A457F75F8bc40495D33c65aBB'.toLowerCase(),
|
|
84
84
|
META: '0xc21ff01229e982d7c8b8691163b0a3cb8f357453'.toLocaleLowerCase(),
|
|
85
85
|
PULP: '0x04Ac48711BCdc45b4d223fb021E09DA73c71095e'.toLowerCase(),
|
|
86
|
-
|
|
86
|
+
PLYWNEAR: '0x044b6B0CD3Bb13D2b9057781Df4459C66781dCe7'.toLowerCase(), //TODO: changes this
|
|
87
87
|
},
|
|
88
88
|
};
|
|
89
89
|
|
|
@@ -104,15 +104,15 @@ export const ONE_DAY = 86400;
|
|
|
104
104
|
export const ONE_WEEK = ONE_DAY * 7;
|
|
105
105
|
export const ONE_YEAR = ONE_DAY * 365;
|
|
106
106
|
|
|
107
|
-
export const
|
|
108
|
-
export const
|
|
107
|
+
export const PLYWNEAR_POOL_ID = 0;
|
|
108
|
+
export const PLYWNEAR_REWARD_TOKENS = [
|
|
109
109
|
'0x09C9D464b58d96837f8d8b6f4d9fE4aD408d3A4f', // PLY
|
|
110
110
|
'0xC42C30aC6Cc15faC9bD938618BcaA1a1FaE8501d', // WNEAR
|
|
111
111
|
'0x8BEc47865aDe3B172A928df8f990Bc7f2A3b9f79', // AURORA
|
|
112
112
|
'0xFa94348467f64D5A457F75F8bc40495D33c65aBB', // TRI
|
|
113
113
|
];
|
|
114
114
|
// could call RPC to get all the staking pools but it's not necessary for now
|
|
115
|
-
// export const ALL_STAKING_POOLS = [
|
|
115
|
+
// export const ALL_STAKING_POOLS = [PLYWNEAR_POOL_ID];
|
|
116
116
|
// TODO: fix this
|
|
117
117
|
export const ALL_STAKING_POOLS = [];
|
|
118
118
|
export const INF = BN.from(2).pow(256).sub(1);
|
package/src/decimals.ts
CHANGED
|
@@ -20,5 +20,5 @@ export const decimalRecords: Record<string, number> = {
|
|
|
20
20
|
'0xf4eb217ba2454613b15dbdea6e5f22276410e89e': 8,
|
|
21
21
|
'0xc21ff01229e982d7c8b8691163b0a3cb8f357453': 24,
|
|
22
22
|
'0x04ac48711bcdc45b4d223fb021e09da73c71095e': 18, // PULP
|
|
23
|
-
'
|
|
23
|
+
'0x044b6b0cd3bb13d2b9057781df4459c66781dce7': 18, // PLYWNEAR
|
|
24
24
|
};
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"configReader": "0x347B321c466663D6A0fE9C0ccfCF8cEa86F8ecD3",
|
|
25
25
|
"auriAirdropImpl": "0x94cdA0Da833b384B901d33D5c56FccDE21D5E6e7",
|
|
26
26
|
"auriAirdrop": "0x6C42aA5b128B62D6CCf357726D7d13F3888335EC",
|
|
27
|
-
"
|
|
27
|
+
"ply_wnear_lp": "0x044b6B0CD3Bb13D2b9057781Df4459C66781dCe7",
|
|
28
28
|
"PULP": "0x04Ac48711BCdc45b4d223fb021E09DA73c71095e",
|
|
29
29
|
"test": {}
|
|
30
30
|
}
|
package/src/priceFetcher.ts
CHANGED
|
@@ -233,7 +233,7 @@ export async function fetchPrice(
|
|
|
233
233
|
address: Address,
|
|
234
234
|
provider: providers.Provider
|
|
235
235
|
): Promise<BigNumber> {
|
|
236
|
-
if (isSameAddress(address, networkAddresses.tokens.
|
|
236
|
+
if (isSameAddress(address, networkAddresses.tokens.PLYWNEAR)) {
|
|
237
237
|
return fetchLPPrice(address, provider);
|
|
238
238
|
} else if (isSameAddress(address, networkAddresses.tokens.PLY)) {
|
|
239
239
|
return fetchPLYPrice(provider);
|
|
@@ -244,8 +244,10 @@ export async function fetchPrice(
|
|
|
244
244
|
export async function fetchPLYPrice(
|
|
245
245
|
provider: providers.Provider
|
|
246
246
|
): Promise<BigNumber> {
|
|
247
|
+
//TODO: Fetch PLY price from CEX?
|
|
248
|
+
return new BigNumber(0);
|
|
247
249
|
const LPInfo = await fetchLPPositions(
|
|
248
|
-
networkAddresses.tokens.
|
|
250
|
+
networkAddresses.tokens.PLYWNEAR,
|
|
249
251
|
provider
|
|
250
252
|
);
|
|
251
253
|
|
|
@@ -257,16 +259,16 @@ export async function fetchPLYPrice(
|
|
|
257
259
|
assert(isSameAddress(plyAddress, networkAddresses.tokens.PLY));
|
|
258
260
|
const plyDecimal = getDecimal(plyAddress);
|
|
259
261
|
|
|
260
|
-
const
|
|
261
|
-
assert(isSameAddress(
|
|
262
|
-
const
|
|
262
|
+
const wnearAddress = LPInfo.token1;
|
|
263
|
+
assert(isSameAddress(wnearAddress, networkAddresses.tokens.WNEAR));
|
|
264
|
+
const wnearDecimal = getDecimal(wnearAddress);
|
|
263
265
|
|
|
264
266
|
// (token0Price * reserve0) / 10^decimal0 = (token1Price * reserve1) / 10^decimal1
|
|
265
267
|
// token0Price = (token1Price * reserve1) * 10^decimal0 / 10^decimal1 / reserve0
|
|
266
|
-
return (await fetchPrice(
|
|
268
|
+
return (await fetchPrice(wnearAddress, provider))
|
|
267
269
|
.multipliedBy(LPInfo.reserve1.toString())
|
|
268
270
|
.multipliedBy(decimalFactor(plyDecimal))
|
|
269
|
-
.dividedBy(decimalFactor(
|
|
271
|
+
.dividedBy(decimalFactor(wnearDecimal))
|
|
270
272
|
.dividedBy(LPInfo.reserve0.toString());
|
|
271
273
|
}
|
|
272
274
|
|
package/src/token.ts
CHANGED
|
@@ -15,7 +15,7 @@ export const PLYToken = new Token(
|
|
|
15
15
|
getDecimal(networkAddresses.tokens.PLY)
|
|
16
16
|
);
|
|
17
17
|
|
|
18
|
-
export const
|
|
19
|
-
networkAddresses.tokens.
|
|
20
|
-
getDecimal(networkAddresses.tokens.
|
|
18
|
+
export const PLYWNEARToken = new Token(
|
|
19
|
+
networkAddresses.tokens.PLYWNEAR,
|
|
20
|
+
getDecimal(networkAddresses.tokens.PLYWNEAR)
|
|
21
21
|
);
|
package/src/types.ts
CHANGED
|
@@ -81,11 +81,16 @@ export type UserMarketDetails = {
|
|
|
81
81
|
underlyingPrice: string;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
export type
|
|
85
|
-
|
|
84
|
+
export type TokenAPY = {
|
|
85
|
+
address: string;
|
|
86
86
|
apy: string;
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
+
export type PLYWNEARPoolDetails = {
|
|
90
|
+
totalStakedLiquidity: TokenValuation;
|
|
91
|
+
APYs: TokenAPY[];
|
|
92
|
+
};
|
|
93
|
+
|
|
89
94
|
export enum MarketAction {
|
|
90
95
|
Deposit = 0,
|
|
91
96
|
Borrow,
|