@kimafinance/kima-transaction-api 1.4.2 → 1.5.5

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.
@@ -0,0 +1,68 @@
1
+ export declare enum SupportedNetworks {
2
+ ETHEREUM = "ETH",
3
+ POLYGON = "POL",
4
+ AVALANCHE = "AVX",
5
+ SOLANA = "SOL",
6
+ BSC = "BSC",
7
+ ARBITRIUM = "ARB",
8
+ OPTIMISM = "OPT",
9
+ POLYGON_ZKEVM = "ZKE",
10
+ BITCOIN = "BTC",
11
+ BERA = "BERA",
12
+ CFX = "CFX",
13
+ TRON = "TRX",
14
+ FIAT = "FIAT",
15
+ CREDITCARD = "CC",
16
+ BASE = "BASE"
17
+ }
18
+ export declare enum CurrencyOptions {
19
+ USDT = "USDT",
20
+ USDC = "USDC",
21
+ USDK = "USDK",
22
+ EURC = "EURC",
23
+ EURK = "EURK",
24
+ EUR = "EUR",
25
+ USD = "USD"
26
+ }
27
+ export interface RequestHtlcReclaimProps {
28
+ senderAddress: string;
29
+ txHash: string;
30
+ }
31
+ export interface RequestHtlcLockProps {
32
+ fromAddress: string;
33
+ senderPubkey: string;
34
+ amount: string;
35
+ htlcTimeout: string;
36
+ txHash: string;
37
+ htlcAddress: string;
38
+ }
39
+ export interface RequestTransferTxProps {
40
+ originChain: SupportedNetworks;
41
+ originAddress: string;
42
+ targetChain: SupportedNetworks;
43
+ targetAddress: string;
44
+ originSymbol: CurrencyOptions;
45
+ targetSymbol: CurrencyOptions;
46
+ amount: string;
47
+ fee: string;
48
+ htlcCreationHash?: string;
49
+ htlcCreationVout?: number;
50
+ htlcExpirationTimestamp?: string;
51
+ htlcVersion?: string;
52
+ senderPubKey?: Uint8Array;
53
+ options: string;
54
+ }
55
+ export interface RequestSwapTxProps {
56
+ originChain: SupportedNetworks;
57
+ originAddress: string;
58
+ targetChain: SupportedNetworks;
59
+ targetAddress: string;
60
+ originSymbol: CurrencyOptions;
61
+ targetSymbol: CurrencyOptions;
62
+ amountIn: string;
63
+ amountOut: string;
64
+ fee: string;
65
+ dex: string;
66
+ slippage: string;
67
+ options: string;
68
+ }
package/build/types.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CurrencyOptions = exports.SupportedNetworks = void 0;
4
+ var SupportedNetworks;
5
+ (function (SupportedNetworks) {
6
+ SupportedNetworks["ETHEREUM"] = "ETH";
7
+ SupportedNetworks["POLYGON"] = "POL";
8
+ SupportedNetworks["AVALANCHE"] = "AVX";
9
+ SupportedNetworks["SOLANA"] = "SOL";
10
+ SupportedNetworks["BSC"] = "BSC";
11
+ SupportedNetworks["ARBITRIUM"] = "ARB";
12
+ SupportedNetworks["OPTIMISM"] = "OPT";
13
+ SupportedNetworks["POLYGON_ZKEVM"] = "ZKE";
14
+ SupportedNetworks["BITCOIN"] = "BTC";
15
+ SupportedNetworks["BERA"] = "BERA";
16
+ SupportedNetworks["CFX"] = "CFX";
17
+ SupportedNetworks["TRON"] = "TRX";
18
+ SupportedNetworks["FIAT"] = "FIAT";
19
+ SupportedNetworks["CREDITCARD"] = "CC";
20
+ SupportedNetworks["BASE"] = "BASE";
21
+ })(SupportedNetworks = exports.SupportedNetworks || (exports.SupportedNetworks = {}));
22
+ var CurrencyOptions;
23
+ (function (CurrencyOptions) {
24
+ CurrencyOptions["USDT"] = "USDT";
25
+ CurrencyOptions["USDC"] = "USDC";
26
+ CurrencyOptions["USDK"] = "USDK";
27
+ CurrencyOptions["EURC"] = "EURC";
28
+ CurrencyOptions["EURK"] = "EURK";
29
+ CurrencyOptions["EUR"] = "EUR";
30
+ CurrencyOptions["USD"] = "USD";
31
+ })(CurrencyOptions = exports.CurrencyOptions || (exports.CurrencyOptions = {}));
32
+ function sleep(ms) {
33
+ return new Promise((resolve) => setTimeout(resolve, ms));
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kimafinance/kima-transaction-api",
3
- "version": "1.4.2",
3
+ "version": "1.5.5",
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
@@ -4,31 +4,18 @@ import {
4
4
  MsgHtlcReclaim,
5
5
  MsgRequestHtlcLock,
6
6
  MsgRequestTransaction,
7
- } from "./kima/tx";
7
+ } from "./kima/transfer_tx";
8
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
- }
9
+ import {
10
+ MsgRequestSwapTransaction,
11
+ } from "./kima/swap_tx";
27
12
 
28
- interface RequestHtlcReclaimProps {
29
- senderAddress: string;
30
- txHash: string;
31
- }
13
+ import {
14
+ RequestHtlcReclaimProps,
15
+ RequestHtlcLockProps,
16
+ RequestTransferTxProps,
17
+ RequestSwapTxProps,
18
+ } from "./types";
32
19
 
