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

market example with protocolSDK #2

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import '@nomiclabs/hardhat-ethers';
import '@typechain/hardhat';
import 'hardhat-dependency-compiler';

import { lyraContractPaths } from '@lyrafinance/protocol/dist/test/utils/package/index-paths';

export default {
networks: {
hardhat: {},
local: {
url: 'http://127.0.0.1:8545',
gasPrice: 0,
},
'kovan-ovm': {
url: 'https://kovan.optimism.io',
ovm: true,
},
},
solidity: {
version: '0.8.9',
settings: {
optimizer: {
enabled: true,
runs: 1,
},
},
},
dependencyCompiler: {
paths: lyraContractPaths,
},
};
Binary file added lyrafinance-protocol-0.1.1.e-alpha.tgz
Binary file not shown.
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@
"@ethersproject/strings": "^5.6.0",
"@ethersproject/units": "^5.6.0",
"@ethersproject/wallet": "^5.6.0",
"@lyrafinance/protocol": "./lyrafinance-protocol-0.1.1.e-alpha.tgz",
"@nomiclabs/hardhat-ethers": "^2.0.5",
"@typechain/hardhat": "^3.0.0",
"ethers": "^5.6.0",
"graphql": "^16.4.0",
"graphql-request": "^4.2.0"
"graphql-request": "^4.2.0",
"hardhat-dependency-compiler": "^1.1.2"
},
"devDependencies": {
"@typechain/ethers-v5": "^9.0.0",
"@typechain/ethers-v5": "^8.0.5",
"@types/fs-extra": "^9.0.13",
"@types/mkdirp": "^1.0.2",
"@types/node": "^17.0.21",
Expand All @@ -56,12 +60,16 @@
"eslint-plugin-simple-import-sort": "^7.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"fs-extra": "^10.0.1",
"hardhat": "^2.9.7",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"ts-node": "^10.5.0",
"tslib": "^2.4.0",
"typechain": "^7.0.0",
"typescript": "^4.5.5",
"yargs": "^17.3.1"
},
"peerDependencies": {
"hardhat": "^2.9.7"
}
}
12 changes: 12 additions & 0 deletions src/examples/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import yargs from 'yargs'
import fromBigNumber from '../utils/fromBigNumber'
import getLyra from './utils/getLyra'

async function main() {
await market(["--market", "sETH"]);
}

export default async function market(argv: string[]) {
const lyra = getLyra()
const args = await yargs(argv).options({
market: { type: 'string', alias: 'm', require: true },
}).argv
console.log(args);
const market = await lyra.market(args.market)
console.log({
address: market.address,
Expand All @@ -26,3 +31,10 @@ export default async function market(argv: string[]) {
.flat(),
})
}

main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
17 changes: 10 additions & 7 deletions src/utils/getERC20Contract.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Contract } from '@ethersproject/contracts'
import { JsonRpcProvider } from '@ethersproject/providers'

import ERC20_ABI from '../contracts/abis/ERC20.json'
import { ERC20 } from '../contracts/typechain/ERC20'
import { Contract } from '@ethersproject/contracts';
import { JsonRpcProvider } from '@ethersproject/providers';
// todo: should be able to just directly load in abi (instead of loading all global contracts)
// import ERC20_ARTIFACT = require('@lyrafinance/protocol/dist/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json')
import { getGlobalDeploys } from '@lyrafinance/protocol';
import { ERC20 } from '@lyrafinance/protocol/dist/typechain-types/';

export default function getERC20Contract(provider: JsonRpcProvider, address: string): ERC20 {
return new Contract(address, ERC20_ABI, provider) as ERC20
}
const abi = (getGlobalDeploys('kovan-ovm')).QuoteAsset.abi;
return new Contract(address, abi, provider) as ERC20
// return new Contract(address, ERC20_ARTIFACT.abi, provider) as ERC20
}
49 changes: 10 additions & 39 deletions src/utils/getLyraContractABI.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,15 @@
import { ContractInterface } from '@ethersproject/contracts'
import { ContractInterface } from '@ethersproject/contracts';
import { getGlobalDeploys,getMarketDeploys } from '@lyrafinance/protocol';

