@exodus/bitcoin-plugin 1.9.0 → 1.10.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-plugin",
3
- "version": "1.9.0",
3
+ "version": "1.10.1",
4
4
  "description": "Exodus bitcoin-plugin",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -22,14 +22,14 @@
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.9.4",
25
+ "@exodus/bitcoin-api": "^2.10.1",
26
26
  "@exodus/bitcoin-lib": "^2.3.0",
27
27
  "@exodus/bitcoin-meta": "^1.0.2",
28
+ "@exodus/bitcoinjs-lib": "^6.1.5-exodus.1",
28
29
  "@exodus/crypto": "^1.0.0-rc.1",
29
30
  "@exodus/fetch": "^1.3.0",
30
31
  "@exodus/models": "^11.0.0",
31
32
  "@exodus/text-encoding-utf8": "^1.0.2",
32
- "bitcoinjs-lib": "^6.1.5",
33
33
  "coininfo": "5.1.0",
34
34
  "create-hash": "^1.2.0",
35
35
  "lodash": "^4.17.21",
@@ -48,5 +48,5 @@
48
48
  "@scure/btc-signer": "^1.1.0",
49
49
  "jest-when": "^3.5.1"
50
50
  },
51
- "gitHead": "a3d4e16dc0b19901cd976cd699814c7070fa116a"
51
+ "gitHead": "59489f1962adac06d14642120d7fe97e2a4f6d43"
52
52
  }
@@ -6,7 +6,7 @@ export const trezor = 'trezor'
6
6
  export const ledger = 'ledger'
7
7
  export const xverse49 = 'xverse49'
8
8
 
9
- export const getDefaultAddressPath = ({ compatibilityMode }) => {
9
+ export const getDefaultAddressPath = ({ compatibilityMode } = Object.create(null)) => {
10
10
  if ([ordinals84, ordinals86].includes(compatibilityMode)) {
11
11
  return 'm/0'
12
12
  }
@@ -1,5 +1,5 @@
1
1
  import _coinInfo from 'coininfo'
2
- import * as bitcoinjsLib from 'bitcoinjs-lib'
2
+ import * as bitcoinjsLib from '@exodus/bitcoinjs-lib'
3
3
  import { createGetKeyIdentifier } from '@exodus/bitcoin-lib'
4
4
 
5
5
  import bip44Constants from '@exodus/bip44-constants/by-ticker'
@@ -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 { unknownDeployInscriptionIds } = await reloadBrc20TokenBalances({
198
- walletAccount,
199
- asset,
200
- ordinalChainIndex,
201
- brc20Client,
202
- assetClientInterface,
203
- tickInscriptionIdIndexer,
204
- })
205
- if (unknownDeployInscriptionIds.length > 0) {
206
- monitor.emit('unknown-tokens', unknownDeployInscriptionIds)
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/btc/brc20/owner_balances/${encodeURIComponent(address)}`)
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/btc/brc20/tick_infos/${encodeURIComponent(tick)}`)
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 resolvedQueryParams = removeNullUndefined(queryParams)
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('/v2/ord/btc/brc20/events', {
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.events)
74
+ events.push(...response.results)
78
75
  } while (offset < response.total)
79
76
 
80
- return events
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
- const getTokenTransactionHistory = ({
84
- tick,
85
- owner,
86
- brc20Op,
87
- showInvalid,
88
- transactionIds,
89
- limit,
90
- offset,
91
- }) => {
92
- return paginatedTransactionHistory({
93
- tick,
94
- owner,
95
- brc20Op,
96
- showInvalid,
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,
@@ -1,11 +1,11 @@
1
1
  import assert from 'minimalistic-assert'
2
- import * as bitcoinjsLib from 'bitcoinjs-lib'
2
+ import * as bitcoinjsLib from '@exodus/bitcoinjs-lib'
3
3
  import { TextEncoder } from '@exodus/text-encoding-utf8'
4
4
  import { randomBytes } from '@exodus/crypto/randomBytes'
5
5
  import secp256k1 from 'tiny-secp256k1'
6
6
  import { DEFAULT_BRC20_POSTAGE, DEFAULT_ORDINAL_POSTAGE } from './ordinals-constants'
7
7
 
8
- import { witnessStackToScriptWitness } from 'bitcoinjs-lib/src/psbt/psbtutils'
8
+ import { witnessStackToScriptWitness } from '@exodus/bitcoinjs-lib/src/psbt/psbtutils'
9
9
  import { getTxSequence } from '@exodus/bitcoin-lib'
10
10
  import {
11
11
  eccFactory,
@@ -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({ owner: address })
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[0].inscriptionId
14
+ const deployInscriptionId = response.token.id
15
15
  save({ deployInscriptionId, brc20Tick })
16
16
  return deployInscriptionId
17
17
  }