Skip to content

Commit 68678e6

Browse files
0xdavincheed10r
andauthored
[WORKFLOWS] Fix deploy framework (#1328)
Co-authored-by: didi <[email protected]>
1 parent d3d43d6 commit 68678e6

21 files changed

+237
-116
lines changed

packages/ethereum-contracts/contracts/interfaces/superfluid/ISuperTokenFactory.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ interface ISuperTokenFactory {
2424
error SUPER_TOKEN_FACTORY_NON_UPGRADEABLE_IS_DEPRECATED(); // 0x478b8e83
2525
error SUPER_TOKEN_FACTORY_ZERO_ADDRESS(); // 0x305c9e82
2626

27+
/**************************************************************************
28+
* Immutable Variables
29+
**************************************************************************/
30+
2731
/**
2832
* @dev Get superfluid host contract address
2933
*/
@@ -33,7 +37,7 @@ interface ISuperTokenFactory {
3337
function initialize() external;
3438

3539
/**
36-
* @dev Get the current super token logic used by the factory
40+
* @notice Get the canonical super token logic.
3741
*/
3842
function getSuperTokenLogic() external view returns (ISuperToken superToken);
3943

packages/ethereum-contracts/ops-scripts/deploy-framework.js

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const {
1515
builtTruffleContractLoader,
1616
sendGovernanceAction,
1717
} = require("./libs/common");
18-
const { ethers } = require("ethers");
18+
const {ethers} = require("ethers");
1919

2020
let resetSuperfluidFramework;
2121
let resolver;
@@ -95,11 +95,11 @@ async function deployContractIfCodeChanged(
9595
* (overriding env: ENABLE_APP_WHITELISTING)
9696
* @param {boolean} options.resetSuperfluidFramework Reset the superfluid framework deployment
9797
* (overriding env: RESET_SUPERFLUID_FRAMEWORK)
98-
* @param {boolean} options.protocolReleaseVersion Specify the protocol release version to be used
98+
* @param {string} options.protocolReleaseVersion Specify the protocol release version to be used
9999
* (overriding env: RELEASE_VERSION)
100-
* @param {boolean} options.outputFile Name of file where to log addresses of newly deployed contracts
100+
* @param {string} options.outputFile Name of file where to log addresses of newly deployed contracts
101101
* (overriding env: OUTPUT_FILE)
102-
* @param {boolean} options.cfaHookContract Address of the contract to be set up as CFA hooks receiver
102+
* @param {Address} options.cfaHookContract Address of the contract to be set up as CFA hooks receiver
103103
* (overriding env: CFA_HOOK_CONTRACT)
104104
*
105105
* Usage: npx truffle exec ops-scripts/deploy-framework.js
@@ -415,6 +415,7 @@ module.exports = eval(`(${S.toString()})({skipArgv: true})`)(async function (
415415
} else {
416416
contract.link(externalLibraryName, externalLibrary.address);
417417
}
418+
console.log(externalLibraryName, "address", externalLibrary.address);
418419
return externalLibrary;
419420
};
420421

@@ -448,7 +449,7 @@ module.exports = eval(`(${S.toString()})({skipArgv: true})`)(async function (
448449
)(superfluid.address, ida.address);
449450
} else {
450451
// NOTE that we are reusing the existing deployed external library
451-
// here as an optimization, this assumes that we do not change the
452+
// here as an optimization, this assumes that we do not change the
452453
// library code.
453454
// link library in order to avoid spurious code change detections
454455
let slotsBitmapLibraryAddress = ZERO_ADDRESS;
@@ -557,17 +558,35 @@ module.exports = eval(`(${S.toString()})({skipArgv: true})`)(async function (
557558
agreementsToUpdate.push(idaNewLogicAddress);
558559
}
559560

560-
// deploy new super token factory logic
561+
// deploy new super token factory logic (depends on SuperToken logic, which links to nft deployer library)
561562
const SuperTokenFactoryLogic = useMocks
562563
? SuperTokenFactoryMock
563564
: SuperTokenFactory;
564565

565566
const SuperTokenLogic = useMocks ? SuperTokenMock : SuperToken;
567+
568+
let superfluidNFTDeployerLibraryAddress = ZERO_ADDRESS;
569+
566570
const factoryAddress = await superfluid.getSuperTokenFactory.call();
571+
if (factoryAddress !== ZERO_ADDRESS) {
572+
const factoryContract = await SuperTokenFactoryLogic.at(factoryAddress);
573+
const superTokenContract = await SuperToken.at(
574+
await factoryContract.getSuperTokenLogic.call()
575+
);
576+
577+
try {
578+
superfluidNFTDeployerLibraryAddress =
579+
await superTokenContract.SUPERFLUID_NFT_DEPLOYER_LIBRARY_ADDRESS.call();
580+
} catch {
581+
console.warn(
582+
"SUPERFLUID_NFT_DEPLOYER_LIBRARY_ADDRESS does not exist on SuperToken contract yet - deployment required."
583+
);
584+
}
585+
}
567586

568-
// deploy new SuperfluidNFTDeployerLibrary if factory is not deployed
587+
// deploy new SuperfluidNFTDeployerLibrary if it is not deployed
569588
// link it to SuperToken logic contract
570-
if (factoryAddress === ZERO_ADDRESS) {
589+
if (superfluidNFTDeployerLibraryAddress === ZERO_ADDRESS) {
571590
await deployExternalLibraryAndLink(
572591
SuperfluidNFTDeployerLibrary,
573592
"SuperfluidNFTDeployerLibrary",
@@ -579,29 +598,32 @@ module.exports = eval(`(${S.toString()})({skipArgv: true})`)(async function (
579598
// here as an optimization, this assumes that we do not change the
580599
// library code.
581600
// link existing deployed external library to SuperToken logic contract
582-
let superfluidNFTDeployerLibraryAddress = ZERO_ADDRESS;
601+
583602
try {
584-
// get factory contract
585-
const factoryContract = await SuperTokenFactoryLogic.at(
586-
factoryAddress
587-
);
588-
const superTokenContract = await SuperToken.at(
589-
await factoryContract.getSuperTokenLogic.call()
590-
);
591-
superfluidNFTDeployerLibraryAddress =
592-
await superTokenContract.SUPERFLUID_NFT_DEPLOYER_LIBRARY_ADDRESS.call();
593-
if (process.env.IS_HARDHAT) {
594-
if (superfluidNFTDeployerLibraryAddress !== ZERO_ADDRESS) {
603+
// if the library is not deployed, deploy it and link it to SuperToken logic contract
604+
if (superfluidNFTDeployerLibraryAddress === ZERO_ADDRESS) {
605+
const superfluidNFTDeployerLibrary =
606+
await deployExternalLibraryAndLink(
607+
SuperfluidNFTDeployerLibrary,
608+
"SuperfluidNFTDeployerLibrary",
609+
"SUPERFLUID_NFT_DEPLOYER_LIBRARY_ADDRESS",
610+
SuperTokenLogic
611+
);
612+
superfluidNFTDeployerLibraryAddress =
613+
superfluidNFTDeployerLibrary.address;
614+
// else link the preexisting contract
615+
} else {
616+
if (process.env.IS_HARDHAT) {
595617
const lib = await SuperfluidNFTDeployerLibrary.at(
596618
superfluidNFTDeployerLibraryAddress
597619
);
598620
SuperTokenLogic.link(lib);
621+
} else {
622+
SuperTokenLogic.link(
623+
"SuperfluidNFTDeployerLibrary",
624+
superfluidNFTDeployerLibraryAddress
625+
);
599626
}
600-
} else {
601-
SuperTokenLogic.link(
602-
"SuperfluidNFTDeployerLibrary",
603-
superfluidNFTDeployerLibraryAddress
604-
);
605627
}
606628
} catch (e) {
607629
console.warn(
@@ -615,17 +637,21 @@ module.exports = eval(`(${S.toString()})({skipArgv: true})`)(async function (
615637
web3,
616638
SuperTokenFactoryLogic,
617639
async () => {
640+
console.log("checking if SuperTokenFactory needs to be redeployed...");
618641
// check if super token factory or super token logic changed
619642
try {
620643
if (factoryAddress === ZERO_ADDRESS) return true;
621644
const factory = await SuperTokenFactoryLogic.at(factoryAddress);
645+
console.log(" factory.getSuperTokenLogic.call()");
622646
const superTokenLogicAddress =
623647
await factory.getSuperTokenLogic.call();
624648
const superTokenLogic = await SuperTokenLogic.at(
625649
superTokenLogicAddress
626650
);
651+
console.log(" superTokenLogic.CONSTANT_OUTFLOW_NFT_LOGIC()");
627652
const constantOutflowNFTLogicAddress =
628653
await superTokenLogic.CONSTANT_OUTFLOW_NFT_LOGIC();
654+
console.log(" superTokenLogic.CONSTANT_INFLOW_NFT_LOGIC()");
629655
const constantInflowNFTLogicAddress =
630656
await superTokenLogic.CONSTANT_INFLOW_NFT_LOGIC();
631657
const superTokenFactoryCodeChanged = await codeChanged(
@@ -665,7 +691,7 @@ module.exports = eval(`(${S.toString()})({skipArgv: true})`)(async function (
665691
superTokenFactoryCodeChanged || superTokenLogicCodeChanged
666692
);
667693
} catch (e) {
668-
console.log(e.toString());
694+
console.log(` re-deploying SuperTokenFactory because checks didn't pass ${e.toString()}`);
669695
// recreate contract on any errors
670696
return true;
671697
}
@@ -690,11 +716,15 @@ module.exports = eval(`(${S.toString()})({skipArgv: true})`)(async function (
690716
ConstantOutflowNFT.new,
691717
"ConstantOutflowNFT.new"
692718
)(cfaV1Address);
719+
output += `CONSTANT_OUTFLOW_NFT_LOGIC_ADDRESS=${constantOutflowNFTLogic.address}\n`;
720+
693721
// deploy constant inflow nft logic contract
694722
const constantInflowNFTLogic = await web3tx(
695723
ConstantInflowNFT.new,
696724
"ConstantInflowNFT.new"
697725
)(cfaV1Address);
726+
output += `CONSTANT_INFLOW_NFT_LOGIC_ADDRESS=${constantInflowNFTLogic.address}\n`;
727+
698728
// deploy super token logic contract
699729
// it now takes the nft logic contracts as parameters
700730
const superTokenLogic = useMocks
@@ -709,6 +739,10 @@ module.exports = eval(`(${S.toString()})({skipArgv: true})`)(async function (
709739
constantOutflowNFTLogic.address,
710740
constantInflowNFTLogic.address
711741
);
742+
743+
console.log(`SuperToken new logic code address ${superTokenLogic.address}`);
744+
output += `SUPERFLUID_SUPER_TOKEN_LOGIC=${superTokenLogic.address}\n`;
745+
712746
superTokenFactoryLogic = await web3tx(
713747
SuperTokenFactoryLogic.new,
714748
"SuperTokenFactoryLogic.new"

packages/ethereum-contracts/ops-scripts/deploy-super-token.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
* @param {boolean} options.isTruffle Whether the script is used within native truffle framework
1515
* @param {Web3} options.web3 Injected web3 instance
1616
* @param {Address} options.from Address to deploy contracts from
17-
* @param {boolean} options.protocolReleaseVersion Specify the protocol release version to be used
17+
* @param {string} options.protocolReleaseVersion Specify the protocol release version to be used
1818
*
1919
* Usage: npx truffle exec ops-scripts/deploy-super-token.js : {UNDERLYING_TOKEN_SYMBOL_OR_ADDRESS}
2020
*

packages/ethereum-contracts/ops-scripts/deploy-unlisted-pure-super-token.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const {
1212
* @param {boolean} options.isTruffle Whether the script is used within native truffle framework
1313
* @param {Web3} options.web3 Injected web3 instance
1414
* @param {Address} options.from Address to deploy contracts from
15-
* @param {boolean} options.protocolReleaseVersion Specify the protocol release version to be used
15+
* @param {string} options.protocolReleaseVersion Specify the protocol release version to be used
1616
*
1717
* Usage: npx truffle exec ops-scripts/deploy-unlisted-pure-super-token.js : {NAME} {SYMBOL} {INITIAL SUPPLY}
1818
*/

packages/ethereum-contracts/ops-scripts/deploy-unlisted-super-token.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const {
1212
* @param {boolean} options.isTruffle Whether the script is used within native truffle framework
1313
* @param {Web3} options.web3 Injected web3 instance
1414
* @param {Address} options.from Address to deploy contracts from
15-
* @param {boolean} options.protocolReleaseVersion Specify the protocol release version to be used
15+
* @param {string} options.protocolReleaseVersion Specify the protocol release version to be used
1616
*
1717
* Usage: npx truffle exec scripts/deploy-unmanaged-super-token.js : {UNDERLYING_TOKEN_ADDRESS} {NAME} {SYMBOL}
1818
*/

packages/ethereum-contracts/ops-scripts/gov-create-new-app-registration-key.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const {
1212
* @param {boolean} options.isTruffle Whether the script is used within native truffle framework
1313
* @param {Web3} options.web3 Injected web3 instance
1414
* @param {Address} options.from Address to deploy contracts from
15-
* @param {boolean} options.protocolReleaseVersion Specify the protocol release version to be used
15+
* @param {string} options.protocolReleaseVersion Specify the protocol release version to be used
1616
*
1717
* Note: the key itself doesn't have much meaning, it could be "stolen" from a broadcast tx anyway.
1818
* But since it's bound to a deployer address, that doesn't really matter.

packages/ethereum-contracts/ops-scripts/gov-create-new-factory-registration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const {
1212
* @param {boolean} options.isTruffle Whether the script is used within native truffle framework
1313
* @param {Web3} options.web3 Injected web3 instance
1414
* @param {Address} options.from Address to deploy contracts from
15-
* @param {boolean} options.protocolReleaseVersion Specify the protocol release version to be used
15+
* @param {string}} options.protocolReleaseVersion Specify the protocol release version to be used
1616
*
1717
* Usage: npx truffle exec ops-scripts/gov-create-new-factory-registration.js : {FACTORY_ADDRESS}
1818
*/

packages/ethereum-contracts/ops-scripts/gov-set-3Ps-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const {
1212
* @param {boolean} options.isTruffle Whether the script is used within native truffle framework
1313
* @param {Web3} options.web3 Injected web3 instance
1414
* @param {Address} options.from Address to deploy contracts from
15-
* @param {boolean} options.protocolReleaseVersion Specify the protocol release version to be used
15+
* @param {string} options.protocolReleaseVersion Specify the protocol release version to be used
1616
*
1717
* Usage: npx truffle exec ops-scripts/gov-set-3Ps-config.js : {TOKEN ADDRESS} {LIQUIDATION PERIOD} {PATRICIAN PERIOD}
1818
* use TOKEN ADDRESS 0x0000000000000000000000000000000000000000 to set a default/fallback value

packages/ethereum-contracts/ops-scripts/gov-set-reward-address.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const {
1313
* @param {boolean} options.isTruffle Whether the script is used within native truffle framework
1414
* @param {Web3} options.web3 Injected web3 instance
1515
* @param {Address} options.from Address to deploy contracts from
16-
* @param {boolean} options.protocolReleaseVersion Specify the protocol release version to be used
16+
* @param {sring} options.protocolReleaseVersion Specify the protocol release version to be used
1717
*
1818
* Usage: npx truffle exec ops-scripts/gov-set-reward-address.js : {TOKEN ADDRESS} {REWARD ADDRESS}
1919
* If REWARD ADDRESS is 0x0000000000000000000000000000000000000000,

packages/ethereum-contracts/ops-scripts/gov-set-token-min-deposit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const {
1212
* @param {boolean} options.isTruffle Whether the script is used within native truffle framework
1313
* @param {Web3} options.web3 Injected web3 instance
1414
* @param {Address} options.from Address to deploy contracts from
15-
* @param {boolean} options.protocolReleaseVersion Specify the protocol release version to be used
15+
* @param {string} options.protocolReleaseVersion Specify the protocol release version to be used
1616
*
1717
* Usage: npx truffle exec ops-scripts/gov-set-token-min-deposit.js : {TOKEN ADDRESS} {MINIMUM DEPOSIT}
1818
*/

0 commit comments

Comments
 (0)