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

Print trade provider logic and Hxro #230

Merged
merged 64 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
b617806
Update CPL libraries, add changes to existing logic
EquilateralDelta Aug 22, 2023
219ceee
Fix several minor upgrade problems
EquilateralDelta Aug 25, 2023
8f15760
Hxro RFQ creation WIP
EquilateralDelta Aug 29, 2023
880969a
Finish minimal hxro print trade provider module
EquilateralDelta Aug 30, 2023
8c7a2bb
Add fetch hxro products instruction
EquilateralDelta Aug 31, 2023
75bb736
Add print trade RFQ and working creation logic
EquilateralDelta Sep 5, 2023
fc92353
Update programs and fixtures
EquilateralDelta Sep 5, 2023
7b304f9
Add actions to modify hxro config and update cli
EquilateralDelta Sep 6, 2023
d17a61b
Add collateral calculation for print trade legs
EquilateralDelta Sep 7, 2023
a3f38db
Prepare settlement WIP and add hxro operator trg initialization
EquilateralDelta Sep 11, 2023
63699e2
Add print trade provider registration
EquilateralDelta Sep 12, 2023
4bb1f20
Bump version, add bootstrap commands
EquilateralDelta Sep 12, 2023
75e0936
Merge branch 'dev' into sdk-279-add-hxro-integration-to-sdk
EquilateralDelta Sep 12, 2023
f2ae53d
Bump versions and fix response state
EquilateralDelta Sep 12, 2023
a912f5e
Add change base asset SDK and CLI operations
EquilateralDelta Sep 13, 2023
528d295
Add a working hxro preparation for the settlement
EquilateralDelta Sep 15, 2023
0cc4ece
Bump versions and add slip preflight to the CLI
EquilateralDelta Sep 15, 2023
428962f
Add expiration to hxro term futures and filter out expired products
EquilateralDelta Sep 15, 2023
db900ff
Make leg info public and add ability to extend data
EquilateralDelta Sep 18, 2023
84adc2f
bump version
EquilateralDelta Sep 18, 2023
6c2c3d0
Add support for print trade settlement
EquilateralDelta Sep 18, 2023
68b36c5
Add an ability to clean a print trade rfq
EquilateralDelta Sep 20, 2023
ddd639d
Update hxro fee derivation and bump versions
EquilateralDelta Sep 20, 2023
276ea34
Update hxro fixtures
EquilateralDelta Sep 20, 2023
b88fe5d
Add revert preparations for print trade
EquilateralDelta Sep 21, 2023
dfdc9de
Add hxro integration tests
EquilateralDelta Sep 22, 2023
4f15bf2
Bump versions
EquilateralDelta Sep 22, 2023
3fa5174
Merge dev
EquilateralDelta Dec 7, 2023
1d00b80
Fix compilation issues after a merge
EquilateralDelta Dec 7, 2023
a9dca3b
Fix existing tests and print trade rfq creation and responding
EquilateralDelta Dec 7, 2023
15f067d
Hxro sdk update in progress
EquilateralDelta Dec 13, 2023
59ca939
Hxro update WIP
EquilateralDelta Dec 14, 2023
cb14c35
Add proper hxro functionality for unlocking collateral
EquilateralDelta Dec 15, 2023
deaabab
Bump package versions
EquilateralDelta Dec 15, 2023
2fecb5b
Fix cli inconsistencies and bump versions
EquilateralDelta Jan 2, 2024
416f6b0
Add fit logic for a tx logic and refactor some hxro code
EquilateralDelta Jan 3, 2024
51b855d
Bump package versions
EquilateralDelta Jan 5, 2024
87d8a32
Update hxro depencency
EquilateralDelta Jan 5, 2024
c89fd56
Merge remote-tracking branch 'origin/dev' into sdk-279-add-hxro-integ…
EquilateralDelta Jan 8, 2024
cfec633
Finish merge and publish new package version
EquilateralDelta Jan 8, 2024
8695849
Update hxro dependency
EquilateralDelta Jan 17, 2024
ffe39c6
Bump package versions
EquilateralDelta Jan 17, 2024
c7e48f2
Merge branch 'dev' of github.com:convergence-rfq/convergence-sdk into…
Nagaprasadvr Feb 1, 2024
6c92641
change programs
Nagaprasadvr Feb 1, 2024
bcd19d6
fix tests
Nagaprasadvr Feb 6, 2024
df151e1
changelog
Nagaprasadvr Feb 6, 2024
92f6574
update cpl packages
Nagaprasadvr Feb 14, 2024
b0557ef
add changeset
Nagaprasadvr Feb 14, 2024
4bdf0ea
Merge branch 'dev' of github.com:convergence-rfq/convergence-sdk into…
Nagaprasadvr Feb 27, 2024
aca8cee
resolve conflicts
Nagaprasadvr Feb 27, 2024
ba3cbfc
fix programs
Nagaprasadvr Feb 27, 2024
8eff171
fix calculate collateral fn
Nagaprasadvr Feb 29, 2024
c717e2a
Update tests.yml
Nagaprasadvr Feb 29, 2024
74f5ca1
Update tests.yml
Nagaprasadvr Feb 29, 2024
4ed087d
Update tests.yml
Nagaprasadvr Feb 29, 2024
b076bc6
Update tests.yml
Nagaprasadvr Feb 29, 2024
9981516
Update tests.yml
Nagaprasadvr Feb 29, 2024
45cab2e
Merge pull request #273 from convergence-rfq/eng-1827-fix-collateral-…
Nagaprasadvr Feb 29, 2024
3fa7952
Merge branch 'dev' of github.com:convergence-rfq/convergence-sdk into…
Nagaprasadvr Feb 29, 2024
5781837
Remove collateral requirement and add spot fees
EquilateralDelta Mar 6, 2024
e32c0ff
Merge pull request #278 from convergence-rfq/spot-rework
Nagaprasadvr Mar 7, 2024
13e1376
Add changeset for the latest changes
EquilateralDelta Mar 7, 2024
4f4574f
resolve conflicts
Nagaprasadvr Mar 7, 2024
b97465e
Merge branch 'dev' of github.com:convergence-rfq/convergence-sdk into…
Nagaprasadvr Mar 7, 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
7 changes: 7 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,12 @@ jobs:
shell: bash
run: yarn validator & sleep 3

