Skip to content

Commit

Permalink
fix: resolve issue with supply collateral event having null user
Browse files Browse the repository at this point in the history
  • Loading branch information
martines3000 committed Aug 16, 2024
1 parent d0bb16b commit 7618667
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
18 changes: 18 additions & 0 deletions apps/indexer/src/EventHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,29 @@ Market.UserSupplyCollateralEvent.loader(({ event, context }) => {
loadCollateralAsset: false,
loadUser: false,
});

const address = event.data.address;
context.User.load(address.bits);
});

Market.UserSupplyCollateralEvent.handler(async ({ event, context }) => {
const id = `${event.transactionId}_${event.receiptIndex}`;

// Create user if it doesn't exist
const user = await context.User.get(event.data.address.bits);

if (!user) {
context.User.set({
id: event.data.address.bits,
address: event.data.address.bits,
principal: BigInt(0),
baseTrackingIndex: BigInt(0),
baseTrackingAccrued: BigInt(0),
totalCollateralBought: BigInt(0),
totalValueLiquidated: BigInt(0),
});
}

context.UserCollateralEvent.set({
id,
user_id: event.data.address.bits,
Expand Down
22 changes: 1 addition & 21 deletions apps/indexer/test/tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,26 +408,6 @@ describe('Market contract event tests', () => {

const userAddress = ALICE_ADDRESS;

// We first need to initialize a mock user entity
const mockUserBasicEvent = Market.UserBasicEvent.mockData({
address: {
bits: userAddress,
},
user_basic: {
principal: {
negative: false,
value: BigInt(0),
},
base_tracking_index: BigInt(0),
base_tracking_accrued: BigInt(0),
},
});

let updatedMockDb = await Market.UserBasicEvent.processEvent({
event: mockUserBasicEvent,
mockDb: mockDbInitial,
});

// Create a mock user collateral event
const mockUserSupplyCollateralEvent =
Market.UserSupplyCollateralEvent.mockData({
Expand All @@ -439,7 +419,7 @@ describe('Market contract event tests', () => {
});

// Processing the mock event on the mock database
updatedMockDb = await Market.UserSupplyCollateralEvent.processEvent({
let updatedMockDb = await Market.UserSupplyCollateralEvent.processEvent({
event: mockUserSupplyCollateralEvent,
mockDb: mockDbInitial,
});
Expand Down

0 comments on commit 7618667

Please sign in to comment.