Skip to content

Commit

Permalink
Support the chain without ethereum compatibility (AcalaNetwork#77)
Browse files Browse the repository at this point in the history
* support with-ethereum-compatibility

* fix tests

* update README.md
  • Loading branch information
zjb0807 authored Sep 15, 2021
1 parent fc575be commit 69283d3
Show file tree
Hide file tree
Showing 21 changed files with 2,592 additions and 121 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Or you can build & run from the Acala repo.

Follow the setup instruction at https://github.com/AcalaNetwork/Acala

Start the chain:

```bash
$ make run
```

Start the chain with evm compatibility mode:

```bash
Expand All @@ -35,6 +41,6 @@ $ make run-eth
- Install dependencies with `yarn`
- Compile contract with `yarn build`
- You can find your contract ABI in the build directory. You can upload these ABI files to [acala evm playground](https://evm.acala.network/#/upload) for testing.
- Run the tests with `yarn test`
- Run the tests with `yarn test` or `yarn test --with-ethereum-compatibility` with the chain which enable evm compatibility mode.

The test cases are written with with [ethers.js](https://docs.ethers.io/v5/) and [waffle](https://ethereum-waffle.readthedocs.io/en/latest/)
12 changes: 10 additions & 2 deletions arbitrager/contracts/Arbitrager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ contract Arbitrager is ADDRESS {

uint256 constant MAX_INT = uint256(-1);

bool private initialized;

/// @notice Constructor sets the global variables and schedules execution of trigger with Scheduler
/// @param factory_ address Address of the Uniswap Factory
/// @param router_ address Address of the Uniswap V2 Router 01 smart contract
/// @param tokenA_ address Address of the first token's smart contract
/// @param tokenB_ address Address of the second token's smart contract
/// @param period_ uint The amount of time to elapse from deploying this contract to having Scheduler trigger the trigger() function
/// @dev The constructor sets the approval of both tokens to maximum available value (2^256 - 1)
/// @dev Scheduler is called with hardcoded values for now, with only period_ being dynamic
constructor(
address factory_,
IUniswapV2Router01 router_,
Expand All @@ -48,14 +49,21 @@ contract Arbitrager is ADDRESS {
// Set approval amount for tokens at maximum possible value
tokenA_.approve(address(router_), MAX_INT);
tokenB_.approve(address(router_), MAX_INT);
}

/// @notice The contract is charged by the Scheduler for handling fees and needs to be transferred first.
/// @dev It schedules another call with Scheduler using the initial period
function initialize() public {
require(!initialized, "Contract instance has already been initialized");
initialized = true;

// Call Scheduler smart contract and schedule a call of trigger() function
ISchedule(ADDRESS.Schedule).scheduleCall(
address(this),
0,
1000000,
5000,
period_,
period,
abi.encodeWithSignature("trigger()")
);
}
Expand Down
2 changes: 1 addition & 1 deletion arbitrager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"dependencies": {
"@acala-network/api": "^2.2.2-1",
"@acala-network/bodhi": "^1.0.2-0",
"@acala-network/bodhi": "^1.0.2-2",
"@acala-network/contracts": "^1.0.23",
"@uniswap/v2-core": "^1.0.1",
"@uniswap/v2-periphery": "^1.1.0-beta.0"
Expand Down
7 changes: 7 additions & 0 deletions arbitrager/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use(evmChai);
const main = async () => {
const { wallet, provider, pair } = await setup();
const deployerAddress = await wallet.getAddress();
const tokenACA = new Contract(ADDRESS.ACA, IERC20.abi, wallet);
const tokenAUSD = new Contract(ADDRESS.AUSD, IERC20.abi, wallet);
const tokenDOT = new Contract(ADDRESS.DOT, IERC20.abi, wallet);

Expand Down Expand Up @@ -60,6 +61,12 @@ const main = async () => {
const arbitrager = await ContractFactory.fromSolidity(Arbitrager).connect(wallet)
.deploy(factory.address, router.address, ADDRESS.AUSD, ADDRESS.DOT, 1);

if (!process.argv.includes("--with-ethereum-compatibility")) {
// The contract is charged by the Scheduler for handling fees and needs to be transferred first
await tokenACA.transfer(arbitrager.address, BigNumber.from(10).pow(13));
}
await arbitrager.initialize();

await tokenAUSD.transfer(arbitrager.address, BigNumber.from(10).pow(13));
await tokenDOT.transfer(arbitrager.address, BigNumber.from(10).pow(13));

Expand Down
100 changes: 94 additions & 6 deletions arbitrager/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"@polkadot/api" "^5.6.2-5"
"@polkadot/rpc-core" "^5.6.2-5"

"@acala-network/bodhi@^1.0.2-0":
version "1.0.2-0"
resolved "https://registry.yarnpkg.com/@acala-network/bodhi/-/bodhi-1.0.2-0.tgz#5ae1c3eb9bcb397517f8c5279bcf5df189b4d2d3"
integrity sha512-4q/bzDlGE0LQJLgEVgMvgIEBF3Q27OKkMkKej4bUVKgFtUUjyyRUZ9lUJ85+EoRHT0grbCykZG9NVUqN89C44A==
"@acala-network/bodhi@^1.0.2-2":
version "1.0.2-2"
resolved "https://registry.yarnpkg.com/@acala-network/bodhi/-/bodhi-1.0.2-2.tgz#6ac927d11f4858c935520cac1ca1a4f31dd755d2"
integrity sha512-4FzAycTOt1Bokk4MsAkOM5ui4dO6MRUtyxmgeU1kcyzgWWG2UjgHpPhPOLKLAanzMPC/rUXemLyAjti74Z5f1g==
dependencies:
"@open-web3/scanner" "^0.9.4-19"
blakejs "^1.1.0"
ethers "^5.0.21"
ethers "^5.4.6"
typescript "^4.2.4"

"@acala-network/contracts@^1.0.23":
Expand Down Expand Up @@ -469,6 +469,21 @@
"@ethersproject/properties" "^5.4.0"
"@ethersproject/strings" "^5.4.0"

"@ethersproject/[email protected]":
version "5.4.1"
resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.4.1.tgz#6ac28fafc9ef6f5a7a37e30356a2eb31fa05d39b"
integrity sha512-9mhbjUk76BiSluiiW4BaYyI58KSbDMMQpCLdsAR+RsT2GyATiNYxVv+pGWRrekmsIdY3I+hOqsYQSTkc8L/mcg==
dependencies:
"@ethersproject/address" "^5.4.0"
"@ethersproject/bignumber" "^5.4.0"
"@ethersproject/bytes" "^5.4.0"
"@ethersproject/constants" "^5.4.0"
"@ethersproject/hash" "^5.4.0"
"@ethersproject/keccak256" "^5.4.0"
"@ethersproject/logger" "^5.4.0"
"@ethersproject/properties" "^5.4.0"
"@ethersproject/strings" "^5.4.0"

"@ethersproject/[email protected]", "@ethersproject/abstract-provider@^5.0.8":
version "5.0.9"
resolved "https://registry.yarnpkg.com/@ethersproject/abstract-provider/-/abstract-provider-5.0.9.tgz#a55410b73e3994842884eb82b1f43e3a9f653eea"
Expand Down Expand Up @@ -774,6 +789,11 @@
resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.4.0.tgz#f39adadf62ad610c420bcd156fd41270e91b3ca9"
integrity sha512-xYdWGGQ9P2cxBayt64d8LC8aPFJk6yWCawQi/4eJ4+oJdMMjEBMrIcIMZ9AxhwpPVmnBPrsB10PcXGmGAqgUEQ==

"@ethersproject/[email protected]":
version "5.4.1"
resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.4.1.tgz#503bd33683538b923c578c07d1c2c0dd18672054"
integrity sha512-DZ+bRinnYLPw1yAC64oRl0QyVZj43QeHIhVKfD/+YwSz4wsv1pfwb5SOFjz+r710YEWzU6LrhuSjpSO+6PeE4A==

"@ethersproject/[email protected]", "@ethersproject/networks@^5.0.7":
version "5.0.8"
resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.0.8.tgz#37e6f8c058f2d540373ea5939056cd3de069132e"
Expand Down Expand Up @@ -818,6 +838,13 @@
dependencies:
"@ethersproject/logger" "^5.4.0"

"@ethersproject/[email protected]":
version "5.4.1"
resolved "https://registry.yarnpkg.com/@ethersproject/properties/-/properties-5.4.1.tgz#9f051f976ce790142c6261ccb7b826eaae1f2f36"
integrity sha512-cyCGlF8wWlIZyizsj2PpbJ9I7rIlUAfnHYwy/T90pdkSn/NFTa5YWZx2wTJBe9V7dD65dcrrEMisCRUJiq6n3w==
dependencies:
"@ethersproject/logger" "^5.4.0"

"@ethersproject/[email protected]":
version "5.0.21"
resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.0.21.tgz#04e6b7734637a82ea4df22ef49311f419fc5e3bd"
Expand Down Expand Up @@ -868,6 +895,31 @@
bech32 "1.1.4"
ws "7.4.6"

"@ethersproject/[email protected]":
version "5.4.5"
resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.4.5.tgz#eb2ea2a743a8115f79604a8157233a3a2c832928"
integrity sha512-1GkrvkiAw3Fj28cwi1Sqm8ED1RtERtpdXmRfwIBGmqBSN5MoeRUHuwHPppMtbPayPgpFcvD7/Gdc9doO5fGYgw==
dependencies:
"@ethersproject/abstract-provider" "^5.4.0"
"@ethersproject/abstract-signer" "^5.4.0"
"@ethersproject/address" "^5.4.0"
"@ethersproject/basex" "^5.4.0"
"@ethersproject/bignumber" "^5.4.0"
"@ethersproject/bytes" "^5.4.0"
"@ethersproject/constants" "^5.4.0"
"@ethersproject/hash" "^5.4.0"
"@ethersproject/logger" "^5.4.0"
"@ethersproject/networks" "^5.4.0"
"@ethersproject/properties" "^5.4.0"
"@ethersproject/random" "^5.4.0"
"@ethersproject/rlp" "^5.4.0"
"@ethersproject/sha2" "^5.4.0"
"@ethersproject/strings" "^5.4.0"
"@ethersproject/transactions" "^5.4.0"
"@ethersproject/web" "^5.4.0"
bech32 "1.1.4"
ws "7.4.6"

"@ethersproject/[email protected]", "@ethersproject/random@^5.0.7":
version "5.0.8"
resolved "https://registry.yarnpkg.com/@ethersproject/random/-/random-5.0.8.tgz#8d3726be48e95467abce9b23c93adbb1de009dda"
Expand Down Expand Up @@ -3941,7 +3993,7 @@ [email protected]:
utf8 "^3.0.0"
uuid "^3.3.2"

ethers@^5.0.0, ethers@^5.0.1, ethers@^5.0.21:
ethers@^5.0.0, ethers@^5.0.1:
version "5.0.28"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.0.28.tgz#3c2a3d41b3639a427a822814870990cfcdd5e0a8"
integrity sha512-prYYCmZMGbrhP2PEXA2re5BpNPjaCP2y5gO1dh1i+fPxdkldQOk+0c0l8KlnxwUztKq4E40xpB0gyURdcAOaAg==
Expand Down Expand Up @@ -4013,6 +4065,42 @@ ethers@^5.0.2, ethers@^5.4.5:
"@ethersproject/web" "5.4.0"
"@ethersproject/wordlists" "5.4.0"

ethers@^5.4.6:
version "5.4.6"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.4.6.tgz#fe0a023956b5502c947f58e82fbcf9a73e5e75b6"
integrity sha512-F7LXARyB/Px3AQC6/QKedWZ8eqCkgOLORqL4B/F0Mag/K+qJSFGqsR36EaOZ6fKg3ZonI+pdbhb4A8Knt/43jQ==
dependencies:
"@ethersproject/abi" "5.4.1"
"@ethersproject/abstract-provider" "5.4.1"
"@ethersproject/abstract-signer" "5.4.1"
"@ethersproject/address" "5.4.0"
"@ethersproject/base64" "5.4.0"
"@ethersproject/basex" "5.4.0"
"@ethersproject/bignumber" "5.4.1"
"@ethersproject/bytes" "5.4.0"
"@ethersproject/constants" "5.4.0"
"@ethersproject/contracts" "5.4.1"
"@ethersproject/hash" "5.4.0"
"@ethersproject/hdnode" "5.4.0"
"@ethersproject/json-wallets" "5.4.0"
"@ethersproject/keccak256" "5.4.0"
"@ethersproject/logger" "5.4.1"
"@ethersproject/networks" "5.4.2"
"@ethersproject/pbkdf2" "5.4.0"
"@ethersproject/properties" "5.4.1"
"@ethersproject/providers" "5.4.5"
"@ethersproject/random" "5.4.0"
"@ethersproject/rlp" "5.4.0"
"@ethersproject/sha2" "5.4.0"
"@ethersproject/signing-key" "5.4.0"
"@ethersproject/solidity" "5.4.0"
"@ethersproject/strings" "5.4.0"
"@ethersproject/transactions" "5.4.0"
"@ethersproject/units" "5.4.0"
"@ethersproject/wallet" "5.4.0"
"@ethersproject/web" "5.4.0"
"@ethersproject/wordlists" "5.4.0"

[email protected]:
version "0.1.6"
resolved "https://registry.yarnpkg.com/ethjs-unit/-/ethjs-unit-0.1.6.tgz#c665921e476e87bce2a9d588a6fe0405b2c41699"
Expand Down
2 changes: 1 addition & 1 deletion dex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@acala-network/api": "^2.2.2-1",
"@acala-network/bodhi": "^1.0.2-0",
"@acala-network/bodhi": "^1.0.2-2",
"@acala-network/contracts": "^1.2.1"
}
}
Loading

0 comments on commit 69283d3

Please sign in to comment.