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

chore: upgrade unified bridge SDK #40

Merged
merged 27 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
34a8da0
chore: upgrade unified bridge sdk
meeh0w Sep 6, 2024
814151c
chore: make extension compatible with new UnifiedBridge SDK
meeh0w Sep 10, 2024
d774bfa
chore: implement schema migration for pending CCTP transfers
meeh0w Sep 10, 2024
d408cc0
fix: schema migration bigint support
meeh0w Sep 10, 2024
8608f37
chore: cleanup translations
meeh0w Sep 10, 2024
2fe74b3
test: update failing tests
meeh0w Sep 10, 2024
af180f2
refactor: update consumer-sdk, isBridgeAddress -> isBridgeTx
meeh0w Sep 26, 2024
4ba7f21
Merge remote-tracking branch 'origin/main' into feat/ictt-2
meeh0w Sep 27, 2024
50d4310
test: update HistoryService tests
meeh0w Oct 2, 2024
7743316
Merge remote-tracking branch 'origin/main' into feat/ictt
meeh0w Oct 10, 2024
8782815
chore: use analyzeTx() from UnifiedBridge SDK
meeh0w Oct 8, 2024
4a57a94
Merge remote-tracking branch 'origin/main' into feat/ictt
meeh0w Oct 11, 2024
bf64965
chore: another sdk update
meeh0w Oct 11, 2024
727961a
chore: type fixes
meeh0w Oct 11, 2024
186e7fd
chore: types & test fixes
meeh0w Oct 11, 2024
4e0dc09
chore: update translations
meeh0w Oct 11, 2024
1f02da9
chore: update vm modules
meeh0w Oct 15, 2024
517f3e3
Merge remote-tracking branch 'origin/main' into feat/ictt
meeh0w Oct 15, 2024
9494ed4
chore: update sdks, disable Avalanche Bridge for now
meeh0w Oct 15, 2024
bd721dc
Merge remote-tracking branch 'origin/main' into feat/ictt
meeh0w Oct 18, 2024
ce3b826
chore: update vm sdks to 0.10.1
meeh0w Oct 22, 2024
e93ba1c
refactor: better name for isTxHistoryItem() util
meeh0w Oct 22, 2024
da600ae
test: missing tests for UnifiedBridgeService retry logic
meeh0w Oct 22, 2024
5bf2855
test: missing tests for UnifiedBridgeProvider
meeh0w Oct 22, 2024
e1871fe
Merge remote-tracking branch 'origin/main' into feat/ictt
meeh0w Oct 22, 2024
ca2b271
Merge remote-tracking branch 'origin/main' into feat/ictt
meeh0w Oct 24, 2024
b5591b5
chore: pin dependencies
meeh0w Oct 24, 2024
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
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@avalabs/avalanche-module": "0.11.2",
"@avalabs/avalanchejs": "4.1.0-alpha.7",
"@avalabs/bitcoin-module": "0.11.2",
"@avalabs/bridge-unified": "2.1.0",
"@avalabs/bridge-unified": "0.0.0-feat-ictt-configs-20241009072139",
"@avalabs/core-bridge-sdk": "3.1.0-alpha.10",
"@avalabs/core-chains-sdk": "3.1.0-alpha.10",
"@avalabs/core-coingecko-sdk": "3.1.0-alpha.10",
Expand Down Expand Up @@ -256,7 +256,10 @@
"@avalabs/bitcoin-module>@avalabs/vm-module-types>@avalabs/core-wallets-sdk>hdkey>secp256k1": false,
"@avalabs/avalanche-module>@avalabs/core-wallets-sdk>@avalabs/hw-app-avalanche>@ledgerhq/hw-app-eth>@ledgerhq/domain-service>eip55>keccak": false,
"@avalabs/avalanche-module>@avalabs/core-wallets-sdk>@ledgerhq/hw-app-btc>bitcoinjs-lib>bip32>tiny-secp256k1": false,
"@avalabs/avalanche-module>@avalabs/core-wallets-sdk>hdkey>secp256k1": false
"@avalabs/avalanche-module>@avalabs/core-wallets-sdk>hdkey>secp256k1": false,
"@avalabs/avalanche-module>@avalabs/vm-module-types>@avalabs/core-wallets-sdk>@avalabs/hw-app-avalanche>@ledgerhq/hw-app-eth>@ledgerhq/domain-service>eip55>keccak": false,
"@avalabs/avalanche-module>@avalabs/vm-module-types>@avalabs/core-wallets-sdk>@ledgerhq/hw-app-btc>bitcoinjs-lib>bip32>tiny-secp256k1": false,
"@avalabs/avalanche-module>@avalabs/vm-module-types>@avalabs/core-wallets-sdk>hdkey>secp256k1": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const RESTRICTED_METHODS = Object.freeze([] as string[]);
* "method not found" error.
*/
export const UNRESTRICTED_METHODS = Object.freeze([
'bitcoin_signTransaction',
'eth_accounts',
'eth_requestAccounts',
'eth_baseFee',
Expand Down
47 changes: 30 additions & 17 deletions src/background/services/history/HistoryService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TxHistoryItem } from './models';
import { TokenType } from '@avalabs/vm-module-types';
import { TransactionType } from '@avalabs/vm-module-types';
import { ETHEREUM_ADDRESS } from '@src/utils/bridgeTransactionUtils';
import { BridgeType } from '@avalabs/bridge-unified';

describe('src/background/services/history/HistoryService.ts', () => {
let service: HistoryService;
Expand Down Expand Up @@ -37,17 +38,14 @@ describe('src/background/services/history/HistoryService.ts', () => {
addressAVM: 'addressBtc',
},
} as any;
const bridgeHistoryHelperServiceMock = {
isBridgeTransactionBTC: jest.fn(),
} as any;
const unifiedBridgeServiceMock = {
state: {
addresses: [],
},
analyzeTx: jest.fn(),
} as any;

const txHistoryItem: TxHistoryItem = {
isBridge: false,
bridgeAnalysis: {
isBridgeTx: false,
},
isContractCall: true,
isIncoming: false,
isOutgoing: true,
Expand All @@ -72,7 +70,9 @@ describe('src/background/services/history/HistoryService.ts', () => {
};

const btcTxHistoryItem: TxHistoryItem = {
isBridge: false,
bridgeAnalysis: {
isBridgeTx: false,
},
isContractCall: true,
isIncoming: false,
isOutgoing: true,
Expand Down Expand Up @@ -102,9 +102,12 @@ describe('src/background/services/history/HistoryService.ts', () => {
service = new HistoryService(
moduleManagereMock,
accountsServiceMock,
bridgeHistoryHelperServiceMock,
unifiedBridgeServiceMock
);

jest
.mocked(unifiedBridgeServiceMock.analyzeTx)
.mockReturnValue({ isBridgeTx: false });
});

it('should return empty array when network is not supported', async () => {
Expand Down Expand Up @@ -137,9 +140,6 @@ describe('src/background/services/history/HistoryService.ts', () => {
return { transactions: [btcTxHistoryItem] };
}),
});
jest
.mocked(bridgeHistoryHelperServiceMock.isBridgeTransactionBTC)
.mockReturnValue(false);
const result = await service.getTxHistory({
...network1,
vmName: NetworkVMType.BITCOIN,
Expand All @@ -153,18 +153,21 @@ describe('src/background/services/history/HistoryService.ts', () => {
return { transactions: [btcTxHistoryItem] };
}),
});
jest
.mocked(bridgeHistoryHelperServiceMock.isBridgeTransactionBTC)
.mockReturnValue(true);
const result = await service.getTxHistory({
...network1,
vmName: NetworkVMType.BITCOIN,
caipId: 'bip122:000000000019d6689c085ae165831e93',
});

expect(result).toEqual([{ ...btcTxHistoryItem, isBridge: true }]);
expect(result).toEqual([
{ ...btcTxHistoryItem, bridgeAnalysis: { isBridgeTx: false } },
]);
});
it('should return results with an ETH bridge transaction', async () => {
jest.mocked(unifiedBridgeServiceMock.analyzeTx).mockReturnValue({
isBridgeTx: true,
bridgeType: BridgeType.AVALANCHE_EVM,
});
jest.mocked(moduleManagereMock.loadModuleByNetwork).mockResolvedValue({
getTransactionHistory: jest.fn(() => {
return {
Expand All @@ -183,10 +186,20 @@ describe('src/background/services/history/HistoryService.ts', () => {
caipId: 'caip',
});
expect(result).toEqual([
{ ...txHistoryItem, isBridge: true, from: ETHEREUM_ADDRESS },
{
...txHistoryItem,
bridgeAnalysis: {
bridgeType: BridgeType.AVALANCHE_EVM,
isBridgeTx: true,
},
from: ETHEREUM_ADDRESS,
},
]);
});
it('should return results with an pchain transaction', async () => {
jest
.mocked(unifiedBridgeServiceMock.analyzeTx)
.mockReturnValue({ isBridgeTx: false });
jest.mocked(moduleManagereMock.loadModuleByNetwork).mockResolvedValue({
getTransactionHistory: jest.fn(() => {
return {
Expand Down
47 changes: 20 additions & 27 deletions src/background/services/history/HistoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ import { NetworkWithCaipId } from '../network/models';
import { ModuleManager } from '@src/background/vmModules/ModuleManager';
import { AccountsService } from '../accounts/AccountsService';
import { TxHistoryItem } from './models';
import { HistoryServiceBridgeHelper } from './HistoryServiceBridgeHelper';
import { Transaction } from '@avalabs/vm-module-types';
import { ETHEREUM_ADDRESS } from '@src/utils/bridgeTransactionUtils';
import { UnifiedBridgeService } from '../unifiedBridge/UnifiedBridgeService';
import { resolve } from '@src/utils/promiseResolver';
import sentryCaptureException, {
SentryExceptionTypes,
} from '@src/monitoring/sentryCaptureException';
import { AnalyzeTxParams } from '@avalabs/bridge-unified';

@singleton()
export class HistoryService {
constructor(
private moduleManager: ModuleManager,
private accountsService: AccountsService,
private bridgeHistoryHelperService: HistoryServiceBridgeHelper,
private unifiedBridgeService: UnifiedBridgeService
) {}

Expand Down Expand Up @@ -52,25 +50,31 @@ export class HistoryService {
});

const txHistoryItem = transactions.map((transaction) => {
const isBridge = this.#getIsBirdge(network, transaction);
const result = this.#analyze(network, transaction);
const vmType = network.vmName;
return { ...transaction, vmType, isBridge };
return {
...transaction,
vmType,
bridgeAnalysis: result,
};
}) as TxHistoryItem[];

return txHistoryItem;
}

#getIsBirdge(network: NetworkWithCaipId, transaction: Transaction) {
if (network.vmName === NetworkVMType.BITCOIN) {
return this.bridgeHistoryHelperService.isBridgeTransactionBTC([
transaction.from,
transaction.to,
]);
}
return (
this.#isBridgeAddress(transaction.from) ||
this.#isBridgeAddress(transaction.to)
);
#analyze(network: NetworkWithCaipId, transaction: Transaction) {
const params: AnalyzeTxParams = {
from: transaction.from as `0x${string}`,
to: transaction.to as `0x${string}`,
chainId: network.caipId,
tokenTransfers: transaction.tokens.map((transfer) => ({
symbol: transfer.symbol,
from: (transfer.from?.address ?? transaction.from) as `0x${string}`,
to: (transfer.to?.address ?? transaction.to) as `0x${string}`,
})),
};

return this.unifiedBridgeService.analyzeTx(params);
}

#getAddress(network: NetworkWithCaipId) {
Expand All @@ -89,15 +93,4 @@ export class HistoryService {
return undefined;
}
}

#isBridgeAddress(address?: string) {
if (!address) {
return false;
}

return [
ETHEREUM_ADDRESS,
...this.unifiedBridgeService.state.addresses,
].includes(address.toLowerCase());
}
}
97 changes: 0 additions & 97 deletions src/background/services/history/HistoryServiceBridgeHelper.ts

This file was deleted.

55 changes: 5 additions & 50 deletions src/background/services/history/models.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,7 @@
import {
NetworkVMType,
Transaction,
TransactionType,
} from '@avalabs/vm-module-types';
import { AnalyzeTxResult } from '@avalabs/bridge-unified';
import { NetworkVMType, Transaction } from '@avalabs/vm-module-types';

export interface TxHistoryItem extends Transaction {
isBridge: boolean;
vmType?: NetworkVMType;
}

export const NonContractCallTypes = [
TransactionType.BRIDGE,
TransactionType.SEND,
TransactionType.RECEIVE,
TransactionType.TRANSFER,
];

export interface HistoryItemCategories {
isBridge: boolean;
isSwap: boolean;
isNativeSend: boolean;
isNativeReceive: boolean;
isNFTPurchase: boolean;
isApprove: boolean;
isTransfer: boolean;
isAirdrop: boolean;
isUnwrap: boolean;
isFillOrder: boolean;
isContractCall: boolean;
method: string;
type: TransactionType;
}

export interface SubnetHistoryItem {
hash: string;
status: number;
gasPrice: number;
gasUsed: number;
timestamp: number;
from: string;
to: string;
value: string;
method: string;
type: number;
block: number;
toContract?: {
name: string;
symbol: string;
decimals: number;
};
export interface TxHistoryItem<VMType = NetworkVMType> extends Transaction {
bridgeAnalysis: AnalyzeTxResult;
vmType?: VMType;
}
Loading
Loading