-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from CirclesUBI/20240509-operators
20240509 operators
- Loading branch information
Showing
11 changed files
with
393 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity >=0.8.24; | ||
|
||
contract TypeDefinitions { | ||
// Type declarations | ||
|
||
/** | ||
* @notice TrustMarker stores the expiry of a trust relation as uint96, | ||
* and is iterable as a linked list of trust markers. | ||
* @dev This is used to store the directional trust relation between two avatars, | ||
* and the expiry of the trust relation as uint96 in unix time. | ||
*/ | ||
struct TrustMarker { | ||
address previous; | ||
uint96 expiry; | ||
} | ||
|
||
struct FlowEdge { | ||
uint16 streamSinkId; | ||
uint240 amount; // todo: set this to uint192 (align with demurrage), and leave it to compiler to pad | ||
} | ||
|
||
struct Stream { | ||
uint16 sourceCoordinate; | ||
uint16[] flowEdgeIds; // todo: this can possible be packed more compactly manually, evaluate | ||
bytes data; | ||
} | ||
|
||
struct Metadata { | ||
bytes32 metadataType; | ||
bytes metadata; | ||
bytes erc1155UserData; | ||
} | ||
|
||
struct GroupMintMetadata { | ||
address group; | ||
} | ||
|
||
// note: Redemption does not require Metadata | ||
|
||
// Constants | ||
|
||
bytes32 internal constant METADATATYPE_GROUPMINT = keccak256("CIRCLESv2:RESERVED_DATA:CirclesGroupMint"); | ||
bytes32 internal constant METADATATYPE_GROUPREDEEM = keccak256("CIRCLESv2:RESERVED_DATA:CirclesGroupRedeem"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity >=0.8.24; | ||
|
||
import "../errors/Errors.sol"; | ||
import "../hub/IHub.sol"; | ||
|
||
contract BaseOperator is ICirclesErrors { | ||
// State variables | ||
|
||
IHubV2 public hub; | ||
|
||
// Constructor | ||
|
||
constructor(IHubV2 _hub) { | ||
if (address(_hub) == address(0)) { | ||
// Must not be the zero address. | ||
revert CirclesAddressCannotBeZero(0); | ||
} | ||
|
||
hub = _hub; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity >=0.8.24; | ||
|
||
import "../hub/IHub.sol"; | ||
import "../hub/TypeDefinitions.sol"; | ||
import "./BaseOperator.sol"; | ||
|
||
contract SignedPathOperator is BaseOperator, TypeDefinitions { | ||
// Errors | ||
|
||
error CirclesOperatorInvalidStreamSource( | ||
uint256 streamIndex, uint256 singleSourceCoordinate, uint256 streamSourceCoordinate | ||
); | ||
|
||
// Constructor | ||
|
||
constructor(IHubV2 _hub) BaseOperator(_hub) {} | ||
|
||
// External functions | ||
|
||
function operateSignedFlowMatrix( | ||
address[] calldata _flowVertices, | ||
FlowEdge[] calldata _flow, | ||
Stream[] calldata _streams, | ||
bytes calldata _packedCoordinates, | ||
uint256 _sourceIndex | ||
) external { | ||
// Extract the alleged source vertex from the flow vertices | ||
uint16 sourceCoordinate = _extractSource(_packedCoordinates, _sourceIndex); | ||
address source = _flowVertices[sourceCoordinate]; | ||
// Ensure the source is the caller | ||
if (msg.sender != source) { | ||
revert CirclesInvalidFunctionCaller(msg.sender, source, 0); | ||
} | ||
|
||
// check that for every stream the source of the stream matches the alleged single source | ||
for (uint256 i = 0; i < _streams.length; i++) { | ||
if (_streams[i].sourceCoordinate != sourceCoordinate) { | ||
revert CirclesOperatorInvalidStreamSource(i, sourceCoordinate, _streams[i].sourceCoordinate); | ||
} | ||
} | ||
|
||
// Call the hub to operate the flow matrix | ||
hub.operateFlowMatrix(_flowVertices, _flow, _streams, _packedCoordinates); | ||
} | ||
|
||
// Internal functions | ||
|
||
function _extractSource(bytes calldata _packedCoordinates, uint256 _sourceIndex) internal pure returns (uint16) { | ||
return | ||
uint16(uint8(_packedCoordinates[_sourceIndex])) << 8 | uint16(uint8(_packedCoordinates[_sourceIndex + 1])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.