From 2d020710715e7060dd567ef3542ca373d5d42fae Mon Sep 17 00:00:00 2001 From: Evgen Date: Fri, 7 Jul 2023 14:39:55 +0300 Subject: [PATCH] Implemented ability to add extra funds during gift-card creating --- client-config.json | 10 ++++++++-- package.json | 2 +- src/account.ts | 21 ++------------------- src/commands.ts | 9 +++++++-- src/index.ts | 2 +- yarn.lock | 4 +--- 6 files changed, 20 insertions(+), 28 deletions(-) diff --git a/client-config.json b/client-config.json index cfaa93d..991d6f5 100644 --- a/client-config.json +++ b/client-config.json @@ -90,18 +90,24 @@ "minters": { "BOB-sepolia": "", "BOB-goerli": "", + "WETH-goerli": "", + "USDC-goerli": "", "BOB-op-goerli": "" }, "cloudApi": { "BOB-sepolia": "http://45.77.217.163:8701", "BOB-goerli": "", + "WETH-goerli": "", + "USDC-goerli": "", "BOB-op-goerli": "" }, "redemptionUrls": { "BOB-sepolia": "https://staging--zkbob.netlify.app", - "BOB-goerli": "", - "BOB-op-goerli": "" + "BOB-goerli": "https://staging--zkbob.netlify.app", + "WETH-goerli": "https://staging--zkbob.netlify.app", + "USDC-goerli": "https://staging--zkbob.netlify.app", + "BOB-op-goerli": "https://staging--zkbob.netlify.app" } } \ No newline at end of file diff --git a/package.json b/package.json index b25d2b8..9f8d215 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "uuid": "^9.0.0", "web3": "^1.7.1", "zeropool-support-js": "https://github.com/zkBob/zeropool-support-js#0.8.0", - "zkbob-client-js": "5.0.0" + "zkbob-client-js": "../zkbob-client-js" }, "devDependencies": { "@parcel/compressor-gzip": "^2.0.1", diff --git a/src/account.ts b/src/account.ts index e719c05..004d5d4 100644 --- a/src/account.ts +++ b/src/account.ts @@ -702,17 +702,7 @@ export class Account { } public async giftCardBalance(giftCard: GiftCardProperties): Promise { - const proverMode = this.config.pools[this.getCurrentPool()].delegatedProverUrls.length > 0 ? - ProverMode.DelegatedWithFallback : - ProverMode.Local; - - const giftCardAccountConfig: AccountConfig = { - sk: giftCard.sk, - pool: this.getZpClient().currentPool(), - birthindex: giftCard.birthIndex, - proverMode, - } - return await this.getZpClient().giftCardBalance(giftCardAccountConfig); + return await this.getZpClient().giftCardBalance(giftCard); } public async redeemGiftCard(giftCard: GiftCardProperties): Promise<{jobId: string, txHash: string}> { @@ -720,15 +710,8 @@ export class Account { ProverMode.DelegatedWithFallback : ProverMode.Local; - const giftCardAccountConfig: AccountConfig = { - sk: giftCard.sk, - pool: this.getZpClient().currentPool(), - birthindex: giftCard.birthIndex, - proverMode, - } - console.log('Redeeming gift-card...'); - const jobId: string = await this.getZpClient().redeemGiftCard(giftCardAccountConfig); + const jobId: string = await this.getZpClient().redeemGiftCard(giftCard, proverMode); console.log(`Please wait relayer provide txHash for job ${jobId}...`); return {jobId, txHash: (await this.getZpClient().waitJobTxHash(jobId))}; diff --git a/src/commands.ts b/src/commands.ts index 4ac1627..3e57ba1 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1285,13 +1285,18 @@ export async function generateGiftCardLocal(amount: string, quantity: string){ const cardBalance = await this.account.humanToShielded(amount); const poolAlias = this.account.getCurrentPool(); + this.echo(`[[;green;]You can add extra funds to cover the relayer fee. Otherwise the user won't receive exactly specified token amount during redemption]`); + this.resume(); + const val = await this.read(`Specify extra funds for the ${qty > 1 ? 'EACH ' : ''}gift-card or press ENTER to leave it zero: `); + const extraFundsForFee = await this.account.humanToShielded(val ?? '0'); + this.pause(); // check is account has enough funds to deposit gift-card this.echo('Checking available funds...'); await this.account.syncState(); const availableFunds = await this.account.getMaxAvailableTransfer(TxType.Transfer); - if (availableFunds >= cardBalance * BigInt(qty) ) { + if (availableFunds >= (cardBalance + extraFundsForFee) * BigInt(qty) ) { this.update(-1, 'Checking available funds... [[;green;]OK]'); let transferRequests:TransferRequest[] = []; @@ -1304,7 +1309,7 @@ export async function generateGiftCardLocal(amount: string, quantity: string){ const receivingAddress = await this.account.genShieldedAddressForSeed(sk) transferRequests.push( { destination: receivingAddress, - amountGwei: cardBalance + amountGwei: cardBalance + extraFundsForFee }); this.update(-1,`Creating burner wallets... ${index+1}/${qty}`); const giftCardProps: GiftCardProperties = { sk, birthIndex, balance: cardBalance, poolAlias }; diff --git a/src/index.ts b/src/index.ts index 5ded5a6..4523023 100644 --- a/src/index.ts +++ b/src/index.ts @@ -70,7 +70,7 @@ const COMMANDS: { [key: string]: [(...args) => void, string, string] } = { 'account-id': [c.getAccountId, '', 'get the client account id (indexed DB name)'], 'support-id': [c.getSupportId, '', 'get the client support id'], 'version': [ c.getVersion, '', 'get console and relayer versions'], - 'gift-card-generate':[c.generateGiftCardLocal, '', 'creates a single burner wallet with specified balance and returns redemption url and qr code'], + 'gift-card-generate':[c.generateGiftCardLocal, ' [quantity]', 'generates a bunch of gift cards from the local account'], 'gift-card-generate-cloud':[c.generateGiftCards,' ','generate gift cards via cloud (you should provide cloud access token)'], 'gift-card-balance': [c.giftCardBalance, ' [code_or_redemption_url2 code_or_redemption_url3 ...]', 'retrieve gift cards balances'], 'gift-card-redeem': [c.redeemGiftCard, '', 'redeem gift card to the current account'], diff --git a/yarn.lock b/yarn.lock index 7e85e6a..048befd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10195,10 +10195,8 @@ yargs@^13.3.2: web3-eth-contract "^1.3.1" web3-utils "^1.3.6" -zkbob-client-js@5.0.0: +zkbob-client-js@../zkbob-client-js: version "5.0.0" - resolved "https://registry.yarnpkg.com/zkbob-client-js/-/zkbob-client-js-5.0.0.tgz#e8ffd21957a1fc2e4630aee06a17a48a36bde861" - integrity sha512-rw/9lYqkDMNqzdAsXMkQV+nwhHrsEJYAaHUAa7K9pyZVmS+jSTi3654i93HIvf+7asoDyEzGyUrdoUMVpSkNsg== dependencies: "@ethereumjs/util" "^8.0.2" "@metamask/eth-sig-util" "5.0.0"