@nadohq/shared 0.1.0-alpha.9 → 0.1.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/dist/abis/index.cjs +12 -12
- package/dist/abis/index.cjs.map +1 -1
- package/dist/abis/index.d.cts +6 -6
- package/dist/abis/index.d.ts +6 -6
- package/dist/abis/index.js +6 -6
- package/dist/abis/index.js.map +1 -1
- package/dist/{chunk-TUJ4HQKF.js → chunk-2GPIH63F.js} +3 -3
- package/dist/chunk-2GPIH63F.js.map +1 -0
- package/dist/consts/chainEnvToChain.cjs +2 -2
- package/dist/consts/chainEnvToChain.cjs.map +1 -1
- package/dist/consts/chainEnvToChain.d.cts +345 -56
- package/dist/consts/chainEnvToChain.d.ts +345 -56
- package/dist/consts/chainEnvToChain.js +3 -3
- package/dist/consts/chainEnvToChain.js.map +1 -1
- package/dist/consts/index.d.cts +0 -1
- package/dist/consts/index.d.ts +0 -1
- package/dist/consts/productIds.cjs +1 -1
- package/dist/consts/productIds.cjs.map +1 -1
- package/dist/consts/productIds.d.cts +1 -1
- package/dist/consts/productIds.d.ts +1 -1
- package/dist/consts/productIds.js +1 -1
- package/dist/consts/productIds.js.map +1 -1
- package/dist/deployments/core/deployment.inkMainnet.json +13 -0
- package/dist/deployments/core/deployment.inkSepolia.json +13 -0
- package/dist/deployments/index.cjs +6 -6
- package/dist/deployments/index.cjs.map +1 -1
- package/dist/deployments/index.js +5 -5
- package/dist/deployments/index.js.map +1 -1
- package/dist/eip712/eip712ValueTypes.cjs.map +1 -1
- package/dist/eip712/eip712ValueTypes.d.cts +3 -3
- package/dist/eip712/eip712ValueTypes.d.ts +3 -3
- package/dist/eip712/getNadoEIP712Domain.cjs.map +1 -1
- package/dist/eip712/getNadoEIP712Domain.js.map +1 -1
- package/dist/eip712/getNadoEIP712PrimaryType.d.cts +1 -1
- package/dist/eip712/getNadoEIP712PrimaryType.d.ts +1 -1
- package/dist/eip712/getNadoEIP712Types.d.cts +1 -1
- package/dist/eip712/getNadoEIP712Types.d.ts +1 -1
- package/dist/eip712/getNadoEIP712Values.d.cts +1 -1
- package/dist/eip712/getNadoEIP712Values.d.ts +1 -1
- package/dist/eip712/getSignedTransactionRequest.d.cts +1 -1
- package/dist/eip712/getSignedTransactionRequest.d.ts +1 -1
- package/dist/eip712/index.cjs +13 -13
- package/dist/eip712/index.cjs.map +1 -1
- package/dist/eip712/index.d.cts +9 -9
- package/dist/eip712/index.d.ts +9 -9
- package/dist/eip712/index.js +6 -6
- package/dist/eip712/index.js.map +1 -1
- package/dist/eip712/orderDigest.d.cts +1 -1
- package/dist/eip712/orderDigest.d.ts +1 -1
- package/dist/eip712/signableRequestType.d.cts +1 -1
- package/dist/eip712/signableRequestType.d.ts +1 -1
- package/dist/eip712/signatureParamTypes.cjs.map +1 -1
- package/dist/eip712/signatureParamTypes.d.cts +13 -13
- package/dist/eip712/signatureParamTypes.d.ts +13 -13
- package/dist/encoding/encoding.cjs +21 -0
- package/dist/encoding/encoding.cjs.map +1 -1
- package/dist/encoding/encoding.d.cts +28 -4
- package/dist/encoding/encoding.d.ts +28 -4
- package/dist/encoding/encoding.js +24 -1
- package/dist/encoding/encoding.js.map +1 -1
- package/dist/encoding/index.d.cts +3 -3
- package/dist/encoding/index.d.ts +3 -3
- package/dist/execute/approveDepositAllowance.cjs.map +1 -1
- package/dist/execute/approveDepositAllowance.d.cts +2 -2
- package/dist/execute/approveDepositAllowance.d.ts +2 -2
- package/dist/execute/approveDepositAllowance.js.map +1 -1
- package/dist/execute/depositCollateral.cjs.map +1 -1
- package/dist/execute/depositCollateral.d.cts +2 -2
- package/dist/execute/depositCollateral.d.ts +2 -2
- package/dist/execute/depositCollateral.js.map +1 -1
- package/dist/execute/index.d.cts +1 -1
- package/dist/execute/index.d.ts +1 -1
- package/dist/index.d.cts +36 -36
- package/dist/index.d.ts +36 -36
- package/dist/types/ChainEnv.cjs +1 -1
- package/dist/types/ChainEnv.cjs.map +1 -1
- package/dist/types/ChainEnv.d.cts +2 -2
- package/dist/types/ChainEnv.d.ts +2 -2
- package/dist/types/ChainEnv.js +1 -1
- package/dist/types/ChainEnv.js.map +1 -1
- package/dist/types/balanceTypes.cjs.map +1 -1
- package/dist/types/balanceTypes.d.cts +5 -5
- package/dist/types/balanceTypes.d.ts +5 -5
- package/dist/types/healthTypes.cjs.map +1 -1
- package/dist/types/healthTypes.d.cts +4 -4
- package/dist/types/healthTypes.d.ts +4 -4
- package/dist/types/index.cjs +7 -7
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +4 -4
- package/dist/types/index.d.ts +4 -4
- package/dist/types/index.js +3 -3
- package/dist/types/index.js.map +1 -1
- package/dist/types/marketTypes.cjs.map +1 -1
- package/dist/types/marketTypes.d.cts +4 -4
- package/dist/types/marketTypes.d.ts +4 -4
- package/dist/types/orderAppendixTypes.cjs.map +1 -1
- package/dist/types/orderAppendixTypes.d.cts +27 -3
- package/dist/types/orderAppendixTypes.d.ts +27 -3
- package/dist/types/productTypes.cjs.map +1 -1
- package/dist/types/productTypes.d.cts +16 -16
- package/dist/types/productTypes.d.ts +16 -16
- package/dist/types/productTypes.js.map +1 -1
- package/dist/types/viemTypes.d.cts +1 -1
- package/dist/types/viemTypes.d.ts +1 -1
- package/dist/utils/balanceValue.cjs.map +1 -1
- package/dist/utils/balanceValue.d.cts +5 -5
- package/dist/utils/balanceValue.d.ts +5 -5
- package/dist/utils/balanceValue.js.map +1 -1
- package/dist/utils/bytes32.d.cts +1 -1
- package/dist/utils/bytes32.d.ts +1 -1
- package/dist/utils/bytes32.test.cjs +2 -2
- package/dist/utils/bytes32.test.cjs.map +1 -1
- package/dist/utils/bytes32.test.js +1 -1
- package/dist/utils/createDeterministicLinkedSignerPrivateKey.cjs.map +1 -1
- package/dist/utils/createDeterministicLinkedSignerPrivateKey.js.map +1 -1
- package/dist/utils/index.cjs +12 -12
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +22 -22
- package/dist/utils/index.d.ts +22 -22
- package/dist/utils/index.js +6 -6
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/interest.cjs +9 -9
- package/dist/utils/interest.cjs.map +1 -1
- package/dist/utils/interest.d.cts +8 -8
- package/dist/utils/interest.d.ts +8 -8
- package/dist/utils/interest.js +10 -14
- package/dist/utils/interest.js.map +1 -1
- package/dist/utils/math/{BigDecimals.cjs → BigNumbers.cjs} +13 -13
- package/dist/utils/math/BigNumbers.cjs.map +1 -0
- package/dist/utils/math/BigNumbers.d.cts +10 -0
- package/dist/utils/math/BigNumbers.d.ts +10 -0
- package/dist/utils/math/BigNumbers.js +14 -0
- package/dist/utils/math/BigNumbers.js.map +1 -0
- package/dist/utils/math/{bigDecimal.cjs → bigNumber.cjs} +12 -14
- package/dist/utils/math/bigNumber.cjs.map +1 -0
- package/dist/utils/math/bigNumber.d.cts +17 -0
- package/dist/utils/math/bigNumber.d.ts +17 -0
- package/dist/utils/math/bigNumber.js +22 -0
- package/dist/utils/math/bigNumber.js.map +1 -0
- package/dist/utils/math/clamp.cjs +3 -3
- package/dist/utils/math/clamp.cjs.map +1 -1
- package/dist/utils/math/clamp.d.cts +5 -5
- package/dist/utils/math/clamp.d.ts +5 -5
- package/dist/utils/math/clamp.js +2 -2
- package/dist/utils/math/clamp.js.map +1 -1
- package/dist/utils/math/decimalAdjustment.cjs +5 -5
- package/dist/utils/math/decimalAdjustment.cjs.map +1 -1
- package/dist/utils/math/decimalAdjustment.d.cts +6 -6
- package/dist/utils/math/decimalAdjustment.d.ts +6 -6
- package/dist/utils/math/decimalAdjustment.js +5 -5
- package/dist/utils/math/decimalAdjustment.js.map +1 -1
- package/dist/utils/math/index.cjs +10 -10
- package/dist/utils/math/index.cjs.map +1 -1
- package/dist/utils/math/index.d.cts +7 -7
- package/dist/utils/math/index.d.ts +7 -7
- package/dist/utils/math/index.js +5 -5
- package/dist/utils/math/index.js.map +1 -1
- package/dist/utils/math/{sumBigDecimalBy.cjs → sumBigNumberBy.cjs} +10 -10
- package/dist/utils/math/sumBigNumberBy.cjs.map +1 -0
- package/dist/utils/math/sumBigNumberBy.d.cts +10 -0
- package/dist/utils/math/sumBigNumberBy.d.ts +10 -0
- package/dist/utils/math/sumBigNumberBy.js +13 -0
- package/dist/utils/math/sumBigNumberBy.js.map +1 -0
- package/dist/utils/math/toBigInt.cjs.map +1 -1
- package/dist/utils/math/toBigInt.d.cts +3 -3
- package/dist/utils/math/toBigInt.d.ts +3 -3
- package/dist/utils/math/toBigInt.js.map +1 -1
- package/dist/utils/math/toIntegerString.cjs +2 -2
- package/dist/utils/math/toIntegerString.cjs.map +1 -1
- package/dist/utils/math/toIntegerString.d.cts +3 -3
- package/dist/utils/math/toIntegerString.d.ts +3 -3
- package/dist/utils/math/toIntegerString.js +2 -2
- package/dist/utils/math/toIntegerString.js.map +1 -1
- package/dist/utils/orders/appendix/appendixIsolatedValue.cjs +50 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.cjs.map +1 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.d.cts +26 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.d.ts +26 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.js +31 -0
- package/dist/utils/orders/appendix/appendixIsolatedValue.js.map +1 -0
- package/dist/utils/orders/appendix/appendixTwapValue.cjs +3 -4
- package/dist/utils/orders/appendix/appendixTwapValue.cjs.map +1 -1
- package/dist/utils/orders/appendix/appendixTwapValue.d.cts +12 -14
- package/dist/utils/orders/appendix/appendixTwapValue.d.ts +12 -14
- package/dist/utils/orders/appendix/appendixTwapValue.js +3 -4
- package/dist/utils/orders/appendix/appendixTwapValue.js.map +1 -1
- package/dist/utils/orders/appendix/index.cjs +4 -4
- package/dist/utils/orders/appendix/index.cjs.map +1 -1
- package/dist/utils/orders/appendix/index.d.cts +3 -3
- package/dist/utils/orders/appendix/index.d.ts +3 -3
- package/dist/utils/orders/appendix/index.js +2 -2
- package/dist/utils/orders/appendix/index.js.map +1 -1
- package/dist/utils/orders/appendix/orderAppendix.test.cjs +67 -14
- package/dist/utils/orders/appendix/orderAppendix.test.cjs.map +1 -1
- package/dist/utils/orders/appendix/orderAppendix.test.js +66 -13
- package/dist/utils/orders/appendix/orderAppendix.test.js.map +1 -1
- package/dist/utils/orders/appendix/packOrderAppendix.cjs +9 -5
- package/dist/utils/orders/appendix/packOrderAppendix.cjs.map +1 -1
- package/dist/utils/orders/appendix/packOrderAppendix.d.cts +1 -1
- package/dist/utils/orders/appendix/packOrderAppendix.d.ts +1 -1
- package/dist/utils/orders/appendix/packOrderAppendix.js +9 -5
- package/dist/utils/orders/appendix/packOrderAppendix.js.map +1 -1
- package/dist/utils/orders/appendix/types.cjs.map +1 -1
- package/dist/utils/orders/appendix/types.d.cts +6 -4
- package/dist/utils/orders/appendix/types.d.ts +6 -4
- package/dist/utils/orders/appendix/unpackOrderAppendix.cjs +22 -5
- package/dist/utils/orders/appendix/unpackOrderAppendix.cjs.map +1 -1
- package/dist/utils/orders/appendix/unpackOrderAppendix.d.cts +2 -2
- package/dist/utils/orders/appendix/unpackOrderAppendix.d.ts +2 -2
- package/dist/utils/orders/appendix/unpackOrderAppendix.js +22 -5
- package/dist/utils/orders/appendix/unpackOrderAppendix.js.map +1 -1
- package/dist/utils/orders/index.cjs +3 -3
- package/dist/utils/orders/index.cjs.map +1 -1
- package/dist/utils/orders/index.d.cts +5 -5
- package/dist/utils/orders/index.d.ts +5 -5
- package/dist/utils/orders/index.js +1 -1
- package/dist/utils/orders/index.js.map +1 -1
- package/dist/utils/productTypeFilter.cjs.map +1 -1
- package/dist/utils/productTypeFilter.d.cts +2 -2
- package/dist/utils/productTypeFilter.d.ts +2 -2
- package/dist/utils/productTypeFilter.js.map +1 -1
- package/dist/utils/toPrintableObject.cjs +29 -11
- package/dist/utils/toPrintableObject.cjs.map +1 -1
- package/dist/utils/toPrintableObject.d.cts +7 -2
- package/dist/utils/toPrintableObject.d.ts +7 -2
- package/dist/utils/toPrintableObject.js +19 -11
- package/dist/utils/toPrintableObject.js.map +1 -1
- package/package.json +14 -7
- package/src/abis/index.ts +6 -6
- package/src/consts/chainEnvToChain.ts +2 -2
- package/src/consts/productIds.ts +1 -1
- package/src/deployments/core/deployment.inkMainnet.json +13 -0
- package/src/deployments/core/deployment.inkSepolia.json +13 -0
- package/src/deployments/index.ts +5 -5
- package/src/eip712/eip712ValueTypes.ts +2 -2
- package/src/eip712/getNadoEIP712Domain.ts +1 -1
- package/src/eip712/index.ts +6 -6
- package/src/eip712/signatureParamTypes.ts +13 -13
- package/src/encoding/encoding.ts +43 -1
- package/src/execute/approveDepositAllowance.ts +2 -2
- package/src/execute/depositCollateral.ts +2 -2
- package/src/types/ChainEnv.ts +1 -1
- package/src/types/balanceTypes.ts +4 -4
- package/src/types/healthTypes.ts +4 -4
- package/src/types/index.ts +3 -3
- package/src/types/marketTypes.ts +4 -4
- package/src/types/orderAppendixTypes.ts +27 -2
- package/src/types/productTypes.ts +16 -16
- package/src/utils/balanceValue.ts +4 -4
- package/src/utils/createDeterministicLinkedSignerPrivateKey.ts +1 -1
- package/src/utils/index.ts +6 -6
- package/src/utils/interest.ts +26 -31
- package/src/utils/math/BigNumbers.ts +8 -0
- package/src/utils/math/bigNumber.ts +31 -0
- package/src/utils/math/clamp.ts +4 -7
- package/src/utils/math/decimalAdjustment.ts +11 -10
- package/src/utils/math/index.ts +5 -5
- package/src/utils/math/sumBigNumberBy.ts +18 -0
- package/src/utils/math/toBigInt.ts +3 -3
- package/src/utils/math/toIntegerString.ts +4 -4
- package/src/utils/orders/appendix/appendixIsolatedValue.ts +49 -0
- package/src/utils/orders/appendix/appendixTwapValue.ts +14 -19
- package/src/utils/orders/appendix/index.ts +2 -2
- package/src/utils/orders/appendix/orderAppendix.test.ts +68 -11
- package/src/utils/orders/appendix/packOrderAppendix.ts +10 -6
- package/src/utils/orders/appendix/types.ts +9 -7
- package/src/utils/orders/appendix/unpackOrderAppendix.ts +24 -7
- package/src/utils/orders/index.ts +1 -1
- package/src/utils/productTypeFilter.ts +2 -2
- package/src/utils/toPrintableObject.ts +32 -12
- package/dist/chunk-TUJ4HQKF.js.map +0 -1
- package/dist/deployments/core/deployment.InkSepolia.json +0 -13
- package/dist/deployments/core/deployment.arbitrumOne.json +0 -18
- package/dist/utils/math/BigDecimals.cjs.map +0 -1
- package/dist/utils/math/BigDecimals.d.cts +0 -8
- package/dist/utils/math/BigDecimals.d.ts +0 -8
- package/dist/utils/math/BigDecimals.js +0 -14
- package/dist/utils/math/BigDecimals.js.map +0 -1
- package/dist/utils/math/bigDecimal.cjs.map +0 -1
- package/dist/utils/math/bigDecimal.d.cts +0 -18
- package/dist/utils/math/bigDecimal.d.ts +0 -18
- package/dist/utils/math/bigDecimal.js +0 -23
- package/dist/utils/math/bigDecimal.js.map +0 -1
- package/dist/utils/math/sumBigDecimalBy.cjs.map +0 -1
- package/dist/utils/math/sumBigDecimalBy.d.cts +0 -10
- package/dist/utils/math/sumBigDecimalBy.d.ts +0 -10
- package/dist/utils/math/sumBigDecimalBy.js +0 -13
- package/dist/utils/math/sumBigDecimalBy.js.map +0 -1
- package/src/deployments/core/deployment.InkSepolia.json +0 -13
- package/src/deployments/core/deployment.arbitrumOne.json +0 -18
- package/src/utils/math/BigDecimals.ts +0 -8
- package/src/utils/math/bigDecimal.ts +0 -32
- package/src/utils/math/sumBigDecimalBy.ts +0 -18
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import { BigNumberish, toBigNumber } from './bigNumber';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* All Nado balances have 18 decimals. Ex. 1e18 = 1.0
|
|
@@ -10,10 +11,10 @@ export const NADO_PRODUCT_DECIMALS = 18;
|
|
|
10
11
|
*
|
|
11
12
|
* - If `T` is `undefined`, the result is `undefined`.
|
|
12
13
|
* - If `T` is a `number`, the result is a `number`.
|
|
13
|
-
* - Otherwise, the result is a `
|
|
14
|
+
* - Otherwise, the result is a `BigNumber`.
|
|
14
15
|
*/
|
|
15
|
-
type AdjustDecimalsResult<T extends
|
|
16
|
-
T extends undefined ? undefined : T extends number ? number :
|
|
16
|
+
type AdjustDecimalsResult<T extends BigNumberish | undefined> =
|
|
17
|
+
T extends undefined ? undefined : T extends number ? number : BigNumber;
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Adds the specified # of decimals to the number. For example, value = 1, decimals = 2, returns 100.
|
|
@@ -22,7 +23,7 @@ type AdjustDecimalsResult<T extends BigDecimalish | undefined> =
|
|
|
22
23
|
* @param decimals number of decimal places to add, defaults to 18, which is the standard within Nado
|
|
23
24
|
*/
|
|
24
25
|
|
|
25
|
-
export function addDecimals<T extends
|
|
26
|
+
export function addDecimals<T extends BigNumberish | undefined>(
|
|
26
27
|
value: T,
|
|
27
28
|
decimals: number = NADO_PRODUCT_DECIMALS,
|
|
28
29
|
): AdjustDecimalsResult<T> {
|
|
@@ -31,8 +32,8 @@ export function addDecimals<T extends BigDecimalish | undefined>(
|
|
|
31
32
|
return undefined;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
const adjustedValue =
|
|
35
|
-
|
|
35
|
+
const adjustedValue = toBigNumber(value).multipliedBy(
|
|
36
|
+
toBigNumber(10).pow(decimals),
|
|
36
37
|
);
|
|
37
38
|
return typeof value === 'number' ? adjustedValue.toNumber() : adjustedValue;
|
|
38
39
|
};
|
|
@@ -46,7 +47,7 @@ export function addDecimals<T extends BigDecimalish | undefined>(
|
|
|
46
47
|
* @param value can be undefined for better developer experience. If undefined, returns undefined.
|
|
47
48
|
* @param decimals number of decimal places to remove, defaults to 18, which is the standard within Nado
|
|
48
49
|
*/
|
|
49
|
-
export function removeDecimals<T extends
|
|
50
|
+
export function removeDecimals<T extends BigNumberish | undefined>(
|
|
50
51
|
value: T,
|
|
51
52
|
decimals: number = NADO_PRODUCT_DECIMALS,
|
|
52
53
|
): AdjustDecimalsResult<T> {
|
|
@@ -55,8 +56,8 @@ export function removeDecimals<T extends BigDecimalish | undefined>(
|
|
|
55
56
|
return undefined;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
const adjustedValue =
|
|
59
|
-
|
|
59
|
+
const adjustedValue = toBigNumber(value).dividedBy(
|
|
60
|
+
toBigNumber(10).pow(decimals),
|
|
60
61
|
);
|
|
61
62
|
return typeof value === 'number' ? adjustedValue.toNumber() : adjustedValue;
|
|
62
63
|
};
|
package/src/utils/math/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './toBigInt';
|
|
1
|
+
export * from './bigNumber';
|
|
2
|
+
export * from './BigNumbers';
|
|
4
3
|
export * from './clamp';
|
|
5
|
-
export * from './sumBigDecimalBy';
|
|
6
4
|
export * from './decimalAdjustment';
|
|
7
|
-
export * from './
|
|
5
|
+
export * from './sumBigNumberBy';
|
|
6
|
+
export * from './toBigInt';
|
|
7
|
+
export * from './toIntegerString';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
|
+
import { BigNumbers } from './BigNumbers';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Util function to sum BigNumber values, inspired by Lodash
|
|
6
|
+
* @param collection
|
|
7
|
+
* @param iteratee
|
|
8
|
+
*/
|
|
9
|
+
export function sumBigNumberBy<T>(
|
|
10
|
+
collection: T[] | null | undefined,
|
|
11
|
+
iteratee: (value: T) => BigNumber.Value,
|
|
12
|
+
): BigNumber {
|
|
13
|
+
return (
|
|
14
|
+
collection?.reduce((total, item) => {
|
|
15
|
+
return total.plus(iteratee(item));
|
|
16
|
+
}, BigNumbers.ZERO) ?? BigNumbers.ZERO
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BigNumberish } from './bigNumber';
|
|
2
2
|
import { toIntegerString } from './toIntegerString';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Converts a
|
|
5
|
+
* Converts a BigNumberish value to bigint
|
|
6
6
|
*
|
|
7
7
|
* @param val
|
|
8
8
|
*/
|
|
9
|
-
export function toBigInt(val:
|
|
9
|
+
export function toBigInt(val: BigNumberish): bigint {
|
|
10
10
|
return BigInt(toIntegerString(val));
|
|
11
11
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BigNumberish, toBigNumber } from './bigNumber';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Converts a
|
|
4
|
+
* Converts a BigNumberish value to string
|
|
5
5
|
*
|
|
6
6
|
* @param val
|
|
7
7
|
*/
|
|
8
|
-
export function toIntegerString(val:
|
|
8
|
+
export function toIntegerString(val: BigNumberish): string {
|
|
9
9
|
// toFixed is required as toString gives values with `e`
|
|
10
|
-
return
|
|
10
|
+
return toBigNumber(val).toFixed(0);
|
|
11
11
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { OrderAppendixIsolatedFields } from '../../../types';
|
|
2
|
+
import {
|
|
3
|
+
addDecimals,
|
|
4
|
+
NADO_PRODUCT_DECIMALS,
|
|
5
|
+
removeDecimals,
|
|
6
|
+
toBigInt,
|
|
7
|
+
} from '../../math';
|
|
8
|
+
import { bitMaskValue } from './bitMaskValue';
|
|
9
|
+
|
|
10
|
+
const APPENDIX_V1_ISO_MARGIN_DECIMALS = 6;
|
|
11
|
+
|
|
12
|
+
/* Appendix v1 uses x6 precision, so we need to adjust precision to/from SDK's usual precision */
|
|
13
|
+
const MARGIN_DECIMAL_ADJUSTMENT =
|
|
14
|
+
NADO_PRODUCT_DECIMALS - APPENDIX_V1_ISO_MARGIN_DECIMALS;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Packs the provided margin into a single 64-bit bigint.
|
|
18
|
+
*
|
|
19
|
+
* Bit layout (MSB → LSB):
|
|
20
|
+
* | margin_x6 |
|
|
21
|
+
* |-----------|
|
|
22
|
+
* | 63..0 |
|
|
23
|
+
* | 64 bits |
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
export function packIsolatedOrderAppendixValue({
|
|
27
|
+
margin,
|
|
28
|
+
}: OrderAppendixIsolatedFields): bigint {
|
|
29
|
+
return bitMaskValue(
|
|
30
|
+
toBigInt(removeDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),
|
|
31
|
+
64,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Unpacks a 64-bit bigint into its component fields for Isolated orders.
|
|
37
|
+
*
|
|
38
|
+
* @param value 64-bit bigint to unpack
|
|
39
|
+
* @returns Object with:
|
|
40
|
+
* - margin_x6: bigint, from bits 63..0
|
|
41
|
+
*/
|
|
42
|
+
export function unpackIsolatedOrderAppendixValue(
|
|
43
|
+
value: bigint,
|
|
44
|
+
): OrderAppendixIsolatedFields {
|
|
45
|
+
const margin = bitMaskValue(value, 64);
|
|
46
|
+
return {
|
|
47
|
+
margin: toBigInt(addDecimals(margin, MARGIN_DECIMAL_ADJUSTMENT)),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -2,17 +2,16 @@ import { OrderAppendixTwapFields } from '../../../types/orderAppendixTypes';
|
|
|
2
2
|
import { addDecimals, removeDecimals, toBigInt } from '../../math';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Packs the provided fields into a single
|
|
5
|
+
* Packs the provided fields into a single 64-bit bigint.
|
|
6
6
|
*
|
|
7
7
|
* Bit layout (MSB → LSB):
|
|
8
|
-
* | times | slippage_x6 |
|
|
9
|
-
*
|
|
10
|
-
* |
|
|
11
|
-
* | 32 bits | 32 bits |
|
|
8
|
+
* | times | slippage_x6 |
|
|
9
|
+
* |-----------|-------------|
|
|
10
|
+
* | 63..32 | 31..0 |
|
|
11
|
+
* | 32 bits | 32 bits |
|
|
12
12
|
*
|
|
13
|
-
* - `times` occupies bits
|
|
14
|
-
* - `slippage_x6` occupies bits
|
|
15
|
-
* - `reserved` occupies bits 31..0 (least significant 32 bits)
|
|
13
|
+
* - `times` occupies bits 63..32 (most significant 32 bits)
|
|
14
|
+
* - `slippage_x6` occupies bits 31..0 (least significant 32 bits)
|
|
16
15
|
*/
|
|
17
16
|
export function packTwapOrderAppendixValue({
|
|
18
17
|
numOrders,
|
|
@@ -22,27 +21,23 @@ export function packTwapOrderAppendixValue({
|
|
|
22
21
|
const slippageX6BigInt = toBigInt(addDecimals(slippageFrac, 6));
|
|
23
22
|
|
|
24
23
|
return (
|
|
25
|
-
((numOrdersBigInt & 0xffffffffn) <<
|
|
26
|
-
((slippageX6BigInt & 0xffffffffn) << 32n) |
|
|
27
|
-
// The last reserved 32 bits are set to 0
|
|
28
|
-
(0n & 0xffffffffn)
|
|
24
|
+
((numOrdersBigInt & 0xffffffffn) << 32n) | (slippageX6BigInt & 0xffffffffn)
|
|
29
25
|
);
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
/**
|
|
33
|
-
* Unpacks a
|
|
29
|
+
* Unpacks a 64-bit bigint into its component fields for TWAP orders.
|
|
34
30
|
*
|
|
35
|
-
* @param value
|
|
31
|
+
* @param value 64-bit bigint to unpack
|
|
36
32
|
* @returns Object with:
|
|
37
|
-
* - times: number, from bits
|
|
38
|
-
* - slippage_x6: number, from bits
|
|
39
|
-
* - reserved: number, from bits 31..0
|
|
33
|
+
* - times: number, from bits 63..32
|
|
34
|
+
* - slippage_x6: number, from bits 31..0
|
|
40
35
|
*/
|
|
41
36
|
export function unpackTwapOrderAppendixValue(
|
|
42
37
|
value: bigint,
|
|
43
38
|
): OrderAppendixTwapFields {
|
|
44
|
-
const numOrders = (value >>
|
|
45
|
-
const slippageX6 =
|
|
39
|
+
const numOrders = (value >> 32n) & 0xffffffffn;
|
|
40
|
+
const slippageX6 = value & 0xffffffffn;
|
|
46
41
|
|
|
47
42
|
return {
|
|
48
43
|
numOrders: Number(numOrders),
|
|
@@ -11,7 +11,7 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
11
11
|
};
|
|
12
12
|
const packed = packOrderAppendix(appendix);
|
|
13
13
|
const unpacked = unpackOrderAppendix(packed);
|
|
14
|
-
expect(packed).toBe(
|
|
14
|
+
expect(packed).toBe(4097n);
|
|
15
15
|
expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);
|
|
16
16
|
expect(unpacked.triggerType).toBe(appendix.triggerType);
|
|
17
17
|
expect(unpacked.reduceOnly).toBeFalsy();
|
|
@@ -25,7 +25,7 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
25
25
|
};
|
|
26
26
|
const packed = packOrderAppendix(appendix);
|
|
27
27
|
const unpacked = unpackOrderAppendix(packed);
|
|
28
|
-
expect(packed).toBe(
|
|
28
|
+
expect(packed).toBe(6145n);
|
|
29
29
|
expect(unpacked.reduceOnly).toBe(true);
|
|
30
30
|
});
|
|
31
31
|
|
|
@@ -60,12 +60,12 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
60
60
|
orderExecutionType: 'default',
|
|
61
61
|
triggerType: 'price',
|
|
62
62
|
|
|
63
|
-
isolated: { margin:
|
|
63
|
+
isolated: { margin: 12345678901000000000000n },
|
|
64
64
|
};
|
|
65
65
|
const packed = packOrderAppendix(appendix);
|
|
66
66
|
const unpacked = unpackOrderAppendix(packed);
|
|
67
|
-
expect(packed).toBe(
|
|
68
|
-
expect(unpacked.isolated?.margin).toBe(
|
|
67
|
+
expect(packed).toBe(227737579102942800187821658369n);
|
|
68
|
+
expect(unpacked.isolated?.margin).toBe(appendix.isolated?.margin);
|
|
69
69
|
});
|
|
70
70
|
|
|
71
71
|
it('should handle TWAP fields', () => {
|
|
@@ -77,7 +77,7 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
77
77
|
};
|
|
78
78
|
const packed = packOrderAppendix(appendix);
|
|
79
79
|
const unpacked = unpackOrderAppendix(packed);
|
|
80
|
-
expect(packed).toBe(
|
|
80
|
+
expect(packed).toBe(792281717376363744483197591553n);
|
|
81
81
|
expect(unpacked.twap).toMatchObject({ numOrders: 10, slippageFrac: 0.005 });
|
|
82
82
|
});
|
|
83
83
|
|
|
@@ -86,16 +86,16 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
86
86
|
orderExecutionType: 'post_only',
|
|
87
87
|
triggerType: undefined,
|
|
88
88
|
reduceOnly: true,
|
|
89
|
-
isolated: { margin:
|
|
89
|
+
isolated: { margin: 18446744073709551615n }, // 2^64-1
|
|
90
90
|
};
|
|
91
91
|
const packed = packOrderAppendix(appendix);
|
|
92
92
|
const unpacked = unpackOrderAppendix(packed);
|
|
93
93
|
expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);
|
|
94
94
|
expect(unpacked.triggerType).toBe(appendix.triggerType);
|
|
95
95
|
expect(unpacked.reduceOnly).toBe(appendix.reduceOnly);
|
|
96
|
-
expect(unpacked.isolated?.margin).toBe(
|
|
96
|
+
expect(unpacked.isolated?.margin).toBe(18446744000000000000n);
|
|
97
97
|
expect(unpacked.twap).toBe(undefined);
|
|
98
|
-
expect(packed).toBe(
|
|
98
|
+
expect(packed).toBe(340282365561237229015142145n);
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
it('should handle max values for all fields for TWAP orders', () => {
|
|
@@ -104,7 +104,6 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
104
104
|
triggerType: 'twap_custom_amounts',
|
|
105
105
|
reduceOnly: true,
|
|
106
106
|
twap: {
|
|
107
|
-
// max 32-bit unsigned int
|
|
108
107
|
numOrders: 4294967295,
|
|
109
108
|
slippageFrac: 0.000001,
|
|
110
109
|
},
|
|
@@ -116,6 +115,64 @@ describe('OrderAppendix packing/unpacking', () => {
|
|
|
116
115
|
expect(unpacked.reduceOnly).toBe(appendix.reduceOnly);
|
|
117
116
|
expect(unpacked.twap?.slippageFrac).toBe(0.000001);
|
|
118
117
|
expect(unpacked.twap?.numOrders).toBe(4294967295);
|
|
119
|
-
expect(packed).toBe(
|
|
118
|
+
expect(packed).toBe(340282366841710300967557013911933828609n);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should handle builder fields', () => {
|
|
122
|
+
const appendix: OrderAppendix = {
|
|
123
|
+
orderExecutionType: 'default',
|
|
124
|
+
builder: { builderId: 123, builderFeeRate: 500 },
|
|
125
|
+
};
|
|
126
|
+
const packed = packOrderAppendix(appendix);
|
|
127
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
128
|
+
expect(unpacked.builder?.builderId).toBe(123);
|
|
129
|
+
expect(unpacked.builder?.builderFeeRate).toBe(500);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should handle builder with zero fee rate', () => {
|
|
133
|
+
const appendix: OrderAppendix = {
|
|
134
|
+
orderExecutionType: 'default',
|
|
135
|
+
builder: { builderId: 42, builderFeeRate: 0 },
|
|
136
|
+
};
|
|
137
|
+
const packed = packOrderAppendix(appendix);
|
|
138
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
139
|
+
expect(unpacked.builder?.builderId).toBe(42);
|
|
140
|
+
expect(unpacked.builder?.builderFeeRate).toBe(0);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('should handle builder with max values', () => {
|
|
144
|
+
const appendix: OrderAppendix = {
|
|
145
|
+
orderExecutionType: 'default',
|
|
146
|
+
builder: { builderId: 65535, builderFeeRate: 1023 }, // 16 bits, 10 bits max
|
|
147
|
+
};
|
|
148
|
+
const packed = packOrderAppendix(appendix);
|
|
149
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
150
|
+
expect(unpacked.builder?.builderId).toBe(65535);
|
|
151
|
+
expect(unpacked.builder?.builderFeeRate).toBe(1023);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should handle builder combined with other flags', () => {
|
|
155
|
+
const appendix: OrderAppendix = {
|
|
156
|
+
orderExecutionType: 'ioc',
|
|
157
|
+
reduceOnly: true,
|
|
158
|
+
triggerType: 'price',
|
|
159
|
+
builder: { builderId: 5, builderFeeRate: 100 },
|
|
160
|
+
};
|
|
161
|
+
const packed = packOrderAppendix(appendix);
|
|
162
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
163
|
+
expect(unpacked.orderExecutionType).toBe('ioc');
|
|
164
|
+
expect(unpacked.reduceOnly).toBe(true);
|
|
165
|
+
expect(unpacked.triggerType).toBe('price');
|
|
166
|
+
expect(unpacked.builder?.builderId).toBe(5);
|
|
167
|
+
expect(unpacked.builder?.builderFeeRate).toBe(100);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('should not return builder fields when builderId is 0', () => {
|
|
171
|
+
const appendix: OrderAppendix = {
|
|
172
|
+
orderExecutionType: 'default',
|
|
173
|
+
};
|
|
174
|
+
const packed = packOrderAppendix(appendix);
|
|
175
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
176
|
+
expect(unpacked.builder).toBeUndefined();
|
|
120
177
|
});
|
|
121
178
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OrderAppendix } from '../../../types/orderAppendixTypes';
|
|
2
|
-
import {
|
|
2
|
+
import { packIsolatedOrderAppendixValue } from './appendixIsolatedValue';
|
|
3
3
|
import { packTwapOrderAppendixValue } from './appendixTwapValue';
|
|
4
4
|
import { bitMaskValue } from './bitMaskValue';
|
|
5
5
|
import { PackedOrderAppendixBits } from './types';
|
|
@@ -12,7 +12,7 @@ function mapOrderAppendixToBitValues(
|
|
|
12
12
|
return packTwapOrderAppendixValue(appendix.twap);
|
|
13
13
|
}
|
|
14
14
|
if (appendix.isolated) {
|
|
15
|
-
return
|
|
15
|
+
return packIsolatedOrderAppendixValue(appendix.isolated);
|
|
16
16
|
}
|
|
17
17
|
return 0n;
|
|
18
18
|
})();
|
|
@@ -43,12 +43,14 @@ function mapOrderAppendixToBitValues(
|
|
|
43
43
|
|
|
44
44
|
return {
|
|
45
45
|
value,
|
|
46
|
+
builderId: appendix.builder?.builderId ?? 0,
|
|
47
|
+
builderFeeRate: appendix.builder?.builderFeeRate ?? 0,
|
|
46
48
|
reserved: 0,
|
|
47
49
|
trigger,
|
|
48
50
|
reduceOnly: appendix.reduceOnly ? 1 : 0,
|
|
49
51
|
orderType,
|
|
50
52
|
isolated: appendix.isolated ? 1 : 0,
|
|
51
|
-
version:
|
|
53
|
+
version: 1,
|
|
52
54
|
};
|
|
53
55
|
}
|
|
54
56
|
|
|
@@ -59,9 +61,11 @@ function mapOrderAppendixToBitValues(
|
|
|
59
61
|
export function packOrderAppendix(appendix: OrderAppendix): bigint {
|
|
60
62
|
const bits = mapOrderAppendixToBitValues(appendix);
|
|
61
63
|
|
|
62
|
-
// Ensure value is within
|
|
63
|
-
let packed = bitMaskValue(bits.value,
|
|
64
|
-
packed = (packed <<
|
|
64
|
+
// Ensure value is within 64 bits
|
|
65
|
+
let packed = bitMaskValue(bits.value, 64);
|
|
66
|
+
packed = (packed << 16n) | bitMaskValue(bits.builderId, 16);
|
|
67
|
+
packed = (packed << 10n) | bitMaskValue(bits.builderFeeRate, 10);
|
|
68
|
+
packed = (packed << 24n) | bitMaskValue(bits.reserved, 24);
|
|
65
69
|
packed = (packed << 2n) | bitMaskValue(bits.trigger, 2);
|
|
66
70
|
packed = (packed << 1n) | bitMaskValue(bits.reduceOnly, 1);
|
|
67
71
|
packed = (packed << 2n) | bitMaskValue(bits.orderType, 2);
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Bit layout for OrderAppendix packing (MSB → LSB):
|
|
3
3
|
*
|
|
4
|
-
* | value | reserved | trigger | reduceOnly | orderType | isolated | version |
|
|
5
|
-
*
|
|
6
|
-
* | 127..
|
|
7
|
-
* |
|
|
4
|
+
* | value | builderId | builderFeeRate | reserved | trigger | reduceOnly | orderType | isolated | version |
|
|
5
|
+
* |-----------|-----------|----------------|----------|---------|------------|-----------|----------|---------|
|
|
6
|
+
* | 127..64 | 63..48 | 47..38 | 37..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |
|
|
7
|
+
* | 64 bits | 16 bits | 10 bits | 24 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |
|
|
8
8
|
*/
|
|
9
9
|
export interface PackedOrderAppendixBits {
|
|
10
|
-
value: bigint; //
|
|
11
|
-
|
|
10
|
+
value: bigint; // 64 bits
|
|
11
|
+
builderId: number; // 16 bits
|
|
12
|
+
builderFeeRate: number; // 10 bits
|
|
13
|
+
reserved: number; // 24 bits, set to 0
|
|
12
14
|
trigger: number; // 2 bits
|
|
13
15
|
reduceOnly: number; // 1 bit
|
|
14
16
|
orderType: number; // 2 bits
|
|
15
17
|
isolated: number; // 1 bit
|
|
16
|
-
version: number; // 8 bits, set to
|
|
18
|
+
version: number; // 8 bits, set to 1
|
|
17
19
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OrderAppendix } from '../../../types/orderAppendixTypes';
|
|
2
|
-
import {
|
|
2
|
+
import { BigNumberish, toBigInt } from '../../math';
|
|
3
|
+
import { unpackIsolatedOrderAppendixValue } from './appendixIsolatedValue';
|
|
3
4
|
import { unpackTwapOrderAppendixValue } from './appendixTwapValue';
|
|
4
5
|
import { bitMaskValue } from './bitMaskValue';
|
|
5
6
|
import { PackedOrderAppendixBits } from './types';
|
|
@@ -35,7 +36,7 @@ function mapBitValuesToAppendix(bits: PackedOrderAppendixBits): OrderAppendix {
|
|
|
35
36
|
})();
|
|
36
37
|
const isolatedFields = (() => {
|
|
37
38
|
if (bits.isolated) {
|
|
38
|
-
return
|
|
39
|
+
return unpackIsolatedOrderAppendixValue(bits.value);
|
|
39
40
|
}
|
|
40
41
|
return undefined;
|
|
41
42
|
})();
|
|
@@ -44,6 +45,15 @@ function mapBitValuesToAppendix(bits: PackedOrderAppendixBits): OrderAppendix {
|
|
|
44
45
|
return unpackTwapOrderAppendixValue(bits.value);
|
|
45
46
|
}
|
|
46
47
|
})();
|
|
48
|
+
const builderFields = (() => {
|
|
49
|
+
if (bits.builderId) {
|
|
50
|
+
return {
|
|
51
|
+
builderId: bits.builderId,
|
|
52
|
+
builderFeeRate: bits.builderFeeRate,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return undefined;
|
|
56
|
+
})();
|
|
47
57
|
|
|
48
58
|
return {
|
|
49
59
|
reduceOnly: !!bits.reduceOnly,
|
|
@@ -51,6 +61,7 @@ function mapBitValuesToAppendix(bits: PackedOrderAppendixBits): OrderAppendix {
|
|
|
51
61
|
triggerType,
|
|
52
62
|
isolated: isolatedFields,
|
|
53
63
|
twap: twapFields,
|
|
64
|
+
builder: builderFields,
|
|
54
65
|
};
|
|
55
66
|
}
|
|
56
67
|
|
|
@@ -58,7 +69,7 @@ function mapBitValuesToAppendix(bits: PackedOrderAppendixBits): OrderAppendix {
|
|
|
58
69
|
* Unpack the OrderAppendix fields from a packed bigint.
|
|
59
70
|
* @param packed
|
|
60
71
|
*/
|
|
61
|
-
export function unpackOrderAppendix(packed:
|
|
72
|
+
export function unpackOrderAppendix(packed: BigNumberish): OrderAppendix {
|
|
62
73
|
let temp = toBigInt(packed);
|
|
63
74
|
// Bitmasks lowest 8 bits for version
|
|
64
75
|
const version = Number(bitMaskValue(temp, 8));
|
|
@@ -73,13 +84,19 @@ export function unpackOrderAppendix(packed: BigDecimalish): OrderAppendix {
|
|
|
73
84
|
temp >>= 1n;
|
|
74
85
|
const trigger = Number(bitMaskValue(temp, 2));
|
|
75
86
|
temp >>= 2n;
|
|
76
|
-
const reserved = Number(bitMaskValue(temp,
|
|
77
|
-
temp >>=
|
|
78
|
-
|
|
79
|
-
|
|
87
|
+
const reserved = Number(bitMaskValue(temp, 24));
|
|
88
|
+
temp >>= 24n;
|
|
89
|
+
const builderFeeRate = Number(bitMaskValue(temp, 10));
|
|
90
|
+
temp >>= 10n;
|
|
91
|
+
const builderId = Number(bitMaskValue(temp, 16));
|
|
92
|
+
temp >>= 16n;
|
|
93
|
+
// The remaining bits are the value, which should be 64 bits
|
|
94
|
+
const value = bitMaskValue(temp, 64);
|
|
80
95
|
|
|
81
96
|
return mapBitValuesToAppendix({
|
|
82
97
|
value,
|
|
98
|
+
builderId,
|
|
99
|
+
builderFeeRate,
|
|
83
100
|
reserved,
|
|
84
101
|
trigger,
|
|
85
102
|
reduceOnly,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Balance, PerpBalance, SpotBalance } from '../types/balanceTypes';
|
|
2
2
|
import {
|
|
3
|
-
ProductEngineType,
|
|
4
3
|
PerpProduct,
|
|
5
|
-
SpotProduct,
|
|
6
4
|
Product,
|
|
5
|
+
ProductEngineType,
|
|
6
|
+
SpotProduct,
|
|
7
7
|
} from '../types/productTypes';
|
|
8
8
|
|
|
9
9
|
export function isSpotProduct(product: Product): product is SpotProduct {
|
|
@@ -1,25 +1,45 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Util for converting any
|
|
4
|
+
* Util for converting any BigNumber types into a string so that it can be logged nicely.
|
|
5
|
+
* Handles cyclic references by returning '[Circular]' for already-visited objects.
|
|
5
6
|
*/
|
|
6
|
-
export function toPrintableObject(
|
|
7
|
-
|
|
7
|
+
export function toPrintableObject(
|
|
8
|
+
obj: null | undefined,
|
|
9
|
+
seen?: WeakSet<object>,
|
|
10
|
+
): null;
|
|
11
|
+
export function toPrintableObject(
|
|
12
|
+
obj: BigNumber | bigint,
|
|
13
|
+
seen?: WeakSet<object>,
|
|
14
|
+
): string;
|
|
15
|
+
export function toPrintableObject(obj: unknown, seen?: WeakSet<object>): object;
|
|
16
|
+
export function toPrintableObject(obj: unknown, seen = new WeakSet()): unknown {
|
|
17
|
+
if (obj === null || obj === undefined) {
|
|
8
18
|
return null;
|
|
9
19
|
}
|
|
10
|
-
if (obj instanceof
|
|
20
|
+
if (obj instanceof BigNumber || typeof obj === 'bigint') {
|
|
11
21
|
return obj.toString();
|
|
12
22
|
}
|
|
13
23
|
if (Array.isArray(obj)) {
|
|
14
|
-
return obj.map(toPrintableObject);
|
|
24
|
+
return obj.map((item) => toPrintableObject(item, seen));
|
|
15
25
|
}
|
|
16
26
|
if (typeof obj === 'object') {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
// Detect cyclic references
|
|
28
|
+
if (seen.has(obj)) {
|
|
29
|
+
return '[Circular]';
|
|
30
|
+
}
|
|
31
|
+
seen.add(obj);
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
return Object.fromEntries(
|
|
35
|
+
Object.entries(obj).map(([key, value]) => [
|
|
36
|
+
key,
|
|
37
|
+
toPrintableObject(value, seen),
|
|
38
|
+
]),
|
|
39
|
+
);
|
|
40
|
+
} catch {
|
|
41
|
+
return { error: '[Unserializable Object]' };
|
|
42
|
+
}
|
|
23
43
|
}
|
|
24
44
|
return obj;
|
|
25
45
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../node_modules/@jest/globals/build/index.js"],"sourcesContent":["/*!\n * /**\n * * Copyright (c) Meta Platforms, Inc. and affiliates.\n * *\n * * This source code is licensed under the MIT license found in the\n * * LICENSE file in the root directory of this source tree.\n * * /\n */\n/******/ (() => { // webpackBootstrap\n/******/ \t\"use strict\";\nvar __webpack_exports__ = {};\n\n\n/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\n\nthrow new Error('Do not import `@jest/globals` outside of the Jest test environment');\nmodule.exports = __webpack_exports__;\n/******/ })()\n;"],"mappings":";;;;;AAAA;AAAA;AAAA;AAQS,KAAC,MAAM;AACN;AACV,UAAI,sBAAsB,CAAC;AAY3B,YAAM,IAAI,MAAM,oEAAoE;AACpF,aAAO,UAAU;AAAA,IACR,GAAG;AAAA;AAAA;","names":[]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"nodeUrl": "https://rpc-gel-sepolia.inkonchain.com",
|
|
3
|
-
"explorerUrl": "https://explorer-sepolia.inkonchain.com",
|
|
4
|
-
"startBlock": 27233833,
|
|
5
|
-
"deployer": "0x8177A1b5bFaAa10A4b1178c6D42aDaa4b75c8146",
|
|
6
|
-
"quote": "0x5F65358d61A9a281ea3BB930d05889ACa21E3f4f",
|
|
7
|
-
"querier": "0x5A62e748b2630560Ffe9E928780cF9Fe0e086A21",
|
|
8
|
-
"clearinghouse": "0x5E9b4336104069467E57E843033e62c79C667F8F",
|
|
9
|
-
"endpoint": "0xf8963f7860aF7DE9b94893EDb9A3b5c155e1Fc0c",
|
|
10
|
-
"spotEngine": "0x61AA7A636df5e72eBe34c70a340eB76ABB3A15bE",
|
|
11
|
-
"perpEngine": "0x3D6Ac7105cA399884739a8CC19cAdB4178844466",
|
|
12
|
-
"withdrawPool": "0xa59613a3e4ce46E20d83b0632E3D857e3f116F66"
|
|
13
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"nodeUrl": "https://arb1.arbitrum.io/rpc",
|
|
3
|
-
"explorerUrl": "https://explorer.arbitrum.io",
|
|
4
|
-
"subgraphCoreUrl": "https://api.thegraph.com/subgraphs/name/nado-protocol/nado-prod-core",
|
|
5
|
-
"subgraphMarketsUrl": "https://api.thegraph.com/subgraphs/name/nado-protocol/nado-prod-markets",
|
|
6
|
-
"subgraphCandleSticksUrl": "https://api.thegraph.com/subgraphs/name/nado-protocol/nado-prod-candlesticks",
|
|
7
|
-
"startBlock": 67108377,
|
|
8
|
-
"deployer": "0xB746472C10f9F128FF9F5029f424cC91bb1D8C3a",
|
|
9
|
-
"quote": "0xff970a61a04b1ca14834a43f5de4533ebddb5cc8",
|
|
10
|
-
"querier": "0x1693273B443699bee277eCbc60e2C8027E91995d",
|
|
11
|
-
"feeCalculator": "0x2259440579447D0625a5E28dfF3E743d207e8890",
|
|
12
|
-
"clearinghouse": "0xAE1ec28d6225dCE2ff787dcb8CE11cF6D3AE064f",
|
|
13
|
-
"clearinghouseLiq": "0xca007C51Fc14eEA88252Cc4FD71e91E44026F020",
|
|
14
|
-
"endpoint": "0xbbEE07B3e8121227AfCFe1E2B82772246226128e",
|
|
15
|
-
"spotEngine": "0x32d91Af2B17054D575A7bF1ACfa7615f41CCEfaB",
|
|
16
|
-
"perpEngine": "0xb74C78cca0FADAFBeE52B2f48A67eE8c834b5fd1",
|
|
17
|
-
"withdrawPool": "0x3567a1f8d79046A7e93Fd76d71104A978cDC6d05"
|
|
18
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/math/BigDecimals.ts"],"sourcesContent":["import { toBigDecimal } from './bigDecimal';\n\nexport const BigDecimals = Object.freeze({\n ZERO: toBigDecimal(0),\n ONE: toBigDecimal(1),\n INF: toBigDecimal(Infinity),\n MAX_I128: toBigDecimal('170141183460469231731687303715884105727'),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA6B;AAEtB,IAAM,cAAc,OAAO,OAAO;AAAA,EACvC,UAAM,gCAAa,CAAC;AAAA,EACpB,SAAK,gCAAa,CAAC;AAAA,EACnB,SAAK,gCAAa,QAAQ;AAAA,EAC1B,cAAU,gCAAa,yCAAyC;AAClE,CAAC;","names":[]}
|