@@ -2,6 +2,7 @@ import { task, types } from "hardhat/config";
2
2
import { Address , encodeAbiParameters , parseAbiParameters , parseEther } from "viem" ;
3
3
4
4
import { MarketConfig } from "../../chainDeploy" ;
5
+ import { prepareAndLogTransaction } from "../../chainDeploy/helpers/logging" ;
5
6
6
7
task ( "market:deploy" , "deploy market" )
7
8
. addParam ( "signer" , "Named account to use for tx" , "deployer" , types . string )
@@ -12,7 +13,8 @@ task("market:deploy", "deploy market")
12
13
. addParam ( "name" , "CToken name" , undefined , types . string )
13
14
. addOptionalParam ( "initialSupplyCap" , "Initial supply cap" , undefined , types . string )
14
15
. addOptionalParam ( "initialBorrowCap" , "Initial borrow cap" , undefined , types . string )
15
- . setAction ( async ( taskArgs , { viem, deployments } ) => {
16
+ . setAction ( async ( taskArgs , { viem, deployments, getNamedAccounts } ) => {
17
+ const { deployer } = await getNamedAccounts ( ) ;
16
18
const publicClient = await viem . getPublicClient ( ) ;
17
19
const comptroller = await viem . getContractAt ( "IonicComptroller" , taskArgs . comptroller as Address ) ;
18
20
@@ -51,28 +53,43 @@ task("market:deploy", "deploy market")
51
53
]
52
54
) ;
53
55
56
+ const feeDistributor = await viem . getContractAt ( "FeeDistributor" , config . feeDistributor ) ;
57
+ const owner = await feeDistributor . read . owner ( ) ;
54
58
// Test Transaction
55
- const errorCode = await comptroller . simulate . _deployMarket ( [
56
- delegateType ,
57
- constructorData ,
58
- implementationData ,
59
- collateralFactorBN
60
- ] ) ;
59
+ const errorCode = await comptroller . simulate . _deployMarket (
60
+ [ delegateType , constructorData , implementationData , collateralFactorBN ] ,
61
+ { account : owner }
62
+ ) ;
61
63
if ( errorCode . result !== 0n ) {
62
64
throw `Unable to _deployMarket: ${ errorCode . result } ` ;
63
65
}
64
- // Make actual Transaction
65
- const tx = await comptroller . write . _deployMarket ( [
66
- delegateType ,
67
- constructorData ,
68
- implementationData ,
69
- collateralFactorBN
70
- ] ) ;
71
- console . log ( "tx" , tx ) ;
66
+ if ( owner . toLowerCase ( ) !== deployer . toLowerCase ( ) ) {
67
+ await prepareAndLogTransaction ( {
68
+ contractInstance : comptroller ,
69
+ functionName : "_deployMarket" ,
70
+ args : [ delegateType , constructorData , implementationData , collateralFactorBN ] ,
71
+ description : `Deploy market for ${ config . underlying } ` ,
72
+ inputs : [
73
+ { internalType : "uint8" , name : "delegateType" , type : "uint8" } ,
74
+ { internalType : "bytes" , name : "constructorData" , type : "bytes" } ,
75
+ { internalType : "bytes" , name : "implementationData" , type : "bytes" } ,
76
+ { internalType : "uint256" , name : "collateralFactor" , type : "uint256" }
77
+ ]
78
+ } ) ;
79
+ } else {
80
+ // Make actual Transaction
81
+ const tx = await comptroller . write . _deployMarket ( [
82
+ delegateType ,
83
+ constructorData ,
84
+ implementationData ,
85
+ collateralFactorBN
86
+ ] ) ;
87
+ console . log ( "tx" , tx ) ;
72
88
73
- // Recreate Address of Deployed Market
74
- const receipt = await publicClient . waitForTransactionReceipt ( { hash : tx } ) ;
75
- if ( receipt . status !== "success" ) {
76
- throw `Failed to deploy market for ${ config . underlying } ` ;
89
+ // Recreate Address of Deployed Market
90
+ const receipt = await publicClient . waitForTransactionReceipt ( { hash : tx } ) ;
91
+ if ( receipt . status !== "success" ) {
92
+ throw `Failed to deploy market for ${ config . underlying } ` ;
93
+ }
77
94
}
78
95
} ) ;
0 commit comments