p2pix-smart-contracts/docs/p2pix.md

5.1 KiB

Solidity API

P2PIX

lockCounter

uint256 lockCounter

mapLocks

mapping(uint256 => struct DataTypes.Lock) mapLocks

List of Locks.

userRecord

mapping(uint256 => uint256) userRecord

Stores an relayer's last computed credit.

constructor

constructor(uint256 defaultBlocks, address[] validSigners, address _reputation, contract ERC20[] tokens, bool[] tokenStates) public payable

deposit

function deposit(string pixTarget, bytes32 allowlistRoot, contract ERC20 token, uint96 amount, bool valid) public

Creates a deposit order based on a seller's offer of an amount of ERC20 tokens. Seller needs to send his tokens to the P2PIX smart contract.

Function sighash: 0x5e918943

Parameters

Name Type Description
pixTarget string Pix key destination provided by the offer's seller.
allowlistRoot bytes32 Optional allow list merkleRoot update bytes32 value. as the deposit identifier.
token contract ERC20
amount uint96
valid bool

setValidState

function setValidState(contract ERC20 token, bool state) public

Enables seller to invalidate future locks made to his/her token offering order. This function does not affect any ongoing active locks.

Function sighash: 0x6d82d9e0

lock

function lock(address seller, contract ERC20 token, uint80 amount, bytes32[] merkleProof, uint256[] expiredLocks, bool bond) public returns (uint256 lockID)

Public method designed to lock an remaining amount of the deposit order of a seller. Transaction forwarding must leave merkleProof empty; otherwise, the trustedForwarder must be previously added to a seller whitelist. This method can be performed either by:

  • An user allowed via the seller's allowlist;
  • An user with enough userRecord to lock the wished amount; There can only exist a lock per each amount partitioned from the total remaining value. Locks can only be performed in valid orders.

Function sighash: 0xdc43221c

Parameters

Name Type Description
seller address
token contract ERC20
amount uint80 The deposit's remaining amount wished to be locked.
merkleProof bytes32[] Provided as a pass if the msg.sender is in the seller's allowlist; Left empty otherwise;
expiredLocks uint256[] An array of identifiers to be provided so to unexpire locks using this transaction gas push.
bond bool

Return Values

Name Type Description
lockID uint256 The lock identifier.

release

function release(uint256 lockID, bytes32 pixTimestamp, bytes signature) public

Lock release method that liquidate lock orders and distributes relayer fees. This method can be called by any public actor as long the signature provided is valid. relayerPremium gets splitted equaly if relayer addresses differ. If the msg.sender of this method and l.relayerAddress are the same, msg.sender accrues both l.amount and l.relayerPremium as userRecord credit. In case of they differing:

  • lock caller gets accrued with l.amount as userRecord credit;
  • release caller gets accrued with l.relayerPremium as userRecord credit;

Function sighash: 0x11fc7f9a

unlockExpired

function unlockExpired(uint256[] lockIDs) public

Unlocks expired locks. Triggered in the callgraph by both lock and withdraw functions. This method can also have any public actor as its tx.origin. For each successfull unexpired lock recovered, userRecord[_castAddrToKey(l.relayerAddress)] is decreased by half of its value.

Function sighash: 0xb0983d39

withdraw

function withdraw(contract ERC20 token, uint256 amount, uint256[] expiredLocks) public

Seller's expired deposit fund sweeper. A seller may use this method to recover tokens from expired deposits.

Function sighash: 0xfb8c5ef0

setRoot

function setRoot(address addr, bytes32 merkleroot) public

receive

receive() external payable

_addLock

function _addLock(uint256 _bal, struct DataTypes.Lock _l) internal

getBalance

function getBalance(address seller, contract ERC20 token) public view returns (uint256 bal)

getValid

function getValid(address seller, contract ERC20 token) public view returns (bool valid)

getPixTarget

function getPixTarget(address seller, contract ERC20 token) public view returns (bytes32 pixTarget)

getPixTargetString

function getPixTargetString(address seller, contract ERC20 token) public view returns (string pixTarget)

getBalances

function getBalances(address[] sellers, contract ERC20 token) external view returns (uint256[])

getLocksStatus

function getLocksStatus(uint256[] ids) external view returns (uint256[], enum DataTypes.LockStatus[])

External getter that returns the status of a lockIDs array. Call will not revert if provided with an empty array as parameter.

Function sighash: 0x49ef8448