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

Gas estimation failed #2

Open
kumarbitindi opened this issue Jan 17, 2023 · 8 comments
Open

Gas estimation failed #2

kumarbitindi opened this issue Jan 17, 2023 · 8 comments

Comments

@kumarbitindi
Copy link

hi i am trying it on BSC network and using https://api.owlracle.info/v3/bsc/gas this for gas

import { ChainId } from "@0x/contract-addresses";
import axios from "axios";
import { ethers } from "ethers";

export const getGasEstimation = async (chainId: ChainId) => {

if (chainId === ChainId.BSC) {
const gasEstimation = await (await axios.get('https://api.owlracle.info/v3/bsc/gas')).data['speeds'];
// solution presented at ethers-io/ethers.js#2828
const maxFeePerGas = ethers.utils.parseUnits(
Math.ceil(gasEstimation.maxFee) + '',
'gwei'
)
const maxPriorityFeePerGas = ethers.utils.parseUnits(
Math.ceil(gasEstimation.maxPriorityFee) + '',
'gwei'
)
return { maxFeePerGas, maxPriorityFeePerGas }
}

return {}
}

@kumarbitindi
Copy link
Author

import { ChainId } from "@0x/contract-addresses";
import { MarketConfig } from "./types";

export const Markets: MarketConfig[] = [
{
baseTokenAddress: '0x77fc65deda64f0cca9e3aea7b9d8521f4151882e',
quoteTokenAddress: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
chainId: ChainId.BSC,
maxBuyUnit: 0.1,
minBuyUnit: 0.05,
minSellUnit: 0.05,
maxSellUnit: 0.1,
minIntervalSeconds: 60 * 5,
maxIntervalSeconds: 60 * 10,
slippagePercentage: 0.05,
maxGasValueInGwei: 5

}

]

@JoaoCampos89
Copy link
Member

Swap api not works well with tokens with taxes, you need to use a higher slippagePercentage to help it cover the tax fee

@JoaoCampos89
Copy link
Member

You don't need to change the gas fee logic for BSC, it should solve the issue when you put a higher slippage

@kumarbitindi
Copy link
Author

