Skip to content

Commit 79df17a

Browse files
committed
fixed tests
1 parent 9c911d8 commit 79df17a

6 files changed

Lines changed: 619 additions & 337 deletions

File tree

apps/app/src/pages/presaleCreation.tsx

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -185,34 +185,38 @@ export default function PresaleCreation() {
185185
endTimeUnix
186186
);
187187
console.log("- No Time Limit:", values.noTimeLimit);
188-
console.log("- Full args array:", [{
189-
name: values.name,
190-
symbol: values.symbol,
191-
supply: BigInt(cleanSupply),
192-
price: priceinETH,
193-
hardCap: hardCapInETH,
194-
softCap: softCapInETH,
195-
startTime: BigInt(startTimeUnix),
196-
endTime: BigInt(endTimeUnix),
197-
softCapPrice: softCapPriceInETH,
198-
}]);
188+
console.log("- Full args array:", [
189+
{
190+
name: values.name,
191+
symbol: values.symbol,
192+
supply: BigInt(cleanSupply),
193+
price: priceinETH,
194+
hardCap: hardCapInETH,
195+
softCap: softCapInETH,
196+
startTime: BigInt(startTimeUnix),
197+
endTime: BigInt(endTimeUnix),
198+
softCapPrice: softCapPriceInETH,
199+
},
200+
]);
199201

