dsa-connectors/contracts/optimism/connectors/spell/main.sol

80 lines
2.1 KiB
Solidity
Raw Normal View History

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
*/
2022-06-19 23:59:53 +00:00
function castOnDSA(
2022-06-19 13:54:10 +00:00
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
2022-06-19 23:59:53 +00:00
_eventName = "LogCastOnDSA(address,string[],bytes[])";
2022-06-19 13:54:10 +00:00
_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.
*/
2022-06-19 23:59:53 +00:00
function retrySpell(string[] memory connectors, bytes[] memory datas)
2022-06-19 15:26:15 +00:00
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]);
2022-06-19 23:59:53 +00:00
if (success) {
(_eventNames[i], _eventParams[i]) = abi.decode(
returnData,
(string, bytes)
);
}
2022-06-19 15:26:15 +00:00
}
2022-06-19 23:59:53 +00:00
eventName = "LogRetrySpell(string[],bytes[])";
2022-06-19 15:26:15 +00:00
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
}