-
Notifications
You must be signed in to change notification settings - Fork 4
/
ERC4626.sol
807 lines (639 loc) · 26.5 KB
/
ERC4626.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.25;
// ## ERC4626 Type Wrapper
//
// This type wraps the address primitive type and contains functions to call the core ERC4626 interface
// without allocating new memory. Functions perform returndata validation.
//
// All external calls that fail will revert internally. This is to simplify the API.
type ERC4626 is address;
using {
asset,
totalAssets,
convertToShares,
convertToAssets,
maxDeposit,
previewDeposit,
deposit,
maxMint,
previewMint,
mint,
maxWithdraw,
previewWithdraw,
withdraw,
maxRedeem,
previewRedeem,
redeem,
totalSupply,
balanceOf,
allowance,
transfer,
transferFrom,
approve,
// -- operators
eq as ==,
neq as !=,
gt as >,
gte as >=,
lt as <,
lte as <=,
add as +,
sub as -,
mul as *,
div as /,
mod as %,
and as &,
or as |,
xor as ^,
not as ~
} for ERC4626 global;
// -------------------------------------------------------------------------------------------------
// Query ERC4626.asset without allocating new memory.
//
// Procedures:
// 01. store asset selector in memory
// 02. staticcall asset; cache as ok
// 03. check that the return value is 32 bytes; compose with ok
// 04. revert if ok is false
// 05. assign returned value to output
function asset(ERC4626 erc4626) view returns (address output) {
assembly ("memory-safe") {
mstore(0x00, 0x38d52e0f00000000000000000000000000000000000000000000000000000000)
let ok := staticcall(gas(), erc4626, 0x00, 0x04, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.totalAssets without allocating new memory.
//
// Procedures:
// 01. store totalAssets selector in memory
// 02. staticcall totalAssets; cache as ok
// 03. check that the return value is 32 bytes; compose with ok
// 04. revert if ok is false
// 05. assign returned value to output
function totalAssets(ERC4626 erc4626) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0x01e1d11400000000000000000000000000000000000000000000000000000000)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.convertToShares without allocating new memory.
//
// Procedures:
// 01. store convertToShares selector in memory
// 02. store assets in memory
// 03. staticcall convertToShares; cache as ok
// 04. check that the return value is 32 bytes; compose with ok
// 05. revert if ok is false
// 06. assign returned value to output
function convertToShares(ERC4626 erc4626, uint256 assets) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0xc6e6f59200000000000000000000000000000000000000000000000000000000)
mstore(0x04, assets)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.convertToAssets without allocating new memory.
//
// Procedures:
// 01. store convertToAssets selector in memory
// 02. store shares in memory
// 03. staticcall convertToAssets; cache as ok
// 04. check that the return value is 32 bytes; compose with ok
// 05. revert if ok is false
// 06. assign returned value to output
function convertToAssets(ERC4626 erc4626, uint256 shares) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0x07a2d13a00000000000000000000000000000000000000000000000000000000)
mstore(0x04, shares)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.maxDeposit without allocating new memory.
//
// Procedures:
// 01. store maxDeposit selector in memory
// 02. store receiver in memory
// 03. staticcall maxDeposit; cache as ok
// 04. check that the return value is 32 bytes; compose with ok
// 05. revert if ok is false
// 06. assign returned value to output
function maxDeposit(ERC4626 erc4626, address receiver) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0x402d267d00000000000000000000000000000000000000000000000000000000)
mstore(0x04, receiver)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.previewDeposit without allocating new memory.
//
// Procedures:
// 01. store previewDeposit selector in memory
// 02. store assets in memory
// 03. staticcall previewDeposit; cache as ok
// 04. check that the return value is 32 bytes; compose with ok
// 05. revert if ok is false
// 06. assign returned value to output
function previewDeposit(ERC4626 erc4626, uint256 assets) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0xef8b30f700000000000000000000000000000000000000000000000000000000)
mstore(0x04, assets)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Call ERC4626.deposit without allocating new memory.
//
// Procedures:
// 01. store previewMint selector in memory
// 02. store receiver in memory
// 03. store assets in memory
// 04. call deposit; cache as ok
// 05. check that the return value is 32 bytes; compose with ok
// 06. revert if ok is false
// 07. assign returned value to output
// 08. restore the upper bits of the free memory pointer to zero
function deposit(ERC4626 erc4626, uint256 assets, address receiver) returns (uint256 output) {
assembly {
mstore(0x00, 0x6e553f6500000000000000000000000000000000000000000000000000000000)
mstore(0x04, assets)
mstore(0x24, receiver)
let ok := call(gas(), erc4626, 0x00, 0x00, 0x44, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
mstore(0x24, 0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.maxMint without allocating new memory.
//
// Procedures:
// 01. store maxMint selector in memory
// 02. store receiver in memory
// 03. staticcall maxMint; cache as ok
// 04. check that the return value is 32 bytes; compose with ok
// 05. revert if ok is false
// 06. assign returned value to output
function maxMint(ERC4626 erc4626, address receiver) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0xc63d75b600000000000000000000000000000000000000000000000000000000)
mstore(0x04, receiver)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.previewMint without allocating new memory.
//
// Procedures:
// 01. store previewMint selector in memory
// 02. store shares in memory
// 03. staticcall previewMint; cache as ok
// 04. check that the return value is 32 bytes; compose with ok
// 05. revert if ok is false
// 06. assign returned value to output
function previewMint(ERC4626 erc4626, uint256 shares) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0xb3d7f6b900000000000000000000000000000000000000000000000000000000)
mstore(0x04, shares)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Call ERC4626.mint without allocating new memory.
//
// Procedures:
// 01. store mint selector in memory
// 02. store shares in memory
// 03. store receiver in memory
// 04. call mint; cache as ok
// 05. check that the return value is 32 bytes; compose with ok
// 06. revert if ok is false
// 07. assign returned value to output
// 08. restore the upper bits of the free memory pointer to zero
function mint(ERC4626 erc4626, uint256 shares, address receiver) returns (uint256 output) {
assembly {
mstore(0x00, 0x94bf804d00000000000000000000000000000000000000000000000000000000)
mstore(0x04, shares)
mstore(0x24, receiver)
let ok := call(gas(), erc4626, 0x00, 0x00, 0x44, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
mstore(0x24, 0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.maxWithdraw without allocating new memory.
//
// Procedures:
// 01. store maxWithdraw selector in memory
// 02. store owner in memory
// 03. staticcall maxWithdraw; cache as ok
// 04. check that the return value is 32 bytes; compose with ok
// 05. revert if ok is false
// 06. assign returned value to output
function maxWithdraw(ERC4626 erc4626, address owner) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0xce96cb7700000000000000000000000000000000000000000000000000000000)
mstore(0x04, owner)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.previewWithdraw without allocating new memory.
//
// Procedures:
// 01. store previewWithdraw selector in memory
// 02. store assets in memory
// 03. staticcall previewWithdraw; cache as ok
// 04. check that the return value is 32 bytes; compose with ok
// 05. revert if ok is false
// 06. assign returned value to output
function previewWithdraw(ERC4626 erc4626, uint256 assets) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0x0a28a47700000000000000000000000000000000000000000000000000000000)
mstore(0x04, assets)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Call ERC4626.withdraw without allocating new memory.
//
// Procedures:
// 01. load free memory pointer; cache as fmp
// 02. store withdraw selector in memory
// 03. store assets in memory
// 04. store receiver in memory
// 05. store owner in memory
// 06. call withdraw; cache as ok
// 07. check that the return value is 32 bytes; compose with ok
// 08. revert if ok is false
// 09. assign returned value to output
// 10. restore the free memory pointer to fmp
// 11. restore the zero slot to zero
function withdraw(ERC4626 erc4626, uint256 assets, address receiver, address owner) returns (uint256 output) {
assembly {
let fmp := mload(0x40)
mstore(0x00, 0xb460af9400000000000000000000000000000000000000000000000000000000)
mstore(0x04, assets)
mstore(0x24, receiver)
mstore(0x44, owner)
let ok := call(gas(), erc4626, 0x00, 0x00, 0x64, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
mstore(0x40, fmp)
mstore(0x60, 0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.maxRedeem without allocating new memory.
//
// Procedures:
// 01. store maxRedeem selector in memory
// 02. store owner in memory
// 03. staticcall maxRedeem; cache as ok
// 04. check that the return value is 32 bytes; compose with ok
// 05. revert if ok is false
// 06. assign returned value to output
function maxRedeem(ERC4626 erc4626, address owner) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0xd905777e00000000000000000000000000000000000000000000000000000000)
mstore(0x04, owner)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.previewRedeem without allocating new memory.
//
// Procedures:
// 01. store previewRedeem selector in memory
// 02. store shares in memory
// 03. staticcall previewRedeem; cache as ok
// 04. check that the return value is 32 bytes; compose with ok
// 05. revert if ok is false
// 06. assign returned value to output
function previewRedeem(ERC4626 erc4626, uint256 shares) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0x4cdad50600000000000000000000000000000000000000000000000000000000)
mstore(0x04, shares)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Call ERC4626.redeem without allocating new memory.
//
// Procedures:
// 01. load free memory pointer; cache as fmp
// 02. store redeem selector in memory
// 03. store shares in memory
// 04. store receiver in memory
// 05. store owner in memory
// 06. call redeem; cache as ok
// 07. check that the return value is 32 bytes; compose with ok
// 08. revert if ok is false
// 09. assign returned value to output
// 10. restore the free memory pointer to fmp
// 11. restore the zero slot to zero
function redeem(ERC4626 erc4626, uint256 shares, address receiver, address owner) returns (uint256 output) {
assembly {
let fmp := mload(0x40)
mstore(0x00, 0xba08765200000000000000000000000000000000000000000000000000000000)
mstore(0x04, shares)
mstore(0x24, receiver)
mstore(0x44, owner)
let ok := call(gas(), erc4626, 0x00, 0x00, 0x64, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
mstore(0x40, fmp)
mstore(0x60, 0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.totalSupply without allocating new memory.
//
// Procedures:
// 01. store totalSupply selector in memory
// 02. staticcall totalSupply; cache as ok
// 03. check that the return value is 32 bytes; compose with ok
// 04. revert if ok is false
// 05. assign returned value to output
function totalSupply(ERC4626 erc4626) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0x18160ddd00000000000000000000000000000000000000000000000000000000)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.balanceOf without allocating new memory.
//
// Procedures:
// 01. store balanceOf selector in memory
// 02. store owner address in memory
// 03. staticcall balanceOf; cache as ok
// 04. check that the return value is 32 bytes; compose with ok
// 05. revert if ok is false
// 06. assign returned value to output
function balanceOf(ERC4626 erc4626, address owner) view returns (uint256 output) {
assembly ("memory-safe") {
mstore(0x00, 0x70a0823100000000000000000000000000000000000000000000000000000000)
mstore(0x04, owner)
let ok := staticcall(gas(), erc4626, 0x00, 0x24, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Query ERC4626.allowance without allocating new memory.
//
// Procedures:
// 01. store allowance selector in memory
// 02. store owner address in memory
// 03. store spender address in memory
// 04. staticcall allowance; cache as ok
// 05. check that the return value is 32 bytes; compose with ok
// 06. revert if ok is false
// 07. assign returned value to output
// 08. restore the upper bits of the free memory pointer to zero
function allowance(ERC4626 erc4626, address owner, address spender) view returns (uint256 output) {
assembly {
mstore(0x00, 0xdd62ed3e00000000000000000000000000000000000000000000000000000000)
mstore(0x04, owner)
mstore(0x24, spender)
let ok := staticcall(gas(), erc4626, 0x00, 0x44, 0x00, 0x20)
ok := and(ok, eq(returndatasize(), 0x20))
if iszero(ok) { revert(0x00, 0x00) }
output := mload(0x00)
mstore(0x24, 0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Call ERC4626.transfer without allocating new memory.
//
// Procedures:
// 01. store transfer selector in memory
// 02. store recipient address in memory
// 03. store amount in memory
// 04. call transfer; cache as ok
// 05. check that either no data was returned or the data is 32 bytes and true; compose with ok
// 06. revert if ok is false
// 07. restore the upper bits of the free memory pointer to zero
function transfer(ERC4626 erc4626, address receiver, uint256 amount) {
assembly {
mstore(0x00, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(0x04, receiver)
mstore(0x24, amount)
let ok := call(gas(), erc4626, 0x00, 0x00, 0x44, 0x00, 0x20)
ok := and(ok, or(iszero(returndatasize()), and(eq(returndatasize(), 0x20), mload(0x00))))
if iszero(ok) { revert(0x00, 0x00) }
mstore(0x24, 0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Call ERC4626.transferFrom without allocating new memory.
//
// Procedures:
// 01. load the free memory pointer; cache as fmp
// 02. store transferFrom selector in memory
// 03. store sender address in memory
// 04. store recipient address in memory
// 05. store amount in memory
// 06. call transferFrom; cache as ok
// 07. check that either no data was returned or the data is 32 bytes and true; compose with ok
// 08. revert if ok is false
// 09. restore the free memory pointer to fmp
// 10. restore the zero slot to zero
function transferFrom(ERC4626 erc4626, address sender, address receiver, uint256 amount) {
assembly {
let fmp := mload(0x40)
mstore(0x00, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(0x04, sender)
mstore(0x24, receiver)
mstore(0x44, amount)
let ok := call(gas(), erc4626, 0x00, 0x00, 0x64, 0x00, 0x20)
ok := and(ok, or(iszero(returndatasize()), and(eq(returndatasize(), 0x20), mload(0x00))))
if iszero(ok) { revert(0x00, 0x00) }
mstore(0x40, fmp)
mstore(0x60, 0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Call ERC4626.approve without allocating new memory.
//
// Procedures:
// 01. store approve selector in memory
// 02. store spender address in memory
// 03. store amount in memory
// 04. call approve; cache as ok
// 05. check that either no data was returned or the data is 32 bytes and true; compose with ok
// 06. revert if ok is false
// 07. restore the upper bits of the free memory pointer to zero
function approve(ERC4626 erc4626, address spender, uint256 amount) {
assembly {
mstore(0x00, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(0x04, spender)
mstore(0x24, amount)
let ok := call(gas(), erc4626, 0x00, 0x00, 0x44, 0x00, 0x20)
ok := and(ok, or(iszero(returndatasize()), and(eq(returndatasize(), 0x20), mload(0x00))))
if iszero(ok) { revert(0x00, 0x00) }
mstore(0x24, 0x00)
}
}
// -------------------------------------------------------------------------------------------------
// Returns `true` if the two ERC4626 instances are equal, `false` otherwise.
function eq(ERC4626 lhs, ERC4626 rhs) pure returns (bool output) {
assembly {
output := eq(lhs, rhs)
}
}
// -------------------------------------------------------------------------------------------------
// Returns `true` if the two ERC4626 instances are not equal, `false` otherwise.
function neq(ERC4626 lhs, ERC4626 rhs) pure returns (bool output) {
assembly {
output := iszero(eq(lhs, rhs))
}
}
// -------------------------------------------------------------------------------------------------
// Returns `true` if `lhs` is greater than `rhs`, `false` otherwise.
function gt(ERC4626 lhs, ERC4626 rhs) pure returns (bool output) {
assembly {
output := gt(lhs, rhs)
}
}
// -------------------------------------------------------------------------------------------------
// Returns `true` if `lhs` is greater than or equal to `rhs`, `false` otherwise.
function gte(ERC4626 lhs, ERC4626 rhs) pure returns (bool output) {
assembly {
output := iszero(lt(lhs, rhs))
}
}
// -------------------------------------------------------------------------------------------------
// Returns `true` if `lhs` is less than `rhs`, `false` otherwise.
function lt(ERC4626 lhs, ERC4626 rhs) pure returns (bool output) {
assembly {
output := lt(lhs, rhs)
}
}
// -------------------------------------------------------------------------------------------------
// Returns `true` if `lhs` is less than or equal to `rhs`, `false` otherwise.
function lte(ERC4626 lhs, ERC4626 rhs) pure returns (bool output) {
assembly {
output := iszero(gt(lhs, rhs))
}
}
// -------------------------------------------------------------------------------------------------
// Returns the sum of two ERC4626 instances.
function add(ERC4626 lhs, ERC4626 rhs) pure returns (ERC4626 output) {
assembly {
output := add(lhs, rhs)
if gt(output, 0xffffffffffffffffffffffffffffffffffffffff) { revert(0x00, 0x00) }
}
}
// -------------------------------------------------------------------------------------------------
// Returns the difference of two ERC4626 instances.
function sub(ERC4626 lhs, ERC4626 rhs) pure returns (ERC4626 output) {
assembly {
output := sub(lhs, rhs)
if gt(output, 0xffffffffffffffffffffffffffffffffffffffff) { revert(0x00, 0x00) }
}
}
// -------------------------------------------------------------------------------------------------
// Returns the product of two ERC4626 instances.
function mul(ERC4626 lhs, ERC4626 rhs) pure returns (ERC4626 output) {
assembly {
if lhs {
output := and(mul(lhs, rhs), 0xffffffffffffffffffffffffffffffffffffffff)
if iszero(eq(div(output, lhs), rhs)) { revert(0x00, 0x00) }
}
}
}
// -------------------------------------------------------------------------------------------------
// Returns the division of two ERC4626 instances.
function div(ERC4626 lhs, ERC4626 rhs) pure returns (ERC4626 output) {
assembly {
if iszero(rhs) { revert(0x00, 0x00) }
output := div(lhs, rhs)
}
}
// -------------------------------------------------------------------------------------------------
// Returns the modulus of two ERC4626 instances.
function mod(ERC4626 lhs, ERC4626 rhs) pure returns (ERC4626 output) {
assembly {
if iszero(rhs) { revert(0x00, 0x00) }
output := mod(lhs, rhs)
}
}
// -------------------------------------------------------------------------------------------------
// Returns the bitwise AND of two ERC4626 instances.
function and(ERC4626 lhs, ERC4626 rhs) pure returns (ERC4626 output) {
assembly {
output := and(lhs, rhs)
}
}
// -------------------------------------------------------------------------------------------------
// Returns the bitwise OR of two ERC4626 instances.
function or(ERC4626 lhs, ERC4626 rhs) pure returns (ERC4626 output) {
assembly {
output := or(lhs, rhs)
}
}
// -------------------------------------------------------------------------------------------------
// Returns the bitwise XOR of two ERC4626 instances.
function xor(ERC4626 lhs, ERC4626 rhs) pure returns (ERC4626 output) {
assembly {
output := xor(lhs, rhs)
}
}
// -------------------------------------------------------------------------------------------------
// Returns the bitwise NOT of an ERC4626 instance.
function not(ERC4626 lhs) pure returns (ERC4626 output) {
assembly {
output := and(not(lhs), 0xffffffffffffffffffffffffffffffffffffffff)
}
}