11/* eslint-disable @typescript-eslint/unbound-method */
22import { HardhatRuntimeEnvironment } from "hardhat/types" ;
3- import { DeployFunction } from "hardhat-deploy/types" ;
3+ import {
4+ DeployFunction ,
5+ DeployOptions ,
6+ DeployResult ,
7+ } from "hardhat-deploy/types" ;
8+ import { MockERC20Dec18 , EntitiesRegistry } from "../typechain" ;
9+ import { ethers } from "hardhat" ;
410import {
511 kindsArr ,
612 eip712name ,
@@ -9,8 +15,56 @@ import {
915 protocolFee ,
1016 retailerFee ,
1117 minDeposit ,
18+ createSupplierId ,
19+ kinds ,
1220} from "../utils" ;
1321
22+ const setupToken = async (
23+ proxySettings : { owner : string ; proxyContract : string } ,
24+ owner : string ,
25+ deploy : ( name : string , options : DeployOptions ) => Promise < DeployResult > ,
26+ name : string ,
27+ contractName : string ,
28+ tokenName : string ,
29+ tokenSymbol : string ,
30+ networkName : string
31+ ) : Promise < DeployResult > => {
32+ const options : DeployOptions = {
33+ contract : contractName ,
34+ proxy : {
35+ ...proxySettings ,
36+ execute : {
37+ methodName : "initialize" ,
38+ args : [ tokenName , tokenSymbol , owner ] ,
39+ } ,
40+ } ,
41+ from : owner ,
42+ log : true ,
43+ autoMine : true ,
44+ } ;
45+ const token = await deploy ( name , options ) ;
46+
47+ if ( token . newlyDeployed ) {
48+ console . log (
49+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
50+ `${ tokenSymbol } token deployed at ${ token . address } using ${ token . receipt ?. gasUsed } gas`
51+ ) ;
52+ }
53+
54+ if ( networkName === "hardhat" ) {
55+ const tokenContract = < MockERC20Dec18 > await ethers . getContract ( name ) ;
56+ const signer = await ethers . getSigner ( owner ) ;
57+ tokenContract . connect ( signer ) ;
58+ await Promise . all (
59+ [ "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" ] . map ( ( addr ) =>
60+ tokenContract . mint ( addr , "1000000000000000000000000" )
61+ )
62+ ) ;
63+ }
64+
65+ return token ;
66+ } ;
67+
1468const func : DeployFunction = async function ( hre : HardhatRuntimeEnvironment ) {
1569 const { network, deployments, getNamedAccounts } = hre ;
1670
@@ -26,6 +80,56 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
2680 proxyContract : "OpenZeppelinTransparentProxy" ,
2781 } ;
2882
83+ // Setup testing stable coins
84+
85+ // STABLE Decimals 6 no permit
86+ await setupToken (
87+ PROXY_SETTINGS_WITH_UPGRADE ,
88+ owner ,
89+ deploy ,
90+ "STABLE6" ,
91+ "MockERC20Dec6" ,
92+ "Stable6NoPermit" ,
93+ "STABLE6" ,
94+ network . name
95+ ) ;
96+
97+ // STABLE Decimals 6 with permit
98+ await setupToken (
99+ PROXY_SETTINGS_WITH_UPGRADE ,
100+ owner ,
101+ deploy ,
102+ "STABLE6PERMIT" ,
103+ "MockERC20Dec6Permit" ,
104+ "Stable6Permit" ,
105+ "STABLE6PERMIT" ,
106+ network . name
107+ ) ;
108+
109+ // STABLE Decimals 18 no permit
110+ await setupToken (
111+ PROXY_SETTINGS_WITH_UPGRADE ,
112+ owner ,
113+ deploy ,
114+ "STABLE18" ,
115+ "MockERC20Dec18" ,
116+ "Stable18NoPermit" ,
117+ "STABLE18" ,
118+ network . name
119+ ) ;
120+
121+ // STABLE Decimals 18 with permit
122+ await setupToken (
123+ PROXY_SETTINGS_WITH_UPGRADE ,
124+ owner ,
125+ deploy ,
126+ "STABLE18PERMIT" ,
127+ "MockERC20Dec18Permit" ,
128+ "Stable18Permit" ,
129+ "STABLE18PERMIT" ,
130+ network . name
131+ ) ;
132+
29133 // Simple ERC20 token
30134 const erc20 = await deploy ( "MockERC20Dec18" , {
31135 proxy : {
@@ -66,6 +170,19 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
66170 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
67171 `MockERC20Dec18Permit (lif) was deployed at: ${ lif . address } using ${ lif . receipt ?. gasUsed } gas`
68172 ) ;
173+
174+ if ( network . name === "hardhat" ) {
175+ const lifContract = < MockERC20Dec18 > (
176+ await ethers . getContract ( "MockERC20Dec18Permit" )
177+ ) ;
178+ const signer = await ethers . getSigner ( owner ) ;
179+ lifContract . connect ( signer ) ;
180+ await Promise . all (
181+ [ "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" ] . map ( ( addr ) =>
182+ lifContract . mint ( addr , "1000000000000000000000000" )
183+ )
184+ ) ;
185+ }
69186 }
70187
71188 // Protocol Config
@@ -117,6 +234,47 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
117234 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
118235 `EntitiesRegistry was deployed at: ${ entities . address } using ${ entities . receipt ?. gasUsed } gas`
119236 ) ;
237+
238+ if ( network . name === "hardhat" ) {
239+ const supplierOwner = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" ;
240+ const supplierSalt =
241+ "0x4c51462692236a1cc8dcde78386cb02a1a59828a92932336770a08cae542c2e8" ;
242+ const supplierId = createSupplierId (
243+ "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" ,
244+ supplierSalt
245+ ) ;
246+
247+ const entities = < EntitiesRegistry > (
248+ await ethers . getContract ( "EntitiesRegistry" )
249+ ) ;
250+ const signer = await ethers . getSigner ( owner ) ;
251+ entities . connect ( signer ) ;
252+
253+ await entities . register (
254+ kinds . supplier ,
255+ supplierSalt ,
256+ "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
257+ ) ;
258+ console . log ( `Registered supplier #${ supplierId } ` ) ;
259+
260+ const supplierSigner = await ethers . getSigner ( supplierOwner ) ;
261+ entities . connect ( supplierSigner ) ;
262+
263+ const lifContract = < MockERC20Dec18 > (
264+ await ethers . getContract ( "MockERC20Dec18Permit" )
265+ ) ;
266+ lifContract . connect ( supplierSigner ) ;
267+
268+ await lifContract . approve ( entities . address , minDeposit ) ;
269+
270+ await entities [ "addDeposit(bytes32,uint256)" ] ( supplierId , minDeposit ) ;
271+
272+ console . log ( `LIF deposit added for supplier #${ supplierId } ` ) ;
273+
274+ await entities . toggleEntity ( supplierId ) ;
275+
276+ console . log ( `Enabled supplier #${ supplierId } ` ) ;
277+ }
120278 }
121279
122280 // Market
0 commit comments