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

refactor: remove max limits and max button, get available liquidity #851

Merged
merged 1 commit into from
Oct 23, 2024
Merged
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
1 change: 0 additions & 1 deletion .env.local.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ VUE_APP_RSK_EXPLORER=https://explorer.testnet.rsk.co/

# replace VALUE with the clarity id for the environment the app is being deployed to.
VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC=0.005
VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC=10
#VUE_APP_CLARITY_ID=VALUE

## fee boundaries
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/deploy_MainNet_UI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ jobs:
VUE_APP_WALLET_ADDRESSES_HARD_STOP=100
VUE_APP_WALLET_ADDRESS_PER_CALL=20
VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC=0.004
VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC=10
VUE_APP_PEGIN_MIN_AMOUNT_ALLOWED_IN_BTC=0.005
VUE_APP_PEGIN_MAX_AMOUNT_ALLOWED_IN_BTC=10
VUE_APP_LBC_ADDRESS='0xAA9cAf1e3967600578727F975F283446A3Da6612'
npm run-script build
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/deploy_TestNet_UI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ jobs:
VUE_APP_WALLET_ADDRESSES_HARD_STOP=100
VUE_APP_WALLET_ADDRESS_PER_CALL=20
VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC=0.004
VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC=10
VUE_APP_PEGIN_MIN_AMOUNT_ALLOWED_IN_BTC=0.005
VUE_APP_PEGIN_MAX_AMOUNT_ALLOWED_IN_BTC=10
VUE_APP_LBC_ADDRESS='0xc2A630c053D12D63d32b025082f6Ba268db18300'
npm run-script build
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/deploy_staging_MainNet_UI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ jobs:
VUE_APP_WALLET_ADDRESSES_HARD_STOP=100
VUE_APP_WALLET_ADDRESS_PER_CALL=20
VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC=0.004
VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC=10
VUE_APP_PEGIN_MIN_AMOUNT_ALLOWED_IN_BTC=0.005
VUE_APP_PEGIN_MAX_AMOUNT_ALLOWED_IN_BTC=10
VUE_APP_LBC_ADDRESS='0xAA9cAf1e3967600578727F975F283446A3Da6612'
npm run-script build
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/deploy_staging_TestNet_UI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ jobs:
VUE_APP_WALLET_ADDRESSES_HARD_STOP=100
VUE_APP_WALLET_ADDRESS_PER_CALL=20
VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC=0.004
VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC=10
VUE_APP_PEGIN_MIN_AMOUNT_ALLOWED_IN_BTC=0.005
VUE_APP_PEGIN_MAX_AMOUNT_ALLOWED_IN_BTC=10
VUE_APP_LBC_ADDRESS='0xc2A630c053D12D63d32b025082f6Ba268db18300'
npm run-script build
Expand Down
3 changes: 0 additions & 3 deletions ENV_VARIABLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ The value of these variables are used in **environment-variables.ts** file.
|VUE_APP_WALLET_ADDRESSES_HARD_STOP | `100` | Maximum number of addresses derived from wallet |
|VUE_APP_WALLET_ADDRESS_PER_CALL | `5` | Number of addresses obtained per derivation call |
|VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC | `0.004` | 0,004 Minimum allowed value for a PEGOUT transaction |
|VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC | `10` | 10 Maximum allowed value for a PEGOUT transaction |
|VUE_APP_PEGIN_MIN_AMOUNT_ALLOWED_IN_BTC | `0.005` | Minimum allowed value for a PEGIN transaction |
|VUE_APP_PEGIN_MAX_AMOUNT_ALLOWED_IN_BTC | `10` | Maximum allowed value for a PEGIN transaction |
|VUE_APP_BURN_DUST_VALUE | `30000` | Max value to burn in the tx fee |
|VUE_APP_MIN_FEE_SAT_PER_BYTE_FAST | `8` | Min fee rate (sats/byte) required to broadcast the transaction |
|VUE_APP_MIN_FEE_SAT_PER_BYTE_AVG | `4` | Min fee rate (sats/byte) required to broadcast the transaction |
Expand All @@ -38,7 +36,6 @@ VUE_APP_RSK_EXPLORER=https://explorer.testnet.rootstock.io/
VUE_APP_WALLET_ADDRESSES_HARD_STOP=100
VUE_APP_WALLET_ADDRESS_PER_CALL=5
VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC=0.005
VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC=10
VUE_APP_BURN_DUST_VALUE=30000
VUE_APP_MIN_FEE_SAT_PER_BYTE_FAST=8
VUE_APP_MIN_FEE_SAT_PER_BYTE_AVG=4
Expand Down
11 changes: 9 additions & 2 deletions src/common/services/FlyoverService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export default class FlyoverService {

private token = '';

private liquidityProviderIdUsed = -1;

constructor(providerUrl?: string) {
this.providerUrl = providerUrl;
const appNetwork = EnvironmentAccessorService.getEnvironmentVariables().vueAppCoin;
Expand Down Expand Up @@ -128,6 +130,7 @@ export default class FlyoverService {
const provider = this.liquidityProviders.find((p: LiquidityProvider) => p.id === providerId);
if (provider) {
this.flyover?.useLiquidityProvider(provider);
this.liquidityProviderIdUsed = providerId;
}
}

Expand Down Expand Up @@ -434,13 +437,17 @@ export default class FlyoverService {
});
}

