add deposit record to deposit events

This commit is contained in:
Barry Gitarts 2021-03-01 15:36:50 -05:00
parent fed3f2e820
commit 7db95a922f
2 changed files with 16 additions and 3 deletions

View File

@ -6,6 +6,7 @@ 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';
import { ERC20Handler__factory } from "../types/factories/ERC20Handler__factory";
export const getSNTEthereum = (provider: Provider) => getSNTContract(provider, SNT_ETHEREUM);
export const getSNTAvalanche = (provider: Provider) => getSNTContract(provider, SNT_AVALANCHE);
@ -21,3 +22,7 @@ export const getSetBalance = async (token: ERC20|undefined, account: string, set
const balance = await token?.balanceOf(account);
setState(balance);
}
export const getERC20Handler = (address: string, provider: Provider) => {
return ERC20Handler__factory.connect(address, provider)
}

View File

@ -1,21 +1,29 @@
import { Bridge as IBridge } from "../types/Bridge";
import { ERC20Handler } from "../types/ERC20Handler";
import { getERC20Handler } from "./contracts";
import { Event } from "ethers";
export interface EnrichedEvent extends Event {
decoded?: Array<any>
decoded?: Array<any>,
depositRecord?: object
}
export const getDepositEvents = async (ethereumBridge: IBridge|undefined, setState: Function) => {
if(!ethereumBridge) return
const events = ethereumBridge.filters.Deposit(null,null,null)
const deposits: Event[] = await ethereumBridge.queryFilter(events)
const enriched = deposits.map(d => {
const enriched = deposits.map(async d => {
const { data, topics, decode } = d
if (!decode) return
const decoded = decode(data, topics)
const newD: EnrichedEvent = d
newD.decoded = decoded
const handlerAddress = await ethereumBridge._resourceIDToHandlerAddress(decoded.resourceID)
const erc20Handler: ERC20Handler = getERC20Handler(handlerAddress, ethereumBridge.provider);
const depositRecord = await erc20Handler._depositRecords(decoded.destinationChainID, decoded.depositNonce);
newD.depositRecord = depositRecord;
return newD
})
setState(enriched)
const resolved = await Promise.all(enriched)
setState(resolved)
}