Skip to content

Commit

Permalink
Saving work to switch over to another task rq
Browse files Browse the repository at this point in the history
  • Loading branch information
ltyu committed Mar 25, 2024
1 parent 69bb682 commit 1bbf245
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 49 deletions.
6 changes: 5 additions & 1 deletion solidity/contracts/token/HypERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ contract HypERC721 is ERC721EnumerableUpgradeable, TokenRouter {
function initialize(
uint256 _mintAmount,
string memory _name,
string memory _symbol
string memory _symbol,
address _hook,
address _interchainSecurityModule,
address _owner
) external initializer {
address owner = msg.sender;
_transferOwnership(owner);
Expand All @@ -32,6 +35,7 @@ contract HypERC721 is ERC721EnumerableUpgradeable, TokenRouter {
for (uint256 i = 0; i < _mintAmount; i++) {
_safeMint(owner, i);
}
_MailboxClient_initialize(_hook, _interchainSecurityModule, _owner);
}

function balanceOf(
Expand Down
113 changes: 65 additions & 48 deletions typescript/sdk/src/token/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ import {
ERC20Metadata,
ERC20RouterConfig,
ERC721RouterConfig,
HypERC20CollateralConfig,
HypERC20Config,
HypERC721CollateralConfig,
HypERC721Config,
TokenConfig,
TokenMetadata,
Expand Down Expand Up @@ -275,32 +273,47 @@ export class HypERC721Deployer extends GasRouterDeployer<
contractVerifier,
});
}
routerContractName<K extends keyof HypERC20Factories>(
routerContractName<K extends keyof HypERC721Factories>(
config: ERC721RouterConfig,
): K {
return TokenType[config.type] as K;
if (isCollateralConfig(config)) {
return (
isUriConfig(config) ? TokenType.collateralUri : TokenType.collateral
) as K;
} else if (isSyntheticConfig(config)) {
return (
isUriConfig(config) ? TokenType.syntheticUri : TokenType.synthetic
) as K;
} else {
return config.type as K;
}
}

async constructorArgs(
chain: ChainName,
config: HypERC20CollateralConfig,
config: ERC721RouterConfig,
): Promise<any> {
switch (config.type) {
case TokenType.fastSynthetic || TokenType.fastCollateral:
return [config.token, config.mailbox];
case TokenType.collateral:
return [config.token, config.mailbox];
case TokenType.collateralVault:
return [config.token, config.mailbox];
if (isCollateralConfig(config)) {
return [config.token, config.mailbox];
} else if (isSyntheticConfig(config)) {
return [config.mailbox];
} else {
throw new Error('Unknown collateral type when constructing arguments');
}
}

//@ts-ignore ignore for now until the contracts get fixed
async initializeArgs(
chain: ChainName,
config: HypERC20CollateralConfig,
config: ERC721RouterConfig,
): Promise<any> {
return config.token;
if (isCollateralConfig(config)) {
return [config.token, config.mailbox];
} else if (isSyntheticConfig(config)) {
return [config.totalSupply, config.name, config.symbol];
} else {
throw new Error('Unknown collateral type when initializing arguments');
}
}

static async fetchMetadata(
Expand Down Expand Up @@ -333,32 +346,32 @@ export class HypERC721Deployer extends GasRouterDeployer<
}
}

protected async deployCollateral(
chain: ChainName,
config: HypERC721CollateralConfig,
): Promise<HypERC721Collateral> {
return this.deployContract(
chain,
isUriConfig(config) ? TokenType.collateralUri : TokenType.collateral,
[config.token, config.mailbox],
);
}

protected async deploySynthetic(
chain: ChainName,
config: HypERC721Config,
): Promise<HypERC721> {
const router = await this.deployContract(
chain,
isUriConfig(config) ? TokenType.syntheticUri : TokenType.synthetic,
[config.mailbox],
);
await this.multiProvider.handleTx(
chain,
router.initialize(config.totalSupply, config.name, config.symbol),
);
return router;
}
// protected async deployCollateral(
// chain: ChainName,
// config: HypERC721CollateralConfig,
// ): Promise<HypERC721Collateral> {
// return this.deployContract(
// chain,
// isUriConfig(config) ? TokenType.collateralUri : TokenType.collateral,
// [config.token, config.mailbox],
// );
// }

// protected async deploySynthetic(
// chain: ChainName,
// config: HypERC721Config,
// ): Promise<HypERC721> {
// const router = await this.deployContract(
// chain,
// isUriConfig(config) ? TokenType.syntheticUri : TokenType.synthetic,
// [config.mailbox],
// );
// await this.multiProvider.handleTx(
// chain,
// router.initialize(config.totalSupply, config.name, config.symbol),
// );
// return router;
// }

router(contracts: HyperlaneContracts<HypERC721Factories>) {
for (const key of objKeys(hypERC721factories)) {
Expand All @@ -370,14 +383,18 @@ export class HypERC721Deployer extends GasRouterDeployer<
}

async deployContracts(chain: ChainName, config: HypERC721Config) {
let router: HypERC721 | HypERC721Collateral;
if (isCollateralConfig(config)) {
router = await this.deployCollateral(chain, config);
} else if (isSyntheticConfig(config)) {
router = await this.deploySynthetic(chain, config);
} else {
throw new Error('Invalid ERC721 token router config');
}
// let router: HypERC721 | HypERC721Collateral;
// if (isCollateralConfig(config)) {
// router = await this.deployCollateral(chain, config);
// } else if (isSyntheticConfig(config)) {
// router = await this.deploySynthetic(chain, config);
// } else {
// throw new Error('Invalid ERC721 token router config');
// }
const { [this.routerContractName(config)]: router } =
await super.deployContracts(chain, config);

await this.configureClient(chain, router as any, config);
return { [config.type]: router } as any;
}

Expand Down

0 comments on commit 1bbf245

Please sign in to comment.