@kimafinance/kima-transaction-api 1.4.0 → 1.4.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.
Files changed (83) hide show
  1. package/README.md +19 -5
  2. package/build/api/htlc-lock.d.ts +23 -0
  3. package/build/api/htlc-lock.js +37 -0
  4. package/build/api/htlc-reclaim.d.ts +14 -0
  5. package/build/api/htlc-reclaim.js +28 -0
  6. package/build/api/submit.d.ts +54 -0
  7. package/build/api/submit.js +94 -0
  8. package/build/config/global-this.config.d.ts +2 -0
  9. package/build/config/global-this.config.js +18 -0
  10. package/build/config/probuff.config.d.ts +2 -0
  11. package/build/config/probuff.config.js +12 -0
  12. package/build/index.d.ts +3 -50
  13. package/build/index.js +17 -121
  14. package/build/kima/common.d.ts +4 -1
  15. package/build/kima/common.js +12 -9
  16. package/build/kima/tx/cancel.d.ts +35 -0
  17. package/build/kima/tx/cancel.js +115 -0
  18. package/build/kima/tx/drain-finalize.d.ts +47 -0
  19. package/build/kima/tx/drain-finalize.js +155 -0
  20. package/build/kima/tx/drain.d.ts +50 -0
  21. package/build/kima/tx/drain.js +164 -0
  22. package/build/kima/tx/finalize.d.ts +47 -0
  23. package/build/kima/tx/finalize.js +155 -0
  24. package/build/kima/tx/htlc-lock.d.ts +42 -0
  25. package/build/kima/tx/htlc-lock.js +152 -0
  26. package/build/kima/tx/htlc-reclaim.d.ts +30 -0
  27. package/build/kima/tx/htlc-reclaim.js +105 -0
  28. package/build/kima/tx/index.d.ts +1 -0
  29. package/build/kima/tx/index.js +4 -0
  30. package/build/kima/tx/liquidity-provision.d.ts +30 -0
  31. package/build/kima/tx/liquidity-provision.js +102 -0
  32. package/build/kima/tx/message-service.d.ts +54 -0
  33. package/build/kima/tx/message-service.js +117 -0
  34. package/build/kima/tx/provision-finalize.d.ts +47 -0
  35. package/build/kima/tx/provision-finalize.js +155 -0
  36. package/build/kima/tx/provision.d.ts +70 -0
  37. package/build/kima/tx/provision.js +230 -0
  38. package/build/kima/tx/request.d.ts +63 -0
  39. package/build/kima/tx/request.js +222 -0
  40. package/build/kima/tx/response.d.ts +21 -0
  41. package/build/kima/tx/response.js +69 -0
  42. package/build/kima/tx/rpc.d.ts +0 -0
  43. package/build/kima/tx/rpc.js +1 -0
  44. package/build/kima/tx/set-hash.d.ts +42 -0
  45. package/build/kima/tx/set-hash.js +130 -0
  46. package/build/kima/tx/set-process.d.ts +37 -0
  47. package/build/kima/tx/set-process.js +121 -0
  48. package/build/kima/tx/transfer-limit.d.ts +30 -0
  49. package/build/kima/tx/transfer-limit.js +102 -0
  50. package/build/kima/tx/withdraw.d.ts +47 -0
  51. package/build/kima/tx/withdraw.js +155 -0
  52. package/build/utils.d.ts +17 -0
  53. package/build/utils.js +49 -0
  54. package/package.json +10 -10
  55. package/src/api/htlc-lock.ts +57 -0
  56. package/src/api/htlc-reclaim.ts +39 -0
  57. package/src/api/submit.ts +132 -0
  58. package/src/config/global-this.config.ts +20 -0
  59. package/src/config/probuff.config.ts +9 -0
  60. package/src/index.ts +3 -206
  61. package/src/kima/common.ts +5 -12
  62. package/src/kima/tx/cancel.ts +147 -0
  63. package/src/kima/tx/drain-finalize.ts +191 -0
  64. package/src/kima/tx/drain.ts +201 -0
  65. package/src/kima/tx/finalize.ts +191 -0
  66. package/src/kima/tx/htlc-lock.ts +183 -0
  67. package/src/kima/tx/htlc-reclaim.ts +132 -0
  68. package/src/kima/tx/index.ts +1 -0
  69. package/src/kima/tx/liquidity-provision.ts +132 -0
  70. package/src/kima/tx/message-service.ts +278 -0
  71. package/src/kima/tx/provision-finalize.ts +191 -0
  72. package/src/kima/tx/provision.ts +279 -0
  73. package/src/kima/tx/request.ts +256 -0
  74. package/src/kima/tx/response.ts +83 -0
  75. package/src/kima/tx/rpc.ts +0 -0
  76. package/src/kima/tx/set-hash.ts +162 -0
  77. package/src/kima/tx/set-process.ts +151 -0
  78. package/src/kima/tx/transfer-limit.ts +132 -0
  79. package/src/kima/tx/withdraw.ts +191 -0
  80. package/src/utils.ts +67 -0
  81. package/build/kima/tx.d.ts +0 -674
  82. package/build/kima/tx.js +0 -2170
  83. package/src/kima/tx.ts +0 -2945
