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

Stop Token Spam on Asset Table #112

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nft_ingester/src/program_transformers/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ pub async fn handle_token_program_account<'a, 'b, 'c>(
.await?;
if let Some(asset) = asset_update {
// will only update owner if token account balance is non-zero
if ta.amount > 0 {
// since the asset is marked as single then the token account balance can only be 1. Greater implies a fungible token in which case no si
// TODO: this does not guarantee in case when wallet receives an amount of 1 for a token but its supply is more. is unlikely since mints often have a decimal
if ta.amount == 1 {
let mut active: asset::ActiveModel = asset.into();
active.owner = Set(Some(owner));
active.delegate = Set(delegate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,23 @@ pub async fn save_v1_asset<T: ConnectionTrait + TransactionTrait>(
let ownership_type = match class {
SpecificationAssetClass::FungibleAsset => OwnerType::Token,
SpecificationAssetClass::FungibleToken => OwnerType::Token,
// FIX: SPL tokens with associated metadata that do not set the token standard are incorrectly marked as single ownership.
_ => OwnerType::Single,
};

// gets the token and token account for the mint to populate the asset. This is required when the token and token account are indexed, but not the metadata account. If the metadata account is indexed, then the token and ta ingester will update the asset with the correct data
// gets the token and token account for the mint to populate the asset. This is required when the token and token account are indexed, but not the metadata account.
// If the metadata account is indexed, then the token and the ingester will update the asset with the correct data

let (token, token_account): (Option<tokens::Model>, Option<token_accounts::Model>) =
match ownership_type {
OwnerType::Single => {
let token: Option<tokens::Model> =
tokens::Entity::find_by_id(mint.clone()).one(conn).await?;
// query for token account associated with mint with positive balance
// query for token account associated with mint with amount of 1 since single ownership is a token account with amount of 1.
// In the case of a transfer the current owner's token account amount is deducted by 1 and the new owner's token account amount for the mint is incremented by 1.
let token_account: Option<token_accounts::Model> = token_accounts::Entity::find()
.filter(token_accounts::Column::Mint.eq(mint.clone()))
.filter(token_accounts::Column::Amount.gt(0))
.filter(token_accounts::Column::Amount.eq(1))
linuskendall marked this conversation as resolved.
Show resolved Hide resolved
.one(conn)
.await?;
Ok((token, token_account))
Expand Down
Loading