@@ -16,8 +16,8 @@ mod HypErc20DexCollateral {
1616 use contracts :: client :: router_component :: RouterComponent ;
1717 use contracts :: paradex :: interface :: {IParaclearDispatcher , IParaclearDispatcherTrait };
1818 use contracts :: utils :: utils :: U256TryIntoContractAddress ;
19+ use contracts :: utils :: utils :: scale_amount;
1920 use core :: array :: ArrayTrait ;
20- use core :: num :: traits :: Pow ;
2121 use openzeppelin :: access :: ownable :: OwnableComponent ;
2222 use openzeppelin :: token :: erc20 :: {ERC20ABIDispatcher , ERC20ABIDispatcherTrait };
2323 use openzeppelin :: upgrades :: interface :: IUpgradeable ;
@@ -31,12 +31,6 @@ mod HypErc20DexCollateral {
3131 },
3232 };
3333
34- // NOTE: Starknet’s version of the Keccak hash function (denoted by sn_keccak)
35- // is defined as the first 250 bits of Ethereum’s keccak256
36- // sn_keccak of selector for "deposit_on_behalf_of" function in the DEX contract
37- const DEX_DEPOSIT_ON_BEHALF_OF_SELECTOR : felt252 =
38- 152884417735717128974538630286950396387019428546378603946454937413393931990 ;
39-
4034 component! (path : OwnableComponent , storage : ownable , event : OwnableEvent );
4135 component! (path : MailboxclientComponent , storage : mailbox , event : MailBoxClientEvent );
4236 component! (path : RouterComponent , storage : router , event : RouterEvent );
@@ -173,17 +167,12 @@ mod HypErc20DexCollateral {
173167 let dex_decimals : u8 = dex_dispatcher . decimals ();
174168
175169 // Scale amount from token decimals to DEX decimals
176- let scaled_amount = if token_decimals > dex_decimals {
177- amount_or_id / (10_u256 . pow ((token_decimals - dex_decimals ). into ()))
178- } else if token_decimals < dex_decimals {
179- amount_or_id * (10_u256 . pow ((dex_decimals - token_decimals ). into ()))
180- } else {
181- amount_or_id
182- };
183-
184- // Approve the DEX to spend the tokens
170+ let scaled_amount = scale_amount (amount_or_id , token_decimals , dex_decimals );
171+
172+ // Approve the DEX to spend the tokens (the original amount)
185173 token_dispatcher . approve (dex_address , amount_or_id );
186174
175+ // Deposit the tokens (the scaled amount)
187176 let amount : felt252 = scaled_amount . try_into (). unwrap ();
188177 dex_dispatcher . deposit_on_behalf_of (recipient , token_address , amount );
189178
0 commit comments