Skip to content

Commit

Permalink
feat(unlock-app): upgrading to Decent v2 (#13878)
Browse files Browse the repository at this point in the history
* decent upgraded

* wip

* removed undue changes

* minor tweak
  • Loading branch information
julien51 committed May 22, 2024
1 parent 7d62e4f commit 8e8e837
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 27 deletions.
1 change: 1 addition & 0 deletions unlock-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"@airstack/airstack-react": "0.6.3",
"@crossmint/client-sdk-react-ui": "1.1.9",
"@decent.xyz/box-common": "2.0.24",
"@enzoferey/ethers-error-parser": "0.2.3",
"@guildxyz/sdk": "1.1.1",
"@headlessui/react": "1.7.19",
Expand Down
72 changes: 45 additions & 27 deletions unlock-app/src/utils/theBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ethers } from 'ethers'
import axios from 'axios'
import { networks } from '@unlock-protocol/networks'
import { ADDRESS_ZERO } from '~/constants'
import { BoxChainInfo, BoxChains } from '@decent.xyz/box-common'

export interface BoxActionRequest {
sender: string
Expand Down Expand Up @@ -55,34 +56,22 @@ export const getCrossChainRoutes = async ({
referrers,
purchaseData,
}: getCrossChainRoutesParams): Promise<CrossChainRoute[]> => {
const baseUrl = 'https://box-v1.api.decent.xyz/api/getBoxAction'
const apiKey = '9f3ef983290e05e38264f4eb65e09754'
const baseUrl = 'https://box-v2.api.decent.xyz/api/getBoxAction'
const apiKey = '6477b3b3671589d81df0cba67ba9f3e6'
const actionRequest: BoxActionRequest = {
srcChainId: 1, // we be replaced when looping over networks
actionType: 'evm-function',
sender,

srcToken: ADDRESS_ZERO, // use the native token. Later: check the user balances!
dstChainId: lock.network,
dstToken: lock.currencyContractAddress || ADDRESS_ZERO,
slippage: 1, // 1%
actionType: 'nft-mint',

srcChainId: 1, // will be replaced when looping over networks
dstChainId: lock.network,
actionConfig: {
contractAddress: lock.address,
chainId: lock.network,
signature:
'function purchase(uint256[] _values,address[] _recipients,address[] _referrers,address[] _keyManagers,bytes[] _data) payable returns (uint256[])', // We need to get this from walletService!
args: [
prices.map((price) => {
const priceInBigNumber = ethers.utils.parseUnits(
price.amount.toString(),
price.decimals
)
return priceInBigNumber.toBigInt()
}),
recipients,
referrers,
keyManagers,
purchaseData,
],
contractAddress: lock.address,

cost: {
isNative: true,
amount: prices
Expand All @@ -98,16 +87,44 @@ export const getCrossChainRoutes = async ({
)
.toBigInt(),
},

signature: encodeURIComponent(
'function purchase(uint256[] _values,address[] _recipients,address[] _referrers,address[] _keyManagers,bytes[] _data) payable returns (uint256[])'
), // We need to get this from walletService!

args: [
prices.map((price) => {
const priceInBigNumber = ethers.utils.parseUnits(
price.amount.toString(),
price.decimals
)
return priceInBigNumber.toBigInt()
}),
recipients,
referrers,
keyManagers,
purchaseData,
],
},
}

const routes: CrossChainRoute[] = (
await Promise.all(
Object.values(networks)
.filter((network) => {
return !network.isTestNetwork && network.id !== lock.network
})
.map(async (network): Promise<CrossChainRoute | undefined> => {
BoxChains.filter((boxChain: BoxChainInfo) => {
if (
boxChain.id === lock.network &&
(!lock.currencyContractAddress ||
lock.currencyContractAddress === ADDRESS_ZERO)
) {
return false // Not checking the chain's lock.
}
const network = networks[boxChain.id]
return !!network && !network.isTestNetwork
}).map(
async (
boxChain: BoxChainInfo
): Promise<CrossChainRoute | undefined> => {
const network = networks[boxChain.id]
const query = JSON.stringify(
{
...actionRequest,
Expand Down Expand Up @@ -141,7 +158,8 @@ export const getCrossChainRoutes = async ({
} as CrossChainRoute
}
return
})
}
)
)
).filter<CrossChainRoute>(
(route: CrossChainRoute | undefined): route is CrossChainRoute => {
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6176,6 +6176,18 @@ __metadata:
languageName: node
linkType: hard

"@decent.xyz/box-common@npm:2.0.24":
version: 2.0.24
resolution: "@decent.xyz/box-common@npm:2.0.24"
peerDependencies:
"@wagmi/core": ^1.0.0
react: ^18.0.0
viem: ^1.0.0
wagmi: ^1.0.0
checksum: 10/41aa911a0d14182edb4440ceecb2ac8c4a28e0db3eed3d7bd0a7dfd32240709a42d8612ea43dadb7851c96a4d4cbcf17696831d6d2dc56e96d638135169ed184
languageName: node
linkType: hard

"@dependents/detective-less@npm:^4.1.0":
version: 4.1.0
resolution: "@dependents/detective-less@npm:4.1.0"
Expand Down Expand Up @@ -19985,6 +19997,7 @@ __metadata:
dependencies:
"@airstack/airstack-react": "npm:0.6.3"
"@crossmint/client-sdk-react-ui": "npm:1.1.9"
"@decent.xyz/box-common": "npm:2.0.24"
"@enzoferey/ethers-error-parser": "npm:0.2.3"
"@guildxyz/sdk": "npm:1.1.1"
"@headlessui/react": "npm:1.7.19"
Expand Down

0 comments on commit 8e8e837

Please sign in to comment.