@pythnetwork/pyth-ton-js 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +5 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +18 -7
- package/package.json +13 -13
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -57,9 +57,13 @@ async function main() {
|
|
|
57
57
|
);
|
|
58
58
|
console.log("Hermes BTC price:", latestPriceUpdates.parsed?.[0].price);
|
|
59
59
|
|
|
60
|
+
const numUpdates = 1; // Only BTC price
|
|
60
61
|
const updateData = Buffer.from(latestPriceUpdates.binary.data[0], "hex");
|
|
61
62
|
console.log("Update data:", updateData);
|
|
62
63
|
|
|
64
|
+
// NOTE: As of 2025/10/19 There's a bug with TON Access (https://ton.access.orbs.network) RPC service where if you provide an
|
|
65
|
+
// update data buffer with length of more than ~320 then the rpc returns error 404 and the function fails. In this case you can use the
|
|
66
|
+
// contract.getSingleUpdateFee() method to get the single update fee and multiply it by the number of updates you want to perform.
|
|
63
67
|
const updateFee = await contract.getUpdateFee(updateData);
|
|
64
68
|
console.log("Update fee:", updateFee);
|
|
65
69
|
|
|
@@ -74,7 +78,7 @@ async function main() {
|
|
|
74
78
|
await contract.sendUpdatePriceFeeds(
|
|
75
79
|
provider.sender(key.secretKey),
|
|
76
80
|
updateData,
|
|
77
|
-
calculateUpdatePriceFeedsFee(
|
|
81
|
+
calculateUpdatePriceFeedsFee(numUpdates) + BigInt(updateFee)
|
|
78
82
|
);
|
|
79
83
|
console.log("Price feeds updated successfully.");
|
|
80
84
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { Address, Cell, Contract, Sender } from "@ton/core";
|
|
3
2
|
import { ContractProvider } from "@ton/ton";
|
|
4
|
-
export declare const PYTH_CONTRACT_ADDRESS_MAINNET = "
|
|
3
|
+
export declare const PYTH_CONTRACT_ADDRESS_MAINNET = "EQBgtfuGIzWLiOzpZO48_psYvco4xRtkAbdbmTwy0_o95LtZ";
|
|
5
4
|
export declare const PYTH_CONTRACT_ADDRESS_TESTNET = "EQB4ZnrI5qsP_IUJgVJNwEGKLzZWsQOFhiaqDbD7pTt_f9oU";
|
|
6
5
|
export declare const UPDATE_PRICE_FEEDS_BASE_GAS = 300000n;
|
|
7
6
|
export declare const UPDATE_PRICE_FEEDS_PER_UPDATE_GAS = 90000n;
|
|
@@ -25,6 +24,7 @@ export declare class PythContract implements Contract {
|
|
|
25
24
|
sendUpdateGuardianSet(provider: ContractProvider, via: Sender, vm: Buffer): Promise<void>;
|
|
26
25
|
sendUpdatePriceFeeds(provider: ContractProvider, via: Sender, updateData: Buffer, updateFee: bigint): Promise<void>;
|
|
27
26
|
sendExecuteGovernanceAction(provider: ContractProvider, via: Sender, governanceAction: Buffer): Promise<void>;
|
|
27
|
+
sendUpgradeContract(provider: ContractProvider, via: Sender, newCode: Cell): Promise<void>;
|
|
28
28
|
getPriceUnsafe(provider: ContractProvider, priceFeedId: string): Promise<{
|
|
29
29
|
price: number;
|
|
30
30
|
conf: number;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,IAAI,EACJ,QAAQ,EAER,MAAM,EAGP,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,eAAO,MAAM,6BAA6B,qDACU,CAAC;AACrD,eAAO,MAAM,6BAA6B,qDACU,CAAC;AAErD,eAAO,MAAM,2BAA2B,UAAU,CAAC;AACnD,eAAO,MAAM,iCAAiC,SAAS,CAAC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AW,EAAE,MAAM;;;;;;IAoBf,YAAY,CAAC,QAAQ,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM;IAQnD,kBAAkB,CAAC,QAAQ,EAAE,gBAAgB;IAM7C,iCAAiC,CAAC,QAAQ,EAAE,gBAAgB;IAS5D,UAAU,CAAC,QAAQ,EAAE,gBAAgB;IAMrC,cAAc,CAAC,QAAQ,EAAE,gBAAgB;IAKzC,uBAAuB,CAAC,QAAQ,EAAE,gBAAgB;IAKlD,cAAc,CAAC,QAAQ,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM;;;;;CAe/D;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAsBpD;AAmBD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,UAAU,EAAE,CAczD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,UAAU,GAAG,IAAI,CAQ7D;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,CAoBzD;AAED,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,MAAM,UAM9D"}
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PythContract = exports.GAS_PRICE_FACTOR = exports.UPDATE_PRICE_FEEDS_PER_UPDATE_GAS = exports.UPDATE_PRICE_FEEDS_BASE_GAS = exports.PYTH_CONTRACT_ADDRESS_TESTNET = exports.PYTH_CONTRACT_ADDRESS_MAINNET = void 0;
|
|
4
|
+
exports.createCellChain = createCellChain;
|
|
5
|
+
exports.parseDataSources = parseDataSources;
|
|
6
|
+
exports.parseDataSource = parseDataSource;
|
|
7
|
+
exports.parseGuardianSetKeys = parseGuardianSetKeys;
|
|
8
|
+
exports.calculateUpdatePriceFeedsFee = calculateUpdatePriceFeedsFee;
|
|
4
9
|
const core_1 = require("@ton/core");
|
|
5
|
-
exports.PYTH_CONTRACT_ADDRESS_MAINNET = "
|
|
10
|
+
exports.PYTH_CONTRACT_ADDRESS_MAINNET = "EQBgtfuGIzWLiOzpZO48_psYvco4xRtkAbdbmTwy0_o95LtZ";
|
|
6
11
|
exports.PYTH_CONTRACT_ADDRESS_TESTNET = "EQB4ZnrI5qsP_IUJgVJNwEGKLzZWsQOFhiaqDbD7pTt_f9oU";
|
|
7
12
|
// This is defined in target_chains/ton/contracts/common/gas.fc
|
|
8
13
|
exports.UPDATE_PRICE_FEEDS_BASE_GAS = 300000n;
|
|
@@ -56,6 +61,17 @@ class PythContract {
|
|
|
56
61
|
body: messageBody,
|
|
57
62
|
});
|
|
58
63
|
}
|
|
64
|
+
async sendUpgradeContract(provider, via, newCode) {
|
|
65
|
+
const messageBody = (0, core_1.beginCell)()
|
|
66
|
+
.storeUint(4, 32) // OP_UPGRADE_CONTRACT
|
|
67
|
+
.storeRef(newCode)
|
|
68
|
+
.endCell();
|
|
69
|
+
await provider.internal(via, {
|
|
70
|
+
value: (0, core_1.toNano)("0.1"),
|
|
71
|
+
sendMode: core_1.SendMode.PAY_GAS_SEPARATELY,
|
|
72
|
+
body: messageBody,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
59
75
|
async getPriceUnsafe(provider, priceFeedId) {
|
|
60
76
|
const result = await provider.get("get_price_unsafe", [
|
|
61
77
|
{ type: "int", value: BigInt(priceFeedId) },
|
|
@@ -179,7 +195,6 @@ function createCellChain(buffer) {
|
|
|
179
195
|
}
|
|
180
196
|
return lastCell;
|
|
181
197
|
}
|
|
182
|
-
exports.createCellChain = createCellChain;
|
|
183
198
|
function bufferToChunks(buff, chunkSizeBytes = 127) {
|
|
184
199
|
const chunks = [];
|
|
185
200
|
const uint8Array = new Uint8Array(buff.buffer, buff.byteOffset, buff.byteLength);
|
|
@@ -202,7 +217,6 @@ function parseDataSources(cell) {
|
|
|
202
217
|
}
|
|
203
218
|
return dataSources;
|
|
204
219
|
}
|
|
205
|
-
exports.parseDataSources = parseDataSources;
|
|
206
220
|
function parseDataSource(cell) {
|
|
207
221
|
const slice = cell.beginParse();
|
|
208
222
|
if (slice.remainingBits === 0) {
|
|
@@ -212,7 +226,6 @@ function parseDataSource(cell) {
|
|
|
212
226
|
const emitterAddress = slice.loadUintBig(256).toString(16).padStart(64, "0");
|
|
213
227
|
return { emitterChain, emitterAddress };
|
|
214
228
|
}
|
|
215
|
-
exports.parseDataSource = parseDataSource;
|
|
216
229
|
function parseGuardianSetKeys(cell) {
|
|
217
230
|
const keys = [];
|
|
218
231
|
function parseCell(c) {
|
|
@@ -232,10 +245,8 @@ function parseGuardianSetKeys(cell) {
|
|
|
232
245
|
parseCell(cell);
|
|
233
246
|
return keys;
|
|
234
247
|
}
|
|
235
|
-
exports.parseGuardianSetKeys = parseGuardianSetKeys;
|
|
236
248
|
function calculateUpdatePriceFeedsFee(numUpdates) {
|
|
237
249
|
return ((exports.UPDATE_PRICE_FEEDS_BASE_GAS +
|
|
238
250
|
exports.UPDATE_PRICE_FEEDS_PER_UPDATE_GAS * numUpdates) *
|
|
239
251
|
exports.GAS_PRICE_FACTOR);
|
|
240
252
|
}
|
|
241
|
-
exports.calculateUpdatePriceFeedsFee = calculateUpdatePriceFeedsFee;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pythnetwork/pyth-ton-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Pyth Network TON Utilities",
|
|
5
5
|
"homepage": "https://pyth.network",
|
|
6
6
|
"author": {
|
|
@@ -19,14 +19,6 @@
|
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "tsc",
|
|
24
|
-
"format": "prettier --write \"src/**/*.ts\"",
|
|
25
|
-
"test:lint": "eslint src/",
|
|
26
|
-
"prepublishOnly": "pnpm run build && pnpm run test:lint",
|
|
27
|
-
"preversion": "pnpm run test:lint",
|
|
28
|
-
"version": "pnpm run format && git add -A src"
|
|
29
|
-
},
|
|
30
22
|
"keywords": [
|
|
31
23
|
"pyth",
|
|
32
24
|
"oracle"
|
|
@@ -41,10 +33,18 @@
|
|
|
41
33
|
"@typescript-eslint/parser": "^5.21.0",
|
|
42
34
|
"eslint": "^8.14.0",
|
|
43
35
|
"jest": "^29.4.1",
|
|
44
|
-
"prettier": "^
|
|
36
|
+
"prettier": "^3.5.3",
|
|
45
37
|
"ts-jest": "^29.0.5",
|
|
46
38
|
"ts-node": "^10.9.2",
|
|
47
|
-
"typescript": "^
|
|
39
|
+
"typescript": "^5.8.2"
|
|
48
40
|
},
|
|
49
|
-
"
|
|
50
|
-
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc",
|
|
43
|
+
"test:lint": "eslint src/ --max-warnings 0",
|
|
44
|
+
"test:format": "prettier --check \"src/**/*.ts\"",
|
|
45
|
+
"fix:lint": "eslint src/ --fix --max-warnings 0",
|
|
46
|
+
"fix:format": "prettier --write \"src/**/*.ts\"",
|
|
47
|
+
"preversion": "pnpm run test:lint",
|
|
48
|
+
"version": "pnpm run test:format && git add -A src"
|
|
49
|
+
}
|
|
50
|
+
}
|