Skip to content

Commit db69509

Browse files
committed
Add Shell contracts WIP
1 parent db46709 commit db69509

3 files changed

Lines changed: 143 additions & 1 deletion

File tree

.soliumrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"error-reason": "error",
1313
"max-len": "error",
1414
"no-trailing-whitespace": "error",
15-
"blank-lines": "error"
15+
"blank-lines": "error",
16+
"custom-errors": "off"
1617
}
1718
}

contracts/bridging/ColonyShell.sol

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
/*
3+
This file is part of The Colony Network.
4+
5+
The Colony Network is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
The Colony Network is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with The Colony Network. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
pragma solidity 0.8.25;
20+
pragma experimental ABIEncoderV2;
21+
22+
import { BasicMetaTransaction } from "./../common/BasicMetaTransaction.sol";
23+
import { CallWithGuards } from "../common/CallWithGuards.sol";
24+
import { ERC20Extended } from "./../common/ERC20Extended.sol";
25+
import { Multicall } from "./../common/Multicall.sol";
26+
import { IColonyNetwork } from "./../colonyNetwork/IColonyNetwork.sol";
27+
28+
contract ColonyShell is BasicMetaTransaction, Multicall, CallWithGuards {
29+
// Address of the Resolver contract used by EtherRouter for lookups and routing
30+
address resolver; // Storage slot 2 (from DSAuth there is authority and owner at storage slots 0 and 1 respectively)
31+
32+
mapping(address => uint256) metatransactionNonces;
33+
34+
function getMetatransactionNonce(address _user) public view override returns (uint256 _nonce) {
35+
return metatransactionNonces[_user];
36+
}
37+
38+
function incrementMetatransactionNonce(address _user) internal override {
39+
metatransactionNonces[_user] += 1;
40+
}
41+
42+
// Public functions
43+
44+
function claimColonyFunds(address _token) public {
45+
uint256 tokenBalance = (_token == address(0x0))
46+
? address(this).balance
47+
: ERC20Extended(_token).balanceOf(address(this));
48+
49+
IColonyNetwork(owner).sendClaimColonyFunds(_token, tokenBalance);
50+
51+
emit ColonyFundsClaimed(_token, tokenBalance);
52+
}
53+
54+
function transfer(address _token, address _user, uint256 _amount) public auth {
55+
ERC20Extended(_token).transfer(_user, _amount);
56+
57+
emit PaymentMade(_token, _user, _amount);
58+
}
59+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
/*
3+
This file is part of The Colony Network.
4+
5+
The Colony Network is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
The Colony Network is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with The Colony Network. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
pragma solidity 0.8.25;
20+
pragma experimental ABIEncoderV2;
21+
22+
import { IColony } from "./../colony/IColony.sol";
23+
import { ICreateX } from "./../../lib/createx/src/ICreateX.sol";
24+
import { Multicall } from "./../common/Multicall.sol";
25+
import { CallWithGuards } from "./../common/CallWithGuards.sol";
26+
import { ColonyNetworkStorage } from "./ColonyNetworkStorage.sol";
27+
import { ColonyShell } from "./../briding/ColonyShell.sol";
28+
29+
contract ColonyNetworkShells is ColonyNetworkStorage, Multicall, CallWithGuards {
30+
// To shells
31+
32+
function deployColonyShell(bytes32 _salt) public onlyColonyBridge {
33+
ICreateX(CREATEX_ADDRESS).deployCreate3AndInit(
34+
_salt,
35+
type(EtherRouterCreate3).creationCode,
36+
abi.encodeWithSignature("setOwner(address)", (address(this))),
37+
ICreateX.Values(0, 0)
38+
);
39+
}
40+
41+
function sendDeployColonyShell(bytes32 _salt) public onlyColony {
42+
bytes memory payload = abi.encodeWithSignature(
43+
"deployColonyShell(bytes32)",
44+
_salt
45+
);
46+
47+
require(callThroughBridgeWithGuards(payload), "colony-network-shell-deploy-failed");
48+
}
49+
50+
function colonyShellTransfer(address _colony, address _token, address _user, uint256 _amount) public onlyColonyBridge {
51+
ColonyShell(_colony).transfer(_token, _user, _amount);
52+
}
53+
54+
function sendColonyShellTransfer(address _token, address _user, uint256 _amount) public onlyColony {
55+
bytes memory payload = abi.encodeWithSignature(
56+
"colonyShellTransfer(address,address,address,uint256)",
57+
msgSender(),
58+
_token,
59+
_user,
60+
_amount
61+
);
62+
63+
require(callThroughBridgeWithGuards(payload), "colony-network-shell-transfer-failed");
64+
}
65+
66+
// From shells
67+
68+
function claimColonyShellFunds(address _colony, address _token, uint256 _balance) public onlyColonyBridge {
69+
IColony(_colony).claimColonyShellFunds(_token, _balance);
70+
}
71+
72+
function sendClaimColonyShellFunds(address _token, uint256 _balance) public onlyColony {
73+
bytes memory payload = abi.encodeWithSignature(
74+
"claimColonyShellFunds(address,address,uint256)",
75+
msgSender(),
76+
_token,
77+
_balance
78+
);
79+
80+
require(callThroughBridgeWithGuards(payload), "colony-network-shell-claim-failed");
81+
}
82+
}

0 commit comments

Comments
 (0)