33
20
  export async function HtlcReclaim({
34
21
  senderAddress,
@@ -52,15 +39,6 @@ export async function HtlcReclaim({
52
39
  return result;
53
40
  }
54
41
 
55
- interface RequestHtlcLockProps {
56
- fromAddress: string;
57
- senderPubkey: string;
58
- amount: string;
59
- htlcTimeout: string;
60
- txHash: string;
61
- htlcAddress: string;
62
- }
63
-
64
42
  export async function submitHtlcLock({
65
43
  fromAddress,
66
44
  senderPubkey,
@@ -91,27 +69,6 @@ export async function submitHtlcLock({
91
69
  return result;
92
70
  }
93
71
 
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
72
  export async function getCreatorAddress() {
116
73
  const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
117
74
  process.env.KIMA_BACKEND_MNEMONIC as string,
@@ -121,7 +78,7 @@ export async function getCreatorAddress() {
121
78
  return firstAccount;
122
79
  }
123
80
 
124
- export async function submitKimaTransaction({
81
+ export async function submitKimaTransferTransaction({
125
82
  originChain,
126
83
  originAddress,
127
84
  targetChain,
@@ -131,12 +88,12 @@ export async function submitKimaTransaction({
131
88
  amount,
132
89
  fee,
133
90
  htlcCreationHash,
134
- htlcCreationVout,
91
+ htlcCreationVout = 0,
135
92
  htlcExpirationTimestamp,
136
- htlcVersion,
93
+ htlcVersion = "",
137
94
  senderPubKey,
138
95
  options,
139
- }: RequestTxProps) {
96
+ }: RequestTransferTxProps) {
140
97
  const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
141
98
  process.env.KIMA_BACKEND_MNEMONIC as string,
142
99
  { prefix: "kima" }
@@ -153,54 +110,58 @@ export async function submitKimaTransaction({
153
110
  targetSymbol,
154
111
  amount: amount,
155
112
  fee: fee,
156
- htlcCreationHash,
157
- htlcCreationVout,
158
- htlcExpirationTimestamp,
113
+ htlcCreationHash: htlcCreationHash || "",
114
+ htlcCreationVout: htlcCreationVout || 0,
115
+ htlcExpirationTimestamp: htlcExpirationTimestamp || "",
159
116
  htlcVersion,
160
- senderPubKey,
117
+ senderPubKey: senderPubKey || new Uint8Array(),
161
118
  options,
162
119
  };
163
120
 
164
121
  const msgTx = await client.msgRequestTransaction(params);
165
122
  const result = await client.signAndBroadcast([msgTx]);
166
123
 
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);
124
+ return result;
125
+ }
184
126
 
185
- const msgSetHash = await client.msgSetTxHash({
127
+ export async function submitKimaSwapTransaction({
128
+ originChain,
129
+ originAddress,
130
+ targetChain,
131
+ targetAddress,
132
+ originSymbol,
133
+ targetSymbol,
134
+ amountIn,
135
+ amountOut,
136
+ fee,
137
+ dex,
138
+ slippage,
139
+ options,
140
+ }: RequestSwapTxProps) {
141
+ const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
142
+ process.env.KIMA_BACKEND_MNEMONIC as string,
143
+ { prefix: "kima" }
144
+ );
145
+ const client = await TxClient(wallet);
146
+ const [firstAccount] = await wallet.getAccounts();
147
+ const params: MsgRequestSwapTransaction = {
186
148
  creator: firstAccount.address,
187
- txId,
188
- txHash: result.transactionHash,
189
- txType: "request_transaction",
190
- });
191
-
192
- console.log(msgSetHash);
149
+ originChain,
150
+ originAddress,
151
+ targetChain,
152
+ targetAddress,
153
+ originSymbol,
154
+ targetSymbol,
155
+ amountIn: amountIn,
156
+ amountOut: amountOut,
157
+ fee: fee,
158
+ dex: dex,
159
+ slippage: slippage,
160
+ options: options,
161
+ };
193
162
 
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);
163
+ const msgTx = await client.msgRequestSwapTransaction(params);
164
+ const result = await client.signAndBroadcast([msgTx]);
204
165
 
205
166
  return result;
206
167
  }
@@ -6,12 +6,17 @@ import {
6
6
  EncodeObject,
7
7
  coin,
8
8
  } from "@cosmjs/proto-signing";
9
+
9
10
  import {
10
11
  MsgRequestHtlcLock,
11
12
  MsgRequestTransaction,
12
13
  MsgSetTxHash,
13
14
  MsgHtlcReclaim,
14
- } from "./tx";
15
+ } from "./transfer_tx";
16
+
17
+ import {
18
+ MsgRequestSwapTransaction,
19
+ } from "./swap_tx";
15
20
 
16
21
  dotenv.config();
17
22
 
@@ -30,6 +35,7 @@ const types = [
30
35
  ["/kimablockchain.transaction.MsgRequestHtlcLock", MsgRequestHtlcLock],
31
36
  ["/kimablockchain.transaction.MsgSetTxHash", MsgSetTxHash],
32
37
  ["/kimablockchain.transaction.MsgHtlcReclaim", MsgHtlcReclaim],
38
+ ["/kimablockchain.swap.MsgRequestSwapTransaction", MsgRequestSwapTransaction],
33
39
  ];
34
40
 
35
41
  export const registry = new Registry(<any>types);
@@ -69,5 +75,9 @@ export const TxClient = async (wallet: OfflineSigner) => {
69
75
  typeUrl: "/kimablockchain.transaction.MsgHtlcReclaim",
70
76
  value: MsgHtlcReclaim.fromPartial(data),
71
77
  }),
78
+ msgRequestSwapTransaction: (data: MsgRequestSwapTransaction): EncodeObject => ({
79
+ typeUrl: "/kimablockchain.swap.MsgRequestSwapTransaction",
80
+ value: MsgRequestSwapTransaction.fromPartial(data),
81
+ }),
72
82
  };
73
83
  };