Core System Contract

Treasury Contract

1
0x1Ee7E501039E0bd75475DD9da69EE744951CaB8B
Copied!
The Treasury Contract determines the expansion and contraction status of the round and plays a central role like the central bank, such as the issuance of new KAI and redemption of bKAI.
[Main role]
  • Determination of expansion/contraction status according to the price of KAI provided by PriceOracle
  • Determination of airdrop ratio based on expansion/contraction/boost result
  • New issuance and distribution of KAI in the expanded state
  • bHolding and paying KAI for bKAI redemption
The following is the code to mint for additional KAI issuance in the expanded state.
1
function allocateSeigniorage() external onlyOneBlock checkCondition checkEpoch checkOperator {
2
_updateKAIPrice();
3
previousRoundKAIPrice = getKAIPrice(); // KAI 가격을 얻어옴
4
uint256 kaiSupply = IERC20(kai).totalSupply().sub(seigniorageSaved);
5
if (round < bootstrapRounds) { // 초기 21라운드는 3% 고정
6
_sendToBoardRoom(kaiSupply.mul(bootstrapSupplyExpansionPercent).div(10000));
7
} else {
8
if (previousRoundKAIPrice > kaiPriceOne) { // KAI 가격이 $1 초과하면 확장
9
uint256 bkaiSupply = IERC20(bkai).totalSupply();
10
uint256 _percentage = previousRoundKAIPrice.sub(kaiPriceOne).mul(seigniorageExpansionRate).div(10000);
11
uint256 _savedForBKAI;
12
uint256 _savedForBoardRoom;
13
// bKAI 의 발행량 이상으로 Treasury 가 KAI 를 보유한 경우 일반적인 확장 진행
14
if (seigniorageSaved >= bkaiSupply.mul(bkaiDepletionFloorPercent).div(10000))
15
uint256 _mse = maxSupplyExpansionPercent.mul(1e14);
16
if (_percentage > _mse) {
17
_percentage = _mse;
18
}
19
_savedForBoardRoom = kaiSupply.mul(_percentage).div(1e18);
20
} else {
21
// bKAI 의 발행량 만큼 Treasury 가 보유하고 있지 않다면, 이는 Debt Phase 로 전환되어 더 많은 KAI 가 Treasury 에 적립됨
22
_percentage = maxSupplyExpansionPercentInDebtPhase.mul(1e14);
23
uint256 _seigniorage = kaiSupply.mul(_percentage).div(1e18);
24
_savedForBoardRoom = _seigniorage.mul(seigniorageExpansionFloorPercent).div(10000);
25
_savedForBKAI = _seigniorage.sub(_savedForBoardRoom);
26
if (mintingFactorForPayingDebt > 0) {
27
_savedForBKAI = _savedForBKAI.mul(mintingFactorForPayingDebt).div(10000);
28
}
29
}
30
if (_savedForBoardRoom > 0) {
31
// 보드룸으로 KAI 생성 요청
32
_sendToBoardRoom(_savedForBoardRoom);
33
}
34
if (_savedForBKAI > 0) {
35
seigniorageSaved = seigniorageSaved.add(_savedForBKAI);
36
IKAIAsset(kai).mint(address(this), _savedForBKAI);
37
emit TreasuryFunded(now, _savedForBKAI);
38
}
39
}
40
}
41
// 바이백 펀드 KAI 생성
42
if (previousRoundKAIPrice > kaiPriceOne) {
43
uint256 _buyBackRate = previousRoundKAIPrice.sub(kaiPriceOne).mul(buyBackFundExpansionRate).div(10000);
44
uint256 _maxBuyBackRate = maxBuyBackFundExpansion.mul(1e14);
45
if (_buyBackRate > _maxBuyBackRate) {
46
_buyBackRate = _maxBuyBackRate;
47
}
48
uint256 _savedForBuyBackFund = kaiSupply.mul(_buyBackRate).div(1e18);
49
if (_savedForBuyBackFund > 0) {
50
IKAIAsset(kai).mint(address(buyBackFund), _savedForBuyBackFund);
51
emit BuyBackFunded(now, _savedForBuyBackFund);
52
}
53
}
54
if (allocateSeigniorageSalary > 0) {
55
IKAIAsset(kai).mint(address(admin), allocateSeigniorageSalary);
56
}
57
}
58
Copied!
After mint, KAI is distributed to Boardroom Contract and Team Fund through the _sendToBoardRoom function.
1
function _sendToBoardRoom(uint256 _amount) internal {
2
IKAIAsset(kai).mint(address(this), _amount);
3
// 10%의 물량은 팀펀드로 적립되며, 해당 물량은 마케팅 및 운영비로 사용됨
4
if (teamFundSharedPercent > 0) {
5
uint256 _teamFundSharedAmount = _amount.mul(teamFundSharedPercent).div(10000);
6
IERC20(kai).transfer(teamFund, _teamFundSharedAmount);
7
emit TeamFundFunded(now, _teamFundSharedAmount);
8
_amount = _amount.sub(_teamFundSharedAmount);
9
}
10
IERC20(kai).safeApprove(boardroom, 0);
11
IERC20(kai).safeApprove(boardroom, _amount);
12
// 보드룸에 나머지 물량을 보내서 단일예치자들에게 배분
13
IBoardroom(boardroom).allocateSeigniorage(_amount);
14
emit BoardroomFunded(now, _amount);
15
}
16
Copied!

