Onchain.Aave.V4.PositionManager (onchain_aave v0.4.0)

Copy Markdown View Source

Aave V4 Giver and Taker Position Manager write wrappers, plus Taker allowances.

V4 has no Pool. Supply and repay go through the Giver Position Manager (:v4_giver_position_manager); borrow and withdraw go through the Taker (:v4_taker_position_manager). Reserves are addressed by a Spoke-scoped reserve_id (from Onchain.Aave.V4.Spoke), not by asset address.

Every *OnBehalfOf and allowance-gated entrypoint takes the position owner as an explicit required argument. The wrappers never default the owner to the signer address. approve_borrow/5 and approve_withdraw/5 have no owner argument because the on-chain functions grant allowance from msg.sender.

Error Format

SourceError Shape
Onchain.Address.validate/1{:error, {:invalid_address, input}}
Amount / reserve id{:error, {:invalid_amount, input}}, {:error, {:invalid_reserve_id, input}}
Onchain.Aave.Contracts.address/2{:error, {:unsupported_network, network}}, {:error, {:unknown_contract, key}}
Taker allowance reverts{:error, {:insufficient_borrow_allowance, allowance, required}}, {:error, {:insufficient_withdraw_allowance, allowance, required}}
Onchain.ABI.encode_call/2{:error, {:encode_error, reason}}
Onchain.Contract.call/5{:error, {:rpc_error, map}}, {:error, {:decode_error, reason}}
Onchain.Signer.send_transaction/3{:error, {:missing_option, ...}}, {:error, {:sign_error, ...}}, etc.

Functions

FunctionPurpose
supply/5Giver supplyOnBehalfOf
repay/5Giver repayOnBehalfOf
borrow/5Taker borrowOnBehalfOf
withdraw/5Taker withdrawOnBehalfOf
approve_borrow/5Taker approveBorrow
approve_withdraw/5Taker approveWithdraw
renounce_borrow_allowance/4Taker renounceBorrowAllowance
renounce_withdraw_allowance/4Taker renounceWithdrawAllowance
borrow_allowance/5Taker borrowAllowance
withdraw_allowance/5Taker withdrawAllowance
decode_revert/1Decode Taker allowance custom-error revert data

API Functions

FunctionArityDescriptionParam Kinds
decode_revert1Decode Taker InsufficientBorrow/WithdrawAllowance custom-error revert data.revert_data: value
withdraw_allowance5Read the Taker withdraw allowance a spender holds from a position owner.spoke: value, reserve_id: value, owner: value, spender: value, opts: value
borrow_allowance5Read the Taker borrow allowance a spender holds from a position owner.spoke: value, reserve_id: value, owner: value, spender: value, opts: value
renounce_withdraw_allowance4Renounce the Taker withdraw allowance granted by a position owner.spoke: value, reserve_id: value, owner: value, opts: value
renounce_borrow_allowance4Renounce the Taker borrow allowance granted by a position owner.spoke: value, reserve_id: value, owner: value, opts: value
approve_withdraw5Grant a spender Taker withdraw allowance from the signer (msg.sender) position.spoke: value, reserve_id: value, spender: value, amount: value, opts: value
approve_borrow5Grant a spender Taker borrow allowance from the signer (msg.sender) position.spoke: value, reserve_id: value, spender: value, amount: value, opts: value
withdraw5Withdraw from a Spoke reserve on behalf of a position owner via the Taker.spoke: value, reserve_id: value, amount: value, on_behalf_of: value, opts: value
borrow5Borrow from a Spoke reserve on behalf of a position owner via the Taker.spoke: value, reserve_id: value, amount: value, on_behalf_of: value, opts: value
repay5Repay a Spoke reserve debt on behalf of a position owner via the Giver.spoke: value, reserve_id: value, amount: value, on_behalf_of: value, opts: value
supply5Supply underlying to a Spoke reserve on behalf of a position owner via the Giver.spoke: value, reserve_id: value, amount: value, on_behalf_of: value, opts: value

Summary

Functions

Grant a spender Taker borrow allowance from the signer (msg.sender) position.

Grant a spender Taker withdraw allowance from the signer (msg.sender) position.

Borrow from a Spoke reserve on behalf of a position owner via the Taker.

Read the Taker borrow allowance a spender holds from a position owner.

Decode Taker InsufficientBorrow/WithdrawAllowance custom-error revert data.

Renounce the Taker borrow allowance granted by a position owner.

Renounce the Taker withdraw allowance granted by a position owner.

Repay a Spoke reserve debt on behalf of a position owner via the Giver.

Supply underlying to a Spoke reserve on behalf of a position owner via the Giver.

Withdraw from a Spoke reserve on behalf of a position owner via the Taker.

