Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⛲️ Prepare Watr devnet deployment #1257

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/contracts-watr/deployments-watr_devnet.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
2 changes: 1 addition & 1 deletion packages/contracts-watr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 1 addition & 6 deletions packages/contracts-watr/scripts/deployment/deployToken.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -24,8 +24,3 @@ export function deployToken<T extends Token>(tokenArtifact: ArtifactFrom<T>, con
proxy,
}
}

function generatePrecompileAddress(assetId: number) {
const idHex = assetId.toString(16)
return utils.getAddress('0xffffffff' + Array.from({ length: 32 - idHex.length }, () => '0').join('') + idHex)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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().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)

await expect(xc20.transfer(deployer.address, parseTrueUSD('5'))).to.be.reverted
})
})

async function waitFor<T>(tx: Promise<{ wait: () => Promise<T> }>) {
Expand Down
3 changes: 3 additions & 0 deletions packages/contracts-watr/utils/bash/marsDeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions packages/contracts-watr/utils/generatePrecompileAddress.ts
Original file line number Diff line number Diff line change
@@ -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)
}