技术开发

本页说明了如何使用智能合约进行编译/部署/测试/交互等操作,其中有四个主要合约——旋风通证,GovernorAlpha / Timelock,Aeolus和Cyclone(代币,ERC20)。

准备工作

  1. 安装truffle

    npm install -g truffle
  2. 安装dependencies

    npm install
  3. 安装 ioctl - 用于与IoTeX区块链交互的命令行工具。

按照说明安装ioctl: https://docs.iotex.io/developer/ioctl/install.html

编制合约

npm run build:contract

部署合约

  • 旋风通证(CycloneToken)

  • 部署 CycloneToken ct

    ioctl contract deploy bytecode CYCLONETOKEN_BYTECODE ABI_PATH '{"_operator": "OPERATOR_ADDRESS", "_lp": "INITIAL_LP_ADDRESS"}'
  • 缓冲段(Timelock )& 治理模块(GovernorAlpha)

  • 部署 Timelock tl

ioctl contract deploy bytecode TIMELOCK_BYTECODE TIMELOCK_ABI_PATH '{"admin_": DEPLOY_ADMIN_ADDRESS, "delay_": DELAY_IN_SEC}'
  1. 部署 GorvernorAlpha ga (例如.投票周期:3天)

ioctl contract deploy bytecode GORVERNOR_BYTECODE GOVERNOR_ABI_PATH '{"timelock_": TIMELOCK_ADDRESS, "sushi_": CYCTOKEN_ADDRESS, "guardian_": ADMIN_ADDRESS, "votingDuration_": 51840}'
  1. 设置 Timelock的待定管理员至 GovernorAlpha ga

 ioctl contract invoke function TIMELOCK_ADDRESS TIMELOCK_ABI_PATH "setPendingAdmin" --with-arguments '{"pendingAdmin_": GOVERNOR_ADDRESS}'
  1. 由监护人触发,接受成为GovernorAlpha ga 的管理员

 ioctl contract invoke function GOVERNOR_ADDRESS GOVERNOR_ABI_PATH "__acceptAdmin"
  • Aeolus

  • 在MimoFactory上为CYC / IOTX添加流动性并接收CYC-IOTX LP通证

  • ct 为地址,部署Aeolus as

    ioctl contract deploy bytecode AEOLUS_BYTECODE ABI_PATH '{"_sushi": CYC_TOKEN, "_sushiPerBlock" : AMOUNT, "_startBlock": BLOCK_NUMBER, "_bonusEndBlock": BLOCK_NUMBER}'
  • 调用 as.添加 CYC-IOTX LP 通证

ioctl contract invoke function AEOLUS_ADDRESS ABI_PATH "add" --with-arguments '{"_allocPoint": 100, "_lpToken": LP_TOKEN_ADDRESS, "_withUpdate" : false }'
  1. 调用 ct.addMinter() ,使as 成为 CYC 通证的生成器

    ioctl contract invoke function CYCTOKEN_ADDRESS CYCTOKEN_ABI_PATH "addMinter" --with-arguments '{"_minter": AEOLUS_ADDRESS}'
  2. IOTXCyclone, XRC20Cyclone

  3. 部署 Hasher hr

    ioctl contract deploy bytecode HASHER_BYTECODE
  4. 部署 Verifier vr

    ioctl contract deploy bytecode VERIFIER_BYTECODE
  5. 部署 IOTXCyclone ic, XRC20Cyclone xc , 由Hasher hrvr, ct, mf )链接,如果必要的话,还需要XRC20 通证的地址

    link IOTXCYCLONE_BYTECODE/XRC20CYCLONE_BYTECODE with HASHER_ADDRESS (use linker.js)
    ioctl contract deploy bytecode IOTXCYCLONE_LINKED_BYTECODE IOTXCYCLONE_ABI_PATH'{"_verifier": VERIFIER_ADDRESS, "_cyctoken": CYCTOKEN_ADDRESS, "_mimoFactory": MIMOFACTORY_ADDRESS, "_denomination" : DENOMINATION_AMOUNT, "_merkleTreeHeight" : MERFLETREE_HEIGHT, "_operator": TIMELOCK_ADDRESS}'
    ioctl contract deploy bytecode XRC20CYCLONE_LINKED_BYTECODE XRC20CYCLONE_ABI_PATH '{"_verifier": VERIFIER_ADDRESS, "_cyctoken": CYCTOKEN_ADDRESS, "_mimoFactory": MIMOFACTORY_ADDRESS, "_denomination" : DENOMINATION_AMOUNT, "_merkleTreeHeight" : MERKLETREE_HEIGHT, "_operator": TIMELOCK_ADDRESS, "_xrc20Token" : XRC20TOKEN_ADDRESS}'
  6. 调用 ct.addMinter() ,使 icxr 成为 CYC 通证的生成器

    ioctl contract invoke function CYCTOKEN_ADDRESS CYCTOKEN_ABI_PATH "addMinter" --with-arguments '{"_minter": IOTXCYCLONE_ADDRESS}'
    ioctl contract invoke function CYCTOKEN_ADDRESS CYCTOKEN_ABI_PATH "addMinter" --with-arguments '{"_minter": XRC20CYCLONE_ADDRESS}'

