Skip to content

Commit

Permalink
FEATURE: Cadence 1.0 Core Contracts Changes (#319)
Browse files Browse the repository at this point in the history
* update to view functions for stable cadence

* Update to newest Stable Cadence Preview (#371)

* update to view functions for stable cadence

* remove unreachable code

* update templates to Stable Cadence

* update to Stable Cadence preview 4

* update for stable cadence

* fix parse error

---------

Co-authored-by: Josh Hannan <[email protected]>
Co-authored-by: Bastian Müller <[email protected]>

* remove casting and fix conflicts

* integrate ft and nft stable cadence changes, use access, view, and entitlements

* use v2 ft and nft

* use string for nft import

* update token deps

* update token deps

* update nft dependecy

* update nft dep

* update ft dep

* add more view

* update FlowToken contract getter to explicitly use metadata views

* implement new standard methods

* update nft dependency

* update ft dep

* fix FungibleToken.Vault types and imports

* remove view from copy

* add correct vault type

* remove views and update balances

* use vault interface type

* remove restricted types

* remove AnyStruct

* remove type restrictions

* fix view modifiers in epoch contracts

* remove view for dkgCompleted

* remove non-view methods from pre-conditions

* use setter methods in QC

* remove pub from QC

* add fun keyword

* use setters for fields and use getBalance

* use view keyword

* remove restricted types from flow epoch

* use setters in FlowEpoch

* correct metadata types

* use UInt64 in NodeVersionBeacon

* dont use restricted types in locked tokens and staking collection

* make LockedTokens compatible with FungibleToken

* use entitlement for manager

* correct entitlement syntax

* fix entitlement issues with locked tokens

* fix entitlement issues with staking collection

* fix entitlement return types

* add withdrawable to machine account functions

* replace addresses and fix transactions and scripts

* fixes to epoch tests

* update to latest token standards and update locked tokens transactions

* Update contracts

* Update more contracts

* Update contracts

* Update contarcts and transactions

* go mod tidy

* Update flow-sdk

* Update more contracts

* Update ft/nft deps

* Generate assets

* Update more cadence codes

* Update staking collection

* Update go mods

* Fix typo

* Replace get()+borrow() with borrow()

* Refactor code

* Update go-sdk and flow-nft versions

* Fix publish_voter transaction

* Update to Cadence v1.0.0-preview.1

* Apply suggestions from code review

Co-authored-by: Bastian Müller <[email protected]>

* Refactor code

* fix and improve syntax

* use optional chaining and nil-coaelescing instead of force-unwrapping

* Update get_total_balance.cdc

* make sure epoch contracts work with capability controllers and entitlements

* update dependencies and add public burn tokens method

* remove view from getRandomSourceHistoryPage and use account.storage

* remove custom destructors and fix entitlement usage

* get all go tests passing for cadence 1.0

* make ci

* make ci

* update random source transactions

* update cli version for CI

* update go version

* Update Cadence version (#406)

* update Withdrawable and createEmptyVault

* update createEmpty in staking

* use Burner and update dependencies

* update to SDK v1.0.0-M1

* update NFT contracts, remove replace statements

* update to Cadence v1.0.0-M3

* update to Cadence v1.0.0-M3 and SDK v1.0.0-M1

* remove getBalance, add isAvailableToWithdraw

* update ft and nft deps

* update emulator dependencies and get tests passing

* use FungibleToken.Balance instead of FlowToken.Vault

* use correct public path types

* update imports

* go mod tidy

* add fungible token switchboard

* fix switchboard

* update error messages for ledger transactions

* add updated manifests with new account, FT, and NFT transactions and removed locked token staking txs

* update account transactions to use simple arguments

* update manifest to include both styles of token transfer transactions:

* update emulator dependency

* use string args for NFT contracts

* update collection machine account transactions to not use keylist entry

* Update contract getter methods to use env (#410)

* update import addresses to better format and use env

* update deps

* update go mod

* re-add lockedaccountinfo

* update ft and nft dependencies

* get address replacement working in tests and add event emission restrictions for FlowToken

* update to latest emulator, cadence, and token standards versions

* Update README

* Don't copy dictionary in getEpochMetadata (#413)

* Don't copy dictionary in getEpochMetadata

* update NFT contracts

* update ft dependency

* update token standard dependencies

* make ci

* fix algorithm typo and test names

* update nft transactions

* fix typos in transactions

* update nft dependencies

* Add entitlement for locked account creator (#423)

* update deps, add entitlement for locked account creator

* make ci

* update ft dependencies

* remove optional chaining in FlowStakingCollection

* remove optional chaining

* update nft imports and remove unnecessary Burner import from FlowToken

* update dependencies

* Improve random distribution (#428)

* better use of  revertible random with correct types

* improve random distribution

* address PR comments and add entitlements to LockedTokens.TokenManager

* remove UseTokens entitlement

* use view more and update nft deps

* make ci

* add view modifiers

* update dependencies

---------

Co-authored-by: Daniel Sainati <[email protected]>
Co-authored-by: Bastian Müller <[email protected]>
Co-authored-by: Supun Setunga <[email protected]>
Co-authored-by: Bastian Müller <[email protected]>
Co-authored-by: Janez Podhostnik <[email protected]>
Co-authored-by: Tarak Ben Youssef <[email protected]>
  • Loading branch information
7 people authored Jun 12, 2024
1 parent 272df6c commit 71b0f49
Show file tree
Hide file tree
Showing 360 changed files with 12,423 additions and 25,233 deletions.
13 changes: 3 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,12 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: "1.21.5"
- uses: actions/setup-node@v3
with:
node-version: 16
cache: "npm"
cache-dependency-path: lib/js/test/package-lock.json
go-version: '1.21.5'
- name: Install Flow CLI
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.15.0
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/feature/stable-cadence/install.sh)"
- name: Flow cli Version
run: flow version
run: flow-c1 version
- name: Update PATH
run: echo "/root/.local/bin" >> $GITHUB_PATH
- name: Install dependencies
run: cd lib/js/test && npm ci
- name: Run tests
run: export GOPATH=$HOME/go && make ci
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
test:
$(MAKE) generate -C lib/go
$(MAKE) test -C lib/go
flow test --cover --covercode="contracts" tests/test_*.cdc
flow-c1 test --cover --covercode="contracts" tests/*.cdc

.PHONY: ci
ci:
$(MAKE) ci -C lib/go
flow test --cover --covercode="contracts" tests/test_*.cdc
flow-c1 test --cover --covercode="contracts" tests/*.cdc
135 changes: 61 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

These are the smart contracts that define the core functionality of the Flow protocol.

The version of the contracts in the `master` branch is the
Cadence 1.0 version of the contracts and is not the same
as the ones that are currently deployed to testnet and mainnet.
See the `cadence-0.42` branch for the currently deployed versions.

# What is Flow?

Flow is a new blockchain for open worlds. Read more about it [here](https://www.onflow.org/).
Expand All @@ -20,12 +25,13 @@ so they can build a basic understanding of the programming language.

`contracts/FlowToken.cdc`

| Network | Contract Address |
| --------------- | -------------------- |
| Emulator/Canary | `0x0ae53cb6e3f42a79` |
| Testnet | `0x7e60df042a9c0868` |
| Sandboxnet | `0x0661ab7d6696a460` |
| Mainnet | `0x1654653399040a61` |
| Network | Contract Address |
| ---------------------------- | -------------------- |
| Emulator | `0x0ae53cb6e3f42a79` |
| Previewnet | `0x4445e7ad11568276` |
| Testnet/Crescendo | `0x7e60df042a9c0868` |
| Sandboxnet | `0x0661ab7d6696a460` |
| Mainnet | `0x1654653399040a61` |

This is the contract that defines the network token for Flow.
This token is used for account creation fees, transaction fees, staking, and more. It is
Expand All @@ -39,25 +45,27 @@ You can find transactions for using the Flow Token in the `transactions/flowToke

`contracts/FlowFees.cdc`

| Network | Contract Address |
| --------------- | -------------------- |
| Emulator/Canary | `0xe5a8b7f23e8b548f` |
| Testnet | `0x912d5440f7e3769e` |
| Sandboxnet | `0xe92c2039bbe9da96` |
| Mainnet | `0xf919ee77447b7497` |
| Network | Contract Address |
| ---------------------------- | -------------------- |
| Emulator | `0xe5a8b7f23e8b548f` |
| Previewnet | `0xab086ce9cc29fc80` |
| Testnet/Crescendo | `0x912d5440f7e3769e` |
| Sandboxnet | `0xe92c2039bbe9da96` |
| Mainnet | `0xf919ee77447b7497` |

This contract defines fees that are spent for executing transactions and creating accounts.

## Storage Fee Contract

`contracts/FlowStorageFees.cdc`

| Network | Contract Address |
| --------------- | -------------------- |
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
| Testnet | `0x8c5303eaa26202d6` |
| Sandboxnet | `0xf4527793ee68aede` |
| Mainnet | `0xe467b9dd11fa00df` |
| Network | Contract Address |
| ---------------------------- | -------------------- |
| Emulator | `0xf8d6e0586b0a20c7` |
| Previewnet | `0xb6763b4399a888c8` |
| Testnet/Crescendo | `0x8c5303eaa26202d6` |
| Sandboxnet | `0xf4527793ee68aede` |
| Mainnet | `0xe467b9dd11fa00df` |

This contract defines fees that are spent to pay for the storage that an account uses.
There is a minimum balance that an account needs to maintain in its main `FlowToken` Vault
Expand All @@ -68,12 +76,13 @@ You can see [more docs about storage capacity and fees here.](https://docs.onflo

`contracts/FlowServiceAccount.cdc`

| Network | Contract Address |
| --------------- | -------------------- |
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
| Testnet | `0x8c5303eaa26202d6` |
| Sandboxnet | `0xf4527793ee68aede` |
| Mainnet | `0xe467b9dd11fa00df` |
| Network | Contract Address |
| ---------------------------- | -------------------- |
| Emulator | `0xf8d6e0586b0a20c7` |
| Previewnet | `0xb6763b4399a888c8` |
| Testnet/Crescendo | `0x8c5303eaa26202d6` |
| Sandboxnet | `0xf4527793ee68aede` |
| Mainnet | `0xe467b9dd11fa00df` |

This contract manages account creation and flow token initialization. It enforces temporary
requirements for which accounts are allowed to create other accounts, and provides common
Expand All @@ -85,12 +94,13 @@ You can find transactions for interacting with the service account contract in t

`contracts/RandomBeaconHistory.cdc`

| Network | Contract Address |
| --------------- | -------------------- |
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
| Testnet | `0x8c5303eaa26202d6` |
| Sandboxnet | `0xf4527793ee68aede` |
| Mainnet | `0xe467b9dd11fa00df` |
| Network | Contract Address |
| ---------------------------- | -------------------- |
| Emulator | `0xf8d6e0586b0a20c7` |
| Previewnet | `0xb6763b4399a888c8` |
| Testnet/Crescendo | `0x8c5303eaa26202d6` |
| Sandboxnet | `0xf4527793ee68aede` |
| Mainnet | `0xe467b9dd11fa00df` |

This contract stores the history of random sources generated by
the Flow network. The defined Heartbeat resource is
Expand All @@ -104,14 +114,15 @@ You can find transactions for interacting with the random beacon

`contracts/NodeVersionBeacon.cdc`

| Network | Contract Address |
| --------------- | -------------------- |
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
| Testnet | `0x8c5303eaa26202d6` |
| Sandboxnet | `0xf4527793ee68aede` |
| Mainnet | `0xe467b9dd11fa00df` |
| Network | Contract Address |
| ----------------- | -------------------- |
| Emulator | `0xf8d6e0586b0a20c7` |
| Previewnet | `0xb6763b4399a888c8` |
| Testnet/Crescendo | `0x8c5303eaa26202d6` |
| Sandboxnet | `0xf4527793ee68aede` |
| Mainnet | `0xe467b9dd11fa00df` |

The NodeVersionBeacon contract holds the past
The `NodeVersionBeacon` contract holds the past
and future protocol versions that should be used
to execute/handle blocks at a given block height.

Expand All @@ -123,12 +134,13 @@ history contract in the `transactions/nodeVersionBeacon` directory.
`contracts/FlowIDTableStaking.cdc`
`contracts/epochs/FlowEpoch.cdc`

| Network | Contract Address |
| --------------- | -------------------- |
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
| Testnet | `0x9eca2b38b18b5dfe` |
| Sandboxnet | `0xf4527793ee68aede` |
| Mainnet | `0x8624b52f9ddcd04a` |
| Network | Contract Address |
| ------------------- | -------------------- |
| Emulator | `0xf8d6e0586b0a20c7` |
| Previewnet | `0xb6763b4399a888c8` |
| Testnet/Crescendo | `0x9eca2b38b18b5dfe` |
| Sandboxnet | `0xf4527793ee68aede` |
| Mainnet | `0x8624b52f9ddcd04a` |

These contract manages the list of identities that correspond to node operators in the Flow network
as well as the process for adding and removing nodes from the network via Epochs.
Expand Down Expand Up @@ -156,7 +168,8 @@ These scripts are documented in the [staking scripts section of the docs](https:

| Network | Contract Address |
| --------------- | -------------------- |
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
| Emulator | `0xf8d6e0586b0a20c7` |
| Previewnet | `0xb6763b4399a888c8` |
| Testnet | `0x95e019a17d0e23d7` |
| Sandboxnet | `0xf4527793ee68aede` |
| Mainnet | `0x8d0e87b65159ae63` |
Expand All @@ -168,12 +181,8 @@ token sale in October of 2020. See more documentation about `LockedTokens` [here

`contracts/FlowStakingCollection.cdc`

| Network | Contract Address |
| --------------- | -------------------- |
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
| Testnet | `0x95e019a17d0e23d7` |
| Sandboxnet | `0xf4527793ee68aede` |
| Mainnet | `0x8d0e87b65159ae63` |
The `StakingCollection` contract has the same import addresses
as the `LockedTokens` contract on all the networks.

A Staking Collection is a resource that allows its owner to manage multiple staking
objects in a single account via a single storage path, and perform staking and delegation actions using both locked and unlocked Flow.
Expand Down Expand Up @@ -226,35 +235,13 @@ need to copy and paste them into your code. We plan on providing packages for di
languages to import in order to use the transactions instead of copying and pasting.

We currently include the `lib/go/templates` package for getting templates in the Go programming language.
To use this package, run `import github.com/onflow/flow-core-contracts/lib/go/templates@{latest version}`
To use this package, run `go get github.com/onflow/flow-core-contracts/lib/go/templates@{latest version}`
in your Go project direcory. To use it in your Go code, you can simply call one of the many
template getters in one of the `*_templates.go` files.

For example, to get the transaction text of the tranasction that is used to register a new node
for staking, and add arguments to it, you would use something like this Go code.

```Go
tx := flow.NewTransaction().
SetScript(templates.GenerateRegisterNodeScript(env)).
SetGasLimit(100).
SetProposalKey(b.ServiceKey().Address, b.ServiceKey().Index, b.ServiceKey().SequenceNumber).
SetPayer(b.ServiceKey().Address).
AddAuthorizer(userAddress)

// Invalid ID: Too short
_ = tx.AddArgument(cadence.NewString("3039"))
_ = tx.AddArgument(cadence.NewUInt8(1))
_ = tx.AddArgument(cadence.NewString("12234"))
_ = tx.AddArgument(cadence.NewString("netkey"))
_ = tx.AddArgument(cadence.NewString("stakekey"))
tokenAmount, err := cadence.NewUFix64("250000.0")
require.NoError(t, err)
_ = tx.AddArgument(tokenAmount)
```

### Packages in other languages

We are planning to add new packages for other popular languages to get transaction templates.
We would like to add new packages for other popular languages to get transaction templates.
If you would like to contribute to add one of these new packages, please reach out
to the team and we would be happy to help!

Expand Down
Loading

0 comments on commit 71b0f49

Please sign in to comment.