Skip to content

Commit

Permalink
Merge branch 'master' into remove-localhost-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
clemsos committed Feb 12, 2024
2 parents 3271721 + d91c413 commit 4e3e669
Show file tree
Hide file tree
Showing 66 changed files with 1,245 additions and 961 deletions.
3 changes: 2 additions & 1 deletion .clabot
Expand Up @@ -56,7 +56,8 @@
"JexxaJ",
"teawaterwire",
"sudheerDev",
"SVell"
"SVell",
"JoaoCampos89"
],
"message": "Thank you for your pull request and welcome to Unlock! We require contributors to sign our [Contributor License Agreement](https://github.com/unlock-protocol/unlock/blob/master/CLA.txt), and we don't seem to have the users {{usersWithoutCLA}} on file. \nIn order for us to review and merge your code, please open _another_ pull request with a single modification: your github username added to the file `.clabot`.\nThank you! "
}
18 changes: 9 additions & 9 deletions governance/scripts/deployments/swapper.js
@@ -1,30 +1,30 @@
const { PERMIT2_ADDRESS } = require('@uniswap/universal-router-sdk')
const {
uniswapRouterAddresses,
getNetwork,
copyAndBuildContractsAtVersion,
deployContract,
} = require('@unlock-protocol/hardhat-helpers')

