@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,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/utils/asyncResult.ts
|
|
21
|
+
var asyncResult_exports = {};
|
|
22
|
+
__export(asyncResult_exports, {
|
|
23
|
+
asyncResult: () => asyncResult
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(asyncResult_exports);
|
|
26
|
+
function asyncResult(promise) {
|
|
27
|
+
return Promise.resolve(promise).then(
|
|
28
|
+
(data) => [data, void 0],
|
|
29
|
+
(error) => [void 0, error]
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
asyncResult
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=asyncResult.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/asyncResult.ts"],"sourcesContent":["export type AsyncResult<TData, TError> =\n | [data: undefined, error: TError]\n | [data: TData, error: undefined];\n\nexport function asyncResult<TData, TError = unknown>(\n promise: Promise<TData>,\n): Promise<AsyncResult<TData, TError>> {\n return Promise.resolve(promise).then(\n (data) => [data, undefined] as [TData, undefined],\n (error) => [undefined, error] as [undefined, TError],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,SAAS,YACd,SACqC;AACrC,SAAO,QAAQ,QAAQ,OAAO,EAAE;AAAA,IAC9B,CAAC,SAAS,CAAC,MAAM,MAAS;AAAA,IAC1B,CAAC,UAAU,CAAC,QAAW,KAAK;AAAA,EAC9B;AACF;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "../chunk-5WRI5ZAA.js";
|
|
2
|
+
|
|
3
|
+
// src/utils/asyncResult.ts
|
|
4
|
+
function asyncResult(promise) {
|
|
5
|
+
return Promise.resolve(promise).then(
|
|
6
|
+
(data) => [data, void 0],
|
|
7
|
+
(error) => [void 0, error]
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
asyncResult
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=asyncResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/asyncResult.ts"],"sourcesContent":["export type AsyncResult<TData, TError> =\n | [data: undefined, error: TError]\n | [data: TData, error: undefined];\n\nexport function asyncResult<TData, TError = unknown>(\n promise: Promise<TData>,\n): Promise<AsyncResult<TData, TError>> {\n return Promise.resolve(promise).then(\n (data) => [data, undefined] as [TData, undefined],\n (error) => [undefined, error] as [undefined, TError],\n );\n}\n"],"mappings":";;;AAIO,SAAS,YACd,SACqC;AACrC,SAAO,QAAQ,QAAQ,OAAO,EAAE;AAAA,IAC9B,CAAC,SAAS,CAAC,MAAM,MAAS;AAAA,IAC1B,CAAC,UAAU,CAAC,QAAW,KAAK;AAAA,EAC9B;AACF;","names":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/utils/balanceValue.ts
|
|
21
|
+
var balanceValue_exports = {};
|
|
22
|
+
__export(balanceValue_exports, {
|
|
23
|
+
calcPerpBalanceNotionalValue: () => calcPerpBalanceNotionalValue,
|
|
24
|
+
calcPerpBalanceValue: () => calcPerpBalanceValue,
|
|
25
|
+
calcSpotBalanceValue: () => calcSpotBalanceValue
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(balanceValue_exports);
|
|
28
|
+
function calcSpotBalanceValue(balanceWithProduct) {
|
|
29
|
+
return balanceWithProduct.amount.multipliedBy(balanceWithProduct.oraclePrice);
|
|
30
|
+
}
|
|
31
|
+
function calcPerpBalanceNotionalValue(balanceWithProduct) {
|
|
32
|
+
return balanceWithProduct.amount.multipliedBy(balanceWithProduct.oraclePrice).abs();
|
|
33
|
+
}
|
|
34
|
+
function calcPerpBalanceValue(balanceWithProduct) {
|
|
35
|
+
return balanceWithProduct.amount.multipliedBy(balanceWithProduct.oraclePrice).plus(balanceWithProduct.vQuoteBalance);
|
|
36
|
+
}
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
calcPerpBalanceNotionalValue,
|
|
40
|
+
calcPerpBalanceValue,
|
|
41
|
+
calcSpotBalanceValue
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=balanceValue.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/balanceValue.ts"],"sourcesContent":["import {\n PerpBalanceWithProduct,\n SpotBalanceWithProduct,\n} from '../types/balanceTypes';\nimport { BigDecimal } from './math';\n\n/**\n * Calculates the quote value of a spot balance, in terms of quote units\n *\n * @param balanceWithProduct\n */\nexport function calcSpotBalanceValue(\n balanceWithProduct: SpotBalanceWithProduct,\n): BigDecimal {\n return balanceWithProduct.amount.multipliedBy(balanceWithProduct.oraclePrice);\n}\n\n/**\n * Calculates the notional value of a perp balance, in terms of quote units\n *\n * @param balanceWithProduct\n */\nexport function calcPerpBalanceNotionalValue(\n balanceWithProduct: PerpBalanceWithProduct,\n): BigDecimal {\n return balanceWithProduct.amount\n .multipliedBy(balanceWithProduct.oraclePrice)\n .abs();\n}\n\n/**\n * Calculates the true quote value of a perp balance, which is the same as its unrealized pnl / unsettled quote, in terms of quote units\n *\n * @param balanceWithProduct\n */\nexport function calcPerpBalanceValue(\n balanceWithProduct: PerpBalanceWithProduct,\n): BigDecimal {\n return balanceWithProduct.amount\n .multipliedBy(balanceWithProduct.oraclePrice)\n .plus(balanceWithProduct.vQuoteBalance);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWO,SAAS,qBACd,oBACY;AACZ,SAAO,mBAAmB,OAAO,aAAa,mBAAmB,WAAW;AAC9E;AAOO,SAAS,6BACd,oBACY;AACZ,SAAO,mBAAmB,OACvB,aAAa,mBAAmB,WAAW,EAC3C,IAAI;AACT;AAOO,SAAS,qBACd,oBACY;AACZ,SAAO,mBAAmB,OACvB,aAAa,mBAAmB,WAAW,EAC3C,KAAK,mBAAmB,aAAa;AAC1C;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SpotBalanceWithProduct, PerpBalanceWithProduct } from '../types/balanceTypes.cjs';
|
|
2
|
+
import BigDecimal from 'bignumber.js';
|
|
3
|
+
import '../types/healthTypes.cjs';
|
|
4
|
+
import '../types/productTypes.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the quote value of a spot balance, in terms of quote units
|
|
8
|
+
*
|
|
9
|
+
* @param balanceWithProduct
|
|
10
|
+
*/
|
|
11
|
+
declare function calcSpotBalanceValue(balanceWithProduct: SpotBalanceWithProduct): BigDecimal;
|
|
12
|
+
/**
|
|
13
|
+
* Calculates the notional value of a perp balance, in terms of quote units
|
|
14
|
+
*
|
|
15
|
+
* @param balanceWithProduct
|
|
16
|
+
*/
|
|
17
|
+
declare function calcPerpBalanceNotionalValue(balanceWithProduct: PerpBalanceWithProduct): BigDecimal;
|
|
18
|
+
/**
|
|
19
|
+
* Calculates the true quote value of a perp balance, which is the same as its unrealized pnl / unsettled quote, in terms of quote units
|
|
20
|
+
*
|
|
21
|
+
* @param balanceWithProduct
|
|
22
|
+
*/
|
|
23
|
+
declare function calcPerpBalanceValue(balanceWithProduct: PerpBalanceWithProduct): BigDecimal;
|
|
24
|
+
|
|
25
|
+
export { calcPerpBalanceNotionalValue, calcPerpBalanceValue, calcSpotBalanceValue };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SpotBalanceWithProduct, PerpBalanceWithProduct } from '../types/balanceTypes.js';
|
|
2
|
+
import BigDecimal from 'bignumber.js';
|
|
3
|
+
import '../types/healthTypes.js';
|
|
4
|
+
import '../types/productTypes.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Calculates the quote value of a spot balance, in terms of quote units
|
|
8
|
+
*
|
|
9
|
+
* @param balanceWithProduct
|
|
10
|
+
*/
|
|
11
|
+
declare function calcSpotBalanceValue(balanceWithProduct: SpotBalanceWithProduct): BigDecimal;
|
|
12
|
+
/**
|
|
13
|
+
* Calculates the notional value of a perp balance, in terms of quote units
|
|
14
|
+
*
|
|
15
|
+
* @param balanceWithProduct
|
|
16
|
+
*/
|
|
17
|
+
declare function calcPerpBalanceNotionalValue(balanceWithProduct: PerpBalanceWithProduct): BigDecimal;
|
|
18
|
+
/**
|
|
19
|
+
* Calculates the true quote value of a perp balance, which is the same as its unrealized pnl / unsettled quote, in terms of quote units
|
|
20
|
+
*
|
|
21
|
+
* @param balanceWithProduct
|
|
22
|
+
*/
|
|
23
|
+
declare function calcPerpBalanceValue(balanceWithProduct: PerpBalanceWithProduct): BigDecimal;
|
|
24
|
+
|
|
25
|
+
export { calcPerpBalanceNotionalValue, calcPerpBalanceValue, calcSpotBalanceValue };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "../chunk-5WRI5ZAA.js";
|
|
2
|
+
|
|
3
|
+
// src/utils/balanceValue.ts
|
|
4
|
+
function calcSpotBalanceValue(balanceWithProduct) {
|
|
5
|
+
return balanceWithProduct.amount.multipliedBy(balanceWithProduct.oraclePrice);
|
|
6
|
+
}
|
|
7
|
+
function calcPerpBalanceNotionalValue(balanceWithProduct) {
|
|
8
|
+
return balanceWithProduct.amount.multipliedBy(balanceWithProduct.oraclePrice).abs();
|
|
9
|
+
}
|
|
10
|
+
function calcPerpBalanceValue(balanceWithProduct) {
|
|
11
|
+
return balanceWithProduct.amount.multipliedBy(balanceWithProduct.oraclePrice).plus(balanceWithProduct.vQuoteBalance);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
calcPerpBalanceNotionalValue,
|
|
15
|
+
calcPerpBalanceValue,
|
|
16
|
+
calcSpotBalanceValue
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=balanceValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/balanceValue.ts"],"sourcesContent":["import {\n PerpBalanceWithProduct,\n SpotBalanceWithProduct,\n} from '../types/balanceTypes';\nimport { BigDecimal } from './math';\n\n/**\n * Calculates the quote value of a spot balance, in terms of quote units\n *\n * @param balanceWithProduct\n */\nexport function calcSpotBalanceValue(\n balanceWithProduct: SpotBalanceWithProduct,\n): BigDecimal {\n return balanceWithProduct.amount.multipliedBy(balanceWithProduct.oraclePrice);\n}\n\n/**\n * Calculates the notional value of a perp balance, in terms of quote units\n *\n * @param balanceWithProduct\n */\nexport function calcPerpBalanceNotionalValue(\n balanceWithProduct: PerpBalanceWithProduct,\n): BigDecimal {\n return balanceWithProduct.amount\n .multipliedBy(balanceWithProduct.oraclePrice)\n .abs();\n}\n\n/**\n * Calculates the true quote value of a perp balance, which is the same as its unrealized pnl / unsettled quote, in terms of quote units\n *\n * @param balanceWithProduct\n */\nexport function calcPerpBalanceValue(\n balanceWithProduct: PerpBalanceWithProduct,\n): BigDecimal {\n return balanceWithProduct.amount\n .multipliedBy(balanceWithProduct.oraclePrice)\n .plus(balanceWithProduct.vQuoteBalance);\n}\n"],"mappings":";;;AAWO,SAAS,qBACd,oBACY;AACZ,SAAO,mBAAmB,OAAO,aAAa,mBAAmB,WAAW;AAC9E;AAOO,SAAS,6BACd,oBACY;AACZ,SAAO,mBAAmB,OACvB,aAAa,mBAAmB,WAAW,EAC3C,IAAI;AACT;AAOO,SAAS,qBACd,oBACY;AACZ,SAAO,mBAAmB,OACvB,aAAa,mBAAmB,WAAW,EAC3C,KAAK,mBAAmB,aAAa;AAC1C;","names":[]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/utils/bytes32.ts
|
|
21
|
+
var bytes32_exports = {};
|
|
22
|
+
__export(bytes32_exports, {
|
|
23
|
+
subaccountFromBytes32: () => subaccountFromBytes32,
|
|
24
|
+
subaccountFromHex: () => subaccountFromHex,
|
|
25
|
+
subaccountNameBytesToStr: () => subaccountNameBytesToStr,
|
|
26
|
+
subaccountNameToBytes12: () => subaccountNameToBytes12,
|
|
27
|
+
subaccountToBytes32: () => subaccountToBytes32,
|
|
28
|
+
subaccountToHex: () => subaccountToHex
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(bytes32_exports);
|
|
31
|
+
var import_viem = require("viem");
|
|
32
|
+
function subaccountToBytes32(subaccount) {
|
|
33
|
+
const address = (0, import_viem.toBytes)(subaccount.subaccountOwner);
|
|
34
|
+
if (address.length != 20) {
|
|
35
|
+
throw new Error(`owner must be 20 bytes, but found ${address.length}`);
|
|
36
|
+
}
|
|
37
|
+
const nameBytes = subaccountNameToBytes12(subaccount.subaccountName);
|
|
38
|
+
const bytes32 = new Uint8Array(32);
|
|
39
|
+
for (let i = 0; i < address.length; i++) {
|
|
40
|
+
bytes32[i] = address[i];
|
|
41
|
+
}
|
|
42
|
+
for (let i = 0; i < nameBytes.length; i++) {
|
|
43
|
+
bytes32[i + 20] = nameBytes[i];
|
|
44
|
+
}
|
|
45
|
+
return bytes32;
|
|
46
|
+
}
|
|
47
|
+
function subaccountFromBytes32(bytes) {
|
|
48
|
+
if (bytes.length != 32) {
|
|
49
|
+
throw new Error("input must be 32 bytes");
|
|
50
|
+
}
|
|
51
|
+
const address = new Uint8Array(20);
|
|
52
|
+
const name = new Uint8Array(12);
|
|
53
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
54
|
+
if (i < 20) {
|
|
55
|
+
address[i] = bytes[i];
|
|
56
|
+
} else {
|
|
57
|
+
name[i - 20] = bytes[i];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
subaccountOwner: (0, import_viem.toHex)(address),
|
|
62
|
+
subaccountName: subaccountNameBytesToStr(name)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function subaccountNameToBytes12(name) {
|
|
66
|
+
return (0, import_viem.toBytes)(name, {
|
|
67
|
+
size: 12
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function subaccountToHex(subaccount) {
|
|
71
|
+
return (0, import_viem.toHex)(subaccountToBytes32(subaccount));
|
|
72
|
+
}
|
|
73
|
+
function subaccountFromHex(subaccount) {
|
|
74
|
+
return subaccountFromBytes32((0, import_viem.toBytes)(subaccount));
|
|
75
|
+
}
|
|
76
|
+
function subaccountNameBytesToStr(input) {
|
|
77
|
+
const toStringResult = (0, import_viem.bytesToString)(input).replace(/\0*$/, "");
|
|
78
|
+
if (toStringResult.includes("\uFFFD")) {
|
|
79
|
+
return (0, import_viem.toHex)(input);
|
|
80
|
+
}
|
|
81
|
+
return toStringResult;
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
subaccountFromBytes32,
|
|
86
|
+
subaccountFromHex,
|
|
87
|
+
subaccountNameBytesToStr,
|
|
88
|
+
subaccountNameToBytes12,
|
|
89
|
+
subaccountToBytes32,
|
|
90
|
+
subaccountToHex
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=bytes32.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/bytes32.ts"],"sourcesContent":["import { bytesToString, Hex, toBytes, toHex } from 'viem';\nimport { Bytes } from '../types/bytes';\nimport {\n Subaccount,\n SubaccountBytes32,\n SubaccountNameBytes12,\n} from '../types/subaccountTypes';\n\n/**\n * Converts a subaccount object (owner + name) to its bytes32 representation.\n * @param subaccount subaccount object (owner + name)\n * @returns bytes32 representation of a subaccount\n */\nexport function subaccountToBytes32(subaccount: Subaccount): SubaccountBytes32 {\n const address = toBytes(subaccount.subaccountOwner);\n\n if (address.length != 20) {\n throw new Error(`owner must be 20 bytes, but found ${address.length}`);\n }\n\n const nameBytes = subaccountNameToBytes12(subaccount.subaccountName);\n\n const bytes32 = new Uint8Array(32);\n for (let i = 0; i < address.length; i++) {\n bytes32[i] = address[i];\n }\n for (let i = 0; i < nameBytes.length; i++) {\n bytes32[i + 20] = nameBytes[i];\n }\n\n return bytes32;\n}\n\n/**\n * Given a bytes32 representation of a subaccount, returns a subaccount object (owner + name)\n * @param bytes bytes32 representaion of a subaccount where bytes[0:20]=owner & bytes[20:32]=subaccountName\n * @returns subaccount object (owner + name)\n */\nexport function subaccountFromBytes32(bytes: SubaccountBytes32): Subaccount {\n if (bytes.length != 32) {\n throw new Error('input must be 32 bytes');\n }\n\n const address = new Uint8Array(20);\n const name = new Uint8Array(12);\n\n for (let i = 0; i < bytes.length; i++) {\n if (i < 20) {\n address[i] = bytes[i];\n } else {\n name[i - 20] = bytes[i];\n }\n }\n\n return {\n subaccountOwner: toHex(address),\n subaccountName: subaccountNameBytesToStr(name),\n };\n}\n\n/**\n * When interacting with the contracts (e.g: deposit collateral);\n * subaccount name is represented as bytes12.\n * This util converts a subaccount name to it's bytes12 representation.\n * @param name subaccount name\n * @returns bytes12 representation of a subaccount name.\n */\nexport function subaccountNameToBytes12(name: string): SubaccountNameBytes12 {\n return toBytes(name, {\n size: 12,\n });\n}\n\n/**\n * When interacting with the engine, we need to send a hex string representation\n * of the bytes32 of a subaccount for serialization reasons. This util\n * converts a subaccount object (owner + name) to such hex representation.\n * @param subaccount subaccount object (owner + name)\n * @returns hex string representation of a subaccount\n */\nexport function subaccountToHex(subaccount: Subaccount): Hex {\n return toHex(subaccountToBytes32(subaccount));\n}\n\n/**\n * Converts a hex string representation of a bytes32 subaccount to a subaccount object (owner + name)\n * @param subaccount hex string representation of a bytes32 subaccount.\n * @returns subaccount object (owner + name)\n */\nexport function subaccountFromHex(subaccount: string): Subaccount {\n return subaccountFromBytes32(toBytes(subaccount));\n}\n\n/**\n * Converts Bytes to a string. If the bytes represent a valid UTF-8 string, then a string is returned, if not,\n * then the hex representation is returned.\n *\n * @param input\n */\nexport function subaccountNameBytesToStr(input: Bytes): string {\n // bytesToString will replace zero bytes with \\0\n // strip out any trailing bytes for a readable name\n // however, we need to leave any leading bytes otherwise reverse conversion to bytes will not work\n const toStringResult = bytesToString(input).replace(/\\0*$/, '');\n // bytesToString will replace invalid byte sequences with �, so default to converting to hex string if � is present\n if (toStringResult.includes('�')) {\n return toHex(input);\n }\n return toStringResult;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmD;AAa5C,SAAS,oBAAoB,YAA2C;AAC7E,QAAM,cAAU,qBAAQ,WAAW,eAAe;AAElD,MAAI,QAAQ,UAAU,IAAI;AACxB,UAAM,IAAI,MAAM,qCAAqC,QAAQ,MAAM,EAAE;AAAA,EACvE;AAEA,QAAM,YAAY,wBAAwB,WAAW,cAAc;AAEnE,QAAM,UAAU,IAAI,WAAW,EAAE;AACjC,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,YAAQ,CAAC,IAAI,QAAQ,CAAC;AAAA,EACxB;AACA,WAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;AACzC,YAAQ,IAAI,EAAE,IAAI,UAAU,CAAC;AAAA,EAC/B;AAEA,SAAO;AACT;AAOO,SAAS,sBAAsB,OAAsC;AAC1E,MAAI,MAAM,UAAU,IAAI;AACtB,UAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C;AAEA,QAAM,UAAU,IAAI,WAAW,EAAE;AACjC,QAAM,OAAO,IAAI,WAAW,EAAE;AAE9B,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,QAAI,IAAI,IAAI;AACV,cAAQ,CAAC,IAAI,MAAM,CAAC;AAAA,IACtB,OAAO;AACL,WAAK,IAAI,EAAE,IAAI,MAAM,CAAC;AAAA,IACxB;AAAA,EACF;AAEA,SAAO;AAAA,IACL,qBAAiB,mBAAM,OAAO;AAAA,IAC9B,gBAAgB,yBAAyB,IAAI;AAAA,EAC/C;AACF;AASO,SAAS,wBAAwB,MAAqC;AAC3E,aAAO,qBAAQ,MAAM;AAAA,IACnB,MAAM;AAAA,EACR,CAAC;AACH;AASO,SAAS,gBAAgB,YAA6B;AAC3D,aAAO,mBAAM,oBAAoB,UAAU,CAAC;AAC9C;AAOO,SAAS,kBAAkB,YAAgC;AAChE,SAAO,0BAAsB,qBAAQ,UAAU,CAAC;AAClD;AAQO,SAAS,yBAAyB,OAAsB;AAI7D,QAAM,qBAAiB,2BAAc,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAE9D,MAAI,eAAe,SAAS,QAAG,GAAG;AAChC,eAAO,mBAAM,KAAK;AAAA,EACpB;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Hex } from 'viem';
|
|
2
|
+
import { Bytes } from '../types/bytes.cjs';
|
|
3
|
+
import { Subaccount, SubaccountBytes32, SubaccountNameBytes12 } from '../types/subaccountTypes.cjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a subaccount object (owner + name) to its bytes32 representation.
|
|
7
|
+
* @param subaccount subaccount object (owner + name)
|
|
8
|
+
* @returns bytes32 representation of a subaccount
|
|
9
|
+
*/
|
|
10
|
+
declare function subaccountToBytes32(subaccount: Subaccount): SubaccountBytes32;
|
|
11
|
+
/**
|
|
12
|
+
* Given a bytes32 representation of a subaccount, returns a subaccount object (owner + name)
|
|
13
|
+
* @param bytes bytes32 representaion of a subaccount where bytes[0:20]=owner & bytes[20:32]=subaccountName
|
|
14
|
+
* @returns subaccount object (owner + name)
|
|
15
|
+
*/
|
|
16
|
+
declare function subaccountFromBytes32(bytes: SubaccountBytes32): Subaccount;
|
|
17
|
+
/**
|
|
18
|
+
* When interacting with the contracts (e.g: deposit collateral);
|
|
19
|
+
* subaccount name is represented as bytes12.
|
|
20
|
+
* This util converts a subaccount name to it's bytes12 representation.
|
|
21
|
+
* @param name subaccount name
|
|
22
|
+
* @returns bytes12 representation of a subaccount name.
|
|
23
|
+
*/
|
|
24
|
+
declare function subaccountNameToBytes12(name: string): SubaccountNameBytes12;
|
|
25
|
+
/**
|
|
26
|
+
* When interacting with the engine, we need to send a hex string representation
|
|
27
|
+
* of the bytes32 of a subaccount for serialization reasons. This util
|
|
28
|
+
* converts a subaccount object (owner + name) to such hex representation.
|
|
29
|
+
* @param subaccount subaccount object (owner + name)
|
|
30
|
+
* @returns hex string representation of a subaccount
|
|
31
|
+
*/
|
|
32
|
+
declare function subaccountToHex(subaccount: Subaccount): Hex;
|
|
33
|
+
/**
|
|
34
|
+
* Converts a hex string representation of a bytes32 subaccount to a subaccount object (owner + name)
|
|
35
|
+
* @param subaccount hex string representation of a bytes32 subaccount.
|
|
36
|
+
* @returns subaccount object (owner + name)
|
|
37
|
+
*/
|
|
38
|
+
declare function subaccountFromHex(subaccount: string): Subaccount;
|
|
39
|
+
/**
|
|
40
|
+
* Converts Bytes to a string. If the bytes represent a valid UTF-8 string, then a string is returned, if not,
|
|
41
|
+
* then the hex representation is returned.
|
|
42
|
+
*
|
|
43
|
+
* @param input
|
|
44
|
+
*/
|
|
45
|
+
declare function subaccountNameBytesToStr(input: Bytes): string;
|
|
46
|
+
|
|
47
|
+
export { subaccountFromBytes32, subaccountFromHex, subaccountNameBytesToStr, subaccountNameToBytes12, subaccountToBytes32, subaccountToHex };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Hex } from 'viem';
|
|
2
|
+
import { Bytes } from '../types/bytes.js';
|
|
3
|
+
import { Subaccount, SubaccountBytes32, SubaccountNameBytes12 } from '../types/subaccountTypes.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Converts a subaccount object (owner + name) to its bytes32 representation.
|
|
7
|
+
* @param subaccount subaccount object (owner + name)
|
|
8
|
+
* @returns bytes32 representation of a subaccount
|
|
9
|
+
*/
|
|
10
|
+
declare function subaccountToBytes32(subaccount: Subaccount): SubaccountBytes32;
|
|
11
|
+
/**
|
|
12
|
+
* Given a bytes32 representation of a subaccount, returns a subaccount object (owner + name)
|
|
13
|
+
* @param bytes bytes32 representaion of a subaccount where bytes[0:20]=owner & bytes[20:32]=subaccountName
|
|
14
|
+
* @returns subaccount object (owner + name)
|
|
15
|
+
*/
|
|
16
|
+
declare function subaccountFromBytes32(bytes: SubaccountBytes32): Subaccount;
|
|
17
|
+
/**
|
|
18
|
+
* When interacting with the contracts (e.g: deposit collateral);
|
|
19
|
+
* subaccount name is represented as bytes12.
|
|
20
|
+
* This util converts a subaccount name to it's bytes12 representation.
|
|
21
|
+
* @param name subaccount name
|
|
22
|
+
* @returns bytes12 representation of a subaccount name.
|
|
23
|
+
*/
|
|
24
|
+
declare function subaccountNameToBytes12(name: string): SubaccountNameBytes12;
|
|
25
|
+
/**
|
|
26
|
+
* When interacting with the engine, we need to send a hex string representation
|
|
27
|
+
* of the bytes32 of a subaccount for serialization reasons. This util
|
|
28
|
+
* converts a subaccount object (owner + name) to such hex representation.
|
|
29
|
+
* @param subaccount subaccount object (owner + name)
|
|
30
|
+
* @returns hex string representation of a subaccount
|
|
31
|
+
*/
|
|
32
|
+
declare function subaccountToHex(subaccount: Subaccount): Hex;
|
|
33
|
+
/**
|
|
34
|
+
* Converts a hex string representation of a bytes32 subaccount to a subaccount object (owner + name)
|
|
35
|
+
* @param subaccount hex string representation of a bytes32 subaccount.
|
|
36
|
+
* @returns subaccount object (owner + name)
|
|
37
|
+
*/
|
|
38
|
+
declare function subaccountFromHex(subaccount: string): Subaccount;
|
|
39
|
+
/**
|
|
40
|
+
* Converts Bytes to a string. If the bytes represent a valid UTF-8 string, then a string is returned, if not,
|
|
41
|
+
* then the hex representation is returned.
|
|
42
|
+
*
|
|
43
|
+
* @param input
|
|
44
|
+
*/
|
|
45
|
+
declare function subaccountNameBytesToStr(input: Bytes): string;
|
|
46
|
+
|
|
47
|
+
export { subaccountFromBytes32, subaccountFromHex, subaccountNameBytesToStr, subaccountNameToBytes12, subaccountToBytes32, subaccountToHex };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import "../chunk-5WRI5ZAA.js";
|
|
2
|
+
|
|
3
|
+
// src/utils/bytes32.ts
|
|
4
|
+
import { bytesToString, toBytes, toHex } from "viem";
|
|
5
|
+
function subaccountToBytes32(subaccount) {
|
|
6
|
+
const address = toBytes(subaccount.subaccountOwner);
|
|
7
|
+
if (address.length != 20) {
|
|
8
|
+
throw new Error(`owner must be 20 bytes, but found ${address.length}`);
|
|
9
|
+
}
|
|
10
|
+
const nameBytes = subaccountNameToBytes12(subaccount.subaccountName);
|
|
11
|
+
const bytes32 = new Uint8Array(32);
|
|
12
|
+
for (let i = 0; i < address.length; i++) {
|
|
13
|
+
bytes32[i] = address[i];
|
|
14
|
+
}
|
|
15
|
+
for (let i = 0; i < nameBytes.length; i++) {
|
|
16
|
+
bytes32[i + 20] = nameBytes[i];
|
|
17
|
+
}
|
|
18
|
+
return bytes32;
|
|
19
|
+
}
|
|
20
|
+
function subaccountFromBytes32(bytes) {
|
|
21
|
+
if (bytes.length != 32) {
|
|
22
|
+
throw new Error("input must be 32 bytes");
|
|
23
|
+
}
|
|
24
|
+
const address = new Uint8Array(20);
|
|
25
|
+
const name = new Uint8Array(12);
|
|
26
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
27
|
+
if (i < 20) {
|
|
28
|
+
address[i] = bytes[i];
|
|
29
|
+
} else {
|
|
30
|
+
name[i - 20] = bytes[i];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
subaccountOwner: toHex(address),
|
|
35
|
+
subaccountName: subaccountNameBytesToStr(name)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function subaccountNameToBytes12(name) {
|
|
39
|
+
return toBytes(name, {
|
|
40
|
+
size: 12
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function subaccountToHex(subaccount) {
|
|
44
|
+
return toHex(subaccountToBytes32(subaccount));
|
|
45
|
+
}
|
|
46
|
+
function subaccountFromHex(subaccount) {
|
|
47
|
+
return subaccountFromBytes32(toBytes(subaccount));
|
|
48
|
+
}
|
|
49
|
+
function subaccountNameBytesToStr(input) {
|
|
50
|
+
const toStringResult = bytesToString(input).replace(/\0*$/, "");
|
|
51
|
+
if (toStringResult.includes("\uFFFD")) {
|
|
52
|
+
return toHex(input);
|
|
53
|
+
}
|
|
54
|
+
return toStringResult;
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
subaccountFromBytes32,
|
|
58
|
+
subaccountFromHex,
|
|
59
|
+
subaccountNameBytesToStr,
|
|
60
|
+
subaccountNameToBytes12,
|
|
61
|
+
subaccountToBytes32,
|
|
62
|
+
subaccountToHex
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=bytes32.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/bytes32.ts"],"sourcesContent":["import { bytesToString, Hex, toBytes, toHex } from 'viem';\nimport { Bytes } from '../types/bytes';\nimport {\n Subaccount,\n SubaccountBytes32,\n SubaccountNameBytes12,\n} from '../types/subaccountTypes';\n\n/**\n * Converts a subaccount object (owner + name) to its bytes32 representation.\n * @param subaccount subaccount object (owner + name)\n * @returns bytes32 representation of a subaccount\n */\nexport function subaccountToBytes32(subaccount: Subaccount): SubaccountBytes32 {\n const address = toBytes(subaccount.subaccountOwner);\n\n if (address.length != 20) {\n throw new Error(`owner must be 20 bytes, but found ${address.length}`);\n }\n\n const nameBytes = subaccountNameToBytes12(subaccount.subaccountName);\n\n const bytes32 = new Uint8Array(32);\n for (let i = 0; i < address.length; i++) {\n bytes32[i] = address[i];\n }\n for (let i = 0; i < nameBytes.length; i++) {\n bytes32[i + 20] = nameBytes[i];\n }\n\n return bytes32;\n}\n\n/**\n * Given a bytes32 representation of a subaccount, returns a subaccount object (owner + name)\n * @param bytes bytes32 representaion of a subaccount where bytes[0:20]=owner & bytes[20:32]=subaccountName\n * @returns subaccount object (owner + name)\n */\nexport function subaccountFromBytes32(bytes: SubaccountBytes32): Subaccount {\n if (bytes.length != 32) {\n throw new Error('input must be 32 bytes');\n }\n\n const address = new Uint8Array(20);\n const name = new Uint8Array(12);\n\n for (let i = 0; i < bytes.length; i++) {\n if (i < 20) {\n address[i] = bytes[i];\n } else {\n name[i - 20] = bytes[i];\n }\n }\n\n return {\n subaccountOwner: toHex(address),\n subaccountName: subaccountNameBytesToStr(name),\n };\n}\n\n/**\n * When interacting with the contracts (e.g: deposit collateral);\n * subaccount name is represented as bytes12.\n * This util converts a subaccount name to it's bytes12 representation.\n * @param name subaccount name\n * @returns bytes12 representation of a subaccount name.\n */\nexport function subaccountNameToBytes12(name: string): SubaccountNameBytes12 {\n return toBytes(name, {\n size: 12,\n });\n}\n\n/**\n * When interacting with the engine, we need to send a hex string representation\n * of the bytes32 of a subaccount for serialization reasons. This util\n * converts a subaccount object (owner + name) to such hex representation.\n * @param subaccount subaccount object (owner + name)\n * @returns hex string representation of a subaccount\n */\nexport function subaccountToHex(subaccount: Subaccount): Hex {\n return toHex(subaccountToBytes32(subaccount));\n}\n\n/**\n * Converts a hex string representation of a bytes32 subaccount to a subaccount object (owner + name)\n * @param subaccount hex string representation of a bytes32 subaccount.\n * @returns subaccount object (owner + name)\n */\nexport function subaccountFromHex(subaccount: string): Subaccount {\n return subaccountFromBytes32(toBytes(subaccount));\n}\n\n/**\n * Converts Bytes to a string. If the bytes represent a valid UTF-8 string, then a string is returned, if not,\n * then the hex representation is returned.\n *\n * @param input\n */\nexport function subaccountNameBytesToStr(input: Bytes): string {\n // bytesToString will replace zero bytes with \\0\n // strip out any trailing bytes for a readable name\n // however, we need to leave any leading bytes otherwise reverse conversion to bytes will not work\n const toStringResult = bytesToString(input).replace(/\\0*$/, '');\n // bytesToString will replace invalid byte sequences with �, so default to converting to hex string if � is present\n if (toStringResult.includes('�')) {\n return toHex(input);\n }\n return toStringResult;\n}\n"],"mappings":";;;AAAA,SAAS,eAAoB,SAAS,aAAa;AAa5C,SAAS,oBAAoB,YAA2C;AAC7E,QAAM,UAAU,QAAQ,WAAW,eAAe;AAElD,MAAI,QAAQ,UAAU,IAAI;AACxB,UAAM,IAAI,MAAM,qCAAqC,QAAQ,MAAM,EAAE;AAAA,EACvE;AAEA,QAAM,YAAY,wBAAwB,WAAW,cAAc;AAEnE,QAAM,UAAU,IAAI,WAAW,EAAE;AACjC,WAAS,IAAI,GAAG,IAAI,QAAQ,QAAQ,KAAK;AACvC,YAAQ,CAAC,IAAI,QAAQ,CAAC;AAAA,EACxB;AACA,WAAS,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;AACzC,YAAQ,IAAI,EAAE,IAAI,UAAU,CAAC;AAAA,EAC/B;AAEA,SAAO;AACT;AAOO,SAAS,sBAAsB,OAAsC;AAC1E,MAAI,MAAM,UAAU,IAAI;AACtB,UAAM,IAAI,MAAM,wBAAwB;AAAA,EAC1C;AAEA,QAAM,UAAU,IAAI,WAAW,EAAE;AACjC,QAAM,OAAO,IAAI,WAAW,EAAE;AAE9B,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,QAAI,IAAI,IAAI;AACV,cAAQ,CAAC,IAAI,MAAM,CAAC;AAAA,IACtB,OAAO;AACL,WAAK,IAAI,EAAE,IAAI,MAAM,CAAC;AAAA,IACxB;AAAA,EACF;AAEA,SAAO;AAAA,IACL,iBAAiB,MAAM,OAAO;AAAA,IAC9B,gBAAgB,yBAAyB,IAAI;AAAA,EAC/C;AACF;AASO,SAAS,wBAAwB,MAAqC;AAC3E,SAAO,QAAQ,MAAM;AAAA,IACnB,MAAM;AAAA,EACR,CAAC;AACH;AASO,SAAS,gBAAgB,YAA6B;AAC3D,SAAO,MAAM,oBAAoB,UAAU,CAAC;AAC9C;AAOO,SAAS,kBAAkB,YAAgC;AAChE,SAAO,sBAAsB,QAAQ,UAAU,CAAC;AAClD;AAQO,SAAS,yBAAyB,OAAsB;AAI7D,QAAM,iBAAiB,cAAc,KAAK,EAAE,QAAQ,QAAQ,EAAE;AAE9D,MAAI,eAAe,SAAS,QAAG,GAAG;AAChC,WAAO,MAAM,KAAK;AAAA,EACpB;AACA,SAAO;AACT;","names":[]}
|