@aurigami/sdk 1.4.8 → 1.5.0-dummy-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/MoneyMarket.d.ts +2 -2
- package/dist/Papermill.d.ts +31 -0
- package/dist/SDK.d.ts +6 -7
- package/dist/airdrop-lottery.d.ts +4 -4
- package/dist/constants.d.ts +6 -2
- package/dist/helpers.d.ts +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/priceFetcher.d.ts +6 -4
- package/dist/sdk.cjs.development.js +700 -270
- 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 +690 -268
- package/dist/sdk.esm.js.map +1 -1
- package/dist/token.d.ts +1 -1
- package/dist/tokenAmount.d.ts +1 -1
- package/dist/transfer-event-query.d.ts +4 -4
- package/dist/types.d.ts +13 -9
- package/package.json +5 -11
- package/src/BlockchainEntity.ts +6 -2
- package/src/MoneyMarket.ts +317 -105
- package/src/Papermill.ts +243 -0
- package/src/SDK.ts +307 -147
- package/src/airdrop-lottery.ts +293 -248
- package/src/aurora-api-helpers.ts +11 -6
- package/src/constants.ts +82 -60
- package/src/decimals.ts +5 -3
- package/src/dummy.ts +17 -23
- package/src/helpers.ts +45 -26
- package/src/index.ts +2 -1
- package/src/priceFetcher.ts +256 -103
- package/src/token.ts +16 -16
- package/src/tokenAmount.ts +21 -21
- package/src/transfer-event-query.ts +64 -54
- package/src/types.ts +39 -19
package/src/Papermill.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
2
|
+
import { NetworkConnection, Address, UserLockingDetails } from './types';
|
|
3
|
+
import { Contract, BigNumber as BN } from 'ethers';
|
|
4
|
+
import AuriFairLaunchABI from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
|
|
5
|
+
import PulpABI from '@aurigami/contracts/artifacts/contracts/PULP.sol/PULP.json';
|
|
6
|
+
import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
|
|
7
|
+
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
8
|
+
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
9
|
+
import {
|
|
10
|
+
AuriFairLaunch,
|
|
11
|
+
AuriLens,
|
|
12
|
+
Comptroller,
|
|
13
|
+
IERC20,
|
|
14
|
+
PULP,
|
|
15
|
+
} from '@aurigami/contracts/typechain';
|
|
16
|
+
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
17
|
+
import {
|
|
18
|
+
networkAddresses,
|
|
19
|
+
ONE_DAY,
|
|
20
|
+
ALL_STAKING_POOLS,
|
|
21
|
+
REWARD_CLAIM_START,
|
|
22
|
+
ONE_WEEK,
|
|
23
|
+
} from './constants';
|
|
24
|
+
import { getCurrentTimestamp } from './helpers';
|
|
25
|
+
import { Token } from './token';
|
|
26
|
+
import { TokenAmount } from './tokenAmount';
|
|
27
|
+
import { getDecimal } from './helpers';
|
|
28
|
+
import BigNumber from 'bignumber.js';
|
|
29
|
+
|
|
30
|
+
export class PapermillRead extends BlockchainEntityRead {
|
|
31
|
+
public plyToken: Token;
|
|
32
|
+
public pulpToken: Token;
|
|
33
|
+
|
|
34
|
+
protected _ply: IERC20;
|
|
35
|
+
protected _pulp: PULP;
|
|
36
|
+
protected _comptroller: Comptroller;
|
|
37
|
+
protected _auriFairLaunch: AuriFairLaunch;
|
|
38
|
+
protected _auriLens: AuriLens;
|
|
39
|
+
|
|
40
|
+
constructor(networkConnection: NetworkConnection) {
|
|
41
|
+
super(networkConnection);
|
|
42
|
+
|
|
43
|
+
let plyAddress = networkAddresses.tokens.PLY;
|
|
44
|
+
let pulpAddress = networkAddresses.tokens.PULP;
|
|
45
|
+
|
|
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(
|
|
65
|
+
plyAddress,
|
|
66
|
+
EIP20InterfaceABI.abi,
|
|
67
|
+
networkConnection.provider
|
|
68
|
+
) as IERC20;
|
|
69
|
+
this._pulp = new Contract(
|
|
70
|
+
pulpAddress,
|
|
71
|
+
PulpABI.abi,
|
|
72
|
+
networkConnection.provider
|
|
73
|
+
) as PULP;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public async getPlyBalance(userAddress: Address): Promise<TokenAmount> {
|
|
77
|
+
const plyBalance = await this._ply.balanceOf(userAddress);
|
|
78
|
+
return new TokenAmount(this.plyToken, plyBalance.toString());
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public async getPulpBalance(userAddress: Address): Promise<TokenAmount> {
|
|
82
|
+
const pulpBalance = await this._pulp.balanceOf(userAddress);
|
|
83
|
+
return new TokenAmount(this.pulpToken, pulpBalance.toString());
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get all unclaimed PLY reward of the user in all markets + all staking pools
|
|
88
|
+
*/
|
|
89
|
+
public async getUnclaimedPlyReward(
|
|
90
|
+
userAddress: Address
|
|
91
|
+
): Promise<TokenAmount> {
|
|
92
|
+
let rewardBalancesMetadata = await this._auriLens.callStatic.claimRewards(
|
|
93
|
+
this._comptroller.address,
|
|
94
|
+
this._auriFairLaunch.address,
|
|
95
|
+
ALL_STAKING_POOLS,
|
|
96
|
+
{ from: userAddress }
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return new TokenAmount(
|
|
100
|
+
this.plyToken,
|
|
101
|
+
rewardBalancesMetadata.plyAccrured.toString()
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Get all locking details of the user in all markets + all staking pools
|
|
107
|
+
*/
|
|
108
|
+
public async getLockingDetails(
|
|
109
|
+
userAddress: Address
|
|
110
|
+
): 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);
|
|
116
|
+
var promises: any[] = [];
|
|
117
|
+
|
|
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
|
+
);
|
|
132
|
+
promises.push(this.getUnclaimedPlyReward(userAddress));
|
|
133
|
+
|
|
134
|
+
var values: any[] = await Promise.all(promises);
|
|
135
|
+
|
|
136
|
+
let percentLockCurrentWeek = BN.from(values[0]);
|
|
137
|
+
let percentLockNextWeek = BN.from(values[1]);
|
|
138
|
+
let totalRewards = values[2] as TokenAmount;
|
|
139
|
+
|
|
140
|
+
let [pulpAmountCurrentWeek, plyAmountCurrentWeek] =
|
|
141
|
+
await this._pulp.calcLockAmount(userAddress, totalRewards.rawAmount());
|
|
142
|
+
|
|
143
|
+
// Predict next week lock amount = totalRewards * percentLock next week
|
|
144
|
+
// This doesn't take (the reward that user might earn in the next week) into account
|
|
145
|
+
let plyAmountNextWeek = percentLockNextWeek
|
|
146
|
+
.mul(totalRewards.rawAmount())
|
|
147
|
+
.div(denominator);
|
|
148
|
+
let pulpAmountNextWeek = BN.from(totalRewards.rawAmount()).sub(
|
|
149
|
+
plyAmountNextWeek
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
// we need to divide these two number by 10000 and multiple by 100 to get the percentage
|
|
153
|
+
// 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();
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
vestingStart: 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 getTimestampToUnlock(
|
|
189
|
+
userAddress: Address,
|
|
190
|
+
targetUnlockPortion: number
|
|
191
|
+
): number {
|
|
192
|
+
let lockPortion = 100 - targetUnlockPortion;
|
|
193
|
+
if (lockPortion >= 95) {
|
|
194
|
+
return REWARD_CLAIM_START;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return REWARD_CLAIM_START + ONE_WEEK * Math.round((95 - lockPortion) / 2);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export class PapermillReadWrite extends PapermillRead {
|
|
202
|
+
constructor(networkConnection: NetworkConnection) {
|
|
203
|
+
super(networkConnection);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Redeem PLY from PULP and transfer PLY to another address
|
|
208
|
+
* @param recipient Address that will receive the PLY.
|
|
209
|
+
* @param amount Amount of PULP to be converted to PLY.
|
|
210
|
+
* Set to ethers.constants.MaxUint256 for max redeem.
|
|
211
|
+
*/
|
|
212
|
+
public async redeem(
|
|
213
|
+
recipient: Address,
|
|
214
|
+
amount: TokenAmount
|
|
215
|
+
): Promise<TransactionResponse> {
|
|
216
|
+
return this._pulp
|
|
217
|
+
.connect(this._networkConnection.signer!)
|
|
218
|
+
.redeem(recipient, amount.rawAmount());
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Redeem PLY from PULP and transfer PLY to msg.sender
|
|
223
|
+
* @param amount Amount of PULP to be converted to PLY.
|
|
224
|
+
* Set to ethers.constants.MaxUint256 for max redeem.
|
|
225
|
+
*/
|
|
226
|
+
public async selfRedeem(amount: TokenAmount): Promise<TransactionResponse> {
|
|
227
|
+
let msgSender: string = await this._networkConnection.signer!.getAddress();
|
|
228
|
+
return this.redeem(msgSender, amount);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export class Papermill extends BlockchainEntity {
|
|
233
|
+
constructor() {
|
|
234
|
+
super();
|
|
235
|
+
}
|
|
236
|
+
public read(networkConnection: NetworkConnection): PapermillRead {
|
|
237
|
+
return new PapermillRead(networkConnection);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public readWrite(networkConnection: NetworkConnection): PapermillReadWrite {
|
|
241
|
+
return new PapermillReadWrite(networkConnection);
|
|
242
|
+
}
|
|
243
|
+
}
|