Skip to content

Commit

Permalink
[rust] add fields in ans table to improve expiration detection for su…
Browse files Browse the repository at this point in the history
…bdomains (#342)

* add fields in ans table to improve expiration date

* sync hasura metadata

* fix subdomain collection
  • Loading branch information
bowenyang007 authored Apr 10, 2024
1 parent 3e2a25e commit ca3f644
Show file tree
Hide file tree
Showing 7 changed files with 371 additions and 13 deletions.
271 changes: 265 additions & 6 deletions hasura-api/metadata-json/unified.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,269 @@
{
"resource_version": 307,
"resource_version": 313,
"metadata": {
"version": 3,
"sources": [
{
"name": "indexer-v2",
"kind": "postgres",
"tables": [
{
"table": {
"name": "current_nft_marketplace_auctions",
"schema": "nft_marketplace_v2"
},
"object_relationships": [
{
"name": "current_token_data",
"using": {
"manual_configuration": {
"column_mapping": {
"token_data_id": "token_data_id"
},
"insertion_order": null,
"remote_table": {
"name": "current_token_datas_v2",
"schema": "public"
}
}
}
}
],
"select_permissions": [
{
"role": "anonymous",
"permission": {
"columns": [
"buy_it_now_price",
"coin_type",
"collection_id",
"contract_address",
"current_bid_price",
"current_bidder",
"entry_function_id_str",
"expiration_time",
"fee_schedule_id",
"is_deleted",
"last_transaction_timestamp",
"last_transaction_version",
"listing_id",
"marketplace",
"seller",
"starting_bid_price",
"token_amount",
"token_data_id",
"token_standard"
],
"filter": {},
"limit": 100
}
}
]
},
{
"table": {
"name": "current_nft_marketplace_collection_offers",
"schema": "nft_marketplace_v2"
},
"object_relationships": [
{
"name": "current_collection_v2",
"using": {
"manual_configuration": {
"column_mapping": {
"collection_id": "collection_id"
},
"insertion_order": null,
"remote_table": {
"name": "current_collections_v2",
"schema": "public"
}
}
}
}
],
"select_permissions": [
{
"role": "anonymous",
"permission": {
"columns": [
"buyer",
"coin_type",
"collection_id",
"collection_offer_id",
"contract_address",
"entry_function_id_str",
"expiration_time",
"fee_schedule_id",
"is_deleted",
"item_price",
"last_transaction_timestamp",
"last_transaction_version",
"marketplace",
"remaining_token_amount",
"token_standard"
],
"filter": {},
"limit": 100
}
}
]
},
{
"table": {
"name": "current_nft_marketplace_listings",
"schema": "nft_marketplace_v2"
},
"object_relationships": [
{
"name": "current_token_data",
"using": {
"manual_configuration": {
"column_mapping": {
"token_data_id": "token_data_id"
},
"insertion_order": null,
"remote_table": {
"name": "current_token_datas_v2",
"schema": "public"
}
}
}
}
],
"select_permissions": [
{
"role": "anonymous",
"permission": {
"columns": [
"coin_type",
"collection_id",
"contract_address",
"entry_function_id_str",
"fee_schedule_id",
"is_deleted",
"last_transaction_timestamp",
"last_transaction_version",
"listing_id",
"marketplace",
"price",
"seller",
"token_amount",
"token_data_id",
"token_standard"
],
"filter": {},
"limit": 100,
"allow_aggregations": true
}
}
]
},
{
"table": {
"name": "current_nft_marketplace_token_offers",
"schema": "nft_marketplace_v2"
},
"object_relationships": [
{
"name": "current_token_data",
"using": {
"manual_configuration": {
"column_mapping": {
"token_data_id": "token_data_id"
},
"insertion_order": null,
"remote_table": {
"name": "current_token_datas_v2",
"schema": "public"
}
}
}
}
],
"select_permissions": [
{
"role": "anonymous",
"permission": {
"columns": [
"buyer",
"coin_type",
"collection_id",
"contract_address",
"entry_function_id_str",
"expiration_time",
"fee_schedule_id",
"is_deleted",
"last_transaction_timestamp",
"last_transaction_version",
"marketplace",
"offer_id",
"price",
"token_amount",
"token_data_id",
"token_standard"
],
"filter": {},
"limit": 100
}
}
]
},
{
"table": {
"name": "nft_marketplace_activities",
"schema": "nft_marketplace_v2"
},
"object_relationships": [
{
"name": "current_token_data",
"using": {
"manual_configuration": {
"column_mapping": {
"token_data_id": "token_data_id"
},
"insertion_order": null,
"remote_table": {
"name": "current_token_datas_v2",
"schema": "public"
}
}
}
}
],
"select_permissions": [
{
"role": "anonymous",
"permission": {
"columns": [
"buyer",
"coin_type",
"collection_id",
"collection_name",
"contract_address",
"creator_address",
"entry_function_id_str",
"event_index",
"event_type",
"fee_schedule_id",
"marketplace",
"offer_or_listing_id",
"price",
"property_version",
"seller",
"token_amount",
"token_data_id",
"token_name",
"token_standard",
"transaction_timestamp",
"transaction_version"
],
"filter": {},
"limit": 100
}
}
]
},
{
"table": {
"name": "parsed_asset_uris",
Expand Down Expand Up @@ -622,17 +879,19 @@
"role": "anonymous",
"permission": {
"columns": [
"last_transaction_version",
"domain",
"domain_expiration_timestamp",
"domain_with_suffix",
"expiration_timestamp",
"is_active",
"is_primary",
"domain",
"last_transaction_version",
"owner_address",
"registered_address",
"subdomain",
"subdomain_expiration_policy",
"token_name",
"token_standard",
"domain_with_suffix",
"expiration_timestamp"
"token_standard"
],
"filter": {},
"limit": 100,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- This file should undo anything in `up.sql`
DROP VIEW IF EXISTS current_aptos_names;
CREATE OR REPLACE VIEW current_aptos_names AS
SELECT cal.domain,
cal.subdomain,
cal.token_name,
cal.token_standard,
cal.registered_address,
cal.expiration_timestamp,
greatest(
cal.last_transaction_version,
capn.last_transaction_version
) as last_transaction_version,
coalesce(not capn.is_deleted, false) as is_primary,
concat(cal.domain, '.apt') as domain_with_suffix,
c.owner_address as owner_address,
cal.expiration_timestamp >= CURRENT_TIMESTAMP as is_active
FROM current_ans_lookup_v2 cal
LEFT JOIN current_ans_primary_name_v2 capn ON cal.token_name = capn.token_name
AND cal.token_standard = capn.token_standard
JOIN current_token_datas_v2 b ON cal.token_name = b.token_name
AND cal.token_standard = b.token_standard
JOIN current_token_ownerships_v2 c ON b.token_data_id = c.token_data_id
AND b.token_standard = c.token_standard
WHERE cal.is_deleted IS false
AND c.amount > 0
AND b.collection_id IN (
'0x1c380887f0cfcc8a82c0df44b24116985a92c58e686a0ea4a441c9f423a72b47',
-- Testnet ANS v1 domain collection
'0x56654f4bf4e528bfef33094d11a3475f0638e949b0976ec831ca0d66a2efb673',
-- Testnet ANS v2 domain collection
'0x3a2c902067bb4f0e37a2a89675d5cbceb07cf1a27479229b269fb1afffa62230',
-- Testnet ANS v2 subdomain collection
'0x09e63a48047b1c2bc51c0abc4b67ffcd9922e0adc99a6cc36532662172976a4b',
-- Mainnet ANS v1 domain collection
'0x63d26a4e3a8aeececf9b878e46bad78997fb38e50936efeabb2c4453f4d7f746',
-- Mainnet ANS v2 domain collection
'0x63d26a4e3a8aeececf9b878e46bad78997fb38e50936efeabb2c4453f4d7f746' -- Mainnet ANS v2 subdomain collection
);
ALTER TABLE current_ans_lookup_v2 DROP COLUMN IF EXISTS subdomain_expiration_policy;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
ALTER TABLE current_ans_lookup_v2
ADD COLUMN IF NOT EXISTS subdomain_expiration_policy BIGINT;
ALTER TABLE ans_lookup_v2
ADD COLUMN IF NOT EXISTS subdomain_expiration_policy BIGINT;
CREATE OR REPLACE VIEW current_aptos_names AS
SELECT cal.domain,
cal.subdomain,
cal.token_name,
cal.token_standard,
cal.registered_address,
cal.expiration_timestamp,
greatest(
cal.last_transaction_version,
capn.last_transaction_version
) as last_transaction_version,
coalesce(not capn.is_deleted, false) as is_primary,
concat(cal.domain, '.apt') as domain_with_suffix,
c.owner_address as owner_address,
cal.expiration_timestamp >= CURRENT_TIMESTAMP as is_active,
cal2.expiration_timestamp as domain_expiration_timestamp,
b.token_data_id as token_data_id,
cal.subdomain_expiration_policy as subdomain_expiration_policy
FROM current_ans_lookup_v2 cal
LEFT JOIN current_ans_primary_name_v2 capn ON cal.token_name = capn.token_name
AND cal.token_standard = capn.token_standard
JOIN current_token_datas_v2 b ON cal.token_name = b.token_name
AND cal.token_standard = b.token_standard
JOIN current_token_ownerships_v2 c ON b.token_data_id = c.token_data_id
AND b.token_standard = c.token_standard
LEFT JOIN current_ans_lookup_v2 cal2 ON cal.domain = cal2.domain
AND cal2.subdomain = ''
AND cal.token_standard = cal2.token_standard
WHERE cal.is_deleted IS false
AND c.amount > 0
AND b.collection_id IN (
'0x1c380887f0cfcc8a82c0df44b24116985a92c58e686a0ea4a441c9f423a72b47',
-- Testnet ANS v1 domain collection
'0x56654f4bf4e528bfef33094d11a3475f0638e949b0976ec831ca0d66a2efb673',
-- Testnet ANS v2 domain collection
'0x3a2c902067bb4f0e37a2a89675d5cbceb07cf1a27479229b269fb1afffa62230',
-- Testnet ANS v2 subdomain collection
'0x09e63a48047b1c2bc51c0abc4b67ffcd9922e0adc99a6cc36532662172976a4b',
-- Mainnet ANS v1 domain collection
'0x63d26a4e3a8aeececf9b878e46bad78997fb38e50936efeabb2c4453f4d7f746',
-- Mainnet ANS v2 domain collection
'0x30fbc956f0f38db2d314bd9c018d34be3e047a804a71e30a4e5d43d8b7c539eb' -- Mainnet ANS v2 subdomain collection
);
Loading

0 comments on commit ca3f644

Please sign in to comment.