diff --git a/Assets/Treasure/Example/Scripts/HarvesterUI.cs b/Assets/Treasure/Example/Scripts/HarvesterUI.cs index 643bbdec..efce0ee2 100644 --- a/Assets/Treasure/Example/Scripts/HarvesterUI.cs +++ b/Assets/Treasure/Example/Scripts/HarvesterUI.cs @@ -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; } diff --git a/Assets/Treasure/TDK/Runtime/API/Corruption.cs b/Assets/Treasure/TDK/Runtime/API/Corruption.cs new file mode 100644 index 00000000..bfa40a5e --- /dev/null +++ b/Assets/Treasure/TDK/Runtime/API/Corruption.cs @@ -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 tokenIds; + public BigInteger amount; + public string customHandler; + } + + public string id; + public BigInteger corruptionRemoved; + public List 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 corruptionRemovalRecipes; + public List userInventoryCorruptionRemovalRecipeItems; + public List userCorruptionRemovals; + } + + public partial class API + { + public async Task GetHarvesterCorruptionRemoval(string id) + { + var response = await Get($"/harvesters/{id}/corruption-removal"); + return JsonConvert.DeserializeObject(response); + } + } +} diff --git a/Assets/Treasure/TDK/Runtime/API/Corruption.cs.meta b/Assets/Treasure/TDK/Runtime/API/Corruption.cs.meta new file mode 100644 index 00000000..72c39cd0 --- /dev/null +++ b/Assets/Treasure/TDK/Runtime/API/Corruption.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c18fb8fea7e1d4d7684acc01b74cbe14 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Treasure/TDK/Runtime/API/Harvester.cs b/Assets/Treasure/TDK/Runtime/API/Harvester.cs index 38e14679..71b195ea 100644 --- a/Assets/Treasure/TDK/Runtime/API/Harvester.cs +++ b/Assets/Treasure/TDK/Runtime/API/Harvester.cs @@ -16,21 +16,6 @@ public struct Booster public int endTimestamp; } - public struct CorruptionRemovalRecipe - { - public struct Item - { - public string address; - public List tokenIds; - public BigInteger amount; - public string customHandler; - } - - public string id; - public BigInteger corruptionRemoved; - public List items; - } - public string id; public string nftHandlerAddress; public string permitsStakingRulesAddress; @@ -46,7 +31,6 @@ public struct Item public int boostersMaxStakeable; public BigInteger magicMaxStakeable; public BigInteger corruptionMaxGenerated; - public List corruptionRemovalRecipes; public double totalEmissionsActivated; public BigInteger totalMagicStaked; public double totalBoost; diff --git a/Assets/Treasure/TDK/Runtime/Bridgeworld/TDK.Bridgeworld.cs b/Assets/Treasure/TDK/Runtime/Bridgeworld/TDK.Bridgeworld.cs index 591dbd4a..1aa3f2a9 100644 --- a/Assets/Treasure/TDK/Runtime/Bridgeworld/TDK.Bridgeworld.cs +++ b/Assets/Treasure/TDK/Runtime/Bridgeworld/TDK.Bridgeworld.cs @@ -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; @@ -102,13 +104,20 @@ public async Task WithdrawMagic(BigInteger amount) public async Task 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 ClaimMagicRewards() @@ -201,5 +210,37 @@ public async Task Deposit(BigInteger amount) await Task.FromResult(string.Empty); #endif } + + public async Task StartCorruptionRemovals(List 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 EndCorruptionRemovals(List 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); + } } } diff --git a/Assets/Treasure/TDK/Runtime/Common/Constants.cs b/Assets/Treasure/TDK/Runtime/Common/Constants.cs index e0a8e4ab..b370f81f 100644 --- a/Assets/Treasure/TDK/Runtime/Common/Constants.cs +++ b/Assets/Treasure/TDK/Runtime/Common/Constants.cs @@ -14,6 +14,8 @@ public enum Contract Consumables, Legions, Treasures, + CorruptionRemoval, + ERC1155TokenSetCorruptionHandler, HarvesterEmberwing, ZeeverseZee, ZeeverseItems, @@ -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> ContractAddresses = new Dictionary> { { @@ -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" }, } @@ -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" }, diff --git a/Assets/Treasure/TDK/Runtime/TDKVersion.cs b/Assets/Treasure/TDK/Runtime/TDKVersion.cs index 361222fe..63892cd7 100644 --- a/Assets/Treasure/TDK/Runtime/TDKVersion.cs +++ b/Assets/Treasure/TDK/Runtime/TDKVersion.cs @@ -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"; } }