diff --git a/lib/go/contracts/contracts.go b/lib/go/contracts/contracts.go index d917bc15..0c619295 100644 --- a/lib/go/contracts/contracts.go +++ b/lib/go/contracts/contracts.go @@ -8,6 +8,7 @@ import ( _ "github.com/kevinburke/go-bindata" ftcontracts "github.com/onflow/flow-ft/lib/go/contracts" + "github.com/onflow/flow-go-sdk" nftcontracts "github.com/onflow/flow-nft/lib/go/contracts" "github.com/onflow/flow-core-contracts/lib/go/templates" @@ -26,22 +27,23 @@ import ( /// const ( - flowFeesFilename = "FlowFees.cdc" - storageFeesFilename = "FlowStorageFees.cdc" - executionParametersFilename = "FlowExecutionParameters.cdc" - flowServiceAccountFilename = "FlowServiceAccount.cdc" - flowTokenFilename = "FlowToken.cdc" - flowIdentityTableFilename = "FlowIDTableStaking.cdc" - flowQCFilename = "epochs/FlowClusterQC.cdc" - flowDKGFilename = "epochs/FlowDKG.cdc" - flowEpochFilename = "epochs/FlowEpoch.cdc" - flowLockedTokensFilename = "LockedTokens.cdc" - flowStakingProxyFilename = "StakingProxy.cdc" - flowStakingCollectionFilename = "FlowStakingCollection.cdc" - flowContractAuditsFilename = "FlowContractAudits.cdc" - flowNodeVersionBeaconFilename = "NodeVersionBeacon.cdc" - flowRandomBeaconHistoryFilename = "RandomBeaconHistory.cdc" - cryptoFilename = "Crypto.cdc" + flowFeesFilename = "FlowFees.cdc" + storageFeesFilename = "FlowStorageFees.cdc" + executionParametersFilename = "FlowExecutionParameters.cdc" + flowServiceAccountFilename = "FlowServiceAccount.cdc" + flowTokenFilename = "FlowToken.cdc" + flowIdentityTableFilename = "FlowIDTableStaking.cdc" + flowQCFilename = "epochs/FlowClusterQC.cdc" + flowDKGFilename = "epochs/FlowDKG.cdc" + flowEpochFilename = "epochs/FlowEpoch.cdc" + flowLockedTokensFilename = "LockedTokens.cdc" + flowStakingProxyFilename = "StakingProxy.cdc" + flowStakingCollectionFilename = "FlowStakingCollection.cdc" + flowContractAuditsFilename = "FlowContractAudits.cdc" + flowNodeVersionBeaconFilename = "NodeVersionBeacon.cdc" + flowRandomBeaconHistoryFilename = "RandomBeaconHistory.cdc" + cryptoFilename = "Crypto.cdc" + linearCodeAddressGeneratorFilename = "LinearCodeAddressGenerator.cdc" // Test contracts // only used for testing @@ -301,6 +303,10 @@ func Crypto() []byte { return assets.MustAsset(cryptoFilename) } +func LinearCodeAddressGenerator() []byte { + return assets.MustAsset(linearCodeAddressGeneratorFilename) +} + /******************** Test contracts *********************/ // TESTFlowIDTableStaking returns the TestFlowIDTableStaking contract @@ -361,3 +367,11 @@ func TestFlowFees(fungibleTokenAddress, flowTokenAddress, storageFeesAddress str return []byte(code) } + +func ExampleToken(env templates.Environment) []byte { + return ftcontracts.ExampleToken(env.FungibleTokenAddress, env.MetadataViewsAddress, env.FungibleTokenMetadataViewsAddress) +} + +func ExampleNFT(env templates.Environment) []byte { + return nftcontracts.ExampleNFTWithCrossVMPointers(flow.HexToAddress(env.NonFungibleTokenAddress), flow.HexToAddress(env.MetadataViewsAddress), flow.HexToAddress(env.ViewResolverAddress), flow.HexToAddress(env.EVMAddress), flow.HexToAddress(env.CrossVMMetadataViewsAddress)) +} diff --git a/lib/go/contracts/contracts_test.go b/lib/go/contracts/contracts_test.go index 634eea2e..e31ed8be 100644 --- a/lib/go/contracts/contracts_test.go +++ b/lib/go/contracts/contracts_test.go @@ -174,6 +174,11 @@ func TestCrypto(t *testing.T) { GetCadenceContractShouldSucceed(t, contract) } +func TestLinearCodeAddressGenerator(t *testing.T) { + contract := string(contracts.LinearCodeAddressGenerator()) + GetCadenceContractShouldSucceed(t, contract) +} + func TestFlowExecutionParameters(t *testing.T) { env := templates.Environment{} SetAllAddresses(&env) diff --git a/lib/go/contracts/go.mod b/lib/go/contracts/go.mod index 65e8d877..cfd61e09 100644 --- a/lib/go/contracts/go.mod +++ b/lib/go/contracts/go.mod @@ -6,9 +6,10 @@ toolchain go1.22.4 require ( github.com/kevinburke/go-bindata v3.24.0+incompatible - github.com/onflow/flow-core-contracts/lib/go/templates v1.5.1-preview + github.com/onflow/flow-core-contracts/lib/go/templates v1.6.1-0.20250226163127-3c9723416637 github.com/onflow/flow-ft/lib/go/contracts v1.0.1 - github.com/onflow/flow-nft/lib/go/contracts v1.2.3 + github.com/onflow/flow-go-sdk v1.0.0-preview.54 + github.com/onflow/flow-nft/lib/go/contracts v1.2.4 github.com/stretchr/testify v1.9.0 ) @@ -38,7 +39,6 @@ require ( github.com/onflow/cadence v1.0.0-preview.51 // indirect github.com/onflow/crypto v0.25.1 // indirect github.com/onflow/flow-ft/lib/go/templates v1.0.1 // indirect - github.com/onflow/flow-go-sdk v1.0.0-preview.54 // indirect github.com/onflow/flow-nft/lib/go/templates v1.2.1 // indirect github.com/onflow/flow/protobuf/go/flow v0.4.3 // indirect github.com/onflow/go-ethereum v1.13.4 // indirect diff --git a/lib/go/contracts/go.sum b/lib/go/contracts/go.sum index 6bf5a3d8..31aaef5d 100644 --- a/lib/go/contracts/go.sum +++ b/lib/go/contracts/go.sum @@ -221,16 +221,16 @@ github.com/onflow/cadence v1.0.0-preview.51 h1:L+toCS2Sw9bsExc2PxeNMmAK96fn2LdTO github.com/onflow/cadence v1.0.0-preview.51/go.mod h1:7wvvecnAZtYOspLOS3Lh+FuAmMeSrXhAWiycC3kQ1UU= github.com/onflow/crypto v0.25.1 h1:0txy2PKPMM873JbpxQNbJmuOJtD56bfs48RQfm0ts5A= github.com/onflow/crypto v0.25.1/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI= -github.com/onflow/flow-core-contracts/lib/go/templates v1.5.1-preview h1:C0PraQFfwpav4nJAf/RPE9BJyYD6lUMvt+cJyiMDeis= -github.com/onflow/flow-core-contracts/lib/go/templates v1.5.1-preview/go.mod h1:pN768Al/wLRlf3bwugv9TyxniqJxMu4sxnX9eQJam64= +github.com/onflow/flow-core-contracts/lib/go/templates v1.6.1-0.20250226163127-3c9723416637 h1:EhhRQDEAc5K3NOtFF+Qd7eXKOToYxEOtSqOtt70ia/Y= +github.com/onflow/flow-core-contracts/lib/go/templates v1.6.1-0.20250226163127-3c9723416637/go.mod h1:pN768Al/wLRlf3bwugv9TyxniqJxMu4sxnX9eQJam64= github.com/onflow/flow-ft/lib/go/contracts v1.0.1 h1:Ts5ob+CoCY2EjEd0W6vdLJ7hLL3SsEftzXG2JlmSe24= github.com/onflow/flow-ft/lib/go/contracts v1.0.1/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A= github.com/onflow/flow-ft/lib/go/templates v1.0.1 h1:FDYKAiGowABtoMNusLuRCILIZDtVqJ/5tYI4VkF5zfM= github.com/onflow/flow-ft/lib/go/templates v1.0.1/go.mod h1:uQ8XFqmMK2jxyBSVrmyuwdWjTEb+6zGjRYotfDJ5pAE= github.com/onflow/flow-go-sdk v1.0.0-preview.54 h1:5GjCkyIyvE9KolOUUPTkGdEiV/8qOe1MGnLHOLBmthA= github.com/onflow/flow-go-sdk v1.0.0-preview.54/go.mod h1:u9oFiS25TpnU1EW62PQlq22jzkwBAj4VEiiCBM6nhHo= -github.com/onflow/flow-nft/lib/go/contracts v1.2.3 h1:4ju20g1xgDKWBT63rOj5f/Sa4Lc+naCSWT4p31x9yQk= -github.com/onflow/flow-nft/lib/go/contracts v1.2.3/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY= +github.com/onflow/flow-nft/lib/go/contracts v1.2.4 h1:gWJgSSgIGo0qWOqr90+khQ69VoYF9vNlqzF+Yh6YYy4= +github.com/onflow/flow-nft/lib/go/contracts v1.2.4/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY= github.com/onflow/flow-nft/lib/go/templates v1.2.1 h1:SAALMZPDw9Eb9p5kSLnmnFxjyig1MLiT4JUlLp0/bSE= github.com/onflow/flow-nft/lib/go/templates v1.2.1/go.mod h1:W6hOWU0xltPqNpv9gQX8Pj8Jtf0OmRxc1XX2V0kzJaI= github.com/onflow/flow/protobuf/go/flow v0.4.3 h1:gdY7Ftto8dtU+0wI+6ZgW4oE+z0DSDUMIDwVx8mqae8= diff --git a/lib/go/templates/templates.go b/lib/go/templates/templates.go index fa8f9efe..f4845cbc 100644 --- a/lib/go/templates/templates.go +++ b/lib/go/templates/templates.go @@ -14,28 +14,30 @@ import ( ) const ( - placeholderFungibleTokenAddress = "\"FungibleToken\"" - placeholderNonFungibleTokenAddress = "\"NonFungibleToken\"" - placeholderEVMAddress = "\"EVM\"" - placeholderViewResolverAddress = "\"ViewResolver\"" - placeholderFungibleTokenMVAddress = "\"FungibleTokenMetadataViews\"" - placeholderMetadataViewsAddress = "\"MetadataViews\"" - placeholderBurnerAddress = "\"Burner\"" - placeholderCryptoAddress = "\"Crypto\"" - placeholderFlowTokenAddress = "\"FlowToken\"" - placeholderIDTableAddress = "\"FlowIDTableStaking\"" - placeholderLockedTokensAddress = "\"LockedTokens\"" - placeholderStakingProxyAddress = "\"StakingProxy\"" - placeholderQuorumCertificateAddress = "\"FlowClusterQC\"" - placeholderFlowFeesAddress = "\"FlowFees\"" - placeholderStorageFeesAddress = "\"FlowStorageFees\"" - placeholderExecutionParametersAddress = "\"FlowExecutionParameters\"" - placeholderServiceAccountAddress = "\"FlowServiceAccount\"" - placeholderDKGAddress = "\"FlowDKG\"" - placeholderEpochAddress = "\"FlowEpoch\"" - placeholderStakingCollectionAddress = "\"FlowStakingCollection\"" - placeholderNodeVersionBeaconAddress = "\"NodeVersionBeacon\"" - placeholderRandomBeaconHistoryAddress = "\"RandomBeaconHistory\"" + placeholderFungibleTokenAddress = "\"FungibleToken\"" + placeholderNonFungibleTokenAddress = "\"NonFungibleToken\"" + placeholderEVMAddress = "\"EVM\"" + placeholderViewResolverAddress = "\"ViewResolver\"" + placeholderFungibleTokenMVAddress = "\"FungibleTokenMetadataViews\"" + placeholderMetadataViewsAddress = "\"MetadataViews\"" + placeholderCrossVMMetadataViewsAddress = "\"CrossVMMetadataViews\"" + placeholderBurnerAddress = "\"Burner\"" + placeholderCryptoAddress = "\"Crypto\"" + placeholderFlowTokenAddress = "\"FlowToken\"" + placeholderIDTableAddress = "\"FlowIDTableStaking\"" + placeholderLockedTokensAddress = "\"LockedTokens\"" + placeholderStakingProxyAddress = "\"StakingProxy\"" + placeholderQuorumCertificateAddress = "\"FlowClusterQC\"" + placeholderFlowFeesAddress = "\"FlowFees\"" + placeholderStorageFeesAddress = "\"FlowStorageFees\"" + placeholderExecutionParametersAddress = "\"FlowExecutionParameters\"" + placeholderServiceAccountAddress = "\"FlowServiceAccount\"" + placeholderDKGAddress = "\"FlowDKG\"" + placeholderEpochAddress = "\"FlowEpoch\"" + placeholderStakingCollectionAddress = "\"FlowStakingCollection\"" + placeholderNodeVersionBeaconAddress = "\"NodeVersionBeacon\"" + placeholderRandomBeaconHistoryAddress = "\"RandomBeaconHistory\"" + placeholderLinearCodeAddressGeneratorAddress = "\"LinearCodeAddressGenerator\"" ) type Environment struct { @@ -47,6 +49,7 @@ type Environment struct { NonFungibleTokenAddress string EVMAddress string MetadataViewsAddress string + CrossVMMetadataViewsAddress string FungibleTokenMetadataViewsAddress string FungibleTokenSwitchboardAddress string FlowTokenAddress string @@ -63,6 +66,7 @@ type Environment struct { ServiceAccountAddress string NodeVersionBeaconAddress string RandomBeaconHistoryAddress string + LinearCodeAddressGeneratorAddress string } func withHexPrefix(address string) string { @@ -112,6 +116,12 @@ func ReplaceAddresses(code string, env Environment) string { env.MetadataViewsAddress, ) + code = ReplaceAddress( + code, + placeholderCrossVMMetadataViewsAddress, + env.CrossVMMetadataViewsAddress, + ) + code = ReplaceAddress( code, placeholderBurnerAddress, @@ -232,5 +242,11 @@ func ReplaceAddresses(code string, env Environment) string { env.RandomBeaconHistoryAddress, ) + code = ReplaceAddress( + code, + placeholderLinearCodeAddressGeneratorAddress, + env.LinearCodeAddressGeneratorAddress, + ) + return code } diff --git a/lib/go/test/go.mod b/lib/go/test/go.mod index ea75f917..c653b5ea 100644 --- a/lib/go/test/go.mod +++ b/lib/go/test/go.mod @@ -129,7 +129,7 @@ require ( github.com/onflow/bridged-usdc/lib/go/contracts v1.0.0 // indirect github.com/onflow/flow-ft/lib/go/contracts v1.0.1 // indirect github.com/onflow/flow-ft/lib/go/templates v1.0.1 // indirect - github.com/onflow/flow-nft/lib/go/contracts v1.2.3 // indirect + github.com/onflow/flow-nft/lib/go/contracts v1.2.4 // indirect github.com/onflow/flow-nft/lib/go/templates v1.2.1 // indirect github.com/onflow/flow/protobuf/go/flow v0.4.7 // indirect github.com/onflow/go-ethereum v1.14.7 // indirect @@ -213,7 +213,7 @@ require ( // replaced by module version in this repo - disregard pinned version github.com/onflow/flow-core-contracts/lib/go/contracts v1.5.1-preview // replaced by module version in this repo - disregard pinned version - github.com/onflow/flow-core-contracts/lib/go/templates v1.5.1-preview + github.com/onflow/flow-core-contracts/lib/go/templates v1.6.1-0.20250226163127-3c9723416637 ) replace github.com/onflow/flow-core-contracts/lib/go/contracts => ../contracts diff --git a/lib/go/test/go.sum b/lib/go/test/go.sum index 12c48d02..47cb79d2 100644 --- a/lib/go/test/go.sum +++ b/lib/go/test/go.sum @@ -582,8 +582,8 @@ github.com/onflow/flow-go v0.38.0-util.0.20250130182921-c8d283b60d12 h1:RUmzt0En github.com/onflow/flow-go v0.38.0-util.0.20250130182921-c8d283b60d12/go.mod h1:bXxLlDLhyMj05TGYWFJdKTZdySShJMT0eqgommYq48w= github.com/onflow/flow-go-sdk v1.3.1 h1:2YdTL/R1/DjMYYmyKgArTeQ93GKvLlfCeCpMVH7b8q4= github.com/onflow/flow-go-sdk v1.3.1/go.mod h1:0rMuCLShdX9F4pLBCPhlMGCFu8gu9SfiXT/Lc9qAi24= -github.com/onflow/flow-nft/lib/go/contracts v1.2.3 h1:4ju20g1xgDKWBT63rOj5f/Sa4Lc+naCSWT4p31x9yQk= -github.com/onflow/flow-nft/lib/go/contracts v1.2.3/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY= +github.com/onflow/flow-nft/lib/go/contracts v1.2.4 h1:gWJgSSgIGo0qWOqr90+khQ69VoYF9vNlqzF+Yh6YYy4= +github.com/onflow/flow-nft/lib/go/contracts v1.2.4/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY= github.com/onflow/flow-nft/lib/go/templates v1.2.1 h1:SAALMZPDw9Eb9p5kSLnmnFxjyig1MLiT4JUlLp0/bSE= github.com/onflow/flow-nft/lib/go/templates v1.2.1/go.mod h1:W6hOWU0xltPqNpv9gQX8Pj8Jtf0OmRxc1XX2V0kzJaI= github.com/onflow/flow/protobuf/go/flow v0.4.7 h1:iP6DFx4wZ3ETORsyeqzHu7neFT3d1CXF6wdK+AOOjmc=