diff --git a/docs/_temp/SprinterNameService.sol b/docs/_temp/SprinterNameService.sol index a17c304..e78abc0 100644 --- a/docs/_temp/SprinterNameService.sol +++ b/docs/_temp/SprinterNameService.sol @@ -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 @@ -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() { diff --git a/docs/_temp/sprinterNameService.abi.json b/docs/_temp/sprinterNameService.abi.json index 672c6ab..acc6fed 100644 --- a/docs/_temp/sprinterNameService.abi.json +++ b/docs/_temp/sprinterNameService.abi.json @@ -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, @@ -152,7 +75,7 @@ { "indexed": false, "internalType": "uint256", - "name": "value", + "name": "Value", "type": "uint256" } ], @@ -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" @@ -230,6 +197,13 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [], "name": "token", @@ -242,5 +216,18 @@ ], "stateMutability": "view", "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" } ] \ No newline at end of file diff --git a/packages/sdk/src/api.ts b/packages/sdk/src/api.ts index e62e6ea..7d62a08 100644 --- a/packages/sdk/src/api.ts +++ b/packages/sdk/src/api.ts @@ -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 { + 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; +} diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 7e6c8fd..c4ec052 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -8,6 +8,7 @@ import { getUserFungibleTokens, setBaseUrl, BASE_URL, + getContractCallSolution, } from "./api"; import type { Address, @@ -130,6 +131,25 @@ class Sprinter { ); } + public async getCallSolution( + settings: Omit, + targetAccount?: Address, + options?: FetchOptions, + ): Promise { + const account = targetAccount || (await this.getAccount()); + + if (typeof settings !== "object" || settings === null) + throw new Error("Missing settings object"); + + return await getContractCallSolution( + { + ...settings, + account, + }, + this.makeFetchOptions(options || {}), + ); + } + private async getAccount(): Promise
{ const [account] = (await this.#provider.request({ method: "eth_requestAccounts", diff --git a/web/src/lib/components/UpdateNameModal.svelte b/web/src/lib/components/UpdateNameModal.svelte index 13a5b27..c5e9973 100644 --- a/web/src/lib/components/UpdateNameModal.svelte +++ b/web/src/lib/components/UpdateNameModal.svelte @@ -2,13 +2,14 @@ import type { SvelteComponent } from 'svelte'; import { getModalStore } from '@skeletonlabs/skeleton'; import { type Solution } from '@chainsafe/sprinter-sdk'; - import { eth } from 'web3'; + import { Contract } from 'web3'; import { selectedProvider } from '$lib/stores/wallet'; import { fromWei, toWei } from 'web3-utils'; import { sprinter, SPRINTER_SEPOLIA_ADDRESS } from '$lib/stores/sprinter'; import TransactionCard from '$lib/components/TransactionCard.svelte'; import { getNetworkByChainId, getTokenBySymbol } from '$lib/utils'; import SkullCrossbonesSolid from '$lib/icons/SkullCrossbonesSolid.svelte'; + import { sprinterNameServiceAbi } from '$lib/sprinterNameService.abi'; // Props /** Exposes parent props to this component. */ @@ -40,16 +41,19 @@ )[0]; const amount = Number(toWei(donation, 6)); - const data = eth.abi.encodeParameters(['address', 'string'], [address, name]); + const sprinterNameService = new Contract(sprinterNameServiceAbi); - const response = await $sprinter.getSolution({ + const data = sprinterNameService.methods.claimName(name, address, amount).encodeABI(); + + const response = await $sprinter.getCallSolution({ amount: amount, token: 'USDC', destinationChain: 11155111, contractCall: { callData: data, contractAddress: SPRINTER_SEPOLIA_ADDRESS, - gasLimit: 10_000_000 + approvalAddress: SPRINTER_SEPOLIA_ADDRESS, + gasLimit: 1_000_000 } }); diff --git a/web/src/lib/erc20.abi.ts b/web/src/lib/erc20.abi.ts index 4dd9a25..c91efe3 100644 --- a/web/src/lib/erc20.abi.ts +++ b/web/src/lib/erc20.abi.ts @@ -1,18 +1,4 @@ export const erc20Abi = [ - { - constant: true, - inputs: [], - name: 'name', - outputs: [ - { - name: '', - type: 'string' - } - ], - payable: false, - stateMutability: 'view', - type: 'function' - }, { constant: false, inputs: [ @@ -36,117 +22,6 @@ export const erc20Abi = [ stateMutability: 'nonpayable', type: 'function' }, - { - constant: true, - inputs: [], - name: 'totalSupply', - outputs: [ - { - name: '', - type: 'uint256' - } - ], - payable: false, - stateMutability: 'view', - type: 'function' - }, - { - constant: false, - inputs: [ - { - name: '_from', - type: 'address' - }, - { - name: '_to', - type: 'address' - }, - { - name: '_value', - type: 'uint256' - } - ], - name: 'transferFrom', - outputs: [ - { - name: '', - type: 'bool' - } - ], - payable: false, - stateMutability: 'nonpayable', - type: 'function' - }, - { - constant: true, - inputs: [], - name: 'decimals', - outputs: [ - { - name: '', - type: 'uint8' - } - ], - payable: false, - stateMutability: 'view', - type: 'function' - }, - { - constant: true, - inputs: [ - { - name: '_owner', - type: 'address' - } - ], - name: 'balanceOf', - outputs: [ - { - name: 'balance', - type: 'uint256' - } - ], - payable: false, - stateMutability: 'view', - type: 'function' - }, - { - constant: true, - inputs: [], - name: 'symbol', - outputs: [ - { - name: '', - type: 'string' - } - ], - payable: false, - stateMutability: 'view', - type: 'function' - }, - { - constant: false, - inputs: [ - { - name: '_to', - type: 'address' - }, - { - name: '_value', - type: 'uint256' - } - ], - name: 'transfer', - outputs: [ - { - name: '', - type: 'bool' - } - ], - payable: false, - stateMutability: 'nonpayable', - type: 'function' - }, { constant: true, inputs: [ @@ -169,54 +44,5 @@ export const erc20Abi = [ payable: false, stateMutability: 'view', type: 'function' - }, - { - payable: true, - stateMutability: 'payable', - type: 'fallback' - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - name: 'owner', - type: 'address' - }, - { - indexed: true, - name: 'spender', - type: 'address' - }, - { - indexed: false, - name: 'value', - type: 'uint256' - } - ], - name: 'Approval', - type: 'event' - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - name: 'from', - type: 'address' - }, - { - indexed: true, - name: 'to', - type: 'address' - }, - { - indexed: false, - name: 'value', - type: 'uint256' - } - ], - name: 'Transfer', - type: 'event' } ] as const; diff --git a/web/src/lib/sprinterNameService.abi.ts b/web/src/lib/sprinterNameService.abi.ts index 9c3249f..daa57b2 100644 --- a/web/src/lib/sprinterNameService.abi.ts +++ b/web/src/lib/sprinterNameService.abi.ts @@ -1,4 +1,27 @@ export const sprinterNameServiceAbi = [ + { + 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: [ { diff --git a/web/src/lib/stores/sprinter.ts b/web/src/lib/stores/sprinter.ts index e27d1d8..dbcf0b9 100644 --- a/web/src/lib/stores/sprinter.ts +++ b/web/src/lib/stores/sprinter.ts @@ -10,4 +10,4 @@ selectedProvider.subscribe((event) => { if (event) sprinter.set(new Sprinter(event.provider)); }); -export const SPRINTER_SEPOLIA_ADDRESS = '0xa8bf0d2Ad50e9B0686da8838AE7D33bEfAbc1413'; +export const SPRINTER_SEPOLIA_ADDRESS = '0xf70fb86F700E8Bb7cDf1c20197633518235c3425';