Gnosis Protocol – Smart Contracts – Gnosis协议-智能合约区块链源码资料下载
本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Gnosis Protocol – Smart Contracts – Gnosis协议-智能合约区块链源码资料下载 是一篇很好的国外资料
Gnosis Protocol – Smart Contracts
The Gnosis Protocol Exchange is a fully decentralized trading protocol which facilitates ring trades via discrete auction between several ERC20 token pairs.
It uses a batch auction for arbitrage-free exchanges while maximizing trader surplus to facilitate the development of a fairer Web3 ecosystem for everyone.
Documentation
Checkout the Smart Contract Documentation.
Audit report
The audit report can be found here.
CLI Examples
Checkout wiki
Deployment Process
For the deployment of the contracts into an official network, follow this steps:
-
Make sure that all depended contracts and libraries – e.g. BytesLib – has been deployed to the intended network and that their network information is available in the npm modules
-
Run the following commands
yarn install # This installs all dependencies npx truffle build # This builds the contracts npx truffle migrate --network $NETWORKNAME --reset yarn run networks-extract # extracts deployed addresses to networks.json
If you are building for a local development network, ganache has to be running locally. For this you can e.g. in a separate shell run
yarn run ganache # start a development network (blocking)
- Verify the contracts for some cool Etherscan.io goodies (see below for more help)
npx truffle run verify BatchExchange --network $NETWORKNAME
- List some default tokens on the StableX exchange
npx truffle exec scripts/add_token_list.js --network $NETWORKNAME
Verifying Contracts
In order to verify a contract on Etherscan.io, you need to first create an account and an API key
- Navigate to https://etherscan.io/myapikey
- Login or create an account
- Generate a new API key
- Add
export MY_ETHERSCAN_API_KEY="..."
to your~/.zshrc
,~/.bash_profile
, or similar
Note, if you have a specific contract address in mind (i.e. one which is not specified in networks.json
) it may be referred to by address as
npx truffle run verify $CONTRACT_NAME@$CONTRACT_ADDRESS --network $NETWORKNAME
Retrieving previous deployments
In order to use the previously deployed contracts, which are documented in the network.json file, the following steps are necessary:
- Build the contracts:
npx truffle compile
- Inject address from network.json into the builds:
yarn run networks-inject
Deploying a simple market maker scenario to Rinkeby:
The following script deploys a simple market maker order and a necessary owl order, to enable trading:
# Get token ID of DAI npx truffle exec scripts/invokeViewFunction.js 'tokenAddressToIdMap' '0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa' --network rinkeby # Export the resulting token ID export TOKEN_ID_DAI=[Result from last call] # Get token ID of TrueUSD npx truffle exec scripts/invokeViewFunction.js 'tokenAddressToIdMap' '0x0000000000085d4780B73119b644AE5ecd22b376' --network rinkeby # Export the resulting token ID export TOKEN_ID_TUSD=[Result from last call] # Make sure that the users have deposited sufficient funds into the exchange # Please be aware that the specified amounts are multiples of 10**18 npx truffle exec scripts/deposit.js --accountId=0 --tokenId=0 --amount=30 --network rinkeby&& npx truffle exec scripts/deposit.js --accountId=0 --tokenId=$TOKEN_ID_TUSD --amount=100 --network rinkeby # Place market-maker order in current auction # This simulates a strategy expected from market makers: trading stable coins against each other # with a spread of 0.02 percent npx truffle exec scripts/place_order.js --accountId=0 --buyToken=$TOKEN_ID_DAI --sellToken=$TOKEN_ID_TUSD --minBuy=1000 --maxSell=998 --validFor=20 --network rinkeby # Place owl token order for the fee mechanism npx truffle exec scripts/place_order.js --accountId=0 --buyToken=$TOKEN_ID_DAI --sellToken=0 --minBuy=1000 --maxSell=1000 --validFor=20 --network rinkeby
Then, the market order can be place, after switching to another account. Usually, this is expected to happen via the UI. If it will be done via the console, following commands can be used:
# Deposit funds into exchange: npx truffle exec scripts/deposit.js --accountId=0 --tokenId=$TOKEN_ID_DAI --amount=100 --network rinkeby # Place market order with 1/2 limit-price npx truffle exec scripts/place_order.js --accountId=1 --buyToken=$TOKEN_ID_TUSD --sellToken=$TOKEN_ID_DAI --minBuy=500 --maxSell=1000 --validFor=5 --network rinkeby
Now, the market can be inspected by:
# view the market status: npx truffle exec scripts/get_auction_elements.js --network rinkeby
And the output should look like this:
[ { user: '0x740a98f8f4fae0986fb3264fe4aacf94ac1ee96f', sellTokenBalance: 100000000000000000000, buyToken: 7, sellToken: 3, validFrom: 5247563, validUntil: 5247583, priceNumerator: 1e+21, priceDenominator: 998000000000000000000, remainingAmount: 998000000000000000000 }, { user: '0x740a98f8f4fae0986fb3264fe4aacf94ac1ee96f', sellTokenBalance: 30000000000000000000, buyToken: 7, sellToken: 0, validFrom: 5247563, validUntil: 5247583, priceNumerator: 1e+21, priceDenominator: 1e+21, remainingAmount: 1e+21 }, { user: 'account', sellTokenBalance: 100000000000000000000, buyToken: 3, sellToken: 7, validFrom: 5247750, validUntil: 5247755, priceNumerator: 500000000000000000000, priceDenominator: 1e+21, remainingAmount: 1e+21 } ]
Building on top of BatchExchange
The integration of the Gnosis Protocol contracts into your own truffle project are demonstrated here: https://github.com/gnosis/dex-contracts-integration-example. This repository contains a minimal truffle project allowing to build on top of contracts. Please consult its readme for further information.
Contributions
The continuous integration is running several linters which must pass in order to make a contribution to this repo. For your convenience there is a pre-commit
hook file contained in the project’s root directory. You can make your life easier by executing the following command after cloning this project (it will ensure your changes pass linting before allowing commits).
cp pre-commit .git/hooks/ chmod +x .git/hooks/pre-commit
For any other questions, comments or concerns please feel free to contact any of the project admins:
- Alex (josojo)
- Ben (bh2smith)
- Felix (fleupold)
decentralized-exchange
Gnosis协议-智能合约
Gnosis协议交换是一个完全分散的交易协议,它通过在多个ERC20令牌对之间的离散拍卖促进环形交易。
它使用批量拍卖进行无套利交易,同时最大化交易员盈余,以促进为每个人开发更公平的Web3生态系统。
文档
查看智能合约文档。
审核报告
审计报告可在此处找到。
CLI示例
签出wiki
部署过程
以便将合同部署到正式网络中,遵循以下步骤:
- 确保所有依赖的契约和库(例如BytesLib)都已部署到预期的网络,并且它们的网络信息在npm模块中可用
- 运行以下命令
yarn install # This installs all dependencies npx truffle build # This builds the contracts npx truffle migrate --network $NETWORKNAME --reset yarn run networks-extract # extracts deployed addresses to networks.json
如果您正在为本地开发网络构建,则ganache必须在本地运行。为此,您可以在单独的shell运行中验证以太网扫描.io,您需要首先创建一个帐户和一个API密钥
yarn run ganache # start a development network (blocking)
- 验证一些很酷的合同以太网扫描.iogoodies(有关更多帮助,请参见下面的内容)
npx truffle run verify BatchExchange --network $NETWORKNAME
- 在StableX exchange上列出一些默认令牌
npx truffle exec scripts/add_token_list.js --network $NETWORKNAME
验证合约
注意,如果您有特定的合同地址(即网络.json)它可以通过地址称为
- 导航到https://etherscan.io/myapikey网站
- 登录或创建帐户
- 生成新的API密钥
- 将导出我的以太网扫描API密钥“…”添加到您的~/.zshrc,~/.bash配置文件中,或类似的
,以便使用先前部署的合同,这些合同记录在网络.json文件中,需要执行以下步骤:
npx truffle run verify $CONTRACT_NAME@$CONTRACT_ADDRESS --network $NETWORKNAME
检索以前的部署
以下脚本部署一个简单的做市商订单一个必要的猫头鹰订单,启用交易:
- 生成合同:
npx truffle compile
- 注入地址网络.json在构建中:
yarn run networks-inject
部署简单的做市商要Rinkeby的场景:
然后,在切换到另一个帐户后,可以下市场订单。通常,这是通过UI实现的。如果要通过控制台完成,可以使用以下命令:
# Get token ID of DAI npx truffle exec scripts/invokeViewFunction.js 'tokenAddressToIdMap' '0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa' --network rinkeby # Export the resulting token ID export TOKEN_ID_DAI=[Result from last call] # Get token ID of TrueUSD npx truffle exec scripts/invokeViewFunction.js 'tokenAddressToIdMap' '0x0000000000085d4780B73119b644AE5ecd22b376' --network rinkeby # Export the resulting token ID export TOKEN_ID_TUSD=[Result from last call] # Make sure that the users have deposited sufficient funds into the exchange # Please be aware that the specified amounts are multiples of 10**18 npx truffle exec scripts/deposit.js --accountId=0 --tokenId=0 --amount=30 --network rinkeby&& npx truffle exec scripts/deposit.js --accountId=0 --tokenId=$TOKEN_ID_TUSD --amount=100 --network rinkeby # Place market-maker order in current auction # This simulates a strategy expected from market makers: trading stable coins against each other # with a spread of 0.02 percent npx truffle exec scripts/place_order.js --accountId=0 --buyToken=$TOKEN_ID_DAI --sellToken=$TOKEN_ID_TUSD --minBuy=1000 --maxSell=998 --validFor=20 --network rinkeby # Place owl token order for the fee mechanism npx truffle exec scripts/place_order.js --accountId=0 --buyToken=$TOKEN_ID_DAI --sellToken=0 --minBuy=1000 --maxSell=1000 --validFor=20 --network rinkeby
现在,可以通过:
# Deposit funds into exchange: npx truffle exec scripts/deposit.js --accountId=0 --tokenId=$TOKEN_ID_DAI --amount=100 --network rinkeby # Place market order with 1/2 limit-price npx truffle exec scripts/place_order.js --accountId=1 --buyToken=$TOKEN_ID_TUSD --sellToken=$TOKEN_ID_DAI --minBuy=500 --maxSell=1000 --validFor=5 --network rinkeby
检查市场,输出应该如下:
# view the market status: npx truffle exec scripts/get_auction_elements.js --network rinkeby
这里演示将Gnosis协议合同集成到您自己的松露项目中:https://github.com/gnosis/dex-contracts-integration-example。这个存储库包含一个最小的truffle项目,允许在合同之上构建。请查阅自述文件以获取更多信息。
[ { user: '0x740a98f8f4fae0986fb3264fe4aacf94ac1ee96f', sellTokenBalance: 100000000000000000000, buyToken: 7, sellToken: 3, validFrom: 5247563, validUntil: 5247583, priceNumerator: 1e+21, priceDenominator: 998000000000000000000, remainingAmount: 998000000000000000000 }, { user: '0x740a98f8f4fae0986fb3264fe4aacf94ac1ee96f', sellTokenBalance: 30000000000000000000, buyToken: 7, sellToken: 0, validFrom: 5247563, validUntil: 5247583, priceNumerator: 1e+21, priceDenominator: 1e+21, remainingAmount: 1e+21 }, { user: 'account', sellTokenBalance: 100000000000000000000, buyToken: 3, sellToken: 7, validFrom: 5247750, validUntil: 5247755, priceNumerator: 500000000000000000000, priceDenominator: 1e+21, remainingAmount: 1e+21 } ]
在BatchExchange之上构建
持续集成正在运行多个linter,这些linter必须通过才能对该repo作出贡献。为了方便起见,项目的根目录中包含一个预提交钩子文件。克隆此项目后执行以下命令可以使您的生活更轻松(它将确保您的更改在允许提交之前通过linting)。
贡献
对于任何其他问题,请随时与任何项目管理员联系:
cp pre-commit .git/hooks/ chmod +x .git/hooks/pre-commit
For any other questions, comments or concerns please feel free to contact any of the project admins:
- Alex(josojo)
- Ben(bh2smith)
- Felix(fleupold)
decentralized-exchange
部分转自网络,侵权联系删除区块链源码网
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » Gnosis Protocol – Smart Contracts – Gnosis协议-智能合约区块链源码资料下载