-
Notifications
You must be signed in to change notification settings - Fork 254
Integration of a swap plugin
Edge calls crypto-to-crypto plugins "swap" plugins. If you would like to build one of these plugins, these are the general steps:
- Set up your system to build edge-react-gui
- Add your plugin to the edge-exchange-plugins repo.
- Integrate your new plugin into the wallet.
Building the wallet begins with the edge-react-gui repo. The instructions in the readme should be more-or-less accurate.
Building React Native applications in general can require a lot of setup. The React Native getting started guide is also a reasonable starting place.
Swap plugins live in the edge-exchange-plugins repo. You can see some existing swap plugins implemented in there, like https://github.com/EdgeApp/edge-exchange-plugins/blob/master/src/plugins/changelly.js
Suppose your exchange is called Foo. Your plugin would begin with a makeFooPlugin
call, which happens once at app boot. This would accept configuration options (like API keys), and return an instance of your plugin. It also accepts an io
object, which provides access to the outside world. You can see the definition of EdgeIo
and other data types here: https://github.com/EdgeApp/edge-core-js/blob/49856eb8f053e4883ab3b94f3dcd4069a1ea9a8f/src/types/types.js#L54
Anyhow, your makeFooPlugin
returns an EdgeSwapPlugin
object. Assuming you don’t need KYC, you only need to implement a single method fetchSwapQuote
. This either needs to return an estimate of the number of coins out + mining fee, or some kind of error (SwapAboveLimitError / SwapBelowLimitError / SwapCurrencyError / SwapPermissionLimitError). You can see the error definitions in https://github.com/EdgeApp/edge-core-js/blob/master/src/types/error.js. Since this is just an estimate, there is no need to create a transaction or otherwise commit to doing the swap - it’s just an information query!
We use nativeAmount
to refer to amounts in Satoshis, Wei, or whatever the smallest integer unit the coin supports. Since coins like Ethereum have too many decimal points for the Javascript number
type, a nativeAmount
is always a string for accuracy.
Most plugins create a transaction as part of the estimate, since this is a quick & easy way to estimate the fee, but they don’t sign or broadcast the transaction. If the user decides to accept the quote, they will call the approve
method on the EdgeSwapPluginQuote
. You can use this opportunity to actually commit to the swap & broadcast the transaction. Otherwise, our app will call the close
method on any rejected quotes.
These are the steps you need to simply make the plugin available in the wallet core:
- Plugin exists in
edge-exchange-plugins
- Plugin is exported from
edge-exchange-plugins/src/index.js
- You have done
yarn updot edge-exchange-plugins && yarn postinstall
inside the edge-react-gui project - You have added the plugin to
contextOptions
inedge-react-gui/src/components/core/EdgeCoreManager.js
- If the plugin depends on
ENV.FOO_INIT
, you have added aFOO_INIT
section to env.json.
If you plugin depends on API keys, put them into an object called FOO_INIT
, then edit env.json
and env.sample.json
to define this object.
Android
200x 70 in android/app.src/main/res/mipmap-mdpi/ <filename_all_lower_case>.png
400 x 140 in android/app.src/main/res/drawable-xxhdpi/<filename_all_lower_case>.png
600x 210 in android/app.src/main/res/drawable-xxxhdpi/<filename_all_lower_case>.png
iOS
200x 70 ios/SplashScreenResource/<filename_all_lower_case>.png
400 x 140 ios/SplashScreenResource/<filename_all_lower_case>@2x.png
600x 210 ios/SplashScreenResource/<filename_all_lower_case>@3x.png
Settings Exchange logos:
64 x 64 In src/assets/images/exchange/<filename>.png
**Javascript files **
src/components/scene/ExchangeSettingsScene.js
Look at how other plugins are integrated into these pages.
src/components/scene/CryptoExchangeScene.js
If your plugin needs to have a user signed into an account for KYC , look at how ShapeShift is handled in getKYCToken function
src/components/scene/CryptoExchangeQuoteScene.js
If your plugin requires an acknowledgement of some KYC feature look at how changelly is set up in the checkForKYC function.