@kimafinance/kima-transaction-api 1.4.1 → 1.4.3

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 (89) hide show
  1. package/README.md +37 -3
  2. package/build/index.d.ts +6 -3
  3. package/build/index.js +91 -17
  4. package/build/kima/common.d.ts +3 -4
  5. package/build/kima/common.js +15 -12
  6. package/build/kima/swap_tx.d.ts +387 -0
  7. package/build/kima/swap_tx.js +1109 -0
  8. package/build/kima/transfer_tx.d.ts +674 -0
  9. package/build/kima/transfer_tx.js +2170 -0
  10. package/build/types.d.ts +68 -0
  11. package/build/types.js +34 -0
  12. package/package.json +10 -10
  13. package/src/index.ts +167 -3
  14. package/src/kima/common.ts +22 -5
  15. package/src/kima/swap_tx.ts +1353 -0
  16. package/src/kima/transfer_tx.ts +2945 -0
  17. package/src/types.ts +78 -0
  18. package/build/api/htlc-lock.d.ts +0 -23
  19. package/build/api/htlc-lock.js +0 -37
  20. package/build/api/htlc-reclaim.d.ts +0 -14
  21. package/build/api/htlc-reclaim.js +0 -28
  22. package/build/api/submit.d.ts +0 -54
  23. package/build/api/submit.js +0 -94
  24. package/build/config/global-this.config.d.ts +0 -2
  25. package/build/config/global-this.config.js +0 -18
  26. package/build/config/probuff.config.d.ts +0 -2
  27. package/build/config/probuff.config.js +0 -12
  28. package/build/kima/tx/cancel.d.ts +0 -35
  29. package/build/kima/tx/cancel.js +0 -115
  30. package/build/kima/tx/drain-finalize.d.ts +0 -47
  31. package/build/kima/tx/drain-finalize.js +0 -155
  32. package/build/kima/tx/drain.d.ts +0 -50
  33. package/build/kima/tx/drain.js +0 -164
  34. package/build/kima/tx/finalize.d.ts +0 -47
  35. package/build/kima/tx/finalize.js +0 -155
  36. package/build/kima/tx/htlc-lock.d.ts +0 -42
  37. package/build/kima/tx/htlc-lock.js +0 -152
  38. package/build/kima/tx/htlc-reclaim.d.ts +0 -30
  39. package/build/kima/tx/htlc-reclaim.js +0 -105
  40. package/build/kima/tx/index.d.ts +0 -1
  41. package/build/kima/tx/index.js +0 -4
  42. package/build/kima/tx/liquidity-provision.d.ts +0 -30
  43. package/build/kima/tx/liquidity-provision.js +0 -102
  44. package/build/kima/tx/message-service.d.ts +0 -54
  45. package/build/kima/tx/message-service.js +0 -117
  46. package/build/kima/tx/provision-finalize.d.ts +0 -47
  47. package/build/kima/tx/provision-finalize.js +0 -155
  48. package/build/kima/tx/provision.d.ts +0 -70
  49. package/build/kima/tx/provision.js +0 -230
  50. package/build/kima/tx/request.d.ts +0 -63
  51. package/build/kima/tx/request.js +0 -222
  52. package/build/kima/tx/response.d.ts +0 -21
  53. package/build/kima/tx/response.js +0 -69
  54. package/build/kima/tx/rpc.d.ts +0 -0
  55. package/build/kima/tx/rpc.js +0 -1
  56. package/build/kima/tx/set-hash.d.ts +0 -42
  57. package/build/kima/tx/set-hash.js +0 -130
  58. package/build/kima/tx/set-process.d.ts +0 -37
  59. package/build/kima/tx/set-process.js +0 -121
  60. package/build/kima/tx/transfer-limit.d.ts +0 -30
  61. package/build/kima/tx/transfer-limit.js +0 -102
  62. package/build/kima/tx/withdraw.d.ts +0 -47
  63. package/build/kima/tx/withdraw.js +0 -155
  64. package/build/utils.d.ts +0 -17
  65. package/build/utils.js +0 -49
  66. package/src/api/htlc-lock.ts +0 -57
  67. package/src/api/htlc-reclaim.ts +0 -39
  68. package/src/api/submit.ts +0 -132
  69. package/src/config/global-this.config.ts +0 -20
  70. package/src/config/probuff.config.ts +0 -9
  71. package/src/kima/tx/cancel.ts +0 -147
  72. package/src/kima/tx/drain-finalize.ts +0 -191
  73. package/src/kima/tx/drain.ts +0 -201
  74. package/src/kima/tx/finalize.ts +0 -191
  75. package/src/kima/tx/htlc-lock.ts +0 -183
  76. package/src/kima/tx/htlc-reclaim.ts +0 -132
  77. package/src/kima/tx/index.ts +0 -1
  78. package/src/kima/tx/liquidity-provision.ts +0 -132
  79. package/src/kima/tx/message-service.ts +0 -278
  80. package/src/kima/tx/provision-finalize.ts +0 -191
  81. package/src/kima/tx/provision.ts +0 -279
  82. package/src/kima/tx/request.ts +0 -256
  83. package/src/kima/tx/response.ts +0 -83
  84. package/src/kima/tx/rpc.ts +0 -0
  85. package/src/kima/tx/set-hash.ts +0 -162
  86. package/src/kima/tx/set-process.ts +0 -151
  87. package/src/kima/tx/transfer-limit.ts +0 -132
  88. package/src/kima/tx/withdraw.ts +0 -191
  89. package/src/utils.ts +0 -67
