@swapkit/toolboxes 1.0.0-beta.0 → 1.0.0-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.
Files changed (103) hide show
  1. package/dist/chunk-0f0249b1.js +3 -0
  2. package/dist/chunk-0f0249b1.js.map +10 -0
  3. package/dist/chunk-0h4xdrwz.js +4 -0
  4. package/dist/chunk-0h4xdrwz.js.map +10 -0
  5. package/dist/chunk-4yap1fvd.js +3 -0
  6. package/dist/chunk-4yap1fvd.js.map +10 -0
  7. package/dist/chunk-fjfxga2v.js +3 -0
  8. package/dist/chunk-fjfxga2v.js.map +10 -0
  9. package/dist/{chunk-tvrdndbw.js → chunk-p1kdg37m.js} +2 -2
  10. package/dist/{chunk-tvrdndbw.js.map → chunk-p1kdg37m.js.map} +1 -1
  11. package/dist/cosmos/index.cjs +2 -2
  12. package/dist/cosmos/index.cjs.map +10 -13
  13. package/dist/cosmos/index.js +2 -2
  14. package/dist/cosmos/index.js.map +10 -13
  15. package/dist/evm/index.cjs +2 -2
  16. package/dist/evm/index.cjs.map +10 -16
  17. package/dist/evm/index.js +2 -2
  18. package/dist/evm/index.js.map +10 -16
  19. package/dist/index.cjs +2 -2
  20. package/dist/index.cjs.map +4 -3
  21. package/dist/index.js +2 -2
  22. package/dist/index.js.map +4 -3
  23. package/dist/radix/index.cjs +2 -2
  24. package/dist/radix/index.cjs.map +3 -3
  25. package/dist/radix/index.js +2 -2
  26. package/dist/radix/index.js.map +3 -3
  27. package/dist/ripple/index.cjs +3 -0
  28. package/dist/ripple/index.cjs.map +10 -0
  29. package/dist/ripple/index.js +3 -0
  30. package/dist/ripple/index.js.map +10 -0
  31. package/dist/solana/index.cjs +2 -2
  32. package/dist/solana/index.cjs.map +3 -3
  33. package/dist/solana/index.js +2 -2
  34. package/dist/solana/index.js.map +3 -3
  35. package/dist/substrate/index.cjs +2 -2
  36. package/dist/substrate/index.cjs.map +5 -6
  37. package/dist/substrate/index.js +2 -2
  38. package/dist/substrate/index.js.map +5 -6
  39. package/dist/utxo/index.cjs +2 -2
  40. package/dist/utxo/index.cjs.map +9 -11
  41. package/dist/utxo/index.js +2 -2
  42. package/dist/utxo/index.js.map +9 -11
  43. package/package.json +30 -24
  44. package/src/cosmos/index.ts +2 -9
  45. package/src/cosmos/thorchainUtils/addressFormat.ts +1 -2
  46. package/src/cosmos/thorchainUtils/index.ts +1 -1
  47. package/src/cosmos/thorchainUtils/messages.ts +74 -56
  48. package/src/cosmos/thorchainUtils/registry.ts +16 -23
  49. package/src/cosmos/thorchainUtils/types/{proto/MsgCompiled.ts → MsgCompiled.ts} +1 -3
  50. package/src/cosmos/thorchainUtils/types/client-types.ts +16 -23
  51. package/src/cosmos/toolbox/cosmos.ts +334 -0
  52. package/src/cosmos/toolbox/index.ts +33 -0
  53. package/src/cosmos/toolbox/thorchain.ts +118 -131
  54. package/src/cosmos/types.ts +37 -18
  55. package/src/cosmos/util.ts +21 -71
  56. package/src/evm/__tests__/ethereum.test.ts +110 -116
  57. package/src/evm/api.ts +11 -147
  58. package/src/evm/helpers.ts +111 -83
  59. package/src/evm/index.ts +1 -17
  60. package/src/evm/toolbox/baseEVMToolbox.ts +742 -0
  61. package/src/evm/toolbox/evm.ts +69 -0
  62. package/src/evm/toolbox/index.ts +36 -0
  63. package/src/evm/toolbox/op.ts +97 -143
  64. package/src/evm/types.ts +50 -28
  65. package/src/index.ts +235 -0
  66. package/src/radix/index.ts +18 -19
  67. package/src/ripple/index.ts +203 -0
  68. package/src/solana/index.ts +11 -5
  69. package/src/solana/toolbox.ts +223 -133
  70. package/src/substrate/index.ts +2 -3
  71. package/src/substrate/{toolbox/baseSubstrateToolbox.ts → substrate.ts} +104 -72
  72. package/src/substrate/types.ts +120 -0
  73. package/src/utils.ts +27 -0
  74. package/src/utxo/helpers/api.ts +27 -23
  75. package/src/utxo/helpers/bchaddrjs.ts +21 -21
  76. package/src/utxo/helpers/index.ts +0 -1
  77. package/src/utxo/helpers/txSize.ts +3 -4
  78. package/src/utxo/index.ts +3 -7
  79. package/src/utxo/toolbox/bitcoinCash.ts +164 -154
  80. package/src/utxo/toolbox/index.ts +63 -24
  81. package/src/utxo/toolbox/utxo.ts +376 -229
  82. package/src/utxo/types.ts +24 -39
  83. package/src/cosmos/thorchainUtils/types/proto/MsgCompiled.js +0 -2806
  84. package/src/cosmos/thorchainUtils/util.ts +0 -46
  85. package/src/cosmos/toolbox/BaseCosmosToolbox.ts +0 -254
  86. package/src/cosmos/toolbox/gaia.ts +0 -39
  87. package/src/cosmos/toolbox/getToolboxByChain.ts +0 -29
  88. package/src/cosmos/toolbox/kujira.ts +0 -61
  89. package/src/evm/provider.ts +0 -6
  90. package/src/evm/toolbox/EVMToolbox.ts +0 -662
  91. package/src/evm/toolbox/arb.ts +0 -61
  92. package/src/evm/toolbox/avax.ts +0 -36
  93. package/src/evm/toolbox/base.ts +0 -42
  94. package/src/evm/toolbox/bsc.ts +0 -34
  95. package/src/evm/toolbox/eth.ts +0 -44
  96. package/src/evm/toolbox/getToolboxByChain.ts +0 -42
  97. package/src/evm/toolbox/matic.ts +0 -42
  98. package/src/radix/toolbox.ts +0 -693
  99. package/src/substrate/toolbox/index.ts +0 -40
  100. package/src/substrate/types/index.ts +0 -2
  101. package/src/substrate/types/network.ts +0 -42
  102. package/src/substrate/types/wallet.ts +0 -78
  103. package/src/utxo/helpers/utils.ts +0 -45
