-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
b617806
219ceee
8f15760
880969a
8c7a2bb
75bb736
fc92353
7b304f9
d17a61b
a3f38db
63699e2
4bb1f20
75e0936
f2ae53d
a912f5e
528d295
0cc4ece
428962f
db900ff
84adc2f
6c2c3d0
68b36c5
ddd639d
276ea34
b88fe5d
dfdc9de
4f15bf2
3fa5174
1d00b80
a9dca3b
15f067d
59ca939
cb14c35
deaabab
2fecb5b
416f6b0
51b855d
87d8a32
c89fd56
cfec633
8695849
ffe39c6
c7e48f2
6c92641
bcd19d6
df151e1
92f6574
b0557ef
4bdf0ea
aca8cee
ba3cbfc
8eff171
c717e2a
74f5ca1
4ed087d
b076bc6
9981516
45cab2e
3fa7952
5781837
e32c0ff
13e1376
4f4574f
b97465e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ import { | |
PriceOracle, | ||
SpotLegInstrument, | ||
SpotQuoteInstrument, | ||
isRiskCategory, | ||
isOracleSource, | ||
addBaseAssetBuilder, | ||
registerMintBuilder, | ||
TransactionBuilder, | ||
|
@@ -16,7 +18,7 @@ import { createCvg, Opts } from './cvg'; | |
import { | ||
fetchBirdeyeTokenPrice, | ||
fetchCoinGeckoTokenPrice, | ||
getInstrumentType, | ||
extractBooleanString, | ||
getSigConfirmation, | ||
getSize, | ||
} from './helpers'; | ||
|
@@ -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, | ||
|
@@ -141,6 +143,20 @@ export const addInstrument = async (opts: Opts) => { | |
} | ||
}; | ||
|
||
export const addPrintTradeProvider = async (opts: Opts) => { | ||
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 { | ||
|
@@ -173,6 +189,85 @@ export const addBaseAsset = async (opts: Opts) => { | |
} | ||
}; | ||
|
||
export const changeBaseAssetParameters = async (opts: Opts) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function |
||
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 { | ||
|
@@ -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) { | ||
|
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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
}; |
There was a problem hiding this comment.
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.