Skip to content

Commit

Permalink
Fix for CwTokenAdapter getBalance method (#3107)
Browse files Browse the repository at this point in the history
### Description

Use getBalance instead of queryContractSmart for CwTokenAdapter

### Drive-by Changes

Fix SmartProvider unit test

### Backward compatibility

Yes

### Testing

Tested in warp UI
  • Loading branch information
jmrossy authored Jan 2, 2024
1 parent 4ce89df commit a04454d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-needles-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': patch
---

Use getBalance instead of queryContractSmart for CwTokenAdapter
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { ChainMetadata } from '../../metadata/chainMetadataTypes';
import { ProviderMethod } from './ProviderMethods';
import { HyperlaneSmartProvider } from './SmartProvider';

const MIN_BLOCK_NUM = 10000000;
const MIN_BLOCK_NUM = 10200000;
const DEFAULT_ACCOUNT = '0x9d525E28Fe5830eE92d7Aa799c4D21590567B595';
const WETH_CONTRACT = '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6';
const WETH_TRANSFER_TOPIC0 =
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
const WETH_TRANSFER_TOPIC1 =
'0x0000000000000000000000004648a43b2c14da09fdf82b161150d3f634f40491';
'0x00000000000000000000000022a9af161b9660f3dc1b996bf1e622a2c58b8558';
const WETH_CALL_DATA =
'0x70a082310000000000000000000000004f7a67464b5976d7547c860109e4432d50afb38e';
const TRANSFER_TX_HASH =
Expand Down Expand Up @@ -61,7 +61,9 @@ describe('SmartProvider', () => {

for (const [description, config] of configs) {
describe(description, () => {
provider = HyperlaneSmartProvider.fromChainMetadata(config);
provider = HyperlaneSmartProvider.fromChainMetadata(config, {
debug: true,
});

itDoesIfSupported(ProviderMethod.GetBlock, async () => {
const latestBlock = await provider.getBlock('latest');
Expand Down
9 changes: 3 additions & 6 deletions typescript/sdk/src/token/adapters/CosmWasmTokenAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,9 @@ export class CwTokenAdapter
}

async getBalance(address: Address): Promise<string> {
const resp = await this.queryToken<BalanceResponse>({
balance: {
address,
},
});
return resp.balance;
const provider = await this.getProvider();
const balance = await provider.getBalance(address, this.addresses.token);
return balance.amount;
}

async getMetadata(): Promise<CW20Metadata> {
Expand Down

0 comments on commit a04454d

Please sign in to comment.