Skip to content

Commit

Permalink
Fix lack check of bridge token id (#244)
Browse files Browse the repository at this point in the history
* Remove `nearTokenId` argument

* Add near tokenId to the event
  • Loading branch information
karim-en authored May 30, 2024
1 parent e6f987b commit 34ab34f
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions erc20-bridge-token/contracts/BridgeTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ contract BridgeTokenFactory is

event Deposit(string indexed token, uint256 amount, address recipient);

event SetMetadata(address indexed token, string name, string symbol, uint8 decimals);
event SetMetadata(
address indexed token,
string tokenId,
string name,
string symbol,
uint8 decimals
);

// BridgeTokenFactory is linked to the bridge token factory on NEAR side.
// It also links to the prover that it uses to unlock the tokens.
Expand Down Expand Up @@ -98,12 +104,9 @@ contract BridgeTokenFactory is
}

function newBridgeToken(
string calldata nearTokenId,
bytes memory proofData,
uint64 proofBlockHeight
) external returns (address) {
require(!_isBridgeToken[_nearToEthToken[nearTokenId]], "ERR_TOKEN_EXIST");

ProofDecoder.ExecutionStatus memory status = _parseAndConsumeProof(
proofData,
proofBlockHeight
Expand All @@ -112,6 +115,8 @@ contract BridgeTokenFactory is
status.successValue
);

require(!_isBridgeToken[_nearToEthToken[result.token]], "ERR_TOKEN_EXIST");

address bridgeTokenProxy = address(
new ERC1967Proxy(
tokenImplementationAddress,
Expand All @@ -124,11 +129,17 @@ contract BridgeTokenFactory is
)
);

emit SetMetadata(bridgeTokenProxy, result.name, result.symbol, result.decimals);
emit SetMetadata(
bridgeTokenProxy,
result.token,
result.name,
result.symbol,
result.decimals
);

_isBridgeToken[address(bridgeTokenProxy)] = true;
_ethToNearToken[address(bridgeTokenProxy)] = nearTokenId;
_nearToEthToken[nearTokenId] = address(bridgeTokenProxy);
_ethToNearToken[address(bridgeTokenProxy)] = result.token;
_nearToEthToken[result.token] = address(bridgeTokenProxy);

return bridgeTokenProxy;
}
Expand All @@ -144,7 +155,13 @@ contract BridgeTokenFactory is

bridgeToken.setMetadata(name, symbol, bridgeToken.decimals());

emit SetMetadata(address(bridgeToken), name, symbol, bridgeToken.decimals());
emit SetMetadata(
address(bridgeToken),
token,
name,
symbol,
bridgeToken.decimals()
);
}

function deposit(
Expand Down

0 comments on commit 34ab34f

Please # to comment.