From 284f5b8ce01e07f97e7bc97e63d9cd8664f05812 Mon Sep 17 00:00:00 2001 From: Marton Lederer Date: Tue, 15 Jul 2025 10:08:45 +0200 Subject: [PATCH] feat: relocate delegation triggers --- src/liquidations/liquidate.lua | 4 ++++ src/process.lua | 14 +------------- src/supply/mint.lua | 4 ++++ src/supply/redeem.lua | 4 ++++ src/token/transfer.lua | 4 ++++ 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/liquidations/liquidate.lua b/src/liquidations/liquidate.lua index 129b5ee..80939c7 100644 --- a/src/liquidations/liquidate.lua +++ b/src/liquidations/liquidate.lua @@ -1,3 +1,4 @@ +local delegation = require ".supply.delegation" local assertions = require ".utils.assertions" local precision = require ".utils.precision" local interest = require ".borrow.interest" @@ -223,6 +224,9 @@ function mod.liquidatePosition(msg) "The liquidation target owns less oTokens than the supplied quantity's worth" ) + -- run delegation + delegation.delegate(msg) + -- liquidate position by updating the oToken quantities, etc. Balances[target] = tostring(balance - qtyValueInoToken) Cash = tostring(availableTokens - quantity) diff --git a/src/process.lua b/src/process.lua index 39257d6..5b6b540 100644 --- a/src/process.lua +++ b/src/process.lua @@ -127,19 +127,7 @@ local function setup_handlers() -- accrued AO distribution for actions that update oToken balances Handlers.add( "supply-delegate-ao", - function (msg) - local action = msg.Tags["X-Action"] or msg.Tags.Action - - if action == "Delegate" then return true end - if - action == "Mint" or - action == "Redeem" or - action == "Liquidate-Position" or - action == "Transfer" - then return "continue" end - - return false - end, + { Action = "Delegate" }, delegation.delegate ) diff --git a/src/supply/mint.lua b/src/supply/mint.lua index 67269ee..a27c7a4 100644 --- a/src/supply/mint.lua +++ b/src/supply/mint.lua @@ -1,3 +1,4 @@ +local delegation = require ".supply.delegation" local assertions = require ".utils.assertions" local precision = require ".utils.precision" local interest = require ".borrow.interest" @@ -26,6 +27,9 @@ function mint.handler(msg) "Mint quantity is above the allowed limit" ) + -- run delegation + delegation.delegate(msg) + -- transfer sender local sender = msg.Tags.Sender diff --git a/src/supply/redeem.lua b/src/supply/redeem.lua index c43dfeb..0661965 100644 --- a/src/supply/redeem.lua +++ b/src/supply/redeem.lua @@ -1,3 +1,4 @@ +local delegation = require ".supply.delegation" local assertions = require ".utils.assertions" local precision = require ".utils.precision" local position = require ".borrow.position" @@ -77,6 +78,9 @@ local function redeem(msg, _, oracle) "Redeem value is too high and requires higher collateralization" ) + -- run delegation + delegation.delegate(msg) + -- update stored quantities (balance, available, total supply) Balances[sender] = tostring(walletBalance - quantity) Cash = tostring(availableTokens - rewardQtyScaled) diff --git a/src/token/transfer.lua b/src/token/transfer.lua index b768387..a5a00e8 100644 --- a/src/token/transfer.lua +++ b/src/token/transfer.lua @@ -1,3 +1,4 @@ +local delegation = require ".supply.delegation" local assertions = require ".utils.assertions" local precision = require ".utils.precision" local position = require ".borrow.position" @@ -53,6 +54,9 @@ local function transfer(msg, _, oracle) "Transfer value is too high and requires higher collateralization" ) + -- run delegation + delegation.delegate(msg) + -- update balances Balances[target] = tostring(bint(Balances[target] or 0) + quantity) Balances[sender] = tostring(walletBalance - quantity)