This project implements a Decentralized Finance (DeFi) application using a Diamond architecture to facilitate Dollar Cost Averaging (DCA) strategies across various ERC-20 tokens and MultiBatch Swap Facet to reduce gas using Diamond. The system leverages the Diamond standard (EIP-2535) for flexibility and upgradability, and Uniswap/Quickswap for token swapping and liquidity management.
dApp is hosted on Cloudflare using Static Site Generation preview: https://pineapple-finance.pages.dev/
Forked Network Polygon is on AWS EC2 instance
DNS: https://ankit5577.eu.org
ec2 ip: 65.2.170.179
The project integrates multiple facets in a diamond architecture to manage different aspects of DCA strategies:
- [WIP] MultiBatchSwapFacet: Allows for batch token swaps, enabling users to swap multiple tokens in a single trensaction .
- [WIP] DCAFacet: Manages the lifecycle of DCA orders, including token swaps via Uniswap/Quickswap.
- TokenManagementFacet: Handles ERC-20 token interactions.
- [WIP] PriceAggregatorFacet: Interfaces with price feed oracles to obtain real-time price data.
- PriceFeedRegistry: Maintains mappings of tokens to their price feeds for real-time price retrieval.
- core: Contains Hardhat and contract-related code.
- app: Contains frontend code built with Next.js.
- Node.js (v14.x or later)
- npm or Yarn or Bun
- Hardhat
- Solidity (v0.8.x)
- OpenZeppelin Contracts
- Next.js (v14 or later)
Clone the repository and install the dependencies:
git clone https://github.com/RudraSphere/pineapple-finance.git
cd pineapple-finance
# for CORE / HARDHAT / CONTRACTS
cd core
npm install -f
# for dAPP / NextJS
cd app
npm install -f
or using Yarn or Bun
yarn install
# or
bun install --clean
Create a .env file at the root of the project directory and populate it with the necessary environment variables:
PK=your-wallet-private-key
MNEMONICS=
Run Node in different terminal w/o deploying (this Project uses a Polygon fork):
npx hardhat node --no-deploy
Compile the smart contracts with Hardhat:
npx hardhat compile
Deploy the contracts to a local testnet or to a live network:
npx hardhat deploy --network localhost
Execute the test suite to ensure the contracts function as expected:
npx hardhat test --grep "" --network localhost
Ensure code consistency using Prettier:
npx prettier --write "contracts/**/*.sol"
# OR
npm run prettier
npm run clean
# for USDC
npx hardhat run scripts/getUsdc.ts --network localhost
# for SHIB
npx hardhat run scripts/getShib.ts --network localhost
The DCAFacet integrates with Uniswap/Quickswap to perform token swaps during DCA order execution. It uses the Uniswap/Quickswap Router for token-to-token swaps and interacts with liquidity pools.
The MultiBatchSwapFacet enables batch token swaps, providing flexibility in swap routes and allowing for multi-hop swaps. This can be useful when direct swap routes don't exist, enabling a more complex swap logic.
Use the batchSwapsToSingleToken
function to swap multiple tokens in one transaction:
Use the batchSwapToSingleToken
function to swap single tokens in one transaction with Hop route if it does not exists:
function batchSwapsToSingleToken(
address[] memory inputTokens,
uint256[] memory inputAmounts,
address outputToken,
address recipient,
uint256 slippageTolerance
) external;
function batchSwapToSingleToken(
address fromToken,
address toToken,
uint256 amount,
address recipient
) external;
- Setting up a DCA Order: Use the setupDCA function to initiate a new DCA order.
function setupDCA(
address _tokenAddress,
uint256 _totalAmount,
uint256 _interval,
uint256 _orderCount
) external;
- Executing a DCA Order: Manually or automatically trigger the execution of DCA orders.
function executeDCA(uint index) public;
- Querying Order Details: Fetch details about specific or all DCA orders for a user.
function getOrderDetails(address user, uint index) public view returns (DCAOrder memory);
function getAllOrders(address user) public view returns (DCAOrder[] memory);