Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 50dbccf

Browse files
committed
bug fix on approve
1 parent 7f49139 commit 50dbccf

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export const config = {
1919
SELL: 2
2020
},
2121
SLIPPAGE: 0.5,
22+
GAS_LIMIT: process.env.GAS_LIMIT!,
2223
EXPLORER: process.env.EXPLORER || 'https://etherscan.io/',
23-
2424
PRICE_CHECK_INTERVAL_IN_SECONDS: process.env.PRICE_CHECK_INTERVAL_IN_SECONDS || 45,
2525
ETH_IN_AMOUNT: parseFloat(process.env.ETH_IN_AMOUNT!),
2626
DB_URL: process.env.DB_URL!

src/index.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const Main = async () => {
138138
console.log(`Buy Tx Data:`, txData);
139139

140140
// send a buy Tx
141-
nonce++;
141+
nonce += 1;
142142
oneInch.sendTx({
143143
data: txData.tx,
144144
nonce
@@ -156,13 +156,13 @@ const Main = async () => {
156156
* Approve Token if it has not been approved before and save it to db
157157
*/
158158
// approve if token has not been approved
159-
const token_is_approved = await Approve.exists({ token: token, by: process.env.PUBLIC_KEY!.toLowerCase() })
159+
const token_is_approved = await Approve.exists({ token: token })
160160
if (!token_is_approved) {
161161
// approve if not approved
162162
message = `Approving ${token.name}...`
163163
sendMessage(users, message)
164164
let txData = await oneInch.approve(token.address)
165-
nonce++;
165+
nonce += 1;
166166
await oneInch.sendTx({
167167
data: txData.tx,
168168
nonce
@@ -182,7 +182,7 @@ const Main = async () => {
182182
let tries = 0
183183
let tokenBalance = '0'
184184
while (tries < 2000) {
185-
tokenBalance = await oneInch.balanceOf(tx.toToken.address)
185+
tokenBalance = await oneInch.balanceOf(token.address)
186186
if (parseInt(tokenBalance) > parseInt(new BigNumber(token_amount).multipliedBy(0.5).toString())) {
187187
break
188188
}
@@ -206,10 +206,11 @@ const Main = async () => {
206206
console.log(`Sell Tx Data:`, txData);
207207

208208
// send the sell Tx
209-
nonce++;
209+
nonce += 1;
210210
oneInch.sendTx({
211211
data: txData.tx,
212-
nonce
212+
nonce,
213+
gasLimit: config.GAS_LIMIT
213214
}).then(async (tx: any) => {
214215
if (tx.hash) {
215216
console.log(`Tx for Sell:`, tx.hash)

src/lib/1inch.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ export class OneInch extends Aggr {
9696
method: "GET",
9797
url: `${this.API_URL}${config.NETWORK.ID}/approve/calldata?tokenAddress=${tokenAddress}`
9898
})
99-
delete data.tx.gasPrice; //ethersjs will find the gasPrice needed
100-
delete data.tx.gas;
99+
console.log(data)
100+
delete data.gasPrice; //ethersjs will find the gasPrice needed
101+
delete data.gas;
101102

102-
data.tx["value"] = toHex(parseInt(data.tx["value"]))
103+
data["value"] = toHex(parseInt(data["value"]))
103104
return data
104105
} catch (error: any) {
105106
throw new Error(error);

src/lib/aggr.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ export abstract class Aggr {
1919
* @param nonce - wallet current nonce
2020
* @returns Tx hash if successful else error message
2121
*/
22-
sendTx = async (params: { data: any, nonce: number }) => {
23-
const { data, nonce } = params
22+
sendTx = async (params: { data: any, gasLimit?: string, nonce: number }) => {
23+
const { data, gasLimit, nonce } = params
2424
try {
2525

26-
if (!isNaN(nonce)) {
27-
data.nonce = nonce + 1
26+
// if (!isNaN(nonce)) {
27+
// data.nonce = nonce + 1
28+
// }
29+
if (gasLimit) {
30+
data.gasLimit = gasLimit
2831
}
2932

3033
const tx = await this.account.sendTransaction(data)

0 commit comments

Comments
 (0)