mirror of
https://github.com/status-im/eth_ava_bridge.git
synced 2025-02-21 07:18:11 +00:00
add proper handling SNT/erc20 deposits
This commit is contained in:
parent
147bbae2a0
commit
0130a8e43b
@ -9,9 +9,11 @@ import { Greeter } from './components/Greeter';
|
||||
import { Bridge } from './components/Bridge';
|
||||
import { getAndSetProvider } from './utils/network';
|
||||
import { ERC20 } from './types/ERC20';
|
||||
import { Bridge as IBridge } from './types/Bridge';
|
||||
import Header from './components/Header';
|
||||
import { getISntEthereum } from './utils/contracts';
|
||||
import { getISntEthereum, getBridge } from './utils/contracts';
|
||||
import { goerliProvider } from './utils/providers'
|
||||
import { ethereumAddress } from './constants/bridges';
|
||||
|
||||
const { useState, useEffect } = React;
|
||||
|
||||
@ -21,6 +23,7 @@ function App() {
|
||||
const [ethereumProvider, setEthereumProvider] = useState<Provider>();
|
||||
const [account, setAccount] = useState<string>('');
|
||||
const [sntEthereum, setSntEthereum] = useState<ERC20>();
|
||||
const [ethereumBridge, setEthereumBridge] = useState<IBridge>();
|
||||
|
||||
useEffect(() => {
|
||||
if (!provider) getAndSetProvider(setProvider);
|
||||
@ -36,6 +39,13 @@ function App() {
|
||||
}
|
||||
}, [provider])
|
||||
|
||||
useEffect(() => {
|
||||
//TODO use ethereum provider
|
||||
if (!provider) return
|
||||
const bridge: IBridge = getBridge(ethereumAddress, provider);
|
||||
setEthereumBridge(bridge);
|
||||
}, [provider])
|
||||
|
||||
useEffect(() => {
|
||||
if (window.ethereum && window.ethereum.selectedAddress) setAccount(window.ethereum.selectedAddress);
|
||||
window.ethereum.on('accountsChanged', function (accounts: Array<string>) {
|
||||
@ -53,11 +63,12 @@ function App() {
|
||||
enableEthereum={undefined}
|
||||
sntEthereum={sntEthereum}
|
||||
/>
|
||||
<Bridge
|
||||
{!!ethereumBridge && <Bridge
|
||||
account={account}
|
||||
provider={provider}
|
||||
sntEthereum={sntEthereum}
|
||||
/>
|
||||
ethereumBridge={ethereumBridge}
|
||||
/>}
|
||||
</div>
|
||||
</Symfoni>
|
||||
</ThemeProvider>
|
||||
|
@ -15,6 +15,7 @@ import { getISntEthereum } from '../utils/contracts';
|
||||
import { ERC20 } from "../types/ERC20";
|
||||
import { fromWei } from "../utils/helpers"
|
||||
import { getSetBalance } from "../utils/contracts";
|
||||
import { ethereumSNTHandlerAddress } from "../constants/bridges";
|
||||
|
||||
type IBridgeInfo = {
|
||||
amount: string,
|
||||
@ -25,7 +26,8 @@ const wallet = Wallet.createRandom();
|
||||
interface Props {
|
||||
account: string,
|
||||
provider: Web3Provider | undefined,
|
||||
sntEthereum: ERC20 | undefined
|
||||
sntEthereum: ERC20 | undefined,
|
||||
ethereumBridge: IBridge
|
||||
}
|
||||
const FUJI_BRIDGE = '0xE57Eb49689bCAE4dE61D326F7E79Bd14aB527f0f';
|
||||
const GOERLI_BRIDGE = '0xD0E461b1Dc56503fC72565FA964C28E274146D44';
|
||||
@ -36,7 +38,7 @@ const fujiVoidSigner = new VoidSigner(wallet.address, fujiProvider);
|
||||
const goerliVoidsigner = new VoidSigner(wallet.address, goerliProvider);
|
||||
|
||||
|
||||
export const Bridge: React.FC<Props> = ({ account, provider, sntEthereum }) => {
|
||||
export const Bridge: React.FC<Props> = ({ account, provider, sntEthereum, ethereumBridge }) => {
|
||||
const classes: any = useStyles()
|
||||
const bridge: SymfoniBridge = useContext(BridgeContext);
|
||||
const [message, setMessage] = useState("");
|
||||
@ -69,17 +71,6 @@ export const Bridge: React.FC<Props> = ({ account, provider, sntEthereum }) => {
|
||||
getSetBalance(sntEthereum, account, setSntEthereumBalance);
|
||||
}, [account])
|
||||
|
||||
const handleSetGreeting = async (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
||||
e.preventDefault()
|
||||
if (!bridge.instance) throw Error("Bridge instance not ready")
|
||||
if (bridge.instance) {
|
||||
//const tx = await bridge.instance.setGreeting(inputGreeting)
|
||||
const tx = await bridge.instance._expiry();
|
||||
//const fuji = await fujiBridge.instance?._expiry();
|
||||
const goerli = await goerliBridge?._expiry();
|
||||
console.log("expiry", {tx, goerli}, goerliBridge?.address);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Formik
|
||||
initialValues={{
|
||||
@ -94,15 +85,16 @@ export const Bridge: React.FC<Props> = ({ account, provider, sntEthereum }) => {
|
||||
if (!provider) return;
|
||||
const signer = provider.getSigner()
|
||||
const sntActiveProvider = sntEthereum?.connect(signer);
|
||||
const activeBridge = ethereumBridge.connect(signer);
|
||||
if(!bridge || !bridge.instance) return
|
||||
//TODO check approval
|
||||
|
||||
const approved = await sntActiveProvider?.allowance(account, bridge.instance.address);
|
||||
const approved = await sntActiveProvider?.allowance(account, ethereumSNTHandlerAddress);
|
||||
if (approved?.lt(weiAmount)) {
|
||||
const amt = approved.eq(0) ? weiAmount : toWei('0');
|
||||
await sntActiveProvider?.approve(bridge.instance?.address, amt);
|
||||
//TODO approve handler not bridge
|
||||
await sntActiveProvider?.approve(ethereumSNTHandlerAddress, amt);
|
||||
} else {
|
||||
const deposit = await bridge.instance?.deposit(
|
||||
console.log({AVA_CHAIN_ID, resourceId, encodedData});
|
||||
const deposit = await activeBridge.deposit(
|
||||
AVA_CHAIN_ID,
|
||||
resourceId,
|
||||
encodedData
|
||||
|
2
frontend/src/constants/bridges.ts
Normal file
2
frontend/src/constants/bridges.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export const ethereumAddress = '0xD0E461b1Dc56503fC72565FA964C28E274146D44';
|
||||
export const ethereumSNTHandlerAddress = '0xf41938b2464B908D5C10287bbfBE69dd368DaC3a';
|
@ -1,13 +1,19 @@
|
||||
import { Wallet, providers, Contract, VoidSigner } from "ethers";
|
||||
import { SNT_ADDRESS } from "../constants/goerliAddress";
|
||||
import { ERC20 } from "../types/ERC20";
|
||||
import { ERC20__factory } from "../types/factories/ERC20__factory"
|
||||
import { Bridge as IBridge } from "../types/Bridge";
|
||||
import { Bridge__factory } from "../types/factories/Bridge__factory";
|
||||
import { ERC20__factory } from "../types/factories/ERC20__factory";
|
||||
import { Provider } from '@ethersproject/providers'
|
||||
|
||||
export const getISntEthereum = (provider: Provider) => {
|
||||
return ERC20__factory.connect(SNT_ADDRESS, provider);
|
||||
}
|
||||
|
||||
export const getBridge = (address: string, provider: Provider) => {
|
||||
return Bridge__factory.connect(address, provider);
|
||||
}
|
||||
|
||||
export const getSetBalance = async (token: ERC20|undefined, account: string, setState: Function) => {
|
||||
const balance = await token?.balanceOf(account);
|
||||
setState(balance);
|
||||
|
0
verify/sntHandler.js
Normal file
0
verify/sntHandler.js
Normal file
9
verify/sntHandler.ts
Normal file
9
verify/sntHandler.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { createResourceID } from "../utils/helpers";
|
||||
import { SNT_ADDRESS } from "../constants/goerliAddress";
|
||||
|
||||
module.exports = [
|
||||
"0xD0E461b1Dc56503fC72565FA964C28E274146D44",
|
||||
[createResourceID(SNT_ADDRESS, 1)],
|
||||
[SNT_ADDRESS],
|
||||
[]
|
||||
];
|
Loading…
x
Reference in New Issue
Block a user