diff --git a/deployment/ccip/changeset/testhelpers/test_helpers_solana_v0_1_0.go b/deployment/ccip/changeset/testhelpers/test_helpers_solana_v0_1_0.go index 0e664d77b66..8a1b926bac8 100644 --- a/deployment/ccip/changeset/testhelpers/test_helpers_solana_v0_1_0.go +++ b/deployment/ccip/changeset/testhelpers/test_helpers_solana_v0_1_0.go @@ -80,6 +80,7 @@ import ( "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/aptos/config" ccipChangeSetSolanaV0_1_0 "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/solana_v0_1_0" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/v1_6" + "github.com/smartcontractkit/chainlink/deployment/ccip/internal/bigint" "github.com/smartcontractkit/chainlink/deployment/ccip/shared" ccipclient "github.com/smartcontractkit/chainlink/deployment/ccip/shared/client" "github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview" @@ -103,8 +104,8 @@ const ( var ( routerABI = abihelpers.MustParseABI(router.RouterABI) - DefaultLinkPrice = deployment.E18Mult(20) - DefaultWethPrice = deployment.E18Mult(4000) + DefaultLinkPrice = bigint.E18Mult(20) + DefaultWethPrice = bigint.E18Mult(4000) DefaultGasPrice = ToPackedFee(big.NewInt(8e14), big.NewInt(0)) OneCoin = new(big.Int).Mul(big.NewInt(1e18), big.NewInt(1)) @@ -1349,13 +1350,13 @@ func AddLaneWithDefaultPricesAndFeeQuoterConfig(t *testing.T, e *DeployedEnv, st tokenPrices[stateChainFrom.Weth9.Address().String()] = DefaultWethPrice case chainsel.FamilyAptos: aptosState := state.AptosChains[from] - tokenPrices[aptosState.LinkTokenAddress.StringLong()] = deployment.EDecMult(20, 28) - tokenPrices[shared.AptosAPTAddress] = deployment.EDecMult(5, 28) + tokenPrices[aptosState.LinkTokenAddress.StringLong()] = bigint.EDecMult(20, 28) + tokenPrices[shared.AptosAPTAddress] = bigint.EDecMult(5, 28) case chainsel.FamilySui: suiState := state.SuiChains[from] gasPrices[from] = big.NewInt(1e17) gasPrices[to] = big.NewInt(1e17) - tokenPrices[suiState.LinkTokenCoinMetadataId] = deployment.EDecMult(20, 28) + tokenPrices[suiState.LinkTokenCoinMetadataId] = bigint.EDecMult(20, 28) } fqCfg := v1_6.DefaultFeeQuoterDestChainConfig(true, to) diff --git a/deployment/ccip/internal/bigint/bigint.go b/deployment/ccip/internal/bigint/bigint.go new file mode 100644 index 00000000000..910053f38d7 --- /dev/null +++ b/deployment/ccip/internal/bigint/bigint.go @@ -0,0 +1,19 @@ +package bigint + +import "math/big" + +func UBigInt(i uint64) *big.Int { + return new(big.Int).SetUint64(i) +} + +func E18Mult(amount uint64) *big.Int { + return new(big.Int).Mul(UBigInt(amount), UBigInt(1e18)) +} + +// EDecMult scales amount by the number of decimals +func EDecMult(amount uint64, decimals int64) *big.Int { + return new(big.Int).Mul( + UBigInt(amount), + new(big.Int).Exp(big.NewInt(10), big.NewInt(decimals), nil), + ) +} diff --git a/deployment/ccip/shared/stateview/evm/state.go b/deployment/ccip/shared/stateview/evm/state.go index 0f5aa8474e1..989ee2bc621 100644 --- a/deployment/ccip/shared/stateview/evm/state.go +++ b/deployment/ccip/shared/stateview/evm/state.go @@ -3,6 +3,7 @@ package evm import ( "errors" "fmt" + "slices" "github.com/Masterminds/semver/v3" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -1214,10 +1215,10 @@ func validateLatestConfigOffRamp(offRamp offramp.OffRampInterface, cfg offramp.M return fmt.Errorf("offRamp %s config signers count mismatch: expected at least 3, got %d", offRamp.Address().Hex(), len(cfg.Signers)) } - if !deployment.IsAddressListUnique(cfg.Signers) { + if !isAddressListUnique(cfg.Signers) { return fmt.Errorf("offRamp %s config signers list %v is not unique", offRamp.Address().Hex(), cfg.Signers) } - if deployment.AddressListContainsEmptyAddress(cfg.Signers) { + if addressListContainsEmptyAddress(cfg.Signers) { return fmt.Errorf("offRamp %s config signers list %v contains empty address", offRamp.Address().Hex(), cfg.Signers) } } else if len(cfg.Signers) != 0 { @@ -1228,10 +1229,10 @@ func validateLatestConfigOffRamp(offRamp offramp.OffRampInterface, cfg offramp.M return fmt.Errorf("offRamp %s config transmitters count mismatch: expected at least 3, got %d", offRamp.Address().Hex(), len(cfg.Transmitters)) } - if !deployment.IsAddressListUnique(cfg.Transmitters) { + if !isAddressListUnique(cfg.Transmitters) { return fmt.Errorf("offRamp %s config transmitters list %v is not unique", offRamp.Address().Hex(), cfg.Transmitters) } - if deployment.AddressListContainsEmptyAddress(cfg.Transmitters) { + if addressListContainsEmptyAddress(cfg.Transmitters) { return fmt.Errorf("offRamp %s config transmitters list %v contains empty address", offRamp.Address().Hex(), cfg.Transmitters) } @@ -1249,3 +1250,18 @@ func validateLatestConfigOffRamp(offRamp offramp.OffRampInterface, cfg offramp.M } return nil } + +func addressListContainsEmptyAddress(addresses []common.Address) bool { + return slices.Contains(addresses, (common.Address{})) +} + +func isAddressListUnique(addresses []common.Address) bool { + addressSet := make(map[common.Address]struct{}) + for _, address := range addresses { + if _, exists := addressSet[address]; exists { + return false + } + addressSet[address] = struct{}{} + } + return true +} diff --git a/deployment/ccip/shared/token_info.go b/deployment/ccip/shared/token_info.go index 2ac862fcc07..37c22572996 100644 --- a/deployment/ccip/shared/token_info.go +++ b/deployment/ccip/shared/token_info.go @@ -10,11 +10,10 @@ import ( "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3" "github.com/smartcontractkit/chainlink-ccip/pluginconfig" + "github.com/smartcontractkit/chainlink/deployment/ccip/internal/bigint" "github.com/smartcontractkit/chainlink-common/pkg/logger" - "github.com/smartcontractkit/chainlink/deployment" - "github.com/smartcontractkit/chainlink-evm/gethwrappers/shared/generated/initial/aggregator_v3_interface" ) @@ -145,7 +144,7 @@ const ( ) var ( - MockLinkPrice = deployment.E18Mult(500) + MockLinkPrice = bigint.E18Mult(500) MockWethPrice = big.NewInt(9e8) // DescriptionToTokenSymbols maps price feed description to token descriptor DescriptionToTokenSymbols = map[string][]TokenSymbol{ diff --git a/deployment/environment.go b/deployment/environment.go index a3e924b7b44..4ea3a4e7c0a 100644 --- a/deployment/environment.go +++ b/deployment/environment.go @@ -6,7 +6,6 @@ import ( "encoding/hex" "errors" "fmt" - "math/big" "regexp" "slices" "sort" @@ -27,22 +26,6 @@ import ( "github.com/smartcontractkit/chainlink-common/keystore/corekeys/p2pkey" ) -func UBigInt(i uint64) *big.Int { - return new(big.Int).SetUint64(i) -} - -func E18Mult(amount uint64) *big.Int { - return new(big.Int).Mul(UBigInt(amount), UBigInt(1e18)) -} - -// EDecMult scales amount by the number of decimals -func EDecMult(amount uint64, decimals int64) *big.Int { - return new(big.Int).Mul( - UBigInt(amount), - new(big.Int).Exp(big.NewInt(10), big.NewInt(decimals), nil), - ) -} - type OCRConfig struct { OffchainPublicKey types2.OffchainPublicKey // For EVM-chains, this an *address*. diff --git a/deployment/environment/crib/helpers.go b/deployment/environment/crib/helpers.go index 5ba955c99c2..abc67fffc94 100644 --- a/deployment/environment/crib/helpers.go +++ b/deployment/environment/crib/helpers.go @@ -22,7 +22,6 @@ import ( cldf_evm "github.com/smartcontractkit/chainlink-deployments-framework/chain/evm" cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" - "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/environment/devenv" ) @@ -31,7 +30,9 @@ const ( ) func distributeTransmitterFunds(lggr logger.Logger, nodeInfo []devenv.Node, env cldf.Environment, evmFundingEth uint64) error { - evmFundingAmount := new(big.Int).Mul(deployment.UBigInt(evmFundingEth), deployment.UBigInt(1e18)) + evmFundingAmount := new(big.Int).Mul(new( + big.Int).SetUint64(evmFundingEth), new(big.Int).SetUint64(1e18), + ) g := new(errgroup.Group) diff --git a/deployment/environment/devenv/chain.go b/deployment/environment/devenv/chain.go index 154798f5ca4..e5e64c990b9 100644 --- a/deployment/environment/devenv/chain.go +++ b/deployment/environment/devenv/chain.go @@ -2,6 +2,7 @@ package devenv import ( "context" + "encoding/json" "errors" "fmt" "math/big" @@ -12,7 +13,9 @@ import ( "time" "github.com/aptos-labs/aptos-go-sdk" + "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/gagliardetto/solana-go" @@ -34,7 +37,7 @@ import ( cldf_tron "github.com/smartcontractkit/chainlink-deployments-framework/chain/tron" tronprovider "github.com/smartcontractkit/chainlink-deployments-framework/chain/tron/provider" cldf_chain_utils "github.com/smartcontractkit/chainlink-deployments-framework/chain/utils" - "github.com/smartcontractkit/chainlink/deployment" + "github.com/smartcontractkit/chainlink/deployment/environment/devenv/internal/kms" ) const ( @@ -115,15 +118,15 @@ func (c *ChainConfig) SetDeployerKey(pvtKeyStr *string) error { c.DeployerKey = deployer return nil } - kmsConfig, err := deployment.KMSConfigFromEnvVars() + kmsConfig, err := kms.KMSConfigFromEnvVars() if err != nil { return fmt.Errorf("failed to get kms config from env vars: %w", err) } - kmsClient, err := deployment.NewKMSClient(kmsConfig) + kmsClient, err := kms.NewKMSClient(kmsConfig) if err != nil { return fmt.Errorf("failed to create KMS client: %w", err) } - evmKMSClient := deployment.NewEVMKMSClient(kmsClient, kmsConfig.KmsDeployerKeyId) + evmKMSClient := kms.NewEVMKMSClient(kmsClient, kmsConfig.KmsDeployerKeyId) chainID, success := new(big.Int).SetString(c.ChainID, 10) if !success { return fmt.Errorf("invalid chainID %s", c.ChainID) @@ -201,7 +204,7 @@ func NewChains(ctx context.Context, logger logger.Logger, configs []ChainConfig) } blockNumber = receipt.BlockNumber.Uint64() if receipt.Status == 0 { - errReason, err := deployment.GetErrorReasonFromTx(ec, chainCfg.DeployerKey.From, tx, receipt) + errReason, err := getErrorReasonFromTx(ec, chainCfg.DeployerKey.From, tx, receipt) if err == nil && errReason != "" { return blockNumber, fmt.Errorf("tx %s reverted,error reason: %s chain %s", tx.Hash().Hex(), errReason, chainInfo.ChainName) } @@ -388,3 +391,48 @@ func (c *ChainConfig) SetAptosDeployerKey(keyString *string) error { c.AptosDeployerKey = *aptosAccount return nil } + +func getErrorReasonFromTx(client bind.ContractBackend, from common.Address, tx *types.Transaction, receipt *types.Receipt) (string, error) { + call := ethereum.CallMsg{ + From: from, + To: tx.To(), + Data: tx.Data(), + Value: tx.Value(), + Gas: tx.Gas(), + GasPrice: tx.GasPrice(), + } + _, callContractErr := client.CallContract(context.Background(), call, receipt.BlockNumber) + if callContractErr != nil { + errorReason, parsingErr := parseError(callContractErr) + // If we get no information from parsing the error, we return the original error from CallContract + if errorReason == "" { + return callContractErr.Error(), nil + } + // If the errorReason exists and we had no issues parsing it, we return it + if parsingErr == nil { + return errorReason, nil + } + } + return "", fmt.Errorf("tx %s reverted with no reason", tx.Hash().Hex()) +} + +func parseError(txError error) (string, error) { + b, err := json.Marshal(txError) + if err != nil { + return "", err + } + var callErr struct { + Code int + Data string `json:"data"` + Message string `json:"message"` + } + if json.Unmarshal(b, &callErr) != nil { + return "", err + } + + if callErr.Data == "" && strings.Contains(callErr.Message, "missing trie node") { + return "", errors.New("please use an archive node") + } + + return callErr.Data, nil +} diff --git a/deployment/evm_kmsclient.go b/deployment/environment/devenv/internal/kms/kms_client.go similarity index 99% rename from deployment/evm_kmsclient.go rename to deployment/environment/devenv/internal/kms/kms_client.go index e5edc3031a2..3c555da07f3 100644 --- a/deployment/evm_kmsclient.go +++ b/deployment/environment/devenv/internal/kms/kms_client.go @@ -1,4 +1,4 @@ -package deployment +package kms import ( "bytes" diff --git a/deployment/evm_kmsclient_test.go b/deployment/environment/devenv/internal/kms/kms_client_test.go similarity index 98% rename from deployment/evm_kmsclient_test.go rename to deployment/environment/devenv/internal/kms/kms_client_test.go index f4917722839..c4e7300aa2b 100644 --- a/deployment/evm_kmsclient_test.go +++ b/deployment/environment/devenv/internal/kms/kms_client_test.go @@ -1,4 +1,4 @@ -package deployment +package kms import ( "encoding/hex" diff --git a/deployment/helpers.go b/deployment/helpers.go deleted file mode 100644 index 691395b7a29..00000000000 --- a/deployment/helpers.go +++ /dev/null @@ -1,122 +0,0 @@ -package deployment - -import ( - "context" - "encoding/json" - "errors" - "fmt" - "slices" - "strings" - - "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" - - "github.com/smartcontractkit/chainlink-deployments-framework/datastore" - cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" -) - -func GetErrorReasonFromTx(client bind.ContractBackend, from common.Address, tx *types.Transaction, receipt *types.Receipt) (string, error) { - call := ethereum.CallMsg{ - From: from, - To: tx.To(), - Data: tx.Data(), - Value: tx.Value(), - Gas: tx.Gas(), - GasPrice: tx.GasPrice(), - } - _, callContractErr := client.CallContract(context.Background(), call, receipt.BlockNumber) - if callContractErr != nil { - errorReason, parsingErr := parseError(callContractErr) - // If we get no information from parsing the error, we return the original error from CallContract - if errorReason == "" { - return callContractErr.Error(), nil - } - // If the errorReason exists and we had no issues parsing it, we return it - if parsingErr == nil { - return errorReason, nil - } - } - return "", fmt.Errorf("tx %s reverted with no reason", tx.Hash().Hex()) -} - -func parseError(txError error) (string, error) { - b, err := json.Marshal(txError) - if err != nil { - return "", err - } - var callErr struct { - Code int - Data string `json:"data"` - Message string `json:"message"` - } - if json.Unmarshal(b, &callErr) != nil { - return "", err - } - - if callErr.Data == "" && strings.Contains(callErr.Message, "missing trie node") { - return "", errors.New("please use an archive node") - } - - return callErr.Data, nil -} - -func ValidateSelectorsInEnvironment(e cldf.Environment, chains []uint64) error { - for _, chain := range chains { - if !e.BlockChains.Exists(chain) { - return fmt.Errorf("chain %d not found in environment", chain) - } - } - return nil -} - -func IsAddressListUnique(addresses []common.Address) bool { - addressSet := make(map[common.Address]struct{}) - for _, address := range addresses { - if _, exists := addressSet[address]; exists { - return false - } - addressSet[address] = struct{}{} - } - return true -} - -func AddressListContainsEmptyAddress(addresses []common.Address) bool { - return slices.Contains(addresses, (common.Address{})) -} - -func MigrateAddressBook(addrBook cldf.AddressBook) (datastore.MutableDataStore, error) { - addrs, err := addrBook.Addresses() - if err != nil { - return nil, err - } - - ds := datastore.NewMemoryDataStore() - - for chainSelector, chainAddresses := range addrs { - for addr, typever := range chainAddresses { - ref := datastore.AddressRef{ - ChainSelector: chainSelector, - Address: addr, - Type: datastore.ContractType(typever.Type), - Version: &typever.Version, - // Since the address book does not have a qualifier, we use the address and type as a - // unique identifier for the addressRef. Otherwise, we would have some clashes in the - // between address refs. - Qualifier: fmt.Sprintf("%s-%s", addr, typever.Type), - } - - // If the address book has labels, we need to add them to the addressRef - if !typever.Labels.IsEmpty() { - ref.Labels = datastore.NewLabelSet(typever.Labels.List()...) - } - - if err = ds.Addresses().Add(ref); err != nil { - return nil, err - } - } - } - - return ds, nil -} diff --git a/deployment/labeled_addresses.go b/deployment/keystone/changeset/internal/addrbook/addrbook.go similarity index 73% rename from deployment/labeled_addresses.go rename to deployment/keystone/changeset/internal/addrbook/addrbook.go index bb7a50da636..1a29edd2e6c 100644 --- a/deployment/labeled_addresses.go +++ b/deployment/keystone/changeset/internal/addrbook/addrbook.go @@ -1,9 +1,16 @@ -package deployment +// Package addrbook provides a way to filter addresses based on labels. +// +// Addressbook is depcreated but this remains as a temporary solution +// for backwards compatibility. -import cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" +package addrbook + +import ( + "github.com/smartcontractkit/chainlink-deployments-framework/deployment" +) // LabeledAddresses is an alias to a map whose keys are contract addresses -type LabeledAddresses map[string]cldf.TypeAndVersion +type LabeledAddresses map[string]deployment.TypeAndVersion // And filters the LabeledAddresses to only include those entries that contain all // labels. If labels is empty, then only unlabeled entries are returned. diff --git a/deployment/labeled_addresses_test.go b/deployment/keystone/changeset/internal/addrbook/addrbook_test.go similarity index 77% rename from deployment/labeled_addresses_test.go rename to deployment/keystone/changeset/internal/addrbook/addrbook_test.go index c4c4fe0b2ab..35047712fd1 100644 --- a/deployment/labeled_addresses_test.go +++ b/deployment/keystone/changeset/internal/addrbook/addrbook_test.go @@ -1,4 +1,4 @@ -package deployment +package addrbook import ( "testing" @@ -6,7 +6,7 @@ import ( "github.com/Masterminds/semver/v3" "github.com/stretchr/testify/require" - cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" + "github.com/smartcontractkit/chainlink-deployments-framework/deployment" ) func TestLabeledAddresses_And(t *testing.T) { @@ -20,7 +20,7 @@ func TestLabeledAddresses_And(t *testing.T) { name: "No labels returns unlabeled", give: LabeledAddresses{ "addr1": {Type: "type1", Version: *semver.MustParse("1.0.0"), Labels: nil}, - "addr2": {Type: "type2", Version: *semver.MustParse("2.0.0"), Labels: cldf.NewLabelSet("label1")}, + "addr2": {Type: "type2", Version: *semver.MustParse("2.0.0"), Labels: deployment.NewLabelSet("label1")}, }, labels: nil, want: LabeledAddresses{ @@ -30,26 +30,26 @@ func TestLabeledAddresses_And(t *testing.T) { { name: "One label", give: LabeledAddresses{ - "addr1": {Type: "type1", Version: *semver.MustParse("1.0.0"), Labels: cldf.NewLabelSet("label1")}, - "addr2": {Type: "type2", Version: *semver.MustParse("2.0.0"), Labels: cldf.NewLabelSet("label2")}, - "addr3": {Type: "type3", Version: *semver.MustParse("3.0.0"), Labels: cldf.NewLabelSet("label1", "label2")}, + "addr1": {Type: "type1", Version: *semver.MustParse("1.0.0"), Labels: deployment.NewLabelSet("label1")}, + "addr2": {Type: "type2", Version: *semver.MustParse("2.0.0"), Labels: deployment.NewLabelSet("label2")}, + "addr3": {Type: "type3", Version: *semver.MustParse("3.0.0"), Labels: deployment.NewLabelSet("label1", "label2")}, }, labels: []string{"label1"}, want: LabeledAddresses{ - "addr1": {Type: "type1", Version: *semver.MustParse("1.0.0"), Labels: cldf.NewLabelSet("label1")}, - "addr3": {Type: "type3", Version: *semver.MustParse("3.0.0"), Labels: cldf.NewLabelSet("label1", "label2")}, + "addr1": {Type: "type1", Version: *semver.MustParse("1.0.0"), Labels: deployment.NewLabelSet("label1")}, + "addr3": {Type: "type3", Version: *semver.MustParse("3.0.0"), Labels: deployment.NewLabelSet("label1", "label2")}, }, }, { name: "Multiple labels", give: LabeledAddresses{ - "addr1": {Type: "type1", Version: *semver.MustParse("1.0.0"), Labels: cldf.NewLabelSet("label1", "label2")}, - "addr2": {Type: "type2", Version: *semver.MustParse("2.0.0"), Labels: cldf.NewLabelSet("label1")}, - "addr3": {Type: "type3", Version: *semver.MustParse("3.0.0"), Labels: cldf.NewLabelSet("label2")}, + "addr1": {Type: "type1", Version: *semver.MustParse("1.0.0"), Labels: deployment.NewLabelSet("label1", "label2")}, + "addr2": {Type: "type2", Version: *semver.MustParse("2.0.0"), Labels: deployment.NewLabelSet("label1")}, + "addr3": {Type: "type3", Version: *semver.MustParse("3.0.0"), Labels: deployment.NewLabelSet("label2")}, }, labels: []string{"label1", "label2"}, want: LabeledAddresses{ - "addr1": {Type: "type1", Version: *semver.MustParse("1.0.0"), Labels: cldf.NewLabelSet("label1", "label2")}, + "addr1": {Type: "type1", Version: *semver.MustParse("1.0.0"), Labels: deployment.NewLabelSet("label1", "label2")}, }, }, { @@ -61,7 +61,7 @@ func TestLabeledAddresses_And(t *testing.T) { { name: "No matching labels", give: LabeledAddresses{ - "addr1": {Type: "type1", Version: *semver.MustParse("1.0.0"), Labels: cldf.NewLabelSet("label1")}, + "addr1": {Type: "type1", Version: *semver.MustParse("1.0.0"), Labels: deployment.NewLabelSet("label1")}, }, labels: []string{"label2"}, want: LabeledAddresses{}, diff --git a/deployment/keystone/changeset/internal/state.go b/deployment/keystone/changeset/internal/state.go index e052c5be2bf..1f782ccc6ac 100644 --- a/deployment/keystone/changeset/internal/state.go +++ b/deployment/keystone/changeset/internal/state.go @@ -12,8 +12,8 @@ import ( cldf_evm "github.com/smartcontractkit/chainlink-deployments-framework/chain/evm" cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" - "github.com/smartcontractkit/chainlink/deployment" commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal/addrbook" capabilities_registry "github.com/smartcontractkit/chainlink-evm/gethwrappers/keystone/generated/capabilities_registry_1_1_0" forwarder "github.com/smartcontractkit/chainlink-evm/gethwrappers/keystone/generated/forwarder_1_0_0" @@ -74,7 +74,7 @@ func GetContractSets(lggr logger.Logger, req *GetContractSetsRequest) (*GetContr // TODO: we need to expand/refactor the way labeled addresses are filtered // see: https://smartcontract-it.atlassian.net/browse/CRE-363 - filtered := deployment.LabeledAddresses(addrs).And(req.Labels...) + filtered := addrbook.LabeledAddresses(addrs).And(req.Labels...) maps.Copy(filtered, forwarderAddrs) diff --git a/deployment/keystone/changeset/state.go b/deployment/keystone/changeset/state.go index 6ff55bbdde8..3ad887383c4 100644 --- a/deployment/keystone/changeset/state.go +++ b/deployment/keystone/changeset/state.go @@ -12,9 +12,9 @@ import ( cldf_evm "github.com/smartcontractkit/chainlink-deployments-framework/chain/evm" cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" - "github.com/smartcontractkit/chainlink/deployment" commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal" + "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal/addrbook" capabilities_registry "github.com/smartcontractkit/chainlink-evm/gethwrappers/keystone/generated/capabilities_registry_1_1_0" forwarder "github.com/smartcontractkit/chainlink-evm/gethwrappers/keystone/generated/forwarder_1_0_0" @@ -102,7 +102,7 @@ func GetContractSets(lggr logger.Logger, req *GetContractSetsRequest) (*GetContr // TODO: we need to expand/refactor the way labeled addresses are filtered // see: https://smartcontract-it.atlassian.net/browse/CRE-363 - filtered := deployment.LabeledAddresses(addrs).And(req.Labels...) + filtered := addrbook.LabeledAddresses(addrs).And(req.Labels...) maps.Copy(filtered, forwarderAddrs) diff --git a/deployment/ton_chain.go b/deployment/ton_chain.go deleted file mode 100644 index e265feff3f4..00000000000 --- a/deployment/ton_chain.go +++ /dev/null @@ -1,17 +0,0 @@ -package deployment - -import ( - "github.com/xssnick/tonutils-go/address" - "github.com/xssnick/tonutils-go/ton" - "github.com/xssnick/tonutils-go/ton/wallet" -) - -// TonChain represents a TON chain. -type TonChain struct { - Selector uint64 // Canonical chain identifier - Client *ton.APIClient // RPC client via Lite Server - Wallet *wallet.Wallet // Wallet abstraction (signing, sending) - WalletAddress *address.Address // Address of deployer wallet - URL string // Liteserver URL - DeployerSeed string // Optional: mnemonic or raw seed -} diff --git a/integration-tests/load/ccip/helpers.go b/integration-tests/load/ccip/helpers.go index f69d6cbfdf9..a4c1db3392c 100644 --- a/integration-tests/load/ccip/helpers.go +++ b/integration-tests/load/ccip/helpers.go @@ -27,11 +27,11 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" + "github.com/smartcontractkit/chainlink/integration-tests/utils/bigint" "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_6_0/nonce_manager" "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_6_0/offramp" "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_6_0/onramp" - "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers" "github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview" "github.com/smartcontractkit/chainlink/deployment/environment/crib" @@ -46,7 +46,7 @@ const ( ) var ( - fundingAmount = new(big.Int).Mul(deployment.UBigInt(100), deployment.UBigInt(1e18)) // 100 eth + fundingAmount = new(big.Int).Mul(bigint.UBigInt(100), bigint.UBigInt(1e18)) // 100 eth ) type finalSeqNrReport struct { diff --git a/integration-tests/smoke/ccip/ccip_aptos_messaging_test.go b/integration-tests/smoke/ccip/ccip_aptos_messaging_test.go index 697753968e1..e35901584c2 100644 --- a/integration-tests/smoke/ccip/ccip_aptos_messaging_test.go +++ b/integration-tests/smoke/ccip/ccip_aptos_messaging_test.go @@ -23,12 +23,12 @@ import ( "github.com/smartcontractkit/chainlink-deployments-framework/chain" cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" - "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers" mlt "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers/messagelimitationstest" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers/messagingtest" "github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview" testsetups "github.com/smartcontractkit/chainlink/integration-tests/testsetups/ccip" + "github.com/smartcontractkit/chainlink/integration-tests/utils/bigint" "github.com/smartcontractkit/chainlink/v2/core/logger" ) @@ -89,7 +89,7 @@ func Test_CCIP_Messaging_EVM2Aptos(t *testing.T) { require.NoError(t, err) // mint token and approve to router - tx, err = evmLinkToken.Mint(e.Env.BlockChains.EVMChains()[sourceChain].DeployerKey, common.BytesToAddress(sender), deployment.E18Mult(10_000)) + tx, err = evmLinkToken.Mint(e.Env.BlockChains.EVMChains()[sourceChain].DeployerKey, common.BytesToAddress(sender), bigint.E18Mult(10_000)) _, err = cldf.ConfirmIfNoError(e.Env.BlockChains.EVMChains()[sourceChain], tx, err) require.NoError(t, err) @@ -99,7 +99,7 @@ func Test_CCIP_Messaging_EVM2Aptos(t *testing.T) { // Deposit 1 ETH to get WETH wethTransactOpts := *e.Env.BlockChains.EVMChains()[sourceChain].DeployerKey - wethTransactOpts.Value = deployment.E18Mult(1) + wethTransactOpts.Value = bigint.E18Mult(1) tx, err = wethToken.Deposit(&wethTransactOpts) _, err = cldf.ConfirmIfNoError(e.Env.BlockChains.EVMChains()[sourceChain], tx, err) require.NoError(t, err) diff --git a/integration-tests/smoke/ccip/ccip_disable_lane_test.go b/integration-tests/smoke/ccip/ccip_disable_lane_test.go index f05ec3a2f0d..e819c83a249 100644 --- a/integration-tests/smoke/ccip/ccip_disable_lane_test.go +++ b/integration-tests/smoke/ccip/ccip_disable_lane_test.go @@ -13,12 +13,12 @@ import ( "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_6_0/onramp" cldf_chain "github.com/smartcontractkit/chainlink-deployments-framework/chain" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" - "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/v1_6" ccipclient "github.com/smartcontractkit/chainlink/deployment/ccip/shared/client" "github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview" testsetups "github.com/smartcontractkit/chainlink/integration-tests/testsetups/ccip" + "github.com/smartcontractkit/chainlink/integration-tests/utils/bigint" ) // Intention of this test is to ensure that the lane can be disabled and enabled correctly @@ -43,8 +43,8 @@ func TestDisableLane(t *testing.T) { expectedSeqNumExec = make(map[testhelpers.SourceDestPair][]uint64) startBlocks = make(map[uint64]*uint64) pairs []testhelpers.SourceDestPair - linkPrice = deployment.E18Mult(100) - wethPrice = deployment.E18Mult(4000) + linkPrice = bigint.E18Mult(100) + wethPrice = bigint.E18Mult(4000) noOfRequests = 3 sendmessage = func(src, dest uint64, deployer *bind.TransactOpts) (*onramp.OnRampCCIPMessageSent, error) { out, err := testhelpers.SendRequest( diff --git a/integration-tests/smoke/ccip/ccip_fees_test.go b/integration-tests/smoke/ccip/ccip_fees_test.go index ff5bed3a2ee..2fec0775b54 100644 --- a/integration-tests/smoke/ccip/ccip_fees_test.go +++ b/integration-tests/smoke/ccip/ccip_fees_test.go @@ -21,11 +21,11 @@ import ( cldf_chain "github.com/smartcontractkit/chainlink-deployments-framework/chain" cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" - "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers/feestest" "github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview" testsetups "github.com/smartcontractkit/chainlink/integration-tests/testsetups/ccip" + "github.com/smartcontractkit/chainlink/integration-tests/utils/bigint" "github.com/smartcontractkit/chainlink/v2/core/logger" ) @@ -58,7 +58,7 @@ func setupNewFeeToken( require.NoError(t, err) // mint token and approve to router - tx, err = token.Mint(deployer, deployer.From, deployment.E18Mult(10_000)) + tx, err = token.Mint(deployer, deployer.From, bigint.E18Mult(10_000)) _, err = cldf.ConfirmIfNoError(chain, tx, err) require.NoError(t, err) @@ -192,8 +192,8 @@ func Test_CCIPFees(t *testing.T) { tenv, sourceChain, destChain, - deployment.E18Mult(10_000), - deployment.E18Mult(10_000), + bigint.E18Mult(10_000), + bigint.E18Mult(10_000), ) // Ensure capreg logs are up to date. @@ -212,7 +212,7 @@ func Test_CCIPFees(t *testing.T) { []router.ClientEVMTokenAmount{ { Token: srcToken.Address(), - Amount: deployment.E18Mult(2), + Amount: bigint.E18Mult(2), }, }, srcToken, @@ -235,7 +235,7 @@ func Test_CCIPFees(t *testing.T) { []router.ClientEVMTokenAmount{ { Token: dstToken.Address(), - Amount: deployment.E18Mult(2), + Amount: bigint.E18Mult(2), }, }, // note the order of src and dest is reversed here @@ -259,7 +259,7 @@ func Test_CCIPFees(t *testing.T) { []router.ClientEVMTokenAmount{ { Token: srcToken.Address(), - Amount: deployment.E18Mult(2), + Amount: bigint.E18Mult(2), }, }, srcToken, @@ -281,7 +281,7 @@ func Test_CCIPFees(t *testing.T) { []router.ClientEVMTokenAmount{ { Token: srcToken.Address(), - Amount: deployment.E18Mult(2), + Amount: bigint.E18Mult(2), }, }, srcToken, @@ -308,7 +308,7 @@ func Test_CCIPFees(t *testing.T) { TokenAmounts: []router.ClientEVMTokenAmount{ { Token: srcToken.Address(), - Amount: deployment.E18Mult(100_000_000), + Amount: bigint.E18Mult(100_000_000), }, }, FeeToken: feeToken, diff --git a/integration-tests/smoke/ccip/ccip_message_limitations_test.go b/integration-tests/smoke/ccip/ccip_message_limitations_test.go index 6867fb86616..49ef7bf3200 100644 --- a/integration-tests/smoke/ccip/ccip_message_limitations_test.go +++ b/integration-tests/smoke/ccip/ccip_message_limitations_test.go @@ -15,11 +15,11 @@ import ( "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_2_0/router" - "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers" mlt "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers/messagelimitationstest" "github.com/smartcontractkit/chainlink/deployment/ccip/shared/stateview" testsetups "github.com/smartcontractkit/chainlink/integration-tests/testsetups/ccip" + "github.com/smartcontractkit/chainlink/integration-tests/utils/bigint" ) func Test_CCIPMessageLimitations(t *testing.T) { @@ -40,8 +40,8 @@ func Test_CCIPMessageLimitations(t *testing.T) { testEnv, chains[0], chains[1], - deployment.E18Mult(10_000), - deployment.E18Mult(10_000), + bigint.E18Mult(10_000), + bigint.E18Mult(10_000), ) sourceChainFeeQuoterDestinationChainConfig, err := onChainState.MustGetEVMChainState(chains[0]).FeeQuoter.GetDestChainConfig(callOpts, chains[1]) diff --git a/integration-tests/utils/bigint/bigint.go b/integration-tests/utils/bigint/bigint.go new file mode 100644 index 00000000000..910053f38d7 --- /dev/null +++ b/integration-tests/utils/bigint/bigint.go @@ -0,0 +1,19 @@ +package bigint + +import "math/big" + +func UBigInt(i uint64) *big.Int { + return new(big.Int).SetUint64(i) +} + +func E18Mult(amount uint64) *big.Int { + return new(big.Int).Mul(UBigInt(amount), UBigInt(1e18)) +} + +// EDecMult scales amount by the number of decimals +func EDecMult(amount uint64, decimals int64) *big.Int { + return new(big.Int).Mul( + UBigInt(amount), + new(big.Int).Exp(big.NewInt(10), big.NewInt(decimals), nil), + ) +}