I have a contract which calls the swap_tokens_for_exact_tokens function of soroswap router to swap tokens .
To execute the swap, the swap_tokens_for_exact_tokens function of soroswap router also calls .transfer of the specified output token to send the tokens to my contract.
The flow of the call to swap tokens is like this
My-contract --> fn swap_tokens_for_exact_tokens (soroswap_router) --> fn transfer (transfers token form token_in to pair)
Therefore since the transfer function of the input token called by soroswap router authorizes the from (my router contract) parameter using from.require_auth() I have used env.authorize_as_current_contract(auth_entries) in my contract before calling swap_tokens_for_exact_tokens function of soroswap to authorize the deeper call (which is the transfer call of the input token)
however I get this error below coming from the transfer function of the output token
topics:[error, Error(Auth, InvalidAction)], data:["[recording authorization only] encountered authorization not tied to the root contract invocation for an address. Use require_auth() in the top invocation or enable non-root authorization.",
this is my auth code
token_out_id.address.clone(), //address
my_contract.clone(), //address
);
e.authorize_as_current_contract(auth_entries);
e.invoke_contract::<Val>(router_id, &function, args);```
This is a slim version of the code ,
I have significantly reduced the code size and uploaded to this repo so the invocation which produces the error is clear https://github.com/ysfkel/authorized-caontract-call/blob/434bf6beeea159560a3f588bea111ce2e88afb38/src/contract.rs#L87