@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 +22 -0
- package/package.json +4 -6
- package/src/create-asset.js +13 -83
- package/src/ordinals/ordinals-constants.js +0 -5
- package/src/web3/createSimulateTransactions.js +16 -6
- package/src/ordinals/brc-20-balances-and-fee-adapter.js +0 -212
- package/src/ordinals/brc-20-client.js +0 -120
- package/src/ordinals/brc-20-utils.js +0 -137
- package/src/ordinals/create-brc-20-command.js +0 -51
- package/src/ordinals/create-token-factory.js +0 -31
- package/src/ordinals/inscriptions-service.js +0 -377
- package/src/ordinals/reload-brc20-token-balances.js +0 -158
- package/src/ordinals/tick-inscription-id-indexer.js +0 -49
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import lodash from 'lodash'
|
|
2
|
-
import assert from 'minimalistic-assert'
|
|
3
|
-
|
|
4
|
-
import { getInscriptionAddresses } from './get-inscription-addresses.js'
|
|
5
|
-
|
|
6
|
-
const { groupBy, mapValues } = lodash
|
|
7
|
-
|
|
8
|
-
const toTxLog = ({ historyItem, baseAsset, asset }) => {
|
|
9
|
-
const amount = asset.currency.defaultUnit(historyItem.brc20Amt || 0)
|
|
10
|
-
|
|
11
|
-
const isSend = historyItem.brc20Op === 'send'
|
|
12
|
-
const isReceive = historyItem.brc20Op === 'receive'
|
|
13
|
-
const isMint = historyItem.brc20Op === 'mint'
|
|
14
|
-
const isTransfer = historyItem.brc20Op === 'transfer'
|
|
15
|
-
|
|
16
|
-
const data = { operation: historyItem.brc20Op }
|
|
17
|
-
return {
|
|
18
|
-
txId: historyItem.txId,
|
|
19
|
-
date: new Date(historyItem.createdAt),
|
|
20
|
-
confirmations: 1,
|
|
21
|
-
data: isSend
|
|
22
|
-
? {
|
|
23
|
-
...data,
|
|
24
|
-
sent: [
|
|
25
|
-
{
|
|
26
|
-
address: historyItem.transferTo,
|
|
27
|
-
amount: amount.toDefaultString({ unit: true }),
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
}
|
|
31
|
-
: data,
|
|
32
|
-
selfSend: isTransfer, // transfer is self inscribed ordinal that hasn't been sent yet
|
|
33
|
-
from: isReceive ? [historyItem.transferFrom] : undefined,
|
|
34
|
-
addresses: isReceive || isMint ? [historyItem.owner] : undefined,
|
|
35
|
-
dropped: false,
|
|
36
|
-
coinAmount: isSend ? amount.negate() : amount,
|
|
37
|
-
coinName: asset.name,
|
|
38
|
-
feeAmount: baseAsset.currency.defaultUnit(0), // unsure a possible value
|
|
39
|
-
feeCoinName: baseAsset.name,
|
|
40
|
-
currencies: { [baseAsset.name]: baseAsset.currency, [asset.name]: asset.currency },
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const reloadBrc20TokenBalances = async ({
|
|
45
|
-
brc20Client,
|
|
46
|
-
assetClientInterface,
|
|
47
|
-
walletAccount,
|
|
48
|
-
asset,
|
|
49
|
-
ordinalChainIndex,
|
|
50
|
-
tickInscriptionIdIndexer,
|
|
51
|
-
}) => {
|
|
52
|
-
assert(brc20Client, 'brc20Client is required')
|
|
53
|
-
assert(assetClientInterface, 'assetClientInterface is required')
|
|
54
|
-
assert(asset, 'asset is required')
|
|
55
|
-
assert(walletAccount, 'walletAccount is required')
|
|
56
|
-
assert(tickInscriptionIdIndexer, 'tickInscriptionIdIndexer is required')
|
|
57
|
-
assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
|
|
58
|
-
const addresses = await getInscriptionAddresses({
|
|
59
|
-
assetClientInterface,
|
|
60
|
-
walletAccount,
|
|
61
|
-
asset,
|
|
62
|
-
ordinalChainIndex,
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
const assets = await assetClientInterface.getAssetsForNetwork({ baseAssetName: asset.name })
|
|
66
|
-
|
|
67
|
-
const assetByAssetId = Object.values(assets)
|
|
68
|
-
.filter((asset) => asset.assetId)
|
|
69
|
-
.reduce((map, token) => {
|
|
70
|
-
map.set(token.assetId, token)
|
|
71
|
-
return map
|
|
72
|
-
}, new Map())
|
|
73
|
-
|
|
74
|
-
const unknownDeployInscriptionIds = new Set()
|
|
75
|
-
|
|
76
|
-
const historyLists = await Promise.all(
|
|
77
|
-
addresses.map(async (address) => {
|
|
78
|
-
const tokensHistoryList = await brc20Client.getTokenTransactionHistory({ address })
|
|
79
|
-
const history = await Promise.all(
|
|
80
|
-
tokensHistoryList.map(async (token) => {
|
|
81
|
-
const deployInscriptionId = await tickInscriptionIdIndexer.getDeployInscriptionId(
|
|
82
|
-
token.brc20Tick
|
|
83
|
-
)
|
|
84
|
-
const assetName = assetByAssetId.get(deployInscriptionId)?.name
|
|
85
|
-
if (assetName) {
|
|
86
|
-
return { ...token, address, assetName, deployInscriptionId }
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
unknownDeployInscriptionIds.add(deployInscriptionId)
|
|
90
|
-
})
|
|
91
|
-
)
|
|
92
|
-
return history.filter(Boolean)
|
|
93
|
-
})
|
|
94
|
-
)
|
|
95
|
-
const brc20History = historyLists.flat()
|
|
96
|
-
|
|
97
|
-
const eventsByAssetNameAndAddress = mapValues(
|
|
98
|
-
groupBy(brc20History, (event) => event.assetName),
|
|
99
|
-
(anotherList) => groupBy(anotherList, (event) => event.address)
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
const brc20Balances = mapValues(eventsByAssetNameAndAddress, (eventsByAddress) => {
|
|
103
|
-
return mapValues(eventsByAddress, (events) => {
|
|
104
|
-
const { brc20OwnerAvailableBalance, brc20OwnerTransferBalance, brc20Tick } = events[0]
|
|
105
|
-
|
|
106
|
-
const sentList = new Set(
|
|
107
|
-
events.filter((event) => event.brc20Op === 'send').map((event) => event.inscriptionId)
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
const transferableList = events
|
|
111
|
-
.filter((event) => event.brc20Op === 'transfer')
|
|
112
|
-
.map((event) => {
|
|
113
|
-
return {
|
|
114
|
-
inscriptionId: event.inscriptionId,
|
|
115
|
-
inscriptionNumber: event.inscriptionNumber,
|
|
116
|
-
brc20Amt: event.brc20Amt,
|
|
117
|
-
txId: event.txId,
|
|
118
|
-
sent: sentList.has(event.inscriptionId),
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
return {
|
|
122
|
-
brc20Tick,
|
|
123
|
-
brc20OwnerAvailableBalance,
|
|
124
|
-
brc20OwnerTransferBalance,
|
|
125
|
-
brc20OwnerTotalBalance: brc20OwnerAvailableBalance + brc20OwnerTransferBalance,
|
|
126
|
-
transferableList,
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
const allLogItems = brc20History
|
|
132
|
-
.filter(({ assetName }) => assetName)
|
|
133
|
-
.map((historyItem) => {
|
|
134
|
-
return toTxLog({ historyItem, baseAsset: asset, asset: assets[historyItem.assetName] })
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
const logItemsByAsset = groupBy(allLogItems, 'coinName')
|
|
138
|
-
|
|
139
|
-
await Promise.all(
|
|
140
|
-
Object.entries(logItemsByAsset).map(([assetName, txs]) => {
|
|
141
|
-
return assetClientInterface.updateTxLogAndNotify({
|
|
142
|
-
assetName,
|
|
143
|
-
walletAccount,
|
|
144
|
-
txs,
|
|
145
|
-
})
|
|
146
|
-
})
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
await assetClientInterface.updateAccountState({
|
|
150
|
-
assetName: asset.name,
|
|
151
|
-
walletAccount,
|
|
152
|
-
newData: { brc20Balances },
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
unknownDeployInscriptionIds: [...unknownDeployInscriptionIds],
|
|
157
|
-
}
|
|
158
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import assert from 'minimalistic-assert'
|
|
2
|
-
|
|
3
|
-
export const tickInscriptionIdIndexerFactory = ({ brc20Client }) => {
|
|
4
|
-
const deployInscriptionIdToBrc20Tick = new Map()
|
|
5
|
-
const brc20TickToDeployInscriptionId = new Map()
|
|
6
|
-
|
|
7
|
-
const save = ({ deployInscriptionId, brc20Tick }) => {
|
|
8
|
-
deployInscriptionIdToBrc20Tick.set(deployInscriptionId, brc20Tick)
|
|
9
|
-
brc20TickToDeployInscriptionId.set(brc20Tick, deployInscriptionId)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const loadDeployInscriptionId = async (brc20Tick) => {
|
|
13
|
-
const response = await brc20Client.getTickerInfo({ tick: brc20Tick })
|
|
14
|
-
const deployInscriptionId = response.token.id
|
|
15
|
-
save({ deployInscriptionId, brc20Tick })
|
|
16
|
-
return deployInscriptionId
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const loadBrc20Tick = async (deployInscriptionId) => {
|
|
20
|
-
const response = await brc20Client.getTickerInfoByDeployInscriptionId({ deployInscriptionId })
|
|
21
|
-
const brc20Tick = response[0].brc20Tick
|
|
22
|
-
save({ deployInscriptionId, brc20Tick })
|
|
23
|
-
return brc20Tick
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const getDeployInscriptionId = async (brc20Tick) => {
|
|
27
|
-
return brc20TickToDeployInscriptionId.get(brc20Tick) || loadDeployInscriptionId(brc20Tick)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const getBrc20Tick = async (deployInscriptionId) => {
|
|
31
|
-
return (
|
|
32
|
-
deployInscriptionIdToBrc20Tick.get(deployInscriptionId) || loadBrc20Tick(deployInscriptionId)
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const getBrc20TickFromAsset = async (asset) => {
|
|
37
|
-
assert(asset.assetType === 'BRC20_TOKEN', `Asset ${asset.name} is not a brc20 asset`)
|
|
38
|
-
const deployInscriptionId = asset.assetId
|
|
39
|
-
const brc20Tick = asset.brc20Tick // this should always be true once CTR is patched
|
|
40
|
-
if (brc20Tick) {
|
|
41
|
-
save({ deployInscriptionId, brc20Tick })
|
|
42
|
-
return brc20Tick
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return getBrc20Tick(deployInscriptionId)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return { getBrc20TickFromAsset, getDeployInscriptionId, getBrc20Tick }
|
|
49
|
-
}
|