diff --git a/fees/tether/attestations-stablecoins.ts b/fees/tether/attestations-stablecoins.ts index 578a7f6179..ccdf7c329f 100644 --- a/fees/tether/attestations-stablecoins.ts +++ b/fees/tether/attestations-stablecoins.ts @@ -2,6 +2,12 @@ import { Adapter, FetchOptions } from "../../adapters/types"; import { METRIC } from "../../helpers/metrics"; import { findClosest } from "../../helpers/utils/findClosest" import { httpGet } from "../../utils/fetchURL"; +import { ethers } from "ethers"; +import ADDRESSES from '../../helpers/coreAssets.json'; + +const TETHER_TREASURY = "0x5754284f345afc66a98fbB0a0Afe71e0F007B949"; +const TRANSFER_EVENT = "event Transfer (address indexed from, address indexed to, uint256 value)"; +const TRANSFER_TOPIC = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"; export function buildStablecoinAdapter(stablecoinId: string, daysBetweenAttestations:number, attestations: { time: string, // time of report @@ -13,15 +19,15 @@ export function buildStablecoinAdapter(stablecoinId: string, daysBetweenAttestat version: 2, adapter: { ethereum: { - fetch: async ({ fromTimestamp, createBalances }: FetchOptions) => { - const dailyFees = createBalances() + fetch: async (options: FetchOptions) => { + const dailyFees = options.createBalances() const stablecoinData = await httpGet(`https://stablecoins.llama.fi/stablecoin/${stablecoinId}`) - const supply = (findClosest(fromTimestamp, stablecoinData.tokens.map((d: any)=>({...d, time: d.date*1e3})), 1.5 * 24 * 3600) as any).circulating.peggedUSD + const supply = (findClosest(options.fromTimestamp, stablecoinData.tokens.map((d: any)=>({...d, time: d.date*1e3})), 1.5 * 24 * 3600) as any).circulating.peggedUSD - const closestAttestation = findClosest(fromTimestamp, attestations) - if (new Date(closestAttestation.time).getTime() - 1.2 * daysBetweenAttestations * 24 * 3600e3 > fromTimestamp * 1e3) { + const closestAttestation = findClosest(options.fromTimestamp, attestations) + if (new Date(closestAttestation.time).getTime() - 1.2 * daysBetweenAttestations * 24 * 3600e3 > options.fromTimestamp * 1e3) { throw new Error("Trying to refill with no attestations, pls add attestations") } @@ -30,6 +36,37 @@ export function buildStablecoinAdapter(stablecoinId: string, daysBetweenAttestat const decimals = 1e6 // assuming 6 decimals dailyFees.add(stablecoinData.address, decimals * annualYield / 365, METRIC.ASSETS_YIELDS) + if (stablecoinId === '1') { + const acquisitionLogs = await options.getLogs({ + eventAbi: TRANSFER_EVENT, + topics: [ + TRANSFER_TOPIC, + ethers.zeroPadValue(TETHER_TREASURY, 32), + ], + target: ADDRESSES.ethereum.USDT + }); + + acquisitionLogs.forEach((acquisition: any) => { + const acquisitionAmount = Number(acquisition.value) / 1e6; + dailyFees.addUSDValue(acquisitionAmount / 1000); + }); + + const redemptionLogs = await options.getLogs({ + eventAbi: TRANSFER_EVENT, + topics: [ + TRANSFER_TOPIC, + null as any, + ethers.zeroPadValue(TETHER_TREASURY, 32), + ], + target: ADDRESSES.ethereum.USDT + }); + + redemptionLogs.forEach((redeem: any) => { + const redemptionAmount = Number(redeem.value) / 1e6; + dailyFees.addUSDValue(Math.max(1000, redemptionAmount / 1000)); + }); + } + return { dailyFees, dailyRevenue: dailyFees, diff --git a/fees/tether/index.ts b/fees/tether/index.ts index fcde5d3c5f..853030ba24 100644 --- a/fees/tether/index.ts +++ b/fees/tether/index.ts @@ -122,20 +122,23 @@ const adapter = buildStablecoinAdapter('1', 30* 3, ]); adapter.methodology = { - Fees: 'All yields from USDT backing assets investments, mostly US Treasury Bills.', - Revenue: 'All yields from USDT backing assets investments, mostly US Treasury Bills collected by Tether.', - ProtocolRevenue: 'All yields from USDT backing assets investments, mostly US Treasury Bills collected by Tether.', + Fees: 'All yields from USDT backing assets investments, mostly US Treasury Bills and 0.1% mint and redeem fees.', + Revenue: 'All yields from USDT backing assets investments, mostly US Treasury Bills collected by Tether and 0.1% mint and redeem fees.', + ProtocolRevenue: 'All yields from USDT backing assets investments, mostly US Treasury Bills collected by Tether and 0.1% mint and redeem fees.', } adapter.breakdownMethodology = { Fees: { [METRIC.ASSETS_YIELDS]: 'All yields from USDT backing assets investments, mostly US Treasury Bills.', + [METRIC.MINT_REDEEM_FEES]: '0.1% Mint and redeem fees.' }, Revenue: { [METRIC.ASSETS_YIELDS]: 'All yields from USDT backing assets investments, mostly US Treasury Bills collected by Tether.', + [METRIC.MINT_REDEEM_FEES]: '0.1% Mint and redeem fees.' }, ProtocolRevenue: { [METRIC.ASSETS_YIELDS]: 'All yields from USDT backing assets investments, mostly US Treasury Bills collected by Tether.', + [METRIC.MINT_REDEEM_FEES]: '0.1% Mint and redeem fees.' }, }