Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 66 additions & 49 deletions script/DeployAllContract.s.sol
Original file line number Diff line number Diff line change
@@ -1,49 +1,66 @@
// // SPDX-License-Identifier: MIT
// pragma solidity ^0.8.0;

// import "forge-std/Script.sol";
// import "../src/Router.sol";
// import "../src/Pool.sol";
// import "../src/PoolLogic.sol";

// contract DeployAllContract is Script {
// function run() external {
// address ZERO_ADDRESS = address(0);
// // Fetch the OWNER_ADDRESS from the environment variables
// address ownerAddress = vm.envAddress("OWNER_ADDRESS");
// console.log("Owner address:", ownerAddress);

// // Fetch the VAULT_ADDRESS from the environment variables
// address vaultAddress = vm.envAddress("VAULT_ADDRESS");
// console.log("Vault address:", vaultAddress);

// // Fetch the PRIVATE_KEY from the environment variables
// uint256 privateKey = vm.envUint("PRIVATE_KEY");

// // Start broadcasting transactions
// vm.startBroadcast(privateKey);

// // Step 1: Deploy Pool contract
// Pool pool = new Pool(vaultAddress, ZERO_ADDRESS, ZERO_ADDRESS);
// console.log("Pool deployed to:", address(pool));

// // Step 2: Deploy PoolLogic contract with Pool address
// PoolLogic poolLogic = new PoolLogic(ownerAddress, address(pool));
// console.log("PoolLogic deployed to:", address(poolLogic));

// // Step 3: Deploy Router contract with Pool address
// Router router = new Router(ownerAddress, address(pool));
// console.log("Router deployed to:", address(router));

// // Step 4: Update Pool contract with Router address
// pool.updateRouterAddress(address(router));
// console.log("Router address updated in Pool:", address(router));

// // Step 5: Update Pool contract with PoolLogic address
// pool.updatePoolLogicAddress(address(poolLogic));
// console.log("PoolLogic address updated in Pool:", address(poolLogic));

// // Stop broadcasting transactions
// vm.stopBroadcast();
// }
// }
// SPDX - License - Identifier: MIT
pragma solidity 0.8.28;

import "forge-std/Script.sol";
import "../src/Router.sol";
import "../src/Pool.sol";
import "../src/PoolLogic.sol";
import "../src/LiquidityLogic.sol";

contract DeployAllContract is Script {
function run() external {
address ZERO_ADDRESS = address(0);
// Fetch the OWNER_ADDRESS from the environment variables
address ownerAddress = vm.envAddress("OWNER_ADDRESS");
console.log("Owner address:", ownerAddress);

// Fetch the VAULT_ADDRESS from the environment variables
address vaultAddress = vm.envAddress("VAULT_ADDRESS");
console.log("Vault address:", vaultAddress);

// Fetch the PRIVATE_KEY from the environment variables
uint256 privateKey = vm.envUint("PRIVATE_KEY");

// Start broadcasting transactions
vm.startBroadcast(privateKey);

// Step 1: Deploy PoolLogic contract
PoolLogic poolLogic = new PoolLogic(ownerAddress, ZERO_ADDRESS, ZERO_ADDRESS);
console.log("PoolLogic deployed to:", address(poolLogic));

// Step 2: Deploy PoolLogic contract
LiquidityLogic liquidityLogic = new LiquidityLogic(ownerAddress, ZERO_ADDRESS, ZERO_ADDRESS);
console.log("LiquidityLogic deployed to:", address(liquidityLogic));

// Step 3: Deploy Pool contract
Pool pool = new Pool(vaultAddress, ZERO_ADDRESS, address(poolLogic), address(liquidityLogic));
console.log("Pool deployed to:", address(pool));

// Step 4: Deploy Router contract with Pool address
Router router = new Router(ownerAddress, address(pool));
console.log("Router deployed to:", address(router));

// Step 5: Update Pool contract with Router address
pool.updateRouterAddress(address(router));
console.log("Router address updated in Pool:", address(router));

// Step 6: Update Pool logic contract with Pool address
poolLogic.updatePoolAddress(address(pool));
console.log("Pool address updated in PoolLogic:", address(pool));

// Step 7: Update Pool logic contract with LiquidityLogic address
poolLogic.updateLiquidityLogicAddress(address(liquidityLogic));
console.log("LiquidityLogic address updated in PoolLogic:", address(liquidityLogic));

// Step 8: Update LiquidityLogic contract with Pool address
liquidityLogic.updatePoolAddress(address(pool));
console.log("Pool address updated in LiquidityLogic:", address(pool));

// Step 9: Update LiquidityLogic contract with PoolLogic address
liquidityLogic.updatePoolLogicAddress(address(poolLogic));
console.log("PoolLogic address updated in LiquidityLogic:", address(poolLogic));

// Stop broadcasting transactions
vm.stopBroadcast();
}
}
51 changes: 51 additions & 0 deletions src/LiquidityLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -655,4 +655,55 @@ contract LiquidityLogic is ILiquidityLogic {
}
}
}

