@exodus/bitcoin-plugin 1.9.0 → 1.10.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Exodus bitcoin-plugin",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@exodus/basic-utils": "^2.1.0",
|
|
23
23
|
"@exodus/bip32": "^1.1.2",
|
|
24
24
|
"@exodus/bip44-constants": "^195.0.0",
|
|
25
|
-
"@exodus/bitcoin-api": "^2.
|
|
25
|
+
"@exodus/bitcoin-api": "^2.10.0",
|
|
26
26
|
"@exodus/bitcoin-lib": "^2.3.0",
|
|
27
27
|
"@exodus/bitcoin-meta": "^1.0.2",
|
|
28
28
|
"@exodus/crypto": "^1.0.0-rc.1",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"@scure/btc-signer": "^1.1.0",
|
|
49
49
|
"jest-when": "^3.5.1"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "ec2ae412ef3401a8a451568382c9d7a6782cbd6a"
|
|
52
52
|
}
|
package/src/create-asset.js
CHANGED
|
@@ -27,7 +27,7 @@ import assert from 'minimalistic-assert'
|
|
|
27
27
|
import { DEFAULT_ORDINAL_CHAIN_INDEX } from './ordinals/ordinals-constants'
|
|
28
28
|
import { reloadBrc20TokenBalances } from './ordinals/reload-brc20-token-balances'
|
|
29
29
|
import { createTokenFactory } from './ordinals/create-token-factory'
|
|
30
|
-
import { brc20ApiClientFactory } from './ordinals/brc-20-client'
|
|
30
|
+
import { brc20ApiClientFactory, DEFAULT_BRC_20_URL } from './ordinals/brc-20-client'
|
|
31
31
|
import { nftsApiFactory } from './ordinals/nfts'
|
|
32
32
|
import { brc20BalancesAndFeeAdapterFactory } from './ordinals/brc-20-balances-and-fee-adapter'
|
|
33
33
|
import { parseCurrency } from '@exodus/bitcoin-api/src/fee/fee-utils'
|
|
@@ -35,6 +35,8 @@ import { inscriptionsServiceFactory } from './ordinals/inscriptions-service'
|
|
|
35
35
|
import { tickInscriptionIdIndexerFactory } from './ordinals/tick-inscription-id-indexer'
|
|
36
36
|
import { getDefaultAddressPath, getSupportedPurposes } from './compatibility-modes'
|
|
37
37
|
|
|
38
|
+
const DEFAULT_TICKS_BETWEEN_BRC20_FETCHES = 30
|
|
39
|
+
|
|
38
40
|
export const createBitcoinAssetFactory =
|
|
39
41
|
({ asset, apiUrl: defaultApiUrl, coinInfoNetwork }) =>
|
|
40
42
|
({
|
|
@@ -43,11 +45,14 @@ export const createBitcoinAssetFactory =
|
|
|
43
45
|
ordinalChainIndex = DEFAULT_ORDINAL_CHAIN_INDEX,
|
|
44
46
|
ordinalsEnabled = false,
|
|
45
47
|
brc20Enabled = false,
|
|
48
|
+
brc20Url = DEFAULT_BRC_20_URL,
|
|
49
|
+
brc20TickInterval = DEFAULT_TICKS_BETWEEN_BRC20_FETCHES,
|
|
46
50
|
gapLimit = 10,
|
|
47
51
|
refreshGapLimit = 25,
|
|
48
52
|
overrideCallback = ({ asset }) => asset,
|
|
49
53
|
feeDataCustomValues,
|
|
50
54
|
isTestnet = false,
|
|
55
|
+
utxosDescendingOrder = false,
|
|
51
56
|
} = {}) => {
|
|
52
57
|
const apiUrl = customApiUrl || defaultApiUrl
|
|
53
58
|
assert(asset, 'asset is required')
|
|
@@ -100,6 +105,7 @@ export const createBitcoinAssetFactory =
|
|
|
100
105
|
const baseFeeResolver = new GetFeeResolver({
|
|
101
106
|
getFeeEstimator,
|
|
102
107
|
allowUnconfirmedRbfEnabledUtxos,
|
|
108
|
+
utxosDescendingOrder,
|
|
103
109
|
})
|
|
104
110
|
|
|
105
111
|
const feeData = bitcoinFeeDataFactory({
|
|
@@ -113,7 +119,7 @@ export const createBitcoinAssetFactory =
|
|
|
113
119
|
ordinalsEnabled,
|
|
114
120
|
})
|
|
115
121
|
|
|
116
|
-
const brc20Client = brc20Enabled ? brc20ApiClientFactory() : undefined
|
|
122
|
+
const brc20Client = brc20Enabled ? brc20ApiClientFactory({ brc20Url }) : undefined
|
|
117
123
|
const tickInscriptionIdIndexer = brc20Enabled
|
|
118
124
|
? tickInscriptionIdIndexerFactory({ brc20Client })
|
|
119
125
|
: undefined
|
|
@@ -122,6 +128,7 @@ export const createBitcoinAssetFactory =
|
|
|
122
128
|
getFeeEstimator,
|
|
123
129
|
allowUnconfirmedRbfEnabledUtxos,
|
|
124
130
|
ordinalsEnabled,
|
|
131
|
+
utxosDescendingOrder,
|
|
125
132
|
})
|
|
126
133
|
const inscriptionsService = brc20Enabled
|
|
127
134
|
? inscriptionsServiceFactory({
|
|
@@ -194,16 +201,19 @@ export const createBitcoinAssetFactory =
|
|
|
194
201
|
|
|
195
202
|
if (brc20Enabled) {
|
|
196
203
|
monitor.addHook('after-tick', async ({ walletAccount }) => {
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
const brc20UpdateTick = monitor.tickCount[walletAccount] % brc20TickInterval === 0
|
|
205
|
+
if (brc20UpdateTick) {
|
|
206
|
+
const { unknownDeployInscriptionIds } = await reloadBrc20TokenBalances({
|
|
207
|
+
walletAccount,
|
|
208
|
+
asset,
|
|
209
|
+
ordinalChainIndex,
|
|
210
|
+
brc20Client,
|
|
211
|
+
assetClientInterface,
|
|
212
|
+
tickInscriptionIdIndexer,
|
|
213
|
+
})
|
|
214
|
+
if (unknownDeployInscriptionIds.length > 0) {
|
|
215
|
+
monitor.emit('unknown-tokens', unknownDeployInscriptionIds)
|
|
216
|
+
}
|
|
207
217
|
}
|
|
208
218
|
})
|
|
209
219
|
}
|
|
@@ -4,7 +4,7 @@ import ms from 'ms'
|
|
|
4
4
|
|
|
5
5
|
const HTTP_POST_TIMEOUT = ms('30s')
|
|
6
6
|
const DEFAULT_ORDINALS_API_KEY = undefined // ME's api key is included in proxy call
|
|
7
|
-
const DEFAULT_BRC_20_URL = 'https://api-mainnet-magiceden.exodus.io'
|
|
7
|
+
export const DEFAULT_BRC_20_URL = 'https://api-mainnet-magiceden.exodus.io'
|
|
8
8
|
|
|
9
9
|
async function improveErrorMessage(err) {
|
|
10
10
|
if (err.response) {
|
|
@@ -43,12 +43,12 @@ export const brc20ApiClientFactory = ({
|
|
|
43
43
|
|
|
44
44
|
const getOwnerTickBalances = async ({ address }) => {
|
|
45
45
|
assert(address, 'address is required')
|
|
46
|
-
return request(`/v2/ord/
|
|
46
|
+
return request(`/v2/ord/brc20/balances/${encodeURIComponent(address)}`)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
const getTickerInfo = async ({ tick }) => {
|
|
50
50
|
assert(tick, 'tick is required')
|
|
51
|
-
return request(`/v2/ord/
|
|
51
|
+
return request(`/v2/ord/brc20/tokens/${encodeURIComponent(tick)}`)
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
const getTickerInfoByDeployInscriptionId = async ({ deployInscriptionId }) => {
|
|
@@ -58,48 +58,58 @@ export const brc20ApiClientFactory = ({
|
|
|
58
58
|
)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const removeNullUndefined = (obj) =>
|
|
62
|
-
Object.fromEntries(Object.entries(obj).filter(([_, v]) => v !== undefined))
|
|
63
|
-
|
|
64
61
|
const paginatedTransactionHistory = async (queryParams) => {
|
|
65
|
-
const
|
|
62
|
+
const address = queryParams.address
|
|
63
|
+
assert(address, 'address is required')
|
|
66
64
|
const events = []
|
|
67
65
|
const limit = queryParams.limit || 40
|
|
68
66
|
let offset = queryParams.offset || 0
|
|
69
67
|
let response
|
|
70
68
|
do {
|
|
71
|
-
response = await request(
|
|
72
|
-
...resolvedQueryParams,
|
|
69
|
+
response = await request(`/v2/ord/brc20/history/${encodeURIComponent(address)}`, {
|
|
73
70
|
limit,
|
|
74
71
|
offset,
|
|
75
72
|
})
|
|
76
73
|
offset = offset + limit
|
|
77
|
-
events.push(...response.
|
|
74
|
+
events.push(...response.results)
|
|
78
75
|
} while (offset < response.total)
|
|
79
76
|
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
// remap to previous event shape that later logic expects
|
|
78
|
+
return events.map((event) => {
|
|
79
|
+
const brc20OwnerAvailableBalance = Number(event.available_balance)
|
|
80
|
+
const brc20OwnerTransferBalance = Number(event.transferrable_balance)
|
|
81
|
+
assert(!isNaN(brc20OwnerAvailableBalance))
|
|
82
|
+
assert(!isNaN(brc20OwnerTransferBalance))
|
|
83
|
+
const brc20Op =
|
|
84
|
+
event.type === 'inscribe-transfer'
|
|
85
|
+
? 'transfer'
|
|
86
|
+
: event.type === 'inscribe-mint'
|
|
87
|
+
? 'mint'
|
|
88
|
+
: event.type === null
|
|
89
|
+
? 'unknown'
|
|
90
|
+
: event.type
|
|
82
91
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
transactionIds,
|
|
98
|
-
limit,
|
|
99
|
-
offset,
|
|
92
|
+
return {
|
|
93
|
+
brc20Tick: event.ticker,
|
|
94
|
+
inscriptionId: event.inscription_id,
|
|
95
|
+
inscriptionNumber: event.inscription_number,
|
|
96
|
+
txId: event.tx_id,
|
|
97
|
+
createdAt: new Date(event.block_time * 1000).toISOString(),
|
|
98
|
+
owner: address,
|
|
99
|
+
transferFrom: event.from,
|
|
100
|
+
transferTo: event.to,
|
|
101
|
+
brc20Op,
|
|
102
|
+
brc20Amt: event.amount,
|
|
103
|
+
brc20OwnerAvailableBalance, // todo use NUs for adding these
|
|
104
|
+
brc20OwnerTransferBalance, // todo use NUs for adding these
|
|
105
|
+
}
|
|
100
106
|
})
|
|
101
107
|
}
|
|
102
108
|
|
|
109
|
+
const getTokenTransactionHistory = ({ ticker, offset, limit, address }) => {
|
|
110
|
+
return paginatedTransactionHistory({ ticker, offset, limit, address })
|
|
111
|
+
}
|
|
112
|
+
|
|
103
113
|
return {
|
|
104
114
|
setUrl,
|
|
105
115
|
getOwnerTickBalances,
|
|
@@ -72,7 +72,7 @@ export const reloadBrc20TokenBalances = async ({
|
|
|
72
72
|
|
|
73
73
|
const historyLists = await Promise.all(
|
|
74
74
|
addresses.map(async (address) => {
|
|
75
|
-
const tokensHistoryList = await brc20Client.getTokenTransactionHistory({
|
|
75
|
+
const tokensHistoryList = await brc20Client.getTokenTransactionHistory({ address })
|
|
76
76
|
const history = await Promise.all(
|
|
77
77
|
tokensHistoryList.map(async (token) => {
|
|
78
78
|
const deployInscriptionId = await tickInscriptionIdIndexer.getDeployInscriptionId(
|
|
@@ -11,7 +11,7 @@ export const tickInscriptionIdIndexerFactory = ({ brc20Client }) => {
|
|
|
11
11
|
|
|
12
12
|
const loadDeployInscriptionId = async (brc20Tick) => {
|
|
13
13
|
const response = await brc20Client.getTickerInfo({ tick: brc20Tick })
|
|
14
|
-
const deployInscriptionId = response
|
|
14
|
+
const deployInscriptionId = response.token.id
|
|
15
15
|
save({ deployInscriptionId, brc20Tick })
|
|
16
16
|
return deployInscriptionId
|
|
17
17
|
}
|