Enabling secret contracts to accept payment in any snip20 (also enables the bridge to convert any supported ERC20/ETH immediately to sSCRT or native SCRT)

Just copy/pasting a comment I made on discord about how we could set up the AMM to make it possible for a secret contract that uses its own snip20 to pay for use, can easily accept payment in any snip20 that it created anAMM pair with its own token. Just wondering what people’s thoughts were.

So one use case I was thinking of regarding if we have the AMM use Send instead of Transfer…Let’s say we have a contract that uses its own token to pay for use. We could have that contract accept any snip20 as payment (assuming they create an AMM pair for that snip20 and their token). It could work as follows (making some assumptions not knowing how the AMM is coded). The customer sends a snip20 to the app contract. Via the snip20 Receive call, the contract sees it didn’t get paid its native coin, so it does a Send to the correct AMM pair where it includes in the optional msg, anything it needs to process later. Via THAT Receive call, the AMM, performs the exchange and just forwards the msg it received into the optional msg that it uses when it does Send back to the contract. So the contract gets its native token for whatever use case, and has Receive called telling it how much was paid after the exchange, and can use the msg to perform whatever it needs to do in response. And the customer was able to pay in any snip20. Obviously IF the AMM requires the user to include some msg in the Send to the AMM pair, you could just include an optional field in THAT msg which is an optional msg that it will forward (so you are just nesting the contract’s optional msg inside the AMM’s msg (if it is using one for exchange calls)). Hope that wasn’t too unclear lol

I think it would be pretty cool to have contracts that can easily accept any snip20 as payment. I don’t know if any other AMM allows that functionality, so we could be the first

1 Like

As a side note, this would also enable letting the bridge be used to convert any ETH/(supported)ERC20 token into sSCRT immediately. Since we see a lot of people looking for ways to buy SCRT, that could be very helpful

And with a small update to the secret secret contract so that you can specify an address when you do a Redeem. This would even enable the bridge to immediately swap the ERC20/ETH for native SCRT

Just wanted to update…
It was explained to me that queries to other contracts can show the intermediate state during a tx with multiple messages, so you wouldn’t need to use Send/Receive. Instead you can use authenticated queries to learn the same information (albeit at a higher gas cost)