Skip to content

Commit

Permalink
track moneta
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Oct 23, 2024
1 parent 2dc6e92 commit f735546
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/adapters/peggedAssets/djed/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
PeggedIssuanceAdapter,
ChainBlocks,
Balances, ChainContracts,
Balances,
} from "../peggedAsset.type";
import { sumSingleBalance } from "../helper/generalUtil";
import { getTotalSupply, getTokenBalance } from "../helper/cardano";
Expand Down
32 changes: 32 additions & 0 deletions src/adapters/peggedAssets/helper/cardano.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ const config = {
},
};

const blockClient = axios.create({
baseURL: 'https://cardano-mainnet.blockfrost.io/api/v0',
headers: {
'project_id': 'mai' + 'nnetcxT8VaeCgVMzMTSe' + 'zZijWlVkyh6XytpS',
'Content-Type': 'application/json'
},
timeout: 300000,
})

export async function getAsset(assetID: string) {
// assetID is concatenation of the policy_id and hex-encoded asset_name
const asset = await retry(
Expand All @@ -34,3 +43,26 @@ export async function getTokenBalance(token: string, owner: string) {
const assets = await getAssets(owner);
return assets.find((i: any) => i.unit === token)?.quantity ?? 0;
}


export async function addressesUtxosAssetAll(address: string, asset: string) {

const addresses = []
let page = 1
let response
do {
response = await blockClient.get(`/addresses/${address}/utxos/${asset}`, {
params: { count: 100, page, }
})
response = response.data
addresses.push(...response)
page++
} while (response.length)
return addresses
}


export async function getScriptsDatum(datumHash: string) {
const { data } = await blockClient.get(`scripts/datum/${datumHash}`)
return data
}
27 changes: 27 additions & 0 deletions src/adapters/peggedAssets/moneta/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {
PeggedIssuanceAdapter,
Balances,
} from "../peggedAsset.type";
import { sumSingleBalance } from "../helper/generalUtil";
import { addressesUtxosAssetAll, getScriptsDatum } from "../helper/cardano";

async function getCardanoSupply() {
let balances = {} as Balances;
const usdm_count_nft_asset = "e319d8e6629ff7991c8ae4f8aec2e0f10463ebdf29b57d26d34914f65553444d5f434f554e54"
const count_address = "addr1wyl82v9qy06hsz50hqqdy0u6xw9hdewy7twjahgek2tpp7c0qajez"
const utxo = (await addressesUtxosAssetAll(count_address, usdm_count_nft_asset))[0]
const datum_hash = utxo.data_hash
const datum = await getScriptsDatum(datum_hash)
const total_value_locked = datum.json_value.fields[0].int / 1_000_000
sumSingleBalance(balances, "peggedUSD", total_value_locked, "issued", false);

return balances;
}

const adapter: PeggedIssuanceAdapter = {
cardano: {
minted: getCardanoSupply,
},
};

export default adapter;

0 comments on commit f735546

Please sign in to comment.