Replace COA.call with COA.callWithSigAndArgs for reduced computation cost#150
Replace COA.call with COA.callWithSigAndArgs for reduced computation cost#150
COA.call with COA.callWithSigAndArgs for reduced computation cost#150Conversation
d5edfcc to
e5ea029
Compare
| 120_000 | ||
| to: self.factoryAddress, | ||
| signature: "getPool(address,address,uint24)", | ||
| args: [tokenA, tokenB, UInt256(fee)], |
There was a problem hiding this comment.
fee is of type UInt32, not sure why it is being casted to UInt256.
The Solidity function expects a uint24, as can be seen from the signature: getPool(address,address,uint24). Cadence doesn't have an equivalent of UInt24, but I suppose that a UInt32 would work just fine.
| message: "unable to get pool: tokenA \(tokenA.toString()), tokenB \(tokenB.toString()), fee: \(fee)" | ||
| ) | ||
|
|
||
| // ABI return is one 32-byte word; the last 20 bytes are the address |
There was a problem hiding this comment.
It is more efficient to use the ABI-decoded result from coa.dryCallWithSigAndArgs, than to do word manipulation in Cadence, on-chain.
e5ea029 to
155943f
Compare
| let s0Res = self._dryCallRaw( | ||
| // slot0() returns (uint160 sqrtPriceX96, int24, uint16, uint16, uint16, uint8, bool) | ||
| let types = [ | ||
| Type<UInt>(), Type<Int32>(), Type<UInt16>(), Type<UInt16>(), Type<UInt16>(), Type<UInt8>(), Type<Bool>() |
There was a problem hiding this comment.
UInt should be large enough to hold a uint160 Solidity value.
Int32 should also be large enough to hold a int24 Solidity value.
| )! | ||
| assert(res.status == EVM.Status.successful, message: "token0() call failed") | ||
|
|
||
| let word = res.data |
There was a problem hiding this comment.
It is more efficient to use the ABI-decoded result from coa.dryCallWithSigAndArgs, than to do word manipulation in Cadence, on-chain.
155943f to
f278020
Compare
joshuahannan
left a comment
There was a problem hiding this comment.
Looks okay to me, but I'm not very familiar with these contracts, so someone else should give a review too
Related: onflow/flow-go#8401
Closes: #149
Description
Previously, to perform contract calls using a COA, it was necessary to produce the
callDataon Cadence side:To be able to ABI-decode the returned data from the COA call, another step was needed:
After doing some profiling on Cadence transactions, the computation cost of ABI encoding/decoding, amounted to about 15%-20% of the total computation, which is not trivial.
To optimize this case, we have a new wrapper function,
callWithSigAndArgs, which does all this more efficiently:We do the same for
dryCall, by replacing it withdryCallWithSigAndArgs.NOTE: CI is failing because we still need to deploy the
EVMsystem contract on testnet/mainnet, for these new functions to be available.