@exodus/bitcoin-plugin 1.32.1 → 1.33.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/CHANGELOG.md +22 -0
- package/package.json +3 -5
- package/src/create-asset.js +10 -83
- package/src/ordinals/ordinals-constants.js +0 -5
- 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
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.33.0](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-plugin@1.32.2...@exodus/bitcoin-plugin@1.33.0) (2025-04-01)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* feat(bitcoin): allow message signing with external signer (#5365)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## [1.32.2](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-plugin@1.32.1...@exodus/bitcoin-plugin@1.32.2) (2025-03-19)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
* fix: remove brc20 dead code (#5286)
|
|
23
|
+
|
|
24
|
+
* fix: spelling (#5284)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [1.32.1](https://github.com/ExodusMovement/assets/compare/@exodus/bitcoin-plugin@1.32.0...@exodus/bitcoin-plugin@1.32.1) (2025-01-27)
|
|
7
29
|
|
|
8
30
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/bitcoin-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.0",
|
|
4
4
|
"description": "Bitcoin plugin for Exodus SDK powered wallets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -23,14 +23,12 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@exodus/asset-lib": "^5.0.0",
|
|
25
25
|
"@exodus/bip44-constants": "^195.0.0",
|
|
26
|
-
"@exodus/bitcoin-api": "^2.
|
|
26
|
+
"@exodus/bitcoin-api": "^2.32.0",
|
|
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
32
|
"@exodus/web3-bitcoin-utils": "^2.3.3",
|
|
35
33
|
"coininfo": "^5.1.0",
|
|
36
34
|
"lodash": "^4.17.21",
|
|
@@ -58,5 +56,5 @@
|
|
|
58
56
|
"type": "git",
|
|
59
57
|
"url": "git+https://github.com/ExodusMovement/assets.git"
|
|
60
58
|
},
|
|
61
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "1f9c50ecd68233dd86ca4275d005a8baf93c85c5"
|
|
62
60
|
}
|
package/src/create-asset.js
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
moveFundsFactory,
|
|
21
21
|
signHardwareFactory,
|
|
22
22
|
signMessage,
|
|
23
|
+
signMessageWithSigner,
|
|
23
24
|
signTxFactory,
|
|
24
25
|
} from '@exodus/bitcoin-api'
|
|
25
26
|
import { parseCurrency } from '@exodus/bitcoin-api/src/fee/fee-utils.js'
|
|
@@ -33,18 +34,10 @@ import { createGetSupportedPurposes, getDefaultAddressPath } from './compatibili
|
|
|
33
34
|
import { createCustomFeesApi } from './custom-fees.js'
|
|
34
35
|
import { bitcoinFeeDataFactory } from './fee-data.js'
|
|
35
36
|
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
37
|
import { nftsApiFactory } from './ordinals/nfts.js'
|
|
41
38
|
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
39
|
import { createWeb3API } from './web3/index.js'
|
|
45
40
|
|
|
46
|
-
const DEFAULT_TICKS_BETWEEN_BRC20_FETCHES = 30
|
|
47
|
-
|
|
48
41
|
export const createBitcoinAssetFactory =
|
|
49
42
|
({ asset, apiUrl: defaultApiUrl, coinInfoNetwork, isTestnet = false }) =>
|
|
50
43
|
(
|
|
@@ -56,9 +49,6 @@ export const createBitcoinAssetFactory =
|
|
|
56
49
|
allowUnconfirmedRbfEnabledUtxos = false,
|
|
57
50
|
ordinalChainIndex = DEFAULT_ORDINAL_CHAIN_INDEX,
|
|
58
51
|
ordinalsEnabled = false,
|
|
59
|
-
brc20Enabled = false,
|
|
60
|
-
brc20Url = DEFAULT_BRC_20_URL,
|
|
61
|
-
brc20TickInterval = DEFAULT_TICKS_BETWEEN_BRC20_FETCHES,
|
|
62
52
|
gapLimit = 10,
|
|
63
53
|
refreshGapLimit = 25,
|
|
64
54
|
feeDataCustomValues,
|
|
@@ -74,10 +64,7 @@ export const createBitcoinAssetFactory =
|
|
|
74
64
|
assert(asset, 'asset is required')
|
|
75
65
|
assert(typeof ordinalChainIndex === 'number', 'ordinalChainIndex must be a number')
|
|
76
66
|
assert(apiUrl, 'apiUrl is required')
|
|
77
|
-
|
|
78
|
-
brc20Enabled ? ordinalsEnabled : true,
|
|
79
|
-
'if brc20Enabled is true then ordinalsEnabled must be true'
|
|
80
|
-
)
|
|
67
|
+
|
|
81
68
|
const coinInfo = _coinInfo(coinInfoNetwork || asset.name)
|
|
82
69
|
|
|
83
70
|
const insightClient = new InsightAPIClient(apiUrl)
|
|
@@ -109,9 +96,9 @@ export const createBitcoinAssetFactory =
|
|
|
109
96
|
moveFunds: true,
|
|
110
97
|
multipleAddresses: true,
|
|
111
98
|
nfts: ordinalsEnabled,
|
|
112
|
-
customTokens: brc20Enabled,
|
|
113
99
|
isTestnet,
|
|
114
100
|
signWithSigner: true,
|
|
101
|
+
signMessageWithSigner: true,
|
|
115
102
|
supportsCustomFees: true,
|
|
116
103
|
}
|
|
117
104
|
|
|
@@ -120,7 +107,7 @@ export const createBitcoinAssetFactory =
|
|
|
120
107
|
addressApi: address,
|
|
121
108
|
})
|
|
122
109
|
|
|
123
|
-
const
|
|
110
|
+
const { getFee, getAvailableBalance, canBumpTx, getSpendableBalance } = new GetFeeResolver({
|
|
124
111
|
getFeeEstimator,
|
|
125
112
|
allowUnconfirmedRbfEnabledUtxos,
|
|
126
113
|
utxosDescendingOrder,
|
|
@@ -132,17 +119,12 @@ export const createBitcoinAssetFactory =
|
|
|
132
119
|
overrideDefaults: feeDataCustomValues,
|
|
133
120
|
})
|
|
134
121
|
|
|
135
|
-
const
|
|
122
|
+
const getBalances = getBalancesFactory({
|
|
136
123
|
feeData,
|
|
137
|
-
getSpendableBalance
|
|
124
|
+
getSpendableBalance,
|
|
138
125
|
ordinalsEnabled,
|
|
139
126
|
})
|
|
140
127
|
|
|
141
|
-
const brc20Client = brc20Enabled ? brc20ApiClientFactory({ brc20Url }) : undefined
|
|
142
|
-
const tickInscriptionIdIndexer = brc20Enabled
|
|
143
|
-
? tickInscriptionIdIndexerFactory({ brc20Client })
|
|
144
|
-
: undefined
|
|
145
|
-
|
|
146
128
|
const baseGetPrepareSendTx = getPrepareSendTransaction({
|
|
147
129
|
getFeeEstimator,
|
|
148
130
|
allowUnconfirmedRbfEnabledUtxos,
|
|
@@ -152,7 +134,7 @@ export const createBitcoinAssetFactory =
|
|
|
152
134
|
changeAddressType,
|
|
153
135
|
})
|
|
154
136
|
|
|
155
|
-
const
|
|
137
|
+
const sendTx = createAndBroadcastTXFactory({
|
|
156
138
|
getFeeEstimator,
|
|
157
139
|
allowUnconfirmedRbfEnabledUtxos,
|
|
158
140
|
ordinalsEnabled,
|
|
@@ -160,29 +142,6 @@ export const createBitcoinAssetFactory =
|
|
|
160
142
|
assetClientInterface,
|
|
161
143
|
changeAddressType,
|
|
162
144
|
})
|
|
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
145
|
|
|
187
146
|
const prepareForSigning = createPrepareForSigning({
|
|
188
147
|
assetName: asset.name,
|
|
@@ -227,19 +186,14 @@ export const createBitcoinAssetFactory =
|
|
|
227
186
|
const accountStateClass = createAccountState({
|
|
228
187
|
asset,
|
|
229
188
|
ordinalsEnabled,
|
|
230
|
-
brc20Enabled,
|
|
231
189
|
})
|
|
232
190
|
|
|
233
191
|
const nfts = ordinalsEnabled
|
|
234
192
|
? nftsApiFactory({ ordinalChainIndex, asset, assetClientInterface })
|
|
235
193
|
: undefined
|
|
236
194
|
|
|
237
|
-
const { createToken, getTokens, validateAssetId } = brc20Enabled
|
|
238
|
-
? createTokenFactory({ address, bip44, keys, getBalances }, [])
|
|
239
|
-
: {}
|
|
240
|
-
|
|
241
195
|
const createHistoryMonitor = (args) => {
|
|
242
|
-
|
|
196
|
+
return createBitcoinMonitor({
|
|
243
197
|
assetClientInterface,
|
|
244
198
|
insightClient,
|
|
245
199
|
ordinalsEnabled,
|
|
@@ -249,27 +203,6 @@ export const createBitcoinAssetFactory =
|
|
|
249
203
|
refreshGapLimit,
|
|
250
204
|
...args,
|
|
251
205
|
})
|
|
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
206
|
}
|
|
274
207
|
|
|
275
208
|
const addressHasHistory = async (address) => {
|
|
@@ -368,13 +301,11 @@ export const createBitcoinAssetFactory =
|
|
|
368
301
|
sendTx,
|
|
369
302
|
signTx,
|
|
370
303
|
signHardware,
|
|
371
|
-
signMessage,
|
|
304
|
+
signMessage: ({ privateKey, signer, message }) =>
|
|
305
|
+
signer ? signMessageWithSigner({ signer, message }) : signMessage({ privateKey, message }),
|
|
372
306
|
getFee,
|
|
373
307
|
moveFunds,
|
|
374
308
|
nfts,
|
|
375
|
-
createToken,
|
|
376
|
-
getTokens,
|
|
377
|
-
validateAssetId,
|
|
378
309
|
web3: createWeb3API({
|
|
379
310
|
assetClientInterface,
|
|
380
311
|
baseAssetName: asset.name,
|
|
@@ -398,7 +329,6 @@ export const createBitcoinAssetFactory =
|
|
|
398
329
|
canBumpTx,
|
|
399
330
|
getAvailableBalance,
|
|
400
331
|
getSpendableBalance,
|
|
401
|
-
inscriptions: inscriptionsService,
|
|
402
332
|
prepareSendTx: baseGetPrepareSendTx,
|
|
403
333
|
createBatchTx,
|
|
404
334
|
encodeMultisigContract,
|
|
@@ -412,9 +342,6 @@ export const createBitcoinAssetFactory =
|
|
|
412
342
|
allowUnconfirmedRbfEnabledUtxos,
|
|
413
343
|
ordinalChainIndex,
|
|
414
344
|
ordinalsEnabled,
|
|
415
|
-
brc20Enabled,
|
|
416
|
-
brc20Url,
|
|
417
|
-
brc20TickInterval,
|
|
418
345
|
gapLimit,
|
|
419
346
|
refreshGapLimit,
|
|
420
347
|
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).
|
|
@@ -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
|
-
}
|