@hinkal/common 0.0.210 → 0.1.3
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/API/duneAPI.cjs +1 -0
- package/API/duneAPI.d.ts +11 -0
- package/API/duneAPI.mjs +20 -0
- package/API/getRelayerURL.cjs +1 -1
- package/API/getRelayerURL.mjs +4 -4
- package/API/getServerURL.cjs +1 -1
- package/API/getServerURL.mjs +8 -10
- package/API/index.d.ts +1 -0
- package/assets/{snarkjsWorkerLauncher-CG86wN85.js → snarkjsWorkerLauncher-T9sCESzH.js} +1 -1
- package/assets/{snarkjsWorkerLogic-C3huMBha.js → snarkjsWorkerLogic-CrBQ1Sdm.js} +5 -2
- package/assets/{zkProofWorkerLauncher-1qQFujaL.js → zkProofWorkerLauncher-BwaZD8dV.js} +1 -1
- package/assets/{zkProofWorkerLogic-Bs68aPkV.js → zkProofWorkerLogic-BwY5sE7i.js} +5 -2
- package/constants/axelar.constants.cjs +1 -1
- package/constants/axelar.constants.mjs +10 -16
- package/constants/backend.constants.cjs +1 -1
- package/constants/backend.constants.d.ts +0 -1
- package/constants/backend.constants.mjs +0 -1
- package/constants/chains.constants.cjs +1 -1
- package/constants/chains.constants.d.ts +0 -1
- package/constants/chains.constants.mjs +40 -57
- package/constants/coingecko.constants.cjs +1 -1
- package/constants/coingecko.constants.d.ts +1 -1
- package/constants/coingecko.constants.mjs +8 -12
- package/constants/crvCvx.registry.cjs +1 -1
- package/constants/crvCvx.registry.mjs +7 -5
- package/constants/deploy-data/index.d.ts +1 -2
- package/constants/protocol.constants.mjs +0 -1
- package/constants/reorg-depths.constants.cjs +1 -1
- package/constants/reorg-depths.constants.mjs +11 -12
- package/constants/server.constants.cjs +1 -1
- package/constants/server.constants.d.ts +3 -7
- package/constants/server.constants.mjs +36 -40
- package/constants/token-data/ERC20Registry.cjs +1 -1
- package/constants/token-data/ERC20Registry.mjs +9 -17
- package/constants/token-data/ethMainnetRegistry.json.cjs +1 -1
- package/constants/token-data/ethMainnetRegistry.json.mjs +17 -0
- package/constants/token-data/ethMainnetRegistryFixed.json.cjs +1 -1
- package/constants/token-data/ethMainnetRegistryFixed.json.mjs +8 -0
- package/constants/token-data/index.d.ts +1 -5
- package/constants/token-data/tokenPricing.consts.cjs +1 -1
- package/constants/token-data/tokenPricing.consts.mjs +3 -5
- package/constants/vite.constants.cjs +1 -1
- package/constants/vite.constants.mjs +9 -6
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +2 -2
- package/data-structures/Hinkal/Hinkal.mjs +25 -21
- package/data-structures/Hinkal/hinkalActionPendleLP.d.ts +1 -1
- package/data-structures/Hinkal/hinkalGetZkMeProvider.cjs +1 -1
- package/data-structures/Hinkal/hinkalGetZkMeProvider.mjs +11 -6
- package/data-structures/token-price-fetcher/TokenChecker.cjs +1 -1
- package/data-structures/token-price-fetcher/TokenChecker.d.ts +1 -2
- package/data-structures/token-price-fetcher/TokenChecker.mjs +7 -9
- package/data-structures/token-price-fetcher/index.d.ts +0 -1
- package/data-structures/transactions-manager/TransactionsManager.cjs +1 -1
- package/data-structures/transactions-manager/TransactionsManager.mjs +97 -93
- package/data-structures/transactions-manager/history/getPendleData.cjs +1 -1
- package/data-structures/transactions-manager/history/getPendleData.mjs +15 -20
- package/data-structures/transactions-manager/history/getVolatileData.d.ts +3 -3
- package/functions/pre-transaction/process-gas-estimates.cjs +1 -1
- package/functions/pre-transaction/process-gas-estimates.mjs +17 -12
- package/functions/protocols/convex.protocols.d.ts +1 -1
- package/functions/snarkjs/constant.cjs +1 -1
- package/functions/snarkjs/constant.mjs +1 -4
- package/functions/utils/cacheFunctions.cjs +1 -1
- package/functions/utils/cacheFunctions.d.ts +4 -4
- package/functions/utils/cacheFunctions.mjs +40 -26
- package/functions/utils/getDataFromTransaction.d.ts +3 -3
- package/functions/web3/uniswapAPI.cjs +1 -1
- package/functions/web3/uniswapAPI.mjs +46 -49
- package/index.cjs +1 -1
- package/index.mjs +613 -621
- package/package.json +1 -1
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.mjs +7 -4
- package/providers/prepareWagmiv1Hinkal.cjs +1 -1
- package/providers/prepareWagmiv1Hinkal.mjs +7 -4
- package/types/curve.types.cjs +1 -1
- package/types/curve.types.mjs +5 -6
- package/types/duneAPI.types.d.ts +9 -0
- package/types/index.d.ts +1 -0
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.mjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
- package/constants/deploy-data/deploy-data-blast.json.cjs +0 -1
- package/constants/deploy-data/deploy-data-blast.json.mjs +0 -9604
- package/constants/token-data/blastRegistry.json.cjs +0 -1
- package/constants/token-data/blastRegistry.json.mjs +0 -137
- package/constants/token-data/blastRegistryFixed.json.cjs +0 -1
- package/constants/token-data/blastRegistryFixed.json.mjs +0 -137
- package/constants/token-data/coingeckoRegistry.json.cjs +0 -1
- package/constants/token-data/coingeckoRegistry.json.mjs +0 -115623
- package/constants/token-data/index.cjs +0 -1
- package/constants/token-data/index.mjs +0 -6
- package/data-structures/token-price-fetcher/TokenPriceFetcher.cjs +0 -1
- package/data-structures/token-price-fetcher/TokenPriceFetcher.d.ts +0 -40
- package/data-structures/token-price-fetcher/TokenPriceFetcher.mjs +0 -198
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./coingeckoRegistry.json.cjs");require("../chains.constants.cjs");const o=e;exports.coingeckoRegistry=o;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("axios"),f=require("ethers"),P=require("../../API/getCoingeckoPrice.cjs"),v=require("../../API/callCurveAPI.cjs"),y=require("../../constants/token-data/tokenPricing.consts.cjs"),g=require("../../constants/protocol.constants.cjs"),a=require("../../constants/chains.constants.cjs"),k=require("../../constants/coingecko.constants.cjs"),T=require("../../constants/token-data/index.cjs"),I=require("../../constants/crvCvx.registry.cjs"),C=require("../../constants/token-data/ERC20Registry.cjs"),p=require("../../externalABIs/BeefyVaultAbi.json.cjs"),b=require("../../functions/utils/erc20tokenFunctions.cjs"),c=require("../../functions/utils/caseInsensitive.utils.cjs"),h=require("./TokenChecker.cjs"),A=require("../../API/callOdosAPI.cjs");class w extends h.TokenChecker{chainId;provider;erc20Registry=[];crvCvxRegistry=[];curvePools=[];beefyVaults=[];beefyTvlData={};usdcSymbol="USDC";supportsCurve=()=>a.getNonLocalhostChainId(this.chainId)!==a.chainIds.bnbMainnet;constructor(n,t){super(),this.chainId=n,this.provider=t;const e=a.getNonLocalhostChainId(this.chainId);this.erc20Registry=C.getERC20Registry(this.chainId),this.crvCvxRegistry=I.getCrvCvxWithChainId(e),this.supportsCurve()&&v.getCurvePoolsforPriceFetching(this.chainId).then(i=>{this.curvePools=i})}async updateBeefyVault(){this.beefyVaults.length===0&&(this.beefyVaults=(await l.get(y.urlForBeefyVaultTokens)).data)}findTokenId(n){let t;const e=k.CoinGeckoChainLabels[this.chainId];return n===g.zeroAddress?k.getCoingeckoIdForNativeTokens[this.chainId]:(T.coingeckoRegistry.find(i=>Object.entries(i.platforms).find(([o,s])=>o===e&&(n?c.caseInsensitiveEqual(n,s):!1))?(t=i.id,!0):!1),t)}async fetchPriceById(n){const t=await P.getCoingeckoPrice(n);return{usd:t?.usd,eth:t.eth}}async fetchPriceByAddress(n){const t=k.getCoingeckoPlatform(this.chainId);return(await P.getCoingeckoPrice2(n,t))?.usd}async fetchHETHPrice(n){const t=b.getERC20Token(n,this.chainId);if(!t||t.underlyingErc20TokenAddress!==g.zeroAddress||!t.isHToken||!this.provider)return;const{contractData:e}=a.networkRegistry[this.chainId];if(!e.hETHOracleAddress||!e.HTokenOracleABI)return;const r=await new f.ethers.Contract(e.hETHOracleAddress,e.HTokenOracleABI,this.provider).callStatic.exchangeRate(),o=Number(f.ethers.utils.formatEther(r)),s=await this.fetchPriceByTokenAddress(t.underlyingErc20TokenAddress);if(s)return o*s}async fetchPriceByTokenAddress(n,t=!1){try{console.log("fetchPriceByTokenAddress",{address:n});const e=await this.fetchHETHPrice(n);if(e)return e;const i=this.findTokenId(n);if(i){const u=(await this.fetchPriceById(i)).usd;if(u)return u}const r=await this.fetchPriceByAddress(n);if(console.log({coingecko:r}),r||t)return r;const o=await this.fetchProtocolPriceinUSD(n);if(console.log({protocolPrice:o}),o)return o;const s=await this.fetchOdosPriceinUSD(n);if(console.log({odosPrice:s}),s)return s;const d=await this.findBeefyLpPrice(n);return console.log({beefyLpPrice:d}),d||void 0}catch(e){console.log("fetchPriceByTokenAddress error ",e);return}}async fetchOdosPriceinUSD(n){const t=a.getNonLocalhostChainId(this.chainId),e=await A.getOdosPriceForToken(t,n);if(e)return e}async fetchProtocolPriceinUSD(n){const t=this.erc20Registry.find(e=>c.caseInsensitiveEqual(e.erc20TokenAddress,n));if(t){if(this.supportsCurve()&&this.curvePools.length===0&&(this.curvePools=await v.getCurvePoolsforPriceFetching(this.chainId)),h.TokenChecker.isCurveOrConvex(t,this.curvePools.map(e=>e.lpTokenAddress))){const e=await this.fetchCurvePriceinUSD(t.underlyingErc20TokenAddress??n);if(e)return e}if(h.TokenChecker.isBeefyToken(t)){const e=await this.findBeefyPriceInUSD(t.underlyingErc20TokenAddress??n);if(e)return e}if(h.TokenChecker.isPendleToken(t)){const e=await this.fetchPendleTokenPriceInUSD(n);if(e)return e}if(h.TokenChecker.isAaveToken(t)){const{underlyingErc20TokenAddress:e}=t;if(!e)return console.log("missing underlying token for aave"),0;const i=await this.fetchPriceByTokenAddress(e);if(i)return i}if(h.TokenChecker.isNonRebasingBlastToken(t)){const e=this.erc20Registry.find(r=>r.symbol===t.symbol.slice(2));if(!e)return console.log("missing rebasing variant for non-rebasing token"),0;const i=await this.fetchPriceByTokenAddress(e.erc20TokenAddress);if(i)return i}if(h.TokenChecker.isKinzaToken(t)){const{underlyingErc20TokenAddress:e}=t;if(!e)return console.log("underlying token does not exists for Kinza token"),0;const i=await this.fetchPriceByTokenAddress(e);if(i)return i}}}async fetchCurvePriceinUSD(n){const t=this.crvCvxRegistry.find(i=>c.caseInsensitiveEqual(i.lpToken,n)||c.caseInsensitiveEqual(i.gauge,n)||c.caseInsensitiveEqual(i.cvxRewards,n)),e=this.curvePools.find(i=>c.caseInsensitiveEqual(i.address,t?.pool)||c.caseInsensitiveEqual(i.lpTokenAddress,n)||c.caseInsensitiveEqual(i.gaugeAddress,n));if(e?.lpPrice)return e.lpPrice}async findBeefyPriceInUSD(n){await this.updateBeefyVault();const t=a.getNonLocalhostChainId(this.chainId),e=this.beefyVaults.find(i=>c.caseInsensitiveEqual(n,i.earnedTokenAddress)&&g.beefyChainIds[t]===i.chain);if(e&&this.provider){const{earnedTokenAddress:i,id:r}=e,s=(await new f.ethers.Contract(i,p.abi,this.provider).totalSupply()).toBigInt(),d=Number(f.ethers.utils.formatUnits(s,18));Object.keys(this.beefyTvlData).length===0&&(this.beefyTvlData=(await l.get(y.urlForBeefyVaultTotalInUSD)).data);const u=this.beefyTvlData[t][r];return!u||!d?void 0:u/d}}async fetchPendleTokenPriceInUSD(n){const t=a.getNonLocalhostChainId(this.chainId),i=this.erc20Registry.find(s=>c.caseInsensitiveEqual(s.erc20TokenAddress,n))?.underlyingErc20TokenAddress??n;console.log({searchToken:i});const r=`${t}/assets/${i}`,o=(await l.get(`${y.urlForPendleAPI}${r}`)).data;return o?o?.price.usd:0}async findBeefyLpPrice(n){await this.updateBeefyVault();const t=this.beefyVaults.find(e=>c.caseInsensitiveEqual(n,e.tokenAddress));if(t)try{const{oracleId:e}=t;return(await l.get(y.urlForBeefyVaultLpTokens)).data?.[e]}catch(e){console.log("findBeefyLpPrice error:",e);return}}}exports.TokenPriceFetcher=w;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import { CrvCvxRegistryType } from '../../constants/crvCvx.registry';
|
|
3
|
-
import { CurvePoolsAllType, ERC20Token } from '../../types';
|
|
4
|
-
import { TokenChecker } from './TokenChecker';
|
|
5
|
-
type IBeefyPool = {
|
|
6
|
-
id: string;
|
|
7
|
-
tokenAddress: string;
|
|
8
|
-
earnedTokenAddress: string;
|
|
9
|
-
pricePerFullShare: string;
|
|
10
|
-
oracleId: string;
|
|
11
|
-
chain: string;
|
|
12
|
-
};
|
|
13
|
-
export declare class TokenPriceFetcher extends TokenChecker {
|
|
14
|
-
protected chainId: number;
|
|
15
|
-
protected provider?: ethers.providers.JsonRpcProvider;
|
|
16
|
-
protected erc20Registry: ERC20Token[];
|
|
17
|
-
protected crvCvxRegistry: CrvCvxRegistryType[];
|
|
18
|
-
protected curvePools: CurvePoolsAllType[];
|
|
19
|
-
protected beefyVaults: IBeefyPool[];
|
|
20
|
-
protected beefyTvlData: Record<string, Record<string, number>>;
|
|
21
|
-
protected readonly usdcSymbol = "USDC";
|
|
22
|
-
private supportsCurve;
|
|
23
|
-
constructor(_chainId: number, _provider?: ethers.providers.JsonRpcProvider);
|
|
24
|
-
private updateBeefyVault;
|
|
25
|
-
private findTokenId;
|
|
26
|
-
fetchPriceById(tokenId: string): Promise<{
|
|
27
|
-
usd: number;
|
|
28
|
-
eth: number;
|
|
29
|
-
}>;
|
|
30
|
-
fetchPriceByAddress(tokenAddress: string): Promise<number | undefined>;
|
|
31
|
-
private fetchHETHPrice;
|
|
32
|
-
fetchPriceByTokenAddress(address: string, onlyMainRegistry?: boolean): Promise<number | undefined>;
|
|
33
|
-
private fetchOdosPriceinUSD;
|
|
34
|
-
private fetchProtocolPriceinUSD;
|
|
35
|
-
private fetchCurvePriceinUSD;
|
|
36
|
-
private findBeefyPriceInUSD;
|
|
37
|
-
private fetchPendleTokenPriceInUSD;
|
|
38
|
-
private findBeefyLpPrice;
|
|
39
|
-
}
|
|
40
|
-
export {};
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import l from "axios";
|
|
2
|
-
import { ethers as u } from "ethers";
|
|
3
|
-
import { getCoingeckoPrice as P, getCoingeckoPrice2 as k } from "../../API/getCoingeckoPrice.mjs";
|
|
4
|
-
import { getCurvePoolsforPriceFetching as y } from "../../API/callCurveAPI.mjs";
|
|
5
|
-
import { urlForBeefyVaultTokens as p, urlForBeefyVaultTotalInUSD as T, urlForPendleAPI as v, urlForBeefyVaultLpTokens as m } from "../../constants/token-data/tokenPricing.consts.mjs";
|
|
6
|
-
import { zeroAddress as g, beefyChainIds as I } from "../../constants/protocol.constants.mjs";
|
|
7
|
-
import { getNonLocalhostChainId as h, chainIds as b, networkRegistry as C } from "../../constants/chains.constants.mjs";
|
|
8
|
-
import { CoinGeckoChainLabels as A, getCoingeckoIdForNativeTokens as w, getCoingeckoPlatform as B } from "../../constants/coingecko.constants.mjs";
|
|
9
|
-
import { coingeckoRegistry as D } from "../../constants/token-data/index.mjs";
|
|
10
|
-
import { getCrvCvxWithChainId as R } from "../../constants/crvCvx.registry.mjs";
|
|
11
|
-
import { getERC20Registry as E } from "../../constants/token-data/ERC20Registry.mjs";
|
|
12
|
-
import { abi as S } from "../../externalABIs/BeefyVaultAbi.json.mjs";
|
|
13
|
-
import { getERC20Token as L } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
14
|
-
import { caseInsensitiveEqual as c } from "../../functions/utils/caseInsensitive.utils.mjs";
|
|
15
|
-
import { TokenChecker as a } from "./TokenChecker.mjs";
|
|
16
|
-
import { getOdosPriceForToken as x } from "../../API/callOdosAPI.mjs";
|
|
17
|
-
class Z extends a {
|
|
18
|
-
chainId;
|
|
19
|
-
provider;
|
|
20
|
-
erc20Registry = [];
|
|
21
|
-
// Curve state variables
|
|
22
|
-
crvCvxRegistry = [];
|
|
23
|
-
curvePools = [];
|
|
24
|
-
// Beefy state variables:
|
|
25
|
-
beefyVaults = [];
|
|
26
|
-
beefyTvlData = {};
|
|
27
|
-
usdcSymbol = "USDC";
|
|
28
|
-
supportsCurve = () => h(this.chainId) !== b.bnbMainnet;
|
|
29
|
-
constructor(r, t) {
|
|
30
|
-
super(), this.chainId = r, this.provider = t;
|
|
31
|
-
const e = h(this.chainId);
|
|
32
|
-
this.erc20Registry = E(this.chainId), this.crvCvxRegistry = R(e), this.supportsCurve() && y(this.chainId).then((i) => {
|
|
33
|
-
this.curvePools = i;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
async updateBeefyVault() {
|
|
37
|
-
this.beefyVaults.length === 0 && (this.beefyVaults = (await l.get(p)).data);
|
|
38
|
-
}
|
|
39
|
-
findTokenId(r) {
|
|
40
|
-
let t;
|
|
41
|
-
const e = A[this.chainId];
|
|
42
|
-
return r === g ? w[this.chainId] : (D.find((i) => Object.entries(i.platforms).find(
|
|
43
|
-
([s, o]) => s === e && (r ? c(r, o) : !1)
|
|
44
|
-
) ? (t = i.id, !0) : !1), t);
|
|
45
|
-
}
|
|
46
|
-
async fetchPriceById(r) {
|
|
47
|
-
const t = await P(r);
|
|
48
|
-
return { usd: t?.usd, eth: t.eth };
|
|
49
|
-
}
|
|
50
|
-
async fetchPriceByAddress(r) {
|
|
51
|
-
const t = B(this.chainId);
|
|
52
|
-
return (await k(r, t))?.usd;
|
|
53
|
-
}
|
|
54
|
-
async fetchHETHPrice(r) {
|
|
55
|
-
const t = L(r, this.chainId);
|
|
56
|
-
if (!t || t.underlyingErc20TokenAddress !== g || !t.isHToken || !this.provider)
|
|
57
|
-
return;
|
|
58
|
-
const { contractData: e } = C[this.chainId];
|
|
59
|
-
if (!e.hETHOracleAddress || !e.HTokenOracleABI)
|
|
60
|
-
return;
|
|
61
|
-
const n = await new u.Contract(
|
|
62
|
-
e.hETHOracleAddress,
|
|
63
|
-
e.HTokenOracleABI,
|
|
64
|
-
this.provider
|
|
65
|
-
).callStatic.exchangeRate(), s = Number(u.utils.formatEther(n)), o = await this.fetchPriceByTokenAddress(t.underlyingErc20TokenAddress);
|
|
66
|
-
if (o)
|
|
67
|
-
return s * o;
|
|
68
|
-
}
|
|
69
|
-
// This is general fetch price function: it has flexibility to fetch only with coingecko or also to try to find protocol specific price (use onlyMainRegistry parameter)
|
|
70
|
-
async fetchPriceByTokenAddress(r, t = !1) {
|
|
71
|
-
try {
|
|
72
|
-
console.log("fetchPriceByTokenAddress", { address: r });
|
|
73
|
-
const e = await this.fetchHETHPrice(r);
|
|
74
|
-
if (e)
|
|
75
|
-
return e;
|
|
76
|
-
const i = this.findTokenId(r);
|
|
77
|
-
if (i) {
|
|
78
|
-
const f = (await this.fetchPriceById(i)).usd;
|
|
79
|
-
if (f)
|
|
80
|
-
return f;
|
|
81
|
-
}
|
|
82
|
-
const n = await this.fetchPriceByAddress(r);
|
|
83
|
-
if (console.log({ coingecko: n }), n || t)
|
|
84
|
-
return n;
|
|
85
|
-
const s = await this.fetchProtocolPriceinUSD(r);
|
|
86
|
-
if (console.log({ protocolPrice: s }), s)
|
|
87
|
-
return s;
|
|
88
|
-
const o = await this.fetchOdosPriceinUSD(r);
|
|
89
|
-
if (console.log({ odosPrice: o }), o)
|
|
90
|
-
return o;
|
|
91
|
-
const d = await this.findBeefyLpPrice(r);
|
|
92
|
-
return console.log({ beefyLpPrice: d }), d || void 0;
|
|
93
|
-
} catch (e) {
|
|
94
|
-
console.log("fetchPriceByTokenAddress error ", e);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
async fetchOdosPriceinUSD(r) {
|
|
99
|
-
const t = h(this.chainId), e = await x(t, r);
|
|
100
|
-
if (e)
|
|
101
|
-
return e;
|
|
102
|
-
}
|
|
103
|
-
async fetchProtocolPriceinUSD(r) {
|
|
104
|
-
const t = this.erc20Registry.find(
|
|
105
|
-
(e) => c(e.erc20TokenAddress, r)
|
|
106
|
-
);
|
|
107
|
-
if (t) {
|
|
108
|
-
if (this.supportsCurve() && this.curvePools.length === 0 && (this.curvePools = await y(this.chainId)), a.isCurveOrConvex(
|
|
109
|
-
t,
|
|
110
|
-
this.curvePools.map((e) => e.lpTokenAddress)
|
|
111
|
-
)) {
|
|
112
|
-
const e = await this.fetchCurvePriceinUSD(t.underlyingErc20TokenAddress ?? r);
|
|
113
|
-
if (e)
|
|
114
|
-
return e;
|
|
115
|
-
}
|
|
116
|
-
if (a.isBeefyToken(t)) {
|
|
117
|
-
const e = await this.findBeefyPriceInUSD(t.underlyingErc20TokenAddress ?? r);
|
|
118
|
-
if (e)
|
|
119
|
-
return e;
|
|
120
|
-
}
|
|
121
|
-
if (a.isPendleToken(t)) {
|
|
122
|
-
const e = await this.fetchPendleTokenPriceInUSD(r);
|
|
123
|
-
if (e)
|
|
124
|
-
return e;
|
|
125
|
-
}
|
|
126
|
-
if (a.isAaveToken(t)) {
|
|
127
|
-
const { underlyingErc20TokenAddress: e } = t;
|
|
128
|
-
if (!e)
|
|
129
|
-
return console.log("missing underlying token for aave"), 0;
|
|
130
|
-
const i = await this.fetchPriceByTokenAddress(e);
|
|
131
|
-
if (i)
|
|
132
|
-
return i;
|
|
133
|
-
}
|
|
134
|
-
if (a.isNonRebasingBlastToken(t)) {
|
|
135
|
-
const e = this.erc20Registry.find((n) => n.symbol === t.symbol.slice(2));
|
|
136
|
-
if (!e)
|
|
137
|
-
return console.log("missing rebasing variant for non-rebasing token"), 0;
|
|
138
|
-
const i = await this.fetchPriceByTokenAddress(e.erc20TokenAddress);
|
|
139
|
-
if (i)
|
|
140
|
-
return i;
|
|
141
|
-
}
|
|
142
|
-
if (a.isKinzaToken(t)) {
|
|
143
|
-
const { underlyingErc20TokenAddress: e } = t;
|
|
144
|
-
if (!e)
|
|
145
|
-
return console.log("underlying token does not exists for Kinza token"), 0;
|
|
146
|
-
const i = await this.fetchPriceByTokenAddress(e);
|
|
147
|
-
if (i)
|
|
148
|
-
return i;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// this should work for Curve Pools, Curve Staking and Convex
|
|
153
|
-
async fetchCurvePriceinUSD(r) {
|
|
154
|
-
const t = this.crvCvxRegistry.find(
|
|
155
|
-
(i) => c(i.lpToken, r) || c(i.gauge, r) || c(i.cvxRewards, r)
|
|
156
|
-
), e = this.curvePools.find(
|
|
157
|
-
(i) => c(i.address, t?.pool) || c(i.lpTokenAddress, r) || c(i.gaugeAddress, r)
|
|
158
|
-
);
|
|
159
|
-
if (e?.lpPrice)
|
|
160
|
-
return e.lpPrice;
|
|
161
|
-
}
|
|
162
|
-
// this should work for Beefy Lp Provision and Beefy Staking
|
|
163
|
-
async findBeefyPriceInUSD(r) {
|
|
164
|
-
await this.updateBeefyVault();
|
|
165
|
-
const t = h(this.chainId), e = this.beefyVaults.find(
|
|
166
|
-
(i) => c(r, i.earnedTokenAddress) && I[t] === i.chain
|
|
167
|
-
);
|
|
168
|
-
if (e && this.provider) {
|
|
169
|
-
const { earnedTokenAddress: i, id: n } = e, o = (await new u.Contract(i, S, this.provider).totalSupply()).toBigInt(), d = Number(u.utils.formatUnits(o, 18));
|
|
170
|
-
Object.keys(this.beefyTvlData).length === 0 && (this.beefyTvlData = (await l.get(T)).data);
|
|
171
|
-
const f = this.beefyTvlData[t][n];
|
|
172
|
-
return !f || !d ? void 0 : f / d;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
async fetchPendleTokenPriceInUSD(r) {
|
|
176
|
-
const t = h(this.chainId), i = this.erc20Registry.find(
|
|
177
|
-
(o) => c(o.erc20TokenAddress, r)
|
|
178
|
-
)?.underlyingErc20TokenAddress ?? r;
|
|
179
|
-
console.log({ searchToken: i });
|
|
180
|
-
const n = `${t}/assets/${i}`, s = (await l.get(`${v}${n}`)).data;
|
|
181
|
-
return s ? s?.price.usd : 0;
|
|
182
|
-
}
|
|
183
|
-
async findBeefyLpPrice(r) {
|
|
184
|
-
await this.updateBeefyVault();
|
|
185
|
-
const t = this.beefyVaults.find((e) => c(r, e.tokenAddress));
|
|
186
|
-
if (t)
|
|
187
|
-
try {
|
|
188
|
-
const { oracleId: e } = t;
|
|
189
|
-
return (await l.get(m)).data?.[e];
|
|
190
|
-
} catch (e) {
|
|
191
|
-
console.log("findBeefyLpPrice error:", e);
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
export {
|
|
197
|
-
Z as TokenPriceFetcher
|
|
198
|
-
};
|