Skip to content

Commit

Permalink
Merge pull request #295 from invariant-labs/update-scripts
Browse files Browse the repository at this point in the history
Update scripts
  • Loading branch information
zielvna authored Sep 10, 2024
2 parents bc8e414 + 9245067 commit 8a64dbf
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 48 deletions.
4 changes: 2 additions & 2 deletions scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions scripts/src/create-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
Invariant,
Keyring,
Network,
TESTNET_BTC_ADDRESS,
TESTNET_ETH_ADDRESS,
TESTNET_INVARIANT_ADDRESS,
BTC_ADDRESS,
ETH_ADDRESS,
INVARIANT_ADDRESS,
initPolkadotApi,
newFeeTier,
newPoolKey,
Expand All @@ -24,11 +24,11 @@ const main = async () => {
const account = keyring.addFromMnemonic(mnemonic)

const FEE_TIER = newFeeTier(toPercentage(1n, 4n), 1n)
const TOKEN_0_ADDRESS = TESTNET_ETH_ADDRESS
const TOKEN_1_ADDRESS = TESTNET_BTC_ADDRESS
const TOKEN_0_ADDRESS = ETH_ADDRESS[network]
const TOKEN_1_ADDRESS = BTC_ADDRESS[network]
const POOL_KEY = newPoolKey(TOKEN_0_ADDRESS, TOKEN_1_ADDRESS, FEE_TIER)

const invariant = await Invariant.load(api, network, TESTNET_INVARIANT_ADDRESS, {
const invariant = await Invariant.load(api, network, INVARIANT_ADDRESS[network], {
storageDepositLimit: 100000000000,
refTime: 100000000000,
proofSize: 100000000000
Expand Down
16 changes: 8 additions & 8 deletions scripts/src/create-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {
Keyring,
Network,
PSP22,
TESTNET_ETH_ADDRESS,
TESTNET_INVARIANT_ADDRESS,
TESTNET_USDC_ADDRESS,
ETH_ADDRESS,
INVARIANT_ADDRESS,
USDC_ADDRESS,
initPolkadotApi,
newFeeTier,
newPoolKey,
Expand All @@ -25,12 +25,12 @@ const main = async () => {
const account = keyring.addFromMnemonic(mnemonic)

const FEE_TIER = newFeeTier(toPercentage(1n, 4n), 1n)
const TOKEN_0_ADDRESS = TESTNET_USDC_ADDRESS
const TOKEN_1_ADDRESS = TESTNET_ETH_ADDRESS
const TOKEN_0_ADDRESS = USDC_ADDRESS[network]
const TOKEN_1_ADDRESS = ETH_ADDRESS[network]
const POOL_KEY = newPoolKey(TOKEN_0_ADDRESS, TOKEN_1_ADDRESS, FEE_TIER)
const AMOUNT = 1000000000000000000n

const invariant = await Invariant.load(api, network, TESTNET_INVARIANT_ADDRESS, {
const invariant = await Invariant.load(api, network, INVARIANT_ADDRESS[network], {
storageDepositLimit: 100000000000,
refTime: 100000000000,
proofSize: 100000000000
Expand All @@ -44,10 +44,10 @@ const main = async () => {
console.log(`Deployer: ${account.address}, Uri: ${mnemonic}`)

await psp22.mint(account, AMOUNT, TOKEN_0_ADDRESS)
await psp22.approve(account, TESTNET_INVARIANT_ADDRESS, AMOUNT, TOKEN_0_ADDRESS)
await psp22.approve(account, INVARIANT_ADDRESS[network], AMOUNT, TOKEN_0_ADDRESS)

await psp22.mint(account, AMOUNT, TOKEN_1_ADDRESS)
await psp22.approve(account, TESTNET_INVARIANT_ADDRESS, AMOUNT, TOKEN_1_ADDRESS)
await psp22.approve(account, INVARIANT_ADDRESS[network], AMOUNT, TOKEN_1_ADDRESS)

await invariant.createPosition(
account,
Expand Down
4 changes: 2 additions & 2 deletions scripts/src/query-tickmap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
Invariant,
Network,
TESTNET_INVARIANT_ADDRESS,
INVARIANT_ADDRESS,
Tickmap,
getMaxTick,
getMinTick,
Expand Down Expand Up @@ -33,7 +33,7 @@ const main = async () => {
const network = Network.Testnet
const api = await initPolkadotApi(network)

const invariant = await Invariant.load(api, network, TESTNET_INVARIANT_ADDRESS, {
const invariant = await Invariant.load(api, network, INVARIANT_ADDRESS[network], {
storageDepositLimit: 100000000000,
refTime: 100000000000,
proofSize: 100000000000
Expand Down
4 changes: 2 additions & 2 deletions scripts/src/replace-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Invariant,
Keyring,
Network,
TESTNET_INVARIANT_ADDRESS,
INVARIANT_ADDRESS,
getCodeHash,
initPolkadotApi,
toPercentage
Expand All @@ -29,7 +29,7 @@ const main = async () => {

const codeHash = await getCodeHash(api, invariant.contract.address.toString())

const testnetInvariant = await Invariant.load(api, network, TESTNET_INVARIANT_ADDRESS, {
const testnetInvariant = await Invariant.load(api, network, INVARIANT_ADDRESS[network], {
storageDepositLimit: 100000000000,
refTime: 100000000000,
proofSize: 100000000000
Expand Down
28 changes: 15 additions & 13 deletions scripts/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Network,
PSP22,
PoolKey,
TESTNET_WAZERO_ADDRESS,
WAZERO_ADDRESS,
WrappedAZERO,
calculateTick,
initPolkadotApi,
Expand Down Expand Up @@ -49,7 +49,7 @@ const main = async () => {
[USDCAddress]: 6n,
[USDTAddress]: 6n,
[SOLAddress]: 9n,
[TESTNET_WAZERO_ADDRESS]: 12n
[WAZERO_ADDRESS[network]]: 12n
}
console.log(
`BTC: ${BTCAddress}, ETH: ${ETHAddress}, USDC: ${USDCAddress}, USDT: ${USDTAddress}, SOL: ${SOLAddress}`
Expand All @@ -65,18 +65,20 @@ const main = async () => {
[USDCAddress]: 1,
[USDTAddress]: 1,
[SOLAddress]: data.find((coin: any) => coin.id === 'solana').current_price,
[TESTNET_WAZERO_ADDRESS]: data.find((coin: any) => coin.id === 'aleph-zero').current_price
[WAZERO_ADDRESS[network]]: data.find((coin: any) => coin.id === 'aleph-zero').current_price
}
console.log(
`BTC: ${prices[BTCAddress]}, ETH: ${prices[ETHAddress]}, USDC: ${prices[USDCAddress]}, USDT: ${prices[USDTAddress]}, SOL: ${prices[SOLAddress]}, AZERO: ${prices[TESTNET_WAZERO_ADDRESS]}`
`BTC: ${prices[BTCAddress]}, ETH: ${prices[ETHAddress]}, USDC: ${prices[USDCAddress]}, USDT: ${
prices[USDTAddress]
}, SOL: ${prices[SOLAddress]}, AZERO: ${prices[WAZERO_ADDRESS[network]]}`
)

const poolKeys: [PoolKey, bigint][] = [
[newPoolKey(TESTNET_WAZERO_ADDRESS, BTCAddress, FEE_TIERS[1]), 10804609546189987720n],
[newPoolKey(TESTNET_WAZERO_ADDRESS, ETHAddress, FEE_TIERS[1]), 4711830510277394610468n],
[newPoolKey(TESTNET_WAZERO_ADDRESS, USDCAddress, FEE_TIERS[1]), 272063075569508447756n],
[newPoolKey(TESTNET_WAZERO_ADDRESS, USDTAddress, FEE_TIERS[1]), 272063075569508447756n],
[newPoolKey(TESTNET_WAZERO_ADDRESS, SOLAddress, FEE_TIERS[1]), 37143700245489847211n],
[newPoolKey(WAZERO_ADDRESS[network], BTCAddress, FEE_TIERS[1]), 10804609546189987720n],
[newPoolKey(WAZERO_ADDRESS[network], ETHAddress, FEE_TIERS[1]), 4711830510277394610468n],
[newPoolKey(WAZERO_ADDRESS[network], USDCAddress, FEE_TIERS[1]), 272063075569508447756n],
[newPoolKey(WAZERO_ADDRESS[network], USDTAddress, FEE_TIERS[1]), 272063075569508447756n],
[newPoolKey(WAZERO_ADDRESS[network], SOLAddress, FEE_TIERS[1]), 37143700245489847211n],
[newPoolKey(BTCAddress, ETHAddress, FEE_TIERS[1]), 130559235944405760n],
[newPoolKey(BTCAddress, USDCAddress, FEE_TIERS[1]), 7865049221247086n],
[newPoolKey(BTCAddress, USDTAddress, FEE_TIERS[1]), 7865049221247086n],
Expand Down Expand Up @@ -117,7 +119,7 @@ const main = async () => {
await psp22.approve(account, invariant.contract.address.toString(), 2n ** 96n - 1n, USDCAddress)
await psp22.approve(account, invariant.contract.address.toString(), 2n ** 96n - 1n, USDTAddress)
await psp22.approve(account, invariant.contract.address.toString(), 2n ** 96n - 1n, SOLAddress)
const wazero = await WrappedAZERO.load(api, network, TESTNET_WAZERO_ADDRESS, {
const wazero = await WrappedAZERO.load(api, network, WAZERO_ADDRESS[network], {
storageDepositLimit: 100000000000,
refTime: 100000000000,
proofSize: 100000000000
Expand All @@ -129,14 +131,14 @@ const main = async () => {
account,
invariant.contract.address.toString(),
2n ** 96n - 1n,
TESTNET_WAZERO_ADDRESS
WAZERO_ADDRESS[network]
)
const BTCBefore = await psp22.balanceOf(account.address, BTCAddress)
const ETHBefore = await psp22.balanceOf(account.address, ETHAddress)
const USDCBefore = await psp22.balanceOf(account.address, USDCAddress)
const USDTBefore = await psp22.balanceOf(account.address, USDTAddress)
const SOLBefore = await psp22.balanceOf(account.address, SOLAddress)
const WAZEROBefore = await psp22.balanceOf(account.address, TESTNET_WAZERO_ADDRESS)
const WAZEROBefore = await psp22.balanceOf(account.address, WAZERO_ADDRESS[network])
for (const [poolKey, amount] of poolKeys) {
const price =
(1 / (prices[poolKey.tokenY] / prices[poolKey.tokenX])) *
Expand Down Expand Up @@ -166,7 +168,7 @@ const main = async () => {
const USDCAfter = await psp22.balanceOf(account.address, USDCAddress)
const USDTAfter = await psp22.balanceOf(account.address, USDTAddress)
const SOLAfter = await psp22.balanceOf(account.address, SOLAddress)
const WAZEROAfter = await psp22.balanceOf(account.address, TESTNET_WAZERO_ADDRESS)
const WAZEROAfter = await psp22.balanceOf(account.address, WAZERO_ADDRESS[network])
console.log(
`BTC: ${BTCBefore - BTCAfter}, ETH: ${ETHBefore - ETHAfter}, USDC: ${
USDCBefore - USDCAfter
Expand Down
8 changes: 4 additions & 4 deletions scripts/src/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
PSP22,
PoolKey,
SwapEvent,
TESTNET_INVARIANT_ADDRESS,
INVARIANT_ADDRESS,
calculateFee,
initPolkadotApi,
positionToTick,
Expand All @@ -28,7 +28,7 @@ const main = async () => {
const POSITION_ID = 0n
const SWAP_AMOUNT = 1000000n

const invariant = await Invariant.load(api, network, TESTNET_INVARIANT_ADDRESS, {
const invariant = await Invariant.load(api, network, INVARIANT_ADDRESS[network], {
storageDepositLimit: 100000000000,
refTime: 100000000000,
proofSize: 100000000000
Expand All @@ -45,15 +45,15 @@ const main = async () => {
await psp22.mint(account, SWAP_AMOUNT, positionBefore.poolKey.tokenX)
await psp22.approve(
account,
TESTNET_INVARIANT_ADDRESS,
INVARIANT_ADDRESS[network],
SWAP_AMOUNT,
positionBefore.poolKey.tokenX
)

await psp22.mint(account, SWAP_AMOUNT, positionBefore.poolKey.tokenY)
await psp22.approve(
account,
TESTNET_INVARIANT_ADDRESS,
INVARIANT_ADDRESS[network],
SWAP_AMOUNT,
positionBefore.poolKey.tokenY
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"skipLibCheck": true,
"rootDir": "./src",
"outDir": "./target",
"moduleResolution": "node"
"moduleResolution": "bundler"
},
"exclude": ["./target"]
}
4 changes: 2 additions & 2 deletions sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@invariant-labs/a0-sdk",
"version": "0.2.19",
"version": "0.2.20",
"collaborators": [
"Invariant Labs"
],
Expand Down
14 changes: 7 additions & 7 deletions sdk/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
getTokenAmountDenominator,
getTokenAmountScale
} from '@invariant-labs/a0-sdk-wasm/invariant_a0_wasm.js'
import { Network } from './network'
import { Network } from './network.js'

export const MAX_REF_TIME = 259058343000
export const DEFAULT_REF_TIME = 1250000000000
Expand All @@ -43,32 +43,32 @@ export const WAZERO_ADDRESS = {
}

export const INVARIANT_ADDRESS = {
[Network.Testnet]: '5HJJ5K4vGixAZo3fpG6niXKKRgvsxsur9CBuiVQGW9AHrnSo',
[Network.Testnet]: '5CQ4E1PnyPTURTCioBqka1CEhfJ5g4wwK8dVLtw97YnLGrkV',
[Network.Mainnet]: '5CvocBcChFccUkNGZpYf1mThQQDaY7ZxXEmdTXbTLqt1SaYQ',
[Network.Local]: ''
}
export const BTC_ADDRESS = {
[Network.Testnet]: '5GPoVZGgTGvXNK85MUYzVCtWgKDT4UPqQti4X5tZGm7ntxPz',
[Network.Testnet]: '5E195YpqcMmBKc8nCyfZS2zvq2Fzwx5QEvi7cwwzVv34KLkq',
[Network.Mainnet]: '5HW9QeCifdKt8gXwXVSE8z56njDQBhGfses1KJNFL68qius9',
[Network.Local]: ''
}
export const ETH_ADDRESS = {
[Network.Testnet]: '5FJvhnohVmEZNVxZatASSgFxpUNe1Nqxccd1gLxHrZoMGdy1',
[Network.Testnet]: '5FfgLxfPM1NPoJ9FoZWuAgeeS8dQFrEmhP7axuqqygAr6SMz',
[Network.Mainnet]: '5EEzffpXkfYKkdtmqNh9UNctYTjmbi9GfKKAWRTKKFh6F1FU',
[Network.Local]: ''
}
export const USDC_ADDRESS = {
[Network.Testnet]: '5Hj9dcaNhAMuhY8ju7crf1Uj4nJexVJWBdRf2WZGE3a78j3G',
[Network.Testnet]: '5GMmP8aBpq1xEeh7vjm7fNuo9kGcUGA2gLyA7YRTRP2waKFD',
[Network.Mainnet]: '5GDsB8Qm6CAoBi7rmM6TCKMQQUg8CiRzuH9YVyfcrwDKWoqB',
[Network.Local]: ''
}
export const USDT_ADDRESS = {
[Network.Testnet]: '5G91YrSRyJhuu6BswzSxcS5QTkoEwhhZpFay3LHMSFZBue4r',
[Network.Testnet]: '5GfpcwQmcqtXBy4NkFCQJ2udZeLSfRwUz1FESozDrNFXakHs',
[Network.Mainnet]: '5HX57YoV7h51NEKhpfXZAJk8RzLX4Uutp36S23RDMPZ424LY',
[Network.Local]: ''
}
export const SOL_ADDRESS = {
[Network.Testnet]: '5DGCxfxuKiE2JasJLstVSaYBXvQJQK7tr87ndWtgYtCqv8vs',
[Network.Testnet]: '5EKM5zqpysKscQhnMYBMR7cjWEZcm2SiEUoNojNrAAEYUYMc',
[Network.Mainnet]: '5F2xiTnahG1tFY3ZHyghh25JsjuCaamRnN7ddQjPEzwvdd3j',
[Network.Local]: ''
}
Expand Down

0 comments on commit 8a64dbf

Please sign in to comment.