Skip to content

Commit

Permalink
feat: counter contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
arthcp committed Nov 29, 2024
1 parent 3a9afb0 commit fae7f01
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/Counter.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

contract Counter {
uint256 public number;
import "socket-poc/contracts/utils/Ownable.sol";

function setNumber(uint256 newNumber) public {
number = newNumber;
contract Counter is Ownable(msg.sender) {
address public socket;
uint256 public counter;

modifier onlySocket() {
require(msg.sender == socket, "not socket");
_;
}

function setSocket(address _socket) external onlyOwner {
socket = _socket;
}

function getSocket() external view returns (address) {
return socket;
}

function increment() public {
number++;
function increase() external onlySocket {
counter++;
}
}
19 changes: 19 additions & 0 deletions src/CounterComposer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

import "socket-poc/contracts/base/AppGatewayBase.sol";
import "./Counter.sol";

contract CounterComposer is AppGatewayBase {
constructor(
address _addressResolver,
address deployerContract_,
FeesData memory feesData_
) AppGatewayBase(_addressResolver, feesData_) Ownable(msg.sender) {
addressResolver.setContractsToGateways(deployerContract_);
}

function incrementCounter(address _instance) public queueAndExecute {
Counter(_instance).increase();
}
}
29 changes: 29 additions & 0 deletions src/CounterDeployer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

import "./Counter.sol";
import "socket-poc/contracts/base/AppDeployerBase.sol";

contract CounterDeployer is AppDeployerBase {
address public counter;

constructor(
address addressResolver_,
FeesData memory feesData_
) AppDeployerBase(addressResolver_, feesData_) Ownable(msg.sender) {
counter = address(new Counter());
creationCodeWithArgs[counter] = type(Counter).creationCode;
}

function deployContracts(
uint32 chainSlug
) external queueAndDeploy(chainSlug) {
_deploy(counter);
}

function initialize(uint32 chainSlug) public override queueAndExecute {
address socket = getSocketAddress(chainSlug);
address counterForwarder = forwarderAddresses[counter][chainSlug];
Counter(counterForwarder).setSocket(socket);
}
}

0 comments on commit fae7f01

Please sign in to comment.