Protocol Mechanics
The smart contract for the Oxygen Prime Brokerage protocol is described here. It can be upgraded through governance over time. It is developed in RUST for deployment on Solana.
Create a Protocol
This function allows you to create a new Prime Brokerage Protocol.
CreateProtocolInstructionParams
Description
This defines the parameters for creating a new Protocol.
export type CreateProtocolInstructionParams = {
programId: PublicKey,
owner: PublicKey,
account: PublicKey,
tokenProgramId: PublicKey,
feeMint: PublicKey,
protocolAuthority: PublicKey,
slotsInDays: number,
}
createProtocol(params: CreateProtocolInstructionParams)
Description
This is the function call for creating a new Protocol.
static createProtocol(params: CreateProtocolInstructionParams): TransactionInstruction {
const keys: AccountMeta[] = [
{ pubkey: params.owner, isSigner: true, isWritable: false },
{ pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
{ pubkey: params.tokenProgramId, isSigner: false, isWritable: false },
{ pubkey: params.programId, isSigner: false, isWritable: false },
{ pubkey: params.account, isSigner: false, isWritable: true },
{ pubkey: params.protocolAuthority, isSigner: false, isWritable: false },
{ pubkey: params.feeMint, isSigner: false, isWritable: false }
];
const data = encodeInstructionData(CreateProtocolLayoutField, { slots_in_days: new BN(params.slotsInDays),
});
return new TransactionInstruction({keys, data, programId:
params.programId});
}
Create a Protocol Asset
This function allows you to create a new Asset for a Prime Brokerage Protocol.
CreateProtocolInstructionParams
Description
This defines the parameters for creating a new Asset for a Protocol.
export type CreateProtocolAssetInstructionParams = {
programId: PublicKey,
owner: PublicKey,
protocolAsset: PublicKey,
protocol: PublicKey,
priceOracleProgramId: PublicKey,
priceOracleAsset: PublicKey,
dexProgramId: PublicKey,
dexMarket: PublicKey,
tokenProgramId: PublicKey,
feeVault: PublicKey,
native: AssetToken,
oxyToken: AssetToken,
iouOxyToken: AssetToken,
iouFutureToken: AssetToken,
debtToken: AssetToken,
futureToken: AssetToken,
data: CreateProtocolAssetType
}
createProtocolAsset(params: CreateProtocolAssetInstructionParams)
Description
Creates an asset for the protocol.
static createProtocolAsset(params: CreateProtocolAssetInstructionParams) {
const keys: AccountMeta[] = [
{ pubkey: params.programId, isSigner: false, isWritable: false },
{ pubkey: params.owner, isSigner: true, isWritable: false },
{ pubkey: params.protocolAsset, isSigner: false, isWritable: true },
{ pubkey: params.protocol, isSigner: false, isWritable: true },
{ pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
{ pubkey: params.priceOracleProgramId, isSigner: false, isWritable: false },
{ pubkey: params.priceOracleAsset, isSigner: false, isWritable: false },
{ pubkey: params.dexProgramId, isSigner: false, isWritable: false },
{ pubkey: params.dexMarket, isSigner: false, isWritable: false },
{ pubkey: params.tokenProgramId, isSigner: false, isWritable: false },
{ pubkey: params.feeVault, isSigner: false, isWritable: true },
];
for (const token of ['native', 'oxyToken', 'debtToken', 'futureToken', 'iouOxyToken', 'iouFutureToken']) {
let assetToken = params[token] as AssetToken;
keys.push({pubkey: assetToken.mint, isSigner: false, isWritable: false});
keys.push({pubkey: assetToken.vault, isSigner: false, isWritable: false});
};
const data = encodeInstructionData(CreateProtocolAssetLayoutField, params.data);
return new TransactionInstruction({keys, data, programId: params.programId});
}
Create Pool
This function allows the user to create a new Pool.
CreatePoolInstructionParams
Description
This defines the parameters required for depositing assets in a Pool
export type CreatePoolInstructionParams = {
programId: PublicKey,
protocolAuthority: PublicKey,
owner: PublicKey,
protocol: PublicKey,
pool: PublicKey,
feeWallet: PublicKey,
nonce: number
}
createPool(params: CreatePoolInstructionParams)
Description
Creates a Pool.
static createPool(params: CreatePoolInstructionParams) : TransactionInstruction {
const keys: AccountMeta[] = [
{ pubkey: params.programId, isSigner: false, isWritable: false },
{ pubkey: params.protocolAuthority, isSigner: false, isWritable: false },
{ pubkey: params.owner, isSigner: true, isWritable: false },
{ pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
{ pubkey: params.protocol, isSigner: false, isWritable: false },
{ pubkey: params.pool, isSigner: false, isWritable: true },
{ pubkey: params.feeWallet, isSigner: false, isWritable: false },
];
const data = encodeInstructionData(CreatePoolLayoutField, { nonce: params.nonce });
return new TransactionInstruction({keys, data, programId:params.programId});
}
Create Pool Wallet
This function allows the user to create a Pool Wallet for a given Pool.
CreatePoolInstructionParams
Description
This defines the parameters required for creating a Pool Wallet.
export type CreatePoolWalletInstructionParams = {
programId: PublicKey
tokenProgramId: PublicKey,
owner: PublicKey,
protocol: PublicKey,
asset: PublicKey,
pool: PublicKey,
tokenAuthority: PublicKey,
wallet: PublicKey,
tokens: AssetToken[];
}
createPoolWallet(params: CreatePoolWalletInstructionParams)
Description
Creates a Pool Wallet for holding the assets deposited into it. This function creates:- OXY_TOKEN – this is the Oxygen representation of an underlying native asset. The user can exchange it for the native asset anytime.
- OXY_IOU – this is a token required for granting of a loan held by the lender until the trade is matched. OXY_IOU is then burned and swapped with OXY_FUTURE.
- OXY_FUTURE – this is a token that is provided to lender representing the asset lent plus interest after matching lender and borrower.
- OXY_IOU_FUTURE – the borrower is given this token when his order is placed. With this token a borrower can burn his debt as well. It represents the pending amount of a borrowing position in the asset and is replaced OXY_TOKEN when the trade settles.
- OXY_DEBT – this represents the borrower debt including the interest to be paid.
static createPoolWallet(params: CreatePoolWalletInstructionParams): TransactionInstruction {
const keys: AccountMeta[] = [
{ pubkey: params.programId, isSigner: false, isWritable: false },
{ pubkey: params.owner, isSigner: true, isWritable: false },
{ pubkey: params.protocol, isSigner: false, isWritable: false },
{ pubkey: params.tokenProgramId, isSigner: false, isWritable: false },
{ pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
{ pubkey: params.pool, isSigner: false, isWritable: true },
{ pubkey: params.tokenAuthority, isSigner: false, isWritable: false },
{ pubkey: params.asset, isSigner: false, isWritable: false },
{ pubkey: params.wallet, isSigner: false, isWritable: true },
];
for (let i = 0; i < params.tokens.length; i++) {
const token: AssetToken = params.tokens[i];
keys.push({pubkey: token.vault, isSigner: false, isWritable: true});
keys.push({pubkey: token.mint, isSigner: false, isWritable: true});
}
const data = encodeInstructionData(CreatePoolWalletLayoutField, {})
const programId = params.programId;
return new TransactionInstruction({keys, data, programId});
}
Attach the Pool Wallet to the Market
AttachPoolWalletToMarketParams
Description
This defines the parameters required for attaching a Pool Wallet to a Market to allow trading.
export type AttachPoolWalletToMarketParams = {
programId: PublicKey,
protocol: PublicKey,
asset: PublicKey,
pool: PublicKey,
wallet: PublicKey,
owner: PublicKey,
lendAgreements: PublicKey,
borrowAgreements: PublicKey,
}
attachWalletToMarket(params: AttachPoolWalletToMarketParams)
Description
This function attaches a Pool Wallet to a Market to allow trading. One given Wallet only relates to one specific market (for example btc_1day and btc_30days each will have a different wallet and attach to a different market).
static attachWalletToMarket(params: AttachPoolWalletToMarketParams): TransactionInstruction {
const keys: AccountMeta[] = [
{ pubkey: params.owner, isSigner: true, isWritable: false },
{ pubkey: params.protocol, isSigner: false, isWritable: false },
{ pubkey: params.asset, isSigner: false, isWritable: false },
{ pubkey: params.pool, isSigner: false, isWritable: false },
{ pubkey: params.wallet, isSigner: false, isWritable: true },
// { pubkey: params.lendOpenOrders, isSigner: false, isWritable: false },
// { pubkey: params.borrowOpenOrders, isSigner: false, isWritable: false },
{ pubkey: params.lendAgreements, isSigner: false, isWritable: true },
{ pubkey: params.borrowAgreements, isSigner: false, isWritable: true },
];
const data = encodeInstructionData(AttachPoolWalletToMarket, {});
const programId = params.programId;
return new TransactionInstruction({keys, data, programId});
}
Deposit Assets to a Pool
This function allows the user to deposit assets in a pool.
DepositToPoolParams
Description
This defines the parameters required for depositing assets in a Pool.
type DepositToPoolParams = {
programId: PublicKey,
owner: PublicKey,
tokenProgramId: PublicKey,
protocol: PublicKey,
pool: PublicKey,
asset: PublicKey,
wallet: PublicKey,
walletOxy: PublicKey,
fromNativeAccount: PublicKey,
assetNativeVault: PublicKey,
assetOxyMint: PublicKey,
assetAuthority: PublicKey,
amount: BN
}
depositToPool(params: DepositToPoolParams)
Description
Deposits assets into a pool. Assets deposited are stored with the Oxygen tokens OXY_TOKEN (e.g. OXT_BTC for BTC).
static depositToPool(params: DepositToPoolParams): TransactionInstruction {
const keys: AccountMeta[] = [
{ pubkey: params.programId, isSigner: false, isWritable: false },
{ pubkey: params.owner, isSigner: true, isWritable: false },
{ pubkey: params.tokenProgramId, isSigner: false, isWritable: false },
{ pubkey: params.protocol, isSigner: false, isWritable: false },
{ pubkey: params.pool, isSigner: false, isWritable: false },
{ pubkey: params.wallet, isSigner: false, isWritable: true },
{ pubkey: params.asset, isSigner: false, isWritable: false },
{ pubkey: params.fromNativeAccount, isSigner: false, isWritable: true },
{ pubkey: params.assetNativeVault, isSigner: false, isWritable: true },
{ pubkey: params.assetOxyMint, isSigner: false, isWritable: true },
{ pubkey: params.walletOxy, isSigner: false, isWritable: true },
{ pubkey: params.assetAuthority, isSigner: false, isWritable: false },
];
const programId = params.programId;
const data = encodeInstructionData(DepositToPoolLayoutField, {
amount: params.amount
});
return new TransactionInstruction({keys, programId, data});
}
Lend assets
This function allows the user to lend assets through the market to a borrower.
LendParams
Description
This defines the parameters required for lending assets to a borrower.
type LendParams = {
programId: PublicKey,
tokenProgramId: PublicKey,
protocol: PublicKey,
protocolAsset: PublicKey,
protocolAssetAuthority: PublicKey
pool: PublicKey,
poolOwner: PublicKey,
poolWallet: PublicKey,
poolAuthority: PublicKey,
poolDexSrmWallet: PublicKey,
poolOxyWallet: PublicKey,
protocolOxyIouMint: PublicKey,
poolOxyIouWallet: PublicKey,
} & DexMarket;
lend(params: LendParams)
Description
Lend assets to a borrower by matching a trade in the market. This function will send the desired number of assets to be lent to the protocol. The lender will then receive OXY_IOU tokens back until the trade settles.
At that point, the lender will receive OXY_FUTURE tokens including the interest payable in the future. The OXY_IOU tokens are then burned.
static lend(params: LendParams) : TransactionInstruction {
const keys :AccountMeta[] = [
{ pubkey: params.programId, isSigner: false, isWritable: false },
{ pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
{ pubkey: params.dexProgramId, isSigner: false, isWritable: false},
{ pubkey: params.tokenProgramId, isSigner: false, isWritable: false },
{ pubkey: params.protocol, isSigner: false, isWritable: false },
{ pubkey: params.pool, isSigner: false, isWritable: false },
{ pubkey: params.poolAuthority, isSigner: false, isWritable: false },
{ pubkey: params.poolDexSrmWallet, isSigner: false, isWritable: true },
{ pubkey: params.poolWallet, isSigner: false, isWritable: true },
{ pubkey: params.protocolAsset, isSigner: false, isWritable: false },
{ pubkey: params.dexMarket, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketRequestQueue, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketCoinVault, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketPriceVault, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketOpenOrders, isSigner: false, isWritable: true },
{ pubkey: params.poolOxyWallet, isSigner: false, isWritable: true },
{ pubkey: params.protocolOxyIouMint, isSigner: false, isWritable: true },
{ pubkey: params.poolOxyIouWallet, isSigner: false, isWritable: true },
{ pubkey: params.protocolAssetAuthority, isSigner: false, isWritable: false }
];
const programId = params.programId;
const data = encodeInstructionData(LendPoolAssetField, {});
return new TransactionInstruction({ keys, data, programId} );
}
SettleLendParams
Description
This defines the parameters required for settling a lending trade.
type SettleLendParams = SettleParams & DexMarket & {
poolWalletOxyIou: PublicKey,
protocolOxyIouMint: PublicKey,
}
settleLend(params: SettleLendParams)
Description
This function settles a lending trade. settleLend checks for an openOrderBalance on DEX. If the borrower matches a lending order, then the Protocol mints an InterestRateValue OXY_IOU (1 BTC * 5% for example) and records a future trade with a slot time when the OXY_IOU_BTC token can be traded with the OXY_BTC token.
static settleLend(params: SettleLendParams) : TransactionInstruction {
const keys: AccountMeta[] = [
{ pubkey: params.programId, isSigner: false, isWritable: false },
{ pubkey: params.protocol, isSigner: false, isWritable: false },
{ pubkey: params.protocolAsset, isSigner: false, isWritable: false },
{ pubkey: params.pool, isSigner: false, isWritable: false },
{ pubkey: params.poolAuthority, isSigner: false, isWritable: false },
{ pubkey: params.poolWallet, isSigner: false, isWritable: true },
{ pubkey: params.dexMarket, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketOpenOrders, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletAgreement, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketCoinVault, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketPriceVault, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletFuture, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletOxy, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletOxyIou, isSigner: false, isWritable: true },
{ pubkey: params.protocolOxyIouMint, isSigner: false, isWritable: true },
{ pubkey: params.protocolOxyVault, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketAuthority, isSigner: false, isWritable: false },
{ pubkey: params.dexProgramId, isSigner: false, isWritable: false },
{ pubkey: params.tokenProgramId, isSigner: false, isWritable: false },
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false },
];
const data = encodeInstructionData(PoolLendSettleLayoutField, {});
const programId = params.programId;
return new TransactionInstruction({keys, data, programId});
}
Stop lending funds
These function are for redeeming or cancelling your lending order.
CancelLendsParams
Description
This defines the parameters required for cancelling a lending order.
type CancelLendsParams = {
programId: PublicKey;
poolOwner: PublicKey;
protocol: PublicKey;
protocolAsset: PublicKey;
pool: PublicKey;
poolAuthority: PublicKey;
poolWallet: PublicKey;
poolWalletOxyIou: PublicKey;
} & DexMarket;
cancelLend(params: CancelLendsParams)
Description
This functions cancels your lending order on the DEX market (if it is still open). It burns the OXY_IOU_XXX that was minted and transfers the OXY_XXX token back. For example if you lent out 5 BTC and you are holding OXY_IOU_BTC =, the cancelLend would burn the 5 OXY_IOU_BTC and return 5 OXT_BTC to you.
static cancelLend(params: CancelLendsParams) : TransactionInstruction {
const keys: AccountMeta[] = [
{ pubkey: params.programId, isSigner: false, isWritable: false },
{ pubkey: params.poolOwner, isSigner: true, isWritable: false },
{ pubkey: params.protocol, isSigner: false, isWritable: false },
{ pubkey: params.protocolAsset, isSigner: false, isWritable: false },
{ pubkey: params.pool, isSigner: false, isWritable: false },
{ pubkey: params.poolAuthority, isSigner: false, isWritable: true },
{ pubkey: params.poolWallet, isSigner: false, isWritable: true },
{ pubkey: params.dexMarket, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketOpenOrders, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletOxyIou, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketRequestQueue, isSigner: false, isWritable: true },
{ pubkey: params.dexProgramId, isSigner: false, isWritable: true },
];
const programId = params.programId;
const data = encodeInstructionData(CancelLendLayoutField, {});
return new TransactionInstruction({ keys, data, programId });
}
LendClearingParams
Description
This function defines the parameters required for clearing a loan on redemption.
type LendClearingParams = {
programId: PublicKey;
tokenProgramId: PublicKey;
protocol: PublicKey;
protocolAsset: PublicKey;
protocolAssetAuthority: PublicKey;
pool: PublicKey;
poolAuthority: PublicKey;
poolWallet: PublicKey;
poolWalletLendAgreement: PublicKey;
poolWalletOxy: PublicKey;
protocolVaultOxy: PublicKey;
protocolOxyMint: PublicKey;
poolWalletFuture: PublicKey;
protocolFutureMint: PublicKey;
poolFeeWallet: PublicKey;
protocolFeeVault: PublicKey;
protocolNativeVault: PublicKey;
}
clearingLend(params: LendClearingParams)
Description
This function swaps IOUs issued with the appropriate amount of of the OXY_XXX token plus interest on redemption of the loan.
static clearingLend(params: LendClearingParams) : TransactionInstruction {
const keys: AccountMeta[] = [
{ pubkey: params.programId, isSigner: false, isWritable: false },
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false },
{ pubkey: params.tokenProgramId, isSigner: false, isWritable: false },
{ pubkey: params.protocol, isSigner: false, isWritable: false },
{ pubkey: params.protocolAsset, isSigner: false, isWritable: false },
{ pubkey: params.protocolAssetAuthority, isSigner: false, isWritable: false },
{ pubkey: params.pool, isSigner: false, isWritable: true },
{ pubkey: params.poolAuthority, isSigner: false, isWritable: false },
{ pubkey: params.poolWallet, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletLendAgreement, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletOxy, isSigner: false, isWritable: true },
{ pubkey: params.protocolVaultOxy, isSigner: false, isWritable: true },
{ pubkey: params.protocolOxyMint, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletFuture, isSigner: false, isWritable: true },
{ pubkey: params.protocolFutureMint, isSigner: false, isWritable: true },
{ pubkey: params.poolFeeWallet, isSigner: false, isWritable: true },
{ pubkey: params.protocolFeeVault, isSigner: false, isWritable: true },
{ pubkey: params.protocolNativeVault, isSigner: false, isWritable: true },
];
const programId = params.programId;
const data = encodeInstructionData(PoolLendClearing, {});
return new TransactionInstruction({keys, data, programId});
}
Borrow assets
This function allows the user to borrow assets in a pool.
BorrowParams
Description
This defines the parameters required for a user to borrow assets.
type BorrowParams = {
programId: PublicKey,
pool: PublicKey,
poolOwner: PublicKey,
poolWallet: PublicKey,
poolAuthority: PublicKey,
tokenProgramId: PublicKey,
protocol: PublicKey,
protocolAsset: PublicKey,
protocolAssetAuthority: PublicKey,
poolWalletFuture: PublicKey,
protocolFutureMint: PublicKey,
poolWalletDebt: PublicKey,
poolWalletIouFuture: PublicKey,
protocolDebtMint: PublicKey,
protocolIouFutureMint: PublicKey,
poolDexSrmWallet: PublicKey,
rate: OptionalU64,
amount: OptionalU64
} & DexMarket;
borrow(params : BorrowParams)
Description
Borrow assets from a lender by matching a trade in the market.
static cancelLend(params: CancelLendsParams) : TransactionInstruction {
const keys: AccountMeta[] = [
{ pubkey: params.programId, isSigner: false, isWritable: false},
{ pubkey: params.poolOwner, isSigner: true, isWritable: true },
{ pubkey: params.dexProgramId, isSigner: false, isWritable: false },
{ pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false},
{ pubkey: params.tokenProgramId, isSigner: false, isWritable: false},
{ pubkey: params.protocol, isSigner: false, isWritable: false},
{ pubkey: params.protocolAsset, isSigner: false, isWritable: false },
{ pubkey: params.protocolAssetAuthority, isSigner: false, isWritable: false },
{ pubkey: params.pool, isSigner: false, isWritable: true },
{ pubkey: params.poolAuthority, isSigner: false, isWritable: true },
{ pubkey: params.poolWallet, isSigner: false, isWritable: true },
{ pubkey: params.dexMarket, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketOpenOrders, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketRequestQueue, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketCoinVault, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketPriceVault, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletFuture, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletIouFuture, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletDebt, isSigner: false, isWritable: true },
{ pubkey: params.protocolDebtMint, isSigner: false, isWritable: true },
{ pubkey: params.protocolIouFutureMint, isSigner: false, isWritable: true },
{ pubkey: params.protocolFutureMint, isSigner: false, isWritable: true },
{ pubkey: params.poolDexSrmWallet, isSigner: false, isWritable: true }
];
const data = encodeInstructionData(BorrowingAssetLayoutField, {
'amount': params.amount,
'rate': params.rate,
})
const programId = params.programId;
return new TransactionInstruction({keys, data, programId});
}
SettleBorrowParams
Description
This defines the parameters required to settle a loan for the borrower.
type SettleBorrowParams = SettleParams & DexMarket & {
poolWalletFutureIou: PublicKey,
protocolFutureIouMint: PublicKey,
protocolFutureMint: PublicKey,
poolWalletDebt: PublicKey,
protocolDebtMint: PublicKey,
}
settleBorrow(params: SettleBorrowParams)
Description
This function settles a lending trade for the borrower. settleBorrow checks for an openOrderBalance on DEX. If a lender matches a borrowing order, then the Protocol mints an InterestRateValue OXY_IOU (1 BTC * 5% for example) for the lender and records a future trade with a slot time when the OXY_IOU_BTC token can be traded with the OXY_BTC token.
static settleBorrow(params: SettleBorrowParams) : TransactionInstruction {
const keys: AccountMeta[] = [
{ pubkey: params.programId, isSigner: false, isWritable: false },
{ pubkey: params.protocol, isSigner: false, isWritable: false },
{ pubkey: params.protocolAsset, isSigner: false, isWritable: false },
{ pubkey: params.pool, isSigner: false, isWritable: false },
{ pubkey: params.poolAuthority, isSigner: false, isWritable: false },
{ pubkey: params.poolWallet, isSigner: false, isWritable: true },
{ pubkey: params.dexMarket, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketOpenOrders, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletAgreement, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketCoinVault, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketPriceVault, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletFuture, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletOxy, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletFutureIou, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletDebt, isSigner: false, isWritable: true },
{ pubkey: params.protocolFutureIouMint, isSigner: false, isWritable: true },
{ pubkey: params.protocolFutureMint, isSigner: false, isWritable: true },
{ pubkey: params.protocolDebtMint, isSigner: false, isWritable: true },
{ pubkey: params.protocolOxyVault, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketAuthority, isSigner: false, isWritable: false },
{ pubkey: params.dexProgramId, isSigner: false, isWritable: false },
{ pubkey: params.tokenProgramId, isSigner: false, isWritable: false },
{ pubkey: SYSVAR_CLOCK_PUBKEY, isSigner: false, isWritable: false },
];
const data = encodeInstructionData(PoolBorrowSettleLayoutField, {});
const programId = params.programId;
return new TransactionInstruction({keys, data, programId});
}
Stop borrowing assets
CancelBorrowParams
Description
This defines the parameters required for cancelling a borrowing order.
type CancelBorrowsParams = {
programId: PublicKey;
poolOwner: PublicKey;
protocol: PublicKey;
protocolAsset: PublicKey;
pool: PublicKey;
poolAuthority: PublicKey;
poolWallet: PublicKey;
poolWalletFutureIou: PublicKey;
} & DexMarket;
cancelBorrow(params: CancelBorrowParams)
Description
This functions cancels your borrowing order on the DEX market (if it is still open).
static cancelBorrow(params: CancelBorrowsParams) : TransactionInstruction {
const keys: AccountMeta[] = [
{ pubkey: params.programId, isSigner: false, isWritable: false },
{ pubkey: params.poolOwner, isSigner: true, isWritable: false },
{ pubkey: params.protocol, isSigner: false, isWritable: false },
{ pubkey: params.protocolAsset, isSigner: false, isWritable: false },
{ pubkey: params.pool, isSigner: false, isWritable: false },
{ pubkey: params.poolAuthority, isSigner: false, isWritable: true },
{ pubkey: params.poolWallet, isSigner: false, isWritable: true },
{ pubkey: params.dexMarket, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketOpenOrders, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletFutureIou, isSigner: false, isWritable: true },
{ pubkey: params.dexMarketRequestQueue, isSigner: false, isWritable: true },
{ pubkey: params.dexProgramId, isSigner: false, isWritable: true }
];
const programId = params.programId;
const data = encodeInstructionData(CancelBorrowLayoutField, {});
return new TransactionInstruction({ keys, data, programId });
}
}
RepaymentBorrowParams
Description
This function defines the parameters required for repaying a loan.
type RepaymentBorrowParams = {
pool: PublicKey;
poolOwner: PublicKey;
poolAuthority: PublicKey;
poolWallet: PublicKey;
programId: PublicKey;
tokenProgramId: PublicKey;
protocol: PublicKey;
protocolAsset: PublicKey;
protocolAssetAuthority: PublicKey;
poolWalletBorrowAgreement: PublicKey;
poolWalletOxy: PublicKey;
protocolVaultOxy: PublicKey;
protocolOxyMint: PublicKey;
poolWalletDebt: PublicKey;
protocolDebtMint: PublicKey;
poolFeeWallet: PublicKey;
protocolFeeVault: PublicKey;
protocolNativeVault: PublicKey;
amount: BN;
}
repaymentBorrow(params: RepaymentBorrowParams)
Description
This function swaps OXY_DEBT_XXX issued with the appropriate amount of the OXY_XXX token plus interest due on the loan.
static repaymentBorrow(params: RepaymentBorrowParams) : TransactionInstruction {
const keys: AccountMeta[] = [
{ pubkey: params.poolOwner, isSigner: true, isWritable: false },
{ pubkey: params.programId, isSigner: false, isWritable: false },
{ pubkey: params.tokenProgramId, isSigner: false, isWritable: false },
{ pubkey: params.protocol, isSigner: false, isWritable: false },
{ pubkey: params.protocolAsset, isSigner: false, isWritable: false },
{ pubkey: params.pool, isSigner: false, isWritable: true },
{ pubkey: params.poolAuthority, isSigner: false, isWritable: false },
{ pubkey: params.poolWallet, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletBorrowAgreement, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletOxy, isSigner: false, isWritable: true },
{ pubkey: params.protocolVaultOxy, isSigner: false, isWritable: true },
{ pubkey: params.protocolOxyMint, isSigner: false, isWritable: true },
{ pubkey: params.protocolDebtMint, isSigner: false, isWritable: true },
{ pubkey: params.poolWalletDebt, isSigner: false, isWritable: true },
{ pubkey: params.poolFeeWallet, isSigner: false, isWritable: true },
{ pubkey: params.protocolFeeVault, isSigner: false, isWritable: true },
{ pubkey: params.protocolNativeVault, isSigner: false, isWritable: true },
];
const programId = params.programId;
const data = encodeInstructionData(PoolRepayment, {
amount: params.amount,
})
return new TransactionInstruction({keys, programId, data});
}