@aurigami/sdk 1.6.4 → 1.6.6

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 (56) hide show
  1. package/ChangeLog.md +163 -0
  2. package/dist/SDK.d.ts +4 -7
  3. package/dist/abis/index.d.ts +14 -0
  4. package/dist/consts/constants.d.ts +2 -2
  5. package/dist/consts/dummy.d.ts +1 -2
  6. package/dist/contracts/{airdrop-lottery.d.ts → Airdrop.d.ts} +1 -6
  7. package/dist/contracts/MoneyMarket.d.ts +3 -4
  8. package/dist/contracts/Multicall.d.ts +2 -2
  9. package/dist/contracts/Papermill.d.ts +4 -9
  10. package/dist/contracts/Referral.d.ts +1 -1
  11. package/dist/contracts/Staking.d.ts +2 -5
  12. package/dist/contracts/index.d.ts +2 -1
  13. package/dist/contracts/misc.d.ts +26 -0
  14. package/dist/entities/auriEnv.d.ts +13 -0
  15. package/dist/entities/index.d.ts +1 -0
  16. package/dist/entities/tokenAmount.d.ts +1 -1
  17. package/dist/helpers/priceFetcher.d.ts +1 -1
  18. package/dist/helpers/transfer-event-query.d.ts +2 -2
  19. package/dist/index.d.ts +1 -1
  20. package/dist/sdk.cjs.development.js +585 -104422
  21. package/dist/sdk.cjs.development.js.map +1 -1
  22. package/dist/sdk.cjs.production.min.js +1 -1
  23. package/dist/sdk.cjs.production.min.js.map +1 -1
  24. package/dist/sdk.esm.js +588 -104427
  25. package/dist/sdk.esm.js.map +1 -1
  26. package/package.json +7 -6
  27. package/src/SDK.ts +23 -330
  28. package/src/abis/index.ts +30 -0
  29. package/src/consts/constants.ts +15 -16
  30. package/src/consts/dummy.ts +4 -14
  31. package/src/contracts/Airdrop.ts +80 -0
  32. package/src/contracts/MoneyMarket.ts +56 -160
  33. package/src/contracts/Multicall.ts +8 -13
  34. package/src/contracts/Papermill.ts +34 -115
  35. package/src/contracts/Referral.ts +11 -14
  36. package/src/contracts/Staking.ts +18 -59
  37. package/src/contracts/index.ts +2 -1
  38. package/src/contracts/misc.ts +281 -0
  39. package/src/entities/BlockchainEntity.ts +2 -6
  40. package/src/entities/auriEnv.ts +39 -0
  41. package/src/entities/index.ts +1 -0
  42. package/src/entities/token.ts +1 -1
  43. package/src/entities/tokenAmount.ts +4 -12
  44. package/src/helpers/aurora-api-helpers.ts +3 -6
  45. package/src/helpers/helpers.ts +5 -17
  46. package/src/helpers/priceFetcher.ts +21 -62
  47. package/src/helpers/transfer-event-query.ts +4 -6
  48. package/src/index.ts +1 -1
  49. package/src/types/index.ts +1 -1
  50. package/src/abis/Faucet.json +0 -157
  51. package/src/abis/IUniswapV2Pair.json +0 -663
  52. package/src/abis/Oracle.json +0 -247
  53. package/src/abis/dummy.json +0 -3
  54. package/src/contracts/airdrop-lottery.ts +0 -320
  55. package/src/misc/airdrop_misc/auTokensInfo.json +0 -34
  56. package/src/misc/airdrop_misc/whitelist.json +0 -102629
