@avalabs/bitcoin-module 0.0.22 → 0.1.0

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/dist/index.cjs +7 -50
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +5 -3
  5. package/dist/index.d.ts +5 -3
  6. package/dist/index.js +8 -45
  7. package/dist/index.js.map +1 -1
  8. package/package.json +12 -3
  9. package/.turbo/turbo-build.log +0 -22
  10. package/.turbo/turbo-lint.log +0 -4
  11. package/.turbo/turbo-test.log +0 -16
  12. package/CHANGELOG.md +0 -49
  13. package/jest.config.js +0 -10
  14. package/src/env.ts +0 -25
  15. package/src/handlers/get-balances/get-balances.test.ts +0 -181
  16. package/src/handlers/get-balances/get-balances.ts +0 -108
  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 -74
  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/package.json CHANGED
@@ -1,18 +1,26 @@
1
1
  {
2
2
  "name": "@avalabs/bitcoin-module",
3
- "version": "0.0.22",
3
+ "version": "0.1.0",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
7
7
  "type": "module",
8
+ "files": [
9
+ "dist",
10
+ "manifest.json"
11
+ ],
12
+ "license": "Limited Ecosystem License",
8
13
  "dependencies": {
9
- "@avalabs/vm-module-types": "0.0.22",
14
+ "@avalabs/vm-module-types": "0.1.0",
10
15
  "@avalabs/wallets-sdk": "2.8.0-alpha.193",
11
16
  "@avalabs/coingecko-sdk": "v2.8.0-alpha.193",
12
17
  "@avalabs/utils-sdk": "2.8.0-alpha.193",
13
18
  "@metamask/rpc-errors": "6.3.0",
14
19
  "big.js": "6.2.1",
15
- "bn.js": "5.2.1"
20
+ "bn.js": "5.2.1",
21
+ "zod": "3.23.8",
22
+ "@zodios/core": "10.9.6",
23
+ "bitcoinjs-lib": "5.2.0"
16
24
  },
17
25
  "devDependencies": {
18
26
  "@types/big.js": "6.2.2",
@@ -27,6 +35,7 @@
27
35
  },
28
36
  "scripts": {
29
37
  "build": "tsup",
38
+ "dev": "tsup --watch",
30
39
  "lint": "eslint \"src/**/*.ts\"",
31
40
  "test": "jest",
32
41
  "test:watch": "jest --watch"
@@ -1,22 +0,0 @@
1
-
2
- > @avalabs/bitcoin-module@0.0.22 build /home/runner/work/vm-modules/vm-modules/packages/bitcoin-module
3
- > tsup
4
-
5
- CLI Building entry: ./src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v7.2.0
8
- CLI Using tsup config: /home/runner/work/vm-modules/vm-modules/packages/bitcoin-module/tsup.config.ts
9
- CLI Target: es2021
10
- CLI Cleaning output folder
11
- CJS Build start
12
- ESM Build start
13
- DTS Build start
14
- ESM dist/index.js 277.03 KB
15
- ESM dist/index.js.map 916.88 KB
16
- ESM ⚡️ Build success in 17748ms
17
- CJS dist/index.cjs 277.92 KB
18
- CJS dist/index.cjs.map 916.88 KB
19
- CJS ⚡️ Build success in 17750ms
20
- DTS ⚡️ Build success in 25765ms
21
- DTS dist/index.d.cts 1.25 KB
22
- DTS dist/index.d.ts 1.25 KB
@@ -1,4 +0,0 @@
1
-
2
- > @avalabs/bitcoin-module@0.0.22 lint /home/runner/work/vm-modules/vm-modules/packages/bitcoin-module
3
- > eslint "src/**/*.ts"
4
-
@@ -1,16 +0,0 @@
1
-
2
- > @avalabs/bitcoin-module@0.0.22 test /home/runner/work/vm-modules/vm-modules/packages/bitcoin-module
3
- > jest
4
-
5
- PASS src/handlers/get-balances/get-balances.test.ts (35.044 s)
6
- PASS src/handlers/get-transaction-history/convert-btc-transaction.test.ts
7
- PASS src/handlers/get-transaction-history/get-transaction-history.test.ts
8
- PASS src/module.test.ts
9
- PASS src/utils/get-provider.test.ts
10
- PASS src/handlers/get-network-fee/get-network-fee.test.ts
11
-
12
- Test Suites: 6 passed, 6 total
13
- Tests: 20 passed, 20 total
14
- Snapshots: 0 total
15
- Time: 42.462 s
16
- Ran all test suites.
package/CHANGELOG.md DELETED
@@ -1,49 +0,0 @@
1
- # @avalabs/bitcoin-module
2
-
3
- ## 0.0.22
4
-
5
- ### Patch Changes
6
-
7
- - @avalabs/vm-module-types@0.0.22
8
-
9
- ## 0.0.21
10
-
11
- ### Patch Changes
12
-
13
- - @avalabs/vm-module-types@0.0.21
14
-
15
- ## 0.0.20
16
-
17
- ### Patch Changes
18
-
19
- - 9bfa82d: Implement balance fetching for BitcoinModule
20
- - Updated dependencies [9bfa82d]
21
- - @avalabs/vm-module-types@0.0.20
22
-
23
- ## 0.0.19
24
-
25
- ### Patch Changes
26
-
27
- - Updated dependencies [5af458b]
28
- - @avalabs/vm-module-types@0.0.19
29
-
30
- ## 0.0.18
31
-
32
- ### Patch Changes
33
-
34
- - @avalabs/vm-module-types@0.0.18
35
-
36
- ## 0.0.17
37
-
38
- ### Patch Changes
39
-
40
- - Updated dependencies [3590edf]
41
- - @avalabs/vm-module-types@0.0.17
42
-
43
- ## 0.0.16
44
-
45
- ### Patch Changes
46
-
47
- - de9824c: feat: created bitcoin module
48
- - Updated dependencies [bc48457]
49
- - @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,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,108 +0,0 @@
1
- import { TokenType, type GetBalancesParams, type GetBalancesResponse } 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 GetBTCBalancesParams = Omit<GetBalancesParams, 'currency'> & {
12
- proxyApiUrl: string;
13
- withScripts?: boolean;
14
- currency?: string;
15
- };
16
-
17
- export const getBalances = async ({
18
- addresses,
19
- currency,
20
- network,
21
- withScripts,
22
- proxyApiUrl,
23
- storage,
24
- }: GetBTCBalancesParams): Promise<GetBalancesResponse> => {
25
- const provider = getProvider({
26
- isTestnet: Boolean(network.isTestnet),
27
- proxyApiUrl,
28
- });
29
-
30
- const tokenService = new TokenService({ proxyApiUrl, storage });
31
- const coingeckoTokenId = network.pricingProviders?.coingecko.nativeTokenId;
32
- const withPrices = typeof currency === 'string' && typeof coingeckoTokenId === 'string';
33
- const marketData = withPrices
34
- ? await tokenService.getSimplePrice({
35
- coinIds: [coingeckoTokenId],
36
- currencies: [currency] as VsCurrencyType[],
37
- })
38
- : undefined;
39
- const denomination = network.networkToken.decimals;
40
- const { priceInCurrency, change24, marketCap, vol24 } = extractTokenMarketData(
41
- coingeckoTokenId ?? '',
42
- currency,
43
- marketData,
44
- );
45
-
46
- const balances = await Promise.allSettled(
47
- addresses.map(async (address) => {
48
- const {
49
- balance: balanceInSatoshis,
50
- utxos,
51
- balanceUnconfirmed: unconfirmedBalanceInSatoshis,
52
- utxosUnconfirmed,
53
- } = await provider.getUtxoBalance(address, withScripts);
54
-
55
- const balanceBig = new Big(balanceInSatoshis).div(10 ** denomination);
56
- const balance = bigToBN(balanceBig, denomination);
57
- const balanceDisplayValue = balanceToDisplayValue(balance, denomination);
58
- const balanceInCurrency =
59
- priceInCurrency === undefined ? undefined : balanceBig.times(priceInCurrency).toNumber();
60
-
61
- const balanceCurrencyDisplayValue = balanceInCurrency?.toFixed(2);
62
-
63
- const unconfirmedBalanceBig = new Big(unconfirmedBalanceInSatoshis).div(10 ** denomination);
64
- const unconfirmedBalance = bigToBN(unconfirmedBalanceBig, denomination);
65
- const unconfirmedBalanceDisplayValue = balanceToDisplayValue(unconfirmedBalance, denomination);
66
- const unconfirmedBalanceInCurrency =
67
- priceInCurrency === undefined ? undefined : unconfirmedBalanceBig.times(priceInCurrency).toNumber();
68
- const unconfirmedBalanceCurrencyDisplayValue = unconfirmedBalanceInCurrency?.toFixed(2);
69
-
70
- const symbol = network.networkToken.symbol;
71
-
72
- return {
73
- [address]: {
74
- [symbol]: {
75
- ...network.networkToken,
76
- utxos,
77
- utxosUnconfirmed,
78
- coingeckoId: coingeckoTokenId ?? '',
79
- type: TokenType.NATIVE,
80
- balance,
81
- balanceDisplayValue,
82
- balanceInCurrency,
83
- balanceCurrencyDisplayValue,
84
- priceInCurrency,
85
- marketCap,
86
- vol24,
87
- change24,
88
- unconfirmedBalance,
89
- unconfirmedBalanceDisplayValue,
90
- unconfirmedBalanceInCurrency,
91
- unconfirmedBalanceCurrencyDisplayValue,
92
- },
93
- },
94
- };
95
- }),
96
- );
97
-
98
- return balances.reduce((acc, accountBalance) => {
99
- if (accountBalance.status === 'rejected') {
100
- return acc;
101
- }
102
-
103
- return {
104
- ...acc,
105
- ...accountBalance.value,
106
- };
107
- }, {});
108
- };
@@ -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
- });