Skip to content

Commit 04d4798

Browse files
authored
Merge pull request #1225 from dev-protocol/stokens-upgrade
Add a new option `bytes32 _payload` for the staking function
2 parents 671c838 + 264db91 commit 04d4798

File tree

7 files changed

+67
-19
lines changed

7 files changed

+67
-19
lines changed

.eslintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
"globals": {
3737
"artifacts": "readonly",
3838
"Truffle": "readonly"
39+
},
40+
"rules": {
41+
"@typescript-eslint/ban-ts-comment": "off",
42+
"@typescript-eslint/prefer-ts-expect-error": "off"
3943
}
4044
}
4145
]

contracts/interface/ILockup.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ interface ILockup {
66
external
77
returns (uint256);
88

9+
function depositToProperty(
10+
address _property,
11+
uint256 _amount,
12+
bytes32 _data
13+
) external returns (uint256);
14+
915
function depositToPosition(uint256 _tokenId, uint256 _amount)
1016
external
1117
returns (bool);

contracts/src/lockup/Lockup.sol

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,31 @@ contract Lockup is ILockup, UsingConfig, LockupStorage {
102102
*/
103103
function depositToProperty(address _property, uint256 _amount)
104104
external
105-
onlyAuthenticatedProperty(_property)
106105
returns (uint256)
107106
{
108-
/**
109-
* Validates _amount is not 0.
110-
*/
111-
require(_amount != 0, "illegal deposit amount");
107+
return _implDepositToProperty(_property, _amount, "");
108+
}
109+
110+
/**
111+
* @dev deposit dev token to dev protocol and generate s-token
112+
* @param _property target property address
113+
* @param _amount staking value
114+
* @param _payload additional bytes for s-token
115+
* @return tokenId The ID of the created new staking position
116+
*/
117+
function depositToProperty(
118+
address _property,
119+
uint256 _amount,
120+
bytes32 _payload
121+
) external returns (uint256) {
122+
return _implDepositToProperty(_property, _amount, _payload);
123+
}
124+
125+
function _implDepositToProperty(
126+
address _property,
127+
uint256 _amount,
128+
bytes32 _payload
129+
) private onlyAuthenticatedProperty(_property) returns (uint256) {
112130
/**
113131
* Gets the latest cumulative sum of the interest price.
114132
*/
@@ -145,7 +163,8 @@ contract Lockup is ILockup, UsingConfig, LockupStorage {
145163
msg.sender,
146164
_property,
147165
_amount,
148-
interest
166+
interest,
167+
_payload
149168
);
150169
emit Lockedup(msg.sender, _property, _amount);
151170
return tokenId;
@@ -1212,7 +1231,8 @@ contract Lockup is ILockup, UsingConfig, LockupStorage {
12121231
msg.sender,
12131232
_property,
12141233
amount,
1215-
price
1234+
price,
1235+
""
12161236
);
12171237
/**
12181238
* update position information

contracts/test/token/STokenManagerTest.sol

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ contract STokensManagerTest is ERC721 {
1313
address public config;
1414
uint256 public latestTokenId;
1515
mapping(bytes32 => bytes) private bytesStorage;
16+
mapping(uint256 => bytes32) private payloadStorage;
1617

1718
struct StakingPositionV1 {
1819
address property;
@@ -42,7 +43,8 @@ contract STokensManagerTest is ERC721 {
4243
address _owner,
4344
address _property,
4445
uint256 _amount,
45-
uint256 _price
46+
uint256 _price,
47+
bytes32 _payload
4648
) external onlyLockup returns (uint256 tokenId_) {
4749
_tokenIds.increment();
4850
uint256 newTokenId = _tokenIds.current();
@@ -56,9 +58,14 @@ contract STokensManagerTest is ERC721 {
5658
);
5759
setStoragePositionsV1(newTokenId, newPosition);
5860
latestTokenId = newTokenId;
61+
payloadStorage[newTokenId] = _payload;
5962
return newTokenId;
6063
}
6164

65+
function payloadOf(uint256 _tokenId) external view returns (bytes32) {
66+
return payloadStorage[_tokenId];
67+
}
68+
6269
function update(
6370
uint256 _tokenId,
6471
uint256 _amount,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"web3": "1.7.4"
5555
},
5656
"dependencies": {
57-
"@devprotocol/i-s-tokens": "1.8.0",
57+
"@devprotocol/i-s-tokens": "2.0.0",
5858
"@openzeppelin/contracts": "2.5.1"
5959
},
6060
"directories": {

test/lockup/lockup-s-token.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ contract('LockupTest', ([deployer, , user2, user3]) => {
9292
expect(position[3].toNumber()).to.be.equal(0)
9393
expect(position[4].toNumber()).to.be.equal(0)
9494
})
95+
it('pass the 3rd option', async () => {
96+
await dev.dev.approve(dev.lockup.address, 100)
97+
// @ts-ignore
98+
await dev.lockup.depositToProperty(
99+
property.address,
100+
100,
101+
web3.utils.keccak256('ADDITIONAL_BYTES')
102+
)
103+
104+
const payload = await dev.sTokenManager.payloadOf(1)
105+
expect(payload).to.be.equal(web3.utils.keccak256('ADDITIONAL_BYTES'))
106+
})
107+
it('0 dev staking', async () => {
108+
await dev.lockup.depositToProperty(property.address, 0)
109+
const position = await dev.sTokenManager.positions(1)
110+
expect(toBigNumber(position[1]).toNumber()).to.be.equal(0)
111+
})
95112
it('generate event.', async () => {
96113
await dev.dev.approve(dev.lockup.address, 100)
97114
dev.lockup.depositToProperty(property.address, 100)
@@ -143,12 +160,6 @@ contract('LockupTest', ([deployer, , user2, user3]) => {
143160
.catch(err)
144161
validateErrorMessage(res, 'unable to stake to unauthenticated property')
145162
})
146-
it('0 dev staking is not possible.', async () => {
147-
const res = await dev.lockup
148-
.depositToProperty(property.address, 0)
149-
.catch(err)
150-
validateErrorMessage(res, 'illegal deposit amount')
151-
})
152163
it('user is not holding dev.', async () => {
153164
const res = await dev.lockup
154165
.depositToProperty(property.address, 100, { from: user3 })

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@
142142
dependencies:
143143
"@jridgewell/trace-mapping" "0.3.9"
144144

145-
"@devprotocol/i-s-tokens@1.8.0":
146-
version "1.8.0"
147-
resolved "https://registry.yarnpkg.com/@devprotocol/i-s-tokens/-/i-s-tokens-1.8.0.tgz#cdad0c794c235b1091e668e6810cf6919d67318c"
148-
integrity sha512-W5uL5DTM8bvseX0Pfm1iFMT4e/0e11cmGnM6QW9tppirgHJBnsvT44wK62v+Q7FRxmupk8KAQQbQV3Ob967Kug==
145+
"@devprotocol/i-s-tokens@2.0.0":
146+
version "2.0.0"
147+
resolved "https://registry.yarnpkg.com/@devprotocol/i-s-tokens/-/i-s-tokens-2.0.0.tgz#569f82aa73341110cb3e498fad140dcc806c77f0"
148+
integrity sha512-r5mpwDu2k5eN2tgGH9+UKJB2L0GPJh88jqbw2ZU1B18hhY/yKsE+S1o8iLxKJcn0JIVowAaDt0hYR4L1DSRSbQ==
149149

150150
"@devprotocol/util-ts@2.2.1":
151151
version "2.2.1"

0 commit comments

Comments
 (0)