Skip to content

Instantly share code, notes, and snippets.

@mikekeke
Last active September 13, 2023 14:00
Show Gist options
  • Save mikekeke/c557b8e7c208badd6861d777887eeb3e to your computer and use it in GitHub Desktop.
Save mikekeke/c557b8e7c208badd6861d777887eeb3e to your computer and use it in GitHub Desktop.
radix
with token_res_id as (select id
from entities
where address = ?),
current_state as (select entity_id,
max(from_state_version) as state
from entity_resource_aggregated_vaults_history,
token_res_id
where resource_entity_id = token_res_id.id
and from_state_version <= ? -- 3293441 -- 3297103
group by entity_id)
select eravh.from_state_version,
eravh.entity_id,
eravh.resource_entity_id,
eravh.balance,
es.address
from entity_resource_aggregated_vaults_history eravh,
entities es,
current_state,
token_res_id
where eravh.entity_id = current_state.entity_id
and eravh.from_state_version = current_state.state
and eravh.resource_entity_id = token_res_id.id
and eravh.entity_id = es.id
order by from_state_version desc
limit 500
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment