Skip to content

Commit

Permalink
Merge pull request #131 from bancorprotocol/trade-by-source-upgrade
Browse files Browse the repository at this point in the history
trade by source extended input upgrade scripts
  • Loading branch information
ivanzhelyazkov authored Jan 30, 2024
2 parents bd0f013 + 7625c30 commit e819de6
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 23 deletions.
2 changes: 1 addition & 1 deletion contracts/carbon/CarbonController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ contract CarbonController is
* @inheritdoc Upgradeable
*/
function version() public pure virtual override(IVersioned, Upgradeable) returns (uint16) {
return 4;
return 5;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion data/named-accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const TestNamedAccounts = {
...mainnet('0x55FE002aefF02F77364de339a1292923A15844B8')
},
wbtcWhale: {
...mainnet('0x77134cbC06cB00b66F4c7e623D5fdBF6777635EC')
...mainnet('0x051d091B254EcdBBB4eB8E6311b7939829380b27')
},
bntWhale: {
...mainnet('0x221A0e3C9AcEa6B3f1CC9DfC7063509c89bE7BC3')
Expand Down
22 changes: 22 additions & 0 deletions deploy/scripts/0010-CarbonController-upgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { DeployedContracts, InstanceName, setDeploymentMetadata, upgradeProxy } from '../../utils/Deploy';
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

/**
* @dev trade by source extended input upgrade
*/
const func: DeployFunction = async ({ getNamedAccounts }: HardhatRuntimeEnvironment) => {
const { deployer } = await getNamedAccounts();
const voucher = await DeployedContracts.Voucher.deployed();

const carbonController = await DeployedContracts.CarbonController.deployed();
await upgradeProxy({
name: InstanceName.CarbonController,
from: deployer,
args: [voucher.address, carbonController.address]
});

return true;
};

export default setDeploymentMetadata(__filename, func);
31 changes: 31 additions & 0 deletions deploy/tests/0010-carbon-controller-upgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { CarbonController, ProxyAdmin } from '../../components/Contracts';
import { DeployedContracts } from '../../utils/Deploy';
import { describeDeployment } from '../../utils/helpers/Deploy';
import { expect } from 'chai';
import { ethers } from 'hardhat';

describeDeployment(__filename, () => {
let proxyAdmin: ProxyAdmin;
let carbonController: CarbonController;

beforeEach(async () => {
proxyAdmin = await DeployedContracts.ProxyAdmin.deployed();
carbonController = await DeployedContracts.CarbonController.deployed();
});

it('should deploy and configure the carbon controller contract', async () => {
expect(await proxyAdmin.getProxyAdmin(carbonController.address)).to.equal(proxyAdmin.address);
expect(await carbonController.version()).to.equal(5);
});

it('carbon controller implementation should be initialized', async () => {
const implementationAddress = await proxyAdmin.getProxyImplementation(carbonController.address);
const carbonControllerImpl: CarbonController = await ethers.getContractAt(
'CarbonController',
implementationAddress
);
// hardcoding gas limit to avoid gas estimation attempts (which get rejected instead of reverted)
const tx = await carbonControllerImpl.initialize({ gasLimit: 6000000 });
await expect(tx.wait()).to.be.reverted;
});
});
28 changes: 17 additions & 11 deletions deployments/setup-fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,23 @@ const fundAccount = async (account: string, fundingRequests: FundingRequest[]) =
Logger.log(`Funding ${account}...`);

for (const fundingRequest of fundingRequests) {
if (fundingRequest.token === NATIVE_TOKEN_ADDRESS) {
await fundingRequest.whale.sendTransaction({
value: fundingRequest.amount,
to: account
});

continue;
try {
if (fundingRequest.token === NATIVE_TOKEN_ADDRESS) {
await fundingRequest.whale.sendTransaction({
value: fundingRequest.amount,
to: account
});

continue;
}

const tokenContract = await Contracts.ERC20.attach(fundingRequest.token);
await tokenContract.connect(fundingRequest.whale).transfer(account, fundingRequest.amount);
} catch (error) {
Logger.error(`Failed to fund ${account} with ${fundingRequest.amount} of token ${fundingRequest.token}`);
Logger.error(error);
Logger.error();
}

const tokenContract = await Contracts.ERC20.attach(fundingRequest.token);
await tokenContract.connect(fundingRequest.whale).transfer(account, fundingRequest.amount);
}
};

Expand Down Expand Up @@ -80,7 +86,7 @@ const fundAccounts = async () => {
},
{
token: wbtc,
amount: toWei(100, 8),
amount: toWei(70, 8),
whale: wbtcWhale
}
];
Expand Down
26 changes: 16 additions & 10 deletions deployments/setup-testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,23 @@ const fundAccount = async (account: string, fundingRequests: FundingRequest[]) =
if (fundingRequest.token === ZERO_ADDRESS) {
continue;
}
if (fundingRequest.token === NATIVE_TOKEN_ADDRESS) {
await fundingRequest.whale.sendTransaction({
value: fundingRequest.amount,
to: account
});

continue;
try {
if (fundingRequest.token === NATIVE_TOKEN_ADDRESS) {
await fundingRequest.whale.sendTransaction({
value: fundingRequest.amount,
to: account
});

continue;
}

const tokenContract = await Contracts.ERC20.attach(fundingRequest.token);
await tokenContract.connect(fundingRequest.whale).transfer(account, fundingRequest.amount);
} catch (error) {
Logger.error(`Failed to fund ${account} with ${fundingRequest.amount} of token ${fundingRequest.tokenName}`);
Logger.error(error);
Logger.error();
}

const tokenContract = await Contracts.ERC20.attach(fundingRequest.token);
await tokenContract.connect(fundingRequest.whale).transfer(account, fundingRequest.amount);
}
};

Expand Down

0 comments on commit e819de6

Please sign in to comment.