@kimafinance/kima-transaction-api 1.4.1 → 1.4.2

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 (82) hide show
  1. package/build/index.d.ts +50 -3
  2. package/build/index.js +121 -17
  3. package/build/kima/common.d.ts +1 -4
  4. package/build/kima/common.js +9 -12
  5. package/build/kima/tx.d.ts +674 -0
  6. package/build/kima/tx.js +2170 -0
  7. package/package.json +10 -10
  8. package/src/index.ts +206 -3
  9. package/src/kima/common.ts +12 -5
  10. package/src/kima/tx.ts +2945 -0
  11. package/build/api/htlc-lock.d.ts +0 -23
  12. package/build/api/htlc-lock.js +0 -37
  13. package/build/api/htlc-reclaim.d.ts +0 -14
  14. package/build/api/htlc-reclaim.js +0 -28
  15. package/build/api/submit.d.ts +0 -54
  16. package/build/api/submit.js +0 -94
  17. package/build/config/global-this.config.d.ts +0 -2
  18. package/build/config/global-this.config.js +0 -18
  19. package/build/config/probuff.config.d.ts +0 -2
  20. package/build/config/probuff.config.js +0 -12
  21. package/build/kima/tx/cancel.d.ts +0 -35
  22. package/build/kima/tx/cancel.js +0 -115
  23. package/build/kima/tx/drain-finalize.d.ts +0 -47
  24. package/build/kima/tx/drain-finalize.js +0 -155
  25. package/build/kima/tx/drain.d.ts +0 -50
  26. package/build/kima/tx/drain.js +0 -164
  27. package/build/kima/tx/finalize.d.ts +0 -47
  28. package/build/kima/tx/finalize.js +0 -155
  29. package/build/kima/tx/htlc-lock.d.ts +0 -42
  30. package/build/kima/tx/htlc-lock.js +0 -152
  31. package/build/kima/tx/htlc-reclaim.d.ts +0 -30
  32. package/build/kima/tx/htlc-reclaim.js +0 -105
  33. package/build/kima/tx/index.d.ts +0 -1
  34. package/build/kima/tx/index.js +0 -4
  35. package/build/kima/tx/liquidity-provision.d.ts +0 -30
  36. package/build/kima/tx/liquidity-provision.js +0 -102
  37. package/build/kima/tx/message-service.d.ts +0 -54
  38. package/build/kima/tx/message-service.js +0 -117
  39. package/build/kima/tx/provision-finalize.d.ts +0 -47
  40. package/build/kima/tx/provision-finalize.js +0 -155
  41. package/build/kima/tx/provision.d.ts +0 -70
  42. package/build/kima/tx/provision.js +0 -230
  43. package/build/kima/tx/request.d.ts +0 -63
  44. package/build/kima/tx/request.js +0 -222
  45. package/build/kima/tx/response.d.ts +0 -21
  46. package/build/kima/tx/response.js +0 -69
  47. package/build/kima/tx/rpc.d.ts +0 -0
  48. package/build/kima/tx/rpc.js +0 -1
  49. package/build/kima/tx/set-hash.d.ts +0 -42
  50. package/build/kima/tx/set-hash.js +0 -130
  51. package/build/kima/tx/set-process.d.ts +0 -37
  52. package/build/kima/tx/set-process.js +0 -121
  53. package/build/kima/tx/transfer-limit.d.ts +0 -30
  54. package/build/kima/tx/transfer-limit.js +0 -102
  55. package/build/kima/tx/withdraw.d.ts +0 -47
  56. package/build/kima/tx/withdraw.js +0 -155
  57. package/build/utils.d.ts +0 -17
  58. package/build/utils.js +0 -49
  59. package/src/api/htlc-lock.ts +0 -57
  60. package/src/api/htlc-reclaim.ts +0 -39
  61. package/src/api/submit.ts +0 -132
  62. package/src/config/global-this.config.ts +0 -20
  63. package/src/config/probuff.config.ts +0 -9
  64. package/src/kima/tx/cancel.ts +0 -147
  65. package/src/kima/tx/drain-finalize.ts +0 -191
  66. package/src/kima/tx/drain.ts +0 -201
  67. package/src/kima/tx/finalize.ts +0 -191
  68. package/src/kima/tx/htlc-lock.ts +0 -183
  69. package/src/kima/tx/htlc-reclaim.ts +0 -132
  70. package/src/kima/tx/index.ts +0 -1
  71. package/src/kima/tx/liquidity-provision.ts +0 -132
  72. package/src/kima/tx/message-service.ts +0 -278
  73. package/src/kima/tx/provision-finalize.ts +0 -191
  74. package/src/kima/tx/provision.ts +0 -279
  75. package/src/kima/tx/request.ts +0 -256
  76. package/src/kima/tx/response.ts +0 -83
  77. package/src/kima/tx/rpc.ts +0 -0
  78. package/src/kima/tx/set-hash.ts +0 -162
  79. package/src/kima/tx/set-process.ts +0 -151
  80. package/src/kima/tx/transfer-limit.ts +0 -132
  81. package/src/kima/tx/withdraw.ts +0 -191
  82. package/src/utils.ts +0 -67
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kimafinance/kima-transaction-api",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
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": "",
@@ -8,7 +8,7 @@
8
8
  "main": "build/index.js",
9
9
  "source": "src/index.ts",
10
10
  "engines": {
11
- "node": ">=20"
11
+ "node": ">=10"
12
12
  },
13
13
  "scripts": {
14
14
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -18,16 +18,16 @@
18
18
  },
19
19
  "keywords": [],
20
20
  "devDependencies": {
21
- "@types/node": "^20.17.6",
22
- "nodemon": "^3.1.7",
23
- "rimraf": "^5.0.10",
24
- "ts-node": "^10.9.2",
21
+ "@types/node": "^18.11.9",
22
+ "nodemon": "^2.0.20",
23
+ "rimraf": "^3.0.2",
24
+ "ts-node": "^10.9.1",
25
25
  "typescript": "^4.9.3"
26
26
  },
27
27
  "dependencies": {
28
- "@cosmjs/cosmwasm-stargate": "^0.32.4",
29
- "@cosmjs/proto-signing": "^0.32.4",
30
- "@cosmjs/stargate": "^0.32.4",
31
- "dotenv": "^16.4.5"
28
+ "@cosmjs/cosmwasm-stargate": "^0.31.1",
29
+ "@cosmjs/proto-signing": "^0.31.1",
30
+ "@cosmjs/stargate": "^0.31.1",
31
+ "dotenv": "^16.0.3"
32
32
  }
33
33
  }
package/src/index.ts CHANGED
@@ -1,3 +1,206 @@
1
- export * from "./api/htlc-reclaim";
2
- export * from "./api/htlc-lock";
3
- export * from "./api/submit";
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,10 +1,17 @@
1
1
  import { SigningStargateClient, StdFee } from "@cosmjs/stargate";
2
2
  import dotenv from "dotenv";
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";
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";
8
15
 
9
16
  dotenv.config();
10
17