Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 6 additions & 27 deletions docs/_temp/SprinterNameService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ contract SprinterNameService is Ownable {
token = IERC20(_tokenAddress);
}

event Deposited (address Sender, string Name, uint value);
event Deposited (address Sender, string Name, uint Value);
event Comment (address Sender, address Recepient, string Message);

function claimName(string memory _name, address _from, uint256 _value) public {
// Require that the payment is made with an ERC20 token
Expand All @@ -26,33 +27,11 @@ contract SprinterNameService is Ownable {
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));
function comment(address _from, address _to, string memory _message) public {
require(bytes(names[_from]).length == 0, "Sender not register registered");
require(bytes(names[_to]).length == 0, "Receiver not register registered");

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);
emit Comment(_from, _to, _message);
}

function burglarize (address _destination, uint256 _value) external onlyOwner() {
Expand Down
189 changes: 88 additions & 101 deletions docs/_temp/sprinterNameService.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,136 +3,59 @@
"inputs": [
{
"internalType": "address",
"name": "_destination",
"name": "_tokenAddress",
"type": "address"
},
{
"internalType": "uint256",
"name": "_value",
"type": "uint256"
}
],
"name": "burglarize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
"type": "constructor"
},
{
"inputs": [
{
"internalType": "string",
"name": "_name",
"type": "string"
},
{
"internalType": "address",
"name": "_from",
"name": "owner",
"type": "address"
},
{
"internalType": "uint256",
"name": "_value",
"type": "uint256"
}
],
"name": "claimName",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
"name": "OwnableInvalidOwner",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "_tokenSent",
"type": "address"
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
},
{
"internalType": "bool",
"name": "",
"type": "bool"
},
{
"internalType": "address",
"name": "",
"name": "account",
"type": "address"
},
{
"internalType": "bytes",
"name": "_data",
"type": "bytes"
}
],
"name": "handleAcrossMessage",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
"name": "OwnableUnauthorizedAccount",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "_tokenSent",
"name": "Sender",
"type": "address"
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "",
"name": "Recepient",
"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"
"indexed": false,
"internalType": "string",
"name": "Message",
"type": "string"
}
],
"name": "OwnableUnauthorizedAccount",
"type": "error"
"name": "Comment",
"type": "event"
},
{
"anonymous": false,
Expand All @@ -152,7 +75,7 @@
{
"indexed": false,
"internalType": "uint256",
"name": "value",
"name": "Value",
"type": "uint256"
}
],
Expand All @@ -179,21 +102,65 @@
"type": "event"
},
{
"inputs": [],
"name": "renounceOwnership",
"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": "newOwner",
"name": "_from",
"type": "address"
},
{
"internalType": "uint256",
"name": "_value",
"type": "uint256"
}
],
"name": "transferOwnership",
"name": "claimName",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_from",
"type": "address"
},
{
"internalType": "address",
"name": "_to",
"type": "address"
},
{
"internalType": "string",
"name": "_message",
"type": "string"
}
],
"name": "comment",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
Expand Down Expand Up @@ -230,6 +197,13 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "token",
Expand All @@ -242,5 +216,18 @@
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
36 changes: 36 additions & 0 deletions packages/sdk/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,39 @@ export async function getContractSolution(
if ("error" in response) return response;
return response.data;
}

export async function getContractCallSolution(
{
account,
destinationChain,
token,
amount,
contractCall,
threshold,
whitelistedSourceChains,
}: ContractSolutionOptions,
{ baseUrl, signal }: FetchOptions = {},
): Promise<SolutionResponse> {
const url = new URL("/solution/call", baseUrl || BASE_URL);

const response = await fetch(url, {
signal,
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;
}
20 changes: 20 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getUserFungibleTokens,
setBaseUrl,
BASE_URL,
getContractCallSolution,
} from "./api";
import type {
Address,
Expand Down Expand Up @@ -130,6 +131,25 @@ class Sprinter {
);
}

public async getCallSolution(
settings: Omit<ContractSolutionOptions, "account">,
targetAccount?: Address,
options?: FetchOptions,
): Promise<SolutionResponse> {
const account = targetAccount || (await this.getAccount());

if (typeof settings !== "object" || settings === null)
throw new Error("Missing settings object");

return await getContractCallSolution(
<ContractSolutionOptions>{
...settings,
account,
},
this.makeFetchOptions(options || {}),
);
}

private async getAccount(): Promise<Address> {
const [account] = (await this.#provider.request({
method: "eth_requestAccounts",
Expand Down
Loading