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

feat/get all balances #214

Merged
merged 20 commits into from
Oct 25, 2023
Merged

feat/get all balances #214

merged 20 commits into from
Oct 25, 2023

Conversation

genaroibc
Copy link
Contributor

@genaroibc genaroibc commented Oct 11, 2023

Description

closes #223

Add methods to get EVM and Cosmos token balances.

const squid = new Squid({
  baseUrl: "https://v2.api.squidrouter.com",
  integratorId: "squid-test"
});

await squid.init();

const cosmos = await squid.getAllCosmosBalances({
  addresses: [
    {
      chainId: "cosmoshub",
      address: "cosmos1awrua7e2kj69d7vn5qt5tccrhavmj9xajl58pw",
      coinType: 118
    }
  ]
});

const evmBalances = await squid.getAllEvmBalances({
  userAddress: "0x9a32549df3ff3c1fd725f81093c47445218de723",
  chains: [1, 43114, 8453]
});

getAllBalances

const balances = await squid.getAllBalances({
  chainIds: [1, 43114, "osmosis-1", "cosmoshub-4"],
  evmAddress: "0x344b63c2BcB4B61765083735e8F49Bb203415a33",
  cosmosAddresses: [
    {
      address: "cosmos1awrua7e2kj69d7vn5qt5tccrhavmj9xajl58pw",
      chainId: "cosmoshub-4",
      coinType: 118
    }
  ]
});

// result
{
  cosmos: [
    {
      balance: "676727870",
      denom: "ibc/E6931F78057F7CC5DA0FD6CEF82FF39373A6E0452BF1FD76910B93292CF356C1",
      chainId: "osmosis-1",
      decimals: 6
    }, {
      balance: "5987424",
      denom: "uosmo",
      chainId: "osmosis-1",
      decimals: 6
    }, {
      balance: "1804685",
      denom: "uatom",
      chainId: "cosmoshub-4",
      decimals: 6
    }
  ],
  evm: [
    {
      symbol: "USDC",
      address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
      decimals: 6,
      balance: "1549424225"
    }, {
      symbol: "AVAX",
      address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
      decimals: 18,
      balance: "41345097216001030"
    }, {
      symbol: "ETH",
      address: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
      decimals: 18,
      balance: "41345097216001030"
    }
  ]
}

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

src/types/index.ts Outdated Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
Copy link
Contributor

@odcey odcey left a comment

Choose a reason for hiding this comment

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

I would unify the response

  • adding decimals on cosmos item
  • naming balance instead of amount for cosmos to be the same as evm

Copy link
Contributor

@jmdev3 jmdev3 left a comment

Choose a reason for hiding this comment

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

LGTM! Good work

@ecdsafu
Copy link
Contributor

ecdsafu commented Oct 25, 2023

Exciting to have this ready, thanks a lot @genaroibc !

Could you please update the PR comments to reflect the updated interface?

@jmdev3 jmdev3 merged commit cf3f1b8 into main Oct 25, 2023
@jmdev3 jmdev3 deleted the feat/get-all-balances branch October 25, 2023 19:45
@genaroibc
Copy link
Contributor Author

Updated!

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.

[SDK] Get all balances
4 participants