@aurigami/sdk 1.20.8 → 1.22.0

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.
@@ -177,23 +177,21 @@ export declare type UserNotification = {
177
177
  liquidation: boolean;
178
178
  }[];
179
179
  };
180
- export declare type UserLiquidationHistorySubgraph = {
181
- liquidationEvents: LiquidationEventSubgraph[];
182
- };
183
- export declare type LiquidationEventSubgraph = {
184
- auTokenSymbol: string;
185
- amount: number;
186
- blockTime: number;
187
- from: string;
188
- id: string;
189
- underlyingRepayAmount: number;
190
- underlyingRepayAmountUSD: number;
191
- underlyingSymbol: string;
180
+ export declare type LiquidationEventEntity = {
181
+ liquidator: string;
182
+ borrower: string;
183
+ /** bigint string */
184
+ repayAmount: string;
185
+ marketRepayToken: string;
186
+ /** bigint string */
187
+ seizeTokens: string;
188
+ auTokenCollateral: string;
189
+ txnHash: string;
190
+ blockNumber: number;
192
191
  };
193
192
  export declare type LiquidationDetail = {
194
193
  liquidationTime: Timestamp;
195
194
  tokenAmount: TokenAmount;
196
- value: CurrencyAmount;
197
195
  transactionId: string;
198
196
  };
199
197
  export declare type Timestamp = number;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.20.8",
2
+ "version": "1.22.0",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -61,7 +61,7 @@
61
61
  "typescript": "^4.5.4"
62
62
  },
