GithubHelp home page GithubHelp logo

dotnet-tinyman-sdk's Introduction

dotnet-tinyman-sdk

Dev CI Status NuGet version Donate Algo

Overview

This library provides access to the Tinyman AMM on the Algorand blockchain.

Release Notes

  • v2.2.0.1
    • Updates Algorand SDK to 2.0.0.*; updates other dependencies
  • v2.1.0.1
    • Adds support for re-keyed accounts
  • v2.0.0.1
    • Adds support for Tinyman V2
    • Significant refactor; removes 'Action' classes
  • v1.0.0.2
    • Updates Algorand SDK to 1.0.0.15; target net6.0

Known Issues

High Severity

  • The V1 pools should NOT be used as they are vulnerable to a liquidity draining attack.
    • See the announcement here for more information.

Installation

Releases are available at nuget.org.

Package Manager

PM> Install-Package -Id Tinyman

.NET CLI

dotnet add package Tinyman

Getting Started

Other than initializing a client instance, no specific setup is required. However, if your application generates a high volume of requests it is suggested that you setup your own Algod node. See the links below for more information:

Notes

Default clients connect to Algod nodes maintained by AlgoNode.io (Thanks AlgoNode!). It's important that your application handle rate limiting (HTTP 429) responses by decreasing the frequency of requests. See this guide for a discussion on the topic.

Usage

Swapping

Swap one asset for another in an existing pool.

// Initialize the client
var client = new TinymanV2TestnetClient(); // or TinymanV1TestnetClient();

// Get the assets
var tinyUsdc = await client.FetchAssetAsync(21582668);
var algo = await client.FetchAssetAsync(0);

// Get the pool
var pool = await client.FetchPoolAsync(algo, tinyUsdc);

// Get a quote to swap 1 Algo for tinyUsdc
var amountIn = Algorand.Utils.Utils.AlgosToMicroalgos(1.0);
var quote = pool.CalculateFixedInputSwapQuote(new AssetAmount(algo, amountIn), 0.005);

// Perform the swap
var result = await client.SwapAsync(account, quote);

Minting

Add assets to an existing pool in exchange for the liquidity pool asset.

// Initialize the client
var client = new TinymanV2TestnetClient(); // or TinymanV1TestnetClient();

// Get the assets
var tinyUsdc = await client.FetchAssetAsync(21582668);
var algo = await client.FetchAssetAsync(0);

// Get the pool
var pool = await client.FetchPoolAsync(algo, tinyUsdc);

// Get a quote to add 1 Algo and the corresponding tinyUsdc amount to the pool
var amountIn = Algorand.Utils.Utils.AlgosToMicroalgos(1.0);
var quote = pool.CalculateMintQuote(new AssetAmount(algo, amountIn), 0.005);

// Perform the minting
var result = await client.MintAsync(account, quote);

Burning

Exchange the liquidity pool asset for the pool assets.

// Initialize the client
var client = new TinymanV2TestnetClient(); // or TinymanV1TestnetClient();

// Get the assets
var tinyUsdc = await client.FetchAssetAsync(21582668);
var algo = await client.FetchAssetAsync(0);

// Get the pool
var pool = await client.FetchPoolAsync(algo, tinyUsdc);

// Get a quote to swap the entire liquidity pool asset balance for pooled assets
var amount = client.GetBalance(account.Address, pool.LiquidityAsset);
var quote = pool.CalculateBurnQuote(amount, 0.005);

// Perform the burning
var result = await client.BurnAsync(account, quote);

Redeeming (V1 only)

Redeem excess amounts from previous transactions.

// Initialize the client
var client = new TinymanV1TestnetClient();

// Fetch the amounts
var excessAmounts = await client.FetchExcessAmountsAsync(account.Address);

// Redeem each amount
foreach (var quote in excessAmounts) {
	var result = await client.RedeemAsync(account, quote);
}

Examples

Full examples, simple and verbose, can be found in /example.

Build

dotnet-tinyman-sdk build pipelines use the Assembly Info Task extension.

License

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

Exceptions

src\Tinyman\V1\asc.json is currently unlicensed. It may be used by this SDK but may not be used in any other way or be distributed separately without the express permission of Tinyman. It is used here with permission.

Disclaimer

Nothing in the repo constitutes professional and/or financial advice. Use this SDK at your own risk.

dotnet-tinyman-sdk's People

Contributors

gbosystems avatar geoffodonnell avatar killyp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dotnet-tinyman-sdk's Issues

Possible MintQuote Bug - Checking both asset amounts are equal in case of new mint

In case the liquidity is 0, the code compares the input asset amounts instead of checking that they are non null values.

https://github.com/geoffodonnell/dotnet-tinyman-sdk/blob/main/src/Tinyman/V1/Model/PoolExtensions.cs#L183

// Pool exists does not contain assets
} else {

if (amount1 != amount2) {
	throw new Exception("Amounts required for both assets for first mint!");
}

liquidityAssetAmount = Convert.ToUInt64(
	Math.Sqrt((double)BigInteger.Multiply(amount1.Amount, amount2.Amount)) - 1000);
slippage = 0;
}

Pool token unit name for V1_1 bootstrapping

The unit name for pool in bootstrapping is set to TM1POOL11 instead of TMPOOL11

if (validatorAppId == Constant.TestnetValidatorAppIdV1_0 ||
				validatorAppId == Constant.MainnetValidatorAppIdV1_0) {
				unitName = "TM1POOL";
				name = $"Tinyman Pool {asset1.UnitName}-{asset2.UnitName}";
			} else {
				unitName = "TM1POOL11";
				name = $"TinymanPool1.1 {asset1.UnitName}-{asset2.UnitName}";
			}

Python sdk - https://github.com/tinymanorg/tinyman-py-sdk/blob/v1-1-updates/tinyman/v1/bootstrap.py#L40

FetchAssetAsync uses FetchAssetFromApiAsync

Hi,

there is issue with FetchAssetAsync. The algod has dropped support for asa fetch from the api, and was transformed only for use by the indexer.

https://algoexplorer.io/api-dev/v2

if tinymanMainnetClient.FetchAssetAsync returns 403, it means your algod does not support it any longer.

i am afraid the only solution is to add the indexer to the library

Error while deserailzation

Looks like algorand api are no longer returning "creator" field for assets. This fields is required, so all tinyman api like GetBalance, FetchAssets are failing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.