Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PricerRule integration test and cleanup #114

Merged
merged 20 commits into from
Feb 25, 2019
Merged
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: 1 addition & 1 deletion contracts/bin/DelayedRecoveryModule.bin

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/bin/PricerRule.bin

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/bin/ProxyFactory.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x608060405234801561001057600080fd5b5061048e806100206000396000f3fe6080604052600436106100405763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166361b69abd8114610045575b600080fd5b34801561005157600080fd5b506101156004803603604081101561006857600080fd5b73ffffffffffffffffffffffffffffffffffffffff82351691908101906040810160208201356401000000008111156100a057600080fd5b8201836020820111156100b257600080fd5b803590602001918460018302840111640100000000831117156100d457600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061013e945050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b600073ffffffffffffffffffffffffffffffffffffffff831615156101c457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f4d617374657220636f70792061646472657373206973206e756c6c2e00000000604482015290519081900360640190fd5b826101cd61027d565b73ffffffffffffffffffffffffffffffffffffffff909116815260405190819003602001906000f080158015610207573d6000803e3d6000fd5b50905060008251111561022f5760008060008451602086016000865af1141561022f57600080fd5b6040805173ffffffffffffffffffffffffffffffffffffffff8316815290517efffc2da0b561cae30d9826d37709e9421c4725faebc226cbbb7ef5fc5e73499181900360200190a192915050565b6040516101d58061028e8339019056fe608060405234801561001057600080fd5b506040516020806101d58339810180604052602081101561003057600080fd5b5051600160a060020a03811615156100a957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f4d617374657220636f70792061646472657373206973206e756c6c2e00000000604482015290519081900360640190fd5b60008054600160a060020a03909216600160a060020a031990921691909117905560fd806100d86000396000f3fe608060405260043610603e5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663a619486e8114607a575b73ffffffffffffffffffffffffffffffffffffffff600054163660008037600080366000845af43d6000803e8015156075573d6000fd5b3d6000f35b348015608557600080fd5b50608c60b5565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b60005473ffffffffffffffffffffffffffffffffffffffff168156fea165627a7a72305820eb990995fbf08f8cf0abe217a80dc901bb5b96fcdac0cc3d3239573815798cdc0029a165627a7a7230582093d04a3929e3148a667e1bf9e8c19fc4cbf697ef8f628b3e2c386b5dae55b1de0029
0x608060405234801561001057600080fd5b5061048e806100206000396000f3fe6080604052600436106100405763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166361b69abd8114610045575b600080fd5b34801561005157600080fd5b506101156004803603604081101561006857600080fd5b73ffffffffffffffffffffffffffffffffffffffff82351691908101906040810160208201356401000000008111156100a057600080fd5b8201836020820111156100b257600080fd5b803590602001918460018302840111640100000000831117156100d457600080fd5b91908080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525092955061013e945050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b600073ffffffffffffffffffffffffffffffffffffffff831615156101c457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f4d617374657220636f70792061646472657373206973206e756c6c2e00000000604482015290519081900360640190fd5b826101cd61027d565b73ffffffffffffffffffffffffffffffffffffffff909116815260405190819003602001906000f080158015610207573d6000803e3d6000fd5b50905060008251111561022f5760008060008451602086016000865af1141561022f57600080fd5b6040805173ffffffffffffffffffffffffffffffffffffffff8316815290517efffc2da0b561cae30d9826d37709e9421c4725faebc226cbbb7ef5fc5e73499181900360200190a192915050565b6040516101d58061028e8339019056fe608060405234801561001057600080fd5b506040516020806101d58339810180604052602081101561003057600080fd5b5051600160a060020a03811615156100a957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f4d617374657220636f70792061646472657373206973206e756c6c2e00000000604482015290519081900360640190fd5b60008054600160a060020a03909216600160a060020a031990921691909117905560fd806100d86000396000f3fe608060405260043610603e5763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663a619486e8114607a575b73ffffffffffffffffffffffffffffffffffffffff600054163660008037600080366000845af43d6000803e8015156075573d6000fd5b3d6000f35b348015608557600080fd5b50608c60b5565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b60005473ffffffffffffffffffffffffffffffffffffffff168156fea165627a7a72305820eb990995fbf08f8cf0abe217a80dc901bb5b96fcdac0cc3d3239573815798cdc0029a165627a7a72305820a2b3a9ec1600033900a730b23095a01a2ff7ca3f834ef1a1bc881ff1ed8800080029
2 changes: 1 addition & 1 deletion contracts/bin/TokenHolder.bin

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/bin/TokenRules.bin

Large diffs are not rendered by default.

30 changes: 0 additions & 30 deletions contracts/generateAbiBins.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ if (process.argv.length > 2) {
contractsRepoPath = process.argv[2];
}

console.log(`Looking for truffle compile output in path ${contractsRepoPath}`);

