UNPKG

@syncswap/sdk

Version:

SyncSwap TypeScript SDK for building DeFi applications

41 lines 1.68 kB
import { Contract } from 'ethers'; import { stateStore } from '../statestore/statestore.js'; const abis = { 'weth': import('../abi/weth.js'), 'erc20': import('../abi/erc20.js'), 'router2': import('../abi/router2.js'), 'pool_master': import('../abi/pool_master.js'), 'factory': import('../abi/factory.js'), 'multicall': import('../abi/multicall.js'), 'route_helper': import('../abi/route_helper.js'), 'token_helper': import('../abi/token_helper.js'), 'pool_helper': import('../abi/pool_helper.js'), 'nft_position_manager': import('../abi/nft_position_manager.js'), 'quoter': import('../abi/quoter.js'), 'routerv3': import('../abi/routerv3.js'), 'multicall2': import('../abi/multicall2.js'), 'multicall3': import('../abi/multicall3.js'), 'wrapper_router': import('../abi/wrapper_router.js'), 'wrapper_router_v3': import('../abi/wrapper_router_v3.js'), }; export default class ContractLoader { static async loadContract(contractType, address) { // let abi = JsonLoader.loadJson(`/abi/${contractType.abi}.json`); let abi = await abis[contractType.abi]; // handles thr raw artifact if (abi.abi) { abi = abi.abi; } if (abi.default) { abi = abi.default; } try { return new Contract(address, abi, stateStore().providerOrSigner); // Note: use {zksync-ethers}.Contract for zkstack chains } catch (error) { console.error(`Error on loading contract`, contractType, address, error); throw Error('Failed to create contract.'); } } } //# sourceMappingURL=contractLoader.js.map