Address Contract Verified
Address
0xb323692b6d4DB96af1f52E4499a2bd0Ded9af3C5
Balance
0 ETH
Nonce
1
Code Size
8855 bytes
Creator
0x9cc99311...3848 at tx 0x1d265da9...ad976c
Indexed Transactions
0
Contract Bytecode
8855 bytes
0x608060405234801561001057600080fd5b506004361061011b5760003560e01c80639f208c0e116100b2578063c2c5e12911610081578063cf1a0ce111610066578063cf1a0ce11461034f578063cf54aaa014610372578063e84b50291461039757600080fd5b8063c2c5e12914610329578063ca3369c61461033c57600080fd5b80639f208c0e146102cd578063a2d7cab8146102e0578063a97e5c93146102f3578063b48105471461031657600080fd5b806369d38e1c116100ee57806369d38e1c146102835780636dd85ef91461029057806375f2d82b146102a35780637ecd81a5146102b857600080fd5b806302dd2d5714610120578063181cdc421461015857806350a814941461017957806363591bfb1461021e575b600080fd5b61014361012e3660046118df565b60036020526000908152604090205460ff1681565b60405190151581526020015b60405180910390f35b61016b610166366004611912565b6103aa565b60405190815260200161014f565b61016b610187366004611a02565b805160208083015160408085015160609586015180518186015191840151845161da7a81890152308187015246998101999099526001600160a01b0397881660808a01529690941660a088015260c087019190915260e086019290925261010085019190915267ffffffffffffffff9092166101208085019190915282518085039091018152610140909301909152815191012090565b61016b61022c366004611acc565b6040805161d15a602080830191909152308284015246606083015294151560808201526001600160a01b039390931660a084015260c0808401929092528051808403909201825260e0909201909152805191012090565b6005546101439060ff1681565b61014361029e3660046118df565b6103f8565b6102ab61047a565b60405161014f9190611b4e565b6102cb6102c6366004611bad565b6104dc565b005b6102cb6102db366004611c27565b61058d565b6102cb6102ee366004611d32565b6105db565b6101436103013660046118df565b60026020526000908152604090205460ff1681565b6102cb610324366004611d79565b6108f3565b61016b610337366004611dfd565b6109bf565b6102cb61034a366004611ea6565b6109dc565b61014361035d366004611ed9565b60046020526000908152604090205460ff1681565b6103856103803660046118df565b610da2565b60405160ff909116815260200161014f565b6102cb6103a5366004611ef2565b610e0a565b6040805161b01260208201523091810191909152466060820152821515608082015260a0810182905260009060c0015b60405160208183030381529060405280519060200120905092915050565b6000816001600160a01b031663ce12cfc76040518163ffffffff1660e01b815260040160206040518083038186803b15801561043357600080fd5b505afa925050508015610463575060408051601f3d908101601f1916820190925261046091810190611f4d565b60015b61046f57506000919050565b92915050565b919050565b606060018054806020026020016040519081016040528092919081815260200182805480156104d257602002820191906000526020600020905b81546001600160a01b031681526001909101906020018083116104b4575b5050505050905090565b600061051b868686808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506109bf92505050565b90506105308161052b8486611f6a565b610fc5565b600081815260046020908152604091829020805460ff1916600117905581518682028181018301909352868152610585928992899189918291908501908490808284376000920191909152506111d092505050565b505050505050565b600061059985856103aa565b90506105a98161052b8486611f6a565b60009081526004602052604090208054600160ff19918216179091556005805490911694151594909417909355505050565b80516001600160a01b03166106375760405162461bcd60e51b815260206004820152601260248201527f45434453413a207a65726f207369676e6572000000000000000000000000000060448201526064015b60405180910390fd5b80602001515160411461068c5760405162461bcd60e51b815260206004820152601f60248201527f45434453413a20696e76616c6964207369676e6174757265206c656e67746800604482015260640161062e565b60208082015190810151604082015160608301519192909160001a907f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a083111561073e5760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202773272076616c60448201527f7565000000000000000000000000000000000000000000000000000000000000606482015260840161062e565b8160ff16601b148061075357508160ff16601c145b6107c55760405162461bcd60e51b815260206004820152602260248201527f45434453413a20696e76616c6964207369676e6174757265202776272076616c60448201527f7565000000000000000000000000000000000000000000000000000000000000606482015260840161062e565b60006040518060400160405280601c81526020017f19457468657265756d205369676e6564204d6573736167653a0a33320000000081525090506000818860405160200161081492919061200a565b60408051601f1981840301815282825280516020918201208a516000855291840180845281905260ff88169284019290925260608301899052608083018890529092506001600160a01b03169060019060a0016020604051602081039080840390855afa158015610889573d6000803e3d6000fd5b505050602060405103516001600160a01b0316146108e95760405162461bcd60e51b815260206004820152600f60248201527f57726f6e67207369676e61747572650000000000000000000000000000000000604482015260640161062e565b5050505050505050565b6040805161d15a602080830191909152308284015246606083015287151560808301526001600160a01b03871660a083015260c08083018790528351808403909101815260e090920190925280519101206109528161052b8486611f6a565b6000818152600460205260409020805460ff191660011790558515610999576001600160a01b0385166000908152600360205260409020805460ff19166001179055610585565b505050506001600160a01b03166000908152600360205260409020805460ff1916905550565b60006105e7304685856040516020016103da95949392919061202c565b6109e4611453565b60055460ff16610a365760405162461bcd60e51b815260206004820152601a60248201527f4c6f636b2069732063757272656e746c792064697361626c6564000000000000604482015260640161062e565b6001600160a01b03831660009081526003602052604090205460ff1615610a9f5760405162461bcd60e51b815260206004820152601460248201527f6c6f636b3a2064697361626c656420746f6b656e000000000000000000000000604482015260640161062e565b610aa8836103f8565b15610af55760405162461bcd60e51b815260206004820152601360248201527f6c6f636b2077726170706564206a6574746f6e00000000000000000000000000604482015260640161062e565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526000906001600160a01b038516906370a082319060240160206040518083038186803b158015610b5057600080fd5b505afa158015610b64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b889190612064565b9050610b9f6001600160a01b0385163330866114ad565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526000906001600160a01b038616906370a082319060240160206040518083038186803b158015610bfa57600080fd5b505afa158015610c0e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c329190612064565b9050818111610ca95760405162461bcd60e51b815260206004820152602a60248201527f6e657742616c616e6365206d7573742062652067726561746572207468616e2060448201527f6f6c6442616c616e636500000000000000000000000000000000000000000000606482015260840161062e565b6effffffffffffffffffffffffffffff811115610d2e5760405162461bcd60e51b815260206004820152602360248201527f4d6178206a6574746f6e20746f74616c537570706c792032202a2a203132302060448201527f2d20310000000000000000000000000000000000000000000000000000000000606482015260840161062e565b826001600160a01b038616337fb63d8201cdffedbd3acaf1b529eaf1fe511144b988c0c97c6a0166c17e135b7c610d6586866120ac565b85610d6f8b610da2565b60408051938452602084019290925260ff16908201526060015b60405180910390a45050610d9d6001600055565b505050565b6000816001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b158015610ddd57600080fd5b505afa925050508015610463575060408051601f3d908101601f19168201909252610460918101906120c3565b610e12611453565b6000610e2661018736869003860186611a02565b9050610e368161052b8486611f6a565b6000818152600460209081526040909120805460ff19166001179055610e8690610e62908601866118df565b60408601803590610e7690602089016118df565b6001600160a01b03169190611564565b6000610e9860408601602087016118df565b6040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526001600160a01b0391909116906370a082319060240160206040518083038186803b158015610ef257600080fd5b505afa158015610f06573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f2a9190612064565b9050610f3960208601866118df565b6001600160a01b03166080860135610f5760408801602089016118df565b6001600160a01b03167f7288db6a9257374290bd46846c6c7a988c10fad7aeba335d3ed9b30da2bea91c6060890135610f9660c08b0160a08c016120e6565b6040805192835267ffffffffffffffff9091166020830152808b01359082015260608101869052608001610d89565b600154600390610fd6906002612101565b610fe190600261213e565b610feb9190612156565b8151101561103b5760405162461bcd60e51b815260206004820152601560248201527f4e6f7420656e6f756768207369676e6174757265730000000000000000000000604482015260640161062e565b60008281526004602052604090205460ff161561109a5760405162461bcd60e51b815260206004820152601860248201527f566f746520697320616c72656164792066696e69736865640000000000000000604482015260640161062e565b80516000805b828110156111c95760008482815181106110bc576110bc612191565b602090810291909101810151516001600160a01b0381166000908152600290925260409091205490915060ff166111355760405162461bcd60e51b815260206004820152601360248201527f556e617574686f72697a6564207369676e657200000000000000000000000000604482015260640161062e565b6001600160a01b03811683811161118e5760405162461bcd60e51b815260206004820152601960248201527f5369676e61747572657320617265206e6f7420736f7274656400000000000000604482015260640161062e565b8093506111b4878785815181106111a7576111a7612191565b60200260200101516105db565b505080806111c1906121c0565b9150506110a0565b5050505050565b60028151116112215760405162461bcd60e51b815260206004820152601460248201527f4e65772073657420697320746f6f2073686f7274000000000000000000000000604482015260640161062e565b60015460005b8181101561128e576000600260006001848154811061124857611248612191565b6000918252602080832091909101546001600160a01b031683528201929092526040019020805460ff191691151591909117905580611286816121c0565b915050611227565b5081516112a2906001906020850190611836565b5060015460005b818110156114135760006001600160a01b03168482815181106112ce576112ce612191565b60200260200101516001600160a01b0316141561132d5760405162461bcd60e51b815260206004820152600b60248201527f7a65726f207369676e6572000000000000000000000000000000000000000000604482015260640161062e565b6002600085838151811061134357611343612191565b6020908102919091018101516001600160a01b031682528101919091526040016000205460ff16156113b75760405162461bcd60e51b815260206004820152601760248201527f4475706c6963617465206f7261636c6520696e20536574000000000000000000604482015260640161062e565b6001600260008684815181106113cf576113cf612191565b6020908102919091018101516001600160a01b03168252810191909152604001600020805460ff19169115159190911790558061140b816121c0565b9150506112a9565b507f9486a6c41bd991eda1bcabe983ebe4fe4a19b8109acdea68feebd49c8cc1d25a84846040516114459291906121f9565b60405180910390a150505050565b600260005414156114a65760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161062e565b6002600055565b6040516001600160a01b038085166024830152831660448201526064810182905261155e9085907f23b872dd00000000000000000000000000000000000000000000000000000000906084015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff00000000000000000000000000000000000000000000000000000000909316929092179091526115ad565b50505050565b6040516001600160a01b038316602482015260448101829052610d9d9084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064016114fa565b6000611602826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166116929092919063ffffffff16565b805190915015610d9d57808060200190518101906116209190611f4d565b610d9d5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f74207375636365656400000000000000000000000000000000000000000000606482015260840161062e565b60606116a184846000856116a9565b949350505050565b6060824710156117215760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c0000000000000000000000000000000000000000000000000000606482015260840161062e565b600080866001600160a01b0316858760405161173d9190612212565b60006040518083038185875af1925050503d806000811461177a576040519150601f19603f3d011682016040523d82523d6000602084013e61177f565b606091505b50915091506117908783838761179b565b979650505050505050565b60608315611807578251611800576001600160a01b0385163b6118005760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161062e565b50816116a1565b6116a1838381511561181c5781518083602001fd5b8060405162461bcd60e51b815260040161062e919061222e565b8280548282559060005260206000209081019282156118a3579160200282015b828111156118a357825182547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b03909116178255602090920191600190910190611856565b506118af9291506118b3565b5090565b5b808211156118af57600081556001016118b4565b80356001600160a01b038116811461047557600080fd5b6000602082840312156118f157600080fd5b6118fa826118c8565b9392505050565b801515811461190f57600080fd5b50565b6000806040838503121561192557600080fd5b823561193081611901565b946020939093013593505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040516060810167ffffffffffffffff811182821017156119905761199061193e565b60405290565b6040805190810167ffffffffffffffff811182821017156119905761199061193e565b604051601f8201601f1916810167ffffffffffffffff811182821017156119e2576119e261193e565b604052919050565b803567ffffffffffffffff8116811461047557600080fd5b600081830360c0811215611a1557600080fd5b6040516080810181811067ffffffffffffffff82111715611a3857611a3861193e565b604052611a44846118c8565b8152611a52602085016118c8565b60208201526040840135604082015260607fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa083011215611a9157600080fd5b611a9961196d565b91506060840135825260808401356020830152611ab860a085016119ea565b604083015260608101919091529392505050565b600080600060608486031215611ae157600080fd5b8335611aec81611901565b9250611afa602085016118c8565b9150604084013590509250925092565b600081518084526020808501945080840160005b83811015611b435781516001600160a01b031687529582019590820190600101611b1e565b509495945050505050565b6020815260006118fa6020830184611b0a565b60008083601f840112611b7357600080fd5b50813567ffffffffffffffff811115611b8b57600080fd5b6020830191508360208260051b8501011115611ba657600080fd5b9250929050565b600080600080600060608688031215611bc557600080fd5b85359450602086013567ffffffffffffffff80821115611be457600080fd5b611bf089838a01611b61565b90965094506040880135915080821115611c0957600080fd5b50611c1688828901611b61565b969995985093965092949392505050565b60008060008060608587031215611c3d57600080fd5b8435611c4881611901565b935060208501359250604085013567ffffffffffffffff811115611c6b57600080fd5b611c7787828801611b61565b95989497509550505050565b600060408284031215611c9557600080fd5b611c9d611996565b9050611ca8826118c8565b815260208083013567ffffffffffffffff80821115611cc657600080fd5b818501915085601f830112611cda57600080fd5b813581811115611cec57611cec61193e565b611cfe84601f19601f840116016119b9565b91508082528684828501011115611d1457600080fd5b80848401858401376000908201840152918301919091525092915050565b60008060408385031215611d4557600080fd5b82359150602083013567ffffffffffffffff811115611d6357600080fd5b611d6f85828601611c83565b9150509250929050565b600080600080600060808688031215611d9157600080fd5b8535611d9c81611901565b9450611daa602087016118c8565b935060408601359250606086013567ffffffffffffffff811115611dcd57600080fd5b611c1688828901611b61565b600067ffffffffffffffff821115611df357611df361193e565b5060051b60200190565b60008060408385031215611e1057600080fd5b8235915060208084013567ffffffffffffffff811115611e2f57600080fd5b8401601f81018613611e4057600080fd5b8035611e53611e4e82611dd9565b6119b9565b81815260059190911b82018301908381019088831115611e7257600080fd5b928401925b82841015611e9757611e88846118c8565b82529284019290840190611e77565b80955050505050509250929050565b600080600060608486031215611ebb57600080fd5b611ec4846118c8565b95602085013595506040909401359392505050565b600060208284031215611eeb57600080fd5b5035919050565b600080600083850360e0811215611f0857600080fd5b60c0811215611f1657600080fd5b5083925060c084013567ffffffffffffffff811115611f3457600080fd5b611f4086828701611b61565b9497909650939450505050565b600060208284031215611f5f57600080fd5b81516118fa81611901565b6000611f78611e4e84611dd9565b80848252602080830192508560051b850136811115611f9657600080fd5b855b81811015611fd257803567ffffffffffffffff811115611fb85760008081fd5b611fc436828a01611c83565b865250938201938201611f98565b50919695505050505050565b60005b83811015611ff9578181015183820152602001611fe1565b8381111561155e5750506000910152565b6000835161201c818460208801611fde565b9190910191825250602001919050565b61ffff861681526001600160a01b038516602082015283604082015282606082015260a06080820152600061179060a0830184611b0a565b60006020828403121561207657600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000828210156120be576120be61207d565b500390565b6000602082840312156120d557600080fd5b815160ff811681146118fa57600080fd5b6000602082840312156120f857600080fd5b6118fa826119ea565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04831182151516156121395761213961207d565b500290565b600082198211156121515761215161207d565b500190565b60008261218c577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156121f2576121f261207d565b5060010190565b8281526040602082015260006116a16040830184611b0a565b60008251612224818460208701611fde565b9190910192915050565b602081526000825180602084015261224d816040850160208701611fde565b601f01601f1916919091016040019291505056fea26469706673582212200d8d65379ad66ea236e1658657519fe56f2f574a7e2b0ef98ae5a806ee52540c64736f6c63430008090033
Verified Source Code Full Match
Compiler: v0.8.9+commit.e5eed63a
EVM: london
Optimization: Yes (5000 runs)
Bridge.sol 191 lines
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./SignatureChecker.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
interface IWrappedJetton {
function isWrappedJetton() external pure returns (bool);
}
interface IDecimals {
function decimals() external view returns (uint8);
}
contract Bridge is SignatureChecker, ReentrancyGuard {
using SafeERC20 for IERC20;
address[] oracleSet;
mapping(address => bool) public isOracle;
mapping(address => bool) public disabledTokens;
mapping(bytes32 => bool) public finishedVotings;
bool public allowLock;
event Lock(
address indexed from,
address indexed token,
bytes32 indexed to_addr_hash,
uint256 value,
uint256 new_bridge_balance,
uint8 decimals
);
event Unlock(
address indexed token,
bytes32 ton_address_hash,
bytes32 indexed ton_tx_hash,
uint64 lt,
address indexed to,
uint256 value,
uint256 new_bridge_balance
);
event NewOracleSet(uint256 oracleSetHash, address[] newOracles);
constructor(address[] memory initialSet) {
_updateOracleSet(0, initialSet);
disabledTokens[address(0)] = true;
disabledTokens[address(0x582d872A1B094FC48F5DE31D3B73F2D9bE47def1)] = true; // wrapped toncoin
disabledTokens[address(0x76A797A59Ba2C17726896976B7B3747BfD1d220f)] = true; // wrapped toncoin
}
function _generalVote(bytes32 digest, Signature[] memory signatures)
internal
view
{
require(
signatures.length >= (2 * oracleSet.length + 2) / 3,
"Not enough signatures"
);
require(!finishedVotings[digest], "Vote is already finished");
uint256 signum = signatures.length;
uint256 last_signer = 0;
for (uint256 i = 0; i < signum; i++) {
address signer = signatures[i].signer;
require(isOracle[signer], "Unauthorized signer");
uint256 next_signer = uint256(uint160(signer));
require(next_signer > last_signer, "Signatures are not sorted");
last_signer = next_signer;
checkSignature(digest, signatures[i]);
}
}
function lock(
address token,
uint256 amount,
bytes32 to_address_hash
) external nonReentrant {
require(allowLock, "Lock is currently disabled");
require(!disabledTokens[token], "lock: disabled token");
require(!checkTokenIsWrappedJetton(token), "lock wrapped jetton");
uint256 oldBalance = IERC20(token).balanceOf(address(this));
IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
uint256 newBalance = IERC20(token).balanceOf(address(this));
require(newBalance > oldBalance, "newBalance must be greater than oldBalance");
require(newBalance <= 2 ** 120 - 1, "Max jetton totalSupply 2 ** 120 - 1");
emit Lock(
msg.sender,
token,
to_address_hash,
newBalance - oldBalance,
newBalance,
getDecimals(token)
);
}
function unlock(SwapData calldata data, Signature[] calldata signatures)
external nonReentrant
{
bytes32 _id = getSwapDataId(data);
_generalVote(_id, signatures);
finishedVotings[_id] = true;
IERC20(data.token).safeTransfer(data.receiver, data.amount);
uint256 newBalance = IERC20(data.token).balanceOf(address(this));
emit Unlock(data.token, data.tx.address_hash, data.tx.tx_hash, data.tx.lt, data.receiver, data.amount, newBalance);
}
function voteForNewOracleSet(
uint256 oracleSetHash,
address[] calldata newOracles,
Signature[] calldata signatures
) external {
bytes32 _id = getNewSetId(oracleSetHash, newOracles);
_generalVote(_id, signatures);
finishedVotings[_id] = true;
_updateOracleSet(oracleSetHash, newOracles);
}
function voteForSwitchLock(
bool newLockStatus,
uint256 nonce,
Signature[] calldata signatures
) external {
bytes32 _id = getNewLockStatusId(newLockStatus, nonce);
_generalVote(_id, signatures);
finishedVotings[_id] = true;
allowLock = newLockStatus;
}
function voteForDisableToken(
bool isDisable,
address tokenAddress,
uint256 nonce,
Signature[] calldata signatures
) external {
bytes32 _id = getNewDisableToken(isDisable, tokenAddress, nonce);
_generalVote(_id, signatures);
finishedVotings[_id] = true;
if (isDisable) {
disabledTokens[tokenAddress] = true;
} else {
delete disabledTokens[tokenAddress];
}
}
function _updateOracleSet(uint256 oracleSetHash, address[] memory newOracles)
internal
{
require(newOracles.length > 2, "New set is too short");
uint256 oldSetLen = oracleSet.length;
for (uint256 i = 0; i < oldSetLen; i++) {
isOracle[oracleSet[i]] = false;
}
oracleSet = newOracles;
uint256 newSetLen = oracleSet.length;
for (uint256 i = 0; i < newSetLen; i++) {
require(newOracles[i] != address(0), "zero signer");
require(!isOracle[newOracles[i]], "Duplicate oracle in Set");
isOracle[newOracles[i]] = true;
}
emit NewOracleSet(oracleSetHash, newOracles);
}
function getFullOracleSet() external view returns (address[] memory) {
return oracleSet;
}
function checkTokenIsWrappedJetton(address token) public pure returns (bool) {
try IWrappedJetton(token).isWrappedJetton() returns (
bool isWrappedJetton
) {
return isWrappedJetton;
} catch {
return false;
}
}
function getDecimals(address token) public view returns (uint8) {
try IDecimals(token).decimals() returns (
uint8 decimals
) {
return decimals;
} catch {
return 0;
}
}
}
TonUtils.sol 22 lines
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
interface TonUtils {
struct TonTxID {
bytes32 address_hash; // sender user address
bytes32 tx_hash; // transaction hash on bridge smart contract
uint64 lt; // transaction LT (logical time) on bridge smart contract
}
struct SwapData {
address receiver; // user's EVM-address to receive tokens
address token; // ERC-20 token address
uint256 amount; // token amount in units to receive in EVM-network
TonTxID tx;
}
struct Signature {
address signer; // oracle's EVM-address
bytes signature; // oracle's signature
}
}
SignatureChecker.sol 90 lines
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
import "./TonUtils.sol";
contract SignatureChecker is TonUtils {
function checkSignature(bytes32 digest, Signature memory sig) public pure {
require(sig.signer != address(0), "ECDSA: zero signer"); // The `ecrecover` function returns zero on failure, so if sig.signer == 0 then any signature will be accepted regardless of whether it is cryptographically valid.
require(sig.signature.length == 65, "ECDSA: invalid signature length");
// Divide the signature in r, s and v variables
bytes32 r;
bytes32 s;
uint8 v;
bytes memory signature = sig.signature;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
// solhint-disable-next-line no-inline-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
require(
uint256(s) <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,
"ECDSA: invalid signature 's' value"
);
require(v == 27 || v == 28, "ECDSA: invalid signature 'v' value");
bytes memory prefix = "\x19Ethereum Signed Message:\n32";
bytes32 prefixedHash = keccak256(abi.encodePacked(prefix, digest));
require(
ecrecover(prefixedHash, v, r, s) == sig.signer,
"Wrong signature"
);
}
function getSwapDataId(SwapData memory data)
public
view
returns (bytes32 result)
{
result = keccak256(
abi.encode(
0xDA7A,
address(this),
block.chainid,
data.receiver,
data.token,
data.amount,
data.tx.address_hash,
data.tx.tx_hash,
data.tx.lt
)
);
}
function getNewSetId(uint256 oracleSetHash, address[] memory set)
public
view
returns (bytes32 result)
{
result = keccak256(
abi.encode(0x5e7, address(this), block.chainid, oracleSetHash, set)
);
}
function getNewLockStatusId(bool newLockStatus, uint256 nonce)
public
view
returns (bytes32 result)
{
result = keccak256(
abi.encode(0xB012, address(this), block.chainid, newLockStatus, nonce)
);
}
function getNewDisableToken(bool isDisable, address tokenAddress, uint256 nonce)
public
view
returns (bytes32 result)
{
result = keccak256(
abi.encode(0xD15A, address(this), block.chainid, isDisable, tokenAddress, nonce)
);
}
}
Address.sol 244 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
ReentrancyGuard.sol 69 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
}
SafeERC20.sol 116 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/draft-IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
draft-IERC20Permit.sol 60 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
Read Contract
allowLock 0x69d38e1c → bool
checkSignature 0x4f0f8a21
checkTokenIsWrappedJetton 0x6dd85ef9 → bool
disabledTokens 0x02dd2d57 → bool
finishedVotings 0xcf1a0ce1 → bool
getDecimals 0xcf54aaa0 → uint8
getFullOracleSet 0x75f2d82b → address[]
getNewDisableToken 0x63591bfb → bytes32
getNewLockStatusId 0x181cdc42 → bytes32
getNewSetId 0xc2c5e129 → bytes32
getSwapDataId 0xa91b27c6 → bytes32
isOracle 0xa97e5c93 → bool
Write Contract 5 functions
These functions modify contract state and require a wallet transaction to execute.
lock 0xca3369c6
address token
uint256 amount
bytes32 to_address_hash
unlock 0x620381ab
tuple data
tuple[] signatures
voteForDisableToken 0x2cb757e9
bool isDisable
address tokenAddress
uint256 nonce
tuple[] signatures
voteForNewOracleSet 0xa45be1ec
uint256 oracleSetHash
address[] newOracles
tuple[] signatures
voteForSwitchLock 0xa2b2bbb7
bool newLockStatus
uint256 nonce
tuple[] signatures
Token Balances (8)
View Transfers →Recent Transactions
No transactions found for this address