@exodus/bitcoin-plugin 1.2.0 → 1.4.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.
- package/jest.config.js +7 -0
- package/package.json +3 -4
- package/src/__tests__/address.test.js +142 -0
- package/src/__tests__/balances.test.js +67 -0
- package/src/__tests__/bitcoin-private-seed-safe-report.json +2754 -0
- package/src/__tests__/bitcoin-signing.test.js +184 -0
- package/src/__tests__/fee-data.test.js +61 -0
- package/src/__tests__/fee-estimator.test.js +174 -0
- package/src/__tests__/fixtures/segwit-all-unsigned-tx.js +87 -0
- package/src/__tests__/fixtures/segwit-legacy-change-unsigned-tx.js +38 -0
- package/src/__tests__/fixtures/segwit-segwit-change-unsigned-tx.js +96 -0
- package/src/__tests__/fixtures/taproot-15000sats-unsigned-tx.js +149 -0
- package/src/__tests__/fixtures/taproot-all-unsigned-tx.js +231 -0
- package/src/__tests__/fixtures/taproot-unsigned-tx.js +85 -0
- package/src/__tests__/get-size.test.js +70 -0
- package/src/__tests__/index.test.js +65 -0
- package/src/__tests__/keys.test.js +97 -0
- package/src/__tests__/monitor.integration.test.js +170 -0
- package/src/__tests__/move-funds.test.js +408 -0
- package/src/__tests__/parse-unsigned-tx.test.js +46 -0
- package/src/__tests__/reports/unit-test-safe-report.json +2790 -0
- package/src/__tests__/send-tx.test.js +145 -0
- package/src/__tests__/sign-tx.test.js +32 -0
- package/src/__tests__/unsigned-btclike-desktop.json +40 -0
- package/src/__tests__/wallet.test.js +78 -0
- package/src/create-asset.js +70 -7
- package/src/ordinals/__tests__/brc-20-client.integration.test.js +86 -0
- package/src/ordinals/__tests__/brc-20-utils.test.js +165 -0
- package/src/ordinals/__tests__/fixtures/inscriptions-send-usigned-tx.js +125 -0
- package/src/ordinals/__tests__/fixtures/nft-send-usigned-tx.js +97 -0
- package/src/ordinals/__tests__/monitor-ordinals-enabled-safe-report-with-inscriptions.json +2908 -0
- package/src/ordinals/__tests__/monitor-ordinals-enabled-safe-report.json +2906 -0
- package/src/ordinals/__tests__/monitor-ordinals-enabled.integration.test.js +16 -0
- package/src/ordinals/__tests__/nfts-api.test.js +221 -0
- package/src/ordinals/__tests__/ordinals-send-tx.test.js +103 -0
- package/src/ordinals/brc-20-balances-and-fee-adapter.js +41 -0
- package/src/ordinals/brc-20-utils.js +79 -0
- package/src/ordinals/create-token-factory.js +30 -0
- package/src/ordinals/get-inscription-addresses.js +42 -0
- package/src/ordinals/nfts.js +65 -0
- package/src/ordinals/ordinals-account-state-utils.js +55 -0
- package/src/ordinals/ordinals-constants.js +4 -0
- package/src/ordinals/reload-brc20-token-balances.js +154 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import shuffle from 'lodash/shuffle'
|
|
2
|
+
|
|
3
|
+
import { createAsset } from '../index'
|
|
4
|
+
import { getPrivateSeed, walletTester } from '@exodus/assets-testing'
|
|
5
|
+
import path from 'path'
|
|
6
|
+
|
|
7
|
+
import { getSchnorrEntropy } from '@exodus/bitcoin-api/src/tx-sign/default-entropy'
|
|
8
|
+
|
|
9
|
+
import taprootUnsignedTx from './fixtures/taproot-unsigned-tx'
|
|
10
|
+
import segwitUnsignedTx from './fixtures/segwit-segwit-change-unsigned-tx'
|
|
11
|
+
import segwitAllUnsignedTx from './fixtures/segwit-all-unsigned-tx'
|
|
12
|
+
import taprootAllUnsignedTx from './fixtures/taproot-all-unsigned-tx'
|
|
13
|
+
import taproot15000satsUnsignedTx from './fixtures/taproot-15000sats-unsigned-tx'
|
|
14
|
+
import { sendTxTest } from '@exodus/bitcoin-api/src/__tests__/tx-send-testing-utils'
|
|
15
|
+
const asset = createAsset()
|
|
16
|
+
|
|
17
|
+
// Tell jest to mock this import
|
|
18
|
+
jest.mock('lodash/shuffle')
|
|
19
|
+
jest.mock('@exodus/bitcoin-api/src/insight-api-client/index')
|
|
20
|
+
jest.mock('@exodus/bitcoin-api/src/tx-sign/default-entropy')
|
|
21
|
+
|
|
22
|
+
// avoid shuffle so order and tx hash can be asserted
|
|
23
|
+
shuffle.mockImplementation((list) => {
|
|
24
|
+
return list
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
getSchnorrEntropy.mockImplementation(() => {
|
|
28
|
+
return Buffer.from('1230000000000000000000000000000000000000000000000000000000000000', 'hex')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const importSafeReportFile = path.join(__dirname, 'reports/unit-test-safe-report.json')
|
|
32
|
+
|
|
33
|
+
describe(`bitcoin tx-send test`, () => {
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
jest.spyOn(asset.api, 'signTx')
|
|
36
|
+
asset.insightClient.fetchBlockHeight.mockImplementation(async () => {
|
|
37
|
+
return 768520
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
jest.clearAllMocks()
|
|
43
|
+
jest.restoreAllMocks()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
walletTester({
|
|
47
|
+
asset,
|
|
48
|
+
seed: getPrivateSeed(),
|
|
49
|
+
importSafeReportFile,
|
|
50
|
+
walletAccountCount: 4,
|
|
51
|
+
tests: {
|
|
52
|
+
'can send 10 satoshis exodus_0': async ({ assetClientInterface, asset }) => {
|
|
53
|
+
const address = 'bc1pkhrae7jrlj3wnz0vpm09tffndpu40vh6y4tl42pt2zdhfms575msdfwuew'
|
|
54
|
+
const amount = asset.currency.parse('10 satoshis')
|
|
55
|
+
const expectedBalance = asset.currency.parse('102520 satoshis')
|
|
56
|
+
const expectedFee = asset.currency.parse('15028 satoshis')
|
|
57
|
+
|
|
58
|
+
const params = {
|
|
59
|
+
assetClientInterface,
|
|
60
|
+
asset,
|
|
61
|
+
address,
|
|
62
|
+
amount,
|
|
63
|
+
options: { multipleAddressesEnabled: false, isSendAll: false },
|
|
64
|
+
expectedBalance,
|
|
65
|
+
expectedFee,
|
|
66
|
+
expectedTxData: segwitUnsignedTx,
|
|
67
|
+
}
|
|
68
|
+
await sendTxTest(params)
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
'can send all exodus_0': async ({ assetClientInterface, asset }) => {
|
|
72
|
+
const address = 'bc1pkhrae7jrlj3wnz0vpm09tffndpu40vh6y4tl42pt2zdhfms575msdfwuew'
|
|
73
|
+
const expectedBalance = asset.currency.parse('97080 satoshis')
|
|
74
|
+
const expectedFee = asset.currency.parse('12920 satoshis')
|
|
75
|
+
|
|
76
|
+
const params = {
|
|
77
|
+
assetClientInterface,
|
|
78
|
+
asset,
|
|
79
|
+
address,
|
|
80
|
+
options: { multipleAddressesEnabled: false, isSendAll: true },
|
|
81
|
+
expectedBalance,
|
|
82
|
+
expectedFee,
|
|
83
|
+
expectedTxData: segwitAllUnsignedTx,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
await sendTxTest(params)
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
'can send 10 satoshis exodus_1 (taproot)': async ({ assetClientInterface, asset }) => {
|
|
90
|
+
// the used utxos - amount - fee is lower that dust. That's why there is no change address!
|
|
91
|
+
const address = 'bc1pkhrae7jrlj3wnz0vpm09tffndpu40vh6y4tl42pt2zdhfms575msdfwuew'
|
|
92
|
+
const amount = asset.currency.parse('10 satoshis')
|
|
93
|
+
const expectedBalance = asset.currency.parse('1309643 satoshis')
|
|
94
|
+
const expectedFee = asset.currency.parse('14348 satoshis')
|
|
95
|
+
const params = {
|
|
96
|
+
assetClientInterface,
|
|
97
|
+
asset,
|
|
98
|
+
address,
|
|
99
|
+
amount,
|
|
100
|
+
options: { multipleAddressesEnabled: false, isSendAll: false },
|
|
101
|
+
expectedBalance,
|
|
102
|
+
expectedFee,
|
|
103
|
+
expectedTxData: taprootUnsignedTx,
|
|
104
|
+
}
|
|
105
|
+
await sendTxTest(params)
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
'can send 15000 sats exodus_1 (taproot)': async ({ assetClientInterface, asset }) => {
|
|
109
|
+
// spends both utxos with change!
|
|
110
|
+
const address = 'bc1pkhrae7jrlj3wnz0vpm09tffndpu40vh6y4tl42pt2zdhfms575msdfwuew'
|
|
111
|
+
const amount = asset.currency.parse('15000 satoshis')
|
|
112
|
+
const expectedBalance = asset.currency.parse('1309643 satoshis')
|
|
113
|
+
const expectedFee = asset.currency.parse('27540 satoshis')
|
|
114
|
+
const params = {
|
|
115
|
+
assetClientInterface,
|
|
116
|
+
asset,
|
|
117
|
+
address,
|
|
118
|
+
amount,
|
|
119
|
+
options: { multipleAddressesEnabled: false, isSendAll: false },
|
|
120
|
+
expectedBalance,
|
|
121
|
+
expectedFee,
|
|
122
|
+
expectedTxData: taproot15000satsUnsignedTx,
|
|
123
|
+
}
|
|
124
|
+
await sendTxTest(params)
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
'can send all exodus_1 (taproot)': async ({ assetClientInterface, asset }) => {
|
|
128
|
+
const address = 'bc1pkhrae7jrlj3wnz0vpm09tffndpu40vh6y4tl42pt2zdhfms575msdfwuew'
|
|
129
|
+
const expectedBalance = asset.currency.parse('1271631 satoshis')
|
|
130
|
+
const expectedFee = asset.currency.parse('49436 satoshis')
|
|
131
|
+
|
|
132
|
+
const params = {
|
|
133
|
+
assetClientInterface,
|
|
134
|
+
asset,
|
|
135
|
+
address,
|
|
136
|
+
options: { multipleAddressesEnabled: false, isSendAll: true },
|
|
137
|
+
expectedBalance,
|
|
138
|
+
expectedFee,
|
|
139
|
+
expectedTxData: taprootAllUnsignedTx,
|
|
140
|
+
}
|
|
141
|
+
await sendTxTest(params)
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
})
|
|
145
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createAsset } from '../index'
|
|
2
|
+
|
|
3
|
+
import { getPrivateSeed, walletTester } from '@exodus/assets-testing'
|
|
4
|
+
import { join } from 'path'
|
|
5
|
+
import { getSchnorrEntropy } from '@exodus/bitcoin-api/src/tx-sign/default-entropy'
|
|
6
|
+
import { createSignTestCases } from '@exodus/bitcoin-api/src/__tests__/bitcoin-testing-utils'
|
|
7
|
+
const asset = createAsset()
|
|
8
|
+
|
|
9
|
+
// mocking insight client just in case
|
|
10
|
+
jest.mock('@exodus/bitcoin-api/src/insight-api-client/index')
|
|
11
|
+
|
|
12
|
+
jest.mock('@exodus/bitcoin-api/src/tx-sign/default-entropy')
|
|
13
|
+
|
|
14
|
+
getSchnorrEntropy.mockImplementation(() => {
|
|
15
|
+
return Buffer.from('1230000000000000000000000000000000000000000000000000000000000000', 'hex')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const fixturesPath = join(__dirname, 'fixtures')
|
|
19
|
+
|
|
20
|
+
describe(`bitcoin tx-sign test`, () => {
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
jest.restoreAllMocks()
|
|
23
|
+
})
|
|
24
|
+
walletTester({
|
|
25
|
+
asset,
|
|
26
|
+
seed: getPrivateSeed(),
|
|
27
|
+
walletAccountCount: 4,
|
|
28
|
+
tests: {
|
|
29
|
+
...createSignTestCases({ fixturesPath }),
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"txData": {
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"txId": "2ee8cee0def7354ccca93df0fc45aa93224a8cecb5fc02dd6f53433419738a6e",
|
|
6
|
+
"vout": 1,
|
|
7
|
+
"address": "bc1qwrt6lujwp3rplt2prrfc66wzc2ksuth2u5yzye",
|
|
8
|
+
"value": 37584,
|
|
9
|
+
"sequence": 4294967295
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"txId": "1ec9fa3f3f74e40266266f319fd7258e7e6676f20000fae2a97e6da9c1fa7cf8",
|
|
13
|
+
"vout": 0,
|
|
14
|
+
"address": "bc1qwrt6lujwp3rplt2prrfc66wzc2ksuth2u5yzye",
|
|
15
|
+
"value": 597157,
|
|
16
|
+
"sequence": 4294967295
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"outputs": [
|
|
20
|
+
[
|
|
21
|
+
"bc1qm7520rkhy4fp25572t0u7ql2cj0utcga8nddxp",
|
|
22
|
+
313866
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
"bc1qu0lc37p9nlh8a5u8qhp0aaj0y204rg979pe0am",
|
|
26
|
+
314251
|
|
27
|
+
]
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"txMeta": {
|
|
31
|
+
"assetName": "bitcoin",
|
|
32
|
+
"addressPathsMap": {
|
|
33
|
+
"bc1qwrt6lujwp3rplt2prrfc66wzc2ksuth2u5yzye": "m/0/0",
|
|
34
|
+
"bc1qu0lc37p9nlh8a5u8qhp0aaj0y204rg979pe0am": "m/1/0"
|
|
35
|
+
},
|
|
36
|
+
"replayProtect": {},
|
|
37
|
+
"hasChange": true,
|
|
38
|
+
"feePerKBUsed": 32000
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createAsset } from '../index'
|
|
2
|
+
|
|
3
|
+
import { getPrivateSeed, getTestingSeed, walletTester } from '@exodus/assets-testing'
|
|
4
|
+
const asset = createAsset()
|
|
5
|
+
|
|
6
|
+
describe(`bitcoin testing seed wallet test`, () => {
|
|
7
|
+
walletTester({
|
|
8
|
+
asset,
|
|
9
|
+
seed: getTestingSeed(),
|
|
10
|
+
testChainIndexes: [0, 1, 2],
|
|
11
|
+
expectedAddresses: {
|
|
12
|
+
bitcoin_44_exodus_0_0_0: '1Ce5zNA1ZhTxCgXd9XQdb87Bf78VR8zL8j',
|
|
13
|
+
bitcoin_44_exodus_0_1_0: '1Cs4UtbjFnJzBcuTYbrrdRP9Jzakw5pQKk',
|
|
14
|
+
bitcoin_44_exodus_0_2_0: '1KqSL7JybmtWcUCZM5tHhmxjo5yVovtsg5',
|
|
15
|
+
bitcoin_44_exodus_1_0_0: '1Kb7JNhQ7ULHBx1TFJuEAmQFb1FFAYYxhs',
|
|
16
|
+
bitcoin_44_exodus_1_1_0: '1Nrh5dtwYQMPB1RkpJ7czFB6sd9iqUaNVW',
|
|
17
|
+
bitcoin_44_exodus_1_2_0: '1CWhmizra8soSHUzLVneh1ixRDQvGJrQfP',
|
|
18
|
+
bitcoin_44_exodus_2_0_0: '1NJaYYJ4HDAFYuswMeFCwFrJ3i4HKfgzDC',
|
|
19
|
+
bitcoin_44_exodus_2_1_0: '1Q7kXCWLcfUqn3UVzaN6VYscMta1bGSQK9',
|
|
20
|
+
bitcoin_44_exodus_2_2_0: '12DbAznGUaXtagip6tAm4ZneDykE4MMATv',
|
|
21
|
+
bitcoin_84_exodus_0_0_0: 'bc1qlrh635rpvps06d9klakf7k3lq4tlnd25e53pez',
|
|
22
|
+
bitcoin_84_exodus_0_1_0: 'bc1qe4ysmg5qlnlsq8gwrqhrhjwg5gaprefwpnvrnv',
|
|
23
|
+
bitcoin_84_exodus_0_2_0: 'bc1qct3fkp7w4ue78rl00fl8cjszt2edwl8mwgapx2',
|
|
24
|
+
bitcoin_84_exodus_1_0_0: 'bc1q78ne29cynskvmx3r647m9dyhngsw5gjpencs0d',
|
|
25
|
+
bitcoin_84_exodus_1_1_0: 'bc1q4fzldmup6nw8qql59nsxtdh4w02hf78zpn5jj8',
|
|
26
|
+
bitcoin_84_exodus_1_2_0: 'bc1qayqcsl09dftkv0uuvkfnn0n95092l7663x8udl',
|
|
27
|
+
bitcoin_84_exodus_2_0_0: 'bc1qcg9vcs203yv6t3z4tnkftsyx6hy6wj6fkmrd4r',
|
|
28
|
+
bitcoin_84_exodus_2_1_0: 'bc1qjmfh6xgfq046hxemu6pfmkzq208c7lfxv673x3',
|
|
29
|
+
bitcoin_84_exodus_2_2_0: 'bc1qtem7mqq3z4z3l8hq44gvm0spqkuqh8fzwtrswd',
|
|
30
|
+
bitcoin_86_exodus_0_0_0: 'bc1pcf8yrw8vf5y3lxlmkjqlme7wpqywmqsdhr5ngzwvgpx63ww706fq3y4x0q',
|
|
31
|
+
bitcoin_86_exodus_0_1_0: 'bc1pvv9azs5ywfuqj7dsydx465qx5kyq7l3y53q7e0wjf7ga5a5lpueswtvlcw',
|
|
32
|
+
bitcoin_86_exodus_0_2_0: 'bc1pht230hfjn3k9wxj7y0q6k6qyfyjg3xc9d6sp6gacw4x50vpxrdyqrkv2av',
|
|
33
|
+
bitcoin_86_exodus_1_0_0: 'bc1pms29vk2n5ds5e2a8tepdahaljjzfaskg5tcx64uharj6fagut6gq7ygsk4',
|
|
34
|
+
bitcoin_86_exodus_1_1_0: 'bc1p7czzagy39sk43dg2gwqqgswcjn6rwr976snnfkvqhx40nc4pufqs2s4at9',
|
|
35
|
+
bitcoin_86_exodus_1_2_0: 'bc1pxrrnvx3tudzxjtqw2cx5kjxsstyqghps333mqz43weterk40f98qhdw5dm',
|
|
36
|
+
bitcoin_86_exodus_2_0_0: 'bc1pffcpm60f00ttg7mqz3zg9ale4fdqajqyr87jeswqs8uxnrc4yvgsxkwazk',
|
|
37
|
+
bitcoin_86_exodus_2_1_0: 'bc1p7df89ppucj9qdvar8dmkr34hq07ndfh7lnadqgv0s089xtp7n2usf9pekp',
|
|
38
|
+
bitcoin_86_exodus_2_2_0: 'bc1pjsre758d9k6ledwu34q7xqu30qz4a46v3gfhj0n8m6enmjul8tcq64qe0s',
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
describe(`bitcoin private seed wallet test`, () => {
|
|
44
|
+
walletTester({
|
|
45
|
+
asset,
|
|
46
|
+
seed: getPrivateSeed(),
|
|
47
|
+
testChainIndexes: [0, 1, 2],
|
|
48
|
+
expectedAddresses: {
|
|
49
|
+
bitcoin_44_exodus_0_0_0: '1Azpg7QEdQ8FHhNLzEpbpo1Uowh3t7B3Ex',
|
|
50
|
+
bitcoin_44_exodus_0_1_0: '1HZ3g5qRpAMApVzeFhfyktH5mb8EVoGYdk',
|
|
51
|
+
bitcoin_44_exodus_0_2_0: '1PRCUCV6AWsdE4d6TxtWYjAtmV2zAmKcNi',
|
|
52
|
+
bitcoin_44_exodus_1_0_0: '1AELPVvN9aDdWsR7hCkpVgA2WAuDjuPDB3',
|
|
53
|
+
bitcoin_44_exodus_1_1_0: '18d1c4KrXaxzCVkP1H3Ffbx58ADfDGX3d7',
|
|
54
|
+
bitcoin_44_exodus_1_2_0: '1EgtiYgoyJ2ZcG472rXunfTUCCVAVqEg1E',
|
|
55
|
+
bitcoin_44_exodus_2_0_0: '14Gmj5bDcdwq9kCeYboSfNBECfrZ59podu',
|
|
56
|
+
bitcoin_44_exodus_2_1_0: '1PDWewrgceDenSAWQz5yGD9Luvvi1EPrrK',
|
|
57
|
+
bitcoin_44_exodus_2_2_0: '1JDN9V98LD6PDDTbyxEi3AvuwZNUAWmeXD',
|
|
58
|
+
bitcoin_84_exodus_0_0_0: 'bc1qz0p68ljq4xslgl09g8rdfzjse7dshm4w6jsh48',
|
|
59
|
+
bitcoin_84_exodus_0_1_0: 'bc1q086jhvqmana3mzf8qvm0xzerxhngyklpcurfh6',
|
|
60
|
+
bitcoin_84_exodus_0_2_0: 'bc1qdys7vkcu7cry55vk0n9x8dy8uhjrvxrvjzp6qf',
|
|
61
|
+
bitcoin_84_exodus_1_0_0: 'bc1qgxz38crda20mlre427ygezgu67kqvqfr4heayn',
|
|
62
|
+
bitcoin_84_exodus_1_1_0: 'bc1qux2sjzksvgzwu2wdlvgtm8ggfp0azwff53yar6',
|
|
63
|
+
bitcoin_84_exodus_1_2_0: 'bc1qy6a50nuralc0vq97zacuhc4s037kprpxvz7xq9',
|
|
64
|
+
bitcoin_84_exodus_2_0_0: 'bc1q80wm35xel29d2xd79e4uveudejwmh3jnecvnl4',
|
|
65
|
+
bitcoin_84_exodus_2_1_0: 'bc1qcsxfqgs8khsj48lghz3vvpaf2ed92lk53uc364',
|
|
66
|
+
bitcoin_84_exodus_2_2_0: 'bc1qlgpz5hysa420avkn9gq7gcew06ent5km9wj3wn',
|
|
67
|
+
bitcoin_86_exodus_0_0_0: 'bc1pegpjkdt4mhexjw2k59jewegv2v6lxekapwjf6sk7euel03vnhfkq8dqhrt',
|
|
68
|
+
bitcoin_86_exodus_0_1_0: 'bc1pgsujrfjjeqe53mt0y0fs5rq9v08dt0rg6ptzpvk539365adtwudq3tslxy',
|
|
69
|
+
bitcoin_86_exodus_0_2_0: 'bc1plt3f50xhr8d5sxwz7z8ux4rp4nrsqwqysu7amlt0u0ygnlplrhqq4r0chr',
|
|
70
|
+
bitcoin_86_exodus_1_0_0: 'bc1pkhrae7jrlj3wnz0vpm09tffndpu40vh6y4tl42pt2zdhfms575msdfwuew',
|
|
71
|
+
bitcoin_86_exodus_1_1_0: 'bc1pj083pf34whgnmwk59gxq08yfxkykqek7p2leh2xte59tfq032s7qruagux',
|
|
72
|
+
bitcoin_86_exodus_1_2_0: 'bc1pe59l2tsfe6t5x6wrcgtsaxy3nrpnky8chq4cvf7zndat99f8t4xsetgm4w',
|
|
73
|
+
bitcoin_86_exodus_2_0_0: 'bc1p22zuaxepunt587sfjjahmlr844qa99p4xsjgtfxzlhk2x2xjcu7sh9ljqu',
|
|
74
|
+
bitcoin_86_exodus_2_1_0: 'bc1py4ax9fxjzp04lst2t6f8ul97zfgha6q6htuz8tjluwayjzzu9gaqs4kqfh',
|
|
75
|
+
bitcoin_86_exodus_2_2_0: 'bc1pds3v9d2j8vd8pn5nsemgqf0r4z59exya2epdd2j8j4zggem7suqskejwa6',
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
})
|
package/src/create-asset.js
CHANGED
|
@@ -23,14 +23,27 @@ import {
|
|
|
23
23
|
import { bitcoinFeeDataFactory } from './fee-data'
|
|
24
24
|
import BitcoinFeeMonitor from './fee-monitor'
|
|
25
25
|
import assert from 'minimalistic-assert'
|
|
26
|
+
import { DEFAULT_ORDINAL_CHAIN_INDEX } from './ordinals/ordinals-constants'
|
|
27
|
+
import { reloadBrc20TokenBalances } from './ordinals/reload-brc20-token-balances'
|
|
28
|
+
import { createTokenFactory } from './ordinals/create-token-factory'
|
|
29
|
+
import { brc20ApiClientFactory } from './ordinals/brc-20-client'
|
|
30
|
+
import { nftsApiFactory } from './ordinals/nfts'
|
|
31
|
+
import { brc20BalancesAndFeeAdapterFactory } from './ordinals/brc-20-balances-and-fee-adapter'
|
|
26
32
|
|
|
27
33
|
export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) => ({
|
|
28
34
|
allowUnconfirmedRbfEnabledUtxos = false,
|
|
35
|
+
ordinalChainIndex = DEFAULT_ORDINAL_CHAIN_INDEX,
|
|
36
|
+
ordinalsEnabled = false,
|
|
37
|
+
brc20Enabled = false,
|
|
29
38
|
overrideCallback = ({ asset }) => asset,
|
|
30
39
|
} = {}) => {
|
|
31
40
|
assert(asset, 'asset is required')
|
|
41
|
+
assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
|
|
32
42
|
assert(apiUrl, 'apiUrl is required')
|
|
33
|
-
|
|
43
|
+
assert(
|
|
44
|
+
brc20Enabled ? ordinalsEnabled : true,
|
|
45
|
+
'if brc20Enabled is true then ordinalsEnabled must be true'
|
|
46
|
+
)
|
|
34
47
|
const coinInfo = _coinInfo(coinInfoNetwork || asset.name)
|
|
35
48
|
|
|
36
49
|
const insightClient = new InsightAPIClient(apiUrl)
|
|
@@ -61,6 +74,8 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
61
74
|
feesApi: true,
|
|
62
75
|
moveFunds: true,
|
|
63
76
|
multipleAddresses: true,
|
|
77
|
+
nfts: ordinalsEnabled,
|
|
78
|
+
customTokens: brc20Enabled,
|
|
64
79
|
}
|
|
65
80
|
|
|
66
81
|
const getFeeEstimator = getFeeEstimatorFactory({
|
|
@@ -69,11 +84,22 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
69
84
|
addressApi: address,
|
|
70
85
|
})
|
|
71
86
|
|
|
72
|
-
const
|
|
87
|
+
const baseFeeResolver = new GetFeeResolver({
|
|
73
88
|
getFeeEstimator,
|
|
74
89
|
allowUnconfirmedRbfEnabledUtxos,
|
|
75
90
|
})
|
|
76
91
|
|
|
92
|
+
const feeData = bitcoinFeeDataFactory(asset.currency)
|
|
93
|
+
|
|
94
|
+
const baseGetBalances = getBalancesFactory({
|
|
95
|
+
feeData,
|
|
96
|
+
getSpendableBalance: baseFeeResolver.getSpendableBalance,
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const { getFee, getBalances, getAvailableBalance, canBumpTx, getSpendableBalance } = brc20Enabled
|
|
100
|
+
? brc20BalancesAndFeeAdapterFactory({ ...baseFeeResolver, getBalances: baseGetBalances })
|
|
101
|
+
: { ...baseFeeResolver, getBalances: baseGetBalances }
|
|
102
|
+
|
|
77
103
|
const sendTx = createAndBroadcastTXFactory({
|
|
78
104
|
getFeeEstimator,
|
|
79
105
|
allowUnconfirmedRbfEnabledUtxos,
|
|
@@ -99,11 +125,44 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
99
125
|
coinInfo,
|
|
100
126
|
}),
|
|
101
127
|
})
|
|
102
|
-
const feeData = bitcoinFeeDataFactory(asset.currency)
|
|
103
128
|
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
const
|
|
129
|
+
const accountStateClass = createAccountState({ asset: asset, ordinalsEnabled, brc20Enabled })
|
|
130
|
+
|
|
131
|
+
const nfts = ordinalsEnabled ? nftsApiFactory({ ordinalChainIndex, asset }) : undefined
|
|
132
|
+
|
|
133
|
+
const { createToken, getTokens, validateAssetId } = brc20Enabled
|
|
134
|
+
? createTokenFactory({ address, bip44, keys, getBalances }, [])
|
|
135
|
+
: {}
|
|
136
|
+
|
|
137
|
+
const createHistoryMonitor = (args) => {
|
|
138
|
+
const monitor = createBitcoinMonitor({
|
|
139
|
+
insightClient,
|
|
140
|
+
ordinalsEnabled,
|
|
141
|
+
ordinalChainIndex,
|
|
142
|
+
apiUrl,
|
|
143
|
+
...args,
|
|
144
|
+
})
|
|
145
|
+
const assetClientInterface = args.assetClientInterface
|
|
146
|
+
if (ordinalsEnabled) {
|
|
147
|
+
nfts.initialize({ assetClientInterface })
|
|
148
|
+
}
|
|
149
|
+
if (brc20Enabled) {
|
|
150
|
+
const brc20Client = brc20ApiClientFactory()
|
|
151
|
+
monitor.addHook('after-tick', async ({ walletAccount }) => {
|
|
152
|
+
const { unknownBrc20Ticks } = await reloadBrc20TokenBalances({
|
|
153
|
+
walletAccount,
|
|
154
|
+
asset,
|
|
155
|
+
ordinalChainIndex,
|
|
156
|
+
brc20Client,
|
|
157
|
+
assetClientInterface,
|
|
158
|
+
})
|
|
159
|
+
if (unknownBrc20Ticks.length) {
|
|
160
|
+
monitor.emit('unknown-tokens', unknownBrc20Ticks)
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
return monitor
|
|
165
|
+
}
|
|
107
166
|
|
|
108
167
|
const addressHasHistory = async (address) => {
|
|
109
168
|
assert(typeof address === 'string', 'Address is required')
|
|
@@ -128,7 +187,7 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
128
187
|
broadcastTx: (...args) => insightClient.broadcastTx(...args),
|
|
129
188
|
createFeeMonitor: (args) =>
|
|
130
189
|
new BitcoinFeeMonitor({ ...args, insight: () => insightClient, assetName: asset.name }),
|
|
131
|
-
createHistoryMonitor
|
|
190
|
+
createHistoryMonitor,
|
|
132
191
|
features,
|
|
133
192
|
getFeeData: () => feeData,
|
|
134
193
|
getBalances,
|
|
@@ -146,6 +205,10 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
146
205
|
signTx,
|
|
147
206
|
getFee,
|
|
148
207
|
moveFunds,
|
|
208
|
+
nfts,
|
|
209
|
+
createToken,
|
|
210
|
+
getTokens,
|
|
211
|
+
validateAssetId,
|
|
149
212
|
}
|
|
150
213
|
|
|
151
214
|
const fullAsset = {
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { brc20ApiClientFactory } from '../brc-20-client'
|
|
2
|
+
|
|
3
|
+
describe('brc-20-client integration tests', () => {
|
|
4
|
+
const client = brc20ApiClientFactory()
|
|
5
|
+
|
|
6
|
+
test('getOwnerTickBalances bc1p8ypcxhyp4qrdt2f4u79gwuq8z3hxrjx67gygzcrrvcgzta7x7lnqnpwjkw', async () => {
|
|
7
|
+
const result = await client.getOwnerTickBalances({
|
|
8
|
+
address: 'bc1p8ypcxhyp4qrdt2f4u79gwuq8z3hxrjx67gygzcrrvcgzta7x7lnqnpwjkw',
|
|
9
|
+
})
|
|
10
|
+
expect(result.length).toBeGreaterThan(0)
|
|
11
|
+
result.forEach((item) => {
|
|
12
|
+
expect(item).toEqual({
|
|
13
|
+
brc20Tick: expect.any(String),
|
|
14
|
+
brc20OwnerAvailableBalance: expect.any(Number),
|
|
15
|
+
brc20OwnerTransferBalance: expect.any(Number),
|
|
16
|
+
brc20OwnerTotalBalance: expect.any(Number),
|
|
17
|
+
numValidTransferTokens: expect.any(Number),
|
|
18
|
+
txBlockHeight: expect.any(Number),
|
|
19
|
+
txId: expect.any(String),
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('getTickerInfo', async () => {
|
|
25
|
+
const result = await client.getTickerInfo({
|
|
26
|
+
tick: 'oxbt',
|
|
27
|
+
})
|
|
28
|
+
expect(result).toEqual([
|
|
29
|
+
{
|
|
30
|
+
inscriptionId: 'c0e650f33432b627ac0346e9cbdfd30f2b8590c16236c42cd45498b0f27f5c4ei0',
|
|
31
|
+
inscriptionNumber: 5583748,
|
|
32
|
+
txBlockTime: '2023-05-11T05:15:31.000Z',
|
|
33
|
+
owner: 'bc1pr7khxjkmhqduddgn3u9gdmdpuh728ul5azlmnh5uj2e3dn7jd6qsd3pfqh',
|
|
34
|
+
brc20Tick: 'oxbt',
|
|
35
|
+
brc20Dec: 18,
|
|
36
|
+
brc20Lim: 200000000,
|
|
37
|
+
brc20Max: 200000000,
|
|
38
|
+
unitPriceFloorInSat: expect.any(Number),
|
|
39
|
+
},
|
|
40
|
+
])
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('getTickerInfo whe not fund', async () => {
|
|
44
|
+
await expect(
|
|
45
|
+
client.getTickerInfo({
|
|
46
|
+
tick: 'a',
|
|
47
|
+
})
|
|
48
|
+
).rejects.toEqual(new Error('Not Found'))
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('getTokenTransactionHistory', async () => {
|
|
52
|
+
const result = await client.getTokenTransactionHistory({
|
|
53
|
+
owner: 'bc1p8ypcxhyp4qrdt2f4u79gwuq8z3hxrjx67gygzcrrvcgzta7x7lnqnpwjkw',
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
expect(result.length).toBeGreaterThan(0)
|
|
57
|
+
result.forEach((item) => {
|
|
58
|
+
const expected = {
|
|
59
|
+
inscriptionId: expect.any(String),
|
|
60
|
+
inscriptionNumber: expect.any(Number),
|
|
61
|
+
txId: expect.any(String),
|
|
62
|
+
txBlockHash: expect.any(String),
|
|
63
|
+
txBlockHeight: expect.any(Number),
|
|
64
|
+
txBlockIndex: expect.any(Number),
|
|
65
|
+
txBlockTime: expect.any(String),
|
|
66
|
+
createdAt: expect.any(String),
|
|
67
|
+
owner: expect.any(String),
|
|
68
|
+
brc20Tick: expect.any(String),
|
|
69
|
+
brc20Op: expect.any(String),
|
|
70
|
+
brc20Dec: expect.any(Number),
|
|
71
|
+
brc20Lim: expect.any(Number),
|
|
72
|
+
brc20Max: expect.any(Number),
|
|
73
|
+
brc20Amt: expect.any(Number),
|
|
74
|
+
brc20OwnerAvailableBalance: expect.any(Number),
|
|
75
|
+
brc20OwnerTransferBalance: expect.any(Number), // optional
|
|
76
|
+
}
|
|
77
|
+
expect({
|
|
78
|
+
// optional fields
|
|
79
|
+
brc20OwnerTransferBalance: -1,
|
|
80
|
+
brc20Amt: -1,
|
|
81
|
+
brc20OwnerAvailableBalance: -1,
|
|
82
|
+
...item,
|
|
83
|
+
}).toEqual(expected)
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
})
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { asset as bitcoinMeta } from '@exodus/bitcoin-meta'
|
|
2
|
+
import { UnitType } from '@exodus/currency'
|
|
3
|
+
import { createAccountState } from '@exodus/bitcoin-api'
|
|
4
|
+
import { brc20Utils } from '../brc-20-utils'
|
|
5
|
+
|
|
6
|
+
describe('brc20 utils', () => {
|
|
7
|
+
const asset = { ...bitcoinMeta, baseAsset: bitcoinMeta }
|
|
8
|
+
|
|
9
|
+
const token = {
|
|
10
|
+
name: 'someBrc20Token',
|
|
11
|
+
baseAsset: asset,
|
|
12
|
+
currency: UnitType.create({ base: 0, SOMEBrc20Token: 18 }),
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const AccountStateClass = createAccountState({
|
|
16
|
+
asset: asset,
|
|
17
|
+
ordinalsEnabled: true,
|
|
18
|
+
brc20Enabled: true,
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
const accountState = AccountStateClass.fromJSON({
|
|
22
|
+
t: 'object',
|
|
23
|
+
v: {
|
|
24
|
+
ordinalsUtxos: {
|
|
25
|
+
t: 'utxocollection',
|
|
26
|
+
v: {
|
|
27
|
+
v: {
|
|
28
|
+
bc1pel0va3rpya6hx8m3q9awhp4mcdp6t48xtwyj2pggywuhxn8c6nhqf6pesz: {
|
|
29
|
+
address: 'bc1pel0va3rpya6hx8m3q9awhp4mcdp6t48xtwyj2pggywuhxn8c6nhqf6pesz',
|
|
30
|
+
path: 'm/2/0',
|
|
31
|
+
utxos: [
|
|
32
|
+
{
|
|
33
|
+
txId: 'ecbbd9bbd6daec39e59d48307ce660ff52aaf3f4eee214f0aec4153947c59d0e',
|
|
34
|
+
vout: 0,
|
|
35
|
+
confirmations: 1,
|
|
36
|
+
inscriptionId:
|
|
37
|
+
'08c0288600f13dd7cd3c0bf7580208c8a12bf709b02e96523a67205447e0db08i0',
|
|
38
|
+
script: '5120cfdecec4612775731f71017aeb86bbc343a5d4e65b8925050823b9734cf8d4ee',
|
|
39
|
+
value: '0.0000844 BTC',
|
|
40
|
+
rbfEnabled: true,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
u: { satoshis: 0, bits: 2, BTC: 8 },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
brc20Balances: {
|
|
49
|
+
t: 'object',
|
|
50
|
+
v: {
|
|
51
|
+
someBrc20Token: {
|
|
52
|
+
t: 'object',
|
|
53
|
+
v: {
|
|
54
|
+
bc1p8ypcxhyp4qrdt2f4u79gwuq8z3hxrjx67gygzcrrvcgzta7x7lnqnpwjkw: {
|
|
55
|
+
t: 'object',
|
|
56
|
+
v: {
|
|
57
|
+
brc20Tick: 'fern',
|
|
58
|
+
brc20OwnerAvailableBalance: 6,
|
|
59
|
+
brc20OwnerTransferBalance: 4,
|
|
60
|
+
brc20OwnerTotalBalance: 10,
|
|
61
|
+
transferableList: {
|
|
62
|
+
t: 'array',
|
|
63
|
+
v: [
|
|
64
|
+
{
|
|
65
|
+
t: 'object',
|
|
66
|
+
v: {
|
|
67
|
+
inscriptionId:
|
|
68
|
+
'9401713d1f4a9cf22b1874483efc06d00233111b05ba15c92d73fc538aec6300i0', // unknown ordinal utxo, removed from balance
|
|
69
|
+
inscriptionNumber: 25948154,
|
|
70
|
+
brc20Amt: 3,
|
|
71
|
+
txId: '9401713d1f4a9cf22b1874483efc06d00233111b05ba15c92d73fc538aec6300',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
t: 'object',
|
|
76
|
+
v: {
|
|
77
|
+
inscriptionId:
|
|
78
|
+
'08c0288600f13dd7cd3c0bf7580208c8a12bf709b02e96523a67205447e0db08i0',
|
|
79
|
+
inscriptionNumber: 25948124,
|
|
80
|
+
brc20Amt: 1,
|
|
81
|
+
txId: '08c0288600f13dd7cd3c0bf7580208c8a12bf709b02e96523a67205447e0db08',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
_version: 1,
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('isToken', () => {
|
|
97
|
+
expect(brc20Utils.isToken({ asset: token })).toEqual(true)
|
|
98
|
+
expect(brc20Utils.isToken({ asset })).toEqual(false)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('getTokenBalance', () => {
|
|
102
|
+
expect(
|
|
103
|
+
brc20Utils.getTokenBalance({ asset: token, accountState }).toDefaultString({ unit: true })
|
|
104
|
+
).toEqual('7 SOMEBrc20Token')
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('getInTransitBalance', () => {
|
|
108
|
+
expect(
|
|
109
|
+
brc20Utils.getInTransitBalance({ asset: token, accountState }).toDefaultString({ unit: true })
|
|
110
|
+
).toEqual('3 SOMEBrc20Token')
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('getTransferableBalance', () => {
|
|
114
|
+
expect(
|
|
115
|
+
brc20Utils
|
|
116
|
+
.getTransferableBalance({ asset: token, accountState })
|
|
117
|
+
.toDefaultString({ unit: true })
|
|
118
|
+
).toEqual('1 SOMEBrc20Token')
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('getAvailableBalance', () => {
|
|
122
|
+
expect(
|
|
123
|
+
brc20Utils.getAvailableBalance({ asset: token, accountState }).toDefaultString({ unit: true })
|
|
124
|
+
).toEqual('6 SOMEBrc20Token')
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('getTransferableList', () => {
|
|
128
|
+
expect(
|
|
129
|
+
brc20Utils
|
|
130
|
+
.getTransferableList({ asset: token, accountState })
|
|
131
|
+
.map((item) => ({ ...item, amount: item.amount.toDefaultString({ unit: true }) }))
|
|
132
|
+
).toEqual([
|
|
133
|
+
{
|
|
134
|
+
amount: '1 SOMEBrc20Token',
|
|
135
|
+
inscriptionId: '08c0288600f13dd7cd3c0bf7580208c8a12bf709b02e96523a67205447e0db08i0',
|
|
136
|
+
txId: '08c0288600f13dd7cd3c0bf7580208c8a12bf709b02e96523a67205447e0db08',
|
|
137
|
+
},
|
|
138
|
+
])
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test('getTransferableList', () => {
|
|
142
|
+
expect(
|
|
143
|
+
brc20Utils
|
|
144
|
+
.getAllTransferableList({ asset: token, accountState })
|
|
145
|
+
.map((item) => ({ ...item, amount: item.amount.toDefaultString({ unit: true }) }))
|
|
146
|
+
).toEqual([
|
|
147
|
+
{
|
|
148
|
+
amount: '3 SOMEBrc20Token',
|
|
149
|
+
inscriptionId: '9401713d1f4a9cf22b1874483efc06d00233111b05ba15c92d73fc538aec6300i0',
|
|
150
|
+
txId: '9401713d1f4a9cf22b1874483efc06d00233111b05ba15c92d73fc538aec6300',
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
amount: '1 SOMEBrc20Token',
|
|
154
|
+
inscriptionId: '08c0288600f13dd7cd3c0bf7580208c8a12bf709b02e96523a67205447e0db08i0',
|
|
155
|
+
txId: '08c0288600f13dd7cd3c0bf7580208c8a12bf709b02e96523a67205447e0db08',
|
|
156
|
+
},
|
|
157
|
+
])
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
test('getKnownInscriptionIds', () => {
|
|
161
|
+
expect(brc20Utils.getKnownInscriptionIds({ asset: token, accountState })).toEqual([
|
|
162
|
+
'08c0288600f13dd7cd3c0bf7580208c8a12bf709b02e96523a67205447e0db08i0',
|
|
163
|
+
])
|
|
164
|
+
})
|
|
165
|
+
})
|