Skip to content

Commit

Permalink
Test instantiate2 on builder
Browse files Browse the repository at this point in the history
  • Loading branch information
tasiov committed Oct 1, 2023
1 parent 225d392 commit ab3e5aa
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 31 deletions.
96 changes: 96 additions & 0 deletions scripts/mainnet/multisig_wasm_store.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash

# This script is used to download infinity wasm files from github
# and generate the multisig store wasm message for deployment on mainnet.

# Download royalty registry

VERSION=v0.3.0
CONTRACT=stargaze_royalty_registry

CORE_CONTRACTS=(
"stargaze_royalty_registry"
)

for contract in "${CORE_CONTRACTS[@]}"; do
contract_tmp=$(echo $contract | tr '_' '-')

# If file exists then skip
if [ -f "./artifacts/${contract}.wasm" ]; then
echo "Skipping ${contract}.wasm"
continue
fi

version=${VERSION}
url=https://github.com/public-awesome/core/releases/download/${contract_tmp}/${version}/${contract}.wasm

if [ -z "$version" ]; then
echo "Version not found for $contract"
exit 1
fi

echo "Downloading $url"
curl -L --output "./artifacts/${contract}.wasm" "${url}"
done


Download infinity contracts

VERSION=v0.1.5
INFINITY_CONTRACTS=(
"infinity_builder"
"infinity_factory"
"infinity_global"
"infinity_index"
"infinity_pair"
"infinity_router"
)

for contract in "${INFINITY_CONTRACTS[@]}"; do
contract_tmp=$(echo $contract | tr '_' '-')

# If file exists then skip
if [ -f "./artifacts/${contract}.wasm" ]; then
echo "Skipping ${contract}.wasm"
continue
fi

url=https://github.com/tasiov/infinity-swap/releases/download/${VERSION}/${contract}.wasm
echo "Downloading $url"
response_code=$(curl -L --output "./artifacts/${contract}.wasm" --write-out "%{http_code}" "${url}")

# Check if the download was successful
if [ "$response_code" -ne 200 ]; then
echo "Error downloading ${contract}.wasm. HTTP status code: ${response_code}"
rm "./artifacts/${contract}.wasm"
exit 1
fi
done

echo "Generating wasm store messages for mainnet..."

FROM="stars1jwgchjqltama8z0v0smpagmnpjkc8sw8r03xzq"
CHAIN_ID="stargaze-1"
NODE="https://rpc.stargaze-apis.com:443"

for contract in "${CORE_CONTRACTS[@]}"; do
starsd tx wasm store artifacts/${contract}.wasm \
--from $FROM \
--chain-id "$CHAIN_ID" \
--node "$NODE" \
--keyring-backend os \
--gas-prices 1ustars \
--generate-only \
> ./tmp/unsigned_store_${contract}.json 2>&1
done

for contract in "${INFINITY_CONTRACTS[@]}"; do
starsd tx wasm store artifacts/${contract}.wasm \
--from $FROM \
--chain-id "$CHAIN_ID" \
--node "$NODE" \
--keyring-backend os \
--gas-prices 1ustars \
--generate-only \
> ./tmp/unsigned_store_${contract}.json 2>&1
done
94 changes: 63 additions & 31 deletions typescript/packages/e2e-tests/tests/setup/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import { SigningCosmWasmClient, instantiate2Address } from '@cosmjs/cosmwasm-stargate'
import chainConfig from '../../configs/chain_config.json'
import testAccounts from '../../configs/test_accounts.json'
import { getSigningClient } from '../utils/client'
import { readChecksumFile } from '../utils/file'
import { hexStringToUint8Array } from '../utils/string'
import { InstantiateMsg as RoyaltyRegistryInstantiateMsg } from '@stargazezone/core-types/lib/RoyaltyRegistry.types'
import { InstantiateMsg as InfinityBuilderInstantiateMsg } from '@stargazezone/infinity-types/lib/codegen/InfinityBuilder.types'
import { InstantiateMsg as VendingFactoryInstantiateMsg } from '@stargazezone/launchpad/src/VendingFactory.types'
Expand Down Expand Up @@ -96,6 +98,62 @@ export default class Context {
return instantiateResult
}