@@ -1,102 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MsgUpdateTransferLimitParamsResponse = exports.MsgUpdateTransferLimitParams = void 0;
7
- const probuff_config_1 = __importDefault(require("../../config/probuff.config"));
8
- const utils_1 = require("../../utils");
9
- function createBaseMsgUpdateTransferLimitParams() {
10
- return { authority: "", maxBTC: "", maxUSDT: "" };
11
- }
12
- exports.MsgUpdateTransferLimitParams = {
13
- encode(message, writer = probuff_config_1.default.Writer.create()) {
14
- if (message.authority !== "") {
15
- writer.uint32(10).string(message.authority);
16
- }
17
- if (message.maxBTC !== "") {
18
- writer.uint32(18).string(message.maxBTC);
19
- }
20
- if (message.maxUSDT !== "") {
21
- writer.uint32(26).string(message.maxUSDT);
22
- }
23
- return writer;
24
- },
25
- decode(input, length) {
26
- const reader = input instanceof probuff_config_1.default.Reader ? input : new probuff_config_1.default.Reader(input);
27
- let end = length === undefined ? reader.len : reader.pos + length;
28
- const message = createBaseMsgUpdateTransferLimitParams();
29
- while (reader.pos < end) {
30
- const tag = reader.uint32();
31
- switch (tag >>> 3) {
32
- case 1:
33
- message.authority = reader.string();
34
- break;
35
- case 2:
36
- message.maxBTC = reader.string();
37
- break;
38
- case 3:
39
- message.maxUSDT = reader.string();
40
- break;
41
- default:
42
- reader.skipType(tag & 7);
43
- break;
44
- }
45
- }
46
- return message;
47
- },
48
- fromJSON(object) {
49
- return {
50
- authority: (0, utils_1.isSet)(object.authority) ? String(object.authority) : "",
51
- maxBTC: (0, utils_1.isSet)(object.maxBTC) ? String(object.maxBTC) : "",
52
- maxUSDT: (0, utils_1.isSet)(object.maxUSDT) ? String(object.maxUSDT) : "",
53
- };
54
- },
55
- toJSON(message) {
56
- const obj = {};
57
- message.authority !== undefined && (obj.authority = message.authority);
58
- message.maxBTC !== undefined && (obj.maxBTC = message.maxBTC);
59
- message.maxUSDT !== undefined && (obj.maxUSDT = message.maxUSDT);
60
- return obj;
61
- },
62
- fromPartial(object) {
63
- const message = createBaseMsgUpdateTransferLimitParams();
64
- message.authority = object.authority ?? "";
65
- message.maxBTC = object.maxBTC ?? "";
66
- message.maxUSDT = object.maxUSDT ?? "";
67
- return message;
68
- },
69
- };
70
- function createBaseMsgUpdateTransferLimitParamsResponse() {
71
- return {};
72
- }
73
- exports.MsgUpdateTransferLimitParamsResponse = {
74
- encode(_, writer = probuff_config_1.default.Writer.create()) {
75
- return writer;
76
- },
77
- decode(input, length) {
78
- const reader = input instanceof probuff_config_1.default.Reader ? input : new probuff_config_1.default.Reader(input);
79
- let end = length === undefined ? reader.len : reader.pos + length;
80
- const message = createBaseMsgUpdateTransferLimitParamsResponse();
81
- while (reader.pos < end) {
82
- const tag = reader.uint32();
83
- switch (tag >>> 3) {
84
- default:
85
- reader.skipType(tag & 7);
86
- break;
87
- }
88
- }
89
- return message;
90
- },
91
- fromJSON(_) {
92
- return {};
93
- },
94
- toJSON(_) {
95
- const obj = {};
96
- return obj;
97
- },
98
- fromPartial(_) {
99
- const message = createBaseMsgUpdateTransferLimitParamsResponse();
100
- return message;
101
- },
102
- };
@@ -1,47 +0,0 @@
1
- import _m0 from "../../config/probuff.config";
2
- export interface MsgFinalizeWithdrawTransaction {
3
- creator: string;
4
- txId: number;
5
- txHash: string;
6
- success: boolean;
7
- signedKey: string;
8
- errReason: string;
9
- }
10
- export interface MsgFinalizeWithdrawTransactionResponse {
11
- code: string;
12
- msg: string;
13
- }
14
- export declare const MsgFinalizeWithdrawTransaction: {
15
- encode(message: MsgFinalizeWithdrawTransaction, writer?: _m0.Writer): _m0.Writer;
16
- decode(input: _m0.Reader | Uint8Array, length?: number): MsgFinalizeWithdrawTransaction;
17
- fromJSON(object: any): MsgFinalizeWithdrawTransaction;
18
- toJSON(message: MsgFinalizeWithdrawTransaction): unknown;
19
- fromPartial<I extends {
20
- creator?: string | undefined;
21
- txId?: number | undefined;
22
- txHash?: string | undefined;
23
- success?: boolean | undefined;
24
- signedKey?: string | undefined;
25
- errReason?: string | undefined;
26
- } & {
27
- creator?: string | undefined;
28
- txId?: number | undefined;
29
- txHash?: string | undefined;
30
- success?: boolean | undefined;
31
- signedKey?: string | undefined;
32
- errReason?: string | undefined;
33
- } & { [K in Exclude<keyof I, keyof MsgFinalizeWithdrawTransaction>]: never; }>(object: I): MsgFinalizeWithdrawTransaction;
34
- };
35
- export declare const MsgFinalizeWithdrawTransactionResponse: {
36
- encode(message: MsgFinalizeWithdrawTransactionResponse, writer?: _m0.Writer): _m0.Writer;
37
- decode(input: _m0.Reader | Uint8Array, length?: number): MsgFinalizeWithdrawTransactionResponse;
38
- fromJSON(object: any): MsgFinalizeWithdrawTransactionResponse;
39
- toJSON(message: MsgFinalizeWithdrawTransactionResponse): unknown;
40
- fromPartial<I extends {
41
- code?: string | undefined;
42
- msg?: string | undefined;
43
- } & {
44
- code?: string | undefined;
45
- msg?: string | undefined;
46
- } & { [K in Exclude<keyof I, keyof MsgFinalizeWithdrawTransactionResponse>]: never; }>(object: I): MsgFinalizeWithdrawTransactionResponse;
47
- };
@@ -1,155 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MsgFinalizeWithdrawTransactionResponse = exports.MsgFinalizeWithdrawTransaction = void 0;
7
- const probuff_config_1 = __importDefault(require("../../config/probuff.config"));
8
- const utils_1 = require("../../utils");
9
- function createBaseMsgFinalizeWithdrawTransaction() {
10
- return {
11
- creator: "",
12
- txId: 0,
13
- txHash: "",
14
- success: false,
15
- signedKey: "",
16
- errReason: "",
17
- };
18
- }
19
- exports.MsgFinalizeWithdrawTransaction = {
20
- encode(message, writer = probuff_config_1.default.Writer.create()) {
21
- if (message.creator !== "") {
22
- writer.uint32(10).string(message.creator);
23
- }
24
- if (message.txId !== 0) {
25
- writer.uint32(16).uint64(message.txId);
26
- }
27
- if (message.txHash !== "") {
28
- writer.uint32(26).string(message.txHash);
29
- }
30
- if (message.success === true) {
31
- writer.uint32(32).bool(message.success);
32
- }
33
- if (message.signedKey !== "") {
34
- writer.uint32(42).string(message.signedKey);
35
- }
36
- if (message.errReason !== "") {
37
- writer.uint32(50).string(message.errReason);
38
- }
39
- return writer;
40
- },
41
- decode(input, length) {
42
- const reader = input instanceof probuff_config_1.default.Reader ? input : new probuff_config_1.default.Reader(input);
43
- let end = length === undefined ? reader.len : reader.pos + length;
44
- const message = createBaseMsgFinalizeWithdrawTransaction();
45
- while (reader.pos < end) {
46
- const tag = reader.uint32();
47
- switch (tag >>> 3) {
48
- case 1:
49
- message.creator = reader.string();
50
- break;
51
- case 2:
52
- message.txId = (0, utils_1.longToNumber)(reader.uint64());
53
- break;
54
- case 3:
55
- message.txHash = reader.string();
56
- break;
57
- case 4:
58
- message.success = reader.bool();
59
- break;
60
- case 5:
61
- message.signedKey = reader.string();
62
- break;
63
- case 6:
64
- message.errReason = reader.string();
65
- break;
66
- default:
67
- reader.skipType(tag & 7);
68
- break;
69
- }
70
- }
71
- return message;
72
- },
73
- fromJSON(object) {
74
- return {
75
- creator: (0, utils_1.isSet)(object.creator) ? String(object.creator) : "",
76
- txId: (0, utils_1.isSet)(object.txId) ? Number(object.txId) : 0,
77
- txHash: (0, utils_1.isSet)(object.txHash) ? String(object.txHash) : "",
78
- success: (0, utils_1.isSet)(object.success) ? Boolean(object.success) : false,
79
- signedKey: (0, utils_1.isSet)(object.signedKey) ? String(object.signedKey) : "",
80
- errReason: (0, utils_1.isSet)(object.errReason) ? String(object.errReason) : "",
81
- };
82
- },
83
- toJSON(message) {
84
- const obj = {};
85
- message.creator !== undefined && (obj.creator = message.creator);
86
- message.txId !== undefined && (obj.txId = Math.round(message.txId));
87
- message.txHash !== undefined && (obj.txHash = message.txHash);
88
- message.success !== undefined && (obj.success = message.success);
89
- message.signedKey !== undefined && (obj.signedKey = message.signedKey);
90
- message.errReason !== undefined && (obj.errReason = message.errReason);
91
- return obj;
92
- },
93
- fromPartial(object) {
94
- const message = createBaseMsgFinalizeWithdrawTransaction();
95
- message.creator = object.creator ?? "";
96
- message.txId = object.txId ?? 0;
97
- message.txHash = object.txHash ?? "";
98
- message.success = object.success ?? false;
99
- message.signedKey = object.signedKey ?? "";
100
- message.errReason = object.errReason ?? "";
101
- return message;
102
- },
103
- };
104
- function createBaseMsgFinalizeWithdrawTransactionResponse() {
105
- return { code: "", msg: "" };
106
- }
107
- exports.MsgFinalizeWithdrawTransactionResponse = {
108
- encode(message, writer = probuff_config_1.default.Writer.create()) {
109
- if (message.code !== "") {
110
- writer.uint32(10).string(message.code);
111
- }
112
- if (message.msg !== "") {
113
- writer.uint32(18).string(message.msg);
114
- }
115
- return writer;
116
- },
117
- decode(input, length) {
118
- const reader = input instanceof probuff_config_1.default.Reader ? input : new probuff_config_1.default.Reader(input);
119
- let end = length === undefined ? reader.len : reader.pos + length;
120
- const message = createBaseMsgFinalizeWithdrawTransactionResponse();
121
- while (reader.pos < end) {
122
- const tag = reader.uint32();
123
- switch (tag >>> 3) {
124
- case 1:
125
- message.code = reader.string();
126
- break;
127
- case 2:
128
- message.msg = reader.string();
129
- break;
130
- default:
131
- reader.skipType(tag & 7);
132
- break;
133
- }
134
- }
135
- return message;
136
- },
137
- fromJSON(object) {
138
- return {
139
- code: (0, utils_1.isSet)(object.code) ? String(object.code) : "",
140
- msg: (0, utils_1.isSet)(object.msg) ? String(object.msg) : "",
141
- };
142
- },
143
- toJSON(message) {
144
- const obj = {};
145
- message.code !== undefined && (obj.code = message.code);
146
- message.msg !== undefined && (obj.msg = message.msg);
147
- return obj;
148
- },
149
- fromPartial(object) {
150
- const message = createBaseMsgFinalizeWithdrawTransactionResponse();
151
- message.code = object.code ?? "";
152
- message.msg = object.msg ?? "";
153
- return message;
154
- },
155
- };
package/build/utils.d.ts DELETED
@@ -1,17 +0,0 @@
1
- /// <reference types="long" />
2
- export declare function isSet(value: any): boolean;
3
- export declare function bytesFromBase64(b64: string): Uint8Array;
4
- export declare function base64FromBytes(arr: Uint8Array): string;
5
- export declare function sleep(ms: number): Promise<unknown>;
6
- export type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
7
- export type DeepPartial<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
8
- [K in keyof T]?: DeepPartial<T[K]>;
9
- } : Partial<T>;
10
- type KeysOfUnion<T> = T extends T ? keyof T : never;
11
- export type Exact<P, I extends P> = P extends Builtin ? P : P & {
12
- [K in keyof P]: Exact<P[K], I[K]>;
13
- } & {
14
- [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
15
- };
16
- export declare function longToNumber(long: Long): number;
17
- export {};
package/build/utils.js DELETED
@@ -1,49 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.longToNumber = exports.sleep = exports.base64FromBytes = exports.bytesFromBase64 = exports.isSet = void 0;
7
- const global_this_config_1 = __importDefault(require("./config/global-this.config"));
8
- function isSet(value) {
9
- return value !== null && value !== undefined;
10
- }
11
- exports.isSet = isSet;
12
- function bytesFromBase64(b64) {
13
- if (global_this_config_1.default.Buffer) {
14
- return Uint8Array.from(global_this_config_1.default.Buffer.from(b64, "base64"));
15
- }
16
- else {
17
- const bin = global_this_config_1.default.atob(b64);
18
- const arr = new Uint8Array(bin.length);
19
- for (let i = 0; i < bin.length; ++i) {
20
- arr[i] = bin.charCodeAt(i);
21
- }
22
- return arr;
23
- }
24
- }
25
- exports.bytesFromBase64 = bytesFromBase64;
26
- function base64FromBytes(arr) {
27
- if (global_this_config_1.default.Buffer) {
28
- return global_this_config_1.default.Buffer.from(arr).toString("base64");
29
- }
30
- else {
31
- const bin = [];
32
- arr.forEach((byte) => {
33
- bin.push(String.fromCharCode(byte));
34
- });
35
- return global_this_config_1.default.btoa(bin.join(""));
36
- }
37
- }
38
- exports.base64FromBytes = base64FromBytes;
39
- function sleep(ms) {
40
- return new Promise((resolve) => setTimeout(resolve, ms));
41
- }
42
- exports.sleep = sleep;
43
- function longToNumber(long) {
44
- if (long.gt(Number.MAX_SAFE_INTEGER)) {
45
- throw new global_this_config_1.default.Error("Value is larger than Number.MAX_SAFE_INTEGER");
46
- }
47
- return long.toNumber();
48
- }
49
- exports.longToNumber = longToNumber;
@@ -1,57 +0,0 @@
1
- import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
2
- import { TxClient } from "../kima/common";
3
- import { MsgRequestHtlcLock } from "../kima/tx/htlc-lock";
4
-
5
- export interface RequestHtlcLockProps {
6
- fromAddress: string;
7
- senderPubkey: string;
8
- amount: string;
9
- htlcTimeout: string;
10
- txHash: string;
11
- htlcAddress: string;
12
- }
13
-
14
-
15
- /**
16
- * Create an HTCL transaction
17
- *
18
- * @export
19
- * @async
20
- * @param {RequestHtlcLockProps} param0
21
- * @param {string} param0.fromAddress - The creator wallet address
22
- * @param {string} param0.senderPubkey - The creator wallet public key
23
- * @param {string} param0.amount - The total amount to be locked including fees
24
- * @param {string} param0.htlcTimeout - The time in seconds the HTLC will be valid for
25
- * @param {string} param0.txHash - The transaction hash of the HTLC lock
26
- * @param {string} param0.htlcAddress - The HTLC address
27
- * @returns {Promise<DeliverTxResponse>}
28
- */
29
- export async function submitHtlcLock({
30
- fromAddress,
31
- senderPubkey,
32
- amount,
33
- htlcTimeout,
34
- txHash,
35
- htlcAddress,
36
- }: RequestHtlcLockProps) {
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: MsgRequestHtlcLock = {
44
- creator: firstAccount.address,
45
- fromAddress,
46
- senderPubkey,
47
- amount,
48
- htlcTimeout,
49
- htlcAddress,
50
- txHash,
51
- };
52
-
53
- let msg = await client.msgRequestHtlcLock(params);
54
- const result = await client.signAndBroadcast([msg]);
55
-
56
- return result;
57
- }
@@ -1,39 +0,0 @@
1
- import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
2
- import { TxClient } from "../kima/common";
3
- import { MsgHtlcReclaim } from "../kima/tx/htlc-reclaim";
4
-
5
- export interface RequestHtlcReclaimProps {
6
- senderAddress: string;
7
- txHash: string;
8
- }
9
-
10
- /**
11
- * Cancel an HTCL lock by user taking back the funds
12
- * @export
13
- * @async
14
- * @param {RequestHtlcReclaimProps} param0
15
- * @param {string} param0.senderAddress - The creator wallet address
16
- * @param {string} param0.txHash - The transaction hash of the HTLC lock
17
- * @returns {Promise<DeliverTxResponse>}
18
- */
19
- export async function HtlcReclaim({
20
- senderAddress,
21
- txHash,
22
- }: RequestHtlcReclaimProps) {
23
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
24
- process.env.KIMA_BACKEND_MNEMONIC as string,
25
- { prefix: "kima" }
26
- );
27
- const client = await TxClient(wallet);
28
- const [firstAccount] = await wallet.getAccounts();
29
- const params: MsgHtlcReclaim = {
30
- creator: firstAccount.address,
31
- senderAddress,
32
- txHash,
33
- };
34
-
35
- let msg = await client.msgHtlcReclaim(params);
36
- const result = await client.signAndBroadcast([msg]);
37
-
38
- return result;
39
- }
package/src/api/submit.ts DELETED
@@ -1,132 +0,0 @@
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
- }
@@ -1,20 +0,0 @@
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;
@@ -1,9 +0,0 @@
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