Skip to content

solana/cs_token_pool : fallback to erc20 decimals for pools without getTokenDecimals#21698

Open
0xsuryansh wants to merge 1 commit intodevelopfrom
0xsuryansh/add-support-to-pools-without-getTokenDecimals
Open

solana/cs_token_pool : fallback to erc20 decimals for pools without getTokenDecimals#21698
0xsuryansh wants to merge 1 commit intodevelopfrom
0xsuryansh/add-support-to-pools-without-getTokenDecimals

Conversation

@0xsuryansh
Copy link
Member

No description provided.

@github-actions
Copy link
Contributor

✅ No conflicts with other open PRs targeting develop

@trunk-io
Copy link

trunk-io bot commented Mar 25, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@0xsuryansh 0xsuryansh marked this pull request as ready for review March 25, 2026 17:19
@0xsuryansh 0xsuryansh requested a review from a team as a code owner March 25, 2026 17:19
Copilot AI review requested due to automatic review settings March 25, 2026 17:19
@0xsuryansh 0xsuryansh requested review from a team as code owners March 25, 2026 17:19
@cl-sonarqube-production
Copy link

@0xsuryansh 0xsuryansh changed the title fallback to erc20 decimals for pools without getTokenDecimals solana/cs_token_poo : lfallback to erc20 decimals for pools without getTokenDecimals Mar 25, 2026
@0xsuryansh 0xsuryansh changed the title solana/cs_token_poo : lfallback to erc20 decimals for pools without getTokenDecimals solana/cs_token_pool : fallback to erc20 decimals for pools without getTokenDecimals Mar 25, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Risk Rating: MEDIUM

This PR updates the Solana v0.1.1 token-pool changeset logic to determine EVM token decimals more robustly by falling back to querying the underlying ERC20 token when the pool’s getTokenDecimals call fails.

Changes:

  • Introduces an ERC20-based fallback for fetching decimals when evmTokenPool.GetTokenDecimals(...) errors.
  • Reuses a single bind.CallOpts instance for the EVM calls within getOnChainEVMPoolConfig.
  • Adds an ERC20 wrapper dependency to support the fallback decimals query.

Comment on lines +562 to +569
tokenAddr, err2 := evmTokenPool.GetToken(callOpts)
if err2 != nil {
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to get token address from evm token pool: %w", err2)
}
token, err2 := erc20.NewERC20(tokenAddr, evmChain.Client)
if err2 != nil {
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to bind erc20 to fetch decimals at %s: %w", tokenAddr.Hex(), err2)
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The fallback path re-reads the token address from the pool via evmTokenPool.GetToken(...), but evmTokenAddress was already fetched earlier by GetTokenStateFromPoolEVM. Consider reusing evmTokenAddress here to avoid an extra RPC call and keep the value consistent with the earlier lookup.

Suggested change
tokenAddr, err2 := evmTokenPool.GetToken(callOpts)
if err2 != nil {
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to get token address from evm token pool: %w", err2)
}
token, err2 := erc20.NewERC20(tokenAddr, evmChain.Client)
if err2 != nil {
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to bind erc20 to fetch decimals at %s: %w", tokenAddr.Hex(), err2)
}
token, err2 := erc20.NewERC20(evmTokenAddress, evmChain.Client)
if err2 != nil {
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to bind erc20 to fetch decimals at %s: %w", evmTokenAddress.Hex(), err2)
}

Copilot uses AI. Check for mistakes.
Comment on lines +564 to +572
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to get token address from evm token pool: %w", err2)
}
token, err2 := erc20.NewERC20(tokenAddr, evmChain.Client)
if err2 != nil {
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to bind erc20 to fetch decimals at %s: %w", tokenAddr.Hex(), err2)
}
evmTokenDecimals, err2 = token.Decimals(callOpts)
if err2 != nil {
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to get token decimals from token contract: %w", err2)
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

If the fallback fails (e.g., GetToken/Decimals errors), the returned error drops the original GetTokenDecimals failure that triggered the fallback. Please include/wrap the original err in fallback error messages so the root cause of the pool call failure is still visible when debugging.

Suggested change
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to get token address from evm token pool: %w", err2)
}
token, err2 := erc20.NewERC20(tokenAddr, evmChain.Client)
if err2 != nil {
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to bind erc20 to fetch decimals at %s: %w", tokenAddr.Hex(), err2)
}
evmTokenDecimals, err2 = token.Decimals(callOpts)
if err2 != nil {
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to get token decimals from token contract: %w", err2)
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to get token address from evm token pool (original GetTokenDecimals error: %v): %w", err, err2)
}
token, err2 := erc20.NewERC20(tokenAddr, evmChain.Client)
if err2 != nil {
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to bind erc20 to fetch decimals at %s (original GetTokenDecimals error: %v): %w", tokenAddr.Hex(), err, err2)
}
evmTokenDecimals, err2 = token.Decimals(callOpts)
if err2 != nil {
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to get token decimals from token contract (original GetTokenDecimals error: %v): %w", err, err2)

Copilot uses AI. Check for mistakes.
Comment on lines +559 to +562
evmTokenDecimals, err := evmTokenPool.GetTokenDecimals(callOpts)
if err != nil {
return solBaseTokenPool.RemoteConfig{}, fmt.Errorf("failed to get token decimals: %w", err)
// Fallback: some pool ABIs omit GetTokenDecimals; read decimals from the underlying ERC20.
tokenAddr, err2 := evmTokenPool.GetToken(callOpts)
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

This change adds a new fallback behavior when GetTokenDecimals fails, but the existing Solana v0.1.1 changeset tests appear to only cover the happy path where GetTokenDecimals succeeds. Please add a test that exercises the fallback branch (e.g., a pool contract instance that lacks getTokenDecimals/reverts on that selector) and asserts decimals are read from the ERC20 token.

Copilot generated this review using guidance from repository custom instructions.
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