aoffp
v0.2.0
Published
[简体中文](./README_CN.md) | English
Downloads
54
Readme
aoffp
简体中文 | English
Installation
npm install aoffp
# or
yarn add aoffp
Using Basic Agent Model
Get Settle Process ID
import { getSettleProcessId } from 'aoffp'
const settleProcessId = getSettleProcessId()
console.log('settleProcessId', settleProcessId)
Create Basic Agent Process
If you haven't created a basic agent process, you need to create one.
import { createBasicProcess } from 'aoffp'
import { createDataItemSigner } from '@permaweb/aoconnect'
const signer = createDataItemSigner(arJWK)
const settleProcessId = getSettleProcessId()
const agent = await createBasicProcess(signer)
const agentProcessId = agent.agentId
console.log('agentProcessId', agentProcessId)
Create Basic Agent Instance
import { Basic } from 'aoffp'
import { createDataItemSigner } from '@permaweb/aoconnect'
const signer = createDataItemSigner(arJWK)
const agentProcessId = 'your-agent-process-id'
const settleProcessId = getSettleProcessId()
const agent = new Basic(signer, agentProcessId, settleProcessId)
Deposit to Basic Agent Process
const depositMessageId = await agent.deposit(tokenProcessId, quantity)
console.log('depositMessageId', depositMessageId)
Withdraw from Basic Agent Process
const withdrawMessageId = await agent.withdraw(tokenProcessId, quantity)
console.log('withdrawMessageId', withdrawMessageId)
Get All Orders (Including Orders from Others)
- tokenInProcessId: Process ID of the token to sell
- tokenOutProcessId: Process ID of the token to buy
- status: Order status, can be
'Open'
|'Settled'
|'Canceled'
, where'Open'
represents unfilled orders,'Settled'
represents filled orders, and'Canceled'
represents canceled orders - desc: Sort by order price in descending order, default is
false
- page: Page number, default is 1
- pageSize: Number of items per page, default is 10
const allOrders = await orderbook.getOrders(tokenIn: string, tokenOut: string, status: 'Open' | 'Settled' | 'Canceled', desc: boolean, page: number = 1, pageSize: number = 10)
console.log('allOrders', allOrders)
/**
[
{
ID: 1,
HolderAssetID: '4557tfvtAlS8WS0-KF0sGdfgy6An2dcVXQUGocrKV7U',
HolderAmount: '3',
NoteID: '2vlZ2ys40YTLbHC6z7dDt5O_ggv4Bn_gxQlzkq37zxA',
Issuer: 'TwgBoDbHTBpkrruRxUTom4VFC5QhaiBwN9hlsUzHd3Q',
Type: 'Orderbook',
AssetID: '-v4cUCUcRiJH67jPMUt-Uhn-K4PHxrkoySM2uqAjAF0',
IssueDate: 1726298572659,
Status: 'Open',
Amount: '1'
},
{
ID: 2,
HolderAssetID: '4557tfvtAlS8WS0-KF0sGdfgy6An2dcVXQUGocrKV7U',
HolderAmount: '3',
NoteID: 'Z-OBeKQX6CEvTcb013fJhU2H8Kxildc-p3OKXRvziBA',
Issuer: 'TwgBoDbHTBpkrruRxUTom4VFC5QhaiBwN9hlsUzHd3Q',
Type: 'Orderbook',
AssetID: '-v4cUCUcRiJH67jPMUt-Uhn-K4PHxrkoySM2uqAjAF0',
IssueDate: 1727248424967,
Status: 'Open',
Amount: '1'
}
]
*/
Get My Orders in Basic Agent
- tokenInProcessId: Process ID of the token to sell
- tokenOutProcessId: Process ID of the token to buy
- status: Order status, can be
'Open'
|'Settled'
|'Canceled'
, also accepts comma-separated values like'Open,Settled'
,'Open,Settled,Canceled'
, where'Open'
represents unfilled orders,'Settled'
represents filled orders, and'Canceled'
represents canceled orders - desc: Sort by
IssueDate
in descending order, default isfalse
- page: Page number, default is 1
- pageSize: Number of items per page, default is 10
const myOrders = await agent.getMyOrders(tokenInProcessId: string, tokenOutProcessId: string, status: 'Open' | 'Settled' | 'Canceled', desc: boolean, page: number = 1, pageSize: number = 10)
console.log('myOrders', myOrders)
/**
[
{
ID: 1,
HolderAssetID: '4557tfvtAlS8WS0-KF0sGdfgy6An2dcVXQUGocrKV7U',
HolderAmount: '3',
NoteID: '2vlZ2ys40YTLbHC6z7dDt5O_ggv4Bn_gxQlzkq37zxA',
Issuer: 'TwgBoDbHTBpkrruRxUTom4VFC5QhaiBwN9hlsUzHd3Q',
Type: 'Orderbook',
AssetID: '-v4cUCUcRiJH67jPMUt-Uhn-K4PHxrkoySM2uqAjAF0',
IssueDate: 1726298572659,
Status: 'Open',
Amount: '1'
},
{
ID: 2,
HolderAssetID: '4557tfvtAlS8WS0-KF0sGdfgy6An2dcVXQUGocrKV7U',
HolderAmount: '3',
NoteID: 'Z-OBeKQX6CEvTcb013fJhU2H8Kxildc-p3OKXRvziBA',
Issuer: 'TwgBoDbHTBpkrruRxUTom4VFC5QhaiBwN9hlsUzHd3Q',
Type: 'Orderbook',
AssetID: '-v4cUCUcRiJH67jPMUt-Uhn-K4PHxrkoySM2uqAjAF0',
IssueDate: 1727248424967,
Status: 'Open',
Amount: '1'
}
]
*/
Get Order Details
const order = await agent.getOrder(noteId)
console.log('order', order)
Take Order
const takeOrderMessageId = await agent.takeOrder([noteId1, noteId2, ...])
console.log('takeOrderMessageId', takeOrderMessageId)
Get Take Order Result
const takeOrderResult = await getProcessResult(takeOrderMessageId, agentProcessId)
console.log('takeOrderResult', JSON.stringify(takeOrderResult, null, 2))
Using Orderbook Model
Get Settle Process ID
import { getSettleProcessId } from 'aoffp'
const settleProcessId = getSettleProcessId()
console.log('settleProcessId', settleProcessId)
Create Orderbook Process
If you haven't created an orderbook process, you need to create one.
import { createOrderbookProcess } from 'aoffp'
import { createDataItemSigner } from '@permaweb/aoconnect'
const address = 'your-arweave-address'
const signer = createDataItemSigner(arJWK)
const settleProcessId = getSettleProcessId()
const orderbookAgent = await createOrderbookProcess(signer)
const orderbookProcessId = orderbookAgent.agentId
console.log('orderbookProcessId', orderbookProcessId)
Create Orderbook Instance
import { Orderbook } from 'aoffp'
import { createDataItemSigner } from '@permaweb/aoconnect'
const signer = createDataItemSigner(arJWK)
const orderbookProcessId = 'your-orderbook-process-id'
const settleProcessId = getSettleProcessId()
const orderbook = new Orderbook(signer, orderbookProcessId, settleProcessId)
Deposit to Orderbook Process
const depositMessageId = await orderbook.deposit(tokenProcessId, quantity)
console.log('depositMessageId', depositMessageId)
Withdraw from Orderbook Process
const withdrawMessageId = await orderbook.withdraw(tokenProcessId, quantity)
console.log('withdrawMessageId', withdrawMessageId)
Make Order
const order = await orderbook.makeOrder(tokenInProcessId, tokenOutProcessId, quantityIn, quantityOut)
console.log('order', order)
Get All Orders (Including Orders from Others)
- tokenInProcessId: Process ID of the token to sell
- tokenOutProcessId: Process ID of the token to buy
- status: Order status, can be
'Open'
|'Settled'
|'Canceled'
, where'Open'
represents unfilled orders,'Settled'
represents filled orders, and'Canceled'
represents canceled orders - desc: Sort by order price in descending order, default is
false
- page: Page number, default is 1
- pageSize: Number of items per page, default is 10
const allOrders = await orderbook.getOrders(tokenIn: string, tokenOut: string, status: 'Open' | 'Settled' | 'Canceled', desc: boolean, page: number = 1, pageSize: number = 10)
console.log('allOrders', allOrders)
/**
[
{
ID: 1,
HolderAssetID: '4557tfvtAlS8WS0-KF0sGdfgy6An2dcVXQUGocrKV7U',
HolderAmount: '3',
NoteID: '2vlZ2ys40YTLbHC6z7dDt5O_ggv4Bn_gxQlzkq37zxA',
Issuer: 'TwgBoDbHTBpkrruRxUTom4VFC5QhaiBwN9hlsUzHd3Q',
Type: 'Orderbook',
AssetID: '-v4cUCUcRiJH67jPMUt-Uhn-K4PHxrkoySM2uqAjAF0',
IssueDate: 1726298572659,
Status: 'Open',
Amount: '1'
},
{
ID: 2,
HolderAssetID: '4557tfvtAlS8WS0-KF0sGdfgy6An2dcVXQUGocrKV7U',
HolderAmount: '3',
NoteID: 'Z-OBeKQX6CEvTcb013fJhU2H8Kxildc-p3OKXRvziBA',
Issuer: 'TwgBoDbHTBpkrruRxUTom4VFC5QhaiBwN9hlsUzHd3Q',
Type: 'Orderbook',
AssetID: '-v4cUCUcRiJH67jPMUt-Uhn-K4PHxrkoySM2uqAjAF0',
IssueDate: 1727248424967,
Status: 'Open',
Amount: '1'
}
]
*/
Get My Orders in Orderbook
- tokenInProcessId: Process ID of the token to sell
- tokenOutProcessId: Process ID of the token to buy
- status: Order status, can be
'Open'
|'Settled'
|'Canceled'
, also accepts comma-separated values like'Open,Settled'
,'Open,Settled,Canceled'
, where'Open'
represents unfilled orders,'Settled'
represents filled orders, and'Canceled'
represents canceled orders - desc: Sort by
IssueDate
in descending order, default isfalse
- page: Page number, default is 1
- pageSize: Number of items per page, default is 10
const myOrders = await orderbook.getMyOrders(tokenInProcessId: string, tokenOutProcessId: string, status: 'Open' | 'Settled' | 'Canceled', desc: boolean, page: number = 1, pageSize: number = 10)
console.log('myOrders', myOrders)
/**
[
{
ID: 1,
HolderAssetID: '4557tfvtAlS8WS0-KF0sGdfgy6An2dcVXQUGocrKV7U',
HolderAmount: '3',
NoteID: '2vlZ2ys40YTLbHC6z7dDt5O_ggv4Bn_gxQlzkq37zxA',
Issuer: 'TwgBoDbHTBpkrruRxUTom4VFC5QhaiBwN9hlsUzHd3Q',
Type: 'Orderbook',
AssetID: '-v4cUCUcRiJH67jPMUt-Uhn-K4PHxrkoySM2uqAjAF0',
IssueDate: 1726298572659,
Status: 'Open',
Amount: '1'
},
{
ID: 2,
HolderAssetID: '4557tfvtAlS8WS0-KF0sGdfgy6An2dcVXQUGocrKV7U',
HolderAmount: '3',
NoteID: 'Z-OBeKQX6CEvTcb013fJhU2H8Kxildc-p3OKXRvziBA',
Issuer: 'TwgBoDbHTBpkrruRxUTom4VFC5QhaiBwN9hlsUzHd3Q',
Type: 'Orderbook',
AssetID: '-v4cUCUcRiJH67jPMUt-Uhn-K4PHxrkoySM2uqAjAF0',
IssueDate: 1727248424967,
Status: 'Open',
Amount: '1'
}
]
*/
Get Order Details
const order = await orderbook.getOrder(noteId)
console.log('order', order)
Cancel Order
const cancelOrderMessageId = await orderbook.cancelOrder(noteId)
console.log('cancelOrderMessageId', cancelOrderMessageId)
Get Cancel Order Result
const cancelOrderResult = await getProcessResult(cancelOrderMessageId, orderbookProcessId)
console.log('cancelOrderResult', JSON.stringify(cancelOrderResult, null, 2))
Take Order
const takeOrderMessageId = await orderbook.takeOrder([noteId1, noteId2, ...])
console.log('takeOrderMessageId', takeOrderMessageId)
Get Take Order Result
const takeOrderResult = await getProcessResult(takeOrderMessageId, orderbookProcessId)
console.log('takeOrderResult', JSON.stringify(takeOrderResult, null, 2))
Using AMM Model
Create AMM Process
import { createAmmProcess } from 'aoffp'
import { createDataItemSigner } from '@permaweb/aoconnect'
const signer = createDataItemSigner(arJWK)
const ammAgent = await createAmmProcess(signer)
const ammProcessId = ammAgent.agentId
console.log('ammProcessId', ammProcessId)
Create AMM Instance
import { Amm } from 'aoffp'
import { createDataItemSigner } from '@permaweb/aoconnect'
const signer = createDataItemSigner(arJWK)
const orderbookProcessId = 'your-amm-process-id'
const amm = new Amm(signer, ammProcess)
Deposit to AMM Process
const depositMessageId = await amm.deposit(tokenProcessId, quantity)
console.log('depositMessageId', depositMessageId)
Withdraw from AMM Process
const withdrawMessageId = await amm.withdraw(tokenProcessId, quantity)
console.log('withdrawMessageId', withdrawMessageId)
Create Pool
Currently supports creating two types of pools: Uniswap v2 model and BigOrder model
Create Uniswap v2 Pool
await ammAgent.addUniswapV2Pool(xTokenProcess, yTokenProcess, px, py, feeOfTenThousandths)
const pools = await ammAgent.getPools()
console.log('pools', pools)
Create BigOrder Pool
await ammAgent.addBigOrderPool(tokenInProcess, amountIn, tokenOutProcess, amountOut)
const pools = await ammAgent.getPools()
console.log('pools', pools)
Update Pool Curve
Currently only supports Uniswap v2 Pool curve updates
Update Uniswap v2 Pool Curve
await ammAgent.updateUniswapV2PoolLiquidity(xTokenProcess, yTokenProcess, newPY, newPY)
const pools = await ammAgent.getPools()
console.log('pools', pools)
Get AMM Pools Information
const pools = await amm.getPools()
console.log('pools', pools)
/*
{
'0fLIp-xxRnQ8Nk-ruq8SBY8icaIvZMujnqCGU79fnM0:AttsQGi4xgSOTeHM6CNgEVxlrdZi4Y86LQCF__p4HUM': {
py: '14',
algo: 'UniswapV2',
fee: '30',
px: '8',
y: 'AttsQGi4xgSOTeHM6CNgEVxlrdZi4Y86LQCF__p4HUM',
balances: {
'0fLIp-xxRnQ8Nk-ruq8SBY8icaIvZMujnqCGU79fnM0': '8',
AttsQGi4xgSOTeHM6CNgEVxlrdZi4Y86LQCF__p4HUM: '14'
},
x: '0fLIp-xxRnQ8Nk-ruq8SBY8icaIvZMujnqCGU79fnM0'
},
'AttsQGi4xgSOTeHM6CNgEVxlrdZi4Y86LQCF__p4HUM:J0B80MpR_koLQpdqOKA5VcaPayqQPSR5ERzdtBVnkP4': {
amountOut: '10',
algo: 'BigOrder',
tokenIn: 'J0B80MpR_koLQpdqOKA5VcaPayqQPSR5ERzdtBVnkP4',
amountIn: '10',
y: 'J0B80MpR_koLQpdqOKA5VcaPayqQPSR5ERzdtBVnkP4',
tokenOut: 'AttsQGi4xgSOTeHM6CNgEVxlrdZi4Y86LQCF__p4HUM',
balances: {
AttsQGi4xgSOTeHM6CNgEVxlrdZi4Y86LQCF__p4HUM: '8',
J0B80MpR_koLQpdqOKA5VcaPayqQPSR5ERzdtBVnkP4: '2'
},
x: 'AttsQGi4xgSOTeHM6CNgEVxlrdZi4Y86LQCF__p4HUM'
}
}
*/
Get AMM Order
const order = await ammRequest(signer, ammAgentId, tokenInProcess, tokenInAmount, tokenOut: string, amountOut?: string)
await new Promise((resolve) => {
setTimeout(resolve, 5000)
})
console.log('order', JSON.stringify(order, null, 2))
/*
{
ID: 2567,
AssetID: 'AttsQGi4xgSOTeHM6CNgEVxlrdZi4Y86LQCF__p4HUM',
MakeTx: 'wFVSJurGy3nObNeiFTHKciJruKGWMPEoW5q34OFzx-M',
ExpireDate: 1733224050340,
HolderAssetID: 'J0B80MpR_koLQpdqOKA5VcaPayqQPSR5ERzdtBVnkP4',
NoteID: 'R05uXunK2XUMVIUz_DsBghbEqm7FOhqxiXFFmuwKJGg',
IssueDate: 1733223960340,
HolderAmount: '2',
Amount: '2',
Status: 'Open',
Price: 1,
Issuer: 'iksN-6mCCaG1nrAert49rfiA0ZBgtPKVE7YLTfhTzvE'
}
*/
Take AMM Order with Basic Agent
const takeOrderMessageId = await agent.takeOrder([order.NoteID])
console.log('takeOrderMessageId', takeOrderMessageId)
Arbitrage Between Orderbook and AMM
const takeOrderMessageId = await agent.takeOrder([orderbookOrder.NoteID, ammArbitrageOrder.NoteID])
console.log('takeOrderMessageId', takeOrderMessageId)