diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 34eabf4..d5f0ea3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,5 +19,18 @@ jobs: run: npm ci - name: typecheck run: npm run build - - name: test - run: npm test \ No newline at end of file + - name: Install PM2 and wait-port + run: | + npm install -g pm2 + npm install -g wait-port + - name: Run Ganache in the background + working-directory: ./pkg/app + run: | + pm2 --name ganache-service start npm -- run start-ganache + wait-port -t 10000 127.0.0.1:8545 + - name: Run tests + run: npm test + - name: Remove ganache process from the background + if: always() + run: | + pm2 delete ganache-service diff --git a/examples/rebalancing.ts b/examples/rebalancing.ts index bc7b67d..af617d7 100644 --- a/examples/rebalancing.ts +++ b/examples/rebalancing.ts @@ -1,5 +1,5 @@ -import { WalletManagerOptions, WalletManagerConfig } from 'wallet-monitor'; -import {buildWalletManager} from "../src"; +import { WalletManagerOptions, WalletManagerConfig } from "wallet-monitor"; +import { buildWalletManager } from "../src"; // npx ganache -i 5777 \ // --wallet.accounts=0xf9fdbcbcdb4c7c72642be9fe7c09ad5869a961a8ae3c3374841cb6ead5fd34b1,200000000000000000 \ @@ -13,16 +13,15 @@ import {buildWalletManager} from "../src"; // --wallet.accounts=0x6790f27fec85575792c7d1fab8de9955aff171b24329eacf2a279defa596c5d3,200000000000000000 \ // --wallet.accounts=0xe94000d730b9655850afc8e39facb7058678f11e765075d4806d27ed619f258c,10000000000000000000 - const options: WalletManagerOptions = { - logLevel: 'debug', + logLevel: "debug", balancePollInterval: 5000, metrics: { enabled: true, serve: true, port: 9091, }, - failOnInvalidChain: true + failOnInvalidChain: true, }; const allChainWallets: WalletManagerConfig = { @@ -32,27 +31,55 @@ const allChainWallets: WalletManagerConfig = { }, rebalance: { enabled: true, - strategy: 'pourOver', + strategy: "pourOver", interval: 10000, minBalanceThreshold: 0.3, maxGasPrice: 10000, gasLimit: 1000000, }, wallets: [ - { privateKey: '0xf9fdbcbcdb4c7c72642be9fe7c09ad5869a961a8ae3c3374841cb6ead5fd34b1' }, - { privateKey: '0x5da88a1c7df3490d040792fcca4676e709fdd3e6f6e0142accc96cb7e205e1e0' }, - { privateKey: '0xa2c984f6a752ee05af03dac0bb65f3ec93f1498d43d23ebe6c31cf988d771423' }, - { privateKey: '0xe0c1c809d0e80dcaaf200b3aec2a91cd00ed05134f10026113219d89d2f6a9b2' }, - { privateKey: '0x3500084e268b862df23a229f268510cdee92623102c4786b0ade6203fa59f421' }, - { privateKey: '0x49692cfecfb48cee7ce8a14273bda6996b832149ff7260bca09c2ea159e9147f' }, - { privateKey: '0xb2868bd9090dcfbc9d6f3012c98039ee20d778f8ef2d8cb721c56b69578934f3' }, - { privateKey: '0x50156cc51cb7ae4f5e6e2cb14a75fc177a1917fbab1a8675db25619567515ddd' }, - { privateKey: '0x6790f27fec85575792c7d1fab8de9955aff171b24329eacf2a279defa596c5d3' }, - { privateKey: '0xe94000d730b9655850afc8e39facb7058678f11e765075d4806d27ed619f258c' }, - ] + { + privateKey: + "0xf9fdbcbcdb4c7c72642be9fe7c09ad5869a961a8ae3c3374841cb6ead5fd34b1", + }, + { + privateKey: + "0x5da88a1c7df3490d040792fcca4676e709fdd3e6f6e0142accc96cb7e205e1e0", + }, + { + privateKey: + "0xa2c984f6a752ee05af03dac0bb65f3ec93f1498d43d23ebe6c31cf988d771423", + }, + { + privateKey: + "0xe0c1c809d0e80dcaaf200b3aec2a91cd00ed05134f10026113219d89d2f6a9b2", + }, + { + privateKey: + "0x3500084e268b862df23a229f268510cdee92623102c4786b0ade6203fa59f421", + }, + { + privateKey: + "0x49692cfecfb48cee7ce8a14273bda6996b832149ff7260bca09c2ea159e9147f", + }, + { + privateKey: + "0xb2868bd9090dcfbc9d6f3012c98039ee20d778f8ef2d8cb721c56b69578934f3", + }, + { + privateKey: + "0x50156cc51cb7ae4f5e6e2cb14a75fc177a1917fbab1a8675db25619567515ddd", + }, + { + privateKey: + "0x6790f27fec85575792c7d1fab8de9955aff171b24329eacf2a279defa596c5d3", + }, + { + privateKey: + "0xe94000d730b9655850afc8e39facb7058678f11e765075d4806d27ed619f258c", + }, + ], }, +}; -} - - -export const manager = buildWalletManager({config: allChainWallets, options}) +export const manager = buildWalletManager({ config: allChainWallets, options }); diff --git a/package.json b/package.json index 2e83dc7..5922903 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,8 @@ "watch": "tsc -w", "lint": "eslint --ignore-path .gitignore --ext .js,.ts .", "prettier": "prettier --ignore-path .gitignore --write .", - "test": "jest --silent=false" + "test": "jest --silent=false", + "start-ganache": "npx ganache -i 5777 --wallet.accounts=0xf9fdbcbcdb4c7c72642be9fe7c09ad5869a961a8ae3c3374841cb6ead5fd34b1,200000000000000000 --wallet.accounts=0x5da88a1c7df3490d040792fcca4676e709fdd3e6f6e0142accc96cb7e205e1e0,200000000000000000 --wallet.accounts=0xa2c984f6a752ee05af03dac0bb65f3ec93f1498d43d23ebe6c31cf988d771423,200000000000000000 --wallet.accounts=0xe0c1c809d0e80dcaaf200b3aec2a91cd00ed05134f10026113219d89d2f6a9b2,200000000000000000 --wallet.accounts=0x3500084e268b862df23a229f268510cdee92623102c4786b0ade6203fa59f421,200000000000000000 --wallet.accounts=0x49692cfecfb48cee7ce8a14273bda6996b832149ff7260bca09c2ea159e9147f,200000000000000000 --wallet.accounts=0xb2868bd9090dcfbc9d6f3012c98039ee20d778f8ef2d8cb721c56b69578934f3,200000000000000000 --wallet.accounts=0x50156cc51cb7ae4f5e6e2cb14a75fc177a1917fbab1a8675db25619567515ddd,200000000000000000 --wallet.accounts=0x6790f27fec85575792c7d1fab8de9955aff171b24329eacf2a279defa596c5d3,200000000000000000 --wallet.accounts=0xe94000d730b9655850afc8e39facb7058678f11e765075d4806d27ed619f258c,10000000000000000000" }, "repository": { "type": "git", diff --git a/test/utilities/wallet.ts b/test/utilities/wallet.ts index 09fcfca..f8688c8 100644 --- a/test/utilities/wallet.ts +++ b/test/utilities/wallet.ts @@ -1,6 +1,9 @@ import { WalletManager } from "../../src/wallet-manager"; import { timeout } from "./common"; +export const ETH_ADDR = "0xFa6E597ca1c7E72838c850d1268dDf618D444712"; +export const ETH_ADDR_2 = "0x0EaC31cB932229D0Dcc628f89894012b7827481c"; + export const checkIfWalletIsReady = async ( walletManager: WalletManager, ): Promise => { @@ -12,3 +15,18 @@ export const checkIfWalletIsReady = async ( await timeout(isWalletReady, 5000); }; + +export const getWallets = () => { + return [ + { + address: ETH_ADDR, + privateKey: + "0xf9fdbcbcdb4c7c72642be9fe7c09ad5869a961a8ae3c3374841cb6ead5fd34b1", + }, + { + address: ETH_ADDR_2, + privateKey: + "0xe94000d730b9655850afc8e39facb7058678f11e765075d4806d27ed619f258c", + }, + ]; +}; diff --git a/test/wallet-manager.test.ts b/test/wallet-manager.test.ts index 47656fe..f32fd04 100644 --- a/test/wallet-manager.test.ts +++ b/test/wallet-manager.test.ts @@ -6,11 +6,14 @@ import { WithWalletExecutor, } from "../src/chain-wallet-manager"; import { ETHEREUM } from "../src/wallets/evm/ethereum.config"; -import { checkIfWalletIsReady } from "./utilities/wallet"; +import { + ETH_ADDR, + ETH_ADDR_2, + checkIfWalletIsReady, + getWallets, +} from "./utilities/wallet"; import { wait } from "./utilities/common"; -const ETH_ADDR = "0xFa6E597ca1c7E72838c850d1268dDf618D444712"; -const ETH_ADDR_2 = "0x0EaC31cB932229D0Dcc628f89894012b7827481c"; const WAIT_TO_ACQUIRE_TIMEOUT = 10; const rebalanceConfig: WalletRebalancingConfig = { @@ -142,18 +145,7 @@ const givenAWalletManager = async ( [ETHEREUM]: { rebalance: rebalanceConfig, network: DEVNET, - wallets: [ - { - address: ETH_ADDR, - privateKey: - "0xf9fdbcbcdb4c7c72642be9fe7c09ad5869a961a8ae3c3374841cb6ead5fd34b1", - }, - { - address: ETH_ADDR_2, - privateKey: - "0xe94000d730b9655850afc8e39facb7058678f11e765075d4806d27ed619f258c", - }, - ], + wallets: getWallets(), }, };