@@ -1141,6 +1141,18 @@ pub impl PerpsTestsFacadeImpl of PerpsTestsFacadeTrait {
11411141
11421142 fn transfer_request (
11431143 ref self : PerpsTestsFacade , sender : User , recipient : User , amount : u64 ,
1144+ ) -> RequestInfo {
1145+ self . _transfer_request (: sender , recipient : recipient , asset_id : self . collateral_id, : amount )
1146+ }
1147+
1148+ fn transfer_spot_request (
1149+ ref self : PerpsTestsFacade , sender : User , recipient : User , asset_id : AssetId , amount : u64 ,
1150+ ) -> RequestInfo {
1151+ self . _transfer_request (: sender , recipient : recipient , : asset_id , : amount )
1152+ }
1153+
1154+ fn _transfer_request (
1155+ ref self : PerpsTestsFacade , sender : User , recipient : User , asset_id : AssetId , amount : u64 ,
11441156 ) -> RequestInfo {
11451157 let expiration = Time :: now (). add (delta : Time :: weeks (1 ));
11461158
@@ -1149,7 +1161,7 @@ pub impl PerpsTestsFacadeImpl of PerpsTestsFacadeTrait {
11491161 position_id : sender . position_id,
11501162 salt ,
11511163 expiration ,
1152- collateral_id : self . collateral_id ,
1164+ collateral_id : asset_id ,
11531165 amount ,
11541166 recipient : recipient . position_id,
11551167 };
@@ -1160,8 +1172,8 @@ pub impl PerpsTestsFacadeImpl of PerpsTestsFacadeTrait {
11601172 sender . account. set_as_caller (self . perpetuals_contract);
11611173 ICoreDispatcher { contract_address : self . perpetuals_contract }
11621174 . transfer_request (
1163- signature ,
1164- asset_id : self . collateral_id ,
1175+ : signature ,
1176+ asset_id : asset_id ,
11651177 recipient : recipient . position_id,
11661178 position_id : sender . position_id,
11671179 : amount ,
@@ -1175,15 +1187,15 @@ pub impl PerpsTestsFacadeImpl of PerpsTestsFacadeTrait {
11751187 spied_event : self . get_last_event (contract_address : self . perpetuals_contract),
11761188 position_id : sender . position_id,
11771189 recipient : recipient . position_id,
1178- collateral_id : self . collateral_id ,
1190+ collateral_id : asset_id ,
11791191 : amount ,
11801192 : expiration ,
11811193 transfer_request_hash : request_hash ,
11821194 : salt ,
11831195 );
11841196
11851197 RequestInfo {
1186- asset_id : self . collateral_id ,
1198+ asset_id ,
11871199 recipient ,
11881200 position_id : sender . position_id,
11891201 amount ,
@@ -1197,13 +1209,18 @@ pub impl PerpsTestsFacadeImpl of PerpsTestsFacadeTrait {
11971209 let RequestInfo {
11981210 asset_id , recipient , position_id , amount , expiration , salt , request_hash ,
11991211 } = transfer_info ;
1200- let dispatcher = IPositionsDispatcher { contract_address : self . perpetuals_contract };
1201- let sender_balance_before = dispatcher
1202- . get_position_assets (position_id : position_id )
1203- . collateral_balance;
1204- let recipient_balance_before = dispatcher
1205- . get_position_assets (position_id : recipient . position_id)
1206- . collateral_balance;
1212+
1213+ let sender_balance_before = if (asset_id == self . collateral_id) {
1214+ self . get_position_collateral_balance (position_id )
1215+ } else {
1216+ self . get_position_asset_balance (position_id , asset_id )
1217+ };
1218+
1219+ let recipient_balance_before = if (asset_id == self . collateral_id) {
1220+ self . get_position_collateral_balance (recipient . position_id)
1221+ } else {
1222+ self . get_position_asset_balance (recipient . position_id, asset_id )
1223+ };
12071224
12081225 let operator_nonce = self . get_nonce ();
12091226 self . operator. set_as_caller (self . perpetuals_contract);
@@ -1223,16 +1240,32 @@ pub impl PerpsTestsFacadeImpl of PerpsTestsFacadeTrait {
12231240 request_hash : request_hash , expected_status : RequestStatus :: PROCESSED ,
12241241 );
12251242
1226- self
1227- . validate_collateral_balance (
1228- position_id : position_id , expected_balance : sender_balance_before - amount . into (),
1229- );
1243+ if (asset_id == self . collateral_id) {
1244+ self
1245+ . validate_collateral_balance (
1246+ : position_id , expected_balance : sender_balance_before - amount . into (),
1247+ );
12301248
1231- self
1232- . validate_collateral_balance (
1233- position_id : recipient . position_id,
1234- expected_balance : recipient_balance_before + amount . into (),
1235- );
1249+ self
1250+ . validate_collateral_balance (
1251+ position_id : recipient . position_id,
1252+ expected_balance : recipient_balance_before + amount . into (),
1253+ );
1254+ } else {
1255+ self
1256+ . validate_asset_balance (
1257+ : position_id ,
1258+ : asset_id ,
1259+ expected_balance : sender_balance_before - amount . into (),
1260+ );
1261+
1262+ self
1263+ . validate_asset_balance (
1264+ position_id : recipient . position_id,
1265+ : asset_id ,
1266+ expected_balance : recipient_balance_before + amount . into (),
1267+ );
1268+ }
12361269
12371270 assert_transfer_event_with_expected (
12381271 spied_event : self . get_last_event (contract_address : self . perpetuals_contract),
0 commit comments