1.7.4 • Published 1 day ago

@dydxprotocol/v4-abacus v1.7.4

Weekly downloads
-
License
BSL-1.1
Repository
-
Last release
1 day ago

Shared front-end and mobile logic written in Kotlin Multiplatform (https://kotlinlang.org/docs/multiplatform.html).

The library generates Swift framework for iOS, JVM library for Android, and Javascript code for Web.

giphy

Install Java 11

https://www.oracle.com/java/technologies/downloads/#java11

Documentation

API Documentation

iOS

Abacus uses Cocoapods to integrate with iOS project. The gradle configuration contains the steps needed to generate the .podspec file. Run

./gradlew podspec

to generate abacus.podspec. Configure your iOS project (https://github.com/dydxprotocol/native-ios) to import abacus.podspec.

You can also build the Abacus for iOS by running:

./gradlew assembleXCFramework

This generates the iOS framework in build/XCFrameworks folder.

Debugging on iOS directly from XCode is possible with a plugin (https://github.com/touchlab/xcode-kotlin)

Android

Abacus builds and pushes the JVM target as a Github package with the following command:

./publish_android.sh

The Android app (https://github.com/dydxprotocol/native-android) has the Gradle build step to pull the Abacus target from GithubPackage.

v4-web

If you are using v4-abacus with the v4-web repo, follow local development instructions here.

Other JavaScript / TypeScript

Abacus generates a Javascript / Typescript UMD module with the following command:

./gradlew assembleJsPackage

This outputs into build/packages/js.

A local npm package can be built with:

./gradlew packJsPackage

A tarball of the package should be created in build/packages and you can install it to your project for local testing:

npm install PATH_TO_TARBALL

Publishing to NPM

Abacus is published to an npm library (https://www.npmjs.com/package/@dydxprotocol/v4-abacus).

Unit Tests

Shared code should have unit tests written in Kotlin residing in the src/CommonTest directory. Run the tests with the following command

./gradlew test

Integration Tests

Integration tests can be written to call Abacus from non-Kotlin code (i.e., Swift, JS). Sample integration projects can be found in the integration directory.

Version Bump

./bump_version.sh

Auto-lint

Enable pre-commit to auto-lint/auto-format your changes before git commit:

brew install pre-commit pre-commit install

How to use

// create a state machine
val stateMachine = PerpTradingStateMachine()

// send socket payload to the state machine and get the state
// the param is the complete socket text
val state = stateMachine.socket(payloadText)

// See src/commonTest/kotlin/exchange.dydx.abacus/PerpV3Tests.kt for testing code

Structure

Misc:

  • Utils
  • Protocols

state (top state)

  • app -> AppStateMachine (contains network logic)
  • modal -> StateMachine (contains business logic)
  • changes -> Changes (utilities to identify which part of the state has changed)

processing:

step 1: processor (dynamic objects - dictionaries, list, not typed)

  • markets
    • orderbook
    • trades
    • funding
  • asset (referenced from markets, such as icon, url etc)
  • wallet (user info)
    • account
      • subaccount
        • assetPositions
        • openPositions
        • orders
        • fills
        • transfers
        • historicalPnl
  • configs (from Veronica mostly)

step 2 calculator (dynamic)

  • market (summary info)
  • account (step 3)
    • subaccount
      • 3.1 calculate positon notionalTotal/valueTotal etc
      • 3.2 calculate account equity etc, leverage, margin usage, buyingpower
      • 3.3 calcualte position levereage, buyingpower
  • account transformer (step 2)
    • calculate postOrder and postAllOrderStates for account (total from trade input) and positions (size from trade input)
  • input (step 1)
    • trade input
      • size (size, usdcSize, leverage)
    • transfer input (not complete)

step 3 validator (from postOrder and postAllOrders states)

  • trade
  • transfer

step 4 output (structs, typed data)

  • converts dynamic data to typed

step 5 responses

  • Construct response object from output

CommonTest

test (supporting classes, mostly mocks) utils (just utilities)

AppStateMachine (app)

  • StateMachine (payload and validation folder)

payload (test StateMachine payload and interaction)

  • API -> expected state validation (separated from payload, to target validation tests)

app (test AppStateMachine IO requests)

1.7.4

1 day ago

1.7.3

3 days ago

1.7.2

3 days ago

1.7.1

5 days ago

1.7.0

6 days ago

1.6.55

7 days ago

1.6.54

8 days ago

1.6.51

9 days ago

1.6.53

8 days ago

1.6.52

9 days ago

1.6.48

13 days ago

1.6.49

13 days ago

1.6.50

12 days ago

1.6.46

13 days ago

1.6.47

13 days ago

1.6.45

14 days ago

1.6.44

16 days ago

1.6.43

16 days ago

1.6.42

27 days ago

1.6.40

28 days ago

1.6.41

27 days ago

1.6.39

28 days ago

1.6.38

28 days ago

1.6.35

30 days ago

1.6.34

30 days ago

1.6.37

29 days ago

1.6.36

29 days ago

1.6.33

1 month ago

1.6.31

1 month ago

1.6.32

1 month ago

1.6.30

1 month ago

1.6.28

1 month ago

1.6.27

1 month ago

1.6.24

1 month ago

1.6.26

1 month ago

1.6.25

1 month ago

1.6.20

1 month ago

1.6.22

1 month ago

1.6.23

1 month ago

1.6.19

1 month ago

1.6.18

1 month ago

1.6.17

1 month ago

1.6.16

1 month ago

1.6.15

1 month ago

1.6.14

2 months ago

1.6.13

2 months ago

1.6.11

2 months ago

1.6.12

2 months ago

1.6.10

2 months ago

1.6.9

2 months ago

1.6.8

2 months ago

1.6.7

2 months ago

1.6.6

2 months ago

1.6.3

2 months ago

1.6.2

2 months ago

1.6.1

2 months ago

1.6.0

2 months ago

1.5.1

2 months ago

1.6.5

2 months ago

1.4.15

2 months ago

1.4.16

2 months ago

1.4.14

2 months ago

1.4.13

2 months ago

1.4.11

3 months ago

1.4.12

3 months ago

1.4.10

3 months ago

1.4.9

3 months ago

1.4.8

3 months ago

1.4.7

3 months ago

1.4.6

3 months ago

1.4.5

3 months ago

1.4.4

3 months ago

1.4.3

3 months ago

1.4.2

3 months ago

1.4.1

3 months ago

1.4.0

3 months ago

1.3.6

3 months ago

1.3.5

3 months ago

1.3.4

3 months ago

1.3.3

3 months ago

1.2.9

4 months ago

1.3.2

3 months ago

1.3.1

3 months ago

1.3.0

3 months ago

1.2.8

4 months ago

1.2.7

4 months ago

1.2.6

4 months ago

1.2.5

4 months ago

1.2.4

4 months ago

1.2.3

4 months ago

1.2.2

4 months ago

1.2.1

4 months ago

1.2.0

4 months ago

1.1.33

4 months ago

1.1.32

4 months ago

1.1.30

5 months ago

1.1.31

5 months ago

1.1.29

5 months ago

1.1.28

5 months ago

1.1.27

5 months ago

1.1.26

5 months ago

1.1.25

5 months ago

1.1.24

5 months ago

1.1.23

5 months ago

1.1.22

5 months ago

1.1.21

5 months ago

1.1.20

5 months ago

1.1.16

5 months ago

1.1.15

5 months ago

1.1.14

5 months ago

1.1.19

5 months ago

1.1.18

5 months ago

1.1.17

5 months ago

1.1.12

5 months ago

1.1.11

5 months ago

1.1.13

5 months ago

1.1.9

5 months ago

1.1.10

5 months ago

1.1.7

5 months ago

1.1.6

5 months ago

1.1.5

5 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.1.2

5 months ago

1.1.1

5 months ago

1.1.0

5 months ago

1.0.31

5 months ago

1.0.30

5 months ago

1.0.29

6 months ago

1.0.28

6 months ago

1.0.27

6 months ago

1.0.26

6 months ago

1.0.25

6 months ago

1.0.24

6 months ago

1.0.23

6 months ago

1.0.22

6 months ago

1.0.21

6 months ago

1.0.20

6 months ago

1.0.19

6 months ago

1.0.18

6 months ago

1.0.17

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago

0.7.9

7 months ago

0.7.8

7 months ago

0.7.7

7 months ago

0.7.6

7 months ago

0.7.5

7 months ago

0.7.3

7 months ago

0.7.2

7 months ago

0.7.1

7 months ago

0.7.0

7 months ago

0.6.20

7 months ago

0.6.19

7 months ago

0.6.18

7 months ago

0.6.17

7 months ago

0.6.16

7 months ago

0.6.15

7 months ago

0.6.14

7 months ago

0.6.13

7 months ago

0.6.12

7 months ago

0.6.5

7 months ago

0.6.4

7 months ago

0.6.3

7 months ago

0.6.2

7 months ago

0.6.1

7 months ago

0.6.0

7 months ago

0.5.12

7 months ago

0.5.11

7 months ago

0.5.10

8 months ago

0.5.9

8 months ago

0.5.8

8 months ago

0.5.7

8 months ago

0.5.6

8 months ago

0.5.5

8 months ago

0.5.4

8 months ago

0.5.3

8 months ago

0.5.2

8 months ago

0.5.1

8 months ago

0.5.0

8 months ago

0.4.46

8 months ago

0.4.45

8 months ago

0.4.44

8 months ago

0.4.33

8 months ago

0.4.32

8 months ago

0.4.30

8 months ago

0.4.29

8 months ago

0.4.28

8 months ago

0.4.27

8 months ago

0.4.26

8 months ago

0.4.24

8 months ago

0.4.23

8 months ago

0.4.22

8 months ago

0.4.21

8 months ago

0.4.20

8 months ago

0.4.18

8 months ago