Counterparty Pool Contract
The Defactor SDK provides utilities and classes to seamless interaction with the Defactor contracts. In this specific section, the focus is in the CounterParty Pool Contract and Pools
class, which implements the fundamental methods to interact with the contract in question.
To support the Admin version of the contract it is needed to use the AdminPools
class instead.
Constants
INTEREST_DECIMAL_PLACES // Use to adjust the decimals in the interest rate calculation.
POOL_FEE // The required amount of USDC to create a pool.
COLLECT_POOL_MAX_SECS // Maximum unix epoch time for collecting funds from a pool.
COLLECT_POOL_MAX_DAYS // Maximum days for collecting funds from a pool.
MIN_POOL_CLOSED_SECS // Minimum unix epoch time before a pool can be archived
MIN_POOL_CLOSED_DAYS // Minimum days before a pool can be archived
Methods Available
// Returns the USDC address configured as the base token.
async USD_ADDRESS(): Promise<string>
// Returns if the contract is paused.
async isPaused(): Promise<boolean>
// Returns the pool with the given poolId.
async getPool(poolId: bigint): Promise<Pool>
// Returns a list of pools within the given range.
async getPools(offset: bigint, limit: bigint): Promise<Pagination<Pool>>
// Pause the contract
async pause(): Promise<ethers.ContractTransaction | ethers.TransactionResponse>
// Unpause the contract
async unpause(): Promise<ethers.ContractTransaction | ethers.TransactionResponse>
// Create a new pool
async createPool(pool: PoolInput): Promise<ethers.ContractTransaction | ethers.TransactionResponse>
// Allows the owner of the pool collects the committed amount and active the pool
async collectPool(poolId: bigint): Promise<ethers.ContractTransaction | ethers.TransactionResponse>
// Allows the owner of the pool deposits the rewards
async depositRewards(
poolId: bigint,
amount: bigint
): Promise<ethers.ContractTransaction | ethers.TransactionResponse>
// Allows to close the pool
async closePool(poolId: bigint): Promise<ethers.ContractTransaction | ethers.TransactionResponse>
// Allows to archive the pool
async archivePool(poolId: bigint): Promise<ethers.ContractTransaction | ethers.TransactionResponse>
// Allows the lender (investor) to commit the specific amount to the pool
async commitToPool(
poolId: bigint,
amount: bigint
): Promise<ethers.ContractTransaction | ethers.TransactionResponse>
// Transfer the committed amount to the pool by the lender (investor)
async uncommitFromPool(poolId: bigint): Promise<ethers.ContractTransaction | ethers.TransactionResponse>
// Allows to the lender (investor) to claim their rewards
async claim(poolId: bigint): Promise<ethers.ContractTransaction | ethers.TransactionResponse>
Examples
Initialize the SelfProvider
Import the library and instantiate the SelfProvider
class with the Pools
contract.
import { Pools, SelfProvider } from "@defactor/defactor-sdk";
const provider = new SelfProvider.SelfProvider<Pools>(
Pools,
contractConfig.contractAddress, // loaded from config file
contractConfig.providerUrl, // loaded from config file
contractConfig.AlicePrivateKey // loaded from config file
)
Access to constants
const poolCreationFee: bigint = provider.contract.POOL_FEE
Create a pool
In the following example Alice will create a pool with a soft cap of 100 USDC, a hard cap of 600 USDC, a minimum APR of 50 USDC and as collateral 15 of GOLD.
To successfully create the pool, the contract must have the allowance to transfer the fee in USDC and the collateral tokens.
await provider.contract.createPool({
softCap: BigInt(100_000000), // 100 USDC
hardCap: BigInt(600_000000), // 600 USDC
deadline: BigInt(1734652800), // 2024-12-20T00:00:00.000Z
minimumAPR: BigInt(50_000000), // 50 USDC
collateralTokens: [
{
contractAddress: contractConfig.goldTokenAddress, // loaded from config file
amount: BigInt(15_000000), // 15 GOLD
id: null
}
]
})
Commit to a pool
In the following example Bob commits 200 USDC to Alice's pool.
To successfully commit to the pool, the contract must have the allowance to transfer the amount of USDC.
const poolId = BigInt(0)
const amount = BigInt(200_000000) // 200 USDC
const provider = new SelfProvider.SelfProvider<Pools>(
Pools,
contractConfig.contractAddress, // loaded from config file
contractConfig.providerUrl, // loaded from config file
contractConfig.BobPrivateKey // loaded from config file
);
await provider.contract.commitToPool(poolId, amount)
Get a pool
Get a pool using the sequential id.
const poolId = BigInt(0)
const pool = await provider.contract.getPool(poolId)
console.log(pool)
Example output:
{
softCap: 100000000n,
hardCap: 600000000n,
totalCommitted: 0n,
totalRewards: 0n,
rewardsPaidOut: 0n,
createdAt: 1717372800n,
deadline: 1734652800n,
minimumAPR: 50000000n,
closedTime: 0n,
poolOwner: '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
poolStatus: 'CREATED',
collateralTokens: [
{
contractAddress: '0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
amount: 15000000n
id: 0n
}
]
}