Skip to content

Commit

Permalink
Merge pull request #869 from nounsDAO/verbs-stream-escrow-subgraph
Browse files Browse the repository at this point in the history
DRAFT: stream escrow subgraph
  • Loading branch information
davidbrai authored Nov 21, 2024
2 parents ed6dc7d + cf241d1 commit 7949033
Show file tree
Hide file tree
Showing 12 changed files with 1,409 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/subgraph-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Prepare subgraph yaml
run: |
cd packages/nouns-subgraph
yarn prepare:rinkeby
yarn prepare:sepolia
- name: Generate code
run: |
cd packages/nouns-subgraph
Expand Down
323 changes: 323 additions & 0 deletions packages/nouns-contracts/abi/contracts/StreamEscrow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,323 @@
[
{
"type": "constructor",
"inputs": [
{ "name": "daoExecutor_", "type": "address", "internalType": "address" },
{ "name": "ethRecipient_", "type": "address", "internalType": "address" },
{ "name": "nounsRecipient_", "type": "address", "internalType": "address" },
{ "name": "nounsToken_", "type": "address", "internalType": "address" },
{ "name": "streamCreator_", "type": "address", "internalType": "address" },
{ "name": "minimumTickDuration_", "type": "uint32", "internalType": "uint32" }
],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "allowedToCreateStream",
"inputs": [{ "name": "", "type": "address", "internalType": "address" }],
"outputs": [{ "name": "", "type": "bool", "internalType": "bool" }],
"stateMutability": "view"
},
{
"type": "function",
"name": "cancelStream",
"inputs": [{ "name": "nounId", "type": "uint256", "internalType": "uint256" }],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "cancelStreams",
"inputs": [{ "name": "nounIds", "type": "uint256[]", "internalType": "uint256[]" }],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "createStream",
"inputs": [
{ "name": "nounId", "type": "uint256", "internalType": "uint256" },
{ "name": "streamLengthInTicks", "type": "uint16", "internalType": "uint16" }
],
"outputs": [],
"stateMutability": "payable"
},
{
"type": "function",
"name": "currentTick",
"inputs": [],
"outputs": [{ "name": "", "type": "uint32", "internalType": "uint32" }],
"stateMutability": "view"
},
{
"type": "function",
"name": "daoExecutor",
"inputs": [],
"outputs": [{ "name": "", "type": "address", "internalType": "address" }],
"stateMutability": "view"
},
{
"type": "function",
"name": "ethRecipient",
"inputs": [],
"outputs": [{ "name": "", "type": "address", "internalType": "address" }],
"stateMutability": "view"
},
{
"type": "function",
"name": "ethStreamEndingAtTick",
"inputs": [{ "name": "tick", "type": "uint256", "internalType": "uint256" }],
"outputs": [{ "name": "ethPerTick", "type": "uint128", "internalType": "uint128" }],
"stateMutability": "view"
},
{
"type": "function",
"name": "ethStreamedPerTick",
"inputs": [],
"outputs": [{ "name": "", "type": "uint128", "internalType": "uint128" }],
"stateMutability": "view"
},
{
"type": "function",
"name": "fastForwardStream",
"inputs": [
{ "name": "nounId", "type": "uint256", "internalType": "uint256" },
{ "name": "ticksToForward", "type": "uint32", "internalType": "uint32" }
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "forwardAll",
"inputs": [],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "forwardAllAndCreateStream",
"inputs": [
{ "name": "nounId", "type": "uint256", "internalType": "uint256" },
{ "name": "streamLengthInTicks", "type": "uint16", "internalType": "uint16" }
],
"outputs": [],
"stateMutability": "payable"
},
{
"type": "function",
"name": "getStream",
"inputs": [{ "name": "nounId", "type": "uint256", "internalType": "uint256" }],
"outputs": [
{
"name": "",
"type": "tuple",
"internalType": "struct IStreamEscrow.Stream",
"components": [
{ "name": "ethPerTick", "type": "uint128", "internalType": "uint128" },
{ "name": "canceled", "type": "bool", "internalType": "bool" },
{ "name": "lastTick", "type": "uint32", "internalType": "uint32" }
]
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "isStreamActive",
"inputs": [{ "name": "nounId", "type": "uint256", "internalType": "uint256" }],
"outputs": [{ "name": "", "type": "bool", "internalType": "bool" }],
"stateMutability": "view"
},
{
"type": "function",
"name": "lastForwardTimestamp",
"inputs": [],
"outputs": [{ "name": "", "type": "uint48", "internalType": "uint48" }],
"stateMutability": "view"
},
{
"type": "function",
"name": "minimumTickDuration",
"inputs": [],
"outputs": [{ "name": "", "type": "uint32", "internalType": "uint32" }],
"stateMutability": "view"
},
{
"type": "function",
"name": "nounsRecipient",
"inputs": [],
"outputs": [{ "name": "", "type": "address", "internalType": "address" }],
"stateMutability": "view"
},
{
"type": "function",
"name": "nounsToken",
"inputs": [],
"outputs": [{ "name": "", "type": "address", "internalType": "contract INounsToken" }],
"stateMutability": "view"
},
{
"type": "function",
"name": "rescueToken",
"inputs": [
{ "name": "token", "type": "address", "internalType": "address" },
{ "name": "to", "type": "address", "internalType": "address" },
{ "name": "amount", "type": "uint256", "internalType": "uint256" }
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "setAllowedToCreateStream",
"inputs": [
{ "name": "address_", "type": "address", "internalType": "address" },
{ "name": "allowed", "type": "bool", "internalType": "bool" }
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "setDAOExecutorAddress",
"inputs": [{ "name": "newAddress", "type": "address", "internalType": "address" }],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "setETHRecipient",
"inputs": [{ "name": "newAddress", "type": "address", "internalType": "address" }],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "setNounsRecipient",
"inputs": [{ "name": "newAddress", "type": "address", "internalType": "address" }],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "event",
"name": "AllowedToCreateStreamChanged",
"inputs": [
{ "name": "address_", "type": "address", "indexed": false, "internalType": "address" },
{ "name": "allowed", "type": "bool", "indexed": false, "internalType": "bool" }
],
"anonymous": false
},
{
"type": "event",
"name": "DAOExecutorAddressSet",
"inputs": [
{ "name": "newAddress", "type": "address", "indexed": false, "internalType": "address" }
],
"anonymous": false
},
{
"type": "event",
"name": "ETHRecipientSet",
"inputs": [
{ "name": "newAddress", "type": "address", "indexed": false, "internalType": "address" }
],
"anonymous": false
},
{
"type": "event",
"name": "ETHStreamedToDAO",
"inputs": [
{ "name": "amount", "type": "uint256", "indexed": false, "internalType": "uint256" }
],
"anonymous": false
},
{
"type": "event",
"name": "NounsRecipientSet",
"inputs": [
{ "name": "newAddress", "type": "address", "indexed": false, "internalType": "address" }
],
"anonymous": false
},
{
"type": "event",
"name": "StreamCanceled",
"inputs": [
{ "name": "nounId", "type": "uint256", "indexed": true, "internalType": "uint256" },
{ "name": "amountToRefund", "type": "uint256", "indexed": false, "internalType": "uint256" },
{
"name": "ethStreamedPerTick",
"type": "uint128",
"indexed": false,
"internalType": "uint128"
}
],
"anonymous": false
},
{
"type": "event",
"name": "StreamCreated",
"inputs": [
{ "name": "nounId", "type": "uint256", "indexed": true, "internalType": "uint256" },
{ "name": "totalAmount", "type": "uint256", "indexed": false, "internalType": "uint256" },
{
"name": "streamLengthInTicks",
"type": "uint16",
"indexed": false,
"internalType": "uint16"
},
{ "name": "ethPerTick", "type": "uint256", "indexed": false, "internalType": "uint256" },
{
"name": "newEthStreamedPerTick",
"type": "uint128",
"indexed": false,
"internalType": "uint128"
},
{ "name": "lastTick", "type": "uint32", "indexed": false, "internalType": "uint32" }
],
"anonymous": false
},
{
"type": "event",
"name": "StreamFastForwarded",
"inputs": [
{ "name": "nounId", "type": "uint256", "indexed": true, "internalType": "uint256" },
{ "name": "ticksToForward", "type": "uint256", "indexed": false, "internalType": "uint256" },
{ "name": "newLastTick", "type": "uint256", "indexed": false, "internalType": "uint256" },
{
"name": "ethStreamedPerTick",
"type": "uint128",
"indexed": false,
"internalType": "uint128"
}
],
"anonymous": false
},
{
"type": "event",
"name": "StreamsForwarded",
"inputs": [
{ "name": "currentTick", "type": "uint256", "indexed": false, "internalType": "uint256" },
{
"name": "ethPerTickStreamEnded",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
},
{
"name": "nextEthStreamedPerTick",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
},
{
"name": "lastForwardTimestamp",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
}
],
"anonymous": false
}
]
22 changes: 20 additions & 2 deletions packages/nouns-contracts/contracts/StreamEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ contract StreamEscrow is IStreamEscrow {
nounsToken = INounsToken(nounsToken_);
allowedToCreateStream[streamCreator_] = true;
minimumTickDuration = minimumTickDuration_;

emit DAOExecutorAddressSet(daoExecutor_);
emit ETHRecipientSet(ethRecipient_);
emit NounsRecipientSet(nounsRecipient_);
emit AllowedToCreateStreamChanged(streamCreator_, true);
}

/**
Expand Down Expand Up @@ -177,7 +182,7 @@ contract StreamEscrow is IStreamEscrow {
(bool sent, ) = msg.sender.call{ value: amountToRefund }('');
require(sent, 'failed to send eth');

emit StreamCanceled(nounId, amountToRefund);
emit StreamCanceled(nounId, amountToRefund, ethStreamedPerTick);
}

/**
Expand Down Expand Up @@ -215,7 +220,20 @@ contract StreamEscrow is IStreamEscrow {
uint256 ethToStream = ticksToForward * stream.ethPerTick;
sendETHToTreasury(ethToStream);

emit StreamFastForwarded(nounId, ticksToForward, newLastTick);
emit StreamFastForwarded(nounId, ticksToForward, newLastTick, ethStreamedPerTick);
}

/**
* @notice Fast-forwards multiple streams by a certain number of ticks. See `fastForwardStream` for more details.
* @param nounIds The IDs of the Noun tokens to fast-forward streams for.
* @param ticksToForward An array of the number of ticks to fast-forward each stream by.
*/
function fastForwardMultipleStreams(uint256[] calldata nounIds, uint32[] calldata ticksToForward) external {
require(nounIds.length == ticksToForward.length, 'length mismatch');

for (uint256 i; i < nounIds.length; ++i) {
fastForwardStream(nounIds[i], ticksToForward[i]);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ interface IStreamEscrow {
uint256 nextEthStreamedPerTick,
uint256 lastForwardTimestamp
);
event StreamCanceled(uint256 indexed nounId, uint256 amountToRefund);
event StreamFastForwarded(uint256 indexed nounId, uint256 ticksToForward, uint256 newLastTick);
event StreamCanceled(uint256 indexed nounId, uint256 amountToRefund, uint128 ethStreamedPerTick);
event StreamFastForwarded(
uint256 indexed nounId,
uint256 ticksToForward,
uint256 newLastTick,
uint128 ethStreamedPerTick
);
event AllowedToCreateStreamChanged(address address_, bool allowed);
event DAOExecutorAddressSet(address newAddress);
event ETHRecipientSet(address newAddress);
Expand Down
Loading

0 comments on commit 7949033

Please sign in to comment.