Skip to content

Commit

Permalink
Merge pull request #6 from kulapio/add-uni-sushi
Browse files Browse the repository at this point in the history
Add UNI and SUSHI
  • Loading branch information
totiz authored Jan 17, 2021
2 parents 18fe75e + f77fc14 commit f60cdd1
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .env.default
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CMC_API_KEY=xxx // CoinMarketCap Key
CMC_API_KEY=xxx // CoinMarketCap Key for unit test
KULAP_API_BASH_URL=https://api.kulap.io/v1/api // Optional
68 changes: 47 additions & 21 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,56 @@ export const CMC_IDS_MAP = {
1982: 'KNC',
1896: 'ZRX',
1808: 'OMG',
2739: 'DGX',
1697: 'BAT',
4687: 'BUSD',
4679: 'BAND'
4679: 'BAND',
7083: 'UNI',
6758: 'SUSHI'
}


export const SUPPORTED_TOKENS = [{ "code": "WBTC", "price": "17483.08059499", "change": "3.36741374985048523788" }, { "code": "OMG", "price": "3.651493605853668234", "change": "1.83939441453954003538" }, { "code": "COMP", "price": "105.63810067652973811", "change": "0.76062063039617354456" }, { "code": "SNX", "price": "4.184655627734776244", "change": "2.03984338045293011831" }, { "code": "LRC", "price": "0.189339548771068673", "change": "-2.3931006249197938885" }, { "code": "BUSD", "price": "0.991809900739853018", "change": "-0.0975453698822696428" }, { "code": "MKR", "price": "523.267687338374522362", "change": "2.14744929231966704198" }, { "code": "BAND", "price": "5.820326313460406007", "change": "0.45303696823388185114" }, { "code": "LINK", "price": "12.882423945769723304", "change": "2.96273320857849270503" }, { "code": "USDC", "price": "0.99594256319189364", "change": "0.02325367167534316717" }, { "code": "ZRX", "price": "0.423964037039613148", "change": "5.3894533931064680138" }, { "code": "ETH", "price": "532.3674514395006", "change": "3.59722682299100083386" }, { "code": "DAI", "price": "1.003349", "change": "0.00877139647609146573" }, { "code": "KNC", "price": "1.172552586985660416", "change": "0" }, { "code": "BAT", "price": "0.226797465901862484", "change": "1.44230726539892270145" }, { "code": "USDT", "price": "0.996382897826282349", "change": "0.04327657922311353915" }]
export const SUPPORTED_TOKENS = [
"ETH",
"USDT",
"USDC",
"DAI",
"WBTC",
"LINK",
"MKR",
"LRC",
"SNX",
"COMP",
"KNC",
"ZRX",
"OMG",
"DGX",
"BAT",
"BUSD",
"BAND",
"UNI",
"SUSHI"
]

export const TOKEN_ADDRESSES = {
"BAND": "0xba11d00c5f74255f56a5e366f4f77f5a186d7f55",
"BAT": "0x0d8775f648430679a709e98d2b0cb6250d2887ef",
"BUSD": "0x4fabb145d64652a948d72533023f6e7a623c7c53",
"COMP": "0xc00e94cb662c3520282e6f5717214004a7f26888",
"DAI": "0x6b175474e89094c44da98b954eedeac495271d0f",
"DGX": "0x4f3afec4e5a3f2a6a1a411def7d7dfe50ee057bf",
"ETH": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"KNC": "0xdd974d5c2e2928dea5f71b9825b8b646686bd200",
"LINK": "0x514910771af9ca656af840dff83e8264ecf986ca",
"LRC": "0xbbbbca6a901c926f240b89eacb641d8aec7aeafd",
"MKR": "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2",
"OMG": "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07",
"SNX": "0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f",
"USDC": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"USDT": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"WBTC": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
"ZRX": "0xe41d2489571d322189246dafa5ebde1f4699f498"
"BAND": "0xba11d00c5f74255f56a5e366f4f77f5a186d7f55",
"BAT": "0x0d8775f648430679a709e98d2b0cb6250d2887ef",
"BUSD": "0x4fabb145d64652a948d72533023f6e7a623c7c53",
"COMP": "0xc00e94cb662c3520282e6f5717214004a7f26888",
"DAI": "0x6b175474e89094c44da98b954eedeac495271d0f",
"DGX": "0x4f3afec4e5a3f2a6a1a411def7d7dfe50ee057bf",
"ETH": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
"KNC": "0xdd974d5c2e2928dea5f71b9825b8b646686bd200",
"LINK": "0x514910771af9ca656af840dff83e8264ecf986ca",
"LRC": "0xbbbbca6a901c926f240b89eacb641d8aec7aeafd",
"MKR": "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2",
"OMG": "0xd26114cd6EE289AccF82350c8d8487fedB8A0C07",
"SNX": "0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f",
"USDC": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"USDT": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"WBTC": "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
"ZRX": "0xe41d2489571d322189246dafa5ebde1f4699f498",
"UNI": "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
"SUSHI": "0x6b3595068778dd592e39a122f4f5a5cf09c90fe2"
}

