diff --git a/subgraph/abis/AcreBitcoinDepositor.json b/subgraph/abis/AcreBitcoinDepositor.json index df4025ed4..41a640c8f 100644 --- a/subgraph/abis/AcreBitcoinDepositor.json +++ b/subgraph/abis/AcreBitcoinDepositor.json @@ -17,7 +17,7 @@ { "indexed": true, "internalType": "address", - "name": "staker", + "name": "depositOwner", "type": "address" }, { @@ -27,7 +27,7 @@ "type": "uint256" } ], - "name": "StakeRequestInitialized", + "name": "DepositInitialized", "type": "event" } ] diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index 63df972c4..a2395d769 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -13,36 +13,36 @@ enum LogType { interface ActivityData @key(fields: "id") { id: ID! - staker: Staker! + depositOwner: DepositOwner! logs: [LogData!] } -type Staker @entity { +type DepositOwner @entity { # Id is the ethereum address of the account. id: ID! - activities: [ActivityData!] @derivedFrom(field: "staker") + activities: [ActivityData!] @derivedFrom(field: "depositOwner") } type Stake implements ActivityData @entity{ id: ID! - staker: Staker! + depositOwner: DepositOwner! logs: [LogData!] @derivedFrom(field: "activity") initialDepositAmountSatoshi: BigInt! - amountToStakeStBtc: BigInt! - shareStBtc: BigInt! + amountToStakeStBtc: BigInt + shareStBtc: BigInt } type Unstake implements ActivityData @entity{ id: ID! - staker: Staker! + depositOwner: DepositOwner! logs: [LogData!] @derivedFrom(field: "activity") initialDepositAmountSatoshi: BigInt! - amountToStakeStBtc: BigInt! - shareStBtc: BigInt! + amountToStakeStBtc: BigInt + shareStBtc: BigInt } type LogData @entity { - # Id is the transaction hash + # Id is the transaction hash. id: ID! timestamp: BigInt! activity: ActivityData diff --git a/subgraph/src/acre-bitcoin-depositor.ts b/subgraph/src/acre-bitcoin-depositor.ts index bcfe97ae3..f3140e5d9 100644 --- a/subgraph/src/acre-bitcoin-depositor.ts +++ b/subgraph/src/acre-bitcoin-depositor.ts @@ -1,13 +1,18 @@ -import { StakeRequestInitialized as StakeRequestInitializedEvent } from "../generated/AcreBitcoinDepositor/AcreBitcoinDepositor" -import { getOrCreateStaker, getOrCreateStake, getOrCreateLog } from "./utils" +import { DepositInitialized as DepositInitializedEvent } from "../generated/AcreBitcoinDepositor/AcreBitcoinDepositor" +import { + getOrCreateDepositOwner, + getOrCreateStake, + getOrCreateLog, +} from "./utils" // eslint-disable-next-line import/prefer-default-export -export function handleStakeRequestInitialized( - event: StakeRequestInitializedEvent, -): void { - const stakerEntity = getOrCreateStaker(event.params.staker) +export function handleDepositInitialized(event: DepositInitializedEvent): void { + const depositOwnerEntity = getOrCreateDepositOwner(event.params.depositOwner) const stakeEntity = getOrCreateStake(event.transaction.hash.toHexString()) + stakeEntity.depositOwner = depositOwnerEntity.id + stakeEntity.initialDepositAmountSatoshi = event.params.initialAmount + const logDataBtc = getOrCreateLog( `${event.transaction.hash.toHexString()}btc`, ) @@ -30,8 +35,8 @@ export function handleStakeRequestInitialized( logDataEth.chain = "Ethereum" logDataEth.amount = event.params.initialAmount - stakerEntity.save() - // stakeEntity.save() + depositOwnerEntity.save() + stakeEntity.save() logDataBtc.save() logDataEth.save() } diff --git a/subgraph/src/utils.ts b/subgraph/src/utils.ts index c2440e666..299e93b0b 100644 --- a/subgraph/src/utils.ts +++ b/subgraph/src/utils.ts @@ -1,15 +1,15 @@ import { Address } from "@graphprotocol/graph-ts" -import { Staker, LogData, Stake } from "../generated/schema" +import { DepositOwner, LogData, Stake } from "../generated/schema" -export function getOrCreateStaker(stakerId: Address): Staker { - const stakerHexString = stakerId.toHexString() - let staker = Staker.load(stakerHexString) +export function getOrCreateDepositOwner(depositOwnerId: Address): DepositOwner { + const depositOwnerHexString = depositOwnerId.toHexString() + let depositOwner = DepositOwner.load(depositOwnerHexString) - if (!staker) { - staker = new Staker(stakerHexString) + if (!depositOwner) { + depositOwner = new DepositOwner(depositOwnerHexString) } - return staker + return depositOwner } export function getOrCreateStake(transactionId: string): Stake { diff --git a/subgraph/subgraph.yaml b/subgraph/subgraph.yaml index 40a0e9eb1..1bf2b1c05 100644 --- a/subgraph/subgraph.yaml +++ b/subgraph/subgraph.yaml @@ -8,20 +8,23 @@ dataSources: name: AcreBitcoinDepositor network: sepolia source: - address: "0x37E34EbC743FFAf96b56b3f62854bb7E733a4B50" + address: "0x2F86FE8C5683372Db667E6f6d88dcB6d55a81286" abi: AcreBitcoinDepositor - startBlock: 5394071 + startBlock: 5675744 mapping: kind: ethereum/events apiVersion: 0.0.7 language: wasm/assemblyscript entities: - - StakeRequestInitialized + - DepositOwner + - Stake + - Unstake + - LogData abis: - name: AcreBitcoinDepositor file: ./abis/AcreBitcoinDepositor.json eventHandlers: - - event: StakeRequestInitialized(indexed uint256,indexed address,indexed address,uint256) - handler: handleStakeRequestInitialized + - event: DepositInitialized(indexed uint256,indexed address,indexed address,uint256) + handler: handleDepositInitialized receipt: true file: ./src/acre-bitcoin-depositor.ts diff --git a/subgraph/tests/acre-bitcoin-depositor-utils.ts b/subgraph/tests/acre-bitcoin-depositor-utils.ts index b0b027998..7143e8c95 100644 --- a/subgraph/tests/acre-bitcoin-depositor-utils.ts +++ b/subgraph/tests/acre-bitcoin-depositor-utils.ts @@ -1,18 +1,17 @@ import { ethereum, BigInt, Address } from "@graphprotocol/graph-ts" import { newMockEvent } from "matchstick-as/assembly/defaults" -import { StakeRequestInitialized } from "../generated/AcreBitcoinDepositor/AcreBitcoinDepositor" +import { DepositInitialized } from "../generated/AcreBitcoinDepositor/AcreBitcoinDepositor" // eslint-disable-next-line import/prefer-default-export -export function createStakeRequestInitializedEvent( +export function createDepositInitializedEvent( depositKey: BigInt, caller: Address, - staker: Address, + depositOwner: Address, initialAmount: BigInt, -): StakeRequestInitialized { - const stakeRequestInitializedEvent = - changetype(newMockEvent()) +): DepositInitialized { + const depositInitializedEvent = changetype(newMockEvent()) - stakeRequestInitializedEvent.parameters = [] + depositInitializedEvent.parameters = [] const depositKeyParam = new ethereum.EventParam( "depositKey", @@ -23,9 +22,9 @@ export function createStakeRequestInitializedEvent( ethereum.Value.fromAddress(caller), ) - const stakerParam = new ethereum.EventParam( - "staker", - ethereum.Value.fromAddress(staker), + const depositOwnerParam = new ethereum.EventParam( + "depositOwner", + ethereum.Value.fromAddress(depositOwner), ) const initialAmountParam = new ethereum.EventParam( @@ -33,10 +32,10 @@ export function createStakeRequestInitializedEvent( ethereum.Value.fromUnsignedBigInt(initialAmount), ) - stakeRequestInitializedEvent.parameters.push(depositKeyParam) - stakeRequestInitializedEvent.parameters.push(callerParam) - stakeRequestInitializedEvent.parameters.push(stakerParam) - stakeRequestInitializedEvent.parameters.push(initialAmountParam) + depositInitializedEvent.parameters.push(depositKeyParam) + depositInitializedEvent.parameters.push(callerParam) + depositInitializedEvent.parameters.push(depositOwnerParam) + depositInitializedEvent.parameters.push(initialAmountParam) - return stakeRequestInitializedEvent + return depositInitializedEvent } diff --git a/subgraph/tests/acre-bitcoin-depositor.test.ts b/subgraph/tests/acre-bitcoin-depositor.test.ts index 9b3938d4b..1de5dd772 100644 --- a/subgraph/tests/acre-bitcoin-depositor.test.ts +++ b/subgraph/tests/acre-bitcoin-depositor.test.ts @@ -7,42 +7,78 @@ import { beforeEach, } from "matchstick-as/assembly/index" import { BigInt, Address } from "@graphprotocol/graph-ts" -import { createStakeRequestInitializedEvent } from "./acre-bitcoin-depositor-utils" -import { handleStakeRequestInitialized } from "../src/acre-bitcoin-depositor" +import { createDepositInitializedEvent } from "./acre-bitcoin-depositor-utils" +import { handleDepositInitialized } from "../src/acre-bitcoin-depositor" const depositKey = BigInt.fromI32(234) const caller = Address.fromString("0x0000000000000000000000000000000000000001") -const staker = Address.fromString("0x0000000000000000000000000000000000000001") +const depositOwner = Address.fromString( + "0x0000000000000000000000000000000000000001", +) const initialAmount = BigInt.fromI32(234) -const event = createStakeRequestInitializedEvent( +const event = createDepositInitializedEvent( depositKey, caller, - staker, + depositOwner, initialAmount, ) describe("createStakeRequestInitialized event", () => { beforeEach(() => { - handleStakeRequestInitialized(event) + handleDepositInitialized(event) }) afterEach(() => { clearStore() }) - test("should create Staker entity", () => { - assert.entityCount("Staker", 1) + test("should create DepositOwner entity", () => { + assert.entityCount("DepositOwner", 1) + }) + + test("should create Stake entity", () => { + assert.entityCount("Stake", 1) }) test("should create LogData entities", () => { assert.entityCount("LogData", 2) }) + test("Stake entity has proper fields", () => { + assert.fieldEquals( + "Stake", + event.transaction.hash.toHexString(), + "depositOwner", + depositOwner.toHexString(), + ) + + assert.fieldEquals( + "Stake", + event.transaction.hash.toHexString(), + "initialDepositAmountSatoshi", + event.params.initialAmount.toString(), + ) + }) + test("LogData entity has proper fields", () => { const txBtcId = `${event.transaction.hash.toHexString()}btc` const txEthId = `${event.transaction.hash.toHexString()}eth` + assert.fieldEquals( + "LogData", + txBtcId, + "activity", + event.transaction.hash.toHexString(), + ) + + assert.fieldEquals( + "LogData", + txEthId, + "activity", + "event.transaction.hash.toHexString()", + ) + assert.fieldEquals( "LogData", txBtcId,