DePayFi / widgets

💸 Payments directly into your wallet. DePay simplifies and improves Web3 Payments with the power of DeFi. Accept any token with on-the-fly conversion and state-of-the-art widgets.
https://depay.com
MIT License
97 stars 36 forks source link

Set payment with a fixed cryptocurrency #115

Closed JTorresConsulta closed 7 months ago

JTorresConsulta commented 7 months ago

Hi !

I am testing dePay with Gnosis chain. I have a wallet with some xDai When I use dePay to make a payment, the Tx Gnosis Scan show something weird.

The transaction was not from xdai to xdai, but from xdai it went to any other currency ( USDC, USDT or Gno).

Why is happening? is cos get fees in the swap ? Is possible to transfer the user currency to same currency? In this case, xDai to xDai

You can see my test history here: https://gnosisscan.io/address/0xf11069faa3e382f78aef9858a51f302709e2772c#tokentxns

Thanks


This is my basic JS:

DePayWidgets.Payment({
    currency: 'USD',
    amount: {
        fix: 1,
        currency: 'USD'
    },
    accept: [
        {
            blockchain: 'gnosis',
            token: '0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb',//xDAI
            receiver: '0xf11069FAa3E382F78Aef9858a51F302709e2772C'
        }
        /*
        {
            blockchain: 'gnosis',
            token: '0x4ECaBa5870353805a9F068101A40E0f32ed605C6',//USDT
            receiver: '0xf11069FAa3E382F78Aef9858a51F302709e2772C'
        },
        {
            blockchain: 'gnosis',
            token: '0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83', //USDC
            receiver: '0xf11069FAa3E382F78Aef9858a51F302709e2772C'
        } 
        */
    ] 
});
0xNe0x1 commented 7 months ago

Hi @JTorresConsulta

It's impossible that you received USDC or GNO if you only have configured to receive XDAI, like in your shared code snippet (as you have commented-out USDT and USDC).

It's important to understand that you do not configure what users can use, but what you will receive. We also recommend to configure as few tokens per chain as possible for performance reasons.

Looking at the transactions it looks like you have configured xDAI, USDT, USDC, and GNO as accepted. Hence you have received what you have configured.

Users can always use whatever they have in their wallet thanks to auto-conversion through DeFi.

0xNe0x1 commented 7 months ago

If you have configured to receive xDAI, USDT, USDC and GNO, and the user selects xDAI, it can happen that a conversion is happening (so you receive USDT, USDC or GNO instead of xDAI) in cases where:

e.g. https://gnosisscan.io/tx/0xcf52c44f21715d4744620f88c29a82c1913c0fd4c0288dddb6ce357797289755 gave you $1.03 worth of GNO even though the user paid $1.005 worth of xDAI.

Screenshot 2024-03-08 at 08 07 11

