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

feat: Add PoolCreated event #109

Open
wants to merge 31 commits into
base: staging
Choose a base branch
from
Open
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
2b6b42d
feat: Add PoolCreated event
quangkeu95 Jan 4, 2024
06010b8
fix: Remove fields from PoolCreated event
quangkeu95 Jan 4, 2024
17699b7
fix: Bump anchor dependencies
quangkeu95 Jan 5, 2024
be95855
chore: Add new updated idl.json
quangkeu95 Jan 5, 2024
caf727e
fix: Seperate the types into files
quangkeu95 Jan 5, 2024
bba87ee
fix: Update import path for anchor
quangkeu95 Jan 5, 2024
cb35e5a
fix: Update localnet wallet path
quangkeu95 Jan 5, 2024
6ef83fd
wip: Add event test for PoolCreated event
quangkeu95 Jan 5, 2024
b4a9157
fix: Update test setup for event test
quangkeu95 Jan 6, 2024
f6d16a2
fix: Using simulate method call
quangkeu95 Jan 6, 2024
b259a47
fix: Update test to use anchor test
quangkeu95 Jan 7, 2024
2fa60b7
chore: Format code
quangkeu95 Jan 8, 2024
429821d
fix: Update the IDL for new field in PoolCreated event
quangkeu95 Jan 8, 2024
ddb26dc
chore: Add subscribe pool account change test
quangkeu95 Jan 8, 2024
2f5d7d1
chore(format): Run pnpm fmt to format all the code
quangkeu95 Jan 8, 2024
cdf2681
feat: Update test for pool reserve tracking
quangkeu95 Jan 8, 2024
e2f515e
fix: Handle after reserve change triggered
quangkeu95 Jan 9, 2024
8e9ba8e
fix: Rebase main
quangkeu95 Jan 10, 2024
d0cf8c6
chore: Update staging AMM idl
quangkeu95 Jan 10, 2024
9d74448
fix: Update anchor localnet specific tests
quangkeu95 Jan 10, 2024
246c500
fix: Update IDL from amm staging
quangkeu95 Jan 12, 2024
416557f
fix: Satisfy cargo check
quangkeu95 Jan 12, 2024
a5e9436
fix: Fix cargo test
quangkeu95 Jan 12, 2024
aa4e1df
fix: Format cargo check
quangkeu95 Jan 12, 2024
d16b95a
chore: Add generated types
quangkeu95 Jan 12, 2024
d351ada
fix: Update PoolCreated event index
quangkeu95 Jan 15, 2024
55e697e
fix: Revert anchor and borsh dependencies version
quangkeu95 Jan 15, 2024
0852783
chore: Update pool test
quangkeu95 Jan 15, 2024
48e1d69
chore: Clone metaplex program
quangkeu95 Jan 15, 2024
cc895f0
fix: Remove generated files
quangkeu95 Jan 17, 2024
df64fe2
fix: Remove redundant
quangkeu95 Jan 17, 2024
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
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

.idea
.anchor
.DS_Store
target
Expand All @@ -9,5 +9,5 @@ test-ledger

ts-client/dist/
ts-client/package-lock.json

ts-client/.env
ts-client/.env
ts-client/.anchor
2 changes: 1 addition & 1 deletion Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ url = "https://anchor.projectserum.com"

[provider]
cluster = "localnet"
wallet = "/home/guantian/.config/solana/id.json"
wallet = "~/.config/solana/id.json"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 103 additions & 7 deletions programs/amm/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//! Event module includes information about events of the program
use crate::state::PoolType;
use anchor_lang::prelude::*;

/// Add liquidity event
#[event]
#[derive(Debug, Clone, Copy)]

