diff --git a/examples/unwrap-eth.ts b/examples/unwrap-eth.ts new file mode 100644 index 0000000..d5222d2 --- /dev/null +++ b/examples/unwrap-eth.ts @@ -0,0 +1,16 @@ +import { parseEther } from "ethers"; +import { signAndSendTransaction } from "../src/chains/ethereum"; +import { wethInterface } from "../src/utils/interfaces"; +import { setupAccount } from "./setup"; + +const run = async (): Promise => { + const sender = await setupAccount(); + const sepoliaWETH = "0xfff9976782d46cc05630d1f6ebab18b2324d6b14"; + const ethAmount = 0.01; + const callData = wethInterface().encodeFunctionData("withdraw", [ + parseEther(ethAmount.toString()), + ]); + await signAndSendTransaction(sender, sepoliaWETH, 0, callData); +}; + +run(); diff --git a/examples/wrap-eth.ts b/examples/wrap-eth.ts new file mode 100644 index 0000000..716759a --- /dev/null +++ b/examples/wrap-eth.ts @@ -0,0 +1,13 @@ +import { signAndSendTransaction } from "../src/chains/ethereum"; +import { setupAccount } from "./setup"; + +const run = async (): Promise => { + const sender = await setupAccount(); + const sepoliaWETH = "0xfff9976782d46cc05630d1f6ebab18b2324d6b14"; + const ethAmount = 0.01; + const deposit = "0xd0e30db0"; + + await signAndSendTransaction(sender, sepoliaWETH, ethAmount, deposit); +}; + +run(); diff --git a/src/abis/WETH.json b/src/abis/WETH.json new file mode 100644 index 0000000..ba877d3 --- /dev/null +++ b/src/abis/WETH.json @@ -0,0 +1,279 @@ +[ + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "guy", + "type": "address" + }, + { + "name": "wad", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "src", + "type": "address" + }, + { + "name": "dst", + "type": "address" + }, + { + "name": "wad", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "name": "wad", + "type": "uint256" + } + ], + "name": "withdraw", + "outputs": [], + "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": "", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "name": "", + "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": "dst", + "type": "address" + }, + { + "name": "wad", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "deposit", + "outputs": [], + "payable": true, + "stateMutability": "payable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "name": "", + "type": "address" + }, + { + "name": "", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "payable": true, + "stateMutability": "payable", + "type": "fallback" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "src", + "type": "address" + }, + { + "indexed": true, + "name": "guy", + "type": "address" + }, + { + "indexed": false, + "name": "wad", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "src", + "type": "address" + }, + { + "indexed": true, + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "name": "wad", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "dst", + "type": "address" + }, + { + "indexed": false, + "name": "wad", + "type": "uint256" + } + ], + "name": "Deposit", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "name": "src", + "type": "address" + }, + { + "indexed": false, + "name": "wad", + "type": "uint256" + } + ], + "name": "Withdrawal", + "type": "event" + } +] \ No newline at end of file diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts index 4c6133d..eeecd7d 100644 --- a/src/utils/interfaces.ts +++ b/src/utils/interfaces.ts @@ -1,7 +1,8 @@ import { ethers } from "ethers"; import erc721ABI from "../abis/ERC721.json"; import erc1155ABI from "../abis/ERC1155.json"; -import seaport from "../abis/Seaport.json"; +import seaportABI from "../abis/Seaport.json"; +import wethABI from "../abis/WETH.json"; export function erc721Interface(): ethers.Interface { return new ethers.Interface(erc721ABI); @@ -12,5 +13,9 @@ export function erc1155Interface(): ethers.Interface { } export function openSeaInterface(): ethers.Interface { - return new ethers.Interface(seaport); + return new ethers.Interface(seaportABI); +} + +export function wethInterface(): ethers.Interface { + return new ethers.Interface(wethABI); }