|
| 1 | +# send_usd |
| 2 | + |
| 3 | +This repository contains examples of applications integrating Pyth products and services. Sample contract demonstrating Pyth price feed integration on TON. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This contract enables USD-denominated payments on TON by integrating with Pyth price oracles. It supports two operations: |
| 8 | + |
| 9 | +1. `send_usd` - Send a USD-denominated payment that gets converted to TON at current price |
| 10 | + |
| 11 | +Message format: |
| 12 | + |
| 13 | +```typescript |
| 14 | +{ |
| 15 | + queryId: number, // 64-bit unique identifier for the request |
| 16 | + recipient: Address, // TON address of payment recipient |
| 17 | + usdAmount: number, // Amount in USD dollars |
| 18 | + updateData: Buffer, // Pyth price update data (converted to cell chain) |
| 19 | + value: bigint // Amount of TON to attach to message |
| 20 | +} |
| 21 | +``` |
| 22 | + |
| 23 | +The `updateData` field contains Pyth price feed data and must be obtained from [Hermes](https://hermes.pyth.network/docs/). This data is converted to a TON cell chain format using the `createCellChain()` helper from the [pyth-ton-js](https://www.npmjs.com/package/@pythnetwork/pyth-ton-js) library. The Pyth contract can be found [here](https://github.com/pyth-network/pyth-crosschain/tree/main/target_chains/ton/contracts). |
| 24 | + |
| 25 | +2. Pyth price update callback |
| 26 | + |
| 27 | +- Receives price updates from Pyth oracle contract |
| 28 | +- Automatically processes pending USD payments using latest price |
| 29 | + |
| 30 | +## Setup |
| 31 | + |
| 32 | +1. Copy environment config: |
| 33 | + |
| 34 | +```bash |
| 35 | +cp .env.example .env |
| 36 | +``` |
| 37 | + |
| 38 | +2. Configure `.env`: |
| 39 | + |
| 40 | +``` |
| 41 | +WALLET_MNEMONIC="your mnemonic here" |
| 42 | +``` |
| 43 | + |
| 44 | +## Usage |
| 45 | + |
| 46 | +1. Deploy contract: |
| 47 | + |
| 48 | +```bash |
| 49 | +npx blueprint run deploySendUsd --custom https://testnet.toncenter.com/api/v2/jsonRPC --custom-version v2 --custom-type testnet --custom-key <YOUR-API-KEY> --mnemonic |
| 50 | +``` |
| 51 | + |
| 52 | +This will deploy the contract and update `.env` with the deployed address. |
| 53 | + |
| 54 | +2. Send USD payment: |
| 55 | + |
| 56 | +```bash |
| 57 | +npx blueprint run sendUsdPayment <YOUR-TON-WALLET-ADDRESS> 1 --custom https://testnet.toncenter.com/api/v2/jsonRPC --custom-version v2 --custom-type testnet --custom-key <YOUR-API-KEY> --mnemonic |
| 58 | +``` |
| 59 | + |
| 60 | +## Project structure |
| 61 | + |
| 62 | +- `contracts` - Smart contract source code and dependencies |
| 63 | +- `wrappers` - Contract wrapper classes implementing serialization and compilation |
| 64 | +- `tests` - Contract test suite |
| 65 | +- `scripts` - Deployment and interaction scripts |
| 66 | + |
| 67 | +## Development |
| 68 | + |
| 69 | +### Build |
| 70 | + |
| 71 | +`npx blueprint build` or `yarn blueprint build` |
| 72 | + |
| 73 | +### Test |
| 74 | + |
| 75 | +`npx blueprint test` or `yarn blueprint test` |
| 76 | + |
| 77 | +### Deploy or run scripts |
| 78 | + |
| 79 | +`npx blueprint run` or `yarn blueprint run` |
| 80 | + |
| 81 | +### Create new contract |
| 82 | + |
| 83 | +`npx blueprint create ContractName` or `yarn blueprint create ContractName` |
0 commit comments