@kimafinance/kima-transaction-api 1.5.11 → 1.5.13
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/README.md +28 -12
- package/build/index.d.ts +2 -1
- package/build/index.js +21 -1
- package/build/kima/swap_tx.d.ts +20 -0
- package/build/kima/swap_tx.js +77 -1
- package/build/types.d.ts +20 -0
- package/package.json +1 -1
- package/src/index.ts +13 -1
- package/src/kima/swap_tx.ts +89 -1
- package/src/types.ts +25 -0
package/README.md
CHANGED
|
@@ -19,10 +19,25 @@ yarn add @kimafinance/kima-transaction-api
|
|
|
19
19
|
import {
|
|
20
20
|
submitKimaTransferTransaction,
|
|
21
21
|
submitKimaSwapTransaction,
|
|
22
|
-
|
|
22
|
+
SupportedNetworks,
|
|
23
23
|
CurrencyOptions,
|
|
24
|
+
SubmitOptionsPayload,
|
|
24
25
|
} from "@kimafinance/kima-transaction-api";
|
|
25
26
|
|
|
27
|
+
const transferOptions: SubmitOptionsPayload = {
|
|
28
|
+
signature: "", // approval message signature
|
|
29
|
+
feeId: "", // fee id from fee quote
|
|
30
|
+
chargeFeeAtTarget: false,
|
|
31
|
+
transactionIdSeed: "",
|
|
32
|
+
transactionIdSignature: "",
|
|
33
|
+
permit2: {
|
|
34
|
+
r: "0x...",
|
|
35
|
+
s: "0x...",
|
|
36
|
+
v: 27,
|
|
37
|
+
deadline: 1735689600,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
26
41
|
const txResult = await submitKimaTransferTransaction({
|
|
27
42
|
originAddress: "0x1234123412341234123412341234123412341234",
|
|
28
43
|
originChain: "ETH",
|
|
@@ -37,13 +52,8 @@ const txResult = await submitKimaTransferTransaction({
|
|
|
37
52
|
htlcExpirationTimestamp: "",
|
|
38
53
|
htlcVersion: "",
|
|
39
54
|
senderPubKey: "",
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
feeId: "", // required: id returned from calculated fee in fcs
|
|
43
|
-
chargeFeeAtTarget: false // required: wether to deduct fees from origin or target
|
|
44
|
-
transactionIdSeed: "", // optional: used in fiat on ramp payments
|
|
45
|
-
transactionIdSignature: "", // optional: used to validate transaction idempotency
|
|
46
|
-
}
|
|
55
|
+
// Runtime wire format stays a serialized JSON string
|
|
56
|
+
options: JSON.stringify(transferOptions),
|
|
47
57
|
});
|
|
48
58
|
|
|
49
59
|
|
|
@@ -59,10 +69,16 @@ const txResult = await submitKimaSwapTransaction({
|
|
|
59
69
|
fee: "0.3",
|
|
60
70
|
dex: "uniswap", // required to send empty strings for now
|
|
61
71
|
slippage: "0.05",
|
|
62
|
-
options: {
|
|
63
|
-
signature: "",
|
|
64
|
-
feeId: "",
|
|
65
|
-
|
|
72
|
+
options: JSON.stringify({
|
|
73
|
+
signature: "",
|
|
74
|
+
feeId: "",
|
|
75
|
+
permit2: {
|
|
76
|
+
r: "0x...",
|
|
77
|
+
s: "0x...",
|
|
78
|
+
v: 28,
|
|
79
|
+
deadline: 1735689600,
|
|
80
|
+
},
|
|
81
|
+
} satisfies SubmitOptionsPayload),
|
|
66
82
|
});
|
|
67
83
|
```
|
|
68
84
|
|
package/build/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { RequestHtlcReclaimProps, RequestHtlcLockProps, HtlcLockingTransactionResponse, QueryHtlcLockingTransactionParams, RequestTransferTxProps, RequestSwapTxProps, RequestExternalTxProps } from "./types";
|
|
2
|
+
export * from "./types";
|
|
2
3
|
export declare function getHtlcLockingTransactions({ baseUrl, limit, offset, paginationKey, }: QueryHtlcLockingTransactionParams): Promise<HtlcLockingTransactionResponse>;
|
|
3
4
|
export declare function HtlcReclaim({ senderAddress, txHash, }: RequestHtlcReclaimProps): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
4
5
|
export declare function submitHtlcLock({ fromAddress, senderPubkey, amount, htlcTimeout, txHash, htlcAddress, }: RequestHtlcLockProps): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
5
6
|
export declare function getCreatorAddress(): Promise<import("@cosmjs/proto-signing").AccountData>;
|
|
6
7
|
export declare function submitKimaTransferTransaction({ originChain, originAddress, targetChain, targetAddress, originSymbol, targetSymbol, amount, fee, htlcCreationHash, htlcCreationVout, htlcExpirationTimestamp, htlcVersion, senderPubKey, options, }: RequestTransferTxProps): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
7
|
-
export declare function submitKimaSwapTransaction({ originChain, originAddress, targetChain, targetAddress, originSymbol, targetSymbol, amountIn, amountOut, fee, dex, slippage,
|
|
8
|
+
export declare function submitKimaSwapTransaction({ originChain, originAddress, targetChain, targetAddress, originSymbol, targetSymbol, amountIn, amountOut, fee, dex, slippage, htlcExpirationTimestamp, htlcCreationHash, htlcCreationVout, htlcVersion, senderPubKey, options }: RequestSwapTxProps): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
8
9
|
export declare function submitKimaExternalTransaction({ originChain, originAddress, targetChain, targetAddress, originSymbol, targetSymbol, amount, fee, options, }: RequestExternalTxProps): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
18
|
};
|
|
@@ -9,6 +23,7 @@ const http_1 = __importDefault(require("http"));
|
|
|
9
23
|
const https_1 = __importDefault(require("https"));
|
|
10
24
|
const url_1 = require("url");
|
|
11
25
|
const common_1 = require("./kima/common");
|
|
26
|
+
__exportStar(require("./types"), exports);
|
|
12
27
|
const requestJson = async (url) => {
|
|
13
28
|
return new Promise((resolve, reject) => {
|
|
14
29
|
const parsed = new url_1.URL(url);
|
|
@@ -117,7 +132,7 @@ async function submitKimaTransferTransaction({ originChain, originAddress, targe
|
|
|
117
132
|
return result;
|
|
118
133
|
}
|
|
119
134
|
exports.submitKimaTransferTransaction = submitKimaTransferTransaction;
|
|
120
|
-
async function submitKimaSwapTransaction({ originChain, originAddress, targetChain, targetAddress, originSymbol, targetSymbol, amountIn, amountOut, fee, dex, slippage,
|
|
135
|
+
async function submitKimaSwapTransaction({ originChain, originAddress, targetChain, targetAddress, originSymbol, targetSymbol, amountIn, amountOut, fee, dex, slippage, htlcExpirationTimestamp, htlcCreationHash, htlcCreationVout, htlcVersion, senderPubKey, options }) {
|
|
121
136
|
const wallet = await proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(process.env.KIMA_BACKEND_MNEMONIC, { prefix: "kima" });
|
|
122
137
|
const client = await (0, common_1.TxClient)(wallet);
|
|
123
138
|
const [firstAccount] = await wallet.getAccounts();
|
|
@@ -134,6 +149,11 @@ async function submitKimaSwapTransaction({ originChain, originAddress, targetCha
|
|
|
134
149
|
fee: fee,
|
|
135
150
|
dex: dex,
|
|
136
151
|
slippage: slippage,
|
|
152
|
+
htlcExpirationTimestamp: htlcExpirationTimestamp || "",
|
|
153
|
+
htlcCreationHash: htlcCreationHash || "",
|
|
154
|
+
htlcCreationVout: htlcCreationVout || 0,
|
|
155
|
+
htlcVersion: htlcVersion || "",
|
|
156
|
+
senderPubKey: senderPubKey || new Uint8Array(),
|
|
137
157
|
options: options,
|
|
138
158
|
};
|
|
139
159
|
const msgTx = await client.msgRequestSwapTransaction(params);
|
package/build/kima/swap_tx.d.ts
CHANGED
|
@@ -24,6 +24,16 @@ export interface MsgRequestSwapTransaction {
|
|
|
24
24
|
dex: string;
|
|
25
25
|
/** the slippage of the swap transaction */
|
|
26
26
|
slippage: string;
|
|
27
|
+
/** the timestamp when the HTLC contract expires and the user can reclaim the funds locked there */
|
|
28
|
+
htlcExpirationTimestamp: string;
|
|
29
|
+
/** the txhash locking the funds in the HTLC */
|
|
30
|
+
htlcCreationHash: string;
|
|
31
|
+
/** the output index of the locked funds in the HTLC creation transaction */
|
|
32
|
+
htlcCreationVout: number;
|
|
33
|
+
/** a version denoting which HTLC script version is being used for the HTLC transaction */
|
|
34
|
+
htlcVersion: string;
|
|
35
|
+
/** for bitcoin transaction this is the public key of the sender */
|
|
36
|
+
senderPubKey: Uint8Array;
|
|
27
37
|
/** the options of the swap transaction */
|
|
28
38
|
options: string;
|
|
29
39
|
}
|
|
@@ -130,6 +140,11 @@ export declare const MsgRequestSwapTransaction: {
|
|
|
130
140
|
fee?: string | undefined;
|
|
131
141
|
dex?: string | undefined;
|
|
132
142
|
slippage?: string | undefined;
|
|
143
|
+
htlcExpirationTimestamp?: string | undefined;
|
|
144
|
+
htlcCreationHash?: string | undefined;
|
|
145
|
+
htlcCreationVout?: number | undefined;
|
|
146
|
+
htlcVersion?: string | undefined;
|
|
147
|
+
senderPubKey?: Uint8Array | undefined;
|
|
133
148
|
options?: string | undefined;
|
|
134
149
|
} & {
|
|
135
150
|
creator?: string | undefined;
|
|
@@ -144,6 +159,11 @@ export declare const MsgRequestSwapTransaction: {
|
|
|
144
159
|
fee?: string | undefined;
|
|
145
160
|
dex?: string | undefined;
|
|
146
161
|
slippage?: string | undefined;
|
|
162
|
+
htlcExpirationTimestamp?: string | undefined;
|
|
163
|
+
htlcCreationHash?: string | undefined;
|
|
164
|
+
htlcCreationVout?: number | undefined;
|
|
165
|
+
htlcVersion?: string | undefined;
|
|
166
|
+
senderPubKey?: Uint8Array | undefined;
|
|
147
167
|
options?: string | undefined;
|
|
148
168
|
} & { [K in Exclude<keyof I, keyof MsgRequestSwapTransaction>]: never; }>(object: I): MsgRequestSwapTransaction;
|
|
149
169
|
};
|
package/build/kima/swap_tx.js
CHANGED
|
@@ -22,6 +22,11 @@ function createBaseMsgRequestSwapTransaction() {
|
|
|
22
22
|
fee: "",
|
|
23
23
|
dex: "",
|
|
24
24
|
slippage: "",
|
|
25
|
+
htlcExpirationTimestamp: "",
|
|
26
|
+
htlcCreationHash: "",
|
|
27
|
+
htlcCreationVout: 0,
|
|
28
|
+
htlcVersion: "",
|
|
29
|
+
senderPubKey: new Uint8Array(),
|
|
25
30
|
options: "",
|
|
26
31
|
};
|
|
27
32
|
}
|
|
@@ -63,8 +68,23 @@ exports.MsgRequestSwapTransaction = {
|
|
|
63
68
|
if (message.slippage !== "") {
|
|
64
69
|
writer.uint32(98).string(message.slippage);
|
|
65
70
|
}
|
|
71
|
+
if (message.htlcExpirationTimestamp !== "") {
|
|
72
|
+
writer.uint32(106).string(message.htlcExpirationTimestamp);
|
|
73
|
+
}
|
|
74
|
+
if (message.htlcCreationHash !== "") {
|
|
75
|
+
writer.uint32(114).string(message.htlcCreationHash);
|
|
76
|
+
}
|
|
77
|
+
if (message.htlcCreationVout !== 0) {
|
|
78
|
+
writer.uint32(120).uint32(message.htlcCreationVout);
|
|
79
|
+
}
|
|
80
|
+
if (message.htlcVersion !== "") {
|
|
81
|
+
writer.uint32(130).string(message.htlcVersion);
|
|
82
|
+
}
|
|
83
|
+
if (message.senderPubKey.length !== 0) {
|
|
84
|
+
writer.uint32(138).bytes(message.senderPubKey);
|
|
85
|
+
}
|
|
66
86
|
if (message.options !== "") {
|
|
67
|
-
writer.uint32(
|
|
87
|
+
writer.uint32(146).string(message.options);
|
|
68
88
|
}
|
|
69
89
|
return writer;
|
|
70
90
|
},
|
|
@@ -112,6 +132,21 @@ exports.MsgRequestSwapTransaction = {
|
|
|
112
132
|
message.slippage = reader.string();
|
|
113
133
|
break;
|
|
114
134
|
case 13:
|
|
135
|
+
message.htlcExpirationTimestamp = reader.string();
|
|
136
|
+
break;
|
|
137
|
+
case 14:
|
|
138
|
+
message.htlcCreationHash = reader.string();
|
|
139
|
+
break;
|
|
140
|
+
case 15:
|
|
141
|
+
message.htlcCreationVout = reader.uint32();
|
|
142
|
+
break;
|
|
143
|
+
case 16:
|
|
144
|
+
message.htlcVersion = reader.string();
|
|
145
|
+
break;
|
|
146
|
+
case 17:
|
|
147
|
+
message.senderPubKey = reader.bytes();
|
|
148
|
+
break;
|
|
149
|
+
case 18:
|
|
115
150
|
message.options = reader.string();
|
|
116
151
|
break;
|
|
117
152
|
default:
|
|
@@ -135,6 +170,11 @@ exports.MsgRequestSwapTransaction = {
|
|
|
135
170
|
fee: isSet(object.fee) ? String(object.fee) : "",
|
|
136
171
|
dex: isSet(object.dex) ? String(object.dex) : "",
|
|
137
172
|
slippage: isSet(object.slippage) ? String(object.slippage) : "",
|
|
173
|
+
htlcExpirationTimestamp: isSet(object.htlcExpirationTimestamp) ? String(object.htlcExpirationTimestamp) : "",
|
|
174
|
+
htlcCreationHash: isSet(object.htlcCreationHash) ? String(object.htlcCreationHash) : "",
|
|
175
|
+
htlcCreationVout: isSet(object.htlcCreationVout) ? Number(object.htlcCreationVout) : 0,
|
|
176
|
+
htlcVersion: isSet(object.htlcVersion) ? String(object.htlcVersion) : "",
|
|
177
|
+
senderPubKey: isSet(object.senderPubKey) ? bytesFromBase64(object.senderPubKey) : new Uint8Array(),
|
|
138
178
|
options: isSet(object.options) ? String(object.options) : "",
|
|
139
179
|
};
|
|
140
180
|
},
|
|
@@ -152,6 +192,12 @@ exports.MsgRequestSwapTransaction = {
|
|
|
152
192
|
message.fee !== undefined && (obj.fee = message.fee);
|
|
153
193
|
message.dex !== undefined && (obj.dex = message.dex);
|
|
154
194
|
message.slippage !== undefined && (obj.slippage = message.slippage);
|
|
195
|
+
message.htlcExpirationTimestamp !== undefined && (obj.htlcExpirationTimestamp = message.htlcExpirationTimestamp);
|
|
196
|
+
message.htlcCreationHash !== undefined && (obj.htlcCreationHash = message.htlcCreationHash);
|
|
197
|
+
message.htlcCreationVout !== undefined && (obj.htlcCreationVout = Math.round(message.htlcCreationVout));
|
|
198
|
+
message.htlcVersion !== undefined && (obj.htlcVersion = message.htlcVersion);
|
|
199
|
+
message.senderPubKey !== undefined
|
|
200
|
+
&& (obj.senderPubKey = base64FromBytes(message.senderPubKey !== undefined ? message.senderPubKey : new Uint8Array()));
|
|
155
201
|
message.options !== undefined && (obj.options = message.options);
|
|
156
202
|
return obj;
|
|
157
203
|
},
|
|
@@ -169,6 +215,11 @@ exports.MsgRequestSwapTransaction = {
|
|
|
169
215
|
message.fee = object.fee ?? "";
|
|
170
216
|
message.dex = object.dex ?? "";
|
|
171
217
|
message.slippage = object.slippage ?? "";
|
|
218
|
+
message.htlcExpirationTimestamp = object.htlcExpirationTimestamp ?? "";
|
|
219
|
+
message.htlcCreationHash = object.htlcCreationHash ?? "";
|
|
220
|
+
message.htlcCreationVout = object.htlcCreationVout ?? 0;
|
|
221
|
+
message.htlcVersion = object.htlcVersion ?? "";
|
|
222
|
+
message.senderPubKey = object.senderPubKey ?? new Uint8Array();
|
|
172
223
|
message.options = object.options ?? "";
|
|
173
224
|
return message;
|
|
174
225
|
},
|
|
@@ -1094,6 +1145,31 @@ var globalThis = (() => {
|
|
|
1094
1145
|
}
|
|
1095
1146
|
throw "Unable to locate global object";
|
|
1096
1147
|
})();
|
|
1148
|
+
function bytesFromBase64(b64) {
|
|
1149
|
+
if (globalThis.Buffer) {
|
|
1150
|
+
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
|
|
1151
|
+
}
|
|
1152
|
+
else {
|
|
1153
|
+
const bin = globalThis.atob(b64);
|
|
1154
|
+
const arr = new Uint8Array(bin.length);
|
|
1155
|
+
for (let i = 0; i < bin.length; ++i) {
|
|
1156
|
+
arr[i] = bin.charCodeAt(i);
|
|
1157
|
+
}
|
|
1158
|
+
return arr;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
function base64FromBytes(arr) {
|
|
1162
|
+
if (globalThis.Buffer) {
|
|
1163
|
+
return globalThis.Buffer.from(arr).toString("base64");
|
|
1164
|
+
}
|
|
1165
|
+
else {
|
|
1166
|
+
const bin = [];
|
|
1167
|
+
arr.forEach((byte) => {
|
|
1168
|
+
bin.push(String.fromCharCode(byte));
|
|
1169
|
+
});
|
|
1170
|
+
return globalThis.btoa(bin.join(""));
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1097
1173
|
function longToNumber(long) {
|
|
1098
1174
|
if (long.gt(Number.MAX_SAFE_INTEGER)) {
|
|
1099
1175
|
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
|
package/build/types.d.ts
CHANGED
|
@@ -25,6 +25,21 @@ export declare enum CurrencyOptions {
|
|
|
25
25
|
EUR = "EUR",
|
|
26
26
|
USD = "USD"
|
|
27
27
|
}
|
|
28
|
+
export interface Permit2SubmitOptions {
|
|
29
|
+
r: string;
|
|
30
|
+
s: string;
|
|
31
|
+
v: number;
|
|
32
|
+
deadline: number;
|
|
33
|
+
}
|
|
34
|
+
export interface SubmitOptionsPayload {
|
|
35
|
+
signature?: string;
|
|
36
|
+
feeId?: string;
|
|
37
|
+
chargeFeeAtTarget?: boolean;
|
|
38
|
+
transactionIdSeed?: string;
|
|
39
|
+
transactionIdSignature?: string;
|
|
40
|
+
permit2?: Permit2SubmitOptions;
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
}
|
|
28
43
|
export interface RequestHtlcReclaimProps {
|
|
29
44
|
senderAddress: string;
|
|
30
45
|
txHash: string;
|
|
@@ -65,6 +80,11 @@ export interface RequestSwapTxProps {
|
|
|
65
80
|
fee: string;
|
|
66
81
|
dex: string;
|
|
67
82
|
slippage: string;
|
|
83
|
+
htlcExpirationTimestamp?: string;
|
|
84
|
+
htlcCreationHash?: string;
|
|
85
|
+
htlcCreationVout?: number;
|
|
86
|
+
htlcVersion?: string;
|
|
87
|
+
senderPubKey?: Uint8Array;
|
|
68
88
|
options: string;
|
|
69
89
|
}
|
|
70
90
|
export interface RequestExternalTxProps {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kimafinance/kima-transaction-api",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.13",
|
|
4
4
|
"description": "A wrapper around Kima's API, enabling sending and monitoring transactions (Beta version)",
|
|
5
5
|
"repository": "https://github.com/kima-finance/kima-transaction-api",
|
|
6
6
|
"author": "",
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,8 @@ import {
|
|
|
24
24
|
RequestExternalTxProps,
|
|
25
25
|
} from "./types";
|
|
26
26
|
|
|
27
|
+
export * from "./types";
|
|
28
|
+
|
|
27
29
|
const requestJson = async <T>(url: string): Promise<T> => {
|
|
28
30
|
return new Promise((resolve, reject) => {
|
|
29
31
|
const parsed = new URL(url);
|
|
@@ -192,7 +194,12 @@ export async function submitKimaSwapTransaction({
|
|
|
192
194
|
fee,
|
|
193
195
|
dex,
|
|
194
196
|
slippage,
|
|
195
|
-
|
|
197
|
+
htlcExpirationTimestamp,
|
|
198
|
+
htlcCreationHash,
|
|
199
|
+
htlcCreationVout,
|
|
200
|
+
htlcVersion,
|
|
201
|
+
senderPubKey,
|
|
202
|
+
options
|
|
196
203
|
}: RequestSwapTxProps) {
|
|
197
204
|
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
|
|
198
205
|
process.env.KIMA_BACKEND_MNEMONIC as string,
|
|
@@ -213,6 +220,11 @@ export async function submitKimaSwapTransaction({
|
|
|
213
220
|
fee: fee,
|
|
214
221
|
dex: dex,
|
|
215
222
|
slippage: slippage,
|
|
223
|
+
htlcExpirationTimestamp: htlcExpirationTimestamp || "",
|
|
224
|
+
htlcCreationHash: htlcCreationHash || "",
|
|
225
|
+
htlcCreationVout: htlcCreationVout || 0,
|
|
226
|
+
htlcVersion: htlcVersion || "",
|
|
227
|
+
senderPubKey: senderPubKey || new Uint8Array(),
|
|
216
228
|
options: options,
|
|
217
229
|
};
|
|
218
230
|
|
package/src/kima/swap_tx.ts
CHANGED
|
@@ -28,6 +28,16 @@ export interface MsgRequestSwapTransaction {
|
|
|
28
28
|
dex: string;
|
|
29
29
|
/** the slippage of the swap transaction */
|
|
30
30
|
slippage: string;
|
|
31
|
+
/** the timestamp when the HTLC contract expires and the user can reclaim the funds locked there */
|
|
32
|
+
htlcExpirationTimestamp: string;
|
|
33
|
+
/** the txhash locking the funds in the HTLC */
|
|
34
|
+
htlcCreationHash: string;
|
|
35
|
+
/** the output index of the locked funds in the HTLC creation transaction */
|
|
36
|
+
htlcCreationVout: number;
|
|
37
|
+
/** a version denoting which HTLC script version is being used for the HTLC transaction */
|
|
38
|
+
htlcVersion: string;
|
|
39
|
+
/** for bitcoin transaction this is the public key of the sender */
|
|
40
|
+
senderPubKey: Uint8Array;
|
|
31
41
|
/** the options of the swap transaction */
|
|
32
42
|
options: string;
|
|
33
43
|
}
|
|
@@ -142,6 +152,11 @@ function createBaseMsgRequestSwapTransaction(): MsgRequestSwapTransaction {
|
|
|
142
152
|
fee: "",
|
|
143
153
|
dex: "",
|
|
144
154
|
slippage: "",
|
|
155
|
+
htlcExpirationTimestamp: "",
|
|
156
|
+
htlcCreationHash: "",
|
|
157
|
+
htlcCreationVout: 0,
|
|
158
|
+
htlcVersion: "",
|
|
159
|
+
senderPubKey: new Uint8Array(),
|
|
145
160
|
options: "",
|
|
146
161
|
};
|
|
147
162
|
}
|
|
@@ -184,8 +199,23 @@ export const MsgRequestSwapTransaction = {
|
|
|
184
199
|
if (message.slippage !== "") {
|
|
185
200
|
writer.uint32(98).string(message.slippage);
|
|
186
201
|
}
|
|
202
|
+
if (message.htlcExpirationTimestamp !== "") {
|
|
203
|
+
writer.uint32(106).string(message.htlcExpirationTimestamp);
|
|
204
|
+
}
|
|
205
|
+
if (message.htlcCreationHash !== "") {
|
|
206
|
+
writer.uint32(114).string(message.htlcCreationHash);
|
|
207
|
+
}
|
|
208
|
+
if (message.htlcCreationVout !== 0) {
|
|
209
|
+
writer.uint32(120).uint32(message.htlcCreationVout);
|
|
210
|
+
}
|
|
211
|
+
if (message.htlcVersion !== "") {
|
|
212
|
+
writer.uint32(130).string(message.htlcVersion);
|
|
213
|
+
}
|
|
214
|
+
if (message.senderPubKey.length !== 0) {
|
|
215
|
+
writer.uint32(138).bytes(message.senderPubKey);
|
|
216
|
+
}
|
|
187
217
|
if (message.options !== "") {
|
|
188
|
-
writer.uint32(
|
|
218
|
+
writer.uint32(146).string(message.options);
|
|
189
219
|
}
|
|
190
220
|
return writer;
|
|
191
221
|
},
|
|
@@ -234,6 +264,21 @@ export const MsgRequestSwapTransaction = {
|
|
|
234
264
|
message.slippage = reader.string();
|
|
235
265
|
break;
|
|
236
266
|
case 13:
|
|
267
|
+
message.htlcExpirationTimestamp = reader.string();
|
|
268
|
+
break;
|
|
269
|
+
case 14:
|
|
270
|
+
message.htlcCreationHash = reader.string();
|
|
271
|
+
break;
|
|
272
|
+
case 15:
|
|
273
|
+
message.htlcCreationVout = reader.uint32();
|
|
274
|
+
break;
|
|
275
|
+
case 16:
|
|
276
|
+
message.htlcVersion = reader.string();
|
|
277
|
+
break;
|
|
278
|
+
case 17:
|
|
279
|
+
message.senderPubKey = reader.bytes();
|
|
280
|
+
break;
|
|
281
|
+
case 18:
|
|
237
282
|
message.options = reader.string();
|
|
238
283
|
break;
|
|
239
284
|
default:
|
|
@@ -258,6 +303,11 @@ export const MsgRequestSwapTransaction = {
|
|
|
258
303
|
fee: isSet(object.fee) ? String(object.fee) : "",
|
|
259
304
|
dex: isSet(object.dex) ? String(object.dex) : "",
|
|
260
305
|
slippage: isSet(object.slippage) ? String(object.slippage) : "",
|
|
306
|
+
htlcExpirationTimestamp: isSet(object.htlcExpirationTimestamp) ? String(object.htlcExpirationTimestamp) : "",
|
|
307
|
+
htlcCreationHash: isSet(object.htlcCreationHash) ? String(object.htlcCreationHash) : "",
|
|
308
|
+
htlcCreationVout: isSet(object.htlcCreationVout) ? Number(object.htlcCreationVout) : 0,
|
|
309
|
+
htlcVersion: isSet(object.htlcVersion) ? String(object.htlcVersion) : "",
|
|
310
|
+
senderPubKey: isSet(object.senderPubKey) ? bytesFromBase64(object.senderPubKey) : new Uint8Array(),
|
|
261
311
|
options: isSet(object.options) ? String(object.options) : "",
|
|
262
312
|
};
|
|
263
313
|
},
|
|
@@ -276,6 +326,14 @@ export const MsgRequestSwapTransaction = {
|
|
|
276
326
|
message.fee !== undefined && (obj.fee = message.fee);
|
|
277
327
|
message.dex !== undefined && (obj.dex = message.dex);
|
|
278
328
|
message.slippage !== undefined && (obj.slippage = message.slippage);
|
|
329
|
+
message.htlcExpirationTimestamp !== undefined && (obj.htlcExpirationTimestamp = message.htlcExpirationTimestamp);
|
|
330
|
+
message.htlcCreationHash !== undefined && (obj.htlcCreationHash = message.htlcCreationHash);
|
|
331
|
+
message.htlcCreationVout !== undefined && (obj.htlcCreationVout = Math.round(message.htlcCreationVout));
|
|
332
|
+
message.htlcVersion !== undefined && (obj.htlcVersion = message.htlcVersion);
|
|
333
|
+
message.senderPubKey !== undefined
|
|
334
|
+
&& (obj.senderPubKey = base64FromBytes(
|
|
335
|
+
message.senderPubKey !== undefined ? message.senderPubKey : new Uint8Array(),
|
|
336
|
+
));
|
|
279
337
|
message.options !== undefined && (obj.options = message.options);
|
|
280
338
|
return obj;
|
|
281
339
|
},
|
|
@@ -294,6 +352,11 @@ export const MsgRequestSwapTransaction = {
|
|
|
294
352
|
message.fee = object.fee ?? "";
|
|
295
353
|
message.dex = object.dex ?? "";
|
|
296
354
|
message.slippage = object.slippage ?? "";
|
|
355
|
+
message.htlcExpirationTimestamp = object.htlcExpirationTimestamp ?? "";
|
|
356
|
+
message.htlcCreationHash = object.htlcCreationHash ?? "";
|
|
357
|
+
message.htlcCreationVout = object.htlcCreationVout ?? 0;
|
|
358
|
+
message.htlcVersion = object.htlcVersion ?? "";
|
|
359
|
+
message.senderPubKey = object.senderPubKey ?? new Uint8Array();
|
|
297
360
|
message.options = object.options ?? "";
|
|
298
361
|
return message;
|
|
299
362
|
},
|
|
@@ -1325,6 +1388,31 @@ var globalThis: any = (() => {
|
|
|
1325
1388
|
throw "Unable to locate global object";
|
|
1326
1389
|
})();
|
|
1327
1390
|
|
|
1391
|
+
function bytesFromBase64(b64: string): Uint8Array {
|
|
1392
|
+
if (globalThis.Buffer) {
|
|
1393
|
+
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
|
|
1394
|
+
} else {
|
|
1395
|
+
const bin = globalThis.atob(b64);
|
|
1396
|
+
const arr = new Uint8Array(bin.length);
|
|
1397
|
+
for (let i = 0; i < bin.length; ++i) {
|
|
1398
|
+
arr[i] = bin.charCodeAt(i);
|
|
1399
|
+
}
|
|
1400
|
+
return arr;
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
function base64FromBytes(arr: Uint8Array): string {
|
|
1405
|
+
if (globalThis.Buffer) {
|
|
1406
|
+
return globalThis.Buffer.from(arr).toString("base64");
|
|
1407
|
+
} else {
|
|
1408
|
+
const bin: string[] = [];
|
|
1409
|
+
arr.forEach((byte) => {
|
|
1410
|
+
bin.push(String.fromCharCode(byte));
|
|
1411
|
+
});
|
|
1412
|
+
return globalThis.btoa(bin.join(""));
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1328
1416
|
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
1329
1417
|
|
|
1330
1418
|
export type DeepPartial<T> = T extends Builtin ? T
|
package/src/types.ts
CHANGED
|
@@ -28,6 +28,23 @@ export enum CurrencyOptions {
|
|
|
28
28
|
USD = "USD",
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export interface Permit2SubmitOptions {
|
|
32
|
+
r: string;
|
|
33
|
+
s: string;
|
|
34
|
+
v: number; // 27 | 28
|
|
35
|
+
deadline: number; // unix timestamp (seconds)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface SubmitOptionsPayload {
|
|
39
|
+
signature?: string;
|
|
40
|
+
feeId?: string;
|
|
41
|
+
chargeFeeAtTarget?: boolean;
|
|
42
|
+
transactionIdSeed?: string;
|
|
43
|
+
transactionIdSignature?: string;
|
|
44
|
+
permit2?: Permit2SubmitOptions;
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
}
|
|
47
|
+
|
|
31
48
|
export interface RequestHtlcReclaimProps {
|
|
32
49
|
senderAddress: string;
|
|
33
50
|
txHash: string;
|
|
@@ -56,6 +73,7 @@ export interface RequestTransferTxProps {
|
|
|
56
73
|
htlcExpirationTimestamp?: string;
|
|
57
74
|
htlcVersion?: string;
|
|
58
75
|
senderPubKey?: Uint8Array;
|
|
76
|
+
// JSON-serialized SubmitOptionsPayload
|
|
59
77
|
options: string;
|
|
60
78
|
}
|
|
61
79
|
|
|
@@ -71,6 +89,12 @@ export interface RequestSwapTxProps {
|
|
|
71
89
|
fee: string;
|
|
72
90
|
dex: string;
|
|
73
91
|
slippage: string;
|
|
92
|
+
htlcExpirationTimestamp?: string;
|
|
93
|
+
htlcCreationHash?: string;
|
|
94
|
+
htlcCreationVout?: number;
|
|
95
|
+
htlcVersion?: string;
|
|
96
|
+
senderPubKey?: Uint8Array;
|
|
97
|
+
// JSON-serialized SubmitOptionsPayload
|
|
74
98
|
options: string;
|
|
75
99
|
}
|
|
76
100
|
|
|
@@ -83,6 +107,7 @@ export interface RequestExternalTxProps {
|
|
|
83
107
|
targetSymbol: CurrencyOptions;
|
|
84
108
|
amount: string;
|
|
85
109
|
fee: string;
|
|
110
|
+
// JSON-serialized SubmitOptionsPayload
|
|
86
111
|
options: string;
|
|
87
112
|
}
|
|
88
113
|
|