// Methods to emit events
function emitAddLiquidityEntered(
uint256 id,
address token,
address user,
uint256 amount,
uint256 streamCount
) internal {
emit AddLiquidityEntered(id, token, user, amount, streamCount);
}

function emitRemoveLiquidityEntered(
uint256 id,
address token,
address user,
uint256 amount,
uint256 streamCount
) internal {
emit RemoveLiquidityEntered(id, token, user, amount, streamCount);
}

function emitAddLiquidityStreamExecuted(
uint256 id
) internal {
emit AddLiquidityStreamExecuted(id);
}

function emitRemoveLiquidityStreamExecuted(
uint256 id
) internal {
emit RemoveLiquidityStreamExecuted(id);
}

function emitGenesisPoolInitialized(
address token,
address user,
uint256 tokenAmount,
uint256 initialDToMint
) internal {
emit GenesisPoolInitialized(token, user, tokenAmount, initialDToMint);
}

function emitPoolInitialized(
bytes32 pairId,
address user,
uint256 tokenAmount,
uint256 dTokenAmount
) internal {
emit PoolInitialized(pairId, user, tokenAmount, dTokenAmount);
}
}
38 changes: 38 additions & 0 deletions src/PoolLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ contract PoolLogic is IPoolLogic {
currentSwap.tokenOut, currentSwap.user, currentSwap.amountOut
);
}

emitSwapUpdated(currentSwap.swapID, currentSwap.streamsRemaining, currentSwap.swapPerStream);
} else if (currentSwap.typeOfOrder == 1 && currentSwap.executionPrice == currentExecPrice) {
currentSwap = _executeStreamAgainstPool(currentSwap);
currentSwap.typeOfOrder++;
Expand All @@ -194,6 +196,8 @@ contract PoolLogic is IPoolLogic {
currentSwap.tokenOut, currentSwap.user, currentSwap.amountOut
);
}

emitSwapUpdated(currentSwap.swapID, currentSwap.streamsRemaining, currentSwap.swapPerStream);
}

unchecked {
Expand Down Expand Up @@ -713,6 +717,8 @@ contract PoolLogic is IPoolLogic {
}
currentSwap.amountOut += amountOut;

emitSwapAgainstPool(currentSwap.swapID, swapAmountIn, amountOut);

return currentSwap;
}

