2022-06-19 13:54:10 +00:00
|
|
|
//SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.7.0;
|
|
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
|
|
|
|
/**
|
2022-06-19 15:26:15 +00:00
|
|
|
* @title DSA Spell.
|
|
|
|
* @dev Cast spells on DSA.
|
2022-06-19 13:54:10 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// import files
|
|
|
|
import { AccountInterface } from "../../common/interfaces.sol";
|
2022-06-19 15:26:15 +00:00
|
|
|
import { Stores } from "../../common/stores.sol";
|
2022-06-19 13:54:10 +00:00
|
|
|
import { Events } from "./events.sol";
|
|
|
|
|
2022-06-19 15:26:15 +00:00
|
|
|
abstract contract DSASpell is Events, Stores {
|
2022-06-19 13:54:10 +00:00
|
|
|
/**
|
|
|
|
*@dev Cast spells on DSA.
|
|
|
|
*@param targetDSA target DSA to cast spells on.
|
2022-06-19 15:26:15 +00:00
|
|
|
*@param connectors Array of connector names.
|
|
|
|
*@param datas Array of connector calldatas.
|
2022-06-19 13:54:10 +00:00
|
|
|
*/
|
|
|
|
function castDSA(
|
|
|
|
address targetDSA,
|
|
|
|
string[] memory connectors,
|
|
|
|
bytes[] memory datas
|
|
|
|
)
|
|
|
|
external
|
|
|
|
payable
|
|
|
|
returns (string memory _eventName, bytes memory _eventParam)
|
|
|
|
{
|
|
|
|
require(instaList.accountID(targetDSA) != 0, "not-a-DSA");
|
|
|
|
|
2022-06-19 15:26:15 +00:00
|
|
|
AccountInterface(targetDSA).cast(connectors, datas, address(this));
|
2022-06-19 13:54:10 +00:00
|
|
|
|
|
|
|
_eventName = "LogCastDSA(address,string[],bytes[])";
|
|
|
|
_eventParam = abi.encode(targetDSA, connectors, datas);
|
|
|
|
}
|
2022-06-19 15:26:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*@dev Perform spells.
|
|
|
|
*@param connectors Array of connector names.
|
|
|
|
*@param datas Array of connector calldatas.
|
|
|
|
*/
|
|
|
|
function castSpells(string[] memory connectors, bytes[] memory datas)
|
|
|
|
external
|
|
|
|
payable
|
|
|
|
returns (string memory eventName, bytes memory eventParam)
|
|
|
|
{
|
|
|
|
uint256 _length = connectors.length;
|
|
|
|
require(_length > 0, "zero-length-not-allowed");
|
|
|
|
require(datas.length == _length, "calldata-length-invalid");
|
|
|
|
|
|
|
|
(bool isOk, address[] memory _connectors) = instaConnectors
|
|
|
|
.isConnectors(connectors);
|
|
|
|
require(isOk, "connector-names-invalid");
|
|
|
|
|
|
|
|
string[] memory _eventNames = new string[](_length);
|
|
|
|
bytes[] memory _eventParams = new bytes[](_length);
|
|
|
|
|
|
|
|
for (uint256 i = 0; i < _length; i++) {
|
|
|
|
(bool success, bytes memory returnData) = _connectors[i]
|
|
|
|
.delegatecall(datas[i]);
|
|
|
|
require(success, "spells-failed");
|
|
|
|
(_eventNames[i], _eventParams[i]) = abi.decode(
|
|
|
|
returnData,
|
|
|
|
(string, bytes)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
eventName = "LogCastSpells(string[],bytes[])";
|
|
|
|
eventParam = abi.encode(_eventNames, _eventParams);
|
|
|
|
}
|
2022-06-19 13:54:10 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 15:26:15 +00:00
|
|
|
contract ConnectV2DSASpellOptimism is DSASpell {
|
|
|
|
string public name = "DSA-Spell-v1.0";
|
2022-06-19 13:54:10 +00:00
|
|
|
}
|