0.5.0 • Published 2 days ago

@redstone-finance/ton-connector v0.5.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 days ago

🔗 @redstone-finance/ton-connector

Discord Twitter

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.

🔥 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,
    dataFeeds: ["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:

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.

Read more here

📄 License

RedStone ton connector is an open-source and free software released under the BUSL-1.1 License.