Skip to content

Commit

Permalink
Merge pull request #9876 from hicommonwealth/tim/transfer-liquidity-t…
Browse files Browse the repository at this point in the history
…o-uniswap
  • Loading branch information
timolegros authored Nov 14, 2024
2 parents 94a4e5b + 555619e commit 113e3b7
Show file tree
Hide file tree
Showing 7 changed files with 444 additions and 21 deletions.
343 changes: 343 additions & 0 deletions libs/model/src/services/commonProtocol/abi/LPBondingCurve.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,343 @@
export const LPBondingCurveAbi = [
{
type: 'constructor',
inputs: [
{
name: '_protocolFeeDestination',
type: 'address',
internalType: 'address',
},
{ name: '_launchpad', type: 'address', internalType: 'address' },
{
name: '_protocolFeePercent',
type: 'uint256',
internalType: 'uint256',
},
{ name: '_LPCurveManager', type: 'address', internalType: 'address' },
{
name: '_curveActionHook',
type: 'address',
internalType: 'address',
},
],
stateMutability: 'nonpayable',
},
{
type: 'function',
name: 'LPCurveManager',
inputs: [],
outputs: [{ name: '', type: 'address', internalType: 'address' }],
stateMutability: 'view',
},
{
type: 'function',
name: '_getFloatingTokenSupply',
inputs: [
{ name: 'tokenAddress', type: 'address', internalType: 'address' },
],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: '_getTotalTokenSupply',
inputs: [
{ name: 'tokenAddress', type: 'address', internalType: 'address' },
],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: '_isFunded',
inputs: [
{ name: 'tokenAddress', type: 'address', internalType: 'address' },
],
outputs: [{ name: '', type: 'bool', internalType: 'bool' }],
stateMutability: 'view',
},
{
type: 'function',
name: '_launchpadLiquidity',
inputs: [
{ name: 'tokenAddress', type: 'address', internalType: 'address' },
],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: '_poolLiquidity',
inputs: [
{ name: 'tokenAddress', type: 'address', internalType: 'address' },
],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'buyToken',
inputs: [
{ name: 'tokenAddress', type: 'address', internalType: 'address' },
{
name: 'minAmountOut',
type: 'uint256',
internalType: 'uint256',
},
],
outputs: [{ name: '', type: 'bool', internalType: 'bool' }],
stateMutability: 'payable',
},
{
type: 'function',
name: 'curveActionHook',
inputs: [],
outputs: [
{ name: '', type: 'address', internalType: 'contract ICurveActionHook' },
],
stateMutability: 'view',
},
{
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',
},
{
type: 'function',
name: 'launchpad',
inputs: [],
outputs: [{ name: '', type: 'address', internalType: 'address' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'liquidity',
inputs: [{ name: '', type: 'address', internalType: 'address' }],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'protocolFeeDestination',
inputs: [],
outputs: [{ name: '', type: 'address', internalType: 'address' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'protocolFeePercent',
inputs: [],
outputs: [{ name: '', type: 'uint256', internalType: 'uint256' }],
stateMutability: 'view',
},
{
type: 'function',
name: 'registerToken',
inputs: [
{
name: 'params',
type: 'tuple',
internalType: 'struct LPBondingCurve.RegisterTokenParams',
components: [
{ name: '_tokenAddress', type: 'address', internalType: 'address' },
{
name: '_curveId',
type: 'uint256',
internalType: 'uint256',
},
{ name: '_scalar', type: 'uint256', internalType: 'uint256' },
{
name: '_reserveRatio',
type: 'uint32',
internalType: 'uint32',
},
{ name: 'totalSupply', type: 'uint256', internalType: 'uint256' },
{
name: 'holders',
type: 'address[]',
internalType: 'address[]',
},
{ name: 'shares', type: 'uint256[]', internalType: 'uint256[]' },
{
name: 'LPHook',
type: 'address',
internalType: 'address',
},
],
},
],
outputs: [],
stateMutability: 'payable',
},
{
type: 'function',
name: 'sellToken',
inputs: [
{ name: 'tokenAddress', type: 'address', internalType: 'address' },
{
name: 'amount',
type: 'uint256',
internalType: 'uint256',
},
{ name: 'minAmountOut', type: 'uint256', internalType: 'uint256' },
],
outputs: [],
stateMutability: 'payable',
},
{
type: 'function',
name: 'tokens',
inputs: [{ name: '', type: 'address', internalType: 'address' }],
outputs: [
{ name: 'launchpadLiquidity', type: 'uint256', internalType: 'uint256' },
{
name: 'poolLiquidity',
type: 'uint256',
internalType: 'uint256',
},
{ name: 'curveId', type: 'uint256', internalType: 'uint256' },
{
name: 'scalar',
type: 'uint256',
internalType: 'uint256',
},
{ name: 'reserveRatio', type: 'uint32', internalType: 'uint32' },
{
name: 'LPhook',
type: 'address',
internalType: 'address',
},
{ name: 'funded', type: 'bool', internalType: 'bool' },
],
stateMutability: 'view',
},
{
type: 'function',
name: 'transferLiquidity',
inputs: [
{ name: 'tokenAddress', type: 'address', internalType: 'address' },
{
name: 'minAmountOut',
type: 'uint256',
internalType: 'uint256',
},
],
outputs: [],
stateMutability: 'payable',
},
{
type: 'event',
name: 'LiquidityTransferred',
inputs: [
{
name: 'tokenAddress',
type: 'address',
indexed: true,
internalType: 'address',
},
{
name: 'LPHook',
type: 'address',
indexed: false,
internalType: 'address',
},
{
name: 'tokensTransferred',
type: 'uint256',
indexed: false,
internalType: 'uint256',
},
{
name: 'liquidityTransferred',
type: 'uint256',
indexed: false,
internalType: 'uint256',
},
],
anonymous: false,
},
{
type: 'event',
name: 'TokenRegistered',
inputs: [
{
name: 'token',
type: 'address',
indexed: false,
internalType: 'address',
},
{
name: 'curveId',
type: 'uint256',
indexed: false,
internalType: 'uint256',
},
{
name: 'totalSupply',
type: 'uint256',
indexed: false,
internalType: 'uint256',
},
],
anonymous: false,
},
{
type: 'event',
name: 'Trade',
inputs: [
{
name: 'trader',
type: 'address',
indexed: false,
internalType: 'address',
},
{
name: 'namespace',
type: 'address',
indexed: false,
internalType: 'address',
},
{
name: 'isBuy',
type: 'bool',
indexed: false,
internalType: 'bool',
},
{
name: 'communityTokenAmount',
type: 'uint256',
indexed: false,
internalType: 'uint256',
},
{
name: 'ethAmount',
type: 'uint256',
indexed: false,
internalType: 'uint256',
},
{
name: 'protocolEthAmount',
type: 'uint256',
indexed: false,
internalType: 'uint256',
},
{
name: 'floatingSupply',
type: 'uint256',
indexed: false,
internalType: 'uint256',
},
],
anonymous: false,
},
];
19 changes: 1 addition & 18 deletions libs/model/src/services/commonProtocol/contestHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { commonProtocol } from '@hicommonwealth/shared';
import { Mutex } from 'async-mutex';
import Web3, { PayableCallOptions } from 'web3';
import { AbiItem } from 'web3-utils';
import { config } from '../../config';
import { contestABI } from './abi/contestAbi';
import { feeManagerABI } from './abi/feeManagerAbi';
import { createWeb3Provider } from './utils';

const nonceMutex = new Mutex();

Expand All @@ -31,23 +31,6 @@ export type ContestScores = {
contestBalance: string;
};

/**
* A helper for creating the web3 provider via an RPC, including private key import
* @param rpc the rpc of the network to use helper with
* @returns
*/
// eslint-disable-next-line @typescript-eslint/require-await
const createWeb3Provider = async (rpc: string): Promise<Web3> => {
if (!config.WEB3.PRIVATE_KEY) throw new AppError('WEB3 private key not set!');
const web3 = new Web3(rpc);
const account = web3.eth.accounts.privateKeyToAccount(
config.WEB3.PRIVATE_KEY,
);
web3.eth.accounts.wallet.add(account);
web3.eth.defaultAccount = account.address;
return web3;
};

/**
* Adds content to an active contest. Includes validation of contest state
* @param rpcNodeUrl the rpc node url
Expand Down
1 change: 1 addition & 0 deletions libs/model/src/services/commonProtocol/contractHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@hicommonwealth/shared';
import Web3 from 'web3';
import { AbiItem } from 'web3-utils';

import { Balances, TokenAttributes, getBalances } from '../tokenBalanceCache';
import { contestABI } from './abi/contestAbi';

Expand Down
1 change: 0 additions & 1 deletion libs/model/src/services/commonProtocol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as contest from './contestHelper';
import * as contract from './contractHelpers';
import * as launchpad from './launchpadHelpers';

// export modules as objects so they can be stubbed in tests
export const communityStakeConfigValidator = { ...stake };
export const contractHelpers = { ...contract };
export const contestHelper = { ...contest };
Expand Down
Loading

0 comments on commit 113e3b7

Please sign in to comment.