pub struct AddLiquidity {
/// LP amount user received upon add liquidity.
pub lp_mint_amount: u64,
Expand All @@ -16,8 +15,6 @@ pub struct AddLiquidity {

/// Remove liquidity event
#[event]
#[derive(Debug, Clone, Copy)]

pub struct RemoveLiquidity {
/// LP amount burned from user upon add remove liquidity.
pub lp_unmint_amount: u64,
Expand All @@ -27,10 +24,21 @@ pub struct RemoveLiquidity {
pub token_b_out_amount: u64,
}

/// Swap event
/// Bootstrap liquidity event
#[event]
#[derive(Debug, Clone, Copy)]
pub struct BootstrapLiquidity {
/// LP amount user received upon add liquidity.
pub lp_mint_amount: u64,
/// Amount of token A user deposited.
pub token_a_amount: u64,
/// Amount of token B user deposited.
pub token_b_amount: u64,
/// Pool address
pub pool: Pubkey,
}

/// Swap event
#[event]
pub struct Swap {
/// Token amount user deposited to the pool for token exchange.
pub in_amount: u64,
Expand All @@ -44,9 +52,23 @@ pub struct Swap {
pub host_fee: u64,
}

/// Set pool fees event
#[event]
pub struct SetPoolFees {
/// New trade fee numerator
pub trade_fee_numerator: u64,
/// New trade fee denominator
pub trade_fee_denominator: u64,
/// New owner (admin) fee numerator
pub owner_trade_fee_numerator: u64,
/// New owner (admin) fee denominator
pub owner_trade_fee_denominator: u64,
/// Pool address
pub pool: Pubkey,
}

/// Pool info event
#[event]
#[derive(Debug, Clone, Copy)]
pub struct PoolInfo {
/// Total token A amount in the pool
pub token_a_amount: u64,
Expand All @@ -57,3 +79,77 @@ pub struct PoolInfo {
/// Current unix timestamp
pub current_timestamp: u64,
}

/// Transfer admin event
#[event]
pub struct TransferAdmin {
/// Old admin of the pool
pub admin: Pubkey,
/// New admin of the pool
pub new_admin: Pubkey,
/// Pool address
pub pool: Pubkey,
}

/// Set admin fee account event
#[event]
pub struct SetAdminFeeAccount {
/// Old admin token A fee account
pub admin_token_a_fee: Pubkey,
/// Old admin token B fee account
pub admin_token_b_fee: Pubkey,
/// New admin token A fee account
pub new_admin_token_a_fee: Pubkey,
/// New admin token B fee account
pub new_admin_token_b_fee: Pubkey,
}

/// Override curve param event
#[event]
pub struct OverrideCurveParam {
/// The new amplification for stable curve
pub new_amp: u64,
/// Updated timestamp
pub updated_timestamp: u64,
/// Pool address
pub pool: Pubkey,
}

/// New pool created event
#[event]
pub struct PoolCreated {
/// LP token mint of the pool
pub lp_mint: Pubkey, //32
/// Token A mint of the pool. Eg: USDT
pub token_a_mint: Pubkey, //32
/// Token B mint of the pool. Eg: USDC
pub token_b_mint: Pubkey, //32
/// Pool type
pub pool_type: PoolType,
/// Pool address
pub pool: Pubkey,
}

/// Pool enabled state change event
#[event]
pub struct PoolEnabled {
/// Pool address
pub pool: Pubkey,
/// Pool enabled state
pub enabled: bool,
}

/// Migrate fee account event
#[event]
pub struct MigrateFeeAccount {
/// Pool address
pub pool: Pubkey,
/// New admin token a fee
pub new_admin_token_a_fee: Pubkey,
/// New admin token b fee
pub new_admin_token_b_fee: Pubkey,
/// Transfer token a fee amount
pub token_a_amount: u64,
/// Transfer token b fee amount
pub token_b_amount: u64,
}
22 changes: 22 additions & 0 deletions ts-client/Anchor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"

[programs.localnet]
amm = "Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB"

[[test.genesis]]
address = "24Uqj9JCLxUeoC3hGfh5W3s9FM9uCHDS2SG3LYwBpyTi"
program = "fixtures/mercurial_vault.so"

[[test.genesis]]
address = "Eo7WjKq67rjJQSZxS6z3YkapzY3eMj6Xy8X5EQVn5UaB"
program = "fixtures/amm.so"

[[test.genesis]]
address = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
program = "fixtures/metaplex.so"

[scripts]
#test = "yarn run ts-mocha -t 1000000 -p ./tsconfig.json src/amm/tests/anchor/events.test.ts"
test = "pnpm ts-mocha -t 1000000 -p ./tsconfig.json --full-trace true src/amm/tests/anchor/*.test.ts "
Binary file added ts-client/fixtures/amm.so
Binary file not shown.
Binary file added ts-client/fixtures/mercurial_vault.so
Binary file not shown.
Binary file added ts-client/fixtures/metaplex.so
Binary file not shown.
1 change: 1 addition & 0 deletions ts-client/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
'^.+\\.ts?$': 'ts-jest',
},
transformIgnorePatterns: ['<rootDir>/node_modules/'],
testPathIgnorePatterns: ['<rootDir/>src/amm/tests/anchor'],
setupFiles: ['<rootDir>/jest/setup.js'],
testTimeout: TIMEOUT_SEC * 90,
};
8 changes: 8 additions & 0 deletions ts-client/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
generate-new-amm-fixture: build-amm-program-fixture
cp ../../mercurial-dynamic-amm/target/deploy/amm.so ./fixtures/amm.so

build-amm-program-fixture:
cd ../../mercurial-dynamic-amm/ && anchor build

copy-amm-idl:
cp ../../mercurial-dynamic-amm/target/types/amm.ts ./src/amm/idl.ts
10 changes: 8 additions & 2 deletions ts-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
"scripts": {
"build": "rm -rf dist && tsc -p tsconfig.build.json && tsc -p tsconfig.esm.json",
"test": "jest ./src/amm/tests/*.test.ts --runInBand --setupFiles dotenv/config",
"test-snapshot": "jest ./src/amm/tests/snapshot.test.ts --runInBand"
"test-snapshot": "jest ./src/amm/tests/snapshot.test.ts --runInBand",
"anchor-test": "anchor test",
"fmt": "pnpm prettier --write src/'**/*'.{ts,json}"
},
"files": [
"dist"
],
"dependencies": {
"@mercurial-finance/vault-sdk": "0.5.3",
"@project-serum/anchor": "0.24.2",
"@project-serum/borsh": "^0.2.5",
"@mercurial-finance/vault-sdk": "0.5.3",
"@saberhq/anchor-contrib": "1.13.32",
"@saberhq/stableswap-sdk": "1.13.32",
"@saberhq/token-utils": "1.13.32",
Expand All @@ -37,9 +39,13 @@
"@types/invariant": "^2.2.35",
"@types/jest": "^27.5.1",
"@types/mocha": "^9.1.1",
"anchor-client-gen": "^0.28.1",
"chai": "^4.3.6",
"jest": "^28.1.0",
"mocha": "^10.0.0",
"pino": "^8.17.2",
"pino-pretty": "^10.3.1",
"prettier": "^3.1.1",
"ts-jest": "^28.0.2",
"ts-mocha": "^10.0.0",
"typescript": "^4.7.2"
Expand Down
Loading
Loading