Skip to content

Commit e63d8aa

Browse files
authored
init commit for P2P launch (#438)
* init commit for P2P launch * updated for sim and atomic transaction
1 parent fcb7e10 commit e63d8aa

3 files changed

Lines changed: 164 additions & 0 deletions

File tree

scripts/assets/P2P/P2P.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "P2P Protocol",
3+
"symbol": "P2P",
4+
"description": "Futarchy Ownership, Protocol Governance and Trust Staking token of the P2P Protocol",
5+
"image": "https://raw.githubusercontent.com/metaDAOproject/programs/refs/heads/develop/scripts/assets/P2P/P2P.png"
6+
}

scripts/assets/P2P/P2P.png

3.31 KB
Loading

scripts/v0.7/launchP2P.ts

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import * as anchor from "@coral-xyz/anchor";
2+
import {
3+
LaunchpadClient,
4+
getLaunchAddr,
5+
getLaunchSignerAddr,
6+
} from "@metadaoproject/futarchy/v0.7";
7+
import {
8+
ComputeBudgetProgram,
9+
PublicKey,
10+
SystemProgram,
11+
Transaction,
12+
} from "@solana/web3.js";
13+
import BN from "bn.js";
14+
import * as token from "@solana/spl-token";
15+
16+
const provider = anchor.AnchorProvider.env();
17+
const payer = provider.wallet["payer"];
18+
19+
const LAUNCH_AUTHORITY = payer.publicKey;
20+
21+
const TEAM_ADDRESS = new PublicKey(
22+
"63miwxnMci7L76tWBGFfmHjbm199MKiteiWrNY1ShQhV",
23+
); // P2P team address
24+
25+
// Launch details
26+
const MIN_GOAL = 6_000_000; // 6M USDC
27+
28+
const SPENDING_MEMBERS = [
29+
new PublicKey("G4vHnTW7PSgTtHAYwmrBvUydWGmz8Bd2px9XYAsBQWgu"),
30+
new PublicKey("6fwrmfLPCQJmF47LdoLTBBojtw8Qbq2wicRyDpzsQjBk"),
31+
new PublicKey("CTDAar2UbkpVq21u8RRvzWT3rtjvoeV2PFZp7PdiMZWg"),
32+
];
33+
const SPENDING_LIMIT = 175_000; // 175k USDC
34+
35+
const PERFORMANCE_PACKAGE_GRANTEE = TEAM_ADDRESS;
36+
const PERFORMANCE_PACKAGE_TOKEN_AMOUNT = 7_740_000; // 7.74M P2P
37+
const PERFORMANCE_PACKAGE_UNLOCK_MONTHS = 12; // 12 months
38+
39+
// Additional carveout details
40+
const ADDITIONAL_CARVEOUT = 5_160_000; // 5.16M P2P
41+
const ADDITIONAL_CARVEOUT_RECIPIENT = new PublicKey(
42+
"BzZhwMzoY5ikk9mWBejb3dKbYXCYZ6eJhijk71WfvTYt",
43+
); // MetaDAO P2P Launch Custody Multisig
44+
45+
const TOKEN_SEED = "ltSNHJR5jLfmx0Zs";
46+
const TOKEN_NAME = "P2P Protocol";
47+
const TOKEN_SYMBOL = "P2P";
48+
const TOKEN_URI =
49+
"https://raw.githubusercontent.com/metaDAOproject/programs/refs/heads/develop/scripts/assets/P2P/P2P.json";
50+
51+
const secondsPerDay = 86_400;
52+
const numberOfDays = 4;
53+
const launchDurationSeconds = secondsPerDay * numberOfDays; // 4 days
54+
55+
const launchpad: LaunchpadClient = LaunchpadClient.createClient({ provider });
56+
57+
export const launch = async () => {
58+
const lamports = await provider.connection.getMinimumBalanceForRentExemption(
59+
token.MINT_SIZE,
60+
);
61+
62+
const TOKEN = await PublicKey.createWithSeed(
63+
payer.publicKey,
64+
TOKEN_SEED,
65+
token.TOKEN_PROGRAM_ID,
66+
);
67+
console.log("Token address:", TOKEN.toBase58());
68+
69+
const [launch] = getLaunchAddr(undefined, TOKEN);
70+
const [launchSigner] = getLaunchSignerAddr(undefined, launch);
71+
72+
const createTokenAccountIx = SystemProgram.createAccountWithSeed({
73+
fromPubkey: payer.publicKey,
74+
newAccountPubkey: TOKEN,
75+
basePubkey: payer.publicKey,
76+
seed: TOKEN_SEED,
77+
lamports: lamports,
78+
space: token.MINT_SIZE,
79+
programId: token.TOKEN_PROGRAM_ID,
80+
});
81+
82+
const initializeMintIx = token.createInitializeMint2Instruction(
83+
TOKEN,
84+
6,
85+
launchSigner,
86+
null,
87+
);
88+
89+
const launchIx = await launchpad
90+
.initializeLaunchIx({
91+
tokenName: TOKEN_NAME,
92+
tokenSymbol: TOKEN_SYMBOL,
93+
tokenUri: TOKEN_URI,
94+
minimumRaiseAmount: new BN(MIN_GOAL * 10 ** 6),
95+
baseMint: TOKEN,
96+
monthlySpendingLimitAmount: new BN(SPENDING_LIMIT * 10 ** 6),
97+
monthlySpendingLimitMembers: SPENDING_MEMBERS,
98+
performancePackageGrantee: PERFORMANCE_PACKAGE_GRANTEE,
99+
performancePackageTokenAmount: new BN(
100+
PERFORMANCE_PACKAGE_TOKEN_AMOUNT * 10 ** 6,
101+
),
102+
monthsUntilInsidersCanUnlock: PERFORMANCE_PACKAGE_UNLOCK_MONTHS,
103+
secondsForLaunch: launchDurationSeconds,
104+
teamAddress: TEAM_ADDRESS,
105+
additionalTokensAmount: ADDITIONAL_CARVEOUT
106+
? new BN(ADDITIONAL_CARVEOUT * 10 ** 6)
107+
: undefined,
108+
additionalTokensRecipient: ADDITIONAL_CARVEOUT_RECIPIENT,
109+
launchAuthority: LAUNCH_AUTHORITY,
110+
})
111+
.instruction();
112+
113+
const tx = new Transaction().add(
114+
createTokenAccountIx,
115+
initializeMintIx,
116+
launchIx,
117+
);
118+
const { blockhash } = await provider.connection.getLatestBlockhash();
119+
tx.recentBlockhash = blockhash;
120+
tx.feePayer = payer.publicKey;
121+
tx.sign(payer);
122+
const simulation = await provider.connection.simulateTransaction(tx);
123+
124+
if (simulation.value.err) {
125+
console.error("Transaction simulation failed:", simulation.value.err);
126+
throw new Error(
127+
`Simulation failed: ${JSON.stringify(simulation.value.err)}`,
128+
);
129+
}
130+
131+
const computeUnitsUsed = simulation.value.unitsConsumed || 200_000;
132+
// Add 20% buffer to the compute units
133+
const computeUnitsWithBuffer = Math.floor(computeUnitsUsed * 1.2);
134+
135+
console.log(`Simulated compute units: ${computeUnitsUsed}`);
136+
console.log(`Setting compute unit limit: ${computeUnitsWithBuffer}`);
137+
138+
// Rebuild transaction with compute budget
139+
const finalTx = new Transaction().add(
140+
ComputeBudgetProgram.setComputeUnitLimit({ units: computeUnitsWithBuffer }),
141+
createTokenAccountIx,
142+
initializeMintIx,
143+
launchIx,
144+
);
145+
146+
finalTx.recentBlockhash = blockhash;
147+
finalTx.feePayer = payer.publicKey;
148+
finalTx.sign(payer);
149+
150+
const txHash = await provider.connection.sendRawTransaction(
151+
finalTx.serialize(),
152+
);
153+
await provider.connection.confirmTransaction(txHash, "confirmed");
154+
155+
console.log("Launch initialized, P2P for you and for me!", txHash);
156+
};
157+
158+
launch().catch(console.error);

0 commit comments

Comments
 (0)