From c01c5d39cefe4bc1fd8c3a4316c1c651d683c81f Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Tue, 16 Jun 2020 11:20:59 -0400 Subject: [PATCH 1/4] feat: add param for legacy hd path --- oracle/example-env | 5 ++++- oracle/oracle.js | 5 +++-- package.json | 4 ++-- scripts/config.js | 1 + scripts/oracle.js | 12 ++++++++---- yarn.lock | 8 ++++---- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/oracle/example-env b/oracle/example-env index ad1f2e1..8eaf0dc 100644 --- a/oracle/example-env +++ b/oracle/example-env @@ -21,4 +21,7 @@ EXPIRY="14400" # how long (in seconds) before the oracle will consider a price expiring and post a new price, regardless of the value of deviation. # for example, if this is set to 600, the oracle will post a price any time the current posted price is expiring in less than 600 seconds. -EXPIRY_THRESHOLD="300" \ No newline at end of file +EXPIRY_THRESHOLD="300" + +# if the oracle should use the legacy HD path for kava (118). Setting to "true" will use 118, false will use 459 +LEGACY_HD_PATH="false" \ No newline at end of file diff --git a/oracle/oracle.js b/oracle/oracle.js index 01b4993..2c4cb4d 100644 --- a/oracle/oracle.js +++ b/oracle/oracle.js @@ -44,9 +44,10 @@ class PriceOracle { * Initialize the Kava client * @param {String} lcdURL api endpoint for Kava's rest-server * @param {String} mnemonic Kava address mnemonic + * @param {Boolean} legacyHDPath * @return {Promise} */ - async initClient(lcdURL, mnemonic) { + async initClient(lcdURL, mnemonic, legacyHDPath=false) { if (!lcdURL) { throw new Error("chain's rest-server url is required"); } @@ -56,7 +57,7 @@ class PriceOracle { // Initiate and set Kava client this.client = new kava.KavaClient(lcdURL); - this.client.setWallet(mnemonic); + this.client.setWallet(mnemonic, '', legacyHDPath); this.client.setBroadcastMode('sync'); try { await this.client.initChain(); diff --git a/package.json b/package.json index 49729cd..368c0ed 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@kava-labs/kava-tools", "description": "Tools for interacting with the Kava blockchain", - "version": "0.1.3", + "version": "0.1.4", "license": "Apache-2.0", "main": "index.js", "author": "Kava Labs", @@ -14,7 +14,7 @@ }, "homepage": "https://github.com/Kava-Labs/kava-tools#readme", "dependencies": { - "@kava-labs/javascript-sdk": "^2.0.0-beta.4", + "@kava-labs/javascript-sdk": "^2.0.0-beta.6", "axios": "^0.19.2", "coingecko-api": "^1.0.10", "dotenv": "^8.2.0", diff --git a/scripts/config.js b/scripts/config.js index 39adc41..a807f7d 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -12,4 +12,5 @@ module.exports = { forward_bid_margin: process.env.FORWARD_BID_MARGIN, reverse_bid_margin: process.env.REVERSE_BID_MARGIN, crontab: process.env.CRONTAB, + legacy_hd_path: process.env.LEGACY_HD_PATH }; diff --git a/scripts/oracle.js b/scripts/oracle.js index ae9a98f..feadacb 100644 --- a/scripts/oracle.js +++ b/scripts/oracle.js @@ -10,15 +10,19 @@ var main = async () => { const expiry = process.env.EXPIRY; const expiryThreshold = process.env.EXPIRY_THRESHOLD; const deviation = process.env.DEVIATION; + let legacyHDPath = false + if (process.env.LEGACY_HD_PATH === 'true') { + legacyHDPath = true + } // Initiate price oracle oracle = new PriceOracle(marketIDs, expiry, expiryThreshold, deviation); - await oracle.initClient(lcdURL, mnemonic); + await oracle.initClient(lcdURL, mnemonic, legacyHDPath); // Start cron job - cron.schedule(process.env.CRONTAB, () => { - oracle.postPrices(); - }); + // cron.schedule(process.env.CRONTAB, () => { + // oracle.postPrices(); + // }); }; main(); diff --git a/yarn.lock b/yarn.lock index 2430c65..3545185 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@kava-labs/javascript-sdk@^2.0.0-beta.4": - version "2.0.0-beta.4" - resolved "https://registry.yarnpkg.com/@kava-labs/javascript-sdk/-/javascript-sdk-2.0.0-beta.4.tgz#0740d46cb68c959870a1fe81030ca108183bf783" - integrity sha512-tuJvxYnlnF6G35HUNmgYZgtFsgDAqFZdZREWCkwjhSAFC2DwxEfPQw2mLiVd1qCJASkFkrt1eShxlSfKnYobCQ== +"@kava-labs/javascript-sdk@^2.0.0-beta.6": + version "2.0.0-beta.6" + resolved "https://registry.yarnpkg.com/@kava-labs/javascript-sdk/-/javascript-sdk-2.0.0-beta.6.tgz#d3677c246a70f7ed7e8af3b28b0b96cd798eff41" + integrity sha512-OvXSAuJ5inHLWJ++8mZIdBs5UNKooixPg48rFPJ9Y2r1wYQcfDQsnr5Rbs+ROKkmiC0RdYuRo4/pjEXcA8Jrug== dependencies: "@kava-labs/sig" "^0.1.0" axios "^0.19.2" From a16d6d935687086bdf3c8bbd5f9fcc30002cbd55 Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Tue, 16 Jun 2020 11:23:28 -0400 Subject: [PATCH 2/4] bump versionx --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 368c0ed..7e86fe7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@kava-labs/kava-tools", "description": "Tools for interacting with the Kava blockchain", - "version": "0.1.4", + "version": "0.1.5", "license": "Apache-2.0", "main": "index.js", "author": "Kava Labs", From cac091289b9aac7c11a203fd77097d595002f93d Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Tue, 16 Jun 2020 11:24:44 -0400 Subject: [PATCH 3/4] update oracle readme --- oracle/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/oracle/README.md b/oracle/README.md index 25b6ae2..1f425be 100644 --- a/oracle/README.md +++ b/oracle/README.md @@ -37,7 +37,7 @@ CRONTAB="* * * * *" # bip39 mnemonic of oracle MNEMONIC="secret words go here" -# List of markets the oracle will post prices for. See pricefeed parameters for the list of active markets. \\TODO add "all" method for next version +# List of markets the oracle will post prices for. See pricefeed parameters for the list of active markets. MARKET_IDS="bnb:usd,bnb:usd:30" # percentage deviation from previous price needed to trigger a new price - (example 0.5%) @@ -49,6 +49,9 @@ EXPIRY="14400" # how long (in seconds) before the oracle will consider a price expiring and post a new price, regardless of the value of deviation. # for example, if this is set to 600, the oracle will post a price any time the current posted price is expiring in less than 600 seconds. EXPIRY_THRESHOLD="300" + +# if the oracle should use the legacy HD path for kava (118). Setting to "true" will use 118, false will use 459 +LEGACY_HD_PATH="false" ``` Setup a `systemd` file to run the oracle process. An example with user `ubuntu` is as follows (note that the `nodejs` process is at `/usr/bin/nodejs`, this may be different depending on how you install node ): From 0d1bb34a92677e575af03cad91aa7e71eb4f58d1 Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Tue, 16 Jun 2020 16:24:20 -0400 Subject: [PATCH 4/4] bump version --- package.json | 2 +- scripts/oracle.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 7e86fe7..b119fd7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@kava-labs/kava-tools", "description": "Tools for interacting with the Kava blockchain", - "version": "0.1.5", + "version": "0.1.6", "license": "Apache-2.0", "main": "index.js", "author": "Kava Labs", diff --git a/scripts/oracle.js b/scripts/oracle.js index feadacb..993e563 100644 --- a/scripts/oracle.js +++ b/scripts/oracle.js @@ -20,9 +20,9 @@ var main = async () => { await oracle.initClient(lcdURL, mnemonic, legacyHDPath); // Start cron job - // cron.schedule(process.env.CRONTAB, () => { - // oracle.postPrices(); - // }); + cron.schedule(process.env.CRONTAB, () => { + oracle.postPrices(); + }); }; main();