Skip to content

Commit

Permalink
Add Oxford (#162)
Browse files Browse the repository at this point in the history
* Oxford scaffold

* Remove OriginationProof from SmartRollupOriginateOperation

* Bootstrap smart rollups

* Operation set_deposits_limit removed

* Remove dead refutation games

* Remove zero tickets

* Adjust protocol parameters

* Rework statistics commit

* Rework inflationary rewards, add AI support

* Rework snapshots, baker cycles, finalize unstake handler

* Add autostaking operations

* Move diagnostics after post changes

* Implement new slashing mechanics

* Support predefined bootstrapped contract addresses

* Rework slashing

* Add triggers migration, comment temp diagnostics

* Remove freezer updates from DB

* Update accounts API models

* Update rewards API models

* Update blocks API model

* Return tokens value migration

* Update cycle and protocol API models

* Update operations API models

* Add autostaking ops to the API

* Add staking ops to the API

* Update baking op API model

* Update report and history repos

* Adjust deprecated fields

* Update docker-compose files. Update README

* Update docs and packages

---------

Co-authored-by: dmir <[email protected]>
  • Loading branch information
Groxan and dmirgaleev authored Feb 5, 2024
1 parent 82506cc commit 49452b7
Show file tree
Hide file tree
Showing 306 changed files with 16,986 additions and 55,975 deletions.
64 changes: 21 additions & 43 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ init:
docker-compose exec -T db createdb -U tzkt -T template0 tzkt_db
docker-compose exec -T db apt update
docker-compose exec -T db apt install -y wget
docker-compose exec -T db wget "https://snapshots.tzkt.io/tzkt_v1.12_mainnet.backup" -O tzkt_db.backup
docker-compose exec -T db wget "https://snapshots.tzkt.io/tzkt_v1.13_mainnet.backup" -O tzkt_db.backup
docker-compose exec -T db pg_restore -U tzkt -O -x -v -d tzkt_db -e -j 4 tzkt_db.backup
docker-compose exec -T db rm tzkt_db.backup
docker-compose exec -T db apt autoremove --purge -y wget
Expand Down Expand Up @@ -52,7 +52,7 @@ ghost-init:
docker-compose -f docker-compose.ghost.yml exec -T ghost-db createdb -U tzkt -T template0 tzkt_db
docker-compose -f docker-compose.ghost.yml exec -T ghost-db apt update
docker-compose -f docker-compose.ghost.yml exec -T ghost-db apt install -y wget
docker-compose -f docker-compose.ghost.yml exec -T ghost-db wget "https://snapshots.tzkt.io/tzkt_v1.12_ghostnet.backup" -O tzkt_db.backup
docker-compose -f docker-compose.ghost.yml exec -T ghost-db wget "https://snapshots.tzkt.io/tzkt_v1.13_ghostnet.backup" -O tzkt_db.backup
docker-compose -f docker-compose.ghost.yml exec -T ghost-db pg_restore -U tzkt -O -x -v -d tzkt_db -e -j 4 tzkt_db.backup
docker-compose -f docker-compose.ghost.yml exec -T ghost-db rm tzkt_db.backup
docker-compose -f docker-compose.ghost.yml exec -T ghost-db apt autoremove --purge -y wget
Expand All @@ -67,49 +67,27 @@ ghost-stop:
ghost-db-start:
docker-compose -f docker-compose.ghost.yml up -d ghost-db

nairobi-init:
docker-compose -f docker-compose.nairobi.yml up -d nairobi-db
docker-compose -f docker-compose.nairobi.yml exec -T nairobi-db psql -U tzkt postgres -c '\l'
docker-compose -f docker-compose.nairobi.yml exec -T nairobi-db dropdb -U tzkt --if-exists tzkt_db
docker-compose -f docker-compose.nairobi.yml exec -T nairobi-db createdb -U tzkt -T template0 tzkt_db
docker-compose -f docker-compose.nairobi.yml exec -T nairobi-db apt update
docker-compose -f docker-compose.nairobi.yml exec -T nairobi-db apt install -y wget
docker-compose -f docker-compose.nairobi.yml exec -T nairobi-db wget "https://snapshots.tzkt.io/tzkt_v1.12_nairobinet.backup" -O tzkt_db.backup
docker-compose -f docker-compose.nairobi.yml exec -T nairobi-db pg_restore -U tzkt -O -x -v -d tzkt_db -e -j 4 tzkt_db.backup
docker-compose -f docker-compose.nairobi.yml exec -T nairobi-db rm tzkt_db.backup
docker-compose -f docker-compose.nairobi.yml exec -T nairobi-db apt autoremove --purge -y wget
oxford-init:
docker-compose -f docker-compose.oxford.yml up -d oxford-db
docker-compose -f docker-compose.oxford.yml exec -T oxford-db psql -U tzkt postgres -c '\l'
docker-compose -f docker-compose.oxford.yml exec -T oxford-db dropdb -U tzkt --if-exists tzkt_db
docker-compose -f docker-compose.oxford.yml exec -T oxford-db createdb -U tzkt -T template0 tzkt_db
docker-compose -f docker-compose.oxford.yml exec -T oxford-db apt update
docker-compose -f docker-compose.oxford.yml exec -T oxford-db apt install -y wget
docker-compose -f docker-compose.oxford.yml exec -T oxford-db wget "https://snapshots.tzkt.io/tzkt_v1.13_oxfordnet.backup" -O tzkt_db.backup
docker-compose -f docker-compose.oxford.yml exec -T oxford-db pg_restore -U tzkt -O -x -v -d tzkt_db -e -j 4 tzkt_db.backup
docker-compose -f docker-compose.oxford.yml exec -T oxford-db rm tzkt_db.backup
docker-compose -f docker-compose.oxford.yml exec -T oxford-db apt autoremove --purge -y wget
docker-compose pull

nairobi-start:
docker-compose -f docker-compose.nairobi.yml up -d

nairobi-stop:
docker-compose -f docker-compose.nairobi.yml down

nairobi-db-start:
docker-compose -f docker-compose.nairobi.yml up -d nairobi-db

mumbai-init:
docker-compose -f docker-compose.mumbai.yml up -d mumbai-db
docker-compose -f docker-compose.mumbai.yml exec -T mumbai-db psql -U tzkt postgres -c '\l'
docker-compose -f docker-compose.mumbai.yml exec -T mumbai-db dropdb -U tzkt --if-exists tzkt_db
docker-compose -f docker-compose.mumbai.yml exec -T mumbai-db createdb -U tzkt -T template0 tzkt_db
docker-compose -f docker-compose.mumbai.yml exec -T mumbai-db apt update
docker-compose -f docker-compose.mumbai.yml exec -T mumbai-db apt install -y wget
docker-compose -f docker-compose.mumbai.yml exec -T mumbai-db wget "https://snapshots.tzkt.io/tzkt_v1.12_mumbainet.backup" -O tzkt_db.backup
docker-compose -f docker-compose.mumbai.yml exec -T mumbai-db pg_restore -U tzkt -O -x -v -d tzkt_db -e -j 4 tzkt_db.backup
docker-compose -f docker-compose.mumbai.yml exec -T mumbai-db rm tzkt_db.backup
docker-compose -f docker-compose.mumbai.yml exec -T mumbai-db apt autoremove --purge -y wget
docker-compose pull

mumbai-start:
docker-compose -f docker-compose.mumbai.yml up -d
oxford-start:
docker-compose -f docker-compose.oxford.yml up -d

mumbai-stop:
docker-compose -f docker-compose.mumbai.yml down
oxford-stop:
docker-compose -f docker-compose.oxford.yml down

mumbai-db-start:
docker-compose -f docker-compose.mumbai.yml up -d mumbai-db
oxford-db-start:
docker-compose -f docker-compose.oxford.yml up -d oxford-db
reset:
docker-compose -f docker-compose.mumbai.yml down --volumes
docker-compose -f docker-compose.mumbai.yml up -d mumbai-db
docker-compose -f docker-compose.oxford.yml down --volumes
docker-compose -f docker-compose.oxford.yml up -d oxford-db
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ sudo apt install -y dotnet-sdk-7.0
#### Install Postgresql

````
sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt update
sudo apt -y install postgresql postgresql-contrib
sudo apt -y install postgresql-16 postgresql-contrib-16
````

---
Expand All @@ -85,7 +87,7 @@ postgres=# \q
#### Download fresh snapshot (example for mainnet)

````
wget "https://snapshots.tzkt.io/tzkt_v1.12_mainnet.backup" -O /tmp/tzkt_db.backup
wget "https://snapshots.tzkt.io/tzkt_v1.13_mainnet.backup" -O /tmp/tzkt_db.backup
````

#### Restore database from the snapshot
Expand Down Expand Up @@ -255,14 +257,11 @@ That's it. If you want to run the API as a daemon, take a look at this guide: ht

In general the steps are the same as for the mainnet, you will just need to use a different RPC endpoint and DB snapshot. Here are presets for the current testnets:
- Ghostnet:
- Snapshot: https://snapshots.tzkt.io/tzkt_v1.12_ghostnet.backup
- Snapshot: https://snapshots.tzkt.io/tzkt_v1.13_ghostnet.backup
- RPC node: https://rpc.tzkt.io/ghostnet/
- Mumbainet:
- Snapshot: https://snapshots.tzkt.io/tzkt_v1.12_mumbainet.backup
- RPC node: https://rpc.tzkt.io/mumbainet/
- Nairobinet:
- Snapshot: https://snapshots.tzkt.io/tzkt_v1.12_nairobinet.backup
- RPC node: https://rpc.tzkt.io/nairobinet/
- Oxfordnet:
- Snapshot: https://snapshots.tzkt.io/tzkt_v1.13_oxfordnet.backup
- RPC node: https://rpc.tzkt.io/oxfordnet/

### Testnets & docker

Expand Down
116 changes: 115 additions & 1 deletion Tzkt.Api/Controllers/OperationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5030,6 +5030,63 @@ public async Task<ActionResult<int>> GetSmartRollupRefuteOpsCount([FromQuery] Sr
}
#endregion

#region staking
/// <summary>
/// Get staking ops
/// </summary>
/// <remarks>
/// Returns a list of staking operations.
/// </remarks>
/// <param name="filter">Filter</param>
/// <param name="pagination">Pagination</param>
/// <param name="selection">Selection</param>
/// <param name="quote">Comma-separated list of ticker symbols to inject historical prices into response</param>
/// <returns></returns>
[HttpGet("staking")]
public async Task<ActionResult<IEnumerable<StakingOperation>>> GetStakingOps(
[FromQuery] StakingOperationFilter filter,
[FromQuery] Pagination pagination,
[FromQuery] Selection selection,
[FromQuery] Symbols quote = Symbols.None)
{
var query = ResponseCacheService.BuildKey(Request.Path.Value,
("filter", filter), ("pagination", pagination), ("selection", selection), ("quote", quote));

if (!ResponseCache.TryGet(query, out var res))
res = ResponseCache.Set(query, selection.select == null
? await Operations.GetStakingOps(filter, pagination, quote)
: new SelectionResponse
{
Cols = selection.Cols,
Rows = await Operations.GetStakingOps(filter, pagination, selection, quote)
});

return this.Bytes(res);
}

/// <summary>
/// Get staking ops count
/// </summary>
/// <remarks>
/// Returns a total number of staking operations.
/// </remarks>
/// <param name="filter">Filter</param>
/// <returns></returns>
[HttpGet("staking/count")]
public async Task<ActionResult<int>> GetStakingOpsCount([FromQuery] StakingOperationFilter filter)
{
if (filter.Empty)
return Ok(State.Current.StakingOpsCount);

var query = ResponseCacheService.BuildKey(Request.Path.Value, ("filter", filter));

if (!ResponseCache.TryGet(query, out var res))
res = ResponseCache.Set(query, await Operations.GetStakingOpsCount(filter));

return this.Bytes(res);
}
#endregion

#region migrations
/// <summary>
/// Get migrations
Expand All @@ -5038,7 +5095,7 @@ public async Task<ActionResult<int>> GetSmartRollupRefuteOpsCount([FromQuery] Sr
/// Returns a list of migration operations (synthetic type).
/// </remarks>
/// <param name="account">Filters migration operations by account. Allowed fields for `.eqx` mode: none.</param>
/// <param name="kind">Filters migration operations by kind (`bootstrap`, `activate_delegate`, `airdrop`, `proposal_invoice`, `origination`, `subsidy`).</param>
/// <param name="kind">Filters migration operations by kind (`bootstrap`, `activate_delegate`, `airdrop`, `proposal_invoice`, `origination`, `subsidy`, `remove_bigmap_key`).</param>
/// <param name="balanceChange">Filters migration operations by amount.</param>
/// <param name="id">Filters migration operations by internal TzKT id.</param>
/// <param name="level">Filters migration operations by level.</param>
Expand Down Expand Up @@ -5611,5 +5668,62 @@ public async Task<ActionResult<int>> GetEndorsingRewardsCount(
return this.Bytes(cached);
}
#endregion

#region autostaking
/// <summary>
/// Get autostaking ops
/// </summary>
/// <remarks>
/// Returns a list of autostaking operations.
/// </remarks>
/// <param name="filter">Filter</param>
/// <param name="pagination">Pagination</param>
/// <param name="selection">Selection</param>
/// <param name="quote">Comma-separated list of ticker symbols to inject historical prices into response</param>
/// <returns></returns>
[HttpGet("autostaking")]
public async Task<ActionResult<IEnumerable<AutostakingOperation>>> GetAutostakingOps(
[FromQuery] AutostakingOperationFilter filter,
[FromQuery] Pagination pagination,
[FromQuery] Selection selection,
[FromQuery] Symbols quote = Symbols.None)
{
var query = ResponseCacheService.BuildKey(Request.Path.Value,
("filter", filter), ("pagination", pagination), ("selection", selection), ("quote", quote));

if (!ResponseCache.TryGet(query, out var res))
res = ResponseCache.Set(query, selection.select == null
? await Operations.GetAutostakingOps(filter, pagination, quote)
: new SelectionResponse
{
Cols = selection.Cols,
Rows = await Operations.GetAutostakingOps(filter, pagination, selection, quote)
});

return this.Bytes(res);
}

/// <summary>
/// Get autostaking ops count
/// </summary>
/// <remarks>
/// Returns a total number of autostaking operations.
/// </remarks>
/// <param name="filter">Filter</param>
/// <returns></returns>
[HttpGet("autostaking/count")]
public async Task<ActionResult<int>> GetAutostakingOpsCount([FromQuery] AutostakingOperationFilter filter)
{
if (filter.Empty)
return Ok(State.Current.AutostakingOpsCount);

var query = ResponseCacheService.BuildKey(Request.Path.Value, ("filter", filter));

if (!ResponseCache.TryGet(query, out var res))
res = ResponseCache.Set(query, await Operations.GetAutostakingOpsCount(filter));

return this.Bytes(res);
}
#endregion
}
}
39 changes: 10 additions & 29 deletions Tzkt.Api/Controllers/RewardsController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;

