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

[Acala]: Add Acala and AcalaEVM chains #3274

Merged
merged 3 commits into from
Jun 30, 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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class CoinAddressDerivationTests {
DIGIBYTE -> assertEquals("dgb1qtjgmerfqwdffyf8ghcrkgy52cghsqptynmyswu", address)
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, -> assertEquals("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address)
AURORA, EVMOS, MOONRIVER, MOONBEAM, KAVAEVM, KLAYTN, METER, OKXCHAIN, POLYGONZKEVM, SCROLL,
CONFLUXESPACE, ACALAEVM -> assertEquals("0x8f348F300873Fd5DA36950B2aC75a26584584feE", address)
RONIN -> assertEquals("ronin:8f348F300873Fd5DA36950B2aC75a26584584feE", address)
ETHEREUMCLASSIC -> assertEquals("0x078bA3228F3E6C08bEEac9A005de0b7e7089aD1c", address)
GOCHAIN -> assertEquals("0x5940ce4A14210d4Ccd0ac206CE92F21828016aC2", address)
Expand Down Expand Up @@ -94,6 +95,7 @@ class CoinAddressDerivationTests {
HARMONY -> assertEquals("one12fk20wmvgypdkn59n4hq8e3aa5899xfx4vsu09", address)
SOLANA -> assertEquals("2bUBiBNZyD29gP1oV6de7nxowMLoDBtopMMTGgMvjG5m", address)
ALGORAND -> assertEquals("JTJWO524JXIHVPGBDWFLJE7XUIA32ECOZOBLF2QP3V5TQBT3NKZSCG67BQ", address)
ACALA -> assertEquals("25GGezx3LWFQj6HZpYzoWoVzLsHojGtybef3vthC9nd19ms3", address)
KUSAMA -> assertEquals("G9xV2EatmrjRC1FLPexc3ddqNRRzCsAdURU8RFiAAJX6ppY", address)
POLKADOT -> assertEquals("13nN6BGAoJwd7Nw1XxeBCx5YcBXuYnL94Mh7i3xBprqVSsFk", address)
PIVX -> assertEquals("D81AqC8zKma3Cht4TbVuh4jyVVyLkZULCm", address)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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.

package com.trustwallet.core.app.blockchains.acala

import com.trustwallet.core.app.utils.toHex
import com.trustwallet.core.app.utils.toHexByteArray
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.*

class TestAcalaAddress {

init {
System.loadLibrary("TrustWalletCore")
}

@Test
fun testAddress() {
val key = PrivateKey("0x9066aa168c379a403becb235c15e7129c133c244e56a757ab07bc369288bcab0".toHexByteArray())
val pubkey = key.publicKeyEd25519
val address = AnyAddress(pubkey, CoinType.ACALA)
assertEquals(address.description(), "269ZCS3WLGydTN8ynhyhZfzJrXkePUcdhwgLQs6TWFs5wVL5")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// 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.

package com.trustwallet.core.app.blockchains.acala

import com.trustwallet.core.app.utils.Numeric
import com.trustwallet.core.app.utils.toHexBytesInByteString
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.java.AnySigner
import wallet.core.jni.CoinType
import wallet.core.jni.proto.Polkadot

class TestAcalaSigner {

init {
System.loadLibrary("TrustWalletCore")
}

@Test
fun AcalaTransactionSigning() {
val transferCallIndices = Polkadot.CallIndices.newBuilder().apply {
custom = Polkadot.CustomCallIndices.newBuilder().apply {
moduleIndex = 0x0a
methodIndex = 0x00
}.build()
}

val call = Polkadot.Balance.Transfer.newBuilder().apply {
value = "0xe8d4a51000".toHexBytesInByteString() // 1 ACA
toAddress = "25Qqz3ARAvnZbahGZUzV3xpP1bB3eRrupEprK7f2FNbHbvsz"
callIndices = transferCallIndices.build()
}

val acalaGenesisHashStr = "0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c".toHexBytesInByteString()

val input = Polkadot.SigningInput.newBuilder().apply {
genesisHash = acalaGenesisHashStr
blockHash = "0x707ffa05b7dc6cdb6356bd8bd51ff20b2757c3214a76277516080a10f1bc7537".toHexBytesInByteString()
nonce = 0
specVersion = 2170
network = CoinType.ACALA.ss58Prefix()
transactionVersion = 2
privateKey = "9066aa168c379a403becb235c15e7129c133c244e56a757ab07bc369288bcab0".toHexBytesInByteString()
era = Polkadot.Era.newBuilder().apply {
blockNumber = 3893613
period = 64
}.build()
balanceCall = Polkadot.Balance.newBuilder().apply {
transfer = call.build()
}.build()
multiAddress = true
}

val output = AnySigner.sign(input.build(), CoinType.ACALA, Polkadot.SigningOutput.parser())
val encoded = Numeric.toHexString(output.encoded.toByteArray())

// https://acala.subscan.io/extrinsic/3893620-3
val expected = "0x41028400e9590e4d99264a14a85e21e69537e4a64f66a875d38cb8f76b305f41fabe24a900dd54466dffd1e3c80b76013e9459fbdcd17805bd5fdbca0961a643bad1cbd2b7fe005c62c51c18b67f31eb9e61b187a911952fee172ef18402d07c703eec3100d50200000a0000c8c602ded977c56076ae38d98026fa669ca10d6a2b5a0bfc4086ae7668ed1c60070010a5d4e8"
assertEquals(encoded, expected)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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.

package com.trustwallet.core.app.blockchains.acalaevm

import com.trustwallet.core.app.utils.toHexByteArray
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.*

class TestAcalaEVMAddress {

init {
System.loadLibrary("TrustWalletCore")
}

@Test
fun testAddress() {
val key = PrivateKey("828c4c48c2cef521f0251920891ed79e871faa24f64f43cde83d07bc99f8dbf0".toHexByteArray())
val pubkey = key.getPublicKeySecp256k1(false)
val address = AnyAddress(pubkey, CoinType.ACALAEVM)
val expected = AnyAddress("0xe32DC46bfBF78D1eada7b0a68C96903e01418D64", CoinType.ACALAEVM)

assertEquals(address.description(), expected.description())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,48 +115,4 @@ class TestPolkadotSigner {
val expected = "0xd10184008361bd08ddca5fda28b5e2aa84dc2621de566e23e089e555a42194c3eaf2da7900c891ba102db672e378945d74cf7f399226a76b43cab502436971599255451597fc2599902e4b62c7ce85ecc3f653c693fef3232be620984b5bb5bcecbbd7b209d50318001a02080706070207004d446617"
assertEquals(encoded, expected)
}

@Test
fun PolkadotTransactionAcalaSigning() {
val transferCallIndices = Polkadot.CallIndices.newBuilder().apply {
custom = Polkadot.CustomCallIndices.newBuilder().apply {
moduleIndex = 0x0a
methodIndex = 0x00
}.build()
}

val call = Polkadot.Balance.Transfer.newBuilder().apply {
value = "0xe8d4a51000".toHexBytesInByteString() // 1 ACA
toAddress = "25Qqz3ARAvnZbahGZUzV3xpP1bB3eRrupEprK7f2FNbHbvsz"
callIndices = transferCallIndices.build()
}

val acalaGenesisHashStr = "0xfc41b9bd8ef8fe53d58c7ea67c794c7ec9a73daf05e6d54b14ff6342c99ba64c".toHexBytesInByteString()
val acalaNetworkSs58Prefix = 10

val input = Polkadot.SigningInput.newBuilder().apply {
genesisHash = acalaGenesisHashStr
blockHash = "0x707ffa05b7dc6cdb6356bd8bd51ff20b2757c3214a76277516080a10f1bc7537".toHexBytesInByteString()
nonce = 0
specVersion = 2170
network = acalaNetworkSs58Prefix
transactionVersion = 2
privateKey = "9066aa168c379a403becb235c15e7129c133c244e56a757ab07bc369288bcab0".toHexBytesInByteString()
era = Polkadot.Era.newBuilder().apply {
blockNumber = 3893613
period = 64
}.build()
balanceCall = Polkadot.Balance.newBuilder().apply {
transfer = call.build()
}.build()
multiAddress = true
}

val output = AnySigner.sign(input.build(), POLKADOT, SigningOutput.parser())
val encoded = Numeric.toHexString(output.encoded.toByteArray())

// https://acala.subscan.io/extrinsic/3893620-3
val expected = "0x41028400e9590e4d99264a14a85e21e69537e4a64f66a875d38cb8f76b305f41fabe24a900dd54466dffd1e3c80b76013e9459fbdcd17805bd5fdbca0961a643bad1cbd2b7fe005c62c51c18b67f31eb9e61b187a911952fee172ef18402d07c703eec3100d50200000a0000c8c602ded977c56076ae38d98026fa669ca10d6a2b5a0bfc4086ae7668ed1c60070010a5d4e8"
assertEquals(encoded, expected)
}
}
2 changes: 2 additions & 0 deletions docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ This list is generated from [./registry.json](../registry.json)
| 637 | Aptos | APT | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/aptos/info/logo.png" width="32" /> | <https://aptoslabs.com/> |
| 714 | BNB Beacon Chain | BNB | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/binance/info/logo.png" width="32" /> | <https://www.bnbchain.org> |
| 784 | Sui | SUI | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/sui/info/logo.png" width="32" /> | <https://sui.io/> |
| 787 | Acala | ACA | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/acala/info/logo.png" width="32" /> | <https://acala.network> |
| 818 | VeChain | VET | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/vechain/info/logo.png" width="32" /> | <https://vechain.org> |
| 820 | Callisto | CLO | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/callisto/info/logo.png" width="32" /> | <https://callisto.network> |
| 888 | NEO | NEO | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/neo/info/logo.png" width="32" /> | <https://neo.org> |
Expand Down Expand Up @@ -105,6 +106,7 @@ This list is generated from [./registry.json](../registry.json)
| 10000324 | zkSync Era | ETH | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/zksync/info/logo.png" width="32" /> | <https://portal.zksync.io/> |
| 10000330 | Terra | LUNA | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/terrav2/info/logo.png" width="32" /> | <https://terra.money> |
| 10000553 | Huobi ECO Chain | HT | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/heco/info/logo.png" width="32" /> | <https://www.hecochain.com/en-us> |
| 10000787 | Acala EVM | ACA | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/acalaevm/info/logo.png" width="32" /> | <https://acala.network> |
| 10000990 | Coreum | CORE | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/coreum/info/logo.png" width="32" /> | <https://www.coreum.com/> |
| 10001088 | Metis | METIS | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/metis/info/logo.png" width="32" /> | <https://www.metis.io/> |
| 10001101 | Polygon zkEVM | ETH | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/polygonzkevm/info/logo.png" width="32" /> | <https://www.polygon.technology/> |
Expand Down
2 changes: 2 additions & 0 deletions include/TrustWalletCore/TWCoinType.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ enum TWCoinType {
TWCoinTypeRootstock = 137,
TWCoinTypeThetaFuel = 361,
TWCoinTypeConfluxeSpace = 1030,
TWCoinTypeAcala = 787,
TWCoinTypeAcalaEVM = 10000787,
};

/// Returns the blockchain for a coin type.
Expand Down
61 changes: 61 additions & 0 deletions registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -1924,6 +1924,67 @@
"documentation": "https://polkadot.js.org/api/substrate/rpc.html"
}
},
{
"id": "acala",
"name": "Acala",
"coinId": 787,
"symbol": "ACA",
"decimals": 12,
"blockchain": "Polkadot",
"derivation": [
{
"path": "m/44'/787'/0'/0'/0'"
}
],
"curve": "ed25519",
"publicKeyType": "ed25519",
"addressHasher": "keccak256",
"ss58Prefix": 10,
"explorer": {
"url": "https://acala.subscan.io",
"txPath": "/extrinsic/",
"accountPath": "/account/",
"sampleTx": "0xf3d58aafb1208bc09d10ba74bbf1c7811dc55a9149c1505256b6fb5603f5047f",
"sampleAccount": "26JqMKx4HJJcmb1kXo24HYYobiK2jURGCq6zuEzFBK3hQ9Ti"
},
"info": {
"url": "https://acala.network",
"source": "https://github.com/AcalaNetwork/Acala",
"rpc": "wss://acala-rpc.dwellir.com",
"documentation": "https://polkadot.js.org/api/substrate/rpc.html"
}
},
{
"id": "acalaevm",
"name": "Acala EVM",
"coinId": 10000787,
"slip44": 60,
"symbol": "ACA",
"decimals": 18,
"blockchain": "Ethereum",
"derivation": [
{
"path": "m/44'/60'/0'/0/0"
}
],
"curve": "secp256k1",
"publicKeyType": "secp256k1Extended",
"chainId": "787",
"addressHasher": "keccak256",
"explorer": {
"url": "https://blockscout.acala.network",
"txPath": "/tx/",
"accountPath": "/address/",
"sampleTx": "0x4b0b151dd71ed8ef3174da18565790bf14f0a903a13e4f3266c7848bc8841593",
"sampleAccount": "0x9d1d97aDFcd324Bbd603D3872BD78e04098510b1"
},
"info": {
"url": "https://acala.network",
"source": "https://github.com/AcalaNetwork/Acala",
"rpc": "https://eth-rpc-acala.aca-api.network",
"documentation": "https://polkadot.js.org/api/substrate/rpc.html"
}
},
{
"id": "aeternity",
"name": "Aeternity",
Expand Down
16 changes: 10 additions & 6 deletions src/Polkadot/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,33 @@
#include "Entry.h"

#include "Address.h"
#include "Coin.h"
#include "Signer.h"
#include "../proto/TransactionCompiler.pb.h"

namespace TW::Polkadot {

// Note: avoid business logic from here, rather just call into classes like Address, Signer, etc.

bool Entry::validateAddress([[maybe_unused]] TWCoinType coin, const std::string& address, const PrefixVariant& addressPrefix) const {
bool Entry::validateAddress(TWCoinType coin, const std::string& address, const PrefixVariant& addressPrefix) const {
if (auto* prefix = std::get_if<SS58Prefix>(&addressPrefix); prefix) {
return Address::isValid(address, *prefix);
}
return Address::isValid(address);
const auto ss58Prefix = TW::ss58Prefix(coin);
return Address::isValid(address, ss58Prefix);
}

std::string Entry::deriveAddress([[maybe_unused]] TWCoinType coin, const PublicKey& publicKey, [[maybe_unused]] TWDerivation derivation, const PrefixVariant& addressPrefix) const {
std::string Entry::deriveAddress(TWCoinType coin, const PublicKey& publicKey, [[maybe_unused]] TWDerivation derivation, const PrefixVariant& addressPrefix) const {
if (auto* ss58Prefix = std::get_if<SS58Prefix>(&addressPrefix); ss58Prefix) {
return Address(publicKey, *ss58Prefix).string();
}
return Address(publicKey).string();
const auto ss58Prefix = TW::ss58Prefix(coin);
return Address(publicKey, ss58Prefix).string();
}

Data Entry::addressToData([[maybe_unused]] TWCoinType coin, const std::string& address) const {
const auto addr = Address(address);
Data Entry::addressToData(TWCoinType coin, const std::string& address) const {
const auto ss58Prefix = TW::ss58Prefix(coin);
const auto addr = Address(address, ss58Prefix);
return {addr.bytes.begin() + 1, addr.bytes.end()};
}

Expand Down
19 changes: 19 additions & 0 deletions swift/Tests/Blockchains/AcalaEVMTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.

import WalletCore
import XCTest

class AcalaEVMTests: XCTestCase {
func testAddress() {
let key = PrivateKey(data: Data(hexString: "828c4c48c2cef521f0251920891ed79e871faa24f64f43cde83d07bc99f8dbf0")!)!
let pubkey = key.getPublicKeySecp256k1(compressed: false)
let address = AnyAddress(publicKey: pubkey, coin: .acalaEVM)
let expected = AnyAddress(string: "0xe32DC46bfBF78D1eada7b0a68C96903e01418D64", coin: .acalaEVM)!

XCTAssertEqual(address.description, expected.description)
}
}
Loading