Skip to content

Commit

Permalink
soroban token stored with symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinsoza committed Dec 6, 2024
1 parent 805f71b commit c4d8ef1
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/managers/token.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address, Keypair, nativeToScVal, xdr } from "@stellar/stellar-sdk";
import { resolveInternalPath } from "../utils/utils";
import { SorobanToolkit } from "../config/toolkit";
import { deployContract, installContract } from "./contract";
import { Address, Keypair, nativeToScVal, xdr } from '@stellar/stellar-sdk';
import { resolveInternalPath } from '../utils/utils';
import { SorobanToolkit } from '../config/toolkit';
import { deployContract, installContract } from './contract';

/**
* Deploy the Soroban Token Contract.
Expand All @@ -10,34 +10,37 @@ import { deployContract, installContract } from "./contract";
* @returns The WASM hash of the deployed token contract.
*/
export async function deploySorobanToken(
toolkit: SorobanToolkit,
toolkit: SorobanToolkit,
name: string,
symbol: string,
decimals: number,
source?: Keypair
) {
toolkit.logVerbose("some", `Deploying Token: ${name} ${symbol}`);
const wasmKey = "soroban_token";
const wasmBuffer = resolveInternalPath("./soroban_token.wasm");
toolkit.logVerbose('some', `Deploying Token: ${name} ${symbol}`);
const wasmKey = 'soroban_token';
const wasmBuffer = resolveInternalPath('./soroban_token.wasm');

// Check if the WASM hash is already stored in the AddressBook
try {
const existingWasmHash = toolkit.addressBook.getWasmHash(wasmKey);
if (existingWasmHash) {
toolkit.logVerbose("full", `WASM is already installed`);
toolkit.logVerbose('full', `WASM is already installed`);
}
} catch {
// WASM not found in AddressBook, proceed with installation
toolkit.logVerbose("full", "WASM not found in AddressBook, proceeding with installation");
toolkit.logVerbose(
'full',
'WASM not found in AddressBook, proceeding with installation'
);
await installContract(toolkit, wasmKey, wasmBuffer, source);
}

const args: xdr.ScVal[] = [
new Address(source?.publicKey() ?? toolkit.admin.publicKey()).toScVal(),
nativeToScVal(decimals, {type: "u32"}),
nativeToScVal(name, {type: "string"}),
nativeToScVal(symbol, {type: "string"}),
nativeToScVal(decimals, { type: 'u32' }),
nativeToScVal(name, { type: 'string' }),
nativeToScVal(symbol, { type: 'string' }),
];

return await deployContract(toolkit, wasmKey, args, source);
}
return await deployContract(toolkit, wasmKey, symbol, args, source);
}

0 comments on commit c4d8ef1

Please sign in to comment.