Skip to content

Commit

Permalink
Merge pull request #30 from TreasureProject/develop
Browse files Browse the repository at this point in the history
v0.2.4
  • Loading branch information
alecananian authored Apr 8, 2024
2 parents 3537ff4 + e93e504 commit 48d4b07
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Assets/Treasure/Example/Scripts/HarvesterUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ User Details

DepositBtn.interactable = _harvester.userMagicBalance >= _magicAmount;
WithdrawBtn.interactable = _harvester.userMagicStaked >= _magicAmount;
StakeCharactersBtn.interactable = _harvester.userInventoryCharacters.Count > 0;
StakeCharactersBtn.interactable = _harvester.userInventoryCharacters != null && _harvester.userInventoryCharacters.Count > 0;
UnstakeCharactersBtn.interactable = _harvester.userCharactersStaked > 0;
}

Expand Down
54 changes: 54 additions & 0 deletions Assets/Treasure/TDK/Runtime/API/Corruption.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Threading.Tasks;

namespace Treasure
{
[Serializable]
public struct CorruptionRemovalRecipe
{
public struct Item
{
public string address;
public List<int> tokenIds;
public BigInteger amount;
public string customHandler;
}

public string id;
public BigInteger corruptionRemoved;
public List<Item> items;
}

public struct CorruptionRemovalRequest
{
public string recipeId;
public BigInteger[] tokenIds;
}

public struct CorruptionRemoval
{
public string requestId;
// TODO: change this to enum? Started | Ready
public string status;
}

[Serializable]
public struct HarvesterCorruptionRemoval
{
public List<CorruptionRemovalRecipe> corruptionRemovalRecipes;
public List<InventoryToken> userInventoryCorruptionRemovalRecipeItems;
public List<CorruptionRemoval> userCorruptionRemovals;
}

public partial class API
{
public async Task<HarvesterCorruptionRemoval> GetHarvesterCorruptionRemoval(string id)
{
var response = await Get($"/harvesters/{id}/corruption-removal");
return JsonConvert.DeserializeObject<HarvesterCorruptionRemoval>(response);
}
}
}
11 changes: 11 additions & 0 deletions Assets/Treasure/TDK/Runtime/API/Corruption.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions Assets/Treasure/TDK/Runtime/API/Harvester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ public struct Booster
public int endTimestamp;
}

public struct CorruptionRemovalRecipe
{
public struct Item
{
public string address;
public List<int> tokenIds;
public BigInteger amount;
public string customHandler;
}

public string id;
public BigInteger corruptionRemoved;
public List<Item> items;
}

public string id;
public string nftHandlerAddress;
public string permitsStakingRulesAddress;
Expand All @@ -46,7 +31,6 @@ public struct Item
public int boostersMaxStakeable;
public BigInteger magicMaxStakeable;
public BigInteger corruptionMaxGenerated;
public List<CorruptionRemovalRecipe> corruptionRemovalRecipes;
public double totalEmissionsActivated;
public BigInteger totalMagicStaked;
public double totalBoost;
Expand Down
55 changes: 48 additions & 7 deletions Assets/Treasure/TDK/Runtime/Bridgeworld/TDK.Bridgeworld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System.Collections.Generic;
using System;
using System.Linq;
using Nethereum.ABI;
using Nethereum.Hex.HexConvertors.Extensions;

#if TDK_THIRDWEB
using Thirdweb;
Expand Down Expand Up @@ -102,13 +104,20 @@ public async Task<Transaction> WithdrawMagic(BigInteger amount)

public async Task<Transaction> WithdrawAllMagic()
{
TDKLogger.Log($"Withdrawing all MAGIC from Harvester");
var transaction = await TDK.API.WriteTransaction(
address: id,
functionName: "withdrawAndHarvestAll",
args: new string[] { }
);
return await TDK.Common.WaitForTransaction(transaction.queueId);
// If user has MAGIC to claim, use the withdrawAndHarvestAll function
if (userMagicRewardsClaimable > 0)
{
TDKLogger.Log($"Withdrawing and harvesting all MAGIC from Harvester");
var transaction = await TDK.API.WriteTransaction(
address: id,
functionName: "withdrawAndHarvestAll",
args: new string[] { }
);
return await TDK.Common.WaitForTransaction(transaction.queueId);
}

// No MAGIC to calim, just call withdraw with full amount
return await WithdrawMagic(userMagicStaked);
}

public async Task<Transaction> ClaimMagicRewards()
Expand Down Expand Up @@ -201,5 +210,37 @@ public async Task Deposit(BigInteger amount)
await Task.FromResult<string>(string.Empty);
#endif
}

