@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.
- package/build/index.d.ts +50 -3
- package/build/index.js +121 -17
- package/build/kima/common.d.ts +1 -4
- package/build/kima/common.js +9 -12
- package/build/kima/tx.d.ts +674 -0
- package/build/kima/tx.js +2170 -0
- package/package.json +10 -10
- package/src/index.ts +206 -3
- package/src/kima/common.ts +12 -5
- package/src/kima/tx.ts +2945 -0
- package/build/api/htlc-lock.d.ts +0 -23
- package/build/api/htlc-lock.js +0 -37
- package/build/api/htlc-reclaim.d.ts +0 -14
- package/build/api/htlc-reclaim.js +0 -28
- package/build/api/submit.d.ts +0 -54
- package/build/api/submit.js +0 -94
- package/build/config/global-this.config.d.ts +0 -2
- package/build/config/global-this.config.js +0 -18
- package/build/config/probuff.config.d.ts +0 -2
- package/build/config/probuff.config.js +0 -12
- package/build/kima/tx/cancel.d.ts +0 -35
- package/build/kima/tx/cancel.js +0 -115
- package/build/kima/tx/drain-finalize.d.ts +0 -47
- package/build/kima/tx/drain-finalize.js +0 -155
- package/build/kima/tx/drain.d.ts +0 -50
- package/build/kima/tx/drain.js +0 -164
- package/build/kima/tx/finalize.d.ts +0 -47
- package/build/kima/tx/finalize.js +0 -155
- package/build/kima/tx/htlc-lock.d.ts +0 -42
- package/build/kima/tx/htlc-lock.js +0 -152
- package/build/kima/tx/htlc-reclaim.d.ts +0 -30
- package/build/kima/tx/htlc-reclaim.js +0 -105
- package/build/kima/tx/index.d.ts +0 -1
- package/build/kima/tx/index.js +0 -4
- package/build/kima/tx/liquidity-provision.d.ts +0 -30
- package/build/kima/tx/liquidity-provision.js +0 -102
- package/build/kima/tx/message-service.d.ts +0 -54
- package/build/kima/tx/message-service.js +0 -117
- package/build/kima/tx/provision-finalize.d.ts +0 -47
- package/build/kima/tx/provision-finalize.js +0 -155
- package/build/kima/tx/provision.d.ts +0 -70
- package/build/kima/tx/provision.js +0 -230
- package/build/kima/tx/request.d.ts +0 -63
- package/build/kima/tx/request.js +0 -222
- package/build/kima/tx/response.d.ts +0 -21
- package/build/kima/tx/response.js +0 -69
- package/build/kima/tx/rpc.d.ts +0 -0
- package/build/kima/tx/rpc.js +0 -1
- package/build/kima/tx/set-hash.d.ts +0 -42
- package/build/kima/tx/set-hash.js +0 -130
- package/build/kima/tx/set-process.d.ts +0 -37
- package/build/kima/tx/set-process.js +0 -121
- package/build/kima/tx/transfer-limit.d.ts +0 -30
- package/build/kima/tx/transfer-limit.js +0 -102
- package/build/kima/tx/withdraw.d.ts +0 -47
- package/build/kima/tx/withdraw.js +0 -155
- package/build/utils.d.ts +0 -17
- package/build/utils.js +0 -49
- package/src/api/htlc-lock.ts +0 -57
- package/src/api/htlc-reclaim.ts +0 -39
- package/src/api/submit.ts +0 -132
- package/src/config/global-this.config.ts +0 -20
- package/src/config/probuff.config.ts +0 -9
- package/src/kima/tx/cancel.ts +0 -147
- package/src/kima/tx/drain-finalize.ts +0 -191
- package/src/kima/tx/drain.ts +0 -201
- package/src/kima/tx/finalize.ts +0 -191
- package/src/kima/tx/htlc-lock.ts +0 -183
- package/src/kima/tx/htlc-reclaim.ts +0 -132
- package/src/kima/tx/index.ts +0 -1
- package/src/kima/tx/liquidity-provision.ts +0 -132
- package/src/kima/tx/message-service.ts +0 -278
- package/src/kima/tx/provision-finalize.ts +0 -191
- package/src/kima/tx/provision.ts +0 -279
- package/src/kima/tx/request.ts +0 -256
- package/src/kima/tx/response.ts +0 -83
- package/src/kima/tx/rpc.ts +0 -0
- package/src/kima/tx/set-hash.ts +0 -162
- package/src/kima/tx/set-process.ts +0 -151
- package/src/kima/tx/transfer-limit.ts +0 -132
- package/src/kima/tx/withdraw.ts +0 -191
- 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.
|
|
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": ">=
|
|
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": "^
|
|
22
|
-
"nodemon": "^
|
|
23
|
-
"rimraf": "^
|
|
24
|
-
"ts-node": "^10.9.
|
|
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.
|
|
29
|
-
"@cosmjs/proto-signing": "^0.
|
|
30
|
-
"@cosmjs/stargate": "^0.
|
|
31
|
-
"dotenv": "^16.
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
}
|
package/src/kima/common.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { SigningStargateClient, StdFee } from "@cosmjs/stargate";
|
|
2
2
|
import dotenv from "dotenv";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|