@aurigami/sdk 1.5.10 → 1.6.0-no-src

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 (55) hide show
  1. package/dist/SDK.d.ts +23 -16
  2. package/dist/consts/deployments.d.ts +3 -0
  3. package/dist/{dummy.d.ts → consts/dummy.d.ts} +3 -3
  4. package/dist/consts/index.d.ts +4 -0
  5. package/dist/{MoneyMarket.d.ts → contracts/MoneyMarket.d.ts} +3 -5
  6. package/dist/{Papermill.d.ts → contracts/Papermill.d.ts} +25 -4
  7. package/dist/{Staking.d.ts → contracts/Staking.d.ts} +8 -3
  8. package/dist/{airdrop-lottery.d.ts → contracts/airdrop-lottery.d.ts} +12 -4
  9. package/dist/contracts/index.d.ts +4 -0
  10. package/dist/{BlockchainEntity.d.ts → entities/BlockchainEntity.d.ts} +1 -1
  11. package/dist/entities/index.d.ts +3 -0
  12. package/dist/{tokenAmount.d.ts → entities/tokenAmount.d.ts} +1 -1
  13. package/dist/{helpers.d.ts → helpers/helpers.d.ts} +10 -1
  14. package/dist/helpers/index.d.ts +4 -0
  15. package/dist/{priceFetcher.d.ts → helpers/priceFetcher.d.ts} +2 -2
  16. package/dist/{transfer-event-query.d.ts → helpers/transfer-event-query.d.ts} +11 -2
  17. package/dist/index.d.ts +4 -11
  18. package/dist/sdk.cjs.development.js +1994 -104381
  19. package/dist/sdk.cjs.development.js.map +1 -1
  20. package/dist/sdk.cjs.production.min.js +1 -1
  21. package/dist/sdk.cjs.production.min.js.map +1 -1
  22. package/dist/sdk.esm.js +1990 -104384
  23. package/dist/sdk.esm.js.map +1 -1
  24. package/dist/{types.d.ts → types/index.d.ts} +15 -1
  25. package/package.json +12 -13
  26. package/src/BlockchainEntity.ts +0 -33
  27. package/src/MoneyMarket.ts +0 -510
  28. package/src/Papermill.ts +0 -262
  29. package/src/SDK.ts +0 -366
  30. package/src/Staking.ts +0 -183
  31. package/src/abis/Faucet.json +0 -157
  32. package/src/abis/IUniswapV2Pair.json +0 -663
  33. package/src/abis/Oracle.json +0 -247
  34. package/src/abis/dummy.json +0 -3
  35. package/src/airdrop-lottery.ts +0 -327
  36. package/src/airdrop_misc/auTokensInfo.json +0 -34
  37. package/src/airdrop_misc/whitelist.example.txt +0 -4
  38. package/src/airdrop_misc/whitelist.json +0 -102629
  39. package/src/aurora-api-helpers.ts +0 -20
  40. package/src/constants.ts +0 -143
  41. package/src/decimals.ts +0 -24
  42. package/src/deployments/aurora_mainnet.json +0 -31
  43. package/src/deployments/aurora_testnet.json +0 -31
  44. package/src/dummy.ts +0 -38
  45. package/src/helpers.ts +0 -91
  46. package/src/index.ts +0 -20
  47. package/src/priceFetcher.ts +0 -309
  48. package/src/token.ts +0 -21
  49. package/src/tokenAmount.ts +0 -42
  50. package/src/transfer-event-query.ts +0 -70
  51. package/src/types.ts +0 -106
  52. /package/dist/{constants.d.ts → consts/constants.d.ts} +0 -0
  53. /package/dist/{decimals.d.ts → consts/decimals.d.ts} +0 -0
  54. /package/dist/{token.d.ts → entities/token.d.ts} +0 -0
  55. /package/dist/{aurora-api-helpers.d.ts → helpers/aurora-api-helpers.d.ts} +0 -0
