@redstone-finance/ton-connector v0.6.2
🔗 @redstone-finance/ton-connector
RedStone proposes a completely new modular design where data is first put into a data availability layer and then fetched on-chain. This allows us to broadcast a large number of assets at high frequency to a cheaper layer and put it on chain only when required by the protocol.
The @redstone-finance/ton-connector
module implements an alternative design of providing oracle data to smart
contracts. Instead of constantly persisting data on the TON network storage (by data providers), the information is
brought on-chain only when needed (by end users). Until that moment data remains in the decentralised cache layer, which
is powered by RedStone light cache gateways and streamr data broadcasting protocol. Data is transferred to the TON
network by end users. The information integrity is verified on-chain through signature checking.
Here also you can find the description of the whole RedStone Oracle model.
👨💻 Code structure
The code structure is defined by the Blueprint the assumptions described here - Blueprint is a development environment for TON blockchain for writing, testing, and deploying smart contracts.
- contracts - source code in FunC for all smart contracts and their imports.
- wrappers - TypeScript interface classes for all contracts (implementing Contract from @ton/core) include message (de)serialization primitives, getter wrappers and compilation functions used by the test suite and client code to interact with the contracts from TypeScript
- scripts - deployment scripts to mainnet/testnet and other scripts interacting with live contracts
- deployPriceFeed.ts / deployPriceManager.ts deploy the particular contract on testnet
- runPriceManagerGetPrices.ts / runPriceManagerReadPrices.ts / runPriceManagerWritePrices.ts execute the methods described here
- runPriceFeedFetchData.ts / runPriceFeedGetData.ts execute the methods described here
- src - TypeScript classes, useful for establishing a connection between TypeScript and TON layers.
- See below, how to connect to the contract.
- test - TypeScript test suite for all contracts (relying on Sandbox for in-process tests):
- TBD
🔥 Connecting to the contract
First, you need to import the connector code to your project
// Typescript
import { TonPricesContractConnector } from "@redstone-finance/ton-connector";
import { ContractParamsProvider } from "@redstone-finance/sdk";
// Javascript
const {
TonPricesContractConnector,
} = require("@redstone-finance/ton-connector");
const { ContractParamsProvider } = require("@redstone-finance/sdk");
Then you can invoke the contract methods described above pointing to the selected RedStone data service and requested data feeds.
const prices = new TonPricesContractConnector(network, yourContractAddress);
const paramsProvider = new ContractParamsProvider({
dataServiceId: "redstone-main-demo",
uniqueSignersCount: 1,
dataPackagesIds: ["ETH", "BTC"],
});
The network
param is needed to be passed because of different ways of configuring TON network access.
If you're using Blueprint or have another custom way, just define the network
param as below.
Note: the @ton/blueprint
is not a dependency of the library, so you need to add to your project manually.
const blueprintNetwork = new BlueprintTonNetwork(networkProvider, apiV2Config);
// or
const customNetwork = new CustomTonNetwork(() => {
return null; /* return your wallet KeyPair here */
}, apiV2Config);
and apiV2Config
should contain apiEndpoint
and apiKey
(when is needed, for example
for https://toncenter.com) strings. The apiEndpoint
can be fetched by using getHttpEndpoint({ network: "testnet" })
method for orbs or can be defined as https://testnet.toncenter.com/api/v2/jsonRPC
for toncenter.
Now you can access any of the contract's methods by invoking the code:
(await prices.getAdapter()).getPricesFromPayload(paramsProvider);
(await prices.getAdapter()).writePricesFromPayloadToContract(paramsProvider);
(await prices.getAdapter()).readPricesFromContract(paramsProvider);
(await prices.getAdapter()).readTimestampFromContract();
Installing the dependencies
yarn install
⚡ The TON Grants Program
TON Foundation provides grants for projects that contribute to TON core infrastructure and introduce new practical use cases and is helping hundreds of builders to battle-test their skills and knowledge while contributing to public good.
📄 License
RedStone ton connector is an open-source and free software released under the BUSL-1.1 License.
3 months ago
5 months ago
5 months ago
7 months ago
5 months ago
7 months ago
5 months ago
7 months ago
5 months ago
7 months ago
8 months ago
8 months ago
9 months ago
9 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago