Skip to content

Commit

Permalink
add EURS on Stellar, and some Stellar-specific helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliotFriend committed Jun 26, 2024
1 parent f7abea7 commit 63ab304
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/adapters/peggedAssets/helper/stellar.ts
Original file line number Diff line number Diff line change
@@ -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;
}
17 changes: 17 additions & 0 deletions src/adapters/peggedAssets/stasis-eurs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -191,6 +205,9 @@ const adapter: PeggedIssuanceAdapter = {
"peggedEUR"
),
},
stellar: {
minted: stellarMinted(),
},
};

export default adapter;

0 comments on commit 63ab304

Please sign in to comment.