Skip to content

Commit

Permalink
[readme] update flipside queries (#139)
Browse files Browse the repository at this point in the history
* [readme] update flipside queries

* [readme] fix epoch calculation
  • Loading branch information
ochaloup authored Nov 8, 2024
1 parent 0bebe5d commit 45334bc
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions programs/validator-bonds/ON_CHAIN_ANALYSIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ To check the historical data of the Validator Bonds program processing
we present here a analysis queries to [FlipSide Crypto](https://flipsidecrypto.xyz/)
that bring the insight of the on-chain data processing.

For details on available tables for Solana transactions table see
[core__fact_transactions view](https://flipsidecrypto.github.io/solana-models/#!/model/model.solana_models.core__fact_transactions).


## Query Validator Bonds Fund instructions

### Fund Bond
Expand Down Expand Up @@ -48,6 +52,7 @@ from
LATERAL FLATTEN(input => account_keys) accounts
WHERE 1=1
and stake_account = accounts.value:pubkey
ORDER BY block_timestamp ASC
```

### Fund Settlement
Expand All @@ -60,9 +65,20 @@ with
fund_ixs as (
select
tx_id,
-- fund_settlement ix was changed from epoch 679 and stake is at index 5 instead of 4 as before
-- https://github.com/marinade-finance/validator-bonds/blob/main/programs/validator-bonds/src/instructions/settlement/fund_settlement.rs - 5th account in ix, index 4
ixs.value:accounts[4] stake_account,
ixs.value:accounts[7] split_stake_account,
CASE
WHEN BLOCK_ID >= 293328000
THEN 5
ELSE 4
END AS stake_account_idx,
CASE
WHEN BLOCK_ID >= 293328000
THEN 8
ELSE 7
END AS split_stake_account_idx,
ixs.value:accounts[stake_account_idx] stake_account,
ixs.value:accounts[split_stake_account_idx] split_stake_account,
ixs.value:accounts[1] bond_account,
ixs.value:data ix_data,
account_keys,
Expand All @@ -73,29 +89,30 @@ with
from solana.core.fact_transactions,
LATERAL FLATTEN(input => instructions) ixs,
where 1=1
and BLOCK_TIMESTAMP > CURRENT_DATE - 7
-- and BLOCK_TIMESTAMP <= CURRENT_DATE - 7
and BLOCK_ID >= 298080000
and bond_account = '<<bond-account-pubkey>>'
and ixs.value:programId = 'vBoNdEvzMrSai7is21XgVYik65mqtaKXuSdMBJ1xkW4'
-- FundSettlement Anchor IX discriminator: '[179, 146, 113, 34, 30, 92, 26, 19]'
-- base58: X35Gz7Wk1Y6
and ixs.value:data = 'X35Gz7Wk1Y6'
and bond_account = '<<bond-account-pubkey>>'
)
select
floor(block_id / 432000) AS epoch,
block_timestamp,
block_id,
tx_id,
stake_account,
split_stake_account,
bond_account,
pre_balances[accounts.index] / 1e9 pre_balance,
post_balances[accounts.index] / 1e9 post_balance,
-- filtering by stake_account to accounts.value:pubkey and the .index is the stake account post balance
post_balances[accounts.index] / 1e9 funded_amount,
ix_data
from
fund_ixs,
LATERAL FLATTEN(input => account_keys) accounts
WHERE 1=1
and stake_account = accounts.value:pubkey
ORDER BY floor(block_id/432000) ASC
```


Expand All @@ -119,7 +136,25 @@ where 1=1
-- filter the list of inner instructions for only the emit log CPI events
-- this instruction is always emitted by the same Anchor CPI PDA defined for the bond program
and array_contains('j6cZKhHTFuWsiCgPT5wriQpZWqWWUSQqjDJ8S2YDvDL'::variant, ixs.value:accounts)
order by block_timestamp ASC;
ORDER BY block_timestamp ASC
```

```sql
-- FundSettlement
select block_timestamp, ixs.value:data
from solana.core.fact_events fe
inner JOIN solana.core.fact_transactions ft USING(block_timestamp, tx_id, succeeded)
,LATERAL FLATTEN(input => fe.inner_instruction:instructions) ixs,
where
fe.succeeded
and fe.program_id = 'vBoNdEvzMrSai7is21XgVYik65mqtaKXuSdMBJ1xkW4'
and array_contains('Program log: Instruction: FundSettlement'::variant, ft.log_messages)
-- vote account: CaraHZBReeNNYAJ326DFsvy41M2p1KWTEoBAwBL6bmWZ -> bond account: 3zVyxrxkR2a3oWoBku7CaAG7UW6JS65vqyoTdG1Djig9
and array_contains('3zVyxrxkR2a3oWoBku7CaAG7UW6JS65vqyoTdG1Djig9'::variant, fe.instruction:accounts)
-- from the list of inner instructions getting only those that contains the CPI event data
-- the CPI PDA call address is always the same for bond program
and array_contains('j6cZKhHTFuWsiCgPT5wriQpZWqWWUSQqjDJ8S2YDvDL'::variant, ixs.value:accounts)
ORDER BY block_timestamp ASC
```

The string found in the `ixs.value:data` column can be decrypted using the
Expand Down

0 comments on commit 45334bc

Please sign in to comment.