The purpose of this repository/package is to make it easy to customize your LSP (Long-Short Pair) deployment. Feel free to use this repository in place or fork and customize it.
For more information on the LSP, read the docs.
This launch repo currently is only for Kovan and Mumbai testnet LSP deployments. This will soon be updated to include Ethereum mainnet and Polygon deployments.
You will need to install nodejs v14 and yarn. If you are testing on local fork with ganache, you will need to use node v12.
Note: these additional dependencies are required -- you may or may not have them on your system already:
libudev
libusb
These dependencies are installed on MacOSX by installing the XCode Developer Tools. For Linux, the example Ubuntu installation command for additional dependencies is:
sudo apt-get update && sudo apt-get install -y libudev-dev libusb-1.0-0-dev
yarn
Before running this command, you should customize the parameters to your needs. YOUR_NODE_URL
should be filled in with a url for the network that you wish to deploy to and the lspCreatorAddress
value should be substituted with the creator address on that same network. These creator addresses can be found in the Contract Addresses
section. It is prefilled with the Kovan LongShortPairCreator
address.
node index.js --gasprice 20 --url YOUR_NODE_URL --mnemonic "your mnemonic (12 word seed phrase)" --lspCreatorAddress 0x4C68829DBD07FEbB250B90f5624d4a5C30BBeC2c --expirationTimestamp 1643678287 --collateralPerPair 1000000000000000000 --priceIdentifier ETHUSD --collateralToken 0xd0a1e359811322d97991e03f863a0c30c2cf029c --syntheticName "ETH 9000 USD Call [December 2021]" --syntheticSymbol ETHc9000-1221 --financialProductLibrary 0x2CcA11DbbDC3E028D6c293eA5d386eE887071C59
You can customize all of the deployment parameters of the LSP simply by changing the parameters that you pass in the run command above. See the script or documentation for more details about these parameters.
Your financial product library address will defines the payout function for your LSP. We have several financial product libraries available for transforming the price, identifier, or collateral requirement of an LSP before or after expiry. For these addresses, see the Contract Addresses
section. In some cases, you may find yourself in need of a custom financial product library for your use case. If so, please see the Deploying new financial product libraries
.
Note that the LongShortPairCreator
contract will differentiate between long and short tokens by appending " Long Token" or " Short Token" to syntheticName
and prepending "l" or "s" to the syntheticSymbol
.
See the files linked below for the LongShortPairCreator
and financial product library contract addresses on various networks. You can pass these as parameters when deploying.
If you wish to deploy your own financial product library, fork the protocol repo and add your CustomFinancialProductLibrary
Solidity file to /packages/core/contracts/financial-templates/common/financial-product-libraries/long-short-pair-libraries. You will probably want a different name for your library, but this is an example!
Then take the following steps to deploy and verify the contract. Sorry that it's a bit complicated! We're working on a simpler workflow, probably using Hardhat deployment.
- In the protocol repo, run
yarn
andyarn build
. - Add your MetaMask mnemonic to your environment with
export MNEMONIC=your mnemonic string
or through an environment file. - From
core
, runyarn truffle console --network mainnet_mnemonic
. - In the Truffle console, run
const fpl = await CustomFinancialProductLibrary.new({gasPrice: currentGasPriceInWei})
, filling in the current gas price. You can find prices in Gwei at ETH Gas Station, and need to add nine zeroes to convert the Gwei price to wei. For example, if the current gas price in Gwei is85
, you should enter85000000000
in the place ofcurrentGasPriceInWei
. Make sure you have enough ETH in your wallet! - After deployment, still in the Truffle console, run
fpl.address
. This will output the deployed address ofCustomFinancialProductLibrary
. - Make a note of the deployed address and exit Truffle console.
- Open
packages/core/artifacts/contracts/financial-templates/common/financial-product-libraries/long-short-pair-libraries/CustomFinancialProductLibrary/CustomFinancialProductLibrary.dbg.json
. It should show some metadata about your Hardhat build, including thebuildInfo
file, which should look like"../../../../../../build-info/example.json"
. Open theexample.json
file in thebuild-info
directory. - In
build-info
, also create a new file calledsolc-input.json
. - From
example.json
, copy the solc input data, which is everything in the curly brackets after"input":
. Your text editor may have a way to collapse everything between the brackets so that you only have to copy{...}
. Also note that you need to copy the curly brackets themselves, not just the stuff in between. - Paste the solc input data into
solc-input.json
. - Go to the contract verification page on Etherscan, enter the deployed address of your library contract, select
Solidity (Standard-Json-Input)
as the compiler type, your compiler version, and your open source license type. Then click continue. - Click
Choose File
and choose yoursolc-input.json
file inbuild-info
. Then click the button that saysClick to Upload selected file
, - Complete the captcha and click
Verify and Publish
. - After some processing, Etherscan should verify your contract! This will allow you to read and write to the contract directly in Etherscan, in addition to seeing the source code.