Replace deposit prices for ETH premium.

This commit is contained in:
Filipe Soccol committed 2022-11-09 16:29:27 -03:00
1 parent 1892e0bd9b
commit d57fbde4c0
5 files changed
+126 -101

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
{
"_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/7e909668316aeda4fb9591ef4393e389.json"
"buildInfo": "../../build-info/fa666dddb19de15d02d4eaf695a7b974.json"
}
+82 -52
View File
@@ -43,7 +43,7 @@
{
"indexed": false,
"internalType": "uint256",
"name": "price",
"name": "premium",
"type": "uint256"
},
{
@@ -75,25 +75,6 @@
"name": "DepositClosed",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "bytes32",
"name": "depositID",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "uint256",
"name": "price",
"type": "uint256"
}
],
"name": "DepositPriceChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
@@ -145,12 +126,6 @@
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "locked",
"type": "uint256"
}
],
"name": "LockAdded",
@@ -194,6 +169,44 @@
"name": "LockReturned",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "owner",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "PremiumsWithdrawn",
"type": "event"
},
{
"inputs": [
{
@@ -207,24 +220,6 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "depositID",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "price",
"type": "uint256"
}
],
"name": "changeDepositPrice",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "defaultLockBlocks",
@@ -250,11 +245,6 @@
"name": "amount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "price",
"type": "uint256"
},
{
"internalType": "string",
"name": "pixTarget",
@@ -269,7 +259,7 @@
"type": "bytes32"
}
],
"stateMutability": "nonpayable",
"stateMutability": "payable",
"type": "function"
},
{
@@ -316,6 +306,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
@@ -349,6 +352,26 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
@@ -398,10 +421,17 @@
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "withdrawPremiums",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x60806040523480156200001157600080fd5b50604051620029a5380380620029a583398181016040528101906200003791906200030d565b8160008190555060005b81518160ff161015620000db576001806000848460ff16815181106200006c576200006b62000373565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080620000d290620003de565b91505062000041565b5050506200040c565b6000604051905090565b600080fd5b600080fd5b6000819050919050565b6200010d81620000f8565b81146200011957600080fd5b50565b6000815190506200012d8162000102565b92915050565b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b620001838262000138565b810181811067ffffffffffffffff82111715620001a557620001a462000149565b5b80604052505050565b6000620001ba620000e4565b9050620001c8828262000178565b919050565b600067ffffffffffffffff821115620001eb57620001ea62000149565b5b602082029050602081019050919050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006200022e8262000201565b9050919050565b620002408162000221565b81146200024c57600080fd5b50565b600081519050620002608162000235565b92915050565b60006200027d6200027784620001cd565b620001ae565b90508083825260208201905060208402830185811115620002a357620002a2620001fc565b5b835b81811015620002d05780620002bb88826200024f565b845260208401935050602081019050620002a5565b5050509392505050565b600082601f830112620002f257620002f162000133565b5b81516200030484826020860162000266565b91505092915050565b60008060408385031215620003275762000326620000ee565b5b600062000337858286016200011c565b925050602083015167ffffffffffffffff8111156200035b576200035a620000f3565b5b6200036985828601620002da565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600060ff82169050919050565b6000620003eb82620003d1565b915060ff8203620004015762000400620003a2565b5b600182019050919050565b612589806200041c6000396000f3fe608060405234801561001057600080fd5b50600436106100935760003560e01c8063708ace6511610066578063708ace651461011c5780638e2749d61461014c5780639872dbfe14610168578063b93bd7d414610186578063e33f7291146101b657610093565b806331404484146100985780633a8cbc38146100b45780634b83a7be146100e45780634e1389ed14610100575b600080fd5b6100b260048036038101906100ad9190611264565b6101d2565b005b6100ce60048036038101906100c9919061138a565b61032e565b6040516100db9190611421565b60405180910390f35b6100fe60048036038101906100f99190611492565b610639565b005b61011a6004803603810190610115919061152b565b61085c565b005b610136600480360381019061013191906115a6565b610cee565b6040516101439190611421565b60405180910390f35b61016660048036038101906101619190611655565b611018565b005b6101706111a1565b60405161017d91906116b1565b60405180910390f35b6101a0600480360381019061019b91906116cc565b6111a7565b6040516101ad9190611714565b60405180910390f35b6101d060048036038101906101cb919061172f565b6111c7565b005b803373ffffffffffffffffffffffffffffffffffffffff166002600083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610277576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161026e906117f2565b60405180910390fd5b60006002600084815260200190815260200160002060040160006101000a81548160ff0219169083151502179055506002600083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f81a84d666c6a692c1cf93ca3b3648cc7bf23d34a1c6afa2e15e346f424baa06c836040516103229190611421565b60405180910390a25050565b600082828660405160200161034593929190611872565b6040516020818303038152906040528051906020012090506002600082815260200190815260200160002060040160009054906101000a900460ff16156103c1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103b89061190e565b60405180910390fd5b60008690508073ffffffffffffffffffffffffffffffffffffffff166323b872dd3330896040518463ffffffff1660e01b81526004016104039392919061193d565b6020604051808303816000875af1158015610422573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061044691906119a0565b5060006040518060c001604052803373ffffffffffffffffffffffffffffffffffffffff1681526020018973ffffffffffffffffffffffffffffffffffffffff16815260200188815260200187815260200160011515815260200186868080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050508152509050806002600085815260200190815260200160002060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506040820151816002015560608201518160Line truncated
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100935760003560e01c8063708ace6511610066578063708ace651461011c5780638e2749d61461014c5780639872dbfe14610168578063b93bd7d414610186578063e33f7291146101b657610093565b806331404484146100985780633a8cbc38146100b45780634b83a7be146100e45780634e1389ed14610100575b600080fd5b6100b260048036038101906100ad9190611264565b6101d2565b005b6100ce60048036038101906100c9919061138a565b61032e565b6040516100db9190611421565b60405180910390f35b6100fe60048036038101906100f99190611492565b610639565b005b61011a6004803603810190610115919061152b565b61085c565b005b610136600480360381019061013191906115a6565b610cee565b6040516101439190611421565b60405180910390f35b61016660048036038101906101619190611655565b611018565b005b6101706111a1565b60405161017d91906116b1565b60405180910390f35b6101a0600480360381019061019b91906116cc565b6111a7565b6040516101ad9190611714565b60405180910390f35b6101d060048036038101906101cb919061172f565b6111c7565b005b803373ffffffffffffffffffffffffffffffffffffffff166002600083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610277576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161026e906117f2565b60405180910390fd5b60006002600084815260200190815260200160002060040160006101000a81548160ff0219169083151502179055506002600083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f81a84d666c6a692c1cf93ca3b3648cc7bf23d34a1c6afa2e15e346f424baa06c836040516103229190611421565b60405180910390a25050565b600082828660405160200161034593929190611872565b6040516020818303038152906040528051906020012090506002600082815260200190815260200160002060040160009054906101000a900460ff16156103c1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103b89061190e565b60405180910390fd5b60008690508073ffffffffffffffffffffffffffffffffffffffff166323b872dd3330896040518463ffffffff1660e01b81526004016104039392919061193d565b6020604051808303816000875af1158015610422573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061044691906119a0565b5060006040518060c001604052803373ffffffffffffffffffffffffffffffffffffffff1681526020018973ffffffffffffffffffffffffffffffffffffffff16815260200188815260200187815260200160011515815260200186868080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050508152509050806002600085815260200190815260200160002060008201518160000160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550604082015181600201556060820151816003015560808201518160040160006101000a81548160ff02191690831515021790555060a08201518160050190816105d69190611c13565b509050503373ffffffffffffffffffffffffffffffffffffffff167fb2d817df1a92003b7e8b40681145547601989b987e206c6f7d0bc46369652913848a898b6040516106269493929190611ce5565b60405180910390a2505095945050505050565b823373ffffffffffffffffffffffffffffffffffffffff166002600083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146106de576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106d5906117f2565b60405180910390fd5b6106e88383611018565b60006002600086815260200190815260200160002090508060040160009054906101000a900460ff16156107205761071f856101d2565b5b60008160010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508073ffffffffffffffffffffffffffffffffffffffff1663a9059cbb8360000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1684600201546040518363ffffffff1660e01b81526004016107ac929190611d2a565b6020604051808303816000875af11580156107cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107ef91906119a0565b50600082600201549050600083600201819055503373ffffffffffffffffffffffffffffffffffffffff167fbc44d79619424e05dd4e8ea6a3e67823f43e45cf0c9b52463ec7a8806146991d888360405161084b929190611d53565b60405180910390a250505050505050565b600060036000878152602001908152602001600020905043816006015411801561088a575060008160050154115b6108c9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108c090611dee565b60405180910390fd5b6000600260008360000154815260200190815260200160002090506000600260008460000154815260200190815260200160002060050183600401548860405160200161091893929190611e91565b6040516020818303038152906040528051906020012090506000816040516020016109439190611f37565b6040516020818303038152906040528051906020012090506004600083815260200190815260200160002060009054906101000a900460ff16156109bc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109b390611fcf565b604051Line truncated
"bytecode": "0x60806040523480156200001157600080fd5b5060405162002d5538038062002d558339818101604052810190620000379190620003fa565b620000576200004b6200010560201b60201c565b6200010d60201b60201c565b8160018190555060005b81518160ff161015620000fc57600160026000848460ff16815181106200008d576200008c62000460565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080620000f390620004cb565b91505062000061565b505050620004f9565b600033905090565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b6000604051905090565b600080fd5b600080fd5b6000819050919050565b620001fa81620001e5565b81146200020657600080fd5b50565b6000815190506200021a81620001ef565b92915050565b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b620002708262000225565b810181811067ffffffffffffffff8211171562000292576200029162000236565b5b80604052505050565b6000620002a7620001d1565b9050620002b5828262000265565b919050565b600067ffffffffffffffff821115620002d857620002d762000236565b5b602082029050602081019050919050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006200031b82620002ee565b9050919050565b6200032d816200030e565b81146200033957600080fd5b50565b6000815190506200034d8162000322565b92915050565b60006200036a6200036484620002ba565b6200029b565b9050808382526020820190506020840283018581111562000390576200038f620002e9565b5b835b81811015620003bd5780620003a888826200033c565b84526020840193505060208101905062000392565b5050509392505050565b600082601f830112620003df57620003de62000220565b5b8151620003f184826020860162000353565b91505092915050565b60008060408385031215620004145762000413620001db565b5b6000620004248582860162000209565b925050602083015167ffffffffffffffff811115620004485762000447620001e0565b5b6200045685828601620003c7565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600060ff82169050919050565b6000620004d882620004be565b915060ff8203620004ee57620004ed6200048f565b5b600182019050919050565b61284c80620005096000396000f3fe6080604052600436106100a75760003560e01c80638da5cb5b116100645780638da5cb5b146101925780638e2749d6146101bd5780639872dbfe146101e6578063b93bd7d414610211578063bfe07da61461024e578063f2fde38b1461027e576100a7565b806331404484146100ac5780634b83a7be146100d55780634e1389ed146100fe5780636193cdfb14610127578063708ace651461013e578063715018a61461017b575b600080fd5b3480156100b857600080fd5b506100d360048036038101906100ce919061153b565b6102a7565b005b3480156100e157600080fd5b506100fc60048036038101906100f791906115cd565b610403565b005b34801561010a57600080fd5b506101256004803603810190610120919061169c565b610626565b005b34801561013357600080fd5b5061013c610ab8565b005b34801561014a57600080fd5b5061016560048036038101906101609190611775565b610b48565b6040516101729190611833565b60405180910390f35b34801561018757600080fd5b50610190610e38565b005b34801561019e57600080fd5b506101a7610e4c565b6040516101b4919061185d565b60405180910390f35b3480156101c957600080fd5b506101e460048036038101906101df9190611878565b610e75565b005b3480156101f257600080fd5b506101fb610ffe565b60405161020891906118d4565b60405180910390f35b34801561021d57600080fd5b50610238600480360381019061023391906118ef565b611004565b6040516102459190611937565b60405180910390f35b610268600480360381019061026391906119a8565b611024565b6040516102759190611833565b60405180910390f35b34801561028a57600080fd5b506102a560048036038101906102a091906118ef565b61132e565b005b803373ffffffffffffffffffffffffffffffffffffffff166003600083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461034c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161034390611a9f565b60405180910390fd5b60006003600084815260200190815260200160002060040160006101000a81548160ff0219169083151502179055506003600083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f81a84d666c6a692c1cf93ca3b3648cc7bf23d34a1c6afa2e15e346f424baa06c836040516103f79190611833565b60405180910390a25050565b823373ffffffffffffffffffffffffffffffffffffffff166003600083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146104a8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161049f90611a9f565b60405180910390fd5b6104b28383610e7556Line truncated
"deployedBytecode": "0x6080604052600436106100a75760003560e01c80638da5cb5b116100645780638da5cb5b146101925780638e2749d6146101bd5780639872dbfe146101e6578063b93bd7d414610211578063bfe07da61461024e578063f2fde38b1461027e576100a7565b806331404484146100ac5780634b83a7be146100d55780634e1389ed146100fe5780636193cdfb14610127578063708ace651461013e578063715018a61461017b575b600080fd5b3480156100b857600080fd5b506100d360048036038101906100ce919061153b565b6102a7565b005b3480156100e157600080fd5b506100fc60048036038101906100f791906115cd565b610403565b005b34801561010a57600080fd5b506101256004803603810190610120919061169c565b610626565b005b34801561013357600080fd5b5061013c610ab8565b005b34801561014a57600080fd5b5061016560048036038101906101609190611775565b610b48565b6040516101729190611833565b60405180910390f35b34801561018757600080fd5b50610190610e38565b005b34801561019e57600080fd5b506101a7610e4c565b6040516101b4919061185d565b60405180910390f35b3480156101c957600080fd5b506101e460048036038101906101df9190611878565b610e75565b005b3480156101f257600080fd5b506101fb610ffe565b60405161020891906118d4565b60405180910390f35b34801561021d57600080fd5b50610238600480360381019061023391906118ef565b611004565b6040516102459190611937565b60405180910390f35b610268600480360381019061026391906119a8565b611024565b6040516102759190611833565b60405180910390f35b34801561028a57600080fd5b506102a560048036038101906102a091906118ef565b61132e565b005b803373ffffffffffffffffffffffffffffffffffffffff166003600083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461034c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161034390611a9f565b60405180910390fd5b60006003600084815260200190815260200160002060040160006101000a81548160ff0219169083151502179055506003600083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167f81a84d666c6a692c1cf93ca3b3648cc7bf23d34a1c6afa2e15e346f424baa06c836040516103f79190611833565b60405180910390a25050565b823373ffffffffffffffffffffffffffffffffffffffff166003600083815260200190815260200160002060000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146104a8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161049f90611a9f565b60405180910390fd5b6104b28383610e75565b60006003600086815260200190815260200160002090508060040160009054906101000a900460ff16156104ea576104e9856102a7565b5b60008160010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508073ffffffffffffffffffffffffffffffffffffffff1663a9059cbb8360000160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1684600201546040518363ffffffff1660e01b8152600401610576929190611abf565b6020604051808303816000875af1158015610595573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105b99190611b14565b50600082600201549050600083600201819055503373ffffffffffffffffffffffffffffffffffffffff167fbc44d79619424e05dd4e8ea6a3e67823f43e45cf0c9b52463ec7a8806146991d8883604051610615929190611b41565b60405180910390a250505050505050565b6000600460008781526020019081526020016000209050438160050154118015610654575060008160040154115b610693576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161068a90611bdc565b60405180910390fd5b600060036000836000015481526020019081526020016000209050600060036000846000015481526020019081526020016000206005018360040154886040516020016106e293929190611d20565b60405160208183030381529060405280519060200120905060008160405160200161070d9190611dc6565b6040516020818303038152906040528051906020012090506005600083815260200190815260200160002060009054906101000a900460ff1615610786576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161077d90611e5e565b60405180910390fd5b6000600182878a8a604051600081526020016040526040516107ab9493929190611e8d565b6020604051602081039080840390855afa1580156107cd573d6000803e3d6000fd5b505050602060405103519050600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610865576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161085c90611f44565b60405180910390fd5b60008460010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508073ffffffffffffffffffffffffffffffffffffffff1663a9059cbb8760010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16886003015489600401546108e39190611f93565b6040518363ffffffff1660e01b8152600401610900929190611abf565b6020604051808303816000875af115801561091f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109439190611b14565b506000866003015411156109f9578073ffffffffffffffffffffffffffffffffffffffff1663a9059cbb8760020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1688600301546040518363ffffffff1660e01b81526004016109b4929190611abf565b6020Line truncated
"linkReferences": {},
"deployedLinkReferences": {}
}
+27 -29
View File
@@ -2,22 +2,24 @@
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract P2PIX {
contract P2PIX is Ownable {
event DepositAdded(address indexed seller, bytes32 depositID, address token, uint256 price, uint256 amount);
event DepositAdded(address indexed seller, bytes32 depositID, address token, uint256 premium, uint256 amount);
event DepositClosed(address indexed seller, bytes32 depositID);
event DepositWithdrawn(address indexed seller, bytes32 depositID, uint256 amount);
event DepositPriceChanged(bytes32 indexed depositID, uint256 price);
event LockAdded(address indexed buyer, bytes32 indexed lockID, bytes32 depositID, uint256 amount, uint256 locked);
event LockAdded(address indexed buyer, bytes32 indexed lockID, bytes32 depositID, uint256 amount);
event LockReleased(address indexed buyer, bytes32 lockId);
event LockReturned(address indexed buyer, bytes32 lockId);
// Events
event PremiumsWithdrawn(address owner, uint256 amount);
struct Deposit {
address seller;
address token; // ERC20 stable token address
uint256 remaining; // Remaining tokens available
uint256 price; // Price in R$ per token
uint256 premium; // Premium paid in ETH for priority
bool valid; // Could be invalidated by the seller
string pixTarget; // The PIX account for the seller receive transactions
}
@@ -28,7 +30,6 @@ contract P2PIX {
address relayerAddress; // Relayer address that facilitated this transaction
uint256 relayerPremium; // Amount to be paid for relayer
uint256 amount; // Amount to be tranfered via PIX
uint256 locked; // Amount locked in tokens from deposit
uint256 expirationBlock; // If not paid at this block will be expired
}
@@ -49,7 +50,7 @@ contract P2PIX {
_;
}
constructor (uint256 defaultBlocks, address[] memory validSigners) {
constructor (uint256 defaultBlocks, address[] memory validSigners) Ownable() {
defaultLockBlocks = defaultBlocks;
for (uint8 i = 0; i < validSigners.length; i++){
validBacenSigners[validSigners[i]] = true;
@@ -60,16 +61,15 @@ contract P2PIX {
function deposit(
address token,
uint256 amount,
uint256 price,
string calldata pixTarget
) public returns (bytes32 depositID){
) public payable returns (bytes32 depositID){
depositID = keccak256(abi.encodePacked(pixTarget, amount));
require(!mapDeposits[depositID].valid, 'P2PIX: Deposit already exist and it is still valid');
IERC20 t = IERC20(token);
t.transferFrom(msg.sender, address(this), amount);
Deposit memory d = Deposit(msg.sender, token, amount, price, true, pixTarget);
Deposit memory d = Deposit(msg.sender, token, amount, msg.value, true, pixTarget);
mapDeposits[depositID] = d;
emit DepositAdded(msg.sender, depositID, token, price, amount);
emit DepositAdded(msg.sender, depositID, token, msg.value, amount);
}
// Vendedor pode invalidar da ordem de venda impedindo novos locks na mesma (isso não afeta nenhum lock que esteja ativo).
@@ -95,8 +95,7 @@ contract P2PIX {
unlockExpired(expiredLocks);
Deposit storage d = mapDeposits[depositID];
require(d.valid, "P2PIX: Deposit not valid anymore");
uint256 toLock = (amount * 1 ether) / d.price;
require(d.remaining >= toLock, "P2PIX: Not enough token remaining on deposit");
require(d.remaining >= amount, "P2PIX: Not enough token remaining on deposit");
lockID = keccak256(abi.encodePacked(depositID, amount, targetAddress));
require(
mapLocks[lockID].expirationBlock < block.number,
@@ -108,12 +107,11 @@ contract P2PIX {
relayerAddress,
relayerPremium,
amount,
toLock,
block.number+defaultLockBlocks
);
mapLocks[lockID] = l;
d.remaining -= toLock;
emit LockAdded(targetAddress, lockID, depositID, amount, toLock);
d.remaining -= amount;
emit LockAdded(targetAddress, lockID, depositID, amount);
}
// Relayer interage com o smart contract, colocando no calldata o comprovante do PIX realizado.
@@ -127,7 +125,7 @@ contract P2PIX {
) public {
// TODO **Prevenir que um Pix não relacionado ao APP seja usado pois tem o mesmo destino
Lock storage l = mapLocks[lockID];
require(l.expirationBlock > block.number && l.locked > 0, "P2PIX: Lock already released or returned");
require(l.expirationBlock > block.number && l.amount > 0, "P2PIX: Lock already released or returned");
Deposit storage d = mapDeposits[l.depositID];
bytes32 message = keccak256(abi.encodePacked(
mapDeposits[l.depositID].pixTarget,
@@ -139,29 +137,22 @@ contract P2PIX {
address signer = ecrecover(messageDigest, v, r, s);
require(validBacenSigners[signer], "P2PIX: Signer is not a valid signer");
IERC20 t = IERC20(d.token);
t.transfer(l.targetAddress, l.locked-l.relayerPremium);
t.transfer(l.targetAddress, l.amount-l.relayerPremium);
if (l.relayerPremium > 0) t.transfer(l.relayerAddress, l.relayerPremium);
l.locked = 0;
l.amount = 0;
l.expirationBlock = 0;
usedTransactions[message] = true;
emit LockReleased(l.targetAddress, lockID);
}
// Change price for deposit amount
function changeDepositPrice(bytes32 depositID, uint256 price) public onlySeller(depositID) {
Deposit storage d = mapDeposits[depositID];
d.price = price;
emit DepositPriceChanged(depositID, price);
}
// Unlock expired locks
function unlockExpired(bytes32[] calldata lockIDs) public {
uint256 locksSize = lockIDs.length;
for (uint16 i = 0; i < locksSize; i++){
Lock storage l = mapLocks[lockIDs[i]];
require(l.expirationBlock < block.number && l.locked > 0, "P2PIX: Lock not expired or already released");
mapDeposits[l.depositID].remaining += l.locked;
l.locked = 0;
require(l.expirationBlock < block.number && l.amount > 0, "P2PIX: Lock not expired or already released");
mapDeposits[l.depositID].remaining += l.amount;
l.amount = 0;
emit LockReturned(l.targetAddress, lockIDs[i]);
}
}
@@ -182,4 +173,11 @@ contract P2PIX {
emit DepositWithdrawn(msg.sender, depositID, amount);
}
// O dono do contrato pode sacar os premiums pagos
function withdrawPremiums() external onlyOwner {
uint256 balance = address(this).balance;
payable(msg.sender).transfer(balance);
emit PremiumsWithdrawn(msg.sender, balance);
}
}
+8 -8
View File
@@ -40,15 +40,15 @@ describe("P2PIX deposit test", function () {
transaction = await p2pix.deposit(
erc20.address,
ethers.utils.parseEther('1000'),
ethers.utils.parseEther('0.99'),
'SELLER PIX KEY'
'SELLER PIX KEY',
{value:ethers.utils.parseEther('0.1')}
);
depositID = ethers.utils.solidityKeccak256(['string', 'uint256'], ['SELLER PIX KEY', ethers.utils.parseEther('1000')])
await expect(transaction).to.emit(p2pix, 'DepositAdded').withArgs(
owner.address,
depositID,
erc20.address,
ethers.utils.parseEther('0.99'),
ethers.utils.parseEther('0.1'),
ethers.utils.parseEther('1000')
)
})
@@ -57,8 +57,8 @@ describe("P2PIX deposit test", function () {
await expect(p2pix.deposit(
erc20.address,
ethers.utils.parseEther('1000'),
ethers.utils.parseEther('0.99'),
'SELLER PIX KEY'
'SELLER PIX KEY',
{value:ethers.utils.parseEther('0.1')}
))
.to.be.revertedWith('P2PIX: Deposit already exist and it is still valid');
})
@@ -83,15 +83,15 @@ describe("P2PIX deposit test", function () {
transaction = await p2pix.deposit(
erc20.address,
ethers.utils.parseEther('1000'),
ethers.utils.parseEther('0.99'),
'SELLER PIX KEY'
'SELLER PIX KEY',
{value:ethers.utils.parseEther('0.1')}
);
depositID = ethers.utils.solidityKeccak256(['string', 'uint256'], ['SELLER PIX KEY', ethers.utils.parseEther('1000')])
await expect(transaction).to.emit(p2pix, 'DepositAdded').withArgs(
owner.address,
depositID,
erc20.address,
ethers.utils.parseEther('0.99'),
ethers.utils.parseEther('0.1'),
ethers.utils.parseEther('1000')
)
})
+8 -11
View File
@@ -41,15 +41,15 @@ describe("P2PIX lock/release test", function () {
transaction = await p2pix.deposit(
erc20.address,
ethers.utils.parseEther('1000'),
ethers.utils.parseEther('0.99'),
'SELLER PIX KEY'
'SELLER PIX KEY',
{value:ethers.utils.parseEther('0.1')}
);
depositID = ethers.utils.solidityKeccak256(['string', 'uint256'], ['SELLER PIX KEY', ethers.utils.parseEther('1000')])
await expect(transaction).to.emit(p2pix, 'DepositAdded').withArgs(
owner.address,
depositID,
erc20.address,
ethers.utils.parseEther('0.99'),
ethers.utils.parseEther('0.1'),
ethers.utils.parseEther('1000')
)
console.log('GAS USED:', (await transaction.wait()).cumulativeGasUsed.toString())
@@ -73,8 +73,7 @@ describe("P2PIX lock/release test", function () {
wallet3.address,
lockID,
depositID,
ethers.utils.parseEther('100'),
"101010101010101010101"
ethers.utils.parseEther('100')
)
console.log('GAS USED:', (await transaction.wait()).cumulativeGasUsed.toString())
})
@@ -113,7 +112,7 @@ describe("P2PIX lock/release test", function () {
lockID
)
console.log('GAS USED:', (await transaction.wait()).cumulativeGasUsed.toString())
expect(await erc20.balanceOf(wallet3.address)).to.equal("101010101010101010101");
expect(await erc20.balanceOf(wallet3.address)).to.equal(ethers.utils.parseEther('100'));
})
it("Should allow recreate same lock", async function () {
@@ -135,7 +134,6 @@ describe("P2PIX lock/release test", function () {
lockID,
depositID,
ethers.utils.parseEther('100'),
"101010101010101010101"
)
})
@@ -167,7 +165,7 @@ describe("P2PIX lock/release test", function () {
sig.s,
sig.v
)
expect(await erc20.balanceOf(wallet3.address)).to.equal("202020202020202020202");
expect(await erc20.balanceOf(wallet3.address)).to.equal(ethers.utils.parseEther('200'));
})
it("Should prevent release again the lock", async function () {
@@ -195,7 +193,7 @@ describe("P2PIX lock/release test", function () {
wallet3.address,
ethers.constants.AddressZero,
'0',
ethers.utils.parseEther('800'),
ethers.utils.parseEther('900'),
[]
)).to.be.revertedWith('P2PIX: Not enough token remaining on deposit');
})
@@ -218,8 +216,7 @@ describe("P2PIX lock/release test", function () {
wallet3.address,
lockID,
depositID,
ethers.utils.parseEther('100'),
"101010101010101010101"
ethers.utils.parseEther('100')
)
})