Giter VIP home page Giter VIP logo

atomex-sdk's Introduction

Atomex SDK

npm version Atomex SDK License: GPL-3.0

⚠️ Atomex SDK is in active development so any component (application, contract, package, API) is subject to change ⚠️

atomex-sdk's People

Contributors

aopoltorzhicky avatar gdsoumya avatar m-kus avatar maxima-net avatar skubarenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

atomex-sdk's Issues

Publish to npm, update readme

  • make release
  • New Github workflow "Release" triggered by tag: build lib, run tests, and publish to npm
  • Add readme badges (workflow status, npm badge)
  • Add few examples and basic workflow for the updated package structure

Unit test coverage

Test requests/responses against OpenAPI spec (see examples at https://github.com/atomex-me/atomex-sdk-ts/blob/master/test/atomex.spec.ts)

  • Atomex.getAuthToken
  • Atomex.getQuotes
  • Atomex.getSymbols
  • Atomex.getOrderBook
  • Atomex.addOrder
  • Atomex.getOrders
  • Atomex.getOrder
  • Atomex.cancelOrder
  • Atomex.addSwapRequisites
  • Atomex.getSwaps
  • Atomex.getSwap

Test Tezos helpers (see examples at https://github.com/atomex-me/atomex-sdk-ts/blob/master/test/tezos.spec.ts)

  • TezosHelpers.getAuthMessage
  • TezosHelpers.buildInitiateTransaction
  • TezosHelpers.buildRedeemTransaction
  • TezosHelpers.buildRefundTransaction
  • TezosHelpers.buildAddTransaction
  • TezosHelpers.getBlockDetails
  • TezosHelpers.parseInitiateParameters (default case covered, need to cover initiate, fund cases; also variants of timestamp: int/string, address: bytes/string)
  • TezosHelpers.findContractCall
  • TezosHelpers.validateInitiateTransaction (mock TezosToolkit, see https://github.com/baking-bad/taquito/blob/master/packages/taquito/test/taquito.spec.ts)

Test Ethereum helpers (see examples at https://github.com/atomex-me/atomex-sdk-ts/blob/master/test/ethereum.spec.ts)

  • EthereumHelpers.buildInitiateTransaction
  • EthereumHelpers.buildRedeemTransaction
  • EthereumHelpers.buildRefundTransaction
  • EthereumHelpers.buildAddTransaction
  • EthereumHelpers.buildActivateTransaction
  • EthereumHelpers.parseInitiateParameters
  • EthereumHelpers.validateInitiateTransaction (mock web3, see https://gist.github.com/nakajo2011/4d09fb1e941d48d131ae3739402d8990)
  • EthereumHelpers.recoverPublicKey
  • EthereumHelpers.getAuthMessage

Create Base Setup for SDK

  • Setup Git and NPM settings
  • Install Base Dependencies [TypeScript, fetch, eslint]
  • Setup Package Scripts [build, compile, lint]
  • Setup Linting and TSConfig

Fix and complete the tutorial

  • Migrate to the new API layout
  • Utilize new helpers (order preview, fees estimation, signature/pubkey encoding)
  • Validate MM's initiate tx using TezosHelpers
  • Make Initiate tx in eth using EthereumHelpers
  • Validate Client's initiate tx using EthereumHelpers
  • Make redeem tx in tez using TezosHelpers
  • Make redeen tx in eth using EthereumHelpers

Helpers: encode signatures (RS) and public keys (SEC)

Tezos uses Base58 encoding (with prefix and checksum) for signatures and public keys.
Ethereum uses RLP codec https://eth.wiki/fundamentals/rlp
Atomex accepts raw R|S signatures and SEC keys (both compressed and uncompressed).
More info: https://bitcoin.stackexchange.com/questions/92680/what-are-the-der-signature-and-sec-format

Implement the following methods:

Helpers {
  abstract encodeSignature(signature: string) : string;
  abstract encodePublicKey(publicKey: string) : string;
}

Write unit tests:

# Tezos public keys
edpku976gpuAD2bXyx1XGraeKuCo1gUZ3LAJcHM12W1ecxZwoiu22R
419491b1796b13d756d394ed925c10727bca06e97353c5ca09402a9b6b07abcc

sppk7aMNM3xh14haqEyaxNjSt7hXanCDyoWtRcxF8wbtya859ak6yZT
0289e69b581187dba9ecfcaebe6874b445349ec0ef263760ea7b31f597a7d9d903

p2pk679D18uQNkdjpRxuBXL5CqcDKTKzsiXVtc9oCUT6xb82zQmgUks
03526cd78c46739469a968cfc2985109b4e3b92419ed5bcca5fdf3352c4425590e

# Tezos signatures
edsigtzLBGCyadERX1QsYHKpwnxSxEYQeGLnJGsSkHEsyY8vB5GcNdnvzUZDdFevJK7YZQ2ujwVjvQZn62ahCEcy74AwtbA8HuN
cabde71255b1f1674182cb7f8000903909dbe6dbb6a76afd3376c08a4f827b2bc938ed447f3e592766e89aea89fecfd1e8c8e82c71f60271cd08ac012262d603

spsig1RriZtYADyRhyNoQMa6AiPuJJ7AUDcrxWZfgqexzgANqMv4nXs6qsXDoXcoChBgmCcn2t7Y3EkJaVRuAmNh2cDDxWTdmsz
993bce003ff00effd092baaefd31474639cdb0e86ec3dd2b605d2865cd8b92d67e9e02b4e5549c2436d1daeeb18a2a8b6c9c3e8f213400a29bfa08a9ace55a06

p2signmC9s4SiDeMggfipq2Y1P3sz8sEEh4Dr3P5XHQ1imsyz9tSRpQQKgiTGzQ5Bfbs9tRyvPhV59rMjhbgG8Xa4wtoMgRnd5
c29b03c206b2a44675596e4fe15d4320840f50af5415b4a1f96ed427ffd0457446866e63a96e823ec65bdb34a7d89726b50440265b97507a4f27dfce16996f9a

sigQVTY9CkYw8qL6Xa7QWestkLSdtPv6HZ4ToSMHDcRot3BwRGwZhSwXd9jJwKkDvvotTLSNWQdUqiDSfXuCNUfjbEaY2j6j
13216a89c0ab77152c24d898792424b03b6f13e3f79323015cfe47e83a8766e4716f34ea83e0cd8efbc0ada95ba5a9d49e290961a8f8d6141c012e45b290e234

# Ethereum public keys
0x0492c4d2894b93d64189d6e2fc660e9090622148f8088c4bd967879d32ed438f9178852b4d34a23021da02b07ff7acc1ffb29404fd268f1c8cea7f92bfc24fdc48
0492c4d2894b93d64189d6e2fc660e9090622148f8088c4bd967879d32ed438f9178852b4d34a23021da02b07ff7acc1ffb29404fd268f1c8cea7f92bfc24fdc48

# Ethereum signatures (NOTE: this is not just split and combine in general case, use RLP decoder)
0xda026bc6ff1a6aaa0838b930a9385c3eed6330c9858b0f8d175ce135376082190163416128cb97a2aed4e8bb98bb2a2fc2b0b4dd69b8595fd7ca8b0388a1076c1c
da026bc6ff1a6aaa0838b930a9385c3eed6330c9858b0f8d175ce135376082190163416128cb97a2aed4e8bb98bb2a2fc2b0b4dd69b8595fd7ca8b0388a1076c 

Helpers: estimate minerFee and rewardForRedeem

MinerFee (for initiate tx)

Use web3/taquito estimation mechanism.

RewardForRedeem (for redeem tx)

Currently we use the following approach: reward for redeem should be approx. 2x miner fee for the redeem operation.
In Tezos also consider whether account is allocated or not (empty) — it will require additional burn in the latter case.

It's also worth caching these values (in a private class field) since they likely won't change during the session, but quite costly in terms of time.

Helpers {
  abstract estimateFees() : Fees;
}

interface Fees {
  minerFee: number;
  rewardForRedeem: number;
}

Write unit tests using jest mocking

Helpers: get order preview

Goal: based on the amount to be sent/received + order book calculate the amount to be received/sent (i.e. price) if possible (enough liquidity). Consider order granularity (should match a single order)

class Helpers {
  static getOrderPreview(orderBook: OrderBook, side: Side, amount: number, direction: Send | Receive) : OrderPreview;
}

interface OrderPreview {
  price: number;
  amountSent: number;
  amountReceived: number;
}

Create Blockchain Helper Functions

  • Generating Nonce
  • Estimating redeem rewards [user choice will be updated to api endpoint]
  • Checking transaction status on-chain - Tezos: 2 confirms, Ethereum: ?
  • Estimating transaction confirmation time (Ethereum, Tezos) + heurustic
  • Preparing transaction contents and signing requests for Web3/Beacon wallets [Need Contract invocation details]

Atomex.getOrderSide

Signature: getOrderSide(symbol, srcChain, dstChain)

symbol -> baseCurrency/quoteCurrency
if baseCurrency ∈ srcChain && quoteCurrency ∈ dstChain then side = "Sell" else "Buy"

For each currency in config add chain (e.g. ETH -> ethereum, XTZ -> tezos, TBTC -> ethereum, TZBTC -> tezos)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.