cli support testToken command

This commit is contained in:
czl1378 2020-12-10 17:20:07 +08:00
parent 403ceb20a0
commit 2e00d6e1f9
5 changed files with 75 additions and 12 deletions

View File

@ -96,6 +96,12 @@ yarn solink feed \
--oracleAddress 4vH5L2jSNXGfcCx42N4sqPiMzEbp1PaQjQ6XngDBu8zR
```
## Test Token
```
yarn solink testToken --amount 10000000000
```
## Program Integration
Please refer to the integration-example

View File

@ -6,5 +6,13 @@
"btc:usd": {
"pubkey": "2jReuMRoYi3pKTF8YLnZEvT2bXcw56SdBxvssrVzu41v",
"secret": "9feec34f2157b6deefc08c2132b321fb379b65fe6901d07e9a4df69fe8bad75a19b9f4ea63a705fc4b822d70015680c6f1cb0d4df30548a673604680760a9d11"
},
"tokenOwner": {
"pubkey": "4MPE1P9k6vCcPwfSmMPx4258PhW8maN8afUc82c2LTvG",
"secret": "d06e46b91e189e2ee24f11668acd635df02a64019996f1b7e005a5fec906fe"
},
"tokenAccount": {
"pubkey": "A4xJLiJrtVigYjJ2NRUrcFza7eB7Y8XeGZh5KmkoxDs1",
"secret": "19c19ac59d379f3d669b6b5957bbf99060b2b15dd4d266b3f76e164f665c512986bc739598f0e5f0252b3e2fbd0c54a9a08b295a4c5c2901b91c6e3d1e8ace5c"
}
}

View File

@ -111,7 +111,6 @@ impl Instruction {
1 => {
let (&index, rest) = rest.split_first().ok_or(InvalidInstruction)?;
info!(format!("das index: {:?}", index));
let (description, _rest) = rest.split_at(32);
let description = description
.try_into()
@ -157,13 +156,4 @@ impl Instruction {
})
}
fn unpack_pubkey(input: &[u8]) -> Result<(Pubkey, &[u8]), ProgramError> {
if input.len() >= 32 {
let (key, rest) = input.split_at(32);
let pk = Pubkey::new(key);
Ok((pk, rest))
} else {
Err(Error::InvalidInstruction.into())
}
}
}

View File

@ -46,7 +46,6 @@ impl Processor {
description,
} => {
info!("Instruction: AddOracle");
info!(format!("index: {:?}", index));
Self::process_add_oracle(
accounts, index, description,
)

View File

@ -3,7 +3,10 @@ import { Command, option } from "commander"
import fs from "fs"
import path from "path"
import { BPFLoader, PublicKey, Wallet, NetworkName, solana, Deployer } from "solray"
import {
BPFLoader, PublicKey, Wallet, NetworkName,
solana, Deployer, SPLToken, ProgramAccount
} from "solray"
import dotenv from "dotenv"
@ -298,4 +301,61 @@ cli
})
})
cli
.command("testToken")
.description("create test token")
.option("--amount <number>", "amount of the test token")
.action(async (opts) => {
const { admin, aggregatorProgram, deployer } = await AdminContext.load()
const { amount } = opts
if (!amount || amount < 0) {
error("invalid amount")
}
const spltoken = new SPLToken(admin)
log(`create test token...`)
// 1. create token
const token = await spltoken.initializeMint({
mintAuthority: admin.account.publicKey,
decimals: 8,
})
// 2. create tokenOwner (program account)
const tokenOwner = await ProgramAccount.forSeed(
Buffer.from(token.publicKey.toBuffer()).slice(0, 30),
aggregatorProgram.publicKey
)
log(`create token acount...`)
// 3. create token account
const tokenAccount = await spltoken.initializeAccount({
token: token.publicKey,
owner: tokenOwner.pubkey
})
log(`mint ${amount} token to token account...`)
// 4. and then, mint tokens to that account
await spltoken.mintTo({
token: token.publicKey,
to: tokenAccount.publicKey,
amount: BigInt(amount),
authority: admin.account,
})
log({
token: token.publicKey.toBase58(),
tokenAccount: tokenAccount.publicKey.toBase58(),
tokenOwner: {
address: tokenOwner.address,
seed: tokenOwner.noncedSeed.toString("hex"),
nonce: tokenOwner.nonce,
}
})
})
cli.parse(process.argv)