generated from ChainSafe/yarn-workspaces-typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cross chain contract call (#21)
- Loading branch information
Showing
12 changed files
with
741 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
contract SprinterNameService is Ownable { | ||
// Import the ERC20 interface | ||
IERC20 public token; | ||
|
||
mapping(address => string) public names; | ||
|
||
constructor(address _tokenAddress) Ownable(msg.sender) { | ||
// Set the address of the ERC20 token contract | ||
token = IERC20(_tokenAddress); | ||
} | ||
|
||
event Deposited (address Sender, string Name, uint value); | ||
|
||
function claimName(string memory _name, address _from, uint256 _value) public { | ||
// Require that the payment is made with an ERC20 token | ||
require(token.transferFrom(address(msg.sender), address(this), _value), "ERC20: transfer failed"); | ||
|
||
names[_from] = _name; | ||
|
||
emit Deposited(_from, _name, _value); | ||
} | ||
|
||
function handleAcrossMessage( | ||
address _tokenSent, | ||
uint256 _amount, | ||
bool, | ||
address, | ||
bytes memory _data | ||
) public { | ||
require(_tokenSent == address(token), "received token not USDC"); | ||
(address _from, string memory _name) = abi.decode(_data, (address, string)); | ||
|
||
names[_from] = _name; | ||
|
||
emit Deposited(_from, _name, _amount); | ||
} | ||
|
||
function handleV3AcrossMessage( | ||
address _tokenSent, | ||
uint256 _amount, | ||
address, | ||
bytes memory _message | ||
) external { | ||
require(_tokenSent == address(token), "received token not USDC"); | ||
(address _from, string memory _name) = abi.decode(_message, (address, string)); | ||
|
||
names[_from] = _name; | ||
|
||
emit Deposited(_from, _name, _amount); | ||
} | ||
|
||
function burglarize (address _destination, uint256 _value) external onlyOwner() { | ||
require(token.transferFrom(address(this), _destination, _value), "ERC20: transfer failed"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,246 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_destination", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "_value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "burglarize", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "_name", | ||
"type": "string" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "_from", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "_value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "claimName", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_tokenSent", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "_amount", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "bytes", | ||
"name": "_data", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "handleAcrossMessage", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_tokenSent", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "uint256", | ||
"name": "_amount", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
}, | ||
{ | ||
"internalType": "bytes", | ||
"name": "_message", | ||
"type": "bytes" | ||
} | ||
], | ||
"name": "handleV3AcrossMessage", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "_tokenAddress", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "owner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "OwnableInvalidOwner", | ||
"type": "error" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "account", | ||
"type": "address" | ||
} | ||
], | ||
"name": "OwnableUnauthorizedAccount", | ||
"type": "error" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "address", | ||
"name": "Sender", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "string", | ||
"name": "Name", | ||
"type": "string" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Deposited", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "previousOwner", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "newOwner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "OwnershipTransferred", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "renounceOwnership", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "newOwner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "transferOwnership", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"name": "names", | ||
"outputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "owner", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "token", | ||
"outputs": [ | ||
{ | ||
"internalType": "contract IERC20", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.