diff --git a/subgraph/.prettierrc.js b/subgraph/.prettierrc.js index 15dafbe4b..6d44c572e 100644 --- a/subgraph/.prettierrc.js +++ b/subgraph/.prettierrc.js @@ -1,3 +1,3 @@ module.exports = { - ...require("../.prettierrc.js"), + ...require("../.prettierrc.js"), } diff --git a/subgraph/README.md b/subgraph/README.md index bf6e72f27..09a2ce5ed 100644 --- a/subgraph/README.md +++ b/subgraph/README.md @@ -38,7 +38,8 @@ EVM-compatible JSON-RPC API. You can use Thesis private RPC from Alchemy or create a private one [here](https://www.alchemy.com/overviews/private-rpc-endpoint). -1. Install Docker on your local machine: +1. Install Docker on your local machine: + - Mac: https://docs.docker.com/desktop/install/mac-install/ - Windows: https://docs.docker.com/desktop/install/windows-install/ - Linux: https://docs.docker.com/desktop/install/linux-install/ @@ -74,3 +75,30 @@ Note: use it only if your subgraph is not created in the local Graph node. ``` http://localhost:8000/subgraphs/name/acre-subgraph ``` + +### Deploy the subgraph to Subgraph Studio + +1. Once your subgraph has been created in Subgraph Studio you can initialize the subgraph code using this command: + + ``` + graph init --studio + ``` + + The value can be found on your subgraph details page in Subgraph Studio + (https://thegraph.com/docs/en/deploying/deploying-a-subgraph-to-studio/#create-your-subgraph-in-subgraph-studio) + +2. Before being able to deploy your subgraph to Subgraph Studio, you need to login into your account within the CLI. + + ``` + graph auth --studio + ``` + + The can be found on your "My Subgraphs" page or your subgraph details page. + +3. Deploying a Subgraph to Subgraph Studio + + ``` + graph deploy --studio + ``` + + After running this command, the CLI will ask for a version label, you can name it however you want, you can use labels such as 0.1 and 0.2 or use letters as well such as uniswap-v2-0.1. diff --git a/subgraph/abis/AcreBitcoinDepositor.json b/subgraph/abis/AcreBitcoinDepositor.json deleted file mode 100644 index 41a640c8f..000000000 --- a/subgraph/abis/AcreBitcoinDepositor.json +++ /dev/null @@ -1,33 +0,0 @@ -[ - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "depositKey", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "caller", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "depositOwner", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "initialAmount", - "type": "uint256" - } - ], - "name": "DepositInitialized", - "type": "event" - } -] diff --git a/subgraph/abis/BitcoinDepositor.json b/subgraph/abis/BitcoinDepositor.json new file mode 100644 index 000000000..3c4462015 --- /dev/null +++ b/subgraph/abis/BitcoinDepositor.json @@ -0,0 +1,82 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "depositKey", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "depositOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint16", + "name": "referral", + "type": "uint16" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "initialAmount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "bridgedAmount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "depositorFee", + "type": "uint256" + } + ], + "name": "DepositFinalized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "uint256", + "name": "depositKey", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "caller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "depositOwner", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "initialAmount", + "type": "uint256" + } + ], + "name": "DepositInitialized", + "type": "event" + } +] diff --git a/subgraph/networks.json b/subgraph/networks.json index 04789726a..3f3a9403c 100644 --- a/subgraph/networks.json +++ b/subgraph/networks.json @@ -1,6 +1,6 @@ { "sepolia": { - "AcreBitcoinDepositor": { + "BitcoinDepositor": { "address": "0x37E34EbC743FFAf96b56b3f62854bb7E733a4B50", "startBlock": 5394071 } diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index a2395d769..ee6e77851 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -4,11 +4,9 @@ enum ChainType { } enum LogType { + Unknown Initialized Finalized - Queued - FinalizedFromQueue - CancelledFromQueue } interface ActivityData @key(fields: "id") { @@ -23,21 +21,21 @@ type DepositOwner @entity { activities: [ActivityData!] @derivedFrom(field: "depositOwner") } -type Stake implements ActivityData @entity{ +type Deposit implements ActivityData @entity { id: ID! depositOwner: DepositOwner! logs: [LogData!] @derivedFrom(field: "activity") initialDepositAmountSatoshi: BigInt! - amountToStakeStBtc: BigInt + amountToDepositStBtc: BigInt shareStBtc: BigInt } -type Unstake implements ActivityData @entity{ +type Withdraw implements ActivityData @entity { id: ID! depositOwner: DepositOwner! logs: [LogData!] @derivedFrom(field: "activity") initialDepositAmountSatoshi: BigInt! - amountToStakeStBtc: BigInt + amountToDepositStBtc: BigInt shareStBtc: BigInt } diff --git a/subgraph/src/acre-bitcoin-depositor.ts b/subgraph/src/acre-bitcoin-depositor.ts deleted file mode 100644 index f3140e5d9..000000000 --- a/subgraph/src/acre-bitcoin-depositor.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { DepositInitialized as DepositInitializedEvent } from "../generated/AcreBitcoinDepositor/AcreBitcoinDepositor" -import { - getOrCreateDepositOwner, - getOrCreateStake, - getOrCreateLog, -} from "./utils" - -// eslint-disable-next-line import/prefer-default-export -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`, - ) - const logDataEth = getOrCreateLog( - `${event.transaction.hash.toHexString()}eth`, - ) - - logDataBtc.activity = stakeEntity.id - - // This timestamp may be different than the actual time - // when the BTC transaction took place: - // It indicates when Ethereum received event about this BTC deposit, - // not when the BTC transaction happened. - logDataBtc.timestamp = event.block.timestamp - logDataBtc.chain = "Bitcoin" - logDataBtc.amount = event.params.initialAmount - - logDataEth.activity = stakeEntity.id - logDataEth.timestamp = event.block.timestamp - logDataEth.chain = "Ethereum" - logDataEth.amount = event.params.initialAmount - - depositOwnerEntity.save() - stakeEntity.save() - logDataBtc.save() - logDataEth.save() -} diff --git a/subgraph/src/bitcoin-depositor.ts b/subgraph/src/bitcoin-depositor.ts new file mode 100644 index 000000000..0616be07a --- /dev/null +++ b/subgraph/src/bitcoin-depositor.ts @@ -0,0 +1,85 @@ +import { + DepositInitialized as DepositInitializedEvent, + DepositFinalized as DepositFinalizedEvent, +} from "../generated/BitcoinDepositor/BitcoinDepositor" +import { + getOrCreateDepositOwner, + getOrCreateDeposit, + getOrCreateLog, +} from "./utils" + +// eslint-disable-next-line import/prefer-default-export +export function handleDepositInitialized(event: DepositInitializedEvent): void { + const depositOwnerEntity = getOrCreateDepositOwner(event.params.depositOwner) + const depositEntity = getOrCreateDeposit( + event.params.depositKey.toHexString(), + ) + + depositEntity.depositOwner = depositOwnerEntity.id + depositEntity.initialDepositAmountSatoshi = event.params.initialAmount + + const logDataBtc = getOrCreateLog( + `${event.transaction.hash.toHexString()}btc`, + ) + const logDataEth = getOrCreateLog( + `${event.transaction.hash.toHexString()}eth`, + ) + + logDataBtc.activity = depositEntity.id + + // This timestamp may be different than the actual time + // when the BTC transaction took place: + // It indicates when Ethereum received event about this BTC deposit, + // not when the BTC transaction happened. + logDataBtc.timestamp = event.block.timestamp + logDataBtc.chain = "Bitcoin" + logDataBtc.amount = event.params.initialAmount + + logDataEth.activity = depositEntity.id + logDataEth.timestamp = event.block.timestamp + logDataEth.chain = "Ethereum" + logDataEth.amount = event.params.initialAmount + + depositOwnerEntity.save() + depositEntity.save() + logDataBtc.save() + logDataEth.save() +} + +export function handleDepositFinalized(event: DepositFinalizedEvent): void { + const depositOwnerEntity = getOrCreateDepositOwner(event.params.depositOwner) + const depositEntity = getOrCreateDeposit( + event.params.depositKey.toHexString(), + ) + + depositEntity.depositOwner = depositOwnerEntity.id + depositEntity.initialDepositAmountSatoshi = event.params.initialAmount + depositEntity.amountToDepositStBtc = event.params.bridgedAmount + + const logDataBtc = getOrCreateLog( + `${event.transaction.hash.toHexString()}btc`, + ) + const logDataEth = getOrCreateLog( + `${event.transaction.hash.toHexString()}eth`, + ) + + logDataBtc.activity = depositEntity.id + + // This timestamp may be different than the actual time + // when the BTC transaction took place: + // It indicates when Ethereum received event about this BTC deposit, + // not when the BTC transaction happened. + logDataBtc.timestamp = event.block.timestamp + logDataBtc.chain = "Bitcoin" + logDataBtc.amount = event.params.initialAmount + + logDataEth.activity = depositEntity.id + logDataEth.timestamp = event.block.timestamp + logDataEth.chain = "Ethereum" + logDataEth.amount = event.params.initialAmount + + depositOwnerEntity.save() + depositEntity.save() + logDataBtc.save() + logDataEth.save() +} diff --git a/subgraph/src/utils.ts b/subgraph/src/utils.ts index 299e93b0b..5d4c786fb 100644 --- a/subgraph/src/utils.ts +++ b/subgraph/src/utils.ts @@ -1,5 +1,5 @@ import { Address } from "@graphprotocol/graph-ts" -import { DepositOwner, LogData, Stake } from "../generated/schema" +import { DepositOwner, LogData, Deposit } from "../generated/schema" export function getOrCreateDepositOwner(depositOwnerId: Address): DepositOwner { const depositOwnerHexString = depositOwnerId.toHexString() @@ -12,15 +12,14 @@ export function getOrCreateDepositOwner(depositOwnerId: Address): DepositOwner { return depositOwner } -export function getOrCreateStake(transactionId: string): Stake { - // const stakeHexString = transactionHash.toHexString() - let stake = Stake.load(transactionId) +export function getOrCreateDeposit(transactionId: string): Deposit { + let deposit = Deposit.load(transactionId) - if (!stake) { - stake = new Stake(transactionId) + if (!deposit) { + deposit = new Deposit(transactionId) } - return stake + return deposit } export function getOrCreateLog(logId: string): LogData { diff --git a/subgraph/subgraph.yaml b/subgraph/subgraph.yaml index 1bf2b1c05..fbde95930 100644 --- a/subgraph/subgraph.yaml +++ b/subgraph/subgraph.yaml @@ -5,11 +5,11 @@ schema: file: ./schema.graphql dataSources: - kind: ethereum - name: AcreBitcoinDepositor + name: BitcoinDepositor network: sepolia source: address: "0x2F86FE8C5683372Db667E6f6d88dcB6d55a81286" - abi: AcreBitcoinDepositor + abi: BitcoinDepositor startBlock: 5675744 mapping: kind: ethereum/events @@ -17,14 +17,16 @@ dataSources: language: wasm/assemblyscript entities: - DepositOwner - - Stake - - Unstake + - Deposit + - Withdraw - LogData abis: - - name: AcreBitcoinDepositor - file: ./abis/AcreBitcoinDepositor.json + - name: BitcoinDepositor + file: ./abis/BitcoinDepositor.json eventHandlers: - event: DepositInitialized(indexed uint256,indexed address,indexed address,uint256) handler: handleDepositInitialized receipt: true - file: ./src/acre-bitcoin-depositor.ts + - event: DepositFinalized(indexed uint256,indexed address,indexed address,indexed uint16,uint256,uint256,uint256) + handler: handleDepositFinalized + file: ./src/bitcoin-depositor.ts diff --git a/subgraph/tests/acre-bitcoin-depositor-utils.ts b/subgraph/tests/acre-bitcoin-depositor-utils.ts deleted file mode 100644 index 7143e8c95..000000000 --- a/subgraph/tests/acre-bitcoin-depositor-utils.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { ethereum, BigInt, Address } from "@graphprotocol/graph-ts" -import { newMockEvent } from "matchstick-as/assembly/defaults" -import { DepositInitialized } from "../generated/AcreBitcoinDepositor/AcreBitcoinDepositor" - -// eslint-disable-next-line import/prefer-default-export -export function createDepositInitializedEvent( - depositKey: BigInt, - caller: Address, - depositOwner: Address, - initialAmount: BigInt, -): DepositInitialized { - const depositInitializedEvent = changetype(newMockEvent()) - - depositInitializedEvent.parameters = [] - - const depositKeyParam = new ethereum.EventParam( - "depositKey", - ethereum.Value.fromUnsignedBigInt(depositKey), - ) - const callerParam = new ethereum.EventParam( - "caller", - ethereum.Value.fromAddress(caller), - ) - - const depositOwnerParam = new ethereum.EventParam( - "depositOwner", - ethereum.Value.fromAddress(depositOwner), - ) - - const initialAmountParam = new ethereum.EventParam( - "initialAmount", - ethereum.Value.fromUnsignedBigInt(initialAmount), - ) - - depositInitializedEvent.parameters.push(depositKeyParam) - depositInitializedEvent.parameters.push(callerParam) - depositInitializedEvent.parameters.push(depositOwnerParam) - depositInitializedEvent.parameters.push(initialAmountParam) - - return depositInitializedEvent -} diff --git a/subgraph/tests/acre-bitcoin-depositor.test.ts b/subgraph/tests/acre-bitcoin-depositor.test.ts deleted file mode 100644 index 4f1248ea1..000000000 --- a/subgraph/tests/acre-bitcoin-depositor.test.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { - assert, - describe, - test, - clearStore, - afterEach, - beforeEach, -} from "matchstick-as/assembly/index" -import { BigInt, Address } from "@graphprotocol/graph-ts" -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 depositOwner = Address.fromString( - "0x0000000000000000000000000000000000000001", -) -const initialAmount = BigInt.fromI32(234) - -const event = createDepositInitializedEvent( - depositKey, - caller, - depositOwner, - initialAmount, -) - -describe("createStakeRequestInitialized event", () => { - beforeEach(() => { - handleDepositInitialized(event) - }) - - afterEach(() => { - clearStore() - }) - - 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, - "timestamp", - event.block.timestamp.toString(), - ) - - assert.fieldEquals( - "LogData", - txEthId, - "timestamp", - event.block.timestamp.toString(), - ) - - assert.fieldEquals("LogData", txBtcId, "chain", "Bitcoin") - assert.fieldEquals("LogData", txEthId, "chain", "Ethereum") - - assert.fieldEquals("LogData", txBtcId, "amount", initialAmount.toString()) - assert.fieldEquals("LogData", txEthId, "amount", initialAmount.toString()) - }) -}) diff --git a/subgraph/tests/bitcoin-depositor-utils.ts b/subgraph/tests/bitcoin-depositor-utils.ts new file mode 100644 index 000000000..aba46e8fb --- /dev/null +++ b/subgraph/tests/bitcoin-depositor-utils.ts @@ -0,0 +1,101 @@ +import { ethereum, BigInt, Address } from "@graphprotocol/graph-ts" +import { newMockEvent } from "matchstick-as/assembly/defaults" +import { + DepositInitialized, + DepositFinalized, +} from "../generated/BitcoinDepositor/BitcoinDepositor" + +export function createDepositInitializedEvent( + depositKey: BigInt, + caller: Address, + depositOwner: Address, + initialAmount: BigInt, +): DepositInitialized { + const depositInitializedEvent = changetype(newMockEvent()) + + depositInitializedEvent.parameters = [] + + const depositKeyParam = new ethereum.EventParam( + "depositKey", + ethereum.Value.fromUnsignedBigInt(depositKey), + ) + const callerParam = new ethereum.EventParam( + "caller", + ethereum.Value.fromAddress(caller), + ) + + const depositOwnerParam = new ethereum.EventParam( + "depositOwner", + ethereum.Value.fromAddress(depositOwner), + ) + + const initialAmountParam = new ethereum.EventParam( + "initialAmount", + ethereum.Value.fromUnsignedBigInt(initialAmount), + ) + + depositInitializedEvent.parameters.push(depositKeyParam) + depositInitializedEvent.parameters.push(callerParam) + depositInitializedEvent.parameters.push(depositOwnerParam) + depositInitializedEvent.parameters.push(initialAmountParam) + + return depositInitializedEvent +} + +export function createDepositFinalizedEvent( + depositKey: BigInt, + caller: Address, + depositOwner: Address, + referral: BigInt, + initialAmount: BigInt, + bridgedAmount: BigInt, + depositorFee: BigInt, +): DepositFinalized { + const depositFinalizedEvent = changetype(newMockEvent()) + + depositFinalizedEvent.parameters = [] + + const depositKeyParam = new ethereum.EventParam( + "depositKey", + ethereum.Value.fromUnsignedBigInt(depositKey), + ) + const callerParam = new ethereum.EventParam( + "caller", + ethereum.Value.fromAddress(caller), + ) + + const depositOwnerParam = new ethereum.EventParam( + "depositOwner", + ethereum.Value.fromAddress(depositOwner), + ) + + const referralParam = new ethereum.EventParam( + "referral", + ethereum.Value.fromUnsignedBigInt(referral), + ) + + const initialAmountParam = new ethereum.EventParam( + "initialAmount", + ethereum.Value.fromUnsignedBigInt(initialAmount), + ) + + const bridgedAmountParam = new ethereum.EventParam( + "bridgedAmount", + ethereum.Value.fromUnsignedBigInt(bridgedAmount), + ) + + const depositorFeeParam = new ethereum.EventParam( + "depositorFee", + ethereum.Value.fromUnsignedBigInt(depositorFee), + ) + + depositFinalizedEvent.parameters.push(depositKeyParam) + depositFinalizedEvent.parameters.push(callerParam) + depositFinalizedEvent.parameters.push(depositOwnerParam) + depositFinalizedEvent.parameters.push(referralParam) + depositFinalizedEvent.parameters.push(initialAmountParam) + depositFinalizedEvent.parameters.push(bridgedAmountParam) + depositFinalizedEvent.parameters.push(depositorFeeParam) + + return depositFinalizedEvent +} diff --git a/subgraph/tests/bitcoin-depositor.test.ts b/subgraph/tests/bitcoin-depositor.test.ts new file mode 100644 index 000000000..57450af2b --- /dev/null +++ b/subgraph/tests/bitcoin-depositor.test.ts @@ -0,0 +1,205 @@ +import { + assert, + describe, + test, + clearStore, + afterEach, + beforeEach, +} from "matchstick-as/assembly/index" +import { BigInt, Address } from "@graphprotocol/graph-ts" +import { + createDepositInitializedEvent, + createDepositFinalizedEvent, +} from "./bitcoin-depositor-utils" +import { + handleDepositFinalized, + handleDepositInitialized, +} from "../src/bitcoin-depositor" + +const depositKey = BigInt.fromI32(234) +const caller = Address.fromString("0x0000000000000000000000000000000000000001") +const depositOwner = Address.fromString( + "0x0000000000000000000000000000000000000001", +) +const referral = BigInt.fromI32(234) +const initialAmount = BigInt.fromI32(234) +const bridgedAmount = BigInt.fromI32(234) +const depositorFee = BigInt.fromI32(234) + +const depositInitializedEvent = createDepositInitializedEvent( + depositKey, + caller, + depositOwner, + initialAmount, +) + +const depositFinalizedEvent = createDepositFinalizedEvent( + depositKey, + caller, + depositOwner, + referral, + initialAmount, + bridgedAmount, + depositorFee, +) + +describe("createDepositInitializedEvent event", () => { + beforeEach(() => { + handleDepositInitialized(depositInitializedEvent) + }) + + afterEach(() => { + clearStore() + }) + + test("should create DepositOwner entity", () => { + assert.entityCount("DepositOwner", 1) + }) + + test("should create Deposit entity", () => { + assert.entityCount("Deposit", 1) + }) + + test("should create LogData entities", () => { + assert.entityCount("LogData", 2) + }) + + test("Deposit entity has proper fields", () => { + assert.fieldEquals( + "Deposit", + depositInitializedEvent.params.depositKey.toHexString(), + "depositOwner", + depositOwner.toHexString(), + ) + + assert.fieldEquals( + "Deposit", + depositInitializedEvent.params.depositKey.toHexString(), + "depositOwner", + depositOwner.toHexString(), + ) + + assert.fieldEquals( + "Deposit", + depositInitializedEvent.params.depositKey.toHexString(), + "initialDepositAmountSatoshi", + depositInitializedEvent.params.initialAmount.toString(), + ) + }) + + test("LogData entity has proper fields", () => { + const txBtcId = `${depositInitializedEvent.transaction.hash.toHexString()}btc` + const txEthId = `${depositInitializedEvent.transaction.hash.toHexString()}eth` + + assert.fieldEquals( + "LogData", + txBtcId, + "activity", + depositInitializedEvent.params.depositKey.toHexString(), + ) + + assert.fieldEquals( + "LogData", + txEthId, + "activity", + depositInitializedEvent.params.depositKey.toHexString(), + ) + + assert.fieldEquals( + "LogData", + txBtcId, + "timestamp", + depositInitializedEvent.block.timestamp.toString(), + ) + + assert.fieldEquals( + "LogData", + txEthId, + "timestamp", + depositInitializedEvent.block.timestamp.toString(), + ) + + assert.fieldEquals("LogData", txBtcId, "chain", "Bitcoin") + assert.fieldEquals("LogData", txEthId, "chain", "Ethereum") + + assert.fieldEquals("LogData", txBtcId, "amount", initialAmount.toString()) + assert.fieldEquals("LogData", txEthId, "amount", initialAmount.toString()) + }) +}) + +describe("createDepositFinalizedEvent event", () => { + beforeEach(() => { + handleDepositFinalized(depositFinalizedEvent) + }) + + afterEach(() => { + clearStore() + }) + + test("should create DepositOwner entity", () => { + assert.entityCount("DepositOwner", 1) + }) + + test("should create Deposit entity", () => { + assert.entityCount("Deposit", 1) + }) + + test("should create LogData entities", () => { + assert.entityCount("LogData", 2) + }) + + test("Deposit entity has proper fields", () => { + assert.fieldEquals( + "Deposit", + depositFinalizedEvent.params.depositKey.toHexString(), + "depositOwner", + depositOwner.toHexString(), + ) + + assert.fieldEquals( + "Deposit", + depositFinalizedEvent.params.depositKey.toHexString(), + "initialDepositAmountSatoshi", + depositFinalizedEvent.params.initialAmount.toString(), + ) + }) + + test("LogData entity has proper fields", () => { + const txBtcId = `${depositFinalizedEvent.transaction.hash.toHexString()}btc` + const txEthId = `${depositFinalizedEvent.transaction.hash.toHexString()}eth` + + assert.fieldEquals( + "LogData", + txBtcId, + "activity", + depositFinalizedEvent.params.depositKey.toHexString(), + ) + + assert.fieldEquals( + "LogData", + txEthId, + "activity", + depositFinalizedEvent.params.depositKey.toHexString(), + ) + + assert.fieldEquals( + "LogData", + txBtcId, + "timestamp", + depositFinalizedEvent.block.timestamp.toString(), + ) + + assert.fieldEquals( + "LogData", + txEthId, + "timestamp", + depositFinalizedEvent.block.timestamp.toString(), + ) + + assert.fieldEquals("LogData", txBtcId, "chain", "Bitcoin") + assert.fieldEquals("LogData", txEthId, "chain", "Ethereum") + + assert.fieldEquals("LogData", txBtcId, "amount", initialAmount.toString()) + assert.fieldEquals("LogData", txEthId, "amount", initialAmount.toString()) + }) +})