diff --git a/Makefile b/Makefile index aa569aa9..db65947e 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,9 @@ reset-pw: build: docker compose build transformer +extract: + docker compose run extractors python main.py + wrap: docker compose run transformer python scripts/wrap_tables.py diff --git a/dashboard/modules/base_mainnet/perp_account.py b/dashboard/modules/base_mainnet/perp_account.py index 7fa4ef1c..e14f6567 100644 --- a/dashboard/modules/base_mainnet/perp_account.py +++ b/dashboard/modules/base_mainnet/perp_account.py @@ -80,6 +80,20 @@ def fetch_data(filters): """, db, ) + df_interest = pd.read_sql_query( + f""" + SELECT + block_timestamp, + transaction_hash, + cast(account_id as text) as account_id, + interest + FROM base_mainnet.perp_interest_charged + WHERE account_id = {account_id if account_id else 'NULL'} + and date(block_timestamp) >= '{start_date}' and date(block_timestamp) <= '{end_date}' + """, + db, + ) + df_account_liq = pd.read_sql_query( f""" SELECT @@ -92,7 +106,6 @@ def fetch_data(filters): """, db, ) - df_hourly = pd.read_sql_query( f""" SELECT @@ -118,6 +131,7 @@ def fetch_data(filters): return { "accounts": df_accounts, "order_expired": df_order_expired, + "interest": df_interest, "trade": df_trade, "transfer": df_transfer, "account_liq": df_account_liq, @@ -275,6 +289,19 @@ def main(): hide_index=True, ) + # Interest charged table + st.markdown( + """ + ### Interest Charged + """ + ) + + st.dataframe( + data["interest"], + use_container_width=True, + hide_index=True, + ) + ## export exports = [{"title": export, "df": data[export]} for export in data.keys()] with st.expander("Exports"): diff --git a/dashboard/modules/base_mainnet/perp_markets.py b/dashboard/modules/base_mainnet/perp_markets.py index da10e216..50ee73b3 100644 --- a/dashboard/modules/base_mainnet/perp_markets.py +++ b/dashboard/modules/base_mainnet/perp_markets.py @@ -30,6 +30,10 @@ def fetch_data(filters): market_id, market_symbol, funding_rate, + interest_rate, + funding_rate_apr, + long_rate_apr, + short_rate_apr, price, skew, size_usd, @@ -54,11 +58,11 @@ def make_charts(data, asset): df = data["market_history"][data["market_history"]["market_symbol"] == asset] return { - "funding": chart_lines( + "rates": chart_lines( df, "ts", - ["funding_rate"], - "Funding Rate per 24 hours", + ["funding_rate_apr", "interest_rate", "long_rate_apr", "short_rate_apr"], + "Rates", smooth=True, y_format="%", ), @@ -127,7 +131,7 @@ def main(): with col2: st.plotly_chart(charts["oi_pct"], use_container_width=True) - st.plotly_chart(charts["funding"], use_container_width=True) + st.plotly_chart(charts["rates"], use_container_width=True) ## export exports = [{"title": export, "df": data[export]} for export in data.keys()] diff --git a/dashboard/modules/base_sepolia/perp_account.py b/dashboard/modules/base_sepolia/perp_account.py index d9fe6132..9e9e4412 100644 --- a/dashboard/modules/base_sepolia/perp_account.py +++ b/dashboard/modules/base_sepolia/perp_account.py @@ -80,6 +80,20 @@ def fetch_data(filters): """, db, ) + df_interest = pd.read_sql_query( + f""" + SELECT + block_timestamp, + transaction_hash, + cast(account_id as text) as account_id, + interest + FROM base_sepolia.perp_interest_charged + WHERE account_id = {account_id if account_id else 'NULL'} + and date(block_timestamp) >= '{start_date}' and date(block_timestamp) <= '{end_date}' + """, + db, + ) + df_account_liq = pd.read_sql_query( f""" SELECT @@ -92,7 +106,6 @@ def fetch_data(filters): """, db, ) - df_hourly = pd.read_sql_query( f""" SELECT @@ -118,6 +131,7 @@ def fetch_data(filters): return { "accounts": df_accounts, "order_expired": df_order_expired, + "interest": df_interest, "trade": df_trade, "transfer": df_transfer, "account_liq": df_account_liq, @@ -275,6 +289,19 @@ def main(): hide_index=True, ) + # Interest charged table + st.markdown( + """ + ### Interest Charged + """ + ) + + st.dataframe( + data["interest"], + use_container_width=True, + hide_index=True, + ) + ## export exports = [{"title": export, "df": data[export]} for export in data.keys()] with st.expander("Exports"): diff --git a/dashboard/modules/base_sepolia/perp_markets.py b/dashboard/modules/base_sepolia/perp_markets.py index 2093d204..8370a313 100644 --- a/dashboard/modules/base_sepolia/perp_markets.py +++ b/dashboard/modules/base_sepolia/perp_markets.py @@ -30,6 +30,10 @@ def fetch_data(filters): market_id, market_symbol, funding_rate, + interest_rate, + funding_rate_apr, + long_rate_apr, + short_rate_apr, price, skew, size_usd, @@ -54,11 +58,11 @@ def make_charts(data, asset): df = data["market_history"][data["market_history"]["market_symbol"] == asset] return { - "funding": chart_lines( + "rates": chart_lines( df, "ts", - ["funding_rate"], - "Funding Rate per 24 hours", + ["funding_rate_apr", "interest_rate", "long_rate_apr", "short_rate_apr"], + "Rates", smooth=True, y_format="%", ), @@ -127,7 +131,7 @@ def main(): with col2: st.plotly_chart(charts["oi_pct"], use_container_width=True) - st.plotly_chart(charts["funding"], use_container_width=True) + st.plotly_chart(charts["rates"], use_container_width=True) ## export exports = [{"title": export, "df": data[export]} for export in data.keys()] diff --git a/indexers/base-mainnet/abi/PerpsMarketProxy.json b/indexers/base-mainnet/abi/PerpsMarketProxy.json index f1ac5f7b..2af79992 100644 --- a/indexers/base-mainnet/abi/PerpsMarketProxy.json +++ b/indexers/base-mainnet/abi/PerpsMarketProxy.json @@ -927,11 +927,6 @@ "internalType": "contract ISpotMarketSystem", "name": "spotMarket", "type": "address" - }, - { - "internalType": "string", - "name": "marketName", - "type": "string" } ], "name": "initializeFactory", @@ -945,6 +940,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "interestRate", + "outputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -1034,6 +1042,29 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "utilizationRate", + "outputs": [ + { + "internalType": "uint256", + "name": "rate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "delegatedCollateral", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lockedCredit", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -1340,6 +1371,11 @@ "internalType": "int128", "name": "positionSize", "type": "int128" + }, + { + "internalType": "uint256", + "name": "owedInterest", + "type": "uint256" } ], "stateMutability": "view", @@ -1747,6 +1783,32 @@ "name": "MaxPositionsPerAccountReached", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "marketId", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "maxMarketValue", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "newSideSize", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + } + ], + "name": "MaxUSDOpenInterestReached", + "type": "error" + }, { "inputs": [], "name": "OverflowInt256ToInt128", @@ -2012,6 +2074,40 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "marketId", + "type": "uint128" + }, + { + "internalType": "int128", + "name": "sizeDelta", + "type": "int128" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + } + ], + "name": "computeOrderFeesWithPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "orderFees", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "fillPrice", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -2109,6 +2205,40 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "accountId", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "marketId", + "type": "uint128" + }, + { + "internalType": "int128", + "name": "sizeDelta", + "type": "int128" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + } + ], + "name": "requiredMarginForOrderWithPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "requiredMargin", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -2208,6 +2338,25 @@ "name": "CollateralDeducted", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint128", + "name": "accountId", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "interest", + "type": "uint256" + } + ], + "name": "InterestCharged", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -2252,6 +2401,12 @@ "internalType": "int256", "name": "currentFundingVelocity", "type": "int256" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "interestRate", + "type": "uint128" } ], "name": "MarketUpdated", @@ -3083,9 +3238,15 @@ "internalType": "uint256", "name": "maxMarketSize", "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "maxMarketValue", + "type": "uint256" } ], - "name": "MaxMarketSizeSet", + "name": "MaxMarketSizesSet", "type": "event" }, { @@ -3437,12 +3598,17 @@ "type": "uint128" } ], - "name": "getMaxMarketSize", + "name": "getMaxMarketSizes", "outputs": [ { "internalType": "uint256", "name": "maxMarketSize", "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxMarketValue", + "type": "uint256" } ], "stateMutability": "view", @@ -3685,9 +3851,14 @@ "internalType": "uint256", "name": "maxMarketSize", "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxMarketValue", + "type": "uint256" } ], - "name": "setMaxMarketSize", + "name": "setMaxMarketSizes", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -3837,6 +4008,22 @@ "name": "InvalidFeeCollectorInterface", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "lowUtilizationInterestRateGradient", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "highUtilizationInterestRateGradient", + "type": "uint128" + } + ], + "name": "InvalidInterestRateParameters", + "type": "error" + }, { "inputs": [ { @@ -3880,6 +4067,50 @@ "name": "FeeCollectorSet", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "lowUtilizationInterestRateGradient", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "interestRateGradientBreakpoint", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "highUtilizationInterestRateGradient", + "type": "uint256" + } + ], + "name": "InterestRateParametersSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint128", + "name": "superMarketId", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "interestRate", + "type": "uint128" + } + ], + "name": "InterestRateUpdated", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -4007,6 +4238,29 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "getInterestRateParameters", + "outputs": [ + { + "internalType": "uint128", + "name": "lowUtilizationInterestRateGradient", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "interestRateGradientBreakpoint", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "highUtilizationInterestRateGradient", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "getKeeperCostNodeId", @@ -4155,6 +4409,29 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "lowUtilizationInterestRateGradient", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "interestRateGradientBreakpoint", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "highUtilizationInterestRateGradient", + "type": "uint128" + } + ], + "name": "setInterestRateParameters", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -4227,6 +4504,13 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "updateInterestRate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { diff --git a/indexers/base-mainnet/abi/PerpsMarketProxyLegacy.json b/indexers/base-mainnet/abi/PerpsMarketProxyLegacy.json index d6de01c7..4f28fb9e 100644 --- a/indexers/base-mainnet/abi/PerpsMarketProxyLegacy.json +++ b/indexers/base-mainnet/abi/PerpsMarketProxyLegacy.json @@ -65,5 +65,54 @@ ], "name": "OrderCommitted", "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint128", + "name": "marketId", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "skew", + "type": "int256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "size", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "sizeDelta", + "type": "int256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "currentFundingRate", + "type": "int256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "currentFundingVelocity", + "type": "int256" + } + ], + "name": "MarketUpdated", + "type": "event" } ] \ No newline at end of file diff --git a/indexers/base-sepolia/abi/PerpsMarketProxy.json b/indexers/base-sepolia/abi/PerpsMarketProxy.json index f1ac5f7b..2af79992 100644 --- a/indexers/base-sepolia/abi/PerpsMarketProxy.json +++ b/indexers/base-sepolia/abi/PerpsMarketProxy.json @@ -927,11 +927,6 @@ "internalType": "contract ISpotMarketSystem", "name": "spotMarket", "type": "address" - }, - { - "internalType": "string", - "name": "marketName", - "type": "string" } ], "name": "initializeFactory", @@ -945,6 +940,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "interestRate", + "outputs": [ + { + "internalType": "uint128", + "name": "", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -1034,6 +1042,29 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "utilizationRate", + "outputs": [ + { + "internalType": "uint256", + "name": "rate", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "delegatedCollateral", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "lockedCredit", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -1340,6 +1371,11 @@ "internalType": "int128", "name": "positionSize", "type": "int128" + }, + { + "internalType": "uint256", + "name": "owedInterest", + "type": "uint256" } ], "stateMutability": "view", @@ -1747,6 +1783,32 @@ "name": "MaxPositionsPerAccountReached", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "marketId", + "type": "uint128" + }, + { + "internalType": "uint256", + "name": "maxMarketValue", + "type": "uint256" + }, + { + "internalType": "int256", + "name": "newSideSize", + "type": "int256" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + } + ], + "name": "MaxUSDOpenInterestReached", + "type": "error" + }, { "inputs": [], "name": "OverflowInt256ToInt128", @@ -2012,6 +2074,40 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "marketId", + "type": "uint128" + }, + { + "internalType": "int128", + "name": "sizeDelta", + "type": "int128" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + } + ], + "name": "computeOrderFeesWithPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "orderFees", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "fillPrice", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -2109,6 +2205,40 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "accountId", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "marketId", + "type": "uint128" + }, + { + "internalType": "int128", + "name": "sizeDelta", + "type": "int128" + }, + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + } + ], + "name": "requiredMarginForOrderWithPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "requiredMargin", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -2208,6 +2338,25 @@ "name": "CollateralDeducted", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint128", + "name": "accountId", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "interest", + "type": "uint256" + } + ], + "name": "InterestCharged", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -2252,6 +2401,12 @@ "internalType": "int256", "name": "currentFundingVelocity", "type": "int256" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "interestRate", + "type": "uint128" } ], "name": "MarketUpdated", @@ -3083,9 +3238,15 @@ "internalType": "uint256", "name": "maxMarketSize", "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "maxMarketValue", + "type": "uint256" } ], - "name": "MaxMarketSizeSet", + "name": "MaxMarketSizesSet", "type": "event" }, { @@ -3437,12 +3598,17 @@ "type": "uint128" } ], - "name": "getMaxMarketSize", + "name": "getMaxMarketSizes", "outputs": [ { "internalType": "uint256", "name": "maxMarketSize", "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxMarketValue", + "type": "uint256" } ], "stateMutability": "view", @@ -3685,9 +3851,14 @@ "internalType": "uint256", "name": "maxMarketSize", "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxMarketValue", + "type": "uint256" } ], - "name": "setMaxMarketSize", + "name": "setMaxMarketSizes", "outputs": [], "stateMutability": "nonpayable", "type": "function" @@ -3837,6 +4008,22 @@ "name": "InvalidFeeCollectorInterface", "type": "error" }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "lowUtilizationInterestRateGradient", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "highUtilizationInterestRateGradient", + "type": "uint128" + } + ], + "name": "InvalidInterestRateParameters", + "type": "error" + }, { "inputs": [ { @@ -3880,6 +4067,50 @@ "name": "FeeCollectorSet", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "lowUtilizationInterestRateGradient", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "interestRateGradientBreakpoint", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "highUtilizationInterestRateGradient", + "type": "uint256" + } + ], + "name": "InterestRateParametersSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint128", + "name": "superMarketId", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint128", + "name": "interestRate", + "type": "uint128" + } + ], + "name": "InterestRateUpdated", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -4007,6 +4238,29 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "getInterestRateParameters", + "outputs": [ + { + "internalType": "uint128", + "name": "lowUtilizationInterestRateGradient", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "interestRateGradientBreakpoint", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "highUtilizationInterestRateGradient", + "type": "uint128" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "getKeeperCostNodeId", @@ -4155,6 +4409,29 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint128", + "name": "lowUtilizationInterestRateGradient", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "interestRateGradientBreakpoint", + "type": "uint128" + }, + { + "internalType": "uint128", + "name": "highUtilizationInterestRateGradient", + "type": "uint128" + } + ], + "name": "setInterestRateParameters", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -4227,6 +4504,13 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "updateInterestRate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { diff --git a/indexers/base-sepolia/abi/PerpsMarketProxyLegacy.json b/indexers/base-sepolia/abi/PerpsMarketProxyLegacy.json index d6de01c7..4f28fb9e 100644 --- a/indexers/base-sepolia/abi/PerpsMarketProxyLegacy.json +++ b/indexers/base-sepolia/abi/PerpsMarketProxyLegacy.json @@ -65,5 +65,54 @@ ], "name": "OrderCommitted", "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint128", + "name": "marketId", + "type": "uint128" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "price", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "skew", + "type": "int256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "size", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "sizeDelta", + "type": "int256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "currentFundingRate", + "type": "int256" + }, + { + "indexed": false, + "internalType": "int256", + "name": "currentFundingVelocity", + "type": "int256" + } + ], + "name": "MarketUpdated", + "type": "event" } ] \ No newline at end of file diff --git a/transformers/synthetix/models/marts/perp/fct_perp_market_history.sql b/transformers/synthetix/models/marts/perp/fct_perp_market_history.sql index e5714037..ace935f0 100644 --- a/transformers/synthetix/models/marts/perp/fct_perp_market_history.sql +++ b/transformers/synthetix/models/marts/perp/fct_perp_market_history.sql @@ -11,7 +11,11 @@ WITH base AS ( {{ convert_wei('size') }} AS SIZE, {{ convert_wei('size_delta') }} AS size_delta, {{ convert_wei('current_funding_rate') }} AS funding_rate, - {{ convert_wei('current_funding_velocity') }} AS funding_velocity + {{ convert_wei('current_funding_velocity') }} AS funding_velocity, + {{ convert_wei('interest_rate') }} AS interest_rate, + {{ convert_wei('current_funding_rate') }} * 365.25 AS funding_rate_apr, + {{ convert_wei('current_funding_rate') }} * 365.25 + {{ convert_wei('interest_rate') }} AS long_rate_apr, + {{ convert_wei('current_funding_rate') }} * -1 * 365.25 + {{ convert_wei('interest_rate') }} AS short_rate_apr FROM {{ ref('perp_market_updated') }} mu diff --git a/transformers/synthetix/models/raw/perp/perp_interest_charged.sql b/transformers/synthetix/models/raw/perp/perp_interest_charged.sql new file mode 100644 index 00000000..698b8d91 --- /dev/null +++ b/transformers/synthetix/models/raw/perp/perp_interest_charged.sql @@ -0,0 +1,4 @@ +{{ get_event_data( + 'perps_market_proxy', + 'interest_charged' +) }} diff --git a/transformers/synthetix/models/raw/perp/perp_interest_rate_updated.sql b/transformers/synthetix/models/raw/perp/perp_interest_rate_updated.sql new file mode 100644 index 00000000..1cf4c9af --- /dev/null +++ b/transformers/synthetix/models/raw/perp/perp_interest_rate_updated.sql @@ -0,0 +1,4 @@ +{{ get_event_data( + 'perps_market_proxy', + 'interest_rate_updated' +) }} diff --git a/transformers/synthetix/models/raw/perp/perp_market_updated.sql b/transformers/synthetix/models/raw/perp/perp_market_updated.sql index a63ca30b..a584ba22 100644 --- a/transformers/synthetix/models/raw/perp/perp_market_updated.sql +++ b/transformers/synthetix/models/raw/perp/perp_market_updated.sql @@ -1,4 +1,47 @@ -{{ get_event_data( - 'perps_market_proxy', - 'market_updated' -) }} +WITH legacy_events AS ( + {{ get_event_data( + 'perps_market_proxy_legacy', + 'market_updated' + ) }} +), +current_events AS ( + {{ get_event_data( + 'perps_market_proxy', + 'market_updated' + ) }} +) +SELECT + id, + block_number, + block_timestamp, + transaction_hash, + "contract", + event_name, + market_id, + price, + skew, + SIZE, + size_delta, + current_funding_rate, + current_funding_velocity, + 0 AS interest_rate +FROM + legacy_events +UNION ALL +SELECT + id, + block_number, + block_timestamp, + transaction_hash, + "contract", + event_name, + market_id, + price, + skew, + SIZE, + size_delta, + current_funding_rate, + current_funding_velocity, + interest_rate +FROM + current_events diff --git a/transformers/synthetix/models/raw/sources.yml b/transformers/synthetix/models/raw/sources.yml index 530da963..8acfedac 100644 --- a/transformers/synthetix/models/raw/sources.yml +++ b/transformers/synthetix/models/raw/sources.yml @@ -12,11 +12,14 @@ sources: - name: perps_market_proxy_event_collateral_modified - name: perps_market_proxy_event_market_created - name: perps_market_proxy_event_market_updated + - name: perps_market_proxy_legacy_event_market_updated - name: perps_market_proxy_event_order_committed - name: perps_market_proxy_legacy_event_order_committed - name: perps_market_proxy_event_order_settled - name: perps_market_proxy_event_position_liquidated - name: perps_market_proxy_event_previous_order_expired + - name: perps_market_proxy_event_interest_rate_updated + - name: perps_market_proxy_event_interest_charged - name: spot_market_proxy_event_order_committed - name: spot_market_proxy_event_order_settled @@ -59,11 +62,14 @@ sources: - name: perps_market_proxy_event_collateral_modified - name: perps_market_proxy_event_market_created - name: perps_market_proxy_event_market_updated + - name: perps_market_proxy_legacy_event_market_updated - name: perps_market_proxy_event_order_committed - name: perps_market_proxy_legacy_event_order_committed - name: perps_market_proxy_event_order_settled - name: perps_market_proxy_event_position_liquidated - name: perps_market_proxy_event_previous_order_expired + - name: perps_market_proxy_event_interest_rate_updated + - name: perps_market_proxy_event_interest_charged - name: spot_market_proxy_event_order_committed - name: spot_market_proxy_event_order_settled