Skip to content

Commit

Permalink
subgraph: update stream escrow ABI and set stream start tick
Browse files Browse the repository at this point in the history
  • Loading branch information
eladmallel committed Nov 20, 2024
1 parent 79bb07f commit 47394bd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
16 changes: 14 additions & 2 deletions packages/nouns-contracts/abi/contracts/StreamEscrow.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,13 @@
"name": "StreamCanceled",
"inputs": [
{ "name": "nounId", "type": "uint256", "indexed": true, "internalType": "uint256" },
{ "name": "amountToRefund", "type": "uint256", "indexed": false, "internalType": "uint256" }
{ "name": "amountToRefund", "type": "uint256", "indexed": false, "internalType": "uint256" },
{
"name": "ethStreamedPerTick",
"type": "uint128",
"indexed": false,
"internalType": "uint128"
}
],
"anonymous": false
},
Expand Down Expand Up @@ -278,7 +284,13 @@
"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": "newLastTick", "type": "uint256", "indexed": false, "internalType": "uint256" },
{
"name": "ethStreamedPerTick",
"type": "uint128",
"indexed": false,
"internalType": "uint128"
}
],
"anonymous": false
},
Expand Down
1 change: 1 addition & 0 deletions packages/nouns-subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ type Stream @entity {

createdTimestamp: BigInt!
createdBlock: BigInt!
startTick: BigInt!

noun: Noun!

Expand Down
1 change: 1 addition & 0 deletions packages/nouns-subgraph/src/stream-escrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function handleStreamCreated(event: StreamCreated): void {
const s = new Stream(streamId);
s.createdTimestamp = event.block.timestamp;
s.createdBlock = event.block.number;
s.startTick = getStreamEscrowState().currentTick;
s.noun = nounId;
s.totalAmount = event.params.totalAmount;
s.streamLengthInTicks = event.params.streamLengthInTicks;
Expand Down
4 changes: 2 additions & 2 deletions packages/nouns-subgraph/subgraph.yaml.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ dataSources:
handler: handleETHStreamedToDAO
- event: StreamCreated(indexed uint256,uint256,uint16,uint256,uint128,uint32)
handler: handleStreamCreated
- event: StreamFastForwarded(indexed uint256,uint256,uint256)
- event: StreamFastForwarded(indexed uint256,uint256,uint256,uint128)
handler: handleStreamFastForwarded
- event: StreamCanceled(indexed uint256,uint256)
- event: StreamCanceled(indexed uint256,uint256,uint128)
handler: handleStreamCanceled
- event: StreamsForwarded(uint256,uint256,uint256,uint256)
handler: handleStreamsForwarded
Expand Down
14 changes: 12 additions & 2 deletions packages/nouns-subgraph/tests/stream-escrow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ describe('stream-escrow', () => {
});
describe('stream lifecycle', () => {
test('create a couple of streams', () => {
let es = getStreamEscrowState();
es.currentTick = BigInt.fromI32(1);
es.save();

const ed = new StreamCreatedData();
ed.nounId = BigInt.fromI32(142);
ed.totalAmount = BigInt.fromI32(420);
Expand All @@ -137,6 +141,7 @@ describe('stream-escrow', () => {

assert.fieldEquals('Stream', streamId, 'createdTimestamp', ed.eventBlockTimestamp.toString());
assert.fieldEquals('Stream', streamId, 'createdBlock', ed.eventBlockNumber.toString());
assert.fieldEquals('Stream', streamId, 'startTick', es.currentTick.toString());
assert.fieldEquals('Stream', streamId, 'noun', ed.nounId.toString());
assert.fieldEquals('Stream', streamId, 'totalAmount', ed.totalAmount.toString());
assert.fieldEquals(
Expand All @@ -155,12 +160,16 @@ describe('stream-escrow', () => {

const prevStreamPerTick = ed.newEthStreamedPerTick;

es = getStreamEscrowState();
es.currentTick = BigInt.fromI32(2);
es.save();

ed.nounId = BigInt.fromI32(2142);
ed.totalAmount = BigInt.fromI32(2420);
ed.streamLengthInTicks = BigInt.fromI32(10);
ed.ethPerTick = BigInt.fromI32(242);
ed.newEthStreamedPerTick = prevStreamPerTick.plus(ed.ethPerTick);
ed.lastTick = BigInt.fromI32(10);
ed.lastTick = BigInt.fromI32(12);
ed.eventBlockNumber = BIGINT_ONE;
ed.eventBlockTimestamp = BIGINT_ONE;
handleStreamCreated(createStreamCreatedEvent(ed));
Expand All @@ -169,6 +178,7 @@ describe('stream-escrow', () => {

assert.fieldEquals('Stream', streamId, 'createdTimestamp', ed.eventBlockTimestamp.toString());
assert.fieldEquals('Stream', streamId, 'createdBlock', ed.eventBlockNumber.toString());
assert.fieldEquals('Stream', streamId, 'startTick', es.currentTick.toString());
assert.fieldEquals('Stream', streamId, 'noun', ed.nounId.toString());
assert.fieldEquals('Stream', streamId, 'totalAmount', ed.totalAmount.toString());
assert.fieldEquals(
Expand All @@ -195,7 +205,7 @@ describe('stream-escrow', () => {
let streamId = StreamsOfNoun.load(nounId)!.currentStream!;

// Stream state BEFORE
assert.fieldEquals('Stream', streamId, 'lastTick', BigInt.fromI32(10).toString());
assert.fieldEquals('Stream', streamId, 'lastTick', BigInt.fromI32(12).toString());
assert.fieldEquals('Stream', streamId, 'streamLengthInTicks', BigInt.fromI32(10).toString());

// handle the event
Expand Down

0 comments on commit 47394bd

Please sign in to comment.