diff --git a/core/bin/data_restore/src/data_restore_driver.rs b/core/bin/data_restore/src/data_restore_driver.rs index 137c0a7be8..5bb3224774 100644 --- a/core/bin/data_restore/src/data_restore_driver.rs +++ b/core/bin/data_restore/src/data_restore_driver.rs @@ -176,13 +176,13 @@ where ); interactor - .save_special_token(Token { - id: NFT_TOKEN_ID, - symbol: "SPECIAL".to_string(), - address: *NFT_STORAGE_ACCOUNT_ADDRESS, - decimals: 18, - kind: TokenKind::NFT, - }) + .save_special_token(Token::new( + NFT_TOKEN_ID, + *NFT_STORAGE_ACCOUNT_ADDRESS, + "SPECIAL", + 18, + TokenKind::NFT, + )) .await; vlog::info!("Special token added"); diff --git a/core/bin/data_restore/src/database_storage_interactor.rs b/core/bin/data_restore/src/database_storage_interactor.rs index 4211ffc920..4b7a335ad7 100644 --- a/core/bin/data_restore/src/database_storage_interactor.rs +++ b/core/bin/data_restore/src/database_storage_interactor.rs @@ -119,13 +119,13 @@ impl StorageInteractor for DatabaseStorageInteractor<'_> { async fn store_token(&mut self, token: TokenInfo, token_id: TokenId) { self.storage .tokens_schema() - .store_token(Token { - id: token_id, - symbol: token.symbol, - address: token.address, - decimals: token.decimals, - kind: TokenKind::ERC20, - }) + .store_token(Token::new( + token_id, + token.address, + &token.symbol, + token.decimals, + TokenKind::ERC20, + )) .await .expect("failed to store token"); } diff --git a/core/bin/data_restore/src/inmemory_storage_interactor.rs b/core/bin/data_restore/src/inmemory_storage_interactor.rs index 3d40cea8b8..7817ccd814 100644 --- a/core/bin/data_restore/src/inmemory_storage_interactor.rs +++ b/core/bin/data_restore/src/inmemory_storage_interactor.rs @@ -66,13 +66,13 @@ impl StorageInteractor for InMemoryStorageInteractor { } async fn store_token(&mut self, token: TokenInfo, token_id: TokenId) { - let token = Token { - id: token_id, - symbol: token.symbol, - address: token.address, - decimals: token.decimals, - kind: TokenKind::ERC20, - }; + let token = Token::new( + token_id, + token.address, + &token.symbol, + token.decimals, + TokenKind::ERC20, + ); self.tokens.insert(token_id, token); } @@ -98,6 +98,7 @@ impl StorageInteractor for InMemoryStorageInteractor { symbol: format!("ERC20-{}", *id), decimals: 18, kind: TokenKind::ERC20, + is_nft: false, }, ); } @@ -277,6 +278,7 @@ impl InMemoryStorageInteractor { symbol: token.symbol.clone(), decimals: 0, kind: TokenKind::NFT, + is_nft: true, }, ); } diff --git a/core/bin/zksync_api/src/api_server/admin_server.rs b/core/bin/zksync_api/src/api_server/admin_server.rs index 9a66d107d2..852f9cfadf 100644 --- a/core/bin/zksync_api/src/api_server/admin_server.rs +++ b/core/bin/zksync_api/src/api_server/admin_server.rs @@ -116,13 +116,13 @@ async fn add_token( } }; - let token = tokens::Token { + let token = tokens::Token::new( id, - address: token_request.address, - symbol: token_request.symbol.clone(), - decimals: token_request.decimals, - kind: TokenKind::ERC20, - }; + token_request.address, + &token_request.symbol, + token_request.decimals, + TokenKind::ERC20, + ); storage .tokens_schema() diff --git a/core/bin/zksync_api/src/fee_ticker/tests.rs b/core/bin/zksync_api/src/fee_ticker/tests.rs index 6788864547..9a93d400d3 100644 --- a/core/bin/zksync_api/src/fee_ticker/tests.rs +++ b/core/bin/zksync_api/src/fee_ticker/tests.rs @@ -565,6 +565,7 @@ async fn test_error_coingecko_api() { symbol: String::from("DAI"), decimals: 18, kind: TokenKind::ERC20, + is_nft: false, }; let (address, handler) = run_server(token.address); let client = reqwest::ClientBuilder::new() diff --git a/core/bin/zksync_core/src/lib.rs b/core/bin/zksync_core/src/lib.rs index a832a3b2d9..87f12c599a 100644 --- a/core/bin/zksync_core/src/lib.rs +++ b/core/bin/zksync_core/src/lib.rs @@ -74,13 +74,13 @@ pub async fn genesis_init(config: &ZkSyncConfig) { .await .expect("failed to access db") .tokens_schema() - .store_token(Token { - id: TokenId(id as u32), - symbol: token.symbol, - address: token.address, - decimals: token.decimals, - kind: TokenKind::ERC20, - }) + .store_token(Token::new( + TokenId(id as u32), + token.address, + &token.symbol, + token.decimals, + TokenKind::ERC20, + )) .await .expect("failed to store token"); } diff --git a/core/bin/zksync_core/src/state_keeper/mod.rs b/core/bin/zksync_core/src/state_keeper/mod.rs index 5c4bfeab4e..61174461a8 100644 --- a/core/bin/zksync_core/src/state_keeper/mod.rs +++ b/core/bin/zksync_core/src/state_keeper/mod.rs @@ -525,13 +525,13 @@ impl ZkSyncStateKeeper { vlog::info!("Adding special token"); transaction .tokens_schema() - .store_token(Token { - id: NFT_TOKEN_ID, - symbol: "SPECIAL".to_string(), - address: *NFT_STORAGE_ACCOUNT_ADDRESS, - decimals: 18, - kind: TokenKind::NFT, - }) + .store_token(Token::new( + NFT_TOKEN_ID, + *NFT_STORAGE_ACCOUNT_ADDRESS, + "SPECIAL", + 18, + TokenKind::NFT, + )) .await .expect("failed to store special token"); vlog::info!("Special token added"); diff --git a/core/lib/storage/sqlx-data.json b/core/lib/storage/sqlx-data.json index 0eacd598c7..5dbc6752b4 100644 --- a/core/lib/storage/sqlx-data.json +++ b/core/lib/storage/sqlx-data.json @@ -2728,24 +2728,6 @@ "nullable": [] } }, - "66dddd41e83db60b333ea6f5697d4507fb090021f4e4b22dbb4496d0999e17f1": { - "query": "\n SELECT tx FROM executed_transactions WHERE tx->'type' = '\"MintNFT\"'\n ORDER BY nonce\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "tx", - "type_info": "Jsonb" - } - ], - "parameters": { - "Left": [] - }, - "nullable": [ - false - ] - } - }, "681359f99d0e4bafdd3109f67c7af4d235dc1197ba88cd0d6148f632ae0cdf8f": { "query": "SELECT * FROM aggregated_proofs WHERE first_block = $1 and last_block = $2", "describe": { @@ -7174,6 +7156,24 @@ ] } }, + "f7a49b80724c8deb1f8af7016e92937fd04f9c5df474986ab61ad201ec41bdb4": { + "query": "\n SELECT tx FROM executed_transactions WHERE tx->'type' = '\"MintNFT\"' AND success = true\n ORDER BY nonce\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "tx", + "type_info": "Jsonb" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false + ] + } + }, "f8f2208c71cbf2d42de633222bb888c773a47b82dd0095b76ad38f535d74fdce": { "query": "SELECT created_at, block_number FROM executed_transactions\n WHERE tx_hash = $1", "describe": { diff --git a/core/lib/storage/src/tests/chain/accounts.rs b/core/lib/storage/src/tests/chain/accounts.rs index 38cd563bbc..a196ab21e9 100644 --- a/core/lib/storage/src/tests/chain/accounts.rs +++ b/core/lib/storage/src/tests/chain/accounts.rs @@ -330,6 +330,7 @@ async fn test_get_account_nft_balance(mut storage: StorageProcessor<'_>) -> Quer symbol: "NFT".to_string(), decimals: 0, kind: TokenKind::NFT, + is_nft: true, }) .await?; storage @@ -340,6 +341,7 @@ async fn test_get_account_nft_balance(mut storage: StorageProcessor<'_>) -> Quer symbol: "SPECIAL".to_string(), decimals: 0, kind: TokenKind::NFT, + is_nft: true, }) .await?; @@ -458,6 +460,7 @@ async fn test_get_nft_owner(mut storage: StorageProcessor<'_>) -> QueryResult<() symbol: "NFT".to_string(), decimals: 0, kind: TokenKind::NFT, + is_nft: true, }) .await?; storage diff --git a/core/lib/storage/src/tests/tokens.rs b/core/lib/storage/src/tests/tokens.rs index f81242e493..aa1a171546 100644 --- a/core/lib/storage/src/tests/tokens.rs +++ b/core/lib/storage/src/tests/tokens.rs @@ -38,6 +38,7 @@ async fn tokens_storage(mut storage: StorageProcessor<'_>) -> QueryResult<()> { symbol: "ETH".into(), decimals: 18, kind: TokenKind::ERC20, + is_nft: false, }; assert_eq!(tokens[&TokenId(0)], eth_token); @@ -48,6 +49,7 @@ async fn tokens_storage(mut storage: StorageProcessor<'_>) -> QueryResult<()> { symbol: "ABC".into(), decimals: 9, kind: TokenKind::ERC20, + is_nft: false, }; let token_b = Token { id: TokenId(2), @@ -55,6 +57,7 @@ async fn tokens_storage(mut storage: StorageProcessor<'_>) -> QueryResult<()> { symbol: "DEF".into(), decimals: 6, kind: TokenKind::None, + is_nft: false, }; let nft = Token { id: TokenId(MIN_NFT_TOKEN_ID), @@ -62,6 +65,7 @@ async fn tokens_storage(mut storage: StorageProcessor<'_>) -> QueryResult<()> { symbol: "NFT".into(), decimals: 0, kind: TokenKind::NFT, + is_nft: true, }; TokensSchema(&mut storage) diff --git a/core/lib/storage/src/tokens/records.rs b/core/lib/storage/src/tokens/records.rs index 9034e5f675..100814d258 100644 --- a/core/lib/storage/src/tokens/records.rs +++ b/core/lib/storage/src/tokens/records.rs @@ -65,13 +65,13 @@ impl From for DbToken { impl From for Token { fn from(val: DbToken) -> Token { - Token { - id: TokenId(val.id as u32), - address: stored_str_address_to_address(&val.address), - symbol: val.symbol, - decimals: val.decimals as u8, - kind: val.kind.into(), - } + Token::new( + TokenId(val.id as u32), + stored_str_address_to_address(&val.address), + &val.symbol, + val.decimals as u8, + val.kind.into(), + ) } } diff --git a/core/lib/types/src/tokens.rs b/core/lib/types/src/tokens.rs index 3df969b4ed..af093f4719 100644 --- a/core/lib/types/src/tokens.rs +++ b/core/lib/types/src/tokens.rs @@ -104,6 +104,7 @@ pub struct Token { /// Token precision (e.g. 18 for "ETH" so "1.0" ETH = 10e18 as U256 number) pub decimals: u8, pub kind: TokenKind, + pub is_nft: bool, } #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)] @@ -121,6 +122,7 @@ impl Token { symbol: symbol.to_string(), decimals, kind, + is_nft: matches!(kind, TokenKind::NFT), } } @@ -131,6 +133,7 @@ impl Token { symbol: symbol.to_string(), decimals: 0, kind: TokenKind::NFT, + is_nft: true, } } } diff --git a/sdk/zksync-rs/tests/unit.rs b/sdk/zksync-rs/tests/unit.rs index 4f907fddaa..74f8552ef9 100644 --- a/sdk/zksync-rs/tests/unit.rs +++ b/sdk/zksync-rs/tests/unit.rs @@ -190,13 +190,13 @@ mod signatures_with_vectors { ) .await; - let token = Token { - id: transfer_tx.token_id, - address: Default::default(), - symbol: sign_data.string_token.clone(), - decimals: 0, - kind: TokenKind::ERC20, - }; + let token = Token::new( + transfer_tx.token_id, + Default::default(), + &sign_data.string_token, + 0, + TokenKind::ERC20, + ); let (transfer, eth_signature) = signer .sign_transfer( token, @@ -247,13 +247,13 @@ mod signatures_with_vectors { ) .await; - let token = Token { - id: withdraw_tx.token_id, - address: Default::default(), - symbol: sign_data.string_token.clone(), - decimals: 0, - kind: TokenKind::ERC20, - }; + let token = Token::new( + withdraw_tx.token_id, + Default::default(), + &sign_data.string_token, + 0, + TokenKind::ERC20, + ); let (withdraw, eth_signature) = signer .sign_withdraw( token, @@ -304,13 +304,13 @@ mod signatures_with_vectors { ) .await; - let fee_token = Token { - id: withdraw_nft_tx.fee_token_id, - address: Default::default(), - symbol: sign_data.string_fee_token.clone(), - decimals: 0, - kind: TokenKind::ERC20, - }; + let fee_token = Token::new( + withdraw_nft_tx.fee_token_id, + Default::default(), + &sign_data.string_fee_token, + 0, + TokenKind::ERC20, + ); let (withdraw_nft, eth_signature) = signer .sign_withdraw_nft( @@ -362,13 +362,13 @@ mod signatures_with_vectors { ) .await; - let fee_token = Token { - id: mint_nft_tx.fee_token_id, - address: Default::default(), - symbol: sign_data.string_fee_token.clone(), - decimals: 0, - kind: TokenKind::ERC20, - }; + let fee_token = Token::new( + mint_nft_tx.fee_token_id, + Default::default(), + &sign_data.string_fee_token, + 0, + TokenKind::ERC20, + ); let (mint_nft, eth_signature) = signer .sign_mint_nft( @@ -420,13 +420,13 @@ mod signatures_with_vectors { .await; signer.pubkey_hash = change_pubkey_tx.new_pk_hash; - let token = Token { - id: change_pubkey_tx.fee_token_id, - address: Default::default(), - symbol: String::new(), - decimals: 0, - kind: TokenKind::ERC20, - }; + let token = Token::new( + change_pubkey_tx.fee_token_id, + Default::default(), + "", + 0, + TokenKind::ERC20, + ); let change_pub_key = signer .sign_change_pubkey_tx( sign_data.nonce, @@ -476,13 +476,13 @@ mod signatures_with_vectors { ) .await; - let token = Token { - id: forced_exit.token_id, - address: Default::default(), - symbol: String::new(), - decimals: 0, - kind: TokenKind::ERC20, - }; + let token = Token::new( + forced_exit.token_id, + Default::default(), + "", + 0, + TokenKind::ERC20, + ); let (forced_exit, _) = signer .sign_forced_exit( forced_exit.target, @@ -586,12 +586,14 @@ mod wallet_tests { let tokens = (1..) .zip(&genesis_tokens[..3]) - .map(|(id, token)| Token { - id: TokenId(id), - symbol: token.symbol.clone(), - address: token.address, - decimals: token.decimals, - kind: TokenKind::ERC20, + .map(|(id, token)| { + Token::new( + TokenId(id), + token.address, + &token.symbol, + token.decimals, + TokenKind::ERC20, + ) }) .map(|token| (token.symbol.clone(), token)) .collect();