Skip to content

Commit

Permalink
fix the spec and the template
Browse files Browse the repository at this point in the history
  • Loading branch information
konnov committed Dec 19, 2024
1 parent 4924f2c commit 5a72ef5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 13 additions & 4 deletions doc/case-studies/xycloans/MCxycloans_monitor.ejs.tla
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ XLM_TOKEN_SAC_TESTNET == "<%- storage[contractId].instance.TokenId %>"

\* user-controlled addresses
USER_ADDR == {
<%
const balanceAddrs =
Object.keys(storage[contractId].persistent)
.filter((key) => key.startsWith("Balance,"))
.map((key) => key.split(",")[1])
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])
%>
<%-
Object.keys(storage[contractId].persistent)
.filter((key) => key.startsWith("Balance,"))
.map((key) => key.split(",")[1])
.map((addr) => `"${addr}"`)
[...new Set(balanceAddrs.concat(tokenAddrs))]
.map((addr) => ` "${addr}"`)
.join(",\n ")
%>
}
Expand Down
17 changes: 11 additions & 6 deletions doc/case-studies/xycloans/xycloans_monitor.tla
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ initialize(tx) ==
\* @type: $tx => Bool;
deposit(tx) ==
LET call == AsDeposit(tx.call)
token == tx.env.storage.self_instance.TokenId
token == tx.env.old_storage.self_instance.TokenId
new_shares == [ shares EXCEPT ![call.from] = @ + call.amount ]
IN
/\ IsDeposit(tx.call)
Expand All @@ -86,9 +86,10 @@ deposit(tx) ==
\* these conditions are not required by a monitor, but needed to avoid spurious generated values
/\ succeeds_with(tx,
\A other \in DOMAIN tx.env.storage.self_persistent.Balance \ {call.from}:
/\ other \in DOMAIN tx.env.old_storage.self_persistent.Balance
/\ tx.env.storage.self_persistent.Balance[other] = tx.env.old_storage.self_persistent.Balance[other])
other \in DOMAIN tx.env.old_storage.self_persistent.Balance
=> tx.env.storage.self_persistent.Balance[other] = tx.env.old_storage.self_persistent.Balance[other])
/\ succeeds_with(tx, call.amount > 0)
/\ succeeds_with(tx, tx.env.storage.self_instance.TokenId = token)
\* update the monitor state
/\ shares' = new_shares
/\ total_shares' = total_shares + call.amount
Expand All @@ -97,6 +98,7 @@ deposit(tx) ==
\* @type: $tx => Bool;
borrow(tx) ==
LET call == AsBorrow(tx.call)
token == tx.env.old_storage.self_instance.TokenId
expected_fee == div_ceil(call.amount * STROOP, 12500000000)
expected_fee_per_share_universal ==
tx.env.old_storage.self_instance.FeePerShareUniversal
Expand All @@ -113,8 +115,9 @@ borrow(tx) ==
/\ succeeds_with(tx, token_balance(tx.env, rcvr) = old_token_balance(tx.env, rcvr) - call.amount)
/\ succeeds_with(tx, token_balance(tx.env, self) = old_token_balance(tx.env, self) + call.amount)
\* these conditions are not required by a monitor, but needed to avoid spurious generated values
/\ succeeds_with(tx, tx.env.storage.self_persistent = tx.env.old_storage.self_persistent)
\*/\ succeeds_with(tx, tx.env.storage.self_persistent = tx.env.old_storage.self_persistent)
/\ succeeds_with(tx, call.amount > 0)
/\ succeeds_with(tx, tx.env.storage.self_instance.TokenId = token)
\* update the monitor state
\* we update the fee per share to compute rewards later
/\ fee_per_share_universal' = expected_fee_per_share_universal
Expand All @@ -123,6 +126,7 @@ borrow(tx) ==
\* @type: $tx => Bool;
update_fee_rewards(tx) ==
LET call == AsUpdateFeeRewards(tx.call)
token == tx.env.old_storage.self_instance.TokenId
fees_not_yet_considered ==
fee_per_share_universal - get_or_else(tx.env.old_storage.self_persistent.FeePerShareParticular, call.addr, 0)
expected_reward == div_floor(get_or_else(shares, call.addr, 0) * fees_not_yet_considered, STROOP)
Expand All @@ -137,8 +141,9 @@ update_fee_rewards(tx) ==
\* delta of matured rewards for `addr` have been added
/\ expected_reward = actual_reward
\* these conditions are not required by a monitor, but needed to avoid spurious generated values
/\ succeeds_with(tx,
tx.env.storage.self_persistent.Balance = tx.env.old_storage.self_persistent.Balance)
\*/\ succeeds_with(tx,
\* tx.env.storage.self_persistent.Balance = tx.env.old_storage.self_persistent.Balance)
/\ succeeds_with(tx, tx.env.storage.self_instance.TokenId = token)
\* update the monitor state
/\ UNCHANGED <<shares, total_shares, fee_per_share_universal>>

Expand Down

0 comments on commit 5a72ef5

Please sign in to comment.