-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSourceMinter.sol
56 lines (46 loc) · 1.78 KB
/
SourceMinter.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import {IRouterClient} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import {Withdraw} from "./utils/Withdraw.sol";
/**
* THIS IS AN EXAMPLE CONTRACT THAT USES HARDCODED VALUES FOR CLARITY.
* THIS IS AN EXAMPLE CONTRACT THAT USES UN-AUDITED CODE.
* DO NOT USE THIS CODE IN PRODUCTION.
*/
contract SourceMinter is Withdraw {
address immutable i_router;
address immutable i_gameToken;
uint256 public price = 1 * 10 ** 18;
event MessageSent(bytes32 messageId);
constructor(address router, address token) {
i_router = router;
i_gameToken = token;
}
receive() external payable {}
function mint(uint64 destinationChainSelector, address receiver) external {
// check the erc transfer to pay for mint
require(
IERC20(i_gameToken).transferFrom(msg.sender, address(this), price),
"mint payment transfer failed"
);
Client.EVM2AnyMessage memory message = Client.EVM2AnyMessage({
receiver: abi.encode(receiver),
data: abi.encodeWithSignature("mint(address)", msg.sender),
tokenAmounts: new Client.EVMTokenAmount[](0),
extraArgs: "",
feeToken: address(0)
});
uint256 fee = IRouterClient(i_router).getFee(
destinationChainSelector,
message
);
bytes32 messageId = IRouterClient(i_router).ccipSend{value: fee}(
destinationChainSelector,
message
);
emit MessageSent(messageId);
}
}