@@ -0,0 +1,132 @@
1
+ import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
2
+ import { TxClient } from "../kima/common";
3
+ import { MsgRequestTransaction } from "../kima/tx/request";
4
+ import { sleep } from "../utils";
5
+
6
+ export enum SupportedNetworks {
7
+ ARBITRIUM = "ARB",
8
+ AVALANCHE = "AVX",
9
+ BSC = "BSC",
10
+ BTC = "BTC",
11
+ ETHEREUM = "ETH",
12
+ OPTIMISM = "OPT",
13
+ POLYGON = "POL",
14
+ SOLANA = "SOL",
15
+ TRON = "TRX",
16
+ }
17
+
18
+ export enum CurrencyOptions {
19
+ USDT = "USDT",
20
+ USDC = "USDC",
21
+ USDK = "USDK",
22
+ }
23
+
24
+ export interface RequestTxProps {
25
+ originChain: SupportedNetworks;
26
+ originAddress: string;
27
+ targetChain: SupportedNetworks;
28
+ targetAddress: string;
29
+ originSymbol: CurrencyOptions;
30
+ targetSymbol: CurrencyOptions;
31
+ amount: number;
32
+ fee: number;
33
+ htlcCreationHash: string;
34
+ htlcCreationVout: number;
35
+ htlcExpirationTimestamp: string;
36
+ htlcVersion: string;
37
+ senderPubKey: Uint8Array;
38
+ }
39
+
40
+ /**
41
+ * Create a Kima transfer transaction. The HTLC parameters are only required on Bitcoin, use blank strings (or zeros) for other chains.
42
+ * The approval or HTLC transaction must be completed before submitting the Kima transaction or it will fail.
43
+ *
44
+ * @export
45
+ * @async
46
+ * @param {RequestTxProps} param0
47
+ * @param {SupportedNetworks} param0.originChain - The chain the funds are being transferred from
48
+ * @param {string} param0.originAddress - The user wallet address
49
+ * @param {SupportedNetworks} param0.targetChain - The chain the funds are being transferred to
50
+ * @param {string} param0.targetAddress - The destination wallet address
51
+ * @param {CurrencyOptions} param0.originSymbol - The starting token symbol
52
+ * @param {CurrencyOptions} param0.targetSymbol - The destination token symbol
53
+ * @param {number} param0.amount - amount of tokens to be transferred
54
+ * @param {number} param0.fee - The total fees to be paid
55
+ * @param {string} param0.htlcCreationHash - (if applicable) The transaction hash of the HTLC lock
56
+ * @param {number} param0.htlcCreationVout - (if applicable) The vout of the HTLC lock
57
+ * @param {string} param0.htlcExpirationTimestamp - (if applicable) The expiration timestamp of the HTLC lock
58
+ * @param {string} param0.htlcVersion - (if applicable) The version of the HTLC lock
59
+ * @param {Uint8Array} param0.senderPubKey - (if HTLC) The creator wallet public key
60
+ * @returns {Promise<DeliverTxResponse>}
61
+ */
62
+ export async function submitKimaTransaction({
63
+ originChain,
64
+ originAddress,
65
+ targetChain,
66
+ targetAddress,
67
+ originSymbol,
68
+ targetSymbol,
69
+ amount,
70
+ fee,
71
+ htlcCreationHash,
72
+ htlcCreationVout,
73
+ htlcExpirationTimestamp,
74
+ htlcVersion,
75
+ senderPubKey,
76
+ }: RequestTxProps) {
77
+ const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
78
+ process.env.KIMA_BACKEND_MNEMONIC as string,
79
+ { prefix: "kima" }
80
+ );
81
+ const client = await TxClient(wallet);
82
+ const [firstAccount] = await wallet.getAccounts();
83
+ const params: MsgRequestTransaction = {
84
+ creator: firstAccount.address,
85
+ originChain,
86
+ originAddress,
87
+ targetChain,
88
+ targetAddress,
89
+ originSymbol,
90
+ targetSymbol,
91
+ amount: amount.toString(),
92
+ fee: fee.toString(),
93
+ htlcCreationHash,
94
+ htlcCreationVout,
95
+ htlcExpirationTimestamp,
96
+ htlcVersion,
97
+ senderPubKey,
98
+ options: "",
99
+ };
100
+
101
+ let msg = await client.msgRequestTransaction(params);
102
+ const result = await client.signAndBroadcast([msg]);
103
+
104
+ let txId = 1;
105
+
106
+ for (const event of result.events) {
107
+ if (event.type === "transaction_requested") {
108
+ for (const attr of event.attributes) {
109
+ if (attr.key === "txId") {
110
+ txId = +attr.value;
111
+ }
112
+ }
113
+ }
114
+ }
115
+
116
+ msg = await client.msgSetTxHash({
117
+ creator: firstAccount.address,
118
+ txId,
119
+ txHash: result.transactionHash,
120
+ txType: "request_transaction",
121
+ });
122
+
123
+ console.log(msg);
124
+
125
+ let hashResult;
126
+ do {
127
+ hashResult = await client.signAndBroadcast([msg]);
128
+ await sleep(1000);
129
+ } while (hashResult.code !== 0);
130
+
131
+ return result;
132
+ }
@@ -0,0 +1,20 @@
1
+ declare var self: any | undefined;
2
+ declare var window: any | undefined;
3
+ declare var global: any | undefined;
4
+ var globalThis: any = (() => {
5
+ if (typeof globalThis !== "undefined") {
6
+ return globalThis;
7
+ }
8
+ if (typeof self !== "undefined") {
9
+ return self;
10
+ }
11
+ if (typeof window !== "undefined") {
12
+ return window;
13
+ }
14
+ if (typeof global !== "undefined") {
15
+ return global;
16
+ }
17
+ throw "Unable to locate global object";
18
+ })();
19
+
20
+ export default globalThis;
@@ -0,0 +1,9 @@
1
+ import _m0 from "protobufjs/minimal";
2
+ import Long from "long";
3
+
4
+ if (_m0.util.Long !== Long) {
5
+ _m0.util.Long = Long as any;
6
+ _m0.configure();
7
+ }
8
+
9
+ export default _m0
package/src/index.ts CHANGED
@@ -1,206 +1,3 @@
1
- import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
2
- import { TxClient } from "./kima/common";
3
- import {
4
- MsgHtlcReclaim,
5
- MsgRequestHtlcLock,
6
- MsgRequestTransaction,
7
- } from "./kima/tx";
8
-
9
- export enum SupportedNetworks {
10
- ETHEREUM = "ETH",
11
- POLYGON = "POL",
12
- AVALANCHE = "AVX",
13
- SOLANA = "SOL",
14
- FUSE = "FUS",
15
- CELO = "CEL",
16
- BSC = "BSC",
17
- ARBITRIUM = "ARB",
18
- OPTIMISM = "OPT",
19
- POLYGON_ZKEVM = "ZKE",
20
- }
21
-
22
- export enum CurrencyOptions {
23
- USDT = "USDT",
24
- USDC = "USDC",
25
- USDK = "USDK",
26
- }
27
-
28
- interface RequestHtlcReclaimProps {
29
- senderAddress: string;
30
- txHash: string;
31
- }
32
-
33
- export async function HtlcReclaim({
34
- senderAddress,
35
- txHash,
36
- }: RequestHtlcReclaimProps) {
37
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
38
- process.env.KIMA_BACKEND_MNEMONIC as string,
39
- { prefix: "kima" }
40
- );
41
- const client = await TxClient(wallet);
42
- const [firstAccount] = await wallet.getAccounts();
43
- const params: MsgHtlcReclaim = {
44
- creator: firstAccount.address,
45
- senderAddress,
46
- txHash,
47
- };
48
-
49
- let msg = await client.msgHtlcReclaim(params);
50
- const result = await client.signAndBroadcast([msg]);
51
-
52
- return result;
53
- }
54
-
55
- interface RequestHtlcLockProps {
56
- fromAddress: string;
57
- senderPubkey: string;
58
- amount: string;
59
- htlcTimeout: string;
60
- txHash: string;
61
- htlcAddress: string;
62
- }
63
-
64
- export async function submitHtlcLock({
65
- fromAddress,
66
- senderPubkey,
67
- amount,
68
- htlcTimeout,
69
- txHash,
70
- htlcAddress,
71
- }: RequestHtlcLockProps) {
72
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
73
- process.env.KIMA_BACKEND_MNEMONIC as string,
74
- { prefix: "kima" }
75
- );
76
- const client = await TxClient(wallet);
77
- const [firstAccount] = await wallet.getAccounts();
78
- const params: MsgRequestHtlcLock = {
79
- creator: firstAccount.address,
80
- fromAddress,
81
- senderPubkey,
82
- amount,
83
- htlcTimeout,
84
- htlcAddress,
85
- txHash,
86
- };
87
-
88
- let msg = await client.msgRequestHtlcLock(params);
89
- const result = await client.signAndBroadcast([msg]);
90
-
91
- return result;
92
- }
93
-
94
- interface RequestTxProps {
95
- originChain: SupportedNetworks;
96
- originAddress: string;
97
- targetChain: SupportedNetworks;
98
- targetAddress: string;
99
- originSymbol: CurrencyOptions;
100
- targetSymbol: CurrencyOptions;
101
- amount: string; // number in whole units i.e. "12.34"
102
- fee: string; // number in whole units i.e "0.061234"
103
- htlcCreationHash: string;
104
- htlcCreationVout: number;
105
- htlcExpirationTimestamp: string;
106
- htlcVersion: string;
107
- senderPubKey: Uint8Array;
108
- options: string;
109
- }
110
-
111
- function sleep(ms: number) {
112
- return new Promise((resolve) => setTimeout(resolve, ms));
113
- }
114
-
115
- export async function getCreatorAddress() {
116
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
117
- process.env.KIMA_BACKEND_MNEMONIC as string,
118
- { prefix: "kima" }
119
- );
120
- const [firstAccount] = await wallet.getAccounts();
121
- return firstAccount;
122
- }
123
-
124
- export async function submitKimaTransaction({
125
- originChain,
126
- originAddress,
127
- targetChain,
128
- targetAddress,
129
- originSymbol,
130
- targetSymbol,
131
- amount,
132
- fee,
133
- htlcCreationHash,
134
- htlcCreationVout,
135
- htlcExpirationTimestamp,
136
- htlcVersion,
137
- senderPubKey,
138
- options,
139
- }: RequestTxProps) {
140
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
141
- process.env.KIMA_BACKEND_MNEMONIC as string,
142
- { prefix: "kima" }
143
- );
144
- const client = await TxClient(wallet);
145
- const [firstAccount] = await wallet.getAccounts();
146
- const params: MsgRequestTransaction = {
147
- creator: firstAccount.address,
148
- originChain,
149
- originAddress,
150
- targetChain,
151
- targetAddress,
152
- originSymbol,
153
- targetSymbol,
154
- amount: amount,
155
- fee: fee,
156
- htlcCreationHash,
157
- htlcCreationVout,
158
- htlcExpirationTimestamp,
159
- htlcVersion,
160
- senderPubKey,
161
- options,
162
- };
163
-
164
- const msgTx = await client.msgRequestTransaction(params);
165
- const result = await client.signAndBroadcast([msgTx]);
166
-
167
- if (result.code !== 0) {
168
- return result;
169
- }
170
-
171
- let txId = 1;
172
-
173
- for (const event of result.events) {
174
- if (event.type === "transaction_requested") {
175
- for (const attr of event.attributes) {
176
- if (attr.key === "txId") {
177
- txId = +attr.value;
178
- }
179
- }
180
- }
181
- }
182
-
183
- await sleep(5000);
184
-
185
- const msgSetHash = await client.msgSetTxHash({
186
- creator: firstAccount.address,
187
- txId,
188
- txHash: result.transactionHash,
189
- txType: "request_transaction",
190
- });
191
-
192
- console.log(msgSetHash);
193
-
194
- let hashResult;
195
- do {
196
- try {
197
- hashResult = await client.signAndBroadcast([msgSetHash]);
198
- } catch (error) {
199
- console.log(error);
200
- await sleep(5000);
201
- continue;
202
- }
203
- } while (hashResult?.code !== 0);
204
-
205
- return result;
206
- }
1
+ export * from "./api/htlc-reclaim";
2
+ export * from "./api/htlc-lock";
3
+ export * from "./api/submit";
@@ -1,17 +1,10 @@
1
1
  import { SigningStargateClient, StdFee } from "@cosmjs/stargate";
