Skip to content
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

Contracts - mesh Spencer and Trevor changes #22

Merged
merged 13 commits into from
Dec 8, 2023
Merged
33 changes: 33 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
PayrollFactory deployed to: 0xfe44aB0B966E57F126130BE6401546c7351484ad --mumbai
TokenTransferor deployed to: 0x21d762ab159676d3bd05e12A95699C1d0b043A48 --mumbai
Payroll deployed to: 0xDBAbe75848c608bDA3382f0D68219542032B3fEa --mumbai
All deployed from 0x9768818565ED5968fAACC6F66ca02CBf2785dB84

https://api-testnet.polygonscan.com/IEWN9BX92EIKVXR22UKQQ9A4UWEF5J9IRG

There is no log out / wallet modal on Register Deploy
Need a rundown of how to log in with wallet and connect to mumbai chain without AA

I shouldnt need to change the web3auth client id correct?

deploy contract in register flow is stuck at getting account address...

## 12/7
Funkornaut@gmail -- 0xBB65877a1207572321dE0ad64A2e196545904a09
trevfost503@gmail -- 0xfd330177602f092b72a3b65893602067Ab69cE2c
sign in with funkornaut through gmail -- 0x1aD394b0c57dbC57f16A5A54b4ccee436b678287

deployed new payroll 0xAB34603b0A8c54f9F9Fe9207b98da8ac354dB68e
- added function isOwner returns bool, owner() func on ownable works but since we then needed to look for bool on front end thought that would simplify from end logic / routing
- think that the LogIn flow is a little better

Login.tsx
Web3 modal pops up when you hit login button - should only pop up if there is a contract address in the form

Now logOut if funky
Cant log in with Metamask

DeployForm
- just using useContractWrite was able to click button and make action got this error in browser console
next-dev.js:20 ConnectorNotFoundError: Connector not found at writeContract (chunk-TSH6VVF4.js:2348:1)

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@
},
"resolutions": {
"usehooks-ts@^2.7.2": "patch:usehooks-ts@npm:^2.7.2#./.yarn/patches/usehooks-ts-npm-2.7.2-fceffe0e43.patch"
},
"dependencies": {
"@web3auth/web3auth-wagmi-connector": "^5.0.1"
}
}
4 changes: 2 additions & 2 deletions packages/hardhat/contracts/Payroll.sol
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ ITokenTransferor public ccip;
}
}

