Skip to content

Commit

Permalink
refactor: optimize cover/uncover 1 -> swap as part of teal optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-makerx committed Jun 17, 2024
1 parent 9b4e82d commit 49d366e
Show file tree
Hide file tree
Showing 170 changed files with 12,001 additions and 11,990 deletions.
52 changes: 26 additions & 26 deletions examples/amm/out/ConstantProductAMM.approval.mir

Large diffs are not rendered by default.

46 changes: 23 additions & 23 deletions examples/amm/out_unoptimized/ConstantProductAMM.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ main_bootstrap_route@5:
callsub bootstrap
itob
byte 0x151f7c75
swap
uncover 1
concat
log
int 1
Expand Down Expand Up @@ -242,7 +242,7 @@ main_bare_routing@11:
// class ConstantProductAMM(ARC4Contract):
txn OnCompletion
int 0
swap
uncover 1
match main_create@12
b main_reject_bare_on_completion@13

Expand Down Expand Up @@ -357,7 +357,7 @@ bootstrap:
// self.pool_token = self._create_pool_token()
callsub _create_pool_token
byte "pool_token"
swap
uncover 1
app_global_put
// amm/contract.py:77
// self._do_opt_in(self.asset_a)
Expand Down Expand Up @@ -408,7 +408,7 @@ _create_pool_token:
asset_params_get AssetUnitName
assert // asset exists
byte "DPT-"
swap
uncover 1
concat
byte "-"
concat
Expand Down Expand Up @@ -581,7 +581,7 @@ mint:
app_global_get_ex
assert // check pool_token exists
frame_dig -3
swap
uncover 1
==
assert // asset pool incorrect
// amm/contract.py:115
Expand All @@ -591,7 +591,7 @@ mint:
app_global_get_ex
assert // check asset_a exists
frame_dig -2
swap
uncover 1
==
assert // asset a incorrect
// amm/contract.py:116
Expand All @@ -601,7 +601,7 @@ mint:
app_global_get_ex
assert // check asset_b exists
frame_dig -1
swap
uncover 1
==
assert // asset b incorrect
// amm/contract.py:117
Expand Down Expand Up @@ -880,7 +880,7 @@ tokens_to_mint_after_if_else@6:
// amm/contract.py:338
// return a_ratio * issued // SCALE
frame_dig 0
swap
uncover 1
*
int 1000
/
Expand All @@ -891,7 +891,7 @@ tokens_to_mint_else_body@8:
// amm/contract.py:340
// return b_ratio * issued // SCALE
frame_dig 1
swap
uncover 1
*
int 1000
/
Expand All @@ -911,15 +911,15 @@ _update_ratio:
// amm/contract.py:258
// b_balance = self._current_b_balance()
callsub _current_b_balance
swap
cover 1
// amm/contract.py:260
// self.ratio = a_balance * SCALE // b_balance
int 1000
*
swap
uncover 1
/
byte "ratio"
swap
uncover 1
app_global_put
retsub

Expand Down Expand Up @@ -952,7 +952,7 @@ burn:
app_global_get_ex
assert // check pool_token exists
frame_dig -3
swap
uncover 1
==
assert // asset pool incorrect
// amm/contract.py:173
Expand All @@ -962,7 +962,7 @@ burn:
app_global_get_ex
assert // check asset_a exists
frame_dig -2
swap
uncover 1
==
assert // asset a incorrect
// amm/contract.py:174
Expand All @@ -972,7 +972,7 @@ burn:
app_global_get_ex
assert // check asset_b exists
frame_dig -1
swap
uncover 1
==
assert // asset b incorrect
// amm/contract.py:177
Expand Down Expand Up @@ -1032,7 +1032,7 @@ burn:
uncover 2
uncover 2
callsub tokens_to_burn
swap
cover 1
// amm/contract.py:193
// supply=self._current_b_balance(),
callsub _current_b_balance
Expand All @@ -1050,7 +1050,7 @@ burn:
uncover 2
uncover 2
callsub tokens_to_burn
swap
cover 1
// amm/contract.py:197-198
// # Send back commensurate amt of a
// do_asset_transfer(receiver=Txn.sender, asset=self.asset_a, amount=a_amt)
Expand Down Expand Up @@ -1095,7 +1095,7 @@ tokens_to_burn:
frame_dig -2
frame_dig -1
*
swap
uncover 1
/
retsub

Expand Down Expand Up @@ -1128,7 +1128,7 @@ swap:
app_global_get_ex
assert // check asset_a exists
frame_dig -2
swap
uncover 1
==
assert // asset a incorrect
// amm/contract.py:226
Expand All @@ -1138,7 +1138,7 @@ swap:
app_global_get_ex
assert // check asset_b exists
frame_dig -1
swap
uncover 1
==
assert // asset b incorrect
// amm/contract.py:228
Expand Down Expand Up @@ -1272,7 +1272,7 @@ tokens_to_swap:
frame_dig -3
-
int 1000
swap
uncover 1
*
frame_dig -3
int 995
Expand All @@ -1287,7 +1287,7 @@ tokens_to_swap:
*
// amm/contract.py:353
// return out_total // in_total
swap
uncover 1
/
retsub

