updated castAny(), comments

This commit is contained in:
Richa-iitr 2022-06-20 18:48:38 +05:30
parent 655bd59878
commit 2dd6321f5a
12 changed files with 210 additions and 96 deletions

View File

@ -8,5 +8,11 @@ contract Events {
string[] connectors, string[] connectors,
bytes[] datas bytes[] datas
); );
event LogSpellFactory(string[] eventNames, bytes[] eventParams); event LogCastAny(
string indexed connector,
string connectorName,
string[] connectors,
string eventName,
bytes eventParam
);
} }

View File

@ -7,17 +7,17 @@ pragma experimental ABIEncoderV2;
* @dev Cast spells on DSA. * @dev Cast spells on DSA.
*/ */
// import files
import { AccountInterface } from "../../common/interfaces.sol"; import { AccountInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol"; import { Stores } from "../../common/stores.sol";
import { Events } from "./events.sol"; import { Events } from "./events.sol";
abstract contract DSASpellsResolver is Events, Stores { abstract contract DSASpellsResolver is Events, Stores {
/** /**
*@dev Cast spells on DSA. *@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.
*@param targetDSA target DSA to cast spells on. *@param targetDSA target DSA to cast spells on.
*@param connectors Array of connector names. *@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]).
*@param datas Array of connector calldatas. *@param datas Array of connector calldatas (function selectors encoded with parameters).
*/ */
function castOnDSA( function castOnDSA(
address targetDSA, address targetDSA,
@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores {
} }
/** /**
*@dev Perform spells. *@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully.
*@param connectors Array of connector names. * Reverts if none of the spells is successful.
*@param datas Array of connector calldatas. *@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).
*/ */
function spellFactory(string[] memory connectors, bytes[] memory datas) function castAny(string[] memory connectors, bytes[] memory datas)
external external
payable payable
returns (string memory eventName, bytes memory eventParam) returns (string memory eventName, bytes memory eventParam)
@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores {
.isConnectors(connectors); .isConnectors(connectors);
require(isOk, "connector-names-invalid"); require(isOk, "connector-names-invalid");
string[] memory _eventNames = new string[](_length); string memory _connectorName;
bytes[] memory _eventParams = new bytes[](_length); string memory _eventName;
bytes memory _eventParam;
bytes memory returnData;
bool success;
for (uint256 i = 0; i < _length; i++) { for (uint256 i = 0; i < _length; i++) {
(bool success, bytes memory returnData) = _connectors[i] (success, returnData) = _connectors[i].delegatecall(datas[i]);
.delegatecall(datas[i]);
if (success) { if (success) {
(_eventNames[i], _eventParams[i]) = abi.decode( _connectorName = connectors[i];
(_eventName, _eventParam) = abi.decode(
returnData, returnData,
(string, bytes) (string, bytes)
); );
break;
} }
} }
require(success, "dsa-spells-failed");
eventName = "LogSpellFactory(string[],bytes[])"; eventName = "LogCastAny(string,string,string[],string,bytes)";
eventParam = abi.encode(_eventNames, _eventParams); eventParam = abi.encode(
_connectorName,
_connectorName,
connectors,
_eventName,
_eventParam
);
} }
} }

View File

@ -8,5 +8,11 @@ contract Events {
string[] connectors, string[] connectors,
bytes[] datas bytes[] datas
); );
event LogSpellFactory(string[] eventNames, bytes[] eventParams); event LogCastAny(
string indexed connector,
string connectorName,
string[] connectors,
string eventName,
bytes eventParam
);
} }

View File