2
2
  import dotenv from "dotenv";
3
- import {
4
- Registry,
5
- OfflineSigner,
6
- EncodeObject,
7
- coin,
8
- } from "@cosmjs/proto-signing";
9
- import {
10
- MsgRequestHtlcLock,
11
- MsgRequestTransaction,
12
- MsgSetTxHash,
13
- MsgHtlcReclaim,
14
- } from "./tx";
3
+ import { Registry, OfflineSigner, EncodeObject, coin } from "@cosmjs/proto-signing";
4
+ import { MsgRequestTransaction } from "./tx/request";
5
+ import { MsgRequestHtlcLock } from "./tx/htlc-lock";
6
+ import { MsgSetTxHash } from "./tx/set-hash";
7
+ import { MsgHtlcReclaim } from "./tx/htlc-reclaim";
15
8
 
16
9
  dotenv.config();
17
10
 
@@ -0,0 +1,147 @@
1
+ import _m0 from "../../config/probuff.config";
2
+ import { DeepPartial, Exact, isSet } from "../../utils";
3
+
4
+ export interface MsgCancelTransaction {
5
+ creator: string;
6
+ transactionId: string;
7
+ }
8
+
9
+ export interface MsgCancelTransactionResponse {
10
+ code: string;
11
+ msg: string;
12
+ }
13
+
14
+ function createBaseMsgCancelTransaction(): MsgCancelTransaction {
15
+ return { creator: "", transactionId: "" };
16
+ }
17
+
18
+ export const MsgCancelTransaction = {
19
+ encode(
20
+ message: MsgCancelTransaction,
21
+ writer: _m0.Writer = _m0.Writer.create()
22
+ ): _m0.Writer {
23
+ if (message.creator !== "") {
24
+ writer.uint32(10).string(message.creator);
25
+ }
26
+ if (message.transactionId !== "") {
27
+ writer.uint32(18).string(message.transactionId);
28
+ }
29
+ return writer;
30
+ },
31
+
32
+ decode(
33
+ input: _m0.Reader | Uint8Array,
34
+ length?: number
35
+ ): MsgCancelTransaction {
36
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
37
+ let end = length === undefined ? reader.len : reader.pos + length;
38
+ const message = createBaseMsgCancelTransaction();
39
+ while (reader.pos < end) {
40
+ const tag = reader.uint32();
41
+ switch (tag >>> 3) {
42
+ case 1:
43
+ message.creator = reader.string();
44
+ break;
45
+ case 2:
46
+ message.transactionId = reader.string();
47
+ break;
48
+ default:
49
+ reader.skipType(tag & 7);
50
+ break;
51
+ }
52
+ }
53
+ return message;
54
+ },
55
+
56
+ fromJSON(object: any): MsgCancelTransaction {
57
+ return {
58
+ creator: isSet(object.creator) ? String(object.creator) : "",
59
+ transactionId: isSet(object.transactionId)
60
+ ? String(object.transactionId)
61
+ : "",
62
+ };
63
+ },
64
+
65
+ toJSON(message: MsgCancelTransaction): unknown {
66
+ const obj: any = {};
67
+ message.creator !== undefined && (obj.creator = message.creator);
68
+ message.transactionId !== undefined &&
69
+ (obj.transactionId = message.transactionId);
70
+ return obj;
71
+ },
72
+
73
+ fromPartial<I extends Exact<DeepPartial<MsgCancelTransaction>, I>>(
74
+ object: I
75
+ ): MsgCancelTransaction {
76
+ const message = createBaseMsgCancelTransaction();
77
+ message.creator = object.creator ?? "";
78
+ message.transactionId = object.transactionId ?? "";
79
+ return message;
80
+ },
81
+ };
82
+
83
+ function createBaseMsgCancelTransactionResponse(): MsgCancelTransactionResponse {
84
+ return { code: "", msg: "" };
85
+ }
86
+
87
+ export const MsgCancelTransactionResponse = {
88
+ encode(
89
+ message: MsgCancelTransactionResponse,
90
+ writer: _m0.Writer = _m0.Writer.create()
91
+ ): _m0.Writer {
92
+ if (message.code !== "") {
93
+ writer.uint32(10).string(message.code);
94
+ }
95
+ if (message.msg !== "") {
96
+ writer.uint32(18).string(message.msg);
97
+ }
98
+ return writer;
99
+ },
100
+
101
+ decode(
102
+ input: _m0.Reader | Uint8Array,
103
+ length?: number
104
+ ): MsgCancelTransactionResponse {
105
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
106
+ let end = length === undefined ? reader.len : reader.pos + length;
107
+ const message = createBaseMsgCancelTransactionResponse();
108
+ while (reader.pos < end) {
109
+ const tag = reader.uint32();
110
+ switch (tag >>> 3) {
111
+ case 1:
112
+ message.code = reader.string();
113
+ break;
114
+ case 2:
115
+ message.msg = reader.string();
116
+ break;
117
+ default:
118
+ reader.skipType(tag & 7);
119
+ break;
120
+ }
121
+ }
122
+ return message;
123
+ },
124
+
125
+ fromJSON(object: any): MsgCancelTransactionResponse {
126
+ return {
127
+ code: isSet(object.code) ? String(object.code) : "",
128
+ msg: isSet(object.msg) ? String(object.msg) : "",
129
+ };
130
+ },
131
+
132
+ toJSON(message: MsgCancelTransactionResponse): unknown {
133
+ const obj: any = {};
134
+ message.code !== undefined && (obj.code = message.code);
135
+ message.msg !== undefined && (obj.msg = message.msg);
136
+ return obj;
137
+ },
138
+
139
+ fromPartial<I extends Exact<DeepPartial<MsgCancelTransactionResponse>, I>>(
140
+ object: I
141
+ ): MsgCancelTransactionResponse {
142
+ const message = createBaseMsgCancelTransactionResponse();
143
+ message.code = object.code ?? "";
144
+ message.msg = object.msg ?? "";
145
+ return message;
146
+ },
147
+ };