Expand All @@ -1314,7 +1314,7 @@ __init__:
// self.governor = Txn.sender
txn Sender
byte "governor"
swap
uncover 1
app_global_put
// amm/contract.py:38-39
// # The asset id of the Pool Token, used to track share of pool the holder may recover
Expand Down
4 changes: 2 additions & 2 deletions examples/arc-28/out/EventEmitter.approval.mir
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ main_abi_routing@1:
txna ApplicationArgs 0 // {txna} class EventEmitter(ARC4Contract): arc-28/contract.py:9
// virtual: store tmp%1#0 to l-stack (no copy) tmp%1#0 class EventEmitter(ARC4Contract): arc-28/contract.py:9
method "emit_swapped(uint64,uint64)void" // tmp%1#0,method<"emit_swapped(uint64,uint64)void"> class EventEmitter(ARC4Contract): arc-28/contract.py:9
swap // load tmp%1#0 from l-stack (no copy) method<"emit_swapped(uint64,uint64)void">,tmp%1#0 class EventEmitter(ARC4Contract): arc-28/contract.py:9
uncover 1 // load tmp%1#0 from l-stack (no copy) method<"emit_swapped(uint64,uint64)void">,tmp%1#0 class EventEmitter(ARC4Contract): arc-28/contract.py:9
match main_emit_swapped_route@2 // class EventEmitter(ARC4Contract): arc-28/contract.py:9
err // reject transaction // class EventEmitter(ARC4Contract): arc-28/contract.py:9

Expand Down Expand Up @@ -69,7 +69,7 @@ emit_swapped_block@0:
concat // (𝕡) a#0,b#0 | {concat} Swapped(b, a) arc-28/contract.py:12
// virtual: store encoded_tuple_buffer%2#0 to l-stack (no copy) (𝕡) a#0,b#0 | encoded_tuple_buffer%2#0 Swapped(b, a) arc-28/contract.py:12
method "Swapped(uint64,uint64)" // (𝕡) a#0,b#0 | encoded_tuple_buffer%2#0,method<"Swapped(uint64,uint64)"> arc4.emit(Swapped(b, a)) arc-28/contract.py:12
swap // load encoded_tuple_buffer%2#0 from l-stack (no copy) (𝕡) a#0,b#0 | method<"Swapped(uint64,uint64)">,encoded_tuple_buffer%2#0 arc4.emit(Swapped(b, a)) arc-28/contract.py:12
uncover 1 // load encoded_tuple_buffer%2#0 from l-stack (no copy) (𝕡) a#0,b#0 | method<"Swapped(uint64,uint64)">,encoded_tuple_buffer%2#0 arc4.emit(Swapped(b, a)) arc-28/contract.py:12
concat // (𝕡) a#0,b#0 | {concat} arc4.emit(Swapped(b, a)) arc-28/contract.py:12
// virtual: store tmp%0#0 to l-stack (no copy) (𝕡) a#0,b#0 | tmp%0#0 arc4.emit(Swapped(b, a)) arc-28/contract.py:12
dup // load tmp%0#0 from l-stack (copy) (𝕡) a#0,b#0 | tmp%0#0,tmp%0#0 arc4.emit(Swapped(b, a)) arc-28/contract.py:12
Expand Down
10 changes: 5 additions & 5 deletions examples/arc-28/out_unoptimized/EventEmitter.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ contract.EventEmitter.approval_program:
bz main_bare_routing@5
txna ApplicationArgs 0
method "emit_swapped(uint64,uint64)void"
swap
uncover 1
match main_emit_swapped_route@2
b main_switch_case_default@3

Expand Down Expand Up @@ -40,7 +40,7 @@ main_bare_routing@5:
// class EventEmitter(ARC4Contract):
txn OnCompletion
int 0
swap
uncover 1
match main_create@6
b main_reject_bare_on_completion@7

Expand Down Expand Up @@ -73,7 +73,7 @@ emit_swapped:
frame_dig -2
concat
method "Swapped(uint64,uint64)"
swap
uncover 1
concat
log
// arc-28/contract.py:13
Expand All @@ -84,7 +84,7 @@ emit_swapped:
frame_dig -2
concat
method "Swapped(uint64,uint64)"
swap
uncover 1
concat
log
// arc-28/contract.py:14
Expand All @@ -95,7 +95,7 @@ emit_swapped:
frame_dig -2
concat
method "Swapped(uint64,uint64)"
swap
uncover 1
concat
log
retsub
Loading

0 comments on commit 49d366e

Please sign in to comment.