@dydxprotocol/v4-client-js 1.8.0 → 1.9.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.
- package/CHANGELOG.md +3 -3
- package/__native__/__ios__/v4-native-client.js +343 -12
- package/build/src/clients/helpers/request-helpers.d.ts +1 -0
- package/build/src/clients/helpers/request-helpers.js +53 -2
- package/build/src/clients/native.js +7 -5
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/clients/helpers/request-helpers.ts +57 -0
- package/src/clients/native.ts +7 -7
- package/webpack.config.js +2 -0
package/package.json
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import Long from "long";
|
|
2
|
+
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
4
|
export function generateQueryPath(url: string, params: {}): string {
|
|
2
5
|
const definedEntries = Object.entries(params).filter(
|
|
3
6
|
([_key, value]: [string, unknown]) => value !== undefined,
|
|
@@ -12,3 +15,57 @@ export function generateQueryPath(url: string, params: {}): string {
|
|
|
12
15
|
.join('&');
|
|
13
16
|
return `${url}?${paramsString}`;
|
|
14
17
|
}
|
|
18
|
+
|
|
19
|
+
export function parseToPrimitives<T>(x: T): T {
|
|
20
|
+
if (typeof x === 'number' || typeof x === 'string' || typeof x === 'boolean' || x === null) {
|
|
21
|
+
return x;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (Array.isArray(x)) {
|
|
25
|
+
return x.map((item) => parseToPrimitives(item)) as T;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (Long.isLong(x)) {
|
|
29
|
+
return x.toString() as T;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (x instanceof Uint8Array) {
|
|
33
|
+
return bytesToBigInt(x).toString() as T;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (x instanceof Date) {
|
|
37
|
+
return x.toString() as T;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (typeof x === 'object') {
|
|
41
|
+
const parsedObj: { [key: string]: any } = {};
|
|
42
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
43
|
+
for (const key in x) {
|
|
44
|
+
if (Object.prototype.hasOwnProperty.call(x, key)) {
|
|
45
|
+
parsedObj[key] = parseToPrimitives((x as any)[key]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return parsedObj as T;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (typeof x === 'bigint') {
|
|
52
|
+
return x.toString() as T;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw new Error(`Unsupported data type: ${typeof x}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Converts a byte array (representing an arbitrary-size signed integer) into a bigint.
|
|
60
|
+
* @param u Array of bytes represented as a Uint8Array.
|
|
61
|
+
*/
|
|
62
|
+
function bytesToBigInt(u: Uint8Array): bigint {
|
|
63
|
+
if (u.length <= 1) {
|
|
64
|
+
return BigInt(0);
|
|
65
|
+
}
|
|
66
|
+
// eslint-disable-next-line no-bitwise
|
|
67
|
+
const negated: boolean = (u[0] & 1) === 1;
|
|
68
|
+
const hex: string = Buffer.from(u.slice(1)).toString('hex');
|
|
69
|
+
const abs: bigint = BigInt(`0x${hex}`);
|
|
70
|
+
return negated ? -abs : abs;
|
|
71
|
+
}
|
package/src/clients/native.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
/*
|
|
2
3
|
Native app can call JS functions with primitives.
|
|
3
4
|
*/
|
|
@@ -30,6 +31,7 @@ import {
|
|
|
30
31
|
SelectedGasDenom,
|
|
31
32
|
} from './constants';
|
|
32
33
|
import { FaucetClient } from './faucet-client';
|
|
34
|
+
import { parseToPrimitives } from './helpers/request-helpers';
|
|
33
35
|
import { Response } from './lib/axios';
|
|
34
36
|
import LocalWallet from './modules/local-wallet';
|
|
35
37
|
import { NobleClient } from './noble-client';
|
|
@@ -1366,7 +1368,7 @@ export async function getMegavaultOwnerShares(payload: string): Promise<string>
|
|
|
1366
1368
|
}
|
|
1367
1369
|
const response =
|
|
1368
1370
|
await globalThis.client?.validatorClient.get.getMegavaultOwnerShares(address);
|
|
1369
|
-
return encodeJson(response);
|
|
1371
|
+
return encodeJson(parseToPrimitives(response));
|
|
1370
1372
|
} catch (e) {
|
|
1371
1373
|
return wrappedError(e);
|
|
1372
1374
|
}
|
|
@@ -1382,7 +1384,7 @@ export async function getMegavaultWithdrawalInfo(
|
|
|
1382
1384
|
}
|
|
1383
1385
|
const response =
|
|
1384
1386
|
await globalThis.client?.validatorClient.get.getMegavaultWithdrawalInfo(sharesToWithdraw);
|
|
1385
|
-
|
|
1387
|
+
return encodeJson(parseToPrimitives(response));
|
|
1386
1388
|
} catch (e) {
|
|
1387
1389
|
return wrappedError(e);
|
|
1388
1390
|
}
|
|
@@ -1407,7 +1409,7 @@ export async function depositToMegavault(
|
|
|
1407
1409
|
amountUsdc,
|
|
1408
1410
|
Method.BroadcastTxCommit,
|
|
1409
1411
|
);
|
|
1410
|
-
return encodeJson(tx);
|
|
1412
|
+
return encodeJson(parseToPrimitives(tx));
|
|
1411
1413
|
} catch (error) {
|
|
1412
1414
|
return wrappedError(error);
|
|
1413
1415
|
}
|
|
@@ -1434,10 +1436,8 @@ export async function withdrawFromMegavault(
|
|
|
1434
1436
|
minAmount,
|
|
1435
1437
|
Method.BroadcastTxCommit,
|
|
1436
1438
|
);
|
|
1437
|
-
return encodeJson(tx);
|
|
1439
|
+
return encodeJson(parseToPrimitives(tx));
|
|
1438
1440
|
} catch (error) {
|
|
1439
1441
|
return wrappedError(error);
|
|
1440
1442
|
}
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
|
|
1443
|
+
}
|
package/webpack.config.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
|
|
3
|
+
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
|
|
3
4
|
const webpack = require('webpack');
|
|
4
5
|
|
|
5
6
|
module.exports = {
|
|
@@ -45,5 +46,6 @@ module.exports = {
|
|
|
45
46
|
},
|
|
46
47
|
},
|
|
47
48
|
}),
|
|
49
|
+
new NodePolyfillPlugin(),
|
|
48
50
|
],
|
|
49
51
|
};
|