@kimafinance/kima-transaction-api 1.0.0 → 1.0.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/README.md +13 -9
- package/build/index.d.ts +15 -3
- package/build/index.js +36 -4
- package/build/kima/common.d.ts +4 -5
- package/build/kima/common.js +10 -24
- package/build/kima/tx.d.ts +325 -20
- package/build/kima/tx.js +2457 -313
- package/package.json +1 -1
- package/src/index.ts +42 -4
- package/src/kima/common.ts +24 -44
- package/src/kima/tx.ts +3588 -1096
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,11 +2,25 @@ import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
|
|
|
2
2
|
import { TxClient } from "./kima/common";
|
|
3
3
|
import { MsgRequestTransaction } from "./kima/tx";
|
|
4
4
|
|
|
5
|
+
export enum SupportNetworks {
|
|
6
|
+
Ethereum = "ETH",
|
|
7
|
+
Polygon = "POL",
|
|
8
|
+
Avalanche = "AVX",
|
|
9
|
+
Solana = "SOL",
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export enum CurrencyOptions {
|
|
13
|
+
USDK = "USDK",
|
|
14
|
+
USDT = "USDT",
|
|
15
|
+
USDC = "USDC",
|
|
16
|
+
}
|
|
17
|
+
|
|
5
18
|
interface Props {
|
|
6
|
-
originChain:
|
|
19
|
+
originChain: SupportNetworks;
|
|
7
20
|
originAddress: string;
|
|
8
|
-
targetChain:
|
|
21
|
+
targetChain: SupportNetworks;
|
|
9
22
|
targetAddress: string;
|
|
23
|
+
symbol: CurrencyOptions;
|
|
10
24
|
amount: number;
|
|
11
25
|
fee: number;
|
|
12
26
|
}
|
|
@@ -16,6 +30,7 @@ export async function submitKimaTransaction({
|
|
|
16
30
|
originAddress,
|
|
17
31
|
targetChain,
|
|
18
32
|
targetAddress,
|
|
33
|
+
symbol,
|
|
19
34
|
amount,
|
|
20
35
|
fee,
|
|
21
36
|
}: Props) {
|
|
@@ -31,10 +46,33 @@ export async function submitKimaTransaction({
|
|
|
31
46
|
originAddress,
|
|
32
47
|
targetChain,
|
|
33
48
|
targetAddress,
|
|
49
|
+
symbol,
|
|
34
50
|
amount: amount.toString(),
|
|
35
51
|
fee: fee.toString(),
|
|
36
52
|
};
|
|
37
53
|
|
|
38
|
-
|
|
39
|
-
|
|
54
|
+
let msg = await client.msgRequestTransaction(params);
|
|
55
|
+
const result = await client.signAndBroadcast([msg]);
|
|
56
|
+
|
|
57
|
+
let txId = "1";
|
|
58
|
+
|
|
59
|
+
for (const event of result.events) {
|
|
60
|
+
if (event.type === "transaction_requested") {
|
|
61
|
+
for (const attr of event.attributes) {
|
|
62
|
+
if (attr.key === "txId") {
|
|
63
|
+
txId = attr.value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
msg = await client.msgSetTxHash({
|
|
70
|
+
creator: firstAccount.address,
|
|
71
|
+
txId,
|
|
72
|
+
txHash: result.transactionHash,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const temp = await client.signAndBroadcast([msg]);
|
|
76
|
+
|
|
77
|
+
return result;
|
|
40
78
|
}
|
package/src/kima/common.ts
CHANGED
|
@@ -1,67 +1,47 @@
|
|
|
1
|
-
import { SigningStargateClient, StdFee } from
|
|
2
|
-
import dotenv from
|
|
3
|
-
import { Registry, OfflineSigner, EncodeObject } from
|
|
4
|
-
import {
|
|
5
|
-
MsgRequestTransaction,
|
|
6
|
-
MsgApproveTransaction,
|
|
7
|
-
MsgFetchBalance
|
|
8
|
-
} from './tx'
|
|
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";
|
|
9
5
|
|
|
10
|
-
dotenv.config()
|
|
6
|
+
dotenv.config();
|
|
11
7
|
|
|
12
8
|
const defaultFee = {
|
|
13
9
|
amount: [],
|
|
14
|
-
gas:
|
|
15
|
-
}
|
|
10
|
+
gas: "200000",
|
|
11
|
+
};
|
|
16
12
|
|
|
17
13
|
interface SignAndBroadcastOptions {
|
|
18
|
-
fee: StdFee
|
|
19
|
-
memo?: string
|
|
14
|
+
fee: StdFee;
|
|
15
|
+
memo?: string;
|
|
20
16
|
}
|
|
21
17
|
|
|
22
18
|
const types = [
|
|
23
|
-
[
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
],
|
|
27
|
-
[
|
|
28
|
-
'/DiversifiTechnologies.diversifi.diversifi.MsgApproveTransaction',
|
|
29
|
-
MsgApproveTransaction
|
|
30
|
-
],
|
|
31
|
-
[
|
|
32
|
-
'/DiversifiTechnologies.diversifi.diversifi.MsgFetchBalance',
|
|
33
|
-
MsgFetchBalance
|
|
34
|
-
]
|
|
35
|
-
]
|
|
19
|
+
["/KimaFinance.kima.kima.MsgRequestTransaction", MsgRequestTransaction],
|
|
20
|
+
["/KimaFinance.kima.kima.MsgSetTxHash", MsgSetTxHash],
|
|
21
|
+
];
|
|
36
22
|
|
|
37
|
-
export const registry = new Registry(<any>types)
|
|
23
|
+
export const registry = new Registry(<any>types);
|
|
38
24
|
|
|
39
25
|
export const TxClient = async (wallet: OfflineSigner) => {
|
|
40
26
|
const client = await SigningStargateClient.connectWithSigner(
|
|
41
|
-
|
|
27
|
+
process.env.KIMA_BACKEND_NODE_PROVIDER as string,
|
|
42
28
|
wallet,
|
|
43
29
|
{ registry }
|
|
44
|
-
)
|
|
45
|
-
const { address } = (await wallet.getAccounts())[0]
|
|
30
|
+
);
|
|
31
|
+
const { address } = (await wallet.getAccounts())[0];
|
|
46
32
|
|
|
47
33
|
return {
|
|
48
34
|
signAndBroadcast: (
|
|
49
35
|
msgs: EncodeObject[],
|
|
50
|
-
{ fee, memo }: SignAndBroadcastOptions = { fee: defaultFee, memo:
|
|
36
|
+
{ fee, memo }: SignAndBroadcastOptions = { fee: defaultFee, memo: "" }
|
|
51
37
|
) => client.signAndBroadcast(address, msgs, fee, memo),
|
|
52
38
|
msgRequestTransaction: (data: MsgRequestTransaction): EncodeObject => ({
|
|
53
|
-
typeUrl:
|
|
54
|
-
|
|
55
|
-
value: MsgRequestTransaction.fromPartial(data)
|
|
39
|
+
typeUrl: "/KimaFinance.kima.kima.MsgRequestTransaction",
|
|
40
|
+
value: MsgRequestTransaction.fromPartial(data),
|
|
56
41
|
}),
|
|
57
|
-
|
|
58
|
-
typeUrl:
|
|
59
|
-
|
|
60
|
-
value: MsgApproveTransaction.fromPartial(data)
|
|
42
|
+
msgSetTxHash: (data: MsgSetTxHash): EncodeObject => ({
|
|
43
|
+
typeUrl: "/KimaFinance.kima.kima.MsgSetTxHash",
|
|
44
|
+
value: MsgSetTxHash.fromPartial(data),
|
|
61
45
|
}),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
value: MsgFetchBalance.fromPartial(data)
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
}
|
|
46
|
+
};
|
|
47
|
+
};
|