@dydxprotocol/v4-client-js 1.1.13 → 1.1.15
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/.eslintrc.js +3 -5
- package/.prettierignore +3 -0
- package/.prettierrc.json +6 -0
- package/.telescope.json +2 -4
- package/.vscode/launch.json +10 -10
- package/README.md +3 -1
- package/__native__/__ios__/v4-native-client.js +2680 -799
- package/__tests__/helpers/constants.ts +10 -8
- package/__tests__/lib/helpers.test.ts +22 -23
- package/__tests__/lib/util.test.ts +2 -8
- package/__tests__/lib/validation.test.ts +23 -26
- package/__tests__/modules/client/Transfers.test.ts +4 -19
- package/__tests__/modules/client/ValidatorPostEndpoints.test.ts +2 -5
- package/__tests__/modules/client/constants.ts +4 -2
- package/__tests__/modules/onboarding.test.ts +9 -7
- package/build/__tests__/helpers/constants.js +7 -7
- package/build/__tests__/lib/helpers.test.js +2 -6
- package/build/__tests__/lib/util.test.js +1 -1
- package/build/__tests__/lib/validation.test.js +3 -11
- package/build/__tests__/modules/client/Transfers.test.js +1 -1
- package/build/__tests__/modules/client/ValidatorPostEndpoints.test.js +2 -2
- package/build/__tests__/modules/client/constants.js +1 -1
- package/build/__tests__/modules/onboarding.test.js +2 -3
- package/build/examples/account_endpoints.js +4 -3
- package/build/examples/composite_example.js +5 -4
- package/build/examples/constants.js +1 -1
- package/build/examples/faucet_endpoint.js +4 -3
- package/build/examples/long_term_order_cancel_example.js +4 -3
- package/build/examples/markets_endpoints.js +4 -3
- package/build/examples/native_examples.js +4 -3
- package/build/examples/noble_example.js +1 -1
- package/build/examples/optimal_node.js +4 -12
- package/build/examples/short_term_order_cancel_example.js +4 -3
- package/build/examples/short_term_order_composite_example.js +4 -3
- package/build/examples/test.js +5 -4
- package/build/examples/transfer_example_deposit.js +4 -3
- package/build/examples/transfer_example_send.js +1 -1
- package/build/examples/transfer_example_subaccount_transfer.js +4 -3
- package/build/examples/transfer_example_withdraw.js +4 -3
- package/build/examples/transfer_example_withdraw_other.js +1 -1
- package/build/examples/utility_endpoints.js +4 -3
- package/build/examples/validator_get_example.js +15 -9
- package/build/examples/validator_post_example.js +4 -3
- package/build/examples/wallet_address.js +5 -4
- package/build/examples/websocket_example.js +1 -1
- package/build/src/clients/composite-client.d.ts +222 -222
- package/build/src/clients/composite-client.js +234 -228
- package/build/src/clients/constants.d.ts +3 -0
- package/build/src/clients/constants.js +6 -2
- package/build/src/clients/faucet-client.d.ts +4 -4
- package/build/src/clients/faucet-client.js +5 -5
- package/build/src/clients/helpers/chain-helpers.js +1 -1
- package/build/src/clients/helpers/request-helpers.js +5 -4
- package/build/src/clients/indexer-client.js +1 -1
- package/build/src/clients/lib/axios/axiosRequest.js +1 -1
- package/build/src/clients/lib/axios/errors.js +1 -1
- package/build/src/clients/lib/cctpProto.d.ts +2 -2
- package/build/src/clients/lib/cctpProto.js +287 -237
- package/build/src/clients/lib/errors.js +1 -1
- package/build/src/clients/modules/account.js +1 -1
- package/build/src/clients/modules/composer.d.ts +4 -0
- package/build/src/clients/modules/composer.js +39 -3
- package/build/src/clients/modules/get.d.ts +10 -3
- package/build/src/clients/modules/get.js +41 -54
- package/build/src/clients/modules/local-wallet.js +1 -1
- package/build/src/clients/modules/post.d.ts +6 -0
- package/build/src/clients/modules/post.js +50 -18
- package/build/src/clients/modules/proto-includes.d.ts +1 -0
- package/build/src/clients/modules/proto-includes.js +3 -2
- package/build/src/clients/modules/rest.js +1 -1
- package/build/src/clients/modules/signer.js +1 -1
- package/build/src/clients/modules/tendermintClient.d.ts +5 -5
- package/build/src/clients/modules/tendermintClient.js +6 -6
- package/build/src/clients/native.d.ts +5 -0
- package/build/src/clients/native.js +44 -9
- package/build/src/clients/noble-client.js +1 -1
- package/build/src/clients/socket-client.js +1 -1
- package/build/src/clients/subaccount.js +1 -1
- package/build/src/clients/types.d.ts +1 -1
- package/build/src/clients/types.js +1 -1
- package/build/src/clients/validator-client.d.ts +12 -12
- package/build/src/clients/validator-client.js +13 -13
- package/build/src/lib/errors.js +1 -1
- package/build/src/lib/onboarding.js +1 -1
- package/build/src/lib/utils.js +3 -3
- package/build/src/lib/validation.js +5 -4
- package/build/src/network_optimizer.js +10 -11
- package/build/src/types.d.ts +1 -1
- package/build/src/types.js +1 -1
- package/examples/account_endpoints.ts +5 -4
- package/examples/composite_example.ts +12 -7
- package/examples/constants.ts +10 -4
- package/examples/faucet_endpoint.ts +5 -4
- package/examples/human_readable_orders.json +85 -85
- package/examples/human_readable_short_term_orders.json +41 -41
- package/examples/long_term_order_cancel_example.ts +11 -6
- package/examples/markets_endpoints.ts +5 -4
- package/examples/native_examples.ts +8 -7
- package/examples/noble_example.ts +11 -23
- package/examples/optimal_node.ts +4 -14
- package/examples/raw_orders.json +128 -128
- package/examples/short_term_order_cancel_example.ts +7 -8
- package/examples/short_term_order_composite_example.ts +7 -8
- package/examples/test.ts +12 -7
- package/examples/transfer_example_deposit.ts +6 -9
- package/examples/transfer_example_send.ts +2 -10
- package/examples/transfer_example_subaccount_transfer.ts +6 -11
- package/examples/transfer_example_withdraw.ts +6 -9
- package/examples/transfer_example_withdraw_other.ts +1 -5
- package/examples/utility_endpoints.ts +5 -4
- package/examples/validator_get_example.ts +19 -10
- package/examples/validator_post_example.ts +7 -9
- package/examples/wallet_address.ts +6 -5
- package/examples/websocket_example.ts +5 -1
- package/package.json +4 -1
- package/src/clients/composite-client.ts +272 -329
- package/src/clients/constants.ts +38 -26
- package/src/clients/faucet-client.ts +5 -8
- package/src/clients/helpers/chain-helpers.ts +10 -6
- package/src/clients/helpers/request-helpers.ts +6 -5
- package/src/clients/indexer-client.ts +34 -34
- package/src/clients/lib/axios/axiosRequest.ts +4 -7
- package/src/clients/lib/axios/errors.ts +16 -21
- package/src/clients/lib/cctpProto.ts +655 -387
- package/src/clients/lib/errors.ts +8 -17
- package/src/clients/modules/account.ts +4 -12
- package/src/clients/modules/composer.ts +61 -20
- package/src/clients/modules/get.ts +71 -89
- package/src/clients/modules/local-wallet.ts +41 -56
- package/src/clients/modules/post.ts +684 -634
- package/src/clients/modules/proto-includes.ts +1 -0
- package/src/clients/modules/rest.ts +23 -26
- package/src/clients/modules/signer.ts +8 -22
- package/src/clients/modules/tendermintClient.ts +13 -36
- package/src/clients/native.ts +119 -140
- package/src/clients/noble-client.ts +1 -5
- package/src/clients/socket-client.ts +216 -216
- package/src/clients/subaccount.ts +16 -16
- package/src/clients/types.ts +14 -10
- package/src/clients/validator-client.ts +14 -16
- package/src/codegen/helpers.ts +149 -150
- package/src/codegen/index.ts +4 -5
- package/src/lib/errors.ts +3 -9
- package/src/lib/onboarding.ts +7 -2
- package/src/lib/utils.ts +5 -12
- package/src/lib/validation.ts +21 -19
- package/src/network_optimizer.ts +78 -65
- package/src/types.ts +5 -6
- package/tasks.json +15 -15
- package/tsconfig.eslint.json +1 -4
- package/tsconfig.json +2 -6
package/src/clients/native.ts
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
Native app can call JS functions with primitives.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { Secp256k1, sha256 } from '@cosmjs/crypto';
|
|
5
6
|
import { EncodeObject, coin as createCoin } from '@cosmjs/proto-signing';
|
|
6
7
|
import { MsgTransferEncodeObject, accountFromAny } from '@cosmjs/stargate';
|
|
7
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
Order_Side,
|
|
10
|
+
Order_TimeInForce,
|
|
11
|
+
} from '@dydxprotocol/v4-proto/src/codegen/dydxprotocol/clob/order';
|
|
8
12
|
import * as AuthModule from 'cosmjs-types/cosmos/auth/v1beta1/query';
|
|
9
13
|
import Long from 'long';
|
|
10
14
|
|
|
@@ -15,7 +19,13 @@ import { deriveHDKeyFromEthereumSignature } from '../lib/onboarding';
|
|
|
15
19
|
import { NetworkOptimizer } from '../network_optimizer';
|
|
16
20
|
import { CompositeClient, MarketInfo } from './composite-client';
|
|
17
21
|
import {
|
|
18
|
-
Network,
|
|
22
|
+
Network,
|
|
23
|
+
OrderType,
|
|
24
|
+
OrderSide,
|
|
25
|
+
OrderTimeInForce,
|
|
26
|
+
OrderExecution,
|
|
27
|
+
IndexerConfig,
|
|
28
|
+
ValidatorConfig,
|
|
19
29
|
} from './constants';
|
|
20
30
|
import { FaucetClient } from './faucet-client';
|
|
21
31
|
import { Response } from './lib/axios';
|
|
@@ -31,6 +41,11 @@ declare global {
|
|
|
31
41
|
var faucetClient: FaucetClient | null;
|
|
32
42
|
// eslint-disable-next-line vars-on-top, no-var
|
|
33
43
|
var wallet: LocalWallet;
|
|
44
|
+
// eslint-disable-next-line vars-on-top, no-var
|
|
45
|
+
var hdKey: {
|
|
46
|
+
privateKey: Uint8Array | null;
|
|
47
|
+
publicKey: Uint8Array | null;
|
|
48
|
+
}
|
|
34
49
|
|
|
35
50
|
// eslint-disable-next-line vars-on-top, no-var
|
|
36
51
|
var nobleClient: NobleClient | undefined;
|
|
@@ -38,9 +53,7 @@ declare global {
|
|
|
38
53
|
var nobleWallet: LocalWallet | undefined;
|
|
39
54
|
}
|
|
40
55
|
|
|
41
|
-
export async function connectClient(
|
|
42
|
-
network: Network,
|
|
43
|
-
): Promise<string> {
|
|
56
|
+
export async function connectClient(network: Network): Promise<string> {
|
|
44
57
|
try {
|
|
45
58
|
globalThis.client = await CompositeClient.connect(network);
|
|
46
59
|
return encodeJson(network);
|
|
@@ -49,9 +62,7 @@ export async function connectClient(
|
|
|
49
62
|
}
|
|
50
63
|
}
|
|
51
64
|
|
|
52
|
-
export async function connectNetwork(
|
|
53
|
-
paramsJSON: string,
|
|
54
|
-
): Promise<string> {
|
|
65
|
+
export async function connectNetwork(paramsJSON: string): Promise<string> {
|
|
55
66
|
try {
|
|
56
67
|
const params = JSON.parse(paramsJSON);
|
|
57
68
|
const {
|
|
@@ -70,16 +81,20 @@ export async function connectNetwork(
|
|
|
70
81
|
txnMemo,
|
|
71
82
|
} = params;
|
|
72
83
|
|
|
73
|
-
if (
|
|
84
|
+
if (
|
|
85
|
+
indexerUrl === undefined ||
|
|
74
86
|
websocketUrl === undefined ||
|
|
75
87
|
validatorUrl === undefined ||
|
|
76
|
-
chainId === undefined
|
|
88
|
+
chainId === undefined
|
|
89
|
+
) {
|
|
77
90
|
throw new UserError('Missing required network params');
|
|
78
91
|
}
|
|
79
|
-
if (
|
|
92
|
+
if (
|
|
93
|
+
USDC_DENOM === undefined ||
|
|
80
94
|
USDC_DECIMALS === undefined ||
|
|
81
95
|
CHAINTOKEN_DENOM === undefined ||
|
|
82
|
-
CHAINTOKEN_DECIMALS === undefined
|
|
96
|
+
CHAINTOKEN_DECIMALS === undefined
|
|
97
|
+
) {
|
|
83
98
|
throw new UserError('Missing required token params');
|
|
84
99
|
}
|
|
85
100
|
if (txnMemo === undefined) {
|
|
@@ -125,15 +140,10 @@ export async function connectNetwork(
|
|
|
125
140
|
}
|
|
126
141
|
}
|
|
127
142
|
|
|
128
|
-
export async function connectWallet(
|
|
129
|
-
mnemonic: string,
|
|
130
|
-
): Promise<string> {
|
|
143
|
+
export async function connectWallet(mnemonic: string): Promise<string> {
|
|
131
144
|
try {
|
|
132
145
|
globalThis.wallet = await LocalWallet.fromMnemonic(mnemonic, BECH32_PREFIX);
|
|
133
|
-
globalThis.nobleWallet = await LocalWallet.fromMnemonic(
|
|
134
|
-
mnemonic,
|
|
135
|
-
NOBLE_BECH32_PREFIX,
|
|
136
|
-
);
|
|
146
|
+
globalThis.nobleWallet = await LocalWallet.fromMnemonic(mnemonic, NOBLE_BECH32_PREFIX);
|
|
137
147
|
|
|
138
148
|
try {
|
|
139
149
|
await globalThis.nobleClient?.connect(globalThis.nobleWallet);
|
|
@@ -148,10 +158,7 @@ export async function connectWallet(
|
|
|
148
158
|
}
|
|
149
159
|
}
|
|
150
160
|
|
|
151
|
-
export async function connect(
|
|
152
|
-
network: Network,
|
|
153
|
-
mnemonic: string,
|
|
154
|
-
): Promise<string> {
|
|
161
|
+
export async function connect(network: Network, mnemonic: string): Promise<string> {
|
|
155
162
|
try {
|
|
156
163
|
await connectClient(network);
|
|
157
164
|
return connectWallet(mnemonic);
|
|
@@ -162,8 +169,11 @@ export async function connect(
|
|
|
162
169
|
|
|
163
170
|
export async function deriveMnemomicFromEthereumSignature(signature: string): Promise<string> {
|
|
164
171
|
try {
|
|
165
|
-
const { mnemonic } = deriveHDKeyFromEthereumSignature(signature);
|
|
172
|
+
const { mnemonic, privateKey, publicKey } = deriveHDKeyFromEthereumSignature(signature);
|
|
166
173
|
const wallet = await LocalWallet.fromMnemonic(mnemonic, BECH32_PREFIX);
|
|
174
|
+
hdKey = {
|
|
175
|
+
privateKey, publicKey
|
|
176
|
+
}
|
|
167
177
|
const result = { mnemonic, address: wallet.address! };
|
|
168
178
|
return new Promise((resolve) => {
|
|
169
179
|
resolve(encodeJson(result));
|
|
@@ -218,8 +228,8 @@ export async function getEquityTiers(): Promise<string> {
|
|
|
218
228
|
if (client === undefined) {
|
|
219
229
|
throw new UserError('client is not connected. Call connectClient() first');
|
|
220
230
|
}
|
|
221
|
-
const equityTiers =
|
|
222
|
-
.getEquityTierLimitConfiguration();
|
|
231
|
+
const equityTiers =
|
|
232
|
+
await globalThis.client?.validatorClient.get.getEquityTierLimitConfiguration();
|
|
223
233
|
return encodeJson(equityTiers, ByteArrayEncoding.BIGINT);
|
|
224
234
|
} catch (e) {
|
|
225
235
|
return wrappedError(e);
|
|
@@ -239,9 +249,7 @@ export async function getPerpetualMarkets(): Promise<string> {
|
|
|
239
249
|
}
|
|
240
250
|
}
|
|
241
251
|
|
|
242
|
-
export async function placeOrder(
|
|
243
|
-
payload: string,
|
|
244
|
-
): Promise<string> {
|
|
252
|
+
export async function placeOrder(payload: string): Promise<string> {
|
|
245
253
|
try {
|
|
246
254
|
const client = globalThis.client;
|
|
247
255
|
if (client === undefined) {
|
|
@@ -323,9 +331,7 @@ export function wrappedError(error: Error): string {
|
|
|
323
331
|
return `{"error": ${text}}`;
|
|
324
332
|
}
|
|
325
333
|
|
|
326
|
-
export async function cancelOrder(
|
|
327
|
-
payload: string,
|
|
328
|
-
): Promise<string> {
|
|
334
|
+
export async function cancelOrder(payload: string): Promise<string> {
|
|
329
335
|
try {
|
|
330
336
|
const client = globalThis.client;
|
|
331
337
|
if (client === undefined) {
|
|
@@ -371,9 +377,7 @@ export async function cancelOrder(
|
|
|
371
377
|
}
|
|
372
378
|
}
|
|
373
379
|
|
|
374
|
-
export async function deposit(
|
|
375
|
-
payload: string,
|
|
376
|
-
): Promise<string> {
|
|
380
|
+
export async function deposit(payload: string): Promise<string> {
|
|
377
381
|
try {
|
|
378
382
|
const client = globalThis.client;
|
|
379
383
|
if (client === undefined) {
|
|
@@ -395,19 +399,14 @@ export async function deposit(
|
|
|
395
399
|
}
|
|
396
400
|
|
|
397
401
|
const subaccount = new SubaccountInfo(wallet, subaccountNumber);
|
|
398
|
-
const tx = await client.depositToSubaccount(
|
|
399
|
-
subaccount,
|
|
400
|
-
amount,
|
|
401
|
-
);
|
|
402
|
+
const tx = await client.depositToSubaccount(subaccount, amount);
|
|
402
403
|
return encodeJson(tx);
|
|
403
404
|
} catch (error) {
|
|
404
405
|
return wrappedError(error);
|
|
405
406
|
}
|
|
406
407
|
}
|
|
407
408
|
|
|
408
|
-
export async function withdraw(
|
|
409
|
-
payload: string,
|
|
410
|
-
): Promise<string> {
|
|
409
|
+
export async function withdraw(payload: string): Promise<string> {
|
|
411
410
|
try {
|
|
412
411
|
const client = globalThis.client;
|
|
413
412
|
if (client === undefined) {
|
|
@@ -429,20 +428,14 @@ export async function withdraw(
|
|
|
429
428
|
}
|
|
430
429
|
|
|
431
430
|
const subaccount = new SubaccountInfo(wallet, subaccountNumber);
|
|
432
|
-
const tx = await client.withdrawFromSubaccount(
|
|
433
|
-
subaccount,
|
|
434
|
-
amount,
|
|
435
|
-
json.recipient,
|
|
436
|
-
);
|
|
431
|
+
const tx = await client.withdrawFromSubaccount(subaccount, amount, json.recipient);
|
|
437
432
|
return encodeJson(tx);
|
|
438
433
|
} catch (error) {
|
|
439
434
|
return wrappedError(error);
|
|
440
435
|
}
|
|
441
436
|
}
|
|
442
437
|
|
|
443
|
-
export async function faucet(
|
|
444
|
-
payload: string,
|
|
445
|
-
): Promise<string> {
|
|
438
|
+
export async function faucet(payload: string): Promise<string> {
|
|
446
439
|
try {
|
|
447
440
|
const faucetClient = globalThis.faucetClient;
|
|
448
441
|
if (!faucetClient) {
|
|
@@ -491,7 +484,7 @@ export async function withdrawToIBC(
|
|
|
491
484
|
throw new UserError('wallet is not set. Call connectWallet() first');
|
|
492
485
|
}
|
|
493
486
|
|
|
494
|
-
const decode = (str: string):string => Buffer.from(str, 'base64').toString('binary');
|
|
487
|
+
const decode = (str: string): string => Buffer.from(str, 'base64').toString('binary');
|
|
495
488
|
const decoded = decode(payload);
|
|
496
489
|
|
|
497
490
|
const json: SquidIBCPayload = JSON.parse(decoded);
|
|
@@ -528,9 +521,7 @@ export async function withdrawToIBC(
|
|
|
528
521
|
}
|
|
529
522
|
}
|
|
530
523
|
|
|
531
|
-
export async function transferNativeToken(
|
|
532
|
-
payload: string,
|
|
533
|
-
): Promise<string> {
|
|
524
|
+
export async function transferNativeToken(payload: string): Promise<string> {
|
|
534
525
|
try {
|
|
535
526
|
const client = globalThis.client;
|
|
536
527
|
if (client === undefined) {
|
|
@@ -547,11 +538,7 @@ export async function transferNativeToken(
|
|
|
547
538
|
throw new UserError('amount is not set');
|
|
548
539
|
}
|
|
549
540
|
|
|
550
|
-
const msg: EncodeObject = client.sendTokenMessage(
|
|
551
|
-
wallet,
|
|
552
|
-
amount,
|
|
553
|
-
json.recipient,
|
|
554
|
-
);
|
|
541
|
+
const msg: EncodeObject = client.sendTokenMessage(wallet, amount, json.recipient);
|
|
555
542
|
const msgs = [msg];
|
|
556
543
|
const encodeObjects: Promise<EncodeObject[]> = new Promise((resolve) => resolve(msgs));
|
|
557
544
|
|
|
@@ -582,8 +569,10 @@ export async function getAccountBalance(): Promise<String> {
|
|
|
582
569
|
}
|
|
583
570
|
const address = globalThis.wallet.address!;
|
|
584
571
|
|
|
585
|
-
const tx = await client.validatorClient.get
|
|
586
|
-
|
|
572
|
+
const tx = await client.validatorClient.get.getAccountBalance(
|
|
573
|
+
address,
|
|
574
|
+
client.validatorClient.config.denoms.USDC_DENOM,
|
|
575
|
+
);
|
|
587
576
|
return encodeJson(tx);
|
|
588
577
|
} catch (error) {
|
|
589
578
|
return wrappedError(error);
|
|
@@ -609,9 +598,7 @@ export async function getAccountBalances(): Promise<String> {
|
|
|
609
598
|
}
|
|
610
599
|
}
|
|
611
600
|
|
|
612
|
-
export async function getUserStats(
|
|
613
|
-
payload: string,
|
|
614
|
-
): Promise<String> {
|
|
601
|
+
export async function getUserStats(payload: string): Promise<String> {
|
|
615
602
|
try {
|
|
616
603
|
const client = globalThis.client;
|
|
617
604
|
if (client === undefined) {
|
|
@@ -630,9 +617,7 @@ export async function getUserStats(
|
|
|
630
617
|
}
|
|
631
618
|
}
|
|
632
619
|
|
|
633
|
-
export async function simulateDeposit(
|
|
634
|
-
payload: string,
|
|
635
|
-
): Promise<string> {
|
|
620
|
+
export async function simulateDeposit(payload: string): Promise<string> {
|
|
636
621
|
try {
|
|
637
622
|
const client = globalThis.client;
|
|
638
623
|
if (client === undefined) {
|
|
@@ -653,28 +638,20 @@ export async function simulateDeposit(
|
|
|
653
638
|
}
|
|
654
639
|
|
|
655
640
|
const subaccount = new SubaccountInfo(wallet, subaccountNumber);
|
|
656
|
-
const msg: EncodeObject = client.depositToSubaccountMessage(
|
|
657
|
-
subaccount,
|
|
658
|
-
amount,
|
|
659
|
-
);
|
|
641
|
+
const msg: EncodeObject = client.depositToSubaccountMessage(subaccount, amount);
|
|
660
642
|
const msgs: EncodeObject[] = [msg];
|
|
661
643
|
const encodeObjects: Promise<EncodeObject[]> = new Promise((resolve) => resolve(msgs));
|
|
662
644
|
|
|
663
|
-
const stdFee = await client.simulate(
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
return encodeObjects;
|
|
667
|
-
},
|
|
668
|
-
);
|
|
645
|
+
const stdFee = await client.simulate(globalThis.wallet, () => {
|
|
646
|
+
return encodeObjects;
|
|
647
|
+
});
|
|
669
648
|
return JSON.stringify(stdFee);
|
|
670
649
|
} catch (error) {
|
|
671
650
|
return wrappedError(error);
|
|
672
651
|
}
|
|
673
652
|
}
|
|
674
653
|
|
|
675
|
-
export async function simulateWithdraw(
|
|
676
|
-
payload: string,
|
|
677
|
-
): Promise<string> {
|
|
654
|
+
export async function simulateWithdraw(payload: string): Promise<string> {
|
|
678
655
|
try {
|
|
679
656
|
const client = globalThis.client;
|
|
680
657
|
if (client === undefined) {
|
|
@@ -703,21 +680,16 @@ export async function simulateWithdraw(
|
|
|
703
680
|
const msgs: EncodeObject[] = [msg];
|
|
704
681
|
const encodeObjects: Promise<EncodeObject[]> = new Promise((resolve) => resolve(msgs));
|
|
705
682
|
|
|
706
|
-
const stdFee = await client.simulate(
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
return encodeObjects;
|
|
710
|
-
},
|
|
711
|
-
);
|
|
683
|
+
const stdFee = await client.simulate(globalThis.wallet, () => {
|
|
684
|
+
return encodeObjects;
|
|
685
|
+
});
|
|
712
686
|
return encodeJson(stdFee);
|
|
713
687
|
} catch (error) {
|
|
714
688
|
return wrappedError(error);
|
|
715
689
|
}
|
|
716
690
|
}
|
|
717
691
|
|
|
718
|
-
export async function simulateTransferNativeToken(
|
|
719
|
-
payload: string,
|
|
720
|
-
): Promise<string> {
|
|
692
|
+
export async function simulateTransferNativeToken(payload: string): Promise<string> {
|
|
721
693
|
try {
|
|
722
694
|
const client = globalThis.client;
|
|
723
695
|
if (client === undefined) {
|
|
@@ -737,11 +709,7 @@ export async function simulateTransferNativeToken(
|
|
|
737
709
|
throw new UserError('amount is not set');
|
|
738
710
|
}
|
|
739
711
|
|
|
740
|
-
const msg: EncodeObject = client.sendTokenMessage(
|
|
741
|
-
wallet,
|
|
742
|
-
amount,
|
|
743
|
-
json.recipient,
|
|
744
|
-
);
|
|
712
|
+
const msg: EncodeObject = client.sendTokenMessage(wallet, amount, json.recipient);
|
|
745
713
|
const msgs: EncodeObject[] = [msg];
|
|
746
714
|
const encodeObjects: Promise<EncodeObject[]> = new Promise((resolve) => resolve(msgs));
|
|
747
715
|
|
|
@@ -800,11 +768,7 @@ export async function signRawPlaceOrder(
|
|
|
800
768
|
);
|
|
801
769
|
resolve([msg]);
|
|
802
770
|
});
|
|
803
|
-
const signed = await client.sign(
|
|
804
|
-
wallet,
|
|
805
|
-
() => msgs,
|
|
806
|
-
true,
|
|
807
|
-
);
|
|
771
|
+
const signed = await client.sign(wallet, () => msgs, true);
|
|
808
772
|
return Buffer.from(signed).toString('base64');
|
|
809
773
|
} catch (error) {
|
|
810
774
|
return wrappedError(error);
|
|
@@ -983,9 +947,7 @@ export async function getRewardsParams(): Promise<string> {
|
|
|
983
947
|
}
|
|
984
948
|
}
|
|
985
949
|
|
|
986
|
-
export async function getDelegatorDelegations(
|
|
987
|
-
payload: string,
|
|
988
|
-
): Promise<string> {
|
|
950
|
+
export async function getDelegatorDelegations(payload: string): Promise<string> {
|
|
989
951
|
try {
|
|
990
952
|
const client = globalThis.client;
|
|
991
953
|
if (client === undefined) {
|
|
@@ -996,17 +958,15 @@ export async function getDelegatorDelegations(
|
|
|
996
958
|
if (address === undefined) {
|
|
997
959
|
throw new UserError('address is not set');
|
|
998
960
|
}
|
|
999
|
-
const delegations =
|
|
1000
|
-
.client?.validatorClient.get.getDelegatorDelegations(address);
|
|
961
|
+
const delegations =
|
|
962
|
+
await globalThis.client?.validatorClient.get.getDelegatorDelegations(address);
|
|
1001
963
|
return encodeJson(delegations);
|
|
1002
964
|
} catch (e) {
|
|
1003
965
|
return wrappedError(e);
|
|
1004
966
|
}
|
|
1005
967
|
}
|
|
1006
968
|
|
|
1007
|
-
export async function getDelegatorUnbondingDelegations(
|
|
1008
|
-
payload: string,
|
|
1009
|
-
): Promise<string> {
|
|
969
|
+
export async function getDelegatorUnbondingDelegations(payload: string): Promise<string> {
|
|
1010
970
|
try {
|
|
1011
971
|
const client = globalThis.client;
|
|
1012
972
|
if (client === undefined) {
|
|
@@ -1017,17 +977,15 @@ export async function getDelegatorUnbondingDelegations(
|
|
|
1017
977
|
if (address === undefined) {
|
|
1018
978
|
throw new UserError('address is not set');
|
|
1019
979
|
}
|
|
1020
|
-
const delegations =
|
|
1021
|
-
.client?.validatorClient.get.getDelegatorUnbondingDelegations(address);
|
|
980
|
+
const delegations =
|
|
981
|
+
await globalThis.client?.validatorClient.get.getDelegatorUnbondingDelegations(address);
|
|
1022
982
|
return encodeJson(delegations);
|
|
1023
983
|
} catch (e) {
|
|
1024
984
|
return wrappedError(e);
|
|
1025
985
|
}
|
|
1026
986
|
}
|
|
1027
987
|
|
|
1028
|
-
export async function getMarketPrice(
|
|
1029
|
-
payload: string,
|
|
1030
|
-
): Promise<string> {
|
|
988
|
+
export async function getMarketPrice(payload: string): Promise<string> {
|
|
1031
989
|
try {
|
|
1032
990
|
const client = globalThis.client;
|
|
1033
991
|
if (client === undefined) {
|
|
@@ -1049,9 +1007,7 @@ export async function getNobleBalance(): Promise<String> {
|
|
|
1049
1007
|
try {
|
|
1050
1008
|
const client = globalThis.nobleClient;
|
|
1051
1009
|
if (client === undefined || !client.isConnected) {
|
|
1052
|
-
throw new UserError(
|
|
1053
|
-
'client is not connected.',
|
|
1054
|
-
);
|
|
1010
|
+
throw new UserError('client is not connected.');
|
|
1055
1011
|
}
|
|
1056
1012
|
const coin = await client.getAccountBalance('uusdc');
|
|
1057
1013
|
return encodeJson(coin);
|
|
@@ -1064,9 +1020,7 @@ export async function sendNobleIBC(squidPayload: string): Promise<String> {
|
|
|
1064
1020
|
try {
|
|
1065
1021
|
const client = globalThis.nobleClient;
|
|
1066
1022
|
if (client === undefined || !client.isConnected) {
|
|
1067
|
-
throw new UserError(
|
|
1068
|
-
'client is not connected.',
|
|
1069
|
-
);
|
|
1023
|
+
throw new UserError('client is not connected.');
|
|
1070
1024
|
}
|
|
1071
1025
|
|
|
1072
1026
|
const json: SquidIBCPayload = JSON.parse(squidPayload);
|
|
@@ -1084,13 +1038,12 @@ export async function sendNobleIBC(squidPayload: string): Promise<String> {
|
|
|
1084
1038
|
const fee = await client.simulateTransaction([ibcMsg]);
|
|
1085
1039
|
|
|
1086
1040
|
if (!ibcMsg.value.token) {
|
|
1087
|
-
throw new UserError(
|
|
1088
|
-
'Payload missing token field',
|
|
1089
|
-
);
|
|
1041
|
+
throw new UserError('Payload missing token field');
|
|
1090
1042
|
}
|
|
1091
1043
|
|
|
1092
1044
|
// take out fee from amount before sweeping
|
|
1093
|
-
const amount =
|
|
1045
|
+
const amount =
|
|
1046
|
+
parseInt(ibcMsg.value.token.amount, 10) -
|
|
1094
1047
|
Math.floor(parseInt(fee.amount[0].amount, 10) * GAS_MULTIPLIER);
|
|
1095
1048
|
|
|
1096
1049
|
if (amount <= 0) {
|
|
@@ -1119,7 +1072,7 @@ export async function withdrawToNobleIBC(payload: string): Promise<String> {
|
|
|
1119
1072
|
|
|
1120
1073
|
const { subaccountNumber, amount, ibcPayload } = json ?? {};
|
|
1121
1074
|
|
|
1122
|
-
const decode = (str: string):string => Buffer.from(str, 'base64').toString('binary');
|
|
1075
|
+
const decode = (str: string): string => Buffer.from(str, 'base64').toString('binary');
|
|
1123
1076
|
const decoded = decode(ibcPayload);
|
|
1124
1077
|
|
|
1125
1078
|
const parsedIbcPayload: SquidIBCPayload = JSON.parse(decoded);
|
|
@@ -1139,11 +1092,7 @@ export async function withdrawToNobleIBC(payload: string): Promise<String> {
|
|
|
1139
1092
|
},
|
|
1140
1093
|
};
|
|
1141
1094
|
|
|
1142
|
-
const tx = await client.send(
|
|
1143
|
-
wallet,
|
|
1144
|
-
() => Promise.resolve([msg, ibcMsg]),
|
|
1145
|
-
false,
|
|
1146
|
-
);
|
|
1095
|
+
const tx = await client.send(wallet, () => Promise.resolve([msg, ibcMsg]), false);
|
|
1147
1096
|
|
|
1148
1097
|
return encodeJson({
|
|
1149
1098
|
txHash: `0x${Buffer.from(tx?.hash).toString('hex')}`,
|
|
@@ -1157,9 +1106,7 @@ export async function cctpWithdraw(squidPayload: string): Promise<String> {
|
|
|
1157
1106
|
try {
|
|
1158
1107
|
const client = globalThis.nobleClient;
|
|
1159
1108
|
if (client === undefined || !client.isConnected) {
|
|
1160
|
-
throw new UserError(
|
|
1161
|
-
'client is not connected.',
|
|
1162
|
-
);
|
|
1109
|
+
throw new UserError('client is not connected.');
|
|
1163
1110
|
}
|
|
1164
1111
|
|
|
1165
1112
|
const json = JSON.parse(squidPayload);
|
|
@@ -1171,7 +1118,8 @@ export async function cctpWithdraw(squidPayload: string): Promise<String> {
|
|
|
1171
1118
|
const fee = await client.simulateTransaction([ibcMsg]);
|
|
1172
1119
|
|
|
1173
1120
|
// take out fee from amount before sweeping
|
|
1174
|
-
const amount =
|
|
1121
|
+
const amount =
|
|
1122
|
+
parseInt(ibcMsg.value.amount, 10) -
|
|
1175
1123
|
Math.floor(parseInt(fee.amount[0].amount, 10) * GAS_MULTIPLIER);
|
|
1176
1124
|
|
|
1177
1125
|
if (amount <= 0) {
|
|
@@ -1188,9 +1136,7 @@ export async function cctpWithdraw(squidPayload: string): Promise<String> {
|
|
|
1188
1136
|
}
|
|
1189
1137
|
}
|
|
1190
1138
|
|
|
1191
|
-
export async function getWithdrawalCapacityByDenom(
|
|
1192
|
-
payload: string,
|
|
1193
|
-
): Promise<string> {
|
|
1139
|
+
export async function getWithdrawalCapacityByDenom(payload: string): Promise<string> {
|
|
1194
1140
|
try {
|
|
1195
1141
|
const client = globalThis.client;
|
|
1196
1142
|
if (client === undefined) {
|
|
@@ -1209,8 +1155,7 @@ export async function getWithdrawalCapacityByDenom(
|
|
|
1209
1155
|
}
|
|
1210
1156
|
}
|
|
1211
1157
|
|
|
1212
|
-
export async function getWithdrawalAndTransferGatingStatus(
|
|
1213
|
-
): Promise<string> {
|
|
1158
|
+
export async function getWithdrawalAndTransferGatingStatus(): Promise<string> {
|
|
1214
1159
|
try {
|
|
1215
1160
|
const client = globalThis.client;
|
|
1216
1161
|
if (client === undefined) {
|
|
@@ -1224,9 +1169,7 @@ export async function getWithdrawalAndTransferGatingStatus(
|
|
|
1224
1169
|
}
|
|
1225
1170
|
}
|
|
1226
1171
|
|
|
1227
|
-
export async function subaccountTransfer(
|
|
1228
|
-
payload: string,
|
|
1229
|
-
): Promise<string> {
|
|
1172
|
+
export async function subaccountTransfer(payload: string): Promise<string> {
|
|
1230
1173
|
try {
|
|
1231
1174
|
const client = globalThis.client;
|
|
1232
1175
|
if (client === undefined) {
|
|
@@ -1269,3 +1212,39 @@ export async function subaccountTransfer(
|
|
|
1269
1212
|
return wrappedError(error);
|
|
1270
1213
|
}
|
|
1271
1214
|
}
|
|
1215
|
+
|
|
1216
|
+
export async function signCompliancePayload(payload: string): Promise<string> {
|
|
1217
|
+
try {
|
|
1218
|
+
const json = JSON.parse(payload);
|
|
1219
|
+
const message = json.message;
|
|
1220
|
+
if (message === undefined) {
|
|
1221
|
+
throw new UserError('message is not set');
|
|
1222
|
+
}
|
|
1223
|
+
const action = json.action;
|
|
1224
|
+
if (action === undefined) {
|
|
1225
|
+
throw new UserError('action is not set');
|
|
1226
|
+
}
|
|
1227
|
+
const currentStatus = json.status;
|
|
1228
|
+
if (currentStatus === undefined) {
|
|
1229
|
+
throw new UserError('status is not set');
|
|
1230
|
+
}
|
|
1231
|
+
if (!hdKey?.privateKey || !hdKey?.publicKey) {
|
|
1232
|
+
throw new Error('Missing hdKey');
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
const timestampInSeconds = Math.floor(Date.now() / 1000);
|
|
1236
|
+
const messageToSign: string = `${message}:${action}"${currentStatus ?? ''}:${timestampInSeconds}`;
|
|
1237
|
+
const messageHash = sha256(Buffer.from(messageToSign));
|
|
1238
|
+
|
|
1239
|
+
const signed = await Secp256k1.createSignature(messageHash, hdKey.privateKey);
|
|
1240
|
+
const signedMessage = signed.toFixedLength();
|
|
1241
|
+
|
|
1242
|
+
return encodeJson({
|
|
1243
|
+
signedMessage: Buffer.from(signedMessage).toString('base64'),
|
|
1244
|
+
publicKey: Buffer.from(hdKey.publicKey).toString('base64'),
|
|
1245
|
+
timestamp: timestampInSeconds,
|
|
1246
|
+
});
|
|
1247
|
+
} catch (error) {
|
|
1248
|
+
return wrappedError(error);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
@@ -99,11 +99,7 @@ export class NobleClient {
|
|
|
99
99
|
throw new Error('NobleClient wallet not initialized');
|
|
100
100
|
}
|
|
101
101
|
// Get simulated response
|
|
102
|
-
const gasEstimate = await this.stargateClient.simulate(
|
|
103
|
-
this.wallet?.address,
|
|
104
|
-
messages,
|
|
105
|
-
memo,
|
|
106
|
-
);
|
|
102
|
+
const gasEstimate = await this.stargateClient.simulate(this.wallet?.address, messages, memo);
|
|
107
103
|
|
|
108
104
|
// Calculate and return the fee
|
|
109
105
|
return calculateFee(Math.floor(gasEstimate * GAS_MULTIPLIER), gasPrice);
|