@avalabs/bitcoin-module 0.0.23 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +1 -1
  3. package/dist/index.cjs +4 -4
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.js +3 -3
  6. package/dist/index.js.map +1 -1
  7. package/package.json +10 -5
  8. package/.turbo/turbo-build.log +0 -22
  9. package/.turbo/turbo-lint.log +0 -4
  10. package/.turbo/turbo-test.log +0 -16
  11. package/CHANGELOG.md +0 -56
  12. package/jest.config.js +0 -10
  13. package/src/env.ts +0 -25
  14. package/src/handlers/get-address/get-address.ts +0 -37
  15. package/src/handlers/get-balances/get-balances.test.ts +0 -181
  16. package/src/handlers/get-balances/get-balances.ts +0 -110
  17. package/src/handlers/get-balances/index.ts +0 -1
  18. package/src/handlers/get-network-fee/get-network-fee.test.ts +0 -67
  19. package/src/handlers/get-network-fee/get-network-fee.ts +0 -34
  20. package/src/handlers/get-network-fee/index.ts +0 -1
  21. package/src/handlers/get-transaction-history/convert-btc-transaction.test.ts +0 -108
  22. package/src/handlers/get-transaction-history/convert-btc-transaction.ts +0 -36
  23. package/src/handlers/get-transaction-history/get-transaction-history.test.ts +0 -98
  24. package/src/handlers/get-transaction-history/get-transaction-history.ts +0 -23
  25. package/src/handlers/get-transaction-history/index.ts +0 -1
  26. package/src/index.ts +0 -1
  27. package/src/module.test.ts +0 -57
  28. package/src/module.ts +0 -77
  29. package/src/utils/extract-token-market-data.ts +0 -16
  30. package/src/utils/get-provider.test.ts +0 -55
  31. package/src/utils/get-provider.ts +0 -18
  32. package/tsconfig.jest.json +0 -7
  33. package/tsconfig.json +0 -14
  34. package/tsup.config.ts +0 -4
