Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
6c3d4e7
Scaffolding
May 21, 2021
3fdc4b3
Add extra test case
May 21, 2021
8f59b50
Merge branch 'master' of github.com:celo-org/celo-monorepo into trevo…
May 22, 2021
31ba691
Scaffolding
May 21, 2021
cd84b82
Add extra test case
May 21, 2021
a899eed
comment change
May 25, 2021
6e18e31
remove unnecessary migrations config
May 25, 2021
0a8e768
add releaseData
May 25, 2021
6355001
A lot
May 25, 2021
efd42d4
Add spread to initializer
May 26, 2021
3ad76fa
better test case wording
May 26, 2021
6342aad
Working tests
May 26, 2021
ed68e14
tests in a decent spot
May 27, 2021
760ca86
Merge branch 'trevor/granda-mento-scaffolding' of github.com:celo-org…
May 27, 2021
acaadda
clean up
May 27, 2021
de9b272
update initialization params in release4.json
May 27, 2021
444b596
Fix lint
May 27, 2021
0c57c56
Make contract changes, now doing tests
May 27, 2021
eaa1785
Create MockToken to fix attestations tests
May 27, 2021
e3a4805
Update GrandaMento.sol
May 27, 2021
00e0da3
Merge branch 'trevor/granda-mento-scaffolding' of github.com:celo-org…
May 27, 2021
455865b
Merge branch 'trevor/granda-mento-proposal' of github.com:celo-org/ce…
May 28, 2021
c92c728
Rename Empty state to None
May 28, 2021
7160508
Merge branch 'trevor/granda-mento-proposal' of github.com:celo-org/ce…
May 28, 2021
6a8335d
Tests working
Jun 1, 2021
00bbc23
Add setApprover test
Jun 1, 2021
b1f64f9
Tests and cancel working
Jun 2, 2021
bff0cbc
Rename proposeExchange -> createExchangeProposal
Jun 2, 2021
431ec40
Rename proposeExchange -> createExchangeProposal
Jun 3, 2021
794e4ad
Allow GrandaMento to mint and burn
Jun 3, 2021
7074cfb
wow everything works
Jun 7, 2021
ffc2f33
PR comments
Jun 8, 2021
d10fb1d
fix lint
Jun 8, 2021
40f8000
Merge branch 'trevor/granda-mento-proposal' into trevor/granda-mento-…
Jun 8, 2021
2f06764
Granda Mento - exchange proposal implementation (#8019)
Jun 9, 2021
738e928
Use registry IDs for stable tokens
Jun 9, 2021
2111a24
Merge branch 'granda-mento' of github.com:celo-org/celo-monorepo into…
Jun 9, 2021
e3b8f2f
Merge branch 'granda-mento' of github.com:celo-org/celo-monorepo into…
Jun 9, 2021
7e6df10
Merge branch 'granda-mento' of github.com:celo-org/celo-monorepo into…
Jun 9, 2021
d772ee6
Bump minor version of StableToken and StableTokenEUR
Jun 9, 2021
fe72229
Use the string registry ID rather than the keccak for exchange limits
Jun 10, 2021
b045bd4
Create assertRevertWithReason
Jun 10, 2021
79e6c23
Remove console.log
Jun 10, 2021
9a094e1
Fix unit and protocol version tests
Jun 10, 2021
05e23d0
Add constructor to StableTokenEUR
Jun 10, 2021
2d2a0fb
WIP granda mento SDK
martinvol Jun 11, 2021
520a6ea
Granda Mento: support for approving, cancelling, and executing exchan…
Jun 18, 2021
2ed62bf
Remove some console.logs
Jun 18, 2021
5a56a9d
Merge branch 'master' of github.com:celo-org/celo-monorepo into grand…
Jun 18, 2021
593cb1c
Merge remote-tracking branch 'origin/granda-mento' into martinvol/gra…
martinvol Jun 21, 2021
00c892f
Fix integration tests (#8138)
martinvol Jun 21, 2021
0a4b7f8
WIP
martinvol Jun 21, 2021
bf6a93f
Merge branch 'master' into martinvol/grandaMentoSDK
martinvol Jun 24, 2021
777b730
WIP transfer ownership
martinvol Jun 28, 2021
9bd1f9d
Merge branch 'master' into granda-mento
martinvol Jun 28, 2021
2b113d0
Merge remote-tracking branch 'origin/granda-mento' into martinvol/gra…
martinvol Jun 28, 2021
5a7346d
Added lint
martinvol Jun 28, 2021
f725677
WIP
martinvol Jun 29, 2021
b2d60c1
More wrappers and tests
martinvol Jul 1, 2021
30f4dec
Feature complete
martinvol Jul 1, 2021
525f7e1
Tests and cleaun-up
martinvol Jul 5, 2021
2151633
Added more config
martinvol Jul 5, 2021
4b4317d
Fixed beforeEach
martinvol Jul 5, 2021
522be01
refactor
martinvol Jul 5, 2021
40120f8
typios
martinvol Jul 5, 2021
cbaf46c
Removed TODOs
martinvol Jul 5, 2021
802641b
lint
martinvol Jul 6, 2021
f20a08c
Checked test
martinvol Jul 6, 2021
399191a
Fixed types
martinvol Jul 9, 2021
0c8ff6f
Added tests
martinvol Jul 9, 2021
c7e1d25
Made a map
martinvol Jul 9, 2021
6ff1c73
Merge branch 'master' into martinvol/grandaMentoSDK
martinvol Jul 9, 2021
030b32d
Restored changes
martinvol Jul 9, 2021
6056d29
Added back script
martinvol Jul 9, 2021
b6b8ee2
Fixed transferownership
martinvol Jul 12, 2021
2696131
Merge branch 'master' into martinvol/grandaMentoSDK
martinvol Jul 12, 2021
e0f51a3
Fix tests
martinvol Jul 12, 2021
2b464fe
Merge branch 'martinvol/grandaMentoSDK' of github.com:celo-org/celo-m…
martinvol Jul 12, 2021
3538159
Small refactor
martinvol Jul 12, 2021
35e0b85
Removed promise
martinvol Jul 12, 2021
7d6d8bb
Merge branch 'master' into martinvol/grandaMentoSDK
martinvol Jul 13, 2021
4012161
Merge branch 'master' into martinvol/grandaMentoSDK
martinvol Jul 14, 2021
92f94b5
Merge branch 'master' into martinvol/grandaMentoSDK
martinvol Jul 15, 2021
79ae2cb
Merge branch 'master' into martinvol/grandaMentoSDK
martinvol Jul 15, 2021
297da58
Merge branch 'master' into martinvol/grandaMentoSDK
martinvol Jul 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/dev-utils/src/migration-override.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,26 @@
"referendumStageDuration": 100,
"executionStageDuration": 100,
"minDeposit": 1,
"concurrentProposals": 5
"concurrentProposals": 5,
"skipTransferOwnership": false
},
"governanceApproverMultiSig": {
"signatories": [
"0x5409ed021d9299bf6814279a6a1411a7e866a631"
],
"numRequiredConfirmations": 1
},
"grandaMento": {
"approver": "0x5409ED021D9299bf6814279A6A1411A7e866A631",
"spread": 0.01,
"vetoPeriodSeconds": 10800
},
"oracles": {
"reportExpiry": 300
},
"reserve": {
"initialBalance": 100000000,
"otherAddresses": ["0x91c987bf62D25945dB517BDAa840A6c661374402"]

},
"reserveSpenderMultiSig": {
"signatories": ["0x5409ed021d9299bf6814279a6a1411a7e866a631", "0x4404ac8bd8F9618D27Ad2f1485AA1B2cFD82482D"],
Expand Down
4 changes: 4 additions & 0 deletions packages/protocol/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const ProxyContracts = [
'GoldTokenProxy',
'GovernanceApproverMultiSigProxy',
'GovernanceProxy',
'GrandaMentoProxy',
'LockedGoldProxy',
'MetaTransactionWalletProxy',
'MetaTransactionWalletDeployerProxy',
Expand Down Expand Up @@ -74,6 +75,9 @@ export const CoreContracts = [
'StableToken',
'StableTokenEUR',
'SortedOracles',

// liquidity
'GrandaMento',
]

const OtherContracts = [
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/contractkit/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum CeloContract {
GasPriceMinimum = 'GasPriceMinimum',
GoldToken = 'GoldToken',
Governance = 'Governance',
GrandaMento = 'GrandaMento',
LockedGold = 'LockedGold',
MetaTransactionWallet = 'MetaTransactionWallet',
MetaTransactionWalletDeployer = 'MetaTransactionWalletDeployer',
Expand Down
6 changes: 6 additions & 0 deletions packages/sdk/contractkit/src/contract-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { FreezerWrapper } from './wrappers/Freezer'
import { GasPriceMinimumWrapper } from './wrappers/GasPriceMinimum'
import { GoldTokenWrapper } from './wrappers/GoldTokenWrapper'
import { GovernanceWrapper } from './wrappers/Governance'
import { GrandaMentoWrapper } from './wrappers/GrandaMento'
import { LockedGoldWrapper } from './wrappers/LockedGold'
import { MetaTransactionWalletWrapper } from './wrappers/MetaTransactionWallet'
import { MetaTransactionWalletDeployerWrapper } from './wrappers/MetaTransactionWalletDeployer'
Expand All @@ -42,6 +43,7 @@ const WrapperFactories = {
[CeloContract.GasPriceMinimum]: GasPriceMinimumWrapper,
[CeloContract.GoldToken]: GoldTokenWrapper,
[CeloContract.Governance]: GovernanceWrapper,
[CeloContract.GrandaMento]: GrandaMentoWrapper,
[CeloContract.LockedGold]: LockedGoldWrapper,
// [CeloContract.Random]: RandomWrapper,
// [CeloContract.Registry]: RegistryWrapper,
Expand Down Expand Up @@ -75,6 +77,7 @@ interface WrapperCacheMap {
[CeloContract.GasPriceMinimum]?: GasPriceMinimumWrapper
[CeloContract.GoldToken]?: GoldTokenWrapper
[CeloContract.Governance]?: GovernanceWrapper
[CeloContract.GrandaMento]?: GrandaMentoWrapper
[CeloContract.LockedGold]?: LockedGoldWrapper
[CeloContract.MetaTransactionWallet]?: MetaTransactionWalletWrapper
[CeloContract.MetaTransactionWalletDeployer]?: MetaTransactionWalletDeployerWrapper
Expand Down Expand Up @@ -143,6 +146,9 @@ export class WrapperCache {
getGovernance() {
return this.getContract(CeloContract.Governance)
}
getGrandaMento() {
return this.getContract(CeloContract.GrandaMento)
}
getLockedGold() {
return this.getContract(CeloContract.LockedGold)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/contractkit/src/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class ContractKit {
this.contracts.getValidators(),
this.contracts.getDowntimeSlasher(),
this.contracts.getBlockchainParameters(),
this.contracts.getGrandaMento(),
]
const contracts = await Promise.all(promises)
const res = await Promise.all([
Expand All @@ -145,6 +146,7 @@ export class ContractKit {
contracts[7].getConfig(),
contracts[8].getConfig(),
contracts[9].getConfig(),
contracts[10].getConfig(),
])
return {
exchanges: res[0],
Expand Down Expand Up @@ -175,6 +177,7 @@ export class ContractKit {
this.contracts.getValidators(),
this.contracts.getDowntimeSlasher(),
this.contracts.getBlockchainParameters(),
this.contracts.getGrandaMento(),
]
const contracts = await Promise.all(promises)
const res = await Promise.all([
Expand All @@ -190,6 +193,7 @@ export class ContractKit {
contracts[7].getHumanReadableConfig(),
contracts[8].getHumanReadableConfig(),
contracts[9].getConfig(),
contracts[10].getConfig(),
])
return {
exchanges: res[0],
Expand Down
62 changes: 62 additions & 0 deletions packages/sdk/contractkit/src/test-utils/transferownership.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { NetworkConfig, timeTravel } from '@celo/dev-utils/lib/ganache-test'
import Web3 from 'web3'
import { newKitFromWeb3 } from '../kit'
import { AccountsWrapper } from '../wrappers/Accounts'
import { Proposal, ProposalTransaction } from '../wrappers/Governance'

// Implements a transfer ownership function using only contractkit primitives

const expConfigGovernance = NetworkConfig.governance

export async function assumeOwnership(web3: Web3, to: string, proposalId: number = 1) {
const kit = newKitFromWeb3(web3)
const ONE_CGLD = web3.utils.toWei('1', 'ether')
const accounts = await web3.eth.getAccounts()
let accountWrapper: AccountsWrapper
accountWrapper = await kit.contracts.getAccounts()
const lockedGold = await kit.contracts.getLockedGold()

try {
await accountWrapper.createAccount().sendAndWaitForReceipt({ from: accounts[0] })
await lockedGold.lock().sendAndWaitForReceipt({ from: accounts[0], value: ONE_CGLD })
} catch (error) {
console.log('Account already created')
}

const grandaMento = await kit._web3Contracts.getGrandaMento()
const governance = await kit.contracts.getGovernance()
const multiSig = await kit.contracts.getMultiSig(await governance.getApprover())

const tenMillionCELO = web3.utils.toWei('10000000')

await lockedGold.lock().sendAndWaitForReceipt({ value: tenMillionCELO })

const ownershiptx: ProposalTransaction = {
value: '0',
to: (grandaMento as any)._address,
input: grandaMento.methods.transferOwnership(to).encodeABI(),
}
const proposal: Proposal = [ownershiptx]

await governance.propose(proposal, 'URL').sendAndWaitForReceipt({
from: accounts[0],
value: (await governance.getConfig()).minDeposit.toNumber(),
})

const tx = await governance.upvote(proposalId, accounts[1])
await tx.sendAndWaitForReceipt()
await timeTravel(expConfigGovernance.dequeueFrequency, web3)
await governance.dequeueProposalsIfReady().sendAndWaitForReceipt()

const tx2 = await governance.approve(proposalId)
const multisigTx = await multiSig.submitOrConfirmTransaction(governance.address, tx2.txo)
await multisigTx.sendAndWaitForReceipt({ from: accounts[0] })
await timeTravel(expConfigGovernance.approvalStageDuration, web3)

const tx3 = await governance.vote(proposalId, 'Yes')
await tx3.sendAndWaitForReceipt({ from: accounts[0] })
await timeTravel(expConfigGovernance.referendumStageDuration, web3)

const tx4 = await governance.execute(proposalId)
await tx4.sendAndWaitForReceipt()
}
5 changes: 5 additions & 0 deletions packages/sdk/contractkit/src/web3-contract-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { newFreezer } from './generated/Freezer'
import { newGasPriceMinimum } from './generated/GasPriceMinimum'
import { newGoldToken } from './generated/GoldToken'
import { newGovernance } from './generated/Governance'
import { newGrandaMento } from './generated/GrandaMento'
import { newIerc20 } from './generated/IERC20'
import { newLockedGold } from './generated/LockedGold'
import { newMetaTransactionWallet } from './generated/MetaTransactionWallet'
Expand Down Expand Up @@ -50,6 +51,7 @@ export const ContractFactories = {
[CeloContract.GasPriceMinimum]: newGasPriceMinimum,
[CeloContract.GoldToken]: newGoldToken,
[CeloContract.Governance]: newGovernance,
[CeloContract.GrandaMento]: newGrandaMento,
[CeloContract.LockedGold]: newLockedGold,
[CeloContract.MetaTransactionWallet]: newMetaTransactionWallet,
[CeloContract.MetaTransactionWalletDeployer]: newMetaTransactionWalletDeployer,
Expand Down Expand Up @@ -124,6 +126,9 @@ export class Web3ContractCache {
getGovernance() {
return this.getContract(CeloContract.Governance)
}
getGrandaMento() {
return this.getContract(CeloContract.GrandaMento)
}
getLockedGold() {
return this.getContract(CeloContract.LockedGold)
}
Expand Down
160 changes: 160 additions & 0 deletions packages/sdk/contractkit/src/wrappers/GrandaMento.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { Address } from '@celo/base/lib/address'
import { NetworkConfig, testWithGanache, timeTravel } from '@celo/dev-utils/lib/ganache-test'
import BigNumber from 'bignumber.js'
import Web3 from 'web3'
import { StableToken } from '../celo-tokens'
import { newKitFromWeb3 } from '../kit'
import { assumeOwnership } from '../test-utils/transferownership'
import { GoldTokenWrapper } from './GoldTokenWrapper'
import { ExchangeProposalState, GrandaMentoWrapper } from './GrandaMento'
import { StableTokenWrapper } from './StableTokenWrapper'

const expConfig = NetworkConfig.grandaMento

testWithGanache('GrandaMento Wrapper', (web3: Web3) => {
const kit = newKitFromWeb3(web3)
let accounts: Address[] = []
let grandaMento: GrandaMentoWrapper
let celoToken: GoldTokenWrapper
let stableToken: StableTokenWrapper
const newLimitMin = new BigNumber('1000')
const newLimitMax = new BigNumber('1000000000000')
let sellAmount: BigNumber

beforeAll(async () => {
accounts = await web3.eth.getAccounts()
kit.defaultAccount = accounts[0]
grandaMento = await kit.contracts.getGrandaMento()

stableToken = await kit.contracts.getStableToken(StableToken.cUSD)
celoToken = await kit.contracts.getGoldToken()
})

const increaseLimits = async () => {
await (
await grandaMento.setStableTokenExchangeLimits(
'StableToken',
newLimitMin.toString(),
newLimitMax.toString()
)
).sendAndWaitForReceipt()
}

describe('No limits sets', () => {
it('gets the proposals', async () => {
const activeProposals = await grandaMento.getActiveProposalIds()
expect(activeProposals).toEqual([])
})

it('fetches empty limits', async () => {
const limits = await grandaMento.stableTokenExchangeLimits(StableToken.cUSD)
expect(limits.minExchangeAmount).toEqBigNumber(new BigNumber(0))
expect(limits.maxExchangeAmount).toEqBigNumber(new BigNumber(0))
})
})

it("fetchs a proposal it doesn't exist", async () => {
await expect(grandaMento.getExchangeProposal(0)).rejects.toThrow("Proposal doesn't exist")
})

describe('When Granda Mento is enabled', () => {
beforeEach(async () => {
await assumeOwnership(web3, accounts[0])
await increaseLimits()
})

it('updated the config', async () => {
const config = await grandaMento.getConfig()
expect(
config.exchangeLimits.get(kit.celoTokens.getContract(StableToken.cUSD))?.minExchangeAmount
).toEqBigNumber(new BigNumber(newLimitMin))
expect(
config.exchangeLimits.get(kit.celoTokens.getContract(StableToken.cUSD))?.maxExchangeAmount
).toEqBigNumber(new BigNumber(newLimitMax))
expect(
config.exchangeLimits.get(kit.celoTokens.getContract(StableToken.cEUR))?.minExchangeAmount
).toEqBigNumber(new BigNumber(0))
expect(
config.exchangeLimits.get(kit.celoTokens.getContract(StableToken.cEUR))?.maxExchangeAmount
).toEqBigNumber(new BigNumber(0))
})

it('has new limits', async () => {
const limits = await grandaMento.stableTokenExchangeLimits(StableToken.cUSD)
expect(limits.minExchangeAmount).toEqBigNumber(newLimitMin)
expect(limits.maxExchangeAmount).toEqBigNumber(newLimitMax)
})

describe('Has a proposal', () => {
beforeEach(async () => {
sellAmount = new BigNumber('100000000')
await (
await celoToken.increaseAllowance(grandaMento.address, sellAmount)
).sendAndWaitForReceipt()

await (
await grandaMento.createExchangeProposal(
kit.celoTokens.getContract(StableToken.cUSD),
sellAmount,
true
)
).sendAndWaitForReceipt()
})

it('executes', async () => {
const activeProposals = await grandaMento.getActiveProposalIds()
expect(activeProposals).not.toEqual([])

let proposal = await grandaMento.getExchangeProposal(activeProposals[0])
expect(proposal.exchanger).toEqual(accounts[0])
expect(proposal.stableToken).toEqual(stableToken.address)
expect(proposal.sellAmount).toEqBigNumber(sellAmount)
expect(proposal.buyAmount).toEqBigNumber(new BigNumber('99000000'))
expect(proposal.approvalTimestamp).toEqual(new BigNumber(0))
expect(proposal.state).toEqual(ExchangeProposalState.Proposed)
expect(proposal.sellCelo).toEqual(true)

await (
await grandaMento.approveExchangeProposal(activeProposals[0])
).sendAndWaitForReceipt()

proposal = await grandaMento.getExchangeProposal(activeProposals[0])

expect(proposal.state).toEqual(ExchangeProposalState.Approved)
await timeTravel(expConfig.vetoPeriodSeconds, web3)
await (
await grandaMento.executeExchangeProposal(activeProposals[0])
).sendAndWaitForReceipt()

proposal = await grandaMento.getExchangeProposal(activeProposals[0])
expect(proposal.state).toEqual(ExchangeProposalState.Executed)
})

it('cancels proposal', async () => {
await (await grandaMento.cancelExchangeProposal(1)).sendAndWaitForReceipt()

const proposal = await grandaMento.getExchangeProposal('1')
expect(proposal.state).toEqual(ExchangeProposalState.Cancelled)
})
})
})

it('#getConfig', async () => {
const config = await grandaMento.getConfig()
// expect(config.approver).toBe(expConfig.approver) // TODO FIX this tests, for some reason `expConfig.approver` is 0x0000...0 even it's writen on the migrations-override.json
expect(config.spread).toEqBigNumber(expConfig.spread)
expect(config.vetoPeriodSeconds).toEqBigNumber(expConfig.vetoPeriodSeconds)
expect(
config.exchangeLimits.get(kit.celoTokens.getContract(StableToken.cUSD))?.minExchangeAmount
).toEqBigNumber(new BigNumber(0))
expect(
config.exchangeLimits.get(kit.celoTokens.getContract(StableToken.cUSD))?.maxExchangeAmount
).toEqBigNumber(new BigNumber(0))
expect(
config.exchangeLimits.get(kit.celoTokens.getContract(StableToken.cEUR))?.minExchangeAmount
).toEqBigNumber(new BigNumber(0))
expect(
config.exchangeLimits.get(kit.celoTokens.getContract(StableToken.cEUR))?.maxExchangeAmount
).toEqBigNumber(new BigNumber(0))
})
})
Loading