Skip to content

Commit

Permalink
Token type renaming (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmay authored Jul 1, 2020
1 parent b292d4c commit fc7a808
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 240 deletions.
30 changes: 15 additions & 15 deletions token-swap/js/cli/token-swap-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { newAccountWithLamports } from '../client/util/new-account-with-lamports
import { url } from '../url';
import { sleep } from '../client/util/sleep';

// The following globals are created by `createNewTokenSwap` and used by subsequent tests
// The following globals are created by `createTokenSwap` and used by subsequent tests
// Token swap
let tokenSwap: TokenSwap;
// authority of the token and accounts
Expand Down Expand Up @@ -116,7 +116,7 @@ export async function createTokenSwap(): Promise<void> {
);

// create pool
[tokenPool, tokenAccountPool] = await Token.createNewToken(
[tokenPool, tokenAccountPool] = await Token.createToken(
connection,
payer,
authority,
Expand All @@ -128,7 +128,7 @@ export async function createTokenSwap(): Promise<void> {
);

// create token A
[tokenA, tokenAccountA] = await Token.createNewToken(
[tokenA, tokenAccountA] = await Token.createToken(
connection,
payer,
owner.publicKey,
Expand All @@ -140,7 +140,7 @@ export async function createTokenSwap(): Promise<void> {
);

// create token B
[tokenB, tokenAccountB] = await Token.createNewToken(
[tokenB, tokenAccountB] = await Token.createToken(
connection,
payer,
owner.publicKey,
Expand Down Expand Up @@ -177,25 +177,25 @@ export async function createTokenSwap(): Promise<void> {
}

export async function deposit(): Promise<void> {
let userAccountA = await tokenA.newAccount(owner.publicKey);
let userAccountA = await tokenA.createAccount(owner.publicKey);
await tokenA.mintTo(owner, userAccountA, USER_AMOUNT);
let delegateAccountA = await tokenA.newAccount(authority, userAccountA);
let delegateAccountA = await tokenA.createAccount(authority, userAccountA);
await tokenA.approve(
owner,
userAccountA,
delegateAccountA,
USER_AMOUNT,
);
let userAccountB = await tokenB.newAccount(owner.publicKey);
let userAccountB = await tokenB.createAccount(owner.publicKey);
await tokenB.mintTo(owner, userAccountB, USER_AMOUNT);
let delegateAccountB = await tokenB.newAccount(authority, userAccountB);
let delegateAccountB = await tokenB.createAccount(authority, userAccountB);
await tokenB.approve(
owner,
userAccountB,
delegateAccountB,
USER_AMOUNT,
);
let newAccountPool = await tokenPool.newAccount(owner.publicKey);
let newAccountPool = await tokenPool.createAccount(owner.publicKey);
const [tokenProgramId,] = await GetPrograms(connection);

await tokenSwap.deposit(
Expand Down Expand Up @@ -237,9 +237,9 @@ export async function deposit(): Promise<void> {
}

export async function withdraw(): Promise<void> {
let userAccountA = await tokenA.newAccount(owner.publicKey);
let userAccountB = await tokenB.newAccount(owner.publicKey);
let delegateAccountPool = await tokenPool.newAccount(authority, tokenAccountPool);
let userAccountA = await tokenA.createAccount(owner.publicKey);
let userAccountB = await tokenB.createAccount(owner.publicKey);
let delegateAccountPool = await tokenPool.createAccount(authority, tokenAccountPool);
await tokenPool.approve(
owner,
tokenAccountPool,
Expand Down Expand Up @@ -283,16 +283,16 @@ export async function withdraw(): Promise<void> {
}

export async function swap(): Promise<void> {
let userAccountA = await tokenA.newAccount(owner.publicKey);
let userAccountA = await tokenA.createAccount(owner.publicKey);
await tokenA.mintTo(owner, userAccountA, USER_AMOUNT);
let delegateAccountA = await tokenA.newAccount(authority, userAccountA);
let delegateAccountA = await tokenA.createAccount(authority, userAccountA);
await tokenA.approve(
owner,
userAccountA,
delegateAccountA,
USER_AMOUNT,
);
let userAccountB = await tokenB.newAccount(owner.publicKey);
let userAccountB = await tokenB.createAccount(owner.publicKey);
const [tokenProgramId,] = await GetPrograms(connection);

await tokenSwap.swap(
Expand Down
9 changes: 5 additions & 4 deletions token-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl State {

/// Deserializes a spl_token `State`.
pub fn token_deserialize(info: &AccountInfo) -> Result<spl_token::state::Token, Error> {
if let Ok(spl_token::state::State::Token(token)) =
if let Ok(spl_token::state::State::Mint(token)) =
spl_token::state::State::deserialize(&info.data.borrow())
{
Ok(token)
Expand Down Expand Up @@ -838,7 +838,7 @@ mod tests {
account::Account, account_info::create_is_signer_account_infos, instruction::Instruction,
};
use spl_token::{
instruction::{new_account, new_token, TokenInfo},
instruction::{initialize_account, initialize_mint, TokenInfo},
state::State as SplState,
};

Expand Down Expand Up @@ -883,7 +883,8 @@ mod tests {

// create pool and pool account
do_process_instruction(
new_account(&program_id, &account_key, &authority_key, &token_key, None).unwrap(),
initialize_account(&program_id, &account_key, &authority_key, &token_key, None)
.unwrap(),
vec![
&mut account_account,
&mut Account::default(),
Expand All @@ -893,7 +894,7 @@ mod tests {
.unwrap();
let mut authority_account = Account::default();
do_process_instruction(
new_token(
initialize_mint(
&program_id,
&token_key,
Some(&account_key),
Expand Down
41 changes: 21 additions & 20 deletions token/inc/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ typedef struct Token_TokenInfo {
*/
typedef enum Token_TokenInstruction_Tag {
/**
* Creates a new token and deposit all the newly minted tokens in an account.
* Initializes a new mint and deposits all the newly minted tokens in an account.
*
* # Accounts expected by this instruction:
*
* 0. `[writable, signer]` New token to create.
* 0. `[writable, signer]` New mint to create.
* 1.
* * If supply is non-zero: `[writable]` Account to hold all the newly minted tokens.
* * If supply is zero: `[]` Owner of the token.
* 2. Optional: `[]` Owner of the token if supply is non-zero, if present then the token allows further minting of tokens.
* * If supply is zero: `[]` Owner of the mint.
* 2. Optional: `[]` Owner of the mint if supply is non-zero, if present then the
* token allows further minting of tokens.
*/
NewToken,
InitializeMint,
/**
* Creates a new account. The new account can either hold tokens or be a delegate
* Initializes a new account. The new account can either hold tokens or be a delegate
* for another account.
*
* # Accounts expected by this instruction:
Expand All @@ -48,7 +49,7 @@ typedef enum Token_TokenInstruction_Tag {
* 2. `[]` Token this account will be associated with.
* 3. Optional: `[]` Source account that this account will be a delegate for.
*/
NewAccount,
InitializeAccount,
/**
* Transfers tokens from one account to another either directly or via a delegate.
*
Expand Down Expand Up @@ -104,9 +105,9 @@ typedef enum Token_TokenInstruction_Tag {
Burn,
} Token_TokenInstruction_Tag;

typedef struct Token_NewToken_Body {
typedef struct Token_InitializeMint_Body {
Token_TokenInfo _0;
} Token_NewToken_Body;
} Token_InitializeMint_Body;

typedef struct Token_Transfer_Body {
uint64_t _0;
Expand All @@ -127,7 +128,7 @@ typedef struct Token_Burn_Body {
typedef struct Token_TokenInstruction {
Token_TokenInstruction_Tag tag;
union {
Token_NewToken_Body new_token;
Token_InitializeMint_Body initialize_mint;
Token_Transfer_Body transfer;
Token_Approve_Body approve;
Token_MintTo_Body mint_to;
Expand Down Expand Up @@ -163,7 +164,7 @@ typedef struct Token_COption_Pubkey {
} Token_COption_Pubkey;

/**
* Represents a token type identified and identified by its public key. Accounts
* Represents a token type identified by its public key. Accounts
* are associated with a specific token type and only accounts with
* matching types my inter-opt.
*/
Expand All @@ -173,8 +174,8 @@ typedef struct Token_Token {
*/
Token_TokenInfo info;
/**
* Optional token owner, used to mint new tokens. The owner may only
* be provided during token creation. If no owner is present then the token
* Optional owner, used to mint new tokens. The owner may only
* be provided during mint creation. If no owner is present then the mint
* has a fixed supply and no further tokens may be minted.
*/
Token_COption_Pubkey owner;
Expand Down Expand Up @@ -220,7 +221,7 @@ typedef struct Token_COption_AccountDelegate {
} Token_COption_AccountDelegate;

/**
* Account that holds or may delegate tokens.
* Account that holds tokens or may delegate tokens.
*/
typedef struct Token_Account {
/**
Expand All @@ -244,17 +245,17 @@ typedef struct Token_Account {
} Token_Account;

/**
* Token program states.
* Program states.
*/
typedef enum Token_State_Tag {
/**
* Unallocated state, may be initialized into another state.
*/
Unallocated,
/**
* A token type.
* A token mint.
*/
Token,
Mint,
/**
* An account that holds an amount of tokens or was delegated the authority to transfer
* tokens on behalf of another account.
Expand All @@ -266,9 +267,9 @@ typedef enum Token_State_Tag {
Invalid,
} Token_State_Tag;

typedef struct Token_Token_Body {
typedef struct Token_Mint_Body {
Token_Token _0;
} Token_Token_Body;
} Token_Mint_Body;

typedef struct Token_Account_Body {
Token_Account _0;
Expand All @@ -277,7 +278,7 @@ typedef struct Token_Account_Body {
typedef struct Token_State {
Token_State_Tag tag;
union {
Token_Token_Body token;
Token_Mint_Body mint;
Token_Account_Body account;
};
} Token_State;
12 changes: 6 additions & 6 deletions token/js/cli/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import {
loadTokenProgram,
createNewToken,
createNewAccount,
createToken,
createAccount,
transfer,
approveRevoke,
invalidApprove,
Expand All @@ -20,10 +20,10 @@ import {
async function main() {
console.log('Run test: loadTokenProgram');
await loadTokenProgram('../target/bpfel-unknown-unknown/release/spl_token.so');
console.log('Run test: createNewToken');
await createNewToken();
console.log('Run test: createNewAccount');
await createNewAccount();
console.log('Run test: createToken');
await createToken();
console.log('Run test: createAccount');
await createAccount();
console.log('Run test: transfer');
await transfer();
console.log('Run test: approveRevoke');
Expand Down
Loading

0 comments on commit fc7a808

Please sign in to comment.