Skip to content

Commit

Permalink
Merge branch 'main' into feat/CP-8359_create_chaingagnostiv
Browse files Browse the repository at this point in the history
  • Loading branch information
vvava authored Aug 21, 2024
2 parents d764839 + a5af551 commit 2ab0518
Show file tree
Hide file tree
Showing 61 changed files with 1,820 additions and 437 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/e2e_testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
if: ${{ !github.event.pull_request.draft }}
environment: alpha
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Checkout extension
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Create .npmrc
run: echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}' >> .npmrc
- name: Create env file
Expand Down Expand Up @@ -57,6 +57,9 @@ jobs:
- name: Remove onboarding video
run: |
rm -fv ./dist/images/core-ext-hero-hq.webm
- name: Add extension key to manifest file
run: |
echo $(cat ./dist/manifest.json | jq '.key = "${{ secrets.EXTENSION_PUBLIC_KEY }}"') > ./dist/manifest.json
- name: Generate a zip
run: yarn zip
- name: Output extension file version before renaming
Expand Down
32 changes: 18 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@
"sentry": "node sentryscript.js"
},
"dependencies": {
"@avalabs/vm-module-types": "0.1.0",
"@avalabs/avalanchejs": "4.0.5",
"@avalabs/bitcoin-module": "0.1.4",
"@avalabs/bridge-unified": "2.1.0",
"@avalabs/core-bridge-sdk": "3.0.0",
"@avalabs/core-chains-sdk": "3.0.0",
"@avalabs/core-coingecko-sdk": "3.0.0",
"@avalabs/core-covalent-sdk": "3.0.0",
"@avalabs/core-etherscan-sdk": "3.0.0",
"@avalabs/core-snowtrace-sdk": "3.0.0",
"@avalabs/core-token-prices-sdk": "3.0.0",
"@avalabs/core-utils-sdk": "3.0.0",
"@avalabs/core-wallets-sdk": "3.0.0",
"@avalabs/glacier-sdk": "2.8.0-alpha.188",
"@avalabs/core-bridge-sdk": "3.0.1-alpha.1",
"@avalabs/core-chains-sdk": "3.0.1-alpha.1",
"@avalabs/core-coingecko-sdk": "3.0.1-alpha.1",
"@avalabs/core-covalent-sdk": "3.0.1-alpha.1",
"@avalabs/core-etherscan-sdk": "3.0.1-alpha.1",
"@avalabs/core-snowtrace-sdk": "3.0.1-alpha.1",
"@avalabs/core-token-prices-sdk": "3.0.1-alpha.1",
"@avalabs/core-utils-sdk": "3.0.1-alpha.1",
"@avalabs/core-wallets-sdk": "3.0.1-alpha.1",
"@avalabs/glacier-sdk": "3.0.1-alpha.1",
"@avalabs/hw-app-avalanche": "0.14.1",
"@avalabs/core-k2-components": "4.18.0-alpha.44",
"@avalabs/types": "2.8.0-alpha.188",
"@avalabs/core-k2-components": "4.18.0-alpha.47",
"@avalabs/types": "3.0.1-alpha.1",
"@avalabs/vm-module-types": "0.1.4",
"@blockaid/client": "0.10.0",
"@coinbase/cbpay-js": "1.6.0",
"@cubist-labs/cubesigner-sdk": "0.3.28",
Expand Down Expand Up @@ -238,7 +239,10 @@
"@avalabs/vm-module-types>@avalabs/wallets-sdk>hdkey>secp256k1": false,
"@avalabs/core-bridge-sdk>@avalabs/core-wallets-sdk>@avalabs/hw-app-avalanche>@ledgerhq/hw-app-eth>@ledgerhq/domain-service>eip55>keccak": false,
"@avalabs/core-bridge-sdk>@avalabs/core-wallets-sdk>@ledgerhq/hw-app-btc>bitcoinjs-lib>bip32>tiny-secp256k1": false,
"@avalabs/core-bridge-sdk>@avalabs/core-wallets-sdk>hdkey>secp256k1": false
"@avalabs/core-bridge-sdk>@avalabs/core-wallets-sdk>hdkey>secp256k1": false,
"@avalabs/bitcoin-module>@avalabs/core-wallets-sdk>@avalabs/hw-app-avalanche>@ledgerhq/hw-app-eth>@ledgerhq/domain-service>eip55>keccak": false,
"@avalabs/bitcoin-module>@avalabs/core-wallets-sdk>@ledgerhq/hw-app-btc>bitcoinjs-lib>bip32>tiny-secp256k1": false,
"@avalabs/bitcoin-module>@avalabs/core-wallets-sdk>hdkey>secp256k1": false
}
}
}
1 change: 1 addition & 0 deletions src/background/connections/extensionConnection/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export enum ExtensionRequest {
SEND_SUBMIT = 'send_submit',

SETTINGS_GET = 'settings_get',
SETTINGS_UPDATE_COLLECTIBLES_VISIBILITY = 'settings_update_collectibles_visibility',
SETTINGS_UPDATE_CURRENCY = 'settings_update_currency',
SETTINGS_UPDATE_SHOW_NO_BALANCE = 'settings_update_show_no_balance',
SETTINGS_UPDATE_THEME = 'settings_update_theme',
Expand Down
5 changes: 5 additions & 0 deletions src/background/connections/extensionConnection/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { GetWalletDetailsHandler } from '@src/background/services/wallet/handler
import { registry } from 'tsyringe';
import { UpdateCurrencyHandler } from '../../services/settings/handlers/updateCurrencySelection';
import { UpdateTokensVisiblityHandler } from '../../services/settings/handlers/updateTokensVisibility';
import { UpdateCollectiblesVisibilityHandler } from '../../services/settings/handlers/updateCollectiblesVisibility';
import { NetworksUpdatedEvents } from '@src/background/services/network/events/networksUpdatedEvent';
import { NetworkUpdatedEvents } from '@src/background/services/network/events/networkUpdatedEvent';
import { UpdateBalancesForNetworkHandler } from '@src/background/services/balances/handlers/updateBalancesForNetwork';
Expand Down Expand Up @@ -235,6 +236,10 @@ import { UnifiedBridgeTrackTransfer } from '@src/background/services/unifiedBrid
{ token: 'ExtensionRequestHandler', useToken: UpdateCurrencyHandler },
{ token: 'ExtensionRequestHandler', useToken: UpdateThemeHandler },
{ token: 'ExtensionRequestHandler', useToken: UpdateTokensVisiblityHandler },
{
token: 'ExtensionRequestHandler',
useToken: UpdateCollectiblesVisibilityHandler,
},
{ token: 'ExtensionRequestHandler', useToken: ResetExtensionStateHandler },
{ token: 'ExtensionRequestHandler', useToken: GetTokenPriceHandler },
{ token: 'ExtensionRequestHandler', useToken: GetHistoryHandler },
Expand Down
3 changes: 3 additions & 0 deletions src/background/runtime/BackgroundRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { singleton } from 'tsyringe';
import { LockService } from '@src/background/services/lock/LockService';
import { OnboardingService } from '@src/background/services/onboarding/OnboardingService';
import { BridgeService } from '@src/background/services/bridge/BridgeService';
import ModuleManager from '../vmModules/ModuleManager';

@singleton()
export class BackgroundRuntime {
Expand All @@ -20,6 +21,8 @@ export class BackgroundRuntime {
this.registerInpageScript();
this.addContextMenus();

ModuleManager.init();

// Activate services which need to run all the or are required for bootstraping the wallet state
this.connectionService.activate();
this.lockService.activate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('src/background/services/balances/BalancesServiceAVM.ts', () => {
showTokensWithoutBalances: false,
theme: ThemeVariant.DARK,
tokensVisibility: {},
collectiblesVisibility: {},
analyticsConsent: AnalyticsConsent.Approved,
language: Languages.EN,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('src/background/services/balances/BalancesServicePVM.ts', () => {
showTokensWithoutBalances: false,
theme: ThemeVariant.DARK,
tokensVisibility: {},
collectiblesVisibility: {},
analyticsConsent: AnalyticsConsent.Approved,
language: Languages.EN,
});
Expand Down
1 change: 1 addition & 0 deletions src/background/services/balances/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface TokenBalanceDataWithDecimals extends TokenBalanceData {
decimals: number;
}

// TODO: remove TokenType once all VM modules are integrated (it should no longer be needed at this point)
export enum TokenType {
NATIVE = 'NATIVE',
ERC20 = 'ERC20',
Expand Down
4 changes: 3 additions & 1 deletion src/background/services/balances/nft/utils/isNFT.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { TokenType as VMModulesTokenType } from '@avalabs/vm-module-types';

import { TokenType } from '../../models';

export function isNFT(tokenType: TokenType) {
export function isNFT(tokenType: TokenType | VMModulesTokenType) {
return tokenType === TokenType.ERC721 || tokenType === TokenType.ERC1155;
}
2 changes: 2 additions & 0 deletions src/background/services/history/HistoryService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ describe('src/background/services/history/HistoryService.ts', () => {
const result = await service.getTxHistory({
...network1,
vmName: NetworkVMType.BITCOIN,
caipId: 'bip122:000000000019d6689c085ae165831e93',
});
expect(btcHistoryServiceMock.getHistory).toHaveBeenCalledTimes(1);
expect(result).toEqual([btcTxHistoryItem]);
Expand All @@ -188,6 +189,7 @@ describe('src/background/services/history/HistoryService.ts', () => {
const result = await service.getTxHistory({
...network1,
vmName: NetworkVMType.BITCOIN,
caipId: 'bip122:000000000019d6689c085ae165831e93',
});
expect(btcHistoryServiceMock.getHistory).toHaveBeenCalledTimes(1);
expect(result).toEqual([btcTxHistoryItem]);
Expand Down
4 changes: 2 additions & 2 deletions src/background/services/history/HistoryService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { singleton } from 'tsyringe';
import { NetworkVMType } from '@avalabs/core-chains-sdk';

import { Network } from '../network/models';
import { NetworkWithCaipId } from '../network/models';
import { GlacierService } from '../glacier/GlacierService';
import { isPchainNetwork } from '../network/utils/isAvalanchePchainNetwork';
import { isXchainNetwork } from '../network/utils/isAvalancheXchainNetwork';
Expand All @@ -24,7 +24,7 @@ export class HistoryService {
private historyServicePVM: HistoryServicePVM
) {}

async getTxHistory(network: Network) {
async getTxHistory(network: NetworkWithCaipId) {
const isSupportedNetwork = await this.glacierService.isNetworkSupported(
network.chainId
);
Expand Down
111 changes: 32 additions & 79 deletions src/background/services/history/HistoryServiceBTC.ts
Original file line number Diff line number Diff line change
@@ -1,103 +1,56 @@
import { Blockchain } from '@avalabs/core-bridge-sdk';
import {
BITCOIN_NETWORK,
Network,
NetworkVMType,
} from '@avalabs/core-chains-sdk';
import { BitcoinHistoryTx, BitcoinProvider } from '@avalabs/core-wallets-sdk';
import { getExplorerAddress } from '@src/utils/getExplorerAddress';
import { NetworkVMType } from '@avalabs/core-chains-sdk';
import { singleton } from 'tsyringe';
import { AccountsService } from '../accounts/AccountsService';
import { TokenType } from '../balances/models';
import { NetworkService } from '../network/NetworkService';
import { HistoryServiceBridgeHelper } from './HistoryServiceBridgeHelper';
import { TransactionType, TxHistoryItem } from './models';
import { getProviderForNetwork } from '@src/utils/network/getProviderForNetwork';
import ModuleManager from '@src/background/vmModules/ModuleManager';
import { NetworkWithCaipId } from '../network/models';
import sentryCaptureException, {
SentryExceptionTypes,
} from '@src/monitoring/sentryCaptureException';

@singleton()
export class HistoryServiceBTC {
constructor(
private networkService: NetworkService,
private accountsService: AccountsService,
private bridgeHistoryHelperService: HistoryServiceBridgeHelper
) {}

private bitcoinAmount(amount: number, demonimation: number) {
if (amount < 0) {
amount = amount * -1;
}
return (amount / Math.pow(10, demonimation)).toString();
}

private txHistoryItemConverter(
tx: BitcoinHistoryTx,
network: Network
): TxHistoryItem {
const userAddress = this.accountsService.activeAccount?.addressBTC
? this.accountsService.activeAccount?.addressBTC
: '';
const txAddress = tx.addresses[0] ? tx.addresses[0] : '';
const denomination = BITCOIN_NETWORK.networkToken.decimals;
const isBridge = this.bridgeHistoryHelperService.isBridgeTransactionBTC(tx);
const type = isBridge
? TransactionType.BRIDGE
: tx.isSender
? TransactionType.SEND
: TransactionType.RECEIVE;
return {
isBridge,
isIncoming: !tx.isSender,
isOutgoing: tx.isSender,
isContractCall: false,
timestamp: new Date(tx.receivedTime * 1000).toISOString(),
hash: tx.hash,
isSender: tx.isSender,
from: tx.isSender ? userAddress : txAddress,
to: tx.isSender ? txAddress : userAddress,
tokens: [
{
decimal: denomination.toString(),
name: BITCOIN_NETWORK.networkToken.name,
symbol: BITCOIN_NETWORK.networkToken.symbol,
amount: this.bitcoinAmount(tx.amount, denomination),
type: TokenType.NATIVE,
},
],
gasUsed: tx.fee.toString(),
explorerLink: getExplorerAddress(
Blockchain.BITCOIN,
tx.hash,
network.chainId === BITCOIN_NETWORK.chainId
),
chainId: network.chainId.toString(),
type,
};
}

async getHistory(network: Network): Promise<TxHistoryItem[]> {
async getHistory(network: NetworkWithCaipId): Promise<TxHistoryItem[]> {
if (network?.vmName !== NetworkVMType.BITCOIN) {
return [];
}
const account = this.accountsService.activeAccount?.addressBTC;
const address = this.accountsService.activeAccount?.addressBTC;

if (!account) {
if (!address) {
return [];
}
const provider = getProviderForNetwork(network) as BitcoinProvider;

try {
const txHistory: BitcoinHistoryTx[] = await provider.getTxHistory(
account
);
const results: TxHistoryItem[] = [];
txHistory.forEach((tx) => {
const converted = this.txHistoryItemConverter(tx, network);
if (converted) {
results.push(converted);
}
const module = await ModuleManager.loadModuleByNetwork(network);
const { transactions } = await module.getTransactionHistory({
address,
network,
});

return transactions.map((tx) => {
const isBridge = this.bridgeHistoryHelperService.isBridgeTransactionBTC(
[tx.from, tx.to]
);

return {
...tx,
// BitcoinModule is not able to recognize bridge txs at the moment, so we need to do it here.
isBridge,
type: isBridge
? TransactionType.BRIDGE
: tx.isSender
? TransactionType.SEND
: TransactionType.RECEIVE,
};
});
return results;
} catch (error) {
} catch (error: any) {
sentryCaptureException(error, SentryExceptionTypes.INTERNAL_ERROR);
return [];
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/background/services/history/HistoryServiceBridgeHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ETHEREUM_ADDRESS } from '@src/utils/bridgeTransactionUtils';
import { BridgeService } from '../bridge/BridgeService';
import { BitcoinHistoryTx } from '@avalabs/core-wallets-sdk';
import { singleton } from 'tsyringe';
import { Erc20Tx } from '@avalabs/core-snowtrace-sdk';
import { Network } from '@avalabs/core-chains-sdk';
Expand Down Expand Up @@ -77,7 +76,7 @@ export class HistoryServiceBridgeHelper {
* config.criticalBitcoin?.walletAddresses.btc or
* config.criticalBitcoin?.walletAddresses.avalanche
*/
isBridgeTransactionBTC(tx: BitcoinHistoryTx): boolean {
isBridgeTransactionBTC(addresses: string[]): boolean {
const config = this.bridgeService.bridgeConfig;
const bitcoinWalletAddresses =
config?.config?.criticalBitcoin?.walletAddresses;
Expand All @@ -86,7 +85,7 @@ export class HistoryServiceBridgeHelper {
return false;
}

return tx.addresses.some((address) => {
return addresses.some((address) => {
return [
bitcoinWalletAddresses.btc,
bitcoinWalletAddresses.avalanche,
Expand Down
4 changes: 3 additions & 1 deletion src/background/services/history/HistoryServiceETH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export class HistoryServiceETH {

// Sort by timestamp
const joined = [...filteredNormalTxs, ...erc20Hist];
return joined.sort((a, b) => b.timestamp.localeCompare(a.timestamp));
return joined.sort((a, b) =>
(b.timestamp as string).localeCompare(a.timestamp as string)
);
}
}
4 changes: 2 additions & 2 deletions src/background/services/history/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
RichAddress,
XChainTransactionType,
} from '@avalabs/glacier-sdk';
import { TokenType } from '../balances/models';
import { TokenType } from '@avalabs/vm-module-types';

export interface TxHistoryItemToken {
decimal?: string;
Expand All @@ -22,7 +22,7 @@ export interface TxHistoryItem {
isIncoming: boolean;
isOutgoing: boolean;
isSender: boolean;
timestamp: string;
timestamp: string | number;
hash: string;
from: string;
to: string;
Expand Down
2 changes: 1 addition & 1 deletion src/background/services/network/NetworkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ export class NetworkService implements OnLock, OnStorageReady {
return getProviderForNetwork(network) as JsonRpcBatchInternal;
}

async getBitcoinNetwork(): Promise<Network> {
async getBitcoinNetwork(): Promise<NetworkWithCaipId> {
const activeNetworks = await this.activeNetworks.promisify();
const network =
activeNetworks[ChainId.BITCOIN] ??
Expand Down
Loading

0 comments on commit 2ab0518

Please sign in to comment.