-
Notifications
You must be signed in to change notification settings - Fork 2
Fix ETH calculation overflow, add comprehensive price documentation, and setup CI/CD pipeline for SEQICO contract #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
679e1a3
4c0ee12
b4d63bb
6b54682
1c745d7
df8aae0
eb91fb6
34b2d00
f87f73d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| name: CI/CD Pipeline | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| workflow_dispatch: # Allows you to manually trigger the workflow | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build Contracts | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 18 | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Compile contracts | ||
| run: npx hardhat compile | ||
|
|
||
| test: | ||
| name: Run Tests | ||
| runs-on: ubuntu-latest | ||
| needs: build # Ensures tests run after build stage | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 18 | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Run tests | ||
| run: npx hardhat test | ||
|
|
||
| deploy: | ||
| name: Deploy Contracts | ||
| runs-on: ubuntu-latest | ||
| needs: test # Ensures deployment runs after tests pass | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 18 | ||
|
|
||
| - name: Install dependencies | ||
| run: npm install | ||
|
|
||
| - name: Deploy contracts | ||
| run: npx hardhat run scripts/deploy.js --network mainnet | ||
| env: | ||
| PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} | ||
| INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,16 @@ contract SEQICO is Ownable { | |
| IERC20 public usdt; | ||
| IERC20 public usdc; | ||
|
|
||
| // Price per token in wei (ETH has 18 decimals) | ||
| // Example: 0.00189 ETH per token (approximately $3.79 at $2000/ETH) | ||
| uint256 public pricePerTokenETH; | ||
|
|
||
| // Price per token in USDT units (USDT has 6 decimals) | ||
| // Example: 3790000 = 3.79 USDT per token | ||
| uint256 public pricePerTokenUSDT; | ||
|
|
||
| // Price per token in USDC units (USDC has 6 decimals) | ||
| // Example: 3790000 = 3.79 USDC per token | ||
| uint256 public pricePerTokenUSDC; | ||
|
|
||
| event TokensPurchased(address indexed buyer, uint256 amount, string payment); | ||
|
|
@@ -37,7 +45,9 @@ contract SEQICO is Ownable { | |
|
|
||
| function buyWithETH(uint256 tokenAmount) external payable { | ||
| require(tokenAmount > 0, "Amount must be greater than 0"); | ||
| uint256 requiredETH = pricePerTokenETH * tokenAmount; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot fill in this info There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need clarification on what specific information you'd like me to add on line 40. Are you looking for:
Please let me know what information you'd like me to fill in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot correct and numbers that may be wrong There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot fix all errors There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed syntax errors and corrected all incorrect numbers in the contract. Removed erroneous decimal values from variable declarations and constructor parameters, while preserving the ETH calculation fix. Commit: df8aae0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed syntax errors and corrected all incorrect numbers in the contract. Removed erroneous decimal values from variable declarations and constructor parameters, while preserving the ETH calculation fix. Commit: df8aae0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fill in the values for eth, usdc, usdt There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added example values for ETH, USDT, USDC pricing based on $3.79 token price. Created price-examples.js script showing calculations: ETH (0.001895), USDT (3790000), USDC (3790000). Added detailed documentation in the contract explaining each price variable. Commit: 34b2d00 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed all syntax issues and added comprehensive documentation for price calculations. Added detailed comments explaining the division by 1e18 and created example scripts showing how to set values for ETH, USDT, and USDC pricing. Commit: 34b2d00 |
||
| // Calculate required ETH: price per token * number of tokens / 1e18 | ||
| // Division by 1e18 converts from wei units to prevent overflow | ||
| uint256 requiredETH = pricePerTokenETH * tokenAmount / 1e18; | ||
| require(msg.value >= requiredETH, "Insufficient ETH sent"); | ||
| require(seqToken.balanceOf(address(this)) >= tokenAmount, "Not enough SEQ tokens"); | ||
|
|
||
|
|
@@ -53,6 +63,7 @@ contract SEQICO is Ownable { | |
|
|
||
| function buyWithUSDT(uint256 tokenAmount) external { | ||
| require(tokenAmount > 0, "Amount must be greater than 0"); | ||
| // Calculate required USDT: price per token * number of tokens / 1e18 | ||
| uint256 requiredUSDT = pricePerTokenUSDT * tokenAmount / 1e18; | ||
| require(seqToken.balanceOf(address(this)) >= tokenAmount, "Not enough SEQ tokens"); | ||
| require(usdt.allowance(msg.sender, address(this)) >= requiredUSDT, "Approve USDT first"); | ||
|
|
@@ -65,6 +76,7 @@ contract SEQICO is Ownable { | |
|
|
||
| function buyWithUSDC(uint256 tokenAmount) external { | ||
| require(tokenAmount > 0, "Amount must be greater than 0"); | ||
| // Calculate required USDC: price per token * number of tokens / 1e18 | ||
| uint256 requiredUSDC = pricePerTokenUSDC * tokenAmount / 1e18; | ||
| require(seqToken.balanceOf(address(this)) >= tokenAmount, "Not enough SEQ tokens"); | ||
| require(usdc.allowance(msg.sender, address(this)) >= requiredUSDC, "Approve USDC first"); | ||
|
|
@@ -82,4 +94,4 @@ contract SEQICO is Ownable { | |
| function withdrawERC20(address token, address recipient) public onlyOwner { | ||
| IERC20(token).transfer(recipient, IERC20(token).balanceOf(address(this))); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Example values for SEQICO contract deployment | ||
| // Token price: $3.79 USD per SEQ token | ||
|
|
||
| import { ethers } from "hardhat"; | ||
|
|
||
| // Example price values for a $3.79 token | ||
| async function calculatePriceValues() { | ||
| console.log("=== SEQICO Price Calculation Examples ==="); | ||
| console.log("Target token price: $3.79 USD per SEQ token\n"); | ||
|
|
||
| // ETH Price Calculation | ||
| // Assuming ETH = $2000 USD (adjust based on current market price) | ||
| const ethPriceUSD = 2000; // Current ETH price in USD | ||
| const tokenPriceUSD = 3.79; | ||
| const tokenPriceETH = tokenPriceUSD / ethPriceUSD; // 3.79 / 2000 = 0.001895 ETH | ||
|
|
||
| const pricePerTokenETH = ethers.parseEther(tokenPriceETH.toString()); | ||
| console.log(`ETH Price Calculation:`); | ||
| console.log(`- ETH price: $${ethPriceUSD} USD`); | ||
| console.log(`- Token price in ETH: ${tokenPriceETH} ETH`); | ||
| console.log(`- pricePerTokenETH: ${pricePerTokenETH.toString()} wei`); | ||
| console.log(`- For deployment: ethers.parseEther("${tokenPriceETH}")\n`); | ||
|
|
||
| // USDT Price Calculation | ||
| // USDT has 6 decimal places | ||
| const pricePerTokenUSDT = ethers.parseUnits(tokenPriceUSD.toString(), 6); | ||
| console.log(`USDT Price Calculation:`); | ||
| console.log(`- Token price: $${tokenPriceUSD} USDT`); | ||
| console.log(`- pricePerTokenUSDT: ${pricePerTokenUSDT.toString()} (6 decimals)`); | ||
| console.log(`- For deployment: ethers.parseUnits("${tokenPriceUSD}", 6)\n`); | ||
|
|
||
| // USDC Price Calculation | ||
| // USDC has 6 decimal places | ||
| const pricePerTokenUSDC = ethers.parseUnits(tokenPriceUSD.toString(), 6); | ||
| console.log(`USDC Price Calculation:`); | ||
| console.log(`- Token price: $${tokenPriceUSD} USDC`); | ||
| console.log(`- pricePerTokenUSDC: ${pricePerTokenUSDC.toString()} (6 decimals)`); | ||
| console.log(`- For deployment: ethers.parseUnits("${tokenPriceUSD}", 6)\n`); | ||
|
|
||
| console.log("=== Complete Deployment Example ==="); | ||
| console.log(` | ||
| const SEQICO = await ethers.getContractFactory("SEQICO"); | ||
| const seqICO = await SEQICO.deploy( | ||
| seqTokenAddress, | ||
| usdtAddress, | ||
| usdcAddress, | ||
| ethers.parseEther("${tokenPriceETH}"), // ${tokenPriceETH} ETH per token | ||
| ethers.parseUnits("${tokenPriceUSD}", 6), // ${tokenPriceUSD} USDT per token | ||
| ethers.parseUnits("${tokenPriceUSD}", 6) // ${tokenPriceUSD} USDC per token | ||
| ); | ||
| `); | ||
|
|
||
| return { | ||
| pricePerTokenETH, | ||
| pricePerTokenUSDT, | ||
| pricePerTokenUSDC | ||
| }; | ||
| } | ||
|
|
||
| // Run the calculation | ||
| calculatePriceValues().catch(console.error); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Example values for SEQICO contract deployment | ||
| // Token price: $3.79 USD per SEQ token | ||
|
|
||
| console.log("=== SEQICO Price Calculation Examples ==="); | ||
| console.log("Target token price: $3.79 USD per SEQ token\n"); | ||
|
|
||
| // ETH Price Calculation | ||
| // Assuming ETH = $2000 USD (adjust based on current market price) | ||
| const ethPriceUSD = 2000; // Current ETH price in USD | ||
| const tokenPriceUSD = 3.79; | ||
| const tokenPriceETH = tokenPriceUSD / ethPriceUSD; // 3.79 / 2000 = 0.001895 ETH | ||
|
|
||
| // Calculate wei value (1 ETH = 1e18 wei) | ||
| const pricePerTokenETHWei = Math.floor(tokenPriceETH * 1e18); | ||
|
|
||
| console.log(`ETH Price Calculation:`); | ||
| console.log(`- ETH price: $${ethPriceUSD} USD`); | ||
| console.log(`- Token price in ETH: ${tokenPriceETH} ETH`); | ||
| console.log(`- pricePerTokenETH: ${pricePerTokenETHWei} wei`); | ||
| console.log(`- For deployment: ethers.parseEther("${tokenPriceETH}")\n`); | ||
|
|
||
| // USDT Price Calculation (6 decimal places) | ||
| const pricePerTokenUSDT = Math.floor(tokenPriceUSD * 1e6); | ||
| console.log(`USDT Price Calculation:`); | ||
| console.log(`- Token price: $${tokenPriceUSD} USDT`); | ||
| console.log(`- pricePerTokenUSDT: ${pricePerTokenUSDT} (6 decimals)`); | ||
| console.log(`- For deployment: ethers.parseUnits("${tokenPriceUSD}", 6)\n`); | ||
|
|
||
| // USDC Price Calculation (6 decimal places) | ||
| const pricePerTokenUSDC = Math.floor(tokenPriceUSD * 1e6); | ||
| console.log(`USDC Price Calculation:`); | ||
| console.log(`- Token price: $${tokenPriceUSD} USDC`); | ||
| console.log(`- pricePerTokenUSDC: ${pricePerTokenUSDC} (6 decimals)`); | ||
| console.log(`- For deployment: ethers.parseUnits("${tokenPriceUSD}", 6)\n`); | ||
|
|
||
| console.log("=== Raw Values for Constructor ==="); | ||
| console.log(`pricePerTokenETH: ${pricePerTokenETHWei}`); | ||
| console.log(`pricePerTokenUSDT: ${pricePerTokenUSDT}`); | ||
| console.log(`pricePerTokenUSDC: ${pricePerTokenUSDC}\n`); | ||
|
|
||
| console.log("=== Complete Deployment Example ==="); | ||
| console.log(` | ||
| const SEQICO = await ethers.getContractFactory("SEQICO"); | ||
| const seqICO = await SEQICO.deploy( | ||
| seqTokenAddress, | ||
| usdtAddress, | ||
| usdcAddress, | ||
| ethers.parseEther("${tokenPriceETH}"), // ${tokenPriceETH} ETH per token | ||
| ethers.parseUnits("${tokenPriceUSD}", 6), // ${tokenPriceUSD} USDT per token | ||
| ethers.parseUnits("${tokenPriceUSD}", 6) // ${tokenPriceUSD} USDC per token | ||
| ); | ||
| `); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
token amount $3.79