data: {
code: 100,
reason: 'Validation Failed',
validationErrors: [Array]

@kumarbitindi
Copy link
Author

  • Executing task: yarn run start

yarn run v1.22.19
warning ......\package.json: No license field
$ ts-node src/index.ts
Starting bot for market: 0
bot address is 0x1404585C6cF024e12Ae471475084ebdEDEc40a8A
fetching metadata
Preparing allowance for quote token
Preparing allowance for base token
All allowances ok we are ready for trade
[AxiosError: Request failed with status code 400] {
code: 'ERR_BAD_REQUEST',
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [Function: httpAdapter],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function] },
validateStatus: [Function: validateStatus],
headers: {
Accept: 'application/json, text/plain, /',
'User-Agent': 'axios/0.27.2'
},
method: 'get',
url: 'https://bsc.api.0x.org/swap/v1/quote?sellAmount=20000000000000000&sellToken=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c&buyToken=0x77fc65deda64f0cca9e3aea7b9d8521f4151882e&takerAddress=0x1404585C6cF024e12Ae471475084ebdEDEc40a8A&intentOnFill=true&slippagePercentage=10&feeRecipient=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d&affiliateAddress=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d',
data: undefined
},
request: <ref *1> ClientRequest {
_events: [Object: null prototype] {
abort: [Function (anonymous)],
aborted: [Function (anonymous)],
connect: [Function (anonymous)],
error: [Function (anonymous)],
socket: [Function (anonymous)],
timeout: [Function (anonymous)],
finish: [Function: requestOnFinish]
},
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
strictContentLength: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
secureConnecting: false,
_SNICallback: null,
servername: 'bsc.api.0x.org',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object: null prototype],
_eventsCount: 10,
connecting: false,
_hadError: false,
_parent: null,
_host: 'bsc.api.0x.org',
_closeAfterHandlingError: false,
_readableState: [ReadableState],
_maxListeners: undefined,
_writableState: [WritableState],
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: [TLSWrap],
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: [Circular *1],
[Symbol(res)]: [TLSWrap],
[Symbol(verified)]: true,
[Symbol(pendingSession)]: null,
[Symbol(async_id_symbol)]: 203,
[Symbol(kHandle)]: [TLSWrap],
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBuffer)]: null,
[Symbol(kBufferCb)]: null,
[Symbol(kBufferGen)]: null,
[Symbol(kCapture)]: false,
[Symbol(kSetNoDelay)]: false,
[Symbol(kSetKeepAlive)]: true,
[Symbol(kSetKeepAliveInitialDelay)]: 60,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: [Object],
[Symbol(RequestTimeout)]: undefined
},
_header: 'GET /swap/v1/quote?sellAmount=20000000000000000&sellToken=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c&buyToken=0x77fc65deda64f0cca9e3aea7b9d8521f4151882e&takerAddress=0x1404585C6cF024e12Ae471475084ebdEDEc40a8A&intentOnFill=true&slippagePercentage=10&feeRecipient=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d&affiliateAddress=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d HTTP/1.1\r\n' +
'Accept: application/json, text/plain, /\r\n' +
'User-Agent: axios/0.27.2\r\n' +
'Host: bsc.api.0x.org\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: Agent {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
defaultPort: 443,
protocol: 'https:',
options: [Object: null prototype],
requests: [Object: null prototype] {},
sockets: [Object: null prototype],
freeSockets: [Object: null prototype] {},
keepAliveMsecs: 1000,
keepAlive: false,
maxSockets: Infinity,
maxFreeSockets: 256,
scheduling: 'lifo',
maxTotalSockets: Infinity,
totalSocketCount: 1,
maxCachedSessions: 100,
_sessionCache: [Object],
[Symbol(kCapture)]: false
},
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/swap/v1/quote?sellAmount=20000000000000000&sellToken=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c&buyToken=0x77fc65deda64f0cca9e3aea7b9d8521f4151882e&takerAddress=0x1404585C6cF024e12Ae471475084ebdEDEc40a8A&intentOnFill=true&slippagePercentage=10&feeRecipient=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d&affiliateAddress=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d',
_ended: true,
res: IncomingMessage {
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 4,
_maxListeners: undefined,
socket: [TLSSocket],
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
rawHeaders: [Array],
rawTrailers: [],
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 400,
statusMessage: 'Bad Request',
client: [TLSSocket],
_consuming: false,
_dumped: false,
req: [Circular *1],
responseUrl: 'https://bsc.api.0x.org/swap/v1/quote?sellAmount=20000000000000000&sellToken=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c&buyToken=0x77fc65deda64f0cca9e3aea7b9d8521f4151882e&takerAddress=0x1404585C6cF024e12Ae471475084ebdEDEc40a8A&intentOnFill=true&slippagePercentage=10&feeRecipient=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d&affiliateAddress=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d',
redirects: [],
[Symbol(kCapture)]: false,
[Symbol(kHeaders)]: [Object],
[Symbol(kHeadersCount)]: 26,
[Symbol(kTrailers)]: null,
[Symbol(kTrailersCount)]: 0,
[Symbol(RequestTimeout)]: undefined
},
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'bsc.api.0x.org',
protocol: 'https:',
_redirectable: Writable {
_writableState: [WritableState],
_events: [Object: null prototype],
_eventsCount: 3,
_maxListeners: undefined,
_options: [Object],
_ended: true,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 0,
_requestBodyBuffers: [],
_onNativeResponse: [Function (anonymous)],
_currentRequest: [Circular 1],
_currentUrl: 'https://bsc.api.0x.org/swap/v1/quote?sellAmount=20000000000000000&sellToken=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c&buyToken=0x77fc65deda64f0cca9e3aea7b9d8521f4151882e&takerAddress=0x1404585C6cF024e12Ae471475084ebdEDEc40a8A&intentOnFill=true&slippagePercentage=10&feeRecipient=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d&affiliateAddress=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d',
[Symbol(kCapture)]: false
},
[Symbol(kCapture)]: false,
[Symbol(kBytesWritten)]: 0,
[Symbol(kEndCalled)]: true,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype] {
accept: [Array],
'user-agent': [Array],
host: [Array]
},
[Symbol(kUniqueHeaders)]: null
},
response: {
status: 400,
statusText: 'Bad Request',
headers: {
date: 'Tue, 17 Jan 2023 21:00:22 GMT',
'content-type': 'application/json; charset=utf-8',
'content-length': '150',
connection: 'close',
'x-powered-by': 'Express',
'cache-control': 'public, max-age=13, s-maxage=13',
'access-control-allow-origin': '
',
etag: 'W/"96-NJKkXQ0aMoKFfq+cEmbEHKju8T8"',
'strict-transport-security': 'max-age=15724800; includeSubDomains',
'access-control-allow-credentials': 'true',
'access-control-allow-methods': 'GET, PUT, POST, DELETE, PATCH, OPTIONS',
'access-control-allow-headers': 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,0x-api-key',
'access-control-max-age': '1728000'
},
config: {
transitional: [Object],
adapter: [Function: httpAdapter],
transformRequest: [Array],
transformResponse: [Array],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: [Object],
validateStatus: [Function: validateStatus],
headers: [Object],
method: 'get',
url: 'https://bsc.api.0x.org/swap/v1/quote?sellAmount=20000000000000000&sellToken=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c&buyToken=0x77fc65deda64f0cca9e3aea7b9d8521f4151882e&takerAddress=0x1404585C6cF024e12Ae471475084ebdEDEc40a8A&intentOnFill=true&slippagePercentage=10&feeRecipient=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d&affiliateAddress=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d',
data: undefined
},
request: <ref *1> ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: false,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
strictContentLength: false,
_contentLength: 0,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
_closed: false,
socket: [TLSSocket],
_header: 'GET /swap/v1/quote?sellAmount=20000000000000000&sellToken=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c&buyToken=0x77fc65deda64f0cca9e3aea7b9d8521f4151882e&takerAddress=0x1404585C6cF024e12Ae471475084ebdEDEc40a8A&intentOnFill=true&slippagePercentage=10&feeRecipient=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d&affiliateAddress=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d HTTP/1.1\r\n' +
'Accept: application/json, text/plain, /\r\n' +
'User-Agent: axios/0.27.2\r\n' +
'Host: bsc.api.0x.org\r\n' +
'Connection: close\r\n' +
'\r\n',
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: 'GET',
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: '/swap/v1/quote?sellAmount=20000000000000000&sellToken=0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c&buyToken=0x77fc65deda64f0cca9e3aea7b9d8521f4151882e&takerAddress=0x1404585C6cF024e12Ae471475084ebdEDEc40a8A&intentOnFill=true&slippagePercentage=10&feeRecipient=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d&affiliateAddress=0x5bD68B4d6f90Bcc9F3a9456791c0Db5A43df676d',
_ended: true,
res: [IncomingMessage],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: 'bsc.api.0x.org',
protocol: 'https:',
_redirectable: [Writable],
[Symbol(kCapture)]: false,
[Symbol(kBytesWritten)]: 0,
[Symbol(kEndCalled)]: true,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype],
[Symbol(kUniqueHeaders)]: null
},
data: {
code: 100,
reason: 'Validation Failed',
validationErrors: [Array]
}
}
}
error processing a buy
next trade will be in 486.73015811932123 s

@kumarbitindi
Copy link
Author

baseTokenAddress: '0x77fc65deda64f0cca9e3aea7b9d8521f4151882e',
quoteTokenAddress: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
chainId: ChainId.BSC,
maxBuyUnit: 0.02,
minBuyUnit: 0.01,
minSellUnit: 0.01,
maxSellUnit: 0.02,
minIntervalSeconds: 60 * 5,
maxIntervalSeconds: 60 * 10,
slippagePercentage: 10,
maxGasValueInGwei: 50

@kumarbitindi
Copy link
Author

token have 1% buy and 1% transfer fees only

@JoaoCampos89
Copy link
Member

Slippage pergentage should be a value between 0 and 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants