Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base unificator + okx,huobi,bitmart networks unification #18495

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from

Conversation

ttodua
Copy link
Member

@ttodua ttodua commented Jul 7, 2023

Preamble:
There are 3-types of exchanges (with regard to network-identification approach).

Type-1

This is how any normal exchange does -from fetchCurrencies their api returns one currency object with a list of supported networks like:

[
  {
    'id': 'Usdt',
    'networks': {
        [  id: 'Erc20',  fee: 3.1, ...  ],
        [  id: 'Sol', fee: 0.2, ... ],
   },
   {
    'id': 'Shib',
    'networks': {
        [  id: 'Erc20',  fee: 3.3, ...  ],
        [  id: 'Sol', fee: 0.3, ... ],
    }
]

so, you can easily refer to any currency & network (i.e. in withdraw) with a common structure:

{
  cc: 'Usdt',
  chain: 'Erc20' // any common-network-id
}

Type-2

Such exchanges (okx, huobi,...) does not return a normal structure from fetchCurrencies, instead they return like:

[
  {
    'id': 'Usdt',
    'networks': {
        [  id: 'usdtErc20',  'commonTitle':'ERC20', fee: 2.1, ...  ],
        [  id: 'Sol_usdt',  'commonTitle':'Solana', fee: 0.4, ... ],
   },
   ...
]

so, each chain-id is unique "junction" of several slugs (while they might also include some generic "title", which is not anywhere used in their api for I/O purposes) and you have to specifically send request (i.e. in withdraw) like:

{
  cc: 'Usdt',
  chain: 'usdtErc20' // UNIQUE NETWORK ID !
}

There we use additional helpers (this.setNetworkMappingForCurrencyNetworkJunction...) during construction of currencies (in 'fetchCurrencies'), where we make an intermediary "common network titles" to link each networkcode to unique exchange-speicfic chain-id, like:

this.tempGeneratedData['usdt']['ERC20'] = 'usdtErc20';
this.tempGeneratedData['usdt']['SOL'] = 'Sol_usdt;
                                 ^
                                 common network names used as intermediary key, by which we refer to an unique-network-id junction

Type-3

one of the worst time of exchange api engine structure (bitmart, etc), where fetchCurrencies api response is like:

[
  { 'ccId': 'USDT-ERC20', 'fee': 3.1 },     // unique junction Currency title & NetworkTitle 
  { 'ccId': 'USDT-SOLANA',  'fee': 3.1  } // unique junction Currency title & NetworkTitle 
]

where each currency object contains only an "unique currency id" which is actually the only way to refer to currency & network together, and in requests (in withdraw etc) you dont have separate fields for currency & network, instead you have just to refer them with:

{
  ccId: 'USDT-SOLANA'
}

similarly to
this.setNetworkMappingFor**NetworkCurrency**Junction (used in okx, huobi...) here we use a helper in fetchCurrencies:
this.setNetworkMappingFor**CurrencyNetwork**Junction


Notes

  1. so, with the help of those methods (and others like handle**CurrencyId**AndParams, handle**NetworkId**AndParams ..) added in base, we can easily wrap & add any such flavours of exchanges with just one line helpers in implementations (and removing massive custom codes from implementations), making the networks-unification possibly complete & ready for all scenarios.
  2. in cases of type-2 & type-3 exchanges, we have an additional option added:
options: {
  'networksAreTitlesInsteadOfIds': true`,
  ...
}

that makes such exchanges recognized to be different. for those exchanges, when you do networkCodeToId ('ERC20') (i.e. returning Eth20) here the Eth20 will not be the exchange-specific chain-id which needs to be sent in request, but an "intermediary" common title, which we further use to locate the unique chain-id (i.e. erc20usdt) in temporary generatedNetworkData container.


(fix #15987, fix #16016 , fix #16176, fix #17422, fix #17862, fix #17027)
(related to #15789)

@ttodua
Copy link
Member Author

ttodua commented Jul 7, 2023

await e.fetchDepositAddress ('USDT', {network:'TRC20'});

{
  currency: "USDT-TRC20",
  address: "TRoT....bap1S",
  tag: undefined,
  network: "TRC20",
  info: {
    currency: "USDT-TRC20",
    chain: "TRON",
    address: "TRoT....bap1S",
    address_memo: "",
  },
}

await e.fetchDepositAddress ('USDT', {network:'ETH'});

 {
  currency: "USDT-ERC20",
  address: "0x5DD6a......C34b",
  tag: undefined,
  network: "Ethereum",
  info: {
    currency: "USDT-ERC20",
    chain: "Ethereum",
    address: "0x5DD6a......C34b",
    address_memo: "",
  },
}

also supports existing (obsolete exchange specific call) await e.fetchDepositAddress ('USDT-ERC20'); which returns same as above last sample.

@ttodua ttodua marked this pull request as ready for review July 7, 2023 12:24
@ttodua ttodua marked this pull request as draft July 15, 2023 19:23
-
Merge branch 'master' of github.com:ccxt/ccxt into bitmart-networks-2
@ttodua ttodua changed the title bitmart - networks unification base unificator + okx,huobi,bitmart networks unification Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
2 participants