@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/build/index.d.ts CHANGED
@@ -1,3 +1,50 @@
1
- export * from "./api/htlc-reclaim";
2
- export * from "./api/htlc-lock";
3
- export * from "./api/submit";
1
+ export declare enum SupportedNetworks {
2
+ ETHEREUM = "ETH",
3
+ POLYGON = "POL",
4
+ AVALANCHE = "AVX",
5
+ SOLANA = "SOL",
6
+ FUSE = "FUS",
7
+ CELO = "CEL",
8
+ BSC = "BSC",
9
+ ARBITRIUM = "ARB",
10
+ OPTIMISM = "OPT",
11
+ POLYGON_ZKEVM = "ZKE"
12
+ }
13
+ export declare enum CurrencyOptions {
14
+ USDT = "USDT",
15
+ USDC = "USDC",
16
+ USDK = "USDK"
17
+ }
18
+ interface RequestHtlcReclaimProps {
19
+ senderAddress: string;
20
+ txHash: string;
21
+ }
22
+ export declare function HtlcReclaim({ senderAddress, txHash, }: RequestHtlcReclaimProps): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
23
+ interface RequestHtlcLockProps {
24
+ fromAddress: string;
25
+ senderPubkey: string;
26
+ amount: string;
27
+ htlcTimeout: string;
28
+ txHash: string;
29
+ htlcAddress: string;
30
+ }
31
+ export declare function submitHtlcLock({ fromAddress, senderPubkey, amount, htlcTimeout, txHash, htlcAddress, }: RequestHtlcLockProps): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
32
+ interface RequestTxProps {
33
+ originChain: SupportedNetworks;
34
+ originAddress: string;
35
+ targetChain: SupportedNetworks;
36
+ targetAddress: string;
37
+ originSymbol: CurrencyOptions;
38
+ targetSymbol: CurrencyOptions;
39
+ amount: string;
40
+ fee: string;
41
+ htlcCreationHash: string;
42
+ htlcCreationVout: number;
43
+ htlcExpirationTimestamp: string;
44
+ htlcVersion: string;
45
+ senderPubKey: Uint8Array;
46
+ options: string;
47
+ }
48
+ export declare function getCreatorAddress(): Promise<import("@cosmjs/proto-signing").AccountData>;
49
+ export declare function submitKimaTransaction({ originChain, originAddress, targetChain, targetAddress, originSymbol, targetSymbol, amount, fee, htlcCreationHash, htlcCreationVout, htlcExpirationTimestamp, htlcVersion, senderPubKey, options, }: RequestTxProps): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
50
+ export {};
package/build/index.js CHANGED
@@ -1,19 +1,123 @@
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
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./api/htlc-reclaim"), exports);
18
- __exportStar(require("./api/htlc-lock"), exports);
19
- __exportStar(require("./api/submit"), exports);
3
+ exports.submitKimaTransaction = exports.getCreatorAddress = exports.submitHtlcLock = exports.HtlcReclaim = exports.CurrencyOptions = exports.SupportedNetworks = void 0;
4
+ const proto_signing_1 = require("@cosmjs/proto-signing");
5
+ const common_1 = require("./kima/common");
6
+ var SupportedNetworks;
7
+ (function (SupportedNetworks) {
8
+ SupportedNetworks["ETHEREUM"] = "ETH";
9
+ SupportedNetworks["POLYGON"] = "POL";
10
+ SupportedNetworks["AVALANCHE"] = "AVX";
11
+ SupportedNetworks["SOLANA"] = "SOL";
12
+ SupportedNetworks["FUSE"] = "FUS";
13
+ SupportedNetworks["CELO"] = "CEL";
14
+ SupportedNetworks["BSC"] = "BSC";
15
+ SupportedNetworks["ARBITRIUM"] = "ARB";
16
+ SupportedNetworks["OPTIMISM"] = "OPT";
17
+ SupportedNetworks["POLYGON_ZKEVM"] = "ZKE";
18
+ })(SupportedNetworks = exports.SupportedNetworks || (exports.SupportedNetworks = {}));
19
+ var CurrencyOptions;
20
+ (function (CurrencyOptions) {
21
+ CurrencyOptions["USDT"] = "USDT";
22
+ CurrencyOptions["USDC"] = "USDC";
23
+ CurrencyOptions["USDK"] = "USDK";
24
+ })(CurrencyOptions = exports.CurrencyOptions || (exports.CurrencyOptions = {}));
25
+ async function HtlcReclaim({ senderAddress, txHash, }) {
26
+ const wallet = await proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(process.env.KIMA_BACKEND_MNEMONIC, { prefix: "kima" });
27
+ const client = await (0, common_1.TxClient)(wallet);
28
+ const [firstAccount] = await wallet.getAccounts();
29
+ const params = {
30
+ creator: firstAccount.address,
31
+ senderAddress,
32
+ txHash,
33
+ };
34
+ let msg = await client.msgHtlcReclaim(params);
35
+ const result = await client.signAndBroadcast([msg]);
36
+ return result;
37
+ }
38
+ exports.HtlcReclaim = HtlcReclaim;
39
+ async function submitHtlcLock({ fromAddress, senderPubkey, amount, htlcTimeout, txHash, htlcAddress, }) {
40
+ const wallet = await proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(process.env.KIMA_BACKEND_MNEMONIC, { prefix: "kima" });
41
+ const client = await (0, common_1.TxClient)(wallet);
42
+ const [firstAccount] = await wallet.getAccounts();
43
+ const params = {
44
+ creator: firstAccount.address,
45
+ fromAddress,
46
+ senderPubkey,
47
+ amount,
48
+ htlcTimeout,
49
+ htlcAddress,
50
+ txHash,
51
+ };
52
+ let msg = await client.msgRequestHtlcLock(params);
53
+ const result = await client.signAndBroadcast([msg]);
54
+ return result;
55
+ }
56
+ exports.submitHtlcLock = submitHtlcLock;
57
+ function sleep(ms) {
58
+ return new Promise((resolve) => setTimeout(resolve, ms));
59
+ }
60
+ async function getCreatorAddress() {
61
+ const wallet = await proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(process.env.KIMA_BACKEND_MNEMONIC, { prefix: "kima" });
62
+ const [firstAccount] = await wallet.getAccounts();
63
+ return firstAccount;
64
+ }
65
+ exports.getCreatorAddress = getCreatorAddress;
66
+ async function submitKimaTransaction({ originChain, originAddress, targetChain, targetAddress, originSymbol, targetSymbol, amount, fee, htlcCreationHash, htlcCreationVout, htlcExpirationTimestamp, htlcVersion, senderPubKey, options, }) {
67
+ const wallet = await proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(process.env.KIMA_BACKEND_MNEMONIC, { prefix: "kima" });
68
+ const client = await (0, common_1.TxClient)(wallet);
69
+ const [firstAccount] = await wallet.getAccounts();
70
+ const params = {
71
+ creator: firstAccount.address,
72
+ originChain,
73
+ originAddress,
74
+ targetChain,
75
+ targetAddress,
76
+ originSymbol,
77
+ targetSymbol,
78
+ amount: amount,
79
+ fee: fee,
80
+ htlcCreationHash,
81
+ htlcCreationVout,
82
+ htlcExpirationTimestamp,
83
+ htlcVersion,
84
+ senderPubKey,
85
+ options,
86
+ };
87
+ const msgTx = await client.msgRequestTransaction(params);
88
+ const result = await client.signAndBroadcast([msgTx]);
89
+ if (result.code !== 0) {
90
+ return result;
91
+ }
92
+ let txId = 1;
93
+ for (const event of result.events) {
94
+ if (event.type === "transaction_requested") {
95
+ for (const attr of event.attributes) {
96
+ if (attr.key === "txId") {
97
+ txId = +attr.value;
98
+ }
99
+ }
100
+ }
101
+ }
102
+ await sleep(5000);
103
+ const msgSetHash = await client.msgSetTxHash({
104
+ creator: firstAccount.address,
105
+ txId,
106
+ txHash: result.transactionHash,
107
+ txType: "request_transaction",
108
+ });
109
+ console.log(msgSetHash);
110
+ let hashResult;
111
+ do {
112
+ try {
113
+ hashResult = await client.signAndBroadcast([msgSetHash]);
114
+ }
115
+ catch (error) {
116
+ console.log(error);
117
+ await sleep(5000);
118
+ continue;
119
+ }
120
+ } while (hashResult?.code !== 0);
121
+ return result;
122
+ }
123
+ exports.submitKimaTransaction = submitKimaTransaction;
@@ -1,8 +1,5 @@
1
1
  import { Registry, OfflineSigner, EncodeObject } from "@cosmjs/proto-signing";
2
- import { MsgRequestTransaction } from "./tx/request";
3
- import { MsgRequestHtlcLock } from "./tx/htlc-lock";
4
- import { MsgSetTxHash } from "./tx/set-hash";
5
- import { MsgHtlcReclaim } from "./tx/htlc-reclaim";
2
+ import { MsgRequestHtlcLock, MsgRequestTransaction, MsgSetTxHash, MsgHtlcReclaim } from "./tx";
6
3
  export declare const registry: Registry;
7
4
  export declare const TxClient: (wallet: OfflineSigner) => Promise<{
8
5
  signAndBroadcast: (msgs: EncodeObject[]) => Promise<import("@cosmjs/stargate").DeliverTxResponse>;
@@ -7,20 +7,17 @@ exports.TxClient = exports.registry = void 0;
7
7
  const stargate_1 = require("@cosmjs/stargate");
8
8
  const dotenv_1 = __importDefault(require("dotenv"));
9
9
  const proto_signing_1 = require("@cosmjs/proto-signing");
10
- const request_1 = require("./tx/request");
11
- const htlc_lock_1 = require("./tx/htlc-lock");
12
- const set_hash_1 = require("./tx/set-hash");
13
- const htlc_reclaim_1 = require("./tx/htlc-reclaim");
10
+ const tx_1 = require("./tx");
14
11
  dotenv_1.default.config();
15
12
  const defaultFee = {
16
13
  amount: [(0, proto_signing_1.coin)(200, "uKIMA")],
17
14
  gas: "200000", // Gas limit
18
15
  };
19
16
  const types = [
20
- ["/kimablockchain.transaction.MsgRequestTransaction", request_1.MsgRequestTransaction],
21
- ["/kimablockchain.transaction.MsgRequestHtlcLock", htlc_lock_1.MsgRequestHtlcLock],
22
- ["/kimablockchain.transaction.MsgSetTxHash", set_hash_1.MsgSetTxHash],
23
- ["/kimablockchain.transaction.MsgHtlcReclaim", htlc_reclaim_1.MsgHtlcReclaim],
17
+ ["/kimablockchain.transaction.MsgRequestTransaction", tx_1.MsgRequestTransaction],
18
+ ["/kimablockchain.transaction.MsgRequestHtlcLock", tx_1.MsgRequestHtlcLock],
19
+ ["/kimablockchain.transaction.MsgSetTxHash", tx_1.MsgSetTxHash],
20
+ ["/kimablockchain.transaction.MsgHtlcReclaim", tx_1.MsgHtlcReclaim],
24
21
  ];
25
22
  exports.registry = new proto_signing_1.Registry(types);
26
23
  const TxClient = async (wallet) => {
@@ -33,19 +30,19 @@ const TxClient = async (wallet) => {
33
30
  },
34
31
  msgRequestTransaction: (data) => ({
35
32
  typeUrl: "/kimablockchain.transaction.MsgRequestTransaction",
36
- value: request_1.MsgRequestTransaction.fromPartial(data),
33
+ value: tx_1.MsgRequestTransaction.fromPartial(data),
37
34
  }),
38
35
  msgRequestHtlcLock: (data) => ({
39
36
  typeUrl: "/kimablockchain.transaction.MsgRequestHtlcLock",
40
- value: htlc_lock_1.MsgRequestHtlcLock.fromPartial(data),
37
+ value: tx_1.MsgRequestHtlcLock.fromPartial(data),
41
38
  }),
42
39
  msgSetTxHash: (data) => ({
43
40
  typeUrl: "/kimablockchain.transaction.MsgSetTxHash",
44
- value: set_hash_1.MsgSetTxHash.fromPartial(data),
41
+ value: tx_1.MsgSetTxHash.fromPartial(data),
45
42
  }),
46
43
  msgHtlcReclaim: (data) => ({
47
44
  typeUrl: "/kimablockchain.transaction.MsgHtlcReclaim",
48
- value: htlc_reclaim_1.MsgHtlcReclaim.fromPartial(data),
45
+ value: tx_1.MsgHtlcReclaim.fromPartial(data),
49
46
  }),
50
47
  };
51
48
  };