@@ -1,247 +0,0 @@
1
- {
2
- "abi": [
3
- {
4
- "inputs": [],
5
- "payable": false,
6
- "stateMutability": "nonpayable",
7
- "type": "constructor"
8
- },
9
- {
10
- "anonymous": false,
11
- "inputs": [
12
- {
13
- "indexed": false,
14
- "internalType": "address",
15
- "name": "feed",
16
- "type": "address"
17
- },
18
- {
19
- "indexed": false,
20
- "internalType": "string",
21
- "name": "symbol",
22
- "type": "string"
23
- }
24
- ],
25
- "name": "FeedSet",
26
- "type": "event"
27
- },
28
- {
29
- "anonymous": false,
30
- "inputs": [
31
- {
32
- "indexed": false,
33
- "internalType": "address",
34
- "name": "oldAdmin",
35
- "type": "address"
36
- },
37
- {
38
- "indexed": false,
39
- "internalType": "address",
40
- "name": "newAdmin",
41
- "type": "address"
42
- }
43
- ],
44
- "name": "NewAdmin",
45
- "type": "event"
46
- },
47
- {
48
- "anonymous": false,
49
- "inputs": [
50
- {
51
- "indexed": false,
52
- "internalType": "address",
53
- "name": "asset",
54
- "type": "address"
55
- },
56
- {
57
- "indexed": false,
58
- "internalType": "uint256",
59
- "name": "previousPriceMantissa",
60
- "type": "uint256"
61
- },
62
- {
63
- "indexed": false,
64
- "internalType": "uint256",
65
- "name": "requestedPriceMantissa",
66
- "type": "uint256"
67
- },
68
- {
69
- "indexed": false,
70
- "internalType": "uint256",
71
- "name": "newPriceMantissa",
72
- "type": "uint256"
73
- }
74
- ],
75
- "name": "PricePosted",
76
- "type": "event"
77
- },
78
- {
79
- "constant": true,
80
- "inputs": [],
81
- "name": "admin",
82
- "outputs": [
83
- {
84
- "internalType": "address",
85
- "name": "",
86
- "type": "address"
87
- }
88
- ],
89
- "payable": false,
90
- "stateMutability": "view",
91
- "type": "function"
92
- },
93
- {
94
- "constant": true,
95
- "inputs": [
96
- {
97
- "internalType": "address",
98
- "name": "asset",
99
- "type": "address"
100
- }
101
- ],
102
- "name": "assetPrices",
103
- "outputs": [
104
- {
105
- "internalType": "uint256",
106
- "name": "",
107
- "type": "uint256"
108
- }
109
- ],
110
- "payable": false,
111
- "stateMutability": "view",
112
- "type": "function"
113
- },
114
- {
115
- "constant": true,
116
- "inputs": [
117
- {
118
- "internalType": "string",
119
- "name": "symbol",
120
- "type": "string"
121
- }
122
- ],
123
- "name": "getFeed",
124
- "outputs": [
125
- {
126
- "internalType": "contract AggregatorV2V3Interface",
127
- "name": "",
128
- "type": "address"
129
- }
130
- ],
131
- "payable": false,
132
- "stateMutability": "view",
133
- "type": "function"
134
- },
135
- {
136
- "constant": true,
137
- "inputs": [
138
- {
139
- "internalType": "contract QiToken",
140
- "name": "qiToken",
141
- "type": "address"
142
- }
143
- ],
144
- "name": "getUnderlyingPrice",
145
- "outputs": [
146
- {
147
- "internalType": "uint256",
148
- "name": "",
149
- "type": "uint256"
150
- }
151
- ],
152
- "payable": false,
153
- "stateMutability": "view",
154
- "type": "function"
155
- },
156
- {
157
- "constant": true,
158
- "inputs": [],
159
- "name": "isPriceOracle",
160
- "outputs": [
161
- {
162
- "internalType": "bool",
163
- "name": "",
164
- "type": "bool"
165
- }
166
- ],
167
- "payable": false,
168
- "stateMutability": "view",
169
- "type": "function"
170
- },
171
- {
172
- "constant": false,
173
- "inputs": [
174
- {
175
- "internalType": "address",
176
- "name": "newAdmin",
177
- "type": "address"
178
- }
179
- ],
180
- "name": "setAdmin",
181
- "outputs": [],
182
- "payable": false,
183
- "stateMutability": "nonpayable",
184
- "type": "function"
185
- },
186
- {
187
- "constant": false,
188
- "inputs": [
189
- {
190
- "internalType": "address",
191
- "name": "asset",
192
- "type": "address"
193
- },
194
- {
195
- "internalType": "uint256",
196
- "name": "price",
197
- "type": "uint256"
198
- }
199
- ],
200
- "name": "setDirectPrice",
201
- "outputs": [],
202
- "payable": false,
203
- "stateMutability": "nonpayable",
204
- "type": "function"
205
- },
206
- {
207
- "constant": false,
208
- "inputs": [
209
- {
210
- "internalType": "string",
211
- "name": "symbol",
212
- "type": "string"
213
- },
214
- {
215
- "internalType": "address",
216
- "name": "feed",
217
- "type": "address"
218
- }
219
- ],
220
- "name": "setFeed",
221
- "outputs": [],
222
- "payable": false,
223
- "stateMutability": "nonpayable",
224
- "type": "function"
225
- },
226
- {
227
- "constant": false,
228
- "inputs": [
229
- {
230
- "internalType": "contract QiToken",
231
- "name": "qiToken",
232
- "type": "address"
233
- },
234
- {
235
- "internalType": "uint256",
236
- "name": "underlyingPriceMantissa",
237
- "type": "uint256"
238
- }
239
- ],
240
- "name": "setUnderlyingPrice",
241
- "outputs": [],
242
- "payable": false,
243
- "stateMutability": "nonpayable",
244
- "type": "function"
245
- }
246
- ]
247
- }
@@ -1,3 +0,0 @@
1
- {
2
- "abi": []
3
- }
@@ -1,320 +0,0 @@
1
- import AuriAirdropABI from '@aurigami/contracts/artifacts/contracts/AuriAirdrop.sol/AuriAirdrop.json';
2
- import { AuriAirdrop } from '@aurigami/contracts/typechain';
3
- import {
4
- Provider,
5
- TransactionResponse,
6
- } from '@ethersproject/abstract-provider';
7
- import { BigNumber as BN, Contract, utils } from 'ethers';
8
- import * as consts from '../consts';
9
- import {
10
- BlockchainEntity,
11
- BlockchainEntityRead,
12
- Token,
13
- TokenAmount,
14
- } from '../entities';
15
- import * as helpers from '../helpers';
16
- import AIRDROP_AUTOKEN_INFO from '../misc/airdrop_misc/auTokensInfo.json';
17
- import AIRDROP_WHITELIST_ADDRESSES from '../misc/airdrop_misc/whitelist.json';
18
- import { Address, NetworkConnection } from '../types';
19
-
20
- type AirdropUnderlyingInfo = {
21
- minDeposit: BN;
22
- };
23
-
24
- type AirdropAuTokenInfo = {
25
- address: string;
26
- exchangeRate: BN;
27
- deploymentBlock: number;
28
- underlying: AirdropUnderlyingInfo;
29
- };
30
-
31
- class AirdropSettings {
32
- private static _instance: AirdropSettings;
33
-
34
- airdropStartBlock: number = 0;
35
- airdropEndBlock: number = 0;
36
- airdropStartTimestamp: number = consts.AIRDROP_START_TIMESTAMP;
37
- airdropEndTimestamp: number = consts.AIRDROP_END_TIMESTAMP;
38
- airdropThreshold: number = consts.AIRDROP_KEEP_THRESHOLD;
39
- private constructor() {}
40
-
41
- public static async getSettings(
42
- provider: Provider
43
- ): Promise<AirdropSettings> {
44
- if (this._instance) return this._instance;
45
-
46
- let settings: AirdropSettings = new AirdropSettings();
47
-
48
- settings.airdropStartBlock = await helpers.getBlockBeforeTimestamp(
49
- provider,
50
- settings.airdropStartTimestamp
51
- );
52
-
53
- settings.airdropEndBlock = await helpers.getBlockBeforeTimestamp(
54
- provider,
55
- settings.airdropEndTimestamp
56
- );
57
-
58
- this._instance = settings;
59
- return settings;
60
- }
61
- }
62
-
63
- class AirdropAuTokenKeepTracker extends BlockchainEntityRead {
64
- private _transferQuery: helpers.TransferEventQuery;
65
- private _airdropAuTokenInfo: AirdropAuTokenInfo;
66
- public constructor(
67
- networkConnection: NetworkConnection,
68
- airdropAuTokenInfo: AirdropAuTokenInfo
69
- ) {
70
- super(networkConnection);
71
- this._transferQuery = new helpers.TransferEventQuery(
72
- airdropAuTokenInfo.address,
73
- networkConnection
74
- );
75
- this._airdropAuTokenInfo = airdropAuTokenInfo;
76
-
77
- // exchangeRate = 102% * exchangeRate, see why in the comment of _toUnderlyingValue
78
- this._airdropAuTokenInfo.exchangeRate =
79
- this._airdropAuTokenInfo.exchangeRate.add(
80
- this._airdropAuTokenInfo.exchangeRate.div(50)
81
- );
82
- }
83
-
84
- /**
85
- * Convert the given amount of auToken to the underlying value with the stored exchange rate
86
- *
87
- * Why we need to do this?
88
- *
89
- * By transfer event, we cannot know the exact underlying, the only
90
- * info that we can keep track of via transfer is event is the auToken amount. So we need to
91
- * convert it to the underlying value with the stored exchange rate.
92
- *
93
- * However, we cannot just simply use auTokenAmount * exchangeRate, because the exchange rate
94
- * is changing over time. As advice of the contract team, use fixed exchangeRate * 102% is good enough.
95
- *
96
- */
97
- private _toUnderlyingValue(auTokenAmount: BN): BN {
98
- return auTokenAmount
99
- .mul(this._airdropAuTokenInfo.exchangeRate)
100
- .div(BN.from(10).pow(18));
101
- }
102
-
103
- /**
104
- * Check if the user has been deposit at least (minDeposit) and keep it for
105
- * more than AIRDROP_KEEP_THRESHOLD milliseconds
106
- *
107
- * How it works:
108
- * Whenever the user balance is exceed minDeposit, we will record the timestamp,
109
- * and when the balance is below minDeposit, we will compare with the saved timestamp to see
110
- * whether it has been keep for more than AIRDROP_KEEP_THRESHOLD milliseconds.
111
- *
112
- */
113
- public async isEligible(address: string): Promise<boolean> {
114
- const settings = await AirdropSettings.getSettings(
115
- this._networkConnection.provider
116
- );
117
- const minDeposit = this._airdropAuTokenInfo.underlying.minDeposit;
118
-
119
- // Get user balance at the time of Airdrop start
120
- let balance = await this._transferQuery.queryERC20BalanceAt(
121
- address,
122
- settings.airdropStartBlock - 1
123
- );
124
-
125
- const [BELOW, ABOVE] = [false, true];
126
- let flag = BELOW;
127
- // variable to store the last timestamp that, from it to "current" timestamp,
128
- // the balance is always above minDeposit
129
- let lastEligibleBalanceTimestamp = 0;
130
-
131
- if (this._toUnderlyingValue(balance).gte(minDeposit)) {
132
- lastEligibleBalanceTimestamp = settings.airdropStartTimestamp;
133
- flag = ABOVE;
134
- }
135
-
136
- let events = await this._transferQuery.queryERC20TransfersOf(
137
- address,
138
- settings.airdropStartBlock,
139
- settings.airdropEndBlock
140
- );
141
-
142
- for (let { from, to, amount, blockNumber } of events) {
143
- if (helpers.isSameAddress(from, address)) {
144
- balance = balance.sub(amount);
145
- }
146
- if (helpers.isSameAddress(to, address)) {
147
- balance = balance.add(amount);
148
- }
149
-
150
- // if it is different from the flag, that means the balance is changing
151
- if (this._toUnderlyingValue(balance).gte(minDeposit) != flag) {
152
- flag = !flag;
153
- const timestamp = (
154
- await this._networkConnection.provider.getBlock(blockNumber)
155
- ).timestamp;
156
-
157
- // if this txn make the balance below the minDeposit,
158
- // check whether it has been keep for more than AIRDROP_KEEP_THRESHOLD
159
- if (flag == BELOW) {
160
- if (
161
- timestamp - lastEligibleBalanceTimestamp >=
162
- settings.airdropThreshold
163
- ) {
164
- return true;
165
- }
166
- lastEligibleBalanceTimestamp = 0;
167
- } else {
168
- // record the timestamp when the balance is above minDeposit
169
- lastEligibleBalanceTimestamp = timestamp;
170
- }
171
- }
172
- }
173
-
174
- // if after the last txn, the balance is still above minDeposit,
175
- // we should check from the last timestamp to "now"
176
- if (flag == ABOVE) {
177
- const timestamp = Math.min(
178
- settings.airdropEndTimestamp,
179
- helpers.getCurrentTimestamp()
180
- );
181
- return (
182
- timestamp - lastEligibleBalanceTimestamp >= settings.airdropThreshold
183
- );
184
- }
185
-
186
- return false;
187
- }
188
- }
189
-
190
- export class AirdropRead extends BlockchainEntityRead {
191
- protected _airDrop: AuriAirdrop;
192
- private _whitelistedAddresses: Set<string>;
193
- private keepTrackers: AirdropAuTokenKeepTracker[] = [];
194
- public constructor(networkConnection: NetworkConnection) {
195
- super(networkConnection);
196
- this._airDrop = new Contract(
197
- consts.networkAddresses.misc.AURI_AIRDROP,
198
- AuriAirdropABI.abi,
199
- networkConnection.provider
200
- ) as AuriAirdrop;
201
-
202
- this._whitelistedAddresses = new Set(
203
- (AIRDROP_WHITELIST_ADDRESSES as string[]).map((e) =>
204
- e.toLocaleLowerCase()
205
- )
206
- );
207
-
208
- let auTokens: any = AIRDROP_AUTOKEN_INFO;
209
-
210
- for (let auToken in auTokens) {
211
- let { address, exchangeRate, deploymentBlock, underlying } =
212
- auTokens[auToken];
213
-
214
- let airdropInfo: AirdropAuTokenInfo = {
215
- address: address,
216
- exchangeRate: BN.from(exchangeRate),
217
- deploymentBlock: parseInt(deploymentBlock),
218
- underlying: {
219
- minDeposit: BN.from(underlying.minDeposit),
220
- },
221
- };
222
-
223
- this.keepTrackers.push(
224
- new AirdropAuTokenKeepTracker(networkConnection, airdropInfo)
225
- );
226
- }
227
- }
228
-
229
- public countWhitelistedAddresses(): number {
230
- return this._whitelistedAddresses.size;
231
- }
232
-
233
- public isWhitelisted(user: string): boolean {
234
- return this._whitelistedAddresses.has(user.toLocaleLowerCase());
235
- }
236
-
237
- public async hasCompletedChallenge(user: string): Promise<boolean> {
238
- const settings = await AirdropSettings.getSettings(
239
- this._networkConnection.provider
240
- );
241
-
242
- if (helpers.getCurrentTimestamp() < settings.airdropStartTimestamp) {
243
- return false;
244
- }
245
-
246
- if (!this.isWhitelisted(user)) {
247
- return false;
248
- }
249
-
250
- // iterate for all the market and check if the user has completed the challenge
251
- return (
252
- await Promise.all(
253
- this.keepTrackers.map(async (keepTracker) => {
254
- return keepTracker.isEligible(user);
255
- })
256
- )
257
- ).includes(true);
258
- }
259
-
260
- /**
261
- * Get redeemable rewards amount of user
262
- */
263
- public async getRedeemableReward(
264
- campaign: string,
265
- token: Address,
266
- user: Address
267
- ): Promise<TokenAmount> {
268
- let tokenInstance: Token = new Token(token, helpers.getDecimal(token));
269
-
270
- let rewards: BN = await this._airDrop.getRedeemableReward(
271
- utils.formatBytes32String(campaign),
272
- token,
273
- user
274
- );
275
-
276
- return new TokenAmount(tokenInstance, rewards.toString());
277
- }
278
- }
279
-
280
- export class AirdropReadWrite extends AirdropRead {
281
- /**
282
- * Transfer rewards from multiple campaigns to msg.sender
283
- */
284
- public async redeemMultiple(
285
- campaigns: string[],
286
- tokens: Address[]
287
- ): Promise<TransactionResponse> {
288
- helpers.assert(
289
- campaigns.length == tokens.length,
290
- 'campaigns and tokens must have the same length'
291
- );
292
- return this._airDrop.connect(this._networkConnection.signer!).redeem(
293
- campaigns.map((e) => utils.formatBytes32String(e)),
294
- tokens,
295
- await this._networkConnection.signer!.getAddress()
296
- );
297
- }
298
-
299
- /**
300
- * Redeem reward from a single campaign
301
- */
302
- public async redeemSingle(
303
- campaign: string,
304
- token: Address
305
- ): Promise<TransactionResponse> {
306
- return this.redeemMultiple([campaign], [token]);
307
- }
308
- }
309
-
310
- export class Airdrop extends BlockchainEntity {
311
- constructor() {
312
- super();
313
- }
314
- public read(networkConnection: NetworkConnection): AirdropRead {
315
- return new AirdropRead(networkConnection);
316
- }
317
- public readWrite(networkConnection: NetworkConnection): AirdropReadWrite {
318
- return new AirdropReadWrite(networkConnection);
319
- }
320
- }
@@ -1,34 +0,0 @@
1
- {
2
- "auUSDC": {
3
- "address": "0x4f0d864b1ABf4B701799a0b30b57A22dFEB5917b",
4
- "exchangeRate": "200810680770707",
5
- "deploymentBlock": "60501576",
6
- "underlying": {
7
- "minDeposit": "1000000000"
8
- }
9
- },
10
- "auETH": {
11
- "address": "0xca9511B610bA5fc7E311FDeF9cE16050eE4449E9",
12
- "exchangeRate": "200390813218617347858934298",
13
- "deploymentBlock": "60501625",
14
- "underlying": {
15
- "minDeposit": "300000000000000000"
16
- }
17
- },
18
- "auWBTC": {
19
- "address": "0xCFb6b0498cb7555e7e21502E0F449bf28760Adbb",
20
- "exchangeRate": "20050472926613996",
21
- "deploymentBlock": "60501670",
22
- "underlying": {
23
- "minDeposit": "2000000"
24
- }
25
- },
26
- "auUSDT": {
27
- "address": "0xaD5A2437Ff55ed7A8Cad3b797b3eC7c5a19B1c54",
28
- "exchangeRate": "200868369820223",
29
- "deploymentBlock": "60501723",
30
- "underlying": {
31
- "minDeposit": "1000000000"
32
- }
33
- }
34
- }