@ -7,17 +7,17 @@ pragma experimental ABIEncoderV2;
* @dev Cast spells on DSA. * @dev Cast spells on DSA.
*/ */
// import files
import { AccountInterface } from "../../common/interfaces.sol"; import { AccountInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol"; import { Stores } from "../../common/stores.sol";
import { Events } from "./events.sol"; import { Events } from "./events.sol";
abstract contract DSASpellsResolver is Events, Stores { abstract contract DSASpellsResolver is Events, Stores {
/** /**
*@dev Cast spells on DSA. *@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.
*@param targetDSA target DSA to cast spells on. *@param targetDSA target DSA to cast spells on.
*@param connectors Array of connector names. *@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]).
*@param datas Array of connector calldatas. *@param datas Array of connector calldatas (function selectors encoded with parameters).
*/ */
function castOnDSA( function castOnDSA(
address targetDSA, address targetDSA,
@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores {
} }
/** /**
*@dev Perform spells. *@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully.
*@param connectors Array of connector names. * Reverts if none of the spells is successful.
*@param datas Array of connector calldatas. *@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).
*/ */
function spellFactory(string[] memory connectors, bytes[] memory datas) function castAny(string[] memory connectors, bytes[] memory datas)
external external
payable payable
returns (string memory eventName, bytes memory eventParam) returns (string memory eventName, bytes memory eventParam)
@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores {
.isConnectors(connectors); .isConnectors(connectors);
require(isOk, "connector-names-invalid"); require(isOk, "connector-names-invalid");
string[] memory _eventNames = new string[](_length); string memory _connectorName;
bytes[] memory _eventParams = new bytes[](_length); string memory _eventName;
bytes memory _eventParam;
bytes memory returnData;
bool success;
for (uint256 i = 0; i < _length; i++) { for (uint256 i = 0; i < _length; i++) {
(bool success, bytes memory returnData) = _connectors[i] (success, returnData) = _connectors[i].delegatecall(datas[i]);
.delegatecall(datas[i]);
if (success) { if (success) {
(_eventNames[i], _eventParams[i]) = abi.decode( _connectorName = connectors[i];
(_eventName, _eventParam) = abi.decode(
returnData, returnData,
(string, bytes) (string, bytes)
); );
break;
} }
} }
require(success, "dsa-spells-failed");
eventName = "LogSpellFactory(string[],bytes[])"; eventName = "LogCastAny(string,string,string[],string,bytes)";
eventParam = abi.encode(_eventNames, _eventParams); eventParam = abi.encode(
_connectorName,
_connectorName,
connectors,
_eventName,
_eventParam
);
} }
} }

View File

@ -8,5 +8,11 @@ contract Events {
string[] connectors, string[] connectors,
bytes[] datas bytes[] datas
); );
event LogSpellFactory(string[] eventNames, bytes[] eventParams); event LogCastAny(
string indexed connector,
string connectorName,
string[] connectors,
string eventName,
bytes eventParam
);
} }

View File

@ -7,17 +7,17 @@ pragma experimental ABIEncoderV2;
* @dev Cast spells on DSA. * @dev Cast spells on DSA.
*/ */
// import files
import { AccountInterface } from "../../common/interfaces.sol"; import { AccountInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol"; import { Stores } from "../../common/stores.sol";
import { Events } from "./events.sol"; import { Events } from "./events.sol";
abstract contract DSASpellsResolver is Events, Stores { abstract contract DSASpellsResolver is Events, Stores {
/** /**
*@dev Cast spells on DSA. *@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.
*@param targetDSA target DSA to cast spells on. *@param targetDSA target DSA to cast spells on.
*@param connectors Array of connector names. *@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]).
*@param datas Array of connector calldatas. *@param datas Array of connector calldatas (function selectors encoded with parameters).
*/ */
function castOnDSA( function castOnDSA(
address targetDSA, address targetDSA,
@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores {
} }
/** /**
*@dev Perform spells. *@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully.
*@param connectors Array of connector names. * Reverts if none of the spells is successful.
*@param datas Array of connector calldatas. *@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).
*/ */
function spellFactory(string[] memory connectors, bytes[] memory datas) function castAny(string[] memory connectors, bytes[] memory datas)
external external
payable payable
returns (string memory eventName, bytes memory eventParam) returns (string memory eventName, bytes memory eventParam)
@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores {
.isConnectors(connectors); .isConnectors(connectors);
require(isOk, "connector-names-invalid"); require(isOk, "connector-names-invalid");
string[] memory _eventNames = new string[](_length); string memory _connectorName;
bytes[] memory _eventParams = new bytes[](_length); string memory _eventName;
bytes memory _eventParam;
bytes memory returnData;
bool success;
for (uint256 i = 0; i < _length; i++) { for (uint256 i = 0; i < _length; i++) {
(bool success, bytes memory returnData) = _connectors[i] (success, returnData) = _connectors[i].delegatecall(datas[i]);
.delegatecall(datas[i]);
if (success) { if (success) {
(_eventNames[i], _eventParams[i]) = abi.decode( _connectorName = connectors[i];
(_eventName, _eventParam) = abi.decode(
returnData, returnData,
(string, bytes) (string, bytes)
); );
break;
} }
} }
require(success, "dsa-spells-failed");
eventName = "LogSpellFactory(string[],bytes[])"; eventName = "LogCastAny(string,string,string[],string,bytes)";
eventParam = abi.encode(_eventNames, _eventParams); eventParam = abi.encode(
_connectorName,
_connectorName,
connectors,
_eventName,
_eventParam
);
} }
} }

View File

@ -8,5 +8,11 @@ contract Events {
string[] connectors, string[] connectors,
bytes[] datas bytes[] datas
); );
event LogSpellFactory(string[] eventNames, bytes[] eventParams); event LogCastAny(
string indexed connector,
string connectorName,
string[] connectors,
string eventName,
bytes eventParam
);
} }

