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

feat(tradingapp): TradingApp nitro force move app #455

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

Conversation

nksazonov
Copy link
Contributor

No description provided.

@mod
Copy link
Contributor

mod commented Nov 26, 2024

What about:

    enum Action { OPEN, FUND, ORDER, TRADE, SETTLE, DEFUND, CLOSE }

    struct Entry {
        Action  action;
        uint256 timestamp;   // The time the entry was created
        bytes32 metadata;    // The data/content of the entry
        bytes32 parent;      // Checksum of the previous entry
        bytes32 current;     // Checksum of the current entry
    }

    // current = keccak256(abi.encodePacked(action, timestamp, metadata, parent));

    // Nitro validation:
    // make a switch case on Action
    // When OPEN:    Verify both signed
    // When FUND:    Verify broker signed
    // When ORDER:   Verify Fund proof, and order is signed by Client
    // When TRADE:   Verify proof of order, verify parent is ORDER, signed by Broker
    // When SETTLE:  Verify proof of trade, verify parent is TRADE, signed by Both

@mod
Copy link
Contributor

mod commented Nov 26, 2024

Using Named structs:

struct Order {
  bytes32 parent;  // Parent Event, can be 0 if first order
  bytes32 orderID; // tradeID
}

struct Trade {
  bytes32 orderID;  // orderID making the trade
  bytes32 tradeID;  // tradeID
}

struct Outcome {
  address token;
  uint256 amount;
}

struct Settle {
 Outcome[] toVault;
 Outcome[] fromVault;
 bytes32   parent;    // Likely the last TradeID
}

nksazonov and others added 2 commits November 26, 2024 18:01
* feat(contracts): add broker vault contract (WIP)

* fix(contracts): init TradingApp in ctor

* refactor(contracts): add underscore to performedSettlements mapping name to adhere code style

* refactor(contracts): resolve review comments

* refactor(contracts): handle edge case for balanceOf methods & use `require` instead of `if`s

* refactor(contracts): add support for native assets in deposit and withdraw methods

* fix(contracts): add nonReentract modifier on deposit, withdraw, and settle methods

* refactor: split TradingApp to adhere 'one interface per file' rule

* feat: verify full order history on settlement

* fix: reverse conditions

* fix(contracts): fix compiler errors and warnings

* refactor: move a settlement proof validation to a separate function

* feat: verify proof hash to avoid accepting modified proof

* fix: proceed with order/response validation if settlement parsing fails

* refactor: inline settlement decoding

* refactor: rename proofHash settlement field to ordersChecksum; resolve review comments

* refactor: rename `orderChecksum` field of settlement struct to plural form

* fix: resolve review comments

* refactor: process proofs in pairs on each iteration

* refactor: move pre/post-fund check out of settlement verification loop to save gas

* refactor: drop redundant verification

---------

Co-authored-by: nksazonov <[email protected]>
Copy link
Contributor

@mod mod left a comment

Choose a reason for hiding this comment

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

Can we start writing very basic tests?

}
}

// FIXME: should Vault support multiple brokers?
Copy link
Contributor

Choose a reason for hiding this comment

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

No, only using multiple vaults

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

Successfully merging this pull request may close these issues.

3 participants