@kimafinance/kima-transaction-api 1.0.25-beta.1 → 1.0.26-beta.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.
package/nodemon.json CHANGED
@@ -1,6 +1,6 @@
1
- {
2
- "watch": ["src"],
3
- "ext": ".ts,.js",
4
- "ignore": [],
5
- "exec": "ts-node ./src/index.ts"
1
+ {
2
+ "watch": ["src"],
3
+ "ext": ".ts,.js",
4
+ "ignore": [],
5
+ "exec": "ts-node ./src/index.ts"
6
6
  }
package/package.json CHANGED
@@ -1,33 +1,33 @@
1
- {
2
- "name": "@kimafinance/kima-transaction-api",
3
- "version": "1.0.25-beta.1",
4
- "description": "A wrapper around Kima's API, enabling sending and monitoring transactions (Beta version)",
5
- "repository": "https://github.com/kima-finance/kima-transaction-api",
6
- "author": "",
7
- "license": "MIT",
8
- "main": "build/index.js",
9
- "source": "src/index.ts",
10
- "engines": {
11
- "node": ">=10"
12
- },
13
- "scripts": {
14
- "test": "echo \"Error: no test specified\" && exit 1",
15
- "dev": "nodemon",
16
- "build": "rimraf ./build && tsc",
17
- "start": "npm run build && node build/index.js"
18
- },
19
- "keywords": [],
20
- "devDependencies": {
21
- "@types/node": "^18.11.9",
22
- "nodemon": "^2.0.20",
23
- "rimraf": "^3.0.2",
24
- "ts-node": "^10.9.1",
25
- "typescript": "^4.9.3"
26
- },
27
- "dependencies": {
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
- }
33
- }
1
+ {
2
+ "name": "@kimafinance/kima-transaction-api",
3
+ "version": "1.0.26-beta.1",
4
+ "description": "A wrapper around Kima's API, enabling sending and monitoring transactions (Beta version)",
5
+ "repository": "https://github.com/kima-finance/kima-transaction-api",
6
+ "author": "",
7
+ "license": "MIT",
8
+ "main": "build/index.js",
9
+ "source": "src/index.ts",
10
+ "engines": {
11
+ "node": ">=10"
12
+ },
13
+ "scripts": {
14
+ "test": "echo \"Error: no test specified\" && exit 1",
15
+ "dev": "nodemon",
16
+ "build": "rimraf ./build && tsc",
17
+ "start": "npm run build && node build/index.js"
18
+ },
19
+ "keywords": [],
20
+ "devDependencies": {
21
+ "@types/node": "^18.11.9",
22
+ "nodemon": "^2.0.20",
23
+ "rimraf": "^3.0.2",
24
+ "ts-node": "^10.9.1",
25
+ "typescript": "^4.9.3"
26
+ },
27
+ "dependencies": {
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
+ }
33
+ }
package/src/index.ts CHANGED
@@ -1,100 +1,110 @@
1
- import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
2
- import { TxClient } from "./kima/common";
3
- import { MsgRequestTransaction } from "./kima/tx";
4
-
5
- export enum SupportedNetworks {
6
- ETHEREUM = "ETH",
7
- POLYGON = "POL",
8
- AVALANCHE = "AVX",
9
- SOLANA = "SOL",
10
- FUSE = "FUS",
11
- CELO = "CEL",
12
- BSC = "BSC",
13
- ARBITRIUM = "ARB",
14
- OPTIMISM = "OPT",
15
- POLYGON_ZKEVM = "ZKE",
16
- }
17
-
18
- export enum CurrencyOptions {
19
- USDT = "USDT",
20
- USDC = "USDC",
21
- USDK = "USDK",
22
- }
23
-
24
- interface Props {
25
- originChain: SupportedNetworks;
26
- originAddress: string;
27
- targetChain: SupportedNetworks;
28
- targetAddress: string;
29
- symbol: CurrencyOptions;
30
- amount: number;
31
- fee: number;
32
- }
33
-
34
- function sleep(ms: number) {
35
- return new Promise((resolve) => setTimeout(resolve, ms));
36
- }
37
-
38
- export async function submitKimaTransaction({
39
- originChain,
40
- originAddress,
41
- targetChain,
42
- targetAddress,
43
- symbol,
44
- amount,
45
- fee,
46
- }: Props) {
47
- const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
48
- process.env.KIMA_BACKEND_MNEMONIC as string,
49
- { prefix: "kima" }
50
- );
51
- const client = await TxClient(wallet);
52
- const [firstAccount] = await wallet.getAccounts();
53
- const params: MsgRequestTransaction = {
54
- creator: firstAccount.address,
55
- originChain,
56
- originAddress,
57
- targetChain,
58
- targetAddress,
59
- symbol,
60
- amount: amount.toString(),
61
- fee: fee.toString(),
62
- htlcCreationHash: "",
63
- htlcCreationVout: 0,
64
- htlcExpirationTimestamp: "",
65
- htlcVersion: "",
66
- senderPubKey: new Uint8Array(0),
67
- };
68
-
69
- let msg = await client.msgRequestTransaction(params);
70
- const result = await client.signAndBroadcast([msg]);
71
-
72
- let txId = 1;
73
-
74
- for (const event of result.events) {
75
- if (event.type === "transaction_requested") {
76
- for (const attr of event.attributes) {
77
- if (attr.key === "txId") {
78
- txId = +attr.value;
79
- }
80
- }
81
- }
82
- }
83
-
84
- msg = await client.msgSetTxHash({
85
- creator: firstAccount.address,
86
- txId,
87
- txHash: result.transactionHash,
88
- txType: "request_transaction",
89
- });
90
-
91
- console.log(msg);
92
-
93
- let hashResult;
94
- do {
95
- hashResult = await client.signAndBroadcast([msg]);
96
- await sleep(1000);
97
- } while (hashResult.code !== 0);
98
-
99
- return result;
100
- }
1
+ import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
2
+ import { TxClient } from "./kima/common";
3
+ import { MsgRequestTransaction } from "./kima/tx";
4
+
5
+ export enum SupportedNetworks {
6
+ ETHEREUM = "ETH",
7
+ POLYGON = "POL",
8
+ AVALANCHE = "AVX",
9
+ SOLANA = "SOL",
10
+ FUSE = "FUS",
11
+ CELO = "CEL",
12
+ BSC = "BSC",
13
+ ARBITRIUM = "ARB",
14
+ OPTIMISM = "OPT",
15
+ POLYGON_ZKEVM = "ZKE",
16
+ }
17
+
18
+ export enum CurrencyOptions {
19
+ USDT = "USDT",
20
+ USDC = "USDC",
21
+ USDK = "USDK",
22
+ }
23
+
24
+ interface Props {
25
+ originChain: SupportedNetworks;
26
+ originAddress: string;
27
+ targetChain: SupportedNetworks;
28
+ targetAddress: string;
29
+ symbol: CurrencyOptions;
30
+ amount: number;
31
+ fee: number;
32
+ htlcCreationHash: string;
33
+ htlcCreationVout: number;
34
+ htlcExpirationTimestamp: string;
35
+ htlcVersion: string;
36
+ senderPubKey: Uint8Array;
37
+ }
38
+
39
+ function sleep(ms: number) {
40
+ return new Promise((resolve) => setTimeout(resolve, ms));
41
+ }
42
+
43
+ export async function submitKimaTransaction({
44
+ originChain,
45
+ originAddress,
46
+ targetChain,
47
+ targetAddress,
48
+ symbol,
49
+ amount,
50
+ fee,
51
+ htlcCreationHash,
52
+ htlcCreationVout,
53
+ htlcExpirationTimestamp,
54
+ htlcVersion,
55
+ senderPubKey,
56
+ }: Props) {
57
+ const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
58
+ process.env.KIMA_BACKEND_MNEMONIC as string,
59
+ { prefix: "kima" }
60
+ );
61
+ const client = await TxClient(wallet);
62
+ const [firstAccount] = await wallet.getAccounts();
63
+ const params: MsgRequestTransaction = {
64
+ creator: firstAccount.address,
65
+ originChain,
66
+ originAddress,
67
+ targetChain,
68
+ targetAddress,
69
+ symbol,
70
+ amount: amount.toString(),
71
+ fee: fee.toString(),
72
+ htlcCreationHash,
73
+ htlcCreationVout,
74
+ htlcExpirationTimestamp,
75
+ htlcVersion,
76
+ senderPubKey,
77
+ };
78
+
79
+ let msg = await client.msgRequestTransaction(params);
80
+ const result = await client.signAndBroadcast([msg]);
81
+
82
+ let txId = 1;
83
+
84
+ for (const event of result.events) {
85
+ if (event.type === "transaction_requested") {
86
+ for (const attr of event.attributes) {
87
+ if (attr.key === "txId") {
88
+ txId = +attr.value;
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ msg = await client.msgSetTxHash({
95
+ creator: firstAccount.address,
96
+ txId,
97
+ txHash: result.transactionHash,
98
+ txType: "request_transaction",
99
+ });
100
+
101
+ console.log(msg);
102
+
103
+ let hashResult;
104
+ do {
105
+ hashResult = await client.signAndBroadcast([msg]);
106
+ await sleep(1000);
107
+ } while (hashResult.code !== 0);
108
+
109
+ return result;
110
+ }
@@ -1,47 +1,47 @@
1
- import { SigningStargateClient, StdFee } from "@cosmjs/stargate";
2
- import dotenv from "dotenv";
3
- import { Registry, OfflineSigner, EncodeObject } from "@cosmjs/proto-signing";
4
- import { MsgRequestTransaction, MsgSetTxHash } from "./tx";
5
-
6
- dotenv.config();
7
-
8
- const defaultFee = {
9
- amount: [],
10
- gas: "4000000",
11
- };
12
-
13
- interface SignAndBroadcastOptions {
14
- fee: StdFee;
15
- memo?: string;
16
- }
17
-
18
- const types = [
19
- ["/kimablockchain.transaction.MsgRequestTransaction", MsgRequestTransaction],
20
- ["/kimablockchain.transaction.MsgSetTxHash", MsgSetTxHash],
21
- ];
22
-
23
- export const registry = new Registry(<any>types);
24
-
25
- export const TxClient = async (wallet: OfflineSigner) => {
26
- const client = await SigningStargateClient.connectWithSigner(
27
- process.env.KIMA_BACKEND_NODE_PROVIDER as string,
28
- wallet,
29
- { registry }
30
- );
31
- const { address } = (await wallet.getAccounts())[0];
32
-
33
- return {
34
- signAndBroadcast: (
35
- msgs: EncodeObject[],
36
- { fee, memo }: SignAndBroadcastOptions = { fee: defaultFee, memo: "" }
37
- ) => client.signAndBroadcast(address, msgs, fee, memo),
38
- msgRequestTransaction: (data: MsgRequestTransaction): EncodeObject => ({
39
- typeUrl: "/kimablockchain.transaction.MsgRequestTransaction",
40
- value: MsgRequestTransaction.fromPartial(data),
41
- }),
42
- msgSetTxHash: (data: MsgSetTxHash): EncodeObject => ({
43
- typeUrl: "/kimablockchain.transaction.MsgSetTxHash",
44
- value: MsgSetTxHash.fromPartial(data),
45
- }),
46
- };
47
- };
1
+ import { SigningStargateClient, StdFee } from "@cosmjs/stargate";
2
+ import dotenv from "dotenv";
3
+ import { Registry, OfflineSigner, EncodeObject } from "@cosmjs/proto-signing";
4
+ import { MsgRequestTransaction, MsgSetTxHash } from "./tx";
5
+
6
+ dotenv.config();
7
+
8
+ const defaultFee = {
9
+ amount: [],
10
+ gas: "4000000",
11
+ };
12
+
13
+ interface SignAndBroadcastOptions {
14
+ fee: StdFee;
15
+ memo?: string;
16
+ }
17
+
18
+ const types = [
19
+ ["/kimablockchain.transaction.MsgRequestTransaction", MsgRequestTransaction],
20
+ ["/kimablockchain.transaction.MsgSetTxHash", MsgSetTxHash],
21
+ ];
22
+
23
+ export const registry = new Registry(<any>types);
24
+
25
+ export const TxClient = async (wallet: OfflineSigner) => {
26
+ const client = await SigningStargateClient.connectWithSigner(
27
+ process.env.KIMA_BACKEND_NODE_PROVIDER as string,
28
+ wallet,
29
+ { registry }
30
+ );
31
+ const { address } = (await wallet.getAccounts())[0];
32
+
33
+ return {
34
+ signAndBroadcast: (
35
+ msgs: EncodeObject[],
36
+ { fee, memo }: SignAndBroadcastOptions = { fee: defaultFee, memo: "" }
37
+ ) => client.signAndBroadcast(address, msgs, fee, memo),
38
+ msgRequestTransaction: (data: MsgRequestTransaction): EncodeObject => ({
39
+ typeUrl: "/kimablockchain.transaction.MsgRequestTransaction",
40
+ value: MsgRequestTransaction.fromPartial(data),
41
+ }),
42
+ msgSetTxHash: (data: MsgSetTxHash): EncodeObject => ({
43
+ typeUrl: "/kimablockchain.transaction.MsgSetTxHash",
44
+ value: MsgSetTxHash.fromPartial(data),
45
+ }),
46
+ };
47
+ };