Skip to content

Commit

Permalink
add wallet when transfer to subaccount (#2519)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryfan01234 authored Oct 18, 2024
1 parent 301b438 commit 8a866a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 11 additions & 4 deletions indexer/services/ender/__tests__/handlers/transfer-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8a866a5

Please sign in to comment.