Skip to content

Commit

Permalink
Merge pull request #18 from aboutcircles/feature/index-standard-treasury
Browse files Browse the repository at this point in the history
Feature/index standard treasury
  • Loading branch information
jaensen authored Aug 28, 2024
2 parents e5679da + de54000 commit 8ee3309
Show file tree
Hide file tree
Showing 34 changed files with 25,447 additions and 170 deletions.
2 changes: 1 addition & 1 deletion Circles.Index.CirclesV1/Circles.Index.CirclesV1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="Nethermind.Numerics.Int256" Version="1.2.0" />
<PackageReference Include="Nethermind.ReferenceAssemblies" Version="1.27.0" />
<PackageReference Include="Nethermind.ReferenceAssemblies" Version="1.28.0" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 8 additions & 2 deletions Circles.Index.CirclesV2.NameRegistry/LogParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ private RegisterShortName RegisterShortName(Block block, TxReceipt receipt, LogE
{
// event RegisterShortName(address indexed avatar, uint72 shortName, uint256 nonce)
string avatar = "0x" + log.Topics[1].ToString().Substring(Consts.AddressEmptyBytesPrefixLength);
UInt256 shortName = new UInt256(log.Topics[2].Bytes, true);
UInt256 nonce = new UInt256(log.Topics[3].Bytes, true);

byte[] shortNameBytes = new byte[9];
Array.Copy(log.Data, shortNameBytes, 9);
UInt256 shortName = new UInt256(shortNameBytes, true);

byte[] nonceBytes = new byte[32];
Array.Copy(log.Data, 9, nonceBytes, 0, 32);
UInt256 nonce = new UInt256(nonceBytes, true);

return new RegisterShortName(
block.Number,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Reference Include="Nethermind.Core">
<HintPath>..\..\..\..\.nuget\packages\nethermind.referenceassemblies\1.28.0\ref\net8.0\Nethermind.Core.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Circles.Index.Common\Circles.Index.Common.csproj" />
</ItemGroup>

</Project>
196 changes: 196 additions & 0 deletions Circles.Index.CirclesV2.StandardTreasury/DatabaseSchema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
using System.Numerics;
using Circles.Index.Common;
using Nethermind.Core.Crypto;

namespace Circles.Index.CirclesV2.StandardTreasury;

public class DatabaseSchema : IDatabaseSchema
{
public ISchemaPropertyMap SchemaPropertyMap { get; } = new SchemaPropertyMap();

public IEventDtoTableMap EventDtoTableMap { get; } = new EventDtoTableMap();

public static readonly EventSchema CreateVault =
EventSchema.FromSolidity("CrcV2",
"event CreateVault(address indexed group, address indexed vault)");

public static readonly EventSchema GroupMintSingle =
EventSchema.FromSolidity("CrcV2",
"event GroupMintSingle(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(),
new List<EventFieldSchema>()
{
new("blockNumber", ValueTypes.Int, true),
new("timestamp", ValueTypes.Int, true),
new("transactionIndex", ValueTypes.Int, true),
new("logIndex", ValueTypes.Int, true),
new("batchIndex", ValueTypes.Int, true, true),
new("transactionHash", ValueTypes.String, true),
new("group", ValueTypes.String, true),
new("id", ValueTypes.BigInt, true),
new("value", ValueTypes.BigInt, true),
new("userData", ValueTypes.Bytes, true)
});

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

public static readonly EventSchema GroupRedeemCollateralReturn =
new EventSchema("CrcV2", "GroupRedeemCollateralReturn",
Keccak.Compute("GroupRedeemCollateralReturn(address,address,uint256[],uint256[])").BytesToArray(),
new List<EventFieldSchema>()
{
new("blockNumber", ValueTypes.Int, true),
new("timestamp", ValueTypes.Int, true),
new("transactionIndex", ValueTypes.Int, true),
new("logIndex", ValueTypes.Int, true),
new("batchIndex", ValueTypes.Int, true, true),
new("transactionHash", ValueTypes.String, true),
new("group", ValueTypes.String, true),
new("to", ValueTypes.String, true),
new("id", ValueTypes.BigInt, true),
new("value", ValueTypes.BigInt, true)
});

public static readonly EventSchema GroupRedeemCollateralBurn =
new EventSchema("CrcV2", "GroupRedeemCollateralBurn",
Keccak.Compute("GroupRedeemCollateralBurn(address,uint256[],uint256[])").BytesToArray(),
new List<EventFieldSchema>()
{
new("blockNumber", ValueTypes.Int, true),
new("timestamp", ValueTypes.Int, true),
new("transactionIndex", ValueTypes.Int, true),
new("logIndex", ValueTypes.Int, true),
new("batchIndex", ValueTypes.Int, true, true),
new("transactionHash", ValueTypes.String, true),
new("group", ValueTypes.String, true),
new("id", ValueTypes.BigInt, true),
new("value", ValueTypes.BigInt, true)
});

public IDictionary<(string Namespace, string Table), EventSchema> Tables { get; } =
new Dictionary<(string Namespace, string Table), EventSchema>
{
{
("CrcV2", "CreateVault"),
CreateVault
},
{
("CrcV2", "GroupMintSingle"),
GroupMintSingle
},
{
("CrcV2", "GroupMintBatch"),
GroupMintBatch
},
{
("CrcV2", "GroupRedeem"),
GroupRedeem
},
{
("CrcV2", "GroupRedeemCollateralReturn"),
GroupRedeemCollateralReturn
},
{
("CrcV2", "GroupRedeemCollateralBurn"),
GroupRedeemCollateralBurn
}
};

public DatabaseSchema()
{
EventDtoTableMap.Add<CreateVault>(("CrcV2", "CreateVault"));
SchemaPropertyMap.Add(("CrcV2", "CreateVault"),
new Dictionary<string, Func<CreateVault, object?>>
{
{ "blockNumber", e => e.BlockNumber },
{ "timestamp", e => e.Timestamp },
{ "transactionIndex", e => e.TransactionIndex },
{ "logIndex", e => e.LogIndex },
{ "transactionHash", e => e.TransactionHash },
{ "group", e => e.Group },
{ "vault", e => e.Vault }
});

EventDtoTableMap.Add<GroupMintSingle>(("CrcV2", "GroupMintSingle"));
SchemaPropertyMap.Add(("CrcV2", "GroupMintSingle"),
new Dictionary<string, Func<GroupMintSingle, object?>>
{
{ "blockNumber", e => e.BlockNumber },
{ "timestamp", e => e.Timestamp },
{ "transactionIndex", e => e.TransactionIndex },
{ "logIndex", e => e.LogIndex },
{ "transactionHash", e => e.TransactionHash },
{ "group", e => e.Group },
{ "id", e => (BigInteger)e.Id },
{ "value", e => (BigInteger)e.Value },
{ "userData", e => e.UserData }
});

EventDtoTableMap.Add<GroupMintBatch>(("CrcV2", "GroupMintBatch"));
SchemaPropertyMap.Add(("CrcV2", "GroupMintBatch"),
new Dictionary<string, Func<GroupMintBatch, object?>>
{
{ "blockNumber", e => e.BlockNumber },
{ "timestamp", e => e.Timestamp },
{ "transactionIndex", e => e.TransactionIndex },
{ "logIndex", e => e.LogIndex },
{ "transactionHash", e => e.TransactionHash },
{ "batchIndex", e => e.BatchIndex },
{ "group", e => e.Group },
{ "id", e => (BigInteger)e.Id },
{ "value", e => (BigInteger)e.Value },
{ "userData", e => e.UserData }
});

EventDtoTableMap.Add<GroupRedeem>(("CrcV2", "GroupRedeem"));
SchemaPropertyMap.Add(("CrcV2", "GroupRedeem"),
new Dictionary<string, Func<GroupRedeem, object?>>
{
{ "blockNumber", e => e.BlockNumber },
{ "timestamp", e => e.Timestamp },
{ "transactionIndex", e => e.TransactionIndex },
{ "logIndex", e => e.LogIndex },
{ "transactionHash", e => e.TransactionHash },
{ "group", e => e.Group },
{ "id", e => (BigInteger)e.Id },
{ "value", e => (BigInteger)e.Value },
{ "data", e => e.Data }
});

EventDtoTableMap.Add<GroupRedeemCollateralReturn>(("CrcV2", "GroupRedeemCollateralReturn"));
SchemaPropertyMap.Add(("CrcV2", "GroupRedeemCollateralReturn"),
new Dictionary<string, Func<GroupRedeemCollateralReturn, object?>>
{
{ "blockNumber", e => e.BlockNumber },
{ "timestamp", e => e.Timestamp },
{ "transactionIndex", e => e.TransactionIndex },
{ "logIndex", e => e.LogIndex },
{ "transactionHash", e => e.TransactionHash },
{ "batchIndex", e => e.BatchIndex },
{ "group", e => e.Group },
{ "to", e => e.To },
{ "id", e => (BigInteger)e.Id },
{ "value", e => (BigInteger)e.Value }
});

EventDtoTableMap.Add<GroupRedeemCollateralBurn>(("CrcV2", "GroupRedeemCollateralBurn"));
SchemaPropertyMap.Add(("CrcV2", "GroupRedeemCollateralBurn"),
new Dictionary<string, Func<GroupRedeemCollateralBurn, object?>>
{
{ "blockNumber", e => e.BlockNumber },
{ "timestamp", e => e.Timestamp },
{ "transactionIndex", e => e.TransactionIndex },
{ "logIndex", e => e.LogIndex },
{ "transactionHash", e => e.TransactionHash },
{ "batchIndex", e => e.BatchIndex },
{ "group", e => e.Group },
{ "id", e => (BigInteger)e.Id },
{ "value", e => (BigInteger)e.Value }
});
}
}
70 changes: 70 additions & 0 deletions Circles.Index.CirclesV2.StandardTreasury/Events.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Circles.Index.Common;
using Nethermind.Int256;

namespace Circles.Index.CirclesV2.StandardTreasury;

public record CreateVault(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
string Group,
string Vault) : IIndexEvent;

public record GroupMintSingle(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
string Group,
UInt256 Id,
UInt256 Value,
byte[] UserData) : IIndexEvent;

public record GroupMintBatch(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
int BatchIndex,
string Group,
UInt256 Id,
UInt256 Value,
byte[] UserData) : IIndexEvent;

public record GroupRedeem(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
string Group,
UInt256 Id,
UInt256 Value,
byte[] Data) : IIndexEvent;

public record GroupRedeemCollateralReturn(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
int BatchIndex,
string Group,
string To,
UInt256 Id,
UInt256 Value) : IIndexEvent;

public record GroupRedeemCollateralBurn(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
int BatchIndex,
string Group,
UInt256 Id,
UInt256 Value) : IIndexEvent;
Loading

0 comments on commit 8ee3309

Please sign in to comment.