Skip to content

Commit

Permalink
fix: contract migration for the new bytecode
Browse files Browse the repository at this point in the history
  • Loading branch information
nugaon committed Oct 3, 2023
1 parent 1aa9ee2 commit 0a6f877
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
14 changes: 7 additions & 7 deletions generator/contract-addresses.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"bzzToken": "0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab",
"swapPriceOrcale": "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24",
"swapFactory": "0xCfEB869F69431e42cdB54A4F4f105C19C080A601",
"postage": "0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B",
"postagePriceOracle": "0xC89Ce4735882C9F0f0FE26686c53074E09B0D550",
"stakeRegistry": "0xD833215cBcc3f914bD1C9ece3EE7BF8B14f841bb",
"redistribution": "0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7"
"bzzToken": "0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7",
"swapPriceOrcale": "0xe982E462b094850F12AF94d21D470e21bE9D0E9C",
"swapFactory": "0x59d3631c86BbE35EF041872d502F218A39FBa150",
"postage": "0x0290FB167208Af455bB137780163b7B7a9a10C16",
"postagePriceOracle": "0x9b1f7F645351AF3631a656421eD2e40f2802E6c0",
"stakeRegistry": "0x67B5656d60a809915323Bf2C40A8bEF15A152e3e",
"redistribution": "0x2612Af3A521c2df9EAF28422Ca335b04AdF3ac66"
}
21 changes: 12 additions & 9 deletions generator/migrations/1_initial.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ function getPostageStampBin(tokenAddress, adminAddress, minimumBucketDepth = 16)
return bin + tokenAddress + minimumBucketDepth + adminAddress
}

function getPostagePriceOracleBin(tokenAddress) {
function getPostagePriceOracleBin(tokenAddress, adminAddress) {
const binPath = Path.join(__dirname, '..', 'contracts', 'PostagePriceOracle.bytecode')
const bin = FS.readFileSync(binPath, 'utf8').toString().trim()
tokenAddress = prefixedAddressParamToByteCode(tokenAddress)
adminAddress = prefixedAddressParamToByteCode(adminAddress)

//add tokenaddress for param to the end of the bytecode
return bin + tokenAddress
return bin + tokenAddress + adminAddress
}

function getSwapPriceOracleBin(price, chequeValueDeduction) {
Expand All @@ -54,25 +55,27 @@ function getSwapPriceOracleBin(price, chequeValueDeduction) {
return bin + priceAbi + chequeValueAbi
}

function getStakeRegistryBin(tokenAddress) {
function getStakeRegistryBin(tokenAddress, adminAddress) {
const binPath = Path.join(__dirname, '..', 'contracts', 'StakeRegistry.bytecode')
const bin = FS.readFileSync(binPath, 'utf8').toString().trim()
tokenAddress = prefixedAddressParamToByteCode(tokenAddress)
adminAddress = prefixedAddressParamToByteCode(adminAddress)
const networkIdAbi = intToByteCode(NETWORK_ID)

//add tokenaddress and encoded network ID for param to the end of the bytecode
return bin + tokenAddress + networkIdAbi
return bin + tokenAddress + networkIdAbi + adminAddress
}

function getRedistributionBin(stakingAddress, postageContractAddress, oracleContractAddress) {
function getRedistributionBin(stakingAddress, postageContractAddress, oracleContractAddress, adminAddress) {
const binPath = Path.join(__dirname, '..', 'contracts', 'Redistribution.bytecode')
const bin = FS.readFileSync(binPath, 'utf8').toString().trim()
stakingAddress = prefixedAddressParamToByteCode(stakingAddress)
postageContractAddress = prefixedAddressParamToByteCode(postageContractAddress)
oracleContractAddress = prefixedAddressParamToByteCode(oracleContractAddress)
adminAddress = prefixedAddressParamToByteCode(adminAddress)

//add staking address, postage address and oracle contract address for param to the end of the bytecode
return bin + stakingAddress + postageContractAddress + oracleContractAddress
return bin + stakingAddress + postageContractAddress + oracleContractAddress + adminAddress
}

/** Returns back contract hash */
Expand Down Expand Up @@ -108,7 +111,7 @@ async function createSwapPriceOracleContract(creatorAccount, price = 100000, che
}

async function createPostagePriceOracleContract(creatorAccount, erc20ContractAddress) {
return createContract('PostagePriceOracle', getPostagePriceOracleBin(erc20ContractAddress), creatorAccount)
return createContract('PostagePriceOracle', getPostagePriceOracleBin(erc20ContractAddress, creatorAccount), creatorAccount)
}

async function createSimpleSwapFactoryContract(creatorAccount, erc20ContractAddress) {
Expand All @@ -120,7 +123,7 @@ async function createPostageStampContract(creatorAccount, erc20ContractAddress)
}

async function createStakeRegistryContract(creatorAccount, erc20ContractAddress) {
return createContract('StakeRegistry', getStakeRegistryBin(erc20ContractAddress), creatorAccount)
return createContract('StakeRegistry', getStakeRegistryBin(erc20ContractAddress, creatorAccount), creatorAccount)
}

async function createRedistributionContract(
Expand All @@ -131,7 +134,7 @@ async function createRedistributionContract(
) {
return createContract(
'Redistribution',
getRedistributionBin(stakeRegistryAddress, postageStampAddress, postagePriceOracleAddress),
getRedistributionBin(stakeRegistryAddress, postageStampAddress, postagePriceOracleAddress, creatorAccount),
creatorAccount,
)
}
Expand Down

0 comments on commit 0a6f877

Please sign in to comment.