Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
changed to use post and get generic
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynki committed Aug 31, 2023
1 parent 299b08f commit fc49b79
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 36 deletions.
5 changes: 3 additions & 2 deletions src/api/deposit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { request } = require('@rhino.fi/dvf-utils')
const post = require('../lib/dvf/post-generic')

const DVFError = require('../lib/dvf/DVFError')
const validateAssertions = require('../lib/validators/validateAssertions')

Expand Down Expand Up @@ -51,7 +52,7 @@ module.exports = async (dvf, token, amount, starkPrivateKey, nonce, signature) =

await dvf.contract.approve(token, dvf.token.toBaseUnitAmount(token, amount), dvf.config.DVF.starkExContractAddress, 'ETHEREUM')

const depositResponse = await request.post(url, { json: data })
const depositResponse = await post(dvf, url, { json: data })

const { status, transactionHash } = await dvf.contract.deposit(
tempVaultId,
Expand Down
4 changes: 2 additions & 2 deletions src/api/estimatedNextBatchTime.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { request } = require('@rhino.fi/dvf-utils')
const get = require('../lib/dvf/get-generic')

module.exports = async dvf => {
// avoid browser cache with timestamp as querystring
const t = Date.now()

const url = `${dvf.config.api}/v1/trading/r/estimatedNextBatchTime?t=${t}`
try {
const data = await request.get(url)
const data = await get(dvf, url)
return JSON.parse(data)
}
catch(e) {
Expand Down
4 changes: 2 additions & 2 deletions src/api/eth/getGasStationPrice.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { request } = require('@rhino.fi/dvf-utils')
const get = require('../../lib/dvf/get-generic')
/**
* Provides a safe average gas price
*/

module.exports = async (dvf) => {
try {
const res = await request.get(`${dvf.config.gasApi}/json/ethgasAPI.json?api-key=${dvf.config.gasStationApiKey || ''}`)
const res = await get(dvf, `${dvf.config.gasApi}/json/ethgasAPI.json?api-key=${dvf.config.gasStationApiKey || ''}`)
dvf.config.defaultGasPrice = parseInt((JSON.parse(res).average * 1.25 *100000000))
} catch(e) {
console.log('Error getting safe gas priec, using default ', e)
Expand Down
4 changes: 2 additions & 2 deletions src/api/fastWithdrawal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { request } = require('@rhino.fi/dvf-utils')
const post = require('../lib/dvf/post-generic')

module.exports = async (dvf, withdrawalData) => {
const url = dvf.config.api + '/v1/trading/w/fastWithdrawal'
const json = await dvf.createFastWithdrawalPayload(withdrawalData)
return request.post(url, { json })
return post(dvf, url, { json })
}
4 changes: 2 additions & 2 deletions src/api/fastWithdrawalFee.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { request } = require('@rhino.fi/dvf-utils')
const get = require('../lib/dvf/get-generic')

// TODO: Deprecated (CHAIN-719)
module.exports = async (dvf, token) => {
const url = dvf.config.api + '/v1/trading/r/fastWithdrawalFee'
return request.get(url, { json: true, qs: { token } })
return get(dvf, url, { json: true, qs: { token } })
}
4 changes: 2 additions & 2 deletions src/api/getConfig.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { request } = require('@rhino.fi/dvf-utils')
const post = require('../lib/dvf/post-generic')

module.exports = async dvf => {
const url = dvf.config.api + '/v1/trading/r/getConf'
try {
const exchangeConf = await request.post(url, { json: {} })
const exchangeConf = await post(dvf, url, { json: {} })
dvf.config = Object.assign({}, dvf.config, exchangeConf)
return exchangeConf
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/api/getGasPrice.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { request } = require('@rhino.fi/dvf-utils')
const get = require('../lib/dvf/get-generic')

module.exports = async (dvf) => {
const defaultGasPrice = dvf.config.defaultGasPrice
Expand All @@ -8,7 +8,7 @@ module.exports = async (dvf) => {
const url = dvf.config.api + endpoint

try {
const newGasPrice = await request.get(url, { json: true })
const newGasPrice = await get(dvf, url, { json: true })
dvf.config.defaultGasPrice = newGasPrice.fast || dvf.config.defaultGasPrice
return newGasPrice || oldGasPrice
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/getTickers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { request } = require('@rhino.fi/dvf-utils')
const get = require('../lib/dvf/get-generic')

module.exports = async (dvf, symbols) => {
if (symbols.constructor !== Array) {
symbols = [symbols]
}

const response = await request.get(`${dvf.config.api}/market-data/tickers?symbols=${symbols.join(',')}`)
const response = await get(dvf, `${dvf.config.api}/market-data/tickers?symbols=${symbols.join(',')}`)
return JSON.parse(response)
}
5 changes: 3 additions & 2 deletions src/api/getTokenHolders.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { request } = require('@rhino.fi/dvf-utils')
const get = require('../lib/dvf/get-generic')

module.exports = async (dvf, token) => {
if (token) {
const response = await request.get(
const response = await get(
dvf,
`${dvf.config.api}/v1/trading/r/getTokenHolders?token=${token}`
)
return response
Expand Down
5 changes: 3 additions & 2 deletions src/api/getTokenLiquidityLeft.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { request } = require('@rhino.fi/dvf-utils')
const get = require('../lib/dvf/get-generic')

module.exports = async (dvf, token) => {
if (token) {
const response = await request.get(
const response = await get(
dvf,
`${dvf.config.api}/v1/trading/r/getTokenLiquidityLeft?token=${token}`
)
return response
Expand Down
5 changes: 3 additions & 2 deletions src/api/getTokenSaleStartEnd.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { request } = require('@rhino.fi/dvf-utils')
const get = require('../lib/dvf/get-generic')

module.exports = async (dvf, token) => {
if (token) {
const response = await request.get(
const response = await get(
dvf,
`${dvf.config.api}/v1/trading/r/getTokenSaleStartEnd?token=${token}`
)
return response
Expand Down
4 changes: 2 additions & 2 deletions src/api/ledger/deposit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { request } = require('@rhino.fi/dvf-utils')
const post = require('../../lib/dvf/post-generic')
const validateAssertions = require('../../lib/validators/validateAssertions')

module.exports = async (dvf, token, amount, path, nonce, signature) => {
Expand All @@ -19,7 +19,7 @@ module.exports = async (dvf, token, amount, path, nonce, signature) => {

const url = dvf.config.api + '/v1/trading/w/deposit'

const deposit = await request.post(url, {json: data})
const deposit = await post(dvf, url, {json: data})
const ctDeposit = await dvf.contract.deposit(tempVaultId, token, amount, `0x${starkDeposit.starkPublicKey.x}`)

return {...deposit, ...ctDeposit}
Expand Down
4 changes: 2 additions & 2 deletions src/api/ledger/transferUsingVaultIdAndStarkKey.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { request } = require('@rhino.fi/dvf-utils')
const post = require('../../lib/dvf/post-generic')
const makeCreateSignedTransferTxLedger = require('../../lib/ledger/makeCreateSignedTransferTxLedger')

module.exports = async (dvf, transferData, path, feeRecipient) => {
const url = dvf.config.api + '/v1/trading/w/transfer'
const createSignedTransferTx = makeCreateSignedTransferTxLedger(dvf)(path)
const json = await dvf.createTransferPayload(transferData, feeRecipient, createSignedTransferTx)
return request.post(url, { json })
return post(dvf, url, { json })
}
4 changes: 2 additions & 2 deletions src/api/ledger/withdraw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { request } = require('@rhino.fi/dvf-utils')
const post = require('../../lib/dvf/post-generic')
const validateAssertions = require('../../lib/validators/validateAssertions')

module.exports = async (dvf, token, amount, starkWithdrawal) => {
Expand Down Expand Up @@ -31,7 +31,7 @@ module.exports = async (dvf, token, amount, starkWithdrawal) => {
//console.log({ data })
const url = dvf.config.api + '/v1/trading/w/withdraw'

return request.post(url, {
return post(dvf, url, {
json: data
})
}
4 changes: 2 additions & 2 deletions src/api/submitMarketOrder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { request } = require('@rhino.fi/dvf-utils')
const post = require('../lib/dvf/post-generic')
const { Joi } = require('@rhino.fi/dvf-utils')
/*
Keeping the schema visible and not in a seperate method
Expand Down Expand Up @@ -30,7 +30,7 @@ const schema = Joi.object({
module.exports = async (dvf, orderData) => {
const { value, error } = schema.validate(orderData)
// TODO handle error
return request.post(dvf.config.api + '/v1/trading/w/submitOrder', {
return post(dvf, dvf.config.api + '/v1/trading/w/submitOrder', {
json: await dvf.createMarketOrderPayload(value)
})
}
4 changes: 2 additions & 2 deletions src/api/submitOrder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { request } = require('@rhino.fi/dvf-utils')
const post = require('../lib/dvf/post-generic')
const DVFError = require('../lib/dvf/DVFError')
const { Joi } = require('@rhino.fi/dvf-utils')
const P = require('@rhino.fi/aigle')
Expand Down Expand Up @@ -67,5 +67,5 @@ module.exports = async (dvf, orderData) => {
: dvf.createOrderPayload(value)
)

return request.post(dvf.config.api + '/v1/trading/w/submitOrder', { json })
return post(dvf, dvf.config.api + '/v1/trading/w/submitOrder', { json })
}
4 changes: 2 additions & 2 deletions src/api/transferUsingVaultIdAndStarkKey.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { request } = require('@rhino.fi/dvf-utils')
const post = require('../lib/dvf/post-generic')

module.exports = async (dvf, transferData, feeRecipient) => {
const url = dvf.config.api + '/v1/trading/w/transfer'

const json = await dvf.createTransferPayload(transferData, feeRecipient)
return request.post(url, { json })
return post(dvf, url, { json })
}
4 changes: 2 additions & 2 deletions src/api/withdraw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { request } = require('@rhino.fi/dvf-utils')
const post = require('../lib/dvf/post-generic')
const DVFError = require('../lib/dvf/DVFError')
const validateAssertions = require('../lib/validators/validateAssertions')
const { Joi } = require('@rhino.fi/dvf-utils')
Expand Down Expand Up @@ -55,5 +55,5 @@ module.exports = async (dvf, token, amount, starkPrivateKey) => {
expireTime
}
//console.log({ data })
return request.post(url, { json: data })
return post(dvf, url, { json: data })
}

0 comments on commit fc49b79

Please sign in to comment.