Request form
Lyra Finance
  • DEX
  • Options
  • AMM
  • Options
  • Protocol
  • Audited
Docs
Source
ChefGPT

The first complete decentralized options protocol built on Ethereum

GMXCompileImports.sol
Governable.sol
IAdmin.sol
IPancakeFactory.sol
IPancakePair.sol
BasePositionManager.sol
IBasePositionManager.sol
IGlpManager.sol
IOrderBook.sol
IPositionRouter.sol
IPositionRouterCallbackReceiver.sol
IRouter.sol
IShortsTracker.sol
IVault.sol
IVaultPriceFeed.sol
IVaultUtils.sol
PositionRouter.sol
Router.sol
ShortsTracker.sol
Vault.sol
VaultErrorController.sol
VaultPriceFeed.sol
SafeMath.sol
IERC20.sol
SafeERC20.sol
Address.sol
ReentrancyGuard.sol
FastPriceEvents.sol
FastPriceFeed.sol
IChainlinkFlags.sol
IFastPriceEvents.sol
IFastPriceFeed.sol
IPriceFeed.sol
ISecondaryPriceFeed.sol
PriceFeed.sol
IHandlerTarget.sol
ITimelock.sol
ITimelockTarget.sol
Reader.sol
Timelock.sol
IReferralStorage.sol
ReferralStorage.sol
IVester.sol
IBaseToken.sol
IDistributor.sol
IMintable.sol
IUSDG.sol
IWETH.sol
IYieldToken.sol
IYieldTracker.sol
TimeDistributor.sol
Token.sol
USDG.sol
YieldToken.sol
YieldTracker.sol
IUniswapV3SwapCallback.sol
IUniswapV3Pool.sol
IUniswapV3PoolActions.sol
IUniswapV3PoolDerivedState.sol
IUniswapV3PoolEvents.sol
IUniswapV3PoolImmutables.sol
IUniswapV3PoolOwnerActions.sol
IUniswapV3PoolState.sol
ISwapRouter.sol
BaseExchangeAdapter.sol
GMXAdapter.sol
GMXFuturesPoolHedger.sol
BaseGovernanceWrapper.sol
GovernanceWrapperViewerGMX.sol
GMXAdapterGovernanceWrapper.sol
GMXHedgerGovernanceWrapper.sol
LiquidityPoolGovernanceWrapper.sol
OptionGreekCacheGovernanceWrapper.sol
OptionMarketGovernanceWrapper.sol
OptionMarketPricerGovernanceWrapper.sol
OptionTokenGovernanceWrapper.sol
SNXAdapterGovernanceWrapper.sol
SNXHedgerGovernanceWrapper.sol
IPositionRouter.sol
IPositionRouterCallbackReceiver.sol
IRouter.sol
IVault.sol
IVaultPriceFeed.sol
IVaultUtils.sol
IAddressResolver.sol
IAggregatorV3.sol
ICollateralShort.sol
ICurve.sol
IDecimals.sol
IDelegateApprovals.sol
IERC20Decimals.sol
IExchanger.sol
IExchangeRates.sol
IFeeCounter.sol
IGWAVOracle.sol
ILiquidityPool.sol
ILiquidityTracker.sol
ILyraRegistry.sol
IOptionGreekCache.sol
IOptionMarket.sol
IOptionMarketPricer.sol
IOptionToken.sol
IShortCollateral.sol
ISwapRouter.sol
ISynthetix.sol
ISynthetixAdapter.sol
IUniswapV3Oracle.sol
IWETH.sol
IFuturesMarketManager.sol
IFuturesMarketSettings.sol
IPerpsV2MarketBaseTypes.sol
IPerpsV2MarketConsolidated.sol
IPerpsV2MarketSettings.sol
ISystemStatus.sol
BlackScholes.sol
ConvertDecimals.sol
FixedPointMathLib.sol
GWAV.sol
Math.sol
PoolHedger.sol
SimpleInitializable.sol
LiquidityPool.sol
LiquidityToken.sol
OptionGreekCache.sol
OptionMarket.sol
OptionMarketPricer.sol
OptionToken.sol
BasicFeeCounter.sol
BasicLiquidityCounter.sol
GWAVOracle.sol
KeeperHelper.sol
LyraAdapter.sol
LyraRegistry.sol
MultistepSwapper.sol
OptionMarketViewer.sol
BasicOptionMarketWrapper.sol
OptionMarketWrapper.sol
OptionMarketWrapperWithSwaps.sol
ShortCollateral.sol
SNXPerpsV2PoolHedger.sol
SNXPerpV2Adapter.sol
AbstractOwned.sol
DecimalMath.sol
Owned.sol
OwnedUpgradeable.sol
SignedDecimalMath.sol
BytesLib.sol
TestGMXPositionRouter.sol
TestGMXRouter.sol
TestGMXVaultChainlinkPrice.sol
ITestERC20.sol
MathTest.sol
MockAggregatorV2V3.sol
OldBlackScholesMath.sol
Path.sol
ShortPoolHedger.sol
MockPerpsV2MarketConsolidated.sol
MockPyth.sol
MockSystemStatus.sol
TestAddressResolver.sol
TestCollateralShort.sol
TestDelegateApprovals.sol
TestExchanger.sol
TestExchangeRates.sol
TestFuturesMarketManager.sol
TestFuturesMarketSettings.sol
TestPerpsMarket.sol
TestSynthetix.sol
TestSynthetixReturnZero.sol
SynthetixAdapter.sol
TestBaseExchangeAdapter.sol
TestBlackScholes.sol
TestCurve.sol
TestERC20.sol
TestERC20Fail.sol
TestERC20SetDecimals.sol
TestERC20SetDecimalsFail.sol
TestFaucet.sol
TestGMXPoolHedger.sol
TestGWAV.sol
TestInaccurateSynthetixAdapter.sol
TestLyraAdapter.sol
TestShortPoolHedger.sol
TestSynthetixAdapterV2.sol
TestWETH.sol
console.sol
Ownable.sol
ReentrancyGuard.sol
ERC20.sol
IERC20Metadata.sol
IERC20.sol
ERC721.sol
ERC721Enumerable.sol
IERC721Enumerable.sol
IERC721Metadata.sol
IERC721.sol
IERC721Receiver.sol
Address.sol
Context.sol
ERC165.sol
IERC165.sol
SafeCast.sol
Strings.sol
Initializable.sol
AddressUpgradeable.sol
IAddressResolver.sol
IDirectIntegrationManager.sol
IERC20.sol
IExchanger.sol
IExchangeRates.sol
IFeePool.sol
IFlexibleStorage.sol
IIssuer.sol
ISynth.sol
ISystemStatus.sol
IVirtualSynth.sol
SNXCompileImport.sol
SafeMath.sol
ReentrancyGuard.sol
AddressResolver.sol
AddressSetLib.sol
FuturesMarketManager.sol
FuturesMarketSettings.sol
IFuturesMarket.sol
IFuturesMarketBaseTypes.sol
IFuturesMarketManager.sol
IFuturesMarketSettings.sol
IPerpsV2ExchangeRate.sol
IPerpsV2Market.sol
IPerpsV2MarketBaseTypes.sol
IPerpsV2MarketDelayedOrders.sol
IPerpsV2MarketOffchainOrders.sol
IPerpsV2MarketSettings.sol
IPerpsV2MarketState.sol
IPerpsV2MarketViews.sol
IPyth.sol
PythStructs.sol
MixinFuturesMarketSettings.sol
MixinPerpsV2MarketSettings.sol
MixinResolver.sol
MixinSystemSettings.sol
Owned.sol
PerpsV2ExchangeRate.sol
PerpsV2Market.sol
PerpsV2MarketBase.sol
PerpsV2MarketData.sol
PerpsV2MarketDelayedOrders.sol
PerpsV2MarketDelayedOrdersBase.sol
PerpsV2MarketDelayedOrdersOffchain.sol
PerpsV2MarketProxyable.sol
PerpsV2MarketSettings.sol
PerpsV2MarketState.sol
PerpsV2MarketViews.sol
Proxy.sol
Proxyable.sol
ProxyPerpsV2.sol
SafeDecimalMath.sol
SignedSafeDecimalMath.sol
SignedSafeMath.sol
StateShared.sol
FullMath.sol
TickMath.sol
OracleLibrary.sol
CompileUniImports.sol

