Skip to content

Commit 5d86a5b

Browse files
Merge pull request elizaOS#444 from ai16z/unrug-fix
fix: unrug
2 parents b31f600 + b8c74a6 commit 5d86a5b

File tree

5 files changed

+149
-15
lines changed

5 files changed

+149
-15
lines changed

packages/plugin-starknet/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@ai16z/eliza": "workspace:*",
99
"@ai16z/plugin-trustdb": "workspace:*",
1010
"@avnu/avnu-sdk": "^2.1.1",
11+
"@uniswap/sdk-core": "^6.0.0",
1112
"@unruggable_starknet/core": "^0.1.0",
1213
"starknet": "^6.17.0",
1314
"tsup": "^8.3.5",

packages/plugin-starknet/src/actions/unruggable.ts

+64-14
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,23 @@ import {
1010
} from "@ai16z/eliza";
1111
import { composeContext } from "@ai16z/eliza";
1212
import { generateObject } from "@ai16z/eliza";
13-
13+
import { Percent } from "@uniswap/sdk-core";
1414
import {
1515
getStarknetAccount,
1616
getStarknetProvider,
17+
parseFormatedAmount,
18+
parseFormatedPercentage,
1719
validateSettings,
1820
} from "../utils/index.ts";
1921
import { DeployData, Factory } from "@unruggable_starknet/core";
20-
21-
interface SwapContent {
22-
sellTokenAddress: string;
23-
buyTokenAddress: string;
24-
sellAmount: string;
25-
}
22+
import {
23+
AMM,
24+
EKUBO_TICK_SPACING,
25+
LiquidityType,
26+
QUOTE_TOKEN_SYMBOL,
27+
RECOMMENDED_EKUBO_FEES,
28+
} from "@unruggable_starknet/core/constants";
29+
import { ACCOUNTS, TOKENS } from "../utils/constants.ts";
2630

2731
export function isDeployTokenContent(
2832
content: DeployData
@@ -108,6 +112,7 @@ export const deployToken: Action = {
108112
context: deployContext,
109113
modelClass: ModelClass.MEDIUM,
110114
});
115+
111116
elizaLogger.log("init supply." + response.initialSupply);
112117
elizaLogger.log(response);
113118

@@ -127,20 +132,65 @@ export const deployToken: Action = {
127132
chainId: await provider.getChainId(),
128133
});
129134

130-
const { tokenAddress, calls } = factory.getDeployCalldata({
131-
name: response.name,
132-
symbol: response.symbol,
133-
owner: response.owner,
134-
initialSupply: response.initialSupply,
135-
});
135+
const { tokenAddress, calls: deployCalls } =
136+
factory.getDeployCalldata({
137+
name: response.name,
138+
symbol: response.symbol,
139+
owner: response.owner,
140+
initialSupply: response.initialSupply,
141+
});
142+
143+
const data = await factory.getMemecoinLaunchData(tokenAddress);
144+
145+
const { calls: launchCalls } = await factory.getEkuboLaunchCalldata(
146+
{
147+
address: tokenAddress,
148+
name: response.name,
149+
symbol: response.symbol,
150+
owner: response.owner,
151+
totalSupply: response.initialSupply,
152+
decimals: 18,
153+
...data,
154+
},
155+
{
156+
fees: parseFormatedPercentage("3"),
157+
amm: AMM.EKUBO,
158+
teamAllocations: [
159+
{
160+
address: ACCOUNTS.ELIZA,
161+
amount: new Percent(
162+
2.5,
163+
response.initialSupply
164+
).toFixed(0),
165+
},
166+
{
167+
address: ACCOUNTS.BLOBERT,
168+
amount: new Percent(
169+
2.5,
170+
response.initialSupply
171+
).toFixed(0),
172+
},
173+
],
174+
holdLimit: parseFormatedPercentage("2"),
175+
antiBotPeriod: 3600,
176+
quoteToken: {
177+
address: TOKENS.LORDS,
178+
symbol: "LORDS" as QUOTE_TOKEN_SYMBOL,
179+
name: "Lords",
180+
decimals: 18,
181+
camelCased: false,
182+
},
183+
startingMarketCap: parseFormatedAmount("5000"),
184+
}
185+
);
136186

137187
elizaLogger.log(
138188
"Deployment has been initiated for coin: " +
139189
response.name +
140190
" at address: " +
141191
tokenAddress
142192
);
143-
const tx = await account.execute(calls);
193+
const tx = await account.execute([...deployCalls, ...launchCalls]);
144194

145195
callback?.({
146196
text:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export enum TOKENS {
2+
LORDS = "0x0124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49",
3+
}
4+
5+
export enum ACCOUNTS {
6+
ELIZA = "0x07c6eE09d10C9a98E5100F017439b825c85c5cbdaE1146c602013F79f4db9f1D",
7+
BLOBERT = "0x04837488b417a286a4a42ccb296398c86b7a88b3ef74c67425aac34b9467f03f",
8+
}

packages/plugin-starknet/src/utils/index.ts

+40
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Content, IAgentRuntime } from "@ai16z/eliza";
2+
import { Fraction, Percent } from "@uniswap/sdk-core";
23

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

@@ -78,3 +79,42 @@ export function isTransferContent(
7879

7980
return validAddresses;
8081
}
82+
83+
export const getPercent = (amount: string | number, decimals: number) => {
84+
return new Percent(amount, decimals);
85+
};
86+
87+
export const parseFormatedAmount = (amount: string) => amount.replace(/,/g, "");
88+
89+
export const PERCENTAGE_INPUT_PRECISION = 2;
90+
91+
export const parseFormatedPercentage = (percent: string) =>
92+
new Percent(
93+
+percent * 10 ** PERCENTAGE_INPUT_PRECISION,
94+
100 * 10 ** PERCENTAGE_INPUT_PRECISION
95+
);
96+
97+
interface ParseCurrencyAmountOptions {
98+
fixed: number;
99+
significant?: number;
100+
}
101+
102+
export const formatCurrenyAmount = (
103+
amount: Fraction,
104+
{ fixed, significant = 1 }: ParseCurrencyAmountOptions
105+
) => {
106+
const fixedAmount = amount.toFixed(fixed);
107+
const significantAmount = amount.toSignificant(significant);
108+
109+
if (+significantAmount > +fixedAmount) return significantAmount;
110+
else return +fixedAmount.toString();
111+
};
112+
113+
export const formatPercentage = (percentage: Percent) => {
114+
const formatedPercentage = +percentage.toFixed(2);
115+
const exact = percentage.equalTo(
116+
new Percent(Math.round(formatedPercentage * 100), 10000)
117+
);
118+
119+
return `${exact ? "" : "~"}${formatedPercentage}%`;
120+
};

pnpm-lock.yaml

+36-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)