Skip to content

Add vaults protocol-fee endpoint - #166

Open
zahorodnyi wants to merge 2 commits into
devfrom
feat/protocol-fee-vaults-api
Open

zahorodnyi wants to merge 2 commits into
devfrom
feat/protocol-fee-vaults-api

Conversation

@zahorodnyi

Copy link
Copy Markdown
Collaborator

No description provided.

@zahorodnyi zahorodnyi self-assigned this Sep 9, 2026
@zahorodnyi
zahorodnyi requested a review from Hrom131 as a code owner September 9, 2026 15:29
Comment thread crates/indexer/src/api/vaults/db.rs Outdated
Comment on lines +38 to +61
let rows = sqlx::query_as!(
HarvestableProtocolFeeVaultRow,
r#"
SELECT
offer_vaults.offer_id,
offer_vaults.txid,
offer_vaults.vout,
offer_vaults.amount,
offer_vaults.created_at_height,
offer_vaults.updated_at_height,
offers.borrower_nft_asset_id,
offers.protocol_fee_keeper_asset_id
FROM offer_vaults
JOIN offers ON offers.id = offer_vaults.offer_id
WHERE offer_vaults.vault_type = 'protocol_fee'
AND offer_vaults.is_finalized = true
AND offer_vaults.spent_txid IS NULL
AND offers.principal_asset_id = $1
ORDER BY offer_vaults.amount DESC, offer_vaults.id DESC
"#,
principal_asset_id,
)
.fetch_all(db)
.await?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's add pagination logic here

.await?;

let count = rows.len() as u64;
let total_amount: i64 = rows.iter().map(|row| row.amount).sum();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

With pagination logic, total_amount needs to be calculated through a separate Query

)
)]
#[tracing::instrument(name = "Getting unspent protocol-fee vaults", skip(state, query))]
pub async fn list_protocol_fee_vaults(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We need to add this method to the IndexerClient

Comment on lines +12 to +23
pub struct ProtocolFeeVaultDto {
#[schema(example = "1")]
pub offer_id: String,
pub txid: String,
pub vout: u32,
#[schema(example = "1000")]
pub amount: String,
pub borrower_nft_asset: String,
pub protocol_fee_keeper_asset: String,
pub created_at_height: u64,
pub updated_at_height: u64,
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this information enough to build the AssetAuthVault contract and spend it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants