@aurigami/sdk 1.18.3 → 1.18.5
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/consts/constants.d.ts +2 -0
- package/dist/helpers/kyber-aggregator-api.d.ts +5 -0
- package/dist/helpers/one-inch-aggregator-api.d.ts +21 -0
- package/dist/helpers/priceFetcher.d.ts +7 -0
- package/dist/sdk.cjs.development.js +398 -215
- 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 +404 -226
- package/dist/sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/consts/constants.ts +4 -0
- package/src/helpers/kyber-aggregator-api.ts +37 -0
- package/src/helpers/one-inch-aggregator-api.ts +45 -0
- package/src/helpers/priceFetcher.ts +55 -9
package/package.json
CHANGED
package/src/consts/constants.ts
CHANGED
|
@@ -186,3 +186,7 @@ export const REFERRAL_CAMPAIGNS: { [k: string]: { start: number; end: number } }
|
|
|
186
186
|
export const CACHE_TIMEOUT = 10 * 1000; // 10 seconds
|
|
187
187
|
|
|
188
188
|
export const SD_INCENTIVE_IN_SD = 83.35;
|
|
189
|
+
|
|
190
|
+
export const STADER_ETH = '0x30D20208d987713f46DFD34EF128Bb16C404D10f'.toLowerCase();
|
|
191
|
+
|
|
192
|
+
export const USDT_ETH = '0xdAC17F958D2ee523a2206206994597C13D831ec7'.toLowerCase();
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
const KYBER_AGGREGATOR_AURORA_API_END_POINT =
|
|
4
|
+
'https://aggregator-api.kyberswap.com/aurora/route/encode';
|
|
5
|
+
|
|
6
|
+
const KYBER_AGGREGATOR_ETH_API_END_POINT =
|
|
7
|
+
'https://aggregator-api.kyberswap.com/ethereum/route/encode';
|
|
8
|
+
|
|
9
|
+
export async function getSwapInfo(
|
|
10
|
+
tokenIn: string,
|
|
11
|
+
tokenOut: string,
|
|
12
|
+
amountIn: string,
|
|
13
|
+
onAurora = true
|
|
14
|
+
): Promise<KyberApiResponse> {
|
|
15
|
+
const params = {
|
|
16
|
+
tokenIn,
|
|
17
|
+
tokenOut,
|
|
18
|
+
amountIn,
|
|
19
|
+
to: '0x0000000000000000000000000000000000000000',
|
|
20
|
+
useMeta: '1',
|
|
21
|
+
saveGas: '1',
|
|
22
|
+
gasInclude: '1',
|
|
23
|
+
};
|
|
24
|
+
const endpoint = onAurora
|
|
25
|
+
? KYBER_AGGREGATOR_AURORA_API_END_POINT
|
|
26
|
+
: KYBER_AGGREGATOR_ETH_API_END_POINT;
|
|
27
|
+
const resp = await axios.get(endpoint + '?' + new URLSearchParams(params), {
|
|
28
|
+
headers: { 'Content-Type': 'application/json' },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return resp.data;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type KyberApiResponse = {
|
|
35
|
+
inputAmount: string;
|
|
36
|
+
outputAmount: string;
|
|
37
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// https://api.1inch.io/v5.0/1313161554/quote?fromTokenAddress=0x8bec47865ade3b172a928df8f990bc7f2a3b9f79&toTokenAddress=0x4988a896b1227218e4a686fde5eabdcabd91571f&amount=1000000000000000000
|
|
2
|
+
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
|
|
5
|
+
const ONEINCH_AGGREGATOR_API_END_POINT = 'https://api.1inch.io/v5.0/1313161554/quote';
|
|
6
|
+
|
|
7
|
+
export async function getQuoteOneInch(
|
|
8
|
+
fromTokenAddress: string,
|
|
9
|
+
toTokenAddress: string,
|
|
10
|
+
amount: string
|
|
11
|
+
): Promise<OneInchApiResponse> {
|
|
12
|
+
const params = {
|
|
13
|
+
fromTokenAddress,
|
|
14
|
+
toTokenAddress,
|
|
15
|
+
amount,
|
|
16
|
+
};
|
|
17
|
+
const resp = await axios.get(
|
|
18
|
+
ONEINCH_AGGREGATOR_API_END_POINT + '?' + new URLSearchParams(params),
|
|
19
|
+
{
|
|
20
|
+
headers: { 'Content-Type': 'application/json' },
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
return resp.data;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type OneInchApiResponse = {
|
|
27
|
+
fromToken: {
|
|
28
|
+
symbol: string;
|
|
29
|
+
name: string;
|
|
30
|
+
decimals: number;
|
|
31
|
+
address: string;
|
|
32
|
+
logoURI: string;
|
|
33
|
+
tags: string[];
|
|
34
|
+
};
|
|
35
|
+
toToken: {
|
|
36
|
+
symbol: string;
|
|
37
|
+
name: string;
|
|
38
|
+
decimals: number;
|
|
39
|
+
address: string;
|
|
40
|
+
logoURI: string;
|
|
41
|
+
tags: string[];
|
|
42
|
+
};
|
|
43
|
+
toTokenAmount: string;
|
|
44
|
+
fromTokenAmount: string;
|
|
45
|
+
};
|
|
@@ -1,18 +1,63 @@
|
|
|
1
1
|
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
2
|
-
import { IUniswapV2Pair, PriceOracle } from '@aurigami/contracts/typechain';
|
|
2
|
+
import { ERC20, IUniswapV2Pair, PriceOracle } from '@aurigami/contracts/typechain';
|
|
3
3
|
import axios from 'axios';
|
|
4
4
|
import BigNumber from 'bignumber.js';
|
|
5
|
-
import { BigNumber as BN, Contract, providers } from 'ethers';
|
|
6
|
-
import { AuriOracleABI, IUniswapV2PairABI } from '../abis';
|
|
5
|
+
import { BigNumber as BN, Contract, ethers, providers } from 'ethers';
|
|
6
|
+
import { AuriOracleABI, EIP20InterfaceABI, IUniswapV2PairABI } from '../abis';
|
|
7
7
|
import {
|
|
8
8
|
DECIMAL_PRECISION,
|
|
9
9
|
HARDCODE_PRICE_TOKENS,
|
|
10
10
|
networkAddresses,
|
|
11
11
|
PRICE_WHITELISTED,
|
|
12
|
+
STADER_ETH,
|
|
13
|
+
USDT_ETH,
|
|
12
14
|
} from '../consts/constants';
|
|
13
15
|
import { TokenAmount } from '../entities/tokenAmount';
|
|
14
16
|
import { Address, TokenValuation } from '../types';
|
|
15
17
|
import { assert, decimalFactor, devLog, getDecimal, isSameAddress } from './helpers';
|
|
18
|
+
import { getSwapInfo } from './kyber-aggregator-api';
|
|
19
|
+
import { getQuoteOneInch } from './one-inch-aggregator-api';
|
|
20
|
+
|
|
21
|
+
export async function prepareParamsAggregator(address: string, provider: providers.Provider) {
|
|
22
|
+
const tokenInErc20 = new Contract(address, EIP20InterfaceABI.abi, provider) as ERC20;
|
|
23
|
+
const tokenInDecimal = await tokenInErc20.decimals();
|
|
24
|
+
const tokenInQuantity = BN.from(10).pow(tokenInDecimal).toString();
|
|
25
|
+
const usdtAddress =
|
|
26
|
+
networkAddresses.auTokens.find((autoken) => autoken.name == 'auUSDT')?.underlying ?? '';
|
|
27
|
+
const usdtDecimal = getDecimal(usdtAddress);
|
|
28
|
+
return {
|
|
29
|
+
tokenInQuantity,
|
|
30
|
+
usdtAddress,
|
|
31
|
+
usdtDecimal,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function fetchPriceFromOneInch(address: string, provider: providers.Provider) {
|
|
36
|
+
const { tokenInQuantity, usdtAddress, usdtDecimal } = await prepareParamsAggregator(
|
|
37
|
+
address,
|
|
38
|
+
provider
|
|
39
|
+
);
|
|
40
|
+
const info = await getQuoteOneInch(address, usdtAddress, tokenInQuantity);
|
|
41
|
+
const outputAmount = info.toTokenAmount;
|
|
42
|
+
return new BigNumber(outputAmount).dividedBy(10 ** usdtDecimal);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export async function fetchPriceFromKyberSwap(
|
|
46
|
+
address: string,
|
|
47
|
+
provider: providers.Provider,
|
|
48
|
+
onAurora = true
|
|
49
|
+
) {
|
|
50
|
+
let { tokenInQuantity, usdtAddress, usdtDecimal } = await prepareParamsAggregator(
|
|
51
|
+
address,
|
|
52
|
+
provider
|
|
53
|
+
);
|
|
54
|
+
if (!onAurora) {
|
|
55
|
+
usdtAddress = USDT_ETH;
|
|
56
|
+
}
|
|
57
|
+
const info = await getSwapInfo(address, usdtAddress, tokenInQuantity, onAurora);
|
|
58
|
+
const outputAmount = info.outputAmount;
|
|
59
|
+
return new BigNumber(outputAmount).dividedBy(10 ** usdtDecimal);
|
|
60
|
+
}
|
|
16
61
|
|
|
17
62
|
export async function fetchPriceFromDefiLlamaAPI(id: string): Promise<BigNumber> {
|
|
18
63
|
const price = await axios
|
|
@@ -225,7 +270,7 @@ export async function fetchUnderlyingTokensPrices(provider: providers.Provider):
|
|
|
225
270
|
});
|
|
226
271
|
}
|
|
227
272
|
|
|
228
|
-
function
|
|
273
|
+
function shouldFetchFromKyberSwap(address: string) {
|
|
229
274
|
address = address.toLowerCase();
|
|
230
275
|
return (
|
|
231
276
|
address == networkAddresses.tokens.AURORA ||
|
|
@@ -243,12 +288,13 @@ async function _fetchPrice(address: Address, provider: providers.Provider): Prom
|
|
|
243
288
|
PRICE_WHITELISTED.has(address.toLocaleLowerCase()),
|
|
244
289
|
`Address ${address} is not whitelisted for price fetching`
|
|
245
290
|
);
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return
|
|
291
|
+
if (shouldFetchFromKyberSwap(address)) {
|
|
292
|
+
if (address == networkAddresses.tokens.STADER) {
|
|
293
|
+
const ETH_PROVIDER = new ethers.providers.JsonRpcProvider('https://rpc.ankr.com/eth');
|
|
294
|
+
|
|
295
|
+
return fetchPriceFromKyberSwap(STADER_ETH, ETH_PROVIDER, false);
|
|
251
296
|
}
|
|
297
|
+
return fetchPriceFromKyberSwap(address, provider);
|
|
252
298
|
}
|
|
253
299
|
const matchingAuToken = networkAddresses.auTokens.find((auToken) => {
|
|
254
300
|
return isSameAddress(auToken.underlying, address);
|