diff --git a/src/adapters/peggedAssets/prices/index.ts b/src/adapters/peggedAssets/prices/index.ts index 3fc7c83..f428c3a 100644 --- a/src/adapters/peggedAssets/prices/index.ts +++ b/src/adapters/peggedAssets/prices/index.ts @@ -16,12 +16,11 @@ type ChainlinkFeeds = { }; }; -type UniswapPools = { +type CurvePools = { [coinGeckoID: string]: { - address: string; - token: 0 | 1; - chain: string; - decimalsDifference: number; // difference between number of decimals for token1 and number for token0 + baseURL: string; + poolID: string; + tokenAddress: string; }; }; @@ -31,6 +30,15 @@ type AddressesForDexes = { }; }; +type UniswapPools = { + [coinGeckoID: string]: { + address: string; + token: 0 | 1; + chain: string; + decimalsDifference: number; // difference between number of decimals for token1 and number for token0 + }; +}; + const feeds: ChainlinkFeeds = { tether: { address: "0x3e7d1eab13ad0104d2750b8863b489d65364e32d", @@ -119,12 +127,81 @@ const feeds: ChainlinkFeeds = { }, // RAI-USD ETH }; -const uniswapPools: UniswapPools = { +const curvePools: CurvePools = { + husd: { + baseURL: "ethereum/main", + poolID: "20", + tokenAddress: "0xdF574c24545E5FfEcb9a659c229253D4111d87e1", + }, + "alchemix-usd": { + baseURL: "ethereum/main", + poolID: "37", + tokenAddress: "0xBC6DA0FE9aD5f3b0d58160288917AA56653660E9", + }, + "yusd-stablecoin": { + baseURL: "avalanche/factory", + poolID: "factory-v2-69", + tokenAddress: "0x111111111111ed1D73f860F57b2798b683f2d325", + }, + usdd: { + baseURL: "ethereum/factory", + poolID: "factory-v2-116", + tokenAddress: "0x0C10bF8FcB7Bf5412187A595ab97a3609160b5c6", + }, + "dola-usd": { + baseURL: "ethereum/factory", + poolID: "factory-v2-27", + tokenAddress: "0x865377367054516e17014CcdED1e7d814EDC9ce4", + }, + "nexus-usd": { + baseURL: "ethereum/factory", + poolID: "factory-v2-21", + tokenAddress: "0x1BEf2e5DE862034Fb0ed456DF59d29Ecadc9934C", + }, + "origin-dollar": { + baseURL: "ethereum/factory", + poolID: "factory-v2-9", + tokenAddress: "0x2A8e1E676Ec238d8A992307B495b45B3fEAa5e86", + }, reserve: { - address: "0x98a19D4954B433Bd315335A05d7d6371D812A492", - token: 0, - chain: "ethereum", - decimalsDifference: -12, + baseURL: "ethereum/main", + poolID: "23", + tokenAddress: "0x196f4727526eA7FB1e17b2071B3d8eAA38486988", + }, + musd: { + baseURL: "ethereum/main", + poolID: "22", + tokenAddress: "0xe2f2a5C287993345a840Db3B0845fbC70f5935a5", + }, + tor: { + baseURL: "fantom/factory", + poolID: "factory-v2-62", + tokenAddress: "0x74E23dF9110Aa9eA0b6ff2fAEE01e740CA1c642e", + }, + spiceusd: { + baseURL: "avalanche/factory", + poolID: "factory-v2-78", + tokenAddress: "0xaB05b04743E0aeAF9D2cA81E5D3b8385e4BF961e", + }, + usdp: { + baseURL: "ethereum/factory", + poolID: "factory-v2-59", + tokenAddress: "0x8E870D67F660D95d5be530380D0eC0bd388289E1", + }, + mimatic: { + baseURL: "polygon/factory", + poolID: "factory-v2-7", + tokenAddress: "0xa3Fa99A148fA48D14Ed51d610c367C61876997F1", + }, + "token-dforce-usd": { + baseURL: "ethereum/factory", + poolID: "factory-v2-77", + tokenAddress: "0x0a5E677a6A24b2F1A2Bf4F3bFfC443231d2fDEc8", + }, + "dei-token": { + baseURL: "ethereum/factory", + poolID: "factory-v2-47", + tokenAddress: "0xDE12c7959E1a72bbe8a5f7A1dc8f8EeF9Ab011B3", }, }; @@ -183,6 +260,15 @@ const birdeye: AddressesForDexes = { }, }; +const uniswapPools: UniswapPools = { + reserve: { + address: "0x98a19D4954B433Bd315335A05d7d6371D812A492", + token: 0, + chain: "ethereum", + decimalsDifference: -12, + }, +}; + export default async function getCurrentPeggedPrice( token: string, chainBlocks: ChainBlocks, @@ -205,6 +291,37 @@ export default async function getCurrentPeggedPrice( console.error(`Could not get ChainLink price for token ${token}`); return null; } + if (priceSource === "curve") { + const pool = curvePools[token]; + const poolID = pool?.poolID; + const tokenAddress = pool?.tokenAddress; + const baseURL = pool?.baseURL; + if (poolID) { + for (let i = 0; i < 5; i++) { + try { + const res = await axios.get( + `https://api.curve.fi/api/getPools/${baseURL}` + ); + const filteredPools = res.data.data.poolData.filter( + (obj: any) => obj?.id === `${poolID}` + ); + const tokenData = filteredPools[0]?.coins?.filter( + (obj: any) => obj.address === `${tokenAddress}` + ); + const price = parseFloat(tokenData[0]?.usdPrice); + if (price) { + return price; + } else { + console.error(`Could not get Curve price for token ${token}`); + return null; + } + } catch (e) { + console.error(e); + continue; + } + } + } + } if (priceSource === "uniswap") { const pool = uniswapPools[token]; if (pool) { diff --git a/src/peggedData/peggedData.ts b/src/peggedData/peggedData.ts index 9cfe46d..52ba83c 100644 --- a/src/peggedData/peggedData.ts +++ b/src/peggedData/peggedData.ts @@ -514,7 +514,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "crypto-backed", - priceSource: "dexscreener", + priceSource: "curve", chains: ["Avalanche"], auditLinks: null, twitter: "https://twitter.com/YetiFinance", @@ -537,7 +537,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "algorithmic", - priceSource: "dexscreener", + priceSource: "curve", chains: ["Tron", "Bittorrent", "Ethereum", "BSC"], auditLinks: ["https://usdd.io/SlowMistAuditReport-USDDTRC20.pdf"], twitter: "https://twitter.com/usddio", @@ -560,7 +560,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "crypto-backed", - priceSource: "dexscreener", + priceSource: "curve", chains: ["Ethereum", "Fantom"], auditLinks: null, twitter: "https://twitter.com/InverseFinance", @@ -606,9 +606,9 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "fiat-backed", - priceSource: "dexscreener", + priceSource: "curve", chains: ["Ethereum", "Tron", "Heco", "Elastos", "Solana"], - auditLinks: [""], + auditLinks: null, twitter: "https://twitter.com/Stablecoin_HUSD", wiki: "https://wiki.defillama.com/wiki/HUSD", }, @@ -629,7 +629,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "crypto-backed", - priceSource: null, + priceSource: "curve", chains: [ "Ethereum", "BSC", @@ -688,7 +688,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "crypto-backed", - priceSource: "dexscreener", + priceSource: "curve", chains: ["Ethereum", "Arbitrum", "Optimism", "Fantom"], auditLinks: null, twitter: "https://twitter.com/AlchemixFi", @@ -757,7 +757,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "crypto-backed", - priceSource: "dexscreener", + priceSource: "curve", chains: ["Ethereum"], auditLinks: null, twitter: "https://twitter.com/originprotocol", @@ -803,7 +803,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "crypto-backed", - priceSource: "uniswap", + priceSource: "curve", chains: ["Ethereum", "Gnosis"], auditLinks: null, twitter: "https://twitter.com/holareserve", @@ -826,7 +826,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "crypto-backed", - priceSource: "coingecko", + priceSource: "curve", chains: ["Ethereum", "Polygon", "Gnosis"], auditLinks: null, twitter: "https://twitter.com/mstable_", @@ -897,7 +897,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "crypto-backed", - priceSource: "dexscreener", + priceSource: "curve", chains: ["Fantom"], auditLinks: null, twitter: "https://twitter.com/HectorDAO_HEC", @@ -943,7 +943,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "algorithmic", - priceSource: "dexscreener", + priceSource: "curve", chains: ["Avalanche", "Ethereum", "Polygon", "BSC"], auditLinks: null, twitter: "https://twitter.com/spicetradeai", @@ -966,7 +966,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "algorithmic", - priceSource: "dexscreener", + priceSource: "dexscreener", // does not liquidity on curve chains: ["Arbitrum"], auditLinks: null, twitter: "https://twitter.com/SperaxUSD", @@ -989,7 +989,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "crypto-backed", - priceSource: "coingecko", + priceSource: "curve", chains: ["Ethereum", "Gnosis", "BSC", "Fantom"], auditLinks: null, twitter: "https://twitter.com/unitprotocol", @@ -1035,7 +1035,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "crypto-backed", - priceSource: "dexscreener", + priceSource: "curve", chains: [ "Polygon", "Fantom", @@ -1144,7 +1144,7 @@ export default [ category: "stablecoins", pegType: "peggedVAR", pegMechanism: "algorithmic", - priceSource: "coingecko", // coingecko not giving correct price atm + priceSource: "coingecko", // curve has no liqudity, and coingecko not giving accurate price chains: ["Ethereum", "Arbitrum"], auditLinks: null, twitter: "https://twitter.com/voltprotocol", @@ -1267,7 +1267,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "crypto-backed", - priceSource: "coingecko", + priceSource: "curve", chains: [ "Ethereum", "Polygon", @@ -1344,7 +1344,7 @@ export default [ category: "stablecoins", pegType: "peggedUSD", pegMechanism: "algorithmic", - priceSource: "dexscreener", + priceSource: "curve", chains: ["Fantom", "Ethereum", "Polygon", "BSC", "Metis"], auditLinks: null, twitter: "https://twitter.com/DeusDao", diff --git a/src/peggedData/types.ts b/src/peggedData/types.ts index 5035874..ab3ec11 100644 --- a/src/peggedData/types.ts +++ b/src/peggedData/types.ts @@ -8,7 +8,7 @@ type Bridges = { type PeggedCategory = "stablecoins"; type PegType = "peggedUSD"; type PegMechanism = "algorithmic" | "fiat-backed" | "crypto-backed"; -export type PriceSource = "chainlink" | "uniswap"; +export type PriceSource = "chainlink" | "uniswap" | "dexscreener" | "curve" | "coingecko" | "birdeye"; export type PeggedAsset = { id: string;