Skip to content

feat: add send_usd example for ton #37

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 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions price_feeds/ton/send_usd/.env.sample
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"
16 changes: 16 additions & 0 deletions price_feeds/ton/send_usd/.gitignore
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
1 change: 1 addition & 0 deletions price_feeds/ton/send_usd/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
7 changes: 7 additions & 0 deletions price_feeds/ton/send_usd/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 120,
"tabWidth": 4,
"singleQuote": true,
"bracketSpacing": true,
"semi": true
}
83 changes: 83 additions & 0 deletions price_feeds/ton/send_usd/README.md
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`
Loading