Skip to content

Commit

Permalink
[Tooling] Update to 9.0.0 for alloyx support (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
crypto-vincent authored Nov 21, 2023
1 parent bcb6b76 commit ce252a3
Show file tree
Hide file tree
Showing 14 changed files with 139 additions and 482 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ scripts/swap_ci_resident_program_id.sh.bak
.github/workflows/ci-anchor-test.yml.bak
docker-target/
/**/.DS_Store
payer.json
10 changes: 5 additions & 5 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"target-deploy-format-check": "prettier --check 'target/deploy'",
"target-types-format-check": "prettier --check 'target/types'",
"target-format-check": "npm run target-idl-format-check && npm run target-deploy-format-check && npm run target-types-format-check",
"maintenance-collect-profits-mercurial": "npx ts-node scripts/trigger_collect_profits_mercurial.ts",
"maintenance-rebalance-credix": "npx ts-node scripts/trigger_rebalance_credix.ts",
"lint": "npm run source-lint && npm run tests-lint",
"format": "npm run source-format && npm run tests-format && npm run target-format",
"format-check": "npm run source-format-check && npm run tests-format-check && npm run target-format-check",
Expand Down
16 changes: 9 additions & 7 deletions programs/uxd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uxd"
version = "8.2.0"
version = "9.0.0"
authors = [
"acammm <[email protected]>",
"cnek <[email protected]>",
Expand All @@ -27,20 +27,22 @@ production = []
development = []

[dependencies]
uxd-cpi = { version = "8.2.0", features = ["development"] }

anchor-lang = "0.26.0"
anchor-spl = "0.26.0"
mercurial-vault = { git = "https://github.com/mercurial-finance/vault-sdk", features = [
"cpi",
], rev = "3724175d8435f7acb7a33077a5a9f1eb58ab3399" }

alloyx-cpi = { version = "0.0.2" }

credix_client = { version = "0.9.1", features = [
"pre-mainnet",
"cpi",
], default-features = false }

alloyx-cpi = { version = "0.0.3", features = ["development"] }

uxd-cpi = { version = "9.0.0", features = ["development"] }

anchor-lang = "0.26.0"
anchor-spl = "0.26.0"

num-traits = "0.2.15"
num = "0.4.0"

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ async fn test_ensure_devnet() -> Result<(), program_context::ProgramError> {
)
.await?;

/* TODO - temporarily disabled as credix disabled their minting for now */
/*
program_uxd::instructions::process_mint_with_credix_lp_depository(
&mut program_context,
&payer,
Expand All @@ -434,6 +436,7 @@ async fn test_ensure_devnet() -> Result<(), program_context::ProgramError> {
10_000, // 0.01 collateral
)
.await?;
*/

program_uxd::instructions::process_rebalance_alloyx_vault_depository(
&mut program_context,
Expand Down
60 changes: 47 additions & 13 deletions scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
IdentityDepository,
MercurialVaultDepository,
CredixLpDepository,
AlloyxVaultDepository,
Controller,
} from '@uxd-protocol/uxd-client';

const TXN_COMMIT = 'confirmed';
Expand All @@ -23,47 +25,58 @@ export const TXN_OPTS = {
skipPreflight: true,
} as ConfirmOptions;

export const uxdProgramId = new PublicKey(
export const uxdProgramIdMainnet = new PublicKey(
'UXD8m9cvwk4RcSxnX2HZ9VudQCEeDH6fRnB4CAP57Dr'
);
const usdcMint = new PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
const usdcMintMainnet = new PublicKey(
'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
);

export function getConnection() {
export function getConnectionMainnet() {
const connection = new Connection(
'https://api.mainnet-beta.solana.com',
connectionConfig
);
return connection;
}

export function createIdentityDepository() {
return new IdentityDepository(usdcMint, 'USDC', 6, uxdProgramId);
export function createControllerMainnet() {
return new Controller('UXD', 6, uxdProgramIdMainnet);
}

export function createIdentityDepositoryMainnet() {
return new IdentityDepository(
usdcMintMainnet,
'USDC',
6,
uxdProgramIdMainnet
);
}

export async function createMercurialVaultDepository() {
export async function createMercurialVaultDepositoryMainnet() {
try {
return await MercurialVaultDepository.initialize({
connection: getConnection(),
connection: getConnectionMainnet(),
collateralMint: {
mint: usdcMint,
mint: usdcMintMainnet,
name: 'USDC',
symbol: 'USDC',
decimals: 6,
},
uxdProgramId,
uxdProgramId: uxdProgramIdMainnet,
});
} catch (error) {
console.error('Failed to initialize mercurial depository');
throw error;
}
}

export async function createCredixLpDepository() {
export async function createCredixLpDepositoryMainnet() {
try {
return await CredixLpDepository.initialize({
connection: getConnection(),
uxdProgramId: uxdProgramId,
collateralMint: usdcMint,
connection: getConnectionMainnet(),
uxdProgramId: uxdProgramIdMainnet,
collateralMint: usdcMintMainnet,
collateralSymbol: 'USDC',
credixProgramId: new PublicKey(
'CRDx2YkdtYtGZXGHZ59wNv1EwKHQndnRc1gT4p8i2vPX'
Expand All @@ -75,6 +88,27 @@ export async function createCredixLpDepository() {
}
}

export async function createAlloyxVaultDepositoryMainnet() {
try {
return await AlloyxVaultDepository.initialize({
connection: getConnectionMainnet(),
uxdProgramId: uxdProgramIdMainnet,
collateralMint: usdcMintMainnet,
collateralSymbol: 'USDC',
alloyxVaultId: 'diversified_public_credit',
alloyxVaultMint: new PublicKey(
'EF6UUehY8YHUiNBp9yp6HVj1nknK1vW2kgTdZwZT2px7'
),
alloyxProgramId: new PublicKey(
'5fuCN8tquSXRJ97f5TP31cLwViuzHmdkyqiprqtz2DTx'
),
});
} catch (error) {
console.error('Failed to initialize credix depository');
throw error;
}
}

// CI script payer on mainnet: 4NtUyktW5evy1Ez4BgfnRBdU7PLsmDRiZiH5HfBPGRSs
export const payer = Keypair.fromSecretKey(
Buffer.from(JSON.parse(require('fs').readFileSync('./payer.json', 'utf-8')))
Expand Down
5 changes: 2 additions & 3 deletions scripts/download_integrations_binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ solana program dump CRDx2YkdtYtGZXGHZ59wNv1EwKHQndnRc1gT4p8i2vPX programs/uxd/te
solana config set --url https://api.devnet.solana.com
solana program dump 8U29WVwDFLxFud36okhqrngUquaZqVnVL9uE5G8DzX5c programs/uxd/tests/integration_tests/api/program_alloyx/binaries/executable-devnet.so

# Alloyx not main-net live yet
# solana config set --url https://api.mainnet-beta.solana.com
# solana program dump 8U29WVwDFLxFud36okhqrngUquaZqVnVL9uE5G8DzX5c programs/uxd/tests/integration_tests/api/program_alloyx/binaries/executable-mainnet-beta.so
solana config set --url https://api.mainnet-beta.solana.com
solana program dump 5fuCN8tquSXRJ97f5TP31cLwViuzHmdkyqiprqtz2DTx programs/uxd/tests/integration_tests/api/program_alloyx/binaries/executable-mainnet-beta.so
31 changes: 18 additions & 13 deletions scripts/trigger_collect_profits_mercurial.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { web3 } from '@project-serum/anchor';
import { amountToUiAmount } from '@solana/spl-token';
import { Transaction } from '@solana/web3.js';
import { Controller, UXDClient } from '@uxd-protocol/uxd-client';
import { UXDClient } from '@uxd-protocol/uxd-client';
import {
createMercurialVaultDepository,
getConnection,
createControllerMainnet,
createMercurialVaultDepositoryMainnet,
getConnectionMainnet,
payer,
TXN_OPTS,
uxdProgramId,
uxdProgramIdMainnet,
} from './common';

async function main() {
const controller = new Controller('UXD', 6, uxdProgramId);
const depository = await createMercurialVaultDepository();
const controller = createControllerMainnet();
const depository = await createMercurialVaultDepositoryMainnet();

controller.info();
depository.info();

const profitsBeneficiaryCollateral = (
await depository.getOnchainAccount(getConnection(), TXN_OPTS)
await depository.getOnchainAccount(getConnectionMainnet(), TXN_OPTS)
).profitsBeneficiaryCollateral;
const profitsBeneficiaryCollateralAmountBefore = (
await getConnection().getTokenAccountBalance(profitsBeneficiaryCollateral)
await getConnectionMainnet().getTokenAccountBalance(
profitsBeneficiaryCollateral
)
).value.uiAmount;
console.log(
'profitsBeneficiaryCollateral',
Expand All @@ -33,19 +36,19 @@ async function main() {
);

const estimatedProfitsCollectedAmount = await amountToUiAmount(
getConnection(),
getConnectionMainnet(),
payer,
depository.collateralMint.mint,
(
await depository.calculateProfitsValue(getConnection(), TXN_OPTS)
await depository.calculateProfitsValue(getConnectionMainnet(), TXN_OPTS)
).toNumber()
);
console.log(
'estimatedProfitsCollectedAmount',
estimatedProfitsCollectedAmount
);

const uxdClient = new UXDClient(uxdProgramId);
const uxdClient = new UXDClient(uxdProgramIdMainnet);

const collectProfitsOfMercurialVaultDepositoryIx =
uxdClient.createCollectProfitsOfMercurialVaultDepositoryInstruction(
Expand All @@ -61,15 +64,17 @@ async function main() {

try {
const txId = await web3.sendAndConfirmTransaction(
getConnection(),
getConnectionMainnet(),
tx,
[payer],
TXN_OPTS
);
console.log(`🔗 'https://explorer.solana.com/tx/${txId}'`);

const profitsBeneficiaryCollateralAmountAfter = (
await getConnection().getTokenAccountBalance(profitsBeneficiaryCollateral)
await getConnectionMainnet().getTokenAccountBalance(
profitsBeneficiaryCollateral
)
).value.uiAmount;
console.log(
'profitsBeneficiaryCollateral amount after',
Expand Down
Loading

0 comments on commit ce252a3

Please sign in to comment.