Skip to content

Commit

Permalink
fix the template
Browse files Browse the repository at this point in the history
  • Loading branch information
konnov committed Dec 20, 2024
1 parent 99f0739 commit 799af43
Showing 1 changed file with 49 additions and 48 deletions.
97 changes: 49 additions & 48 deletions doc/case-studies/xycloans/MCxycloans_monitor.ejs.tla
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@ XYCLOANS == "<%- contractId %>"
\* the token address
XLM_TOKEN_SAC_TESTNET == "<%- storage[contractId].instance.TokenId %>"

<%
const balanceAddrs =
Object.keys(storage[contractId].persistent)
.filter((key) => key.startsWith("Balance,"))
.map((key) => key.split(",")[1])
%>
\* user-controlled addresses
USER_ADDR == {
<%
const balanceAddrs =
Object.keys(storage[contractId].persistent)
.filter((key) => key.startsWith("Balance,"))
.map((key) => key.split(",")[1])
%>
<%-
<%-
balanceAddrs
.map((addr) => ` "${addr}"`)
.join(",\n ")
%>
.join(",\n")
%>
}

<%
const tokenAddrs =
Object.keys(storage[storage[contractId].instance.TokenId].persistent)
.filter((key) => key.startsWith("Balance,"))
.filter((key) => key !== `Balance,${contractId}`)
.map((key) => key.split(",")[1])
%>
\* addresses that hold token balances
TOKEN_ADDR == {
<%
const tokenAddrs =
Object.keys(storage[storage[contractId].instance.TokenId].persistent)
.filter((key) => key.startsWith("Balance,"))
.filter((key) => key !== `Balance,${contractId}`)
.map((key) => key.split(",")[1])
%>
<%-
<%-
tokenAddrs
.map((addr) => ` "${addr}"`)
.join(",\n ")
%>
.join(",\n")
%>
}

\* the pool of addresses to draw the values from
Expand All @@ -70,43 +70,44 @@ VARIABLES

INSTANCE xycloans_monitor

<%
function renderKVStore(storage, prefix, mapper = (x) => x) {
return Object.keys(storage)
.filter((key) => key.startsWith(prefix))
.map((key) => key.split(",")[1])
.map((addr) => ` <<"${addr}", ${mapper(storage[prefix + addr])}>>`)
.join(",\n")
}
%>

Init ==
LET init_stor == [
self_instance |-> [
FeePerShareUniversal |-> <%- storage[contractId].instance.FeePerShareUniversal %>,
TokenId |-> "<%- storage[contractId].instance.TokenId %>"
],
self_persistent |-> [
Balance |-> SetAsFun({<%-
Object.keys(storage[contractId].persistent)
.filter((key) => key.startsWith("Balance,"))
.map((key) => key.split(",")[1])
.map((addr) => `<<"${addr}", ${storage[contractId].persistent["Balance," + addr]}>>`)
.join(",\n ")
%>}),
MaturedFeesParticular |-> SetAsFun({<%-
Object.keys(storage[contractId].persistent)
.filter((key) => key.startsWith("MaturedFeesParticular,"))
.map((key) => key.split(",")[1])
.map((addr) => `<<"${addr}", ${storage[contractId].persistent["MaturedFeesParticular," + addr]}>>`)
.join(",\n ")
%>}),
FeePerShareParticular |-> SetAsFun({<%-
Object.keys(storage[contractId].persistent)
.filter((key) => key.startsWith("FeePerShareParticular,"))
.map((key) => key.split(",")[1])
.map((addr) => `<<"${addr}", ${storage[contractId].persistent["FeePerShareParticular," + addr]}>>`)
.join(",\n ")
%>})
Balance |-> SetAsFun({
<%-
renderKVStore(storage[contractId].persistent, "Balance,")
%>
}),
MaturedFeesParticular |-> SetAsFun({
<%-
renderKVStore(storage[contractId].persistent, "MaturedFeesParticular,")
%>
}),
FeePerShareParticular |-> SetAsFun({
<%-
renderKVStore(storage[contractId].persistent, "FeePerShareParticular,")
%>
})
],
token_persistent |-> [ Balance |-> SetAsFun({<%-
Object.keys(storage[storage[contractId].instance.TokenId].persistent)
.filter((key) => key.startsWith("Balance,"))
.map((key) => key.split(",")[1])
.map((addr) =>
`<<"${addr}", ${storage[storage[contractId].instance.TokenId].persistent["Balance," + addr].amount}>>`)
.join(",\n ")
%>})]
token_persistent |-> [ Balance |-> SetAsFun({
<%-
renderKVStore(storage[storage[contractId].instance.TokenId].persistent, "Balance,", (x) => x.amount)
%>
})]
]
IN
\* initialize the monitor non-deterministically
Expand Down

0 comments on commit 799af43

Please sign in to comment.