@teleportdao/bitcoin 1.6.1 → 1.7.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/.tmp/check.ts +101 -0
- package/.tmp/psbt/sign-transaction.ts +121 -0
- package/.tmp/rbf.ts +45 -0
- package/dist/bitcoin-interface-ordinal.d.ts +109 -0
- package/dist/bitcoin-interface-ordinal.d.ts.map +1 -0
- package/dist/bitcoin-interface-ordinal.js +141 -0
- package/dist/bitcoin-interface-ordinal.js.map +1 -0
- package/dist/bitcoin-interface-teleswap.d.ts +148 -0
- package/dist/bitcoin-interface-teleswap.d.ts.map +1 -0
- package/dist/bitcoin-interface-teleswap.js +179 -0
- package/dist/bitcoin-interface-teleswap.js.map +1 -0
- package/dist/bitcoin-interface-utils.d.ts.map +1 -1
- package/dist/bitcoin-interface-utils.js.map +1 -1
- package/dist/bitcoin-interface.d.ts +45 -333
- package/dist/bitcoin-interface.d.ts.map +1 -1
- package/dist/bitcoin-interface.js +68 -202
- package/dist/bitcoin-interface.js.map +1 -1
- package/dist/bitcoin-utils.d.ts +12 -59
- package/dist/bitcoin-utils.d.ts.map +1 -1
- package/dist/bitcoin-utils.js +61 -61
- package/dist/bitcoin-utils.js.map +1 -1
- package/dist/{bitcoin-base.d.ts → bitcoin-wallet-base.d.ts} +9 -9
- package/dist/bitcoin-wallet-base.d.ts.map +1 -0
- package/dist/{bitcoin-base.js → bitcoin-wallet-base.js} +15 -14
- package/dist/bitcoin-wallet-base.js.map +1 -0
- package/dist/helper/brc20-helper.d.ts +43 -0
- package/dist/helper/brc20-helper.d.ts.map +1 -0
- package/dist/helper/brc20-helper.js +129 -0
- package/dist/helper/brc20-helper.js.map +1 -0
- package/dist/helper/index.d.ts +4 -0
- package/dist/helper/index.d.ts.map +1 -0
- package/dist/helper/index.js +30 -0
- package/dist/helper/index.js.map +1 -0
- package/dist/helper/ordinal-helper.d.ts +13 -0
- package/dist/helper/ordinal-helper.d.ts.map +1 -0
- package/dist/helper/ordinal-helper.js +127 -0
- package/dist/helper/ordinal-helper.js.map +1 -0
- package/dist/helper/teleswap-helper.d.ts +84 -0
- package/dist/helper/teleswap-helper.d.ts.map +1 -0
- package/dist/helper/teleswap-helper.js +181 -0
- package/dist/helper/teleswap-helper.js.map +1 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/ordinal-wallet.d.ts +536 -0
- package/dist/ordinal-wallet.d.ts.map +1 -0
- package/dist/ordinal-wallet.js +448 -0
- package/dist/ordinal-wallet.js.map +1 -0
- package/dist/sign/sign-transaction.d.ts +2 -4
- package/dist/sign/sign-transaction.d.ts.map +1 -1
- package/dist/sign/sign-transaction.js +26 -22
- package/dist/sign/sign-transaction.js.map +1 -1
- package/dist/teleswap-wallet.d.ts +54 -0
- package/dist/teleswap-wallet.d.ts.map +1 -0
- package/dist/teleswap-wallet.js +87 -0
- package/dist/teleswap-wallet.js.map +1 -0
- package/dist/transaction-builder/bitcoin-transaction-builder.d.ts +2 -20
- package/dist/transaction-builder/bitcoin-transaction-builder.d.ts.map +1 -1
- package/dist/transaction-builder/bitcoin-transaction-builder.js +5 -4
- package/dist/transaction-builder/bitcoin-transaction-builder.js.map +1 -1
- package/dist/transaction-builder/index.d.ts +2 -1
- package/dist/transaction-builder/index.d.ts.map +1 -1
- package/dist/transaction-builder/index.js +2 -6
- package/dist/transaction-builder/index.js.map +1 -1
- package/dist/transaction-builder/ordinal-transaction-builder.d.ts +63 -0
- package/dist/transaction-builder/ordinal-transaction-builder.d.ts.map +1 -0
- package/dist/transaction-builder/ordinal-transaction-builder.js +131 -0
- package/dist/transaction-builder/ordinal-transaction-builder.js.map +1 -0
- package/dist/transaction-builder/transaction-builder.d.ts +10 -7
- package/dist/transaction-builder/transaction-builder.d.ts.map +1 -1
- package/dist/transaction-builder/transaction-builder.js +18 -9
- package/dist/transaction-builder/transaction-builder.js.map +1 -1
- package/dist/type.d.ts +43 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +3 -0
- package/dist/type.js.map +1 -0
- package/dist/utils/tools.d.ts +4 -4
- package/dist/utils/tools.d.ts.map +1 -1
- package/dist/utils/tools.js +8 -5
- package/dist/utils/tools.js.map +1 -1
- package/package.json +6 -9
- package/src/bitcoin-interface-ordinal.ts +181 -0
- package/src/bitcoin-interface-teleswap.ts +255 -0
- package/src/bitcoin-interface-utils.ts +1 -1
- package/src/bitcoin-interface.ts +99 -303
- package/src/bitcoin-utils.ts +65 -90
- package/src/{bitcoin-base.ts → bitcoin-wallet-base.ts} +24 -19
- package/src/helper/brc20-helper.ts +181 -0
- package/src/helper/index.ts +3 -0
- package/src/helper/ordinal-helper.ts +118 -0
- package/src/helper/teleswap-helper.ts +300 -0
- package/src/index.ts +11 -3
- package/src/ordinal-wallet.ts +738 -0
- package/src/sign/sign-transaction.ts +42 -33
- package/src/teleswap-wallet.ts +155 -0
- package/src/transaction-builder/bitcoin-transaction-builder.ts +7 -24
- package/src/transaction-builder/index.ts +2 -1
- package/src/transaction-builder/ordinal-transaction-builder.ts +147 -0
- package/src/transaction-builder/transaction-builder.ts +33 -15
- package/src/type.ts +43 -0
- package/src/utils/tools.ts +17 -11
- package/tsconfig.json +1 -2
- package/dist/bitcoin-base.d.ts.map +0 -1
- package/dist/bitcoin-base.js.map +0 -1
- package/dist/bitcoin-utils-2.d.ts +0 -2
- package/dist/bitcoin-utils-2.d.ts.map +0 -1
- package/dist/bitcoin-utils-2.js +0 -13
- package/dist/bitcoin-utils-2.js.map +0 -1
- package/dist/bundle.js +0 -17
- package/dist/helper/burn-request-helper.d.ts +0 -7
- package/dist/helper/burn-request-helper.d.ts.map +0 -1
- package/dist/helper/burn-request-helper.js +0 -26
- package/dist/helper/burn-request-helper.js.map +0 -1
- package/dist/helper/teleport-request-helper.d.ts +0 -47
- package/dist/helper/teleport-request-helper.d.ts.map +0 -1
- package/dist/helper/teleport-request-helper.js +0 -146
- package/dist/helper/teleport-request-helper.js.map +0 -1
- package/dist/mempool-space.d.ts +0 -69
- package/dist/mempool-space.d.ts.map +0 -1
- package/dist/mempool-space.js +0 -266
- package/dist/mempool-space.js.map +0 -1
- package/dist/teleport-dao-payments.d.ts +0 -76
- package/dist/teleport-dao-payments.d.ts.map +0 -1
- package/dist/teleport-dao-payments.js +0 -217
- package/dist/teleport-dao-payments.js.map +0 -1
- package/src/helper/burn-request-helper.js +0 -27
- package/src/helper/teleport-request-helper.js +0 -181
- package/src/teleport-dao-payments.ts +0 -347
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import type { ExtendedUtxo, Target } from "./transaction-builder/transaction-builder";
|
|
2
|
-
import { BitcoinBase } from "./bitcoin-base";
|
|
3
|
-
export type TransferRequest = {
|
|
4
|
-
changeAddress?: string;
|
|
5
|
-
lockerAddress: string;
|
|
6
|
-
amount: number;
|
|
7
|
-
fullAmount?: boolean;
|
|
8
|
-
chainId: number;
|
|
9
|
-
appId: number;
|
|
10
|
-
recipientAddress: string;
|
|
11
|
-
percentageFee: number;
|
|
12
|
-
speed?: number | boolean;
|
|
13
|
-
isExchange?: boolean;
|
|
14
|
-
exchangeTokenAddress?: string;
|
|
15
|
-
outputAmount?: number;
|
|
16
|
-
deadline?: number;
|
|
17
|
-
isFixedToken?: boolean;
|
|
18
|
-
feeSpeed?: "normal" | "fast" | "slow";
|
|
19
|
-
staticFeeRate?: number;
|
|
20
|
-
};
|
|
21
|
-
export declare class TeleportDaoPayment extends BitcoinBase {
|
|
22
|
-
payBurnRequest(receivers: Target[], feeSpeed?: "normal" | "fast" | "slow"): Promise<string>;
|
|
23
|
-
transferBitcoinToEth({ lockerAddress, amount, fullAmount, chainId, appId, recipientAddress, percentageFee, speed, isExchange, exchangeTokenAddress, outputAmount, deadline, isFixedToken, feeSpeed, staticFeeRate, }: TransferRequest): Promise<string>;
|
|
24
|
-
getBitcoinToEthTargetOutputs({ lockerAddress, amount, fullAmount, chainId, appId, recipientAddress, percentageFee, speed, isExchange, exchangeTokenAddress, outputAmount, deadline, isFixedToken, }: TransferRequest): Promise<Target[]>;
|
|
25
|
-
getBitcoinToEthUnsignedPsbt({ changeAddress, extendedUtxo, lockerAddress, amount, fullAmount, chainId, appId, recipientAddress, percentageFee, speed, isExchange, exchangeTokenAddress, outputAmount, deadline, isFixedToken, feeSpeed, staticFeeRate, }: TransferRequest & {
|
|
26
|
-
extendedUtxo: ExtendedUtxo[];
|
|
27
|
-
}): Promise<{
|
|
28
|
-
unsignedTransaction: string;
|
|
29
|
-
outputs: Target[];
|
|
30
|
-
inputs: {
|
|
31
|
-
hash: string;
|
|
32
|
-
value: number;
|
|
33
|
-
index: number;
|
|
34
|
-
signerInfo: import("./transaction-builder/transaction-builder").SignerInfo;
|
|
35
|
-
}[];
|
|
36
|
-
fee: number;
|
|
37
|
-
change: import("./transaction-builder/transaction-builder").ChangeTarget | undefined;
|
|
38
|
-
}>;
|
|
39
|
-
bitcoinToEthLend({ lockerAddress, amount, chainId, appId, recipientAddress, percentageFee, mode, isBorrow, tokenAddress, borrowAmount, staticFeeRate, }: {
|
|
40
|
-
lockerAddress: string;
|
|
41
|
-
amount: number;
|
|
42
|
-
chainId: number;
|
|
43
|
-
appId: number;
|
|
44
|
-
recipientAddress: string;
|
|
45
|
-
percentageFee: number;
|
|
46
|
-
staticFeeRate: number;
|
|
47
|
-
mode?: 0 | 1 | boolean;
|
|
48
|
-
isBorrow?: boolean;
|
|
49
|
-
tokenAddress?: string;
|
|
50
|
-
borrowAmount?: number;
|
|
51
|
-
}): Promise<string>;
|
|
52
|
-
static getTransferOpReturnData({ chainId, appId, recipientAddress, percentageFee, speed, isExchange, exchangeTokenAddress, outputAmount, deadline, isFixedToken, }: {
|
|
53
|
-
chainId: number;
|
|
54
|
-
appId: number;
|
|
55
|
-
recipientAddress: string;
|
|
56
|
-
percentageFee: number;
|
|
57
|
-
deadline: number;
|
|
58
|
-
speed?: number | boolean;
|
|
59
|
-
isExchange?: boolean;
|
|
60
|
-
exchangeTokenAddress?: string;
|
|
61
|
-
outputAmount?: number;
|
|
62
|
-
isFixedToken?: boolean;
|
|
63
|
-
}): string;
|
|
64
|
-
static getLendingOpReturnData({ chainId, appId, recipientAddress, percentageFee, mode, isBorrow, tokenAddress, borrowAmount, }: {
|
|
65
|
-
chainId: number;
|
|
66
|
-
appId: number;
|
|
67
|
-
recipientAddress: string;
|
|
68
|
-
percentageFee: number;
|
|
69
|
-
mode?: 0 | 1 | boolean;
|
|
70
|
-
isBorrow?: boolean;
|
|
71
|
-
tokenAddress?: string;
|
|
72
|
-
borrowAmount?: number;
|
|
73
|
-
}): string;
|
|
74
|
-
}
|
|
75
|
-
export default TeleportDaoPayment;
|
|
76
|
-
//# sourceMappingURL=teleport-dao-payments.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"teleport-dao-payments.d.ts","sourceRoot":"","sources":["../src/teleport-dao-payments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAA;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,gBAAgB,EAAE,MAAM,CAAA;IACxB,aAAa,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACxB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,OAAO,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,CAAC,EAAE,MAAM,CAAA;QACrB,YAAY,CAAC,EAAE,MAAM,CAAA;KACtB;CAoBF;AACD,eAAe,kBAAkB,CAAA"}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.TeleportDaoPayment = void 0;
|
|
13
|
-
const bitcoin_base_1 = require("./bitcoin-base");
|
|
14
|
-
class TeleportDaoPayment extends bitcoin_base_1.BitcoinBase {
|
|
15
|
-
payBurnRequest(receivers, feeSpeed = "normal") {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
if (!this.currentAccount || !this.currentAccountType || !this.publicKey || !this.privateKey) {
|
|
18
|
-
throw new Error("account not initialized");
|
|
19
|
-
}
|
|
20
|
-
let extendedUtxo = yield this.getExtendedUtxo({
|
|
21
|
-
address: this.currentAccount,
|
|
22
|
-
addressType: this.currentAccountType,
|
|
23
|
-
publicKey: this.publicKey.toString("hex"),
|
|
24
|
-
});
|
|
25
|
-
let feeRate = yield this.transactionBuilder._getFeeRate(feeSpeed);
|
|
26
|
-
let unsignedTx = yield this.transactionBuilder.processUnsignedTransaction({
|
|
27
|
-
extendedUtxo,
|
|
28
|
-
targets: receivers,
|
|
29
|
-
changeAddress: this.currentAccount,
|
|
30
|
-
feeRate,
|
|
31
|
-
fullAmount: false,
|
|
32
|
-
});
|
|
33
|
-
let signedPsbt = yield this.signer.signPsbt(unsignedTx, this.privateKey);
|
|
34
|
-
let signedTx = this.signer.finalizePsbts([signedPsbt]);
|
|
35
|
-
let txId = yield this.transactionBuilder.sendTx(signedTx);
|
|
36
|
-
return txId;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
transferBitcoinToEth({ lockerAddress, amount, fullAmount = false, chainId, appId, recipientAddress, percentageFee, speed = 0, isExchange = false, exchangeTokenAddress = "0x0000000000000000000000000000000000000000", outputAmount = 0, deadline, isFixedToken = false, feeSpeed = "normal", staticFeeRate, }) {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
if (!this.currentAccount || !this.currentAccountType || !this.publicKey || !this.privateKey) {
|
|
42
|
-
throw new Error("account not initialized");
|
|
43
|
-
}
|
|
44
|
-
let extendedUtxo = yield this.getExtendedUtxo({
|
|
45
|
-
address: this.currentAccount,
|
|
46
|
-
addressType: this.currentAccountType,
|
|
47
|
-
publicKey: this.publicKey.toString("hex"),
|
|
48
|
-
});
|
|
49
|
-
let unsignedTx = yield this.getBitcoinToEthUnsignedPsbt({
|
|
50
|
-
changeAddress: this.currentAccount,
|
|
51
|
-
extendedUtxo,
|
|
52
|
-
lockerAddress,
|
|
53
|
-
amount,
|
|
54
|
-
fullAmount,
|
|
55
|
-
chainId,
|
|
56
|
-
appId,
|
|
57
|
-
recipientAddress,
|
|
58
|
-
percentageFee,
|
|
59
|
-
speed,
|
|
60
|
-
isExchange,
|
|
61
|
-
exchangeTokenAddress,
|
|
62
|
-
outputAmount,
|
|
63
|
-
deadline,
|
|
64
|
-
isFixedToken,
|
|
65
|
-
feeSpeed,
|
|
66
|
-
staticFeeRate,
|
|
67
|
-
});
|
|
68
|
-
let signedPsbt = yield this.signer.signPsbt(unsignedTx, this.privateKey);
|
|
69
|
-
let txId = yield this.sendSignedPsbt(signedPsbt);
|
|
70
|
-
return txId;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
getBitcoinToEthTargetOutputs({ lockerAddress, amount, fullAmount = false, chainId, appId, recipientAddress, percentageFee, speed = 0, isExchange = false, exchangeTokenAddress = "0x0000000000000000000000000000000000000000", outputAmount = 0, deadline = 0, isFixedToken = false, }) {
|
|
74
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
let dataHex = TeleportDaoPayment.getTransferOpReturnData({
|
|
76
|
-
chainId,
|
|
77
|
-
appId,
|
|
78
|
-
recipientAddress,
|
|
79
|
-
percentageFee,
|
|
80
|
-
speed,
|
|
81
|
-
isExchange,
|
|
82
|
-
exchangeTokenAddress,
|
|
83
|
-
outputAmount,
|
|
84
|
-
deadline,
|
|
85
|
-
isFixedToken,
|
|
86
|
-
});
|
|
87
|
-
let opTarget = this.transactionBuilder.getOpReturnTarget(dataHex);
|
|
88
|
-
return fullAmount
|
|
89
|
-
? [opTarget]
|
|
90
|
-
: [
|
|
91
|
-
{
|
|
92
|
-
address: lockerAddress,
|
|
93
|
-
value: amount,
|
|
94
|
-
},
|
|
95
|
-
opTarget,
|
|
96
|
-
];
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
getBitcoinToEthUnsignedPsbt({ changeAddress, extendedUtxo, lockerAddress, amount, fullAmount = false, chainId, appId, recipientAddress, percentageFee, speed = 0, isExchange = false, exchangeTokenAddress = "0x0000000000000000000000000000000000000000", outputAmount = 0, deadline = 0, isFixedToken = false, feeSpeed = "normal", staticFeeRate, }) {
|
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
let feeRate = staticFeeRate || (yield this.transactionBuilder._getFeeRate(feeSpeed));
|
|
102
|
-
let targets = yield this.getBitcoinToEthTargetOutputs({
|
|
103
|
-
lockerAddress,
|
|
104
|
-
amount,
|
|
105
|
-
fullAmount,
|
|
106
|
-
chainId,
|
|
107
|
-
appId,
|
|
108
|
-
recipientAddress,
|
|
109
|
-
percentageFee,
|
|
110
|
-
speed,
|
|
111
|
-
isExchange,
|
|
112
|
-
exchangeTokenAddress,
|
|
113
|
-
outputAmount,
|
|
114
|
-
deadline,
|
|
115
|
-
isFixedToken,
|
|
116
|
-
});
|
|
117
|
-
let unsignedTx = yield this.transactionBuilder.processUnsignedTransaction({
|
|
118
|
-
extendedUtxo,
|
|
119
|
-
targets,
|
|
120
|
-
changeAddress: fullAmount ? lockerAddress : changeAddress,
|
|
121
|
-
feeRate,
|
|
122
|
-
fullAmount,
|
|
123
|
-
});
|
|
124
|
-
return unsignedTx;
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
bitcoinToEthLend({ lockerAddress, amount, chainId, appId, recipientAddress, percentageFee, mode = 0, isBorrow = false, tokenAddress = "0x0000000000000000000000000000000000000000", borrowAmount = 0, staticFeeRate, }) {
|
|
128
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
-
if (!this.currentAccount || !this.currentAccountType || !this.publicKey || !this.privateKey) {
|
|
130
|
-
throw new Error("account not initialized");
|
|
131
|
-
}
|
|
132
|
-
let dataHex = TeleportDaoPayment.getLendingOpReturnData({
|
|
133
|
-
chainId,
|
|
134
|
-
appId,
|
|
135
|
-
recipientAddress,
|
|
136
|
-
percentageFee,
|
|
137
|
-
mode,
|
|
138
|
-
isBorrow,
|
|
139
|
-
tokenAddress,
|
|
140
|
-
borrowAmount,
|
|
141
|
-
});
|
|
142
|
-
let opTarget = this.transactionBuilder.getOpReturnTarget(dataHex);
|
|
143
|
-
let extendedUtxo = yield this.transactionBuilder.getExtendedUtxo({
|
|
144
|
-
address: this.currentAccount,
|
|
145
|
-
addressType: this.currentAccountType,
|
|
146
|
-
publicKey: this.publicKey.toString("hex"),
|
|
147
|
-
});
|
|
148
|
-
let unsignedTx = yield this.transactionBuilder.processUnsignedTransaction({
|
|
149
|
-
extendedUtxo,
|
|
150
|
-
targets: [
|
|
151
|
-
{
|
|
152
|
-
address: lockerAddress,
|
|
153
|
-
value: amount,
|
|
154
|
-
},
|
|
155
|
-
opTarget,
|
|
156
|
-
],
|
|
157
|
-
changeAddress: this.currentAccount,
|
|
158
|
-
feeRate: staticFeeRate,
|
|
159
|
-
fullAmount: false,
|
|
160
|
-
});
|
|
161
|
-
let signedPsbt = yield this.signer.signPsbt(unsignedTx, this.privateKey);
|
|
162
|
-
let signedTx = this.signer.finalizePsbts([signedPsbt]);
|
|
163
|
-
let txId = yield this.transactionBuilder.sendTx(signedTx);
|
|
164
|
-
return txId;
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
static getTransferOpReturnData({ chainId, appId, recipientAddress, percentageFee, speed = 0, isExchange = false, exchangeTokenAddress = "0x0000000000000000000000000000000000000000", outputAmount = 0, deadline, isFixedToken = false, }) {
|
|
168
|
-
let chainIdHex = Number(chainId).toString(16).padStart(2, "0");
|
|
169
|
-
let appIdHex = Number(appId).toString(16).padStart(4, "0");
|
|
170
|
-
let recipientAddressHex = recipientAddress.replace("0x", "").toLowerCase().padStart(40, "0");
|
|
171
|
-
let percentageFeeHex = Number((percentageFee * 100).toFixed(0))
|
|
172
|
-
.toString(16)
|
|
173
|
-
.padStart(4, "0");
|
|
174
|
-
let speedHex = speed ? "01" : "00";
|
|
175
|
-
let dataHex = chainIdHex + appIdHex + recipientAddressHex + percentageFeeHex + speedHex;
|
|
176
|
-
if (!isExchange) {
|
|
177
|
-
if (dataHex.length !== 26 * 2)
|
|
178
|
-
throw new Error("invalid data length");
|
|
179
|
-
return dataHex;
|
|
180
|
-
}
|
|
181
|
-
let exchangeTokenAddressHex = exchangeTokenAddress
|
|
182
|
-
.replace("0x", "")
|
|
183
|
-
.toLowerCase()
|
|
184
|
-
.padStart(40, "0");
|
|
185
|
-
let outputAmountHex = Number(outputAmount).toString(16).padStart(56, "0");
|
|
186
|
-
let deadlineHex = Number(deadline).toString(16).padStart(8, "0");
|
|
187
|
-
let isFixedTokenHex = isFixedToken ? "01" : "00";
|
|
188
|
-
dataHex = dataHex + exchangeTokenAddressHex + outputAmountHex + deadlineHex + isFixedTokenHex;
|
|
189
|
-
if (dataHex.length !== 79 * 2)
|
|
190
|
-
throw new Error("invalid data length");
|
|
191
|
-
return dataHex;
|
|
192
|
-
}
|
|
193
|
-
static getLendingOpReturnData({ chainId, appId, recipientAddress, percentageFee, mode, isBorrow = false, tokenAddress = "0x0000000000000000000000000000000000000000", borrowAmount = 0, }) {
|
|
194
|
-
let chainIdHex = Number(chainId).toString(16).padStart(2, "0");
|
|
195
|
-
let appIdHex = Number(appId).toString(16).padStart(4, "0");
|
|
196
|
-
let recipientAddressHex = recipientAddress.replace("0x", "").toLowerCase().padStart(40, "0");
|
|
197
|
-
let percentageFeeHex = Number((percentageFee * 100).toFixed(0))
|
|
198
|
-
.toString(16)
|
|
199
|
-
.padStart(4, "0");
|
|
200
|
-
let modeHex = Number(mode).toString(16).padStart(2, "0");
|
|
201
|
-
let dataHex = chainIdHex + appIdHex + recipientAddressHex + percentageFeeHex + modeHex;
|
|
202
|
-
if (!isBorrow) {
|
|
203
|
-
if (dataHex.length !== 26 * 2)
|
|
204
|
-
throw new Error("invalid data length");
|
|
205
|
-
return dataHex;
|
|
206
|
-
}
|
|
207
|
-
let tokenAddressHex = tokenAddress.replace("0x", "").toLowerCase().padStart(40, "0");
|
|
208
|
-
let borrowAmountHex = Number(borrowAmount).toString(16).padStart(56, "0");
|
|
209
|
-
dataHex = dataHex + tokenAddressHex + borrowAmountHex;
|
|
210
|
-
if (dataHex.length !== 74 * 2)
|
|
211
|
-
throw new Error("invalid data length");
|
|
212
|
-
return dataHex;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
exports.TeleportDaoPayment = TeleportDaoPayment;
|
|
216
|
-
exports.default = TeleportDaoPayment;
|
|
217
|
-
//# sourceMappingURL=teleport-dao-payments.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"teleport-dao-payments.js","sourceRoot":"","sources":["../src/teleport-dao-payments.ts"],"names":[],"mappings":";;;;;;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AAC,IAAI,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;QACpF,IAAI,eAAe,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;QACzE,OAAO,GAAG,OAAO,GAAG,eAAe,GAAG,eAAe,CAAA;QACrD,IAAI,OAAO,CAAC,MAAM,KAAK,EAAE,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;QACrE,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AAnUD,gDAmUC;AACD,kBAAe,kBAAkB,CAAA"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
function getBurnTransactionInfo(address, vin = [], vouts = []) {
|
|
2
|
-
let lockerVinIndex = vin.findIndex((vi) => vi.address === address)
|
|
3
|
-
if (lockerVinIndex >= 0) {
|
|
4
|
-
let lockerVin = vin[lockerVinIndex]
|
|
5
|
-
lockerVin.vinIndex = lockerVinIndex
|
|
6
|
-
let totalInputValue = vin.reduce((acc, current) => +acc + +current.value, 0)
|
|
7
|
-
let receivers = []
|
|
8
|
-
let changes = []
|
|
9
|
-
for (let i in vouts) {
|
|
10
|
-
let vout = {
|
|
11
|
-
...vouts[i],
|
|
12
|
-
index: i,
|
|
13
|
-
}
|
|
14
|
-
if (vout.address === address) {
|
|
15
|
-
changes.push(vout)
|
|
16
|
-
} else {
|
|
17
|
-
receivers.push(vout)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return { receivers, changes, totalInputValue, lockerVin }
|
|
21
|
-
}
|
|
22
|
-
return null
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = {
|
|
26
|
-
getBurnTransactionInfo,
|
|
27
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
const { requestTypes: teleportRequestsType } = require("@teleportdao/configs").teleswap
|
|
2
|
-
const { BigNumber } = require("bignumber.js")
|
|
3
|
-
|
|
4
|
-
function parseTeleportAndExchangeRequest(data) {
|
|
5
|
-
let parsedData = {}
|
|
6
|
-
parsedData.requestType = "transfer"
|
|
7
|
-
|
|
8
|
-
let offset = 0
|
|
9
|
-
parsedData.chainId = Number(`0x${data.slice(offset, (offset += 2))}`) // 1 bytes
|
|
10
|
-
parsedData.appId = Number(`0x${data.slice(offset, (offset += 4))}`) // 2 bytes
|
|
11
|
-
parsedData.recipientAddress = `0x${data.slice(offset, (offset += 40))}` // 20 bytes
|
|
12
|
-
parsedData.percentageFee = Number(`0x${data.slice(offset, (offset += 4))}`) / 100 // 2 bytes
|
|
13
|
-
parsedData.speed = data.slice(offset, (offset += 2)) === "01" // 1 byte
|
|
14
|
-
if (data.length === offset) {
|
|
15
|
-
return {
|
|
16
|
-
status: true,
|
|
17
|
-
data: parsedData,
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
parsedData.requestType = "exchange"
|
|
22
|
-
parsedData.exchangeTokenAddress = `0x${data.slice(offset, (offset += 40))}` // 20 bytes
|
|
23
|
-
parsedData.outputAmount = new BigNumber(`0x${data.slice(offset, (offset += 56))}`).toFixed() // 28 bytes
|
|
24
|
-
parsedData.deadline = new BigNumber(`0x${data.slice(offset, (offset += 8))}`).toFixed() // 4 bytes
|
|
25
|
-
parsedData.isFixedToken = data.slice(offset, (offset += 2)) === "01" // 1 byte
|
|
26
|
-
if (data.length === offset) {
|
|
27
|
-
return {
|
|
28
|
-
status: true,
|
|
29
|
-
data: parsedData,
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
status: false,
|
|
35
|
-
message: `invalid OP_RETURN data for requestType: 'transfer or exchange'. invalid data length : ${data.length} - valid length : ${offset}`,
|
|
36
|
-
code: "INVALID_OP_RETURN",
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function parseLendAndBorrowRequest(data) {
|
|
41
|
-
let parsedData = {}
|
|
42
|
-
parsedData.requestType = "lend"
|
|
43
|
-
|
|
44
|
-
let offset = 0
|
|
45
|
-
parsedData.chainId = Number(`0x${data.slice(offset, (offset += 2))}`) // 1 bytes
|
|
46
|
-
parsedData.appId = Number(`0x${data.slice(offset, (offset += 4))}`) // 2 bytes
|
|
47
|
-
parsedData.recipientAddress = `0x${data.slice(offset, (offset += 40))}` // 20 bytes
|
|
48
|
-
parsedData.percentageFee = Number(`0x${data.slice(offset, (offset += 4))}`) / 100 // 2 bytes
|
|
49
|
-
parsedData.mode = Number(`0x${data.slice(offset, (offset += 2))}`) // 1 byte
|
|
50
|
-
if (data.length === offset) {
|
|
51
|
-
return {
|
|
52
|
-
status: true,
|
|
53
|
-
data: parsedData,
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
parsedData.requestType = "borrow"
|
|
57
|
-
parsedData.tokenAddress = `0x${data.slice(offset, (offset += 40))}` // 20 bytes
|
|
58
|
-
parsedData.borrowAmount = Number(`0x${data.slice(offset, (offset += 56))}`) // 28 bytes
|
|
59
|
-
if (data.length === offset) {
|
|
60
|
-
return {
|
|
61
|
-
status: true,
|
|
62
|
-
data: parsedData,
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
status: false,
|
|
67
|
-
message: `invalid OP_RETURN data for requestType: 'lend or borrow'. invalid data length : ${data.length} - valid length : ${offset}`,
|
|
68
|
-
code: "INVALID_OP_RETURN",
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function parseRawRequest(opReturnData) {
|
|
73
|
-
let data = opReturnData.slice(2, 4) === "4c" ? opReturnData.slice(6) : opReturnData.slice(4)
|
|
74
|
-
|
|
75
|
-
// eslint-disable-next-line no-unused-vars
|
|
76
|
-
let _chainId = Number(`0x${data.slice(0, 2)}`) // 1 bytes
|
|
77
|
-
let appIdHex = data.slice(2, 6) // 2 bytes
|
|
78
|
-
if (!appIdHex) {
|
|
79
|
-
return {
|
|
80
|
-
status: false,
|
|
81
|
-
message: `invalid OP_RETURN data : ${data}`,
|
|
82
|
-
code: "INVALID_APP_ID",
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
let appId = Number(`0x${appIdHex}`) // 2 bytes
|
|
87
|
-
|
|
88
|
-
// get type base on appId
|
|
89
|
-
let requestType = Object.keys(teleportRequestsType).find(
|
|
90
|
-
(key) =>
|
|
91
|
-
appId >= teleportRequestsType[key].appIdRange[0] &&
|
|
92
|
-
appId <= teleportRequestsType[key].appIdRange[1],
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
switch (requestType) {
|
|
96
|
-
case "transfer":
|
|
97
|
-
case "exchange":
|
|
98
|
-
return parseTeleportAndExchangeRequest(data)
|
|
99
|
-
case "lend":
|
|
100
|
-
return parseLendAndBorrowRequest(data)
|
|
101
|
-
default:
|
|
102
|
-
return {
|
|
103
|
-
status: false,
|
|
104
|
-
message: `invalid appId : ${appId}`,
|
|
105
|
-
code: "INVALID_OP_RETURN",
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function validateRequestAndValue(
|
|
111
|
-
data,
|
|
112
|
-
requestOutputIndex,
|
|
113
|
-
value,
|
|
114
|
-
valueOutputIndex,
|
|
115
|
-
{ minTeleporterFeeAmount = 0 },
|
|
116
|
-
) {
|
|
117
|
-
if (!data) {
|
|
118
|
-
return {
|
|
119
|
-
status: false,
|
|
120
|
-
message: "no data to validate. it should not happen",
|
|
121
|
-
code: "NOT_ACCEPTED_BY_TELEPORTER",
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (+data.percentageFee > 100) {
|
|
126
|
-
return {
|
|
127
|
-
status: false,
|
|
128
|
-
message: `percentageFee greater than 100 is invalid. percentageFee: ${data.percentageFee}`,
|
|
129
|
-
code: "INVALID_FEE",
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if ((data.percentageFee / 100) * +value <= minTeleporterFeeAmount) {
|
|
134
|
-
return {
|
|
135
|
-
status: false,
|
|
136
|
-
message: `fee amount is less than or equal minimum teleporter fee amount.percentageFee: ${
|
|
137
|
-
data.percentageFee
|
|
138
|
-
} - value: ${value} - feeAmount ${((data.percentageFee / 100) * +value).toFixed(
|
|
139
|
-
8,
|
|
140
|
-
)} - minimumFee: ${minTeleporterFeeAmount}`,
|
|
141
|
-
code: "NOT_ACCEPTED_BY_TELEPORTER",
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
status: true,
|
|
147
|
-
data,
|
|
148
|
-
requestOutputIndex,
|
|
149
|
-
value,
|
|
150
|
-
valueOutputIndex,
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function checkAndParseProtocolRequest(vouts, address, config = { minTeleporterFeeAmount: 0 }) {
|
|
155
|
-
let requestOutputIndex = vouts.findIndex((vout_) => vout_.script.startsWith("6a"))
|
|
156
|
-
if (requestOutputIndex >= 0) {
|
|
157
|
-
let opReturnData = vouts[requestOutputIndex]?.script || null
|
|
158
|
-
let valueOutputIndex = vouts.findIndex((vout_) => vout_.address === address)?.value || 0
|
|
159
|
-
let value = valueOutputIndex >= 0 ? vouts[valueOutputIndex].value || 0 : 0
|
|
160
|
-
let dataResponse = parseRawRequest(opReturnData)
|
|
161
|
-
if (dataResponse.status) {
|
|
162
|
-
return validateRequestAndValue(
|
|
163
|
-
dataResponse.data,
|
|
164
|
-
requestOutputIndex,
|
|
165
|
-
value,
|
|
166
|
-
valueOutputIndex,
|
|
167
|
-
config,
|
|
168
|
-
)
|
|
169
|
-
}
|
|
170
|
-
return dataResponse
|
|
171
|
-
}
|
|
172
|
-
return {
|
|
173
|
-
status: false,
|
|
174
|
-
message: "transaction outputs should contain OP_RETURN",
|
|
175
|
-
code: "NO_OP_RETURN",
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
module.exports = {
|
|
180
|
-
checkAndParseProtocolRequest,
|
|
181
|
-
}
|