From 5b4b3a274f6c13507e77441b774e46ecffe77ddd Mon Sep 17 00:00:00 2001 From: KojimaGeniy Date: Fri, 26 Jul 2019 16:47:23 +0300 Subject: [PATCH 1/6] Totle API added --- README.md | 223 +++++++++++++++++++++++- src/index.js | 6 + src/totle/config.js | 9 + src/totle/index.js | 37 ++++ src/totle/methods/createOrder.js | 27 +++ src/totle/methods/getSupportedTokens.js | 26 +++ src/totle/methods/index.js | 7 + src/totle/validMethods.js | 1 + 8 files changed, 334 insertions(+), 2 deletions(-) create mode 100644 src/totle/config.js create mode 100644 src/totle/index.js create mode 100644 src/totle/methods/createOrder.js create mode 100644 src/totle/methods/getSupportedTokens.js create mode 100644 src/totle/methods/index.js create mode 100644 src/totle/validMethods.js diff --git a/README.md b/README.md index 230ab1d..860d3af 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Serverless APIs for MEW Partners -Serverless api to communicate with Changelly/Bity api +Serverless api to communicate with Bity/Changelly/Kyber/Totle api # Live endpoint @@ -24,6 +24,9 @@ Serverless api to communicate with Changelly/Bity api - **[getSupportedTokens](#getSupportedTokens)**
- **[getCryptoRates](#getCryptoRates)**
- **[getGasLimits](#getGasLimits)**
+**[Totle Network API](#Totle-API)**
+- **[getSupportedTokens](#getSupportedTokens)**
+- **[createOrder](#createOrder)**
--- # Bity API @@ -555,4 +558,220 @@ Except `api-key` and `sign` headers are not required "params": [], "id": 85 } -``` \ No newline at end of file +``` + +# Totle API + +> `https://swap.mewapi.io/totle` + +#### getSupportedTokens + +Request: +``` +{ + "jsonrpc": "2.0", + "method": "tokens", + "params": [], + "id": 85 +} +``` + +Response: +``` +{ + "jsonrpc": "2.0", + "result": { + "tokens": [{ + "name": "DATAcoin", + "symbol": "DATA", + "address": "0x0cf0ee63788a0849fe5297f3407f701e122cc023", + "decimals": 18, + "tradable": true + }] + }, + "id": 85 +} +``` + +#### createOrder + +Request: + +``` +{ + "jsonrpc": "2.0", + "method": "swap", + "params": { + "apiKey": "", + "partnerContract": "0x0d8775f648430679a709e98d2b0cb6250d2887ef", + "address": "0x0d8775f648430679a709e98d2b0cb6250d2887ef", + "config": { + "transactions": true, + "fillNonce": false, + "skipBalanceChecks": false + }, + "swap": { + "sourceAsset": "0x0f5d2fb29fb7d3cfee444a200298f468908cc942", + "destinationAsset": "0x0000000000000000000000000000000000000000", + "sourceAmount": 15, // send either sourceAmount OR destinationAmount, not both + "minFillPercent": 5, + "maxMarketSlippagePercent": 5, + "maxExecutionSlippagePercent": 5, + "destinationAmount": 100000000000000000, + "isOptional": false + } + }, + "id": 85 +} +``` + +Response: +``` +{ + "jsonrpc": "2.0", + "result": { + "success": true, + "response": { + "id": "0x4e7ed7b2df7f429f9aeaa9a00cff25555e518f797a694e7fa59f9880c80a7887", + "summary": [ + { + "sourceAsset": { + "address": "0x0f5d2fb29fb7d3cfee444a200298f468908cc942", + "symbol": "MANA", + "decimals": "18" + }, + "sourceAmount": "100000000000000000", + "destinationAsset": { + "address": "0x0000000000000000000000000000000000000000", + "symbol": "ETH", + "decimals": "18" + }, + "destinationAmount": "19387450738027", + "notes": [], + "rate": "0.00019387450738027", + "market": { + "rate": "0.00019387450738027", + "slippage": "0%" + }, + "runnerUpRoutes": [], + "trades": [ + { + "sourceAsset": { + "address": "0x0f5d2fb29fb7d3cfee444a200298f468908cc942", + "symbol": "MANA", + "decimals": "18" + }, + "sourceAmount": "100000000000000000", + "destinationAsset": { + "address": "0x0000000000000000000000000000000000000000", + "symbol": "ETH", + "decimals": "18" + }, + "destinationAmount": "19387450738027", + "orders": [ + { + "sourceAsset": { + "address": "0x0f5d2fb29fb7d3cfee444a200298f468908cc942", + "symbol": "MANA", + "decimals": "18" + }, + "sourceAmount": "100000000000000000", + "destinationAsset": { + "address": "0x0000000000000000000000000000000000000000", + "symbol": "ETH", + "decimals": "18" + }, + "destinationAmount": "19485367155895", + "exchange": { + "id": 2, + "name": "Kyber" + }, + "fee": { + "percentage": "0", + "amount": "0", + "asset": { + "address": "0x0f5d2fb29fb7d3cfee444a200298f468908cc942", + "symbol": "MANA", + "decimals": "18" + } + } + } + ], + "runnerUpOrders": [ + { + "sourceAsset": { + "address": "0x0f5d2fb29fb7d3cfee444a200298f468908cc942", + "symbol": "MANA", + "decimals": "18" + }, + "sourceAmount": "100000000000000000", + "destinationAsset": { + "address": "0x0000000000000000000000000000000000000000", + "symbol": "ETH", + "decimals": "18" + }, + "destinationAmount": "19381017264445", + "exchange": { + "id": 4, + "name": "Bancor" + }, + "fee": { + "percentage": "0", + "amount": "0", + "asset": { + "address": "0x0f5d2fb29fb7d3cfee444a200298f468908cc942", + "symbol": "MANA", + "decimals": "18" + } + } + } + ] + } + ], + "totleFee": { + "asset": { + "address": "0x0000000000000000000000000000000000000000", + "symbol": "ETH", + "decimals": "18" + }, + "percentage": "0.5", + "amount": "97916417868" + }, + "partnerFee": { + "asset": { + "address": "0x0000000000000000000000000000000000000000", + "symbol": "ETH", + "decimals": "18" + }, + "percentage": "0", + "amount": "0" + } + } + ], + "transactions": [ + { + "type": "swap", + "tx": { + "to": "0xcd2053679De3BCf2b7E2C2EfB6B499C57701222c", + "from": "0xd18cec4907b50f4eda4a197a50b619741e921b4d", + "value": "0", + "data": "0xa32305a2000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000076edf2d56f60f3717c59e90b1c3cc95cd574272900000000000000000000000000000000000000000000000000000000007d86474e7ed7b2df7f429f9aeaa9a00cff25555e518f797a694e7fa59f9880c80a7887000000000000000000000000000000000000000000000000000000000000001c96c16c4c21e7bdb8773e75fa46422c44a9829ad7fbba2672c87401556d441e9f5726e940e03eee6646bcf8159db1dffea40b2ca25a7fee2720e2fdb092a9cee600000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000009eb1ef0770c30000000000000000000000000000000000000000000000000000111a92a6a20f000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d18cec4907b50f4eda4a197a50b619741e921b4d0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000f5d2fb29fb7d3cfee444a200298f468908cc9420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016345785d8a0000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000077b26c9f9b87668b66db65dce7cc2b392ff59966000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000f5d2fb29fb7d3cfee444a200298f468908cc9420000000000000000000000000000000000000000000000000000000000000000000000000000000000000000716156326b3dd55ed5e795ac5f19afdaab866daf000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000967f1c667fc490ddd2fb941e3a461223c03d40e90000000000000000000000000f5d2fb29fb7d3cfee444a200298f468908cc94200000000000000000000000079d83b390cf0edf86b9efbe47b556cc6e20926ac0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c0000000000000000000000001f573d6fb3f13d689ff844b4ce37794d79a7ff1c000000000000000000000000c0829421c1d260bd3cb3e0f06cfe2d52db2ce3150000000000000000000000000000000000000000000000000000000000000000", + "gasPrice": "8734375000", + "gas": "900000" + } + } + ], + "rateLimit": { + "callsMade": 10, + "callsLeft": 10 + }, + "signature": "", + "expiration": { + "blockNumber": 8226375, + "estimatedTimestamp": "" + } + } + }, + "id": 85 +} +``` diff --git a/src/index.js b/src/index.js index b9e36cd..2810333 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ import api from "./api"; import changelly from "./changelly"; import bity from "./bity"; import kyber from './kyber' +import totle from './totle' import { cloudWatchLogger } from "./loggers"; api.post("/changelly", request => { @@ -19,6 +20,11 @@ api.post("/kyber", request => { return kyber(request, cloudwatch); }); +api.post("/totle", request => { + const cloudwatch = new cloudWatchLogger("TOTLE"); + return totle(request, cloudwatch); +}); + api.get("/", () => "MyEtherWallet Partners API"); module.exports = api; diff --git a/src/totle/config.js b/src/totle/config.js new file mode 100644 index 0000000..d4d8dde --- /dev/null +++ b/src/totle/config.js @@ -0,0 +1,9 @@ +require("dotenv").config(); +export default { + EXIT_TO_FIAT_API_URL: 'https://bity.com', + TOTLE_API_KEY: process.env.TOTLE_API_KEY || '', + SUPPORTED: '/tokens', + SWAP: '/swap', + API_INFO_URL_ETH: 'https://services.totlesystem.com', + API_URL_ETH: 'https://api.totle.com/swap' +}; diff --git a/src/totle/index.js b/src/totle/index.js new file mode 100644 index 0000000..1c964fb --- /dev/null +++ b/src/totle/index.js @@ -0,0 +1,37 @@ +import { error } from '../response'; +import allowedMethods from './validMethods'; +import { + getSupportedTokens, + createOrder +} from './methods'; + +export default (req, logger) => { + return new Promise((resolve, reject) => { + if (req.body) { + let body = req.body; + if (logger) logger.process(body); + if (Array.isArray(body)) { + reject(error(`Invalid Request - ${body}`)); + } else { + if (allowedMethods.indexOf(body.method) == -1) + reject(error(`Invalid Method - ${body.method}`)); + else { + switch (body.method) { + case 'getSupportedTokens': + getSupportedTokens(body) + .then(resolve) + .catch(reject); + break; + case 'createOrder': + createOrder(body) + .then(resolve) + .catch(reject); + break; + default: + reject(error('unknown error')); + } + } + } + } + }); +}; diff --git a/src/totle/methods/createOrder.js b/src/totle/methods/createOrder.js new file mode 100644 index 0000000..0228983 --- /dev/null +++ b/src/totle/methods/createOrder.js @@ -0,0 +1,27 @@ +import configs from '../config'; +import request from '../../request'; +import { error, success } from '../../response'; + + +export default body => { + return new Promise((resolve, reject) => { + const req = { + url: configs.API_URL_ETH + configs.SWAP + }; + body.apiKey = configs.TOTLE_API_KEY + + request(req, body) + .then(result => { + resolve( + success({ + jsonrpc: "2.0", + result: JSON.parse(result), + id: body.id + }) + ); + }) + .catch(err => { + reject(error(err, '')); + }); + }); +}; diff --git a/src/totle/methods/getSupportedTokens.js b/src/totle/methods/getSupportedTokens.js new file mode 100644 index 0000000..6758118 --- /dev/null +++ b/src/totle/methods/getSupportedTokens.js @@ -0,0 +1,26 @@ +import configs from '../config'; +import request from '../../request'; +import { error, success } from '../../response'; + + +export default body => { + return new Promise((resolve, reject) => { + const req = { + url: configs.API_INFO_URL_ETH + configs.SUPPORTED, + method: 'GET' + }; + request(req) + .then(result => { + resolve( + success({ + jsonrpc: "2.0", + result: JSON.parse(result), + id: body.id + }) + ); + }) + .catch(err => { + reject(error(err, '')); + }); + }); +}; diff --git a/src/totle/methods/index.js b/src/totle/methods/index.js new file mode 100644 index 0000000..9ec3795 --- /dev/null +++ b/src/totle/methods/index.js @@ -0,0 +1,7 @@ +import getSupportedTokens from './getSupportedTokens' +import createOrder from './createOrder' + +export { + getSupportedTokens, + createOrder +}; diff --git a/src/totle/validMethods.js b/src/totle/validMethods.js new file mode 100644 index 0000000..002ac2c --- /dev/null +++ b/src/totle/validMethods.js @@ -0,0 +1 @@ +export default ['getSupportedTokens', 'createOrder']; From 9dc12b088ec8849dce6bcd6832717c261cd5f4f5 Mon Sep 17 00:00:00 2001 From: Andrew <34808650+KojimaGeniy@users.noreply.github.com> Date: Fri, 26 Jul 2019 16:53:26 +0300 Subject: [PATCH 2/6] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 860d3af..7b2fc21 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Serverless api to communicate with Bity/Changelly/Kyber/Totle api - **[getSupportedTokens](#getSupportedTokens)**
- **[getCryptoRates](#getCryptoRates)**
- **[getGasLimits](#getGasLimits)**
+ **[Totle Network API](#Totle-API)**
- **[getSupportedTokens](#getSupportedTokens)**
- **[createOrder](#createOrder)**
From 5e42e929dfea8837bdcff9fe6551a8bd44322761 Mon Sep 17 00:00:00 2001 From: KojimaGeniy Date: Fri, 26 Jul 2019 19:42:05 +0300 Subject: [PATCH 3/6] Fix totle call --- src/totle/config.js | 2 +- src/totle/methods/createOrder.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/totle/config.js b/src/totle/config.js index d4d8dde..da009d2 100644 --- a/src/totle/config.js +++ b/src/totle/config.js @@ -5,5 +5,5 @@ export default { SUPPORTED: '/tokens', SWAP: '/swap', API_INFO_URL_ETH: 'https://services.totlesystem.com', - API_URL_ETH: 'https://api.totle.com/swap' + API_URL_ETH: 'https://api.totle.com' }; diff --git a/src/totle/methods/createOrder.js b/src/totle/methods/createOrder.js index 0228983..10a7c22 100644 --- a/src/totle/methods/createOrder.js +++ b/src/totle/methods/createOrder.js @@ -10,12 +10,12 @@ export default body => { }; body.apiKey = configs.TOTLE_API_KEY - request(req, body) + request(req, body.params) .then(result => { resolve( success({ jsonrpc: "2.0", - result: JSON.parse(result), + result, id: body.id }) ); From 44bc4ec6ba45e29f127b88dff838c4d0a06d06ca Mon Sep 17 00:00:00 2001 From: Andrew <34808650+KojimaGeniy@users.noreply.github.com> Date: Fri, 26 Jul 2019 19:47:38 +0300 Subject: [PATCH 4/6] Update README.md --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7b2fc21..2670216 100644 --- a/README.md +++ b/README.md @@ -571,7 +571,7 @@ Request: ``` { "jsonrpc": "2.0", - "method": "tokens", + "method": "getSupportedTokens", "params": [], "id": 85 } @@ -601,7 +601,7 @@ Request: ``` { "jsonrpc": "2.0", - "method": "swap", + "method": "createOrder", "params": { "apiKey": "", "partnerContract": "0x0d8775f648430679a709e98d2b0cb6250d2887ef", @@ -614,10 +614,6 @@ Request: "swap": { "sourceAsset": "0x0f5d2fb29fb7d3cfee444a200298f468908cc942", "destinationAsset": "0x0000000000000000000000000000000000000000", - "sourceAmount": 15, // send either sourceAmount OR destinationAmount, not both - "minFillPercent": 5, - "maxMarketSlippagePercent": 5, - "maxExecutionSlippagePercent": 5, "destinationAmount": 100000000000000000, "isOptional": false } From 084c1970d95a23865b402b210ab0e85123c9499f Mon Sep 17 00:00:00 2001 From: KojimaGeniy Date: Mon, 29 Jul 2019 16:42:37 +0300 Subject: [PATCH 5/6] Updated API URL for Totle --- src/totle/config.js | 1 - src/totle/methods/getSupportedTokens.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/totle/config.js b/src/totle/config.js index da009d2..2119f7c 100644 --- a/src/totle/config.js +++ b/src/totle/config.js @@ -4,6 +4,5 @@ export default { TOTLE_API_KEY: process.env.TOTLE_API_KEY || '', SUPPORTED: '/tokens', SWAP: '/swap', - API_INFO_URL_ETH: 'https://services.totlesystem.com', API_URL_ETH: 'https://api.totle.com' }; diff --git a/src/totle/methods/getSupportedTokens.js b/src/totle/methods/getSupportedTokens.js index 6758118..da9267d 100644 --- a/src/totle/methods/getSupportedTokens.js +++ b/src/totle/methods/getSupportedTokens.js @@ -6,7 +6,7 @@ import { error, success } from '../../response'; export default body => { return new Promise((resolve, reject) => { const req = { - url: configs.API_INFO_URL_ETH + configs.SUPPORTED, + url: configs.API_URL_ETH + configs.SUPPORTED, method: 'GET' }; request(req) From 3e72afb33858145387e4018047080ffd62aa7560 Mon Sep 17 00:00:00 2001 From: KojimaGeniy Date: Thu, 14 Nov 2019 12:50:49 +0300 Subject: [PATCH 6/6] Fixed Totle api key param --- src/totle/methods/createOrder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/totle/methods/createOrder.js b/src/totle/methods/createOrder.js index 10a7c22..6856fe0 100644 --- a/src/totle/methods/createOrder.js +++ b/src/totle/methods/createOrder.js @@ -8,7 +8,7 @@ export default body => { const req = { url: configs.API_URL_ETH + configs.SWAP }; - body.apiKey = configs.TOTLE_API_KEY + body.params.apiKey = configs.TOTLE_API_KEY request(req, body.params) .then(result => {