geoffodonnell / dotnet-yieldly-sdk Goto Github PK
View Code? Open in Web Editor NEWYieldly .NET SDK
License: MIT License
Yieldly .NET SDK
License: MIT License
Suggestion 1 would make fewer lines of code, and more flexibility. Suggestion 2 would make it easier to understand that "Deposit" means Stake or maybe a comment that confirms that functionality.
Not sure if you'd like to get this added, but command line
offers more flexibility. Not entirely complete yet, but the staking & withdrawal works.
using Algorand;
using Algorand.V2;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Configuration;
using System.Threading.Tasks;
using Yieldly.V1;
using CommandLine;
using System.Net;
using Newtonsoft.Json.Linq;
namespace Yieldly.YieldlyStakingWithdrawExample {
public class Program {
public class Options
{
[Option('p', "poolid", Required = true, HelpText = "Staking pool id")]
public ulong PoolId { get; set; }
[Option('a', "assetid", Required = false, HelpText = "Asset id")]
public ulong AssetId { get; set; }
[Option('n', "percent", Required = false, HelpText = "Percent of amount, example: 75 = 75%")]
public ulong Percent { get; set; }
[Option('t', "task", Required = false, HelpText = "s = stake, w = withdraw, c = claim")]
public string Task { get; set; }
}
public static async Task Main(string[] args) {
ulong poolid = 0;
ulong assetid = 1;
ulong percent = 0;
string task = "t";
Parser.Default.ParseArguments<Options>(args)
.WithParsed<Options>(o =>
{
poolid = o.PoolId;
assetid = o.AssetId;
percent = o.Percent;
task = o.Task;
});
var settings = ConfigurationManager.AppSettings;
var mnemonic = settings.Get("Account.Mnemonic");
if (String.IsNullOrWhiteSpace(mnemonic))
{
throw new Exception("'Account.Mnemonic' key is not set in App.Config.");
}
var account = new Account(mnemonic);
// Initialize the client
var url = Constant.AlgodMainnetHost;
var token = String.Empty;
var httpClient = HttpClientConfigurator.ConfigureHttpClient(url, token);
var client = new YieldlyClient(httpClient, url);
// Fetch all asa asset amount
var amounts = await client.FetchAmountsAsync(account.Address, poolid);
// Withdraw all YLDY currently deposited in the Yieldly staking pool
try
{
//Console.WriteLine(amounts.AmountAssetStaked);
switch (task)
{
case "w":
var result = await client.AsaStakingWithdrawAsync(poolid, account, amounts.AmountAssetStaked, assetid);
Console.WriteLine($"Asa staking withdraw complete, transaction ID: {result.TxId}");
break;
case "c":
var result1 = await client.AsaStakingClaimRewardAsync(poolid, account, amounts.StakingReward, assetid);
Console.WriteLine($"Asa staking claim complete, transaction ID: {result1.TxId}");
break;
case "s":
string json = new WebClient().DownloadString(url + "/idx2/v2/accounts/" + account.Address);
var assets = JObject.Parse(json)["account"]["assets"];
ulong assetValue = 0;
foreach (var asset in assets)
{
//var test3 = asset["asset-id"];
if (Convert.ToUInt64(asset["asset-id"]) == assetid)
{
assetValue = Convert.ToUInt64(asset["amount"]);
break;
}
}
var result2 = await client.AsaStakingDepositAsync(poolid, account, assetValue, assetid);
Console.WriteLine($"Asa staking stake complete, transaction ID: {result2.TxId}");
break;
}
}
catch (Exception ex)
{
Console.WriteLine($"An error occured: {ex.Message}");
}
Console.WriteLine("Execution complete.");
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.