Skip to content

Commit

Permalink
Merge pull request #284 from invariant-labs/update-setup-script
Browse files Browse the repository at this point in the history
Update setup script
  • Loading branch information
zielvna authored Jul 19, 2024
2 parents aca2dd1 + f725c7b commit 5cff475
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 170 deletions.
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions scripts/addresses.json

This file was deleted.

16 changes: 0 additions & 16 deletions scripts/call.sh

This file was deleted.

106 changes: 0 additions & 106 deletions scripts/deploy.sh

This file was deleted.

8 changes: 4 additions & 4 deletions sdk-usage/package-lock.json → scripts/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-usage/package.json → scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "sdk-test",
"name": "scripts",
"version": "1.0.0",
"description": "",
"main": "target/index.js",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 33 additions & 6 deletions sdk-usage/src/setup.ts → scripts/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,52 @@ const main = async () => {
const BTCAddress = await PSP22.deploy(api, account, 0n, 'Bitcoin', 'BTC', 8n)
const ETHAddress = await PSP22.deploy(api, account, 0n, 'Ether', 'ETH', 12n)
const USDCAddress = await PSP22.deploy(api, account, 0n, 'USDC', 'USDC', 6n)
const USDTAddress = await PSP22.deploy(api, account, 0n, 'Tether USD', 'USDT', 6n)
const SOLAddress = await PSP22.deploy(api, account, 0n, 'Solana', 'SOL', 9n)
const decimals = {
[BTCAddress]: 8n,
[ETHAddress]: 12n,
[USDCAddress]: 6n,
[USDTAddress]: 6n,
[SOLAddress]: 9n,
[TESTNET_WAZERO_ADDRESS]: 12n
}
console.log(`BTC: ${BTCAddress}, ETH: ${ETHAddress}, USDC: ${USDCAddress}`)
console.log(
`BTC: ${BTCAddress}, ETH: ${ETHAddress}, USDC: ${USDCAddress}, USDT: ${USDTAddress}, SOL: ${SOLAddress}`
)

const response = await fetch(
'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin,ethereum,aleph-zero'
'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=bitcoin,ethereum,aleph-zero,solana'
)
const data = await response.json()
const prices = {
[BTCAddress]: data.find((coin: any) => coin.id === 'bitcoin').current_price,
[ETHAddress]: data.find((coin: any) => coin.id === 'ethereum').current_price,
[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
}
console.log(
`BTC: ${prices[BTCAddress]}, ETH: ${prices[ETHAddress]}, USDC: ${prices[USDCAddress]}, AZERO: ${prices[TESTNET_WAZERO_ADDRESS]}`
`BTC: ${prices[BTCAddress]}, ETH: ${prices[ETHAddress]}, USDC: ${prices[USDCAddress]}, USDT: ${prices[USDTAddress]}, SOL: ${prices[SOLAddress]}, AZERO: ${prices[TESTNET_WAZERO_ADDRESS]}`
)

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(BTCAddress, ETHAddress, FEE_TIERS[1]), 130559235944405760n],
[newPoolKey(BTCAddress, USDCAddress, FEE_TIERS[1]), 7865049221247086n],
[newPoolKey(ETHAddress, USDCAddress, FEE_TIERS[1]), 3454809855596621497n]
[newPoolKey(BTCAddress, USDTAddress, FEE_TIERS[1]), 7865049221247086n],
[newPoolKey(BTCAddress, SOLAddress, FEE_TIERS[1]), 977937074251981n],
[newPoolKey(ETHAddress, USDCAddress, FEE_TIERS[1]), 3454809855596621497n],
[newPoolKey(ETHAddress, USDTAddress, FEE_TIERS[1]), 3454809855596621497n],
[newPoolKey(ETHAddress, SOLAddress, FEE_TIERS[1]), 423131631710393596n],
[newPoolKey(USDCAddress, USDTAddress, FEE_TIERS[1]), 9999818389598293n],
[newPoolKey(USDCAddress, SOLAddress, FEE_TIERS[1]), 24911294718392400n],
[newPoolKey(USDTAddress, SOLAddress, FEE_TIERS[1]), 24911294718392400n]
]
for (const [poolKey] of poolKeys) {
const price =
Expand All @@ -93,17 +110,21 @@ const main = async () => {
await psp22.mint(account, 2n ** 96n - 1n, BTCAddress)
await psp22.mint(account, 2n ** 96n - 1n, ETHAddress)
await psp22.mint(account, 2n ** 96n - 1n, USDCAddress)
await psp22.mint(account, 2n ** 96n - 1n, USDTAddress)
await psp22.mint(account, 2n ** 96n - 1n, SOLAddress)
await psp22.approve(account, invariant.contract.address.toString(), 2n ** 96n - 1n, BTCAddress)
await psp22.approve(account, invariant.contract.address.toString(), 2n ** 96n - 1n, ETHAddress)
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, {
storageDepositLimit: 100000000000,
refTime: 100000000000,
proofSize: 100000000000
})
const wazeroBalance = await wazero.balanceOf(account.address)
await wazero.withdraw(account, wazeroBalance)
await wazero.deposit(account, 30000n * 10n ** 12n)
await wazero.deposit(account, 50000n * 10n ** 12n)
await psp22.approve(
account,
invariant.contract.address.toString(),
Expand All @@ -113,6 +134,8 @@ const main = async () => {
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)
for (const [poolKey, amount] of poolKeys) {
const price =
Expand Down Expand Up @@ -141,11 +164,15 @@ const main = async () => {
const BTCAfter = await psp22.balanceOf(account.address, BTCAddress)
const ETHAfter = await psp22.balanceOf(account.address, ETHAddress)
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)
console.log(
`BTC: ${BTCBefore - BTCAfter}, ETH: ${ETHBefore - ETHAfter}, USDC: ${
USDCBefore - USDCAfter
}, AZERO: ${WAZEROBefore - WAZEROAfter}`
}, USDT: ${USDTBefore - USDTAfter}, SOL: ${SOLBefore - SOLAfter}, AZERO: ${
WAZEROBefore - WAZEROAfter
}`
)
console.log('Successfully created positions')

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion sdk-usage/tests.sh → scripts/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cd sdk
npm run node:start &
sleep 5
cd ..
cd sdk-usage
cd scripts
npm i
npm run start &
test_pid=$!
Expand Down
File renamed without changes.
8 changes: 0 additions & 8 deletions scripts/update_contract_addresses.sh

This file was deleted.

17 changes: 0 additions & 17 deletions scripts/update_contract_metadata.sh

This file was deleted.

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.12",
"version": "0.2.13",
"collaborators": [
"Invariant Labs"
],
Expand Down
10 changes: 6 additions & 4 deletions sdk/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ export const DEFAULT_LOCAL = 'ws://127.0.0.1:9944'

export const TESTNET_WAZERO_ADDRESS = '5EFDb7mKbougLtr5dnwd5KDfZ3wK55JPGPLiryKq4uRMPR46'

export const TESTNET_INVARIANT_ADDRESS = '5FxTEpmxrqr8Nwx7u1Y7heTFJiSe8xU1zZMfWmuC5f1UJMbf'
export const TESTNET_BTC_ADDRESS = '5DPvVudq6bCZ84jwFSsRwD7hDh4aaGh7XzpJUKXWDDHMHXaL'
export const TESTNET_ETH_ADDRESS = '5GmqniLhEcZCsn7vrer6yHzn7giapNG6N4fHx9exXHn29MvC'
export const TESTNET_USDC_ADDRESS = '5Cr6gjWk5cUavkbo9d6GTZBGjf4XavQf6WpiLkgT9UCmGQYP'
export const TESTNET_INVARIANT_ADDRESS = '5FU7vwthg7LDANp2Ljmw4gYdBY8rAF2UeS3rtM4sFZfnFNXv'
export const TESTNET_BTC_ADDRESS = '5FsnMq7UCvkaniSKiLdas2ujqRfKNiUehE21pQ4eCtZ4Hdgm'
export const TESTNET_ETH_ADDRESS = '5E3MV1sZQSav3BCf9aucDnZ79vRLWWE2eZbuy5dbNbj62qwN'
export const TESTNET_USDC_ADDRESS = '5Duwky8RAzWFKb8GNYcejjmxAAU2EkxPgeWCxMtvcsPdKtHm'
export const TESTNET_USDT_ADDRESS = '5FR9i4PwD9T3fokcLocyzWLCfUs7CstGRnwUSVovMDhnDxrz'
export const TESTNET_SOL_ADDRESS = '5CRMY8uap4JAQPcoJiaM4bHnuHjZLxRWRzYWh118BNiMsPW5'

export const FEE_GROWTH_DENOMINATOR = getFeeGrowthDenominator()
export const FIXED_POINT_DENOMINATOR = getFixedPointDenominator()
Expand Down

0 comments on commit 5cff475

Please sign in to comment.