Skip to content

Commit

Permalink
feat(sdk): add typescript SDK for memecoin creation (#285)
Browse files Browse the repository at this point in the history
This PR introduces a new TypeScript SDK package that enables
programmatic interaction with the Unruggable Meme on-chain factory on
Starknet. The SDK is designed to simplify memecoin creation.

NPM Package: https://www.npmjs.com/package/unruggable-sdk

Related Issue: #278
  • Loading branch information
remiroyc authored Dec 2, 2024
1 parent 299d5d6 commit 0eecbd9
Show file tree
Hide file tree
Showing 16 changed files with 559 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/constants/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import JediswapPair from '../abis/JediswapPair.json'
import Multicall from '../abis/Multicall.json'

export const TOKEN_CLASS_HASH = {
[constants.StarknetChainId.SN_SEPOLIA]: '0x05ba9aea47a8dd7073ab82b9e91721bdb3a2c1b259cffd68669da1454faa80ac',
[constants.StarknetChainId.SN_SEPOLIA]: '0x063ee878d3559583ceae80372c6088140e1180d9893aa65fbefc81f45ddaaa17',
[constants.StarknetChainId.SN_MAIN]: '0x063ee878d3559583ceae80372c6088140e1180d9893aa65fbefc81f45ddaaa17',
}

export const FACTORY_ADDRESSES = {
[constants.StarknetChainId.SN_SEPOLIA]: '0x076c3112e95994507c44c72b8dfb7f8d568a370d2f7c2d918ed9f55327671385',
[constants.StarknetChainId.SN_SEPOLIA]: '0x06b5096ba5a3c30e231e7b74ca565594d167a0a22d71cce0ebf9ae2b06584097',
[constants.StarknetChainId.SN_MAIN]: '0x01a46467a9246f45c8c340f1f155266a26a71c07bd55d36e8d1c7d0d438a2dbc',
}

export const EKUBO_POSITIONS_ADDRESSES = {
[constants.StarknetChainId.SN_SEPOLIA]: '0x073fa8432bf59f8ed535f29acfd89a7020758bda7be509e00dfed8a9fde12ddc',
[constants.StarknetChainId.SN_SEPOLIA]: '0x06a2aee84bb0ed5dded4384ddd0e40e9c1372b818668375ab8e3ec08807417e5',
[constants.StarknetChainId.SN_MAIN]: '0x02e0af29598b407c8716b17f6d2795eca1b471413fa03fb145a5e33722184067',
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function multiCallContract(
entrypoint: Entrypoint.AGGREGATE,
calldata: [calldata.length, ...calldata.flat()],
})
const raw = rawResult.result.slice(2)
const raw = rawResult.slice(2)

const result: string[][] = []
let idx = 0
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ACCOUNT_ADDRESS=
ACCOUNT_PRIVATE_KEY=
141 changes: 141 additions & 0 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Unruggable SDK

A TypeScript SDK for creating and managing Unruggable Memecoins on Starknet. This SDK provides a simple interface for deploying memecoin tokens and launching them on various AMMs.

## Installation

```bash
npm install unruggable-sdk
# or
yarn add unruggable-sdk
```

## Features

- Create new memecoin tokens
- Launch tokens on Ekubo AMM
- Launch tokens on Standard AMM (JediSwap)
- Collect Ekubo fees
- Built-in address validation and amount normalization
- TypeScript support with comprehensive type definitions

## Quick start

```typescript
import { createMemecoin, launchOnEkubo } from 'unruggable-sdk';
import { constants } from "starknet";

// Configure the SDK
const config = {
starknetProvider: yourProvider,
starknetChainId: constants.StarknetChainId.SN_MAIN,
};

// Create a new memecoin
const createResult = await createMemecoin(config, {
name: 'My Memecoin',
symbol: 'MMC',
initialSupply: '1000000000',
owner: ownerAddress,
starknetAccount: account,
});

// Launch on Ekubo
const launchResult = await launchOnEkubo(config, {
memecoinAddress: createResult.tokenAddress,
currencyAddress: ethAddress,
startingMarketCap: '1000000',
fees: '3.5',
holdLimit: '2.5',
antiBotPeriodInSecs: 300,
starknetAccount: account,
});
```

## API Reference

### Configuration

The SDK requires a configuration object with the following properties:

```typescript
interface Config {
starknetProvider: any; // Your Starknet provider
starknetChainId: string; // Starknet chain ID
}
```

### Functions
#### createMemecoin
Creates a new memecoin token on Starknet.

```typescript
async function createMemecoin(
config: Config,
parameters: {
name: string;
symbol: string;
initialSupply: string;
owner: string;
starknetAccount: any;
}
): Promise<{
transactionHash: string;
tokenAddress: string;
}>;
```

#### launchOnEkubo
Launches a memecoin on the Ekubo AMM.

```typescript
async function launchOnEkubo(
config: Config,
parameters: {
memecoinAddress: string;
currencyAddress: string;
startingMarketCap: string;
fees: string;
holdLimit: string;
antiBotPeriodInSecs: number;
starknetAccount: any;
}
): Promise<{
transactionHash: string;
}>;
```

#### launchOnStandardAMM
Launches a memecoin on JediSwap or StarkDefi

```typescript
async function launchOnStandardAMM(
config: Config,
parameters: {
memecoinAddress: string;
currencyAddress: string;
startingMarketCap: string;
holdLimit: string;
antiBotPeriodInSecs: number;
liquidityLockPeriod: number;
starknetAccount: any;
}
): Promise<{
transactionHash: string;
}>;
```

#### collectEkuboFees
Collects accumulated fees from Ekubo pool.

```typescript
async function collectEkuboFees(
config: Config,
parameters: {
memecoinAddress: string;
starknetAccount: any;
}
): Promise<{
transactionHash: string;
} | null>;
```
3 changes: 3 additions & 0 deletions packages/sdk/eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['../../.eslintrc.js', '@uniswap/eslint-config/node'],
}
48 changes: 48 additions & 0 deletions packages/sdk/examples/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { createMemecoin, Config, launchOnEkubo } from '../src'
import { RpcProvider, Account, constants } from 'starknet'
import { ETH_ADDRESSES } from 'core/constants'
;(async () => {
const starknetProvider = new RpcProvider({ nodeUrl: 'https://starknet-mainnet.public.blastapi.io' })

const starknetChainId = constants.StarknetChainId.SN_MAIN

const config: Config = {
starknetProvider,
starknetChainId,
}

const starknetAccount = new Account(
starknetProvider,
process.env.ACCOUNT_ADDRESS || '',
process.env.ACCOUNT_PRIVATE_KEY || '',
)

const result = await createMemecoin(config, {
initialSupply: '1',
name: 'R5MI',
owner: '0x0416ba0f3d21eda5a87d05d0acc827075792132697e9ed973f4390808790a11a',
starknetAccount,
symbol: 'R5MI',
})

if (result) {
const { tokenAddress, transactionHash } = result
console.log(`Creating memecoin... Transaction hash: ${transactionHash} - Token Address: ${tokenAddress}`)
await starknetProvider.waitForTransaction(transactionHash)

const launchResult = await launchOnEkubo(config, {
memecoinAddress: tokenAddress,
starknetAccount,
antiBotPeriodInSecs: 0,
fees: '0.3',
holdLimit: '1',
startingMarketCap: '100000',
currencyAddress: ETH_ADDRESSES[starknetChainId],
teamAllocations: [],
})

if (launchResult) {
console.log(`Launching on Ekubo... Transaction hash: ${launchResult.transactionHash}`)
}
}
})()
55 changes: 55 additions & 0 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "unruggable-sdk",
"version": "0.1.0",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"module": "dist/index.mjs",
"repository": {
"type": "git",
"url": "git+https://github.com/keep-starknet-strange/unruggable.meme.git"
},
"homepage": "https://www.unruggable.meme/",
"publishConfig": {
"access": "public"
},
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"browser": "./dist/index.global.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"example": "yarn with-env tsx ./examples/create.ts",
"with-env": "dotenv -e .env --",
"start": "tsup --watch",
"build": "tsup --clean true",
"test": "vitest run",
"test:watch": "vitest watch",
"lint": "eslint . --max-warnings=0 --ignore-path ../../.eslintignore",
"lint:fix": "eslint src --fix",
"prepare": "npm run build",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@uniswap/sdk-core": "^4.2.0",
"core": "*",
"moment": "^2.30.1",
"starknet": "6.11.0"
},
"peerDependencies": {
"starknet": ">=5.0.0"
},
"devDependencies": {
"@uniswap/eslint-config": "^1.2.0",
"dotenv-cli": "^7.4.3",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.2.5",
"tsup": "^8.0.2",
"typescript": "^5.4.5",
"vitest": "^1.5.0"
}
}
3 changes: 3 additions & 0 deletions packages/sdk/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const PERCENTAGE_INPUT_PRECISION = 2

export const STARKNET_MAX_BLOCK_TIME = 3600 * 2 // 2h
Loading

0 comments on commit 0eecbd9

Please sign in to comment.