Skip to content

Commit

Permalink
Merge pull request #34 from effectai/disable_bridge
Browse files Browse the repository at this point in the history
Update bridge
  • Loading branch information
jeisses authored Jun 12, 2023
2 parents faeea7e + 50cf0a8 commit 264a629
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 58 deletions.
239 changes: 195 additions & 44 deletions components/SwapForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,48 @@
<!-- <div class="notification is-warning is-light">
The bridge is currently under maintenance. Please come back later.
</div> -->
<div class="columns is-vcentered" :class="{'is-flex-direction-row-reverse': !swapFromEOS}">
<div class="notification is-danger is-light has-text-centered">
<strong>Notice:</strong>
<p class="has-text-left">
<br> A minimum 10$ fee has been introduced by pNetwork, $10 for each transaction that doesn’t meet the
breakeven point.
Transactions above the breaking point will be charged 0.25% for pegins (BSC to EOS) and 0.01% for
pegouts (EOS to BSC).
<br>
<br>Pegin (BSC to EOS) breakeven point: $10,000 ($10/0.25%)
<br>Pegout (EOS to BSC) breakeven point: $4,000 ($10/0.01%)
<br>
<br>Going forward a minimum of 5000 EFX is required to swap.
</p>
<p class="has-text-centered">
<br><a href="https://ipfs.io/ipfs/QmWDApJT7GjBDmHgcZcxvopry2XsVJfLY5Jg8k2oPzaWpD" target="_blank"
rel="noopener noreferrer">Read more about it here.</a>
</p>
</div>
<div class="columns is-vcentered" :class="{ 'is-flex-direction-row-reverse': !swapFromEOS }">
<div class="column is-align-self-stretch is-5 ">
<small class="is-size-7"><span v-if="swapFromEOS">From</span><span v-else>To</span></small>
<div class="box is-shadowless has-border has-text-centered is-fullheight">
<div class="subtitle has-text-weight-semibold mb-2">EOS</div>
<img src="~assets/img/EOS-logo.svg" height="100" />
<div v-if="!eosWallet">
<a class="button is-small is-accent" @click="$eos.loginModal = true">
<strong>Connect EOS</strong>
</a>
<strong>Connect EOS</strong>
</a>
</div>
<div v-else>
<a :href="$eos.explorer + '/account/'+ eosWallet.auth.accountName" target="_blank" class="blockchain-address">{{ eosWallet.auth.accountName }}</a>
<a :href="$eos.explorer + '/account/' + eosWallet.auth.accountName" target="_blank"
class="blockchain-address">{{ eosWallet.auth.accountName }}</a>
<a class="has-text-danger" @click="$eos.logout()">
<small class="is-size-7">Disconnect</small>
</a>
<small class="is-size-7">Disconnect</small>
</a>
</div>
</div>
</div>
<div class="column switch is-2 has-text-centered">
<a class="has-text-centered" @click="switchChains">
<i class="fas fa-exchange-alt"></i><br>
<small class="is-size-7"><a @click="">switch</a></small>
<i class="fas fa-exchange-alt"></i><br>
<small class="is-size-7"><a @click="">switch</a></small>
</a>
</div>
<div class="column is-align-self-stretch is-5">
Expand All @@ -37,66 +56,91 @@
<img src="~assets/img/BSC-logo.svg" height="100" />
<div v-if="!bscWallet">
<a class="button is-small is-accent" @click="$bsc.loginModal = true">
<strong>Connect BSC</strong>
</a>
<strong>Connect BSC</strong>
</a>
</div>
<div v-else>
<a :href="$bsc.explorer + '/address/'+ bscWallet[0]" target="_blank" class="blockchain-address">{{ bscWallet[0] }}</a>
<a :href="$bsc.explorer + '/address/' + bscWallet[0]" target="_blank"
class="blockchain-address">{{ bscWallet[0] }}</a>
<a class="has-text-danger" @click="$bsc.logout()">
<small class="is-size-7">Disconnect</small>
</a>
<small class="is-size-7">Disconnect</small>
</a>
</div>
</div>
</div>
</div>
<div class="is-size-7 columns mb-0 is-mobile">
<div class="column py-0">
Amount
Send:
</div>
<div class="column has-text-right py-0">
Balance:
<span v-if="swapFromEOS">
<span v-if="$eos.efxAvailable !== null"><a @click="efxAmount = $eos.efxAvailable">{{ $eos.efxAvailable }}</a></span>
<span v-else>-</span>
<span v-if="$eos.efxAvailable !== null"><a @click="efxAmount = $eos.efxAvailable">{{
$eos.efxAvailable }}</a></span>
<span v-else>-</span>
</span>
<span v-else>
<span v-if="$bsc.efxAvailable !== null"><a @click="efxAmount = $bsc.efxAvailable">{{$bsc.efxAvailable}}</a></span>
<span v-else>-</span>
<span v-if="$bsc.efxAvailable !== null"><a @click="efxAmount = $bsc.efxAvailable">{{
$bsc.efxAvailable }}</a></span>
<span v-else>-</span>
</span>
</div>
</div>
<div class="field has-addons">
<div class="control is-flex-grow-1">
<input class="input is-medium" type="number" placeholder="Minumum 1800 EFX" min="0" v-model="efxAmount">
<input class="input is-medium" type="number" placeholder="Minumum 5000 EFX" min="5000"
v-model="efxAmount">
</div>
<p class="control">
<a class="button is-static is-medium">EFX</a>
</p>
</div>