let metadata = {
abi: {
generated: [],
Expand Down Expand Up @@ -58,59 +56,31 @@ fs.readdir(contractsRepoPath, function(err, items) {
continue;
}

console.log(`Processing ${fileName}`);

let jsonFilePath = path.join(contractsRepoPath, fileName);
console.log(`jsonFilePath ${jsonFilePath}`);
let json = require(jsonFilePath);

//Generate Abi files
if (json.abi && json.abi.length) {
console.log('--- Generating abi file');
//Write to file.
let fileContent = JSON.stringify(json.abi);
let outputFile = path.join(abiOutputPath, contractName + '.abi');
fs.writeFileSync(outputFile, fileContent);
//Update Metadata
metadata.abi.generated.push(contractName);
} else {
console.log('--- abi file not generated');
metadata.abi.ignored.push(contractName);
}

//Generate Bin files
if (json.bytecode && json.bytecode.length && json.bytecode != '0x') {
console.log('--- Generating bin file');
//Write to file.
let fileContent = json.bytecode;
let outputFile = path.join(binOutputPath, contractName + '.bin');
fs.writeFileSync(outputFile, fileContent);
//Update Metadata
metadata.bin.generated.push(contractName);
} else {
console.log('--- bin file not generated');
metadata.bin.ignored.push(contractName);
}
}

console.log('------ Task Completed ------');
console.log('Total truffle Artifacts:', metadata.total);
console.log(
'Abi File generated for',
metadata.abi.generated.length,
'contracts. Artifacts can be found here: ',
abiOutputPath
);
console.log(
'Bin generated for',
metadata.bin.generated.length,
'contracts. Artifacts can be found here: ',
binOutputPath
);
if (metadata.abi.ignored.length) {
console.log('Abi generation ignored for \n\t', metadata.abi.ignored.join('\n\t '));
}
if (metadata.bin.ignored.length) {
console.log('Bin generation ignored for \n\t', metadata.bin.ignored.join('\n\t '));
}
});
68 changes: 66 additions & 2 deletions lib/Contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,70 @@ class OpenSTContracts extends Contracts {
return contractInstance;
}

/**
* Static method which returns TokenRules contract instance.
*
* @param auxiliaryWeb3 Origin chain web3 object.
* @param address TokenRules contract address.
* @param options Tx options.
* @returns {web3.eth.Contract} Contract instance.
* @constructor
*/
static getTokenRules(auxiliaryWeb3, address, options) {
const oThis = this;
const jsonInterface = abiBinProvider.getABI('TokenRules');
const contract = new auxiliaryWeb3.eth.Contract(jsonInterface, address, options);
return contract;
}

/**
* Static method which returns PricerRule contract instance.
*
* @param auxiliaryWeb3 Origin chain web3 object.
* @param address PricerRule contract instance.
* @param options Tx options.
* @returns {web3.eth.Contract} Contract instance.
* @constructor
*/
static getPricerRule(auxiliaryWeb3, address, options) {
const oThis = this;
const jsonInterface = abiBinProvider.getABI('PricerRule');
const contract = new auxiliaryWeb3.eth.Contract(jsonInterface, address, options);
return contract;
}

/**
* Static method which returns TokenHolder contract instance.
*
* @param auxiliaryWeb3 Auxiliary chain web3 object.
* @param address TokenHolder contract address.
* @param options Tx options.
* @returns {web3.eth.Contract} Contract instance.
* @constructor
*/
static getTokenHolder(auxiliaryWeb3, address, options) {
const oThis = this;
const jsonInterface = abiBinProvider.getABI('TokenHolder');
const contract = new auxiliaryWeb3.eth.Contract(jsonInterface, address, options);
return contract;
}

/**
* Static method which returns GnosisSafe contract instance.
*
* @param auxiliaryWeb3 Auxiliary chain web3 object.
* @param address GnosisSafe contract address.
* @param options Tx options.
* @returns {web3.eth.Contract} Contract instance.
* @constructor
*/
static getGnosisSafe(auxiliaryWeb3, address, options) {
const oThis = this;
const jsonInterface = abiBinProvider.getABI('GnosisSafe');
const contract = new auxiliaryWeb3.eth.Contract(jsonInterface, address, options);
return contract;
}

/**
* Static method which returns delayed recovery module instance.
*
Expand All @@ -94,9 +158,9 @@ class OpenSTContracts extends Contracts {
* @returns {auxiliaryWeb3Object.eth.Contract}
*/
static getDelayedRecovery(auxiliaryWeb3, address, options) {
const auxiliaryWeb3Object = Contracts._getWeb3(auxiliaryWeb3);
const oThis = this;
const jsonInterface = abiBinProvider.getABI('DelayedRecoveryModule');
const contractInstance = new auxiliaryWeb3Object.eth.Contract(jsonInterface, address, options);
const contractInstance = new auxiliaryWeb3.eth.Contract(jsonInterface, address, options);
return contractInstance;
}

Expand Down
22 changes: 22 additions & 0 deletions lib/helper/rules/PricerRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const AbiBinProvider = require('./../../AbiBinProvider'),

const Utils = require('../../../utils/Utils');

const BN = require('bn.js');

/**
* Helper class which provides interaction methods of PricerRule contract.
*/
Expand Down Expand Up @@ -110,6 +112,26 @@ class PricerRule {
return payExecutableData;
}

/**
* Converts PayCurrencyCode amount to BT amount.
*
* @param amountInWei Amount which is being transferred.
* @param priceInWei Price set in PriceOracle contract.
* @param conversionRate OST to BT conversion rate.
* @param conversionRateDecimals OST to BT conversion rate decimals.
*
* @returns {BigNumber} Converted BT amount.
*/
static convertPayCurrencyToToken(amountInWei, priceInWei, conversionRate, conversionRateDecimals) {
const conversionRateDecimalsBN = new BN(10).pow(new BN(conversionRateDecimals));
const amountBN = new BN(amountInWei);
const priceBN = new BN(priceInWei);
return amountBN
.mul(new BN(conversionRate))
.div(priceBN)
.div(conversionRateDecimalsBN);
}

/**
* Adds a new price oracle.
*
Expand Down
Loading