-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c54e02
commit 6f40011
Showing
1 changed file
with
139 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { | ||
Connection, | ||
Keypair, | ||
PublicKey, | ||
Transaction, | ||
sendAndConfirmTransaction, | ||
} from "@solana/web3.js"; | ||
import "dotenv/config"; | ||
import { UpgradeManagerProgram } from "../src/upgradeManager"; | ||
|
||
const UPGRADE_MANAGER_ID = "4jyJ7EEsYa72REdD8ZMBvHFTXZ4VYGQPUHaJTajsK8SN"; | ||
|
||
// Here we go. | ||
main(); | ||
|
||
// impl | ||
|
||
async function main() { | ||
const connection = new Connection("https://api.mainnet.solana.com", "confirmed"); | ||
const upgradeManager = new UpgradeManagerProgram(connection, UPGRADE_MANAGER_ID); | ||
|
||
if (process.env.SOLANA_PRIVATE_KEY === undefined) { | ||
throw new Error("SOLANA_PRIVATE_KEY is undefined"); | ||
} | ||
const payer = Keypair.fromSecretKey(Buffer.from(process.env.SOLANA_PRIVATE_KEY, "base64")); | ||
|
||
// TODO: update the buffer addresses | ||
// { | ||
// const buffer = new PublicKey("7Ug82c9aZDCNBpjyBsYyZWuBFnphM2K3tSJmYQw6Huev"); | ||
// await upgradeMatchingEngine(upgradeManager, payer, buffer); | ||
// } | ||
|
||
// { | ||
// const buffer = new PublicKey("2ZKYhV56iaFpHQsdGc2TXdnomVCf3KytCb8ZnjxnLBPN"); | ||
// await upgradeTokenRouter(upgradeManager, payer, buffer); | ||
// } | ||
} | ||
|
||
async function upgradeMatchingEngine( | ||
upgradeManager: UpgradeManagerProgram, | ||
owner: Keypair, | ||
matchingEngineBuffer: PublicKey, | ||
) { | ||
const connection = upgradeManager.program.provider.connection; | ||
|
||
const accInfo = await connection.getAccountInfo(matchingEngineBuffer, { | ||
dataSlice: { offset: 0, length: 8 }, | ||
}); | ||
if (accInfo === null) { | ||
throw new Error("no buffer found"); | ||
} | ||
|
||
const executeIx = await upgradeManager.executeMatchingEngineUpgradeIx({ | ||
owner: owner.publicKey, | ||
matchingEngineBuffer, | ||
}); | ||
|
||
const executeTxSig = await sendAndConfirmTransaction( | ||
connection, | ||
new Transaction().add(executeIx), | ||
[owner], | ||
{ | ||
commitment: "finalized", | ||
}, | ||
).catch((err) => { | ||
console.log(err); | ||
throw err; | ||
}); | ||
console.log("executed upgrade", executeTxSig); | ||
|
||
const commitIx = await upgradeManager.commitMatchingEngineUpgradeIx({ | ||
owner: owner.publicKey, | ||
}); | ||
|
||
let commitTxSig: string | null = null; | ||
while (commitTxSig === null) { | ||
console.log("attempting to commit..."); | ||
await new Promise((r) => setTimeout(r, 2000)); | ||
|
||
commitTxSig = await sendAndConfirmTransaction(connection, new Transaction().add(commitIx), [ | ||
owner, | ||
]).catch((err) => { | ||
console.log(err); | ||
return null; | ||
}); | ||
} | ||
console.log("committed upgrade", commitTxSig); | ||
} | ||
|
||
async function upgradeTokenRouter( | ||
upgradeManager: UpgradeManagerProgram, | ||
owner: Keypair, | ||
tokenRouterBuffer: PublicKey, | ||
) { | ||
const connection = upgradeManager.program.provider.connection; | ||
|
||
const accInfo = await connection.getAccountInfo(tokenRouterBuffer, { | ||
dataSlice: { offset: 0, length: 8 }, | ||
}); | ||
if (accInfo === null) { | ||
throw new Error("no buffer found"); | ||
} | ||
|
||
const executeIx = await upgradeManager.executeTokenRouterUpgradeIx({ | ||
owner: owner.publicKey, | ||
tokenRouterBuffer, | ||
}); | ||
|
||
const executeTxSig = await sendAndConfirmTransaction( | ||
connection, | ||
new Transaction().add(executeIx), | ||
[owner], | ||
{ | ||
commitment: "finalized", | ||
}, | ||
).catch((err) => { | ||
console.log(err); | ||
throw err; | ||
}); | ||
console.log("executed upgrade", executeTxSig); | ||
|
||
const commitIx = await upgradeManager.commitTokenRouterUpgradeIx({ | ||
owner: owner.publicKey, | ||
}); | ||
|
||
let commitTxSig: string | null = null; | ||
while (commitTxSig === null) { | ||
console.log("attempting to commit..."); | ||
await new Promise((r) => setTimeout(r, 2000)); | ||
|
||
commitTxSig = await sendAndConfirmTransaction(connection, new Transaction().add(commitIx), [ | ||
owner, | ||
]).catch((err) => { | ||
console.log(err); | ||
return null; | ||
}); | ||
} | ||
console.log("committed upgrade", commitTxSig); | ||
} |