Skip to content

Commit b696869

Browse files
authored
Merge pull request #303 from dev-protocol/supports-arbitrary-tokens
Supports arbitrary tokens for MembersCollections/TimeCollections
2 parents bcf6500 + f93af6c commit b696869

File tree

5 files changed

+966
-99
lines changed

5 files changed

+966
-99
lines changed

contracts/MembersCollection.sol

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "@devprotocol/i-s-tokens/contracts/interfaces/ITokenURIDescriptor.sol";
55
import "@devprotocol/i-s-tokens/contracts/interfaces/ISTokensManagerStruct.sol";
66
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
77
import "./interfaces/IProperty.sol";
8-
import "./interfaces/ISwapAndStake.sol";
8+
import "./interfaces/IDynamicTokenSwapAndStake.sol";
99

1010
contract MembersCollections is ITokenURIDescriptor, OwnableUpgradeable {
1111
struct Image {
@@ -14,20 +14,21 @@ contract MembersCollections is ITokenURIDescriptor, OwnableUpgradeable {
1414
string description;
1515
// number of slots a image can have
1616
uint32 slots;
17-
uint256 requiredETHAmount;
18-
uint256 requiredETHFee;
17+
uint256 requiredTokenAmount;
18+
uint256 requiredTokenFee;
19+
address token;
1920
address gateway;
2021
}
2122

22-
ISwapAndStake public swapAndStake;
23+
IDynamicTokenSwapAndStake public swapAndStake;
2324
mapping(address => mapping(bytes32 => Image)) public propertyImages;
2425
mapping(address => mapping(uint256 => uint256)) public stakedAmountAtMinted;
2526
mapping(address => mapping(bytes32 => uint32))
2627
public propertyImageClaimedSlots;
2728

2829
function initialize(address _contract) external initializer {
2930
__Ownable_init();
30-
swapAndStake = ISwapAndStake(_contract);
31+
swapAndStake = IDynamicTokenSwapAndStake(_contract);
3132
}
3233

3334
modifier onlyPropertyAuthor(address _property) {
@@ -37,7 +38,7 @@ contract MembersCollections is ITokenURIDescriptor, OwnableUpgradeable {
3738
}
3839

3940
function setSwapAndStake(address _contract) external onlyOwner {
40-
swapAndStake = ISwapAndStake(_contract);
41+
swapAndStake = IDynamicTokenSwapAndStake(_contract);
4142
}
4243

4344
function image(
@@ -115,8 +116,8 @@ contract MembersCollections is ITokenURIDescriptor, OwnableUpgradeable {
115116
// When key, slots are not defined or 0 slots
116117
if (
117118
bytes(img.src).length == 0 &&
118-
img.requiredETHAmount == 0 &&
119-
img.requiredETHFee == 0 &&
119+
img.requiredTokenAmount == 0 &&
120+
img.requiredTokenFee == 0 &&
120121
img.slots == 0
121122
) {
122123
return false;
@@ -127,13 +128,13 @@ contract MembersCollections is ITokenURIDescriptor, OwnableUpgradeable {
127128
}
128129

129130
// Always only allow staking via the SwapAndStake contract.
130-
ISwapAndStake.Amounts memory stakeVia = swapAndStake.gatewayOf(
131-
img.gateway
132-
);
131+
IDynamicTokenSwapAndStake.Amounts memory stakeVia = swapAndStake
132+
.gatewayOf(img.gateway);
133133

134134
// Validate the staking position.
135-
bool valid = img.requiredETHAmount <= stakeVia.input &&
136-
img.requiredETHFee <= stakeVia.fee;
135+
bool valid = img.requiredTokenAmount <= stakeVia.input &&
136+
img.requiredTokenFee <= stakeVia.fee &&
137+
img.token == stakeVia.token;
137138

138139
if (valid) {
139140
stakedAmountAtMinted[_positions.property][id] = _positions.amount;

contracts/TimeCollection.sol

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@ import "@devprotocol/i-s-tokens/contracts/interfaces/ITokenURIDescriptor.sol";
55
import "@devprotocol/i-s-tokens/contracts/interfaces/ISTokensManagerStruct.sol";
66
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
77
import "./interfaces/IProperty.sol";
8-
import "./interfaces/ISwapAndStake.sol";
8+
import "./interfaces/IDynamicTokenSwapAndStake.sol";
99

1010
contract TimeCollections is ITokenURIDescriptor, OwnableUpgradeable {
1111
struct Image {
1212
string src;
1313
string name;
1414
string description;
1515
uint256 deadline;
16-
uint256 requiredETHAmount;
17-
uint256 requiredETHFee;
16+
uint256 requiredTokenAmount;
17+
uint256 requiredTokenFee;
18+
address token;
1819
address gateway;
1920
}
2021

21-
ISwapAndStake public swapAndStake;
22+
IDynamicTokenSwapAndStake public swapAndStake;
2223
mapping(address => mapping(bytes32 => Image)) public propertyImages;
2324
mapping(address => mapping(uint256 => uint256)) public stakedAmountAtMinted;
2425

2526
function initialize(address _contract) external initializer {
2627
__Ownable_init();
27-
swapAndStake = ISwapAndStake(_contract);
28+
swapAndStake = IDynamicTokenSwapAndStake(_contract);
2829
}
2930

3031
modifier onlyPropertyAuthor(address _property) {
@@ -34,7 +35,7 @@ contract TimeCollections is ITokenURIDescriptor, OwnableUpgradeable {
3435
}
3536

3637
function setSwapAndStake(address _contract) external onlyOwner {
37-
swapAndStake = ISwapAndStake(_contract);
38+
swapAndStake = IDynamicTokenSwapAndStake(_contract);
3839
}
3940

4041
function image(
@@ -113,8 +114,8 @@ contract TimeCollections is ITokenURIDescriptor, OwnableUpgradeable {
113114
if (
114115
bytes(img.src).length == 0 &&
115116
img.deadline == 0 &&
116-
img.requiredETHAmount == 0 &&
117-
img.requiredETHFee == 0
117+
img.requiredTokenAmount == 0 &&
118+
img.requiredTokenFee == 0
118119
) {
119120
return false;
120121
}
@@ -123,13 +124,13 @@ contract TimeCollections is ITokenURIDescriptor, OwnableUpgradeable {
123124
return false;
124125
}
125126
// Always only allow staking via the SwapAndStake contract.
126-
ISwapAndStake.Amounts memory stakeVia = swapAndStake.gatewayOf(
127-
img.gateway
128-
);
127+
IDynamicTokenSwapAndStake.Amounts memory stakeVia = swapAndStake
128+
.gatewayOf(img.gateway);
129129

130130
// Validate the staking position.
131-
bool valid = img.requiredETHAmount <= stakeVia.input &&
132-
img.requiredETHFee <= stakeVia.fee;
131+
bool valid = img.requiredTokenAmount <= stakeVia.input &&
132+
img.requiredTokenFee <= stakeVia.fee &&
133+
img.token == stakeVia.token;
133134

134135
if (valid) {
135136
stakedAmountAtMinted[_positions.property][id] = _positions.amount;

contracts/interfaces/IDynamicTokenSwapAndStake.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ pragma solidity 0.8.9;
44

55
interface IDynamicTokenSwapAndStake {
66
struct Amounts {
7+
address token;
78
uint256 input;
89
uint256 fee;
9-
address token;
1010
}
1111

1212
function gatewayOf(address _addr) external view returns (Amounts memory);

0 commit comments

Comments
 (0)