Interact with Aurora DeFi protocols with your NEAR accounts
To call a view function in one contract in Aurora, we call the view()
function on aurora
contract, with the following args
pub struct ViewCallArgs {
pub sender: RawAddress, // sender address
pub address: RawAddress, // contract address
pub amount: RawU256, // not really needed?
pub input: Vec<u8>, // parameters in HEX
}
Example
Call view function in TriSolaris contract.
export NEAR_ENV=mainnet
export AURORA_ENGINE=aurora
aurora view 0x49eb1f160e167aa7ba96bdd88b6c1f2ffda5212a 0x252dba4200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000016000000000000000000000000020f8aefb5697b77e0bb835a8518be70775cda1b0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac0000000000000000000000000000000000000000000000000000000000000000000000000000000084b123875f0f36b966d0b6ca14b31121bd9676ad000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000000000000000000000000000fa94348467f64d5a457f75f8bc40495d33c65abb0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000418160ddd00000000000000000000000000000000000000000000000000000000
P.S. Here we use eth_call
's method and input parameters in the above command.
The result is as follows, which could be decoded with contract ABI
0x0000000000000000000000000000000000000000000000000000000003836b9400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000140eb539eced0000000000000000000000000000000000000014ae42faff9d8269fbf2ac5cab0000000000000000000000000000000000000000000000000000000061ffb7de0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000bea6b7285741effb5ae25c2680000000000000000000000000000000000000000000b15cc839de6696004d3a90000000000000000000000000000000000000000000000000000000061ffb7ea0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000a1d9cebebe8debb64c3408
To call contract functions that mutate states in contracts deployed on Aurora, there're two major methods that can be invoked in aurora
contract:
submit()
which is now ususally called by Aurora Relayer who sends the transactions that are signed by user via MetaMask to Aurora Engine. The signer of the transaction (e.g. sign via MetaMask) will be the origin of transaction.call()
which can be called by any account. The encoded EVM address from the NEAR account will be the origin of the transaction.
The call arguments of aurora.call()
pub struct FunctionCallArgsV2 {
pub contract: RawAddress,
pub value: WeiU256,
pub input: Vec<u8>,
}
Example
Call mutable function that changes states in TriSolaris contract. (This tx actually calls a view function via aurora.call()
)
export NEAR_MASTER_ACCOUNT=alice.near
aurora call 0x49eb1f160e167aa7ba96bdd88b6c1f2ffda5212a 0x252dba4200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000016000000000000000000000000020f8aefb5697b77e0bb835a8518be70775cda1b0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac0000000000000000000000000000000000000000000000000000000000000000000000000000000084b123875f0f36b966d0b6ca14b31121bd9676ad000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000040902f1ac00000000000000000000000000000000000000000000000000000000000000000000000000000000fa94348467f64d5a457f75f8bc40495d33c65abb0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000418160ddd00000000000000000000000000000000000000000000000000000000
To get the encoded EVM account of a NEAR account, we can use the encode-address
command from Aurora CLI. The encoding methods are implemented in aurora.js and aurora-engine-sdk.
$ aurora encode-address test.near
0xCBdA96B3F2B8eb962f97AE50C3852CA976740e2B
However, since the user usually doesn't own the private key of the encoded EVM address, one target Aurora address might need to be provided under some use cases such as swap (needs more research and testing).
In the current test, the Aurora function call via aurora.call()
is not included in the transactions in the Aurora explorer: https://explorer.mainnet.aurora.dev/
Only transactions submitted by Aurora relayer is included in Aurora Explorer.
- Aurora CLI: https://github.com/aurora-is-near/aurora-cli
- Aurora Engine: https://github.com/aurora-is-near/aurora-engine
- Aurora JS (Engine part): https://github.com/aurora-is-near/aurora.js/blob/master/src/engine.ts
Unfortunately this is not supported yet at the moment.
- aurora-is-near/aurora-engine#291
- https://gov.near.org/t/aurora-to-near-coross-contract-call-possible/8254
Create an application where contracts in NEAR and contracts in Aurora communicate between each other. https://metabuild.devpost.com/details/sponsor-challenges#h_42475642918091639626542295
Examples:
- NEAR Native Token on Aurora: create native NEAR support inside Aurora. Description of the task is on the issue. Near-One/rainbow-bridge#642
- Oracle that allows fetching information from NEAR in Aurora (or vice versa).
- Off-chain tools that allow integration, building and testing of this type of apps easier.