Read the Taker withdraw allowance a spender holds from a position owner.

Types

address()

@type address() :: String.t() | binary()

result(value)

@type result(value) :: {:ok, value} | {:error, term()}

Functions

approve_borrow(spoke, reserve_id, spender, amount, opts)

@spec approve_borrow(
  address(),
  non_neg_integer(),
  address(),
  non_neg_integer(),
  keyword()
) ::
  result(String.t())

Grant a spender Taker borrow allowance from the signer (msg.sender) position.

Parameters

  • spoke - Spoke contract address as 0x hex string or 20-byte binary (value)
  • reserve_id - Spoke-local reserve identifier (not an asset address) (value)
  • spender - Address receiving (or holding) the Taker allowance (value)
  • amount - Allowance amount; type(uint256).max is infinite (value)
  • opts - Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (value)

Returns

Transaction hash hex string ({:ok, String.t()} | {:error, term()})

# descripex:contract
%{
  params: %{
    opts: %{
      description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit",
      kind: :value
    },
    amount: %{
      description: "Allowance amount; `type(uint256).max` is infinite",
      kind: :value
    },
    spender: %{
      description: "Address receiving (or holding) the Taker allowance",
      kind: :value
    },
    spoke: %{
      description: "Spoke contract address as 0x hex string or 20-byte binary",
      kind: :value
    },
    reserve_id: %{
      description: "Spoke-local reserve identifier (not an asset address)",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, String.t()} | {:error, term()}",
    description: "Transaction hash hex string"
  }
}

approve_withdraw(spoke, reserve_id, spender, amount, opts)

@spec approve_withdraw(
  address(),
  non_neg_integer(),
  address(),
  non_neg_integer(),
  keyword()
) ::
  result(String.t())

Grant a spender Taker withdraw allowance from the signer (msg.sender) position.

Parameters

  • spoke - Spoke contract address as 0x hex string or 20-byte binary (value)
  • reserve_id - Spoke-local reserve identifier (not an asset address) (value)
  • spender - Address receiving (or holding) the Taker allowance (value)
  • amount - Allowance amount; type(uint256).max is infinite (value)
  • opts - Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (value)

Returns

Transaction hash hex string ({:ok, String.t()} | {:error, term()})

# descripex:contract
%{
  params: %{
    opts: %{
      description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit",
      kind: :value
    },
    amount: %{
      description: "Allowance amount; `type(uint256).max` is infinite",
      kind: :value
    },
    spender: %{
      description: "Address receiving (or holding) the Taker allowance",
      kind: :value
    },
    spoke: %{
      description: "Spoke contract address as 0x hex string or 20-byte binary",
      kind: :value
    },
    reserve_id: %{
      description: "Spoke-local reserve identifier (not an asset address)",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, String.t()} | {:error, term()}",
    description: "Transaction hash hex string"
  }
}

borrow(spoke, reserve_id, amount, on_behalf_of, opts)

Borrow from a Spoke reserve on behalf of a position owner via the Taker.

Parameters

  • spoke - Spoke contract address as 0x hex string or 20-byte binary (value)
  • reserve_id - Spoke-local reserve identifier (not an asset address) (value)
  • amount - Raw integer amount in underlying token units (value)
  • on_behalf_of - Position owner. Required; never defaulted to the signer (value)
  • opts - Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (value)

Returns

Transaction hash hex string ({:ok, String.t()} | {:error, term()})

# descripex:contract
%{
  params: %{
    opts: %{
      description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit",
      kind: :value
    },
    amount: %{
      description: "Raw integer amount in underlying token units",
      kind: :value
    },
    on_behalf_of: %{
      description: "Position owner. Required; never defaulted to the signer",
      kind: :value
    },
    spoke: %{
      description: "Spoke contract address as 0x hex string or 20-byte binary",
      kind: :value
    },
    reserve_id: %{
      description: "Spoke-local reserve identifier (not an asset address)",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, String.t()} | {:error, term()}",
    description: "Transaction hash hex string"
  }
}

borrow_allowance(spoke, reserve_id, owner, spender, opts \\ [])

@spec borrow_allowance(address(), non_neg_integer(), address(), address(), keyword()) ::
  result(non_neg_integer())

Read the Taker borrow allowance a spender holds from a position owner.

Parameters

  • spoke - Spoke contract address as 0x hex string or 20-byte binary (value)
  • reserve_id - Spoke-local reserve identifier (not an asset address) (value)
  • owner - Position owner. Required; never defaulted to the signer (value)
  • spender - Address receiving (or holding) the Taker allowance (value)
  • opts - Options: :network (default :ethereum), :rpc_url, :timeout, :block (default: [], value)

Returns

Current borrow allowance ({:ok, non_neg_integer()} | {:error, term()})

