Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nexus Mutual - products & covers #6142

Merged
merged 13 commits into from
Jun 25, 2024
329 changes: 329 additions & 0 deletions models/nexusmutual/ethereum/covers/_schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,329 @@
version: 2

models:
- name: nexusmutual_ethereum_product_types_v2
meta:
blockchain: ethereum
project: nexusmutual
contributors: tomfutago
config:
tags: ["ethereum", "nexusmutual", "covers"]
description: "Nexus Mutual Product Types v2"
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- product_type_id
columns:
- &block_time
name: block_time
description: "UTC event block time"
tests:
- not_null
- &block_number
name: block_number
description: "Block number"
tests:
- not_null
- &product_type_id
name: product_type_id
description: "product type id"
tests:
- not_null
- &product_type_name
name: product_type_name
description: "product type name"
tests:
- not_null
- name: claim_method
description: "claim method"
- name: grace_period
description: "grace period"
- name: product_type_ipfs_metadata
description: "product type ipfs metadata"
- name: cover_wording_url
description: "cover wording url"
- &evt_index
name: evt_index
description: "event index"
- &tx_hash
name: tx_hash
description: "unique transaction hash value"
tests:
- not_null

- name: nexusmutual_ethereum_products_v2
meta:
blockchain: ethereum
project: nexusmutual
contributors: tomfutago
config:
tags: ["ethereum", "nexusmutual", "covers"]
description: "Nexus Mutual Products v2"
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- product_id
columns:
- *block_time
- *block_number
- *product_type_id
- &product_id
name: product_id
description: "product id"
tests:
- not_null
- &product_name
name: product_name
description: "product name"
tests:
- not_null
- name: cover_assets
description: "cover assets: ETH, DAI, USDC"
- name: is_deprecated
description: "is deprecated flag"
- name: initial_price_ratio
description: "initial price ratio"
- name: use_fixed_price
description: "use fixed price?"
- name: capacity_reduction_ratio
description: "capacity reduction ratio"
- name: allowed_pools
description: "allowed pools (array)"
- name: yield_token_address
description: "yield token address"
- name: product_ipfs_metadata
description: "product ipfs metadata"
- *evt_index
- *tx_hash

- name: nexusmutual_ethereum_products_v1
meta:
blockchain: ethereum
project: nexusmutual
contributors: guyhow, tomfutago
config:
tags: ["ethereum", "nexusmutual", "covers"]
description: "Nexus Mutual Products v1"
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- product_contract_address
columns:
- &product_contract_address
name: product_contract_address
description: "product contract address"
tests:
- unique
- *product_name
- &product_type
name: product_type
description: "product type"
- &date_added
name: date_added
description: "date added"

- name: nexusmutual_ethereum_covers_v1
meta:
blockchain: ethereum
project: nexusmutual
contributors: tomfutago
config:
tags: ["ethereum", "nexusmutual", "covers"]
description: "Nexus Mutual Covers v1"
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- cover_id
columns:
- *block_time
- &block_date
name: block_date
description: "block date"
- *block_number
- &cover_id
name: block_date
description: "cover id"
tests:
- not_null
- &cover_start_time
name: cover_start_time
description: "cover start time"
tests:
- not_null
- &cover_end_time
name: cover_end_time
description: "cover end time"
tests:
- not_null
- &cover_start_date
name: cover_start_date
description: "cover start date"
- &cover_end_date
name: cover_end_date
description: "cover end date"
- &product_contract
name: product_contract
description: "product contract"
- name: syndicate
description: "syndicate"
- *product_name
- *product_type
- &cover_asset
name: cover_asset
description: "cover asset"
- &sum_assured
name: sum_assured
description: "total cover amount"
- &premium_asset
name: premium_asset
description: "premium asset"
- &premium
name: premium
description: "premium in cover asset"
- &premium_nxm
name: premium_nxm
description: "premium in NXM"
- &cover_owner
name: cover_owner
description: "cover owner"
- *evt_index
- *tx_hash

- name: nexusmutual_ethereum_covers_v2
meta:
blockchain: ethereum
project: nexusmutual
contributors: tomfutago
config:
tags: ["ethereum", "nexusmutual", "covers"]
description: "Nexus Mutual Covers v2"
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- cover_id
- staking_pool
columns:
- *block_time
- *block_date
- *block_number
- *cover_id
- *cover_start_time
- *cover_end_time
- *cover_start_date
- *cover_end_date
- &staking_pool
name: staking_pool
description: "staking pool id"
- *product_type
- *product_name
- *cover_asset
- *sum_assured
- &partial_cover_amount
name: partial_cover_amount
description: "partial cover amount"
- *premium_asset
- *premium
- *premium_nxm
- &premium_incl_commission
name: premium_incl_commission
description: "premium incl commission"
- *cover_owner
- &is_migrated
name: is_migrated
description: "is migrated flag"
- *tx_hash


