Query editor
-- ===========================================================================-- FSA XRPL-owner cohort segmentation: who did FSA bring to DeFi?-- User = xrplOwner of MasterAccountController PersonalAccountCreated (1 PA per owner).-- first FSA use = first successful XRPL payment to an FSA anchor (matview result_smart_account_instructions).-- account created ~ ledger = xrpl Sequence of that payment (post-DeletableAccounts (Apr-2020) accounts start-- with Sequence = creation ledger; off by #txs sent before, i.e. hours). seq < 50M => pre-Apr-2020.-- XRPL history scanned 2024-01-01 .. now only (cost): "dormant" = no account-SIGNED tx in the 180 d before-- first FSA use; "XRPL DeFi" = OfferCreate / AMM* / TrustSet / NFToken* signed 2024-01-01 .. first FSA use.-- prior FAssets = before first FSA use the owner either paid an FAssets agent underlying address on XRPL-- (plain mint) or received an FXRP redemption from a non-PA redeemer.-- mints = MAC CollateralReserved -> MintingExecuted (minted + pool fee) + DirectMintingExecutedToSmartAccount-- (minted + minting fee). deposits = FXRP transferred PA -> ClearStar / Monarq / Firelight vault.-- Output: long format (dim, bucket, sub, users, minted, deposited, ...).-- ===========================================================================with pa as (select xrplOwner as owner, personalAccount as pafrom fassets_flare.masteraccountcontroller_evt_personalaccountcreated),first_fsa as (select xrpl_source as owner,min(ledger_close_time) as t0,min_by(xrpl_sequence, ledger_index * 10000 + transaction_index) as seq,min_by(xrpl_delivered_drops, ledger_index * 10000 + transaction_index) / 1e6 as first_xrpfrom dune.flare.result_smart_account_instructionswhere xrpl_success and xrpl_source in (select owner from pa)group by 1),day_ledger as (select d, lo, coalesce(lead(lo) over (order by d), 9999999999) as hifrom (select ledger_close_date as d, min(ledger_index) as lofrom xrpl.ledger where ledger_close_date >= date '2020-01-01' group by 1)),agent_addr as (select distinct paymentAddress as a from fassets_flare.assetmanager_evt_collateralreserved),-- single scan of XRPL history; each tx fans out to (owner, role) for signer and destinationxs as (select u.who, u.role, x.destination_address, x.ledger_close_time, x.transaction_type, x.delivered_amountfrom xrpl.transactions_base xcross join unnest(array[x.account_address, x.destination_address], array['out', 'in']) as u(who, role)where x.ledger_close_date >= date '2024-01-01'and x.transaction_result = 'tesSUCCESS'and (x.account_address in (select owner from pa) or x.destination_address in (select owner from pa))),hist as (select f.owner,max(case when x.role = 'out' then x.ledger_close_time end) as last_out,count_if(x.role = 'out' and x.transaction_type in ('OfferCreate','AMMDeposit','AMMWithdraw','AMMCreate','AMMVote','AMMBid','TrustSet','NFTokenMint','NFTokenCreateOffer','NFTokenAcceptOffer')) as defi_n,count_if(x.role = 'out' and x.transaction_type = 'Payment'and x.destination_address in (select a from agent_addr)) as agent_pay_n,sum(case when x.role = 'in' and x.transaction_type = 'Payment' and x.delivered_amount.currency = 'XRP'and x.ledger_close_time >= f.t0 - interval '30' daythen try_cast(x.delivered_amount.value as double) end) / 1e6 as xrp_in_30dfrom first_fsa fjoin xs x on x.who = f.owner and x.ledger_close_time < f.t0group by 1),prior_redeem as (select f.owner, count(*) as n