-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve setup scripts. #37
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
978bd44
Increase tokens seeded in the exemplary setups.
deuszx 6ccfb88
Rename tokens
deuszx 9144e74
Separate creating PSP22 tokens from seeding liquidity
deuszx 77d1bc6
rm unused file
deuszx 32238c0
rename and update scripts
deuszx cee641d
Update package.json
deuszx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void> { | ||
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'; | ||
import { loadAddresses, storeAddresses } from './utils'; | ||
import Token_factory from '../types/constructors/psp22_token'; | ||
import * as token from './token'; | ||
import { TOTAL_SUPPLY, STABLE_TOTAL_SUPPLY } from './constants'; | ||
|
||
// 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<void> { | ||
const api = await ApiPromise.create({ provider: wsProvider }); | ||
const deployer = keyring.addFromUri(process.env.AUTHORITY_SEED); | ||
const tokenCodeHash = await token.upload(api, deployer); | ||
console.log('token code hash:', tokenCodeHash); | ||
|
||
const addresses = loadAddresses(); | ||
|
||
const tokenFactory = new Token_factory(api, deployer); | ||
|
||
/// Create tokens | ||
const tokenInitGas = await token.estimateInit(api, deployer); | ||
const { address: dogeAddress } = await tokenFactory.new( | ||
TOTAL_SUPPLY, | ||
'Doge Coin', | ||
'DOGE', | ||
18, | ||
{ gasLimit: tokenInitGas }, | ||
); | ||
console.log('doge coin address', dogeAddress); | ||
const { address: usdcAddress } = await tokenFactory.new( | ||
STABLE_TOTAL_SUPPLY, | ||
'USD Coin', | ||
'USDC', | ||
6, | ||
{ gasLimit: tokenInitGas }, | ||
); | ||
console.log('usdc token address:', usdcAddress); | ||
const { address: usdtAddress } = await tokenFactory.new( | ||
STABLE_TOTAL_SUPPLY, | ||
'Tether USD', | ||
'USDT', | ||
6, | ||
{ gasLimit: tokenInitGas }, | ||
); | ||
console.log('usdt token address:', usdtAddress); | ||
|
||
storeAddresses({ | ||
...addresses, | ||
dogeAddress, | ||
usdcAddress, | ||
usdtAddress, | ||
}); | ||
|
||
console.log('psp22 token addresses stored'); | ||
|
||
await api.disconnect(); | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is not relevant, as the line merely connects to ws.