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
function calculateAPYFromAPR(annualPercentageRate) { | |
// Slot calculations | |
const SLOTS_PER_SECOND = 2; | |
const SLOTS_PER_MINUTE = SLOTS_PER_SECOND * 60; | |
const SLOTS_PER_HOUR = SLOTS_PER_MINUTE * 60; | |
const SLOTS_PER_DAY = SLOTS_PER_HOUR * 24; | |
const SLOTS_PER_YEAR = SLOTS_PER_DAY * 365; | |
// Step 1: Calculate the rate per slot | |
const ratePerSlot = new Decimal(1).plus( |
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
async function profiledFunctionExecution(asyncFunctionToProfile, functionName, additionalData = []) { | |
const startTime = Date.now(); | |
const PROFILE_LOG_PREFIX = "[PROFILING]"; | |
// Start a transaction for monitoring (assuming a monitoring library is used) | |
const transaction = startTransaction({ name: functionName }); | |
// Log the start of function execution | |
console.log(PROFILE_LOG_PREFIX, `function=${functionName} event=start ts=${new Date(startTime).toISOString()}`); |
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
async processTrancationJito( | |
jitoTip: number, // in ui | |
tx: Transaction, | |
luts?: AddressLookupTableAccount[], | |
priorityFee?: number, // priorityFeeUi | |
) { | |
console.log(`this.provider.connection.commitment :: ${this.provider.connection.commitment}`); | |
const jitoTipInLamport = jitoTip * LAMPORTS_PER_SOL; | |
console.log(`jitoTipInLamport :: ${jitoTipInLamport}`) |
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
use spl_associated_token_account::instruction::create_associated_token_account_idempotent; | |
use spl_token::instruction::close_account; | |
pub fn make_wrap_sol_ixs(config: &Config) -> Result<()> { | |
println!("sol transfer :: {}", config.payer.pubkey()); | |
// ata get -> ata create_idempotent -> trasnfer -> sync | |
let deposit_ata = anchor_spl::associated_token::get_associated_token_address( | |
&config.payer.pubkey(), | |
&pubkey!("So11111111111111111111111111111111111111112"), |
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
import * as fs from 'fs/promises'; | |
import * as path from 'path'; | |
const writeKeypairToFile = async (sk: Uint8Array, fileName: string): Promise<void> => { | |
const filePath = path.join('tests/keys', `${fileName}.json`); | |
try { | |
await fs.writeFile(filePath, JSON.stringify(Array.from(sk))); | |
console.log(`Keypair written to file: ${filePath}`); | |
} catch (error) { |
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
const credential = (await | |
navigator | |
.credentials.create({ | |
publicKey: { | |
challenge: new Uint8Array(16), | |
rp: { | |
name: "0xdeep.com", | |
}, | |
user: { | |
id: new Uint8Array(16), |
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
import * as anchor from "@project-serum/anchor"; | |
import { Program } from "@project-serum/anchor"; | |
import { HelloSupersec } from "../target/types/hello_supersec"; | |
describe("hello-supersec", () => { | |
// Configure the client to use the local cluster. | |
const provider = anchor.AnchorProvider.env(); | |
anchor.setProvider(provider); | |
const program = anchor.workspace.HelloSupersec as Program<HelloSupersec>; |
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
// Define the size of each chunk | |
const chunkSize = 1000; | |
// Create a function to iterate over the items in chunks | |
async function iterateInChunks(items: any[], callback: (chunk: any[]) => void) { | |
// Calculate the number of chunks | |
const numChunks = Math.ceil(items.length / chunkSize); | |
// Create an array to hold the promises for the async operations | |
const promises = []; |
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
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.7.0 <0.9.0; | |
import "@openzeppelin/contracts/utils/math/SafeMath.sol"; | |
import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; | |
import "@openzeppelin/contracts/utils/Counters.sol"; | |
contract AMM is ReentrancyGuard{ | |
using Counters for Counters.Counter; | |
Counters.Counter private caseID; |
NewerOlder