@aurigami/sdk 1.6.0-no-src → 1.6.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.
Files changed (39) hide show
  1. package/dist/SDK.d.ts +9 -0
  2. package/dist/contracts/Multicall.d.ts +18 -0
  3. package/dist/contracts/Papermill.d.ts +8 -0
  4. package/dist/sdk.cjs.development.js +102841 -40
  5. package/dist/sdk.cjs.development.js.map +1 -1
  6. package/dist/sdk.cjs.production.min.js +1 -1
  7. package/dist/sdk.cjs.production.min.js.map +1 -1
  8. package/dist/sdk.esm.js +102841 -40
  9. package/dist/sdk.esm.js.map +1 -1
  10. package/package.json +4 -3
  11. package/src/SDK.ts +430 -0
  12. package/src/abis/Faucet.json +157 -0
  13. package/src/abis/IUniswapV2Pair.json +663 -0
  14. package/src/abis/Oracle.json +247 -0
  15. package/src/abis/dummy.json +3 -0
  16. package/src/consts/constants.ts +146 -0
  17. package/src/consts/decimals.ts +24 -0
  18. package/src/consts/deployments.ts +4 -0
  19. package/src/consts/dummy.ts +38 -0
  20. package/src/consts/index.ts +4 -0
  21. package/src/contracts/MoneyMarket.ts +510 -0
  22. package/src/contracts/Multicall.ts +55 -0
  23. package/src/contracts/Papermill.ts +271 -0
  24. package/src/contracts/Staking.ts +183 -0
  25. package/src/contracts/airdrop-lottery.ts +320 -0
  26. package/src/contracts/index.ts +4 -0
  27. package/src/entities/BlockchainEntity.ts +33 -0
  28. package/src/entities/index.ts +3 -0
  29. package/src/entities/token.ts +21 -0
  30. package/src/entities/tokenAmount.ts +42 -0
  31. package/src/helpers/aurora-api-helpers.ts +20 -0
  32. package/src/helpers/helpers.ts +97 -0
  33. package/src/helpers/index.ts +4 -0
  34. package/src/helpers/priceFetcher.ts +317 -0
  35. package/src/helpers/transfer-event-query.ts +70 -0
  36. package/src/index.ts +13 -0
  37. package/src/misc/airdrop_misc/auTokensInfo.json +34 -0
  38. package/src/misc/airdrop_misc/whitelist.json +102629 -0
  39. package/src/types/index.ts +106 -0
