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

tinyman-ts-sdk

v1.0.1

Published

Tinyman Typescript SDK

Downloads

1

Readme

tinyman-ts-sdk

Tinyman Typescript SDK

Design Goal

This SDK is designed for automated interaction with the Tinyman AMM. It will be most useful for developers who wish to create automated trading programs/bots. It may also be useful to create an alternative UI but that is not a design goal of this library. It is designed to be reasonably low level so that pieces can be used in isolation.

Status

This SDK is currently under active early development and should not be considered stable.

The SDK has been updated for Tinyman V1.1.

Support Development

If you'd like to support the development of this SDK, you can send ALGO or a coffee my-algo DFL62FKU5OYG54Y5FRJ3JWAUQ27Y7PTA4HTNXOE6KCZRRHKDWGIOQWKNMA

ko-fi

Installation

tinyman-ts-sdk is available on npm. : npm i tinyman-ts-sdk

Sneak Preview

import algosdk from "algosdk";
import { Asset,TinymanMainnetClient } from "./../index.js";

const MNEMONIC = '<YOUR MNEMONIC HERE>';
const ACCOUNT = algosdk.mnemonicToSecretKey(MNEMONIC);
const WALLET_ADDRESS = ACCOUNT.addr;
const SECRET_KEY = ACCOUNT.sk;

const client = new algosdk.Algodv2('','https://api.algoexplorer.io','',{'user-agent':'algo-sdk'});

//Initialize Tinyman's Mainnet Client
const TinymanClient = new TinymanMainnetClient(client,WALLET_ADDRESS);

//Fetch the Assets from the network
const A1 = await new Asset(0).fetch(client);       //ALGO
const A2 = await new Asset(31566704).fetch(client); //USDC

//Get the Pool for this Asset pair
const POOL = await TinymanClient.fetch_pool(A1,A2,true);

//Get a Fixed Input Swap Quote
const FIXED_INPUT_SWAP = await POOL.fetch_fixed_input_swap_quote(A1.AssetAmount(1000000),0.01);

//Prepare the Swap Transactions
const TXNS = await POOL.prepare_swap_transactions(
    FIXED_INPUT_SWAP.amount_in_with_slippage(),
    FIXED_INPUT_SWAP.amount_out_with_slippage(),
    'fixed-input',
    WALLET_ADDRESS
);

//Sign the Transactions
TXNS.sign_with_private_key(WALLET_ADDRESS,SECRET_KEY);

//Submit the transactions and wait for confirmation
await TXNS.submit(client,true);
# See the examples for the rest...

Examples

TODO

Conventions

  • Methods starting with fetch_ all make network requests to fetch current balances/state.
  • Methods of the form prepare_X_transactions all return TransactionGroup objects (see below).
  • All asset amounts are returned as AssetAmount objects which contain an Asset and Amount (number).
  • All asset amount inputs are expected as micro units e.g. 1 Algo = 1_000_000 micro units.

Signing & Submission

The SDk separates transaction preparation from signing and submission to leave the developer in full control of how transactions are signed and submitted to the network.

Preparation

The prepare_X_transactions methods all return a TransactionGroup object. This is a container object containing an array of transaction objects (.TRANSACTIONS) and a list for signed transactions (.SIGNED_TRANSACTIONS).

prepare_app_optin_transactions(ACCOUNT:string)

Signing

In most cases some of the transactions have a corresponding entry in .signed_transactions because they have been signed by the Pool LogicSig. The remaining transactions should be signed by the 'user'.

The TransactionGroup includes a method to do this when signing with a private key:

sign_with_private_key(ACCOUNT_ADDRESS:string, ACCOUNT_PRIVATE_KEY:Uint8Array)

A User account LogicSig can also be used in a similar way or using the sign_with_logicisg convenience method:

sign_with_logicisg(LOGICSIG:algosdk.LogicSigAccount)

Submission

A TransactionGroup containing fully signed transactions can be submitted to the network in either of two ways:

Using an Algod client:

const algod = new algosdk.Algodv2('','https://api.algoexplorer.io','',{'user-agent':'algo-sdk'});
const txid = algod.sendRawTransaction(transaction_group.signed_transactions)

Or, using the convenience method of the TinymanClient:

const result = client.submit(transaction_group, true)

This method submits the signed transactions and optionally waits for confirmation.

License

tinyman-py-sdk is licensed under a MIT license except for the exceptions listed below. See the LICENSE file for details.

Exceptions

src/asc.json is covered by the license here: https://github.com/tinymanorg/tinyman-contracts-v1/blob/main/LICENSE