From 5997543405cef8b330ec0f3e9ad835513fda63f1 Mon Sep 17 00:00:00 2001 From: Yorke Rhodes Date: Wed, 4 Aug 2021 17:15:53 -0700 Subject: [PATCH 01/33] GrandaMento comment fixes & clearer revert msgs - N01 and N02 (#8473) Co-authored-by: Trevor Porter --- .../contracts/liquidity/GrandaMento.sol | 17 ++++++++++------- packages/protocol/test/liquidity/grandamento.ts | 9 ++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/protocol/contracts/liquidity/GrandaMento.sol b/packages/protocol/contracts/liquidity/GrandaMento.sol index e15e16badd9..0733bfacf10 100644 --- a/packages/protocol/contracts/liquidity/GrandaMento.sol +++ b/packages/protocol/contracts/liquidity/GrandaMento.sol @@ -75,11 +75,12 @@ contract GrandaMento is address payable exchanger; // The stable token involved in this proposal. This is stored rather than // the stable token's registry ID in case the contract address is changed - // while a stable token deposit + // after a proposal is created, which could affect refunding or burning the + // stable token. address stableToken; // The state of the exchange proposal. ExchangeProposalState state; - // Whether CELO is being sold and stableToken is being bought. + // Whether the exchanger is selling CELO and buying stableToken. bool sellCelo; // The amount of the sell token being sold. If a stable token is being sold, // the amount of stable token in "units" is stored rather than the "value." @@ -310,11 +311,13 @@ contract GrandaMento is // Require the appropriate state and sender. // This will also revert if a proposalId is given that does not correspond // to a previously created exchange proposal. - require( - (proposal.state == ExchangeProposalState.Proposed && proposal.exchanger == msg.sender) || - (proposal.state == ExchangeProposalState.Approved && isOwner()), - "Sender cannot cancel the exchange proposal" - ); + if (proposal.state == ExchangeProposalState.Proposed) { + require(proposal.exchanger == msg.sender, "Sender must be exchanger"); + } else if (proposal.state == ExchangeProposalState.Approved) { + require(isOwner(), "Sender must be owner"); + } else { + revert("Proposal must be in Proposed or Approved state"); + } // Mark the proposal as cancelled. Do so prior to refunding as a measure against reentrancy. proposal.state = ExchangeProposalState.Cancelled; // Get the token and amount that will be refunded to the proposer. diff --git a/packages/protocol/test/liquidity/grandamento.ts b/packages/protocol/test/liquidity/grandamento.ts index bbbe26d4ed2..06701814834 100644 --- a/packages/protocol/test/liquidity/grandamento.ts +++ b/packages/protocol/test/liquidity/grandamento.ts @@ -8,7 +8,6 @@ import { } from '@celo/protocol/lib/test-utils' import { fromFixed, reciprocal, toFixed } from '@celo/utils/lib/fixidity' import BigNumber from 'bignumber.js' -import _ from 'lodash' import { GoldTokenContract, GoldTokenInstance, @@ -492,7 +491,7 @@ contract('GrandaMento', (accounts: string[]) => { // Try to have Alice cancel it when the exchange proposal is in the Approved state. await assertRevertWithReason( grandaMento.cancelExchangeProposal(1, { from: alice }), - 'Sender cannot cancel the exchange proposal' + 'Sender must be owner' ) }) }) @@ -515,7 +514,7 @@ contract('GrandaMento', (accounts: string[]) => { // Try to cancel it when the exchange proposal is in the Proposed state. await assertRevertWithReason( grandaMento.cancelExchangeProposal(1, { from: owner }), - 'Sender cannot cancel the exchange proposal' + 'Sender must be exchanger' ) }) }) @@ -614,14 +613,14 @@ contract('GrandaMento', (accounts: string[]) => { await createExchangeProposal(false, alice) await assertRevertWithReason( grandaMento.cancelExchangeProposal(1, { from: approver }), - 'Sender cannot cancel the exchange proposal' + 'Sender must be exchanger' ) }) it('reverts when the proposalId does not exist', async () => { await assertRevertWithReason( grandaMento.cancelExchangeProposal(1, { from: approver }), - 'Sender cannot cancel the exchange proposal' + 'Proposal must be in Proposed or Approved state' ) }) }) From 1815b1dc23dfcc9377413caec3818f62d398cf33 Mon Sep 17 00:00:00 2001 From: Yorke Rhodes Date: Wed, 4 Aug 2021 17:16:41 -0700 Subject: [PATCH 02/33] GrandaMento - Add hardcoded max for veto period - L07 (#8474) Co-authored-by: Trevor Porter --- .../contracts/liquidity/GrandaMento.sol | 5 +++ .../protocol/test/liquidity/grandamento.ts | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/packages/protocol/contracts/liquidity/GrandaMento.sol b/packages/protocol/contracts/liquidity/GrandaMento.sol index 0733bfacf10..38419c88566 100644 --- a/packages/protocol/contracts/liquidity/GrandaMento.sol +++ b/packages/protocol/contracts/liquidity/GrandaMento.sol @@ -605,6 +605,11 @@ contract GrandaMento is * @param newVetoPeriodSeconds The new value for the veto period in seconds. */ function setVetoPeriodSeconds(uint256 newVetoPeriodSeconds) public onlyOwner { + // Hardcode a max of 4 weeks. + // A minimum is not enforced for flexibility. A case of interest is if + // Governance were to be set as the `approver`, it would be desirable to + // set the veto period to 0 seconds. + require(newVetoPeriodSeconds <= 4 weeks, "Veto period cannot exceed 4 weeks"); vetoPeriodSeconds = newVetoPeriodSeconds; emit VetoPeriodSecondsSet(newVetoPeriodSeconds); } diff --git a/packages/protocol/test/liquidity/grandamento.ts b/packages/protocol/test/liquidity/grandamento.ts index 06701814834..91672730930 100644 --- a/packages/protocol/test/liquidity/grandamento.ts +++ b/packages/protocol/test/liquidity/grandamento.ts @@ -1082,6 +1082,39 @@ contract('GrandaMento', (accounts: string[]) => { ) }) }) + + describe('#setVetoPeriodSeconds', () => { + const newVetoPeriodSeconds = 60 * 60 * 24 * 7 // 7 days + it('sets the spread', async () => { + await grandaMento.setVetoPeriodSeconds(newVetoPeriodSeconds) + assertEqualBN(await grandaMento.vetoPeriodSeconds(), newVetoPeriodSeconds) + }) + + it('emits the VetoPeriodSecondsSet event', async () => { + const receipt = await grandaMento.setVetoPeriodSeconds(newVetoPeriodSeconds) + assertLogMatches2(receipt.logs[0], { + event: 'VetoPeriodSecondsSet', + args: { + vetoPeriodSeconds: newVetoPeriodSeconds, + }, + }) + }) + + it('reverts when the veto period is greater than 4 weeks', async () => { + const fourWeeks = 60 * 60 * 24 * 7 * 4 + await assertRevertWithReason( + grandaMento.setVetoPeriodSeconds(fourWeeks + 1), + 'Veto period cannot exceed 4 weeks' + ) + }) + + it('reverts when the sender is not the owner', async () => { + await assertRevertWithReason( + grandaMento.setVetoPeriodSeconds(newVetoPeriodSeconds, { from: accounts[1] }), + 'Ownable: caller is not the owner' + ) + }) + }) }) // exchangeRate is the price of the sell token quoted in buy token From 2ffa4da73b6a1beb8be7d2bbdf1e4345725bd2bf Mon Sep 17 00:00:00 2001 From: Yorke Rhodes Date: Wed, 4 Aug 2021 17:17:14 -0700 Subject: [PATCH 03/33] GrandaMento - Lock in veto period in proposal - L01 (#8472) * Lock in veto period in proposal * Test case when time elapsed since approval is after the proposal's vetoPeriodSeconds but before the contract's vetoPeriodSeconds Co-authored-by: Trevor Porter --- .../contracts/liquidity/GrandaMento.sol | 10 ++++-- .../protocol/test/liquidity/grandamento.ts | 32 +++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/packages/protocol/contracts/liquidity/GrandaMento.sol b/packages/protocol/contracts/liquidity/GrandaMento.sol index 38419c88566..73ce0709562 100644 --- a/packages/protocol/contracts/liquidity/GrandaMento.sol +++ b/packages/protocol/contracts/liquidity/GrandaMento.sol @@ -101,6 +101,11 @@ contract GrandaMento is // is being sold that has demurrage enabled, the original value when the stable // tokens were deposited cannot be calculated. uint256 celoStableTokenExchangeRate; + // The veto period in seconds at the time the proposal was created. This is kept + // track of on a per-proposal basis to lock-in the veto period for a proposal so + // that changes to the contract's vetoPeriodSeconds do not affect existing + // proposals. + uint256 vetoPeriodSeconds; // The timestamp (`block.timestamp`) at which the exchange proposal was approved // in seconds. If the exchange proposal has not ever been approved, is 0. uint256 approvalTimestamp; @@ -253,6 +258,7 @@ contract GrandaMento is sellAmount: storedSellAmount, buyAmount: buyAmount, celoStableTokenExchangeRate: celoStableTokenExchangeRate, + vetoPeriodSeconds: vetoPeriodSeconds, approvalTimestamp: 0 // initial value when not approved yet }); // Push it into the array of active proposals. @@ -333,7 +339,7 @@ contract GrandaMento is /** * @notice Executes an exchange proposal that's been approved and not vetoed. * @dev Callable by anyone. Reverts if the proposal is not in the Approved state - * or vetoPeriodSeconds has not elapsed since approval. + * or proposal.vetoPeriodSeconds has not elapsed since approval. * @param proposalId The identifier of the proposal to execute. */ function executeExchangeProposal(uint256 proposalId) external nonReentrant { @@ -342,7 +348,7 @@ contract GrandaMento is require(proposal.state == ExchangeProposalState.Approved, "Proposal must be in Approved state"); // Require that the veto period has elapsed since the approval time. require( - proposal.approvalTimestamp.add(vetoPeriodSeconds) <= block.timestamp, + proposal.approvalTimestamp.add(proposal.vetoPeriodSeconds) <= block.timestamp, "Veto period not elapsed" ); // Mark the proposal as executed. Do so prior to exchanging as a measure against reentrancy. diff --git a/packages/protocol/test/liquidity/grandamento.ts b/packages/protocol/test/liquidity/grandamento.ts index 91672730930..3ac8180a7b8 100644 --- a/packages/protocol/test/liquidity/grandamento.ts +++ b/packages/protocol/test/liquidity/grandamento.ts @@ -57,7 +57,17 @@ enum ExchangeProposalState { } function parseExchangeProposal( - proposalRaw: [string, string, BigNumber, any, BigNumber, BigNumber, BigNumber, BigNumber] + proposalRaw: [ + string, + string, + BigNumber, + any, + BigNumber, + BigNumber, + BigNumber, + BigNumber, + BigNumber + ] ) { return { exchanger: proposalRaw[0], @@ -67,7 +77,8 @@ function parseExchangeProposal( sellAmount: proposalRaw[4], buyAmount: proposalRaw[5], celoStableTokenExchangeRate: proposalRaw[6], - approvalTimestamp: proposalRaw[7], + vetoPeriodSeconds: proposalRaw[7], + approvalTimestamp: proposalRaw[8], } } @@ -321,6 +332,7 @@ contract('GrandaMento', (accounts: string[]) => { getBuyAmount(fromFixed(oracleRate), sellAmount, spread) ) assertEqualBN(exchangeProposal.celoStableTokenExchangeRate, defaultCeloStableTokenRate) + assertEqualBN(exchangeProposal.vetoPeriodSeconds, vetoPeriodSeconds) assertEqualBN(exchangeProposal.approvalTimestamp, 0) }) } @@ -766,7 +778,21 @@ contract('GrandaMento', (accounts: string[]) => { }) }) - it('reverts when the vetoPeriodSeconds has not elapsed since the approval time', async () => { + it("executes the proposal when time since approval is between the proposal's vetoPeriodSeconds and the contract's vetoPeriodSeconds", async () => { + const newContractVetoPeriodSeconds = vetoPeriodSeconds * 2 + // Set the contract's vetoPeriodSeconds to a higher value than the proposal's + // vetoPeriodSeconds to illustrate that the proposal's vetoPeriodSeconds is used + // in the require. + await grandaMento.setVetoPeriodSeconds(newContractVetoPeriodSeconds) + await timeTravel(vetoPeriodSeconds, web3) + await grandaMento.executeExchangeProposal(1) + }) + + it("reverts when the proposal's vetoPeriodSeconds has not elapsed since the approval time", async () => { + // Set the contract's vetoPeriodSeconds to 0 to illustrate that + // the proposal's vetoPeriodSeconds is used rather than the contract's + // vetoPeriodSeconds. + await grandaMento.setVetoPeriodSeconds(0) // Traveling vetoPeriodSeconds - 1 can be flaky due to block times, // so instead just subtract by 10 to be safe. await timeTravel(vetoPeriodSeconds - 10, web3) From 10233f61f7c9400d94267388e6228def1d9e1a8a Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 11 Aug 2021 17:43:03 +0200 Subject: [PATCH 04/33] Check if executing a proposal would overflow (#8500) * Check if executing a proposal would overflow * Appease the linter * Fix typo * Fix search-and-replace --- .../contracts/liquidity/GrandaMento.sol | 6 ++ .../protocol/test/liquidity/grandamento.ts | 63 ++++++++++++++++++- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/packages/protocol/contracts/liquidity/GrandaMento.sol b/packages/protocol/contracts/liquidity/GrandaMento.sol index 73ce0709562..631d37be971 100644 --- a/packages/protocol/contracts/liquidity/GrandaMento.sol +++ b/packages/protocol/contracts/liquidity/GrandaMento.sol @@ -261,6 +261,12 @@ contract GrandaMento is vetoPeriodSeconds: vetoPeriodSeconds, approvalTimestamp: 0 // initial value when not approved yet }); + // StableToken.unitsToValue (called within getSellTokenAndSellAmount) can + // overflow for very large StableToken amounts. Call it here as a sanity + // check, so that the overflow happens here, blocking proposal creation + // rather than when attempting to execute the proposal, which would lock + // funds in this contract. + getSellTokenAndSellAmount(exchangeProposals[exchangeProposalCount]); // Push it into the array of active proposals. activeProposalIdsSuperset.push(exchangeProposalCount); // Even if stable tokens are being sold, the sellAmount emitted is the "value." diff --git a/packages/protocol/test/liquidity/grandamento.ts b/packages/protocol/test/liquidity/grandamento.ts index 3ac8180a7b8..f8dc56404ef 100644 --- a/packages/protocol/test/liquidity/grandamento.ts +++ b/packages/protocol/test/liquidity/grandamento.ts @@ -9,6 +9,8 @@ import { import { fromFixed, reciprocal, toFixed } from '@celo/utils/lib/fixidity' import BigNumber from 'bignumber.js' import { + FreezerContract, + FreezerInstance, GoldTokenContract, GoldTokenInstance, GrandaMentoContract, @@ -23,8 +25,12 @@ import { MockStableTokenInstance, RegistryContract, RegistryInstance, + StableTokenContract, + StableTokenInstance, } from 'types' +import { SECONDS_IN_A_WEEK } from '../constants' +const Freezer: FreezerContract = artifacts.require('Freezer') const GoldToken: GoldTokenContract = artifacts.require('GoldToken') const GrandaMento: GrandaMentoContract = artifacts.require('GrandaMento') const MockGoldToken: MockGoldTokenContract = artifacts.require('MockGoldToken') @@ -32,6 +38,7 @@ const MockSortedOracles: MockSortedOraclesContract = artifacts.require('MockSort const MockStableToken: MockStableTokenContract = artifacts.require('MockStableToken') const Registry: RegistryContract = artifacts.require('Registry') const MockReserve: MockReserveContract = artifacts.require('MockReserve') +const StableToken: StableTokenContract = artifacts.require('StableToken') // @ts-ignore GoldToken.numberFormat = 'BigNumber' @@ -127,18 +134,22 @@ contract('GrandaMento', (accounts: string[]) => { const createExchangeProposal = async ( sellCelo: boolean, from: string = owner, - _stableTokenRegistryId?: CeloContractName + _stableTokenRegistryId?: CeloContractName, + sellAmount?: BigNumber ) => { + if (!sellAmount) { + sellAmount = sellCelo ? celoSellAmount : stableTokenSellAmount + } // When a test sets sellCelo to true, the sender in the test must approve // the CELO to grandaMento. // The MockStableToken does not enforce allowances so there is no need // to approve the stable token to grandaMento when sellCelo is false. if (sellCelo) { - await goldToken.approve(grandaMento.address, celoSellAmount, { from }) + await goldToken.approve(grandaMento.address, sellAmount, { from }) } return grandaMento.createExchangeProposal( _stableTokenRegistryId || stableTokenRegistryId, - sellCelo ? celoSellAmount : stableTokenSellAmount, + sellAmount, sellCelo, { from } ) @@ -260,6 +271,52 @@ contract('GrandaMento', (accounts: string[]) => { assertEqualBN(await grandaMento.activeProposalIdsSuperset(1), new BigNumber(2)) }) + it('fails if the stable token amount would overflow in a unitsToValue call', async () => { + // We need to deploy the real StableToken contract because MockStableToken + // calls balanceOf during transfers which can overflow before the overflow + // we actually want to detect. + const realStableToken: StableTokenInstance = await StableToken.new(true) + await registry.setAddressFor(stableTokenRegistryId, realStableToken.address) + + await sortedOracles.setMedianRate(realStableToken.address, defaultCeloStableTokenRate) + await sortedOracles.setMedianTimestampToNow(realStableToken.address) + await sortedOracles.setNumRates(realStableToken.address, 2) + + // StableToken.transferFrom is freezable so it looks up Freezer in the + // Registry + const freezer: FreezerInstance = await Freezer.new(true) + await freezer.initialize() + await registry.setAddressFor(CeloContractName.Freezer, freezer.address) + + // We set ourselves as the Exchange to be able to mint + await registry.setAddressFor('Exchange', owner) + await realStableToken.initialize( + 'Celo Dollar', + 'cUSD', + 18, + registry.address, + unit, + SECONDS_IN_A_WEEK, + [], + [], + 'Exchange' // USD + ) + + await grandaMento.setStableTokenExchangeLimits( + stableTokenRegistryId, + minExchangeAmount, + unit.times(2e12) + ) + const sellAmount = unit.times(2e11) + await realStableToken.mint(owner, sellAmount) + await realStableToken.approve(grandaMento.address, sellAmount) + + await assertRevertWithReason( + createExchangeProposal(false, owner, stableTokenRegistryId, sellAmount), + 'overflow at divide' + ) + }) + for (const sellCelo of [true, false]) { let sellTokenString: string let sellAmount: BigNumber From 75e4c40a50c5702d1b642524a23113411c7052ba Mon Sep 17 00:00:00 2001 From: Trevor Porter Date: Mon, 26 Jul 2021 22:49:42 +0200 Subject: [PATCH 05/33] Move GrandaMento from liquidity dir to stability (#8300) ### Description CI doesn't automatically look at new directories, so just moving GrandaMento to the stability directory. ### Other changes n/a ### Tested Building & testing ### Related issues n/a ### Backwards compatibility Yes ### Documentation n/a --- .../protocol/contracts/{liquidity => stability}/GrandaMento.sol | 0 packages/protocol/test/{liquidity => stability}/grandamento.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename packages/protocol/contracts/{liquidity => stability}/GrandaMento.sol (100%) rename packages/protocol/test/{liquidity => stability}/grandamento.ts (100%) diff --git a/packages/protocol/contracts/liquidity/GrandaMento.sol b/packages/protocol/contracts/stability/GrandaMento.sol similarity index 100% rename from packages/protocol/contracts/liquidity/GrandaMento.sol rename to packages/protocol/contracts/stability/GrandaMento.sol diff --git a/packages/protocol/test/liquidity/grandamento.ts b/packages/protocol/test/stability/grandamento.ts similarity index 100% rename from packages/protocol/test/liquidity/grandamento.ts rename to packages/protocol/test/stability/grandamento.ts From 7e7569f5bd1fb96b25441c93780a1f036cb8b03c Mon Sep 17 00:00:00 2001 From: luisgj Date: Tue, 19 Oct 2021 18:13:33 -0500 Subject: [PATCH 06/33] cBRL contract from contracts.v5 tag --- .../contracts/stability/ExchangeBRL.sol | 18 +++++++++++++++++ .../contracts/stability/StableTokenBRL.sol | 20 +++++++++++++++++++ .../stability/proxies/ExchangeBRLProxy.sol | 6 ++++++ .../stability/proxies/StableTokenBRLProxy.sol | 6 ++++++ .../initializationData/release6.json | 4 ++++ 5 files changed, 54 insertions(+) create mode 100644 packages/protocol/contracts/stability/ExchangeBRL.sol create mode 100644 packages/protocol/contracts/stability/StableTokenBRL.sol create mode 100644 packages/protocol/contracts/stability/proxies/ExchangeBRLProxy.sol create mode 100644 packages/protocol/contracts/stability/proxies/StableTokenBRLProxy.sol create mode 100644 packages/protocol/releaseData/initializationData/release6.json diff --git a/packages/protocol/contracts/stability/ExchangeBRL.sol b/packages/protocol/contracts/stability/ExchangeBRL.sol new file mode 100644 index 00000000000..f8834be65e9 --- /dev/null +++ b/packages/protocol/contracts/stability/ExchangeBRL.sol @@ -0,0 +1,18 @@ +import "./Exchange.sol"; + +contract ExchangeBRL is Exchange { + /** + * @notice Sets initialized == true on implementation contracts + * @param test Set to true to skip implementation initialization + */ + constructor(bool test) public Exchange(test) {} + + /** + * @notice Returns the storage, major, minor, and patch version of the contract. +* @dev This function is overloaded to maintain a distinct version from Exchange.sol. +* @return The storage, major, minor, and patch version of the contract. +*/ + function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { + return (1, 1, 0, 0); + } +} diff --git a/packages/protocol/contracts/stability/StableTokenBRL.sol b/packages/protocol/contracts/stability/StableTokenBRL.sol new file mode 100644 index 00000000000..c3eb7d4e7a4 --- /dev/null +++ b/packages/protocol/contracts/stability/StableTokenBRL.sol @@ -0,0 +1,20 @@ +pragma solidity ^0.5.13; + +import "./StableToken.sol"; + +contract StableTokenBRL is StableToken { + /** + * @notice Sets initialized == true on implementation contracts. + * @param test Set to true to skip implementation initialization. + */ + constructor(bool test) public StableToken(test) {} + + /** + * @notice Returns the storage, major, minor, and patch version of the contract. + * @dev This function is overloaded to maintain a distinct version from StableToken.sol. + * @return The storage, major, minor, and patch version of the contract. + */ + function getVersionNumber() external pure returns (uint256, uint256, uint256, uint256) { + return (1, 1, 0, 0); + } +} diff --git a/packages/protocol/contracts/stability/proxies/ExchangeBRLProxy.sol b/packages/protocol/contracts/stability/proxies/ExchangeBRLProxy.sol new file mode 100644 index 00000000000..2ca17219b50 --- /dev/null +++ b/packages/protocol/contracts/stability/proxies/ExchangeBRLProxy.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.5.13; + +import "../../common/Proxy.sol"; + +/* solhint-disable no-empty-blocks */ +contract ExchangeBRLProxy is Proxy {} diff --git a/packages/protocol/contracts/stability/proxies/StableTokenBRLProxy.sol b/packages/protocol/contracts/stability/proxies/StableTokenBRLProxy.sol new file mode 100644 index 00000000000..11648bc686a --- /dev/null +++ b/packages/protocol/contracts/stability/proxies/StableTokenBRLProxy.sol @@ -0,0 +1,6 @@ +pragma solidity ^0.5.13; + +import "../../common/Proxy.sol"; + +/* solhint-disable no-empty-blocks */ +contract StableTokenBRLProxy is Proxy {} diff --git a/packages/protocol/releaseData/initializationData/release6.json b/packages/protocol/releaseData/initializationData/release6.json new file mode 100644 index 00000000000..a2d21ce7e94 --- /dev/null +++ b/packages/protocol/releaseData/initializationData/release6.json @@ -0,0 +1,4 @@ +{ + "StableTokenBRL": ["Celo Real", "cBRL", 18, "0x000000000000000000000000000000000000ce10", "1000000000000000000000000", "47304000", ["0xD533Ca259b330c7A88f74E000a3FaEa2d63B7972", "0x989e1a3B344A43911e02cCC609D469fbc15AB1F1"], ["2000000000000000000000000", "6000000000000000000000000"], "ExchangeBRL"], + "ExchangeBRL": ["0x000000000000000000000000000000000000ce10", "0x0000000000000000000000000000000000000000", "5000000000000000000000", "1300000000000000000000", "300", "5"] +} From 64a4a45eccb3e3fba616ff95a782d0fc5998e091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 26 Oct 2021 14:14:36 +0200 Subject: [PATCH 07/33] Added constitution parameters to cREAL --- packages/protocol/governanceConstitution.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/protocol/governanceConstitution.js b/packages/protocol/governanceConstitution.js index fa433496bf0..b0ceff0e5dd 100644 --- a/packages/protocol/governanceConstitution.js +++ b/packages/protocol/governanceConstitution.js @@ -61,6 +61,15 @@ const DefaultConstitution = { setStableToken: 0.8, setSpread: 0.8, setReserveFraction: 0.8, + }, + ExchangeBRL: { + default: 0.8, + setRegistry: 0.9, + setUpdateFrequency: 0.8, + setMinimumReports: 0.8, + setStableToken: 0.8, + setSpread: 0.8, + setReserveFraction: 0.8, }, FeeCurrencyWhitelist: { default: 0.8, @@ -171,6 +180,14 @@ const DefaultConstitution = { transferWithComment: 0.6, approve: 0.6, }, + StableTokenBRL: { + default: 0.8, + setRegistry: 0.9, + setInflationParameters: 0.9, + transfer: 0.6, + transferWithComment: 0.6, + approve: 0.6, + }, Validators: { default: 0.7, setRegistry: 0.9, From 9c1f98138f89ef4f352f264139972e8649ddc1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Thu, 28 Oct 2021 00:23:22 +0200 Subject: [PATCH 08/33] Changing cREAL parameters --- .../protocol/releaseData/initializationData/creal_deploy.json | 4 ++++ .../protocol/releaseData/initializationData/release6.json | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 packages/protocol/releaseData/initializationData/creal_deploy.json delete mode 100644 packages/protocol/releaseData/initializationData/release6.json diff --git a/packages/protocol/releaseData/initializationData/creal_deploy.json b/packages/protocol/releaseData/initializationData/creal_deploy.json new file mode 100644 index 00000000000..9861e7fe165 --- /dev/null +++ b/packages/protocol/releaseData/initializationData/creal_deploy.json @@ -0,0 +1,4 @@ +{ + "StableTokenBRL": ["Celo Brazilian Real", "cReal", 18, "0x000000000000000000000000000000000000ce10", "1000000000000000000000000", "47304000", ["0xD533Ca259b330c7A88f74E000a3FaEa2d63B7972", "0x989e1a3B344A43911e02cCC609D469fbc15AB1F1"], ["2000000000000000000000000", "6000000000000000000000000"], "ExchangeBRL"], + "ExchangeBRL": ["0x000000000000000000000000000000000000ce10", "0x0000000000000000000000000000000000000000", "2500000000000000000000", "1300000000000000000000", "300", "5"] +} diff --git a/packages/protocol/releaseData/initializationData/release6.json b/packages/protocol/releaseData/initializationData/release6.json deleted file mode 100644 index a2d21ce7e94..00000000000 --- a/packages/protocol/releaseData/initializationData/release6.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "StableTokenBRL": ["Celo Real", "cBRL", 18, "0x000000000000000000000000000000000000ce10", "1000000000000000000000000", "47304000", ["0xD533Ca259b330c7A88f74E000a3FaEa2d63B7972", "0x989e1a3B344A43911e02cCC609D469fbc15AB1F1"], ["2000000000000000000000000", "6000000000000000000000000"], "ExchangeBRL"], - "ExchangeBRL": ["0x000000000000000000000000000000000000ce10", "0x0000000000000000000000000000000000000000", "5000000000000000000000", "1300000000000000000000", "300", "5"] -} From 5aa77e26886cd3c3fc9f7fb1f4a11822b5d56357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Thu, 28 Oct 2021 00:23:58 +0200 Subject: [PATCH 09/33] Update packages/protocol/releaseData/initializationData/creal_deploy.json --- .../protocol/releaseData/initializationData/creal_deploy.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/releaseData/initializationData/creal_deploy.json b/packages/protocol/releaseData/initializationData/creal_deploy.json index 9861e7fe165..2fa33272659 100644 --- a/packages/protocol/releaseData/initializationData/creal_deploy.json +++ b/packages/protocol/releaseData/initializationData/creal_deploy.json @@ -1,4 +1,4 @@ { - "StableTokenBRL": ["Celo Brazilian Real", "cReal", 18, "0x000000000000000000000000000000000000ce10", "1000000000000000000000000", "47304000", ["0xD533Ca259b330c7A88f74E000a3FaEa2d63B7972", "0x989e1a3B344A43911e02cCC609D469fbc15AB1F1"], ["2000000000000000000000000", "6000000000000000000000000"], "ExchangeBRL"], + "StableTokenBRL": ["Celo Brazilian Real", "cREAL", 18, "0x000000000000000000000000000000000000ce10", "1000000000000000000000000", "47304000", ["0xD533Ca259b330c7A88f74E000a3FaEa2d63B7972", "0x989e1a3B344A43911e02cCC609D469fbc15AB1F1"], ["2000000000000000000000000", "6000000000000000000000000"], "ExchangeBRL"], "ExchangeBRL": ["0x000000000000000000000000000000000000ce10", "0x0000000000000000000000000000000000000000", "2500000000000000000000", "1300000000000000000000", "300", "5"] } From a4276324e1c89bdaf97da1527a0bc2c81730c406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Sat, 30 Oct 2021 22:23:58 +0200 Subject: [PATCH 10/33] Added migrations cREAL --- packages/protocol/lib/registry-utils.ts | 2 + .../migrations/09_2_stableToken_BRL.ts | 92 +++++++++++++++++++ .../protocol/migrations/10_2_exchange_BRL.ts | 53 +++++++++++ packages/protocol/test/common/integration.ts | 1 + 4 files changed, 148 insertions(+) create mode 100644 packages/protocol/migrations/09_2_stableToken_BRL.ts create mode 100644 packages/protocol/migrations/10_2_exchange_BRL.ts diff --git a/packages/protocol/lib/registry-utils.ts b/packages/protocol/lib/registry-utils.ts index dd4a0f7f3f4..d6dae2db095 100644 --- a/packages/protocol/lib/registry-utils.ts +++ b/packages/protocol/lib/registry-utils.ts @@ -19,6 +19,7 @@ export enum CeloContractName { Escrow = 'Escrow', Exchange = 'Exchange', ExchangeEUR = 'ExchangeEUR', + ExchangeBRL = 'ExchangeBRL', FeeCurrencyWhitelist = 'FeeCurrencyWhitelist', Freezer = 'Freezer', GasPriceMinimum = 'GasPriceMinimum', @@ -34,6 +35,7 @@ export enum CeloContractName { SortedOracles = 'SortedOracles', StableToken = 'StableToken', StableTokenEUR = 'StableTokenEUR', + StableTokenBRL = 'StableTokenBRL', TransferWhitelist = 'TransferWhitelist', Validators = 'Validators', } diff --git a/packages/protocol/migrations/09_2_stableToken_BRL.ts b/packages/protocol/migrations/09_2_stableToken_BRL.ts new file mode 100644 index 00000000000..562bc170db9 --- /dev/null +++ b/packages/protocol/migrations/09_2_stableToken_BRL.ts @@ -0,0 +1,92 @@ +/* tslint:disable:no-console */ +import { ensureLeading0x, eqAddress, NULL_ADDRESS } from '@celo/base/lib/address' +import { CeloContractName } from '@celo/protocol/lib/registry-utils' +import { + deploymentForCoreContract, + getDeployedProxiedContract, +} from '@celo/protocol/lib/web3-utils' +import { config } from '@celo/protocol/migrationsConfig' +import { toFixed } from '@celo/utils/lib/fixidity' +import { + FeeCurrencyWhitelistInstance, + FreezerInstance, + ReserveInstance, + SortedOraclesInstance, + StableTokenBRLInstance, +} from 'types' +import Web3 from 'web3' + +const truffle = require('@celo/protocol/truffle-config.js') + +const initializeArgs = async (): Promise => { + const rate = toFixed(config.stableTokenBRL.inflationRate) + return [ + config.stableTokenBRL.tokenName, + config.stableTokenBRL.tokenSymbol, + config.stableTokenBRL.decimals, + config.registry.predeployedProxyAddress, + rate.toString(), + config.stableTokenBRL.inflationPeriod, + config.stableTokenBRL.initialBalances.addresses, + config.stableTokenBRL.initialBalances.values, + 'ExchangeBRL', + ] +} + +// TODO make this general +module.exports = deploymentForCoreContract( + web3, + artifacts, + CeloContractName.StableTokenBRL, + initializeArgs, + async (stableToken: StableTokenBRLInstance, _web3: Web3, networkName: string) => { + if (config.stableTokenBRL.frozen) { + const freezer: FreezerInstance = await getDeployedProxiedContract( + 'Freezer', + artifacts + ) + await freezer.freeze(stableToken.address) + } + const sortedOracles: SortedOraclesInstance = await getDeployedProxiedContract( + 'SortedOracles', + artifacts + ) + + for (const oracle of config.stableTokenBRL.oracles) { + console.info(`Adding ${oracle} as an Oracle for StableToken (BRL)`) + await sortedOracles.addOracle(stableToken.address, ensureLeading0x(oracle)) + } + + const goldPrice = config.stableTokenBRL.goldPrice + if (goldPrice) { + const fromAddress = truffle.networks[networkName].from + const isOracle = config.stableTokenBRL.oracles.some((o) => eqAddress(o, fromAddress)) + if (!isOracle) { + console.warn( + `Gold price specified in migration but ${fromAddress} not explicitly authorized as oracle, authorizing...` + ) + await sortedOracles.addOracle(stableToken.address, ensureLeading0x(fromAddress)) + } + console.info('Reporting price of StableToken (BRL) to oracle') + await sortedOracles.report( + stableToken.address, + toFixed(goldPrice), + NULL_ADDRESS, + NULL_ADDRESS + ) + const reserve: ReserveInstance = await getDeployedProxiedContract( + 'Reserve', + artifacts + ) + console.info('Adding StableToken (BRL) to Reserve') + await reserve.addToken(stableToken.address) + } + + console.info('Whitelisting StableToken (BRL) as a fee currency') + const feeCurrencyWhitelist: FeeCurrencyWhitelistInstance = await getDeployedProxiedContract( + 'FeeCurrencyWhitelist', + artifacts + ) + await feeCurrencyWhitelist.addToken(stableToken.address) + } +) diff --git a/packages/protocol/migrations/10_2_exchange_BRL.ts b/packages/protocol/migrations/10_2_exchange_BRL.ts new file mode 100644 index 00000000000..50f5053d066 --- /dev/null +++ b/packages/protocol/migrations/10_2_exchange_BRL.ts @@ -0,0 +1,53 @@ +/* tslint:disable:no-console */ + +import { CeloContractName } from '@celo/protocol/lib/registry-utils' +import { + deploymentForCoreContract, + getDeployedProxiedContract, +} from '@celo/protocol/lib/web3-utils' +import { config } from '@celo/protocol/migrationsConfig' +import { toFixed } from '@celo/utils/lib/fixidity' +import { + ExchangeBRLInstance, + FreezerInstance, + ReserveInstance, + StableTokenBRLInstance, +} from 'types' + +const initializeArgs = async (): Promise => { + const stableTokenBRL: StableTokenBRLInstance = await getDeployedProxiedContract( + 'StableTokenBRL', + artifacts + ) + return [ + config.registry.predeployedProxyAddress, + stableTokenBRL.address, + toFixed(config.exchange.spread).toString(), + toFixed(config.exchange.reserveFraction).toString(), + config.exchange.updateFrequency, + config.exchange.minimumReports, + ] +} + +module.exports = deploymentForCoreContract( + web3, + artifacts, + CeloContractName.ExchangeBRL, + initializeArgs, + async (exchange: ExchangeBRLInstance) => { + if (config.exchange.frozen) { + const freezer: FreezerInstance = await getDeployedProxiedContract( + 'Freezer', + artifacts + ) + await freezer.freeze(exchange.address) + } + + const reserve: ReserveInstance = await getDeployedProxiedContract( + 'Reserve', + artifacts + ) + // cUSD doesn't need to be added as it currently harcoded in Reserve.sol + await reserve.addExchangeSpender(exchange.address) + } +) diff --git a/packages/protocol/test/common/integration.ts b/packages/protocol/test/common/integration.ts index 13a5a401238..acb931cb745 100644 --- a/packages/protocol/test/common/integration.ts +++ b/packages/protocol/test/common/integration.ts @@ -394,6 +394,7 @@ contract('Integration: Governance', (accounts: string[]) => { Array.from([ ['Exchange', 'StableToken'], // USD ['ExchangeEUR', 'StableTokenEUR'], // EUR + ['ExchangeBRL', 'StableTokenBRL'], // BRL ]).forEach(([exchangeId, stableTokenId]) => contract(`Integration: ${exchangeId} ${stableTokenId}`, (accounts: string[]) => { const transferAmount = 10 From c14464057f3be87acae031ed49d802077867bacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Sat, 30 Oct 2021 22:51:04 +0200 Subject: [PATCH 11/33] Added integration tests and migrations config --- packages/protocol/migrationsConfig.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/protocol/migrationsConfig.js b/packages/protocol/migrationsConfig.js index 136bd7cbffa..9563a2a4a86 100644 --- a/packages/protocol/migrationsConfig.js +++ b/packages/protocol/migrationsConfig.js @@ -182,6 +182,20 @@ const DefaultConfig = { oracles: [network.from], frozen: false, }, + stableTokenBRL: { + decimals: 18, + goldPrice: 1.2, + tokenName: 'Celo Euro', + tokenSymbol: 'cEUR', + inflationRate: 1, + inflationPeriod: 1.5 * YEAR, + initialBalances: { + addresses: [network.from], + values: ['5000000000000000000000000'], + }, + oracles: [network.from], + frozen: false, + }, transferWhitelist: { addresses: [], registryIds: [], From 95816c9162ad2c283f5b6edec7245d20f332104d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 2 Nov 2021 15:18:46 +0100 Subject: [PATCH 12/33] lint --- packages/protocol/governanceConstitution.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/governanceConstitution.js b/packages/protocol/governanceConstitution.js index b0ceff0e5dd..bcc1732ba9a 100644 --- a/packages/protocol/governanceConstitution.js +++ b/packages/protocol/governanceConstitution.js @@ -62,7 +62,7 @@ const DefaultConstitution = { setSpread: 0.8, setReserveFraction: 0.8, }, - ExchangeBRL: { + ExchangeBRL: { default: 0.8, setRegistry: 0.9, setUpdateFrequency: 0.8, From 2958943d10f785b1d4be49626ce9a82800cfbaba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 2 Nov 2021 17:53:54 +0100 Subject: [PATCH 13/33] Update packages/protocol/test/common/integration.ts --- packages/protocol/test/common/integration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/test/common/integration.ts b/packages/protocol/test/common/integration.ts index acb931cb745..9b9d4940ff4 100644 --- a/packages/protocol/test/common/integration.ts +++ b/packages/protocol/test/common/integration.ts @@ -394,7 +394,7 @@ contract('Integration: Governance', (accounts: string[]) => { Array.from([ ['Exchange', 'StableToken'], // USD ['ExchangeEUR', 'StableTokenEUR'], // EUR - ['ExchangeBRL', 'StableTokenBRL'], // BRL + ['ExchangeBRL', 'StableTokenBRL'], // BRL (cREAL) ]).forEach(([exchangeId, stableTokenId]) => contract(`Integration: ${exchangeId} ${stableTokenId}`, (accounts: string[]) => { const transferAmount = 10 From 89fcede0f552c15492499bcd05607efcf555aeef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Wed, 3 Nov 2021 15:34:47 +0100 Subject: [PATCH 14/33] Removed json --- .../initializationData/{creal_deploy.json => release6.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/protocol/releaseData/initializationData/{creal_deploy.json => release6.json} (100%) diff --git a/packages/protocol/releaseData/initializationData/creal_deploy.json b/packages/protocol/releaseData/initializationData/release6.json similarity index 100% rename from packages/protocol/releaseData/initializationData/creal_deploy.json rename to packages/protocol/releaseData/initializationData/release6.json From 035dddc258f19630ef2dec6996813b018890e550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Wed, 3 Nov 2021 15:45:45 +0100 Subject: [PATCH 15/33] retigger CI From b0f4a12e701135350cb71e23e9cefb5656c7b4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Wed, 3 Nov 2021 16:45:07 +0100 Subject: [PATCH 16/33] Changed base RELEASE_TAG --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 25d16851fe1..1dde9665e30 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,7 +34,7 @@ defaults: &defaults contract-defaults: &contract-defaults <<: *defaults environment: - RELEASE_TAG: core-contracts.v4 + RELEASE_TAG: core-contracts.v5 e2e-defaults: &e2e-defaults <<: *defaults From 5ebade06ce233c02daa44e6203bf490c166c7957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Wed, 3 Nov 2021 17:07:27 +0100 Subject: [PATCH 17/33] Added release5-report.json --- .../versionReports/release5-report.json | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 packages/protocol/releaseData/versionReports/release5-report.json diff --git a/packages/protocol/releaseData/versionReports/release5-report.json b/packages/protocol/releaseData/versionReports/release5-report.json new file mode 100644 index 00000000000..8fb0ed9b192 --- /dev/null +++ b/packages/protocol/releaseData/versionReports/release5-report.json @@ -0,0 +1,105 @@ +{ + "oldArtifactsFolder": "/home/circleci/app/packages/protocol/build/core-contracts.v4/contracts", + "newArtifactsFolder": "/home/circleci/app/packages/protocol/build/core-contracts.v5/contracts", + "exclude": "/.*Test|Mock.*|I[A-Z].*|.*Proxy|MultiSig.*|ReleaseGold|SlasherUtil|UsingPrecompiles/", + "report": { + "contracts": { + "GrandaMento": { + "changes": { + "storage": [], + "major": [ + { + "contract": "GrandaMento", + "type": "NewContract" + } + ], + "minor": [], + "patch": [] + }, + "versionDelta": { + "storage": "=", + "major": "+1", + "minor": "0", + "patch": "0" + } + }, + "UsingRegistryV2": { + "changes": { + "storage": [], + "major": [ + { + "contract": "UsingRegistryV2", + "type": "NewContract" + } + ], + "minor": [], + "patch": [] + }, + "versionDelta": { + "storage": "=", + "major": "+1", + "minor": "0", + "patch": "0" + } + }, + "StableToken": { + "changes": { + "storage": [], + "major": [], + "minor": [], + "patch": [ + { + "contract": "StableToken", + "type": "DeployedBytecode" + } + ] + }, + "versionDelta": { + "storage": "=", + "major": "=", + "minor": "=", + "patch": "+1" + } + }, + "StableTokenEUR": { + "changes": { + "storage": [], + "major": [], + "minor": [], + "patch": [ + { + "contract": "StableTokenEUR", + "type": "DeployedBytecode" + } + ] + }, + "versionDelta": { + "storage": "=", + "major": "=", + "minor": "=", + "patch": "+1" + } + }, + "Validators": { + "changes": { + "storage": [], + "major": [], + "minor": [], + "patch": [ + { + "contract": "Validators", + "type": "DeployedBytecode" + } + ] + }, + "versionDelta": { + "storage": "=", + "major": "=", + "minor": "=", + "patch": "+1" + } + } + }, + "libraries": {} + } +} \ No newline at end of file From a60635a4544f8f8e1ad2b902d7f891117cc68fbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Wed, 3 Nov 2021 18:11:09 +0100 Subject: [PATCH 18/33] new line --- .../protocol/releaseData/versionReports/release5-report.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/releaseData/versionReports/release5-report.json b/packages/protocol/releaseData/versionReports/release5-report.json index 8fb0ed9b192..62e24408edc 100644 --- a/packages/protocol/releaseData/versionReports/release5-report.json +++ b/packages/protocol/releaseData/versionReports/release5-report.json @@ -102,4 +102,4 @@ }, "libraries": {} } -} \ No newline at end of file +} From 452db85836374e9f6eb675d86df7dfb47be770be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Wed, 3 Nov 2021 18:58:06 +0100 Subject: [PATCH 19/33] Added CR6 script --- .../scripts/make-release-6-changes.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 packages/protocol/scripts/make-release-6-changes.ts diff --git a/packages/protocol/scripts/make-release-6-changes.ts b/packages/protocol/scripts/make-release-6-changes.ts new file mode 100644 index 00000000000..245c77abc49 --- /dev/null +++ b/packages/protocol/scripts/make-release-6-changes.ts @@ -0,0 +1,35 @@ +import { ensureLeading0x, trimLeading0x } from '@celo/base' +import { readJsonSync, writeJsonSync } from 'fs-extra' +import { + getProposedProxyAddress, + isProxyRepointAndInitForIdTransaction, +} from '../lib/compatibility/verify-bytecode' +import { ProposalTx } from './truffle/make-release' + +const makeRelease3Changes = (releaseProposal: ProposalTx[]) => { + const stableTokenBRLaddr = getProposedProxyAddress('StableTokenBRL', releaseProposal) + const exchangeInitIndex = releaseProposal.findIndex((tx) => + isProxyRepointAndInitForIdTransaction(tx, 'ExchangeBRLProxy') + ) + const initCallData = trimLeading0x(releaseProposal[exchangeInitIndex].args[1]) + const paramPosition = (4 + 32) * 2 // (functionSelector + 1 parameter) * 2 hex + releaseProposal[exchangeInitIndex].args[1] = ensureLeading0x( + initCallData.slice(0, paramPosition) + + trimLeading0x(stableTokenBRLaddr).padStart(64, '0') + + initCallData.slice(paramPosition + 32 * 2) // offset 1 parameter * 2 hex + ) + return releaseProposal +} + +try { + const argv = require('minimist')(process.argv.slice(2), { + string: ['input_proposal', 'output_proposal'], + }) + const releaseProposal: ProposalTx[] = readJsonSync(argv.input_proposal) + writeJsonSync(argv.output_proposal, makeRelease3Changes(releaseProposal), { spaces: 2 }) + // tslint:disable-next-line: no-console + console.log(`Modifications made sucessfully; written to ${argv.output_proposal}`) +} catch (e) { + // tslint:disable-next-line: no-console + console.error(`Something went wrong: ${e}`) +} From f4abaa6ca0dbf7a623e46978a920cae51d8d9b42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Sun, 7 Nov 2021 22:15:56 +0100 Subject: [PATCH 20/33] Fixed typos --- packages/protocol/migrations/10_1_exchange_EUR.ts | 2 +- packages/protocol/migrations/10_2_exchange_BRL.ts | 2 +- packages/protocol/scripts/make-release-6-changes.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/protocol/migrations/10_1_exchange_EUR.ts b/packages/protocol/migrations/10_1_exchange_EUR.ts index 11806370c88..425a967b3a1 100644 --- a/packages/protocol/migrations/10_1_exchange_EUR.ts +++ b/packages/protocol/migrations/10_1_exchange_EUR.ts @@ -47,7 +47,7 @@ module.exports = deploymentForCoreContract( 'Reserve', artifacts ) - // cUSD doesn't need to be added as it currently harcoded in Reserve.sol + // cUSD doesn't need to be added as it is currently harcoded in Reserve.sol await reserve.addExchangeSpender(exchange.address) } ) diff --git a/packages/protocol/migrations/10_2_exchange_BRL.ts b/packages/protocol/migrations/10_2_exchange_BRL.ts index 50f5053d066..c7f42903f4e 100644 --- a/packages/protocol/migrations/10_2_exchange_BRL.ts +++ b/packages/protocol/migrations/10_2_exchange_BRL.ts @@ -47,7 +47,7 @@ module.exports = deploymentForCoreContract( 'Reserve', artifacts ) - // cUSD doesn't need to be added as it currently harcoded in Reserve.sol + // cUSD doesn't need to be added as it is currently harcoded in Reserve.sol await reserve.addExchangeSpender(exchange.address) } ) diff --git a/packages/protocol/scripts/make-release-6-changes.ts b/packages/protocol/scripts/make-release-6-changes.ts index 245c77abc49..d5b2c0bbf4e 100644 --- a/packages/protocol/scripts/make-release-6-changes.ts +++ b/packages/protocol/scripts/make-release-6-changes.ts @@ -6,7 +6,7 @@ import { } from '../lib/compatibility/verify-bytecode' import { ProposalTx } from './truffle/make-release' -const makeRelease3Changes = (releaseProposal: ProposalTx[]) => { +const makeRelease6Changes = (releaseProposal: ProposalTx[]) => { const stableTokenBRLaddr = getProposedProxyAddress('StableTokenBRL', releaseProposal) const exchangeInitIndex = releaseProposal.findIndex((tx) => isProxyRepointAndInitForIdTransaction(tx, 'ExchangeBRLProxy') @@ -26,7 +26,7 @@ try { string: ['input_proposal', 'output_proposal'], }) const releaseProposal: ProposalTx[] = readJsonSync(argv.input_proposal) - writeJsonSync(argv.output_proposal, makeRelease3Changes(releaseProposal), { spaces: 2 }) + writeJsonSync(argv.output_proposal, makeRelease6Changes(releaseProposal), { spaces: 2 }) // tslint:disable-next-line: no-console console.log(`Modifications made sucessfully; written to ${argv.output_proposal}`) } catch (e) { From c2ddce54a7cc9ba8c2aad117bd7ebbb018f5e31c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Sun, 7 Nov 2021 23:34:36 +0100 Subject: [PATCH 21/33] contractkit now knows BRL exists --- packages/protocol/scripts/build.ts | 4 ++++ packages/sdk/contractkit/src/base.ts | 2 ++ packages/sdk/contractkit/src/web3-contract-cache.ts | 3 +++ 3 files changed, 9 insertions(+) diff --git a/packages/protocol/scripts/build.ts b/packages/protocol/scripts/build.ts index 9ceb32f940b..4a9dbb06738 100644 --- a/packages/protocol/scripts/build.ts +++ b/packages/protocol/scripts/build.ts @@ -18,6 +18,7 @@ export const ProxyContracts = [ 'ElectionProxy', 'EpochRewardsProxy', 'EscrowProxy', + 'ExchangeBRLProxy', 'ExchangeEURProxy', 'ExchangeProxy', 'FeeCurrencyWhitelistProxy', @@ -31,6 +32,7 @@ export const ProxyContracts = [ 'RegistryProxy', 'ReserveProxy', 'ReserveSpenderMultiSigProxy', + 'StableTokenBRLProxy', 'StableTokenEURProxy', 'StableTokenProxy', 'SortedOraclesProxy', @@ -69,10 +71,12 @@ export const CoreContracts = [ // stability 'Exchange', 'ExchangeEUR', + 'ExchangeBRL', 'Reserve', 'ReserveSpenderMultiSig', 'StableToken', 'StableTokenEUR', + 'StableTokenBRL', 'SortedOracles', ] diff --git a/packages/sdk/contractkit/src/base.ts b/packages/sdk/contractkit/src/base.ts index ed079912dae..c3f5d1e2030 100644 --- a/packages/sdk/contractkit/src/base.ts +++ b/packages/sdk/contractkit/src/base.ts @@ -10,6 +10,7 @@ export enum CeloContract { Escrow = 'Escrow', Exchange = 'Exchange', ExchangeEUR = 'ExchangeEUR', + ExchangeBRL = 'ExchangeBRL', FeeCurrencyWhitelist = 'FeeCurrencyWhitelist', Freezer = 'Freezer', GasPriceMinimum = 'GasPriceMinimum', @@ -25,6 +26,7 @@ export enum CeloContract { SortedOracles = 'SortedOracles', StableToken = 'StableToken', StableTokenEUR = 'StableTokenEUR', + StableTokenBRL = 'StableTokenBRL', TransferWhitelist = 'TransferWhitelist', Validators = 'Validators', } diff --git a/packages/sdk/contractkit/src/web3-contract-cache.ts b/packages/sdk/contractkit/src/web3-contract-cache.ts index a120d9d7aea..a1823ea287f 100644 --- a/packages/sdk/contractkit/src/web3-contract-cache.ts +++ b/packages/sdk/contractkit/src/web3-contract-cache.ts @@ -10,6 +10,7 @@ import { newElection } from './generated/Election' import { newEpochRewards } from './generated/EpochRewards' import { newEscrow } from './generated/Escrow' import { newExchange } from './generated/Exchange' +import { newExchangeBrl } from './generated/ExchangeBRL' import { newExchangeEur } from './generated/ExchangeEUR' import { newFeeCurrencyWhitelist } from './generated/FeeCurrencyWhitelist' import { newFreezer } from './generated/Freezer' @@ -45,6 +46,7 @@ export const ContractFactories = { [CeloContract.Escrow]: newEscrow, [CeloContract.Exchange]: newExchange, [CeloContract.ExchangeEUR]: newExchangeEur, + [CeloContract.ExchangeBRL]: newExchangeBrl, [CeloContract.FeeCurrencyWhitelist]: newFeeCurrencyWhitelist, [CeloContract.Freezer]: newFreezer, [CeloContract.GasPriceMinimum]: newGasPriceMinimum, @@ -60,6 +62,7 @@ export const ContractFactories = { [CeloContract.SortedOracles]: newSortedOracles, [CeloContract.StableToken]: newStableToken, [CeloContract.StableTokenEUR]: newStableToken, + [CeloContract.StableTokenBRL]: newStableToken, [CeloContract.TransferWhitelist]: newTransferWhitelist, [CeloContract.Validators]: newValidators, } From c608350d86dfb486d68968552453680a5d565df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 9 Nov 2021 18:19:15 +0100 Subject: [PATCH 22/33] WIP cli --- packages/sdk/contractkit/src/base.ts | 10 ++++++++-- packages/sdk/contractkit/src/celo-tokens.ts | 6 ++++++ packages/sdk/contractkit/src/contract-cache.ts | 4 ++++ packages/sdk/contractkit/src/web3-contract-cache.ts | 3 ++- .../sdk/contractkit/src/wrappers/StableToken.test.ts | 5 +++++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/sdk/contractkit/src/base.ts b/packages/sdk/contractkit/src/base.ts index c3f5d1e2030..ed679a4c05d 100644 --- a/packages/sdk/contractkit/src/base.ts +++ b/packages/sdk/contractkit/src/base.ts @@ -31,9 +31,15 @@ export enum CeloContract { Validators = 'Validators', } -export type StableTokenContract = CeloContract.StableToken | CeloContract.StableTokenEUR +export type StableTokenContract = + | CeloContract.StableToken + | CeloContract.StableTokenEUR + | CeloContract.StableTokenBRL -export type ExchangeContract = CeloContract.Exchange | CeloContract.ExchangeEUR +export type ExchangeContract = + | CeloContract.Exchange + | CeloContract.ExchangeEUR + | CeloContract.ExchangeBRL export type CeloTokenContract = StableTokenContract | CeloContract.GoldToken /** diff --git a/packages/sdk/contractkit/src/celo-tokens.ts b/packages/sdk/contractkit/src/celo-tokens.ts index 7da283714b1..33a0f1f87aa 100644 --- a/packages/sdk/contractkit/src/celo-tokens.ts +++ b/packages/sdk/contractkit/src/celo-tokens.ts @@ -7,6 +7,7 @@ import { StableTokenWrapper } from './wrappers/StableTokenWrapper' export enum StableToken { cUSD = 'cUSD', cEUR = 'cEUR', + cREAL = 'cREAL', } export enum Token { @@ -45,6 +46,11 @@ export const stableTokenInfos: { exchangeContract: CeloContract.ExchangeEUR, symbol: StableToken.cEUR, }, + [StableToken.cREAL]: { + contract: CeloContract.StableTokenBRL, + exchangeContract: CeloContract.ExchangeBRL, + symbol: StableToken.cREAL, + }, } /** Basic info for each supported celo token, including stable tokens */ diff --git a/packages/sdk/contractkit/src/contract-cache.ts b/packages/sdk/contractkit/src/contract-cache.ts index 7bb5e2d9b18..dad345e4a53 100644 --- a/packages/sdk/contractkit/src/contract-cache.ts +++ b/packages/sdk/contractkit/src/contract-cache.ts @@ -37,6 +37,7 @@ const WrapperFactories = { [CeloContract.Escrow]: EscrowWrapper, [CeloContract.Exchange]: ExchangeWrapper, [CeloContract.ExchangeEUR]: ExchangeWrapper, + [CeloContract.ExchangeBRL]: ExchangeWrapper, // [CeloContract.FeeCurrencyWhitelist]: FeeCurrencyWhitelistWrapper, [CeloContract.Freezer]: FreezerWrapper, [CeloContract.GasPriceMinimum]: GasPriceMinimumWrapper, @@ -52,6 +53,7 @@ const WrapperFactories = { [CeloContract.SortedOracles]: SortedOraclesWrapper, [CeloContract.StableToken]: StableTokenWrapper, [CeloContract.StableTokenEUR]: StableTokenWrapper, + [CeloContract.StableTokenBRL]: StableTokenWrapper, [CeloContract.Validators]: ValidatorsWrapper, } @@ -70,6 +72,7 @@ interface WrapperCacheMap { [CeloContract.Escrow]?: EscrowWrapper [CeloContract.Exchange]?: ExchangeWrapper [CeloContract.ExchangeEUR]?: ExchangeWrapper + [CeloContract.ExchangeBRL]?: ExchangeWrapper // [CeloContract.FeeCurrencyWhitelist]?: FeeCurrencyWhitelistWrapper, [CeloContract.Freezer]?: FreezerWrapper [CeloContract.GasPriceMinimum]?: GasPriceMinimumWrapper @@ -85,6 +88,7 @@ interface WrapperCacheMap { [CeloContract.SortedOracles]?: SortedOraclesWrapper [CeloContract.StableToken]?: StableTokenWrapper [CeloContract.StableTokenEUR]?: StableTokenWrapper + [CeloContract.StableTokenBRL]?: StableTokenWrapper [CeloContract.Validators]?: ValidatorsWrapper } diff --git a/packages/sdk/contractkit/src/web3-contract-cache.ts b/packages/sdk/contractkit/src/web3-contract-cache.ts index a1823ea287f..1260378fa2f 100644 --- a/packages/sdk/contractkit/src/web3-contract-cache.ts +++ b/packages/sdk/contractkit/src/web3-contract-cache.ts @@ -171,7 +171,8 @@ export class Web3ContractCache { try { address = await this.kit.registry.addressFor(contract) } catch (e) { - throw new Error(`${contract} not yet deployed for this chain`) + console.log(console.trace()) + throw new Error(`${contract} not yet deployed for this chain2`) } } debug('Initiating contract %s', contract) diff --git a/packages/sdk/contractkit/src/wrappers/StableToken.test.ts b/packages/sdk/contractkit/src/wrappers/StableToken.test.ts index c4802f147f9..14365db4b7b 100644 --- a/packages/sdk/contractkit/src/wrappers/StableToken.test.ts +++ b/packages/sdk/contractkit/src/wrappers/StableToken.test.ts @@ -25,6 +25,11 @@ testWithGanache('StableToken Wrapper', async (web3) => { name: 'Celo Euro', symbol: 'cEUR', }, + [StableToken.cREAL]: { + stableToken: StableToken.cREAL, + name: 'Celo Brazilian Rean', + symbol: 'cREAL', + }, } for (const stableTokenInfo of Object.values(stableTokenInfos)) { From 85ba946b62a71b7920fd895bc73eae66ef1041f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 9 Nov 2021 18:20:24 +0100 Subject: [PATCH 23/33] added release6.json --- packages/protocol/releaseData/initializationData/release6.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/releaseData/initializationData/release6.json b/packages/protocol/releaseData/initializationData/release6.json index 2fa33272659..84936c21694 100644 --- a/packages/protocol/releaseData/initializationData/release6.json +++ b/packages/protocol/releaseData/initializationData/release6.json @@ -1,4 +1,4 @@ { - "StableTokenBRL": ["Celo Brazilian Real", "cREAL", 18, "0x000000000000000000000000000000000000ce10", "1000000000000000000000000", "47304000", ["0xD533Ca259b330c7A88f74E000a3FaEa2d63B7972", "0x989e1a3B344A43911e02cCC609D469fbc15AB1F1"], ["2000000000000000000000000", "6000000000000000000000000"], "ExchangeBRL"], + "StableTokenBRL": ["Celo Brazilian Real", "cREAL", 18, "0x000000000000000000000000000000000000ce10", "1000000000000000000000000", "47304000", ["0xCF691062547bbe97B25B07f69C2Bffc93B4ddb96", "0x4e3D385eCdEE402DA395a3b18575B05Cc5e8Ff21"], ["2000000000000000000000000", "6000000000000000000000000"], "ExchangeBRL"], "ExchangeBRL": ["0x000000000000000000000000000000000000ce10", "0x0000000000000000000000000000000000000000", "2500000000000000000000", "1300000000000000000000", "300", "5"] } From 588f1b41d658223e608f72fbe8bcd501d6569455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Fri, 12 Nov 2021 16:21:00 +0100 Subject: [PATCH 24/33] add cREAL as default for env tests --- packages/env-tests/src/monorepoRun.ts | 14 +++++--------- packages/env-tests/src/tests/exchange.ts | 3 +++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/env-tests/src/monorepoRun.ts b/packages/env-tests/src/monorepoRun.ts index 3b1acdd313b..800845e9710 100644 --- a/packages/env-tests/src/monorepoRun.ts +++ b/packages/env-tests/src/monorepoRun.ts @@ -3,14 +3,10 @@ import Web3 from 'web3' import { loadFromEnvFile } from './env' import { rootLogger } from './logger' import { clearAllFundsToRoot, parseStableTokensList } from './scaffold' -import { runAttestationTest } from './tests/attestation' import { runExchangeTest } from './tests/exchange' -import { runGrandaMentoTest } from './tests/granda-mento' -import { runOracleTest } from './tests/oracle' -import { runReserveTest } from './tests/reserve' import { runTransfersTest } from './tests/transfer' -const DEFAULT_TOKENS_TO_TEST = [StableToken.cUSD] +const DEFAULT_TOKENS_TO_TEST = [StableToken.cREAL] jest.setTimeout(120000) @@ -39,10 +35,10 @@ function runTests() { // TODO: Assert maximum loss after test runTransfersTest(context, stableTokensToTest) runExchangeTest(context, stableTokensToTest) - runOracleTest(context) - runReserveTest(context) - runAttestationTest(context) - runGrandaMentoTest(context, stableTokensToTest) + // runOracleTest(context) + // runReserveTest(context) + // runAttestationTest(context) + // runGrandaMentoTest(context, stableTokensToTest) // TODO: Governance Proposals // TODO: Validator election + Slashing diff --git a/packages/env-tests/src/tests/exchange.ts b/packages/env-tests/src/tests/exchange.ts index 8eafdbd4181..57abc12331c 100644 --- a/packages/env-tests/src/tests/exchange.ts +++ b/packages/env-tests/src/tests/exchange.ts @@ -35,10 +35,12 @@ export function runExchangeTest(context: EnvTestContext, stableTokensToTest: Sta `quote selling ${stableToken}` ) + // console.log(exchange.address) const approveTx = await stableTokenInstance .approve(exchange.address, stableTokenAmountToSell.toString()) .send() await approveTx.waitReceipt() + // console.log("approve1") const sellTx = await exchange .sell( stableTokenAmountToSell, @@ -68,6 +70,7 @@ export function runExchangeTest(context: EnvTestContext, stableTokensToTest: Sta .approve(exchange.address, goldAmountToSell.toString()) .send() await approveGoldTx.waitReceipt() + // console.log("approve2") await sleep(5000) const sellGoldTx = await exchange .sellGold( From d2f20a7740e15b3c722f6dd1774d307933520910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 16 Nov 2021 18:55:21 -0600 Subject: [PATCH 25/33] Added cREAL release data --- .../protocol/releaseData/initializationData/release6.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/protocol/releaseData/initializationData/release6.json b/packages/protocol/releaseData/initializationData/release6.json index 84936c21694..b3e85ae1f65 100644 --- a/packages/protocol/releaseData/initializationData/release6.json +++ b/packages/protocol/releaseData/initializationData/release6.json @@ -1,4 +1,4 @@ { - "StableTokenBRL": ["Celo Brazilian Real", "cREAL", 18, "0x000000000000000000000000000000000000ce10", "1000000000000000000000000", "47304000", ["0xCF691062547bbe97B25B07f69C2Bffc93B4ddb96", "0x4e3D385eCdEE402DA395a3b18575B05Cc5e8Ff21"], ["2000000000000000000000000", "6000000000000000000000000"], "ExchangeBRL"], - "ExchangeBRL": ["0x000000000000000000000000000000000000ce10", "0x0000000000000000000000000000000000000000", "2500000000000000000000", "1300000000000000000000", "300", "5"] -} + "StableTokenBRL": ["Celo Brazilian Real", "cREAL", 18, "0x000000000000000000000000000000000000ce10", "1000000000000000000000000", "47304000", [], [], "ExchangeBRL"], + "ExchangeBRL": ["0x000000000000000000000000000000000000ce10", "0x0000000000000000000000000000000000000000", "5000000000000000000000", "250000000000000000000", "300", "5"] +} \ No newline at end of file From 7f05e856ddf9bc799dbfb1e86561b3e37ff0bb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 7 Dec 2021 16:56:43 +0100 Subject: [PATCH 26/33] Update packages/env-tests/src/monorepoRun.ts --- packages/env-tests/src/monorepoRun.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/env-tests/src/monorepoRun.ts b/packages/env-tests/src/monorepoRun.ts index 800845e9710..b5129f91039 100644 --- a/packages/env-tests/src/monorepoRun.ts +++ b/packages/env-tests/src/monorepoRun.ts @@ -35,10 +35,10 @@ function runTests() { // TODO: Assert maximum loss after test runTransfersTest(context, stableTokensToTest) runExchangeTest(context, stableTokensToTest) - // runOracleTest(context) - // runReserveTest(context) - // runAttestationTest(context) - // runGrandaMentoTest(context, stableTokensToTest) + runOracleTest(context) + runReserveTest(context) + runAttestationTest(context) + runGrandaMentoTest(context, stableTokensToTest) // TODO: Governance Proposals // TODO: Validator election + Slashing From e7c7009631c6991d902ce858446e27560e8d30db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 7 Dec 2021 16:57:22 +0100 Subject: [PATCH 27/33] Update packages/env-tests/src/monorepoRun.ts --- packages/env-tests/src/monorepoRun.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/env-tests/src/monorepoRun.ts b/packages/env-tests/src/monorepoRun.ts index b5129f91039..adea152df0b 100644 --- a/packages/env-tests/src/monorepoRun.ts +++ b/packages/env-tests/src/monorepoRun.ts @@ -6,7 +6,7 @@ import { clearAllFundsToRoot, parseStableTokensList } from './scaffold' import { runExchangeTest } from './tests/exchange' import { runTransfersTest } from './tests/transfer' -const DEFAULT_TOKENS_TO_TEST = [StableToken.cREAL] +const DEFAULT_TOKENS_TO_TEST = [StableToken.cUSD] jest.setTimeout(120000) From 11cb7be0312d5972b79755b57f9cc7c6d137109e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 7 Dec 2021 16:57:44 +0100 Subject: [PATCH 28/33] Update packages/env-tests/src/tests/exchange.ts --- packages/env-tests/src/tests/exchange.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/env-tests/src/tests/exchange.ts b/packages/env-tests/src/tests/exchange.ts index 57abc12331c..8750faa046c 100644 --- a/packages/env-tests/src/tests/exchange.ts +++ b/packages/env-tests/src/tests/exchange.ts @@ -35,7 +35,6 @@ export function runExchangeTest(context: EnvTestContext, stableTokensToTest: Sta `quote selling ${stableToken}` ) - // console.log(exchange.address) const approveTx = await stableTokenInstance .approve(exchange.address, stableTokenAmountToSell.toString()) .send() From 3d458dfea4af93a2bd583642fbec888823ed31da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 7 Dec 2021 16:58:04 +0100 Subject: [PATCH 29/33] Update packages/env-tests/src/tests/exchange.ts --- packages/env-tests/src/tests/exchange.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/env-tests/src/tests/exchange.ts b/packages/env-tests/src/tests/exchange.ts index 8750faa046c..e57b22d6726 100644 --- a/packages/env-tests/src/tests/exchange.ts +++ b/packages/env-tests/src/tests/exchange.ts @@ -39,7 +39,6 @@ export function runExchangeTest(context: EnvTestContext, stableTokensToTest: Sta .approve(exchange.address, stableTokenAmountToSell.toString()) .send() await approveTx.waitReceipt() - // console.log("approve1") const sellTx = await exchange .sell( stableTokenAmountToSell, From 01bb5a822f6010c42f48b2411c1f99a8c389d3d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Tue, 7 Dec 2021 16:58:21 +0100 Subject: [PATCH 30/33] Update packages/env-tests/src/tests/exchange.ts --- packages/env-tests/src/tests/exchange.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/env-tests/src/tests/exchange.ts b/packages/env-tests/src/tests/exchange.ts index e57b22d6726..8eafdbd4181 100644 --- a/packages/env-tests/src/tests/exchange.ts +++ b/packages/env-tests/src/tests/exchange.ts @@ -68,7 +68,6 @@ export function runExchangeTest(context: EnvTestContext, stableTokensToTest: Sta .approve(exchange.address, goldAmountToSell.toString()) .send() await approveGoldTx.waitReceipt() - // console.log("approve2") await sleep(5000) const sellGoldTx = await exchange .sellGold( From 2509144f62d09d9e7b0a136ad8c6abb526bf8ee8 Mon Sep 17 00:00:00 2001 From: Martin Volpe Date: Tue, 7 Dec 2021 17:02:08 +0100 Subject: [PATCH 31/33] Rooled back env test run --- packages/env-tests/src/monorepoRun.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/env-tests/src/monorepoRun.ts b/packages/env-tests/src/monorepoRun.ts index adea152df0b..3b1acdd313b 100644 --- a/packages/env-tests/src/monorepoRun.ts +++ b/packages/env-tests/src/monorepoRun.ts @@ -3,7 +3,11 @@ import Web3 from 'web3' import { loadFromEnvFile } from './env' import { rootLogger } from './logger' import { clearAllFundsToRoot, parseStableTokensList } from './scaffold' +import { runAttestationTest } from './tests/attestation' import { runExchangeTest } from './tests/exchange' +import { runGrandaMentoTest } from './tests/granda-mento' +import { runOracleTest } from './tests/oracle' +import { runReserveTest } from './tests/reserve' import { runTransfersTest } from './tests/transfer' const DEFAULT_TOKENS_TO_TEST = [StableToken.cUSD] From 2cfc43b508bfaf85cc339fd3b074ed9845b20d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Volpe?= Date: Wed, 8 Dec 2021 13:59:49 +0100 Subject: [PATCH 32/33] Update packages/sdk/contractkit/src/wrappers/StableToken.test.ts Co-authored-by: Nicolas Brugneaux --- packages/sdk/contractkit/src/wrappers/StableToken.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/contractkit/src/wrappers/StableToken.test.ts b/packages/sdk/contractkit/src/wrappers/StableToken.test.ts index 14365db4b7b..aac8bcbc688 100644 --- a/packages/sdk/contractkit/src/wrappers/StableToken.test.ts +++ b/packages/sdk/contractkit/src/wrappers/StableToken.test.ts @@ -27,7 +27,7 @@ testWithGanache('StableToken Wrapper', async (web3) => { }, [StableToken.cREAL]: { stableToken: StableToken.cREAL, - name: 'Celo Brazilian Rean', + name: 'Celo Brazilian Real', symbol: 'cREAL', }, } From 030dc3d377ffde4887d3750c4afad609fc2f86cf Mon Sep 17 00:00:00 2001 From: Martin Volpe Date: Wed, 8 Dec 2021 14:35:19 +0100 Subject: [PATCH 33/33] Added commands and docs --- packages/cli/src/commands/exchange/reals.ts | 28 ++++++++++++++ packages/cli/src/commands/transfer/reals.ts | 19 ++++++++++ .../docs/command-line-interface/config.md | 21 +++++------ .../docs/command-line-interface/exchange.md | 37 +++++++++++++++++-- .../command-line-interface/grandamento.md | 13 ++++--- .../docs/command-line-interface/transfer.md | 28 +++++++++++++- 6 files changed, 124 insertions(+), 22 deletions(-) create mode 100644 packages/cli/src/commands/exchange/reals.ts create mode 100644 packages/cli/src/commands/transfer/reals.ts diff --git a/packages/cli/src/commands/exchange/reals.ts b/packages/cli/src/commands/exchange/reals.ts new file mode 100644 index 00000000000..6507803ae4b --- /dev/null +++ b/packages/cli/src/commands/exchange/reals.ts @@ -0,0 +1,28 @@ +import { StableToken } from '@celo/contractkit' +import ExchangeStableBase from '../../exchange-stable-base' +import { Flags } from '../../utils/command' +export default class ExchangeEuros extends ExchangeStableBase { + static description = 'Exchange Celo Brazilian Real (cBRL) for CELO via the stability mechanism' + + static flags = { + ...ExchangeStableBase.flags, + from: Flags.address({ + required: true, + description: 'The address with Celo Brazilian Real to exchange', + }), + value: Flags.wei({ + required: true, + description: 'The value of Celo Brazilian Real to exchange for CELO', + }), + } + + static examples = [ + 'reals --value 10000000000000 --from 0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d', + 'reals --value 10000000000000 --forAtLeast 50000000000000 --from 0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d', + ] + + async init() { + this._stableCurrency = StableToken.cREAL + await super.init() + } +} diff --git a/packages/cli/src/commands/transfer/reals.ts b/packages/cli/src/commands/transfer/reals.ts new file mode 100644 index 00000000000..a84e304570c --- /dev/null +++ b/packages/cli/src/commands/transfer/reals.ts @@ -0,0 +1,19 @@ +import { StableToken } from '@celo/contractkit' +import { TransferStableBase } from '../../transfer-stable-base' + +export default class TransferEuros extends TransferStableBase { + static description = 'Transfer Celo Brazilian Real (cREAL) to a specified address.' + + static flags = { + ...TransferStableBase.flags, + } + + static examples = [ + 'reals --from 0xa0Af2E71cECc248f4a7fD606F203467B500Dd53B --to 0x5409ed021d9299bf6814279a6a1411a7e866a631 --value 1000000000000000000', + ] + + async init() { + this._stableCurrency = StableToken.cREAL + await super.init() + } +} diff --git a/packages/docs/command-line-interface/config.md b/packages/docs/command-line-interface/config.md index 75a4e13752c..e9d315483c4 100644 --- a/packages/docs/command-line-interface/config.md +++ b/packages/docs/command-line-interface/config.md @@ -30,18 +30,15 @@ USAGE $ celocli config:set OPTIONS - -n, --node=node URL of the node to run - commands against (defaults to - 'http://localhost:8545') - - --gasCurrency=(auto|Auto|CELO|celo|cUSD|cusd|cEUR|ceur) Use a specific gas currency - for transaction fees - (defaults to 'auto' which - uses whatever feeCurrency is - available) - - --globalHelp View all available global - flags + -n, --node=node + URL of the node to run commands against (defaults to 'http://localhost:8545') + + --gasCurrency=(auto|Auto|CELO|celo|cUSD|cusd|cEUR|ceur|cREAL|creal) + Use a specific gas currency for transaction fees (defaults to 'auto' which uses + whatever feeCurrency is available) + + --globalHelp + View all available global flags EXAMPLES set --node ws://localhost:2500 diff --git a/packages/docs/command-line-interface/exchange.md b/packages/docs/command-line-interface/exchange.md index b2e38f6688d..bec86595530 100644 --- a/packages/docs/command-line-interface/exchange.md +++ b/packages/docs/command-line-interface/exchange.md @@ -23,7 +23,7 @@ OPTIONS --globalHelp View all available global flags - --stableToken=(cUSD|cusd|cEUR|ceur) [default: cUSD] Name of the stable + --stableToken=(cUSD|cusd|cEUR|ceur|cREAL|creal) [default: cUSD] Name of the stable to receive --value=10000000000000000000000 (required) The value of CELO to @@ -120,7 +120,7 @@ OPTIONS --globalHelp View all available global flags - --stableToken=(cUSD|cusd|cEUR|ceur) [default: cUSD] Name of the stable + --stableToken=(cUSD|cusd|cEUR|ceur|cREAL|creal) [default: cUSD] Name of the stable to receive --value=10000000000000000000000 (required) The value of CELO to @@ -135,6 +135,37 @@ EXAMPLES _See code: [src/commands/exchange/gold.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/exchange/gold.ts)_ +## `celocli exchange:reals` + +Exchange Celo Brazilian Real (cBRL) for CELO via the stability mechanism + +``` +Exchange Celo Brazilian Real (cBRL) for CELO via the stability mechanism + +USAGE + $ celocli exchange:reals + +OPTIONS + --forAtLeast=10000000000000000000000 [default: 0] Optional, the minimum + value of CELO to receive in return + + --from=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d (required) The address with Celo + Brazilian Real to exchange + + --globalHelp View all available global flags + + --value=10000000000000000000000 (required) The value of Celo + Brazilian Real to exchange for CELO + +EXAMPLES + reals --value 10000000000000 --from 0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d + + reals --value 10000000000000 --forAtLeast 50000000000000 --from + 0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d +``` + +_See code: [src/commands/exchange/reals.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/exchange/reals.ts)_ + ## `celocli exchange:show` Show the current exchange rates offered by the Exchange @@ -176,7 +207,7 @@ OPTIONS --globalHelp View all available global flags - --stableToken=(cUSD|cusd|cEUR|ceur) Name of the stable token to be + --stableToken=(cUSD|cusd|cEUR|ceur|cREAL|creal) Name of the stable token to be transfered --value=10000000000000000000000 (required) The value of Stable diff --git a/packages/docs/command-line-interface/grandamento.md b/packages/docs/command-line-interface/grandamento.md index 338ef6baf09..fe08df44f74 100644 --- a/packages/docs/command-line-interface/grandamento.md +++ b/packages/docs/command-line-interface/grandamento.md @@ -56,13 +56,14 @@ USAGE $ celocli grandamento:get-buy-amount OPTIONS - --globalHelp View all available global flags - --sellCelo=(true|false) (required) Sell or buy CELO + --globalHelp View all available global flags + --sellCelo=(true|false) (required) Sell or buy CELO - --stableToken=(cUSD|cusd|cEUR|ceur) (required) [default: cUSD] Name of the stable to - receive or send + --stableToken=(cUSD|cusd|cEUR|ceur|cREAL|creal) (required) [default: cUSD] Name of + the stable to receive or send - --value=10000000000000000000000 (required) The value of the tokens to exchange + --value=10000000000000000000000 (required) The value of the tokens to + exchange ``` _See code: [src/commands/grandamento/get-buy-amount.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/grandamento/get-buy-amount.ts)_ @@ -101,7 +102,7 @@ OPTIONS --sellCelo=(true|false) (required) Sell or buy CELO - --stableToken=(cUSD|cusd|cEUR|ceur) (required) [default: cUSD] Name of + --stableToken=(cUSD|cusd|cEUR|ceur|cREAL|creal) (required) [default: cUSD] Name of the stable to receive or send --value=10000000000000000000000 (required) The value of the tokens diff --git a/packages/docs/command-line-interface/transfer.md b/packages/docs/command-line-interface/transfer.md index 7b4d23c949f..84071fba25b 100644 --- a/packages/docs/command-line-interface/transfer.md +++ b/packages/docs/command-line-interface/transfer.md @@ -141,6 +141,32 @@ EXAMPLE _See code: [src/commands/transfer/gold.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/transfer/gold.ts)_ +## `celocli transfer:reals` + +Transfer Celo Brazilian Real (cREAL) to a specified address. + +``` +Transfer Celo Brazilian Real (cREAL) to a specified address. + +USAGE + $ celocli transfer:reals + +OPTIONS + --comment=comment Transfer comment + --from=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d (required) Address of the sender + --globalHelp View all available global flags + --to=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d (required) Address of the receiver + + --value=value (required) Amount to transfer (in + wei) + +EXAMPLE + reals --from 0xa0Af2E71cECc248f4a7fD606F203467B500Dd53B --to + 0x5409ed021d9299bf6814279a6a1411a7e866a631 --value 1000000000000000000 +``` + +_See code: [src/commands/transfer/reals.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/transfer/reals.ts)_ + ## `celocli transfer:stable` Transfer a stable token to a specified address. @@ -155,7 +181,7 @@ OPTIONS --comment=comment Transfer comment --from=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d (required) Address of the sender --globalHelp View all available global flags - --stableToken=(cUSD|cusd|cEUR|ceur) Name of the stable to be transfered + --stableToken=(cUSD|cusd|cEUR|ceur|cREAL|creal) Name of the stable to be transfered --to=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d (required) Address of the receiver --value=value (required) Amount to transfer (in