Boardroom Contract

1
0x931579Fa23580CB2214fBE89aB487f6AEDE8a352
Copied!
Boardroom Contract acts like a general bank that manages sKAI deposit(Stake) and distributes KAI received from Treasury Contract to sKAI deposit users in the expanded state.
[Main role]
  • Stake sKAI
  • Distribution of additional minted KAI
  • Distributed minted vKAI

BBFund Contract - Buyback Fund

1
0x451033434Fb739a538DA0a77d3DcA23Bf0801255
Copied!
A complementary device to KAI's $1 pegging algorithm through bKAI can stabilize the price by backing up KAI when the estimated price (TWAP) for the next round is less than $1. Depending on KAI distribution and the status of buyback funds, buyback KAI may be incinerated.
The creation of the buyback fund will be carried out through KAI and vKAI, and it will be converted into KUSDT and KDAI and accumulated.
[Main role]
  • KAI -> KUSDT or KAI -> KDAI exchange when KAI price is over $1
  • KUSDT -> KAI or KDAI -> KAI exchange when KAI price is less than $1
The Buyback Fund Contract does not have a transfer function and consists only of Sell, Buy, and Burn functions to maintain the KAI price.
1
function setKAIPriceToSell(uint256 _priceToSell) external onlyStrategist {
2
require(_priceToSell > 1.0 ether, "out of range"); // 1불을 초과해야 매도 가능
3
kaiPriceToSell = _priceToSell;
4
}
5
6
function setKAIPriceToBuy(uint256 _priceToBuy) external onlyStrategist {
7
require(_priceToBuy < 1.0 ether, "out of range"); // 1 불 미만일 때 매수 가능
8
kaiPriceToBuy = _priceToBuy;
9
}
10
11
function forceSell(address _buyingToken, uint256 _amount) external onlyStrategist {
12
require(getKAIUpdatedPrice() >= kaiPriceToSell, "price is too low to sell");
13
_swapToken(kai, _buyingToken, _amount);
14
}
15
16
function forceBuy(address _sellingToken, uint256 _amount) external onlyStrategist {
17
require(getKAIUpdatedPrice() <= kaiPriceToBuy, "price is too high to buy");
18
_swapToken(_sellingToken, kai, _amount);
19
}
20
21
function _swapToken(address _inputToken, address _outputToken, uint256 _amount) internal {
22
if (_amount == 0) return;
23
uint256 _maxAmount = maxAmountToTrade[_inputToken];
24
25
if (_maxAmount > 0 && _maxAmount < _amount) {
26
_amount = _maxAmount;
27
}
28
29
address[] memory _path;
30
IERC20(_inputToken).safeIncreaseAllowance(address(klayswapFactory), _amount);
31
IKlayswapFactory(klayswapFactory).exchangeKctPos(_inputToken, _amount, _outputToken, 1, _path);
32
}
33
Copied!