Skip to content

Commit

Permalink
add native token hash on the constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
vrolland committed Sep 29, 2021
1 parent 7cc050a commit 4593ade
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
Expand Up @@ -72,6 +72,7 @@ export default async function deploy(args: any, hre: HardhatRuntimeEnvironment)
...args,
chainlinkConversionPathAddress: conversionPathInstance.address,
ethFeeProxyAddress: '0x3d49d1eF2adE060a33c6E6Aa213513A7EE9a6241',
nativeTokenHash: ETH_address,
},
hre,
);
Expand Down
8 changes: 7 additions & 1 deletion packages/smart-contracts/scripts/eth-conversion-proxy.ts
Expand Up @@ -2,7 +2,7 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { deployOne } from './deploy-one';

export default async function deploy(
args: { chainlinkConversionPathAddress?: string; ethFeeProxyAddress?: string },
args: { chainlinkConversionPathAddress?: string; ethFeeProxyAddress?: string, nativeTokenHash?: string },
hre: HardhatRuntimeEnvironment,
) {
const contractName = 'EthConversionProxy';
Expand All @@ -20,8 +20,14 @@ export default async function deploy(
return;
}

if (!args.nativeTokenHash) {
console.error(`Missing nativeTokenHash on ${hre.network.name}, cannot deploy ${contractName}.`);
return;
}

return deployOne(args, hre, contractName, [
args.ethFeeProxyAddress,
args.chainlinkConversionPathAddress,
args.nativeTokenHash,
]);
}
11 changes: 6 additions & 5 deletions packages/smart-contracts/src/contracts/EthConversionProxy.sol
Expand Up @@ -14,10 +14,12 @@ import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract EthConversionProxy is ReentrancyGuard {
address public paymentProxy;
ChainlinkConversionPath public chainlinkConversionPath;
address public nativeTokenHash;

constructor(address _paymentProxyAddress, address _chainlinkConversionPathAddress) {
constructor(address _paymentProxyAddress, address _chainlinkConversionPathAddress, address _nativeTokenHash) {
paymentProxy = _paymentProxyAddress;
chainlinkConversionPath = ChainlinkConversionPath(_chainlinkConversionPathAddress);
nativeTokenHash = _nativeTokenHash;
}

// Event to declare a conversion with a reference
Expand Down Expand Up @@ -60,10 +62,9 @@ contract EthConversionProxy is ReentrancyGuard {
external
payable
{
// Request currency hash for ether: 0xF5AF88e117747e87fC5929F2ff87221B1447652E
require(
_path[_path.length - 1] == address(0xF5AF88e117747e87fC5929F2ff87221B1447652E),
"payment currency must be ethers"
_path[_path.length - 1] == nativeTokenHash,
"payment currency must be the native token"
);

(uint256 amountToPay, uint256 amountToPayInFees) = getConversions(
Expand Down Expand Up @@ -115,7 +116,7 @@ contract EthConversionProxy is ReentrancyGuard {
"aggregator rate is outdated"
);

// Get the amount to pay in the crypto currency chosen
// Get the amount to pay in the native token
amountToPay = (_requestAmount * rate) / decimals;
amountToPayInFees = (_feeAmount * rate) /decimals;
}
Expand Down
Expand Up @@ -11,6 +11,11 @@
"internalType": "address",
"name": "_chainlinkConversionPathAddress",
"type": "address"
},
{
"internalType": "address",
"name": "_nativeTokenHash",
"type": "address"
}
],
"stateMutability": "nonpayable",
Expand Down Expand Up @@ -103,6 +108,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "nativeTokenHash",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "paymentProxy",
Expand Down
Expand Up @@ -43,6 +43,7 @@ describe('contract: EthConversionProxy', () => {
testEthConversionProxy = await new EthConversionProxy__factory(signer).deploy(
ethFeeProxy.address,
chainlinkPath.address,
ETH_address,
);
});

Expand Down

0 comments on commit 4593ade

Please sign in to comment.