@aurigami/sdk 1.19.0 → 1.19.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/SDK.d.ts +2 -0
- package/dist/consts/constants.d.ts +2 -0
- package/dist/helpers/graphql-helpers.d.ts +1 -1
- package/dist/helpers/subgraphQuery.d.ts +1 -0
- package/dist/interactors/misc.d.ts +4 -0
- package/dist/sdk.cjs.development.js +163 -79
- 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 +162 -80
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types/index.d.ts +20 -0
- package/package.json +1 -1
- package/src/SDK.ts +38 -1
- package/src/consts/constants.ts +5 -0
- package/src/helpers/graphql-helpers.ts +2 -4
- package/src/helpers/helpers.ts +2 -2
- package/src/helpers/subgraphQuery.ts +17 -0
- package/src/interactors/misc.ts +23 -0
- package/src/types/index.ts +24 -0
package/dist/types/index.d.ts
CHANGED
|
@@ -178,3 +178,23 @@ export declare type UserNotification = {
|
|
|
178
178
|
liquidation: boolean;
|
|
179
179
|
}[];
|
|
180
180
|
};
|
|
181
|
+
export declare type UserLiquidationHistorySubgraph = {
|
|
182
|
+
liquidationEvents: LiquidationEventSubgraph[];
|
|
183
|
+
};
|
|
184
|
+
export declare type LiquidationEventSubgraph = {
|
|
185
|
+
auTokenSymbol: string;
|
|
186
|
+
amount: number;
|
|
187
|
+
blockTime: number;
|
|
188
|
+
from: string;
|
|
189
|
+
id: string;
|
|
190
|
+
underlyingRepayAmount: number;
|
|
191
|
+
underlyingRepayAmountUSD: number;
|
|
192
|
+
underlyingSymbol: string;
|
|
193
|
+
};
|
|
194
|
+
export declare type LiquidationDetail = {
|
|
195
|
+
liquidationTime: Timestamp;
|
|
196
|
+
tokenAmount: TokenAmount;
|
|
197
|
+
value: CurrencyAmount;
|
|
198
|
+
transactionId: string;
|
|
199
|
+
};
|
|
200
|
+
export declare type Timestamp = number;
|
package/package.json
CHANGED
package/src/SDK.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ALL_STAKING_POOLS,
|
|
5
|
+
AURIGAMI_SUBGRAPH_URL,
|
|
6
|
+
SD_INCENTIVE_IN_SD,
|
|
7
|
+
networkAddresses,
|
|
8
|
+
} from './consts';
|
|
4
9
|
import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from './entities';
|
|
5
10
|
import { MiscRead, StakingRead, StakingReadWrite } from './interactors';
|
|
6
11
|
import * as types from './types';
|
|
7
12
|
import * as NotificationApi from './helpers/notification-api';
|
|
8
13
|
import { BigNumber as BN } from 'ethers';
|
|
14
|
+
import { getDecimal, queryGraphQL } from './helpers';
|
|
15
|
+
import { getLiquidationEventsQuery } from './helpers/subgraphQuery';
|
|
9
16
|
|
|
10
17
|
export class SdkRead extends BlockchainEntityRead {
|
|
11
18
|
protected env: AuriEnv;
|
|
@@ -147,6 +154,36 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
147
154
|
const response = await NotificationApi.postApi('alert-setting/get-user-setting', body);
|
|
148
155
|
return response;
|
|
149
156
|
}
|
|
157
|
+
|
|
158
|
+
public async getLiquidationHistory(address: string): Promise<types.LiquidationDetail[]> {
|
|
159
|
+
const liquidationHistorySubgraph = (await queryGraphQL(
|
|
160
|
+
getLiquidationEventsQuery(address, 100),
|
|
161
|
+
AURIGAMI_SUBGRAPH_URL
|
|
162
|
+
)) as types.UserLiquidationHistorySubgraph;
|
|
163
|
+
const liquidationEvents = liquidationHistorySubgraph.liquidationEvents.map((event) => {
|
|
164
|
+
const value: types.CurrencyAmount = {
|
|
165
|
+
amount: event.underlyingRepayAmountUSD.toString(),
|
|
166
|
+
currency: 'USD',
|
|
167
|
+
};
|
|
168
|
+
const underlyingAddress = networkAddresses.auTokens.find(
|
|
169
|
+
(auToken) => auToken.name.slice(2).toLowerCase() === event.underlyingSymbol.toLowerCase()
|
|
170
|
+
)!.underlying;
|
|
171
|
+
const decimal = getDecimal(underlyingAddress);
|
|
172
|
+
const token = new Token(underlyingAddress, decimal);
|
|
173
|
+
const tokenAmount = new TokenAmount(token, event.underlyingRepayAmount.toString(), false);
|
|
174
|
+
return {
|
|
175
|
+
liquidationTime: event.blockTime,
|
|
176
|
+
tokenAmount,
|
|
177
|
+
value,
|
|
178
|
+
transactionId: event.id.split('-')[0],
|
|
179
|
+
};
|
|
180
|
+
}) as types.LiquidationDetail[];
|
|
181
|
+
return liquidationEvents;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public calculateBorrowPower(tokenAmount: TokenAmount): Promise<types.CurrencyAmount> {
|
|
185
|
+
return this._misc.calcBorrowPower(tokenAmount);
|
|
186
|
+
}
|
|
150
187
|
}
|
|
151
188
|
|
|
152
189
|
export class SdkReadWrite extends SdkRead {
|
package/src/consts/constants.ts
CHANGED
|
@@ -190,3 +190,8 @@ export const SD_INCENTIVE_IN_SD = 83.35;
|
|
|
190
190
|
export const STADER_ETH = '0x30D20208d987713f46DFD34EF128Bb16C404D10f'.toLowerCase();
|
|
191
191
|
|
|
192
192
|
export const USDT_ETH = '0xdAC17F958D2ee523a2206206994597C13D831ec7'.toLowerCase();
|
|
193
|
+
|
|
194
|
+
export const AURIGAMI_SUBGRAPH_URL =
|
|
195
|
+
'https://api.thegraph.com/subgraphs/name/takao-aurigami/aurigami-feb-27';
|
|
196
|
+
|
|
197
|
+
export const GRAPHQL_URL = 'https://explorer.mainnet.aurora.dev/graphiql';
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export async function queryGraphQL(query: string): Promise<any> {
|
|
6
|
-
let resp = await axios.post(GRAPHQL_URL, {
|
|
3
|
+
export async function queryGraphQL(query: string, graphqlUrl: string): Promise<any> {
|
|
4
|
+
let resp = await axios.post(graphqlUrl, {
|
|
7
5
|
query: query,
|
|
8
6
|
});
|
|
9
7
|
return resp.data.data!;
|
package/src/helpers/helpers.ts
CHANGED
|
@@ -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, networkAddresses } from '../consts/constants';
|
|
6
|
+
import { CACHE_TIMEOUT, 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';
|
|
@@ -129,7 +129,7 @@ export async function getBlocksTimestamp(
|
|
|
129
129
|
|
|
130
130
|
for (let i = 0; i < lines.length; i += CHUNK_SIZE) {
|
|
131
131
|
let query = `{ ${lines.slice(i, i + CHUNK_SIZE).join('\n')} }`;
|
|
132
|
-
promises.push(queryGraphQL(query));
|
|
132
|
+
promises.push(queryGraphQL(query, GRAPHQL_URL));
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
// merge all the json objects
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function getLiquidationEventsQuery(address: string, limit: number) {
|
|
2
|
+
return `{
|
|
3
|
+
liquidationEvents(
|
|
4
|
+
first: ${limit},
|
|
5
|
+
where: {from: "${address.toLowerCase()}"}
|
|
6
|
+
) {
|
|
7
|
+
amount
|
|
8
|
+
auTokenSymbol
|
|
9
|
+
blockTime
|
|
10
|
+
from
|
|
11
|
+
id
|
|
12
|
+
underlyingRepayAmountUSD
|
|
13
|
+
underlyingSymbol
|
|
14
|
+
underlyingRepayAmount
|
|
15
|
+
}
|
|
16
|
+
}`;
|
|
17
|
+
}
|
package/src/interactors/misc.ts
CHANGED
|
@@ -145,6 +145,29 @@ export class MiscRead extends BlockchainEntityRead {
|
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
public async calcBorrowPower(tokenAmount: TokenAmount) {
|
|
149
|
+
const autoken = consts.networkAddresses.auTokens.find((auToken) =>
|
|
150
|
+
isSameAddress(auToken.underlying, tokenAmount.token.address)
|
|
151
|
+
)!;
|
|
152
|
+
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
153
|
+
this._networkConnection,
|
|
154
|
+
autoken.address,
|
|
155
|
+
autoken.underlying
|
|
156
|
+
);
|
|
157
|
+
const collateralRatio = await moneyMarket.getCollateralRatio();
|
|
158
|
+
const underlyingPrice = await fetchPrice(
|
|
159
|
+
tokenAmount.token.address,
|
|
160
|
+
this._networkConnection.provider
|
|
161
|
+
);
|
|
162
|
+
const borrowPower = calcValuation(tokenAmount!, new BigNumber(underlyingPrice))
|
|
163
|
+
.multipliedBy(collateralRatio)
|
|
164
|
+
.multipliedBy(consts.BORROW_LIMIT_BUFFER);
|
|
165
|
+
return {
|
|
166
|
+
currency: 'USD',
|
|
167
|
+
amount: borrowPower.toFixed(consts.DECIMAL_PRECISION),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
148
171
|
public calcHypotheticalStats({
|
|
149
172
|
userMarketDetail,
|
|
150
173
|
currentBorrowLimit,
|
package/src/types/index.ts
CHANGED
|
@@ -200,3 +200,27 @@ export type UserNotification = {
|
|
|
200
200
|
liquidation: boolean;
|
|
201
201
|
}[];
|
|
202
202
|
};
|
|
203
|
+
|
|
204
|
+
export type UserLiquidationHistorySubgraph = {
|
|
205
|
+
liquidationEvents: LiquidationEventSubgraph[];
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export type LiquidationEventSubgraph = {
|
|
209
|
+
auTokenSymbol: string;
|
|
210
|
+
amount: number;
|
|
211
|
+
blockTime: number;
|
|
212
|
+
from: string;
|
|
213
|
+
id: string;
|
|
214
|
+
underlyingRepayAmount: number;
|
|
215
|
+
underlyingRepayAmountUSD: number;
|
|
216
|
+
underlyingSymbol: string;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export type LiquidationDetail = {
|
|
220
|
+
liquidationTime: Timestamp;
|
|
221
|
+
tokenAmount: TokenAmount;
|
|
222
|
+
value: CurrencyAmount;
|
|
223
|
+
transactionId: string;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export type Timestamp = number;
|