import { LyraContractId, LyraMarketContractId } from '../constants/contracts'
import LIQUIDITY_POOL_ABI from '../contracts/abis/LiquidityPool.json'
import LIQUIDITY_TOKENS_ABI from '../contracts/abis/LiquidityTokens.json'
import OPTION_GREEK_CACHE_ABI from '../contracts/abis/OptionGreekCache.json'
import OPTION_MARKET_ABI from '../contracts/abis/OptionMarket.json'
import OPTION_MARKET_PRICER_ABI from '../contracts/abis/OptionMarketPricer.json'
import OPTION_MARKET_VIEWER_ABI from '../contracts/abis/OptionMarketViewer.json'
import OPTION_MARKET_WRAPPER_ABI from '../contracts/abis/OptionMarketWrapper.json'
import OPTION_TOKEN_ABI from '../contracts/abis/OptionToken.json'
import POOL_HEDGER_ABI from '../contracts/abis/PoolHedger.json'
import SHORT_COLLATERAL_ABI from '../contracts/abis/ShortCollateral.json'
import SYNTHETIX_ADAPTER_ABI from '../contracts/abis/SynthetixAdapter.json'
import TEST_FAUCET_ABI from '../contracts/abis/TestFaucet.json'
import { LyraContractId, LyraMarketContractId } from '../constants/contracts';

export default function getLyraContractABI(contractId: LyraContractId | LyraMarketContractId): ContractInterface {
switch (contractId) {
case LyraContractId.OptionMarketViewer:
return OPTION_MARKET_VIEWER_ABI
case LyraContractId.OptionMarketWrapper:
return OPTION_MARKET_WRAPPER_ABI
case LyraContractId.TestFaucet:
return TEST_FAUCET_ABI
case LyraContractId.SynthetixAdapter:
return SYNTHETIX_ADAPTER_ABI
case LyraMarketContractId.LiquidityPool:
return LIQUIDITY_POOL_ABI
case LyraMarketContractId.LiquidityTokens:
return LIQUIDITY_TOKENS_ABI
case LyraMarketContractId.OptionGreekCache:
return OPTION_GREEK_CACHE_ABI
case LyraMarketContractId.OptionMarket:
return OPTION_MARKET_ABI
case LyraMarketContractId.OptionToken:
return OPTION_TOKEN_ABI
case LyraMarketContractId.ShortCollateral:
return SHORT_COLLATERAL_ABI
case LyraMarketContractId.OptionMarketPricer:
return OPTION_MARKET_PRICER_ABI
case LyraMarketContractId.PoolHedger:
return POOL_HEDGER_ABI
if (contractId == LyraContractId.OptionMarketViewer ||
contractId == LyraContractId.OptionMarketWrapper ||
contractId == LyraContractId.TestFaucet ||
contractId == LyraContractId.SynthetixAdapter) {
return (getGlobalDeploys('kovan-ovm'))[contractId].abi
} else {
return (getMarketDeploys('kovan-ovm', 'sETH'))[contractId].abi
}
}
12 changes: 5 additions & 7 deletions src/utils/getLyraContractAddress.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { getGlobalDeploys } from '@lyrafinance/protocol'

import { Deployment, LyraContractId } from '../constants/contracts'
import KOVAN_ADDRESS_MAP from '../contracts/addresses/kovan.addresses.json'
// TODO: @earthtojake Use @lyrafinance/protocol to get addresses
import LOCAL_ADDRESS_MAP from '../contracts/addresses/local.addresses.json'
import MAINNET_ADDRESS_MAP from '../contracts/addresses/mainnet.addresses.json'

export default function getLyraContractAddress(deployment: Deployment, contractId: LyraContractId): string {
switch (deployment) {
case Deployment.Kovan:
return (KOVAN_ADDRESS_MAP as Record<LyraContractId, string>)[contractId]
return getGlobalDeploys('kovan-ovm')[contractId].address;
case Deployment.Mainnet:
return (MAINNET_ADDRESS_MAP as Record<LyraContractId, string>)[contractId]
return getGlobalDeploys('mainnet-ovm')[contractId].address;
case Deployment.Local:
return (LOCAL_ADDRESS_MAP as Record<LyraContractId, string>)[contractId]
return getGlobalDeploys('local')[contractId].address;
}
}
Loading