Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit50dbccf

Browse files
committed
bug fix on approve
1 parent7f49139 commit50dbccf

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

‎config.ts‎

Lines changed: 1 addition & 1 deletion
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‎

Lines changed: 7 additions & 6 deletions
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-
consttoken_is_approved=awaitApprove.exists({token:token,by:process.env.PUBLIC_KEY!.toLowerCase()})
159+
consttoken_is_approved=awaitApprove.exists({token:token})
160160
if(!token_is_approved){
161161
// approve if not approved
162162
message=`Approving${token.name}...`
163163
sendMessage(users,message)
164164
lettxData=awaitoneInch.approve(token.address)
165-
nonce++;
165+
nonce+=1;
166166
awaitoneInch.sendTx({
167167
data:txData.tx,
168168
nonce
@@ -182,7 +182,7 @@ const Main = async () => {
182182
lettries=0
183183
lettokenBalance='0'
184184
while(tries<2000){
185-
tokenBalance=awaitoneInch.balanceOf(tx.toToken.address)
185+
tokenBalance=awaitoneInch.balanceOf(token.address)
186186
if(parseInt(tokenBalance)>parseInt(newBigNumber(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‎

Lines changed: 4 additions & 3 deletions
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-
deletedata.tx.gasPrice;//ethersjs will find the gasPrice needed
100-
deletedata.tx.gas;
99+
console.log(data)
100+
deletedata.gasPrice;//ethersjs will find the gasPrice needed
101+
deletedata.gas;
101102

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

‎src/lib/aggr.ts‎

Lines changed: 7 additions & 4 deletions
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
consttx=awaitthis.account.sendTransaction(data)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp