Skip to content

Commit

Permalink
Merge branch 'main' into latest-released-awm-relayer
Browse files Browse the repository at this point in the history
  • Loading branch information
arturrez authored Oct 21, 2024
2 parents 420a2d9 + 5bfbdec commit aef0aec
Show file tree
Hide file tree
Showing 45 changed files with 501 additions and 345 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
pull_request:
workflow_call:

jobs:
lint:
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
tags:
- "*"
branches:
- acp-77

jobs:
# First confirm that the linting and unit tests pass at this commit prior to creating release artifacts.
Expand Down Expand Up @@ -59,14 +61,24 @@ jobs:

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Build Docker Image with acp77-latest tag
if: github.ref == 'refs/heads/acp-77' # special case for acp-77 branch
run: |
docker buildx build --pull --push --platform=linux/amd64,linux/arm64 \
-t avaplatform/avalanche-cli:acp77-latest \
-f ./Dockerfile .
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TELEMETRY_TOKEN: ${{ secrets.POSTHOG_PROD_TOKEN }}

- name: Run GoReleaser
if: github.ref != 'refs/heads/acp-77' # skip for acp-77 branch
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --clean
workdir: ./avalanche-cli/
env:
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
pull_request:
workflow_call:

jobs:
unit_test:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ pkg/contract/contracts/remappings.txt
pkg/contract/contracts/lib/
pkg/contract/contracts/cache/
pkg/contract/contracts/out/

osxcross/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============= Compilation Stage ================
FROM golang:1.20-bullseye AS builder
FROM golang:1.22.7-bullseye AS builder

