- Trustless on chain token price Oracle (for any ERC20 token on the Bancor network)
- Utilises the arbitraged service provided by Bancor
- Simulates
BancorConversion
containing US$50k in the token liquidity and US$150k in BNT-DAI liquidity - Check out the CAN -> DAI conversion on Ropsten
- Deployable and testable on testnet via truffle migration
npm install -g truffle
- Modify settings in
2_converter_migration.js
to your ERC20 values:
var myTokenName = 'CanYaCoin';
var myTokenSymbol = 'CAN';
var myTokenDecimals = '6';
var myTokenPriceUsd = 0.04;
var BNTPriceUsd = 1.6;
npm install -g ganache-cli
ganache-cli
truffle migrate --network ganache
- Congrats! You deployed an oracle
- ensure you have followed the first 2 steps above
- Fill in your details on
environment.sh
and run the script (./environment.sh
) npm install truffle-hdwallet-provider
truffle migrate --network ropsten
- Either choose to use a currently deployed and maintained version of the
OracleBase
contract or add these lines to your truffle migration: await deployer.deploy(ERC20BancorPriceOracleBase, <BNTToken>.address, <DAIToken>.address, <DAIBNTConverter>.address)
<- deploy base oracle (DAI -> BNT conversion)await deployer.deploy(ERC20BancorPriceOracle, <MyERC20Token>.address, <BancorToTokenConverter>.address, <ERC20BancorPriceOracleBase>.address)
<- ERC20->DAI oracle- Use the address of this price oracle to interact with the contract from a custom contract
- Load up Remix (http://remix.ethereum.org) and create/compile a file with the code from
ERC20BancorPriceOracle.sol
- Choose environment
Web3 Provider
on Remix and set it to localhost:8545 (ganache-cli) - Grab the deployed
ERC20BancorPriceOracle
address from the migration output - Deploy an instance of the contract at this address
- Get the value of your token (including decimals) by hitting
getDaiToToken(1000000000000000000)
- xxx
-
Load up Remix (http://remix.ethereum.org) and create/compile a file with the
BancorConverter.sol
-
Choose environment
Web3 Provider
on Remix and set it to localhost:8545 (ganache-cli) -
BNT -> ERC20
- Grab the deployed
BancorToTokenConverter
address from the migration output, head to Remix and connect to an instance ofBancorConverter
at that address - Interact with the
getReturn
function with the following parameters_fromToken
(BNT token address) -> executeconnectorTokens(0)
on the deployed contract_toToken
(MyERC20 token address) -> executeconnectorTokens(1)
on the deployed contract_amount
-> 1000000000000000000 (1 * 10**[BNT Decimals])
- Return value should be (1/
myTokenRatioToBNT
) * (10**myTokenDecimals
)
- Grab the deployed
-
DAI -> BNT
- Grab the deployed
DAIBNTConverter
address from the migration output, head to Remix and connect to an instance ofBancorConverter
at that address - Interact with the
getReturn
function with the following parameters_fromToken
(DAI token address) -> executeconnectorTokens(1)
on the deployed contract_toToken
(BNT token address) -> executeconnectorTokens(0)
on the deployed contract_amount
-> 1000000000000000000 (1 * 10**[DAI Decimals])
- Return value should be (1/
currentBNTDAIRatio
) * (10**18)
- Grab the deployed
-
To do a DAI -> ERC20 calculation, grab the output from DAI -> BNT and use it as the amount in BNT -> ERC20 15.624599
- Had to create multiple ERC20 contracts with different names in order to play nice with the truffle migration script