Skip to content

Commit

Permalink
Merge pull request #444 from ai16z/unrug-fix
Browse files Browse the repository at this point in the history
fix: unrug
  • Loading branch information
ponderingdemocritus authored Nov 20, 2024
2 parents b31f600 + b8c74a6 commit 5d86a5b
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/plugin-starknet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
78 changes: 64 additions & 14 deletions packages/plugin-starknet/src/actions/unruggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,6 +112,7 @@ export const deployToken: Action = {
context: deployContext,
modelClass: ModelClass.MEDIUM,
});

elizaLogger.log("init supply." + response.initialSupply);
elizaLogger.log(response);

Expand All @@ -127,20 +132,65 @@ 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: " +
response.name +
" at address: " +
tokenAddress
);
const tx = await account.execute(calls);
const tx = await account.execute([...deployCalls, ...launchCalls]);

callback?.({
text:
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-starknet/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export enum TOKENS {
LORDS = "0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49",
}

export enum ACCOUNTS {
ELIZA = "0x07c6eE09d10C9a98E5100F017439b825c85c5cbdaE1146c602013F79f4db9f1D",
BLOBERT = "0x04837488b417a286a4a42ccb296398c86b7a88b3ef74c67425aac34b9467f03f",
}
40 changes: 40 additions & 0 deletions packages/plugin-starknet/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Content, IAgentRuntime } from "@ai16z/eliza";
import { Fraction, Percent } from "@uniswap/sdk-core";

import { Account, Contract, RpcProvider } from "starknet";

Expand Down Expand Up @@ -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}%`;
};
37 changes: 36 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d86a5b

Please sign in to comment.