package/CHANGELOG.md DELETED
@@ -1,56 +0,0 @@
1
- # @avalabs/bitcoin-module
2
-
3
- ## 0.0.23
4
-
5
- ### Patch Changes
6
-
7
- - Updated dependencies [fbdefd2]
8
- - @avalabs/vm-module-types@0.0.23
9
-
10
- ## 0.0.22
11
-
12
- ### Patch Changes
13
-
14
- - @avalabs/vm-module-types@0.0.22
15
-
16
- ## 0.0.21
17
-
18
- ### Patch Changes
19
-
20
- - @avalabs/vm-module-types@0.0.21
21
-
22
- ## 0.0.20
23
-
24
- ### Patch Changes
25
-
26
- - 9bfa82d: Implement balance fetching for BitcoinModule
27
- - Updated dependencies [9bfa82d]
28
- - @avalabs/vm-module-types@0.0.20
29
-
30
- ## 0.0.19
31
-
32
- ### Patch Changes
33
-
34
- - Updated dependencies [5af458b]
35
- - @avalabs/vm-module-types@0.0.19
36
-
37
- ## 0.0.18
38
-
39
- ### Patch Changes
40
-
41
- - @avalabs/vm-module-types@0.0.18
42
-
43
- ## 0.0.17
44
-
45
- ### Patch Changes
46
-
47
- - Updated dependencies [3590edf]
48
- - @avalabs/vm-module-types@0.0.17
49
-
50
- ## 0.0.16
51
-
52
- ### Patch Changes
53
-
54
- - de9824c: feat: created bitcoin module
55
- - Updated dependencies [bc48457]
56
- - @avalabs/vm-module-types@0.0.16
package/jest.config.js DELETED
@@ -1,10 +0,0 @@
1
- /** @type {import('ts-jest').JestConfigWithTsJest} */
2
- export default {
3
- clearMocks: true,
4
- preset: 'ts-jest',
5
- testEnvironment: 'node',
6
- passWithNoTests: true,
7
- transform: {
8
- '.ts': ['ts-jest', { tsconfig: './tsconfig.jest.json' }],
9
- },
10
- };
package/src/env.ts DELETED
@@ -1,25 +0,0 @@
1
- import { Environment } from '@avalabs/vm-module-types';
2
-
3
- type Env = {
4
- glacierApiUrl: string;
5
- proxyApiUrl: string;
6
- };
7
-
8
- export const prodEnv: Env = {
9
- glacierApiUrl: 'https://glacier-api.avax.network',
10
- proxyApiUrl: 'https://proxy-api.avax.network',
11
- };
12
-
13
- export const devEnv: Env = {
14
- glacierApiUrl: 'https://glacier-api-dev.avax.network',
15
- proxyApiUrl: 'https://proxy-api-dev.avax.network',
16
- };
17
-
18
- export const getEnv = (environment: Environment): Env => {
19
- switch (environment) {
20
- case Environment.PRODUCTION:
21
- return prodEnv;
22
- case Environment.DEV:
23
- return devEnv;
24
- }
25
- };
@@ -1,37 +0,0 @@
1
- import type { GetAddressParams, GetAddressResponse } from '@avalabs/vm-module-types';
2
- import { getBech32AddressFromXPub, getBtcAddressFromPubKey } from '@avalabs/wallets-sdk';
3
- import { networks } from 'bitcoinjs-lib';
4
- import { NetworkVMType, WalletType } from '@avalabs/vm-module-types';
5
- import { rpcErrors } from '@metamask/rpc-errors';
6
-
7
- type GetAddress = Omit<GetAddressParams, 'xpubXP'>;
8
-
9
- export const getAddress = async ({
10
- accountIndex,
11
- xpub,
12
- isTestnet,
13
- walletType,
14
- }: GetAddress): Promise<GetAddressResponse> => {
15
- switch (walletType) {
16
- case WalletType.Mnemonic:
17
- case WalletType.Ledger:
18
- case WalletType.Keystone: {
19
- return {
20
- [NetworkVMType.BITCOIN]: getBech32AddressFromXPub(
21
- xpub,
22
- accountIndex,
23
- isTestnet ? networks.testnet : networks.bitcoin,
24
- ),
25
- };
26
- }
27
- case WalletType.LedgerLive:
28
- case WalletType.Seedless: {
29
- const pubKeyBuffer = Buffer.from(xpub, 'hex');
30
- return {
31
- [NetworkVMType.BITCOIN]: getBtcAddressFromPubKey(pubKeyBuffer, isTestnet ? networks.testnet : networks.bitcoin),
32
- };
33
- }
34
- default:
35
- throw rpcErrors.invalidParams(`Unsupported wallet type: ${walletType}`);
36
- }
37
- };
@@ -1,181 +0,0 @@
1
- import type { BitcoinProvider } from '@avalabs/wallets-sdk';
2
-
3
- import { getProvider } from '../../utils/get-provider';
4
- import { getBalances } from './get-balances';
5
- import { TokenType, type Network } from '@avalabs/vm-module-types';
6
- import { BN } from 'bn.js';
7
- import { TokenService } from '@internal/utils';
8
-
9
- jest.mock('../../utils/get-provider');
10
-
11
- const proxyApiUrl = 'https://proxy.api/';
12
-
13
- describe('get-balances', () => {
14
- const provider = { getUtxoBalance: jest.fn() } as unknown as BitcoinProvider;
15
- const nativeTokenId = 'btc-id';
16
- const network = {
17
- pricingProviders: {
18
- coingecko: {
19
- nativeTokenId,
20
- },
21
- },
22
- networkToken: {
23
- decimals: 8,
24
- symbol: 'BTC',
25
- name: 'Bitcoin',
26
- },
27
- isTestnet: false,
28
- } as const as Network;
29
-
30
- const mockedBalance = {
31
- balance: 15_000_000,
32
- balanceUnconfirmed: 5_000_000,
33
- utxos: [
34
- { txHash: 'utxo-1', index: 0, value: 10_000_000, blockHeight: 10, confirmations: 20 },
35
- { txHash: 'utxo-2', index: 1, value: 5_000_000, blockHeight: 15, confirmations: 5 },
36
- ],
37
- utxosUnconfirmed: [{ txHash: 'utxo-3', index: 2, value: 5_000_000, blockHeight: 20, confirmations: 0 }],
38
- };
39
-
40
- const marketData = {
41
- [nativeTokenId]: {
42
- USD: {
43
- price: 50_000,
44
- marketCap: 1_500_000_000_000,
45
- vol24: 500_000_000_000,
46
- change24: 0.01,
47
- },
48
- },
49
- };
50
-
51
- beforeEach(() => {
52
- jest.mocked(provider.getUtxoBalance).mockResolvedValue(mockedBalance);
53
- jest.mocked(getProvider).mockReturnValue(provider);
54
-
55
- jest.spyOn(TokenService.prototype, 'getSimplePrice').mockResolvedValue(marketData);
56
- });
57
-
58
- it('should build the provider and use it', async () => {
59
- await getBalances({
60
- addresses: [],
61
- network: {
62
- ...network,
63
- isTestnet: true,
64
- },
65
- proxyApiUrl,
66
- });
67
-
68
- expect(getProvider).toHaveBeenCalledWith({ isTestnet: true, proxyApiUrl });
69
-
70
- await getBalances({
71
- addresses: [],
72
- network: {
73
- ...network,
74
- isTestnet: false,
75
- },
76
- proxyApiUrl: 'https://proxy-dev.api/',
77
- });
78
-
79
- expect(getProvider).toHaveBeenCalledWith({ isTestnet: false, proxyApiUrl: 'https://proxy-dev.api/' });
80
- });
81
-
82
- it('should call getUtxoBalance() method', async () => {
83
- await getBalances({
84
- addresses: ['first-address'],
85
- network,
86
- proxyApiUrl,
87
- });
88
-
89
- expect(provider.getUtxoBalance).toHaveBeenCalledWith('first-address', undefined);
90
- });
91
-
92
- it('uses withScripts option when requested', async () => {
93
- await getBalances({
94
- addresses: ['first-address'],
95
- network,
96
- proxyApiUrl,
97
- withScripts: true,
98
- });
99
-
100
- expect(provider.getUtxoBalance).toHaveBeenCalledWith('first-address', true);
101
- });
102
-
103
- describe('when no currency is passed', () => {
104
- it('does not call the token service', async () => {
105
- jest.spyOn(TokenService.prototype, 'getSimplePrice');
106
-
107
- await getBalances({
108
- addresses: ['first-address'],
109
- network,
110
- proxyApiUrl,
111
- });
112
-
113
- expect(TokenService.prototype.getSimplePrice).not.toHaveBeenCalled();
114
- });
115
-
116
- it('does not return the price-related information', async () => {
117
- expect(
118
- await getBalances({
119
- addresses: ['first-address'],
120
- network,
121
- proxyApiUrl,
122
- }),
123
- ).toEqual({
124
- 'first-address': {
125
- BTC: {
126
- ...network.networkToken,
127
- utxos: mockedBalance.utxos,
128
- utxosUnconfirmed: mockedBalance.utxosUnconfirmed,
129
- coingeckoId: network.pricingProviders?.coingecko?.nativeTokenId,
130
- type: TokenType.NATIVE,
131
- balance: new BN(mockedBalance.balance, 8),
132
- balanceDisplayValue: '0.15',
133
- balanceInCurrency: undefined,
134
- balanceCurrencyDisplayValue: undefined,
135
- priceInCurrency: undefined,
136
- marketCap: undefined,
137
- vol24: undefined,
138
- change24: undefined,
139
- unconfirmedBalance: new BN(mockedBalance.balanceUnconfirmed, 8),
140
- unconfirmedBalanceDisplayValue: '0.05',
141
- unconfirmedBalanceInCurrency: undefined,
142
- unconfirmedBalanceCurrencyDisplayValue: undefined,
143
- },
144
- },
145
- });
146
- });
147
- });
148
-
149
- it('maps returned balances to known model', async () => {
150
- expect(
151
- await getBalances({
152
- addresses: ['first-address'],
153
- currency: 'USD',
154
- network,
155
- proxyApiUrl,
156
- }),
157
- ).toEqual({
158
- 'first-address': {
159
- BTC: {
160
- ...network.networkToken,
161
- utxos: mockedBalance.utxos,
162
- utxosUnconfirmed: mockedBalance.utxosUnconfirmed,
163
- coingeckoId: network.pricingProviders?.coingecko?.nativeTokenId,
164
- type: TokenType.NATIVE,
165
- balance: new BN(mockedBalance.balance, 8),
166
- balanceDisplayValue: '0.15',
167
- balanceInCurrency: 7500,
168
- balanceCurrencyDisplayValue: '7500.00',
169
- priceInCurrency: 50_000,
170
- marketCap: 1_500_000_000_000,
171
- vol24: 500_000_000_000,
172
- change24: 0.01,
173
- unconfirmedBalance: new BN(mockedBalance.balanceUnconfirmed, 8),
174
- unconfirmedBalanceDisplayValue: '0.05',
175
- unconfirmedBalanceInCurrency: 2500,
176
- unconfirmedBalanceCurrencyDisplayValue: '2500.00',
177
- },
178
- },
179
- });
180
- });
181
- });
@@ -1,110 +0,0 @@
1
- import { TokenType, type GetBalancesParams, type TokenWithBalanceBTC } from '@avalabs/vm-module-types';
2
- import { bigToBN, balanceToDisplayValue } from '@avalabs/utils-sdk';
3
- import type { VsCurrencyType } from '@avalabs/coingecko-sdk';
4
- import Big from 'big.js';
5
-
6
- import { TokenService } from '@internal/utils';
7
-
8
- import { getProvider } from '../../utils/get-provider';
9
- import { extractTokenMarketData } from '../../utils/extract-token-market-data';
10
-
11
- type GetBtcBalancesResponse = Record<string, Record<string, TokenWithBalanceBTC>>;
12
-
13
- type GetBTCBalancesParams = Omit<GetBalancesParams, 'currency'> & {
14
- proxyApiUrl: string;
15
- withScripts?: boolean;
16
- currency?: string;
17
- };
18
-
19
- export const getBalances = async ({
20
- addresses,
21
- currency,
22
- network,
23
- withScripts,
24
- proxyApiUrl,
25
- storage,
26
- }: GetBTCBalancesParams): Promise<GetBtcBalancesResponse> => {
27
- const provider = getProvider({
28
- isTestnet: Boolean(network.isTestnet),
29
- proxyApiUrl,
30
- });
31
-
32
- const tokenService = new TokenService({ proxyApiUrl, storage });
33
- const coingeckoTokenId = network.pricingProviders?.coingecko.nativeTokenId;
34
- const withPrices = typeof currency === 'string' && typeof coingeckoTokenId === 'string';
35
- const marketData = withPrices
36
- ? await tokenService.getSimplePrice({
37
- coinIds: [coingeckoTokenId],
38
- currencies: [currency] as VsCurrencyType[],
39
- })
40
- : undefined;
41
- const denomination = network.networkToken.decimals;
42
- const { priceInCurrency, change24, marketCap, vol24 } = extractTokenMarketData(
43
- coingeckoTokenId ?? '',
44
- currency,
45
- marketData,
46
- );
47
-
48
- const balances = await Promise.allSettled(
49
- addresses.map(async (address) => {
50
- const {
51
- balance: balanceInSatoshis,
52
- utxos,
53
- balanceUnconfirmed: unconfirmedBalanceInSatoshis,
54
- utxosUnconfirmed,
55
- } = await provider.getUtxoBalance(address, withScripts);
56
-
57
- const balanceBig = new Big(balanceInSatoshis).div(10 ** denomination);
58
- const balance = bigToBN(balanceBig, denomination);
59
- const balanceDisplayValue = balanceToDisplayValue(balance, denomination);
60
- const balanceInCurrency =
61
- priceInCurrency === undefined ? undefined : balanceBig.times(priceInCurrency).toNumber();
62
-
63
- const balanceCurrencyDisplayValue = balanceInCurrency?.toFixed(2);
64
-
65
- const unconfirmedBalanceBig = new Big(unconfirmedBalanceInSatoshis).div(10 ** denomination);
66
- const unconfirmedBalance = bigToBN(unconfirmedBalanceBig, denomination);
67
- const unconfirmedBalanceDisplayValue = balanceToDisplayValue(unconfirmedBalance, denomination);
68
- const unconfirmedBalanceInCurrency =
69
- priceInCurrency === undefined ? undefined : unconfirmedBalanceBig.times(priceInCurrency).toNumber();
70
- const unconfirmedBalanceCurrencyDisplayValue = unconfirmedBalanceInCurrency?.toFixed(2);
71
-
72
- const symbol = network.networkToken.symbol;
73
-
74
- return {
75
- [address]: {
76
- [symbol]: {
77
- ...network.networkToken,
78
- utxos,
79
- utxosUnconfirmed,
80
- coingeckoId: coingeckoTokenId ?? '',
81
- type: TokenType.NATIVE,
82
- balance,
83
- balanceDisplayValue,
84
- balanceInCurrency,
85
- balanceCurrencyDisplayValue,
86
- priceInCurrency,
87
- marketCap,
88
- vol24,
89
- change24,
90
- unconfirmedBalance,
91
- unconfirmedBalanceDisplayValue,
92
- unconfirmedBalanceInCurrency,
93
- unconfirmedBalanceCurrencyDisplayValue,
94
- },
95
- },
96
- };
97
- }),
98
- );
99
-
100
- return balances.reduce((acc, accountBalance) => {
101
- if (accountBalance.status === 'rejected') {
102
- return acc;
103
- }
104
-
105
- return {
106
- ...acc,
107
- ...accountBalance.value,
108
- };
109
- }, {});
110
- };
@@ -1 +0,0 @@
1
- export * from './get-balances';
@@ -1,67 +0,0 @@
1
- import type { BitcoinProvider } from '@avalabs/wallets-sdk';
2
-
3
- import { getProvider } from '../../utils/get-provider';
4
- import { getNetworkFee } from './get-network-fee';
5
-
6
- jest.mock('../../utils/get-provider');
7
-
8
- const proxyApiUrl = 'https://proxy.api/';
9
-
10
- describe('get-network-fee', () => {
11
- const provider = { getFeeRates: jest.fn() } as unknown as BitcoinProvider;
12
-
13
- beforeEach(() => {
14
- jest.mocked(provider.getFeeRates).mockResolvedValue({
15
- low: 1,
16
- medium: 2,
17
- high: 4,
18
- });
19
-
20
- jest.mocked(getProvider).mockReturnValue(provider);
21
- });
22
-
23
- it('should build the provider and use it', async () => {
24
- await getNetworkFee({
25
- isTestnet: true,
26
- proxyApiUrl,
27
- });
28
-
29
- expect(getProvider).toHaveBeenCalledWith({ isTestnet: true, proxyApiUrl });
30
-
31
- await getNetworkFee({
32
- isTestnet: false,
33
- proxyApiUrl: 'https://proxy-dev.api/',
34
- });
35
-
36
- expect(getProvider).toHaveBeenCalledWith({ isTestnet: false, proxyApiUrl: 'https://proxy-dev.api/' });
37
- });
38
-
39
- it('should call getFeeRates() method', async () => {
40
- await getNetworkFee({
41
- isTestnet: false,
42
- proxyApiUrl,
43
- });
44
-
45
- expect(provider.getFeeRates).toHaveBeenCalled();
46
- });
47
-
48
- it('maps returned fee rates to known model', async () => {
49
- expect(
50
- await getNetworkFee({
51
- isTestnet: false,
52
- proxyApiUrl,
53
- }),
54
- ).toEqual({
55
- low: {
56
- maxFeePerGas: 1n,
57
- },
58
- medium: {
59
- maxFeePerGas: 2n,
60
- },
61
- high: {
62
- maxFeePerGas: 4n,
63
- },
64
- isFixedFee: false,
65
- });
66
- });
67
- });
@@ -1,34 +0,0 @@
1
- import type { NetworkFees } from '@avalabs/vm-module-types';
2
-
3
- import { getProvider } from '../../utils/get-provider';
4
-
5
- /**
6
- * Returns {@link NetworkFees} based on `estimatesmartfee` RPC call
7
- */
8
- export async function getNetworkFee({
9
- isTestnet,
10
- proxyApiUrl,
11
- }: {
12
- isTestnet: boolean;
13
- proxyApiUrl: string;
14
- }): Promise<NetworkFees> {
15
- const provider = getProvider({
16
- isTestnet,
17
- proxyApiUrl,
18
- });
19
-
20
- const { high, low, medium } = await provider.getFeeRates();
21
-
22
- return {
23
- low: {
24
- maxFeePerGas: BigInt(low),
25
- },
26
- medium: {
27
- maxFeePerGas: BigInt(medium),
28
- },
29
- high: {
30
- maxFeePerGas: BigInt(high),
31
- },
32
- isFixedFee: false,
33
- };
34
- }
@@ -1 +0,0 @@
1
- export * from './get-network-fee';
@@ -1,108 +0,0 @@
1
- import { TokenType, TransactionType, type Network } from '@avalabs/vm-module-types';
2
-
3
- import { convertBtcTransaction } from './convert-btc-transaction';
4
-
5
- const btcMain: Network = {
6
- isTestnet: false,
7
- chainId: 987654,
8
- networkToken: {
9
- decimals: 8,
10
- name: 'Bitcoin',
11
- symbol: 'BTC',
12
- },
13
- explorerUrl: 'https://btc.main',
14
- } as unknown as Network;
15
-
16
- const btcTest: Network = {
17
- isTestnet: true,
18
- chainId: 987653,
19
- networkToken: {
20
- decimals: 8,
21
- name: 'Bitcoin',
22
- symbol: 'BTC',
23
- },
24
- explorerUrl: 'https://btc.test',
25
- } as unknown as Network;
26
-
27
- const userAddress = 'b1-user-address';
28
- const txAddress = 'b1-tx-address';
29
-
30
- const outgoingTx = {
31
- addresses: [txAddress],
32
- amount: 15_000,
33
- fee: 600,
34
- block: 100_000,
35
- confirmations: 1,
36
- containsMultisig: false,
37
- hash: '0x1rstTxHash',
38
- isSender: true,
39
- receivedTime: 123_456_789,
40
- confirmedTime: 123_456_987,
41
- };
42
-
43
- const incomingTx = {
44
- addresses: [txAddress],
45
- amount: 30_000,
46
- fee: 450,
47
- block: 110_000,
48
- confirmations: 5,
49
- containsMultisig: false,
50
- hash: '0x2ndTxHash',
51
- isSender: false,
52
- receivedTime: 123_654_789,
53
- confirmedTime: 123_654_987,
54
- };
55
-
56
- describe('convert-btc-transaction', () => {
57
- it('should properly map outgoing txs', () => {
58
- expect(convertBtcTransaction(outgoingTx, { address: userAddress, network: btcMain })).toEqual({
59
- chainId: btcMain.chainId.toString(),
60
- explorerLink: `${btcMain.explorerUrl}/btc/tx/${outgoingTx.hash}`,
61
- from: userAddress,
62
- gasUsed: outgoingTx.fee.toString(),
63
- hash: outgoingTx.hash,
64
- isContractCall: false,
65
- isIncoming: false,
66
- isOutgoing: true,
67
- isSender: true,
68
- timestamp: outgoingTx.receivedTime * 1000,
69
- to: txAddress,
70
- tokens: [
71
- {
72
- amount: (Math.abs(outgoingTx.amount) / 10 ** btcMain.networkToken.decimals).toString(),
73
- decimal: btcMain.networkToken.decimals.toString(),
74
- name: btcMain.networkToken.name,
75
- symbol: btcMain.networkToken.symbol,
76
- type: TokenType.NATIVE,
77
- },
78
- ],
79
- txType: TransactionType.SEND,
80
- });
81
- });
82
-
83
- it('should properly map incoming txs', () => {
84
- expect(convertBtcTransaction(incomingTx, { address: userAddress, network: btcTest })).toEqual({
85
- chainId: btcTest.chainId.toString(),
86
- explorerLink: `${btcTest.explorerUrl}/btc-testnet/tx/${incomingTx.hash}`,
87
- from: txAddress,
88
- gasUsed: incomingTx.fee.toString(),
89
- hash: incomingTx.hash,
90
- isContractCall: false,
91
- isIncoming: true,
92
- isOutgoing: false,
93
- isSender: false,
94
- timestamp: incomingTx.receivedTime * 1000,
95
- to: userAddress,
96
- tokens: [
97
- {
98
- amount: (Math.abs(incomingTx.amount) / 10 ** btcTest.networkToken.decimals).toString(),
99
- decimal: btcTest.networkToken.decimals.toString(),
100
- name: btcTest.networkToken.name,
101
- symbol: btcTest.networkToken.symbol,
102
- type: TokenType.NATIVE,
103
- },
104
- ],
105
- txType: TransactionType.RECEIVE,
106
- });
107
- });
108
- });
@@ -1,36 +0,0 @@
1
- import { TokenType, TransactionType, type Network, type Transaction } from '@avalabs/vm-module-types';
2
- import type { BitcoinHistoryTx } from '@avalabs/wallets-sdk';
3
-
4
- type ConverterOptions = {
5
- address: string;
6
- network: Network;
7
- };
8
-
9
- export const convertBtcTransaction = (tx: BitcoinHistoryTx, { address, network }: ConverterOptions): Transaction => {
10
- const { explorerUrl, isTestnet, networkToken } = network;
11
- const txAddress = tx.addresses[0] ?? '';
12
-
13
- return {
14
- chainId: network.chainId.toString(),
15
- explorerLink: `${explorerUrl}/${isTestnet ? 'btc-testnet' : 'btc'}/tx/${tx.hash}`,
16
- from: tx.isSender ? address : txAddress,
17
- gasUsed: tx.fee.toString(),
18
- hash: tx.hash,
19
- isContractCall: false,
20
- isIncoming: !tx.isSender,
21
- isOutgoing: tx.isSender,
22
- isSender: tx.isSender,
23
- timestamp: tx.receivedTime * 1000,
24
- to: tx.isSender ? txAddress : address,
25
- tokens: [
26
- {
27
- amount: (Math.abs(tx.amount) / 10 ** networkToken.decimals).toString(),
28
- decimal: networkToken.decimals.toString(),
29
- name: networkToken.name,
30
- symbol: networkToken.symbol,
31
- type: TokenType.NATIVE,
32
- },
33
- ],
34
- txType: tx.isSender ? TransactionType.SEND : TransactionType.RECEIVE,
35
- };
36
- };