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

WIP: Updated Docker Image File for Keeper/Liquidator #893

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-code-review-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ env:
CARGO_TERM_COLOR: always
SOLANA_VERSION: '1.16.14'
RUST_TOOLCHAIN: '1.69.0'
LOG_PROGRAM: '4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg'
LOG_PROGRAM: 'zF2vSz6V9g1YHGmfrzsY497NJzbRr84QUrPry4bLQ25'

jobs:
format:
Expand Down
4 changes: 2 additions & 2 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
exclude = ["programs/margin-trade"]

[programs.localnet]
mango_v4 = "4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg"
mango_v4 = "zF2vSz6V9g1YHGmfrzsY497NJzbRr84QUrPry4bLQ25"

[programs.devnet]
mango_v4 = "4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg"
mango_v4 = "zF2vSz6V9g1YHGmfrzsY497NJzbRr84QUrPry4bLQ25"

[features]
seeds = true
Expand Down
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# syntax = docker/dockerfile:1.2
# Base image containing all binaries, deployed to ghcr.io/blockworks-foundation/mango-v4:latest
FROM rust:1.69.0-bullseye as base
RUN cargo install cargo-chef --locked
RUN rustup component add rustfmt
RUN apt-get update && apt-get -y install clang cmake
FROM lukemathwalker/cargo-chef:latest-rust-1.69-slim-bullseye as base
RUN apt-get update && apt-get -y install clang cmake perl libfindbin-libs-perl
WORKDIR /app

FROM base as plan
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ See DEVELOPING.md and FAQ-DEV.md

### Deployments

- devnet: 4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg
- mainnet-beta: 4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg
- primary mango group on mainnet-beta: 78b8f4cGCwmZ9ysPFMWLaLTkkaYnUjwMJYStWe5RTSSX
- devnet: zF2vSz6V9g1YHGmfrzsY497NJzbRr84QUrPry4bLQ25
- mainnet-beta: zF2vSz6V9g1YHGmfrzsY497NJzbRr84QUrPry4bLQ25
- primary mango group on mainnet-beta: AKeMSYiJekyKfwCc3CUfVNDVAiqk9FfbQVMY3G7RUZUf

### Release

Expand Down
7 changes: 4 additions & 3 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- $KEY as a path to a keypair (needs around 20 SOL for the buffer)
- $RPC_URL as a url to an RPC node
- 4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg is the address of the Mango v4 Program
- zF2vSz6V9g1YHGmfrzsY497NJzbRr84QUrPry4bLQ25 is the address of the Mango v4 Program
- FP4PxqHTVzeG2c6eZd7974F9WvKUSdBeduUK3rjYyvBw is the address of the Mango v4 Program Governance

- Check out the latest version of the `dev` branch
Expand Down Expand Up @@ -47,17 +47,18 @@

- Create IDL buffer

anchor idl write-buffer --provider.cluster $RPC_URL --provider.wallet $KEY --filepath target/idl/mango_v4_no_docs.json 4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg
anchor idl write-buffer --provider.cluster $RPC_URL --provider.wallet $KEY --filepath target/idl/mango_v4_no_docs.json zF2vSz6V9g1YHGmfrzsY497NJzbRr84QUrPry4bLQ25

Save the returned address as $IDL_BUFFER

- Set IDL buffer authority

anchor idl set-authority --provider.cluster $RPC_URL --provider.wallet $KEY --program-id 4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg --new-authority FP4PxqHTVzeG2c6eZd7974F9WvKUSdBeduUK3rjYyvBw $IDL_BUFFER
anchor idl set-authority --provider.cluster $RPC_URL --provider.wallet $KEY --program-id zF2vSz6V9g1YHGmfrzsY497NJzbRr84QUrPry4bLQ25 --new-authority FP4PxqHTVzeG2c6eZd7974F9WvKUSdBeduUK3rjYyvBw $IDL_BUFFER

- Make a gist for the proposal description, ideally based on previous upgrade proposals

- Go to the DAO proposal website and make a proposal:

- Upgrade program with the new buffer, set the spill address to the address of $KEY
- Upgrade idl with the new buffer

Expand Down
2 changes: 1 addition & 1 deletion anchor-tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum MINTS {
BTC = 'BTC',
}
const NUM_USERS = 4;
const PROGRAM_ID = '4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg';
const PROGRAM_ID = 'zF2vSz6V9g1YHGmfrzsY497NJzbRr84QUrPry4bLQ25';

