Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
-%}
{# Contains pool addresses #}

SELECT pool_address, pool_name, v4_upgrate_lt FROM (VALUES
('0:BCAD466A47FA565750729565253CD073CA24D856804499090C2100D95C809F9E', 'Main pool', 49828980000001),
('0:489595F65115A45C24A0DD0176309654FB00B95E40682F0C3E85D5A4D86DFB25', 'LP pool', 49712577000001),
('0:0D511552DDF8413BD6E2BE2837E22C89422F7B16131BA62BE8D5A504012D8661', 'Alts pool', 0),
('0:9D21D5DFD6403FD8777D99B1B34850C43C0F8FC7E7ADF2A4D61C45E0446A342B', 'Stable pool', 0)
) AS T(pool_address, pool_name, v4_upgrate_lt)
SELECT pool_address, pool_name, v4_upgrate_lt, v9_upgrate_lt FROM (VALUES
('0:BCAD466A47FA565750729565253CD073CA24D856804499090C2100D95C809F9E', 'Main pool', 49828980000001, 61426459000001),
('0:489595F65115A45C24A0DD0176309654FB00B95E40682F0C3E85D5A4D86DFB25', 'LP pool', 49712577000001, 61359759000001),
('0:0D511552DDF8413BD6E2BE2837E22C89422F7B16131BA62BE8D5A504012D8661', 'Alts pool', 0, 61187409000001),
('0:9D21D5DFD6403FD8777D99B1B34850C43C0F8FC7E7ADF2A4D61C45E0446A342B', 'Stable pool', 0, 61359759000001)
) AS T(pool_address, pool_name, v4_upgrate_lt, v9_upgrate_lt)

{%- endmacro -%}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ SELECT asset_id, asset_name, jetton_master, decimals FROM
(CAST('101563884026323503647891287974015286987607783840172791059852695820980647056177' AS UINT256), 'CATI', '0:FE72F474373E97032441BDB873F9A6D3AD10BAB08E6DBC7BEFA5E42B695F5400', 9),
(CAST('33604868692898791249369426189145713090064546741393719833658701125733712580919' AS UINT256), 'tsUSDe', '0:D0E545323C7ACB7102653C073377F7E3C67F122EB94D430A250739F109D4A57D', 6),
(CAST('98281638255104512379049519410242269170317135545117667048087651483812279009354' AS UINT256), 'USDe', '0:086FA2A675F74347B08DD4606A549B8FDB98829CB282BC1949D3B12FBAED9DCC', 6),
(CAST('6111297782570570129290420344884587495512746870153062431820826875465825931443' AS UINT256), 'PT_tsUSDe_01Sep2025', '0:DBF7406CB39167232ABB54C9A71B651E648CD9A2642C20BC3D1E3A35C31685D5', 9)
(CAST('6111297782570570129290420344884587495512746870153062431820826875465825931443' AS UINT256), 'PT_tsUSDe_01Sep2025', '0:DBF7406CB39167232ABB54C9A71B651E648CD9A2642C20BC3D1E3A35C31685D5', 9),
(CAST('45271267922377506789669073275694049849109676194656489600278771174506032218722' AS UINT256), 'TONUSDT_STONFI', '0:8649CAD97B5C5BC96A960EF748EA6CCFF8601C01616FE995EE6893AE4AA7A6C6', 9)
) AS temp (asset_id, asset_name, jetton_master, decimals)
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@

-- log::liquidate_success is sent by the router and contains all the data regarding the liquidation
-- https://github.com/evaafi/contracts/blob/d5a6bf889f8bbfa8bcc82671c17e65a3b2b360cd/contracts/core/master-liquidate.fc#L353-L377
-- https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-liquidate.fc#L399-L423

