feat: deployment scripts fixed and lock fx unit tests added

This commit is contained in:
PedroCailleret committed 2022-12-07 12:43:57 -03:00
1 parent 1a4b4973d4
commit d541e7b70c
17 files changed
+585 -96

No files matched your search

@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/ce60783a904758b510bc61bc47947601.json"
"buildInfo": "../../build-info/4a0f142c7439e90ed9431fa5c0d6c0c6.json"
}
@@ -286,6 +286,25 @@
"name": "ReputationUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "seller",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "merkleRoot",
"type": "bytes32"
}
],
"name": "RootUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
+1 -1
View File
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/351fea96dbbd5ddc7250e49d27b4151f.json"
"buildInfo": "../../build-info/4a0f142c7439e90ed9431fa5c0d6c0c6.json"
}
+21 -2
View File
@@ -341,6 +341,25 @@
"name": "ReputationUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "seller",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "merkleRoot",
"type": "bytes32"
}
],
"name": "RootUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
@@ -854,8 +873,8 @@
"type": "receive"
}
],
"bytecode": "0x60806040526001805560405162002825380380620028258339810160408190526200002a916200049d565b600080546001600160a01b031916339081178255604051909182917f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d76908290a3506200007685620000a3565b620000818362000133565b6200008c84620001bd565b620000988282620002a1565b505050505062000620565b6000546001600160a01b03163314620000f25760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b806004557f70fa43ca70216ad905ade86b9e650a691b2ce5a01980d0a81bdd8324141b8511816040516200012891815260200190565b60405180910390a150565b6000546001600160a01b031633146200017e5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b60028190556040516001600160a01b03821681527fe127cf589a3879da0156d4a24f43b44f65cfa3570de594806b0bfa2fcf06884f9060200162000128565b6000546001600160a01b03163314620002085760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b80516000905b808210156200026e57600062000246848481518110620002325762000232620005bb565b60200260200101516200038760201b60201c565b6000908152600660205260409020805460ff191660019081179091559290920191506200020e565b50507f14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d781604051620001289190620005d1565b6000546001600160a01b03163314620002ec5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b815180620003025763df9578836000526004601cfd5b81518114620003195763ff633a386000526004601cfd5b60208301602083016020830282015b8083146200037f578251600052600b60205260406000208251815550815183517f5d6e86e5341d57a92c49934296c51542a25015c9b1782a1c2722a940131c3d9a600080a360208301925060208201915062000328565b505050505050565b600c1b611000600160ac1b031690565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715620003d857620003d862000397565b604052919050565b60006001600160401b03821115620003fc57620003fc62000397565b5060051b60200190565b6001600160a01b03811681146200041c57600080fd5b50565b600082601f8301126200043157600080fd5b815160206200044a6200044483620003e0565b620003ad565b82815260059290921b840181019181810190868411156200046a57600080fd5b8286015b8481101562000492578051620004848162000406565b83529183019183016200046e565b509695505050505050565b600080600080600060a08688031215620004b657600080fd5b8551602080880151919650906001600160401b0380821115620004d857600080fd5b620004e68a838b016200041f565b965060408901519150620004fa8262000406565b6060890151919550808211156200051057600080fd5b6200051e8a838b016200041f565b945060808901519150808211156200053557600080fd5b508701601f810189136200054857600080fd5b8051620005596200044482620003e0565b81815260059190911b8201830190838101908b8311156200057957600080fd5b928401925b82841015620005a95783518015158114620005995760008081fd5b825292840192908401906200057e565b80955050505050509295509295909350565b634e487b7160e01b600052603260045260246000fd5b6020808252825182820181905260009190848201906040850190845b81811015620006145783516001600160a01b031683529284019291840191600101620005ed565b50909695505050505050565b6121f580620006306000396000f3fe60806040526004361061018f5760003560e01c806377cd38a4116100d65780638e2a3d361161007f578063c52164c611610059578063c52164c614610539578063d6e8b97314610559578063f7d0e04b1461057957600080fd5b80638e2a3d36146104c25780639872dbfe146104f357806398a268711461050957600080fd5b80638652b37e116100b05780638652b37e1461044a5780638da5cb5b1461046a5780638e2749d6146104a257600080fd5b806377cd38a4146103dd5780637f94f65d1461040a5780638642b5c31461042a57600080fd5b806336317972116101385780635fd8c710116101125780635fd8c7101461036857806369cc6af41461037d57806372fada5c146103bd57600080fd5b806336317972146102fd5780634b2ae9801461031d578063574983c81461034857600080fd5b806316d722401161016957806316d722401461021d57806329cc7d10146102c65780632dfdf0b5146102e657600080fd5b8063049373201461019b5780630d2a2d44146101db57806313af4035146101fd57600080fd5b3661019657005b600080fd5b3480156101a757600080fd5b506101c86101b6366004611af1565b60056020526000908152604090205481565b6040519081526020015b60405180910390f35b3480156101e757600080fd5b506101fb6101f6366004611bfe565b610599565b005b34801561020957600080fd5b506101fb610218366004611c3b565b61068a565b34801561022957600080fd5b50610282610238366004611af1565b600860205260009081526040902080546001820154600283015460038401546004850154600586015460069096015494959394929391926001600160a01b03918216928216911687565b6040805197885260208801969096529486019390935260608501919091526001600160a01b03908116608085015290811660a08401521660c082015260e0016101d2565b3480156102d257600080fd5b506101c86102e1366004611c58565b61071e565b3480156102f257600080fd5b506003546101c89081565b34801561030957600080fd5b506101fb610318366004611d35565b6108fc565b34801561032957600080fd5b506101c8610338366004611c3b565b600c1b611000600160ac1b031690565b34801561035457600080fd5b506101fb610363366004611af1565b6109bc565b34801561037457600080fd5b506101fb610a3a565b34801561038957600080fd5b50Line truncated
"deployedBytecode": "0x60806040526004361061018f5760003560e01c806377cd38a4116100d65780638e2a3d361161007f578063c52164c611610059578063c52164c614610539578063d6e8b97314610559578063f7d0e04b1461057957600080fd5b80638e2a3d36146104c25780639872dbfe146104f357806398a268711461050957600080fd5b80638652b37e116100b05780638652b37e1461044a5780638da5cb5b1461046a5780638e2749d6146104a257600080fd5b806377cd38a4146103dd5780637f94f65d1461040a5780638642b5c31461042a57600080fd5b806336317972116101385780635fd8c710116101125780635fd8c7101461036857806369cc6af41461037d57806372fada5c146103bd57600080fd5b806336317972146102fd5780634b2ae9801461031d578063574983c81461034857600080fd5b806316d722401161016957806316d722401461021d57806329cc7d10146102c65780632dfdf0b5146102e657600080fd5b8063049373201461019b5780630d2a2d44146101db57806313af4035146101fd57600080fd5b3661019657005b600080fd5b3480156101a757600080fd5b506101c86101b6366004611af1565b60056020526000908152604090205481565b6040519081526020015b60405180910390f35b3480156101e757600080fd5b506101fb6101f6366004611bfe565b610599565b005b34801561020957600080fd5b506101fb610218366004611c3b565b61068a565b34801561022957600080fd5b50610282610238366004611af1565b600860205260009081526040902080546001820154600283015460038401546004850154600586015460069096015494959394929391926001600160a01b03918216928216911687565b6040805197885260208801969096529486019390935260608501919091526001600160a01b03908116608085015290811660a08401521660c082015260e0016101d2565b3480156102d257600080fd5b506101c86102e1366004611c58565b61071e565b3480156102f257600080fd5b506003546101c89081565b34801561030957600080fd5b506101fb610318366004611d35565b6108fc565b34801561032957600080fd5b506101c8610338366004611c3b565b600c1b611000600160ac1b031690565b34801561035457600080fd5b506101fb610363366004611af1565b6109bc565b34801561037457600080fd5b506101fb610a3a565b34801561038957600080fd5b506103ad610398366004611c3b565b600b6020526000908152604090205460ff1681565b60405190151581526020016101d2565b3480156103c957600080fd5b506101fb6103d8366004611af1565b610ac4565b3480156103e957600080fd5b506101c86103f8366004611af1565b600a6020526000908152604090205481565b34801561041657600080fd5b506101fb610425366004611d81565b610b4c565b34801561043657600080fd5b506101fb610445366004611dad565b610b97565b34801561045657600080fd5b506101c8610465366004611e11565b610f65565b34801561047657600080fd5b5060005461048a906001600160a01b031681565b6040516001600160a01b0390911681526020016101d2565b3480156104ae57600080fd5b506101fb6104bd366004611ec5565b6112b8565b3480156104ce57600080fd5b506104e26104dd366004611af1565b611410565b6040516101d2959493929190611f07565b3480156104ff57600080fd5b506101c860045481565b34801561051557600080fd5b506103ad610524366004611af1565b60066020526000908152604090205460ff1681565b34801561054557600080fd5b5060025461048a906001600160a01b031681565b34801561056557600080fd5b506101fb610574366004611f94565b6114da565b34801561058557600080fd5b506101fb610594366004611c3b565b6115b2565b6000546001600160a01b031633146105e75760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b80516000905b8082101561064e57600061062784848151811061060c5761060c61205e565b6020026020010151611000600160ac1b03600c9190911b1690565b6000908152600660205260409020805460ff191660019081179091559290920191506105ed565b50507f14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d78160405161067f9190612074565b60405180910390a150565b6000546001600160a01b031633146106d35760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064016105de565b600080546001600160a01b0319166001600160a01b0383169081178255604051909133917f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d769190a350565b6001600160a01b0385166000908152600b6020526040812054869060ff1661075957604051630abc194760e11b815260040160405180910390fd5b610761611639565b915060006040518060a0016040528088815260200187878080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050908252503360208201526001600160a01b038a166040820152600160609091015290506107d6611689565b83156107e6576107e63385610b4c565b6000838152600760209081526040909120825181558183015180518493610814926001850192910190611a58565b5060408201516002820180546001600160a01b039283166001600160a01b03199091161790556060830151600392830180546080909501511515600160a01b027fffffffffffffffffffffff0000000000000000000000000000000000000000009095169190921617929092179091556108919080546001019055565b61089d8233308a6116b4565b6108a660018055565b604080518481526001600160a01b038a16602082015290810188905233907f25ac57b911b0f66b64c294827f539545fbc3ddd002cafab117776274f3241e4c9060600160405180910390a2505095945050505050565b610904611689565b61090d8361174b565b61091782826112b8565b60008381526007602052604090206003810154600160a01b900460ff161515600114156109475761094784610ac4565b600381015481546000835560028301546001600160a01b03928316926109709184911683611788565b604080518781526020810183905233917f7719804546c0185709e60c90d164447ff251a5ba29af0216faa921350f6bebf7910160405180910390a25050506109b76001805556Line truncated
"bytecode": "0x608060405260018055604051620027e1380380620027e18339810160408190526200002a916200049d565b600080546001600160a01b031916339081178255604051909182917f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d76908290a3506200007685620000a3565b620000818362000133565b6200008c84620001bd565b620000988282620002a1565b505050505062000620565b6000546001600160a01b03163314620000f25760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b806004557f70fa43ca70216ad905ade86b9e650a691b2ce5a01980d0a81bdd8324141b8511816040516200012891815260200190565b60405180910390a150565b6000546001600160a01b031633146200017e5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b60028190556040516001600160a01b03821681527fe127cf589a3879da0156d4a24f43b44f65cfa3570de594806b0bfa2fcf06884f9060200162000128565b6000546001600160a01b03163314620002085760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b80516000905b808210156200026e57600062000246848481518110620002325762000232620005bb565b60200260200101516200038760201b60201c565b6000908152600660205260409020805460ff191660019081179091559290920191506200020e565b50507f14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d781604051620001289190620005d1565b6000546001600160a01b03163314620002ec5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b815180620003025763df9578836000526004601cfd5b81518114620003195763ff633a386000526004601cfd5b60208301602083016020830282015b8083146200037f578251600052600b60205260406000208251815550815183517f5d6e86e5341d57a92c49934296c51542a25015c9b1782a1c2722a940131c3d9a600080a360208301925060208201915062000328565b505050505050565b600c1b611000600160ac1b031690565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715620003d857620003d862000397565b604052919050565b60006001600160401b03821115620003fc57620003fc62000397565b5060051b60200190565b6001600160a01b03811681146200041c57600080fd5b50565b600082601f8301126200043157600080fd5b815160206200044a6200044483620003e0565b620003ad565b82815260059290921b840181019181810190868411156200046a57600080fd5b8286015b8481101562000492578051620004848162000406565b83529183019183016200046e565b509695505050505050565b600080600080600060a08688031215620004b657600080fd5b8551602080880151919650906001600160401b0380821115620004d857600080fd5b620004e68a838b016200041f565b965060408901519150620004fa8262000406565b6060890151919550808211156200051057600080fd5b6200051e8a838b016200041f565b945060808901519150808211156200053557600080fd5b508701601f810189136200054857600080fd5b8051620005596200044482620003e0565b81815260059190911b8201830190838101908b8311156200057957600080fd5b928401925b82841015620005a95783518015158114620005995760008081fd5b825292840192908401906200057e565b80955050505050509295509295909350565b634e487b7160e01b600052603260045260246000fd5b6020808252825182820181905260009190848201906040850190845b81811015620006145783516001600160a01b031683529284019291840191600101620005ed565b50909695505050505050565b6121b180620006306000396000f3fe60806040526004361061018f5760003560e01c806377cd38a4116100d65780638e2a3d361161007f578063c52164c611610059578063c52164c614610539578063d6e8b97314610559578063f7d0e04b1461057957600080fd5b80638e2a3d36146104c25780639872dbfe146104f357806398a268711461050957600080fd5b80638652b37e116100b05780638652b37e1461044a5780638da5cb5b1461046a5780638e2749d6146104a257600080fd5b806377cd38a4146103dd5780637f94f65d1461040a5780638642b5c31461042a57600080fd5b806336317972116101385780635fd8c710116101125780635fd8c7101461036857806369cc6af41461037d57806372fada5c146103bd57600080fd5b806336317972146102fd5780634b2ae9801461031d578063574983c81461034857600080fd5b806316d722401161016957806316d722401461021d57806329cc7d10146102c65780632dfdf0b5146102e657600080fd5b8063049373201461019b5780630d2a2d44146101db57806313af4035146101fd57600080fd5b3661019657005b600080fd5b3480156101a757600080fd5b506101c86101b6366004611aad565b60056020526000908152604090205481565b6040519081526020015b60405180910390f35b3480156101e757600080fd5b506101fb6101f6366004611bba565b610599565b005b34801561020957600080fd5b506101fb610218366004611bf7565b61068a565b34801561022957600080fd5b50610282610238366004611aad565b600860205260009081526040902080546001820154600283015460038401546004850154600586015460069096015494959394929391926001600160a01b03918216928216911687565b6040805197885260208801969096529486019390935260608501919091526001600160a01b03908116608085015290811660a08401521660c082015260e0016101d2565b3480156102d257600080fd5b506101c86102e1366004611c14565b61072b565b3480156102f257600080fd5b506003546101c89081565b34801561030957600080fd5b506101fb610318366004611cf1565b610916565b34801561032957600080fd5b506101c8610338366004611bf7565b600c1b611000600160ac1b031690565b34801561035457600080fd5b506101fb610363366004611aad565b6109d6565b34801561037457600080fd5b506101fb610a54565b34801561038957600080fd5b50Line truncated
"deployedBytecode": "0x60806040526004361061018f5760003560e01c806377cd38a4116100d65780638e2a3d361161007f578063c52164c611610059578063c52164c614610539578063d6e8b97314610559578063f7d0e04b1461057957600080fd5b80638e2a3d36146104c25780639872dbfe146104f357806398a268711461050957600080fd5b80638652b37e116100b05780638652b37e1461044a5780638da5cb5b1461046a5780638e2749d6146104a257600080fd5b806377cd38a4146103dd5780637f94f65d1461040a5780638642b5c31461042a57600080fd5b806336317972116101385780635fd8c710116101125780635fd8c7101461036857806369cc6af41461037d57806372fada5c146103bd57600080fd5b806336317972146102fd5780634b2ae9801461031d578063574983c81461034857600080fd5b806316d722401161016957806316d722401461021d57806329cc7d10146102c65780632dfdf0b5146102e657600080fd5b8063049373201461019b5780630d2a2d44146101db57806313af4035146101fd57600080fd5b3661019657005b600080fd5b3480156101a757600080fd5b506101c86101b6366004611aad565b60056020526000908152604090205481565b6040519081526020015b60405180910390f35b3480156101e757600080fd5b506101fb6101f6366004611bba565b610599565b005b34801561020957600080fd5b506101fb610218366004611bf7565b61068a565b34801561022957600080fd5b50610282610238366004611aad565b600860205260009081526040902080546001820154600283015460038401546004850154600586015460069096015494959394929391926001600160a01b03918216928216911687565b6040805197885260208801969096529486019390935260608501919091526001600160a01b03908116608085015290811660a08401521660c082015260e0016101d2565b3480156102d257600080fd5b506101c86102e1366004611c14565b61072b565b3480156102f257600080fd5b506003546101c89081565b34801561030957600080fd5b506101fb610318366004611cf1565b610916565b34801561032957600080fd5b506101c8610338366004611bf7565b600c1b611000600160ac1b031690565b34801561035457600080fd5b506101fb610363366004611aad565b6109d6565b34801561037457600080fd5b506101fb610a54565b34801561038957600080fd5b506103ad610398366004611bf7565b600b6020526000908152604090205460ff1681565b60405190151581526020016101d2565b3480156103c957600080fd5b506101fb6103d8366004611aad565b610ade565b3480156103e957600080fd5b506101c86103f8366004611aad565b600a6020526000908152604090205481565b34801561041657600080fd5b506101fb610425366004611d3d565b610b66565b34801561043657600080fd5b506101fb610445366004611d69565b610bf9565b34801561045657600080fd5b506101c8610465366004611dcd565b610fc7565b34801561047657600080fd5b5060005461048a906001600160a01b031681565b6040516001600160a01b0390911681526020016101d2565b3480156104ae57600080fd5b506101fb6104bd366004611e81565b611176565b3480156104ce57600080fd5b506104e26104dd366004611aad565b6112ce565b6040516101d2959493929190611ec3565b3480156104ff57600080fd5b506101c860045481565b34801561051557600080fd5b506103ad610524366004611aad565b60066020526000908152604090205460ff1681565b34801561054557600080fd5b5060025461048a906001600160a01b031681565b34801561056557600080fd5b506101fb610574366004611f50565b611398565b34801561058557600080fd5b506101fb610594366004611bf7565b611470565b6000546001600160a01b031633146105e75760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b80516000905b8082101561064e57600061062784848151811061060c5761060c61201a565b6020026020010151611000600160ac1b03600c9190911b1690565b6000908152600660205260409020805460ff191660019081179091559290920191506105ed565b50507f14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d78160405161067f9190612030565b60405180910390a150565b6000546001600160a01b031633146106d35760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064016105de565b6000805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0383169081178255604051909133917f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d769190a350565b6001600160a01b0385166000908152600b6020526040812054869060ff1661076657604051630abc194760e11b815260040160405180910390fd5b61076e6114f7565b915060006040518060a0016040528088815260200187878080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050908252503360208201526001600160a01b038a166040820152600160609091015290506107e3611547565b83156107f3576107f33385610b66565b6000838152600760209081526040909120825181558183015180518493610821926001850192910190611a14565b5060408201516002820180546001600160a01b0392831673ffffffffffffffffffffffffffffffffffffffff199091161790556060830151600392830180546080909501511515600160a01b027fffffffffffffffffffffff0000000000000000000000000000000000000000009095169190921617929092179091556108ab9080546001019055565b6108b78233308a611572565b6108c060018055565b604080518481526001600160a01b038a16602082015290810188905233907f25ac57b911b0f66b64c294827f539545fbc3ddd002cafab117776274f3241e4c9060600160405180910390a2505095945050505050565b61091e611547565b61092783611609565b6109318282611176565b60008381526007602052604090206003810154600160a01b900460ff161515600114156109615761096184610ade565b600381015481546000835560028301546001600160a01b039283169261098a9184911683611646565b604080518781526020810183905233917f7719804546c0185709e60c90d164447ff251a5ba29af0216faa921Line truncated
"linkReferences": {},
"deployedLinkReferences": {}
}
+20 -6
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
// prettier-ignore
interface EventAndErrors {
/// ███ Events ████████████████████████████████████████████████████████████
@@ -25,16 +26,29 @@ interface EventAndErrors {
uint256 depositID,
uint256 amount
);
event LockReleased(address indexed buyer, bytes32 lockId);
event LockReturned(address indexed buyer, bytes32 lockId);
event FundsWithdrawn(address owner, uint256 amount);
event ReputationUpdated(address reputation);
event LockBlocksUpdated(uint256 blocks);
event ValidSignersUpdated(address[] signers);
event LockReleased(
address indexed buyer,
bytes32 lockId
);
event LockReturned(
address indexed buyer,
bytes32 lockId
);
event FundsWithdrawn(
address owner,
uint256 amount
);
event RootUpdated(
address seller,
bytes32 merkleRoot
);
event AllowedERC20Updated(
address indexed token,
bool indexed state
);
event ReputationUpdated(address reputation);
event LockBlocksUpdated(uint256 blocks);
event ValidSignersUpdated(address[] signers);
/// ███ Errors ████████████████████████████████████████████████████████████
+37 -28
View File
@@ -194,40 +194,29 @@ contract P2PIX is
msg.sender
);
mapLocks[lockID] = l;
d.remaining -= _amount;
emit LockAdded(
_buyerAddress,
lockID,
l.depositID,
_amount
);
_addLock(lockID, l, d);
// Halt execution and output `lockID`.
return lockID;
} else {
uint256 userCredit = userRecord[
_castAddrToKey(msg.sender)
];
uint256 spendLimit;
(spendLimit) = _limiter(userCredit);
if (l.amount <= 1e2) {
_addLock(lockID, l, d);
// Halt execution and output `lockID`.
return lockID;
} else {
uint256 userCredit = userRecord[
_castAddrToKey(msg.sender)
];
uint256 spendLimit;
(spendLimit) = _limiter(userCredit);
if (l.amount > spendLimit || l.amount > 1e6)
revert AmountNotAllowed();
if (l.amount > spendLimit || l.amount > 1e6)
revert AmountNotAllowed();
mapLocks[lockID] = l;
d.remaining -= _amount;
emit LockAdded(
_buyerAddress,
lockID,
l.depositID,
_amount
);
// Halt execution and output `lockID`.
return lockID;
_addLock(lockID, l, d);
// Halt execution and output `lockID`.
return lockID;
}
}
}
@@ -417,6 +406,10 @@ contract P2PIX is
sellerAllowList[
_castAddrToKey(addr)
] = merkleroot;
emit RootUpdated(
addr,
merkleroot
);
} else revert OnlySeller();
}
@@ -587,6 +580,22 @@ contract P2PIX is
revert DepositAlreadyExists();
}
function _addLock(
bytes32 _lockID,
DT.Lock memory _l,
DT.Deposit storage _d
) internal {
mapLocks[_lockID] = _l;
_d.remaining -= _l.amount;
emit LockAdded(
_l.buyerAddress,
_lockID,
_l.depositID,
_l.amount
);
}
/// @notice Private view auxiliar logic that encodes/returns
/// the `bytes32` identifier of an lock.
/// @dev reverts on a not expired lock with the same ID passed
+3 -3
View File
@@ -3,6 +3,6 @@
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
],
"p2pix": "0x294003F602c321627152c6b7DED3EAb5bEa853Ee",
"token": "0x5BdEa33E2D14E3D4C66f9A7bbbc38Cd785D0C592"
}
"p2pix": "0x37c856F4d5bC2597da60f607b1335738468453F3",
"token": "0x294003F602c321627152c6b7DED3EAb5bEa853Ee"
}
+3 -2
View File
@@ -14,8 +14,8 @@
"compile": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile",
"typechain": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat typechain",
"test": "hardhat test",
"deploy1:localhost": "hardhat run scripts/1-deploy-p2pix.ts --network localhost",
"deploy2:localhost": "hardhat run scripts/2-deploy-mockToken.ts --network localhost",
"deploy1:localhost": "hardhat run scripts/1-deploy-mockToken.ts --network localhost",
"deploy2:localhost": "hardhat run scripts/2-deploy-p2pix.ts --network localhost",
"coverage": "hardhat coverage --solcoverjs ./.solcover.js --temp artifacts --testfiles \"test/**/*.ts\" && yarn typechain",
"lint": "yarn lint:sol && yarn lint:ts && yarn prettier:check",
"lint:sol": "solhint --config ./.solhint.json --max-warnings 0 \"contracts/**/*.sol\"",
@@ -49,6 +49,7 @@
"@typescript-eslint/eslint-plugin": "^5.42.0",
"@typescript-eslint/parser": "^5.42.0",
"chai": "^4.3.6",
"chalk": "4.x",
"commitizen": "^4.2.5",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.3.0",
File renamed without changes.
@@ -2,14 +2,8 @@ import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-etherscan";
import * as fs from "fs";
import { ethers, network } from "hardhat";
import { Deploys } from "../test/utils/fixtures";
// import hre from "hardhat";
interface Deploys {
signers: string[];
p2pix: string;
token: string;
}
let deploysJson: Deploys;
@@ -28,8 +22,18 @@ const main = async () => {
const [deployer] = await ethers.getSigners();
console.log(`Deploying contracts with ${deployer.address}`);
const Reputation = await ethers.getContractFactory("Reputation");
const reputation = await Reputation.deploy();
await reputation.deployed();
const P2PIX = await ethers.getContractFactory("P2PIX");
const p2pix = await P2PIX.deploy(2, deploysJson.signers);
const p2pix = await P2PIX.deploy(
10,
deploysJson.signers,
reputation.address,
[deploysJson.token],
[true]
);
await p2pix.deployed();
deploysJson.p2pix = p2pix.address;
+19
View File
@@ -26,6 +26,7 @@ export interface EventAndErrorsInterface extends utils.Interface {
"LockReleased(address,bytes32)": EventFragment;
"LockReturned(address,bytes32)": EventFragment;
"ReputationUpdated(address)": EventFragment;
"RootUpdated(address,bytes32)": EventFragment;
"ValidSignersUpdated(address[])": EventFragment;
};
@@ -39,6 +40,7 @@ export interface EventAndErrorsInterface extends utils.Interface {
getEvent(nameOrSignatureOrTopic: "LockReleased"): EventFragment;
getEvent(nameOrSignatureOrTopic: "LockReturned"): EventFragment;
getEvent(nameOrSignatureOrTopic: "ReputationUpdated"): EventFragment;
getEvent(nameOrSignatureOrTopic: "RootUpdated"): EventFragment;
getEvent(nameOrSignatureOrTopic: "ValidSignersUpdated"): EventFragment;
}
@@ -159,6 +161,17 @@ export type ReputationUpdatedEvent = TypedEvent<
export type ReputationUpdatedEventFilter =
TypedEventFilter<ReputationUpdatedEvent>;
export interface RootUpdatedEventObject {
seller: string;
merkleRoot: string;
}
export type RootUpdatedEvent = TypedEvent<
[string, string],
RootUpdatedEventObject
>;
export type RootUpdatedEventFilter = TypedEventFilter<RootUpdatedEvent>;
export interface ValidSignersUpdatedEventObject {
signers: string[];
}
@@ -288,6 +301,12 @@ export interface EventAndErrors extends BaseContract {
): ReputationUpdatedEventFilter;
ReputationUpdated(reputation?: null): ReputationUpdatedEventFilter;
"RootUpdated(address,bytes32)"(
seller?: null,
merkleRoot?: null
): RootUpdatedEventFilter;
RootUpdated(seller?: null, merkleRoot?: null): RootUpdatedEventFilter;
"ValidSignersUpdated(address[])"(
signers?: null
): ValidSignersUpdatedEventFilter;
@@ -293,6 +293,25 @@ const _abi = [
name: "ReputationUpdated",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "seller",
type: "address",
},
{
indexed: false,
internalType: "bytes32",
name: "merkleRoot",
type: "bytes32",
},
],
name: "RootUpdated",
type: "event",
},
{
anonymous: false,
inputs: [
@@ -352,6 +352,25 @@ const _abi = [
name: "ReputationUpdated",
type: "event",
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "address",
name: "seller",
type: "address",
},
{
indexed: false,
internalType: "bytes32",
name: "merkleRoot",
type: "bytes32",
},
],
name: "RootUpdated",
type: "event",
},
{
anonymous: false,
inputs: [
@@ -867,7 +886,7 @@ const _abi = [
];
const _bytecode =
"0x60806040526001805560405162002825380380620028258339810160408190526200002a916200049d565b600080546001600160a01b031916339081178255604051909182917f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d76908290a3506200007685620000a3565b620000818362000133565b6200008c84620001bd565b620000988282620002a1565b505050505062000620565b6000546001600160a01b03163314620000f25760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b806004557f70fa43ca70216ad905ade86b9e650a691b2ce5a01980d0a81bdd8324141b8511816040516200012891815260200190565b60405180910390a150565b6000546001600160a01b031633146200017e5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b60028190556040516001600160a01b03821681527fe127cf589a3879da0156d4a24f43b44f65cfa3570de594806b0bfa2fcf06884f9060200162000128565b6000546001600160a01b03163314620002085760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b80516000905b808210156200026e57600062000246848481518110620002325762000232620005bb565b60200260200101516200038760201b60201c565b6000908152600660205260409020805460ff191660019081179091559290920191506200020e565b50507f14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d781604051620001289190620005d1565b6000546001600160a01b03163314620002ec5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b815180620003025763df9578836000526004601cfd5b81518114620003195763ff633a386000526004601cfd5b60208301602083016020830282015b8083146200037f578251600052600b60205260406000208251815550815183517f5d6e86e5341d57a92c49934296c51542a25015c9b1782a1c2722a940131c3d9a600080a360208301925060208201915062000328565b505050505050565b600c1b611000600160ac1b031690565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715620003d857620003d862000397565b604052919050565b60006001600160401b03821115620003fc57620003fc62000397565b5060051b60200190565b6001600160a01b03811681146200041c57600080fd5b50565b600082601f8301126200043157600080fd5b815160206200044a6200044483620003e0565b620003ad565b82815260059290921b840181019181810190868411156200046a57600080fd5b8286015b8481101562000492578051620004848162000406565b83529183019183016200046e565b509695505050505050565b600080600080600060a08688031215620004b657600080fd5b8551602080880151919650906001600160401b0380821115620004d857600080fd5b620004e68a838b016200041f565b965060408901519150620004fa8262000406565b6060890151919550808211156200051057600080fd5b6200051e8a838b016200041f565b945060808901519150808211156200053557600080fd5b508701601f810189136200054857600080fd5b8051620005596200044482620003e0565b81815260059190911b8201830190838101908b8311156200057957600080fd5b928401925b82841015620005a95783518015158114620005995760008081fd5b825292840192908401906200057e565b80955050505050509295509295909350565b634e487b7160e01b600052603260045260246000fd5b6020808252825182820181905260009190848201906040850190845b81811015620006145783516001600160a01b031683529284019291840191600101620005ed565b50909695505050505050565b6121f580620006306000396000f3fe60806040526004361061018f5760003560e01c806377cd38a4116100d65780638e2a3d361161007f578063c52164c611610059578063c52164c614610539578063d6e8b97314610559578063f7d0e04b1461057957600080fd5b80638e2a3d36146104c25780639872dbfe146104f357806398a268711461050957600080fd5b80638652b37e116100b05780638652b37e1461044a5780638da5cb5b1461046a5780638e2749d6146104a257600080fd5b806377cd38a4146103dd5780637f94f65d1461040a5780638642b5c31461042a57600080fd5b806336317972116101385780635fd8c710116101125780635fd8c7101461036857806369cc6af41461037d57806372fada5c146103bd57600080fd5b806336317972146102fd5780634b2ae9801461031d578063574983c81461034857600080fd5b806316d722401161016957806316d722401461021d57806329cc7d10146102c65780632dfdf0b5146102e657600080fd5b8063049373201461019b5780630d2a2d44146101db57806313af4035146101fd57600080fd5b3661019657005b600080fd5b3480156101a757600080fd5b506101c86101b6366004611af1565b60056020526000908152604090205481565b6040519081526020015b60405180910390f35b3480156101e757600080fd5b506101fb6101f6366004611bfe565b610599565b005b34801561020957600080fd5b506101fb610218366004611c3b565b61068a565b34801561022957600080fd5b50610282610238366004611af1565b600860205260009081526040902080546001820154600283015460038401546004850154600586015460069096015494959394929391926001600160a01b03918216928216911687565b6040805197885260208801969096529486019390935260608501919091526001600160a01b03908116608085015290811660a08401521660c082015260e0016101d2565b3480156102d257600080fd5b506101c86102e1366004611c58565b61071e565b3480156102f257600080fd5b506003546101c89081565b34801561030957600080fd5b506101fb610318366004611d35565b6108fc565b34801561032957600080fd5b506101c8610338366004611c3b565b600c1b611000600160ac1b031690565b34801561035457600080fd5b506101fb610363366004611af1565b6109bc565b34801561037457600080fd5b506101fb610a3a565b34801561038957600080fd5b506103ad610398Line truncated
"0x608060405260018055604051620027e1380380620027e18339810160408190526200002a916200049d565b600080546001600160a01b031916339081178255604051909182917f8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d76908290a3506200007685620000a3565b620000818362000133565b6200008c84620001bd565b620000988282620002a1565b505050505062000620565b6000546001600160a01b03163314620000f25760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b60448201526064015b60405180910390fd5b806004557f70fa43ca70216ad905ade86b9e650a691b2ce5a01980d0a81bdd8324141b8511816040516200012891815260200190565b60405180910390a150565b6000546001600160a01b031633146200017e5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b60028190556040516001600160a01b03821681527fe127cf589a3879da0156d4a24f43b44f65cfa3570de594806b0bfa2fcf06884f9060200162000128565b6000546001600160a01b03163314620002085760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b80516000905b808210156200026e57600062000246848481518110620002325762000232620005bb565b60200260200101516200038760201b60201c565b6000908152600660205260409020805460ff191660019081179091559290920191506200020e565b50507f14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d781604051620001289190620005d1565b6000546001600160a01b03163314620002ec5760405162461bcd60e51b815260206004820152600c60248201526b15539055551213d49256915160a21b6044820152606401620000e9565b815180620003025763df9578836000526004601cfd5b81518114620003195763ff633a386000526004601cfd5b60208301602083016020830282015b8083146200037f578251600052600b60205260406000208251815550815183517f5d6e86e5341d57a92c49934296c51542a25015c9b1782a1c2722a940131c3d9a600080a360208301925060208201915062000328565b505050505050565b600c1b611000600160ac1b031690565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715620003d857620003d862000397565b604052919050565b60006001600160401b03821115620003fc57620003fc62000397565b5060051b60200190565b6001600160a01b03811681146200041c57600080fd5b50565b600082601f8301126200043157600080fd5b815160206200044a6200044483620003e0565b620003ad565b82815260059290921b840181019181810190868411156200046a57600080fd5b8286015b8481101562000492578051620004848162000406565b83529183019183016200046e565b509695505050505050565b600080600080600060a08688031215620004b657600080fd5b8551602080880151919650906001600160401b0380821115620004d857600080fd5b620004e68a838b016200041f565b965060408901519150620004fa8262000406565b6060890151919550808211156200051057600080fd5b6200051e8a838b016200041f565b945060808901519150808211156200053557600080fd5b508701601f810189136200054857600080fd5b8051620005596200044482620003e0565b81815260059190911b8201830190838101908b8311156200057957600080fd5b928401925b82841015620005a95783518015158114620005995760008081fd5b825292840192908401906200057e565b80955050505050509295509295909350565b634e487b7160e01b600052603260045260246000fd5b6020808252825182820181905260009190848201906040850190845b81811015620006145783516001600160a01b031683529284019291840191600101620005ed565b50909695505050505050565b6121b180620006306000396000f3fe60806040526004361061018f5760003560e01c806377cd38a4116100d65780638e2a3d361161007f578063c52164c611610059578063c52164c614610539578063d6e8b97314610559578063f7d0e04b1461057957600080fd5b80638e2a3d36146104c25780639872dbfe146104f357806398a268711461050957600080fd5b80638652b37e116100b05780638652b37e1461044a5780638da5cb5b1461046a5780638e2749d6146104a257600080fd5b806377cd38a4146103dd5780637f94f65d1461040a5780638642b5c31461042a57600080fd5b806336317972116101385780635fd8c710116101125780635fd8c7101461036857806369cc6af41461037d57806372fada5c146103bd57600080fd5b806336317972146102fd5780634b2ae9801461031d578063574983c81461034857600080fd5b806316d722401161016957806316d722401461021d57806329cc7d10146102c65780632dfdf0b5146102e657600080fd5b8063049373201461019b5780630d2a2d44146101db57806313af4035146101fd57600080fd5b3661019657005b600080fd5b3480156101a757600080fd5b506101c86101b6366004611aad565b60056020526000908152604090205481565b6040519081526020015b60405180910390f35b3480156101e757600080fd5b506101fb6101f6366004611bba565b610599565b005b34801561020957600080fd5b506101fb610218366004611bf7565b61068a565b34801561022957600080fd5b50610282610238366004611aad565b600860205260009081526040902080546001820154600283015460038401546004850154600586015460069096015494959394929391926001600160a01b03918216928216911687565b6040805197885260208801969096529486019390935260608501919091526001600160a01b03908116608085015290811660a08401521660c082015260e0016101d2565b3480156102d257600080fd5b506101c86102e1366004611c14565b61072b565b3480156102f257600080fd5b506003546101c89081565b34801561030957600080fd5b506101fb610318366004611cf1565b610916565b34801561032957600080fd5b506101c8610338366004611bf7565b600c1b611000600160ac1b031690565b34801561035457600080fd5b506101fb610363366004611aad565b6109d6565b34801561037457600080fd5b506101fb610a54565b34801561038957600080fd5b506103ad610398Line truncated
type P2PIXConstructorParams =
| [signer?: Signer]
+19
View File
@@ -276,6 +276,7 @@ export interface P2PIXInterface extends utils.Interface {
"LockReturned(address,bytes32)": EventFragment;
"OwnerUpdated(address,address)": EventFragment;
"ReputationUpdated(address)": EventFragment;
"RootUpdated(address,bytes32)": EventFragment;
"ValidSignersUpdated(address[])": EventFragment;
};
@@ -290,6 +291,7 @@ export interface P2PIXInterface extends utils.Interface {
getEvent(nameOrSignatureOrTopic: "LockReturned"): EventFragment;
getEvent(nameOrSignatureOrTopic: "OwnerUpdated"): EventFragment;
getEvent(nameOrSignatureOrTopic: "ReputationUpdated"): EventFragment;
getEvent(nameOrSignatureOrTopic: "RootUpdated"): EventFragment;
getEvent(nameOrSignatureOrTopic: "ValidSignersUpdated"): EventFragment;
}
@@ -421,6 +423,17 @@ export type ReputationUpdatedEvent = TypedEvent<
export type ReputationUpdatedEventFilter =
TypedEventFilter<ReputationUpdatedEvent>;
export interface RootUpdatedEventObject {
seller: string;
merkleRoot: string;
}
export type RootUpdatedEvent = TypedEvent<
[string, string],
RootUpdatedEventObject
>;
export type RootUpdatedEventFilter = TypedEventFilter<RootUpdatedEvent>;
export interface ValidSignersUpdatedEventObject {
signers: string[];
}
@@ -985,6 +998,12 @@ export interface P2PIX extends BaseContract {
): ReputationUpdatedEventFilter;
ReputationUpdated(reputation?: null): ReputationUpdatedEventFilter;
"RootUpdated(address,bytes32)"(
seller?: null,
merkleRoot?: null
): RootUpdatedEventFilter;
RootUpdated(seller?: null, merkleRoot?: null): RootUpdatedEventFilter;
"ValidSignersUpdated(address[])"(
signers?: null
): ValidSignersUpdatedEventFilter;
+370 -29
View File
@@ -2,13 +2,13 @@ import "@nomicfoundation/hardhat-chai-matchers";
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { BigNumber, Wallet } from "ethers";
import { BigNumber, ContractReceipt, Wallet } from "ethers";
import {
ethers,
network,
/* , tracer */
} from "hardhat";
import keccak256 from "keccak256";
// import keccak256 from "keccak256";
import { MockToken, P2PIX, Reputation } from "../src/types";
import { P2PixErrors } from "./utils/errors";
@@ -595,7 +595,7 @@ describe("P2PIX", () => {
P2PixErrors.AddressDenied,
);
});
it ("should revert if msg.sender does not have enough credit in his spend limit", async () => {
it("should revert if msg.sender does not have enough credit in his spend limit", async () => {
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
erc20.address,
@@ -620,9 +620,246 @@ describe("P2PIX", () => {
P2PixErrors.AmountNotAllowed,
);
});
// it ("should create a lock, update storage and emit events via the allowlist path")
// it ("should create a lock, update storage and emit events via the reputation path")
// it ("should create multiple locks") - EDGE CASE TEST
it("should create a lock, update storage and emit events via the allowlist path", async () => {
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
erc20.address,
price,
"pixTarget",
merkleRoot,
);
const tx = await p2pix
.connect(acc01)
.lock(
0,
acc02.address,
acc03.address,
0,
price,
proof,
[],
);
const lockID = ethers.utils.solidityKeccak256(
["uint256", "uint256", "address"],
[0, price, acc02.address],
);
const storage: Lock = await p2pix.callStatic.mapLocks(
lockID,
);
const rc: ContractReceipt = await tx.wait();
const expiration = rc.blockNumber + 10;
expect(tx).to.be.ok;
expect(storage.depositID).to.eq(0);
expect(storage.relayerPremium).to.eq(
ethers.constants.Zero,
);
expect(storage.amount).to.eq(price);
expect(storage.expirationBlock).to.eq(expiration);
expect(storage.buyerAddress).to.eq(acc02.address);
expect(storage.relayerTarget).to.eq(acc03.address);
expect(storage.relayerAddress).to.eq(acc01.address);
await expect(tx)
.to.emit(p2pix, "LockAdded")
.withArgs(
acc02.address,
lockID,
storage.depositID,
storage.amount,
);
});
it("should create a lock, update storage and emit events via the reputation path", async () => {
const root = ethers.constants.HashZero;
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
erc20.address,
price,
"pixTarget",
root,
);
const tx = await p2pix
.connect(acc01)
.lock(
0,
acc02.address,
acc03.address,
0,
100,
[],
[],
);
const lockID = ethers.utils.solidityKeccak256(
["uint256", "uint256", "address"],
[0, 100, acc02.address],
);
const storage: Lock = await p2pix.callStatic.mapLocks(
lockID,
);
const rc: ContractReceipt = await tx.wait();
const expiration = rc.blockNumber + 10;
expect(tx).to.be.ok;
expect(storage.depositID).to.eq(0);
expect(storage.relayerPremium).to.eq(
ethers.constants.Zero,
);
expect(storage.amount).to.eq(
ethers.BigNumber.from(100),
);
expect(storage.expirationBlock).to.eq(expiration);
expect(storage.buyerAddress).to.eq(acc02.address);
expect(storage.relayerTarget).to.eq(acc03.address);
expect(storage.relayerAddress).to.eq(acc01.address);
await expect(tx)
.to.emit(p2pix, "LockAdded")
.withArgs(
acc02.address,
lockID,
storage.depositID,
storage.amount,
);
});
// edge case test
it("should create multiple locks", async () => {
const newPrice = price.div(ethers.BigNumber.from(2));
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
erc20.address,
price,
"pixTarget",
merkleRoot,
);
const tx1 = await p2pix
.connect(acc01)
.lock(
0,
acc02.address,
acc03.address,
0,
newPrice,
proof,
[],
);
const lockID1 = ethers.utils.solidityKeccak256(
["uint256", "uint256", "address"],
[0, newPrice, acc02.address],
);
const storage1: Lock = await p2pix.callStatic.mapLocks(
lockID1,
);
const rc1: ContractReceipt = await tx1.wait();
const expiration1 = rc1.blockNumber + 10;
const tx2 = await p2pix
.connect(acc01)
.lock(
0,
acc02.address,
acc03.address,
0,
100,
[],
[],
);
const lockID2 = ethers.utils.solidityKeccak256(
["uint256", "uint256", "address"],
[0, 100, acc02.address],
);
const storage2: Lock = await p2pix.callStatic.mapLocks(
lockID2,
);
const rc2: ContractReceipt = await tx2.wait();
const expiration2 = rc2.blockNumber + 10;
const tx3 = await p2pix
.connect(acc03)
.lock(
0,
acc03.address,
acc03.address,
0,
100,
[],
[],
);
const lockID3 = ethers.utils.solidityKeccak256(
["uint256", "uint256", "address"],
[0, 100, acc03.address],
);
const storage3: Lock = await p2pix.callStatic.mapLocks(
lockID3,
);
const rc3: ContractReceipt = await tx3.wait();
const expiration3 = rc3.blockNumber + 10;
expect(tx1).to.be.ok;
expect(tx2).to.be.ok;
expect(tx3).to.be.ok;
expect(0)
.to.eq(storage1.depositID)
.and.to.eq(storage2.depositID)
.and.to.eq(storage3.depositID);
expect(ethers.constants.Zero)
.to.eq(storage1.relayerPremium)
.and.to.eq(storage2.relayerPremium)
.and.to.eq(storage3.relayerPremium);
expect(storage1.amount).to.eq(newPrice);
expect(ethers.BigNumber.from(100))
.to.eq(storage2.amount)
.and.to.eq(storage3.amount);
expect(storage1.expirationBlock).to.eq(expiration1);
expect(storage2.expirationBlock).to.eq(expiration2);
expect(storage3.expirationBlock).to.eq(expiration3);
expect(acc02.address)
.to.eq(storage1.buyerAddress)
.and.to.eq(storage2.buyerAddress);
expect(storage3.buyerAddress).to.eq(acc03.address);
expect(acc03.address)
.to.eq(storage1.relayerTarget)
.and.to.eq(storage2.relayerTarget)
.and.to.eq(storage3.relayerTarget);
expect(acc01.address)
.to.eq(storage1.relayerAddress)
.and.to.eq(storage2.relayerAddress);
expect(storage3.relayerAddress).to.eq(acc03.address);
await expect(tx1)
.to.emit(p2pix, "LockAdded")
.withArgs(
acc02.address,
lockID1,
storage1.depositID,
storage1.amount,
);
await expect(tx2)
.to.emit(p2pix, "LockAdded")
.withArgs(
acc02.address,
lockID2,
storage2.depositID,
storage2.amount,
);
await expect(tx3)
.to.emit(p2pix, "LockAdded")
.withArgs(
acc03.address,
lockID3,
storage3.depositID,
storage3.amount,
);
});
});
describe("Cancel Deposit", async () => {
it("should revert if the msg.sender isn't the deposit's seller", async () => {
@@ -634,7 +871,10 @@ describe("P2PIX", () => {
merkleRoot,
);
const fail = p2pix.connect(acc01).cancelDeposit(0);
await expect(fail).to.be.revertedWithCustomError(p2pix, P2PixErrors.OnlySeller);
await expect(fail).to.be.revertedWithCustomError(
p2pix,
P2PixErrors.OnlySeller,
);
});
it("should cancel deposit, update storage and emit events", async () => {
await erc20.approve(p2pix.address, price);
@@ -644,12 +884,16 @@ describe("P2PIX", () => {
"pixTarget",
merkleRoot,
);
const state1:Deposit = await p2pix.callStatic.mapDeposits(0);
const state1: Deposit =
await p2pix.callStatic.mapDeposits(0);
const tx = await p2pix.cancelDeposit(0);
const state2:Deposit = await p2pix.callStatic.mapDeposits(0);
const state2: Deposit =
await p2pix.callStatic.mapDeposits(0);
expect(tx).to.be.ok;
await expect(tx).to.emit(p2pix, "DepositClosed").withArgs(owner.address, 0);
await expect(tx)
.to.emit(p2pix, "DepositClosed")
.withArgs(owner.address, 0);
expect(state1.valid).to.be.true;
expect(state2.valid).to.be.false;
});
@@ -675,22 +919,34 @@ describe("P2PIX", () => {
"pixTarget",
ethers.constants.HashZero,
);
const oldState1:Deposit = await p2pix.callStatic.mapDeposits(0);
const oldState2:Deposit = await p2pix.callStatic.mapDeposits(1);
const oldState3:Deposit = await p2pix.callStatic.mapDeposits(2);
const oldState1: Deposit =
await p2pix.callStatic.mapDeposits(0);
const oldState2: Deposit =
await p2pix.callStatic.mapDeposits(1);
const oldState3: Deposit =
await p2pix.callStatic.mapDeposits(2);
const tx1 = await p2pix.cancelDeposit(0);
const tx2 = await p2pix.cancelDeposit(1);
const tx3 = await p2pix.cancelDeposit(2);
const newState1:Deposit = await p2pix.callStatic.mapDeposits(0);
const newState2:Deposit = await p2pix.callStatic.mapDeposits(1);
const newState3:Deposit = await p2pix.callStatic.mapDeposits(2);
const newState1: Deposit =
await p2pix.callStatic.mapDeposits(0);
const newState2: Deposit =
await p2pix.callStatic.mapDeposits(1);
const newState3: Deposit =
await p2pix.callStatic.mapDeposits(2);
expect(tx1).to.be.ok;
expect(tx2).to.be.ok;
expect(tx3).to.be.ok;
await expect(tx1).to.emit(p2pix, "DepositClosed").withArgs(owner.address, 0);
await expect(tx2).to.emit(p2pix, "DepositClosed").withArgs(owner.address, 1);
await expect(tx3).to.emit(p2pix, "DepositClosed").withArgs(owner.address, 2);
await expect(tx1)
.to.emit(p2pix, "DepositClosed")
.withArgs(owner.address, 0);
await expect(tx2)
.to.emit(p2pix, "DepositClosed")
.withArgs(owner.address, 1);
await expect(tx3)
.to.emit(p2pix, "DepositClosed")
.withArgs(owner.address, 2);
expect(oldState1.valid).to.be.true;
expect(oldState2.valid).to.be.true;
expect(oldState3.valid).to.be.true;
@@ -712,19 +968,104 @@ describe("P2PIX", () => {
// )}
});
describe("Unexpire Locks", async () => {
// it("should revert if lock isn't expired")
// it("should unlock expired locks, update storage and emit events")
// CHECK FOR userRecord STORAGE UPDATE
// test method through lock fx
// test method through withdraw fx
it("should revert if lock isn't expired", async () => {
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
erc20.address,
price,
"pixTarget",
merkleRoot,
);
await p2pix
.connect(acc02)
.lock(0, acc02.address, acc03.address, 0, 1, [], []);
const lockID = ethers.utils.solidityKeccak256(
["uint256", "uint256", "address"],
[0, 1, acc02.address],
);
const fail = p2pix.unlockExpired([lockID]);
await expect(fail).to.be.revertedWithCustomError(
p2pix,
P2PixErrors.NotExpired,
);
});
it("should unlock expired locks, update storage and emit events", async () => {
// CHECK FOR userRecord STORAGE UPDATE
// test method through lock fx
// test method through withdraw fx
});
});
describe("Seller Withdraw", async () => {
// it("should revert if the msg.sender isn't the deposit's seller")
// it -> withdraw remaining funds from deposit
it("should revert if the msg.sender isn't the deposit's seller", async () => {
await erc20.approve(p2pix.address, price);
await p2pix.deposit(
erc20.address,
price,
"pixTarget",
merkleRoot,
);
const fail = p2pix.connect(acc02).withdraw(0, []);
await expect(fail).to.be.revertedWithCustomError(
p2pix,
P2PixErrors.OnlySeller,
);
});
it("should withdraw remaining funds from deposit, update storage and emit event", async () => {
await erc20.approve(p2pix.address, price);
const dep = await p2pix.deposit(
erc20.address,
price,
"pixTarget",
merkleRoot,
);
const tx = await p2pix.withdraw(0, []);
expect(tx).to.be.ok;
await expect(dep)
.to.changeTokenBalance(
erc20,
owner.address,
"-100000000000000000000",
)
.and.to.changeTokenBalance(
erc20,
p2pix.address,
price,
);
await expect(tx)
.to.changeTokenBalance(erc20, owner.address, price)
.and.to.changeTokenBalance(
erc20,
p2pix.address,
"-100000000000000000000",
);
await expect(tx)
.to.emit(p2pix, "DepositWithdrawn")
.withArgs(owner.address, 0, price);
});
});
describe("Allowlist Settings", async () => {
// it -> set root of seller's allowlist
// (test msg.sender != seller error)
// i.e., set it in the fixture
it(" should revert if the msg.sender differs from deposit's seller", async () => {
const root = ethers.utils.keccak256(
ethers.utils.toUtf8Bytes("root"),
);
const fail = p2pix.connect(acc02).setRoot(owner.address, root);
await expect(fail).to.be.revertedWithCustomError(p2pix, P2PixErrors.OnlySeller);
});
it("should set root of seller's allowlist, update storage and emit event", async () => {
const ownerKey = await p2pix.callStatic._castAddrToKey(owner.address);
const oldState = await p2pix.callStatic.sellerAllowList(ownerKey);
const tx = await p2pix.connect(owner).setRoot(owner.address, merkleRoot);
const newState = await p2pix.callStatic.sellerAllowList(ownerKey);
expect(tx).to.be.ok;
await expect(tx).to.emit(p2pix, "RootUpdated").withArgs(owner.address, merkleRoot);
expect(oldState).to.eq(ethers.constants.HashZero);
expect(newState).to.eq(merkleRoot);
});
});
});
+10 -5
View File
@@ -11,6 +11,11 @@ import {
} from "../../src/types";
// exported interfaces
export interface Deploys {
signers: string[];
p2pix: string;
token: string;
}
export interface Deposit {
remaining: BigNumber;
@@ -21,10 +26,10 @@ export interface Deposit {
}
export interface Lock {
depositID: string;
relayerPremium: string;
amount: string;
expirationBlock: string;
depositID: BigNumber;
relayerPremium: BigNumber;
amount: BigNumber;
expirationBlock: BigNumber;
buyerAddress: string;
relayerTarget: string;
relayerAddress: string;
@@ -130,7 +135,7 @@ export async function p2pixFixture(): Promise<P2PixAndReputation> {
});
const merkleRoot: string = tree.getHexRoot();
const proof: string[] = tree.getHexProof(
padBuffer(whitelisted[0].address),
padBuffer(whitelisted[1].address),
);
return {
+11 -10
View File
@@ -3495,6 +3495,16 @@ __metadata:
languageName: node
linkType: hard
"chalk@npm:4.x, chalk@npm:^4.1.1":
version: 4.1.2
resolution: "chalk@npm:4.1.2"
dependencies:
ansi-styles: ^4.1.0
supports-color: ^7.1.0
checksum: fe75c9d5c76a7a98d45495b91b2172fa3b7a09e0cc9370e5c8feb1c567b85c4288e2b3fded7cfdd7359ac28d6b3844feb8b82b8686842e93d23c827c417e83fc
languageName: node
linkType: hard
"chalk@npm:^2.0.0, chalk@npm:^2.1.0, chalk@npm:^2.4.1, chalk@npm:^2.4.2":
version: 2.4.2
resolution: "chalk@npm:2.4.2"
@@ -3516,16 +3526,6 @@ __metadata:
languageName: node
linkType: hard
"chalk@npm:^4.1.1":
version: 4.1.2
resolution: "chalk@npm:4.1.2"
dependencies:
ansi-styles: ^4.1.0
supports-color: ^7.1.0
checksum: fe75c9d5c76a7a98d45495b91b2172fa3b7a09e0cc9370e5c8feb1c567b85c4288e2b3fded7cfdd7359ac28d6b3844feb8b82b8686842e93d23c827c417e83fc
languageName: node
linkType: hard
"chardet@npm:^0.7.0":
version: 0.7.0
resolution: "chardet@npm:0.7.0"
@@ -8448,6 +8448,7 @@ fsevents@~2.1.1:
"@typescript-eslint/eslint-plugin": ^5.42.0
"@typescript-eslint/parser": ^5.42.0
chai: ^4.3.6
chalk: 4.x
commitizen: ^4.2.5
cross-env: ^7.0.3
cz-conventional-changelog: ^3.3.0