Skip to content

Commit

Permalink
Add fileparser and mechanism for running batches
Browse files Browse the repository at this point in the history
  • Loading branch information
stevieraykatz committed Aug 28, 2024
1 parent 6e1c1eb commit 1f17dbb
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 18 deletions.
3 changes: 2 additions & 1 deletion mainnet/2024-08-27-disburse-basenames/.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
OP_COMMIT=e87e5ef2b96893eb8b446da420f7ba7f3e3c5985
BASE_CONTRACTS_COMMIT=5d98dab6a4f3ba60713a17417a2df7a17d77c52f
BASE_CONTRACTS_COMMIT=4202fd86330404d337c1b9dc3acc59df27b4ab61

ECOSYSTEM_MULTISIG=0xB5fa2Ea9845C67c76b1813D4778601F209875Bf6

REGISTRY_ADDR=0xb94704422c2a1e396835a571837aa5ae53285a95
BASE_REGISTRAR_ADDR=0x03c4738ee98ae44591e1a4a4f3cab6641d95dd9a
L2_RESOLVER_ADDR=0xC6d566A56A1aFf6508b41f6c90ff131615583BCD
8 changes: 6 additions & 2 deletions mainnet/2024-08-27-disburse-basenames/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ endif

.PHONY: sign-disbursement
sign-disbursement:
$(GOPATH)/bin/eip712sign --ledger --hd-paths "m/44'/60'/$(LEDGER_ACCOUNT)'/0/0" -- \
./parser.sh disbursement1.csv; $(GOPATH)/bin/eip712sign --ledger --hd-paths "m/44'/60'/$(LEDGER_ACCOUNT)'/0/0" -- \
forge script --rpc-url $(L2_RPC_URL) DisburseBasenames \
--sig "sign()"

Expand All @@ -26,7 +26,7 @@ endif
# Solidity Setup
##
.PHONY: deps
deps: install-eip712sign clean-lib forge-deps checkout-base-contracts-commit
deps: install-eip712sign clean-lib forge-deps checkout-base-contracts-commit parser-setup

.PHONY: install-eip712sign
install-eip712sign:
Expand All @@ -51,3 +51,7 @@ checkout-base-contracts-commit:
git remote add origin https://github.com/base-org/contracts.git; \
git fetch --depth=1 origin $(BASE_CONTRACTS_COMMIT); \
git reset --hard FETCH_HEAD

.PHONY: parser-setup
parser-setup:
chmod +x parser.sh
8 changes: 8 additions & 0 deletions mainnet/2024-08-27-disburse-basenames/parser.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
jq -Rsn '
{"singles":
[inputs
| . / "\n"
| (.[] | select(length > 0) | . / ",") as $input
| {"name": $input[0], "addr": $input[1]}]}
' <$1 > disbursement.json
76 changes: 61 additions & 15 deletions mainnet/2024-08-27-disburse-basenames/script/DisburseBasenames.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import {Registry} from "basenames/L2/Registry.sol";
import {BaseRegistrar} from "basenames/L2/BaseRegistrar.sol";
import {L2Resolver, NameResolver, Multicallable} from "basenames/L2/L2Resolver.sol";
import {BASE_ETH_NODE} from "basenames/util/Constants.sol";
Expand All @@ -14,6 +15,7 @@ import {
} from "@base-contracts/script/universal/MultisigBuilder.sol";
import { Vm } from "forge-std/Vm.sol";


