From 4fd844a899f0347b32bad603327339753a237030 Mon Sep 17 00:00:00 2001 From: EvgenKor Date: Tue, 19 Dec 2023 17:17:03 +0300 Subject: [PATCH 1/4] Ability to add custom address prefix (#100) * Improve address info * Removing temporary prefixes * Setting new js lib version * Updating client lib --- package.json | 4 ++-- src/account.ts | 1 + src/commands.ts | 8 +++++++- src/environment.ts | 3 ++- yarn.lock | 26 ++++++++++++++------------ 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 9944ed6..7a5a5e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zkbob-console", - "version": "3.8.0", + "version": "3.9.0", "license": "MIT", "author": "Dmitry Vdovin ", "homepage": "https://github.com/zkBob/zkbob-console", @@ -39,7 +39,7 @@ "tslib": "^2.3.1", "uuid": "^9.0.0", "web3": "^1.7.1", - "zkbob-client-js": "5.4.0", + "zkbob-client-js": "5.5.0-beta1", "zkbob-support-js": "1.0.1" }, "devDependencies": { diff --git a/src/account.ts b/src/account.ts index af88ed2..2ea402f 100644 --- a/src/account.ts +++ b/src/account.ts @@ -74,6 +74,7 @@ export class Account { this.config = { pools: env.pools, chains: env.chains, + extraPrefixes: env.extraPrefixes, snarkParams: env.globalSnarks, snarkParamsSet: env.snarkParamsSet, supportId: this.supportId, diff --git a/src/commands.ts b/src/commands.ts index 8f8030b..723bd46 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -110,13 +110,19 @@ export async function genShieldedAddressUniversal(number: string) { } export async function shieldedAddressInfo(shieldedAddress: string) { + this.echo('Validating ...'); + const isValid = await account(this).verifyShieldedAddress(shieldedAddress); + this.update(-1, `Validating ${isValid ? '[[;green;]PASS]' : '[[;red;]ERROR]'}`) + this.echo('Checking ownable on the current pool ...'); + const isOwn = await account(this).isMyAddress(shieldedAddress); + this.update(-1, `Checking ownable on the current pool ${isOwn ? '[[;green;]YES]' : '[[;red;]NO]'}`) + this.echo('Parsing address...'); try { const components = await account(this).zkAddressInfo(shieldedAddress); this.update(-1, 'Parsing address... [[;green;]OK]'); this.echo(`Address format: [[;white;]${components.format}]`); this.echo(`Is it derived from my SK: ${components.derived_from_our_sk ? '[[;green;]YES]' : '[[;white;]NO]'}`); - const isValid = await account(this).verifyShieldedAddress(shieldedAddress); this.echo(`Is it valid on current pool: ${isValid ? '[[;green;]YES]' : '[[;red;]NO]'}`); try { const poolId = BigInt(components.pool_id); diff --git a/src/environment.ts b/src/environment.ts index 8045128..400ffe8 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -1,4 +1,4 @@ -import { Chains, Pools, SnarkConfigParams, Parameters } from 'zkbob-client-js'; +import { Chains, Pools, SnarkConfigParams, Parameters, ZkAddressPrefix } from 'zkbob-client-js'; export interface TokenMigrationConfig { tokenAddress: string; @@ -10,6 +10,7 @@ export interface ConsoleConfig { defaultPool: string; pools: Pools; chains: Chains; + extraPrefixes?: ZkAddressPrefix[]; globalSnarks?: SnarkConfigParams; snarkParamsSet?: Parameters; blockExplorerUrls: {[chainId: string]: {tx: string, address: string} }; diff --git a/yarn.lock b/yarn.lock index fd0896c..07adbf1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8216,15 +8216,15 @@ levn@^0.3.0, levn@~0.3.0: prelude-ls "~1.1.2" type-check "~0.3.2" -libzkbob-rs-wasm-web-mt@1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/libzkbob-rs-wasm-web-mt/-/libzkbob-rs-wasm-web-mt-1.5.0.tgz#6a88fe3fdfcd0fe856fd791fa0976bdde2fea34b" - integrity sha512-2uwwE5mm32ITMvYgW3uPsPXLrPVutnpYB003wzDzMbPfF2EBjP1kh+sQwPUDmEl+ic4OSTXU/q3sdkWWmhUhRQ== +libzkbob-rs-wasm-web-mt@1.6.0-beta2: + version "1.6.0-beta2" + resolved "https://registry.yarnpkg.com/libzkbob-rs-wasm-web-mt/-/libzkbob-rs-wasm-web-mt-1.6.0-beta2.tgz#a324d891d4c0418d185d64aba06a126d7e626cab" + integrity sha512-BKXR/Gsl0uGhjWGhiLhDJ/ckq4+cnNgjxVGARWkXyRRXyHzUNBL9VHf4HQwxNVwOK/Vl3rRTA0A3wukOpXL5Qg== -libzkbob-rs-wasm-web@1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/libzkbob-rs-wasm-web/-/libzkbob-rs-wasm-web-1.5.0.tgz#41c2b0a51a9283a96457bd5439cfeed27f866913" - integrity sha512-QlnFMNzqjFakkIDrST4kmOdr+OikMZVZoOi2B73F/kb/3elcPSA5vAjYM/AdmB3+Ojty4ZrQW1GnsFWJrebF5w== +libzkbob-rs-wasm-web@1.6.0-beta2: + version "1.6.0-beta2" + resolved "https://registry.yarnpkg.com/libzkbob-rs-wasm-web/-/libzkbob-rs-wasm-web-1.6.0-beta2.tgz#bb3b87758efb7082fcb2ee0fce5a0da85119cd99" + integrity sha512-XbR7x7kcYAJIEVPa+HppkfpWvbgX2pSB5fjSfUN16c5UUwY+ahrmqKpTBenPF4HvhrglmBpworQjCWo8d2HcrQ== lie@3.1.1: version "3.1.1" @@ -13074,8 +13074,10 @@ yocto-queue@^0.1.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== -"zkbob-client-js@file:../zkbob-client-js": - version "5.4.0" +zkbob-client-js@5.5.0-beta1: + version "5.5.0-beta1" + resolved "https://registry.yarnpkg.com/zkbob-client-js/-/zkbob-client-js-5.5.0-beta1.tgz#b24d9d456817a5a3aab2fe77962499132dc30ba2" + integrity sha512-SUS58kxBRPLIi+M34V+uz25csLQwE70IRzCcXf+5697CG8GJ5bPSGu2EtNBh0HzAOh4AAbdkXBZ+xILr3dFxWw== dependencies: "@ethereumjs/util" "^8.0.2" "@graphprotocol/client-cli" "3.0.0" @@ -13088,8 +13090,8 @@ yocto-queue@^0.1.0: graphql "16.7.1" hdwallet-babyjub "^0.0.2" idb "^7.0.0" - libzkbob-rs-wasm-web "1.5.0" - libzkbob-rs-wasm-web-mt "1.5.0" + libzkbob-rs-wasm-web "1.6.0-beta2" + libzkbob-rs-wasm-web-mt "1.6.0-beta2" promise-retry "^2.0.1" promise-throttle "^1.1.2" regenerator-runtime "^0.13.9" From 0660ee553d70a881a56a49df21e4eaacff46f763 Mon Sep 17 00:00:00 2001 From: EvgenKor Date: Wed, 20 Dec 2023 16:34:59 +0300 Subject: [PATCH 2/4] Nile MPC Guard deployment support (#102) * MPC guard supporting * Removing unneeded changes * Fix * Udpating yarn.lock --- client-config-full.json | 30 ++++++++++++++++++++++++++---- src/account.ts | 7 ++++--- src/commands.ts | 26 ++++++++++++++++++-------- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/client-config-full.json b/client-config-full.json index 8512c18..d1da31a 100644 --- a/client-config-full.json +++ b/client-config-full.json @@ -1,5 +1,5 @@ { - "defaultPool": "BOB2USDC-goerli", + "defaultPool": "USDT-nile-guard", "pools": { "USDC-polygon": { @@ -128,9 +128,28 @@ "feeDecimals": 2, "minTxAmount": 50000, "depositScheme": "approve" + }, + "USDT-nile-guard": { + "chainId": 3448148188, + "poolAddress": "TJp4J3M2rEZ5euswTpGzUaVVEJxkXX66mL", + "tokenAddress": "TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf", + "relayerUrls": ["https://tron-nile-mpc-relayer.thgkjlr.website"], + "delegatedProverUrls": [], + "coldStorageConfigPath": "", + "feeDecimals": 2, + "minTxAmount": 50000, + "depositScheme": "approve" } }, + "extraPrefixes": [ + { + "poolId": 16776968, + "prefix": "zkbob_nile_g", + "name": "USDT on Nile testnet (MPC guard contracts)" + } + ], + "chains": { "137": { "rpcUrls": ["https://polygon-rpc.com", "https://rpc.ankr.com/polygon"] @@ -216,7 +235,8 @@ "BOB-op-goerli": "0x357cA353dbCad28418d5F3110727B2af62803F20", "USDT-shasta": "", "USDT-devnet": "TRdunaTZCKYM9xW3HGJjJLQYV6f89UHEkD", - "USDT-nile": "" + "USDT-nile": "", + "USDT-nile-guard": "" }, "cloudApi": { @@ -230,7 +250,8 @@ "BOB-op-goerli": "", "USDT-shasta": "", "USDT-devnet": "", - "USDT-nile": "" + "USDT-nile": "", + "USDT-nile-guard": "" }, "redemptionUrls": { @@ -244,7 +265,8 @@ "BOB-op-goerli": "https://staging--zkbob.netlify.app", "USDT-shasta": "https://staging--zkbob.netlify.app", "USDT-devnet": "https://staging--zkbob.netlify.app", - "USDT-nile": "https://staging--zkbob.netlify.app" + "USDT-nile": "https://staging--zkbob.netlify.app", + "USDT-nile-guard": "https://staging--zkbob.netlify.app" }, "migrations": { diff --git a/src/account.ts b/src/account.ts index 2ea402f..a88630a 100644 --- a/src/account.ts +++ b/src/account.ts @@ -603,11 +603,12 @@ export class Account { let totalNeededAmount = await this.getZpClient().shieldedAmountToWei(amount + feeEst.total); if (depositScheme == DepositType.Approve) { // check a token approvement if needed (in case of approve deposit scheme) - const currentAllowance = await this.getClient().allowance(this.getTokenAddr(), this.getPoolAddr()); + const depositDestination = this.getPoolAddr(); + const currentAllowance = await this.getClient().allowance(this.getTokenAddr(), depositDestination); if (totalNeededAmount > currentAllowance) { totalNeededAmount -= currentAllowance; - console.log(`Increasing allowance for the Pool (${this.getPoolAddr()}) to spend our tokens (+ ${await this.weiToHuman(totalNeededAmount)} ${this.tokenSymbol()})`); - await this.getClient().increaseAllowance(this.getTokenAddr(), this.getPoolAddr(), totalNeededAmount); + console.log(`Increasing allowance for the Pool contract (${depositDestination}) to spend our tokens (+ ${await this.weiToHuman(totalNeededAmount)} ${this.tokenSymbol()})`); + await this.getClient().increaseAllowance(this.getTokenAddr(), depositDestination, totalNeededAmount); } else { console.log(`Current allowance (${await this.weiToHuman(currentAllowance)} ${this.tokenSymbol()}) is greater or equal than needed (${await this.weiToHuman(totalNeededAmount)} ${this.tokenSymbol()}). Skipping approve`); } diff --git a/src/commands.ts b/src/commands.ts index 723bd46..590fe27 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -20,7 +20,7 @@ function account(_this: any): Account { } export async function currentPoolEnvironment() { - const curPool = await account(this).getCurrentPool(); + const curPool = account(this).getCurrentPool(); const poolEnv = env.pools[curPool]; const chainEnv = env.chains[String(poolEnv.chainId)]; @@ -827,21 +827,31 @@ export async function getRoot(index: string) { this.echo(`Requesting additional info...`); this.pause(); - const relayerState = account(this).getRelayerTreeState(); + const relayerState = account(this).getRelayerTreeState().catch((e) => e.message); let relayerOptimisticState; if (idx === undefined) { - relayerOptimisticState = account(this).getRelayerOptimisticTreeState(); + relayerOptimisticState = account(this).getRelayerOptimisticTreeState().catch((e) => e.message); } - const poolState = account(this).getPoolTreeState(idx); + const poolState = account(this).getPoolTreeState(idx).catch((e) => e.message); let promises = [relayerState, relayerOptimisticState, poolState] Promise.all(promises).then((states) => { + const relayerState = typeof states[0] === "string" ? `[[;red;]${states[0]}]` : + `[[;white;]${states[0].root.toString()} @${states[0].index.toString()}]`; + const relayerOpState = typeof states[1] === "string" ? `[[;red;]${states[1]}]` : + `[[;white;]${states[1].root.toString()} @${states[1].index.toString()}]`; + const poolState = typeof states[2] === "string" ? `[[;red;]${states[2]}]` : + `[[;white;]${states[2].root.toString()} @${states[2].index.toString()}]`; + if (relayerOptimisticState !== undefined) { - this.update(-1, `Relayer: [[;white;]${states[0].root.toString()} @${states[0].index.toString()}]`); - this.echo(`Relayer optimistic: [[;white;]${states[1].root.toString()} @${states[1].index.toString()}]`); - this.echo(`Pool contract: [[;white;]${states[2].root.toString()} @${states[2].index.toString()}]`); + const relayerOpState = typeof states[1] === "string" ? `[[;red;]${states[1]}]` : + `[[;white;]${states[1].root.toString()} @${states[1].index.toString()}]`; + + this.update(-1, `Relayer: ${relayerState}`); + this.echo(`Relayer optimistic: ${relayerOpState}`); + this.echo(`Pool contract: ${poolState}`); } else { - this.update(-1, `Pool contract: [[;white;]${states[2].root.toString()} @${states[2].index.toString()}]`); + this.update(-1, `Pool contract: ${poolState}`); } }).catch((reason) => { this.error(`Cannot fetch additional info: ${reason}`); From fa7e1a8c71cffdf3ac7f950a45c214b7cede8582 Mon Sep 17 00:00:00 2001 From: EvgenKor Date: Sat, 6 Jan 2024 16:56:19 +0300 Subject: [PATCH 3/4] Added tron mainnet pool, requesting token seller (#103) --- client-config-full.json | 43 ++++++++++++++++++++++------------------- src/account.ts | 4 ++++ 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/client-config-full.json b/client-config-full.json index d1da31a..7c9e26a 100644 --- a/client-config-full.json +++ b/client-config-full.json @@ -1,5 +1,5 @@ { - "defaultPool": "USDT-nile-guard", + "defaultPool": "USDT-tron", "pools": { "USDC-polygon": { @@ -107,17 +107,6 @@ "minTxAmount": 50000, "depositScheme": "approve" }, - "USDT-devnet": { - "chainId": 728126428, - "poolAddress": "TVtGa6o4KWYa6pfcd6A34xQte1FuDJPFah", - "tokenAddress": "TRdunaTZCKYM9xW3HGJjJLQYV6f89UHEkD", - "relayerUrls": ["https://tron-devnet-relayer.thgkjlr.website"], - "delegatedProverUrls": [], - "coldStorageConfigPath": "", - "feeDecimals": 2, - "minTxAmount": 50000, - "depositScheme": "approve" - }, "USDT-nile": { "chainId": 3448148188, "poolAddress": "TT8GgygLhEDh88kYwY8mYz38iEpJWw1YLG", @@ -139,6 +128,17 @@ "feeDecimals": 2, "minTxAmount": 50000, "depositScheme": "approve" + }, + "USDT-tron": { + "chainId": 728126428, + "poolAddress": "TXViaNRhEugXpAZApviBqBnbTSKUgejnR9", + "tokenAddress": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", + "relayerUrls": ["https://relayer-tron-mpc.zkbob.com/"], + "delegatedProverUrls": [], + "coldStorageConfigPath": "", + "minTxAmount": 50000, + "depositScheme": "approve", + "ddSubgraph": "" } }, @@ -169,11 +169,11 @@ "2494104990": { "rpcUrls": ["https://api.shasta.trongrid.io"] }, - "728126428": { - "rpcUrls": ["https://tron-devnet.zkbob.com"] - }, "3448148188": { "rpcUrls": ["https://nile.trongrid.io"] + }, + "728126428": { + "rpcUrls": ["https://api.trongrid.io"] } }, @@ -215,8 +215,8 @@ "address": "https://shasta.tronscan.org/#/address/{{addr}}" }, "728126428": { - "tx": "{{hash}}", - "address": "{{addr}}" + "tx": "https://tronscan.org/#/transaction/{{hash}}", + "address": "https://tronscan.org/#/address/{{addr}}" }, "3448148188": { "tx": "https://nile.tronscan.org/#/transaction/{{hash}}", @@ -236,7 +236,8 @@ "USDT-shasta": "", "USDT-devnet": "TRdunaTZCKYM9xW3HGJjJLQYV6f89UHEkD", "USDT-nile": "", - "USDT-nile-guard": "" + "USDT-nile-guard": "", + "USDT-tron": "" }, "cloudApi": { @@ -251,7 +252,8 @@ "USDT-shasta": "", "USDT-devnet": "", "USDT-nile": "", - "USDT-nile-guard": "" + "USDT-nile-guard": "", + "USDT-tron": "" }, "redemptionUrls": { @@ -266,7 +268,8 @@ "USDT-shasta": "https://staging--zkbob.netlify.app", "USDT-devnet": "https://staging--zkbob.netlify.app", "USDT-nile": "https://staging--zkbob.netlify.app", - "USDT-nile-guard": "https://staging--zkbob.netlify.app" + "USDT-nile-guard": "https://staging--zkbob.netlify.app", + "USDT-tron": "https://tron.zkbob.com" }, "migrations": { diff --git a/src/account.ts b/src/account.ts index a88630a..0832464 100644 --- a/src/account.ts +++ b/src/account.ts @@ -842,4 +842,8 @@ export class Account { public async proverVersion(): Promise { return await this.getZpClient().getProverVersion(); } + + public async getTokenSeller() : Promise { + return await this.getZpClient().tokenSellerContract(); + } } \ No newline at end of file From 37ac32e8d5c9dec5cdd671cd323803dace75818a Mon Sep 17 00:00:00 2001 From: EvgenKor Date: Wed, 10 Jan 2024 17:04:45 +0300 Subject: [PATCH 4/4] Updating client library (v5.5.0) (#104) --- package.json | 2 +- yarn.lock | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 7a5a5e9..51a78fa 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "tslib": "^2.3.1", "uuid": "^9.0.0", "web3": "^1.7.1", - "zkbob-client-js": "5.5.0-beta1", + "zkbob-client-js": "5.5.0", "zkbob-support-js": "1.0.1" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 07adbf1..83254fa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8216,15 +8216,15 @@ levn@^0.3.0, levn@~0.3.0: prelude-ls "~1.1.2" type-check "~0.3.2" -libzkbob-rs-wasm-web-mt@1.6.0-beta2: - version "1.6.0-beta2" - resolved "https://registry.yarnpkg.com/libzkbob-rs-wasm-web-mt/-/libzkbob-rs-wasm-web-mt-1.6.0-beta2.tgz#a324d891d4c0418d185d64aba06a126d7e626cab" - integrity sha512-BKXR/Gsl0uGhjWGhiLhDJ/ckq4+cnNgjxVGARWkXyRRXyHzUNBL9VHf4HQwxNVwOK/Vl3rRTA0A3wukOpXL5Qg== +libzkbob-rs-wasm-web-mt@1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/libzkbob-rs-wasm-web-mt/-/libzkbob-rs-wasm-web-mt-1.6.0.tgz#9437cdd240fb1ac47e6e3fbc7e34f45ade5af19e" + integrity sha512-nAfmUh8ZrQ5WfEc3v7+vWWRWjOy3uFWn/LRdIce7zmnq1t8X91MD+RgnPcHxbgDpz5eGpSn5V/OSc3XYPwm9aw== -libzkbob-rs-wasm-web@1.6.0-beta2: - version "1.6.0-beta2" - resolved "https://registry.yarnpkg.com/libzkbob-rs-wasm-web/-/libzkbob-rs-wasm-web-1.6.0-beta2.tgz#bb3b87758efb7082fcb2ee0fce5a0da85119cd99" - integrity sha512-XbR7x7kcYAJIEVPa+HppkfpWvbgX2pSB5fjSfUN16c5UUwY+ahrmqKpTBenPF4HvhrglmBpworQjCWo8d2HcrQ== +libzkbob-rs-wasm-web@1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/libzkbob-rs-wasm-web/-/libzkbob-rs-wasm-web-1.6.0.tgz#050887671fb1af20adb22a144e95e06c59e42460" + integrity sha512-Mtpc/pqutA2tUzb8nir7Ec2oXTSPbYvjf969QsJKcdJR/JmCGbv1gmylxjVdL7QnAUTH3ldt0jj5CU8v8X6yzw== lie@3.1.1: version "3.1.1" @@ -13074,10 +13074,10 @@ yocto-queue@^0.1.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== -zkbob-client-js@5.5.0-beta1: - version "5.5.0-beta1" - resolved "https://registry.yarnpkg.com/zkbob-client-js/-/zkbob-client-js-5.5.0-beta1.tgz#b24d9d456817a5a3aab2fe77962499132dc30ba2" - integrity sha512-SUS58kxBRPLIi+M34V+uz25csLQwE70IRzCcXf+5697CG8GJ5bPSGu2EtNBh0HzAOh4AAbdkXBZ+xILr3dFxWw== +zkbob-client-js@5.5.0: + version "5.5.0" + resolved "https://registry.yarnpkg.com/zkbob-client-js/-/zkbob-client-js-5.5.0.tgz#b5811083680b47562cb5fa7de8a789d8c216fed5" + integrity sha512-KJlQ6T1iy3uyZP/BbGwQSuK8zqsw1VUcMz3aSVrqMU9hgEbOUa18vF4U6IUELMsahw4QfPE/1W0lwAYmyNZShA== dependencies: "@ethereumjs/util" "^8.0.2" "@graphprotocol/client-cli" "3.0.0" @@ -13090,8 +13090,8 @@ zkbob-client-js@5.5.0-beta1: graphql "16.7.1" hdwallet-babyjub "^0.0.2" idb "^7.0.0" - libzkbob-rs-wasm-web "1.6.0-beta2" - libzkbob-rs-wasm-web-mt "1.6.0-beta2" + libzkbob-rs-wasm-web "1.6.0" + libzkbob-rs-wasm-web-mt "1.6.0" promise-retry "^2.0.1" promise-throttle "^1.1.2" regenerator-runtime "^0.13.9"