@exodus/bitcoin-plugin 1.32.0 → 1.32.2

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/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.32.2](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-plugin@1.32.1...@exodus/bitcoin-plugin@1.32.2) (2025-03-19)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+
12
+ * fix: remove brc20 dead code (#5286)
13
+
14
+ * fix: spelling (#5284)
15
+
16
+
17
+
18
+ ## [1.32.1](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-plugin@1.32.0...@exodus/bitcoin-plugin@1.32.1) (2025-01-27)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+
24
+ * fix: ETH web3 assert typo (#4826)
25
+
26
+
27
+
6
28
  ## [1.32.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-plugin@1.31.1...@exodus/bitcoin-plugin@1.32.0) (2025-01-10)
7
29
 
8
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/bitcoin-plugin",
3
- "version": "1.32.0",
3
+ "version": "1.32.2",
4
4
  "description": "Bitcoin plugin for Exodus SDK powered wallets",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -23,15 +23,13 @@
23
23
  "dependencies": {
24
24
  "@exodus/asset-lib": "^5.0.0",
25
25
  "@exodus/bip44-constants": "^195.0.0",
26
- "@exodus/bitcoin-api": "^2.30.0",
26
+ "@exodus/bitcoin-api": "^2.31.1",
27
27
  "@exodus/bitcoin-lib": "^2.4.2",
28
28
  "@exodus/bitcoin-meta": "^2.0.1",
29
29
  "@exodus/bitcoinjs": "^1.1.0",
30
- "@exodus/crypto": "^1.0.0-rc.13",
31
30
  "@exodus/fetch": "^1.3.0",
32
31
  "@exodus/models": "^12.0.1",
33
- "@exodus/text-encoding-utf8": "^1.0.2",
34
- "@exodus/web3-bitcoin-utils": "^2.3.0",
32
+ "@exodus/web3-bitcoin-utils": "^2.3.3",
35
33
  "coininfo": "^5.1.0",
36
34
  "lodash": "^4.17.21",
37
35
  "minimalistic-assert": "^1.0.1",
@@ -58,5 +56,5 @@
58
56
  "type": "git",
59
57
  "url": "git+https://github.com/ExodusMovement/assets.git"
60
58
  },
61
- "gitHead": "94e7e3c3c61802ff79891bf67e66e9f2b87b80a6"
59
+ "gitHead": "f1b6ccb198231db1fb6c9c51a0173967ec4efd1f"
62
60
  }
@@ -33,18 +33,10 @@ import { createGetSupportedPurposes, getDefaultAddressPath } from './compatibili
33
33
  import { createCustomFeesApi } from './custom-fees.js'
34
34
  import { bitcoinFeeDataFactory } from './fee-data.js'
35
35
  import BitcoinFeeMonitor from './fee-monitor.js'
36
- import { brc20BalancesAndFeeAdapterFactory } from './ordinals/brc-20-balances-and-fee-adapter.js'
37
- import { brc20ApiClientFactory, DEFAULT_BRC_20_URL } from './ordinals/brc-20-client.js'
38
- import { createTokenFactory } from './ordinals/create-token-factory.js'
39
- import { inscriptionsServiceFactory } from './ordinals/inscriptions-service.js'
40
36
  import { nftsApiFactory } from './ordinals/nfts.js'
41
37
  import { DEFAULT_ORDINAL_CHAIN_INDEX } from './ordinals/ordinals-constants.js'
42
- import { reloadBrc20TokenBalances } from './ordinals/reload-brc20-token-balances.js'
43
- import { tickInscriptionIdIndexerFactory } from './ordinals/tick-inscription-id-indexer.js'
44
38
  import { createWeb3API } from './web3/index.js'
45
39
 
46
- const DEFAULT_TICKS_BETWEEN_BRC20_FETCHES = 30
47
-
48
40
  export const createBitcoinAssetFactory =
49
41
  ({ asset, apiUrl: defaultApiUrl, coinInfoNetwork, isTestnet = false }) =>
50
42
  (
@@ -56,9 +48,6 @@ export const createBitcoinAssetFactory =
56
48
  allowUnconfirmedRbfEnabledUtxos = false,
57
49
  ordinalChainIndex = DEFAULT_ORDINAL_CHAIN_INDEX,
58
50
  ordinalsEnabled = false,
59
- brc20Enabled = false,
60
- brc20Url = DEFAULT_BRC_20_URL,
61
- brc20TickInterval = DEFAULT_TICKS_BETWEEN_BRC20_FETCHES,
62
51
  gapLimit = 10,
63
52
  refreshGapLimit = 25,
64
53
  feeDataCustomValues,
@@ -74,10 +63,7 @@ export const createBitcoinAssetFactory =
74
63
  assert(asset, 'asset is required')
75
64
  assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
76
65
  assert(apiUrl, 'apiUrl is required')
77
- assert(
78
- brc20Enabled ? ordinalsEnabled : true,
79
- 'if brc20Enabled is true then ordinalsEnabled must be true'
80
- )
66
+
81
67
  const coinInfo = _coinInfo(coinInfoNetwork || asset.name)
82
68
 
83
69
  const insightClient = new InsightAPIClient(apiUrl)
@@ -109,7 +95,6 @@ export const createBitcoinAssetFactory =
109
95
  moveFunds: true,
110
96
  multipleAddresses: true,
111
97
  nfts: ordinalsEnabled,
112
- customTokens: brc20Enabled,
113
98
  isTestnet,
114
99
  signWithSigner: true,
115
100
  supportsCustomFees: true,
@@ -120,7 +105,7 @@ export const createBitcoinAssetFactory =
120
105
  addressApi: address,
121
106
  })
122
107
 
123
- const baseFeeResolver = new GetFeeResolver({
108
+ const { getFee, getAvailableBalance, canBumpTx, getSpendableBalance } = new GetFeeResolver({
124
109
  getFeeEstimator,
125
110
  allowUnconfirmedRbfEnabledUtxos,
126
111
  utxosDescendingOrder,
@@ -132,17 +117,12 @@ export const createBitcoinAssetFactory =
132
117
  overrideDefaults: feeDataCustomValues,
133
118
  })
134
119
 
135
- const baseGetBalances = getBalancesFactory({
120
+ const getBalances = getBalancesFactory({
136
121
  feeData,
137
- getSpendableBalance: baseFeeResolver.getSpendableBalance,
122
+ getSpendableBalance,
138
123
  ordinalsEnabled,
139
124
  })
140
125
 
141
- const brc20Client = brc20Enabled ? brc20ApiClientFactory({ brc20Url }) : undefined
142
- const tickInscriptionIdIndexer = brc20Enabled
143
- ? tickInscriptionIdIndexerFactory({ brc20Client })
144
- : undefined
145
-
146
126
  const baseGetPrepareSendTx = getPrepareSendTransaction({
147
127
  getFeeEstimator,
148
128
  allowUnconfirmedRbfEnabledUtxos,
@@ -152,7 +132,7 @@ export const createBitcoinAssetFactory =
152
132
  changeAddressType,
153
133
  })
154
134
 
155
- const baseSendTx = createAndBroadcastTXFactory({
135
+ const sendTx = createAndBroadcastTXFactory({
156
136
  getFeeEstimator,
157
137
  allowUnconfirmedRbfEnabledUtxos,
158
138
  ordinalsEnabled,
@@ -160,29 +140,6 @@ export const createBitcoinAssetFactory =
160
140
  assetClientInterface,
161
141
  changeAddressType,
162
142
  })
163
- const inscriptionsService = brc20Enabled
164
- ? inscriptionsServiceFactory({
165
- asset,
166
- network: coinInfo.toBitcoinJS(),
167
- ordinalChainIndex,
168
- })
169
- : undefined
170
-
171
- const { getFee, getBalances, getAvailableBalance, canBumpTx, getSpendableBalance, sendTx } =
172
- brc20Enabled
173
- ? brc20BalancesAndFeeAdapterFactory({
174
- assetClientInterface,
175
- inscriptionsService,
176
- ...baseFeeResolver,
177
- getBalances: baseGetBalances,
178
- sendTx: baseSendTx,
179
- tickInscriptionIdIndexer,
180
- })
181
- : {
182
- ...baseFeeResolver,
183
- getBalances: baseGetBalances,
184
- sendTx: baseSendTx,
185
- }
186
143
 
187
144
  const prepareForSigning = createPrepareForSigning({
188
145
  assetName: asset.name,
@@ -227,19 +184,14 @@ export const createBitcoinAssetFactory =
227
184
  const accountStateClass = createAccountState({
228
185
  asset,
229
186
  ordinalsEnabled,
230
- brc20Enabled,
231
187
  })
232
188
 
233
189
  const nfts = ordinalsEnabled
234
190
  ? nftsApiFactory({ ordinalChainIndex, asset, assetClientInterface })
235
191
  : undefined
236
192
 
237
- const { createToken, getTokens, validateAssetId } = brc20Enabled
238
- ? createTokenFactory({ address, bip44, keys, getBalances }, [])
239
- : {}
240
-
241
193
  const createHistoryMonitor = (args) => {
242
- const monitor = createBitcoinMonitor({
194
+ return createBitcoinMonitor({
243
195
  assetClientInterface,
244
196
  insightClient,
245
197
  ordinalsEnabled,
@@ -249,27 +201,6 @@ export const createBitcoinAssetFactory =
249
201
  refreshGapLimit,
250
202
  ...args,
251
203
  })
252
-
253
- if (brc20Enabled) {
254
- monitor.addHook('after-tick', async ({ walletAccount }) => {
255
- const brc20UpdateTick = monitor.tickCount[walletAccount] % brc20TickInterval === 0
256
- if (brc20UpdateTick) {
257
- const { unknownDeployInscriptionIds } = await reloadBrc20TokenBalances({
258
- walletAccount,
259
- asset,
260
- ordinalChainIndex,
261
- brc20Client,
262
- assetClientInterface,
263
- tickInscriptionIdIndexer,
264
- })
265
- if (unknownDeployInscriptionIds.length > 0) {
266
- monitor.emit('unknown-tokens', unknownDeployInscriptionIds)
267
- }
268
- }
269
- })
270
- }
271
-
272
- return monitor
273
204
  }
274
205
 
275
206
  const addressHasHistory = async (address) => {
@@ -372,10 +303,13 @@ export const createBitcoinAssetFactory =
372
303
  getFee,
373
304
  moveFunds,
374
305
  nfts,
375
- createToken,
376
- getTokens,
377
- validateAssetId,
378
- web3: createWeb3API({ asset, assetClientInterface, prepareForSigning }),
306
+ web3: createWeb3API({
307
+ assetClientInterface,
308
+ baseAssetName: asset.name,
309
+ currency: asset.currency,
310
+ insightClient,
311
+ prepareForSigning,
312
+ }),
379
313
  }
380
314
 
381
315
  const fullAsset = {
@@ -392,7 +326,6 @@ export const createBitcoinAssetFactory =
392
326
  canBumpTx,
393
327
  getAvailableBalance,
394
328
  getSpendableBalance,
395
- inscriptions: inscriptionsService,
396
329
  prepareSendTx: baseGetPrepareSendTx,
397
330
  createBatchTx,
398
331
  encodeMultisigContract,
@@ -406,9 +339,6 @@ export const createBitcoinAssetFactory =
406
339
  allowUnconfirmedRbfEnabledUtxos,
407
340
  ordinalChainIndex,
408
341
  ordinalsEnabled,
409
- brc20Enabled,
410
- brc20Url,
411
- brc20TickInterval,
412
342
  gapLimit,
413
343
  refreshGapLimit,
414
344
  feeDataCustomValues,
@@ -1,8 +1,3 @@
1
- // Ordinal postage is the amount of sats left in an inscription for future transferring fee
2
- // Wallet may use some postage when transferring an ordinal utxos or consume the fee from another regular utxos
3
- // In general, wallets don't spend the postage.
4
- export const DEFAULT_BRC20_POSTAGE = 546
5
-
6
1
  export const DEFAULT_ORDINAL_POSTAGE = 10_000
7
2
 
8
3
  // What's the taproot chain index to use as the default ordinal address (as in purpose 86, m/2/0).
@@ -2,13 +2,24 @@ import { createSimulateTransactions as createSimulateBitcoinTransactions } from
2
2
  import assert from 'minimalistic-assert'
3
3
 
4
4
  // This function accepts either a list of transactions created by a wallet (unsignedTxs) or a web3 transaction (transactionBuffers).
5
- export const createSimulateTransactions = ({ asset, assetClientInterface, prepareForSigning }) => {
6
- assert('asset', '"asset" should be passed.')
7
- assert('assetClientInterface', '"assetClientInterface" should be passed.')
8
- assert('prepareForSigning', '"prepareForSigning" should be passed')
5
+ export const createSimulateTransactions = ({
6
+ assetClientInterface,
7
+ baseAssetName,
8
+ currency,
9
+ insightClient,
10
+ prepareForSigning,
11
+ }) => {
12
+ assert(assetClientInterface, '"assetClientInterface" should be passed.')
13
+ assert(baseAssetName, '"baseAssetName" should be passed.')
14
+ assert(currency, '"currency" should be passed.')
15
+ assert(insightClient, '"insightClient" should be passed.')
16
+ assert(prepareForSigning, '"prepareForSigning" should be passed')
9
17
 
10
18
  const simulateBitcoinTransactions = createSimulateBitcoinTransactions({
11
- logger: assetClientInterface.createLogger(`${asset.name}:simulation`),
19
+ baseAssetName,
20
+ currency,
21
+ insightClient,
22
+ logger: assetClientInterface.createLogger(`${baseAssetName}:simulation`),
12
23
  })
13
24
 
14
25
  return function simulateTransactions({ transactionBuffers, unsignedTxs, ...restParameters }) {
@@ -52,7 +63,6 @@ export const createSimulateTransactions = ({ asset, assetClientInterface, prepar
52
63
  }, {})
53
64
 
54
65
  return simulateBitcoinTransactions({
55
- asset,
56
66
  transactions: [psbtBase64],
57
67
  walletAddresses,
58
68
  indexToAddressRecord,
@@ -1,212 +0,0 @@
1
- import { getOrdinalsUtxos } from '@exodus/bitcoin-api'
2
- import { BumpType } from '@exodus/bitcoin-lib'
3
- import { Address, UtxoCollection } from '@exodus/models'
4
- import assert from 'minimalistic-assert'
5
-
6
- import { brc20Utils } from './brc-20-utils.js'
7
- import { createBrc20Command } from './create-brc-20-command.js'
8
-
9
- export const brc20BalancesAndFeeAdapterFactory = ({
10
- assetClientInterface,
11
- inscriptionsService,
12
- getBalances,
13
- getFee,
14
- getAvailableBalance,
15
- canBumpTx,
16
- getSpendableBalance,
17
- sendTx,
18
- tickInscriptionIdIndexer,
19
- }) => {
20
- assert(inscriptionsService, 'inscriptionsService is required')
21
- assert(getBalances, 'getBalances is required')
22
- assert(getFee, 'getFee is required')
23
- assert(getAvailableBalance, 'getAvailableBalance is required')
24
- assert(canBumpTx, 'canBumpTx is required')
25
- assert(getSpendableBalance, 'getSpendableBalance is required')
26
- assert(sendTx, 'sendTx is required')
27
- assert(tickInscriptionIdIndexer, 'unknownDeployInscriptionIds is required')
28
-
29
- const { isToken, getTokenBalance } = brc20Utils
30
-
31
- const isInscription = ({ options }) => {
32
- return !options?.feeOpts?.inscriptionIds?.length
33
- }
34
-
35
- const sendBrc20 = async ({ asset: token, walletAccount, address, amount, options }) => {
36
- const { broadcastInscription, createBrc20Inscription } = inscriptionsService
37
-
38
- const { customFee, isSendAll } = options || {}
39
-
40
- const asset = token.baseAsset
41
- const accountState = await assetClientInterface.getAccountState({
42
- walletAccount,
43
- assetName: asset.name,
44
- })
45
-
46
- const tick = await tickInscriptionIdIndexer.getBrc20TickFromAsset(token)
47
-
48
- const tokenAmount =
49
- (isSendAll ? getTokenBalance({ asset: token, accountState }) : amount) || token.currency.ZERO
50
-
51
- if (tokenAmount.lte(token.currency.ZERO)) {
52
- throw new Error(
53
- `Cannot send ${tokenAmount.toDefaultString({ unit: true })} amount for asset :${
54
- token.name
55
- }. Tick: ${tick}`
56
- )
57
- }
58
-
59
- const { inscriptionIds, newInscriptions } = createBrc20Command({
60
- asset: token,
61
- amount: tokenAmount,
62
- accountState,
63
- })
64
-
65
- for (const newInscription of newInscriptions) {
66
- const inscription = createBrc20Inscription({
67
- op: 'transfer',
68
- tick,
69
- amt: newInscription.amount.toDefaultString({ unit: false }),
70
- })
71
-
72
- const inscriptionResult = await broadcastInscription({
73
- asset,
74
- assetClientInterface,
75
- walletAccount,
76
- receiverWalletAccount: walletAccount,
77
- inscription,
78
- customFee,
79
- })
80
-
81
- inscriptionIds.push(inscriptionResult.inscriptionId)
82
- }
83
-
84
- return sendTx({
85
- asset: token,
86
- walletAccount,
87
- address,
88
- amount: tokenAmount,
89
- options: {
90
- ...options,
91
- isRbfAllowed: false,
92
- brc20: { inscriptionIds },
93
- },
94
- })
95
- }
96
-
97
- const getFeeBrc20 = ({
98
- asset: token,
99
- accountState,
100
- txSet,
101
- feeData,
102
- amount,
103
- customFee,
104
- isSendAll,
105
- }) => {
106
- const { getInscriptionFees, createBrc20Inscription } = inscriptionsService
107
-
108
- const asset = token.baseAsset
109
-
110
- const availableBalance = getTokenBalance({ asset: token, accountState })
111
-
112
- const tokenAmount = (isSendAll ? availableBalance : amount) || token.currency.ZERO
113
-
114
- if (tokenAmount.lte(token.currency.ZERO) || availableBalance.lt(tokenAmount)) {
115
- return { fee: asset.currency.ZERO }
116
- }
117
-
118
- const { inscriptionIds, newInscriptions } = createBrc20Command({
119
- asset: token,
120
- amount: tokenAmount,
121
- accountState,
122
- })
123
-
124
- const newInscriptionFees = []
125
-
126
- let index = 0
127
- for (const newInscription of newInscriptions) {
128
- const inscription = createBrc20Inscription({
129
- op: 'transfer',
130
- tick: 'abcd',
131
- amt: newInscription.amount.toDefaultString({ unit: false }),
132
- })
133
- const newInscriptionFee = getInscriptionFees({
134
- asset,
135
- getFee,
136
- txSet,
137
- inscription,
138
- customFee,
139
- accountState,
140
- feeData,
141
- })
142
- newInscriptionFees.push(newInscriptionFee)
143
- const inscriptionId = `new_inscription_${index++}`
144
- newInscription.inscriptionId = inscriptionId
145
- inscriptionIds.push(inscriptionId) // this is just to count how many utxos needs to be send in the last txs
146
- }
147
-
148
- const ordinalsUtxos = getOrdinalsUtxos({ accountState, asset })
149
-
150
- const mockedOrdinalsUtxos = ordinalsUtxos.union(
151
- UtxoCollection.fromArray(
152
- newInscriptions.map(({ address, inscriptionId }, index) => {
153
- return {
154
- address: Address.create(address),
155
- txId: inscriptionId,
156
- confirmations: 1,
157
- value: '600 satoshis',
158
- vout: 0,
159
- script: '5120d96a4516786abc536ac4445887262770134f2ab139012856c1f3fdd13c1b02ac', // dummy taproot script
160
- inscriptions: [{ inscriptionId, offset: 0 }],
161
- }
162
- }),
163
- { currency: asset.currency }
164
- )
165
- )
166
- const { fee: lastSendingFee } = getFee({
167
- asset,
168
- accountState: {
169
- ...accountState,
170
- ordinalsUtxos: mockedOrdinalsUtxos,
171
- },
172
- txSet,
173
- feeData,
174
- amount: asset.currency.ZERO,
175
- customFee,
176
- brc20: { inscriptionIds },
177
- })
178
-
179
- const fee = newInscriptionFees.reduce(
180
- (total, newInscriptionFee) => total.add(newInscriptionFee.totalFee),
181
- lastSendingFee
182
- )
183
-
184
- return { fee, lastSendingFee, newInscriptionFees }
185
- }
186
-
187
- return {
188
- canBumpTx: (args) => {
189
- return isToken(args) ? { bumpType: BumpType.NONE } : canBumpTx(args)
190
- },
191
-
192
- getSpendableBalance: (args) => {
193
- return isToken(args) ? getTokenBalance(args) : getSpendableBalance(args)
194
- },
195
-
196
- getFee: (args) => {
197
- return isToken(args) ? getFeeBrc20(args) : getFee(args)
198
- },
199
-
200
- getAvailableBalance: (args) => {
201
- return isToken(args) ? getTokenBalance(args) : getAvailableBalance(args)
202
- },
203
-
204
- getBalances: (args) => {
205
- return isToken(args) ? { balance: getTokenBalance(args) } : getBalances(args)
206
- },
207
-
208
- sendTx: (...args) => {
209
- return isToken(args[0]) && isInscription(...args) ? sendBrc20(...args) : sendTx(...args)
210
- },
211
- }
212
- }
@@ -1,120 +0,0 @@
1
- import { fetchival } from '@exodus/fetch'
2
- import assert from 'minimalistic-assert'
3
- import ms from 'ms'
4
-
5
- const HTTP_POST_TIMEOUT = ms('30s')
6
- const DEFAULT_ORDINALS_API_KEY = undefined // ME's api key is included in proxy call
7
- export const DEFAULT_BRC_20_URL = 'https://api-mainnet-magiceden.exodus.io'
8
-
9
- async function improveErrorMessage(err) {
10
- if (err.response) {
11
- try {
12
- const responseText = await err.response.text()
13
- if (responseText)
14
- // eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
15
- return Promise.reject(new Error(`${err.message}. Error: ${responseText.slice(0, 200)}`)) // trying to get error more info from body)
16
- } catch {}
17
- }
18
-
19
- throw new Error(err.message)
20
- }
21
-
22
- export const brc20ApiClientFactory = ({
23
- brc20Url = DEFAULT_BRC_20_URL,
24
- ordinalsApiKey = DEFAULT_ORDINALS_API_KEY,
25
- } = {}) => {
26
- let baseUrl = brc20Url
27
-
28
- const setUrl = (newBaseUrl) => {
29
- baseUrl = newBaseUrl || DEFAULT_BRC_20_URL
30
- }
31
-
32
- const request = (path, queryParams) => {
33
- const headers = {
34
- Accept: 'application/json',
35
- 'Content-Type': 'application/json',
36
- }
37
- if (ordinalsApiKey) headers.Authorization = `Bearer ${ordinalsApiKey}`
38
-
39
- return fetchival(baseUrl + path, { headers, timeout: HTTP_POST_TIMEOUT })
40
- .get(queryParams)
41
- .catch(improveErrorMessage)
42
- }
43
-
44
- const getOwnerTickBalances = async ({ address }) => {
45
- assert(address, 'address is required')
46
- return request(`/v2/ord/brc20/balances/${encodeURIComponent(address)}`)
47
- }
48
-
49
- const getTickerInfo = async ({ tick }) => {
50
- assert(tick, 'tick is required')
51
- return request(`/v2/ord/brc20/tokens/${encodeURIComponent(tick)}`)
52
- }
53
-
54
- const getTickerInfoByDeployInscriptionId = async ({ deployInscriptionId }) => {
55
- assert(deployInscriptionId, 'deployInscriptionId is required')
56
- return request(
57
- `/v2/ord/btc/brc20/deployed_inscription/${encodeURIComponent(deployInscriptionId)}`
58
- )
59
- }
60
-
61
- const paginatedTransactionHistory = async (queryParams) => {
62
- const address = queryParams.address
63
- assert(address, 'address is required')
64
- const events = []
65
- const limit = queryParams.limit || 40
66
- let offset = queryParams.offset || 0
67
- let response
68
- do {
69
- response = await request(`/v2/ord/brc20/history/${encodeURIComponent(address)}`, {
70
- limit,
71
- offset,
72
- })
73
- offset = offset + limit
74
- events.push(...response.results)
75
- } while (offset < response.total)
76
-
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
91
-
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
- }
106
- })
107
- }
108
-
109
- const getTokenTransactionHistory = ({ ticker, offset, limit, address }) => {
110
- return paginatedTransactionHistory({ ticker, offset, limit, address })
111
- }
112
-
113
- return {
114
- setUrl,
115
- getOwnerTickBalances,
116
- getTickerInfo,
117
- getTickerInfoByDeployInscriptionId,
118
- getTokenTransactionHistory,
119
- }
120
- }