From defedb6da544ba41d8c33648812da062fb8e7ee9 Mon Sep 17 00:00:00 2001 From: satoshiotomakan <127754187+satoshiotomakan@users.noreply.github.com> Date: Wed, 6 Sep 2023 13:13:31 +0200 Subject: [PATCH] [Mantle]: Add Mantle EVM-compatible chain (#3417) --- .../blockchains/CoinAddressDerivationTests.kt | 2 +- docs/registry.md | 1 + include/TrustWalletCore/TWCoinType.h | 1 + .../core/test/CoinAddressDerivationTests.kt | 2 +- registry.json | 30 +++++++++++++++ swift/Tests/CoinAddressDerivationTests.swift | 3 +- tests/chains/Mantle/TWCoinTypeTests.cpp | 37 +++++++++++++++++++ tests/common/CoinAddressDerivationTests.cpp | 1 + 8 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 tests/chains/Mantle/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 dc52b3f81be..860cf75ebb9 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, ARBITRUMNOVA, ECOCHAIN, AVALANCHECCHAIN, XDAI, FANTOM, CELO, CRONOSCHAIN, SMARTBITCOINCASH, KUCOINCOMMUNITYCHAIN, BOBA, METIS, AURORA, EVMOS, MOONRIVER, MOONBEAM, KAVAEVM, KLAYTN, METER, OKXCHAIN, POLYGONZKEVM, SCROLL, - CONFLUXESPACE, ACALAEVM, OPBNB, NEON, BASE, LINEA, GREENFIELD -> assertEquals("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address) + CONFLUXESPACE, ACALAEVM, OPBNB, NEON, BASE, LINEA, GREENFIELD, MANTLE -> 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 c32440788a3..fd40414e96b 100644 --- a/docs/registry.md +++ b/docs/registry.md @@ -85,6 +85,7 @@ This list is generated from [./registry.json](../registry.json) | 2301 | Qtum | QTUM | | | | 2718 | Nebulas | NAS | | | | 3030 | Hedera | HBAR | | | +| 5000 | Mantle | ETH | | | | 5600 | BNB Greenfield | BNB | | | | 6060 | GoChain | GO | | | | 8453 | Base | ETH | | | diff --git a/include/TrustWalletCore/TWCoinType.h b/include/TrustWalletCore/TWCoinType.h index 47d979733c9..0d1c1d66ba3 100644 --- a/include/TrustWalletCore/TWCoinType.h +++ b/include/TrustWalletCore/TWCoinType.h @@ -175,6 +175,7 @@ enum TWCoinType { TWCoinTypeArbitrumNova = 10042170, TWCoinTypeLinea = 59144, TWCoinTypeGreenfield = 5600, + TWCoinTypeMantle = 5000, }; /// Returns the blockchain for a coin type. diff --git a/kotlin/wallet-core-kotlin/src/commonTest/kotlin/com/trustwallet/core/test/CoinAddressDerivationTests.kt b/kotlin/wallet-core-kotlin/src/commonTest/kotlin/com/trustwallet/core/test/CoinAddressDerivationTests.kt index fd55e64e5f5..fa444921583 100644 --- a/kotlin/wallet-core-kotlin/src/commonTest/kotlin/com/trustwallet/core/test/CoinAddressDerivationTests.kt +++ b/kotlin/wallet-core-kotlin/src/commonTest/kotlin/com/trustwallet/core/test/CoinAddressDerivationTests.kt @@ -39,7 +39,7 @@ class CoinAddressDerivationTests { Ethereum, SmartChain, Polygon, Optimism, Zksync, Arbitrum, ArbitrumNova, ECOChain, AvalancheCChain, XDai, Fantom, Celo, CronosChain, SmartBitcoinCash, KuCoinCommunityChain, Boba, Metis, Aurora, Evmos, Moonriver, Moonbeam, KavaEvm, Klaytn, Meter, OKXChain, PolygonzkEVM, Scroll, - ConfluxeSpace, AcalaEVM, OpBNB, Neon, Base, Linea, Greenfield, + ConfluxeSpace, AcalaEVM, OpBNB, Neon, Base, Linea, Greenfield, Mantle, -> "0x8f348F300873Fd5DA36950B2aC75a26584584feE" Ronin -> "ronin:8f348F300873Fd5DA36950B2aC75a26584584feE" diff --git a/registry.json b/registry.json index e7c368edc3d..dcc1f141df0 100644 --- a/registry.json +++ b/registry.json @@ -410,6 +410,36 @@ "documentation": "https://docs.linea.build" } }, + { + "id": "mantle", + "name": "Mantle", + "coinId": 5000, + "symbol": "MNT", + "decimals": 18, + "blockchain": "Ethereum", + "derivation": [ + { + "path": "m/44'/60'/0'/0/0" + } + ], + "curve": "secp256k1", + "publicKeyType": "secp256k1Extended", + "chainId": "5000", + "addressHasher": "keccak256", + "explorer": { + "url": "https://explorer.mantle.xyz", + "txPath": "/tx/", + "accountPath": "/address/", + "sampleTx": "0xfae996ea23f1ff9909ac04d26ae6e52ab600a84163fab9e0e893483c685629dd", + "sampleAccount": "0xA295EEFd401C8BE1457F266d3e73cdD015e5CFbb" + }, + "info": { + "url": "https://www.mantle.xyz", + "source": "https://github.com/mantlenetworkio", + "rpc": "https://rpc.mantle.xyz", + "documentation": "https://docs.mantle.xyz/network/introduction/overview" + } + }, { "id": "ethereum", "name": "Ethereum", diff --git a/swift/Tests/CoinAddressDerivationTests.swift b/swift/Tests/CoinAddressDerivationTests.swift index 81e0bdc55f7..15125af209e 100644 --- a/swift/Tests/CoinAddressDerivationTests.swift +++ b/swift/Tests/CoinAddressDerivationTests.swift @@ -112,7 +112,8 @@ class CoinAddressDerivationTests: XCTestCase { .neon, .base, .linea, - .greenfield: + .greenfield, + .mantle: let expectedResult = "0x8f348F300873Fd5DA36950B2aC75a26584584feE" assertCoinDerivation(coin, expectedResult, derivedAddress, address) case .ronin: diff --git a/tests/chains/Mantle/TWCoinTypeTests.cpp b/tests/chains/Mantle/TWCoinTypeTests.cpp new file mode 100644 index 00000000000..85483037897 --- /dev/null +++ b/tests/chains/Mantle/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(TWMantleCoinType, TWCoinType) { + const auto coin = TWCoinTypeMantle; + 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("0xfae996ea23f1ff9909ac04d26ae6e52ab600a84163fab9e0e893483c685629dd")); + const auto txUrl = WRAPS(TWCoinTypeConfigurationGetTransactionURL(coin, txId.get())); + const auto accId = WRAPS(TWStringCreateWithUTF8Bytes("0xA295EEFd401C8BE1457F266d3e73cdD015e5CFbb")); + const auto accUrl = WRAPS(TWCoinTypeConfigurationGetAccountURL(coin, accId.get())); + + assertStringsEqual(id, "mantle"); + assertStringsEqual(name, "Mantle"); + assertStringsEqual(symbol, "MNT"); + ASSERT_EQ(TWCoinTypeConfigurationGetDecimals(coin), 18); + ASSERT_EQ(TWCoinTypeBlockchain(coin), TWBlockchainEthereum); + ASSERT_EQ(TWCoinTypeP2shPrefix(coin), 0x0); + ASSERT_EQ(TWCoinTypeStaticPrefix(coin), 0x0); + assertStringsEqual(chainId, "5000"); + assertStringsEqual(txUrl, "https://explorer.mantle.xyz/tx/0xfae996ea23f1ff9909ac04d26ae6e52ab600a84163fab9e0e893483c685629dd"); + assertStringsEqual(accUrl, "https://explorer.mantle.xyz/address/0xA295EEFd401C8BE1457F266d3e73cdD015e5CFbb"); +} diff --git a/tests/common/CoinAddressDerivationTests.cpp b/tests/common/CoinAddressDerivationTests.cpp index 98d21a8a6f8..8c365316973 100644 --- a/tests/common/CoinAddressDerivationTests.cpp +++ b/tests/common/CoinAddressDerivationTests.cpp @@ -82,6 +82,7 @@ TEST(Coin, DeriveAddress) { case TWCoinTypeBase: case TWCoinTypeLinea: case TWCoinTypeGreenfield: + case TWCoinTypeMantle: EXPECT_EQ(address, "0x9d8A62f656a8d1615C1294fd71e9CFb3E4855A4F"); break;