Created
July 13, 2025 11:02
-
-
Save gr1zix/057271fe3057be1d6cd47a627b4603d4 to your computer and use it in GitHub Desktop.
Add liq FS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const addLiquidityTab = '/html/body/div/div[2]/main/div/div[1]/div/div[2]/div/div[2]/div[2]/div[1]/button[1]'; | |
const removeLiquidityTab = '/html/body/div/div[2]/main/div/div[1]/div/div[2]/div/div[2]/div[2]/div[1]/button[2]'; | |
const nativeTokenInput = '/html/body/div/div[2]/main/div/div[1]/div/div[2]/div/div[2]/div[2]/div[2]/div[1]/div[1]/div[2]/input'; | |
const usdcInput = '/html/body/div/div[2]/main/div/div[1]/div/div[2]/div/div[2]/div[2]/div[2]/div[1]/div[3]/div[2]/input'; | |
const addButton = '/html/body/div/div[2]/main/div/div[1]/div/div[2]/div/div[2]/div[2]/div[2]/div[2]/button'; | |
function getElementByXpath(path) { | |
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | |
} | |
function getRandomAmount(min = 0.5, max = 5) { | |
return (Math.random() * (max - min) + min).toFixed(3); | |
} | |
function getRandom(min, max) { | |
return Math.floor(Math.random() * (max - min) ) + min; | |
} | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
function setReactInputValue(element, value) { | |
try { | |
if (!element || typeof element.value === 'undefined') { | |
throw new Error('Element is not a valid input'); | |
} | |
const descriptor = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value'); | |
if (!descriptor || !descriptor.set) { | |
element.value = value; | |
element.dispatchEvent(new Event('input', { bubbles: true })); | |
return; | |
} | |
descriptor.set.call(element, value); | |
const events = ['input', 'change', 'blur']; | |
events.forEach(type => { | |
element.dispatchEvent(new Event(type, { bubbles: true })); | |
}); | |
} catch (error) { | |
console.error('Error in setReactInputValue:', error); | |
if (element) { | |
element.value = value; | |
element.dispatchEvent(new Event('input', { bubbles: true })); | |
} | |
} | |
} | |
async function sendForm() { | |
try { | |
await sleep(1000); | |
// 1. Enter input amount | |
const liquidityAmountInputElement = getElementByXpath(usdcInput); | |
if (!liquidityAmountInputElement) throw new Error('Amount input not found'); | |
setReactInputValue(liquidityAmountInputElement, getRandomAmount()); | |
await sleep(300); | |
// 2. Click button to add simulate transaction | |
const addFormBtn = getElementByXpath(addButton); | |
if (!addFormBtn) throw new Error('Add form button not found'); | |
addFormBtn.click(); | |
await sleep(1000); | |
// 3. Click remove liquidity tab to reset Adding form | |
const removeLiquidityTabBtn = getElementByXpath(removeLiquidityTab); | |
if (!removeLiquidityTabBtn) throw new Error('Remove liquidity tab not found'); | |
removeLiquidityTabBtn.click(); | |
await sleep(300); | |
// 4. Click remove liquidity tab to reset Adding form | |
const addLiquidityTabBtn = getElementByXpath(addLiquidityTab); | |
if (!addLiquidityTabBtn) throw new Error('Add liquidity tab not found'); | |
addLiquidityTabBtn.click(); | |
await sleep(300); | |
return true; | |
} catch (error) { | |
console.error('Error during form submission:', error); | |
return false; | |
} | |
} | |
async function runIterations(iterations, delayBetweenIterationsFrom = 500, delayBetweenIterationsTo = 2000) { | |
let isCancelled = false; | |
let completedIterations = 0; | |
// Function to cancel execution | |
const cancel = () => { | |
isCancelled = true; | |
}; | |
// To be able to cancel from console, we can expose `cancel` function globally | |
window.cancelScript = cancel; | |
console.log("To stop execution, type 'window.cancelScript()' in the console."); | |
for (let i = 0; i < iterations && !isCancelled; i++) { | |
console.log(`Starting iteration ${i + 1}/${iterations}`); | |
const success = await sendForm(); | |
if (!success) { | |
console.log(`Iteration ${i + 1} failed. Stopping.`); | |
break; | |
} | |
completedIterations++; | |
console.log(`Iteration ${i + 1} completed successfully.`); | |
if (i < iterations - 1 && !isCancelled) { | |
const delay = getRandom(delayBetweenIterationsFrom, delayBetweenIterationsTo) | |
console.log(`Waiting for ${delay}ms before next iteration...`); | |
await sleep(delay); | |
} | |
} | |
console.log(`Completed ${completedIterations} of ${iterations} iterations.`); | |
window.cancelScript = undefined; // Clean up | |
return { completed: completedIterations, cancelled: isCancelled }; | |
} | |
/** | |
* 30 - iterations | |
* 500 - start of range delay in ms between iterations | |
* 1500 - end of range delay in ms between iterations | |
*/ | |
runIterations(20, 500, 1500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment