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.

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

Usage

Swapping

Swap one asset for another in an existing pool.

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

// 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.AlgosToMicroalgos(1.0);
var quote = pool.CalculateFixedInputSwapQuote(new AssetAmount(algo, amountIn), 0.05);

// Convert to action
var action = Swap.FromQuote(quote);

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

Minting

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

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

// 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.AlgosToMicroalgos(1.0);
var quote = pool.CalculateMintQuote(new AssetAmount(algo, amountIn), 0.05);

// Convert to action
var action = Mint.FromQuote(quote);

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

Burning

Exchange the liquidity pool asset for the pool assets.

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

// 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.05);

// Convert to action
var action = Burn.FromQuote(quote);

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

Redeeming

Redeem excess amounts from previous transactions.

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

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

// Redeem each amount
foreach (var quote in excessAmounts) {

	var action = Redeem.FromQuote(quote);
	var result = await client.RedeemAsync(account, action);
}

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

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.