-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve swap contract and deployment (#1043)
- Loading branch information
Showing
25 changed files
with
628 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/smart-contracts/scripts-create2/contract-setup/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
export { setupChainlinkConversionPath } from './setupChainlinkConversionPath'; | ||
export { setupErc20ConversionProxy } from './setupErc20ConversionProxy'; | ||
export { setupETHConversionProxy } from './setupETHConversionProxy'; | ||
export { setupERC20SwapToPay } from './setupERC20SwapToPay'; | ||
export { setupERC20SwapToConversion } from './setupERC20SwapToConversion'; | ||
export { setupBatchConversionPayments } from './setupBatchConversionPayments'; |
46 changes: 46 additions & 0 deletions
46
packages/smart-contracts/scripts-create2/contract-setup/setupChainlinkConversionPath.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { CurrencyManager } from '@requestnetwork/currency'; | ||
import { RequestLogicTypes } from '@requestnetwork/types'; | ||
import { chainlinkConversionPath } from '../../src/lib'; | ||
import { HardhatRuntimeEnvironmentExtended } from '../types'; | ||
import { getSignerAndGasFees, updateNativeTokenHash } from './adminTasks'; | ||
|
||
/** | ||
* Setup the chainlinkConversionPath values once deployed | ||
* @param contractAddress address of the ChainlinkConversionPath contract | ||
* @param hre Hardhat runtime environment | ||
*/ | ||
export const setupChainlinkConversionPath = async ( | ||
contractAddress: string, | ||
hre: HardhatRuntimeEnvironmentExtended, | ||
): Promise<void> => { | ||
// Setup contract parameters | ||
const ChainlinkConversionPathContract = new hre.ethers.Contract( | ||
contractAddress, | ||
chainlinkConversionPath.getContractAbi(), | ||
); | ||
await Promise.all( | ||
hre.config.xdeploy.networks.map(async (network) => { | ||
try { | ||
const { signer, txOverrides } = await getSignerAndGasFees(network, hre); | ||
const nativeTokenHash = CurrencyManager.getDefault().getNativeCurrency( | ||
RequestLogicTypes.CURRENCY.ETH, | ||
network, | ||
)?.hash; | ||
if (!nativeTokenHash) { | ||
throw new Error(`Could not guess native token hash for network ${network}`); | ||
} | ||
const ChainlinkConversionPathConnected = ChainlinkConversionPathContract.connect(signer); | ||
await updateNativeTokenHash( | ||
'ChainlinkConversionPath', | ||
ChainlinkConversionPathConnected, | ||
nativeTokenHash, | ||
txOverrides, | ||
); | ||
console.log(`Setup of ChainlinkConversionPath successful on ${network}`); | ||
} catch (err) { | ||
console.warn(`An error occurred during the setup of ChainlinkConversionPath on ${network}`); | ||
console.warn(err); | ||
} | ||
}), | ||
); | ||
}; |
34 changes: 34 additions & 0 deletions
34
packages/smart-contracts/scripts-create2/contract-setup/setupERC20SwapToPay.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { erc20SwapToPayArtifact } from '../../src/lib'; | ||
import { HardhatRuntimeEnvironmentExtended } from '../types'; | ||
import { getSignerAndGasFees, updateRequestSwapFees, updateSwapRouter } from './adminTasks'; | ||
|
||
/** | ||
* Once deployed, setup the values of the ERC20SwapToPay contract | ||
* @param contractAddress address of the ERC20SwapToPay Proxy | ||
* @param hre Hardhat runtime environment | ||
*/ | ||
export const setupERC20SwapToPay = async ( | ||
contractAddress: string, | ||
hre: HardhatRuntimeEnvironmentExtended, | ||
): Promise<void> => { | ||
// Setup contract parameters | ||
const ERC20SwapToPayContract = new hre.ethers.Contract( | ||
contractAddress, | ||
erc20SwapToPayArtifact.getContractAbi(), | ||
); | ||
await Promise.all( | ||
hre.config.xdeploy.networks.map(async (network) => { | ||
try { | ||
const { signer, txOverrides } = await getSignerAndGasFees(network, hre); | ||
const ERC20SwapToPayConnected = await ERC20SwapToPayContract.connect(signer); | ||
|
||
await updateSwapRouter(ERC20SwapToPayConnected, network, txOverrides); | ||
await updateRequestSwapFees(ERC20SwapToPayConnected, txOverrides); | ||
console.log(`Setup of ERC20SwapToPay successful on ${network}`); | ||
} catch (err) { | ||
console.warn(`An error occurred during the setup of ERC20SwapToPay on ${network}`); | ||
console.warn(err); | ||
} | ||
}), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.