与旋风合约的交互[匿名式挖矿]

  1. 要求

  2. nvm use 11.15.0

  3. npm install -g npx

  4. 设置 .env文件

    • cp .env.example .env

    • vi .env - 添加您的私钥,已部署的合约地址和面额

  5. 搭建zk circuits: npm run build. 请注意,如果要在本地构建zk circuits(包括verifier.sol,证明/验证密钥),则需要:

    • npm uninstall websnark

    • npm install websnark@"git+https://github.com/tornadocash/websnark.git#2041cfa5fa0b71cd5cca9022a4eeea4afe28c9f7"

    • npm run build:local - 在本地执行可信设置时,可能要花费10分钟以上的时间。

  6. 存款

    • 测试网

      ./client.js deposit IOTX|XRC20 --rpc http://api.testnet.iotex.one:80

    • 主网

      ./client.js deposit IOTX|XRC20 --rpc http://api.iotex.one:80

  7. 提取

    • 测试网

      ./client.js withdraw NOTE RECIPIENT_ADDRESS --rpc http://api.testnet.iotex.one:80 --relayer RELAYER_URL

    • 主网

      ./client.js withdraw NOTE RECIPIENT_ADDRESS --rpc http://api.iotex.one:80 --relayer RELAYER_URL

与Aeolus合约的交互[流动性挖矿]

  1. 使用MimoFactory添加流动性 CYC/IOTX,并接收 CYC-IOTX LP通证

  2. CYC-IOTX LP通证许可

ioctl xrc20 approve AEOLUS_ADDRESS AMOUNT -c LPTOKEN_ADDRESS
  1. 存款

ioctl contract invoke function AEOLUS_ADDRESS abi/Aeolus.json "deposit" --with-arguments '{"_pid": 0, "_amount": AMOUNT}'
  1. 提取

ioctl contract invoke function AEOLUS_ADDRESS abi/Aeolus.json "withdraw" --with-arguments '{"_pid": 0, "_amount": AMOUNT}'

与GovernorAlpha合约的交互[去中心化治理]

  1. 自我委托或委托您的CYC通证进行治理,如果你不把你的选票委托给别人,则通证将不被视为投票权。

ioctl contract invoke function CYCTOKEN_ADDRESS abi/CycloneToken.json "delegate" --with-arguments '{"delegatee": ADDRESS_YOU_WANT_TO_DELEGATE}' -s mainnet -y
  1. 在旋风合约中提出新的变更,例如更新Tax,修改GovDAO和升级Verifier。 提议者应拥有CYC代币总供应量1%以上的额度。 投票将进行3天。

  2. 使用 abi-encoder 获得编码的参数数据。

    ioctl contract invoke function GOVERNOR_ADDRESS abi/GovernorAlpha.json "propose" --with-arguments '{"targets": [CYCLONE_ADDRESS], "values": [0], "signatures": ["updateTax(uint256)"], "calldatas": ["0x0000000000000000000000000000000000000000000000000000000000000064"], "description": "update tax in cyclone contract"}'
  3. 在为期3天的投票期间,自我委托或委托的通证持有者可以对某个提案进行投票。

    ioctl contract invoke function GOVERNOR_ADDRESS abi/GovernorAlpha.json "castVote" --with-arguments '{"proposalId": 1, "support": true}'
  4. 投票持续3天时间,如果提案获得总供应量的4%以上的投票,则提案人可以将交易排队到缓冲段(Timelock)中。

    ioctl contract invoke function GOVERNOR_ADDRESS abi/GovernorAlpha.json "queue" --with-arguments '{"proposalId": 1}'
  5. 延迟缓冲段后,提议者可以在缓冲段中执行事务。

    ioctl contract invoke function GOVERNOR_ADDRESS abi/GovernorAlpha.json "execute" --with-arguments '{"proposalId": 1}'

Last updated