-
Notifications
You must be signed in to change notification settings - Fork 2
EVMTXGun Non-EVM Destination Support #1147
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
Open
Farber98
wants to merge
7
commits into
main
Choose a base branch
from
juan/evm-load-gun-nonevm-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+203
−81
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
decaab7
EVMTXGun Non-EVM Destination Support
Farber98 8ccb060
fix disableTokenAmountValidation and better logging
Farber98 2e282a9
fix comms
Farber98 eb7255b
weth fixes
Farber98 8d4e419
copilot feedback
Farber98 c64d949
copilot feedback
Farber98 901b1f5
copilot feedback
Farber98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "context" | ||
| "math/big" | ||
| "strconv" | ||
| "testing" | ||
|
|
||
| "github.com/Masterminds/semver/v3" | ||
| "github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/rs/zerolog" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_0_0/operations/weth" | ||
| "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_2_0/operations/router" | ||
| cldfevm "github.com/smartcontractkit/chainlink-deployments-framework/chain/evm" | ||
| "github.com/smartcontractkit/chainlink-deployments-framework/datastore" | ||
| "github.com/smartcontractkit/chainlink-deployments-framework/deployment" | ||
| "github.com/smartcontractkit/chainlink-evm/gethwrappers/shared/generated/initial/weth9" | ||
| ) | ||
|
|
||
| const requiredWETHBalanceForLoad = 1e18 | ||
|
|
||
| // EnsureWETHBalanceAndApproval prepares WETH and router approval for CCIP load senders on chain.Users. | ||
| func EnsureWETHBalanceAndApproval(ctx context.Context, t *testing.T, logger zerolog.Logger, e *deployment.Environment, chain cldfevm.Chain) { | ||
| t.Helper() | ||
|
|
||
| requiredWETH := big.NewInt(requiredWETHBalanceForLoad) | ||
|
|
||
| logger.Info().Str("chain", strconv.FormatUint(chain.Selector, 10)).Msg("Ensuring WETH balance and approval") | ||
| wethContract, err := e.DataStore.Addresses().Get( | ||
| datastore.NewAddressRefKey( | ||
| chain.Selector, | ||
| datastore.ContractType(weth.ContractType), | ||
| semver.MustParse(weth.Deploy.Version()), | ||
| "")) | ||
| require.NoErrorf(t, err, "failed to resolve WETH contract for chain %d", chain.Selector) | ||
|
|
||
| wethInstance, err := weth9.NewWETH9(common.HexToAddress(wethContract.Address), chain.Client) | ||
| require.NoErrorf(t, err, "failed to bind WETH contract %s for chain %d", wethContract.Address, chain.Selector) | ||
|
|
||
| routerInstance, err := e.DataStore.Addresses().Get(datastore.NewAddressRefKey( | ||
| chain.Selector, | ||
| datastore.ContractType(router.ContractType), | ||
| semver.MustParse(router.Deploy.Version()), | ||
| "")) | ||
| require.NoErrorf(t, err, "failed to resolve router contract for chain %d", chain.Selector) | ||
|
|
||
| routerAddr := common.HexToAddress(routerInstance.Address) | ||
| funded := make(map[common.Address]struct{}, len(chain.Users)+1) | ||
|
|
||
| for _, user := range chain.Users { | ||
| ensureUserWETHBalanceAndApproval(ctx, t, logger, chain, wethInstance, routerAddr, user, requiredWETH) | ||
| funded[user.From] = struct{}{} | ||
| } | ||
|
|
||
| // SendChainMessage pre-checks DeployerKey, not the round-robin sender. | ||
| if _, ok := funded[chain.DeployerKey.From]; !ok { | ||
| ensureUserWETHBalanceAndApproval(ctx, t, logger, chain, wethInstance, routerAddr, chain.DeployerKey, requiredWETH) | ||
| } | ||
| } | ||
|
|
||
| // ensureUserWETHBalanceAndApproval makes one signing key ready to pay CCIP load fees in WETH. | ||
| func ensureUserWETHBalanceAndApproval( | ||
| ctx context.Context, | ||
| t *testing.T, | ||
| logger zerolog.Logger, | ||
| chain cldfevm.Chain, | ||
| wethInstance *weth9.WETH9, | ||
| routerAddr common.Address, | ||
| user *bind.TransactOpts, | ||
| requiredWETH *big.Int, | ||
| ) { | ||
| t.Helper() | ||
|
|
||
| oldValue := user.Value | ||
| defer func() { user.Value = oldValue }() | ||
|
|
||
| logger.Info().Str("user", user.From.String()).Msg("User address") | ||
| balance, err := chain.Client.BalanceAt(ctx, user.From, nil) | ||
| require.NoErrorf(t, err, "failed to read native balance for user %s on chain %d", user.From.String(), chain.Selector) | ||
| logger.Info().Str("balance", balance.String()).Msg("User native balance before deposit") | ||
|
|
||
| wethBalance, err := wethInstance.BalanceOf(&bind.CallOpts{Context: ctx}, user.From) | ||
| require.NoErrorf(t, err, "failed to read WETH balance for user %s on chain %d", user.From.String(), chain.Selector) | ||
| logger.Info(). | ||
| Str("wethBalance", wethBalance.String()). | ||
| Str("requiredWETH", requiredWETH.String()). | ||
| Msg("User WETH balance before deposit") | ||
|
|
||
| if wethBalance.Cmp(requiredWETH) < 0 { | ||
| depositAmount := new(big.Int).Sub(requiredWETH, wethBalance) | ||
| user.Value = depositAmount | ||
| tx1, err := wethInstance.Deposit(user) | ||
| require.NoErrorf(t, err, "failed to deposit WETH for user %s on chain %d", user.From.String(), chain.Selector) | ||
| _, err = chain.Confirm(tx1) | ||
| require.NoErrorf(t, err, "failed to confirm WETH deposit tx %s for user %s on chain %d", tx1.Hash().Hex(), user.From.String(), chain.Selector) | ||
| logger.Info().Str("depositAmount", depositAmount.String()).Msg("Deposited WETH") | ||
| } | ||
|
Farber98 marked this conversation as resolved.
|
||
|
|
||
| // Approve is non-payable; shared TransactOpts may carry stale msg.Value. | ||
| user.Value = nil | ||
| tx, err := wethInstance.Approve(user, routerAddr, requiredWETH) | ||
| require.NoErrorf(t, err, "failed to approve router %s for user %s on chain %d", routerAddr.Hex(), user.From.String(), chain.Selector) | ||
|
Farber98 marked this conversation as resolved.
|
||
| _, err = chain.Confirm(tx) | ||
| require.NoErrorf(t, err, "failed to confirm approve tx %s for user %s on chain %d", tx.Hash().Hex(), user.From.String(), chain.Selector) | ||
|
Farber98 marked this conversation as resolved.
|
||
| logger.Info().Str("approvedAmount", requiredWETH.String()).Msg("Approved WETH for router") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.