Expand Down Expand Up @@ -897,4 +903,36 @@ contract PoolLogic is IPoolLogic {
function STREAM_COUNT_PRECISION() external view override returns (uint256) {
return liquidityLogic.STREAM_COUNT_PRECISION();
}

function emitSwapEntered(
uint256 swapID,
bytes32 pairId,
uint256 swapAmount,
uint256 executionPrice,
address user,
uint8 typeOfOrder
)
internal
{
emit SwapEntered(swapID, pairId, swapAmount, executionPrice, user, typeOfOrder);
}

function emitSwapAgainstOrderBook(
uint256 swapIdIncoming,
uint256 swapIdOpposite,
uint256 settledAmountIn,
uint256 settledAmountOut
)
internal
{
emit SwapAgainstOrderBook(swapIdIncoming, swapIdOpposite, settledAmountIn, settledAmountOut);
}

function emitSwapUpdated(uint256 swapId, uint256 streamCountRemaining, uint256 swapPerStream) internal {
emit SwapUpdated(swapId, streamCountRemaining, swapPerStream);
}

function emitSwapAgainstPool(uint256 swapId, uint256 amountIn, uint256 amountOut) internal {
emit SwapAgainstPool(swapId, amountIn, amountOut);
}
}
44 changes: 44 additions & 0 deletions src/interfaces/liquidity-logic/ILiquidityLogicEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,48 @@ interface ILiquidityLogicEvents {
event PoolAddressUpdated(address, address);
event PoolLogicAddressUpdated(address, address);
event OwnerUpdated(address, address);

// Event 1: Add Liquidity Entered
event AddLiquidityEntered(
uint256 indexed id,
address token,
address user,
uint256 amount,
uint256 streamCount
);

// Event 2: Remove Liquidity Entered
event RemoveLiquidityEntered(
uint256 indexed id,
address token,
address user,
uint256 amount,
uint256 streamCount
);

// Event 3: Add Liquidity Stream Executed
event AddLiquidityStreamExecuted(
uint256 indexed id
);

// Event 4: Remove Liquidity Stream Executed
event RemoveLiquidityStreamExecuted(
uint256 indexed id
);

// Event 5: Genesis Pool Initialized
event GenesisPoolInitialized(
address indexed token,
address indexed user,
uint256 tokenAmount,
uint256 initialDToMint
);

// Event 6: Pool Initialized
event PoolInitialized(
bytes32 indexed pairId,
address indexed user,
uint256 tokenAmount,
uint256 dTokenAmount
);
}
32 changes: 32 additions & 0 deletions src/interfaces/pool-logic/IPoolLogicEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,36 @@ interface IPoolLogicEvents {
event PoolAddressUpdated(address, address);
event LiquidityLogicAddressUpdated(address, address);
event OwnerUpdated(address, address);

// Event 1: SwapEntered called every time when a swap is started
event SwapEntered(
uint256 indexed swapID, // Unique identifier for the swap
bytes32 indexed pairId, // Token pair identifier (e.g., token AB)
uint256 indexed swapAmount, // Total amount involved in the swap (tokenIn)
uint256 executionPrice, // Current execution price (D/token during swap)
address user, // Address of the user initiating the swap
uint8 typeOfOrder // 1 = TRIGGER, 2 = MARKET, 3 = LIMIT
);

// Event 2: SwapAgainstOrderBook called every time when a swap is settled against opposite swap
event SwapAgainstOrderBook(
uint256 indexed swapIdIncoming, // Identifier linking the stream to its parent swap
uint256 indexed swapIdOpposite, // Identifier of the opposite swap
uint256 settledAmountIn, // (tokenIn) Amount involved in the stream
uint256 settledAmountOut // (tokenOut) Amount involved in the stream
);

// Event 3: SwapUpdated Called every time stream count is recalculated
event SwapUpdated(
uint256 indexed swapId, // Swap ID
uint256 indexed streamCountRemaining, // 0 as false if there is no opposite swap
uint256 indexed swapPerStream // Amount per stream
);

// Event 4: SwapAgainstPool called every time when a swap is settled against pool
event SwapAgainstPool(
uint256 indexed swapId, // Identifier linking the stream to its parent swap
uint256 amountIn, // Input amount
uint256 amountOut // Output amount
);
}