forked from connext/chaindata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
185 lines (150 loc) · 42.7 KB
/
deploy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
const {
deployContract,
deployFactory,
getCreate2Address,
isDeployed
} = require("solidity-create2-deployer");
const ethers = require("ethers");
const fetch = require('node-fetch');
const fs = require('fs')
const util = require('util');
const request = require('request-promise-native')
const readFile = util.promisify(fs.readFile);
/*
FILL IN THE BELOW
* provider
* verifyURL
* privateKey
* apikey
* mpcAddress
* constructorArgs
*/
/*
PROVIDERS
BSC = https://bsc-dataseed1.binance.org/
FTM = https://rpc.fantom.network
xDAI =https://rpc.xdaichain.com
Polygon (Matic) = https://rpc-mainnet.matic.network
Heco = https://http-testnet.hecochain.com
*/
const provider = new ethers.providers.JsonRpcProvider("https://bsc-dataseed1.binance.org/");
const verifyURL = 'https://api.bscscan.com/api'; // api.etherscan.io for Ethereum, api.ftmscam.com for Fantom, etc
const privateKey = ''; // private key of wallet being used to deploy
const apikey = ''; // apiKey for etherscan / bscscan / ftmscan / etc
/*
MPC ADDRESS
BSC = 0x533e3c0e6b48010873B947bddC4721b1bDFF9648
FTM = 0xC564EE9f21Ed8A2d8E7e76c085740d5e4c5FaFbE
xDAI =0x2F10c5eE93ac666dA72195abA8a49FD6D27fA02F
Polygon (Matic) = 0x668b9734FfE9eE8a01d4Ade3362De71E8989EA87
*/
const mpcAddress = "0x533e3c0e6b48010873B947bddC4721b1bDFF9648";
const signer = new ethers.Wallet(privateKey, provider);
const constructorArgs = ["Token Name", "Symbol", "decimals", "underlying", signer.address];
/*
FILL IN THE ABOVE
*/
const salt = 2021;
const factoryAddress = "0x54F5A04417E29FF5D7141a6d33cb286F50d5d50e";
const anyswapERC20 = '0x60e06040526202a3006005553480156200001857600080fd5b5060405162002f7f38038062002f7f8339810160408190526200003b91620003c5565b8451620000509060009060208801906200023d565b508351620000669060019060208701906200023d565b507fff0000000000000000000000000000000000000000000000000000000000000060f884901b166080526001600160601b0319606083901b1660a0526001600160a01b038216156200013a57816001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015620000ed57600080fd5b505afa15801562000102573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000128919062000464565b60ff168360ff16146200013a57600080fd5b6004805461ff001960ff19909116600117169055600880546001600160a01b0383166001600160a01b03199182168117909255600b8054909116909117905542600c5560405146907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f90620001b29060009062000488565b60408051918290038220828201825260018352603160f81b6020938401528151928301939093528101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc66060820152608081018290523060a082015260c00160408051601f19818403018152919052805160209091012060c052506200057e945050505050565b8280546200024b906200052b565b90600052602060002090601f0160209004810192826200026f5760008555620002ba565b82601f106200028a57805160ff1916838001178555620002ba565b82800160010185558215620002ba579182015b82811115620002ba5782518255916020019190600101906200029d565b50620002c8929150620002cc565b5090565b5b80821115620002c85760008155600101620002cd565b80516001600160a01b0381168114620002fb57600080fd5b919050565b600082601f83011262000311578081fd5b81516001600160401b03808211156200032e576200032e62000568565b604051601f8301601f19908116603f0116810190828211818310171562000359576200035962000568565b8160405283815260209250868385880101111562000375578485fd5b8491505b8382101562000398578582018301518183018401529082019062000379565b83821115620003a957848385830101525b9695505050505050565b805160ff81168114620002fb57600080fd5b600080600080600060a08688031215620003dd578081fd5b85516001600160401b0380821115620003f4578283fd5b6200040289838a0162000300565b9650602088015191508082111562000418578283fd5b50620004278882890162000300565b9450506200043860408701620003b3565b92506200044860608701620002e3565b91506200045860808701620002e3565b90509295509295909350565b60006020828403121562000476578081fd5b6200048182620003b3565b9392505050565b8154600090819060028104600180831680620004a557607f831692505b6020808410821415620004c657634e487b7160e01b87526022600452602487fd5b818015620004dd5760018114620004ef576200051d565b60ff198616895284890196506200051d565b60008a815260209020885b86811015620005155781548b820152908501908301620004fa565b505084890196505b509498975050505050505050565b6002810460018216806200054057607f821691505b602082108114156200056257634e487b7160e01b600052602260045260246000fd5b50919050565b634e487b7160e01b600052604160045260246000fd5b60805160f81c60a05160601c60c05161297e620006016000396000818161048c0152611dda015260008181610590015281816113520152818161139e0152818161141e015281816116450152818161185a015281816118e301528181611bb001528181611ccd0152818161209601526120c901526000610453015261297e6000f3fe608060405234801561001057600080fd5b506004361061033f5760003560e01c80637ecebe00116101b8578063bebbf4d011610104578063d93f2445116100a2578063f75c26641161007c578063f75c266414610774578063f954734e1461077c578063fbfa77cf1461078f578063fca3b5aa146107a25761033f565b8063d93f24451461072e578063dd62ed3e14610736578063ec126c77146107615761033f565b8063cae9ca51116100de578063cae9ca51146106ed578063cfbd488514610700578063d0e30db014610713578063d505accf1461071b5761033f565b8063bebbf4d0146106be578063c3081240146106d1578063c4b740f5146106da5761033f565b806395d89b4111610171578063a29dff721161014b578063a29dff721461066c578063a9059cbb14610675578063aa271e1a14610688578063b6b55f25146106ab5761033f565b806395d89b411461063c5780639dc29fac14610644578063a045442c146106575761033f565b80637ecebe00146105d257806381a37c18146105f25780638623ec7b1461060557806387689e28146106185780638da5cb5b1461062157806391c5df49146106295761033f565b80633ccfd60b1161029257806360e232a9116102305780636a42b8f81161020a5780636a42b8f81461056f5780636e553f65146105785780636f307dc31461058b57806370a08231146105b25761033f565b806360e232a914610536578063628d6cba146105495780636817031b1461055c5761033f565b80634ca8f0ed1161026c5780634ca8f0ed146104dc57806352113ba7146104e55780635f9b105d14610510578063605629d6146105235761033f565b80633ccfd60b146104ae5780634000aea0146104b657806340c10f19146104c95761033f565b806318160ddd116102ff5780632ebe3fbb116102d95780632ebe3fbb1461041457806330adf81f14610427578063313ce5671461044e5780633644e515146104875761033f565b806318160ddd146103e657806323b872dd146103ee5780632e1a7d4d146104015761033f565b806239d6ec14610344578062bf26f41461036a578062f714ce1461039157806306fdde03146103a4578063095ea7b3146103b95780630d707df8146103dc575b600080fd5b610357610352366004612443565b6107b5565b6040519081526020015b60405180910390f35b6103577f42ce63790c28229c123925d83266e77c04d28784552ab68b350a9003226cbd5981565b61035761039f3660046125f5565b61080b565b6103ac61081f565b6040516103619190612709565b6103cc6103c736600461241a565b6108ad565b6040519015158152602001610361565b6103e4610907565b005b6103576109c3565b6103cc6103fc366004612376565b6109ca565b61035761040f3660046125c5565b610bb5565b6103e461042236600461232a565b610bca565b6103577f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b6104757f000000000000000000000000000000000000000000000000000000000000000081565b60405160ff9091168152602001610361565b6103577f000000000000000000000000000000000000000000000000000000000000000081565b610357610ca1565b6103cc6104c436600461247e565b610cc2565b6103cc6104d736600461241a565b610e1b565b610357600d5481565b600b546104f8906001600160a01b031681565b6040516001600160a01b039091168152602001610361565b6103cc61051e36600461232a565b610e5d565b6103cc6105313660046123b1565b610f31565b6103cc61054436600461232a565b611141565b6103cc6105573660046125f5565b611215565b6103e461056a36600461232a565b6112dd565b61035760055481565b6103576105863660046125f5565b611343565b6104f87f000000000000000000000000000000000000000000000000000000000000000081565b6103576105c036600461232a565b60026020526000908152604090205481565b6103576105e036600461232a565b600f6020526000908152604090205481565b610357610600366004612500565b611384565b6104f86106133660046125c5565b61145e565b610357600c5481565b6104f8611488565b6009546104f8906001600160a01b031681565b6103ac611492565b6103cc61065236600461241a565b61149f565b61065f6114fe565b60405161036191906126bc565b610357600e5481565b6103cc61068336600461241a565b611560565b6103cc61069636600461232a565b60066020526000908152604090205460ff1681565b6103576106b93660046125c5565b611636565b6103576106cc3660046125f5565b611677565b610357600a5481565b6103e46106e8366004612569565b6116b1565b6103cc6106fb36600461247e565b611703565b6103e461070e36600461232a565b6117df565b610357611838565b6103e46107293660046123b1565b61191b565b6103e4611a89565b610357610744366004612344565b601060209081526000928352604080842090915290825290205481565b6103cc61076f3660046125a1565b611af4565b6104f8611b69565b61035761078a366004612500565b611b96565b6008546104f8906001600160a01b031681565b6103e46107b036600461232a565b611c4e565b60006107bf611b69565b6001600160a01b0316336001600160a01b0316146107f85760405162461bcd60e51b81526004016107ef9061273c565b60405180910390fd5b610803848484611cb4565b949350505050565b6000610818338484611cb4565b9392505050565b6000805461082c9061288b565b80601f01602080910402602001604051908101604052809291908181526020018280546108589061288b565b80156108a55780601f1061087a576101008083540402835291602001916108a5565b820191906000526020600020905b81548152906001019060200180831161088857829003601f168201915b505050505081565b3360008181526010602090815260408083206001600160a01b03871680855292528083208590555191929091600080516020612929833981519152906108f69086815260200190565b60405180910390a350600192915050565b61090f611b69565b6001600160a01b0316336001600160a01b03161461093f5760405162461bcd60e51b81526004016107ef9061273c565b600a5442101561094e57600080fd5b600980546001600160a01b039081166000908152600660205260408120805460ff1916600190811790915592546007805494850181559091527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68890920180546001600160a01b03191692909116919091179055565b6003545b90565b60006001600160a01b0383161515806109ec57506001600160a01b0383163014155b6109f557600080fd5b6001600160a01b0384163314610aef576001600160a01b03841660009081526010602090815260408083203384529091529020546000198114610aed5782811015610a945760405162461bcd60e51b815260206004820152602960248201527f416e7973776170563345524332303a2072657175657374206578636565647320604482015268616c6c6f77616e636560b81b60648201526084016107ef565b6000610aa08483612848565b6001600160a01b03871660008181526010602090815260408083203380855290835292819020859055518481529394509092600080516020612929833981519152910160405180910390a3505b505b6001600160a01b03841660009081526002602052604090205482811015610b285760405162461bcd60e51b81526004016107ef906127aa565b610b328382612848565b6001600160a01b038087166000908152600260205260408082209390935590861681529081208054859290610b68908490612830565b92505081905550836001600160a01b0316856001600160a01b031660008051602061290983398151915285604051610ba291815260200190565b60405180910390a3506001949350505050565b6000610bc2338333611cb4565b90505b919050565b610bd2611b69565b6001600160a01b0316336001600160a01b031614610c025760405162461bcd60e51b81526004016107ef9061273c565b60045460ff16610c1157600080fd5b600880546001600160a01b039092166001600160a01b03199283168117909155600b80548316821790556000818152600660205260408120805460ff1990811660019081179092556007805492830181559092527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68801805490931690911790915542600c55600480549091169055565b336000818152600260205260408120549091610cbd9181611cb4565b905090565b60006001600160a01b038516151580610ce457506001600160a01b0385163014155b610ced57600080fd5b3360009081526002602052604090205484811015610d1d5760405162461bcd60e51b81526004016107ef906127aa565b610d278582612848565b33600090815260026020526040808220929092556001600160a01b03881681529081208054879290610d5a908490612830565b90915550506040518581526001600160a01b0387169033906000805160206129098339815191529060200160405180910390a3604051635260769b60e11b81526001600160a01b0387169063a4c0ed3690610dbf903390899089908990600401612674565b602060405180830381600087803b158015610dd957600080fd5b505af1158015610ded573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e119190612585565b9695505050505050565b3360009081526006602052604081205460ff16610e4a5760405162461bcd60e51b81526004016107ef906127f9565b610e548383611cfc565b50600192915050565b6000610e67611b69565b6001600160a01b0316336001600160a01b031614610e975760405162461bcd60e51b81526004016107ef9061273c565b6001600160a01b038216610ebd5760405162461bcd60e51b81526004016107ef90612773565b600b80546001600160a01b0319166001600160a01b038416179055600554610ee59042612830565b600c819055600b546008546040516001600160a01b0392831692909116907f1d065115f314fb9bad9557bd5460b9e3c66f7223b1dd04e73e828f0bb5afe89f90600090a4506001919050565b600084421115610f835760405162461bcd60e51b815260206004820152601e60248201527f416e7973776170563345524332303a2045787069726564207065726d6974000060448201526064016107ef565b6001600160a01b0388166000908152600f6020526040812080547f42ce63790c28229c123925d83266e77c04d28784552ab68b350a9003226cbd59918b918b918b919086610fd0836128c6565b909155506040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810187905260e0016040516020818303038152906040528051906020012090506110318982878787611dca565b8061104457506110448982878787611eba565b61104d57600080fd5b6001600160a01b03881615158061106d57506001600160a01b0388163014155b61107657600080fd5b6001600160a01b038916600090815260026020526040902054878110156110af5760405162461bcd60e51b81526004016107ef906127aa565b6110b98882612848565b6001600160a01b03808c1660009081526002602052604080822093909355908b16815290812080548a92906110ef908490612830565b92505081905550886001600160a01b03168a6001600160a01b03166000805160206129098339815191528a60405161112991815260200190565b60405180910390a35060019998505050505050505050565b600061114b611b69565b6001600160a01b0316336001600160a01b03161461117b5760405162461bcd60e51b81526004016107ef9061273c565b6001600160a01b0382166111a15760405162461bcd60e51b81526004016107ef90612773565b600b80546001600160a01b0319166001600160a01b0384161790556005546111c99042612830565b600c819055600b546008546040516001600160a01b0392831692909116907f5c364079e7102c27c608f9b237c735a1b7bfa0b67f27c2ad26bad447bf965cac90600090a4506001919050565b600454600090610100900460ff16156112705760405162461bcd60e51b815260206004820152601860248201527f416e7973776170563445524332303a206f6e6c7941757468000000000000000060448201526064016107ef565b6001600160a01b0382166112965760405162461bcd60e51b81526004016107ef90612773565b6112a03384611f4f565b6040518381526001600160a01b0383169033907f6b616089d04950dc06c45c6dd787d657980543f89651aec47924752c7d16c888906020016108f6565b6112e5611b69565b6001600160a01b0316336001600160a01b0316146113155760405162461bcd60e51b81526004016107ef9061273c565b600b80546001600160a01b0319166001600160a01b03831617905560055461133d9042612830565b600c5550565b600061137a6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333086612021565b6108188383612092565b60405163d505accf60e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063d505accf906113df908b9030908c908c908c908c908c90600401612633565b600060405180830381600087803b1580156113f957600080fd5b505af115801561140d573d6000803e3d6000fd5b506114489250506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016905089308a612021565b6114528783612092565b98975050505050505050565b6007818154811061146e57600080fd5b6000918252602090912001546001600160a01b0316905081565b6000610cbd611b69565b6001805461082c9061288b565b3360009081526006602052604081205460ff166114ce5760405162461bcd60e51b81526004016107ef906127f9565b6001600160a01b0383166114f45760405162461bcd60e51b81526004016107ef90612773565b610e548383611f4f565b6060600780548060200260200160405190810160405280929190818152602001828054801561155657602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311611538575b5050505050905090565b60006001600160a01b03831615158061158257506001600160a01b0383163014155b61158b57600080fd5b33600090815260026020526040902054828110156115bb5760405162461bcd60e51b81526004016107ef906127aa565b6115c58382612848565b33600090815260026020526040808220929092556001600160a01b038616815290812080548592906115f8908490612830565b90915550506040518381526001600160a01b038516903390600080516020612909833981519152906020015b60405180910390a35060019392505050565b600061166d6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333085612021565b610bc28233612092565b6000611681611b69565b6001600160a01b0316336001600160a01b03161461137a5760405162461bcd60e51b81526004016107ef9061273c565b6116b9611b69565b6001600160a01b0316336001600160a01b0316146116e95760405162461bcd60e51b81526004016107ef9061273c565b600480549115156101000261ff0019909216919091179055565b3360008181526010602090815260408083206001600160a01b038916808552925280832087905551919290916000805160206129298339815191529061174c9088815260200190565b60405180910390a360405162ba451f60e01b81526001600160a01b0386169062ba451f90611784903390889088908890600401612674565b602060405180830381600087803b15801561179e57600080fd5b505af11580156117b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117d69190612585565b95945050505050565b6117e7611b69565b6001600160a01b0316336001600160a01b0316146118175760405162461bcd60e51b81526004016107ef9061273c565b6001600160a01b03166000908152600660205260409020805460ff19169055565b6040516370a0823160e01b815233600482015260009081906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a082319060240160206040518083038186803b15801561189c57600080fd5b505afa1580156118b0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118d491906125dd565b905061190b6001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333084612021565b6119158133612092565b91505090565b8342111561196b5760405162461bcd60e51b815260206004820152601e60248201527f416e7973776170563345524332303a2045787069726564207065726d6974000060448201526064016107ef565b6001600160a01b0387166000908152600f6020526040812080547f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9918a918a918a9190866119b8836128c6565b909155506040805160208101969096526001600160a01b0394851690860152929091166060840152608083015260a082015260c0810186905260e001604051602081830303815290604052805190602001209050611a198882868686611dca565b80611a2c5750611a2c8882868686611eba565b611a3557600080fd5b6001600160a01b038881166000818152601060209081526040808320948c16808452948252918290208a90559051898152600080516020612929833981519152910160405180910390a35050505050505050565b611a91611b69565b6001600160a01b0316336001600160a01b031614611ac15760405162461bcd60e51b81526004016107ef9061273c565b600c54421015611ad057600080fd5b600b54600880546001600160a01b0319166001600160a01b03909216919091179055565b3360009081526006602052604081205460ff16611b235760405162461bcd60e51b81526004016107ef906127f9565b611b2d8383611cfc565b826001600160a01b0316847f05d0634fe981be85c22e2942a880821b70095d84e152c3ea3c17a4e4250d9d618460405161162491815260200190565b6000600c544210611b865750600b546001600160a01b03166109c7565b506008546001600160a01b031690565b60405163302b14eb60e11b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063605629d690611bf1908b9030908c908c908c908c908c90600401612633565b602060405180830381600087803b158015611c0b57600080fd5b505af1158015611c1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c439190612585565b506114528783612092565b611c56611b69565b6001600160a01b0316336001600160a01b031614611c865760405162461bcd60e51b81526004016107ef9061273c565b600980546001600160a01b0319166001600160a01b038316179055600554611cae9042612830565b600a5550565b6000611cc08484611f4f565b611cf46001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016838561210f565b509092915050565b6001600160a01b038216611d525760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f20616464726573730060448201526064016107ef565b8060036000828254611d649190612830565b90915550506001600160a01b03821660009081526002602052604081208054839290611d91908490612830565b90915550506040518181526001600160a01b03831690600090600080516020612909833981519152906020015b60405180910390a35050565b60405161190160f01b60208201527f0000000000000000000000000000000000000000000000000000000000000000602282015260428101859052600090819060620160408051601f198184030181528282528051602091820120600080855291840180845281905260ff89169284019290925260608301879052608083018690529092509060019060a0015b6020604051602081039080840390855afa158015611e79573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906114525750876001600160a01b0316816001600160a01b03161498975050505050505050565b600080611f14866040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b6040805160008082526020820180845284905260ff89169282019290925260608101879052608081018690529192509060019060a001611e57565b6001600160a01b038216611faf5760405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f206164647265736044820152607360f81b60648201526084016107ef565b6001600160a01b03821660009081526002602052604081208054839290611fd7908490612848565b925050819055508060036000828254611ff09190612848565b90915550506040518181526000906001600160a01b0384169060008051602061290983398151915290602001611dbe565b6040516001600160a01b038085166024830152831660448201526064810182905261208c9085906323b872dd60e01b906084015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612144565b50505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316158015906120f557507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163014155b6120fe57600080fd5b6121088284611cfc565b5090919050565b6040516001600160a01b03831660248201526044810182905261213f90849063a9059cbb60e01b90606401612055565b505050565b612156826001600160a01b03166122cb565b6121a25760405162461bcd60e51b815260206004820152601f60248201527f5361666545524332303a2063616c6c20746f206e6f6e2d636f6e74726163740060448201526064016107ef565b600080836001600160a01b0316836040516121bd9190612617565b6000604051808303816000865af19150503d80600081146121fa576040519150601f19603f3d011682016040523d82523d6000602084013e6121ff565b606091505b5091509150816122515760405162461bcd60e51b815260206004820181905260248201527f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c656460448201526064016107ef565b80511561208c578080602001905181019061226c9190612585565b61208c5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016107ef565b6000813f7fc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a47081158015906108035750141592915050565b80356001600160a01b0381168114610bc557600080fd5b803560ff81168114610bc557600080fd5b60006020828403121561233b578081fd5b61081882612302565b60008060408385031215612356578081fd5b61235f83612302565b915061236d60208401612302565b90509250929050565b60008060006060848603121561238a578081fd5b61239384612302565b92506123a160208501612302565b9150604084013590509250925092565b600080600080600080600060e0888a0312156123cb578283fd5b6123d488612302565b96506123e260208901612302565b955060408801359450606088013593506123fe60808901612319565b925060a0880135915060c0880135905092959891949750929550565b6000806040838503121561242c578182fd5b61243583612302565b946020939093013593505050565b600080600060608486031215612457578283fd5b61246084612302565b92506020840135915061247560408501612302565b90509250925092565b60008060008060608587031215612493578384fd5b61249c85612302565b935060208501359250604085013567ffffffffffffffff808211156124bf578384fd5b818701915087601f8301126124d2578384fd5b8135818111156124e0578485fd5b8860208285010111156124f1578485fd5b95989497505060200194505050565b600080600080600080600060e0888a03121561251a578283fd5b61252388612302565b9650602088013595506040880135945061253f60608901612319565b93506080880135925060a0880135915061255b60c08901612302565b905092959891949750929550565b60006020828403121561257a578081fd5b8135610818816128f7565b600060208284031215612596578081fd5b8151610818816128f7565b6000806000606084860312156125b5578283fd5b833592506123a160208501612302565b6000602082840312156125d6578081fd5b5035919050565b6000602082840312156125ee578081fd5b5051919050565b60008060408385031215612607578182fd5b8235915061236d60208401612302565b6000825161262981846020870161285f565b9190910192915050565b6001600160a01b0397881681529590961660208601526040850193909352606084019190915260ff16608083015260a082015260c081019190915260e00190565b6001600160a01b0385168152602081018490526060604082018190528101829052600082846080840137818301608090810191909152601f909201601f191601019392505050565b6020808252825182820181905260009190848201906040850190845b818110156126fd5783516001600160a01b0316835292840192918401916001016126d8565b50909695505050505050565b600060208252825180602084015261272881604085016020870161285f565b601f01601f19169190910160400192915050565b60208082526019908201527f416e7973776170563345524332303a20464f5242494444454e00000000000000604082015260600190565b6020808252601c908201527f416e7973776170563345524332303a2061646472657373283078302900000000604082015260600190565b6020808252602f908201527f416e7973776170563345524332303a207472616e7366657220616d6f756e742060408201526e657863656564732062616c616e636560881b606082015260800190565b60208082526019908201527f416e7973776170563445524332303a20464f5242494444454e00000000000000604082015260600190565b60008219821115612843576128436128e1565b500190565b60008282101561285a5761285a6128e1565b500390565b60005b8381101561287a578181015183820152602001612862565b8381111561208c5750506000910152565b60028104600182168061289f57607f821691505b602082108114156128c057634e487b7160e01b600052602260045260246000fd5b50919050565b60006000198214156128da576128da6128e1565b5060010190565b634e487b7160e01b600052601160045260246000fd5b801515811461290557600080fd5b5056feddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a26469706673582212208419b2ad269a82ca3ad876aff3c46be03a8dbfa4d02646df103fd48e9bce340c64736f6c63430008020033';
const anyswapERC20ABI = '[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"address","name":"_underlying","type":"address"},{"internalType":"address","name":"_vault","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"auth","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"LogAddAuth","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"},{"indexed":true,"internalType":"uint256","name":"effectiveHeight","type":"uint256"}],"name":"LogChangeMPCOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldVault","type":"address"},{"indexed":true,"internalType":"address","name":"newVault","type":"address"},{"indexed":true,"internalType":"uint256","name":"effectiveTime","type":"uint256"}],"name":"LogChangeVault","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"txhash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"LogSwapin","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"bindaddr","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"LogSwapout","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"txhash","type":"bytes32"},{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Swapin","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"bindaddr","type":"address"}],"name":"Swapout","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"TRANSFER_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"applyMinter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"applyVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"approveAndCall","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newVault","type":"address"}],"name":"changeMPCOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newVault","type":"address"}],"name":"changeVault","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"delay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"delayDelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"delayMinter","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"delayVault","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"depositVault","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"address","name":"to","type":"address"}],"name":"depositWithPermit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"address","name":"to","type":"address"}],"name":"depositWithTransferPermit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getAllMinters","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"}],"name":"initVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"minters","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mpc","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingDelay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingMinter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingVault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_auth","type":"address"}],"name":"revokeMinter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_auth","type":"address"}],"name":"setMinter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_vault","type":"address"}],"name":"setVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"enabled","type":"bool"}],"name":"setVaultOnly","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"transferAndCall","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"transferWithPermit","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"underlying","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"withdrawVault","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]';
const factoryABI = '[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"uint256","name":"salt","type":"uint256"}],"name":"Deployed","type":"event"},{"inputs":[{"internalType":"bytes","name":"code","type":"bytes"},{"internalType":"uint256","name":"salt","type":"uint256"}],"name":"deploy","outputs":[],"stateMutability":"nonpayable","type":"function"}]';
//string memory _name, string memory _symbol, uint8 _decimals, address _underlying, address _vault
const constructorTypes = ["string", "string", "uint8", "address", "address"];
const factory = new ethers.Contract(factoryAddress, factoryABI, signer);
const constructor = encodeParam(
constructorTypes,
constructorArgs
).slice(2)
console.log(constructor);
const bytecode = `${anyswapERC20}${constructor}`;
// encodes parameter to pass as contract argument
function encodeParam(dataType, data) {
const abiCoder = ethers.utils.defaultAbiCoder;
return abiCoder.encode(dataType, data);
}
function buildCreate2Address(creatorAddress, saltHex, byteCode) {
return `0x${ethers.utils
.keccak256(
`0x${["ff", creatorAddress, saltHex, ethers.utils.keccak256(byteCode)]
.map(x => x.replace(/0x/, ""))
.join("")}`
)
.slice(-40)}`.toLowerCase();
}
// converts an int to uint256
function numberToUint256(value) {
const hex = value.toString(16);
return `0x${"0".repeat(64 - hex.length)}${hex}`;
}
// returns true if contract is deployed on-chain
async function isContract(address) {
const code = await provider.getCode(address);
return code.slice(2).length > 0;
}
setup()
async function setup() {
// First see if already deployed
const computedAddr = buildCreate2Address(
factoryAddress,
numberToUint256(salt),
bytecode
);
console.log(computedAddr)
const isDeployed = await isContract(computedAddr);
if (!isDeployed) {
await (await factory.deploy(bytecode, salt)).wait();
}
const anyswap = new ethers.Contract(computedAddr, anyswapERC20ABI, signer);
const vault = await anyswap.vault();
if (vault !== mpcAddress) {
await (await anyswap.initVault(mpcAddress)).wait();
}
verify(computedAddr, constructor);
}
async function verify(contractAddress, constructorABI) {
const sourceCode = await readFile('./AnyswapV4ERC20.sol').toString();
request
.post({
method: 'POST',
url: verifyURL,
form: {
apikey: apikey,
module: 'contract',
action: 'verifysourcecode',
contractaddress: contractAddress,
sourceCode: sourceCode,
contractname: 'AnyswapV4ERC20.sol:AnyswapV4ERC20',
compilerversion: 'v0.8.2+commit.661d1103',
optimizationUsed: 1,
runs: 200,
constructorArguements: constructorABI, //if applicable
licenseType: 7, //Valid codes 1-12 where 1=No License .. 12=Apache 2.0, see https://BscScan.com/contract-license-types
}
}).then(res => console.log(res))
.catch(err => console.log(err));
}
async function checkCode() {
const computedAddr = buildCreate2Address(
factoryAddress,
numberToUint256(salt),
bytecode
);
console.log(await isContract(computedAddr));
}
async function mpc() {
const computedAddr = buildCreate2Address(
factoryAddress,
numberToUint256(salt),
bytecode
);
const anyswap = new ethers.Contract(computedAddr, anyswapERC20ABI, signer);
const result = await (await anyswap.changeMPCOwner(mpcAddress)).wait();
console.log(result.transactionHash);
}
async function run() {
const result = await (await factory.deploy(bytecode, salt)).wait();
const addr = result.events[0].args.addr.toLowerCase();
console.log(result.transactionHash);
console.log(addr);
}