WITH evaa_ton_pools AS (
{{ evaa_ton_pools() }}
),
source_data AS (
SELECT M.block_date, M.tx_hash, M.trace_id, M.tx_now, M.tx_lt, pool_address, pool_name, tx_lt <= v4_upgrate_lt AS is_pre_v4, body_boc
SELECT M.block_date, M.tx_hash, M.trace_id, M.tx_now, M.tx_lt, pool_address, pool_name,
tx_lt <= v4_upgrate_lt AS is_pre_v4,
tx_lt <= v9_upgrate_lt AS is_pre_v9,
CASE
WHEN tx_lt <= v4_upgrate_lt THEN 'v3'
WHEN v4_upgrate_lt < tx_lt AND tx_lt <= v9_upgrate_lt THEN 'v4'
ELSE 'v9'
END AS protocol_version,
body_boc
FROM {{ source('ton', 'messages') }} M
JOIN evaa_ton_pools ON M.source = pool_address
WHERE M.direction = 'out' AND M.destination IS NULL -- ext out message
Expand Down Expand Up @@ -88,24 +97,69 @@ select {{ ton_from_boc('body_boc', [
ton_load_int(64, 'new_collateral_total_borrow'),
ton_load_uint(64, 'collateral_s_rate'),
ton_load_uint(64, 'collateral_b_rate')
]) }} as result, * FROM source_data WHERE NOT is_pre_v4
]) }} as result, * FROM source_data WHERE is_pre_v4 = false AND is_pre_v9 = true
), parse_output_postv9 as (
select {{ ton_from_boc('body_boc', [
ton_begin_parse(),
ton_load_uint(8, 'opcode'),
ton_load_address('owner_address'),
ton_load_address('sender_address'),
ton_load_address('liquidator_address'),
ton_load_uint(32, '_current_time'),
ton_load_int(16, 'subaccount_id'),
ton_load_ref(),
ton_begin_parse(),
ton_load_uint(256, 'transferred_asset_id'),
ton_load_uint(64, 'transferred_amount'),
ton_load_int(64, 'new_user_loan_principal'),
ton_load_int(64, 'loan_new_total_supply'),
ton_load_int(64, 'loan_new_total_borrow'),
ton_load_uint(64, 'loan_s_rate'),
ton_load_uint(64, 'loan_b_rate'),
ton_restart_parse(),
ton_begin_parse(),
ton_skip_refs(1),
ton_load_ref(),
ton_begin_parse(),
ton_load_uint(256, 'collateral_asset_id'),
ton_load_uint(64, 'collateral_reward'),
ton_load_int(64, 'new_user_collateral_principal'),
ton_load_int(64, 'new_collateral_total_supply'),
ton_load_int(64, 'new_collateral_total_borrow'),
ton_load_uint(64, 'collateral_s_rate'),
ton_load_uint(64, 'collateral_b_rate')
]) }} as result, * FROM source_data WHERE is_pre_v9 = false
)
select block_date, tx_hash, trace_id, tx_now, tx_lt, pool_address, pool_name,
select block_date, tx_hash, trace_id, tx_now, tx_lt, pool_address, pool_name, protocol_version,
result.owner_address, result.sender_address, null AS liquidator_address, result.transferred_asset_id,
result.transferred_amount, result.new_user_loan_principal, result.loan_new_total_supply,
result.loan_new_total_borrow, CAST(result.loan_s_rate AS bigint) AS loan_s_rate, CAST(result.loan_b_rate AS bigint) AS loan_b_rate,-- should be less than 2^64
result.collateral_asset_id, result.collateral_reward, result.new_user_collateral_principal,
result.new_collateral_total_supply, result.new_collateral_total_borrow,
CAST(result.collateral_s_rate AS bigint) AS collateral_s_rate, CAST(result.collateral_b_rate AS bigint) AS collateral_b_rate -- should be less than 2^64
CAST(result.collateral_s_rate AS bigint) AS collateral_s_rate, CAST(result.collateral_b_rate AS bigint) AS collateral_b_rate, -- should be less than 2^64
CAST(NULL AS int) AS subaccount_id
FROM parse_output_prev4

UNION ALL

select block_date, tx_hash, trace_id, tx_now, tx_lt, pool_address, pool_name,
select block_date, tx_hash, trace_id, tx_now, tx_lt, pool_address, pool_name, protocol_version,
result.owner_address, result.sender_address, result.liquidator_address, result.transferred_asset_id,
result.transferred_amount, result.new_user_loan_principal, result.loan_new_total_supply,
result.loan_new_total_borrow, CAST(result.loan_s_rate AS bigint) AS loan_s_rate, CAST(result.loan_b_rate AS bigint) AS loan_b_rate,-- should be less than 2^64
result.collateral_asset_id, result.collateral_reward, result.new_user_collateral_principal,
result.new_collateral_total_supply, result.new_collateral_total_borrow,
CAST(result.collateral_s_rate AS bigint) AS collateral_s_rate, CAST(result.collateral_b_rate AS bigint) AS collateral_b_rate, -- should be less than 2^64
CAST(NULL AS int) AS subaccount_id
FROM parse_output_postv4

