Skip to content

Commit

Permalink
pyth prices fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
kamalbuilds committed Aug 11, 2024
1 parent bc904b9 commit 37a69ee
Show file tree
Hide file tree
Showing 6 changed files with 4,894 additions and 253 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Cross Pay
# Cross Pay Merchants Pay

**Connecting Merchants' Preferences with Customers' Choices through Cross-Chain Payments**

Expand All @@ -8,7 +8,14 @@ Cross Pay is an innovative cross-chain payment solution designed to bridge the g

Cross Pay leverages advanced blockchain technology to deliver a comprehensive payment solution that caters to the needs of both merchants and users.

## Demo URL

## Contract Deployments via create2

Base Sepolia - https://base-sepolia.blockscout.com/address/0xC0204113CcC43D83De06191C082ea696C65466f9

Mode Testnet - https://sepolia.explorer.mode.network/address/0xc8E2B6AC668AC47ffE8814E86aDCb966C6AA3d5b

OP Sepolia Testnet - https://optimism-sepolia.blockscout.com/address/0x2AAC535db31DB35D13AECe36Ea7954A2089D55bE

## Features

Expand All @@ -22,11 +29,16 @@ Cross Pay leverages advanced blockchain technology to deliver a comprehensive pa
- **SwapKit API and SDK Integration**: Utilizes SwapKit's robust API and SDK for secure and efficient transaction processing across multiple blockchains.
- **End-to-End Encryption**: Ensures that all transactions are protected by advanced encryption methods, providing security and peace of mind.

### Plugin Integrations
### Partner Integrations

- **Innovative Use of Pyth Price Feeds**:

- Real-Time Data Integration for Secure Payments: In our project, Merchant's Pay, we utilize Pyth's real-time price feeds to ensure that cross-chain payments are accurately and fairly valued at the moment of the transaction. By integrating Pyth’s pull oracle, we can fetch low-latency price data that allows merchants to receive payments in their preferred currency, with confidence that the conversion rates are up-to-date and accurate. This is critical in a volatile market, where real-time data directly impacts the fairness and security of financial transactions.

- Enhancing Trust in Onchain Commerce: By pulling and consuming Pyth price feeds, we enhance the transparency and trustworthiness of our payment platform. Users and merchants can verify that the price used for each transaction reflects the current market value, minimizing discrepancies and disputes. This use of Pyth not only powers our dapp but also establishes a higher standard for accuracy and reliability in onchain commerce.

- **ThorSwap**: Integrates with ThorSwap to facilitate easy swaps and liquidity provision across different blockchain networks.
- **ChainFlip**: Uses ChainFlip's technology to enable seamless cross-chain swaps, ensuring users can transact with their preferred tokens without hassle.
- **MayoChain**: Incorporates MayoChain to leverage its unique features for enhanced transaction speed and reliability.
Why Our Integration Stands Out:
- Leveraging Pyth for Real-World Impact: We have built our payment platform with the end user in mind, ensuring that Pyth’s technology enhances the overall user experience. By accurately pricing transactions and adding security through randomness, we are addressing real-world challenges in onchain commerce, such as price volatility and transaction.

### Non-Transferable ERC721 Tokens

Expand Down
2 changes: 2 additions & 0 deletions smartcontract/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ node_modules
/cache
/artifacts

bun.lockb

# TypeChain files
/typechain
/typechain-types
Expand Down
Binary file modified smartcontract/bun.lockb
Binary file not shown.
40 changes: 36 additions & 4 deletions smartcontract/contracts/MerchantsPay.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,36 @@ pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
import "@pythnetwork/pyth-sdk-solidity/PythStructs.sol";

contract MerchantsPay is ERC721, Ownable, AccessControl, ReentrancyGuard {

IPyth pyth;

bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");

string public baseURI = "https://crosspay.vercel.app/token.json?id=";
string public baseURI = "https://superhack-merchants-pay.vercel.app/token.json?id=";

mapping(address => string) public pointers;

event PointerSet(address indexed user, string pointer);
event BaseURISet(string baseURI);

constructor() ERC721("Cross Pay", "CP") {
constructor(address pythContract) ERC721("CrossChain MerchantsPay", "CMP") {
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
_setupRole(ADMIN_ROLE, msg.sender);

// The IPyth interface from pyth-sdk-solidity provides the methods to interact with the Pyth contract.
// Instantiate it with the Pyth contract address from https://docs.pyth.network/price-feeds/contract-addresses/evm
pyth = IPyth(pythContract);
}

function setPythContract(address pythContract) public onlyRole(ADMIN_ROLE) {
pyth = IPyth(pythContract);
}

function setPointer(string memory pointerValue) public nonReentrant {
Expand All @@ -33,7 +47,7 @@ contract MerchantsPay is ERC721, Ownable, AccessControl, ReentrancyGuard {
_safeMint(msg.sender, tokenId);
emit PointerSet(msg.sender, pointerValue);
}

function getPointer(address user) public view returns (string memory) {
return pointers[user];
}
Expand Down Expand Up @@ -69,4 +83,22 @@ contract MerchantsPay is ERC721, Ownable, AccessControl, ReentrancyGuard {
_safeMint(user, tokenId);
emit PointerSet(user, pointerValue);
}

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, AccessControl) returns (bool) {
return super.supportsInterface(interfaceId);
}

function getprices(bytes[] calldata priceUpdate) public payable {
// Submit a priceUpdate to the Pyth contract to update the on-chain price.
// Updating the price requires paying the fee returned by getUpdateFee.
// WARNING: These lines are required to ensure the getPriceNoOlderThan call below succeeds. If you remove them, transactions may fail with "0x19abf40e" error.
uint fee = pyth.getUpdateFee(priceUpdate);
pyth.updatePriceFeeds{ value: fee }(priceUpdate);

// Read the current price from a price feed if it is less than 60 seconds old.
// Each price feed (e.g., ETH/USD) is identified by a price feed ID.
// The complete list of feed IDs is available at https://pyth.network/developers/price-feed-ids
bytes32 priceFeedId = 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace; // ETH/USD
PythStructs.Price memory price = pyth.getPriceNoOlderThan(priceFeedId, 60);
}
}
Loading

0 comments on commit 37a69ee

Please sign in to comment.