Skip to content

Commit

Permalink
polygon behind staff flag
Browse files Browse the repository at this point in the history
  • Loading branch information
chibie authored and thelostone-mc committed Sep 7, 2021
1 parent b42e0fd commit fa17dfa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 60 deletions.
60 changes: 1 addition & 59 deletions app/assets/v2/js/cart-ethereum-polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,66 +337,8 @@ Vue.component('grantsCartEthereumPolygon', {
// The below heuristics are used instead of `estimateGas()` so we can send the donation
// transaction before the approval txs are confirmed, because if the approval txs
// are not confirmed then estimateGas will fail.
let networkId = appCart.$refs.cart.networkId;

if (networkId !== '80001' && networkId !== '137' && appCart.$refs.cart.chainId !== '1') {
return;
}

let gasLimit = 0;

// If user has enough balance within Polygon, cost equals the minimum amount
let { isBalanceSufficient, requiredAmounts } = await this.hasEnoughBalanceInPolygon();

if (!isBalanceSufficient) {
// If we're here, user needs at least one L1 deposit, so let's calculate the total cost
requiredAmounts = objectMap(requiredAmounts, value => {
if (value.isBalanceSufficient == false) {
return value.amount;
}
});

for (const tokenSymbol in requiredAmounts) {
if (tokenSymbol === 'ETH') {
gasLimit += 94659; // add ~94.66k gas for ETH deposits
} else {
gasLimit += 103000; // add 103k gas for token deposits
}
}
}

// If we have a cart where all donations are in Dai, we use a linear regression to
// estimate gas costs based on real checkout transaction data, and add a 50% margin
const donationCurrencies = this.donationInputs.map(donation => donation.token);
const daiAddress = this.getTokenByName('DAI')?.addr;
const isAllDai = donationCurrencies.every((addr) => addr === daiAddress);

if (isAllDai) {
if (donationCurrencies.length === 1) {
// Special case since we overestimate here otherwise
return gasLimit + 65000;
}
// https://github.com/mds1/Gitcoin-Checkout-Gas-Analysis
return gasLimit + 10000 * donationCurrencies.length + 45000;
}

/**
* Otherwise, based on contract tests, we use the more conservative heuristic below to get
* a gas estimate. The estimates used here are based on testing the cost of a single
* donation (i.e. one item in the cart). Because gas prices go down with batched
* transactions, whereas this assumes they're constant, this gives us a conservative estimate
*/
gasLimit += this.donationInputs.reduce((accumulator, currentValue) => {
// const tokenAddr = currentValue.token?.toLowerCase();

if (currentValue.token === MATIC_ADDRESS) {
return accumulator + 25000; // MATIC donation gas estimate
}

return accumulator + 70000; // generic token donation gas estimate
}, 0);

return gasLimit;
return 70000;
},

// Returns true if user has enough balance within Polygon to avoid L1 deposit, false otherwise
Expand Down
6 changes: 5 additions & 1 deletion app/grants/templates/grants/cart/eth.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ <h4 class="col gc-font-base text-dark p-0">Summary</h4>
<div v-if="zkSyncUnsupportedTokens.length > 0">
zkSync checkout not supported due to [[ zkSyncUnsupportedTokens.join(', ') ]]
</div>
{% if is_staff %}
<div v-if="polygonUnsupportedTokens.length > 0">
Polygon checkout not supported due to [[ polygonUnsupportedTokens.join(', ') ]]
</div>
{% endif %}
</div>
<div v-else-if="!isNaN(checkoutRecommendation.savingsInPercent)">
💡 Save <span class="text-primary">~[[ checkoutRecommendation.savingsInPercent ]]%</span>
Expand All @@ -166,7 +168,8 @@ <h4 class="col gc-font-base text-dark p-0">Summary</h4>
<!-- Checkout buttons -->
<div class="row justify-content-end">
<div class="btn-group flex-column flex-grow-1 flex-md-grow-0 flex-md-row" role="group" aria-label="Checkout buttons">


{% if is_staff %}
<!-- CHECKOUT WITH POLYGON -->
<grants-cart-ethereum-polygon
inline-template
Expand Down Expand Up @@ -270,6 +273,7 @@ <h3 class="font-subheader">Having issues with depositing funds to Polygon (Matic
</b-modal>
</div>
</grants-cart-ethereum-polygon>
{% endif %}

<!-- CHECKOUT WITH ZKSYNC -->
<grants-cart-ethereum-zksync
Expand Down

0 comments on commit fa17dfa

Please sign in to comment.