@@ -0,0 +1,271 @@
1
+ import AuriFairLaunchABI from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
2
+ import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
3
+ import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
4
+ import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
5
+ import PulpABI from '@aurigami/contracts/artifacts/contracts/PULP.sol/PULP.json';
6
+ import {
7
+ AuriFairLaunch,
8
+ AuriLens,
9
+ Comptroller,
10
+ IERC20,
11
+ PULP,
12
+ } from '@aurigami/contracts/typechain';
13
+ import { TransactionResponse } from '@ethersproject/abstract-provider';
14
+ import BigNumber from 'bignumber.js';
15
+ import { BigNumber as BN, Contract } from 'ethers';
16
+ import * as consts from '../consts';
17
+ import {
18
+ BlockchainEntity,
19
+ BlockchainEntityRead,
20
+ Token,
21
+ TokenAmount,
22
+ } from '../entities';
23
+ import * as helpers from '../helpers';
24
+ import { Address, NetworkConnection, UserLockingDetails } from '../types';
25
+
26
+ const LOCKING_DENOMINATOR = BN.from(10000);
27
+ export class PapermillRead extends BlockchainEntityRead {
28
+ public plyToken: Token;
29
+ public pulpToken: Token;
30
+
31
+ protected _ply: IERC20;
32
+ protected _pulp: PULP;
33
+ protected _comptroller: Comptroller;
34
+ protected _auriFairLaunch: AuriFairLaunch;
35
+ protected _auriLens: AuriLens;
36
+
37
+ constructor(networkConnection: NetworkConnection) {
38
+ super(networkConnection);
39
+
40
+ let plyAddress = consts.networkAddresses.tokens.PLY;
41
+ let pulpAddress = consts.networkAddresses.tokens.PULP;
42
+
43
+ this.plyToken = new Token(plyAddress, helpers.getDecimal(plyAddress));
44
+ this.pulpToken = new Token(pulpAddress, helpers.getDecimal(pulpAddress));
45
+
46
+ this._comptroller = new Contract(
47
+ consts.networkAddresses.misc.COMPTROLLER,
48
+ ComptrollerABI.abi,
49
+ networkConnection.provider
50
+ ) as Comptroller;
51
+ this._auriFairLaunch = new Contract(
52
+ consts.networkAddresses.misc.AURIFAIRLAUNCH,
53
+ AuriFairLaunchABI.abi,
54
+ networkConnection.provider
55
+ ) as AuriFairLaunch;
56
+ this._auriLens = new Contract(
57
+ consts.networkAddresses.misc.AURILENS,
58
+ AuriLensABI.abi,
59
+ networkConnection.provider
60
+ ) as AuriLens;
61
+ this._ply = new Contract(
62
+ plyAddress,
63
+ EIP20InterfaceABI.abi,
64
+ networkConnection.provider
65
+ ) as IERC20;
66
+ this._pulp = new Contract(
67
+ pulpAddress,
68
+ PulpABI.abi,
69
+ networkConnection.provider
70
+ ) as PULP;
71
+ }
72
+
73
+ public async getPlyBalance(userAddress: Address): Promise<TokenAmount> {
74
+ const plyBalance = await this._ply.balanceOf(userAddress);
75
+ return new TokenAmount(this.plyToken, plyBalance.toString());
76
+ }
77
+
78
+ public async getPulpBalance(userAddress: Address): Promise<TokenAmount> {
79
+ const pulpBalance = await this._pulp.balanceOf(userAddress);
80
+ return new TokenAmount(this.pulpToken, pulpBalance.toString());
81
+ }
82
+
83
+ /**
84
+ * Get all unclaimed PLY reward of the user in all markets + all staking pools
85
+ */
86
+ public async getUnclaimedPlyReward(
87
+ userAddress: Address
88
+ ): Promise<TokenAmount> {
89
+ let rewardBalancesMetadata = await this._auriLens.callStatic.claimRewards(
90
+ this._comptroller.address,
91
+ this._auriFairLaunch.address,
92
+ consts.ALL_STAKING_POOLS,
93
+ { from: userAddress }
94
+ );
95
+
96
+ return new TokenAmount(
97
+ this.plyToken,
98
+ rewardBalancesMetadata.plyAccrured.toString()
99
+ );
100
+ }
101
+
102
+ private getWeek(timestamp: number): number {
103
+ return BN.from(timestamp - consts.REWARD_CLAIM_START)
104
+ .div(consts.ONE_WEEK)
105
+ .toNumber();
106
+ }
107
+
108
+ /**
109
+ * Get all locking details of the user in all markets + all staking pools
110
+ */
111
+ public async getLockingDetails(
112
+ userAddress: Address
113
+ ): Promise<UserLockingDetails> {
114
+ const currentWeek = this.getWeek(helpers.getCurrentTimestamp());
115
+ var promises: any[] = [];
116
+
117
+ promises.push(
118
+ this._auriLens.getPercentLock(
119
+ this._pulp.address,
120
+ userAddress,
121
+ currentWeek
122
+ )
123
+ );
124
+ promises.push(
125
+ this._auriLens.getPercentLock(
126
+ this._pulp.address,
127
+ userAddress,
128
+ currentWeek + 1
129
+ )
130
+ );
131
+ promises.push(this.getUnclaimedPlyReward(userAddress));
132
+
133
+ var values: any[] = await Promise.all(promises);
134
+
135
+ let percentLockCurrentWeek = BN.from(values[0]);
136
+ let percentLockNextWeek = BN.from(values[1]);
137
+ let totalRewards = values[2] as TokenAmount;
138
+
139
+ let [pulpAmountCurrentWeek, plyAmountCurrentWeek] =
140
+ await this._pulp.calcLockAmount(userAddress, totalRewards.rawAmount());
141
+
142
+ // Predict next week lock amount = totalRewards * percentLock next week
143
+ // This doesn't take (the reward that user might earn in the next week) into account
144
+ let plyAmountNextWeek = percentLockNextWeek
145
+ .mul(totalRewards.rawAmount())
146
+ .div(LOCKING_DENOMINATOR);
147
+ let pulpAmountNextWeek = BN.from(totalRewards.rawAmount()).sub(
148
+ plyAmountNextWeek
149
+ );
150
+
151
+ // we need to divide these two number by 10000 and multiple by 100 to get the percentage
152
+ // I need to use BigNumber to do this because BN of ethers.js doesn't support floating point
153
+ let currentUnlockPortion = LOCKING_DENOMINATOR.sub(
154
+ percentLockCurrentWeek
155
+ ).toString();
156
+ let nextUnlockPortion =
157
+ LOCKING_DENOMINATOR.sub(percentLockNextWeek).toString();
158
+
159
+ return {
160
+ vestingStart: consts.REWARD_CLAIM_START,
161
+ currentUnlockPortion: new BigNumber(currentUnlockPortion)
162
+ .dividedBy(100)
163
+ .toNumber(),
164
+ accruedPly: totalRewards,
165
+ currentPly: new TokenAmount(
166
+ this.plyToken,
167
+ plyAmountCurrentWeek.toString()
168
+ ),
169
+ currentPulp: new TokenAmount(
170
+ this.pulpToken,
171
+ pulpAmountCurrentWeek.toString()
172
+ ),
173
+ //
174
+ nextUnlockPortion: new BigNumber(nextUnlockPortion)
175
+ .dividedBy(100)
176
+ .toNumber(),
177
+ nextPly: new TokenAmount(this.plyToken, plyAmountNextWeek.toString()),
178
+ nextPulp: new TokenAmount(this.pulpToken, pulpAmountNextWeek.toString()),
179
+ };
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 consts.REWARD_CLAIM_START + consts.ONE_WEEK * weekId.toNumber();
199
+ }
200
+
201
+ /**
202
+ * Get the start timestamp of next week of the papermill contract.
203
+ *
204
+ * This is a sync function!
205
+ *
206
+ * @returns the timestamp in seconds
207
+ */
208
+ public getNextWeekTimestamp(): number {
209
+ const nextWeek = this.getWeek(helpers.getCurrentTimestamp()) + 1;
210
+ return consts.REWARD_CLAIM_START + consts.ONE_WEEK * nextWeek;
211
+ }
212
+
213
+ public async getUnlockPortionAt(
214
+ userAddress: Address,
215
+ timestamp: number
216
+ ): Promise<number> {
217
+ let lockPortion = await this._auriLens.getPercentLock(
218
+ this._pulp.address,
219
+ userAddress,
220
+ this.getWeek(timestamp)
221
+ );
222
+
223
+ let unlockPortion = LOCKING_DENOMINATOR.sub(lockPortion);
224
+
225
+ return unlockPortion.toNumber() / 100;
226
+ }
227
+ }
228
+
229
+ export class PapermillReadWrite extends PapermillRead {
230
+ constructor(networkConnection: NetworkConnection) {
231
+ super(networkConnection);
232
+ }
233
+
234
+ /**
235
+ * Redeem PLY from PULP and transfer PLY to another address
236
+ * @param recipient Address that will receive the PLY.
237
+ * @param amount Amount of PULP to be converted to PLY.
238
+ * Set to ethers.constants.MaxUint256 for max redeem.
239
+ */
240
+ public async redeem(
241
+ recipient: Address,
242
+ amount: TokenAmount
243
+ ): Promise<TransactionResponse> {
244
+ return this._pulp
245
+ .connect(this._networkConnection.signer!)
246
+ .redeem(recipient, amount.rawAmount());
247
+ }
248
+
249
+ /**
250
+ * Redeem PLY from PULP and transfer PLY to msg.sender
251
+ * @param amount Amount of PULP to be converted to PLY.
252
+ * Set to ethers.constants.MaxUint256 for max redeem.
253
+ */
254
+ public async selfRedeem(amount: TokenAmount): Promise<TransactionResponse> {
255
+ let msgSender: string = await this._networkConnection.signer!.getAddress();
256
+ return this.redeem(msgSender, amount);
257
+ }
258
+ }
259
+
260
+ export class Papermill extends BlockchainEntity {
261
+ constructor() {
262
+ super();
263
+ }
264
+ public read(networkConnection: NetworkConnection): PapermillRead {
265
+ return new PapermillRead(networkConnection);
266
+ }
267
+
268
+ public readWrite(networkConnection: NetworkConnection): PapermillReadWrite {
269
+ return new PapermillReadWrite(networkConnection);
270
+ }
271
+ }
@@ -0,0 +1,183 @@
1
+ import AuriFairLaunchABI from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
2
+ import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
3
+ import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
4
+ import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
5
+ import {
6
+ AuriFairLaunch,
7
+ AuriLens,
8
+ Comptroller,
9
+ IERC20,
10
+ } from '@aurigami/contracts/typechain';
11
+ import { TransactionResponse } from '@ethersproject/abstract-provider';
12
+ import BigNumber from 'bignumber.js';
13
+ import { BigNumber as BN, Contract } from 'ethers';
14
+ import * as consts from '../consts';
15
+ import {
16
+ BlockchainEntity,
17
+ BlockchainEntityRead,
18
+ PLYWNEARToken,
19
+ Token,
20
+ TokenAmount,
21
+ } from '../entities';
22
+ import { calcLMRewardApr, getDecimal } from '../helpers';
23
+ import { fetchValuation } from '../helpers/priceFetcher';
24
+ import { NetworkConnection, PLYWNEARPoolDetails, TokenAPY } from '../types';
25
+
26
+ export class StakingRead extends BlockchainEntityRead {
27
+ protected _comptroller: Comptroller;
28
+ protected _auriFairLaunch: AuriFairLaunch;
29
+ protected _auriLens: AuriLens;
30
+ constructor(networkConnection: NetworkConnection) {
31
+ super(networkConnection);
32
+ this._comptroller = new Contract(
33
+ consts.networkAddresses.misc.COMPTROLLER,
34
+ ComptrollerABI.abi,
35
+ networkConnection.provider
36
+ ) as Comptroller;
37
+ this._auriFairLaunch = new Contract(
38
+ consts.networkAddresses.misc.AURIFAIRLAUNCH,
39
+ AuriFairLaunchABI.abi,
40
+ networkConnection.provider
41
+ ) as AuriFairLaunch;
42
+ this._auriLens = new Contract(
43
+ consts.networkAddresses.misc.AURILENS,
44
+ AuriLensABI.abi,
45
+ networkConnection.provider
46
+ ) as AuriLens;
47
+ }
48
+
49
+ public async getPLYWNEARPoolDetails(): Promise<PLYWNEARPoolDetails> {
50
+ var stakedLiquidity: BN, rewardPerSeconds: BN[];
51
+ await this._auriFairLaunch
52
+ .getPoolInfo(consts.PLYWNEAR_POOL_ID)
53
+ .then((res) => {
54
+ stakedLiquidity = res.totalStake;
55
+ rewardPerSeconds = res.rewardPerSeconds;
56
+ });
57
+
58
+ let stakedLiquidityAmount = new TokenAmount(
59
+ PLYWNEARToken,
60
+ stakedLiquidity!.toString()
61
+ );
62
+
63
+ var totalStakeValuation: BigNumber = await fetchValuation(
64
+ stakedLiquidityAmount,
65
+ this._networkConnection.provider
66
+ );
67
+
68
+ var promises = [];
69
+
70
+ // Calculate the reward per second in USD
71
+ for (let i = 0; i < rewardPerSeconds!.length; i++) {
72
+ let rewardTokenAddress = consts.PLYWNEAR_REWARD_TOKENS[i];
73
+ let rewardToken = new Token(
74
+ rewardTokenAddress,
75
+ getDecimal(rewardTokenAddress)
76
+ );
77
+ let rewardPerSecond = rewardPerSeconds![i];
78
+ promises.push(
79
+ fetchValuation(
80
+ new TokenAmount(rewardToken, rewardPerSecond!.toString()),
81
+ this._networkConnection.provider
82
+ )
83
+ );
84
+ }
85
+
86
+ let APYs: TokenAPY[] = [];
87
+ (await Promise.all(promises)).forEach((rewardPerSecondValuation, i) => {
88
+ let rewardTokenAddress = consts.PLYWNEAR_REWARD_TOKENS[i];
89
+ let apy = calcLMRewardApr(
90
+ rewardPerSecondValuation,
91
+ totalStakeValuation,
92
+ consts.ONE_DAY * 365
93
+ ).toFixed(consts.DECIMAL_PRECISION);
94
+
95
+ APYs.push({
96
+ address: rewardTokenAddress,
97
+ apy: apy,
98
+ });
99
+ });
100
+
101
+ return {
102
+ totalStakedLiquidity: stakedLiquidityAmount,
103
+ APYs: APYs,
104
+ };
105
+ }
106
+
107
+ /**
108
+ * Get amount of staked LP tokens
109
+ */
110
+ public async stakeBalanceOf(user: string): Promise<TokenAmount> {
111
+ const userInfo = await this._auriFairLaunch.getUserInfo(
112
+ consts.PLYWNEAR_POOL_ID,
113
+ user
114
+ );
115
+ return new TokenAmount(PLYWNEARToken, userInfo.amount.toString());
116
+ }
117
+
118
+ /**
119
+ * Get amount of LP token in user wallet
120
+ */
121
+ public async LpBalanceOf(user: string): Promise<TokenAmount> {
122
+ let lpContract = new Contract(
123
+ consts.networkAddresses.tokens.PLYWNEAR,
124
+ EIP20InterfaceABI.abi,
125
+ this._networkConnection.provider
126
+ ) as IERC20;
127
+ let balance = await lpContract.balanceOf(user);
128
+
129
+ return new TokenAmount(PLYWNEARToken, balance.toString());
130
+ }
131
+
132
+ public async unclaimedRewardsOf(user: string): Promise<TokenAmount[]> {
133
+ let userInfo = await this._auriFairLaunch.callStatic.updateAndGetUserInfo(
134
+ consts.PLYWNEAR_POOL_ID,
135
+ user,
136
+ { from: user }
137
+ );
138
+
139
+ let rewards = userInfo.unclaimedRewards;
140
+ return rewards.map((reward, i) =>
141
+ TokenAmount.fromAddressAndAmount(
142
+ consts.PLYWNEAR_REWARD_TOKENS[i],
143
+ reward.toString()
144
+ )
145
+ );
146
+ }
147
+ }
148
+
149
+ export class StakingReadWrite extends StakingRead {
150
+ public async stake(amount: TokenAmount): Promise<TransactionResponse> {
151
+ return this._auriFairLaunch
152
+ .connect(this._networkConnection.signer!)
153
+ .deposit(consts.PLYWNEAR_POOL_ID, amount.rawAmount());
154
+ }
155
+
156
+ public async unstake(amount: TokenAmount): Promise<TransactionResponse> {
157
+ const msgSender = await this._networkConnection.signer!.getAddress();
158
+ const amountInput = BN.from(amount.rawAmount());
159
+ const stakedAmount = BN.from(
160
+ (await this.stakeBalanceOf(msgSender)).rawAmount()
161
+ );
162
+ // unstakeAmount = min(amountInput, stakedAmount - 1)
163
+ const unstakeAmount = amountInput.lt(stakedAmount)
164
+ ? amountInput
165
+ : stakedAmount.sub(1);
166
+ return this._auriFairLaunch
167
+ .connect(this._networkConnection.signer!)
168
+ .withdraw(consts.PLYWNEAR_POOL_ID, unstakeAmount);
169
+ }
170
+ }
171
+
172
+ export class Staking extends BlockchainEntity {
173
+ constructor() {
174
+ super();
175
+ }
176
+ public read(networkConnection: NetworkConnection): StakingRead {
177
+ return new StakingRead(networkConnection);
178
+ }
179
+
180
+ public readWrite(networkConnection: NetworkConnection): StakingReadWrite {
181
+ return new StakingReadWrite(networkConnection);
182
+ }
183
+ }