# descripex:contract
%{
  params: %{
    owner: %{
      description: "Position owner. Required; never defaulted to the signer",
      kind: :value
    },
    opts: %{
      default: [],
      description: "Options: :network (default :ethereum), :rpc_url, :timeout, :block",
      kind: :value
    },
    spender: %{
      description: "Address receiving (or holding) the Taker allowance",
      kind: :value
    },
    spoke: %{
      description: "Spoke contract address as 0x hex string or 20-byte binary",
      kind: :value
    },
    reserve_id: %{
      description: "Spoke-local reserve identifier (not an asset address)",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, non_neg_integer()} | {:error, term()}",
    description: "Current borrow allowance"
  }
}

decode_revert(revert_data)

@spec decode_revert(String.t() | binary()) ::
  {:error,
   {:insufficient_borrow_allowance, non_neg_integer(), non_neg_integer()}}
  | {:error,
     {:insufficient_withdraw_allowance, non_neg_integer(), non_neg_integer()}}
  | {:error, {:unknown_revert, term()}}

Decode Taker InsufficientBorrow/WithdrawAllowance custom-error revert data.

Parameters

  • revert_data - 0x-prefixed hex or raw revert bytes (4-byte selector + ABI args) (value)

Returns

Tagged allowance error with (allowance, required), or unknown_revert ({:error, {:insufficient_borrow_allowance | :insufficient_withdraw_allowance, non_neg_integer(), non_neg_integer()}} | {:error, {:unknown_revert, term()}})

# descripex:contract
%{
  params: %{
    revert_data: %{
      description: "0x-prefixed hex or raw revert bytes (4-byte selector + ABI args)",
      kind: :value
    }
  },
  returns: %{
    type: "{:error, {:insufficient_borrow_allowance | :insufficient_withdraw_allowance, non_neg_integer(), non_neg_integer()}} | {:error, {:unknown_revert, term()}}",
    description: "Tagged allowance error with (allowance, required), or unknown_revert"
  }
}

renounce_borrow_allowance(spoke, reserve_id, owner, opts)

@spec renounce_borrow_allowance(address(), non_neg_integer(), address(), keyword()) ::
  result(String.t())

Renounce the Taker borrow allowance granted by a position owner.

Parameters

  • spoke - Spoke contract address as 0x hex string or 20-byte binary (value)
  • reserve_id - Spoke-local reserve identifier (not an asset address) (value)
  • owner - Position owner. Required; never defaulted to the signer (value)
  • opts - Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (value)

Returns

Transaction hash hex string ({:ok, String.t()} | {:error, term()})

# descripex:contract
%{
  params: %{
    owner: %{
      description: "Position owner. Required; never defaulted to the signer",
      kind: :value
    },
    opts: %{
      description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit",
      kind: :value
    },
    spoke: %{
      description: "Spoke contract address as 0x hex string or 20-byte binary",
      kind: :value
    },
    reserve_id: %{
      description: "Spoke-local reserve identifier (not an asset address)",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, String.t()} | {:error, term()}",
    description: "Transaction hash hex string"
  }
}

renounce_withdraw_allowance(spoke, reserve_id, owner, opts)

@spec renounce_withdraw_allowance(address(), non_neg_integer(), address(), keyword()) ::
  result(String.t())

Renounce the Taker withdraw allowance granted by a position owner.

Parameters

  • spoke - Spoke contract address as 0x hex string or 20-byte binary (value)
  • reserve_id - Spoke-local reserve identifier (not an asset address) (value)
  • owner - Position owner. Required; never defaulted to the signer (value)
  • opts - Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (value)

Returns

Transaction hash hex string ({:ok, String.t()} | {:error, term()})

# descripex:contract
%{
  params: %{
    owner: %{
      description: "Position owner. Required; never defaulted to the signer",
      kind: :value
    },
    opts: %{
      description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit",
      kind: :value
    },
    spoke: %{
      description: "Spoke contract address as 0x hex string or 20-byte binary",
      kind: :value
    },
    reserve_id: %{
      description: "Spoke-local reserve identifier (not an asset address)",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, String.t()} | {:error, term()}",
    description: "Transaction hash hex string"
  }
}

repay(spoke, reserve_id, amount, on_behalf_of, opts)

Repay a Spoke reserve debt on behalf of a position owner via the Giver.

Parameters

  • spoke - Spoke contract address as 0x hex string or 20-byte binary (value)
  • reserve_id - Spoke-local reserve identifier (not an asset address) (value)
  • amount - Raw integer amount in underlying token units (value)
  • on_behalf_of - Position owner. Required; never defaulted to the signer (value)
  • opts - Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (value)

Returns

Transaction hash hex string ({:ok, String.t()} | {:error, term()})