# to be deprecated:
- name: nexusmutual_ethereum_product_information
meta:
blockchain: ethereum
project: nexusmutual
contributors: [guyhow]
description: >
nexusmutual product information for v1
columns:
- *product_contract_address
- *product_name
- *product_type
- *date_added
- name: syndicate

- name: nexusmutual_ethereum_quotation_trades
meta:
blockchain: ethereum
project: nexusmutual
contributors: [zxf, jonah]
config:
tags: ["ethereum","nexusmutual","quotation_trades"]
description: >
nexusmutual quotation trades on Ethereum
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- block_date
- evt_tx_hash
- evt_index
- cid
- check_seed:
seed_file: ref("nexusmutual_ethereum_trades_seed")
match_columns:
- evt_tx_hash
check_columns:
- premium
- premium_nxm
- sum_assured
columns:
- &cid
name: cid
- &contract_address
name: contract_address
- &symbol
name: symbol
- *evt_index
- &evt_tx_hash
name: evt_tx_hash
- &curr
name: curr
- *premium
- &pre_amount
name: pre_amount
- *premium_nxm
- &pre_nxm_amount
name: pre_nxm_amount
- &sc_add
name: sc_add
- *sum_assured
- &block_hash
name: block_hash
- &nonce
name: nonce
- &gas_limit
name: gas_limit
- &gas_price
name: gas_price
- &gas_used
name: gas_used
- &max_fee_per_gas
name: max_fee_per_gas
- &max_priority_fee_per_gas
name: max_priority_fee_per_gas
- &priority_fee_per_gas
name: priority_fee_per_gas
- &success
name: success
- &tx_type
name: tx_type
- &tx_value
name: tx_value
- &evt_block_number
name: evt_block_number
- &evt_block_time
name: evt_block_time
- &evt_expiry
name: evt_expiry
- &evt_expiry_date
name: evt_expiry_date
- *block_date
- &token_address
name: token_address
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{
config(
schema = 'nexusmutual_ethereum',
alias = 'covers_v1',
materialized = 'view',
post_hook = '{{ expose_spells(\'["ethereum"]\',
"project",
"nexusmutual",
\'["tomfutago"]\') }}'
)
}}

with

cover_details as (
select
cde.evt_block_time as block_time,
cde.evt_block_number as block_number,
cde.cid as cover_id,
cde.evt_block_time as cover_start_time,
from_unixtime(cde.expiry) as cover_end_time,
cde.scAdd as product_contract,
cast(cde.sumAssured as double) as sum_assured,
case
when ct.call_success or cm.payWithNXM then 'NXM'
when cde.curr = 0x45544800 then 'ETH'
when cde.curr = 0x44414900 then 'DAI'
end as premium_asset,
cde.premium / 1e18 as premium,
case
when cde.curr = 0x45544800 then 'ETH'
when cde.curr = 0x44414900 then 'DAI'
end as cover_asset,
cde.premiumNXM / 1e18 as premium_nxm,
ac._userAddress as cover_owner,
cde.evt_index,
cde.evt_tx_hash as tx_hash
from {{ source('nexusmutual_ethereum', 'QuotationData_evt_CoverDetailsEvent') }} cde
left join {{ source('nexusmutual_ethereum', 'Quotation_call_buyCoverWithMetadata') }} cm
on cde.evt_tx_hash = cm.call_tx_hash and cde.evt_block_number = cm.call_block_number and cm.call_success
left join {{ source('nexusmutual_ethereum', 'Quotation_call_makeCoverUsingNXMTokens') }} ct
on cde.evt_tx_hash = ct.call_tx_hash and cde.evt_block_number = ct.call_block_number and ct.call_success
left join {{ source('nexusmutual_ethereum', 'QuotationData_call_addCover') }} ac
on cde.evt_tx_hash = ac.call_tx_hash and cde.evt_block_number = ac.call_block_number and ac.call_success
)

select
cd.block_time,
date_trunc('day', cd.block_time) as block_date,
cd.block_number,
cd.cover_id,
cd.cover_start_time,
cd.cover_end_time,
date_trunc('day', cd.cover_start_time) as cover_start_date,
date_trunc('day', cd.cover_end_time) as cover_end_date,
cd.product_contract,
'v1' as syndicate,
coalesce(p.product_name, 'unknown') as product_name,
coalesce(p.product_type, 'unknown') as product_type,
cd.cover_asset,
cd.sum_assured,
cd.premium_asset,
cd.premium,
cd.premium_nxm,
cd.cover_owner,
cd.evt_index,
cd.tx_hash
from cover_details cd
left join {{ ref('nexusmutual_ethereum_products_v1') }} p on cd.product_contract = p.product_contract_address
Loading
Loading