diff --git a/build/ci.Dockerfile b/build/ci.Dockerfile index 00ad853f..9a6c5b20 100644 --- a/build/ci.Dockerfile +++ b/build/ci.Dockerfile @@ -1,3 +1,14 @@ +FROM node:22-alpine AS build-ui +RUN apk add --no-cache npm git curl build-base python3 + +COPY ["new-lamassu-admin/package.json", "new-lamassu-admin/package-lock.json", "./"] + +RUN npm version --allow-same-version --git-tag-version false --commit-hooks false 1.0.0 +RUN npm install + +COPY new-lamassu-admin/ ./ +RUN npm run build + FROM ubuntu:20.04 as base ARG VERSION @@ -25,9 +36,6 @@ RUN npm version --allow-same-version --git-tag-version false --commit-hooks fals RUN npm install --production COPY . ./ - -RUN cd new-lamassu-admin && npm install && npm run build -RUN mv new-lamassu-admin/build public/ -RUN rm -rf new-lamassu-admin/node_modules +COPY --from=build-ui /build /lamassu-server/public RUN cd .. && tar -zcvf lamassu-server.tar.gz ./lamassu-server \ No newline at end of file diff --git a/lib/commission-math.js b/lib/commission-math.js index c29a6af9..61103f2d 100644 --- a/lib/commission-math.js +++ b/lib/commission-math.js @@ -35,7 +35,6 @@ function getDiscountRate (discount, commission) { } module.exports = { - truncateCrypto, fiatToCrypto, getDiscountRate } diff --git a/lib/exchange.js b/lib/exchange.js index ee325b2f..00316eae 100644 --- a/lib/exchange.js +++ b/lib/exchange.js @@ -16,6 +16,7 @@ function fetchExchange (settings, cryptoCode) { return Promise.resolve() .then(() => { const exchangeName = lookupExchange(settings, cryptoCode) + if (exchangeName === 'mock-exchange') return { exchangeName, account: { currencyMarket: 'EUR' } } if (!exchangeName) throw new Error('No exchange set') const account = settings.accounts[exchangeName] diff --git a/lib/plugins.js b/lib/plugins.js index fb6e561d..477809a5 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -460,6 +460,15 @@ function plugins (settings, deviceId) { * Trader functions */ + function toMarketString (fiatCode, cryptoCode) { + return [fiatCode, cryptoCode].join('-') + } + + function fromMarketString (market) { + const [fiatCode, cryptoCode] = market.split('-') + return { fiatCode, cryptoCode } + } + function buy (rec, tx) { return buyAndSell(rec, true, tx) } @@ -470,14 +479,14 @@ function plugins (settings, deviceId) { function buyAndSell (rec, doBuy, tx) { const cryptoCode = rec.cryptoCode + if (!exchange.active(settings, cryptoCode)) return + return exchange.fetchExchange(settings, cryptoCode) .then(_exchange => { const fiatCode = _exchange.account.currencyMarket const cryptoAtoms = doBuy ? commissionMath.fiatToCrypto(tx, rec, deviceId, settings.config) : rec.cryptoAtoms.negated() - const market = [fiatCode, cryptoCode].join('') - - if (!exchange.active(settings, cryptoCode)) return + const market = toMarketString(fiatCode, cryptoCode) const direction = doBuy ? 'cashIn' : 'cashOut' const internalTxId = tx ? tx.id : rec.id @@ -495,7 +504,7 @@ function plugins (settings, deviceId) { } function consolidateTrades (cryptoCode, fiatCode) { - const market = [fiatCode, cryptoCode].join('') + const market = toMarketString(fiatCode, cryptoCode) const marketTradesQueues = tradesQueues[market] if (!marketTradesQueues || marketTradesQueues.length === 0) return null @@ -543,35 +552,23 @@ function plugins (settings, deviceId) { } function executeTrades () { - return machineLoader.getMachines() - .then(devices => { - const deviceIds = devices.map(device => device.deviceId) - const lists = deviceIds.map(deviceId => { - const localeConfig = configManager.getLocale(deviceId, settings.config) - const cryptoCodes = localeConfig.cryptoCurrencies + const pairs = _.map(fromMarketString)(_.keys(tradesQueues)) + pairs.forEach(({ fiatCode, cryptoCode }) => { + try { + executeTradesForMarket(settings, fiatCode, cryptoCode) + } catch (err) { + logger.error(err) + } + }) - return Promise.all(cryptoCodes.map(cryptoCode => { - return exchange.fetchExchange(settings, cryptoCode) - .then(exchange => ({ - fiatCode: exchange.account.currencyMarket, - cryptoCode - })) - })) - }) - - return Promise.all(lists) - }) - .then(lists => { - return Promise.all(_.uniq(_.flatten(lists)) - .map(r => executeTradesForMarket(settings, r.fiatCode, r.cryptoCode))) - }) - .catch(logger.error) + // Poller expects a promise + return Promise.resolve() } function executeTradesForMarket (settings, fiatCode, cryptoCode) { if (!exchange.active(settings, cryptoCode)) return - const market = [fiatCode, cryptoCode].join('') + const market = toMarketString(fiatCode, cryptoCode) const tradeEntry = consolidateTrades(cryptoCode, fiatCode) if (tradeEntry === null || tradeEntry.cryptoAtoms.eq(0)) return diff --git a/package-lock.json b/package-lock.json index c8abac1c..2047f067 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "lamassu-server", - "version": "10.2.0", + "version": "11.0.0-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "lamassu-server", - "version": "10.2.0", + "version": "11.0.0-beta.1", "license": "./LICENSE", "dependencies": { "@apollo/server": "^4.11.3", diff --git a/package.json b/package.json index ca3a7045..88ba579d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "lamassu-server", "description": "bitcoin atm client server protocol module", "keywords": [], - "version": "10.2.0", + "version": "11.0.0-beta.1", "license": "./LICENSE", "author": "Lamassu (https://lamassu.is)", "dependencies": {