UNION ALL

select block_date, tx_hash, trace_id, tx_now, tx_lt, pool_address, pool_name, protocol_version,
result.owner_address, result.sender_address, result.liquidator_address, result.transferred_asset_id,
result.transferred_amount, result.new_user_loan_principal, result.loan_new_total_supply,
result.loan_new_total_borrow, CAST(result.loan_s_rate AS bigint) AS loan_s_rate, CAST(result.loan_b_rate AS bigint) AS loan_b_rate,-- should be less than 2^64
result.collateral_asset_id, result.collateral_reward, result.new_user_collateral_principal,
result.new_collateral_total_supply, result.new_collateral_total_borrow,
CAST(result.collateral_s_rate AS bigint) AS collateral_s_rate, CAST(result.collateral_b_rate AS bigint) AS collateral_b_rate -- should be less than 2^64
FROM parse_output_postv4
CAST(result.collateral_s_rate AS bigint) AS collateral_s_rate, CAST(result.collateral_b_rate AS bigint) AS collateral_b_rate, -- should be less than 2^64
CAST(result.subaccount_id AS int) AS subaccount_id
FROM parse_output_postv9
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ models:
sector: lending
contributors: pshuvalov
config:
tags: ['ton', 'evaa', 'lending']
tags: ["ton", "evaa", "lending"]
description: >
EVAA protocol withdraw events
data_tests:
Expand All @@ -30,12 +30,16 @@ models:
description: "EVAA pool address"
- name: pool_name
description: "EVAA pool name"
- name: protocol_version
description: "Protocol version (v3, v4, v9)"
- name: owner_address
description: "owner address"
- name: sender_address
description: "user smart contract address"
- name: recipient_address
description: "recipient address (only for after v4 protcool upgrade, otherwise null)"
description: "recipient address (only for after v4 protocol upgrade, otherwise null)"
- name: subaccount_id
description: "subaccount id (only for v9 protocol upgrade, otherwise null)"
- name: asset_id
description: "asset id"
- name: withdraw_amount_current
Expand All @@ -56,7 +60,7 @@ models:
sector: lending
contributors: pshuvalov
config:
tags: ['ton', 'evaa', 'lending']
tags: ["ton", "evaa", "lending"]
description: >
EVAA protocol supply events
data_tests:
Expand All @@ -79,6 +83,10 @@ models:
description: "EVAA pool address"
- name: pool_name
description: "EVAA pool name"
- name: protocol_version
description: "Protocol version (v3, v4, v9)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • subaccount_id

- name: subaccount_id
description: "subaccount id (only for v9 protocol upgrade, otherwise null)"
- name: owner_address
description: "owner address"
- name: sender_address
Expand All @@ -103,7 +111,7 @@ models:
sector: lending
contributors: pshuvalov
config:
tags: ['ton', 'evaa', 'lending']
tags: ["ton", "evaa", "lending"]
description: >
EVAA protocol liquidate events
data_tests:
Expand All @@ -126,6 +134,10 @@ models:
description: "EVAA pool address"
- name: pool_name
description: "EVAA pool name"
- name: protocol_version
description: "Protocol version (v3, v4, v9)"
- name: subaccount_id
description: "subaccount id (only for v9 protocol upgrade, otherwise null)"
- name: owner_address
description: "owner address"
- name: sender_address
Expand Down Expand Up @@ -166,7 +178,7 @@ models:
sector: lending
contributors: pshuvalov
config:
tags: ['ton', 'evaa', 'lending']
tags: ["ton", "evaa", "lending"]
description: >
EVAA protocol assets mapping
data_tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,22 @@


