Last active
November 30, 2022 18:33
-
-
Save staccDOTsol/719debfd38df1f8f2e8bf31b37a5bdf1 to your computer and use it in GitHub Desktop.
streamflo savings
This file contains hidden or 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 { Connection, Keypair, PublicKey } from "@solana/web3.js"; | |
import { NodeWallet } from "@project-serum/common"; | |
import { getOrCreateAssociatedTokenAccount } from "@solana/spl-token"; | |
import fs from "fs"; | |
import { | |
StreamClient, | |
Stream, | |
CreateParams, | |
CreateMultiParams, | |
WithdrawParams, | |
TransferParams, | |
TopupParams, | |
CancelParams, | |
GetAllParams, | |
StreamDirection, | |
StreamType, | |
Cluster, | |
BN, | |
getBN, | |
getNumberFromBN, | |
} from "@streamflow/stream"; | |
const client = new StreamClient( | |
process.env.SOLANA_RPC || "https://api.mainnet-beta.solana.com", | |
Cluster.Mainnet, | |
"confirmed" | |
); | |
setTimeout(async function () { | |
let atas = await new Connection( | |
process.env.SOLANA_RPC || "https://api.mainnet-beta.solana.com" | |
).getParsedTokenAccountsByOwner( | |
Keypair.fromSecretKey( | |
new Uint8Array( | |
JSON.parse(fs.readFileSync("/home/jd/.config/solana/id.json").toString()) | |
) | |
).publicKey, | |
{ programId: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") } | |
); | |
for (var ata of atas.value) { | |
console.log(ata.account.data.parsed); | |
let total = Math.floor( | |
parseFloat(ata.account.data.parsed.info.tokenAmount.amount) * 0.98 | |
); | |
if (total > 1) { | |
let periods = Math.floor(Math.random() * 10) + 8; | |
let test = await getOrCreateAssociatedTokenAccount( | |
new Connection( | |
process.env.SOLANA_RPC || "https://api.mainnet-beta.solana.com" | |
), | |
Keypair.fromSecretKey( | |
new Uint8Array( | |
JSON.parse(fs.readFileSync("/home/jd/.config/solana/id.json").toString()) | |
) | |
), | |
new PublicKey(ata.account.data.parsed.info.mint), | |
new PublicKey("Gf3sbc5Jb62jH7WcTr3WSNGDQLk1w6wcKMZXKK1SC1E6") | |
); | |
console.log(test); | |
var createStreamParams = { | |
sender: new NodeWallet( | |
// @ts-ignore | |
Keypair.fromSecretKey( | |
new Uint8Array( | |
JSON.parse(fs.readFileSync("/home/jd/.config/solana/id.json").toString()) | |
) | |
) | |
), // Wallet/Keypair signing the transaction, creating and sending the stream. | |
recipient: "Gf3sbc5Jb62jH7WcTr3WSNGDQLk1w6wcKMZXKK1SC1E6", // Solana recipient address. | |
mint: ata.account.data.parsed.info.mint, // SPL Token mint. | |
partner: "F9fER1Cb8hmjapWGZDukzcEYshAUDbSFpbXkj9QuBaQj", | |
cliff: (new Date().getTime() + 1000 * 60) / 1000, // Vesting contract "cliff" timestamp in seconds. | |
name: "flipped books nov 30", | |
cliffAmount: new BN(0), // Amount (smallest denomination) unlocked at the "cliff" timestamp. | |
depositedAmount: new BN(Math.floor(total / 4)), // Deposited amount of tokens (using smallest denomination). | |
start: (new Date().getTime() + 1000 * 60) / 1000, // Timestamp (in seconds) when the stream/token vesting starts. | |
period: 1 * 60 * 60 * 24 * 30, // Time step (period) in seconds per which the unlocking occurs. | |
//cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds. | |
// cliffAmount: getBN(100000000000, 9), // Amount unlocked at the "cliff" timestamp. | |
amountPerPeriod: new BN(Math.floor(total / periods / 4)), // Release rate: how many tokens are unlocked per each period. | |
canTopup: true, // setting to FALSE will effectively create a vesting contract. | |
cancelableBySender: false, // Whether or not sender can cancel the stream. | |
cancelableByRecipient: false, // Whether or not recipient can cancel the stream. | |
transferableBySender: true, // Whether or not sender can transfer the stream. | |
transferableByRecipient: true, // Whether or not recipient can transfer the stream. | |
automaticWithdrawal: false, // Whether or not a 3rd party can initiate withdraw in the name of recipient (currently not used, set it to FALSE). | |
isNative: false, | |
}; | |
try { | |
const { ixs, tx, metadata } = await client.createUnchecked( | |
createStreamParams | |
); | |
} catch (exception) { | |
console.log(exception); | |
} | |
var createStreamParams = { | |
sender: new NodeWallet( | |
// @ts-ignore | |
Keypair.fromSecretKey( | |
new Uint8Array( | |
JSON.parse(fs.readFileSync("/home/jd/.config/solana/id.json").toString()) | |
) | |
) | |
), // Wallet/Keypair signing the transaction, creating and sending the stream. | |
recipient: "Gf3sbc5Jb62jH7WcTr3WSNGDQLk1w6wcKMZXKK1SC1E6", // Solana recipient address. | |
mint: ata.account.data.parsed.info.mint, // SPL Token mint. | |
partner: "F9fER1Cb8hmjapWGZDukzcEYshAUDbSFpbXkj9QuBaQj", | |
cliff: (new Date().getTime() + 1000 * 60) / 1000, // Vesting contract "cliff" timestamp in seconds. | |
name: "flipped books nov 30", | |
cliffAmount: new BN(0), // Amount (smallest denomination) unlocked at the "cliff" timestamp. | |
depositedAmount: new BN(Math.floor(total / 4)), // Deposited amount of tokens (using smallest denomination). | |
start: (new Date().getTime() + 1000 * 60) / 1000, // Timestamp (in seconds) when the stream/token vesting starts. | |
period: 1 * 60 * 60 * 24 * 7, // Time step (period) in seconds per which the unlocking occurs. | |
//cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds. | |
// cliffAmount: getBN(100000000000, 9), // Amount unlocked at the "cliff" timestamp. | |
amountPerPeriod: new BN(Math.floor(total / periods / 4)), // Release rate: how many tokens are unlocked per each period. | |
canTopup: true, // setting to FALSE will effectively create a vesting contract. | |
cancelableBySender: false, // Whether or not sender can cancel the stream. | |
cancelableByRecipient: false, // Whether or not recipient can cancel the stream. | |
transferableBySender: true, // Whether or not sender can transfer the stream. | |
transferableByRecipient: true, // Whether or not recipient can transfer the stream. | |
automaticWithdrawal: false, // Whether or not a 3rd party can initiate withdraw in the name of recipient (currently not used, set it to FALSE). | |
isNative: false, | |
}; | |
try { | |
const { ixs, tx, metadata } = await client.createUnchecked( | |
createStreamParams | |
); | |
} catch (exception) { | |
console.log(exception); | |
} | |
var createStreamParams = { | |
sender: new NodeWallet( | |
// @ts-ignore | |
Keypair.fromSecretKey( | |
new Uint8Array( | |
JSON.parse(fs.readFileSync("/home/jd/.config/solana/id.json").toString()) | |
) | |
) | |
), // Wallet/Keypair signing the transaction, creating and sending the stream. | |
recipient: "Gf3sbc5Jb62jH7WcTr3WSNGDQLk1w6wcKMZXKK1SC1E6", // Solana recipient address. | |
mint: ata.account.data.parsed.info.mint, // SPL Token mint. | |
partner: "F9fER1Cb8hmjapWGZDukzcEYshAUDbSFpbXkj9QuBaQj", | |
cliff: (new Date().getTime() + 1000 * 60) / 1000, // Vesting contract "cliff" timestamp in seconds. | |
name: "flipped books nov 30", | |
cliffAmount: new BN(0), // Amount (smallest denomination) unlocked at the "cliff" timestamp. | |
depositedAmount: new BN(Math.floor(total / 4)), // Deposited amount of tokens (using smallest denomination). | |
start: (new Date().getTime() + 1000 * 60) / 1000, // Timestamp (in seconds) when the stream/token vesting starts. | |
period: 1 * 60 * 60, // Time step (period) in seconds per which the unlocking occurs. | |
//cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds. | |
// cliffAmount: getBN(100000000000, 9), // Amount unlocked at the "cliff" timestamp. | |
amountPerPeriod: new BN(Math.floor(total / periods / 4)), // Release rate: how many tokens are unlocked per each period. | |
canTopup: true, // setting to FALSE will effectively create a vesting contract. | |
cancelableBySender: false, // Whether or not sender can cancel the stream. | |
cancelableByRecipient: false, // Whether or not recipient can cancel the stream. | |
transferableBySender: true, // Whether or not sender can transfer the stream. | |
transferableByRecipient: true, // Whether or not recipient can transfer the stream. | |
automaticWithdrawal: false, // Whether or not a 3rd party can initiate withdraw in the name of recipient (currently not used, set it to FALSE). | |
isNative: false, | |
}; | |
try { | |
const { ixs, tx, metadata } = await client.createUnchecked( | |
createStreamParams | |
); | |
} catch (exception) { | |
console.log(exception); | |
} | |
var createStreamParams = { | |
sender: new NodeWallet( | |
// @ts-ignore | |
Keypair.fromSecretKey( | |
new Uint8Array( | |
JSON.parse(fs.readFileSync("/home/jd/.config/solana/id.json").toString()) | |
) | |
) | |
), // Wallet/Keypair signing the transaction, creating and sending the stream. | |
recipient: "Gf3sbc5Jb62jH7WcTr3WSNGDQLk1w6wcKMZXKK1SC1E6", // Solana recipient address. | |
mint: ata.account.data.parsed.info.mint, // SPL Token mint. | |
partner: "F9fER1Cb8hmjapWGZDukzcEYshAUDbSFpbXkj9QuBaQj", | |
cliff: (new Date().getTime() + 1000 * 60) / 1000, // Vesting contract "cliff" timestamp in seconds. | |
name: "flipped books nov 30", | |
cliffAmount: new BN(0), // Amount (smallest denomination) unlocked at the "cliff" timestamp. | |
depositedAmount: new BN(Math.floor(total / 4)), // Deposited amount of tokens (using smallest denomination). | |
start: (new Date().getTime() + 1000 * 60) / 1000, // Timestamp (in seconds) when the stream/token vesting starts. | |
period: 1 * 60 * 60 * 24, // Time step (period) in seconds per which the unlocking occurs. | |
//cliff: 1643363160, // Vesting contract "cliff" timestamp in seconds. | |
// cliffAmount: getBN(100000000000, 9), // Amount unlocked at the "cliff" timestamp. | |
amountPerPeriod: new BN(Math.floor(total / periods / 4)), // Release rate: how many tokens are unlocked per each period. | |
canTopup: true, // setting to FALSE will effectively create a vesting contract. | |
cancelableBySender: false, // Whether or not sender can cancel the stream. | |
cancelableByRecipient: false, // Whether or not recipient can cancel the stream. | |
transferableBySender: true, // Whether or not sender can transfer the stream. | |
transferableByRecipient: true, // Whether or not recipient can transfer the stream. | |
automaticWithdrawal: false, // Whether or not a 3rd party can initiate withdraw in the name of recipient (currently not used, set it to FALSE). | |
isNative: false, | |
}; | |
try { | |
const { ixs, tx, metadata } = await client.createUnchecked( | |
createStreamParams | |
); | |
} catch (exception) { | |
console.log(exception); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment