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

add indexer gateway client #619

Merged
merged 3 commits into from
Dec 11, 2024
Merged

add indexer gateway client #619

merged 3 commits into from
Dec 11, 2024

Conversation

xiam
Copy link
Contributor

@xiam xiam commented Dec 4, 2024

This PRs adds the TypeScript client for Indexer Gateway.

@xiam xiam requested a review from a team as a code owner December 4, 2024 17:03
@xiam
Copy link
Contributor Author

xiam commented Dec 4, 2024

This example:

import {
  SequenceIndexerGateway
} from '0xsequence/indexergw'

const ACCOUNT_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'

const indexerGateway = new SequenceIndexerGateway(
  API_URL,
)

indexerGateway.getNativeTokenBalance({
  accountAddress: ACCOUNT_ADDRESS,
}).then((res:any) => {
  res.balances.forEach((balance:any) => {
    console.log({balance})
  })
}).catch((error:any) => {
  console.log({error})
})

Prints:

{
  balance: {
    chainID: 42170,
    balance: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '0'
    }
  }
}
{
  balance: {
    chainID: 10,
    balance: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '371086549230872066'
    }
  }
}
{
  balance: {
    chainID: 43113,
    balance: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '100100000000000000000'
    }
  }
}
{
  balance: {
    chainID: 81457,
    balance: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '0'
    }
  }
}
{
  balance: {
    chainID: 660279,
    balance: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '0'
    }
  }
}
{
  balance: {
    chainID: 11155420,
    balance: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '615667615048000000'
    }
  }
}
{
  balance: {
    chainID: 13473,
    balance: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '8100000000000000000'
    }
  }
}
{
  balance: {
    chainID: 97,
    balance: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '16003756289696138882'
    }
  }
}
{
  balance: {
    chainID: 11155111,
    balance: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '11164700846227378526'
    }
  }
}
{
  balance: {
    chainID: 1101,
    balance: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '6827072461408461'
    }
  }
}
...

@xiam xiam force-pushed the add-indexer-gateway-client branch from 9983206 to b4592f1 Compare December 4, 2024 17:42
@corbanbrook
Copy link
Contributor

Could we include the indexer gateway within the existing indexer package instead of creating a new one

@corbanbrook
Copy link
Contributor

Also looking at the output seems like there is redundant wrapping of balances:

{
  balance: {
    chainID: 11155111,
    balance: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '11164700846227378526'
    }
  }
}

balances[0].balance.balance.balance

this could just be:

{
  chainId: 11155111,
  accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
  balance: '11164700846227378526'
}

@pkieltyka
Copy link
Member

please lets not introduce another "indexergw" package. I know we are doing this on the Go side, but I don't want to do this on the Typescript side.

Please instead keep everything in @0xsequence/indexer and just have packages/indexer/src/indexer.gen.ts and packages/indexer/src/gateway.gen.ts and then for index.ts we can export separately or even we can use the "exports" so developers can import { IndexerGatewayClient } from '@0xsequence/indexer/gateway' as an example. But also could also do: import { IndexerGatewayClient } from '@0xsequence/indexer' ... we could export as .... from index, and bunch of other options.. but lets not introduce "indexergw" package here.

Copy link
Member

@pkieltyka pkieltyka left a comment

Choose a reason for hiding this comment

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

see comment

@xiam xiam force-pushed the add-indexer-gateway-client branch from 82e85fa to 4ec68bc Compare December 5, 2024 15:47
@xiam
Copy link
Contributor Author

xiam commented Dec 5, 2024

@corbanbrook This is how output from the latest version looks:

[
  {
    chainId: 10,
    result: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '371086549230872066'
    }
  },
  {
    chainId: 81457,
    result: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '0'
    }
  },
  {
    chainId: 137,
    result: {
      accountAddress: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
      balance: '52408389691068799440368'
    }
  },
  ...

packages/indexer/src/indexergw.gen.ts Outdated Show resolved Hide resolved
packages/indexer/src/indexergw.gen.ts Outdated Show resolved Hide resolved
packages/indexer/src/indexergw.gen.ts Outdated Show resolved Hide resolved
packages/indexer/src/indexergw.gen.ts Show resolved Hide resolved
packages/indexer/src/indexergw.gen.ts Show resolved Hide resolved
@xiam xiam force-pushed the add-indexer-gateway-client branch from 161c709 to d6f6245 Compare December 5, 2024 16:44
@xiam
Copy link
Contributor Author

xiam commented Dec 5, 2024

@corbanbrook I fixed the spelling for the newly introduced chainId properties; I'll tackle the legacy ones in a follow-up PR.

corbanbrook
corbanbrook previously approved these changes Dec 5, 2024
@xiam xiam changed the title add indexergw package add indexer gateway client Dec 9, 2024
@xiam xiam force-pushed the add-indexer-gateway-client branch from d6f6245 to 20c9ba3 Compare December 11, 2024 17:51
@corbanbrook corbanbrook self-requested a review December 11, 2024 18:32
@corbanbrook corbanbrook dismissed pkieltyka’s stale review December 11, 2024 18:33

This was already done

@xiam xiam force-pushed the add-indexer-gateway-client branch from 20c9ba3 to 5e9bdac Compare December 11, 2024 20:03
@corbanbrook corbanbrook merged commit b84ed2d into master Dec 11, 2024
22 checks passed
@corbanbrook corbanbrook deleted the add-indexer-gateway-client branch December 11, 2024 20:22
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.

3 participants