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

173 update app implementations and abis for slippage parameter #9336

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
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: '0x6b118c6efa258903939ed981e6f644330effebab',
lpBondingCurve: '0x24634Cc9A0606b7927B3Fb44b782003B604dDDC4',
chainId: 84532,
},
[ValidChains.Blast]: {
Expand Down
19 changes: 8 additions & 11 deletions libs/shared/src/commonProtocol/contractHelpers/Launchpad.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const lpHook = '';

export const launchToken = async (
// eslint-disable-next-line @typescript-eslint/no-explicit-any
contract: any,
Expand All @@ -10,7 +8,7 @@ export const launchToken = async (
totalSupply: number,
walletAddress: string,
) => {
const txReceipt = await contract.mehtods
const txReceipt = await contract.methods
.launchTokenWithLiquidity(
name,
symbol,
Expand All @@ -19,8 +17,8 @@ export const launchToken = async (
totalSupply,
0,
0,
lpHook,
'',
'0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000',
)
.send({ from: walletAddress });
return txReceipt;
Expand All @@ -33,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,
});
Expand All @@ -47,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;
};
Expand Down Expand Up @@ -87,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,
Expand All @@ -97,7 +94,7 @@ export const transferLiquidity = async (
);

const txReceipt = await contract.methods
.transferLiquidity(tokenAddress)
.transferLiquidity(tokenAddress, remainingTokens)
.send({ value: amountIn, from: walletAddress });
return txReceipt;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
export const LpBondingCurve = [
{
inputs: [
{ internalType: 'address', name: 'tokenAddress', type: 'address' },
{ internalType: 'uint256', name: 'minAmountOut', type: 'uint256' },
],
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' },
{ internalType: 'uint256', name: 'minAmountOut', 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' },
{ 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' }],
},
];
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
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) {
Expand All @@ -23,12 +44,13 @@ 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
// 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,
);
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 @@ -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,
);

Expand Down
Loading