UNPKG

@syncswap/sdk

Version:

SyncSwap TypeScript SDK for building DeFi applications

40 lines 2.12 kB
import { Contract } from 'ethers'; const abis = { 'weth': import('../abi/weth.json', { assert: { type: 'json' } }), 'erc20': import('../abi/erc20.json', { assert: { type: 'json' } }), 'router2': import('../abi/router2.json', { assert: { type: 'json' } }), 'pool_master': import('../abi/pool_master.json', { assert: { type: 'json' } }), 'factory': import('../abi/factory.json', { assert: { type: 'json' } }), 'multicall': import('../abi/multicall.json', { assert: { type: 'json' } }), 'route_helper': import('../abi/route_helper.json', { assert: { type: 'json' } }), 'token_helper': import('../abi/token_helper.json', { assert: { type: 'json' } }), 'pool_helper': import('../abi/pool_helper.json', { assert: { type: 'json' } }), 'nft_position_manager': import('../abi/nft_position_manager.json', { assert: { type: 'json' } }), 'quoter': import('../abi/quoter.json', { assert: { type: 'json' } }), 'routerv3': import('../abi/routerv3.json', { assert: { type: 'json' } }), 'multicall2': import('../abi/multicall2.json', { assert: { type: 'json' } }), 'multicall3': import('../abi/multicall3.json', { assert: { type: 'json' } }), 'wrapper_router': import('../abi/wrapper_router.json', { assert: { type: 'json' } }), 'wrapper_router_v3': import('../abi/wrapper_router_v3.json', { assert: { type: 'json' } }), }; export default class ContractLoader { static async loadContract(provider, 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, provider); // 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