Skip to content

Commit 0634911

Browse files
committed
feat: add token receiver function
1 parent f31e902 commit 0634911

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

contracts/tokens/WrappedPinakion.sol

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,30 @@ 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+
*/
120+
function onTokenBridged(address _token, uint _amount, bytes _data) external {
121+
require(msg.sender == address(tokenBridge), "Sender not authorized.");
122+
require(_token == address(xPinakion), "Token bridged is not xPinakion.");
123+
124+
address recipient;
125+
assembly {
126+
recipient := calldataload(0x84)
127+
}
128+
_mint(recipient, _amount);
129+
}
130+
112131
/** @dev Withdraws bridged pinakions.
113132
* @param _amount The amount of bridged pinakions to withdraw.
114133
*/
@@ -223,12 +242,13 @@ contract WrappedPinakion is Initializable {
223242
* @dev Internal function that mints an amount of the token and assigns it to
224243
* an account. This encapsulates the modification of balances such that the
225244
* proper events are emitted.
245+
* @param _recipient The amount that will be created.
226246
* @param _amount The amount that will be created.
227247
*/
228-
function _mint(uint256 _amount) internal {
248+
function _mint(address _recipient, uint256 _amount) internal {
229249
totalSupply = totalSupply.add(_amount);
230-
balances[msg.sender] = balances[msg.sender].add(_amount);
231-
emit Transfer(address(0x0), msg.sender, _amount);
250+
balances[_recipient] = balances[_recipient].add(_amount);
251+
emit Transfer(address(0x0), _recipient, _amount);
232252
}
233253

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

0 commit comments

Comments
 (0)