This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Near field communication payment #13
Open
quThinh
wants to merge
1
commit into
klaytn:main
Choose a base branch
from
quThinh:NFC-Payment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 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,19 @@ | ||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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,57 @@ | ||
# Viction NFC Payment | ||
Indexer and Core Settlement for Payment System | ||
|
||
## NFC Payment Architecture | ||
![Alt text](public/architecture.jpg) | ||
|
||
NFC Payment leverages Near-Field Communications (NFC) and Account Abstraction to create a payment gateway integrating cryptocurrency through card, phone tab or QR-Code. | ||
|
||
### POS Contract | ||
|
||
The **POS** contract manages payment requests when a user taps their NFC-enabled card. The POS device, whether an Android or iOS reader, receives contract information from the user, including a signature signed by the ephemeral key on the NFC card and payment details. This data is encoded and passed to the Pay function in the Vault Contract. | ||
|
||
### Vault Contract | ||
|
||
- **Deposit**: User deposits funds into the vault. | ||
- **Withdraw**: User withdraw funds from the vault. | ||
- **setLimit**: User can set limit for regular payments, Note that when the transfer amount exceeds the set limit, the user's Account Abstraction will need to provide a reconfirmation signature. | ||
- **Pay** function (called by **POS** contract) | ||
- If the transfer amount is within the limit user set on the **Vault** Contract, no reconfirmation signature is necessary. | ||
- If the transfer amount exceeds the set limit, the Account Abstraction of the user (via Phone Biometrics or Mail OTP) must provide a reconfirmation signature to complete the transaction. | ||
|
||
### Swap Contract | ||
|
||
The Swap contract simulates a decentralized exchange (DEX) platform for swapping tokens in case the token the user possesses is different from the token required by the POS system. Examples of such platforms include Pancake Swap and Uniswap. | ||
|
||
## Features | ||
|
||
### Already Implemented | ||
- NFC or Phone NFC tapping | ||
- Pre-condition checker system for limit conditions | ||
- Mail OTP for user Account Abstraction confirmation for exceeding the Vault-set limit | ||
- User's Smart Account Vault | ||
- QR-Code implementation | ||
- Social recovery | ||
- Gas less transactions | ||
- Spending limits | ||
- Liquid and non-liquid asset router | ||
|
||
### In The Future | ||
|
||
- Transactions batching | ||
- Biometric Authentication | ||
- Integration with DeFi Protocols | ||
- Privacy Features (zk Proof) | ||
|
||
## Deployment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have any of these deployment on Klaytn? |
||
### BSC Testnet | ||
|
||
- `Swap`: 0x8aB386e5507c0B97a9b398641F0C3d6D90bD82B8 | ||
- `POS`: 0x0DBb0069A7684E2DB1b9962F22Afdc6eB61F43b0 | ||
- `Vault`: 0x0731fE55F95B5b986F4EBd187315fB1F4C823b94 | ||
|
||
### Viction testnet | ||
|
||
- `Swap`: 0x138A20058F977B96c63306C1cC910339dC2301Fa | ||
- `POS`: 0xCefe4a5123b8b683dA995E2031053cb93079e909 | ||
- `Vault`: 0x56dEAdD2Cda0193116c34975a041c261bFCCC981 |
This file contains 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 @@ | ||
{"tokenIn":"0x240A4297443bE4c8f398D4f8B42B83a3fa23918B","tokenOUt":"0xa0DE6eD40A071Cc3e137Bc854DA160978E1227D0","swap":"0x138A20058F977B96c63306C1cC910339dC2301Fa","POS":"0xCefe4a5123b8b683dA995E2031053cb93079e909","Vault":"0x56dEAdD2Cda0193116c34975a041c261bFCCC981"} |
This file contains 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,55 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.18; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@openzeppelin/contracts/utils/Address.sol"; | ||
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; | ||
import {VaultContract} from "./VaultContract.sol"; | ||
import {ISwap} from "./interfaces/ISwap.sol"; | ||
contract POS is Ownable { | ||
using Address for address payable; | ||
|
||
uint256 public constant VERSION = 1; | ||
|
||
address public verifier; | ||
address public swapContract; | ||
|
||
// mapping used signature | ||
mapping(bytes => bool) private invalidSignatures; | ||
|
||
event PaymentRequest( | ||
uint256 indexed _sessionId, | ||
address indexed _token, | ||
address _vault | ||
); | ||
|
||
/** | ||
* @dev Constructor | ||
* @notice The platform fee basis points must be less than 10000 | ||
* @notice The fee to address must not be the zero address | ||
*/ | ||
constructor(address _swapContract) { | ||
swapContract = _swapContract; | ||
} | ||
|
||
function requestPayment( | ||
uint256 _sessionId, | ||
bytes calldata paymentData, | ||
address vaultAddress, | ||
address paymentToken | ||
) external payable { | ||
(bool success, bytes memory result) = vaultAddress.call(paymentData); | ||
require(success, "POS: failed to request approve from vault contract"); | ||
|
||
(address transferToken, uint256 amount) = abi.decode( | ||
result, | ||
(address, uint256) | ||
); | ||
if (paymentToken != transferToken) { | ||
ISwap(swapContract).swap(transferToken, paymentToken, amount); | ||
} | ||
|
||
emit PaymentRequest(_sessionId, paymentToken, vaultAddress); | ||
} | ||
} |
This file contains 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,31 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.18; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {ISwap} from "./interfaces/ISwap.sol"; | ||
|
||
contract Swap { | ||
// mapping token used by Swap Contract | ||
mapping(address => bool) private tokenList; | ||
// mapping current liquidity of token | ||
mapping(address => uint256) private liquidity; | ||
address public tokenIn; | ||
address public tokenOut; | ||
|
||
constructor(address _tokenIn, address _tokenOut) { | ||
tokenIn = _tokenIn; | ||
tokenOut = _tokenOut; | ||
} | ||
|
||
function swap( | ||
address _tokenIn, | ||
address _tokenOut, | ||
uint256 amountIn | ||
) external { | ||
uint256 amountOut; | ||
amountOut = amountIn; | ||
require(IERC20(_tokenOut).balanceOf(address(this)) >= amountOut, "Not enough liquidity"); | ||
IERC20(_tokenIn).transfer(address(this), amountIn); | ||
IERC20(_tokenOut).transfer(msg.sender, amountIn); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you care to change to Klaytn NFC Payment?