This library provides access to the Tinyman AMM on the Algorand blockchain.
- The V1 pools should NOT be used as they are vulnerable to a liquidity draining attack.
- See the announcement here for more information.
Releases are available at nuget.org.
PM> Install-Package -Id Tinyman
dotnet add package Tinyman
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);
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);
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);
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);
}
Full examples, simple and verbose, can be found in /example.
dotnet-tinyman-sdk build pipelines use the Assembly Info Task extension.
dotnet-tinyman-sdk is licensed under a MIT license except for the exceptions listed below. See the LICENSE file for details.
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.
Nothing in the repo constitutes professional and/or financial advice. Use this SDK at your own risk.