Skip to content

Commit

Permalink
Merge pull request #172 from eforest-finance/feature/approveoptimize
Browse files Browse the repository at this point in the history
Approve optimize
  • Loading branch information
fyannch authored Jul 25, 2024
2 parents b101522 + d4cf510 commit 9c73745
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
5 changes: 4 additions & 1 deletion contract/Forest/ForestContractConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ public partial class ForestContract
public const int DefaultMaxBatchCancelListCount= 20;
public const string CollectionSymbolSuffix = "0";
public const string SymbolSeparator = "-";

public const long DefaultApproveAllowance = 10000;
public const long MaxApproveAllowance = 9223372000000000000;


}
10 changes: 6 additions & 4 deletions contract/Forest/ForestContract_Sellers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,14 @@ public override Empty ListWithFixedPrice(ListWithFixedPriceInput input)
var collectionAllowance = State.ListedNFTTotalAmountMap[collectionSymbol][Context.Sender];
if (collectionAllowance == null || collectionAllowance == "")
{
State.ListedNFTTotalAmountMap[collectionSymbol][Context.Sender] =
Math.Max(allowance, input.Quantity).ToString();
var listedNFTTotalAmount = (allowance >= MaxApproveAllowance) ? input.Quantity : Math.Max(allowance, input.Quantity);
State.ListedNFTTotalAmountMap[collectionSymbol][Context.Sender] = listedNFTTotalAmount.ToString();
}
else
{
var originQuantity = long.Parse(collectionAllowance);
var originQuantity = (long.Parse(collectionAllowance) >= MaxApproveAllowance)
? DefaultApproveAllowance
: long.Parse(collectionAllowance);
State.ListedNFTTotalAmountMap[collectionSymbol][Context.Sender] =
(input.Quantity + originQuantity).ToString();
}
Expand Down Expand Up @@ -238,7 +240,7 @@ private Empty SingleDelist(DelistInput input)
var originQuantity = long.Parse(collectionAllowance);
var resultQuantity = originQuantity - input.Quantity;
State.ListedNFTTotalAmountMap[collectionSymbol][Context.Sender] =
(resultQuantity >= 0 ? resultQuantity.ToString() : "");
(resultQuantity >= 0 ? resultQuantity.ToString() : "0");
}

return new Empty();
Expand Down
4 changes: 2 additions & 2 deletions contract/Forest/ForestContract_Views.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ public override GetTotalEffectiveListedNFTAmountOutput GetTotalEffectiveListedNF
{
Symbol = input.Symbol,
Allowance = allowance,
TotalAmount = Math.Max(allowance,totalAmount)
TotalAmount = (allowance >= MaxApproveAllowance) ? totalAmount : Math.Max(allowance,totalAmount)
};
}

var getTotalEffectiveListedNftAmountOutput = new GetTotalEffectiveListedNFTAmountOutput()
{
Symbol = input.Symbol,
Allowance = allowance,
TotalAmount = long.Parse(collectionAllowance)
TotalAmount = (long.Parse(collectionAllowance) >= MaxApproveAllowance) ? DefaultApproveAllowance : long.Parse(collectionAllowance)
};

return getTotalEffectiveListedNftAmountOutput;
Expand Down

0 comments on commit 9c73745

Please sign in to comment.