Skip to content

Commit 71b0f49

Browse files
joshuahannandsainati1turbolentSupunSjanezpodhostnik
authored
FEATURE: Cadence 1.0 Core Contracts Changes (#319)
* 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]>
1 parent 272df6c commit 71b0f49

File tree

360 files changed

+12423
-25233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

360 files changed

+12423
-25233
lines changed

.github/workflows/ci.yml

+3-10
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,12 @@ jobs:
1111
- uses: actions/checkout@v2
1212
- uses: actions/setup-go@v1
1313
with:
14-
go-version: "1.21.5"
15-
- uses: actions/setup-node@v3
16-
with:
17-
node-version: 16
18-
cache: "npm"
19-
cache-dependency-path: lib/js/test/package-lock.json
14+
go-version: '1.21.5'
2015
- name: Install Flow CLI
21-
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.15.0
16+
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/feature/stable-cadence/install.sh)"
2217
- name: Flow cli Version
23-
run: flow version
18+
run: flow-c1 version
2419
- name: Update PATH
2520
run: echo "/root/.local/bin" >> $GITHUB_PATH
26-
- name: Install dependencies
27-
run: cd lib/js/test && npm ci
2821
- name: Run tests
2922
run: export GOPATH=$HOME/go && make ci

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
test:
33
$(MAKE) generate -C lib/go
44
$(MAKE) test -C lib/go
5-
flow test --cover --covercode="contracts" tests/test_*.cdc
5+
flow-c1 test --cover --covercode="contracts" tests/*.cdc
66

77
.PHONY: ci
88
ci:
99
$(MAKE) ci -C lib/go
10-
flow test --cover --covercode="contracts" tests/test_*.cdc
10+
flow-c1 test --cover --covercode="contracts" tests/*.cdc

README.md

+61-74
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

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

5+
The version of the contracts in the `master` branch is the
6+
Cadence 1.0 version of the contracts and is not the same
7+
as the ones that are currently deployed to testnet and mainnet.
8+
See the `cadence-0.42` branch for the currently deployed versions.
9+
510
# What is Flow?
611

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

2126
`contracts/FlowToken.cdc`
2227

23-
| Network | Contract Address |
24-
| --------------- | -------------------- |
25-
| Emulator/Canary | `0x0ae53cb6e3f42a79` |
26-
| Testnet | `0x7e60df042a9c0868` |
27-
| Sandboxnet | `0x0661ab7d6696a460` |
28-
| Mainnet | `0x1654653399040a61` |
28+
| Network | Contract Address |
29+
| ---------------------------- | -------------------- |
30+
| Emulator | `0x0ae53cb6e3f42a79` |
31+
| Previewnet | `0x4445e7ad11568276` |
32+
| Testnet/Crescendo | `0x7e60df042a9c0868` |
33+
| Sandboxnet | `0x0661ab7d6696a460` |
34+
| Mainnet | `0x1654653399040a61` |
2935

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

4046
`contracts/FlowFees.cdc`
4147

42-
| Network | Contract Address |
43-
| --------------- | -------------------- |
44-
| Emulator/Canary | `0xe5a8b7f23e8b548f` |
45-
| Testnet | `0x912d5440f7e3769e` |
46-
| Sandboxnet | `0xe92c2039bbe9da96` |
47-
| Mainnet | `0xf919ee77447b7497` |
48+
| Network | Contract Address |
49+
| ---------------------------- | -------------------- |
50+
| Emulator | `0xe5a8b7f23e8b548f` |
51+
| Previewnet | `0xab086ce9cc29fc80` |
52+
| Testnet/Crescendo | `0x912d5440f7e3769e` |
53+
| Sandboxnet | `0xe92c2039bbe9da96` |
54+
| Mainnet | `0xf919ee77447b7497` |
4855

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

5158
## Storage Fee Contract
5259

5360
`contracts/FlowStorageFees.cdc`
5461

55-
| Network | Contract Address |
56-
| --------------- | -------------------- |
57-
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
58-
| Testnet | `0x8c5303eaa26202d6` |
59-
| Sandboxnet | `0xf4527793ee68aede` |
60-
| Mainnet | `0xe467b9dd11fa00df` |
62+
| Network | Contract Address |
63+
| ---------------------------- | -------------------- |
64+
| Emulator | `0xf8d6e0586b0a20c7` |
65+
| Previewnet | `0xb6763b4399a888c8` |
66+
| Testnet/Crescendo | `0x8c5303eaa26202d6` |
67+
| Sandboxnet | `0xf4527793ee68aede` |
68+
| Mainnet | `0xe467b9dd11fa00df` |
6169

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

6977
`contracts/FlowServiceAccount.cdc`
7078

71-
| Network | Contract Address |
72-
| --------------- | -------------------- |
73-
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
74-
| Testnet | `0x8c5303eaa26202d6` |
75-
| Sandboxnet | `0xf4527793ee68aede` |
76-
| Mainnet | `0xe467b9dd11fa00df` |
79+
| Network | Contract Address |
80+
| ---------------------------- | -------------------- |
81+
| Emulator | `0xf8d6e0586b0a20c7` |
82+
| Previewnet | `0xb6763b4399a888c8` |
83+
| Testnet/Crescendo | `0x8c5303eaa26202d6` |
84+
| Sandboxnet | `0xf4527793ee68aede` |
85+
| Mainnet | `0xe467b9dd11fa00df` |
7786

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

8695
`contracts/RandomBeaconHistory.cdc`
8796

88-
| Network | Contract Address |
89-
| --------------- | -------------------- |
90-
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
91-
| Testnet | `0x8c5303eaa26202d6` |
92-
| Sandboxnet | `0xf4527793ee68aede` |
93-
| Mainnet | `0xe467b9dd11fa00df` |
97+
| Network | Contract Address |
98+
| ---------------------------- | -------------------- |
99+
| Emulator | `0xf8d6e0586b0a20c7` |
100+
| Previewnet | `0xb6763b4399a888c8` |
101+
| Testnet/Crescendo | `0x8c5303eaa26202d6` |
102+
| Sandboxnet | `0xf4527793ee68aede` |
103+
| Mainnet | `0xe467b9dd11fa00df` |
94104

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

105115
`contracts/NodeVersionBeacon.cdc`
106116

107-
| Network | Contract Address |
108-
| --------------- | -------------------- |
109-
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
110-
| Testnet | `0x8c5303eaa26202d6` |
111-
| Sandboxnet | `0xf4527793ee68aede` |
112-
| Mainnet | `0xe467b9dd11fa00df` |
117+
| Network | Contract Address |
118+
| ----------------- | -------------------- |
119+
| Emulator | `0xf8d6e0586b0a20c7` |
120+
| Previewnet | `0xb6763b4399a888c8` |
121+
| Testnet/Crescendo | `0x8c5303eaa26202d6` |
122+
| Sandboxnet | `0xf4527793ee68aede` |
123+
| Mainnet | `0xe467b9dd11fa00df` |
113124

114-
The NodeVersionBeacon contract holds the past
125+
The `NodeVersionBeacon` contract holds the past
115126
and future protocol versions that should be used
116127
to execute/handle blocks at a given block height.
117128

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

126-
| Network | Contract Address |
127-
| --------------- | -------------------- |
128-
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
129-
| Testnet | `0x9eca2b38b18b5dfe` |
130-
| Sandboxnet | `0xf4527793ee68aede` |
131-
| Mainnet | `0x8624b52f9ddcd04a` |
137+
| Network | Contract Address |
138+
| ------------------- | -------------------- |
139+
| Emulator | `0xf8d6e0586b0a20c7` |
140+
| Previewnet | `0xb6763b4399a888c8` |
141+
| Testnet/Crescendo | `0x9eca2b38b18b5dfe` |
142+
| Sandboxnet | `0xf4527793ee68aede` |
143+
| Mainnet | `0x8624b52f9ddcd04a` |
132144

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

157169
| Network | Contract Address |
158170
| --------------- | -------------------- |
159-
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
171+
| Emulator | `0xf8d6e0586b0a20c7` |
172+
| Previewnet | `0xb6763b4399a888c8` |
160173
| Testnet | `0x95e019a17d0e23d7` |
161174
| Sandboxnet | `0xf4527793ee68aede` |
162175
| Mainnet | `0x8d0e87b65159ae63` |
@@ -168,12 +181,8 @@ token sale in October of 2020. See more documentation about `LockedTokens` [here
168181

169182
`contracts/FlowStakingCollection.cdc`
170183

171-
| Network | Contract Address |
172-
| --------------- | -------------------- |
173-
| Emulator/Canary | `0xf8d6e0586b0a20c7` |
174-
| Testnet | `0x95e019a17d0e23d7` |
175-
| Sandboxnet | `0xf4527793ee68aede` |
176-
| Mainnet | `0x8d0e87b65159ae63` |
184+
The `StakingCollection` contract has the same import addresses
185+
as the `LockedTokens` contract on all the networks.
177186

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

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

233-
For example, to get the transaction text of the tranasction that is used to register a new node
234-
for staking, and add arguments to it, you would use something like this Go code.
235-
236-
```Go
237-
tx := flow.NewTransaction().
238-
SetScript(templates.GenerateRegisterNodeScript(env)).
239-
SetGasLimit(100).
240-
SetProposalKey(b.ServiceKey().Address, b.ServiceKey().Index, b.ServiceKey().SequenceNumber).
241-
SetPayer(b.ServiceKey().Address).
242-
AddAuthorizer(userAddress)
243-
244-
// Invalid ID: Too short
245-
_ = tx.AddArgument(cadence.NewString("3039"))
246-
_ = tx.AddArgument(cadence.NewUInt8(1))
247-
_ = tx.AddArgument(cadence.NewString("12234"))
248-
_ = tx.AddArgument(cadence.NewString("netkey"))
249-
_ = tx.AddArgument(cadence.NewString("stakekey"))
250-
tokenAmount, err := cadence.NewUFix64("250000.0")
251-
require.NoError(t, err)
252-
_ = tx.AddArgument(tokenAmount)
253-
```
254-
255242
### Packages in other languages
256243

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

0 commit comments

Comments
 (0)