From b8c74a608b1ecf65963b6a3205047fa8ace57745 Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Wed, 20 Nov 2024 20:25:03 +1100 Subject: [PATCH] unrug --- packages/plugin-starknet/package.json | 1 + .../plugin-starknet/src/actions/unruggable.ts | 78 +++++++++++++++---- .../plugin-starknet/src/utils/constants.ts | 8 ++ packages/plugin-starknet/src/utils/index.ts | 40 ++++++++++ pnpm-lock.yaml | 37 ++++++++- 5 files changed, 149 insertions(+), 15 deletions(-) create mode 100644 packages/plugin-starknet/src/utils/constants.ts diff --git a/packages/plugin-starknet/package.json b/packages/plugin-starknet/package.json index 09af3bbf52..129e66f16e 100644 --- a/packages/plugin-starknet/package.json +++ b/packages/plugin-starknet/package.json @@ -8,6 +8,7 @@ "@ai16z/eliza": "workspace:*", "@ai16z/plugin-trustdb": "workspace:*", "@avnu/avnu-sdk": "^2.1.1", + "@uniswap/sdk-core": "^6.0.0", "@unruggable_starknet/core": "^0.1.0", "starknet": "^6.17.0", "tsup": "^8.3.5", diff --git a/packages/plugin-starknet/src/actions/unruggable.ts b/packages/plugin-starknet/src/actions/unruggable.ts index 7318ceb8e4..897fb1bfa2 100644 --- a/packages/plugin-starknet/src/actions/unruggable.ts +++ b/packages/plugin-starknet/src/actions/unruggable.ts @@ -10,19 +10,23 @@ import { } from "@ai16z/eliza"; import { composeContext } from "@ai16z/eliza"; import { generateObject } from "@ai16z/eliza"; - +import { Percent } from "@uniswap/sdk-core"; import { getStarknetAccount, getStarknetProvider, + parseFormatedAmount, + parseFormatedPercentage, validateSettings, } from "../utils/index.ts"; import { DeployData, Factory } from "@unruggable_starknet/core"; - -interface SwapContent { - sellTokenAddress: string; - buyTokenAddress: string; - sellAmount: string; -} +import { + AMM, + EKUBO_TICK_SPACING, + LiquidityType, + QUOTE_TOKEN_SYMBOL, + RECOMMENDED_EKUBO_FEES, +} from "@unruggable_starknet/core/constants"; +import { ACCOUNTS, TOKENS } from "../utils/constants.ts"; export function isDeployTokenContent( content: DeployData @@ -108,6 +112,7 @@ export const deployToken: Action = { context: deployContext, modelClass: ModelClass.MEDIUM, }); + elizaLogger.log("init supply." + response.initialSupply); elizaLogger.log(response); @@ -127,12 +132,57 @@ export const deployToken: Action = { chainId: await provider.getChainId(), }); - const { tokenAddress, calls } = factory.getDeployCalldata({ - name: response.name, - symbol: response.symbol, - owner: response.owner, - initialSupply: response.initialSupply, - }); + const { tokenAddress, calls: deployCalls } = + factory.getDeployCalldata({ + name: response.name, + symbol: response.symbol, + owner: response.owner, + initialSupply: response.initialSupply, + }); + + const data = await factory.getMemecoinLaunchData(tokenAddress); + + const { calls: launchCalls } = await factory.getEkuboLaunchCalldata( + { + address: tokenAddress, + name: response.name, + symbol: response.symbol, + owner: response.owner, + totalSupply: response.initialSupply, + decimals: 18, + ...data, + }, + { + fees: parseFormatedPercentage("3"), + amm: AMM.EKUBO, + teamAllocations: [ + { + address: ACCOUNTS.ELIZA, + amount: new Percent( + 2.5, + response.initialSupply + ).toFixed(0), + }, + { + address: ACCOUNTS.BLOBERT, + amount: new Percent( + 2.5, + response.initialSupply + ).toFixed(0), + }, + ], + holdLimit: parseFormatedPercentage("2"), + antiBotPeriod: 3600, + quoteToken: { + address: TOKENS.LORDS, + symbol: "LORDS" as QUOTE_TOKEN_SYMBOL, + name: "Lords", + decimals: 18, + camelCased: false, + }, + startingMarketCap: parseFormatedAmount("5000"), + } + ); elizaLogger.log( "Deployment has been initiated for coin: " + @@ -140,7 +190,7 @@ export const deployToken: Action = { " at address: " + tokenAddress ); - const tx = await account.execute(calls); + const tx = await account.execute([...deployCalls, ...launchCalls]); callback?.({ text: diff --git a/packages/plugin-starknet/src/utils/constants.ts b/packages/plugin-starknet/src/utils/constants.ts new file mode 100644 index 0000000000..13812f44f8 --- /dev/null +++ b/packages/plugin-starknet/src/utils/constants.ts @@ -0,0 +1,8 @@ +export enum TOKENS { + LORDS = "0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49", +} + +export enum ACCOUNTS { + ELIZA = "0x07c6eE09d10C9a98E5100F017439b825c85c5cbdaE1146c602013F79f4db9f1D", + BLOBERT = "0x04837488b417a286a4a42ccb296398c86b7a88b3ef74c67425aac34b9467f03f", +} diff --git a/packages/plugin-starknet/src/utils/index.ts b/packages/plugin-starknet/src/utils/index.ts index 8e3e7a157d..17c9b8d8e6 100644 --- a/packages/plugin-starknet/src/utils/index.ts +++ b/packages/plugin-starknet/src/utils/index.ts @@ -1,4 +1,5 @@ import { Content, IAgentRuntime } from "@ai16z/eliza"; +import { Fraction, Percent } from "@uniswap/sdk-core"; import { Account, Contract, RpcProvider } from "starknet"; @@ -78,3 +79,42 @@ export function isTransferContent( return validAddresses; } + +export const getPercent = (amount: string | number, decimals: number) => { + return new Percent(amount, decimals); +}; + +export const parseFormatedAmount = (amount: string) => amount.replace(/,/g, ""); + +export const PERCENTAGE_INPUT_PRECISION = 2; + +export const parseFormatedPercentage = (percent: string) => + new Percent( + +percent * 10 ** PERCENTAGE_INPUT_PRECISION, + 100 * 10 ** PERCENTAGE_INPUT_PRECISION + ); + +interface ParseCurrencyAmountOptions { + fixed: number; + significant?: number; +} + +export const formatCurrenyAmount = ( + amount: Fraction, + { fixed, significant = 1 }: ParseCurrencyAmountOptions +) => { + const fixedAmount = amount.toFixed(fixed); + const significantAmount = amount.toSignificant(significant); + + if (+significantAmount > +fixedAmount) return significantAmount; + else return +fixedAmount.toString(); +}; + +export const formatPercentage = (percentage: Percent) => { + const formatedPercentage = +percentage.toFixed(2); + const exact = percentage.equalTo( + new Percent(Math.round(formatedPercentage * 100), 10000) + ); + + return `${exact ? "" : "~"}${formatedPercentage}%`; +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d956967330..f85cfec055 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -875,6 +875,9 @@ importers: '@avnu/avnu-sdk': specifier: ^2.1.1 version: 2.1.1(ethers@6.13.4(bufferutil@4.0.8)(utf-8-validate@5.0.10))(qs@6.13.0)(starknet@6.18.0(encoding@0.1.13)) + '@uniswap/sdk-core': + specifier: ^6.0.0 + version: 6.0.0 '@unruggable_starknet/core': specifier: ^0.1.0 version: 0.1.0(starknet@6.18.0(encoding@0.1.13)) @@ -2801,6 +2804,9 @@ packages: '@ethersproject/bytes@5.7.0': resolution: {integrity: sha512-nsbxwgFXWh9NyYWo+U8atvmMsSdKJprTcICAkvbBffT75qDocbuggBU0SJiVK2MuTrp0q+xvLkTnGMPK1+uA9A==} + '@ethersproject/constants@5.7.0': + resolution: {integrity: sha512-DHI+y5dBNvkpYUMiRQyxRBYBefZkJfo70VUkUAsRjcPs47muV9evftfZ0PJVCXYbAiCgght0DtcF9srFQmIgWA==} + '@ethersproject/keccak256@5.7.0': resolution: {integrity: sha512-2UcPboeL/iW+pSg6vZ6ydF8tCnv3Iu/8tUmLLzWWGzxWKFFqOBQFLo6uLUv6BDrLgCDfN28RJ/wtByx+jZ4KBg==} @@ -2810,6 +2816,9 @@ packages: '@ethersproject/rlp@5.7.0': resolution: {integrity: sha512-rBxzX2vK8mVF7b0Tol44t5Tb8gomOHkj5guL+HhzQ1yBh/ydjGnpw6at+X6Iw0Kp3OzzzkcKp8N9r0W4kYSs9w==} + '@ethersproject/strings@5.7.0': + resolution: {integrity: sha512-/9nu+lj0YswRNSH0NXYqrh8775XNyEdUQAuf3f+SmOrnVewcJ5SBNAjF7lpgehKi4abvNNXyf+HX86czCdJ8Mg==} + '@google-cloud/vertexai@1.9.0': resolution: {integrity: sha512-8brlcJwFXI4fPuBtsDNQqCdWZmz8gV9jeEKOU0vc5H2SjehCQpXK/NwuSEr916zbhlBHtg/sU37qQQdgvh5BRA==} engines: {node: '>=18.0.0'} @@ -4775,6 +4784,10 @@ packages: resolution: {integrity: sha512-hr7vwYrXScg+V8/rRc2UL/Ixc/p0P7yqe4D/OxzUdMRYr8RZd+8z5Iu9+WembjZT/DCdbTjde6lsph4Og0n1BQ==} engines: {node: '>=10'} + '@uniswap/sdk-core@6.0.0': + resolution: {integrity: sha512-6rwBG/Ut7rL2Dw4xtTF1dHSmtctT3h57q4vXIneLYjlePa1PT0mgp5D7cu/6xKEvO1MFtnMchImpWsclfafdUg==} + engines: {node: '>=10'} + '@unruggable_starknet/core@0.1.0': resolution: {integrity: sha512-qhKqw1XKhSRHzK3Ll/RzCblGFJDD4oeGoPQbal/X7QVVG1qz+VnqoyA1U6SDmlSGTHfskvMoXrVWkPRFL2RqHA==} peerDependencies: @@ -15683,6 +15696,10 @@ snapshots: dependencies: '@ethersproject/logger': 5.7.0 + '@ethersproject/constants@5.7.0': + dependencies: + '@ethersproject/bignumber': 5.7.0 + '@ethersproject/keccak256@5.7.0': dependencies: '@ethersproject/bytes': 5.7.0 @@ -15695,6 +15712,12 @@ snapshots: '@ethersproject/bytes': 5.7.0 '@ethersproject/logger': 5.7.0 + '@ethersproject/strings@5.7.0': + dependencies: + '@ethersproject/bytes': 5.7.0 + '@ethersproject/constants': 5.7.0 + '@ethersproject/logger': 5.7.0 + '@google-cloud/vertexai@1.9.0(encoding@0.1.13)': dependencies: google-auth-library: 9.15.0(encoding@0.1.13) @@ -18130,6 +18153,18 @@ snapshots: tiny-invariant: 1.3.3 toformat: 2.0.0 + '@uniswap/sdk-core@6.0.0': + dependencies: + '@ethersproject/address': 5.7.0 + '@ethersproject/bytes': 5.7.0 + '@ethersproject/keccak256': 5.7.0 + '@ethersproject/strings': 5.7.0 + big.js: 5.2.2 + decimal.js-light: 2.5.1 + jsbi: 3.2.5 + tiny-invariant: 1.3.3 + toformat: 2.0.0 + '@unruggable_starknet/core@0.1.0(starknet@6.18.0(encoding@0.1.13))': dependencies: '@uniswap/sdk-core': 4.2.1 @@ -20783,7 +20818,7 @@ snapshots: extract-zip@2.0.1: dependencies: - debug: 4.3.4 + debug: 4.3.7(supports-color@5.5.0) get-stream: 5.2.0 yauzl: 2.10.0 optionalDependencies: