@exodus/bitcoin-plugin 1.4.2 → 1.5.0-alpha.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.4.2",
3
+ "version": "1.5.0-alpha.0",
4
4
  "description": "Exodus bitcoin-plugin",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -19,11 +19,12 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@exodus/asset-lib": "^3.7.1",
22
- "@exodus/bitcoin-api": "^2.4.1",
22
+ "@exodus/bitcoin-api": "^2.5.0-alpha.0",
23
23
  "@exodus/bitcoin-lib": "^2.2.8",
24
24
  "minimalistic-assert": "^1.0.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@exodus/keychain": "^3.0.0"
28
- }
28
+ },
29
+ "gitHead": "04641210f5ac2a4b490cf348b2917b28cf463ba2"
29
30
  }
@@ -1,5 +1,5 @@
1
1
  import _coinInfo from 'coininfo'
2
- import * as bitcoinjsLib from '@exodus/bitcoinjs-lib'
2
+ import * as bitcoinjsLib from 'bitcoinjs-lib'
3
3
  import createGetKeyIdentifier from '@exodus/bitcoin-lib/lib/key-identifier'
4
4
 
5
5
  import bip44Constants from '@exodus/bip44-constants/by-ticker'
@@ -150,15 +150,15 @@ export const createBitcoinAssetFactory = ({ asset, apiUrl, coinInfoNetwork }) =>
150
150
  if (brc20Enabled) {
151
151
  const brc20Client = brc20ApiClientFactory()
152
152
  monitor.addHook('after-tick', async ({ walletAccount }) => {
153
- const { unknownDeployInscriptionIds } = await reloadBrc20TokenBalances({
153
+ const { unknownBrc20Ticks } = await reloadBrc20TokenBalances({
154
154
  walletAccount,
155
155
  asset,
156
156
  ordinalChainIndex,
157
157
  brc20Client,
158
158
  assetClientInterface,
159
159
  })
160
- if (unknownDeployInscriptionIds.length) {
161
- monitor.emit('unknown-tokens', unknownDeployInscriptionIds)
160
+ if (unknownBrc20Ticks.length) {
161
+ monitor.emit('unknown-tokens', unknownBrc20Ticks)
162
162
  }
163
163
  })
164
164
  }
@@ -49,13 +49,6 @@ export const brc20ApiClientFactory = ({
49
49
  return request(`/v2/ord/btc/brc20/tick_infos/${encodeURIComponent(tick)}`)
50
50
  }
51
51
 
52
- const getTickerInfoByDeployInscriptionId = async ({ deployInscriptionId }) => {
53
- assert(deployInscriptionId, 'deployInscriptionId is required')
54
- return request(
55
- `/v2/ord/btc/brc20/deployed_inscription/${encodeURIComponent(deployInscriptionId)}`
56
- )
57
- }
58
-
59
52
  const removeNullUndefined = (obj) =>
60
53
  Object.fromEntries(Object.entries(obj).filter(([_, v]) => v !== undefined))
61
54
 
@@ -98,11 +91,5 @@ export const brc20ApiClientFactory = ({
98
91
  })
99
92
  }
100
93
 
101
- return {
102
- setUrl,
103
- getOwnerTickBalances,
104
- getTickerInfo,
105
- getTickerInfoByDeployInscriptionId,
106
- getTokenTransactionHistory,
107
- }
94
+ return { setUrl, getOwnerTickBalances, getTickerInfo, getTokenTransactionHistory }
108
95
  }
@@ -1,6 +1,6 @@
1
- export function validateAssetId(assetId) {
1
+ function validateAssetId(assetId) {
2
2
  if (typeof assetId !== 'string') return false
3
- const rgx = /^[a-f0-9]{64}i\d+$/
3
+ const rgx = /^[A-Za-z0-9]{4}$/ // 4 letters/numbers tickers
4
4
  return rgx.test(assetId)
5
5
  }
6
6
 
@@ -2,7 +2,6 @@ import assert from 'minimalistic-assert'
2
2
  import { getInscriptionAddresses } from './get-inscription-addresses'
3
3
  import { groupBy, mapValues } from 'lodash'
4
4
  import { updateAccountStateUtxos } from './ordinals-account-state-utils'
5
- import { memoizeLruCache } from '@exodus/asset-lib'
6
5
  const toTxLog = ({ historyItem, baseAsset, asset }) => {
7
6
  const amount = asset.currency.defaultUnit(historyItem.brc20Amt || 0)
8
7
 
@@ -55,15 +54,6 @@ export const reloadBrc20TokenBalances = async ({
55
54
  ordinalChainIndex,
56
55
  })
57
56
 
58
- const toDeployInscriptionId = memoizeLruCache(
59
- async (tick) => {
60
- const response = await brc20Client.getTickerInfo({ tick })
61
- return response[0].inscriptionId.toLowerCase()
62
- },
63
- (tick) => tick,
64
- 200
65
- )
66
-
67
57
  const assets = await assetClientInterface.getAssetsForNetwork({ baseAssetName: asset.name })
68
58
 
69
59
  const assetByAssetId = Object.values(assets)
@@ -73,29 +63,25 @@ export const reloadBrc20TokenBalances = async ({
73
63
  return map
74
64
  }, new Map())
75
65
 
76
- const unknownDeployInscriptionIds = new Set()
66
+ const unknownBrc20Ticks = new Set()
77
67
  const knownInscriptionIds = new Set()
78
68
 
79
69
  const brc20History = (
80
70
  await Promise.all(
81
71
  addresses.map(async (address) => {
82
72
  const tokensHistoryList = await brc20Client.getTokenTransactionHistory({ owner: address })
83
- return (
84
- await Promise.all(
85
- tokensHistoryList.map(async (token) => {
86
- const deployInscriptionId = await toDeployInscriptionId(token.brc20Tick)
87
- knownInscriptionIds.add(deployInscriptionId)
88
- knownInscriptionIds.add(token.inscriptionId.toLowerCase())
89
- const assetName = assetByAssetId.get(deployInscriptionId)?.name
90
- if (assetName) {
91
- return { ...token, address, assetName, deployInscriptionId }
92
- } else {
93
- unknownDeployInscriptionIds.add(deployInscriptionId)
94
- return undefined
95
- }
96
- })
97
- )
98
- ).filter(Boolean)
73
+ return tokensHistoryList
74
+ .map((token) => {
75
+ knownInscriptionIds.add(token.inscriptionId.toLowerCase())
76
+ const assetName = assetByAssetId.get(token.brc20Tick)?.name
77
+ if (assetName) {
78
+ return { ...token, address, assetName }
79
+ } else {
80
+ unknownBrc20Ticks.add(token.brc20Tick)
81
+ return undefined
82
+ }
83
+ })
84
+ .filter(Boolean)
99
85
  })
100
86
  )
101
87
  ).flat()
@@ -163,6 +149,6 @@ export const reloadBrc20TokenBalances = async ({
163
149
  })
164
150
 
165
151
  return {
166
- unknownDeployInscriptionIds: [...unknownDeployInscriptionIds],
152
+ unknownBrc20Ticks: [...unknownBrc20Ticks],
167
153
  }
168
154
  }