63
63
  "dependencies": {
64
- "@aurigami/contracts": "3.18.0",
64
+ "@aurigami/contracts": "3.20.0",
65
65
  "axios": "^0.26.1",
66
66
  "bignumber.js": "^9.0.2",
67
67
  "cache-decorator": "^0.1.6",
package/src/SDK.ts CHANGED
@@ -1,18 +1,12 @@
1
1
  import { TransactionResponse } from '@ethersproject/abstract-provider';
2
2
  import BigNumber from 'bignumber.js';
3
- import {
4
- ALL_STAKING_POOLS,
5
- AURIGAMI_SUBGRAPH_URL,
6
- SD_INCENTIVE_IN_SD,
7
- networkAddresses,
8
- } from './consts';
3
+ import { ALL_STAKING_POOLS, networkAddresses } from './consts';
9
4
  import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from './entities';
5
+ import { getBlocksTimestamp, getDecimal } from './helpers';
6
+ import * as AuriAPI from './helpers/aurigami-api';
7
+ import * as NotificationApi from './helpers/notification-api';
10
8
  import { MiscRead, StakingRead, StakingReadWrite } from './interactors';
11
9
  import * as types from './types';
12
- import * as NotificationApi from './helpers/notification-api';
13
- import { BigNumber as BN } from 'ethers';
14
- import { getDecimal, queryGraphQL } from './helpers';
15
- import { getLiquidationEventsQuery } from './helpers/subgraphQuery';
16
10
 
17
11
  export class SdkRead extends BlockchainEntityRead {
18
12
  protected env: AuriEnv;
@@ -158,26 +152,26 @@ export class SdkRead extends BlockchainEntityRead {
158
152
  }
159
153
 
160
154
  public async getLiquidationHistory(address: string): Promise<types.LiquidationDetail[]> {
161
- const liquidationHistorySubgraph = (await queryGraphQL(
162
- getLiquidationEventsQuery(address, 100),
163
- AURIGAMI_SUBGRAPH_URL
164
- )) as types.UserLiquidationHistorySubgraph;
165
- const liquidationEvents = liquidationHistorySubgraph.liquidationEvents.map((event) => {
166
- const value: types.CurrencyAmount = {
167
- amount: event.underlyingRepayAmountUSD.toString(),
168
- currency: 'USD',
169
- };
155
+ const liquidationHistoryResp = await AuriAPI.getPaginatedApi<types.LiquidationEventEntity>(
156
+ '/liquidate/history',
157
+ {
158
+ user: address,
159
+ }
160
+ );
161
+ const blocks = liquidationHistoryResp.items.map((event) => event.blockNumber);
162
+ const blocksTimestamp = await getBlocksTimestamp(this._networkConnection.provider, blocks);
163
+
164
+ const liquidationEvents = liquidationHistoryResp.items.map((event, idx) => {
170
165
  const underlyingAddress = networkAddresses.auTokens.find(
171
- (auToken) => auToken.name.slice(2).toLowerCase() === event.underlyingSymbol.toLowerCase()
166
+ (auToken) => auToken.address.toLowerCase() === event.marketRepayToken.toLowerCase()
172
167
  )!.underlying;
173
168
  const decimal = getDecimal(underlyingAddress);
174
169
  const token = new Token(underlyingAddress, decimal);
175
- const tokenAmount = new TokenAmount(token, event.underlyingRepayAmount.toString(), false);
170
+ const tokenAmount = new TokenAmount(token, event.repayAmount.toString(), true);
176
171
  return {
177
- liquidationTime: event.blockTime,
172
+ liquidationTime: blocksTimestamp[idx],
178
173
  tokenAmount,
179
- value,
180
- transactionId: event.id.split('-')[0],
174
+ transactionId: event.txnHash,
181
175
  };
182
176
  }) as types.LiquidationDetail[];
183
177
  return liquidationEvents;
@@ -75,7 +75,8 @@ export const networkAddresses = {
75
75
  ],
76
76
  misc: {
77
77
  COMPTROLLER: MAINNET_ADDRESSES.comptroller.toLowerCase(),
78
- oracle: MAINNET_ADDRESSES.oracle.toLowerCase(),
78
+ DEPRECATED_OLD_ORACLE: MAINNET_ADDRESSES.oracle.toLowerCase(),
79
+ PYTH_ORACLE: MAINNET_ADDRESSES.pythOracle.toLowerCase(),
79
80
  AURIFAIRLAUNCH: MAINNET_ADDRESSES.fairLaunch.toLowerCase(),
80
81
  AURILENS: MAINNET_ADDRESSES.auriLens.toLowerCase(),
81
82
  ETHREPAYHELPER: MAINNET_ADDRESSES.ethRepayHelper.toLowerCase(),
@@ -194,4 +195,4 @@ export const USDT_ETH = '0xdAC17F958D2ee523a2206206994597C13D831ec7'.toLowerCase
194
195
  export const AURIGAMI_SUBGRAPH_URL =
195
196
  'https://api.thegraph.com/subgraphs/name/takao-aurigami/aurigami-feb-27';
196
197
 
197
- export const GRAPHQL_URL = 'https://explorer.mainnet.aurora.dev/graphiql';
198
+ export const GRAPHQL_URL = 'https://old.explorer.aurora.dev/api/v1/graphql';
@@ -7,15 +7,15 @@ import {
7
7
  AuriOracle,
8
8
  Comptroller,
9
9
  IERC20,
10
- PlyGame,
11
10
  PULP,
12
- ReferralDirectoryV2,
11
+ PlyGame,
13
12
  PlyTokenLock,
13
+ ReferralDirectoryV2,
14
14
  } from '@aurigami/contracts/typechain';
15
15
  import { Contract } from 'ethers';
16
- import { assert } from '../helpers/helpers';
17
16
  import * as abis from '../abis';
18
17
  import { networkAddresses } from '../consts/constants';
18
+ import { assert } from '../helpers/helpers';
19
19
  import { AuTokenWithUnderlying } from '../types';
20
20
  import { BlockchainEntityRead } from './BlockchainEntity';
21
21
 
@@ -152,7 +152,7 @@ export class AuriEnv extends BlockchainEntityRead {
152
152
  get oracle(): AuriOracle {
153
153
  if (!this._oracle) {
154
154
  this._oracle = this.getContract<AuriOracle>(
155
- networkAddresses.misc.oracle,
155
+ networkAddresses.misc.PYTH_ORACLE,
156
156
  abis.AuriOracleABI.abi
157
157
  );
158
158
  }
@@ -23,12 +23,12 @@ export type PaginagedApiResponse<T> = {
23
23
  meta: MetaApiResponse;
24
24
  };
25
25
 
26
- export async function getPaginatedApi(
26
+ export async function getPaginatedApi<T = any>(
27
27
  url: string,
28
28
  params: Record<string, any> = {},
29
29
  page: number = 1,
30
30
  pageSize: number = 50
31
- ): Promise<PaginagedApiResponse<any>> {
31
+ ): Promise<PaginagedApiResponse<T>> {
32
32
  params = {
33
33
  ...params,
34
34
  page,
@@ -3,7 +3,7 @@ import { Provider } from '@ethersproject/abstract-provider';
3
3
  import BigNumber from 'bignumber.js';
4
4
  import { BigNumber as BN, utils } from 'ethers';
5
5
  import { Result } from 'ethers/lib/utils';
6
- import { CACHE_TIMEOUT, GRAPHQL_URL, networkAddresses } from '../consts/constants';
6
+ import { GRAPHQL_URL, networkAddresses } from '../consts/constants';
7
7
  import { decimalRecords } from '../consts/decimals';
8
8
  import { symbolRecords } from '../consts/symbols';
9
9
  import { Address } from '../types';
@@ -135,7 +135,7 @@ export async function getBlocksTimestamp(
135
135
  // merge all the json objects
136
136
  let results = (await Promise.all(promises)).reduce((acc, cur) => {
137
137
  return { ...acc, ...cur };
138
- });
138
+ }, {});
139
139
 
140
140
  let missingBlocks = blockNumbers.filter((blockNumber) => !results[`b${blockNumber}`]);
141
141
  if (missingBlocks.length > 0) {
@@ -104,8 +104,15 @@ export async function fetchHistoricalPriceFromOracle(
104
104
  provider: providers.Provider,
105
105
  block: number
106
106
  ): Promise<BigNumber> {
107
+ // from this block, we switch to use pyth
108
+ // TODO: add to consts
109
+ const oracleAddress =
110
+ block < 102438637
111
+ ? networkAddresses.misc.DEPRECATED_OLD_ORACLE
112
+ : networkAddresses.misc.PYTH_ORACLE;
113
+
107
114
  const oracleContract: PriceOracle = new Contract(
108
- networkAddresses.misc.oracle,
115
+ oracleAddress,
109
116
  AuriOracleABI.abi,
110
117
  provider
111
118
  ) as PriceOracle;
@@ -1,5 +1,5 @@
1
1
  import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
2
- import { ERC20, IUniswapV2Pair, PriceOracle } from '@aurigami/contracts/typechain';
2
+ import { AuriPythOracle, ERC20, IUniswapV2Pair } from '@aurigami/contracts/typechain';
3
3
  import axios from 'axios';
4
4
  import BigNumber from 'bignumber.js';
5
5
  import { BigNumber as BN, Contract, ethers, providers } from 'ethers';
@@ -7,10 +7,10 @@ import { AuriOracleABI, EIP20InterfaceABI, IUniswapV2PairABI } from '../abis';
7
7
  import {
8
8
  DECIMAL_PRECISION,
9
9
  HARDCODE_PRICE_TOKENS,
10
- networkAddresses,
11
10
  PRICE_WHITELISTED,
12
11
  STADER_ETH,
13
12
  USDT_ETH,
13
+ networkAddresses,
14
14
  } from '../consts/constants';
15
15
  import { TokenAmount } from '../entities/tokenAmount';
16
16
  import { Address, TokenValuation } from '../types';
@@ -229,11 +229,11 @@ export async function fetchPriceFromOracle(
229
229
  underlyingDecimal: number,
230
230
  provider: providers.Provider
231
231
  ): Promise<BigNumber> {
232
- const oracleContract: PriceOracle = new Contract(
233
- networkAddresses.misc.oracle,
232
+ const oracleContract: AuriPythOracle = new Contract(
233
+ networkAddresses.misc.PYTH_ORACLE,
234
234
  AuriOracleABI.abi,
235
235
  provider
236
- ) as PriceOracle;
236
+ ) as AuriPythOracle;
237
237
  const rawPrice = await oracleContract.getUnderlyingPrice(auTokenAddress).catch((e: any) => {
238
238
  console.log(`Unable to fetch price from oracle for ${auTokenAddress}`);
239
239
  return BN.from(0);
@@ -1,4 +1,4 @@
1
- import { AuToken, PriceOracle } from '@aurigami/contracts/typechain';
1
+ import { AuToken } from '@aurigami/contracts/typechain';
2
2
  import BigNumber from 'bignumber.js';
3
3
  import { BigNumber as BN } from 'ethers';
4
4
  import * as abis from '../abis';
@@ -290,10 +290,7 @@ export class MiscRead extends BlockchainEntityRead {
290
290
  dust: BigNumber = new BigNumber(0.1)
291
291
  ): Promise<types.AccountAuTokensInfo[]> {
292
292
  const _1E18 = BN.from(10).pow(18);
293
- const oracle = this.env.getContract<PriceOracle>(
294
- consts.networkAddresses.misc.oracle,
295
- abis.AuriOracleABI.abi
296
- );
293
+ const oracle = this.env.oracle;
297
294
  const tokens = tokenAddresses.map((addr) =>
298
295
  this.env.getContract<AuToken>(addr, abis.AuTokenABI.abi)
299
296
  );
@@ -200,25 +200,22 @@ export type UserNotification = {
200
200
  }[];
201
201
  };
202
202
 
203
- export type UserLiquidationHistorySubgraph = {
204
- liquidationEvents: LiquidationEventSubgraph[];
205
- };
206
-
207
- export type LiquidationEventSubgraph = {
208
- auTokenSymbol: string;
209
- amount: number;
210
- blockTime: number;
211
- from: string;
212
- id: string;
213
- underlyingRepayAmount: number;
214
- underlyingRepayAmountUSD: number;
215
- underlyingSymbol: string;
203
+ export type LiquidationEventEntity = {
204
+ liquidator: string;
205
+ borrower: string;
206
+ /** bigint string */
207
+ repayAmount: string;
208
+ marketRepayToken: string;
209
+ /** bigint string */
210
+ seizeTokens: string;
211
+ auTokenCollateral: string;
212
+ txnHash: string;
213
+ blockNumber: number;
216
214
  };
217
215
 
218
216
  export type LiquidationDetail = {
219
217
  liquidationTime: Timestamp;
220
218
  tokenAmount: TokenAmount;
221
- value: CurrencyAmount;
222
219
  transactionId: string;
223
220
  };
224
221