From 348aef176e327be721fba123bb717bddc589bbb0 Mon Sep 17 00:00:00 2001 From: ZeKraken Date: Thu, 13 Apr 2023 08:43:00 -0400 Subject: [PATCH 1/9] header update --- src/App.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 08e8ced..b75c473 100644 --- a/src/App.js +++ b/src/App.js @@ -278,7 +278,11 @@ function App() { Rate Providers - + + + Token Approvals + + {rows.map((_, rowIndex) => ( From 2bc90ddb210a574d01693f7ccb3cb4b5efe63d70 Mon Sep 17 00:00:00 2001 From: ZeKraken Date: Thu, 13 Apr 2023 18:01:25 -0400 Subject: [PATCH 2/9] update for initjoin --- .gitignore | 1 + README.md | 17 ------- src/App.js | 128 +++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 116 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 4d29575..36d5bdc 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ .env.development.local .env.test.local .env.production.local +.scratchpad npm-debug.log* yarn-debug.log* diff --git a/README.md b/README.md index c38fe5b..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,17 +0,0 @@ -token addresses -0xdfcea9088c8a88a76ff74892c1457c17dfeef9c1 -0xfa8449189744799ad2ace7e0ebac8bb7575eff47 - -amounts -800000000000000000 -200000000000000000 - -swap fee -10000000000000000 - -owner -0xaffc70b81d54f229a5f50ec07e2c76d2aaad07ae - -rate provider -0x0000000000000000000000000000000000000000 -0x0000000000000000000000000000000000000000 diff --git a/src/App.js b/src/App.js index b75c473..b99931e 100644 --- a/src/App.js +++ b/src/App.js @@ -7,8 +7,10 @@ import Box from "@mui/material/Box"; import Container from "@mui/material/Container"; import { CreateABI } from "./abi/WeightedPoolFactory"; import { ERC20 } from "./abi/erc20"; +import { vaultABI } from "./abi/BalVault"; function App() { + const [isConnected, setIsConnected] = useState(false); const FactoryAddress = "0x230a59f4d9adc147480f03b0d3fffecd56c3289a"; const [walletAddress, setWalletAddress] = useState(); const [buttonText, setButtonText] = useState("Connect Wallet"); @@ -31,6 +33,7 @@ function App() { const [tokenAddresses, setTokenAddresses] = useState(new Array(8).fill("")); const [tokenWeights, setTokenWeights] = useState(new Array(8).fill("")); const [rateProviders, setRateProviders] = useState(new Array(8).fill("")); + const [tokenAmounts, setTokenAmounts] = useState(new Array(8).fill("")); const handleInputChange = (event, rowIndex, setter) => { const newValue = event.target.value; setter((prevState) => { @@ -45,7 +48,7 @@ function App() { const accounts = await window.ethereum.request({ method: "eth_accounts", }); - if (accounts.length) { + if (accounts.length && !isConnected) { const networkId = await window.ethereum.request({ method: "net_version", }); @@ -54,17 +57,24 @@ function App() { const ethaddress = accounts[0]; setWalletAddress(ethaddress); setButtonText("Wallet Connected"); - } else { + setIsConnected(true); + } else if (!accounts.length && isConnected) { console.log("Metamask is not connected"); + setIsConnected(false); } } - window.ethereum.on("chainChanged", () => { + const onChainChanged = () => { checkWalletonLoad(); - }); - window.ethereum.on("accountsChanged", () => { + }; + + const onAccountsChanged = () => { checkWalletonLoad(); - }); + }; + + window.ethereum.setMaxListeners(window.ethereum.getMaxListeners() + 2); // Increase the max listeners limit + window.ethereum.on("chainChanged", onChainChanged); + window.ethereum.on("accountsChanged", onAccountsChanged); async function checkApprovedTokens() { const provider = new ethers.providers.Web3Provider(window.ethereum); @@ -88,7 +98,13 @@ function App() { checkWalletonLoad(); checkApprovedTokens(); - }, [tokenAddresses, approvedTokens, walletAddress]); + + return () => { + window.ethereum.removeListener("chainChanged", onChainChanged); + window.ethereum.removeListener("accountsChanged", onAccountsChanged); + window.ethereum.setMaxListeners(window.ethereum.getMaxListeners() - 2); // Decrease the max listeners limit back + }; + }, [tokenAddresses, approvedTokens, walletAddress, isConnected]); function getNetworkName(networkId) { switch (networkId) { @@ -161,6 +177,57 @@ function App() { ); } + async function initJoin() { + await requestAccount(); + const provider = new ethers.providers.Web3Provider(window.ethereum); + await provider.send("eth_requestAccounts", []); + const signer = await provider.getSigner(); + const ethcontract = new ethers.Contract(contractAddress, vaultABI, signer); + const gasoverride = { gasLimit: 6000000 }; + + const poolId = + "0xd503dd8ae0e4669106167ad1a7df0569a9c1340500020000000000000000073a"; + const assets = [ + "0xdfcea9088c8a88a76ff74892c1457c17dfeef9c1", + "0xfa8449189744799ad2ace7e0ebac8bb7575eff47", + ]; + const amountsIn = ["1000000000000000", "70000000000000000"]; + + const linkedItems = assets.map((asset, index) => [asset, amountsIn[index]]); + + linkedItems.sort((a, b) => { + if (a[0] < b[0]) return -1; + if (a[0] > b[0]) return 1; + return 0; + }); + + const sortedAssets = linkedItems.map((item) => item[0]); + const sortedAmountsIn = linkedItems.map((item) => item[1]); + + const JOIN_KIND_INIT = 0; + + const userData = ethers.utils.defaultAbiCoder.encode( + ["uint256", "uint256[]"], + [JOIN_KIND_INIT, sortedAmountsIn] + ); + + const joinRequest = { + assets: sortedAssets, + maxAmountsIn: amountsIn, + userData, + fromInternalBalance: false, + }; + + console.log(joinRequest); + + await ethcontract.joinPool( + poolId, + walletAddress, + walletAddress, + joinRequest, + gasoverride + ); + } // const checkAllowance = async (tokenAddress, contractAddress) => { // const provider = new ethers.providers.Web3Provider(window.ethereum); // const tokenContract = new ethers.Contract(tokenAddress, ERC20, provider); @@ -243,9 +310,16 @@ function App() {
- +

@@ -262,13 +336,13 @@ function App() { }} > - + Token Addresses - + Token Weights @@ -278,11 +352,16 @@ function App() { Rate Providers - + Token Approvals + + + Token Amounts + + {rows.map((_, rowIndex) => ( @@ -307,7 +386,7 @@ function App() { }} /> - + - +