-- log::supply_success is sent by the router and contains all the data regarding the supply
-- https://github.com/evaafi/contracts/blob/d5a6bf889f8bbfa8bcc82671c17e65a3b2b360cd/contracts/core/master-supply.fc#L239-L254
-- https://github.com/evaafi/contracts/blob/d5a6bf889f8bbfa8bcc82671c17e65a3b2b360cd/contracts/core/master-supply.fc#L239-L254 (V4 parsing)
-- https://github.com/evaafi/contracts/blob/d9138cb24f03b53522774351aceb38c51a047eee/contracts/core/master-supply.fc#L316-L331 (v9 parsing)

WITH evaa_ton_pools AS (
{{ evaa_ton_pools() }}
),
parsed_boc AS (
SELECT M.block_date, M.tx_hash, M.trace_id, M.tx_now, M.tx_lt, pool_address, pool_name, body_boc
SELECT M.block_date, M.tx_hash, M.trace_id, M.tx_now, M.tx_lt, pool_address, pool_name,
tx_lt <= v4_upgrate_lt AS is_pre_v4,
tx_lt <= v9_upgrate_lt AS is_pre_v9,
CASE
WHEN tx_lt <= v4_upgrate_lt THEN 'v3'
WHEN v4_upgrate_lt < tx_lt AND tx_lt <= v9_upgrate_lt THEN 'v4'
ELSE 'v9'
END AS protocol_version,
body_boc
FROM {{ source('ton', 'messages') }} M
JOIN evaa_ton_pools ON M.source = pool_address
WHERE M.direction = 'out' AND M.destination IS NULL -- ext out message
Expand All @@ -47,10 +56,47 @@ select {{ ton_from_boc('body_boc', [
ton_load_uint(64, 's_rate'),
ton_load_uint(64, 'b_rate')
]) }} as result, * from parsed_boc
WHERE is_pre_v4 = true
), parse_output_postv4 as (
select {{ ton_from_boc('body_boc', [
ton_begin_parse(),
ton_load_uint(8, 'opcode'),
ton_load_address('owner_address'),
ton_load_address('sender_address'),
ton_load_uint(32, '_current_time'),
ton_load_int(16, 'subaccount_id'),
ton_load_ref(),
ton_begin_parse(),
ton_load_uint(256, 'asset_id'),
ton_load_uint(64, 'amount_supplied'),
ton_load_int(64, 'user_new_principal'),
ton_load_int(64, 'new_total_supply'),
ton_load_int(64, 'new_total_borrow'),
ton_load_uint(64, 's_rate'),
ton_load_uint(64, 'b_rate')
]) }} as result, * from parsed_boc
WHERE is_pre_v4 = false
), combined_results as (
select block_date, tx_hash, trace_id, tx_now, tx_lt, pool_address, pool_name, protocol_version,
result.owner_address, result.sender_address, result.asset_id,
result.amount_supplied, result.user_new_principal, result.new_total_supply,
result.new_total_borrow,
CAST(result.s_rate AS bigint) AS s_rate, CAST(result.b_rate AS bigint) AS b_rate, -- should be less than 2^64
CAST(NULL AS int) AS subaccount_id
from parse_output

UNION ALL

select block_date, tx_hash, trace_id, tx_now, tx_lt, pool_address, pool_name, protocol_version,
result.owner_address, result.sender_address, result.asset_id,
result.amount_supplied, result.user_new_principal, result.new_total_supply,
result.new_total_borrow,
CAST(result.s_rate AS bigint) AS s_rate, CAST(result.b_rate AS bigint) AS b_rate, -- should be less than 2^64
CAST(result.subaccount_id AS int) AS subaccount_id
from parse_output_postv4
)
select block_date, tx_hash, trace_id, tx_now, tx_lt, pool_address, pool_name,
result.owner_address, result.sender_address, result.asset_id,
result.amount_supplied, result.user_new_principal, result.new_total_supply,
result.new_total_borrow,
CAST(result.s_rate AS bigint) AS s_rate, CAST(result.b_rate AS bigint) AS b_rate -- should be less than 2^64
from parse_output
select block_date, tx_hash, trace_id, tx_now, tx_lt, pool_address, pool_name, protocol_version,
owner_address, sender_address, asset_id,
amount_supplied, user_new_principal, new_total_supply,
new_total_borrow, s_rate, b_rate, subaccount_id
from combined_results
Loading
Loading