Skip to content

Commit

Permalink
Migrate event processor, pt. 1 (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
silochad authored Jun 27, 2023
2 parents bfd9373 + 36a6ccc commit 49b4eb1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 539 deletions.
1 change: 1 addition & 0 deletions projects/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export { TokenValue } from "@beanstalk/sdk-core";
export { Workflow } from "src/classes/Workflow";
export { DecimalBigNumber } from "src/classes/DecimalBigNumber";
export { SwapOperation } from "src/lib/swap/SwapOperation";
export { EventProcessor } from "src/lib/events/processor";

// Modules
export { FarmWorkflow, FarmFromMode, FarmToMode } from "src/lib/farm";
Expand Down
10 changes: 0 additions & 10 deletions projects/sdk/src/lib/events/EventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ export class EventManager {
fromBlockOrGenesis,
toBlock
),
this.sdk.contracts.beanstalk.queryFilter(
this.sdk.contracts.beanstalk.filters.AddWithdrawal(_account, _token),
fromBlockOrGenesis,
toBlock
),
this.sdk.contracts.beanstalk.queryFilter(
this.sdk.contracts.beanstalk.filters.RemoveWithdrawal(_account, _token),
fromBlockOrGenesis,
Expand Down Expand Up @@ -81,11 +76,6 @@ export class EventManager {
case EventType.SILO:
return Promise.all([
this.sdk.contracts.beanstalk.queryFilter(this.sdk.contracts.beanstalk.filters.AddDeposit(_account), fromBlockOrGenesis, toBlock),
this.sdk.contracts.beanstalk.queryFilter(
this.sdk.contracts.beanstalk.filters.AddWithdrawal(_account),
fromBlockOrGenesis,
toBlock
),
this.sdk.contracts.beanstalk.queryFilter(
this.sdk.contracts.beanstalk.filters.RemoveWithdrawal(_account),
fromBlockOrGenesis,
Expand Down
136 changes: 1 addition & 135 deletions projects/sdk/src/lib/events/processor.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { BigNumber as EBN } from "ethers";
import {
AddDepositEvent,
AddWithdrawalEvent,
RemoveDepositEvent,
RemoveWithdrawalEvent,
RemoveWithdrawalsEvent
} from "src/constants/generated/protocol/abi/Beanstalk";
import EventProcessor, { EventProcessingParameters } from "./processor";
import { EventProcessor, EventProcessingParameters } from "./processor";
import { BeanstalkSDK } from "../BeanstalkSDK";
import { getProvider } from "../../utils/TestUtils/provider";

Expand Down Expand Up @@ -249,58 +248,6 @@ describe("the Silo", () => {
});
});

it("adds withdrawals", () => {
const p = mockProcessor();

// Withdrawal: 1000 Bean, Season 6074
const amount1 = EBN.from(1000 * 10 ** Bean.decimals); // Withdrew 1,000 Bean
p.ingest({
event: "AddWithdrawal",
args: propArray({
account,
token: Bean.address,
season: EBN.from(6074),
amount: amount1
})
} as AddWithdrawalEvent);

expect(p.withdrawals.get(Bean)?.["6074"]).toStrictEqual({
amount: amount1
});

// Withdrawal: 500 Bean, Season 6074
const amount2 = EBN.from(500 * 10 ** Bean.decimals); // Withdrew 500 Bean
p.ingest({
event: "AddWithdrawal",
args: propArray({
account,
token: Bean.address,
season: EBN.from(6074),
amount: amount2
})
} as AddWithdrawalEvent);

expect(p.withdrawals.get(Bean)?.["6074"]).toStrictEqual({
amount: amount1.add(amount2)
});

// Deposit: 1000 Bean:CRV3 LP, Season 6100
const amount3 = EBN.from(1000).mul(EBN.from(10).pow(BeanCrv3.decimals));
p.ingest({
event: "AddWithdrawal",
args: propArray({
account,
token: BeanCrv3.address,
season: EBN.from(6100),
amount: amount3 // Deposited 1,000 Bean:CRV3
})
} as AddWithdrawalEvent);

expect(p.withdrawals.get(BeanCrv3)?.["6100"]).toStrictEqual({
amount: amount3
});
});

it("removes a single deposit, partial -> full", () => {
const p = mockProcessor();

Expand Down Expand Up @@ -354,87 +301,6 @@ describe("the Silo", () => {
expect(p.deposits.get(Bean)?.["6074"]).toBeUndefined();
});

it("removes a single withdrawal", () => {
const p = mockProcessor();

// Withdraw: 1000 Bean in Season 6074
const amount1 = EBN.from(1000 * 10 ** Bean.decimals);
p.ingest({
event: "AddWithdrawal",
args: propArray({
account,
token: Bean.address,
season: EBN.from(6074),
amount: amount1
})
} as AddWithdrawalEvent);

// Claim: 600 Bean from Withdrawal in Season 6074
p.ingest({
event: "RemoveWithdrawal",
args: propArray({
account,
token: Bean.address,
season: EBN.from(6074),
amount: amount1
})
} as RemoveWithdrawalEvent);

// withdrawal should be deleted
expect(p.withdrawals.get(Bean)?.["6074"]).toBeUndefined();
});

it("removes multiple withdrawals, full", () => {
const p = mockProcessor();

// Withdraw: 1000 Bean in Season 6074
const amount1 = EBN.from(1000 * 10 ** Bean.decimals);
p.ingest({
event: "AddWithdrawal",
args: propArray({
account,
token: Bean.address,
season: EBN.from(6074),
amount: amount1
})
} as AddWithdrawalEvent);

expect(p.withdrawals.get(Bean)?.["6074"]).toStrictEqual({
amount: amount1
});

// Withdraw: 5000 Bean in Season 6100
const amount2 = EBN.from(5000 * 10 ** Bean.decimals);
p.ingest({
event: "AddWithdrawal",
args: propArray({
account,
token: Bean.address,
season: EBN.from(6100),
amount: amount2
})
} as AddWithdrawalEvent);

expect(p.withdrawals.get(Bean)?.["6100"]).toStrictEqual({
amount: amount2
});

// Claim: 1000 from 6074, 5000 from 6100
const amount3 = EBN.from(6000 * 10 ** Bean.decimals);
p.ingest({
event: "RemoveWithdrawals",
args: propArray({
account,
token: Bean.address,
seasons: ["6074", "6100"],
amount: amount3
})
} as RemoveWithdrawalsEvent);

expect(p.withdrawals.get(Bean)?.["6074"]).toBeUndefined();
expect(p.withdrawals.get(Bean)?.["6100"]).toBeUndefined();
});

it("ignores empty RemoveWithdrawal events", () => {
const p = mockProcessor();

Expand Down
Loading

0 comments on commit 49b4eb1

Please sign in to comment.