Page MenuHomePhabricator

[ecash-agora] Improve approximation for USD-esque tokens
AbandonedPublicDraft

Authored by tobias_ruck on Thu, Oct 24, 21:48.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

Currently, the token parameter approximation is really imprecise for "normal" amounts for USD amounts.

For example, if someone offers 50 BUX tokens for $1 each (at $0.00003425/XEC), the actual price (for the maximum accepted amount) currently is $1.06/BUX, which is really imprecise, and precludes for any actual market discovery.

A quick fix is really simple: We just bump minTokenScaleFactor from 1000 to 10000, which trades off token amount precision in favor of price precision.

After this change, for the the same 50 BUX at $1 (for the maximum accepted amount), the actual price is $1.000017, which is much more precise (and the minimum is $1.0001).

minTokenScaleFactor parameter has been mostly chosen at random anyway (1000 being a "nice" number), but now with a real application, we can start to tune approximation to be more user friendly.

The tradeoff is that users won't be able to offer exactly 50 BUX, but instead 49.9968 BUX. and in 0.0256 BUX increments, but it's a reasonable assumption that users care more about price granularity than acceptable amount granularity.

The long term solution is to bump Script integers to 64-bits, which would make approximation so precise that we don't really have to worry about it.

Test Plan

npm test && npm run integration-tests

Diff Detail

Repository
rABC Bitcoin ABC
Branch
ecash-agora-improve-approximation
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 30822
Build 61157: Build Diffcashtab-tests · ecash-agora-tests · ecash-agora-integration-tests
Build 61156: arc lint + arc unit

Event Timeline

Failed tests logs:

====== CashTab Unit Tests: <Token /> available actions rendered We can list an SLP1 fungible token ======
TestingLibraryElementError: Unable to find an element with the text: List VSP?. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.

Ignored nodes: comments, script, style
<body>
  <div>
    <div
      class="sc-nrwXf hqTGAg"
    >
      <div
        class="Toastify"
      >
        <div
          class="Toastify__toast-container Toastify__toast-container--top-right sc-cpHetk gUNDhQ"
        >
          <div
            class="Toastify__toast Toastify__toast-theme--light Toastify__toast--error Toastify__toast--close-on-click Toastify--animate Toastify__bounce-enter--top-right"
            data-in="true"
            id="1"
          >
            <div
              class="Toastify__toast-body"
              role="alert"
            >
              <div
                class="Toastify__toast-icon Toastify--animate-icon Toastify__zoom-enter"
              >
                <svg
                  fill="var(--toastify-icon-color-error)"
                  height="100%"
                  viewBox="0 0 24 24"
                  width="100%"
                >
                  <path
                    d="M11.983 0a12.206 12.206 0 00-8.51 3.653A11.8 11.8 0 000 12.207 11.779 11.779 0 0011.8 24h.214A12.111 12.111 0 0024 11.791 11.766 11.766 0 0011.983 0zM10.5 16.542a1.476 1.476 0 011.449-1.53h.027a1.527 1.527 0 011.523 1.47 1.475 1.475 0 01-1.449 1.53h-.027a1.529 1.529 0 01-1.523-1.47zM11 12.5v-6a1 1 0 012 0v6a1 1 0 11-2 0z"
                  />
                </svg>
              </div>
              <div>
                Unable to create Agora offer with these parameters, try increasing the min buy.
              </div>
            </div>
            <button
              aria-label="close"
              class="Toastify__close-button Toastify__close-button--light"
              type="button"
            >
              <svg
                aria-hidden="true"
                viewBox="0 0 14 16"
              >
                <path
                  d="M7.71 8.23l3.75 3.75-1.48 1.48-3.75-3.75-3.75 3.75L1 11.98l3.75-3.75L1 4.48 2.48 3l3.75 3.75L9.98 3l1.48 1.48-3.75 3.75z"
                  fill-rule="evenodd"
                />
              </svg>
            </button>
            <div
              class="Toastify__progress-bar--wrp"
              data-hidden="false"
            >
              <div
                class="Toastify__progress-bar--bg Toastify__progress-bar-theme--light Toastify__progress-bar--error"
              />
              <div
                aria-hidden="false"
                aria-label="notification timer"
                class="Toastify__progress-bar Toastify__progress-bar--animated Toastify__progress-bar-theme--light Toastify__progress-bar--error"
                role="progressbar"
                style="animation-duration: 5000ms; animation-play-state: paused;"
              />
            </div>
          </div>
        </div>
      </div>
      <div
        class="sc-eitiEO ifMKmp"
      >
        <div
          class="sc-bhlBdH eMmGHI"
        >
          <div
            class="sc-jvEmr dkQKxn"
          >
            <img
              alt="cashtab"
              class="sc-hycgNl cDCVJE"
              src="test-file-stub"
            />
          </div>
          <div
            class="sc-ekulBa OErlf"
          >
            <select
              class="sc-ciodno hwcpAq"
              data-testid="wallet-select"
              id="wallets"
              name="wallets"
            >
              <option
                class="sc-gGCbJM cDEiNr"
                value="Token Test"
              >
                Token Test
              </option>
            </select>
            <div
              class="sc-dznXNo goxNXI"
            >
              <button
                aria-label="Copy ecash:qqq9f9z3uhpzkxrgdjkd7dxuuey7tmpmugpmnw0kue"
                class="sc-cQFLBn jGCEIx"
              >
                <svg
                  title="copy-paste"
                />
              </button>
              <div
                class="sc-gFaPwZ bhfoic"
              >
                <div
                  class="sc-fhYwyz kXwmEk"
                >
                  <input
                    checked=""
                    class="sc-bMvGRv dnGmSn"
                    id="show-hide-balance"
                    name="show-hide-balance"
                    title="show-hide-balance"
                    type="checkbox"
                  />
                  <label
                    class="sc-jzgbtB hsNhPD"
                    for="show-hide-balance"
                  >
                    <span
                      class="sc-gJWqzi dYGNll"
                      data-off=""
                      data-on=""
                    />
                    <span
                      class="sc-rBLzX gWpmmy"
                    />
                  </label>
                </div>
              </div>
            </div>
          </div>
          <div
            class="sc-ivVeuv cIXIDc"
            title="Wallet Info"
          >
            <div
             ...
    at Object.getElementError (/work/cashtab/node_modules/@testing-library/dom/dist/config.js:37:19)
    at /work/cashtab/node_modules/@testing-library/dom/dist/query-helpers.js:76:38
    at /work/cashtab/node_modules/@testing-library/dom/dist/query-helpers.js:52:17
    at /work/cashtab/node_modules/@testing-library/dom/dist/query-helpers.js:95:19
    at Object.getByText (/work/cashtab/src/components/Etokens/__tests__/TokenActions.test.js:387:23)

Each failure log is accessible here:
CashTab Unit Tests: <Token /> available actions rendered We can list an SLP1 fungible token

Please update the ecash-agora README changelog section with a link to this diff and a quick summary of what's going on