Skip to content

Commit

Permalink
Merge pull request #289 from invariant-labs/replace-code-script
Browse files Browse the repository at this point in the history
create replace code script
  • Loading branch information
zielvna authored Aug 8, 2024
2 parents 936a21a + b504b73 commit c894d98
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"create-pool": "npx tsc && node --experimental-wasm-modules target/create-pool.js",
"query-tickmap": "npx tsc && node --experimental-wasm-modules target/query-tickmap.js",
"swap": "npx tsc && node --experimental-wasm-modules target/swap.js",
"setup": "npx tsc && node --experimental-wasm-modules target/setup.js"
"setup": "npx tsc && node --experimental-wasm-modules target/setup.js",
"replace-code": "npx tsc && node --experimental-wasm-modules target/replace-code.js"
},
"keywords": [],
"author": "",
Expand Down
42 changes: 42 additions & 0 deletions scripts/src/replace-code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
Invariant,
Keyring,
Network,
TESTNET_INVARIANT_ADDRESS,
getCodeHash,
initPolkadotApi,
toPercentage
} from '@invariant-labs/a0-sdk'
import dotenv from 'dotenv'

dotenv.config()

const main = async () => {
const network = Network.Testnet
const api = await initPolkadotApi(network)

const keyring = new Keyring({ type: 'sr25519' })
const mnemonic = process.env.DEPLOYER_MNEMONIC ?? ''
const account = keyring.addFromMnemonic(mnemonic)
console.log(`Deployer: ${account.address}, Mnemonic: ${mnemonic}`)

const invariant = await Invariant.deploy(api, network, account, toPercentage(1n, 2n), {
storageDepositLimit: 100000000000,
refTime: 100000000000,
proofSize: 100000000000
})
console.log(`Invariant: ${invariant.contract.address.toString()}`)

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

const testnetInvariant = await Invariant.load(api, network, TESTNET_INVARIANT_ADDRESS, {
storageDepositLimit: 100000000000,
refTime: 100000000000,
proofSize: 100000000000
})
await testnetInvariant.setCode(account, codeHash)

process.exit(0)
}

main()

0 comments on commit c894d98

Please sign in to comment.