onflow / flow-core-contracts Goto Github PK
View Code? Open in Web Editor NEWCadence smart contracts that define core functionality of the Flow protocol
Home Page: https://onflow.org
License: The Unlicense
Cadence smart contracts that define core functionality of the Flow protocol
Home Page: https://onflow.org
License: The Unlicense
Need developer docs for the staking collection contract
Do a short write-up that helps developers in the community get comfortable with it so they can help review the PR.
Write documentation that replaces the staking with unlocked FLOW guide: https://docs.onflow.org/staking/unlocked-staking-guide/
The documentation should describe how to use the staking collection contract in the same style as the existing docs
This also applies to locked FLOW, so find a way to merge the two docs into one so all can see it
Need to be able to calculate new rewards payout every epoch and save as as part of epoch metadata
feature/epochs
branchRewards might need to be paid during a different phase, so it shouldn't be part of the start new epoch function.
payRewards
function for epochs that is separateIf you want to know the status of a NodeRecord right now you have to call lots of methods to fetch different fields. Having the ability to return a single NodeRecordStatus struct of a map of all of them would make it easier to write scripts on top of the api to show what is staked.
Create a NodeRecordStatus struct with calculated and safe properties and return that. Kind like versus does it here: https://github.com/versus-flow/auction-flow-contract/blob/master/contracts/Auction.cdc#L13
Nothing, just want a nice API.
For epochs, the admin needs to ability to enable and disable staking so that EpochSetup
and EpochCommitted
actions can be performed without staking transactions operating at the same time.
stakingEnabled: Bool
field to staking contractNeed to be able to calculate rewards for an epoch and pay at separate times
payRewards
to calculateRewards
and have it return a dictionary mapping nodes and delegators to their reward amountspayRewards
function to the the epoch contract to pay rewards to all the nodes from the previous epochThe epoch smart contracts currently enforce that QC and DKG resources can only be created during epoch setup. They should be able to be created at any time.
flow/epochs
branchVoter
Participant
FlowEpoch
contract for creating QC Voter
and DKG Participant
Document rewards in the flow-docs website
From the FLIP (onflow/flow#99):
Each account will have a public StorageCapacity.depositStorage
capability and a private StorageCapacity
resource on predetermined paths.
The StorageCapacity
resource defined on the StorageFees
smart contract:
storageCapacity
field which defines how much storage can the account holding this resource use.FlowVault
with Flow that was used for paying for this storage. This vault cannot be accessed by anyone except the StorageFees
smart contract. The exception is the balance of this flow vault which should be readable by anyone.purchases
used for keeping track of how much storage was purchased for how much flow.depositStorage
function that can only be used by the StorageFees
smart contract (is this possible?):
storageCapacity
field deposit into the FlowVault
and append to purchases
The StorageFees
smart contract will also have the following responsibilities:
minimumStorageUnit
: define the minimum unit (chunk) size of storage in bytes. Storage can only be bought (or refunded) in a multiple of the minimum storage unit.minimumAccountStorage
: defines the minimum amount of storage_capacity
an address can have and also the amount every new account has. minimumAccountStorage
is a multiple of minimumStorageUnit
.flowPerByte
: defines the cost of 1 byte of storage in FLOW tokens.flowPerAccountCreation
: define the cost of purchasing the initial minimum storage in FLOW tokens.refundingEnabled
: defines if accounts can refund storageminimumAccountStorage
, refundingEnabled
, flowPerByte
and flowPerAccountCreation
should be able to change in the future.setupStorageForAccount(paymentVault, authAccount)
:
StorageCapacity
is already present on the account (if so panic; account already bought some storage).StorageCapacity
resource with minimumAccountStorage
and put the paymentVault
into it.StorageCapacity
resource onto the account with a corresponding receiver.purchaseStorageForAddress(paymentVault, address, amount)
:
StorageCapacity
is present on the address (if not so panic; account needs to buy initial storage first).minimumStorageUnit
(if not panic).paymentVault
. Should be flowPerByte
x amountStorageCapacity.depositStorage
on the destination account, increment its StorageCapacity.storageCapacity
and deposit paymentVault
into StorageCapacity.FlowVault
.refundStorage(authAccount, amount)
:
StorageCapacity
is present on the address (if not so panic; account needs to buy initial storage first)amount
is divisible by minimumStorageUnit
(if not panic)minimumAccountStorage
(if so panic)StorageCapacity.purchases
to determine how much Flow to return, withdraw from StorageCapacity.FlowVault
edit StorageCapacity.purchases
and reduce StorageCapacity.storageCapacity
Some users want to be able to query an account address to see if they operate a node
Add a public interface NodeInfoPublic
that exposes the nodeID for a node operator
NodeStaker
should implement this interface
Add a public interface DelegatorInfoPublic
that exposes the nodeID and delegatorID or a delegator
NodeDelegator
should implement this interface
Change transactions to create this public link when stakers are registered
Create Script to read this node info from a PublicAccount
Tests to make sure it all works
Document it all
There are various improvements we could make to the staking and locked tokens contracts. This is to track those.
We current have a go package for getting transaction templates, but we should also have a javascript package so users of the contracts can import and use the correct versions without having to copy and paste.
lib/go/javascript/templates
package that does a similar thing to the lib/go/templates
package.transactions/
as a source of truth, replace the import addresses with user provided addresses, and return the correct transaction texts.Would like to get this implemented soon because more organizations are using the transactions and scripts.
For epoch switchovers, we need to be able to perform all the epoch switchover operations in a single transaction so that new accounts cannot register in-between staking auction end and epoch end.
end_staking_auction.cdc
, pay_rewards.cdc
, and move_tokens.cdc
Need to change the storage fee contract to use the normal FlowToken Vault to track how much storage an account is allowed to use.
Remove everything from the contract except for the conversion field, minimum field, and admin resource to change those fields.
Set Up tests and templates to test the contract
Change the service account to use the normal FlowToken Vault instead of the special Storage Fee vault
Need to design and code a first draft of the staking helper contract
Requirements are outlined in this doc: https://www.notion.so/dapperlabs/Token-Staking-Process-6877e85a057e4eab8beae7f5187f3ffb
Add functionality to cancel a pending unstake request
There are some functions that get data about nodes and delegators that should be moved to their respective Info
structs.
getNodeCommittedBalanceWithoutDelegators
getNodeCommittedBalanceWithDelegators
getNodeStakedBalanceWithDelegators
getOnlyDelegatedBalance
Test the new cases
Document these new cases
An error is thrown by Cadence when attempting to register a new node with the central staking contract via the LockedTokens
contract.
amount
set to 50.0
Execution failed:
pre-condition failed: Amount withdrawn must be less than or equal than the balance of the Vault
Users with unlocked FLOW and locked FLOW want to be able to have a universal interface they can go through to stake their flow to multiple nodes/delegators in their account
StakingProxy
interfaces so that this staking collection can stake locked or unlocked tokens in the exact same way.Blocking ledger and flow port support for staking with unlocked FLOW
The staking reward needs to now be a proportion of all the tokens staked instead of the tokens staked for the node role.
New Reward(user) = Tr * (Sn / St)
Test with the correct delegation cut: 8%
Context:
Need to document events in the LockedTokens and Staking Proxy contract
Definition of Done:
Write an events page in the token docs site
With realistic node operator and delegator numbers (400 nodes, 10k delegators), iterating through all of them will break the gas limit by A LOT
When the DKG fails, it returns a key vector containing nil keys. Despite the failure, these key vectors should still be submitted to the smart contract. When deciding whether the DKG has completed, we should consider a key vector (final submission) containing any nil keys to be invalid, even if a majority of participants have submitted that key vector.
Array<Optional<String>>
and encode nil keys as nil or define a canonical serialization for a nil key (eg. 0x00...) coordinate with https://github.com/dapperlabs/flow-go/issues/5452EpochCommit
eventA balance of 10K Flow looks like this: balance: 1000000000000
Just checking that the minimums are right here:
We must see what the time to execute and gas usage is for 1000 nodes and 20k delegators on testnet
lib/go/test/flow_idtable_nodes_test.go
with 1000 nodes and 20k delegators on testnetend_epoch
and pay_rewards.cdc
transactions with all these registered users.Who is your Code Partner - @Kay-Zee
Who can provide external eyes - @psiemens
Need to be able to verify that an account address has registered with the token admin before we send tokens to them, which implies that they have a correctly set up locked tokens account.
Transaction:
The locked tokens transfer needs to make sure that the address it is sending to has been registered
Pre-condition in the deposit locked tokens function that makes sure it is registered in the admin collection
QC contract has been written but needs more thorough tests
For the intermediate stage of epochs before BFT is implemented, admin needs to be able to remove unapproved nodes before the staking auction ends
feature/epochs
branchendStakingAuction
that just removes unapproved nodes and doesn't end the auction.Need a service account smart contract to manage delegation and enforce rules for node operators.
Details are in https://www.notion.so/dapperlabs/Flow-Delegation-a39af01f4ccc4ce3abaf7614679b3824
User's node Info should be able to be queried from a script by using their address.
This would allow third parties to securely and reliably receive and manage locked tokens on a user's behalf.
Account Setup should have an option for the user agent to create only the User Account account 1
and the ability to request the creation of the Shared Account account 2
by Dapper Labs. This ensures Flow can safely and securely enforce token lock-ups without blocking community wallets from supporting people who hold locked Flow.
Add the ability for a user agent to request the flow token admin
(or some other Dapper Labs controlled account) creates account 2
(so that Dapper Labs does not have to trust or check that account 2
was created correctly by the user agent.
Following initial account creation, the process and interactions should be identical. The user and custody/wallet provider's roles, abilities, and interactions should be the same.
@psiemens options:
- Custodian is permitted to create the locked account, but only through a special method: FlowServiceAccount.createLockedAccount . This method would simply return the LockedTokens resource which the custodian can link into the unlocked account. We then know that the locked account was created properly
- Custodian is not permitted to create the locked account and instead places a LockedTokenReceiver in the unlocked account. We then create the locked account at the time of token delivery and connect it to the unlocked account with the receiver.
- The locked account is created automatically by the protocol when createAccount (AuthAccount(…)) is called. Every account receives a locked sidecar account by default
Option 1 considerations:
Currently custodians have account creator capability
Anyone unregisteered locked account is un-trusted
We could modify service account to have account creator capability - would return token manager resource which could be linked into public account - input would be users pubkey
tl;dr service account is account creator via pub.fun calling restricted code
Smart contract changes needed:
Other changes needed:
Option 2 considerations:
Complicates matters to not have both accounts exist immediately
Option 3 considerations:
Not all accounts need to receive locked tokens and this would create hidden complexity
Reference Documentation: https://docs.onflow.org/token/staking/locked/setup/
This would ensure the Blocto wallet could participate in supporting the initial token delivery.
Loading contracts for a script or transaction also has to load all the dictionary field values, so they need to be changed to use account storage instead.
Define paths to store the fields for addresses and keys used instead of fields
define path to store staking enabled field as well
Define utility functions to access these paths in storage
We want token holders to have the option to delegate their tokens to multiple nodes should they choose to.
This address the missing functionality identified in the current documentation :https://docs.onflow.org/token/staking/locked/delegators/
Reference text:
Note: This transaction delegates additional tokens to the same node that was registered in the setup phase. It is currently not possible to delegate to multiple nodes from the same account.
The storage fees smart contract overflows when the account balance times the MbPerFlow constant is more than max UFix64. When it overflows it results in the account storage capacity being 0.
Instead it should result in the account storage capacity being max UFix64.
This is not a problem for mainnet as the entire FLOW supply is not high enough.
When a node operator registers to stake, we should validate their public keys to ensure they are well-formed, using the updated Crypto
contract in Cadence (onflow/cadence#582).
Crypto.PublicKey
typeCurrently, we enforce that node info must be unique for each node, by iterating through the whole table and checking. This works, but is inefficient and uses a lot of gas, which could hurt normal users.
networkingAddress: Bool
, networkingKey: Bool
, stakingKey: Bool
to indicate if a key or address has been registered already.When the DKG fails, it returns a key vector containing nil keys. Despite the failure, these key vectors should still be submitted to the smart contract. When deciding whether the DKG has completed, we should consider a key vector (final submission) containing any nil keys to be invalid, even if a majority of participants have submitted that key vector.
Array<Optional<String>>
and encode nil keys as nil or define a canonical serialization for a nil key (eg. 0x00...) coordinate with https://github.com/dapperlabs/flow-go/issues/5452Needs docs in the locked tokens documentation to describe new capabilities with locked tokens
Currently the LockedTokens.LockedAccountInfo
interface includes these methods:
getNodeID
- node ID of a staked nodegetDelegatorID
- delegator IDHowever, in order to fetch delegator info from the central staking contract, we need both the delegator ID and the node ID being delegated to. The currently implementation doesn't provide the node ID that is being delegated to.
Add a getDelegatorNodeID
function to the LockedTokens.LockedAccountInfo
interface
This is currently blocking @JeffreyDoyle from testing delegation through Flow Port
Context:
We need a smart contract that will manage T-system's rewards.
Definition of Done:
@laynelafrance to provide specs
Need to deploy contracts/FlowIDTableStaking
on testnet and test with automated tests as well as manual tests.
The current behaviour of the FlowDKG
and EpochLifecycle
contracts is to stop the DKG for a given epoch once the threshold (50%) of key vector submissions is met. We can still consider the FlowDKG
complete once this threshold is reached, and emit the EpochCommit
event at this point, but we would like to continue allowing key vector submissions after the threshold has been met.
This allows us to have a better sense for the health of the DKG by seeing how many nodes submitted valid key vectors (and therefore can be reasonably expected to participate in consensus in the next epoch).
EpochLifecycle
- end DKG
immediately before transitioning to next epoch rather than when the DKG
reports being "done"LockedTokensDeposited is declared in LockedTokens but not emitted in the code. Is it meant to be emitted in deposit() or somewhere?
https://github.com/onflow/flow-core-contracts/blob/master/contracts/LockedTokens.cdc#L44
https://github.com/onflow/flow-core-contracts/blob/master/contracts/LockedTokens.cdc#L304
Based on the work that is done via ticket https://app.zenhub.com/workspaces/flow-5a2ad022cee40e25b0885f82/issues/dapperlabs/flow-internal/1467, we will need stored interactions that implement the transactions that were created via this ticket to ensure Flow Port can call these transactions successfully.
Write tests to test contract described in https://github.com/dapperlabs/flow-go/issues/4530
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.