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 { 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-20 05:45:10 +00:00
|
|
|
abstract contract DSASpellsResolver is Events, Stores {
|
2022-06-19 13:54:10 +00:00
|
|
|
/**
|
2022-06-20 13:18:38 +00:00
|
|
|
*@dev Casts spells on a DSA, caller DSA should be an auth of the target DSA. Reverts if any spell failed.
|
|
|
|
*@notice Interact with a target DSA by casting spells on it.
|
2022-06-19 13:54:10 +00:00
|
|
|
*@param targetDSA target DSA to cast spells on.
|
2022-06-20 13:18:38 +00:00
|
|
|
*@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]).
|
|
|
|
*@param datas Array of connector calldatas (function selectors encoded with parameters).
|
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
|
|
|
|
|
|
|
/**
|
2022-06-20 13:18:38 +00:00
|
|
|
*@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully.
|
|
|
|
* Reverts if none of the spells is successful.
|
|
|
|
*@notice Casts the first successful spell on the DSA.
|
|
|
|
*@param connectors Array of connector names, in preference order, if any (For example, ["1INCH-A", "ZEROX-A"]).
|
|
|
|
*@param datas Array of connector calldatas (function selectors encoded with parameters).
|
2022-06-19 15:26:15 +00:00
|
|
|
*/
|
2022-06-20 13:18:38 +00:00
|
|
|
function castAny(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");
|
|
|
|
|
2022-06-20 13:18:38 +00:00
|
|
|
string memory _connectorName;
|
|
|
|
string memory _eventName;
|
|
|
|
bytes memory _eventParam;
|
|
|
|
bytes memory returnData;
|
|
|
|
bool success;
|
2022-06-19 15:26:15 +00:00
|
|
|
|
|
|
|
for (uint256 i = 0; i < _length; i++) {
|
2022-06-20 13:18:38 +00:00
|
|
|
(success, returnData) = _connectors[i].delegatecall(datas[i]);
|
2022-06-19 23:59:53 +00:00
|
|
|
|
|
|
|
if (success) {
|
2022-06-20 13:18:38 +00:00
|
|
|
_connectorName = connectors[i];
|
|
|
|
(_eventName, _eventParam) = abi.decode(
|
2022-06-19 23:59:53 +00:00
|
|
|
returnData,
|
|
|
|
(string, bytes)
|
|
|
|
);
|
2022-06-20 13:18:38 +00:00
|
|
|
break;
|
2022-06-19 23:59:53 +00:00
|
|
|
}
|
2022-06-19 15:26:15 +00:00
|
|
|
}
|
2022-06-20 13:18:38 +00:00
|
|
|
require(success, "dsa-spells-failed");
|
2022-06-19 15:26:15 +00:00
|
|
|
|
2022-06-20 16:56:33 +00:00
|
|
|
eventName = "LogCastAny(string[],string,string,bytes)";
|
2022-06-20 13:18:38 +00:00
|
|
|
eventParam = abi.encode(
|
|
|
|
connectors,
|
2022-06-20 16:56:33 +00:00
|
|
|
_connectorName,
|
2022-06-20 13:18:38 +00:00
|
|
|
_eventName,
|
|
|
|
_eventParam
|
|
|
|
);
|
2022-06-19 15:26:15 +00:00
|
|
|
}
|
2022-06-19 13:54:10 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 05:45:10 +00:00
|
|
|
contract ConnectV2DSASpellFantom is DSASpellsResolver {
|
2022-06-19 15:26:15 +00:00
|
|
|
string public name = "DSA-Spell-v1.0";
|
2022-06-19 13:54:10 +00:00
|
|
|
}
|