UNPKG

dp-contract-proxy-kit

Version:

Enable batched transactions and contract account interactions using a unique deterministic Gnosis Safe.

71 lines 3.43 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { normalizeGasLimit } from '../../utils/transactions'; class EthersV4ContractAdapter { constructor(contract, ethersAdapter) { this.contract = contract; this.ethersAdapter = ethersAdapter; } get address() { return this.contract.address; } call(methodName, params, options) { return __awaiter(this, void 0, void 0, function* () { const data = this.encode(methodName, params); const resHex = yield this.ethersAdapter.ethCall(Object.assign(Object.assign({}, options), { to: this.address, data }), 'latest'); const rets = this.contract.interface.functions[methodName].decode(resHex); if (rets.length === 1) { return rets[0]; } return rets; }); } send(methodName, params, options) { return __awaiter(this, void 0, void 0, function* () { let transactionResponse; if (options) { const _a = normalizeGasLimit(options), { from, gas } = _a, sendOptions = __rest(_a, ["from", "gas"]); yield this.ethersAdapter.checkFromAddress(from); transactionResponse = yield this.contract.functions[methodName](...params, Object.assign({ gasLimit: gas }, sendOptions)); } else { transactionResponse = yield this.contract.functions[methodName](...params); } return { transactionResponse, hash: transactionResponse.hash }; }); } estimateGas(methodName, params, options) { return __awaiter(this, void 0, void 0, function* () { if (!options) { return (yield this.contract.estimate[methodName](...params)).toNumber(); } else { const _a = normalizeGasLimit(options), { gas } = _a, callOptions = __rest(_a, ["gas"]); return (yield this.contract.estimate[methodName](...params, Object.assign({ gasLimit: gas }, callOptions))).toNumber(); } }); } encode(methodName, params) { return this.contract.interface.functions[methodName].encode(params); } } export default EthersV4ContractAdapter; //# sourceMappingURL=EthersV4ContractAdapter.js.map