TVL

$29.09M

178 downloads

Chains

Authors

Lyra Finance
  • DEX
  • Options
  • AMM
  • Options
  • Protocol
  • Audited
Info
Source
ChefGPT
Expand
Share

Get Cookin'

178 downloads

Chains

Authors

Lyra - Smart Contracts

CI codecov

:warning: This SDK is in open alpha and is constantly under development. :warning: GWAVOracle.sol and LyraAdapter.sol not yet audited.

  1. Avalon documentation
  2. Installation
  3. Importing Lyra into your contract
  4. Lyra integration testing
  5. Call Lyra on kovan/mainnet
  6. Deploy Lyra to localhost
  7. Advanced
  8. Useful calls/common errors

Documentation

Avalon docs under development: Avalon Docs

Installation

$ yarn add @lyrafinance/protocol
$ yarn add hardhat-dependency-compiler

Include the dependency compiler plug-in in your hardhat.config.ts:

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

export default {
  // other hardhat config params...
  dependencyCompiler: {
    paths: lyraContractPaths,
  }
}

Importing Lyra into your contract

import {LyraAdapter} from '@lyrafinance/protocol/contracts/periphery/LyraAdapter.sol';

contract DeltaStrategy is LyraAdapter {
  // your structured product contract
}

Refer to the lyra-vaults on using the LyraAdapter to connect your contract to Lyra.

