From de28bdc314083cfe54f26cd8421594b73f05c563 Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Fri, 15 Sep 2023 10:02:46 +0100 Subject: [PATCH 1/7] smart-contracts - add Shibarium connection and migration --- smart-contracts/migrations/2_deploy.js | 14 ++++---------- smart-contracts/truffle-config.js | 21 ++++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/smart-contracts/migrations/2_deploy.js b/smart-contracts/migrations/2_deploy.js index aa27b6b..61bb064 100644 --- a/smart-contracts/migrations/2_deploy.js +++ b/smart-contracts/migrations/2_deploy.js @@ -31,16 +31,6 @@ module.exports = function (deployer, network) { ) }) break - case "rinkeby": - case "rinkeby-fork": - // Router - deployer.deploy(Router, "0x245330351344f9301690d5d8de2a07f5f32e1149") - break - case "goerli": - case "goerli-fork": - // Router - deployer.deploy(Router, "0xb07C72acF3D7A5E9dA28C56af6F93862f8cc8196") - break case "mainnet": case "mainnet-fork": // Router @@ -56,5 +46,9 @@ module.exports = function (deployer, network) { // Router deployer.deploy(Router, "0xb07C72acF3D7A5E9dA28C56af6F93862f8cc8196") break + case "shibarium": + case "shibarium-fork": + deployer.deploy(Router, "0x89dc93C6c12CaE47aCAf4aD9305d7A442C30dBB2") + break } } diff --git a/smart-contracts/truffle-config.js b/smart-contracts/truffle-config.js index 4436444..a667107 100644 --- a/smart-contracts/truffle-config.js +++ b/smart-contracts/truffle-config.js @@ -35,17 +35,6 @@ module.exports = { network_id: "*", defaultEtherBalance: 500, }, - goerli: { - provider: () => - new HDWalletProvider({ - privateKeys: [ETH_PKEY_TESTNET], - providerOrUrl: `https://goerli.infura.io/v3/${INFURA_PROJECT_ID}`, - }), - network_id: "5", - gas: 10000000, - gasPrice: 2000000000, - skipDryRun: true, - }, sepolia: { provider: () => new HDWalletProvider({ @@ -77,6 +66,16 @@ module.exports = { gasPrice: 40000000000, // 40 gwei skipDryRun: true, }, + shibarium: { + provider: () => + new HDWalletProvider({ + privateKeys: [ETH_PKEY_MAINNET], + providerOrUrl: 'https://rpc.shibrpc.com', + }), + network_id: "109", + gasPrice: 10000000000, // 10 gwei + skipDryRun: true, + }, ...customNetworks, }, From 3ed660749b608b030b9c5e1a22f6948ae98a6146 Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Fri, 15 Sep 2023 10:03:17 +0100 Subject: [PATCH 2/7] smart-contracts - update to latest OpenZeppelin contracts --- smart-contracts/package.json | 10 ++++++++-- smart-contracts/yarn.lock | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/smart-contracts/package.json b/smart-contracts/package.json index 2765162..ca5ad83 100644 --- a/smart-contracts/package.json +++ b/smart-contracts/package.json @@ -12,12 +12,18 @@ "info:abi:dev": "node scripts/export_abi.js", "info:abi:tn": "node scripts/export_abi.js -n sepolia", "info:abi:mn": "node scripts/export_abi.js -n mainnet", + "info:abi:shib": "node scripts/export_abi.js -n shibarium", + "info:abi:poly": "node scripts/export_abi.js -n polygon", "info:addr:dev": "node scripts/export_abi.js -w addr", "info:addr:tn": "node scripts/export_abi.js -w addr -n sepolia", "info:addr:mn": "node scripts/export_abi.js -w addr -n mainnet", + "info:addr:shib": "node scripts/export_abi.js -w addr -n shibarium", + "info:addr:poly": "node scripts/export_abi.js -w addr -n polygon", "info:dev": "yarn run info:abi:dev && yarn run info:addr:dev", "info:tn": "yarn run info:abi:tn && yarn run info:addr:tn", - "info:mn": "yarn run info:abi:mn && yarn run info:addr:mn" + "info:mn": "yarn run info:abi:mn && yarn run info:addr:mn", + "info:shib": "yarn run info:abi:shib && yarn run info:addr:shib", + "info:poly": "yarn run info:abi:poly && yarn run info:addr:poly" }, "repository": { "type": "git", @@ -30,7 +36,7 @@ }, "homepage": "https://github.com/unification-com/xfund-router#readme", "dependencies": { - "@openzeppelin/contracts": "^4.0.0", + "@openzeppelin/contracts": "^4.9.3", "@truffle/hdwallet-provider": "^1.2.0", "arg": "^5.0.0", "bn.js": "^5.1.3", diff --git a/smart-contracts/yarn.lock b/smart-contracts/yarn.lock index f7efb75..524ffd2 100644 --- a/smart-contracts/yarn.lock +++ b/smart-contracts/yarn.lock @@ -1759,10 +1759,10 @@ find-up "^4.1.0" fs-extra "^8.1.0" -"@openzeppelin/contracts@^4.0.0": - version "4.0.0" - resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.0.0.tgz#54d1de30911635020c383cb73b160b698e7ae179" - integrity sha512-UcIJl/vUVjTr3H1yYXZi7Sr2PlXzBEHVUJKOUlVyzyy0FI8oQCCy0Wx+BuK/fojdnmLeMvUk4KUvhKUybP+C7Q== +"@openzeppelin/contracts@^4.9.3": + version "4.9.3" + resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.3.tgz#00d7a8cf35a475b160b3f0293a6403c511099364" + integrity sha512-He3LieZ1pP2TNt5JbkPA4PNT9WC3gOTOlDcFGJW4Le4QKqwmiNJCRt44APfxMxvq7OugU/cqYuPcSBzOw38DAg== "@openzeppelin/test-environment@^0.1.8": version "0.1.9" From b735a68d2cb2dae92629270de7413e69b0a42a73 Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Fri, 15 Sep 2023 10:04:07 +0100 Subject: [PATCH 3/7] smart-contracts - regenerate flattened Router.sol for Shibarium verification on shibascan --- smart-contracts/flat/Router.sol | 905 ++++++++++++++++--- smart-contracts/scripts/export_abi.js | 8 +- smart-contracts/scripts/flatten_contracts.js | 4 - 3 files changed, 775 insertions(+), 142 deletions(-) diff --git a/smart-contracts/flat/Router.sol b/smart-contracts/flat/Router.sol index cfce394..e2d3378 100644 --- a/smart-contracts/flat/Router.sol +++ b/smart-contracts/flat/Router.sol @@ -2,11 +2,24 @@ pragma solidity ^0.8.0; - /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); + /** * @dev Returns the amount of tokens in existence. */ @@ -18,13 +31,13 @@ interface IERC20 { function balanceOf(address account) external view returns (uint256); /** - * @dev Moves `amount` tokens from the caller's account to `recipient`. + * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ - function transfer(address recipient, uint256 amount) external returns (bool); + function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be @@ -52,7 +65,7 @@ interface IERC20 { function approve(address spender, uint256 amount) external returns (bool); /** - * @dev Moves `amount` tokens from `sender` to `recipient` using the + * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * @@ -60,21 +73,7 @@ interface IERC20 { * * Emits a {Transfer} event. */ - function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); - - /** - * @dev Emitted when `value` tokens are moved from one account (`from`) to - * another (`to`). - * - * Note that `value` may be zero. - */ - event Transfer(address indexed from, address indexed to, uint256 value); - - /** - * @dev Emitted when the allowance of a `spender` for an `owner` is set by - * a call to {approve}. `value` is the new allowance. - */ - event Approval(address indexed owner, address indexed spender, uint256 value); + function transferFrom(address from, address to, uint256 amount) external returns (bool); } @@ -85,7 +84,7 @@ interface IERC20 { /** * @dev Wrappers over Solidity's arithmetic operations. * - * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler + * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMath { @@ -95,23 +94,23 @@ library SafeMath { * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { - unchecked { - uint256 c = a + b; - if (c < a) return (false, 0); - return (true, c); - } + unchecked { + uint256 c = a + b; + if (c < a) return (false, 0); + return (true, c); + } } /** - * @dev Returns the substraction of two unsigned integers, with an overflow flag. + * @dev Returns the subtraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { - unchecked { - if (b > a) return (false, 0); - return (true, a - b); - } + unchecked { + if (b > a) return (false, 0); + return (true, a - b); + } } /** @@ -120,15 +119,15 @@ library SafeMath { * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { - unchecked { + unchecked { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 - if (a == 0) return (true, 0); - uint256 c = a * b; - if (c / a != b) return (false, 0); - return (true, c); - } + if (a == 0) return (true, 0); + uint256 c = a * b; + if (c / a != b) return (false, 0); + return (true, c); + } } /** @@ -137,10 +136,10 @@ library SafeMath { * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { - unchecked { - if (b == 0) return (false, 0); - return (true, a / b); - } + unchecked { + if (b == 0) return (false, 0); + return (true, a / b); + } } /** @@ -149,10 +148,10 @@ library SafeMath { * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { - unchecked { - if (b == 0) return (false, 0); - return (true, a % b); - } + unchecked { + if (b == 0) return (false, 0); + return (true, a % b); + } } /** @@ -241,20 +240,16 @@ library SafeMath { * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { - unchecked { - require(b <= a, errorMessage); - return a - b; - } + unchecked { + require(b <= a, errorMessage); + return a - b; + } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * - * Counterpart to Solidity's `%` operator. This function uses a `revert` - * opcode (which leaves remaining gas untouched) while Solidity uses an - * invalid opcode to revert (consuming all remaining gas). - * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). @@ -264,10 +259,10 @@ library SafeMath { * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { - unchecked { - require(b > 0, errorMessage); - return a / b; - } + unchecked { + require(b > 0, errorMessage); + return a / b; + } } /** @@ -286,10 +281,10 @@ library SafeMath { * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { - unchecked { - require(b > 0, errorMessage); - return a % b; - } + unchecked { + require(b > 0, errorMessage); + return a % b; + } } } @@ -313,17 +308,27 @@ library Address { * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed + * + * Furthermore, `isContract` will also return true if the target contract within + * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, + * which only has an effect at the end of a transaction. + * ==== + * + * [IMPORTANT] + * ==== + * You shouldn't rely on `isContract` to protect against flash loan attacks! + * + * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets + * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract + * constructor. * ==== */ function isContract(address account) internal view returns (bool) { - // This method relies on extcodesize, which returns 0 for contracts in - // construction, since the code is only stored at the end of the - // constructor execution. + // This method relies on extcodesize/address.code.length, which returns 0 + // for contracts in construction, since the code is only stored at the end + // of the constructor execution. - uint256 size; - // solhint-disable-next-line no-inline-assembly - assembly { size := extcodesize(account) } - return size > 0; + return account.code.length > 0; } /** @@ -335,24 +340,23 @@ library Address { * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * - * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. + * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the - * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. + * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); - // solhint-disable-next-line avoid-low-level-calls, avoid-call-value - (bool success, ) = recipient.call{ value: amount }(""); + (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A - * plain`call` is an unsafe replacement for a function call: use this + * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this @@ -369,7 +373,7 @@ library Address { * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { - return functionCall(target, data, "Address: low-level call failed"); + return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** @@ -378,7 +382,11 @@ library Address { * * _Available since v3.1._ */ - function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { + function functionCall( + address target, + bytes memory data, + string memory errorMessage + ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } @@ -403,13 +411,15 @@ library Address { * * _Available since v3.1._ */ - function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { + function functionCallWithValue( + address target, + bytes memory data, + uint256 value, + string memory errorMessage + ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); - require(isContract(target), "Address: call to non-contract"); - - // solhint-disable-next-line avoid-low-level-calls - (bool success, bytes memory returndata) = target.call{ value: value }(data); - return _verifyCallResult(success, returndata, errorMessage); + (bool success, bytes memory returndata) = target.call{value: value}(data); + return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** @@ -428,12 +438,13 @@ library Address { * * _Available since v3.3._ */ - function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { - require(isContract(target), "Address: static call to non-contract"); - - // solhint-disable-next-line avoid-low-level-calls + function functionStaticCall( + address target, + bytes memory data, + string memory errorMessage + ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); - return _verifyCallResult(success, returndata, errorMessage); + return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** @@ -452,31 +463,525 @@ library Address { * * _Available since v3.4._ */ - function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { - require(isContract(target), "Address: delegate call to non-contract"); - - // solhint-disable-next-line avoid-low-level-calls + function functionDelegateCall( + address target, + bytes memory data, + string memory errorMessage + ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); - return _verifyCallResult(success, returndata, errorMessage); + return verifyCallResultFromTarget(target, success, returndata, errorMessage); } - function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { + /** + * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling + * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. + * + * _Available since v4.8._ + */ + function verifyCallResultFromTarget( + address target, + bool success, + bytes memory returndata, + string memory errorMessage + ) internal view returns (bytes memory) { + if (success) { + if (returndata.length == 0) { + // only check isContract if the call was successful and the return data is empty + // otherwise we already know that it was a contract + require(isContract(target), "Address: call to non-contract"); + } + return returndata; + } else { + _revert(returndata, errorMessage); + } + } + + /** + * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the + * revert reason or using the provided one. + * + * _Available since v4.3._ + */ + function verifyCallResult( + bool success, + bytes memory returndata, + string memory errorMessage + ) internal pure returns (bytes memory) { if (success) { return returndata; } else { - // Look for revert reason and bubble it up if present - if (returndata.length > 0) { - // The easiest way to bubble the revert reason is using memory via assembly + _revert(returndata, errorMessage); + } + } + + function _revert(bytes memory returndata, string memory errorMessage) private pure { + // Look for revert reason and bubble it up if present + if (returndata.length > 0) { + // The easiest way to bubble the revert reason is using memory via assembly + /// @solidity memory-safe-assembly + assembly { + let returndata_size := mload(returndata) + revert(add(32, returndata), returndata_size) + } + } else { + revert(errorMessage); + } + } +} + + +/** + * @dev Standard math utilities missing in the Solidity language. + */ +library Math { + enum Rounding { + Down, // Toward negative infinity + Up, // Toward infinity + Zero // Toward zero + } + + /** + * @dev Returns the largest of two numbers. + */ + function max(uint256 a, uint256 b) internal pure returns (uint256) { + return a > b ? a : b; + } + + /** + * @dev Returns the smallest of two numbers. + */ + function min(uint256 a, uint256 b) internal pure returns (uint256) { + return a < b ? a : b; + } + + /** + * @dev Returns the average of two numbers. The result is rounded towards + * zero. + */ + function average(uint256 a, uint256 b) internal pure returns (uint256) { + // (a + b) / 2 can overflow. + return (a & b) + (a ^ b) / 2; + } + + /** + * @dev Returns the ceiling of the division of two numbers. + * + * This differs from standard division with `/` in that it rounds up instead + * of rounding down. + */ + function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { + // (a + b - 1) / b can overflow on addition, so we distribute. + return a == 0 ? 0 : (a - 1) / b + 1; + } + + /** + * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 + * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) + * with further edits by Uniswap Labs also under MIT license. + */ + function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) { + unchecked { + // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use + // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 + // variables such that product = prod1 * 2^256 + prod0. + uint256 prod0; // Least significant 256 bits of the product + uint256 prod1; // Most significant 256 bits of the product + assembly { + let mm := mulmod(x, y, not(0)) + prod0 := mul(x, y) + prod1 := sub(sub(mm, prod0), lt(mm, prod0)) + } + + // Handle non-overflow cases, 256 by 256 division. + if (prod1 == 0) { + // Solidity will revert if denominator == 0, unlike the div opcode on its own. + // The surrounding unchecked block does not change this fact. + // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. + return prod0 / denominator; + } + + // Make sure the result is less than 2^256. Also prevents denominator == 0. + require(denominator > prod1, "Math: mulDiv overflow"); + + /////////////////////////////////////////////// + // 512 by 256 division. + /////////////////////////////////////////////// + + // Make division exact by subtracting the remainder from [prod1 prod0]. + uint256 remainder; + assembly { + // Compute remainder using mulmod. + remainder := mulmod(x, y, denominator) + + // Subtract 256 bit number from 512 bit number. + prod1 := sub(prod1, gt(remainder, prod0)) + prod0 := sub(prod0, remainder) + } + + // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. + // See https://cs.stackexchange.com/q/138556/92363. + + // Does not overflow because the denominator cannot be zero at this stage in the function. + uint256 twos = denominator & (~denominator + 1); + assembly { + // Divide denominator by twos. + denominator := div(denominator, twos) + + // Divide [prod1 prod0] by twos. + prod0 := div(prod0, twos) + + // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. + twos := add(div(sub(0, twos), twos), 1) + } + + // Shift in bits from prod1 into prod0. + prod0 |= prod1 * twos; + + // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such + // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for + // four bits. That is, denominator * inv = 1 mod 2^4. + uint256 inverse = (3 * denominator) ^ 2; + + // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works + // in modular arithmetic, doubling the correct bits in each step. + inverse *= 2 - denominator * inverse; // inverse mod 2^8 + inverse *= 2 - denominator * inverse; // inverse mod 2^16 + inverse *= 2 - denominator * inverse; // inverse mod 2^32 + inverse *= 2 - denominator * inverse; // inverse mod 2^64 + inverse *= 2 - denominator * inverse; // inverse mod 2^128 + inverse *= 2 - denominator * inverse; // inverse mod 2^256 + + // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. + // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is + // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 + // is no longer required. + result = prod0 * inverse; + return result; + } + } + + /** + * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. + */ + function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) { + uint256 result = mulDiv(x, y, denominator); + if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { + result += 1; + } + return result; + } + + /** + * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. + * + * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). + */ + function sqrt(uint256 a) internal pure returns (uint256) { + if (a == 0) { + return 0; + } + + // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. + // + // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have + // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. + // + // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` + // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` + // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` + // + // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. + uint256 result = 1 << (log2(a) >> 1); + + // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, + // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at + // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision + // into the expected uint128 result. + unchecked { + result = (result + a / result) >> 1; + result = (result + a / result) >> 1; + result = (result + a / result) >> 1; + result = (result + a / result) >> 1; + result = (result + a / result) >> 1; + result = (result + a / result) >> 1; + result = (result + a / result) >> 1; + return min(result, a / result); + } + } + + /** + * @notice Calculates sqrt(a), following the selected rounding direction. + */ + function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { + unchecked { + uint256 result = sqrt(a); + return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); + } + } + + /** + * @dev Return the log in base 2, rounded down, of a positive value. + * Returns 0 if given 0. + */ + function log2(uint256 value) internal pure returns (uint256) { + uint256 result = 0; + unchecked { + if (value >> 128 > 0) { + value >>= 128; + result += 128; + } + if (value >> 64 > 0) { + value >>= 64; + result += 64; + } + if (value >> 32 > 0) { + value >>= 32; + result += 32; + } + if (value >> 16 > 0) { + value >>= 16; + result += 16; + } + if (value >> 8 > 0) { + value >>= 8; + result += 8; + } + if (value >> 4 > 0) { + value >>= 4; + result += 4; + } + if (value >> 2 > 0) { + value >>= 2; + result += 2; + } + if (value >> 1 > 0) { + result += 1; + } + } + return result; + } + + /** + * @dev Return the log in base 2, following the selected rounding direction, of a positive value. + * Returns 0 if given 0. + */ + function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { + unchecked { + uint256 result = log2(value); + return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); + } + } + + /** + * @dev Return the log in base 10, rounded down, of a positive value. + * Returns 0 if given 0. + */ + function log10(uint256 value) internal pure returns (uint256) { + uint256 result = 0; + unchecked { + if (value >= 10 ** 64) { + value /= 10 ** 64; + result += 64; + } + if (value >= 10 ** 32) { + value /= 10 ** 32; + result += 32; + } + if (value >= 10 ** 16) { + value /= 10 ** 16; + result += 16; + } + if (value >= 10 ** 8) { + value /= 10 ** 8; + result += 8; + } + if (value >= 10 ** 4) { + value /= 10 ** 4; + result += 4; + } + if (value >= 10 ** 2) { + value /= 10 ** 2; + result += 2; + } + if (value >= 10 ** 1) { + result += 1; + } + } + return result; + } - // solhint-disable-next-line no-inline-assembly + /** + * @dev Return the log in base 10, following the selected rounding direction, of a positive value. + * Returns 0 if given 0. + */ + function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { + unchecked { + uint256 result = log10(value); + return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); + } + } + + /** + * @dev Return the log in base 256, rounded down, of a positive value. + * Returns 0 if given 0. + * + * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. + */ + function log256(uint256 value) internal pure returns (uint256) { + uint256 result = 0; + unchecked { + if (value >> 128 > 0) { + value >>= 128; + result += 16; + } + if (value >> 64 > 0) { + value >>= 64; + result += 8; + } + if (value >> 32 > 0) { + value >>= 32; + result += 4; + } + if (value >> 16 > 0) { + value >>= 16; + result += 2; + } + if (value >> 8 > 0) { + result += 1; + } + } + return result; + } + + /** + * @dev Return the log in base 256, following the selected rounding direction, of a positive value. + * Returns 0 if given 0. + */ + function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { + unchecked { + uint256 result = log256(value); + return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); + } + } +} + + + +/** + * @dev Standard signed math utilities missing in the Solidity language. + */ +library SignedMath { + /** + * @dev Returns the largest of two signed numbers. + */ + function max(int256 a, int256 b) internal pure returns (int256) { + return a > b ? a : b; + } + + /** + * @dev Returns the smallest of two signed numbers. + */ + function min(int256 a, int256 b) internal pure returns (int256) { + return a < b ? a : b; + } + + /** + * @dev Returns the average of two signed numbers without overflow. + * The result is rounded towards zero. + */ + function average(int256 a, int256 b) internal pure returns (int256) { + // Formula from the book "Hacker's Delight" + int256 x = (a & b) + ((a ^ b) >> 1); + return x + (int256(uint256(x) >> 255) & (a ^ b)); + } + + /** + * @dev Returns the absolute unsigned value of a signed value. + */ + function abs(int256 n) internal pure returns (uint256) { + unchecked { + // must be unchecked in order to support `n = type(int256).min` + return uint256(n >= 0 ? n : -n); + } + } +} + + +/** + * @dev String operations. + */ +library Strings { + bytes16 private constant _SYMBOLS = "0123456789abcdef"; + uint8 private constant _ADDRESS_LENGTH = 20; + + /** + * @dev Converts a `uint256` to its ASCII `string` decimal representation. + */ + function toString(uint256 value) internal pure returns (string memory) { + unchecked { + uint256 length = Math.log10(value) + 1; + string memory buffer = new string(length); + uint256 ptr; + /// @solidity memory-safe-assembly + assembly { + ptr := add(buffer, add(32, length)) + } + while (true) { + ptr--; + /// @solidity memory-safe-assembly assembly { - let returndata_size := mload(returndata) - revert(add(32, returndata), returndata_size) + mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } - } else { - revert(errorMessage); + value /= 10; + if (value == 0) break; } + return buffer; + } + } + + /** + * @dev Converts a `int256` to its ASCII `string` decimal representation. + */ + function toString(int256 value) internal pure returns (string memory) { + return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value)))); + } + + /** + * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. + */ + function toHexString(uint256 value) internal pure returns (string memory) { + unchecked { + return toHexString(value, Math.log256(value) + 1); + } + } + + /** + * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. + */ + function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { + bytes memory buffer = new bytes(2 * length + 2); + buffer[0] = "0"; + buffer[1] = "x"; + for (uint256 i = 2 * length + 1; i > 1; --i) { + buffer[i] = _SYMBOLS[value & 0xf]; + value >>= 4; } + require(value == 0, "Strings: hex length insufficient"); + return string(buffer); + } + + /** + * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. + */ + function toHexString(address addr) internal pure returns (string memory) { + return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); + } + + /** + * @dev Returns true if the two strings are equal. + */ + function equal(string memory a, string memory b) internal pure returns (bool) { + return keccak256(bytes(a)) == keccak256(bytes(b)); } } @@ -488,6 +993,65 @@ library Address { * of the private keys of a given address. */ library ECDSA { + enum RecoverError { + NoError, + InvalidSignature, + InvalidSignatureLength, + InvalidSignatureS, + InvalidSignatureV // Deprecated in v4.8 + } + + function _throwError(RecoverError error) private pure { + if (error == RecoverError.NoError) { + return; // no error: do nothing + } else if (error == RecoverError.InvalidSignature) { + revert("ECDSA: invalid signature"); + } else if (error == RecoverError.InvalidSignatureLength) { + revert("ECDSA: invalid signature length"); + } else if (error == RecoverError.InvalidSignatureS) { + revert("ECDSA: invalid signature 's' value"); + } + } + + /** + * @dev Returns the address that signed a hashed message (`hash`) with + * `signature` or error string. This address can then be used for verification purposes. + * + * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: + * this function rejects them by requiring the `s` value to be in the lower + * half order, and the `v` value to be either 27 or 28. + * + * IMPORTANT: `hash` _must_ be the result of a hash operation for the + * verification to be secure: it is possible to craft signatures that + * recover to arbitrary addresses for non-hashed data. A safe way to ensure + * this is by receiving a hash of the original message (which may otherwise + * be too long), and then calling {toEthSignedMessageHash} on it. + * + * Documentation for signature generation: + * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] + * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] + * + * _Available since v4.3._ + */ + function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) { + if (signature.length == 65) { + bytes32 r; + bytes32 s; + uint8 v; + // ecrecover takes the signature parameters, and the only way to get them + // currently is to use assembly. + /// @solidity memory-safe-assembly + assembly { + r := mload(add(signature, 0x20)) + s := mload(add(signature, 0x40)) + v := byte(0, mload(add(signature, 0x60))) + } + return tryRecover(hash, v, r, s); + } else { + return (address(0), RecoverError.InvalidSignatureLength); + } + } + /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. @@ -503,50 +1067,72 @@ library ECDSA { * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover(bytes32 hash, bytes memory signature) internal pure returns (address) { - // Check the signature length - if (signature.length != 65) { - revert("ECDSA: invalid signature length"); - } - - // Divide the signature in r, s and v variables - bytes32 r; - bytes32 s; - uint8 v; + (address recovered, RecoverError error) = tryRecover(hash, signature); + _throwError(error); + return recovered; + } - // ecrecover takes the signature parameters, and the only way to get them - // currently is to use assembly. - // solhint-disable-next-line no-inline-assembly - assembly { - r := mload(add(signature, 0x20)) - s := mload(add(signature, 0x40)) - v := byte(0, mload(add(signature, 0x60))) - } + /** + * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. + * + * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] + * + * _Available since v4.3._ + */ + function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) { + bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff); + uint8 v = uint8((uint256(vs) >> 255) + 27); + return tryRecover(hash, v, r, s); + } - return recover(hash, v, r, s); + /** + * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. + * + * _Available since v4.2._ + */ + function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) { + (address recovered, RecoverError error) = tryRecover(hash, r, vs); + _throwError(error); + return recovered; } /** - * @dev Overload of {ECDSA-recover} that receives the `v`, + * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. + * + * _Available since v4.3._ */ - function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) { + function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines - // the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most + // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. - require(uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0, "ECDSA: invalid signature 's' value"); - require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value"); + if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) { + return (address(0), RecoverError.InvalidSignatureS); + } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); - require(signer != address(0), "ECDSA: invalid signature"); + if (signer == address(0)) { + return (address(0), RecoverError.InvalidSignature); + } + + return (signer, RecoverError.NoError); + } - return signer; + /** + * @dev Overload of {ECDSA-recover} that receives the `v`, + * `r` and `s` signature fields separately. + */ + function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) { + (address recovered, RecoverError error) = tryRecover(hash, v, r, s); + _throwError(error); + return recovered; } /** @@ -557,10 +1143,27 @@ library ECDSA { * * See {recover}. */ - function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) { + function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) { // 32 is the length in bytes of hash, // enforced by the type signature above - return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)); + /// @solidity memory-safe-assembly + assembly { + mstore(0x00, "\x19Ethereum Signed Message:\n32") + mstore(0x1c, hash) + message := keccak256(0x00, 0x3c) + } + } + + /** + * @dev Returns an Ethereum Signed Message, created from `s`. This + * produces hash corresponding to the one signed with the + * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] + * JSON-RPC method as part of EIP-191. + * + * See {recover}. + */ + function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) { + return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s)); } /** @@ -572,8 +1175,25 @@ library ECDSA { * * See {recover}. */ - function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) { - return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); + function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) { + /// @solidity memory-safe-assembly + assembly { + let ptr := mload(0x40) + mstore(ptr, "\x19\x01") + mstore(add(ptr, 0x02), domainSeparator) + mstore(add(ptr, 0x22), structHash) + data := keccak256(ptr, 0x42) + } + } + + /** + * @dev Returns an Ethereum Signed Data with intended validator, created from a + * `validator` and `data` according to the version 0 of EIP-191. + * + * See {recover}. + */ + function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) { + return keccak256(abi.encodePacked("\x19\x00", validator, data)); } } @@ -611,7 +1231,7 @@ abstract contract ReentrancyGuard { uint256 private _status; - constructor () { + constructor() { _status = _NOT_ENTERED; } @@ -619,30 +1239,44 @@ abstract contract ReentrancyGuard { * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening - * by making the `nonReentrant` function external, and make it call a + * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { - // On the first call to nonReentrant, _notEntered will be true + _nonReentrantBefore(); + _; + _nonReentrantAfter(); + } + + function _nonReentrantBefore() private { + // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; + } - _; - + function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } + + /** + * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a + * `nonReentrant` function in the call stack. + */ + function _reentrancyGuardEntered() internal view returns (bool) { + return _status == _ENTERED; + } } + interface IConsumerBase { function rawReceiveData(uint256 _price, bytes32 _requestId) external; } - /** * @title RequestIdBase * @@ -673,7 +1307,6 @@ contract RequestIdBase { } - /** * @title Router smart contract * @@ -944,7 +1577,7 @@ contract Router is RequestIdBase, ReentrancyGuard { // msg.sender is the address of the data provider require(msg.sender == provider && msg.sender == recoveredProvider && - recoveredProvider == provider, + recoveredProvider == provider, "ECDSA.recover mismatch - correct provider and data?" ); diff --git a/smart-contracts/scripts/export_abi.js b/smart-contracts/scripts/export_abi.js index 2d18935..0b06686 100644 --- a/smart-contracts/scripts/export_abi.js +++ b/smart-contracts/scripts/export_abi.js @@ -24,6 +24,10 @@ const getNetwork = (network) => { return 5777 case "mainnet": return 1 + case "shibarium": + return 109 + case "polygon": + return 137 } } @@ -46,9 +50,9 @@ const getAbiAndAddressForEnv = (contract, network) => { const getDeployedAddresses = (network) => { const networkId = getNetwork(network) const contracts = [ - "xFUNDTestnet", + // "xFUNDTestnet", "Router", - "ConsumerLib", + // "ConsumerLib", ] console.log(`Network: ${network} (${networkId})`) for(let i = 0; i < contracts.length; i += 1) { diff --git a/smart-contracts/scripts/flatten_contracts.js b/smart-contracts/scripts/flatten_contracts.js index fab8ed5..07eee6e 100644 --- a/smart-contracts/scripts/flatten_contracts.js +++ b/smart-contracts/scripts/flatten_contracts.js @@ -6,10 +6,6 @@ const contractsToFlatten = [ path: "contracts", fileName: "Router.sol", }, - { - path: "contracts/dev", - fileName: "BlockhashStore.sol", - }, { path: "contracts/mocks", fileName: "xFUNDTestnet.sol", From 1c220690c77ebf4b9695d45832b4f17f0e927d1b Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Fri, 15 Sep 2023 10:04:40 +0100 Subject: [PATCH 4/7] smart-contracts -update unit tests for updated OZ contracts --- smart-contracts/test/04_data_request.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smart-contracts/test/04_data_request.test.js b/smart-contracts/test/04_data_request.test.js index 4d891f0..c01a6ce 100644 --- a/smart-contracts/test/04_data_request.test.js +++ b/smart-contracts/test/04_data_request.test.js @@ -257,6 +257,7 @@ contract("Router - data request tests", (accounts) => { it("initialiseRequest - insufficient xFUND balance", async function () { // register provider on router await this.RouterContract.registerAsProvider(defaultFee, { from: dataProvider }) + await this.MockConsumerContract.increaseRouterAllowance(defaultFee, { from: dataConsumerOwner }) await expectRevert( this.MockConsumerContract.getData(dataProvider, defaultFee, endpoint, { from: dataConsumerOwner }), "ERC20: transfer amount exceeds balance", @@ -270,7 +271,7 @@ contract("Router - data request tests", (accounts) => { await this.xFUNDTestnetContract.transfer(this.MockConsumerContract.address, defaultFee, { from: admin }) await expectRevert( this.MockConsumerContract.getData(dataProvider, defaultFee, endpoint, { from: dataConsumerOwner }), - "ERC20: transfer amount exceeds allowance", + "ERC20: insufficient allowance.", ) }) }) From 598aff1bec2f4bb16d8b035d68754dfe504aacd8 Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Fri, 15 Sep 2023 10:04:57 +0100 Subject: [PATCH 5/7] go-ooo - add init method for Shibarium --- go-ooo/cmd/root.go | 8 +------- go-ooo/config/config.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/go-ooo/cmd/root.go b/go-ooo/cmd/root.go index a2cb80b..8d0b510 100644 --- a/go-ooo/cmd/root.go +++ b/go-ooo/cmd/root.go @@ -13,13 +13,7 @@ var keystorePass string // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ Use: "app", - Short: "A brief description of your application", - Long: `A longer description that spans multiple lines and likely contains -examples and usage of using your application. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Short: "OoO Provider Application", PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { return server.InterceptConfigsPreRunHandler(cmd) }, diff --git a/go-ooo/config/config.go b/go-ooo/config/config.go index cc33b88..35a0df1 100644 --- a/go-ooo/config/config.go +++ b/go-ooo/config/config.go @@ -145,6 +145,9 @@ func (c *Config) InitForNet(network string) { case "dev": c.InitForDevNet() break + case "shibarium": + c.InitForShibarium() + break default: c.InitForDevNet() break @@ -192,6 +195,14 @@ func (c *Config) InitForPolygon() { c.Chain.FirstBlock = 24460663 } +func (c *Config) InitForShibarium() { + c.Chain.ContractAddress = "0x2E9ade949900e19735689686E61BF6338a65B881" + c.Chain.EthHttpHost = "" + c.Chain.EthWsHost = "" + c.Chain.NetworkId = 109 + c.Chain.FirstBlock = 591096 +} + func (c *Config) SetKeystore(path, account string) { c.Keystore.File = path c.Keystore.Account = account From 612e36cc4cdb91b70220e3c751fecef9e789922f Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Fri, 15 Sep 2023 10:05:49 +0100 Subject: [PATCH 6/7] docker - fix topic idx --- docker/assets/request-data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/assets/request-data.js b/docker/assets/request-data.js index 8da2148..d4da109 100644 --- a/docker/assets/request-data.js +++ b/docker/assets/request-data.js @@ -60,7 +60,7 @@ module.exports = async function (callback) { console.log("requesting", data) receipt = await demoConsumer.requestData(endpoint, pair, { from: consumerOwner }) console.log("tx hash", receipt.tx) - const requestId = receipt.receipt.rawLogs[2].topics[3] + const requestId = receipt.receipt.rawLogs[1].topics[3] console.log("requestId", requestId) console.log("waiting for fulfilment. This may take 3 - 4 blocks.") From 158e23d6f881f35081b80685e7ddbf8d7ee917d9 Mon Sep 17 00:00:00 2001 From: Codegnosis Date: Fri, 15 Sep 2023 10:06:15 +0100 Subject: [PATCH 7/7] makefile - fix abigen target --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0df8ea2..1048dd8 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ #!/usr/bin/make -f abigen: - npx truffle run abigen - abigen --abi smart-contracrts/abigenBindings/abi/Router.abi --pkg ooo_router --out go-ooo/ooo_router/ooo_router.go + cd smart-contracts && npx truffle run abigen + abigen --abi smart-contracts/abigenBindings/abi/Router.abi --pkg ooo_router --out go-ooo/ooo_router/ooo_router.go # Dev environment dev-env: