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

Feature: API to drive the Lamden Link UI #29

Open
JeffWScott opened this issue Nov 23, 2021 · 0 comments
Open

Feature: API to drive the Lamden Link UI #29

JeffWScott opened this issue Nov 23, 2021 · 0 comments

Comments

@JeffWScott
Copy link
Contributor

JeffWScott commented Nov 23, 2021

Scope

Problem

There is a lot of data that www.lamdenlink.com has to aggregate during a swap to be able to determine the status of the swap and when to continue to the next step. When a user refreshes the site in the middle of a swap then tracking the state of the swap is lost.
All of this data could be better aggregated by an API which the UI can just listen to and be told when to move on. The UI could also be given a swap history for the connected lamden wallet from the API and provide an option to resume incomplete ones.

A high level description of how lamden link works can be referenced here #28

Work

  • Create an API which aggregates the transactions and events to from all the lamden link contracts (on Lamden, BSC and ETH).
  • The API should track events/transactions on ETH/BSC contracts
  • The API should use a Lamden Blockservice to discover events on the Lamden Blockchain (help on setting this up can be provided)
  • This API should be able to detect when swaps are started and track their progress
    • For example in a Lamden to BSC swap tokens are Burned on Lamden. The API should detect this transaction and then check BSC transaction from the Bridge contract that transfers that same amount to the metamask address contained in the Burn transaction (this is now Lamden Link works).
  • The UI should implement socket.io websockets to allow the UI to join rooms based on wallet address to receive updates about swaps
  • The API should also query price information for each token to be able to prove this to the UI. This would allow the UI to display the USD value of an asset when the user is inputting the amounts.
  • The API should estimate gas for ETH transactions so the UI can provide that information to the user before they decide to swap. This prevents a user from bridging $10 of WETH and getting hit with a $60 tx fee.

Details

Data

swap_id

A UID for each swap for the API to reference/store each swap. This is up for discussion but I would use the tx hash that first makes the API aware of the swap. So for a Lamden -> ETH/BSC swap that would be the tx_hash of the Lamden Burn transaction. All tx hashes are unique on Lamden as well as ETH/BSC so I don't think we should have any crossover.

Endpoints

** any amount provided should be in both token amount and USD value

/swaps GET

  • params
    • page (int) allows getting more results
  • response Provide a list of recent completed swaps, default 10, should paginate via params
[
  {
    "swap_id": "abc123",
    "origin_blockchain": {
          "blockchain_name":  "Lamden",
          "token_info": {"name": "LUSD", "contract": "con_lusd_lst001"}
    }, 
    "dest_blockchain": {
          "blockchain_name":  "Lamden",
          "token_info": {"name": "USDT", "contract": "0x55d398326f99059ff775485246999027b3197955"}
    },
    "amount": {"token":"0.000056", "USD": "0.56"}, 
    "hashes": {},
    "lamden_address": "",
    "metamask_address: "",
    "status": {"message": "successful", "code": 0},
    "date_completed": 1637685878
  },
  {...}
]

/swaps/:lamden_wallet_address/pending GET

  • params
    • page (int) allows getting more results
  • response Provide a list of pending swaps associated with the lamden account provided
[
  {
    "swap_id": "abc123",
    "origin_blockchain": {
          "blockchain_name":  "Lamden",
          "token_info": {"name": "LUSD", "contract": "con_lusd_lst001"}
    }, 
    "dest_blockchain": {
          "blockchain_name":  "Lamden",
          "token_info": {"name": "USDT", "contract": "0x55d398326f99059ff775485246999027b3197955"}
    },
    "amount": {"token":"0.000056", "USD": "0.56"}, 
    "hashes": {},
    "lamden_address": "",
    "metamask_address: "",
    "status": {"message": "successful", "code": 0},
    "date_completed": 1637685878
  },
  {...}
]

/swaps/:lamden_wallet_address/successful GET

  • params
    • page (int) allows getting more results
  • response Provide a list of the successful swaps associated with the lamden account provided
[
  {
    "swap_id": "abc123",
    "origin_blockchain": {
          "blockchain_name":  "Lamden",
          "token_info": {"name": "LUSD", "contract": "con_lusd_lst001"}
    }, 
    "dest_blockchain": {
          "blockchain_name":  "Lamden",
          "token_info": {"name": "USDT", "contract": "0x55d398326f99059ff775485246999027b3197955"}
    },
    "amount": {"token":"0.000056", "USD": "0.56"}, 
    "hashes": {},
    "lamden_address": "",
    "metamask_address: "",
    "status": {"message": "successful", "code": 0},
    "date_completed": 1637685878
  },
  {...}
]

/status/:swap_idGET

  • response Provide the current status of a swap. The details here are probaby TBA and will depend greatly on how the UI will use this info.
{
    "message": "Checking for Proof of Burn...",
    "errors": [],
    "code": 0
}

Socket.io Websockets

  • The UI should be able to join a couple rooms for getting various updates

Rooms

successful_swaps
new event:

  • provides updates of all successful swaps from the entire system

:swap_id
update event

  • Allows the UI to join a room by swap_id to get status updates as the swap progresses
  • This socket should provide status updates as the API sees transactions complete on the blockchain.
    • For example the API would provide the Proof-of-Burn from the Lamden blockchain as an update on this socket.

price_updates
update event

  • current prices of all tokens supported by Lamden Link
@JeffWScott JeffWScott changed the title API to drive the Lamden Link UI Feature: API to drive the Lamden Link UI Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant