From 8a866a592bc6d5e190bf0f611528b04155432dea Mon Sep 17 00:00:00 2001 From: jerryfan01234 <44346807+jerryfan01234@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:11:04 -0400 Subject: [PATCH] add wallet when transfer to subaccount (#2519) --- .../__tests__/handlers/transfer-handler.test.ts | 15 +++++++++++---- .../scripts/handlers/dydx_transfer_handler.sql | 5 +++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/indexer/services/ender/__tests__/handlers/transfer-handler.test.ts b/indexer/services/ender/__tests__/handlers/transfer-handler.test.ts index 4f7f959070..cd8c7e8005 100644 --- a/indexer/services/ender/__tests__/handlers/transfer-handler.test.ts +++ b/indexer/services/ender/__tests__/handlers/transfer-handler.test.ts @@ -311,7 +311,7 @@ describe('transferHandler', () => { expect(wallet).toEqual(defaultWallet); }); - it('creates new deposit for previously non-existent subaccount', async () => { + it('creates new deposit for previously non-existent subaccount (also non-existent recipient wallet)', async () => { const transactionIndex: number = 0; const depositEvent: TransferEventV1 = defaultDepositEvent; @@ -348,16 +348,23 @@ describe('transferHandler', () => { newTransfer, asset, ); - // Confirm the wallet was created - const wallet: WalletFromDatabase | undefined = await WalletTable.findById( + // Confirm the wallet was created for the sender and recipient + const walletSender: WalletFromDatabase | undefined = await WalletTable.findById( defaultWalletAddress, ); + const walletRecipient: WalletFromDatabase | undefined = await WalletTable.findById( + defaultDepositEvent.recipient!.subaccountId!.owner, + ); const newRecipientSubaccount: SubaccountFromDatabase | undefined = await SubaccountTable.findById( defaultRecipientSubaccountId, ); expect(newRecipientSubaccount).toBeDefined(); - expect(wallet).toEqual(defaultWallet); + expect(walletSender).toEqual(defaultWallet); + expect(walletRecipient).toEqual({ + ...defaultWallet, + address: defaultDepositEvent.recipient!.subaccountId!.owner, + }); }); it('creates new withdrawal for existing subaccount', async () => { diff --git a/indexer/services/ender/src/scripts/handlers/dydx_transfer_handler.sql b/indexer/services/ender/src/scripts/handlers/dydx_transfer_handler.sql index 396a0075f8..8e9b251548 100644 --- a/indexer/services/ender/src/scripts/handlers/dydx_transfer_handler.sql +++ b/indexer/services/ender/src/scripts/handlers/dydx_transfer_handler.sql @@ -46,6 +46,11 @@ BEGIN SET "updatedAtHeight" = recipient_subaccount_record."updatedAtHeight", "updatedAt" = recipient_subaccount_record."updatedAt"; + + recipient_wallet_record."address" = event_data->'recipient'->'subaccountId'->>'owner'; + recipient_wallet_record."totalTradingRewards" = '0'; + recipient_wallet_record."totalVolume" = '0'; + INSERT INTO wallets VALUES (recipient_wallet_record.*) ON CONFLICT DO NOTHING; END IF; IF event_data->'sender'->'subaccountId' IS NOT NULL THEN