-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added in deploy/test scripts for the Tokens
- Loading branch information
root
authored and
root
committed
Oct 29, 2024
1 parent
584cdc9
commit 65e8c4c
Showing
15 changed files
with
651 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {Script} from "lib/forge-std/src/Script.sol"; | ||
import {FyreToken} from "src/Tokens/FYREToken.sol"; | ||
import {console} from "lib/forge-std/src/console.sol"; | ||
import {HelperConfig} from "./HelperConfig.s.sol"; // Import HelperConfig | ||
|
||
contract DeployFyreToken is Script { | ||
// Declare fyreToken as a public state variable | ||
FyreToken public fyreToken; | ||
|
||
function run() external { | ||
// Use HelperConfig to determine the correct owner address | ||
HelperConfig helperConfig = new HelperConfig(); | ||
address deployer = helperConfig.owner(); // Deployer address for initial minting | ||
address finalOwner = 0x21310a7f2c88194fb70194df679b260F024cCF77; // New owner address for production | ||
|
||
uint256 initialSupply = 250_000 ether; // Updated initial supply for hackathon | ||
|
||
// Start a broadcast as the deployer | ||
vm.startBroadcast(deployer); | ||
fyreToken = new FyreToken(deployer, initialSupply); // Deploy the contract | ||
|
||
// Transfer ownership to the final owner | ||
fyreToken.transferOwnership(finalOwner); | ||
|
||
// Transfer all minted tokens to the final owner | ||
fyreToken.transfer(finalOwner, initialSupply); | ||
vm.stopBroadcast(); | ||
|
||
// Print the deployed contract address and the new owner address | ||
console.log("Deployed FyreToken at:", address(fyreToken)); | ||
console.log("Ownership transferred to:", finalOwner); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {Script} from "lib/forge-std/src/Script.sol"; | ||
|
||
contract HelperConfig is Script { | ||
address public owner; | ||
|
||
constructor() { | ||
// Set the owner address depending on the network | ||
uint256 chainId = block.chainid; | ||
if (chainId == 31337) { | ||
// Local network (anvil) | ||
owner = 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266; // Anvil's default account | ||
} else if (chainId == 1313161555) { | ||
// Aurora testnet | ||
owner = vm.envAddress("OWNER_ADDRESS"); // From environment variable | ||
} else if (chainId == 1313161554) { | ||
// Aurora Mainnet | ||
owner = vm.envAddress("OWNER_ADDRESS"); | ||
} else { | ||
// Default to the environment variable for other networks | ||
owner = vm.envAddress("OWNER_ADDRESS"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// File: script/DeployMANA.s.sol | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import {MANA} from "src/Tokens/MANA.sol"; | ||
import {ManaToken} from "src/Tokens/ManaToken.sol"; | ||
import {HelperConfig} from "./HelperConfig.s.sol"; | ||
import {console} from "lib/forge-std/src/console.sol"; | ||
|
||
contract DeployMANA is Script { | ||
function run() external { | ||
HelperConfig helperConfig = new HelperConfig(); | ||
HelperConfig.NetworkConfig memory config = helperConfig | ||
.activeNetworkConfig; | ||
|
||
// Load the deployer's private key from the HelperConfig | ||
uint256 deployerPrivateKey = config.deployerKey; | ||
|
||
// Start broadcasting transactions | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
// Retrieve the deployed MANA contracts | ||
MANA manaGovernanceToken = MANA(config.manaGovernanceToken); | ||
ManaToken manaToken = ManaToken(config.manaToken); | ||
|
||
// Log deployed contract addresses | ||
console.log( | ||
"MANA Governance Token deployed at:", | ||
address(manaGovernanceToken) | ||
); | ||
console.log("ManaToken deployed at:", address(manaToken)); | ||
|
||
// Stop broadcasting transactions | ||
vm.stopBroadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// File: script/DeployManaToken.s.sol | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import {ManaToken} from "src/Tokens/ManaToken.sol"; // Adjust the import path as needed | ||
import {console2} from "lib/forge-std/src/console2.sol"; | ||
|
||
contract DeployManaToken is Script { | ||
function run() external { | ||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
// Deploy ManaToken with initial supply of 1000 tokens and the specified address | ||
ManaToken manaToken = new ManaToken( | ||
1000, | ||
0x77e0dFD1D2BfEC5c1816F9c06BEe673b14e0f72e | ||
); | ||
|
||
console2.log("ManaToken deployed to:", address(manaToken)); | ||
vm.stopBroadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// File: script/HelperConfig.s.sol | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import {MockV3Aggregator} from "test/mocks/MockV3Aggregator.sol"; | ||
import {MANA} from "src/Tokens/MANA.sol"; | ||
import {ManaToken} from "src/Tokens/ManaToken.sol"; | ||
|
||
contract HelperConfig is Script { | ||
NetworkConfig public activeNetworkConfig; | ||
|
||
uint256 public constant INITIAL_SUPPLY = 10000 * 10 ** 18; | ||
uint256 public constant DEFAULT_ANVIL_PRIVATE_KEY = | ||
0x59c6995e998f97a5a004497d4a9c9f90000000000000000000000000000000000; // Anvil Default Private Key | ||
|
||
struct NetworkConfig { | ||
address manaGovernanceToken; | ||
address manaToken; | ||
uint256 deployerKey; | ||
} | ||
|
||
constructor() { | ||
if (block.chainid == 11155111) { | ||
// Sepolia Network | ||
activeNetworkConfig = getSepoliaConfig(); | ||
} else { | ||
// Default to Anvil Config | ||
activeNetworkConfig = getOrCreateAnvilConfig(); | ||
} | ||
} | ||
|
||
function getSepoliaConfig() | ||
public | ||
view | ||
returns (NetworkConfig memory sepoliaConfig) | ||
{ | ||
sepoliaConfig = NetworkConfig({ | ||
manaGovernanceToken: 0x1234, // Sepolia MANA (ERC-1400) Address | ||
manaToken: 0x5678, // Sepolia ManaToken (ERC-20) Address | ||
deployerKey: vm.envUint("PRIVATE_KEY") // Set PRIVATE_KEY in .env for Sepolia | ||
}); | ||
} | ||
|
||
function getOrCreateAnvilConfig() | ||
public | ||
returns (NetworkConfig memory anvilConfig) | ||
{ | ||
if (activeNetworkConfig.manaGovernanceToken != address(0)) { | ||
return activeNetworkConfig; | ||
} | ||
|
||
// Broadcast transactions for mock contract deployment | ||
vm.startBroadcast(); | ||
|
||
// Corrected contract instantiation | ||
MANA manaGovernanceToken = new MANA(); // Initialize MANA contract (assuming MANA constructor does not require parameters) | ||
ManaToken manaToken = new ManaToken( | ||
INITIAL_SUPPLY, | ||
address(manaGovernanceToken) | ||
); // Mock ERC-20 | ||
|
||
vm.stopBroadcast(); | ||
|
||
anvilConfig = NetworkConfig({ | ||
manaGovernanceToken: address(manaGovernanceToken), | ||
manaToken: address(manaToken), | ||
deployerKey: DEFAULT_ANVIL_PRIVATE_KEY | ||
}); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {Test} from "lib/forge-std/src/Test.sol"; | ||
import {FyreToken} from "src/Tokens/FYREToken.sol"; | ||
|
||
contract FyreTokenHandler is Test { | ||
FyreToken fyreToken; | ||
address owner; | ||
|
||
uint256 constant MAX_SUPPLY = 1_000_000 ether; // Limit max token supply for fuzzing | ||
uint256 constant MIN_AMOUNT = 1 ether; // Min amount for minting/burning to avoid small numbers | ||
uint256 constant MAX_AMOUNT = 1_000 ether; // Max amount to mint/burn per operation | ||
|
||
constructor(FyreToken _fyreToken, address _owner) { | ||
fyreToken = _fyreToken; | ||
owner = _owner; | ||
} | ||
|
||
function mintTokens(address account, uint256 amount) public { | ||
// Check total supply before minting to avoid exceeding MAX_SUPPLY | ||
uint256 totalSupply = fyreToken.totalSupply(); | ||
uint256 remainingSupply = MAX_SUPPLY - totalSupply; | ||
amount = bound(amount, MIN_AMOUNT, remainingSupply); // Bound the amount for safe fuzzing | ||
|
||
if (amount == 0) { | ||
return; // Prevent minting if no remaining supply | ||
} | ||
|
||
vm.prank(owner); | ||
fyreToken.mint(account, amount); | ||
} | ||
|
||
function burnTokens(address account, uint256 amount) public { | ||
uint256 balance = fyreToken.balanceOf(account); | ||
amount = bound(amount, MIN_AMOUNT, balance); // Bound to available balance to avoid underflow | ||
|
||
if (amount == 0) { | ||
return; // Prevent burning if balance is too small | ||
} | ||
|
||
vm.prank(owner); | ||
fyreToken.burn(account, amount); | ||
} | ||
|
||
function transferTokens(address from, address to, uint256 amount) public { | ||
uint256 balance = fyreToken.balanceOf(from); | ||
amount = bound(amount, MIN_AMOUNT, balance); // Avoid transferring more than the balance | ||
vm.prank(from); | ||
fyreToken.transfer(to, amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {Test, console} from "lib/forge-std/src/Test.sol"; | ||
import {StdInvariant} from "lib/forge-std/src/StdInvariant.sol"; | ||
import {FyreTokenHandler} from "test/Tokens/FYRE/Fuzz/FYRETokenHandler.t.sol"; | ||
import {FyreToken} from "src/Tokens/FYREToken.sol"; | ||
|
||
contract FyreTokenInvariantTest is StdInvariant { | ||
FyreToken fyreToken; | ||
FyreTokenHandler handler; | ||
|
||
uint256 constant MAX_SUPPLY = 1_000_000 ether; // Maximum supply allowed | ||
|
||
function setUp() public { | ||
address owner = address(0xABCD); | ||
fyreToken = new FyreToken(owner, MAX_SUPPLY); | ||
handler = new FyreTokenHandler(fyreToken, owner); | ||
targetContract(address(handler)); // Set the handler as the target for fuzz testing | ||
} | ||
|
||
// Ensure that the total supply never exceeds the MAX_SUPPLY | ||
function invariant_TotalSupplyShouldBeWithinBounds() public view { | ||
uint256 totalSupply = fyreToken.totalSupply(); | ||
assert(totalSupply <= MAX_SUPPLY); // Total supply should not exceed MAX_SUPPLY | ||
console.log("Total Supply: ", totalSupply); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {Test} from "lib/forge-std/src/Test.sol"; | ||
import {DeployFyreToken} from "script/Tokens/FYRE/DeployFYREToken.s.sol"; // Import the script | ||
import {FyreToken} from "src/Tokens/FYREToken.sol"; | ||
|
||
contract DeployFyreTokenTest is Test { | ||
function testDeploymentScript() public { | ||
DeployFyreToken deployScript = new DeployFyreToken(); // Instantiate the script | ||
deployScript.run(); // Execute the script | ||
|
||
// Retrieve the deployed contract address from the DeployFyreToken script | ||
FyreToken fyreToken = FyreToken(address(deployScript.fyreToken())); // Access the public state variable | ||
|
||
// Test the deployed contract properties | ||
uint256 expectedSupply = 250_000 ether; | ||
assertEq(fyreToken.totalSupply(), expectedSupply); | ||
assertEq(fyreToken.balanceOf(fyreToken.owner()), expectedSupply); | ||
|
||
// Ensure the ownership was transferred to the final owner | ||
address finalOwner = 0x21310a7f2c88194fb70194df679b260F024cCF77; | ||
assertEq(fyreToken.owner(), finalOwner); // Ensure the owner is now the finalOwner | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.19; | ||
|
||
import {Test} from "lib/forge-std/src/Test.sol"; | ||
import {FyreToken} from "src/Tokens/FYREToken.sol"; | ||
|
||
contract FyreTokenUnitTest is Test { | ||
FyreToken fyreToken; | ||
address owner = address(0xABCD); | ||
address addr1 = address(0x1234); | ||
address addr2 = address(0x5678); | ||
uint256 initialSupply = 1_000_000 ether; | ||
|
||
function setUp() public { | ||
fyreToken = new FyreToken(owner, initialSupply); | ||
} | ||
|
||
function testInitialSupply() public { | ||
assertEq(fyreToken.totalSupply(), initialSupply); | ||
assertEq(fyreToken.balanceOf(owner), initialSupply); | ||
} | ||
|
||
function testTransfer() public { | ||
uint256 transferAmount = 100 ether; | ||
vm.prank(owner); | ||
fyreToken.transfer(addr1, transferAmount); | ||
assertEq(fyreToken.balanceOf(addr1), transferAmount); | ||
assertEq(fyreToken.balanceOf(owner), initialSupply - transferAmount); | ||
} | ||
|
||
function testMint() public { | ||
uint256 mintAmount = 500 ether; | ||
vm.prank(owner); | ||
fyreToken.mint(addr1, mintAmount); | ||
assertEq(fyreToken.balanceOf(addr1), mintAmount); | ||
assertEq(fyreToken.totalSupply(), initialSupply + mintAmount); | ||
} | ||
|
||
function testBurn() public { | ||
uint256 burnAmount = 200 ether; | ||
vm.prank(owner); | ||
fyreToken.mint(addr1, burnAmount); // Mint first | ||
vm.prank(owner); | ||
fyreToken.burn(addr1, burnAmount); | ||
assertEq(fyreToken.balanceOf(addr1), 0); | ||
assertEq(fyreToken.totalSupply(), initialSupply); | ||
} | ||
} |
Oops, something went wrong.