Skip to content

Commit 295e7fa

Browse files
authored
feat(ton): update ton testnet addr (#2110)
* update ton testnet addr * update addr * update deploy script * update mainnet addr * update mainnet addr * upd addr * upd addr
1 parent c6ec886 commit 295e7fa

File tree

12 files changed

+62
-15
lines changed

12 files changed

+62
-15
lines changed

contract_manager/store/chains/TonChains.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33
mainnet: false
44
rpcUrl: https://testnet.toncenter.com/api/v2/jsonRPC
55
type: TonChain
6+
- id: ton_mainnet
7+
wormholeChainName: ton_mainnet
8+
mainnet: true
9+
rpcUrl: https://toncenter.com/api/v2/jsonRPC
10+
type: TonChain
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
- chain: ton_testnet
2-
address: "EQDwGkJmcj7MMmWAHmhldnY-lAKI6hcTQ2tAEcapmwCnztQU"
2+
address: "EQB4ZnrI5qsP_IUJgVJNwEGKLzZWsQOFhiaqDbD7pTt_f9oU"
3+
type: TonPriceFeedContract
4+
- chain: ton_mainnet
5+
address: "EQBU6k8HH6yX4Jf3d18swWbnYr31D3PJI7PgjXT-flsKHqql"
36
type: TonPriceFeedContract
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
- chain: ton_testnet
2-
address: "EQDwGkJmcj7MMmWAHmhldnY-lAKI6hcTQ2tAEcapmwCnztQU"
2+
address: "EQB4ZnrI5qsP_IUJgVJNwEGKLzZWsQOFhiaqDbD7pTt_f9oU"
3+
type: TonWormholeContract
4+
- chain: ton_mainnet
5+
address: "EQBU6k8HH6yX4Jf3d18swWbnYr31D3PJI7PgjXT-flsKHqql"
36
type: TonWormholeContract

governance/xc_admin/packages/xc_admin_common/src/chains.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export const RECEIVER_CHAINS = {
9393
superseed_mainnet: 60066,
9494
fuel_mainnet: 60067, // Note: Currently deployed at 50084 (fuel_testnet) but we should use 60067 for future deployments
9595
hemi_mainnet: 60068,
96+
ton_mainnet: 60069,
9697
// Testnets as a separate chain ids (to use stable data sources and governance for them)
9798
injective_testnet: 60013,
9899
osmosis_testnet_4: 60015,

target_chains/ton/contracts/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@
1919

2020
### Deploy or run another script
2121

22-
`npx blueprint run` or `yarn blueprint run`
22+
First, visit [TON Center](https://toncenter.com/) and register to get an API key to bypass rate limits. Replace `<YOUR-API-KEY>` with the API key you obtained from TON Center. `<CUSTOM-TYPE>` is either `testnet` or `mainnet`. `<CHAIN-ID>` is the chain ID of the chain you want to deploy to.
23+
24+
Then run:
25+
26+
```bash
27+
CHAIN_ID=<CHAIN-ID> npx blueprint run --custom https://testnet.toncenter.com/api/v2/jsonRPC --custom-version v2 --custom-type <CUSTOM-TYPE> --custom-key <YOUR-API-KEY>
28+
```
2329

2430
### Add a new contract
2531

target_chains/ton/contracts/contracts/Pyth.fc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ cell create_price_feed_cell_chain(tuple price_feeds) {
357357
;; - 6 bits: optimized way of serializing the tag and the first 4 fields
358358
;; - 256 bits: owner address
359359
;; - 128 bits: coins (VarUInteger 16) from grams$_ amount:(VarUInteger 16) = Grams
360-
;; - 107 bits: other data (extra_currencies + ihr_fee + fwd_fee + lt of transaction + unixtime of transaction + no init-field flag + inplace message body flag)
360+
;; - 107 bits: MSG_SERIALIZE_BITS
361361
;; - PRICE_FEED_BITS * num_price_feeds: space for each price feed
362-
int bits = 6 + 256 + 128 + 107 + (PRICE_FEED_BITS * num_price_feeds);
362+
int bits = 6 + 256 + 128 + MSG_SERIALIZE_BITS + (PRICE_FEED_BITS * num_price_feeds);
363363
int fwd_fee = get_forward_fee(cells, bits, WORKCHAIN);
364364

365365
;; Calculate all fees
@@ -375,7 +375,7 @@ cell create_price_feed_cell_chain(tuple price_feeds) {
375375
.store_uint(0x18, 6)
376376
.store_slice(sender_address)
377377
.store_coins(excess)
378-
.store_uint(1, 1 + 4 + 4 + 64 + 32 + 1 + 1)
378+
.store_uint(1, MSG_SERIALIZE_BITS)
379379
.store_ref(response.end_cell())
380380
.end_cell(),
381381
0);

target_chains/ton/contracts/contracts/common/constants.fc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ const int WORMHOLE_MERKLE_UPDATE_TYPE = 0;
1515

1616
const int PRICE_FEED_MESSAGE_TYPE = 0;
1717

18+
;; Bit layout: (https://docs.ton.org/v3/documentation/smart-contracts/message-management/sending-messages#message-layout)
19+
;; 1 - extra-currencies dictionary (0 = empty)
20+
;; 4 - ihr_fee (VarUInteger 16)
21+
;; 4 - fwd_fee (VarUInteger 16)
22+
;; 64 - created_lt (uint64)
23+
;; 32 - created_at (uint32)
24+
;; 1 - init field presence (0 = no init)
25+
;; 1 - body serialization (0 = in-place)
26+
const int MSG_SERIALIZE_BITS = 1 + 4 + 4 + 64 + 32 + 1 + 1; ;; 107 bits total
27+
1828
;; Structure:
1929
;; - 256 bits: price_id
2030
;; Price:

target_chains/ton/contracts/scripts/deployPyth.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
MAINNET_UPGRADE_VAAS,
1111
} from "../tests/utils/wormhole";
1212
import { BTC_PRICE_FEED_ID, ETH_PRICE_FEED_ID } from "../tests/utils/pyth";
13+
import { calculateUpdatePriceFeedsFee } from "@pythnetwork/pyth-ton-js";
1314

1415
export async function run(provider: NetworkProvider) {
1516
const SINGLE_UPDATE_FEE = 1;
@@ -21,12 +22,28 @@ export async function run(provider: NetworkProvider) {
2122
},
2223
];
2324

25+
// Require CHAIN_ID environment variable
26+
if (!process.env.CHAIN_ID) {
27+
throw new Error(
28+
"CHAIN_ID environment variable is required. Example usage: CHAIN_ID=2 npx blueprint run ..."
29+
);
30+
}
31+
32+
const chainId = parseInt(process.env.CHAIN_ID, 10);
33+
34+
// Validate that chainId is a valid number
35+
if (isNaN(chainId)) {
36+
throw new Error("CHAIN_ID must be a valid number");
37+
}
38+
39+
console.log("Chain ID:", chainId);
40+
2441
const config: MainConfig = {
2542
singleUpdateFee: SINGLE_UPDATE_FEE,
2643
dataSources: DATA_SOURCES,
2744
guardianSetIndex: 0,
2845
guardianSet: GUARDIAN_SET_0,
29-
chainId: 1,
46+
chainId,
3047
governanceChainId: 1,
3148
governanceContract:
3249
"0000000000000000000000000000000000000000000000000000000000000004",
@@ -97,12 +114,14 @@ export async function run(provider: NetworkProvider) {
97114

98115
// NOTE: As of 2024/10/14 There's a bug with TON Access (https://ton.access.orbs.network) RPC service where if you provide an update data buffer with length of more than ~320 then the rpc returns error 404 and the function fails
99116
const updateFee = await main.getUpdateFee(updateData);
100-
console.log("Update fee:", updateFee);
101117

102-
await main.sendUpdatePriceFeeds(
118+
const totalFee =
119+
calculateUpdatePriceFeedsFee(BigInt(updateFee)) + BigInt(updateFee);
120+
121+
const result = await main.sendUpdatePriceFeeds(
103122
provider.sender(),
104123
updateData,
105-
toNano(updateFee)
124+
totalFee
106125
);
107126
console.log("Price feeds updated successfully.");
108127

target_chains/ton/contracts/tests/PythTest.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ import {
2323
HERMES_BTC_EMA_CONF,
2424
HERMES_BTC_EMA_EXPO,
2525
HERMES_BTC_EMA_PRICE,
26-
HERMES_BTC_EMA_PUBLISH_TIME,
2726
HERMES_ETH_CONF,
2827
HERMES_ETH_EMA_CONF,
2928
HERMES_ETH_EMA_EXPO,
3029
HERMES_ETH_EMA_PRICE,
31-
HERMES_ETH_EMA_PUBLISH_TIME,
3230
HERMES_ETH_EXPO,
3331
HERMES_BTC_ETH_UNIQUE_UPDATE,
3432
HERMES_ETH_UNIQUE_EMA_PRICE,

target_chains/ton/contracts/tests/utils/wormhole.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,5 @@ export const MAINNET_UPGRADE_VAAS = [
174174
export const GOVERNANCE_DATA_SOURCE: DataSource = {
175175
emitterChain: 1,
176176
emitterAddress:
177-
"0000000000000000000000000000000000000000000000000000000000000029",
177+
"5635979a221c34931e32620b9293a463065555ea71fe97cd6237ade875b12e9e",
178178
};

0 commit comments

Comments
 (0)