|
1 | 1 | const sdk = require("@defillama/sdk");
|
| 2 | +import axios from "axios"; |
2 | 3 | import { sumSingleBalance } from "../helper/generalUtil";
|
3 | 4 | import {
|
4 | 5 | bridgedSupply,
|
@@ -86,37 +87,35 @@ Frax works differently from other stables, bridged amounts don't matter.
|
86 | 87 | See: https://docs.frax.finance/cross-chain/bridge
|
87 | 88 | */
|
88 | 89 |
|
89 |
| -async function chainMinted(chain: string, decimals: number) { |
| 90 | + |
| 91 | +async function fraxMinted() { |
90 | 92 | return async function (
|
91 | 93 | _timestamp: number,
|
92 | 94 | _ethBlock: number,
|
93 | 95 | _chainBlocks: ChainBlocks
|
94 | 96 | ) {
|
95 | 97 | let balances = {} as Balances;
|
96 |
| - for (let issued of chainContracts[chain].issued) { |
97 |
| - const totalSupply = ( |
98 |
| - await sdk.api.abi.call({ |
99 |
| - abi: "erc20:totalSupply", |
100 |
| - target: issued, |
101 |
| - block: _chainBlocks?.[chain], |
102 |
| - chain: chain, |
103 |
| - }) |
104 |
| - ).output; |
105 |
| - sumSingleBalance( |
106 |
| - balances, |
107 |
| - "peggedUSD", |
108 |
| - totalSupply / 10 ** decimals, |
109 |
| - "issued", |
110 |
| - false |
| 98 | + try { |
| 99 | + const response = await axios.get( |
| 100 | + "https://api.frax.finance/v2/frax/balance-sheet/latest" |
111 | 101 | );
|
| 102 | + const data = response.data; |
| 103 | + |
| 104 | + // Calculate total supply |
| 105 | + const totalSupply = (data.totalLiabilities - data.categorySummaryUsd["asset:owned:frax"]) - data.totalLockedLiquidity |
| 106 | + const supply = totalSupply; |
| 107 | + sumSingleBalance(balances, "peggedUSD", supply, "issued", false); |
| 108 | + return balances; |
| 109 | + } catch (error) { |
| 110 | + console.error("Error fetching supply data:", error); |
112 | 111 | }
|
113 | 112 | return balances;
|
114 | 113 | };
|
115 | 114 | }
|
116 | 115 |
|
117 | 116 | const adapter: PeggedIssuanceAdapter = {
|
118 | 117 | ethereum: {
|
119 |
| - minted: chainMinted("ethereum", 18), |
| 118 | + minted: fraxMinted(), |
120 | 119 | unreleased: async () => ({}),
|
121 | 120 | },
|
122 | 121 | bsc: {
|
|
0 commit comments