Skip to content

Commit

Permalink
Merge pull request #23 from aboutcircles/feat/contractrs-v0.3.7
Browse files Browse the repository at this point in the history
Feat/contractrs v0.3.7
  • Loading branch information
jaensen authored Oct 13, 2024
2 parents a7f2700 + 3400947 commit c204765
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 170 deletions.
30 changes: 15 additions & 15 deletions Circles.Index.CirclesV2.StandardTreasury/DatabaseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public class DatabaseSchema : IDatabaseSchema
EventSchema.FromSolidity("CrcV2",
"event CreateVault(address indexed group, address indexed vault)");

public static readonly EventSchema GroupMintSingle =
public static readonly EventSchema CollateralLockedSingle =
EventSchema.FromSolidity("CrcV2",
"event GroupMintSingle(address indexed group, uint256 indexed id, uint256 value, bytes userData)");
"event CollateralLockedSingle(address indexed group, uint256 indexed id, uint256 value, bytes userData)");

public static readonly EventSchema GroupMintBatch =
new EventSchema("CrcV2", "GroupMintBatch",
Keccak.Compute("GroupMintBatch(address,uint256[],uint256[],bytes)").BytesToArray(),
public static readonly EventSchema CollateralLockedBatch =
new EventSchema("CrcV2", "CollateralLockedBatch",
Keccak.Compute("CollateralLockedBatch(address,uint256[],uint256[],bytes)").BytesToArray(),
new List<EventFieldSchema>()
{
new("blockNumber", ValueTypes.Int, true),
Expand Down Expand Up @@ -80,12 +80,12 @@ public class DatabaseSchema : IDatabaseSchema
CreateVault
},
{
("CrcV2", "GroupMintSingle"),
GroupMintSingle
("CrcV2", "CollateralLockedSingle"),
CollateralLockedSingle
},
{
("CrcV2", "GroupMintBatch"),
GroupMintBatch
("CrcV2", "CollateralLockedBatch"),
CollateralLockedBatch
},
{
("CrcV2", "GroupRedeem"),
Expand Down Expand Up @@ -116,9 +116,9 @@ public DatabaseSchema()
{ "vault", e => e.Vault }
});

EventDtoTableMap.Add<GroupMintSingle>(("CrcV2", "GroupMintSingle"));
SchemaPropertyMap.Add(("CrcV2", "GroupMintSingle"),
new Dictionary<string, Func<GroupMintSingle, object?>>
EventDtoTableMap.Add<CollateralLockedSingle>(("CrcV2", "CollateralLockedSingle"));
SchemaPropertyMap.Add(("CrcV2", "CollateralLockedSingle"),
new Dictionary<string, Func<CollateralLockedSingle, object?>>
{
{ "blockNumber", e => e.BlockNumber },
{ "timestamp", e => e.Timestamp },
Expand All @@ -131,9 +131,9 @@ public DatabaseSchema()
{ "userData", e => e.UserData }
});

EventDtoTableMap.Add<GroupMintBatch>(("CrcV2", "GroupMintBatch"));
SchemaPropertyMap.Add(("CrcV2", "GroupMintBatch"),
new Dictionary<string, Func<GroupMintBatch, object?>>
EventDtoTableMap.Add<CollateralLockedBatch>(("CrcV2", "CollateralLockedBatch"));
SchemaPropertyMap.Add(("CrcV2", "CollateralLockedBatch"),
new Dictionary<string, Func<CollateralLockedBatch, object?>>
{
{ "blockNumber", e => e.BlockNumber },
{ "timestamp", e => e.Timestamp },
Expand Down
4 changes: 2 additions & 2 deletions Circles.Index.CirclesV2.StandardTreasury/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record CreateVault(
string Group,
string Vault) : IIndexEvent;

public record GroupMintSingle(
public record CollateralLockedSingle(
long BlockNumber,
long Timestamp,
int TransactionIndex,
Expand All @@ -23,7 +23,7 @@ public record GroupMintSingle(
UInt256 Value,
byte[] UserData) : IIndexEvent;

public record GroupMintBatch(
public record CollateralLockedBatch(
long BlockNumber,
long Timestamp,
int TransactionIndex,
Expand Down
16 changes: 8 additions & 8 deletions Circles.Index.CirclesV2.StandardTreasury/LogParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace Circles.Index.CirclesV2.StandardTreasury;
public class LogParser(Address standardTreasuryAddress) : ILogParser
{
private readonly Hash256 _createVaultTopic = new(DatabaseSchema.CreateVault.Topic);
private readonly Hash256 _groupMintSingleTopic = new(DatabaseSchema.GroupMintSingle.Topic);
private readonly Hash256 _groupMintBatchTopic = new(DatabaseSchema.GroupMintBatch.Topic);
private readonly Hash256 _groupMintSingleTopic = new(DatabaseSchema.CollateralLockedSingle.Topic);
private readonly Hash256 _groupMintBatchTopic = new(DatabaseSchema.CollateralLockedBatch.Topic);
private readonly Hash256 _groupRedeemTopic = new(DatabaseSchema.GroupRedeem.Topic);
private readonly Hash256 _groupRedeemCollateralReturnTopic = new(DatabaseSchema.GroupRedeemCollateralReturn.Topic);
private readonly Hash256 _groupRedeemCollateralBurnTopic = new(DatabaseSchema.GroupRedeemCollateralBurn.Topic);
Expand Down Expand Up @@ -41,12 +41,12 @@ public IEnumerable<IIndexEvent> ParseLog(Block block, Transaction transaction, T

if (topic == _groupMintSingleTopic)
{
yield return GroupMintSingle(block, receipt, log, logIndex);
yield return CollateralLockedSingle(block, receipt, log, logIndex);
}

if (topic == _groupMintBatchTopic)
{
foreach (var batchEvent in GroupMintBatch(block, receipt, log, logIndex))
foreach (var batchEvent in CollateralLockedBatch(block, receipt, log, logIndex))
{
yield return batchEvent;
}
Expand Down Expand Up @@ -90,14 +90,14 @@ private CreateVault CreateVault(Block block, TxReceipt receipt, LogEntry log, in
vaultAddress);
}

private GroupMintSingle GroupMintSingle(Block block, TxReceipt receipt, LogEntry log, int logIndex)
private CollateralLockedSingle CollateralLockedSingle(Block block, TxReceipt receipt, LogEntry log, int logIndex)
{
string groupAddress = "0x" + log.Topics[1].ToString().Substring(Consts.AddressEmptyBytesPrefixLength);
UInt256 id = new UInt256(log.Topics[2].Bytes, true);
UInt256 value = new UInt256(log.Data.Slice(0, 32), true);
byte[] userData = log.Data.Slice(32);

return new GroupMintSingle(
return new CollateralLockedSingle(
block.Number,
(long)block.Timestamp,
receipt.Index,
Expand All @@ -109,7 +109,7 @@ private GroupMintSingle GroupMintSingle(Block block, TxReceipt receipt, LogEntry
userData);
}

private IEnumerable<GroupMintBatch> GroupMintBatch(Block block, TxReceipt receipt, LogEntry log, int logIndex)
private IEnumerable<CollateralLockedBatch> CollateralLockedBatch(Block block, TxReceipt receipt, LogEntry log, int logIndex)
{
string groupAddress = "0x" + log.Topics[1].ToString().Substring(Consts.AddressEmptyBytesPrefixLength);

Expand Down Expand Up @@ -138,7 +138,7 @@ private IEnumerable<GroupMintBatch> GroupMintBatch(Block block, TxReceipt receip

for (int i = 0; i < idsLength; i++)
{
yield return new GroupMintBatch(
yield return new CollateralLockedBatch(
block.Number,
(long)block.Timestamp,
receipt.Index,
Expand Down
54 changes: 39 additions & 15 deletions Circles.Index.CirclesV2/DatabaseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DatabaseSchema : IDatabaseSchema
"event RegisterGroup(address indexed group, address indexed mint, address indexed treasury, string indexed name, string indexed symbol)");

public static readonly EventSchema RegisterHuman =
EventSchema.FromSolidity("CrcV2", "event RegisterHuman(address indexed avatar)");
EventSchema.FromSolidity("CrcV2", "event RegisterHuman(address indexed avatar, address indexed inviter)");

public static readonly EventSchema RegisterOrganization =
EventSchema.FromSolidity("CrcV2",
Expand All @@ -33,24 +33,29 @@ public class DatabaseSchema : IDatabaseSchema
public static readonly EventSchema Trust =
EventSchema.FromSolidity("CrcV2",
"event Trust(address indexed truster, address indexed trustee, uint256 expiryTime)");

public static readonly EventSchema DiscountCost =
EventSchema.FromSolidity("CrcV2",
"event DiscountCost(address indexed account, uint256 indexed id, uint256 discountCost)");

//
// public static readonly EventSchema TransferSingle = EventSchema.FromSolidity(
// "CrcV2",
// "event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 indexed id, uint256 value)");
public static readonly EventSchema TransferSingle = new("CrcV2", "TransferSingle",
public static readonly EventSchema TransferSingle = new("CrcV2", "TransferSingle",
Keccak.Compute("TransferSingle(address,address,address,uint256,uint256)").BytesToArray(), [
new("blockNumber", ValueTypes.Int, true),
new("timestamp", ValueTypes.Int, true),
new("transactionIndex", ValueTypes.Int, true),
new("logIndex", ValueTypes.Int, true),
new("transactionHash", ValueTypes.String, true),
new("operator", ValueTypes.Address, true),
new("from", ValueTypes.Address, true),
new("to", ValueTypes.Address, true),
new("id", ValueTypes.BigInt, true),
new("value", ValueTypes.BigInt, false),
new("tokenAddress", ValueTypes.Address, true)
]);
new("blockNumber", ValueTypes.Int, true),
new("timestamp", ValueTypes.Int, true),
new("transactionIndex", ValueTypes.Int, true),
new("logIndex", ValueTypes.Int, true),
new("transactionHash", ValueTypes.String, true),
new("operator", ValueTypes.Address, true),
new("from", ValueTypes.Address, true),
new("to", ValueTypes.Address, true),
new("id", ValueTypes.BigInt, true),
new("value", ValueTypes.BigInt, false),
new("tokenAddress", ValueTypes.Address, true)
]);

// public static readonly EventSchema URI =
// EventSchema.FromSolidity("CrcV2", "event URI(string value, uint256 indexed id)");
Expand Down Expand Up @@ -207,6 +212,10 @@ public class DatabaseSchema : IDatabaseSchema
{
("CrcV2", "StreamCompleted"),
StreamCompleted
},
{
("CrcV2", "DiscountCost"),
DiscountCost
}
};

Expand Down Expand Up @@ -265,7 +274,8 @@ public DatabaseSchema()
{ "transactionIndex", e => e.TransactionIndex },
{ "logIndex", e => e.LogIndex },
{ "transactionHash", e => e.TransactionHash },
{ "avatar", e => e.Avatar }
{ "avatar", e => e.Avatar },
{ "inviter", e => e.Inviter }
});

EventDtoTableMap.Add<RegisterOrganization>(("CrcV2", "RegisterOrganization"));
Expand Down Expand Up @@ -472,5 +482,19 @@ public DatabaseSchema()
{ "amount", e => (BigInteger)e.Amount },
{ "tokenAddress", e => ConversionUtils.UInt256ToAddress(e.Id).ToString(true, false) }
});

EventDtoTableMap.Add<DiscountCost>(("CrcV2", "DiscountCost"));
SchemaPropertyMap.Add(("CrcV2", "DiscountCost"),
new Dictionary<string, Func<DiscountCost, object?>>
{
{ "blockNumber", e => e.BlockNumber },
{ "timestamp", e => e.Timestamp },
{ "transactionIndex", e => e.TransactionIndex },
{ "logIndex", e => e.LogIndex },
{ "transactionHash", e => e.TransactionHash },
{ "account", e => e.Account },
{ "id", e => (BigInteger)e.Id },
{ "discountCost", e => (BigInteger)e.Cost }
});
}
}
15 changes: 13 additions & 2 deletions Circles.Index.CirclesV2/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public record RegisterHuman(
int TransactionIndex,
int LogIndex,
string TransactionHash,
string Avatar) : IIndexEvent;
string Avatar,
string Inviter) : IIndexEvent;

public record PersonalMint(
long BlockNumber,
Expand Down Expand Up @@ -186,4 +187,14 @@ public record StreamCompleted(
string From,
string To,
UInt256 Id,
UInt256 Amount) : IIndexEvent;
UInt256 Amount) : IIndexEvent;

public record DiscountCost(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
string Account,
UInt256 Id,
UInt256 Cost) : IIndexEvent;
27 changes: 26 additions & 1 deletion Circles.Index.CirclesV2/LogParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class LogParser(Address v2HubAddress, Address erc20LiftAddress) : ILogPar
private readonly Hash256 _depositDemurraged = new(DatabaseSchema.DepositDemurraged.Topic);
private readonly Hash256 _withdrawDemurraged = new(DatabaseSchema.WithdrawDemurraged.Topic);
private readonly Hash256 _streamCompletedTopic = new(DatabaseSchema.StreamCompleted.Topic);
private readonly Hash256 _discountCostTopic = new(DatabaseSchema.DiscountCost.Topic);

public static readonly ConcurrentDictionary<Address, object?> Erc20WrapperAddresses = new();

Expand Down Expand Up @@ -166,6 +167,11 @@ public IEnumerable<IIndexEvent> ParseLog(Block block, Transaction transaction, T
yield return streamCompleted;
}
}

if (topic == _discountCostTopic)
{
yield return DiscountCost(block, receipt, log, logIndex);
}
}

if (log.LoggersAddress == erc20LiftAddress)
Expand Down Expand Up @@ -350,14 +356,16 @@ private RegisterGroup CrcV2RegisterGroup(Block block, TxReceipt receipt, LogEntr
private RegisterHuman CrcV2RegisterHuman(Block block, TxReceipt receipt, LogEntry log, int logIndex)
{
string humanAddress = "0x" + log.Topics[1].ToString().Substring(Consts.AddressEmptyBytesPrefixLength);
string inviterAddress = "0x" + log.Topics[2].ToString().Substring(Consts.AddressEmptyBytesPrefixLength);

return new RegisterHuman(
block.Number,
(long)block.Timestamp,
receipt.Index,
logIndex,
receipt.TxHash!.ToString(),
humanAddress);
humanAddress,
inviterAddress);
}

private PersonalMint CrcV2PersonalMint(Block block, TxReceipt receipt, LogEntry log, int logIndex)
Expand Down Expand Up @@ -496,6 +504,23 @@ private WithdrawDemurraged WithdrawDemurraged(Block block, TxReceipt receipt, Lo
inflationaryAmount);
}

private DiscountCost DiscountCost(Block block, TxReceipt receipt, LogEntry log, int logIndex)
{
string account = "0x" + log.Topics[1].ToString().Substring(Consts.AddressEmptyBytesPrefixLength);
UInt256 id = new UInt256(log.Topics[2].Bytes, true);
UInt256 discountCost = new UInt256(log.Data, true);

return new DiscountCost(
block.Number,
(long)block.Timestamp,
receipt.Index,
logIndex,
receipt.TxHash!.ToString(),
account,
id,
discountCost);
}

private IEnumerable<StreamCompleted> StreamCompleted(Block block, TxReceipt receipt, LogEntry log, int logIndex)
{
string operatorAddress = "0x" + log.Topics[1].ToString().Substring(Consts.AddressEmptyBytesPrefixLength);
Expand Down
Loading

0 comments on commit c204765

Please sign in to comment.