@aurigami/sdk 1.8.6 → 1.9.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 +1 -1
- package/dist/helpers/priceFetcher.d.ts +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/sdk.cjs.development.js +171 -97
- 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 +171 -98
- package/dist/sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/SDK.ts +1 -1
- package/src/helpers/helpers.ts +1 -1
- package/src/helpers/priceFetcher.ts +40 -4
- package/src/index.ts +1 -1
- package/src/{contracts → interactors}/MoneyMarket.ts +1 -1
- /package/dist/{contracts → interactors}/Airdrop.d.ts +0 -0
- /package/dist/{contracts → interactors}/MoneyMarket.d.ts +0 -0
- /package/dist/{contracts → interactors}/Multicall.d.ts +0 -0
- /package/dist/{contracts → interactors}/Papermill.d.ts +0 -0
- /package/dist/{contracts → interactors}/Referral.d.ts +0 -0
- /package/dist/{contracts → interactors}/Staking.d.ts +0 -0
- /package/dist/{contracts → interactors}/index.d.ts +0 -0
- /package/dist/{contracts → interactors}/misc.d.ts +0 -0
- /package/src/{contracts → interactors}/Airdrop.ts +0 -0
- /package/src/{contracts → interactors}/Multicall.ts +0 -0
- /package/src/{contracts → interactors}/Papermill.ts +0 -0
- /package/src/{contracts → interactors}/Referral.ts +0 -0
- /package/src/{contracts → interactors}/Staking.ts +0 -0
- /package/src/{contracts → interactors}/index.ts +0 -0
- /package/src/{contracts → interactors}/misc.ts +0 -0
package/package.json
CHANGED
package/src/SDK.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
2
2
|
import BigNumber from 'bignumber.js';
|
|
3
3
|
import { ALL_STAKING_POOLS } from './consts';
|
|
4
|
-
import { MiscRead, StakingRead, StakingReadWrite } from './contracts';
|
|
5
4
|
import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from './entities';
|
|
5
|
+
import { MiscRead, StakingRead, StakingReadWrite } from './interactors';
|
|
6
6
|
import * as types from './types';
|
|
7
7
|
|
|
8
8
|
export class SdkRead extends BlockchainEntityRead {
|
package/src/helpers/helpers.ts
CHANGED
|
@@ -157,6 +157,6 @@ export async function getBlockBeforeTimestamp(provider: Provider, timestamp: num
|
|
|
157
157
|
|
|
158
158
|
export function devLog(message?: any, ...optionalParams: any[]): void {
|
|
159
159
|
if ('production' !== process.env.NODE_ENV) {
|
|
160
|
-
console.log(message, ...optionalParams);
|
|
160
|
+
console.log('[DEV LOG]', message, ...optionalParams);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
@@ -18,10 +18,14 @@ export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber>
|
|
|
18
18
|
const price = await axios
|
|
19
19
|
.get(`https://api.coingecko.com/api/v3/simple/price?ids=${id}&vs_currencies=usd`)
|
|
20
20
|
.then((res: any) => {
|
|
21
|
-
return res.data;
|
|
21
|
+
return res.data[id];
|
|
22
|
+
})
|
|
23
|
+
.catch((err: any) => {
|
|
24
|
+
console.log(`Unable to fetch price from Coingecko API for ${id}`);
|
|
25
|
+
return { usd: 0 };
|
|
22
26
|
});
|
|
23
27
|
|
|
24
|
-
return new BigNumber(price
|
|
28
|
+
return new BigNumber(price.usd);
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
export async function fetchPriceFromCoingecko(id: Address): Promise<BigNumber> {
|
|
@@ -98,10 +102,14 @@ export async function fetchLPPrice(
|
|
|
98
102
|
|
|
99
103
|
try {
|
|
100
104
|
// MUST await here
|
|
101
|
-
|
|
105
|
+
const lpPrice = await fetchLPPriceBy({
|
|
102
106
|
address: LPInfo.token0,
|
|
103
107
|
reserve: LPInfo.reserve0,
|
|
104
108
|
});
|
|
109
|
+
if (lpPrice.isZero()) {
|
|
110
|
+
throw Error(`Price is zero`);
|
|
111
|
+
}
|
|
112
|
+
return lpPrice;
|
|
105
113
|
} catch (e) {
|
|
106
114
|
devLog(`fetchLPPriceBy ${LPInfo.token0} failed`, e);
|
|
107
115
|
try {
|
|
@@ -117,6 +125,19 @@ export async function fetchLPPrice(
|
|
|
117
125
|
}
|
|
118
126
|
}
|
|
119
127
|
|
|
128
|
+
export async function fetchStNEARPrice(): Promise<BigNumber> {
|
|
129
|
+
const ratioPromise = axios
|
|
130
|
+
.get('https://validators.narwallets.com/metrics_json')
|
|
131
|
+
.then((res) => res.data);
|
|
132
|
+
const nearPricePromise = fetchPriceFromCoingeckoAPI('near');
|
|
133
|
+
const [ratioRes, nearPrice]: [any, BigNumber] = await Promise.all([
|
|
134
|
+
ratioPromise,
|
|
135
|
+
nearPricePromise,
|
|
136
|
+
]);
|
|
137
|
+
const ratio = new BigNumber(ratioRes.st_near_price);
|
|
138
|
+
return ratio.multipliedBy(nearPrice);
|
|
139
|
+
}
|
|
140
|
+
|
|
120
141
|
function processPriceFromOracle(rawPrice: BN, underlyingDecimal: number) {
|
|
121
142
|
return new BigNumber(rawPrice.toString()).div(decimalFactor(36 - underlyingDecimal));
|
|
122
143
|
}
|
|
@@ -130,7 +151,22 @@ export async function fetchPriceFromOracle(
|
|
|
130
151
|
AuriOracleABI.abi,
|
|
131
152
|
provider
|
|
132
153
|
) as PriceOracle;
|
|
133
|
-
const rawPrice = await oracleContract.getUnderlyingPrice(auTokenAddress)
|
|
154
|
+
const rawPrice = await oracleContract.getUnderlyingPrice(auTokenAddress).catch((e: any) => {
|
|
155
|
+
console.log(`Unable to fetch price from oracle for ${auTokenAddress}`);
|
|
156
|
+
return BN.from(0);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// In case of error, probally it is because the underlying token is not supported
|
|
160
|
+
// by the backup oracle. In that case, we will fetch from third-party.
|
|
161
|
+
if (rawPrice.isZero()) {
|
|
162
|
+
const matchingAuToken = networkAddresses.auTokens.find((auToken) => {
|
|
163
|
+
return isSameAddress(auToken.address, auTokenAddress);
|
|
164
|
+
});
|
|
165
|
+
if (matchingAuToken?.name == 'auSTNEAR') {
|
|
166
|
+
return fetchStNEARPrice();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
134
170
|
return processPriceFromOracle(rawPrice, underlyingDecimal);
|
|
135
171
|
}
|
|
136
172
|
|
package/src/index.ts
CHANGED
|
@@ -7,8 +7,8 @@ BigNumber.config({ DECIMAL_PLACES: 50 });
|
|
|
7
7
|
|
|
8
8
|
export * as abis from './abis';
|
|
9
9
|
export * from './consts';
|
|
10
|
-
export * from './contracts';
|
|
11
10
|
export * from './entities';
|
|
12
11
|
export * from './helpers';
|
|
12
|
+
export * from './interactors';
|
|
13
13
|
export * from './SDK';
|
|
14
14
|
export * from './types';
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
Token,
|
|
13
13
|
TokenAmount,
|
|
14
14
|
} from '../entities';
|
|
15
|
-
import * as helpers from '../helpers
|
|
15
|
+
import * as helpers from '../helpers';
|
|
16
16
|
import { calcValuation, fetchPrice, fetchValuation } from '../helpers/priceFetcher';
|
|
17
17
|
import { Address, ComptrollerRewardType, MoneyMarketDetails, NetworkConnection } from '../types';
|
|
18
18
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|