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

[ERC20 Launchpad] - Token Signature Signing step #9320

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
4 changes: 4 additions & 0 deletions libs/shared/src/commonProtocol/chainConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const factoryContracts: {
[key in ValidChains]: {
factory: string;
communityStake: string;
launchpad?: string;
lpBondingCurve?: string;
chainId: number;
};
} = {
Expand All @@ -31,6 +33,8 @@ export const factoryContracts: {
[ValidChains.SepoliaBase]: {
factory: '0xD8a357847cABA76133D5f2cB51317D3C74609710',
communityStake: '0xd097926d8765A7717206559E7d19EECCbBa68c18',
launchpad: '0x5045238a20f07acb34dd1265bb240eab8c8db7a9',
lpBondingCurve: '0x8E506c3D1Ba9e0c00B1f0bC6C3457bbfB1Fe6464',
chainId: 84532,
},
[ValidChains.Blast]: {
Expand Down
16 changes: 7 additions & 9 deletions libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
const lpHook = '';

export const launchToken = async (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
contract: any,
name: string,
symbol: string,
shares: number[],
holders: string[],
totalSupply: number,
totalSupply: string,
walletAddress: string,
) => {
const txReceipt = await contract.mehtods
const txReceipt = await contract.methods
.launchTokenWithLiquidity(
name,
symbol,
shares,
holders,
totalSupply,
1,
0,
0,
lpHook,
'',
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
)
.send({ from: walletAddress });
.send({ from: walletAddress, value: 0.00011e18 });
return txReceipt;
};

Expand All @@ -47,7 +45,7 @@ export const sellToken = async (
amount: number,
walletAddress: string,
) => {
const txReceipt = await contract.mehthods
const txReceipt = await contract.methhods
.sellToken(tokenAddress, amount)
.send({ from: walletAddress });
return txReceipt;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
export const LpBondingCurve = [
{
inputs: [
{ internalType: 'address', name: 'tokenAddress', type: 'address' },
],
stateMutability: 'payable',
type: 'function',
name: 'buyToken',
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
},
{
inputs: [
{ internalType: 'address', name: 'tokenAddress', type: 'address' },
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
],
stateMutability: 'payable',
type: 'function',
name: 'sellToken',
},
{
type: 'function',
name: 'getPrice',
inputs: [
{ name: 'tokenAddress', type: 'address', internalType: 'address' },
{ name: 'amountIn', type: 'uint256', internalType: 'uint256' },
{ name: 'isBuy', type: 'bool', internalType: 'bool' },
],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
{
inputs: [
{ internalType: 'address', name: 'tokenAddress', type: 'address' },
],
stateMutability: 'view',
type: 'function',
name: '_getFloatingTokenSupply',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
},
{
inputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
name: 'liquidity',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
},
{
type: 'function',
name: '_launchpadLiquidity',
inputs: [
{ name: 'tokenAddress', type: 'address', internalType: 'address' },
],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'transferLiquidity',
inputs: [
{ name: 'tokenAddress', type: 'address', internalType: 'address' },
],
outputs: [],
stateMutability: 'payable',
},
];
Original file line number Diff line number Diff line change
@@ -1,34 +1,61 @@
import { Contract } from 'web3';
import { AbiItem } from 'web3-utils';
import {
buyToken,
getPrice,
launchToken,
sellToken,
transferLiquidity,
} from '../../../../../../libs/shared/src/commonProtocol';
import { LpBondingCurve } from './Abi/LpBondingCurveAbi';
import ContractBase from './ContractBase';

const LPBondingCurveAbi = {};
import { LaunchpadFactory } from './LaunchpadFactoryAbi';

class LaunchpadBondingCurve extends ContractBase {
tokenAddress: string;
launchpadFactoryAddress: string;
launchpadFactory: Contract<typeof LaunchpadFactory>;

constructor(bondingCurveAddress: string, tokenAddress: string, rpc: string) {
super(bondingCurveAddress, LPBondingCurveAbi, rpc);
constructor(
bondingCurveAddress: string,
launchpadFactoryAddress: string,
tokenAddress: string,
rpc: string,
) {
super(bondingCurveAddress, LpBondingCurve, rpc);
this.tokenAddress = tokenAddress;
this.launchpadFactoryAddress = launchpadFactoryAddress;
}

async initialize(
withWallet?: boolean,
chainId?: string | undefined,
): Promise<void> {
await super.initialize(withWallet, chainId);
this.launchpadFactory = new this.web3.eth.Contract(
LaunchpadFactory as AbiItem[],
this.launchpadFactoryAddress,
) as unknown as Contract<typeof LaunchpadFactory>;
}

async launchToken(name: string, symbol: string, walletAddress: string) {
async launchToken(
name: string,
symbol: string,
walletAddress: string,
chainId: string,
) {
if (!this.initialized || !this.walletEnabled) {
await this.initialize(true);
await this.initialize(true, chainId);
}

const txReceipt = await launchToken(
this.contract,
this.launchpadFactory,
name,
symbol,
[], // TODO 9207: where do shares come from?
[], // TODO 9207: where do holders come from?
0, // TODO 9207: where does totalSupply come from?
[7000, 1250, 1000, 750], // 9181 parameters
// should include at community treasury at [0] and contest creation util at [1] curr tbd
[walletAddress, walletAddress],
this.web3.utils.toWei(1e9, 'ether'), // Default 1B tokens
walletAddress,
);
return txReceipt;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const LaunchpadFactory = [
{
type: 'function',
name: 'launchTokenWithLiquidity',
inputs: [
{ name: 'name', type: 'string', internalType: 'string' },
{ name: 'symbol', type: 'string', internalType: 'string' },
{ name: 'shares', type: 'uint256[]', internalType: 'uint256[]' },
{ name: 'holders', type: 'address[]', internalType: 'address[]' },
{ name: 'totalSupply', type: 'uint256', internalType: 'uint256' },
{ name: 'curveId', type: 'uint256', internalType: 'uint256' },
{ name: 'scalar', type: 'uint256', internalType: 'uint256' },
{ name: 'lphook', type: 'address', internalType: 'address' },
{ name: 'launchAction', type: 'address', internalType: 'address' },
],
outputs: [],
stateMutability: 'payable',
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ const launchToken = async ({
walletAddress,
}: LaunchTokenProps) => {
const launchPad = new LaunchpadBondingCurve(
commonProtocol.factoryContracts[ethChainId].lpBondingCurve,
commonProtocol.factoryContracts[ethChainId].launchpad,
'',
commonProtocol.factoryContracts[ethChainId].factory,
chainRpc,
);

return await launchPad.launchToken(name, symbol, walletAddress);
return await launchPad.launchToken(
name,
symbol,
walletAddress,
`${ethChainId}`,
);
};

const useLaunchTokenMutation = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@ import useAppStatus from '../../../hooks/useAppStatus';
import { useBrowserAnalyticsTrack } from '../../../hooks/useBrowserAnalyticsTrack';
import './LaunchToken.scss';
import CommunityInformationStep from './steps/CommunityInformationStep';
import SignatureStep from './steps/SignatureStep';
import TokenInformationStep from './steps/TokenInformationStep';
import useCreateCommunity from './useCreateCommunity';
import { CreateTokenCommunityStep, getFormSteps } from './utils';

const LaunchToken = () => {
const navigate = useCommonNavigate();
const {
baseNode,
createTokenCommunityStep,
onChangeStep,
createdTokenInfo,
draftTokenInfo,
selectedAddress,
setSelectedAddress,
setCreatedTokenInfo,
setDraftTokenInfo,
createdCommunityId,
setCreatedCommunityId,
} = useCreateCommunity();

const { isAddedToHomeScreen } = useAppStatus();
Expand All @@ -41,7 +45,7 @@ const LaunchToken = () => {
<TokenInformationStep
handleGoBack={() => navigate('/')} // redirect to home
handleContinue={(tokenInfo) => {
setCreatedTokenInfo({
setDraftTokenInfo({
name: tokenInfo.tokenName,
symbol: tokenInfo.tokenTicker,
description: tokenInfo.tokenDescription,
Expand All @@ -58,14 +62,29 @@ const LaunchToken = () => {
return (
<CommunityInformationStep
handleGoBack={() => onChangeStep(false)}
handleContinue={() => onChangeStep(true)}
tokenInfo={createdTokenInfo}
handleContinue={(communityId) => {
setCreatedCommunityId(communityId);

onChangeStep(true);
}}
tokenInfo={draftTokenInfo}
selectedAddress={selectedAddress}
/>
);
case CreateTokenCommunityStep.SignatureLaunch:
// TODO: https://github.com/hicommonwealth/commonwealth/issues/8707
return <>Not Implemented</>;
// this condition will never be triggered, adding this to avoid typescript errors
if (!createdCommunityId || !selectedAddress || !draftTokenInfo)
return <></>;

return (
<SignatureStep
createdCommunityId={createdCommunityId}
baseNode={baseNode}
tokenInfo={draftTokenInfo}
goToSuccessStep={() => {}} // TODO 8707: show success screen here - create ticket
selectedAddress={selectedAddress}
/>
);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { generateCommunityNameFromToken } from './utils';

interface CommunityInformationStepProps {
handleGoBack: () => void;
handleContinue: () => void;
handleContinue: (communityId: string) => void;
tokenInfo?: TokenInfo;
selectedAddress?: AddressInfo;
}
Expand Down Expand Up @@ -68,7 +68,7 @@ const CommunityInformationStep = ({

const nodes = fetchCachedNodes();
const baseNode = nodes?.find(
(n) => n.ethChainId === commonProtocol.ValidChains.Base,
(n) => n.ethChainId === commonProtocol.ValidChains.SepoliaBase,
);
if (!baseNode || !baseNode.ethChainId) {
notifyError('Could not find base chain node');
Expand All @@ -84,12 +84,11 @@ const CommunityInformationStep = ({
iconUrl: values.communityProfileImageURL,
socialLinks: values.links ?? [],
userAddress: selectedAddress.address,
chainNodeId: baseNode.ethChainId,
chainNodeId: baseNode.id,
isPWA: isAddedToHomeScreen,
tokenName: tokenInfo?.name || '',
});
await createCommunityMutation(input);
handleContinue();
handleContinue(values.communityId);
} catch (err) {
notifyError(err.message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@import '../../../../../../../styles/shared';

$form-width: 596px;

.SignTokenTransactions {
display: flex;

.header {
margin-top: 8px;
width: 100%;
display: flex;
gap: 16px;
flex-direction: column;
max-width: 596px;
margin-right: 110px;

@include smallInclusive {
margin-right: unset;
}

.description {
color: $neutral-500;
}

.Divider {
margin-block: 8px;
}

.action-buttons {
display: flex;
justify-content: space-between;
}
}

.CWBanner {
display: flex !important;
max-width: $form-width !important;

.content-container {
max-width: calc($form-width - 70px) !important;
}
}
}
Loading
Loading