Skip to content

Commit

Permalink
PST2GWT bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiushi committed Jun 19, 2024
1 parent 3b4d29e commit cfa47dc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions contracts/pst_bridge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./gwt.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract PSTBridge is Ownable {
GWT public gwt;

// PST到GWT的兑换
mapping(bytes32 => uint256) public pst_to_gwt;

constructor(address _gwt) Ownable(msg.sender) {
gwt = GWT(_gwt);
}

function getClaimableGWT(string calldata cookie) public view returns (uint256) {
return pst_to_gwt[keccak256(abi.encodePacked(msg.sender, cookie))];
}

function registerPST(address[] calldata recvAddress, string[] calldata cookie, uint256[] calldata pstAmount) onlyOwner public {
for (uint i = 0; i < recvAddress.length; i++) {
pst_to_gwt[keccak256(abi.encodePacked(recvAddress[i], cookie[i]))] = pstAmount[i] / 210;
}
}

function claimGWT(string calldata cookie) public {
bytes32 key = keccak256(abi.encodePacked(msg.sender, cookie));
require(pst_to_gwt[key] > 0, "no dmc1 amount");
uint256 gwtAmount = pst_to_gwt[key];
pst_to_gwt[key] = 0;

gwt.mint(msg.sender, gwtAmount);
}
}

0 comments on commit cfa47dc

Please sign in to comment.