-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Remove granda mento + metatransaction wallet (#10822)"
This reverts commit 9ab9d00.
- Loading branch information
Showing
148 changed files
with
7,002 additions
and
3,005 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Address } from '@celo/base/lib/address' | ||
import { newKitFromWeb3 } from '@celo/contractkit' | ||
import { assumeOwnership } from '@celo/contractkit/lib/test-utils/transferownership' | ||
import { GrandaMentoWrapper } from '@celo/contractkit/lib/wrappers/GrandaMento' | ||
import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' | ||
import BigNumber from 'bignumber.js' | ||
import Web3 from 'web3' | ||
import { testLocally } from '../../test-utils/cliUtils' | ||
import Cancel from './cancel' | ||
import Propose from './propose' | ||
|
||
testWithGanache('grandamento:cancel cmd', (web3: Web3) => { | ||
const kit = newKitFromWeb3(web3) | ||
let grandaMento: GrandaMentoWrapper | ||
const newLimitMin = new BigNumber('1000') | ||
const newLimitMax = new BigNumber('1000000000000') | ||
let accounts: Address[] = [] | ||
|
||
const increaseLimits = async () => { | ||
await grandaMento | ||
.setStableTokenExchangeLimits('StableToken', newLimitMin.toString(), newLimitMax.toString()) | ||
.sendAndWaitForReceipt() | ||
} | ||
|
||
beforeAll(async () => { | ||
accounts = await web3.eth.getAccounts() | ||
kit.defaultAccount = accounts[0] | ||
grandaMento = await kit.contracts.getGrandaMento() | ||
}) | ||
|
||
beforeEach(async () => { | ||
await assumeOwnership(web3, accounts[0]) | ||
await increaseLimits() | ||
// create mock proposal | ||
await testLocally(Propose, [ | ||
'--from', | ||
accounts[0], | ||
'--sellCelo', | ||
'true', | ||
'--stableToken', | ||
'cUSD', | ||
'--value', | ||
'10000', | ||
]) | ||
}) | ||
|
||
describe('cancel', () => { | ||
it('left no proposal', async () => { | ||
await testLocally(Cancel, ['--from', accounts[0], '--proposalID', '1']) | ||
const activeProposals = await grandaMento.getActiveProposalIds() | ||
expect(activeProposals).toEqual([]) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { flags } from '@oclif/command' | ||
import { BaseCommand } from '../../base' | ||
import { newCheckBuilder } from '../../utils/checks' | ||
import { displaySendTx } from '../../utils/cli' | ||
import { Flags } from '../../utils/command' | ||
|
||
export default class Cancel extends BaseCommand { | ||
static description = 'Cancels a Granda Mento exchange proposal' | ||
|
||
static flags = { | ||
...BaseCommand.flags, | ||
from: Flags.address({ | ||
required: true, | ||
description: 'The address allowed to cancel the proposal', | ||
}), | ||
proposalID: flags.string({ | ||
required: true, | ||
exclusive: ['account', 'hotfix'], | ||
description: 'UUID of proposal to view', | ||
}), | ||
} | ||
|
||
async run() { | ||
const grandaMento = await this.kit.contracts.getGrandaMento() | ||
|
||
const res = this.parse(Cancel) | ||
const proposalID = res.flags.proposalID | ||
|
||
await newCheckBuilder(this).grandaMentoProposalExists(proposalID).runChecks() | ||
|
||
await displaySendTx( | ||
'cancelExchangeProposal', | ||
grandaMento.cancelExchangeProposal(proposalID), | ||
undefined, | ||
'ExchangeProposalCancelled' | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Address } from '@celo/base/lib/address' | ||
import { newKitFromWeb3 } from '@celo/contractkit' | ||
import { assumeOwnership } from '@celo/contractkit/lib/test-utils/transferownership' | ||
import { GrandaMentoWrapper } from '@celo/contractkit/lib/wrappers/GrandaMento' | ||
import { testWithGanache, timeTravel } from '@celo/dev-utils/lib/ganache-test' | ||
import BigNumber from 'bignumber.js' | ||
import Web3 from 'web3' | ||
import { testLocally } from '../../test-utils/cliUtils' | ||
import Execute from './execute' | ||
import Propose from './propose' | ||
|
||
testWithGanache('grandamento:execute cmd', (web3: Web3) => { | ||
const kit = newKitFromWeb3(web3) | ||
let grandaMento: GrandaMentoWrapper | ||
const newLimitMin = new BigNumber('1000') | ||
const newLimitMax = new BigNumber('1000000000000') | ||
let accounts: Address[] = [] | ||
const dateNowOriginal = Date.now | ||
let originalNoSyncCheck: string | undefined | ||
|
||
const increaseLimits = () => { | ||
return grandaMento | ||
.setStableTokenExchangeLimits('StableToken', newLimitMin.toString(), newLimitMax.toString()) | ||
.sendAndWaitForReceipt() | ||
} | ||
|
||
const createExchangeProposal = () => { | ||
// create mock proposal | ||
return testLocally(Propose, [ | ||
'--from', | ||
accounts[0], | ||
'--sellCelo', | ||
'true', | ||
'--stableToken', | ||
'cUSD', | ||
'--value', | ||
'10000', | ||
]) | ||
} | ||
|
||
const approveExchangeProposal = async (proposalID: number | string) => { | ||
await grandaMento.setApprover(accounts[0]).sendAndWaitForReceipt() | ||
await grandaMento.approveExchangeProposal(proposalID).sendAndWaitForReceipt() | ||
} | ||
|
||
const timeTravelDateAndChain = async (seconds: number) => { | ||
await timeTravel(seconds, web3) | ||
jest.useFakeTimers().setSystemTime(dateNowOriginal() + seconds * 1000) | ||
// Otherwise contractkit complains there is a difference between Date.now() | ||
// and the timestamp of the last block | ||
process.env.NO_SYNCCHECK = 'true' | ||
} | ||
|
||
beforeAll(async () => { | ||
accounts = await web3.eth.getAccounts() | ||
kit.defaultAccount = accounts[0] | ||
grandaMento = await kit.contracts.getGrandaMento() | ||
originalNoSyncCheck = process.env.NO_SYNCCHECK | ||
}) | ||
|
||
afterEach(() => { | ||
process.env.NO_SYNCCHECK = originalNoSyncCheck | ||
}) | ||
|
||
beforeEach(async () => { | ||
await assumeOwnership(web3, accounts[0]) | ||
await increaseLimits() | ||
await createExchangeProposal() | ||
// Approve it | ||
await approveExchangeProposal(1) | ||
// Wait the veto period plus some extra time to be safe | ||
await timeTravelDateAndChain((await grandaMento.vetoPeriodSeconds()).toNumber() + 1000) | ||
}) | ||
|
||
describe('execute', () => { | ||
it('executes the proposal', async () => { | ||
await testLocally(Execute, ['--from', accounts[0], '--proposalID', '1']) | ||
const activeProposals = await grandaMento.getActiveProposalIds() | ||
expect(activeProposals).toEqual([]) | ||
}) | ||
|
||
it('fails if the exchange proposal is not executable', async () => { | ||
// Create a proposal with proposalID 2, but don't wait the veto period | ||
await createExchangeProposal() | ||
await approveExchangeProposal(2) | ||
await expect( | ||
testLocally(Execute, ['--from', accounts[0], '--proposalID', '2']) | ||
).rejects.toThrow() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { flags } from '@oclif/command' | ||
import { BaseCommand } from '../../base' | ||
import { newCheckBuilder } from '../../utils/checks' | ||
import { displaySendTx } from '../../utils/cli' | ||
import { Flags } from '../../utils/command' | ||
|
||
export default class Execute extends BaseCommand { | ||
static description = 'Executes a Granda Mento exchange proposal' | ||
|
||
static flags = { | ||
...BaseCommand.flags, | ||
from: Flags.address({ | ||
required: true, | ||
description: 'The address to execute the exchange proposal', | ||
}), | ||
proposalID: flags.string({ | ||
required: true, | ||
description: 'UUID of proposal to view', | ||
}), | ||
} | ||
|
||
async run() { | ||
const grandaMento = await this.kit.contracts.getGrandaMento() | ||
|
||
const res = this.parse(Execute) | ||
const proposalID = res.flags.proposalID | ||
|
||
await newCheckBuilder(this) | ||
.grandaMentoProposalExists(proposalID) | ||
.grandaMentoProposalIsExecutable(proposalID) | ||
.runChecks() | ||
|
||
await displaySendTx( | ||
'executeExchangeProposal', | ||
grandaMento.executeExchangeProposal(proposalID), | ||
undefined, | ||
'ExchangeProposalExecuted' | ||
) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/cli/src/commands/grandamento/get-buy-amount.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Address } from '@celo/base/lib/address' | ||
import { newKitFromWeb3 } from '@celo/contractkit' | ||
import { assumeOwnership } from '@celo/contractkit/lib/test-utils/transferownership' | ||
import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' | ||
import Web3 from 'web3' | ||
import { testLocally } from '../../test-utils/cliUtils' | ||
import GetBuyAmount from './get-buy-amount' | ||
|
||
testWithGanache('grandamento:get-buy-amount cmd', (web3: Web3) => { | ||
const kit = newKitFromWeb3(web3) | ||
let accounts: Address[] = [] | ||
|
||
beforeAll(async () => { | ||
accounts = await web3.eth.getAccounts() | ||
kit.defaultAccount = accounts[0] | ||
}) | ||
|
||
beforeEach(async () => { | ||
await assumeOwnership(web3, accounts[0]) | ||
}) | ||
|
||
it('gets the buy amount', async () => { | ||
await testLocally(GetBuyAmount, [ | ||
'--sellCelo', | ||
'true', | ||
'--stableToken', | ||
'cusd', | ||
'--value', | ||
'100000000000000000000000', | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { StableToken } from '@celo/contractkit' | ||
import { toFixed } from '@celo/utils/lib/fixidity' | ||
import { flags } from '@oclif/command' | ||
import { BaseCommand } from '../../base' | ||
import { printValueMap } from '../../utils/cli' | ||
import { Flags } from '../../utils/command' | ||
import { enumEntriesDupWithLowercase } from '../../utils/helpers' | ||
|
||
const stableTokenOptions = enumEntriesDupWithLowercase(Object.entries(StableToken)) | ||
|
||
export default class GetBuyAmount extends BaseCommand { | ||
static description = 'Gets the buy amount for a prospective Granda Mento exchange' | ||
|
||
static flags = { | ||
...BaseCommand.flags, | ||
value: Flags.wei({ | ||
required: true, | ||
description: 'The value of the tokens to exchange', | ||
}), | ||
stableToken: flags.enum({ | ||
required: true, | ||
options: Object.keys(stableTokenOptions), | ||
description: 'Name of the stable to receive or send', | ||
default: 'cUSD', | ||
}), | ||
sellCelo: flags.enum({ | ||
options: ['true', 'false'], | ||
required: true, | ||
description: 'Sell or buy CELO', | ||
}), | ||
} | ||
|
||
async run() { | ||
const grandaMento = await this.kit.contracts.getGrandaMento() | ||
|
||
const res = this.parse(GetBuyAmount) | ||
const sellAmount = res.flags.value | ||
const stableToken = stableTokenOptions[res.flags.stableToken] | ||
const sellCelo = res.flags.sellCelo === 'true' | ||
|
||
const stableTokenAddress = await this.kit.celoTokens.getAddress(stableToken) | ||
const sortedOracles = await this.kit.contracts.getSortedOracles() | ||
const celoStableTokenOracleRate = (await sortedOracles.medianRate(stableTokenAddress)).rate | ||
|
||
const buyAmount = await grandaMento.getBuyAmount( | ||
toFixed(celoStableTokenOracleRate), | ||
sellAmount, | ||
sellCelo | ||
) | ||
|
||
printValueMap({ | ||
buyAmount, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Address } from '@celo/base/lib/address' | ||
import { newKitFromWeb3 } from '@celo/contractkit' | ||
import { StableToken } from '@celo/contractkit/lib/celo-tokens' | ||
import { assumeOwnership } from '@celo/contractkit/lib/test-utils/transferownership' | ||
import { GoldTokenWrapper } from '@celo/contractkit/lib/wrappers/GoldTokenWrapper' | ||
import { GrandaMentoWrapper } from '@celo/contractkit/lib/wrappers/GrandaMento' | ||
import { testWithGanache } from '@celo/dev-utils/lib/ganache-test' | ||
import BigNumber from 'bignumber.js' | ||
import Web3 from 'web3' | ||
import { testLocally } from '../../test-utils/cliUtils' | ||
import { setGrandaMentoLimits } from '../../test-utils/grandaMento' | ||
import List from './list' | ||
|
||
testWithGanache('grandamento:list cmd', (web3: Web3) => { | ||
const kit = newKitFromWeb3(web3) | ||
let grandaMento: GrandaMentoWrapper | ||
let accounts: Address[] = [] | ||
let celoToken: GoldTokenWrapper | ||
|
||
beforeAll(async () => { | ||
accounts = await web3.eth.getAccounts() | ||
kit.defaultAccount = accounts[0] | ||
grandaMento = await kit.contracts.getGrandaMento() | ||
|
||
celoToken = await kit.contracts.getGoldToken() | ||
}) | ||
|
||
beforeEach(async () => { | ||
await assumeOwnership(web3, accounts[0]) | ||
await setGrandaMentoLimits(grandaMento) | ||
}) | ||
|
||
it('shows an empty list of proposals', async () => { | ||
await testLocally(List, []) | ||
}) | ||
|
||
it('shows proposals', async () => { | ||
// create mock proposal | ||
const sellAmount = new BigNumber('100000000') | ||
await celoToken.increaseAllowance(grandaMento.address, sellAmount).sendAndWaitForReceipt() | ||
await ( | ||
await grandaMento.createExchangeProposal( | ||
kit.celoTokens.getContract(StableToken.cUSD), | ||
sellAmount, | ||
true | ||
) | ||
).sendAndWaitForReceipt() | ||
|
||
await testLocally(List, []) | ||
}) | ||
}) |
Oops, something went wrong.