From 978bd44aea4e43a235a6441f3165d42a26a3a416 Mon Sep 17 00:00:00 2001 From: deuszx Date: Wed, 4 Oct 2023 17:19:06 +0200 Subject: [PATCH 1/6] Increase tokens seeded in the exemplary setups. --- scripts/constants.ts | 6 +++++- scripts/example_setup.ts | 14 +++++++------- scripts/utils.ts | 6 +++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/constants.ts b/scripts/constants.ts index 7722c862..f5656d46 100644 --- a/scripts/constants.ts +++ b/scripts/constants.ts @@ -2,7 +2,11 @@ import { parseUnits } from './shared'; export const DEADLINE = '111111111111111111'; export const ONE_WAZERO = parseUnits(1, 12).toString(); -export const ONE_STABLECOIN = parseUnits(100, 6).toString(); +export const ONE_HUNDRED_WAZERO = parseUnits(100, 12).toString(); +export const ONE_THOUSAND_WAZERO = parseUnits(1_000, 12).toString(); +export const ONE_STABLECOIN = parseUnits(1, 6).toString(); +export const ONE_HUNDRED_STABLECOIN = parseUnits(100, 6).toString(); +export const ONE_THOUSAND_STABLECOIN = parseUnits(1_000, 6).toString(); export const TOTAL_SUPPLY = parseUnits(1_000_000, 18).toString(); export const STABLE_TOTAL_SUPPLY = parseUnits(1_000_000, 6).toString(); export const DUMMY_ADDRESS = diff --git a/scripts/example_setup.ts b/scripts/example_setup.ts index 7b8bdc50..58eec956 100644 --- a/scripts/example_setup.ts +++ b/scripts/example_setup.ts @@ -5,7 +5,7 @@ import Token from '../types/contracts/psp22_token'; import Router from '../types/contracts/router_contract'; import Factory from '../types/contracts/factory_contract'; import * as token from './token'; -import { TOTAL_SUPPLY, STABLE_TOTAL_SUPPLY, ONE_STABLECOIN } from './constants'; +import { TOTAL_SUPPLY, STABLE_TOTAL_SUPPLY, ONE_THOUSAND_STABLECOIN } from './constants'; import { addLiquidityNative } from './utils'; import { parseUnits } from './shared'; @@ -70,23 +70,23 @@ async function main(): Promise { deployer.address, ); console.log('added aplo liquidity'); - await usdc.tx.approve(router.address, ONE_STABLECOIN); + await usdc.tx.approve(router.address, ONE_THOUSAND_STABLECOIN); console.log('approved usdc to spend by router'); await addLiquidityNative( router, usdc, - ONE_STABLECOIN, - ONE_STABLECOIN, + ONE_THOUSAND_STABLECOIN, + ONE_THOUSAND_STABLECOIN, deployer.address, ); console.log('added usdc liquidity'); - await usdt.tx.approve(router.address, ONE_STABLECOIN); + await usdt.tx.approve(router.address, ONE_THOUSAND_STABLECOIN); console.log('approved usdt to spend by router'); await addLiquidityNative( router, usdt, - ONE_STABLECOIN, - ONE_STABLECOIN, + ONE_THOUSAND_STABLECOIN, + ONE_THOUSAND_STABLECOIN, deployer.address, ); console.log('added usdt liquidity'); diff --git a/scripts/utils.ts b/scripts/utils.ts index 4d78cde4..48f62667 100644 --- a/scripts/utils.ts +++ b/scripts/utils.ts @@ -1,6 +1,6 @@ import Token from '../types/contracts/psp22_token'; import Router from '../types/contracts/router_contract'; -import { ONE_WAZERO, DEADLINE } from './constants'; +import { DEADLINE, ONE_THOUSAND_WAZERO } from './constants'; import { Addresses } from './shared'; import fs from 'fs'; @@ -24,11 +24,11 @@ export const addLiquidityNative = async ( token.address, amountDesired, amountMin, - ONE_WAZERO, + ONE_THOUSAND_WAZERO, to, DEADLINE, { - value: ONE_WAZERO, + value: ONE_THOUSAND_WAZERO, }, ); }; From 6ccfb88d82d915b9b8e93391f16ac345b649cedf Mon Sep 17 00:00:00 2001 From: deuszx Date: Wed, 4 Oct 2023 17:23:02 +0200 Subject: [PATCH 2/6] Rename tokens --- scripts/example_setup.ts | 38 +++++++++++++++++++------------------- scripts/token.ts | 4 ++-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/scripts/example_setup.ts b/scripts/example_setup.ts index 58eec956..6f6ec0dd 100644 --- a/scripts/example_setup.ts +++ b/scripts/example_setup.ts @@ -29,15 +29,15 @@ async function main(): Promise { /// Create tokens const tokenInitGas = await token.estimateInit(api, deployer); - const { address: aploAddress } = await tokenFactory.new( + const { address: dogeAddress } = await tokenFactory.new( TOTAL_SUPPLY, - 'Apollo Token', - 'APLO', + 'Doge Coin', + 'DOGE', 18, { gasLimit: tokenInitGas }, ); - console.log('aplo token address:', aploAddress); - const aplo = new Token(aploAddress, deployer, api); + console.log('doge coin address', dogeAddress); + const doge = new Token(dogeAddress, deployer, api); const { address: usdcAddress } = await tokenFactory.new( STABLE_TOTAL_SUPPLY, 'USD Coin', @@ -58,18 +58,18 @@ async function main(): Promise { const usdt = new Token(usdtAddress, deployer, api); /// Add liquidity - const aploAmount = parseUnits(100, 18).toString(); + const dogeAmount = parseUnits(100, 18).toString(); - await aplo.tx.approve(router.address, aploAmount); - console.log('approved aplo to spend by router'); + await doge.tx.approve(router.address, dogeAmount); + console.log('approved doge to spend by router'); await addLiquidityNative( router, - aplo, - aploAmount, - aploAmount, + doge, + dogeAmount, + dogeAmount, deployer.address, ); - console.log('added aplo liquidity'); + console.log('added doge liquidity'); await usdc.tx.approve(router.address, ONE_THOUSAND_STABLECOIN); console.log('approved usdc to spend by router'); await addLiquidityNative( @@ -93,17 +93,17 @@ async function main(): Promise { /// Query pair addresses const { - value: { ok: aploSbyAddress }, - } = await factory.query.getPair(aplo.address, wnativeAddress); - console.log('aploSbyAddress', aploSbyAddress); + value: { ok: dogeWAzeroAddress }, + } = await factory.query.getPair(doge.address, wnativeAddress); + console.log('dogeWAzeroAddress', dogeWAzeroAddress); const { - value: { ok: usdcSbyAddress }, + value: { ok: usdcWAzeroAddress }, } = await factory.query.getPair(usdc.address, wnativeAddress); - console.log('usdcSbyAddress', usdcSbyAddress); + console.log('usdcWAzeroAddress', usdcWAzeroAddress); const { - value: { ok: usdtSbyAddress }, + value: { ok: usdtWAzeroAddress }, } = await factory.query.getPair(usdt.address, wnativeAddress); - console.log('usdtSbyAddress', usdtSbyAddress); + console.log('usdtWAzeroAddress', usdtWAzeroAddress); await api.disconnect(); } diff --git a/scripts/token.ts b/scripts/token.ts index 1a08797c..9d9d9901 100644 --- a/scripts/token.ts +++ b/scripts/token.ts @@ -19,8 +19,8 @@ export async function estimateInit( ): Promise { return estimateContractInit(api, deployer, 'psp22_token.contract', [ TOTAL_SUPPLY, - 'Apollo Token', - 'APLO', + 'Doge Coin', + 'DOGE', 18, ]); } From 9144e740ef57f112016bf9e148128fa566b8cb31 Mon Sep 17 00:00:00 2001 From: deuszx Date: Wed, 4 Oct 2023 17:34:36 +0200 Subject: [PATCH 3/6] Separate creating PSP22 tokens from seeding liquidity --- package.json | 1 + scripts/add_liquidity.ts | 91 ++++++++++++++++++++++++++++++++++++++++ scripts/example_setup.ts | 70 +++++-------------------------- scripts/shared.ts | 3 ++ 4 files changed, 105 insertions(+), 60 deletions(-) create mode 100644 scripts/add_liquidity.ts diff --git a/package.json b/package.json index 6b867f81..0ec22c74 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "compile:release": "typechain-compiler --release --toolchain nightly-2023-08-10", "deploy:local": "source scripts/local_env && ts-node scripts/deploy.ts", "example:local": "source scripts/local_env && ts-node scripts/example_setup.ts", + "liquidity:local": "source scripts/local_env && ts-node scripts/add_liquidity.ts", "format": "prettier --write ." }, "dependencies": { diff --git a/scripts/add_liquidity.ts b/scripts/add_liquidity.ts new file mode 100644 index 00000000..85aa5ffb --- /dev/null +++ b/scripts/add_liquidity.ts @@ -0,0 +1,91 @@ +import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'; +import { loadAddresses } from './utils'; +import Token from '../types/contracts/psp22_token'; +import Router from '../types/contracts/router_contract'; +import Factory from '../types/contracts/factory_contract'; +import { ONE_THOUSAND_STABLECOIN } from './constants'; +import { addLiquidityNative } from './utils'; +import { parseUnits } from './shared'; + +// Create a new instance of contract +const wsProvider = new WsProvider(process.env.WS_NODE); +// Create a keyring instance +const keyring = new Keyring({ type: 'sr25519' }); + +async function main(): Promise { + const api = await ApiPromise.create({ provider: wsProvider }); + const deployer = keyring.addFromUri(process.env.AUTHORITY_SEED); + + const { + routerAddress, + factoryAddress, + wnativeAddress, + dogeAddress, + usdcAddress, + usdtAddress, + } = loadAddresses(); + + const router = new Router(routerAddress, deployer, api); + const factory = new Factory(factoryAddress, deployer, api); + + /// Create tokens + + const doge = new Token(dogeAddress, deployer, api); + const usdc = new Token(usdcAddress, deployer, api); + const usdt = new Token(usdtAddress, deployer, api); + + /// Add liquidity + const dogeAmount = parseUnits(1000, 18).toString(); + + await doge.tx.approve(router.address, dogeAmount); + console.log('approved 1000 DOGE to spend by router'); + await addLiquidityNative( + router, + doge, + dogeAmount, + dogeAmount, + deployer.address, + ); + console.log('added 1000 DOGE liquidity'); + await usdc.tx.approve(router.address, ONE_THOUSAND_STABLECOIN); + console.log('approved 1000 USDC to spend by router'); + await addLiquidityNative( + router, + usdc, + ONE_THOUSAND_STABLECOIN, + ONE_THOUSAND_STABLECOIN, + deployer.address, + ); + console.log('added 1000 USDC liquidity'); + await usdt.tx.approve(router.address, ONE_THOUSAND_STABLECOIN); + console.log('approved 1000 USDT to spend by router'); + await addLiquidityNative( + router, + usdt, + ONE_THOUSAND_STABLECOIN, + ONE_THOUSAND_STABLECOIN, + deployer.address, + ); + console.log('added 1000 USDT liquidity'); + + /// Query pair addresses + const { + value: { ok: dogeWAzeroAddress }, + } = await factory.query.getPair(doge.address, wnativeAddress); + console.log('dogeWAzeroAddress', dogeWAzeroAddress); + const { + value: { ok: usdcWAzeroAddress }, + } = await factory.query.getPair(usdc.address, wnativeAddress); + console.log('usdcWAzeroAddress', usdcWAzeroAddress); + const { + value: { ok: usdtWAzeroAddress }, + } = await factory.query.getPair(usdt.address, wnativeAddress); + console.log('usdtWAzeroAddress', usdtWAzeroAddress); + + await api.disconnect(); +} + +main().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/scripts/example_setup.ts b/scripts/example_setup.ts index 6f6ec0dd..990153cd 100644 --- a/scripts/example_setup.ts +++ b/scripts/example_setup.ts @@ -1,13 +1,8 @@ import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'; -import { loadAddresses } from './utils'; +import { loadAddresses, storeAddresses } from './utils'; import Token_factory from '../types/constructors/psp22_token'; -import Token from '../types/contracts/psp22_token'; -import Router from '../types/contracts/router_contract'; -import Factory from '../types/contracts/factory_contract'; import * as token from './token'; -import { TOTAL_SUPPLY, STABLE_TOTAL_SUPPLY, ONE_THOUSAND_STABLECOIN } from './constants'; -import { addLiquidityNative } from './utils'; -import { parseUnits } from './shared'; +import { TOTAL_SUPPLY, STABLE_TOTAL_SUPPLY } from './constants'; // Create a new instance of contract const wsProvider = new WsProvider(process.env.WS_NODE); @@ -20,14 +15,11 @@ async function main(): Promise { const tokenCodeHash = await token.upload(api, deployer); console.log('token code hash:', tokenCodeHash); - const { routerAddress, factoryAddress, wnativeAddress } = loadAddresses(); + const addresses = loadAddresses(); const tokenFactory = new Token_factory(api, deployer); - const router = new Router(routerAddress, deployer, api); - const factory = new Factory(factoryAddress, deployer, api); /// Create tokens - const tokenInitGas = await token.estimateInit(api, deployer); const { address: dogeAddress } = await tokenFactory.new( TOTAL_SUPPLY, @@ -37,7 +29,6 @@ async function main(): Promise { { gasLimit: tokenInitGas }, ); console.log('doge coin address', dogeAddress); - const doge = new Token(dogeAddress, deployer, api); const { address: usdcAddress } = await tokenFactory.new( STABLE_TOTAL_SUPPLY, 'USD Coin', @@ -46,7 +37,6 @@ async function main(): Promise { { gasLimit: tokenInitGas }, ); console.log('usdc token address:', usdcAddress); - const usdc = new Token(usdcAddress, deployer, api); const { address: usdtAddress } = await tokenFactory.new( STABLE_TOTAL_SUPPLY, 'Tether USD', @@ -55,55 +45,15 @@ async function main(): Promise { { gasLimit: tokenInitGas }, ); console.log('usdt token address:', usdtAddress); - const usdt = new Token(usdtAddress, deployer, api); - - /// Add liquidity - const dogeAmount = parseUnits(100, 18).toString(); - await doge.tx.approve(router.address, dogeAmount); - console.log('approved doge to spend by router'); - await addLiquidityNative( - router, - doge, - dogeAmount, - dogeAmount, - deployer.address, - ); - console.log('added doge liquidity'); - await usdc.tx.approve(router.address, ONE_THOUSAND_STABLECOIN); - console.log('approved usdc to spend by router'); - await addLiquidityNative( - router, - usdc, - ONE_THOUSAND_STABLECOIN, - ONE_THOUSAND_STABLECOIN, - deployer.address, - ); - console.log('added usdc liquidity'); - await usdt.tx.approve(router.address, ONE_THOUSAND_STABLECOIN); - console.log('approved usdt to spend by router'); - await addLiquidityNative( - router, - usdt, - ONE_THOUSAND_STABLECOIN, - ONE_THOUSAND_STABLECOIN, - deployer.address, - ); - console.log('added usdt liquidity'); + storeAddresses({ + ...addresses, + dogeAddress, + usdcAddress, + usdtAddress, + }); - /// Query pair addresses - const { - value: { ok: dogeWAzeroAddress }, - } = await factory.query.getPair(doge.address, wnativeAddress); - console.log('dogeWAzeroAddress', dogeWAzeroAddress); - const { - value: { ok: usdcWAzeroAddress }, - } = await factory.query.getPair(usdc.address, wnativeAddress); - console.log('usdcWAzeroAddress', usdcWAzeroAddress); - const { - value: { ok: usdtWAzeroAddress }, - } = await factory.query.getPair(usdt.address, wnativeAddress); - console.log('usdtWAzeroAddress', usdtWAzeroAddress); + console.log('psp22 token addresses stored'); await api.disconnect(); } diff --git a/scripts/shared.ts b/scripts/shared.ts index cb22ac6d..d4a7bb5a 100644 --- a/scripts/shared.ts +++ b/scripts/shared.ts @@ -7,4 +7,7 @@ export type Addresses = { factoryAddress: string; wnativeAddress: string; routerAddress: string; + dogeAddress?: string; + usdcAddress?: string; + usdtAddress?: string; }; From 77d1bc6b15722ed40d7a3beb34d818c92989593a Mon Sep 17 00:00:00 2001 From: deuszx Date: Wed, 4 Oct 2023 19:42:24 +0200 Subject: [PATCH 4/6] rm unused file --- .env.example | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .env.example diff --git a/.env.example b/.env.example deleted file mode 100644 index 5b857907..00000000 --- a/.env.example +++ /dev/null @@ -1 +0,0 @@ -PRIVATE_KEY=horn horn horn horn horn horn horn horn horn horn horn horn From 32238c042908a135040b00e2fe07b03208a8b04a Mon Sep 17 00:00:00 2001 From: deuszx Date: Wed, 4 Oct 2023 19:42:38 +0200 Subject: [PATCH 5/6] rename and update scripts --- package.json | 4 ++-- scripts/{example_setup.ts => create_tokens.ts} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename scripts/{example_setup.ts => create_tokens.ts} (100%) diff --git a/package.json b/package.json index 0ec22c74..8b4a3f1f 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "compile": "typechain-compiler --toolchain nightly-2023-08-10", "compile:release": "typechain-compiler --release --toolchain nightly-2023-08-10", "deploy:local": "source scripts/local_env && ts-node scripts/deploy.ts", - "example:local": "source scripts/local_env && ts-node scripts/example_setup.ts", - "liquidity:local": "source scripts/local_env && ts-node scripts/add_liquidity.ts", + "createTokens:local": "source scripts/local_env && ts-node scripts/create_tokens.ts", + "addLiquidity:local": "source scripts/local_env && ts-node scripts/add_liquidity.ts", "format": "prettier --write ." }, "dependencies": { diff --git a/scripts/example_setup.ts b/scripts/create_tokens.ts similarity index 100% rename from scripts/example_setup.ts rename to scripts/create_tokens.ts From cee641d0138f131a97b6ab7f557881f4b1669b85 Mon Sep 17 00:00:00 2001 From: deuszx <95355183+deuszx@users.noreply.github.com> Date: Wed, 4 Oct 2023 22:39:54 +0200 Subject: [PATCH 6/6] Update package.json Co-authored-by: Piotr --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8b4a3f1f..c7bf2bb9 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "compile": "typechain-compiler --toolchain nightly-2023-08-10", "compile:release": "typechain-compiler --release --toolchain nightly-2023-08-10", "deploy:local": "source scripts/local_env && ts-node scripts/deploy.ts", - "createTokens:local": "source scripts/local_env && ts-node scripts/create_tokens.ts", - "addLiquidity:local": "source scripts/local_env && ts-node scripts/add_liquidity.ts", + "create-tokens-local": "source scripts/local_env && ts-node scripts/create_tokens.ts", + "add-liquidity-local": "source scripts/local_env && ts-node scripts/add_liquidity.ts", "format": "prettier --write ." }, "dependencies": {