Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devnet -> testnet - circulating supply event data #105

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ local ActionMap = {
CancelDelegateWithdrawal = "Cancel-Delegate-Withdrawal",
}

-- Low fidelity trackers
local lastKnownTotalSupply = 0
local lastKnownCirculatingSupply = 0
local lastKnownLockedSupply = 0
local lastKnownStakedSupply = 0
local lastKnownDelegatedSupply = 0
local lastKnownWithdrawSupply = 0

local function eventingPcall(ioEvent, onError, fnToCall, ...)
local status, result = pcall(fnToCall, ...)
if not status then
Expand Down Expand Up @@ -1335,41 +1343,59 @@ addEventingHandler("totalTokenSupply", utils.hasMatchingTag("Action", "Total-Tok
local delegatedSupply = 0
local withdrawSupply = 0
local protocolBalance = balances.getBalance(Protocol)
local balances = balances.getBalances()
for _, balance in pairs(balances) do
totalSupply = totalSupply + balance
local userBalances = balances.getBalances()

-- tally circulating supply
for _, balance in pairs(userBalances) do
circulatingSupply = circulatingSupply + balance
end
-- gateways and delegates
totalSupply = totalSupply + circulatingSupply

-- tally supply stashed in gateways and delegates
local gateways = gar.getGateways()
for _, gateway in pairs(gateways) do
totalSupply = totalSupply + gateway.operatorStake + gateway.totalDelegatedStake
stakedSupply = stakedSupply + gateway.operatorStake
delegatedSupply = delegatedSupply + gateway.totalDelegatedStake
for _, delegate in pairs(gateway.delegates) do
-- check vaults
-- tally delegates' vaults
for _, vault in pairs(delegate.vaults) do
totalSupply = totalSupply + vault.balance
withdrawSupply = withdrawSupply + vault.balance
end
end
-- iterate through vaults
-- tally gateway's own vaults
for _, vault in pairs(gateway.vaults) do
totalSupply = totalSupply + vault.balance
withdrawSupply = withdrawSupply + vault.balance
end
end

-- vaults
local vaults = vaults.getVaults()
for _, vaultsForAddress in pairs(vaults) do
-- user vaults
local userVaults = vaults.getVaults()
for _, vaultsForAddress in pairs(userVaults) do
-- they may have several vaults iterate through them
for _, vault in pairs(vaultsForAddress) do
totalSupply = totalSupply + vault.balance
lockedSupply = lockedSupply + vault.balance
end
end

lastKnownTotalSupply = totalSupply
lastKnownCirculatingSupply = circulatingSupply
lastKnownLockedSupply = lockedSupply
lastKnownStakedSupply = stakedSupply
lastKnownDelegatedSupply = delegatedSupply
lastKnownWithdrawSupply = withdrawSupply

msg.ioEvent:addField("Total-Token-Supply", lastKnownTotalSupply)
msg.ioEvent:addField("Circulating-Supply", lastKnownCirculatingSupply)
msg.ioEvent:addField("Locked-Supply", lastKnownLockedSupply)
msg.ioEvent:addField("Staked-Supply", lastKnownStakedSupply)
msg.ioEvent:addField("Delegated-Supply", lastKnownDelegatedSupply)
msg.ioEvent:addField("Withdraw-Supply", lastKnownWithdrawSupply)
msg.ioEvent:addField("Protocol-Balance", protocolBalance)

ao.send({
Target = msg.From,
Action = "Total-Token-Supply-Notice",
Expand Down
Loading