Mint / Redeem

Simple Index - Mint: setprotocol_v2."BasicIssuanceModule_evt_SetTokenIssued"

Simple Index - Redeem: setprotocol_v2."BasicIssuanceModule_evt_SetTokenRedeemed"

Simple Index (Exchange Issuance) - Mint: setprotocol_v2."ExchangeIssuance_evt_ExchangeIssue"

Simple Index (Exchange Issuance) - Redeem: setprotocol_v2."ExchangeIssuance_evt_ExchangeRedeem"

Flexible Leverage Index - Mint: setprotocol_v2."DebtIssuanceModule_evt_SetTokenIssued"

Flexible Leverage Index - Redeem: setprotocol_v2."DebtIssuanceModule_evt_SetTokenRedeemed"

Code Example:

dpi_daily_minted_units AS (
SELECT 
    date_trunc('day', evt_block_time) AS day, 
    "_setToken" AS token_address,
    SUM("_quantity"/1e18) AS amount
FROM setprotocol_v2."BasicIssuanceModule_evt_SetTokenIssued"
WHERE "_setToken" = '\\x1494ca1f11d487c2bbe4543e90080aeba4ba3c2b'
GROUP BY 1,2
)
dpi_daily_redeemed_units AS (
SELECT 
    date_trunc('day', evt_block_time) AS day, 
    "_setToken" AS token_address,
    SUM("_quantity"/1e18) AS amount
FROM setprotocol_v2."BasicIssuanceModule_evt_SetTokenRedeemed"
WHERE "_setToken" = '\\x1494ca1f11d487c2bbe4543e90080aeba4ba3c2b'
GROUP BY 1,2
)

Prices

ERC20 Prices: prices.usd

Layer 1 Prices: prices.layer1_usd

DEX Prices: dex.trades

Code Example

dpi_eth_price_hourly AS (
SELECT
		date_trunc('hour', block_time) AS hour,
		(SUM(token_b_amount)/1e18) / (SUM(token_a_amount)/1e18) AS dpi_weth
FROM dex.trades
WHERE token_a_address = '\\x1494ca1f11d487c2bbe4543e90080aeba4ba3c2b' -- DPI
AND token_b_address = '\\xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' -- WETH
GROUP BY 1
)
eth_usd_price_hourly AS (
SELECT
    date_trunc('hour', minute) AS hour,
    AVG(price) AS eth_usd
FROM prices.layer1_usd
WHERE symbol = 'ETH'
AND minute >= (SELECT MIN(hour) FROM dpi_eth_price_hourly)
GROUP BY 1
)
dpi_usd_price_hourly AS (
SELECT
    a.hour,
    a.dpi_weth * b.eth_usd AS dpi_usd
FROM dpi_eth_price_hourly a
LEFT JOIN eth_usd_price_hourly b ON a.hour = b.hour
)