WORKDIR /build
# Copy and download avalanche dependencies using go mod
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.5
1.7.7
Binary file added assets/bootstrapSnapshot.PreDurango12.tar.gz
Binary file not shown.
Binary file modified assets/bootstrapSnapshot.tar.gz
Binary file not shown.
Binary file not shown.
Binary file modified assets/bootstrapSnapshotSingleNode.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions assets/sha256sum.PreDurango12.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
811e73be1ad9b56f05a14ca6d239ee50bc3882fa10fdb2f78d41b02fb81ac6fe assets/bootstrapSnapshot.PreDurango12.tar.gz
2 changes: 1 addition & 1 deletion assets/sha256sum.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
811e73be1ad9b56f05a14ca6d239ee50bc3882fa10fdb2f78d41b02fb81ac6fe assets/bootstrapSnapshot.tar.gz
26b07c304da467d3a28ebc936f5b44c5f27f65b0a626da81fabe9154a821ec24 assets/bootstrapSnapshot.tar.gz
1 change: 1 addition & 0 deletions assets/sha256sumSingleNode.PreDurango12.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
53ef0b4c6ef6bd54e07bd065d58164bd464cd46576d36230731c93d3cc254df9 assets/bootstrapSnapshotSingleNode.PreDurango12.tar.gz
2 changes: 1 addition & 1 deletion assets/sha256sumSingleNode.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
53ef0b4c6ef6bd54e07bd065d58164bd464cd46576d36230731c93d3cc254df9 assets/bootstrapSnapshotSingleNode.tar.gz
ec7332442743b1943e298d7301b8962948ae104edb78f70b5cad30376b60557c assets/bootstrapSnapshotSingleNode.tar.gz
5 changes: 2 additions & 3 deletions cmd/blockchaincmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {

// subnet-evm check based on genesis
// covers both subnet-evm vms and custom vms
if hasSubnetEVMGenesis, rawErr, err := app.HasSubnetEVMGenesis(blockchainName); rawErr != nil {
return rawErr
} else if err != nil {
if hasSubnetEVMGenesis, _, err := app.HasSubnetEVMGenesis(blockchainName); err != nil {
return err
} else if hasSubnetEVMGenesis && createFlags.enableDebugging {
if err := SetBlockchainConf(
Expand All @@ -379,6 +377,7 @@ func createBlockchainConfig(cmd *cobra.Command, args []string) error {
if err = app.CreateSidecar(sc); err != nil {
return err
}

if vmType == models.SubnetEvm {
err = sendMetrics(cmd, vmType.RepoName(), blockchainName)
if err != nil {
Expand Down
99 changes: 57 additions & 42 deletions cmd/interchaincmd/tokentransferrercmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"time"

cmdflags "github.com/ava-labs/avalanche-cli/cmd/flags"
"github.com/ava-labs/avalanche-cli/pkg/application"
"github.com/ava-labs/avalanche-cli/pkg/cobrautils"
"github.com/ava-labs/avalanche-cli/pkg/constants"
"github.com/ava-labs/avalanche-cli/pkg/contract"
"github.com/ava-labs/avalanche-cli/pkg/ictt"
"github.com/ava-labs/avalanche-cli/pkg/models"
"github.com/ava-labs/avalanche-cli/pkg/networkoptions"
"github.com/ava-labs/avalanche-cli/pkg/precompiles"
"github.com/ava-labs/avalanche-cli/pkg/prompts"
Expand Down Expand Up @@ -101,6 +103,43 @@ func deploy(_ *cobra.Command, args []string) error {
return CallDeploy(args, deployFlags)
}

func getHomeKeyAndAddress(app *application.Avalanche, network models.Network, homeFlags HomeFlags) (string, string, error) {
// First check if there is a genesis key able to be used.
genesisAddress, genesisPrivateKey, err := contract.GetEVMSubnetPrefundedKey(
app,
network,
homeFlags.chainFlags,
)
if err != nil {
return "", "", err
}

// Propmt for the key to be used.
// Note that this key must have enough funds to cover gas cost on the
// home chain, and also enough of the token on the home chain to collateralize
// the remote chain if it is a native token remote.
homeKey, err := prompts.PromptPrivateKey(
app.Prompt,
"pay for home deployment fees, and collateralization (if necessary)",
app.GetKeyDir(),
app.GetKey,
genesisAddress,
genesisPrivateKey,
)
if err != nil {
return "", "", err
}

// Calculate the address for the key.
pk, err := crypto.HexToECDSA(homeKey)
if err != nil {
return "", "", err
}
homeKeyAddress := crypto.PubkeyToAddress(pk.PublicKey).Hex()

return homeKey, homeKeyAddress, nil
}

func CallDeploy(_ []string, flags DeployFlags) error {
if !ictt.FoundryIsInstalled() {
if err := ictt.InstallFoundry(); err != nil {
Expand Down Expand Up @@ -304,41 +343,11 @@ func CallDeploy(_ []string, flags DeployFlags) error {
}
}

var (
homeKey string
homeKeyAddress string
)
if flags.homeFlags.homeAddress == "" {
genesisAddress, genesisPrivateKey, err := contract.GetEVMSubnetPrefundedKey(
app,
network,
flags.homeFlags.chainFlags,
)
if err != nil {
return err
}
homeKey, err = flags.homeFlags.privateKeyFlags.GetPrivateKey(app, genesisPrivateKey)
if err != nil {
return err
}
if homeKey == "" {
homeKey, err = prompts.PromptPrivateKey(
app.Prompt,
"pay for home deploy fees",
app.GetKeyDir(),
app.GetKey,
genesisAddress,
genesisPrivateKey,
)
if err != nil {
return err
}
}
pk, err := crypto.HexToECDSA(homeKey)
if err != nil {
return err
}
homeKeyAddress = crypto.PubkeyToAddress(pk.PublicKey).Hex()
// Get the key to be used to deploy the token home contract and collateralize the remote
// in the case that it is a native token remote.
homeKey, homeKeyAddress, err := getHomeKeyAndAddress(app, network, flags.homeFlags)
if err != nil {
return err
}

// Home Contract Validations
Expand Down Expand Up @@ -483,7 +492,6 @@ func CallDeploy(_ []string, flags DeployFlags) error {
if err := ictt.BuildContracts(app); err != nil {
return err
}
ux.Logger.PrintToUser("")

// Home Deploy
icttSrcDir, err := ictt.RepoDir(app)
Expand Down Expand Up @@ -667,8 +675,10 @@ func CallDeploy(_ []string, flags DeployFlags) error {
return err
}
}
ux.Logger.PrintToUser("Remote Deployed to %s", remoteRPCEndpoint)
ux.Logger.PrintToUser("Remote Address: %s", remoteAddress)

if err := ictt.RegisterERC20Remote(
if err := ictt.RegisterRemote(
remoteRPCEndpoint,
remoteKey,
remoteAddress,
Expand All @@ -679,6 +689,7 @@ func CallDeploy(_ []string, flags DeployFlags) error {
checkInterval := 100 * time.Millisecond
checkTimeout := 10 * time.Second
t0 := time.Now()
var collateralNeeded *big.Int
for {
registeredRemote, err := ictt.TokenHomeGetRegisteredRemote(
homeRPCEndpoint,
Expand All @@ -690,6 +701,7 @@ func CallDeploy(_ []string, flags DeployFlags) error {
return err
}
if registeredRemote.Registered {
collateralNeeded = registeredRemote.CollateralNeeded
break
}
elapsed := time.Since(t0)
Expand All @@ -699,19 +711,21 @@ func CallDeploy(_ []string, flags DeployFlags) error {
time.Sleep(checkInterval)
}

if flags.remoteFlags.native {
// Collateralize the remote contract on the home contract if necessary
if collateralNeeded.Cmp(big.NewInt(0)) != 0 {
err = ictt.TokenHomeAddCollateral(
homeRPCEndpoint,
homeAddress,
homeKey,
remoteBlockchainID,
remoteAddress,
remoteSupply,
collateralNeeded,
)
if err != nil {
return err
}

// Check that the remote is collateralized on the home contract now.
registeredRemote, err := ictt.TokenHomeGetRegisteredRemote(
homeRPCEndpoint,
homeAddress,
Expand All @@ -724,7 +738,10 @@ func CallDeploy(_ []string, flags DeployFlags) error {
if registeredRemote.CollateralNeeded.Cmp(big.NewInt(0)) != 0 {
return fmt.Errorf("failure setting collateral in home endpoint: remaining collateral=%d", registeredRemote.CollateralNeeded)
}
}

if flags.remoteFlags.native {
ux.Logger.PrintToUser("Enabling native token remote contract to mint native tokens")
if err := precompiles.SetEnabled(
remoteRPCEndpoint,
precompiles.NativeMinterPrecompile,
Expand All @@ -734,6 +751,7 @@ func CallDeploy(_ []string, flags DeployFlags) error {
return err
}

// Send a single token unit to report that the remote is collateralized.
err = ictt.Send(
homeRPCEndpoint,
homeAddress,
Expand Down Expand Up @@ -785,8 +803,5 @@ func CallDeploy(_ []string, flags DeployFlags) error {
}
}

ux.Logger.PrintToUser("Remote Deployed to %s", remoteRPCEndpoint)
ux.Logger.PrintToUser("Remote Address: %s", remoteAddress)

return nil
}
56 changes: 36 additions & 20 deletions cmd/keycmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,28 +558,44 @@ func getEvmBasedChainAddrInfo(
if err != nil {
return addressInfos, err
}

// Ignore contract address access errors as those may depend on network
tokenSymbol, err := token.Symbol(nil)
if err == nil {
// just ignore contract address access errors as those may depend on network
balance, err := token.BalanceOf(nil, common.HexToAddress(cChainAddr))
if err != nil {
return addressInfos, err
}
formattedBalance, err := formatCChainBalance(balance)
if err != nil {
return addressInfos, err
}
info := addressInfo{
kind: kind,
name: name,
chain: chainName,
token: fmt.Sprintf("%s (%s.)", tokenSymbol, tokenAddress[:6]),
address: cChainAddr,
balance: formattedBalance,
network: network.Name(),
}
addressInfos = append(addressInfos, info)
if err != nil {
continue
}

// Get the raw balance for the given token.
balance, err := token.BalanceOf(nil, common.HexToAddress(cChainAddr))
if err != nil {
return addressInfos, err
}

// Get the decimal count for the token to format the balance.
// Note: decimals() is not officially part of the IERC20 interface, but is a common extension.
decimals, err := token.Decimals(nil)
if err != nil {
return addressInfos, err
}

// Format the balance to a human-readable string.
var formattedBalance string
if useGwei {
formattedBalance = fmt.Sprintf("%d", balance)
} else {
formattedBalance = utils.FormatAmount(balance, decimals)
}

info := addressInfo{
kind: kind,
name: name,
chain: chainName,
token: fmt.Sprintf("%s (%s.)", tokenSymbol, tokenAddress[:6]),
address: cChainAddr,
balance: formattedBalance,
network: network.Name(),
}
addressInfos = append(addressInfos, info)
}
}
return addressInfos, nil
Expand Down
19 changes: 17 additions & 2 deletions cmd/keycmd/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
avmtxs "github.com/ava-labs/avalanchego/vms/avm/txs"
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
avagofee "github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
Expand Down Expand Up @@ -426,9 +427,9 @@ func transferF(*cobra.Command, []string) error {
var useLedger bool
goalStr := ""
if send {
goalStr = " for the sender address"
goalStr = "as the sender address"
} else {
goalStr = " for the destination address"
goalStr = "as the destination address"
}
useLedger, keyName, err = prompts.GetKeyOrLedger(app.Prompt, goalStr, app.GetKeyDir(), true)
if err != nil {
Expand Down Expand Up @@ -598,6 +599,20 @@ func transferF(*cobra.Command, []string) error {
return fmt.Errorf("error signing tx: %w", err)
}

pContext := wallet.P().Builder().Context()
var pFeeCalculator avagofee.Calculator
if pContext.GasPrice != 0 {
pFeeCalculator = avagofee.NewDynamicCalculator(pContext.ComplexityWeights, pContext.GasPrice)
} else {
pFeeCalculator = avagofee.NewStaticCalculator(pContext.StaticFeeConfig)
}
txFee, err := pFeeCalculator.CalculateFee(unsignedTx)
if err != nil {
return err
}
ux.Logger.PrintToUser("")
ux.Logger.PrintToUser("Paid fee: %.9f", float64(txFee)/float64(units.Avax))

ctx, cancel := utils.GetAPIContext()
defer cancel()
err = wallet.P().IssueTx(
Expand Down
Loading

0 comments on commit aef0aec

Please sign in to comment.