Skip to content

Commit

Permalink
Merge pull request #79 from webb-tools/drew/token-removal
Browse files Browse the repository at this point in the history
Adds token removal function from the whitelist
  • Loading branch information
akileshtangella authored Dec 21, 2021
2 parents c8687e6 + 8c3a9a2 commit 9ea1ffd
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 11 deletions.
31 changes: 31 additions & 0 deletions contracts/tokens/GovernedTokenWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ contract GovernedTokenWrapper is TokenWrapper {

address public governor;
address[] public tokens;
address[] public historicalTokens;
mapping (address => bool) valid;
mapping (address => bool) historicallyValid;

bool public isNativeAllowed;
uint256 public wrappingLimit;
Expand All @@ -39,9 +41,34 @@ contract GovernedTokenWrapper is TokenWrapper {
function add(address tokenAddress) public onlyGovernor {
require(!valid[tokenAddress], "Token should not be valid");
tokens.push(tokenAddress);

if (!historicallyValid[tokenAddress]) {
historicalTokens.push(tokenAddress);
historicallyValid[tokenAddress] = true;
}
valid[tokenAddress] = true;
}

function remove(address tokenAddress) public onlyGovernor {
require(valid[tokenAddress], "Token should be valid");
uint index = 0;
for (uint i = 0; i < tokens.length; i++) {
if (tokens[i] == tokenAddress) {
index = i;
break;
}
}

valid[tokenAddress] = false;
removeTokenAtIndex(index);
}

function removeTokenAtIndex(uint index) internal {
require(index < tokens.length);
tokens[index] = tokens[tokens.length-1];
tokens.pop();
}

function updateLimit(uint256 limit) public onlyGovernor {
wrappingLimit = limit;
}
Expand All @@ -54,6 +81,10 @@ contract GovernedTokenWrapper is TokenWrapper {
function _isValidAddress(address tokenAddress) override internal virtual returns (bool) {
return valid[tokenAddress];
}

function _isValidHistoricalAddress(address tokenAddress) override internal virtual returns (bool) {
return historicallyValid[tokenAddress];
}

function _isValidAmount(uint256 amount) override internal virtual returns (bool) {
return amount + this.totalSupply() <= wrappingLimit;
Expand Down
5 changes: 4 additions & 1 deletion contracts/tokens/TokenWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ abstract contract TokenWrapper is ERC20PresetMinterPauser, ITokenWrapper {
/** @dev this function is defined in a child contract */
function _isValidAddress(address tokenAddress) internal virtual returns (bool);

/** @dev this function is defined in a child contract */
function _isValidHistoricalAddress(address tokenAddress) internal virtual returns (bool);

/** @dev this function is defined in a child contract */
function _isNativeValid() internal virtual returns (bool);

Expand Down Expand Up @@ -214,7 +217,7 @@ abstract contract TokenWrapper is ERC20PresetMinterPauser, ITokenWrapper {
require(_isNativeValid(), "Native unwrapping is not allowed for this token wrapper");
} else {
require(IERC20(tokenAddress).balanceOf(address(this)) >= amount, "Insufficient ERC20 balance");
require(_isValidAddress(tokenAddress), "Invalid token address");
require(_isValidHistoricalAddress(tokenAddress), "Invalid historical token address");
}

_;
Expand Down
38 changes: 38 additions & 0 deletions docs/GovernedTokenWrapper.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,28 @@ function hasRole(bytes32 role, address account) external view returns (bool)
|---|---|---|
| _0 | bool | undefined

### historicalTokens

```solidity
function historicalTokens(uint256) external view returns (address)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| _0 | uint256 | undefined

#### Returns

| Name | Type | Description |
|---|---|---|
| _0 | address | undefined

### increaseAllowance

```solidity
Expand Down Expand Up @@ -505,6 +527,22 @@ function paused() external view returns (bool)
|---|---|---|
| _0 | bool | undefined

### remove

```solidity
function remove(address tokenAddress) external nonpayable
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| tokenAddress | address | undefined

### renounceRole

```solidity
Expand Down
59 changes: 59 additions & 0 deletions packages/contracts/src/GovernedTokenWrapper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ interface GovernedTokenWrapperInterface extends ethers.utils.Interface {
"governor()": FunctionFragment;
"grantRole(bytes32,address)": FunctionFragment;
"hasRole(bytes32,address)": FunctionFragment;
"historicalTokens(uint256)": FunctionFragment;
"increaseAllowance(address,uint256)": FunctionFragment;
"isNativeAllowed()": FunctionFragment;
"mint(address,uint256)": FunctionFragment;
"name()": FunctionFragment;
"pause()": FunctionFragment;
"paused()": FunctionFragment;
"remove(address)": FunctionFragment;
"renounceRole(bytes32,address)": FunctionFragment;
"revokeRole(bytes32,address)": FunctionFragment;
"setFee(uint8)": FunctionFragment;
Expand Down Expand Up @@ -132,6 +134,10 @@ interface GovernedTokenWrapperInterface extends ethers.utils.Interface {
functionFragment: "hasRole",
values: [BytesLike, string]
): string;
encodeFunctionData(
functionFragment: "historicalTokens",
values: [BigNumberish]
): string;
encodeFunctionData(
functionFragment: "increaseAllowance",
values: [string, BigNumberish]
Expand All @@ -147,6 +153,7 @@ interface GovernedTokenWrapperInterface extends ethers.utils.Interface {
encodeFunctionData(functionFragment: "name", values?: undefined): string;
encodeFunctionData(functionFragment: "pause", values?: undefined): string;
encodeFunctionData(functionFragment: "paused", values?: undefined): string;
encodeFunctionData(functionFragment: "remove", values: [string]): string;
encodeFunctionData(
functionFragment: "renounceRole",
values: [BytesLike, string]
Expand Down Expand Up @@ -266,6 +273,10 @@ interface GovernedTokenWrapperInterface extends ethers.utils.Interface {
decodeFunctionResult(functionFragment: "governor", data: BytesLike): Result;
decodeFunctionResult(functionFragment: "grantRole", data: BytesLike): Result;
decodeFunctionResult(functionFragment: "hasRole", data: BytesLike): Result;
decodeFunctionResult(
functionFragment: "historicalTokens",
data: BytesLike
): Result;
decodeFunctionResult(
functionFragment: "increaseAllowance",
data: BytesLike
Expand All @@ -278,6 +289,7 @@ interface GovernedTokenWrapperInterface extends ethers.utils.Interface {
decodeFunctionResult(functionFragment: "name", data: BytesLike): Result;
decodeFunctionResult(functionFragment: "pause", data: BytesLike): Result;
decodeFunctionResult(functionFragment: "paused", data: BytesLike): Result;
decodeFunctionResult(functionFragment: "remove", data: BytesLike): Result;
decodeFunctionResult(
functionFragment: "renounceRole",
data: BytesLike
Expand Down Expand Up @@ -507,6 +519,11 @@ export class GovernedTokenWrapper extends BaseContract {
overrides?: CallOverrides
): Promise<[boolean]>;

historicalTokens(
arg0: BigNumberish,
overrides?: CallOverrides
): Promise<[string]>;

increaseAllowance(
spender: string,
addedValue: BigNumberish,
Expand All @@ -529,6 +546,11 @@ export class GovernedTokenWrapper extends BaseContract {

paused(overrides?: CallOverrides): Promise<[boolean]>;

remove(
tokenAddress: string,
overrides?: Overrides & { from?: string | Promise<string> }
): Promise<ContractTransaction>;

renounceRole(
role: BytesLike,
account: string,
Expand Down Expand Up @@ -716,6 +738,11 @@ export class GovernedTokenWrapper extends BaseContract {
overrides?: CallOverrides
): Promise<boolean>;

historicalTokens(
arg0: BigNumberish,
overrides?: CallOverrides
): Promise<string>;

increaseAllowance(
spender: string,
addedValue: BigNumberish,
Expand All @@ -738,6 +765,11 @@ export class GovernedTokenWrapper extends BaseContract {

paused(overrides?: CallOverrides): Promise<boolean>;

remove(
tokenAddress: string,
overrides?: Overrides & { from?: string | Promise<string> }
): Promise<ContractTransaction>;

renounceRole(
role: BytesLike,
account: string,
Expand Down Expand Up @@ -919,6 +951,11 @@ export class GovernedTokenWrapper extends BaseContract {
overrides?: CallOverrides
): Promise<boolean>;

historicalTokens(
arg0: BigNumberish,
overrides?: CallOverrides
): Promise<string>;

increaseAllowance(
spender: string,
addedValue: BigNumberish,
Expand All @@ -939,6 +976,8 @@ export class GovernedTokenWrapper extends BaseContract {

paused(overrides?: CallOverrides): Promise<boolean>;

remove(tokenAddress: string, overrides?: CallOverrides): Promise<void>;

renounceRole(
role: BytesLike,
account: string,
Expand Down Expand Up @@ -1226,6 +1265,11 @@ export class GovernedTokenWrapper extends BaseContract {
overrides?: CallOverrides
): Promise<BigNumber>;

historicalTokens(
arg0: BigNumberish,
overrides?: CallOverrides
): Promise<BigNumber>;

increaseAllowance(
spender: string,
addedValue: BigNumberish,
Expand All @@ -1248,6 +1292,11 @@ export class GovernedTokenWrapper extends BaseContract {

paused(overrides?: CallOverrides): Promise<BigNumber>;

remove(
tokenAddress: string,
overrides?: Overrides & { from?: string | Promise<string> }
): Promise<BigNumber>;

renounceRole(
role: BytesLike,
account: string,
Expand Down Expand Up @@ -1444,6 +1493,11 @@ export class GovernedTokenWrapper extends BaseContract {
overrides?: CallOverrides
): Promise<PopulatedTransaction>;

historicalTokens(
arg0: BigNumberish,
overrides?: CallOverrides
): Promise<PopulatedTransaction>;

increaseAllowance(
spender: string,
addedValue: BigNumberish,
Expand All @@ -1466,6 +1520,11 @@ export class GovernedTokenWrapper extends BaseContract {

paused(overrides?: CallOverrides): Promise<PopulatedTransaction>;

remove(
tokenAddress: string,
overrides?: Overrides & { from?: string | Promise<string> }
): Promise<PopulatedTransaction>;

renounceRole(
role: BytesLike,
account: string,
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 9ea1ffd

Please sign in to comment.