Spaces:
No application file
No application file
Create index.html
Browse files- index.html +62 -0
index.html
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
try {
|
| 3 |
+
showStatus('Preparing swap...');
|
| 4 |
+
const router = new ethers.Contract(CONFIG.ROUTER_ADDRESS, ROUTER_ABI, signer);
|
| 5 |
+
// NOTE: In production use WBNB address and proper path. Here we use placeholder.
|
| 6 |
+
const WBNB = '0xBB4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c'; // mainnet WBNB (demo) — replace for testnet if needed
|
| 7 |
+
const path = [WBNB, CONFIG.TOKEN_ADDRESS];
|
| 8 |
+
const deadline = Math.floor(Date.now() / 1000) + 60 * 10;
|
| 9 |
+
const amountIn = ethers.utils.parseEther('0.05');
|
| 10 |
+
const tx = await router.swapExactETHForTokens(0, path, account, deadline, { value: amountIn });
|
| 11 |
+
showStatus('Swap tx sent: ' + tx.hash);
|
| 12 |
+
await tx.wait();
|
| 13 |
+
showStatus('Swap confirmed: ' + tx.hash);
|
| 14 |
+
window.open(CONFIG.BSCSCAN_BASE + 'tx/' + tx.hash, '_blank');
|
| 15 |
+
} catch (e) { console.error(e); showStatus('Swap failed: ' + (e.message || e)); }
|
| 16 |
+
};
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
// Add liquidity
|
| 20 |
+
addLPBtn.onclick = async () => {
|
| 21 |
+
try {
|
| 22 |
+
showStatus('Adding liquidity...');
|
| 23 |
+
const router = new ethers.Contract(CONFIG.ROUTER_ADDRESS, ROUTER_ABI, signer);
|
| 24 |
+
const token = new ethers.Contract(CONFIG.TOKEN_ADDRESS, TOKEN_ABI, signer);
|
| 25 |
+
const tokenAmount = ethers.utils.parseUnits('1000', 18);
|
| 26 |
+
const ethAmount = ethers.utils.parseEther('0.05');
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
const approveTx = await token.approve(CONFIG.ROUTER_ADDRESS, tokenAmount);
|
| 30 |
+
showStatus('Approve tx: ' + approveTx.hash);
|
| 31 |
+
await approveTx.wait();
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
const deadline = Math.floor(Date.now() / 1000) + 60 * 10;
|
| 35 |
+
const tx = await router.addLiquidityETH(CONFIG.TOKEN_ADDRESS, tokenAmount, 0, 0, account, deadline, { value: ethAmount });
|
| 36 |
+
showStatus('AddLiquidity tx sent: ' + tx.hash);
|
| 37 |
+
await tx.wait();
|
| 38 |
+
showStatus('Liquidity added: ' + tx.hash);
|
| 39 |
+
window.open(CONFIG.BSCSCAN_BASE + 'tx/' + tx.hash, '_blank');
|
| 40 |
+
} catch (e) { console.error(e); showStatus('Add liquidity failed: ' + (e.message || e)); }
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
// Stake LP (demo)
|
| 45 |
+
stakeLPBtn.onclick = async () => {
|
| 46 |
+
try {
|
| 47 |
+
showStatus('Staking LP...');
|
| 48 |
+
const staking = new ethers.Contract(CONFIG.STAKING_ADDRESS, STAKING_ABI, signer);
|
| 49 |
+
const amount = ethers.utils.parseUnits('1', 18); // stake 1 LP (demo)
|
| 50 |
+
const tx = await staking.stake(amount);
|
| 51 |
+
showStatus('Stake tx sent: ' + tx.hash);
|
| 52 |
+
await tx.wait();
|
| 53 |
+
showStatus('Stake confirmed: ' + tx.hash);
|
| 54 |
+
window.open(CONFIG.BSCSCAN_BASE + 'tx/' + tx.hash, '_blank');
|
| 55 |
+
} catch (e) { console.error(e); showStatus('Stake failed: ' + (e.message || e)); }
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
// Refresh balances (demo)
|
| 60 |
+
refreshBtn.onclick = async () => {
|
| 61 |
+
try {
|
| 62 |
+
if (!pr
|