0.6.2 • Published 3 months ago

@redstone-finance/ton-connector v0.6.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months 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.

  • contracts - source code in FunC for all smart contracts and their imports.
    • You can read here how the contracts work.
    • redstone directory contains the RedStone library containing aggregation as well as full data-processing written in FunC
  • 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
  • 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):
    • TODO 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.

Read more here

📄 License

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

0.6.2

3 months ago

0.6.0-fixed

5 months ago

0.6.0-fix

5 months ago

0.5.4

7 months ago

0.6.0-1

5 months ago

0.5.3

7 months ago

0.6.1

5 months ago

0.5.2

7 months ago

0.6.0

5 months ago

0.5.1

7 months ago

0.5.0-alpha.0

8 months ago

0.5.0

8 months ago

0.4.0-alpha.0

9 months ago

0.4.0

9 months ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.3-alpha.0

1 year ago