Add total burned method

This commit is contained in:
lash 2022-12-05 18:25:04 +00:00
parent 90fb95208f
commit 140dde7bc3
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
5 changed files with 36 additions and 5 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -167,6 +167,21 @@ class DemurrageToken(ERC20):
return tx return tx
def total_burned(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
j = JSONRPCRequest(id_generator)
o = j.template()
o['method'] = 'eth_call'
enc = ABIContractEncoder()
enc.method('totalBurned')
data = add_0x(enc.get())
tx = self.template(sender_address, contract_address)
tx = self.set_code(tx, data)
o['params'].append(self.normalize(tx))
o['params'].append('latest')
o = j.finalize(o)
return o
def to_base_amount(self, contract_address, value, sender_address=ZERO_ADDRESS, id_generator=None): def to_base_amount(self, contract_address, value, sender_address=ZERO_ADDRESS, id_generator=None):
j = JSONRPCRequest(id_generator) j = JSONRPCRequest(id_generator)
o = j.template() o = j.template()
@ -538,6 +553,7 @@ class DemurrageToken(ERC20):
def parse_supply_cap(self, v): def parse_supply_cap(self, v):
return abi_decode_single(ABIContractType.UINT256, v) return abi_decode_single(ABIContractType.UINT256, v)
@classmethod @classmethod
def parse_grow_by(self, v): def parse_grow_by(self, v):
return abi_decode_single(ABIContractType.UINT256, v) return abi_decode_single(ABIContractType.UINT256, v)
@ -561,3 +577,8 @@ class DemurrageToken(ERC20):
@classmethod @classmethod
def parse_resolution_factor(self, v): def parse_resolution_factor(self, v):
return abi_decode_single(ABIContractType.UINT256, v) return abi_decode_single(ABIContractType.UINT256, v)
@classmethod
def parse_total_burned(self, v):
return abi_decode_single(ABIContractType.UINT256, v)

View File

@ -37,7 +37,7 @@ class TestBurn(TestDemurrageDefault):
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc) nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash, o) = c.burn(self.address, self.accounts[1], 500000) (tx_hash, o) = c.burn(self.address, self.accounts[1], 600000)
r = self.rpc.do(o) r = self.rpc.do(o)
o = receipt(tx_hash) o = receipt(tx_hash)
r = self.rpc.do(o) r = self.rpc.do(o)
@ -50,7 +50,7 @@ class TestBurn(TestDemurrageDefault):
nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc) nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc)
c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) c = DemurrageToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash, o) = c.burn(self.address, self.accounts[1], 500000) (tx_hash, o) = c.burn(self.address, self.accounts[1], 600000)
r = self.rpc.do(o) r = self.rpc.do(o)
o = receipt(tx_hash) o = receipt(tx_hash)
r = self.rpc.do(o) r = self.rpc.do(o)
@ -59,7 +59,12 @@ class TestBurn(TestDemurrageDefault):
o = c.total_supply(self.address, sender_address=self.accounts[0]) o = c.total_supply(self.address, sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
new_supply = c.parse_total_supply(r) new_supply = c.parse_total_supply(r)
self.assertEqual(new_supply, 500000) self.assertEqual(new_supply, 400000)
o = c.total_burned(self.address, sender_address=self.accounts[0])
r = self.rpc.do(o)
burned = c.parse_total_burned(r)
self.assertEqual(burned, 600000)
def test_burned_redistribution(self): def test_burned_redistribution(self):

View File

@ -509,6 +509,11 @@ contract DemurrageTokenSingleCap {
return supply - burned; return supply - burned;
} }
// Return total number of burned tokens
function totalBurned() public view returns (uint256) {
return burned;
}
// Implements EIP165 // Implements EIP165
function supportsInterface(bytes4 _sum) public pure returns (bool) { function supportsInterface(bytes4 _sum) public pure returns (bool) {
if (_sum == 0xc6bb4b70) { // ERC20 if (_sum == 0xc6bb4b70) { // ERC20