-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from 33-Labs/feature/staking_info
feat: staking info
- Loading branch information
Showing
7 changed files
with
447 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
import * as fcl from "@onflow/fcl" | ||
|
||
export const getEpochMetadata = async (epochCounter) => { | ||
const code = ` | ||
import FlowEpoch from 0x8624b52f9ddcd04a | ||
pub fun main(epochCounter: UInt64): FlowEpoch.EpochMetadata? { | ||
return FlowEpoch.getEpochMetadata(epochCounter) | ||
} | ||
` | ||
|
||
const result = await fcl.query({ | ||
cadence: code, | ||
args: (arg, t) => [ | ||
arg(epochCounter, t.UInt64) | ||
] | ||
}) | ||
|
||
return result | ||
} | ||
|
||
export const getStakingInfo = async (address) => { | ||
const code = ` | ||
import LockedTokens from 0x8d0e87b65159ae63 | ||
import FlowIDTableStaking from 0x8624b52f9ddcd04a | ||
import FlowEpoch from 0x8624b52f9ddcd04a | ||
pub struct EpochInfo { | ||
pub let currentEpochCounter: UInt64 | ||
pub let currentEpochPhase: UInt8 | ||
init( | ||
currentEpochCounter: UInt64, | ||
currentEpochPhase: UInt8 | ||
) { | ||
self.currentEpochCounter = currentEpochCounter | ||
self.currentEpochPhase = currentEpochPhase | ||
} | ||
} | ||
pub struct Result { | ||
pub let stakingInfo: StakingInfo? | ||
init(stakingInfo: StakingInfo?) { | ||
self.stakingInfo = stakingInfo | ||
} | ||
} | ||
pub struct StakingInfo { | ||
pub let epochInfo: EpochInfo | ||
pub let lockedAddress: Address | ||
pub let lockedBalance: UFix64 | ||
pub let unlockLimit: UFix64 | ||
pub let nodeInfo: NodeInfo? | ||
pub let delegatorInfo: DelegatorInfo? | ||
init( | ||
epochInfo: EpochInfo, | ||
lockedAddress: Address, | ||
lockedBalance: UFix64, | ||
unlockLimit: UFix64, | ||
nodeInfo: NodeInfo?, | ||
delegatorInfo: DelegatorInfo?, | ||
) { | ||
self.epochInfo = epochInfo | ||
self.lockedAddress = lockedAddress | ||
self.lockedBalance = lockedBalance | ||
self.unlockLimit = unlockLimit | ||
self.nodeInfo = nodeInfo | ||
self.delegatorInfo = delegatorInfo | ||
} | ||
} | ||
pub struct NodeInfo { | ||
pub let id: String | ||
pub let networkingAddress: String | ||
pub let role: UInt8 | ||
pub let tokensStaked: UFix64 | ||
pub let tokensCommitted: UFix64 | ||
pub let tokensUnstaking: UFix64 | ||
pub let tokensUnstaked: UFix64 | ||
pub let tokensRewarded: UFix64 | ||
pub let delegatorIDCounter: UInt32 | ||
pub let tokensRequestedToUnstake: UFix64 | ||
pub let initialWeight: UInt64 | ||
init(nodeID: String) { | ||
let nodeInfo = FlowIDTableStaking.NodeInfo(nodeID: nodeID) | ||
self.id = nodeInfo.id | ||
self.networkingAddress = nodeInfo.networkingAddress | ||
self.role = nodeInfo.role | ||
self.tokensStaked = nodeInfo.tokensStaked | ||
self.tokensCommitted = nodeInfo.tokensCommitted | ||
self.tokensUnstaking = nodeInfo.tokensUnstaking | ||
self.tokensUnstaked = nodeInfo.tokensUnstaked | ||
self.tokensRewarded = nodeInfo.tokensRewarded | ||
self.delegatorIDCounter = nodeInfo.delegatorIDCounter | ||
self.tokensRequestedToUnstake = nodeInfo.tokensRequestedToUnstake | ||
self.initialWeight = nodeInfo.initialWeight | ||
} | ||
} | ||
pub struct DelegatorInfo { | ||
pub let id: UInt32 | ||
pub let nodeID: String | ||
pub let tokensCommitted: UFix64 | ||
pub let tokensStaked: UFix64 | ||
pub let tokensUnstaking: UFix64 | ||
pub let tokensRewarded: UFix64 | ||
pub let tokensUnstaked: UFix64 | ||
pub let tokensRequestedToUnstake: UFix64 | ||
init(nodeID: String, delegatorID: UInt32) { | ||
let delegatorInfo = FlowIDTableStaking.DelegatorInfo(nodeID: nodeID, delegatorID: delegatorID) | ||
self.id = delegatorInfo.id | ||
self.nodeID = delegatorInfo.nodeID | ||
self.tokensCommitted = delegatorInfo.tokensCommitted | ||
self.tokensStaked = delegatorInfo.tokensStaked | ||
self.tokensUnstaking = delegatorInfo.tokensUnstaking | ||
self.tokensRewarded = delegatorInfo.tokensRewarded | ||
self.tokensUnstaked = delegatorInfo.tokensUnstaked | ||
self.tokensRequestedToUnstake = delegatorInfo.tokensRequestedToUnstake | ||
} | ||
} | ||
pub fun main(address: Address): Result { | ||
let tokenHolderRef = | ||
getAuthAccount(address) | ||
.borrow<&LockedTokens.TokenHolder>(from: LockedTokens.TokenHolderStoragePath) | ||
var stakingInfo: StakingInfo? = nil | ||
if let tokenHolder = tokenHolderRef { | ||
let lockedAddress = tokenHolder.getLockedAccountAddress() | ||
let lockedBalance = tokenHolder.getLockedAccountBalance() | ||
let unlockLimit = tokenHolder.getUnlockLimit() | ||
var nodeInfo: NodeInfo? = nil | ||
var delegatorInfo: DelegatorInfo? = nil | ||
if let delegatorNodeID = tokenHolder.getDelegatorNodeID() { | ||
if let delegatorID = tokenHolder.getDelegatorID() { | ||
nodeInfo = NodeInfo(nodeID: delegatorNodeID) | ||
delegatorInfo = DelegatorInfo(nodeID: delegatorNodeID, delegatorID: delegatorID) | ||
} | ||
} | ||
let epochInfo = EpochInfo( | ||
currentEpochCounter: FlowEpoch.currentEpochCounter, | ||
currentEpochPhase: FlowEpoch.currentEpochPhase.rawValue | ||
) | ||
stakingInfo = StakingInfo( | ||
epochInfo: epochInfo, | ||
lockedAddress: lockedAddress, | ||
lockedBalance: lockedBalance, | ||
unlockLimit: unlockLimit, | ||
nodeInfo: nodeInfo, | ||
delegatorInfo: delegatorInfo | ||
) | ||
} | ||
return Result(stakingInfo: stakingInfo) | ||
} | ||
` | ||
|
||
const result = await fcl.query({ | ||
cadence: code, | ||
args: (arg, t) => [ | ||
arg(address, t.Address) | ||
] | ||
}) | ||
|
||
return result | ||
} | ||
|
||
export const getNodeInfo = async (nodeID) => { | ||
const code = ` | ||
import FlowIDTableStaking from 0x8624b52f9ddcd04a | ||
pub fun main(nodeID: String): FlowIDTableStaking.NodeInfo { | ||
return FlowIDTableStaking.NodeInfo(nodeID: nodeID) | ||
} | ||
` | ||
|
||
const result = await fcl.query({ | ||
cadence: code, | ||
args: (arg, t) => [ | ||
arg(nodeID, t.String) | ||
] | ||
}) | ||
|
||
return result | ||
} | ||
|
||
export const getDelegatorInfo = async (nodeID, delegatorID) => { | ||
const code = ` | ||
import FlowIDTableStaking from 0x8624b52f9ddcd04a | ||
pub fun main(nodeID: String, delegatorID: UInt32): FlowIDTableStaking.DelegatorInfo { | ||
return FlowIDTableStaking.DelegatorInfo(nodeID: nodeID, delegatorID: delegatorID) | ||
} | ||
` | ||
|
||
const result = await fcl.query({ | ||
cadence: code, | ||
args: (arg, t) => [ | ||
arg(nodeID, t.String), | ||
arg(delegatorID, t.UInt32) | ||
] | ||
}) | ||
|
||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
93f839b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
flowview – ./
flowview-git-main-33lab.vercel.app
flowview.vercel.app
flowview-33lab.vercel.app
flowview.app
www.flowview.app