interface TestUser {
keypair: anchor.web3.Keypair;
Expand Down
32 changes: 2 additions & 30 deletions bin/liquidator/src/rebalance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,7 @@ impl Rebalancer {
in_amount_quote: u64,
) -> anyhow::Result<(Signature, jupiter::Quote)> {
let quote_token = self.mango_client.context.token(QUOTE_TOKEN_INDEX);
let sol_token = self.mango_client.context.token(
*self
.mango_client
.context
.token_indexes_by_name
.get("SOL") // TODO: better use mint
.unwrap(),
);
let quote_mint = quote_token.mint;
let sol_mint = sol_token.mint;
let jupiter_version = self.config.jupiter_version;

let full_route_job = self.jupiter_quote(
Expand All @@ -142,16 +133,8 @@ impl Rebalancer {
);

// For the SOL -> output route we need to adjust the in amount by the SOL price
let sol_price = self
.account_fetcher
.fetch_bank_price(&sol_token.first_bank())?;
let in_amount_sol = (I80F48::from(in_amount_quote) / sol_price)
.ceil()
.to_num::<u64>();
let direct_sol_route_job =
self.jupiter_quote(sol_mint, output_mint, in_amount_sol, true, jupiter_version);

let jobs = vec![full_route_job, direct_quote_route_job, direct_sol_route_job];
let jobs = vec![full_route_job, direct_quote_route_job];

let mut results = futures::future::join_all(jobs).await;
let full_route = results.remove(0)?;
Expand Down Expand Up @@ -181,26 +164,15 @@ impl Rebalancer {
in_amount: u64,
) -> anyhow::Result<(Signature, jupiter::Quote)> {
let quote_token = self.mango_client.context.token(QUOTE_TOKEN_INDEX);
let sol_token = self.mango_client.context.token(
*self
.mango_client
.context
.token_indexes_by_name
.get("SOL") // TODO: better use mint
.unwrap(),
);
let quote_mint = quote_token.mint;
let sol_mint = sol_token.mint;
let jupiter_version = self.config.jupiter_version;

let full_route_job =
self.jupiter_quote(input_mint, quote_mint, in_amount, false, jupiter_version);
let direct_quote_route_job =
self.jupiter_quote(input_mint, quote_mint, in_amount, true, jupiter_version);
let direct_sol_route_job =
self.jupiter_quote(input_mint, sol_mint, in_amount, true, jupiter_version);

let jobs = vec![full_route_job, direct_quote_route_job, direct_sol_route_job];
let jobs = vec![full_route_job, direct_quote_route_job];

let mut results = futures::future::join_all(jobs).await;
let full_route = results.remove(0)?;
Expand Down
13 changes: 13 additions & 0 deletions cd/keeper-boost.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
app = "boost-keeper-1"
kill_signal = "SIGINT"
kill_timeout = 5

[build]
dockerfile = "../Dockerfile"

[experimental]
cmd = ["keeper", "crank"]

[metrics]
path = "/metrics"
port = 9091
9 changes: 9 additions & 0 deletions cd/liquidator-boost.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
app = "boost-liquidator-1"
kill_signal = "SIGTERM"
kill_timeout = 30

[build]
dockerfile = "../Dockerfile"

[experimental]
cmd = ["liquidator"]
13 changes: 9 additions & 4 deletions lib/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2418,10 +2418,15 @@ impl TransactionBuilder {
.sum()
})
.unwrap_or(0);
Ok(TransactionSize {
accounts,
length: bytes.len(),
})
let length: usize = bytes.len();
if length > 1232 {
Err(anyhow::format_err!("Transaction too large: {length} bytes"))
} else {
Ok(TransactionSize {
accounts,
length,
})
}
}
}

Expand Down
61 changes: 47 additions & 14 deletions mango_v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,36 @@
}
]
},
{
"name": "sequenceCheck",
"accounts": [
{
"name": "group",
"isMut": false,
"isSigner": false
},
{
"name": "account",
"isMut": true,
"isSigner": false,
"relations": [
"group",
"owner"
]
},
{
"name": "owner",
"isMut": false,
"isSigner": true
}
],
"args": [
{
"name": "expectedSequenceNumber",
"type": "u8"
}
]
},
{
"name": "stubOracleCreate",
"accounts": [
Expand Down Expand Up @@ -7871,13 +7901,8 @@
"type": "u8"
},
{
"name": "padding",
"type": {
"array": [
"u8",
1
]
}
"name": "sequenceNumber",
"type": "u8"
},
{
"name": "netDeposits",
Expand Down Expand Up @@ -9669,13 +9694,8 @@
"type": "u8"
},
{
"name": "padding",
"type": {
"array": [
"u8",
1
]
}
"name": "sequenceNumber",
"type": "u8"
},
{
"name": "netDeposits",
Expand Down Expand Up @@ -11008,6 +11028,9 @@
},
{
"name": "TokenForceWithdraw"
},
{
"name": "SequenceCheck"
}
]
}
Expand Down Expand Up @@ -14347,6 +14370,16 @@
"code": 6069,
"name": "TokenAssetLiquidationDisabled",
"msg": "the asset does not allow liquidation"
},
{
"code": 6070,
"name": "BorrowsRequireHealthAccountBank",
"msg": "for borrows the bank must be in the health account list"
},
{
"code": 6071,
"name": "InvalidSequenceNumber",
"msg": "invalid sequence number"
}
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@blockworks-foundation/mango-v4",
"version": "0.21.29",
"version": "0.23.0-rc2",
"description": "Typescript Client for mango-v4 program.",
"repository": "https://github.com/blockworks-foundation/mango-v4",
"author": {
Expand Down Expand Up @@ -62,7 +62,7 @@
"trailingComma": "all"
},
"dependencies": {
"@blockworks-foundation/mango-v4-settings": "0.4.10",
"@blockworks-foundation/mango-v4-settings": "0.14.15",
"@blockworks-foundation/mangolana": "0.0.14",
"@coral-xyz/anchor": "^0.28.1-beta.2",
"@project-serum/serum": "0.13.65",
Expand Down
2 changes: 2 additions & 0 deletions programs/mango-v4/src/accounts_ix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub use perp_place_order::*;
pub use perp_settle_fees::*;
pub use perp_settle_pnl::*;
pub use perp_update_funding::*;
pub use sequence_check::*;
pub use serum3_cancel_all_orders::*;
pub use serum3_cancel_order::*;
pub use serum3_close_open_orders::*;
Expand Down Expand Up @@ -123,6 +124,7 @@ mod perp_place_order;
mod perp_settle_fees;
mod perp_settle_pnl;
mod perp_update_funding;
mod sequence_check;
mod serum3_cancel_all_orders;
mod serum3_cancel_order;
mod serum3_close_open_orders;
Expand Down
20 changes: 20 additions & 0 deletions programs/mango-v4/src/accounts_ix/sequence_check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::error::*;
use crate::state::*;
use anchor_lang::prelude::*;

#[derive(Accounts)]
pub struct SequenceCheck<'info> {
#[account(
constraint = group.load()?.is_ix_enabled(IxGate::SequenceCheck) @ MangoError::IxIsDisabled,
)]
pub group: AccountLoader<'info, Group>,