private instantiateInfinityBuilder = async (
client: SigningCosmWasmClient,
sender: string,
fairBurnAddress: string,
marketplaceAddress: string,
royaltyRegistryAddress: string,
) => {
let infinityBuilderInstantiateMsg: InfinityBuilderInstantiateMsg = {
code_ids: {
infinity_factory: this.codeIds[CONTRACT_MAP.INFINITY_FACTORY],
infinity_global: this.codeIds[CONTRACT_MAP.INFINITY_GLOBAL],
infinity_index: this.codeIds[CONTRACT_MAP.INFINITY_INDEX],
infinity_pair: this.codeIds[CONTRACT_MAP.INFINITY_PAIR],
infinity_router: this.codeIds[CONTRACT_MAP.INFINITY_ROUTER],
},
fair_burn: fairBurnAddress,
fair_burn_fee_percent: '0.005',
marketplace: marketplaceAddress,
max_royalty_fee_percent: '0.05',
max_swap_fee_percent: '0.10',
min_prices: [{ amount: '1000000', denom: 'ustars' }],
pair_creation_fee: { amount: '100000000', denom: 'ustars' },
royalty_registry: royaltyRegistryAddress,
}

let checksumFilePath = path.join(chainConfig.artifacts_path, 'checksums.txt')
const checksum = await readChecksumFile(checksumFilePath, 'infinity_builder.wasm')
const checksumUint8Array = hexStringToUint8Array(checksum)
const salt = new Uint8Array()
const address2 = instantiate2Address(checksumUint8Array, sender, salt, 'stars')

const instantiateInfinityBuilderResult = await client.instantiate2(
sender,
this.codeIds[CONTRACT_MAP.INFINITY_BUILDER],
salt,
infinityBuilderInstantiateMsg,
CONTRACT_MAP.INFINITY_BUILDER,
'auto',
)

this.addContractAddress(CONTRACT_MAP.INFINITY_BUILDER, instantiateInfinityBuilderResult.contractAddress)
console.log(
`Instantiated ${CONTRACT_MAP.INFINITY_BUILDER} contract with address ${instantiateInfinityBuilderResult.contractAddress}`,
)
assert(address2 === instantiateInfinityBuilderResult.contractAddress, 'address2 does not match')

_.forEach(instantiateInfinityBuilderResult.events, (event) => {
if (event.type === 'instantiate') {
let codeId = parseInt(event.attributes[1].value, 10)
let contractKey = this.getContractKeyByCodeId(codeId)
assert(contractKey, 'contractKey not found in wasm event attributes')
this.addContractAddress(contractKey, event.attributes[0].value)
}
})
}

private instantiateContracts = async () => {
let { client, address: sender } = this.getTestUser('user1')

Expand Down Expand Up @@ -139,39 +197,13 @@ export default class Context {
}
await this.instantiateContract(client, sender, CONTRACT_MAP.VENDING_FACTORY, vendingFactoryInstantiateMsg)

// Instantiate stargaze_reserve_auction
let infinityBuilderInstantiateMsg: InfinityBuilderInstantiateMsg = {
code_ids: {
infinity_factory: this.codeIds[CONTRACT_MAP.INFINITY_FACTORY],
infinity_global: this.codeIds[CONTRACT_MAP.INFINITY_GLOBAL],
infinity_index: this.codeIds[CONTRACT_MAP.INFINITY_INDEX],
infinity_pair: this.codeIds[CONTRACT_MAP.INFINITY_PAIR],
infinity_router: this.codeIds[CONTRACT_MAP.INFINITY_ROUTER],
},
fair_burn: instantiateFairBurnResult.contractAddress,
fair_burn_fee_percent: '0.005',
marketplace: instantiateFairBurnResult.contractAddress,
max_royalty_fee_percent: '0.05',
max_swap_fee_percent: '0.10',
min_prices: [{ amount: '1000000', denom: 'ustars' }],
pair_creation_fee: { amount: '100000000', denom: 'ustars' },
royalty_registry: instantiateRoyaltyRegistryResult.contractAddress,
}
let instantiateInfinityBuilderResult = await this.instantiateContract(
await this.instantiateInfinityBuilder(
client,
sender,
CONTRACT_MAP.INFINITY_BUILDER,
infinityBuilderInstantiateMsg,
instantiateFairBurnResult.contractAddress,
instantiateFairBurnResult.contractAddress,
instantiateRoyaltyRegistryResult.contractAddress,
)

_.forEach(instantiateInfinityBuilderResult.events, (event) => {
if (event.type === 'instantiate') {
let codeId = parseInt(event.attributes[1].value, 10)
let contractKey = this.getContractKeyByCodeId(codeId)
assert(contractKey, 'contractKey not found in wasm event attributes')
this.addContractAddress(contractKey, event.attributes[0].value)
}
})
}

private writeContext = () => {
Expand Down
20 changes: 20 additions & 0 deletions typescript/packages/e2e-tests/tests/utils/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import fs from 'fs'
import readline from 'readline'

export const readChecksumFile = async (checksumFilePath: string, target: string): Promise<string> => {
return new Promise((resolve, reject) => {
const readInterface = readline.createInterface(fs.createReadStream(checksumFilePath))

readInterface.on('line', function (line) {
const [checksum, fileName] = line.split(/\s+/) // Split by whitespace
if (fileName === target) {
readInterface.close() // Close the stream if the checksum is found
resolve(checksum)
}
})

readInterface.on('close', function () {
reject(`Checksum for ${target} not found.`)
})
})
}
10 changes: 10 additions & 0 deletions typescript/packages/e2e-tests/tests/utils/string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const hexStringToUint8Array = (hexString: string) => {
const length = hexString.length
const uint8Array = new Uint8Array(length / 2)

for (let i = 0; i < length; i += 2) {
uint8Array[i / 2] = parseInt(hexString.substring(i, i + 2), 16)
}

return uint8Array
}

0 comments on commit ab3e5aa

Please sign in to comment.