Skip to content

Commit

Permalink
add wrap/unwrap eth examples
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith committed Mar 15, 2024
1 parent c52455f commit aff8239
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 2 deletions.
16 changes: 16 additions & 0 deletions examples/unwrap-eth.ts
Original file line number Diff line number Diff line change
@@ -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<void> => {
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();
13 changes: 13 additions & 0 deletions examples/wrap-eth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { signAndSendTransaction } from "../src/chains/ethereum";
import { setupAccount } from "./setup";

const run = async (): Promise<void> => {
const sender = await setupAccount();
const sepoliaWETH = "0xfff9976782d46cc05630d1f6ebab18b2324d6b14";
const ethAmount = 0.01;
const deposit = "0xd0e30db0";

await signAndSendTransaction(sender, sepoliaWETH, ethAmount, deposit);
};

run();
279 changes: 279 additions & 0 deletions src/abis/WETH.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
9 changes: 7 additions & 2 deletions src/utils/interfaces.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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);
}

0 comments on commit aff8239

Please sign in to comment.