Skip to content
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

fix: compass attestation with ERC20 tokens #1253

Merged
merged 1 commit into from
Aug 9, 2024
Merged
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
5 changes: 2 additions & 3 deletions x/evm/keeper/attest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ var _ = g.Describe("attest router", func() {

g.When("target chain has no deployed ERC20 tokens", func() {
g.BeforeEach(func() {
gk.On("CastAllERC20ToDenoms", mock.Anything).Return(nil, nil)
gk.On("CastChainERC20ToDenoms", mock.Anything, mock.Anything).Return(nil, nil)
})
g.It("removes deployment", func() {
setupChainSupport()
Expand All @@ -590,10 +590,9 @@ var _ = g.Describe("attest router", func() {

g.When("target chain has active ERC20 tokens deployed", func() {
g.BeforeEach(func() {
gk.On("CastAllERC20ToDenoms", mock.Anything).Return([]types.ERC20Record{
gk.On("CastChainERC20ToDenoms", mock.Anything, newChain.ChainReferenceID).Return([]types.ERC20Record{
record{"denom", "address1", newChain.ChainReferenceID},
record{"denom2", "address2", newChain.ChainReferenceID},
record{"denom3", "address3", "unknown-chain"},
}, nil)
})
g.It("updates deployment", func() {
Expand Down
10 changes: 9 additions & 1 deletion x/evm/keeper/attest_upload_smart_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func (a *uploadSmartContractAttester) attest(ctx sdk.Context, evidence *types.Tx
return err
}

records, err := a.k.Skyway.CastAllERC20ToDenoms(ctx)
// Get the ERC20 tokens just for this chain
records, err := a.k.Skyway.CastChainERC20ToDenoms(ctx, a.chainReferenceID)
if err != nil {
a.logger.WithError(err).Error("Failed to extract ERC20 records.")
return err
Expand Down Expand Up @@ -212,6 +213,13 @@ func (a *uploadSmartContractAttester) startTokenRelink(
})
}

// This shouldn't be needed anymore, since we query the ERC20 tokens for
// this specific chain. However, just to make double sure, we check the
// transfers. If there's none, just set the contract to active.
if len(transfers) == 0 {
return a.k.SetSmartContractAsActive(ctx, smartContractID, a.chainReferenceID)
}

deployment.Erc20Transfers = transfers
if err := a.k.updateSmartContractDeployment(ctx, smartContractID, a.chainReferenceID, deployment); err != nil {
a.logger.WithError(err).Error("Failed to update smart contract deployment")
Expand Down
1 change: 1 addition & 0 deletions x/evm/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type ERC20Record interface {
type SkywayKeeper interface {
GetLastObservedSkywayNonce(ctx context.Context, chainReferenceID string) (uint64, error)
CastAllERC20ToDenoms(ctx context.Context) ([]ERC20Record, error)
CastChainERC20ToDenoms(ctx context.Context, chainReferenceID string) ([]ERC20Record, error)
}

//go:generate mockery --name=MetrixKeeper
Expand Down
33 changes: 31 additions & 2 deletions x/evm/types/mocks/SkywayKeeper.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions x/skyway/keeper/cosmos-originated.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ func (k Keeper) CastAllERC20ToDenoms(ctx context.Context) ([]evmtypes.ERC20Recor
return cast, nil
}

func (k Keeper) CastChainERC20ToDenoms(
ctx context.Context,
chainReferenceID string,
) ([]evmtypes.ERC20Record, error) {
all, err := k.GetAllERC20ToDenoms(ctx)
if err != nil {
return nil, err
}

cast := make([]evmtypes.ERC20Record, 0, len(all))
for _, v := range all {
if v.GetChainReferenceId() == chainReferenceID {
cast = append(cast, v)
}
}

return cast, nil
}

func (k Keeper) setDenomToERC20(ctx context.Context, chainReferenceId, denom string, tokenContract types.EthAddress) error {
store := k.GetStore(ctx, types.StoreModulePrefix)

Expand Down
Loading