@exodus/bitcoin-plugin 1.8.0 → 1.8.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.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Exodus bitcoin-plugin",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -20,7 +20,7 @@
20
20
  "dependencies": {
21
21
  "@exodus/asset-lib": "^4.0.0",
22
22
  "@exodus/basic-utils": "^2.1.0",
23
- "@exodus/bitcoin-api": "^2.9.0",
23
+ "@exodus/bitcoin-api": "^2.9.1",
24
24
  "@exodus/bitcoin-lib": "^2.3.0",
25
25
  "@exodus/models": "^11.0.0",
26
26
  "@exodus/text-encoding-utf8": "^1.0.2",
@@ -29,5 +29,5 @@
29
29
  "devDependencies": {
30
30
  "@exodus/nfts-proxy": "^2.10.1"
31
31
  },
32
- "gitHead": "ed03529f7a8bb4b39bfd173387f9cdd5d7207925"
32
+ "gitHead": "1f96673b2977e792373f9f3c4eb98c778817b2b6"
33
33
  }
@@ -41,12 +41,12 @@ export const brc20ApiClientFactory = ({
41
41
 
42
42
  const getOwnerTickBalances = async ({ address }) => {
43
43
  assert(address, 'address is required')
44
- return request(`/v2/ord/brc20/balances/${encodeURIComponent(address)}`)
44
+ return request(`/v2/ord/btc/brc20/owner_balances/${encodeURIComponent(address)}`)
45
45
  }
46
46
 
47
47
  const getTickerInfo = async ({ tick }) => {
48
48
  assert(tick, 'tick is required')
49
- return request(`/v2/ord/brc20/tokens/${encodeURIComponent(tick)}`)
49
+ return request(`/v2/ord/btc/brc20/tick_infos/${encodeURIComponent(tick)}`)
50
50
  }
51
51
 
52
52
  const getTickerInfoByDeployInscriptionId = async ({ deployInscriptionId }) => {
@@ -56,54 +56,46 @@ export const brc20ApiClientFactory = ({
56
56
  )
57
57
  }
58
58
 
59
+ const removeNullUndefined = (obj) =>
60
+ Object.fromEntries(Object.entries(obj).filter(([_, v]) => v !== undefined))
61
+
59
62
  const paginatedTransactionHistory = async (queryParams) => {
60
- const address = queryParams.address
61
- assert(address, 'address is required')
63
+ const resolvedQueryParams = removeNullUndefined(queryParams)
62
64
  const events = []
63
65
  const limit = queryParams.limit || 40
64
66
  let offset = queryParams.offset || 0
65
67
  let response
66
68
  do {
67
- response = await request(`/v2/ord/brc20/history/${encodeURIComponent(address)}`, {
69
+ response = await request('/v2/ord/btc/brc20/events', {
70
+ ...resolvedQueryParams,
68
71
  limit,
69
72
  offset,
70
73
  })
71
74
  offset = offset + limit
72
- events.push(...response.results)
75
+ events.push(...response.events)
73
76
  } while (offset < response.total)
74
77
 
75
- // remap to previous event shape that later logic expects
76
- return events.map((event) => {
77
- const brc20OwnerAvailableBalance = Number(event.available_balance)
78
- const brc20OwnerTransferBalance = Number(event.transferrable_balance)
79
- assert(!isNaN(brc20OwnerAvailableBalance))
80
- assert(!isNaN(brc20OwnerTransferBalance))
81
- const brc20Op =
82
- event.type === 'inscribe-transfer'
83
- ? 'transfer'
84
- : event.type === 'inscribe-mint'
85
- ? 'mint'
86
- : event.type
87
-
88
- return {
89
- brc20Tick: event.ticker,
90
- inscriptionId: event.inscription_id,
91
- inscriptionNumber: event.inscription_number,
92
- txId: event.tx_id,
93
- createdAt: new Date(event.block_time * 1000).toISOString(),
94
- owner: address,
95
- transferFrom: event.from,
96
- transferTo: event.to,
97
- brc20Op,
98
- brc20Amt: event.amount,
99
- brc20OwnerAvailableBalance, // todo use NUs for adding these
100
- brc20OwnerTransferBalance, // todo use NUs for adding these
101
- }
102
- })
78
+ return events
103
79
  }
104
80
 
105
- const getTokenTransactionHistory = ({ ticker, offset, limit, address }) => {
106
- return paginatedTransactionHistory({ ticker, offset, limit, address })
81
+ const getTokenTransactionHistory = ({
82
+ tick,
83
+ owner,
84
+ brc20Op,
85
+ showInvalid,
86
+ transactionIds,
87
+ limit,
88
+ offset,
89
+ }) => {
90
+ return paginatedTransactionHistory({
91
+ tick,
92
+ owner,
93
+ brc20Op,
94
+ showInvalid,
95
+ transactionIds,
96
+ limit,
97
+ offset,
98
+ })
107
99
  }
108
100
 
109
101
  return {
@@ -36,7 +36,16 @@ export const getInscriptionAddresses = async ({
36
36
  addressIndex: 0,
37
37
  })
38
38
 
39
- const allAddresses = [specialAddress1, specialAddress2, ...addresses].map((t) =>
39
+ const specialAddress3 = await aci.getAddress({
40
+ // xverse
41
+ assetName,
42
+ walletAccount,
43
+ purpose: 49,
44
+ chainIndex: 0,
45
+ addressIndex: 0,
46
+ })
47
+
48
+ const allAddresses = [specialAddress1, specialAddress2, specialAddress3, ...addresses].map((t) =>
40
49
  t.address.toString()
41
50
  )
42
51
  return [...new Set(allAddresses)]
@@ -9,6 +9,60 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
9
9
  assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
10
10
  let aci // convert to constructor argument when wallet send aci at createAsset time
11
11
 
12
+ const processAdditionalInscriptions = async function({ walletAccount, nfts }) {
13
+ const ordinalAddress = await getOrdinalAddress({
14
+ asset,
15
+ assetClientInterface: aci,
16
+ walletAccount,
17
+ ordinalChainIndex: ordinalChainIndex,
18
+ })
19
+
20
+ const accountState = await aci.getAccountState({
21
+ assetName: asset.name,
22
+ walletAccount: walletAccount,
23
+ })
24
+
25
+ const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
26
+ const storedUtxos = getUtxos({ accountState, asset })
27
+ const allStoredUtxos = storedUtxos.union(storedOrdinalsUtxos)
28
+
29
+ const knownUtxoIds = [...allStoredUtxos].map((utxo) =>
30
+ `${utxo.txId}:${utxo.vout}`.toLowerCase()
31
+ )
32
+
33
+ const additionalInscriptions = nfts
34
+ .filter((nft) => knownUtxoIds.includes(nft.output.toLowerCase()))
35
+ .map((nft) => {
36
+ const output = nft.output.split(':')
37
+ return { txId: output[0], vout: parseInt(output[1]), inscriptionId: nft.tokenId }
38
+ })
39
+
40
+ if (!isEqual(accountState.additionalInscriptions || [], additionalInscriptions)) {
41
+ const { utxos, ordinalsUtxos } = partitionUtxos({
42
+ allUtxos: getUtxos({ accountState, asset }).union(
43
+ getOrdinalsUtxos({ accountState, asset })
44
+ ),
45
+ ordinalsEnabled: true,
46
+ ordinalAddress: ordinalAddress,
47
+ mustAvoidUtxoIds: accountState.mustAvoidUtxoIds,
48
+ knownBalanceUtxoIds: accountState.knownBalanceUtxoIds,
49
+ additionalInscriptions: additionalInscriptions,
50
+ })
51
+
52
+ await aci.updateAccountState({
53
+ walletAccount,
54
+ assetName: asset.name,
55
+ newData: {
56
+ utxos,
57
+ ordinalsUtxos,
58
+ additionalInscriptions,
59
+ },
60
+ })
61
+ return ordinalsUtxos
62
+ }
63
+ return storedOrdinalsUtxos
64
+ }
65
+
12
66
  return {
13
67
  initialize: ({ assetClientInterface }) => {
14
68
  aci = assetClientInterface
@@ -38,11 +92,12 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
38
92
  return []
39
93
  }
40
94
 
41
- const accountState = await aci.getAccountState({
42
- assetName: asset.name,
43
- walletAccount: walletAccountInstance.toString(),
95
+ const walletAccount = walletAccountInstance.toString()
96
+
97
+ const storedOrdinalsUtxos = await processAdditionalInscriptions({
98
+ walletAccount,
99
+ nfts,
44
100
  })
45
- const storedOrdinalsUtxos = getOrdinalsUtxos({ accountState, asset })
46
101
 
47
102
  if (nftsProxy) {
48
103
  const unconfirmedUtxosArray = storedOrdinalsUtxos
@@ -92,7 +147,7 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
92
147
 
93
148
  const unconfirmedTxs = Array.from(
94
149
  await aci.getTxLog({
95
- walletAccount: walletAccountInstance.toString(),
150
+ walletAccount: walletAccount,
96
151
  assetName: asset.name,
97
152
  })
98
153
  ).filter((tx) => !tx.confirmations)
@@ -181,6 +236,7 @@ export const nftsApiFactory = ({ ordinalChainIndex, asset }) => {
181
236
  ordinalAddress: ordinalAddress,
182
237
  mustAvoidUtxoIds: mustAvoidUtxoIds,
183
238
  knownBalanceUtxoIds: accountState.knownBalanceUtxoIds,
239
+ additionalInscriptions: accountState.additionalInscriptions,
184
240
  })
185
241
 
186
242
  await aci.updateAccountState({
@@ -72,7 +72,7 @@ export const reloadBrc20TokenBalances = async ({
72
72
  const brc20History = (
73
73
  await Promise.all(
74
74
  addresses.map(async (address) => {
75
- const tokensHistoryList = await brc20Client.getTokenTransactionHistory({ address })
75
+ const tokensHistoryList = await brc20Client.getTokenTransactionHistory({ owner: address })
76
76
  return (
77
77
  await Promise.all(
78
78
  tokensHistoryList.map(async (token) => {
@@ -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.token.id
14
+ const deployInscriptionId = response[0].inscriptionId
15
15
  save({ deployInscriptionId, brc20Tick })
16
16
  return deployInscriptionId
17
17
  }