@nadohq/shared 0.1.0-alpha.4
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/README.md +2 -0
- package/dist/abis/Clearinghouse.cjs +891 -0
- package/dist/abis/Clearinghouse.cjs.map +1 -0
- package/dist/abis/Clearinghouse.d.cts +669 -0
- package/dist/abis/Clearinghouse.d.ts +669 -0
- package/dist/abis/Clearinghouse.js +868 -0
- package/dist/abis/Clearinghouse.js.map +1 -0
- package/dist/abis/ERC20.cjs +215 -0
- package/dist/abis/ERC20.cjs.map +1 -0
- package/dist/abis/ERC20.d.cts +143 -0
- package/dist/abis/ERC20.d.ts +143 -0
- package/dist/abis/ERC20.js +192 -0
- package/dist/abis/ERC20.js.map +1 -0
- package/dist/abis/Endpoint.cjs +589 -0
- package/dist/abis/Endpoint.cjs.map +1 -0
- package/dist/abis/Endpoint.d.cts +433 -0
- package/dist/abis/Endpoint.d.ts +433 -0
- package/dist/abis/Endpoint.js +566 -0
- package/dist/abis/Endpoint.js.map +1 -0
- package/dist/abis/MockERC20.cjs +341 -0
- package/dist/abis/MockERC20.cjs.map +1 -0
- package/dist/abis/MockERC20.d.cts +239 -0
- package/dist/abis/MockERC20.d.ts +239 -0
- package/dist/abis/MockERC20.js +318 -0
- package/dist/abis/MockERC20.js.map +1 -0
- package/dist/abis/PerpEngine.cjs +886 -0
- package/dist/abis/PerpEngine.cjs.map +1 -0
- package/dist/abis/PerpEngine.d.cts +661 -0
- package/dist/abis/PerpEngine.d.ts +661 -0
- package/dist/abis/PerpEngine.js +863 -0
- package/dist/abis/PerpEngine.js.map +1 -0
- package/dist/abis/Querier.cjs +1522 -0
- package/dist/abis/Querier.cjs.map +1 -0
- package/dist/abis/Querier.d.cts +1149 -0
- package/dist/abis/Querier.d.ts +1149 -0
- package/dist/abis/Querier.js +1499 -0
- package/dist/abis/Querier.js.map +1 -0
- package/dist/abis/SpotEngine.cjs +937 -0
- package/dist/abis/SpotEngine.cjs.map +1 -0
- package/dist/abis/SpotEngine.d.cts +701 -0
- package/dist/abis/SpotEngine.d.ts +701 -0
- package/dist/abis/SpotEngine.js +914 -0
- package/dist/abis/SpotEngine.js.map +1 -0
- package/dist/abis/WithdrawPool.cjs +307 -0
- package/dist/abis/WithdrawPool.cjs.map +1 -0
- package/dist/abis/WithdrawPool.d.cts +214 -0
- package/dist/abis/WithdrawPool.d.ts +214 -0
- package/dist/abis/WithdrawPool.js +284 -0
- package/dist/abis/WithdrawPool.js.map +1 -0
- package/dist/abis/index.cjs +41 -0
- package/dist/abis/index.cjs.map +1 -0
- package/dist/abis/index.d.cts +9 -0
- package/dist/abis/index.d.ts +9 -0
- package/dist/abis/index.js +11 -0
- package/dist/abis/index.js.map +1 -0
- package/dist/abis/nadoAbis.cjs +44 -0
- package/dist/abis/nadoAbis.cjs.map +1 -0
- package/dist/abis/nadoAbis.d.cts +3821 -0
- package/dist/abis/nadoAbis.d.ts +3821 -0
- package/dist/abis/nadoAbis.js +21 -0
- package/dist/abis/nadoAbis.js.map +1 -0
- package/dist/chunk-5WRI5ZAA.js +31 -0
- package/dist/chunk-5WRI5ZAA.js.map +1 -0
- package/dist/chunk-TUJ4HQKF.js +33 -0
- package/dist/chunk-TUJ4HQKF.js.map +1 -0
- package/dist/consts/chainEnvToChain.cjs +44 -0
- package/dist/consts/chainEnvToChain.cjs.map +1 -0
- package/dist/consts/chainEnvToChain.d.cts +388 -0
- package/dist/consts/chainEnvToChain.d.ts +388 -0
- package/dist/consts/chainEnvToChain.js +20 -0
- package/dist/consts/chainEnvToChain.js.map +1 -0
- package/dist/consts/index.cjs +27 -0
- package/dist/consts/index.cjs.map +1 -0
- package/dist/consts/index.d.cts +6 -0
- package/dist/consts/index.d.ts +6 -0
- package/dist/consts/index.js +4 -0
- package/dist/consts/index.js.map +1 -0
- package/dist/consts/productIds.cjs +34 -0
- package/dist/consts/productIds.cjs.map +1 -0
- package/dist/consts/productIds.d.cts +4 -0
- package/dist/consts/productIds.d.ts +4 -0
- package/dist/consts/productIds.js +10 -0
- package/dist/consts/productIds.js.map +1 -0
- package/dist/deployments/core/deployment.InkSepolia.json +13 -0
- package/dist/deployments/core/deployment.arbitrumOne.json +18 -0
- package/dist/deployments/core/deployment.localhost.json +18 -0
- package/dist/deployments/index.cjs +65 -0
- package/dist/deployments/index.cjs.map +1 -0
- package/dist/deployments/index.d.cts +13 -0
- package/dist/deployments/index.d.ts +13 -0
- package/dist/deployments/index.js +32 -0
- package/dist/deployments/index.js.map +1 -0
- package/dist/eip712/eip712ValueTypes.cjs +19 -0
- package/dist/eip712/eip712ValueTypes.cjs.map +1 -0
- package/dist/eip712/eip712ValueTypes.d.cts +48 -0
- package/dist/eip712/eip712ValueTypes.d.ts +48 -0
- package/dist/eip712/eip712ValueTypes.js +1 -0
- package/dist/eip712/eip712ValueTypes.js.map +1 -0
- package/dist/eip712/getNadoEIP712Domain.cjs +39 -0
- package/dist/eip712/getNadoEIP712Domain.cjs.map +1 -0
- package/dist/eip712/getNadoEIP712Domain.d.cts +11 -0
- package/dist/eip712/getNadoEIP712Domain.d.ts +11 -0
- package/dist/eip712/getNadoEIP712Domain.js +16 -0
- package/dist/eip712/getNadoEIP712Domain.js.map +1 -0
- package/dist/eip712/getNadoEIP712PrimaryType.cjs +35 -0
- package/dist/eip712/getNadoEIP712PrimaryType.cjs.map +1 -0
- package/dist/eip712/getNadoEIP712PrimaryType.d.cts +16 -0
- package/dist/eip712/getNadoEIP712PrimaryType.d.ts +16 -0
- package/dist/eip712/getNadoEIP712PrimaryType.js +12 -0
- package/dist/eip712/getNadoEIP712PrimaryType.js.map +1 -0
- package/dist/eip712/getNadoEIP712Types.cjs +129 -0
- package/dist/eip712/getNadoEIP712Types.cjs.map +1 -0
- package/dist/eip712/getNadoEIP712Types.d.cts +20 -0
- package/dist/eip712/getNadoEIP712Types.d.ts +20 -0
- package/dist/eip712/getNadoEIP712Types.js +106 -0
- package/dist/eip712/getNadoEIP712Types.js.map +1 -0
- package/dist/eip712/getNadoEIP712Values.cjs +206 -0
- package/dist/eip712/getNadoEIP712Values.cjs.map +1 -0
- package/dist/eip712/getNadoEIP712Values.d.cts +20 -0
- package/dist/eip712/getNadoEIP712Values.d.ts +20 -0
- package/dist/eip712/getNadoEIP712Values.js +183 -0
- package/dist/eip712/getNadoEIP712Values.js.map +1 -0
- package/dist/eip712/getOrderVerifyingAddress.cjs +34 -0
- package/dist/eip712/getOrderVerifyingAddress.cjs.map +1 -0
- package/dist/eip712/getOrderVerifyingAddress.d.cts +9 -0
- package/dist/eip712/getOrderVerifyingAddress.d.ts +9 -0
- package/dist/eip712/getOrderVerifyingAddress.js +11 -0
- package/dist/eip712/getOrderVerifyingAddress.js.map +1 -0
- package/dist/eip712/getSignedTransactionRequest.cjs +42 -0
- package/dist/eip712/getSignedTransactionRequest.cjs.map +1 -0
- package/dist/eip712/getSignedTransactionRequest.d.cts +19 -0
- package/dist/eip712/getSignedTransactionRequest.d.ts +19 -0
- package/dist/eip712/getSignedTransactionRequest.js +19 -0
- package/dist/eip712/getSignedTransactionRequest.js.map +1 -0
- package/dist/eip712/index.cjs +43 -0
- package/dist/eip712/index.cjs.map +1 -0
- package/dist/eip712/index.d.cts +17 -0
- package/dist/eip712/index.d.ts +17 -0
- package/dist/eip712/index.js +12 -0
- package/dist/eip712/index.js.map +1 -0
- package/dist/eip712/orderDigest.cjs +45 -0
- package/dist/eip712/orderDigest.cjs.map +1 -0
- package/dist/eip712/orderDigest.d.cts +20 -0
- package/dist/eip712/orderDigest.d.ts +20 -0
- package/dist/eip712/orderDigest.js +22 -0
- package/dist/eip712/orderDigest.js.map +1 -0
- package/dist/eip712/signableRequestType.cjs +19 -0
- package/dist/eip712/signableRequestType.cjs.map +1 -0
- package/dist/eip712/signableRequestType.d.cts +26 -0
- package/dist/eip712/signableRequestType.d.ts +26 -0
- package/dist/eip712/signableRequestType.js +1 -0
- package/dist/eip712/signableRequestType.js.map +1 -0
- package/dist/eip712/signatureParamTypes.cjs +19 -0
- package/dist/eip712/signatureParamTypes.cjs.map +1 -0
- package/dist/eip712/signatureParamTypes.d.cts +68 -0
- package/dist/eip712/signatureParamTypes.d.ts +68 -0
- package/dist/eip712/signatureParamTypes.js +1 -0
- package/dist/eip712/signatureParamTypes.js.map +1 -0
- package/dist/encoding/encoding.cjs +73 -0
- package/dist/encoding/encoding.cjs.map +1 -0
- package/dist/encoding/encoding.d.cts +11 -0
- package/dist/encoding/encoding.d.ts +11 -0
- package/dist/encoding/encoding.js +49 -0
- package/dist/encoding/encoding.js.map +1 -0
- package/dist/encoding/index.cjs +25 -0
- package/dist/encoding/index.cjs.map +1 -0
- package/dist/encoding/index.d.cts +7 -0
- package/dist/encoding/index.d.ts +7 -0
- package/dist/encoding/index.js +3 -0
- package/dist/encoding/index.js.map +1 -0
- package/dist/execute/approveDepositAllowance.cjs +38 -0
- package/dist/execute/approveDepositAllowance.cjs.map +1 -0
- package/dist/execute/approveDepositAllowance.d.cts +18 -0
- package/dist/execute/approveDepositAllowance.d.ts +18 -0
- package/dist/execute/approveDepositAllowance.js +15 -0
- package/dist/execute/approveDepositAllowance.js.map +1 -0
- package/dist/execute/depositCollateral.cjs +59 -0
- package/dist/execute/depositCollateral.cjs.map +1 -0
- package/dist/execute/depositCollateral.d.cts +21 -0
- package/dist/execute/depositCollateral.d.ts +21 -0
- package/dist/execute/depositCollateral.js +36 -0
- package/dist/execute/depositCollateral.js.map +1 -0
- package/dist/execute/index.cjs +27 -0
- package/dist/execute/index.cjs.map +1 -0
- package/dist/execute/index.d.cts +9 -0
- package/dist/execute/index.d.ts +9 -0
- package/dist/execute/index.js +4 -0
- package/dist/execute/index.js.map +1 -0
- package/dist/index.cjs +39 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +67 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/types/ChainEnv.cjs +44 -0
- package/dist/types/ChainEnv.cjs.map +1 -0
- package/dist/types/ChainEnv.d.cts +7 -0
- package/dist/types/ChainEnv.d.ts +7 -0
- package/dist/types/ChainEnv.js +18 -0
- package/dist/types/ChainEnv.js.map +1 -0
- package/dist/types/OrderExecutionType.cjs +19 -0
- package/dist/types/OrderExecutionType.cjs.map +1 -0
- package/dist/types/OrderExecutionType.d.cts +10 -0
- package/dist/types/OrderExecutionType.d.ts +10 -0
- package/dist/types/OrderExecutionType.js +1 -0
- package/dist/types/OrderExecutionType.js.map +1 -0
- package/dist/types/balanceTypes.cjs +19 -0
- package/dist/types/balanceTypes.cjs.map +1 -0
- package/dist/types/balanceTypes.d.cts +38 -0
- package/dist/types/balanceTypes.d.ts +38 -0
- package/dist/types/balanceTypes.js +1 -0
- package/dist/types/balanceTypes.js.map +1 -0
- package/dist/types/bytes.cjs +19 -0
- package/dist/types/bytes.cjs.map +1 -0
- package/dist/types/bytes.d.cts +3 -0
- package/dist/types/bytes.d.ts +3 -0
- package/dist/types/bytes.js +1 -0
- package/dist/types/bytes.js.map +1 -0
- package/dist/types/healthTypes.cjs +19 -0
- package/dist/types/healthTypes.cjs.map +1 -0
- package/dist/types/healthTypes.d.cts +15 -0
- package/dist/types/healthTypes.d.ts +15 -0
- package/dist/types/healthTypes.js +1 -0
- package/dist/types/healthTypes.js.map +1 -0
- package/dist/types/index.cjs +45 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +15 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.js +13 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/marketTypes.cjs +19 -0
- package/dist/types/marketTypes.cjs.map +1 -0
- package/dist/types/marketTypes.d.cts +31 -0
- package/dist/types/marketTypes.d.ts +31 -0
- package/dist/types/marketTypes.js +1 -0
- package/dist/types/marketTypes.js.map +1 -0
- package/dist/types/nadoContractTypes.cjs +19 -0
- package/dist/types/nadoContractTypes.cjs.map +1 -0
- package/dist/types/nadoContractTypes.d.cts +14 -0
- package/dist/types/nadoContractTypes.d.ts +14 -0
- package/dist/types/nadoContractTypes.js +1 -0
- package/dist/types/nadoContractTypes.js.map +1 -0
- package/dist/types/orderAppendixTypes.cjs +19 -0
- package/dist/types/orderAppendixTypes.cjs.map +1 -0
- package/dist/types/orderAppendixTypes.d.cts +54 -0
- package/dist/types/orderAppendixTypes.d.ts +54 -0
- package/dist/types/orderAppendixTypes.js +1 -0
- package/dist/types/orderAppendixTypes.js.map +1 -0
- package/dist/types/productTypes.cjs +47 -0
- package/dist/types/productTypes.cjs.map +1 -0
- package/dist/types/productTypes.d.cts +55 -0
- package/dist/types/productTypes.d.ts +55 -0
- package/dist/types/productTypes.js +23 -0
- package/dist/types/productTypes.js.map +1 -0
- package/dist/types/subaccountTypes.cjs +19 -0
- package/dist/types/subaccountTypes.cjs.map +1 -0
- package/dist/types/subaccountTypes.d.cts +13 -0
- package/dist/types/subaccountTypes.d.ts +13 -0
- package/dist/types/subaccountTypes.js +1 -0
- package/dist/types/subaccountTypes.js.map +1 -0
- package/dist/types/viemTypes.cjs +19 -0
- package/dist/types/viemTypes.cjs.map +1 -0
- package/dist/types/viemTypes.d.cts +23 -0
- package/dist/types/viemTypes.d.ts +23 -0
- package/dist/types/viemTypes.js +1 -0
- package/dist/types/viemTypes.js.map +1 -0
- package/dist/utils/asyncResult.cjs +36 -0
- package/dist/utils/asyncResult.cjs.map +1 -0
- package/dist/utils/asyncResult.d.cts +4 -0
- package/dist/utils/asyncResult.d.ts +4 -0
- package/dist/utils/asyncResult.js +13 -0
- package/dist/utils/asyncResult.js.map +1 -0
- package/dist/utils/balanceValue.cjs +43 -0
- package/dist/utils/balanceValue.cjs.map +1 -0
- package/dist/utils/balanceValue.d.cts +25 -0
- package/dist/utils/balanceValue.d.ts +25 -0
- package/dist/utils/balanceValue.js +18 -0
- package/dist/utils/balanceValue.js.map +1 -0
- package/dist/utils/bytes32.cjs +92 -0
- package/dist/utils/bytes32.cjs.map +1 -0
- package/dist/utils/bytes32.d.cts +47 -0
- package/dist/utils/bytes32.d.ts +47 -0
- package/dist/utils/bytes32.js +64 -0
- package/dist/utils/bytes32.js.map +1 -0
- package/dist/utils/bytes32.test.cjs +203 -0
- package/dist/utils/bytes32.test.cjs.map +1 -0
- package/dist/utils/bytes32.test.d.cts +2 -0
- package/dist/utils/bytes32.test.d.ts +2 -0
- package/dist/utils/bytes32.test.js +165 -0
- package/dist/utils/bytes32.test.js.map +1 -0
- package/dist/utils/createDeterministicLinkedSignerPrivateKey.cjs +56 -0
- package/dist/utils/createDeterministicLinkedSignerPrivateKey.cjs.map +1 -0
- package/dist/utils/createDeterministicLinkedSignerPrivateKey.d.cts +20 -0
- package/dist/utils/createDeterministicLinkedSignerPrivateKey.d.ts +20 -0
- package/dist/utils/createDeterministicLinkedSignerPrivateKey.js +33 -0
- package/dist/utils/createDeterministicLinkedSignerPrivateKey.js.map +1 -0
- package/dist/utils/errors/WalletNotProvidedError.cjs +36 -0
- package/dist/utils/errors/WalletNotProvidedError.cjs.map +1 -0
- package/dist/utils/errors/WalletNotProvidedError.d.cts +5 -0
- package/dist/utils/errors/WalletNotProvidedError.d.ts +5 -0
- package/dist/utils/errors/WalletNotProvidedError.js +13 -0
- package/dist/utils/errors/WalletNotProvidedError.js.map +1 -0
- package/dist/utils/errors/index.cjs +25 -0
- package/dist/utils/errors/index.cjs.map +1 -0
- package/dist/utils/errors/index.d.cts +1 -0
- package/dist/utils/errors/index.d.ts +1 -0
- package/dist/utils/errors/index.js +3 -0
- package/dist/utils/errors/index.js.map +1 -0
- package/dist/utils/getValidatedAddress.cjs +37 -0
- package/dist/utils/getValidatedAddress.cjs.map +1 -0
- package/dist/utils/getValidatedAddress.d.cts +9 -0
- package/dist/utils/getValidatedAddress.d.ts +9 -0
- package/dist/utils/getValidatedAddress.js +14 -0
- package/dist/utils/getValidatedAddress.js.map +1 -0
- package/dist/utils/getValidatedHex.cjs +37 -0
- package/dist/utils/getValidatedHex.cjs.map +1 -0
- package/dist/utils/getValidatedHex.d.cts +9 -0
- package/dist/utils/getValidatedHex.d.ts +9 -0
- package/dist/utils/getValidatedHex.js +14 -0
- package/dist/utils/getValidatedHex.js.map +1 -0
- package/dist/utils/index.cjs +53 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +37 -0
- package/dist/utils/index.d.ts +37 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/interest.cjs +94 -0
- package/dist/utils/interest.cjs.map +1 -0
- package/dist/utils/interest.d.cts +50 -0
- package/dist/utils/interest.d.ts +50 -0
- package/dist/utils/interest.js +70 -0
- package/dist/utils/interest.js.map +1 -0
- package/dist/utils/isWriteableContract.cjs +33 -0
- package/dist/utils/isWriteableContract.cjs.map +1 -0
- package/dist/utils/isWriteableContract.d.cts +6 -0
- package/dist/utils/isWriteableContract.d.ts +6 -0
- package/dist/utils/isWriteableContract.js +10 -0
- package/dist/utils/isWriteableContract.js.map +1 -0
- package/dist/utils/mapValues.cjs +38 -0
- package/dist/utils/mapValues.cjs.map +1 -0
- package/dist/utils/mapValues.d.cts +6 -0
- package/dist/utils/mapValues.d.ts +6 -0
- package/dist/utils/mapValues.js +15 -0
- package/dist/utils/mapValues.js.map +1 -0
- package/dist/utils/math/BigDecimals.cjs +37 -0
- package/dist/utils/math/BigDecimals.cjs.map +1 -0
- package/dist/utils/math/BigDecimals.d.cts +8 -0
- package/dist/utils/math/BigDecimals.d.ts +8 -0
- package/dist/utils/math/BigDecimals.js +14 -0
- package/dist/utils/math/BigDecimals.js.map +1 -0
- package/dist/utils/math/bigDecimal.cjs +57 -0
- package/dist/utils/math/bigDecimal.cjs.map +1 -0
- package/dist/utils/math/bigDecimal.d.cts +18 -0
- package/dist/utils/math/bigDecimal.d.ts +18 -0
- package/dist/utils/math/bigDecimal.js +23 -0
- package/dist/utils/math/bigDecimal.js.map +1 -0
- package/dist/utils/math/clamp.cjs +38 -0
- package/dist/utils/math/clamp.cjs.map +1 -0
- package/dist/utils/math/clamp.d.cts +15 -0
- package/dist/utils/math/clamp.d.ts +15 -0
- package/dist/utils/math/clamp.js +15 -0
- package/dist/utils/math/clamp.js.map +1 -0
- package/dist/utils/math/decimalAdjustment.cjs +60 -0
- package/dist/utils/math/decimalAdjustment.cjs.map +1 -0
- package/dist/utils/math/decimalAdjustment.d.cts +31 -0
- package/dist/utils/math/decimalAdjustment.d.ts +31 -0
- package/dist/utils/math/decimalAdjustment.js +35 -0
- package/dist/utils/math/decimalAdjustment.js.map +1 -0
- package/dist/utils/math/index.cjs +37 -0
- package/dist/utils/math/index.cjs.map +1 -0
- package/dist/utils/math/index.d.cts +8 -0
- package/dist/utils/math/index.d.ts +8 -0
- package/dist/utils/math/index.js +9 -0
- package/dist/utils/math/index.js.map +1 -0
- package/dist/utils/math/sumBigDecimalBy.cjs +36 -0
- package/dist/utils/math/sumBigDecimalBy.cjs.map +1 -0
- package/dist/utils/math/sumBigDecimalBy.d.cts +10 -0
- package/dist/utils/math/sumBigDecimalBy.d.ts +10 -0
- package/dist/utils/math/sumBigDecimalBy.js +13 -0
- package/dist/utils/math/sumBigDecimalBy.js.map +1 -0
- package/dist/utils/math/toBigInt.cjs +34 -0
- package/dist/utils/math/toBigInt.cjs.map +1 -0
- package/dist/utils/math/toBigInt.d.cts +11 -0
- package/dist/utils/math/toBigInt.d.ts +11 -0
- package/dist/utils/math/toBigInt.js +11 -0
- package/dist/utils/math/toBigInt.js.map +1 -0
- package/dist/utils/math/toIntegerString.cjs +34 -0
- package/dist/utils/math/toIntegerString.cjs.map +1 -0
- package/dist/utils/math/toIntegerString.d.cts +11 -0
- package/dist/utils/math/toIntegerString.d.ts +11 -0
- package/dist/utils/math/toIntegerString.js +11 -0
- package/dist/utils/math/toIntegerString.js.map +1 -0
- package/dist/utils/orders/appendix/appendixTWAPValue.cjs +50 -0
- package/dist/utils/orders/appendix/appendixTWAPValue.cjs.map +1 -0
- package/dist/utils/orders/appendix/appendixTWAPValue.d.cts +31 -0
- package/dist/utils/orders/appendix/appendixTWAPValue.d.ts +31 -0
- package/dist/utils/orders/appendix/appendixTWAPValue.js +26 -0
- package/dist/utils/orders/appendix/appendixTWAPValue.js.map +1 -0
- package/dist/utils/orders/appendix/bitMaskValue.cjs +34 -0
- package/dist/utils/orders/appendix/bitMaskValue.cjs.map +1 -0
- package/dist/utils/orders/appendix/bitMaskValue.d.cts +10 -0
- package/dist/utils/orders/appendix/bitMaskValue.d.ts +10 -0
- package/dist/utils/orders/appendix/bitMaskValue.js +11 -0
- package/dist/utils/orders/appendix/bitMaskValue.js.map +1 -0
- package/dist/utils/orders/appendix/index.cjs +33 -0
- package/dist/utils/orders/appendix/index.cjs.map +1 -0
- package/dist/utils/orders/appendix/index.d.cts +9 -0
- package/dist/utils/orders/appendix/index.d.ts +9 -0
- package/dist/utils/orders/appendix/index.js +7 -0
- package/dist/utils/orders/appendix/index.js.map +1 -0
- package/dist/utils/orders/appendix/orderAppendix.test.cjs +165 -0
- package/dist/utils/orders/appendix/orderAppendix.test.cjs.map +1 -0
- package/dist/utils/orders/appendix/orderAppendix.test.d.cts +2 -0
- package/dist/utils/orders/appendix/orderAppendix.test.d.ts +2 -0
- package/dist/utils/orders/appendix/orderAppendix.test.js +120 -0
- package/dist/utils/orders/appendix/orderAppendix.test.js.map +1 -0
- package/dist/utils/orders/appendix/packOrderAppendix.cjs +88 -0
- package/dist/utils/orders/appendix/packOrderAppendix.cjs.map +1 -0
- package/dist/utils/orders/appendix/packOrderAppendix.d.cts +12 -0
- package/dist/utils/orders/appendix/packOrderAppendix.d.ts +12 -0
- package/dist/utils/orders/appendix/packOrderAppendix.js +65 -0
- package/dist/utils/orders/appendix/packOrderAppendix.js.map +1 -0
- package/dist/utils/orders/appendix/types.cjs +19 -0
- package/dist/utils/orders/appendix/types.cjs.map +1 -0
- package/dist/utils/orders/appendix/types.d.cts +19 -0
- package/dist/utils/orders/appendix/types.d.ts +19 -0
- package/dist/utils/orders/appendix/types.js +1 -0
- package/dist/utils/orders/appendix/types.js.map +1 -0
- package/dist/utils/orders/appendix/unpackOrderAppendix.cjs +106 -0
- package/dist/utils/orders/appendix/unpackOrderAppendix.cjs.map +1 -0
- package/dist/utils/orders/appendix/unpackOrderAppendix.d.cts +12 -0
- package/dist/utils/orders/appendix/unpackOrderAppendix.d.ts +12 -0
- package/dist/utils/orders/appendix/unpackOrderAppendix.js +83 -0
- package/dist/utils/orders/appendix/unpackOrderAppendix.js.map +1 -0
- package/dist/utils/orders/index.cjs +29 -0
- package/dist/utils/orders/index.cjs.map +1 -0
- package/dist/utils/orders/index.d.cts +11 -0
- package/dist/utils/orders/index.d.ts +11 -0
- package/dist/utils/orders/index.js +5 -0
- package/dist/utils/orders/index.js.map +1 -0
- package/dist/utils/orders/orderNonce.cjs +44 -0
- package/dist/utils/orders/orderNonce.cjs.map +1 -0
- package/dist/utils/orders/orderNonce.d.cts +14 -0
- package/dist/utils/orders/orderNonce.d.ts +14 -0
- package/dist/utils/orders/orderNonce.js +20 -0
- package/dist/utils/orders/orderNonce.js.map +1 -0
- package/dist/utils/orders/recvTime.cjs +33 -0
- package/dist/utils/orders/recvTime.cjs.map +1 -0
- package/dist/utils/orders/recvTime.d.cts +9 -0
- package/dist/utils/orders/recvTime.d.ts +9 -0
- package/dist/utils/orders/recvTime.js +10 -0
- package/dist/utils/orders/recvTime.js.map +1 -0
- package/dist/utils/productTypeFilter.cjs +49 -0
- package/dist/utils/productTypeFilter.cjs.map +1 -0
- package/dist/utils/productTypeFilter.d.cts +11 -0
- package/dist/utils/productTypeFilter.d.ts +11 -0
- package/dist/utils/productTypeFilter.js +25 -0
- package/dist/utils/productTypeFilter.js.map +1 -0
- package/dist/utils/time.cjs +47 -0
- package/dist/utils/time.cjs.map +1 -0
- package/dist/utils/time.d.cts +17 -0
- package/dist/utils/time.d.ts +17 -0
- package/dist/utils/time.js +22 -0
- package/dist/utils/time.js.map +1 -0
- package/dist/utils/toPrintableObject.cjs +51 -0
- package/dist/utils/toPrintableObject.cjs.map +1 -0
- package/dist/utils/toPrintableObject.d.cts +6 -0
- package/dist/utils/toPrintableObject.d.ts +6 -0
- package/dist/utils/toPrintableObject.js +28 -0
- package/dist/utils/toPrintableObject.js.map +1 -0
- package/package.json +49 -0
- package/src/abis/Clearinghouse.ts +861 -0
- package/src/abis/ERC20.ts +185 -0
- package/src/abis/Endpoint.ts +559 -0
- package/src/abis/MockERC20.ts +311 -0
- package/src/abis/PerpEngine.ts +856 -0
- package/src/abis/Querier.ts +1492 -0
- package/src/abis/SpotEngine.ts +907 -0
- package/src/abis/WithdrawPool.ts +277 -0
- package/src/abis/index.ts +9 -0
- package/src/abis/nadoAbis.ts +19 -0
- package/src/consts/chainEnvToChain.ts +16 -0
- package/src/consts/index.ts +2 -0
- package/src/consts/productIds.ts +3 -0
- package/src/deployments/core/deployment.InkSepolia.json +13 -0
- package/src/deployments/core/deployment.arbitrumOne.json +18 -0
- package/src/deployments/core/deployment.localhost.json +18 -0
- package/src/deployments/index.ts +40 -0
- package/src/eip712/eip712ValueTypes.ts +83 -0
- package/src/eip712/getNadoEIP712Domain.ts +20 -0
- package/src/eip712/getNadoEIP712PrimaryType.ts +13 -0
- package/src/eip712/getNadoEIP712Types.ts +113 -0
- package/src/eip712/getNadoEIP712Values.ts +248 -0
- package/src/eip712/getOrderVerifyingAddress.ts +9 -0
- package/src/eip712/getSignedTransactionRequest.ts +30 -0
- package/src/eip712/index.ts +10 -0
- package/src/eip712/orderDigest.ts +28 -0
- package/src/eip712/signableRequestType.ts +32 -0
- package/src/eip712/signatureParamTypes.ts +84 -0
- package/src/encoding/encoding.ts +50 -0
- package/src/encoding/index.ts +1 -0
- package/src/execute/approveDepositAllowance.ts +20 -0
- package/src/execute/depositCollateral.ts +43 -0
- package/src/execute/index.ts +2 -0
- package/src/index.ts +8 -0
- package/src/types/ChainEnv.ts +13 -0
- package/src/types/OrderExecutionType.ts +8 -0
- package/src/types/balanceTypes.ts +47 -0
- package/src/types/bytes.ts +1 -0
- package/src/types/healthTypes.ts +17 -0
- package/src/types/index.ts +11 -0
- package/src/types/marketTypes.ts +40 -0
- package/src/types/nadoContractTypes.ts +14 -0
- package/src/types/orderAppendixTypes.ts +58 -0
- package/src/types/productTypes.ts +76 -0
- package/src/types/subaccountTypes.ts +13 -0
- package/src/types/viemTypes.ts +42 -0
- package/src/utils/asyncResult.ts +12 -0
- package/src/utils/balanceValue.ts +42 -0
- package/src/utils/bytes32.test.ts +117 -0
- package/src/utils/bytes32.ts +110 -0
- package/src/utils/createDeterministicLinkedSignerPrivateKey.ts +46 -0
- package/src/utils/errors/WalletNotProvidedError.ts +6 -0
- package/src/utils/errors/index.ts +1 -0
- package/src/utils/getValidatedAddress.ts +13 -0
- package/src/utils/getValidatedHex.ts +13 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/interest.ts +133 -0
- package/src/utils/isWriteableContract.ts +11 -0
- package/src/utils/mapValues.ts +18 -0
- package/src/utils/math/BigDecimals.ts +8 -0
- package/src/utils/math/bigDecimal.ts +32 -0
- package/src/utils/math/clamp.ts +26 -0
- package/src/utils/math/decimalAdjustment.ts +65 -0
- package/src/utils/math/index.ts +7 -0
- package/src/utils/math/sumBigDecimalBy.ts +18 -0
- package/src/utils/math/toBigInt.ts +11 -0
- package/src/utils/math/toIntegerString.ts +11 -0
- package/src/utils/orders/appendix/appendixTWAPValue.ts +51 -0
- package/src/utils/orders/appendix/bitMaskValue.ts +11 -0
- package/src/utils/orders/appendix/index.ts +5 -0
- package/src/utils/orders/appendix/orderAppendix.test.ts +121 -0
- package/src/utils/orders/appendix/packOrderAppendix.ts +71 -0
- package/src/utils/orders/appendix/types.ts +17 -0
- package/src/utils/orders/appendix/unpackOrderAppendix.ts +90 -0
- package/src/utils/orders/index.ts +3 -0
- package/src/utils/orders/orderNonce.ts +32 -0
- package/src/utils/orders/recvTime.ts +9 -0
- package/src/utils/productTypeFilter.ts +23 -0
- package/src/utils/time.ts +21 -0
- package/src/utils/toPrintableObject.ts +25 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { SpotProduct } from '../types/productTypes';
|
|
2
|
+
import {
|
|
3
|
+
BigDecimal,
|
|
4
|
+
BigDecimalish,
|
|
5
|
+
BigDecimals,
|
|
6
|
+
removeDecimals,
|
|
7
|
+
toBigDecimal,
|
|
8
|
+
} from './math';
|
|
9
|
+
import { TimeInSeconds } from './time';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Calculate amount total borrowed for a product
|
|
13
|
+
*/
|
|
14
|
+
export function calcTotalBorrowed(
|
|
15
|
+
totalBorrowsNormalized: BigDecimalish,
|
|
16
|
+
cumulativeBorrowsMultiplierX18: BigDecimalish,
|
|
17
|
+
): BigDecimal {
|
|
18
|
+
return toBigDecimal(totalBorrowsNormalized).multipliedBy(
|
|
19
|
+
removeDecimals(cumulativeBorrowsMultiplierX18),
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Calculate amount total deposited for a product.
|
|
25
|
+
*/
|
|
26
|
+
export function calcTotalDeposited(
|
|
27
|
+
totalDepositsNormalized: BigDecimalish,
|
|
28
|
+
cumulativeDepositsMultiplierX18: BigDecimalish,
|
|
29
|
+
): BigDecimal {
|
|
30
|
+
return toBigDecimal(totalDepositsNormalized).multipliedBy(
|
|
31
|
+
removeDecimals(cumulativeDepositsMultiplierX18),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Calculates utilization ratio = abs(total borrowed / total deposited)
|
|
37
|
+
*
|
|
38
|
+
* @param product Spot product
|
|
39
|
+
*/
|
|
40
|
+
export function calcUtilizationRatio(product: SpotProduct) {
|
|
41
|
+
if (product.totalDeposited.eq(0) || product.totalBorrowed.eq(0)) {
|
|
42
|
+
return toBigDecimal(0);
|
|
43
|
+
}
|
|
44
|
+
return product.totalBorrowed.abs().div(product.totalDeposited);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Calculates per-second borrow interest rate for a product. For example, a returned rate of 0.1 indicates 10% borrower
|
|
49
|
+
* interest. The calculation for interest rate is as follows:
|
|
50
|
+
*
|
|
51
|
+
* If utilization ratio > inflection:
|
|
52
|
+
* annual rate = (1 - utilization ratio) / (1 - inflection) * interestLargeCap + interestFloor + interestSmallCap
|
|
53
|
+
*
|
|
54
|
+
* If utilization ratio < inflection:
|
|
55
|
+
* annual rate = utilization * interestSmallCap / inflection + utilization
|
|
56
|
+
*
|
|
57
|
+
* The returned rate is annual rate / 31536000 seconds per year.
|
|
58
|
+
*
|
|
59
|
+
* @param product Spot product
|
|
60
|
+
*/
|
|
61
|
+
export function calcBorrowRatePerSecond(product: SpotProduct) {
|
|
62
|
+
const {
|
|
63
|
+
interestFloor,
|
|
64
|
+
interestInflectionUtil,
|
|
65
|
+
interestSmallCap,
|
|
66
|
+
interestLargeCap,
|
|
67
|
+
} = product;
|
|
68
|
+
const utilization = calcUtilizationRatio(product);
|
|
69
|
+
if (utilization.eq(0)) {
|
|
70
|
+
return toBigDecimal(0);
|
|
71
|
+
}
|
|
72
|
+
const pastInflection = utilization.gt(interestInflectionUtil);
|
|
73
|
+
|
|
74
|
+
let annualRate: BigDecimal;
|
|
75
|
+
if (pastInflection) {
|
|
76
|
+
const utilizationTerm = interestLargeCap.times(
|
|
77
|
+
toBigDecimal(utilization)
|
|
78
|
+
.minus(interestInflectionUtil)
|
|
79
|
+
.div(BigDecimals.ONE.minus(interestInflectionUtil)),
|
|
80
|
+
);
|
|
81
|
+
annualRate = interestFloor.plus(interestSmallCap).plus(utilizationTerm);
|
|
82
|
+
} else {
|
|
83
|
+
const utilizationTerm = utilization
|
|
84
|
+
.div(interestInflectionUtil)
|
|
85
|
+
.times(interestSmallCap);
|
|
86
|
+
annualRate = interestFloor.plus(utilizationTerm);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return annualRate.div(TimeInSeconds.YEAR);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Calculates borrower interest rate compounded for a period of time.
|
|
94
|
+
*
|
|
95
|
+
* @param product Spot product
|
|
96
|
+
* @param seconds Number of seconds for the time period
|
|
97
|
+
*/
|
|
98
|
+
export function calcBorrowRateForTimeRange(
|
|
99
|
+
product: SpotProduct,
|
|
100
|
+
seconds: BigDecimalish,
|
|
101
|
+
minDepositRate: BigDecimalish,
|
|
102
|
+
) {
|
|
103
|
+
const borrowRatePerSecond = calcBorrowRatePerSecond(product);
|
|
104
|
+
|
|
105
|
+
// Convert to number for this, with some loss of precision, but using `.pow()` causes us to hit browser resource limits
|
|
106
|
+
const borrowRateForTime =
|
|
107
|
+
borrowRatePerSecond.plus(1).toNumber() ** toBigDecimal(seconds).toNumber() -
|
|
108
|
+
1;
|
|
109
|
+
return toBigDecimal(borrowRateForTime).plus(toBigDecimal(minDepositRate));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Calculate depositor interest rate compounded for a period of time.
|
|
114
|
+
*
|
|
115
|
+
* @param product Spot product
|
|
116
|
+
* @param seconds Number of seconds for the time period
|
|
117
|
+
* @param interestFeeFrac Fraction of paid borrower interest that is paid as a fee (0.2 = 20% fee)
|
|
118
|
+
*/
|
|
119
|
+
export function calcRealizedDepositRateForTimeRange(
|
|
120
|
+
product: SpotProduct,
|
|
121
|
+
seconds: BigDecimalish,
|
|
122
|
+
interestFeeFrac: BigDecimalish,
|
|
123
|
+
minDepositRate: BigDecimalish,
|
|
124
|
+
) {
|
|
125
|
+
const utilization = calcUtilizationRatio(product);
|
|
126
|
+
if (utilization.eq(0)) {
|
|
127
|
+
return toBigDecimal(0);
|
|
128
|
+
}
|
|
129
|
+
return utilization
|
|
130
|
+
.times(calcBorrowRateForTimeRange(product, seconds, toBigDecimal(0)))
|
|
131
|
+
.times(BigDecimals.ONE.minus(toBigDecimal(interestFeeFrac)))
|
|
132
|
+
.plus(toBigDecimal(minDepositRate));
|
|
133
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Abi } from 'viem';
|
|
2
|
+
import {
|
|
3
|
+
ContractInstance,
|
|
4
|
+
WriteableContractInstance,
|
|
5
|
+
} from '../types/viemTypes';
|
|
6
|
+
|
|
7
|
+
export function isWriteableContract<TAbi extends Abi>(
|
|
8
|
+
contract: ContractInstance<TAbi>,
|
|
9
|
+
): contract is WriteableContractInstance<TAbi> {
|
|
10
|
+
return 'write' in contract;
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map values of an object given mapFn. Avoids needing to pull in lodash
|
|
3
|
+
*/
|
|
4
|
+
export function mapValues<
|
|
5
|
+
TKey extends string | number | symbol,
|
|
6
|
+
TValue,
|
|
7
|
+
TNewValue,
|
|
8
|
+
>(
|
|
9
|
+
obj: Record<TKey, TValue>,
|
|
10
|
+
mapFn: (value: TValue, key: TKey, index: number) => TNewValue,
|
|
11
|
+
): Record<TKey, TNewValue> {
|
|
12
|
+
return Object.fromEntries(
|
|
13
|
+
Object.entries(obj).map(([key, value], index) => [
|
|
14
|
+
key,
|
|
15
|
+
mapFn(value as TValue, key as TKey, index),
|
|
16
|
+
]),
|
|
17
|
+
) as Record<TKey, TNewValue>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { default as BigDecimal } from 'bignumber.js';
|
|
2
|
+
|
|
3
|
+
// Renames `BigNumber` type from `bignumber.js`.
|
|
4
|
+
export { default as BigDecimal } from 'bignumber.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* BigDecimal is a renamed `BigNumber` type from `bignumber.js`.
|
|
8
|
+
* Includes valid values & instances for BigDecimal.
|
|
9
|
+
*
|
|
10
|
+
* @see https://mikemcl.github.io/bignumber.js/
|
|
11
|
+
*/
|
|
12
|
+
export type BigDecimalish = BigDecimal | BigDecimal.Value | bigint;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Converts a value to an instance of BigDecimal
|
|
16
|
+
*
|
|
17
|
+
* @param val
|
|
18
|
+
*/
|
|
19
|
+
export function toBigDecimal(val: BigDecimalish): BigDecimal {
|
|
20
|
+
const bnConstructorVal = (() => {
|
|
21
|
+
if (val instanceof BigDecimal) {
|
|
22
|
+
return val;
|
|
23
|
+
} else if (typeof val === 'string' || typeof val === 'number') {
|
|
24
|
+
return val;
|
|
25
|
+
} else if (typeof val === 'bigint') {
|
|
26
|
+
return val.toString();
|
|
27
|
+
}
|
|
28
|
+
// This is unlikely to occur, but it's here for completeness. Uses the suggestion here: https://typescript-eslint.io/rules/no-base-to-string/#alternatives
|
|
29
|
+
return JSON.stringify(val);
|
|
30
|
+
})();
|
|
31
|
+
return new BigDecimal(bnConstructorVal);
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BigDecimal } from './bigDecimal';
|
|
2
|
+
|
|
3
|
+
interface ClampOptions {
|
|
4
|
+
// Inclusive minimum value
|
|
5
|
+
min?: BigDecimal;
|
|
6
|
+
// Inclusive maximum value
|
|
7
|
+
max?: BigDecimal;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Clamps a value between optional minimum and maximum values.
|
|
12
|
+
*
|
|
13
|
+
* @param val
|
|
14
|
+
* @param opts Clamp options
|
|
15
|
+
*/
|
|
16
|
+
export function clampBigDecimal(
|
|
17
|
+
val: BigDecimal,
|
|
18
|
+
opts: ClampOptions,
|
|
19
|
+
): BigDecimal {
|
|
20
|
+
if (opts.min != null && val.lt(opts.min)) {
|
|
21
|
+
return opts.min;
|
|
22
|
+
} else if (opts.max != null && val.gt(opts.max)) {
|
|
23
|
+
return opts.max;
|
|
24
|
+
}
|
|
25
|
+
return val;
|
|
26
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { BigDecimal, BigDecimalish, toBigDecimal } from './bigDecimal';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* All Nado balances have 18 decimals. Ex. 1e18 = 1.0
|
|
5
|
+
*/
|
|
6
|
+
export const NADO_PRODUCT_DECIMALS = 18;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Determines the result type after adjusting decimals based on the input type `T`.
|
|
10
|
+
*
|
|
11
|
+
* - If `T` is `undefined`, the result is `undefined`.
|
|
12
|
+
* - If `T` is a `number`, the result is a `number`.
|
|
13
|
+
* - Otherwise, the result is a `BigDecimal`.
|
|
14
|
+
*/
|
|
15
|
+
type AdjustDecimalsResult<T extends BigDecimalish | undefined> =
|
|
16
|
+
T extends undefined ? undefined : T extends number ? number : BigDecimal;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Adds the specified # of decimals to the number. For example, value = 1, decimals = 2, returns 100.
|
|
20
|
+
*
|
|
21
|
+
* @param value can be undefined for better developer experience. If undefined, returns undefined.
|
|
22
|
+
* @param decimals number of decimal places to add, defaults to 18, which is the standard within Nado
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export function addDecimals<T extends BigDecimalish | undefined>(
|
|
26
|
+
value: T,
|
|
27
|
+
decimals: number = NADO_PRODUCT_DECIMALS,
|
|
28
|
+
): AdjustDecimalsResult<T> {
|
|
29
|
+
const getResult = () => {
|
|
30
|
+
if (value == null) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const adjustedValue = toBigDecimal(value).multipliedBy(
|
|
35
|
+
toBigDecimal(10).pow(decimals),
|
|
36
|
+
);
|
|
37
|
+
return typeof value === 'number' ? adjustedValue.toNumber() : adjustedValue;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return getResult() as AdjustDecimalsResult<T>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Removes the specified # of decimals from the number. For example, value = 100, decimals = 2, returns 1.
|
|
45
|
+
*
|
|
46
|
+
* @param value can be undefined for better developer experience. If undefined, returns undefined.
|
|
47
|
+
* @param decimals number of decimal places to remove, defaults to 18, which is the standard within Nado
|
|
48
|
+
*/
|
|
49
|
+
export function removeDecimals<T extends BigDecimalish | undefined>(
|
|
50
|
+
value: T,
|
|
51
|
+
decimals: number = NADO_PRODUCT_DECIMALS,
|
|
52
|
+
): AdjustDecimalsResult<T> {
|
|
53
|
+
const getResult = () => {
|
|
54
|
+
if (value == null) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const adjustedValue = toBigDecimal(value).dividedBy(
|
|
59
|
+
toBigDecimal(10).pow(decimals),
|
|
60
|
+
);
|
|
61
|
+
return typeof value === 'number' ? adjustedValue.toNumber() : adjustedValue;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return getResult() as AdjustDecimalsResult<T>;
|
|
65
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BigDecimal } from './bigDecimal';
|
|
2
|
+
import { BigDecimals } from './BigDecimals';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Util function to sum BigDecimal values, inspired by Lodash
|
|
6
|
+
* @param collection
|
|
7
|
+
* @param iteratee
|
|
8
|
+
*/
|
|
9
|
+
export function sumBigDecimalBy<T>(
|
|
10
|
+
collection: T[] | null | undefined,
|
|
11
|
+
iteratee: (value: T) => BigDecimal.Value,
|
|
12
|
+
): BigDecimal {
|
|
13
|
+
return (
|
|
14
|
+
collection?.reduce((total, item) => {
|
|
15
|
+
return total.plus(iteratee(item));
|
|
16
|
+
}, BigDecimals.ZERO) ?? BigDecimals.ZERO
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BigDecimalish } from './bigDecimal';
|
|
2
|
+
import { toIntegerString } from './toIntegerString';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts a BigDecimalish value to bigint
|
|
6
|
+
*
|
|
7
|
+
* @param val
|
|
8
|
+
*/
|
|
9
|
+
export function toBigInt(val: BigDecimalish): bigint {
|
|
10
|
+
return BigInt(toIntegerString(val));
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BigDecimalish, toBigDecimal } from './bigDecimal';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts a BigDecimalish value to string
|
|
5
|
+
*
|
|
6
|
+
* @param val
|
|
7
|
+
*/
|
|
8
|
+
export function toIntegerString(val: BigDecimalish): string {
|
|
9
|
+
// toFixed is required as toString gives values with `e`
|
|
10
|
+
return toBigDecimal(val).toFixed(0);
|
|
11
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { OrderAppendixTWAPFields } from '../../../types/orderAppendixTypes';
|
|
2
|
+
import { addDecimals, removeDecimals, toBigInt } from '../../math';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Packs the provided fields into a single 96-bit bigint.
|
|
6
|
+
*
|
|
7
|
+
* Bit layout (MSB → LSB):
|
|
8
|
+
* | times | slippage_x6 | reserved |
|
|
9
|
+
* |-----------|-------------|----------|
|
|
10
|
+
* | 95..64 | 63..32 | 31..0 |
|
|
11
|
+
* | 32 bits | 32 bits | 32 bits |
|
|
12
|
+
*
|
|
13
|
+
* - `times` occupies bits 95..64 (most significant 32 bits)
|
|
14
|
+
* - `slippage_x6` occupies bits 63..32 (middle 32 bits)
|
|
15
|
+
* - `reserved` occupies bits 31..0 (least significant 32 bits)
|
|
16
|
+
*/
|
|
17
|
+
export function packTWAPOrderAppendixValue({
|
|
18
|
+
numOrders,
|
|
19
|
+
slippageFrac,
|
|
20
|
+
}: OrderAppendixTWAPFields): bigint {
|
|
21
|
+
const numOrdersBigInt = toBigInt(numOrders);
|
|
22
|
+
const slippageX6BigInt = toBigInt(addDecimals(slippageFrac, 6));
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
((numOrdersBigInt & 0xffffffffn) << 64n) |
|
|
26
|
+
((slippageX6BigInt & 0xffffffffn) << 32n) |
|
|
27
|
+
// The last reserved 32 bits are set to 0
|
|
28
|
+
(0n & 0xffffffffn)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Unpacks a 96-bit bigint into its component fields for TWAP orders.
|
|
34
|
+
*
|
|
35
|
+
* @param value 96-bit bigint to unpack
|
|
36
|
+
* @returns Object with:
|
|
37
|
+
* - times: number, from bits 95..64
|
|
38
|
+
* - slippage_x6: number, from bits 63..32
|
|
39
|
+
* - reserved: number, from bits 31..0
|
|
40
|
+
*/
|
|
41
|
+
export function unpackTWAPOrderAppendixValue(
|
|
42
|
+
value: bigint,
|
|
43
|
+
): OrderAppendixTWAPFields {
|
|
44
|
+
const numOrders = (value >> 64n) & 0xffffffffn;
|
|
45
|
+
const slippageX6 = (value >> 32n) & 0xffffffffn;
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
numOrders: Number(numOrders),
|
|
49
|
+
slippageFrac: removeDecimals(slippageX6, 6).toNumber(),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the value masked to the specified bit width.
|
|
3
|
+
*
|
|
4
|
+
* @param {bigint} value - The value to be masked.
|
|
5
|
+
* @param {number} bitWidth - The bit width for masking.
|
|
6
|
+
* @returns {bigint} - The masked value.
|
|
7
|
+
*/
|
|
8
|
+
export function bitMaskValue(value: bigint | number, bitWidth: number): bigint {
|
|
9
|
+
const bitMask = (1n << BigInt(bitWidth)) - 1n;
|
|
10
|
+
return BigInt(value) & bitMask;
|
|
11
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { describe, expect, it } from '@jest/globals';
|
|
2
|
+
import { OrderAppendix, OrderExecutionType } from '../../../types';
|
|
3
|
+
import { packOrderAppendix } from './packOrderAppendix';
|
|
4
|
+
import { unpackOrderAppendix } from './unpackOrderAppendix';
|
|
5
|
+
|
|
6
|
+
describe('OrderAppendix packing/unpacking', () => {
|
|
7
|
+
it('should pack and unpack an order appendix without iso/twap values', () => {
|
|
8
|
+
const appendix: OrderAppendix = {
|
|
9
|
+
orderExecutionType: 'default',
|
|
10
|
+
triggerType: 'price',
|
|
11
|
+
};
|
|
12
|
+
const packed = packOrderAppendix(appendix);
|
|
13
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
14
|
+
expect(packed).toBe(4096n);
|
|
15
|
+
expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);
|
|
16
|
+
expect(unpacked.triggerType).toBe(appendix.triggerType);
|
|
17
|
+
expect(unpacked.reduceOnly).toBeFalsy();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should handle reduceOnly true', () => {
|
|
21
|
+
const appendix: OrderAppendix = {
|
|
22
|
+
orderExecutionType: 'default',
|
|
23
|
+
triggerType: 'price',
|
|
24
|
+
reduceOnly: true,
|
|
25
|
+
};
|
|
26
|
+
const packed = packOrderAppendix(appendix);
|
|
27
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
28
|
+
expect(packed).toBe(6144n);
|
|
29
|
+
expect(unpacked.reduceOnly).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should handle all orderExecutionType values', () => {
|
|
33
|
+
const types: OrderExecutionType[] = ['default', 'ioc', 'fok', 'post_only'];
|
|
34
|
+
for (const type of types) {
|
|
35
|
+
const appendix: OrderAppendix = {
|
|
36
|
+
orderExecutionType: type,
|
|
37
|
+
triggerType: 'price',
|
|
38
|
+
};
|
|
39
|
+
const packed = packOrderAppendix(appendix);
|
|
40
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
41
|
+
expect(unpacked.orderExecutionType).toBe(type);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should handle all triggerType values', () => {
|
|
46
|
+
const triggers = ['price', 'twap', 'twap_custom_amounts'] as const;
|
|
47
|
+
for (const trigger of triggers) {
|
|
48
|
+
const appendix: OrderAppendix = {
|
|
49
|
+
orderExecutionType: 'default',
|
|
50
|
+
triggerType: trigger,
|
|
51
|
+
};
|
|
52
|
+
const packed = packOrderAppendix(appendix);
|
|
53
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
54
|
+
expect(unpacked.triggerType).toBe(trigger);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should handle isolated margin', () => {
|
|
59
|
+
const appendix: OrderAppendix = {
|
|
60
|
+
orderExecutionType: 'default',
|
|
61
|
+
triggerType: 'price',
|
|
62
|
+
|
|
63
|
+
isolated: { margin: 123456789012345678901234n },
|
|
64
|
+
};
|
|
65
|
+
const packed = packOrderAppendix(appendix);
|
|
66
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
67
|
+
expect(packed).toBe(530242871277196831127717244047616n);
|
|
68
|
+
expect(unpacked.isolated?.margin).toBe(123456789012345678901234n);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should handle TWAP fields', () => {
|
|
72
|
+
const appendix: OrderAppendix = {
|
|
73
|
+
orderExecutionType: 'default',
|
|
74
|
+
triggerType: 'twap',
|
|
75
|
+
|
|
76
|
+
twap: { numOrders: 10, slippageFrac: 0.005 },
|
|
77
|
+
};
|
|
78
|
+
const packed = packOrderAppendix(appendix);
|
|
79
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
80
|
+
expect(packed).toBe(792281717376363744483197591552n);
|
|
81
|
+
expect(unpacked.twap).toMatchObject({ numOrders: 10, slippageFrac: 0.005 });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should handle max values for all fields for iso orders', () => {
|
|
85
|
+
const appendix: OrderAppendix = {
|
|
86
|
+
orderExecutionType: 'post_only',
|
|
87
|
+
triggerType: undefined,
|
|
88
|
+
reduceOnly: true,
|
|
89
|
+
isolated: { margin: 79228162514264337593543950335n }, // 2^96-1
|
|
90
|
+
};
|
|
91
|
+
const packed = packOrderAppendix(appendix);
|
|
92
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
93
|
+
expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);
|
|
94
|
+
expect(unpacked.triggerType).toBe(appendix.triggerType);
|
|
95
|
+
expect(unpacked.reduceOnly).toBe(appendix.reduceOnly);
|
|
96
|
+
expect(unpacked.isolated?.margin).toBe(79228162514264337593543950335n);
|
|
97
|
+
expect(unpacked.twap).toBe(undefined);
|
|
98
|
+
expect(packed).toBe(340282366920938463463374607427473248000n);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should handle max values for all fields for TWAP orders', () => {
|
|
102
|
+
const appendix: OrderAppendix = {
|
|
103
|
+
orderExecutionType: 'post_only',
|
|
104
|
+
triggerType: 'twap_custom_amounts',
|
|
105
|
+
reduceOnly: true,
|
|
106
|
+
twap: {
|
|
107
|
+
// max 32-bit unsigned int
|
|
108
|
+
numOrders: 4294967295,
|
|
109
|
+
slippageFrac: 0.000001,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
const packed = packOrderAppendix(appendix);
|
|
113
|
+
const unpacked = unpackOrderAppendix(packed);
|
|
114
|
+
expect(unpacked.orderExecutionType).toBe(appendix.orderExecutionType);
|
|
115
|
+
expect(unpacked.triggerType).toBe(appendix.triggerType);
|
|
116
|
+
expect(unpacked.reduceOnly).toBe(appendix.reduceOnly);
|
|
117
|
+
expect(unpacked.twap?.slippageFrac).toBe(0.000001);
|
|
118
|
+
expect(unpacked.twap?.numOrders).toBe(4294967295);
|
|
119
|
+
expect(packed).toBe(340282366841710300967557013911933828608n);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { OrderAppendix } from '../../../types/orderAppendixTypes';
|
|
2
|
+
import { toBigInt } from '../../math/toBigInt';
|
|
3
|
+
import { packTWAPOrderAppendixValue } from './appendixTWAPValue';
|
|
4
|
+
import { bitMaskValue } from './bitMaskValue';
|
|
5
|
+
import { PackedOrderAppendixBits } from './types';
|
|
6
|
+
|
|
7
|
+
function mapOrderAppendixToBitValues(
|
|
8
|
+
appendix: OrderAppendix,
|
|
9
|
+
): PackedOrderAppendixBits {
|
|
10
|
+
const value = (() => {
|
|
11
|
+
if (appendix.twap) {
|
|
12
|
+
return packTWAPOrderAppendixValue(appendix.twap);
|
|
13
|
+
}
|
|
14
|
+
if (appendix.isolated) {
|
|
15
|
+
return toBigInt(appendix.isolated.margin);
|
|
16
|
+
}
|
|
17
|
+
return 0n;
|
|
18
|
+
})();
|
|
19
|
+
const trigger = (() => {
|
|
20
|
+
switch (appendix.triggerType) {
|
|
21
|
+
case 'price':
|
|
22
|
+
return 1;
|
|
23
|
+
case 'twap':
|
|
24
|
+
return 2;
|
|
25
|
+
case 'twap_custom_amounts':
|
|
26
|
+
return 3;
|
|
27
|
+
default:
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
})();
|
|
31
|
+
const orderType = (() => {
|
|
32
|
+
switch (appendix.orderExecutionType) {
|
|
33
|
+
case 'default':
|
|
34
|
+
return 0;
|
|
35
|
+
case 'ioc':
|
|
36
|
+
return 1;
|
|
37
|
+
case 'fok':
|
|
38
|
+
return 2;
|
|
39
|
+
case 'post_only':
|
|
40
|
+
return 3;
|
|
41
|
+
}
|
|
42
|
+
})();
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
value,
|
|
46
|
+
reserved: 0,
|
|
47
|
+
trigger,
|
|
48
|
+
reduceOnly: appendix.reduceOnly ? 1 : 0,
|
|
49
|
+
orderType,
|
|
50
|
+
isolated: appendix.isolated ? 1 : 0,
|
|
51
|
+
version: 0,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Pack the OrderAppendix fields into a single bigint.
|
|
57
|
+
* @param appendix
|
|
58
|
+
*/
|
|
59
|
+
export function packOrderAppendix(appendix: OrderAppendix): bigint {
|
|
60
|
+
const bits = mapOrderAppendixToBitValues(appendix);
|
|
61
|
+
|
|
62
|
+
// Ensure value is within 96 bits
|
|
63
|
+
let packed = bitMaskValue(bits.value, 96);
|
|
64
|
+
packed = (packed << 18n) | bitMaskValue(bits.reserved, 18);
|
|
65
|
+
packed = (packed << 2n) | bitMaskValue(bits.trigger, 2);
|
|
66
|
+
packed = (packed << 1n) | bitMaskValue(bits.reduceOnly, 1);
|
|
67
|
+
packed = (packed << 2n) | bitMaskValue(bits.orderType, 2);
|
|
68
|
+
packed = (packed << 1n) | bitMaskValue(bits.isolated, 1);
|
|
69
|
+
packed = (packed << 8n) | bitMaskValue(bits.version, 8);
|
|
70
|
+
return packed;
|
|
71
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bit layout for OrderAppendix packing (MSB → LSB):
|
|
3
|
+
*
|
|
4
|
+
* | value | reserved | trigger | reduceOnly | orderType | isolated | version |
|
|
5
|
+
* |-----------|----------|---------|------------|-----------|----------|---------|
|
|
6
|
+
* | 127..32 | 31..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |
|
|
7
|
+
* | 96 bits | 18 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |
|
|
8
|
+
*/
|
|
9
|
+
export interface PackedOrderAppendixBits {
|
|
10
|
+
value: bigint; // 96 bits
|
|
11
|
+
reserved: number; // 18 bits, set to 0
|
|
12
|
+
trigger: number; // 2 bits
|
|
13
|
+
reduceOnly: number; // 1 bit
|
|
14
|
+
orderType: number; // 2 bits
|
|
15
|
+
isolated: number; // 1 bit
|
|
16
|
+
version: number; // 8 bits, set to 0
|
|
17
|
+
}
|