Skip to content

Commit d275b86

Browse files
authored
Merge pull request #22 from windingtree/develop
Deployment: Polygon zkEVM Testnet
2 parents 686a3c0 + f56a4fe commit d275b86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+12187
-1250
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ jobs:
2020
run: yarn install --frozen-lockfile
2121
- name: Lint
2222
run: yarn lint
23+
- name: Check contract sizes
24+
run: yarn hardhat size-contracts
2325
- name: Test
2426
run: yarn test:src && yarn test:contracts

README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1-
# contracts
1+
[![@windingtree/contracts](https://img.shields.io/npm/v/@windingtree/contracts)](https://www.npmjs.com/package/@windingtree/contracts)
2+
[![Beta Release](https://github.com/windingtree/contracts/actions/workflows/release.yml/badge.svg?branch=beta)](https://github.com/windingtree/contracts/actions/workflows/release.yml)
3+
4+
# @windingtree/contracts
25

36
The WindingTree market protocol smart contracts and utilities
7+
8+
## Deployments
9+
10+
### Polygon zkEVM
11+
12+
- Config ([0x098b1d12cAfE7315C77b6d308A62ce02806260Ee](https://explorer.public.zkevm-test.net/address/0x098b1d12cAfE7315C77b6d308A62ce02806260Ee/read-proxy#address-tabs)): the protocol configuration smart contract
13+
- EntitiesRegistry ([0x4bB51528C83844b509E1152EEb05260eE1bf60e6](https://explorer.public.zkevm-test.net/address/0x4bB51528C83844b509E1152EEb05260eE1bf60e6/read-proxy#address-tabs)): the protocol identity management
14+
- Market ([0xDd5B6ffB3585E109ECddec5293e31cdc1e9DeD57](https://explorer.public.zkevm-test.net/address/0xDd5B6ffB3585E109ECddec5293e31cdc1e9DeD57/read-proxy#address-tabs)): the protocol entry point
15+
- LIF ([0xba515AB7FfDa899a2e6c8FDbcDf351c8c15f4009](https://explorer.public.zkevm-test.net/address/0xba515AB7FfDa899a2e6c8FDbcDf351c8c15f4009/read-proxy#address-tabs)): Test version of LIF token
16+
17+
## Install package
18+
19+
```bash
20+
yarn add @windingtree/contracts
21+
```
22+
23+
## Setup
24+
25+
```bash
26+
yarn
27+
yarn build:contracts
28+
```
29+
30+
## Testing
31+
32+
```bash
33+
yarn test:contracts
34+
```
35+
36+
## Contributing
37+
38+
[Contribution guidelines](https://windingtree.github.io/sdk/#/docs/contribution)

contracts/Config.sol

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.19;
3+
4+
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
5+
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
6+
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
7+
import "./interfaces/IConfig.sol";
8+
9+
contract Config is IConfig, OwnableUpgradeable {
10+
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.Bytes32Set;
11+
using SafeMathUpgradeable for uint256;
12+
13+
EnumerableSetUpgradeable.Bytes32Set private _variables;
14+
15+
/// @dev Mapping of a named Id to uint256 number
16+
mapping(bytes32 => uint256) private numbers;
17+
18+
/// @dev Mapping of a named Id to address
19+
mapping(bytes32 => address) private addresses;
20+
21+
/// @dev Mapping of en entity type on minimum deposit value
22+
mapping(bytes32 => uint256) private minDeposits;
23+
24+
/// Events
25+
26+
/// @dev Emitted when a variable is created/updated
27+
event ConfigNumbers(bytes32 name, uint256 value);
28+
29+
/// @dev Emitted when a variable is created/updated
30+
event ConfigAddresses(bytes32 name, address value);
31+
32+
/// @dev Emitted when an entity minimum deposit set/updates
33+
event ConfigMinDeposit(bytes32 kind, uint256 value);
34+
35+
/// Errors
36+
37+
/// @dev Thrown when a user attempts to provide an invalid config property value
38+
error InvalidConfig();
39+
40+
/**
41+
* @dev Initializes Config contract
42+
* @param _asset The address of the asset used by the protocol in tokenomics
43+
* @param _claimPeriod The default time period, in seconds, allowed for the supplier to claim the deal.
44+
* @param _protocolFee Protocol's fee in percents
45+
* @param _retailerFee Retailer's fee in percents
46+
* @param _feeRecipient he recipient of the protocol fee
47+
* @param _kinds Supported entity types
48+
* @param _minDeposits Minimum value of deposit
49+
*/
50+
function initialize(
51+
address _owner,
52+
address _asset,
53+
uint256 _claimPeriod,
54+
uint256 _protocolFee,
55+
uint256 _retailerFee,
56+
address _feeRecipient,
57+
bytes32[] memory _kinds,
58+
uint256[] memory _minDeposits
59+
) external initializer {
60+
_transferOwnership(_owner);
61+
62+
// Save an asset address
63+
config("asset", _asset);
64+
65+
// The default time period, in seconds, allowed for the supplier to claim the deal.
66+
// The buyer is not able to cancel the deal during this period
67+
config("claim_period", _claimPeriod);
68+
69+
// The recipient of the protocol fee
70+
config("fee_recipient", _feeRecipient);
71+
72+
// In total, all the fees must not be greater than 100.
73+
// Of course, having 100% of the fees is absurd case.
74+
if (_protocolFee.add(_retailerFee) > 100) {
75+
revert InvalidConfig();
76+
}
77+
78+
// Protocol's fee in percents
79+
config("protocol_fee", _protocolFee);
80+
81+
// Retailer's fee in percents
82+
config("retailer_fee", _retailerFee);
83+
84+
// Save initial minimum deposits values
85+
_setMinDeposits(_kinds, _minDeposits);
86+
}
87+
88+
/// @inheritdoc IConfig
89+
function getNumber(bytes32 _name) public view returns (uint256) {
90+
return numbers[_name];
91+
}
92+
93+
/// @inheritdoc IConfig
94+
function getAddress(bytes32 _name) public view returns (address) {
95+
return addresses[_name];
96+
}
97+
98+
/// @inheritdoc IConfig
99+
function getMinDeposit(bytes32 _name) public view returns (uint256) {
100+
return minDeposits[_name];
101+
}
102+
103+
/// @inheritdoc IConfig
104+
function variables() external view returns (bytes32[] memory) {
105+
return _variables.values();
106+
}
107+
108+
/// @inheritdoc IConfig
109+
function config(bytes32 name, uint256 value) public onlyOwner {
110+
numbers[name] = value;
111+
_variables.add(name);
112+
emit ConfigNumbers(name, value);
113+
}
114+
115+
/// @inheritdoc IConfig
116+
function config(bytes32 name, address value) public onlyOwner {
117+
addresses[name] = value;
118+
_variables.add(name);
119+
emit ConfigAddresses(name, value);
120+
}
121+
122+
/// @inheritdoc IConfig
123+
function setMinDeposits(
124+
bytes32[] memory _kinds,
125+
uint256[] memory _minDeposits
126+
) external onlyOwner {
127+
_setMinDeposits(_kinds, _minDeposits);
128+
}
129+
130+
/// Internal functions
131+
132+
/// @dev See {IConfig.setMinDeposits}
133+
function _setMinDeposits(
134+
bytes32[] memory _kinds,
135+
uint256[] memory _minDeposits
136+
) internal {
137+
// Entity types number must be equal to minimum deposits values number
138+
if (_kinds.length != _minDeposits.length) {
139+
revert InvalidConfig();
140+
}
141+
142+
// Save minimum deposit values
143+
for (uint256 i = 0; i < _minDeposits.length; i++) {
144+
minDeposits[_kinds[i]] = _minDeposits[i];
145+
emit ConfigMinDeposit(_kinds[i], _minDeposits[i]);
146+
}
147+
}
148+
}

contracts/Configurable.sol

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)