@teleportdao/bitcoin 4.0.3 → 4.1.0-alpha.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/dist/bitcoin-interface-teleswap.d.ts +3 -3
- package/dist/bitcoin-interface-teleswap.d.ts.map +1 -1
- package/dist/bitcoin-interface-teleswap.js.map +1 -1
- package/dist/helper/teleswap-helper.d.ts +39 -4
- package/dist/helper/teleswap-helper.d.ts.map +1 -1
- package/dist/helper/teleswap-helper.js +162 -17
- package/dist/helper/teleswap-helper.js.map +1 -1
- package/dist/sign/sign-transaction.d.ts.map +1 -1
- package/dist/sign/sign-transaction.js +0 -1
- package/dist/sign/sign-transaction.js.map +1 -1
- package/dist/teleswap-wallet.d.ts +18 -0
- package/dist/teleswap-wallet.d.ts.map +1 -1
- package/dist/teleswap-wallet.js +41 -0
- package/dist/teleswap-wallet.js.map +1 -1
- package/dist/transaction-builder/transaction-builder.d.ts.map +1 -1
- package/dist/transaction-builder/transaction-builder.js +21 -24
- package/dist/transaction-builder/transaction-builder.js.map +1 -1
- package/dist/utils/tools.d.ts.map +1 -1
- package/dist/utils/tools.js +0 -1
- package/dist/utils/tools.js.map +1 -1
- package/package.json +4 -4
- package/src/bitcoin-interface-teleswap.ts +2 -1
- package/src/helper/teleswap-helper.ts +234 -31
- package/src/sign/sign-transaction.ts +0 -1
- package/src/teleswap-wallet.ts +67 -1
- package/src/transaction-builder/transaction-builder.ts +31 -25
- package/src/utils/tools.ts +0 -1
package/src/teleswap-wallet.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
TargetAddress,
|
|
6
6
|
} from "./transaction-builder/transaction-builder"
|
|
7
7
|
import { BitcoinBaseWallet, FeeRateType } from "./bitcoin-wallet-base"
|
|
8
|
-
import { generateWrapOpReturn } from "./helper/teleswap-helper"
|
|
8
|
+
import { generateWrapOpReturn, generateWrapOpReturnV2 } from "./helper/teleswap-helper"
|
|
9
9
|
|
|
10
10
|
export type TransferRequest = {
|
|
11
11
|
changeAddress?: string
|
|
@@ -134,5 +134,71 @@ export class TeleswapWallet extends BitcoinBaseWallet {
|
|
|
134
134
|
|
|
135
135
|
return unsignedTx
|
|
136
136
|
}
|
|
137
|
+
|
|
138
|
+
async wrapUnsignedV2(
|
|
139
|
+
recipientAddress: string,
|
|
140
|
+
amount: string,
|
|
141
|
+
networkFee: string,
|
|
142
|
+
lockerAddress: string,
|
|
143
|
+
chainId: number, // 80001
|
|
144
|
+
signer: SignerInfo,
|
|
145
|
+
exchange?: {
|
|
146
|
+
outputToken: string
|
|
147
|
+
minOutputAmount: string
|
|
148
|
+
bridgePercentageFee?: number
|
|
149
|
+
},
|
|
150
|
+
appId = exchange
|
|
151
|
+
? teleswap.requestAppId.WrapAndSwap.default
|
|
152
|
+
: teleswap.requestAppId.Wrap.default,
|
|
153
|
+
speed = false,
|
|
154
|
+
fee: FeeRateType = "normal",
|
|
155
|
+
thirdPartyId?: number,
|
|
156
|
+
staticExtendedUtxo?: ExtendedUtxo[],
|
|
157
|
+
changeAddress?: string,
|
|
158
|
+
fullAmount = false,
|
|
159
|
+
) {
|
|
160
|
+
// split last 8 bytes of outputToken to get outputTokenId
|
|
161
|
+
|
|
162
|
+
const outputTokenId = exchange?.outputToken
|
|
163
|
+
? exchange.outputToken.replace("0x", "").slice(-16)
|
|
164
|
+
: undefined
|
|
165
|
+
const dataHex = generateWrapOpReturnV2({
|
|
166
|
+
chainId,
|
|
167
|
+
appId,
|
|
168
|
+
recipientAddress,
|
|
169
|
+
networkFee,
|
|
170
|
+
speed,
|
|
171
|
+
isExchange: !!exchange,
|
|
172
|
+
minOutputAmount: exchange?.minOutputAmount,
|
|
173
|
+
minIntermediaryTokenAmount: "0",
|
|
174
|
+
outputTokenId,
|
|
175
|
+
bridgePercentageFee: exchange?.bridgePercentageFee,
|
|
176
|
+
thirdPartyId,
|
|
177
|
+
})
|
|
178
|
+
let extendedUtxo = staticExtendedUtxo || (await this.getExtendedUtxo(signer))
|
|
179
|
+
let feeRate = await this.getFeeRate(fee)
|
|
180
|
+
|
|
181
|
+
const targets = fullAmount
|
|
182
|
+
? [this.transactionBuilder.getOpReturnTarget(dataHex)]
|
|
183
|
+
: [
|
|
184
|
+
{
|
|
185
|
+
address: lockerAddress,
|
|
186
|
+
value: +amount,
|
|
187
|
+
},
|
|
188
|
+
this.transactionBuilder.getOpReturnTarget(dataHex),
|
|
189
|
+
]
|
|
190
|
+
|
|
191
|
+
const sequenceNumber = speed === true ? this.transactionBuilder.NO_RBF_SEQUENCE : undefined
|
|
192
|
+
const unsignedTx = this.transactionBuilder.processUnsignedTransaction({
|
|
193
|
+
extendedUtxo,
|
|
194
|
+
feeRate,
|
|
195
|
+
targets,
|
|
196
|
+
changeAddress: fullAmount ? lockerAddress : changeAddress || signer.address,
|
|
197
|
+
fullAmount,
|
|
198
|
+
sequenceNumber,
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
return unsignedTx
|
|
202
|
+
}
|
|
137
203
|
}
|
|
138
204
|
export default TeleswapWallet
|
|
@@ -257,10 +257,6 @@ export abstract class BaseTransactionBuilder {
|
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
let diff = fee - txFee
|
|
260
|
-
|
|
261
|
-
if (Math.abs(diff) >= DUST) {
|
|
262
|
-
console.log("diff", diff, "fee", fee, "txFee", txFee)
|
|
263
|
-
}
|
|
264
260
|
let changeIndex = outputs.findIndex((x) => !x?.address && !x.script && (x.value || 0) > 0)
|
|
265
261
|
let change: ChangeTarget | undefined
|
|
266
262
|
if (diff > 0) {
|
|
@@ -312,9 +308,7 @@ export abstract class BaseTransactionBuilder {
|
|
|
312
308
|
}
|
|
313
309
|
|
|
314
310
|
if (Math.abs(fee - newFee) > DUST) {
|
|
315
|
-
|
|
316
|
-
console.log("newFee", newFee)
|
|
317
|
-
throw new Error("fee mismatch")
|
|
311
|
+
throw new Error(`fee mismatch: ${JSON.stringify({ fee, newFee })}`)
|
|
318
312
|
}
|
|
319
313
|
|
|
320
314
|
// check outputs
|
|
@@ -322,32 +316,38 @@ export abstract class BaseTransactionBuilder {
|
|
|
322
316
|
let totalNewOutputValue = newOutputs.reduce((a, b) => a + b.value, 0)
|
|
323
317
|
|
|
324
318
|
if (totalOutputValue - totalNewOutputValue !== 0) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
throw new Error("output value mismatch")
|
|
319
|
+
throw new Error(
|
|
320
|
+
`output value mismatch${JSON.stringify({ totalOutputValue, totalNewOutputValue })}`,
|
|
321
|
+
)
|
|
329
322
|
}
|
|
330
323
|
|
|
331
324
|
if (outputs.length !== newOutputs.length) {
|
|
332
|
-
|
|
333
|
-
console.log("newOutputs", newOutputs)
|
|
334
|
-
throw new Error("output length mismatch")
|
|
325
|
+
throw new Error(`output length mismatch: ${JSON.stringify({ outputs, newOutputs })}`)
|
|
335
326
|
}
|
|
336
327
|
for (let i = 0; i < outputs.length; i += 1) {
|
|
337
328
|
if (outputs[i].value !== newOutputs[i].value) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
329
|
+
throw new Error(
|
|
330
|
+
`output value mismatch: ${JSON.stringify({
|
|
331
|
+
old: outputs[i].value,
|
|
332
|
+
new: newOutputs[i].value,
|
|
333
|
+
})}`,
|
|
334
|
+
)
|
|
341
335
|
}
|
|
342
336
|
if (outputs[i].address !== newOutputs[i].address) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
337
|
+
throw new Error(
|
|
338
|
+
`output address mismatch: ${JSON.stringify({
|
|
339
|
+
old: outputs[i].address,
|
|
340
|
+
new: newOutputs[i].address,
|
|
341
|
+
})}`,
|
|
342
|
+
)
|
|
346
343
|
}
|
|
347
344
|
if (outputs[i].script !== newOutputs[i].script) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
345
|
+
throw new Error(
|
|
346
|
+
`output script mismatch: ${JSON.stringify({
|
|
347
|
+
old: outputs[i].script,
|
|
348
|
+
new: newOutputs[i].script,
|
|
349
|
+
})}`,
|
|
350
|
+
)
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
353
|
|
|
@@ -360,8 +360,14 @@ export abstract class BaseTransactionBuilder {
|
|
|
360
360
|
totalInputValue - (change?.value || 0) - (totalNewInputValue - (newChange?.value || 0)),
|
|
361
361
|
) > DUST
|
|
362
362
|
) {
|
|
363
|
-
|
|
364
|
-
|
|
363
|
+
throw new Error(
|
|
364
|
+
`input value mismatch: ${JSON.stringify({
|
|
365
|
+
totalInputValue,
|
|
366
|
+
totalNewInputValue,
|
|
367
|
+
changeValue: change?.value,
|
|
368
|
+
newChangeValue: newChange?.value,
|
|
369
|
+
})}`,
|
|
370
|
+
)
|
|
365
371
|
}
|
|
366
372
|
|
|
367
373
|
return { inputs, outputs, change, fee }
|
package/src/utils/tools.ts
CHANGED