using NSwag.Annotations;
using Tzkt.Api.Models;
using Tzkt.Api.Repositories;

Expand Down Expand Up @@ -88,20 +85,12 @@ public async Task<ActionResult<IEnumerable<BakerRewards>>> GetBakerRewards(
}
}

/// <summary>
/// Get baker cycle rewards by cycle
/// </summary>
/// <remarks>
/// Returns baker cycle rewards for the specified cycle.
/// </remarks>
/// <param name="address">Baker address</param>
/// <param name="cycle">Rewards cycle</param>
/// <param name="quote">Comma-separated list of ticker symbols to inject historical prices into response</param>
/// <returns></returns>
// deprecated
[OpenApiIgnore]
[HttpGet("bakers/{address}/{cycle:int}")]
public Task<BakerRewards> GetBakerRewardsByCycle([Required][TzAddress] string address, [Min(0)] int cycle, Symbols quote = Symbols.None)
public async Task<BakerRewards> GetBakerRewardsByCycle([Required][TzAddress] string address, [Min(0)] int cycle, Symbols quote = Symbols.None)
{
return Rewards.GetBakerRewards(address, cycle, quote);
return (await Rewards.GetBakerRewards(address, cycle, null, null, 100, quote)).FirstOrDefault();
}

/// <summary>
Expand Down Expand Up @@ -172,20 +161,12 @@ public async Task<ActionResult<IEnumerable<DelegatorRewards>>> GetDelegatorRewar
}
}

/// <summary>
/// Get delegator cycle rewards by cycle
/// </summary>
/// <remarks>
/// Returns delegator cycle rewards for the specified cycle.
/// </remarks>
/// <param name="address">Delegator address</param>
/// <param name="cycle">Rewards cycle</param>
/// <param name="quote">Comma-separated list of ticker symbols to inject historical prices into response</param>
/// <returns></returns>
// deprecated
[OpenApiIgnore]
[HttpGet("delegators/{address}/{cycle:int}")]
public Task<DelegatorRewards> GetDelegatorRewardsByCycle([Required][Address] string address, [Min(0)] int cycle, Symbols quote = Symbols.None)
public async Task<DelegatorRewards> GetDelegatorRewardsByCycle([Required][Address] string address, [Min(0)] int cycle, Symbols quote = Symbols.None)
{
return Rewards.GetDelegatorRewards(address, cycle, quote);
return (await Rewards.GetDelegatorRewards(address, cycle, null, null, 100, quote)).FirstOrDefault();
}

/// <summary>
Expand Down
Loading

0 comments on commit 49452b7

Please sign in to comment.