Skip to content

Commit

Permalink
Merge pull request #26 from CirclesUBI/feature/index-erc20-wrappers
Browse files Browse the repository at this point in the history
Added support for the inflationary and demurraged ERC20 wrappers.
  • Loading branch information
jaensen authored Jun 18, 2024
2 parents 465ff67 + b26f975 commit 07c1548
Show file tree
Hide file tree
Showing 7 changed files with 647 additions and 64 deletions.
139 changes: 138 additions & 1 deletion Circles.Index.CirclesV2/DatabaseSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace Circles.Index.CirclesV2;
Manual events:
event TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values);
TODO: Add the 'Lift' contract events
lift/
DemurrageCircles.sol:
event DepositDemurraged(address indexed account, uint256 amount, uint256 inflationaryAmount);
Expand Down Expand Up @@ -173,6 +172,35 @@ UNION ALL
")
};

public static readonly EventSchema Erc20WrapperTransfer = new("CrcV2", "Erc20WrapperTransfer",
Keccak.Compute("Transfer(address,address,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("tokenAddress", ValueTypes.Address, true),
new("from", ValueTypes.Address, true),
new("to", ValueTypes.Address, true),
new("amount", ValueTypes.BigInt, false)
]);

public static readonly EventSchema Erc20WrapperDeployed = EventSchema.FromSolidity("CrcV2",
"event ERC20WrapperDeployed(address indexed avatar, address indexed erc20Wrapper, CirclesType circlesType)");

public static readonly EventSchema DepositInflationary = EventSchema.FromSolidity("CrcV2",
"event DepositInflationary(address indexed account, uint256 amount, uint256 demurragedAmount)");

public static readonly EventSchema WithdrawInflationary = EventSchema.FromSolidity("CrcV2",
"event WithdrawInflationary(address indexed account, uint256 amount, uint256 demurragedAmount)");

public static readonly EventSchema DepositDemurraged = EventSchema.FromSolidity("CrcV2",
"event DepositDemurraged(address indexed account, uint256 amount, uint256 inflationaryAmount)");

public static readonly EventSchema WithdrawDemurraged = EventSchema.FromSolidity("CrcV2",
"event WithdrawDemurraged(address indexed account, uint256 amount, uint256 inflationaryAmount)");

public static readonly EventSchema TrustRelations = new("V_CrcV2", "TrustRelations", new byte[32], [
new("blockNumber", ValueTypes.Int, true),
new("timestamp", ValueTypes.Int, true),
Expand Down Expand Up @@ -272,6 +300,30 @@ create or replace view ""V_CrcV2_TrustRelations"" as
{
("V_CrcV2", "TrustRelations"),
TrustRelations
},
{
("CrcV2", "ERC20WrapperDeployed"),
Erc20WrapperDeployed
},
{
("CrcV2", "Erc20WrapperTransfer"),
Erc20WrapperTransfer
},
{
("CrcV2", "DepositInflationary"),
DepositInflationary
},
{
("CrcV2", "WithdrawInflationary"),
WithdrawInflationary
},
{
("CrcV2", "DepositDemurraged"),
DepositDemurraged
},
{
("CrcV2", "WithdrawDemurraged"),
WithdrawDemurraged
}
};

Expand Down Expand Up @@ -445,5 +497,90 @@ public DatabaseSchema()
{ "id", e => (BigInteger)e.Id },
{ "discountCost", e => (BigInteger)e._DiscountCost }
});

EventDtoTableMap.Add<Erc20WrapperDeployed>(("CrcV2", "Erc20WrapperDeployed"));
SchemaPropertyMap.Add(("CrcV2", "Erc20WrapperDeployed"),
new Dictionary<string, Func<Erc20WrapperDeployed, object?>>
{
{ "blockNumber", e => e.BlockNumber },
{ "timestamp", e => e.Timestamp },
{ "transactionIndex", e => e.TransactionIndex },
{ "logIndex", e => e.LogIndex },
{ "transactionHash", e => e.TransactionHash },
{ "avatar", e => e.Avatar },
{ "erc20Wrapper", e => e.Erc20Wrapper },
{ "circlesType", e => BitConverter.ToInt64(e.CirclesType) }
});