public async Task<Transaction> StartCorruptionRemovals(List<CorruptionRemovalRequest> requests)
{
TDKLogger.Log($"Starting {requests.Count} Corruption removals");
var args = new object[requests.Count, 3];
for (var i = 0; i < requests.Count; i++)
{
var request = requests[i];
var customData = new ABIEncode().GetABIEncoded(new ABIValue("uint256[]", request.tokenIds)).ToHex(true);
args[i, 0] = id;
args[i, 1] = request.recipeId;
args[i, 2] = new string[] { customData };
}

var transaction = await TDK.API.WriteTransaction(
contract: Contract.CorruptionRemoval,
functionName: "startRemovingCorruption",
args: new object[] { args }
);
return await TDK.Common.WaitForTransaction(transaction.queueId);
}

public async Task<Transaction> EndCorruptionRemovals(List<string> requestIds)
{
TDKLogger.Log("Ending corruption removals");
var transaction = await TDK.API.WriteTransaction(
contract: Contract.CorruptionRemoval,
functionName: "endRemovingCorruption",
args: new object[] { requestIds }
);
return await TDK.Common.WaitForTransaction(transaction.queueId);
}
}
}
14 changes: 10 additions & 4 deletions Assets/Treasure/TDK/Runtime/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public enum Contract
Consumables,
Legions,
Treasures,
CorruptionRemoval,
ERC1155TokenSetCorruptionHandler,
HarvesterEmberwing,
ZeeverseZee,
ZeeverseItems,
Expand All @@ -25,9 +27,9 @@ public static class Constants
public const string PPREFS_EPOCH_DIFF = "treasure.epoch_diff";

// misc values
public const string SERVER_TIME_ENDPOINT_DEV = "https://darkmatter-dev.treasure.lol/utils/time-unix"; //"https://trove-api.treasure.lol/v1/time";
public const string SERVER_TIME_ENDPOINT_PROD = "https://darkmatter.treasure.lol/utils/time-unix"; //"https://trove-api.treasure.lol/v1/time";
public const string SERVER_TIME_ENDPOINT_DEV = "https://darkmatter-dev.treasure.lol/utils/time-unix"; //"https://trove-api.treasure.lol/v1/time";
public const string SERVER_TIME_ENDPOINT_PROD = "https://darkmatter.treasure.lol/utils/time-unix"; //"https://trove-api.treasure.lol/v1/time";

// contract accresses
public static Dictionary<ChainId, Dictionary<Contract, string>> ContractAddresses = new Dictionary<ChainId, Dictionary<Contract, string>> {
{
Expand All @@ -36,7 +38,9 @@ public static class Constants
{ Contract.Consumables, "0xf3d00a2559d84de7ac093443bcaada5f4ee4165c" },
{ Contract.Legions, "0xfe8c1ac365ba6780aec5a985d989b327c27670a1" },
{ Contract.Treasures, "0xebba467ecb6b21239178033189ceae27ca12eadf" },
{ Contract.HarvesterEmberwing, "" },
{ Contract.CorruptionRemoval, "0xebba467ecb6b21239178033189ceae27ca12eadf" },
{ Contract.ERC1155TokenSetCorruptionHandler, "0x3c62778d8e01ed17c1048b64edaf121d36c71a4e" },
{ Contract.HarvesterEmberwing, "0x08f3533acdf2b9c400204056f771bdd6f1f1c200" },
{ Contract.ZeeverseZee, "0x094fa8ae08426ab180e71e60fa253b079e13b9fe" },
{ Contract.ZeeverseItems, "0x58318bceaa0d249b62fad57d134da7475e551b47" },
}
Expand All @@ -47,6 +51,8 @@ public static class Constants
{ Contract.Consumables, "0x9d012712d24C90DDEd4574430B9e6065183896BE" },
{ Contract.Legions, "0xd144e34c3c0a8e605e9d45792380841a2169dd8f" },
{ Contract.Treasures, "0xfe592736200d7545981397ca7a8e896ac0c166d4" },
{ Contract.CorruptionRemoval, "0xdd8b0dd8128873049b1d528262724bde600f5be2" },
{ Contract.ERC1155TokenSetCorruptionHandler, "0x937817e7fe8e3b3543db46f14473d5f110a79ece" },
{ Contract.HarvesterEmberwing, "0x816c0717cf263e7da4cd33d4979ad15dbb70f122" },
{ Contract.ZeeverseZee, "0xb1af672c7e0e8880c066ecc24930a12ff2ee8534" },
{ Contract.ZeeverseItems, "0xfaad5aa3209ab1b25ede22ed4da5521538b649fa" },
Expand Down
2 changes: 1 addition & 1 deletion Assets/Treasure/TDK/Runtime/TDKVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public static class TDKVersion
{
public static string name = "tdk-unity";
public static string version = "0.2.3";
public static string version = "0.2.4";
}
}

0 comments on commit 48d4b07

Please sign in to comment.