Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
22388o authored Oct 7, 2023
1 parent d1333ec commit 5244cc9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,35 @@
return 0; // Return 0 in case of an error
}
}
let liquidityPool = {
btcBalance: 1000, // Initial BTC balance in the pool
usdtBalance: 35000, // Initial USDT balance in the pool
};

// Function to handle the swap button click event
function handleSwap() {
const btcInput = document.getElementById('btcInput');
const usdtInput = document.getElementById('usdtInput');

const btcAmount = parseFloat(btcInput.value);
const usdtAmount = parseFloat(usdtInput.value);

if (isNaN(btcAmount) || isNaN(usdtAmount)) {
alert('Please enter valid amounts.');
return;
}

// Calculate new BTC and USDT amounts based on the AMM formula x * y = k
const k = liquidityPool.btcBalance * liquidityPool.usdtBalance;
const newBtcBalance = liquidityPool.btcBalance + btcAmount;
const newUsdtBalance = k / newBtcBalance;

liquidityPool.btcBalance = newBtcBalance;
liquidityPool.usdtBalance = newUsdtBalance;

// Add event listener to the swap button
const swapButton = document.getElementById('swapButton');
swapButton.addEventListener('click', handleSwap);

// Function to handle the swap button click event
async function handleSwap() {
Expand Down

0 comments on commit 5244cc9

Please sign in to comment.