@kimafinance/kima-transaction-api 1.0.0

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 ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "watch": ["src"],
3
+ "ext": ".ts,.js",
4
+ "ignore": [],
5
+ "exec": "ts-node ./src/index.ts"
6
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@kimafinance/kima-transaction-api",
3
+ "version": "1.0.0",
4
+ "description": "A wrapper around Kima's API, enabling sending and monitoring transactions",
5
+ "author": "",
6
+ "license": "MIT",
7
+ "main": "build/index.js",
8
+ "source": "src/index.ts",
9
+ "engines": {
10
+ "node": ">=10"
11
+ },
12
+ "scripts": {
13
+ "test": "echo \"Error: no test specified\" && exit 1",
14
+ "dev": "nodemon",
15
+ "build": "rimraf ./build && tsc",
16
+ "start": "npm run build && node build/index.js"
17
+ },
18
+ "keywords": [],
19
+ "devDependencies": {
20
+ "@types/node": "^18.11.9",
21
+ "nodemon": "^2.0.20",
22
+ "rimraf": "^3.0.2",
23
+ "ts-node": "^10.9.1",
24
+ "typescript": "^4.9.3"
25
+ },
26
+ "dependencies": {
27
+ "@cosmjs/cosmwasm-stargate": "^0.29.4",
28
+ "@cosmjs/proto-signing": "^0.29.4",
29
+ "@cosmjs/stargate": "^0.29.4",
30
+ "dotenv": "^16.0.3"
31
+ }
32
+ }
package/src/index.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
2
+ import { TxClient } from "./kima/common";
3
+ import { MsgRequestTransaction } from "./kima/tx";
4
+
5
+ interface Props {
6
+ originChain: string;
7
+ originAddress: string;
8
+ targetChain: string;
9
+ targetAddress: string;
10
+ amount: number;
11
+ fee: number;
12
+ }
13
+
14
+ export async function submitKimaTransaction({
15
+ originChain,
16
+ originAddress,
17
+ targetChain,
18
+ targetAddress,
19
+ amount,
20
+ fee,
21
+ }: Props) {
22
+ const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
23
+ process.env.KIMA_BACKEND_MNEMONIC as string,
24
+ { prefix: "kima" }
25
+ );
26
+ const client = await TxClient(wallet);
27
+ const [firstAccount] = await wallet.getAccounts();
28
+ const params: MsgRequestTransaction = {
29
+ creator: firstAccount.address,
30
+ originChain,
31
+ originAddress,
32
+ targetChain,
33
+ targetAddress,
34
+ amount: amount.toString(),
35
+ fee: fee.toString(),
36
+ };
37
+
38
+ const msg = await client.msgRequestTransaction(params);
39
+ return await client.signAndBroadcast([msg]);
40
+ }
@@ -0,0 +1,67 @@
1
+ import { SigningStargateClient, StdFee } from '@cosmjs/stargate'
2
+ import dotenv from 'dotenv'
3
+ import { Registry, OfflineSigner, EncodeObject } from '@cosmjs/proto-signing'
4
+ import {
5
+ MsgRequestTransaction,
6
+ MsgApproveTransaction,
7
+ MsgFetchBalance
8
+ } from './tx'
9
+
10
+ dotenv.config()
11
+
12
+ const defaultFee = {
13
+ amount: [],
14
+ gas: '200000'
15
+ }
16
+
17
+ interface SignAndBroadcastOptions {
18
+ fee: StdFee
19
+ memo?: string
20
+ }
21
+
22
+ const types = [
23
+ [
24
+ '/DiversifiTechnologies.diversifi.diversifi.MsgRequestTransaction',
25
+ MsgRequestTransaction
26
+ ],
27
+ [
28
+ '/DiversifiTechnologies.diversifi.diversifi.MsgApproveTransaction',
29
+ MsgApproveTransaction
30
+ ],
31
+ [
32
+ '/DiversifiTechnologies.diversifi.diversifi.MsgFetchBalance',
33
+ MsgFetchBalance
34
+ ]
35
+ ]
36
+
37
+ export const registry = new Registry(<any>types)
38
+
39
+ export const TxClient = async (wallet: OfflineSigner) => {
40
+ const client = await SigningStargateClient.connectWithSigner(
41
+ 'https://' + process.env.KIMA_BACKEND_DIVERSIFI_NODE_PROVIDER1,
42
+ wallet,
43
+ { registry }
44
+ )
45
+ const { address } = (await wallet.getAccounts())[0]
46
+
47
+ return {
48
+ signAndBroadcast: (
49
+ msgs: EncodeObject[],
50
+ { fee, memo }: SignAndBroadcastOptions = { fee: defaultFee, memo: '' }
51
+ ) => client.signAndBroadcast(address, msgs, fee, memo),
52
+ msgRequestTransaction: (data: MsgRequestTransaction): EncodeObject => ({
53
+ typeUrl:
54
+ '/DiversifiTechnologies.diversifi.diversifi.MsgRequestTransaction',
55
+ value: MsgRequestTransaction.fromPartial(data)
56
+ }),
57
+ msgApproveTransaction: (data: MsgApproveTransaction): EncodeObject => ({
58
+ typeUrl:
59
+ '/DiversifiTechnologies.diversifi.diversifi.MsgApproveTransaction',
60
+ value: MsgApproveTransaction.fromPartial(data)
61
+ }),
62
+ msgFetchBalance: (data: MsgFetchBalance): EncodeObject => ({
63
+ typeUrl: '/DiversifiTechnologies.diversifi.diversifi.MsgFetchBalance',
64
+ value: MsgFetchBalance.fromPartial(data)
65
+ })
66
+ }
67
+ }