View File

@ -7,17 +7,17 @@ pragma experimental ABIEncoderV2;
* @dev Cast spells on DSA. * @dev Cast spells on DSA.
*/ */
// import files
import { AccountInterface } from "../../common/interfaces.sol"; import { AccountInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol"; import { Stores } from "../../common/stores.sol";
import { Events } from "./events.sol"; import { Events } from "./events.sol";
abstract contract DSASpellsResolver is Events, Stores { abstract contract DSASpellsResolver is Events, Stores {
/** /**
*@dev Cast spells on DSA. *@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.
*@param targetDSA target DSA to cast spells on. *@param targetDSA target DSA to cast spells on.
*@param connectors Array of connector names. *@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]).
*@param datas Array of connector calldatas. *@param datas Array of connector calldatas (function selectors encoded with parameters).
*/ */
function castOnDSA( function castOnDSA(
address targetDSA, address targetDSA,
@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores {
} }
/** /**
*@dev Perform spells. *@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully.
*@param connectors Array of connector names. * Reverts if none of the spells is successful.
*@param datas Array of connector calldatas. *@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).
*/ */
function spellFactory(string[] memory connectors, bytes[] memory datas) function castAny(string[] memory connectors, bytes[] memory datas)
external external
payable payable
returns (string memory eventName, bytes memory eventParam) returns (string memory eventName, bytes memory eventParam)
@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores {
.isConnectors(connectors); .isConnectors(connectors);
require(isOk, "connector-names-invalid"); require(isOk, "connector-names-invalid");
string[] memory _eventNames = new string[](_length); string memory _connectorName;
bytes[] memory _eventParams = new bytes[](_length); string memory _eventName;
bytes memory _eventParam;
bytes memory returnData;
bool success;
for (uint256 i = 0; i < _length; i++) { for (uint256 i = 0; i < _length; i++) {
(bool success, bytes memory returnData) = _connectors[i] (success, returnData) = _connectors[i].delegatecall(datas[i]);
.delegatecall(datas[i]);
if (success) { if (success) {
(_eventNames[i], _eventParams[i]) = abi.decode( _connectorName = connectors[i];
(_eventName, _eventParam) = abi.decode(
returnData, returnData,
(string, bytes) (string, bytes)
); );
break;
} }
} }
require(success, "dsa-spells-failed");
eventName = "LogSpellFactory(string[],bytes[])"; eventName = "LogCastAny(string,string,string[],string,bytes)";
eventParam = abi.encode(_eventNames, _eventParams); eventParam = abi.encode(
_connectorName,
_connectorName,
connectors,
_eventName,
_eventParam
);
} }
} }

View File

@ -8,5 +8,11 @@ contract Events {
string[] connectors, string[] connectors,
bytes[] datas bytes[] datas
); );
event LogSpellFactory(string[] eventNames, bytes[] eventParams); event LogCastAny(
string indexed connector,
string connectorName,
string[] connectors,
string eventName,
bytes eventParam
);
} }

View File

