Skip to content
Merged
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
4 changes: 4 additions & 0 deletions ccip-sdk/src/cct/solana/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ describe('SolanaTokenManager (cct/solana)', () => {
assert.equal(typeof cct.deployTokenPool, 'function')
assert.equal(typeof cct.generateUnsignedDeleteChainRemoteConfig, 'function')
assert.equal(typeof cct.deleteChainRemoteConfig, 'function')
assert.equal(typeof cct.generateUnsignedSetCanAcceptLiquidity, 'function')
assert.equal(typeof cct.setCanAcceptLiquidity, 'function')
assert.equal(typeof cct.generateUnsignedSetChainRateLimit, 'function')
assert.equal(typeof cct.setChainRateLimit, 'function')
assert.equal(typeof cct.generateUnsignedSetRateLimitAdmin, 'function')
assert.equal(typeof cct.setRateLimitAdmin, 'function')
assert.equal(typeof cct.generateUnsignedSetRebalancer, 'function')
assert.equal(typeof cct.setRebalancer, 'function')
assert.equal(typeof cct.generateUnsignedTransferOwnership, 'function')
assert.equal(typeof cct.transferOwnership, 'function')
assert.equal(typeof cct.generateUnsignedAcceptOwnership, 'function')
Expand Down
163 changes: 163 additions & 0 deletions ccip-sdk/src/cct/solana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ import {
type ExecuteInitChainRemoteConfigResult,
type ExecuteRemoveFromAllowlistParams,
type ExecuteRemoveFromAllowlistResult,
type ExecuteSetCanAcceptLiquidityParams,
type ExecuteSetCanAcceptLiquidityResult,
type ExecuteSetChainRateLimitParams,
type ExecuteSetChainRateLimitResult,
type ExecuteSetRateLimitAdminParams,
type ExecuteSetRateLimitAdminResult,
type ExecuteSetRebalancerParams,
type ExecuteSetRebalancerResult,
type ExecuteTransferOwnershipParams,
type ExecuteTransferOwnershipResult,
type GenerateAcceptOwnershipParams,
Expand All @@ -120,10 +124,14 @@ import {
type GenerateInitChainRemoteConfigResult,
type GenerateRemoveFromAllowlistParams,
type GenerateRemoveFromAllowlistResult,
type GenerateSetCanAcceptLiquidityParams,
type GenerateSetCanAcceptLiquidityResult,
type GenerateSetChainRateLimitParams,
type GenerateSetChainRateLimitResult,
type GenerateSetRateLimitAdminParams,
type GenerateSetRateLimitAdminResult,
type GenerateSetRebalancerParams,
type GenerateSetRebalancerResult,
type GenerateTransferOwnershipParams,
type GenerateTransferOwnershipResult,
type GetTokenPoolRemotesParams,
Expand All @@ -144,8 +152,10 @@ import {
GetTokenPoolState,
InitChainRemoteConfig,
RemoveFromAllowlist,
SetCanAcceptLiquidity,
SetChainRateLimit,
SetRateLimitAdmin,
SetRebalancer,
TransferOwnership,
} from './token-pool/operations/index.ts'

Expand Down Expand Up @@ -180,8 +190,10 @@ export class SolanaTokenManager extends TokenManager<typeof ChainFamily.Solana>
readonly #getTokenPoolState = new GetTokenPoolState()
readonly #initChainRemoteConfig = new InitChainRemoteConfig()
readonly #removeFromAllowlist = new RemoveFromAllowlist()
readonly #setCanAcceptLiquidity = new SetCanAcceptLiquidity()
readonly #setChainRateLimit = new SetChainRateLimit()
readonly #setRateLimitAdmin = new SetRateLimitAdmin()
readonly #setRebalancer = new SetRebalancer()
readonly #transferOwnership = new TransferOwnership()

/** Creates a Solana CCT manager for an existing chain. */
Expand Down Expand Up @@ -1058,6 +1070,157 @@ export class SolanaTokenManager extends TokenManager<typeof ChainFamily.Solana>
return this.#setRateLimitAdmin.execute(this.chain, opts)
}

/**
* Builds an unsigned instruction that sets whether an initialized Solana lock-release token pool
* accepts `provideLiquidity` deposits and `withdrawLiquidity` transfers. Pass canonical
* `poolType: 'lock-release'` or a compatible `poolProgramAddress`; `authority` defaults to `payer`.
*
* @remarks
* ⚠️ **Consequence:** Setting `allow` to `true` lets the rebalancer both `provideLiquidity` and
* `withdrawLiquidity`. Setting `allow` to `false` **disables both** — liquidity already in the pool cannot be
* withdrawn until `allow` is re-enabled. Verify the current liquidity balance before flipping to `false`.
*
* @see {@link setCanAcceptLiquidity}
* @see {@link generateUnsignedSetRebalancer}
*
* @throws {@link CCTParamsInvalidError} If `allow`, a pool parameter, or public key is invalid.
*
* @example
* ```ts
* const cct = SolanaTokenManager.fromChain(chain)
* const unsigned = await cct.generateUnsignedSetCanAcceptLiquidity({
* tokenAddress: mint,
* poolType: 'lock-release',
* allow: true,
* payer,
* authority,
* })
* ```
*/
generateUnsignedSetCanAcceptLiquidity(
opts: GenerateSetCanAcceptLiquidityParams,
): Promise<GenerateSetCanAcceptLiquidityResult> {
return this.#setCanAcceptLiquidity.generate(this.chain, opts)
}

/**
* Sets whether an initialized Solana lock-release token pool accepts `provideLiquidity` deposits
* and `withdrawLiquidity` transfers using the pool owner wallet.
*
* @remarks
* ⚠️ **Consequence:** Setting `allow` to `true` lets the rebalancer both `provideLiquidity` and
* `withdrawLiquidity`. Setting `allow` to `false` **disables both** — liquidity already in the pool cannot be
* withdrawn until `allow` is re-enabled. Verify the current liquidity balance before flipping to `false`.
*
* @see {@link generateUnsignedSetCanAcceptLiquidity}
* @see {@link setRebalancer}
*
* @throws {@link CCIPWalletInvalidError} If `wallet` cannot sign Solana transactions.
* @throws {@link CCTParamsInvalidError} If `allow` or a pool parameter is invalid, or the authority differs
* from the executing wallet.
* @throws {@link CCTTxFailedError} If the wallet is not the pool owner or simulation/submission fails.
*
* @example
* ```ts
* const cct = SolanaTokenManager.fromChain(chain)
* await cct.setCanAcceptLiquidity({
* tokenAddress: mint,
* poolType: 'lock-release',
* allow: true,
* wallet,
* })
* ```
*/
setCanAcceptLiquidity(
opts: ExecuteSetCanAcceptLiquidityParams,
): Promise<ExecuteSetCanAcceptLiquidityResult> {
return this.#setCanAcceptLiquidity.execute(this.chain, opts)
}

/**
* Builds an unsigned instruction that sets the address authorized to provide or withdraw
* liquidity for an initialized Solana lock-release token pool. Pass canonical
* `poolType: 'lock-release'` or a compatible `poolProgramAddress`; `authority` defaults to
* `payer`. The default/zero public key (`11111111111111111111111111111111`) disables
* rebalancing.
*
* @remarks
* ⚠️ **Consequence:** Rebalancer is the address allowed to provide or withdraw liquidity.
* Setting the zero address (`11111111111111111111111111111111`) removes the rebalancer; until a new one
* is set, **no account can provide or withdraw liquidity**, even liquidity already in the pool.
* This does not affect whether the pool accepts liquidity — see {@link setCanAcceptLiquidity}.
*
* @see {@link setRebalancer}
* @see {@link setCanAcceptLiquidity}
* @see {@link generateUnsignedSetCanAcceptLiquidity}
*
* @throws {@link CCTParamsInvalidError} If a pool parameter or public key is invalid.
*
* @example
* ```ts
* const cct = SolanaTokenManager.fromChain(chain)
* const unsigned = await cct.generateUnsignedSetRebalancer({
* tokenAddress: mint,
* poolType: 'lock-release',
* rebalancer,
* payer,
* authority,
* })
* ```
*/
generateUnsignedSetRebalancer(
opts: GenerateSetRebalancerParams,
): Promise<GenerateSetRebalancerResult> {
return this.#setRebalancer.generate(this.chain, opts)
}

/**
* Sets the address authorized to provide or withdraw liquidity for an initialized Solana
* lock-release token pool using the pool owner wallet. Pass canonical `poolType: 'lock-release'`
* or a compatible `poolProgramAddress`; set `rebalancer` to the default/zero public key
* (`11111111111111111111111111111111`) to disable rebalancing.
*
* @remarks
* ⚠️ **Consequence:** Rebalancer is the address allowed to provide or withdraw liquidity.
* Setting the zero address (`11111111111111111111111111111111`) removes the rebalancer; until a new one
* is set, **no account can provide or withdraw liquidity**, even liquidity already in the pool.
* This does not affect whether the pool accepts liquidity — see {@link setCanAcceptLiquidity}.
*
* @see {@link generateUnsignedSetRebalancer}
* @see {@link setCanAcceptLiquidity}
* @see {@link generateUnsignedSetCanAcceptLiquidity}
*
* @throws {@link CCIPWalletInvalidError} If `wallet` cannot sign Solana transactions.
* @throws {@link CCTParamsInvalidError} If a pool parameter is invalid or the authority differs
* from the executing wallet.
* @throws {@link CCTTxFailedError} If the wallet is not the pool owner or simulation/submission fails.
*
* @example
* ```ts
* const cct = SolanaTokenManager.fromChain(chain)
* await cct.setRebalancer({
* tokenAddress: mint,
* poolType: 'lock-release',
* rebalancer,
* wallet,
* })
* ```
*
* @example Disable rebalancing
* ```ts
* const cct = SolanaTokenManager.fromChain(chain)
* await cct.setRebalancer({
* tokenAddress: mint,
* poolType: 'lock-release',
* rebalancer: PublicKey.default.toBase58(), // disable
* wallet,
* })
* ```
*/
setRebalancer(opts: ExecuteSetRebalancerParams): Promise<ExecuteSetRebalancerResult> {
return this.#setRebalancer.execute(this.chain, opts)
}

/**
* Builds an unsigned instruction that proposes a new owner for an initialized Solana token pool.
* Pass canonical `poolType` or a compatible `poolProgramAddress`; `authority` defaults to `payer`.
Expand Down
12 changes: 11 additions & 1 deletion ccip-sdk/src/cct/solana/programs/token-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PublicKey } from '@solana/web3.js'
import { CCIPError } from '../../../errors/index.ts'
import {
type TokenPoolConfig,
LOCK_RELEASE_TOKEN_POOL_IDL,
TOKEN_POOL_IDL,
tokenPoolCoder,
} from '../../../solana/idl/token-pool-coder.ts'
Expand Down Expand Up @@ -64,7 +65,7 @@ export function resolveTokenPoolProgram(poolType: TokenPoolType): PublicKey {
return new PublicKey(TOKEN_POOL_PROGRAMS[poolType])
}

/** Creates an Anchor Program client for a token pool program. */
/** Creates an Anchor Program client for a burn-mint token pool program. */
export function createTokenPoolProgram(
chain: SolanaChain,
poolProgram: PublicKey,
Expand All @@ -73,6 +74,15 @@ export function createTokenPoolProgram(
return new Program(TOKEN_POOL_IDL, poolProgram, simulationProvider(chain, payer))
}

/** Creates an Anchor Program client for a lock-release token pool program. */
export function createLockReleaseTokenPoolProgram(
chain: SolanaChain,
poolProgram: PublicKey,
payer: PublicKey,
) {
return new Program(LOCK_RELEASE_TOKEN_POOL_IDL, poolProgram, simulationProvider(chain, payer))
}

/** Decodes a canonical token pool state account. */
export function decodeTokenPoolState(
data: Buffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ export * from './append-to-lookup-table.ts'
export * from './create-lookup-table.ts'
export * from './get-supported-tokens.ts'
export * from './get-token-admin-registry.ts'
export * from './register-admin.ts'
export { RegisterAdmin } from './register-admin.ts'
export type {
ExecuteRegisterAdminParams,
ExecuteRegisterAdminResult,
GenerateRegisterAdminParams,
GenerateRegisterAdminResult,
RegisterAdminMethod,
} from './register-admin.ts'
export * from './set-pool.ts'
export * from './transfer-admin.ts'
2 changes: 2 additions & 0 deletions ccip-sdk/src/cct/solana/token-pool/operations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export * from './get-token-pool-remotes.ts'
export * from './get-token-pool-state.ts'
export * from './init-chain-remote-config.ts'
export * from './remove-from-allowlist.ts'
export * from './set-can-accept-liquidity.ts'
export * from './set-chain-rate-limit.ts'
export * from './set-rate-limit-admin.ts'
export * from './set-rebalancer.ts'
export * from './transfer-ownership.ts'
Loading
Loading