Skip to content

Commit 7cf9945

Browse files
Merge pull request #40 from useLiquidOps/feat/summarize-patch
Summerize patching
2 parents e3ffd72 + 30e3b42 commit 7cf9945

16 files changed

Lines changed: 50 additions & 35 deletions

File tree

__tests__/token.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ describe("Token standard functionalities", () => {
681681
const res = await handle(
682682
generateOracleResponse({ BTC: 85325.425 }, oracleRes)
683683
);
684-
684+
685685
expect(res.Messages).toEqual(
686686
expect.arrayContaining([
687687
expect.objectContaining({

src/borrow/borrow.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ function mod.borrow(msg, _, oracle)
9494
" " ..
9595
CollateralTicker
9696
)
97-
ao.send({
98-
device = "patch@1.0",
97+
patch({
9998
["pool-state"] = {
10099
cash = precision.formatInternalAsNative(Cash, "rounddown"),
101100
["total-borrows"] = precision.formatInternalAsNative(TotalBorrows, "roundup"),

src/borrow/interest.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ function mod.accrueInterest(msg)
170170
ReservesRemainder = tostring(remainder)
171171

172172
-- patch the updated globals
173-
ao.send({
174-
device = "patch@1.0",
173+
patch({
175174
["pool-state"] = {
176175
["total-borrows"] = precision.formatInternalAsNative(TotalBorrows, "roundup"),
177176
["total-reserves"] = precision.formatInternalAsNative(Reserves, "roundup"),
@@ -212,8 +211,7 @@ function mod.accrueInterestForUser(address)
212211
InterestIndices[address] = tostring(interestIndex)
213212

214213
-- patch updated global values
215-
ao.send({
216-
device = "patch@1.0",
214+
patch({
217215
loans = { [address] = Loans[address] },
218216
["interest-indices"] = { [address] = InterestIndices[address] },
219217
-- !!do not update positions to avoid an infinite recursive loop!!

src/borrow/repay.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ function repay.repayToPool(target, quantity)
159159
TotalBorrows = tostring(bint(TotalBorrows) - precision.toInternalPrecision(actualRepaidQty))
160160

161161
-- patch the updated globals
162-
ao.send({
163-
device = "patch@1.0",
162+
patch({
164163
["pool-state"] = {
165164
cash = precision.formatInternalAsNative(Cash, "rounddown"),
166165
["total-borrows"] = precision.formatInternalAsNative(TotalBorrows, "roundup"),

src/controller/config.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ function mod.update(msg)
111111
if newAOToken then AOToken = newAOToken end
112112

113113
-- patch
114-
ao.send({
115-
device = "patch@1.0",
114+
patch({
116115
environment = {
117116
["risk-parameters"] = {
118117
["collateral-factor"] = CollateralFactor,
@@ -173,8 +172,7 @@ function mod.toggleInteractions(msg)
173172
-- patch
174173
local enabledInteractions, disabledInteractions = patching.utils.interactionsState()
175174

176-
ao.send({
177-
device = "patch@1.0",
175+
patch({
178176
environment = {
179177
limits = {
180178
["enabled-interactions"] = enabledInteractions,

src/controller/cooldown.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ function mod.gate(msg)
4949
Cooldowns[sender] = msg["Block-Height"] + CooldownPeriod
5050

5151
-- patch
52-
ao.send({
53-
device = "patch@1.0",
52+
patch({
5453
cooldowns = { [sender] = Cooldowns[sender] }
5554
})
5655
end

src/controller/friend.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local assertions = require ".utils.assertions"
2+
local patching = require ".token.patching"
23
local utils = require ".utils.utils"
34
local json = require "json"
45

@@ -52,8 +53,7 @@ function friend.add(msg)
5253
})
5354

5455
-- patch
55-
ao.send({
56-
device = "patch@1.0",
56+
patch({
5757
environment = { friends = Friends }
5858
})
5959

@@ -89,8 +89,7 @@ function friend.remove(msg)
8989
assert(#removed > 0, "Friend " .. target .. " not yet added")
9090

9191
-- patch
92-
ao.send({
93-
device = "patch@1.0",
92+
patch({
9493
environment = { friends = Friends }
9594
})
9695

src/controller/reserves.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local assertions = require ".utils.assertions"
22
local precision = require ".utils.precision"
3+
local patching = require ".token.patching"
34
local bint = require ".utils.bint"(1024)
45

56
local mod = {}
@@ -66,8 +67,7 @@ function mod.deploy(msg)
6667
Cash = tostring(bint(Cash) + quantity)
6768

6869
-- patch
69-
ao.send({
70-
device = "patch@1.0",
70+
patch({
7171
["pool-state"] = {
7272
cash = precision.formatInternalAsNative(Cash, "rounddown"),
7373
["total-reserves"] = precision.formatInternalAsNative(Reserves, "roundup")

src/liquidations/liquidate.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ function mod.liquidatePosition(msg)
243243
})
244244

245245
-- patch
246-
ao.send({
247-
device = "patch@1.0",
246+
patch({
248247
["token-info"] = { supply = TotalSupply },
249248
["pool-state"] = {
250249
cash = precision.formatInternalAsNative(Cash, "rounddown"),

src/process.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ require(".utils.assignment").init(ao)
77
local process = { _version = "0.0.1" }
88

99
local coroutine = require "coroutine"
10+
local utils = require ".utils.utils"
11+
12+
patch = function (data) utils.patch_table(PatchData or {}, data) end
1013

1114
local friend = require ".controller.friend"
1215
local config = require ".controller.config"
@@ -34,7 +37,6 @@ local rate = require ".supply.rate"
3437
local redeem = require ".supply.redeem"
3538
local delegation = require ".supply.delegation"
3639

37-
local utils = require ".utils.utils"
3840
local precision = require ".utils.precision"
3941

4042
HandlersAdded = HandlersAdded or false
@@ -380,8 +382,6 @@ function process.handle(msg, env)
380382
if not status then
381383
-- call default error handler
382384
Handlers.defaultErrorHandler(msg, env, result)
383-
384-
return ao.result()
385385
end
386386

387387
return ao.result()

0 commit comments

Comments
 (0)