interface IERC721 {
function safeTransferFrom(address from, address to, uint256 id) external;
}
Expand All @@ -27,23 +29,51 @@ interface AddrResolver {
contract DisburseBasenames is MultisigBuilder {
address internal ECOSYSTEM_MULTISIG = vm.envAddress("ECOSYSTEM_MULTISIG");
address internal BASE_REGISTRAR_ADDR = vm.envAddress("BASE_REGISTRAR_ADDR");
address internal REGISTRY_ADDR = vm.envAddress("REGISTRY_ADDR");
address internal L2_RESOLVER_ADDR = vm.envAddress("L2_RESOLVER_ADDR");

struct Disbursement {
Single[] singles;
}

function _postCheck(Vm.AccountAccess[] memory, SimulationPayload memory) internal override view {
struct Single {
address addr;
string name;
}

function _parseFile() internal view returns (Disbursement memory) {
string memory json = vm.readFile("disbursement.json");
bytes memory data = vm.parseJson(json);
return abi.decode(data, (Disbursement));
}

function _buildCalls() internal view override returns (IMulticall3.Call3[] memory) {
IMulticall3.Call3[] memory calls = new IMulticall3.Call3[](4);
Disbursement memory allData = _parseFile();
uint256 callcount = allData.singles.length * 5; // 5 calls per disbursement
IMulticall3.Call3[] memory calls = new IMulticall3.Call3[](callcount);

uint256 accumulator;
for(uint256 i; i < allData.singles.length; i++) {
IMulticall3.Call3[] memory singleCalls = new IMulticall3.Call3[](5);
singleCalls = _buildCallsForSingle(allData.singles[i]);
calls[accumulator++] = singleCalls[0];
calls[accumulator++] = singleCalls[1];
calls[accumulator++] = singleCalls[2];
calls[accumulator++] = singleCalls[3];
calls[accumulator++] = singleCalls[4];
}

uint256 id = 101607177989908133428079416239706370710574677396813813478356790246028549915433;
string memory name = "aave";
address addr = 0xac140648435d03f784879cd789130F22Ef588Fcd;
return _buildCallsForOne(id, addr, name);
return calls;
}

function _buildCallsForOne(uint256 id, address addr, string memory name) internal view returns (IMulticall3.Call3[] memory) {
IMulticall3.Call3[] memory calls = new IMulticall3.Call3[](4);
function _buildCallsForSingle(Single memory single) internal view returns (IMulticall3.Call3[] memory) {
uint256 id = _getIdFromName(single.name);
address addr = single.addr;
string memory name = single.name;
console.log(id);
console.log(addr);
console.log(name);
IMulticall3.Call3[] memory calls = new IMulticall3.Call3[](5);

// CALL 0 :: call reclaim to give the multisig permission to edit records for this name.
calls[0] = IMulticall3.Call3({
Expand All @@ -52,22 +82,29 @@ contract DisburseBasenames is MultisigBuilder {
callData: abi.encodeWithSelector(BaseRegistrar.reclaim.selector, id, ECOSYSTEM_MULTISIG)
});

// CALL 1 :: set the resolver data for the name using `setAddr` and `setName` encoded for multicall.
// CALL 1 :: set the L2 resolver as the resolver for the node in the regsitry
calls[1] = IMulticall3.Call3({
target: REGISTRY_ADDR,
allowFailure: false,
callData: abi.encodeWithSelector(Registry.setResolver.selector, _getNodeFromId(id), L2_RESOLVER_ADDR)
});

// CALL 2 :: set the resolver data for the name using `setAddr` and `setName` encoded for multicall.
calls[2] = IMulticall3.Call3({
target: L2_RESOLVER_ADDR,
allowFailure: false,
callData: _buildResolverData(_getNodeFromId(id), addr, name)
});

// CALL 2 :: call reclaim on behalf of the new owner.
calls[2] = IMulticall3.Call3({
// CALL 3 :: call reclaim on behalf of the new owner.
calls[3] = IMulticall3.Call3({
target: BASE_REGISTRAR_ADDR,
allowFailure: false,
callData: abi.encodeWithSelector(BaseRegistrar.reclaim.selector, id, addr)
});

// CALL 3 :: call safeTransferFrom to transfer the name to the new owner.
calls[3] = IMulticall3.Call3({
// CALL 4 :: call safeTransferFrom to transfer the name to the new owner.
calls[4] = IMulticall3.Call3({
target: BASE_REGISTRAR_ADDR,
allowFailure: false,
callData: abi.encodeWithSelector(IERC721.safeTransferFrom.selector, ECOSYSTEM_MULTISIG, addr, id)
Expand All @@ -76,11 +113,15 @@ contract DisburseBasenames is MultisigBuilder {
return calls;
}

function _getNodeFromId(uint256 id) internal view returns (bytes32 node) {
function _getNodeFromId(uint256 id) internal pure returns (bytes32 node) {
node = keccak256(abi.encodePacked(BASE_ETH_NODE, bytes32(id)));
}

function _buildResolverData(bytes32 node, address addr, string memory name) internal view returns (bytes memory data) {
function _getIdFromName(string memory name) internal pure returns (uint256 id) {
id = uint256(keccak256(bytes(name)));
}

function _buildResolverData(bytes32 node, address addr, string memory name) internal pure returns (bytes memory data) {
bytes[] memory multicallData = new bytes[](2);
multicallData[0] = abi.encodeWithSelector(AddrResolver.setAddr.selector, node, addr);
multicallData[1] = abi.encodeWithSelector(NameResolver.setName.selector, node, string.concat(name,".base.eth"));
Expand All @@ -97,4 +138,9 @@ contract DisburseBasenames is MultisigBuilder {
uint256 _nonce = _getNonce(safe);
return overrideSafeThresholdOwnerAndNonce(_safe, DEFAULT_SENDER, _nonce);
}

function _postCheck(Vm.AccountAccess[] memory, SimulationPayload memory) internal override{
console.log(L2Resolver(L2_RESOLVER_ADDR).name(_getNodeFromId(_getIdFromName("aave"))));
console.log(L2Resolver(L2_RESOLVER_ADDR).addr(_getNodeFromId(_getIdFromName("aave"))));
}
}

0 comments on commit 1f17dbb

Please sign in to comment.