Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions fees/tether/attestations-stablecoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}

Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions fees/tether/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
},
}

Expand Down
Loading