From c676192c505486bbd6866144fb0435499d1f55b7 Mon Sep 17 00:00:00 2001 From: Sebastian Melendez Date: Mon, 8 Apr 2024 19:25:58 -0400 Subject: [PATCH] adding stablecoin contracts as well as celo transfer events --- macros/decode/decode_events.sql | 5 +- macros/decode/transfer_events.sql | 21 + .../contracts/dim_contract_abis.sql | 630 +++++++++++++++++- .../dimensions/events/dim_events_silver.sql | 22 +- .../fact_celo_stablecoin_contracts.sql | 9 + .../celo/fact_celo_token_transfers.sql | 3 + 6 files changed, 681 insertions(+), 9 deletions(-) create mode 100644 macros/decode/transfer_events.sql create mode 100644 models/metrics/stablecoins/contracts/fact_celo_stablecoin_contracts.sql create mode 100644 models/staging/celo/fact_celo_token_transfers.sql diff --git a/macros/decode/decode_events.sql b/macros/decode/decode_events.sql index 71bdcadb..0b26c14d 100644 --- a/macros/decode/decode_events.sql +++ b/macros/decode/decode_events.sql @@ -7,11 +7,12 @@ contract_address, origin_from_address, origin_to_address, - status, + status as tx_status, + t1.topic_zero, t2.event_name, {{ target.schema }}.decode_evm_event_log( event_data, t2.event_info - ) as decoded_event + ) as decoded_log from {{ ref("fact_" ~ chain ~ "_events") }} t1 inner join {{ ref("dim_events_silver") }} t2 on t1.topic_zero = t2.topic_zero {% if is_incremental() %} diff --git a/macros/decode/transfer_events.sql b/macros/decode/transfer_events.sql new file mode 100644 index 00000000..c5606050 --- /dev/null +++ b/macros/decode/transfer_events.sql @@ -0,0 +1,21 @@ +{% macro transfer_events(chain) %} + select + block_timestamp, + block_number, + transaction_hash, + event_index, + origin_from_address, + origin_to_address, + contract_address, + decoded_log:"from"::string as "from", + decoded_log:"to"::string as "to", + decoded_log:"value"::string as amount, + tx_status + from {{ ref("fact_" ~ chain ~ "_decoded_events") }} + where topic_zero = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' + {% if is_incremental() %} + and + block_timestamp + >= (select dateadd('day', -3, max(block_timestamp)) from {{ this }}) + {% endif %} +{% endmacro %} diff --git a/models/dimensions/contracts/dim_contract_abis.sql b/models/dimensions/contracts/dim_contract_abis.sql index 9b44b2b6..1a751146 100644 --- a/models/dimensions/contracts/dim_contract_abis.sql +++ b/models/dimensions/contracts/dim_contract_abis.sql @@ -1,6 +1,6 @@ {{ config(materialized="table") }} -select null as contract_address, 'ERC20_Standard' as abi_type, parse_json('[ +select null as contract_address, null as chain, 'ERC20_Standard' as abi_type, parse_json('[ { "constant": true, "inputs": [], @@ -223,3 +223,631 @@ select null as contract_address, 'ERC20_Standard' as abi_type, parse_json('[ } ] ') as abi + +union all +select '0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e' as contract_address, 'celo' as chain, 'Contract' as abi_type, parse_json('[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "authorizer", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "nonce", + "type": "bytes32" + } + ], + "name": "AuthorizationCanceled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "authorizer", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "nonce", + "type": "bytes32" + } + ], + "name": "AuthorizationUsed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "_user", + "type": "address" + } + ], + "name": "BlockPlaced", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "_user", + "type": "address" + } + ], + "name": "BlockReleased", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "_blockedUser", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_balance", + "type": "uint256" + } + ], + "name": "DestroyedBlockedFunds", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "feeCurrencyWrapper", + "type": "address" + } + ], + "name": "LogSetFeeCurrencyWrapper", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "_destination", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "Mint", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "_amount", + "type": "uint256" + } + ], + "name": "Redeem", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [], + "name": "CANCEL_AUTHORIZATION_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "RECEIVE_WITH_AUTHORIZATION_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "TRANSFER_WITH_AUTHORIZATION_TYPEHASH", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_user", "type": "address" } + ], + "name": "addToBlockedList", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" } + ], + "name": "allowance", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "approve", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "authorizer", "type": "address" }, + { "internalType": "bytes32", "name": "nonce", "type": "bytes32" } + ], + "name": "authorizationState", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "account", "type": "address" } + ], + "name": "balanceOf", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "authorizer", "type": "address" }, + { "internalType": "bytes32", "name": "nonce", "type": "bytes32" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "cancelAuthorization", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "authorizer", "type": "address" }, + { "internalType": "bytes32", "name": "nonce", "type": "bytes32" }, + { "internalType": "bytes", "name": "signature", "type": "bytes" } + ], + "name": "cancelAuthorization", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "refundRecipient", + "type": "address" + }, + { "internalType": "address", "name": "tipRecipient", "type": "address" }, + { "internalType": "address", "name": "", "type": "address" }, + { + "internalType": "address", + "name": "baseFeeRecipient", + "type": "address" + }, + { "internalType": "uint256", "name": "refundAmount", "type": "uint256" }, + { "internalType": "uint256", "name": "tipAmount", "type": "uint256" }, + { "internalType": "uint256", "name": "", "type": "uint256" }, + { "internalType": "uint256", "name": "baseFeeAmount", "type": "uint256" } + ], + "name": "creditGasFees", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" } + ], + "name": "debitGasFees", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_blockedUser", "type": "address" } + ], + "name": "destroyBlockedFunds", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "feeCurrencyWrapper", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "addedValue", "type": "uint256" } + ], + "name": "increaseAllowance", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "string", "name": "_name", "type": "string" }, + { "internalType": "string", "name": "_symbol", "type": "string" }, + { "internalType": "uint8", "name": "_decimals", "type": "uint8" } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "isBlocked", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [{ "internalType": "address", "name": "", "type": "address" }], + "name": "isTrusted", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_destination", "type": "address" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "mint", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "_recipients", + "type": "address[]" + }, + { "internalType": "uint256[]", "name": "_values", "type": "uint256[]" } + ], + "name": "multiTransfer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner", "type": "address" } + ], + "name": "nonces", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner_", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "bytes", "name": "signature", "type": "bytes" } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "owner_", "type": "address" }, + { "internalType": "address", "name": "spender", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "deadline", "type": "uint256" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "validAfter", "type": "uint256" }, + { "internalType": "uint256", "name": "validBefore", "type": "uint256" }, + { "internalType": "bytes32", "name": "nonce", "type": "bytes32" }, + { "internalType": "bytes", "name": "signature", "type": "bytes" } + ], + "name": "receiveWithAuthorization", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "validAfter", "type": "uint256" }, + { "internalType": "uint256", "name": "validBefore", "type": "uint256" }, + { "internalType": "bytes32", "name": "nonce", "type": "bytes32" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "receiveWithAuthorization", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "redeem", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_user", "type": "address" } + ], + "name": "removeFromBlockedList", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_feeCurrencyWrapper", + "type": "address" + } + ], + "name": "setFeeCurrencyWrapper", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [{ "internalType": "string", "name": "", "type": "string" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "recipient", "type": "address" }, + { "internalType": "uint256", "name": "amount", "type": "uint256" } + ], + "name": "transfer", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "_sender", "type": "address" }, + { "internalType": "address", "name": "_recipient", "type": "address" }, + { "internalType": "uint256", "name": "_amount", "type": "uint256" } + ], + "name": "transferFrom", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "newOwner", "type": "address" } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "validAfter", "type": "uint256" }, + { "internalType": "uint256", "name": "validBefore", "type": "uint256" }, + { "internalType": "bytes32", "name": "nonce", "type": "bytes32" }, + { "internalType": "bytes", "name": "signature", "type": "bytes" } + ], + "name": "transferWithAuthorization", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "from", "type": "address" }, + { "internalType": "address", "name": "to", "type": "address" }, + { "internalType": "uint256", "name": "value", "type": "uint256" }, + { "internalType": "uint256", "name": "validAfter", "type": "uint256" }, + { "internalType": "uint256", "name": "validBefore", "type": "uint256" }, + { "internalType": "bytes32", "name": "nonce", "type": "bytes32" }, + { "internalType": "uint8", "name": "v", "type": "uint8" }, + { "internalType": "bytes32", "name": "r", "type": "bytes32" }, + { "internalType": "bytes32", "name": "s", "type": "bytes32" } + ], + "name": "transferWithAuthorization", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +]') as abi \ No newline at end of file diff --git a/models/dimensions/events/dim_events_silver.sql b/models/dimensions/events/dim_events_silver.sql index a6ea4e7d..50d7e5e9 100644 --- a/models/dimensions/events/dim_events_silver.sql +++ b/models/dimensions/events/dim_events_silver.sql @@ -1,7 +1,17 @@ {{ config(materialized="table", unique_key="topic_zero", sort="topic_zero") }} -select - value:"name"::string as event_name, - value as event_info, - {{ target.schema }}.event_info_to_keccak_event_signature(event_info) as topic_zero -from {{ ref("dim_contract_abis") }}, lateral flatten(input => abi) as f -where value:"type" = 'event' +with +event_signatures as ( + select + value:"name"::string as event_name, + value as event_info, + {{ target.schema }}.event_info_to_keccak_event_signature(value) as topic_zero, + row_number() over (partition by topic_zero order by event_name) as event_id + from {{ ref("dim_contract_abis") }}, lateral flatten(input => abi) as f + where value:"type" = 'event' +) +select + event_name, + event_info, + topic_zero +from event_signatures +where event_id = 1 \ No newline at end of file diff --git a/models/metrics/stablecoins/contracts/fact_celo_stablecoin_contracts.sql b/models/metrics/stablecoins/contracts/fact_celo_stablecoin_contracts.sql new file mode 100644 index 00000000..681194d4 --- /dev/null +++ b/models/metrics/stablecoins/contracts/fact_celo_stablecoin_contracts.sql @@ -0,0 +1,9 @@ +{{ config(materialized="table") }} +select symbol, contract_address, num_decimals, coingecko_id, initial_supply +from + ( + values + ('USDC', '0xcebA9300f2b948710d2653dD7B07f33A8B32118C', 6, 'usd-coin', 0), + ('USDT', '0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e', 6, 'tether', 0), + ('cUSD', '0x765DE816845861e75A25fCA122bb6898B8B1282a', 18, 'celo-dollar', 0), + ) as results(symbol, contract_address, num_decimals, coingecko_id, initial_supply) diff --git a/models/staging/celo/fact_celo_token_transfers.sql b/models/staging/celo/fact_celo_token_transfers.sql new file mode 100644 index 00000000..a985cb9c --- /dev/null +++ b/models/staging/celo/fact_celo_token_transfers.sql @@ -0,0 +1,3 @@ +{{ config(materialized="incremental", unique_key=["transaction_hash", "event_index"]) }} + +{{ transfer_events("celo") }} \ No newline at end of file