async function main() {
// fetch chain info
const { unlockAddress, id: chainId } = await getNetwork()
const {
unlockAddress,
id: chainId,
uniswapV3: { universalRouterAddress },
} = await getNetwork()

const routers = [universalRouterAddress]

const routers = Object.values(uniswapRouterAddresses[chainId])
console.log(`Deploying SwapPurchaser to ${chainId}
- unlockAddress: ${unlockAddress}
- PERMIT2_ADDRESS : ${PERMIT2_ADDRESS}
- routers: ${routers}`)

if (!routers.length) {
console.log('Uniswap undefined for this network')
if (!universalRouterAddress) {
console.log('`universalRouterAddress` undefined for this network')
return
}

console.log(
`Deploying UnlockSwapPurchaser on chain ${chainId} (unlock: ${unlockAddress}, permit2: ${PERMIT2_ADDRESS}, routers: ${routers.toString()}) `
)

const [qualifiedPath] = await copyAndBuildContractsAtVersion(__dirname, [
{ contractName: 'UnlockSwapPurchaser', subfolder: 'utils' },
])
Expand Down
129 changes: 0 additions & 129 deletions locksmith/__tests__/utils/keyPricer.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion locksmith/package.json
Expand Up @@ -75,7 +75,7 @@
"path-to-regexp": "6.2.1",
"pg": "8.11.3",
"random-words": "2.0.0",
"rate-limiter-flexible": "4.0.0",
"rate-limiter-flexible": "4.0.1",
"react": "18.2.0",
"remark-html": "15.0.2",
"remark-parse": "10.0.2",
Expand Down
2 changes: 1 addition & 1 deletion locksmith/src/controllers/v2/keyController.ts
Expand Up @@ -99,6 +99,7 @@ export default class KeyController {
filters,
loggedInUserAddress,
})

return response.status(200).send({
keys,
meta: {
Expand All @@ -108,7 +109,6 @@ export default class KeyController {
},
})
} catch (error) {
logger.error(error.message)
return response.status(500).send({
message: 'Keys list could not be retrieved.',
})
Expand Down
3 changes: 2 additions & 1 deletion locksmith/src/controllers/v2/rsvpController.ts
Expand Up @@ -82,8 +82,9 @@ export const rsvp = async (request: Request, response: Response) => {
template: 'eventRsvpSubmitted',
failoverTemplate: 'eventRsvpSubmitted',
recipient: data.email,
// @ts-expect-error
// @ts-expect-error object incomplete
params: {
lockAddress: lockAddress,
eventName: eventDetail?.eventName,
eventDate: eventDetail?.eventDate,
eventTime: eventDetail?.eventTime,
Expand Down
2 changes: 1 addition & 1 deletion locksmith/src/operations/keysOperations.ts
Expand Up @@ -171,7 +171,7 @@ export async function getKeysWithMetadata({
owner: r.userAddress,
}
}),
total,
totalKeys: total,
}
} else {
// Get from subgraph!
Expand Down
3 changes: 2 additions & 1 deletion locksmith/src/operations/metadataOperations.ts
Expand Up @@ -315,8 +315,9 @@ export const getLockMetadata = async ({
// Add the event data!
if (event) {
lockMetadata = {
...lockMetadata,
...event.data,
...lockMetadata, // priority to the lock metadata if it has been set
attributes: [...event.data.attributes, ...lockMetadata.attributes],
external_url: getEventUrl(event),
}
}
Expand Down
2 changes: 1 addition & 1 deletion locksmith/src/routes/index.ts
Expand Up @@ -102,7 +102,7 @@ router.use('/v2/checkout', checkoutConfigRouter)
router.use('/v2/stripe', stripeRouter)
router.use('/v2/lock-settings', lockSettingsRouter)
router.use('/v2/certificate', certificateRouter)
router.use('/v2/og', ogRouter)
router.use('/v2/og', ogRouter) // deprecated!
router.use('/v2/events', eventsRouter)
router.use('/v2/hooks', hooksRooter)
router.use('/v2/email-subscriptions', emailSubscriptionRouter)
Expand Down
98 changes: 1 addition & 97 deletions locksmith/src/utils/keyPricer.ts
@@ -1,21 +1,10 @@
import { ethers } from 'ethers'
import { Web3Service } from '@unlock-protocol/unlock-js'
import networks from '@unlock-protocol/networks'
import logger from '../logger'
import * as Normalizer from './normalizer'
import { ItemizedKeyPrice } from '../types'
import PriceConversion from './priceConversion'
import GasPrice from './gasPrice'
import {
GAS_COST,
stripePercentage,
baseStripeFee,
GAS_COST_TO_GRANT,
} from './constants'
import { GAS_COST_TO_GRANT } from './constants'
import { getProviderForNetwork, getPurchaser } from '../fulfillment/dispatcher'

const ZERO = ethers.constants.AddressZero

// @deprecated - Remove once no longer used anywhere. Use functions in pricing.ts instead.
export default class KeyPricer {
readOnlyEthereumService: any
Expand Down Expand Up @@ -58,89 +47,4 @@ export default class KeyPricer {
}
return { canAfford: true }
}

async keyPriceUSD(lockAddress: string, network: number) {
// can we reduce load here?
const lock = await this.readOnlyEthereumService.getLock(
Normalizer.ethereumAddress(lockAddress),
network,
{ fields: ['currencyContractAddress', 'currencySymbol', 'keyPrice'] }
)

let symbol =
networks[network]?.nativeCurrency?.coinbase ||
networks[network]?.nativeCurrency?.symbol
if (lock?.currencyContractAddress !== ZERO && lock.currencySymbol) {
symbol = lock.currencySymbol
}
if (!symbol) {
logger.info(
`We could not determine currency symbol for ${lockAddress} on ${network}`
)
throw new Error(`Missing currency`)
}
// If key is free, no need to convert!
if (lock.keyPrice === '0') {
return 0
}
const priceConversion = new PriceConversion()
const usdPrice = await priceConversion.convertToUSD(
symbol.toUpperCase(),
lock.keyPrice
)
return usdPrice
}

// Fee denominated in cents by default. multiply base to get more accurate
async gasFee(network: number, base?: number): Promise<number> {
if (!base) {
base = 1
}

const gasPrice = new GasPrice()
// Price of gas
const gasCost = (await gasPrice.gasPriceUSD(network, GAS_COST)) * base
return gasCost
}

// Fee denominated in cents
creditCardProcessingFee(subtotal: number): number {
// This is rounded up to an integer number of cents.
const percentageFee = Math.ceil(subtotal * stripePercentage)

return baseStripeFee + percentageFee
}

// Fee denominated in cents
unlockServiceFee(cost: number): number {
return Math.ceil(cost * 0.1) // Unlock charges 10% of transaction.
}

async generate(
lockAddress: string,
network: number,
quantity = 1
): Promise<ItemizedKeyPrice> {
const [usdKeyPrice, gasFee] = await Promise.all([
this.keyPriceUSD(lockAddress, network),
this.gasFee(network),
])
const usdKeyPricing = usdKeyPrice * quantity
let unlockServiceFee = gasFee

// Temporary : for some locks, Unlock labs does not take credit card fees (only gas)
if (
['0x339D848115981125eEfBA2F654E1F9644363c7DB'].indexOf(lockAddress) === -1
) {
unlockServiceFee += this.unlockServiceFee(usdKeyPricing)
}

return {
keyPrice: usdKeyPricing, // shows price for all of the keys
unlockServiceFee,
creditCardProcessing: this.creditCardProcessingFee(
usdKeyPricing + unlockServiceFee
),
}
}
}
22 changes: 12 additions & 10 deletions locksmith/src/utils/pricing.ts
Expand Up @@ -129,24 +129,26 @@ export const getUnlockServiceFee = (
) => {
if (
normalizer.ethereumAddress(options?.lockAddress) ===
normalizer.ethereumAddress(
'0xB9d79698599B3efa025c654B4c6f2c760c15d0d0'
) ||
'0xB9d79698599B3efa025c654B4c6f2c760c15d0d0' ||
normalizer.ethereumAddress(options?.lockAddress) ===
normalizer.ethereumAddress(
'0xc94b031cE1837277dDABaFE2d993e0A9a2FC4E92'
) ||
'0xc94b031cE1837277dDABaFE2d993e0A9a2FC4E92' ||
normalizer.ethereumAddress(options?.lockAddress) ===
normalizer.ethereumAddress(
'0xcbEF4c0E59A224B56D408CE72C59f0D275E7adAe'
) ||
'0xcbEF4c0E59A224B56D408CE72C59f0D275E7adAe' ||
normalizer.ethereumAddress(options?.lockAddress) ===
normalizer.ethereumAddress('0x3EbE147eCd6970f49fde34b5042996e140f63c22')
'0x3EbE147eCd6970f49fde34b5042996e140f63c22'
) {
// For LexDAO, we take 3% only
return Math.ceil(cost * 0.03)
}

if (
normalizer.ethereumAddress(options?.lockAddress) ===
'0x456CC03543d41Eb1c9a7cA9FA86e9383B404f50d'
) {
// For FarCon Summit, we take 2.5% only
return Math.ceil(cost * 0.025)
}

return Math.ceil(cost * 0.1) // Unlock charges 10% of transaction.
}

Expand Down

0 comments on commit 4e3e669

Please sign in to comment.