The algorithm is supposed to deliver the most to you based on the configuration, while also making sure to not cost to much in gas fees (it's a tricky balance).

0xNe0x1 commented 7 months ago

if you only want to receive xDAI, only configure xDAI as accepted.

0xNe0x1 commented 7 months ago

Also, configuring the widget with

currency: 'USD',
amount: {
  fix: 1,
  currency: 'USD'
},

makes those conversion cases even more likely as its only a very naive approach of defining token amounts based on fiat currencies... you should configure amounts within accept and remove amount on the top level:

DePayWidgets.Payment({
  currency: 'USD',
  accept: [
    {
      blockchain: 'gnosis',
      token: '0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb',//xDAI
      receiver: '0xf11069FAa3E382F78Aef9858a51F302709e2772C',
      amount: 1
    },
    {
      blockchain: 'gnosis',
      token: '0x4ECaBa5870353805a9F068101A40E0f32ed605C6',//USDT
      receiver: '0xf11069FAa3E382F78Aef9858a51F302709e2772C',
      amount: 1
    },
    {
      blockchain: 'gnosis',
      token: '0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83', //USDC
      receiver: '0xf11069FAa3E382F78Aef9858a51F302709e2772C',
      amount: 1
    } 
  ]
})

if your goal is to receive a stable amount e.g. 1 USDC, xDAI or USDT and reduce eventual conversions

JTorresConsulta commented 7 months ago

It's impossible that you received USDC or GNO if you only have configured to receive XDAI, like in your shared code snippet (as you have commented-out USDT and USDC).

It's important to understand that you do not configure what users can use, but what you will receive. We also recommend to configure as few tokens per chain as possible for performance reasons.

Looking at the transactions it looks like you have configured xDAI, USDT, USDC, and GNO as accepted. Hence you have received what you have configured.

No, dont have configured to receive GNO in any case. Now, I tried again with the next :

You can look the TX here: https://gnosisscan.io/tx/0x77e4c04c12c12ca83769dfa5871375fe694ef3ab68a00a5fc18b7f586191c027

This is other test with the next JS:

DePayWidgets.Payment({
    currency: 'USD',
    amount: {
        fix: 1,
        currency: 'USD'
    },
    accept: [
        {
            blockchain: 'gnosis',
            token: '0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb',//xDAI
            receiver: '0xf11069FAa3E382F78Aef9858a51F302709e2772C'
        }
    ] 
});
JTorresConsulta commented 7 months ago

My goal is se the price in dollars and accept and receive only stable coins of any network Thanks ! @0xNe0x1

0xNe0x1 commented 7 months ago

You received GNO because 0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb is GNO https://gnosisscan.io/address/0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb

You need to configure 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE if you want to receive the native token of the respective blockchain (xDAI in gnosis case)

0xNe0x1 commented 7 months ago

sorry I have not spotted that earlier

0xNe0x1 commented 7 months ago

And I guess your goal is to receive the stable coins that you believe are stable. There is no common understanding of what a "stable coin" is. (e.g. pretty sure you dont want to receive Terra USD, which is also a "stable coin")...

Considering your goal, I recommend you configure 1 stable coin of your choice per blockchain and make sure to configure amounts via accept!

DePayWidgets.Payment({
  accept: [
    {
      blockchain: 'gnosis',
      token: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE', // xDAI (native)
      receiver: '0xf11069FAa3E382F78Aef9858a51F302709e2772C',
      amount: 1
    } 
  ]
})

we also do not recommend to enforce "USD" as display currency as users prefer to see value in their local currency (if you have a global audience).

JTorresConsulta commented 7 months ago

You received GNO because 0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb is GNO

OMG ! @0xNe0x1 Excuse me, you are right 👍

But I have other question. If I accept several stables like USDC, USDT and xDAI, and the user pay with xDAI. What will I receive? In other attempts user paid with xDAI and the received was in USDC or USDT...

0xNe0x1 commented 7 months ago

If you configure to receive USDC, USDT and xDAI and the user uses xDAI you should also receive xDAI (in most cases).

But as stable coins are not as stable as most people wrongly assume, it could happen that for some payments you do receive USDC or USDT, as I've tried to explained prior, in cases where e.g. 1 USDC > 1 xDAI.

JTorresConsulta commented 7 months ago

Considering your goal, I recommend you configure 1 stable coin of your choice per blockchain and make sure to configure amounts via accept!

Now I dont want to make the conversion in my client site. He wants to work and show to his ecommerce user the cart total amount in $.

He is open to receive any crypto if it conversion amount corresponds to dollars.

Do you think it would be best not to set any accepted tokens and only set the fix and currency like next?

DePayWidgets.Payment({
    currency: 'USD',
    amount: {
        fix: 1,
        currency: 'USD'
    }
});
0xNe0x1 commented 7 months ago

Some one has to make the decision what stable coins to receive. Without accept configuration the widget will not work, as the widget is not gonna make that decision for you either.

JTorresConsulta commented 7 months ago

I understand. Even though it indicates some tokens in accept (like USDT). Will the user be able to pay with any token with sufficient balance on that blockchain?

0xNe0x1 commented 7 months ago

I think I cant follow any more.

You will always receive whats defined in accept. if you define amount in accept you will receive exactly that amount, if you define currency: amount a naive way to calculate token accept amounts will be performed.

Users will be able to pay with any token with sufficient balance on that blockchain, correct.

JTorresConsulta commented 7 months ago

All clear now. Thanks @0xNe0x1