unlock
unlock copied to clipboard
Allow purchaser to "swap" one of their coins (maybe starting with ether) into what the lock asks for
Is your feature request related to a problem? Please describe. At the moment when I price a lock in ERC20 tokens, I have to choose just one. There are several stablecoins out there today and presumably many content creators are just as happy with one as they are with another.
Describe the solution you'd like Allow the lock owner to specify one or more addresses for ERC20 token support. All tokens listed leverage the same price value, so each of these addresses must have approximately the same value.
e.g. a Key cost $2.50, paid in Dai, USDC, TUSD, or USDT.
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Additional context Note a complexity to solve: each stable coin may have a different number of decimals. Normally contracts completely ignore this, but we may need to consider shifting to ensure consistent pricing.
This too would be a great feature! However I wonder if there is not a thing to do at a larger scale by allowing any ERC20 to be "swapped" for the one that the contract needs when trying to purchase a key? I believe we could for example integrate with Uniswap for that?
Uniswap (or similar) is an option. I would need to research to see if it's possible to leverage that and then buy a key with a single transaction, or if you swap and then buy the key. (the send feature is not sufficient by itself since our contract can't react to receiving tokens). But even if they do support that, I wonder if it complicates things for Key buyers. A simple example is the conversion rate - 1 Dai != 1 USDC
We'll need to test to be sure, but I believe Uniswap could work by:
- The key buyer initiates the purchase with a call to our contract
- Our contract forwards the swap request to Uniswap
- Then we process the purchase
Assuming this works out okay, we could also add a feature which says the Lock owner eats the conversion cost - so to the user 1 Dai does equal 1 USDC (and maybe we put a max slippage of x%, reverting the transaction if for example 1 Dai was only 0.80 USDC).
The solution we use here should be upgradable. Either via ZOS upgrades or maybe by being a stateless proxy. This proxy does the swap, performs purchases a key for the user, and then sends any remaining balance back to the user.
I really like the "generic" version of this (where the user is given the ability, in a single call to convert whatever currency they have into whatever the lock needs and purchase the key).
How "generic" should we go? ;) @julien51
Thinking on this a bit, I'm considering adding this to my npm package instead of Unlocks. We can make a contract that does a swapAndCall which works for the Unlock use case (via the purchase for feature).
The flow would be something like:
- Call swapAndCall(address token, uint amount, address contract, bytes data)
- The generic contract looks up the uniswap exchange and does the swap
- The generic contract calls contract with data, and reverts the tx if that fails
- The generic contract then refunds any ETH and/or tokens remaining
UniswapAndCall! With this you can buy a key priced in Dai using only ether - in a single transaction. (and we can add token -> token swaps): https://github.com/HardlyDifficult/hardlydifficult-ethereum-contracts/blob/master/contracts/UniswapAndCall.sol
I have a few features to add and some more testing to do. But as a proof of concept it's working. here's a test buying a Dai priced key with eth https://github.com/HardlyDifficult/hardlydifficult-ethereum-contracts/blob/master/test/contracts/uniswapAndCall.js#L67

Here design and prototype for Instant Swap (BAT is clickable): https://www.figma.com/proto/YIvjlf89MZAXTFuBYXI3fv/Paywall-2?node-id=28%3A579&viewport=-1123%2C-372%2C0.8438658118247986&scaling=min-zoom
@NickCuso @julien51 @cnasc
Why does the text mention credit card but not expose that option? Why do students get an eth option but not corporate? Instead of "Instant Swapp" would it be more clear to say "Pay with SAI"?
...I'm probably noticing fake parts of the mock...
;p
Yeah, I think the actual copy will need to be changed ;)
I believe it is now time to revisit this. However we should probably handle this on the front-end ion the new checkout UI. An easy way would be to have a way to "hook" into the local Uniswap clone and let the user swap any of their coins in the lock's required currency.
cc @searchableguy
We are now collaborating with our friends at Depay around this and we will implement that logic using their contract and plugin!
https://github.com/unlock-protocol/unlock/pull/9966
@clemsos Please make sure the plugin you are writing for DePay includes all the methods that can be called on the contract to pay : purchase but also extend!
We now have this! Finally! To be announced soon!