1
1
import { ethers , upgrades } from "hardhat" ;
2
2
import { loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers" ;
3
3
import { expect } from "chai" ;
4
- import { DMock , usdFP , perpFP , lpAmtFP , percentageFP , priceFP } from "./helpers" ;
4
+ import { DMock , usdFP , perpFP , lpAmtFP , percFP , priceFP } from "./helpers" ;
5
5
6
6
describe ( "BillBroker" , function ( ) {
7
7
async function setupContracts ( ) {
@@ -14,16 +14,17 @@ describe("BillBroker", function () {
14
14
await usd . init ( "USD token" , "usd" , 6 ) ;
15
15
const perp = await Token . deploy ( ) ;
16
16
await perp . init ( "Perp token" , "perp" , 9 ) ;
17
- const pricingStrategy = new DMock ( "SpotAppraiser" ) ;
18
- await pricingStrategy . deploy ( ) ;
19
- await pricingStrategy . mockMethod ( "decimals()" , [ 18 ] ) ;
20
- await pricingStrategy . mockMethod ( "perpPrice()" , [ priceFP ( "1.15" ) , true ] ) ;
21
- await pricingStrategy . mockMethod ( "usdPrice()" , [ priceFP ( "1" ) , true ] ) ;
17
+ const oracle = new DMock ( "IPerpPricer" ) ;
18
+ await oracle . deploy ( ) ;
19
+ await oracle . mockMethod ( "decimals()" , [ 18 ] ) ;
20
+ await oracle . mockMethod ( "perpFmvUsdPrice()" , [ priceFP ( "1.15" ) , true ] ) ;
21
+ await oracle . mockMethod ( "usdPrice()" , [ priceFP ( "1" ) , true ] ) ;
22
+ await oracle . mockMethod ( "perpBeta()" , [ percFP ( "1" ) , true ] ) ;
22
23
23
24
const BillBroker = await ethers . getContractFactory ( "BillBroker" ) ;
24
25
const billBroker = await upgrades . deployProxy (
25
26
BillBroker . connect ( deployer ) ,
26
- [ "BillBroker LP" , "LP token" , usd . target , perp . target , pricingStrategy . target ] ,
27
+ [ "BillBroker LP" , "LP token" , usd . target , perp . target , oracle . target ] ,
27
28
{
28
29
initializer : "init(string,string,address,address,address)" ,
29
30
} ,
@@ -45,7 +46,7 @@ describe("BillBroker", function () {
45
46
await perp . mint ( await deployer . getAddress ( ) , perpFP ( "2000" ) ) ;
46
47
await usd . mint ( await otherUser . getAddress ( ) , usdFP ( "2000" ) ) ;
47
48
await perp . mint ( await otherUser . getAddress ( ) , perpFP ( "2000" ) ) ;
48
- return { deployer, otherUser, usd, perp, pricingStrategy , billBroker } ;
49
+ return { deployer, otherUser, usd, perp, oracle , billBroker } ;
49
50
}
50
51
51
52
async function assetRatio ( billBroker ) {
@@ -145,7 +146,7 @@ describe("BillBroker", function () {
145
146
perpFP ( "100" ) ,
146
147
) ;
147
148
await billBroker . updateFees ( {
148
- mintFeePerc : percentageFP ( "0.1" ) ,
149
+ mintFeePerc : percFP ( "0.1" ) ,
149
150
burnFeePerc : 0n ,
150
151
perpToUSDSwapFeePercs : {
151
152
lower : 0n ,
@@ -259,7 +260,7 @@ describe("BillBroker", function () {
259
260
perpFP ( "200" ) ,
260
261
) ;
261
262
await billBroker . updateFees ( {
262
- mintFeePerc : percentageFP ( "0.1" ) ,
263
+ mintFeePerc : percFP ( "0.1" ) ,
263
264
burnFeePerc : 0n ,
264
265
perpToUSDSwapFeePercs : {
265
266
lower : 0n ,
@@ -347,7 +348,7 @@ describe("BillBroker", function () {
347
348
perpFP ( "100" ) ,
348
349
) ;
349
350
await billBroker . updateFees ( {
350
- mintFeePerc : percentageFP ( "0.1" ) ,
351
+ mintFeePerc : percFP ( "0.1" ) ,
351
352
burnFeePerc : 0n ,
352
353
perpToUSDSwapFeePercs : {
353
354
lower : 0n ,
@@ -565,7 +566,7 @@ describe("BillBroker", function () {
565
566
it ( "should withhold fees and mint lp tokens" , async function ( ) {
566
567
const { billBroker, usd, perp, deployer } = await loadFixture ( setupContracts ) ;
567
568
await billBroker . updateFees ( {
568
- mintFeePerc : percentageFP ( "0.1" ) ,
569
+ mintFeePerc : percFP ( "0.1" ) ,
569
570
burnFeePerc : 0n ,
570
571
perpToUSDSwapFeePercs : {
571
572
lower : 0n ,
@@ -645,15 +646,14 @@ describe("BillBroker", function () {
645
646
it ( "should revert" , async function ( ) {
646
647
const { billBroker } = await loadFixture ( setupContracts ) ;
647
648
await billBroker . pause ( ) ;
648
- await expect ( billBroker . depositUSD ( usdFP ( "115" ) , percentageFP ( "1" ) ) ) . to . be
649
- . reverted ;
649
+ await expect ( billBroker . depositUSD ( usdFP ( "115" ) , percFP ( "1" ) ) ) . to . be . reverted ;
650
650
} ) ;
651
651
} ) ;
652
652
653
653
describe ( "when usdAmtIn is zero" , function ( ) {
654
654
it ( "should return zero" , async function ( ) {
655
655
const { billBroker } = await loadFixture ( setupContracts ) ;
656
- const r = await billBroker . depositUSD . staticCall ( 0n , percentageFP ( "1" ) ) ;
656
+ const r = await billBroker . depositUSD . staticCall ( 0n , percFP ( "1" ) ) ;
657
657
expect ( r ) . to . eq ( 0n ) ;
658
658
} ) ;
659
659
} ) ;
@@ -744,7 +744,7 @@ describe("BillBroker", function () {
744
744
745
745
await usd . approve ( billBroker . target , usdFP ( "10" ) ) ;
746
746
await expect (
747
- billBroker . depositUSD ( usdFP ( "10" ) , percentageFP ( "0.50" ) ) ,
747
+ billBroker . depositUSD ( usdFP ( "10" ) , percFP ( "0.50" ) ) ,
748
748
) . to . be . revertedWithCustomError ( billBroker , "SlippageTooHigh" ) ;
749
749
} ) ;
750
750
} ) ;
@@ -763,7 +763,7 @@ describe("BillBroker", function () {
763
763
764
764
await usd . approve ( billBroker . target , usdFP ( "10" ) ) ;
765
765
await expect ( ( ) =>
766
- billBroker . depositUSD ( usdFP ( "10" ) , percentageFP ( "1" ) ) ,
766
+ billBroker . depositUSD ( usdFP ( "10" ) , percFP ( "1" ) ) ,
767
767
) . to . changeTokenBalance ( usd , deployer , usdFP ( "-10" ) ) ;
768
768
} ) ;
769
769
@@ -780,7 +780,7 @@ describe("BillBroker", function () {
780
780
781
781
await usd . approve ( billBroker . target , usdFP ( "10" ) ) ;
782
782
await expect ( ( ) =>
783
- billBroker . depositUSD ( usdFP ( "10" ) , percentageFP ( "1" ) ) ,
783
+ billBroker . depositUSD ( usdFP ( "10" ) , percFP ( "1" ) ) ,
784
784
) . to . changeTokenBalance (
785
785
billBroker ,
786
786
deployer ,
@@ -803,7 +803,7 @@ describe("BillBroker", function () {
803
803
) ;
804
804
await usd . approve ( billBroker . target , usdFP ( "10" ) ) ;
805
805
const r = await billBroker . reserveState . staticCall ( ) ;
806
- await expect ( billBroker . depositUSD ( usdFP ( "10" ) , percentageFP ( "1" ) ) )
806
+ await expect ( billBroker . depositUSD ( usdFP ( "10" ) , percFP ( "1" ) ) )
807
807
. to . emit ( billBroker , "DepositUSD" )
808
808
. withArgs ( usdFP ( "10" ) , r ) ;
809
809
expect ( await billBroker . totalSupply ( ) ) . to . eq (
@@ -823,7 +823,7 @@ describe("BillBroker", function () {
823
823
) ;
824
824
825
825
await usd . approve ( billBroker . target , usdFP ( "10" ) ) ;
826
- const r = await billBroker . depositUSD . staticCall ( usdFP ( "10" ) , percentageFP ( "1" ) ) ;
826
+ const r = await billBroker . depositUSD . staticCall ( usdFP ( "10" ) , percFP ( "1" ) ) ;
827
827
expect ( r ) . to . eq ( lpAmtFP ( "9.130434782608695652173913" ) ) ;
828
828
} ) ;
829
829
} ) ;
@@ -832,7 +832,7 @@ describe("BillBroker", function () {
832
832
it ( "should withhold fees and mint lp tokens" , async function ( ) {
833
833
const { billBroker, usd, perp, deployer } = await loadFixture ( setupContracts ) ;
834
834
await billBroker . updateFees ( {
835
- mintFeePerc : percentageFP ( "0.1" ) ,
835
+ mintFeePerc : percFP ( "0.1" ) ,
836
836
burnFeePerc : 0n ,
837
837
perpToUSDSwapFeePercs : {
838
838
lower : 0n ,
@@ -856,7 +856,7 @@ describe("BillBroker", function () {
856
856
857
857
await usd . approve ( billBroker . target , usdFP ( "10" ) ) ;
858
858
await expect ( ( ) =>
859
- billBroker . depositUSD ( usdFP ( "10" ) , percentageFP ( "1" ) ) ,
859
+ billBroker . depositUSD ( usdFP ( "10" ) , percFP ( "1" ) ) ,
860
860
) . to . changeTokenBalance (
861
861
billBroker ,
862
862
deployer ,
@@ -871,15 +871,14 @@ describe("BillBroker", function () {
871
871
it ( "should revert" , async function ( ) {
872
872
const { billBroker } = await loadFixture ( setupContracts ) ;
873
873
await billBroker . pause ( ) ;
874
- await expect ( billBroker . depositPerp ( perpFP ( "100" ) , percentageFP ( "1" ) ) ) . to . be
875
- . reverted ;
874
+ await expect ( billBroker . depositPerp ( perpFP ( "100" ) , percFP ( "1" ) ) ) . to . be . reverted ;
876
875
} ) ;
877
876
} ) ;
878
877
879
878
describe ( "when perpAmtIn is zero" , function ( ) {
880
879
it ( "should return zero" , async function ( ) {
881
880
const { billBroker } = await loadFixture ( setupContracts ) ;
882
- const r = await billBroker . depositPerp . staticCall ( 0n , percentageFP ( "1" ) ) ;
881
+ const r = await billBroker . depositPerp . staticCall ( 0n , percFP ( "1" ) ) ;
883
882
expect ( r ) . to . eq ( 0n ) ;
884
883
} ) ;
885
884
} ) ;
@@ -959,7 +958,7 @@ describe("BillBroker", function () {
959
958
960
959
await perp . approve ( billBroker . target , perpFP ( "10" ) ) ;
961
960
await expect (
962
- billBroker . depositPerp ( perpFP ( "10" ) , percentageFP ( "1.85" ) ) ,
961
+ billBroker . depositPerp ( perpFP ( "10" ) , percFP ( "1.85" ) ) ,
963
962
) . to . be . revertedWithCustomError ( billBroker , "SlippageTooHigh" ) ;
964
963
} ) ;
965
964
} ) ;
@@ -978,7 +977,7 @@ describe("BillBroker", function () {
978
977
979
978
await perp . approve ( billBroker . target , perpFP ( "10" ) ) ;
980
979
await expect ( ( ) =>
981
- billBroker . depositPerp ( perpFP ( "10" ) , percentageFP ( "1" ) ) ,
980
+ billBroker . depositPerp ( perpFP ( "10" ) , percFP ( "1" ) ) ,
982
981
) . to . changeTokenBalance ( perp , deployer , perpFP ( "-10" ) ) ;
983
982
} ) ;
984
983
@@ -995,7 +994,7 @@ describe("BillBroker", function () {
995
994
996
995
await perp . approve ( billBroker . target , perpFP ( "10" ) ) ;
997
996
await expect ( ( ) =>
998
- billBroker . depositPerp ( perpFP ( "10" ) , percentageFP ( "1" ) ) ,
997
+ billBroker . depositPerp ( perpFP ( "10" ) , percFP ( "1" ) ) ,
999
998
) . to . changeTokenBalance ( billBroker , deployer , lpAmtFP ( "11" ) ) ;
1000
999
expect ( await billBroker . totalSupply ( ) ) . to . eq ( lpAmtFP ( "341" ) ) ;
1001
1000
} ) ;
@@ -1013,7 +1012,7 @@ describe("BillBroker", function () {
1013
1012
1014
1013
await perp . approve ( billBroker . target , perpFP ( "10" ) ) ;
1015
1014
const r = await billBroker . reserveState . staticCall ( ) ;
1016
- await expect ( billBroker . depositPerp ( perpFP ( "10" ) , percentageFP ( "1" ) ) )
1015
+ await expect ( billBroker . depositPerp ( perpFP ( "10" ) , percFP ( "1" ) ) )
1017
1016
. to . emit ( billBroker , "DepositPerp" )
1018
1017
. withArgs ( perpFP ( "10" ) , r ) ;
1019
1018
expect ( await billBroker . totalSupply ( ) ) . to . eq ( lpAmtFP ( "341" ) ) ;
@@ -1031,10 +1030,7 @@ describe("BillBroker", function () {
1031
1030
) ;
1032
1031
1033
1032
await perp . approve ( billBroker . target , perpFP ( "10" ) ) ;
1034
- const r = await billBroker . depositPerp . staticCall (
1035
- perpFP ( "10" ) ,
1036
- percentageFP ( "1" ) ,
1037
- ) ;
1033
+ const r = await billBroker . depositPerp . staticCall ( perpFP ( "10" ) , percFP ( "1" ) ) ;
1038
1034
expect ( r ) . to . eq ( lpAmtFP ( "11" ) ) ;
1039
1035
} ) ;
1040
1036
} ) ;
@@ -1052,7 +1048,7 @@ describe("BillBroker", function () {
1052
1048
) ;
1053
1049
1054
1050
await billBroker . updateFees ( {
1055
- mintFeePerc : percentageFP ( "0.1" ) ,
1051
+ mintFeePerc : percFP ( "0.1" ) ,
1056
1052
burnFeePerc : 0n ,
1057
1053
perpToUSDSwapFeePercs : {
1058
1054
lower : 0n ,
@@ -1066,7 +1062,7 @@ describe("BillBroker", function () {
1066
1062
} ) ;
1067
1063
await perp . approve ( billBroker . target , perpFP ( "10" ) ) ;
1068
1064
await expect ( ( ) =>
1069
- billBroker . depositPerp ( perpFP ( "10" ) , percentageFP ( "1" ) ) ,
1065
+ billBroker . depositPerp ( perpFP ( "10" ) , percFP ( "1" ) ) ,
1070
1066
) . to . changeTokenBalance ( billBroker , deployer , lpAmtFP ( "9.9" ) ) ;
1071
1067
} ) ;
1072
1068
} ) ;
@@ -1129,7 +1125,7 @@ describe("BillBroker", function () {
1129
1125
const { billBroker, usd, perp } = await loadFixture ( setupContracts ) ;
1130
1126
await billBroker . updateFees ( {
1131
1127
mintFeePerc : 0n ,
1132
- burnFeePerc : percentageFP ( "0.1" ) ,
1128
+ burnFeePerc : percFP ( "0.1" ) ,
1133
1129
perpToUSDSwapFeePercs : {
1134
1130
lower : 0n ,
1135
1131
upper : 0n ,
@@ -1170,15 +1166,7 @@ describe("BillBroker", function () {
1170
1166
await billBroker . swapUSDForPerps ( usdFP ( "115" ) , 0n ) ;
1171
1167
expect ( await perp . balanceOf ( billBroker . target ) ) . to . eq ( 0n ) ;
1172
1168
1173
- const s = await billBroker . reserveState . staticCall ( ) ;
1174
- expect (
1175
- await billBroker . assetRatio ( {
1176
- usdBalance : s [ 0 ] ,
1177
- perpBalance : s [ 1 ] ,
1178
- usdPrice : s [ 2 ] ,
1179
- perpPrice : s [ 3 ] ,
1180
- } ) ,
1181
- ) . to . eq ( ethers . MaxUint256 ) ;
1169
+ expect ( await assetRatio ( billBroker ) ) . to . eq ( ethers . MaxUint256 ) ;
1182
1170
1183
1171
const r = await billBroker . computeRedemptionAmts . staticCall ( lpAmtFP ( "100" ) ) ;
1184
1172
expect ( r [ 0 ] ) . to . eq ( usdFP ( "106.976744" ) ) ;
@@ -1202,15 +1190,7 @@ describe("BillBroker", function () {
1202
1190
await billBroker . swapPerpsForUSD ( perpFP ( "100" ) , 0n ) ;
1203
1191
expect ( await usd . balanceOf ( billBroker . target ) ) . to . eq ( 0n ) ;
1204
1192
1205
- const s = await billBroker . reserveState . staticCall ( ) ;
1206
- expect (
1207
- await billBroker . assetRatio ( {
1208
- usdBalance : s [ 0 ] ,
1209
- perpBalance : s [ 1 ] ,
1210
- usdPrice : s [ 2 ] ,
1211
- perpPrice : s [ 3 ] ,
1212
- } ) ,
1213
- ) . to . eq ( 0 ) ;
1193
+ expect ( await assetRatio ( billBroker ) ) . to . eq ( 0 ) ;
1214
1194
1215
1195
const r = await billBroker . computeRedemptionAmts . staticCall ( lpAmtFP ( "100" ) ) ;
1216
1196
expect ( r [ 0 ] ) . to . eq ( 0n ) ;
@@ -1426,15 +1406,7 @@ describe("BillBroker", function () {
1426
1406
await billBroker . swapUSDForPerps ( usdFP ( "115" ) , 0n ) ;
1427
1407
expect ( await perp . balanceOf ( billBroker . target ) ) . to . eq ( 0n ) ;
1428
1408
1429
- const s = await billBroker . reserveState . staticCall ( ) ;
1430
- expect (
1431
- await billBroker . assetRatio ( {
1432
- usdBalance : s [ 0 ] ,
1433
- perpBalance : s [ 1 ] ,
1434
- usdPrice : s [ 2 ] ,
1435
- perpPrice : s [ 3 ] ,
1436
- } ) ,
1437
- ) . to . eq ( ethers . MaxUint256 ) ;
1409
+ expect ( await assetRatio ( billBroker ) ) . to . eq ( ethers . MaxUint256 ) ;
1438
1410
1439
1411
const perpBal = await perp . balanceOf ( await deployer . getAddress ( ) ) ;
1440
1412
await expect ( ( ) => billBroker . redeem ( lpAmtFP ( "100" ) ) ) . to . changeTokenBalance (
@@ -1463,15 +1435,7 @@ describe("BillBroker", function () {
1463
1435
await billBroker . swapPerpsForUSD ( perpFP ( "100" ) , 0n ) ;
1464
1436
expect ( await usd . balanceOf ( billBroker . target ) ) . to . eq ( 0n ) ;
1465
1437
1466
- const s = await billBroker . reserveState . staticCall ( ) ;
1467
- expect (
1468
- await billBroker . assetRatio ( {
1469
- usdBalance : s [ 0 ] ,
1470
- perpBalance : s [ 1 ] ,
1471
- usdPrice : s [ 2 ] ,
1472
- perpPrice : s [ 3 ] ,
1473
- } ) ,
1474
- ) . to . eq ( 0 ) ;
1438
+ expect ( await assetRatio ( billBroker ) ) . to . eq ( 0 ) ;
1475
1439
1476
1440
const usdBal = await usd . balanceOf ( await deployer . getAddress ( ) ) ;
1477
1441
await expect ( ( ) => billBroker . redeem ( lpAmtFP ( "100" ) ) ) . to . changeTokenBalance (
0 commit comments