npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@redstone-finance/ton-connector

v0.6.2

Published

A tool to inject RedStone data into TON compatible smart contracts

Downloads

213

Readme

🔗 @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.