function getOwner() public view returns (address){
return owner();
function isOwner(address _address) public view returns (bool){
return _address == owner();
}

function getEmployeePaymentSplits(address _employeeAddress) public view returns (PaymentSplit memory){
Expand Down
207 changes: 115 additions & 92 deletions packages/hardhat/contracts/PayrollFactory.sol
Original file line number Diff line number Diff line change
@@ -1,98 +1,121 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import {TokenTransferor} from "./TokenTransferor.sol";
import {Payroll} from "./Payroll.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {OwnerIsCreator} from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {IERC20} from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/token/ERC20/IERC20.sol";
import { TokenTransferor } from "./TokenTransferor.sol";
import { Payroll } from "./Payroll.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IRouterClient } from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import { OwnerIsCreator } from "@chainlink/contracts-ccip/src/v0.8/shared/access/OwnerIsCreator.sol";
import { Client } from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import { IERC20 } from "@chainlink/contracts-ccip/src/v0.8/vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/IERC20.sol";

contract PayrollFactory is Ownable {
// Set the deployment fee
uint256 public deployment_fee = 1 wei; // Example fee

IRouterClient public router;
IERC20 public linkToken;
IERC20 public paymentToken;

error InvalidAddress();
error InsufficientFunds(uint256 amount);

event TokenTransferorDeployed(address indexed deployer, address contractAddress);
event PayrollDeployed(address indexed deployer, address contractAddress, address tokenTransferorAddress);

///@param _router The address of the Chainlink Router for local chain
///@param _linkToken The address of the LINK token for local chain
///@param _paymentToken The address of the payment token for Payroll Contract on native chain
constructor(address _router, address _linkToken, address _paymentToken) {
router = IRouterClient(_router);
linkToken = IERC20(_linkToken);
paymentToken = IERC20(_paymentToken);
}

///@dev Deploys TokenTransferor and Payroll contracts
function deployPayrollAndTokenTransferor() external payable returns (address payrollAddress, address tokenTransferorAddress) {
if(msg.value < deployment_fee){
revert InsufficientFunds(msg.value);
}

tokenTransferorAddress = deployTokenTransferor();
payrollAddress = deployPayroll(tokenTransferorAddress);
return (payrollAddress, tokenTransferorAddress);
}

// Function to deploy TokenTransferor
///@dev transfers ownership of TokenTransferor to caller of deployPayrollAndTokenTransferor
function deployTokenTransferor() internal returns (address) {
//require(msg.value >= deployment_fee, "Insufficient funds sent for deployment");

TokenTransferor newTokenTransferor = new TokenTransferor(address(router), address(linkToken));
newTokenTransferor.transferOwnership(msg.sender);
emit TokenTransferorDeployed(msg.sender, address(newTokenTransferor));
return address(newTokenTransferor);
}

/// Function to deploy Payroll
///@dev transfers ownership of Payroll to caller of deployPayrollAndTokenTransferor
///@param tokenTransferorAddress The address of the newly deployed TokenTransferor contract
function deployPayroll(address tokenTransferorAddress) internal returns (address) {
//require(msg.value >= deployment_fee, "Insufficient funds sent for deployment");

Payroll newPayroll = new Payroll(tokenTransferorAddress, address(paymentToken));
newPayroll.transferOwnership(msg.sender); // Transfer ownership
emit PayrollDeployed(msg.sender, address(newPayroll), tokenTransferorAddress);
return address(newPayroll);
}

/// Functions to update deployment params so that they can be changed in the future or for deployment on other chains
function updateDeploymentFee(uint256 newFee) external onlyOwner {
deployment_fee = newFee;
}

function changeRouter(address newRouter) external onlyOwner {
router = IRouterClient(newRouter);
}

function changeLinkToken(address newLinkToken) external onlyOwner {
linkToken = IERC20(newLinkToken);
}

function changePaymentToken(address newPaymentToken) external onlyOwner {
paymentToken = IERC20(newPaymentToken);
}

// Fallback function to receive ETH
receive() external payable {}

// Function to withdraw collected fees
function withdrawFees(address payable _beneficiary) public onlyOwner {
// Only contract owner should be able to withdraw fees
// Implement ownership and access control
if (_beneficiary == address(0)) {
revert InvalidAddress();
}
_beneficiary.transfer(address(this).balance);
}
// Set the deployment fee
uint256 public deployment_fee = 1 wei; // Example fee

IRouterClient public router;
IERC20 public linkToken;
IERC20 public paymentToken;

error InvalidAddress();
error InsufficientFunds(uint256 amount);

event TokenTransferorDeployed(
address indexed deployer,
address contractAddress
);
event PayrollDeployed(
address indexed deployer,
address contractAddress,
address tokenTransferorAddress
);

///@param _router The address of the Chainlink Router for local chain
///@param _linkToken The address of the LINK token for local chain
///@param _paymentToken The address of the payment token for Payroll Contract on native chain
constructor(address _router, address _linkToken, address _paymentToken) {
router = IRouterClient(_router);
linkToken = IERC20(_linkToken);
paymentToken = IERC20(_paymentToken);
}

///@dev Deploys TokenTransferor and Payroll contracts
function deployPayrollAndTokenTransferor()
external
payable
returns (address payrollAddress, address tokenTransferorAddress)
{
if (msg.value < deployment_fee) {
revert InsufficientFunds(msg.value);
}

tokenTransferorAddress = deployTokenTransferor();
payrollAddress = deployPayroll(tokenTransferorAddress);
return (payrollAddress, tokenTransferorAddress);
}

// Function to deploy TokenTransferor
///@dev transfers ownership of TokenTransferor to caller of deployPayrollAndTokenTransferor
function deployTokenTransferor() internal returns (address) {
//require(msg.value >= deployment_fee, "Insufficient funds sent for deployment");

TokenTransferor newTokenTransferor = new TokenTransferor(
address(router),
address(linkToken)
);
newTokenTransferor.transferOwnership(msg.sender);
emit TokenTransferorDeployed(msg.sender, address(newTokenTransferor));
return address(newTokenTransferor);
}

/// Function to deploy Payroll
///@dev transfers ownership of Payroll to caller of deployPayrollAndTokenTransferor
///@param tokenTransferorAddress The address of the newly deployed TokenTransferor contract
function deployPayroll(
address tokenTransferorAddress
) internal returns (address) {
//require(msg.value >= deployment_fee, "Insufficient funds sent for deployment");

Payroll newPayroll = new Payroll(
tokenTransferorAddress,
address(paymentToken)
);
newPayroll.transferOwnership(msg.sender); // Transfer ownership
emit PayrollDeployed(
msg.sender,
address(newPayroll),
tokenTransferorAddress
);
return address(newPayroll);
}

/// Functions to update deployment params so that they can be changed in the future or for deployment on other chains
function updateDeploymentFee(uint256 newFee) external onlyOwner {
deployment_fee = newFee;
}

function changeRouter(address newRouter) external onlyOwner {
router = IRouterClient(newRouter);
}

function changeLinkToken(address newLinkToken) external onlyOwner {
linkToken = IERC20(newLinkToken);
}

function changePaymentToken(address newPaymentToken) external onlyOwner {
paymentToken = IERC20(newPaymentToken);
}

// Fallback function to receive ETH
receive() external payable {}

// Function to withdraw collected fees
function withdrawFees(address payable _beneficiary) public onlyOwner {
// Only contract owner should be able to withdraw fees
// Implement ownership and access control
if (_beneficiary == address(0)) {
revert InvalidAddress();
}
_beneficiary.transfer(address(this).balance);
}
}
Loading
Loading