dp-contract-proxy-kit
Version:
Enable batched transactions and contract account interactions using a unique deterministic Gnosis Safe.
58 lines • 2.39 kB
JavaScript
;
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatCallTx = exports.normalizeGasLimit = exports.standardizeTransaction = exports.TransactionError = exports.OperationType = void 0;
const constants_1 = require("./constants");
const hexData_1 = require("./hexData");
var OperationType;
(function (OperationType) {
OperationType[OperationType["Call"] = 0] = "Call";
OperationType[OperationType["DelegateCall"] = 1] = "DelegateCall"; // 1
})(OperationType = exports.OperationType || (exports.OperationType = {}));
class TransactionError extends Error {
constructor(message, revertData, revertMessage) {
super(message);
this.revertData = revertData;
this.revertMessage = revertMessage;
}
}
exports.TransactionError = TransactionError;
function standardizeTransaction(tx) {
return {
operation: tx.operation ? tx.operation : constants_1.defaultTxOperation,
to: tx.to,
value: tx.value ? tx.value.toString() : constants_1.defaultTxValue.toString(),
data: tx.data ? tx.data : constants_1.defaultTxData
};
}
exports.standardizeTransaction = standardizeTransaction;
function normalizeGasLimit(options) {
const { gas, gasLimit } = options, rest = __rest(options, ["gas", "gasLimit"]);
if (gas != null && gasLimit != null) {
throw new Error(`specified both gas and gasLimit on options: ${options}`);
}
return Object.assign(Object.assign({}, rest), { gas: gas || gasLimit });
}
exports.normalizeGasLimit = normalizeGasLimit;
function formatCallTx(tx) {
const { from, to, value, data, gas } = normalizeGasLimit(tx);
return {
from,
to,
value: !value ? undefined : hexData_1.toHex(value),
data,
gas: !gas ? undefined : hexData_1.toHex(gas)
};
}
exports.formatCallTx = formatCallTx;
//# sourceMappingURL=transactions.js.map