From 0d696937cac7e5cc2484d4a4571c3d1626f5436f Mon Sep 17 00:00:00 2001 From: Soil King <157099073+soilking@users.noreply.github.com> Date: Mon, 30 Sep 2024 16:58:04 -0700 Subject: [PATCH] handle contract pod migration --- .../manifests/arbitrum.yaml | 20 +++++++++++++++++++ .../legacy/ArbitrumMigrationHandler.ts | 11 ++++++++-- .../tests/Migration.test.ts | 9 +++++++++ .../tests/event-mocking/Migration.ts | 18 +++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/projects/subgraph-beanstalk/manifests/arbitrum.yaml b/projects/subgraph-beanstalk/manifests/arbitrum.yaml index 4d77aa8be..9d6ba9d27 100644 --- a/projects/subgraph-beanstalk/manifests/arbitrum.yaml +++ b/projects/subgraph-beanstalk/manifests/arbitrum.yaml @@ -36,6 +36,26 @@ dataSources: - event: InternalBalanceMigrated(indexed address,indexed address,int256) handler: handleInternalBalanceMigrated file: ../src/handlers/legacy/ArbitrumMigrationHandler.ts + - kind: ethereum/contract + name: ReseedContractMigration + network: arbitrum-one + source: + address: "0xD1A0060ba708BC4BCD3DA6C37EFa8deDF015FB70" + abi: Reseed + startBlock: 585858585858 # Reseed + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + entities: + - Plot + abis: + - name: Reseed + file: ../../subgraph-core/abis/Beanstalk/Beanstalk-BIP50.json + eventHandlers: + - event: L1PlotsMigrated(indexed address,indexed address,uint256[],uint256[]) + handler: handleL1PlotsMigrated + file: ../src/handlers/legacy/ArbitrumMigrationHandler.ts ### # INITIALIZATION ### diff --git a/projects/subgraph-beanstalk/src/handlers/legacy/ArbitrumMigrationHandler.ts b/projects/subgraph-beanstalk/src/handlers/legacy/ArbitrumMigrationHandler.ts index 276441b31..94de72d03 100644 --- a/projects/subgraph-beanstalk/src/handlers/legacy/ArbitrumMigrationHandler.ts +++ b/projects/subgraph-beanstalk/src/handlers/legacy/ArbitrumMigrationHandler.ts @@ -3,6 +3,7 @@ import { ZERO_BI } from "../../../../subgraph-core/utils/Decimals"; import { AddMigratedDeposit, InternalBalanceMigrated, + L1PlotsMigrated, MigratedAccountStatus, MigratedPlot, MigratedPodListing, @@ -32,12 +33,18 @@ export function handleMigratedAccountStatus(event: MigratedAccountStatus): void updateStalkBalances(event.address, event.params.account, event.params.stalk, event.params.roots, event.block); } -// TODO: L1PlotsMigrated + in manifest - +// Executed upon Reseed export function handleMigratedPlot(event: MigratedPlot): void { addMigratedPlot(event.params.account, event.params.plotIndex, event.params.pods, event, true); } +// Executed upon contract balances migrated to L2 +export function handleL1PlotsMigrated(event: L1PlotsMigrated): void { + for (let i = 0; i < event.params.index.length; ++i) { + addMigratedPlot(event.params.receiver, event.params.index[i], event.params.pods[i], event, false); + } +} + export function handleMigratedPodListing(event: MigratedPodListing): void { podListingCreated({ event: event, diff --git a/projects/subgraph-beanstalk/tests/Migration.test.ts b/projects/subgraph-beanstalk/tests/Migration.test.ts index d3194d7d8..ba12131ec 100644 --- a/projects/subgraph-beanstalk/tests/Migration.test.ts +++ b/projects/subgraph-beanstalk/tests/Migration.test.ts @@ -19,6 +19,7 @@ import { import { handleAddMigratedDeposit, handleInternalBalanceMigrated, + handleL1PlotsMigrated, handleMigratedAccountStatus, handleMigratedPlot, handleMigratedPodListing, @@ -27,6 +28,7 @@ import { import { createAddMigratedDepositEvent, createInternalBalanceMigratedEvent, + createL1PlotsMigratedEvent, createMigratedAccountStatus, createMigratedPlotEvent, createMigratedPodListingEvent, @@ -135,6 +137,13 @@ describe("Beanstalk 3 Migration", () => { assert.fieldEquals("Plot", index.toString(), "source", "RESEED_MIGRATED"); assert.fieldEquals("Field", account.toHexString(), "unharvestablePods", amount.toString()); }); + test("L1PlotsMigrated", () => { + const index = [BigInt.fromU32(250000000).times(BI_10.pow(6)), BigInt.fromU32(450000000).times(BI_10.pow(6))]; + const amount = [BigInt.fromU32(1500).times(BI_10.pow(6)), BigInt.fromU32(2500).times(BI_10.pow(6))]; + handleL1PlotsMigrated(createL1PlotsMigratedEvent(account, account, index, amount)); + assert.fieldEquals("Plot", index[1].toString(), "source", "CONTRACT_RECEIVER_MIGRATED"); + assert.fieldEquals("Field", account.toHexString(), "unharvestablePods", amount[0].plus(amount[1]).toString()); + }); test("MigratedPodListing", () => { const index = BigInt.fromU32(500).times(BI_10.pow(6)); const amount = BigInt.fromU32(1500).times(BI_10.pow(6)); diff --git a/projects/subgraph-beanstalk/tests/event-mocking/Migration.ts b/projects/subgraph-beanstalk/tests/event-mocking/Migration.ts index b71c32e89..8d250690a 100644 --- a/projects/subgraph-beanstalk/tests/event-mocking/Migration.ts +++ b/projects/subgraph-beanstalk/tests/event-mocking/Migration.ts @@ -2,6 +2,7 @@ import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts"; import { AddMigratedDeposit, InternalBalanceMigrated, + L1PlotsMigrated, MigratedAccountStatus, MigratedPlot, MigratedPodListing, @@ -65,6 +66,23 @@ export function createMigratedPlotEvent(account: Address, plotIndex: BigInt, pod return event as MigratedPlot; } +export function createL1PlotsMigratedEvent(owner: Address, receiver: Address, index: BigInt[], pods: BigInt[]): L1PlotsMigrated { + let event = changetype(mockContractEvent(BEANSTALK_ARB)); + event.parameters = new Array(); + + let param1 = new ethereum.EventParam("owner", ethereum.Value.fromAddress(owner)); + let param2 = new ethereum.EventParam("receiver", ethereum.Value.fromAddress(receiver)); + let param3 = new ethereum.EventParam("index", ethereum.Value.fromUnsignedBigIntArray(index)); + let param4 = new ethereum.EventParam("pods", ethereum.Value.fromUnsignedBigIntArray(pods)); + + event.parameters.push(param1); + event.parameters.push(param2); + event.parameters.push(param3); + event.parameters.push(param4); + + return event as L1PlotsMigrated; +} + export function createMigratedPodListingEvent( lister: Address, fieldId: BigInt,