@kimafinance/kima-transaction-api 1.4.2 → 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.
- package/README.md +37 -3
- package/build/index.d.ts +3 -47
- package/build/index.js +30 -60
- package/build/kima/common.d.ts +3 -1
- package/build/kima/common.js +15 -9
- package/build/kima/swap_tx.d.ts +387 -0
- package/build/kima/swap_tx.js +1109 -0
- package/build/types.d.ts +68 -0
- package/build/types.js +34 -0
- package/package.json +1 -1
- package/src/index.ts +56 -95
- package/src/kima/common.ts +11 -1
- package/src/kima/swap_tx.ts +1353 -0
- package/src/types.ts +78 -0
- /package/build/kima/{tx.d.ts → transfer_tx.d.ts} +0 -0
- /package/build/kima/{tx.js → transfer_tx.js} +0 -0
- /package/src/kima/{tx.ts → transfer_tx.ts} +0 -0
package/README.md
CHANGED
|
@@ -17,12 +17,13 @@ yarn add @kimafinance/kima-transaction-api
|
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
19
|
import {
|
|
20
|
-
|
|
20
|
+
submitKimaTransferTransaction,
|
|
21
|
+
submitKimaSwapTransaction,
|
|
21
22
|
SupportNetworks,
|
|
22
23
|
CurrencyOptions,
|
|
23
24
|
} from "@kimafinance/kima-transaction-api";
|
|
24
25
|
|
|
25
|
-
const txResult = await
|
|
26
|
+
const txResult = await submitKimaTransferTransaction({
|
|
26
27
|
originAddress: "0x1234123412341234123412341234123412341234",
|
|
27
28
|
originChain: "ETH",
|
|
28
29
|
originSymbol: "USDK",
|
|
@@ -44,11 +45,30 @@ const txResult = await submitKimaTransaction({
|
|
|
44
45
|
transactionIdSignature: "", // optional: used to validate transaction idempotency
|
|
45
46
|
}
|
|
46
47
|
});
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
const txResult = await submitKimaSwapTransaction({
|
|
51
|
+
originAddress: "0x1234123412341234123412341234123412341234",
|
|
52
|
+
originChain: "ETH",
|
|
53
|
+
originSymbol: "USDK",
|
|
54
|
+
targetAddress: "0x1234123412341234123412341234123412341234",
|
|
55
|
+
targetChain: "POL",
|
|
56
|
+
targetSymbol: "USDK",
|
|
57
|
+
amountIn: "100",
|
|
58
|
+
amountOut: "100",
|
|
59
|
+
fee: "0.3",
|
|
60
|
+
dex: "uniswap", // required to send empty strings for now
|
|
61
|
+
slippage: "0.05",
|
|
62
|
+
options: {
|
|
63
|
+
signature: "", // required: generated signature from the approval message
|
|
64
|
+
feeId: "", // required: id returned from calculated fee in fcs
|
|
65
|
+
}
|
|
66
|
+
});
|
|
47
67
|
```
|
|
48
68
|
|
|
49
69
|
## Available Functions
|
|
50
70
|
|
|
51
|
-
`
|
|
71
|
+
`submitKimaTransferTransaction` : Submit a transaction to transfer liquidity from one change to another.
|
|
52
72
|
|
|
53
73
|
- `originAddress`: sending address
|
|
54
74
|
- `originChain`: sending chain
|
|
@@ -59,6 +79,20 @@ const txResult = await submitKimaTransaction({
|
|
|
59
79
|
- `amount`: amount of token to transfer
|
|
60
80
|
- `fee`: amount of token that kima consumes to pay gas fee for pulling & releasing token transactions
|
|
61
81
|
|
|
82
|
+
`submitKimaSwapTransaction` : Submit a transaction to swap token from one chain to another.
|
|
83
|
+
|
|
84
|
+
- `originAddress`: sending address
|
|
85
|
+
- `originChain`: sending chain
|
|
86
|
+
- `originSymbol`: sending token symbol
|
|
87
|
+
- `targetAddress`: receiving address
|
|
88
|
+
- `targetChain`: receiving chain
|
|
89
|
+
- `targetSymbol`: receiving token symbol
|
|
90
|
+
- `amountIn`: amount of token to swap
|
|
91
|
+
- `amountOut`: expected amount of token to receive
|
|
92
|
+
- `fee`: amount of token that kima consumes to pay gas fee for pulling & swapping token transactions
|
|
93
|
+
- `dex`: the name of the dex that user wants to interact with (optional)
|
|
94
|
+
- `slippage`: maximum acceptable slippage parameter
|
|
95
|
+
|
|
62
96
|
## Environment Variables
|
|
63
97
|
|
|
64
98
|
`KIMA_BACKEND_MNEMONIC` : Seed phrase of developer wallet. This wallet must have KIMA token to submit a transaction to kima chain.
|
package/build/index.d.ts
CHANGED
|
@@ -1,50 +1,6 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
import { RequestHtlcReclaimProps, RequestHtlcLockProps, RequestTransferTxProps, RequestSwapTxProps } from "./types";
|
|
22
2
|
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
3
|
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
4
|
export declare function getCreatorAddress(): Promise<import("@cosmjs/proto-signing").AccountData>;
|
|
49
|
-
export declare function
|
|
50
|
-
export {}
|
|
5
|
+
export declare function submitKimaTransferTransaction({ originChain, originAddress, targetChain, targetAddress, originSymbol, targetSymbol, amount, fee, htlcCreationHash, htlcCreationVout, htlcExpirationTimestamp, htlcVersion, senderPubKey, options, }: RequestTransferTxProps): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
6
|
+
export declare function submitKimaSwapTransaction({ originChain, originAddress, targetChain, targetAddress, originSymbol, targetSymbol, amountIn, amountOut, fee, dex, slippage, options, }: RequestSwapTxProps): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
package/build/index.js
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.submitKimaSwapTransaction = exports.submitKimaTransferTransaction = exports.getCreatorAddress = exports.submitHtlcLock = exports.HtlcReclaim = void 0;
|
|
4
4
|
const proto_signing_1 = require("@cosmjs/proto-signing");
|
|
5
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
6
|
async function HtlcReclaim({ senderAddress, txHash, }) {
|
|
26
7
|
const wallet = await proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(process.env.KIMA_BACKEND_MNEMONIC, { prefix: "kima" });
|
|
27
8
|
const client = await (0, common_1.TxClient)(wallet);
|
|
@@ -54,16 +35,13 @@ async function submitHtlcLock({ fromAddress, senderPubkey, amount, htlcTimeout,
|
|
|
54
35
|
return result;
|
|
55
36
|
}
|
|
56
37
|
exports.submitHtlcLock = submitHtlcLock;
|
|
57
|
-
function sleep(ms) {
|
|
58
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
59
|
-
}
|
|
60
38
|
async function getCreatorAddress() {
|
|
61
39
|
const wallet = await proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(process.env.KIMA_BACKEND_MNEMONIC, { prefix: "kima" });
|
|
62
40
|
const [firstAccount] = await wallet.getAccounts();
|
|
63
41
|
return firstAccount;
|
|
64
42
|
}
|
|
65
43
|
exports.getCreatorAddress = getCreatorAddress;
|
|
66
|
-
async function
|
|
44
|
+
async function submitKimaTransferTransaction({ originChain, originAddress, targetChain, targetAddress, originSymbol, targetSymbol, amount, fee, htlcCreationHash, htlcCreationVout = 0, htlcExpirationTimestamp, htlcVersion = "", senderPubKey, options, }) {
|
|
67
45
|
const wallet = await proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(process.env.KIMA_BACKEND_MNEMONIC, { prefix: "kima" });
|
|
68
46
|
const client = await (0, common_1.TxClient)(wallet);
|
|
69
47
|
const [firstAccount] = await wallet.getAccounts();
|
|
@@ -77,47 +55,39 @@ async function submitKimaTransaction({ originChain, originAddress, targetChain,
|
|
|
77
55
|
targetSymbol,
|
|
78
56
|
amount: amount,
|
|
79
57
|
fee: fee,
|
|
80
|
-
htlcCreationHash,
|
|
81
|
-
htlcCreationVout,
|
|
82
|
-
htlcExpirationTimestamp,
|
|
58
|
+
htlcCreationHash: htlcCreationHash || "",
|
|
59
|
+
htlcCreationVout: htlcCreationVout || 0,
|
|
60
|
+
htlcExpirationTimestamp: htlcExpirationTimestamp || "",
|
|
83
61
|
htlcVersion,
|
|
84
|
-
senderPubKey,
|
|
62
|
+
senderPubKey: senderPubKey || new Uint8Array(),
|
|
85
63
|
options,
|
|
86
64
|
};
|
|
87
65
|
const msgTx = await client.msgRequestTransaction(params);
|
|
88
66
|
const result = await client.signAndBroadcast([msgTx]);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
txId = +attr.value;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
await sleep(5000);
|
|
103
|
-
const msgSetHash = await client.msgSetTxHash({
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
exports.submitKimaTransferTransaction = submitKimaTransferTransaction;
|
|
70
|
+
async function submitKimaSwapTransaction({ originChain, originAddress, targetChain, targetAddress, originSymbol, targetSymbol, amountIn, amountOut, fee, dex, slippage, options, }) {
|
|
71
|
+
const wallet = await proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(process.env.KIMA_BACKEND_MNEMONIC, { prefix: "kima" });
|
|
72
|
+
const client = await (0, common_1.TxClient)(wallet);
|
|
73
|
+
const [firstAccount] = await wallet.getAccounts();
|
|
74
|
+
const params = {
|
|
104
75
|
creator: firstAccount.address,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
} while (hashResult?.code !== 0);
|
|
76
|
+
originChain,
|
|
77
|
+
originAddress,
|
|
78
|
+
targetChain,
|
|
79
|
+
targetAddress,
|
|
80
|
+
originSymbol,
|
|
81
|
+
targetSymbol,
|
|
82
|
+
amountIn: amountIn,
|
|
83
|
+
amountOut: amountOut,
|
|
84
|
+
fee: fee,
|
|
85
|
+
dex: dex,
|
|
86
|
+
slippage: slippage,
|
|
87
|
+
options: options,
|
|
88
|
+
};
|
|
89
|
+
const msgTx = await client.msgRequestSwapTransaction(params);
|
|
90
|
+
const result = await client.signAndBroadcast([msgTx]);
|
|
121
91
|
return result;
|
|
122
92
|
}
|
|
123
|
-
exports.
|
|
93
|
+
exports.submitKimaSwapTransaction = submitKimaSwapTransaction;
|
package/build/kima/common.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Registry, OfflineSigner, EncodeObject } from "@cosmjs/proto-signing";
|
|
2
|
-
import { MsgRequestHtlcLock, MsgRequestTransaction, MsgSetTxHash, MsgHtlcReclaim } from "./
|
|
2
|
+
import { MsgRequestHtlcLock, MsgRequestTransaction, MsgSetTxHash, MsgHtlcReclaim } from "./transfer_tx";
|
|
3
|
+
import { MsgRequestSwapTransaction } from "./swap_tx";
|
|
3
4
|
export declare const registry: Registry;
|
|
4
5
|
export declare const TxClient: (wallet: OfflineSigner) => Promise<{
|
|
5
6
|
signAndBroadcast: (msgs: EncodeObject[]) => Promise<import("@cosmjs/stargate").DeliverTxResponse>;
|
|
@@ -7,4 +8,5 @@ export declare const TxClient: (wallet: OfflineSigner) => Promise<{
|
|
|
7
8
|
msgRequestHtlcLock: (data: MsgRequestHtlcLock) => EncodeObject;
|
|
8
9
|
msgSetTxHash: (data: MsgSetTxHash) => EncodeObject;
|
|
9
10
|
msgHtlcReclaim: (data: MsgHtlcReclaim) => EncodeObject;
|
|
11
|
+
msgRequestSwapTransaction: (data: MsgRequestSwapTransaction) => EncodeObject;
|
|
10
12
|
}>;
|
package/build/kima/common.js
CHANGED
|
@@ -7,17 +7,19 @@ 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
|
|
10
|
+
const transfer_tx_1 = require("./transfer_tx");
|
|
11
|
+
const swap_tx_1 = require("./swap_tx");
|
|
11
12
|
dotenv_1.default.config();
|
|
12
13
|
const defaultFee = {
|
|
13
14
|
amount: [(0, proto_signing_1.coin)(200, "uKIMA")],
|
|
14
15
|
gas: "200000", // Gas limit
|
|
15
16
|
};
|
|
16
17
|
const types = [
|
|
17
|
-
["/kimablockchain.transaction.MsgRequestTransaction",
|
|
18
|
-
["/kimablockchain.transaction.MsgRequestHtlcLock",
|
|
19
|
-
["/kimablockchain.transaction.MsgSetTxHash",
|
|
20
|
-
["/kimablockchain.transaction.MsgHtlcReclaim",
|
|
18
|
+
["/kimablockchain.transaction.MsgRequestTransaction", transfer_tx_1.MsgRequestTransaction],
|
|
19
|
+
["/kimablockchain.transaction.MsgRequestHtlcLock", transfer_tx_1.MsgRequestHtlcLock],
|
|
20
|
+
["/kimablockchain.transaction.MsgSetTxHash", transfer_tx_1.MsgSetTxHash],
|
|
21
|
+
["/kimablockchain.transaction.MsgHtlcReclaim", transfer_tx_1.MsgHtlcReclaim],
|
|
22
|
+
["/kimablockchain.swap.MsgRequestSwapTransaction", swap_tx_1.MsgRequestSwapTransaction],
|
|
21
23
|
];
|
|
22
24
|
exports.registry = new proto_signing_1.Registry(types);
|
|
23
25
|
const TxClient = async (wallet) => {
|
|
@@ -30,19 +32,23 @@ const TxClient = async (wallet) => {
|
|
|
30
32
|
},
|
|
31
33
|
msgRequestTransaction: (data) => ({
|
|
32
34
|
typeUrl: "/kimablockchain.transaction.MsgRequestTransaction",
|
|
33
|
-
value:
|
|
35
|
+
value: transfer_tx_1.MsgRequestTransaction.fromPartial(data),
|
|
34
36
|
}),
|
|
35
37
|
msgRequestHtlcLock: (data) => ({
|
|
36
38
|
typeUrl: "/kimablockchain.transaction.MsgRequestHtlcLock",
|
|
37
|
-
value:
|
|
39
|
+
value: transfer_tx_1.MsgRequestHtlcLock.fromPartial(data),
|
|
38
40
|
}),
|
|
39
41
|
msgSetTxHash: (data) => ({
|
|
40
42
|
typeUrl: "/kimablockchain.transaction.MsgSetTxHash",
|
|
41
|
-
value:
|
|
43
|
+
value: transfer_tx_1.MsgSetTxHash.fromPartial(data),
|
|
42
44
|
}),
|
|
43
45
|
msgHtlcReclaim: (data) => ({
|
|
44
46
|
typeUrl: "/kimablockchain.transaction.MsgHtlcReclaim",
|
|
45
|
-
value:
|
|
47
|
+
value: transfer_tx_1.MsgHtlcReclaim.fromPartial(data),
|
|
48
|
+
}),
|
|
49
|
+
msgRequestSwapTransaction: (data) => ({
|
|
50
|
+
typeUrl: "/kimablockchain.swap.MsgRequestSwapTransaction",
|
|
51
|
+
value: swap_tx_1.MsgRequestSwapTransaction.fromPartial(data),
|
|
46
52
|
}),
|
|
47
53
|
};
|
|
48
54
|
};
|