-
Notifications
You must be signed in to change notification settings - Fork 91
feat: Payment network any-to-eth in the smartcontracts #602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
60a9284
add advanced logic and specs for any to eth
vrolland 659a4ff
Merge branch 'master' into any-to-eth-adv-logic
vrolland 558978a
add types
vrolland d19acc5
gather chainlink supported currencies
vrolland 0301e1d
add tests
vrolland b32ecdf
feat: Payment netwrok any-to-eth smartcontracts
vrolland 2cba701
fix from YMA review
vrolland 5adabec
from YMA review 2
vrolland 7cc050a
Merge branch 'any-to-eth-adv-logic' into any-to-eth-smartcontracts
vrolland 4593ade
add native token hash on the constructor
vrolland 91df39e
Merge branch 'master' into any-to-eth-adv-logic
vrolland 577a48f
Update packages/advanced-logic/specs/payment-network-any-to-eth-proxy…
vrolland dfd5fe2
rename chainlink to conversion
vrolland b9b41a5
remove defult network
vrolland ba44ed2
network mandatory
vrolland 8a3e862
fix import
vrolland a52fbad
fix commit
vrolland 8976c58
Merge branch 'any-to-eth-adv-logic' into any-to-eth-smartcontracts
vrolland cf163d8
Merge branch 'master' into any-to-eth-adv-logic
vrolland caeae86
rename test var
vrolland 68325a2
Merge branch 'master' into any-to-eth-adv-logic
vrolland af3961e
from BJU revieuw
vrolland b663f56
Merge branch 'any-to-eth-adv-logic' into any-to-eth-smartcontracts
vrolland 9035394
Merge branch 'master' into any-to-eth-smartcontracts
vrolland 433fc62
Merge branch 'master' into any-to-eth-smartcontracts
vrolland ebb5208
Update packages/smart-contracts/src/contracts/EthConversionProxy.sol
vrolland c5ee3a2
from BLE review
vrolland 75a6561
add comment
vrolland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { HardhatRuntimeEnvironment } from 'hardhat/types'; | ||
| import { deployOne } from './deploy-one'; | ||
|
|
||
| export default async function deploy( | ||
| args: { chainlinkConversionPathAddress?: string; ethFeeProxyAddress?: string, nativeTokenHash?: string }, | ||
| hre: HardhatRuntimeEnvironment, | ||
| ) { | ||
| const contractName = 'EthConversionProxy'; | ||
|
|
||
| if (!args.chainlinkConversionPathAddress) { | ||
| // FIXME: should try to retrieve information from artifacts instead | ||
| console.error( | ||
| `Missing ChainlinkConversionPath on ${hre.network.name}, cannot deploy ${contractName}.`, | ||
| ); | ||
| return; | ||
| } | ||
| if (!args.ethFeeProxyAddress) { | ||
| // FIXME: should try to retrieve information from artifacts instead | ||
| console.error(`Missing EthereumFeeProxy on ${hre.network.name}, cannot deploy ${contractName}.`); | ||
| 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, | ||
| ]); | ||
| } |
124 changes: 124 additions & 0 deletions
124
packages/smart-contracts/src/contracts/EthConversionProxy.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import "./ChainlinkConversionPath.sol"; | ||
| import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; | ||
|
|
||
| /** | ||
| * @title EthConversionProxy | ||
| * @notice This contract converts from chainlink then swaps ETH (or native token) | ||
| * before paying a request thanks to a conversion payment proxy. | ||
| * The inheritance from ReentrancyGuard is required to perform | ||
| * "transferExactEthWithReferenceAndFee" on the eth-fee-proxy contract | ||
| */ | ||
| contract EthConversionProxy is ReentrancyGuard { | ||
| address public paymentProxy; | ||
| ChainlinkConversionPath public chainlinkConversionPath; | ||
| address public nativeTokenHash; | ||
|
|
||
| constructor(address _paymentProxyAddress, address _chainlinkConversionPathAddress, address _nativeTokenHash) { | ||
| paymentProxy = _paymentProxyAddress; | ||
| chainlinkConversionPath = ChainlinkConversionPath(_chainlinkConversionPathAddress); | ||
| nativeTokenHash = _nativeTokenHash; | ||
| } | ||
|
|
||
| // Event to declare a conversion with a reference | ||
| event TransferWithConversionAndReference( | ||
| uint256 amount, | ||
| address currency, | ||
| bytes indexed paymentReference, | ||
| uint256 feeAmount, | ||
| uint256 maxRateTimespan | ||
| ); | ||
|
|
||
| // Event to declare a transfer with a reference | ||
| // This event is emitted by this contract from a delegate call of the payment-proxy | ||
| event TransferWithReferenceAndFee( | ||
| address to, | ||
| uint256 amount, | ||
| bytes indexed paymentReference, | ||
| uint256 feeAmount, | ||
| address feeAddress | ||
| ); | ||
|
|
||
| /** | ||
| * @notice Performs an ETH transfer with a reference computing the payment amount based on the request amount | ||
| * @param _to Transfer recipient of the payement | ||
| * @param _requestAmount Request amount | ||
| * @param _path Conversion path | ||
| * @param _paymentReference Reference of the payment related | ||
| * @param _feeAmount The amount of the payment fee | ||
| * @param _feeAddress The fee recipient | ||
| * @param _maxRateTimespan Max time span with the oldestrate, ignored if zero | ||
| */ | ||
| function transferWithReferenceAndFee( | ||
vrolland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| address _to, | ||
| uint256 _requestAmount, | ||
| address[] calldata _path, | ||
| bytes calldata _paymentReference, | ||
| uint256 _feeAmount, | ||
| address _feeAddress, | ||
| uint256 _maxRateTimespan | ||
| ) | ||
| external | ||
| payable | ||
| { | ||
| require( | ||
| _path[_path.length - 1] == nativeTokenHash, | ||
benjlevesque marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "payment currency must be the native token" | ||
| ); | ||
|
|
||
| (uint256 amountToPay, uint256 amountToPayInFees) = getConversions( | ||
| _path, | ||
| _requestAmount, | ||
| _feeAmount, | ||
| _maxRateTimespan); | ||
|
|
||
| // Pay the request and fees | ||
| (bool status, ) = paymentProxy.delegatecall( | ||
| abi.encodeWithSignature( | ||
| "transferExactEthWithReferenceAndFee(address,uint256,bytes,uint256,address)", | ||
| _to, | ||
| amountToPay, | ||
| _paymentReference, | ||
| amountToPayInFees, | ||
| _feeAddress | ||
| ) | ||
| ); | ||
|
|
||
| require(status, "paymentProxy transferExactEthWithReferenceAndFee failed"); | ||
|
|
||
| // Event to declare a transfer with a reference | ||
| emit TransferWithConversionAndReference( | ||
| _requestAmount, | ||
| // request currency | ||
| _path[0], | ||
| _paymentReference, | ||
| _feeAmount, | ||
| _maxRateTimespan | ||
| ); | ||
| } | ||
|
|
||
| function getConversions( | ||
| address[] memory _path, | ||
| uint256 _requestAmount, | ||
| uint256 _feeAmount, | ||
| uint256 _maxRateTimespan | ||
| ) | ||
| internal | ||
| view | ||
| returns (uint256 amountToPay, uint256 amountToPayInFees) | ||
| { | ||
| (uint256 rate, uint256 oldestTimestampRate, uint256 decimals) = chainlinkConversionPath.getRate(_path); | ||
|
|
||
| // Check rate timespan | ||
| require( | ||
| _maxRateTimespan == 0 || block.timestamp - oldestTimestampRate <= _maxRateTimespan, | ||
| "aggregator rate is outdated" | ||
| ); | ||
|
|
||
| // Get the amount to pay in the native token | ||
| amountToPay = (_requestAmount * rate) / decimals; | ||
| amountToPayInFees = (_feeAmount * rate) /decimals; | ||
| } | ||
| } | ||
181 changes: 181 additions & 0 deletions
181
packages/smart-contracts/src/lib/artifacts/EthConversionProxy/0.1.0.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| { | ||
| "abi": [ | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "_paymentProxyAddress", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "address", | ||
| "name": "_chainlinkConversionPathAddress", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "address", | ||
| "name": "_nativeTokenHash", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "stateMutability": "nonpayable", | ||
| "type": "constructor" | ||
| }, | ||
| { | ||
| "anonymous": false, | ||
| "inputs": [ | ||
| { | ||
| "indexed": false, | ||
| "internalType": "uint256", | ||
| "name": "amount", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "address", | ||
| "name": "currency", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "indexed": true, | ||
| "internalType": "bytes", | ||
| "name": "paymentReference", | ||
| "type": "bytes" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "uint256", | ||
| "name": "feeAmount", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "uint256", | ||
| "name": "maxRateTimespan", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "name": "TransferWithConversionAndReference", | ||
| "type": "event" | ||
| }, | ||
| { | ||
| "anonymous": false, | ||
| "inputs": [ | ||
| { | ||
| "indexed": false, | ||
| "internalType": "address", | ||
| "name": "to", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "uint256", | ||
| "name": "amount", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "indexed": true, | ||
| "internalType": "bytes", | ||
| "name": "paymentReference", | ||
| "type": "bytes" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "uint256", | ||
| "name": "feeAmount", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "indexed": false, | ||
| "internalType": "address", | ||
| "name": "feeAddress", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "name": "TransferWithReferenceAndFee", | ||
| "type": "event" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "chainlinkConversionPath", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "contract ChainlinkConversionPath", | ||
| "name": "", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "nativeTokenHash", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [], | ||
| "name": "paymentProxy", | ||
| "outputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "", | ||
| "type": "address" | ||
| } | ||
| ], | ||
| "stateMutability": "view", | ||
| "type": "function" | ||
| }, | ||
| { | ||
| "inputs": [ | ||
| { | ||
| "internalType": "address", | ||
| "name": "_to", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "_requestAmount", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "internalType": "address[]", | ||
| "name": "_path", | ||
| "type": "address[]" | ||
| }, | ||
| { | ||
| "internalType": "bytes", | ||
| "name": "_paymentReference", | ||
| "type": "bytes" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "_feeAmount", | ||
| "type": "uint256" | ||
| }, | ||
| { | ||
| "internalType": "address", | ||
| "name": "_feeAddress", | ||
| "type": "address" | ||
| }, | ||
| { | ||
| "internalType": "uint256", | ||
| "name": "_maxRateTimespan", | ||
| "type": "uint256" | ||
| } | ||
| ], | ||
| "name": "transferWithReferenceAndFee", | ||
| "outputs": [], | ||
| "stateMutability": "payable", | ||
| "type": "function" | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.