Skip to content

Commit

Permalink
handle contract pod migration
Browse files Browse the repository at this point in the history
  • Loading branch information
soilking committed Sep 30, 2024
1 parent 00226a4 commit 0d69693
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
20 changes: 20 additions & 0 deletions projects/subgraph-beanstalk/manifests/arbitrum.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
###
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ZERO_BI } from "../../../../subgraph-core/utils/Decimals";
import {
AddMigratedDeposit,
InternalBalanceMigrated,
L1PlotsMigrated,
MigratedAccountStatus,
MigratedPlot,
MigratedPodListing,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions projects/subgraph-beanstalk/tests/Migration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import {
handleAddMigratedDeposit,
handleInternalBalanceMigrated,
handleL1PlotsMigrated,
handleMigratedAccountStatus,
handleMigratedPlot,
handleMigratedPodListing,
Expand All @@ -27,6 +28,7 @@ import {
import {
createAddMigratedDepositEvent,
createInternalBalanceMigratedEvent,
createL1PlotsMigratedEvent,
createMigratedAccountStatus,
createMigratedPlotEvent,
createMigratedPodListingEvent,
Expand Down Expand Up @@ -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));
Expand Down
18 changes: 18 additions & 0 deletions projects/subgraph-beanstalk/tests/event-mocking/Migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts";
import {
AddMigratedDeposit,
InternalBalanceMigrated,
L1PlotsMigrated,
MigratedAccountStatus,
MigratedPlot,
MigratedPodListing,
Expand Down Expand Up @@ -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<L1PlotsMigrated>(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,
Expand Down

0 comments on commit 0d69693

Please sign in to comment.