Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One inch quote flow #2490

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 99 additions & 1 deletion server/api/controllers/broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const createBrokerPair = (req, res) => {
account,
formula,
spread,
meta
} = req.swagger.params.data.value;

loggerBroker.verbose(
Expand Down Expand Up @@ -88,6 +89,7 @@ const createBrokerPair = (req, res) => {
account,
formula,
spread,
meta
})
.then((data) => {
toolsLib.user.createAuditLog({ email: req?.auth?.sub?.email, session_id: req?.session_id }, req?.swagger?.apiPath, req?.swagger?.operationPath?.[2], req?.swagger?.params?.data?.value);
Expand All @@ -113,11 +115,13 @@ const testBroker = (req, res) => {
const {
formula,
spread,
meta
} = req.swagger.params.data.value;

toolsLib.broker.testBroker({
formula,
spread,
meta
})
.then((data) => {
return res.json(data);
Expand All @@ -132,6 +136,96 @@ const testBroker = (req, res) => {
});
};

const testBrokerOneinch = (req, res) => {
loggerBroker.verbose(
req.uuid,
'controllers/broker/testBrokerOneinch get',
req.auth
);

const {
base_coin,
spread,
quote_coin,
chain,
meta
} = req.swagger.params.data.value;

toolsLib.broker.testBrokerOneinch({
base_coin,
spread,
quote_coin,
chain,
meta
})
.then((data) => {
return res.json(data);
})
.catch((err) => {
loggerBroker.error(
req.uuid,
'controllers/broker/testBrokerOneinch err',
err.message
);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

const testBrokerWowmax = (req, res) => {
loggerBroker.verbose(
req.uuid,
'controllers/broker/testBrokerWowmax get',
req.auth
);

const {
base_coin,
spread,
quote_coin,
chain,
meta
} = req.swagger.params.data.value;

toolsLib.broker.testBrokerWowmax({
base_coin,
spread,
quote_coin,
chain,
meta
})
.then((data) => {
return res.json(data);
})
.catch((err) => {
loggerBroker.error(
req.uuid,
'controllers/broker/testBrokerWowmax err',
err.message
);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

const getBrokerOneinchTokens = (req, res) => {
loggerBroker.verbose(
req.uuid,
'controllers/broker/getBrokerOneinchTokens get',
req.auth
);

toolsLib.broker.getBrokerOneinchTokens()
.then((data) => {
return res.json(data);
})
.catch((err) => {
loggerBroker.error(
req.uuid,
'controllers/broker/getBrokerOneinchTokens err',
err.message
);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
}

const testRebalance = (req, res) => {
loggerBroker.verbose(
Expand Down Expand Up @@ -265,6 +359,7 @@ function getBrokerPairs(req, res) {
'rebalancing_symbol',
'account',
'spread',
'meta',
'formula'
];

Expand All @@ -291,5 +386,8 @@ module.exports = {
updateBrokerPair,
deleteBrokerPair,
getBrokerPairs,
getTrackedExchangeMarkets
getTrackedExchangeMarkets,
testBrokerOneinch,
getBrokerOneinchTokens,
testBrokerWowmax
};
108 changes: 108 additions & 0 deletions server/api/swagger/broker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,114 @@ paths:
formula:
type: string
maxLength: 1024
meta:
type: object
responses:
200:
description: Success
schema:
$ref: "#/definitions/ObjectResponse"
default:
description: Error
schema:
$ref: "#/definitions/MessageResponse"
security:
- Token: []
x-security-types:
- bearer
x-security-scopes:
- admin
/broker/oneinch:
x-swagger-router-controller: broker
get:
operationId: getBrokerOneinchTokens
description: get broker oneinch
tags:
- Broker
responses:
200:
description: Success
schema:
$ref: "#/definitions/ObjectResponse"
default:
description: Error
schema:
$ref: "#/definitions/MessageResponse"
security:
- Token: []
x-security-types:
- bearer
x-security-scopes:
- admin
/broker/oneinch/test:
x-swagger-router-controller: broker
post:
operationId: testBrokerOneinch
description: test broker oneinch
tags:
- Broker
parameters:
- name: data
in: body
required: true
schema:
type: object
properties:
spread:
type: number
base_coin:
type: string
maxLength: 256
quote_coin:
type: string
maxLength: 256
chain:
type: string
maxLength: 256
meta:
type: object
responses:
200:
description: Success
schema:
$ref: "#/definitions/ObjectResponse"
default:
description: Error
schema:
$ref: "#/definitions/MessageResponse"
security:
- Token: []
x-security-types:
- bearer
x-security-scopes:
- admin
/broker/wowmax/test:
x-swagger-router-controller: broker
post:
operationId: testBrokerWowmax
description: test broker wowmax
tags:
- Broker
parameters:
- name: data
in: body
required: true
schema:
type: object
properties:
spread:
type: number
base_coin:
type: string
maxLength: 256
quote_coin:
type: string
maxLength: 256
chain:
type: string
maxLength: 256
meta:
type: object
responses:
200:
description: Success
Expand Down
4 changes: 4 additions & 0 deletions server/api/swagger/definitions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,8 @@ definitions:
maxLength: 256
quote_expiry_time:
type: ['number', 'null']
meta:
type: ['object', 'null']
rebalancing_symbol:
type: ['string', 'null']
account:
Expand Down Expand Up @@ -1520,6 +1522,8 @@ definitions:
type: number
increment_size:
type: number
meta:
type: object
type:
type: string
maxLength: 256
Expand Down
50 changes: 47 additions & 3 deletions server/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,56 @@ exports.EXCHANGE_PLAN_INTERVAL_TIME = {
boost: 60
};
exports.EXCHANGE_PLAN_PRICE_SOURCE = {
fiat: ['hollaex', 'oracle', 'binance', 'bitfinex', 'coinbase', 'kraken', 'bybit', 'gateio', 'uniswap'],
boost: ['hollaex', 'oracle', 'binance', 'bitfinex', 'coinbase', 'kraken', 'bybit', 'gateio', 'uniswap'],
fiat: ['hollaex', 'oracle', 'binance', 'bitfinex', 'coinbase', 'kraken', 'bybit', 'gateio', 'wowmax', 'oneinch'],
boost: ['hollaex', 'oracle', 'binance', 'bitfinex', 'coinbase', 'kraken', 'bybit', 'gateio', 'wowmax', 'oneinch'],
crypto: ['hollaex', 'oracle', 'binance'],
ALL: [ 'hollaex', 'oracle', 'binance', 'bitfinex', 'coinbase', 'kraken', 'bybit', 'gateio', 'uniswap']
ALL: [ 'hollaex', 'oracle', 'binance', 'bitfinex', 'coinbase', 'kraken', 'bybit', 'gateio', 'wowmax', 'oneinch']
};

exports.ONEINCH_URL = 'https://api.1inch.dev/swap/v5.2/';
exports.WOWMAX_QUOTE_URL = 'https://api-gateway.wowmax.exchange/chains/';

exports.ONEINCH_COINS = {
eth: {
wbtc: { token: "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599", decimals: 8 },
eth: { token: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", decimals: 18 },
usdt: { token: "0xdAC17F958D2ee523a2206206994597C13D831ec7", decimals: 6 },
dai: { token: "0x6b175474e89094c44da98b954eedeac495271d0f", decimals: 18 },
usdc: { token: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", decimals: 6 },
weth: { token: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", decimals: 18 },
mkr: { token: "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2", decimals: 18 },
hex: { token: '0X2B591E99AFE9F32EAA6214F7B7629768C40EEB39', decimals: 8 },
matic: { token: "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0", decimals: 18 },
mana: { token: "0x0f5d2fb29fb7d3cfee444a200298f468908cc942", decimals: 18 },
sushi: { token: "0x6b3595068778dd592e39a122f4f5a5cf09c90fe2", decimals: 18 },
bat: { token: "0x0d8775f648430679a709e98d2b0cb6250d2887ef", decimals: 18 },
knc: { token: "0xdd974d5c2e2928dea5f71b9825b8b646686bd200", decimals: 18 },
aave: { token: '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9', decimals: 18 },
link: { token: '0x514910771AF9Ca656af840dff83E8264EcF986CA', decimals: 18 },
sETH2: { token: '0xFe2e637202056d30016725477c5da089Ab0A043A', decimals: 18 },
stETH: { token: '0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84', decimals: 18 },
gtc: { token: '0xDe30da39c46104798bB5aA3fe8B9e0e1F348163F', decimals: 18 },
snt: { token: '0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F', decimals: 18 },
allt: { token: '0x6B0b3a982b4634aC68dD83a4DBF02311cE324181', decimals: 18 }
},
bnb: {
btcb: { token: "0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c", decimals: 18 },
eth: { token: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8", decimals: 18 },
usdt: { token: "0x55d398326f99059ff775485246999027b3197955", decimals: 18 },
},
matic: {
btcb: { token: "0x2297aEbD383787A160DD0d9F71508148769342E3", decimals: 8 },
weth: { token: "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0", decimals: 18 },
usdt: { token: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F", decimals: 6 },
}
}

exports.ONEINCH_CHAINS = {
eth: 1,
bnb: 56,
matic: 137,
}


// BROKER CONSTANTS END

Expand Down
14 changes: 14 additions & 0 deletions server/db/migrations/20231127100362-add-meta-broker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

const TABLE = 'Brokers';
const COLUMN = 'meta';

module.exports = {
up: (queryInterface, Sequelize) =>
queryInterface.addColumn(TABLE, COLUMN, {
type: Sequelize.JSONB,
allowNull: true
}),
down: (queryInterface, Sequelize) =>
queryInterface.removeColumn(TABLE, COLUMN)
};
5 changes: 4 additions & 1 deletion server/db/models/broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ module.exports = function (sequelize, DataTypes) {
type: DataTypes.TEXT,
allowNull: true
},

meta: {
type: DataTypes.JSONB,
allowNull: true
}
},
{
timestamps: true,
Expand Down
2 changes: 2 additions & 0 deletions server/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ exports.INVALID_NETWORK = (network, validNetworks) => `Invalid network: ${networ
exports.NETWORK_REQUIRED = (coin, validNetworks) => `Must specify network for coin: ${coin}${validNetworks ? `. Valid networks: ${validNetworks}` : ''}`;
exports.AUTH_NOT_MATCHED = 'Auth doesn\'t match';
exports.BROKER_NOT_FOUND = 'Broker pair could not be found';
exports.BROKER_ONEINCH_CHAIN = 'Oneinch Blockchain not defiend';
exports.BROKER_ONEINCH_KEY = 'Oneinch API key not defiend';
exports.BROKER_SIZE_EXCEED = 'Size should be between minimum and maximum set size of broker';
exports.BROKER_PAUSED = 'Broker pair is paused';
exports.BROKER_ERROR_DELETE_UNPAUSED = 'Broker pair could not be deleted while unpaused';
Expand Down
Loading