Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Improve TakerNegotiator interface #116

Merged
merged 17 commits into from
Feb 18, 2020
Merged

Improve TakerNegotiator interface #116

merged 17 commits into from
Feb 18, 2020

Conversation

D4nte
Copy link

@D4nte D4nte commented Feb 14, 2020

This test demonstrates how to use the TakerNegotiator.
Note that the last part await order.take() is not tested as it involves creating a few mock. Not yet sure whether I should do it.

it("Returns an order and takes it", async () => {

Usage in the example drafted here: comit-network/create-comit-app#440

Resolves #89

Copy link
Member

@bonomat bonomat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I see it correctly then you had to make bitcoinWallet and ethereumWallet optional and expose these two fields publicly just to facilitate the tests.
I think we should try to avoid this.

src/actor.ts Show resolved Hide resolved
src/negotiation/order.ts Outdated Show resolved Hide resolved
src/negotiation/order.ts Show resolved Hide resolved
src/negotiation/order.ts Outdated Show resolved Hide resolved
src/negotiation/order.ts Show resolved Hide resolved
src/negotiation/taker_negotiator.spec.ts Show resolved Hide resolved
@D4nte
Copy link
Author

D4nte commented Feb 15, 2020

If I see it correctly then you had to make bitcoinWallet and ethereumWallet optional and expose these two fields publicly just to facilitate the tests.
I think we should try to avoid this.

We won't need a Bitcoin Wallet if ones only wants to do LNBTC-ERC20 swaps. Hence I believe it is a move in the right direction.

@bonomat
Copy link
Member

bonomat commented Feb 15, 2020

We won't need a Bitcoin Wallet if ones only wants to do LNBTC-ERC20 swaps. Hence I believe it is a move in the right direction.

Ok, valid point.

@D4nte D4nte added the no-mergify Stop mergify to merge this automatically label Feb 15, 2020
const comitClient = new ComitClient(bitcoinWallet, ethereumWallet, cnd);
const comitClient = new ComitClient(cnd);
comitClient.ethereumWallet = ethereumWallet;
comitClient.bitcoinWallet = bitcoinWallet;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of exposing these fields publicly you could apply the builder pattern. This would allow for something like this:

const comitClient = new ComitClient(cnd)
    .withEthereumWallet(ethereumWallet)
    .withBitcoinWallet(bitcoinWallet)
    ....;

Let me know what you think and I can provide a small PR once your changes are in.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please hold, I am finishing off few things. I'll ping you.

import { getToken, Token } from "../tokens/tokens";

export interface Order {
tradingPair: string;
export interface OrderParams {
Copy link
Member

@da-kami da-kami Feb 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃 I find the design of the Order a bit confusing. From code

export class Order {
  constructor(
    public readonly orderParams: OrderParams,
    public readonly criteria: TakerCriteria,
    public readonly takeOrder: (
      orderParams: OrderParams
    ) => Promise<Swap | undefined>
  ) {}

So the order consists of OrderParams and a TakerCriteria, why is the abstraction of OrderParams needed? What exactly is a TakerCriteria?

I feel there is quite a lot of classes now and it's not immediately understandable why and what they are for.
Motivation for writing this: Started to write comments for code documentation and it's not that easy to explain what is going on. What is currently there works, but I wonder if we could design it so it is easier to understand.

Can we simplify this by integrating the OrderParams into the Order? Is this abstraction really needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that the lib consumer is not supposed to constructor Order by themselves.
They would only use OrderParams (a simple object) to add orders to the order book.

Interesting point about documentation because this means that the constructor of Order should not be documented for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand what you are doing, but I still find the naming a bit confusing. I don't have a perfect solution in mind yet, but maybe we should step back, take a whiteboard and design this outside the code. The way Order and OrderParams is introduced in this PR is a bit confusing for me. we have a lot of variables named order now, that are actually OrderParams. Maybe a simple rename can fix this, not sure.

return response.data;
}

public async takeOrder(order: OrderParams, swapId: string) {
Copy link
Member

@da-kami da-kami Feb 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ How come we already have a swapId at this point? Aren't we supposed to get the swapId from the maker after taking the order?

(Maybe I'm just confused by the syntax...?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the swap Id indeed. I have documented in f622aea

@da-kami
Copy link
Member

da-kami commented Feb 17, 2020

Overall: Like the approach towards tests, but don't understand why certain design decisions were made. Would be cool if could go over this with me Franck and explain it (Would help for creating good documentation).

@D4nte
Copy link
Author

D4nte commented Feb 17, 2020

Overall: Like the approach towards tests, but don't understand why certain design decisions were made. Would be cool if could go over this with me Franck and explain it (Would help for creating good documentation).

Please review @da-kami I added documentation.

@D4nte D4nte requested a review from da-kami February 17, 2020 05:28
Copy link
Member

@da-kami da-kami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sry for being a bit nit-picky about this @D4nte - added some comments.

src/negotiation/maker_client.ts Outdated Show resolved Hide resolved
src/negotiation/maker_client.ts Show resolved Hide resolved
src/negotiation/maker_client.ts Outdated Show resolved Hide resolved
src/negotiation/maker_client.ts Show resolved Hide resolved
src/negotiation/maker_negotiator.ts Outdated Show resolved Hide resolved
src/negotiation/order.ts Outdated Show resolved Hide resolved
src/negotiation/order.ts Outdated Show resolved Hide resolved
src/negotiation/taker_negotiator.spec.ts Outdated Show resolved Hide resolved
src/negotiation/taker_negotiator.ts Outdated Show resolved Hide resolved
src/negotiation/taker_negotiator.ts Outdated Show resolved Hide resolved
@D4nte D4nte force-pushed the 89-taker-order-criteria branch from 584e472 to ec07812 Compare February 17, 2020 23:08
@D4nte D4nte requested a review from luckysori February 17, 2020 23:21
@D4nte D4nte added no-mergify Stop mergify to merge this automatically and removed no-mergify Stop mergify to merge this automatically labels Feb 17, 2020
@D4nte D4nte requested a review from da-kami February 17, 2020 23:22
Copy link
Member

@da-kami da-kami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added one commit.

*/
export class Order {
/**
* **Note: This should not be used, `Order` should be created by using `TakerNegotiatior.getOrder()`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* **Note: This should not be used, `Order` should be created by using `TakerNegotiatior.getOrder()`

Not a blocker, feel free to ignore.

Franck Royer added 6 commits February 18, 2020 13:23
Not only this helps with mocking but I believe it is the correct move.
Indeed, if one decides to use the SDK for LN-Bitcoin to ERC20 only, then
It would not use a `BitcoinWallet` class but one that handles LightningBitcoin
Create mock class to mock axios calls.
@D4nte D4nte force-pushed the 89-taker-order-criteria branch from dd03f68 to 2077cd3 Compare February 18, 2020 02:31
@D4nte D4nte merged commit 2cbf2f4 into master Feb 18, 2020
@D4nte D4nte deleted the 89-taker-order-criteria branch February 18, 2020 02:33
bors bot added a commit to comit-network/create-comit-app that referenced this pull request Feb 20, 2020
440: Use new `TakerNegotiator` interface r=D4nte a=D4nte

Incorporates SDK changes from comit-network/comit-js-sdk#116

Related to comit-network/comit-js-sdk#89

Co-authored-by: Franck Royer <franck@coblox.tech>
@D4nte D4nte removed the no-mergify Stop mergify to merge this automatically label Feb 24, 2020
@mergify
Copy link
Contributor

mergify bot commented Feb 24, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 24, 2020

Already running a review

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Taker's order criteria
3 participants