@@ -9,7 +9,7 @@ import {
9
9
  } from "../util";
10
10
 
11
11
  import { createDefaultAminoTypes, createDefaultRegistry } from "./registry";
12
- import type { ThorchainDepositTxParams, ThorchainTransferTxParams } from "./types/client-types";
12
+ import type { ThorchainCreateTransactionParams } from "./types";
13
13
 
14
14
  type MsgSend = ReturnType<typeof transferMsgAmino>;
15
15
  type MsgDeposit = ReturnType<typeof depositMsgAmino>;
@@ -22,40 +22,40 @@ export const THORCHAIN_GAS_VALUE = getDefaultChainFee(Chain.THORChain).gas;
22
22
  export const MAYA_GAS_VALUE = getDefaultChainFee(Chain.Maya).gas;
23
23
 
24
24
  export const transferMsgAmino = ({
25
- from,
25
+ sender,
26
26
  recipient,
27
27
  assetValue,
28
- chain,
29
28
  }: {
30
- from: string;
29
+ sender: string;
31
30
  recipient?: string;
32
31
  assetValue: AssetValue;
33
- chain: Chain.THORChain | Chain.Maya;
34
- }) => ({
35
- type: `${chain === Chain.Maya ? "mayachain" : "thorchain"}/MsgSend` as const,
36
- value: {
37
- from_address: from,
38
- to_address: recipient,
39
- amount: [
40
- {
41
- amount: assetValue.getBaseValue("string"),
42
- denom: getMsgSendDenom(assetValue.symbol, true),
43
- },
44
- ],
45
- },
46
- });
32
+ }) => {
33
+ const chain = assetValue.chain as Chain.THORChain | Chain.Maya;
34
+ return {
35
+ type: `${chain === Chain.Maya ? "mayachain" : "thorchain"}/MsgSend` as const,
36
+ value: {
37
+ from_address: sender,
38
+ to_address: recipient,
39
+ amount: [
40
+ {
41
+ amount: assetValue.getBaseValue("string"),
42
+ denom: getMsgSendDenom(assetValue.symbol, true),
43
+ },
44
+ ],
45
+ },
46
+ };
47
+ };
47
48
 
48
49
  export const depositMsgAmino = ({
49
- from,
50
+ sender,
50
51
  assetValue,
51
52
  memo = "",
52
- chain,
53
53
  }: {
54
- from: string;
54
+ sender: string;
55
55
  assetValue: AssetValue;
56
56
  memo?: string;
57
- chain: Chain.THORChain | Chain.Maya;
58
57
  }) => {
58
+ const chain = assetValue.chain as Chain.THORChain | Chain.Maya;
59
59
  return {
60
60
  type: `${chain === Chain.Maya ? "mayachain" : "thorchain"}/MsgDeposit` as const,
61
61
  value: {
@@ -65,36 +65,33 @@ export const depositMsgAmino = ({
65
65
  asset: getDenomWithChain(assetValue),
66
66
  },
67
67
  ],
68
- signer: from,
68
+ signer: sender,
69
69
  memo,
70
70
  },
71
71
  };
72
72
  };
73
73
 
74
74
  export const buildAminoMsg = ({
75
- from,
75
+ sender,
76
76
  recipient,
77
77
  assetValue,
78
78
  memo,
79
- chain,
80
79
  }: {
81
- from: string;
80
+ sender: string;
82
81
  recipient?: string;
83
82
  assetValue: AssetValue;
84
83
  memo?: string;
85
- chain: Chain.THORChain | Chain.Maya;
86
84
  }) => {
87
85
  const isDeposit = !recipient;
88
86
  const msg = isDeposit
89
- ? depositMsgAmino({ from, assetValue, memo, chain })
90
- : transferMsgAmino({ from, recipient, assetValue, chain });
87
+ ? depositMsgAmino({ sender, assetValue, memo })
88
+ : transferMsgAmino({ sender, recipient, assetValue });
91
89
 
92
90
  return msg;
93
91
  };
94
92
 
