Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bounce for withdraw、borrow 、repay #32

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contracts/constants.tact
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const ACTION_LIQUIDATION: Int = 3;

const RERUN_ACTION_UPDATE_POSITION: Int = 100;
const RERUN_ACTION_MINT: Int = 101;
const RERUN_ACTION_TOKEN_TRANSFER: Int = 102;
const RERUN_ACTION_TOKEN_BURN: Int = 103;

const JETTON_UNIT: Int = pow(10, 9);
// Mock zero address
Expand Down
2 changes: 1 addition & 1 deletion contracts/jetton/assetToken/atoken-wallet.tact
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ contract ATokenDefaultWallet
queryId: msg.queryId,
amount: msg.amount,
owner: self.owner,
response_destination: self.owner
response_destination: msg.response_destination
}.toCell()
}
);
Expand Down
2 changes: 1 addition & 1 deletion contracts/jetton/assetToken/atoken.tact
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract AToken with ATokenJettonTrait {
self.requireOwner();
self.requireNotStopped();
require(self.mintable, "Can't Mint Anymore");
self.mint(msg.queryId, msg.receiver, msg.amount, self.owner); // (to, amount, response_destination)
self.mint(msg.queryId, msg.receiver, msg.amount, self.owner); // (queryId, to, amount, response_destination)
}

// ====== Get Methods ====== //
Expand Down
4 changes: 2 additions & 2 deletions contracts/jetton/debtToken/dtoken-master.tact
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ trait DTokenJettonTrait with Ownable, Deployable, Resumable {
// @to The Address receive the Jetton token after minting
// @amount The amount of Jetton token being minted
// @response_destination The previous owner address
fun mint(to: Address, amount: Int, response_destination: Address) {
fun mint(queryId: Int, to: Address, amount: Int, response_destination: Address) {
self.totalSupply = (self.totalSupply + amount); // Update total supply

let winit: StateInit = self.getJettonWalletInit(to); // Create message
Expand All @@ -50,7 +50,7 @@ trait DTokenJettonTrait with Ownable, Deployable, Resumable {
bounce: false,
mode: SendRemainingValue,
body: TokenTransferInternal{
queryId: 0,
queryId: queryId,
amount: amount,
from: myAddress(),
response_destination: response_destination,
Expand Down
2 changes: 1 addition & 1 deletion contracts/jetton/debtToken/dtoken-wallet.tact
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ contract DTokenDefaultWallet
queryId: msg.queryId,
amount: msg.amount,
owner: self.owner,
response_destination: self.owner
response_destination: msg.response_destination
}.toCell()
}
);
Expand Down
2 changes: 1 addition & 1 deletion contracts/jetton/debtToken/dtoken.tact
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ contract DToken with DTokenJettonTrait {
self.requireOwner();
self.requireNotStopped();
require(self.mintable, "Can't Mint Anymore");
self.mint(msg.receiver, msg.amount, self.owner); // (to, amount, response_destination)
self.mint(msg.queryId, msg.receiver, msg.amount, self.owner); // (queryId, to, amount, response_destination)
}

// ====== Get Methods ====== //
Expand Down
1 change: 0 additions & 1 deletion contracts/jetton/messages.tact
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ message CheckAndTransferAToken {
// custom Mint message
message Mint {
queryId: Int as uint64;
token: Address;
amount: Int;
receiver: Address;
}
35 changes: 19 additions & 16 deletions contracts/pool-view.tact
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ trait PoolView with Ownable, Resumable {
reservesConfiguration: map<Address, ReserveConfiguration>;
reserveInterestRateStrategy: map<Address, ReserveInterestRateStrategy>;
// bounce messages
updatePositionMsg: map<Int, UpdatePosition>;
mintMsg: map<Int, Mint>;
updatePositionMsg: map<Int, UpdatePositionBounce>;
mintMsg: map<Int, MintBounce>;
tokenTransferMsg: map<Int, TokenTransferBounce>;
tokenBurnMsg: map<Int, TokenBurnBounce>;

// ===== Get functions =====

Expand Down Expand Up @@ -101,20 +103,13 @@ trait PoolView with Ownable, Resumable {
return self.reservesData.get(reserveAddress)!!;
}

get fun reserveDataForUI(reserveAddress: Address): ReserveDataForUI {
get fun reserveDataAndConfiguration(reserveAddress: Address): ReserveDataAndConfiguration {
let reserveData: ReserveData = self.reservesData.get(reserveAddress)!!;
let reserveConfiguration: ReserveConfiguration = self.reservesConfiguration.get(reserveAddress)!!;
return
ReserveDataForUI{
liquidityIndex: reserveData.liquidityIndex,
currentLiquidityRate: reserveData.currentLiquidityRate,
borrowIndex: reserveData.borrowIndex,
currentBorrowRate: reserveData.currentBorrowRate,
totalSupply: reserveData.totalSupply,
availableLiquidity: reserveData.availableLiquidity,
accruedToTreasury: reserveData.accruedToTreasury,
totalBorrow: reserveData.totalBorrow,
lastUpdateTimestamp: reserveData.lastUpdateTimestamp,
price: reserveData.price,
ReserveDataAndConfiguration{
reserveData: reserveData,
reserveConfiguration: reserveConfiguration,
normalizedIncome: reserveData.getNormalizedIncome(),
normalizedDebt: reserveData.getNormalizedDebt()
};
Expand Down Expand Up @@ -158,14 +153,22 @@ trait PoolView with Ownable, Resumable {
}

get fun bounceMsg(queryId: Int): Cell? {
let updatePositionMsg: UpdatePosition? = self.updatePositionMsg.get(queryId);
let updatePositionMsg: UpdatePositionBounce? = self.updatePositionMsg.get(queryId);
if (updatePositionMsg != null) {
return updatePositionMsg!!.toCell();
}
let mintMsg: Mint? = self.mintMsg.get(queryId);
let mintMsg: MintBounce? = self.mintMsg.get(queryId);
if (mintMsg != null) {
return mintMsg!!.toCell();
}
let tokenTransferMsg: TokenTransferBounce? = self.tokenTransferMsg.get(queryId);
if (tokenTransferMsg != null) {
return tokenTransferMsg!!.toCell();
}
let tokenBurnMsg: TokenBurnBounce? = self.tokenBurnMsg.get(queryId);
if (tokenBurnMsg != null) {
return tokenBurnMsg!!.toCell();
}
return null;
}
}
Loading