@teleportdao/bitcoin 1.7.2 → 1.7.6
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/dist/bitcoin-base.d.ts +93 -0
- package/dist/bitcoin-base.d.ts.map +1 -0
- package/dist/bitcoin-base.js +236 -0
- package/dist/bitcoin-base.js.map +1 -0
- package/dist/bitcoin-interface-teleswap.d.ts +6 -1
- package/dist/bitcoin-interface-teleswap.d.ts.map +1 -1
- package/dist/bitcoin-interface-teleswap.js +2 -4
- package/dist/bitcoin-interface-teleswap.js.map +1 -1
- package/dist/helper/burn-request-helper.d.ts +7 -0
- package/dist/helper/burn-request-helper.d.ts.map +1 -0
- package/dist/helper/burn-request-helper.js +26 -0
- package/dist/helper/burn-request-helper.js.map +1 -0
- package/dist/helper/teleport-request-helper.d.ts +47 -0
- package/dist/helper/teleport-request-helper.d.ts.map +1 -0
- package/dist/helper/teleport-request-helper.js +146 -0
- package/dist/helper/teleport-request-helper.js.map +1 -0
- package/dist/helper/teleswap-helper.d.ts +20 -8
- package/dist/helper/teleswap-helper.d.ts.map +1 -1
- package/dist/helper/teleswap-helper.js +55 -50
- package/dist/helper/teleswap-helper.js.map +1 -1
- package/dist/teleport-dao-payments.d.ts +76 -0
- package/dist/teleport-dao-payments.d.ts.map +1 -0
- package/dist/teleport-dao-payments.js +217 -0
- package/dist/teleport-dao-payments.js.map +1 -0
- package/dist/teleswap-wallet.d.ts +4 -6
- package/dist/teleswap-wallet.d.ts.map +1 -1
- package/dist/teleswap-wallet.js +7 -8
- package/dist/teleswap-wallet.js.map +1 -1
- package/package.json +5 -5
- package/src/bitcoin-interface-ordinal.ts +181 -181
- package/src/bitcoin-interface-teleswap.ts +252 -255
- package/src/bitcoin-interface-utils.ts +59 -59
- package/src/bitcoin-interface.ts +247 -247
- package/src/bitcoin-utils.ts +591 -591
- package/src/bitcoin-wallet-base.ts +314 -314
- package/src/helper/brc20-helper.ts +181 -181
- package/src/helper/ordinal-helper.ts +118 -118
- package/src/helper/teleswap-helper.ts +77 -101
- package/src/index.ts +15 -15
- package/src/ordinal-wallet.ts +738 -738
- package/src/sign/index.ts +1 -1
- package/src/sign/sign-transaction.ts +108 -108
- package/src/teleswap-wallet.ts +152 -155
- package/src/transaction-builder/bitcoin-transaction-builder.ts +44 -44
- package/src/transaction-builder/index.ts +3 -3
- package/src/transaction-builder/ordinal-transaction-builder.ts +147 -147
- package/src/transaction-builder/transaction-builder.ts +705 -705
- package/src/type.ts +43 -43
- package/src/utils/networks.ts +33 -33
- package/src/utils/tools.ts +89 -89
- package/tsconfig.json +9 -9
- package/webpack.config.js +16 -16
|
@@ -16,13 +16,13 @@ export type WrapOpReturn = {
|
|
|
16
16
|
chainId: number
|
|
17
17
|
appId: number
|
|
18
18
|
recipientAddress: string
|
|
19
|
-
|
|
19
|
+
thirdPartyId: number
|
|
20
|
+
networkFee: string
|
|
20
21
|
speed: boolean
|
|
21
22
|
//
|
|
22
23
|
outputToken?: string
|
|
23
24
|
outputAmount?: string
|
|
24
|
-
|
|
25
|
-
isFixedToken?: boolean
|
|
25
|
+
bridgePercentageFee?: number
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export type UnwrapInfo = {
|
|
@@ -41,29 +41,32 @@ export type UnwrapInfo = {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export type WrapOpReturnWithType = WrapOpReturn & {
|
|
44
|
-
requestType: "
|
|
44
|
+
requestType: "Wrap" | "WrapAndSwap"
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
// hex length -> 1 byte = 2
|
|
47
48
|
const wrapOpReturnLength = {
|
|
48
|
-
chainId:
|
|
49
|
-
appId:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
chainId: 4,
|
|
50
|
+
appId: 2,
|
|
51
|
+
thirdPartyId: 2,
|
|
52
|
+
networkFee: 6,
|
|
53
|
+
bridgePercentageFee: 6,
|
|
54
|
+
outputAmount: 28,
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
export function generateWrapOpReturn({
|
|
56
58
|
chainId,
|
|
57
59
|
appId,
|
|
58
60
|
recipientAddress, // 20 bytes
|
|
59
|
-
|
|
61
|
+
networkFee, // 2 bytes in percent %
|
|
62
|
+
thirdPartyId = 0,
|
|
60
63
|
speed = false, // 1 byte
|
|
61
64
|
isExchange = false,
|
|
62
65
|
outputToken, // 20 bytes
|
|
63
66
|
outputAmount, // 28 bytes
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
bridgePercentageFee = 0,
|
|
68
|
+
}: Omit<WrapOpReturn, "thirdPartyId"> & {
|
|
69
|
+
thirdPartyId?: number
|
|
67
70
|
isExchange?: boolean
|
|
68
71
|
}) {
|
|
69
72
|
let data = ""
|
|
@@ -73,18 +76,20 @@ export function generateWrapOpReturn({
|
|
|
73
76
|
if (BigNumber(appId).toString(16).length > wrapOpReturnLength.appId) {
|
|
74
77
|
throw new Error("invalid appId")
|
|
75
78
|
}
|
|
76
|
-
if (BigNumber(
|
|
79
|
+
if (BigNumber(networkFee).toString(16).length > wrapOpReturnLength.networkFee) {
|
|
77
80
|
throw new Error("invalid percentageFee")
|
|
78
81
|
}
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
if (BigNumber(thirdPartyId).toString(16).length > wrapOpReturnLength.thirdPartyId) {
|
|
83
|
+
throw new Error("invalid percentageFee")
|
|
84
|
+
}
|
|
85
|
+
data += BigNumber(chainId).toString(16).padStart(wrapOpReturnLength.chainId, "0")
|
|
86
|
+
data += BigNumber(appId).toString(16).padStart(wrapOpReturnLength.appId, "0")
|
|
81
87
|
data += recipientAddress.replace("0x", "").toLowerCase().padStart(40, "0")
|
|
82
|
-
data += BigNumber((
|
|
83
|
-
.toString(16)
|
|
84
|
-
.padStart(4, "0")
|
|
88
|
+
data += BigNumber(networkFee).toString(16).padStart(wrapOpReturnLength.networkFee, "0")
|
|
85
89
|
data += speed ? "01" : "00"
|
|
90
|
+
data += BigNumber(thirdPartyId).toString(16).padStart(wrapOpReturnLength.thirdPartyId, "0")
|
|
86
91
|
if (!isExchange) {
|
|
87
|
-
if (data.length !==
|
|
92
|
+
if (data.length !== 28 * 2) throw new Error("invalid data length")
|
|
88
93
|
return data
|
|
89
94
|
}
|
|
90
95
|
if (!outputToken) {
|
|
@@ -96,15 +101,22 @@ export function generateWrapOpReturn({
|
|
|
96
101
|
) {
|
|
97
102
|
throw new Error("invalid outputAmount")
|
|
98
103
|
}
|
|
99
|
-
if (
|
|
100
|
-
|
|
104
|
+
if (
|
|
105
|
+
(bridgePercentageFee || 0) > 100 ||
|
|
106
|
+
BigNumber(bridgePercentageFee || 0)
|
|
107
|
+
.multipliedBy(1e7)
|
|
108
|
+
.toString(16).length > wrapOpReturnLength.bridgePercentageFee
|
|
109
|
+
) {
|
|
110
|
+
throw new Error("invalid percentageFee")
|
|
101
111
|
}
|
|
102
|
-
|
|
103
112
|
data += outputToken.replace("0x", "").toLowerCase().padStart(40, "0")
|
|
104
|
-
data += BigNumber(outputAmount).toString(16).padStart(
|
|
105
|
-
|
|
106
|
-
data +=
|
|
107
|
-
|
|
113
|
+
data += BigNumber(outputAmount).toString(16).padStart(wrapOpReturnLength.outputAmount, "0")
|
|
114
|
+
|
|
115
|
+
data += BigNumber(bridgePercentageFee || 0)
|
|
116
|
+
.multipliedBy(1e7)
|
|
117
|
+
.toString(16)
|
|
118
|
+
.padStart(wrapOpReturnLength.bridgePercentageFee, "0")
|
|
119
|
+
if (data.length !== 65 * 2) throw new Error("invalid data length")
|
|
108
120
|
return data
|
|
109
121
|
}
|
|
110
122
|
|
|
@@ -132,21 +144,24 @@ export function getBurnTransactionInfo(address: string, vin: Vin[] = [], vouts:
|
|
|
132
144
|
})
|
|
133
145
|
return { receivers, changes, totalInputValue, lockerVin }
|
|
134
146
|
}
|
|
135
|
-
return
|
|
136
147
|
}
|
|
137
148
|
|
|
138
149
|
//
|
|
139
150
|
|
|
140
|
-
function parseWrapRequest(data: string) {
|
|
141
|
-
let parsedData:
|
|
142
|
-
parsedData.requestType = "
|
|
151
|
+
export function parseWrapRequest(data: string) {
|
|
152
|
+
let parsedData: Partial<WrapOpReturnWithType> = {}
|
|
153
|
+
parsedData.requestType = "Wrap"
|
|
143
154
|
let offset = 0
|
|
144
|
-
parsedData.chainId = BigNumber(
|
|
145
|
-
|
|
155
|
+
parsedData.chainId = BigNumber(
|
|
156
|
+
`0x${data.slice(offset, (offset += wrapOpReturnLength.chainId))}`,
|
|
157
|
+
).toNumber() // 1 bytes
|
|
158
|
+
parsedData.appId = BigNumber(
|
|
159
|
+
`0x${data.slice(offset, (offset += wrapOpReturnLength.appId))}`,
|
|
160
|
+
).toNumber() // 2 bytes
|
|
146
161
|
parsedData.recipientAddress = `0x${data.slice(offset, (offset += 40))}` // 20 bytes
|
|
147
|
-
parsedData.
|
|
148
|
-
.
|
|
149
|
-
|
|
162
|
+
parsedData.networkFee = new BigNumber(
|
|
163
|
+
`0x${data.slice(offset, (offset += wrapOpReturnLength.networkFee))}`,
|
|
164
|
+
).toFixed(0)
|
|
150
165
|
parsedData.speed = data.slice(offset, (offset += 2)) === "01" // 1 byte
|
|
151
166
|
if (data.length === offset) {
|
|
152
167
|
return {
|
|
@@ -155,11 +170,24 @@ function parseWrapRequest(data: string) {
|
|
|
155
170
|
}
|
|
156
171
|
}
|
|
157
172
|
|
|
158
|
-
parsedData.requestType = "
|
|
159
|
-
parsedData.
|
|
160
|
-
parsedData.outputAmount = new BigNumber(
|
|
161
|
-
|
|
162
|
-
|
|
173
|
+
parsedData.requestType = "WrapAndSwap"
|
|
174
|
+
parsedData.outputToken = `0x${data.slice(offset, (offset += 40))}` // 20 bytes
|
|
175
|
+
parsedData.outputAmount = new BigNumber(
|
|
176
|
+
`0x${data.slice(offset, (offset += wrapOpReturnLength.outputAmount))}`,
|
|
177
|
+
).toFixed(0) // 28 bytes
|
|
178
|
+
parsedData.bridgePercentageFee = new BigNumber(
|
|
179
|
+
`0x${data.slice(offset, (offset += wrapOpReturnLength.bridgePercentageFee))}`,
|
|
180
|
+
)
|
|
181
|
+
.dividedBy(1e7)
|
|
182
|
+
.toNumber()
|
|
183
|
+
|
|
184
|
+
if (parsedData.bridgePercentageFee > 100) {
|
|
185
|
+
return {
|
|
186
|
+
status: false,
|
|
187
|
+
message: `invalid OP_RETURN data for requestType: 'wrap or wrapAndSwap'. invalid bridgePercentageFee`,
|
|
188
|
+
code: "INVALID_OP_RETURN",
|
|
189
|
+
}
|
|
190
|
+
}
|
|
163
191
|
if (data.length === offset) {
|
|
164
192
|
return {
|
|
165
193
|
status: true,
|
|
@@ -169,43 +197,11 @@ function parseWrapRequest(data: string) {
|
|
|
169
197
|
|
|
170
198
|
return {
|
|
171
199
|
status: false,
|
|
172
|
-
message: `invalid OP_RETURN data for requestType: '
|
|
200
|
+
message: `invalid OP_RETURN data for requestType: 'wrap or wrapAndSwap'. invalid data length : ${data.length} - valid length : ${offset}`,
|
|
173
201
|
code: "INVALID_OP_RETURN",
|
|
174
202
|
}
|
|
175
203
|
}
|
|
176
204
|
|
|
177
|
-
// function parseLendAndBorrowRequest(data: string) {
|
|
178
|
-
// let parsedData: any = {}
|
|
179
|
-
// parsedData.requestType = "lend"
|
|
180
|
-
|
|
181
|
-
// let offset = 0
|
|
182
|
-
// parsedData.chainId = BigNumber(`0x${data.slice(offset, (offset += 2))}`) // 1 bytes
|
|
183
|
-
// parsedData.appId = BigNumber(`0x${data.slice(offset, (offset += 4))}`) // 2 bytes
|
|
184
|
-
// parsedData.recipientAddress = `0x${data.slice(offset, (offset += 40))}` // 20 bytes
|
|
185
|
-
// parsedData.percentageFee = BigNumber(`0x${data.slice(offset, (offset += 4))}`) / 100 // 2 bytes
|
|
186
|
-
// parsedData.mode = BigNumber(`0x${data.slice(offset, (offset += 2))}`) // 1 byte
|
|
187
|
-
// if (data.length === offset) {
|
|
188
|
-
// return {
|
|
189
|
-
// status: true,
|
|
190
|
-
// data: parsedData,
|
|
191
|
-
// }
|
|
192
|
-
// }
|
|
193
|
-
// parsedData.requestType = "borrow"
|
|
194
|
-
// parsedData.tokenAddress = `0x${data.slice(offset, (offset += 40))}` // 20 bytes
|
|
195
|
-
// parsedData.borrowAmount = BigNumber(`0x${data.slice(offset, (offset += 56))}`) // 28 bytes
|
|
196
|
-
// if (data.length === offset) {
|
|
197
|
-
// return {
|
|
198
|
-
// status: true,
|
|
199
|
-
// data: parsedData,
|
|
200
|
-
// }
|
|
201
|
-
// }
|
|
202
|
-
// return {
|
|
203
|
-
// status: false,
|
|
204
|
-
// message: `invalid OP_RETURN data for requestType: 'lend or borrow'. invalid data length : ${data.length} - valid length : ${offset}`,
|
|
205
|
-
// code: "INVALID_OP_RETURN",
|
|
206
|
-
// }
|
|
207
|
-
// }
|
|
208
|
-
|
|
209
205
|
export function parseWrapRawRequest(opReturnData: string) {
|
|
210
206
|
let data = opReturnData.slice(2, 4) === "4c" ? opReturnData.slice(6) : opReturnData.slice(4)
|
|
211
207
|
let appIdHex = data.slice(2, 6) // 2 bytes
|
|
@@ -239,11 +235,7 @@ export function parseWrapRawRequest(opReturnData: string) {
|
|
|
239
235
|
}
|
|
240
236
|
}
|
|
241
237
|
|
|
242
|
-
export function checkAndParseWrapRequest(
|
|
243
|
-
vouts: Vout[],
|
|
244
|
-
lockerAddress: string,
|
|
245
|
-
{ minTeleporterFeeAmount = 0 } = {},
|
|
246
|
-
) {
|
|
238
|
+
export function checkAndParseWrapRequest(vouts: Vout[], lockerAddress: string) {
|
|
247
239
|
let requestOutputIndex = vouts.findIndex((vout_) => vout_.script.startsWith("6a"))
|
|
248
240
|
if (requestOutputIndex >= 0) {
|
|
249
241
|
let opReturnData = vouts[requestOutputIndex]?.script || null
|
|
@@ -268,29 +260,13 @@ export function checkAndParseWrapRequest(
|
|
|
268
260
|
}
|
|
269
261
|
}
|
|
270
262
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
code: "INVALID_FEE",
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if ((data.percentageFee / 100) * +value <= minTeleporterFeeAmount) {
|
|
282
|
-
return {
|
|
283
|
-
status: false,
|
|
284
|
-
message: `fee amount is less than or equal minimum teleporter fee amount.percentageFee: ${
|
|
285
|
-
data.percentageFee
|
|
286
|
-
} - value: ${value} - feeAmount ${((data.percentageFee / 100) * +value).toFixed(
|
|
287
|
-
8,
|
|
288
|
-
)} - minimumFee: ${minTeleporterFeeAmount}`,
|
|
289
|
-
code: "NOT_ACCEPTED_BY_TELEPORTER",
|
|
290
|
-
}
|
|
263
|
+
return {
|
|
264
|
+
status: response.status,
|
|
265
|
+
data: response.data,
|
|
266
|
+
value,
|
|
267
|
+
valueOutputIndex,
|
|
268
|
+
requestOutputIndex,
|
|
291
269
|
}
|
|
292
|
-
|
|
293
|
-
return { status: response.status, data, value, valueOutputIndex }
|
|
294
270
|
}
|
|
295
271
|
return {
|
|
296
272
|
status: false,
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export * as bitcoinUtils from "./bitcoin-utils"
|
|
2
|
-
export * from "./helper"
|
|
3
|
-
export * from "./type"
|
|
4
|
-
//
|
|
5
|
-
export * from "./teleswap-wallet"
|
|
6
|
-
export * from "./ordinal-wallet"
|
|
7
|
-
export * from "./bitcoin-wallet-base"
|
|
8
|
-
//
|
|
9
|
-
export * from "./bitcoin-interface-utils"
|
|
10
|
-
export * from "./bitcoin-interface"
|
|
11
|
-
export * from "./bitcoin-interface-teleswap"
|
|
12
|
-
export * from "./bitcoin-interface-ordinal"
|
|
13
|
-
//
|
|
14
|
-
export * from "./transaction-builder"
|
|
15
|
-
export * from "./sign"
|
|
1
|
+
export * as bitcoinUtils from "./bitcoin-utils"
|
|
2
|
+
export * from "./helper"
|
|
3
|
+
export * from "./type"
|
|
4
|
+
//
|
|
5
|
+
export * from "./teleswap-wallet"
|
|
6
|
+
export * from "./ordinal-wallet"
|
|
7
|
+
export * from "./bitcoin-wallet-base"
|
|
8
|
+
//
|
|
9
|
+
export * from "./bitcoin-interface-utils"
|
|
10
|
+
export * from "./bitcoin-interface"
|
|
11
|
+
export * from "./bitcoin-interface-teleswap"
|
|
12
|
+
export * from "./bitcoin-interface-ordinal"
|
|
13
|
+
//
|
|
14
|
+
export * from "./transaction-builder"
|
|
15
|
+
export * from "./sign"
|