# Question about Tinyman and margin protocol

**URL:** <https://forum.algorand.co/t/question-about-tinyman-and-margin-protocol/4866>\
**Category:** General\
**Tags:** teal, smart-contracts\
**Created:** [October 25, 2021, 9:25pm UTC](https://forum.algorand.co/t/question-about-tinyman-and-margin-protocol/4866 "2021-10-25T21:25:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![javier0rosas](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.algorand.co/javier0rosas/32/1578_2.png) [@javier0rosas](https://forum.algorand.co/u/javier0rosas)\
**Post date:** [October 25, 2021, 9:25pm UTC](https://forum.algorand.co/t/question-about-tinyman-and-margin-protocol/4866/1 "2021-10-25T21:25:38Z")

</div>

So I want to leverage Tinyman to create a decentralized margin/leverage protocol on Algorand. The idea is the following: a user can borrow money to trade on Tinyman, but the user can only borrow algos if collateral has already been sent to a contract account (say a stateless logic signature account).

This is what it would look like:

 ![Screen Shot 2021-10-25 at 4.47.05 PM](https://us1.discourse-cdn.com/flex016/uploads/algorand/original/2X/7/7df04a10460523b3d132ae0e0e831f7a897aa97d.jpeg)

Unfortunately, this cannot be done through an atomic grouped transaction because Tinyman pool contracts check for GroupSize, indexes, etc. It can also not be achieved through inner transactions because of the same reason.

I was also thinking about doing this in three separate transactions. The first two transactions would be in an atomic group, and the transactions from collateral contract account to Tinyman would happen later (only if the first two were successful).

 ![Screen Shot 2021-10-25 at 5.12.21 PM](https://us1.discourse-cdn.com/flex016/uploads/algorand/original/2X/b/b6ef6158391ece0d6998e4baf082367807289939.jpeg)

The first would send a transaction with collateral from Borrower to Collateral Contract Account, and the second would be a transaction made to a stateful app that will store the amount of collateral sent in the Borrower’s local storage. The idea is that the collateral contract account would only send a swap transaction to Tinyman with borrowed money if there is local storage for the Borrower in the stateful validator app. For this, I wanted to use app\_local\_get or localGetEx in Pyteal. Unfortunately, this opcode is not allowed in stateless logic signatures.

I was wondering if you had any ideas or comments on how I should restructure my code to accomplish this.

Sorry for the lengthy question, but I wanted to ensure that you understood my thought process.

Best,

Javier
