AmbireTech / adex-protocol-eth

Ethereum implementation of the Ambire Protocol: Ambire Wallet contracts and AdEx payment channels
https://www.ambire.com
MIT License
49 stars 24 forks source link
adex advertising defi ethereum metatx payment-channels smart-wallet solidity state-channels wallet walletconnect

adex-protocol-eth

The Ethereum implementation of the AdEx Protocol.

This replaces adex-core.

This repository implements OUTPACE (off-chain unidirectional trustless payment channel) and a gas abstraction layer called AdEx Identity.

Please note

Testing

First, run ganache-cli in a separate terminal

truffle build # This is important cause js/IdentityProxyDeploy uses artifacts from there
npm test

Deployment

The contract AdExCore from version v3.1.0, compiled with solc v0.5.6 is deployed here:

An Identity, initialized with no privileges, to be used as a basis for IdentityProxy:

An IdentityFactory, set up with the AdEx relayer:

And the Registry (now obsolete, no longer used):

v4.1

All contracts here were compiled with solc v0.5.13.

The Identity, initialized with no privileges, to be used as a basis for IdentityProxy:

An IdentityFactory, set up with the AdEx relayer:

And the Staking:

v4.2

The ADXSupplyController contract:

The ADXToken contract:

An instance of IdentityFactory used for staking:

The Staking contract:

The ADXFlashLoans contract:

The ADXLoyaltyPoolToken contract:

The ADXLoyaltyPoolIncentiveController contract:

Not a base contract, but closely related to those systems. Reward distributor Identity:

v5

The SupplyController contract:

New V5 SupplyController (increased cap to account for the to-be burned staking migration ADX):

New V5 SupplyController (increased cap to account for the governance-induced burn):

New V5 SupplyController (increase cap again to account for governance-induced burn):

New V5 SupplyController (increase cap again to account for governance-induced burn and discount treasury tokens):

StakingPool:

StakingMigrator:

GaslessSweeper:

Wallet (first demo)

IdentityFactory contract:

Identity contract:

Ambire Wallet

Same addresses on Ethereum, Polygon, BSC, Fantom, Arbitrum, Avalanche, Moonbeam, Moonriver, Cronos, Metis, Gnosis Chain (formerly xDAI), NEAR Aurora

Deployment

truffle migrate --network mainnet
truffle migrate --network polygon
truffle migrate --network bsc

Verifying on etherscan

truffle compile
cat build/contracts/AdExCore.json | jq '.bytecode' # this is the bytecode you have to deploy
./scripts/bundle.sh contracts/AdExCore.sol # this will output a bundled .sol code

Gas usage, from the tests

Measured with solc v0.5.6, commit d80fa80424ef7b8932399424f8d919d67b135a30

channelOpen: 69961
channelWithdrawExpired: 70470
channelWithdraw: 137117
execute: 89900
execRoutines: 114440
channelOpen, through execute: 115086
deploying an identity proxy through the IdentityFactory: 127549
addBond  73404
requestUnbond  34807
unbond  41770

ENS

This is not a part of the adex-protocol-eth source code, but it may be useful for anyone building on top of adex-protocol-eth who wishes to integrate with ENS.

Code style and design principles

Audits

Integration guide: Identity v5.2

EIP 1271 isValidSignature doesn't work until deployed

Since isValidSignature relies on calling the Identity contract through eth_call, we need that said Identity contract (proxy) is deployed. With the relayer, this is not true until the first transaction, due to the counterfactual deployment.

dApps can actually work around this by asking the user to deploy the proxy first.

Credits