<br>
<div class="is-size-7 columns mb-0 is-mobile">
<div class="column py-0">
Receive:
</div>
</div>
<div class="field has-addons">
<div class="control is-flex-grow-1">
<input disabled class="input is-medium" type="number" placeholder="Receive" min="0"
v-model="userWillReceive">
</div>
<p class="control">
<a class="button is-static is-medium">EFX</a>
</p>
</div>
<div class="is-size-7">
To your <span v-if="swapFromEOS">BSC Address</span><span v-else>EOS Account</span>

<br>
<div class="is-size-7 columns mb-0 is-mobile">
<div class="column py-0">
Fees:
</div>
</div>
<div class="field">
<input class="input" disabled :value="swapFromEOS ? (bscWallet ? bscWallet[0] : '- login with your BSC wallet -') : (eosWallet ? eosWallet.auth.accountName : '- login with your EOS wallet -')" type="text" />
<div class="field has-addons">
<div class="control is-flex-grow-1">
<input disabled class="input is-medium" type="number" placeholder="Fees" min="0"
v-model="userWillPayInFees">
</div>
<p class="control">
<a class="button is-static is-medium">EFX</a>
</p>
</div>
<button :disabled="!efxAmount || !eosWallet || !bscWallet || efxAmount < 10 || !swapFromEOS" class="button is-medium is-accent is-fullwidth mt-5" @click="onSwap">

