Smart Contract Integration
Takes a few hours
If rewards are calculated on-chain (like for every core staking contract on Terra), then teams can integrate with the Passport on-chain smart contract.
As shown in the diagram below, teams need to follow the below steps to integrate with both the Passport web2 backend and the Passport on-chain smart contracts:
Ask passport team for an api key to be used to get primitives and proof from the Passport web2 backend
Issue a web2 API request to receive the scores and Merkle proof: Passport's web2 backend stores a Merkle tree for all of the primitive scores. Rather than storing all wallet scores on-chain (which is transaction heavy and expensive), only the Merkle root will be written on chain. In order to make sure the requested scores' integrity, every on-chain smart contract should pass the scores along with their Merkle proof to the Passport verification smart contract, which will construct a Merkle root from the address + scores + proof. If the Merkle root that it constructed matches the Merkle root on Passport verification contract, then that score is trustworthy.
Update your smart contract to accept Passport primitive scores and merkle proofs: A smart contract needs to accept message containing both Passport primitive scores and merkle proofs in order to use the primitive scores in the on-chain computations. Because of the limitation of Cosmwasm message size, the scores will be passed in the schematized form that contains integer and the wallet address only. The details about the schematization is explained below:
Choice 1) Pass along the Merkle proof and raw primitive scores to the loyalty score smart contract to get a multiplier: The loyalty score smart contract is a middleware that helps to verify the integrity of the scores and returns a composable multiplier from the raw primitive scores. Teams are encouraged to fork the loyalty score smart contract and modify the multiplier formula per their needs. Current available query endpoints are listed below:
Choice 2) Directly pass along the Merkle proof and primitive scores to the Passport verification smart contract. Current available query endpoints of the verification contract are listed below:
Example of querying the contracts
Use the multiplier in your reward calculation logic: The protocol's smart contract will need to be updated to make use of the multiplier in their rewards logic
Resources
Terra Testnet loyalty smart contract address: terra1f02cg9v9cul92s2spgwyj704chvp0n2nk6h3jj
Terra Testnet verification contract address: terra1ajr226sp93tyd98phmev0mzpptmlzz43me9nap
Terra Mainnet loyalty smart contract address: terra1xt58s8zwcs3u7zvek9j3ds9gj6trr0p7hzxsvp
Terra Mainnet verification contract address: terra1scmxemz6y47jxt3gdt5s6pysvwfsgggfp58zk5
Last updated