Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
HristiyanG committed Jul 5, 2021
2 parents 71e3bad + 7da5b1c commit f15eb19
Show file tree
Hide file tree
Showing 33 changed files with 5,605 additions and 6,617 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"ecmaVersion": 2020
},
"plugins": [
// "truffle"
"@typescript-eslint"
],
"rules": {
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ node_modules
coverage*

# Personal Preferences
.vscode
.vscode
*.txt
60 changes: 49 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ the latest deployment details here, as well.
For more details about how Boson Protocol works and how you might make use of
it, please see the [documentation site](https://docs.bosonprotocol.io/).

---
**Table of Contents**

- [Local Development](#local-development)
- [Testing](#testing)
- [Code Linting](#code-linting)
- [Documentation](#documentation)
- [Prerequisites](#prerequisites)
- [Build](#build)
- [Run](#run)
- [Test](#test)
- [Code Linting & Formatting](#code-linting--formatting)
- [Documentation](#documentation)
- [Contributing](#contributing)
- [License](#license)

---
## Local Development

### Prerequisites
Expand All @@ -43,17 +48,20 @@ For instructions on how to get set up with these specific versions:
* See the [OS X guide](docs/setup/osx.md) if you are on a Mac.
* See the [Linux guide](docs/setup/linux.md) if you use a Linux distribution.

### Running the build
---
### Build

We have a fully automated local build process to check that your changes are
good to be merged. To run the build:
good to be merged. It is based on a script called `go`, which is implemented using Ruby and Rake. Always run the `go` script before committing or pushing to GitHub.
To run the build:

```shell script
./go
````

By default, the build process fetches all dependencies, compiles, lints,
formats and tests the codebase. There are also tasks for each step. This and
formats and tests the codebase. If the linting or formatting tasks find problems, the script will attempt to fix them silently, so always check for changes in your files before committing or pushing to GitHub.
There are also tasks for each step that can be run separately. This and
subsequent sections provide more details of each of the tasks.

To fetch dependencies:
Expand All @@ -68,9 +76,35 @@ To compile the contracts:
./go contracts:compile
```

## Testing
---
### Run
To deploy instances of the contracts for local development without prior knowledge Ganache and Truffle, run the following command:
```shell
./go contracts:run
```

This command starts up Ganache on a random port and migrates all contracts to the Ganache instance. The Ganache instance will remain running in the background, even though the command prompt returns.
The pid of the Ganache instance is written to a file in the run/pid directory.

To stop the Ganache instance, run the following command:
```shell
./go ganache:stop
```

If preferred by those who are familiar with Truffle and Ganache, the standard Truffle and Ganache commands can be used. Ganache can be started up manually in a terminal using the command:
```shell
node ./node_modules/.bin/ganache-cli --port 8545 --allowUnlimitedContractSize --acctKeys build/ganache/accounts-8545.json
```
In a separate terminal, contracts can be deployed using
```shell
./node_modules/.bin/truffle migrate
```
One of the contracts that gets deployed locally is a mock contract that represents the $BOSON token. The mock exists for unit testing purposes and so that those who want to develop against the protocol locally don't have to point to a testnet deployment of the $BOSON token.
---
### Test
### Unit Tests
#### Unit Tests
All contracts are thoroughly unit tested using
[Truffle's JavaScript testing](https://www.trufflesuite.com/docs/truffle/testing/writing-tests-in-javascript)
Expand All @@ -94,7 +128,7 @@ otherwise, create a JSON file creating accounts in the same format as
./go "tests:unit[<port>,<path-to-accounts-json>]"
```

### Coverage
#### Coverage

We use [solidity-coverage](https://github.com/sc-forks/solidity-coverage) to
provide test coverage reports.
Expand All @@ -108,12 +142,13 @@ To check the test coverage:
`solidity-coverage` runs its own instance of Ganache internally, as well as
instrumenting contracts before running.

### Interaction Tests
#### Interaction Tests

To run the interaction tests, follow the instructions in the
[interaction tests README.md](testUserInteractions/README.md).

## Code Linting
---
### Code Linting & Formatting

Both the contracts themselves and the tests are linted and formatted as part of
the build process.
Expand Down Expand Up @@ -161,12 +196,14 @@ Similarly, for the tests, to perform the same tasks:
./go tests:format_fix
```

---
## Documentation

For an overview of the contracts and their responsibilities, see
[Overview](docs/contracts/overview.md).
The whitepaper is available through the project's [website](https://www.bosonprotocol.io/).
---
## Contributing
We welcome contributions! Until now, Boson Protocol has been largely worked on by a small dedicated team. However, the ultimate goal is for all of the Boson Protocol repositories to be fully owned by the community and contributors. Issues, pull requests, suggestions, and any sort of involvement are more than welcome.
Expand All @@ -179,6 +216,7 @@ All PRs must pass all tests before being merged.
By being in this community, you agree to the [Code of Conduct](CODE_OF_CONDUCT.md). Take a look at it, if you haven't already.

---
## License

Licensed under [LGPL v3](LICENSE).
41 changes: 25 additions & 16 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ namespace :dependencies do
end

namespace :contracts do
desc "Run all contracts (must be manually stopped)"
task :run, [:port, :account_keys_file] =>
[:'ganache:start'] do |_, args|
Ganache.on_available_port(
allow_unlimited_contract_size: true) do |ganache|
sh({
"HOST" => "127.0.0.1",
"PORT" => "#{ganache.port}",
"ACCOUNT_KEYS_FILE" => "#{ganache.account_keys_file}"
}, 'npm', 'run', 'contracts:run')
end
end

desc "Compile all contracts"
task :compile => [:'dependencies:install'] do
sh('npm', 'run', 'contracts:compile')
Expand Down Expand Up @@ -119,26 +132,22 @@ namespace :tests do
desc "Run all contract unit tests"
task :unit, [:port, :account_keys_file] =>
[:'dependencies:install'] do |_, args|
run_unit_tests = lambda do |port, account_keys_file|
sh({
"HOST" => "127.0.0.1",
"PORT" => "#{port}",
"ACCOUNT_KEYS_FILE" => "#{account_keys_file}"
}, 'npm', 'run', 'tests:unit')
run_unit_tests = lambda do ||
sh({}, 'npm', 'run', 'tests:unit')

# run_unit_tests.call()
end

if args.port
puts "Running unit tests against node listening on #{args.port}..."
run_unit_tests.call(
args.port,
args.account_keys_file || 'config/accounts.json')
# puts "Running unit tests against node listening on #{args.port}..."
run_unit_tests.call()
else
puts "Running unit tests against node listening on random available " +
"port..."
Ganache.on_available_port(
allow_unlimited_contract_size: true) do |ganache|
run_unit_tests.call(ganache.port, ganache.account_keys_file)
end
# puts "Running unit tests against node listening on random available " +
# "port..."
# Ganache.on_available_port(
# allow_unlimited_contract_size: true) do |ganache|
run_unit_tests.call()
# end
end
end

Expand Down
65 changes: 57 additions & 8 deletions contracts/BosonRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ contract BosonRouter is
using Address for address payable;
using SafeMath for uint256;

mapping(address => uint256) public correlationIds; // whenever a seller or a buyer interacts with the smart contract, a personal txID is emitted from an event.
mapping(address => uint256) private correlationIds; // whenever a seller or a buyer interacts with the smart contract, a personal txID is emitted from an event.

using SafeMath for uint256;

address public cashierAddress;
address public voucherKernel;
address public fundLimitsOracle;
address private cashierAddress;
address private voucherKernel;
address private fundLimitsOracle;

event LogOrderCreated(
uint256 indexed _tokenIdSupply,
Expand Down Expand Up @@ -692,10 +692,6 @@ contract BosonRouter is
);
}

// // // // // // // //
// UTILS
// // // // // // // //

/**
* @notice Increment a seller or buyer's correlation Id
* @param _party The address of the seller or buyer
Expand All @@ -706,4 +702,57 @@ contract BosonRouter is
{
correlationIds[_party]++;
}

/**
* @notice Return a seller or buyer's correlation Id
* @param _party The address of the seller or buyer
* @return the specified party's correlation Id
*/
function getCorrelationId(address _party)
external
override
view
returns (uint256)
{
return correlationIds[_party];
}

/**
* @notice Get the address of Cashier contract
* @return Address of Cashier address
*/
function getCashierAddress()
external
view
override
returns (address)
{
return cashierAddress;
}

/**
* @notice Get the address of Voucher Kernel contract
* @return Address of Voucher Kernel contract
*/
function getVoucherKernelAddress()
external
view
override
returns (address)
{
return voucherKernel;
}

/**
* @notice Get the address of Fund Limits Oracle contract
* @return Address of Fund Limits Oracle contract
*/
function getFundLimitOracleAddress()
external
view
override
returns (address)
{
return fundLimitsOracle;
}
}
62 changes: 55 additions & 7 deletions contracts/Cashier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ contract Cashier is ICashier, UsingHelpers, ReentrancyGuard, Ownable, Pausable {
using Address for address payable;
using SafeMath for uint256;

address public voucherKernel;
address public bosonRouterAddress;
address public tokensContractAddress;
bool public disasterState;
address private voucherKernel;
address private bosonRouterAddress;
address private tokensContractAddress;
bool private disasterState;

enum PaymentType {PAYMENT, DEPOSIT_SELLER, DEPOSIT_BUYER}

mapping(address => uint256) public escrow; // both types of deposits AND payments >> can be released token-by-token if checks pass
mapping(address => uint256) private escrow; // both types of deposits AND payments >> can be released token-by-token if checks pass
// slashedDepositPool can be obtained through getEscrowAmount(poolAddress)
mapping(address => mapping(address => uint256)) public escrowTokens; //token address => mgsSender => amount
mapping(address => mapping(address => uint256)) private escrowTokens; //token address => mgsSender => amount

uint256 internal constant CANCELFAULT_SPLIT = 2; //for POC purposes, this is hardcoded; e.g. each party gets depositSe / 2

Expand Down Expand Up @@ -178,7 +178,8 @@ contract Cashier is ICashier, UsingHelpers, ReentrancyGuard, Ownable, Pausable {
(
voucherDetails.currStatus.status,
voucherDetails.currStatus.isPaymentReleased,
voucherDetails.currStatus.isDepositsReleased
voucherDetails.currStatus.isDepositsReleased,
,
) = IVoucherKernel(voucherKernel).getVoucherStatus(
voucherDetails.tokenIdVoucher
);
Expand Down Expand Up @@ -1049,6 +1050,53 @@ contract Cashier is ICashier, UsingHelpers, ReentrancyGuard, Ownable, Pausable {
// GETTERS
// // // // // // // //

/**
* @notice Get the address of Voucher Kernel contract
* @return Address of Voucher Kernel contract
*/
function getVoucherKernelAddress()
external
view
override
returns (address)
{
return voucherKernel;
}

/**
* @notice Get the address of Boson Router contract
* @return Address of Boson Router contract
*/
function getBosonRouterAddress()
external
view
override
returns (address)
{
return bosonRouterAddress;
}

/**
* @notice Get the address of ERC1155ERC721 contract
* @return Address of ERC1155ERC721 contract
*/
function getTokensContractAddress()
external
view
override
returns (address)
{
return tokensContractAddress;
}

/**
* @notice Ensure whether or not contract has been set to disaster state
* @return disasterState
*/
function isDisasterStateSet() external view override returns(bool) {
return disasterState;
}

/**
* @notice Get the amount in escrow of an address
* @param _account The address of an account to query
Expand Down
Loading

0 comments on commit f15eb19

Please sign in to comment.