dp-contract-proxy-kit
Version:
Enable batched transactions and contract account interactions using a unique deterministic Gnosis Safe.
39 lines • 1.57 kB
JavaScript
import { joinHexData } from '../utils/hexData';
class EthLibAdapter {
abiEncodePacked(...params) {
return joinHexData(params.map(({ type, value }) => {
const encoded = this.abiEncode([type], [value]);
if (type === 'bytes' || type === 'string') {
const bytesLength = parseInt(encoded.slice(66, 130), 16);
return encoded.slice(130, 130 + 2 * bytesLength);
}
let typeMatch = type.match(/^(?:u?int\d*|bytes\d+|address)\[\]$/);
if (typeMatch) {
return encoded.slice(130);
}
if (type.startsWith('bytes')) {
const bytesLength = parseInt(type.slice(5));
return encoded.slice(2, 2 + 2 * bytesLength);
}
typeMatch = type.match(/^u?int(\d*)$/);
if (typeMatch) {
if (typeMatch[1] !== '') {
const bytesLength = parseInt(typeMatch[1]) / 8;
return encoded.slice(-2 * bytesLength);
}
return encoded.slice(-64);
}
if (type === 'address') {
return encoded.slice(-40);
}
throw new Error(`unsupported type ${type}`);
}));
}
decodeError(revertData) {
if (!revertData.startsWith('0x08c379a0'))
throw new Error('Unrecognized error format');
return this.abiDecode(['string'], `0x${revertData.slice(10)}`)[0];
}
}
export default EthLibAdapter;
//# sourceMappingURL=EthLibAdapter.js.map