# descripex:contract
%{
  params: %{
    opts: %{
      description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit",
      kind: :value
    },
    amount: %{
      description: "Raw integer amount in underlying token units",
      kind: :value
    },
    on_behalf_of: %{
      description: "Position owner. Required; never defaulted to the signer",
      kind: :value
    },
    spoke: %{
      description: "Spoke contract address as 0x hex string or 20-byte binary",
      kind: :value
    },
    reserve_id: %{
      description: "Spoke-local reserve identifier (not an asset address)",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, String.t()} | {:error, term()}",
    description: "Transaction hash hex string"
  }
}

supply(spoke, reserve_id, amount, on_behalf_of, opts)

Supply underlying to a Spoke reserve on behalf of a position owner via the Giver.

Parameters

  • spoke - Spoke contract address as 0x hex string or 20-byte binary (value)
  • reserve_id - Spoke-local reserve identifier (not an asset address) (value)
  • amount - Raw integer amount in underlying token units (value)
  • on_behalf_of - Position owner. Required; never defaulted to the signer (value)
  • opts - Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (value)

Returns

Transaction hash hex string ({:ok, String.t()} | {:error, term()})

# descripex:contract
%{
  params: %{
    opts: %{
      description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit",
      kind: :value
    },
    amount: %{
      description: "Raw integer amount in underlying token units",
      kind: :value
    },
    on_behalf_of: %{
      description: "Position owner. Required; never defaulted to the signer",
      kind: :value
    },
    spoke: %{
      description: "Spoke contract address as 0x hex string or 20-byte binary",
      kind: :value
    },
    reserve_id: %{
      description: "Spoke-local reserve identifier (not an asset address)",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, String.t()} | {:error, term()}",
    description: "Transaction hash hex string"
  }
}

withdraw(spoke, reserve_id, amount, on_behalf_of, opts)

@spec withdraw(address(), non_neg_integer(), non_neg_integer(), address(), keyword()) ::
  result(String.t())

Withdraw from a Spoke reserve on behalf of a position owner via the Taker.

Parameters

  • spoke - Spoke contract address as 0x hex string or 20-byte binary (value)
  • reserve_id - Spoke-local reserve identifier (not an asset address) (value)
  • amount - Raw integer amount in underlying token units (value)
  • on_behalf_of - Position owner. Required; never defaulted to the signer (value)
  • opts - Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit (value)

Returns

Transaction hash hex string ({:ok, String.t()} | {:error, term()})

# descripex:contract
%{
  params: %{
    opts: %{
      description: "Required: :private_key, :nonce, :chain_id, :rpc_url. Optional: :network (default :ethereum), :gas_limit",
      kind: :value
    },
    amount: %{
      description: "Raw integer amount in underlying token units",
      kind: :value
    },
    on_behalf_of: %{
      description: "Position owner. Required; never defaulted to the signer",
      kind: :value
    },
    spoke: %{
      description: "Spoke contract address as 0x hex string or 20-byte binary",
      kind: :value
    },
    reserve_id: %{
      description: "Spoke-local reserve identifier (not an asset address)",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, String.t()} | {:error, term()}",
    description: "Transaction hash hex string"
  }
}

withdraw_allowance(spoke, reserve_id, owner, spender, opts \\ [])

@spec withdraw_allowance(
  address(),
  non_neg_integer(),
  address(),
  address(),
  keyword()
) ::
  result(non_neg_integer())

Read the Taker withdraw allowance a spender holds from a position owner.

Parameters

  • spoke - Spoke contract address as 0x hex string or 20-byte binary (value)
  • reserve_id - Spoke-local reserve identifier (not an asset address) (value)
  • owner - Position owner. Required; never defaulted to the signer (value)
  • spender - Address receiving (or holding) the Taker allowance (value)
  • opts - Options: :network (default :ethereum), :rpc_url, :timeout, :block (default: [], value)

Returns

Current withdraw allowance ({:ok, non_neg_integer()} | {:error, term()})

# descripex:contract
%{
  params: %{
    owner: %{
      description: "Position owner. Required; never defaulted to the signer",
      kind: :value
    },
    opts: %{
      default: [],
      description: "Options: :network (default :ethereum), :rpc_url, :timeout, :block",
      kind: :value
    },
    spender: %{
      description: "Address receiving (or holding) the Taker allowance",
      kind: :value
    },
    spoke: %{
      description: "Spoke contract address as 0x hex string or 20-byte binary",
      kind: :value
    },
    reserve_id: %{
      description: "Spoke-local reserve identifier (not an asset address)",
      kind: :value
    }
  },
  returns: %{
    type: "{:ok, non_neg_integer()} | {:error, term()}",
    description: "Current withdraw allowance"
  }
}