95
- // TODO I think the msg typing is wrong it should be not prepared for broadcast
96
93
  export const convertToSignable = async (
97
- msg: DirectMsgDepositForBroadcast | DirectMsgSendForBroadcast | MsgSend | MsgDeposit,
94
+ msg: MsgSend | MsgDeposit,
98
95
  chain: Chain.THORChain | Chain.Maya,
99
96
  ) => {
100
97
  const aminoTypes = await createDefaultAminoTypes(chain);
@@ -102,16 +99,9 @@ export const convertToSignable = async (
102
99
  return aminoTypes.fromAmino(msg);
103
100
  };
104
101
 
105
- const getAccount = async ({
106
- rpcUrl,
107
- from,
108
- }: {
109
- from: string;
110
- rpcUrl: string;
111
- }) => {
102
+ const getAccount = async ({ rpcUrl, sender }: { sender: string; rpcUrl: string }) => {
112
103
  const client = await createStargateClient(rpcUrl);
113
-
114
- const account = await client.getAccount(from);
104
+ const account = await client.getAccount(sender);
115
105
 
116
106
  if (!account) {
117
107
  throw new Error("Account does not exist");
@@ -120,24 +110,50 @@ const getAccount = async ({
120
110
  return account;
121
111
  };
122
112
 
113
+ export function getCreateTransaction(rpcUrl: string) {
114
+ return function createTransaction(params: ThorchainCreateTransactionParams) {
115
+ const { assetValue, recipient, memo, sender, asSignable, asAminoMessage } = params;
116
+
117
+ if (recipient) {
118
+ return buildTransferTx(rpcUrl)({
119
+ sender,
120
+ recipient,
121
+ assetValue,
122
+ memo,
123
+ asSignable,
124
+ asAminoMessage,
125
+ });
126
+ }
127
+
128
+ return buildDepositTx(rpcUrl)({
129
+ sender,
130
+ assetValue,
131
+ memo,
132
+ asSignable,
133
+ asAminoMessage,
134
+ });
135
+ };
136
+ }
137
+
123
138
  export const buildTransferTx =
124
139
  (rpcUrl: string) =>
125
140
  async ({
126
- from,
141
+ sender,
127
142
  recipient,
128
143
  assetValue,
129
144
  memo = "",
130
- chain,
131
145
  asSignable = true,
132
146
  asAminoMessage = false,
133
- }: ThorchainTransferTxParams) => {
134
- const account = await getAccount({ rpcUrl, from });
147
+ sequence,
148
+ accountNumber,
149
+ }: ThorchainCreateTransactionParams) => {
150
+ const account = await getAccount({ rpcUrl, sender });
151
+ const chain = assetValue.chain as Chain.THORChain | Chain.Maya;
135
152
 
136
153
  const transferMsg = transferMsgAmino({
137
- from,
154
+ sender,
138
155
  recipient,
139
156
  assetValue,
140
- chain,
141
157
  });
142
158
 
143
159
  const msg = asSignable
@@ -149,8 +165,8 @@ export const buildTransferTx =
149
165
 
150
166
  const transaction = {
151
167
  chainId: ChainToChainId[chain],
152
- accountNumber: account.accountNumber,
153
- sequence: account.sequence,
168
+ accountNumber: accountNumber || account.accountNumber,
169
+ sequence: sequence || account.sequence,
154
170
  msgs: [msg],
155
171
  fee: getDefaultChainFee(assetValue.chain as Chain.THORChain | Chain.Maya),
156
172
  memo,
@@ -162,16 +178,18 @@ export const buildTransferTx =
162
178
  export const buildDepositTx =
163
179
  (rpcUrl: string) =>
164
180
  async ({
165
- from,
181
+ sender,
166
182
  assetValue,
167
183
  memo = "",
168
- chain,
169
184
  asSignable = true,
170
185
  asAminoMessage = false,
171
- }: ThorchainDepositTxParams) => {
172
- const account = await getAccount({ rpcUrl, from });
186
+ sequence,
187
+ accountNumber,
188
+ }: ThorchainCreateTransactionParams) => {
189
+ const account = await getAccount({ rpcUrl, sender });
190
+ const chain = assetValue.chain as Chain.THORChain | Chain.Maya;
173
191
 
174
- const depositMsg = depositMsgAmino({ from, assetValue, memo, chain });
192
+ const depositMsg = depositMsgAmino({ sender, assetValue, memo });
175
193
 
176
194
  const msg = asSignable
177
195
  ? await convertToSignable(
@@ -182,8 +200,8 @@ export const buildDepositTx =
182
200
 
183
201
  const transaction = {
184
202
  chainId: ChainToChainId[chain],
185
- accountNumber: account.accountNumber,
186
- sequence: account.sequence,
203
+ accountNumber: accountNumber || account.accountNumber,
204
+ sequence: sequence || account.sequence,
187
205
  msgs: [msg],
188
206
  fee: getDefaultChainFee(assetValue.chain as Chain.THORChain | Chain.Maya),
189
207
  memo,
@@ -214,7 +232,7 @@ export function parseAminoMessageForDirectSigning<T extends MsgDeposit | MsgSend
214
232
  asset: {
215
233
  chain,
216
234
  symbol,
217
- ticker: symbol,
235
+ ticker: assetValue.ticker,
218
236
  synth: assetValue.isSynthetic,
219
237
  },
220
238
  };
@@ -1,47 +1,40 @@
1
1
  import { Chain } from "@swapkit/helpers";
2
- import * as types from "../thorchainUtils/types/proto/MsgCompiled";
3
2
  import { base64ToBech32, bech32ToBase64 } from "./addressFormat";
4
3
 
5
4
  export async function createDefaultRegistry() {
5
+ const { $root } = await import("./types/MsgCompiled");
6
6
  const { Registry } = await import("@cosmjs/proto-signing");
7
7
  const { defaultRegistryTypes } = await import("@cosmjs/stargate");
8
8
 
9
9
  return new Registry([
10
10
  ...defaultRegistryTypes,
11
- ["/types.MsgSend", { ...types.default.types.MsgSend }],
12
- ["/types.MsgDeposit", { ...types.default.types.MsgDeposit }],
11
+ ["/types.MsgSend", $root.types.MsgSend],
12
+ ["/types.MsgDeposit", $root.types.MsgDeposit],
13
13
  ]);
14
14
  }
15
15
 
16
16
  export async function createDefaultAminoTypes(chain: Chain.THORChain | Chain.Maya) {
17
17
  const { AminoTypes } = await import("@cosmjs/stargate");
18
+ const aminoTypePrefix = chain === Chain.THORChain ? "thorchain" : "mayachain";
18
19
 
19
20
  return new AminoTypes({
20
21
  "/types.MsgSend": {
21
- aminoType: `${chain === Chain.Maya ? "mayachain" : "thorchain"}/MsgSend`,
22
- toAmino: (params: any) => ({
23
- from_address: base64ToBech32(params.fromAddress),
24
- to_address: base64ToBech32(params.toAddress),
25
- amount: [...params.amount],
22
+ aminoType: `${aminoTypePrefix}/MsgSend`,
23
+ toAmino: ({ fromAddress, toAddress, ...rest }: any) => ({
24
+ ...rest,
25
+ from_address: base64ToBech32(fromAddress),
26
+ to_address: base64ToBech32(toAddress),
26
27
  }),
27
- fromAmino: (params: any) => ({
28
- fromAddress: bech32ToBase64(params.from_address),
29
- toAddress: bech32ToBase64(params.to_address),
30
- amount: [...params.amount],
28
+ fromAmino: ({ from_address, to_address, ...rest }: any) => ({
29
+ ...rest,
30
+ fromAddress: bech32ToBase64(from_address),
31
+ toAddress: bech32ToBase64(to_address),
31
32
  }),
32
33
  },
33
34
  "/types.MsgDeposit": {
34
- aminoType: `${chain === Chain.Maya ? "mayachain" : "thorchain"}/MsgDeposit`,
35
- toAmino: (params: any) => ({
36
- signer: base64ToBech32(params.signer),
37
- memo: params.memo,
38
- coins: [...params.coins],
39
- }),
40
- fromAmino: (params: any) => ({
41
- signer: bech32ToBase64(params.signer),
42
- memo: params.memo,
43
- coins: [...params.coins],
44
- }),
35
+ aminoType: `${aminoTypePrefix}/MsgDeposit`,
36
+ toAmino: ({ signer, ...rest }: any) => ({ ...rest, signer: base64ToBech32(signer) }),
37
+ fromAmino: ({ signer, ...rest }: any) => ({ ...rest, signer: bech32ToBase64(signer) }),
45
38
  },
46
39
  });
47
40
  }
@@ -8,7 +8,7 @@ const $util = $protobuf.util;
8
8
 
9
9
  // Exported root namespace
10
10
 
11
- const $root = ($protobuf.roots["default"] || ($protobuf.roots["default"] = {})) as any;
11
+ export const $root = ($protobuf.roots.default || ($protobuf.roots.default = {})) as any;
12
12
 
13
13
  $root.common = (() => {
14
14
  /**
@@ -2798,5 +2798,3 @@ $root.cosmos = (() => {
2798
2798
 
2799
2799
  return cosmos;
2800
2800
  })();
2801
-
2802
- export default $root;
@@ -1,6 +1,10 @@
1
- import type { OfflineAminoSigner } from "@cosmjs/amino";
2
- import type { EncodeObject, OfflineDirectSigner } from "@cosmjs/proto-signing";
3
- import type { Asset, AssetValue, Chain, ChainId } from "@swapkit/helpers";
1
+ import type { EncodeObject } from "@cosmjs/proto-signing";
2
+ import type {
3
+ Asset,
4
+ ChainId,
5
+ GenericCreateTransactionParams,
6
+ GenericTransferParams,
7
+ } from "@swapkit/helpers";
4
8
 
5
9
  enum TxType {
6
10
  Transfer = "transfer",
@@ -21,13 +25,6 @@ export type NodeUrl = {
21
25
  rpc: string;
22
26
  };
23
27
 
24
- export type DepositParam = {
25
- signer?: OfflineDirectSigner | OfflineAminoSigner;
26
- walletIndex?: number;
27
- assetValue: AssetValue;
28
- memo: string;
29
- };
30
-
31
28
  export type TxData = Pick<Tx, "from" | "to" | "type">;
32
29
 
33
30
  /**
@@ -59,22 +56,18 @@ export type TransferTransaction = {
59
56
  fee: { amount: { denom: string; amount: string }[]; gas: string };
60
57
  };
61
58
 
62
- export type CosmosNativeTransferTxParams = {
63
- fromAddress: string;
64
- toAddress: string;
65
- assetValue: AssetValue;
66
- memo?: string;
67
- fee?: string;
59
+ export type CosmosCreateTransactionParams = GenericCreateTransactionParams & {
60
+ accountNumber?: number;
61
+ sequence?: number;
68
62
  };
69
63
 
70
- export type ThorchainTransferTxParams = {
71
- from: string;
72
- recipient: string;
73
- assetValue: AssetValue;
74
- memo?: string;
75
- chain: Chain.THORChain | Chain.Maya;
64
+ export type ThorchainCreateTransactionParams = Omit<
65
+ CosmosCreateTransactionParams,
66
+ "feeRate" | "recipient"
67
+ > & {
68
+ recipient?: string;
76
69
  asSignable?: boolean;
77
70
  asAminoMessage?: boolean;
78
71
  };
79
72
 
80
- export type ThorchainDepositTxParams = Omit<ThorchainTransferTxParams, "recipient">;
73
+ export type ThorchainDepositParams = Omit<GenericTransferParams, "recipient">;