From 49a8691a1848bcedb1d0eddb1fb76b02e5b29b06 Mon Sep 17 00:00:00 2001 From: Define101 Date: Thu, 4 Jan 2024 12:56:41 +0000 Subject: [PATCH] add euroe on concordium --- .../peggedAssets/euroe-stablecoin/index.ts | 36 +++++++++++++++++-- src/adapters/peggedAssets/helper/chains.json | 3 +- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/adapters/peggedAssets/euroe-stablecoin/index.ts b/src/adapters/peggedAssets/euroe-stablecoin/index.ts index 52cdab63..5885efae 100644 --- a/src/adapters/peggedAssets/euroe-stablecoin/index.ts +++ b/src/adapters/peggedAssets/euroe-stablecoin/index.ts @@ -1,6 +1,7 @@ const sdk = require("@defillama/sdk"); -import { sumSingleBalance } from "../helper/generalUtil"; -import { bridgedSupply, solanaMintedOrBridged } from "../helper/getSupply"; +import fetch from "node-fetch"; +import { sumSingleBalance, } from "../helper/generalUtil"; +import { solanaMintedOrBridged } from "../helper/getSupply"; import { ChainBlocks, PeggedIssuanceAdapter, @@ -34,6 +35,33 @@ const chainContracts: ChainContracts = { }, }; +async function concordiumMinted(apiEndpoint: string, decimals: number) { + return async function ( + _timestamp: number, + _ethBlock: number, + _chainBlocks: ChainBlocks + ) { + let balances = {} as Balances; + + try { + const res = await fetch(apiEndpoint); + + if (!res.ok) { + throw new Error(`Failed to fetch data from Concordium API. Status: ${res.status}`); + } + + const totalSupply = parseFloat(await res.text()); + const formattedTotalSupply = Number(totalSupply.toFixed(decimals)); + sumSingleBalance(balances, "peggedEUR", formattedTotalSupply, apiEndpoint, true); + + } catch (error) { + console.error(`Error fetching data from Concordium API: ${error}`); + } + + return balances; + }; +} + async function chainMinted(chain: string, decimals: number) { return async function ( _timestamp: number, @@ -87,6 +115,10 @@ const adapter: PeggedIssuanceAdapter = { minted: chainMinted("optimism", 6), unreleased: async () => ({}), }, + concordium: { + minted: concordiumMinted("https://www.euroe.com/api/totalsupply/CCD", 6), + unreleased: async () => ({}), + }, }; export default adapter; diff --git a/src/adapters/peggedAssets/helper/chains.json b/src/adapters/peggedAssets/helper/chains.json index 52cccfd8..a5195ccf 100644 --- a/src/adapters/peggedAssets/helper/chains.json +++ b/src/adapters/peggedAssets/helper/chains.json @@ -135,5 +135,6 @@ "linea", "mantle", "agoric", - "emoney" + "emoney", + "concordium" ]