-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add send_usd example for ton (#37)
* add send_usd example for ton * update data * update readme * address comments
- Loading branch information
Showing
16 changed files
with
7,274 additions
and
0 deletions.
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,5 @@ | ||
WALLET_VERSION="v4" | ||
WALLET_MNEMONIC="" | ||
TONCENTER_API_KEY="" # Get from https://toncenter.com/ | ||
PYTH_CONTRACT_ADDRESS="EQB4ZnrI5qsP_IUJgVJNwEGKLzZWsQOFhiaqDbD7pTt_f9oU" | ||
SEND_USD_CONTRACT_ADDRESS="EQBSXhaZHDbb7WRcdxXnmlFXsh_VDLJFSuFdWWV_FxxWFx-q" |
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,16 @@ | ||
node_modules | ||
temp | ||
build | ||
dist | ||
.DS_Store | ||
|
||
# VS Code | ||
.vscode/* | ||
.history/ | ||
*.vsix | ||
|
||
# IDEA files | ||
.idea | ||
|
||
# VIM | ||
Session.vim |
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 @@ | ||
build |
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,7 @@ | ||
{ | ||
"printWidth": 120, | ||
"tabWidth": 4, | ||
"singleQuote": true, | ||
"bracketSpacing": true, | ||
"semi": true | ||
} |
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,83 @@ | ||
# send_usd | ||
|
||
This repository contains examples of applications integrating Pyth products and services. Sample contract demonstrating Pyth price feed integration on TON. | ||
|
||
## Overview | ||
|
||
This contract enables USD-denominated payments on TON by integrating with Pyth price oracles. It supports two operations: | ||
|
||
1. `send_usd` - Send a USD-denominated payment that gets converted to TON at current price | ||
|
||
Message format: | ||
|
||
```typescript | ||
{ | ||
queryId: number, // 64-bit unique identifier for the request | ||
recipient: Address, // TON address of payment recipient | ||
usdAmount: number, // Amount in USD dollars | ||
updateData: Buffer, // Pyth price update data (converted to cell chain) | ||
value: bigint // Amount of TON to attach to message | ||
} | ||
``` | ||
|
||
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). | ||
|
||
2. Pyth price update callback | ||
|
||
- Receives price updates from Pyth oracle contract | ||
- Automatically processes pending USD payments using latest price | ||
|
||
## Setup | ||
|
||
1. Copy environment config: | ||
|
||
```bash | ||
cp .env.example .env | ||
``` | ||
|
||
2. Configure `.env`: | ||
|
||
``` | ||
WALLET_MNEMONIC="your mnemonic here" | ||
``` | ||
|
||
## Usage | ||
|
||
1. Deploy contract: | ||
|
||
```bash | ||
npx blueprint run deploySendUsd --custom https://testnet.toncenter.com/api/v2/jsonRPC --custom-version v2 --custom-type testnet --custom-key <YOUR-API-KEY> --mnemonic | ||
``` | ||
|
||
This will deploy the contract and update `.env` with the deployed address. | ||
|
||
2. Send USD payment: | ||
|
||
```bash | ||
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 | ||
``` | ||
|
||
## Project structure | ||
|
||
- `contracts` - Smart contract source code and dependencies | ||
- `wrappers` - Contract wrapper classes implementing serialization and compilation | ||
- `tests` - Contract test suite | ||
- `scripts` - Deployment and interaction scripts | ||
|
||
## Development | ||
|
||
### Build | ||
|
||
`npx blueprint build` or `yarn blueprint build` | ||
|
||
### Test | ||
|
||
`npx blueprint test` or `yarn blueprint test` | ||
|
||
### Deploy or run scripts | ||
|
||
`npx blueprint run` or `yarn blueprint run` | ||
|
||
### Create new contract | ||
|
||
`npx blueprint create ContractName` or `yarn blueprint create ContractName` |
Oops, something went wrong.