- name: Logs
continue-on-error: false
shell: bash
run: yarn validator:logs & sleep 3

- name: Test
run: yarn test


25 changes: 25 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# @convergence-rfq/cli

## 6.1.0

### Minor Changes

- Remove collateral requirements, add quote spot fees, add spot instrument config, remove operations to unlock collateral or settle defaults

### Patch Changes

- Updated dependencies
- @convergence-rfq/[email protected]

## 6.0.1

### Patch Changes

- Updated dependencies
- @convergence-rfq/[email protected]

## 6.0.0

### Patch Changes

- Updated dependencies
- @convergence-rfq/[email protected]

## 4.5.35

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@convergence-rfq/cli",
"description": "Official Convergence CLI",
"version": "4.5.35",
"version": "6.1.0",
"license": "MIT",
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -47,7 +47,7 @@
"cli": "ts-node src/index.ts"
},
"dependencies": {
"@convergence-rfq/sdk": "4.5.35",
"@convergence-rfq/sdk": "6.1.0",
"@solana/web3.js": "^1.87.6",
"@types/cookie": "^0.5.1",
"commander": "^10.0.0"
Expand Down
13 changes: 10 additions & 3 deletions packages/cli/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ set -e

export DEVNET="true"

export SPOT_INSTRUMENT="CjQCEjXtG3QNBuT5Z1sctaAYCo5Mt6edftqHQetEPo9w"
export PSYOPTIONS_EUROPEAN_INSTRUMENT="A86fhhdNVDdXV8pB48WXtPeM3EBkcBeJEdrx9xrUo9nF"
export PSYOPTIONS_AMERICAN_INSTRUMENT="6JG1tWK4w6LmjeXbmDZJsmUsPSjgnp74j2XPsTvjjTX8"
export SPOT_INSTRUMENT="4A9M7iojGDPc4n4YDGnTmsYsNKUohG1zM1nrAqVMMmrm"
export PSYOPTIONS_EUROPEAN_INSTRUMENT="6B7TdBNAF7tWWz5sZbbBZj8jH1ix7QWAchtkvMHveEuW"
export PSYOPTIONS_AMERICAN_INSTRUMENT="HGmSFSRfVAG8RC8Ae4G1JFSHK7Au5GrGskDxncG3JRok"
export HXRO_PRINT_TRADE_PROVIDER="4WbVwc5Edfo3oB1n16bVC9qrghYHSNh1qAECbSCyiT95"

# Same for devnet and mainnet
export BTC_ORACLE_ADDRESS="8SXvChNYFhRq4EZuZvnhjrB3jJRQCv4k3P4W6hesH3Ee"
Expand All @@ -31,6 +32,12 @@ convergence protocol initialize --collateral-mint=$USDC_MINT --rpc-endpoint=$RPC

convergence risk-engine initialize --rpc-endpoint=$RPC_ENDPOINT

convergence protocol add-print-trade-provider --print-trade-provider-program $HXRO_PRINT_TRADE_PROVIDER --settlement-can-expire false --validate-response-account-amount 2 --rpc-endpoint=$RPC_ENDPOINT
convergence hxro initialize-config --valid-mpg $HXRO_MPG --rpc-endpoint=$RPC_ENDPOINT
convergence hxro initialize-operator-trg --rpc-endpoint=$RPC_ENDPOINT

convergence spot-instrument initialize-config --fee-bps "0.01" --rpc-endpoint=$RPC_ENDPOINT

convergence protocol add-instrument --instrument-program=$SPOT_INSTRUMENT --can-be-used-as-quote=true --validate-data-account-amount=1 --prepare-to-settle-account-amount=7 --settle-account-amount=3 --revert-preparation-account-amount=3 --clean-up-account-amount=4 --rpc-endpoint=$RPC_ENDPOINT
convergence protocol add-instrument --instrument-program=$PSYOPTIONS_EUROPEAN_INSTRUMENT --can-be-used-as-quote=false --validate-data-account-amount=2 --prepare-to-settle-account-amount=7 --settle-account-amount=3 --revert-preparation-account-amount=3 --clean-up-account-amount=4 --rpc-endpoint=$RPC_ENDPOINT
convergence protocol add-instrument --instrument-program=$PSYOPTIONS_AMERICAN_INSTRUMENT --can-be-used-as-quote=false --validate-data-account-amount=3 --prepare-to-settle-account-amount=7 --settle-account-amount=3 --revert-preparation-account-amount=3 --clean-up-account-amount=4 --rpc-endpoint=$RPC_ENDPOINT
Expand Down
101 changes: 98 additions & 3 deletions packages/cli/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
PriceOracle,
SpotLegInstrument,
SpotQuoteInstrument,
isRiskCategory,
isOracleSource,
addBaseAssetBuilder,
registerMintBuilder,
TransactionBuilder,
Expand All @@ -16,7 +18,7 @@ import { createCvg, Opts } from './cvg';
import {
fetchBirdeyeTokenPrice,
fetchCoinGeckoTokenPrice,
getInstrumentType,
extractBooleanString,
getSigConfirmation,
getSize,
} from './helpers';
Expand Down Expand Up @@ -128,7 +130,7 @@ export const addInstrument = async (opts: Opts) => {
const { response } = await cvg.protocol().addInstrument({
authority: cvg.rpc().getDefaultFeePayer(),
instrumentProgram: new PublicKey(opts.instrumentProgram),
canBeUsedAsQuote: opts.canBeUsedAsQuote,
canBeUsedAsQuote: extractBooleanString(opts, 'canBeUsedAsQuote'),
validateDataAccountAmount: opts.validateDataAccountAmount,
prepareToSettleAccountAmount: opts.prepareToSettleAccountAmount,
settleAccountAmount: opts.settleAccountAmount,
Expand All @@ -141,6 +143,20 @@ export const addInstrument = async (opts: Opts) => {
}
};

export const addPrintTradeProvider = async (opts: Opts) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

const cvg = await createCvg(opts);
try {
const { response } = await cvg.protocol().addPrintTradeProvider({
printTradeProviderProgram: new PublicKey(opts.printTradeProviderProgram),
settlementCanExpire: extractBooleanString(opts, 'settlementCanExpire'),
validateResponseAccountAmount: opts.validateResponseAccountAmount,
});
logResponse(response);
} catch (e) {
logError(e);
}
};

export const addBaseAsset = async (opts: Opts) => {
const cvg = await createCvg(opts);
try {
Expand Down Expand Up @@ -173,6 +189,85 @@ export const addBaseAsset = async (opts: Opts) => {
}
};

export const changeBaseAssetParameters = async (opts: Opts) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function changeBaseAssetParameters has 69 lines of code (exceeds 25 allowed). Consider refactoring.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function changeBaseAssetParameters has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.

const cvg = await createCvg(opts);
try {
const {
index,
enabled: enabledOpts,
riskCategory,
oracleSource,
switchboardOracle: switchboardOracleOpts,
pythOracle: pythOracleOpts,
inPlacePrice: inPlacePriceOpts,
}: {
index: number;
enabled?: string;
riskCategory?: string;
oracleSource?: string;
switchboardOracle?: string;
pythOracle?: string;
inPlacePrice?: number;
} = opts;

let enabled;
switch (enabledOpts) {
case undefined:
break;
case 'true':
enabled = true;
break;
case 'false':
enabled = false;
break;
default:
throw new Error('Unrecognized enabled parameter!');
}

if (riskCategory !== undefined && !isRiskCategory(riskCategory)) {
throw new Error('Unrecognized risk category parameter!');
}

if (oracleSource !== undefined && !isOracleSource(oracleSource)) {
throw new Error('Unrecognized oracle source parameter!');
}

let switchboardOracle;
if (switchboardOracleOpts === 'none') {
switchboardOracle = null;
} else if (typeof switchboardOracleOpts === 'string') {
switchboardOracle = new PublicKey(switchboardOracleOpts);
}

let pythOracle;
if (pythOracleOpts === 'none') {
pythOracle = null;
} else if (typeof pythOracleOpts === 'string') {
pythOracle = new PublicKey(pythOracleOpts);
}

let inPlacePrice;
if (inPlacePriceOpts === -1) {
inPlacePrice = null;
} else if (typeof inPlacePriceOpts === 'number') {
inPlacePrice = inPlacePriceOpts;
}

const { response } = await cvg.protocol().changeBaseAssetParameters({
index,
enabled,
riskCategory,
oracleSource,
switchboardOracle,
pythOracle,
inPlacePrice,
});
logResponse(response);
} catch (e) {
logError(e);
}
};

export const updateBaseAsset = async (opts: Opts) => {
const cvg = await createCvg(opts);
const {
Expand Down Expand Up @@ -443,7 +538,7 @@ export const setRiskEngineInstrumentType = async (opts: Opts) => {
try {
const { response } = await cvg.riskEngine().setInstrumentType({
instrumentProgram: new PublicKey(opts.program),
instrumentType: getInstrumentType(opts.type),
instrumentType: opts.type,
});
logResponse(response);
} catch (e) {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
airdropGroup,
rfqGroup,
tokenGroup,
hxroGroup,
spotInstrumentGroup,
} from './groups';

export const makeCli = (): Command => {
Expand All @@ -17,6 +19,8 @@ export const makeCli = (): Command => {
riskEngineGroup,
collateralGroup,
rfqGroup,
hxroGroup,
spotInstrumentGroup,
];

const cli = new Command();
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/cvg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ export const createCvg = async (opts: Opts): Promise<Convergence> => {
new Connection(opts.rpcEndpoint, {
commitment: 'confirmed',
}),

{ transactionPriority: opts?.txPriority ?? 'none', skipPreflight: false }
{ skipPreflight: opts.skipPreflight }
);
cvg.use(keypairIdentity(user));
return cvg;
Expand Down
120 changes: 120 additions & 0 deletions packages/cli/src/groups/hxro.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/* eslint-disable no-console */

import { Command } from 'commander';

import { PublicKey } from '@solana/web3.js';
import { HxroProductInfo } from '@convergence-rfq/sdk';
import { addCmd } from '../helpers';
import { createCvg, Opts } from '../cvg';
import { logError, logHxroConfig, logResponse } from '../logger';

const initializeConfigCmd = (c: Command) =>
addCmd(c, 'initialize-config', 'initializes hxro config', initializeConfig, [
{
flags: '--valid-mpg <string>',
description: 'Valid Hxro market product group',
},
]);

const initializeConfig = async (opts: Opts) => {
const cvg = await createCvg(opts);
try {
const response = await cvg
.hxro()
.initializeConfig({ validMpg: new PublicKey(opts.validMpg) });
logResponse(response);
} catch (e) {
logError(e);
}
};

const modifyConfigCmd = (c: Command) =>
addCmd(c, 'modify-config', 'modifiess hxro config', modifyConfig, [
{
flags: '--valid-mpg <string>',
description: 'Valid Hxro market product group',
},
]);

const modifyConfig = async (opts: Opts) => {
const cvg = await createCvg(opts);
try {
const response = await cvg
.hxro()
.modifyConfig({ validMpg: new PublicKey(opts.validMpg) });
logResponse(response);
} catch (e) {
logError(e);
}
};

const displayConfigCmd = (c: Command) =>
addCmd(c, 'display-config', 'displays hxro config', displayConfig, []);

const displayConfig = async (opts: Opts) => {
const cvg = await createCvg(opts);
try {
const config = await cvg.hxro().fetchConfig();
logHxroConfig(config);
} catch (e) {
logError(e);
}
};

const displayProductsCmd = (c: Command) =>
addCmd(c, 'display-products', 'displays hxro products', displayProducts, []);

const displayProducts = async (opts: Opts) => {
const cvg = await createCvg(opts);
try {
const products: HxroProductInfo[] = await cvg.hxro().fetchProducts();
console.log(`Products amount: ${products.length}`);
products.forEach((product) => {
console.log(JSON.stringify(product));
});
} catch (e) {
logError(e);
}
};

const initializeOperatorTRGCmd = (c: Command) =>
addCmd(
c,
'initialize-operator-trg',
'initialized a trg for an operator, which is required for hxro settlements',
initializeOperatorTRG,
[
{
flags: '--hxro-risk-engine <string>',
description:
'Overrides hxro risk engine address. Should be used primarely for testing purposes',
defaultValue: '',
},
]
);

const initializeOperatorTRG = async (opts: Opts) => {
const cvg = await createCvg(opts);

try {
const hxroRiskEngineAddress =
opts.hxroRiskEngine !== ''
? new PublicKey(opts.hxroRiskEngine)
: undefined;
const response = await cvg.hxro().initializeOperatorTraderRiskGroup({
hxroRiskEngineAddress,
});
logResponse(response);
} catch (e) {
logError(e);
}
};

export const hxroGroup = (c: Command) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

const group = c.command('hxro');
initializeConfigCmd(group);
modifyConfigCmd(group);
displayConfigCmd(group);
initializeOperatorTRGCmd(group);
displayProductsCmd(group);
};
2 changes: 2 additions & 0 deletions packages/cli/src/groups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export * from './protocol';
export * from './rfq';
export * from './riskEngine';
export * from './token';
export * from './hxro';
export * from './spotInstrument';
Loading
Loading