From 63ab3048f28006222c1bb874293404c5c764fbd4 Mon Sep 17 00:00:00 2001 From: Elliot Voris Date: Wed, 26 Jun 2024 12:45:04 -0500 Subject: [PATCH] add EURS on Stellar, and some Stellar-specific helper functions --- src/adapters/peggedAssets/helper/stellar.ts | 24 +++++++++++++++++++ .../peggedAssets/stasis-eurs/index.ts | 17 +++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/adapters/peggedAssets/helper/stellar.ts diff --git a/src/adapters/peggedAssets/helper/stellar.ts b/src/adapters/peggedAssets/helper/stellar.ts new file mode 100644 index 00000000..4dff5c04 --- /dev/null +++ b/src/adapters/peggedAssets/helper/stellar.ts @@ -0,0 +1,24 @@ +const axios = require("axios"); +const retry = require("async-retry"); + +const stellarExpertEndpoint = (assetCode: string, assetIssuer: string): string => + `https://api.stellar.expert/explorer/public/asset/${assetCode}-${assetIssuer}`; + +export async function getAsset(assetID: string) { + // assetID is concatenation of the assetCode and assetIssuer, separated by a colon + const [assetCode, assetIssuer] = assetID.split(":"); + const asset = await retry( + async (_bail: any) => + await axios.get(stellarExpertEndpoint(assetCode, assetIssuer)) + ); + const data = asset.data; + return data; +} + +export async function getTotalSupply(assetID: string) { + // assetID is concatenation of the assetCode and assetIssuer, separated by a colon + const asset = await getAsset(assetID); + const decimals = 7; + const supply = asset?.supply; + return supply / 10 ** decimals; +} diff --git a/src/adapters/peggedAssets/stasis-eurs/index.ts b/src/adapters/peggedAssets/stasis-eurs/index.ts index 26b58924..0acd35b7 100644 --- a/src/adapters/peggedAssets/stasis-eurs/index.ts +++ b/src/adapters/peggedAssets/stasis-eurs/index.ts @@ -10,6 +10,7 @@ import { PeggedIssuanceAdapter, Balances, ChainContracts, } from "../peggedAsset.type"; +import * as stellar from "../helper/stellar"; const axios = require("axios"); const retry = require("async-retry"); @@ -152,6 +153,19 @@ async function algorandMinted() { }; } +async function stellarMinted() { + return async function ( + _timestamp: number, + _ethBlock: number, + _chainBlocks: ChainBlocks + ) { + let balances = {} as Balances; + const supply = await stellar.getTotalSupply("EURS:GC5FGCDEOGOGSNWCCNKS3OMEVDHTE3Q5A5FEQWQKV3AXA7N6KDQ2CUZJ") + sumSingleBalance(balances, "peggedEUR", supply, "issued", false) + return balances; + } +} + const adapter: PeggedIssuanceAdapter = { ethereum: { minted: chainMinted("ethereum", 2), @@ -191,6 +205,9 @@ const adapter: PeggedIssuanceAdapter = { "peggedEUR" ), }, + stellar: { + minted: stellarMinted(), + }, }; export default adapter;