-
Notifications
You must be signed in to change notification settings - Fork 0
chore: port evm state and link views [CLD-1911] #7
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5f46152
feat: port evm state and link views
ecPablo 6c0e9db
fix: remove unused function, will be ported in graham's PR
ecPablo 038d5a2
Potential fix for pull request finding
ecPablo 3cde725
Potential fix for pull request finding
ecPablo d2207a3
Potential fix for pull request finding
ecPablo 7894204
fix: update contract types imports
ecPablo 4e70ade
Merge branch 'main' into ecpablo/port-evm-state-and-link-views
ecPablo 1abb521
Potential fix for pull request finding
ecPablo 34bb0a7
Potential fix for pull request finding
ecPablo 96757da
Potential fix for pull request finding
ecPablo 0d11917
fix: go mod
ecPablo 60d7fe8
fix: unit tests
ecPablo 08e30b4
Merge branch 'main' into ecpablo/port-evm-state-and-link-views
ecPablo 8d76f05
fix: move views into pkg/contracts
ecPablo 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,36 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| ) | ||
|
|
||
| type ContractMetaData struct { | ||
| TypeAndVersion string `json:"typeAndVersion,omitempty"` | ||
| Address common.Address `json:"address,omitempty"` | ||
| Owner common.Address `json:"owner,omitempty"` | ||
| } | ||
|
|
||
| func NewContractMetaData(tv Meta, addr common.Address) (ContractMetaData, error) { | ||
| tvStr, err := tv.TypeAndVersion(nil) | ||
| if err != nil { | ||
| return ContractMetaData{}, fmt.Errorf("failed to get type and version addr %s: %w", addr.String(), err) | ||
| } | ||
| owner, err := tv.Owner(nil) | ||
| if err != nil { | ||
| return ContractMetaData{}, fmt.Errorf("failed to get owner addr %s: %w", addr.String(), err) | ||
| } | ||
|
|
||
| return ContractMetaData{ | ||
| TypeAndVersion: tvStr, | ||
| Address: addr, | ||
| Owner: owner, | ||
| }, nil | ||
| } | ||
|
|
||
| type Meta interface { | ||
| TypeAndVersion(opts *bind.CallOpts) (string, error) | ||
| Owner(opts *bind.CallOpts) (common.Address, error) | ||
| } |
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,21 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "github.com/Masterminds/semver/v3" | ||
| ) | ||
|
|
||
| var ( | ||
| Version0_5_0 = *semver.MustParse("0.5.0") | ||
| Version1_0_0 = *semver.MustParse("1.0.0") | ||
| Version1_1_0 = *semver.MustParse("1.1.0") | ||
| Version1_2_0 = *semver.MustParse("1.2.0") | ||
| Version1_5_0 = *semver.MustParse("1.5.0") | ||
| Version1_5_1 = *semver.MustParse("1.5.1") | ||
| Version1_6_0 = *semver.MustParse("1.6.0") | ||
| Version1_6_1 = *semver.MustParse("1.6.1") | ||
| Version1_6_1Dev = *semver.MustParse("1.6.1-dev") | ||
| Version1_6_2 = *semver.MustParse("1.6.2") | ||
| Version1_6_3Dev = *semver.MustParse("1.6.3-dev") | ||
| Version1_6_3 = *semver.MustParse("1.6.3") | ||
| Version1_7_0 = *semver.MustParse("1.7.0") | ||
| ) | ||
|
ecPablo marked this conversation as resolved.
|
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,61 @@ | ||
| package v1_0 | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "math/big" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| linkcontracts "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/contracts/link" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-evm/gethwrappers/shared/generated/initial/link_token" | ||
|
|
||
| cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" | ||
|
|
||
| cldchangesetscommon "github.com/smartcontractkit/cld-changesets/pkg/common" | ||
| ) | ||
|
|
||
| type LinkTokenView struct { | ||
| cldchangesetscommon.ContractMetaData | ||
| Decimals uint8 `json:"decimals"` | ||
| Supply *big.Int `json:"supply"` | ||
| Minters []common.Address `json:"minters"` | ||
| Burners []common.Address `json:"burners"` | ||
| } | ||
|
|
||
| func GenerateLinkTokenView(lt *link_token.LinkToken) (LinkTokenView, error) { | ||
| owner, err := lt.Owner(nil) | ||
| if err != nil { | ||
| owner = common.Address{} | ||
| } | ||
| decimals, err := lt.Decimals(nil) | ||
| if err != nil { | ||
| return LinkTokenView{}, fmt.Errorf("failed to get decimals %s: %w", lt.Address(), err) | ||
| } | ||
| totalSupply, err := lt.TotalSupply(nil) | ||
| if err != nil { | ||
| return LinkTokenView{}, fmt.Errorf("failed to get total supply %s: %w", lt.Address(), err) | ||
| } | ||
| minters, err := lt.GetMinters(nil) | ||
| if err != nil { | ||
| minters = []common.Address{} | ||
| } | ||
| burners, err := lt.GetBurners(nil) | ||
| if err != nil { | ||
| burners = []common.Address{} | ||
| } | ||
|
ecPablo marked this conversation as resolved.
ecPablo marked this conversation as resolved.
ecPablo marked this conversation as resolved.
|
||
|
|
||
| return LinkTokenView{ | ||
| ContractMetaData: cldchangesetscommon.ContractMetaData{ | ||
| TypeAndVersion: cldf.TypeAndVersion{ | ||
| Type: linkcontracts.LinkToken, | ||
| Version: cldchangesetscommon.Version1_0_0, | ||
| }.String(), | ||
| Address: lt.Address(), | ||
| Owner: owner, | ||
| }, | ||
| Decimals: decimals, | ||
| Supply: totalSupply, | ||
| Minters: minters, | ||
| Burners: burners, | ||
| }, nil | ||
| } | ||
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,87 @@ | ||
| package v1_0 | ||
|
|
||
| import ( | ||
| "math/big" | ||
| "testing" | ||
|
|
||
| chainselectors "github.com/smartcontractkit/chain-selectors" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-evm/gethwrappers/shared/generated/initial/link_token" | ||
|
|
||
| cldf_evm "github.com/smartcontractkit/chainlink-deployments-framework/chain/evm" | ||
| "github.com/smartcontractkit/chainlink-deployments-framework/engine/test/environment" | ||
| ) | ||
|
|
||
| func TestLinkTokenView(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| selector := chainselectors.TEST_90000001.Selector | ||
| env, err := environment.New(t.Context(), | ||
| environment.WithEVMSimulated(t, []uint64{selector}), | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| chain := env.BlockChains.EVMChains()[selector] | ||
| _, tx, lt, err := link_token.DeployLinkToken(chain.DeployerKey, chain.Client) | ||
| require.NoError(t, err) | ||
| _, err = chain.Confirm(tx) | ||
| require.NoError(t, err) | ||
|
|
||
| testLinkTokenViewWithChain(t, chain, lt) | ||
| } | ||
|
|
||
| func TestLinkTokenViewZk(t *testing.T) { | ||
| // Timeouts in CI | ||
| tests.SkipFlakey(t, "https://smartcontract-it.atlassian.net/browse/CCIP-6427") | ||
| t.Parallel() | ||
|
|
||
| selector := chainselectors.TEST_90000050.Selector | ||
| env, err := environment.New(t.Context(), | ||
| environment.WithZKSyncContainer(t, []uint64{selector}), | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| chain := env.BlockChains.EVMChains()[selector] | ||
| _, _, lt, err := link_token.DeployLinkTokenZk(nil, chain.ClientZkSyncVM, chain.DeployerKeyZkSyncVM, chain.Client) | ||
| require.NoError(t, err) | ||
|
|
||
| testLinkTokenViewWithChain(t, chain, lt) | ||
| } | ||
|
|
||
| func testLinkTokenViewWithChain(t *testing.T, chain cldf_evm.Chain, lt *link_token.LinkToken) { | ||
| t.Helper() | ||
|
|
||
| v, err := GenerateLinkTokenView(lt) | ||
| require.NoError(t, err) | ||
|
|
||
| assert.Equal(t, v.Owner, chain.DeployerKey.From) | ||
| assert.Equal(t, "LinkToken 1.0.0", v.TypeAndVersion) | ||
| assert.Equal(t, uint8(18), v.Decimals) | ||
| // Initially nothing minted and no minters/burners. | ||
| assert.Equal(t, "0", v.Supply.String()) | ||
| require.Empty(t, v.Minters) | ||
| require.Empty(t, v.Burners) | ||
|
|
||
| // Add some minters | ||
| tx, err := lt.GrantMintAndBurnRoles(chain.DeployerKey, chain.DeployerKey.From) | ||
| require.NoError(t, err) | ||
| _, err = chain.Confirm(tx) | ||
| require.NoError(t, err) | ||
| tx, err = lt.Mint(chain.DeployerKey, chain.DeployerKey.From, big.NewInt(100)) | ||
| require.NoError(t, err) | ||
| _, err = chain.Confirm(tx) | ||
| require.NoError(t, err) | ||
|
|
||
| v, err = GenerateLinkTokenView(lt) | ||
| require.NoError(t, err) | ||
|
|
||
| assert.Equal(t, "100", v.Supply.String()) | ||
| require.Len(t, v.Minters, 1) | ||
| require.Equal(t, v.Minters[0].String(), chain.DeployerKey.From.String()) | ||
| require.Len(t, v.Burners, 1) | ||
| require.Equal(t, v.Burners[0].String(), chain.DeployerKey.From.String()) | ||
| } |
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,43 @@ | ||
| package v1_0 | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "math/big" | ||
|
|
||
| linkcontracts "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/contracts/link" | ||
| "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/link_token_interface" | ||
|
|
||
| cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" | ||
|
|
||
| "github.com/smartcontractkit/cld-changesets/pkg/common" | ||
| ) | ||
|
|
||
| type StaticLinkTokenView struct { | ||
| common.ContractMetaData | ||
| Decimals uint8 `json:"decimals"` | ||
| Supply *big.Int `json:"supply"` | ||
| } | ||
|
|
||
| func GenerateStaticLinkTokenView(lt *link_token_interface.LinkToken) (StaticLinkTokenView, error) { | ||
| decimals, err := lt.Decimals(nil) | ||
| if err != nil { | ||
| return StaticLinkTokenView{}, fmt.Errorf("failed to get decimals %s: %w", lt.Address(), err) | ||
| } | ||
| totalSupply, err := lt.TotalSupply(nil) | ||
| if err != nil { | ||
| return StaticLinkTokenView{}, fmt.Errorf("failed to get total supply %s: %w", lt.Address(), err) | ||
| } | ||
|
|
||
| return StaticLinkTokenView{ | ||
| ContractMetaData: common.ContractMetaData{ | ||
| TypeAndVersion: cldf.TypeAndVersion{ | ||
| Type: linkcontracts.StaticLinkToken, | ||
| Version: common.Version1_0_0, | ||
| }.String(), | ||
| Address: lt.Address(), | ||
| // No owner. | ||
| }, | ||
| Decimals: decimals, | ||
| Supply: totalSupply, | ||
| }, nil | ||
| } |
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,39 @@ | ||
| package v1_0 | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| chain_selectors "github.com/smartcontractkit/chain-selectors" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-deployments-framework/engine/test/environment" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/link_token_interface" | ||
| ) | ||
|
|
||
| func TestStaticLinkTokenView(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| selector := chain_selectors.TEST_90000001.Selector | ||
| env, err := environment.New(t.Context(), | ||
| environment.WithEVMSimulated(t, []uint64{selector}), | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| chain := env.BlockChains.EVMChains()[selector] | ||
| _, tx, lt, err := link_token_interface.DeployLinkToken(chain.DeployerKey, chain.Client) | ||
| require.NoError(t, err) | ||
| _, err = chain.Confirm(tx) | ||
| require.NoError(t, err) | ||
| v, err := GenerateStaticLinkTokenView(lt) | ||
| require.NoError(t, err) | ||
|
|
||
| assert.Equal(t, v.Owner, common.HexToAddress("0x0")) // Ownerless | ||
| assert.Equal(t, "StaticLinkToken 1.0.0", v.TypeAndVersion) | ||
| assert.Equal(t, uint8(18), v.Decimals) | ||
| assert.Equal(t, "1000000000000000000000000000", v.Supply.String()) | ||
| } |
Oops, something went wrong.
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.