@ -7,17 +7,17 @@ pragma experimental ABIEncoderV2;
* @dev Cast spells on DSA. * @dev Cast spells on DSA.
*/ */
// import files
import { AccountInterface } from "../../common/interfaces.sol"; import { AccountInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol"; import { Stores } from "../../common/stores.sol";
import { Events } from "./events.sol"; import { Events } from "./events.sol";
abstract contract DSASpellsResolver is Events, Stores { abstract contract DSASpellsResolver is Events, Stores {
/** /**
*@dev Cast spells on DSA. *@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.
*@param targetDSA target DSA to cast spells on. *@param targetDSA target DSA to cast spells on.
*@param connectors Array of connector names. *@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]).
*@param datas Array of connector calldatas. *@param datas Array of connector calldatas (function selectors encoded with parameters).
*/ */
function castOnDSA( function castOnDSA(
address targetDSA, address targetDSA,
@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores {
} }
/** /**
*@dev Perform spells. *@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully.
*@param connectors Array of connector names. * Reverts if none of the spells is successful.
*@param datas Array of connector calldatas. *@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).
*/ */
function spellFactory(string[] memory connectors, bytes[] memory datas) function castAny(string[] memory connectors, bytes[] memory datas)
external external
payable payable
returns (string memory eventName, bytes memory eventParam) returns (string memory eventName, bytes memory eventParam)
@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores {
.isConnectors(connectors); .isConnectors(connectors);
require(isOk, "connector-names-invalid"); require(isOk, "connector-names-invalid");
string[] memory _eventNames = new string[](_length); string memory _connectorName;
bytes[] memory _eventParams = new bytes[](_length); string memory _eventName;
bytes memory _eventParam;
bytes memory returnData;
bool success;
for (uint256 i = 0; i < _length; i++) { for (uint256 i = 0; i < _length; i++) {
(bool success, bytes memory returnData) = _connectors[i] (success, returnData) = _connectors[i].delegatecall(datas[i]);
.delegatecall(datas[i]);
if (success) { if (success) {
(_eventNames[i], _eventParams[i]) = abi.decode( _connectorName = connectors[i];
(_eventName, _eventParam) = abi.decode(
returnData, returnData,
(string, bytes) (string, bytes)
); );
break;
} }
} }
require(success, "dsa-spells-failed");
eventName = "LogSpellFactory(string[],bytes[])"; eventName = "LogCastAny(string,string,string[],string,bytes)";
eventParam = abi.encode(_eventNames, _eventParams); eventParam = abi.encode(
_connectorName,
_connectorName,
connectors,
_eventName,
_eventParam
);
} }
} }

View File

@ -8,5 +8,11 @@ contract Events {
string[] connectors, string[] connectors,
bytes[] datas bytes[] datas
); );
event LogSpellFactory(string[] eventNames, bytes[] eventParams); event LogCastAny(
string indexed connector,
string connectorName,
string[] connectors,
string eventName,
bytes eventParam
);
} }

View File

@ -7,17 +7,17 @@ pragma experimental ABIEncoderV2;
* @dev Cast spells on DSA. * @dev Cast spells on DSA.
*/ */
// import files
import { AccountInterface } from "../../common/interfaces.sol"; import { AccountInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol"; import { Stores } from "../../common/stores.sol";
import { Events } from "./events.sol"; import { Events } from "./events.sol";
abstract contract DSASpellsResolver is Events, Stores { abstract contract DSASpellsResolver is Events, Stores {
/** /**
*@dev Cast spells on DSA. *@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.
*@param targetDSA target DSA to cast spells on. *@param targetDSA target DSA to cast spells on.
*@param connectors Array of connector names. *@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]).
*@param datas Array of connector calldatas. *@param datas Array of connector calldatas (function selectors encoded with parameters).
*/ */
function castOnDSA( function castOnDSA(
address targetDSA, address targetDSA,
@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores {
} }
/** /**
*@dev Perform spells. *@dev Casts spell on caller DSA. Stops casting further spells as soon as a spell gets casted successfully.
*@param connectors Array of connector names. * Reverts if none of the spells is successful.
*@param datas Array of connector calldatas. *@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).
*/ */
function spellFactory(string[] memory connectors, bytes[] memory datas) function castAny(string[] memory connectors, bytes[] memory datas)
external external
payable payable
returns (string memory eventName, bytes memory eventParam) returns (string memory eventName, bytes memory eventParam)
@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores {
.isConnectors(connectors); .isConnectors(connectors);
require(isOk, "connector-names-invalid"); require(isOk, "connector-names-invalid");
string[] memory _eventNames = new string[](_length); string memory _connectorName;
bytes[] memory _eventParams = new bytes[](_length); string memory _eventName;
bytes memory _eventParam;
bytes memory returnData;
bool success;
for (uint256 i = 0; i < _length; i++) { for (uint256 i = 0; i < _length; i++) {
(bool success, bytes memory returnData) = _connectors[i] (success, returnData) = _connectors[i].delegatecall(datas[i]);
.delegatecall(datas[i]);
if (success) { if (success) {
(_eventNames[i], _eventParams[i]) = abi.decode( _connectorName = connectors[i];
(_eventName, _eventParam) = abi.decode(
returnData, returnData,
(string, bytes) (string, bytes)
); );
break;
} }
} }
require(success, "dsa-spells-failed");
eventName = "LogSpellFactory(string[],bytes[])"; eventName = "LogCastAny(string,string,string[],string,bytes)";
eventParam = abi.encode(_eventNames, _eventParams); eventParam = abi.encode(
_connectorName,
_connectorName,
connectors,
_eventName,
_eventParam
);
} }
} }