Lyra integration testing

Deploy a full Lyra market in hardhat without need for custom mock contracts.

import { TestSystem } from '@lyrafinance/protocol'

describe('Integration Test', () => {
  before(async () => {
    let testSystem = await TestSystem.deploy(signer);
    await TestSystem.seed(signer, testSystem);
  });

  it('your integration test', async () => {
    ...
  });
});

Open position and confirm correct payout example test:

it('will pay out long calls', async () => {
  boardIds = await testSystem.optionMarket.getLiveBoards();
  strikeIds = await testSystem.optionMarket.getBoardStrikes(boardIds[0]);

  // Buy long call
  await testSystem.optionMarket.openPosition( {
    strikeId: strikeIds[0],
    positionId: 0,
    amount: toBN('1'),
    setCollateralTo: 0,
    iterations: 1,
    minTotalCost: 0,
    maxTotalCost: MAX_UINT,
    optionType: TestSystem.OptionType.LONG_CALL
  });

  // Wait till board expires
  await fastForward(MONTH_SEC);

  // Mock sETH price
  await TestSystem.mockPrice(testSystem, toBN("1500"), 'sETH');

  // Settle option and confirm payout
  await testSystem.optionMarket.settleExpiredBoard(boardIds[0]);
  const preBalance = await testSystem.snx.quoteAsset.balanceOf(signer.address);
  await testSystem.shortCollateral.settleOptions([strikeIds[0]]);
  const postBalance = await testSystem.snx.quoteAsset.balanceOf(signer.address);
  expect(postBalance.sub(preBalance)).to.eq(toBN('500'));
});

Refer to the integration testing example on hardhat testing against a mock Lyra market.

Call Lyra on kovan-ovm/mainnet-ovm

import { getMarketDeploys, getGlobalDeploys } from '@lyrafinance/protocol';

// get lyra address/abi/bytecode/more
let lyraMarket = await getMarketDeploys('kovan-ovm', 'sETH');
let lyraGlobal = await getGlobalDeploys('kovan-ovm');

const testFaucet = new Contract(lyraGlobal.TestFaucet.address, lyraGlobal.TestFaucet.abi, deployer);
const sUSD = new Contract(lyraGlobal.QuoteAsset.address, lyraGlobal.QuoteAsset.abi, deployer);
const optionMarket = new Contract(lyraMarket.OptionMarket.address, lyraMarket.OptionMarket.abi, deployer);

