Skip to content

Commit f5d5a4f

Browse files
prettify (#1702)
1 parent 7a94a4a commit f5d5a4f

File tree

5 files changed

+146
-1
lines changed

5 files changed

+146
-1
lines changed

programs/drift/src/instructions/admin.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5100,6 +5100,27 @@ pub fn handle_add_amm_constituent_data<'info>(
51005100
Ok(())
51015101
}
51025102

5103+
pub fn handle_update_constituent_correlation_data<'info>(
5104+
ctx: Context<UpdateConstituentCorrelation>,
5105+
index1: u16,
5106+
index2: u16,
5107+
corr: i64,
5108+
) -> Result<()> {
5109+
let constituent_correlations = &mut ctx.accounts.constituent_correlations;
5110+
constituent_correlations.set_correlation(index1, index2, corr)?;
5111+
5112+
msg!(
5113+
"Updated correlation between constituent {} and {} to {}",
5114+
index1,
5115+
index2,
5116+
corr
5117+
);
5118+
5119+
constituent_correlations.validate()?;
5120+
5121+
Ok(())
5122+
}
5123+
51035124
pub fn handle_begin_lp_swap<'c: 'info, 'info>(
51045125
ctx: Context<'_, '_, 'c, 'info, LPTakerSwap<'info>>,
51055126
in_market_index: u16,
@@ -6459,6 +6480,24 @@ pub struct RemoveAmmConstituentMappingData<'info> {
64596480
pub state: Box<Account<'info, State>>,
64606481
}
64616482

6483+
#[derive(Accounts)]
6484+
pub struct UpdateConstituentCorrelation<'info> {
6485+
#[account(
6486+
mut,
6487+
constraint = admin.key() == admin_hot_wallet::id() || admin.key() == state.admin
6488+
)]
6489+
pub admin: Signer<'info>,
6490+
pub lp_pool: AccountLoader<'info, LPPool>,
6491+
6492+
#[account(
6493+
mut,
6494+
seeds = [CONSTITUENT_CORRELATIONS_PDA_SEED.as_ref(), lp_pool.key().as_ref()],
6495+
bump = constituent_correlations.bump,
6496+
)]
6497+
pub constituent_correlations: Box<Account<'info, ConstituentCorrelations>>,
6498+
pub state: Box<Account<'info, State>>,
6499+
}
6500+
64626501
#[derive(Accounts)]
64636502
#[instruction(
64646503
in_market_index: u16,

programs/drift/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,15 @@ pub mod drift {
18021802
handle_remove_amm_constituent_mapping_data(ctx, perp_market_index, constituent_index)
18031803
}
18041804

1805+
pub fn update_constituent_correlation_data(
1806+
ctx: Context<UpdateConstituentCorrelation>,
1807+
index1: u16,
1808+
index2: u16,
1809+
correlation: i64,
1810+
) -> Result<()> {
1811+
handle_update_constituent_correlation_data(ctx, index1, index2, correlation)
1812+
}
1813+
18051814
pub fn update_lp_constituent_target_base<'c: 'info, 'info>(
18061815
ctx: Context<'_, '_, 'c, 'info, UpdateConstituentTargetBase<'info>>,
18071816
) -> Result<()> {

sdk/src/adminClient.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4769,6 +4769,50 @@ export class AdminClient extends DriftClient {
47694769
];
47704770
}
47714771

4772+
public async updateConstituentCorrelationData(
4773+
lpPoolName: number[],
4774+
index1: number,
4775+
index2: number,
4776+
correlation: BN
4777+
): Promise<TransactionSignature> {
4778+
const ixs = await this.getUpdateConstituentCorrelationDataIx(
4779+
lpPoolName,
4780+
index1,
4781+
index2,
4782+
correlation
4783+
);
4784+
const tx = await this.buildTransaction(ixs);
4785+
const { txSig } = await this.sendTransaction(tx, []);
4786+
return txSig;
4787+
}
4788+
4789+
public async getUpdateConstituentCorrelationDataIx(
4790+
lpPoolName: number[],
4791+
index1: number,
4792+
index2: number,
4793+
correlation: BN
4794+
): Promise<TransactionInstruction[]> {
4795+
const lpPool = getLpPoolPublicKey(this.program.programId, lpPoolName);
4796+
return [
4797+
this.program.instruction.updateConstituentCorrelationData(
4798+
index1,
4799+
index2,
4800+
correlation,
4801+
{
4802+
accounts: {
4803+
admin: this.wallet.publicKey,
4804+
lpPool,
4805+
constituentCorrelations: getConstituentCorrelationsPublicKey(
4806+
this.program.programId,
4807+
lpPool
4808+
),
4809+
state: await this.getStatePublicKey(),
4810+
},
4811+
}
4812+
),
4813+
];
4814+
}
4815+
47724816
/**
47734817
* Get the drift begin_swap and end_swap instructions
47744818
*

sdk/src/idl/drift.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7591,6 +7591,45 @@
75917591
}
75927592
]
75937593
},
7594+
{
7595+
"name": "updateConstituentCorrelationData",
7596+
"accounts": [
7597+
{
7598+
"name": "admin",
7599+
"isMut": true,
7600+
"isSigner": true
7601+
},
7602+
{
7603+
"name": "lpPool",
7604+
"isMut": false,
7605+
"isSigner": false
7606+
},
7607+
{
7608+
"name": "constituentCorrelations",
7609+
"isMut": true,
7610+
"isSigner": false
7611+
},
7612+
{
7613+
"name": "state",
7614+
"isMut": false,
7615+
"isSigner": false
7616+
}
7617+
],
7618+
"args": [
7619+
{
7620+
"name": "index1",
7621+
"type": "u16"
7622+
},
7623+
{
7624+
"name": "index2",
7625+
"type": "u16"
7626+
},
7627+
{
7628+
"name": "correlation",
7629+
"type": "i64"
7630+
}
7631+
]
7632+
},
75947633
{
75957634
"name": "updateLpConstituentTargetBase",
75967635
"accounts": [

tests/lpPool.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ describe('LP Pool', () => {
477477
assert(ammCache.cache[0].oraclePrice.eq(new BN(200000000)));
478478
});
479479

480-
it('can update constituent properties', async () => {
480+
it('can update constituent properties and correlations', async () => {
481481
const constituentPublicKey = getConstituentPublicKey(
482482
program.programId,
483483
lpPoolKey,
@@ -505,6 +505,20 @@ describe('LP Pool', () => {
505505
)) as ConstituentTargetBase;
506506
expect(targets).to.not.be.null;
507507
assert(targets.targets[constituent.constituentIndex].costToTradeBps == 10);
508+
509+
await adminClient.updateConstituentCorrelationData(
510+
encodeName(lpPoolName),
511+
0,
512+
1,
513+
PERCENTAGE_PRECISION.muln(87).divn(100)
514+
);
515+
516+
await adminClient.updateConstituentCorrelationData(
517+
encodeName(lpPoolName),
518+
0,
519+
1,
520+
PERCENTAGE_PRECISION
521+
);
508522
});
509523

510524
it('fails adding datum with bad params', async () => {

0 commit comments

Comments
 (0)