Exchange
This is a smart contract to expand KIP7 that is created with every liquidity pair. The Factory deploys this as new pool creation is requested. Although the Factory actually stores the two tokens of a pair and swapping takes place through it, the Exchange Contract must be called for liquidity to be provided or taken.
Github Link: (Will be updated after official launch)
Contract address after production is deployed (scope link)
Events
Read-Only Functions
State-Changing Functions
event Transfer(address indexed from, address indexed to, uint amount);
- KIP7 Standard
- Event log of Transfer/Mint/Burn
event Approval(address indexed holder, address indexed spender, uint amount);
- KIP7 Standard
- Event log of Approvals
event ChangeMiningRate(uint _mining);
- Event log of mining rate change
event ChangeFee(uint _fee);
- Event log of trading fee rate changes
event UpdateMiningIndex(uint lastMined, uint miningIndex);
- Event log of pairs’ mining index changes
lastMined
: Factory.mined() value at the time index is updatedminingIndex
: pairs’ miningIndex value at the time
event GiveReward(address user, uint amount, uint lastIndex, uint rewardSum);
- Event log of when mined KSP is claimed and distributed
user
: address of the user who claimedamount
: the amount of KSP claimedlastIndex
: index result of the pair of the wallet after claimingrewardSum
: The amount of KSP that has been accrued so far
event ExchangePos(address tokenA, uint amountA, address tokenB, uint amountB);
- Event log of POS transactions
tokenA
: Token address delivered by the useramountA
: the amount of tokens delivered by the usertokenB
: token address received by useramountB
: the amount of tokens received by the user
event ExchangeNeg(address tokenA, uint amountA, address tokenB, uint amountB);
- Event log of NEG transactions
tokenA
: token address delivered by the useramountA
: the amount of tokens delivered by the usertokenB
: token address received by the useramountB
: the amount of tokens received by the user
event AddLiquidity(address user, address tokenA, uint amountA, address tokenB, uint amountB, uint liquidity);
- Event log of liquidity additions
liquidity
: the amount of LP tokens minted due to additional liquidity
event RemoveLiquidity(address user, address tokenA, uint amountA, address tokenB, uint amountB, uint liquidity);
- Event log of liquidity removals
liquidity
: the amount of LP tokens burned due to liquidity removal
- KlaySwap LP
- "KSLP" + " " + symbolA + "-" + symbolB
- 18
- mint/burn depending on liquidity addition/removal
- Number of LP tokens held by each address
- Status of approval to spender for each address
- The factory address where the LP smart contract is deployed
- The first token address composed of the pair
- When KLAY is one part of the pair, tokenA == 0x0
- The second token address composed of the pair
- Transaction fee for the pair
- It is a value between 0 and 100, in units of 0.01%
- 1 == 0.01%, 100 == 1%
- The mining rate of the pair
- It is a value between 0 and 100, in units of 1%
- e.g. If mining is 10, the pair has claim authority for 10% of the quantity mined per block in the factory.
- Factory.mined() value at the last time the pair updated the index
- Index value of the last recorded pair
- mapping(address => uint)
- Stores the index value at the time of last reward for each user
- mapping(address => uint )
- Stores the cumulatively claimed KSP quantity value for each user
function getCurrentPool() public view returns (uint, uint)
- Returns the liquidity quantity of the two assets in the current pool
function estimatePos(address token, uint amount) public view returns (uint)
- When a request is made to sell the amount of the corresponding token through a POS transaction, the expected receiving amount of the opposite token is returned.
function estimateNeg(address token, uint amount) public view returns (uint)
- When a request is made to purchase the amount of the corresponding token through a NEG transaction, the expected payment amount of the opposite token is returned.
function transfer(address _to, uint _value) public returns (bool)
- KIP7 Standard
- Method for KSP token transfer
function transferFrom(address _from, address _to, uint _value) public returns (bool)
- KIP7 Standard
- Method to transfer tokens on behalf of the approved wallet
function approve(address _spender, uint _value) public returns (bool)
- KIP7 Standard
- Method to approve transfer as much as value to the spender
function updateMiningIndex() public
- Method to update the value of the pair contract based on the current Factory.mined() value
- Anyone can call in real time. Even if no one calls it, it calls itself if necessary.
function claimReward() public
- Method that a user calls to claim the claimable KSP that has accumulated for the pair
- When called, KSP is claimed from the Factory and paid to msg.sender
- Even if the method is not called directly, it is automatically called when the LP token balance of the user’s wallet changes.
- When liquidity is added
- When liquidity is removed
- When LP tokens are sent
- When LP tokens are received
function addKlayLiquidity(uint amount) public payable
- Method used to provide liquidity when tokenA is KLAY
- Liquidity of the KLAY
msg.value
and tokenBamount
is provided. - After liquidity is provided, the LP token corresponding to the pool share is minted in the msg.sender wallet.
- If the pair ratio is wrong, as much liquidity as possible is supplied at the current pair ratio, and the remaining tokens are returned to msg.sender.
- If there is claimable KSP when called, the claim proceeds to msg.sender.
addKlayLiquidityWithLimit
function addKlayLiquidityWithLimit(uint amount, uint minAmountA, uint minAmountB) public payable
- Method used to provide liquidity when tokenA is KLAY
- Liquidity of the KLAY
msg.value
and tokenBamount
is provided. - Set the minimum amount of tokenA and tokenB to be used for liquidity supply using minAmountA, minAmountB.
- After liquidity is provided, the LP token corresponding to the pool share is minted in the msg.sender wallet.
- If the pair ratio is wrong, as much liquidity as possible is supplied at the current pair ratio, and the remaining tokens are returned to msg.sender.
- If there is claimable KSP when called, the claim proceeds to msg.sender.
function addKctLiquidity(uint amountA, uint amountB) public
- Method used to provide liquidity when tokenA is KIP7 standard token
- Liquidity of the number of tokenA
amountA
and tokenBamountB
is provided. - After liquidity is provided, the LP token corresponding to the pool share is minted in the msg.sender wallet.
- If the pair ratio is wrong, as much liquidity as possible is supplied at the current pair ratio, and the remaining tokens are returned to msg.sender.
- If there is claimable KSP when called, the claim proceeds to msg.sender.
addKctLiquidityWithLimit
function addKctLiquidityWithLimit(uint amountA, uint amountB, uint minAmountA, uint minAmountB) public
- Method used to provide liquidity when tokenA is KIP7 standard token
- Liquidity of the number of tokenA
amountA
and tokenBamountB
is provided. - Set the minimum amount of tokenA and tokenB to be used for liquidity supply using minAmountA, minAmountB.
- After liquidity is provided, the LP token corresponding to the pool share is minted in the msg.sender wallet.
- If the pair ratio is wrong, as much liquidity as possible is supplied at the current pair ratio, and the remaining tokens are returned to msg.sender.
- If there is claimable KSP when called, the claim proceeds to msg.sender.
function removeLiquidity(uint amount) public
- Returns the amount of LP tokens, and distributes the corresponding tokenA and tokenB to the msg.sender wallet
- The returned LP token amount is burned
- If there is claimable KSP when called, the claim proceeds to msg.sender.
removeLiquidityWithLimit
function removeLiquidityWithLimit(uint amount, uint minAmountA, uint minAmountB) public
- Returns the amount of LP tokens, and distributes the corresponding tokenA and tokenB to the msg.sender wallet
- Set the minimum amount for the returned tokenA and tokenB amounts by using minAmountA, minAmountB.
- The returned LP token amount is burned
- If there is claimable KSP when called, the claim proceeds to msg.sender.
Last modified 7mo ago