// call lyra (`execute` is any implementation of a contract call)
await execute(testFaucet, 'drip', [] as any, provider);
await execute(sUSD, 'approve', [optionMarket.address, MAX_UINT], provider);
await execute(optionMarket, 'openPosition', [tradeParams], provider);

Refer to the lyra-vaults kovan/mainnet scripts for calling kovan/main-net Lyra markets.

Deploy Lyra to localhost

// deployLyraExample.ts
import { TestSystem } from '@lyrafinance/protocol';

async function main() {
  // 1. create local deployer and network
  const provider = new ethers.providers.JsonRpcProvider('http://localhost:8545');
  const privateKey = 'local eth address with ETH';

  // 2. optional settings to prevent errors
  provider.getGasPrice = async () => { return ethers.BigNumber.from('0'); };
  provider.estimateGas = async () => { return ethers.BigNumber.from(15000000); }
  const deployer = new ethers.Wallet(privateKey, provider);

  // 3. deploy and seed Lyra market
  let linkTracer = false;
  let exportAddresses = true;
  let localTestSystem = await TestSystem.deploy(deployer, linkTracer, exportAddresses);
  await TestSystem.seed(deployer, localTestSystem, overrides={});

  // 4. call local contracts
  await localTestSystem.optionMarket.openPosition({
    strikeId: 1;
    positionId: 0;
    optionType: TestSystem.OptionType.LONG_CALL;
    amount: toBN("1");
    setCollateralTo: toBN("0");
    iterations: 3;
    minTotalCost: toBN("0");
    maxTotalCost?: toBN("250");
  };)
$ yarn hardhat node 
$ yarn hardhat run deployLyraExample.ts // in a separate window

Can also use getGlobal/MarketDeploys on local network by setting exportAddresses=true

Refer to the lyra-vaults localhost deploy scripts for creating a local Lyra market.

Advanced

For overriding specific parameters when using TestSystem.deploy() or TestSystem.seed()

const overrides: DeployOverrides = { 
  optionMarketParams: {
    ...lyraCore.defaultParams.optionMarketPerams, feePortionReserved: toBN('0.05')
  }
}

For easy debugging, set linkTracer = true to use hardhat-tracer to display all emitted events for every hardhat contract call (does not work in local/kovan/main-net yet)

let linkTracer=true;
let localTestSystem = await deployTestSystem(deployer, linkTracer);

Run your test scripts with the yarn test --logs to enable the plug-in. As hardhat-tracer does not log on reverted calls, rely on CustomErrors thrown by the core Lyra contracts.

Useful calls / common errors [WIP]

For local/hardhat:

  • testSystem.optionGreekCache.updateBoardCachedGreeks(boardId) to prevent deposit/withdraw early returns when boards stale
  • testSystem.optionMarket.settleBoard(boardId) before settling individual positions
  • testSystem.mockPrice() to set mock prices
  • lyraEvm.fastForward(jumpTime)to jump to expiry/fast-forward
  • use DeployOverride and SeedOverride during testSystem.deploy/seed for setting custom market params such as standardSize, minDelta and etc.

Refer to the lyra-vaults example project for example usage of above functions.

Slither (dev)

To run slither, install it via instructions found in the slither repo, and then run the following command: slither --exclude-informational --exclude-optimization .

To prevent false-positives in runs of slither, slither.db.json has been added to the repo -- this is a file generated by slither in triage mode to mark what shouldn't be tested. This will periodically need to be reset, depending on how much the code has changed between the last run and may error on a future run of the contracts. [Note that it is only present to reduce duplicate work in slither results, and does not strictly need to be present in the result]

The first complete decentralized options protocol built on Ethereum
GMXCompileImports.sol
Governable.sol
IAdmin.sol
IPancakeFactory.sol
IPancakePair.sol
BasePositionManager.sol
IBasePositionManager.sol
IGlpManager.sol
IOrderBook.sol
IPositionRouter.sol
IPositionRouterCallbackReceiver.sol
IRouter.sol
IShortsTracker.sol
IVault.sol
IVaultPriceFeed.sol
IVaultUtils.sol
PositionRouter.sol
Router.sol
ShortsTracker.sol
Vault.sol
VaultErrorController.sol
VaultPriceFeed.sol
SafeMath.sol
IERC20.sol
SafeERC20.sol
Address.sol
ReentrancyGuard.sol
FastPriceEvents.sol
FastPriceFeed.sol
IChainlinkFlags.sol
IFastPriceEvents.sol
IFastPriceFeed.sol
IPriceFeed.sol
ISecondaryPriceFeed.sol
PriceFeed.sol
IHandlerTarget.sol
ITimelock.sol
ITimelockTarget.sol
Reader.sol
Timelock.sol
IReferralStorage.sol
ReferralStorage.sol
IVester.sol
IBaseToken.sol
IDistributor.sol
IMintable.sol
IUSDG.sol
IWETH.sol
IYieldToken.sol
IYieldTracker.sol
TimeDistributor.sol
Token.sol
USDG.sol
YieldToken.sol
YieldTracker.sol
IUniswapV3SwapCallback.sol
IUniswapV3Pool.sol
IUniswapV3PoolActions.sol
IUniswapV3PoolDerivedState.sol
IUniswapV3PoolEvents.sol
IUniswapV3PoolImmutables.sol
IUniswapV3PoolOwnerActions.sol
IUniswapV3PoolState.sol
ISwapRouter.sol
BaseExchangeAdapter.sol
GMXAdapter.sol
GMXFuturesPoolHedger.sol
BaseGovernanceWrapper.sol
GovernanceWrapperViewerGMX.sol
GMXAdapterGovernanceWrapper.sol
GMXHedgerGovernanceWrapper.sol
LiquidityPoolGovernanceWrapper.sol
OptionGreekCacheGovernanceWrapper.sol
OptionMarketGovernanceWrapper.sol
OptionMarketPricerGovernanceWrapper.sol
OptionTokenGovernanceWrapper.sol
SNXAdapterGovernanceWrapper.sol
SNXHedgerGovernanceWrapper.sol
IPositionRouter.sol
IPositionRouterCallbackReceiver.sol
IRouter.sol
IVault.sol
IVaultPriceFeed.sol
IVaultUtils.sol
IAddressResolver.sol
IAggregatorV3.sol
ICollateralShort.sol
ICurve.sol
IDecimals.sol
IDelegateApprovals.sol
IERC20Decimals.sol
IExchanger.sol
IExchangeRates.sol
IFeeCounter.sol
IGWAVOracle.sol
ILiquidityPool.sol
ILiquidityTracker.sol
ILyraRegistry.sol
IOptionGreekCache.sol
IOptionMarket.sol
IOptionMarketPricer.sol
IOptionToken.sol
IShortCollateral.sol
ISwapRouter.sol
ISynthetix.sol
ISynthetixAdapter.sol
IUniswapV3Oracle.sol
IWETH.sol
IFuturesMarketManager.sol
IFuturesMarketSettings.sol
IPerpsV2MarketBaseTypes.sol
IPerpsV2MarketConsolidated.sol
IPerpsV2MarketSettings.sol
ISystemStatus.sol
BlackScholes.sol
ConvertDecimals.sol
FixedPointMathLib.sol
GWAV.sol
Math.sol
PoolHedger.sol
SimpleInitializable.sol
LiquidityPool.sol
LiquidityToken.sol
OptionGreekCache.sol
OptionMarket.sol
OptionMarketPricer.sol
OptionToken.sol
BasicFeeCounter.sol
BasicLiquidityCounter.sol
GWAVOracle.sol
KeeperHelper.sol
LyraAdapter.sol
LyraRegistry.sol
MultistepSwapper.sol
OptionMarketViewer.sol
BasicOptionMarketWrapper.sol
OptionMarketWrapper.sol
OptionMarketWrapperWithSwaps.sol
ShortCollateral.sol
SNXPerpsV2PoolHedger.sol
SNXPerpV2Adapter.sol
AbstractOwned.sol
DecimalMath.sol
Owned.sol
OwnedUpgradeable.sol
SignedDecimalMath.sol
BytesLib.sol
TestGMXPositionRouter.sol
TestGMXRouter.sol
TestGMXVaultChainlinkPrice.sol
ITestERC20.sol
MathTest.sol
MockAggregatorV2V3.sol
OldBlackScholesMath.sol
Path.sol
ShortPoolHedger.sol
MockPerpsV2MarketConsolidated.sol
MockPyth.sol
MockSystemStatus.sol
TestAddressResolver.sol
TestCollateralShort.sol
TestDelegateApprovals.sol
TestExchanger.sol
TestExchangeRates.sol
TestFuturesMarketManager.sol
TestFuturesMarketSettings.sol
TestPerpsMarket.sol
TestSynthetix.sol
TestSynthetixReturnZero.sol
SynthetixAdapter.sol
TestBaseExchangeAdapter.sol
TestBlackScholes.sol
TestCurve.sol
TestERC20.sol
TestERC20Fail.sol
TestERC20SetDecimals.sol
TestERC20SetDecimalsFail.sol
TestFaucet.sol
TestGMXPoolHedger.sol
TestGWAV.sol
TestInaccurateSynthetixAdapter.sol
TestLyraAdapter.sol
TestShortPoolHedger.sol
TestSynthetixAdapterV2.sol
TestWETH.sol
console.sol
Ownable.sol
ReentrancyGuard.sol
ERC20.sol
IERC20Metadata.sol
IERC20.sol
ERC721.sol
ERC721Enumerable.sol
IERC721Enumerable.sol
IERC721Metadata.sol
IERC721.sol
IERC721Receiver.sol
Address.sol
Context.sol
ERC165.sol
IERC165.sol
SafeCast.sol
Strings.sol
Initializable.sol
AddressUpgradeable.sol
IAddressResolver.sol
IDirectIntegrationManager.sol
IERC20.sol
IExchanger.sol
IExchangeRates.sol
IFeePool.sol
IFlexibleStorage.sol
IIssuer.sol
ISynth.sol
ISystemStatus.sol
IVirtualSynth.sol
SNXCompileImport.sol
SafeMath.sol
ReentrancyGuard.sol
AddressResolver.sol
AddressSetLib.sol
FuturesMarketManager.sol
FuturesMarketSettings.sol
IFuturesMarket.sol
IFuturesMarketBaseTypes.sol
IFuturesMarketManager.sol
IFuturesMarketSettings.sol
IPerpsV2ExchangeRate.sol
IPerpsV2Market.sol
IPerpsV2MarketBaseTypes.sol
IPerpsV2MarketDelayedOrders.sol
IPerpsV2MarketOffchainOrders.sol
IPerpsV2MarketSettings.sol
IPerpsV2MarketState.sol
IPerpsV2MarketViews.sol
IPyth.sol
PythStructs.sol
MixinFuturesMarketSettings.sol
MixinPerpsV2MarketSettings.sol
MixinResolver.sol
MixinSystemSettings.sol
Owned.sol
PerpsV2ExchangeRate.sol
PerpsV2Market.sol
PerpsV2MarketBase.sol
PerpsV2MarketData.sol
PerpsV2MarketDelayedOrders.sol
PerpsV2MarketDelayedOrdersBase.sol
PerpsV2MarketDelayedOrdersOffchain.sol
PerpsV2MarketProxyable.sol
PerpsV2MarketSettings.sol
PerpsV2MarketState.sol
PerpsV2MarketViews.sol
Proxy.sol
Proxyable.sol
ProxyPerpsV2.sol
SafeDecimalMath.sol
SignedSafeDecimalMath.sol
SignedSafeMath.sol
StateShared.sol
FullMath.sol
TickMath.sol
OracleLibrary.sol
CompileUniImports.sol