Commit 4b9c1cfe authored by smartcontracts's avatar smartcontracts Committed by GitHub

feat: add array of created drips to Drippie (#10742)

Adds a simple array that keeps track of all the drip names created
inside of the Drippie contract. Can be used by offchain services
to avoid needing event queries which are slow and expensive.
parent bfeecbdb
...@@ -139,6 +139,25 @@ ...@@ -139,6 +139,25 @@
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "type": "function"
}, },
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "created",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{ {
"inputs": [ "inputs": [
{ {
...@@ -249,6 +268,19 @@ ...@@ -249,6 +268,19 @@
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{
"inputs": [],
"name": "getDripCount",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{ {
"inputs": [ "inputs": [
{ {
......
...@@ -12,5 +12,12 @@ ...@@ -12,5 +12,12 @@
"offset": 0, "offset": 0,
"slot": "1", "slot": "1",
"type": "mapping(string => struct Drippie.DripState)" "type": "mapping(string => struct Drippie.DripState)"
},
{
"bytes": "32",
"label": "created",
"offset": 0,
"slot": "2",
"type": "string[]"
} }
] ]
\ No newline at end of file
...@@ -76,6 +76,11 @@ contract Drippie is AssetReceiver { ...@@ -76,6 +76,11 @@ contract Drippie is AssetReceiver {
/// @notice Maps from drip names to drip states. /// @notice Maps from drip names to drip states.
mapping(string => DripState) public drips; mapping(string => DripState) public drips;
/// @notice Array of created drips. Used so offchain services can easily iterate over all drips
/// without resorting to event queries. Convenience feature and shouldn't really be
/// used onchain because the array will grow indefinitely.
string[] public created;
//// @param _owner Initial contract owner. //// @param _owner Initial contract owner.
constructor(address _owner) AssetReceiver(_owner) { } constructor(address _owner) AssetReceiver(_owner) { }
...@@ -112,6 +117,9 @@ contract Drippie is AssetReceiver { ...@@ -112,6 +117,9 @@ contract Drippie is AssetReceiver {
state.config.actions.push(_config.actions[i]); state.config.actions.push(_config.actions[i]);
} }
// Add the name of the drip to the array of created drips.
created.push(_name);
// Tell the world! // Tell the world!
emit DripCreated(_name, _name, _config); emit DripCreated(_name, _name, _config);
} }
...@@ -258,4 +266,10 @@ contract Drippie is AssetReceiver { ...@@ -258,4 +266,10 @@ contract Drippie is AssetReceiver {
function getDripInterval(string calldata _name) public view returns (uint256) { function getDripInterval(string calldata _name) public view returns (uint256) {
return drips[_name].config.interval; return drips[_name].config.interval;
} }
/// @notice Returns the number of created drips.
/// @return Number of created drips.
function getDripCount() public view returns (uint256) {
return created.length;
}
} }
...@@ -125,6 +125,9 @@ contract Drippie_Test is Test { ...@@ -125,6 +125,9 @@ contract Drippie_Test is Test {
assertTrue(cfg.interval > 0); assertTrue(cfg.interval > 0);
} }
// Drip count is 0 before creating the drip.
assertEq(drippie.getDripCount(), 0);
vm.prank(drippie.owner()); vm.prank(drippie.owner());
drippie.create(dripName, cfg); drippie.create(dripName, cfg);
...@@ -148,6 +151,12 @@ contract Drippie_Test is Test { ...@@ -148,6 +151,12 @@ contract Drippie_Test is Test {
assertEq(a.data, b.data); assertEq(a.data, b.data);
assertEq(a.value, b.value); assertEq(a.value, b.value);
} }
// Drip count is 1 after creating the drip.
assertEq(drippie.getDripCount(), 1);
// Name of the first created drip is the same as the name of the drip.
assertEq(drippie.created(0), dripName);
} }
/// @notice Ensures that the same drip cannot be created two times. /// @notice Ensures that the same drip cannot be created two times.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment