Skip to content

Commit

Permalink
staking del minimum for locked token register delegator
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Jun 26, 2023
1 parent 3a41da7 commit de95d0c
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 17 deletions.
9 changes: 7 additions & 2 deletions contracts/LockedTokens.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ pub contract LockedTokens {

let vaultRef = self.vault.borrow()!

assert(
vaultRef.balance >= FlowIDTableStaking.getDelegatorMinimumStakeRequirement(),
message: "Must have the delegation minimum FLOW requirement in the locked vault to register a node"
)

let tokens <- vaultRef.withdraw(amount: amount)

let delegator <- self.nodeDelegator <- FlowIDTableStaking.registerNewDelegator(nodeID: nodeID, tokensCommitted: <-tokens)
Expand Down Expand Up @@ -347,9 +352,9 @@ pub contract LockedTokens {

/// The user calls this function if they want to register as a node operator
/// They have to provide the node ID for the node they want to delegate to
pub fun createNodeDelegator(nodeID: String, amount: UFix64) {
pub fun createNodeDelegator(nodeID: String) {

self.borrowTokenManager().registerDelegator(nodeID: nodeID, amount: amount)
self.borrowTokenManager().registerDelegator(nodeID: nodeID, amount: FlowIDTableStaking.getDelegatorMinimumStakeRequirement())

// create a new delegator proxy that can be accessed in transactions
self.nodeDelegatorProxy = LockedNodeDelegatorProxy(tokenManager: self.tokenManager)
Expand Down
6 changes: 6 additions & 0 deletions contracts/testContracts/TestFlowIDTableStaking.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ pub contract FlowIDTableStaking {
return <-create NodeDelegator(id: 1, nodeID: nodeID)
}

/// Gets the minimum stake requirement for delegators
pub fun getDelegatorMinimumStakeRequirement(): UFix64 {
return self.account.copy<UFix64>(from: /storage/delegatorStakingMinimum)
?? 0.0
}

init(_ epochTokenPayout: UFix64, _ rewardCut: UFix64, _ candidateLimits: {UInt8: UInt64}) {
}
}
12 changes: 6 additions & 6 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

29 changes: 26 additions & 3 deletions lib/go/templates/internal/assets/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/go/templates/manifest.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@
{
"id": "TH.17",
"name": "Register Delegator",
"source": "import FlowToken from 0x1654653399040a61\nimport LockedTokens from 0x8d0e87b65159ae63\n\ntransaction(id: String, amount: UFix64) {\n\n let holderRef: \u0026LockedTokens.TokenHolder\n\n let vaultRef: \u0026FlowToken.Vault\n\n prepare(account: AuthAccount) {\n self.holderRef = account.borrow\u003c\u0026LockedTokens.TokenHolder\u003e(from: LockedTokens.TokenHolderStoragePath) \n ?? panic(\"TokenHolder is not saved at specified path\")\n\n self.vaultRef = account.borrow\u003c\u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault)\n ?? panic(\"Could not borrow flow token vault reference\")\n }\n\n execute {\n let lockedBalance = self.holderRef.getLockedAccountBalance()\n\n if amount \u003c= lockedBalance {\n\n self.holderRef.createNodeDelegator(nodeID: id, amount: amount)\n\n } else if ((amount - lockedBalance) \u003c= self.vaultRef.balance) {\n\n self.holderRef.deposit(from: \u003c-self.vaultRef.withdraw(amount: amount - lockedBalance))\n\n self.holderRef.createNodeDelegator(nodeID: id, amount: amount)\n\n } else {\n panic(\"Not enough tokens to stake!\")\n }\n }\n}\n",
"source": "import FlowToken from 0x1654653399040a61\nimport LockedTokens from 0x8d0e87b65159ae63\nimport FlowIDTableStaking from 0x8624b52f9ddcd04a\n\ntransaction(id: String, amount: UFix64) {\n\n let holderRef: \u0026LockedTokens.TokenHolder\n\n let vaultRef: \u0026FlowToken.Vault\n\n prepare(account: AuthAccount) {\n self.holderRef = account.borrow\u003c\u0026LockedTokens.TokenHolder\u003e(from: LockedTokens.TokenHolderStoragePath) \n ?? panic(\"TokenHolder is not saved at specified path\")\n\n self.vaultRef = account.borrow\u003c\u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault)\n ?? panic(\"Could not borrow flow token vault reference\")\n }\n\n execute {\n let lockedBalance = self.holderRef.getLockedAccountBalance()\n\n if amount \u003c= lockedBalance {\n\n self.holderRef.createNodeDelegator(nodeID: id)\n\n let stakerProxy = self.holderRef.borrowDelegator()\n\n stakerProxy.delegateNewTokens(amount: amount - FlowIDTableStaking.getDelegatorMinimumStakeRequirement())\n\n } else if ((amount - lockedBalance) \u003c= self.vaultRef.balance) {\n\n self.holderRef.deposit(from: \u003c-self.vaultRef.withdraw(amount: amount - lockedBalance))\n\n self.holderRef.createNodeDelegator(nodeID: id)\n\n let stakerProxy = self.holderRef.borrowDelegator()\n\n stakerProxy.delegateNewTokens(amount: amount - FlowIDTableStaking.getDelegatorMinimumStakeRequirement())\n\n } else {\n panic(\"Not enough tokens to stake!\")\n }\n }\n}\n",
"arguments": [
{
"type": "String",
Expand All @@ -315,7 +315,7 @@
}
],
"network": "mainnet",
"hash": "38b3863f83ae9920c3bedf6db9cbfb67c2c6f73fab7fa96c116511419d4cec3c"
"hash": "35bd380710b471bc5efb41b2f1e8538aec2985f3e2bf196d5b2846a7d2db89ec"
},
{
"id": "TH.19",
Expand Down
Loading

0 comments on commit de95d0c

Please sign in to comment.