unlock icon indicating copy to clipboard operation
unlock copied to clipboard

Allow purchaser to "swap" one of their coins (maybe starting with ether) into what the lock asks for

Open HardlyDifficult opened this issue 6 years ago • 12 comments

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.

HardlyDifficult avatar Mar 18 '19 22:03 HardlyDifficult

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?

julien51 avatar Mar 19 '19 18:03 julien51

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

HardlyDifficult avatar Mar 19 '19 19:03 HardlyDifficult

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).

HardlyDifficult avatar Mar 20 '19 18:03 HardlyDifficult

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.

HardlyDifficult avatar Jun 11 '19 23:06 HardlyDifficult

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).

julien51 avatar Oct 05 '19 08:10 julien51

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

HardlyDifficult avatar Oct 08 '19 03:10 HardlyDifficult

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

HardlyDifficult avatar Oct 09 '19 06:10 HardlyDifficult

image

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

smombartz avatar Jan 14 '20 16:01 smombartz

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...

HardlyDifficult avatar Jan 14 '20 19:01 HardlyDifficult

;p

julien51 avatar Jan 14 '20 19:01 julien51

Yeah, I think the actual copy will need to be changed ;)

julien51 avatar Jan 14 '20 19:01 julien51

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

julien51 avatar Jul 25 '22 08:07 julien51

We are now collaborating with our friends at Depay around this and we will implement that logic using their contract and plugin!

julien51 avatar Oct 05 '22 16:10 julien51

https://github.com/unlock-protocol/unlock/pull/9966

julien51 avatar Nov 10 '22 02:11 julien51

@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!

julien51 avatar Nov 16 '22 04:11 julien51

We now have this! Finally! To be announced soon!

julien51 avatar Jan 22 '23 00:01 julien51