From 7ed92d49503adedc7a7e109ac65a98847437d325 Mon Sep 17 00:00:00 2001 From: abam-iksde Date: Wed, 19 Apr 2023 17:43:18 +0200 Subject: [PATCH 1/5] Modify depoyment script --- packages/contracts-watr/utils/bash/marsDeploy.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/contracts-watr/utils/bash/marsDeploy.sh b/packages/contracts-watr/utils/bash/marsDeploy.sh index 7bb015d5b..6f7a71455 100755 --- a/packages/contracts-watr/utils/bash/marsDeploy.sh +++ b/packages/contracts-watr/utils/bash/marsDeploy.sh @@ -23,6 +23,9 @@ while [[ "$@" ]]; do if [[ "$2" == 'local' ]]; then network_name='watr_local' network='http://127.0.0.1:8822' + elif [[ "$2" == 'devnet' ]]; then + network_name='watr_devnet' + network='https://rpc.dev.watr.org' else echo "Error: invalid network parameter: '$2'" exit 1 From 06db8e96b6026af67b1860e501382d2df83178fa Mon Sep 17 00:00:00 2001 From: abam-iksde Date: Wed, 19 Apr 2023 17:43:32 +0200 Subject: [PATCH 2/5] Add deployments --- .../deployments-watr_devnet.json | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 packages/contracts-watr/deployments-watr_devnet.json diff --git a/packages/contracts-watr/deployments-watr_devnet.json b/packages/contracts-watr/deployments-watr_devnet.json new file mode 100644 index 000000000..d7b025595 --- /dev/null +++ b/packages/contracts-watr/deployments-watr_devnet.json @@ -0,0 +1,39 @@ +{ + "unknown": { + "pausedTrueUSD": { + "txHash": "0x0d9194f40ea5982565cb499faf6dd7b792dcdae60b96bf57c09e601396c24f6d", + "address": "0x5014a961801de9a52548068bDac853CE337221e7", + "multisig": false + }, + "tokenControllerV3": { + "txHash": "0x7e7dce7e950940a73119c614a0a3fb224524c73d1d2e6eb6e2f1ff7d9d84deae", + "address": "0x32Caf123F6f574035f51532E597125062C0Aa8EE", + "multisig": false + }, + "tokenControllerV3_proxy": { + "txHash": "0x8ce0fdd33fcae155d67ee20c7c2e62dc54341e2eca23e8e9e1c176c5da062323", + "address": "0x85da1a7602C2b557020413cB0Df6456188027948", + "multisig": false + }, + "trueUSD": { + "txHash": "0xb137804e1e444c65e27de41e863214fe9de6c194df420c771e0fe3d653f5c20d", + "address": "0x361bb027e4B639B400850e98A85Cdc1B0a80e9ba", + "multisig": false + }, + "trueUSD_proxy": { + "txHash": "0x027ea3740e12e1ac007ad352a45a3bf1d7c9af04056e7584a2467b2a8e2a7f1c", + "address": "0xB01E27E914cF947b66424Fcf4f1A1C7828a8fd99", + "multisig": false + }, + "registry": { + "txHash": "0xa6e80ecb049c24eef4f84192c03b46ea701f1a4b7414fdd86543fa9287c90f46", + "address": "0xc62059Ff82A0352F2D090aAe7bB59D592B932DE6", + "multisig": false + }, + "registry_proxy": { + "txHash": "0x8408de1c3e6ccebc8e840954601d0f4c2a5a02983f923db568d722b48d8fb27b", + "address": "0x86b2FBd508c1CC3E847A734a95fe7511280BA247", + "multisig": false + } + } +} From 2f7fe5b378127e2ae3c4adf79690234f247ab4f8 Mon Sep 17 00:00:00 2001 From: abam-iksde Date: Wed, 19 Apr 2023 17:43:42 +0200 Subject: [PATCH 3/5] WIP tests --- .../scripts/deployment/deployToken.ts | 7 +----- .../verifyDeployment/verifyDeployment.test.ts | 24 ++++++++++++++++++- .../utils/generatePrecompileAddress.ts | 6 +++++ 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 packages/contracts-watr/utils/generatePrecompileAddress.ts diff --git a/packages/contracts-watr/scripts/deployment/deployToken.ts b/packages/contracts-watr/scripts/deployment/deployToken.ts index b4da3f5d1..e66fe4512 100644 --- a/packages/contracts-watr/scripts/deployment/deployToken.ts +++ b/packages/contracts-watr/scripts/deployment/deployToken.ts @@ -1,7 +1,7 @@ import { AddressLike, ArtifactFrom, contract, createProxy, Transaction, TransactionOverrides } from 'ethereum-mars' import { OwnedUpgradeabilityProxy } from '../../build/artifacts' import { NoParams } from 'ethereum-mars/build/src/syntax/contract' -import { utils } from 'ethers' +import {generatePrecompileAddress} from "../../utils/generatePrecompileAddress"; type Token = NoParams & { initialize(nativeToken: AddressLike, options?: TransactionOverrides): Transaction, @@ -24,8 +24,3 @@ export function deployToken(tokenArtifact: ArtifactFrom, con proxy, } } - -function generatePrecompileAddress(assetId: number) { - const idHex = assetId.toString(16) - return utils.getAddress('0xffffffff' + Array.from({ length: 32 - idHex.length }, () => '0').join('') + idHex) -} diff --git a/packages/contracts-watr/test/verifyDeployment/verifyDeployment.test.ts b/packages/contracts-watr/test/verifyDeployment/verifyDeployment.test.ts index ad3397ef0..e4e9c0793 100644 --- a/packages/contracts-watr/test/verifyDeployment/verifyDeployment.test.ts +++ b/packages/contracts-watr/test/verifyDeployment/verifyDeployment.test.ts @@ -2,9 +2,11 @@ import { Contract, ethers } from 'ethers' import { JsonRpcProvider } from '@ethersproject/providers' import { expect, use } from 'chai' import { unknown as deployments } from '../../deployments-watr_local.json' -import { TokenControllerV3__factory, TrueUSD__factory } from 'contracts' +import {IERC20__factory, TokenControllerV3__factory, TrueUSD__factory} from 'contracts' import { parseEther } from '@ethersproject/units' import { solidity } from 'ethereum-waffle' +import {generatePrecompileAddress} from "../../utils/generatePrecompileAddress"; +import {parseTrueUSD} from "utils"; use(solidity) @@ -71,6 +73,26 @@ describe('verify deployment', () => { await expect(tx).to.changeTokenBalances(token, [deployer, toAccount(otherAddress)], [parseEther('-0.5'), parseEther('0.5')]) }).timeout(100000) + + it('token has the right precompile address', async () => { + const deployer = new ethers.Wallet(process.env['PRIVATE_KEY_DEPLOYER'], provider) + const token = TrueUSD__factory.connect(deployments.trueUSD_proxy.address, deployer) + const precompile = await token.nativeToken() + + expect(precompile).to.eq(generatePrecompileAddress(2018)) + }) + + it('cannot transfer directly with precompile', async () => { + const deployer = new ethers.Wallet(process.env['PRIVATE_KEY_DEPLOYER'], provider) + const wallet = ethers.Wallet.createRandom() + const tokenController = TokenControllerV3__factory.connect(deployments.tokenControllerV3_proxy.address, deployer) + + await waitFor(tokenController.instantMint(wallet.address, parseTrueUSD('10'))) + + const xc20 = IERC20__factory.connect(generatePrecompileAddress(2018), wallet) + + expect(xc20.transfer(deployer.address, parseTrueUSD('5'))).to.be.reverted + }) }) async function waitFor(tx: Promise<{ wait: () => Promise }>) { diff --git a/packages/contracts-watr/utils/generatePrecompileAddress.ts b/packages/contracts-watr/utils/generatePrecompileAddress.ts new file mode 100644 index 000000000..db1149a08 --- /dev/null +++ b/packages/contracts-watr/utils/generatePrecompileAddress.ts @@ -0,0 +1,6 @@ +import {utils} from "ethers"; + +export function generatePrecompileAddress(assetId: number) { + const idHex = assetId.toString(16) + return utils.getAddress('0xffffffff' + Array.from({ length: 32 - idHex.length }, () => '0').join('') + idHex) +} From 98a202e924c63ed34be73c3f76ed798637566e34 Mon Sep 17 00:00:00 2001 From: abam-iksde Date: Thu, 20 Apr 2023 10:29:35 +0200 Subject: [PATCH 4/5] Add precompile transfer test --- .../test/verifyDeployment/verifyDeployment.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/contracts-watr/test/verifyDeployment/verifyDeployment.test.ts b/packages/contracts-watr/test/verifyDeployment/verifyDeployment.test.ts index e4e9c0793..27cdead47 100644 --- a/packages/contracts-watr/test/verifyDeployment/verifyDeployment.test.ts +++ b/packages/contracts-watr/test/verifyDeployment/verifyDeployment.test.ts @@ -84,14 +84,14 @@ describe('verify deployment', () => { it('cannot transfer directly with precompile', async () => { const deployer = new ethers.Wallet(process.env['PRIVATE_KEY_DEPLOYER'], provider) - const wallet = ethers.Wallet.createRandom() + const wallet = ethers.Wallet.createRandom().connect(provider) const tokenController = TokenControllerV3__factory.connect(deployments.tokenControllerV3_proxy.address, deployer) await waitFor(tokenController.instantMint(wallet.address, parseTrueUSD('10'))) const xc20 = IERC20__factory.connect(generatePrecompileAddress(2018), wallet) - expect(xc20.transfer(deployer.address, parseTrueUSD('5'))).to.be.reverted + await expect(xc20.transfer(deployer.address, parseTrueUSD('5'))).to.be.reverted }) }) From 65e6abb289193658cfb6a8f98336d80b800f17a9 Mon Sep 17 00:00:00 2001 From: abam-iksde Date: Thu, 20 Apr 2023 10:31:52 +0200 Subject: [PATCH 5/5] Lint --- packages/contracts-watr/package.json | 2 +- packages/contracts-watr/scripts/deployment/deployToken.ts | 2 +- .../test/verifyDeployment/verifyDeployment.test.ts | 6 +++--- packages/contracts-watr/utils/generatePrecompileAddress.ts | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/contracts-watr/package.json b/packages/contracts-watr/package.json index 390232909..43706dae8 100644 --- a/packages/contracts-watr/package.json +++ b/packages/contracts-watr/package.json @@ -8,7 +8,7 @@ "lint": "yarn lint:sol && yarn lint:ts", "typecheck": "tsc --noEmit", "lint:sol": "solhint 'contracts/**/*.sol' && prettylint 'contracts/**/*.sol'", - "lint:ts": "eslint '{test,scripts}/**/*.ts' -c .eslintrc.typescript.js", + "lint:ts": "eslint '{test,scripts,utils}/**/*.ts' -c .eslintrc.typescript.js", "lint:fix": "prettier 'contracts/**/*.sol' --write --loglevel error && yarn lint:ts --fix", "prebuild": "yarn clean", "build:hardhat": "hardhat compile", diff --git a/packages/contracts-watr/scripts/deployment/deployToken.ts b/packages/contracts-watr/scripts/deployment/deployToken.ts index e66fe4512..52a13449b 100644 --- a/packages/contracts-watr/scripts/deployment/deployToken.ts +++ b/packages/contracts-watr/scripts/deployment/deployToken.ts @@ -1,7 +1,7 @@ import { AddressLike, ArtifactFrom, contract, createProxy, Transaction, TransactionOverrides } from 'ethereum-mars' import { OwnedUpgradeabilityProxy } from '../../build/artifacts' import { NoParams } from 'ethereum-mars/build/src/syntax/contract' -import {generatePrecompileAddress} from "../../utils/generatePrecompileAddress"; +import { generatePrecompileAddress } from '../../utils/generatePrecompileAddress' type Token = NoParams & { initialize(nativeToken: AddressLike, options?: TransactionOverrides): Transaction, diff --git a/packages/contracts-watr/test/verifyDeployment/verifyDeployment.test.ts b/packages/contracts-watr/test/verifyDeployment/verifyDeployment.test.ts index 27cdead47..19c7c4741 100644 --- a/packages/contracts-watr/test/verifyDeployment/verifyDeployment.test.ts +++ b/packages/contracts-watr/test/verifyDeployment/verifyDeployment.test.ts @@ -2,11 +2,11 @@ import { Contract, ethers } from 'ethers' import { JsonRpcProvider } from '@ethersproject/providers' import { expect, use } from 'chai' import { unknown as deployments } from '../../deployments-watr_local.json' -import {IERC20__factory, TokenControllerV3__factory, TrueUSD__factory} from 'contracts' +import { IERC20__factory, TokenControllerV3__factory, TrueUSD__factory } from 'contracts' import { parseEther } from '@ethersproject/units' import { solidity } from 'ethereum-waffle' -import {generatePrecompileAddress} from "../../utils/generatePrecompileAddress"; -import {parseTrueUSD} from "utils"; +import { generatePrecompileAddress } from '../../utils/generatePrecompileAddress' +import { parseTrueUSD } from 'utils' use(solidity) diff --git a/packages/contracts-watr/utils/generatePrecompileAddress.ts b/packages/contracts-watr/utils/generatePrecompileAddress.ts index db1149a08..a37eaae3c 100644 --- a/packages/contracts-watr/utils/generatePrecompileAddress.ts +++ b/packages/contracts-watr/utils/generatePrecompileAddress.ts @@ -1,6 +1,6 @@ -import {utils} from "ethers"; +import { utils } from 'ethers' export function generatePrecompileAddress(assetId: number) { - const idHex = assetId.toString(16) - return utils.getAddress('0xffffffff' + Array.from({ length: 32 - idHex.length }, () => '0').join('') + idHex) + const idHex = assetId.toString(16) + return utils.getAddress('0xffffffff' + Array.from({ length: 32 - idHex.length }, () => '0').join('') + idHex) }