Skip to content

Commit

Permalink
Merge branch 'main' into fix/rsk/ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDaedalus authored Jan 19, 2023
2 parents 84f5555 + 1c427db commit 9eaa7e4
Show file tree
Hide file tree
Showing 89 changed files with 2,802 additions and 701 deletions.
1 change: 1 addition & 0 deletions .env.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SUPPORT_FORGOT_PASSWORD=false
SUPPORT_AVALANCHE=true
SUPPORT_BINANCE_SMART_CHAIN=true
SUPPORT_ARBITRUM_NOVA=false
SUPPORT_SWAP_QUOTE_REFRESH=false
ENABLE_ACHIEVEMENTS_TAB=true
SUPPORT_ACHIEVEMENTS_BANNER=false
SWITCH_RUNTIME_FLAGS=false
Expand Down
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/BUG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ body:
label: Version
description: What version of the extension are you running?
options:
- v0.18.9
- v0.18.8
- v0.18.7
- v0.18.6
- v0.18.5
Expand Down
2 changes: 1 addition & 1 deletion background/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HexString } from "./types"

/**
* An account balance at a particular time and block height, on a particular
* network. Flexible enough to represent base assets like ETH and BTC as well
* network. Flexible enough to represent base assets like ETH as well
* application-layer tokens like ERC-20s.
*/
export type AccountBalance = {
Expand Down
17 changes: 16 additions & 1 deletion background/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export type Asset = {
* asset id in CoinGecko's records.
*/
export type CoinGeckoAsset = Asset & {
metadata: Asset["metadata"] & {
metadata?: Asset["metadata"] & {
coinGeckoID: string
}
}
Expand Down Expand Up @@ -120,6 +120,7 @@ export type AnyAsset =
| FiatCurrency
| FungibleAsset
| SmartContractFungibleAsset
| NetworkBaseAsset

/**
* An asset that can be swapped with our current providers
Expand Down Expand Up @@ -211,6 +212,20 @@ export function isFungibleAssetAmount(
): assetAmount is FungibleAssetAmount {
return isFungibleAsset(assetAmount.asset)
}
/**
* Flips `pair` and `amounts` values in the PricePoint object.
*
* @param pricePoint
* @returns pricePoint with flipped pair and amounts
*/
export function flipPricePoint(pricePoint: PricePoint): PricePoint {
const { pair, amounts, time } = pricePoint
return {
pair: [pair[1], pair[0]],
amounts: [amounts[1], amounts[0]],
time,
}
}

/**
* Converts the given source asset amount, fungible or non-fungible, to a target
Expand Down
70 changes: 70 additions & 0 deletions background/constants/base-assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { NetworkBaseAsset } from "../networks"

const ETH: NetworkBaseAsset = {
chainID: "1",
name: "Ether",
symbol: "ETH",
decimals: 18,
}

const ARBITRUM_ONE_ETH: NetworkBaseAsset = {
...ETH,
chainID: "42161",
}

const ARBITRUM_NOVA_ETH: NetworkBaseAsset = {
...ETH,
chainID: "42170",
}

const OPTIMISTIC_ETH: NetworkBaseAsset = {
...ETH,
chainID: "10",
}

const GOERLI_ETH: NetworkBaseAsset = {
...ETH,
chainID: "5",
}

const RBTC: NetworkBaseAsset = {
chainID: "30",
name: "RSK Token",
symbol: "RBTC",
decimals: 18,
}

const MATIC: NetworkBaseAsset = {
chainID: "137",
name: "Matic Token",
symbol: "MATIC",
decimals: 18,
}

const AVAX: NetworkBaseAsset = {
chainID: "43114",
name: "Avalanche",
symbol: "AVAX",
decimals: 18,
}

const BNB: NetworkBaseAsset = {
chainID: "56",
name: "Binance Coin",
symbol: "BNB",
decimals: 18,
}

export const BASE_ASSETS_BY_CUSTOM_NAME = {
ETH,
MATIC,
RBTC,
AVAX,
BNB,
ARBITRUM_ONE_ETH,
ARBITRUM_NOVA_ETH,
OPTIMISTIC_ETH,
GOERLI_ETH,
}

export const BASE_ASSETS = Object.values(BASE_ASSETS_BY_CUSTOM_NAME)
2 changes: 0 additions & 2 deletions background/constants/coin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Limited extension-specific list of coin types by asset symbol.
*/
export const coinTypesByAssetSymbol = {
BTC: 0,
"Testnet BTC": 1,
ETH: 60,
RBTC: 137,
MATIC: 966,
Expand Down
99 changes: 45 additions & 54 deletions background/constants/currencies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FiatCurrency } from "../assets"
import { CoinGeckoAsset, FiatCurrency } from "../assets"
import { NetworkBaseAsset } from "../networks"
import { BASE_ASSETS_BY_CUSTOM_NAME } from "./base-assets"
import { coinTypesByAssetSymbol } from "./coin-types"

export const USD: FiatCurrency = {
Expand All @@ -13,10 +14,7 @@ export const FIAT_CURRENCIES_SYMBOL = FIAT_CURRENCIES.map(
(currency) => currency.symbol
)

export const ETH: NetworkBaseAsset = {
name: "Ether",
symbol: "ETH",
decimals: 18,
export const ETH_DATA = {
coinType: coinTypesByAssetSymbol.ETH,
metadata: {
coinGeckoID: "ethereum",
Expand All @@ -25,10 +23,13 @@ export const ETH: NetworkBaseAsset = {
},
}

export const RBTC: NetworkBaseAsset = {
name: "RSK Token",
symbol: "RBTC",
decimals: 18,
export const ETH: NetworkBaseAsset & Required<CoinGeckoAsset> = {
...BASE_ASSETS_BY_CUSTOM_NAME.ETH,
...ETH_DATA,
}

export const RBTC: NetworkBaseAsset & Required<CoinGeckoAsset> = {
...BASE_ASSETS_BY_CUSTOM_NAME.RBTC,
coinType: coinTypesByAssetSymbol.RBTC,
metadata: {
coinGeckoID: "rootstock",
Expand All @@ -37,23 +38,29 @@ export const RBTC: NetworkBaseAsset = {
},
}

export const OPTIMISTIC_ETH: NetworkBaseAsset = {
name: "Ether",
symbol: "ETH",
decimals: 18,
coinType: coinTypesByAssetSymbol.ETH,
export const OPTIMISTIC_ETH: NetworkBaseAsset & Required<CoinGeckoAsset> = {
...BASE_ASSETS_BY_CUSTOM_NAME.OPTIMISTIC_ETH,
...ETH_DATA,
contractAddress: "0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000",
metadata: {
coinGeckoID: "ethereum",
tokenLists: [],
websiteURL: "https://ethereum.org",
},
}

export const MATIC: NetworkBaseAsset = {
name: "Matic Token",
symbol: "MATIC",
decimals: 18,
export const ARBITRUM_ONE_ETH: NetworkBaseAsset & Required<CoinGeckoAsset> = {
...BASE_ASSETS_BY_CUSTOM_NAME.ARBITRUM_ONE_ETH,
...ETH_DATA,
}

export const ARBITRUM_NOVA_ETH: NetworkBaseAsset & Required<CoinGeckoAsset> = {
...BASE_ASSETS_BY_CUSTOM_NAME.ARBITRUM_NOVA_ETH,
...ETH_DATA,
}

export const GOERLI_ETH: NetworkBaseAsset & Required<CoinGeckoAsset> = {
...BASE_ASSETS_BY_CUSTOM_NAME.GOERLI_ETH,
...ETH_DATA,
}

export const MATIC: NetworkBaseAsset & Required<CoinGeckoAsset> = {
...BASE_ASSETS_BY_CUSTOM_NAME.MATIC,
coinType: coinTypesByAssetSymbol.MATIC,
contractAddress: "0x0000000000000000000000000000000000001010",
metadata: {
Expand All @@ -63,10 +70,8 @@ export const MATIC: NetworkBaseAsset = {
},
}

export const AVAX: NetworkBaseAsset = {
name: "Avalanche",
symbol: "AVAX",
decimals: 18,
export const AVAX: NetworkBaseAsset & Required<CoinGeckoAsset> = {
...BASE_ASSETS_BY_CUSTOM_NAME.AVAX,
coinType: coinTypesByAssetSymbol.AVAX,
metadata: {
coinGeckoID: "avalanche-2",
Expand All @@ -75,10 +80,8 @@ export const AVAX: NetworkBaseAsset = {
},
}

export const BNB: NetworkBaseAsset = {
name: "Binance Coin",
symbol: "BNB",
decimals: 18,
export const BNB: NetworkBaseAsset & Required<CoinGeckoAsset> = {
...BASE_ASSETS_BY_CUSTOM_NAME.BNB,
coinType: coinTypesByAssetSymbol.BNB,
metadata: {
coinGeckoID: "binancecoin",
Expand All @@ -87,26 +90,14 @@ export const BNB: NetworkBaseAsset = {
},
}

export const BTC: NetworkBaseAsset = {
name: "Bitcoin",
symbol: "BTC",
decimals: 8,
coinType: coinTypesByAssetSymbol.BTC,
metadata: {
coinGeckoID: "bitcoin",
tokenLists: [],
websiteURL: "https://bitcoin.org",
},
}

export const BASE_ASSETS = [ETH, BTC, MATIC, RBTC, OPTIMISTIC_ETH, AVAX, BNB]

export const BASE_ASSETS_BY_SYMBOL = BASE_ASSETS.reduce<{
[assetSymbol: string]: NetworkBaseAsset
}>((acc, asset) => {
const newAcc = {
...acc,
}
newAcc[asset.symbol] = asset
return newAcc
}, {})
export const BUILT_IN_NETWORK_BASE_ASSETS = [
ETH,
MATIC,
RBTC,
OPTIMISTIC_ETH,
ARBITRUM_ONE_ETH,
ARBITRUM_NOVA_ETH,
GOERLI_ETH,
AVAX,
BNB,
]
1 change: 1 addition & 0 deletions background/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ export enum EarnStages {
export * from "./assets"
export * from "./currencies"
export * from "./networks"
export * from "./base-assets"
27 changes: 15 additions & 12 deletions background/constants/networks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { FeatureFlags, isEnabled } from "../features"
import { EVMNetwork, Network } from "../networks"
import { AVAX, BNB, BTC, ETH, MATIC, OPTIMISTIC_ETH, RBTC } from "./currencies"
import { EVMNetwork } from "../networks"
import {
ARBITRUM_NOVA_ETH,
ARBITRUM_ONE_ETH,
AVAX,
BNB,
ETH,
GOERLI_ETH,
MATIC,
OPTIMISTIC_ETH,
RBTC,
} from "./currencies"

export const ETHEREUM: EVMNetwork = {
name: "Ethereum",
Expand Down Expand Up @@ -28,7 +38,7 @@ export const POLYGON: EVMNetwork = {

export const ARBITRUM_ONE: EVMNetwork = {
name: "Arbitrum",
baseAsset: ETH,
baseAsset: ARBITRUM_ONE_ETH,
chainID: "42161",
family: "EVM",
coingeckoPlatformID: "arbitrum-one",
Expand All @@ -52,7 +62,7 @@ export const BINANCE_SMART_CHAIN: EVMNetwork = {

export const ARBITRUM_NOVA: EVMNetwork = {
name: "Arbitrum Nova",
baseAsset: ETH,
baseAsset: ARBITRUM_NOVA_ETH,
chainID: "42170",
family: "EVM",
coingeckoPlatformID: "arbitrum-nova",
Expand All @@ -68,19 +78,12 @@ export const OPTIMISM: EVMNetwork = {

export const GOERLI: EVMNetwork = {
name: "Goerli",
baseAsset: ETH,
baseAsset: GOERLI_ETH,
chainID: "5",
family: "EVM",
coingeckoPlatformID: "ethereum",
}

export const BITCOIN: Network = {
name: "Bitcoin",
baseAsset: BTC,
family: "BTC",
coingeckoPlatformID: "bitcoin",
}

export const DEFAULT_NETWORKS = [
ETHEREUM,
POLYGON,
Expand Down
1 change: 1 addition & 0 deletions background/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const RuntimeFlag = {
SUPPORT_NFT_TAB: process.env.SUPPORT_NFT_TAB === "true",
SUPPORT_NFT_SEND: process.env.SUPPORT_NFT_SEND === "true",
SUPPORT_WALLET_CONNECT: process.env.SUPPORT_WALLET_CONNECT === "true",
SUPPORT_SWAP_QUOTE_REFRESH: process.env.SUPPORT_SWAP_QUOTE_REFRESH === "true",
SUPPORT_ABILITIES: process.env.SUPPORT_ABILITIES === "true",
SUPPORT_CUSTOM_NETWORKS: process.env.SUPPORT_CUSTOM_NETWORKS === "true",
SUPPORT_CUSTOM_RPCS: process.env.SUPPORT_CUSTOM_RPCS === "true",
Expand Down
2 changes: 1 addition & 1 deletion background/lib/alchemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function getAssetTransfers(
fromBlock: number,
toBlock?: number,
order: "asc" | "desc" = "desc",
maxCount = 1000
maxCount = 25
): Promise<AssetTransfer[]> {
const { address: account, network } = addressOnNetwork

Expand Down
2 changes: 2 additions & 0 deletions background/lib/asset-similarity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export function findClosestAssetIndex(
export function mergeAssets(asset1: AnyAsset, asset2: AnyAsset): AnyAsset {
return {
...asset1,
...("coinType" in asset1 ? { coinType: asset1.coinType } : {}),
...("coinType" in asset2 ? { coinType: asset2.coinType } : {}),
metadata: {
...asset1.metadata,
...asset2.metadata,
Expand Down
8 changes: 8 additions & 0 deletions background/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,16 @@ export function serializeLogs(): string {
return splitLogs
})

const HOUR = 1000 * 60 * 60
return (
logEntries
// Only grab logs from the past hour
.filter((logLine) => {
return (
new Date(logLine.substring(1, iso8601Length)) >
new Date(Date.now() - HOUR)
)
})
// Sort by date.
.sort((a, b) => {
return a
Expand Down
Loading

0 comments on commit 9eaa7e4

Please sign in to comment.