public getAvailableLiquidity(): Promise<{peginLiquidity: WeiBig, pegoutLiquidity: SatoshiBig}> {
public getAvailableLiquidity(): Promise<{
providerId: number,
peginLiquidity: WeiBig,
pegoutLiquidity: SatoshiBig,
}> {
return new Promise((resolve, reject) => {
this.flyover?.getAvailableLiquidity()
.then(({ peginLiquidityAmount, pegoutLiquidityAmount }) => {
const peginLiquidity = new WeiBig(peginLiquidityAmount, 'wei');
const pegoutLiquidity = new SatoshiBig(pegoutLiquidityAmount, 'satoshi');
resolve({ peginLiquidity, pegoutLiquidity });
resolve({ providerId: this.liquidityProviderIdUsed, peginLiquidity, pegoutLiquidity });
})
.catch((error) => {
reject(new ServiceError(
Expand Down
9 changes: 1 addition & 8 deletions src/common/services/WalletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export default abstract class WalletService {
return (this.subscribers.length > 0);
}

public async startAskingForBalance(sessionId: string, maxAmountPegin: number): Promise<void> {
public async startAskingForBalance(): Promise<void> {
this.balanceAccumulated = {
legacy: new SatoshiBig(0, 'satoshi'),
segwit: new SatoshiBig(0, 'satoshi'),
Expand All @@ -208,13 +208,6 @@ export default abstract class WalletService {
while (this.hasSubscribers() && !this.areEnoughUnusedAddresses()) {
// eslint-disable-next-line no-await-in-loop
await this.askForBalance();
const maxAmountPeginCompare = new SatoshiBig(maxAmountPegin, 'satoshi');
if (this.balanceAccumulated.legacy.gte(maxAmountPeginCompare)
&& this.balanceAccumulated.segwit.gte(maxAmountPeginCompare)
&& this.balanceAccumulated.nativeSegwit.gte(maxAmountPeginCompare)
) {
break;
}
this.setAddressesToFetch();
const maxIndexReached = Math.max(
this.addressesToFetch.legacy.lastIndex,
Expand Down
4 changes: 2 additions & 2 deletions src/common/store/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export const FLYOVER_PEGOUT_SET_SELECTED_QUOTE_HASH = 'FLYOVER_PEGOUT_SET_SELECT
export const FLYOVER_PEGOUT_CLEAR_QUOTE_DIFFERENCES = 'FLYOVER_PEGOUT_CLEAR_QUOTE_DIFFERENCES';

// Flyover PegIn actions

export const FLYOVER_PEGIN_INIT = 'FLYOVER_PEGIN_INIT';
export const FLYOVER_PEGIN_GET_PROVIDERS = 'FLYOVER_PEGIN_GET_PROVIDERS';
export const FLYOVER_PEGIN_ADD_AMOUNT = 'FLYOVER_PEGIN_ADD_AMOUNT';
Expand All @@ -90,6 +89,7 @@ export const FLYOVER_PEGIN_USE_LIQUIDITY_PROVIDER = 'FLYOVER_PEGIN_USE_LIQUIDITY
export const FLYOVER_PEGIN_GET_QUOTES = 'FLYOVER_PEGIN_GET_QUOTES';
export const FLYOVER_PEGIN_ADD_SELECTED_QUOTE = 'FLYOVER_PEGIN_ADD_SELECTED_QUOTE';
export const FLYOVER_PEGIN_CLEAR_QUOTES = 'FLYOVER_PEGIN_CLEAR_QUOTES';
export const FLYOVER_PEGIN_GET_AVAILABLE_LIQUIDITY = 'FLYOVER_PEGIN_GET_AVAILABLE_LIQUIDITY';
// Hardcoded address for Leather wallet FYI the bridge requires a
// BTC address but is not really used during PEGIN-FLYOVER process.
export const VALID_ADDRESS_UNUSED_BY_FLYOVER = {
Expand Down Expand Up @@ -162,12 +162,12 @@ export const FLYOVER_PEGOUT_SET_SELECTED_QUOTE = 'FLYOVER_PEGOUT_SET_SELECTED_QU
export const FLYOVER_PEGOUT_SET_QUOTES_DIFFERENCES = 'FLYOVER_PEGOUT_SET_QUOTES_DIFFERENCES';

// Flyover PegIn mutations

export const FLYOVER_PEGIN_SET_PROVIDERS = 'FLYOVER_PEGIN_SET_PROVIDERS';
export const FLYOVER_PEGIN_SET_AMOUNT = 'FLYOVER_PEGIN_SET_AMOUNT';
export const FLYOVER_PEGIN_SET_ROOTSTOCK_ADDRESS = 'FLYOVER_PEGIN_SET_ROOTSTOCK_ADDRESS';
export const FLYOVER_PEGIN_SET_QUOTES = 'FLYOVER_PEGIN_SET_QUOTES';
export const FLYOVER_PEGIN_SET_SELECTED_QUOTE = 'FLYOVER_PEGIN_SET_SELECTED_QUOTE';
export const FLYOVER_PEGIN_PROVIDERS_SET_AVAILABLE_LIQUIDITY = 'FLYOVER_PEGIN_PROVIDERS_SET_AVAILABLE_LIQUIDITY';

// Session mutations
export const SESSION_SET_ACCOUNT = 'SESSION_SET_ACCOUNT';
Expand Down
1 change: 1 addition & 0 deletions src/common/types/Flyover/Flyover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface PeginProviderDetail {
maxTransactionValue: SatoshiBig;
minTransactionValue: SatoshiBig;
requiredConfirmations: number;
availableLiquidity?: SatoshiBig;
}
interface PegoutProviderDetail {
fee: WeiBig;
Expand Down
12 changes: 0 additions & 12 deletions src/common/types/environment-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export class EnvironmentVariables {

public pegoutMinValue: number;

public pegoutMaxValue: number;

public debugMode: boolean;

public minFeeSatPerByte: {
Expand All @@ -43,14 +41,10 @@ export class EnvironmentVariables {

public burnDustValue: number;

public maxAmountAllowedInSatoshis: number;

public lbcAddress: string;

public peginMinAmountAllowedInBtc: number;

public peginMaxAmountAllowedInBtc: number;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(defaultValues: any = {}) {
this.vueAppCoin = process.env.VUE_APP_COIN || defaultValues.vueAppCoin;
Expand All @@ -72,8 +66,6 @@ export class EnvironmentVariables {
this.vueAppClarityId = process.env.VUE_APP_CLARITY_ID || defaultValues.vueAppClarityId;
this.pegoutMinValue = process.env.VUE_APP_PEGOUT_MIN_AMOUNT_ALLOWED_IN_RBTC
|| defaultValues.pegoutMinValue;
this.pegoutMaxValue = process.env.VUE_APP_PEGOUT_MAX_AMOUNT_ALLOWED_IN_RBTC
|| defaultValues.pegoutMaxValue;
this.minFeeSatPerByte = {
fast: process.env.VUE_APP_MIN_FEE_SAT_PER_BYTE_FAST
|| (defaultValues.minFeeSatPerByte ? defaultValues.minFeeSatPerByte.fast : 0),
Expand All @@ -91,13 +83,9 @@ export class EnvironmentVariables {
|| (defaultValues.miningSpeedBlock ? defaultValues.miningSpeedBlock.slow : 0),
};
this.burnDustValue = Number(process.env.VUE_APP_BURN_DUST_VALUE) || defaultValues.burnDustValue;
this.maxAmountAllowedInSatoshis = process.env.VUE_APP_MAX_AMOUNT_ALLOWED_IN_SATOSHI
|| defaultValues.maxAmountAllowedInSatoshis;
this.lbcAddress = process.env.VUE_APP_LBC_ADDRESS || defaultValues.lbcAddress;
this.debugMode = process.env.VUE_APP_DEBUG_MODE === 'true' || defaultValues.debugMode;
this.peginMinAmountAllowedInBtc = Number(process.env.VUE_APP_PEGIN_MIN_AMOUNT_ALLOWED_IN_BTC)
|| defaultValues.peginMinValue;
this.peginMaxAmountAllowedInBtc = Number(process.env.VUE_APP_PEGIN_MAX_AMOUNT_ALLOWED_IN_BTC)
|| defaultValues.peginMaxValue;
}
}
1 change: 0 additions & 1 deletion src/common/types/pegInTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export interface RequestBalance {

export interface PeginConfiguration {
minValue: number; // SatoshiBN
maxValue: number; // SatoshiBN
federationAddress: string;
feePerKb?: number; // SatoshiBN
sessionId: string;
Expand Down
1 change: 0 additions & 1 deletion src/common/types/pegOutTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import SatoshiBig from '@/common/types/SatoshiBig';

export interface PegoutConfiguration {
minValue: WeiBig;
maxValue: WeiBig;
bridgeContractAddress: string;
}

Expand Down
2 changes: 0 additions & 2 deletions src/common/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const getChunkedValue = (value: string, maxLength: number) => (value.leng
export const getClearPeginTxState = (): PegInTxState => ({
peginConfiguration: {
minValue: 0,
maxValue: 0,
federationAddress: '',
sessionId: '',
},
Expand Down Expand Up @@ -73,7 +72,6 @@ export const getClearPegoutTxState = (): PegOutTxState => ({
amountToTransfer: new WeiBig(0, 'wei'),
pegoutConfiguration: {
minValue: new WeiBig(0, 'wei'),
maxValue: new WeiBig(0, 'wei'),
bridgeContractAddress: '',
},
validAmount: false,
Expand Down
2 changes: 0 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ const defaultEnvironmentVariables = {
vueAppHotjarId: '',
vueAppClarityId: '',
peginMinValue: 0.005,
peginMaxValue: 10,
pegoutMinValue: 0.005,
pegoutMaxValue: 10,
minFeeSatPerByte: {
fast: 8,
average: 4,
Expand Down
43 changes: 5 additions & 38 deletions src/pegin/components/create/BtcInputAmount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
<v-chip variant="outlined" density="compact" @click="setMin">
{{ boundaries.minValue.toBTCString().slice(0,5) }} MIN
</v-chip>
<v-chip variant="outlined" density="compact" @click="setMax">
{{ boundaries.maxValue.toBTCString().slice(0,5) }} MAX
</v-chip>
</div>
</template>
</v-text-field>
Expand Down Expand Up @@ -143,16 +140,14 @@ export default defineComponent({

const boundaries = computed(() => {
const minValue: SatoshiBig = new SatoshiBig(peginConfiguration.value.minValue, 'btc');
const maxValue: SatoshiBig = new SatoshiBig(peginConfiguration.value.maxValue, 'btc');
return {
minValue,
maxValue,
};
});

const amountErrorMessage = computed(() => { // mayor rework
const feePlusAmount: SatoshiBig = safeAmount.value.plus(safeTxFee.value);
const { minValue, maxValue } = boundaries.value;
const { minValue } = boundaries.value;
if (selectedAccountBalance.value.eq('0') && !isValidAmountToTransfer.value) {
return 'Selected account has no balance';
}
Expand Down Expand Up @@ -180,19 +175,15 @@ export default defineComponent({
if (!enoughBalanceSelectedFee) {
return 'The selected fee does not satisfy the minimum required by the network';
}
if (safeAmount.value.gt(maxValue)) {
return `The maximum accepted value is ${maxValue.toBTCTrimmedString()} ${environmentContext.getBtcTicker()}`;
}
return 'Invalid format';
});

const insufficientAmount = computed(() => {
const feePlusAmount: SatoshiBig = safeAmount.value.plus(safeTxFee.value);
const { minValue, maxValue } = boundaries.value;
const { minValue } = boundaries.value;
if (safeAmount.value.lte('0')
|| feePlusAmount.gt(selectedAccountBalance.value)
|| safeAmount.value.lt(minValue)
|| safeAmount.value.gt(maxValue)) {
|| safeAmount.value.lt(minValue)) {
return true;
}
if (safeAmount.value.gt('0') && feePlusAmount.lte(selectedAccountBalance.value)) {
Expand Down Expand Up @@ -239,10 +230,9 @@ export default defineComponent({
}

const isValidAmount = (amount: SatoshiBig) => {
const { minValue, maxValue } = boundaries.value;
const { minValue } = boundaries.value;
return isBTCAmountValidRegex(amount.toBTCString())
&& amount.gte(minValue)
&& amount.lte(maxValue);
&& amount.gte(minValue);
};

async function getOptionsData() {
Expand All @@ -269,33 +259,11 @@ export default defineComponent({
},
});

function fillMaxValueAvailable() {
const maxAvailable = selectedAccountBalance.value
.cmp(boundaries.value.maxValue.plus(safeTxFee.value)) === -1
? selectedAccountBalance.value : boundaries.value.maxValue;
const tempValue = maxAvailable.minus(safeTxFee.value);
bitcoinAmount.value = tempValue.toBTCTrimmedString();
setBtcAmount(tempValue);
setIsValidAmount(selectedAccountBalance.value.gt('0'));
}

function setMin() {
const min = new SatoshiBig(peginConfiguration.value.minValue, 'btc');
bitcoinAmountModel.value = min.toBTCTrimmedString();
}

async function setMax() {
fillMaxValueAvailable();
calculateTxFee()
.then(() => {
fillMaxValueAvailable();
bitcoinAmountModel.value = bitcoinAmount.value;
})
.catch((e) => {
context.emit('pegin-error', e);
});
}

function watchBitcoinAmount() {
checkStep();
amountStyle.value = stepState.value === 'done' ? 'black-box' : 'yellow-box';
Expand Down Expand Up @@ -337,7 +305,6 @@ export default defineComponent({
rbtcAmount,
amountErrorMessage,
mdiArrowRight,
setMax,
setMin,
mdiBitcoin,
boundaries,
Expand Down
2 changes: 0 additions & 2 deletions src/pegin/services/peginConfigurationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ export default class PeginConfigurationService {
const bridgeService = new BridgeService();
const {
peginMinAmountAllowedInBtc: minValue,
peginMaxAmountAllowedInBtc: maxValue,
} = EnvironmentAccessorService.getEnvironmentVariables();
bridgeService.getFederationAddress().then((federationAddress) => {
const peginConf: PeginConfiguration = ({
minValue,
maxValue,
federationAddress,
// sessionId should be removed eventually
sessionId: '',
Expand Down
Loading
Loading