From c58d93563825252d43a660041d85594c05bfa6e1 Mon Sep 17 00:00:00 2001 From: Milerius Date: Tue, 1 Aug 2023 08:27:15 +0200 Subject: [PATCH] feat(base): add base blockchain --- .../blockchains/CoinAddressDerivationTests.kt | 2 +- docs/registry.md | 1 + include/TrustWalletCore/TWCoinType.h | 1 + registry.json | 30 +++++++++++++++ swift/Tests/CoinAddressDerivationTests.swift | 3 +- tests/chains/Base/TWCoinTypeTests.cpp | 37 +++++++++++++++++++ tests/chains/Bitcoin/TWBitcoinFeeTests.cpp | 6 +-- tests/common/CoinAddressDerivationTests.cpp | 1 + 8 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 tests/chains/Base/TWCoinTypeTests.cpp diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt index bef1b60cea7..94b2f723f45 100644 --- a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/CoinAddressDerivationTests.kt @@ -45,7 +45,7 @@ class CoinAddressDerivationTests { ETHEREUM, SMARTCHAIN, POLYGON, OPTIMISM, ZKSYNC, ARBITRUM, ECOCHAIN, AVALANCHECCHAIN, XDAI, FANTOM, CELO, CRONOSCHAIN, SMARTBITCOINCASH, KUCOINCOMMUNITYCHAIN, BOBA, METIS, AURORA, EVMOS, MOONRIVER, MOONBEAM, KAVAEVM, KLAYTN, METER, OKXCHAIN, POLYGONZKEVM, SCROLL, - CONFLUXESPACE, ACALAEVM, OPBNBTESTNET, NEON -> assertEquals("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address) + CONFLUXESPACE, ACALAEVM, OPBNBTESTNET, NEON, BASE -> assertEquals("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address) RONIN -> assertEquals("ronin:8f348F300873Fd5DA36950B2aC75a26584584feE", address) ETHEREUMCLASSIC -> assertEquals("0x078bA3228F3E6C08bEEac9A005de0b7e7089aD1c", address) GOCHAIN -> assertEquals("0x5940ce4A14210d4Ccd0ac206CE92F21828016aC2", address) diff --git a/docs/registry.md b/docs/registry.md index 6d914e0aa96..ae123be4198 100644 --- a/docs/registry.md +++ b/docs/registry.md @@ -86,6 +86,7 @@ This list is generated from [./registry.json](../registry.json) | 3030 | Hedera | HBAR | | | | 5611 | OpBNB testnet | tBNB | | | | 6060 | GoChain | GO | | | +| 8453 | Base | ETH | | | | 8964 | NULS | NULS | | | | 14001 | WAX | WAXP | | | | 18000 | Meter | MTR | | | diff --git a/include/TrustWalletCore/TWCoinType.h b/include/TrustWalletCore/TWCoinType.h index a762105c596..beef6628af1 100644 --- a/include/TrustWalletCore/TWCoinType.h +++ b/include/TrustWalletCore/TWCoinType.h @@ -170,6 +170,7 @@ enum TWCoinType { TWCoinTypeAcalaEVM = 10000787, TWCoinTypeOpBNBtestnet = 5611, TWCoinTypeNeon = 245022934, + TWCoinTypeBase = 8453, }; /// Returns the blockchain for a coin type. diff --git a/registry.json b/registry.json index 20f15fbe17e..84addcd0cf6 100644 --- a/registry.json +++ b/registry.json @@ -350,6 +350,36 @@ "documentation": "https://docs.syscoin.org" } }, + { + "id": "base", + "name": "Base", + "coinId": 8453, + "symbol": "ETH", + "decimals": 18, + "blockchain": "Ethereum", + "derivation": [ + { + "path": "m/44'/60'/0'/0/0" + } + ], + "curve": "secp256k1", + "publicKeyType": "secp256k1Extended", + "chainId": "8453", + "addressHasher": "keccak256", + "explorer": { + "url": "https://basescan.org", + "txPath": "/tx/", + "accountPath": "/address/", + "sampleTx": "0x4acb15506b7696a2dfac4258f3f86392b4b2b717a3f316a8aa78509b2c3b6ab4", + "sampleAccount": "0xb8ff877ed78ba520ece21b1de7843a8a57ca47cb" + }, + "info": { + "url": "https://base.mirror.xyz/", + "source": "https://github.com/base-org", + "rpc": "https://mainnet.base.org", + "documentation": "https://docs.base.org/" + } + }, { "id": "ethereum", "name": "Ethereum", diff --git a/swift/Tests/CoinAddressDerivationTests.swift b/swift/Tests/CoinAddressDerivationTests.swift index c5f39c9d51f..ed6254e2a8f 100644 --- a/swift/Tests/CoinAddressDerivationTests.swift +++ b/swift/Tests/CoinAddressDerivationTests.swift @@ -108,7 +108,8 @@ class CoinAddressDerivationTests: XCTestCase { .confluxeSpace, .opBNBtestnet, .acalaEVM, - .neon: + .neon, + .base: let expectedResult = "0x8f348F300873Fd5DA36950B2aC75a26584584feE" assertCoinDerivation(coin, expectedResult, derivedAddress, address) case .ronin: diff --git a/tests/chains/Base/TWCoinTypeTests.cpp b/tests/chains/Base/TWCoinTypeTests.cpp new file mode 100644 index 00000000000..a07285626d2 --- /dev/null +++ b/tests/chains/Base/TWCoinTypeTests.cpp @@ -0,0 +1,37 @@ +// Copyright © 2017-2023 Trust Wallet. +// +// This file is part of Trust. The full Trust copyright notice, including +// terms governing use, modification, and redistribution, is contained in the +// file LICENSE at the root of the source code distribution tree. +// +// This is a GENERATED FILE, changes made here MAY BE LOST. +// Generated one-time (codegen/bin/cointests) +// + +#include "TestUtilities.h" +#include +#include + + +TEST(TWBaseCoinType, TWCoinType) { + const auto coin = TWCoinTypeBase; + const auto symbol = WRAPS(TWCoinTypeConfigurationGetSymbol(coin)); + const auto id = WRAPS(TWCoinTypeConfigurationGetID(coin)); + const auto name = WRAPS(TWCoinTypeConfigurationGetName(coin)); + const auto chainId = WRAPS(TWCoinTypeChainId(coin)); + const auto txId = WRAPS(TWStringCreateWithUTF8Bytes("0x4acb15506b7696a2dfac4258f3f86392b4b2b717a3f316a8aa78509b2c3b6ab4")); + const auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(coin, txId.get())); + const auto accId = WRAPS(TWStringCreateWithUTF8Bytes("0xb8ff877ed78ba520ece21b1de7843a8a57ca47cb")); + const auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(coin, accId.get())); + + assertStringsEqual(id, "base"); + assertStringsEqual(name, "Base"); + assertStringsEqual(symbol, "ETH"); + ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(coin), 18); + ASSERT_EQ(TWCoinTypeBlockchain(coin), TWBlockchainEthereum); + ASSERT_EQ(TWCoinTypeP2shPrefix(coin), 0x0); + ASSERT_EQ(TWCoinTypeStaticPrefix(coin), 0x0); + assertStringsEqual(chainId, "8453"); + assertStringsEqual(txUrl, "https://basescan.org/tx/0x4acb15506b7696a2dfac4258f3f86392b4b2b717a3f316a8aa78509b2c3b6ab4"); + assertStringsEqual(accUrl, "https://basescan.org/address/0xb8ff877ed78ba520ece21b1de7843a8a57ca47cb"); +} diff --git a/tests/chains/Bitcoin/TWBitcoinFeeTests.cpp b/tests/chains/Bitcoin/TWBitcoinFeeTests.cpp index 0692760478f..9344e7dfcd6 100644 --- a/tests/chains/Bitcoin/TWBitcoinFeeTests.cpp +++ b/tests/chains/Bitcoin/TWBitcoinFeeTests.cpp @@ -14,14 +14,14 @@ TEST(TWBitcoinFee, P2pkhFee) { auto satVb = 10; auto data = DATA("02000000017be4e642bb278018ab12277de9427773ad1c5f5b1d164a157e0d99aa48dc1c1e000000006a473044022078eda020d4b86fcb3af78ef919912e6d79b81164dbbb0b0b96da6ac58a2de4b102201a5fd8d48734d5a02371c4b5ee551a69dca3842edbf577d863cf8ae9fdbbd4590121036666dd712e05a487916384bfcd5973eb53e8038eccbbf97f7eed775b87389536ffffffff01c0aff629010000001976a9145eaaa4f458f9158f86afcba08dd7448d27045e3d88ac00000000"); auto fee = TWBitcoinFeeCalculateFee(data.get(), satVb); - ASSERT_EQ(fee, 191 * satVb); + ASSERT_EQ(fee, 191UL * satVb); } TEST(TWBitcoinFee, P2wpkhFee) { auto satVb = 12; auto data = DATA("020000000111b9f62923af73e297abb69f749e7a1aa2735fbdfd32ac5f6aa89e5c96841c18000000006b483045022100df9ed0b662b759e68b89a42e7144cddf787782a7129d4df05642dd825930e6e6022051a08f577f11cc7390684bbad2951a6374072253ffcf2468d14035ed0d8cd6490121028d7dce6d72fb8f7af9566616c6436349c67ad379f2404dd66fe7085fe0fba28fffffffff01c0aff629010000001600140d0e1cec6c2babe8badde5e9b3dea667da90036d00000000"); auto fee = TWBitcoinFeeCalculateFee(data.get(), satVb); - ASSERT_EQ(fee, 189 * satVb); + ASSERT_EQ(fee, 189UL * satVb); } // Metadata can be observed live on: @@ -34,7 +34,7 @@ TEST(TWBitcoinFee, BRC20TransferCommitFee) { auto satVb = 19; auto data = DATA("02000000000101089098890d2653567b9e8df2d1fbe5c3c8bf1910ca7184e301db0ad3b495c88e0100000000ffffffff02581b000000000000225120e8b706a97732e705e22ae7710703e7f589ed13c636324461afa443016134cc051040000000000000160014e311b8d6ddff856ce8e9a4e03bc6d4fe5050a83d02483045022100a44aa28446a9a886b378a4a65e32ad9a3108870bd725dc6105160bed4f317097022069e9de36422e4ce2e42b39884aa5f626f8f94194d1013007d5a1ea9220a06dce0121030f209b6ada5edb42c77fd2bc64ad650ae38314c8f451f3e36d80bc8e26f132cb00000000"); auto fee = TWBitcoinFeeCalculateFee(data.get(), satVb); - ASSERT_EQ(fee, 153 * satVb); // 153 = ceil(610/4) + ASSERT_EQ(fee, 153UL * satVb); // 153 = ceil(610/4) } } // namespace TW::Bitcoin diff --git a/tests/common/CoinAddressDerivationTests.cpp b/tests/common/CoinAddressDerivationTests.cpp index ac948f7aa11..0a242324f7c 100644 --- a/tests/common/CoinAddressDerivationTests.cpp +++ b/tests/common/CoinAddressDerivationTests.cpp @@ -78,6 +78,7 @@ TEST(Coin, DeriveAddress) { case TWCoinTypeScroll: case TWCoinTypeOpBNBtestnet: case TWCoinTypeNeon: + case TWCoinTypeBase: EXPECT_EQ(address, "0x9d8A62f656a8d1615C1294fd71e9CFb3E4855A4F"); break;