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(wallet): migrate 0x Swap API to v2 #26231

Open
wants to merge 8 commits into
base: master
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
29 changes: 29 additions & 0 deletions components/brave_wallet/browser/brave_wallet_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,33 @@ const base::flat_map<std::string, std::string>& GetAnkrBlockchains() {

return *blockchains;
}

// See https://0x.org/docs/introduction/0x-cheat-sheet#allowanceholder-address
std::optional<std::string> GetZeroExAllowanceHolderAddress(
const std::string& chain_id) {
// key = chain_id, value = allowance_holder_contract_address
static base::NoDestructor<std::map<std::string, std::string>>
allowance_holder_addresses(
{{mojom::kMainnetChainId, kZeroExAllowanceHolderCancun},
{mojom::kArbitrumMainnetChainId, kZeroExAllowanceHolderCancun},
{mojom::kAvalancheMainnetChainId, kZeroExAllowanceHolderShanghai},
{mojom::kBaseMainnetChainId, kZeroExAllowanceHolderCancun},
{mojom::kBlastMainnetChainId, kZeroExAllowanceHolderCancun},
{mojom::kBnbSmartChainMainnetChainId, kZeroExAllowanceHolderCancun},
{mojom::kLineaChainId, kZeroExAllowanceHolderLondon},
{mojom::kOptimismMainnetChainId, kZeroExAllowanceHolderCancun},
{mojom::kPolygonMainnetChainId, kZeroExAllowanceHolderCancun},
{mojom::kScrollChainId, kZeroExAllowanceHolderShanghai}});

auto allowance_holder_address_pair =
allowance_holder_addresses->find(chain_id.c_str());

if (allowance_holder_address_pair == allowance_holder_addresses->end()) {
// not found
return std::nullopt;
}

return allowance_holder_address_pair->second;
}

} // namespace brave_wallet
35 changes: 13 additions & 22 deletions components/brave_wallet/browser/brave_wallet_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -1609,30 +1609,17 @@ inline constexpr webui::LocalizedString kLocalizedStrings[] = {
{"braveWalletDetails", IDS_BRAVE_WALLET_DETAILS}};

// 0x swap constants
inline constexpr char kZeroExSepoliaBaseAPIURL[] =
"https://sepolia.api.0x.wallet.brave.com";
inline constexpr char kZeroExPolygonBaseAPIURL[] =
"https://polygon.api.0x.wallet.brave.com";
inline constexpr char kZeroExBinanceSmartChainBaseAPIURL[] =
"https://bsc.api.0x.wallet.brave.com";
inline constexpr char kZeroExAvalancheBaseAPIURL[] =
"https://avalanche.api.0x.wallet.brave.com";
inline constexpr char kZeroExFantomBaseAPIURL[] =
"https://fantom.api.0x.wallet.brave.com";
inline constexpr char kZeroExCeloBaseAPIURL[] =
"https://celo.api.0x.wallet.brave.com";
inline constexpr char kZeroExOptimismBaseAPIURL[] =
"https://optimism.api.0x.wallet.brave.com";
inline constexpr char kZeroExArbitrumBaseAPIURL[] =
"https://arbitrum.api.0x.wallet.brave.com";
inline constexpr char kZeroExBaseBaseAPIURL[] =
"https://base.api.0x.wallet.brave.com";
inline constexpr char kZeroExEthereumBaseAPIURL[] =
"https://api.0x.wallet.brave.com";
inline constexpr char kZeroExBaseAPIURL[] = "https://api.0x.wallet.brave.com";
inline constexpr char kEVMFeeRecipient[] =
"0xbd9420A98a7Bd6B89765e5715e169481602D9c3d";
inline constexpr char kAffiliateAddress[] =
"0xbd9420A98a7Bd6B89765e5715e169481602D9c3d";
inline constexpr char kZeroExAllowanceHolderCancun[] =
"0x0000000000001fF3684f28c67538d4D072C22734";
inline constexpr char kZeroExAllowanceHolderShanghai[] =
"0x0000000000005E88410CcDFaDe4a5EfaE4b49562";
inline constexpr char kZeroExAllowanceHolderLondon[] =
"0x000000000000175a8b9bC6d539B3708EEd92EA6c";
inline constexpr char kZeroExAPIVersionHeader[] = "0x-version";
inline constexpr char kZeroExAPIVersion[] = "v2";

// Jupiter swap constants
inline constexpr char kJupiterBaseAPIURL[] = "https://jupiter.wallet.brave.com";
Expand Down Expand Up @@ -1712,6 +1699,10 @@ const std::string GetAssetRatioBaseURL();
const base::flat_map<std::string, std::string>& GetAnkrBlockchains();
// https://docs.rs/solana-program/1.18.10/src/solana_program/clock.rs.html#129-131
inline constexpr int kSolanaValidBlockHeightThreshold = 150;

std::optional<std::string> GetZeroExAllowanceHolderAddress(
const std::string& chain_id);

} // namespace brave_wallet

#endif // BRAVE_COMPONENTS_BRAVE_WALLET_BROWSER_BRAVE_WALLET_CONSTANTS_H_
Loading
Loading