Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules
src/public/dist
public/dist
src/secrets/
/secrets/
logs
package-lock.json
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Webpack
2. npm install -g mocha nodemon
3. To build the client create an empty directory "public/dist" and run "npm run build-client"
4. Create empty directories "logs" and "db" in the project root
5. Create directory "secrets" and within a file accounts.js with the credentials of the liquidator/rollover/arbitrage wallets
5. Create directory "src/secrets" and within a file accounts.js with the credentials of the liquidator/rollover/arbitrage wallets
ks = encrypted keystore file in v3 standard.
(alternatively, you can specify pKey instead of ks to just use the private key)

Expand All @@ -65,7 +65,7 @@ export default "[telegram-bot-token]";
export default ""; for no notifications

6. Charge the Sovryn node wallets with all relevant tokens and enough Rbtc to cover tx cost.
7. Execute node -r esm util/approval.js to approve the Sovryn smart contract to spend Doc on behalf of the Sovryn node wallets as well as the swap network contract to spend tokens on behalf of the arbitrage wallet.
7. Execute npm run approve:[main || test] to approve the Sovryn smart contract to spend Doc on behalf of the Sovryn node wallets as well as the swap network contract to spend tokens on behalf of the arbitrage wallet.

```

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ require('chai')

// monkey-patch these at the earliest opportunity, otherwise initializing controller/Contract.js
// will fail if you have "ks" anywhere
import accounts from '../secrets/accounts';
import accounts from '../src/secrets/accounts';
accounts.liquidator = [];
accounts.rollover = [];
accounts.arbitrage = [];

// monkey-patch these too, to be sure.
import conf from '../config/config';
import conf from '../src/config/config';
conf.nodeProvider = 'http://example.invalid';
conf.publicNodeProvider = 'http://example.invalid';
conf.errorBotTelegram = undefined;
Expand Down
10 changes: 7 additions & 3 deletions integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"npm": "^3.0.0"
},
"scripts": {
"test": "node -r esm node_modules/.bin/hardhat test",
"test": "node -r ts-node/register node_modules/.bin/hardhat test",
"publish": "echo no && false",
"init-contracts": "git submodule update --init && bash ./initialize_contracts.sh",
"show-smart-contract-state": "node -r esm tools/showSmartContractState.js",
"show-arbitrage-state": "node -r esm tools/showSmartContractState.js"
"show-smart-contract-state": "node -r ts-node/register tools/showSmartContractState.js",
"show-arbitrage-state": "node -r ts-node/register tools/showSmartContractState.js"
},
"devDependencies": {
"@nomiclabs/hardhat-truffle5": "^2.0.0",
Expand All @@ -39,5 +39,9 @@
"sinon": "^10.0.0",
"truffle": "5.1.36",
"web3": "^1.2.11"
},
"dependencies": {
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
}
}
10 changes: 5 additions & 5 deletions integration-tests/test/base/backend.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { constants } from "@openzeppelin/test-helpers";
import conf from '../../../config/config';
import C from '../../../controller/contract';
import Wallet from '../../../controller/wallet';
import A from '../../../secrets/accounts';
import db from '../../../controller/db';
import conf from '../../../src/config/config';
import C from '../../../src/controller/contract';
import Wallet from '../../../src/controller/wallet';
import A from '../../../src/secrets/accounts';
import db from '../../../src/controller/db';
import {existsSync, unlinkSync} from 'fs';

/**
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/test/base/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import C from '../../../controller/contract';
import C from '../../../src/controller/contract';
const { BN } = require("@openzeppelin/test-helpers");
import abiTestToken from '../../../config/abiTestToken';
import abiTestToken from '../../../src/config/abiTestToken';
import {ether} from "@openzeppelin/test-helpers";

export async function transferAlmostAllRbtc({
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/test/test_arbitrage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { expect } from 'chai';
import { BN, ether, constants } from '@openzeppelin/test-helpers';
const { MAX_UINT256 } = constants;

import A from '../../secrets/accounts';
import Arbitrage from '../../controller/arbitrage';
import DB from '../../controller/db';
import conf from '../../config/config';
import A from '../../src/secrets/accounts';
import Arbitrage from '../../src/controller/arbitrage';
import DB from '../../src/controller/db';
import conf from '../../src/config/config';

import {initSovrynNodeForTesting} from "./base/backend";
import {initSovrynContracts, ConverterHelper} from "./base/contracts";
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/test/test_contract.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { BN } from '@openzeppelin/test-helpers';

import Contract from '../../controller/contract';
import Contract from '../../src/controller/contract';

import {initSovrynNodeForTesting} from "./base/backend";
import {initSovrynContracts, ConverterHelper} from "./base/contracts";
Expand Down
14 changes: 7 additions & 7 deletions integration-tests/test/test_liquidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { expect } from 'chai';
import { BN, ether, constants } from '@openzeppelin/test-helpers';
import sinon from 'sinon';

import A from '../../secrets/accounts';
import Liquidator from '../../controller/liquidator';
import Arbitrage from '../../controller/arbitrage';
import C from '../../controller/contract';
import PositionScanner from '../../controller/scanner';
import U from '../../util/helper';
import DB from '../../controller/db';
import A from '../../src/secrets/accounts';
import Liquidator from '../../src/controller/liquidator';
import Arbitrage from '../../src/controller/arbitrage';
import C from '../../src/controller/contract';
import PositionScanner from '../../src/controller/scanner';
import U from '../../src/util/helper';
import DB from '../../src/controller/db';

const LoanOpeningsEvents = artifacts.require("LoanOpeningsEvents");
import {initSovrynNodeForTesting} from "./base/backend";
Expand Down
10 changes: 5 additions & 5 deletions integration-tests/test/test_rollover.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { expect } from 'chai';
import { BN } from '@openzeppelin/test-helpers';
import sinon from 'sinon';

import A from '../../secrets/accounts';
import Rollover from '../../controller/rollover';
import C from '../../controller/contract';
import PositionScanner from '../../controller/scanner';
import DB from '../../controller/db';
import A from '../../src/secrets/accounts';
import Rollover from '../../src/controller/rollover';
import C from '../../src/controller/contract';
import PositionScanner from '../../src/controller/scanner';
import DB from '../../src/controller/db';

const LoanOpeningsEvents = artifacts.require("LoanOpeningsEvents");
import {initSovrynNodeForTesting} from "./base/backend";
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"version": "1.0.0",
"description": "liquidation handler and rollover of open positions for sovryn smart contracts",
"scripts": {
"test-lx": "mocha -r esm ./tests/test_liquidations.js --timeout 2500000",
"test-network": "node -r esm ./tests/network.js",
"start:test": "nodemon -r esm start.js testnet",
"start:main": "nodemon -r esm start.js mainnet",
"dev": "npx webpack-dev-server --open --config ./public/webpack.config.ts",
"build-client": "npx webpack --config ./public/webpack.config.ts",
"approveWalletsMain": "node -r esm ./util/approval.js mainnet",
"approveWalletsTest": "node -r esm ./util/approval.js testnet"
"test-lx": "mocha -r ts-node/register ./tests/test_liquidations.js --timeout 2500000",
"test-network": "node -r ts-node/register ./tests/network.js",
"start:test": "nodemon -r ts-node/register ./src/start.js testnet",
"start:main": "nodemon -r ts-node/register ./src/start.js mainnet",
"dev": "npx webpack-dev-server --open --config ./src/public/webpack.config.ts",
"build-client": "npx webpack --config ./src/public/webpack.config.ts",
"approve:main": "node -r ts-node/register ./src/util/approval.js mainnet",
"approve:test": "node -r ts-node/register ./src/util/approval.js testnet"
},
"author": "",
"license": "ISC",
Expand All @@ -27,10 +27,13 @@
"sqlite3": "^5.0.0",
"style-loader": "^2.0.0",
"telegraf": "^3.38.0",
"ts-node": "^9.1.1",
"typescript": "^4.2.4",
"web3": "1.3.3",
"webpack-dev-server": "^3.11.2"
},
"devDependencies": {
"mocha": "^8.4.0",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12"
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion controller/db.js → src/controller/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DbCtrl {

async initDb(dbName) {
return new Promise(resolve => {
const file = path.join(__dirname, '../db/' + dbName);
const file = path.join(__dirname, '../../db/' + dbName);
this.db = new sqlite3.Database(file, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {
if (err) {
console.error(err.message, file);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions public/webpack.config.ts → src/public/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const CopyPlugin = require('copy-webpack-plugin');

module.exports = {
entry: [
'./public/src/initWeb3.js',
'./public/src/index.js',
'./public/src/styles.css'
`${__dirname}/src/initWeb3.js`,
`${__dirname}/src/index.js`,
`${__dirname}/src/styles.css`
],
devtool: 'inline-source-map',
devServer: {
Expand All @@ -24,7 +24,7 @@ module.exports = {
plugins: [
new CopyPlugin({
patterns: [
{from: 'public/src/index.html'}
{from: `${__dirname}/src/index.html`}
]
}),
],
Expand Down
2 changes: 1 addition & 1 deletion start.js → src/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ monitor({
port: conf.healthMonitorPort
});

app.use('/', express.static('public/dist'));
app.use('/', express.static('../public/dist'));
http.listen(conf.serverPort, () => {
console.log('listening on *:'+conf.serverPort);
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/encrypt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import Web3 from 'web3';
import conf from '../config/config';
import wallets from '../secrets/accounts';
import conf from '../src/config/config';
import wallets from '../src/secrets/accounts';
var web3 = new Web3(conf.nodeProvider);


Expand Down
2 changes: 1 addition & 1 deletion tests/telegrambot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Testing telegram bot api
*/

import c from '../config/config';
import c from '../src/config/config';
const Telegram = require('telegraf/telegram');

console.log("start bot "+c.errorBotTelegram)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Api tester
*/
import c from '../config/config_testnet';
import c from '../src/config/config_testnet';
import io from 'socket.io-client';

const assert = require('assert');
Expand Down
2 changes: 1 addition & 1 deletion tests/test_arbitrage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import conf from '../config/config';
import C from '../controller/contract';
import Arbitrage from '../controller/arbitrage';
const assert = require('assert');
import db from "../controller/db";
import db from "../src/controller/db";
var pPriceFeed, pAmm;

describe('Arbitrage', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Tests for the Contract helper
* Set config file in /config.config.js manually because mocha.js overwrites process.arg
*/
import C from '../controller/contract';
import C from '../src/controller/contract';
const assert = require('assert');

describe('Contract', () => {
Expand Down
16 changes: 8 additions & 8 deletions tests/test_liquidations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
* Set test/mainnet in file /config.config.js manually because mocha.js overwrites process.arg
*/

import conf from '../config/config';
import conf from '../src/config/config';

import abiComplete from '../config/abiComplete';
import abiComplete from '../src/config/abiComplete';
import abiLoanToken from './abi/abiLoanToken';
import C from '../controller/contract';
import A from '../secrets/accounts';
import Liquidator from '../controller/liquidator';
import PosScanner from '../controller/scanner';
import Wallet from '../controller/wallet';
import common from '../controller/common'
import C from '../src/controller/contract';
import A from '../src/secrets/accounts';
import Liquidator from '../src/controller/liquidator';
import PosScanner from '../src/controller/scanner';
import Wallet from '../src/controller/wallet';
import common from '../src/controller/common'

const abiDecoder = require('abi-decoder');
const assert = require('assert');
Expand Down
4 changes: 2 additions & 2 deletions tests/test_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* general tests for interacting with the node.
*/

import c from '../config/config_testnet';
import abiComplete from '../config/abiComplete';
import c from '../src/config/config_testnet';
import abiComplete from '../src/config/abiComplete';
import abiLoanToken from './abi/abiLoanToken';
import abiLoanOpeningEvents from './abi/abiLoanOpeningEvents';
import Web3 from 'web3';
Expand Down
14 changes: 7 additions & 7 deletions tests/test_rollover.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
*
* Set config file in /config.config.js manually because mocha.js overwrites process.arg
*/
import conf from '../config/config';
import abiComplete from '../config/abiComplete';
import A from '../secrets/accounts';
import C from '../controller/contract';
import Rollover from '../controller/rollover';
import PosScanner from '../controller/scanner';
import Wallet from '../controller/wallet';
import conf from '../src/config/config';
import abiComplete from '../src/config/abiComplete';
import A from '../src/secrets/accounts';
import C from '../src/controller/contract';
import Rollover from '../src/controller/rollover';
import PosScanner from '../src/controller/scanner';
import Wallet from '../src/controller/wallet';
import abiLoanToken from './abi/abiLoanToken';

const assert = require('assert');
Expand Down
10 changes: 5 additions & 5 deletions tests/test_scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* Test the position scanner loop
* Set config file in /config.config.js manually because mocha.js overwrites process.arg
*/
import abiComplete from '../config/abiComplete';
import PosScanner from '../controller/scanner';
import C from '../controller/contract';
import common from '../controller/common'
import abiComplete from '../src/config/abiComplete';
import PosScanner from '../src/controller/scanner';
import C from '../src/controller/contract';
import common from '../src/controller/common'
const assert = require('assert');
const abiDecoder = require('abi-decoder');
abiDecoder.addABI(abiComplete);
import config from "../config/config";
import config from "../src/config/config";

let positions = {}
let liquidations = {};
Expand Down
10 changes: 5 additions & 5 deletions tests/test_wallets.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Set config file in /config.config.js manually because mocha.js overwrites process.arg
*/
const assert = require('assert');
import conf from '../config/config';
import C from '../controller/contract';
import A from '../secrets/accounts';
import Wallet from '../controller/wallet';
import U from '../util/helper';
import conf from '../src/config/config';
import C from '../src/controller/contract';
import A from '../src/secrets/accounts';
import Wallet from '../src/controller/wallet';
import U from '../src/util/helper';

var liqQueue={};

Expand Down
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"esModuleInterop": true,
"allowJs": true,
},
"include": ["./src/**/*"],
"exclude": ["./integration-tests/**/*"]
}