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

Add Totle support #9

Open
wants to merge 8 commits into
base: master
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
220 changes: 218 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -25,6 +25,10 @@ Serverless api to communicate with Changelly/Bity api
- **[getCryptoRates](#getCryptoRates)**<br>
- **[getGasLimits](#getGasLimits)**<br>

**[Totle Network API](#Totle-API)**<br>
- **[getSupportedTokens](#getSupportedTokens)**<br>
- **[createOrder](#createOrder)**<br>

---
# Bity API

Expand Down Expand Up @@ -555,4 +559,216 @@ Except `api-key` and `sign` headers are not required
"params": [],
"id": 85
}
```
```

# Totle API

> `https://swap.mewapi.io/totle`

#### getSupportedTokens

Request:
```
{
"jsonrpc": "2.0",
"method": "getSupportedTokens",
"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": "createOrder",
"params": {
"apiKey": "",
"partnerContract": "0x0d8775f648430679a709e98d2b0cb6250d2887ef",
"address": "0x0d8775f648430679a709e98d2b0cb6250d2887ef",
"config": {
"transactions": true,
"fillNonce": false,
"skipBalanceChecks": false
},
"swap": {
"sourceAsset": "0x0f5d2fb29fb7d3cfee444a200298f468908cc942",
"destinationAsset": "0x0000000000000000000000000000000000000000",
"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
}
```
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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;
8 changes: 8 additions & 0 deletions src/totle/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
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_URL_ETH: 'https://api.totle.com'
};
37 changes: 37 additions & 0 deletions src/totle/index.js
Original file line number Diff line number Diff line change
@@ -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'));
}
}
}
}
});
};
27 changes: 27 additions & 0 deletions src/totle/methods/createOrder.js
Original file line number Diff line number Diff line change
@@ -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.params.apiKey = configs.TOTLE_API_KEY

request(req, body.params)
.then(result => {
resolve(
success({
jsonrpc: "2.0",
result,
id: body.id
})
);
})
.catch(err => {
reject(error(err, ''));
});
});
};
26 changes: 26 additions & 0 deletions src/totle/methods/getSupportedTokens.js
Original file line number Diff line number Diff line change
@@ -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_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, ''));
});
});
};
7 changes: 7 additions & 0 deletions src/totle/methods/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import getSupportedTokens from './getSupportedTokens'
import createOrder from './createOrder'

export {
getSupportedTokens,
createOrder
};
1 change: 1 addition & 0 deletions src/totle/validMethods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['getSupportedTokens', 'createOrder'];