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

Oxford #162

Merged
merged 31 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
12366d2
Oxford scaffold
Groxan Sep 4, 2023
e51b13f
Remove OriginationProof from SmartRollupOriginateOperation
Groxan Sep 4, 2023
94554c8
Bootstrap smart rollups
Groxan Sep 4, 2023
e92da05
Operation set_deposits_limit removed
Groxan Sep 5, 2023
80a6dac
Remove dead refutation games
Groxan Sep 5, 2023
cdb82b4
Remove zero tickets
Groxan Sep 6, 2023
e95ba94
Adjust protocol parameters
Groxan Sep 7, 2023
f86316d
Rework statistics commit
Groxan Sep 7, 2023
898d9e5
Rework inflationary rewards, add AI support
Groxan Sep 26, 2023
ab556a3
Rework snapshots, baker cycles, finalize unstake handler
Groxan Nov 7, 2023
504d000
Add autostaking operations
Groxan Jan 12, 2024
dbf3de5
Move diagnostics after post changes
Groxan Jan 12, 2024
82de8c8
Implement new slashing mechanics
Groxan Jan 16, 2024
984d464
Support predefined bootstrapped contract addresses
Groxan Jan 17, 2024
746e849
Rework slashing
Groxan Jan 30, 2024
ccda8d6
Add triggers migration, comment temp diagnostics
Groxan Jan 30, 2024
5374b51
Remove freezer updates from DB
Groxan Jan 30, 2024
f68a7a0
Update accounts API models
Groxan Jan 31, 2024
f8a07f0
Update rewards API models
Groxan Feb 1, 2024
7855ee0
Update blocks API model
Groxan Feb 1, 2024
d1a1407
Return tokens value migration
Groxan Feb 1, 2024
57a2a7c
Update cycle and protocol API models
Groxan Feb 1, 2024
bb60634
Update operations API models
Groxan Feb 1, 2024
7ae2f10
Add autostaking ops to the API
Groxan Feb 1, 2024
f2f8950
Add staking ops to the API
Groxan Feb 1, 2024
812812e
Update baking op API model
Groxan Feb 1, 2024
d7aa564
Update report and history repos
Groxan Feb 2, 2024
8ae8322
Adjust deprecated fields
Groxan Feb 2, 2024
bfe9c75
Update docker-compose files. Update README
dmirgaleev Feb 5, 2024
9df11c5
Update docs and packages
Groxan Feb 5, 2024
d849758
Merge master into oxford
Groxan Feb 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
Loading