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

1155 NFT URI Endpoint and setter + Base deployment config #6694

Merged
merged 8 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
6 changes: 6 additions & 0 deletions libs/core/src/commonProtocol/chainConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Chains with deployed namespace factories. As new chains are enabled, add here.
export enum ValidChains {
Sepolia = 11155111,
Base = 8453,
}

export const STAKE_ID = 2;
Expand All @@ -18,4 +19,9 @@ export const factoryContracts: {
communityStake: '0x377004f12eEE739204D44073F160798235160711',
chainId: 11155111,
},
[ValidChains.Base]: {
jnaviask marked this conversation as resolved.
Show resolved Hide resolved
factory: '0xD656267Af2E41580d47451Df2e6E21f5367CC04D',
communityStake: '0xfef0dEE36609C0B223EEbbC6089356A9D8f5490f',
chainId: 8453,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export const namespaceFactoryAbi = [
name: 'name',
type: 'string',
},
{
internalType: 'string',
name: '_uri',
type: 'string',
},
{
internalType: 'address',
name: '_feeManager',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ class CommunityStakes extends ContractBase {
txReceipt = await this.contract.methods
.buyStake(namespaceAddress, id, amount)
.send({ value: totalPrice, from: walletAddress });
try {
await this.web3.givenProvider.request({
method: 'wallet_watchAsset',
params: {
type: 'ERC1155',
options: {
address: namespaceAddress,
tokenId: id.toString(),
},
},
});
} catch (error) {
console.log('Failed to watch asset in MM, watch manaually', error);
}
} catch {
throw new Error('Transaction failed');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ class NamespaceFactory extends ContractBase {

let txReceipt;
try {
const uri = `${window.location.origin}/api/namespaceMetadata/${name}/{id}`;
txReceipt = await this.contract.methods
.deployNamespace(name, feeManager, [])
.deployNamespace(name, uri, feeManager, [])
.send({ from: walletAddress });
} catch (error) {
throw new Error('Transaction failed: ' + error);
Expand Down Expand Up @@ -134,7 +135,7 @@ class NamespaceFactory extends ContractBase {
name + ' Community Stake',
stakesId,
'0x0000000000000000000000000000000000000000',
16000,
100000000,
mhagel marked this conversation as resolved.
Show resolved Hide resolved
0,
)
.send({ from: walletAddress });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const buyStake = async ({
const CommunityStakes = await lazyLoadCommunityStakes();
const communityStakes = new CommunityStakes(
commonProtocol.factoryContracts[
commonProtocol.ValidChains.Sepolia
commonProtocol.ValidChains.Base
].communityStake,
commonProtocol.factoryContracts[commonProtocol.ValidChains.Sepolia].factory,
commonProtocol.factoryContracts[commonProtocol.ValidChains.Base].factory,
chainRpc,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const getBuyPrice = async ({
const CommunityStakes = await lazyLoadCommunityStakes();
const communityStakes = new CommunityStakes(
commonProtocol.factoryContracts[
commonProtocol.ValidChains.Sepolia
commonProtocol.ValidChains.Base
].communityStake,
commonProtocol.factoryContracts[commonProtocol.ValidChains.Sepolia].factory,
commonProtocol.factoryContracts[commonProtocol.ValidChains.Base].factory,
chainRpc,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const getSellPrice = async ({
const CommunityStakes = await lazyLoadCommunityStakes();
const communityStakes = new CommunityStakes(
commonProtocol.factoryContracts[
commonProtocol.ValidChains.Sepolia
commonProtocol.ValidChains.Base
].communityStake,
commonProtocol.factoryContracts[commonProtocol.ValidChains.Sepolia].factory,
commonProtocol.factoryContracts[commonProtocol.ValidChains.Base].factory,
chainRpc,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const getUserEthBalance = async ({
const CommunityStakes = await lazyLoadCommunityStakes();
const communityStakes = new CommunityStakes(
commonProtocol.factoryContracts[
commonProtocol.ValidChains.Sepolia
commonProtocol.ValidChains.Base
].communityStake,
commonProtocol.factoryContracts[commonProtocol.ValidChains.Sepolia].factory,
commonProtocol.factoryContracts[commonProtocol.ValidChains.Base].factory,
chainRpc,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const getUserStakeBalance = async ({
const CommunityStakes = await lazyLoadCommunityStakes();
const communityStakes = new CommunityStakes(
commonProtocol.factoryContracts[
commonProtocol.ValidChains.Sepolia
commonProtocol.ValidChains.Base
].communityStake,
commonProtocol.factoryContracts[commonProtocol.ValidChains.Sepolia].factory,
commonProtocol.factoryContracts[commonProtocol.ValidChains.Base].factory,
chainRpc,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const sellStake = async ({
const CommunityStakes = await lazyLoadCommunityStakes();
const communityStakes = new CommunityStakes(
commonProtocol.factoryContracts[
commonProtocol.ValidChains.Sepolia
commonProtocol.ValidChains.Base
].communityStake,
commonProtocol.factoryContracts[commonProtocol.ValidChains.Sepolia].factory,
commonProtocol.factoryContracts[commonProtocol.ValidChains.Base].factory,
chainRpc,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const convertEthToUsd = (
};

export const buildEtherscanLink = (txHash: string) => {
const prefix = 'sepolia.';
return `https://${prefix}etherscan.io/tx/${txHash}`;
//const prefix = 'Base.';
return `https://basescan.org/tx/${txHash}`;
};

export const capDecimals = (value: string, capNumber = 8) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import app from 'state';

const useNamespaceFactory = () => {
const goerliFactoryAddress =
commonProtocol.factoryContracts[commonProtocol.ValidChains.Sepolia].factory;
commonProtocol.factoryContracts[commonProtocol.ValidChains.Base].factory;
const chainRpc = app.config.nodes
.getAll()
.find(
(node) => node.ethChainId === commonProtocol.ValidChains.Sepolia,
)?.url;
.find((node) => node.ethChainId === commonProtocol.ValidChains.Base)?.url;
const namespaceFactory = new NamespaceFactory(goerliFactoryAddress, chainRpc);

return { namespaceFactory };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const useCreateCommunity = () => {
].includes(createCommunityStep);
const isEthereumMainnetSelected =
// selectedChainId === ETHEREUM_MAINNET_ID ||
selectedChainId === String(commonProtocol.ValidChains.Sepolia);
selectedChainId === String(commonProtocol.ValidChains.Base);
const showCommunityStakeStep =
isValidStepToShowCommunityStakeFormStep &&
selectedCommunity.type === 'ethereum' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export async function __createCommentReaction(
await commonProtocolService.contractHelpers.getNamespaceBalance(
community.namespace,
stake.stake_id,
commonProtocol.ValidChains.Sepolia,
commonProtocol.ValidChains.Base,
address.address,
this.models,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export async function __createThreadReaction(
await commonProtocolService.contractHelpers.getNamespaceBalance(
community.namespace,
stake.stake_id,
commonProtocol.ValidChains.Sepolia,
commonProtocol.ValidChains.Base,
address.address,
this.models,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { AppError } from '@hicommonwealth/core';
import { DB } from '@hicommonwealth/model';
import { TypedRequestParams } from 'server/types';

export const getNamespaceMetadata = async (
models: DB,
req: TypedRequestParams<{ namespace: string; stake_id: string }>,
res: any,
) => {
//stake_id will be a 32 byte hex string, convert to number
const decodedId = parseInt(req.params.stake_id, 16);
const metadata = await models.Community.findOne({
where: {
namespace: req.params.namespace,
},
include: [
{
model: models.CommunityStake,
required: true,
attributes: ['stake_id'],
where: {
stake_id: decodedId,
},
},
],
attributes: ['namespace', 'icon_url'],
});

if (!metadata) {
throw new AppError('Token metadata does not exist');
}

return res.json({
name: `${metadata.namespace} Community Stake`,
image: metadata.icon_url,
});
};
8 changes: 8 additions & 0 deletions packages/commonwealth/server/routing/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ import { ServerTopicsController } from '../controllers/server_topics_controller'
import { GENERATE_IMAGE_RATE_LIMIT } from 'server/config';
import { rateLimiterMiddleware } from 'server/middleware/rateLimiter';
import { getTopUsersHandler } from 'server/routes/admin/get_top_users_handler';
import { getNamespaceMetadata } from 'server/routes/communities/get_namespace_metadata';
import { getStatsHandler } from '../routes/admin/get_stats_handler';
import { createCommentReactionHandler } from '../routes/comments/create_comment_reaction_handler';
import { deleteBotCommentHandler } from '../routes/comments/delete_comment_bot_handler';
Expand Down Expand Up @@ -368,6 +369,13 @@ function setupRouter(
getCommunityStakeHandler.bind(this, models, serverControllers),
);

registerRoute(
router,
'get',
'/namespaceMetadata/:namespace/:stake_id',
getNamespaceMetadata.bind(this, models),
);

registerRoute(
router,
'post',
Expand Down
Loading