Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add erc20 lift #22

Merged
merged 11 commits into from
Sep 10, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

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

</Project>
196 changes: 196 additions & 0 deletions Circles.Index.CirclesV2.Erc20Lift/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.Erc20Lift;

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 }
});
}
}
13 changes: 13 additions & 0 deletions Circles.Index.CirclesV2.Erc20Lift/Events.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Circles.Index.Common;
using Nethermind.Int256;

namespace Circles.Index.CirclesV2.Erc20Lift;

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