Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const methodsData = _.map(methodAbis, (methodAbi, methodAbiIndex: number) => {
_.forEach(methodAbi.inputs, (input, inputIndex: number) => {
if (_.isEmpty(input.name)) {
// Auto-generated getters don't have parameter names
input.name = `index_${inputIndex}`;
}
});
const functionSignature = new AbiEncoder.Method(methodAbi).getSignature();
const languageSpecificName: string = makeLanguageSpecificName(sanitizedMethodAbis[methodAbiIndex].name);
// This will make templates simpler
const methodData = {
...methodAbi,
singleReturnValue: methodAbi.outputs.length === 1,
hasReturnValue: methodAbi.outputs.length !== 0,
languageSpecificName,
functionSignature,
devdoc: devdoc ? devdoc.methods[functionSignature] : undefined,
};
return methodData;
});
const methodAbi = _.find(this.abi, (abiDefinition: AbiDefinition) => {
if (abiDefinition.type !== AbiType.Function) {
return false;
}
// tslint:disable-next-line:no-unnecessary-type-assertion
const abiFunctionSignature = new AbiEncoder.Method(abiDefinition as MethodAbi).getSignature();
if (abiFunctionSignature === functionSignature) {
return true;
}
return false;
}) as MethodAbi;
return methodAbi;
public async getCalldataOrThrowAsync(
quote: SwapQuote,
opts: Partial = {},
): Promise {
assert.isValidForwarderSwapQuote('quote', quote, this._getEtherTokenAssetDataOrThrow());
const { toAddress, methodAbi, ethAmount, params } = await this.getSmartContractParamsOrThrowAsync(quote, opts);
const abiEncoder = new AbiEncoder.Method(methodAbi);
const { orders, signatures, feePercentage, feeRecipient } = params;
let args: any[];
if (params.type === MarketOperation.Buy) {
const { makerAssetFillAmount } = params;
args = [orders, makerAssetFillAmount, signatures, feePercentage, feeRecipient];
} else {
args = [orders, signatures, feePercentage, feeRecipient];
}
const calldataHexString = abiEncoder.encode(args, { shouldOptimize: true });
return {
calldataHexString,
methodAbi,
toAddress,
ethAmount,
};
_.each(methodAbis, methodAbi => {
const abiEncoder = new AbiEncoder.Method(methodAbi);
const functionSignature = abiEncoder.getSignature();
this._abiEncoderByFunctionSignature[functionSignature] = abiEncoder;
});
}
public async getCalldataOrThrowAsync(
quote: SwapQuote,
opts: Partial,
): Promise {
assert.isValidSwapQuote('quote', quote);
const { toAddress, methodAbi, ethAmount, params } = await this.getSmartContractParamsOrThrowAsync(quote, opts);
const abiEncoder = new AbiEncoder.Method(methodAbi);
const { orders, signatures } = params;
let args: any[];
if (params.type === MarketOperation.Buy) {
const { makerAssetFillAmount } = params;
args = [orders, makerAssetFillAmount, signatures];
} else {
const { takerAssetFillAmount } = params;
args = [orders, takerAssetFillAmount, signatures];
}
const calldataHexString = abiEncoder.encode(args, { shouldOptimize: true });
return {
calldataHexString,
methodAbi,
toAddress,
ethAmount,
public async getCalldataOrThrowAsync(
quote: SwapQuote,
opts: Partial,
): Promise {
assert.isValidSwapQuote('quote', quote);
const { to, methodAbi, ethAmount, params } = await this.getSmartContractParamsOrThrowAsync(quote, opts);
const abiEncoder = new AbiEncoder.Method(methodAbi);
const { orders, signatures } = params;
let args: any[];
if (params.type === 'marketBuy') {
const { makerAssetFillAmount } = params;
args = [orders, makerAssetFillAmount, signatures];
} else {
const { takerAssetFillAmount } = params;
args = [orders, takerAssetFillAmount, signatures];
}
const calldataHexString = abiEncoder.encode(args);
return {
calldataHexString,
methodAbi,
to,
ethAmount,