Skip to content
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: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ jobs:
run: yarn install --frozen-lockfile
- name: Lint
run: yarn lint
- name: Check contract sizes
run: yarn hardhat size-contracts
- name: Test
run: yarn test:src && yarn test:contracts
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
# contracts
[![@windingtree/contracts](https://img.shields.io/npm/v/@windingtree/contracts)](https://www.npmjs.com/package/@windingtree/contracts)
[![Beta Release](https://github.com/windingtree/contracts/actions/workflows/release.yml/badge.svg?branch=beta)](https://github.com/windingtree/contracts/actions/workflows/release.yml)

# @windingtree/contracts

The WindingTree market protocol smart contracts and utilities

## Deployments

### Polygon zkEVM

- Config ([0x098b1d12cAfE7315C77b6d308A62ce02806260Ee](https://explorer.public.zkevm-test.net/address/0x098b1d12cAfE7315C77b6d308A62ce02806260Ee/read-proxy#address-tabs)): the protocol configuration smart contract
- EntitiesRegistry ([0x4bB51528C83844b509E1152EEb05260eE1bf60e6](https://explorer.public.zkevm-test.net/address/0x4bB51528C83844b509E1152EEb05260eE1bf60e6/read-proxy#address-tabs)): the protocol identity management
- Market ([0xDd5B6ffB3585E109ECddec5293e31cdc1e9DeD57](https://explorer.public.zkevm-test.net/address/0xDd5B6ffB3585E109ECddec5293e31cdc1e9DeD57/read-proxy#address-tabs)): the protocol entry point
- LIF ([0xba515AB7FfDa899a2e6c8FDbcDf351c8c15f4009](https://explorer.public.zkevm-test.net/address/0xba515AB7FfDa899a2e6c8FDbcDf351c8c15f4009/read-proxy#address-tabs)): Test version of LIF token

## Install package

```bash
yarn add @windingtree/contracts
```

## Setup

```bash
yarn
yarn build:contracts
```

## Testing

```bash
yarn test:contracts
```

## Contributing

[Contribution guidelines](https://windingtree.github.io/sdk/#/docs/contribution)
148 changes: 148 additions & 0 deletions contracts/Config.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
import "./interfaces/IConfig.sol";

contract Config is IConfig, OwnableUpgradeable {
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.Bytes32Set;
using SafeMathUpgradeable for uint256;

EnumerableSetUpgradeable.Bytes32Set private _variables;

/// @dev Mapping of a named Id to uint256 number
mapping(bytes32 => uint256) private numbers;

/// @dev Mapping of a named Id to address
mapping(bytes32 => address) private addresses;

/// @dev Mapping of en entity type on minimum deposit value
mapping(bytes32 => uint256) private minDeposits;

/// Events

/// @dev Emitted when a variable is created/updated
event ConfigNumbers(bytes32 name, uint256 value);

/// @dev Emitted when a variable is created/updated
event ConfigAddresses(bytes32 name, address value);

/// @dev Emitted when an entity minimum deposit set/updates
event ConfigMinDeposit(bytes32 kind, uint256 value);

/// Errors

/// @dev Thrown when a user attempts to provide an invalid config property value
error InvalidConfig();

/**
* @dev Initializes Config contract
* @param _asset The address of the asset used by the protocol in tokenomics
* @param _claimPeriod The default time period, in seconds, allowed for the supplier to claim the deal.
* @param _protocolFee Protocol's fee in percents
* @param _retailerFee Retailer's fee in percents
* @param _feeRecipient he recipient of the protocol fee
* @param _kinds Supported entity types
* @param _minDeposits Minimum value of deposit
*/
function initialize(
address _owner,
address _asset,
uint256 _claimPeriod,
uint256 _protocolFee,
uint256 _retailerFee,
address _feeRecipient,
bytes32[] memory _kinds,
uint256[] memory _minDeposits
) external initializer {
_transferOwnership(_owner);

// Save an asset address
config("asset", _asset);

// The default time period, in seconds, allowed for the supplier to claim the deal.
// The buyer is not able to cancel the deal during this period
config("claim_period", _claimPeriod);

// The recipient of the protocol fee
config("fee_recipient", _feeRecipient);

// In total, all the fees must not be greater than 100.
// Of course, having 100% of the fees is absurd case.
if (_protocolFee.add(_retailerFee) > 100) {
revert InvalidConfig();
}

// Protocol's fee in percents
config("protocol_fee", _protocolFee);

// Retailer's fee in percents
config("retailer_fee", _retailerFee);

// Save initial minimum deposits values
_setMinDeposits(_kinds, _minDeposits);
}

/// @inheritdoc IConfig
function getNumber(bytes32 _name) public view returns (uint256) {
return numbers[_name];
}

/// @inheritdoc IConfig
function getAddress(bytes32 _name) public view returns (address) {
return addresses[_name];
}

/// @inheritdoc IConfig
function getMinDeposit(bytes32 _name) public view returns (uint256) {
return minDeposits[_name];
}

/// @inheritdoc IConfig
function variables() external view returns (bytes32[] memory) {
return _variables.values();
}

/// @inheritdoc IConfig
function config(bytes32 name, uint256 value) public onlyOwner {
numbers[name] = value;
_variables.add(name);
emit ConfigNumbers(name, value);
}

/// @inheritdoc IConfig
function config(bytes32 name, address value) public onlyOwner {
addresses[name] = value;
_variables.add(name);
emit ConfigAddresses(name, value);
}

/// @inheritdoc IConfig
function setMinDeposits(
bytes32[] memory _kinds,
uint256[] memory _minDeposits
) external onlyOwner {
_setMinDeposits(_kinds, _minDeposits);
}

/// Internal functions

/// @dev See {IConfig.setMinDeposits}
function _setMinDeposits(
bytes32[] memory _kinds,
uint256[] memory _minDeposits
) internal {
// Entity types number must be equal to minimum deposits values number
if (_kinds.length != _minDeposits.length) {
revert InvalidConfig();
}

// Save minimum deposit values
for (uint256 i = 0; i < _minDeposits.length; i++) {
minDeposits[_kinds[i]] = _minDeposits[i];
emit ConfigMinDeposit(_kinds[i], _minDeposits[i]);
}
}
}
63 changes: 0 additions & 63 deletions contracts/Configurable.sol

This file was deleted.

Loading