Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cross chain contract call #21

Merged
merged 13 commits into from
Jul 26, 2024
61 changes: 61 additions & 0 deletions docs/_temp/SprinterNameService.sol
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");
}
}
246 changes: 246 additions & 0 deletions docs/_temp/sprinterNameService.abi.json
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"
}
]
33 changes: 33 additions & 0 deletions packages/sdk/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Address,
Chain,
ChainID,
ContractSolutionOptions,
FailedSolution,
FungibleToken,
FungibleTokenBalance,
Expand Down Expand Up @@ -103,3 +104,35 @@ export async function getSolution({
if ("error" in response) return response;
return response.data;
}

export async function getContractSolution({
account,
destinationChain,
token,
amount,
contractCall,
threshold,
whitelistedSourceChains,
}: ContractSolutionOptions): Promise<SolutionResponse> {
const url = new URL("/solutions/aggregation", BASE_URL);

const response = await fetch(url, {
method: "POST",
body: JSON.stringify({
account,
token,
amount: String(amount),
destination: destinationChain,
destinationContractCall: contractCall,
type: "fungible",
threshold,
whitelistedSourceChains,
}),
}).then(
(response) =>
response.json() as unknown as { data: Solution[] } | FailedSolution
);

if ("error" in response) return response;
return response.data;
}
Loading
Loading