Skip to content

Conversation

@gregoriustanleyy
Copy link
Member

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @gregoriustanleyy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request establishes a robust data infrastructure for Aptos stablecoins. It introduces new dbt models to curate stablecoin metadata and track their mint and burn activities, providing a comprehensive view of stablecoin supply dynamics on the Aptos blockchain. The changes involve adding seed data, defining silver-level metadata and event tables, and a gold-level dimension table, all designed for incremental updates and efficient querying.

Highlights

  • New Stablecoin Data Models: Introduced a suite of new dbt models to comprehensively track Aptos stablecoins, including their metadata and mint/burn events.
  • Stablecoin Metadata Curation: Implemented a silver-level model (silver__stablecoins_metadata) that consolidates stablecoin information from cross-chain sources and a new manual seed file, enriching it with details like decimals, names, and verification status.
  • Mint and Burn Event Tracking: Developed a silver-level model (silver__stablecoins_mint_burn) to identify and quantify mint and burn transactions for verified Aptos stablecoins, carefully excluding bridge-related activities.
  • Dimension Table for Stablecoins: Created a gold-level dimension table (defi__dim_stablecoins) to provide a curated and optimized view of stablecoin metadata for downstream analysis.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces models for Aptos stablecoins, including metadata and mint/burn events. The overall logic is sound, but I have a few suggestions for improvement.

In silver__stablecoins_metadata.sql, I found a critical issue where the deduplication logic is only applied during incremental runs, which could lead to primary key violations on a full refresh. I've also suggested populating a timestamp column that is currently NULL.

In silver__stablecoins_mint_burn.sql, I've proposed a refactoring to reduce code duplication and improve maintainability.

Please see the detailed comments for suggestions.

Comment on lines +118 to +127
{% if is_incremental() %}
WHERE modified_timestamp >= (
SELECT MAX(modified_timestamp)
FROM {{ this }}
)
QUALIFY ROW_NUMBER() OVER (
PARTITION BY token_address
ORDER BY COALESCE(crosschain_modified_timestamp, metadata_modified_timestamp) DESC
) = 1
{% endif %}

Choose a reason for hiding this comment

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

critical

The QUALIFY clause is inside an {% if is_incremental() %} block, which means it only runs for incremental loads. On a full refresh, if a token_address exists in both crosschain_stablecoins and seed_stablecoins, this model will produce duplicate records for that token_address, causing a violation of the unique_key constraint. The QUALIFY clause should be applied unconditionally to ensure deduplication.

Additionally, the WHERE clause within the incremental block is redundant because incremental filtering is already handled within the crosschain_stablecoins and seed_stablecoins CTEs and can be removed for clarity.

QUALIFY ROW_NUMBER() OVER (
    PARTITION BY token_address
    ORDER BY COALESCE(crosschain_modified_timestamp, metadata_modified_timestamp) DESC
) = 1

c.peg_type,
c.peg_mechanism,
COALESCE(pr.is_verified, FALSE) AS is_verified,
NULL AS is_verified_modified_timestamp,

Choose a reason for hiding this comment

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

medium

The column is_verified_modified_timestamp is hardcoded to NULL. The downstream model defi__dim_stablecoins consumes this column. To provide more meaningful data, this should be populated with the timestamp when the verification status was last updated.

You can achieve this by modifying the join on price__ez_prices_hourly (lines 85-91) to also select the modified_timestamp and then use it here.

For example, you can change the subquery to:

...
    LEFT JOIN (
        SELECT
            token_address,
            is_verified,
            modified_timestamp AS is_verified_modified_timestamp,
            ROW_NUMBER() OVER (PARTITION BY token_address ORDER BY hour DESC) AS rn
        FROM {{ ref('price__ez_prices_hourly') }}
    ) pr ON c.token_address = pr.token_address AND pr.rn = 1
...

Then you can use pr.is_verified_modified_timestamp here.

        pr.is_verified_modified_timestamp,

Comment on lines +168 to +220
)

SELECT
block_number,
block_timestamp,
tx_hash,
version,
success,
event_index,
event_type,
event_resource,
metadata_address,
symbol,
name,
decimals,
sender_address,
receiver_address,
owner_address,
amount_unadj,
amount,
{{ dbt_utils.generate_surrogate_key(['tx_hash', 'event_index']) }} AS stablecoins_mint_burn_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id,
source_modified_timestamp
FROM mint_events

UNION ALL

SELECT
block_number,
block_timestamp,
tx_hash,
version,
success,
event_index,
event_type,
event_resource,
metadata_address,
symbol,
name,
decimals,
sender_address,
receiver_address,
owner_address,
amount_unadj,
amount,
{{ dbt_utils.generate_surrogate_key(['tx_hash', 'event_index']) }} AS stablecoins_mint_burn_id,
SYSDATE() AS inserted_timestamp,
SYSDATE() AS modified_timestamp,
'{{ invocation_id }}' AS _invocation_id,
source_modified_timestamp
FROM burn_events

Choose a reason for hiding this comment

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

medium

The final two SELECT statements are identical, differing only in the CTE they select from (mint_events and burn_events). This code duplication can be avoided by first using UNION ALL on the two event CTEs into a new final CTE and then selecting from that result. This improves maintainability, as any future changes to the final column list will only need to be made in one place.

),

final_events AS (
    SELECT * FROM mint_events
    UNION ALL
    SELECT * FROM burn_events
)

SELECT
    block_number,
    block_timestamp,
    tx_hash,
    version,
    success,
    event_index,
    event_type,
    event_resource,
    metadata_address,
    symbol,
    name,
    decimals,
    sender_address,
    receiver_address,
    owner_address,
    amount_unadj,
    amount,
    {{ dbt_utils.generate_surrogate_key(['tx_hash', 'event_index']) }} AS stablecoins_mint_burn_id,
    SYSDATE() AS inserted_timestamp,
    SYSDATE() AS modified_timestamp,
    '{{ invocation_id }}' AS _invocation_id,
    source_modified_timestamp
FROM final_events

GROUP BY tx_hash, metadata_address
),

mint_txs AS (
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont think this makes sense. Your definition of "mint" looks like it's really "transaction with more deposits than withdraws". Does this always hold true for the inbound bridge transactions?

Copy link
Member Author

Choose a reason for hiding this comment

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

this model will be used purely for native aptos mints/burns. the mint/burn or locked stablecoins in bridge platforms will be on a different model silver__stablecoin_supply_contracts

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.

3 participants