"use strict";function countDecimals(t){if(Math.floor(t)===t)return 0;const a=t.toString(),e=/^(\d+\.?\d*|\.\d+)e([+-]\d+)$/.exec(a);if(e){let t=(e[1].split(".")[1]||"").length+parseInt(e[2]);t=Math.abs(t);return Math.min(t,8)}{const t=a.split(".")[1]||"";return Math.min(t.length,8)}}async function saveLicense(t,a){await db_1.sequelize.transaction(async e=>{await db_1.models.exchange.update({status:!1},{where:{status:!0,productId:{[sequelize_1.Op.not]:t}},transaction:e});await db_1.models.exchange.update({licenseStatus:!0,status:!0,username:a},{where:{productId:t},transaction:e})}).catch(t=>{console_1.logger.error("EXCHANGE","Error in saveLicense",t);throw(0,error_1.createError)({statusCode:500,message:`Failed to save license: ${t.message}`})})}Object.defineProperty(exports,"__esModule",{value:!0});exports.standardizeOkxData=exports.standardizeXtData=exports.standardizeKucoinData=exports.standardizeBinanceData=void 0;exports.countDecimals=countDecimals;exports.saveLicense=saveLicense;const db_1=require("@b/db"),sequelize_1=require("sequelize"),console_1=require("@b/utils/console"),error_1=require("@b/utils/error"),standardizeBinanceData=t=>t&&"object"==typeof t&&!Array.isArray(t)?Object.values(t).map(t=>{const a=t.info;return{network:t.network,withdrawStatus:t.withdraw,depositStatus:t.deposit,minWithdraw:parseFloat(a.withdrawMin),maxWithdraw:parseFloat(a.withdrawMax),withdrawFee:parseFloat(a.withdrawFee),withdrawMemo:!(!a.memoRegex||""===a.memoRegex.trim())}}):[];exports.standardizeBinanceData=standardizeBinanceData;const standardizeKucoinData=t=>Object.values(t.networks||[]).map(t=>{var a,e,i,r,s;return{network:t.name,withdrawStatus:t.withdraw,depositStatus:t.deposit,minWithdraw:parseFloat(null!==(i=null===(e=null===(a=t.limits)||void 0===a?void 0:a.withdrawal)||void 0===e?void 0:e.min)&&void 0!==i?i:0),maxWithdraw:null,withdrawFee:parseFloat(null!==(r=t.fee)&&void 0!==r?r:0),withdrawMemo:!(!t.contractAddress||""===t.contractAddress.trim()),chainId:t.id?t.id.toUpperCase():null,precision:countDecimals(null!==(s=t.precision)&&void 0!==s?s:0)||8}});exports.standardizeKucoinData=standardizeKucoinData;const standardizeXtData=t=>{var a,e,i,r,s,o;const n=[];if(t&&"object"==typeof t)for(const d in t.networks||{}){const l=t.networks[d],w=parseFloat(t.fee),c=isNaN(w)?null:w;n.push({network:d,withdrawStatus:"1"===t.info.withdrawStatus,depositStatus:"1"===t.info.depositStatus,minWithdraw:parseFloat(null!==(i=null===(e=null===(a=l.limits)||void 0===a?void 0:a.withdraw)||void 0===e?void 0:e.min)&&void 0!==i?i:"0"),maxWithdraw:(null===(s=null===(r=l.limits)||void 0===r?void 0:r.withdraw)||void 0===s?void 0:s.max)?parseFloat(l.limits.withdraw.max):null,withdrawFee:null!=c?c:0,withdrawMemo:!1,chainId:d.toUpperCase(),precision:countDecimals(null!==(o=t.precision)&&void 0!==o?o:1e-8)})}return n};exports.standardizeXtData=standardizeXtData;const standardizeOkxData=t=>t&&"object"==typeof t&&!Array.isArray(t)?Object.values(t).map(t=>({network:t.network,withdrawStatus:t.withdraw,depositStatus:t.deposit,minWithdraw:parseFloat(t.minWithdrawal),maxWithdraw:parseFloat(t.maxWithdrawal),withdrawFee:parseFloat(t.withdrawalFee),withdrawMemo:!(!t.memoRegex||""===t.memoRegex.trim())})):[];exports.standardizeOkxData=standardizeOkxData;