#[account(
mut,
has_one = group,
has_one = owner,
constraint = account.load()?.is_operational() @ MangoError::AccountIsFrozen
)]
pub account: AccountLoader<'info, MangoAccountFixed>,
pub owner: Signer<'info>,
}
4 changes: 4 additions & 0 deletions programs/mango-v4/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ pub enum MangoError {
MissingFeedForCLMMOracle,
#[msg("the asset does not allow liquidation")]
TokenAssetLiquidationDisabled,
#[msg("for borrows the bank must be in the health account list")]
BorrowsRequireHealthAccountBank,
#[msg("invalid sequence number")]
InvalidSequenceNumber,
}

impl MangoError {
Expand Down
1 change: 1 addition & 0 deletions programs/mango-v4/src/instructions/ix_gate_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub fn ix_gate_set(ctx: Context<IxGateSet>, ix_gate: u128) -> Result<()> {
);
log_if_changed(&group, ix_gate, IxGate::Serum3PlaceOrderV2);
log_if_changed(&group, ix_gate, IxGate::TokenForceWithdraw);
log_if_changed(&group, ix_gate, IxGate::SequenceCheck);

group.ix_gate = ix_gate;

Expand Down
2 changes: 2 additions & 0 deletions programs/mango-v4/src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub use perp_place_order::*;
pub use perp_settle_fees::*;
pub use perp_settle_pnl::*;
pub use perp_update_funding::*;
pub use sequence_check::*;
pub use serum3_cancel_all_orders::*;
pub use serum3_cancel_order::*;
pub use serum3_cancel_order_by_client_order_id::*;
Expand Down Expand Up @@ -104,6 +105,7 @@ mod perp_place_order;
mod perp_settle_fees;
mod perp_settle_pnl;
mod perp_update_funding;
mod sequence_check;
mod serum3_cancel_all_orders;
mod serum3_cancel_order;
mod serum3_cancel_order_by_client_order_id;
Expand Down
18 changes: 18 additions & 0 deletions programs/mango-v4/src/instructions/sequence_check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use anchor_lang::prelude::*;

use crate::accounts_ix::*;
use crate::error::MangoError;
use crate::state::*;

pub fn sequence_check(ctx: Context<SequenceCheck>, expected_sequence_number: u8) -> Result<()> {
let mut account = ctx.accounts.account.load_full_mut()?;

require_eq!(
expected_sequence_number,
account.fixed.sequence_number,
MangoError::InvalidSequenceNumber
);

account.fixed.sequence_number = account.fixed.sequence_number.wrapping_add(1);
Ok(())
}
Loading
Loading