Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

58 setup queries for nabla backend for campaign and mainnet reward program #62

Conversation

bogdanS98
Copy link
Contributor

@bogdanS98 bogdanS98 commented May 2, 2024

Closes #58.

This should be merged to main only after #52 is merged.

Tested some of these changes locally by running the nabla indexer tests from this wasm-deploy branch, therefore generating some events data. This is not enough, so more events must be generated in order to test all queries.

@bogdanS98 bogdanS98 requested a review from a team May 8, 2024 20:05
@bogdanS98 bogdanS98 marked this pull request as ready for review May 8, 2024 20:05
@prayagd
Copy link
Contributor

prayagd commented May 20, 2024

@pendulum-chain/devs can we please review this? it would unblock the nabla testnet campaign

TorstenStueber
TorstenStueber previously approved these changes May 22, 2024
Copy link
Member

@TorstenStueber TorstenStueber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor comment. I already approve and leave it to you to change the name if this is low effort.

schema.graphql Outdated Show resolved Hide resolved
@bogdanS98
Copy link
Contributor Author

@pendulum-chain/devs any update on this? is there a fix to be done, can we please priortize this as this is blocking the campaign

I'm working on this as we speak, will push the latest changes requested in the next few hours

@prayagd
Copy link
Contributor

prayagd commented May 28, 2024

I'm working on this as we speak, will push the latest changes requested in the next few hours

Thank you Bogdan for the update

@bogdanS98
Copy link
Contributor Author

bogdanS98 commented May 28, 2024

I would expect the sender to have a properly encoded address so that I can easily look up the account on chain. This is not the case at the moment. image

I also get quite a lot of errors when processing on Foucoco locally. Any ideas @bogdanS98?

18:08:08 INFO  sqd:processor 1508390 / 1562149, rate: 1449 blocks/sec, mapping: 939 blocks/sec, 1681 items/sec, eta: 37s
Error processing event 'Contracts.ContractEmitted'. Skipping due to error: QueryFailedError: update or delete on table "nabla_swap_fee" violates foreign key constraint "FK_dd24afed240ad46290bfcf0603b" on table "nabla_swap"
    at PostgresQueryRunner.query (/Users/marcel/Documents/pendulum-squids/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:211:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async DeleteQueryBuilder.execute (/Users/marcel/Documents/pendulum-squids/node_modules/typeorm/query-builder/DeleteQueryBuilder.js:52:33)
    at async Store.remove (/Users/marcel/Documents/pendulum-squids/node_modules/@subsquid/typeorm-store/lib/store.js:114:17)
    at async filterSwapFeeHistory (/Users/marcel/Documents/pendulum-squids/lib/mappings/nabla/swapPoolEventHandler.js:118:13)
    at async updateAndPruneSwapFeeHistory (/Users/marcel/Documents/pendulum-squids/lib/mappings/nabla/swapPoolEventHandler.js:112:5)
    at async updateAprAfterSwap (/Users/marcel/Documents/pendulum-squids/lib/mappings/nabla/swapPoolEventHandler.js:124:5)
    at async handleChargedSwapFees (/Users/marcel/Documents/pendulum-squids/lib/mappings/nabla/swapPoolEventHandler.js:68:5)
    at async handleSwapPoolEvent (/Users/marcel/Documents/pendulum-squids/lib/mappings/nabla/swapPoolEventHandler.js:23:13)
    at async handleContractEvent (/Users/marcel/Documents/pendulum-squids/lib/mappings/nabla/handleEvent.js:71:13) {
  query: 'DELETE FROM "nabla_swap_fee" WHERE "id" IN ($1)',
  parameters: [ '1495223-3' ],
  driverError: error: update or delete on table "nabla_swap_fee" violates foreign key constraint "FK_dd24afed240ad46290bfcf0603b" on table "nabla_swap"
      at Parser.parseErrorMessage (/Users/marcel/Documents/pendulum-squids/node_modules/pg-protocol/dist/parser.js:287:98)
      at Parser.handlePacket (/Users/marcel/Documents/pendulum-squids/node_modules/pg-protocol/dist/parser.js:126:29)
      at Parser.parse (/Users/marcel/Documents/pendulum-squids/node_modules/pg-protocol/dist/parser.js:39:38)
      at Socket.<anonymous> (/Users/marcel/Documents/pendulum-squids/node_modules/pg-protocol/dist/index.js:11:42)
      at Socket.emit (node:events:512:28)
      at addChunk (node:internal/streams/readable:324:12)
      at readableAddChunk (node:internal/streams/readable:297:9)
      at Readable.push (node:internal/streams/readable:234:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
    length: 317,
    severity: 'ERROR',
    code: '23503',
    detail: 'Key (id)=(1495223-3) is still referenced from table "nabla_swap".',
    hint: undefined,
    position: undefined,
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: 'public',
    table: 'nabla_swap',
    column: undefined,
    dataType: undefined,
    constraint: 'FK_dd24afed240ad46290bfcf0603b',
    file: 'ri_triggers.c',
    line: '2609',
    routine: 'ri_ReportViolation'
  },
  length: 317,
  severity: 'ERROR',
  code: '23503',
  detail: 'Key (id)=(1495223-3) is still referenced from table "nabla_swap".',
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: 'public',
  table: 'nabla_swap',
  column: undefined,
  dataType: undefined,
  constraint: 'FK_dd24afed240ad46290bfcf0603b',
  file: 'ri_triggers.c',
  line: '2609',
  routine: 'ri_ReportViolation'
}
Error processing event 'Tokens.Transfer'. Skipping due to error: QueryFailedError: current transaction is aborted, commands ignored until end of transaction block
    at PostgresQueryRunner.query (/Users/marcel/Documents/pendulum-squids/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:211:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async InsertQueryBuilder.execute (/Users/marcel/Documents/pendulum-squids/node_modules/typeorm/query-builder/InsertQueryBuilder.js:106:33)
    at async Store.upsert (/Users/marcel/Documents/pendulum-squids/node_modules/@subsquid/typeorm-store/lib/store.js:38:13)
    at async handleTokenTransfer (/Users/marcel/Documents/pendulum-squids/lib/mappings/token.js:329:5)
    at async /Users/marcel/Documents/pendulum-squids/lib/processor.js:130:25
    at async TypeormDatabase.performUpdates (/Users/marcel/Documents/pendulum-squids/node_modules/@subsquid/typeorm-store/lib/database.js:139:13)
    at async /Users/marcel/Documents/pendulum-squids/node_modules/@subsquid/typeorm-store/lib/database.js:84:13
    at async EntityManager.transaction (/Users/marcel/Documents/pendulum-squids/node_modules/typeorm/entity-manager/EntityManager.js:73:28)
    at async TypeormDatabase.submit (/Users/marcel/Documents/pendulum-squids/node_modules/@subsquid/typeorm-store/lib/database.js:151:24) {
  query: 'INSERT INTO "token_transfer"("id", "block_number", "timestamp", "extrinsic_hash", "from", "to", "currency_id", "amount", "remark") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, DEFAULT) ON CONFLICT ( "id" ) DO UPDATE SET "id" = EXCLUDED."id", "block_number" = EXCLUDED."block_number", "timestamp" = EXCLUDED."timestamp", "extrinsic_hash" = EXCLUDED."extrinsic_hash", "from" = EXCLUDED."from", "to" = EXCLUDED."to", "currency_id" = EXCLUDED."currency_id", "amount" = EXCLUDED."amount"',
  parameters: [
    '0001522352-781cd-000031',
    1522352,
    2024-05-08T11:15:48.155Z,
    '0x279944f9ff33020065859b585b89b63c2bff00c6641e1e67d314d4266e3c3a8f',
    '6kjpZPe7tkAKD7e8UyLeLMz1vUEDgkwxXuyCrtiCWXUzhe7u',
    '6ijJtaZuwpZCiaVo6pSHRJbd8qejgywYsejnjfo2AVanN14E',
    'XCM(0)',
    '904545686'
  ],
  driverError: error: current transaction is aborted, commands ignored until end of transaction block
      at Parser.parseErrorMessage (/Users/marcel/Documents/pendulum-squids/node_modules/pg-protocol/dist/parser.js:287:98)
      at Parser.handlePacket (/Users/marcel/Documents/pendulum-squids/node_modules/pg-protocol/dist/parser.js:126:29)
      at Parser.parse (/Users/marcel/Documents/pendulum-squids/node_modules/pg-protocol/dist/parser.js:39:38)
      at Socket.<anonymous> (/Users/marcel/Documents/pendulum-squids/node_modules/pg-protocol/dist/index.js:11:42)
      at Socket.emit (node:events:512:28)
      at addChunk (node:internal/streams/readable:324:12)
      at readableAddChunk (node:internal/streams/readable:297:9)
      at Readable.push (node:internal/streams/readable:234:10)
      at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
    length: 145,
    severity: 'ERROR',
    code: '25P02',
    detail: undefined,
    hint: undefined,
    position: undefined,
    internalPosition: undefined,
    internalQuery: undefined,
    where: undefined,
    schema: undefined,
    table: undefined,
    column: undefined,
    dataType: undefined,
    constraint: undefined,
    file: 'postgres.c',
    line: '1470',
    routine: 'exec_parse_message'
  },
  length: 145,
  severity: 'ERROR',
  code: '25P02',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'postgres.c',
  line: '1470',
  routine: 'exec_parse_message'
}
Error processing event 'Contracts.ContractEmitted'. Skipping due to error: QueryFailedError: current transaction is aborted, commands ignored until end of transaction block
    at PostgresQueryRunner.query (/Users/marcel/Documents/pendulum-squids/node_modules/typeorm/driver/postgres/PostgresQueryRunner.js:211:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SelectQueryBuilder.loadRawResults (/Users/marcel/Documents/pendulum-squids/node_modules/typeorm/query-builder/SelectQueryBuilder.js:2183:25)
    at async SelectQueryBuilder.getRawMany (/Users/marcel/Documents/pendulum-squids/node_modules/typeorm/query-builder/SelectQueryBuilder.js:646:29)
    at async SelectQueryBuilder.executeEntitiesAndRawResults (/Users/marcel/Documents/pendulum-squids/node_modules/typeorm/query-builder/SelectQueryBuilder.js:1973:26)
    at async SelectQueryBuilder.getRawAndEntities (/Users/marcel/Documents/pendulum-squids/node_modules/typeorm/query-builder/SelectQueryBuilder.js:684:29)
    at async SelectQueryBuilder.getOne (/Users/marcel/Documents/pendulum-squids/node_modules/typeorm/query-builder/SelectQueryBuilder.js:711:25)
    at async getBackstopPool (/Users/marcel/Documents/pendulum-squids/lib/mappings/nabla/creation.js:34:12)
    at async Promise.all (index 0)
    at async handleContractEvent (/Users/marcel/Documents/pendulum-squids/lib/mappings/nabla/handleEvent.js:58:61) {

This fixes the errors in the console by setting the reference to swapFee to null before deleting a swap pool.
Also, I converted hex addresses to ss58 👍🏼

Copy link
Member

@ebma ebma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm that the error messages don't appear anymore during the processing, good job @bogdanS98 👍

We should change the schema so that the deposit and withdrawal events link to either the respective swap or backstop pool. Otherwise, we are missing very important information and the events are useless.
image

Base automatically changed from 44-migrate-to-new-nabla-contracts to main May 29, 2024 11:52
@TorstenStueber TorstenStueber dismissed their stale review May 29, 2024 11:52

The base branch was changed.

@bogdanS98 bogdanS98 requested review from ebma and gianfra-t May 30, 2024 16:23
Copy link
Member

@ebma ebma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

schema.graphql Outdated Show resolved Hide resolved
Copy link
Contributor

@gianfra-t gianfra-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too 👍

@gianfra-t gianfra-t self-requested a review May 30, 2024 19:23
Copy link
Member

@ebma ebma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge @bogdanS98?

@bogdanS98 bogdanS98 merged commit 68ee4fd into main May 31, 2024
@bogdanS98 bogdanS98 deleted the 58-setup-queries-for-nabla-backend-for-campaign-and-mainnet-reward-program branch May 31, 2024 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setup queries for Nabla backend for campaign and mainnet reward program
5 participants