@@ -894,6 +894,16 @@ describe("BridgePool", () => {
894
894
. send ( { from : disputer } ) ;
895
895
896
896
assert ( await didContractThrow ( bridgePool . methods . settleRelay ( depositData ) . send ( { from : relayer } ) ) ) ;
897
+
898
+ // Cannot settle even if disputed price was resolved.
899
+ const price = toWei ( "1" ) ;
900
+ const stampedDisputeAncillaryData = await optimisticOracle . methods
901
+ . stampAncillaryData ( relayAncillaryData , bridgePool . options . address )
902
+ . call ( ) ;
903
+ await mockOracle . methods
904
+ . pushPrice ( defaultIdentifier , relayStatus . priceRequestTime . toString ( ) , stampedDisputeAncillaryData , price )
905
+ . send ( { from : owner } ) ;
906
+ assert ( await didContractThrow ( bridgePool . methods . settleRelay ( depositData ) . send ( { from : relayer } ) ) ) ;
897
907
} ) ;
898
908
it ( "Can settle pending relays that passed challenge period" , async ( ) => {
899
909
// Cache price request timestamp.
@@ -931,41 +941,8 @@ describe("BridgePool", () => {
931
941
) ;
932
942
assert ( await didContractThrow ( bridgePool . methods . settleRelay ( depositData ) . send ( { from : relayer } ) ) ) ;
933
943
934
- // Expire and settle proposal on the OptimisticOracle .
944
+ // Set time such that optimistic price request is settleable .
935
945
await timer . methods . setCurrentTime ( expectedExpirationTimestamp ) . send ( { from : owner } ) ;
936
- await optimisticOracle . methods
937
- . settle (
938
- bridgePool . options . address ,
939
- defaultIdentifier ,
940
- relayStatus . priceRequestTime . toString ( ) ,
941
- relayAncillaryData
942
- )
943
- . send ( { from : relayer } ) ;
944
-
945
- // Verify price is available.
946
- assert . equal (
947
- await optimisticOracle . methods
948
- . hasPrice (
949
- bridgePool . options . address ,
950
- defaultIdentifier ,
951
- relayStatus . priceRequestTime . toString ( ) ,
952
- relayAncillaryData
953
- )
954
- . call ( ) ,
955
- true
956
- ) ;
957
-
958
- // If the relay status is PENDING and the price is available, then the value must match the original proposal:
959
- // 1e18.
960
- assert . equal ( relayStatus . relayState , InsuredBridgeRelayStateEnum . PENDING ) ;
961
- assert . equal (
962
- (
963
- await optimisticOracle . methods
964
- . settleAndGetPrice ( defaultIdentifier , relayStatus . priceRequestTime . toString ( ) , relayAncillaryData )
965
- . call ( { from : bridgePool . options . address } )
966
- ) . toString ( ) ,
967
- toWei ( "1" )
968
- ) ;
969
946
970
947
// Settle relay and check event logs.
971
948
const settleTxn = await bridgePool . methods . settleRelay ( depositData ) . send ( { from : rando } ) ;
@@ -1029,22 +1006,13 @@ describe("BridgePool", () => {
1029
1006
relayData . realizedLpFeePct
1030
1007
)
1031
1008
. send ( { from : relayer } ) ;
1032
- const relayStatus = await bridgePool . methods . relays ( depositHash ) . call ( ) ;
1033
1009
1034
1010
// Speed up relay.
1035
1011
await l1Token . methods . approve ( bridgePool . options . address , slowRelayAmountSubFee ) . send ( { from : instantRelayer } ) ;
1036
1012
await bridgePool . methods . speedUpRelay ( depositData ) . send ( { from : instantRelayer } ) ;
1037
1013
1038
- // Expire and settle proposal on the OptimisticOracle .
1014
+ // Set time such that optimistic price request is settleable .
1039
1015
await timer . methods . setCurrentTime ( expectedExpirationTimestamp ) . send ( { from : owner } ) ;
1040
- await optimisticOracle . methods
1041
- . settle (
1042
- bridgePool . options . address ,
1043
- defaultIdentifier ,
1044
- relayStatus . priceRequestTime . toString ( ) ,
1045
- relayAncillaryData
1046
- )
1047
- . send ( { from : relayer } ) ;
1048
1016
1049
1017
const relayerBalanceBefore = await l1Token . methods . balanceOf ( relayer ) . call ( ) ;
1050
1018
const instantRelayerBalanceBefore = await l1Token . methods . balanceOf ( instantRelayer ) . call ( ) ;
@@ -1059,8 +1027,8 @@ describe("BridgePool", () => {
1059
1027
toBN ( await l1Token . methods . balanceOf ( relayer ) . call ( ) )
1060
1028
. sub ( toBN ( relayerBalanceBefore ) )
1061
1029
. toString ( ) ,
1062
- realizedSlowRelayFeeAmount . toString ( ) ,
1063
- "Slow relayer should receive proposal slow relay reward"
1030
+ toBN ( totalRelayBond ) . add ( realizedSlowRelayFeeAmount ) . toString ( ) ,
1031
+ "Slow relayer should receive proposal bond + slow relay reward"
1064
1032
) ;
1065
1033
assert . equal (
1066
1034
toBN ( await l1Token . methods . balanceOf ( instantRelayer ) . call ( ) )
@@ -1082,6 +1050,42 @@ describe("BridgePool", () => {
1082
1050
"BridgePool should have balance reduced by relayed amount to recipient"
1083
1051
) ;
1084
1052
} ) ;
1053
+ it ( "Does not revert if price was already settled on OptimisticOracle" , async ( ) => {
1054
+ // Cache price request timestamp.
1055
+ const requestTimestamp = ( await bridgePool . methods . getCurrentTime ( ) . call ( ) ) . toString ( ) ;
1056
+ const expectedExpirationTimestamp = ( Number ( requestTimestamp ) + defaultLiveness ) . toString ( ) ;
1057
+
1058
+ // Proposer approves pool to withdraw total bond.
1059
+ await l1Token . methods . approve ( bridgePool . options . address , totalRelayBond ) . send ( { from : relayer } ) ;
1060
+ await bridgePool . methods
1061
+ . relayDeposit (
1062
+ depositData . depositId ,
1063
+ depositData . depositTimestamp ,
1064
+ depositData . recipient ,
1065
+ depositData . l2Sender ,
1066
+ depositData . amount ,
1067
+ depositData . slowRelayFeePct ,
1068
+ depositData . instantRelayFeePct ,
1069
+ depositData . quoteTimestamp ,
1070
+ relayData . realizedLpFeePct
1071
+ )
1072
+ . send ( { from : relayer } ) ;
1073
+ const relayStatus = await bridgePool . methods . relays ( depositHash ) . call ( ) ;
1074
+
1075
+ // Settle price directly via optimistic oracle
1076
+ await timer . methods . setCurrentTime ( expectedExpirationTimestamp ) . send ( { from : owner } ) ;
1077
+ await optimisticOracle . methods
1078
+ . settle (
1079
+ bridgePool . options . address ,
1080
+ defaultIdentifier ,
1081
+ relayStatus . priceRequestTime . toString ( ) ,
1082
+ relayAncillaryData
1083
+ )
1084
+ . send ( { from : rando } ) ;
1085
+
1086
+ // Settle relay and check event logs.
1087
+ assert . ok ( await bridgePool . methods . settleRelay ( depositData ) . send ( { from : rando } ) , "SettleRelay reverted" ) ;
1088
+ } ) ;
1085
1089
} ) ;
1086
1090
describe ( "Liquidity provision" , ( ) => {
1087
1091
beforeEach ( async function ( ) {
@@ -1182,20 +1186,11 @@ describe("BridgePool", () => {
1182
1186
1183
1187
// Next, finalize the bridging action. This should reset the pendingReserves to 0 and increment the utilizedReserves.
1184
1188
// Expire and settle proposal on the OptimisticOracle.
1185
- const relayStatus = await bridgePool . methods . relays ( depositHash ) . call ( ) ;
1186
-
1187
1189
await timer . methods
1188
1190
. setCurrentTime ( Number ( await bridgePool . methods . getCurrentTime ( ) . call ( ) ) + defaultLiveness )
1189
1191
. send ( { from : owner } ) ;
1190
- await optimisticOracle . methods
1191
- . settle (
1192
- bridgePool . options . address ,
1193
- defaultIdentifier ,
1194
- relayStatus . priceRequestTime . toString ( ) ,
1195
- relayAncillaryData
1196
- )
1197
- . send ( { from : relayer } ) ;
1198
1192
await bridgePool . methods . settleRelay ( depositData ) . send ( { from : rando } ) ;
1193
+
1199
1194
// Check the balances have updated correctly. Pending should be 0 (funds are actually utilized now), liquid should
1200
1195
// be equal to the LP fee of 10 and the utilized should equal the total bridged amount (100).
1201
1196
assert . equal ( await bridgePool . methods . pendingReserves ( ) . call ( ) , "0" ) ;
@@ -1247,20 +1242,10 @@ describe("BridgePool", () => {
1247
1242
. send ( { from : relayer } ) ;
1248
1243
1249
1244
// Expire and settle proposal on the OptimisticOracle.
1250
- const relayStatus = await bridgePool . methods . relays ( depositHash ) . call ( ) ;
1251
1245
await timer . methods . setCurrentTime ( expectedExpirationTimestamp ) . send ( { from : owner } ) ;
1252
- await optimisticOracle . methods
1253
- . settle (
1254
- bridgePool . options . address ,
1255
- defaultIdentifier ,
1256
- relayStatus . priceRequestTime . toString ( ) ,
1257
- relayAncillaryData
1258
- )
1259
- . send ( { from : relayer } ) ;
1246
+ await bridgePool . methods . settleRelay ( depositData ) . send ( { from : rando } ) ;
1260
1247
} ) ;
1261
1248
it ( "SettleRelay modifies virtual balances" , async ( ) => {
1262
- await bridgePool . methods . settleRelay ( depositData ) . send ( { from : rando } ) ;
1263
-
1264
1249
// Exchange rate should still be 1, no fees accumulated yet as no time has passed from the settlement. Pool
1265
1250
// balance, liquidReserves and utilizedReserves should update accordingly. Calculate the bridge tokens used as
1266
1251
// the amount sent to the receiver+the bond.
@@ -1282,8 +1267,6 @@ describe("BridgePool", () => {
1282
1267
) ;
1283
1268
} ) ;
1284
1269
it ( "Fees correctly accumulate to LPs over the one week loan interval" , async ( ) => {
1285
- await bridgePool . methods . settleRelay ( depositData ) . send ( { from : rando } ) ;
1286
-
1287
1270
await bridgePool . methods . exchangeRateCurrent ( ) . send ( { from : rando } ) ; // force sync
1288
1271
1289
1272
// As no time has elapsed, no fees should be earned and the exchange rate should still be 1.
@@ -1340,8 +1323,6 @@ describe("BridgePool", () => {
1340
1323
assert . equal ( ( await bridgePool . methods . undistributedLpFees ( ) . call ( ) ) . toString ( ) , toWei ( "2.607616" ) ) ;
1341
1324
} ) ;
1342
1325
it ( "Fees correctly accumulate with multiple relays" , async ( ) => {
1343
- await bridgePool . methods . settleRelay ( depositData ) . send ( { from : rando } ) ;
1344
-
1345
1326
// Advance time by a 2 days (172800s) and check that the exchange rate increments accordingly. Expected exchange rate is (910+90+10-(10-0.0000015*172800*10))/1000=1.002592.
1346
1327
await advanceTime ( 172800 ) ;
1347
1328
@@ -1391,18 +1372,9 @@ describe("BridgePool", () => {
1391
1372
depositHash = soliditySha3 ( depositDataAbiEncoded ) ;
1392
1373
1393
1374
// Expire and settle proposal on the OptimisticOracle.
1394
- const relayStatus = await bridgePool . methods . relays ( depositHash ) . call ( ) ;
1395
1375
await advanceTime ( defaultLiveness ) ;
1396
1376
1397
1377
relayAncillaryData = await bridgePool . methods . getRelayAncillaryData ( depositData , relayData ) . call ( ) ;
1398
- await optimisticOracle . methods
1399
- . settle (
1400
- bridgePool . options . address ,
1401
- defaultIdentifier ,
1402
- relayStatus . priceRequestTime . toString ( ) ,
1403
- relayAncillaryData
1404
- )
1405
- . send ( { from : relayer } ) ;
1406
1378
1407
1379
// Settle the relay action.
1408
1380
await bridgePool . methods . settleRelay ( depositData ) . send ( { from : rando } ) ;
@@ -1477,8 +1449,6 @@ describe("BridgePool", () => {
1477
1449
assert . equal ( ( await bridgePool . methods . undistributedLpFees ( ) . call ( ) ) . toString ( ) , toWei ( "0" ) ) ;
1478
1450
} ) ;
1479
1451
it ( "Adding/removing impact exchange rate accumulation as expected" , async ( ) => {
1480
- await bridgePool . methods . settleRelay ( depositData ) . send ( { from : rando } ) ;
1481
-
1482
1452
// Advance time by a 2 days (172800s). Exchange rate should be (1000+10*172800*0.0000015)/1000=1.002592
1483
1453
await advanceTime ( 172800 ) ;
1484
1454
assert . equal ( ( await bridgePool . methods . exchangeRateCurrent ( ) . call ( ) ) . toString ( ) , toWei ( "1.002592" ) ) ;
@@ -1522,9 +1492,8 @@ describe("BridgePool", () => {
1522
1492
} ) ;
1523
1493
it ( "Fees & Exchange rate can correctly handel gifted tokens" , async ( ) => {
1524
1494
// We cant control when funds are sent to the contract, just like we cant control when the bridging action
1525
- // concludes. If someone was to randomly send the contract tokens the exchange rate should ignore this. The contract should ignore the exchange rate if someone was to randomly send tokens.
1526
-
1527
- await bridgePool . methods . settleRelay ( depositData ) . send ( { from : rando } ) ;
1495
+ // concludes. If someone was to randomly send the contract tokens the exchange rate should ignore this. The
1496
+ // contract should ignore the exchange rate if someone was to randomly send tokens.
1528
1497
1529
1498
// Advance time by a 2 days (172800s). Exchange rate should be (1000+10*172800*0.0000015)/1000=1.002592
1530
1499
await advanceTime ( 172800 ) ;
0 commit comments