GithubHelp home page GithubHelp logo

dotnet-yieldly-sdk's People

Contributors

geoffodonnell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dotnet-yieldly-sdk's Issues

Added command line 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.");
			 
		}


	}

}

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.