From ad2b5e22fcfee9111e58dcebf015bfa950a26969 Mon Sep 17 00:00:00 2001 From: ianrowan Date: Tue, 17 Sep 2024 15:28:43 -0500 Subject: [PATCH 1/9] update token launch impl --- libs/shared/src/commonProtocol/chainConfig.ts | 2 ++ .../contractHelpers/Launchpad.ts | 3 --- .../helpers/ContractHelpers/Launchpad.ts | 21 ++++++++++++++----- .../state/api/launchPad/launchToken.ts | 3 ++- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/libs/shared/src/commonProtocol/chainConfig.ts b/libs/shared/src/commonProtocol/chainConfig.ts index 514c676f331..a5b0f668e0a 100644 --- a/libs/shared/src/commonProtocol/chainConfig.ts +++ b/libs/shared/src/commonProtocol/chainConfig.ts @@ -20,6 +20,8 @@ export const factoryContracts: { [key in ValidChains]: { factory: string; communityStake: string; + launchpad?: string; + lpBondingCurve?: string; chainId: number; }; } = { diff --git a/libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts b/libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts index e6407520eff..0ce746ae043 100644 --- a/libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts +++ b/libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts @@ -1,5 +1,3 @@ -const lpHook = ''; - export const launchToken = async ( // eslint-disable-next-line @typescript-eslint/no-explicit-any contract: any, @@ -19,7 +17,6 @@ export const launchToken = async ( totalSupply, 0, 0, - lpHook, '', ) .send({ from: walletAddress }); diff --git a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts index 6016bbf5e64..bb1bf21a1b4 100644 --- a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts +++ b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts @@ -1,3 +1,4 @@ +import { Contract } from 'web3'; import { buyToken, getPrice, @@ -11,10 +12,20 @@ const LPBondingCurveAbi = {}; class LaunchpadBondingCurve extends ContractBase { tokenAddress: string; + launchpadFactory: Contract; - constructor(bondingCurveAddress: string, tokenAddress: string, rpc: string) { + constructor( + bondingCurveAddress: string, + launchpadFactoryAddress: string, + tokenAddress: string, + rpc: string, + ) { super(bondingCurveAddress, LPBondingCurveAbi, rpc); this.tokenAddress = tokenAddress; + this.launchpadFactory = new this.web3.eth.Contract( + lpFactoryAbi, + launchpadFactoryAddress, + ); } async launchToken(name: string, symbol: string, walletAddress: string) { @@ -23,12 +34,12 @@ class LaunchpadBondingCurve extends ContractBase { } 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, 1500, 750], // 9181 parameters + [walletAddress, walletAddress], // should include at community treasury at [0] and contest creation util at [1] curr tbd + 1_000_000_000e18, // Default 1B tokens walletAddress, ); return txReceipt; diff --git a/packages/commonwealth/client/scripts/state/api/launchPad/launchToken.ts b/packages/commonwealth/client/scripts/state/api/launchPad/launchToken.ts index 75710d1b5c2..7adc0f725be 100644 --- a/packages/commonwealth/client/scripts/state/api/launchPad/launchToken.ts +++ b/packages/commonwealth/client/scripts/state/api/launchPad/launchToken.ts @@ -19,7 +19,8 @@ const launchToken = async ({ }: LaunchTokenProps) => { const launchPad = new LaunchpadBondingCurve( '', - commonProtocol.factoryContracts[ethChainId].factory, + commonProtocol.factoryContracts[ethChainId].lpBondingCurve, + commonProtocol.factoryContracts[ethChainId].launchpad, chainRpc, ); From b7e8c2b5e5bb269dd4fc91478ee344bc7d10f223 Mon Sep 17 00:00:00 2001 From: ianrowan Date: Wed, 18 Sep 2024 14:15:36 -0500 Subject: [PATCH 2/9] All required variables --- libs/shared/src/commonProtocol/chainConfig.ts | 2 + .../ContractHelpers/Abi/LpBondingCurveAbi.ts | 65 +++++++++++++++++++ .../helpers/ContractHelpers/Launchpad.ts | 8 +-- .../ContractHelpers/LaunchpadFactoryAbi.ts | 19 ++++++ 4 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/LpBondingCurveAbi.ts create mode 100644 packages/commonwealth/client/scripts/helpers/ContractHelpers/LaunchpadFactoryAbi.ts diff --git a/libs/shared/src/commonProtocol/chainConfig.ts b/libs/shared/src/commonProtocol/chainConfig.ts index a5b0f668e0a..c97ca06444b 100644 --- a/libs/shared/src/commonProtocol/chainConfig.ts +++ b/libs/shared/src/commonProtocol/chainConfig.ts @@ -33,6 +33,8 @@ export const factoryContracts: { [ValidChains.SepoliaBase]: { factory: '0xD8a357847cABA76133D5f2cB51317D3C74609710', communityStake: '0xd097926d8765A7717206559E7d19EECCbBa68c18', + launchpad: '0x5045238a20f07acb34dd1265bb240eab8c8db7a9', + lpBondingCurve: '0x7Cc4d8902e3Ca342825D35b9C4ddb064582a910d', chainId: 84532, }, [ValidChains.Blast]: { diff --git a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/LpBondingCurveAbi.ts b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/LpBondingCurveAbi.ts new file mode 100644 index 00000000000..efdc1df411b --- /dev/null +++ b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/LpBondingCurveAbi.ts @@ -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', + }, +]; diff --git a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts index bb1bf21a1b4..52e57b2eb6e 100644 --- a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts +++ b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts @@ -6,9 +6,9 @@ import { 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; @@ -20,10 +20,10 @@ class LaunchpadBondingCurve extends ContractBase { tokenAddress: string, rpc: string, ) { - super(bondingCurveAddress, LPBondingCurveAbi, rpc); + super(bondingCurveAddress, LpBondingCurve, rpc); this.tokenAddress = tokenAddress; this.launchpadFactory = new this.web3.eth.Contract( - lpFactoryAbi, + LaunchpadFactory, launchpadFactoryAddress, ); } diff --git a/packages/commonwealth/client/scripts/helpers/ContractHelpers/LaunchpadFactoryAbi.ts b/packages/commonwealth/client/scripts/helpers/ContractHelpers/LaunchpadFactoryAbi.ts new file mode 100644 index 00000000000..21b0f2a34a3 --- /dev/null +++ b/packages/commonwealth/client/scripts/helpers/ContractHelpers/LaunchpadFactoryAbi.ts @@ -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', + }, +]; From 979be8c7894521c185cc393e78f378734b80a6e5 Mon Sep 17 00:00:00 2001 From: ianrowan Date: Wed, 18 Sep 2024 14:16:47 -0500 Subject: [PATCH 3/9] hardcode lp hook --- libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts b/libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts index 0ce746ae043..892c16ce293 100644 --- a/libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts +++ b/libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts @@ -17,7 +17,7 @@ export const launchToken = async ( totalSupply, 0, 0, - '', + '0x12a35d50a7a12e92063e19d90186c95a10e3e311', ) .send({ from: walletAddress }); return txReceipt; From 404b572570e8c3d39369b43f15161790c17cc7b8 Mon Sep 17 00:00:00 2001 From: ianrowan Date: Thu, 19 Sep 2024 14:02:10 -0500 Subject: [PATCH 4/9] fix lint issues --- .../client/scripts/helpers/ContractHelpers/Launchpad.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts index 52e57b2eb6e..8c647b4576b 100644 --- a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts +++ b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts @@ -1,4 +1,5 @@ -import { Contract } from 'web3'; +import { Contract } from 'web3-eth-contract'; +import { AbiItem } from 'web3-utils'; import { buyToken, getPrice, @@ -12,7 +13,7 @@ import { LaunchpadFactory } from './LaunchpadFactoryAbi'; class LaunchpadBondingCurve extends ContractBase { tokenAddress: string; - launchpadFactory: Contract; + launchpadFactory: Contract; constructor( bondingCurveAddress: string, @@ -23,9 +24,9 @@ class LaunchpadBondingCurve extends ContractBase { super(bondingCurveAddress, LpBondingCurve, rpc); this.tokenAddress = tokenAddress; this.launchpadFactory = new this.web3.eth.Contract( - LaunchpadFactory, + LaunchpadFactory as AbiItem[], launchpadFactoryAddress, - ); + ) as unknown as Contract; } async launchToken(name: string, symbol: string, walletAddress: string) { From cd525ab955494a9db2994d3c32887a2b570896d5 Mon Sep 17 00:00:00 2001 From: ianrowan Date: Thu, 19 Sep 2024 14:05:44 -0500 Subject: [PATCH 5/9] fix lint --- .../client/scripts/helpers/ContractHelpers/Launchpad.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts index 8c647b4576b..6d7709b1d3b 100644 --- a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts +++ b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts @@ -39,7 +39,8 @@ class LaunchpadBondingCurve extends ContractBase { name, symbol, [7000, 1250, 1500, 750], // 9181 parameters - [walletAddress, walletAddress], // should include at community treasury at [0] and contest creation util at [1] curr tbd + // should include at community treasury at [0] and contest creation util at [1] curr tbd + [walletAddress, walletAddress], 1_000_000_000e18, // Default 1B tokens walletAddress, ); From 5be617b894e2325e02fc1b9d0afa47c9f841787d Mon Sep 17 00:00:00 2001 From: ianrowan Date: Thu, 19 Sep 2024 14:12:27 -0500 Subject: [PATCH 6/9] type fix --- .../client/scripts/helpers/ContractHelpers/Launchpad.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts index 6d7709b1d3b..561c153515f 100644 --- a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts +++ b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts @@ -1,4 +1,4 @@ -import { Contract } from 'web3-eth-contract'; +import { Contract } from 'web3'; import { AbiItem } from 'web3-utils'; import { buyToken, From c89c3e47c9ce17ab4e1775e94fc5ed4ec921b7ac Mon Sep 17 00:00:00 2001 From: ianrowan Date: Wed, 25 Sep 2024 10:10:58 -0500 Subject: [PATCH 7/9] fix initializaiton logic --- .../scripts/helpers/ContractHelpers/Launchpad.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts index 561c153515f..85ea6cda7cd 100644 --- a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts +++ b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Launchpad.ts @@ -13,6 +13,7 @@ import { LaunchpadFactory } from './LaunchpadFactoryAbi'; class LaunchpadBondingCurve extends ContractBase { tokenAddress: string; + launchpadFactoryAddress: string; launchpadFactory: Contract; constructor( @@ -23,9 +24,17 @@ class LaunchpadBondingCurve extends ContractBase { ) { super(bondingCurveAddress, LpBondingCurve, rpc); this.tokenAddress = tokenAddress; + this.launchpadFactoryAddress = launchpadFactoryAddress; + } + + async initialize( + withWallet?: boolean, + chainId?: string | undefined, + ): Promise { + await super.initialize(withWallet, chainId); this.launchpadFactory = new this.web3.eth.Contract( LaunchpadFactory as AbiItem[], - launchpadFactoryAddress, + this.launchpadFactoryAddress, ) as unknown as Contract; } From 5f0f6059d26cfd187c42b3c2d0f8eb20c7eff15d Mon Sep 17 00:00:00 2001 From: ianrowan Date: Wed, 25 Sep 2024 14:47:48 -0500 Subject: [PATCH 8/9] update abis and implementations --- .../commonProtocol/contractHelpers/Launchpad.ts | 16 ++++++++-------- .../ContractHelpers/Abi/LpBondingCurveAbi.ts | 12 ++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts b/libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts index 892c16ce293..6249d0e56f9 100644 --- a/libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts +++ b/libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts @@ -8,7 +8,7 @@ export const launchToken = async ( totalSupply: number, walletAddress: string, ) => { - const txReceipt = await contract.mehtods + const txReceipt = await contract.methods .launchTokenWithLiquidity( name, symbol, @@ -17,7 +17,8 @@ export const launchToken = async ( totalSupply, 0, 0, - '0x12a35d50a7a12e92063e19d90186c95a10e3e311', + '0x0000000000000000000000000000000000000000', + '0x0000000000000000000000000000000000000000', ) .send({ from: walletAddress }); return txReceipt; @@ -30,7 +31,7 @@ export const buyToken = async ( walletAddress: string, value: number, ) => { - const txReceipt = await contract.methods.buyToken(tokenAddress).send({ + const txReceipt = await contract.methods.buyToken(tokenAddress, 0).send({ from: walletAddress, value, }); @@ -44,8 +45,8 @@ export const sellToken = async ( amount: number, walletAddress: string, ) => { - const txReceipt = await contract.mehthods - .sellToken(tokenAddress, amount) + const txReceipt = await contract.methods + .sellToken(tokenAddress, amount, 0) .send({ from: walletAddress }); return txReceipt; }; @@ -84,8 +85,7 @@ export const transferLiquidity = async ( tokenAddress: string, walletAddress: string, ) => { - const remainingTokens = - await contract.methods._launchpadLiquidity(tokenAddress); + const remainingTokens = await contract.methods._poolLiquidity(tokenAddress); const amountIn = await getAmountIn( contract, tokenAddress, @@ -94,7 +94,7 @@ export const transferLiquidity = async ( ); const txReceipt = await contract.methods - .transferLiquidity(tokenAddress) + .transferLiquidity(tokenAddress, remainingTokens) .send({ value: amountIn, from: walletAddress }); return txReceipt; }; diff --git a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/LpBondingCurveAbi.ts b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/LpBondingCurveAbi.ts index efdc1df411b..ce0d551a39d 100644 --- a/packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/LpBondingCurveAbi.ts +++ b/packages/commonwealth/client/scripts/helpers/ContractHelpers/Abi/LpBondingCurveAbi.ts @@ -2,6 +2,7 @@ export const LpBondingCurve = [ { inputs: [ { internalType: 'address', name: 'tokenAddress', type: 'address' }, + { internalType: 'uint256', name: 'minAmountOut', type: 'uint256' }, ], stateMutability: 'payable', type: 'function', @@ -12,6 +13,7 @@ export const LpBondingCurve = [ inputs: [ { internalType: 'address', name: 'tokenAddress', type: 'address' }, { internalType: 'uint256', name: 'amount', type: 'uint256' }, + { internalType: 'uint256', name: 'minAmountOut', type: 'uint256' }, ], stateMutability: 'payable', type: 'function', @@ -58,8 +60,18 @@ export const LpBondingCurve = [ name: 'transferLiquidity', inputs: [ { name: 'tokenAddress', type: 'address', internalType: 'address' }, + { name: 'minAmountOut', type: 'uint256', internalType: 'uint256' }, ], outputs: [], stateMutability: 'payable', }, + { + inputs: [ + { internalType: 'address', name: 'tokenAddress', type: 'address' }, + ], + stateMutability: 'view', + type: 'function', + name: '_poolLiquidity', + outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }], + }, ]; From d6a7439ebd99732551c997b872291359df20ddf0 Mon Sep 17 00:00:00 2001 From: ianrowan Date: Wed, 25 Sep 2024 15:02:36 -0500 Subject: [PATCH 9/9] update with new contracts --- libs/shared/src/commonProtocol/chainConfig.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/shared/src/commonProtocol/chainConfig.ts b/libs/shared/src/commonProtocol/chainConfig.ts index c97ca06444b..07999cb6afd 100644 --- a/libs/shared/src/commonProtocol/chainConfig.ts +++ b/libs/shared/src/commonProtocol/chainConfig.ts @@ -33,8 +33,8 @@ export const factoryContracts: { [ValidChains.SepoliaBase]: { factory: '0xD8a357847cABA76133D5f2cB51317D3C74609710', communityStake: '0xd097926d8765A7717206559E7d19EECCbBa68c18', - launchpad: '0x5045238a20f07acb34dd1265bb240eab8c8db7a9', - lpBondingCurve: '0x7Cc4d8902e3Ca342825D35b9C4ddb064582a910d', + launchpad: '0x6b118c6efa258903939ed981e6f644330effebab', + lpBondingCurve: '0x24634Cc9A0606b7927B3Fb44b782003B604dDDC4', chainId: 84532, }, [ValidChains.Blast]: {