EventDtoTableMap.Add<Erc20WrapperTransfer>(("CrcV2", "Erc20WrapperTransfer"));
SchemaPropertyMap.Add(("CrcV2", "Erc20WrapperTransfer"),
new Dictionary<string, Func<Erc20WrapperTransfer, object?>>
{
{ "blockNumber", e => e.BlockNumber },
{ "timestamp", e => e.Timestamp },
{ "transactionIndex", e => e.TransactionIndex },
{ "logIndex", e => e.LogIndex },
{ "transactionHash", e => e.TransactionHash },
{ "tokenAddress", e => e.TokenAddress },
{ "from", e => e.From },
{ "to", e => e.To },
{ "amount", e => (BigInteger)e.Value }
});

EventDtoTableMap.Add<DepositInflationary>(("CrcV2", "DepositInflationary"));
SchemaPropertyMap.Add(("CrcV2", "DepositInflationary"),
new Dictionary<string, Func<DepositInflationary, 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 },
{ "amount", e => (BigInteger)e.Amount },
{ "demurragedAmount", e => (BigInteger)e.DemurragedAmount }
});

EventDtoTableMap.Add<WithdrawInflationary>(("CrcV2", "WithdrawInflationary"));
SchemaPropertyMap.Add(("CrcV2", "WithdrawInflationary"),
new Dictionary<string, Func<WithdrawInflationary, 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 },
{ "amount", e => (BigInteger)e.Amount },
{ "demurragedAmount", e => (BigInteger)e.DemurragedAmount }
});

EventDtoTableMap.Add<DepositDemurraged>(("CrcV2", "DepositDemurraged"));
SchemaPropertyMap.Add(("CrcV2", "DepositDemurraged"),
new Dictionary<string, Func<DepositDemurraged, 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 },
{ "amount", e => (BigInteger)e.Amount },
{ "inflationaryAmount", e => (BigInteger)e.InflationaryAmount }
});

EventDtoTableMap.Add<WithdrawDemurraged>(("CrcV2", "WithdrawDemurraged"));
SchemaPropertyMap.Add(("CrcV2", "WithdrawDemurraged"),
new Dictionary<string, Func<WithdrawDemurraged, 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 },
{ "amount", e => (BigInteger)e.Amount },
{ "inflationaryAmount", e => (BigInteger)e.InflationaryAmount }
});
}
}
63 changes: 62 additions & 1 deletion Circles.Index.CirclesV2/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,65 @@ public record DiscountCost(
string TransactionHash,
string Account,
UInt256 Id,
UInt256 _DiscountCost) : IIndexEvent;
UInt256 _DiscountCost) : IIndexEvent;

public record Erc20WrapperDeployed(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
string Avatar,
string Erc20Wrapper,
byte[] CirclesType) : IIndexEvent;

public record Erc20WrapperTransfer(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
string TokenAddress,
string From,
string To,
UInt256 Value) : IIndexEvent;

public record DepositInflationary(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
string Account,
UInt256 Amount,
UInt256 DemurragedAmount) : IIndexEvent;

public record WithdrawInflationary(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
string Account,
UInt256 Amount,
UInt256 DemurragedAmount) : IIndexEvent;

public record DepositDemurraged(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
string Account,
UInt256 Amount,
UInt256 InflationaryAmount) : IIndexEvent;

public record WithdrawDemurraged(
long BlockNumber,
long Timestamp,
int TransactionIndex,
int LogIndex,
string TransactionHash,
string Account,
UInt256 Amount,
UInt256 InflationaryAmount) : IIndexEvent;
Loading

0 comments on commit 07c1548

Please sign in to comment.