From bbd0dca3da006d52bbfcdac9a9798e2266f8b651 Mon Sep 17 00:00:00 2001 From: Ayagoumi Date: Fri, 15 Dec 2023 10:17:55 +0100 Subject: [PATCH 1/4] feat: undeposit funds from a deposit --- .../wallet/earn/ClaimableRewardCard.vue | 14 +- .../wallet/earn/DepositRewardCard.vue | 99 ++++---- src/components/wallet/earn/ModalUndeposit.vue | 213 ++++++++++++++++++ src/helpers/wallet_helper.ts | 65 ++++-- src/locales/en.json | 3 +- src/views/CreateMultisigWallet.vue | 12 +- 6 files changed, 331 insertions(+), 75 deletions(-) create mode 100644 src/components/wallet/earn/ModalUndeposit.vue diff --git a/src/components/wallet/earn/ClaimableRewardCard.vue b/src/components/wallet/earn/ClaimableRewardCard.vue index b3a40b60c..80706eec1 100644 --- a/src/components/wallet/earn/ClaimableRewardCard.vue +++ b/src/components/wallet/earn/ClaimableRewardCard.vue @@ -6,13 +6,9 @@

{{ cleanAvaxBN(reward.amountToClaim) }} {{ nativeAssetSymbol }}

- +
diff --git a/src/helpers/wallet_helper.ts b/src/helpers/wallet_helper.ts index 9119cd66c..6e0aac3f3 100644 --- a/src/helpers/wallet_helper.ts +++ b/src/helpers/wallet_helper.ts @@ -1,18 +1,7 @@ -import { ava, bintools } from '@/AVA' -import { - buildCreateNftFamilyTx, - buildEvmTransferERCNftTx, - buildEvmTransferErc20Tx, - buildEvmTransferNativeTx, - buildMintNftTx, -} from '@/js/TxHelper' -import { WalletType } from '@/js/wallets/types' -import { AmountOutput } from '@c4tplatform/caminojs/dist/apis/avm' -import { UnsignedTx } from '@c4tplatform/caminojs/dist/apis/platformvm' - -import { ITransaction } from '@/components/wallet/transfer/types' import { BN, Buffer } from '@c4tplatform/caminojs/dist' +import { AmountOutput } from '@c4tplatform/caminojs/dist/apis/avm' import { UTXO as AVMUTXO } from '@c4tplatform/caminojs/dist/apis/avm/utxos' +import { UnsignedTx } from '@c4tplatform/caminojs/dist/apis/platformvm' import { ClaimAmountParams, ClaimType, @@ -20,22 +9,32 @@ import { UTXO as PlatformUTXO, UTXOSet as PlatformUTXOSet, } from '@c4tplatform/caminojs/dist/apis/platformvm' +import { MultisigAliasParams } from '@c4tplatform/caminojs/dist/apis/platformvm' +import { OutputOwners, SignatureError } from '@c4tplatform/caminojs/dist/common' import { PayloadBase } from '@c4tplatform/caminojs/dist/utils' +import { ModelDepositOfferSig } from '@c4tplatform/signavaultjs' +import { ava, bintools } from '@/AVA' import { ValidatorRaw } from '@/components/misc/ValidatorList/types' +import { ITransaction } from '@/components/wallet/transfer/types' import { ChainIdType, ZeroBN } from '@/constants' import { web3 } from '@/evm' import { bnToBig } from '@/helpers/helper' import { getStakeForAddresses } from '@/helpers/utxo_helper' -import ERCNftToken from '@/js/ERCNftToken' import Erc20Token from '@/js/Erc20Token' +import ERCNftToken from '@/js/ERCNftToken' +import { + buildCreateNftFamilyTx, + buildEvmTransferErc20Tx, + buildEvmTransferERCNftTx, + buildEvmTransferNativeTx, + buildMintNftTx, +} from '@/js/TxHelper' import MnemonicWallet from '@/js/wallets/MnemonicWallet' import { MultisigWallet } from '@/js/wallets/MultisigWallet' import { SingletonWallet } from '@/js/wallets/SingletonWallet' +import { WalletType } from '@/js/wallets/types' import { GetValidatorsResponse } from '@/store/modules/platform/types' -import { MultisigAliasParams } from '@c4tplatform/caminojs/dist/apis/platformvm' -import { OutputOwners, SignatureError } from '@c4tplatform/caminojs/dist/common' -import { ModelDepositOfferSig } from '@c4tplatform/signavaultjs' class WalletHelper { static async getStake(wallet: WalletType): Promise { let addrs = wallet.getAllAddressesP() @@ -634,6 +633,38 @@ class WalletHelper { return await ava.PChain().issueTx(tx) } + static async buildUnlockDepositTx(wallet: WalletType, amount: BN) { + const pAddressStrings = wallet.getAllAddressesP() + const signerAddresses = wallet.getSignerAddresses('P') + const changeAddress = wallet.getChangeAddressPlatform() + + const threshold = + wallet.type === 'multisig' ? (wallet as MultisigWallet)?.keyData?.owner?.threshold : 1 + + const unsignedTx = await ava + .PChain() + .buildUnlockDepositTx( + wallet.platformUtxoset, + [pAddressStrings, signerAddresses], + [changeAddress], + Buffer.alloc(0), + ZeroBN, + amount, + threshold + ) + + try { + const tx = await wallet.signP(unsignedTx) + return await ava.PChain().issueTx(tx) + } catch (err) { + if (err instanceof SignatureError) { + return undefined + } else { + throw err + } + } + } + static async buildAddDepositOfferTx(wallet: WalletType, offer: DepositOffer) { const pAddressStrings = wallet.getAllAddressesP() const signerAddresses = wallet.getSignerAddresses('P') diff --git a/src/locales/en.json b/src/locales/en.json index a202493f2..284f7e8e9 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -571,7 +571,8 @@ "deposit_start": "Deposit Start", "deposit_end": "Deposit End", "deposit_amount": "Deposit Amount", - "deposited_amount": "Deposited Amount" + "deposited_amount": "Deposited Amount", + "undeposit": "Undeposit" }, "claim_modal": { "are_you_sure": "Are you sure you want to claim {amount} {symbol} rewards?", diff --git a/src/views/CreateMultisigWallet.vue b/src/views/CreateMultisigWallet.vue index 72a906e13..dcd527d93 100644 --- a/src/views/CreateMultisigWallet.vue +++ b/src/views/CreateMultisigWallet.vue @@ -95,23 +95,25 @@