Skip to content

Commit a0e8179

Browse files
authored
Liquidation program (#435)
* Liquidation program v0.1.0 * SDK updates for Liquidation program
1 parent c10a6a8 commit a0e8179

36 files changed

Lines changed: 4440 additions & 3 deletions

.github/workflows/deploy-programs.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515
- price_based_performance_package_v6
1616
- launchpad_v7
1717
- bid_wall
18+
- liquidation
1819
priority-fee:
1920
description: "Priority fee in microlamports"
2021
required: true
@@ -41,6 +42,25 @@ jobs:
4142
MAINNET_MULTISIG: ${{ secrets.MAINNET_MULTISIG }}
4243
MAINNET_MULTISIG_VAULT: ${{ secrets.MAINNET_MULTISIG_VAULT }}
4344

45+
liquidation:
46+
if: inputs.program == 'liquidation' || inputs.program == 'all'
47+
uses: ./.github/workflows/reusable-build.yaml
48+
with:
49+
program: "liquidation"
50+
override-program-id: "LiQnowFbFQdYyZhF4pUbpsrZCjxRTQ1upKJxZ2VXjde"
51+
network: "mainnet"
52+
deploy: true
53+
upload_idl: true
54+
verify: true
55+
use-squads: true
56+
features: "production"
57+
priority-fee: ${{ inputs.priority-fee }}
58+
secrets:
59+
MAINNET_SOLANA_DEPLOY_URL: ${{ secrets.MAINNET_SOLANA_DEPLOY_URL }}
60+
MAINNET_DEPLOYER_KEYPAIR: ${{ secrets.MAINNET_DEPLOYER_KEYPAIR }}
61+
MAINNET_MULTISIG: ${{ secrets.MAINNET_MULTISIG }}
62+
MAINNET_MULTISIG_VAULT: ${{ secrets.MAINNET_MULTISIG_VAULT }}
63+
4464
futarchy-v6:
4565
if: inputs.program == 'futarchy_v6' || inputs.program == 'all'
4666
uses: ./.github/workflows/reusable-build.yaml

.github/workflows/generate-verifiable-builds.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,21 @@ jobs:
111111
uses: EndBug/add-and-commit@v9.1.4
112112
with:
113113
default_author: github_actions
114-
message: 'Update bid_wall verifiable build'
114+
message: 'Update bid_wall verifiable build'
115+
generate-verifiable-liquidation:
116+
runs-on: ubuntu-22.04
117+
steps:
118+
- uses: actions/checkout@v4
119+
- uses: metadaoproject/anchor-verifiable-build@v0.4
120+
with:
121+
program: liquidation
122+
anchor-version: '0.29.0'
123+
solana-cli-version: '1.17.31'
124+
features: 'production'
125+
- run: 'git pull --rebase'
126+
- run: cp target/deploy/liquidation.so ./verifiable-builds
127+
- name: Commit verifiable build back to mainline
128+
uses: EndBug/add-and-commit@v9.1.4
129+
with:
130+
default_author: github_actions
131+
message: 'Update liquidation verifiable build'

Anchor.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ conditional_vault = "VLTX1ishMBbcX3rdBWGssxawAo1Q2X2qxYFYqiGodVg"
1111
futarchy = "FUTARELBfJfQ8RDGhg1wdhddq1odMAJUePHFuBYfUxKq"
1212
launchpad = "MooNyh4CBUYEKyXVnjGYQ8mEiJDpGvJMdvrZx1iGeHV"
1313
launchpad_v7 = "moontUzsdepotRGe5xsfip7vLPTJnVuafqdUWexVnPM"
14+
liquidation = "LiQnowFbFQdYyZhF4pUbpsrZCjxRTQ1upKJxZ2VXjde"
1415
mint_governor = "gvnr27cVeyW3AVf3acL7VCJ5WjGAphytnsgcK1feHyH"
1516
performance_package_v2 = "pPV2pfrxnmstSb9j7kEeCLny5BGj6SNwCWGd6xbGGzz"
1617
price_based_performance_package = "pbPPQH7jyKoSLu8QYs3rSY3YkDRXEBojKbTgnUg7NDS"

CLAUDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ pub recipient_ata: Account<'info, TokenAccount>,
148148
pub funder_token_account: Account<'info, TokenAccount>,
149149
```
150150

151+
### Events
152+
Always use CPI events (`#[event_cpi]` on accounts structs, `emit_cpi!` for emission) rather than regular `emit!`.
153+
151154
### Require Macros
152155
When writing validation checks, prefer specific require macros over generic `require!`:
153156
1. `require_keys_eq!` - when comparing two `Pubkey` values
@@ -289,3 +292,4 @@ External programs required for tests. These are pre-compiled `.so` files in `tes
289292
| conditional_vault | v0.4 | `VLTX1ishMBbcX3rdBWGssxawAo1Q2X2qxYFYqiGodVg` |
290293
| price_based_performance_package | v0.6.0 | `pbPPQH7jyKoSLu8QYs3rSY3YkDRXEBojKbTgnUg7NDS` |
291294
| mint_governor | v0.7.0 | `gvnr27cVeyW3AVf3acL7VCJ5WjGAphytnsgcK1feHyH` |
295+
| liquidation | v0.1.0 | `LiQnowFbFQdYyZhF4pUbpsrZCjxRTQ1upKJxZ2VXjde` |

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Programs for unruggable capital formation and market-driven governance.
1010
| ----------------- | ---- | -------------------------------------------- |
1111
| launchpad | v0.7.0 | moontUzsdepotRGe5xsfip7vLPTJnVuafqdUWexVnPM |
1212
| bid_wall | v0.7.0 | WALL8ucBuUyL46QYxwYJjidaFYhdvxUFrgvBxPshERx |
13+
| liquidation | v0.1.0 | LiQnowFbFQdYyZhF4pUbpsrZCjxRTQ1upKJxZ2VXjde |
1314
| futarchy | v0.6.0 | FUTARELBfJfQ8RDGhg1wdhddq1odMAJUePHFuBYfUxKq |
1415
| launchpad | v0.6.0 | MooNyh4CBUYEKyXVnjGYQ8mEiJDpGvJMdvrZx1iGeHV |
1516
| price_based_performance_package | v0.6.0 | pbPPQH7jyKoSLu8QYs3rSY3YkDRXEBojKbTgnUg7NDS |

programs/liquidation/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "liquidation"
3+
version = "0.1.0"
4+
description = "Manages the orderly liquidation of a project's treasury back to token holders."
5+
edition = "2021"
6+
7+
[lib]
8+
crate-type = ["cdylib", "lib"]
9+
name = "liquidation"
10+
11+
[features]
12+
no-entrypoint = []
13+
no-idl = []
14+
no-log-ix-name = []
15+
cpi = ["no-entrypoint"]
16+
default = []
17+
production = []
18+
19+
[dependencies]
20+
anchor-lang = { version = "0.29.0", features = ["event-cpi", "init-if-needed"] }
21+
anchor-spl = "0.29.0"
22+
solana-security-txt = "1.1.1"

programs/liquidation/Xargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.bpfel-unknown-unknown.dependencies.std]
2+
features = []

programs/liquidation/src/error.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use super::*;
2+
3+
#[error_code]
4+
pub enum LiquidationError {
5+
#[msg("Refunding is not enabled")]
6+
RefundingNotEnabled,
7+
#[msg("Liquidation is already activated")]
8+
AlreadyActivated,
9+
#[msg("No quote tokens to fund")]
10+
NothingToFund,
11+
#[msg("No base tokens assigned")]
12+
NoBaseAssigned,
13+
#[msg("Refund window has expired")]
14+
RefundWindowExpired,
15+
#[msg("Refund window has not expired")]
16+
RefundWindowNotExpired,
17+
#[msg("Duration must be greater than zero")]
18+
InvalidDuration,
19+
#[msg("Nothing to refund")]
20+
NothingToRefund,
21+
#[msg("Invalid allocation")]
22+
InvalidAllocation,
23+
#[msg("Invalid authority")]
24+
InvalidAuthority,
25+
#[msg("Invalid mint")]
26+
InvalidMint,
27+
}

programs/liquidation/src/events.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use anchor_lang::prelude::*;
2+
3+
#[derive(AnchorSerialize, AnchorDeserialize)]
4+
pub struct CommonFields {
5+
pub slot: u64,
6+
pub unix_timestamp: i64,
7+
pub liquidation_seq_num: u64,
8+
}
9+
10+
impl CommonFields {
11+
pub fn new(clock: &Clock, liquidation_seq_num: u64) -> Self {
12+
Self {
13+
slot: clock.slot,
14+
unix_timestamp: clock.unix_timestamp,
15+
liquidation_seq_num,
16+
}
17+
}
18+
}
19+
20+
#[event]
21+
pub struct LiquidationCreatedEvent {
22+
pub common: CommonFields,
23+
pub liquidation: Pubkey,
24+
pub create_key: Pubkey,
25+
pub record_authority: Pubkey,
26+
pub liquidation_authority: Pubkey,
27+
pub base_mint: Pubkey,
28+
pub quote_mint: Pubkey,
29+
pub duration_seconds: u32,
30+
pub pda_bump: u8,
31+
}
32+
33+
#[event]
34+
pub struct LiquidationActivatedEvent {
35+
pub common: CommonFields,
36+
pub liquidation: Pubkey,
37+
pub total_quote_funded: u64,
38+
pub started_at: i64,
39+
}
40+
41+
#[event]
42+
pub struct RefundRecordSetEvent {
43+
pub common: CommonFields,
44+
pub liquidation: Pubkey,
45+
pub refund_record: Pubkey,
46+
pub recipient: Pubkey,
47+
pub base_assigned: u64,
48+
pub quote_refundable: u64,
49+
pub liquidation_total_base_assigned: u64,
50+
pub liquidation_total_quote_refundable: u64,
51+
pub pda_bump: u8,
52+
}
53+
54+
#[event]
55+
pub struct RefundEvent {
56+
pub common: CommonFields,
57+
pub liquidation: Pubkey,
58+
pub refund_record: Pubkey,
59+
pub recipient: Pubkey,
60+
pub base_burned: u64,
61+
pub quote_refunded: u64,
62+
pub post_record_base_burned: u64,
63+
pub post_record_quote_refunded: u64,
64+
pub post_liquidation_total_base_burned: u64,
65+
pub post_liquidation_total_quote_refunded: u64,
66+
}
67+
68+
#[event]
69+
pub struct WithdrawRemainingQuoteEvent {
70+
pub common: CommonFields,
71+
pub liquidation: Pubkey,
72+
pub liquidation_authority: Pubkey,
73+
pub amount: u64,
74+
}

0 commit comments

Comments
 (0)