Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))
Expand Down Expand Up @@ -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)

Expand Down
19 changes: 19 additions & 0 deletions deployment/ccip/internal/bigint/bigint.go
Original file line number Diff line number Diff line change
@@ -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),
)
}
24 changes: 20 additions & 4 deletions deployment/ccip/shared/stateview/evm/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package evm
import (
"errors"
"fmt"
"slices"

"github.com/Masterminds/semver/v3"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}

Expand All @@ -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
}
5 changes: 2 additions & 3 deletions deployment/ccip/shared/token_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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{
Expand Down
17 changes: 0 additions & 17 deletions deployment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"math/big"
"regexp"
"slices"
"sort"
Expand All @@ -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*.
Expand Down
5 changes: 3 additions & 2 deletions deployment/environment/crib/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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),
)
Comment on lines +33 to +35

g := new(errgroup.Group)

Expand Down
58 changes: 53 additions & 5 deletions deployment/environment/devenv/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package devenv

import (
"context"
"encoding/json"
"errors"
"fmt"
"math/big"
Expand All @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Comment on lines +429 to +431

if callErr.Data == "" && strings.Contains(callErr.Message, "missing trie node") {
return "", errors.New("please use an archive node")
}

return callErr.Data, nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package deployment
package kms

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package deployment
package kms

import (
"encoding/hex"
Expand Down
Loading
Loading