@exodus/bitcoin-plugin 1.6.9 → 1.6.11
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-plugin",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.11",
|
|
4
4
|
"description": "Exodus bitcoin-plugin",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -20,11 +20,14 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@exodus/asset-lib": "^4.0.0",
|
|
22
22
|
"@exodus/basic-utils": "^2.1.0",
|
|
23
|
-
"@exodus/bitcoin-api": "^2.
|
|
23
|
+
"@exodus/bitcoin-api": "^2.7.1",
|
|
24
24
|
"@exodus/bitcoin-lib": "^2.2.11",
|
|
25
25
|
"@exodus/models": "^11.0.0",
|
|
26
26
|
"@exodus/text-encoding-utf8": "^1.0.2",
|
|
27
27
|
"minimalistic-assert": "^1.0.1"
|
|
28
28
|
},
|
|
29
|
-
"
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@exodus/nfts-proxy": "^2.10.1"
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "9c993eed3a3bcfc1c49d86377fdc5c7cb731d632"
|
|
30
33
|
}
|
package/src/create-asset.js
CHANGED
|
@@ -15,9 +15,11 @@ import {
|
|
|
15
15
|
getFeeEstimatorFactory,
|
|
16
16
|
GetFeeResolver,
|
|
17
17
|
InsightAPIClient,
|
|
18
|
+
isValidInscription,
|
|
18
19
|
moveFundsFactory,
|
|
19
20
|
parseUnsignedTx,
|
|
20
21
|
signTxFactory,
|
|
22
|
+
signHardwareFactory,
|
|
21
23
|
} from '@exodus/bitcoin-api'
|
|
22
24
|
import { bitcoinFeeDataFactory } from './fee-data'
|
|
23
25
|
import BitcoinFeeMonitor from './fee-monitor'
|
|
@@ -33,7 +35,8 @@ import { inscriptionsServiceFactory } from './ordinals/inscriptions-service'
|
|
|
33
35
|
import { tickInscriptionIdIndexerFactory } from './ordinals/tick-inscription-id-indexer'
|
|
34
36
|
import { getDefaultAddressPath, getSupportedPurposes } from './compatibility-modes'
|
|
35
37
|
|
|
36
|
-
export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) => ({
|
|
38
|
+
export const createBitcoinAssetFactory = ({ asset, apiUrl: defaultApiUrl, coinInfoNetwork }) => ({
|
|
39
|
+
apiUrl: customApiUrl,
|
|
37
40
|
allowUnconfirmedRbfEnabledUtxos = false,
|
|
38
41
|
ordinalChainIndex = DEFAULT_ORDINAL_CHAIN_INDEX,
|
|
39
42
|
ordinalsEnabled = false,
|
|
@@ -41,7 +44,10 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
41
44
|
gapLimit = 10,
|
|
42
45
|
refreshGapLimit = 25,
|
|
43
46
|
overrideCallback = ({ asset }) => asset,
|
|
47
|
+
nftsProxy,
|
|
48
|
+
feeDataCustomValues,
|
|
44
49
|
} = {}) => {
|
|
50
|
+
const apiUrl = customApiUrl || defaultApiUrl
|
|
45
51
|
assert(asset, 'asset is required')
|
|
46
52
|
assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
|
|
47
53
|
assert(apiUrl, 'apiUrl is required')
|
|
@@ -52,6 +58,9 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
52
58
|
const coinInfo = _coinInfo(coinInfoNetwork || asset.name)
|
|
53
59
|
|
|
54
60
|
const insightClient = new InsightAPIClient(apiUrl)
|
|
61
|
+
|
|
62
|
+
if (customApiUrl) insightClient.setBaseUrl = () => {} // not let the configuration override url when providing a custom one
|
|
63
|
+
|
|
55
64
|
const useBip84 = true
|
|
56
65
|
const useBip86 = true
|
|
57
66
|
|
|
@@ -90,7 +99,10 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
90
99
|
allowUnconfirmedRbfEnabledUtxos,
|
|
91
100
|
})
|
|
92
101
|
|
|
93
|
-
const feeData = bitcoinFeeDataFactory(
|
|
102
|
+
const feeData = bitcoinFeeDataFactory({
|
|
103
|
+
currency: asset.currency,
|
|
104
|
+
overrideDefaults: feeDataCustomValues,
|
|
105
|
+
})
|
|
94
106
|
|
|
95
107
|
const baseGetBalances = getBalancesFactory({
|
|
96
108
|
feeData,
|
|
@@ -105,6 +117,7 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
105
117
|
const baseSendTx = createAndBroadcastTXFactory({
|
|
106
118
|
getFeeEstimator,
|
|
107
119
|
allowUnconfirmedRbfEnabledUtxos,
|
|
120
|
+
ordinalsEnabled,
|
|
108
121
|
})
|
|
109
122
|
const inscriptionsService = brc20Enabled
|
|
110
123
|
? inscriptionsServiceFactory({
|
|
@@ -138,6 +151,13 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
138
151
|
coinInfo,
|
|
139
152
|
})
|
|
140
153
|
|
|
154
|
+
const signHardware = signHardwareFactory({
|
|
155
|
+
assetName: asset.name,
|
|
156
|
+
resolvePurpose: address.resolvePurpose,
|
|
157
|
+
keys,
|
|
158
|
+
coinInfo,
|
|
159
|
+
})
|
|
160
|
+
|
|
141
161
|
const moveFunds = moveFundsFactory({
|
|
142
162
|
asset: asset,
|
|
143
163
|
insightClient,
|
|
@@ -153,7 +173,7 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
153
173
|
|
|
154
174
|
const accountStateClass = createAccountState({ asset: asset, ordinalsEnabled, brc20Enabled })
|
|
155
175
|
|
|
156
|
-
const nfts = ordinalsEnabled ? nftsApiFactory({ ordinalChainIndex, asset }) : undefined
|
|
176
|
+
const nfts = ordinalsEnabled ? nftsApiFactory({ ordinalChainIndex, asset, nftsProxy }) : undefined
|
|
157
177
|
|
|
158
178
|
const { createToken, getTokens, validateAssetId } = brc20Enabled
|
|
159
179
|
? createTokenFactory({ address, bip44, keys, getBalances }, [])
|
|
@@ -205,8 +225,18 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
205
225
|
}
|
|
206
226
|
|
|
207
227
|
const isOrdinalTx = (tx) => {
|
|
208
|
-
|
|
209
|
-
|
|
228
|
+
if (!ordinalsEnabled || tx.coinName !== asset.name) {
|
|
229
|
+
return false
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!tx.data.inscriptionsIndexed) {
|
|
233
|
+
return false // allows users seeing the pending tx because we don't know yet if it is ordinals or btc
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
tx.data.receivedInscriptions?.some(isValidInscription) ||
|
|
238
|
+
tx.data.sentInscriptions?.some(isValidInscription)
|
|
239
|
+
)
|
|
210
240
|
}
|
|
211
241
|
|
|
212
242
|
const txLogFilter = (tx) => {
|
|
@@ -221,13 +251,8 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
221
251
|
if (tx.sent && Array.isArray(tx.data.sent) && tx.data.sent.length > 0) {
|
|
222
252
|
const feeAmount = tx.feeAmount.div(tx.data.sent.length)
|
|
223
253
|
return tx.data.sent
|
|
224
|
-
.map((to, i) =>
|
|
225
|
-
|
|
226
|
-
console.warn(
|
|
227
|
-
`${asset.name} tx ${tx.txId} sent index ${i} does not have an amount!!!`
|
|
228
|
-
)
|
|
229
|
-
}
|
|
230
|
-
return tx.update({
|
|
254
|
+
.map((to, i) =>
|
|
255
|
+
tx.update({
|
|
231
256
|
to: to.address,
|
|
232
257
|
data: { sentIndex: i },
|
|
233
258
|
coinAmount: to.amount
|
|
@@ -235,7 +260,7 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
235
260
|
: asset.currency.ZERO,
|
|
236
261
|
feeAmount,
|
|
237
262
|
})
|
|
238
|
-
|
|
263
|
+
)
|
|
239
264
|
.reverse()
|
|
240
265
|
}
|
|
241
266
|
return tx
|
|
@@ -269,6 +294,7 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
|
|
|
269
294
|
signUnsignedTx: (unsignedTx, privateKey, opts) => signTx({ unsignedTx, privateKey, ...opts }), // legacy
|
|
270
295
|
sendTx,
|
|
271
296
|
signTx,
|
|
297
|
+
signHardware,
|
|
272
298
|
getFee,
|
|
273
299
|
moveFunds,
|
|
274
300
|
nfts,
|
package/src/fee-data.js
CHANGED
|
@@ -11,6 +11,7 @@ export const _defaults = {
|
|
|
11
11
|
rbfBumpFeeBlocks: 3,
|
|
12
12
|
rbfBumpFeeThreshold: 0.8,
|
|
13
13
|
rbfEnabled: true,
|
|
14
|
+
utxoDustValue: 0,
|
|
14
15
|
}
|
|
15
|
-
export const bitcoinFeeDataFactory = (currency) =>
|
|
16
|
-
new FeeData({ config: _defaults, mainKey: 'feePerKB', currency })
|
|
16
|
+
export const bitcoinFeeDataFactory = ({ currency, overrideDefaults }) =>
|
|
17
|
+
new FeeData({ config: { ..._defaults, ...overrideDefaults }, mainKey: 'feePerKB', currency })
|
|
@@ -8,7 +8,7 @@ export const brc20Utils = {
|
|
|
8
8
|
assert(asset, 'asset is required')
|
|
9
9
|
return getOrdinalsUtxos({ accountState, asset })
|
|
10
10
|
.toArray()
|
|
11
|
-
.
|
|
11
|
+
.flatMap((utxo) => utxo.inscriptions?.map((i) => i.inscriptionId))
|
|
12
12
|
},
|
|
13
13
|
|
|
14
14
|
getAllTransferableList: ({ accountState, asset }) => {
|
package/src/ordinals/nfts.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert'
|
|
2
2
|
import { getInscriptionAddresses } from './get-inscription-addresses'
|
|
3
|
-
import { updateAccountStateUtxos } from './ordinals-account-state-utils'
|
|
4
3
|
import { isNftBrc20 } from './nft-utils'
|
|
4
|
+
import { getOrdinalsUtxos } from '@exodus/bitcoin-api'
|
|
5
5
|
|
|
6
|
-
export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
6
|
+
export const nftsApiFactory = ({ ordinalChainIndex, asset, nftsProxy }) => {
|
|
7
7
|
assert(asset, 'asset is required')
|
|
8
8
|
assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
|
|
9
9
|
let aci // convert to constructor argument when wallet send aci at createAsset time
|
|
10
|
+
|
|
10
11
|
return {
|
|
11
12
|
initialize: ({ assetClientInterface }) => {
|
|
12
13
|
aci = assetClientInterface
|
|
@@ -27,38 +28,94 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
|
|
|
27
28
|
},
|
|
28
29
|
|
|
29
30
|
/*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*/
|
|
31
|
+
It flags the nfts in transfer, that don't have a utxo anymore
|
|
32
|
+
It removes nfts that have brc20 content
|
|
33
|
+
*/
|
|
34
34
|
postProcessNfts: async ({ nfts, walletAccount: walletAccountInstance }) => {
|
|
35
35
|
if (!aci) {
|
|
36
36
|
console.warn('bitcoin nfts not initialized yet')
|
|
37
37
|
return []
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const { allUpdatedUtxos } = await updateAccountStateUtxos({
|
|
43
|
-
asset,
|
|
40
|
+
const accountState = await aci.getAccountState({
|
|
41
|
+
assetName: asset.name,
|
|
44
42
|
walletAccount: walletAccountInstance.toString(),
|
|
45
|
-
assetClientInterface: aci,
|
|
46
|
-
outputToInscriptionId,
|
|
47
|
-
ordinalChainIndex,
|
|
48
43
|
})
|
|
49
|
-
const
|
|
44
|
+
const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
|
|
45
|
+
|
|
46
|
+
const unconfirmedUtxosArray = storedOrdinalsUtxos
|
|
47
|
+
.toArray()
|
|
48
|
+
.filter((utxo) => !utxo.confirmations)
|
|
49
|
+
|
|
50
|
+
if (nftsProxy) {
|
|
51
|
+
try {
|
|
52
|
+
const retrievedNfts = await Promise.all(
|
|
53
|
+
unconfirmedUtxosArray.map(async (utxo) => {
|
|
54
|
+
const inscriptions = utxo.inscriptions || []
|
|
55
|
+
return Promise.all(
|
|
56
|
+
inscriptions.map(async ({ inscriptionId }) => {
|
|
57
|
+
if (nfts.find((nft) => nft.tokenId === inscriptionId)) {
|
|
58
|
+
return undefined
|
|
59
|
+
}
|
|
60
|
+
const id = `${asset.name}:${inscriptionId}`
|
|
61
|
+
try {
|
|
62
|
+
const json = await nftsProxy.getNft(id)
|
|
63
|
+
return {
|
|
64
|
+
...json,
|
|
65
|
+
receiving: true,
|
|
66
|
+
output: `${utxo.txId}:${utxo.vout}`,
|
|
67
|
+
pendingTxId: utxo.txId,
|
|
68
|
+
}
|
|
69
|
+
} catch (e) {
|
|
70
|
+
console.warn(`Cannot load nft ${id} from proxy server. Error: ${e.message}`)
|
|
71
|
+
return undefined
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
)
|
|
75
|
+
})
|
|
76
|
+
)
|
|
77
|
+
const unconfirmedNfts = retrievedNfts.flat().filter((i) => i)
|
|
78
|
+
nfts.push(...unconfirmedNfts)
|
|
79
|
+
} catch (e) {
|
|
80
|
+
console.warn(
|
|
81
|
+
`There has been an error adding mempool bitcoin ordinals into nfts list. Error: ${e.message}`
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const unconfirmedTxs = Array.from(
|
|
87
|
+
await aci.getTxLog({
|
|
88
|
+
walletAccount: walletAccountInstance.toString(),
|
|
89
|
+
assetName: asset.name,
|
|
90
|
+
})
|
|
91
|
+
).filter((tx) => !tx.confirmations)
|
|
92
|
+
|
|
93
|
+
const utxosOutputs = storedOrdinalsUtxos
|
|
50
94
|
.toArray()
|
|
51
95
|
.map((utxo) => {
|
|
52
96
|
return `${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
53
97
|
})
|
|
54
98
|
.filter(Boolean)
|
|
55
99
|
|
|
56
|
-
const expandedNfts = nfts.map((nft) =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
100
|
+
const expandedNfts = nfts.map((nft) => {
|
|
101
|
+
const sending = !utxosOutputs.includes(nft.output.toLowerCase())
|
|
102
|
+
if (sending) {
|
|
103
|
+
const sendingTx = unconfirmedTxs.find((tx) =>
|
|
104
|
+
tx.data.sentInscriptions?.find((i) => i.inscriptionId === nft.tokenId)
|
|
105
|
+
)
|
|
106
|
+
return {
|
|
107
|
+
...nft,
|
|
108
|
+
sending,
|
|
109
|
+
pendingTxId: sendingTx?.txId,
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
return nft
|
|
113
|
+
}
|
|
114
|
+
})
|
|
60
115
|
|
|
61
|
-
return expandedNfts
|
|
116
|
+
return expandedNfts
|
|
117
|
+
.filter((nft) => !isNftBrc20(nft))
|
|
118
|
+
.map((nft) => ({ ...nft, collectionName: nft.collectionName || 'No Collection' }))
|
|
62
119
|
},
|
|
63
120
|
}
|
|
64
121
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert'
|
|
2
2
|
import { getInscriptionAddresses } from './get-inscription-addresses'
|
|
3
3
|
import { groupBy, mapValues } from 'lodash'
|
|
4
|
-
import { updateAccountStateUtxos } from './ordinals-account-state-utils'
|
|
5
4
|
const toTxLog = ({ historyItem, baseAsset, asset }) => {
|
|
6
5
|
const amount = asset.currency.defaultUnit(historyItem.brc20Amt || 0)
|
|
7
6
|
|
|
@@ -69,7 +68,6 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
69
68
|
}, new Map())
|
|
70
69
|
|
|
71
70
|
const unknownDeployInscriptionIds = new Set()
|
|
72
|
-
const knownInscriptionIds = new Set()
|
|
73
71
|
|
|
74
72
|
const brc20History = (
|
|
75
73
|
await Promise.all(
|
|
@@ -81,8 +79,6 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
81
79
|
const deployInscriptionId = await tickInscriptionIdIndexer.getDeployInscriptionId(
|
|
82
80
|
token.brc20Tick
|
|
83
81
|
)
|
|
84
|
-
knownInscriptionIds.add(deployInscriptionId)
|
|
85
|
-
knownInscriptionIds.add(token.inscriptionId.toLowerCase())
|
|
86
82
|
const assetName = assetByAssetId.get(deployInscriptionId)?.name
|
|
87
83
|
if (assetName) {
|
|
88
84
|
return { ...token, address, assetName, deployInscriptionId }
|
|
@@ -149,15 +145,10 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
149
145
|
})
|
|
150
146
|
)
|
|
151
147
|
|
|
152
|
-
await
|
|
153
|
-
asset,
|
|
148
|
+
await assetClientInterface.updateAccountState({
|
|
149
|
+
assetName: asset.name,
|
|
154
150
|
walletAccount,
|
|
155
|
-
|
|
156
|
-
knownInscriptionIds: [...knownInscriptionIds],
|
|
157
|
-
ordinalChainIndex,
|
|
158
|
-
moreNewData: {
|
|
159
|
-
brc20Balances,
|
|
160
|
-
},
|
|
151
|
+
newData: { brc20Balances },
|
|
161
152
|
})
|
|
162
153
|
|
|
163
154
|
return {
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { getOrdinalsUtxos, getUtxos, partitionUtxos, getOrdinalAddress } from '@exodus/bitcoin-api'
|
|
2
|
-
import { UtxoCollection } from '@exodus/models'
|
|
3
|
-
import { isEmpty, pickBy } from 'lodash'
|
|
4
|
-
import { getOwnProperty } from '@exodus/basic-utils'
|
|
5
|
-
|
|
6
|
-
export const updateAccountStateUtxos = async ({
|
|
7
|
-
asset,
|
|
8
|
-
walletAccount,
|
|
9
|
-
assetClientInterface: aci,
|
|
10
|
-
outputToInscriptionId,
|
|
11
|
-
ordinalChainIndex,
|
|
12
|
-
moreNewData = {},
|
|
13
|
-
}) => {
|
|
14
|
-
const assetName = asset.name
|
|
15
|
-
const accountState = await aci.getAccountState({ assetName, walletAccount })
|
|
16
|
-
const storedUtxos = getUtxos({ accountState, asset })
|
|
17
|
-
const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
|
|
18
|
-
|
|
19
|
-
const allStoredUtxos = storedUtxos.union(storedOrdinalsUtxos)
|
|
20
|
-
const allUpdatedUtxos = UtxoCollection.fromArray(
|
|
21
|
-
allStoredUtxos.toArray().map((utxo) => {
|
|
22
|
-
const inscriptionId = getOwnProperty(
|
|
23
|
-
outputToInscriptionId,
|
|
24
|
-
`${utxo.txId}:${utxo.vout}`.toLowerCase()
|
|
25
|
-
)
|
|
26
|
-
if (inscriptionId) {
|
|
27
|
-
return { ...utxo, inscriptionId }
|
|
28
|
-
}
|
|
29
|
-
return utxo
|
|
30
|
-
}),
|
|
31
|
-
{
|
|
32
|
-
currency: asset.currency,
|
|
33
|
-
}
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
const ordinalAddress = await getOrdinalAddress({
|
|
37
|
-
asset,
|
|
38
|
-
assetClientInterface: aci,
|
|
39
|
-
walletAccount,
|
|
40
|
-
ordinalChainIndex,
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
if (!allUpdatedUtxos.equals(allStoredUtxos) || !isEmpty(moreNewData)) {
|
|
44
|
-
const { utxos, ordinalsUtxos } = partitionUtxos({
|
|
45
|
-
allUtxos: allUpdatedUtxos,
|
|
46
|
-
ordinalAddress,
|
|
47
|
-
})
|
|
48
|
-
const utxosData = pickBy(
|
|
49
|
-
{
|
|
50
|
-
utxos,
|
|
51
|
-
ordinalsUtxos,
|
|
52
|
-
},
|
|
53
|
-
Boolean
|
|
54
|
-
)
|
|
55
|
-
await aci.updateAccountState({
|
|
56
|
-
assetName,
|
|
57
|
-
walletAccount,
|
|
58
|
-
newData: { ...utxosData, ...moreNewData },
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
return { allUpdatedUtxos }
|
|
62
|
-
}
|