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

feat: add Base chain support #515

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
154 changes: 154 additions & 0 deletions apps/evm_family/base/base_app.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/**
* @file base_app.c
* @author Cypherock X1 Team
* @brief BASE application configuration and helpers
* @copyright Copyright (c) 2023 HODL TECH PTE LTD
* <br/> You may obtain a copy of license at <a href="https://mitcc.org/"
*target=_blank>https://mitcc.org/</a>
*
******************************************************************************
* @attention
*
* (c) Copyright 2023 by HODL TECH PTE LTD
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
* "Commons Clause" License Condition v1.0
*
* The Software is provided to you by the Licensor under the License,
* as defined below, subject to the following condition.
*
* Without limiting other conditions in the License, the grant of
* rights under the License will not include, and the License does not
* grant to you, the right to Sell the Software.
*
* For purposes of the foregoing, "Sell" means practicing any or all
* of the rights granted to you under the License to provide to third
* parties, for a fee or other consideration (including without
* limitation fees for hosting or consulting/ support services related
* to the Software), a product or service whose value derives, entirely
* or substantially, from the functionality of the Software. Any license
* notice or attribution required by the License must also include
* this Commons Clause License Condition notice.
*
* Software: All X1Wallet associated files.
* License: MIT
* Licensor: HODL TECH PTE LTD
*
******************************************************************************
*/

/*****************************************************************************
* INCLUDES
*****************************************************************************/

#include "base_app.h"

#include <stddef.h>

#include "evm_main.h"

/*****************************************************************************
* EXTERN VARIABLES
*****************************************************************************/

/**
* @brief Whitelisted contracts with respective token symbol
* @details A map of Ethereum contract addresses with their token symbols. These
* will enable the device to verify the ERC20 token transaction in a
* user-friendly manner.
*
* @see erc20_contracts_t
*/
extern const erc20_contracts_t base_contracts[];

/*****************************************************************************
* PRIVATE MACROS AND DEFINES
*****************************************************************************/

/*****************************************************************************
* PRIVATE TYPEDEFS
*****************************************************************************/

/*****************************************************************************
* STATIC FUNCTION PROTOTYPES
*****************************************************************************/

/**
* @brief Checks if the provided token address is whitelisted and return the
* matching contract instance.
*
* @param address Reference to the buffer containing the token address
* @param contract Pointer to store the matched contract address instance
*
* @return bool Indicating if the provided token address is whitelisted
* @return true If the address matches to an entry in the whitelist
* @return false If the address does not match to an entry in the whitelist
*/
static bool is_token_whitelisted(const uint8_t *address,
const erc20_contracts_t **contract);

/*****************************************************************************
* STATIC VARIABLES
*****************************************************************************/

static const evm_config_t base_app_config = {
.lunit_name = "ETH",
.name = "BASE",
.chain_id = 8453,

// whitelisted contracts
.is_token_whitelisted = is_token_whitelisted,
};

static const cy_app_desc_t base_app_desc = {
.id = 18,
.version =
Copy link
Contributor

@ParnikaGupta9 ParnikaGupta9 Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Branch out from our repo. Re-base to the "develop" branch. Kindly follow the same for sdk and cysync.
change id to 19.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also resolve the commit checks in CI

{
.major = 1,
.minor = 1,
.patch = 0,
},
.app = evm_main,
.app_config = &base_app_config};
/*****************************************************************************
* GLOBAL VARIABLES
*****************************************************************************/

/*****************************************************************************
* STATIC FUNCTIONS
*****************************************************************************/

static bool is_token_whitelisted(const uint8_t *address,
const erc20_contracts_t **contract) {
if (NULL != contract) {
*contract = NULL;
}
return false;
}

/*****************************************************************************
* GLOBAL FUNCTIONS
*****************************************************************************/

const cy_app_desc_t *get_base_app_desc() {
return &base_app_desc;
}
44 changes: 44 additions & 0 deletions apps/evm_family/base/base_app.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @file BASE_app.h
* @author Cypherock X1 Team
* @brief BASE application configuration
* @copyright Copyright (c) 2023 HODL TECH PTE LTD
* <br/> You may obtain a copy of license at <a href="https://mitcc.org/"
* target=_blank>https://mitcc.org/</a>
*/
#ifndef BASE_APP_H
#define BASE_APP_H

/*****************************************************************************
* INCLUDES
*****************************************************************************/

#include "app_registry.h"
#include "evm_context.h"
/*****************************************************************************
* MACROS AND DEFINES
*****************************************************************************/

/// Number of entries in whitelisted contracts list
#define BASE_WHITELISTED_CONTRACTS_COUNT 0

/*****************************************************************************
* TYPEDEFS
*****************************************************************************/

/*****************************************************************************
* EXPORTED VARIABLES
*****************************************************************************/

/*****************************************************************************
* GLOBAL FUNCTION PROTOTYPES
*****************************************************************************/

/**
* @brief Returns the config for BASE chin app descriptor
*
* @return A const reference to cy_app_desc_t
*/
const cy_app_desc_t *get_base_app_desc();

#endif // BASE_APP_H
21 changes: 21 additions & 0 deletions common/coin_support/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @file base.h
* @author Cypherock X1 Team
* @brief BASE C-Chain network config
* Place to define all values specific to BASE C-Chain
* @copyright Copyright (c) 2022 HODL TECH PTE LTD
* <br/> You may obtain a copy of license at <a href="https://mitcc.org/"
* target=_blank>https://mitcc.org/</a>
*
*/
#ifndef BASE_H
#define BASE_H

#define BASE_COIN_VERSION 0x00000000

#define BASE_MAINNET_CHAIN 8453

#define BASE_MAINNET_NAME "Base"
#define BASE_TOKEN_SYMBOL "ETH"

#endif
1 change: 1 addition & 0 deletions common/coin_support/coin_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "coin_utils.h"

#include "arbitrum.h"
#include "base.h"
#include "avalanche.h"
#include "bsc.h"
#include "etc.h"
Expand Down
1 change: 1 addition & 0 deletions common/coin_support/coin_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef enum Coin_Type {
COIN_TYPE_HARMONY = 0x0E,
COIN_TYPE_ETHEREUM_CLASSIC = 0x0f,
COIN_TYPE_ARBITRUM = 0x10,
COIN_TYPE_BASE = 0x11,
} Coin_Type;

#pragma pack(push, 1)
Expand Down
2 changes: 2 additions & 0 deletions common/core/core_flow_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "app_registry.h"
#include "application_startup.h"
#include "arbitrum_app.h"
#include "base_app.h"
#include "avalanche_app.h"
#include "bsc_app.h"
#include "btc_app.h"
Expand Down Expand Up @@ -177,4 +178,5 @@ void core_init_app_registry() {
registry_add_app(get_avalanche_app_desc());
registry_add_app(get_optimism_app_desc());
registry_add_app(get_arbitrum_app_desc());
registry_add_app(get_base_app_desc());
}
1 change: 1 addition & 0 deletions utilities/cmake/firmware/firmware.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ target_include_directories(${EXECUTABLE} PRIVATE
apps/evm_family/avalanche
apps/evm_family/optimism
apps/evm_family/arbitrum
apps/evm_family/base
apps/near_app
apps/solana_app

Expand Down
1 change: 1 addition & 0 deletions utilities/cmake/simulator/simulator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE
apps/evm_family/avalanche
apps/evm_family/optimism
apps/evm_family/arbitrum
apps/evm_family/base
apps/near_app

apps/solana_app
Expand Down
Loading