Skip to content

Commit

Permalink
Merge pull request hummingbot#65 from CoinAlpha/feat/dexalot
Browse files Browse the repository at this point in the history
Feat/dexalot
  • Loading branch information
fengtality authored Mar 23, 2023
2 parents e68d562 + 33df6bc commit 71b55ca
Show file tree
Hide file tree
Showing 36 changed files with 1,736 additions and 72 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
/.idea
package-lock.json
/certs
/coverage
/node_modules
/coverage
**/.DS_Store
**/gateway_files
**/gateway_files

# VSCode
.vscode/
.history
36 changes: 35 additions & 1 deletion docs/swagger/definitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ definitions:
- 'tokenSymbols'
- 'chain'
- 'network'
- 'connector'
properties:
privateKey:
type: 'string'
Expand All @@ -123,6 +124,9 @@ definitions:
network:
type: 'string'
example: 'goerli'
connector:
type: 'string'
example: 'dexalot'

BalancesResponse:
type: 'object'
Expand Down Expand Up @@ -659,11 +663,41 @@ definitions:
properties:
chain:
type: 'string'
tokenSymbols:
walletAddresses:
type: 'array'
items: 'string'
example: ['0xd0A1E359811322d97991E03f863a0C30C2cF029C', '0xd0A1E359811322d97991E03f863a0C30C2XXXXXX']

GetWalletSignRequest:
type: 'object'
required:
- 'chain'
- 'network'
- 'address'
- 'message'
properties:
chain:
type: 'string'
example: 'ethereum'
network:
type: 'string'
example: 'mainnet'
address:
type: 'string'
example: '0x...'
message:
type: 'string'
example: 'Message to be signed'

GetWalletSignResponse:
type: 'object'
required:
- 'signature'
properties:
signature:
type: 'string'
example: '0xb234d423b065317fdbb30408c5b83ac3f1c6a273b5b4f65faac2d70ec412e2762099917c62f21924aee59cab277e9ba001147dd5b300fcf4cafb6e79a97c756d1c'

ConfigUpdateRequest:
type: 'object'
required:
Expand Down
23 changes: 23 additions & 0 deletions docs/swagger/wallet-routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,26 @@ paths:
schema:
$ref: '#/definitions/RemoveWalletRequest'
responses: '200'

