-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from MeteoraAg/feat/m3m3
feat: Add script to create m3m3 farm
- Loading branch information
Showing
12 changed files
with
418 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"rpcUrl": "https://api.mainnet-beta.solana.com", | ||
"dryRun": false, | ||
"keypairFilePath": "keypair.json", | ||
"computeUnitPriceMicroLamports": 100000, | ||
"baseMint": "FvxPZWBViVsmzS11MGi3ybNGjTKChwdfXU3UWopBujTn", | ||
"quoteSymbol": "SOL", | ||
"m3m3": { | ||
"topListLength": 100, | ||
"unstakeLockDurationSecs": 25200, | ||
"secondsToFullUnlock": 86400, | ||
"startFeeDistributeTimestamp": 1737590400 | ||
}, | ||
"lockLiquidity": { | ||
"allocations": [ | ||
{ | ||
"percentage": 100, | ||
"address": "D2Yt1jtjjk6cPiwYKs6krtbjfjjYiQmYWbFtTrgL2WR2" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { BN, Wallet } from "@coral-xyz/anchor"; | ||
import { | ||
Connection, | ||
PublicKey, | ||
sendAndConfirmTransaction, | ||
} from "@solana/web3.js"; | ||
import { MeteoraConfig, parseConfigFromCli } from "./libs/config"; | ||
import { DEFAULT_COMMITMENT_LEVEL, M3M3_PROGRAM_IDS } from "./libs/constants"; | ||
import { | ||
safeParseKeypairFromFile, | ||
getQuoteMint, | ||
getQuoteDecimals, | ||
runSimulateTransaction, | ||
} from "./libs/utils"; | ||
import { createTokenMint } from "./libs/create_token_mint"; | ||
import { createPermissionlessDynamicPool } from "./libs/create_pool_utils"; | ||
import { | ||
createProgram, | ||
deriveCustomizablePermissionlessConstantProductPoolAddress, | ||
} from "@mercurial-finance/dynamic-amm-sdk/dist/cjs/src/amm/utils"; | ||
import AmmImpl from "@mercurial-finance/dynamic-amm-sdk"; | ||
import StakeForFee, { deriveFeeVault } from "@meteora-ag/m3m3"; | ||
import { | ||
create_m3m3_farm, | ||
lockLiquidityToFeeVault, | ||
} from "./libs/create_m3m3_farm_utils"; | ||
|
||
async function main() { | ||
let config: MeteoraConfig = parseConfigFromCli(); | ||
|
||
console.log(`> Using keypair file path ${config.keypairFilePath}`); | ||
let keypair = safeParseKeypairFromFile(config.keypairFilePath); | ||
|
||
console.log("\n> Initializing with general configuration..."); | ||
console.log(`- Using RPC URL ${config.rpcUrl}`); | ||
console.log(`- Dry run = ${config.dryRun}`); | ||
console.log(`- Using payer ${keypair.publicKey} to execute commands`); | ||
|
||
const connection = new Connection(config.rpcUrl, DEFAULT_COMMITMENT_LEVEL); | ||
const wallet = new Wallet(keypair); | ||
|
||
if (!config.baseMint) { | ||
throw new Error("Missing baseMint in configuration"); | ||
} | ||
let baseMint = new PublicKey(config.baseMint); | ||
let quoteMint = getQuoteMint(config.quoteSymbol); | ||
const ammProgram = createProgram(connection).ammProgram; | ||
const poolKey = deriveCustomizablePermissionlessConstantProductPoolAddress( | ||
baseMint, | ||
quoteMint, | ||
ammProgram.programId, | ||
); | ||
|
||
const poolAccount = await connection.getAccountInfo(poolKey, { | ||
commitment: 'confirmed' | ||
}); | ||
|
||
if (!poolAccount) { | ||
throw new Error(`Pool ${poolKey} didn't exist. Please create it first.`); | ||
} | ||
|
||
console.log(`- Using base token mint ${baseMint.toString()}`); | ||
console.log(`- Using quote token mint ${quoteMint.toString()}`); | ||
console.log(`- Pool key ${poolKey}`); | ||
|
||
if (!config.m3m3) { | ||
throw new Error("Missing M3M3 configuration"); | ||
} | ||
|
||
// 3. Create M3M3 farm | ||
await create_m3m3_farm( | ||
connection, | ||
wallet.payer, | ||
poolKey, | ||
baseMint, | ||
config.m3m3, | ||
config.dryRun, | ||
config.computeUnitPriceMicroLamports | ||
); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
Connection, | ||
Keypair, | ||
PublicKey, | ||
sendAndConfirmTransaction, | ||
} from "@solana/web3.js"; | ||
import { M3m3Config, MeteoraConfig } from "./config"; | ||
import { M3M3_PROGRAM_IDS } from "./constants"; | ||
import StakeForFee, { deriveFeeVault } from "@meteora-ag/m3m3"; | ||
import { BN } from "@coral-xyz/anchor"; | ||
import { modifyComputeUnitPriceIx, runSimulateTransaction } from "./utils"; | ||
import { getAssociatedTokenAddressSync } from "@solana/spl-token"; | ||
import AmmImpl, { VaultIdl } from "@mercurial-finance/dynamic-amm-sdk"; | ||
import Decimal from "decimal.js"; | ||
|
||
export async function create_m3m3_farm( | ||
connection: Connection, | ||
payer: Keypair, | ||
poolKey: PublicKey, | ||
stakeMint: PublicKey, | ||
config: M3m3Config, | ||
dryRun: boolean, | ||
computeUnitPriceMicroLamports: number, | ||
opts?: { | ||
m3m3ProgramId: PublicKey; | ||
}, | ||
): Promise<void> { | ||
const m3m3ProgramId = | ||
opts?.m3m3ProgramId ?? new PublicKey(M3M3_PROGRAM_IDS["mainnet-beta"]); | ||
const m3m3VaultPubkey = deriveFeeVault(poolKey, m3m3ProgramId); | ||
console.log(`- M3M3 fee vault ${m3m3VaultPubkey}`); | ||
|
||
// 1. Create m3m3 farm | ||
const m3m3VaultAccount = await connection.getAccountInfo(m3m3VaultPubkey, { | ||
commitment: 'confirmed', | ||
}); | ||
|
||
if (m3m3VaultAccount) { | ||
console.log(`>>> M3M3 farm is already existed. Skip creating new farm.`); | ||
return; | ||
} | ||
|
||
console.log(`>> Creating M3M3 fee farm...`); | ||
const topListLength = config.topListLength; | ||
const unstakeLockDuration = new BN(config.unstakeLockDurationSecs); | ||
const secondsToFullUnlock = new BN(config.secondsToFullUnlock); | ||
const startFeeDistributeTimestamp = new BN( | ||
config.startFeeDistributeTimestamp, | ||
); | ||
|
||
console.log(`- Using topListLength: ${topListLength}`); | ||
console.log(`- Using unstakeLockDuration ${unstakeLockDuration}`); | ||
console.log(`- Using secondsToFullUnlock ${secondsToFullUnlock}`); | ||
console.log(`- Using startFeeDistributeTimestamp ${startFeeDistributeTimestamp}`); | ||
|
||
// m3m3 farm didn't exist | ||
const createTx = await StakeForFee.createFeeVault( | ||
connection, | ||
poolKey, | ||
stakeMint, | ||
payer.publicKey, | ||
{ | ||
topListLength, | ||
unstakeLockDuration, | ||
secondsToFullUnlock, | ||
startFeeDistributeTimestamp, | ||
}, | ||
); | ||
modifyComputeUnitPriceIx(createTx, computeUnitPriceMicroLamports); | ||
|
||
if (dryRun) { | ||
console.log(`> Simulating create m3m3 farm tx...`); | ||
await runSimulateTransaction(connection, [payer], payer.publicKey, [ | ||
createTx, | ||
]); | ||
} else { | ||
console.log(`>> Sending create m3m3 farm transaction...`); | ||
const txHash = await sendAndConfirmTransaction(connection, createTx, [ | ||
payer, | ||
]).catch((err) => { | ||
console.error(err); | ||
throw err; | ||
}); | ||
console.log( | ||
`>>> M3M3 farm initialized successfully with tx hash: ${txHash}`, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.