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

View File

@ -8,5 +8,11 @@ contract Events {
string[] connectors,
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.
*/
// import files
import { AccountInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol";
import { Events } from "./events.sol";
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 connectors Array of connector names.
*@param datas Array of connector calldatas.
*@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]).
*@param datas Array of connector calldatas (function selectors encoded with parameters).
*/
function castOnDSA(
address targetDSA,
@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores {
}
/**
*@dev Perform spells.
*@param connectors Array of connector names.
*@param datas Array of connector calldatas.
*@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).
*/
function spellFactory(string[] memory connectors, bytes[] memory datas)
function castAny(string[] memory connectors, bytes[] memory datas)
external
payable
returns (string memory eventName, bytes memory eventParam)
@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores {
.isConnectors(connectors);
require(isOk, "connector-names-invalid");
string[] memory _eventNames = new string[](_length);
bytes[] memory _eventParams = new bytes[](_length);
string memory _connectorName;
string memory _eventName;
bytes memory _eventParam;
bytes memory returnData;
bool success;
for (uint256 i = 0; i < _length; i++) {
(bool success, bytes memory returnData) = _connectors[i]
.delegatecall(datas[i]);
(success, returnData) = _connectors[i].delegatecall(datas[i]);
if (success) {
(_eventNames[i], _eventParams[i]) = abi.decode(
_connectorName = connectors[i];
(_eventName, _eventParam) = abi.decode(
returnData,
(string, bytes)
);
break;
}
}
require(success, "dsa-spells-failed");
eventName = "LogSpellFactory(string[],bytes[])";
eventParam = abi.encode(_eventNames, _eventParams);
eventName = "LogCastAny(string,string,string[],string,bytes)";
eventParam = abi.encode(
_connectorName,
_connectorName,
connectors,
_eventName,
_eventParam
);
}
}

View File

@ -8,5 +8,11 @@ contract Events {
string[] connectors,
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.
*/
// import files
import { AccountInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol";
import { Events } from "./events.sol";
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 connectors Array of connector names.
*@param datas Array of connector calldatas.
*@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]).
*@param datas Array of connector calldatas (function selectors encoded with parameters).
*/
function castOnDSA(
address targetDSA,
@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores {
}
/**
*@dev Perform spells.
*@param connectors Array of connector names.
*@param datas Array of connector calldatas.
*@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).
*/
function spellFactory(string[] memory connectors, bytes[] memory datas)
function castAny(string[] memory connectors, bytes[] memory datas)
external
payable
returns (string memory eventName, bytes memory eventParam)
@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores {
.isConnectors(connectors);
require(isOk, "connector-names-invalid");
string[] memory _eventNames = new string[](_length);
bytes[] memory _eventParams = new bytes[](_length);
string memory _connectorName;
string memory _eventName;
bytes memory _eventParam;
bytes memory returnData;
bool success;
for (uint256 i = 0; i < _length; i++) {
(bool success, bytes memory returnData) = _connectors[i]
.delegatecall(datas[i]);
(success, returnData) = _connectors[i].delegatecall(datas[i]);
if (success) {
(_eventNames[i], _eventParams[i]) = abi.decode(
_connectorName = connectors[i];
(_eventName, _eventParam) = abi.decode(
returnData,
(string, bytes)
);
break;
}
}
require(success, "dsa-spells-failed");
eventName = "LogSpellFactory(string[],bytes[])";
eventParam = abi.encode(_eventNames, _eventParams);
eventName = "LogCastAny(string,string,string[],string,bytes)";
eventParam = abi.encode(
_connectorName,
_connectorName,
connectors,
_eventName,
_eventParam
);
}
}

View File

@ -8,5 +8,11 @@ contract Events {
string[] connectors,
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.
*/
// import files
import { AccountInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol";
import { Events } from "./events.sol";
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 connectors Array of connector names.
*@param datas Array of connector calldatas.
*@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]).
*@param datas Array of connector calldatas (function selectors encoded with parameters).
*/
function castOnDSA(
address targetDSA,
@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores {
}
/**
*@dev Perform spells.
*@param connectors Array of connector names.
*@param datas Array of connector calldatas.
*@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).
*/
function spellFactory(string[] memory connectors, bytes[] memory datas)
function castAny(string[] memory connectors, bytes[] memory datas)
external
payable
returns (string memory eventName, bytes memory eventParam)
@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores {
.isConnectors(connectors);
require(isOk, "connector-names-invalid");
string[] memory _eventNames = new string[](_length);
bytes[] memory _eventParams = new bytes[](_length);
string memory _connectorName;
string memory _eventName;
bytes memory _eventParam;
bytes memory returnData;
bool success;
for (uint256 i = 0; i < _length; i++) {
(bool success, bytes memory returnData) = _connectors[i]
.delegatecall(datas[i]);
(success, returnData) = _connectors[i].delegatecall(datas[i]);
if (success) {
(_eventNames[i], _eventParams[i]) = abi.decode(
_connectorName = connectors[i];
(_eventName, _eventParam) = abi.decode(
returnData,
(string, bytes)
);
break;
}
}
require(success, "dsa-spells-failed");
eventName = "LogSpellFactory(string[],bytes[])";
eventParam = abi.encode(_eventNames, _eventParams);
eventName = "LogCastAny(string,string,string[],string,bytes)";
eventParam = abi.encode(
_connectorName,
_connectorName,
connectors,
_eventName,
_eventParam
);
}
}

View File

@ -8,5 +8,11 @@ contract Events {
string[] connectors,
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.
*/
// import files
import { AccountInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol";
import { Events } from "./events.sol";
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 connectors Array of connector names.
*@param datas Array of connector calldatas.
*@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]).
*@param datas Array of connector calldatas (function selectors encoded with parameters).
*/
function castOnDSA(
address targetDSA,
@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores {
}
/**
*@dev Perform spells.
*@param connectors Array of connector names.
*@param datas Array of connector calldatas.
*@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).
*/
function spellFactory(string[] memory connectors, bytes[] memory datas)
function castAny(string[] memory connectors, bytes[] memory datas)
external
payable
returns (string memory eventName, bytes memory eventParam)
@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores {
.isConnectors(connectors);
require(isOk, "connector-names-invalid");
string[] memory _eventNames = new string[](_length);
bytes[] memory _eventParams = new bytes[](_length);
string memory _connectorName;
string memory _eventName;
bytes memory _eventParam;
bytes memory returnData;
bool success;
for (uint256 i = 0; i < _length; i++) {
(bool success, bytes memory returnData) = _connectors[i]
.delegatecall(datas[i]);
(success, returnData) = _connectors[i].delegatecall(datas[i]);
if (success) {
(_eventNames[i], _eventParams[i]) = abi.decode(
_connectorName = connectors[i];
(_eventName, _eventParam) = abi.decode(
returnData,
(string, bytes)
);
break;
}
}
require(success, "dsa-spells-failed");
eventName = "LogSpellFactory(string[],bytes[])";
eventParam = abi.encode(_eventNames, _eventParams);
eventName = "LogCastAny(string,string,string[],string,bytes)";
eventParam = abi.encode(
_connectorName,
_connectorName,
connectors,
_eventName,
_eventParam
);
}
}

View File

@ -8,5 +8,11 @@ contract Events {
string[] connectors,
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.
*/
// import files
import { AccountInterface } from "../../common/interfaces.sol";
import { Stores } from "../../common/stores.sol";
import { Events } from "./events.sol";
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 connectors Array of connector names.
*@param datas Array of connector calldatas.
*@param connectors Array of connector names (For example, ["1INCH-A", "BASIC-A"]).
*@param datas Array of connector calldatas (function selectors encoded with parameters).
*/
function castOnDSA(
address targetDSA,
@ -37,11 +37,13 @@ abstract contract DSASpellsResolver is Events, Stores {
}
/**
*@dev Perform spells.
*@param connectors Array of connector names.
*@param datas Array of connector calldatas.
*@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).
*/
function spellFactory(string[] memory connectors, bytes[] memory datas)
function castAny(string[] memory connectors, bytes[] memory datas)
external
payable
returns (string memory eventName, bytes memory eventParam)
@ -54,23 +56,34 @@ abstract contract DSASpellsResolver is Events, Stores {
.isConnectors(connectors);
require(isOk, "connector-names-invalid");
string[] memory _eventNames = new string[](_length);
bytes[] memory _eventParams = new bytes[](_length);
string memory _connectorName;
string memory _eventName;
bytes memory _eventParam;
bytes memory returnData;
bool success;
for (uint256 i = 0; i < _length; i++) {
(bool success, bytes memory returnData) = _connectors[i]
.delegatecall(datas[i]);
(success, returnData) = _connectors[i].delegatecall(datas[i]);
if (success) {
(_eventNames[i], _eventParams[i]) = abi.decode(
_connectorName = connectors[i];
(_eventName, _eventParam) = abi.decode(
returnData,
(string, bytes)
);
break;
}
}
require(success, "dsa-spells-failed");
eventName = "LogSpellFactory(string[],bytes[])";
eventParam = abi.encode(_eventNames, _eventParams);
eventName = "LogCastAny(string,string,string[],string,bytes)";
eventParam = abi.encode(
_connectorName,
_connectorName,
connectors,
_eventName,
_eventParam
);
}
}