/wallet/sign:
get:
tags:
- 'wallet'
summary: 'Sign a message using the private key associated with the supplied public key address'
operationId: 'get'
consumes:
- 'application/json'
produces:
- 'application/json'
parameters:
- in: 'body'
name: 'body'
description: 'Request body.'
required: true
schema:
$ref: '#/definitions/GetWalletSignRequest'
responses:
'200':
description: 'Successful response.'
schema:
$ref: '#/definitions/GetWalletSignResponse'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"format": "prettier . --write",
"lint": "eslint src test test-scripts --format table --fix",
"dev": "nodemon src/index.ts",
"dev:debug": "nodemon --inspect src/index.ts",
"dev:debug": "NODE_ENV=dev DEBUG=* nodemon src/index.ts",
"start": "/bin/bash ./startup.sh",
"copy-files": "copyfiles -a 'src/**/schema/*.json' 'src/templates/*.yml' 'test/services/data/**/*.*' dist",
"test": "jest --verbose",
Expand Down
72 changes: 72 additions & 0 deletions src/chains/avalanche/avanlanche_tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,78 @@
},
"timestamp": "2022-12-15T12:00:00+00:00",
"tokens": [
{
"chainId": 432204,
"address": "0x9983F755Bbd60d1886CbfE103c98C272AA0F03d6",
"decimals": 18,
"name": "Dexalot Token",
"symbol": "ALOT",
"logoURI": "https://raw.githubusercontent.com/Dexalot/tokenlist/main/imgs/alot/logo.png"
},
{
"chainId": 432204,
"address": "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
"decimals": 6,
"name": "USDC",
"symbol": "USDC",
"logoURI": "https://raw.githubusercontent.com/Dexalot/tokenlist/main/imgs/usdc/logo.png"
},
{
"chainId": 432204,
"address": "0x0000000000000000000000000000000000000000",
"decimals": 18,
"name": "Avalanche",
"symbol": "AVAX",
"logoURI": "https://raw.githubusercontent.com/Dexalot/tokenlist/main/imgs/avax/logo.png"
},
{
"chainId": 432204,
"address": "0x152b9d0FdC40C096757F570A51E494bd4b943E50",
"decimals": 18,
"name": "BTC.b",
"symbol": "BTC.b",
"logoURI": "https://raw.githubusercontent.com/Dexalot/tokenlist/main/imgs/btc/logo.png"
},
{
"chainId": 432204,
"address": "0x932bC2933d1782ECBe1b8cE03B7fe3867fD72056",
"decimals": 18,
"name": "DEGIS Token",
"symbol": "DEG",
"logoURI": "https://raw.githubusercontent.com/Dexalot/tokenlist/main/imgs/deg/logo.png"
},
{
"chainId": 432204,
"address": "0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB",
"decimals": 18,
"name": "WETH.e",
"symbol": "WETH.e",
"logoURI": "https://raw.githubusercontent.com/Dexalot/tokenlist/main/imgs/eth/logo.png"
},
{
"chainId": 432204,
"address": "0x5a15Bdcf9a3A8e799fa4381E666466a516F2d9C8",
"decimals": 18,
"name": "SLIME Token",
"symbol": "SLIME",
"logoURI": "https://raw.githubusercontent.com/Dexalot/tokenlist/main/imgs/slime/logo.png"
},
{
"chainId": 432204,
"address": "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7",
"decimals": 6,
"name": "TetherToken",
"symbol": "USDT",
"logoURI": "https://raw.githubusercontent.com/Dexalot/tokenlist/main/imgs/usdt/logo.png"
},
{
"chainId": 432204,
"address": "0x449674B82F05d498E126Dd6615a1057A9c088f2C",
"decimals": 18,
"name": "LOST Token",
"symbol": "LOST",
"logoURI": "https://raw.githubusercontent.com/Dexalot/tokenlist/main/imgs/lost/logo.png"
},
{
"chainId": 114,
"address": "0x6169CD307Be7E24152dF23a7A945A1ea3eC7b438",
Expand Down
99 changes: 59 additions & 40 deletions src/chains/ethereum/ethereum.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
Ethereumish,
UniswapLPish,
Uniswapish,
CLOBish,
} from '../../services/common-interfaces';
import {
NonceRequest,
Expand Down Expand Up @@ -126,52 +127,66 @@ export async function balances(
const initTime = Date.now();

let wallet: Wallet;
try {
wallet = await ethereumish.getWallet(req.address);
} catch (err) {
throw new HttpException(
500,
LOAD_WALLET_ERROR_MESSAGE + err,
LOAD_WALLET_ERROR_CODE
);
}
const tokens = getTokenSymbolsToTokens(ethereumish, req.tokenSymbols);
const connector: CLOBish | undefined = req.connector
? ((await getConnector(req.chain, req.network, req.connector)) as CLOBish)
: undefined;
const balances: Record<string, string> = {};
if (req.tokenSymbols.includes(ethereumish.nativeTokenSymbol)) {
balances[ethereumish.nativeTokenSymbol] = tokenValueToString(
await ethereumish.getNativeBalance(wallet)
);
}
await Promise.all(
Object.keys(tokens).map(async (symbol) => {
if (tokens[symbol] !== undefined) {
const address = tokens[symbol].address;
const decimals = tokens[symbol].decimals;
// instantiate a contract and pass in provider for read-only access
const contract = ethereumish.getContract(address, ethereumish.provider);
const balance = await ethereumish.getERC20Balance(
contract,
wallet,
decimals
);
balances[symbol] = tokenValueToString(balance);
}
})
);
let connectorBalances: { [key: string]: string } | undefined;

if (!connector?.balances) {
try {
wallet = await ethereumish.getWallet(req.address);
} catch (err) {
throw new HttpException(
500,
LOAD_WALLET_ERROR_MESSAGE + err,
LOAD_WALLET_ERROR_CODE
);
}

if (!Object.keys(balances).length) {
throw new HttpException(
500,
TOKEN_NOT_SUPPORTED_ERROR_MESSAGE,
TOKEN_NOT_SUPPORTED_ERROR_CODE
const tokens = getTokenSymbolsToTokens(ethereumish, req.tokenSymbols);
if (req.tokenSymbols.includes(ethereumish.nativeTokenSymbol)) {
balances[ethereumish.nativeTokenSymbol] = tokenValueToString(
await ethereumish.getNativeBalance(wallet)
);
}
await Promise.all(
Object.keys(tokens).map(async (symbol) => {
if (tokens[symbol] !== undefined) {
const address = tokens[symbol].address;
const decimals = tokens[symbol].decimals;
// instantiate a contract and pass in provider for read-only access
const contract = ethereumish.getContract(
address,
ethereumish.provider
);
const balance = await ethereumish.getERC20Balance(
contract,
wallet,
decimals
);
balances[symbol] = tokenValueToString(balance);
}
})
);

if (!Object.keys(balances).length) {
throw new HttpException(
500,
TOKEN_NOT_SUPPORTED_ERROR_MESSAGE,
TOKEN_NOT_SUPPORTED_ERROR_CODE
);
}
} else {
// CLOB connector or any other connector that has the concept of separation of account has to implement a balance function
connectorBalances = await connector.balances(req);
}

return {
network: ethereumish.chain,
timestamp: initTime,
latency: latency(initTime, Date.now()),
balances: balances,
balances: connectorBalances || balances,
};
}

Expand Down Expand Up @@ -379,9 +394,13 @@ export async function poll(
// decode logs
if (req.connector) {
try {
const connector: Uniswapish | UniswapLPish = await getConnector<
Uniswapish | UniswapLPish
>(req.chain, req.network, req.connector);
const connector: Uniswapish | UniswapLPish | CLOBish =
await getConnector<Uniswapish | UniswapLPish | CLOBish>(
req.chain,
req.network,
req.connector
);

txReceipt.logs = connector.abiDecoder?.decodeLogs(txReceipt.logs);
} catch (e) {
logger.error(e);
Expand Down
Loading

0 comments on commit 71b55ca

Please sign in to comment.