200202
if (contractAddress) {
201203
createPresale({
202204
address: contractAddress,
203205
abi: PresaleFactoryABI,
204206
functionName: "createPresale",
205-
args: [{
206-
name: values.name,
207-
symbol: values.symbol,
208-
supply: BigInt(cleanSupply),
209-
price: priceinETH,
210-
hardCap: hardCapInETH,
211-
softCap: softCapInETH,
212-
startTime: BigInt(startTimeUnix),
213-
endTime: BigInt(endTimeUnix),
214-
softCapPrice: softCapPriceInETH,
215-
}],
207+
args: [
208+
{
209+
name: values.name,
210+
symbol: values.symbol,
211+
supply: BigInt(cleanSupply),
212+
price: priceinETH,
213+
hardCap: hardCapInETH,
214+
softCap: softCapInETH,
215+
startTime: BigInt(startTimeUnix),
216+
endTime: BigInt(endTimeUnix),
217+
softCapPrice: softCapPriceInETH,
218+
},
219+
],
216220
});
217221
}
218222
}
@@ -453,13 +457,18 @@ export default function PresaleCreation() {
453457
render={({ field }) => (
454458
<FormItem>
455459
<FormLabel>
456-
End Time {form.watch("hasSoftCap") && <span className="text-red-500">*</span>}
460+
End Time{" "}
461+
{form.watch("hasSoftCap") && (
462+
<span className="text-red-500">*</span>
463+
)}
457464
</FormLabel>
458465
<FormControl>
459466
<Input
460467
type="datetime-local"
461468
{...field}
462-
disabled={form.watch("noTimeLimit") || form.watch("hasSoftCap")}
469+
disabled={
470+
form.watch("noTimeLimit") || form.watch("hasSoftCap")
471+
}
463472
/>
464473
</FormControl>
465474
<FormDescription>

packages/contracts/contracts/Presale.sol

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ contract Presale is OwnableUpgradeable {
3535
bool public softCapReached;
3636

3737
function presaleFailed() public view returns (bool) {
38-
return hasSoftCap() && !softCapReached && block.timestamp > endTime;
38+
return hasSoftCap() && block.timestamp > endTime && !softCapReached;
3939
}
4040

4141
mapping(address => uint256) public tokenContributions;
@@ -89,16 +89,17 @@ contract Presale is OwnableUpgradeable {
8989
function contribute(uint256 amount) external payable {
9090
if (block.timestamp < startTime) revert PresaleNotStarted();
9191

92-
// If presale failed (time is up and softcap not reached), don't allow contributions
93-
if (presaleFailed()) {
94-
revert PresaleFailedNoRefund();
95-
}
96-
9792
// Check if we're past the end time (but not yet failed, meaning soft cap was reached)
9893
if (endTime != 0 && block.timestamp > endTime) {
94+
// If the presale has ended and hasn't reached soft cap, contributions are not allowed
95+
if (hasSoftCap() && !softCapReached) {
96+
revert PresaleFailedNoRefund();
97+
}
98+
// If time is up regardless of soft cap status, no new contributions allowed
9999
revert PresaleEnded();
100100
}
101101

102+
// Determine the price to use for this contribution (before updating softCapReached)
102103
uint256 total = amount * currentPrice();
103104

104105
if (total != msg.value) revert InvalidEtherSent(msg.value, total);
@@ -108,9 +109,13 @@ contract Presale is OwnableUpgradeable {
108109

109110
totalContributed += msg.value;
110111
ethContributions[msg.sender] += msg.value;
112+
113+
// Add the tokens based on the amount contributed using the current price at time of contribution
111114
tokenContributions[msg.sender] += amount * 10 ** token.decimals();
112115

113-
if (!softCapReached && totalContributed >= softCap) {
116+
// Check if soft cap is reached after the contribution
117+
// Only update if soft cap is set (greater than 0)
118+
if (!softCapReached && hasSoftCap() && totalContributed >= softCap) {
114119
softCapReached = true;
115120
}
116121

packages/contracts/hardhat.config.ts

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,51 @@
1-
import type { HardhatUserConfig } from "hardhat/config";
1+
import { configVariable, type HardhatUserConfig } from "hardhat/config";
22
import hardhatViem from "@nomicfoundation/hardhat-viem";
33
import hardhatVerify from "@nomicfoundation/hardhat-verify";
44
import hardhatViemAssertions from "@nomicfoundation/hardhat-viem-assertions";
55
import HardhatNodeTestRunner from "@nomicfoundation/hardhat-node-test-runner";
66
import hardhatNetworkHelpers from "@nomicfoundation/hardhat-network-helpers";
7+
import hardhatAbiExporter from "@solidstate/hardhat-abi-exporter";
8+
import {
9+
bsc,
10+
bscTestnet,
11+
mainnet,
12+
sepolia,
13+
polygon,
14+
polygonAmoy,
15+
celo,
16+
celoAlfajores,
17+
} from "viem/chains";
18+
19+
export const desiredChains = [
20+
// 56
21+
bsc,
22+
// 1
23+
mainnet,
24+
// 137
25+
polygon,
26+
// 42220
27+
celo,
28+
// ========== Testnets ==========
29+
// 11155111
30+
sepolia,
31+
// 97
32+
bscTestnet,
33+
// 44787
34+
celoAlfajores,
35+
// 80002
36+
polygonAmoy,
37+
];
38+
39+
const networks: HardhatUserConfig["networks"] = {};
40+
41+
for (const chain of desiredChains) {
42+
networks[chain.id.toString()] = {
43+
url: chain.rpcUrls.default.http[0],
44+
accounts: [configVariable("DEPLOYER_PRIVATE_KEY")],
45+
chainId: chain.id,
46+
type: "http",
47+
};
48+
}
749

850
const config: HardhatUserConfig = {
951
plugins: [
@@ -12,6 +54,7 @@ const config: HardhatUserConfig = {
1254
hardhatViem,
1355
hardhatViemAssertions,
1456
hardhatNetworkHelpers,
57+
hardhatAbiExporter,
1558
],
1659
paths: {
1760
tests: {
@@ -27,9 +70,23 @@ const config: HardhatUserConfig = {
2770
},
2871
},
2972
},
73+
abiExporter: [
74+
{
75+
path: "./abi",
76+
format: "json",
77+
runOnCompile: true,
78+
},
79+
{
80+
path: "./abi_ts",
81+
format: "typescript",
82+
clear: true,
83+
runOnCompile: true,
84+
},
85+
],
86+
networks,
3087
verify: {
3188
etherscan: {
32-
apiKey: "YOUR_ETHERSCAN_API_KEY",
89+
apiKey: configVariable("ETHERSCAN_API_KEY"),
3390
},
3491
blockscout: {
3592
enabled: true,

packages/contracts/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"version": "0.0.0",
55
"scripts": {
6-
"build": "hardhat compile && hardhat export-abi",
6+
"build": "hardhat compile",
77
"clean": "hardhat clean && hardhat clear-abi && rm -rf .turbo && rm -rf node_modules && rm -rf dist",
88
"test": "hardhat test",
99
"deploy": "hardhat ignition deploy ignition/modules/PresaleFactory.ts --network",
@@ -16,9 +16,11 @@
1616
"@nomicfoundation/hardhat-network-helpers": "^3.0.0",
1717
"@nomicfoundation/hardhat-node-test-runner": "^3.0.3",
1818
"@nomicfoundation/hardhat-toolbox-mocha-ethers": "^3.0.0",
19+
"@nomicfoundation/hardhat-toolbox-viem": "^5.0.0",
1920
"@nomicfoundation/hardhat-verify": "^3.0.2",
2021
"@nomicfoundation/hardhat-viem": "^3.0.0",
2122
"@nomicfoundation/hardhat-viem-assertions": "^3.0.2",
23+
"@solidstate/hardhat-abi-exporter": "^3.0.0",
2224
"@types/chai": "^4.3.16",
2325
"@types/chai-as-promised": "^7.1.8",
2426
"@types/mocha": "^10.0.7",

0 commit comments

Comments
 (0)