export const TOKEN_DECIMALS = {
Expand All @@ -64,7 +88,9 @@ export const TOKEN_DECIMALS = {
"USDC": 6,
"USDT": 6,
"WBTC": 8,
"ZRX": 18
"ZRX": 18,
"UNI": 18,
"SUSHI": 18
}

export const KULAP_DEX_CONTRACT = "0x3833cf2972394d636b1C5b80d34FeE1F17175b77"
Expand Down
2 changes: 1 addition & 1 deletion src/kulap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Kulap {
}

listSymbols(): Array<string> {
const symbols = SUPPORTED_TOKENS.map(item => item.code)
const symbols = SUPPORTED_TOKENS
return symbols.sort()
}

Expand Down
49 changes: 49 additions & 0 deletions tests/constants.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require('dotenv').config()
import {
CMC_IDS_MAP,
SUPPORTED_TOKENS,
TOKEN_ADDRESSES,
TOKEN_DECIMALS,
KULAP_DEX_CONTRACT
} from '../src/constants'

function length(object: Object) {
return Object.keys(object).length
}

describe('Asset', () => {
test('Configure Asset Information correctly', async () => {
// Number of assets
expect(length(CMC_IDS_MAP) - 1).toEqual(SUPPORTED_TOKENS.length) // exclude BTC
expect(length(TOKEN_ADDRESSES)).toEqual(SUPPORTED_TOKENS.length)
expect(length(TOKEN_DECIMALS)).toEqual(SUPPORTED_TOKENS.length)

// Asset informations
const tokens = SUPPORTED_TOKENS.sort()
const cmcIdAssets = Object.values(CMC_IDS_MAP).sort().filter(asset => asset !== 'BTC')
const tokenAddressAssets = Object.keys(TOKEN_ADDRESSES).sort()
const tokenDecimalsAssets = Object.keys(TOKEN_DECIMALS).sort()
expect(cmcIdAssets).toEqual(tokens)
expect(tokenAddressAssets).toEqual(tokens)
expect(tokenDecimalsAssets).toEqual(tokens)

// Token addresses
Object.entries(TOKEN_ADDRESSES).forEach(([key, tokenAddress]) => {
expect([tokenAddress, tokenAddress.length]).toEqual([tokenAddress, 42])
expect([tokenAddress, tokenAddress.slice(0, 2)]).toEqual([tokenAddress, '0x'])
})

// Token decimals
Object.entries(TOKEN_DECIMALS).forEach(([key, tokenDecimals]) => {
expect(tokenDecimals).toBeGreaterThan(0)
expect(tokenDecimals).toBeLessThanOrEqual(18)
})
})

test('Dex', async () => {
// Dex Contract Address
expect(KULAP_DEX_CONTRACT).toEqual('0x3833cf2972394d636b1C5b80d34FeE1F17175b77')
expect(KULAP_DEX_CONTRACT.length).toEqual(42)
expect(KULAP_DEX_CONTRACT.slice(0, 2)).toEqual('0x')
})
})
24 changes: 11 additions & 13 deletions tests/rate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { resolveTokenDecimals } from '../src/utils'
import { MockCmcRates } from './mocks/cmcRates'

const MAXIMUM_PERCENT_DIFF = '6'
const UNTRACKED_TOKENS = ['BUSD'] // Because of low liquidity
const UNTRACKED_TOKENS = ['DGX', 'BUSD'] // Because of low liquidity
const CMC_RATES_MOCK = false
let kulapSDK: Kulap
let cmc: Cmc
Expand All @@ -21,14 +21,14 @@ let symbols: Array<string>

const logger = winston.createLogger({
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: 'tests-rate.log' })
new winston.transports.Console(),
new winston.transports.File({ filename: 'tests-rate.log' })
]
})
logger.log({
})
logger.log({
level: 'info',
message: `run rate.test.ts ${new Date()}`
})
})


async function getKulapRateAmountIn(quotes: Quotes, fromSymbol: string, toSymbol: string, amountIn: string)
Expand Down Expand Up @@ -91,10 +91,10 @@ async function getRatesAmountIn(quotes: Quotes, fromSymbol: string, toSymbol: st
}

function writeLog(rateMessage: string) {
logger.log({
level: 'info',
message: rateMessage
})
logger.log({
level: 'info',
message: rateMessage
})
}

function verifyRates(
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('Rate', () => {
cmcQuotes = MockCmcRates
} else {
cmcQuotes = await cmc.quotes(symbols) as Quotes
console.log(JSON.stringify(cmcQuotes))
console.log(cmcQuotes)
}
expect(Object.keys(cmcQuotes).length).toEqual(symbols.length)
})
Expand Down Expand Up @@ -180,8 +180,6 @@ describe('Rate', () => {
describe('Compare query AmountOut with AmountIn', () => {
test('Any -> Any for $5,000 volume', async () => {
const usdAmount = '5000'
// const fromSymbol = 'COMP'
// const toSymbol = 'ETH'
for (const fromSymbol of symbols) {
for (const toSymbol of symbols.filter(symbol => symbol !== fromSymbol)) {
const fromTokenDecimals = resolveTokenDecimals(fromSymbol).toString()
Expand Down

0 comments on commit f60cdd1

Please sign in to comment.