<div class="is-size-7">
To your <span v-if="swapFromEOS">BSC Address</span><span v-else>EOS Account</span>
</div>
<div class="field">
<input class="input" disabled
:value="swapFromEOS ? (bscWallet ? bscWallet[0] : '- login with your BSC wallet -') : (eosWallet ? eosWallet.auth.accountName : '- login with your EOS wallet -')"
type="text" />
</div>
<button :disabled="!efxAmount || !eosWallet || !bscWallet || efxAmount < 5000"
class="button is-medium is-accent is-fullwidth mt-5" @click="onSwap">
<strong>Swap</strong>
</button>
<!-- Fee 0.25 % (min 1.80e+3 EFX) -->
<p class="is-size-7 is-center has-text-centered mt-3" v-if="!swapFromEOS">
Transaction fee: 0.25%
0.25% (min 1800 EFX + 3 EFX)
</p>
<p class="is-size-7 is-center has-text-centered mt-3" v-else>
Transaction fee:
0.10% (min 1800 EFX + 3 EFX) + 90.0 EFX
</p>
<p class="has-text-centered notification is-warning is-light">
<strong>Important:</strong> The bridge is currently under maintenance. BSC to EOS swaps are not available at the moment.
</p>
<p class="has-text-centered notification is-warning is-light">
<strong>Important:</strong> pNetwork has recently introduced a new policy and introduced higher fees.
</p>
</button>
</div>
</div>
</template>
Expand All @@ -107,16 +151,123 @@ export default {
return {
swapFromEOS: true,
efxAmount: null,
assets: null,
minimumEfxAmount: 5000,
}
},
async created() {
this.assets = await this.$ptokens.initAssets()
},
computed: {
// EOS
eosWallet() {
return (this.$eos) ? this.$eos.wallet : null
},
bscWallet() {
return (this.$bsc) ? this.$bsc.wallet : null
}
},
userWillReceive() {
if (this.efxAmount && this.assets) {
const minimumEfx = Number(this.assets.eosioAsset._assetInfo.fees.minNodeOperatorFee) / Number(1e18)
const minimumUsd = Number(this.assets.eosioAsset._assetInfo.fees.minNodeOperatorFeeUsd)
const percentage = this.assets.eosioAsset._assetInfo.fees.basisPoints.nativeToHost / 10000 // 0.10%
const breakEvenPointEfx = minimumEfx / percentage
const breakEvenPointUsd = minimumUsd / percentage
if (this.swapFromEOS) {
if (this.efxAmount < breakEvenPointEfx) {
return this.efxAmount - minimumEfx
} else {
return this.efxAmount - (this.efxAmount * percentage)
}
} else {
if (this.efxAmount < breakEvenPointEfx) {
return this.efxAmount - minimumEfx
} else {
return this.efxAmount - (this.efxAmount * percentage)
}
}
}
},
userWillPayInFees() {
if (this.efxAmount && this.assets) {
const minimumEfx = Number(this.assets.eosioAsset._assetInfo.fees.minNodeOperatorFee) / Number(1e18)
if (this.swapFromEOS) {
// EOS -> BSC
const networkFee = this.assets.bscAsset._assetInfo.fees.networkFee / Number(1e18)
const percentage = this.assets.eosioAsset._assetInfo.fees.basisPoints.nativeToHost / 10000 // 0.10%
const breakEvenPointEfx = minimumEfx / percentage
if (this.efxAmount < breakEvenPointEfx) {
return minimumEfx + networkFee
} else {
return (this.efxAmount * percentage) + networkFee
}
} else {
// BSC -> EOS
const percentage = this.assets.bscAsset._assetInfo.fees.basisPoints.hostToNative / 10000 // 0.25%
const breakEvenPointEfx = minimumEfx / percentage
const networkFee = 0
if (this.efxAmount < breakEvenPointEfx) {
return minimumEfx + networkFee
} else {
return (this.efxAmount * percentage) + networkFee
}
}
}
},
eosToBscFees() {
/**
* users will pay $10 for each transaction that doesn’t meet the breakeven point.
* After the breakeven point they will pay 0.10% of the amount.
* Pegout breakeven point: $4,000 ($10/0.01%)
*/
if (this.assets) {
const minimumEfx = Number(this.assets.eosioAsset._assetInfo.fees.minNodeOperatorFee) / Number(1e18)
const minimumUsd = Number(this.assets.eosioAsset._assetInfo.fees.minNodeOperatorFeeUsd)
const percentage = this.assets.eosioAsset._assetInfo.fees.basisPoints.nativeToHost / 10000 // 0.10%
const breakEvenPointEfx = minimumEfx / percentage
const breakEvenPointUsd = minimumUsd / percentage
return {
type: 'native-to-host',
roundedMinimumEfx: Math.ceil(minimumEfx),
minimumEfx,
minimumUsd,
percentage,
breakEvenPointEfx,
breakEvenPointUsd,
networkFee: 0
}
} else {
return null
}
}, // EOS -> BSC
bscToEos() {
/**
* users will pay $10 for each transaction that doesn’t meet the breakeven point.
* After the breakeven point they will pay 0.25% of the amount.
* Pegin breakeven point: $10,000 ($10/0.25%)
*/
if (this.assets) {
const minimumEfx = Number(this.assets.bscAsset._assetInfo.fees.minNodeOperatorFee) / Number(1e18)
const minimumUsd = Number(this.assets.bscAsset._assetInfo.fees.minNodeOperatorFeeUsd)
const percentage = this.assets.bscAsset._assetInfo.fees.basisPoints.hostToNative / 10000 // 0.25%
const breakEvenPointEfx = minimumEfx / percentage
const breakEvenPointUsd = minimumUsd / percentage
const networkFee = this.assets.bscAsset._assetInfo.fees.networkFee
return {
type: 'host-to-native',
roundedMinimumEfx: Math.ceil(minimumEfx),
minimumEfx,
minimumUsd,
percentage,
breakEvenPointEfx,
breakEvenPointUsd,
networkFee
}
} else {
return null
}
} // BSC -> EOS
},
methods: {
switchChains() {
Expand All @@ -136,8 +287,8 @@ export default {
}
} else {
try {
alert('This feature is disabled for now.')
// await this.$ptokens.swapBscToEos(this.efxAmount)
// alert('This feature is disabled for now.')
await this.$ptokens.swapBscToEos(this.efxAmount)
} catch (e) {
console.error('swap ptokes.swapBscToEos() error', e)
this.swapError = e.message
Expand All @@ -146,7 +297,7 @@ export default {
},
},
mounted() {
this.$ptokens.resetSwap()
this.$ptokens.resetSwap()
}
}
</script>
Expand Down
1 change: 1 addition & 0 deletions pages/swap-progress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
</nuxt-link>
</div>
</div>
<br>
</div>
</template>

Expand Down
Loading

0 comments on commit 264a629

Please sign in to comment.