Skip to content

Commit fc31ebc

Browse files
authored
Merge pull request #9 from kleros/feat/stpnk-relayer
Feat/stpnk relayer
2 parents f31e902 + 52fb9a6 commit fc31ebc

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ MetaMask setup for Sokol:
1313
## Deployed Addresses
1414

1515
Sokol:
16-
- Wrapped PNK: `0x03FCABBE7680ff0513349E643b11CE83A7434fD7`
17-
- xKlerosLiquid: `0xec8726b782D77fC9Fdf64d12D895CA15956b9e0e`
18-
- xKlerosLiquidExtraViews: `0x850753F8785471893d552e7Bdadcc2ccD8eB182F`
16+
- Wrapped PNK: `0x9Bc02E9f5291adbb1f0Cf5C15ab1B400dccd3665`
17+
- xKlerosLiquid: `0xb701ff19fBD9702DD7Ca099Ee7D0D42a2612baB5`
18+
- xKlerosLiquidExtraViews: `0x1Aab57DD59afc98bff1D939b34974E9c8fc705fF`
1919
- PolicyRegistry: `0x0Bee63bC7220d0Bacd8A3c9d6B6511126CDfe58f`
2020

2121
xDai:
@@ -26,11 +26,17 @@ xDai:
2626

2727
## Stake
2828
1. Get Kovan PNK from [faucet](https://kovan.etherscan.io/address/0x4e95b2e0ecb3bd394e1dddd775504820a746d3bd#writeContract). The Kovan PNK contract address is `0x1ee318dbc19267dbce08f54a66ab198f73ede356`.
29+
1. [approve](https://kovan.etherscan.io/address/0x1ee318dbc19267dbce08f54a66ab198f73ede356#writeContract) the amount of PNK that you want to stake to the foreign token bridge contract (`0xa960d095470f7509955d5402e36d9db984b5c8e2`).
30+
1. [relayTokensAndCall](https://kovan.etherscan.io/address/0xa960d095470f7509955d5402e36d9db984b5c8e2#writeProxyContract) in order to bridge the tokens to Sokol. Use token: `0x1ee318dbc19267dbce08f54a66ab198f73ede356`, _receiver: `0x9Bc02E9f5291adbb1f0Cf5C15ab1B400dccd3665`, _value: amount of PNK to bridge, _data: the address that will receive the tokens on Sokol padded to 32 bytes.
31+
1. Now, you are ready to [stake](https://blockscout.com/poa/sokol/address/0xb701ff19fBD9702DD7Ca099Ee7D0D42a2612baB5/write-proxy) in the Sokol general court by calling `setStake`.
32+
33+
## Stake (using Omnibridge)
34+
1. Get Kovan PNK from [faucet](https://kovan.etherscan.io/address/0x4e95b2e0ecb3bd394e1dddd775504820a746d3bd#writeContract). The Kovan PNK contract address is `0x1ee318dbc19267dbce08f54a66ab198f73ede356`.
2935
1. Go to the [token bridge](https://sokol-omnibridge.web.app/bridge) and convert Kovan PNK into Sokol PNK. The Sokol PNK contract address is `0x184A7Fc4fa965D18Af84C6d97dfed8C4561ff8c2`.
30-
1. Sokol PNK are not directly used for staking. Instead, the token is wrapped in order to let xKlerosLiquid (the courts) be the controller of the PNK contract. To convert Sokol PNK into Sokol Wrapped PNK, first [approve](https://blockscout.com/poa/sokol/address/0x184A7Fc4fa965D18Af84C6d97dfed8C4561ff8c2/write-proxy) the address `0x03FCABBE7680ff0513349E643b11CE83A7434fD7` the amount you want to convert and then call [deposit](https://blockscout.com/poa/sokol/address/0x03FCABBE7680ff0513349E643b11CE83A7434fD7/write-proxy).
31-
1. Now, you are ready to [stake](https://blockscout.com/poa/sokol/address/0xec8726b782D77fC9Fdf64d12D895CA15956b9e0e/write-proxy) in the Sokol general court by calling `setStake`.
36+
1. Sokol PNK are not directly used for staking. Instead, the token is wrapped in order to let xKlerosLiquid (the courts) be the controller of the PNK contract. To convert Sokol PNK into Sokol Wrapped PNK, first [approve](https://blockscout.com/poa/sokol/address/0x184A7Fc4fa965D18Af84C6d97dfed8C4561ff8c2/write-proxy) the address `0x9Bc02E9f5291adbb1f0Cf5C15ab1B400dccd3665` the amount you want to convert and then call [deposit](https://blockscout.com/poa/sokol/address/0x9Bc02E9f5291adbb1f0Cf5C15ab1B400dccd3665/write-proxy).
37+
1. Now, you are ready to [stake](https://blockscout.com/poa/sokol/address/0xb701ff19fBD9702DD7Ca099Ee7D0D42a2612baB5/write-proxy) in the Sokol general court by calling `setStake`.
3238

3339
## Unstake
3440
1. Unstake from the Sokol general court.
35-
1. You can use `withdrawAndConvertToPNK()` [method](https://blockscout.com/poa/sokol/address/0x03FCABBE7680ff0513349E643b11CE83A7434fD7/write-contract) to directly convert the Sokol Wrapped PNK into Kovan PNK. If you use this method, it is possible to set the receiver. On the Kovan chain, the tokens have to be claimed though. Go to the [token bridge](https://sokol-omnibridge.web.app/bridge), connect MetaMask with your Kovan account and claim your tokens.
36-
1. If you rather use the token bridge, call `withdraw()` [method](https://blockscout.com/poa/sokol/address/0x03FCABBE7680ff0513349E643b11CE83A7434fD7/write-contract) instead. Then go to the [token bridge](https://sokol-omnibridge.web.app/bridge) convert your tokens.
41+
1. You can use `withdrawAndConvertToPNK()` [method](https://blockscout.com/poa/sokol/address/0x9Bc02E9f5291adbb1f0Cf5C15ab1B400dccd3665/write-contract) to directly convert the Sokol Wrapped PNK into Kovan PNK. If you use this method, it is possible to set the receiver. On the Kovan chain, the tokens have to be claimed though. Go to the [token bridge](https://sokol-omnibridge.web.app/bridge), connect MetaMask with your Kovan account and claim your tokens.
42+
1. If you rather use the token bridge, call `withdraw()` [method](https://blockscout.com/poa/sokol/address/0x9Bc02E9f5291adbb1f0Cf5C15ab1B400dccd3665/write-contract) instead. Then go to the [token bridge](https://sokol-omnibridge.web.app/bridge) convert your tokens.

contracts/tokens/WrappedPinakion.sol

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* https://contributing.kleros.io/smart-contract-workflow
33
* @authors: [@fnanni-0]
4-
* @reviewers: [@unknownunknown1, @MerlinEgalite, @hbarcelos, @shalzz]
4+
* @reviewers: [@unknownunknown1*, @MerlinEgalite*, @hbarcelos*, @shalzz*]
55
* @auditors: []
66
* @bounties: []
77
* @deployments: []
@@ -104,11 +104,31 @@ contract WrappedPinakion is Initializable {
104104
* @param _amount The amount of wrapped pinakions to mint.
105105
*/
106106
function deposit(uint _amount) external {
107-
_mint(_amount);
107+
_mint(msg.sender, _amount);
108108
require(xPinakion.transferFrom(msg.sender, address(this), _amount), "Sender does not have enough approved funds.");
109109
}
110110

111111

112+
/** @dev IERC20 Receiver functionality.
113+
* Converts bridged PNK (xPinakion) into wrapped PNK which can be staked in KlerosLiquid.
114+
* If the tokenBridge is calling this function, then this contract has already received
115+
* the xPinakion tokens.
116+
* @param _token The token address the _amount belongs to.
117+
* @param _amount The amount of wrapped pinakions to mint.
118+
* @param _data Calldata containing the address of the recipient.
119+
* Notice that the address has to be padded to 32 bytes.
120+
*/
121+
function onTokenBridged(address _token, uint _amount, bytes _data) external {
122+
require(msg.sender == address(tokenBridge), "Sender not authorized.");
123+
require(_token == address(xPinakion), "Token bridged is not xPinakion.");
124+
125+
address recipient;
126+
assembly {
127+
recipient := calldataload(0x84)
128+
}
129+
_mint(recipient, _amount);
130+
}
131+
112132
/** @dev Withdraws bridged pinakions.
113133
* @param _amount The amount of bridged pinakions to withdraw.
114134
*/
@@ -223,12 +243,13 @@ contract WrappedPinakion is Initializable {
223243
* @dev Internal function that mints an amount of the token and assigns it to
224244
* an account. This encapsulates the modification of balances such that the
225245
* proper events are emitted.
246+
* @param _recipient The address which will receive the minted tokens.
226247
* @param _amount The amount that will be created.
227248
*/
228-
function _mint(uint256 _amount) internal {
249+
function _mint(address _recipient, uint256 _amount) internal {
229250
totalSupply = totalSupply.add(_amount);
230-
balances[msg.sender] = balances[msg.sender].add(_amount);
231-
emit Transfer(address(0x0), msg.sender, _amount);
251+
balances[_recipient] = balances[_recipient].add(_amount);
252+
emit Transfer(address(0x0), _recipient, _amount);
232253
}
233254

234255
/** @dev Destroys `_amount` tokens from the caller. Cannot burn locked tokens.

0 commit comments

Comments
 (0)