@@ -1,309 +0,0 @@
1
- import BigNumber from 'bignumber.js';
2
- import { Contract, providers, BigNumber as BN, ethers } from 'ethers';
3
- import {
4
- DECIMAL_PRECISION,
5
- networkAddresses,
6
- PRICE_WHITELISTED,
7
- } from './constants';
8
- import OracleABI from './abis/Oracle.json';
9
- import { isSameAddress, decimalFactor, getDecimal, assert } from './helpers';
10
- import { IUniswapV2Pair, PriceOracle } from '@aurigami/contracts/typechain';
11
- import { TokenAmount } from './tokenAmount';
12
- import { Address, TokenValuation } from './types';
13
- import IUniswapV2PairABI from './abis/IUniswapV2Pair.json';
14
- import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
15
- import axios from 'axios';
16
-
17
- const hardcodePLYPrice = true;
18
- export async function fetchPriceFromCoingeckoAPI(
19
- id: string
20
- ): Promise<BigNumber> {
21
- const price = await axios
22
- .get(
23
- `https://api.coingecko.com/api/v3/simple/price?ids=${id}&vs_currencies=usd`
24
- )
25
- .then((res: any) => {
26
- return res.data;
27
- });
28
-
29
- return new BigNumber(price[id].usd);
30
- }
31
-
32
- export async function fetchPriceFromCoingecko(id: Address): Promise<BigNumber> {
33
- switch (id.toLowerCase()) {
34
- case networkAddresses.tokens.AURORA:
35
- return fetchPriceFromCoingeckoAPI('aurora-near');
36
-
37
- case networkAddresses.tokens.TRI:
38
- return fetchPriceFromCoingeckoAPI('trisolaris');
39
-
40
- case networkAddresses.tokens.META:
41
- return fetchPriceFromCoingeckoAPI('meta-pool');
42
-
43
- default:
44
- throw Error(`Unknown token ${id} in fetchPriceFromCoingecko`);
45
- }
46
- }
47
-
48
- export async function fetchLPPositions(
49
- LPAddress: Address,
50
- provider: providers.Provider
51
- ): Promise<{
52
- token0: Address;
53
- token1: Address;
54
- reserve0: BN;
55
- reserve1: BN;
56
- totalSupply: BN;
57
- }> {
58
- const LPContract = new Contract(
59
- LPAddress,
60
- IUniswapV2PairABI.abi,
61
- provider
62
- ) as IUniswapV2Pair;
63
- var promises: any[] = [];
64
- promises.push(LPContract.token0());
65
- promises.push(LPContract.token1());
66
- promises.push(LPContract.getReserves());
67
- promises.push(LPContract.totalSupply());
68
- const values: any[] = await Promise.all(promises);
69
-
70
- return {
71
- token0: values[0] as string,
72
- token1: values[1] as string,
73
- reserve0: (values[2] as { reserve0: BN; reserve1: BN }).reserve0,
74
- reserve1: (values[2] as { reserve0: BN; reserve1: BN }).reserve1,
75
- totalSupply: values[3] as BN,
76
- };
77
- }
78
-
79
- export async function fetchLPPrice(
80
- address: Address,
81
- provider: providers.Provider
82
- ): Promise<BigNumber> {
83
- var LPInfo = await fetchLPPositions(address, provider);
84
- const LPDecimal = getDecimal(address);
85
-
86
- async function fetchLPPriceBy(tokenReverse: {
87
- address: string;
88
- reserve: BN;
89
- }): Promise<BigNumber> {
90
- if (tokenReverse.reserve.isZero()) return new BigNumber(0);
91
-
92
- // Should NOT call `fetchPrice`, it will cause an infinite loop
93
- // because the token can be PLY. To calculate PLY price, we need to
94
- // call `fetchPrice` again...
95
- const tokenPrice: BigNumber = await _fetchPrice(
96
- tokenReverse.address,
97
- provider
98
- );
99
- const tokenDecimal = getDecimal(tokenReverse.address);
100
-
101
- // reserveUSD will be divided by 10^tokenDecimal later for more precision
102
- const reserveUSD: BigNumber = tokenPrice
103
- .multipliedBy(tokenReverse.reserve.toString())
104
- .multipliedBy(2);
105
- return reserveUSD
106
- .multipliedBy(decimalFactor(LPDecimal))
107
- .dividedBy(new BigNumber(LPInfo.totalSupply.toString()))
108
- .dividedBy(decimalFactor(tokenDecimal));
109
- }
110
-
111
- try {
112
- // MUST await here
113
- return await fetchLPPriceBy({
114
- address: LPInfo.token0,
115
- reserve: LPInfo.reserve0,
116
- });
117
- } catch {
118
- try {
119
- // MUST await here
120
- return await fetchLPPriceBy({
121
- address: LPInfo.token1,
122
- reserve: LPInfo.reserve1,
123
- });
124
- } catch {
125
- throw Error(`Unable to fetch price for both tokens of LP ${address}`);
126
- }
127
- }
128
- }
129
-
130
- function processPriceFromOracle(rawPrice: BN, underlyingDecimal: number) {
131
- return new BigNumber(rawPrice.toString()).div(
132
- decimalFactor(36 - underlyingDecimal)
133
- );
134
- }
135
- export async function fetchPriceFromOracle(
136
- auTokenAddress: Address,
137
- underlyingDecimal: number,
138
- provider: providers.Provider
139
- ): Promise<BigNumber> {
140
- const oracleContract: PriceOracle = new Contract(
141
- networkAddresses.misc.oracle,
142
- OracleABI.abi,
143
- provider
144
- ) as PriceOracle;
145
- const rawPrice = await oracleContract.getUnderlyingPrice(auTokenAddress);
146
- return processPriceFromOracle(rawPrice, underlyingDecimal);
147
- }
148
-
149
- export async function fetchUnderlyingTokensPrices(
150
- provider: providers.Provider
151
- ): Promise<
152
- {
153
- auToken: string;
154
- underlyingPrice: BigNumber;
155
- }[]
156
- > {
157
- const auriLens: Contract = new Contract(
158
- networkAddresses.misc.AURILENS,
159
- AuriLensABI.abi,
160
- provider
161
- );
162
- const auTokenAddresses = networkAddresses.auTokens.map(
163
- (auToken) => auToken.address
164
- );
165
- const underlyingDecimals = networkAddresses.auTokens.map((auToken) =>
166
- getDecimal(auToken.underlying)
167
- );
168
- const rawPrices = await auriLens.auTokenUnderlyingPriceAll(auTokenAddresses);
169
- return rawPrices.map((res: any, ind: number) => {
170
- return {
171
- auToken: res.auToken,
172
- underlyingPrice: processPriceFromOracle(
173
- res.underlyingPrice,
174
- underlyingDecimals[ind]
175
- ),
176
- };
177
- });
178
- }
179
-
180
- export async function fetchStNEARPrice(): Promise<BigNumber> {
181
- const ratioPromise = axios
182
- .get('https://validators.narwallets.com/metrics_json')
183
- .then((res) => res.data);
184
- const nearPricePromise = fetchPriceFromCoingeckoAPI('near');
185
- const [ratioRes, nearPrice]: [any, BigNumber] = await Promise.all([
186
- ratioPromise,
187
- nearPricePromise,
188
- ]);
189
- const ratio = new BigNumber(ratioRes.st_near_price);
190
- return ratio.multipliedBy(nearPrice);
191
- }
192
-
193
- function shouldFetchFromCoingecko(address: string) {
194
- address = address.toLowerCase();
195
- return (
196
- address == networkAddresses.tokens.AURORA ||
197
- address == networkAddresses.tokens.TRI ||
198
- address == networkAddresses.tokens.META
199
- );
200
- }
201
-
202
- /**
203
- * Fetch price from Oracle or Coingecko
204
- */
205
- async function _fetchPrice(
206
- address: Address,
207
- provider: providers.Provider
208
- ): Promise<BigNumber> {
209
- assert(
210
- PRICE_WHITELISTED.has(address.toLocaleLowerCase()),
211
- `Address ${address} is not whitelisted for price fetching`
212
- );
213
-
214
- if (isSameAddress(address, networkAddresses.tokens.stNEAR))
215
- return fetchStNEARPrice();
216
- if (shouldFetchFromCoingecko(address))
217
- return fetchPriceFromCoingecko(address);
218
-
219
- const matchingAuToken = networkAddresses.auTokens.find((auToken) => {
220
- return isSameAddress(auToken.underlying, address);
221
- });
222
-
223
- if (matchingAuToken !== undefined) {
224
- return fetchPriceFromOracle(
225
- matchingAuToken.address,
226
- getDecimal(address),
227
- provider
228
- );
229
- } else {
230
- throw Error(`Unable to fetch price for ${address}`);
231
- }
232
- }
233
-
234
- export async function fetchPrice(
235
- address: Address,
236
- provider: providers.Provider
237
- ): Promise<BigNumber> {
238
- if (isSameAddress(address, networkAddresses.tokens.PLYWNEAR)) {
239
- return fetchLPPrice(address, provider);
240
- } else if (isSameAddress(address, networkAddresses.tokens.PLY)) {
241
- return fetchPLYPrice(provider);
242
- } else if (isSameAddress(address, networkAddresses.tokens.PULP)) {
243
- return fetchPULPPrice(provider);
244
- }
245
- return _fetchPrice(address, provider);
246
- }
247
-
248
- export async function fetchPLYPrice(
249
- provider: providers.Provider
250
- ): Promise<BigNumber> {
251
- //TODO: Fetch PLY price from CEX?
252
- return fetchToken0PriceByLP(networkAddresses.tokens.PLYWNEAR, provider);
253
- }
254
-
255
- export async function fetchPULPPrice(
256
- provider: providers.Provider
257
- ): Promise<BigNumber> {
258
- //TODO: Calculate PULP price
259
- return new BigNumber(0);
260
- }
261
-
262
- export async function fetchToken0PriceByLP(
263
- LP: Address,
264
- provider: providers.Provider
265
- ): Promise<BigNumber> {
266
- const LPInfo = await fetchLPPositions(LP, provider);
267
-
268
- if (LPInfo.reserve1.isZero()) {
269
- return new BigNumber(0);
270
- }
271
-
272
- const token0Decimal = getDecimal(LPInfo.token0);
273
- const token1Decimal = getDecimal(LPInfo.token1);
274
-
275
- // (token0Price * reserve0) / 10^decimal0 = (token1Price * reserve1) / 10^decimal1
276
- // token0Price = (token1Price * reserve1) * 10^decimal0 / 10^decimal1 / reserve0
277
- return (await fetchPrice(LPInfo.token1, provider))
278
- .multipliedBy(LPInfo.reserve1.toString())
279
- .multipliedBy(decimalFactor(token0Decimal))
280
- .dividedBy(decimalFactor(token1Decimal))
281
- .dividedBy(LPInfo.reserve0.toString());
282
- }
283
-
284
- export async function fetchValuation(
285
- tokenAmount: TokenAmount,
286
- provider: providers.Provider
287
- ): Promise<BigNumber> {
288
- if (tokenAmount.rawAmount() == '0') return new BigNumber(0);
289
- var price = await fetchPrice(tokenAmount.token.address, provider);
290
- return calcValuation(tokenAmount, price);
291
- }
292
-
293
- export function calcValuation(tokenAmount: TokenAmount, price: BigNumber) {
294
- return new BigNumber(tokenAmount.formattedAmount()).multipliedBy(price);
295
- }
296
-
297
- export async function valuateToken(
298
- tokenAmount: TokenAmount,
299
- provider: providers.Provider
300
- ): Promise<TokenValuation> {
301
- let tokenValuation = await fetchValuation(tokenAmount, provider);
302
- return {
303
- tokenAmount: tokenAmount,
304
- currencyAmount: {
305
- currency: 'USD',
306
- amount: tokenValuation.toFixed(DECIMAL_PRECISION),
307
- },
308
- };
309
- }
package/src/token.ts DELETED
@@ -1,21 +0,0 @@
1
- import { getDecimal } from './helpers';
2
- import { networkAddresses } from './constants';
3
-
4
- export class Token {
5
- public readonly address: string;
6
- public readonly decimals: number;
7
- public constructor(address: string, decimals: number) {
8
- this.address = address.toLowerCase();
9
- this.decimals = decimals;
10
- }
11
- }
12
-
13
- export const PLYToken = new Token(
14
- networkAddresses.tokens.PLY,
15
- getDecimal(networkAddresses.tokens.PLY)
16
- );
17
-
18
- export const PLYWNEARToken = new Token(
19
- networkAddresses.tokens.PLYWNEAR,
20
- getDecimal(networkAddresses.tokens.PLYWNEAR)
21
- );
@@ -1,42 +0,0 @@
1
- import { Token } from './token';
2
- import BigNumber from 'bignumber.js';
3
- import { decimalFactor, getDecimal } from './helpers';
4
- import { Address } from './types';
5
-
6
- export class TokenAmount {
7
- public readonly token: Token;
8
- private rawAmnt: string;
9
-
10
- public constructor(token: Token, amount: string, isRaw: boolean = true) {
11
- if (isRaw) {
12
- this.rawAmnt = amount;
13
- } else {
14
- this.rawAmnt = new BigNumber(amount)
15
- .times(decimalFactor(token.decimals))
16
- .toFixed(0);
17
- }
18
- this.token = token;
19
- }
20
-
21
- public formattedAmount(): string {
22
- return new BigNumber(this.rawAmnt)
23
- .div(decimalFactor(this.token.decimals))
24
- .toString();
25
- }
26
-
27
- public rawAmount(): string {
28
- return this.rawAmnt;
29
- }
30
-
31
- public static fromAddressAndAmount(
32
- tokenAddress: Address,
33
- amount: string,
34
- isRaw: boolean = true
35
- ): TokenAmount {
36
- return new TokenAmount(
37
- new Token(tokenAddress, getDecimal(tokenAddress)),
38
- amount,
39
- isRaw
40
- );
41
- }
42
- }
@@ -1,70 +0,0 @@
1
- import { BlockchainEntityRead } from './BlockchainEntity';
2
- import { NetworkConnection } from './types';
3
- import { AuToken } from '@aurigami/contracts/typechain';
4
- import AuTokenABI from '@aurigami/contracts/artifacts/contracts/AuToken.sol/AuToken.json';
5
- import { BigNumber as BN, Contract } from 'ethers';
6
-
7
- type SimpleTransfer = {
8
- from: string;
9
- to: string;
10
- amount: BN;
11
- blockNumber: number;
12
- };
13
-
14
- export class TransferEventQuery extends BlockchainEntityRead {
15
- auToken: AuToken;
16
-
17
- constructor(tokenAddr: string, networkConnection: NetworkConnection) {
18
- super(networkConnection);
19
- this.auToken = new Contract(
20
- tokenAddr,
21
- AuTokenABI.abi,
22
- this._networkConnection.provider
23
- ) as AuToken;
24
- }
25
-
26
- /**
27
- * query ERC20 transfers from/to an address & auto convert them into SimpleTransfer.
28
- * The result will be sorted by blocknumber.
29
- */
30
- async queryERC20TransfersOf(
31
- address: string,
32
- fromBlock: number,
33
- toBlock: number
34
- ): Promise<SimpleTransfer[]> {
35
- const filters = [
36
- this.auToken.filters.Transfer(address, null),
37
- this.auToken.filters.Transfer(null, address),
38
- ];
39
-
40
- const events = (
41
- await Promise.all(
42
- filters.map((filter) =>
43
- this.auToken.queryFilter(filter, fromBlock, toBlock)
44
- )
45
- )
46
- ).flat();
47
-
48
- let results: SimpleTransfer[] = events.map((event) => {
49
- return {
50
- from: event.args![0],
51
- to: event.args![1],
52
- amount: event.args![2],
53
- blockNumber: event.blockNumber,
54
- };
55
- });
56
-
57
- results.sort((a, b) => a.blockNumber - b.blockNumber);
58
-
59
- return results;
60
- }
61
-
62
- /**
63
- * Get the balance of an address at a given block number.
64
- *
65
- * Note that this will return the balance after the block get mined.
66
- */
67
- async queryERC20BalanceAt(address: string, endBlock: number): Promise<BN> {
68
- return this.auToken.balanceOf(address, { blockTag: endBlock + 1 });
69
- }
70
- }
package/src/types.ts DELETED
@@ -1,106 +0,0 @@
1
- import type { BigNumber, providers, Signer } from 'ethers';
2
- import { TokenAmount } from './tokenAmount';
3
-
4
- export enum ComptrollerRewardType {
5
- PLY = 0,
6
- AURORA,
7
- }
8
- export type NetworkConnection = {
9
- provider: providers.Provider;
10
- signer?: Signer;
11
- };
12
-
13
- export type Address = string;
14
-
15
- export type CurrencyAmount = {
16
- currency: string;
17
- amount: string;
18
- };
19
-
20
- export type TokenValuation = {
21
- tokenAmount: TokenAmount;
22
- currencyAmount: CurrencyAmount;
23
- };
24
-
25
- export type MoneyMarketDetails = {
26
- auTokenAddress: string;
27
- totalTokenDeposited: TokenAmount;
28
- totalTokenBorrowed: TokenAmount;
29
- depositApy: number;
30
- depositPlyApy: number;
31
- borrowApy: number;
32
- borrowPlyApy: number;
33
- collateralRatio: number;
34
- depositPlyPerWeek: TokenAmount;
35
- borrowPlyPerWeek: TokenAmount;
36
- depositMETAApy: number;
37
- depositNEARApy: number;
38
- borrowNEARApy: number;
39
- };
40
-
41
- export type UserDetails = {
42
- markets: UserMarketDetails[];
43
- borrowLimit: CurrencyAmount;
44
- userLockingDetails: UserLockingDetails;
45
- borrowableAmount: CurrencyAmount;
46
- };
47
-
48
- export type UserLockingDetails = {
49
- vestingStart: number;
50
- /** % of reward they will receive in PLY, if they claim this week */
51
- currentUnlockPortion: number;
52
- //** Amount of PLY rewards that a user has. Equal to currentPly + currentPulp */
53
- accruedPly: TokenAmount;
54
- /** Amount of PLY they will receive, if they claim this week */
55
- currentPly: TokenAmount;
56
- /** Amount of PULP they will receive, if they claim this week */
57
- currentPulp: TokenAmount;
58
- /** % of reward they will receive in PLY, if they claim next week */
59
- nextUnlockPortion: number;
60
- /**
61
- * Amount of PLY they will receive, if they claim next week.
62
- * This doesn't include the additional reward that they will earn
63
- * in the next week.
64
- */
65
- nextPly: TokenAmount;
66
- /**
67
- * Amount of PULP they will receive, if they claim next week.
68
- * This doesn't include the additional reward that they will earn
69
- * in the next week.
70
- */
71
- nextPulp: TokenAmount;
72
- };
73
-
74
- export type UserMarketDetails = {
75
- market: string;
76
- depositBalance: TokenAmount;
77
- borrowBalance: TokenAmount;
78
- isCollateral: boolean;
79
- maxWithdrawableAmount: TokenAmount;
80
- collateralRatio: number;
81
- underlyingPrice: string;
82
- };
83
-
84
- export type TokenAPY = {
85
- address: string;
86
- apy: string;
87
- };
88
-
89
- export type PLYWNEARPoolDetails = {
90
- totalStakedLiquidity: TokenAmount;
91
- APYs: TokenAPY[];
92
- };
93
-
94
- export enum MarketAction {
95
- Deposit = 0,
96
- Borrow,
97
- Withdraw,
98
- Repay,
99
- EnableCollateral,
100
- DisableCollateral,
101
- }
102
-
103
- export type HypotheticalStats = {
104
- newBorrowLimit: CurrencyAmount;
105
- newBorrowUtilization: number;
106
- };
File without changes
File without changes
File without changes